@vfarcic/dot-ai
Version:
AI-powered development productivity platform that enhances software development workflows through intelligent automation and AI-driven assistance
109 lines (108 loc) • 4.56 kB
JavaScript
;
/**
* CRD Availability Check with Global Caching
*
* Checks once per MCP server lifecycle if Solution CRD is available,
* then caches the result globally to avoid repeated cluster queries.
*
* PRD #359: Uses unified plugin registry for K8s operations
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSolutionCRDAvailable = isSolutionCRDAvailable;
exports.resetCRDAvailabilityCache = resetCRDAvailabilityCache;
const plugin_registry_1 = require("./plugin-registry");
/**
* Singleton cache for CRD availability check
* Checks once per MCP server lifecycle, caches result globally
*/
class CRDAvailabilityCache {
static instance;
crdAvailable = null;
constructor() { }
static getInstance() {
if (!CRDAvailabilityCache.instance) {
CRDAvailabilityCache.instance = new CRDAvailabilityCache();
}
return CRDAvailabilityCache.instance;
}
async isSolutionCRDAvailable() {
// Return cached result if available
if (this.crdAvailable !== null) {
return this.crdAvailable;
}
// PRD #359: All K8s operations go through unified plugin registry
if (!(0, plugin_registry_1.isPluginInitialized)()) {
console.log('ℹ️ Plugin system not available - Solution CR generation disabled');
this.crdAvailable = false;
return false;
}
// Check cluster for Solution CRD via plugin
const crdName = 'solutions.dot-ai.devopstoolkit.live';
try {
const response = await (0, plugin_registry_1.invokePluginTool)('agentic-tools', 'kubectl_get_resource_json', {
resource: `crd/${crdName}`,
});
if (response.success) {
// Check for nested error - plugin wraps kubectl errors in { success: false, error: "..." }
const result = response.result;
if (result && result.success === false) {
const errorMsg = result.error || '';
if (errorMsg.includes('NotFound') || errorMsg.includes('not found')) {
this.crdAvailable = false;
console.log('ℹ️ Solution CRD not available - Solution CR generation disabled (graceful degradation)');
return false;
}
throw new Error(`Failed to check Solution CRD availability: ${errorMsg}`);
}
// CRD exists, cache result
this.crdAvailable = true;
console.log('✅ Solution CRD available - Solution CR generation enabled');
return true;
}
else {
// CRD not found or error
const errorMsg = response.error?.message || '';
if (errorMsg.includes('NotFound') || errorMsg.includes('not found')) {
this.crdAvailable = false;
console.log('ℹ️ Solution CRD not available - Solution CR generation disabled (graceful degradation)');
return false;
}
// Other errors - don't cache, throw
throw new Error(`Failed to check Solution CRD availability: ${errorMsg}`);
}
}
catch (error) {
// Check if it's a "not found" error
const errorMsg = error instanceof Error ? error.message : String(error);
if (errorMsg.includes('NotFound') || errorMsg.includes('not found')) {
this.crdAvailable = false;
console.log('ℹ️ Solution CRD not available - Solution CR generation disabled (graceful degradation)');
return false;
}
// Other errors - don't cache, throw
throw new Error(`Failed to check Solution CRD availability: ${errorMsg}`, { cause: error });
}
}
/**
* Reset cache (for testing or manual refresh)
*/
reset() {
this.crdAvailable = null;
}
}
/**
* Helper function for checking CRD availability
* Use this function throughout the codebase
* PRD #359: No longer requires pluginManager parameter - uses unified registry
*/
async function isSolutionCRDAvailable() {
const cache = CRDAvailabilityCache.getInstance();
return cache.isSolutionCRDAvailable();
}
/**
* Reset CRD availability cache (primarily for testing)
*/
function resetCRDAvailabilityCache() {
const cache = CRDAvailabilityCache.getInstance();
cache.reset();
}