Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38c977b9aa | ||
|
|
fa59c14cbd | ||
|
|
1f69c568bb |
No files matched your search
@@ -78,7 +78,7 @@ export class AnthropicClient {
|
||||
} else if (commentaryStyle === 'custom') {
|
||||
throw new ConfigurationError('Custom commentary style requires a custom prompt. Please provide customCommentaryPrompt.');
|
||||
} else {
|
||||
commentaryPrompt = COMMENTARY_PRESETS[commentaryStyle as Exclude<CommentaryStyle, 'custom'>];
|
||||
commentaryPrompt = COMMENTARY_PRESETS[commentaryStyle];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ export class CleanupCommand {
|
||||
} else if (error instanceof ServiceUnavailableError) {
|
||||
new Notice(error.message);
|
||||
} else if (error instanceof InvalidResponseError) {
|
||||
new Notice('Received an unexpected response from Claude. Please try again.');
|
||||
new Notice('Received an unexpected response from Claude. Please try again');
|
||||
} else if (error instanceof NetworkError) {
|
||||
new Notice('Network error. Check your connection and try again.');
|
||||
} else if (error instanceof Error) {
|
||||
|
||||
@@ -72,7 +72,7 @@ export default class FreewritingCleanupPlugin extends Plugin {
|
||||
*/
|
||||
async loadSettings(): Promise<FreewritingCleanupData | null> {
|
||||
const data = await this.loadData() as FreewritingCleanupData | null;
|
||||
const { modelCache, ...persisted } = data ?? {};
|
||||
const { ...persisted } = data ?? {};
|
||||
this.settings = {
|
||||
...DEFAULT_SETTINGS,
|
||||
...(persisted as Partial<FreewritingCleanupSettings>)
|
||||
@@ -111,7 +111,7 @@ export default class FreewritingCleanupPlugin extends Plugin {
|
||||
*/
|
||||
private registerCommand() {
|
||||
this.addCommand({
|
||||
id: 'freewriting-cleanup-cleanup-text',
|
||||
id: 'cleanup-text',
|
||||
name: 'Clean up text',
|
||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||
await this.executeCleanupCommand(editor, view);
|
||||
|
||||
+22
-28
@@ -1,7 +1,6 @@
|
||||
// ABOUTME: Service class for orchestrating freewriting text cleanup operations
|
||||
// ABOUTME: Handles validation, API coordination, and result formatting
|
||||
|
||||
import { Notice } from 'obsidian';
|
||||
import { AnthropicClient } from '../api/anthropicClient';
|
||||
import { FreewritingCleanupSettings, CleanupResult, ANTHROPIC_LIMITS } from '../types';
|
||||
import { ApiKeyError, TextTooLongError } from '../errors';
|
||||
@@ -64,36 +63,31 @@ export class CleanupService {
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const { cleanedText, commentary, usage } = await this.client.cleanupText(
|
||||
text,
|
||||
settings.model,
|
||||
settings.cleanupPrompt,
|
||||
settings.enableCommentary,
|
||||
settings.commentaryStyle,
|
||||
settings.customCommentaryPrompt
|
||||
);
|
||||
const { cleanedText, commentary, usage } = await this.client.cleanupText(
|
||||
text,
|
||||
settings.model,
|
||||
settings.cleanupPrompt,
|
||||
settings.enableCommentary,
|
||||
settings.commentaryStyle,
|
||||
settings.customCommentaryPrompt
|
||||
);
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
const duration = Date.now() - startTime;
|
||||
|
||||
const result: CleanupResult = {
|
||||
originalText: text,
|
||||
cleanedText,
|
||||
commentary,
|
||||
timestamp: new Date(),
|
||||
model: settings.model,
|
||||
tokensUsed: {
|
||||
input: usage?.input_tokens ?? 0,
|
||||
output: usage?.output_tokens ?? 0
|
||||
},
|
||||
duration
|
||||
};
|
||||
const result: CleanupResult = {
|
||||
originalText: text,
|
||||
cleanedText,
|
||||
commentary,
|
||||
timestamp: new Date(),
|
||||
model: settings.model,
|
||||
tokensUsed: {
|
||||
input: usage?.input_tokens ?? 0,
|
||||
output: usage?.output_tokens ?? 0
|
||||
},
|
||||
duration
|
||||
};
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
// Let the command layer handle user feedback to avoid duplicate notices
|
||||
throw error;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+23
-26
@@ -54,7 +54,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
private scheduleSave(): void {
|
||||
if (this.saveDebounce !== null) window.clearTimeout(this.saveDebounce);
|
||||
this.saveDebounce = window.setTimeout(() => {
|
||||
this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
this.saveDebounce = null;
|
||||
}, 300);
|
||||
}
|
||||
@@ -70,8 +70,6 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h2', { text: 'Freewriting Cleanup Settings' });
|
||||
|
||||
// Load models asynchronously in the background
|
||||
this.loadModels()
|
||||
.then(() => {
|
||||
@@ -86,13 +84,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
// MARK: - API Configuration
|
||||
|
||||
containerEl.createEl('h3', { text: 'API Configuration' });
|
||||
new Setting(containerEl).setName('API configuration').setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Anthropic API Key')
|
||||
.setName('Anthropic API key')
|
||||
.setDesc('Your Anthropic API key for Claude. Get one at https://console.anthropic.com/')
|
||||
.addText(text => text
|
||||
.setPlaceholder('sk-ant-...')
|
||||
.setPlaceholder('Enter API key')
|
||||
.setValue(this.plugin.settings.apiKey)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.apiKey = value;
|
||||
@@ -115,17 +113,17 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Test API Key')
|
||||
.setName('Test API key')
|
||||
.setDesc('Test your API key to verify it works correctly')
|
||||
.addButton(button => button
|
||||
.setButtonText('Test Connection')
|
||||
.setButtonText('Test connection')
|
||||
.onClick(async () => {
|
||||
await this.testApiKey(button);
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Claude Model')
|
||||
.setDesc('Which Claude model to use for text cleanup')
|
||||
.setName('Claude model')
|
||||
.setDesc('Claude model to use for text cleanup')
|
||||
.addDropdown(dropdown => {
|
||||
this.modelDropdown = dropdown;
|
||||
this.populateModelDropdown(dropdown);
|
||||
@@ -139,16 +137,16 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
// MARK: - Cleanup Configuration
|
||||
|
||||
containerEl.createEl('h3', { text: 'Cleanup Configuration' });
|
||||
new Setting(containerEl).setName('Cleanup configuration').setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Cleanup Prompt')
|
||||
.setDesc('Instructions for how Claude should clean up your freewriting text')
|
||||
.setName('Cleanup prompt')
|
||||
.setDesc('Instructions for how to clean up your freewriting text')
|
||||
.addTextArea(textArea => {
|
||||
textArea
|
||||
.setPlaceholder('Enter your cleanup instructions...')
|
||||
.setValue(this.plugin.settings.cleanupPrompt)
|
||||
.onChange(async (value) => {
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.cleanupPrompt = value;
|
||||
this.scheduleSave();
|
||||
});
|
||||
@@ -160,14 +158,14 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
// MARK: - Commentary Configuration
|
||||
|
||||
containerEl.createEl('h3', { text: 'AI Commentary' });
|
||||
new Setting(containerEl).setName('AI commentary').setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('AI should comment on text')
|
||||
.setDesc('After cleaning up your text, AI will provide thoughtful commentary on your freewriting session')
|
||||
.addToggle(toggle => toggle
|
||||
.setValue(this.plugin.settings.enableCommentary)
|
||||
.onChange(async (value) => {
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.enableCommentary = value;
|
||||
this.scheduleSave();
|
||||
this.display(); // Refresh to show/hide commentary options
|
||||
@@ -175,7 +173,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
if (this.plugin.settings.enableCommentary) {
|
||||
new Setting(containerEl)
|
||||
.setName('Commentary Style')
|
||||
.setName('Commentary style')
|
||||
.setDesc('Choose the type of feedback AI should provide')
|
||||
.addDropdown(dropdown => {
|
||||
COMMENTARY_STYLES.forEach(style => {
|
||||
@@ -184,7 +182,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
});
|
||||
dropdown
|
||||
.setValue(this.plugin.settings.commentaryStyle)
|
||||
.onChange(async (value) => {
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.commentaryStyle = value as CommentaryStyle;
|
||||
this.scheduleSave();
|
||||
this.display(); // Refresh to show/hide custom prompt
|
||||
@@ -193,13 +191,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
if (this.plugin.settings.commentaryStyle === 'custom') {
|
||||
new Setting(containerEl)
|
||||
.setName('Custom Commentary Prompt')
|
||||
.setName('Custom commentary prompt')
|
||||
.setDesc('Instructions for how AI should comment on your freewriting')
|
||||
.addTextArea(textArea => {
|
||||
textArea
|
||||
.setPlaceholder('Enter your commentary instructions...')
|
||||
.setValue(this.plugin.settings.customCommentaryPrompt)
|
||||
.onChange(async (value) => {
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.customCommentaryPrompt = value;
|
||||
this.scheduleSave();
|
||||
});
|
||||
@@ -210,7 +208,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
});
|
||||
} else {
|
||||
// Show the current preset for reference
|
||||
const presetText = COMMENTARY_PRESETS[this.plugin.settings.commentaryStyle as Exclude<CommentaryStyle, 'custom'>];
|
||||
const presetText = COMMENTARY_PRESETS[this.plugin.settings.commentaryStyle];
|
||||
const descDiv = containerEl.createDiv({ cls: 'setting-item-description freewriting-cleanup-description' });
|
||||
descDiv.empty();
|
||||
descDiv.createEl('strong', { text: 'Selected style: ' });
|
||||
@@ -220,7 +218,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
// MARK: - Usage Information
|
||||
|
||||
containerEl.createEl('h3', { text: 'Usage Information' });
|
||||
new Setting(containerEl).setName('Usage information').setHeading();
|
||||
|
||||
const usageDiv = containerEl.createDiv();
|
||||
usageDiv.empty();
|
||||
@@ -243,13 +241,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
|
||||
// MARK: - Reset Settings
|
||||
|
||||
containerEl.createEl('h3', { text: 'Reset' });
|
||||
new Setting(containerEl).setName('Reset').setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Reset to Defaults')
|
||||
.setName('Reset to defaults')
|
||||
.setDesc('Reset all settings to their default values')
|
||||
.addButton(button => button
|
||||
.setButtonText('Reset Settings')
|
||||
.setButtonText('Reset settings')
|
||||
.setWarning()
|
||||
.onClick(async () => {
|
||||
await this.resetSettings();
|
||||
@@ -334,7 +332,6 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
|
||||
const newModel = this.availableModels[0].id;
|
||||
this.plugin.settings.model = newModel;
|
||||
this.modelDropdown.setValue(newModel);
|
||||
console.log(`Model '${currentModel}' no longer available, switched to '${newModel}'`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user