@vfarcic/dot-ai
Version:
AI-powered development productivity platform that enhances software development workflows through intelligent automation and AI-driven assistance
66 lines (65 loc) • 2.29 kB
JavaScript
;
/**
* Solution utilities for working with solution data structures
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractUserAnswers = extractUserAnswers;
exports.sanitizeIntentForLabel = sanitizeIntentForLabel;
exports.generateDotAiLabels = generateDotAiLabels;
exports.addDotAiLabels = addDotAiLabels;
/**
* Extract all user answers from a solution's questions
*/
function extractUserAnswers(solution) {
const userAnswers = {};
// Extract from all question categories
const questionCategories = ['required', 'basic', 'advanced'];
for (const category of questionCategories) {
const questions = solution.questions[category] || [];
for (const question of questions) {
if (question.id && question.answer !== undefined && question.answer !== null) {
userAnswers[question.id] = question.answer;
}
}
}
// Include open answer if provided
if (solution.questions.open?.answer) {
userAnswers.open = solution.questions.open.answer;
}
return userAnswers;
}
/**
* Sanitize intent string for use as Kubernetes label (63 char limit, alphanumeric + hyphens)
*/
function sanitizeIntentForLabel(intent) {
return intent
.toLowerCase()
.replace(/[^a-z0-9-]/g, '-')
.substring(0, 63)
.replace(/^-+|-+$/g, '');
}
/**
* Generate standard dot-ai labels for Kubernetes resources
*/
function generateDotAiLabels(userAnswers, solution) {
const appName = userAnswers.name;
const originalIntent = solution.intent;
if (!appName) {
throw new Error('Application name is required for dot-ai labels. This indicates a bug in the MCP workflow.');
}
if (!originalIntent) {
throw new Error('Application intent is required for dot-ai labels. This indicates a bug in the solution data.');
}
return {
'dot-ai.io/managed': 'true',
'dot-ai.io/app-name': appName,
'dot-ai.io/intent': sanitizeIntentForLabel(originalIntent)
};
}
/**
* Add dot-ai labels to existing labels object
*/
function addDotAiLabels(existingLabels, userAnswers, solution) {
const dotAiLabels = generateDotAiLabels(userAnswers, solution);
return { ...existingLabels, ...dotAiLabels };
}