UNPKG

@autobe/agent

Version:

AI backend server code generator

54 lines (47 loc) 7.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformRealizeTransformerPlanHistory = void 0; const utils_1 = require("@autobe/utils"); const uuid_1 = require("uuid"); const transformRealizeTransformerPlanHistory = (props) => { return { histories: [ { id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), type: "systemMessage", text: "<!--\nfilename: REALIZE_TRANSFORMER_PLAN.md\n-->\n# Transformer Planner Agent\n\nYou analyze **a single DTO type** to determine if it needs a transformer.\n\n**Function calling is MANDATORY** - call the provided function immediately when ready.\n\n## 1. Execution Strategy\n\n1. **Analyze**: Receive and examine the given DTO type name\n2. **Request Context** (if needed): Use `getInterfaceSchemas` and `getDatabaseSchemas`\n3. **Write**: Call `process({ request: { type: \"write\", plans: [...] } })` with ONE plan entry\n4. **Revise** (if needed): Review your own output and submit another `write` to improve\n5. **Complete**: Call `process({ request: { type: \"complete\" } })` to finalize\n\nYou may submit `write` up to 3 times (initial + 2 revisions), but this is a safety cap \u2014 not a target. Review your output and call `complete` if satisfied. Revise only for critical flaws \u2014 structural errors, missing requirements, or broken logic that would cause downstream failure.\n\n**PROHIBITIONS**:\n- \u274C NEVER call `write` or `complete` in parallel with preliminary requests\n- \u274C NEVER call `complete` before submitting at least one `write`\n- \u274C NEVER ask for user permission or present a plan\n- \u274C NEVER respond with text when all requirements are met\n- \u274C NEVER include DTOs other than the one you were asked to analyze\n\n## 2. Chain of Thought: `thinking` Field\n\n```typescript\n// Preliminary - state what's missing\nthinking: \"Need database schema to verify DTO-to-table mapping.\"\n\n// Write - explain your plan decision\nthinking: \"IShoppingSale maps to shopping_sales. Transformable.\"\n\n// Revise (if resubmitting)\nthinking: \"Previous submission had wrong schema name. Correcting to shopping_sales.\"\n\n// Complete - finalize the loop\nthinking: \"Plan is correct. IShoppingSale maps to shopping_sales.\"\n```\n\n## 3. Transformable Criteria\n\nA DTO is **transformable** if ALL conditions met:\n- \u2705 **Read DTO**: Used for API responses (not request parameters)\n- \u2705 **DB-backed**: Data comes directly from database queries\n- \u2705 **Direct mapping**: The DTO structure maps to one primary database table\n\n**Key Hint**: Check `x-autobe-database-schema` in the DTO schema - it contains the mapped table name when present.\n\n| Transformable Patterns | Non-Transformable Patterns |\n|----------------------|--------------------------|\n| `IShoppingSale` (entity) | `IPage.IRequest` (request param) |\n| `IShoppingSale.ISummary` (summary) | `IPageIShoppingSale` (pagination wrapper) |\n| `IBbsArticle.IInvert` (invert view) | `IAuthorizationToken` (business logic) |\n\n## 4. Output Format\n\n```typescript\n// Step 1: Submit plan (can repeat to revise)\nexport namespace IAutoBeRealizeTransformerPlanApplication {\n export interface IWrite {\n type: \"write\";\n plans: IPlan[]; // Exactly ONE entry\n }\n\n export interface IPlan {\n dtoTypeName: string; // Given DTO type name\n thinking: string; // Decision reasoning\n databaseSchemaName: string | null; // Table name or null\n }\n}\n\n// Step 2: Confirm finalization (after at least one write)\nexport interface IAutoBePreliminaryComplete {\n type: \"complete\";\n}\n```\n\n## 5. Plan Examples\n\n### Transformable DTO\n\n```typescript\n// Step 1: Submit plan\nprocess({\n thinking: \"IShoppingSale maps to shopping_sales. Transformable.\",\n request: {\n type: \"write\",\n plans: [{\n dtoTypeName: \"IShoppingSale\",\n thinking: \"Transforms shopping_sales with category and tags relations\",\n databaseSchemaName: \"shopping_sales\"\n }]\n }\n});\n\n// Step 2: Finalize\nprocess({\n thinking: \"Plan is correct. IShoppingSale \u2192 shopping_sales.\",\n request: { type: \"complete\" }\n});\n```\n\n### Non-Transformable DTO\n\n```typescript\n// Step 1: Submit plan\nprocess({\n thinking: \"IPage.IRequest is pagination parameter. Non-transformable.\",\n request: {\n type: \"write\",\n plans: [{\n dtoTypeName: \"IPage.IRequest\",\n thinking: \"Pagination parameter, not database-backed\",\n databaseSchemaName: null\n }]\n }\n});\n\n// Step 2: Finalize\nprocess({\n thinking: \"Plan is correct. IPage.IRequest is non-transformable.\",\n request: { type: \"complete\" }\n});\n```\n\n## 6. Common Mistakes\n\n| Mistake | Wrong | Correct |\n|---------|-------|---------|\n| Multiple DTOs | `plans: [{...}, {...}]` | `plans: [{ /* one entry */ }]` |\n| DTO name as table | `databaseSchemaName: \"IShoppingSale\"` | `databaseSchemaName: \"shopping_sales\"` |\n| Wrong null handling | `databaseSchemaName: \"\"` | `databaseSchemaName: null` |\n\n## 7. Final Checklist\n\n### DTO Analysis\n- [ ] Given DTO type analyzed\n- [ ] Transformable criteria checked (Read DTO + DB-backed + Direct mapping)\n\n### Plan Completeness\n- [ ] Plan contains exactly ONE entry\n- [ ] `dtoTypeName` matches given DTO\n- [ ] `databaseSchemaName` correct (table name or null)\n- [ ] `thinking` explains the decision\n\n**REMEMBER**: Return ONE plan entry for the given DTO. Nested DTOs are analyzed separately." /* AutoBeSystemPromptConstant.REALIZE_TRANSFORMER_PLAN */, }, ...props.preliminary.getHistories(), { id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), type: "assistantMessage", text: utils_1.StringUtil.trim ` I understand the task. I need to analyze the given DTO type "${props.dtoTypeName}" and determine if it needs a transformer. **My approach**: 1. Analyze the DTO to determine if it's transformable or not 2. Generate a plan with ONE entry for this DTO **For transformable DTOs**: Set databaseSchemaName to actual database table name **For non-transformable DTOs**: Set databaseSchemaName to null I will return exactly ONE plan entry for the given DTO. `, }, ], userMessage: utils_1.StringUtil.trim ` Analyze the DTO type "${props.dtoTypeName}" and create a transformer plan entry. **Your task**: 1. Determine if this DTO is transformable (maps to database table) or non-transformable 2. Generate a plan with exactly ONE entry for this DTO **Remember**: - Your plan must contain exactly ONE entry for "${props.dtoTypeName}" - Transformable DTOs: Set databaseSchemaName to actual database table name - Non-transformable DTOs: Set databaseSchemaName to null - Do NOT include other DTOs in your plan Create the plan for this DTO now. `, }; }; exports.transformRealizeTransformerPlanHistory = transformRealizeTransformerPlanHistory; //# sourceMappingURL=transformRealizeTransformerPlanHistory.js.map