import{s as Ye,a as ve,g as we,c as $e}from"./mem0_proxy-D5oyS3vJ.js";import{M as He}from"./api-D2MZ7O5A.js";import{S as Ae}from"./messages-CjQo1qp0.js";import{S as a}from"./storage-pXeRtiJs.js";import{c as Ge,a as Ce,C as F,S as f}from"./util_positioning-Cx352_Ay.js";Ye();async function Xe(){try{const B=await $e();chrome.runtime.sendMessage({action:Ae.OPEN_DASHBOARD,url:B})}catch(B){console.warn("Unable to open Memory Platform dashboard",B)}}try{let B=function(){const o=D();o&&(o.dataset.replitBackgroundHooked||(o.dataset.replitBackgroundHooked="true",ne||(ne=function(){const e=(o.textContent||o.innerText||"").trim();Se.setText(e)}),o.addEventListener("input",ne),o.addEventListener("keyup",ne)))},D=function(){const o=['div[contenteditable="true"][class="cm-content cm-lineWrapping"][role="textbox"]','div.cm-content.cm-lineWrapping[contenteditable="true"]','.cm-content[contenteditable="true"]','div[contenteditable="true"].cm-content','div.cm-content[role="textbox"]',".cm-content",'div[contenteditable="true"]','[contenteditable="true"]'];for(const e of o){const t=document.querySelector(e);if(t)return q||setTimeout(()=>{q||me()},500),t}return null},Te=function(){if(fe)return;const o=D();if(!o){let e=0;const t=10;(()=>{e<t&&(e++,setTimeout(Te,500))})();return}C=o.textContent||o.innerText||"",fe=new MutationObserver(e=>{for(const t of e)if(t.type==="characterData"||t.type==="childList"){const n=o.textContent||o.innerText||"";n!==C&&(C=n)}}),fe.observe(o,{childList:!0,characterData:!0,subtree:!0}),o.dataset.mem0InputListener||(o.dataset.mem0InputListener="true",o.addEventListener("input",function(){const e=this.textContent||this.innerText||"";e!==C&&(C=e)}))},Ne=function(o,e){if(o)if(o.contentEditable==="true"){o.innerHTML="",e.split(`
`).forEach((r,p)=>{const c=document.createElement("div");c.className="cm-line",p===0&&(c.className+=" cm-replit-active-line"),r.trim()===""?c.innerHTML="<br>":c.textContent=r,o.appendChild(c)}),C=e,o.dispatchEvent(new Event("input",{bubbles:!0})),o.focus();const n=document.createRange(),s=window.getSelection();n.selectNodeContents(o),n.collapse(!1),s&&(s.removeAllRanges(),s.addRange(n))}else o.value=e,C=e,o.dispatchEvent(new Event("input",{bubbles:!0}))},pe=function(o=null){let e;if(o)e=o;else{const s=D();if(!s)return"";e=s.textContent||s.innerText||""}const t=Ce.memory_header_text,n=e.indexOf(t);n!==-1&&(e=e.substring(0,n).trim());try{const s=Ce.memory_header_plain_regex;e=e.replace(s,"").trim()}catch{}return e},ue=function(){return new Promise(o=>{chrome.storage.sync.get([a.MEMORY_ENABLED],function(e){o(e.memory_enabled!==!1)})})},me=function(){const o=['button[data-cy="ai-prompt-submit"]','button[data-cy="ai-chat-send-button"]','button[aria-label="Send"]','button[type="button"][aria-label="Send"]','.useView_view__C2mnv[aria-label="Send"]','button[type="submit"]','button:has(svg[data-testid="send"])','button:has([data-testid="send"])'];function e(){const r=D();if(!r)return;let p=(r.textContent||r.innerText||"").trim();if(!p&&C&&(p=C.trim()),!p)return;const c=pe(p);xe&&ge===c||(xe=!0,ge=c,setTimeout(()=>{xe=!1,ge=""},1e3),chrome.storage.sync.get([a.API_KEY,a.USER_ID_CAMEL,a.ACCESS_TOKEN,a.MEMORY_ENABLED,a.SELECTED_ORG,a.SELECTED_PROJECT,a.USER_ID],function(d){if(d.memory_enabled===!1||!d.apiKey&&!d.access_token)return;const m=d.access_token?`Bearer ${d.access_token}`:`Token ${d.apiKey}`,u=d.userId||d.user_id||"chrome-extension-user",b={};d.selected_org&&(b.org_id=d.selected_org),d.selected_project&&(b.project_id=d.selected_project),fetch("https://api.mem0.ai/v1/memories/",{method:"POST",headers:{"Content-Type":"application/json",Authorization:m},body:JSON.stringify({messages:[{role:He.User,content:c}],user_id:u,infer:!0,metadata:{provider:"Replit"},source:"COGNIZ_CHROME_EXTENSION",...b})}).then(w=>w.json()).then(()=>{}).catch(w=>{console.error("[Mem0 Replit] Error saving memory:",w)})}),setTimeout(()=>{K=[],M.clear()},100))}let t=null,n=!1;for(const r of o)if(t=document.querySelector(r),t)if(t.dataset.mem0Listener){n=!0;break}else{t.dataset.mem0Listener="true",t.addEventListener("click",function(){e()}),n=!0;break}const s=D();s&&(s.dataset.mem0KeyListener||(s.dataset.mem0KeyListener="true",s.addEventListener("keydown",function(r){r.key.length===1&&!r.ctrlKey&&!r.metaKey&&!r.altKey&&setTimeout(()=>{C=s.textContent||s.innerText||""},0),r.key==="Enter"&&!r.shiftKey&&setTimeout(()=>{e()},10)}),s.addEventListener("keyup",function(){C=s.textContent||s.innerText||""}))),n||s?q=!0:q=!1},he=function(){try{if(ee)return;ee=!0,Te();try{B()}catch{}if(F&&F.mountOnEditorFocus){try{document.getElementById("mem0-icon-button")||F.resolveCachedAnchor({learnKey:location.host+":"+location.pathname},null,864e5).then(function(e){if(!e||!e.el)return;let t=F.createShadowRootHost("mem0-root"),n=t.host,s=t.shadow;n.id="mem0-icon-button";let r=typeof f<"u"&&f.replit?f.replit:null,p=e.placement||r&&r.placement||{strategy:"float",placement:"right-center",gap:12};F.applyPlacement({container:n,anchor:e.el,placement:p});let c=document.createElement("style");c.textContent=`
                :host { position: relative; }
                .mem0-btn { all: initial; cursor: pointer; display:inline-flex; align-items:center; justify-content:center; width:40px; height:40px; border-radius:50%; box-shadow: 0 6px 16px rgba(0,0,0,0.3); background:#1C1C1E; }
                .mem0-btn img { width:20px; height:20px; border-radius:50%; }
                .dot { position:absolute; top:-2px; right:-2px; width:8px; height:8px; background:#80DDA2; border-radius:50%; border:2px solid #1C1C1E; display:none; }
                :host([data-has-text="1"]) .dot { display:block; }
              `;let d=document.createElement("button");d.className="mem0-btn";let m=document.createElement("img");m.src=chrome.runtime.getURL("icons/icon48.png");let u=document.createElement("div");u.className="dot",d.appendChild(m),s.append(c,d,u),d.addEventListener("click",function(){oe()}),typeof j=="function"&&setTimeout(j,0)})}catch{}F.mountOnEditorFocus({existingHostSelector:"#mem0-icon-button",editorSelector:typeof f<"u"&&f.replit&&f.replit.editorSelector?f.replit.editorSelector:'textarea, [contenteditable="true"], input[type="text"]',deriveAnchor:typeof f<"u"&&f.replit&&typeof f.replit.deriveAnchor=="function"?f.replit.deriveAnchor:function(e){return e.closest("form")||e.parentElement||document.body},placement:typeof f<"u"&&f.replit&&f.replit.placement?f.replit.placement:{strategy:"float",placement:"right-center",gap:12},render:function(e,t){t.id="mem0-icon-button";let n=document.createElement("style");n.textContent=`
              :host { position: relative; }
              .mem0-btn { all: initial; cursor: pointer; display:inline-flex; align-items:center; justify-content:center; width:40px; height:40px; border-radius:50%; box-shadow: 0 6px 16px rgba(0,0,0,0.3); background:#1C1C1E; }
              .mem0-btn img { width:20px; height:20px; border-radius:50%; }
              .dot { position:absolute; top:-2px; right:-2px; width:8px; height:8px; background:#80DDA2; border-radius:50%; border:2px solid #1C1C1E; display:none; }
              :host([data-has-text="1"]) .dot { display:block; }
            `;let s=document.createElement("button");s.className="mem0-btn";let r=document.createElement("img");r.src=chrome.runtime.getURL("icons/icon48.png");let p=document.createElement("div");p.className="dot",s.appendChild(r),e.append(n,s,p),s.addEventListener("click",function(){oe()}),typeof j=="function"&&setTimeout(j,0)},fallback:function(){let e=typeof f<"u"&&f.replit?f.replit:null;return F.mountResilient({anchors:[{find:function(){let t=e&&e.editorSelector||'textarea, [contenteditable="true"], input[type="text"]',n=document.querySelector(t);if(!n)return null;try{return e&&typeof e.deriveAnchor=="function"?e.deriveAnchor(n):n.closest("form")||n.parentElement||document.body}catch{return n.closest("form")||n.parentElement||document.body}}}],placement:e&&e.placement||{strategy:"float",placement:"right-center",gap:12},enableFloatingFallback:!0,render:function(t,n){n.id="mem0-icon-button";let s=document.createElement("style");s.textContent=`
                  :host { position: relative; }
                  .mem0-btn { all: initial; cursor: pointer; display:inline-flex; align-items:center; justify-content:center; width:40px; height:40px; border-radius:50%; box-shadow: 0 6px 16px rgba(0,0,0,0.3); background:#1C1C1E; }
                  .mem0-btn img { width:20px; height:20px; border-radius:50%; }
                  .dot { position:absolute; top:-2px; right:-2px; width:8px; height:8px; background:#80DDA2; border-radius:50%; border:2px solid #1C1C1E; display:none; }
                  :host([data-has-text="1"]) .dot { display:block; }
                `;let r=document.createElement("button");r.className="mem0-btn";let p=document.createElement("img");p.src=chrome.runtime.getURL("icons/icon48.png");let c=document.createElement("div");c.className="dot",r.appendChild(p),t.append(s,r,c),r.addEventListener("click",function(){oe()}),typeof j=="function"&&setTimeout(j,0)}})}})}me()}catch(e){console.error("[Mem0] Error during initialization:",e),ee=!1}T&&T.disconnect(),T=new MutationObserver(async()=>{T&&T.debounceTimer&&clearTimeout(T.debounceTimer),T&&(T.debounceTimer=setTimeout(async()=>{const e=await ue();if(!e){const t=document.querySelector('button[aria-label="Mem0"]');t&&t.parentElement&&t.parentElement.remove()}e&&!q&&me(),j()},100))}),document.body.dataset.mem0KeyboardListener||(document.body.dataset.mem0KeyboardListener="true",document.addEventListener("keydown",function(e){e.ctrlKey&&e.key==="m"&&(e.preventDefault(),(async()=>await oe())())})),T.observe(document.body,{childList:!0,subtree:!0,attributeFilter:["class","style"]});const o=setInterval(async()=>{const e=await ue(),t=document.querySelector('button[aria-label="Mem0"]');!e&&t&&t.parentElement?.remove()},1e4);T&&(T.memoryStateInterval=o)},ke=function(){const o=D();if(o&&K.length>0){const e=pe();let t=`

`+Ce.memory_header_text+`
`;K.forEach((n,s)=>{t+=`- ${n}`,s<K.length-1&&(t+=`
`)}),Ne(o,e+t)}},Be=function(o,e){const t=document.querySelector(".mem0-button-popup");t&&t.remove();const n=document.createElement("div");n.className="mem0-button-popup",n.style.cssText=`
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #2d2e30;
    border: 1px solid #5f6368;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 10001;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  `,n.textContent=e;const s=document.createElement("div");s.style.cssText=`
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 8px;
    height: 8px;
    background-color: #2d2e30;
    border-right: 1px solid #5f6368;
    border-bottom: 1px solid #5f6368;
  `,n.appendChild(s),o.style.position="relative",o.appendChild(n),setTimeout(()=>{n&&n.parentElement&&n.remove()},3e3)},je=function(){const o=document.querySelector("#mem0-login-popup");o&&o.remove();const e=document.createElement("div");e.id="mem0-login-popup",e.style.cssText=`
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
  `;const t=document.createElement("div");t.style.cssText=`
    background-color: #2d2e30;
    border-radius: 12px;
    width: 320px;
    padding: 24px;
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  `;const n=document.createElement("button");n.style.cssText=`
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: #9aa0a6;
    font-size: 16px;
    cursor: pointer;
  `,n.innerHTML="&times;",n.addEventListener("click",()=>{document.body.removeChild(e)});const s=document.createElement("div");s.style.cssText=`
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
  `;const r=document.createElement("h2");r.textContent="Sign in to Cogniz",r.style.cssText=`
    margin: 0;
    font-size: 18px;
    font-weight: 600;
  `,s.appendChild(r);const p=document.createElement("p");p.textContent="Please sign in to access your memories and enhance your conversations!",p.style.cssText=`
    margin-bottom: 24px;
    color: #e8eaed;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
  `;const c=document.createElement("button");c.style.cssText=`
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
    background-color: #1a73e8;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    gap: 8px;
  `;const d=document.createElement("img");d.src=chrome.runtime.getURL("icons/icon48.png"),d.style.cssText=`
    width: 20px;
    height: 20px;
    border-radius: 50%;
  `;const m=document.createElement("span");m.textContent="Sign in with Cogniz",c.appendChild(d),c.appendChild(m),c.addEventListener("mouseenter",()=>{c.style.backgroundColor="#1557b0"}),c.addEventListener("mouseleave",()=>{c.style.backgroundColor="#1a73e8"}),c.addEventListener("click",()=>{Xe(),document.body.removeChild(e)}),t.appendChild(s),t.appendChild(p),t.appendChild(c),e.appendChild(t),e.appendChild(n),e.addEventListener("click",u=>{u.target===e&&document.body.removeChild(e)}),document.body.appendChild(e)},Q=function(o,e=!1){let t=null;if(Y&&v){const i=v.querySelector('div[style*="position: absolute"]');i&&(t={top:parseInt(i.style.top)||0,left:parseInt(i.style.left)||0}),document.body.removeChild(v)}Y=!0;let n=0;const s=447;let r=400,p=3,c,d;if(t){c=t.top,d=t.left;const i=window.innerWidth-s,l=window.innerHeight-r;d=Math.max(0,Math.min(d,i)),c=Math.max(0,Math.min(c,l))}else{const i=document.querySelector("#mem0-icon-button");if(i){const l=i.getBoundingClientRect(),E=window.innerHeight,S=E-l.bottom;d=Math.max(l.left+l.width/2-s/2,10),d+s>window.innerWidth-10&&(d=window.innerWidth-s-10),S>=r?c=l.bottom+10:(c=l.top-r-10,l.top<E/2&&(r=300,p=2))}else c=100,d=window.innerWidth/2-s/2}const m=document.createElement("div");m.style.cssText=`
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    display: flex;
    z-index: 10000;
    pointer-events: auto;
  `,v=m,m.addEventListener("click",i=>{i.target===m&&Ee()});const u=document.createElement("div");u.style.cssText=`
    background-color: #2d2e30;
    border-radius: 12px;
    width: ${s}px;
    height: ${r}px;
    display: flex;
    flex-direction: column;
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: absolute;
    top: ${c}px;
    left: ${d}px;
    pointer-events: auto;
    border: 1px solid #5f6368;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    cursor: move;
    `;let b=!1,w=0,$=0,Le=0,Me=0;function Ke(i){const l=i.target;(l&&l.closest(".mem0-modal-header")||i.target===u)&&(b=!0,w=i.clientX,$=i.clientY,Le=parseInt(u.style.left),Me=parseInt(u.style.top),u.style.cursor="grabbing",i.preventDefault())}function _e(i){if(!b)return;const l=i.clientX-w,E=i.clientY-$;let S=Le+l,x=Me+E;const O=window.innerWidth-s,R=window.innerHeight-r;S=Math.max(0,Math.min(S,O)),x=Math.max(0,Math.min(x,R)),u.style.left=S+"px",u.style.top=x+"px"}function Ie(){b=!1,u.style.cursor="move"}u.addEventListener("mousedown",Ke),document.addEventListener("mousemove",_e),document.addEventListener("mouseup",Ie);const _=document.createElement("div");_.className="mem0-modal-header",_.style.cssText=`
    display: flex;
    align-items: center;
    padding: 10px 16px;
    justify-content: space-between;
    background-color: #35373a;
    flex-shrink: 0;
    cursor: grab;
  `,_.addEventListener("mousedown",()=>{_.style.cursor="grabbing"}),_.addEventListener("mouseup",()=>{_.style.cursor="grab"});const ie=document.createElement("div");ie.style.cssText=`
    display: flex;
    flex-direction: row;
    align-items: center;
  `;const ye=document.createElement("img");ye.src=chrome.runtime.getURL("icons/icon48.png"),ye.style.cssText=`
    width: 26px;
    height: 26px;
    border-radius: 50%;
  `;const be=document.createElement("div");be.textContent="Cogniz Memory",be.style.cssText=`
    font-size: 16px;
    font-weight: 600;
    color: white;
    margin-left: 8px;
  `;const re=document.createElement("div");re.style.cssText=`
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  `;const I=document.createElement("button");I.style.cssText=`
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 5px 16px;
    gap: 8px;
    background-color:rgb(27, 27, 27);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: white;
    transition: background-color 0.2s;
  `,I.textContent="Add to Prompt";const se=document.createElement("span");se.innerHTML=`<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
    <path d="M5 12h14M12 5l7 7-7 7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>
`,se.style.position="relative",se.style.top="2px",I.appendChild(se),I.addEventListener("mouseenter",()=>{I.style.backgroundColor="rgb(36, 36, 36)"}),I.addEventListener("mouseleave",()=>{I.style.backgroundColor="rgb(27, 27, 27)"});const H=document.createElement("button");H.style.cssText=`
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
  `,H.innerHTML=`<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#FFFFFF" xmlns="http://www.w3.org/2000/svg">
    <path d="M12 15a3 3 0 100-6 3 3 0 000 6z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0 010-2.83l.06-.06a1.65 1.65 0 00.33-1.82 1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06a1.65 1.65 0 001.82.33H9a1.65 1.65 0 001-1.51V3a2 2 0 012-2 2 2 0 012 2v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 0 2 2 0 010 2.83l-.06.06a1.65 1.65 0 00-.33 1.82V9a1.65 1.65 0 001.51 1H21a2 2 0 012 2 2 2 0 01-2 2h-.09a1.65 1.65 0 00-1.51 1z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,H.addEventListener("click",()=>{v&&document.body.contains(v)&&(document.body.removeChild(v),Y=!1,v=null),chrome.runtime.sendMessage({action:Ae.SIDEBAR_SETTINGS})}),H.addEventListener("mouseenter",()=>{H.style.opacity="1"}),H.addEventListener("mouseleave",()=>{H.style.opacity="0.6"});const ae=document.createElement("div"),Oe=r-130;ae.style.cssText=`
    display: flex;
    flex-direction: column;
    padding: 0 16px;
    gap: 12px;
    overflow: hidden;
    flex: 1;
    height: ${Oe}px;
  `;const W=document.createElement("div");if(W.style.cssText=`
    font-size: 16px;
    font-weight: 600;
    color: #FFFFFF;
    margin-top: 16px;
    flex-shrink: 0;
  `,e)W.textContent="Loading Relevant Memories...";else{const i=o.filter(l=>l&&l.id&&!M.has(l.id)).length;W.textContent=`${i} Relevant Memories`}const ze=Oe-40,k=document.createElement("div");k.style.cssText=`
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex: 1;
    max-height: ${ze}px;
    padding-right: 8px;
    margin-right: -8px;
    scrollbar-width: thin;
    scrollbar-color: #5f6368 transparent;
  `;let J=null;function Ue(){k.innerHTML="";for(let i=0;i<p;i++){const l=document.createElement("div");l.style.cssText=`
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        padding: 12px;
        background-color: #3c4043;
        border-radius: 8px;
        height: 72px;
        flex-shrink: 0;
        animation: pulse 1.5s infinite ease-in-out;
      `;const E=document.createElement("div");E.style.cssText=`
        background-color: #5f6368;
        border-radius: 4px;
        height: 14px;
        width: 85%;
        margin-bottom: 8px;
      `;const S=document.createElement("div");S.style.cssText=`
        background-color: #5f6368;
        border-radius: 4px;
        height: 14px;
        width: 65%;
      `;const x=document.createElement("div");x.style.cssText=`
        display: flex;
        gap: 4px;
        margin-left: 10px;
      `;const O=document.createElement("div");O.style.cssText=`
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background-color: #5f6368;
      `;const R=document.createElement("div");R.style.cssText=`
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background-color: #5f6368;
      `,x.appendChild(O),x.appendChild(R);const A=document.createElement("div");A.style.cssText=`
        display: flex;
        flex-direction: column;
        flex-grow: 1;
      `,A.appendChild(E),A.appendChild(S),l.appendChild(A),l.appendChild(x),k.appendChild(l)}if(!document.getElementById("skeleton-animation")){const i=document.createElement("style");i.id="skeleton-animation",i.innerHTML=`
        @keyframes pulse {
          0% { opacity: 0.6; }
          50% { opacity: 0.8; }
          100% { opacity: 0.6; }
        }
      `,document.head.appendChild(i)}}function Re(){k.innerHTML="";const i=document.createElement("div");i.style.cssText=`
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 32px 16px;
      text-align: center;
      flex: 1;
      min-height: 200px;
    `;const l=document.createElement("div");l.innerHTML=`<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#9aa0a6" xmlns="http://www.w3.org/2000/svg">
      <path d="M9 3H5a2 2 0 00-2 2v4m6-6h10a2 2 0 012 2v10a2 2 0 01-2 2h-4M3 21h4a2 2 0 002-2v-4m-6 6V9m18 12a9 9 0 11-18 0 9 9 0 0118 0z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    </svg>`,l.style.marginBottom="16px";const E=document.createElement("div");E.textContent="No relevant memories found",E.style.cssText=`
      color: #9aa0a6;
      font-size: 14px;
      font-weight: 500;
    `,i.appendChild(l),i.appendChild(E),k.appendChild(i)}ae.appendChild(W),ae.appendChild(k);const le=document.createElement("div");le.style.cssText=`
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 10px;
    border-top: none;
    flex-shrink: 0;
  `;const g=document.createElement("button");g.innerHTML=`<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M15 19l-7-7 7-7" stroke="#9aa0a6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,g.style.cssText=`
    background: #3c4043;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
  `;const y=document.createElement("button");y.innerHTML=`<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M9 5l7 7-7 7" stroke="#9aa0a6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,y.style.cssText=g.style.cssText,le.appendChild(g),le.appendChild(y),ie.appendChild(ye),ie.appendChild(be),re.appendChild(I),re.appendChild(H),_.appendChild(ie),_.appendChild(re),u.appendChild(_),u.appendChild(ae),u.appendChild(le),m.appendChild(u),document.body.appendChild(m);function G(){if(k.innerHTML="",e){Ue();return}const i=o.filter(x=>{const O=x&&typeof x.id=="string",R=O&&M.has(x.id);return O&&!R});if(W.textContent=e?"Loading Relevant Memories...":`${i.length} Relevant Memories`,i.length===0){Re(),Pe(0,0);return}const l=Math.min(p,i.length),E=Math.ceil(i.length/l),S=Math.floor(n/l)+1;n>=i.length&&(n=Math.max(0,i.length-l)),Pe(S,E);for(let x=0;x<l;x++){let O=function(){J&&J!==h&&J.dispatchEvent(new Event("collapse")),V=!0,U.style.webkitLineClamp="unset",U.style.height="auto",P.style.overflowY="auto",P.style.maxHeight="240px",P.style.scrollbarWidth="thin",P.style.scrollbarColor="#5f6368 transparent",h.style.backgroundColor="#2d2e30",h.style.maxHeight="300px",h.style.overflow="hidden",L.style.display="flex",J=h,k.scrollTop=h.offsetTop-k.offsetTop},R=function(){V=!1,U.style.webkitLineClamp="2",U.style.height="42px",P.style.overflowY="visible",h.style.backgroundColor="#3c4043",h.style.maxHeight="72px",h.style.overflow="hidden",L.style.display="none",J=null};const A=n+x;if(A>=i.length)break;const z=i[A];z.id||(z.id=`memory-${Date.now()}-${A}`);const h=document.createElement("div");h.style.cssText=`
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        padding: 12px; 
        background-color: #3c4043;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
        min-height: 68px; 
        max-height: 68px; 
        overflow: hidden;
        flex-shrink: 0;
      `;const U=document.createElement("div");U.style.cssText=`
        font-size: 14px;
        line-height: 1.5;
        color: #e8eaed;
        flex-grow: 1;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        transition: all 0.2s ease;
        height: 42px; /* Height for 2 lines of text */
      `,U.textContent=String(z.text||"");const ce=document.createElement("div");ce.style.cssText=`
        display: flex;
        gap: 4px;
        margin-left: 10px;
        flex-shrink: 0;
      `;const N=document.createElement("button");N.style.cssText=`
        border: none;
        cursor: pointer;
        padding: 4px;
        background: #5f6368;
        color: #e8eaed;
        border-radius: 100%;
        width: 28px;
        height: 28px;
        transition: all 0.2s ease;
      `,N.innerHTML=`<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>`,N.addEventListener("mouseenter",()=>{N.style.backgroundColor="rgb(36, 36, 36)"}),N.addEventListener("mouseleave",()=>{N.style.backgroundColor="#5f6368"}),N.addEventListener("click",Z=>{Z.stopPropagation(),ve("memory_injection",{provider:"replit",source:"COGNIZ_CHROME_EXTENSION",browser:we(),injected_all:!1,memory_id:z.id}),M.add(String(z.id)),K.push(String(z.text||"")),ke(),G()});const de=document.createElement("button");de.style.cssText=`
        background: none;
        border: none;
        cursor: pointer;
        padding: 4px;
        color: #9aa0a6;
      `,de.innerHTML=`<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
        <circle cx="12" cy="12" r="2"/>
        <circle cx="12" cy="5" r="2"/>
        <circle cx="12" cy="19" r="2"/>
      </svg>`;let V=!1;const L=document.createElement("button");L.style.cssText=`
        display: none;
        align-items: center;
        gap: 6px;
        background: #5f6368;
        color: #e8eaed;
        border-radius: 8px;
        padding: 2px 4px;
        border: none;
        cursor: pointer;
        font-size: 13px;
        margin-top: 12px;
        width: fit-content;
        transition: background-color 0.2s;
      `,L.innerHTML=`
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
        Remove
      `,L.addEventListener("mouseenter",()=>{L.style.backgroundColor="#ea4335"}),L.addEventListener("mouseleave",()=>{L.style.backgroundColor="#5f6368"});const P=document.createElement("div");P.style.cssText=`
        display: flex;
        flex-direction: column;
        flex-grow: 1;
      `,P.appendChild(U),P.appendChild(L),h.addEventListener("collapse",R),de.addEventListener("click",Z=>{Z.stopPropagation(),V?R():O()}),L.addEventListener("click",Z=>{Z.stopPropagation();const De=o.findIndex(Fe=>Fe.id===z.id);De!==-1&&(o.splice(De,1),G())}),ce.appendChild(N),ce.appendChild(de),h.appendChild(P),h.appendChild(ce),k.appendChild(h),h.addEventListener("mouseenter",()=>{h.style.backgroundColor=V?"#25272a":"#484b4f"}),h.addEventListener("mouseleave",()=>{h.style.backgroundColor=V?"#2d2e30":"#3c4043"})}k.children.length===0&&i.length>0&&(n>0?(n=Math.max(0,n-p),G()):Re())}g.addEventListener("click",()=>{n>=p&&(n=Math.max(0,n-p),G())}),y.addEventListener("click",()=>{const i=o.filter(l=>!M.has(l.id));n+p<i.length&&(n=n+p,G())}),[g,y].forEach(i=>{i.addEventListener("mouseenter",()=>{i.disabled||(i.style.backgroundColor="#484b4f")}),i.addEventListener("mouseleave",()=>{i.disabled||(i.style.backgroundColor="#3c4043")})}),G();function Pe(i,l){if(o.length===0||l===0){g.disabled=!0,g.style.opacity="0.5",g.style.cursor="not-allowed",y.disabled=!0,y.style.opacity="0.5",y.style.cursor="not-allowed";return}i<=1?(g.disabled=!0,g.style.opacity="0.5",g.style.cursor="not-allowed"):(g.disabled=!1,g.style.opacity="1",g.style.cursor="pointer"),i>=l?(y.disabled=!0,y.style.opacity="0.5",y.style.cursor="not-allowed"):(y.disabled=!1,y.style.opacity="1",y.style.cursor="pointer")}I.addEventListener("click",()=>{const i=o.filter(l=>!M.has(l.id)).map(l=>(M.add(l.id),l.text));ve("memory_injection",{provider:"replit",source:"COGNIZ_CHROME_EXTENSION",browser:we(),injected_all:!0,memory_count:i.length}),K.push(...i),K.length>0?(ke(),Ee()):M.size>0&&Ee()});function Ee(){v&&document.body.contains(v)&&(document.removeEventListener("mousemove",_e),document.removeEventListener("mouseup",Ie),document.body.removeChild(v)),v=null,Y=!1}},j=function(){const o=D(),e=document.querySelector("#mem0-notification-dot");if(!o||!e)return;te&&te.disconnect();const t=()=>{(o.textContent||o.innerText||"").trim()!==""?(e.classList.add("active"),e.style.display="block"):(e.classList.remove("active"),e.style.display="none")};te=new MutationObserver(t),te.observe(o,{characterData:!0,subtree:!0,childList:!0}),o.dataset.mem0NotificationListener||(o.dataset.mem0NotificationListener="true",o.addEventListener("input",t),o.addEventListener("keyup",t),o.addEventListener("focus",t)),t()},X=!1,Y=!1,K=[];const M=new Set;let v=null,fe=null,C="",ee=!1,q=!1,T=null,te=null;const Se=Ge({fetch:async function(o,e){const t=await new Promise(w=>{chrome.storage.sync.get([a.API_KEY,a.USER_ID_CAMEL,a.ACCESS_TOKEN,a.SELECTED_ORG,a.SELECTED_PROJECT,a.USER_ID,a.SIMILARITY_THRESHOLD,a.TOP_K],function($){w($)})}),n=t[a.API_KEY],s=t[a.ACCESS_TOKEN];if(!n&&!s)return[];const r=s?`Bearer ${s}`:`Token ${n}`,p=t[a.USER_ID_CAMEL]||t[a.USER_ID]||"chrome-extension-user",c=t[a.SIMILARITY_THRESHOLD]!==void 0?t[a.SIMILARITY_THRESHOLD]:.1,d=t[a.TOP_K]!==void 0?t[a.TOP_K]:10,m={};t[a.SELECTED_ORG]&&(m.org_id=t[a.SELECTED_ORG]),t[a.SELECTED_PROJECT]&&(m.project_id=t[a.SELECTED_PROJECT]);const u={query:o,filters:{user_id:p},rerank:!0,threshold:c,top_k:d,filter_memories:!1,source:"COGNIZ_CHROME_EXTENSION",...m},b=await fetch("https://api.mem0.ai/v2/memories/search/",{method:"POST",headers:{"Content-Type":"application/json",Authorization:r},body:JSON.stringify(u),signal:e&&e.signal});if(!b.ok)throw new Error(`API request failed with status ${b.status}`);return await b.json()},onSuccess:function(o,e){if(!Y)return;const t=(e||[]).map(n=>({id:String(n.id),text:n.memory,categories:n.categories||[]}));Q(t,!1)},onError:function(){Y&&Q([],!1)},minLength:3,debounceMs:75,cacheTTL:6e4});let ne=null,xe=!1,ge="";async function oe(){if(X||(M.clear(),!await ue()))return;const e=await new Promise(r=>{chrome.storage.sync.get([a.API_KEY,a.USER_ID_CAMEL,a.ACCESS_TOKEN],function(p){r(p)})});if(!e.apiKey&&!e.access_token){je();return}const t=D();let n=t?(t.textContent||t.innerText||"").trim():"";if(!n){const r=document.querySelector('button[aria-label="Mem0"]');r&&Be(r,"Please enter some text first");return}n=pe(),X=!0;const s=setTimeout(()=>{X=!1},3e4);Q([],!0);try{const r=await new Promise(w=>{chrome.storage.sync.get([a.API_KEY,a.USER_ID_CAMEL,a.ACCESS_TOKEN,a.SELECTED_ORG,a.SELECTED_PROJECT,a.USER_ID,a.SIMILARITY_THRESHOLD,a.TOP_K],function($){w($)})}),p=r[a.API_KEY],c=r[a.USER_ID_CAMEL]||r[a.USER_ID]||"chrome-extension-user",d=r[a.ACCESS_TOKEN],m={};if(r[a.SELECTED_ORG]&&(m.org_id=r[a.SELECTED_ORG]),r[a.SELECTED_PROJECT]&&(m.project_id=r[a.SELECTED_PROJECT]),!p&&!d){X=!1;return}ve("modal_clicked",{provider:"replit",source:"COGNIZ_CHROME_EXTENSION",browser:we()});const u=d?`Bearer ${d}`:`Token ${p}`,b=[{role:He.User,content:n}];Se.runImmediate(n),fetch("https://api.mem0.ai/v1/memories/",{method:"POST",headers:{"Content-Type":"application/json",Authorization:u},body:JSON.stringify({messages:b,user_id:c,infer:!0,metadata:{provider:"Replit"},source:"COGNIZ_CHROME_EXTENSION",...m})}).catch(w=>{console.error("Error adding memory:",w)})}catch(r){console.error("Error:",r),Q([],!1)}finally{clearTimeout(s),X=!1}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{he()}):he(),setTimeout(()=>{ee||he()},2e3),setTimeout(()=>{},5e3)}catch(B){console.error("[Mem0] Critical error in content script:",B)}
