UNPKG

@autobe/agent

Version:

AI backend server code generator

504 lines 27.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createAutoBeFacadeController = void 0; const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport")); const __typia_transform__llmApplicationFinalize = __importStar(require("typia/lib/internal/_llmApplicationFinalize")); const utils_1 = require("@autobe/utils"); const typia_1 = __importDefault(require("typia")); const orchestrateAnalyze_1 = require("../analyze/orchestrateAnalyze"); const orchestrateDatabase_1 = require("../database/orchestrateDatabase"); const orchestrateInterface_1 = require("../interface/orchestrateInterface"); const orchestrateRealize_1 = require("../realize/orchestrateRealize"); const orchestrateTest_1 = require("../test/orchestrateTest"); const createAutoBeFacadeController = (props) => { const application = __typia_transform__llmApplicationFinalize._llmApplicationFinalize({ functions: [ { name: "analyze", parameters: { type: "object", properties: {}, additionalProperties: false, required: [], $defs: {} }, output: { description: "Current Type: {@link IAutoBeFacadeApplicationResult}", type: "object", properties: { type: { type: "string", "enum": [ "success", "failure", "exception", "in-progress", "prerequisites-not-satisfied" ] }, description: { type: "string" } }, required: [ "type", "description" ], additionalProperties: false, $defs: {} }, description: "Run Analyze Agent.\n\nExecutes the Analyze agent to process user requirements and generate a\nstructured specification document. This agent analyzes all conversation\nhistory between users and AI, separates business logic from technical\nrequirements, and establishes development priorities and scope.\n\n**IMPORTANT**: Only call this function when sufficient requirements have\nbeen discussed to generate a comprehensive specification. The context must\ncontain enough detail about the system's purpose, core features, data\nmodels, and business rules. If requirements are unclear or incomplete,\ncontinue gathering information through conversation instead.\n\nThe agent will automatically generate follow-up questions for any ambiguous\nrequirements and continuously refine its understanding through iterative\nconversation. When executed after other agents have generated code, it can\nalso interpret change requests in the context of existing implementations.", validate: (() => { const __is = input => true; let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => true)(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "database", parameters: { type: "object", properties: { instruction: { description: "Database design instructions from user conversation.\n\nPass empty string \"\" if no database-specific instructions exist.", type: "string" } }, required: [ "instruction" ], additionalProperties: false, $defs: {} }, output: { description: "Current Type: {@link IAutoBeFacadeApplicationResult}", type: "object", properties: { type: { type: "string", "enum": [ "success", "failure", "exception", "in-progress", "prerequisites-not-satisfied" ] }, description: { type: "string" } }, required: [ "type", "description" ], additionalProperties: false, $defs: {} }, description: "Run database agent.\n\nExecutes the Database agent to generate database schema files and ERD\ndocumentation. This agent reads the requirements specification created by\nthe {@link analyze Analyze agent} and produces a complete database schema\nwith comprehensive documentation for each entity and attribute.\n\n**PREREQUISITE**: Only call this function after the {@link analyze} function\nhas been successfully executed and a requirements specification document\nhas been generated. The Database agent depends on the structured\nrequirements analysis to design the database schema properly. Without a\ncompleted requirements specification, this function should NOT be called.\n\nThe agent will automatically validate the generated schema using the\ndatabase schema compilation, self-correct any compilation errors through\nfeedback loops, and generate ERD documentation using prisma-markdown. An\ninternal review process ensures schema quality and optimization.", validate: (() => { const _io0 = input => "string" === typeof input.instruction; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.instruction || _report(_exceptionable, { path: _path + ".instruction", expected: "string", value: input.instruction })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "interface", parameters: { type: "object", properties: { instruction: { description: "API design instructions from user conversation.\n\nPass empty string \"\" if no API-specific instructions exist.", type: "string" } }, required: [ "instruction" ], additionalProperties: false, $defs: {} }, output: { description: "Current Type: {@link IAutoBeFacadeApplicationResult}", type: "object", properties: { type: { type: "string", "enum": [ "success", "failure", "exception", "in-progress", "prerequisites-not-satisfied" ] }, description: { type: "string" } }, required: [ "type", "description" ], additionalProperties: false, $defs: {} }, description: "Run interface agent.\n\nExecutes the Interface agent to design and generate API interfaces. This\nagent creates OpenAPI schemas and TypeScript/NestJS code based on the\nrequirements specification and ERD documentation from previous agents.\n\nThe agent follows a sophisticated pipeline: first constructing formal\nOpenAPI Operation Schemas and JSON Schemas, then validating these schemas,\nand finally transforming them into NestJS controllers and DTOs. Each\ngenerated interface includes comprehensive JSDoc comments and undergoes\ninternal review for consistency.", validate: (() => { const _io0 = input => "string" === typeof input.instruction; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.instruction || _report(_exceptionable, { path: _path + ".instruction", expected: "string", value: input.instruction })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "test", parameters: { type: "object", properties: { instruction: { description: "Testing strategy instructions from user conversation.\n\nPass empty string \"\" if no test-specific instructions exist.", type: "string" } }, required: [ "instruction" ], additionalProperties: false, $defs: {} }, output: { description: "Current Type: {@link IAutoBeFacadeApplicationResult}", type: "object", properties: { type: { type: "string", "enum": [ "success", "failure", "exception", "in-progress", "prerequisites-not-satisfied" ] }, description: { type: "string" } }, required: [ "type", "description" ], additionalProperties: false, $defs: {} }, description: "Run test program agent.\n\nExecutes the Test agent to generate comprehensive E2E test suites for all\n{@link interface API interfaces}. This agent synthesizes outputs from\nprevious agents to create tests that validate both individual endpoints and\ntheir interactions.\n\n**PREREQUISITE**: Only call this function after the {@link interface}\nfunction has been successfully executed and API interfaces have been\ngenerated. The Test agent requires the completed API interface definitions,\nOpenAPI schemas, and TypeScript code to generate appropriate test\nscenarios. Without completed interface design, this function should NOT be\ncalled.\n\nThe agent will analyze dependency relationships between API functions,\nstructure integrated test scenarios with correct execution sequences, and\nenhance pre-generated test scaffolds with business logic validation.\nTypeScript compiler validation and internal review ensure test quality and\noptimal coverage.", validate: (() => { const _io0 = input => "string" === typeof input.instruction; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.instruction || _report(_exceptionable, { path: _path + ".instruction", expected: "string", value: input.instruction })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "realize", parameters: { type: "object", properties: { instruction: { description: "Implementation instructions from user conversation.\n\nPass empty string \"\" if no implementation-specific instructions exist.", type: "string" } }, required: [ "instruction" ], additionalProperties: false, $defs: {} }, output: { description: "Current Type: {@link IAutoBeFacadeApplicationResult}", type: "object", properties: { type: { type: "string", "enum": [ "success", "failure", "exception", "in-progress", "prerequisites-not-satisfied" ] }, description: { type: "string" } }, required: [ "type", "description" ], additionalProperties: false, $defs: {} }, description: "Run realize agent.\n\nExecutes the Realize agent to implement the actual business logic for each\nAPI endpoint. This agent synthesizes all outputs from previous agents to\ngenerate fully functional service provider code.\n\n**PREREQUISITE**: Only call this function after the {@link interface}\nfunction has been successfully executed and API interfaces have been\ngenerated. The Realize agent requires the completed API interface\ndefinitions to implement the corresponding service logic. It also benefits\nfrom having test code available for validation. Without completed interface\ndesign, this function should NOT be called.\n\nThe agent will create service implementations with multiple validation\nlayers: TypeScript compiler feedback, runtime validation through test\nexecution, and quality optimization through internal review. The generated\ncode handles database interactions through Database, implements security\nand validation checks, and processes business rules according to\nspecifications.", validate: (() => { const _io0 = input => "string" === typeof input.instruction; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.instruction || _report(_exceptionable, { path: _path + ".instruction", expected: "string", value: input.instruction })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() } ] }); return { protocol: "class", name: "autobe", application, execute: { analyze: () => __awaiter(void 0, void 0, void 0, function* () { const history = yield (0, orchestrateAnalyze_1.orchestrateAnalyze)(props.context); if (history.type === "assistantMessage") return { type: "in-progress", description: utils_1.StringUtil.trim ` Requirements are not yet fully elicited, therefore additional questions will be made to the user. `, }; return { type: "success", description: "Analysis completed successfully, and report has been published.", }; }), database: (next) => __awaiter(void 0, void 0, void 0, function* () { const history = yield (0, orchestrateDatabase_1.orchestrateDatabase)(props.context, next); if (history.type === "assistantMessage") return { type: "prerequisites-not-satisfied", description: "Requirement analysis is not yet completed.", }; return { type: history.compiled.type, description: history.compiled.type === "success" ? "Database schemas have been generated successfully." : history.result.success === false || history.compiled.type === "failure" ? "Database schemas are generated, but compilation failed." : "Unexpected error occurred while generating database schemas.", }; }), interface: (next) => __awaiter(void 0, void 0, void 0, function* () { const history = yield (0, orchestrateInterface_1.orchestrateInterface)(props.context)(next); if (history.type === "assistantMessage") return { type: "prerequisites-not-satisfied", description: "Database schemas are not yet completed.", }; return { type: "success", description: "API interfaces have been designed successfully.", }; }), test: (next) => __awaiter(void 0, void 0, void 0, function* () { const history = yield (0, orchestrateTest_1.orchestrateTest)(props.context)(next); if (history.type === "assistantMessage") return { type: "prerequisites-not-satisfied", description: "API interfaces are not yet completed.", }; return { type: history.compiled.type, description: history.compiled.type === "success" ? "Test functions have been generated successfully." : history.compiled.type === "failure" ? "Test functions are written, but compilation failed." : "Unexpected error occurred while writing test functions.", }; }), realize: (next) => __awaiter(void 0, void 0, void 0, function* () { const history = yield (0, orchestrateRealize_1.orchestrateRealize)(props.context)(next); if (history.type === "assistantMessage") return { type: "prerequisites-not-satisfied", description: "API interfaces are not yet completed.", }; return { type: history.compiled.type, description: history.compiled.type === "success" ? "API implementation codes have been generated successfully." : history.compiled.type === "failure" ? "Implementation codes are composed, but compilation failed." : "Unexpected error occurred while writing implementation codes.", }; }), }, }; }; exports.createAutoBeFacadeController = createAutoBeFacadeController; //# sourceMappingURL=createAutoBeFacadeController.js.map