UNPKG

@autobe/agent

Version:

AI backend server code generator

376 lines 26.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.orchestrateTestPrepare = orchestrateTestPrepare; const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport")); const __typia_transform__llmApplicationFinalize = __importStar(require("typia/lib/internal/_llmApplicationFinalize")); const typia_1 = __importDefault(require("typia")); const orchestrateTestCorrectCasting_1 = require("./internal/orchestrateTestCorrectCasting"); const orchestrateTestCorrectOverall_1 = require("./internal/orchestrateTestCorrectOverall"); const orchestrateTestPrepareWrite_1 = require("./orchestrateTestPrepareWrite"); const AutoBeTestPrepareProgrammer_1 = require("./programmers/AutoBeTestPrepareProgrammer"); function orchestrateTestPrepare(ctx, props) { return __awaiter(this, void 0, void 0, function* () { const compile = (procedure) => __awaiter(this, void 0, void 0, function* () { var _a, _b; return AutoBeTestPrepareProgrammer_1.AutoBeTestPrepareProgrammer.compile({ compiler: yield ctx.compiler(), document: props.document, procedure, progress: props.validateProgress, step: (_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : 0, }); }); const replaceImportStatements = (procedure) => __awaiter(this, void 0, void 0, function* () { return AutoBeTestPrepareProgrammer_1.AutoBeTestPrepareProgrammer.replaceImportStatements({ compiler: yield ctx.compiler(), typeName: procedure.typeName, schemas: props.document.components.schemas, content: procedure.function.content, }); }); let procedures = yield (0, orchestrateTestPrepareWrite_1.orchestrateTestPrepareWrite)(ctx, { instruction: props.instruction, document: props.document, progress: props.writeProgress, }); props.validateProgress.total += procedures.length; procedures = yield (0, orchestrateTestCorrectCasting_1.orchestrateTestCorrectCasting)(ctx, { programmer: { compile, replaceImportStatements, asynchronous: false, }, procedures, progress: props.validateProgress, }); procedures = yield (0, orchestrateTestCorrectOverall_1.orchestrateTestCorrectOverall)(ctx, { programmer: { compile, replaceImportStatements, controller: (next) => createCorrectOverallController(next), }, procedures, instruction: props.instruction, progress: props.validateProgress, discard: false, }); return procedures.map((p) => p.function); }); } function createCorrectOverallController(props) { const validate = (input) => { const result = (() => { const _io0 = input => "string" === typeof input.think && (Array.isArray(input.mappings) && input.mappings.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io2(input.revise)); const _io1 = input => "string" === typeof input.property && "string" === typeof input.how; const _io2 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.think || _report(_exceptionable, { path: _path + ".think", expected: "string", value: input.think }), (Array.isArray(input.mappings) || _report(_exceptionable, { path: _path + ".mappings", expected: "Array<AutoBeTestPrepareMapping>", value: input.mappings })) && input.mappings.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".mappings[" + _index2 + "]", expected: "AutoBeTestPrepareMapping", value: elem })) && _vo1(elem, _path + ".mappings[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".mappings[" + _index2 + "]", expected: "AutoBeTestPrepareMapping", value: elem })).every(flag => flag) || _report(_exceptionable, { path: _path + ".mappings", expected: "Array<AutoBeTestPrepareMapping>", value: input.mappings }), "string" === typeof input.draft || _report(_exceptionable, { path: _path + ".draft", expected: "string", value: input.draft }), ("object" === typeof input.revise && null !== input.revise || _report(_exceptionable, { path: _path + ".revise", expected: "IAutoBeTestPrepareCorrectOverallApplication.IReviseProps", value: input.revise })) && _vo2(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, { path: _path + ".revise", expected: "IAutoBeTestPrepareCorrectOverallApplication.IReviseProps", value: input.revise })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.property || _report(_exceptionable, { path: _path + ".property", expected: "string", value: input.property }), "string" === typeof input.how || _report(_exceptionable, { path: _path + ".how", expected: "string", value: input.how })].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => ["string" === typeof input.review || _report(_exceptionable, { path: _path + ".review", expected: "string", value: input.review }), null === input.final || "string" === typeof input.final || _report(_exceptionable, { path: _path + ".final", expected: "(null | string)", value: input.final })].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: "IAutoBeTestPrepareCorrectOverallApplication.IProps", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "IAutoBeTestPrepareCorrectOverallApplication.IProps", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })()(input); if (result.success === false) return result; const errors = AutoBeTestPrepareProgrammer_1.AutoBeTestPrepareProgrammer.validate({ typeName: props.procedure.typeName, schema: props.procedure.schema, mappings: result.data.mappings, draft: result.data.draft, revise: result.data.revise, }); return errors.length ? { success: false, errors, data: result.data, } : result; }; const application = __typia_transform__llmApplicationFinalize._llmApplicationFinalize({ functions: [ { name: "rewrite", parameters: { description: "Current Type: {@link IAutoBeTestPrepareCorrectOverallApplication.IProps}", type: "object", properties: { think: { description: "Step 1: Deep compilation error analysis and correction strategy.\n\nAI performs comprehensive analysis of compilation errors to develop\ntargeted correction strategies. This step involves deep examination of\nerror messages, identification of error patterns, understanding root\ncauses, and planning systematic corrections.\n\nThe AI examines each compilation diagnostic to understand where the\nimplementation diverged from correct TypeScript usage, identifies the\nbusiness logic intent behind the failed code, and formulates strategies\nto fix errors while preserving the original prepare function purpose.\nThis analysis correlates error patterns with code structure to ensure\ncorrections address root causes rather than symptoms.\n\nThis deep analysis forms the foundation for all subsequent correction\nefforts, ensuring a methodical approach to resolving compilation issues.\n\nWorkflow: Error diagnostic analysis \u2192 Root cause identification \u2192\nCorrection strategy planning \u2192 Business logic preservation strategy", type: "string" }, mappings: { description: "Step 2: Property-by-property mapping table for complete DTO coverage.\n\nMUST include EVERY property from the DTO schema - no exceptions. Each\nmapping specifies:\n\n- `property`: Exact property name from DTO schema\n- `how`: How to generate the value for that property\n\nThe `mappings` field is your Chain-of-Thought (CoT) mechanism - it forces\nyou to explicitly think through EVERY property before coding, preventing\nomissions and incorrect data generation during error correction.\n\nMissing even a single property will cause validation failure and trigger\nregeneration.\n\nThis structured approach:\n\n- Prevents property omissions through systematic coverage\n- Forces explicit decision-making for each property\n- Enables validation before code generation\n- Creates clear documentation of data generation strategy\n- Ensures corrections maintain complete DTO coverage\n\nThe validator will cross-check this list against the actual DTO schema\nand reject incomplete mappings.", type: "array", items: { $ref: "#/$defs/AutoBeTestPrepareMapping" } }, draft: { description: "Step 3: Draft corrected TypeScript prepare function implementation.\n\nAI generates the first corrected version of the prepare function based on\nerror analysis, property mappings, and correction strategies. This draft\naddresses all identified compilation errors while preserving the original\ndata generation logic and ensuring complete DTO coverage. The code is\ncompilation-error-free and follows all established conventions.\n\nThe implementation incorporates lessons learned from error analysis and\nstrictly follows the property mappings to produce properly typed,\nsyntactically correct code that maintains the intended prepare function\nfunctionality. All type safety requirements and framework conventions are\nfollowed in this corrected implementation.\n\nWorkflow: Error correction \u2192 Property mapping implementation \u2192 TypeScript\nimplementation \u2192 Functional preservation\n\nDO: Resolve all compilation errors while maintaining original prepare\nfunction intent and complete DTO coverage", type: "string" }, revise: { description: "Step 4-5: Review and finalization process.\n\nEncapsulates the review and final implementation phases into a single\nrevision process. This structured approach ensures systematic validation\nand refinement of the corrected code through comprehensive review\nfollowed by production-ready implementation.\n\nThe revision process maintains clear separation between review feedback\nand final deliverable while ensuring all corrections are properly\nvalidated and integrated.", $ref: "#/$defs/IAutoBeTestPrepareCorrectOverallApplication.IReviseProps" } }, required: [ "think", "mappings", "draft", "revise" ], additionalProperties: false, $defs: { AutoBeTestPrepareMapping: { description: "Property-by-property data generation mapping for test prepare functions.\n\nExplicit mapping ensures complete DTO coverage by documenting generation\nstrategy for each property before implementation.", type: "object", properties: { property: { description: "Exact property name from the DTO schema.\n\nMust match actual DTO property - no fabricated names allowed.", type: "string" }, how: { description: "Data generation strategy for this property.\n\nExplains how the value will be generated (e.g., \"typia.random with uuid\nformat\", \"RandomGenerator.paragraph with 2-5 sentences\", \"input override or\ndefault generation\").", type: "string" } }, required: [ "property", "how" ] }, "IAutoBeTestPrepareCorrectOverallApplication.IReviseProps": { description: "Revision properties for the final review and implementation phases.\n\nThis interface encapsulates the final two steps of the error correction\nworkflow, ensuring systematic review and production-ready code delivery.", type: "object", properties: { review: { description: "Step 4: Code review and correction validation.\n\nAI performs a comprehensive review of the corrected draft implementation,\nvalidating that all compilation errors have been resolved and that the\ncode maintains the original functionality with complete DTO coverage.\nThis review examines both technical correctness and data generation logic\npreservation.\n\nThe review process includes verification of TypeScript compilation\ncompatibility, property mapping completeness, constraint compliance,\nnested structure handling correctness, and adherence to all quality\nstandards. Any remaining issues or potential improvements are identified\nfor incorporation into the final implementation.\n\nMUST systematically verify using these checklists:\n\n1. Schema Fidelity - Cross-check EVERY property name against the DTO schema,\n verify all properties are generated, no fabricated properties\n2. Type Safety - DeepPartial<> used (not Partial<>), proper typing, correct\n nested handling\n3. Constraint Compliance - String lengths, number bounds, formats, enums\n4. Compilation Fix - All original compilation errors resolved\n\nWorkflow: Draft validation \u2192 Compilation verification \u2192 Mapping coverage\nreview \u2192 Quality assessment", type: "string" }, final: { description: "Step 5: Final production-ready corrected prepare function code.\n\nAI produces the final, polished version of the corrected prepare function\ncode incorporating all review feedback and validation results. This code\nrepresents the completed error correction, guaranteed to compile\nsuccessfully while preserving all original data generation functionality\nand complete DTO coverage. When the draft correction already perfectly\nresolves all issues with no problems found during review, this value can\nbe null, indicating no further refinement was necessary.\n\nThe final implementation resolves all compilation issues, maintains\nstrict type safety, follows all established conventions, covers all DTO\nproperties, and delivers a production-ready prepare function that\naccurately generates realistic test data. A null value signifies the\ndraft correction was already optimal and requires no modifications.\n\nWorkflow: Review integration \u2192 Final refinement \u2192 Production-ready\nimplementation (or null if draft needs no changes). This is the ultimate\ndeliverable that will replace the compilation-failed code when provided,\notherwise the draft correction is used as-is.", anyOf: [ { type: "null" }, { type: "string" } ] } }, required: [ "review", "final" ] } } }, description: "Main entry point for AI Function Call - analyzes compilation errors and\ngenerates corrected test data preparation function.\n\nThe AI executes this function to perform the complete error correction\nworkflow: compilation error analysis \u2192 property mappings \u2192 draft correction\n\u2192 code review \u2192 final corrected implementation. This multi-step process\nensures systematic error resolution while preserving original prepare\nfunction functionality and maintaining complete DTO coverage.\n\nThe corrector analyzes compilation diagnostics to identify specific issues,\nmaps all properties to ensure no omissions during correction, develops\ncorrection strategies, and produces corrected code through iterative\nrefinement with comprehensive review and validation.", validate: (() => { const _io0 = input => "string" === typeof input.think && (Array.isArray(input.mappings) && input.mappings.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io2(input.revise)); const _io1 = input => "string" === typeof input.property && "string" === typeof input.how; const _io2 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.think || _report(_exceptionable, { path: _path + ".think", expected: "string", value: input.think }), (Array.isArray(input.mappings) || _report(_exceptionable, { path: _path + ".mappings", expected: "Array<AutoBeTestPrepareMapping>", value: input.mappings })) && input.mappings.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".mappings[" + _index2 + "]", expected: "AutoBeTestPrepareMapping", value: elem })) && _vo1(elem, _path + ".mappings[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".mappings[" + _index2 + "]", expected: "AutoBeTestPrepareMapping", value: elem })).every(flag => flag) || _report(_exceptionable, { path: _path + ".mappings", expected: "Array<AutoBeTestPrepareMapping>", value: input.mappings }), "string" === typeof input.draft || _report(_exceptionable, { path: _path + ".draft", expected: "string", value: input.draft }), ("object" === typeof input.revise && null !== input.revise || _report(_exceptionable, { path: _path + ".revise", expected: "IAutoBeTestPrepareCorrectOverallApplication.IReviseProps", value: input.revise })) && _vo2(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, { path: _path + ".revise", expected: "IAutoBeTestPrepareCorrectOverallApplication.IReviseProps", value: input.revise })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.property || _report(_exceptionable, { path: _path + ".property", expected: "string", value: input.property }), "string" === typeof input.how || _report(_exceptionable, { path: _path + ".how", expected: "string", value: input.how })].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => ["string" === typeof input.review || _report(_exceptionable, { path: _path + ".review", expected: "string", value: input.review }), null === input.final || "string" === typeof input.final || _report(_exceptionable, { path: _path + ".final", expected: "(null | string)", value: input.final })].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: "IAutoBeTestPrepareCorrectOverallApplication.IProps", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "IAutoBeTestPrepareCorrectOverallApplication.IProps", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() } ] }, { validate: { rewrite: validate, }, }); return { protocol: "class", name: "testCorrect", application, execute: { rewrite: (v) => { props.build(v); }, }, }; } //# sourceMappingURL=orchestrateTestPrepare.js.map