mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
- Implement ITokenService interface and GeminiTokenService for token counting - Add StatusBarService for managing status bar messages - Extract AIProviderModel enum to centralize model configuration - Remove unused MessageService and AIThoughtMessage classes - Update dependency registration to include new services - Clean up main plugin initialization and status bar handling
85 lines
No EOL
2 KiB
TypeScript
85 lines
No EOL
2 KiB
TypeScript
import { WorkspaceLeaf, Plugin } from 'obsidian';
|
|
import { AIProvider } from './Enums/ApiProvider';
|
|
import { MainView, VIEW_TYPE_MAIN } from 'Views/MainView';
|
|
import { RegisterAiProvider, RegisterDependencies } from 'Services/ServiceRegistration';
|
|
import { AIAgentSettingTab } from 'AIAgentSettingTab';
|
|
import { Services } from 'Services/Services';
|
|
import type { StatusBarService } from 'Services/StatusBarService';
|
|
import { Resolve } from 'Services/DependencyService';
|
|
|
|
interface IAIAgentSettings {
|
|
apiProvider: string;
|
|
apiKey: string;
|
|
exclusions: string[];
|
|
}
|
|
|
|
const DEFAULT_SETTINGS: IAIAgentSettings = {
|
|
apiProvider: AIProvider.Gemini,
|
|
apiKey: "",
|
|
exclusions: []
|
|
}
|
|
|
|
export default class AIAgentPlugin extends Plugin {
|
|
public settings: IAIAgentSettings;
|
|
|
|
async onload() {
|
|
// KaTeX CSS is bundled with the plugin to comply with CSP
|
|
require('katex/dist/katex.min.css');
|
|
// Plugin styles
|
|
require('./styles.css');
|
|
|
|
await this.loadSettings();
|
|
|
|
RegisterDependencies(this);
|
|
|
|
this.registerView(
|
|
VIEW_TYPE_MAIN,
|
|
(leaf) => new MainView(leaf)
|
|
);
|
|
|
|
this.addCommand({
|
|
id: 'ai-agent',
|
|
name: 'AI Agent',
|
|
callback: () => {
|
|
this.activateView();
|
|
}
|
|
});
|
|
|
|
this.addRibbonIcon('sparkles', 'AI Agent', (_: MouseEvent) => {
|
|
this.activateView();
|
|
});
|
|
|
|
this.addSettingTab(new AIAgentSettingTab(this.app, this));
|
|
}
|
|
|
|
async onunload() {
|
|
Resolve<StatusBarService>(Services.StatusBarService).removeStatusBarMessage();
|
|
}
|
|
|
|
async activateView() {
|
|
const { workspace } = this.app;
|
|
|
|
let leaf: WorkspaceLeaf | null = null;
|
|
const leaves = workspace.getLeavesOfType(VIEW_TYPE_MAIN);
|
|
|
|
if (leaves.length > 0) {
|
|
leaf = leaves[0];
|
|
} else {
|
|
leaf = workspace.getRightLeaf(false);
|
|
await leaf?.setViewState({ type: VIEW_TYPE_MAIN, active: true });
|
|
}
|
|
|
|
if (leaf != null) {
|
|
workspace.revealLeaf(leaf);
|
|
}
|
|
}
|
|
|
|
async loadSettings() {
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
|
}
|
|
|
|
async saveSettings() {
|
|
await this.saveData(this.settings);
|
|
RegisterAiProvider(this);
|
|
}
|
|
} |