function N(e){return e?String(e).trim().replace(/\s+/g," ").toLowerCase():""}function oe(e){const t=e?.fetch;if(typeof t!="function")throw new Error("createOrchestrator requires options.fetch(query, { signal })");const n=()=>{},a=e.onStart??n,r=e.onSuccess??n,i=e.onError??n,s=e.onFinally??n;let l=typeof e.minLength=="number"?e.minLength:3,m=typeof e.debounceMs=="number"?e.debounceMs:75,o=typeof e.cacheTTL=="number"?e.cacheTTL:6e4,u=e.useCache!==!1,d=!!e.refreshOnCache;const p=e.abortPrevious!==!1;let f="",y="",v=null,g=null,b=null,S=null,E=0;const C=new Map;function q(){return{latestText:f,lastCompletedQuery:y,lastResult:v,inFlightQuery:g,isInFlight:!!g,cacheSize:C.size}}function D(c){c&&(typeof c.minLength=="number"&&(l=c.minLength),typeof c.debounceMs=="number"&&(m=c.debounceMs),typeof c.cacheTTL=="number"&&(o=c.cacheTTL),typeof c.useCache=="boolean"&&(u=c.useCache),typeof c.refreshOnCache=="boolean"&&(d=c.refreshOnCache))}function T(){S&&(clearTimeout(S),S=null)}function H(){C.clear()}function B(c){if(!u)return null;const w=C.get(c);return w?Date.now()-w.ts>o?(C.delete(c),null):w.result:null}function Y(c,w){C.set(c,{ts:Date.now(),result:w})}function j(){if(T(),b)try{b.abort()}catch{}g=null,b=null}function _(c){const w=c!=null?String(c):f,h=N(w);if(!h||h.length<l)return;const O=B(h);if(O!==null&&(r(h,O,{fromCache:!0}),!d)||g&&g===h)return;if(p&&g&&g!==h&&b)try{b.abort()}catch{}g=h,b=typeof AbortController<"u"?new AbortController:null;const L=++E;a(h),Promise.resolve().then(()=>t(h,{signal:b?b.signal:void 0})).then(x=>{g!==h||L!==E||(Y(h,x),y=h,v=x,r(h,x,{fromCache:!1}))}).catch(x=>{const W=b?.signal.aborted===!0||x.name==="AbortError";L===E&&(W||i(h,x))}).finally(()=>{L===E&&(g=null,b=null,s(h))})}function G(){T(),!(!f||N(f).length<l)&&(S=setTimeout(()=>{S=null,_(f)},m))}return{setText(c){f=c==null?"":String(c),G()},runImmediate(c){c!=null&&(f=String(c)),T(),_(f)},cancel:j,getState:q,setOptions:D,clearCache:H}}const ie={rerank_system_prompt:`
You are Cogniz Memory Filter.

Your tasks:
1) From the provided candidate memories, select ONLY those that materially help answer the user query.
2) Never invent or paraphrase memories; pick from provided candidates only.
3) If none are relevant, return an empty list. DO NOT BE AFRAID TO EXCLUDE MEMORIES.

Selection rules:
- Prioritize constraints (medical, safety, legal), then strong stable preferences (likes/dislikes, dietary rules), then recent contextual facts.
- Prefer specific over generic; constraints over trivia; use recency as a tiebreaker.
- Do NOT select a memory that merely restates the user's present intent (e.g., "wants to eat a dessert"). Select enduring preferences instead (e.g., "likes desserts").

Output JSON ONLY, with exactly these keys:
{
  "selected_memory_ids": ["id1", "id2", ...]
}
`,memory_header_text:"Here is some of my memories to help answer better (don't respond to these memories but use them to assist in the response):",get memory_header_html_strong(){return`<strong>${this.memory_header_text}</strong>`},memory_marker_prefix:"Here is some of my memories to help answer better",memory_header_plain_regex:/\s*Here is some of my memories to help answer better \(don't respond to these memories but use them to assist in the response\):[\s\S]*$/,memory_header_html_regex:/<p><strong>Here is some of my memories to help answer better \(don't respond to these memories but use them to assist in the response\):<\/strong><\/p>([\s\S]*?)(?=<p>|$)/},ae={claude:{editorSelector:'div[contenteditable="true"], textarea, p[data-placeholder], [contenteditable="true"]',deriveAnchor:e=>e.closest("form")||e.parentElement,placement:{strategy:"float",placement:"right-start",gap:8},fallbackAnchors:["#input-tools-menu-trigger",'button[aria-label*="Send" i]']},chatgpt:{editorSelector:'textarea, [contenteditable="true"], input[type="text"]',deriveAnchor:e=>{const t=e.closest("form");return t&&(t.querySelector('[data-testid="composer-trailing-actions"]')||t.querySelector(".composer-trailing-actions")||t.querySelector(".items-center.gap-1\\.5")||t.querySelector(".items-center.gap-2"))||null||t||e.parentElement},placement:{strategy:"inline",where:"beforeend",inlineAlign:"end"},adjacentTargets:['button[aria-label="Dictate button"]','button[aria-label*="mic" i]','button[aria-label*="voice" i]'],fallbackAnchors:['form [data-testid="composer-trailing-actions"]',"form .composer-trailing-actions","form textarea","main form textarea"],enableFloatingFallback:!0},grok:{editorSelector:'textarea, [contenteditable="true"], input[type="text"]',deriveAnchor:e=>{const t=e.closest("form")||e.parentElement||document.body,n=Array.from(t.querySelectorAll('button,[role="button"]')).find(a=>/\bAuto\b/i.test((a.textContent||"").trim()));return n&&n.parentElement||t},placement:{strategy:"inline",where:"beforeend",inlineAlign:"end"},autoButtonTextPattern:/\bAuto\b/i,fallbackAnchors:['button[aria-label*="Send" i]','button[data-testid*="send" i]','form button[type="submit"]',"textarea",'[role="textbox"]']},deepseek:{editorSelector:'textarea, [contenteditable="true"], input[type="text"]',deriveAnchor:e=>e.closest("form")||e.parentElement,placement:{strategy:"inline",where:"beforeend",inlineAlign:"end"}},gemini:{editorSelector:'textarea, [contenteditable="true"], input[type="text"]',deriveAnchor:e=>e.closest("form")||e.parentElement,placement:{strategy:"inline",where:"beforeend",inlineAlign:"end"}},perplexity:{editorSelector:'textarea, [contenteditable], input[type="text"]',deriveAnchor:e=>e.closest("form")||e.parentElement,placement:{strategy:"inline",where:"beforeend",inlineAlign:"end"},sendButtonSelector:'button[aria-label="Submit"]',modelButtonSelector:'button[aria-label="Choose a model"]'},replit:{editorSelector:'textarea, [contenteditable="true"], input[type="text"]',deriveAnchor:e=>e.closest("form")||e.parentElement||document.body,placement:{strategy:"float",placement:"right-center",gap:12}}},Q=e=>new Promise(t=>setTimeout(t,e));function U(e,t){const n=new MutationObserver(()=>{if(!document.contains(e)){try{n.disconnect()}catch{}t()}});return n.observe(document.documentElement,{childList:!0,subtree:!0}),n}function X(e,t=500){const n=globalThis,a=n.location,r=n.history;let i=a.href;const s=n.setInterval(()=>{a.href!==i&&(i=a.href,e())},t);n.addEventListener("popstate",e);const l=r.pushState.bind(r),m=r.replaceState.bind(r);return r.pushState=((...o)=>{const u=l(...o);return e(),u}),r.replaceState=((...o)=>{const u=m(...o);return e(),u}),()=>{n.clearInterval(s),n.removeEventListener("popstate",e),r.pushState=l,r.replaceState=m}}function A(e="mem0-root"){const t=document.createElement("div");t.className=e;const n=t.attachShadow({mode:"open"});return{host:t,shadow:n}}async function F(e=[],t=2e3,n=250){const a=Date.now()+t;for(;Date.now()<a;){for(let r=0;r<e.length;r++){const i=e[r];let s=null;if(typeof i=="string"?s=document.querySelector(i):i&&typeof i.find=="function"&&(s=i.find()),s)return s}await Q(n)}return null}function k(e){const{container:t,anchor:n,placement:a}=e;if(!n)return document.body.appendChild(t),()=>{};const r=a||{strategy:"inline"};switch(r.strategy){case"inline":{const i=r.where||"beforeend";return n.insertAdjacentElement(i,t),r.inlineAlign==="end"&&(t.style.marginLeft="auto"),r.inlineClass&&t.classList.add(r.inlineClass),()=>{}}case"dock":{const i=r.container?typeof r.container=="string"?n.closest(r.container)||n:r.container:n;getComputedStyle(i).position==="static"&&(i.style.position="relative");const s=r.side||"bottom",l=r.align||"start",m=r.gap??8,o=t.style;o.position="absolute",o.zIndex="2147483647";const u=()=>{i.getBoundingClientRect(),s==="top"&&(o.top=`${-t.offsetHeight-m}px`,o.bottom=""),s==="bottom"&&(o.top=`${i.offsetHeight+m}px`,o.bottom=""),s==="left"&&(o.left=`${-t.offsetWidth-m}px`,o.right="",o.top=""),s==="right"&&(o.left=`${i.offsetWidth+m}px`,o.right="",o.top="");const f={start:"0px",center:"50%",end:"100%"}[l];s==="top"||s==="bottom"?(o.left=f,o.transform=l==="center"?"translateX(-50%)":""):(o.top=f,o.transform=l==="center"?"translateY(-50%)":"")};i.appendChild(t),u();const d=new ResizeObserver(u);d.observe(i);const p=()=>u();return globalThis.addEventListener("scroll",p,!0),globalThis.addEventListener("resize",p),()=>{d.disconnect(),globalThis.removeEventListener("scroll",p,!0),globalThis.removeEventListener("resize",p)}}case"float":{const i=r.gap??8,s=()=>{const o=n.getBoundingClientRect(),u=t.style;u.position="fixed",u.zIndex="2147483647";const d=(r.placement||"right-start").split("-"),p=d[0],f=d[1]||"start",y=(b,S)=>{u.left=`${b}px`,u.top=`${S}px`},v={start:o.top,center:o.top+o.height/2,end:o.bottom},g={start:o.left,center:o.left+o.width/2,end:o.right};p==="right"&&y(o.right+i,v[f]??o.top),p==="left"&&y(o.left-t.offsetWidth-i,v[f]??o.top),p==="bottom"&&y(g[f]??o.left,o.bottom+i),p==="top"&&y(g[f]??o.left,o.top-t.offsetHeight-i)};document.body.appendChild(t),s();const l=()=>s();globalThis.addEventListener("scroll",l,!0),globalThis.addEventListener("resize",l);const m=new ResizeObserver(l);return m.observe(n),()=>{globalThis.removeEventListener("scroll",l,!0),globalThis.removeEventListener("resize",l),m.disconnect()}}default:return n.appendChild(t),()=>{}}}function P(e,t){const n=e?document.querySelector(e):null;if(!n||!n.isConnected||!document.contains(n))return{ok:!1,reason:"missing"};if(t&&!(n===t||n.contains(t)||t.contains(n)))return{ok:!1,reason:"mismatch"};const a=n.getBoundingClientRect();return a.width===0&&a.height===0?{ok:!1,reason:"invisible"}:{ok:!0,el:n}}function Z(e){if(!e)return"";if(e.id)return`#${e.id}`;const t=(e.tagName||"").toLowerCase(),n=e.className&&typeof e.className=="string"?"."+e.className.trim().split(/\s+/).slice(0,2).join("."):"",a=t+n,r=e.parentElement;return r&&r.id?`#${r.id} > ${a}`:a}function I(e){const t=globalThis.location;return"mem0_anchor_hint:"+(e.learnKey||`${t.host}:${t.pathname}`)}function M(){return Date.now()}function z(){try{return chrome?.runtime?.getManifest().version??"0"}catch{return"0"}}async function J(e){return new Promise(t=>{try{chrome?.storage?.session?.get(e,n=>t(n?.[e]??null))}catch{t(null)}})}async function K(e,t){return new Promise(n=>{try{const a={};a[e]=t,chrome?.storage?.session?.set(a,n)}catch{n()}})}async function V(e){return new Promise(t=>{try{chrome?.storage?.local?.get(e,n=>t(n?.[e]??null))}catch{t(null)}})}async function ee(e,t){return new Promise(n=>{try{const a={};a[e]=t,chrome?.storage?.local?.set(a,n)}catch{n()}})}async function te(e){return new Promise(t=>{try{chrome?.storage?.local?.remove(e,t)}catch{t()}})}async function $(e,t,n=1440*60*1e3){const a=I(e);let r=await J(a)||null;if(r?.sel){const i=P(r.sel,t);if(i.ok)return{el:i.el,placement:r.placement}}if(r=await V(a)||null,r?.sel&&r.ver===z()&&M()-r.ts<n){const i=P(r.sel,t);if(i.ok)return{el:i.el,placement:r.placement}}else r&&await te(a);return null}async function R(e,t,n,a){const r=I(e),i={sel:Z(t),placement:n??null,ts:M(),ver:z()};await K(r,i),a&&await ee(r,i)}function ne(e){let t=null,n=null,a=null,r=null;const i=async()=>{try{if(t){try{t()}catch{}t=null}if(a){try{a.disconnect()}catch{}a=null}r?.isConnected&&r.remove(),r=null;const s=await F(e.anchors||[],e.timeoutMs??2e3,e.pollMs??200),{host:l,shadow:m}=A("mem0-root");r=l;let o=()=>{};if(s)o=k({container:r,anchor:s,placement:e.placement});else if(e.enableFloatingFallback)Object.assign(r.style,{position:"fixed",right:"16px",bottom:"16px",zIndex:"2147483647"}),document.body.appendChild(r);else return;const u=typeof e.render=="function"?e.render(m,r,s):null;typeof u=="function"&&(t=u),a=U(s||r,()=>{try{o()}catch{}if(t)try{t()}catch{}i()}),n||(n=X(()=>i()))}catch{setTimeout(()=>i(),1500)}};return i(),()=>{t&&t(),n&&n(),a&&a.disconnect(),r?.isConnected&&r.remove()}}function re(e){let t=!1;const n=e.editorSelector||'textarea, [contenteditable="true"], input[type="text"]',a=e.deriveAnchor||(s=>s.closest("form")||s.parentElement||null),r=e.existingHostSelector||"#mem0-icon-button, .mem0-root",i=s=>{if(t)return;try{if(r&&document.querySelector(r))return}catch{}const l=s.target;!l||!(l.matches&&l.matches(n))||(t=!0,Promise.resolve().then(()=>$(e,l,e.cacheTtlMs)).then(async m=>{const o=m?.el??a(l),u=m?.placement??(e.placement||{strategy:"inline"});if(!o&&typeof e.fallback=="function")return t=!1,e.fallback();if(!o){t=!1;return}const{host:d,shadow:p}=A("mem0-root"),f=k({container:d,anchor:o,placement:u}),y=e.render&&typeof e.render=="function"?e.render(p,d,o):null;if(!m?.el)try{await R(e,o,u,e.persistCache)}catch{}const v=new MutationObserver(()=>{if(!document.contains(o)||!document.contains(d)){try{f()}catch{}if(y)try{y()}catch{}try{v.disconnect()}catch{}t=!1}});v.observe(document.documentElement,{childList:!0,subtree:!0})}).catch(()=>{t=!1}))};return globalThis.addEventListener("focusin",i,!0),globalThis.addEventListener("keydown",i,!0),globalThis.addEventListener("pointerdown",i,!0),function(){globalThis.removeEventListener("focusin",i,!0),globalThis.removeEventListener("keydown",i,!0),globalThis.removeEventListener("pointerdown",i,!0)}}const se={createShadowRootHost:A,findAnchor:F,applyPlacement:k,resolveCachedAnchor:$,saveAnchorHint:R,mountResilient:ne,mountOnEditorFocus:re};export{se as C,ae as S,ie as a,oe as c};
