From 696477d6cb60a675912c3caca957da01755ad7bb Mon Sep 17 00:00:00 2001 From: Vijay Janapa Reddi Date: Mon, 18 Nov 2024 12:02:57 -0500 Subject: [PATCH] Changed widget_access to socratiq --- contents/ai/socratiq.qmd | 8 ++++---- scripts/ai_menu/dist/bundle.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contents/ai/socratiq.qmd b/contents/ai/socratiq.qmd index 190e6e94..b8753e6a 100644 --- a/contents/ai/socratiq.qmd +++ b/contents/ai/socratiq.qmd @@ -21,18 +21,18 @@ Please note that this is an experimental feature. We are experimenting with the You can enable SocratiQ by clicking the button below: -[Activate SocratiQ]{.btn .btn-success onclick="window.location.href = window.location.pathname + '?widget_access=true'"} +[Activate SocratiQ]{.btn .btn-success onclick="window.location.href = window.location.pathname + '?socratiq=true'"} At anytime, you can deacticate SocratiQ by clicking this button: -[Deactivate SocratiQ]{.btn .btn-warning onclick="window.location.href = window.location.pathname + '?widget_access=false'"} +[Deactivate SocratiQ]{.btn .btn-warning onclick="window.location.href = window.location.pathname + '?socratiq=false'"} :::{.callout-tip} ## Quick URL Access You can directly control SocratiQ by adding these parameters to your URL: -- To activate: [mlsysbook.ai/?widget_access=true](https://mlsysbook.ai/?widget_access=true) -- To deactivate: [mlsysbook.ai/?widget_access=false](https://mlsysbook.ai/?widget_access=false) +- To activate: [mlsysbook.ai/?socratiq=true](https://mlsysbook.ai/?socratiq=true) +- To deactivate: [mlsysbook.ai/?socratiq=false](https://mlsysbook.ai/?socratiq=false) This gives you quick access to toggle SocratiQ's functionality directly from your browser's address bar. ::: diff --git a/scripts/ai_menu/dist/bundle.js b/scripts/ai_menu/dist/bundle.js index 870ee881..be9cedf0 100644 --- a/scripts/ai_menu/dist/bundle.js +++ b/scripts/ai_menu/dist/bundle.js @@ -1564,7 +1564,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),J=k,Z=z),V===void 0&&( `;const l=o();navigator.clipboard.writeText(l).then(()=>{setTimeout(()=>{n.innerHTML=s},2e3)}).catch(c=>{console.error("Failed to copy: ",c),n.innerHTML=s})}),r&&r.addEventListener("click",function(){const s=o(),l=new Blob([s],{type:"text/markdown"}),c=URL.createObjectURL(l),u=document.createElement("a");u.href=c,u.download="content.md",document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(c)}),i&&i.addEventListener("click",s=>{if(s.preventDefault(),!s.currentTarget.closest(".p-3.relative.max-w-xs.bg-white, .p-3.max-w-xs.bg-white")){Hi(t,"Could not find message to share","error");return}const c=i.innerHTML;i.innerHTML=` - `;try{const A={markdown:o(),type:"ai-message"},d=encodeURIComponent(JSON.stringify(A)),f=new URLSearchParams(window.location.search);f.set("shared_messages",d),f.set("widget_access","true");const p=`${window.location.origin}${window.location.pathname}?${f.toString()}`;navigator.clipboard.writeText(p).then(()=>{Hi(t,"Share URL copied to clipboard! Share this link to show this conversation to others.")}).catch(g=>{Hi(t,"Failed to copy share URL","error"),console.error("Failed to copy:",g)}).finally(()=>{setTimeout(()=>{i.innerHTML=c},2e3)})}catch(u){console.error("Error sharing message:",u),Hi(t,"Failed to create share URL","error"),i.innerHTML=c}}),a&&a.addEventListener("click",s=>{if(s.preventDefault(),a.dataset.matches&&a.dataset.matches!=="[]"){const A=parseInt(a.dataset.currentIndex||"0");Mg(a,A);return}const l=a.innerHTML;requestAnimationFrame(()=>{a.innerHTML=` + `;try{const A={markdown:o(),type:"ai-message"},d=encodeURIComponent(JSON.stringify(A)),f=new URLSearchParams(window.location.search);f.set("shared_messages",d),f.set("socratiq","true");const p=`${window.location.origin}${window.location.pathname}?${f.toString()}`;navigator.clipboard.writeText(p).then(()=>{Hi(t,"Share URL copied to clipboard! Share this link to show this conversation to others.")}).catch(g=>{Hi(t,"Failed to copy share URL","error"),console.error("Failed to copy:",g)}).finally(()=>{setTimeout(()=>{i.innerHTML=c},2e3)})}catch(u){console.error("Error sharing message:",u),Hi(t,"Failed to create share URL","error"),i.innerHTML=c}}),a&&a.addEventListener("click",s=>{if(s.preventDefault(),a.dataset.matches&&a.dataset.matches!=="[]"){const A=parseInt(a.dataset.currentIndex||"0");Mg(a,A);return}const l=a.innerHTML;requestAnimationFrame(()=>{a.innerHTML=` `});const c=a.closest(".flex.space-x-2"),u=a.closest(".p-3.relative.max-w-xs.bg-white, .p-3.max-w-xs.bg-white");setTimeout(()=>{Woe(a,c,u,l,t)},0)})}async function Woe(t,e,n,r,i){if(!e||!n){console.error("Required elements not found"),t.innerHTML=r;return}if(e.dataset.initialScrollY=window.scrollY,!e.querySelector("#back-btn-group")){const o=Koe(i);o.addEventListener("click",s=>{s.preventDefault();const l=parseInt(e.dataset.initialScrollY||"0");window.scrollTo({top:l,behavior:"smooth"})}),e.appendChild(o)}document.querySelectorAll(".fuzzy-highlight").forEach(o=>{o.classList.remove("fuzzy-highlight"),o.style.animation=""});const a=n.getAttribute("data-markdown")||n.querySelector(".text-sm.text-zinc-800")?.textContent||n.textContent;try{const o=await i4(a);if(o.length>0){if(t.dataset.matches=JSON.stringify(o),t.dataset.currentIndex="0",!document.getElementById("highlight-styles")){const s=document.createElement("style");s.id="highlight-styles",s.textContent=` @@ -2444,7 +2444,7 @@ ${g.value.content}`;QT(b,t),r.style.display="none"});a.appendChild(_)});const p= display: none; `,t.appendChild(i);const a=async l=>{e.style.display==="block"?(e.style.display="none",i.style.display="none",document.body.style.overflow=""):(await Rx(l),e.style.display="block",i.style.display="block",document.body.style.overflow="hidden")},o=t.querySelector("#new-chat"),s=t.querySelector("#new-chat-btn");return co(o,"Start a new chat or load a previous chat",t),o.addEventListener("click",()=>{Vpe(),a(t)}),s?.addEventListener("click",async()=>{a(t)}),n?.addEventListener("click",()=>{a(t)}),i.addEventListener("click",()=>{a(t)}),r&&r.addEventListener("keyup",async l=>{await Kpe(l.target.value,t)}),e.addEventListener("click",l=>{l.stopPropagation()}),window.addEventListener("keydown",l=>{l.key==="Escape"&&e.style.display==="block"&&a(t)}),()=>{i&&i.parentNode&&i.parentNode.removeChild(i)}}let rP=[];async function Kpe(t,e){const n=await gpe("tinyMLDB","tinyMLDB_chats",t);if(!Wpe(n,rP)){const r=e.querySelector("#list-container");r.innerHTML="",n.forEach((i,a)=>{RU(e,i),rP=n})}}function Wpe(t,e){if(t===e)return!0;if(t==null||e==null||t.length!==e.length)return!1;for(let n=0;n{r.forEach(i=>{i.addedNodes.forEach(a=>{a.nodeType===1&&(a.classList?.contains("ai-message-chat")?[a]:Array.from(a.querySelectorAll(".ai-message-chat"))).forEach(s=>this.initializeMessageDropdown(s))})})}).observe(this.shadowRoot,{childList:!0,subtree:!0}),this.shadowRoot.querySelectorAll(".ai-message-chat").forEach(r=>this.initializeMessageDropdown(r))}initializeMessageDropdown(e){const n=e.querySelector(".difficulty-dropdown");if(!n)return;const r=["🚲 Beginner","🚗 Intermediate","🚁 Advanced","🛸 Bloom's Taxonomy"],i=n.querySelector(".current-difficulty-level"),a=n.querySelector("button"),o=n.querySelector(".difficulty-options");if(i){const l=e.getAttribute("data-difficulty");if(l!==null){const c=Math.min(Math.max(parseInt(l,10),0),r.length-1);i.textContent=r[c].slice(2).trim()}else i.textContent=r[0].slice(2).trim()}if(a){const l=a.cloneNode(!0);a.parentNode.replaceChild(l,a),l.addEventListener("click",c=>{c.stopPropagation(),o.classList.toggle("hidden")})}n.querySelectorAll(".difficulty-option").forEach((l,c)=>{const u=l.cloneNode(!0);l.parentNode.replaceChild(u,l),u.addEventListener("click",()=>{i&&(i.textContent=r[c].slice(2).trim()),o.classList.add("hidden");const A=n.closest(".ai-message-chat");if(!A)return;A.dataset.selectedDifficulty=c;const d=document.createElement("div");d.id="progress";const f=A.querySelector(".markdown-preview-container"),p=A.querySelector(".copy-paste-share-btn-container");p&&p.remove(),f&&(f.parentNode.insertBefore(d,f),f.id="markdown-preview"),this.dropdownHandler.handleDifficultySelection(n,c,A)})}),this.hasInitializedGlobalListener||(document.addEventListener("click",l=>{this.shadowRoot.querySelectorAll(".difficulty-dropdown").forEach(u=>{if(!u.contains(l.target)){const A=u.querySelector(".difficulty-options");A&&A.classList.add("hidden")}})}),this.hasInitializedGlobalListener=!0),n.dataset.initialized="true"}}const Bx=`::: loader ::: -`;let kf,gu=ox("explain"),cd=ox("quiz"),Jpe=ox("query"),oo="",at,ku,Zpe,Mf=l4,Dx;async function ehe(){if(!the())return;const t=new URLSearchParams(window.location.search),e=t.get("x"),n=t.get("y");e&&n&&window.scrollTo(parseInt(e,10),parseInt(n,10)),kf=await ase(),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",iP):iP()}ehe();function the(){const e=new URLSearchParams(window.location.search).get("widget_access");return e==="true"?document.cookie="widget_access=true; path=/; max-age="+60*60*24*365:e==="false"&&(document.cookie="widget_access=true; path=/; max-age=0"),document.cookie.split("; ").some(r=>r.startsWith("widget_access=true"))}async function iP(){const t=document.createElement("div");t.id="widget-chat-container",t.style.position="fixed",t.style.zIndex="9999",document.body.appendChild(t),at=t.attachShadow({mode:"open"});const e=document.createElement("link");e.rel="stylesheet",e.href="https://cdn.jsdelivr.net/npm/tailwindcss@^2.2.19/dist/tailwind.min.css",at.appendChild(e);const n=document.createElement("style");n.textContent=` +`;let kf,gu=ox("explain"),cd=ox("quiz"),Jpe=ox("query"),oo="",at,ku,Zpe,Mf=l4,Dx;async function ehe(){if(!the())return;const t=new URLSearchParams(window.location.search),e=t.get("x"),n=t.get("y");e&&n&&window.scrollTo(parseInt(e,10),parseInt(n,10)),kf=await ase(),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",iP):iP()}ehe();function the(){const e=new URLSearchParams(window.location.search).get("socratiq");return e==="true"?document.cookie="socratiq=true; path=/; max-age="+60*60*24*365:e==="false"&&(document.cookie="socratiq=true; path=/; max-age=0"),document.cookie.split("; ").some(r=>r.startsWith("socratiq=true"))}async function iP(){const t=document.createElement("div");t.id="widget-chat-container",t.style.position="fixed",t.style.zIndex="9999",document.body.appendChild(t),at=t.attachShadow({mode:"open"});const e=document.createElement("link");e.rel="stylesheet",e.href="https://cdn.jsdelivr.net/npm/tailwindcss@^2.2.19/dist/tailwind.min.css",at.appendChild(e);const n=document.createElement("style");n.textContent=` ${VQ} `,at.appendChild(n),at.innerHTML+=zQ,Goe(),new Xpe(at),che(),ise(at),Zfe(at),cY(at),g4(),wpe(at),Npe(at);const r=new Jfe(at);r.init(),Mf=r.generateSystemPrompt(),ku=await rhe(at),Ope(at),Lpe(at),Fpe(at),Qpe(),Qfe(at),mY(at),Hpe(at),uY(at),Gpe(at),nhe(),jpe(at),Ype(at);const i=document.querySelector(".quarto-page-breadcrumbs");i&&dle(i),ose(at,kf)}function nhe(){Wy(at),setTimeout(()=>{at.querySelectorAll(".ai-message-chat"),Wy(at)},1e3)}async function rhe(t){let e;try{e=fpe(),e!==null&&await wU(t,e).then(()=>{Wy(at)}).catch(i=>console.error("Error loading chat:",i))}catch(i){console.error("Failed to load content:",i)}await new Promise(i=>setTimeout(i,1e3));const r=new URLSearchParams(window.location.search).get("shared_messages");if(r)try{window.history.replaceState({},"",window.location.pathname);const i=JSON.parse(decodeURIComponent(r));ahe(i.markdown),await new Promise(a=>setTimeout(a,500)),b0(at,!0),pc(at)}catch(i){console.error("Error handling shared message:",i),tl(at,"Failed to load shared message","error")}return e}async function ihe(t,e=["https://harvard-edge.github.io/cs249r_book/"],n="",r,i=3,a=3){gu.set_field("quote",""),gu.set_field("understanding",i),gu.set_field("power_up",a);let o=t;r?(o=`${r}