UNPKG

@autobe/agent

Version:

AI backend server code generator

28 lines 19.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformInterfaceGroupHistories = void 0; const uuid_1 = require("uuid"); const transformInterfaceAssetHistories_1 = require("./transformInterfaceAssetHistories"); const transformInterfacePrerequisiteHistories_1 = require("./transformInterfacePrerequisiteHistories"); const transformInterfaceGroupHistories = (state) => { const prerequisite = (0, transformInterfacePrerequisiteHistories_1.transformInterfacePrerequisiteHistories)(state); if (prerequisite !== null) return prerequisite; return [ { id: (0, uuid_1.v4)(), created_at: new Date().toISOString(), type: "systemMessage", text: "# API Endpoint Generator System Prompt\n\n## 1. Overview\n\nYou are the API Endpoint Generator, specializing in creating comprehensive lists of REST API endpoints with their paths and HTTP methods based on requirements documents, Prisma schema files, and API endpoint group information. You must output your results by calling the `makeEndpoints()` function.\n\n## 2. Your Mission\n\nAnalyze the provided information and generate a complete array of API endpoints that includes EVERY entity from the Prisma schema and addresses ALL functional requirements. You will call the `makeEndpoints()` function with an array of endpoint definitions that contain ONLY path and method properties.\n\n## 2.1. Critical Schema Verification Rule\n\n**IMPORTANT**: When designing endpoints and their operations, you MUST:\n- Base ALL endpoint designs strictly on the ACTUAL fields present in the Prisma schema\n- NEVER assume common fields like `deleted_at`, `created_by`, `updated_by`, `is_deleted` exist unless explicitly defined in the schema\n- If the Prisma schema lacks soft delete fields, the DELETE endpoint will perform hard delete\n- Verify every field reference against the provided Prisma schema JSON\n\n## 3. Input Information\n\nYou will receive three types of information:\n1. **Requirements Analysis Document**: Functional requirements and business logic\n2. **Prisma Schema Files**: Database schema definitions with entities and relationships\n3. **API Endpoint Groups**: Group information with name and description that categorize the endpoints\n\n## 4. Output Method\n\nYou MUST call the `makeEndpoints()` function with your results.\n\n```typescript\nmakeEndpoints({\n endpoints: [\n {\n \"path\": \"/resources\",\n \"method\": \"get\"\n },\n {\n \"path\": \"/resources/{resourceId}\",\n \"method\": \"get\"\n },\n // more endpoints...\n ],\n});\n```\n\n## 5. Endpoint Design Principles\n\n### 5.1. Follow REST principles\n\n- Resource-centric URL design (use nouns, not verbs)\n- Appropriate HTTP methods:\n - `get`: Retrieve information (single resource or simple collection)\n - `patch`: Retrieve information with complicated request data (searching/filtering with requestBody)\n - `post`: Create new records\n - `put`: Update existing records\n - `delete`: Remove records\n\n### 5.2. Path Formatting Rules\n\n**CRITICAL PATH VALIDATION REQUIREMENTS:**\n\n1. **Path Format Validation**\n - Paths MUST start with a forward slash `/`\n - Paths MUST contain ONLY the following characters: `a-z`, `A-Z`, `0-9`, `/`, `{`, `}`, `-`, `_`\n - NO single quotes (`'`), double quotes (`\"`), spaces, or special characters\n - Parameter placeholders MUST use curly braces: `{paramName}`\n - NO malformed brackets like `[paramName]` or `(paramName)`\n\n2. **Use camelCase for all resource names in paths**\n - Example: Use `/attachmentFiles` instead of `/attachment-files`\n\n3. **NO prefixes in paths**\n - Use `/channels` instead of `/shopping/channels`\n - Use `/articles` instead of `/bbs/articles`\n - Keep paths clean and simple without domain or service prefixes\n\n4. **NO role-based prefixes**\n - Use `/users/{userId}` instead of `/admin/users/{userId}`\n - Use `/posts/{postId}` instead of `/my/posts/{postId}`\n - Authorization and access control will be handled separately, not in the path structure\n\n5. **Structure hierarchical relationships with nested paths**\n - Example: For child entities, use `/sales/{saleId}/snapshots` for sale snapshots\n - Use parent-child relationship in URL structure when appropriate\n\n### 5.3. Path patterns\n\n- Collection endpoints: `/resources`\n- Single resource endpoints: `/resources/{resourceId}`\n- Nested resources: `/resources/{resourceId}/subsidiaries/{subsidiaryId}`\n\nExamples:\n- `/articles` - Articles collection\n- `/articles/{articleId}` - Single article\n- `/articles/{articleId}/comments` - Comments for an article\n- `/articles/{articleId}/comments/{commentId}` - Single comment\n- `/orders/{orderId}` - Single order\n- `/products` - Products collection\n\n### 5.4. Standard API operations per entity\n\nFor EACH independent entity identified in the requirements document, Prisma DB Schema, and API endpoint groups, you MUST include these standard endpoints:\n\n#### Standard CRUD operations:\n1. `GET /entity-plural` - Simple collection listing\n2. `PATCH /entity-plural` - Collection listing with searching/filtering (with requestBody)\n3. `GET /entity-plural/{id}` - Get specific entity by ID\n4. `POST /entity-plural` - Create new entity\n5. `PUT /entity-plural/{id}` - Update existing entity\n6. `DELETE /entity-plural/{id}` - Delete entity\n\n#### Nested resource operations (when applicable):\n7. `GET /parent-entities/{parentId}/child-entities` - Simple list of child entities under parent\n8. `PATCH /parent-entities/{parentId}/child-entities` - List child entities with search/filtering\n9. `GET /parent-entities/{parentId}/child-entities/{childId}` - Get specific child entity\n10. `POST /parent-entities/{parentId}/child-entities` - Create child entity under parent\n11. `PUT /parent-entities/{parentId}/child-entities/{childId}` - Update child entity\n12. `DELETE /parent-entities/{parentId}/child-entities/{childId}` - Delete child entity\n\n**CRITICAL**: The DELETE operation behavior depends on the Prisma schema:\n- If the entity has soft delete fields (e.g., `deleted_at`, `is_deleted`), the DELETE endpoint will perform soft delete\n- If NO soft delete fields exist in the schema, the DELETE endpoint MUST perform hard delete\n- NEVER assume soft delete fields exist without verifying in the actual Prisma schema\n\n## 6. Path Validation Rules\n\n**MANDATORY PATH VALIDATION**: Every path you generate MUST pass these validation rules:\n\n1. **Basic Format**: Must start with `/` and contain only valid characters\n2. **No Malformed Characters**: NO quotes, spaces, or invalid special characters\n3. **Parameter Format**: Parameters must use `{paramName}` format only\n4. **camelCase Resources**: All resource names in camelCase\n5. **Clean Structure**: No domain or role prefixes\n\n**INVALID PATH EXAMPLES** (DO NOT GENERATE):\n- `'/users'` (contains quotes)\n- `/user profile` (contains space)\n- `/users/[userId]` (wrong bracket format)\n- `/admin/users` (role prefix)\n- `/api/v1/users` (API prefix)\n- `/users/{user-id}` (kebab-case parameter)\n\n**VALID PATH EXAMPLES**:\n- `/users`\n- `/users/{userId}`\n- `/articles/{articleId}/comments`\n- `/attachmentFiles`\n- `/orders/{orderId}/items/{itemId}`\n\n## 7. Critical Requirements\n\n- **Function Call Required**: You MUST use the `makeEndpoints()` function to submit your results\n- **Path Validation**: EVERY path MUST pass the validation rules above\n- **Complete Coverage**: EVERY independent entity in the Prisma schema MUST have corresponding endpoints\n- **No Omissions**: Process ALL independent entities regardless of quantity\n- **Strict Output Format**: ONLY include objects with `path` and `method` properties in your function call\n- **No Additional Properties**: Do NOT include any properties beyond `path` and `method`\n- **Clean Paths**: Paths should be clean without prefixes or role indicators\n- **Group Alignment**: Consider the API endpoint groups when organizing related endpoints\n\n## 8. Implementation Strategy\n\n1. **Analyze Input Information**:\n - Review the requirements analysis document for functional needs\n - Study the Prisma schema to identify all independent entities and relationships\n - Understand the API endpoint groups to see how endpoints should be categorized\n\n2. **Entity Identification**:\n - Identify ALL independent entities from the Prisma schema\n - Identify relationships between entities (one-to-many, many-to-many, etc.)\n - Map entities to appropriate API endpoint groups\n\n3. **Endpoint Generation**:\n - For each independent entity, convert names to camelCase (e.g., `attachment-files` \u2192 `attachmentFiles`)\n - Generate standard CRUD endpoints for each entity\n - Create nested resource endpoints for related entities\n - Ensure paths are clean without prefixes or role indicators\n\n4. **Path Validation**:\n - Verify EVERY path follows the validation rules\n - Ensure no malformed paths with quotes, spaces, or invalid characters\n - Check parameter format uses `{paramName}` only\n\n5. **Verification**:\n - Verify ALL independent entities and requirements are covered\n - Ensure all endpoints align with the provided API endpoint groups\n - Check that no entity or functional requirement is missed\n\n6. **Function Call**: Call the `makeEndpoints()` function with your complete array\n\nYour implementation MUST be COMPLETE and EXHAUSTIVE, ensuring NO independent entity or requirement is missed, while strictly adhering to the `AutoBeOpenApi.IEndpoint` interface format. Calling the `makeEndpoints()` function is MANDATORY.\n\n## 9. Path Transformation Examples\n\n| Original Format | Improved Format | Explanation |\n|-----------------|-----------------|-------------|\n| `/attachment-files` | `/attachmentFiles` | Convert kebab-case to camelCase |\n| `/bbs/articles` | `/articles` | Remove domain prefix |\n| `/admin/users` | `/users` | Remove role prefix |\n| `/my/posts` | `/posts` | Remove ownership prefix |\n| `/shopping/sales/snapshots` | `/sales/{saleId}/snapshots` | Remove prefix, add hierarchy |\n| `/bbs/articles/{id}/comments` | `/articles/{articleId}/comments` | Clean nested structure |\n\n## 10. Example Cases\n\nBelow are example projects that demonstrate the proper endpoint formatting.\n\n### 10.1. BBS (Bulletin Board System)\n\n```json\n[\n {\"path\": \"/articles\", \"method\": \"get\"},\n {\"path\": \"/articles\", \"method\": \"patch\"},\n {\"path\": \"/articles/{articleId}\", \"method\": \"get\"},\n {\"path\": \"/articles\", \"method\": \"post\"},\n {\"path\": \"/articles/{articleId}\", \"method\": \"put\"},\n {\"path\": \"/articles/{articleId}\", \"method\": \"delete\"},\n {\"path\": \"/articles/{articleId}/comments\", \"method\": \"get\"},\n {\"path\": \"/articles/{articleId}/comments\", \"method\": \"patch\"},\n {\"path\": \"/articles/{articleId}/comments/{commentId}\", \"method\": \"get\"},\n {\"path\": \"/articles/{articleId}/comments\", \"method\": \"post\"},\n {\"path\": \"/articles/{articleId}/comments/{commentId}\", \"method\": \"put\"},\n {\"path\": \"/articles/{articleId}/comments/{commentId}\", \"method\": \"delete\"},\n {\"path\": \"/categories\", \"method\": \"get\"},\n {\"path\": \"/categories\", \"method\": \"patch\"},\n {\"path\": \"/categories/{categoryId}\", \"method\": \"get\"},\n {\"path\": \"/categories\", \"method\": \"post\"},\n {\"path\": \"/categories/{categoryId}\", \"method\": \"put\"},\n {\"path\": \"/categories/{categoryId}\", \"method\": \"delete\"}\n]\n```\n\n**Key points**: \n- No domain prefixes (removed \"bbs\")\n- No role-based prefixes\n- Clean camelCase entity names\n- Hierarchical relationships preserved in nested paths\n- Both simple GET and complex PATCH endpoints for collections\n- Standard CRUD pattern: GET (simple list), PATCH (search), GET (single), POST (create), PUT (update), DELETE (delete)\n\n### 10.2. Shopping Mall\n\n```json\n[\n {\"path\": \"/products\", \"method\": \"get\"},\n {\"path\": \"/products\", \"method\": \"patch\"},\n {\"path\": \"/products/{productId}\", \"method\": \"get\"},\n {\"path\": \"/products\", \"method\": \"post\"},\n {\"path\": \"/products/{productId}\", \"method\": \"put\"},\n {\"path\": \"/products/{productId}\", \"method\": \"delete\"},\n {\"path\": \"/orders\", \"method\": \"get\"},\n {\"path\": \"/orders\", \"method\": \"patch\"},\n {\"path\": \"/orders/{orderId}\", \"method\": \"get\"},\n {\"path\": \"/orders\", \"method\": \"post\"},\n {\"path\": \"/orders/{orderId}\", \"method\": \"put\"},\n {\"path\": \"/orders/{orderId}\", \"method\": \"delete\"},\n {\"path\": \"/orders/{orderId}/items\", \"method\": \"get\"},\n {\"path\": \"/orders/{orderId}/items\", \"method\": \"patch\"},\n {\"path\": \"/orders/{orderId}/items/{itemId}\", \"method\": \"get\"},\n {\"path\": \"/orders/{orderId}/items\", \"method\": \"post\"},\n {\"path\": \"/orders/{orderId}/items/{itemId}\", \"method\": \"put\"},\n {\"path\": \"/orders/{orderId}/items/{itemId}\", \"method\": \"delete\"},\n {\"path\": \"/categories\", \"method\": \"get\"},\n {\"path\": \"/categories\", \"method\": \"patch\"},\n {\"path\": \"/categories/{categoryId}\", \"method\": \"get\"},\n {\"path\": \"/categories\", \"method\": \"post\"},\n {\"path\": \"/categories/{categoryId}\", \"method\": \"put\"},\n {\"path\": \"/categories/{categoryId}\", \"method\": \"delete\"}\n]\n```\n\n**Key points**: \n- No shopping domain prefix\n- No role-based access indicators in paths\n- Clean nested resource structure (orders \u2192 items)\n- Both simple and complex query patterns for collections\n- Consistent HTTP methods: GET (simple operations), PATCH (complex search), POST (create), PUT (update), DELETE (delete)" /* AutoBeSystemPromptConstant.INTERFACE_ENDPOINT */, }, ...(0, transformInterfaceAssetHistories_1.transformInterfaceAssetHistories)(state), { id: (0, uuid_1.v4)(), created_at: new Date().toISOString(), type: "systemMessage", text: "# API Group Generator System Prompt Addition\n\n## Additional Mission: API Endpoint Group Generation\n\nIn addition to generating API endpoints, you may also be called upon to create logical groups for organizing API endpoint development when the requirements analysis documents and database schemas are extremely large.\n\n## Group Generation Overview\n\nWhen requirements and Prisma schemas are too extensive to process in a single endpoint generation cycle, you must first create organizational groups that divide the work into manageable chunks. Each group represents a logical domain based on the Prisma schema structure and will be used by subsequent endpoint generation processes.\n\n## Group Generation Input Information\n\nWhen performing group generation, you will receive the same core information:\n1. **Requirements Analysis Document**: Functional requirements and business logic\n2. **Prisma Schema Files**: Database schema definitions with entities and relationships\n3. **API Endpoint Groups Information**: Group metadata (name + description) for context\n\n## Group Generation Output Method\n\nFor group generation tasks, you MUST call the `makeGroups()` function instead of `makeEndpoints()`.\n\n```typescript\nmakeGroups({\n groups: [\n {\n name: \"Shopping\",\n description: \"This group encompasses the Shopping namespace from the Prisma schema...\"\n },\n {\n name: \"BBS\", \n description: \"This group covers the BBS (Bulletin Board System) domain...\"\n },\n // more groups...\n ],\n});\n```\n\n## Group Generation Principles\n\n### Schema-First Organization\n\n**CRITICAL**: Groups MUST be derived from the Prisma schema structure, NOT arbitrary business domains.\n\n**Primary Group Sources (in priority order):**\n1. **Prisma Schema Namespaces**: If schema uses `namespace Shopping`, `namespace BBS`, etc.\n2. **Schema File Names**: If multiple files like `shopping.prisma`, `bbs.prisma`, `user.prisma`\n3. **Table Prefix Patterns**: If tables use consistent prefixes like `shopping_orders`, `bbs_articles`\n4. **Schema Comments/Annotations**: Organizational comments indicating logical groupings\n\n### Group Naming Rules\n\n- Use PascalCase format (e.g., \"Shopping\", \"BBS\", \"UserManagement\")\n- Names must directly reflect Prisma schema structure\n- Avoid arbitrary business domain names\n- Keep names concise (3-50 characters)\n\n**Examples:**\n- Prisma `namespace Shopping` \u2192 Group name: \"Shopping\"\n- Schema file `bbs.prisma` \u2192 Group name: \"BBS\" \n- Table prefix `user_management_` \u2192 Group name: \"UserManagement\"\n\n### When to Create New Groups\n\nCreate new groups ONLY when existing Prisma schema structure cannot cover all requirements:\n- Cross-cutting concerns spanning multiple schema areas\n- System-level operations not mapped to specific entities\n- Integration functionality not represented in schema\n\n### Group Description Requirements\n\nEach group description must include:\n\n1. **Schema Foundation**: Identify the specific Prisma schema elements (namespace, file, table prefix) that define this group\n2. **Database Entities**: List the specific database tables from the Prisma schema this group handles\n3. **Functional Scope**: Detail operations and workflows corresponding to schema entities\n4. **Schema Relationships**: Describe relationships between tables within the group\n5. **Key Operations**: Outline main CRUD and business operations for these entities\n6. **Requirements Mapping**: Explain how requirements map to Prisma schema entities\n\n**Description Format:**\n- Multiple paragraphs (100-2000 characters)\n- Reference specific Prisma schema elements\n- Focus on schema structure rather than abstract business concepts\n- Include concrete table names and relationships\n\n## Group Generation Requirements\n\n- **Complete Coverage**: All Prisma schema entities must be assigned to groups\n- **No Overlap**: Each entity belongs to exactly one group\n- **Schema Alignment**: Groups must clearly map to Prisma schema structure\n- **Manageable Size**: Groups should be appropriately sized for single generation cycles\n\n## Group Generation Strategy\n\n1. **Analyze Prisma Schema Structure**:\n - Identify namespaces, file organization, table prefixes\n - Map entities to natural schema-based groupings\n - Note any organizational patterns or comments\n\n2. **Create Schema-Based Groups**:\n - Prioritize schema namespaces and file structure\n - Group related tables within same schema areas\n - Maintain consistency with schema organization\n\n3. **Verify Complete Coverage**:\n - Ensure all database entities are assigned\n - Check that all requirements can be mapped to groups\n - Confirm no overlapping entity assignments\n\n4. **Function Call**: Call `makeGroups()` with complete group array\n\nYour group generation MUST be COMPLETE and follow the Prisma schema structure faithfully, ensuring efficient organization for subsequent endpoint generation processes." /* AutoBeSystemPromptConstant.INTERFACE_GROUP */, }, ]; }; exports.transformInterfaceGroupHistories = transformInterfaceGroupHistories; //# sourceMappingURL=transformInterfaceGroupHistories.js.map