mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Migrate AIProvider and SearchTrigger from namespace pattern to exported functions. Simplify OpenAITokenService async implementation, remove unused imports, fix enum aliases, and update placeholder text.
86 lines
No EOL
2.3 KiB
TypeScript
86 lines
No EOL
2.3 KiB
TypeScript
import type VaultkeeperAIPlugin from "main";
|
|
import { Resolve } from "./DependencyService";
|
|
import { Services } from "./Services";
|
|
import { AIProvider, AIProviderModel, fromModel } from "Enums/ApiProvider";
|
|
|
|
const DEFAULT_SETTINGS: IVaultkeeperAISettings = {
|
|
firstTimeStart: true,
|
|
userInstruction: "",
|
|
|
|
model: AIProviderModel.ClaudeSonnet_4_5,
|
|
apiKeys: {
|
|
claude: "",
|
|
openai: "",
|
|
gemini: ""
|
|
},
|
|
exclusions: [],
|
|
|
|
searchResultsLimit: 15,
|
|
snippetSizeLimit: 300
|
|
}
|
|
|
|
export interface IVaultkeeperAISettings {
|
|
firstTimeStart: boolean;
|
|
userInstruction: string;
|
|
|
|
model: string;
|
|
apiKeys: {
|
|
claude: string;
|
|
openai: string;
|
|
gemini: string;
|
|
};
|
|
exclusions: string[];
|
|
|
|
searchResultsLimit: number;
|
|
snippetSizeLimit: number;
|
|
}
|
|
|
|
export class SettingsService {
|
|
|
|
private readonly plugin: VaultkeeperAIPlugin;
|
|
|
|
public readonly settings: IVaultkeeperAISettings;
|
|
|
|
public constructor(loadedSettings: Partial<IVaultkeeperAISettings>) {
|
|
this.plugin = Resolve<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin);
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, loadedSettings);
|
|
}
|
|
|
|
public async saveSettings(onSave?: () => void) {
|
|
await this.plugin.saveData(this.settings);
|
|
if (onSave) {
|
|
onSave();
|
|
}
|
|
}
|
|
|
|
public getApiKeyForCurrentModel(): string {
|
|
const provider = fromModel(this.settings.model);
|
|
return this.getApiKeyForProvider(provider);
|
|
}
|
|
|
|
public getApiKeyForProvider(provider: AIProvider): string {
|
|
switch (provider) {
|
|
case AIProvider.Claude:
|
|
return this.settings.apiKeys.claude;
|
|
case AIProvider.OpenAI:
|
|
return this.settings.apiKeys.openai;
|
|
case AIProvider.Gemini:
|
|
return this.settings.apiKeys.gemini;
|
|
}
|
|
}
|
|
|
|
public setApiKeyForProvider(provider: AIProvider, key: string): void {
|
|
switch (provider) {
|
|
case AIProvider.Claude:
|
|
this.settings.apiKeys.claude = key;
|
|
break;
|
|
case AIProvider.OpenAI:
|
|
this.settings.apiKeys.openai = key;
|
|
break;
|
|
case AIProvider.Gemini:
|
|
this.settings.apiKeys.gemini = key;
|
|
break;
|
|
}
|
|
}
|
|
|
|
} |