forked from superdesigndev/superdesign
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaudeCodeService.ts
More file actions
119 lines (99 loc) · 4.36 KB
/
claudeCodeService.ts
File metadata and controls
119 lines (99 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as vscode from 'vscode';
import { Logger } from './logger';
import { LLMProviderFactory } from '../providers/llmProviderFactory';
import { LLMProvider, LLMProviderOptions, LLMMessage, LLMStreamCallback } from '../providers/llmProvider';
export class ClaudeCodeService {
private providerFactory: LLMProviderFactory;
private outputChannel: vscode.OutputChannel;
constructor(outputChannel: vscode.OutputChannel) {
this.outputChannel = outputChannel;
this.providerFactory = LLMProviderFactory.getInstance(outputChannel);
}
private async getCurrentProvider(): Promise<LLMProvider> {
return await this.providerFactory.getProvider();
}
async query(prompt: string, options?: Partial<LLMProviderOptions>, abortController?: AbortController, onMessage?: LLMStreamCallback): Promise<LLMMessage[]> {
Logger.info('Starting LLM query via provider');
try {
const provider = await this.getCurrentProvider();
return await provider.query(prompt, options, abortController, onMessage);
} catch (error) {
Logger.error(`LLM query failed: ${error}`);
throw error;
}
}
get isReady(): boolean {
const currentProvider = this.providerFactory.getCurrentProvider();
return currentProvider ? currentProvider.isReady() : false;
}
async waitForInitialization(): Promise<boolean> {
try {
const provider = await this.getCurrentProvider();
return await provider.waitForInitialization();
} catch (error) {
Logger.error(`Initialization failed: ${error}`);
return false;
}
}
getWorkingDirectory(): string {
const currentProvider = this.providerFactory.getCurrentProvider();
return currentProvider ? currentProvider.getWorkingDirectory() : process.cwd();
}
// Method to refresh configuration and reinitialize if needed
async refreshApiKey(): Promise<boolean> {
try {
return await this.providerFactory.refreshCurrentProvider();
} catch (error) {
Logger.error(`Failed to refresh configuration: ${error}`);
return false;
}
}
// Method to check if current provider has valid configuration
async hasApiKey(): Promise<boolean> {
try {
const provider = await this.getCurrentProvider();
return provider.hasValidConfiguration();
} catch (error) {
Logger.error(`Failed to check provider configuration: ${error}`);
return false;
}
}
// Method to detect if an error is related to authentication
public isApiKeyAuthError(errorMessage: string): boolean {
const currentProvider = this.providerFactory.getCurrentProvider();
return currentProvider ? currentProvider.isAuthError(errorMessage) : false;
}
// Method to get current provider information
async getProviderInfo(): Promise<{ name: string; type: 'api' | 'binary' }> {
try {
const provider = await this.getCurrentProvider();
return {
name: provider.getProviderName(),
type: provider.getProviderType()
};
} catch (error) {
Logger.error(`Failed to get provider info: ${error}`);
return { name: 'Unknown', type: 'api' };
}
}
// Method to get provider status for debugging
async getProviderStatus() {
return await this.providerFactory.getProviderStatus();
}
// Method to get current configuration for debugging
async debugProviderConfig(): Promise<void> {
try {
const config = vscode.workspace.getConfiguration('superdesign');
const providerType = config.get<string>('llmProvider');
Logger.info(`Current LLM provider setting: ${providerType}`);
const providerInfo = await this.getProviderInfo();
Logger.info(`Active provider: ${providerInfo.name} (${providerInfo.type})`);
const hasValidConfig = await this.hasApiKey();
Logger.info(`Provider has valid configuration: ${hasValidConfig}`);
} catch (error) {
Logger.error(`Failed to debug provider config: ${error}`);
}
}
}
// Legacy export for backward compatibility
export type { LLMMessage, LLMProviderOptions, LLMStreamCallback };