Files
freewriting-cleanup/main.ts
T
AlexKucera a63d184448 Implements freewriting cleanup plugin
Adds a plugin to clean up freewriting text using the Anthropic API.

This initial commit introduces core functionality, including:
- API client for interacting with Anthropic's Claude models.
- Service for orchestrating cleanup operations and managing API calls.
- Command for executing the cleanup process on selected text within Obsidian editor.
- Settings tab for configuring the API key, model, prompts, and commentary preferences.
- Type definitions for settings, API requests/responses, and cleanup results.

The plugin provides a command to clean up selected text, apply custom prompts, and optionally generate commentary on the freewriting session.
2025-09-20 12:14:55 +02:00

70 lines
2.2 KiB
TypeScript

// ABOUTME: Main plugin file for Freewriting Cleanup - cleans up freewriting text using AI
// ABOUTME: Coordinates between services, commands, and Obsidian's plugin lifecycle
import { Editor, MarkdownView, Plugin } from 'obsidian';
import { FreewritingCleanupSettings } from './types';
import { DEFAULT_SETTINGS, FreewritingCleanupSettingTab } from './settings';
import { CleanupService } from './services/cleanupService';
import { CleanupCommand } from './commands/cleanupCommand';
export default class FreewritingCleanupPlugin extends Plugin {
settings: FreewritingCleanupSettings;
cleanupService: CleanupService;
cleanupCommand: CleanupCommand;
async onload() {
await this.loadSettings();
// Initialize services
this.cleanupService = new CleanupService(this.settings.apiKey);
this.cleanupCommand = new CleanupCommand(this.cleanupService);
// Register command
this.registerCommand();
// Add settings tab
this.addSettingTab(new FreewritingCleanupSettingTab(this.app, this));
}
onunload() {
// Cleanup if needed
}
// MARK: - Settings Management
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
// Update the cleanup service with new settings
if (this.cleanupService) {
this.cleanupService.updateApiKey(this.settings.apiKey);
}
}
// MARK: - Command Registration
private registerCommand() {
this.addCommand({
id: 'cleanup-freewriting',
name: 'Clean Up Freewriting',
editorCallback: async (editor: Editor, view: MarkdownView) => {
await this.executeCleanupCommand(editor, view);
}
});
}
// MARK: - Command Implementation
private async executeCleanupCommand(editor: Editor, view: MarkdownView): Promise<void> {
try {
await this.cleanupCommand.execute(editor, view, this.settings);
} catch (error) {
console.error('Error executing cleanup command:', error);
}
}
}