diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..9ac7e57 Binary files /dev/null and b/icon.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..9199c69 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +
'+(t?A:c(A,!0))+"
\n":""+(t?A:c(A,!0))+"
\n"}blockquote(A){return`\n${A}\n`}html(A){return A}heading(A,e,t,r){return this.options.headerIds?`
${A}
\n`}table(A,e){return e&&(e=`${e}`),"${A}
`}br(){return this.options.xhtml?"An error occurred:
"+c(A.message+"",!0)+"";throw A}try{const t=D.lex(A,e);if(e.walkTokens){if(e.async)return Promise.all(G.walkTokens(t,e.walkTokens)).then((()=>O.parse(t,e))).catch(r);G.walkTokens(t,e.walkTokens)}return O.parse(t,e)}catch(A){r(A)}}G.options=G.setOptions=function(A){var e;return m(G.defaults,A),e=G.defaults,r=e,G},G.getDefaults=function(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}},G.defaults=r,G.use=function(...A){const e=G.defaults.extensions||{renderers:{},childTokens:{}};A.forEach((A=>{const t=m({},A);if(t.async=G.defaults.async||t.async,A.extensions&&(A.extensions.forEach((A=>{if(!A.name)throw new Error("extension name required");if(A.renderer){const t=e.renderers[A.name];e.renderers[A.name]=t?function(...e){let r=A.renderer.apply(this,e);return!1===r&&(r=t.apply(this,e)),r}:A.renderer}if(A.tokenizer){if(!A.level||"block"!==A.level&&"inline"!==A.level)throw new Error("extension level must be 'block' or 'inline'");e[A.level]?e[A.level].unshift(A.tokenizer):e[A.level]=[A.tokenizer],A.start&&("block"===A.level?e.startBlock?e.startBlock.push(A.start):e.startBlock=[A.start]:"inline"===A.level&&(e.startInline?e.startInline.push(A.start):e.startInline=[A.start]))}A.childTokens&&(e.childTokens[A.name]=A.childTokens)})),t.extensions=e),A.renderer){const e=G.defaults.renderer||new S;for(const t in A.renderer){const r=e[t];e[t]=(...n)=>{let s=A.renderer[t].apply(e,n);return!1===s&&(s=r.apply(e,n)),s}}t.renderer=e}if(A.tokenizer){const e=G.defaults.tokenizer||new K;for(const t in A.tokenizer){const r=e[t];e[t]=(...n)=>{let s=A.tokenizer[t].apply(e,n);return!1===s&&(s=r.apply(e,n)),s}}t.tokenizer=e}if(A.walkTokens){const e=G.defaults.walkTokens;t.walkTokens=function(t){let r=[];return r.push(A.walkTokens.call(this,t)),e&&(r=r.concat(e.call(this,t))),r}}G.setOptions(t)}))},G.walkTokens=function(A,e){let t=[];for(const r of A)switch(t=t.concat(e.call(G,r)),r.type){case"table":for(const A of r.header)t=t.concat(G.walkTokens(A.tokens,e));for(const A of r.rows)for(const r of A)t=t.concat(G.walkTokens(r.tokens,e));break;case"list":t=t.concat(G.walkTokens(r.items,e));break;default:G.defaults.extensions&&G.defaults.extensions.childTokens&&G.defaults.extensions.childTokens[r.type]?G.defaults.extensions.childTokens[r.type].forEach((function(A){t=t.concat(G.walkTokens(r[A],e))})):r.tokens&&(t=t.concat(G.walkTokens(r.tokens,e)))}return t},G.parseInline=function(A,e){if(null==A)throw new Error("marked.parseInline(): input parameter is undefined or null");if("string"!=typeof A)throw new Error("marked.parseInline(): input parameter is of type "+Object.prototype.toString.call(A)+", string expected");y(e=m({},G.defaults,e||{}));try{const t=D.lexInline(A,e);return e.walkTokens&&G.walkTokens(t,e.walkTokens),O.parseInline(t,e)}catch(A){if(A.message+="\nPlease report this to https://github.com/markedjs/marked.",e.silent)return"
An error occurred:
"+c(A.message+"",!0)+"";throw A}},G.Parser=O,G.parser=O.parse,G.Renderer=S,G.TextRenderer=T,G.Lexer=D,G.lexer=D.lex,G.Tokenizer=K,G.Slugger=M,G.parse=G,G.options,G.setOptions,G.use,G.walkTokens,G.parseInline;const R=G,V=(O.parse,D.lex,A=>{A=(A=(A=A.replaceAll("&","&")).replaceAll("<","<")).replaceAll(">",">");const t=(0,e.sanitize)(R(A,{gfm:!0,breaks:!0})),r=N(t);for(const A of r.querySelectorAll("code"))A.innerHTML=A.innerHTML.replaceAll("&","&");return r}),N=A=>{var e=document.createElement("template");return e.innerHTML=A,e.content};var P=t(120),X=t.n(P);const J=()=>{const A=document.querySelectorAll(".api-key-status");A.forEach((A=>A.classList.remove("error"))),A.forEach((A=>A.classList.remove("success"))),A.forEach((A=>A.innerText=""))},_=()=>{const A=document.querySelectorAll(".api-key-status"),e=document.querySelector("#intro-continue");J(),e.classList.add("secondary");const t=localStorage.getItem("api-key");if(!t)return;A.forEach((A=>A.innerText="Checking..."));const r=(A=>fetch("https://api.openai.com/v1/models",{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${A}`}}).then((A=>A.json())))(t);r.then((t=>{t.error?(A.forEach((A=>A.classList.add("error"))),"invalid_api_key"===t.error.code?A.forEach((A=>A.innerText="This API key doesn’t work.")):A.forEach((A=>A.innerText="There was an error when checking the API key."))):(A.forEach((A=>A.innerText="This API key is working!")),A.forEach((A=>A.classList.add("success"))),e.classList.remove("secondary"))}),(e=>{A.forEach((A=>A.innerText="There was an error when checking the API key.")),A.forEach((A=>A.classList.add("error")))}))};let Y=!1,W=!1;document.addEventListener("mousedown",(()=>{Y=!0,W=!1})),document.addEventListener("mousemove",(()=>{Y&&window.getSelection().toString().length>0&&(W=!0)})),document.addEventListener("mouseup",(()=>{Y=!1}));let Z=null;const z=A=>{let e=document.querySelector("#notification");e.className="notification show",e.innerText=A,Z&&clearInterval(Z),Z=setTimeout((()=>{e.className="notification"}),4e3)},q=A=>{for(const e of A.querySelectorAll("code, pre"))e.addEventListener("click",(A=>{W||(A.stopPropagation(),navigator.clipboard.writeText(e.innerText).then((()=>{z("Copied!")})).catch((A=>{z("Error copying text to clipboard:")})))}))},j=(A,e)=>{const t=document.querySelector("#output"),r=document.createElement("div");r.classList.add(`${e}-container`),t.appendChild(r);const n=document.createElement("div");n.classList.add(`${e}-bubble`),n.classList.add("message-bubble");const s=V(A);q(s),n.appendChild(s),r.appendChild(n);const o=document.createElement("span");return o.classList.add("copied-indicator"),r.appendChild(o),r};window.addEventListener("click",(()=>{const A=document.querySelectorAll(".copied-indicator");for(const e of A)e.innerText=""}));const $=A=>j(A,"response");window.addEventListener("load",(()=>{(()=>{const A=document.querySelectorAll("[data-persistent-name]"),e=A=>A.getAttribute("data-persistent-name");for(const t of A){const A=e(t);localStorage.getItem(A)||localStorage.setItem(A,t.value)}for(const t of A){const r=e(t);t.value=localStorage.getItem(r),t.addEventListener("input",(()=>{const n=t.value;localStorage.setItem(r,n),console.log("saving:",r,n);for(const t of A)e(t)===r&&(t.value=n)})),window.addEventListener("storage",(A=>{A.key===r&&(t.value=A.newValue)}))}})(),(()=>{window.addEventListener("storage",(A=>{"api-key"===A.key&&_()}));const A=document.querySelectorAll(".api-key-input");for(const e of A)e.addEventListener("input",(()=>{_()}));const e=localStorage.getItem("api-key"),t=document.querySelector("#intro-view");e||t.classList.remove("hidden"),document.querySelector("#intro-continue").addEventListener("click",(()=>{t.classList.add("hidden"),document.querySelector("#prompt").focus()}))})(),(()=>{const e=document.querySelector("#settings-view");document.querySelector("#settings-button").addEventListener("click",(()=>{e.classList.remove("hidden"),J();for(const e of document.querySelectorAll("textarea"))A(e)})),document.querySelector("#settings-exit-button").addEventListener("click",(()=>{e.classList.add("hidden")})),document.querySelector("#settings-show-intro").addEventListener("click",(()=>{e.classList.add("hidden"),document.querySelector("#intro-view").classList.remove("hidden"),_()}))})();let e=[{role:"system",content:localStorage.getItem("initial-system-message")}];document.querySelector("#screenshot-button").addEventListener("click",(()=>{(()=>{const A=document.querySelector("#output"),e=getComputedStyle(document.body).backgroundColor;X()(A,{backgroundColor:e}).then((A=>{const e=A.toDataURL("image/png"),t=document.createElement("a");t.href=e,t.download="assistant.png",document.body.appendChild(t),t.click(),document.body.removeChild(t)}))})()})),document.querySelector("#save-md-button").addEventListener("click",(()=>{(A=>{const e=A.map((A=>{return`## ${e=A.role,e[0].toUpperCase()+e.slice(1)}\n${A.content}`;var e})).join("\n\n"),t="data:text/markdown;charset=utf-8,"+encodeURIComponent(e),r=document.createElement("a");r.href=t,r.download="assistant.md",document.body.appendChild(r),r.click(),document.body.removeChild(r)})(e)}));const t=A=>{(()=>{for(const A of document.querySelectorAll(".error"))A.remove()})(),(A=>{j(A,"my-message")})(A);const t=$("● ● ●");document.body.scrollIntoView({block:"end",behavior:"smooth"}),e.push({role:"user",content:A});const r=localStorage.getItem("api-key"),n=(()=>{const A=document.querySelector("#model-select");return A.options[A.selectedIndex].value})();let s={},o=null;const i=parseInt(localStorage.getItem("maximum-messages"))+1;((A,e,t)=>{e.model||(e.model="gpt-3.5-turbo"),e.stream=!0,fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${A}`},body:JSON.stringify(e)}).then((A=>{const e=A.body.getReader();let r="";const n=({done:A,value:s})=>{if(A)return;const o=new TextDecoder("utf-8");for(r+=o.decode(s);-1!==r.indexOf("\n");){const A=r.indexOf("\n"),e=r.substring(0,A);r=r.substring(A+1);const n=e.replace("data: ","");if(!n)continue;if("[DONE]"===n)return;let s;try{s=JSON.parse(n)}catch(A){r=e+r;continue}t(s)}e.read().then(n)};e.read().then(n).catch((A=>{console.error("Error reading stream:",A),e.cancel()}))})).catch((A=>{console.error("Error:",A)}))})(r,{messages:[e[0],...e.slice(1).slice(-i)],model:n},(A=>{t.remove();const r=(()=>{const{scrollTop:A,clientHeight:e,scrollHeight:t}=document.documentElement;return A+e>=t})();if("error"in A)((A,e)=>{const t=document.querySelector("#output"),r=document.createElement("div");r.classList.add("assistant-container"),r.classList.add("error"),t.appendChild(r),r.innerText=A})(A.error.message);else if("choices"in A){const t=A.choices[0].delta;if("role"in t&&(s={role:t.role,content:""},e.push(s),o=$(s.content)),"content"in t){s.content+=t.content,o.firstChild.innerHTML="";const A=V(s.content+"\n");q(A),o.firstChild.appendChild(A)}}r&&window.scrollTo(0,document.body.scrollHeight)}))},r=(()=>{const A={};return window.location.hash.substring(1).split("&").forEach((e=>{const[t,r]=e.split("=");A[decodeURIComponent(t)]=decodeURIComponent(r)})),A})();"q"in r&&r.q&&t(r.q);const n=()=>{const e=document.querySelector("#prompt").value;document.querySelector("#prompt").value="",A(s),t(e)},s=document.querySelector("#prompt");s.addEventListener("keydown",(A=>{13!==A.keyCode||A.ctrlKey||A.altKey||A.shiftKey||(A.preventDefault(),n())})),document.querySelector("form").addEventListener("submit",(A=>{A.preventDefault(),n()}));for(const e of document.querySelectorAll("textarea"))e.addEventListener("input",(()=>{A(e)})),A(e);document.addEventListener("keydown",(A=>{A.ctrlKey&&"m"===A.key.toLowerCase()&&o("model-select")}));const o=A=>{const e=document.querySelector(`#${A}`);e.selectedIndex