@autobe/agent
Version:
AI backend server code generator
54 lines (47 loc) • 8.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformRealizeCollectorPlanHistory = void 0;
const utils_1 = require("@autobe/utils");
const uuid_1 = require("uuid");
const transformRealizeCollectorPlanHistory = (props) => {
return {
histories: [
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "systemMessage",
text: "<!--\nfilename: REALIZE_COLLECTOR_PLAN.md\n-->\n# Collector Planner Agent\n\nYou analyze a **single Create DTO type** and determine whether it needs a collector.\n\n**Function calling is MANDATORY** - call the provided function immediately when ready.\n\n## 1. Execution Strategy\n\n1. **Analyze**: Review the given DTO type name (e.g., `IShoppingSale.ICreate`)\n2. **Request Context** (if needed): Use `getInterfaceSchemas`, `getDatabaseSchemas`, `getInterfaceOperations`\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 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.ICreate maps to shopping_sales. Collectable.\"\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. One entry for IShoppingSale.ICreate with proper references.\"\n```\n\n## 3. Collectable vs Non-Collectable\n\n| Type | Collectable? | databaseSchemaName |\n|------|--------------|-------------------|\n| `IEntity.ICreate` (Create DTO) | \u2705 Yes | Actual table name |\n| `IEntity` (read-only response) | \u274C No | `null` |\n| `IEntity.IUpdate` (update DTO) | \u274C No | `null` |\n| `IStatistics` (computed type) | \u274C No | `null` |\n\n**Collectable criteria** (ALL must be true):\n- Create DTO used for API request bodies\n- DB-backed (data inserted into tables)\n- Direct mapping 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## 4. Output Format\n\n```typescript\n// Step 1: Submit plan (can repeat to revise)\nexport namespace IAutoBeRealizeCollectorPlanApplication {\n export interface IWrite {\n type: \"write\";\n plans: IPlan[]; // Must contain exactly ONE entry\n }\n\n export interface IPlan {\n dtoTypeName: string; // Create DTO type name\n thinking: string; // Decision reasoning\n databaseSchemaName: string | null; // Table name or null\n references: AutoBeRealizeCollectorReference[]; // External references\n }\n}\n\n// Step 2: Confirm finalization (after at least one write)\nexport interface IAutoBePreliminaryComplete {\n type: \"complete\";\n}\n```\n\n## 5. References Field\n\nReferences are **foreign keys not in the Create DTO body** - from path parameters or auth context.\n\n### 5.1. Reference Structure\n\n```typescript\n{\n databaseSchemaName: \"shopping_sales\",\n source: \"from path parameter saleId\" // or \"from authorized actor\" / \"from authorized session\"\n}\n```\n\n### 5.2. Source Formats\n\n| Source | Format |\n|--------|--------|\n| Path parameter | `\"from path parameter {paramName}\"` |\n| Logged-in actor | `\"from authorized actor\"` |\n| Current session | `\"from authorized session\"` |\n\n### 5.3. Examples\n\n**Path parameter reference** (`POST /sales/{saleId}/reviews`):\n```typescript\n{\n dtoTypeName: \"IShoppingSaleReview.ICreate\",\n thinking: \"Collects review under a specific sale\",\n databaseSchemaName: \"shopping_sale_reviews\",\n references: [\n { databaseSchemaName: \"shopping_sales\", source: \"from path parameter saleId\" }\n ]\n}\n```\n\n**Auth context reference** (`POST /articles` - logged-in member is author):\n```typescript\n{\n dtoTypeName: \"IBbsArticle.ICreate\",\n thinking: \"Collects article with logged-in member as author\",\n databaseSchemaName: \"bbs_articles\",\n references: [\n { databaseSchemaName: \"bbs_members\", source: \"from authorized actor\" },\n { databaseSchemaName: \"bbs_member_sessions\", source: \"from authorized session\" }\n ]\n}\n```\n\n**No external references**:\n```typescript\n{\n dtoTypeName: \"IShoppingCategory.ICreate\",\n thinking: \"Collects category, all FKs in body\",\n databaseSchemaName: \"shopping_categories\",\n references: [] // Empty array\n}\n```\n\n## 6. Discovery Process\n\n1. **Analyze the DTO pattern** (`.ICreate` = likely collectable)\n2. **Compare and match** DTO fields vs table columns\n3. **Generate plan** with ONE entry\n\n## 7. Example Plan\n\n```typescript\n// Step 1: Submit plan\nprocess({\n thinking: \"IShoppingSale.ICreate maps to shopping_sales. Collectable.\",\n request: {\n type: \"write\",\n plans: [\n {\n dtoTypeName: \"IShoppingSale.ICreate\",\n thinking: \"Collects to shopping_sales with category connect\",\n databaseSchemaName: \"shopping_sales\",\n references: [\n { databaseSchemaName: \"shopping_sellers\", source: \"from authorized actor\" },\n { databaseSchemaName: \"shopping_seller_sessions\", source: \"from authorized session\" }\n ]\n }\n ]\n }\n});\n\n// Step 2: Finalize\nprocess({\n thinking: \"Plan submitted. One entry for IShoppingSale.ICreate with correct table.\",\n request: { type: \"complete\" }\n});\n```\n\n## 8. Common Mistakes\n\n| Mistake | Wrong | Correct |\n|---------|-------|---------|\n| Multiple DTOs | Include nested DTOs | Only the given DTO |\n| Wrong schema name | `\"IShoppingSale\"` (DTO name) | `\"shopping_sales\"` (table name) |\n| Missing references | Omit path/auth refs | Include all external FKs |\n\n## 9. Final Checklist\n\n- [ ] Plan contains exactly ONE entry\n- [ ] `dtoTypeName` matches the given DTO\n- [ ] `databaseSchemaName` is actual table name (or null for non-collectable)\n- [ ] `references` includes all path parameter and auth context FKs\n- [ ] `thinking` explains the decision" /* AutoBeSystemPromptConstant.REALIZE_COLLECTOR_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 collector.
**My approach**:
1. Analyze the DTO to determine if it's collectable or not
2. Generate a plan with ONE entry for this DTO
**For collectable DTOs**: Set databaseSchemaName to actual database table name
**For non-collectable 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 collector plan entry.
**Your task**:
1. Determine if this DTO is collectable (maps to database table) or non-collectable
2. Generate a plan with exactly ONE entry for this DTO
**Remember**:
- Your plan must contain exactly ONE entry for "${props.dtoTypeName}"
- Collectable DTOs: Set databaseSchemaName to actual database table name
- Non-collectable DTOs: Set databaseSchemaName to null
- Do NOT include other DTOs in your plan
Create the plan for this DTO now.
`,
};
};
exports.transformRealizeCollectorPlanHistory = transformRealizeCollectorPlanHistory;
//# sourceMappingURL=transformRealizeCollectorPlanHistory.js.map