@autobe/agent
Version:
AI backend server code generator
88 lines (73 loc) • 6.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformAnalyzeWriteSectionPatchHistory = void 0;
const utils_1 = require("@autobe/utils");
const uuid_1 = require("uuid");
const transformAnalyzeWriteSectionPatchHistory = (_ctx, props) => {
var _a, _b, _c, _d, _e, _f;
const moduleSection = props.moduleEvent.moduleSections[props.moduleIndex];
const unitSection = props.unitEvent.unitSections[props.unitIndex];
const hasSectionTargets = props.sectionIndices != null && props.sectionIndices.length > 0;
const targetSet = hasSectionTargets ? new Set(props.sectionIndices) : null;
const previousOutputBlock = hasSectionTargets
? `The following sections were generated. Sections marked [NEEDS FIX] must be corrected.
Sections marked [APPROVED] must be returned EXACTLY as-is, character-for-character.
${props.previousSectionEvent.sectionSections
.map((s, i) => `
### Section ${i + 1}: ${s.title} ${targetSet.has(i) ? "[NEEDS FIX]" : "[APPROVED - DO NOT MODIFY]"}
${s.content}
`)
.join("\n---\n")}`
: `The following sections were generated but REJECTED by review:
${props.previousSectionEvent.sectionSections
.map((s, i) => `
### Section ${i + 1}: ${s.title}
${s.content}
`)
.join("\n---\n")}`;
const taskBlock = hasSectionTargets
? `Fix ONLY sections marked [NEEDS FIX] (section indices: ${props.sectionIndices.map((i) => i + 1).join(", ")}).
Return ALL sections (both fixed and unchanged) in the same sectionSections format.
Sections marked [APPROVED] MUST be returned EXACTLY as they appear above -- do NOT modify them.`
: `Fix ONLY the issues identified above. Return ALL sections
(both fixed and unchanged) in the same sectionSections format.
Do NOT rewrite sections that were not flagged in the feedback.`;
return {
histories: [
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "systemMessage",
text: "<!--\nfilename: ANALYZE_WRITE_SECTION_PATCH.md\n-->\n# Section Patch Agent\n\nYou are a **Section Patch Agent**. You receive a previously generated set of section sections\nthat was **REJECTED** by review, along with specific feedback.\n\n---\n\n## 1. Your Task\n\nFix ONLY the issues identified in the review feedback.\nDo NOT rewrite content that was NOT flagged.\n\n---\n\n## 2. Rules\n\n### 2.1. Preserve unchanged content\n- If a section was not mentioned in the feedback, return it **EXACTLY** as-is\n- Keep title, order, and content character-for-character\n\n### 2.2. Targeted fixes only\n- Address each feedback point specifically\n- Make the smallest change that resolves the issue\n\n### 2.3. Same output format\n- Return the complete `sectionSections` array (both fixed and unchanged sections)\n- Do NOT change the JSON structure or field names\n\n### 2.4. No new issues\n- Do not introduce new requirements or new topics\n- Do not alter formatting or style of unflagged sections\n\n---\n\n## 3. Section-Level Targeting\n\nWhen specific sections are marked `[NEEDS FIX]` and others `[APPROVED - DO NOT MODIFY]`:\n\n1. **Fix ONLY `[NEEDS FIX]` sections** \u2014 Apply the review feedback to resolve issues\n2. **Return `[APPROVED]` sections EXACTLY as-is** \u2014 Copy them character-for-character\n3. **Same array length** \u2014 The output `sectionSections` array must have the same number of entries\n4. **Same order** \u2014 Maintain the original section ordering\n\n---\n\n## 4. Anti-Patterns (PROHIBITED)\n\n- Rewriting sections that were not flagged\n- Adding new content beyond what feedback requires\n- Changing formatting/style of unflagged sections\n- \"Improving\" content that wasn't criticized\n\n---\n\n## 5. Output\n\nReturn a full `process({ request: { type: \"write\", ... } })` call that includes **all**\nsection sections, with only the necessary edits applied.\n\n---\n\n## 6. Final Checklist\n\n**Patch Quality:**\n- [ ] Only flagged sections are modified\n- [ ] Approved sections are returned exactly as-is\n- [ ] Same array length and order maintained\n- [ ] Feedback issues are fully addressed\n\n**Prohibited Content (MUST NOT introduce):**\n- [ ] NO database schemas or field definitions\n- [ ] NO API endpoints or HTTP methods\n- [ ] NO technical error codes\n- [ ] NO implementation details\n\n**Business Language:**\n- [ ] Fixed content uses natural language\n- [ ] No technical specifications introduced" /* AutoBeSystemPromptConstant.ANALYZE_WRITE_SECTION_PATCH */,
},
...((_b = (_a = props.preliminary) === null || _a === void 0 ? void 0 : _a.getHistories()) !== null && _b !== void 0 ? _b : []),
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "assistantMessage",
text: utils_1.StringUtil.trim `
## Parent Context
**Module**: ${(_c = moduleSection === null || moduleSection === void 0 ? void 0 : moduleSection.title) !== null && _c !== void 0 ? _c : "Unknown"}
**Unit**: ${(_d = unitSection === null || unitSection === void 0 ? void 0 : unitSection.title) !== null && _d !== void 0 ? _d : "Unknown"}
**Purpose**: ${(_e = unitSection === null || unitSection === void 0 ? void 0 : unitSection.purpose) !== null && _e !== void 0 ? _e : "Unknown"}
## AUTHORITATIVE Scope Reference
**Service Prefix**: ${props.scenario.prefix}
**Actors**: ${JSON.stringify(props.scenario.actors.map((a) => ({ name: a.name, kind: a.kind })))}
**Domain Entities**:
${props.scenario.entities.map((e) => { var _a; return `- **${e.name}**: ${e.attributes.slice(0, 5).join(", ")}${((_a = e.relationships) === null || _a === void 0 ? void 0 : _a.length) ? ` | ${e.relationships.join(", ")}` : ""}`; }).join("\n")}
**CRITICAL**: You MUST NOT reference entities, actors, or features not listed above.
## Previous Output
${previousOutputBlock}
## Review Feedback
The review REJECTED the above output for these reasons:
${props.feedback}
## Your Task
${taskBlock}
`,
},
],
userMessage: `Fix the rejected sections for "${(_f = unitSection === null || unitSection === void 0 ? void 0 : unitSection.title) !== null && _f !== void 0 ? _f : "Unknown"}" based on the review feedback above.`,
};
};
exports.transformAnalyzeWriteSectionPatchHistory = transformAnalyzeWriteSectionPatchHistory;
//# sourceMappingURL=transformAnalyzeWriteSectionPatchHistory.js.map