@autobe/agent
Version:
AI backend server code generator
122 lines (98 loc) • 11.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformAnalyzeWriteUnitHistory = void 0;
const utils_1 = require("@autobe/utils");
const uuid_1 = require("uuid");
const FixedAnalyzeTemplate_1 = require("../structures/FixedAnalyzeTemplate");
const transformAnalyzeWriteUnitHistory = (ctx, props) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const moduleSection = props.moduleEvent.moduleSections[props.moduleIndex];
// Find the matching file template and expand units for this module
const expandedTemplate = (0, FixedAnalyzeTemplate_1.buildFixedAnalyzeExpandedTemplate)(((_a = props.scenario.features) !== null && _a !== void 0 ? _a : []));
const fileIndex = expandedTemplate.findIndex((t) => t.filename === props.file.filename);
const fileTemplate = fileIndex >= 0 ? expandedTemplate[fileIndex] : undefined;
const moduleTemplate = fileTemplate === null || fileTemplate === void 0 ? void 0 : fileTemplate.modules[props.moduleIndex];
const expandedUnits = moduleTemplate
? (0, FixedAnalyzeTemplate_1.expandFixedAnalyzeTemplateUnits)(moduleTemplate, props.scenario.entities, props.scenario.actors)
: [];
return {
histories: [
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "systemMessage",
text: "<!--\nfilename: ANALYZE_WRITE_UNIT.md\n-->\n# Unit Content Writer\n\nYou are the **Unit Content Writer** \u2014 Step 2 in a 3-step process:\n1. Module (#) \u2192 Done\n2. **Unit (##)** \u2192 You are here\n3. Section (###) \u2192 Next\n\n**Your Job**: Write `content` (5-15 sentences) and `keywords` (7-18 anchors) for each pre-defined unit.\n\n**Your Mindset**: Describe business operations from a user perspective.\n\n**Boundary**: Do not define database schemas or API endpoints. Those belong to later phases.\n\n---\n\n## 1. Execution Strategy\n\n1. **Analyze**: Review provided module index, unit titles, and purposes\n2. **Write**: Call `process({ request: { type: \"write\", ... } })` with unit sections\n3. **Revise** (if needed): Submit another `write` to refine\n4. **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\n## 2. Chain of Thought: `thinking` Field\n\n```typescript\n// Write - summarize what you are submitting\nthinking: \"Wrote content and keywords for all units in module 0.\"\n\n// Revise (if resubmitting) - explain what changed\nthinking: \"Previous write had vague keywords. Using more specific business phrases.\"\n\n// Complete - finalize the loop\nthinking: \"All units have proper content and keywords.\"\n```\n\n## 3. Output Format\n\n```typescript\n// Step 1: Submit unit sections (can repeat to revise)\nprocess({\n thinking: \"Wrote content and keywords for all units in this module.\",\n request: {\n type: \"write\",\n moduleIndex: 0,\n unitSections: [\n {\n title: \"Unit Title Here\", // Fixed by template\n purpose: \"Unit purpose here\", // Fixed by template\n content: \"Describe what users can do in detail based on the original requirements. Cover the main operations, key business rules, which actors are involved, and what happens on errors. Do not include database field names or API specifications.\",\n keywords: [\n \"descriptive phrase from user requirements\",\n \"another specific business operation\",\n \"error scenario phrase\"\n ]\n }\n ]\n }\n});\n\n// Step 2: Finalize the loop (after at least one write)\nprocess({\n thinking: \"All units have proper content and keywords. Submitted unit sections for module 0 with content and keywords. Validation passed.\",\n request: { type: \"complete\" }\n});\n```\n\n---\n\n## 4. Content Guidelines\n\nWrite **5-15 sentences** covering:\n- What this area does\n- Which actors interact and how\n- Key business rules\n- Error scenarios\n\n**Good**: \"Users can create an item with a title and optional description. Title is required. The system rejects requests without a title.\"\n\n**Bad**: \"This unit details the item creation process...\" \u2014 skip meta-descriptions.\n\n---\n\n## 5. Keywords\n\nShort phrases that capture what this unit covers. Used to guide section writing.\n\n**Good keywords**: \"item creation flow\", \"ownership rules\", \"draft to published\", \"access denied scenarios\"\n\n**Bad keywords**: \"login\", \"validation\", \"permissions\" \u2014 too vague.\n\n---\n\n## 6. Rules\n\n1. **Unit titles/purposes are fixed** \u2014 only write content and keywords\n2. **No duplicates** \u2014 each topic in exactly one unit\n3. **Business language** \u2014 describe what users can do, not how it's implemented\n4. **English only**\n5. **No invented features** \u2014 only generate keywords for features explicitly stated or directly implied by the original user requirements. Do not add common industry features (e.g., email verification, rate limiting, password recovery) unless the user mentioned them.\n\n---\n\n## 7. Final Checklist\n\n**Content Quality:**\n- [ ] 5-15 sentences per unit\n- [ ] 7-18 keywords per unit\n- [ ] Keywords are descriptive phrases, not technical terms\n- [ ] Content describes business operations from user perspective\n- [ ] Every keyword is traceable to the original user requirements\n- [ ] No industry-standard features added that the user did not mention\n\n**Prohibited Content (DO NOT write any of these):**\n- [ ] NO database schemas or field definitions\n- [ ] NO API endpoints or HTTP methods\n- [ ] NO field types (`string`, `boolean`, `integer`)\n- [ ] NO length constraints (`1-500 characters`)\n- [ ] NO technical error codes\n- [ ] NO technical field names (`passwordHash`, `isDeleted`, `isCompleted`, `userId`, `createdAt`, `deletedAt`)\n- [ ] NO camelCase identifiers \u2014 use natural language instead\n\n**Business Language Only:**\n- [ ] Describes WHAT users can do, not HOW it's implemented\n- [ ] Uses natural language, not technical specifications\n- [ ] Use plain words: \"due date\", \"completion status\", \"owner\" \u2014 NOT `dueDate`, `isCompleted`, `ownerId`\n\n**Function Call:**\n- [ ] Submit unit sections via `write` (revise only for critical flaws)\n- [ ] Finalize via `complete` after last `write`" /* AutoBeSystemPromptConstant.ANALYZE_WRITE_UNIT */,
},
...((_c = (_b = props.preliminary) === null || _b === void 0 ? void 0 : _b.getHistories()) !== null && _c !== void 0 ? _c : []),
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "assistantMessage",
text: utils_1.StringUtil.trim `
## Language
The language of the document is ${JSON.stringify((_d = props.scenario.language) !== null && _d !== void 0 ? _d : "en-US")}.
## Original User Requirements (READ-ONLY Reference)
Below is the original user input. Your unit sections MUST cover features described below
that fall within this module's scope. Do NOT invent features not stated or directly implied.
${ctx
.histories()
.filter((h) => h.type === "userMessage")
.flatMap((h) => h.type === "userMessage"
? h.contents.filter((c) => c.type === "text").map((c) => c.text)
: [])
.join("\n\n---\n\n")}
## Document Context
**Document Title**: ${props.moduleEvent.title}
**Document Summary**: ${props.moduleEvent.summary}
**File**: ${props.file.filename}
**File Scope**: ${(_e = fileTemplate === null || fileTemplate === void 0 ? void 0 : fileTemplate.description) !== null && _e !== void 0 ? _e : props.file.reason}
## Domain Entities Reference
${props.scenario.entities.map((e) => `- **${e.name}**: ${e.attributes.slice(0, 3).join(", ")}`).join("\n")}
Units MUST reference ONLY entities listed above.
## Approved Module Section Structure
Here are all the module sections for context:
${props.moduleEvent.moduleSections
.map((section, index) => `
### ${index + 1}. ${section.title}
**Purpose**: ${section.purpose}
`)
.join("\n")}
## Your Task: Write Content for Module Section ${props.moduleIndex + 1}
**Module Section**: ${(_f = moduleSection === null || moduleSection === void 0 ? void 0 : moduleSection.title) !== null && _f !== void 0 ? _f : "Unknown"}
**Module Index**: ${props.moduleIndex}
**Purpose**: ${(_g = moduleSection === null || moduleSection === void 0 ? void 0 : moduleSection.purpose) !== null && _g !== void 0 ? _g : "Unknown"}
### Pre-defined Unit Sections (FIXED — do NOT change titles or purposes)
The following unit sections are pre-defined by the template. You MUST write
\`content\` (5-15 sentences) and \`keywords\` (7-18 structured anchors) for EACH unit below.
Do NOT add, remove, or rename any units.
${expandedUnits
.map((unit, index) => `
**Unit ${index + 1}**: ${unit.titlePattern}
- **Purpose**: ${unit.purposePattern}
- **Template Keywords** (use as starting points — only add keywords traceable to the original user requirements above): ${unit.keywords.join(", ")}
`)
.join("\n")}
## CRITICAL: Value Consistency
**You MUST use the EXACT same values defined in the module section content above.**
If the module section says "10MB file limit", you MUST use 10MB, not 25MB or 5MB.
Any deviation will cause the review to REJECT your output.
## CRITICAL: No Duplication with Other Module Sections
The module sections listed above define clear boundaries. Your unit sections
for "${(_h = moduleSection === null || moduleSection === void 0 ? void 0 : moduleSection.title) !== null && _h !== void 0 ? _h : "Unknown"}" MUST NOT overlap with content belonging
to other module sections.
Write content and keywords for all ${expandedUnits.length} pre-defined unit sections.
${props.feedback
? `
## Previous Attempt Feedback
Your previous attempt was rejected with the following feedback. Please address these issues:
${props.feedback}
`
: ""}
`,
},
],
userMessage: `Write content and keywords for the ${expandedUnits.length} pre-defined unit sections in module "${(_j = moduleSection === null || moduleSection === void 0 ? void 0 : moduleSection.title) !== null && _j !== void 0 ? _j : "Unknown"}".`,
};
};
exports.transformAnalyzeWriteUnitHistory = transformAnalyzeWriteUnitHistory;
//# sourceMappingURL=transformAnalyzeWriteUnitHistory.js.map