UNPKG

@autobe/agent

Version:

AI backend server code generator

112 lines (106 loc) 4.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.predicateStateMessage = void 0; const utils_1 = require("@autobe/utils"); /** * Validates pipeline state before executing a phase, returning user-friendly * error message if prerequisites are missing or outdated. * * Enforces the waterfall dependency structure: each phase requires all previous * phases to be completed with matching step counters. When requirements change * (analyze step increments), downstream phases become invalid through step * mismatch, and this function generates clear messages guiding users to * regenerate affected phases. * * This is the gatekeeper preventing users from executing phases out of order or * with stale dependencies, ensuring generated artifacts always reflect current * requirements. Without this validation, users could generate API * implementations based on outdated database schemas, causing subtle bugs. * * @param state Current pipeline state * @param future Phase attempting to execute * @returns Error message if validation fails, null if valid to proceed */ const predicateStateMessage = (state, future) => { if (future === "analyze") return null; if (future === "database") return predicateDatabase(state); const futureIndex = STEP_ORDER.indexOf(future); for (const key of STEP_ORDER.slice(0, futureIndex)) if (state[key] === null) return buildMissingStepsMessage(future, key); const prevStepName = STEP_ORDER[futureIndex - 1]; if (state.analyze.step !== state[prevStepName].step) return buildOutdatedMessage(prevStepName, "analyze", state); return null; }; exports.predicateStateMessage = predicateStateMessage; /** Generates error message listing steps needed to reach current phase. */ const buildMissingStepsMessage = (current, missing) => { const currentIndex = STEP_ORDER.indexOf(current); const missingIndex = STEP_ORDER.indexOf(missing); const remainingSteps = STEP_ORDER.slice(missingIndex, currentIndex + 1) .map((step, index) => `${index + 1}. ${STEP_DESCRIPTIONS[step]}`) .join("\n "); const currentAction = ACTION_NAMES[current]; return utils_1.StringUtil.trim ` ${STEP_DESCRIPTIONS[missing]} not completed yet. To ${currentAction}, complete these steps: ${remainingSteps} Start with step ${missingIndex + 1}. `; }; /** * Generates error message indicating phase is outdated due to requirements * change. */ const buildOutdatedMessage = (outdatedStep, currentStep, state) => { var _a, _b; const outdatedVersion = (_a = state[outdatedStep]) === null || _a === void 0 ? void 0 : _a.step; const currentVersion = (_b = state[currentStep]) === null || _b === void 0 ? void 0 : _b.step; return utils_1.StringUtil.trim ` ${STEP_NAMES[outdatedStep]} is outdated (step ${outdatedVersion}). Requirements are now at step ${currentVersion}. Please update ${outdatedStep} to match current requirements. `; }; /** Special validation for Database phase requiring only analyze completion. */ const predicateDatabase = (state) => { if (state.analyze !== null) return null; return utils_1.StringUtil.trim ` Requirements analysis not started. Discuss your project with AI to generate requirements analysis. Database design will follow after requirements are ready. `; }; const STEP_DESCRIPTIONS = { analyze: "Requirements analysis", database: "Database design", interface: "API interface design", test: "E2E test creation", realize: "Implementation", }; const STEP_NAMES = { analyze: "Requirements analysis", database: "Database schema", interface: "API interface", test: "Test functions", realize: "Implementation", }; const ACTION_NAMES = { analyze: "analyze requirements", database: "design database", interface: "design API interface", test: "create tests", realize: "implement the program", }; const STEP_ORDER = [ "analyze", "database", "interface", "test", "realize", ]; //# sourceMappingURL=predicateStateMessage.js.map