UNPKG

@autobe/agent

Version:

AI backend server code generator

151 lines 5.93 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.AutoBeMockAgent = void 0; const tstl_1 = require("tstl"); const uuid_1 = require("uuid"); const AutoBeAgentBase_1 = require("./AutoBeAgentBase"); const AutoBeTokenUsage_1 = require("./context/AutoBeTokenUsage"); const createAutoBeState_1 = require("./factory/createAutoBeState"); /** @internal */ class AutoBeMockAgent extends AutoBeAgentBase_1.AutoBeAgentBase { constructor(props) { super({ compiler: () => this.compiler_.get(), state: () => (0, createAutoBeState_1.createAutoBeState)(this.histories_), }); this.props_ = props; this.histories_ = []; this.compiler_ = new tstl_1.Singleton(() => __awaiter(this, void 0, void 0, function* () { return props.compiler({ realize: { test: { onOperation: () => __awaiter(this, void 0, void 0, function* () { }), onReset: () => __awaiter(this, void 0, void 0, function* () { }), }, }, }); })); this.token_usage_ = new AutoBeTokenUsage_1.AutoBeTokenUsage(); } conversate(content) { return __awaiter(this, void 0, void 0, function* () { // THE USER-MESSAGE const userMessage = { id: (0, uuid_1.v4)(), type: "userMessage", contents: typeof content === "string" ? [ { type: "text", text: content, }, ] : Array.isArray(content) ? content : [content], created_at: new Date().toISOString(), }; void this.dispatch(userMessage).catch(() => { }); // ALREADY REALIZED CASE const state = (0, createAutoBeState_1.createAutoBeState)(this.histories_); if (state.realize !== null) { yield (0, tstl_1.sleep_for)(2000); const assistantMessage = { id: (0, uuid_1.v4)(), type: "assistantMessage", text: [ "AutoBE has successfully realized the application.", "", "Thanks for using AutoBE!", ].join("\n"), created_at: new Date().toISOString(), completed_at: new Date().toISOString(), }; void this.dispatch(assistantMessage).catch(() => { }); this.histories_.push(userMessage, assistantMessage); return this.histories_; } const take = (type) => __awaiter(this, void 0, void 0, function* () { var _a; for (const s of this.getEventSnapshots(type)) { const time = (_a = sleepMap[s.event.type]) !== null && _a !== void 0 ? _a : 500; yield (0, tstl_1.sleep_for)((0, tstl_1.randint)(time * 0.2, time * 1.8)); void this.dispatch(s.event).catch(() => { }); this.token_usage_ = new AutoBeTokenUsage_1.AutoBeTokenUsage(s.tokenUsage); } this.histories_.push(userMessage); this.histories_.push(this.props_.preset.histories.find((h) => h.type === type)); }); if (state.analyze === null) yield take("analyze"); else if (state.prisma === null) yield take("prisma"); else if (state.interface === null) yield take("interface"); else if (state.test === null) yield take("test"); else if (state.realize === null) yield take("realize"); return this.histories_; }); } getHistories() { return this.histories_; } getTokenUsage() { return this.token_usage_; } getEventSnapshots(state) { return this.props_.preset[state]; } } exports.AutoBeMockAgent = AutoBeMockAgent; const sleepMap = { // ANALYZE analyzeStart: 1000, analyzeWrite: 500, analyzeReview: 300, analyzeComplete: 1000, // PRISMA prismaStart: 1000, prismaComponents: 1000, prismaSchemas: 500, prismaValidate: 2000, prismaCorrect: 500, prismaInsufficient: 1000, prismaComplete: 1000, // INTERFACE interfaceStart: 1000, interfaceEndpoints: 1000, interfaceOperations: 400, interfaceSchemas: 400, interfaceComplement: 2000, interfaceComplete: 1000, // TEST testStart: 1000, testScenario: 1000, testWrite: 40, testValidate: 100, testCorrect: 100, testComplete: 1000, // REALIZE realizeStart: 1000, realizeComplete: 1000, realizeWrite: 80, realizeCorrect: 80, realizeValidate: 200, realizeAuthorizationStart: 1000, realizeAuthorizationWrite: 200, realizeAuthorizationValidate: 200, realizeAuthorizationComplete: 1000, }; //# sourceMappingURL=AutoBeMockAgent.js.map