@autobe/agent
Version:
AI backend server code generator
97 lines • 4.96 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.AutoBePreliminaryController = void 0;
const openapi_1 = require("@samchon/openapi");
const uuid_1 = require("uuid");
const transformPreliminaryHistory_1 = require("./histories/transformPreliminaryHistory");
const complementPreliminaryCollection_1 = require("./internal/complementPreliminaryCollection");
const createPreliminaryCollection_1 = require("./internal/createPreliminaryCollection");
const validatePreliminary_1 = require("./internal/validatePreliminary");
const orchestratePreliminary_1 = require("./orchestratePreliminary");
class AutoBePreliminaryController {
constructor(props) {
this.source = props.source;
this.source_id = (0, uuid_1.v7)();
this.kinds = props.kinds;
this.argumentTypeNames = (() => {
var _a, _b, _c;
const func = props.application.functions.find((f) => f.name === "process");
if (func === undefined)
throw new Error("Unable to find 'process' function in application.");
const param = (_a = func.parameters[0]) === null || _a === void 0 ? void 0 : _a.schema;
if (param === undefined ||
openapi_1.OpenApiTypeChecker.isReference(param) === false)
throw new Error("'process' function parameter is not a reference type.");
const schema = (_b = props.application.components.schemas) === null || _b === void 0 ? void 0 : _b[param.$ref.split("/").pop()];
if (schema === undefined || openapi_1.OpenApiTypeChecker.isObject(schema) === false)
throw new Error("'process' function parameter reference is not an object type.");
const request = (_c = schema.properties) === null || _c === void 0 ? void 0 : _c.request;
if (request === undefined ||
openapi_1.OpenApiTypeChecker.isOneOf(request) === false)
throw new Error("'process' function parameter.request is not a oneOf type.");
else if (request.oneOf.length === 0 ||
request.oneOf.every((sch) => openapi_1.OpenApiTypeChecker.isReference(sch) === false))
throw new Error("'process' function parameter.request oneOf does not contain any reference type.");
return request.oneOf.map((sch) => {
const ref = sch.$ref;
return ref.split("/").pop();
});
})();
this.all = (0, createPreliminaryCollection_1.createPreliminaryCollection)(props.state, props.all);
this.local = (0, createPreliminaryCollection_1.createPreliminaryCollection)(null, props.local);
(0, complementPreliminaryCollection_1.complementPreliminaryCollection)({
kinds: props.kinds,
all: this.all,
local: this.local,
});
}
validate(input) {
return (0, validatePreliminary_1.validatePreliminary)(this, input);
}
getHistories() {
return (0, transformPreliminaryHistory_1.transformPreliminaryHistory)(this);
}
getSource() {
return this.source;
}
getKinds() {
return this.kinds;
}
getArgumentTypeNames() {
return this.argumentTypeNames;
}
getAll() {
return this.all;
}
getLocal() {
return this.local;
}
orchestrate(ctx, process) {
return __awaiter(this, void 0, void 0, function* () {
for (let i = 0; i < 10 /* AutoBeConfigConstant.RAG_LIMIT */; ++i) {
const result = yield process((x) => (value) => (Object.assign(Object.assign({}, x), { value })));
if (result.value !== null)
return result.value;
yield (0, orchestratePreliminary_1.orchestratePreliminary)(ctx, {
source_id: this.source_id,
source: this.source,
preliminary: this,
trial: i + 1,
histories: result.histories,
});
}
throw new Error("Preliminary process exceeded the maximum number of retries.");
});
}
}
exports.AutoBePreliminaryController = AutoBePreliminaryController;
//# sourceMappingURL=AutoBePreliminaryController.js.map