UNPKG

@autobe/agent

Version:

AI backend server code generator

80 lines 3.8 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 orchestrateTestCorrect_1 = require("./orchestrateTestCorrect"); const orchestrateTestScenario_1 = require("./orchestrateTestScenario"); const orchestrateTestWrite_1 = require("./orchestrateTestWrite"); const orchestrateTest = (ctx) => (props) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h; const start = new Date(); ctx.dispatch({ type: "testStart", created_at: start.toISOString(), reason: props.reason, step: (_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : 0, }); const operations = (_d = (_c = ctx.state().interface) === null || _c === void 0 ? void 0 : _c.document.operations) !== null && _d !== void 0 ? _d : []; if (operations.length === 0) { const history = { id: (0, uuid_1.v4)(), 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.", }; ctx.histories().push(history); ctx.dispatch(history); return history; } // PLAN const scenarioEvent = yield (0, orchestrateTestScenario_1.orchestrateTestScenario)(ctx); ctx.dispatch(scenarioEvent); // TEST CODE const written = yield (0, orchestrateTestWrite_1.orchestrateTestWrite)(ctx, scenarioEvent.scenarios); const corrects = yield (0, orchestrateTestCorrect_1.orchestrateTestCorrect)(ctx, written); const success = corrects.filter((c) => c.result.type === "success"); // DO COMPILE const compiler = yield ctx.compiler(); const result = success.map((c) => c.file); const compiled = yield compiler.typescript.compile({ files: Object.fromEntries([ ...Object.entries(yield ctx.files({ dbms: "sqlite", })).filter(([key]) => key.endsWith(".ts")), ...result.map((f) => [f.location, f.content]), ]), }); const history = { type: "test", id: (0, uuid_1.v4)(), completed_at: new Date().toISOString(), created_at: start.toISOString(), files: result, compiled, reason: "Step to the test generation referencing the interface", step: (_f = (_e = ctx.state().interface) === null || _e === void 0 ? void 0 : _e.step) !== null && _f !== void 0 ? _f : 0, }; ctx.dispatch({ type: "testComplete", created_at: start.toISOString(), files: result, compiled, step: (_h = (_g = ctx.state().interface) === null || _g === void 0 ? void 0 : _g.step) !== null && _h !== void 0 ? _h : 0, }); ctx.state().test = history; ctx.histories().push(history); return history; }); exports.orchestrateTest = orchestrateTest; //# sourceMappingURL=orchestrateTest.js.map