/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var E=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var N=(l,t)=>{for(var e in t)E(l,e,{get:t[e],enumerable:!0})},D=(l,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of b(t))!I.call(l,n)&&n!==e&&E(l,n,{get:()=>t[n],enumerable:!(r=M(t,n))||r.enumerable});return l};var _=l=>D(E({},"__esModule",{value:!0}),l);var L={};N(L,{default:()=>w});module.exports=_(L);var P=require("obsidian");var o=require("obsidian");var v=["claude-opus-4-1-20250805","claude-opus-4-20250514","claude-sonnet-4-20250514","claude-3-7-sonnet-latest","claude-3-5-haiku-latest","claude-3-haiku-20240307"],x=["constructive","encouraging","analytical","brief","custom"],d={constructive:"Provide balanced feedback on this freewriting, noting strengths and areas for development. Consider the flow of ideas, creativity, and any interesting themes that emerged.",encouraging:"Offer positive, supportive observations about this freewriting session. Focus on what worked well, creative insights, and encouraging the writer to continue exploring these ideas.",analytical:"Analyze the writing structure, themes, and patterns in this freewriting. Look at the progression of thoughts, recurring concepts, and the overall coherence of ideas.",brief:"Give 2-3 concise observations about this freewriting session. Keep it short but insightful."},c={MAX_TOKENS:2e5,MAX_CHARACTERS:68e4,DEFAULT_MAX_OUTPUT_TOKENS:4e3};var A={apiKey:"",model:"claude-3-5-haiku-latest",cleanupPrompt:"I did some free writing. Please correct my jumbled typo mess. Only fix spelling, grammar, and punctuation. Add line breaks and paragraphs as appropriate. Do not make stylistic changes to the content or tone.",enableCommentary:!1,commentaryStyle:"constructive",customCommentaryPrompt:"Provide thoughtful feedback on this freewriting session, considering the writer's flow of thoughts and ideas."},g=class extends o.PluginSettingTab{constructor(e,r){super(e,r);this.plugin=r}display(){let{containerEl:e}=this;if(e.empty(),e.createEl("h2",{text:"Freewriting Cleanup Settings"}),e.createEl("h3",{text:"API Configuration"}),new o.Setting(e).setName("Anthropic API Key").setDesc("Your Anthropic API key for Claude. Get one at https://console.anthropic.com/").addText(n=>n.setPlaceholder("sk-ant-...").setValue(this.plugin.settings.apiKey).onChange(async s=>{this.plugin.settings.apiKey=s,await this.plugin.saveSettings(),this.plugin.cleanupService.updateApiKey(s)})).then(n=>{var s;(s=n.controlEl.querySelector("input"))==null||s.setAttribute("type","password")}),new o.Setting(e).setName("Test API Key").setDesc("Test your API key to verify it works correctly").addButton(n=>n.setButtonText("Test Connection").onClick(async()=>{await this.testApiKey(n)})),new o.Setting(e).setName("Claude Model").setDesc("Which Claude model to use for text cleanup").addDropdown(n=>{v.forEach(s=>{n.addOption(s,s)}),n.setValue(this.plugin.settings.model).onChange(async s=>{this.plugin.settings.model=s,await this.plugin.saveSettings()})}),e.createEl("h3",{text:"Cleanup Configuration"}),new o.Setting(e).setName("Cleanup Prompt").setDesc("Instructions for how Claude should clean up your freewriting text").addTextArea(n=>{n.setPlaceholder("Enter your cleanup instructions...").setValue(this.plugin.settings.cleanupPrompt).onChange(async s=>{this.plugin.settings.cleanupPrompt=s,await this.plugin.saveSettings()}),n.inputEl.rows=4,n.inputEl.addClass("freewriting-cleanup-textarea")}),e.createEl("h3",{text:"AI Commentary"}),new o.Setting(e).setName("AI should comment on text").setDesc("After cleaning up your text, AI will provide thoughtful commentary on your freewriting session").addToggle(n=>n.setValue(this.plugin.settings.enableCommentary).onChange(async s=>{this.plugin.settings.enableCommentary=s,await this.plugin.saveSettings(),this.display()})),this.plugin.settings.enableCommentary)if(new o.Setting(e).setName("Commentary Style").setDesc("Choose the type of feedback AI should provide").addDropdown(n=>{x.forEach(s=>{let i=s.charAt(0).toUpperCase()+s.slice(1);n.addOption(s,i)}),n.setValue(this.plugin.settings.commentaryStyle).onChange(async s=>{this.plugin.settings.commentaryStyle=s,await this.plugin.saveSettings(),this.display()})}),this.plugin.settings.commentaryStyle==="custom")new o.Setting(e).setName("Custom Commentary Prompt").setDesc("Instructions for how AI should comment on your freewriting").addTextArea(n=>{n.setPlaceholder("Enter your commentary instructions...").setValue(this.plugin.settings.customCommentaryPrompt).onChange(async s=>{this.plugin.settings.customCommentaryPrompt=s,await this.plugin.saveSettings()}),n.inputEl.rows=3,n.inputEl.addClass("freewriting-cleanup-textarea-small")});else{let n=d[this.plugin.settings.commentaryStyle],s=e.createDiv({cls:"setting-item-description freewriting-cleanup-description"});s.innerHTML=`Selected style: ${n}`}e.createEl("h3",{text:"Usage Information"});let r=e.createDiv();r.innerHTML=`
How to use:
Limits: Maximum 680,000 characters (~150,000 words) per cleanup
Format: Original text \u2192 separator \u2192 cleaned text
`,e.createEl("h3",{text:"Reset"}),new o.Setting(e).setName("Reset to Defaults").setDesc("Reset all settings to their default values").addButton(n=>n.setButtonText("Reset Settings").setWarning().onClick(async()=>{await this.resetSettings()}))}async testApiKey(e){let r=e.buttonEl.textContent;e.setButtonText("Testing..."),e.setDisabled(!0);try{let n=await this.plugin.cleanupService.testConnection(this.plugin.settings);if(n.success){if(new o.Notice("\u2705 API connection successful!"),n.details){let s=n.details;new o.Notice(`Model: ${s.model}, Response time: ${s.responseTime}ms`)}}else new o.Notice(`\u274C API test failed: ${n.message}`)}catch(n){new o.Notice(`\u274C API test failed: ${n instanceof Error?n.message:"Unknown error"}`)}finally{e.setButtonText(r||"Test Connection"),e.setDisabled(!1)}}async resetSettings(){if(await this.showConfirmDialog("Reset Settings","Are you sure you want to reset all settings to their defaults? This cannot be undone.")){let r=this.plugin.settings.apiKey;this.plugin.settings={...A,apiKey:r},await this.plugin.saveSettings(),this.plugin.cleanupService.updateApiKey(r),this.display(),new o.Notice("Settings reset to defaults")}}async showConfirmDialog(e,r){return new Promise(n=>{new T(this.app,e,r,i=>{n(i)}).open()})}},T=class{constructor(t,e,r,n){this.app=t,this.title=e,this.message=r,this.callback=n}open(){this.modalEl=document.createElement("div"),this.modalEl.className="modal-container mod-dim";let t=this.modalEl.createDiv("modal");t.createDiv("modal-header").createEl("h3",{text:this.title}),t.createDiv("modal-content").createEl("p",{text:this.message});let n=t.createDiv("modal-button-container"),s=n.createEl("button",{text:"Cancel"});s.onclick=()=>this.close(!1);let i=n.createEl("button",{text:"Confirm",cls:"mod-warning"});i.onclick=()=>this.close(!0),document.body.appendChild(this.modalEl),i.focus()}close(t){this.modalEl&&this.modalEl.parentNode&&this.modalEl.parentNode.removeChild(this.modalEl),this.callback(t)}};var S=require("obsidian");var R=require("obsidian");var y=class{constructor(t){this.baseUrl="https://api.anthropic.com/v1/messages";this.MAX_RETRIES=3;this.RETRY_DELAY_BASE=1e3;this.apiKey=t}async cleanupText(t,e,r,n=!1,s="constructive",i){if(!this.apiKey)throw new Error("API key is required");if(t.length>c.MAX_CHARACTERS)throw new Error(`Text too long. Maximum ${c.MAX_CHARACTERS} characters allowed.`);let a="";n&&(s==="custom"&&i?a=i:a=d[s]);let C=`${r} ${n?`After cleaning the text, also provide commentary based on this instruction: ${a}`:""} CRITICAL OUTPUT REQUIREMENTS - YOU MUST FOLLOW THIS EXACT FORMAT: ===CLEANED TEXT=== [Put the cleaned up text here] - Fix spelling, grammar, and punctuation errors - Add line breaks and paragraphs as appropriate for readability - Preserve any existing markdown formatting (bold, italics, links, etc.) - Do not add quotation marks or any wrapper text ===END CLEANED TEXT=== ${n?` ===COMMENTARY=== [Put your commentary here based on the instruction above] ===END COMMENTARY=== `:""} You MUST use exactly these markers. Do not deviate from this format.`,m=`Please process this freewriting text according to the format requirements: ${t}`,h={model:e,max_tokens:c.DEFAULT_MAX_OUTPUT_TOKENS,messages:[{role:"user",content:m}],system:C},k=await this.makeRequestWithRetry(h);return this.parseStructuredResponse(k,n)}async testConnection(t){if(!this.validateApiKey())return{success:!1,message:"API key is empty or invalid format",error:"INVALID_KEY_FORMAT"};let e=Date.now(),r={model:t,max_tokens:50,messages:[{role:"user",content:'Hello! Please respond with just "Test successful."'}],system:'You are a test assistant. Respond only with "Test successful." and nothing else.'};try{let n=await this.makeRequest(r),s=Date.now()-e;return{success:!0,message:"API connection successful",details:{model:n.model,responseTime:s,inputTokens:n.usage.input_tokens,outputTokens:n.usage.output_tokens}}}catch(n){return{success:!1,message:n instanceof Error?n.message:"Unknown error",error:"CONNECTION_FAILED"}}}async makeRequestWithRetry(t){let e=new Error("No attempts made");for(let r=1;r<=this.MAX_RETRIES;r++)try{let n=await this.makeRequest(t);return this.extractTextFromResponse(n)}catch(n){if(e=n instanceof Error?n:new Error("Unknown error"),r