@autobe/agent
Version:
AI backend server code generator
71 lines • 3.55 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 uuid_1 = require("uuid");
const orchestrateInterfaceComplement_1 = require("./orchestrateInterfaceComplement");
const orchestrateInterfaceEndpoints_1 = require("./orchestrateInterfaceEndpoints");
const orchestrateInterfaceGroups_1 = require("./orchestrateInterfaceGroups");
const orchestrateInterfaceOperations_1 = require("./orchestrateInterfaceOperations");
const orchestrateInterfaceSchemas_1 = require("./orchestrateInterfaceSchemas");
const orchestrateInterface = (ctx) => (props) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h;
// ENDPOINTS
const start = new Date();
ctx.dispatch({
type: "interfaceStart",
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 init = yield (0, orchestrateInterfaceGroups_1.orchestrateInterfaceGroups)(ctx);
if (init.type === "assistantMessage") {
ctx.dispatch(init);
ctx.histories().push(init);
return init;
}
else
ctx.dispatch(init);
// ENDPOINTS & OPERATIONS
const endpoints = yield (0, orchestrateInterfaceEndpoints_1.orchestrateInterfaceEndpoints)(ctx, init.groups);
const operations = yield (0, orchestrateInterfaceOperations_1.orchestrateInterfaceOperations)(ctx, endpoints);
// TYPE SCHEMAS
const document = {
operations,
components: {
authorization: (_d = (_c = ctx.state().analyze) === null || _c === void 0 ? void 0 : _c.roles) !== null && _d !== void 0 ? _d : [],
schemas: yield (0, orchestrateInterfaceSchemas_1.orchestrateInterfaceSchemas)(ctx, operations),
},
};
document.components.schemas = yield (0, orchestrateInterfaceComplement_1.orchestrateInterfaceComplement)(ctx, document);
// DO COMPILE
const result = {
type: "interface",
id: (0, uuid_1.v4)(),
document,
reason: props.reason,
step: (_f = (_e = ctx.state().analyze) === null || _e === void 0 ? void 0 : _e.step) !== null && _f !== void 0 ? _f : 0,
created_at: start.toISOString(),
completed_at: new Date().toISOString(),
};
ctx.state().interface = result;
ctx.histories().push(result);
ctx.dispatch({
type: "interfaceComplete",
document: result.document,
created_at: start.toISOString(),
reason: props.reason,
step: (_h = (_g = ctx.state().analyze) === null || _g === void 0 ? void 0 : _g.step) !== null && _h !== void 0 ? _h : 0,
});
return result;
});
exports.orchestrateInterface = orchestrateInterface;
//# sourceMappingURL=orchestrateInterface.js.map