import{u as N,l as U,j as f,A as q,m as K,r as m,i as W,c as $,P as O,s as R,a as F,b as z}from"./logo-BvVs1LL9.js";const S={"sentinax-badge":"_sentinax-badge_4l0hr_1","sentinax-badge--status-safe":"_sentinax-badge--status-safe_4l0hr_18","sentinax-badge__icon":"_sentinax-badge__icon_4l0hr_22","sentinax-badge--status-warning":"_sentinax-badge--status-warning_4l0hr_26","sentinax-badge__text":"_sentinax-badge__text_4l0hr_49"},B=({status:a})=>{const _=N(b=>b.settings.language),p=typeof chrome<"u"&&chrome.runtime?chrome.runtime.getURL("logo.png"):U,y=a==="safe"?S["sentinax-badge--status-safe"]:S["sentinax-badge--status-warning"],g=_==="ru"?a==="safe"?"Sentinax Активен":"Обработка...":a==="safe"?"Sentinax Active":"Processing...";return f.jsx(q,{mode:"wait",children:f.jsxs(K.div,{initial:{opacity:0,scale:.9,y:5},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:-5},transition:{duration:.4,ease:[.175,.885,.32,1.275]},className:`${S["sentinax-badge"]} ${y}`,children:[f.jsx("span",{className:S["sentinax-badge__icon"],children:f.jsx("img",{src:p,alt:"S",style:{width:"14px",height:"14px",display:"block",objectFit:"contain"}})}),f.jsx("span",{className:S["sentinax-badge__text"],children:g})]},a)})},V=a=>{const[_,p]=m.useState(null);return m.useEffect(()=>{const y=Array.isArray(a)?a:[a],x=()=>{for(const u of y){const d=document.querySelector(u);if(d)return d}return null},h=()=>{const u=x();p(d=>u&&u!==d?(console.log("Sentinax: DOM Watcher found NEW element:",u),u):d&&!d.isConnected?(console.log("Sentinax: DOM Watcher detected DETACHMENT. Resetting."),u):d||u)};h();const g=setInterval(h,1e3),b=new MutationObserver(()=>{h()});return b.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class","hidden"]}),()=>{clearInterval(g),b.disconnect()}},[JSON.stringify(a)]),_},J=()=>{const a=V(["#prompt-textarea",'[contenteditable="true"]']),[_,p]=m.useState("safe"),[y]=F(),x=m.useRef(!1),h=m.useRef(null);m.useEffect(()=>{const e=document.createElement("div");return e.id="sentinax-badge-wrapper",e.style.cssText=`
      position: fixed;
      bottom: 20px;
      right: 80px;
      z-index: 10000;
      pointer-events: auto;
      width: 180px !important;
      height: 36px !important;
      display: flex !important;
      align-items: center !important;
      justify-content: flex-end !important;
      overflow: hidden !important;
      background: transparent !important;
    `,document.body.appendChild(e),h.current=e,()=>{e.remove(),h.current=null}},[]);const g=e=>{let n="";if(e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement)n=e.value;else{const t=e.cloneNode(!0);t.querySelectorAll('[data-testid*="file"], .file-chip, [class*="file"]').forEach(o=>o.remove()),n=t.innerText||t.textContent||""}return n.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,"").trim()};m.useEffect(()=>{const e=async t=>{const o=t.target;(o.closest('[data-testid="send-button"]')||o.closest('button[aria-label="Send message"]'))&&a&&!x.current&&g(a).trim()!==""&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),await I(a))};document.addEventListener("click",e,{capture:!0});const n=async t=>{t.key==="Enter"&&!t.shiftKey&&a&&!x.current&&g(a).trim()!==""&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),await I(a))};return a&&a.addEventListener("keydown",n,{capture:!0}),()=>{document.removeEventListener("click",e,{capture:!0}),a&&a.removeEventListener("keydown",n,{capture:!0})}},[a,y]);const[b,u]=m.useState("session-"+Math.random().toString(36).substring(2,10)),d=m.useRef(window.location.pathname);m.useEffect(()=>{const n=setInterval(()=>{const t=window.location.pathname;d.current.includes("/c/")&&(t==="/"||t==="")&&u("session-"+Math.random().toString(36).substring(2,10)),d.current=t},1500);return()=>clearInterval(n)},[]);const I=async e=>{try{x.current=!0,p("warning");const n=g(e);if(!n||n.trim()===""){x.current=!1,p("safe");return}const t=window.location.pathname.match(/\/c\/([a-zA-Z0-9-]+)/),o=t?t[1]:b,l=Array.from(document.querySelectorAll('[data-message-author-role="assistant"]')),E=l[l.length-1],C=E?.innerText||E?.textContent||void 0,v=`sentinax_history_${o}`,r=`sentinax_history_${b}`,w=await chrome.storage.local.get([v,r]);let c=w[v]||[];t&&b!==o&&w[r]&&w[r].length>0&&(c=[...w[r],...c],await chrome.storage.local.set({[v]:c,[`sentinax_meta_${o}`]:{lastUpdated:Date.now()}}),await chrome.storage.local.remove(r));const s=await y({text:n,chatId:o,lastResponse:C,history:c}).unwrap();s.assistantSummary&&c.push({role:"Assistant",content:s.assistantSummary}),s.userSummary&&c.push({role:"User",content:s.userSummary,originalMessage:n}),await chrome.storage.local.set({[v]:c,[`sentinax_meta_${o}`]:{lastUpdated:Date.now()}});let i=s.cleanedText||n;const T=s.roadmapText,M=R.getState().settings.injectionMode;if(M==="file"&&T){await L(T,n),p("safe");return}else M==="text"&&T&&(i=`${i}

\`\`\`txt:roadmap.txt
${T}
\`\`\``);await P(e,i),await D(e);for(let k=0;k<3;k++)await new Promise(H=>setTimeout(H,200*(k+1))),await j(e);p("safe")}catch{p("safe")}finally{setTimeout(()=>{x.current=!1},500)}},L=async(e,n)=>{try{let t="ChatContext.txt";try{const r=n.toLowerCase().replace(/[^\w\sа-яА-Я]/g," ").trim();if(!r)t="ChatContext.txt";else{const c=r.split(/\s+/).filter(s=>s.length>=3).filter(s=>!["the","and","for","are","but","not","you","all","can","her","was","one","our","out","day","get","has","him","his","how","its","may","new","now","old","see","two","who","boy","did","car","let","put","say","she","too","use","what","when","where","which","will","with","have","this","that","from","they","been","were","would","could","should","about","after","before","there","their","these","those"].includes(s)).slice(0,4);if(c.length>0)t=c.map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join("_")+".txt";else{const s=r.split(/\s+/).filter(i=>i.length>0).slice(0,3).map(i=>i.charAt(0).toUpperCase()+i.slice(1));t=s.length>0?s.join("_")+".txt":"ChatContext.txt"}}t=t.replace(/[<>:"/\\|?*]/g,"_"),t.length>50&&(t=t.substring(0,47)+".txt"),(t==="_.txt"||t===".txt")&&(t="ChatContext.txt")}catch{t="ChatContext.txt"}const o=new File([e],t,{type:"text/plain"}),l=a;if(!l)return;const E=new DataTransfer;E.items.add(o),l.focus(),await new Promise(r=>setTimeout(r,200));const C=new ClipboardEvent("paste",{bubbles:!0,cancelable:!0,clipboardData:E});l.dispatchEvent(C),await new Promise(r=>setTimeout(r,2e3));const v=document.querySelector('[class*="file"]')||document.querySelector('[data-testid*="file"]');await new Promise(r=>setTimeout(r,500));for(let r=1;r<=10;r++){const w=["#composer-submit-button",'[data-testid="send-button"]','button[aria-label="Send prompt"]',".composer-submit-btn",'button[data-testid="fruitjuice-send-button"]','button[aria-label="Send message"]','button[aria-label="Send"]','form button[type="submit"]'];let c=null;for(const s of w){const i=document.querySelector(s);if(i&&!i.disabled){c=i;break}}if(c){if(c.click(),a)for(let s=0;s<3;s++)await new Promise(i=>setTimeout(i,500*(s+1))),await j(a);break}if(!c&&l&&r>7){const s={key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:!0,cancelable:!0,composed:!0};l.dispatchEvent(new KeyboardEvent("keydown",s)),l.dispatchEvent(new KeyboardEvent("keypress",s)),l.dispatchEvent(new KeyboardEvent("keyup",s)),a&&(await new Promise(i=>setTimeout(i,200)),await P(a,""))}await new Promise(s=>setTimeout(s,500))}}catch{}},P=async(e,n)=>{if(e.focus(),e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement){const t=Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value")?.set;t?t.call(e,n):e.value=n}else{const t=window.getSelection();if(t){const o=document.createRange();o.selectNodeContents(e),t.removeAllRanges(),t.addRange(o)}document.execCommand("insertText",!1,n)}e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),await new Promise(t=>setTimeout(t,50))},j=async e=>{if(!e)return;e.focus(),document.execCommand("selectAll",!1),document.execCommand("insertText",!1,""),e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement?e.value="":(e.innerText="",e.innerHTML="");const n={bubbles:!0,cancelable:!0,composed:!0};e.dispatchEvent(new Event("input",n)),e.dispatchEvent(new Event("change",n)),e.dispatchEvent(new Event("blur",n))},D=async e=>{const n=()=>document.querySelector('[data-testid="send-button"]')||document.querySelector('button[aria-label="Send message"]');let t=n();for(let o=0;o<15&&!(t&&!t.disabled);o++)await new Promise(l=>setTimeout(l,100)),t=n();return t&&!t.disabled?(t.click(),!0):(e.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter",code:"Enter",keyCode:13,bubbles:!0})),!0)};return f.jsx(f.Fragment,{children:h.current&&z.createPortal(f.jsx(B,{status:_}),h.current)})},A=document.createElement("div");A.id="sentinax-root-container";document.body.appendChild(A);W().then(()=>{$.createRoot(A).render(f.jsx(O,{store:R,children:f.jsx(J,{})}))});
