@vfarcic/dot-ai 0.104.0 → 0.105.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.
Files changed (56) hide show
  1. package/README.md +0 -1
  2. package/dist/core/ai-provider-factory.d.ts +90 -0
  3. package/dist/core/ai-provider-factory.d.ts.map +1 -0
  4. package/dist/core/ai-provider-factory.js +187 -0
  5. package/dist/core/ai-provider.interface.d.ts +116 -0
  6. package/dist/core/ai-provider.interface.d.ts.map +1 -0
  7. package/dist/core/ai-provider.interface.js +14 -0
  8. package/dist/core/capabilities.d.ts +3 -3
  9. package/dist/core/capabilities.d.ts.map +1 -1
  10. package/dist/core/capabilities.js +4 -4
  11. package/dist/core/capability-scan-workflow.d.ts.map +1 -1
  12. package/dist/core/capability-scan-workflow.js +29 -14
  13. package/dist/core/doc-testing-session.d.ts +1 -1
  14. package/dist/core/doc-testing-session.js +1 -1
  15. package/dist/core/error-handling.js +2 -2
  16. package/dist/core/index.d.ts +4 -6
  17. package/dist/core/index.d.ts.map +1 -1
  18. package/dist/core/index.js +11 -22
  19. package/dist/core/platform-operations.d.ts +3 -3
  20. package/dist/core/platform-operations.d.ts.map +1 -1
  21. package/dist/core/platform-operations.js +6 -6
  22. package/dist/core/providers/anthropic-provider.d.ts +32 -0
  23. package/dist/core/providers/anthropic-provider.d.ts.map +1 -0
  24. package/dist/core/providers/anthropic-provider.js +177 -0
  25. package/dist/core/providers/vercel-provider.d.ts +34 -0
  26. package/dist/core/providers/vercel-provider.d.ts.map +1 -0
  27. package/dist/core/providers/vercel-provider.js +202 -0
  28. package/dist/core/schema.d.ts +4 -7
  29. package/dist/core/schema.d.ts.map +1 -1
  30. package/dist/core/schema.js +13 -11
  31. package/dist/core/unified-creation-session.d.ts.map +1 -1
  32. package/dist/core/unified-creation-session.js +13 -14
  33. package/dist/interfaces/mcp.d.ts +1 -1
  34. package/dist/interfaces/mcp.js +1 -1
  35. package/dist/interfaces/rest-api.js +1 -1
  36. package/dist/mcp/server.d.ts +1 -1
  37. package/dist/mcp/server.js +2 -2
  38. package/dist/tools/answer-question.d.ts.map +1 -1
  39. package/dist/tools/answer-question.js +8 -10
  40. package/dist/tools/build-platform.js +3 -3
  41. package/dist/tools/generate-manifests.d.ts.map +1 -1
  42. package/dist/tools/generate-manifests.js +7 -8
  43. package/dist/tools/organizational-data.d.ts.map +1 -1
  44. package/dist/tools/organizational-data.js +3 -2
  45. package/dist/tools/recommend.d.ts.map +1 -1
  46. package/dist/tools/recommend.js +50 -30
  47. package/dist/tools/remediate.d.ts.map +1 -1
  48. package/dist/tools/remediate.js +23 -39
  49. package/dist/tools/version.d.ts +3 -2
  50. package/dist/tools/version.d.ts.map +1 -1
  51. package/dist/tools/version.js +35 -23
  52. package/package.json +5 -2
  53. package/prompts/question-generation.md +31 -3
  54. package/dist/core/claude.d.ts +0 -88
  55. package/dist/core/claude.d.ts.map +0 -1
  56. package/dist/core/claude.js +0 -414
@@ -5,11 +5,11 @@
5
5
  * Shared intelligence for both CLI and MCP interfaces
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.OpenAIEmbeddingProvider = exports.EmbeddingService = exports.CapabilityVectorService = exports.PolicyVectorService = exports.PatternVectorService = exports.BaseVectorService = exports.VectorDBService = exports.deserializePattern = exports.serializePattern = exports.createPattern = exports.validatePattern = exports.ResourceRecommender = exports.ManifestValidator = exports.SchemaParser = exports.ClaudeIntegration = exports.WorkflowEngine = exports.MemorySystem = exports.KubernetesDiscovery = exports.DotAI = void 0;
8
+ exports.OpenAIEmbeddingProvider = exports.EmbeddingService = exports.CapabilityVectorService = exports.PolicyVectorService = exports.PatternVectorService = exports.BaseVectorService = exports.VectorDBService = exports.deserializePattern = exports.serializePattern = exports.createPattern = exports.validatePattern = exports.ResourceRecommender = exports.ManifestValidator = exports.SchemaParser = exports.AIProviderFactory = exports.createAIProvider = exports.WorkflowEngine = exports.MemorySystem = exports.KubernetesDiscovery = exports.DotAI = void 0;
9
9
  const discovery_1 = require("./discovery");
10
10
  const memory_1 = require("./memory");
11
11
  const workflow_1 = require("./workflow");
12
- const claude_1 = require("./claude");
12
+ const ai_provider_factory_1 = require("./ai-provider-factory");
13
13
  const schema_1 = require("./schema");
14
14
  class DotAI {
15
15
  config;
@@ -17,14 +17,11 @@ class DotAI {
17
17
  discovery;
18
18
  memory;
19
19
  workflow;
20
- claude;
20
+ ai;
21
21
  schema;
22
22
  constructor(config = {}) {
23
- this.validateConfig(config);
24
- // Centralize environment variable reading
25
23
  this.config = {
26
- kubernetesConfig: config.kubernetesConfig || process.env.KUBECONFIG,
27
- anthropicApiKey: config.anthropicApiKey || process.env.ANTHROPIC_API_KEY
24
+ kubernetesConfig: config.kubernetesConfig || process.env.KUBECONFIG
28
25
  };
29
26
  // Initialize modules
30
27
  this.discovery = new discovery_1.KubernetesDiscovery({
@@ -32,13 +29,12 @@ class DotAI {
32
29
  });
33
30
  this.memory = new memory_1.MemorySystem();
34
31
  this.workflow = new workflow_1.WorkflowEngine();
35
- this.claude = new claude_1.ClaudeIntegration(this.config.anthropicApiKey || 'test-key');
32
+ this.ai = (0, ai_provider_factory_1.createAIProvider)();
36
33
  // Initialize schema components
37
34
  const parser = new schema_1.SchemaParser();
38
35
  const validator = new schema_1.ManifestValidator();
39
- const ranker = this.config.anthropicApiKey ?
40
- new schema_1.ResourceRecommender({ claudeApiKey: this.config.anthropicApiKey }) :
41
- null;
36
+ // ResourceRecommender uses the AI provider directly
37
+ const ranker = new schema_1.ResourceRecommender(this.ai);
42
38
  this.schema = {
43
39
  parser,
44
40
  validator,
@@ -68,7 +64,7 @@ class DotAI {
68
64
  },
69
65
  rankResources: async (intent) => {
70
66
  if (!ranker) {
71
- throw new Error('ResourceRanker not available. ANTHROPIC_API_KEY is required for AI-powered ranking.');
67
+ throw new Error('ResourceRanker not available. AI provider API key is required for AI-powered ranking.');
72
68
  }
73
69
  // Create discovery function with proper binding
74
70
  const explainResourceFn = async (resource) => await this.discovery.explainResource(resource);
@@ -76,11 +72,6 @@ class DotAI {
76
72
  }
77
73
  };
78
74
  }
79
- validateConfig(config) {
80
- if (config.anthropicApiKey === '') {
81
- throw new Error('Invalid configuration: Empty API key provided');
82
- }
83
- }
84
75
  async initialize() {
85
76
  try {
86
77
  // Initialize all modules
@@ -112,9 +103,6 @@ class DotAI {
112
103
  getVersion() {
113
104
  return '0.1.0';
114
105
  }
115
- getAnthropicApiKey() {
116
- return this.config.anthropicApiKey;
117
- }
118
106
  }
119
107
  exports.DotAI = DotAI;
120
108
  // Re-export all modules for convenience
@@ -124,8 +112,9 @@ var memory_2 = require("./memory");
124
112
  Object.defineProperty(exports, "MemorySystem", { enumerable: true, get: function () { return memory_2.MemorySystem; } });
125
113
  var workflow_2 = require("./workflow");
126
114
  Object.defineProperty(exports, "WorkflowEngine", { enumerable: true, get: function () { return workflow_2.WorkflowEngine; } });
127
- var claude_2 = require("./claude");
128
- Object.defineProperty(exports, "ClaudeIntegration", { enumerable: true, get: function () { return claude_2.ClaudeIntegration; } });
115
+ var ai_provider_factory_2 = require("./ai-provider-factory");
116
+ Object.defineProperty(exports, "createAIProvider", { enumerable: true, get: function () { return ai_provider_factory_2.createAIProvider; } });
117
+ Object.defineProperty(exports, "AIProviderFactory", { enumerable: true, get: function () { return ai_provider_factory_2.AIProviderFactory; } });
129
118
  var schema_2 = require("./schema");
130
119
  Object.defineProperty(exports, "SchemaParser", { enumerable: true, get: function () { return schema_2.SchemaParser; } });
131
120
  Object.defineProperty(exports, "ManifestValidator", { enumerable: true, get: function () { return schema_2.ManifestValidator; } });
@@ -4,7 +4,7 @@
4
4
  * Discovers available Nu shell script operations and maps user intent to operations
5
5
  * using AI-powered parsing and matching.
6
6
  */
7
- import { ClaudeIntegration } from './claude';
7
+ import { AIProvider } from './ai-provider.interface';
8
8
  import { Logger } from './error-handling';
9
9
  export interface OperationCommand {
10
10
  name: string;
@@ -47,11 +47,11 @@ export interface PlatformSession {
47
47
  /**
48
48
  * Discover available operations from Nu shell scripts using AI parsing
49
49
  */
50
- export declare function discoverOperations(claudeIntegration: ClaudeIntegration, logger: Logger): Promise<Operation[]>;
50
+ export declare function discoverOperations(aiProvider: AIProvider, logger: Logger): Promise<Operation[]>;
51
51
  /**
52
52
  * Map user intent to a specific operation using AI
53
53
  */
54
- export declare function mapIntentToOperation(intent: string, operations: Operation[], claudeIntegration: ClaudeIntegration, logger: Logger): Promise<IntentMapping>;
54
+ export declare function mapIntentToOperation(intent: string, operations: Operation[], aiProvider: AIProvider, logger: Logger): Promise<IntentMapping>;
55
55
  /**
56
56
  * Get parameters for a specific operation using Nushell's structured JSON output
57
57
  */
@@ -1 +1 @@
1
- {"version":3,"file":"platform-operations.d.ts","sourceRoot":"","sources":["../../src/core/platform-operations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AA4B1C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,gBAAgB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,G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AsB,gBAAgB,CACpC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAkE/F"}
@@ -74,7 +74,7 @@ function stripMarkdownCodeBlocks(content) {
74
74
  /**
75
75
  * Discover available operations from Nu shell scripts using AI parsing
76
76
  */
77
- async function discoverOperations(claudeIntegration, logger) {
77
+ async function discoverOperations(aiProvider, logger) {
78
78
  try {
79
79
  // Execute Nu script help command
80
80
  const scriptPath = path.join(getScriptsDir(), 'dot.nu');
@@ -87,8 +87,8 @@ async function discoverOperations(claudeIntegration, logger) {
87
87
  const promptTemplate = fs.readFileSync(promptPath, 'utf8');
88
88
  // Replace template variable with actual help output
89
89
  const prompt = promptTemplate.replace('{helpOutput}', stdout);
90
- // Send to Claude for AI-powered parsing
91
- const response = await claudeIntegration.sendMessage(prompt);
90
+ // Send to AI provider for AI-powered parsing
91
+ const response = await aiProvider.sendMessage(prompt);
92
92
  // Strip markdown code blocks and parse JSON
93
93
  const jsonContent = stripMarkdownCodeBlocks(response.content);
94
94
  const operations = JSON.parse(jsonContent);
@@ -105,7 +105,7 @@ async function discoverOperations(claudeIntegration, logger) {
105
105
  /**
106
106
  * Map user intent to a specific operation using AI
107
107
  */
108
- async function mapIntentToOperation(intent, operations, claudeIntegration, logger) {
108
+ async function mapIntentToOperation(intent, operations, aiProvider, logger) {
109
109
  try {
110
110
  // Load AI prompt template for intent mapping
111
111
  const promptPath = path.join(process.cwd(), 'prompts', 'map-intent-to-operation.md');
@@ -114,8 +114,8 @@ async function mapIntentToOperation(intent, operations, claudeIntegration, logge
114
114
  const prompt = promptTemplate
115
115
  .replace('{intent}', intent)
116
116
  .replace('{operations}', JSON.stringify(operations, null, 2));
117
- // Send to Claude for AI-powered intent matching
118
- const response = await claudeIntegration.sendMessage(prompt);
117
+ // Send to AI provider for AI-powered intent matching
118
+ const response = await aiProvider.sendMessage(prompt);
119
119
  // Strip markdown code blocks and parse JSON
120
120
  const jsonContent = stripMarkdownCodeBlocks(response.content);
121
121
  const mapping = JSON.parse(jsonContent);
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Anthropic AI Provider Implementation
3
+ *
4
+ * Implements AIProvider interface using Anthropic SDK directly.
5
+ * Supports streaming for long operations and debug logging.
6
+ */
7
+ import { AIProvider, AIResponse, AIProviderConfig } from '../ai-provider.interface';
8
+ export declare class AnthropicProvider implements AIProvider {
9
+ private client;
10
+ private apiKey;
11
+ private model;
12
+ private debugMode;
13
+ constructor(config: AIProviderConfig);
14
+ private validateApiKey;
15
+ getProviderType(): string;
16
+ getDefaultModel(): string;
17
+ isInitialized(): boolean;
18
+ /**
19
+ * Create debug directory if it doesn't exist
20
+ */
21
+ private ensureDebugDirectory;
22
+ /**
23
+ * Generate unique identifier for debug files with operation context
24
+ */
25
+ private generateDebugId;
26
+ /**
27
+ * Save AI interaction for debugging when DEBUG_DOT_AI=true
28
+ */
29
+ private debugLogInteraction;
30
+ sendMessage(message: string, operation?: string): Promise<AIResponse>;
31
+ }
32
+ //# sourceMappingURL=anthropic-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-provider.d.ts","sourceRoot":"","sources":["../../../src/core/providers/anthropic-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,UAAU,EACV,UAAU,EACV,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,qBAAa,iBAAkB,YAAW,UAAU;IAClD,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,SAAS,CAAU;gBAEf,MAAM,EAAE,gBAAgB;IAWpC,OAAO,CAAC,cAAc;IAStB,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM;IAIzB,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAQ5B;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA+BrB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;CAkDvF"}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ /**
3
+ * Anthropic AI Provider Implementation
4
+ *
5
+ * Implements AIProvider interface using Anthropic SDK directly.
6
+ * Supports streaming for long operations and debug logging.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.AnthropicProvider = void 0;
46
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const crypto = __importStar(require("crypto"));
50
+ class AnthropicProvider {
51
+ client;
52
+ apiKey;
53
+ model;
54
+ debugMode;
55
+ constructor(config) {
56
+ this.apiKey = config.apiKey;
57
+ this.model = config.model || this.getDefaultModel();
58
+ this.debugMode = config.debugMode ?? (process.env.DEBUG_DOT_AI === 'true');
59
+ this.validateApiKey();
60
+ this.client = new sdk_1.default({
61
+ apiKey: this.apiKey,
62
+ });
63
+ }
64
+ validateApiKey() {
65
+ if (!this.apiKey) {
66
+ throw new Error('API key is required for Anthropic provider');
67
+ }
68
+ if (this.apiKey.length === 0) {
69
+ throw new Error('Invalid API key: API key cannot be empty');
70
+ }
71
+ }
72
+ getProviderType() {
73
+ return 'anthropic';
74
+ }
75
+ getDefaultModel() {
76
+ return 'claude-sonnet-4-5-20250929';
77
+ }
78
+ isInitialized() {
79
+ return this.client !== undefined;
80
+ }
81
+ /**
82
+ * Create debug directory if it doesn't exist
83
+ */
84
+ ensureDebugDirectory() {
85
+ const debugDir = path.join(process.cwd(), 'tmp', 'debug-ai');
86
+ if (!fs.existsSync(debugDir)) {
87
+ fs.mkdirSync(debugDir, { recursive: true });
88
+ }
89
+ return debugDir;
90
+ }
91
+ /**
92
+ * Generate unique identifier for debug files with operation context
93
+ */
94
+ generateDebugId(operation) {
95
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '').split('T');
96
+ const dateTime = timestamp[0] + 'T' + timestamp[1].substring(0, 6);
97
+ const randomHex = crypto.randomBytes(4).toString('hex');
98
+ return `${dateTime}_${randomHex}_${operation}`;
99
+ }
100
+ /**
101
+ * Save AI interaction for debugging when DEBUG_DOT_AI=true
102
+ */
103
+ debugLogInteraction(debugId, prompt, response, operation = 'ai_call') {
104
+ if (!this.debugMode)
105
+ return;
106
+ try {
107
+ const debugDir = this.ensureDebugDirectory();
108
+ // Save prompt with descriptive naming
109
+ const promptFile = path.join(debugDir, `${debugId}_prompt.md`);
110
+ fs.writeFileSync(promptFile, `# AI Prompt - ${operation}\n\nTimestamp: ${new Date().toISOString()}\nOperation: ${operation}\n\n---\n\n${prompt}`);
111
+ // Save response with matching naming
112
+ const responseFile = path.join(debugDir, `${debugId}_response.md`);
113
+ const responseContent = `# AI Response - ${operation}
114
+
115
+ Timestamp: ${new Date().toISOString()}
116
+ Operation: ${operation}
117
+ Input Tokens: ${response.usage.input_tokens}
118
+ Output Tokens: ${response.usage.output_tokens}
119
+
120
+ ---
121
+
122
+ ${response.content}`;
123
+ fs.writeFileSync(responseFile, responseContent);
124
+ console.log(`🐛 DEBUG: AI interaction logged to tmp/debug-ai/${debugId}_*.md`);
125
+ }
126
+ catch (error) {
127
+ console.warn('Failed to log AI debug interaction:', error);
128
+ }
129
+ }
130
+ async sendMessage(message, operation = 'generic') {
131
+ if (!this.client) {
132
+ throw new Error('Anthropic client not initialized');
133
+ }
134
+ try {
135
+ // Make real API call to Anthropic with streaming
136
+ const stream = await this.client.messages.create({
137
+ model: this.model,
138
+ max_tokens: 64000,
139
+ messages: [{ role: 'user', content: message }],
140
+ stream: true // Enable streaming by default to support long operations (>10 minutes)
141
+ });
142
+ let content = '';
143
+ let input_tokens = 0;
144
+ let output_tokens = 0;
145
+ for await (const chunk of stream) {
146
+ if (chunk.type === 'message_start') {
147
+ input_tokens = chunk.message.usage.input_tokens;
148
+ }
149
+ else if (chunk.type === 'content_block_delta') {
150
+ if (chunk.delta.type === 'text_delta') {
151
+ content += chunk.delta.text;
152
+ }
153
+ }
154
+ else if (chunk.type === 'message_delta') {
155
+ output_tokens = chunk.usage.output_tokens;
156
+ }
157
+ }
158
+ const response = {
159
+ content,
160
+ usage: {
161
+ input_tokens,
162
+ output_tokens
163
+ }
164
+ };
165
+ // Debug log the interaction if enabled
166
+ if (this.debugMode) {
167
+ const debugId = this.generateDebugId(operation);
168
+ this.debugLogInteraction(debugId, message, response, operation);
169
+ }
170
+ return response;
171
+ }
172
+ catch (error) {
173
+ throw new Error(`Anthropic API error: ${error}`);
174
+ }
175
+ }
176
+ }
177
+ exports.AnthropicProvider = AnthropicProvider;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Vercel AI Provider Implementation
3
+ *
4
+ * Implements AIProvider interface using Vercel AI SDK.
5
+ * Supports OpenAI and Google Gemini providers through unified interface.
6
+ */
7
+ import { AIProvider, AIResponse, AIProviderConfig } from '../ai-provider.interface';
8
+ export declare class VercelProvider implements AIProvider {
9
+ private providerType;
10
+ private model;
11
+ private apiKey;
12
+ private debugMode;
13
+ private modelInstance;
14
+ constructor(config: AIProviderConfig);
15
+ private validateConfiguration;
16
+ private initializeModel;
17
+ getProviderType(): string;
18
+ getDefaultModel(): string;
19
+ isInitialized(): boolean;
20
+ /**
21
+ * Create debug directory if it doesn't exist
22
+ */
23
+ private ensureDebugDirectory;
24
+ /**
25
+ * Generate unique identifier for debug files with operation context
26
+ */
27
+ private generateDebugId;
28
+ /**
29
+ * Save AI interaction for debugging when DEBUG_DOT_AI=true
30
+ */
31
+ private debugLogInteraction;
32
+ sendMessage(message: string, operation?: string): Promise<AIResponse>;
33
+ }
34
+ //# sourceMappingURL=vercel-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-provider.d.ts","sourceRoot":"","sources":["../../../src/core/providers/vercel-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EACL,UAAU,EACV,UAAU,EACV,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAalC,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,aAAa,CAAM;gBAEf,MAAM,EAAE,gBAAgB;IAUpC,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,eAAe;IAgCvB,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM;IAIzB,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAQ5B;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAiCrB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;CAiCvF"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ /**
3
+ * Vercel AI Provider Implementation
4
+ *
5
+ * Implements AIProvider interface using Vercel AI SDK.
6
+ * Supports OpenAI and Google Gemini providers through unified interface.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.VercelProvider = void 0;
43
+ const ai_1 = require("ai");
44
+ const openai_1 = require("@ai-sdk/openai");
45
+ const google_1 = require("@ai-sdk/google");
46
+ const anthropic_1 = require("@ai-sdk/anthropic");
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const crypto = __importStar(require("crypto"));
50
+ /**
51
+ * Provider-specific default models
52
+ */
53
+ const PROVIDER_MODELS = {
54
+ openai: 'gpt-5',
55
+ google: 'gemini-2.5-pro',
56
+ anthropic: 'claude-sonnet-4-5-20250929'
57
+ };
58
+ class VercelProvider {
59
+ providerType;
60
+ model;
61
+ apiKey;
62
+ debugMode;
63
+ modelInstance; // Vercel AI SDK model instance
64
+ constructor(config) {
65
+ this.apiKey = config.apiKey;
66
+ this.providerType = config.provider;
67
+ this.model = config.model || this.getDefaultModel();
68
+ this.debugMode = config.debugMode ?? (process.env.DEBUG_DOT_AI === 'true');
69
+ this.validateConfiguration();
70
+ this.initializeModel();
71
+ }
72
+ validateConfiguration() {
73
+ if (!this.apiKey) {
74
+ throw new Error(`API key is required for ${this.providerType} provider`);
75
+ }
76
+ if (!['openai', 'google', 'anthropic'].includes(this.providerType)) {
77
+ throw new Error(`Unsupported provider: ${this.providerType}. Must be 'openai', 'google', or 'anthropic'`);
78
+ }
79
+ }
80
+ initializeModel() {
81
+ try {
82
+ switch (this.providerType) {
83
+ case 'openai': {
84
+ const provider = (0, openai_1.createOpenAI)({
85
+ apiKey: this.apiKey
86
+ });
87
+ this.modelInstance = provider(this.model);
88
+ break;
89
+ }
90
+ case 'google': {
91
+ const provider = (0, google_1.createGoogleGenerativeAI)({
92
+ apiKey: this.apiKey
93
+ });
94
+ this.modelInstance = provider(this.model);
95
+ break;
96
+ }
97
+ case 'anthropic': {
98
+ const provider = (0, anthropic_1.createAnthropic)({
99
+ apiKey: this.apiKey
100
+ });
101
+ this.modelInstance = provider(this.model);
102
+ break;
103
+ }
104
+ default:
105
+ throw new Error(`Cannot initialize model for provider: ${this.providerType}`);
106
+ }
107
+ }
108
+ catch (error) {
109
+ throw new Error(`Failed to initialize ${this.providerType} model: ${error}`);
110
+ }
111
+ }
112
+ getProviderType() {
113
+ return this.providerType;
114
+ }
115
+ getDefaultModel() {
116
+ return PROVIDER_MODELS[this.providerType];
117
+ }
118
+ isInitialized() {
119
+ return this.modelInstance !== undefined;
120
+ }
121
+ /**
122
+ * Create debug directory if it doesn't exist
123
+ */
124
+ ensureDebugDirectory() {
125
+ const debugDir = path.join(process.cwd(), 'tmp', 'debug-ai');
126
+ if (!fs.existsSync(debugDir)) {
127
+ fs.mkdirSync(debugDir, { recursive: true });
128
+ }
129
+ return debugDir;
130
+ }
131
+ /**
132
+ * Generate unique identifier for debug files with operation context
133
+ */
134
+ generateDebugId(operation) {
135
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '').split('T');
136
+ const dateTime = timestamp[0] + 'T' + timestamp[1].substring(0, 6);
137
+ const randomHex = crypto.randomBytes(4).toString('hex');
138
+ return `${dateTime}_${randomHex}_${operation}`;
139
+ }
140
+ /**
141
+ * Save AI interaction for debugging when DEBUG_DOT_AI=true
142
+ */
143
+ debugLogInteraction(debugId, prompt, response, operation = 'ai_call') {
144
+ if (!this.debugMode)
145
+ return;
146
+ try {
147
+ const debugDir = this.ensureDebugDirectory();
148
+ // Save prompt with descriptive naming
149
+ const promptFile = path.join(debugDir, `${debugId}_prompt.md`);
150
+ fs.writeFileSync(promptFile, `# AI Prompt - ${operation}\n\nTimestamp: ${new Date().toISOString()}\nProvider: ${this.providerType}\nModel: ${this.model}\nOperation: ${operation}\n\n---\n\n${prompt}`);
151
+ // Save response with matching naming
152
+ const responseFile = path.join(debugDir, `${debugId}_response.md`);
153
+ const responseContent = `# AI Response - ${operation}
154
+
155
+ Timestamp: ${new Date().toISOString()}
156
+ Provider: ${this.providerType}
157
+ Model: ${this.model}
158
+ Operation: ${operation}
159
+ Input Tokens: ${response.usage.input_tokens}
160
+ Output Tokens: ${response.usage.output_tokens}
161
+
162
+ ---
163
+
164
+ ${response.content}`;
165
+ fs.writeFileSync(responseFile, responseContent);
166
+ console.log(`🐛 DEBUG: AI interaction logged to tmp/debug-ai/${debugId}_*.md`);
167
+ }
168
+ catch (error) {
169
+ console.warn('Failed to log AI debug interaction:', error);
170
+ }
171
+ }
172
+ async sendMessage(message, operation = 'generic') {
173
+ if (!this.isInitialized()) {
174
+ throw new Error(`${this.providerType} provider not initialized`);
175
+ }
176
+ try {
177
+ // Use Vercel AI SDK generateText
178
+ // Note: maxTokens omitted - let SDK/provider use model-specific optimal defaults
179
+ const result = await (0, ai_1.generateText)({
180
+ model: this.modelInstance,
181
+ prompt: message,
182
+ });
183
+ const response = {
184
+ content: result.text,
185
+ usage: {
186
+ input_tokens: result.usage.inputTokens || 0,
187
+ output_tokens: result.usage.outputTokens || 0
188
+ }
189
+ };
190
+ // Debug log the interaction if enabled
191
+ if (this.debugMode) {
192
+ const debugId = this.generateDebugId(operation);
193
+ this.debugLogInteraction(debugId, message, response, operation);
194
+ }
195
+ return response;
196
+ }
197
+ catch (error) {
198
+ throw new Error(`${this.providerType} API error: ${error}`);
199
+ }
200
+ }
201
+ }
202
+ exports.VercelProvider = VercelProvider;
@@ -5,6 +5,7 @@
5
5
  * Fetches structured OpenAPI schemas from Kubernetes API server and validates manifests
6
6
  */
7
7
  import { ResourceExplanation } from './discovery';
8
+ import { AIProvider } from './ai-provider.interface';
8
9
  export interface FieldConstraints {
9
10
  minimum?: number;
10
11
  maximum?: number;
@@ -97,9 +98,6 @@ export interface ResourceSolution {
97
98
  patternInfluences?: PatternInfluence[];
98
99
  usedPatterns?: boolean;
99
100
  }
100
- export interface AIRankingConfig {
101
- claudeApiKey: string;
102
- }
103
101
  export interface ClusterOptions {
104
102
  namespaces: string[];
105
103
  storageClasses: string[];
@@ -151,12 +149,11 @@ export declare class ManifestValidator {
151
149
  * ResourceRecommender determines which resources best meet user needs using AI
152
150
  */
153
151
  export declare class ResourceRecommender {
154
- private claudeIntegration;
155
- private config;
152
+ private aiProvider;
156
153
  private patternService?;
157
154
  private capabilityService?;
158
155
  private policyService?;
159
- constructor(config: AIRankingConfig);
156
+ constructor(aiProvider?: AIProvider);
160
157
  /**
161
158
  * Find the best resource solution(s) for user intent using two-phase analysis
162
159
  */
@@ -239,7 +236,7 @@ export declare class ResourceRecommender {
239
236
  .replace('{patterns}', patternsContext);
240
237
 
241
238
 
242
- const response = await this.claudeIntegration.sendMessage(selectionPrompt, 'resource-selection');
239
+ const response = await this.aiProvider.sendMessage(selectionPrompt, 'resource-selection');
243
240
 
244
241
  try {
245
242
  // Extract JSON from response with robust parsing