@autobe/agent
Version:
AI backend server code generator
73 lines • 3.31 kB
JavaScript
;
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.orchestratePrisma = void 0;
const uuid_1 = require("uuid");
const orchestratePrismaComponent_1 = require("./orchestratePrismaComponent");
const orchestratePrismaCorrect_1 = require("./orchestratePrismaCorrect");
const orchestratePrismaSchemas_1 = require("./orchestratePrismaSchemas");
const orchestratePrisma = (ctx) => (props) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
const start = new Date();
ctx.dispatch({
type: "prismaStart",
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,
});
// COMPONENTS
const components = yield (0, orchestratePrismaComponent_1.orchestratePrismaComponents)(ctx);
if (components.type === "assistantMessage") {
ctx.histories().push(components);
ctx.dispatch(components);
return components;
}
else
ctx.dispatch(components);
// CONSTRUCT AST DATA
const events = yield (0, orchestratePrismaSchemas_1.orchestratePrismaSchemas)(ctx, components.components);
// VALIDATE
const result = yield (0, orchestratePrismaCorrect_1.orchestratePrismaCorrect)(ctx, {
files: events.map((e) => e.file),
});
// COMPILE
const compiler = yield ctx.compiler();
const schemas = yield compiler.prisma.write(result.data, "postgres");
// PROPAGATE
const history = {
type: "prisma",
id: (0, uuid_1.v4)(),
created_at: start.toISOString(),
completed_at: new Date().toISOString(),
reason: props.reason,
description: "",
result: result,
schemas,
compiled: yield compiler.prisma.compile({
files: schemas,
}),
step: (_d = (_c = ctx.state().analyze) === null || _c === void 0 ? void 0 : _c.step) !== null && _d !== void 0 ? _d : 0,
};
ctx.state().prisma = history;
ctx.histories().push(history);
if (history.result.success === true)
ctx.dispatch({
type: "prismaComplete",
application: history.result.data,
schemas: history.schemas,
compiled: history.compiled,
step: (_f = (_e = ctx.state().analyze) === null || _e === void 0 ? void 0 : _e.step) !== null && _f !== void 0 ? _f : 0,
created_at: new Date().toISOString(),
});
return history;
});
exports.orchestratePrisma = orchestratePrisma;
//# sourceMappingURL=orchestratePrisma.js.map