diff --git a/extension/dist/extension.browser.js b/extension/dist/extension.browser.js index d382456..f49cdb3 100644 --- a/extension/dist/extension.browser.js +++ b/extension/dist/extension.browser.js @@ -114,7 +114,7 @@ ${t}`}];function $1(G,I,l){var Z;if(l===void 0&&(l={}),!I.codes){I.codes={};for( ${l} `,G.document.lineAt(I));return Z.insert(G.document.uri,N.start,X),y.workspace.applyEdit(Z),N},U1=(G,{startLine:I},l)=>{let Z=new y.WorkspaceEdit,b=G.selection.start,d=G.document.lineAt(b.line).rangeIncludingLineBreak,N=new y.Range(d.start,d.start),X=$2(` ${l} -`,G.document.lineAt(I));return Z.insert(G.document.uri,N.start,X),y.workspace.applyEdit(Z),N},U2=(G,{startLine:I,endLine:l},Z)=>{let b=new y.WorkspaceEdit,d=new y.Range(new y.Position(I,0),new y.Position(l,G.document.lineAt(l).range.end.character)),N=$2(Z,G.document.lineAt(I));return b.replace(G.document.uri,d,N),y.workspace.applyEdit(b),d},c2=G=>{if(!G||!G?.selection)return{selectedText:"",startLine:0,endLine:0};let{selection:I}=G,l=I.start.line,Z=I.end.line;return{selectedText:G.document.getText(I),startLine:l,endLine:Z}};var I1=G=>y.window.showErrorMessage(G),D=G=>G?.document?.languageId??"plaintext",k1=G=>G?.document?.fileName?.split?.(".").pop()||"",b2={},o1=()=>{F1.map(I=>({...I,promptId:l1(I.title),insertionMethod:I.insertionMethod||"replace",mode:N2.find(l=>l.id===I.modeId)})).forEach(I=>{b2[I.promptId]=I,F.set(h.prompt(I.promptId),I)}),F.set(h.promptMap(),b2)},h5=G=>G.toLowerCase().replaceAll(/[^a-zA-Z\d]+/g,"_").split("_").filter(Boolean).reduce((Z,b,d)=>d===0?Z+b:Z+b.charAt(0).toUpperCase()+b.slice(1),""),l1=G=>`${h5(G)}-${Y5()}`;var Q5=async(G,I)=>await F.getSecret(G)??I;var Q2=()=>{let G=F.get(h.activeMode());return G||e1},k2=()=>{let G=F.get(h.modes());return G||N2},h={activeModePresets(){return`${Q2().id}-presets`},activeModeActivePreset(){return`${Q2().id}-activePreset`},activeModeChatHistory(){return`${Q2().id}-chatHistory`},activeMode(){return"activeMode"},modes(){return"modes"},welcomeWizard(){return"welcomeWizard"},providerApiKey(G){return`${G}-apiKey`},stateCreated(){return"stateCreated"},prompt(G){return`${G}-prompt`},promptMap(){return"promptMap"}};var M=G=>{let I=F.get(h.activeModeActivePreset());if(I&&I[G])return typeof I[G]=="object"?{...I[G]}:I[G]},o2=async()=>{let G=M("provider"),I=await Q5(h.providerApiKey(G));return I||""};var G1=class extends Error{constructor(I){super(I),this.name="TimeoutError"}},Z1=class extends Error{constructor(I){super(),this.name="AbortError",this.message=I}},z1=G=>globalThis.DOMException===void 0?new Z1(G):new DOMException(G),x1=G=>{let I=G.reason===void 0?z1("This operation was aborted."):G.reason;return I instanceof Error?I:z1(I)};function a2(G,I){let{milliseconds:l,fallback:Z,message:b,customTimers:d={setTimeout,clearTimeout}}=I,N,V=new Promise((m,W)=>{if(typeof l!="number"||Math.sign(l)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${l}\``);if(I.signal){let{signal:Q}=I;Q.aborted&&W(x1(Q)),Q.addEventListener("abort",()=>{W(x1(Q))})}if(l===Number.POSITIVE_INFINITY){G.then(m,W);return}let Y=new G1;N=d.setTimeout.call(void 0,()=>{if(Z){try{m(Z())}catch(Q){W(Q)}return}typeof G.cancel=="function"&&G.cancel(),b===!1?m():b instanceof Error?W(b):(Y.message=b??`Promise timed out after ${l} milliseconds`,W(Y))},l),(async()=>{try{m(await G)}catch(Q){W(Q)}})()}).finally(()=>{V.clear()});return V.clear=()=>{d.clearTimeout.call(void 0,N),N=void 0},V}var a5="anthropic-typescript/0.4.4",H5="2023-01-01",e2=class{key;command;created=!1;constructor(I){this.command=I}async create(){this.key=await o2(),this.created=!0}async stream(I,l){this.created||await this.create();let Z=new AbortController,b=JSON.stringify(this.command.completionParams),d=new Promise((N,X)=>{I.addEventListener("abort",V=>{Z.abort(V),X(new Error("Caller aborted completion stream."))}),h2(this.command.url,{method:"POST",body:b,signal:Z.signal,headers:{Accept:"application/json","Content-Type":"application/json","Anthropic-SDK":a5,"Anthropic-Version":H5,"X-API-Key":this.key},onopen:async V=>{if(!V.ok)return Z.abort(),X(new Error(`Failed to open completion stream: ${V.status} ${V.statusText}`))},onmessage:async V=>{if(V.event==="ping")return;if(V.data==="[DONE]"){console.error("Unexpected done message before stop_reason has been issued");return}let m=JSON.parse(V.data);if(l?.(m),m.stop_reason!==null)return Z.abort(),N(m)},onerror:V=>(Z.abort(),X(new Error(V)))})});return a2(d,{milliseconds:6e4,message:"Completion stream timed out."}).catch(()=>{Z.abort()}),d}};var z2=class{webviewView;command;onProgressCallback;client;abortController;history="";constructor(I,l,Z){this.webviewView=I,this.command=l,this.abortController=new AbortController,this.onProgressCallback=Z,this.client=new e2(this.command)}async send(I=void 0){let{first:l}=b1("Anthropic",this.command);if(I===void 0)this.history=l;else{let Z={...this.command,message:I},{user:b}=b1("Anthropic",Z);this.history=`${this.history}${b}`}this.command.completionParams.stream=!0,this.command.completionParams.prompt=this.history;try{let Z=await this.client.stream(this.abortController.signal,b=>{this.onProgressCallback?.(b.completion)});return this.history=`${this.history}${Z.completion}`,Z.completion}catch(Z){throw new Error(Z)}}abort(){try{this.abortController&&this.abortController.abort(),this.abortController=new AbortController}catch(I){console.error(I)}}};var x2=class{key;command;created=!1;constructor(I){this.command=I}async create(){this.key=await o2(),this.created=!0}async stream(I,l){this.created||await this.create();let Z=new AbortController,b=JSON.stringify(this.command.completionParams),d={role:"assistant",id:"1",text:"",delta:"",detail:{}},N=new Promise((X,V)=>{I.addEventListener("abort",m=>{Z.abort(m),V(new Error("Caller aborted completion stream."))}),h2(this.command.url,{method:"POST",body:b,signal:Z.signal,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.key}`},onopen:async m=>{if(!m.ok)return Z.abort(),V(new Error(`Failed to open completion stream: ${m.status} ${m.statusText}`))},onmessage:m=>{if(m.data==="[DONE]")return d.text=d.text.trim(),X(d);try{let W=JSON.parse(m.data);if(W?.id&&(d.id=W.id),W?.choices?.length){let{delta:Y}=W.choices[0];d.delta=Y.content,Y.content&&(d.text+=Y.content),Y.role&&(d.role=Y.role),d.detail=W,l?.(d)}}catch(W){V(W)}},onerror:m=>(Z.abort(),V(m))})});return a2(N,{milliseconds:6e4,message:"Completion stream timed out."}).catch(()=>{Z.abort()}),N}};var B2=class{webviewView;command;onProgressCallback;client;abortController;messages=[];constructor(I,l,Z){this.webviewView=I,this.command=l,this.abortController=new AbortController,this.onProgressCallback=Z,this.client=new x2(this.command)}async send(I=void 0){this.messages.length===0&&this.messages.push({role:"system",content:this.command.system}),I===void 0?this.messages.push({role:"user",content:this.command.message}):this.messages.push({role:"user",content:I}),this.command.completionParams.max_tokens=2048,this.command.completionParams.stream=!0,this.command.completionParams.messages=this.messages;try{let l=await this.client.stream(this.abortController.signal,Z=>{this.onProgressCallback?.(Z.text)});return this.messages.push({role:"assistant",content:l.text}),l.text}catch(l){throw new Error(l)}}abort(){try{this.abortController&&this.abortController.abort(),this.abortController=new AbortController}catch(I){console.error(I)}}};var c1={OpenAI:{system:"{system_message}",user:"{user_message}",first:"{system}",stops:[]},Anthropic:{system:"{system_message}",user:` +`,G.document.lineAt(I));return Z.insert(G.document.uri,N.start,X),y.workspace.applyEdit(Z),N},U2=(G,{startLine:I,endLine:l},Z)=>{let b=new y.WorkspaceEdit,d=new y.Range(new y.Position(I,0),new y.Position(l,G.document.lineAt(l).range.end.character)),N=$2(Z,G.document.lineAt(I));return b.replace(G.document.uri,d,N),y.workspace.applyEdit(b),d},c2=G=>{if(!G||!G?.selection)return{selectedText:"",startLine:0,endLine:0};let{selection:I}=G,l=I.start.line,Z=I.end.line;return{selectedText:G.document.getText(I),startLine:l,endLine:Z}};var I1=G=>y.window.showErrorMessage(G),D=G=>G?.document?.languageId??"plaintext",k1=G=>G?.document?.fileName?.split?.(".").pop()||"",b2={},o1=()=>{F1.map(I=>({...I,promptId:l1(I.title),insertionMethod:I.insertionMethod||"replace",mode:N2.find(l=>l.id===I.modeId)})).forEach(I=>{b2[I.promptId]=I,F.set(h.prompt(I.promptId),I)}),F.set(h.promptMap(),b2)},h5=G=>G.toLowerCase().replaceAll(/[^a-zA-Z\d]+/g,"_").split("_").filter(Boolean).reduce((Z,b,d)=>d===0?Z+b:Z+b.charAt(0).toUpperCase()+b.slice(1),""),l1=G=>`${h5(G)}-${Y5()}`;var Q5=async(G,I)=>await F.getSecret(G)??I;var Q2=()=>{let G=F.get(h.activeMode());return G||e1},k2=()=>{let G=F.get(h.modes());return G||N2},h={activeModePresets(){return`${Q2().id}-presets`},activeModeActivePreset(){return`${Q2().id}-activePreset`},activeModeChatHistory(){return`${Q2().id}-chatHistory`},activeMode(){return"activeMode"},modes(){return"modes"},welcomeWizard(){return"welcomeWizard"},providerApiKey(G){return`${G}-apiKey`},stateCreated(){return"stateCreated"},prompt(G){return`${G}-prompt`},promptMap(){return"promptMap"}};var M=G=>{let I=F.get(h.activeModeActivePreset());if(I&&I[G])return typeof I[G]=="object"?{...I[G]}:I[G]},o2=async()=>{let G=M("provider"),I=await Q5(h.providerApiKey(G));return I||""};var G1=class extends Error{constructor(I){super(I),this.name="TimeoutError"}},Z1=class extends Error{constructor(I){super(),this.name="AbortError",this.message=I}},z1=G=>globalThis.DOMException===void 0?new Z1(G):new DOMException(G),x1=G=>{let I=G.reason===void 0?z1("This operation was aborted."):G.reason;return I instanceof Error?I:z1(I)};function a2(G,I){let{milliseconds:l,fallback:Z,message:b,customTimers:d={setTimeout,clearTimeout}}=I,N,V=new Promise((m,W)=>{if(typeof l!="number"||Math.sign(l)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${l}\``);if(I.signal){let{signal:Q}=I;Q.aborted&&W(x1(Q)),Q.addEventListener("abort",()=>{W(x1(Q))})}if(l===Number.POSITIVE_INFINITY){G.then(m,W);return}let Y=new G1;N=d.setTimeout.call(void 0,()=>{if(Z){try{m(Z())}catch(Q){W(Q)}return}typeof G.cancel=="function"&&G.cancel(),b===!1?m():b instanceof Error?W(b):(Y.message=b??`Promise timed out after ${l} milliseconds`,W(Y))},l),(async()=>{try{m(await G)}catch(Q){W(Q)}})()}).finally(()=>{V.clear()});return V.clear=()=>{d.clearTimeout.call(void 0,N),N=void 0},V}var a5="anthropic-typescript/0.4.4",H5="2023-01-01",e2=class{key;command;created=!1;constructor(I){this.command=I}async create(){this.key=await o2(),this.created=!0}async stream(I,l){this.created||await this.create();let Z=new AbortController,b=JSON.stringify(this.command.completionParams),d=new Promise((N,X)=>{I.addEventListener("abort",V=>{Z.abort(V),X(new Error("Caller aborted completion stream."))}),h2(this.command.url,{method:"POST",body:b,signal:Z.signal,headers:{Accept:"application/json","Content-Type":"application/json","Anthropic-SDK":a5,"Anthropic-Version":H5,"X-API-Key":this.key},onopen:async V=>{if(!V.ok)return Z.abort(),X(new Error(`Failed to open completion stream: ${V.status} ${V.statusText}`))},onmessage:async V=>{if(V.event==="ping")return;if(V.data==="[DONE]"){console.error("Unexpected done message before stop_reason has been issued");return}let m=JSON.parse(V.data);if(l?.(m),m.stop_reason!==null)return Z.abort(),N(m)},onerror:V=>(Z.abort(),X(new Error(V)))})});return a2(d,{milliseconds:6e4,message:"Completion stream timed out."}).catch(()=>{Z.abort()}),d}};var z2=class{webviewView;command;onProgressCallback;client;abortController;history="";constructor(I,l,Z){this.webviewView=I,this.command=l,this.abortController=new AbortController,this.onProgressCallback=Z,this.client=new e2(this.command)}async send(I=void 0){let{first:l}=b1("Anthropic",this.command);if(I===void 0)this.history=l;else{let Z={...this.command,message:I},{user:b}=b1("Anthropic",Z);this.history=`${this.history}${b}`}this.command.completionParams.stream=!0,this.command.completionParams.prompt=this.history;try{let Z=await this.client.stream(this.abortController.signal,b=>{this.onProgressCallback?.(b.completion)});return this.history=`${this.history}${Z.completion}`,Z.completion}catch(Z){throw new Error(Z)}}abort(){try{this.abortController&&this.abortController.abort(),this.abortController=new AbortController}catch(I){console.error(I)}}};var x2=class{key;command;created=!1;constructor(I){this.command=I}async create(){this.key=await o2(),this.created=!0}async stream(I,l){this.created||await this.create();let Z=new AbortController,b=JSON.stringify(this.command.completionParams),d={role:"assistant",id:"1",text:"",delta:"",detail:{}},N=new Promise((X,V)=>{I.addEventListener("abort",m=>{Z.abort(m),V(new Error("Caller aborted completion stream."))}),h2(this.command.url,{method:"POST",body:b,signal:Z.signal,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.key}`},onopen:async m=>{if(!m.ok)return Z.abort(),V(new Error(`Failed to open completion stream: ${m.status} ${m.statusText}`))},onmessage:m=>{if(m.data==="[DONE]")return d.text=d.text.trim(),X(d);try{let W=JSON.parse(m.data);if(W?.id&&(d.id=W.id),W?.choices?.length){let{delta:Y}=W.choices[0];d.delta=Y.content,Y.content&&(d.text+=Y.content),Y.role&&(d.role=Y.role),d.detail=W,l?.(d)}}catch(W){V(W)}},onerror:m=>(Z.abort(),V(m)),onclose:()=>(d.text=d.text.trim(),X(d))})});return a2(N,{milliseconds:6e4,message:"Completion stream timed out."}).catch(()=>{Z.abort()}),N}};var B2=class{webviewView;command;onProgressCallback;client;abortController;messages=[];constructor(I,l,Z){this.webviewView=I,this.command=l,this.abortController=new AbortController,this.onProgressCallback=Z,this.client=new x2(this.command)}async send(I=void 0){this.messages.length===0&&this.messages.push({role:"system",content:this.command.system}),I===void 0?this.messages.push({role:"user",content:this.command.message}):this.messages.push({role:"user",content:I}),this.command.completionParams.max_tokens=2048,this.command.completionParams.stream=!0,this.command.completionParams.messages=this.messages;try{let l=await this.client.stream(this.abortController.signal,Z=>{this.onProgressCallback?.(Z.text)});return this.messages.push({role:"assistant",content:l.text}),l.text}catch(l){throw new Error(l)}}abort(){try{this.abortController&&this.abortController.abort(),this.abortController=new AbortController}catch(I){console.error(I)}}};var c1={OpenAI:{system:"{system_message}",user:"{user_message}",first:"{system}",stops:[]},Anthropic:{system:"{system_message}",user:` Human: {user_message}