@autobe/agent
Version:
AI backend server code generator
98 lines • 4.79 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.orchestrateInterface = void 0;
const utils_1 = require("@autobe/utils");
const uuid_1 = require("uuid");
const predicateStateMessage_1 = require("../../utils/predicateStateMessage");
const orchestrateInterfaceAuthorization_1 = require("./orchestrateInterfaceAuthorization");
const orchestrateInterfaceEndpoint_1 = require("./orchestrateInterfaceEndpoint");
const orchestrateInterfaceGroup_1 = require("./orchestrateInterfaceGroup");
const orchestrateInterfaceOperation_1 = require("./orchestrateInterfaceOperation");
const orchestrateInterfacePrerequisite_1 = require("./orchestrateInterfacePrerequisite");
const orchestrateInterfaceSchema_1 = require("./orchestrateInterfaceSchema");
const orchestrateInterface = (ctx) => (props) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f;
// PREDICATION
const start = new Date();
const predicate = (0, predicateStateMessage_1.predicateStateMessage)(ctx.state(), "interface");
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: "interfaceStart",
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,
});
// GROUPS
const init = yield (0, orchestrateInterfaceGroup_1.orchestrateInterfaceGroup)(ctx, {
instruction: props.instruction,
});
ctx.dispatch(init);
// AUTHORIZATION
const authorizations = yield (0, orchestrateInterfaceAuthorization_1.orchestrateInterfaceAuthorization)(ctx, {
instruction: props.instruction,
});
// ENDPOINTS
const endpoints = yield (0, orchestrateInterfaceEndpoint_1.orchestrateInterfaceEndpoint)(ctx, {
instruction: props.instruction,
authorizeOperations: authorizations.map((a) => a.operations).flat(),
groups: init.groups,
});
// OPERATIONS
const operations = [
...authorizations.map((auth) => auth.operations).flat(),
...(yield (0, orchestrateInterfaceOperation_1.orchestrateInterfaceOperation)(ctx, {
designs: endpoints,
instruction: props.instruction,
})),
];
// THE DOCUMENT WITH SCHEMAS
const document = {
operations,
components: {
authorizations: (_d = (_c = ctx.state().analyze) === null || _c === void 0 ? void 0 : _c.actors) !== null && _d !== void 0 ? _d : [],
schemas: yield (0, orchestrateInterfaceSchema_1.orchestrateInterfaceSchema)(ctx, {
instruction: props.instruction,
operations,
}),
},
};
(0, utils_1.revertOpenApiAccessor)(document);
// PREREQUISITES
const prerequisites = yield (0, orchestrateInterfacePrerequisite_1.orchestrateInterfacePrerequisite)(ctx, document);
document.operations.forEach((op) => {
var _a, _b;
op.prerequisites =
(_b = (_a = prerequisites.find((p) => p.endpoint.method === op.method && p.endpoint.path === op.path)) === null || _a === void 0 ? void 0 : _a.prerequisites) !== null && _b !== void 0 ? _b : [];
});
// DO COMPILE
return ctx.dispatch({
type: "interfaceComplete",
id: (0, uuid_1.v7)(),
document,
missed: (0, utils_1.missedOpenApiSchemas)(document),
authorizations,
aggregates: ctx.getCurrentAggregates("interface"),
step: (_f = (_e = ctx.state().analyze) === null || _e === void 0 ? void 0 : _e.step) !== null && _f !== void 0 ? _f : 0,
elapsed: new Date().getTime() - start.getTime(),
created_at: new Date().toISOString(),
});
});
exports.orchestrateInterface = orchestrateInterface;
//# sourceMappingURL=orchestrateInterface.js.map