UNPKG

@autobe/agent

Version:

AI backend server code generator

74 lines 3.56 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.orchestrateRealize = void 0; const uuid_1 = require("uuid"); const getAutoBeGenerated_1 = require("../../factory/getAutoBeGenerated"); const orchestrateRealizeAuthorization_1 = require("./orchestrateRealizeAuthorization"); const writeCodeUntilCompilePassed_1 = require("./writeCodeUntilCompilePassed"); const orchestrateRealize = (ctx) => (props) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g; const operations = (_a = ctx.state().interface) === null || _a === void 0 ? void 0 : _a.document.operations; if (!operations) { throw new Error("Can't do realize agent because operations are nothing."); } const start = new Date(); ctx.dispatch({ type: "realizeStart", created_at: new Date().toISOString(), reason: props.reason, step: (_c = (_b = ctx.state().test) === null || _b === void 0 ? void 0 : _b.step) !== null && _c !== void 0 ? _c : 0, }); // generate authorizations and functions const authorizations = yield (0, orchestrateRealizeAuthorization_1.orchestrateRealizeAuthorization)(ctx); const result = yield (0, writeCodeUntilCompilePassed_1.writeCodeUntilCompilePassed)(ctx)({ operations, authorizations, retry: 4, }); const functions = result.functions; // compile controllers const compiler = yield ctx.compiler(); const controllers = yield compiler.realize.controller({ document: ctx.state().interface.document, functions, authorizations, }); const history = { type: "realize", compiled: result.compiled, authorizations, functions, controllers, completed_at: new Date().toISOString(), created_at: start.toISOString(), id: (0, uuid_1.v4)(), reason: props.reason, step: (_e = (_d = ctx.state().analyze) === null || _d === void 0 ? void 0 : _d.step) !== null && _e !== void 0 ? _e : 0, }; // report ctx.dispatch({ type: "realizeComplete", created_at: new Date().toISOString(), functions: history.functions, authorizations: history.authorizations, controllers: history.controllers, compiled: yield compiler.typescript.compile({ files: yield (0, getAutoBeGenerated_1.getAutoBeGenerated)(compiler, Object.assign(Object.assign({}, ctx.state()), { realize: history }), [...ctx.histories(), history], ctx.usage()), }), step: (_g = (_f = ctx.state().analyze) === null || _f === void 0 ? void 0 : _f.step) !== null && _g !== void 0 ? _g : 0, }); ctx.state().realize = history; ctx.histories().push(history); return history; }); exports.orchestrateRealize = orchestrateRealize; //# sourceMappingURL=orchestrateRealize.js.map