@ai-coders/context 0.1.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/LICENSE +21 -0
- package/README.md +658 -0
- package/dist/generators/agentGenerator.d.ts +23 -0
- package/dist/generators/agentGenerator.d.ts.map +1 -0
- package/dist/generators/agentGenerator.js +357 -0
- package/dist/generators/agentGenerator.js.map +1 -0
- package/dist/generators/documentationGenerator.d.ts +40 -0
- package/dist/generators/documentationGenerator.d.ts.map +1 -0
- package/dist/generators/documentationGenerator.js +786 -0
- package/dist/generators/documentationGenerator.js.map +1 -0
- package/dist/generators/incrementalDocumentationGenerator.d.ts +33 -0
- package/dist/generators/incrementalDocumentationGenerator.d.ts.map +1 -0
- package/dist/generators/incrementalDocumentationGenerator.js +400 -0
- package/dist/generators/incrementalDocumentationGenerator.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +559 -0
- package/dist/index.js.map +1 -0
- package/dist/services/anthropicClient.d.ts +12 -0
- package/dist/services/anthropicClient.d.ts.map +1 -0
- package/dist/services/anthropicClient.js +98 -0
- package/dist/services/anthropicClient.js.map +1 -0
- package/dist/services/baseLLMClient.d.ts +12 -0
- package/dist/services/baseLLMClient.d.ts.map +1 -0
- package/dist/services/baseLLMClient.js +41 -0
- package/dist/services/baseLLMClient.js.map +1 -0
- package/dist/services/changeAnalyzer.d.ts +44 -0
- package/dist/services/changeAnalyzer.d.ts.map +1 -0
- package/dist/services/changeAnalyzer.js +344 -0
- package/dist/services/changeAnalyzer.js.map +1 -0
- package/dist/services/geminiClient.d.ts +12 -0
- package/dist/services/geminiClient.d.ts.map +1 -0
- package/dist/services/geminiClient.js +96 -0
- package/dist/services/geminiClient.js.map +1 -0
- package/dist/services/grokClient.d.ts +12 -0
- package/dist/services/grokClient.d.ts.map +1 -0
- package/dist/services/grokClient.js +101 -0
- package/dist/services/grokClient.js.map +1 -0
- package/dist/services/llmClientFactory.d.ts +14 -0
- package/dist/services/llmClientFactory.d.ts.map +1 -0
- package/dist/services/llmClientFactory.js +109 -0
- package/dist/services/llmClientFactory.js.map +1 -0
- package/dist/services/openRouterClient.d.ts +12 -0
- package/dist/services/openRouterClient.d.ts.map +1 -0
- package/dist/services/openRouterClient.js +96 -0
- package/dist/services/openRouterClient.js.map +1 -0
- package/dist/services/openaiClient.d.ts +12 -0
- package/dist/services/openaiClient.d.ts.map +1 -0
- package/dist/services/openaiClient.js +98 -0
- package/dist/services/openaiClient.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cliUI.d.ts +25 -0
- package/dist/utils/cliUI.d.ts.map +1 -0
- package/dist/utils/cliUI.js +236 -0
- package/dist/utils/cliUI.js.map +1 -0
- package/dist/utils/fileMapper.d.ts +11 -0
- package/dist/utils/fileMapper.d.ts.map +1 -0
- package/dist/utils/fileMapper.js +125 -0
- package/dist/utils/fileMapper.js.map +1 -0
- package/dist/utils/gitService.d.ts +50 -0
- package/dist/utils/gitService.d.ts.map +1 -0
- package/dist/utils/gitService.js +470 -0
- package/dist/utils/gitService.js.map +1 -0
- package/dist/utils/interactiveMode.d.ts +16 -0
- package/dist/utils/interactiveMode.d.ts.map +1 -0
- package/dist/utils/interactiveMode.js +432 -0
- package/dist/utils/interactiveMode.js.map +1 -0
- package/dist/utils/pricing.d.ts +14 -0
- package/dist/utils/pricing.d.ts.map +1 -0
- package/dist/utils/pricing.js +115 -0
- package/dist/utils/pricing.js.map +1 -0
- package/dist/utils/tokenEstimator.d.ts +27 -0
- package/dist/utils/tokenEstimator.d.ts.map +1 -0
- package/dist/utils/tokenEstimator.js +198 -0
- package/dist/utils/tokenEstimator.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeminiClient = void 0;
|
|
4
|
+
const genai_1 = require("@google/genai");
|
|
5
|
+
const baseLLMClient_1 = require("./baseLLMClient");
|
|
6
|
+
class GeminiClient extends baseLLMClient_1.BaseLLMClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config.model);
|
|
9
|
+
this.model = config.model;
|
|
10
|
+
this.client = new genai_1.GoogleGenAI({ apiKey: config.apiKey });
|
|
11
|
+
}
|
|
12
|
+
async generateText(prompt, systemPrompt) {
|
|
13
|
+
try {
|
|
14
|
+
const fullPrompt = systemPrompt
|
|
15
|
+
? `System: ${systemPrompt}\n\nUser: ${prompt}`
|
|
16
|
+
: prompt;
|
|
17
|
+
const response = await this.client.models.generateContent({
|
|
18
|
+
model: this.model,
|
|
19
|
+
contents: fullPrompt
|
|
20
|
+
});
|
|
21
|
+
const text = response.text || '';
|
|
22
|
+
// Google AI doesn't provide detailed usage stats in the free tier
|
|
23
|
+
// We'll estimate based on content length
|
|
24
|
+
const estimatedPromptTokens = Math.ceil(fullPrompt.length / 4);
|
|
25
|
+
const estimatedCompletionTokens = Math.ceil(text.length / 4);
|
|
26
|
+
this.trackUsage({
|
|
27
|
+
prompt_tokens: estimatedPromptTokens,
|
|
28
|
+
completion_tokens: estimatedCompletionTokens,
|
|
29
|
+
total_tokens: estimatedPromptTokens + estimatedCompletionTokens
|
|
30
|
+
}, this.calculateGeminiCost.bind(this));
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`Gemini API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
calculateGeminiCost(promptTokens, completionTokens) {
|
|
38
|
+
// Google AI pricing (as of 2024) - per 1M tokens
|
|
39
|
+
const prices = {
|
|
40
|
+
'gemini-pro': { input: 0.5, output: 1.5 },
|
|
41
|
+
'gemini-1.5-pro': { input: 3.5, output: 10.5 },
|
|
42
|
+
'gemini-1.5-flash': { input: 0.075, output: 0.3 },
|
|
43
|
+
'gemini-2.0-flash-exp': { input: 0.075, output: 0.3 },
|
|
44
|
+
'gemini-2.0-flash-001': { input: 0.075, output: 0.3 }
|
|
45
|
+
};
|
|
46
|
+
const pricing = prices[this.model] || prices['gemini-pro']; // fallback
|
|
47
|
+
const inputCost = (promptTokens / 1000000) * pricing.input;
|
|
48
|
+
const outputCost = (completionTokens / 1000000) * pricing.output;
|
|
49
|
+
return inputCost + outputCost;
|
|
50
|
+
}
|
|
51
|
+
async generateDocumentation(codeContent, filePath, context) {
|
|
52
|
+
const systemPrompt = `You are a technical documentation expert. Generate clear, comprehensive documentation for the provided code file. Include:
|
|
53
|
+
1. Purpose and overview
|
|
54
|
+
2. Key components/functions
|
|
55
|
+
3. Dependencies and relationships
|
|
56
|
+
4. Usage examples where applicable
|
|
57
|
+
5. Important notes or gotchas
|
|
58
|
+
|
|
59
|
+
Focus on being practical and helpful for developers working with this codebase.`;
|
|
60
|
+
const prompt = `File: ${filePath}
|
|
61
|
+
|
|
62
|
+
Context: ${context}
|
|
63
|
+
|
|
64
|
+
Code:
|
|
65
|
+
\`\`\`
|
|
66
|
+
${codeContent}
|
|
67
|
+
\`\`\`
|
|
68
|
+
|
|
69
|
+
Generate comprehensive documentation for this file.`;
|
|
70
|
+
return this.generateText(prompt, systemPrompt);
|
|
71
|
+
}
|
|
72
|
+
async generateAgentPrompt(repoStructure, fileContext, agentType) {
|
|
73
|
+
const systemPrompt = `You are an expert at creating AI agent prompts for software development. Create a specialized prompt that would help an AI assistant understand and work effectively with this specific codebase.
|
|
74
|
+
|
|
75
|
+
The prompt should include:
|
|
76
|
+
1. Clear understanding of the codebase structure and patterns
|
|
77
|
+
2. Key conventions and best practices used in this project
|
|
78
|
+
3. Important files and their purposes
|
|
79
|
+
4. Common tasks and workflows
|
|
80
|
+
5. Specific guidance for the agent type requested
|
|
81
|
+
|
|
82
|
+
Make the prompt practical and actionable.`;
|
|
83
|
+
const prompt = `Codebase Structure:
|
|
84
|
+
${repoStructure}
|
|
85
|
+
|
|
86
|
+
File Context:
|
|
87
|
+
${fileContext}
|
|
88
|
+
|
|
89
|
+
Agent Type: ${agentType}
|
|
90
|
+
|
|
91
|
+
Generate a comprehensive agent prompt that would help an AI assistant work effectively with this codebase for ${agentType} tasks.`;
|
|
92
|
+
return this.generateText(prompt, systemPrompt);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.GeminiClient = GeminiClient;
|
|
96
|
+
//# sourceMappingURL=geminiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiClient.js","sourceRoot":"","sources":["../../src/services/geminiClient.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,mDAAgD;AAEhD,MAAa,YAAa,SAAQ,6BAAa;IAI7C,YAAY,MAAiB;QAC3B,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,mBAAW,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAAc,EAAE,YAAqB;QACtD,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,YAAY;gBAC7B,CAAC,CAAC,WAAW,YAAY,aAAa,MAAM,EAAE;gBAC9C,CAAC,CAAC,MAAM,CAAC;YAEX,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;gBACxD,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,QAAQ,EAAE,UAAU;aACrB,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;YAEjC,kEAAkE;YAClE,yCAAyC;YACzC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,C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,GAAG,CAAC,gBAAgB,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;QAEjE,OAAO,SAAS,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,WAAmB,EACnB,QAAgB,EAChB,OAAe;QAEf,MAAM,YAAY,GAAG;;;;;;;oFAO2D,CAAC;QAEjF,MAAM,MAAM,GAAG,SAAS,QAAQ;;WAEzB,OAAO;;;;EAIhB,WAAW;;;oDAGuC,CAAC;QAEjD,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,aAAqB,EACrB,WAAmB,EACnB,SAAiB;QAEjB,MAAM,YAAY,GAAG;;;;;;;;;0CASiB,CAAC;QAEvC,MAAM,MAAM,GAAG;EACjB,aAAa;;;EAGb,WAAW;;cAEC,SAAS;;gHAEyF,SAAS,SAAS,CAAC;QAE/H,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC;CACF;AAjHD,oCAiHC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LLMConfig } from '../types';
|
|
2
|
+
import { BaseLLMClient } from './baseLLMClient';
|
|
3
|
+
export declare class GrokClient extends BaseLLMClient {
|
|
4
|
+
private client;
|
|
5
|
+
private model;
|
|
6
|
+
constructor(config: LLMConfig);
|
|
7
|
+
generateText(prompt: string, systemPrompt?: string): Promise<string>;
|
|
8
|
+
private calculateGrokCost;
|
|
9
|
+
generateDocumentation(codeContent: string, filePath: string, context: string): Promise<string>;
|
|
10
|
+
generateAgentPrompt(repoStructure: string, fileContext: string, agentType: string): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=grokClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokClient.d.ts","sourceRoot":"","sources":["../../src/services/grokClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,UAAW,SAAQ,aAAa;IAC3C,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,KAAK,CAAS;gBAEV,MAAM,EAAE,SAAS;IAYvB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6B1E,OAAO,CAAC,iBAAiB;IAcnB,qBAAqB,CACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAwBZ,mBAAmB,CACvB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC;CAwBnB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GrokClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const baseLLMClient_1 = require("./baseLLMClient");
|
|
9
|
+
class GrokClient extends baseLLMClient_1.BaseLLMClient {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super(config.model);
|
|
12
|
+
this.model = config.model;
|
|
13
|
+
this.client = axios_1.default.create({
|
|
14
|
+
baseURL: config.baseUrl || 'https://api.x.ai/v1',
|
|
15
|
+
headers: {
|
|
16
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async generateText(prompt, systemPrompt) {
|
|
22
|
+
try {
|
|
23
|
+
const messages = [];
|
|
24
|
+
if (systemPrompt) {
|
|
25
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
26
|
+
}
|
|
27
|
+
messages.push({ role: 'user', content: prompt });
|
|
28
|
+
const response = await this.client.post('/chat/completions', {
|
|
29
|
+
model: this.model,
|
|
30
|
+
messages,
|
|
31
|
+
max_tokens: 4000,
|
|
32
|
+
temperature: 0.7
|
|
33
|
+
});
|
|
34
|
+
// Track usage statistics
|
|
35
|
+
this.trackUsage(response.data.usage, this.calculateGrokCost.bind(this));
|
|
36
|
+
return response.data.choices[0]?.message?.content || '';
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
40
|
+
throw new Error(`Grok API error: ${error.response?.data?.error?.message || error.message}`);
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
calculateGrokCost(promptTokens, completionTokens) {
|
|
46
|
+
// Grok pricing (as of 2024) - per 1M tokens
|
|
47
|
+
const prices = {
|
|
48
|
+
'grok-beta': { input: 5.0, output: 15.0 },
|
|
49
|
+
'grok-vision-beta': { input: 5.0, output: 15.0 }
|
|
50
|
+
};
|
|
51
|
+
const pricing = prices[this.model] || prices['grok-beta']; // fallback
|
|
52
|
+
const inputCost = (promptTokens / 1000000) * pricing.input;
|
|
53
|
+
const outputCost = (completionTokens / 1000000) * pricing.output;
|
|
54
|
+
return inputCost + outputCost;
|
|
55
|
+
}
|
|
56
|
+
async generateDocumentation(codeContent, filePath, context) {
|
|
57
|
+
const systemPrompt = `You are a technical documentation expert. Generate clear, comprehensive documentation for the provided code file. Include:
|
|
58
|
+
1. Purpose and overview
|
|
59
|
+
2. Key components/functions
|
|
60
|
+
3. Dependencies and relationships
|
|
61
|
+
4. Usage examples where applicable
|
|
62
|
+
5. Important notes or gotchas
|
|
63
|
+
|
|
64
|
+
Focus on being practical and helpful for developers working with this codebase.`;
|
|
65
|
+
const prompt = `File: ${filePath}
|
|
66
|
+
|
|
67
|
+
Context: ${context}
|
|
68
|
+
|
|
69
|
+
Code:
|
|
70
|
+
\`\`\`
|
|
71
|
+
${codeContent}
|
|
72
|
+
\`\`\`
|
|
73
|
+
|
|
74
|
+
Generate comprehensive documentation for this file.`;
|
|
75
|
+
return this.generateText(prompt, systemPrompt);
|
|
76
|
+
}
|
|
77
|
+
async generateAgentPrompt(repoStructure, fileContext, agentType) {
|
|
78
|
+
const systemPrompt = `You are an expert at creating AI agent prompts for software development. Create a specialized prompt that would help an AI assistant understand and work effectively with this specific codebase.
|
|
79
|
+
|
|
80
|
+
The prompt should include:
|
|
81
|
+
1. Clear understanding of the codebase structure and patterns
|
|
82
|
+
2. Key conventions and best practices used in this project
|
|
83
|
+
3. Important files and their purposes
|
|
84
|
+
4. Common tasks and workflows
|
|
85
|
+
5. Specific guidance for the agent type requested
|
|
86
|
+
|
|
87
|
+
Make the prompt practical and actionable.`;
|
|
88
|
+
const prompt = `Codebase Structure:
|
|
89
|
+
${repoStructure}
|
|
90
|
+
|
|
91
|
+
File Context:
|
|
92
|
+
${fileContext}
|
|
93
|
+
|
|
94
|
+
Agent Type: ${agentType}
|
|
95
|
+
|
|
96
|
+
Generate a comprehensive agent prompt that would help an AI assistant work effectively with this codebase for ${agentType} tasks.`;
|
|
97
|
+
return this.generateText(prompt, systemPrompt);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.GrokClient = GrokClient;
|
|
101
|
+
//# sourceMappingURL=grokClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grokClient.js","sourceRoot":"","sources":["../../src/services/grokClient.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAE7C,mDAAgD;AAEhD,MAAa,UAAW,SAAQ,6BAAa;IAI3C,YAAY,MAAiB;QAC3B,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpB,IAA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AM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC;CACF;AAnHD,gCAmHC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LLMConfig } from '../types';
|
|
2
|
+
import { BaseLLMClient } from './baseLLMClient';
|
|
3
|
+
export declare class LLMClientFactory {
|
|
4
|
+
static createClient(config: LLMConfig): BaseLLMClient;
|
|
5
|
+
static detectProviderFromModel(model: string): LLMConfig['provider'];
|
|
6
|
+
static getProviderFromApiKey(apiKey: string): LLMConfig['provider'];
|
|
7
|
+
static getDefaultModels(): {
|
|
8
|
+
[key in LLMConfig['provider']]: string[];
|
|
9
|
+
};
|
|
10
|
+
static getEnvironmentVariables(): {
|
|
11
|
+
[key in LLMConfig['provider']]: string[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=llmClientFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llmClientFactory.d.ts","sourceRoot":"","sources":["../../src/services/llmClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOhD,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa;IA0BrD,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC;IAapE,MAAM,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC;IAenE,MAAM,CAAC,gBAAgB,IAAI;SAAG,GAAG,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,MAAM,EAAE;KAAE;IAmCvE,MAAM,CAAC,uBAAuB,IAAI;SAAG,GAAG,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,MAAM,EAAE;KAAE;CAS/E"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LLMClientFactory = void 0;
|
|
4
|
+
const openRouterClient_1 = require("./openRouterClient");
|
|
5
|
+
const openaiClient_1 = require("./openaiClient");
|
|
6
|
+
const anthropicClient_1 = require("./anthropicClient");
|
|
7
|
+
const geminiClient_1 = require("./geminiClient");
|
|
8
|
+
const grokClient_1 = require("./grokClient");
|
|
9
|
+
class LLMClientFactory {
|
|
10
|
+
static createClient(config) {
|
|
11
|
+
switch (config.provider) {
|
|
12
|
+
case 'openai':
|
|
13
|
+
return new openaiClient_1.OpenAIClient(config);
|
|
14
|
+
case 'anthropic':
|
|
15
|
+
return new anthropicClient_1.AnthropicClient(config);
|
|
16
|
+
case 'gemini':
|
|
17
|
+
return new geminiClient_1.GeminiClient(config);
|
|
18
|
+
case 'grok':
|
|
19
|
+
return new grokClient_1.GrokClient(config);
|
|
20
|
+
case 'openrouter':
|
|
21
|
+
default:
|
|
22
|
+
// Convert LLMConfig to OpenRouterConfig for backward compatibility
|
|
23
|
+
const openRouterConfig = {
|
|
24
|
+
apiKey: config.apiKey,
|
|
25
|
+
baseUrl: config.baseUrl || 'https://openrouter.ai/api/v1',
|
|
26
|
+
model: config.model
|
|
27
|
+
};
|
|
28
|
+
return new openRouterClient_1.OpenRouterClient(openRouterConfig);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
static detectProviderFromModel(model) {
|
|
32
|
+
if (model.startsWith('gpt-')) {
|
|
33
|
+
return 'openai';
|
|
34
|
+
}
|
|
35
|
+
else if (model.startsWith('claude-')) {
|
|
36
|
+
return 'anthropic';
|
|
37
|
+
}
|
|
38
|
+
else if (model.includes('gemini')) {
|
|
39
|
+
return 'gemini';
|
|
40
|
+
}
|
|
41
|
+
else if (model.includes('grok')) {
|
|
42
|
+
return 'grok';
|
|
43
|
+
}
|
|
44
|
+
return 'openrouter'; // default
|
|
45
|
+
}
|
|
46
|
+
static getProviderFromApiKey(apiKey) {
|
|
47
|
+
if (apiKey.startsWith('sk-') && !apiKey.includes('or-v1')) {
|
|
48
|
+
return 'openai';
|
|
49
|
+
}
|
|
50
|
+
else if (apiKey.startsWith('sk-ant-')) {
|
|
51
|
+
return 'anthropic';
|
|
52
|
+
}
|
|
53
|
+
else if (apiKey.startsWith('AIza')) {
|
|
54
|
+
return 'gemini';
|
|
55
|
+
}
|
|
56
|
+
else if (apiKey.startsWith('xai-')) {
|
|
57
|
+
return 'grok';
|
|
58
|
+
}
|
|
59
|
+
else if (apiKey.includes('or-v1')) {
|
|
60
|
+
return 'openrouter';
|
|
61
|
+
}
|
|
62
|
+
return 'openrouter'; // default fallback
|
|
63
|
+
}
|
|
64
|
+
static getDefaultModels() {
|
|
65
|
+
return {
|
|
66
|
+
openrouter: [
|
|
67
|
+
'google/gemini-2.5-flash-preview-05-20',
|
|
68
|
+
'anthropic/claude-3-sonnet',
|
|
69
|
+
'anthropic/claude-3-opus',
|
|
70
|
+
'openai/gpt-4',
|
|
71
|
+
'openai/gpt-3.5-turbo',
|
|
72
|
+
'google/gemini-pro',
|
|
73
|
+
'meta-llama/llama-3.1-70b-instruct'
|
|
74
|
+
],
|
|
75
|
+
openai: [
|
|
76
|
+
'gpt-4',
|
|
77
|
+
'gpt-4-turbo',
|
|
78
|
+
'gpt-3.5-turbo'
|
|
79
|
+
],
|
|
80
|
+
anthropic: [
|
|
81
|
+
'claude-3-haiku-20240307',
|
|
82
|
+
'claude-3-sonnet-20240229',
|
|
83
|
+
'claude-3-opus-20240229',
|
|
84
|
+
'claude-3-5-sonnet-20241022'
|
|
85
|
+
],
|
|
86
|
+
gemini: [
|
|
87
|
+
'gemini-pro',
|
|
88
|
+
'gemini-1.5-pro',
|
|
89
|
+
'gemini-1.5-flash',
|
|
90
|
+
'gemini-2.0-flash-exp'
|
|
91
|
+
],
|
|
92
|
+
grok: [
|
|
93
|
+
'grok-beta',
|
|
94
|
+
'grok-vision-beta'
|
|
95
|
+
]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
static getEnvironmentVariables() {
|
|
99
|
+
return {
|
|
100
|
+
openrouter: ['OPENROUTER_API_KEY'],
|
|
101
|
+
openai: ['OPENAI_API_KEY'],
|
|
102
|
+
anthropic: ['ANTHROPIC_API_KEY'],
|
|
103
|
+
gemini: ['GOOGLE_AI_API_KEY', 'GEMINI_API_KEY'],
|
|
104
|
+
grok: ['GROK_API_KEY', 'XAI_API_KEY']
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.LLMClientFactory = LLMClientFactory;
|
|
109
|
+
//# sourceMappingURL=llmClientFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llmClientFactory.js","sourceRoot":"","sources":["../../src/services/llmClientFactory.ts"],"names":[],"mappings":";;;AAEA,yDAAsD;AACtD,iDAA8C;AAC9C,uDAAoD;AACpD,iDAA8C;AAC9C,6CAA0C;AAE1C,MAAa,gBAAgB;IAC3B,MAAM,CAAC,YAAY,CAAC,MAAiB;QACnC,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,QAAQ;gBACX,OAAO,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAC;YAElC,KAAK,WAAW;gBACd,OAAO,IAAI,iCAAe,CAAC,MAAM,CAAC,CAAC;YAErC,KAAK,QAAQ;gBACX,OAAO,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAC;YAElC,KAAK,MAAM;gBACT,OAAO,IAAI,uBAAU,CAAC,MAAM,CAAC,CAAC;YAEhC,KAAK,YAAY,CAAC;YAClB;gBACE,mEAAmE;gBACnE,MAAM,gBAAgB,GAAqB;oBACzC,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,8BAA8B;oBACzD,KAAK,EAAE,MAAM,CAAC,KAAK;iBACpB,CAAC;gBACF,OAAO,IAAI,mCAAgB,CAAC,gBAAgB,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AyB;gBACzB,cAAc;gBACd,sBAAsB;gBACtB,mBAAmB;gBACnB,mCAAmC;aACpC;YACD,MAAM,EAAE;gBACN,OAAO;gBACP,aAAa;gBACb,eAAe;aAChB;YACD,SAAS,EAAE;gBACT,yBAAyB;gBACzB,0BAA0B;gBAC1B,wBAAwB;gBACxB,4BAA4B;aAC7B;YACD,MAAM,EAAE;gBACN,YAAY;gBACZ,gBAAgB;gBAChB,kBAAkB;gBAClB,sBAAsB;aACvB;YACD,IAAI,EAAE;gBACJ,WAAW;gBACX,kBAAkB;aACnB;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,uBAAuB;QAC5B,OAAO;YACL,UAAU,EAAE,CAAC,oBAAoB,CAAC;YAClC,MAAM,EAAE,CAAC,gBAAgB,CAAC;YAC1B,SAAS,EAAE,CAAC,mBAAmB,CAAC;YAChC,MAAM,EAAE,CAAC,mBAAmB,EAAE,gBAAgB,CAAC;YAC/C,IAAI,EAAE,CAAC,cAAc,EAAE,aAAa,CAAC;SACtC,CAAC;IACJ,CAAC;CACF;AAnGD,4CAmGC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OpenRouterConfig } from '../types';
|
|
2
|
+
import { BaseLLMClient } from './baseLLMClient';
|
|
3
|
+
export declare class OpenRouterClient extends BaseLLMClient {
|
|
4
|
+
private client;
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: OpenRouterConfig);
|
|
7
|
+
generateText(prompt: string, systemPrompt?: string): Promise<string>;
|
|
8
|
+
private calculateOpenRouterCost;
|
|
9
|
+
generateDocumentation(codeContent: string, filePath: string, context: string): Promise<string>;
|
|
10
|
+
generateAgentPrompt(repoStructure: string, fileContext: string, agentType: string): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=openRouterClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openRouterClient.d.ts","sourceRoot":"","sources":["../../src/services/openRouterClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,gBAAgB;IAc9B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6B1E,OAAO,CAAC,uBAAuB;IAIzB,qBAAqB,CACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAwBZ,mBAAmB,CACvB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC;CAwBnB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OpenRouterClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const pricing_1 = require("../utils/pricing");
|
|
9
|
+
const baseLLMClient_1 = require("./baseLLMClient");
|
|
10
|
+
class OpenRouterClient extends baseLLMClient_1.BaseLLMClient {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config.model);
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.client = axios_1.default.create({
|
|
15
|
+
baseURL: config.baseUrl || 'https://openrouter.ai/api/v1',
|
|
16
|
+
headers: {
|
|
17
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'HTTP-Referer': 'https://ai-coders-context',
|
|
20
|
+
'X-Title': 'AI Coders Context'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async generateText(prompt, systemPrompt) {
|
|
25
|
+
try {
|
|
26
|
+
const messages = [];
|
|
27
|
+
if (systemPrompt) {
|
|
28
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
29
|
+
}
|
|
30
|
+
messages.push({ role: 'user', content: prompt });
|
|
31
|
+
const response = await this.client.post('/chat/completions', {
|
|
32
|
+
model: this.config.model || 'google/gemini-2.5-pro',
|
|
33
|
+
messages,
|
|
34
|
+
max_tokens: 4000,
|
|
35
|
+
temperature: 0.7
|
|
36
|
+
});
|
|
37
|
+
// Track usage statistics
|
|
38
|
+
this.trackUsage(response.data.usage, this.calculateOpenRouterCost.bind(this));
|
|
39
|
+
return response.data.choices[0]?.message?.content || '';
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
43
|
+
throw new Error(`OpenRouter API error: ${error.response?.data?.error?.message || error.message}`);
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
calculateOpenRouterCost(promptTokens, completionTokens) {
|
|
49
|
+
return (0, pricing_1.calculateCost)(this.config.model || 'google/gemini-2.5-pro', promptTokens, completionTokens);
|
|
50
|
+
}
|
|
51
|
+
async generateDocumentation(codeContent, filePath, context) {
|
|
52
|
+
const systemPrompt = `You are a technical documentation expert. Generate clear, comprehensive documentation for the provided code file. Include:
|
|
53
|
+
1. Purpose and overview
|
|
54
|
+
2. Key components/functions
|
|
55
|
+
3. Dependencies and relationships
|
|
56
|
+
4. Usage examples where applicable
|
|
57
|
+
5. Important notes or gotchas
|
|
58
|
+
|
|
59
|
+
Focus on being practical and helpful for developers working with this codebase.`;
|
|
60
|
+
const prompt = `File: ${filePath}
|
|
61
|
+
|
|
62
|
+
Context: ${context}
|
|
63
|
+
|
|
64
|
+
Code:
|
|
65
|
+
\`\`\`
|
|
66
|
+
${codeContent}
|
|
67
|
+
\`\`\`
|
|
68
|
+
|
|
69
|
+
Generate comprehensive documentation for this file.`;
|
|
70
|
+
return this.generateText(prompt, systemPrompt);
|
|
71
|
+
}
|
|
72
|
+
async generateAgentPrompt(repoStructure, fileContext, agentType) {
|
|
73
|
+
const systemPrompt = `You are an expert at creating AI agent prompts for software development. Create a specialized prompt that would help an AI assistant understand and work effectively with this specific codebase.
|
|
74
|
+
|
|
75
|
+
The prompt should include:
|
|
76
|
+
1. Clear understanding of the codebase structure and patterns
|
|
77
|
+
2. Key conventions and best practices used in this project
|
|
78
|
+
3. Important files and their purposes
|
|
79
|
+
4. Common tasks and workflows
|
|
80
|
+
5. Specific guidance for the agent type requested
|
|
81
|
+
|
|
82
|
+
Make the prompt practical and actionable.`;
|
|
83
|
+
const prompt = `Codebase Structure:
|
|
84
|
+
${repoStructure}
|
|
85
|
+
|
|
86
|
+
File Context:
|
|
87
|
+
${fileContext}
|
|
88
|
+
|
|
89
|
+
Agent Type: ${agentType}
|
|
90
|
+
|
|
91
|
+
Generate a comprehensive agent prompt that would help an AI assistant work effectively with this codebase for ${agentType} tasks.`;
|
|
92
|
+
return this.generateText(prompt, systemPrompt);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.OpenRouterClient = OpenRouterClient;
|
|
96
|
+
//# sourceMappingURL=openRouterClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openRouterClient.js","sourceRoot":"","sources":["../../src/services/openRouterClient.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAE7C,8CAAiD;AACjD,mDAAgD;AAEhD,MAAa,gBAAiB,SAAQ,6BAAa;IAIjD,YAAY,MAAwB;QAClC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,eAA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C,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACpG,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,uBAAuB,CAAC,YAAoB,EAAE,gBAAwB;QAC5E,OAAO,IAAA,uBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,uBAAuB,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC;IACrG,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,WAAmB,EACnB,QAAgB,EAChB,OAAe;QAEf,MAAM,YAAY,GAAG;;;;;;;oFAO2D,CAAC;QAEjF,MAAM,MAAM,GAAG,SAAS,QAAQ;;WAEzB,OAAO;;;;EAIhB,WAAW;;;oDAGuC,CAAC;QAEjD,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,aAAqB,EACrB,WAAmB,EACnB,SAAiB;QAEjB,MAAM,YAAY,GAAG;;;;;;;;;0CASiB,CAAC;QAEvC,MAAM,MAAM,GAAG;EACjB,aAAa;;;EAGb,WAAW;;cAEC,SAAS;;gHAEyF,SAAS,SAAS,CAAC;QAE/H,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC;CACF;AA3GD,4CA2GC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LLMConfig } from '../types';
|
|
2
|
+
import { BaseLLMClient } from './baseLLMClient';
|
|
3
|
+
export declare class OpenAIClient extends BaseLLMClient {
|
|
4
|
+
private client;
|
|
5
|
+
private model;
|
|
6
|
+
constructor(config: LLMConfig);
|
|
7
|
+
generateText(prompt: string, systemPrompt?: string): Promise<string>;
|
|
8
|
+
private calculateOpenAICost;
|
|
9
|
+
generateDocumentation(codeContent: string, filePath: string, context: string): Promise<string>;
|
|
10
|
+
generateAgentPrompt(repoStructure: string, fileContext: string, agentType: string): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=openaiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openaiClient.d.ts","sourceRoot":"","sources":["../../src/services/openaiClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,YAAa,SAAQ,aAAa;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;gBAEV,MAAM,EAAE,SAAS;IASvB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0B1E,OAAO,CAAC,mBAAmB;IAiBrB,qBAAqB,CACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAwBZ,mBAAmB,CACvB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC;CAwBnB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OpenAIClient = void 0;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
const baseLLMClient_1 = require("./baseLLMClient");
|
|
9
|
+
class OpenAIClient extends baseLLMClient_1.BaseLLMClient {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super(config.model);
|
|
12
|
+
this.model = config.model;
|
|
13
|
+
this.client = new openai_1.default({
|
|
14
|
+
apiKey: config.apiKey,
|
|
15
|
+
baseURL: config.baseUrl
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async generateText(prompt, systemPrompt) {
|
|
19
|
+
try {
|
|
20
|
+
const messages = [];
|
|
21
|
+
if (systemPrompt) {
|
|
22
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
23
|
+
}
|
|
24
|
+
messages.push({ role: 'user', content: prompt });
|
|
25
|
+
const response = await this.client.chat.completions.create({
|
|
26
|
+
model: this.model,
|
|
27
|
+
messages,
|
|
28
|
+
max_tokens: 4000,
|
|
29
|
+
temperature: 0.7
|
|
30
|
+
});
|
|
31
|
+
// Track usage statistics
|
|
32
|
+
this.trackUsage(response.usage, this.calculateOpenAICost.bind(this));
|
|
33
|
+
return response.choices[0]?.message?.content || '';
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw new Error(`OpenAI API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
calculateOpenAICost(promptTokens, completionTokens) {
|
|
40
|
+
// OpenAI pricing (as of 2024)
|
|
41
|
+
const prices = {
|
|
42
|
+
'gpt-4': { input: 30.0, output: 60.0 },
|
|
43
|
+
'gpt-4-turbo': { input: 10.0, output: 30.0 },
|
|
44
|
+
'gpt-4-turbo-preview': { input: 10.0, output: 30.0 },
|
|
45
|
+
'gpt-3.5-turbo': { input: 1.0, output: 2.0 },
|
|
46
|
+
'gpt-3.5-turbo-16k': { input: 3.0, output: 4.0 }
|
|
47
|
+
};
|
|
48
|
+
const pricing = prices[this.model] || prices['gpt-3.5-turbo']; // fallback
|
|
49
|
+
const inputCost = (promptTokens / 1000000) * pricing.input;
|
|
50
|
+
const outputCost = (completionTokens / 1000000) * pricing.output;
|
|
51
|
+
return inputCost + outputCost;
|
|
52
|
+
}
|
|
53
|
+
async generateDocumentation(codeContent, filePath, context) {
|
|
54
|
+
const systemPrompt = `You are a technical documentation expert. Generate clear, comprehensive documentation for the provided code file. Include:
|
|
55
|
+
1. Purpose and overview
|
|
56
|
+
2. Key components/functions
|
|
57
|
+
3. Dependencies and relationships
|
|
58
|
+
4. Usage examples where applicable
|
|
59
|
+
5. Important notes or gotchas
|
|
60
|
+
|
|
61
|
+
Focus on being practical and helpful for developers working with this codebase.`;
|
|
62
|
+
const prompt = `File: ${filePath}
|
|
63
|
+
|
|
64
|
+
Context: ${context}
|
|
65
|
+
|
|
66
|
+
Code:
|
|
67
|
+
\`\`\`
|
|
68
|
+
${codeContent}
|
|
69
|
+
\`\`\`
|
|
70
|
+
|
|
71
|
+
Generate comprehensive documentation for this file.`;
|
|
72
|
+
return this.generateText(prompt, systemPrompt);
|
|
73
|
+
}
|
|
74
|
+
async generateAgentPrompt(repoStructure, fileContext, agentType) {
|
|
75
|
+
const systemPrompt = `You are an expert at creating AI agent prompts for software development. Create a specialized prompt that would help an AI assistant understand and work effectively with this specific codebase.
|
|
76
|
+
|
|
77
|
+
The prompt should include:
|
|
78
|
+
1. Clear understanding of the codebase structure and patterns
|
|
79
|
+
2. Key conventions and best practices used in this project
|
|
80
|
+
3. Important files and their purposes
|
|
81
|
+
4. Common tasks and workflows
|
|
82
|
+
5. Specific guidance for the agent type requested
|
|
83
|
+
|
|
84
|
+
Make the prompt practical and actionable.`;
|
|
85
|
+
const prompt = `Codebase Structure:
|
|
86
|
+
${repoStructure}
|
|
87
|
+
|
|
88
|
+
File Context:
|
|
89
|
+
${fileContext}
|
|
90
|
+
|
|
91
|
+
Agent Type: ${agentType}
|
|
92
|
+
|
|
93
|
+
Generate a comprehensive agent prompt that would help an AI assistant work effectively with this codebase for ${agentType} tasks.`;
|
|
94
|
+
return this.generateText(prompt, systemPrompt);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.OpenAIClient = OpenAIClient;
|
|
98
|
+
//# sourceMappingURL=openaiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openaiClient.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