@vfarcic/dot-ai 0.138.0 → 0.140.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/capability-scan-workflow.d.ts.map +1 -1
- package/dist/core/capability-scan-workflow.js +3 -2
- package/dist/core/command-executor.d.ts +39 -0
- package/dist/core/command-executor.d.ts.map +1 -0
- package/dist/core/command-executor.js +111 -0
- package/dist/core/deploy-operation.d.ts.map +1 -1
- package/dist/core/deploy-operation.js +3 -5
- package/dist/core/pattern-vector-service.d.ts +1 -1
- package/dist/core/pattern-vector-service.d.ts.map +1 -1
- package/dist/core/pattern-vector-service.js +2 -2
- package/dist/core/schema.js +1 -1
- package/dist/interfaces/mcp.d.ts.map +1 -1
- package/dist/interfaces/mcp.js +9 -1
- package/dist/tools/answer-question.d.ts.map +1 -1
- package/dist/tools/answer-question.js +27 -142
- package/dist/tools/choose-solution.d.ts.map +1 -1
- package/dist/tools/choose-solution.js +22 -85
- package/dist/tools/deploy-manifests.js +1 -1
- package/dist/tools/generate-manifests.d.ts.map +1 -1
- package/dist/tools/generate-manifests.js +33 -71
- package/dist/tools/operate-analysis.d.ts +15 -0
- package/dist/tools/operate-analysis.d.ts.map +1 -0
- package/dist/tools/operate-analysis.js +238 -0
- package/dist/tools/operate-execution.d.ts +18 -0
- package/dist/tools/operate-execution.d.ts.map +1 -0
- package/dist/tools/operate-execution.js +122 -0
- package/dist/tools/operate.d.ts +133 -0
- package/dist/tools/operate.d.ts.map +1 -0
- package/dist/tools/operate.js +237 -0
- package/dist/tools/recommend.d.ts +23 -1
- package/dist/tools/recommend.d.ts.map +1 -1
- package/dist/tools/recommend.js +14 -116
- package/dist/tools/remediate.d.ts +7 -4
- package/dist/tools/remediate.d.ts.map +1 -1
- package/dist/tools/remediate.js +38 -81
- package/dist/tools/version.js +1 -1
- package/package.json +1 -1
- package/prompts/operate-system.md +322 -0
- package/prompts/operate-user.md +25 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Operate Execution Workflow
|
|
4
|
+
*
|
|
5
|
+
* Executes approved operational changes using shared command executor
|
|
6
|
+
* and validates results using remediate tool
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.executeOperations = executeOperations;
|
|
10
|
+
const error_handling_1 = require("../core/error-handling");
|
|
11
|
+
const command_executor_1 = require("../core/command-executor");
|
|
12
|
+
const remediate_1 = require("./remediate");
|
|
13
|
+
/**
|
|
14
|
+
* Executes approved operational changes
|
|
15
|
+
* @param sessionId - Session ID with approved changes
|
|
16
|
+
* @param logger - Logger instance
|
|
17
|
+
* @param sessionManager - Session manager instance
|
|
18
|
+
* @returns Operation output with execution results
|
|
19
|
+
*/
|
|
20
|
+
async function executeOperations(sessionId, logger, sessionManager) {
|
|
21
|
+
logger.info('Starting operation execution', { sessionId });
|
|
22
|
+
try {
|
|
23
|
+
// 1. Load session with approved commands
|
|
24
|
+
const session = sessionManager.getSession(sessionId);
|
|
25
|
+
if (!session) {
|
|
26
|
+
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.VALIDATION, error_handling_1.ErrorSeverity.HIGH, `Session not found: ${sessionId}. The session may have expired or been deleted.`, { operation: 'session_loading', component: 'OperateExecutionTool' });
|
|
27
|
+
}
|
|
28
|
+
// Check if already executed
|
|
29
|
+
if (session.data.status === 'executing' || session.data.status === 'executed_successfully' || session.data.status === 'executed_with_errors') {
|
|
30
|
+
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.VALIDATION, error_handling_1.ErrorSeverity.MEDIUM, `Session ${sessionId} has already been executed. Current status: ${session.data.status}`, { operation: 'execution_validation', component: 'OperateExecutionTool' });
|
|
31
|
+
}
|
|
32
|
+
// Update session status to executing
|
|
33
|
+
sessionManager.updateSession(sessionId, { status: 'executing' });
|
|
34
|
+
logger.info('Loaded session for execution', {
|
|
35
|
+
sessionId,
|
|
36
|
+
commandCount: session.data.commands.length,
|
|
37
|
+
intent: session.data.intent
|
|
38
|
+
});
|
|
39
|
+
// 2. Execute commands using shared executor
|
|
40
|
+
const { results, overallSuccess } = await (0, command_executor_1.executeCommands)(session.data.commands, logger, {
|
|
41
|
+
sessionId,
|
|
42
|
+
context: 'operation',
|
|
43
|
+
logMetadata: { intent: session.data.intent }
|
|
44
|
+
});
|
|
45
|
+
// Convert CommandExecutionResult to ExecutionResult
|
|
46
|
+
const executionResults = results.map(r => ({
|
|
47
|
+
command: r.command,
|
|
48
|
+
success: r.success,
|
|
49
|
+
output: r.output,
|
|
50
|
+
error: r.error,
|
|
51
|
+
timestamp: r.timestamp
|
|
52
|
+
}));
|
|
53
|
+
// 3. Run validation via remediate tool (only if commands succeeded)
|
|
54
|
+
let validationSummary = 'Validation skipped due to command failures.';
|
|
55
|
+
if (overallSuccess && session.data.validationIntent) {
|
|
56
|
+
logger.info('Running post-execution validation via remediate', {
|
|
57
|
+
sessionId,
|
|
58
|
+
validationIntent: session.data.validationIntent
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
// Call remediate tool internally with validation intent
|
|
62
|
+
const validationResponse = await (0, remediate_1.handleRemediateTool)({
|
|
63
|
+
issue: session.data.validationIntent,
|
|
64
|
+
executedCommands: session.data.commands,
|
|
65
|
+
interaction_id: session.data.interaction_id
|
|
66
|
+
});
|
|
67
|
+
// Extract validation result from remediate response
|
|
68
|
+
const validationData = JSON.parse(validationResponse.content[0].text);
|
|
69
|
+
if (validationData.status === 'resolved' || validationData.status === 'no_issue_found') {
|
|
70
|
+
validationSummary = `Validation successful: ${validationData.message || 'Operations completed as expected.'}`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
validationSummary = `Validation completed with confidence ${Math.round((validationData.analysis?.confidence || 0) * 100)}%: ${validationData.analysis?.rootCause || 'See validation details'}`;
|
|
74
|
+
}
|
|
75
|
+
logger.info('Validation completed', { sessionId, validationSummary });
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger.error('Validation failed', error, { sessionId });
|
|
79
|
+
validationSummary = `Validation encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}. Manual verification recommended.`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// 4. Update session with execution results
|
|
83
|
+
const finalStatus = overallSuccess ? 'executed_successfully' : 'executed_with_errors';
|
|
84
|
+
sessionManager.updateSession(sessionId, {
|
|
85
|
+
status: finalStatus,
|
|
86
|
+
executionResults
|
|
87
|
+
});
|
|
88
|
+
logger.info('Execution completed', {
|
|
89
|
+
sessionId,
|
|
90
|
+
finalStatus,
|
|
91
|
+
successCount: executionResults.filter(r => r.success).length,
|
|
92
|
+
failureCount: executionResults.filter(r => !r.success).length
|
|
93
|
+
});
|
|
94
|
+
// 5. Return execution results with validation
|
|
95
|
+
return {
|
|
96
|
+
status: overallSuccess ? 'success' : 'failed',
|
|
97
|
+
sessionId,
|
|
98
|
+
execution: {
|
|
99
|
+
results: executionResults,
|
|
100
|
+
validation: validationSummary
|
|
101
|
+
},
|
|
102
|
+
message: overallSuccess
|
|
103
|
+
? `All ${executionResults.length} command(s) executed successfully. ${validationSummary}`
|
|
104
|
+
: `${executionResults.filter(r => !r.success).length} of ${executionResults.length} command(s) failed. See execution results for details.`
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
logger.error('Execution failed', error, { sessionId });
|
|
109
|
+
// Mark session as failed if we can
|
|
110
|
+
try {
|
|
111
|
+
sessionManager.updateSession(sessionId, { status: 'failed' });
|
|
112
|
+
}
|
|
113
|
+
catch (updateError) {
|
|
114
|
+
// Ignore - session might not exist
|
|
115
|
+
}
|
|
116
|
+
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.OPERATION, error_handling_1.ErrorSeverity.HIGH, `Execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`, {
|
|
117
|
+
operation: 'execute_operations',
|
|
118
|
+
component: 'OperateExecutionTool',
|
|
119
|
+
sessionId
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operate Tool - AI-powered Kubernetes application operations
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { Logger } from '../core/error-handling';
|
|
6
|
+
import { OrganizationalPattern, PolicyIntent } from '../core/organizational-types';
|
|
7
|
+
import { ResourceCapability } from '../core/capabilities';
|
|
8
|
+
export declare const OPERATE_TOOL_NAME = "operate";
|
|
9
|
+
export declare const OPERATE_TOOL_DESCRIPTION = "AI-powered Kubernetes application operations tool for Day 2 operations. Handles updates, scaling, enhancements, rollbacks, and deletions through natural language intents. Analyzes current state, applies organizational patterns and policies, validates changes via dry-run, and executes approved operations safely.";
|
|
10
|
+
export declare const OPERATE_TOOL_INPUT_SCHEMA: {
|
|
11
|
+
intent: z.ZodOptional<z.ZodString>;
|
|
12
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
13
|
+
executeChoice: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
refinedIntent: z.ZodOptional<z.ZodString>;
|
|
15
|
+
interaction_id: z.ZodOptional<z.ZodString>;
|
|
16
|
+
};
|
|
17
|
+
export interface OperateInput {
|
|
18
|
+
intent?: string;
|
|
19
|
+
sessionId?: string;
|
|
20
|
+
executeChoice?: number;
|
|
21
|
+
refinedIntent?: string;
|
|
22
|
+
interaction_id?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface OperateSessionData {
|
|
25
|
+
intent: string;
|
|
26
|
+
interaction_id?: string;
|
|
27
|
+
context: EmbeddedContext;
|
|
28
|
+
proposedChanges: ProposedChanges;
|
|
29
|
+
commands: string[];
|
|
30
|
+
dryRunValidation: {
|
|
31
|
+
status: 'success' | 'failed';
|
|
32
|
+
details: string;
|
|
33
|
+
};
|
|
34
|
+
patternsApplied: string[];
|
|
35
|
+
capabilitiesUsed: string[];
|
|
36
|
+
policiesChecked: string[];
|
|
37
|
+
risks: {
|
|
38
|
+
level: 'low' | 'medium' | 'high';
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
validationIntent: string;
|
|
42
|
+
status: 'analyzing' | 'analysis_complete' | 'executing' | 'executed_successfully' | 'executed_with_errors' | 'failed';
|
|
43
|
+
executionResults?: ExecutionResult[];
|
|
44
|
+
}
|
|
45
|
+
export type OperateSession = {
|
|
46
|
+
sessionId: string;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
updatedAt: string;
|
|
49
|
+
data: OperateSessionData;
|
|
50
|
+
};
|
|
51
|
+
export interface EmbeddedContext {
|
|
52
|
+
patterns: OrganizationalPattern[];
|
|
53
|
+
policies: PolicyIntent[];
|
|
54
|
+
capabilities: ResourceCapability[];
|
|
55
|
+
}
|
|
56
|
+
export interface ProposedChanges {
|
|
57
|
+
create: ResourceChange[];
|
|
58
|
+
update: ResourceChange[];
|
|
59
|
+
delete: ResourceChange[];
|
|
60
|
+
}
|
|
61
|
+
export interface ResourceChange {
|
|
62
|
+
kind: string;
|
|
63
|
+
name: string;
|
|
64
|
+
namespace?: string;
|
|
65
|
+
manifest?: string;
|
|
66
|
+
changes?: string;
|
|
67
|
+
rationale: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ExecutionResult {
|
|
70
|
+
command: string;
|
|
71
|
+
success: boolean;
|
|
72
|
+
output?: string;
|
|
73
|
+
error?: string;
|
|
74
|
+
timestamp: Date;
|
|
75
|
+
}
|
|
76
|
+
export interface OperateOutput {
|
|
77
|
+
status: 'success' | 'failed' | 'awaiting_user_approval';
|
|
78
|
+
sessionId: string;
|
|
79
|
+
analysis?: {
|
|
80
|
+
summary: string;
|
|
81
|
+
currentState: any;
|
|
82
|
+
proposedChanges: ProposedChanges;
|
|
83
|
+
commands: string[];
|
|
84
|
+
dryRunValidation: {
|
|
85
|
+
status: 'success' | 'failed';
|
|
86
|
+
details: string;
|
|
87
|
+
};
|
|
88
|
+
patternsApplied: string[];
|
|
89
|
+
capabilitiesUsed: string[];
|
|
90
|
+
policiesChecked: string[];
|
|
91
|
+
risks: {
|
|
92
|
+
level: 'low' | 'medium' | 'high';
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
validationIntent: string;
|
|
96
|
+
};
|
|
97
|
+
execution?: {
|
|
98
|
+
results: ExecutionResult[];
|
|
99
|
+
validation: string;
|
|
100
|
+
};
|
|
101
|
+
message: string;
|
|
102
|
+
nextAction?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Embed context (patterns, policies, capabilities) for AI analysis
|
|
106
|
+
* @param intent User's operational intent
|
|
107
|
+
* @returns Embedded context with patterns, policies, and capabilities
|
|
108
|
+
* @throws Error if capabilities are not available (mandatory)
|
|
109
|
+
*/
|
|
110
|
+
export declare function embedContext(intent: string, logger: Logger): Promise<EmbeddedContext>;
|
|
111
|
+
/**
|
|
112
|
+
* Format patterns for template placeholder
|
|
113
|
+
*/
|
|
114
|
+
export declare function formatPatterns(patterns: OrganizationalPattern[]): string;
|
|
115
|
+
/**
|
|
116
|
+
* Format policies for template placeholder
|
|
117
|
+
*/
|
|
118
|
+
export declare function formatPolicies(policies: PolicyIntent[]): string;
|
|
119
|
+
/**
|
|
120
|
+
* Format capabilities for template placeholder
|
|
121
|
+
* Capabilities are already ordered by relevance from vector search
|
|
122
|
+
*/
|
|
123
|
+
export declare function formatCapabilities(capabilities: ResourceCapability[]): string;
|
|
124
|
+
/**
|
|
125
|
+
* Main operate tool entry point
|
|
126
|
+
*/
|
|
127
|
+
export declare function operate(args: OperateInput): Promise<OperateOutput>;
|
|
128
|
+
/**
|
|
129
|
+
* MCP handler for operate tool
|
|
130
|
+
* Wraps the main operate function with consistent return format
|
|
131
|
+
*/
|
|
132
|
+
export declare function handleOperateTool(args: any): Promise<any>;
|
|
133
|
+
//# sourceMappingURL=operate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operate.d.ts","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/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.OPERATE_TOOL_INPUT_SCHEMA = exports.OPERATE_TOOL_DESCRIPTION = exports.OPERATE_TOOL_NAME = void 0;
|
|
40
|
+
exports.embedContext = embedContext;
|
|
41
|
+
exports.formatPatterns = formatPatterns;
|
|
42
|
+
exports.formatPolicies = formatPolicies;
|
|
43
|
+
exports.formatCapabilities = formatCapabilities;
|
|
44
|
+
exports.operate = operate;
|
|
45
|
+
exports.handleOperateTool = handleOperateTool;
|
|
46
|
+
const zod_1 = require("zod");
|
|
47
|
+
const error_handling_1 = require("../core/error-handling");
|
|
48
|
+
const generic_session_manager_1 = require("../core/generic-session-manager");
|
|
49
|
+
const pattern_vector_service_1 = require("../core/pattern-vector-service");
|
|
50
|
+
const policy_vector_service_1 = require("../core/policy-vector-service");
|
|
51
|
+
const capability_vector_service_1 = require("../core/capability-vector-service");
|
|
52
|
+
// Tool metadata for direct MCP registration
|
|
53
|
+
exports.OPERATE_TOOL_NAME = 'operate';
|
|
54
|
+
exports.OPERATE_TOOL_DESCRIPTION = 'AI-powered Kubernetes application operations tool for Day 2 operations. Handles updates, scaling, enhancements, rollbacks, and deletions through natural language intents. Analyzes current state, applies organizational patterns and policies, validates changes via dry-run, and executes approved operations safely.';
|
|
55
|
+
// Zod schema for MCP registration
|
|
56
|
+
exports.OPERATE_TOOL_INPUT_SCHEMA = {
|
|
57
|
+
intent: zod_1.z.string().min(1).max(2000).optional().describe('User intent for operation: "update X to Y", "scale Z", "make W HA", etc.'),
|
|
58
|
+
sessionId: zod_1.z.string().optional().describe('Session ID from previous operate call'),
|
|
59
|
+
executeChoice: zod_1.z.number().min(1).max(1).optional().describe('Execute approved changes (1=execute)'),
|
|
60
|
+
refinedIntent: zod_1.z.string().min(1).max(2000).optional().describe('Clarified intent if user wants to provide more details'),
|
|
61
|
+
interaction_id: zod_1.z.string().optional().describe('INTERNAL ONLY - Do not populate. Used for evaluation dataset generation.')
|
|
62
|
+
};
|
|
63
|
+
// Session manager instance
|
|
64
|
+
const sessionManager = new generic_session_manager_1.GenericSessionManager('opr');
|
|
65
|
+
// Initialize logger
|
|
66
|
+
const logger = new error_handling_1.ConsoleLogger('OperateTool');
|
|
67
|
+
/**
|
|
68
|
+
* Embed context (patterns, policies, capabilities) for AI analysis
|
|
69
|
+
* @param intent User's operational intent
|
|
70
|
+
* @returns Embedded context with patterns, policies, and capabilities
|
|
71
|
+
* @throws Error if capabilities are not available (mandatory)
|
|
72
|
+
*/
|
|
73
|
+
async function embedContext(intent, logger) {
|
|
74
|
+
const context = {
|
|
75
|
+
patterns: [],
|
|
76
|
+
policies: [],
|
|
77
|
+
capabilities: []
|
|
78
|
+
};
|
|
79
|
+
// Search for relevant patterns (optional - non-blocking)
|
|
80
|
+
try {
|
|
81
|
+
const patternService = new pattern_vector_service_1.PatternVectorService();
|
|
82
|
+
const patternResults = await patternService.searchPatterns(intent, { limit: 5 });
|
|
83
|
+
context.patterns = patternResults.map(result => result.data);
|
|
84
|
+
logger.info(`Found ${context.patterns.length} relevant organizational patterns`);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
logger.warn('Pattern search failed, continuing without patterns', { error });
|
|
88
|
+
}
|
|
89
|
+
// Search for relevant policies (optional - non-blocking)
|
|
90
|
+
try {
|
|
91
|
+
const policyService = new policy_vector_service_1.PolicyVectorService();
|
|
92
|
+
const policyResults = await policyService.searchPolicyIntents(intent, { limit: 5 });
|
|
93
|
+
context.policies = policyResults.map(result => result.data);
|
|
94
|
+
logger.info(`Found ${context.policies.length} relevant organizational policies`);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
logger.warn('Policy search failed, continuing without policies', { error });
|
|
98
|
+
}
|
|
99
|
+
// Search for relevant cluster capabilities (MANDATORY)
|
|
100
|
+
try {
|
|
101
|
+
// Use QDRANT_CAPABILITIES_COLLECTION env var for collection name
|
|
102
|
+
// Integration tests set this to 'capabilities-policies' (pre-populated test data)
|
|
103
|
+
// Production uses default 'capabilities' collection
|
|
104
|
+
const collectionName = process.env.QDRANT_CAPABILITIES_COLLECTION || 'capabilities';
|
|
105
|
+
const capabilityService = new capability_vector_service_1.CapabilityVectorService(collectionName);
|
|
106
|
+
const capabilityResults = await capabilityService.searchCapabilities(intent, { limit: 50 });
|
|
107
|
+
if (capabilityResults.length === 0) {
|
|
108
|
+
throw new Error(`No cluster capabilities found for intent "${intent}". Please scan your cluster first:\n` +
|
|
109
|
+
`Run: manageOrgData({ dataType: "capabilities", operation: "scan" })\n` +
|
|
110
|
+
`Note: Capabilities are required to understand what resources and operators are available in the cluster.`);
|
|
111
|
+
}
|
|
112
|
+
context.capabilities = capabilityResults.map(result => result.data);
|
|
113
|
+
logger.info(`Found ${context.capabilities.length} relevant cluster capabilities`);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
// If it's our specific "no capabilities" error, re-throw it
|
|
117
|
+
if (error instanceof Error && error.message.includes('No cluster capabilities found')) {
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
// Otherwise, it's a capability service initialization or retrieval error
|
|
121
|
+
throw new Error(`Capability service not available for intent "${intent}". Please scan your cluster first:\n` +
|
|
122
|
+
`Run: manageOrgData({ dataType: "capabilities", operation: "scan" })\n` +
|
|
123
|
+
`Note: Vector DB is required for capability-based operations.\n` +
|
|
124
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
125
|
+
}
|
|
126
|
+
return context;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Format patterns for template placeholder
|
|
130
|
+
*/
|
|
131
|
+
function formatPatterns(patterns) {
|
|
132
|
+
if (patterns.length === 0) {
|
|
133
|
+
return 'No organizational patterns found matching this intent.';
|
|
134
|
+
}
|
|
135
|
+
let formatted = '';
|
|
136
|
+
patterns.forEach((pattern, index) => {
|
|
137
|
+
formatted += `### Pattern ${index + 1}: ${pattern.description}\n\n`;
|
|
138
|
+
formatted += `**Triggers:** ${pattern.triggers.join(', ')}\n\n`;
|
|
139
|
+
formatted += `**Suggested Resources:** ${pattern.suggestedResources.join(', ')}\n\n`;
|
|
140
|
+
formatted += `**Rationale:** ${pattern.rationale}\n\n`;
|
|
141
|
+
if (index < patterns.length - 1) {
|
|
142
|
+
formatted += '---\n\n';
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return formatted;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Format policies for template placeholder
|
|
149
|
+
*/
|
|
150
|
+
function formatPolicies(policies) {
|
|
151
|
+
if (policies.length === 0) {
|
|
152
|
+
return 'No organizational policies found matching this intent.';
|
|
153
|
+
}
|
|
154
|
+
let formatted = '';
|
|
155
|
+
policies.forEach((policy, index) => {
|
|
156
|
+
formatted += `### Policy ${index + 1}: ${policy.description}\n\n`;
|
|
157
|
+
if (policy.triggers && policy.triggers.length > 0) {
|
|
158
|
+
formatted += `**Applies to:** ${policy.triggers.join(', ')}\n\n`;
|
|
159
|
+
}
|
|
160
|
+
formatted += `**Rationale:** ${policy.rationale}\n\n`;
|
|
161
|
+
if (index < policies.length - 1) {
|
|
162
|
+
formatted += '---\n\n';
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return formatted;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Format capabilities for template placeholder
|
|
169
|
+
* Capabilities are already ordered by relevance from vector search
|
|
170
|
+
*/
|
|
171
|
+
function formatCapabilities(capabilities) {
|
|
172
|
+
if (capabilities.length === 0) {
|
|
173
|
+
return 'No custom capabilities detected. Only standard Kubernetes resources available.';
|
|
174
|
+
}
|
|
175
|
+
// List capabilities in order received (most relevant first from vector search)
|
|
176
|
+
let formatted = '';
|
|
177
|
+
capabilities.forEach(cap => {
|
|
178
|
+
const apiInfo = cap.apiVersion || cap.group || 'core';
|
|
179
|
+
formatted += `- **${cap.resourceName}** (${apiInfo}): ${cap.description || 'Custom resource'}\n`;
|
|
180
|
+
if (cap.capabilities && cap.capabilities.length > 0) {
|
|
181
|
+
formatted += ` Capabilities: ${cap.capabilities.join(', ')}\n`;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return formatted;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Main operate tool entry point
|
|
188
|
+
*/
|
|
189
|
+
async function operate(args) {
|
|
190
|
+
try {
|
|
191
|
+
// Route 1: Execute approved operation
|
|
192
|
+
if (args.sessionId && args.executeChoice) {
|
|
193
|
+
// Import and delegate to execution workflow
|
|
194
|
+
const { executeOperations } = await Promise.resolve().then(() => __importStar(require('./operate-execution')));
|
|
195
|
+
return await executeOperations(args.sessionId, logger, sessionManager);
|
|
196
|
+
}
|
|
197
|
+
// Route 2: Refine intent with more context
|
|
198
|
+
if (args.sessionId && args.refinedIntent) {
|
|
199
|
+
// Import and delegate to analysis workflow with refined intent
|
|
200
|
+
const { analyzeIntent } = await Promise.resolve().then(() => __importStar(require('./operate-analysis')));
|
|
201
|
+
return await analyzeIntent(args.refinedIntent, logger, sessionManager, args.sessionId, args.interaction_id);
|
|
202
|
+
}
|
|
203
|
+
// Route 3: New operation analysis
|
|
204
|
+
if (args.intent) {
|
|
205
|
+
// Import and delegate to analysis workflow
|
|
206
|
+
const { analyzeIntent } = await Promise.resolve().then(() => __importStar(require('./operate-analysis')));
|
|
207
|
+
return await analyzeIntent(args.intent, logger, sessionManager, undefined, args.interaction_id);
|
|
208
|
+
}
|
|
209
|
+
// Invalid input
|
|
210
|
+
throw error_handling_1.ErrorHandler.createError(error_handling_1.ErrorCategory.VALIDATION, error_handling_1.ErrorSeverity.HIGH, 'Invalid input: must provide either intent (for new operation) or sessionId + executeChoice (for execution)', {
|
|
211
|
+
operation: 'operate',
|
|
212
|
+
component: 'OperateTool'
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
217
|
+
logger.error(`Operate tool error: ${errorMsg}`);
|
|
218
|
+
return {
|
|
219
|
+
status: 'failed',
|
|
220
|
+
sessionId: args.sessionId || 'unknown',
|
|
221
|
+
message: `Operation failed: ${errorMsg}`
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* MCP handler for operate tool
|
|
227
|
+
* Wraps the main operate function with consistent return format
|
|
228
|
+
*/
|
|
229
|
+
async function handleOperateTool(args) {
|
|
230
|
+
const result = await operate(args);
|
|
231
|
+
return {
|
|
232
|
+
content: [{
|
|
233
|
+
type: 'text',
|
|
234
|
+
text: JSON.stringify(result, null, 2)
|
|
235
|
+
}]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -5,7 +5,7 @@ import { z } from 'zod';
|
|
|
5
5
|
import { DotAI } from '../core/index';
|
|
6
6
|
import { Logger } from '../core/error-handling';
|
|
7
7
|
export declare const RECOMMEND_TOOL_NAME = "recommend";
|
|
8
|
-
export declare const RECOMMEND_TOOL_DESCRIPTION = "Deploy
|
|
8
|
+
export declare const RECOMMEND_TOOL_DESCRIPTION = "Deploy applications, infrastructure, and services using Kubernetes resources with AI recommendations. Supports cloud resources via operators like Crossplane, cluster management via CAPI, and traditional Kubernetes workloads. Describe what you want to deploy. Does NOT handle policy creation, organizational patterns, or resource capabilities - use manageOrgData for those.";
|
|
9
9
|
export declare const RECOMMEND_TOOL_INPUT_SCHEMA: {
|
|
10
10
|
stage: z.ZodOptional<z.ZodString>;
|
|
11
11
|
intent: z.ZodOptional<z.ZodString>;
|
|
@@ -15,6 +15,28 @@ export declare const RECOMMEND_TOOL_INPUT_SCHEMA: {
|
|
|
15
15
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
16
16
|
interaction_id: z.ZodOptional<z.ZodString>;
|
|
17
17
|
};
|
|
18
|
+
export interface SolutionData {
|
|
19
|
+
intent: string;
|
|
20
|
+
type: string;
|
|
21
|
+
score: number;
|
|
22
|
+
description: string;
|
|
23
|
+
reasons: string[];
|
|
24
|
+
analysis: string;
|
|
25
|
+
resources: Array<{
|
|
26
|
+
kind: string;
|
|
27
|
+
apiVersion: string;
|
|
28
|
+
group: string;
|
|
29
|
+
description: string;
|
|
30
|
+
}>;
|
|
31
|
+
questions: {
|
|
32
|
+
required?: any[];
|
|
33
|
+
basic?: any[];
|
|
34
|
+
advanced?: any[];
|
|
35
|
+
open?: any;
|
|
36
|
+
};
|
|
37
|
+
answers: Record<string, any>;
|
|
38
|
+
timestamp: string;
|
|
39
|
+
}
|
|
18
40
|
/**
|
|
19
41
|
* Direct MCP tool handler for recommend functionality (unified with stage routing)
|
|
20
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../../src/tools/recommend.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../../src/tools/recommend.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAWhD,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C,eAAO,MAAM,0BAA0B,yXAAyX,CAAC;AAGja,eAAO,MAAM,2BAA2B;;;;;;;;CAWvC,CAAC;AAGF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC,CAAC;IACH,SAA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