feat: keychain secret picker, proofreading timing and reasoning controls
- API keys: pick an existing Obsidian keychain secret per provider (SecretComponent); data.json stores only the secret name and keys are read at call time. One-time migration links the old fixed-name secrets and drops legacy fields; no more writing empty secrets on every save. - AIService: treat max-token truncation and empty content as errors instead of crashing on null.trim() or replacing text with a truncated answer. - Proofreading: live elapsed-time notice, then a summary with model, upstream host and prompt/output/reasoning tokens. - Proofreading (OpenRouter): Reasoning toggle and Effort setting, default off/low.
This commit is contained in:
1 parent
bf27867d20
commit
f66d45db68
10 files changed
+264
-108
No files matched your search
@@ -18,6 +18,7 @@ export class Proofreader {
|
||||
}
|
||||
|
||||
const config = resolveChatProvider(
|
||||
this.plugin.app,
|
||||
this.plugin.settings,
|
||||
this.plugin.settings.proofreadingProvider || "openrouter"
|
||||
);
|
||||
@@ -28,23 +29,34 @@ export class Proofreader {
|
||||
return;
|
||||
}
|
||||
|
||||
new Notice("🤖 Fixing punctuation and grammar...");
|
||||
const model = this.plugin.settings.proofreadingModel;
|
||||
const startedAt = performance.now();
|
||||
const elapsed = () => `${((performance.now() - startedAt) / 1000).toFixed(1)} s`;
|
||||
const progress = new Notice(`🤖 Proofreading with ${model}… 0.0 s`, 0);
|
||||
const ticker = window.setInterval(
|
||||
() => progress.setMessage(`🤖 Proofreading with ${model}… ${elapsed()}`),
|
||||
100
|
||||
);
|
||||
|
||||
try {
|
||||
const systemPrompt =
|
||||
this.plugin.settings.proofreadingSystemPrompt ||
|
||||
"You are a text proofreading tool. Fix punctuation and grammar in the text below. Return only the corrected text, nothing else.";
|
||||
|
||||
const corrected = await AIService.callChatCompletion(
|
||||
const { text: corrected, upstream, usage } = await AIService.callChatCompletion(
|
||||
selection,
|
||||
systemPrompt,
|
||||
{
|
||||
apiKey: config.apiKey,
|
||||
model: this.plugin.settings.proofreadingModel,
|
||||
model,
|
||||
endpoint: config.endpoint,
|
||||
provider: config.provider,
|
||||
temperature: this.plugin.settings.proofreadingTemperature,
|
||||
maxTokens: this.plugin.settings.proofreadingMaxTokens,
|
||||
reasoning: {
|
||||
enabled: this.plugin.settings.proofreadingReasoning,
|
||||
effort: this.plugin.settings.proofreadingEffort,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -54,12 +66,27 @@ export class Proofreader {
|
||||
}
|
||||
|
||||
editor.replaceSelection(corrected);
|
||||
new Notice("✅ Punctuation and grammar fixed.");
|
||||
// Prompt tokens = system prompt + selection. Reasoning tokens are part
|
||||
// of the output count and are usually what makes a short fix slow.
|
||||
const tokens = usage
|
||||
? `Prompt ${usage.promptTokens} tok · output ${usage.completionTokens} tok` +
|
||||
(usage.reasoningTokens ? ` (${usage.reasoningTokens} reasoning)` : "")
|
||||
: "Token usage not reported";
|
||||
const knobs =
|
||||
config.provider === "openrouter"
|
||||
? ` · reasoning ${this.plugin.settings.proofreadingReasoning ? "on" : "off"} · effort ${this.plugin.settings.proofreadingEffort}`
|
||||
: "";
|
||||
const summary = `✅ Fixed in ${elapsed()}\n${model}${upstream ? ` via ${upstream}` : ""}${knobs}\n${tokens}`;
|
||||
console.info(`NibbleAI proofread: ${summary.replace(/\n/g, " | ")}`);
|
||||
new Notice(summary, 10000);
|
||||
} catch (error) {
|
||||
console.error("Proofreading error:", error);
|
||||
new Notice(
|
||||
`❌ Fix failed: ${error instanceof Error ? error.message : String(error)}`
|
||||
`❌ Fix failed after ${elapsed()} (${model}): ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
} finally {
|
||||
window.clearInterval(ticker);
|
||||
progress.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user