yepanywhere 0.4.27 → 0.4.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yep-anywhere/shared",
3
- "version": "0.4.27",
3
+ "version": "0.4.28",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts"
@@ -171,4 +171,4 @@ ${s.map(({path:f,message:m})=>`- \`${f}\`: ${m}`).join(`
171
171
  ${f}`})})})},renderToolResult(e,t,s,i){const l=$f(e),c=Bf(l),d=uh(i),f=Ic(i);return c.output.trim()?d==="Read"&&f?r.jsx(Tb,{filePath:f,output:c.output}):r.jsx("div",{className:`bash-result ${t?"bash-result-error":""}`,children:r.jsx("pre",{className:`code-block ${t?"code-block-error":""}`,children:r.jsx("code",{children:c.output})})}):c.exitCode!==void 0?r.jsx("div",{className:"bash-empty",children:`Command exited with code ${c.exitCode}`}):r.jsx("div",{className:"bash-empty",children:"No output"})},getUseSummary(e){const t=_b(e),s=Cb(e),i=kb(e);return s===void 0||s.length===0?i||"waiting for output":i?`${i} (input)`:`sent input (${t})`},getResultSummary(e,t){if(t)return"Error";const s=$f(e),i=Bf(s);return i.exitCode!==void 0&&i.wallTime?`exit ${i.exitCode} in ${i.wallTime}`:i.exitCode!==void 0?`exit ${i.exitCode}`:i.output.trim()?`${i.output.split(`
172
172
  `).filter(Boolean).length} lines`:"No output"},renderInteractiveSummary(e,t,s,i){if(s)return null;const l=uh(e),c=Ic(e);if(l!=="Read"||!c)return null;const d=$f(t),f=Bf(d);return f.output.trim()?r.jsx(Tb,{filePath:c,output:f.output,inline:!0}):null}},Ab={shell_command:"Bash",exec_command:"Bash",write_stdin:"WriteStdin",update_plan:"UpdatePlan",apply_patch:"Edit",web_search_call:"WebSearch",search_query:"WebSearch",Agent:"Task",view_image:"ViewImage",imageView:"ViewImage"};function hY(e){return Ab[e]??Ab[e.toLowerCase()]??e}class mY{constructor(t){ze(this,"tools",new Map);ze(this,"fallback");this.fallback=t}register(t){this.tools.set(t.tool,t)}get(t){const s=hY(t);return this.tools.get(s)||this.fallback}renderToolUse(t,s,i){return this.get(t).renderToolUse(s,i)}renderToolResult(t,s,i,l,c){return this.get(t).renderToolResult(s,i,l,c)}hasInteractiveSummary(t){return typeof this.get(t).renderInteractiveSummary=="function"}hasCollapsedPreview(t){return typeof this.get(t).renderCollapsedPreview=="function"}renderCollapsedPreview(t,s,i,l,c){const d=this.get(t);return d.renderCollapsedPreview?d.renderCollapsedPreview(s,i,l,c):null}renderInteractiveSummary(t,s,i,l,c){const d=this.get(t);return d.renderInteractiveSummary?d.renderInteractiveSummary(s,i,l,c):null}hasInlineRenderer(t){return typeof this.get(t).renderInline=="function"}renderInline(t,s,i,l,c,d){const f=this.get(t);return f.renderInline?f.renderInline(s,i,l,c,d):null}getDisplayName(t){return this.get(t).displayName||t}}const pY={tool:"__fallback__",renderToolUse(e,t){return r.jsx("pre",{className:"tool-fallback",children:r.jsx("code",{children:JSON.stringify(e,null,2)})})},renderToolResult(e,t,s){return r.jsx("pre",{className:`tool-fallback ${t?"tool-fallback-error":""}`,children:r.jsx("code",{children:JSON.stringify(e,null,2)})})}},un=new mY(pY);un.register(kV);un.register(fW);un.register(HV);un.register(iY);un.register(GV);un.register(tW);un.register(IW);un.register(DW);un.register(JW);un.register(KW);un.register(uV);un.register(VV);un.register(HW);un.register(fY);un.register(WW);un.register(pV);un.register(pW);un.register(oW);function Ff(e){try{return e()}catch{return}}function pS(e,t,s,i){const l=un.get(e);if(i==="pending"||i==="aborted"){if(l.getUseSummary){const f=Ff(()=>{var m;return(m=l.getUseSummary)==null?void 0:m.call(l,t)});if(f!==void 0)return f}return Hf(e,t)}let c;l.getUseSummary?c=Ff(()=>{var m;return(m=l.getUseSummary)==null?void 0:m.call(l,t)})??Hf(e,t):c=Hf(e,t);let d;return l.getResultSummary?d=Ff(()=>{var m;return(m=l.getResultSummary)==null?void 0:m.call(l,(s==null?void 0:s.structured)??(s==null?void 0:s.content),(s==null?void 0:s.isError)??!1,t)})??Rb(e,s,i):d=Rb(e,s,i),e==="Glob"||e==="Grep"?`${c} → ${d}`:e==="Bash"?c:e==="WriteStdin"&&c&&c!=="waiting for output"?`${c} → ${d}`:d}function Hf(e,t){if(!t||typeof t!="object")return"...";const s=t;switch(e){case"Read":case"Write":case"Edit":if(typeof s.file_path=="string")return xY(s.file_path);break;case"Bash":{const i=Gh(s);if(i)return i}break;case"Glob":if(typeof s.pattern=="string")return s.pattern;break;case"Grep":if(typeof s.pattern=="string")return`"${s.pattern}"`;break;case"Task":case"Agent":if(typeof s.description=="string")return zc(s.description,30);break;case"WebSearch":if(typeof s.query=="string")return zc(s.query,30);break;case"WebFetch":if(typeof s.url=="string")return zc(s.url,40);break}return gY(s)}function gY(e){for(const t of Object.values(e))if(typeof t=="string"&&t.length>0&&t.length<100)return zc(t,40);return"..."}function Rb(e,t,s){if(s==="error")return"failed";if(!t)return"done";const l=(typeof t.content=="string"?t.content:"").split(`
173
173
  `).filter(Boolean).length;switch(e){case"Read":return`${l} lines`;case"Bash":return`${l} lines`;case"Glob":return`${l} files`;case"Grep":return`${l} matches`;default:return"done"}}function zc(e,t){return e.length<=t?e:`${e.slice(0,t-3)}...`}function xY(e){return e.split("/").pop()||e}const vY=h.memo(function({id:t,toolName:s,toolInput:i,toolResult:l,status:c,sessionProvider:d}){const f=h.useMemo(()=>({isStreaming:c==="pending",theme:"dark",toolUseId:t,provider:d}),[c,t,d]),m=(l==null?void 0:l.structured)??(l==null?void 0:l.content),g=un.hasInlineRenderer(s),v=bY(s,i,d,c),b=h.useMemo(()=>c!=="complete"?null:un.renderInteractiveSummary(s,i,m,(l==null?void 0:l.isError)??!1,f),[c,s,i,m,l,f]),w=b!=null&&b!==!1,_=h.useMemo(()=>v?null:un.renderCollapsedPreview(s,i,m,(l==null?void 0:l.isError)??!1,f),[v,s,i,m,l,f]),C=_!=null&&_!==!1,S=s==="Bash"&&c==="pending"&&C&&Q0(i,d),N=w||C,[T,k]=h.useState(!N&&(s==="Edit"||s==="TodoWrite")),A=h.useMemo(()=>pS(s,i,l,c),[s,i,l,c]),P=()=>{N||k(!T)};return g?r.jsx("div",{className:"tool-inline timeline-item",children:un.renderInline(s,i,m,(l==null?void 0:l.isError)??!1,c,f)}):r.jsxs("div",{className:`tool-row timeline-item ${T?"expanded":"collapsed"} status-${c} ${N?"interactive":""}`,children:[r.jsxs("div",{className:`tool-row-header ${N?"non-expandable":""}`,onClick:N?void 0:P,onKeyDown:N?void 0:U=>U.key==="Enter"&&P(),role:N?"presentation":"button",tabIndex:N?void 0:0,children:[c==="pending"&&r.jsx("span",{className:"tool-spinner","aria-label":"Running",children:r.jsx(wY,{})}),c==="aborted"&&r.jsx("span",{className:"tool-aborted-icon","aria-label":"Interrupted",children:"⨯"}),r.jsx("span",{className:"tool-name",children:un.getDisplayName(s)}),w&&c==="complete"?r.jsx("span",{className:"tool-summary interactive-summary",children:b}):S?null:r.jsxs("span",{className:"tool-summary",children:[A,c==="aborted"&&r.jsx("span",{className:"tool-aborted-label",children:" (interrupted)"})]}),!N&&r.jsx("span",{className:"expand-chevron","aria-hidden":"true",children:T?"▾":"▸"})]}),C&&r.jsx("div",{className:"tool-row-collapsed-preview",children:_}),T&&!N&&r.jsx("div",{className:"tool-row-content",children:c==="pending"||c==="aborted"?r.jsx(yY,{toolName:s,toolInput:i,context:f}):r.jsx(SY,{toolName:s,toolInput:i,toolResult:l,context:f})})]})});function bY(e,t,s,i){if(e!=="Bash"||!Q0(t,s))return!1;if(i==="pending"||i==="complete"||i==="error"||i==="aborted")return!0;const l=Gh(t);return l?/^(rg|grep|sed|nl|cat)\b/.test(l.trimStart()):!1}function yY({toolName:e,toolInput:t,context:s}){return r.jsx("div",{className:"tool-use-expanded",children:un.renderToolUse(e,t,s)})}function SY({toolName:e,toolInput:t,toolResult:s,context:i}){if(!s)return r.jsx("div",{className:"tool-no-result",children:"No result data"});const l=s.structured??s.content;return r.jsx("div",{className:"tool-result-expanded",children:un.renderToolResult(e,l,s.isError,i,t)})}function wY(){return r.jsx("svg",{className:"spinner",viewBox:"0 0 16 16",width:"12",height:"12","aria-hidden":"true",children:r.jsx("circle",{cx:"8",cy:"8",r:"6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"24",strokeDashoffset:"8"})})}function jY(e){return typeof e.uuid=="string"&&e.uuid.length>0?e.uuid:typeof e.id=="string"&&e.id.length>0?e.id:"<missing>"}function EY(e){const t={sdk:0,jsonl:0,unknown:0},s={},i=[];let l=0,c=0;for(const d of e){const f=d._source==="sdk"||d._source==="jsonl"?d._source:"unknown";t[f]=(t[f]??0)+1;const m=typeof d.type=="string"?d.type:"unknown";s[m]=(s[m]??0)+1,m==="stream_event"&&l++,d._isStreaming&&c++,i.push(jY(d))}return{total:e.length,bySource:t,byType:s,streamEventCount:l,streamingPlaceholderCount:c,ids:i}}function NY(e,t){var i;const s=EY(e.sourceMessages);return{render:{id:e.id,type:e.type,isSubagent:e.isSubagent??!1},uiContext:{sessionProvider:t.sessionProvider??"unknown",sessionIsStreaming:t.isStreaming,thinkingExpanded:t.thinkingExpanded},itemContext:e.type==="tool_call"?{toolName:e.toolName,status:e.status,hasToolResult:!!e.toolResult,hasStructuredResult:((i=e.toolResult)==null?void 0:i.structured)!==void 0,toolUseId:e.id}:e.type==="text"?{isStreamingTextBlock:e.isStreaming??!1,hasAugmentHtml:!!e.augmentHtml}:e.type==="thinking"?{status:e.status,thinkingLength:e.thinking.length}:e.type==="system"?{subtype:e.subtype,status:e.status??null}:e.type==="session_setup"?{promptCount:e.prompts.length}:null,sourceSummary:s,sourceMessages:e.sourceMessages,renderItem:e}}const dh=h.memo(function({item:t,isStreaming:s,thinkingExpanded:i,toggleThinkingExpanded:l,sessionProvider:c}){const d=h.useCallback(m=>{const g=window.getSelection();g&&g.toString().length>0||m.shiftKey&&!m.ctrlKey&&!m.metaKey&&(m.preventDefault(),m.stopPropagation(),console.log("[DEBUG] Render snapshot",NY(t,{isStreaming:s,thinkingExpanded:i,sessionProvider:c})))},[t,s,i,c]),f=()=>{switch(t.type){case"text":return r.jsx(Xq,{text:t.text,isStreaming:t.isStreaming,augmentHtml:t.augmentHtml});case"thinking":return r.jsx(eV,{thinking:t.thinking,status:t.status,isExpanded:i,onToggle:l});case"tool_call":return r.jsx(vY,{id:t.id,toolName:t.toolName,toolInput:t.toolInput,toolResult:t.toolResult,status:t.status,sessionProvider:c});case"user_prompt":return r.jsx(V0,{content:t.content});case"session_setup":return r.jsx(Hq,{title:t.title,prompts:t.prompts});case"system":{const m=t.subtype==="status"&&t.status==="compacting",g=t.subtype==="error",v=g?"!":"⟳";return r.jsxs("div",{className:`system-message ${m?"system-message-compacting":""} ${g?"system-message-error":""}`,children:[r.jsx("span",{className:`system-message-icon ${m?"spinning":""}`,children:v}),r.jsx("span",{className:"system-message-text",children:t.content})]})}default:return null}};return r.jsx("div",{className:t.isSubagent?"subagent-item":void 0,"data-render-type":t.type,"data-render-id":t.id,onClick:d,children:f()})});function _Y(e){const t=[];let s=[];for(const i of e)i.type==="user_prompt"||i.type==="session_setup"?(s.length>0&&(t.push({isUserPrompt:!1,items:s}),s=[]),t.push({isUserPrompt:!0,items:[i]})):s.push(i);return s.length>0&&t.push({isUserPrompt:!1,items:s}),t}const CY=h.memo(function({messages:t,provider:s,isStreaming:i=!1,isProcessing:l=!1,isCompacting:c=!1,scrollTrigger:d=0,pendingMessages:f=[],deferredMessages:m=[],onCancelDeferred:g,markdownAugments:v,activeToolApproval:b,hasOlderMessages:w=!1,loadingOlder:_=!1,onLoadOlderMessages:C}){const S=h.useRef(null),N=h.useRef(!0),T=h.useRef(!0),k=h.useRef(!1),A=h.useRef(0),P=h.useRef(null),[U,O]=h.useState(!1),z=h.useCallback(Z=>{k.current=!0,Z.scrollTop=Z.scrollHeight-Z.clientHeight,A.current=Z.scrollHeight,requestAnimationFrame(()=>{k.current=!1}),P.current!==null&&clearTimeout(P.current),P.current=setTimeout(()=>{P.current=null,N.current&&(k.current=!0,Z.scrollTop=Z.scrollHeight-Z.clientHeight,A.current=Z.scrollHeight,requestAnimationFrame(()=>{k.current=!1}))},50)},[]),q=h.useMemo(()=>Zh(t,{markdown:v,activeToolApproval:b}),[t,v,b]),oe=h.useMemo(()=>_Y(q),[q]),K=h.useCallback(()=>{O(Z=>!Z)},[]),I=h.useCallback(()=>{var W;if(!C)return;const Z=(W=S.current)==null?void 0:W.parentElement;if(!Z){C();return}const Q=Z.scrollHeight,ae=Z.scrollTop;C(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{const V=Z.scrollHeight-Q;k.current=!0,Z.scrollTop=ae+V,A.current=Z.scrollHeight,requestAnimationFrame(()=>{k.current=!1})})})},[C]),B=h.useCallback(()=>{var W;if(k.current)return;const Z=(W=S.current)==null?void 0:W.parentElement;if(!Z)return;const Q=100,ae=Z.scrollHeight-Z.scrollTop-Z.clientHeight;N.current=ae<Q},[]);return h.useEffect(()=>{var Q;const Z=(Q=S.current)==null?void 0:Q.parentElement;if(Z)return Z.addEventListener("scroll",B),()=>{Z.removeEventListener("scroll",B)}},[B]),h.useEffect(()=>{var W;const Z=(W=S.current)==null?void 0:W.parentElement;if(!Z)return;const Q=Z;A.current=Q.scrollHeight;const ae=new ResizeObserver(()=>{const Y=Q.scrollHeight;Y>A.current&&N.current?z(Q):A.current=Y});return S.current&&ae.observe(S.current),()=>{ae.disconnect(),P.current!==null&&clearTimeout(P.current)}},[z]),h.useEffect(()=>{var Z;if(d>0){N.current=!0;const Q=(Z=S.current)==null?void 0:Z.parentElement;Q&&z(Q)}},[d,z]),h.useEffect(()=>{var Z;if(T.current&&q.length>0){const Q=(Z=S.current)==null?void 0:Z.parentElement;Q&&z(Q),T.current=!1}},[q.length,z]),r.jsxs("div",{className:"message-list",ref:S,children:[w&&r.jsx("div",{className:"load-older-messages",children:r.jsx("button",{type:"button",className:"load-older-button",onClick:I,disabled:_,children:_?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"spinning",children:"↻"})," Loading..."]}):"Load older messages"})}),oe.map(Z=>{if(Z.isUserPrompt){const ae=Z.items[0];return ae?r.jsx(dh,{item:ae,isStreaming:i,thinkingExpanded:U,toggleThinkingExpanded:K,sessionProvider:s},ae.id):null}const Q=Z.items[0];return Q?r.jsx("div",{className:"assistant-turn",children:Z.items.map(ae=>r.jsx(dh,{item:ae,isStreaming:i,thinkingExpanded:U,toggleThinkingExpanded:K,sessionProvider:s},ae.id))},`turn-${Q.id}`):null}),f.map(Z=>r.jsxs("div",{className:"pending-message",children:[r.jsx("div",{className:"message-user-prompt pending-message-bubble",children:Z.content}),r.jsx("div",{className:"pending-message-status",children:Z.status||"Sending..."})]},Z.tempId)),m.map((Z,Q)=>r.jsxs("div",{className:"deferred-message",children:[r.jsx("div",{className:"message-user-prompt deferred-message-bubble",children:Z.content}),r.jsxs("div",{className:"deferred-message-footer",children:[r.jsx("span",{className:"deferred-message-status",children:Q===0?"Queued (next)":`Queued (#${Q+1})`}),Z.tempId&&g&&r.jsx("button",{type:"button",className:"deferred-message-cancel",onClick:()=>g(Z.tempId),"aria-label":"Cancel queued message",children:"×"})]})]},Z.tempId??`deferred-${Q}`)),c&&r.jsxs("div",{className:"system-message system-message-compacting",children:[r.jsx("span",{className:"system-message-icon spinning",children:"⟳"}),r.jsx("span",{className:"system-message-text",children:"Compacting context..."})]}),r.jsx(kq,{isProcessing:l})]})});function kY({processId:e,currentModel:t,onModelChanged:s,onClose:i}){const{t:l}=xt(),[c,d]=h.useState([]),[f,m]=h.useState(!0),[g,v]=h.useState(null),[b,w]=h.useState(!1);h.useEffect(()=>{Re.getProcessModels(e).then(C=>d(C.models)).catch(C=>v(C.message||l("modelSwitchLoadFailed"))).finally(()=>m(!1))},[e,l]);const _=async C=>{if(!b){w(!0),v(null);try{await Re.setProcessModel(e,C),s(C),i()}catch(S){v(S instanceof Error?S.message:l("modelSwitchChangeFailed")),w(!1)}}};return r.jsx(Yn,{title:l("modelSwitchTitle"),onClose:i,children:r.jsxs("div",{className:"model-switch-content",children:[f&&r.jsx("div",{className:"model-switch-loading",children:l("modelSwitchLoading")}),g&&r.jsx("div",{className:"model-switch-error",children:g}),!f&&!g&&c.length===0&&r.jsx("div",{className:"model-switch-loading",children:l("modelSwitchEmpty")}),!f&&c.length>0&&r.jsx("div",{className:"model-switch-list",children:c.map(C=>{const S=t?t.includes(C.id)||C.id.includes(t):!1;return r.jsxs("button",{type:"button",className:`model-switch-item ${S?"current":""}`,onClick:()=>_(C.id),disabled:b,children:[r.jsx("span",{className:"model-switch-name",children:C.name}),C.description&&r.jsx("span",{className:"model-switch-description",children:C.description}),S&&r.jsx("span",{className:"model-switch-badge",children:l("modelSwitchCurrent")})]},C.id)})})]})})}function TY(e,t,s){if(!e||e.type==="disabled")return s?s("processInfoThinkingDisabled"):"Disabled";const i=e.type==="adaptive"?s?s("processInfoThinkingAdaptive"):"Adaptive":s?s("processInfoThinkingEnabled"):"Enabled";return t?`${i} (${t})`:i}function AY(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/1e3),c=Math.floor(l/60),d=Math.floor(c/60),f=Math.floor(d/24);return f>0?`${f}d ${d%24}h`:d>0?`${d}h ${c%60}m`:c>0?`${c}m ${l%60}s`:`${l}s`}function Cc(e){return new Date(e).toLocaleString()}function RY(e,t){if(!e)return t("processInfoNever");const s=Math.floor((Date.now()-e)/1e3);if(s<5)return t("processInfoJustNow");if(s<60)return t("processInfoSecondsAgo",{seconds:s});const i=Math.floor(s/60);if(i<60)return t("processInfoMinutesAgo",{minutes:i});const l=Math.floor(i/60);return t("processInfoHoursAgo",{hours:l,minutes:i%60})}function MY(e,t){if(!e)return null;const s=[];return e.networkAccess!==void 0&&s.push(e.networkAccess?t("processInfoNetworkOn"):t("processInfoNetworkOff")),e.excludeTmpdirEnvVar!==void 0&&s.push(e.excludeTmpdirEnvVar?t("processInfoTmpdirExcluded"):t("processInfoTmpdirIncluded")),e.excludeSlashTmp!==void 0&&s.push(e.excludeSlashTmp?t("processInfoTmpExcluded"):t("processInfoTmpIncluded")),s.length===0?e.type:`${e.type} (${s.join(", ")})`}function cn({label:e,value:t,mono:s=!1}){return t==null?null:r.jsxs("div",{className:"process-info-row",children:[r.jsx("span",{className:"process-info-label",children:e}),r.jsx("span",{className:`process-info-value ${s?"mono":""}`,children:t})]})}function za({title:e,children:t}){return r.jsxs("div",{className:"process-info-section",children:[r.jsx("h3",{className:"process-info-section-title",children:e}),t]})}function DY({sessionId:e,provider:t,model:s,status:i,processState:l,contextUsage:c,originator:d,cliVersion:f,sessionSource:m,approvalPolicy:g,sandboxPolicy:v,createdAt:b,sessionStreamConnected:w,lastSessionEventAt:_,onClose:C}){const{t:S}=xt(),N=(I,B)=>S(I,B),[T,k]=h.useState(null),[A,P]=h.useState(!1),[U,O]=h.useState(null),{connected:z,connectionState:q}=Ah();h.useEffect(()=>{i.owner==="self"&&(P(!0),O(null),Re.getProcessInfo(e).then(I=>{k(I.process)}).catch(I=>{O(I.message||S("processInfoError"))}).finally(()=>{P(!1)}))},[e,i.owner,S]);const oe=I=>I.split("-").map(B=>B.charAt(0).toUpperCase()+B.slice(1)).join(" "),K=I=>{switch(I){case"claude":return"Claude (Anthropic)";case"codex":return"Codex (OpenAI)";case"codex-oss":return"Codex OSS (Local)";case"gemini":return"Gemini (Google)";case"opencode":return"OpenCode";default:return I}};return r.jsx(Yn,{title:S("processInfoTitle"),onClose:C,children:r.jsxs("div",{className:"process-info-content",children:[r.jsxs(za,{title:S("processInfoSectionSession"),children:[r.jsx(cn,{label:S("processInfoLabelSessionId"),value:e,mono:!0}),b&&r.jsx(cn,{label:S("processInfoLabelCreated"),value:Cc(b)}),r.jsx(cn,{label:S("processInfoLabelProvider"),value:K(t)}),r.jsx(cn,{label:S("processInfoLabelModel"),value:s||S("processInfoDefaultModel"),mono:!0}),r.jsx(cn,{label:S("processInfoLabelOwnership"),value:oe(i.owner)}),r.jsx(cn,{label:S("processInfoLabelActivity"),value:oe(l)}),r.jsx(cn,{label:S("processInfoLabelOriginator"),value:d}),r.jsx(cn,{label:S("processInfoLabelCliVersion"),value:f,mono:!0}),r.jsx(cn,{label:S("processInfoLabelSessionSource"),value:m}),r.jsx(cn,{label:S("processInfoLabelApprovalPolicy"),value:g,mono:!0}),r.jsx(cn,{label:S("processInfoLabelSandboxPolicy"),value:MY(v,N),mono:!0})]}),r.jsxs(za,{title:S("processInfoSectionConnection"),children:[r.jsx(cn,{label:S("processInfoLabelActivityStream"),value:S(z?"processInfoConnected":"processInfoDisconnected")}),r.jsx(cn,{label:S("processInfoLabelConnectionState"),value:q}),r.jsx(cn,{label:i.owner==="external"?S("processInfoLabelSessionWatch"):S("processInfoLabelSessionStream"),value:i.owner==="none"?S("processInfoNotSubscribed"):S(w?"processInfoConnected":"processInfoDisconnected")}),i.owner==="self"&&_&&r.jsx(cn,{label:S("processInfoLabelLastSessionEvent"),value:RY(new Date(_).getTime(),N)}),i.owner==="external"&&r.jsx(cn,{label:S("processInfoLabelSubscriptionMode"),value:S("processInfoFocusedWatch")})]}),c&&r.jsxs(za,{title:S("processInfoSectionTokenUsage"),children:[r.jsx(cn,{label:S("processInfoLabelInputTokens"),value:c.inputTokens.toLocaleString()}),c.outputTokens!==void 0&&r.jsx(cn,{label:S("processInfoLabelOutputTokens"),value:c.outputTokens.toLocaleString()}),r.jsx(cn,{label:S("processInfoLabelContextUsed"),value:`${c.percentage.toFixed(1)}%`}),c.cacheReadTokens!==void 0&&r.jsx(cn,{label:S("processInfoLabelCacheRead"),value:c.cacheReadTokens.toLocaleString()}),c.cacheCreationTokens!==void 0&&r.jsx(cn,{label:S("processInfoLabelCacheCreated"),value:c.cacheCreationTokens.toLocaleString()})]}),r.jsx(za,{title:S("processInfoSectionProcess"),children:i.owner==="self"?r.jsxs(r.Fragment,{children:[A&&r.jsx("div",{className:"process-info-loading",children:S("newSessionLoading")}),U&&r.jsx("div",{className:"process-info-error",children:U}),T&&r.jsxs(r.Fragment,{children:[r.jsx(cn,{label:S("processInfoLabelProcessId"),value:T.id,mono:!0}),r.jsx(cn,{label:S("processInfoLabelStarted"),value:Cc(T.startedAt)}),r.jsx(cn,{label:S("processInfoLabelUptime"),value:AY(T.startedAt)}),r.jsx(cn,{label:S("processInfoLabelQueueDepth"),value:T.queueDepth}),r.jsx(cn,{label:S("processInfoLabelExtendedThinking"),value:TY(T.thinking,T.effort,N)}),T.idleSince&&r.jsx(cn,{label:S("processInfoLabelIdleSince"),value:Cc(T.idleSince)}),T.holdSince&&r.jsx(cn,{label:S("processInfoLabelHoldSince"),value:Cc(T.holdSince)})]}),!A&&!T&&!U&&r.jsx("div",{className:"process-info-loading",children:S("processInfoNoProcessData")})]}):i.owner==="external"?r.jsx("div",{className:"process-info-muted",children:S("processInfoExternalProcess")}):r.jsx("div",{className:"process-info-muted",children:S("processInfoNoActiveProcess")})}),T&&r.jsxs(za,{title:S("processInfoSectionProject"),children:[r.jsx(cn,{label:S("processInfoLabelProjectName"),value:T.projectName}),r.jsx(cn,{label:S("processInfoLabelProjectPath"),value:T.projectPath,mono:!0}),r.jsx(cn,{label:S("processInfoLabelRemoteHost"),value:T.executor,mono:!0})]})]})})}const LY={claude:"var(--provider-claude)","claude-ollama":"var(--provider-claude)",codex:"var(--provider-codex)","codex-oss":"var(--provider-codex)",gemini:"var(--provider-gemini)","gemini-acp":"var(--provider-gemini)",opencode:"var(--provider-opencode)"},OY={claude:"Claude","claude-ollama":"Ollama",codex:"Codex","codex-oss":"CodexOSS",gemini:"Gemini","gemini-acp":"Gemini ACP",opencode:"OpenCode"};function UY({provider:e,compact:t=!1,model:s,isThinking:i=!1,className:l=""}){const c=LY[e],d=OY[e],m=(b=>{if(!b||b==="default")return null;const w=b.includes("[1m]"),_=Yc.find(N=>N.value===b);if(_&&_.value!=="default")return _.label;const C=b.match(/claude-(\w+)-/);if(C!=null&&C[1]){const N=C[1],T=Yc.find(A=>A.value===N);if(T)return w?`${T.label} 1M`:T.label;const k=N.charAt(0).toUpperCase()+N.slice(1);return w?`${k} 1M`:k}const S=b.charAt(0).toUpperCase()+b.slice(1);return w?`${S} 1M`:S})(s);if(t)return r.jsx("span",{className:`provider-badge-stripe ${l}`,style:{backgroundColor:c},title:m?`${d} (${m})`:d,"aria-label":`Provider: ${d}${m?` (${m})`:""}`});const g=i?"provider-badge-dot-inline thinking":"provider-badge-dot-inline",v=i?{backgroundColor:"var(--thinking-color)"}:{backgroundColor:c};return r.jsxs("span",{className:`provider-badge ${l}`,style:{borderColor:c,color:c},children:[r.jsx("span",{className:g,style:v}),r.jsx("span",{className:"provider-badge-label",children:d}),m&&r.jsx("span",{className:"provider-badge-model",children:m})]})}function PY({request:e,sessionId:t,onSubmit:s,onDeny:i}){const{t:l}=xt(),c=e.toolInput,d=(c==null?void 0:c.questions)||[],[f,m]=h.useState(0),[g,v]=h.useState({}),[b,w,_]=WF(t),[C,S]=h.useState(!1),[N,T]=h.useState(!1),k=h.useRef(null),A=d[f],P=f===d.length-1,U=A?g[A.question]:void 0,O=U==="__other__",z=d.every(Z=>{const Q=g[Z.question];return Q?Q==="__other__"?(b[Z.question]||"").trim().length>0:!0:!1});h.useEffect(()=>{O&&k.current&&(k.current.focus(),setTimeout(()=>{var Z;(Z=k.current)==null||Z.scrollIntoView({behavior:"smooth",block:"center"})},100))},[O]);const q=h.useCallback(Z=>{A&&v(Q=>({...Q,[A.question]:Z}))},[A]),oe=h.useCallback(Z=>{A&&w(A.question,Z)},[A,w]),K=h.useCallback(()=>{P||m(Z=>Z+1)},[P]),I=h.useCallback(async()=>{if(!z||C)return;const Z={};for(const Q of d){const ae=g[Q.question];ae==="__other__"?Z[Q.question]=b[Q.question]||"":ae&&(Z[Q.question]=ae)}S(!0);try{await s(Z),_()}finally{S(!1)}},[z,C,d,g,b,s,_]),B=h.useCallback(async()=>{S(!0);try{await i()}finally{S(!1)}},[i]);return h.useEffect(()=>{const Z=Q=>{if(!C){if(Q.key==="Escape"){Q.preventDefault(),B();return}if(Q.key==="Enter"&&!Q.shiftKey){const ae=U&&U!=="__other__",W=U==="__other__"&&(b[(A==null?void 0:A.question)||""]||"").trim().length>0;(ae||W)&&(Q.preventDefault(),P&&z?I():K())}Q.key==="Tab"&&!O&&(Q.preventDefault(),Q.shiftKey?m(ae=>Math.max(0,ae-1)):m(ae=>Math.min(d.length-1,ae+1)))}};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[C,U,A,b,P,z,O,d.length,B,I,K]),d.length?r.jsxs("div",{className:"question-panel-wrapper",children:[r.jsx("button",{type:"button",className:"question-panel-toggle",onClick:()=>T(!N),"aria-label":l(N?"questionPanelExpand":"questionPanelCollapse"),"aria-expanded":!N,children:r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:N?"chevron-up":"chevron-down","aria-hidden":"true",children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})}),!N&&r.jsxs("div",{className:"question-panel",children:[r.jsx("div",{className:"question-tabs",children:d.map((Z,Q)=>{const ae=Q===f,W=!!g[Z.question];return r.jsxs("button",{type:"button",className:`question-tab ${ae?"active":""} ${W?"answered":""}`,onClick:()=>m(Q),children:[W&&r.jsx("span",{className:"question-tab-check",children:"✓"}),Z.header]},Z.question)})}),A&&r.jsxs("div",{className:"question-content",children:[r.jsx("div",{className:"question-text",children:A.question}),r.jsxs("div",{className:"question-options-list",children:[A.options.map(Z=>{const Q=U===Z.label;return r.jsxs("button",{type:"button",className:`question-option-btn ${Q?"selected":""}`,onClick:()=>q(Z.label),children:[r.jsx("span",{className:"question-option-radio",children:A.multiSelect?Q?"☑":"☐":Q?"●":"○"}),r.jsxs("div",{className:"question-option-text",children:[r.jsx("span",{className:"question-option-label",children:Z.label}),Z.description&&r.jsx("span",{className:"question-option-desc",children:Z.description})]})]},Z.label)}),r.jsxs("button",{type:"button",className:`question-option-btn other ${O?"selected":""}`,onClick:()=>q("__other__"),children:[r.jsx("span",{className:"question-option-radio",children:O?"●":"○"}),r.jsx("div",{className:"question-option-text",children:r.jsx("span",{className:"question-option-label",children:l("questionPanelOther")})})]}),O&&r.jsx("div",{className:"question-other-input",children:r.jsx("input",{ref:k,type:"text",placeholder:l("questionPanelTypeAnswer"),value:b[A.question]||"",onChange:Z=>oe(Z.target.value)})})]})]}),r.jsxs("div",{className:"question-actions",children:[r.jsxs("button",{type:"button",className:"question-btn deny",onClick:B,disabled:C,children:[l("questionPanelCancel"),r.jsx("kbd",{children:"esc"})]}),P?r.jsxs("button",{type:"button",className:"question-btn submit",onClick:I,disabled:!z||C,children:[l("questionPanelSubmit"),r.jsx("kbd",{children:"↵"})]}):r.jsxs("button",{type:"button",className:"question-btn next",onClick:K,disabled:!U||C,children:[l("questionPanelNext"),r.jsx("kbd",{children:"↵"})]})]})]})]}):r.jsx("div",{className:"question-panel-wrapper",children:r.jsx("div",{className:"question-panel",children:r.jsx("div",{className:"question-panel-empty",children:l("questionPanelNoQuestions")})})})}const Mb=10;function IY(e){const t=Date.now(),s=new Date(e).getTime(),i=t-s,l=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return l<1?"now":l<60?`${l}m`:c<24?`${c}h`:d<7?`${d}d`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function zY(e){return e.customTitle||e.title||"Untitled"}function $Y({session:e}){if(e.activity==="in-turn")return r.jsx(Oo,{});if(e.pendingInputType){const s=e.pendingInputType==="tool-approval"?"Appr":"Q";return r.jsx("span",{className:"recent-sessions-badge needs-input",children:s})}return e.ownership.owner==="external"?r.jsx("span",{className:"recent-sessions-badge external",children:"Ext"}):null}function BY({currentSessionId:e,isOpen:t,onClose:s,onNavigate:i,triggerRef:l,basePath:c=""}){var w;const d=h.useRef(null),{sessions:f}=Zc({limit:Mb+5,includeStats:!1}),m=f.filter(_=>_.id!==e&&!_.isArchived).slice(0,Mb);if(h.useEffect(()=>{if(!t)return;const _=S=>{const N=S.target;d.current&&!d.current.contains(N)&&l.current&&!l.current.contains(N)&&s()},C=S=>{S.key==="Escape"&&s()};return document.addEventListener("mousedown",_),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",C)}},[t,s,l]),h.useEffect(()=>{if(!t)return;const _=()=>s();return window.addEventListener("scroll",_,{passive:!0}),()=>window.removeEventListener("scroll",_)},[t,s]),!t)return null;const g=(w=l.current)==null?void 0:w.getBoundingClientRect(),v=g?{position:"fixed",top:g.bottom+4,left:Math.max(8,g.left-100),width:"min(830px, calc(100vw - 32px))"}:{},b=r.jsxs("div",{ref:d,className:"recent-sessions-dropdown",style:v,children:[r.jsx("div",{className:"recent-sessions-header",children:"Recent Sessions"}),m.length===0?r.jsx("div",{className:"recent-sessions-empty",children:"No other sessions"}):r.jsx("div",{className:"recent-sessions-list",children:m.map(_=>r.jsxs(Xs,{to:`${c}/projects/${_.projectId}/sessions/${_.id}`,className:`recent-session-item${_.hasUnread?" unread":""}`,onClick:()=>{i(_.id,_.projectId),s()},children:[r.jsxs("div",{className:"recent-session-content",children:[r.jsxs("span",{className:"recent-session-title",children:[_.isStarred&&r.jsx("svg",{className:"recent-session-star",width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:r.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),r.jsx("span",{className:"recent-session-title-text",children:zY(_)})]}),r.jsx("span",{className:"recent-session-project",children:_.projectName})]}),r.jsxs("div",{className:"recent-session-meta",children:[r.jsx($Y,{session:_}),r.jsx("span",{className:"recent-session-time",children:IY(_.updatedAt)})]})]},_.id))})]});return zi.createPortal(b,document.body)}const FY=["Edit","Write","NotebookEdit"],qf=e=>e==="ExitPlanMode",HY=150;function qY({request:e,sessionId:t,onApprove:s,onDeny:i,onApproveAcceptEdits:l,onDenyWithFeedback:c,collapsed:d=!1,onCollapsedChange:f}){const{t:m}=xt(),[g,v]=h.useState(!1),[b,w]=h.useState(!1),[_,C,S]=VF(t),[N,T]=h.useState(()=>_.length>0),k=h.useRef(null);h.useEffect(()=>{w(!1);const Q=setTimeout(()=>w(!0),HY);return()=>clearTimeout(Q)},[e.id]);const A=e.toolName&&FY.includes(e.toolName),P=h.useCallback(async()=>{v(!0);try{await s()}finally{v(!1)}},[s]),U=h.useCallback(async()=>{if(l){v(!0);try{await l()}finally{v(!1)}}},[l]),O=h.useCallback(async()=>{v(!0);try{await i()}finally{v(!1)}},[i]),z=h.useCallback(async()=>{if(!(!c||!_.trim())){v(!0);try{await c(_.trim()),S(),T(!1)}finally{v(!1)}}},[c,_,S]);h.useEffect(()=>{N&&k.current&&k.current.focus()},[N]),h.useEffect(()=>{const Q=ae=>{if(g||!b)return;if(N){ae.key==="Escape"?(ae.preventDefault(),T(!1),S()):ae.key==="Enter"&&_.trim()&&(ae.preventDefault(),z());return}qf(e.toolName)?ae.key==="1"&&l?(ae.preventDefault(),U()):ae.key==="2"?(ae.preventDefault(),P()):ae.key==="3"?(ae.preventDefault(),O()):ae.key==="Enter"&&!ae.shiftKey&&l?(ae.preventDefault(),U()):ae.key==="Escape"&&(ae.preventDefault(),O()):ae.key==="1"?(ae.preventDefault(),P()):ae.key==="2"&&A&&l?(ae.preventDefault(),U()):ae.key==="3"||ae.key==="2"&&(!A||!l)?(ae.preventDefault(),O()):ae.key==="Enter"&&!ae.shiftKey?(ae.preventDefault(),P()):ae.key==="Escape"&&(ae.preventDefault(),O())};return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[P,U,O,z,g,b,N,_,S,A,l,e.toolName]);const q=e.toolName?pS(e.toolName,e.toolInput,void 0,"pending"):e.prompt,[oe,K]=h.useState(!1),B=`Allow ${e.toolName??""} ${q??""}?`.length>120,Z=h.useMemo(()=>({isStreaming:!0,theme:"dark",toolUseId:e.id}),[e.id]);return r.jsxs("div",{className:"tool-approval-wrapper",children:[r.jsx("button",{type:"button",className:`tool-approval-toggle ${d?"has-pending":""}`,onClick:()=>f==null?void 0:f(!d),"aria-label":m(d?"toolApprovalExpand":"toolApprovalCollapse"),"aria-expanded":!d,children:r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:d?"chevron-up":"chevron-down","aria-hidden":"true",children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})}),!d&&r.jsxs("div",{className:"tool-approval-panel",children:[r.jsx("div",{className:"tool-approval-header",children:qf(e.toolName)?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"tool-approval-title",children:m("toolApprovalPlanTitle")}),r.jsx("span",{className:"tool-approval-subtitle",children:m("toolApprovalPlanSubtitle")})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"tool-approval-question-row",children:[r.jsx("span",{className:"tool-approval-question",children:m("toolApprovalAllow",{tool:e.toolName??"",summary:q??""})}),B&&r.jsx("button",{type:"button",className:"tool-approval-view-details",onClick:()=>K(!0),children:m("toolApprovalViewDetails")})]}),oe&&e.toolName&&r.jsx(Yn,{title:m("toolApprovalDetailsTitle",{tool:e.toolName}),onClose:()=>K(!1),children:r.jsx("div",{className:"tool-use-expanded",children:un.renderToolUse(e.toolName,e.toolInput,Z)})})]})}),r.jsxs("div",{className:"tool-approval-options",children:[qf(e.toolName)?r.jsxs(r.Fragment,{children:[r.jsxs("button",{type:"button",className:"tool-approval-option primary",onClick:U,disabled:!b||g||!l,children:[r.jsx("kbd",{children:"1"}),r.jsx("span",{children:m("toolApprovalYesAuto")})]}),r.jsxs("button",{type:"button",className:"tool-approval-option",onClick:P,disabled:!b||g,children:[r.jsx("kbd",{children:"2"}),r.jsx("span",{children:m("toolApprovalYesManual")})]}),r.jsxs("button",{type:"button",className:"tool-approval-option",onClick:O,disabled:!b||g,children:[r.jsx("kbd",{children:"3"}),r.jsx("span",{children:m("toolApprovalNoKeepPlanning")})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{type:"button",className:"tool-approval-option primary",onClick:P,disabled:!b||g,children:[r.jsx("kbd",{children:"1"}),r.jsx("span",{children:m("toolApprovalYes")})]}),A&&l&&r.jsxs("button",{type:"button",className:"tool-approval-option",onClick:U,disabled:!b||g,children:[r.jsx("kbd",{children:"2"}),r.jsx("span",{children:m("toolApprovalYesDontAsk")})]}),r.jsxs("button",{type:"button",className:"tool-approval-option",onClick:O,disabled:!b||g,children:[r.jsx("kbd",{children:A&&l?"3":"2"}),r.jsx("span",{children:m("toolApprovalNo")})]})]}),c&&!N&&r.jsx("button",{type:"button",className:"tool-approval-option feedback-toggle",onClick:()=>T(!0),disabled:!b||g,children:r.jsx("span",{children:m("toolApprovalTellInstead")})}),c&&N&&r.jsxs("div",{className:"tool-approval-feedback",children:[r.jsx("input",{ref:k,type:"text",placeholder:m("toolApprovalFeedbackPlaceholder"),value:_,onChange:Q=>C(Q.target.value),disabled:!b||g,className:"tool-approval-feedback-input"}),r.jsx("button",{type:"button",className:"tool-approval-feedback-submit",onClick:z,disabled:!b||g||!_.trim(),children:m("toolApprovalSend")})]})]})]})]})}const VY=3e4,Db=2e3;function WY(e){const{sessionId:t,activityAt:s,updatedAt:i,lastSeenAt:l,hasUnread:c=!1,enabled:d=!0}=e,f=h.useRef(Date.now()),m=h.useRef(null),g=h.useRef(null),v=h.useRef(!0),b=h.useRef(!0),w=h.useCallback(()=>s?l?s>l||c:!0:!1,[s,l,c]),_=h.useCallback(()=>{const N=document.hasFocus(),T=Date.now()-f.current<VY;return N&&T},[]),C=h.useCallback(()=>{!d||!v.current||!s||!i||m.current!==s&&_()&&w()&&(g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{if(v.current)try{await Re.markSessionSeen(t,i),m.current=s}catch(N){console.warn("[useEngagementTracking] Failed to mark session as seen:",N)}},Db))},[d,t,s,i,_,w]);return h.useEffect(()=>{if(!d)return;const N=()=>{f.current=Date.now(),w()&&_()&&C()},T=["mousemove","keydown","scroll","click","touchstart"];for(const k of T)window.addEventListener(k,N,{passive:!0});return()=>{for(const k of T)window.removeEventListener(k,N)}},[d,w,_,C]),h.useEffect(()=>{if(!d)return;const N=()=>{document.visibilityState==="visible"&&w()&&_()&&C()},T=()=>{f.current=Date.now(),w()&&_()&&C()};return document.addEventListener("visibilitychange",N),window.addEventListener("focus",T),()=>{document.removeEventListener("visibilitychange",N),window.removeEventListener("focus",T)}},[d,w,_,C]),h.useEffect(()=>{d&&(!s||!i||b.current&&(b.current=!1,w()&&(g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{if(v.current&&m.current!==s)try{await Re.markSessionSeen(t,i),m.current=s}catch(N){console.warn("[useEngagementTracking] Failed to mark session as seen:",N)}},Db))))},[d,t,s,i,w]),h.useEffect(()=>(v.current=!0,()=>{v.current=!1,g.current&&clearTimeout(g.current)}),[]),{forceMarkSeen:h.useCallback(async()=>{if(!(!d||!i))try{await Re.markSessionSeen(t,i),m.current=s}catch(N){console.warn("[useEngagementTracking] Failed to force mark session as seen:",N)}},[d,t,s,i]),isEngaged:_}}function YY(e,t){Re.recordVisit(e,t).catch(s=>{console.error("Failed to record session visit:",s)})}function ZY(e){var i;const t=new Map,s=new Set;for(const l of e){const c=((i=l.message)==null?void 0:i.content)??l.content;if(Array.isArray(c))for(const d of c){if(d.type==="tool_use"&&(d.name==="Task"||d.name==="Agent")&&typeof d.id=="string"){const f=d.input;t.set(d.id,{description:(f==null?void 0:f.description)??"Unknown task",subagentType:(f==null?void 0:f.subagent_type)??"unknown"})}d.type==="tool_result"&&typeof d.tool_use_id=="string"&&s.add(d.tool_use_id)}}return[...t.entries()].filter(([l])=>!s.has(l)).map(([l,{description:c,subagentType:d}])=>({toolUseId:l,description:c,subagentType:d}))}function GY(e){const t=e.relativePath.split(/[\\/]/).pop();if(!t)return null;let s=t;if(s.endsWith(".jsonl")?s=s.slice(0,-6):s.endsWith(".json")&&(s=s.slice(0,-5)),e.provider==="codex"){const i=s.match(/([0-9a-fA-F-]{36})$/);if(i)return i[1]??null}return s}const tm=3e3,nm=9e4,KY=400,kc=new WeakMap;function XY(e){var s;const t=(s=e.message)==null?void 0:s.role;return t==="user"||t==="assistant"?t:e.role==="user"||e.role==="assistant"||e.role==="system"?e.role:"unknown"}function Ga(e){return e==null?String(e):typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):Array.isArray(e)?`[${e.map(t=>Ga(t)).join(",")}]`:typeof e=="object"?`{${Object.entries(e).sort(([s],[i])=>s.localeCompare(i)).map(([s,i])=>`${s}:${Ga(i)}`).join(",")}}`:String(e)}function QY(e){if(typeof e=="string")return`text:${e}`;if(!e||typeof e!="object")return"";const t=e,s=typeof t.type=="string"?t.type:"unknown";switch(s){case"text":case"output_text":return`text:${typeof t.text=="string"?t.text:""}`;case"thinking":return`thinking:${typeof t.thinking=="string"?t.thinking:""}`;case"tool_use":return`tool_use:${typeof t.id=="string"?t.id:""}:${typeof t.name=="string"?t.name:""}:${Ga(t.input)}`;case"tool_result":return`tool_result:${typeof t.tool_use_id=="string"?t.tool_use_id:""}:${t.is_error===!0?"1":"0"}:${typeof t.content=="string"?t.content:Ga(t.content)}`;default:return`${s}:${Ga(t)}`}}function fh(e){return e.isReplay===!0}function JY(e,t){return fh(e)||fh(t)?nm:tm}function Qc(e){const t=kc.get(e);if(t!==void 0)return t;const s=KF(e);let i;if(typeof s=="string")i=`text:${s}`;else if(Array.isArray(s))i=s.map(QY).join("|");else return kc.set(e,null),null;if(!i.trim())return kc.set(e,null),null;const l=typeof e.type=="string"?e.type:"unknown",c=XY(e),d=`${l}|${c}|${i}`;return kc.set(e,d),d}function Oi(e){if(typeof e.timestamp!="string")return null;const t=Date.parse(e.timestamp);return Number.isFinite(t)?t:null}function eZ(e,t,s){const i=Qc(t),l=Oi(t);if(!i||l===null)return!1;const c=tm,d=nm,f=KY,m=Math.max(0,e.length-f);for(let g=e.length-1;g>=m;g-=1){const v=e[g];if(!v||v._source!=="jsonl"||Qc(v)!==i)continue;const b=Oi(v);if(b===null)continue;const w=fh(t)?d:c;if(Math.abs(b-l)<=w)return!0}return!1}function Tc(e,t){const s=tm,l=Math.max(s,nm),c=e.map((f,m)=>({message:f,originalIndex:m,timestampMs:Oi(f),fingerprint:Qc(f)})).sort((f,m)=>f.timestampMs===null&&m.timestampMs===null?f.originalIndex-m.originalIndex:f.timestampMs===null?1:m.timestampMs===null?-1:f.timestampMs!==m.timestampMs?f.timestampMs-m.timestampMs:f.originalIndex-m.originalIndex),d=[];for(const f of c){let m=!1;if(f.fingerprint&&f.timestampMs!==null)for(let g=d.length-1;g>=0;g-=1){const v=d[g];if(!v||v.timestampMs===null)continue;if(f.timestampMs-v.timestampMs>l)break;if(v.fingerprint!==f.fingerprint||v.message._source===void 0||f.message._source===void 0||v.message._source===f.message._source)continue;const b=JY(v.message,f.message)??s;if(!(f.timestampMs-v.timestampMs>b)){v.message=Hh(v.message,f.message,f.message._source),v.timestampMs=Oi(v.message)??v.timestampMs,v.fingerprint=Qc(v.message),m=!0;break}}m||d.push(f)}return d.map(f=>f.message)}function $a(e){return e==="codex"||e==="codex-oss"}function tZ(e){var s;if(e.type!=="assistant")return!1;const t=(s=e.message)==null?void 0:s.content;return typeof t=="string"?t.trim().length===0:Array.isArray(t)?t.every(i=>{if(!i||typeof i!="object")return!0;const l=i;return l.type==="text"?typeof l.text!="string"||l.text.trim()==="":l.type==="thinking"?typeof l.thinking!="string"||l.thinking.trim()==="":!1}):!1}function nZ(e){const{projectId:t,sessionId:s,onLoadComplete:i,onLoadError:l}=e,[c,d]=h.useState([]),[f,m]=h.useState({}),[g,v]=h.useState(()=>new Map),[b,w]=h.useState(!0),[_,C]=h.useState(null),[S,N]=h.useState(),[T,k]=h.useState(!1),A=h.useRef([]),P=h.useRef(!1),U=h.useRef(void 0),O=h.useRef(void 0),z=h.useRef(Number.NEGATIVE_INFINITY),q=h.useCallback(ne=>{let ge=z.current;for(const $ of ne){const G=Oi($);G!==null&&G>ge&&(ge=G)}z.current=ge},[]);h.useEffect(()=>{const ne=c[c.length-1];ne&&(O.current=Hn(ne))},[c]);const oe=h.useCallback((ne,ge=!1)=>{const $=U.current,G=ne.isReplay===!0,le=(ge||G)&&$a($),fe=Oi(ne),ue=G&&fe!==null&&fe<=z.current;d(_e=>{if(ue||le&&(tZ(ne)||eZ(_e,ne)))return _e;const Ke=tH(_e,ne);return $a($)?Tc(Ke.messages):Ke.messages})},[]),K=h.useCallback((ne,ge)=>{m($=>{const G=$[ge]??{messages:[],status:"running"},le=Hn(ne);return G.messages.some(fe=>Hn(fe)===le)?$:{...$,[ge]:{...G,messages:[...G.messages,ne],status:"running"}}})},[]),I=h.useCallback(()=>{const ne=A.current;A.current=[];for(const ge of ne)ge.type==="message"?oe(ge.msg,!0):K(ge.msg,ge.agentId)},[oe,K]);h.useEffect(()=>{P.current=!1,A.current=[],z.current=Number.NEGATIVE_INFINITY,w(!0),m({}),Re.getSession(t,s,void 0,{tailCompactions:2}).then(ne=>{C(ne.session),N(ne.pagination),U.current=ne.session.provider;const ge=ne.messages.map(G=>({...G,_source:"jsonl"}));q(ge),d($a(ne.session.provider)?Tc(ge):ge);const $=ge[ge.length-1];$&&(O.current=Hn($)),P.current=!0,I(),w(!1),i==null||i({session:ne.session,status:ne.ownership,pendingInputRequest:ne.pendingInputRequest,slashCommands:ne.slashCommands})}).catch(ne=>{w(!1),l==null||l(ne)})},[t,s,i,l,I,q]);const B=h.useCallback((ne,ge)=>{const $=Hn(ne);if($){if(ge){m(G=>{const le=G[ge]??{messages:[],status:"running"},fe=le.messages.findIndex(ue=>Hn(ue)===$);if(fe>=0){const ue=[...le.messages];return ue[fe]=ne,{...G,[ge]:{...le,messages:ue}}}return{...G,[ge]:{...le,messages:[...le.messages,ne]}}});return}d(G=>{const le=G.findIndex(fe=>Hn(fe)===$);if(le>=0){const fe=[...G];return fe[le]=ne,fe}return[...G,ne]})}},[]),Z=h.useCallback(ne=>{if(!P.current){A.current.push({type:"message",msg:ne});return}oe(ne)},[oe]),Q=h.useCallback((ne,ge)=>{if(!P.current){A.current.push({type:"subagent",msg:ne,agentId:ge});return}K(ne,ge)},[K]),ae=h.useCallback((ne,ge)=>{v($=>{if($.has(ne))return $;const G=new Map($);return G.set(ne,ge),G})},[]),W=h.useCallback(async()=>{try{const ne=await Re.getSession(t,s,O.current);ne.messages.length>0&&(q(ne.messages),d(ge=>{const $=eH(ge,ne.messages,{skipDagOrdering:!E0(ne.session.provider).capabilities.supportsDag});return $a(ne.session.provider)?Tc($.messages):$.messages})),C(ge=>ge?{...ge,...ne.session,messages:ge.messages}:ne.session)}catch{}},[t,s,q]),Y=h.useCallback(async()=>{if(!(!(S!=null&&S.hasOlderMessages)||!S.truncatedBeforeMessageId)){k(!0);try{const ne=await Re.getSession(t,s,void 0,{tailCompactions:2,beforeMessageId:S.truncatedBeforeMessageId});d(ge=>{const $=ne.messages.map(le=>({...le,_source:"jsonl"}));q($);const G=[...$,...ge];return $a(ne.session.provider)?Tc(G):G}),N(ne.pagination)}catch{}finally{k(!1)}}},[t,s,S,q]),V=h.useCallback(async()=>{try{const ne=await Re.getSessionMetadata(t,s);C(ge=>ge?{...ge,...ne.session,messages:ge.messages}:{...ne.session,messages:[]})}catch{}},[t,s]);return{messages:c,agentContent:f,toolUseToAgent:g,loading:b,session:_,setSession:C,handleStreamingUpdate:B,handleStreamMessageEvent:Z,handleStreamSubagentMessage:Q,registerToolUseAgent:ae,setAgentContent:m,setToolUseToAgent:v,setMessages:d,fetchNewMessages:W,fetchSessionMetadata:V,pagination:S,loadingOlder:T,loadOlderMessages:Y}}function sZ(e,t){const[s,i]=h.useState(!1),l=h.useRef(null),c=h.useRef(null),d=h.useRef(t);d.current=t;const f=h.useRef(null),m=h.useRef(!1),g=h.useCallback(()=>{if(!e){f.current=null;return}l.current||f.current!==e&&(f.current=e,v(e,$r()))},[e]),v=h.useCallback((w,_)=>{if(l.current){const T=l.current;l.current=null,T.close()}let C=null;const S=()=>C!==null&&l.current!==C,N={onEvent:(T,k,A)=>{if(Mn.recordEvent(),T==="heartbeat"){Mn.recordHeartbeat();return}k&&(c.current=k),d.current.onMessage({...A,eventType:T})},onOpen:()=>{var T,k;S()||(i(!0),Mn.markConnected(),(k=(T=d.current).onOpen)==null||k.call(T))},onError:T=>{var k,A;if(!S()){if(i(!1),l.current=null,f.current=null,(A=(k=d.current).onError)==null||A.call(k,new Event("error")),Va(T)){console.warn("[useSessionStream] Non-retryable error, not reconnecting:",T.message);return}Mn.handleError(T)}},onClose:()=>{m.current||S()||(i(!1),l.current=null,f.current=null)}};C=_.subscribeSession(w,N,c.current??void 0),l.current=C},[]);h.useEffect(()=>Mn.on("stateChange",w=>{if(w==="reconnecting"||w==="disconnected"){if(l.current){const _=l.current;l.current=null,_.close()}i(!1),f.current=null}w==="connected"&&e&&!l.current&&g()}),[e,g]);const b=h.useCallback(()=>{if(e){if(l.current){const w=l.current;l.current=null,w.close()}f.current=null,i(!1),setTimeout(()=>g(),50)}},[e,g]);return h.useEffect(()=>(g(),()=>{var w;m.current=!0,(w=l.current)==null||w.close(),l.current=null,f.current=null,m.current=!1}),[g]),{connected:s,reconnect:b}}function oZ(e,t){const[s,i]=h.useState(!1),l=h.useRef(null),c=h.useRef(t);c.current=t;const d=h.useRef(null),f=h.useRef(!1),m=h.useCallback(()=>{if(!e){d.current=null;return}const v=`${e.projectId}:${e.sessionId}`;l.current||d.current!==v&&(d.current=v,g(e,$r()))},[e]),g=h.useCallback((v,b)=>{if(l.current){const S=l.current;l.current=null,S.close()}let w=null;const _=()=>w!==null&&l.current!==w,C={onEvent:(S,N,T)=>{if(Mn.recordEvent(),S==="heartbeat"){Mn.recordHeartbeat();return}S==="session-watch-change"&&c.current.onChange()},onOpen:()=>{var S,N;_()||(i(!0),Mn.markConnected(),(N=(S=c.current).onOpen)==null||N.call(S))},onError:S=>{var N,T;if(!_()){if(i(!1),l.current=null,d.current=null,(T=(N=c.current).onError)==null||T.call(N,new Event("error")),Va(S)){console.warn("[useSessionWatchStream] Non-retryable error, not reconnecting:",S.message);return}Mn.handleError(S)}},onClose:()=>{f.current||_()||(i(!1),l.current=null,d.current=null)}};w=b.subscribeSessionWatch(v.sessionId,C,{projectId:v.projectId,provider:v.provider}),l.current=w},[]);return h.useEffect(()=>Mn.on("stateChange",v=>{if(v==="reconnecting"||v==="disconnected"){if(l.current){const b=l.current;l.current=null,b.close()}i(!1),d.current=null}v==="connected"&&e&&!l.current&&m()}),[e,m]),h.useEffect(()=>(m(),()=>{var v;f.current=!0,(v=l.current)==null||v.close(),l.current=null,d.current=null,f.current=!1}),[m]),{connected:s}}function gS(){const e=localStorage.getItem(mn.streamingEnabled);return e===null?!0:e==="true"}function rZ(e){localStorage.setItem(mn.streamingEnabled,String(e))}function iZ(){const[e,t]=h.useState(gS),s=h.useCallback(i=>{t(i),rZ(i)},[]);return{streamingEnabled:e,setStreamingEnabled:s}}function aZ(){return gS()}const lZ=50;function cZ(e){const{onUpdateMessage:t,streamingMarkdownCallbacks:s,onToolUseMapping:i,onAgentContextUsage:l,contextWindowSize:c}=e,d=h.useRef(new Map),f=h.useRef(null),m=h.useRef(null),g=h.useRef({timer:null,pendingIds:new Set}),v=h.useCallback(N=>{const T=d.current.get(N);if(!T)return;const k={id:N,type:"assistant",role:"assistant",message:{role:"assistant",content:T.blocks},_isStreaming:!0,_source:"sdk"};t(k,T.agentId)},[t]),b=h.useCallback(N=>{const T=g.current;T.pendingIds.add(N),T.timer||(T.timer=setTimeout(()=>{for(const k of T.pendingIds)v(k);T.pendingIds.clear(),T.timer=null},lZ))},[v]),w=h.useCallback(N=>{var q,oe;if(N.type!=="stream_event"||!aZ())return!1;const k=N.event;if(!k)return!0;const A=k.type,U=N.isSubagent&&(typeof N.parentToolUseId=="string"||typeof N.agentId=="string")?N.parentToolUseId??N.agentId:void 0;if(U&&i&&i(U,U),A==="message_start"){const K=k.message;if(K!=null&&K.id&&(f.current=K.id,m.current=U??null,(q=s==null?void 0:s.setCurrentMessageId)==null||q.call(s,K.id),U&&l)){const I=K.usage;if(I!=null&&I.input_tokens){const B=I.input_tokens,Z=typeof K.model=="string"?K.model:void 0,Q=typeof K.model_context_window=="number"?K.model_context_window:void 0,ae=Q&&Q>0?Q:Z?Xf(Z):c??Xf(void 0),W=B/ae*100;l(U,{inputTokens:B,percentage:W})}}return!0}const O=f.current??`stream-${Date.now()}`,z=m.current??U;if(A==="content_block_start"){const K=k.index,I=k.content_block;if(I){const B=d.current.get(O)??{blocks:[],isStreaming:!0,agentId:z};for(;B.blocks.length<=K;)B.blocks.push({type:"text",text:""});B.blocks[K]={type:I.type??"text",text:I.text??"",thinking:I.thinking??void 0},d.current.set(O,B),v(O)}}else if(A==="content_block_delta"){const K=k.index,I=k.delta;if(I){const B=d.current.get(O);if(B!=null&&B.blocks[K]){const Z=B.blocks[K],Q=I.type;Q==="text_delta"&&I.text?Z.text=(Z.text??"")+I.text:Q==="thinking_delta"&&I.thinking&&(Z.thinking=(Z.thinking??"")+I.thinking),b(O)}}}else A==="content_block_stop"||A==="message_stop"&&(d.current.delete(O),(oe=s==null?void 0:s.onStreamEnd)==null||oe.call(s));return!0},[v,b,s,i,l,c]),_=h.useCallback(()=>{d.current.clear(),f.current=null,m.current=null},[]),C=h.useCallback(()=>m.current,[]),S=h.useCallback(()=>{g.current.timer&&(clearTimeout(g.current.timer),g.current.timer=null)},[]);return{handleStreamEvent:w,clearStreaming:_,cleanup:S,getCurrentAgentId:C}}const uZ=500;function dZ(e){const t=e.message,s=t==null?void 0:t.content;if(typeof s=="string"){const i=s.trim();return i.length>0?i:null}if(Array.isArray(s)){const i=s.map(c=>{if(!c||typeof c!="object")return"";const d=c.text;return typeof d=="string"?d:""}).filter(c=>c.length>0);if(i.length===0)return null;const l=i.join(`
174
- `).trim();return l.length>0?l:null}return null}function fZ(e,t,s,i){const[l,c]=h.useState(s??{owner:"none"}),[d,f]=h.useState(s?"in-turn":"idle"),[m,g]=h.useState(null),[v,b]=h.useState(null),[w,_]=h.useState(t),[C,S]=h.useState(null),[N,T]=h.useState([]),[k,A]=h.useState([]),[P,U]=h.useState(!1),[O,z]=h.useState({}),[q,oe]=h.useState("default"),[K,I]=h.useState("default"),[B,Z]=h.useState(0),Q=h.useRef(!1);h.useEffect(()=>{Q.current=!1},[t]);const[ae,W]=h.useState([]),[Y,V]=h.useState([]),[ne,ge]=h.useState([]),$=h.useRef(0),G=h.useCallback((Ue,ct)=>{ct>=$.current&&($.current=ct,I(Ue),oe(Ue),Z(ct))},[]),le=h.useCallback(Ue=>{var ct;c(on=>on.owner==="self"&&Ue.status.owner!=="self"?on:Ue.status),Ue.status.owner==="self"&&Ue.status.permissionMode&&Ue.status.modeVersion!==void 0&&G(Ue.status.permissionMode,Ue.status.modeVersion),Ue.pendingInputRequest&&g(Ue.pendingInputRequest),(ct=Ue.slashCommands)!=null&&ct.length&&W(Ue.slashCommands.map(on=>on.name))},[G]),fe=h.useCallback(Ue=>{b(Ue)},[]),{messages:ue,agentContent:_e,toolUseToAgent:Ke,loading:tt,session:De,setSession:vt,handleStreamingUpdate:me,handleStreamMessageEvent:We,handleStreamSubagentMessage:ot,registerToolUseAgent:ut,setAgentContent:$e,setToolUseToAgent:Et,setMessages:Oe,fetchNewMessages:Ot,pagination:Tt,loadingOlder:Sn,loadOlderMessages:In}=nZ({projectId:e,sessionId:t,onLoadComplete:le,onLoadError:fe}),pn=h.useCallback(async Ue=>{if(oe(Ue),l.owner==="self"||l.owner==="external")try{const ct=await Re.setPermissionMode(t,Ue);ct.modeVersion>=$.current&&($.current=ct.modeVersion,I(ct.permissionMode),Z(ct.modeVersion))}catch(ct){console.warn("Failed to sync permission mode:",ct)}},[t,l.owner]),Nn=h.useCallback(async Ue=>{if(l.owner!=="self"&&l.owner!=="external"){console.warn("Cannot set hold: no active process");return}try{const ct=await Re.setHold(t,Ue);ct.state==="hold"?f("hold"):ct.state==="in-turn"&&f("in-turn")}catch(ct){console.warn("Failed to set hold:",ct)}},[t,l.owner]),Jt=h.useRef({timer:null,pending:!1}),jt=h.useCallback(Ue=>{const ct=`temp-${Date.now()}`;return T(on=>[...on,{tempId:ct,content:Ue,timestamp:new Date().toISOString()}]),ct},[]),ts=h.useCallback(Ue=>{T(ct=>ct.filter(on=>on.tempId!==Ue))},[]),ms=h.useCallback((Ue,ct)=>{T(on=>on.map(ls=>ls.tempId===Ue?{...ls,...ct}:ls))},[]),zn=h.useRef(null);h.useEffect(()=>{if(tt||zn.current===t||ue.length===0)return;(async()=>{zn.current=t;const ct=ZY(ue);if(ct.length!==0)try{const{mappings:on}=await Re.getAgentMappings(e,t),ls=new Map(on.map(Me=>[Me.toolUseId,Me.agentId]));Et(Me=>{const nn=new Map(Me);for(const[E,M]of ls)nn.has(E)||nn.set(E,M);return nn});for(const Me of ct){const nn=ls.get(Me.toolUseId);if(nn)try{const E=await Re.getAgentSession(e,t,nn);$e(M=>{const R=M[nn];if(R&&R.messages.length>0){const y=new Set(R.messages.map(ee=>Hn(ee))),L=E.messages.filter(ee=>!y.has(Hn(ee)));return{...M,[nn]:{messages:[...R.messages,...L],status:E.status}}}return{...M,[nn]:E}})}catch{}}}catch{}})()},[tt,ue,e,t,$e,Et]);const be=h.useCallback(()=>{const Ue=Jt.current;Ue.timer?Ue.pending=!0:(Ot(),Ue.timer=setTimeout(()=>{Ue.timer=null,Ue.pending&&(Ue.pending=!1,be())},uZ))},[Ot]),Be=h.useCallback(Ue=>{Ue.fileType!=="session"&&Ue.fileType!=="agent-session"||GY(Ue)!==t||l.owner!=="self"&&be()},[t,l.owner,be]),Pe=h.useCallback(Ue=>{Ue.sessionId===t&&vt(ct=>ct&&{...ct,...Ue.title!==void 0&&{title:Ue.title},...Ue.messageCount!==void 0&&{messageCount:Ue.messageCount},...Ue.updatedAt!==void 0&&{updatedAt:Ue.updatedAt},...Ue.contextUsage!==void 0&&{contextUsage:Ue.contextUsage},...Ue.model!==void 0&&{model:Ue.model}})},[t,vt]),Nt=h.useCallback(Ue=>{Ue.sessionId===t&&c(Ue.ownership)},[t]),sn=h.useCallback(async Ue=>{Ue.sessionId===t&&((Ue.activity==="idle"||Ue.activity==="in-turn"||Ue.activity==="waiting-input"||Ue.activity==="hold")&&f(Ue.activity),Ue.activity==="waiting-input"&&Ue.pendingInputType&&g(ct=>ct||(Re.getSessionMetadata(e,t).then(on=>{on.pendingInputRequest&&g(on.pendingInputRequest)}),ct)))},[e,t]),ve=h.useCallback(async()=>{Ot();try{const Ue=await Re.getSessionMetadata(e,t);c(Ue.ownership),Ue.ownership.owner==="none"&&(f("idle"),g(null))}catch{}},[e,t,Ot]);qi({onSessionStatusChange:Nt,onFileChange:Be,onSessionUpdated:Pe,onProcessStateChange:sn,onReconnect:ve});const Ye=h.useCallback(()=>{l.owner!=="self"&&be()},[l.owner,be]),{connected:at}=oZ(l.owner!=="self"?{sessionId:t,projectId:e,provider:De==null?void 0:De.provider}:null,{onChange:Ye});h.useEffect(()=>()=>{Jt.current.timer&&clearTimeout(Jt.current.timer)},[]);const Ut=h.useCallback((Ue,ct)=>{$e(on=>{const ls=on[Ue]??{messages:[],status:"running"};return{...on,[Ue]:{...ls,contextUsage:ct}}})},[$e]),{handleStreamEvent:kn,clearStreaming:Yt,cleanup:_n}=cZ({onUpdateMessage:me,onToolUseMapping:ut,onAgentContextUsage:Ut,contextWindowSize:Xf(De==null?void 0:De.model,De==null?void 0:De.provider),streamingMarkdownCallbacks:i});h.useEffect(()=>()=>{_n()},[_n]);const as=h.useCallback(Ue=>{var ct,on,ls;if(Ue.eventType==="message"){S(new Date().toISOString());const Me=Ue,nn=Me.uuid,E=Me.id,M=(typeof nn=="string"?nn:null)??(typeof E=="string"?E:null)??`msg-${Date.now()}`,R=typeof Me.type=="string"?Me.type:void 0,y=Me.role;if(R==="stream_event"&&kn(Me))return;if(R==="assistant"){const xe=Me.isSubagent&&typeof Me.parentToolUseId=="string"?Me.parentToolUseId:void 0;Yt(),xe?$e(ke=>{const Ge=ke[xe];if(!Ge)return ke;const Fe=Ge.messages.filter(Mt=>!Mt._isStreaming);return Fe.length===Ge.messages.length?ke:{...ke,[xe]:{...Ge,messages:Fe}}}):Oe(ke=>ke.filter(Ge=>!Ge._isStreaming))}const L={...Me,id:M,type:R,role:y??(R==="user"||R==="assistant"?R:void 0)};if(L.eventType=void 0,R==="system"&&Me.subtype==="init"&&(Array.isArray(Me.slash_commands)&&W(Me.slash_commands),Array.isArray(Me.tools)&&V(Me.tools),Array.isArray(Me.mcp_servers)&&ge(Me.mcp_servers)),R==="system"&&Me.subtype==="status"){const te=Me.status;U(te==="compacting");return}R==="system"&&Me.subtype==="compact_boundary"&&U(!1);const ee=Me.tempId;if(R==="user"&&ee)ts(ee);else if(R==="user"){const te=dZ(Me);te&&T(xe=>{const ke=xe.findIndex(Ge=>Ge.content.trim()===te);return ke===-1?xe:xe.filter((Ge,Fe)=>Fe!==ke)})}if(Me.isSubagent&&typeof Me.parentToolUseId=="string"){const te=Me.parentToolUseId;ut(te,te),ot(L,te);return}We(L)}else if(Ue.eventType==="status"){const Me=Ue;(Me.state==="idle"||Me.state==="in-turn"||Me.state==="waiting-input"||Me.state==="hold")&&f(Me.state),Me.state==="waiting-input"&&Me.request?(g(Me.request),Me.request.sessionId&&Me.request.sessionId!==t&&_(Me.request.sessionId)):g(null)}else if(Ue.eventType==="deferred-queue")A(Ue.messages??[]);else if(Ue.eventType==="complete")f("idle"),c({owner:"none"}),g(null),A([]);else if(Ue.eventType==="connected"){const Me=Ue,nn=Me.sessionId??((ct=Me.request)==null?void 0:ct.sessionId);nn&&nn!==t&&_(nn),(Me.state==="idle"||Me.state==="in-turn"||Me.state==="waiting-input"||Me.state==="hold")&&f(Me.state),Me.state==="waiting-input"&&Me.request?g(Me.request):g(null),Me.permissionMode&&Me.modeVersion!==void 0&&G(Me.permissionMode,Me.modeVersion);const E=Me.provider,M=Me.model;E&&vt(ee=>ee&&{...ee,provider:ee.provider||E,...M&&{model:M}}),A(Me.deferredMessages??[]);const R=Me.provider??(De==null?void 0:De.provider),y=R==="codex"||R==="codex-oss",L=!Q.current;Q.current=!0,L&&y||Ot()}else if(Ue.eventType==="mode-change"){const Me=Ue;Me.permissionMode&&Me.modeVersion!==void 0&&G(Me.permissionMode,Me.modeVersion)}else if(Ue.eventType==="markdown-augment"){const Me=Ue;Me.messageId&&Me.blockIndex===void 0&&Me.html?z(nn=>({...nn,[Me.messageId]:{html:Me.html}})):Me.blockIndex!==void 0&&((on=i==null?void 0:i.onAugment)==null||on.call(i,{blockIndex:Me.blockIndex,html:Me.html,type:Me.type??"text",messageId:Me.messageId}))}else if(Ue.eventType==="pending"){const Me=Ue;(ls=i==null?void 0:i.onPending)==null||ls.call(i,{html:Me.html})}else if(Ue.eventType==="session-id-changed"){const Me=Ue;Me.newSessionId&&Me.newSessionId!==t&&(_(Me.newSessionId),g(nn=>nn&&nn.sessionId===Me.oldSessionId?{...nn,sessionId:Me.newSessionId}:nn))}},[G,t,kn,Yt,ts,i,We,ot,ut,$e,Oe,vt,Ot,De==null?void 0:De.provider]),Cs=h.useCallback(async()=>{try{(await Re.getSessionMetadata(e,t)).ownership.owner!=="self"&&(c({owner:"none"}),f("idle"))}catch{c({owner:"none"}),f("idle")}},[e,t]),{connected:ns,reconnect:gn}=sZ(l.owner==="self"?t:null,{onMessage:as,onError:Cs}),qn=l.owner==="self"?ns:l.owner==="external"?at:!1,ss=h.useCallback(Ue=>{vt(ct=>ct&&{...ct,model:Ue})},[vt]);return{session:De,setSessionModel:ss,messages:ue,agentContent:_e,setAgentContent:$e,toolUseToAgent:Ke,markdownAugments:O,status:l,processState:d,isCompacting:P,isHeld:d==="hold",pendingInputRequest:m,actualSessionId:w,permissionMode:q,modeVersion:B,loading:tt,error:v,connected:ns,sessionWatchConnected:at,sessionUpdatesConnected:qn,lastStreamActivityAt:C,setStatus:c,setProcessState:f,setPermissionMode:pn,setHold:Nn,pendingMessages:N,addPendingMessage:jt,removePendingMessage:ts,updatePendingMessage:ms,deferredMessages:k,slashCommands:ae,sessionTools:Y,mcpServers:ne,pagination:Tt,loadingOlder:Sn,loadOlderMessages:In,reconnectStream:gn}}function hZ(){const{projectId:e,sessionId:t}=tu();return!e||!t?r.jsx(mZ,{}):r.jsx(qq,{children:r.jsx(pZ,{projectId:e,sessionId:t},t)})}function mZ(){const{t:e}=xt();return r.jsx("div",{className:"error",children:e("sessionInvalidUrl")})}function pZ({projectId:e,sessionId:t}){const{t:s}=xt(),{openSidebar:i,isWideScreen:l,toggleSidebar:c,isSidebarCollapsed:d}=Io(),f=mo(),{project:m}=Dh(e),g=js(),v=ws(),b=v.state,w=b==null?void 0:b.initialStatus,_=b==null?void 0:b.initialTitle,C=b==null?void 0:b.initialModel,S=b==null?void 0:b.initialProvider,N=Y0(),T=h.useMemo(()=>{if(N)return{onAugment:N.dispatchAugment,onPending:N.dispatchPending,onStreamEnd:N.dispatchStreamEnd,setCurrentMessageId:N.setCurrentMessageId,captureHtml:N.captureStreamingHtml}},[N]),{session:k,messages:A,agentContent:P,setAgentContent:U,toolUseToAgent:O,markdownAugments:z,status:q,processState:oe,isCompacting:K,pendingInputRequest:I,actualSessionId:B,permissionMode:Z,loading:Q,error:ae,sessionUpdatesConnected:W,lastStreamActivityAt:Y,setStatus:V,setProcessState:ne,setPermissionMode:ge,setHold:$,isHeld:G,pendingMessages:le,addPendingMessage:fe,removePendingMessage:ue,updatePendingMessage:_e,deferredMessages:Ke,slashCommands:tt,setSessionModel:De,pagination:vt,loadingOlder:me,loadOlderMessages:We,reconnectStream:ot}=fZ(e,t,w,T),{holdModeEnabled:ut,showConnectionBars:$e}=Hi(),{connectionState:Et}=Ah(),Oe=q.owner==="self"||q.owner==="external",Ot=!$e||!Oe?"idle":W?"connected":Et==="reconnecting"?"connecting":"disconnected",Tt=(k==null?void 0:k.provider)??S,Sn=(k==null?void 0:k.model)??C,[In,pn]=h.useState(0),Nn=h.useRef(null),Jt=h.useCallback(Le=>{Nn.current=Le},[]),{showToast:jt}=$h(),[ts,ms]=h.useState(!1);h.useEffect(()=>{Re.getSharingStatus().then(Le=>ms(Le.configured)).catch(()=>{})},[]);const zn=U0(),be=h.useMemo(()=>q.owner==="self"?tt.includes("model")?tt:["model",...tt]:tt,[tt,q.owner]),{providers:Be}=Yh(),Pe=h.useMemo(()=>k!=null&&k.provider?Be.find(Le=>Le.name===k.provider)??null:null,[Be,k==null?void 0:k.provider]),Nt=(Pe==null?void 0:Pe.supportsPermissionMode)??!0,sn=(Pe==null?void 0:Pe.supportsThinkingToggle)??!0;Pe==null||Pe.supportsSlashCommands;const[ve,Ye]=h.useState(!1),[at,Ut]=h.useState(""),[kn,Yt]=h.useState(!1),_n=h.useRef(null),as=h.useRef(!1),[Cs,ns]=h.useState(!1),gn=h.useRef(null),[qn,ss]=h.useState(void 0),[Ue,ct]=h.useState(void 0),[on,ls]=h.useState(void 0),[Me,nn]=h.useState(void 0);h.useEffect(()=>{ss(void 0),ct(void 0),ls(void 0),nn(void 0)},[t]),h.useEffect(()=>{YY(t,e)},[t,e]),h.useEffect(()=>{B&&B!==t&&g(`${f}/projects/${e}/sessions/${B}`,{replace:!0,state:v.state})},[B,t,e,g,v.state,f]);const[E,M]=h.useState([]),[R,y]=h.useState([]),L=h.useRef(new Map),[ee,te]=h.useState(!1),[xe,ke]=h.useState(!1),[Ge,Fe]=h.useState(!1),Mt=(k==null?void 0:k.updatedAt)??null,Qe=h.useMemo(()=>!Mt&&!Y?null:Mt?Y?Mt>Y?Mt:Y:Mt:Y,[Mt,Y]);WY({sessionId:t,activityAt:Qe,updatedAt:Mt,lastSeenAt:k==null?void 0:k.lastSeenAt,hasUnread:k==null?void 0:k.hasUnread,enabled:q.owner!=="external"});const ht=async Le=>{var zt,tn,Kt;const He=fe(Le);ne("in-turn"),pn(Wt=>Wt+1);const it=[...E],Vt=[...L.current.values()];if(Vt.length>0){_e(He,{status:s("sessionUploading")}),M([]);const Wt=await Promise.all(Vt);for(const $n of Wt)$n&&it.push($n);const Zn=new Set(it.map($n=>$n.id));M($n=>$n.filter(po=>!Zn.has(po.id))),_e(He,{status:void 0})}else M([]);try{if(q.owner==="none"){const Wt=(k==null?void 0:k.model)??sh(),Zn=qa(),$n=await Re.resumeSession(e,t,Le,{mode:Z,model:Wt,thinking:Zn,provider:Tt,executor:k==null?void 0:k.executor},it.length>0?it:void 0,He);V({owner:"self",processId:$n.processId})}else{const Wt=qa(),Zn=await Re.queueMessage(t,Le,Z,it.length>0?it:void 0,He,Wt);Zn.restarted&&Zn.processId&&(V({owner:"self",processId:Zn.processId}),ot())}(zt=Nn.current)==null||zt.clearDraft()}catch(Wt){if(console.error("Failed to send:",Wt),Wt instanceof Error&&(Wt.message.includes("404")||Wt.message.includes("No active process")))try{const po=(k==null?void 0:k.model)??sh(),Yi=qa(),zo=await Re.resumeSession(e,t,Le,{mode:Z,model:po,thinking:Yi,provider:Tt,executor:k==null?void 0:k.executor},it.length>0?it:void 0,He);V({owner:"self",processId:zo.processId}),(tn=Nn.current)==null||tn.clearDraft();return}catch(po){console.error("Failed to resume session:",po)}ue(He),(Kt=Nn.current)==null||Kt.restoreFromStorage(),M(it),ne("idle");const $n=Wt instanceof Error?Wt.message:String(Wt);jt(s("sessionSendFailed",{message:$n}),"error")}},bt=async Le=>{var zt,tn;const He=fe(Le);pn(Kt=>Kt+1);const it=[...E],Vt=[...L.current.values()];if(Vt.length>0){_e(He,{status:s("sessionUploading")}),M([]);const Kt=await Promise.all(Vt);for(const Zn of Kt)Zn&&it.push(Zn);const Wt=new Set(it.map(Zn=>Zn.id));M(Zn=>Zn.filter($n=>!Wt.has($n.id))),_e(He,{status:void 0})}else M([]);try{const Kt=qa();await Re.queueMessage(t,Le,Z,it.length>0?it:void 0,He,Kt,!0),ue(He),(zt=Nn.current)==null||zt.clearDraft()}catch(Kt){console.error("Failed to queue deferred message:",Kt),ue(He),(tn=Nn.current)==null||tn.restoreFromStorage(),M(it);const Wt=Kt instanceof Error?Kt.message:String(Kt);jt(s("sessionQueueFailed",{message:Wt}),"error")}},St=h.useCallback(Le=>{De(Le),jt(s("sessionSwitchedModel",{model:Le}),"success")},[De,jt,s]),yt=h.useCallback(Le=>Le==="model"?(Fe(!0),!0):!1,[]),mt=async()=>{if(q.owner==="self"&&q.processId){try{if((await Re.interruptProcess(q.processId)).interrupted)return}catch{}await Re.abortProcess(q.processId)}},gt=h.useCallback(async()=>{if(I)try{await Re.respondToInput(t,I.id,"approve")}catch(Le){const He=Le.status,it=He?`Error ${He}`:s("sessionApproveFailed");jt(it,"error")}},[t,I,jt,s]),et=h.useCallback(async()=>{if(I)try{await Re.respondToInput(t,I.id,"approve_accept_edits"),ge("acceptEdits")}catch(Le){const He=Le.status,it=He?`Error ${He}`:s("sessionApproveFailed");jt(it,"error")}},[t,I,ge,jt,s]),Je=h.useCallback(async()=>{if(I)try{await Re.respondToInput(t,I.id,"deny")}catch(Le){const He=Le.status,it=He?`Error ${He}`:s("sessionDenyFailed");jt(it,"error")}},[t,I,jt,s]),rt=h.useCallback(async Le=>{if(I)try{await Re.respondToInput(t,I.id,"deny",void 0,Le)}catch(He){const it=He.status,Vt=it?`Error ${it}`:s("sessionFeedbackFailed");jt(Vt,"error")}},[t,I,jt,s]),qe=h.useCallback(async Le=>{if(I)try{await Re.respondToInput(t,I.id,"approve",Le)}catch(He){const it=He.status,Vt=it?`Error ${it}`:s("sessionAnswerFailed");jt(Vt,"error")}},[t,I,jt,s]),Xe=h.useCallback(Le=>{for(const He of Le){const it=Fi();y(zt=>[...zt,{fileId:it,fileName:He.name,bytesUploaded:0,totalBytes:He.size,percent:0}]);const Vt=zn.upload(e,t,He,{onProgress:zt=>{y(tn=>tn.map(Kt=>Kt.fileId===it?{...Kt,bytesUploaded:zt,percent:Math.round(zt/He.size*100)}:Kt))}}).then(zt=>(M(tn=>[...tn,zt]),zt),zt=>{console.error("Upload failed:",zt);const tn=zt instanceof Error?zt.message:s("sessionShareFailed");return jt(s("sessionUploadFailed",{file:He.name,message:tn}),"error"),null}).finally(()=>{y(zt=>zt.filter(tn=>tn.fileId!==it)),L.current.delete(it)});L.current.set(it,Vt)}},[e,t,jt,zn,s]),nt=h.useCallback(Le=>{M(He=>He.filter(it=>it.id!==Le))},[]),Ve=(I==null?void 0:I.toolName)==="AskUserQuestion",de=oe==="in-turn"||oe==="waiting-input"||Oe&&!W,he=h.useMemo(()=>q.owner!=="none"?!1:Zh(A).some(He=>He.type==="tool_call"&&He.status==="pending"),[A,q.owner]),Te=Do(k),ye=qn??(Te!=="Untitled"?Te:null)??_??s("sessionUntitled"),Se=Ue??(k==null?void 0:k.isArchived)??!1,Ce=on??(k==null?void 0:k.isStarred)??!1;Wh(m==null?void 0:m.name,ye);const dt=()=>{Ut(ye),Ye(!0),setTimeout(()=>{var Le,He;(Le=_n.current)==null||Le.focus(),(He=_n.current)==null||He.select()},0)},At=()=>{as.current||(Ye(!1),Ut(""))},Rt=()=>{if(!as.current){if(!at.trim()||at.trim()===ye){At();return}_t()}},_t=async()=>{if(!(!at.trim()||kn)){as.current=!0,Yt(!0);try{await Re.updateSessionMetadata(t,{title:at.trim()}),ss(at.trim()),Ye(!1),jt(s("sessionRenamed"),"success")}catch(Le){console.error("Failed to rename session:",Le),jt(s("sessionRenameFailed"),"error")}finally{Yt(!1),as.current=!1}}},F=Le=>{Le.key==="Enter"?(Le.preventDefault(),_t()):Le.key==="Escape"&&(Le.preventDefault(),At())},Pt=async()=>{const Le=!Se;try{await Re.updateSessionMetadata(t,{archived:Le}),ct(Le),jt(s(Le?"sessionArchived":"sessionUnarchived"),"success")}catch(He){console.error("Failed to update archive status:",He),jt(s("sessionArchiveFailed"),"error")}},Ct=async()=>{const Le=!Ce;try{await Re.updateSessionMetadata(t,{starred:Le}),ls(Le),jt(s(Le?"sessionStarred":"sessionUnstarred"),"success")}catch(He){console.error("Failed to update star status:",He),jt(s("sessionStarFailed"),"error")}},Ht=Me??(k==null?void 0:k.hasUnread)??!1,Dt=async()=>{const Le=!Ht;nn(Le);try{Le?await Re.markSessionUnread(t):await Re.markSessionSeen(t),jt(s(Le?"sessionMarkedUnread":"sessionMarkedRead"),"success")}catch(He){console.error("Failed to update read status:",He),nn(void 0),jt(s("sessionReadFailed"),"error")}},qt=async()=>{if(q.owner==="self"&&q.processId)try{await Re.abortProcess(q.processId),jt(s("sessionTerminated"),"success")}catch(Le){console.error("Failed to terminate session:",Le);const He=Le instanceof Error?Le.message:String(Le);jt(s("sessionTerminateFailed",{message:He}),"error")}},It=h.useCallback(async()=>{try{const{snapshotSession:Le}=await _i(async()=>{const{snapshotSession:Vt}=await import("./snapshotSession-CUC6Plno.js");return{snapshotSession:Vt}},[]),He=Le(ye),it=await Re.shareSession(He,ye);await navigator.clipboard.writeText(it.url),jt(s("sessionLinkCopied"),"success")}catch(Le){const He=Le instanceof Error?Le.message:s("sessionShareFailed");jt(He,"error")}},[ye,jt,s]);if(ae)return r.jsxs("div",{className:"error",children:[s("sessionErrorPrefix")," ",ae.message]});const Cn=()=>r.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]});return r.jsx("div",{className:l?"main-content-wrapper":"main-content-mobile",children:r.jsxs("div",{className:l?"main-content-constrained":"main-content-mobile-inner",children:[r.jsx("header",{className:"session-header",children:r.jsxs("div",{className:"session-header-inner",children:[r.jsxs("div",{className:"session-header-left",children:[!(l&&d)&&r.jsx("button",{type:"button",className:"sidebar-toggle",onClick:l?c:i,title:s(l?"sessionToggleSidebar":"sessionOpenSidebar"),"aria-label":s(l?"sessionToggleSidebar":"sessionOpenSidebar"),children:r.jsx(Cn,{})}),(m==null?void 0:m.name)&&r.jsx(Xs,{to:`${f}/sessions?project=${e}`,className:"project-breadcrumb",title:m.name,children:m.name.length>12?`${m.name.slice(0,12)}...`:m.name}),r.jsxs("div",{className:"session-title-row",children:[Ce&&r.jsxs("svg",{className:"star-indicator-inline",width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",role:"img","aria-label":s("sessionStarredLabel"),children:[r.jsx("title",{children:s("sessionStarredLabel")}),r.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})]}),Q?r.jsx("span",{className:"session-title-skeleton"}):ve?r.jsx("input",{ref:_n,type:"text",className:"session-title-input",value:at,onChange:Le=>Ut(Le.target.value),onKeyDown:F,onBlur:Rt,disabled:kn}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{ref:gn,type:"button",className:"session-title session-title-dropdown-trigger",onClick:()=>ns(!Cs),title:(k==null?void 0:k.fullTitle)??ye,children:[r.jsx("span",{className:"session-title-text",children:ye}),r.jsx("svg",{className:"session-title-chevron",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),r.jsx(BY,{currentSessionId:t,isOpen:Cs,onClose:()=>ns(!1),onNavigate:()=>ns(!1),triggerRef:gn,basePath:f})]}),!Q&&Se&&r.jsx("span",{className:"archived-badge",children:s("sessionArchivedBadge")}),!Q&&r.jsx(N0,{sessionId:t,projectId:e,isStarred:Ce,isArchived:Se,hasUnread:Ht,provider:k==null?void 0:k.provider,processId:q.owner==="self"?q.processId:void 0,onToggleStar:Ct,onToggleArchive:Pt,onToggleRead:Dt,onRename:dt,onClone:Le=>{g(`${f}/projects/${e}/sessions/${Le}`)},onTerminate:qt,sharingConfigured:ts,onShare:It,useFixedPositioning:!0,useEllipsisIcon:!0})]})]}),r.jsx("div",{className:"session-header-right",children:!Q&&Tt&&r.jsx("button",{type:"button",className:"provider-badge-button",onClick:()=>ke(!0),title:s("sessionViewInfo"),children:r.jsx(UY,{provider:Tt,model:Sn,isThinking:oe==="in-turn"})})})]})}),xe&&k&&r.jsx(DY,{sessionId:B,provider:k.provider,model:k.model,status:q,processState:oe,contextUsage:k.contextUsage,originator:k.originator,cliVersion:k.cliVersion,sessionSource:k.source,approvalPolicy:k.approvalPolicy,sandboxPolicy:k.sandboxPolicy,createdAt:k.createdAt,sessionStreamConnected:W,lastSessionEventAt:Y,onClose:()=>ke(!1)}),Ge&&q.owner==="self"&&q.processId&&r.jsx(kY,{processId:q.processId,currentModel:k==null?void 0:k.model,onModelChanged:St,onClose:()=>Fe(!1)}),q.owner==="external"&&r.jsx("div",{className:"external-session-warning",children:s("sessionExternalWarning")}),he&&r.jsx("div",{className:"external-session-warning pending-tool-warning",children:s("sessionPendingElsewhereWarning")}),r.jsx("main",{className:"session-messages",children:Q?r.jsx("div",{className:"loading",children:s("sessionLoading")}):r.jsx(TV,{projectId:e,projectPath:(m==null?void 0:m.path)??null,sessionId:t,children:r.jsx(gW,{agentContent:P,setAgentContent:U,toolUseToAgent:O,projectId:e,sessionId:t,children:r.jsx(CY,{messages:A,provider:k==null?void 0:k.provider,isProcessing:q.owner==="self"&&oe==="in-turn",isCompacting:K,scrollTrigger:In,pendingMessages:le,deferredMessages:Ke,onCancelDeferred:Le=>Re.cancelDeferredMessage(t,Le),markdownAugments:z,activeToolApproval:de,hasOlderMessages:vt==null?void 0:vt.hasOlderMessages,loadingOlder:me,onLoadOlderMessages:We})})})}),r.jsxs("footer",{className:"session-input",children:[r.jsx("div",{className:`session-connection-bar session-connection-${Ot}`}),r.jsxs("div",{className:"session-input-inner",children:[I&&I.sessionId===B&&Ve&&r.jsx(PY,{request:I,sessionId:B,onSubmit:qe,onDeny:Je}),I&&I.sessionId===B&&!Ve&&r.jsxs(r.Fragment,{children:[r.jsx(qY,{request:I,sessionId:B,onApprove:gt,onDeny:Je,onApproveAcceptEdits:et,onDenyWithFeedback:rt,collapsed:ee,onCollapsedChange:te}),r.jsx(z0,{mode:Z,onModeChange:ge,isHeld:ut?G:void 0,onHoldChange:ut?$:void 0,supportsPermissionMode:Nt,supportsThinkingToggle:sn,contextUsage:k==null?void 0:k.contextUsage,isRunning:q.owner==="self",isThinking:oe==="in-turn",onStop:mt,pendingApproval:ee?{type:"tool-approval",onExpand:()=>te(!1)}:void 0})]}),!(I&&I.sessionId===B&&!Ve)&&r.jsx(rq,{onSend:ht,onQueue:q.owner!=="none"&&oe!=="idle"?bt:void 0,placeholder:q.owner==="external"?s("sessionPlaceholderExternal"):s(oe==="idle"?"sessionPlaceholderResume":"sessionPlaceholderQueue"),mode:Z,onModeChange:ge,isHeld:ut?G:void 0,onHoldChange:ut?$:void 0,supportsPermissionMode:Nt,supportsThinkingToggle:sn,isRunning:q.owner==="self",isThinking:oe==="in-turn",onStop:mt,draftKey:`draft-message-${t}`,onDraftControlsReady:Jt,collapsed:!!(I&&I.sessionId===B),contextUsage:k==null?void 0:k.contextUsage,projectId:e,sessionId:t,attachments:E,onAttach:Xe,onRemoveAttachment:nt,uploadProgress:R,slashCommands:q.owner==="self"?be:[],onCustomCommand:yt})]})]})]})})}function gZ(e,t){switch(e){case"auto":return t("themeAuto");case"light":return t("themeLight");case"dark":return t("themeDark");case"verydark":return t("themeVerydark")}}function xZ(e,t){switch(e){case"small":return t("fontSizeSmall");case"default":return t("fontSizeDefault");case"large":return t("fontSizeLarge");case"larger":return t("fontSizeLarger")}}function vZ(e,t){switch(e){case"en":return t("localeNameEn");case"zh-CN":return t("localeNameZhCn");case"es":return t("localeNameEs");case"fr":return t("localeNameFr");case"de":return t("localeNameDe");case"ja":return t("localeNameJa")}}function bZ(e){return[{id:"appearance",label:e("settingsAppearanceTitle"),icon:"🎨",description:e("settingsAppearanceDescription")},{id:"model",label:e("settingsModelTitle"),icon:"🧠",description:e("settingsModelDescription")},{id:"agent-context",label:e("settingsAgentContextTitle"),icon:"📋",description:e("settingsAgentContextDescription")},{id:"notifications",label:e("settingsNotificationsTitle"),icon:"🔔",description:e("settingsNotificationsDescription")},{id:"webhooks",label:e("settingsWebhooksTitle"),icon:"🪝",description:e("settingsWebhooksDescription")},{id:"devices",label:e("settingsDevicesTitle"),icon:"📱",description:e("settingsDevicesDescription")},{id:"local-access",label:e("settingsLocalAccessTitle"),icon:"🔒",description:e("settingsLocalAccessDescription")},{id:"remote",label:e("settingsRemoteTitle"),icon:"🌐",description:e("settingsRemoteDescription")},{id:"providers",label:e("settingsProvidersTitle"),icon:"🔌",description:e("settingsProvidersDescription")},{id:"remote-executors",label:e("settingsRemoteExecutorsTitle"),icon:"🖥️",description:e("settingsRemoteExecutorsDescription")},{id:"about",label:e("settingsAboutTitle"),icon:"ℹ️",description:e("settingsAboutDescription")}]}function yZ(e){return{id:"emulator",label:e("settingsEmulatorTitle"),icon:"🤖",description:e("settingsEmulatorDescription")}}function SZ(e){return{id:"development",label:e("settingsDevelopmentTitle"),icon:"🛠️",description:e("settingsDevelopmentDescription")}}let Pr=null;function wZ(){const[e,t]=h.useState(!1),[s,i]=h.useState(!1);h.useEffect(()=>{if(window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0){i(!0);return}Pr&&t(!0);const d=m=>{m.preventDefault(),Pr=m,t(!0)},f=()=>{i(!0),t(!1),Pr=null};return window.addEventListener("beforeinstallprompt",d),window.addEventListener("appinstalled",f),()=>{window.removeEventListener("beforeinstallprompt",d),window.removeEventListener("appinstalled",f)}},[]);const l=h.useCallback(async()=>{if(!Pr)return!1;await Pr.prompt();const{outcome:c}=await Pr.userChoice;return c==="accepted"?(t(!1),Pr=null,!0):!1},[]);return{canInstall:e,isInstalled:s,install:l}}function jZ(){const{t:e}=xt(),{canInstall:t,isInstalled:s,install:i}=wZ(),{version:l,loading:c,error:d,refetchFresh:f}=il({freshOnMount:!0}),m=Vi(),{resetOnboarding:g}=h0(),{remoteLogCollectionEnabled:v,setRemoteLogCollectionEnabled:b}=Hi(),w=!!(m!=null&&m.currentRelayUsername),_=((l==null?void 0:l.resumeProtocolVersion)??1)>=2,C=w&&!!l&&!_,[S,N]=h.useState(!1),[T,k]=h.useState(0);h.useEffect(()=>{Ie("/status/workers").then(P=>k(P.activeWorkers)).catch(()=>{})},[]),h.useEffect(()=>{if(S)return En.on("reconnect",()=>{N(!1)})},[S]);const A=h.useCallback(async()=>{N(!0);try{await Re.restartServer()}catch{}},[]);return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("aboutTitle")}),r.jsxs("div",{className:"settings-group",children:[(t||s)&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutInstallTitle")}),r.jsx("p",{children:e(s?"aboutInstalledDescription":"aboutInstallDescription")})]}),s?r.jsx("span",{className:"settings-status-badge",children:e("aboutInstalled")}):r.jsx("button",{type:"button",className:"settings-button",onClick:i,children:e("aboutInstall")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutVersionTitle")}),r.jsxs("p",{children:[e("aboutServerVersion")," ",l?r.jsxs(r.Fragment,{children:["v",l.current,l.updateAvailable&&l.latest?r.jsxs("span",{className:"settings-update-available",children:[" ",e("aboutVersionAvailable",{version:l.latest})]}):l.latest?r.jsxs("span",{className:"settings-up-to-date",children:[" ",e("aboutUpToDate")]}):null]}):e("loginLoading")]}),r.jsxs("p",{children:[e("aboutClientVersion")," v","0.4.27"]}),d&&r.jsx("p",{className:"settings-warning",children:e("aboutUnableRefresh")}),C&&r.jsx("p",{className:"settings-warning",children:e("aboutRelayResumeWarning")}),(l==null?void 0:l.updateAvailable)&&r.jsx("p",{className:"settings-update-hint",children:e("aboutUpdateHint")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:()=>void f(),disabled:c,children:e(c?"aboutChecking":"aboutCheckUpdates")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentRestartTitle")}),r.jsx("p",{children:e("developmentRestartDescription")}),T>0&&!S&&r.jsx("p",{className:"settings-warning",children:e("developmentInterruptedWarning",{count:T,suffix:T!==1?"s ":" "})})]}),r.jsx("button",{type:"button",className:`settings-button ${T>0?"settings-button-danger":""}`,onClick:A,disabled:S,children:S?e("developmentRestarting"):T>0?e("developmentRestartAnyway"):e("developmentRestart")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutReportBugTitle")}),r.jsx("p",{children:e("aboutReportBugDescription")})]}),r.jsx("a",{href:"https://github.com/kzahel/yepanywhere/issues",target:"_blank",rel:"noopener noreferrer",className:"settings-button",children:e("aboutReportBug")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutSetupWizardTitle")}),r.jsx("p",{children:e("aboutSetupWizardDescription")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:g,children:e("aboutLaunchWizard")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutDiagnosticsTitle")}),r.jsx("p",{children:e("aboutDiagnosticsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:v,onChange:P=>b(P.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]})]})}const Lb=1e4;function EZ(){const{t:e}=xt(),{settings:t,isLoading:s,error:i,updateSetting:l}=io(),[c,d]=h.useState(""),[f,m]=h.useState(!1),[g,v]=h.useState(!1),[b,w]=h.useState(null);h.useEffect(()=>{t&&d(t.globalInstructions??"")},[t]);const _=h.useCallback(async()=>{m(!0),w(null);try{await l("globalInstructions",c.trim()||void 0),v(!1)}catch(S){w(S instanceof Error?S.message:e("agentContextSaveFailed"))}finally{m(!1)}},[c,l,e]);if(s)return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("agentContextTitle")}),r.jsx("p",{className:"settings-section-description",children:e("agentContextLoading")})]});const C=(t==null?void 0:t.globalInstructions)??"";return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("agentContextTitle")}),r.jsx("p",{className:"settings-section-description",children:e("agentContextDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",style:{flexDirection:"column",alignItems:"stretch"},children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("agentContextGlobalInstructions")}),r.jsx("p",{children:e("agentContextGlobalInstructionsDescription")})]}),r.jsx("textarea",{className:"settings-textarea",value:c,onChange:S=>{const N=S.target.value.slice(0,Lb);d(N),v(N!==C),w(null)},placeholder:e("agentContextPlaceholder"),rows:10}),r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"var(--space-2)"},children:[r.jsx("span",{className:"settings-hint",children:e("agentContextCharacters",{current:c.length.toLocaleString(),max:Lb.toLocaleString()})}),r.jsx("button",{type:"button",className:"settings-button",disabled:!g||f,onClick:_,children:e(f?"providersSaving":"providersSave")})]}),(b||i)&&r.jsx("p",{className:"settings-warning",children:b||i})]})})]})}function NZ(){const{locale:e,setLocale:t,t:s}=xt(),{fontSize:i,setFontSize:l}=zF(),{tabSize:c,setTabSize:d}=FF(),{theme:f,setTheme:m}=i0(),{streamingEnabled:g,setStreamingEnabled:v}=iZ(),{funPhrasesEnabled:b,setFunPhrasesEnabled:w}=wq(),{showConnectionBars:_,setShowConnectionBars:C}=Hi(),S=N=>s(N);return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:s("appearanceSectionTitle")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceLanguageTitle")}),r.jsx("p",{children:s("appearanceLanguageDescription")})]}),r.jsx("select",{className:"settings-select",value:e,onChange:N=>t(N.target.value),"aria-label":s("appearanceLanguageTitle"),children:Xy.map(N=>r.jsx("option",{value:N,children:vZ(N,S)},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceThemeTitle")}),r.jsx("p",{children:s("appearanceThemeDescription")})]}),r.jsx("div",{className:"font-size-selector",children:Ph.map(N=>r.jsx("button",{type:"button",className:`font-size-option ${f===N?"active":""}`,onClick:()=>m(N),children:gZ(N,S)},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceFontSizeTitle")}),r.jsx("p",{children:s("appearanceFontSizeDescription")})]}),r.jsx("div",{className:"font-size-selector",children:g0.map(N=>r.jsx("button",{type:"button",className:`font-size-option ${i===N?"active":""}`,onClick:()=>l(N),children:xZ(N,S)},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceTabSizeTitle")}),r.jsx("p",{children:s("appearanceTabSizeDescription")})]}),r.jsx("div",{className:"font-size-selector",children:b0.map(N=>r.jsx("button",{type:"button",className:`font-size-option ${c===N?"active":""}`,onClick:()=>d(N),children:N},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceStreamingTitle")}),r.jsx("p",{children:s("appearanceStreamingDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:N=>v(N.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceFunPhrasesTitle")}),r.jsx("p",{children:s("appearanceFunPhrasesDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:b,onChange:N=>w(N.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceConnectionBarsTitle")}),r.jsx("p",{children:s("appearanceConnectionBarsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:_,onChange:N=>C(N.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]})]})}function _Z(){const{t:e}=xt(),{isManualReloadMode:t,pendingReloads:s,connected:i,reloadBackend:l,unsafeToRestart:c,workerActivity:d}=Bh(),{settings:f,setEnabled:m}=c0(),{holdModeEnabled:g,setHoldModeEnabled:v}=Hi(),{ignoredTools:b,clearIgnoredTools:w}=es(),{settings:_,updateSetting:C}=io(),[S,N]=h.useState(!1);h.useEffect(()=>{S&&i&&N(!1)},[S,i]);const T=async()=>{N(!0),await l()};return t?r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("developmentSectionTitle")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentSchemaTitle")}),r.jsx("p",{children:e("developmentSchemaDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:f.enabled,onChange:k=>m(k.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),b.length>0&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentIgnoredToolsTitle")}),r.jsx("p",{children:e("developmentIgnoredToolsDescription")}),r.jsx("div",{className:"ignored-tools-list",children:b.map(k=>r.jsx("span",{className:"ignored-tool-badge",children:k},k))})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-secondary",onClick:w,children:e("developmentClearIgnored")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentHoldModeTitle")}),r.jsx("p",{children:e("developmentHoldModeDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:k=>v(k.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentServiceWorkerTitle")}),r.jsx("p",{children:e("developmentServiceWorkerDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(_==null?void 0:_.serviceWorkerEnabled)??!0,onChange:k=>C("serviceWorkerEnabled",k.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentRestartTitle")}),r.jsxs("p",{children:[e("developmentRestartDescription"),s.backend&&r.jsxs("span",{className:"settings-pending",children:[" ",e("developmentChangesPending")]})]}),c&&r.jsx("p",{className:"settings-warning",children:e("developmentInterruptedWarning",{count:d.activeWorkers,suffix:d.activeWorkers!==1?"s ":" "})})]}),r.jsx("button",{type:"button",className:`settings-button ${c?"settings-button-danger":""}`,onClick:T,disabled:S,children:e(S?"developmentRestarting":c?"developmentRestartAnyway":"developmentRestart")})]})})]}):null}function CZ(){const[e,t]=h.useState({profiles:[],isLoading:!0,error:null}),s=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{profiles:l}=await Re.getBrowserProfiles();t({profiles:l,isLoading:!1,error:null})}catch(l){console.error("[useBrowserProfiles] Failed to fetch:",l),t(c=>({...c,isLoading:!1,error:l instanceof Error?l.message:"Failed to load profiles"}))}},[]);h.useEffect(()=>{s()},[s]);const i=h.useCallback(async l=>{t(c=>({...c,isLoading:!0,error:null}));try{await Re.deleteBrowserProfile(l),await s()}catch(c){console.error("[useBrowserProfiles] Failed to delete:",c),t(d=>({...d,isLoading:!1,error:c instanceof Error?c.message:"Failed to delete profile"}))}},[s]);return{...e,deleteProfile:i,refetch:s}}function xS(){const[e,t]=h.useState({connections:new Map,isLoading:!0,error:null}),s=h.useCallback(async()=>{t(i=>({...i,isLoading:!0,error:null}));try{const{connections:i}=await Re.getConnections(),l=new Map;for(const c of i)l.set(c.browserProfileId,c);t({connections:l,isLoading:!1,error:null})}catch(i){console.error("[useConnectedDevices] Failed to fetch:",i),t(l=>({...l,isLoading:!1,error:i instanceof Error?i.message:"Failed to load connections"}))}},[]);return h.useEffect(()=>{s()},[s]),h.useEffect(()=>{const i=En.on("browser-tab-connected",f=>{t(m=>{var v;const g=new Map(m.connections);return g.set(f.browserProfileId,{browserProfileId:f.browserProfileId,connectionCount:f.tabCount,connectedAt:f.timestamp,deviceName:(v=m.connections.get(f.browserProfileId))==null?void 0:v.deviceName}),{...m,connections:g}})}),l=En.on("browser-tab-disconnected",f=>{t(m=>{const g=new Map(m.connections);if(f.tabCount===0)g.delete(f.browserProfileId);else{const v=g.get(f.browserProfileId);v&&g.set(f.browserProfileId,{...v,connectionCount:f.tabCount})}return{...m,connections:g}})}),c=En.on("reconnect",()=>{s()}),d=En.on("refresh",()=>{s()});return()=>{i(),l(),c(),d()}},[s]),{...e,connectionList:Array.from(e.connections.values()),refetch:s}}const kZ="/sw.js";function sm(){const[e,t]=h.useState({isSupported:!1,isSubscribed:!1,isLoading:!0,error:null,permission:"default",browserProfileId:null}),[s,i]=h.useState(null),l=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;h.useEffect(()=>{(async()=>{if(!l){const b=Po("browserProfileId",Ss.browserProfileId);t(w=>({...w,isSupported:!1,isLoading:!1,error:"Push notifications not supported in this browser",browserProfileId:b}));return}try{const b=await navigator.serviceWorker.register(kZ);i(b),await navigator.serviceWorker.ready;const w=await b.pushManager.getSubscription(),_=Fa();t({isSupported:!0,isSubscribed:!!w,isLoading:!1,error:null,permission:Notification.permission,browserProfileId:_})}catch(b){console.error("[usePushNotifications] Init error:",b),t(w=>({...w,isSupported:!0,isLoading:!1,error:b instanceof Error?b.message:"Failed to initialize"}))}})()},[l]);const c=h.useCallback(async()=>{if(!s){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await Notification.requestPermission();if(t(N=>({...N,permission:v})),v!=="granted"){t(N=>({...N,isLoading:!1,error:"Notification permission denied"}));return}const{publicKey:b}=await Re.getPushPublicKey(),w=TZ(b),_=await s.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:w.buffer}),C=Fa(),S=_.toJSON();await Re.subscribePush(C,S,AZ()),t(N=>({...N,isSubscribed:!0,isLoading:!1,error:null,browserProfileId:C}))}catch(v){console.error("[usePushNotifications] Subscribe error:",v),t(b=>({...b,isLoading:!1,error:v instanceof Error?v.message:"Failed to subscribe"}))}},[s]),d=h.useCallback(async()=>{if(!s){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await s.pushManager.getSubscription();v&&await v.unsubscribe();const b=Fa();await Re.unsubscribePush(b),t(w=>({...w,isSubscribed:!1,isLoading:!1,error:null}))}catch(v){console.error("[usePushNotifications] Unsubscribe error:",v),t(b=>({...b,isLoading:!1,error:v instanceof Error?v.message:"Failed to unsubscribe"}))}},[s]),f=h.useCallback(async(v="normal")=>{const b=Fa();t(w=>({...w,isLoading:!0,error:null}));try{await Re.testPush(b,void 0,v),t(w=>({...w,isLoading:!1}))}catch(w){console.error("[usePushNotifications] Test push error:",w),t(_=>({..._,isLoading:!1,error:w instanceof Error?w.message:"Failed to send test"}))}},[]),m=h.useCallback(async()=>{var b;const v=(b=navigator.serviceWorker)==null?void 0:b.controller;return v?new Promise(w=>{const _=new MessageChannel;_.port1.onmessage=C=>{var S;w(((S=C.data)==null?void 0:S.logs)||[])},v.postMessage({type:"get-sw-logs"},[_.port2]),setTimeout(()=>w([]),2e3)}):(console.warn("[usePushNotifications] No active service worker"),[])},[]),g=h.useCallback(async()=>{var b;const v=(b=navigator.serviceWorker)==null?void 0:b.controller;if(v)return new Promise(w=>{const _=new MessageChannel;_.port1.onmessage=()=>w(),v.postMessage({type:"clear-sw-logs"},[_.port2]),setTimeout(w,1e3)})},[]);return{...e,subscribe:c,unsubscribe:d,sendTest:f,getSwLogs:m,clearSwLogs:g}}function TZ(e){const t="=".repeat((4-e.length%4)%4),s=(e+t).replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(s),l=new Uint8Array(i.length);for(let c=0;c<i.length;++c)l[c]=i.charCodeAt(c);return l}function AZ(){const e=navigator.userAgent;return/iPhone/.test(e)?"iPhone":/iPad/.test(e)?"iPad":/Android/.test(e)?"Android":/Mac/.test(e)?"Mac":/Windows/.test(e)?"Windows":/Linux/.test(e)?"Linux":"Browser"}function Ob(e,t){const s=new Date(e),l=new Date().getTime()-s.getTime(),c=Math.floor(l/(1e3*60)),d=Math.floor(l/(1e3*60*60)),f=Math.floor(l/(1e3*60*60*24));return c<1?t("devicesJustNow"):c<60?t("devicesMinutesAgo",{count:c,suffix:c===1?"":"s"}):d<24?t("devicesHoursAgo",{count:d,suffix:d===1?"":"s"}):f===1?t("devicesYesterday"):f<7?`${f} days ago`:s.toLocaleDateString()}function RZ(){const{t:e}=xt(),{profiles:t,isLoading:s,error:i,deleteProfile:l}=CZ(),{browserProfileId:c}=sm(),{connections:d}=xS();return r.jsx(r.Fragment,{children:r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("devicesProfilesTitle")}),r.jsx("p",{className:"settings-section-description",children:e("devicesProfilesDescription")}),i&&r.jsx("p",{className:"form-error",children:i}),r.jsx("div",{className:"settings-group",children:s?r.jsx("p",{className:"settings-hint",children:e("devicesLoadingProfiles")}):t.length===0?r.jsx("p",{className:"settings-hint",children:e("devicesEmpty")}):r.jsx("div",{className:"device-list",children:t.map(f=>{const m=f.browserProfileId===c,g=d.has(f.browserProfileId),v=f.deviceName||`${f.browserProfileId.slice(0,8)}...`;return r.jsxs("div",{className:"device-list-item device-profile-item",children:[r.jsxs("div",{className:"device-list-info",children:[r.jsxs("strong",{children:[r.jsx("span",{className:`device-status ${g?"device-status-online":"device-status-offline"}`,title:e(g?"devicesConnected":"devicesDisconnected")}),v,m&&r.jsx("span",{className:"device-current-badge",children:e("devicesThisDevice")})]}),r.jsx("div",{className:"device-origins",children:f.origins.map(b=>{const{browser:w,os:_}=s0(b.userAgent);return r.jsxs("div",{className:"device-origin",children:[r.jsx("code",{className:"device-origin-url",children:b.origin}),r.jsxs("span",{className:"device-origin-details",children:[w," · ",_]}),r.jsx("span",{className:"device-origin-time",children:e("devicesLastSeen",{date:Ob(b.lastSeen,e)})})]},b.origin)})}),r.jsx("p",{className:"device-profile-meta",children:e("devicesFirstSeen",{date:Ob(f.createdAt,e)})})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>l(f.browserProfileId),title:e("devicesForgetThisDevice"),children:e("devicesForget")})]},f.browserProfileId)})})})]})})}const MZ=["high","medium","low"];function DZ(e,t,s){return s!=null&&s.length?s.includes("start"):e==="emulator"&&t==="stopped"}function LZ(e,t,s){return s!=null&&s.length?s.includes("stop"):e==="emulator"&&t!=="stopped"}function OZ(){const{t:e}=xt(),{emulators:t,loading:s,error:i,startEmulator:l,stopEmulator:c,refresh:d}=D0(),{maxFps:f,setMaxFps:m,maxWidth:g,setMaxWidth:v,quality:b,setQuality:w,adaptiveFps:_,setAdaptiveFps:C}=M0(),{settings:S,isLoading:N,error:T,updateSetting:k}=io(),[A,P]=h.useState(""),[U,O]=h.useState(null),z=(S==null?void 0:S.chromeOsHosts)??[],q=async()=>{const I=A.trim();if(!I){O(e("emulatorHostAliasRequired"));return}if(/\s/.test(I)){O(e("emulatorHostAliasNoSpaces"));return}const B=Array.from(new Set([...z,I]));try{await k("chromeOsHosts",B),P(""),O(null),await d()}catch(Z){O(Z instanceof Error?Z.message:e("emulatorHostAliasSaveFailed"))}},oe=async I=>{const B=z.filter(Z=>Z.toLowerCase()!==I.toLowerCase());try{await k("chromeOsHosts",B),O(null),await d()}catch(Z){O(Z instanceof Error?Z.message:e("emulatorHostAliasRemoveFailed"))}},K=(S==null?void 0:S.deviceBridgeEnabled)??!1;return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("emulatorSectionTitle")}),r.jsx("p",{className:"settings-description",children:e("emulatorSectionDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorEnableTitle")}),r.jsx("p",{children:e("emulatorEnableDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:K,onChange:I=>{k("deviceBridgeEnabled",I.target.checked)},disabled:N}),r.jsx("span",{className:"toggle-slider"})]})]})}),K?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("emulatorStreamQualityTitle")}),r.jsx("p",{className:"settings-description",children:e("emulatorStreamQualityDescription")}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorFrameRateTitle")}),r.jsx("p",{children:e("emulatorFrameRateDescription")})]}),r.jsx("div",{className:"font-size-selector",children:_0.map(I=>r.jsxs("button",{type:"button",className:`font-size-option ${f===I?"active":""}`,onClick:()=>m(I),children:[I," fps"]},I))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorResolutionTitle")}),r.jsx("p",{children:e("emulatorResolutionDescription")})]}),r.jsx("div",{className:"font-size-selector",children:C0.map(I=>r.jsxs("button",{type:"button",className:`font-size-option ${g===I?"active":""}`,onClick:()=>v(I),children:[I,"p"]},I))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorQualityTitle")}),r.jsx("p",{children:e("emulatorQualityDescription")})]}),r.jsx("div",{className:"font-size-selector",children:MZ.map(I=>r.jsx("button",{type:"button",className:`font-size-option ${b===I?"active":""}`,onClick:()=>w(I),children:FH(I)},I))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorAdaptiveFpsTitle")}),r.jsx("p",{children:e("emulatorAdaptiveFpsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:_,onChange:I=>C(I.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("emulatorChromeOsHostsTitle")}),r.jsxs("p",{className:"settings-description",children:[e("emulatorChromeOsHostsDescription"),r.jsx("code",{children:" chromeroot"}),e("emulatorChromeOsHostsDescriptionSuffix")]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorAddHostAliasTitle")}),r.jsx("p",{children:e("emulatorAddHostAliasDescription")})]}),r.jsxs("form",{className:"settings-item-actions",onSubmit:I=>{I.preventDefault(),q()},children:[r.jsx("input",{type:"text",name:"chromeosHost",placeholder:e("emulatorHostAliasPlaceholder"),className:"settings-select",autoComplete:"off",value:A,onChange:I=>P(I.target.value)}),r.jsx("button",{type:"submit",className:"settings-button",disabled:N,children:e("projectsAddConfirm")})]})]}),U&&r.jsx("p",{className:"settings-error",children:U}),T&&r.jsx("p",{className:"settings-error",children:T}),z.length===0?r.jsx("p",{className:"settings-muted",children:e("emulatorNoChromeOsHosts")}):z.map(I=>r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("span",{className:"settings-item-label",children:I}),r.jsxs("span",{className:"settings-item-description",children:["Device ID: chromeos:",I]})]}),r.jsx("div",{className:"settings-item-action",children:r.jsx("button",{type:"button",className:"settings-button",onClick:()=>{oe(I)},disabled:N,children:e("emulatorRemove")})})]},I))]}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("emulatorDiscoveredDevicesTitle")}),s&&r.jsx("p",{className:"settings-muted",children:e("projectsLoading")}),i&&r.jsx("p",{className:"settings-error",children:i}),!s&&t.length===0&&r.jsx("p",{className:"settings-muted",children:e("emulatorNoDevicesFound")}),t.map(I=>r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("span",{className:"settings-item-label",children:I.label||I.avd||I.id}),r.jsxs("span",{className:"settings-item-description",children:[I.type," - ",I.id," - ",I.state]})]}),r.jsx("div",{className:"settings-item-action",children:LZ(I.type,I.state,I.actions)?r.jsx("button",{type:"button",className:"settings-button",onClick:()=>c(I.id),children:e("emulatorStop")}):DZ(I.type,I.state,I.actions)?r.jsx("button",{type:"button",className:"settings-button",onClick:()=>l(I.id),children:e("emulatorStart")}):null})]},I.id))]})]}):null]})}const UZ=2e3,PZ=5e3;function IZ(){const{t:e}=xt(),{settings:t,isLoading:s,error:i,updateSetting:l}=io(),[c,d]=h.useState(""),[f,m]=h.useState(""),[g,v]=h.useState(!1),[b,w]=h.useState(!1),[_,C]=h.useState(null);h.useEffect(()=>{t&&(d(t.lifecycleWebhookUrl??""),m(t.lifecycleWebhookToken??""))},[t]);const S=h.useCallback(async()=>{v(!0),C(null);try{await Promise.all([l("lifecycleWebhookUrl",c.trim()||void 0),l("lifecycleWebhookToken",f.trim()||void 0)]),w(!1)}catch(P){C(P instanceof Error?P.message:e("lifecycleWebhooksSaveFailed"))}finally{v(!1)}},[e,f,l,c]);if(s)return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("lifecycleWebhooksTitle")}),r.jsx("p",{className:"settings-section-description",children:e("lifecycleWebhooksLoading")})]});const N=(t==null?void 0:t.lifecycleWebhookUrl)??"",T=(t==null?void 0:t.lifecycleWebhookToken)??"",k=(t==null?void 0:t.lifecycleWebhooksEnabled)??!1,A=(t==null?void 0:t.lifecycleWebhookDryRun)??!0;return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("lifecycleWebhooksTitle")}),r.jsx("p",{className:"settings-section-description",children:e("lifecycleWebhooksDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("label",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksEnableTitle")}),r.jsx("p",{children:e("lifecycleWebhooksEnableDescription")})]}),r.jsx("input",{type:"checkbox",checked:k,onChange:P=>void l("lifecycleWebhooksEnabled",P.target.checked)})]}),r.jsxs("div",{className:"settings-item",style:{flexDirection:"column",alignItems:"stretch"},children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksUrlTitle")}),r.jsx("p",{children:e("lifecycleWebhooksUrlDescription")})]}),r.jsx("input",{type:"url",className:"settings-input",value:c,onChange:P=>{const U=P.target.value.slice(0,UZ);d(U),w(U!==N||f!==T),C(null)},placeholder:"https://example.com/hooks/yep"})]}),r.jsxs("div",{className:"settings-item",style:{flexDirection:"column",alignItems:"stretch"},children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksTokenTitle")}),r.jsx("p",{children:e("lifecycleWebhooksTokenDescription")})]}),r.jsx("input",{type:"password",className:"settings-input",value:f,onChange:P=>{const U=P.target.value.slice(0,PZ);m(U),w(c!==N||U!==T),C(null)},placeholder:e("lifecycleWebhooksTokenPlaceholder")})]}),r.jsxs("label",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksDryRunTitle")}),r.jsx("p",{children:e("lifecycleWebhooksDryRunDescription")})]}),r.jsx("input",{type:"checkbox",checked:A,onChange:P=>void l("lifecycleWebhookDryRun",P.target.checked)})]}),r.jsx("div",{className:"settings-item",style:{justifyContent:"flex-end",gap:"var(--space-2)"},children:r.jsx("button",{type:"button",className:"settings-button",disabled:!b||g,onClick:S,children:e(g?"providersSaving":"providersSave")})}),(_||i)&&r.jsx("p",{className:"settings-warning",children:_||i})]})]})}function zZ(){const[e,t]=h.useState(null),[s,i]=h.useState(!0),[l,c]=h.useState(null),[d,f]=h.useState(!1),m=h.useRef(!1),g=h.useCallback(async()=>{i(!0),c(null);try{const w=await Re.getNetworkBinding();t(w)}catch(w){c(w instanceof Error?w:new Error(String(w)))}finally{i(!1)}},[]);h.useEffect(()=>{m.current||(m.current=!0,g())},[g]);const v=h.useCallback(async w=>{f(!0),c(null);try{const _=await Re.setNetworkBinding(w);if(!_.success)throw new Error(_.error??"Failed to update binding");return await g(),{redirectUrl:_.redirectUrl}}catch(_){const C=_ instanceof Error?_:new Error(String(_));throw c(C),C}finally{f(!1)}},[g]),b=h.useCallback(async()=>{f(!0),c(null);try{const w=await Re.disableNetworkBinding();if(!w.success)throw new Error(w.error??"Failed to disable network socket");await g()}catch(w){const _=w instanceof Error?w:new Error(String(w));throw c(_),_}finally{f(!1)}},[g]);return{binding:e,loading:s,error:l,applying:d,updateBinding:v,disableNetwork:b,refetch:g}}function $Z(){const[e,t]=h.useState(null),[s,i]=h.useState(!0),[l,c]=h.useState(null),d=h.useRef(!1),f=h.useCallback(async()=>{i(!0),c(null);try{const m=await Re.getServerInfo();t(m)}catch(m){c(m instanceof Error?m:new Error(String(m)))}finally{i(!1)}},[]);return h.useEffect(()=>{d.current||(d.current=!0,f())},[f]),{serverInfo:e,loading:s,error:l,refetch:f}}function BZ(){const{t:e}=xt(),t=dF(),s=Vi(),{relayDebugEnabled:i,setRelayDebugEnabled:l}=Hi(),{serverInfo:c,loading:d}=$Z(),{binding:f,loading:m,applying:g,updateBinding:v}=zZ(),{settings:b,isLoading:w}=io(),[_,C]=h.useState(""),[S,N]=h.useState(!1),[T,k]=h.useState(""),[A,P]=h.useState(""),[U,O]=h.useState(!1),[z,q]=h.useState(!1),[oe,K]=h.useState(""),[I,B]=h.useState(""),[Z,Q]=h.useState(!1),[ae,W]=h.useState(""),[Y,V]=h.useState(null),[ne,ge]=h.useState(!1),[$,G]=h.useState(!1),[le,fe]=h.useState(!1);if(f&&t&&b&&!le){C(String(f.localhost.port)),N(f.network.enabled),k(f.network.host??""),O(t.authEnabled),q(t.localhostOpen);const De=b.allowedHosts;De==="*"?(Q(!0),W("")):(Q(!1),W(De??"")),fe(!0)}const ue=(De,vt)=>De?"*":vt.trim()||void 0,_e=(De,vt,me,We,ot,ut,$e,Et)=>{if(!f||!t||!b)return!1;const Oe=De!==String(f.localhost.port),Ot=vt!==f.network.enabled,Tt=me!==(f.network.host??""),Sn=We!==t.authEnabled,In=ot.length>0,pn=Et!==t.localhostOpen,Nn=ue(ut,$e),Jt=b.allowedHosts;return Oe||Ot||Tt||Sn||In||pn||(Nn??"")!==(Jt??"")},Ke=De=>{ge(_e(De.port??_,De.networkEnabled??S,De.iface??T,De.requirePw??U,De.password??oe,De.allowAll??Z,De.hostsText??ae,De.localhostOpen??z))},tt=async()=>{if(!t)return;V(null);const De=Number.parseInt(_,10);if(Number.isNaN(De)||De<1||De>65535){V(e("localAccessErrorPortRange"));return}const vt=U&&!t.authEnabled,me=U&&t.authEnabled&&oe.length>0;if(vt||me){if(oe.length<6){V(e("localAccessErrorPasswordLength"));return}if(oe!==I){V(e("localAccessErrorPasswordMismatch"));return}}const We=T==="custom"?A:T;G(!0);try{const ot={};f!=null&&f.localhost.overriddenByCli||(ot.localhostPort=De),f!=null&&f.network.overriddenByCli||(ot.network={enabled:S,host:S?We:void 0});const ut=await v(ot);vt?(await t.enableAuth(oe),K(""),B("")):me?(await t.changePassword(oe),K(""),B("")):!U&&t.authEnabled&&await t.disableAuth(),z!==t.localhostOpen&&await t.setLocalhostOpen(z);const $e=ue(Z,ae);if(await Re.updateServerSettings({allowedHosts:$e??""}),ut.redirectUrl){const Et=new URL(ut.redirectUrl);Et.pathname=window.location.pathname,Et.search=window.location.search,window.location.href=Et.toString()}else ge(!1)}catch(ot){V(ot instanceof Error?ot.message:e("localAccessErrorApplyFailed"))}finally{G(!1)}};if(t){if(d||m||w||t.isLoading||!le)return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("settingsLocalAccessTitle")}),r.jsx("p",{className:"settings-section-description",children:e("localAccessLoading")})]});const vt=U;return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("settingsLocalAccessTitle")}),r.jsx("p",{className:"settings-section-description",children:e("localAccessDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessStatusTitle")}),r.jsx("p",{children:c?(()=>{const me=f==null?void 0:f.network.host,We=(f==null?void 0:f.network.port)??c.port,ot=me==="0.0.0.0"||me==="::",ut=We===c.port;return f!=null&&f.network.enabled&&ot&&ut?r.jsxs(r.Fragment,{children:[e("localAccessListeningOn")," ",r.jsxs("code",{children:[me,":",We]})]}):r.jsxs(r.Fragment,{children:[e("localAccessListeningOn")," ",r.jsxs("code",{children:[c.host,":",c.port]}),(f==null?void 0:f.network.enabled)&&me&&r.jsxs(r.Fragment,{children:[" ",e("localAccessListeningAnd")," ",r.jsxs("code",{children:[me,":",We]})]})]})})():e("localAccessUnableToFetch")})]}),(c==null?void 0:c.localhostOnly)&&!(f!=null&&f.network.enabled)&&r.jsx("span",{className:"settings-status-badge settings-status-detected",children:e("localAccessBadgeLocalOnly")}),((c==null?void 0:c.boundToAllInterfaces)||(f==null?void 0:f.network.enabled))&&!t.authEnabled&&r.jsx("span",{className:"settings-status-badge settings-status-warning",children:e("localAccessBadgeNetworkExposed")})]})}),r.jsxs("form",{className:"settings-group",onSubmit:me=>{me.preventDefault(),tt()},children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessListeningPortTitle")}),r.jsx("p",{children:e("localAccessListeningPortDescription")})]}),f!=null&&f.localhost.overriddenByCli?r.jsxs("span",{className:"settings-value-readonly",children:[f.localhost.port," ",r.jsx("span",{className:"settings-hint",children:e("localAccessSetViaPort")})]}):r.jsx("input",{type:"number",className:"settings-input-small",value:_,onChange:me=>{C(me.target.value),Ke({port:me.target.value})},min:1,max:65535,autoComplete:"off"})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessNetworkTitle")}),r.jsx("p",{children:e("localAccessNetworkDescription")})]}),f!=null&&f.network.overriddenByCli?r.jsxs("span",{className:"settings-value-readonly",children:[f.network.host,":",f.network.port," ",r.jsx("span",{className:"settings-hint",children:e("localAccessSetViaHost")})]}):r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:me=>{N(me.target.checked),Ke({networkEnabled:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),S&&!(f!=null&&f.network.overriddenByCli)&&f&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessInterfaceTitle")}),r.jsx("p",{children:e("localAccessInterfaceDescription")})]}),r.jsx(dr,{label:e("localAccessInterfaceTitle"),placeholder:e("localAccessInterfacePlaceholder"),multiSelect:!1,align:"right",options:[...f.interfaces.map(me=>({value:me.address,label:me.displayName})),{value:"0.0.0.0",label:e("localAccessInterfaceAll")},{value:"custom",label:e("localAccessInterfaceCustom")}],selected:T?[T]:[],onChange:me=>{const We=me[0]??"";k(We),Ke({iface:We})}})]}),S&&!(f!=null&&f.network.overriddenByCli)&&T==="custom"&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessCustomIpTitle")}),r.jsx("p",{children:e("localAccessCustomIpDescription")})]}),r.jsx("input",{type:"text",className:"settings-input",placeholder:"192.168.1.100",value:A,onChange:me=>P(me.target.value)})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessAllowAllHostsTitle")}),r.jsx("p",{children:e("localAccessAllowAllHostsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:Z,onChange:me=>{Q(me.target.checked),Ke({allowAll:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),!Z&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessAllowedHostsTitle")}),r.jsx("p",{children:e("localAccessAllowedHostsDescription")})]}),r.jsx("input",{type:"text",className:"settings-input",placeholder:e("localAccessAllowedHostsPlaceholder"),value:ae,onChange:me=>{W(me.target.value),Ke({hostsText:me.target.value})}})]}),r.jsx("p",{className:"form-hint",children:e("localAccessAllowedHostsHint")}),!t.authDisabledByEnv&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessRequirePasswordTitle")}),r.jsx("p",{children:e("localAccessRequirePasswordDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:U,onChange:me=>{O(me.target.checked),Ke({requirePw:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),vt&&r.jsxs(r.Fragment,{children:[r.jsx("input",{type:"text",name:"username",autoComplete:"username",style:{position:"absolute",visibility:"hidden",pointerEvents:"none"},tabIndex:-1}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessPasswordTitle")}),r.jsx("p",{children:t.authEnabled?e("localAccessPasswordKeepCurrent"):e("localAccessPasswordMinLength")})]}),r.jsx("input",{type:"password",className:"settings-input",value:oe,onChange:me=>{K(me.target.value),Ke({password:me.target.value})},autoComplete:"new-password",placeholder:t.authEnabled?e("localAccessPasswordNewPlaceholder"):e("localAccessPasswordPlaceholder")})]}),oe.length>0&&r.jsxs("div",{className:"settings-item",children:[r.jsx("div",{className:"settings-item-info",children:r.jsx("strong",{children:e("localAccessConfirmPasswordTitle")})}),r.jsx("input",{type:"password",className:"settings-input",value:I,onChange:me=>B(me.target.value),autoComplete:"new-password",placeholder:e("localAccessConfirmPasswordPlaceholder")})]}),!t.authEnabled&&r.jsx("p",{className:"form-hint",children:e("localAccessPasswordResetHint")})]}),t.hasDesktopToken&&!U&&!t.authDisabledByEnv&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessLocalhostOpenTitle")}),r.jsx("p",{children:e("localAccessLocalhostOpenDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:z,onChange:me=>{q(me.target.checked),Ke({localhostOpen:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),t.authDisabledByEnv&&r.jsx("p",{className:"form-warning",children:e("localAccessAuthDisabled")}),r.jsxs("div",{className:"settings-item",children:[Y&&r.jsx("p",{className:"form-error",children:Y}),r.jsx("button",{type:"submit",className:"settings-button",disabled:!ne||$||g,children:e($||g?"localAccessApplying":"localAccessApply")})]})]}),t.authEnabled&&t.isAuthenticated&&r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessLogoutTitle")}),r.jsx("p",{children:e("localAccessLogoutDescription")})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:t.logout,children:e("remoteAccessLogout")})]})})]})}return s?r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("settingsLocalAccessTitle")}),r.jsx("p",{className:"settings-section-description",children:e("localAccessRemoteDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessLogoutTitle")}),r.jsx("p",{children:e("localAccessRemoteLogoutDescription")})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>s.disconnect(),children:e("remoteAccessLogout")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessRelayDebugTitle")}),r.jsx("p",{children:e("localAccessRelayDebugDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:i,onChange:De=>l(De.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]})]}):null}function FZ(){const{t:e}=xt(),{model:t,setModel:s,effortLevel:i,setEffortLevel:l}=au();return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("modelSettingsTitle")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("modelSettingsModelTitle")}),r.jsx("p",{children:e("modelSettingsModelDescription")})]}),r.jsx("div",{className:"font-size-selector",children:Yc.map(c=>r.jsx("button",{type:"button",className:`font-size-option ${t===c.value?"active":""}`,onClick:()=>s(c.value),children:c.label},c.value))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("modelSettingsEffortTitle")}),r.jsx("p",{children:e("modelSettingsEffortDescription")})]}),r.jsx("div",{className:"font-size-selector",children:H9.map(c=>r.jsx("button",{type:"button",className:`font-size-option ${i===c.value?"active":""}`,onClick:()=>l(c.value),title:c.description,children:c.label},c.value))})]})]})]})}function vS(){const[e,t]=h.useState(()=>{const l=typeof window<"u"&&"Notification"in window,c=K9();return{isSupported:l&&!c,isMobile:c,permission:l?Notification.permission:"denied",isRequesting:!1}});h.useEffect(()=>{if(!e.isSupported)return;const l=()=>{const c=Notification.permission;c!==e.permission&&t(d=>({...d,permission:c}))};return window.addEventListener("focus",l),()=>window.removeEventListener("focus",l)},[e.isSupported,e.permission]);const s=h.useCallback(async()=>{if(e.isSupported&&e.permission!=="granted"){t(l=>({...l,isRequesting:!0}));try{const l=await Notification.requestPermission();t(c=>({...c,permission:l,isRequesting:!1}))}catch(l){console.error("[useBrowserNotifications] Permission request failed:",l),t(c=>({...c,isRequesting:!1}))}}},[e.isSupported,e.permission]),i=h.useCallback((l,c)=>{if(!e.isSupported||e.permission!=="granted")return!1;try{return new Notification(l,c),!0}catch(d){return console.error("[useBrowserNotifications] Failed to show notification:",d),!1}},[e.isSupported,e.permission]);return{...e,isEnabled:e.permission==="granted",isDenied:e.permission==="denied",requestPermission:s,showNotification:i}}function HZ(){const{t:e}=xt(),{isSupported:t,isMobile:s,isEnabled:i,isDenied:l,isRequesting:c,requestPermission:d,showNotification:f}=vS();if(s)return null;if(!t)return r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:"Desktop Notifications"}),r.jsx("p",{children:e("browserToggleUnsupported")})]})});if(l)return r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTitle")}),r.jsx("p",{className:"settings-warning",children:e("browserToggleBlocked")})]})});if(i){const m=()=>{f(e("browserToggleTestNotification"),{body:e("browserToggleTestBody"),icon:"/icon-192.png"})};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTitle")}),r.jsx("p",{children:e("browserToggleEnabled")})]}),r.jsx("span",{className:"settings-badge settings-badge-success",children:e("browserToggleEnabledBadge")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTestTitle")}),r.jsx("p",{children:e("browserToggleTestDescription")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:m,children:e("pushToggleSendTest")})]})]})}return r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTitle")}),r.jsx("p",{children:e("browserToggleDescription")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:d,disabled:c,children:e(c?"browserToggleRequesting":"browserToggleEnable")})]})}function qZ(){const{t:e}=xt(),{isSupported:t,isSubscribed:s,isLoading:i,error:l,permission:c,subscribe:d,unsubscribe:f,sendTest:m}=sm(),{notifyInApp:g,setNotifyInApp:v}=EF(),[b,w]=h.useState("normal"),_=async()=>{s?await f():await d()};if(!t){const C=l==null?void 0:l.includes("Service worker disabled in dev mode");return r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTitle")}),r.jsx("p",{children:l||e("pushToggleUnsupported")}),C&&r.jsxs("div",{className:"settings-info-box",style:{marginTop:"0.5rem"},children:[r.jsx("p",{children:e("pushToggleThisDeviceOnly")}),r.jsx("p",{children:e("pushToggleDevModeHint")})]}),r.jsx("p",{style:{marginTop:"0.5rem"},children:r.jsx("a",{href:"https://github.com/kzahel/yepanywhere/blob/main/docs/push-notifications.md",target:"_blank",rel:"noopener noreferrer",children:e("pushToggleTroubleshooting")})})]})})}return c==="denied"?r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTitle")}),r.jsx("p",{className:"settings-warning",children:e("pushToggleBlocked")})]})}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTitle")}),r.jsx("p",{children:e("pushToggleDescription")}),l&&r.jsx("p",{className:"settings-error",children:l})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:s,onChange:_,disabled:i}),r.jsx("span",{className:"toggle-slider"})]})]}),s&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleNotifyInAppTitle")}),r.jsx("p",{children:e("pushToggleNotifyInAppDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:C=>v(C.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTestTitle")}),r.jsx("p",{children:e("pushToggleTestDescription")})]}),r.jsxs("div",{className:"settings-item-actions",children:[r.jsxs("select",{className:"settings-select",value:b,onChange:C=>w(C.target.value),disabled:i,children:[r.jsx("option",{value:"normal",children:e("pushToggleUrgencyNormal")}),r.jsx("option",{value:"persistent",children:e("pushToggleUrgencyPersistent")}),r.jsx("option",{value:"silent",children:e("pushToggleUrgencySilent")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:()=>m(b),disabled:i,children:e(i?"pushToggleSending":"pushToggleSendTest")})]})]})]})]})}function VZ(){const[e,t]=h.useState({settings:null,isLoading:!0,error:null});h.useEffect(()=>{(async()=>{try{const{settings:l}=await Re.getNotificationSettings();t({settings:l,isLoading:!1,error:null})}catch(l){console.error("[useNotificationSettings] Failed to fetch:",l),t(c=>({...c,isLoading:!1,error:l instanceof Error?l.message:"Failed to load settings"}))}})()},[]);const s=h.useCallback(async(i,l)=>{t(c=>({...c,isLoading:!0,error:null}));try{const{settings:c}=await Re.updateNotificationSettings({[i]:l});t({settings:c,isLoading:!1,error:null})}catch(c){console.error("[useNotificationSettings] Failed to update:",c),t(d=>({...d,isLoading:!1,error:c instanceof Error?c.message:"Failed to update"}))}},[]);return{...e,updateSetting:s}}function WZ(){const[e,t]=h.useState({devices:[],isLoading:!0,error:null}),s=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{subscriptions:l}=await Re.getPushSubscriptions();t({devices:l,isLoading:!1,error:null})}catch(l){console.error("[useSubscribedDevices] Failed to fetch:",l),t(c=>({...c,isLoading:!1,error:l instanceof Error?l.message:"Failed to load devices"}))}},[]);h.useEffect(()=>{s()},[s]);const i=h.useCallback(async l=>{t(c=>({...c,isLoading:!0,error:null}));try{await Re.deletePushSubscription(l),await s()}catch(c){console.error("[useSubscribedDevices] Failed to remove:",c),t(d=>({...d,isLoading:!1,error:c instanceof Error?c.message:"Failed to remove device"}))}},[s]);return{...e,removeDevice:i,refetch:s}}function YZ(e,t){const s=e||"Unknown device";return t!=null&&t.includes("google")?{displayName:s,browserType:"(Android/Chrome)"}:t!=null&&t.includes("apple")||t!=null&&t.includes("push.apple")?{displayName:s,browserType:"(iOS/Safari)"}:t!=null&&t.includes("mozilla")||t!=null&&t.includes("push.services.mozilla")?{displayName:s,browserType:"(Firefox)"}:{displayName:s,browserType:""}}function ZZ(e,t){const s=new Date(e),l=new Date().getTime()-s.getTime(),c=Math.floor(l/(1e3*60*60*24));return c===0?new Date().toLocaleDateString():c===1?new Date(Date.now()-864e5).toLocaleDateString():c<7?t("hostPickerLastConnectedDays",{count:c}):s.toLocaleDateString()}function GZ(e,t,s){const i=new Map;for(const c of e){const{displayName:d,browserType:f}=YZ(c.deviceName,c.endpointDomain),m=t.get(c.browserProfileId);i.set(c.browserProfileId,{browserProfileId:c.browserProfileId,displayName:d,browserType:f,isSubscribed:!0,isConnected:!!m,tabCount:(m==null?void 0:m.connectionCount)??0,subscribedAt:c.createdAt,isCurrentDevice:c.browserProfileId===s})}for(const[c,d]of t)if(!i.has(c)){const f=c.slice(0,8);i.set(c,{browserProfileId:c,displayName:f,browserType:"",isSubscribed:!1,isConnected:!0,tabCount:d.connectionCount,isCurrentDevice:c===s})}const l=Array.from(i.values());return l.sort((c,d)=>c.isCurrentDevice&&!d.isCurrentDevice?-1:!c.isCurrentDevice&&d.isCurrentDevice?1:c.isConnected&&!d.isConnected?-1:!c.isConnected&&d.isConnected?1:c.isConnected&&d.isConnected?d.tabCount-c.tabCount:c.subscribedAt&&d.subscribedAt?new Date(d.subscribedAt).getTime()-new Date(c.subscribedAt).getTime():0),l}function KZ(){const{t:e}=xt(),{browserProfileId:t}=sm(),{isMobile:s}=vS(),{devices:i,isLoading:l,removeDevice:c}=WZ(),{connections:d,isLoading:f}=xS(),{settings:m,isLoading:g,updateSetting:v}=VZ(),b=i.length>0,w=l||f,_=GZ(i,d,t);return r.jsxs(r.Fragment,{children:[r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsServerTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsServerDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("notificationsToolApprovalsTitle")}),r.jsx("p",{children:e("notificationsToolApprovalsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.toolApproval)??!0,onChange:C=>v("toolApproval",C.target.checked),disabled:g||!b}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("notificationsQuestionsTitle")}),r.jsx("p",{children:e("notificationsQuestionsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.userQuestion)??!0,onChange:C=>v("userQuestion",C.target.checked),disabled:g||!b}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("notificationsSessionHaltedTitle")}),r.jsx("p",{children:e("notificationsSessionHaltedDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.sessionHalted)??!0,onChange:C=>v("sessionHalted",C.target.checked),disabled:g||!b}),r.jsx("span",{className:"toggle-slider"})]})]}),!b&&!l&&r.jsx("p",{className:"settings-hint",children:e("notificationsNoSubscribedDevices")})]})]}),!s&&r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsDesktopTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsDesktopDescription")}),r.jsx("div",{className:"settings-group",children:r.jsx(HZ,{})})]}),r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsPushTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsPushDescription")}),r.jsx("div",{className:"settings-group",children:r.jsx(qZ,{})})]}),r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsDevicesTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsDevicesDescription")}),r.jsx("div",{className:"settings-group",children:w?r.jsx("p",{className:"settings-hint",children:e("notificationsLoadingDevices")}):_.length===0?r.jsx("p",{className:"settings-hint",children:e("notificationsNoDevices")}):r.jsx("div",{className:"device-list",children:_.map(C=>r.jsxs("div",{className:"device-list-item",children:[r.jsxs("div",{className:"device-list-info",children:[r.jsxs("strong",{children:[C.displayName,C.browserType&&` ${C.browserType}`,C.isCurrentDevice&&r.jsx("span",{className:"device-current-badge",children:e("notificationsThisDevice")})]}),r.jsxs("p",{children:[C.isConnected?r.jsx("span",{className:"device-status device-status-online",children:C.tabCount===1?e("notificationsOneTab"):e("notificationsTabs",{count:C.tabCount})}):r.jsx("span",{className:"device-status device-status-offline",children:e("notificationsOffline")}),!C.isSubscribed&&r.jsx("span",{className:"device-no-push",children:e("notificationsNoPush")}),C.subscribedAt&&r.jsx("span",{className:"device-subscribed-date",children:e("notificationsSubscribed",{date:ZZ(C.subscribedAt,e)})})]})]}),C.isSubscribed&&r.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>c(C.browserProfileId),title:C.isCurrentDevice?e("notificationsRemoveThisDevice"):e("notificationsRemoveDevice"),children:e("notificationsRemove")})]},C.browserProfileId))})})]})]})}const XZ="You are a helpful coding assistant. You help users with software engineering tasks. You have access to tools for reading files, editing files, running shell commands, and searching code. Use tools when needed to answer questions or make changes. Be concise and direct.";function QZ(){const{t:e}=xt(),{settings:t,updateSetting:s}=io(),[i,l]=h.useState(""),[c,d]=h.useState(!1),[f,m]=h.useState(!1),g=(t==null?void 0:t.ollamaUrl)??"";h.useEffect(()=>{t&&l(t.ollamaUrl??"")},[t]);const v=h.useCallback(async()=>{d(!0);try{await s("ollamaUrl",i.trim()||void 0),m(!1)}catch{}finally{d(!1)}},[i,s]);return r.jsxs("div",{style:{marginTop:"var(--space-2)",width:"100%"},children:[r.jsxs("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center"},children:[r.jsx("input",{type:"text",className:"settings-input",value:i,onChange:b=>{l(b.target.value),m(b.target.value!==g)},placeholder:"http://localhost:11434",style:{flex:1}}),r.jsx("button",{type:"button",className:"settings-button",disabled:!f||c,onClick:v,children:e(c?"providersSaving":"providersSave")})]}),r.jsx("span",{className:"settings-hint",children:e("providersOllamaUrlHint")})]})}function JZ(){const{t:e}=xt(),{settings:t,updateSetting:s}=io(),i=(t==null?void 0:t.ollamaUseFullSystemPrompt)??!1;return r.jsxs("label",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",marginTop:"var(--space-2)",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:i,onChange:l=>s("ollamaUseFullSystemPrompt",l.target.checked)}),r.jsx("span",{children:e("providersUseFullPrompt")}),r.jsx("span",{className:"settings-hint",style:{marginLeft:"auto"},children:e("providersUseFullPromptHint")})]})}function eG(){const{t:e}=xt(),{settings:t,updateSetting:s}=io(),[i,l]=h.useState(""),[c,d]=h.useState(!1),[f,m]=h.useState(!1),g=(t==null?void 0:t.ollamaSystemPrompt)??"";h.useEffect(()=>{t&&l(t.ollamaSystemPrompt??"")},[t]);const v=h.useCallback(async()=>{d(!0);try{await s("ollamaSystemPrompt",i.trim()||void 0),m(!1)}catch{}finally{d(!1)}},[i,s]);return r.jsxs("div",{style:{marginTop:"var(--space-2)",width:"100%"},children:[r.jsx("textarea",{className:"settings-textarea",value:i,onChange:b=>{l(b.target.value),m(b.target.value!==g)},placeholder:XZ,rows:4}),r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"var(--space-2)"},children:[r.jsx("span",{className:"settings-hint",children:e("providersOllamaPromptHint")}),r.jsx("button",{type:"button",className:"settings-button",disabled:!f||c,onClick:v,children:e(c?"providersSaving":"providersSave")})]})]})}function tG(){const{settings:e}=io(),t=(e==null?void 0:e.ollamaUseFullSystemPrompt)??!1;return r.jsxs(r.Fragment,{children:[r.jsx(QZ,{}),r.jsx(JZ,{}),!t&&r.jsx(eG,{})]})}function nG(){const{t:e}=xt(),{providers:t}=Yh(),i=hH().map(l=>{const c=t.find(d=>d.name===l.id);return{...l,installed:(c==null?void 0:c.installed)??!1,authenticated:(c==null?void 0:c.authenticated)??!1}});return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("providersSectionTitle")}),r.jsx("p",{className:"settings-section-description",children:e("providersSectionDescription")}),r.jsx("div",{className:"settings-group",children:i.map(l=>r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsxs("div",{className:"settings-item-header",children:[r.jsx("strong",{children:l.displayName}),l.installed?r.jsx("span",{className:"settings-status-badge settings-status-detected",children:e("providersDetected")}):r.jsx("span",{className:"settings-status-badge settings-status-not-detected",children:e("providersNotDetected")})]}),r.jsx("p",{children:l.metadata.description}),l.metadata.limitations.length>0&&r.jsx("ul",{className:"settings-limitations",children:l.metadata.limitations.map(c=>r.jsx("li",{children:c},c))}),l.id==="claude-ollama"&&r.jsx(tG,{})]}),l.metadata.website&&r.jsx("a",{href:l.metadata.website,target:"_blank",rel:"noopener noreferrer",className:"settings-link",children:e("providersWebsite")})]},l.id))})]})}function sG(){const[e,t]=h.useState(null),[s,i]=h.useState(null),[l,c]=h.useState(null),[d,f]=h.useState([]),[m,g]=h.useState(!0),[v,b]=h.useState(null),w=h.useCallback(async()=>{try{const[U,O,z,q]=await Promise.all([Ie("/remote-access/config"),Ie("/remote-access/relay"),Ie("/remote-access/relay/status"),Ie("/remote-access/sessions")]);t(U),i(O.relay),c(z),f(q.sessions),b(null)}catch(U){console.error("[useRemoteAccess] Failed to fetch config:",U),b(U instanceof Error?U.message:"Failed to fetch config")}},[]);h.useEffect(()=>{g(!0),w().finally(()=>g(!1))},[w]);const _=h.useCallback(async U=>{try{await Ie("/remote-access/configure",{method:"POST",body:JSON.stringify({password:U})}),await w()}catch(O){const z=O instanceof Error?O.message:"Failed to configure remote access";throw b(z),new Error(z)}},[w]),C=h.useCallback(async()=>{try{await Ie("/remote-access/enable",{method:"POST"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to enable remote access";throw b(O),new Error(O)}},[w]),S=h.useCallback(async()=>{try{await Ie("/remote-access/disable",{method:"POST"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to disable remote access";throw b(O),new Error(O)}},[w]),N=h.useCallback(async()=>{try{await Ie("/remote-access/clear",{method:"POST"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to clear remote access credentials";throw b(O),new Error(O)}},[w]),T=h.useCallback(async U=>{try{await Ie("/remote-access/relay",{method:"PUT",body:JSON.stringify(U)}),await w()}catch(O){const z=O instanceof Error?O.message:"Failed to update relay configuration";throw b(z),new Error(z)}},[w]),k=h.useCallback(async()=>{try{await Ie("/remote-access/relay",{method:"DELETE"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to clear relay configuration";throw b(O),new Error(O)}},[w]),A=h.useCallback(async U=>{try{await Ie(`/remote-access/sessions/${U}`,{method:"DELETE"}),await w()}catch(O){const z=O instanceof Error?O.message:"Failed to revoke session";throw b(z),new Error(z)}},[w]),P=h.useCallback(async()=>{try{await Ie("/remote-access/sessions",{method:"DELETE"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to revoke all sessions";throw b(O),new Error(O)}},[w]);return{config:e,relayConfig:s,relayStatus:l,sessions:d,loading:m,error:v,configure:_,enable:C,disable:S,clearCredentials:N,updateRelayConfig:T,clearRelayConfig:k,revokeSession:A,revokeAllSessions:P,refresh:w}}var Ir=(e=>(e[e.Border=-1]="Border",e[e.Data=0]="Data",e[e.Function=1]="Function",e[e.Position=2]="Position",e[e.Timing=3]="Timing",e[e.Alignment=4]="Alignment",e))(Ir||{}),oG=Object.defineProperty,rG=(e,t,s)=>t in e?oG(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,Ac=(e,t,s)=>(rG(e,typeof t!="symbol"?t+"":t,s),s);const iG=[0,1],bS=[1,0],yS=[2,3],SS=[3,2],aG={L:iG,M:bS,Q:yS,H:SS},lG=/^[0-9]*$/,cG=/^[A-Z0-9 $%*+.\/:-]*$/,Vf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",om=1,rm=40,Ub=3,uG=3,Rc=40,dG=10,wS=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],jS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]];class fG{constructor(t,s,i,l){if(this.version=t,this.ecc=s,Ac(this,"size"),Ac(this,"mask"),Ac(this,"modules",[]),Ac(this,"types",[]),t<om||t>rm)throw new RangeError("Version value out of range");if(l<-1||l>7)throw new RangeError("Mask value out of range");this.size=t*4+17;const c=Array.from({length:this.size},()=>!1);for(let f=0;f<this.size;f++)this.modules.push(c.slice()),this.types.push(c.map(()=>0));this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),l===-1){let f=1e9;for(let m=0;m<8;m++){this.applyMask(m),this.drawFormatBits(m);const g=this.getPenaltyScore();g<f&&(l=m,f=g),this.applyMask(m)}}this.mask=l,this.applyMask(l),this.drawFormatBits(l)}getModule(t,s){return t>=0&&t<this.size&&s>=0&&s<this.size&&this.modules[s][t]}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2===0,Ir.Timing),this.setFunctionModule(i,6,i%2===0,Ir.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const t=this.getAlignmentPatternPositions(),s=t.length;for(let i=0;i<s;i++)for(let l=0;l<s;l++)i===0&&l===0||i===0&&l===s-1||i===s-1&&l===0||this.drawAlignmentPattern(t[i],t[l]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){const s=this.ecc[1]<<3|t;let i=s;for(let c=0;c<10;c++)i=i<<1^(i>>>9)*1335;const l=(s<<10|i)^21522;for(let c=0;c<=5;c++)this.setFunctionModule(8,c,Mo(l,c));this.setFunctionModule(8,7,Mo(l,6)),this.setFunctionModule(8,8,Mo(l,7)),this.setFunctionModule(7,8,Mo(l,8));for(let c=9;c<15;c++)this.setFunctionModule(14-c,8,Mo(l,c));for(let c=0;c<8;c++)this.setFunctionModule(this.size-1-c,8,Mo(l,c));for(let c=8;c<15;c++)this.setFunctionModule(8,this.size-15+c,Mo(l,c));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let i=0;i<12;i++)t=t<<1^(t>>>11)*7973;const s=this.version<<12|t;for(let i=0;i<18;i++){const l=Mo(s,i),c=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(c,d,l),this.setFunctionModule(d,c,l)}}drawFinderPattern(t,s){for(let i=-4;i<=4;i++)for(let l=-4;l<=4;l++){const c=Math.max(Math.abs(l),Math.abs(i)),d=t+l,f=s+i;d>=0&&d<this.size&&f>=0&&f<this.size&&this.setFunctionModule(d,f,c!==2&&c!==4,Ir.Position)}}drawAlignmentPattern(t,s){for(let i=-2;i<=2;i++)for(let l=-2;l<=2;l++)this.setFunctionModule(t+l,s+i,Math.max(Math.abs(l),Math.abs(i))!==1,Ir.Alignment)}setFunctionModule(t,s,i,l=Ir.Function){this.modules[s][t]=i,this.types[s][t]=l}addEccAndInterleave(t){const s=this.version,i=this.ecc;if(t.length!==$c(s,i))throw new RangeError("Invalid argument");const l=jS[i[0]][s],c=wS[i[0]][s],d=Math.floor(hh(s)/8),f=l-d%l,m=Math.floor(d/l),g=[],v=SG(c);for(let w=0,_=0;w<l;w++){const C=t.slice(_,_+m-c+(w<f?0:1));_+=C.length;const S=wG(C,v);w<f&&C.push(0),g.push(C.concat(S))}const b=[];for(let w=0;w<g[0].length;w++)g.forEach((_,C)=>{(w!==m-c||C>=f)&&b.push(_[w])});return b}drawCodewords(t){if(t.length!==Math.floor(hh(this.version)/8))throw new RangeError("Invalid argument");let s=0;for(let i=this.size-1;i>=1;i-=2){i===6&&(i=5);for(let l=0;l<this.size;l++)for(let c=0;c<2;c++){const d=i-c,m=(i+1&2)===0?this.size-1-l:l;!this.types[m][d]&&s<t.length*8&&(this.modules[m][d]=Mo(t[s>>>3],7-(s&7)),s++)}}}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let s=0;s<this.size;s++)for(let i=0;i<this.size;i++){let l;switch(t){case 0:l=(i+s)%2===0;break;case 1:l=s%2===0;break;case 2:l=i%3===0;break;case 3:l=(i+s)%3===0;break;case 4:l=(Math.floor(i/3)+Math.floor(s/2))%2===0;break;case 5:l=i*s%2+i*s%3===0;break;case 6:l=(i*s%2+i*s%3)%2===0;break;case 7:l=((i+s)%2+i*s%3)%2===0;break;default:throw new Error("Unreachable")}!this.types[s][i]&&l&&(this.modules[s][i]=!this.modules[s][i])}}getPenaltyScore(){let t=0;for(let c=0;c<this.size;c++){let d=!1,f=0;const m=[0,0,0,0,0,0,0];for(let g=0;g<this.size;g++)this.modules[c][g]===d?(f++,f===5?t+=Ub:f>5&&t++):(this.finderPenaltyAddHistory(f,m),d||(t+=this.finderPenaltyCountPatterns(m)*Rc),d=this.modules[c][g],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,m)*Rc}for(let c=0;c<this.size;c++){let d=!1,f=0;const m=[0,0,0,0,0,0,0];for(let g=0;g<this.size;g++)this.modules[g][c]===d?(f++,f===5?t+=Ub:f>5&&t++):(this.finderPenaltyAddHistory(f,m),d||(t+=this.finderPenaltyCountPatterns(m)*Rc),d=this.modules[g][c],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,m)*Rc}for(let c=0;c<this.size-1;c++)for(let d=0;d<this.size-1;d++){const f=this.modules[c][d];f===this.modules[c][d+1]&&f===this.modules[c+1][d]&&f===this.modules[c+1][d+1]&&(t+=uG)}let s=0;for(const c of this.modules)s=c.reduce((d,f)=>d+(f?1:0),s);const i=this.size*this.size,l=Math.ceil(Math.abs(s*20-i*10)/i)-1;return t+=l*dG,t}getAlignmentPatternPositions(){if(this.version===1)return[];{const t=Math.floor(this.version/7)+2,s=this.version===32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,i=[6];for(let l=this.size-7;i.length<t;l-=s)i.splice(1,0,l);return i}}finderPenaltyCountPatterns(t){const s=t[1],i=s>0&&t[2]===s&&t[3]===s*3&&t[4]===s&&t[5]===s;return(i&&t[0]>=s*4&&t[6]>=s?1:0)+(i&&t[6]>=s*4&&t[0]>=s?1:0)}finderPenaltyTerminateAndCount(t,s,i){return t&&(this.finderPenaltyAddHistory(s,i),s=0),s+=this.size,this.finderPenaltyAddHistory(s,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(t,s){s[0]===0&&(t+=this.size),s.pop(),s.unshift(t)}}function Lo(e,t,s){if(t<0||t>31||e>>>t)throw new RangeError("Value out of range");for(let i=t-1;i>=0;i--)s.push(e>>>i&1)}function Mo(e,t){return(e>>>t&1)!==0}class im{constructor(t,s,i){if(this.mode=t,this.numChars=s,this.bitData=i,s<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}getData(){return this.bitData.slice()}}const hG=[1,10,12,14],mG=[2,9,11,13],pG=[4,8,16,16];function ES(e,t){return e[Math.floor((t+7)/17)+1]}function NS(e){const t=[];for(const s of e)Lo(s,8,t);return new im(pG,e.length,t)}function gG(e){if(!_S(e))throw new RangeError("String contains non-numeric characters");const t=[];for(let s=0;s<e.length;){const i=Math.min(e.length-s,3);Lo(Number.parseInt(e.substring(s,s+i),10),i*3+1,t),s+=i}return new im(hG,e.length,t)}function xG(e){if(!CS(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");const t=[];let s;for(s=0;s+2<=e.length;s+=2){let i=Vf.indexOf(e.charAt(s))*45;i+=Vf.indexOf(e.charAt(s+1)),Lo(i,11,t)}return s<e.length&&Lo(Vf.indexOf(e.charAt(s)),6,t),new im(mG,e.length,t)}function vG(e){return e===""?[]:_S(e)?[gG(e)]:CS(e)?[xG(e)]:[NS(yG(e))]}function _S(e){return lG.test(e)}function CS(e){return cG.test(e)}function bG(e,t){let s=0;for(const i of e){const l=ES(i.mode,t);if(i.numChars>=1<<l)return Number.POSITIVE_INFINITY;s+=4+l+i.bitData.length}return s}function yG(e){e=encodeURI(e);const t=[];for(let s=0;s<e.length;s++)e.charAt(s)!=="%"?t.push(e.charCodeAt(s)):(t.push(Number.parseInt(e.substring(s+1,s+3),16)),s+=2);return t}function hh(e){if(e<om||e>rm)throw new RangeError("Version number out of range");let t=(16*e+128)*e+64;if(e>=2){const s=Math.floor(e/7)+2;t-=(25*s-10)*s-55,e>=7&&(t-=36)}return t}function $c(e,t){return Math.floor(hh(e)/8)-wS[t[0]][e]*jS[t[0]][e]}function SG(e){if(e<1||e>255)throw new RangeError("Degree out of range");const t=[];for(let i=0;i<e-1;i++)t.push(0);t.push(1);let s=1;for(let i=0;i<e;i++){for(let l=0;l<t.length;l++)t[l]=mh(t[l],s),l+1<t.length&&(t[l]^=t[l+1]);s=mh(s,2)}return t}function wG(e,t){const s=t.map(i=>0);for(const i of e){const l=i^s.shift();s.push(0),t.forEach((c,d)=>s[d]^=mh(c,l))}return s}function mh(e,t){if(e>>>8||t>>>8)throw new RangeError("Byte out of range");let s=0;for(let i=7;i>=0;i--)s=s<<1^(s>>>7)*285,s^=(t>>>i&1)*e;return s}function jG(e,t,s=1,i=40,l=-1,c=!0){if(!(om<=s&&s<=i&&i<=rm)||l<-1||l>7)throw new RangeError("Invalid value");let d,f;for(d=s;;d++){const b=$c(d,t)*8,w=bG(e,d);if(w<=b){f=w;break}if(d>=i)throw new RangeError("Data too long")}for(const b of[bS,yS,SS])c&&f<=$c(d,b)*8&&(t=b);const m=[];for(const b of e){Lo(b.mode[0],4,m),Lo(b.numChars,ES(b.mode,d),m);for(const w of b.getData())m.push(w)}const g=$c(d,t)*8;Lo(0,Math.min(4,g-m.length),m),Lo(0,(8-m.length%8)%8,m);for(let b=236;m.length<g;b^=253)Lo(b,8,m);const v=Array.from({length:Math.ceil(m.length/8)},()=>0);return m.forEach((b,w)=>v[w>>>3]|=b<<7-(w&7)),new fG(d,t,v,l)}function EG(e,t){const{ecc:s="L",boostEcc:i=!1,minVersion:l=1,maxVersion:c=40,maskPattern:d=-1,border:f=1}={},m=typeof e=="string"?vG(e):Array.isArray(e)?[NS(e)]:void 0;if(!m)throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);const g=jG(m,aG[s],l,c,d,i);return NG({version:g.version,maskPattern:g.mask,size:g.size,data:g.modules,types:g.types},f)}function NG(e,t=1){if(!t)return e;const{size:s}=e,i=s+t*2;e.size=i,e.data.forEach(c=>{for(let d=0;d<t;d++)c.unshift(!1),c.push(!1)});for(let c=0;c<t;c++)e.data.unshift(Array.from({length:i},d=>!1)),e.data.push(Array.from({length:i},d=>!1));const l=Ir.Border;e.types.forEach(c=>{for(let d=0;d<t;d++)c.unshift(l),c.push(l)});for(let c=0;c<t;c++)e.types.unshift(Array.from({length:i},d=>l)),e.types.push(Array.from({length:i},d=>l));return e}function _G({value:e,size:t=200,color:s="#000000",bgColor:i="#ffffff"}){const{data:l}=EG(e),c=l.length,d=t/c;let f="";for(let m=0;m<c;m++){const g=l[m];if(g){for(let v=0;v<c;v++)if(g[v]){const b=v*d,w=m*d;f+=`M${b},${w}h${d}v${d}h-${d}z`}}}return r.jsxs("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"QR code",children:[r.jsx("rect",{width:t,height:t,fill:i}),r.jsx("path",{d:f,fill:s})]})}const Ni="wss://relay.yepanywhere.com/ws",Wf="https://yepanywhere.com/remote/login/relay";function CG(e){return new Date(e).toLocaleDateString()}function Pb(e,t){const s=new Date(e),l=new Date().getTime()-s.getTime(),c=Math.floor(l/(1e3*60)),d=Math.floor(l/(1e3*60*60)),f=Math.floor(l/(1e3*60*60*24));return c<1?t("remoteSetupJustNow"):c<60?t("remoteSetupMinutesAgo",{count:c,suffix:c===1?"":"s"}):d<24?t("remoteSetupHoursAgo",{count:d,suffix:d===1?"":"s"}):f===1?t("remoteSetupYesterday"):f<7?t("hostPickerLastConnectedDays",{count:f}):CG(e)}function kG(e,t,s,i){if(!t)return{text:i("remoteSetupStatusDisabled"),className:"status-disabled"};if(!s)return{text:i("remoteSetupStatusNotConfigured"),className:"status-warning"};switch(e){case"waiting":return{text:i("remoteSetupStatusConnected"),className:"status-success"};case"connecting":return{text:i("remoteSetupStatusConnecting"),className:"status-pending"};case"registering":return{text:i("remoteSetupStatusRegistering"),className:"status-pending"};case"rejected":return{text:i("remoteSetupStatusUsernameTaken"),className:"status-error"};default:return{text:i("remoteSetupStatusDisconnected"),className:"status-warning"}}}function TG({title:e="Remote Access",description:t="Access your server from anywhere.",onSetupComplete:s}){const{t:i}=xt(),{config:l,relayConfig:c,relayStatus:d,sessions:f,loading:m,error:g,configure:v,enable:b,disable:w,updateRelayConfig:_,revokeSession:C,revokeAllSessions:S,refresh:N}=sG(),[T,k]=h.useState(""),[A,P]=h.useState(""),[U,O]=h.useState(""),[z,q]=h.useState("default"),[oe,K]=h.useState(""),[I,B]=h.useState(!1),[Z,Q]=h.useState(null),[ae,W]=h.useState(!1),[Y,V]=h.useState(!1),[ne,ge]=h.useState(null),[$,G]=h.useState(!1);h.useEffect(()=>{c&&(k(c.username),c.url===Ni?(q("default"),K("")):(q("custom"),K(c.url)))},[c]),h.useEffect(()=>{const $e=T!==((c==null?void 0:c.username)??""),Et=A.length>0,Oe=z==="default"?Ni:oe,Ot=(c==null?void 0:c.url)??Ni;V($e||Et||Oe!==Ot)},[T,A,z,oe,c]),h.useEffect(()=>{if((d==null?void 0:d.status)==="connecting"||(d==null?void 0:d.status)==="registering"){const $e=setInterval(N,2e3);return()=>clearInterval($e)}},[d==null?void 0:d.status,N]);const le=(l==null?void 0:l.enabled)??!1,fe=!!(l!=null&&l.username),ue=()=>z==="default"?Ni:oe,_e=async()=>{if(Q(null),!T.trim())return Q(i("remoteSetupErrorUsernameRequired")),!1;if(T.length<3)return Q(i("remoteSetupErrorUsernameShort")),!1;if(!fe&&!A)return Q(i("remoteSetupErrorPasswordRequired")),!1;if(A&&A.length<8)return Q(i("remoteSetupErrorPasswordShort")),!1;if(A&&A!==U)return Q(i("remoteSetupErrorPasswordMismatch")),!1;if(z==="custom"&&!oe.trim())return Q(i("remoteSetupErrorCustomRelayRequired")),!1;try{const $e=ue();return(T!==(c==null?void 0:c.username)||$e!==(c==null?void 0:c.url))&&await _({url:$e,username:T}),A&&(await v(A),ge(A)),P(""),O(""),V(!1),!0}catch($e){return Q($e instanceof Error?$e.message:i("remoteSetupErrorSaveFailed")),!1}},Ke=async $e=>{Q(null),B(!0);try{if($e)if(Y){if(!await _e()){B(!1);return}s==null||s()}else fe&&(await b(),s==null||s());else await w()}catch(Et){Q(Et instanceof Error?Et.message:i("remoteSetupErrorUpdateFailed"))}finally{B(!1)}},tt=async $e=>{$e.preventDefault(),B(!0),await _e()&&(s==null||s()),B(!1)},De=async $e=>{await navigator.clipboard.writeText($e),W(!0),setTimeout(()=>W(!1),2e3)};if(m)return r.jsxs("div",{className:"remote-access-setup",children:[r.jsx("div",{className:"remote-access-header",children:r.jsxs("div",{children:[r.jsx("h3",{children:e}),r.jsx("p",{children:t})]})}),r.jsx("div",{className:"remote-access-loading",children:i("remoteSetupLoading")})]});const vt=kG((d==null?void 0:d.status)??null,le,fe,i),me=(()=>{const $e=new URLSearchParams;T&&$e.set("u",T);const Et=ue();Et!==Ni&&$e.set("r",Et);const Oe=$e.toString();return Oe?`${Wf}?${Oe}`:Wf})(),We=(()=>{if(!ne||!T)return null;const $e=new URLSearchParams;$e.set("u",T),$e.set("p",ne);const Et=ue();return Et!==Ni&&$e.set("r",Et),`${Wf}#${$e.toString()}`})(),ot=le&&(d==null?void 0:d.status)==="waiting"&&We!==null,ut=fe||T&&A;return r.jsxs("div",{className:"remote-access-setup",children:[r.jsxs("div",{className:"remote-access-header",children:[r.jsxs("div",{children:[r.jsx("h3",{children:e}),r.jsx("p",{children:t})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:le,onChange:$e=>Ke($e.target.checked),disabled:I||!le&&!ut}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("form",{onSubmit:tt,className:"remote-access-form",children:[r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"remote-username",children:i("remoteSetupUsername")}),r.jsx("input",{id:"remote-username",type:"text",value:T,onChange:$e=>k($e.target.value.toLowerCase()),placeholder:i("remoteSetupUsernamePlaceholder"),minLength:3,maxLength:32,pattern:"[a-z0-9][a-z0-9-]*[a-z0-9]|[a-z0-9]{1,2}",title:i("remoteSetupUsernameHint"),autoComplete:"username",disabled:I})]}),r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"remote-password",children:i(fe?"remoteSetupNewPassword":"remoteSetupPassword")}),r.jsx("input",{id:"remote-password",type:"password",value:A,onChange:$e=>P($e.target.value),placeholder:fe?"••••••••":"",minLength:8,autoComplete:"new-password",disabled:I})]}),A&&r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"remote-confirm",children:i("remoteSetupConfirmPassword")}),r.jsx("input",{id:"remote-confirm",type:"password",value:U,onChange:$e=>O($e.target.value),minLength:8,autoComplete:"new-password",disabled:I})]}),r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"relay-select",children:i("remoteSetupRelayServer")}),r.jsxs("select",{id:"relay-select",value:z,onChange:$e=>q($e.target.value),disabled:I,className:"form-select",children:[r.jsx("option",{value:"default",children:i("remoteSetupRelayDefault")}),r.jsx("option",{value:"custom",children:i("remoteSetupRelayCustom")})]})]}),z==="custom"&&r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"custom-relay-url",children:i("remoteSetupCustomRelayUrl")}),r.jsx("input",{id:"custom-relay-url",type:"text",value:oe,onChange:$e=>K($e.target.value),placeholder:i("remoteSetupCustomRelayPlaceholder"),disabled:I})]}),r.jsxs("div",{className:"remote-access-status",children:[r.jsx("span",{className:"status-label",children:i("remoteSetupStatus")}),r.jsx("span",{className:`status-indicator ${vt.className}`,children:vt.text}),(d==null?void 0:d.error)&&r.jsx("span",{className:"status-error-detail",children:d.error})]}),(Z||g)&&r.jsx("p",{className:"form-error",children:Z||g}),le&&T&&r.jsxs("div",{className:"remote-access-connect",children:[r.jsx("span",{className:"connect-label",children:i("remoteSetupConnectFrom")}),r.jsxs("div",{className:"connect-url-row",children:[r.jsx("code",{className:"connect-url",children:me}),r.jsx("button",{type:"button",className:"copy-button",onClick:()=>De(me),title:i("remoteSetupCopyUrl"),children:i(ae?"remoteSetupCopied":"remoteSetupCopy")})]})]}),ot&&r.jsxs("div",{className:"remote-access-qr",children:[r.jsx("button",{type:"button",className:"qr-toggle-button",onClick:()=>G(!$),children:i($?"remoteSetupHideQr":"remoteSetupShowQr")}),$&&We&&r.jsxs("div",{className:"qr-code-container",children:[r.jsx(_G,{value:We,size:200}),r.jsx("p",{className:"qr-code-hint",children:i("remoteSetupQrHint")})]})]}),r.jsxs("div",{className:"remote-access-sessions",children:[r.jsxs("div",{className:"sessions-header",children:[r.jsx("span",{className:"sessions-title",children:i("remoteSetupSessions",{count:f.length})}),f.length>0&&r.jsx("button",{type:"button",className:"revoke-all-button",onClick:()=>S(),disabled:I,children:i("remoteSetupRevokeAll")})]}),f.length===0?r.jsx("p",{className:"sessions-empty",children:i("remoteSetupNoSessions")}):r.jsx("ul",{className:"sessions-list",children:f.map($e=>{const{browser:Et,os:Oe}=$e.userAgent?s0($e.userAgent):{browser:i("remoteSetupUnknownBrowser"),os:i("remoteSetupUnknownOs")},Ot=$e.userAgent||$e.origin;return r.jsxs("li",{className:"session-item",children:[r.jsx("div",{className:"session-info",children:Ot?r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"session-device",children:[Et," · ",Oe]}),$e.origin&&r.jsx("code",{className:"session-origin",children:$e.origin}),r.jsxs("span",{className:"session-dates",children:[i("remoteSetupCreated",{date:Pb($e.createdAt,i)})," ","·"," ",i("remoteSetupLastUsed",{date:Pb($e.lastUsed,i)})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"session-created",children:[i("remoteSetupCreatedLabel")," ",new Date($e.createdAt).toLocaleDateString()]}),r.jsxs("span",{className:"session-last-used",children:[i("remoteSetupLastUsedLabel")," ",new Date($e.lastUsed).toLocaleDateString()]})]})}),r.jsx("button",{type:"button",className:"revoke-button",onClick:()=>C($e.sessionId),disabled:I,children:i("remoteSetupRevoke")})]},$e.sessionId)})})]}),r.jsx("div",{className:"remote-access-actions",children:r.jsx("button",{type:"submit",className:"settings-button",disabled:I||!Y,children:i(I?"remoteSetupSaving":"remoteSetupSave")})})]})]})}function AG(){const{t:e}=xt(),t=js(),s=Vi(),{settings:i,isLoading:l,error:c,updateSetting:d}=io(),f=()=>{s==null||s.disconnect(),t("/login")},m=r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentPersistRemoteTitle")}),r.jsxs("p",{children:[e("developmentPersistRemoteDescriptionPrefix")," ",r.jsx("code",{children:"remote-sessions.json"})," so relay reconnect survives",e("developmentPersistRemoteDescriptionSuffix")]})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.persistRemoteSessionsToDisk)??!1,disabled:l,onChange:g=>void d("persistRemoteSessionsToDisk",g.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})}),c&&r.jsx("p",{className:"settings-warning",children:c})]});if(s){const g=s.currentHostId?pR(s.currentHostId):null,v=(g==null?void 0:g.displayName)||s.storedUsername||e("remoteAccessDefaultHost");return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("remoteAccessConnectedTitle")}),r.jsx("p",{className:"settings-section-description",children:e("remoteAccessConnectedDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessCurrentHostTitle")}),r.jsx("p",{children:v})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:f,children:e("sidebarSwitchHost")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessLogoutTitle")}),r.jsx("p",{children:e("remoteAccessLogoutDescription")})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>s.disconnect(),children:e("remoteAccessLogout")})]})]}),m]})}return r.jsxs("section",{className:"settings-section",children:[r.jsx(TG,{title:e("remoteAccessConnectedTitle"),description:e("remoteAccessSetupDescription")}),m]})}function RG(){const{t:e}=xt(),{executors:t,loading:s,addExecutor:i,removeExecutor:l,testExecutor:c}=I0(),[d,f]=h.useState(""),[m,g]=h.useState(!1),[v,b]=h.useState(null),[w,_]=h.useState({}),C=async()=>{if(!(!d.trim()||m)){g(!0),b(null);try{await i(d.trim()),f("")}catch(k){b(k instanceof Error?k.message:e("remoteExecutorsAddFailed"))}finally{g(!1)}}},S=async k=>{try{await l(k),_(A=>{const{[k]:P,...U}=A;return U})}catch(A){console.error("Failed to remove executor:",A)}},N=async k=>{_(A=>({...A,[k]:{testing:!0}}));try{const A=await c(k);_(P=>({...P,[k]:{testing:!1,result:A}}))}catch(A){_(P=>({...P,[k]:{testing:!1,result:{success:!1,error:A instanceof Error?A.message:e("remoteExecutorsConnectionFailed")}}}))}},T=k=>{k.key==="Enter"&&(k.preventDefault(),C())};return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("remoteExecutorsTitle")}),r.jsx("p",{className:"settings-section-description",children:e("remoteExecutorsDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteExecutorsAddTitle")}),r.jsx("p",{children:e("remoteExecutorsAddDescription")})]}),r.jsxs("div",{className:"remote-executor-add",children:[r.jsx("input",{type:"text",value:d,onChange:k=>f(k.target.value),onKeyDown:T,placeholder:e("remoteExecutorsHostPlaceholder"),disabled:m,className:"remote-executor-input"}),r.jsx("button",{type:"button",onClick:C,disabled:!d.trim()||m,className:"remote-executor-add-button",children:e(m?"remoteExecutorsAdding":"remoteExecutorsAdd")})]}),v&&r.jsx("p",{className:"settings-error",children:v})]})}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("remoteExecutorsConfigured")}),s?r.jsx("p",{className:"settings-loading",children:e("loginLoading")}):t.length===0?r.jsx("p",{className:"settings-empty",children:e("remoteExecutorsEmpty")}):r.jsx("div",{className:"remote-executor-list",children:t.map(k=>{var P;const A=w[k];return r.jsxs("div",{className:"remote-executor-item",children:[r.jsxs("div",{className:"remote-executor-item-info",children:[r.jsx("span",{className:"remote-executor-host",children:k}),(A==null?void 0:A.result)&&r.jsx("span",{className:`settings-status-badge ${A.result.success?"settings-status-detected":"settings-status-not-detected"}`,children:A.result.success?e("remoteExecutorsConnected"):e("remoteExecutorsFailed")})]}),(A==null?void 0:A.result)&&!A.result.success&&r.jsx("p",{className:"settings-error remote-executor-error",children:A.result.error}),((P=A==null?void 0:A.result)==null?void 0:P.success)&&r.jsx("p",{className:"remote-executor-details",children:A.result.claudeAvailable?A.result.claudeVersion?e("remoteExecutorsClaudeVersion",{version:A.result.claudeVersion}):e("remoteExecutorsClaudeAvailable"):e("remoteExecutorsClaudeMissing")}),r.jsxs("div",{className:"remote-executor-actions",children:[r.jsx("button",{type:"button",onClick:()=>N(k),disabled:A==null?void 0:A.testing,className:"remote-executor-test-button",children:A!=null&&A.testing?e("remoteExecutorsTesting"):e("remoteExecutorsTestConnection")}),r.jsx("button",{type:"button",onClick:()=>S(k),className:"remote-executor-remove-button",children:e("remoteExecutorsRemove")})]})]},k)})})]}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("remoteExecutorsSetupRequirements")}),r.jsxs("ul",{className:"settings-requirements",children:[r.jsx("li",{children:e("remoteExecutorsRequirementSshConfig")}),r.jsx("li",{children:e("remoteExecutorsRequirementKeyAuth")}),r.jsx("li",{children:e("remoteExecutorsRequirementClaude")}),r.jsx("li",{children:e("remoteExecutorsRequirementPaths")})]})]})]})}const MG={appearance:NZ,model:FZ,"agent-context":EZ,notifications:KZ,webhooks:IZ,devices:RZ,"local-access":BZ,remote:AG,providers:nG,"remote-executors":RG,emulator:OZ,about:jZ,development:_Z};function Ib({category:e,isActive:t,onClick:s}){return r.jsxs("button",{type:"button",className:`settings-category-item ${t?"active":""}`,onClick:s,children:[r.jsx("span",{className:"settings-category-icon",children:e.icon}),r.jsxs("div",{className:"settings-category-text",children:[r.jsx("span",{className:"settings-category-label",children:e.label}),r.jsx("span",{className:"settings-category-description",children:e.description})]}),r.jsx("span",{className:"settings-category-chevron",children:"›"})]})}function zb(){var N;const{t:e}=xt(),{category:t}=tu(),s=js(),i=mo(),{openSidebar:l,isWideScreen:c,toggleSidebar:d,isSidebarCollapsed:f}=Io(),{isManualReloadMode:m}=Bh(),{version:g}=il(),v=(g==null?void 0:g.capabilities)??[],b=[...bZ(T=>e(T))];if(v.includes("deviceBridge")||v.includes("deviceBridge-download")||v.includes("deviceBridge-available")){const T=b.findIndex(k=>k.id==="about");b.splice(T>=0?T:b.length,0,yZ(k=>e(k)))}m&&b.push(SZ(T=>e(T)));const w=t||(c?(N=b[0])==null?void 0:N.id:void 0),_=T=>{s(`${i}/settings/${T}`)},C=()=>{s(`${i}/settings`)},S=w?MG[w]:null;if(!c){if(!t)return r.jsx("div",{className:"main-content-mobile",children:r.jsxs("div",{className:"main-content-mobile-inner",children:[r.jsx(ro,{title:e("pageTitleSettings"),onOpenSidebar:l,onToggleSidebar:d,isWideScreen:c,isSidebarCollapsed:f}),r.jsx("main",{className:"page-scroll-container",children:r.jsx("div",{className:"page-content-inner",children:r.jsx("div",{className:"settings-category-list",children:b.map(k=>r.jsx(Ib,{category:k,isActive:!1,onClick:()=>_(k.id)},k.id))})})})]})});const T=b.find(k=>k.id===t);return r.jsx("div",{className:"main-content-mobile",children:r.jsxs("div",{className:"main-content-mobile-inner",children:[r.jsx(ro,{title:(T==null?void 0:T.label)||e("pageTitleSettings"),onOpenSidebar:l,showBack:!0,onBack:C}),r.jsx("main",{className:"page-scroll-container",children:r.jsx("div",{className:"page-content-inner",children:S&&r.jsx(S,{})})})]})})}return r.jsx("div",{className:"main-content-wrapper",children:r.jsxs("div",{className:"main-content-constrained",children:[r.jsx(ro,{title:e("pageTitleSettings"),onOpenSidebar:l,onToggleSidebar:d,isWideScreen:c,isSidebarCollapsed:f}),r.jsx("main",{className:"page-scroll-container",children:r.jsxs("div",{className:"settings-two-column",children:[r.jsx("nav",{className:"settings-category-nav",children:r.jsx("div",{className:"settings-category-list",children:b.map(T=>r.jsx(Ib,{category:T,isActive:w===T.id,onClick:()=>_(T.id)},T.id))})}),r.jsx("div",{className:"settings-content-panel",children:S&&r.jsx(S,{})})]})})]})})}const DG=h.Fragment;iF();$F();HF();const LG="/".replace(/\/$/,"")||void 0,kS=document.getElementById("root");if(!kS)throw new Error("Root element not found");Hj.createRoot(kS).render(r.jsx(DG,{children:r.jsx(UF,{children:r.jsx(mE,{basename:LG,children:r.jsx(OF,{children:r.jsxs(H1,{children:[r.jsx(us,{path:"/",element:r.jsx(tv,{to:"/projects",replace:!0})}),r.jsx(us,{path:"/login",element:r.jsx(W7,{})}),r.jsxs(us,{element:r.jsx(vH,{}),children:[r.jsx(us,{path:"/projects",element:r.jsx(eq,{})}),r.jsx(us,{path:"/sessions",element:r.jsx(B7,{})}),r.jsx(us,{path:"/agents",element:r.jsx(PH,{})}),r.jsx(us,{path:"/inbox",element:r.jsx(V7,{})}),r.jsx(us,{path:"/settings",element:r.jsx(zb,{})}),r.jsx(us,{path:"/settings/:category",element:r.jsx(zb,{})}),r.jsx(us,{path:"/projects/:projectId",element:r.jsx(tv,{to:"/sessions",replace:!0})}),r.jsx(us,{path:"/git-status",element:r.jsx(M7,{})}),r.jsx(us,{path:"/devices",element:r.jsx(Gv,{})}),r.jsx(us,{path:"/devices/:deviceId",element:r.jsx(Gv,{})}),r.jsx(us,{path:"/new-session",element:r.jsx(X7,{})}),r.jsx(us,{path:"/projects/:projectId/sessions/:sessionId",element:r.jsx(hZ,{})})]}),r.jsx(us,{path:"/projects/:projectId/file",element:r.jsx(k7,{})}),r.jsx(us,{path:"/activity",element:r.jsx(NH,{})})]})})})})}));
174
+ `).trim();return l.length>0?l:null}return null}function fZ(e,t,s,i){const[l,c]=h.useState(s??{owner:"none"}),[d,f]=h.useState(s?"in-turn":"idle"),[m,g]=h.useState(null),[v,b]=h.useState(null),[w,_]=h.useState(t),[C,S]=h.useState(null),[N,T]=h.useState([]),[k,A]=h.useState([]),[P,U]=h.useState(!1),[O,z]=h.useState({}),[q,oe]=h.useState("default"),[K,I]=h.useState("default"),[B,Z]=h.useState(0),Q=h.useRef(!1);h.useEffect(()=>{Q.current=!1},[t]);const[ae,W]=h.useState([]),[Y,V]=h.useState([]),[ne,ge]=h.useState([]),$=h.useRef(0),G=h.useCallback((Ue,ct)=>{ct>=$.current&&($.current=ct,I(Ue),oe(Ue),Z(ct))},[]),le=h.useCallback(Ue=>{var ct;c(on=>on.owner==="self"&&Ue.status.owner!=="self"?on:Ue.status),Ue.status.owner==="self"&&Ue.status.permissionMode&&Ue.status.modeVersion!==void 0&&G(Ue.status.permissionMode,Ue.status.modeVersion),Ue.pendingInputRequest&&g(Ue.pendingInputRequest),(ct=Ue.slashCommands)!=null&&ct.length&&W(Ue.slashCommands.map(on=>on.name))},[G]),fe=h.useCallback(Ue=>{b(Ue)},[]),{messages:ue,agentContent:_e,toolUseToAgent:Ke,loading:tt,session:De,setSession:vt,handleStreamingUpdate:me,handleStreamMessageEvent:We,handleStreamSubagentMessage:ot,registerToolUseAgent:ut,setAgentContent:$e,setToolUseToAgent:Et,setMessages:Oe,fetchNewMessages:Ot,pagination:Tt,loadingOlder:Sn,loadOlderMessages:In}=nZ({projectId:e,sessionId:t,onLoadComplete:le,onLoadError:fe}),pn=h.useCallback(async Ue=>{if(oe(Ue),l.owner==="self"||l.owner==="external")try{const ct=await Re.setPermissionMode(t,Ue);ct.modeVersion>=$.current&&($.current=ct.modeVersion,I(ct.permissionMode),Z(ct.modeVersion))}catch(ct){console.warn("Failed to sync permission mode:",ct)}},[t,l.owner]),Nn=h.useCallback(async Ue=>{if(l.owner!=="self"&&l.owner!=="external"){console.warn("Cannot set hold: no active process");return}try{const ct=await Re.setHold(t,Ue);ct.state==="hold"?f("hold"):ct.state==="in-turn"&&f("in-turn")}catch(ct){console.warn("Failed to set hold:",ct)}},[t,l.owner]),Jt=h.useRef({timer:null,pending:!1}),jt=h.useCallback(Ue=>{const ct=`temp-${Date.now()}`;return T(on=>[...on,{tempId:ct,content:Ue,timestamp:new Date().toISOString()}]),ct},[]),ts=h.useCallback(Ue=>{T(ct=>ct.filter(on=>on.tempId!==Ue))},[]),ms=h.useCallback((Ue,ct)=>{T(on=>on.map(ls=>ls.tempId===Ue?{...ls,...ct}:ls))},[]),zn=h.useRef(null);h.useEffect(()=>{if(tt||zn.current===t||ue.length===0)return;(async()=>{zn.current=t;const ct=ZY(ue);if(ct.length!==0)try{const{mappings:on}=await Re.getAgentMappings(e,t),ls=new Map(on.map(Me=>[Me.toolUseId,Me.agentId]));Et(Me=>{const nn=new Map(Me);for(const[E,M]of ls)nn.has(E)||nn.set(E,M);return nn});for(const Me of ct){const nn=ls.get(Me.toolUseId);if(nn)try{const E=await Re.getAgentSession(e,t,nn);$e(M=>{const R=M[nn];if(R&&R.messages.length>0){const y=new Set(R.messages.map(ee=>Hn(ee))),L=E.messages.filter(ee=>!y.has(Hn(ee)));return{...M,[nn]:{messages:[...R.messages,...L],status:E.status}}}return{...M,[nn]:E}})}catch{}}}catch{}})()},[tt,ue,e,t,$e,Et]);const be=h.useCallback(()=>{const Ue=Jt.current;Ue.timer?Ue.pending=!0:(Ot(),Ue.timer=setTimeout(()=>{Ue.timer=null,Ue.pending&&(Ue.pending=!1,be())},uZ))},[Ot]),Be=h.useCallback(Ue=>{Ue.fileType!=="session"&&Ue.fileType!=="agent-session"||GY(Ue)!==t||l.owner!=="self"&&be()},[t,l.owner,be]),Pe=h.useCallback(Ue=>{Ue.sessionId===t&&vt(ct=>ct&&{...ct,...Ue.title!==void 0&&{title:Ue.title},...Ue.messageCount!==void 0&&{messageCount:Ue.messageCount},...Ue.updatedAt!==void 0&&{updatedAt:Ue.updatedAt},...Ue.contextUsage!==void 0&&{contextUsage:Ue.contextUsage},...Ue.model!==void 0&&{model:Ue.model}})},[t,vt]),Nt=h.useCallback(Ue=>{Ue.sessionId===t&&c(Ue.ownership)},[t]),sn=h.useCallback(async Ue=>{Ue.sessionId===t&&((Ue.activity==="idle"||Ue.activity==="in-turn"||Ue.activity==="waiting-input"||Ue.activity==="hold")&&f(Ue.activity),Ue.activity==="waiting-input"&&Ue.pendingInputType&&g(ct=>ct||(Re.getSessionMetadata(e,t).then(on=>{on.pendingInputRequest&&g(on.pendingInputRequest)}),ct)))},[e,t]),ve=h.useCallback(async()=>{Ot();try{const Ue=await Re.getSessionMetadata(e,t);c(Ue.ownership),Ue.ownership.owner==="none"&&(f("idle"),g(null))}catch{}},[e,t,Ot]);qi({onSessionStatusChange:Nt,onFileChange:Be,onSessionUpdated:Pe,onProcessStateChange:sn,onReconnect:ve});const Ye=h.useCallback(()=>{l.owner!=="self"&&be()},[l.owner,be]),{connected:at}=oZ(l.owner!=="self"?{sessionId:t,projectId:e,provider:De==null?void 0:De.provider}:null,{onChange:Ye});h.useEffect(()=>()=>{Jt.current.timer&&clearTimeout(Jt.current.timer)},[]);const Ut=h.useCallback((Ue,ct)=>{$e(on=>{const ls=on[Ue]??{messages:[],status:"running"};return{...on,[Ue]:{...ls,contextUsage:ct}}})},[$e]),{handleStreamEvent:kn,clearStreaming:Yt,cleanup:_n}=cZ({onUpdateMessage:me,onToolUseMapping:ut,onAgentContextUsage:Ut,contextWindowSize:Xf(De==null?void 0:De.model,De==null?void 0:De.provider),streamingMarkdownCallbacks:i});h.useEffect(()=>()=>{_n()},[_n]);const as=h.useCallback(Ue=>{var ct,on,ls;if(Ue.eventType==="message"){S(new Date().toISOString());const Me=Ue,nn=Me.uuid,E=Me.id,M=(typeof nn=="string"?nn:null)??(typeof E=="string"?E:null)??`msg-${Date.now()}`,R=typeof Me.type=="string"?Me.type:void 0,y=Me.role;if(R==="stream_event"&&kn(Me))return;if(R==="assistant"){const xe=Me.isSubagent&&typeof Me.parentToolUseId=="string"?Me.parentToolUseId:void 0;Yt(),xe?$e(ke=>{const Ge=ke[xe];if(!Ge)return ke;const Fe=Ge.messages.filter(Mt=>!Mt._isStreaming);return Fe.length===Ge.messages.length?ke:{...ke,[xe]:{...Ge,messages:Fe}}}):Oe(ke=>ke.filter(Ge=>!Ge._isStreaming))}const L={...Me,id:M,type:R,role:y??(R==="user"||R==="assistant"?R:void 0)};if(L.eventType=void 0,R==="system"&&Me.subtype==="init"&&(Array.isArray(Me.slash_commands)&&W(Me.slash_commands),Array.isArray(Me.tools)&&V(Me.tools),Array.isArray(Me.mcp_servers)&&ge(Me.mcp_servers)),R==="system"&&Me.subtype==="status"){const te=Me.status;U(te==="compacting");return}R==="system"&&Me.subtype==="compact_boundary"&&U(!1);const ee=Me.tempId;if(R==="user"&&ee)ts(ee);else if(R==="user"){const te=dZ(Me);te&&T(xe=>{const ke=xe.findIndex(Ge=>Ge.content.trim()===te);return ke===-1?xe:xe.filter((Ge,Fe)=>Fe!==ke)})}if(Me.isSubagent&&typeof Me.parentToolUseId=="string"){const te=Me.parentToolUseId;ut(te,te),ot(L,te);return}We(L)}else if(Ue.eventType==="status"){const Me=Ue;(Me.state==="idle"||Me.state==="in-turn"||Me.state==="waiting-input"||Me.state==="hold")&&f(Me.state),Me.state==="waiting-input"&&Me.request?(g(Me.request),Me.request.sessionId&&Me.request.sessionId!==t&&_(Me.request.sessionId)):g(null)}else if(Ue.eventType==="deferred-queue")A(Ue.messages??[]);else if(Ue.eventType==="complete")f("idle"),c({owner:"none"}),g(null),A([]);else if(Ue.eventType==="connected"){const Me=Ue,nn=Me.sessionId??((ct=Me.request)==null?void 0:ct.sessionId);nn&&nn!==t&&_(nn),(Me.state==="idle"||Me.state==="in-turn"||Me.state==="waiting-input"||Me.state==="hold")&&f(Me.state),Me.state==="waiting-input"&&Me.request?g(Me.request):g(null),Me.permissionMode&&Me.modeVersion!==void 0&&G(Me.permissionMode,Me.modeVersion);const E=Me.provider,M=Me.model;E&&vt(ee=>ee&&{...ee,provider:ee.provider||E,...M&&{model:M}}),A(Me.deferredMessages??[]);const R=Me.provider??(De==null?void 0:De.provider),y=R==="codex"||R==="codex-oss",L=!Q.current;Q.current=!0,L&&y||Ot()}else if(Ue.eventType==="mode-change"){const Me=Ue;Me.permissionMode&&Me.modeVersion!==void 0&&G(Me.permissionMode,Me.modeVersion)}else if(Ue.eventType==="markdown-augment"){const Me=Ue;Me.messageId&&Me.blockIndex===void 0&&Me.html?z(nn=>({...nn,[Me.messageId]:{html:Me.html}})):Me.blockIndex!==void 0&&((on=i==null?void 0:i.onAugment)==null||on.call(i,{blockIndex:Me.blockIndex,html:Me.html,type:Me.type??"text",messageId:Me.messageId}))}else if(Ue.eventType==="pending"){const Me=Ue;(ls=i==null?void 0:i.onPending)==null||ls.call(i,{html:Me.html})}else if(Ue.eventType==="session-id-changed"){const Me=Ue;Me.newSessionId&&Me.newSessionId!==t&&(_(Me.newSessionId),g(nn=>nn&&nn.sessionId===Me.oldSessionId?{...nn,sessionId:Me.newSessionId}:nn))}},[G,t,kn,Yt,ts,i,We,ot,ut,$e,Oe,vt,Ot,De==null?void 0:De.provider]),Cs=h.useCallback(async()=>{try{(await Re.getSessionMetadata(e,t)).ownership.owner!=="self"&&(c({owner:"none"}),f("idle"))}catch{c({owner:"none"}),f("idle")}},[e,t]),{connected:ns,reconnect:gn}=sZ(l.owner==="self"?t:null,{onMessage:as,onError:Cs}),qn=l.owner==="self"?ns:l.owner==="external"?at:!1,ss=h.useCallback(Ue=>{vt(ct=>ct&&{...ct,model:Ue})},[vt]);return{session:De,setSessionModel:ss,messages:ue,agentContent:_e,setAgentContent:$e,toolUseToAgent:Ke,markdownAugments:O,status:l,processState:d,isCompacting:P,isHeld:d==="hold",pendingInputRequest:m,actualSessionId:w,permissionMode:q,modeVersion:B,loading:tt,error:v,connected:ns,sessionWatchConnected:at,sessionUpdatesConnected:qn,lastStreamActivityAt:C,setStatus:c,setProcessState:f,setPermissionMode:pn,setHold:Nn,pendingMessages:N,addPendingMessage:jt,removePendingMessage:ts,updatePendingMessage:ms,deferredMessages:k,slashCommands:ae,sessionTools:Y,mcpServers:ne,pagination:Tt,loadingOlder:Sn,loadOlderMessages:In,reconnectStream:gn}}function hZ(){const{projectId:e,sessionId:t}=tu();return!e||!t?r.jsx(mZ,{}):r.jsx(qq,{children:r.jsx(pZ,{projectId:e,sessionId:t},t)})}function mZ(){const{t:e}=xt();return r.jsx("div",{className:"error",children:e("sessionInvalidUrl")})}function pZ({projectId:e,sessionId:t}){const{t:s}=xt(),{openSidebar:i,isWideScreen:l,toggleSidebar:c,isSidebarCollapsed:d}=Io(),f=mo(),{project:m}=Dh(e),g=js(),v=ws(),b=v.state,w=b==null?void 0:b.initialStatus,_=b==null?void 0:b.initialTitle,C=b==null?void 0:b.initialModel,S=b==null?void 0:b.initialProvider,N=Y0(),T=h.useMemo(()=>{if(N)return{onAugment:N.dispatchAugment,onPending:N.dispatchPending,onStreamEnd:N.dispatchStreamEnd,setCurrentMessageId:N.setCurrentMessageId,captureHtml:N.captureStreamingHtml}},[N]),{session:k,messages:A,agentContent:P,setAgentContent:U,toolUseToAgent:O,markdownAugments:z,status:q,processState:oe,isCompacting:K,pendingInputRequest:I,actualSessionId:B,permissionMode:Z,loading:Q,error:ae,sessionUpdatesConnected:W,lastStreamActivityAt:Y,setStatus:V,setProcessState:ne,setPermissionMode:ge,setHold:$,isHeld:G,pendingMessages:le,addPendingMessage:fe,removePendingMessage:ue,updatePendingMessage:_e,deferredMessages:Ke,slashCommands:tt,setSessionModel:De,pagination:vt,loadingOlder:me,loadOlderMessages:We,reconnectStream:ot}=fZ(e,t,w,T),{holdModeEnabled:ut,showConnectionBars:$e}=Hi(),{connectionState:Et}=Ah(),Oe=q.owner==="self"||q.owner==="external",Ot=!$e||!Oe?"idle":W?"connected":Et==="reconnecting"?"connecting":"disconnected",Tt=(k==null?void 0:k.provider)??S,Sn=(k==null?void 0:k.model)??C,[In,pn]=h.useState(0),Nn=h.useRef(null),Jt=h.useCallback(Le=>{Nn.current=Le},[]),{showToast:jt}=$h(),[ts,ms]=h.useState(!1);h.useEffect(()=>{Re.getSharingStatus().then(Le=>ms(Le.configured)).catch(()=>{})},[]);const zn=U0(),be=h.useMemo(()=>q.owner==="self"?tt.includes("model")?tt:["model",...tt]:tt,[tt,q.owner]),{providers:Be}=Yh(),Pe=h.useMemo(()=>k!=null&&k.provider?Be.find(Le=>Le.name===k.provider)??null:null,[Be,k==null?void 0:k.provider]),Nt=(Pe==null?void 0:Pe.supportsPermissionMode)??!0,sn=(Pe==null?void 0:Pe.supportsThinkingToggle)??!0;Pe==null||Pe.supportsSlashCommands;const[ve,Ye]=h.useState(!1),[at,Ut]=h.useState(""),[kn,Yt]=h.useState(!1),_n=h.useRef(null),as=h.useRef(!1),[Cs,ns]=h.useState(!1),gn=h.useRef(null),[qn,ss]=h.useState(void 0),[Ue,ct]=h.useState(void 0),[on,ls]=h.useState(void 0),[Me,nn]=h.useState(void 0);h.useEffect(()=>{ss(void 0),ct(void 0),ls(void 0),nn(void 0)},[t]),h.useEffect(()=>{YY(t,e)},[t,e]),h.useEffect(()=>{B&&B!==t&&g(`${f}/projects/${e}/sessions/${B}`,{replace:!0,state:v.state})},[B,t,e,g,v.state,f]);const[E,M]=h.useState([]),[R,y]=h.useState([]),L=h.useRef(new Map),[ee,te]=h.useState(!1),[xe,ke]=h.useState(!1),[Ge,Fe]=h.useState(!1),Mt=(k==null?void 0:k.updatedAt)??null,Qe=h.useMemo(()=>!Mt&&!Y?null:Mt?Y?Mt>Y?Mt:Y:Mt:Y,[Mt,Y]);WY({sessionId:t,activityAt:Qe,updatedAt:Mt,lastSeenAt:k==null?void 0:k.lastSeenAt,hasUnread:k==null?void 0:k.hasUnread,enabled:q.owner!=="external"});const ht=async Le=>{var zt,tn,Kt;const He=fe(Le);ne("in-turn"),pn(Wt=>Wt+1);const it=[...E],Vt=[...L.current.values()];if(Vt.length>0){_e(He,{status:s("sessionUploading")}),M([]);const Wt=await Promise.all(Vt);for(const $n of Wt)$n&&it.push($n);const Zn=new Set(it.map($n=>$n.id));M($n=>$n.filter(po=>!Zn.has(po.id))),_e(He,{status:void 0})}else M([]);try{if(q.owner==="none"){const Wt=(k==null?void 0:k.model)??sh(),Zn=qa(),$n=await Re.resumeSession(e,t,Le,{mode:Z,model:Wt,thinking:Zn,provider:Tt,executor:k==null?void 0:k.executor},it.length>0?it:void 0,He);V({owner:"self",processId:$n.processId})}else{const Wt=qa(),Zn=await Re.queueMessage(t,Le,Z,it.length>0?it:void 0,He,Wt);Zn.restarted&&Zn.processId&&(V({owner:"self",processId:Zn.processId}),ot())}(zt=Nn.current)==null||zt.clearDraft()}catch(Wt){if(console.error("Failed to send:",Wt),Wt instanceof Error&&(Wt.message.includes("404")||Wt.message.includes("No active process")))try{const po=(k==null?void 0:k.model)??sh(),Yi=qa(),zo=await Re.resumeSession(e,t,Le,{mode:Z,model:po,thinking:Yi,provider:Tt,executor:k==null?void 0:k.executor},it.length>0?it:void 0,He);V({owner:"self",processId:zo.processId}),(tn=Nn.current)==null||tn.clearDraft();return}catch(po){console.error("Failed to resume session:",po)}ue(He),(Kt=Nn.current)==null||Kt.restoreFromStorage(),M(it),ne("idle");const $n=Wt instanceof Error?Wt.message:String(Wt);jt(s("sessionSendFailed",{message:$n}),"error")}},bt=async Le=>{var zt,tn;const He=fe(Le);pn(Kt=>Kt+1);const it=[...E],Vt=[...L.current.values()];if(Vt.length>0){_e(He,{status:s("sessionUploading")}),M([]);const Kt=await Promise.all(Vt);for(const Zn of Kt)Zn&&it.push(Zn);const Wt=new Set(it.map(Zn=>Zn.id));M(Zn=>Zn.filter($n=>!Wt.has($n.id))),_e(He,{status:void 0})}else M([]);try{const Kt=qa();await Re.queueMessage(t,Le,Z,it.length>0?it:void 0,He,Kt,!0),ue(He),(zt=Nn.current)==null||zt.clearDraft()}catch(Kt){console.error("Failed to queue deferred message:",Kt),ue(He),(tn=Nn.current)==null||tn.restoreFromStorage(),M(it);const Wt=Kt instanceof Error?Kt.message:String(Kt);jt(s("sessionQueueFailed",{message:Wt}),"error")}},St=h.useCallback(Le=>{De(Le),jt(s("sessionSwitchedModel",{model:Le}),"success")},[De,jt,s]),yt=h.useCallback(Le=>Le==="model"?(Fe(!0),!0):!1,[]),mt=async()=>{if(q.owner==="self"&&q.processId){try{if((await Re.interruptProcess(q.processId)).interrupted)return}catch{}await Re.abortProcess(q.processId)}},gt=h.useCallback(async()=>{if(I)try{await Re.respondToInput(t,I.id,"approve")}catch(Le){const He=Le.status,it=He?`Error ${He}`:s("sessionApproveFailed");jt(it,"error")}},[t,I,jt,s]),et=h.useCallback(async()=>{if(I)try{await Re.respondToInput(t,I.id,"approve_accept_edits"),ge("acceptEdits")}catch(Le){const He=Le.status,it=He?`Error ${He}`:s("sessionApproveFailed");jt(it,"error")}},[t,I,ge,jt,s]),Je=h.useCallback(async()=>{if(I)try{await Re.respondToInput(t,I.id,"deny")}catch(Le){const He=Le.status,it=He?`Error ${He}`:s("sessionDenyFailed");jt(it,"error")}},[t,I,jt,s]),rt=h.useCallback(async Le=>{if(I)try{await Re.respondToInput(t,I.id,"deny",void 0,Le)}catch(He){const it=He.status,Vt=it?`Error ${it}`:s("sessionFeedbackFailed");jt(Vt,"error")}},[t,I,jt,s]),qe=h.useCallback(async Le=>{if(I)try{await Re.respondToInput(t,I.id,"approve",Le)}catch(He){const it=He.status,Vt=it?`Error ${it}`:s("sessionAnswerFailed");jt(Vt,"error")}},[t,I,jt,s]),Xe=h.useCallback(Le=>{for(const He of Le){const it=Fi();y(zt=>[...zt,{fileId:it,fileName:He.name,bytesUploaded:0,totalBytes:He.size,percent:0}]);const Vt=zn.upload(e,t,He,{onProgress:zt=>{y(tn=>tn.map(Kt=>Kt.fileId===it?{...Kt,bytesUploaded:zt,percent:Math.round(zt/He.size*100)}:Kt))}}).then(zt=>(M(tn=>[...tn,zt]),zt),zt=>{console.error("Upload failed:",zt);const tn=zt instanceof Error?zt.message:s("sessionShareFailed");return jt(s("sessionUploadFailed",{file:He.name,message:tn}),"error"),null}).finally(()=>{y(zt=>zt.filter(tn=>tn.fileId!==it)),L.current.delete(it)});L.current.set(it,Vt)}},[e,t,jt,zn,s]),nt=h.useCallback(Le=>{M(He=>He.filter(it=>it.id!==Le))},[]),Ve=(I==null?void 0:I.toolName)==="AskUserQuestion",de=oe==="in-turn"||oe==="waiting-input"||Oe&&!W,he=h.useMemo(()=>q.owner!=="none"?!1:Zh(A).some(He=>He.type==="tool_call"&&He.status==="pending"),[A,q.owner]),Te=Do(k),ye=qn??(Te!=="Untitled"?Te:null)??_??s("sessionUntitled"),Se=Ue??(k==null?void 0:k.isArchived)??!1,Ce=on??(k==null?void 0:k.isStarred)??!1;Wh(m==null?void 0:m.name,ye);const dt=()=>{Ut(ye),Ye(!0),setTimeout(()=>{var Le,He;(Le=_n.current)==null||Le.focus(),(He=_n.current)==null||He.select()},0)},At=()=>{as.current||(Ye(!1),Ut(""))},Rt=()=>{if(!as.current){if(!at.trim()||at.trim()===ye){At();return}_t()}},_t=async()=>{if(!(!at.trim()||kn)){as.current=!0,Yt(!0);try{await Re.updateSessionMetadata(t,{title:at.trim()}),ss(at.trim()),Ye(!1),jt(s("sessionRenamed"),"success")}catch(Le){console.error("Failed to rename session:",Le),jt(s("sessionRenameFailed"),"error")}finally{Yt(!1),as.current=!1}}},F=Le=>{Le.key==="Enter"?(Le.preventDefault(),_t()):Le.key==="Escape"&&(Le.preventDefault(),At())},Pt=async()=>{const Le=!Se;try{await Re.updateSessionMetadata(t,{archived:Le}),ct(Le),jt(s(Le?"sessionArchived":"sessionUnarchived"),"success")}catch(He){console.error("Failed to update archive status:",He),jt(s("sessionArchiveFailed"),"error")}},Ct=async()=>{const Le=!Ce;try{await Re.updateSessionMetadata(t,{starred:Le}),ls(Le),jt(s(Le?"sessionStarred":"sessionUnstarred"),"success")}catch(He){console.error("Failed to update star status:",He),jt(s("sessionStarFailed"),"error")}},Ht=Me??(k==null?void 0:k.hasUnread)??!1,Dt=async()=>{const Le=!Ht;nn(Le);try{Le?await Re.markSessionUnread(t):await Re.markSessionSeen(t),jt(s(Le?"sessionMarkedUnread":"sessionMarkedRead"),"success")}catch(He){console.error("Failed to update read status:",He),nn(void 0),jt(s("sessionReadFailed"),"error")}},qt=async()=>{if(q.owner==="self"&&q.processId)try{await Re.abortProcess(q.processId),jt(s("sessionTerminated"),"success")}catch(Le){console.error("Failed to terminate session:",Le);const He=Le instanceof Error?Le.message:String(Le);jt(s("sessionTerminateFailed",{message:He}),"error")}},It=h.useCallback(async()=>{try{const{snapshotSession:Le}=await _i(async()=>{const{snapshotSession:Vt}=await import("./snapshotSession-CUC6Plno.js");return{snapshotSession:Vt}},[]),He=Le(ye),it=await Re.shareSession(He,ye);await navigator.clipboard.writeText(it.url),jt(s("sessionLinkCopied"),"success")}catch(Le){const He=Le instanceof Error?Le.message:s("sessionShareFailed");jt(He,"error")}},[ye,jt,s]);if(ae)return r.jsxs("div",{className:"error",children:[s("sessionErrorPrefix")," ",ae.message]});const Cn=()=>r.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]});return r.jsx("div",{className:l?"main-content-wrapper":"main-content-mobile",children:r.jsxs("div",{className:l?"main-content-constrained":"main-content-mobile-inner",children:[r.jsx("header",{className:"session-header",children:r.jsxs("div",{className:"session-header-inner",children:[r.jsxs("div",{className:"session-header-left",children:[!(l&&d)&&r.jsx("button",{type:"button",className:"sidebar-toggle",onClick:l?c:i,title:s(l?"sessionToggleSidebar":"sessionOpenSidebar"),"aria-label":s(l?"sessionToggleSidebar":"sessionOpenSidebar"),children:r.jsx(Cn,{})}),(m==null?void 0:m.name)&&r.jsx(Xs,{to:`${f}/sessions?project=${e}`,className:"project-breadcrumb",title:m.name,children:m.name.length>12?`${m.name.slice(0,12)}...`:m.name}),r.jsxs("div",{className:"session-title-row",children:[Ce&&r.jsxs("svg",{className:"star-indicator-inline",width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",role:"img","aria-label":s("sessionStarredLabel"),children:[r.jsx("title",{children:s("sessionStarredLabel")}),r.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})]}),Q?r.jsx("span",{className:"session-title-skeleton"}):ve?r.jsx("input",{ref:_n,type:"text",className:"session-title-input",value:at,onChange:Le=>Ut(Le.target.value),onKeyDown:F,onBlur:Rt,disabled:kn}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{ref:gn,type:"button",className:"session-title session-title-dropdown-trigger",onClick:()=>ns(!Cs),title:(k==null?void 0:k.fullTitle)??ye,children:[r.jsx("span",{className:"session-title-text",children:ye}),r.jsx("svg",{className:"session-title-chevron",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),r.jsx(BY,{currentSessionId:t,isOpen:Cs,onClose:()=>ns(!1),onNavigate:()=>ns(!1),triggerRef:gn,basePath:f})]}),!Q&&Se&&r.jsx("span",{className:"archived-badge",children:s("sessionArchivedBadge")}),!Q&&r.jsx(N0,{sessionId:t,projectId:e,isStarred:Ce,isArchived:Se,hasUnread:Ht,provider:k==null?void 0:k.provider,processId:q.owner==="self"?q.processId:void 0,onToggleStar:Ct,onToggleArchive:Pt,onToggleRead:Dt,onRename:dt,onClone:Le=>{g(`${f}/projects/${e}/sessions/${Le}`)},onTerminate:qt,sharingConfigured:ts,onShare:It,useFixedPositioning:!0,useEllipsisIcon:!0})]})]}),r.jsx("div",{className:"session-header-right",children:!Q&&Tt&&r.jsx("button",{type:"button",className:"provider-badge-button",onClick:()=>ke(!0),title:s("sessionViewInfo"),children:r.jsx(UY,{provider:Tt,model:Sn,isThinking:oe==="in-turn"})})})]})}),xe&&k&&r.jsx(DY,{sessionId:B,provider:k.provider,model:k.model,status:q,processState:oe,contextUsage:k.contextUsage,originator:k.originator,cliVersion:k.cliVersion,sessionSource:k.source,approvalPolicy:k.approvalPolicy,sandboxPolicy:k.sandboxPolicy,createdAt:k.createdAt,sessionStreamConnected:W,lastSessionEventAt:Y,onClose:()=>ke(!1)}),Ge&&q.owner==="self"&&q.processId&&r.jsx(kY,{processId:q.processId,currentModel:k==null?void 0:k.model,onModelChanged:St,onClose:()=>Fe(!1)}),q.owner==="external"&&r.jsx("div",{className:"external-session-warning",children:s("sessionExternalWarning")}),he&&r.jsx("div",{className:"external-session-warning pending-tool-warning",children:s("sessionPendingElsewhereWarning")}),r.jsx("main",{className:"session-messages",children:Q?r.jsx("div",{className:"loading",children:s("sessionLoading")}):r.jsx(TV,{projectId:e,projectPath:(m==null?void 0:m.path)??null,sessionId:t,children:r.jsx(gW,{agentContent:P,setAgentContent:U,toolUseToAgent:O,projectId:e,sessionId:t,children:r.jsx(CY,{messages:A,provider:k==null?void 0:k.provider,isProcessing:q.owner==="self"&&oe==="in-turn",isCompacting:K,scrollTrigger:In,pendingMessages:le,deferredMessages:Ke,onCancelDeferred:Le=>Re.cancelDeferredMessage(t,Le),markdownAugments:z,activeToolApproval:de,hasOlderMessages:vt==null?void 0:vt.hasOlderMessages,loadingOlder:me,onLoadOlderMessages:We})})})}),r.jsxs("footer",{className:"session-input",children:[r.jsx("div",{className:`session-connection-bar session-connection-${Ot}`}),r.jsxs("div",{className:"session-input-inner",children:[I&&I.sessionId===B&&Ve&&r.jsx(PY,{request:I,sessionId:B,onSubmit:qe,onDeny:Je}),I&&I.sessionId===B&&!Ve&&r.jsxs(r.Fragment,{children:[r.jsx(qY,{request:I,sessionId:B,onApprove:gt,onDeny:Je,onApproveAcceptEdits:et,onDenyWithFeedback:rt,collapsed:ee,onCollapsedChange:te}),r.jsx(z0,{mode:Z,onModeChange:ge,isHeld:ut?G:void 0,onHoldChange:ut?$:void 0,supportsPermissionMode:Nt,supportsThinkingToggle:sn,contextUsage:k==null?void 0:k.contextUsage,isRunning:q.owner==="self",isThinking:oe==="in-turn",onStop:mt,pendingApproval:ee?{type:"tool-approval",onExpand:()=>te(!1)}:void 0})]}),!(I&&I.sessionId===B&&!Ve)&&r.jsx(rq,{onSend:ht,onQueue:q.owner!=="none"&&oe!=="idle"?bt:void 0,placeholder:q.owner==="external"?s("sessionPlaceholderExternal"):s(oe==="idle"?"sessionPlaceholderResume":"sessionPlaceholderQueue"),mode:Z,onModeChange:ge,isHeld:ut?G:void 0,onHoldChange:ut?$:void 0,supportsPermissionMode:Nt,supportsThinkingToggle:sn,isRunning:q.owner==="self",isThinking:oe==="in-turn",onStop:mt,draftKey:`draft-message-${t}`,onDraftControlsReady:Jt,collapsed:!!(I&&I.sessionId===B),contextUsage:k==null?void 0:k.contextUsage,projectId:e,sessionId:t,attachments:E,onAttach:Xe,onRemoveAttachment:nt,uploadProgress:R,slashCommands:q.owner==="self"?be:[],onCustomCommand:yt})]})]})]})})}function gZ(e,t){switch(e){case"auto":return t("themeAuto");case"light":return t("themeLight");case"dark":return t("themeDark");case"verydark":return t("themeVerydark")}}function xZ(e,t){switch(e){case"small":return t("fontSizeSmall");case"default":return t("fontSizeDefault");case"large":return t("fontSizeLarge");case"larger":return t("fontSizeLarger")}}function vZ(e,t){switch(e){case"en":return t("localeNameEn");case"zh-CN":return t("localeNameZhCn");case"es":return t("localeNameEs");case"fr":return t("localeNameFr");case"de":return t("localeNameDe");case"ja":return t("localeNameJa")}}function bZ(e){return[{id:"appearance",label:e("settingsAppearanceTitle"),icon:"🎨",description:e("settingsAppearanceDescription")},{id:"model",label:e("settingsModelTitle"),icon:"🧠",description:e("settingsModelDescription")},{id:"agent-context",label:e("settingsAgentContextTitle"),icon:"📋",description:e("settingsAgentContextDescription")},{id:"notifications",label:e("settingsNotificationsTitle"),icon:"🔔",description:e("settingsNotificationsDescription")},{id:"webhooks",label:e("settingsWebhooksTitle"),icon:"🪝",description:e("settingsWebhooksDescription")},{id:"devices",label:e("settingsDevicesTitle"),icon:"📱",description:e("settingsDevicesDescription")},{id:"local-access",label:e("settingsLocalAccessTitle"),icon:"🔒",description:e("settingsLocalAccessDescription")},{id:"remote",label:e("settingsRemoteTitle"),icon:"🌐",description:e("settingsRemoteDescription")},{id:"providers",label:e("settingsProvidersTitle"),icon:"🔌",description:e("settingsProvidersDescription")},{id:"remote-executors",label:e("settingsRemoteExecutorsTitle"),icon:"🖥️",description:e("settingsRemoteExecutorsDescription")},{id:"about",label:e("settingsAboutTitle"),icon:"ℹ️",description:e("settingsAboutDescription")}]}function yZ(e){return{id:"emulator",label:e("settingsEmulatorTitle"),icon:"🤖",description:e("settingsEmulatorDescription")}}function SZ(e){return{id:"development",label:e("settingsDevelopmentTitle"),icon:"🛠️",description:e("settingsDevelopmentDescription")}}let Pr=null;function wZ(){const[e,t]=h.useState(!1),[s,i]=h.useState(!1);h.useEffect(()=>{if(window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0){i(!0);return}Pr&&t(!0);const d=m=>{m.preventDefault(),Pr=m,t(!0)},f=()=>{i(!0),t(!1),Pr=null};return window.addEventListener("beforeinstallprompt",d),window.addEventListener("appinstalled",f),()=>{window.removeEventListener("beforeinstallprompt",d),window.removeEventListener("appinstalled",f)}},[]);const l=h.useCallback(async()=>{if(!Pr)return!1;await Pr.prompt();const{outcome:c}=await Pr.userChoice;return c==="accepted"?(t(!1),Pr=null,!0):!1},[]);return{canInstall:e,isInstalled:s,install:l}}function jZ(){const{t:e}=xt(),{canInstall:t,isInstalled:s,install:i}=wZ(),{version:l,loading:c,error:d,refetchFresh:f}=il({freshOnMount:!0}),m=Vi(),{resetOnboarding:g}=h0(),{remoteLogCollectionEnabled:v,setRemoteLogCollectionEnabled:b}=Hi(),w=!!(m!=null&&m.currentRelayUsername),_=((l==null?void 0:l.resumeProtocolVersion)??1)>=2,C=w&&!!l&&!_,[S,N]=h.useState(!1),[T,k]=h.useState(0);h.useEffect(()=>{Ie("/status/workers").then(P=>k(P.activeWorkers)).catch(()=>{})},[]),h.useEffect(()=>{if(S)return En.on("reconnect",()=>{N(!1)})},[S]);const A=h.useCallback(async()=>{N(!0);try{await Re.restartServer()}catch{}},[]);return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("aboutTitle")}),r.jsxs("div",{className:"settings-group",children:[(t||s)&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutInstallTitle")}),r.jsx("p",{children:e(s?"aboutInstalledDescription":"aboutInstallDescription")})]}),s?r.jsx("span",{className:"settings-status-badge",children:e("aboutInstalled")}):r.jsx("button",{type:"button",className:"settings-button",onClick:i,children:e("aboutInstall")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutVersionTitle")}),r.jsxs("p",{children:[e("aboutServerVersion")," ",l?r.jsxs(r.Fragment,{children:["v",l.current,l.updateAvailable&&l.latest?r.jsxs("span",{className:"settings-update-available",children:[" ",e("aboutVersionAvailable",{version:l.latest})]}):l.latest?r.jsxs("span",{className:"settings-up-to-date",children:[" ",e("aboutUpToDate")]}):null]}):e("loginLoading")]}),r.jsxs("p",{children:[e("aboutClientVersion")," v","0.4.28"]}),d&&r.jsx("p",{className:"settings-warning",children:e("aboutUnableRefresh")}),C&&r.jsx("p",{className:"settings-warning",children:e("aboutRelayResumeWarning")}),(l==null?void 0:l.updateAvailable)&&r.jsx("p",{className:"settings-update-hint",children:e("aboutUpdateHint")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:()=>void f(),disabled:c,children:e(c?"aboutChecking":"aboutCheckUpdates")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentRestartTitle")}),r.jsx("p",{children:e("developmentRestartDescription")}),T>0&&!S&&r.jsx("p",{className:"settings-warning",children:e("developmentInterruptedWarning",{count:T,suffix:T!==1?"s ":" "})})]}),r.jsx("button",{type:"button",className:`settings-button ${T>0?"settings-button-danger":""}`,onClick:A,disabled:S,children:S?e("developmentRestarting"):T>0?e("developmentRestartAnyway"):e("developmentRestart")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutReportBugTitle")}),r.jsx("p",{children:e("aboutReportBugDescription")})]}),r.jsx("a",{href:"https://github.com/kzahel/yepanywhere/issues",target:"_blank",rel:"noopener noreferrer",className:"settings-button",children:e("aboutReportBug")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutSetupWizardTitle")}),r.jsx("p",{children:e("aboutSetupWizardDescription")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:g,children:e("aboutLaunchWizard")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("aboutDiagnosticsTitle")}),r.jsx("p",{children:e("aboutDiagnosticsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:v,onChange:P=>b(P.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]})]})}const Lb=1e4;function EZ(){const{t:e}=xt(),{settings:t,isLoading:s,error:i,updateSetting:l}=io(),[c,d]=h.useState(""),[f,m]=h.useState(!1),[g,v]=h.useState(!1),[b,w]=h.useState(null);h.useEffect(()=>{t&&d(t.globalInstructions??"")},[t]);const _=h.useCallback(async()=>{m(!0),w(null);try{await l("globalInstructions",c.trim()||void 0),v(!1)}catch(S){w(S instanceof Error?S.message:e("agentContextSaveFailed"))}finally{m(!1)}},[c,l,e]);if(s)return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("agentContextTitle")}),r.jsx("p",{className:"settings-section-description",children:e("agentContextLoading")})]});const C=(t==null?void 0:t.globalInstructions)??"";return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("agentContextTitle")}),r.jsx("p",{className:"settings-section-description",children:e("agentContextDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",style:{flexDirection:"column",alignItems:"stretch"},children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("agentContextGlobalInstructions")}),r.jsx("p",{children:e("agentContextGlobalInstructionsDescription")})]}),r.jsx("textarea",{className:"settings-textarea",value:c,onChange:S=>{const N=S.target.value.slice(0,Lb);d(N),v(N!==C),w(null)},placeholder:e("agentContextPlaceholder"),rows:10}),r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"var(--space-2)"},children:[r.jsx("span",{className:"settings-hint",children:e("agentContextCharacters",{current:c.length.toLocaleString(),max:Lb.toLocaleString()})}),r.jsx("button",{type:"button",className:"settings-button",disabled:!g||f,onClick:_,children:e(f?"providersSaving":"providersSave")})]}),(b||i)&&r.jsx("p",{className:"settings-warning",children:b||i})]})})]})}function NZ(){const{locale:e,setLocale:t,t:s}=xt(),{fontSize:i,setFontSize:l}=zF(),{tabSize:c,setTabSize:d}=FF(),{theme:f,setTheme:m}=i0(),{streamingEnabled:g,setStreamingEnabled:v}=iZ(),{funPhrasesEnabled:b,setFunPhrasesEnabled:w}=wq(),{showConnectionBars:_,setShowConnectionBars:C}=Hi(),S=N=>s(N);return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:s("appearanceSectionTitle")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceLanguageTitle")}),r.jsx("p",{children:s("appearanceLanguageDescription")})]}),r.jsx("select",{className:"settings-select",value:e,onChange:N=>t(N.target.value),"aria-label":s("appearanceLanguageTitle"),children:Xy.map(N=>r.jsx("option",{value:N,children:vZ(N,S)},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceThemeTitle")}),r.jsx("p",{children:s("appearanceThemeDescription")})]}),r.jsx("div",{className:"font-size-selector",children:Ph.map(N=>r.jsx("button",{type:"button",className:`font-size-option ${f===N?"active":""}`,onClick:()=>m(N),children:gZ(N,S)},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceFontSizeTitle")}),r.jsx("p",{children:s("appearanceFontSizeDescription")})]}),r.jsx("div",{className:"font-size-selector",children:g0.map(N=>r.jsx("button",{type:"button",className:`font-size-option ${i===N?"active":""}`,onClick:()=>l(N),children:xZ(N,S)},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceTabSizeTitle")}),r.jsx("p",{children:s("appearanceTabSizeDescription")})]}),r.jsx("div",{className:"font-size-selector",children:b0.map(N=>r.jsx("button",{type:"button",className:`font-size-option ${c===N?"active":""}`,onClick:()=>d(N),children:N},N))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceStreamingTitle")}),r.jsx("p",{children:s("appearanceStreamingDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:N=>v(N.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceFunPhrasesTitle")}),r.jsx("p",{children:s("appearanceFunPhrasesDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:b,onChange:N=>w(N.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:s("appearanceConnectionBarsTitle")}),r.jsx("p",{children:s("appearanceConnectionBarsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:_,onChange:N=>C(N.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]})]})}function _Z(){const{t:e}=xt(),{isManualReloadMode:t,pendingReloads:s,connected:i,reloadBackend:l,unsafeToRestart:c,workerActivity:d}=Bh(),{settings:f,setEnabled:m}=c0(),{holdModeEnabled:g,setHoldModeEnabled:v}=Hi(),{ignoredTools:b,clearIgnoredTools:w}=es(),{settings:_,updateSetting:C}=io(),[S,N]=h.useState(!1);h.useEffect(()=>{S&&i&&N(!1)},[S,i]);const T=async()=>{N(!0),await l()};return t?r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("developmentSectionTitle")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentSchemaTitle")}),r.jsx("p",{children:e("developmentSchemaDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:f.enabled,onChange:k=>m(k.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),b.length>0&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentIgnoredToolsTitle")}),r.jsx("p",{children:e("developmentIgnoredToolsDescription")}),r.jsx("div",{className:"ignored-tools-list",children:b.map(k=>r.jsx("span",{className:"ignored-tool-badge",children:k},k))})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-secondary",onClick:w,children:e("developmentClearIgnored")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentHoldModeTitle")}),r.jsx("p",{children:e("developmentHoldModeDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:k=>v(k.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentServiceWorkerTitle")}),r.jsx("p",{children:e("developmentServiceWorkerDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(_==null?void 0:_.serviceWorkerEnabled)??!0,onChange:k=>C("serviceWorkerEnabled",k.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentRestartTitle")}),r.jsxs("p",{children:[e("developmentRestartDescription"),s.backend&&r.jsxs("span",{className:"settings-pending",children:[" ",e("developmentChangesPending")]})]}),c&&r.jsx("p",{className:"settings-warning",children:e("developmentInterruptedWarning",{count:d.activeWorkers,suffix:d.activeWorkers!==1?"s ":" "})})]}),r.jsx("button",{type:"button",className:`settings-button ${c?"settings-button-danger":""}`,onClick:T,disabled:S,children:e(S?"developmentRestarting":c?"developmentRestartAnyway":"developmentRestart")})]})})]}):null}function CZ(){const[e,t]=h.useState({profiles:[],isLoading:!0,error:null}),s=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{profiles:l}=await Re.getBrowserProfiles();t({profiles:l,isLoading:!1,error:null})}catch(l){console.error("[useBrowserProfiles] Failed to fetch:",l),t(c=>({...c,isLoading:!1,error:l instanceof Error?l.message:"Failed to load profiles"}))}},[]);h.useEffect(()=>{s()},[s]);const i=h.useCallback(async l=>{t(c=>({...c,isLoading:!0,error:null}));try{await Re.deleteBrowserProfile(l),await s()}catch(c){console.error("[useBrowserProfiles] Failed to delete:",c),t(d=>({...d,isLoading:!1,error:c instanceof Error?c.message:"Failed to delete profile"}))}},[s]);return{...e,deleteProfile:i,refetch:s}}function xS(){const[e,t]=h.useState({connections:new Map,isLoading:!0,error:null}),s=h.useCallback(async()=>{t(i=>({...i,isLoading:!0,error:null}));try{const{connections:i}=await Re.getConnections(),l=new Map;for(const c of i)l.set(c.browserProfileId,c);t({connections:l,isLoading:!1,error:null})}catch(i){console.error("[useConnectedDevices] Failed to fetch:",i),t(l=>({...l,isLoading:!1,error:i instanceof Error?i.message:"Failed to load connections"}))}},[]);return h.useEffect(()=>{s()},[s]),h.useEffect(()=>{const i=En.on("browser-tab-connected",f=>{t(m=>{var v;const g=new Map(m.connections);return g.set(f.browserProfileId,{browserProfileId:f.browserProfileId,connectionCount:f.tabCount,connectedAt:f.timestamp,deviceName:(v=m.connections.get(f.browserProfileId))==null?void 0:v.deviceName}),{...m,connections:g}})}),l=En.on("browser-tab-disconnected",f=>{t(m=>{const g=new Map(m.connections);if(f.tabCount===0)g.delete(f.browserProfileId);else{const v=g.get(f.browserProfileId);v&&g.set(f.browserProfileId,{...v,connectionCount:f.tabCount})}return{...m,connections:g}})}),c=En.on("reconnect",()=>{s()}),d=En.on("refresh",()=>{s()});return()=>{i(),l(),c(),d()}},[s]),{...e,connectionList:Array.from(e.connections.values()),refetch:s}}const kZ="/sw.js";function sm(){const[e,t]=h.useState({isSupported:!1,isSubscribed:!1,isLoading:!0,error:null,permission:"default",browserProfileId:null}),[s,i]=h.useState(null),l=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;h.useEffect(()=>{(async()=>{if(!l){const b=Po("browserProfileId",Ss.browserProfileId);t(w=>({...w,isSupported:!1,isLoading:!1,error:"Push notifications not supported in this browser",browserProfileId:b}));return}try{const b=await navigator.serviceWorker.register(kZ);i(b),await navigator.serviceWorker.ready;const w=await b.pushManager.getSubscription(),_=Fa();t({isSupported:!0,isSubscribed:!!w,isLoading:!1,error:null,permission:Notification.permission,browserProfileId:_})}catch(b){console.error("[usePushNotifications] Init error:",b),t(w=>({...w,isSupported:!0,isLoading:!1,error:b instanceof Error?b.message:"Failed to initialize"}))}})()},[l]);const c=h.useCallback(async()=>{if(!s){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await Notification.requestPermission();if(t(N=>({...N,permission:v})),v!=="granted"){t(N=>({...N,isLoading:!1,error:"Notification permission denied"}));return}const{publicKey:b}=await Re.getPushPublicKey(),w=TZ(b),_=await s.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:w.buffer}),C=Fa(),S=_.toJSON();await Re.subscribePush(C,S,AZ()),t(N=>({...N,isSubscribed:!0,isLoading:!1,error:null,browserProfileId:C}))}catch(v){console.error("[usePushNotifications] Subscribe error:",v),t(b=>({...b,isLoading:!1,error:v instanceof Error?v.message:"Failed to subscribe"}))}},[s]),d=h.useCallback(async()=>{if(!s){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await s.pushManager.getSubscription();v&&await v.unsubscribe();const b=Fa();await Re.unsubscribePush(b),t(w=>({...w,isSubscribed:!1,isLoading:!1,error:null}))}catch(v){console.error("[usePushNotifications] Unsubscribe error:",v),t(b=>({...b,isLoading:!1,error:v instanceof Error?v.message:"Failed to unsubscribe"}))}},[s]),f=h.useCallback(async(v="normal")=>{const b=Fa();t(w=>({...w,isLoading:!0,error:null}));try{await Re.testPush(b,void 0,v),t(w=>({...w,isLoading:!1}))}catch(w){console.error("[usePushNotifications] Test push error:",w),t(_=>({..._,isLoading:!1,error:w instanceof Error?w.message:"Failed to send test"}))}},[]),m=h.useCallback(async()=>{var b;const v=(b=navigator.serviceWorker)==null?void 0:b.controller;return v?new Promise(w=>{const _=new MessageChannel;_.port1.onmessage=C=>{var S;w(((S=C.data)==null?void 0:S.logs)||[])},v.postMessage({type:"get-sw-logs"},[_.port2]),setTimeout(()=>w([]),2e3)}):(console.warn("[usePushNotifications] No active service worker"),[])},[]),g=h.useCallback(async()=>{var b;const v=(b=navigator.serviceWorker)==null?void 0:b.controller;if(v)return new Promise(w=>{const _=new MessageChannel;_.port1.onmessage=()=>w(),v.postMessage({type:"clear-sw-logs"},[_.port2]),setTimeout(w,1e3)})},[]);return{...e,subscribe:c,unsubscribe:d,sendTest:f,getSwLogs:m,clearSwLogs:g}}function TZ(e){const t="=".repeat((4-e.length%4)%4),s=(e+t).replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(s),l=new Uint8Array(i.length);for(let c=0;c<i.length;++c)l[c]=i.charCodeAt(c);return l}function AZ(){const e=navigator.userAgent;return/iPhone/.test(e)?"iPhone":/iPad/.test(e)?"iPad":/Android/.test(e)?"Android":/Mac/.test(e)?"Mac":/Windows/.test(e)?"Windows":/Linux/.test(e)?"Linux":"Browser"}function Ob(e,t){const s=new Date(e),l=new Date().getTime()-s.getTime(),c=Math.floor(l/(1e3*60)),d=Math.floor(l/(1e3*60*60)),f=Math.floor(l/(1e3*60*60*24));return c<1?t("devicesJustNow"):c<60?t("devicesMinutesAgo",{count:c,suffix:c===1?"":"s"}):d<24?t("devicesHoursAgo",{count:d,suffix:d===1?"":"s"}):f===1?t("devicesYesterday"):f<7?`${f} days ago`:s.toLocaleDateString()}function RZ(){const{t:e}=xt(),{profiles:t,isLoading:s,error:i,deleteProfile:l}=CZ(),{browserProfileId:c}=sm(),{connections:d}=xS();return r.jsx(r.Fragment,{children:r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("devicesProfilesTitle")}),r.jsx("p",{className:"settings-section-description",children:e("devicesProfilesDescription")}),i&&r.jsx("p",{className:"form-error",children:i}),r.jsx("div",{className:"settings-group",children:s?r.jsx("p",{className:"settings-hint",children:e("devicesLoadingProfiles")}):t.length===0?r.jsx("p",{className:"settings-hint",children:e("devicesEmpty")}):r.jsx("div",{className:"device-list",children:t.map(f=>{const m=f.browserProfileId===c,g=d.has(f.browserProfileId),v=f.deviceName||`${f.browserProfileId.slice(0,8)}...`;return r.jsxs("div",{className:"device-list-item device-profile-item",children:[r.jsxs("div",{className:"device-list-info",children:[r.jsxs("strong",{children:[r.jsx("span",{className:`device-status ${g?"device-status-online":"device-status-offline"}`,title:e(g?"devicesConnected":"devicesDisconnected")}),v,m&&r.jsx("span",{className:"device-current-badge",children:e("devicesThisDevice")})]}),r.jsx("div",{className:"device-origins",children:f.origins.map(b=>{const{browser:w,os:_}=s0(b.userAgent);return r.jsxs("div",{className:"device-origin",children:[r.jsx("code",{className:"device-origin-url",children:b.origin}),r.jsxs("span",{className:"device-origin-details",children:[w," · ",_]}),r.jsx("span",{className:"device-origin-time",children:e("devicesLastSeen",{date:Ob(b.lastSeen,e)})})]},b.origin)})}),r.jsx("p",{className:"device-profile-meta",children:e("devicesFirstSeen",{date:Ob(f.createdAt,e)})})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>l(f.browserProfileId),title:e("devicesForgetThisDevice"),children:e("devicesForget")})]},f.browserProfileId)})})})]})})}const MZ=["high","medium","low"];function DZ(e,t,s){return s!=null&&s.length?s.includes("start"):e==="emulator"&&t==="stopped"}function LZ(e,t,s){return s!=null&&s.length?s.includes("stop"):e==="emulator"&&t!=="stopped"}function OZ(){const{t:e}=xt(),{emulators:t,loading:s,error:i,startEmulator:l,stopEmulator:c,refresh:d}=D0(),{maxFps:f,setMaxFps:m,maxWidth:g,setMaxWidth:v,quality:b,setQuality:w,adaptiveFps:_,setAdaptiveFps:C}=M0(),{settings:S,isLoading:N,error:T,updateSetting:k}=io(),[A,P]=h.useState(""),[U,O]=h.useState(null),z=(S==null?void 0:S.chromeOsHosts)??[],q=async()=>{const I=A.trim();if(!I){O(e("emulatorHostAliasRequired"));return}if(/\s/.test(I)){O(e("emulatorHostAliasNoSpaces"));return}const B=Array.from(new Set([...z,I]));try{await k("chromeOsHosts",B),P(""),O(null),await d()}catch(Z){O(Z instanceof Error?Z.message:e("emulatorHostAliasSaveFailed"))}},oe=async I=>{const B=z.filter(Z=>Z.toLowerCase()!==I.toLowerCase());try{await k("chromeOsHosts",B),O(null),await d()}catch(Z){O(Z instanceof Error?Z.message:e("emulatorHostAliasRemoveFailed"))}},K=(S==null?void 0:S.deviceBridgeEnabled)??!1;return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("emulatorSectionTitle")}),r.jsx("p",{className:"settings-description",children:e("emulatorSectionDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorEnableTitle")}),r.jsx("p",{children:e("emulatorEnableDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:K,onChange:I=>{k("deviceBridgeEnabled",I.target.checked)},disabled:N}),r.jsx("span",{className:"toggle-slider"})]})]})}),K?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("emulatorStreamQualityTitle")}),r.jsx("p",{className:"settings-description",children:e("emulatorStreamQualityDescription")}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorFrameRateTitle")}),r.jsx("p",{children:e("emulatorFrameRateDescription")})]}),r.jsx("div",{className:"font-size-selector",children:_0.map(I=>r.jsxs("button",{type:"button",className:`font-size-option ${f===I?"active":""}`,onClick:()=>m(I),children:[I," fps"]},I))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorResolutionTitle")}),r.jsx("p",{children:e("emulatorResolutionDescription")})]}),r.jsx("div",{className:"font-size-selector",children:C0.map(I=>r.jsxs("button",{type:"button",className:`font-size-option ${g===I?"active":""}`,onClick:()=>v(I),children:[I,"p"]},I))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorQualityTitle")}),r.jsx("p",{children:e("emulatorQualityDescription")})]}),r.jsx("div",{className:"font-size-selector",children:MZ.map(I=>r.jsx("button",{type:"button",className:`font-size-option ${b===I?"active":""}`,onClick:()=>w(I),children:FH(I)},I))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorAdaptiveFpsTitle")}),r.jsx("p",{children:e("emulatorAdaptiveFpsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:_,onChange:I=>C(I.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("emulatorChromeOsHostsTitle")}),r.jsxs("p",{className:"settings-description",children:[e("emulatorChromeOsHostsDescription"),r.jsx("code",{children:" chromeroot"}),e("emulatorChromeOsHostsDescriptionSuffix")]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("emulatorAddHostAliasTitle")}),r.jsx("p",{children:e("emulatorAddHostAliasDescription")})]}),r.jsxs("form",{className:"settings-item-actions",onSubmit:I=>{I.preventDefault(),q()},children:[r.jsx("input",{type:"text",name:"chromeosHost",placeholder:e("emulatorHostAliasPlaceholder"),className:"settings-select",autoComplete:"off",value:A,onChange:I=>P(I.target.value)}),r.jsx("button",{type:"submit",className:"settings-button",disabled:N,children:e("projectsAddConfirm")})]})]}),U&&r.jsx("p",{className:"settings-error",children:U}),T&&r.jsx("p",{className:"settings-error",children:T}),z.length===0?r.jsx("p",{className:"settings-muted",children:e("emulatorNoChromeOsHosts")}):z.map(I=>r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("span",{className:"settings-item-label",children:I}),r.jsxs("span",{className:"settings-item-description",children:["Device ID: chromeos:",I]})]}),r.jsx("div",{className:"settings-item-action",children:r.jsx("button",{type:"button",className:"settings-button",onClick:()=>{oe(I)},disabled:N,children:e("emulatorRemove")})})]},I))]}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("emulatorDiscoveredDevicesTitle")}),s&&r.jsx("p",{className:"settings-muted",children:e("projectsLoading")}),i&&r.jsx("p",{className:"settings-error",children:i}),!s&&t.length===0&&r.jsx("p",{className:"settings-muted",children:e("emulatorNoDevicesFound")}),t.map(I=>r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("span",{className:"settings-item-label",children:I.label||I.avd||I.id}),r.jsxs("span",{className:"settings-item-description",children:[I.type," - ",I.id," - ",I.state]})]}),r.jsx("div",{className:"settings-item-action",children:LZ(I.type,I.state,I.actions)?r.jsx("button",{type:"button",className:"settings-button",onClick:()=>c(I.id),children:e("emulatorStop")}):DZ(I.type,I.state,I.actions)?r.jsx("button",{type:"button",className:"settings-button",onClick:()=>l(I.id),children:e("emulatorStart")}):null})]},I.id))]})]}):null]})}const UZ=2e3,PZ=5e3;function IZ(){const{t:e}=xt(),{settings:t,isLoading:s,error:i,updateSetting:l}=io(),[c,d]=h.useState(""),[f,m]=h.useState(""),[g,v]=h.useState(!1),[b,w]=h.useState(!1),[_,C]=h.useState(null);h.useEffect(()=>{t&&(d(t.lifecycleWebhookUrl??""),m(t.lifecycleWebhookToken??""))},[t]);const S=h.useCallback(async()=>{v(!0),C(null);try{await Promise.all([l("lifecycleWebhookUrl",c.trim()||void 0),l("lifecycleWebhookToken",f.trim()||void 0)]),w(!1)}catch(P){C(P instanceof Error?P.message:e("lifecycleWebhooksSaveFailed"))}finally{v(!1)}},[e,f,l,c]);if(s)return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("lifecycleWebhooksTitle")}),r.jsx("p",{className:"settings-section-description",children:e("lifecycleWebhooksLoading")})]});const N=(t==null?void 0:t.lifecycleWebhookUrl)??"",T=(t==null?void 0:t.lifecycleWebhookToken)??"",k=(t==null?void 0:t.lifecycleWebhooksEnabled)??!1,A=(t==null?void 0:t.lifecycleWebhookDryRun)??!0;return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("lifecycleWebhooksTitle")}),r.jsx("p",{className:"settings-section-description",children:e("lifecycleWebhooksDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("label",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksEnableTitle")}),r.jsx("p",{children:e("lifecycleWebhooksEnableDescription")})]}),r.jsx("input",{type:"checkbox",checked:k,onChange:P=>void l("lifecycleWebhooksEnabled",P.target.checked)})]}),r.jsxs("div",{className:"settings-item",style:{flexDirection:"column",alignItems:"stretch"},children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksUrlTitle")}),r.jsx("p",{children:e("lifecycleWebhooksUrlDescription")})]}),r.jsx("input",{type:"url",className:"settings-input",value:c,onChange:P=>{const U=P.target.value.slice(0,UZ);d(U),w(U!==N||f!==T),C(null)},placeholder:"https://example.com/hooks/yep"})]}),r.jsxs("div",{className:"settings-item",style:{flexDirection:"column",alignItems:"stretch"},children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksTokenTitle")}),r.jsx("p",{children:e("lifecycleWebhooksTokenDescription")})]}),r.jsx("input",{type:"password",className:"settings-input",value:f,onChange:P=>{const U=P.target.value.slice(0,PZ);m(U),w(c!==N||U!==T),C(null)},placeholder:e("lifecycleWebhooksTokenPlaceholder")})]}),r.jsxs("label",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("lifecycleWebhooksDryRunTitle")}),r.jsx("p",{children:e("lifecycleWebhooksDryRunDescription")})]}),r.jsx("input",{type:"checkbox",checked:A,onChange:P=>void l("lifecycleWebhookDryRun",P.target.checked)})]}),r.jsx("div",{className:"settings-item",style:{justifyContent:"flex-end",gap:"var(--space-2)"},children:r.jsx("button",{type:"button",className:"settings-button",disabled:!b||g,onClick:S,children:e(g?"providersSaving":"providersSave")})}),(_||i)&&r.jsx("p",{className:"settings-warning",children:_||i})]})]})}function zZ(){const[e,t]=h.useState(null),[s,i]=h.useState(!0),[l,c]=h.useState(null),[d,f]=h.useState(!1),m=h.useRef(!1),g=h.useCallback(async()=>{i(!0),c(null);try{const w=await Re.getNetworkBinding();t(w)}catch(w){c(w instanceof Error?w:new Error(String(w)))}finally{i(!1)}},[]);h.useEffect(()=>{m.current||(m.current=!0,g())},[g]);const v=h.useCallback(async w=>{f(!0),c(null);try{const _=await Re.setNetworkBinding(w);if(!_.success)throw new Error(_.error??"Failed to update binding");return await g(),{redirectUrl:_.redirectUrl}}catch(_){const C=_ instanceof Error?_:new Error(String(_));throw c(C),C}finally{f(!1)}},[g]),b=h.useCallback(async()=>{f(!0),c(null);try{const w=await Re.disableNetworkBinding();if(!w.success)throw new Error(w.error??"Failed to disable network socket");await g()}catch(w){const _=w instanceof Error?w:new Error(String(w));throw c(_),_}finally{f(!1)}},[g]);return{binding:e,loading:s,error:l,applying:d,updateBinding:v,disableNetwork:b,refetch:g}}function $Z(){const[e,t]=h.useState(null),[s,i]=h.useState(!0),[l,c]=h.useState(null),d=h.useRef(!1),f=h.useCallback(async()=>{i(!0),c(null);try{const m=await Re.getServerInfo();t(m)}catch(m){c(m instanceof Error?m:new Error(String(m)))}finally{i(!1)}},[]);return h.useEffect(()=>{d.current||(d.current=!0,f())},[f]),{serverInfo:e,loading:s,error:l,refetch:f}}function BZ(){const{t:e}=xt(),t=dF(),s=Vi(),{relayDebugEnabled:i,setRelayDebugEnabled:l}=Hi(),{serverInfo:c,loading:d}=$Z(),{binding:f,loading:m,applying:g,updateBinding:v}=zZ(),{settings:b,isLoading:w}=io(),[_,C]=h.useState(""),[S,N]=h.useState(!1),[T,k]=h.useState(""),[A,P]=h.useState(""),[U,O]=h.useState(!1),[z,q]=h.useState(!1),[oe,K]=h.useState(""),[I,B]=h.useState(""),[Z,Q]=h.useState(!1),[ae,W]=h.useState(""),[Y,V]=h.useState(null),[ne,ge]=h.useState(!1),[$,G]=h.useState(!1),[le,fe]=h.useState(!1);if(f&&t&&b&&!le){C(String(f.localhost.port)),N(f.network.enabled),k(f.network.host??""),O(t.authEnabled),q(t.localhostOpen);const De=b.allowedHosts;De==="*"?(Q(!0),W("")):(Q(!1),W(De??"")),fe(!0)}const ue=(De,vt)=>De?"*":vt.trim()||void 0,_e=(De,vt,me,We,ot,ut,$e,Et)=>{if(!f||!t||!b)return!1;const Oe=De!==String(f.localhost.port),Ot=vt!==f.network.enabled,Tt=me!==(f.network.host??""),Sn=We!==t.authEnabled,In=ot.length>0,pn=Et!==t.localhostOpen,Nn=ue(ut,$e),Jt=b.allowedHosts;return Oe||Ot||Tt||Sn||In||pn||(Nn??"")!==(Jt??"")},Ke=De=>{ge(_e(De.port??_,De.networkEnabled??S,De.iface??T,De.requirePw??U,De.password??oe,De.allowAll??Z,De.hostsText??ae,De.localhostOpen??z))},tt=async()=>{if(!t)return;V(null);const De=Number.parseInt(_,10);if(Number.isNaN(De)||De<1||De>65535){V(e("localAccessErrorPortRange"));return}const vt=U&&!t.authEnabled,me=U&&t.authEnabled&&oe.length>0;if(vt||me){if(oe.length<6){V(e("localAccessErrorPasswordLength"));return}if(oe!==I){V(e("localAccessErrorPasswordMismatch"));return}}const We=T==="custom"?A:T;G(!0);try{const ot={};f!=null&&f.localhost.overriddenByCli||(ot.localhostPort=De),f!=null&&f.network.overriddenByCli||(ot.network={enabled:S,host:S?We:void 0});const ut=await v(ot);vt?(await t.enableAuth(oe),K(""),B("")):me?(await t.changePassword(oe),K(""),B("")):!U&&t.authEnabled&&await t.disableAuth(),z!==t.localhostOpen&&await t.setLocalhostOpen(z);const $e=ue(Z,ae);if(await Re.updateServerSettings({allowedHosts:$e??""}),ut.redirectUrl){const Et=new URL(ut.redirectUrl);Et.pathname=window.location.pathname,Et.search=window.location.search,window.location.href=Et.toString()}else ge(!1)}catch(ot){V(ot instanceof Error?ot.message:e("localAccessErrorApplyFailed"))}finally{G(!1)}};if(t){if(d||m||w||t.isLoading||!le)return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("settingsLocalAccessTitle")}),r.jsx("p",{className:"settings-section-description",children:e("localAccessLoading")})]});const vt=U;return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("settingsLocalAccessTitle")}),r.jsx("p",{className:"settings-section-description",children:e("localAccessDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessStatusTitle")}),r.jsx("p",{children:c?(()=>{const me=f==null?void 0:f.network.host,We=(f==null?void 0:f.network.port)??c.port,ot=me==="0.0.0.0"||me==="::",ut=We===c.port;return f!=null&&f.network.enabled&&ot&&ut?r.jsxs(r.Fragment,{children:[e("localAccessListeningOn")," ",r.jsxs("code",{children:[me,":",We]})]}):r.jsxs(r.Fragment,{children:[e("localAccessListeningOn")," ",r.jsxs("code",{children:[c.host,":",c.port]}),(f==null?void 0:f.network.enabled)&&me&&r.jsxs(r.Fragment,{children:[" ",e("localAccessListeningAnd")," ",r.jsxs("code",{children:[me,":",We]})]})]})})():e("localAccessUnableToFetch")})]}),(c==null?void 0:c.localhostOnly)&&!(f!=null&&f.network.enabled)&&r.jsx("span",{className:"settings-status-badge settings-status-detected",children:e("localAccessBadgeLocalOnly")}),((c==null?void 0:c.boundToAllInterfaces)||(f==null?void 0:f.network.enabled))&&!t.authEnabled&&r.jsx("span",{className:"settings-status-badge settings-status-warning",children:e("localAccessBadgeNetworkExposed")})]})}),r.jsxs("form",{className:"settings-group",onSubmit:me=>{me.preventDefault(),tt()},children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessListeningPortTitle")}),r.jsx("p",{children:e("localAccessListeningPortDescription")})]}),f!=null&&f.localhost.overriddenByCli?r.jsxs("span",{className:"settings-value-readonly",children:[f.localhost.port," ",r.jsx("span",{className:"settings-hint",children:e("localAccessSetViaPort")})]}):r.jsx("input",{type:"number",className:"settings-input-small",value:_,onChange:me=>{C(me.target.value),Ke({port:me.target.value})},min:1,max:65535,autoComplete:"off"})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessNetworkTitle")}),r.jsx("p",{children:e("localAccessNetworkDescription")})]}),f!=null&&f.network.overriddenByCli?r.jsxs("span",{className:"settings-value-readonly",children:[f.network.host,":",f.network.port," ",r.jsx("span",{className:"settings-hint",children:e("localAccessSetViaHost")})]}):r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:me=>{N(me.target.checked),Ke({networkEnabled:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),S&&!(f!=null&&f.network.overriddenByCli)&&f&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessInterfaceTitle")}),r.jsx("p",{children:e("localAccessInterfaceDescription")})]}),r.jsx(dr,{label:e("localAccessInterfaceTitle"),placeholder:e("localAccessInterfacePlaceholder"),multiSelect:!1,align:"right",options:[...f.interfaces.map(me=>({value:me.address,label:me.displayName})),{value:"0.0.0.0",label:e("localAccessInterfaceAll")},{value:"custom",label:e("localAccessInterfaceCustom")}],selected:T?[T]:[],onChange:me=>{const We=me[0]??"";k(We),Ke({iface:We})}})]}),S&&!(f!=null&&f.network.overriddenByCli)&&T==="custom"&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessCustomIpTitle")}),r.jsx("p",{children:e("localAccessCustomIpDescription")})]}),r.jsx("input",{type:"text",className:"settings-input",placeholder:"192.168.1.100",value:A,onChange:me=>P(me.target.value)})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessAllowAllHostsTitle")}),r.jsx("p",{children:e("localAccessAllowAllHostsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:Z,onChange:me=>{Q(me.target.checked),Ke({allowAll:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),!Z&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessAllowedHostsTitle")}),r.jsx("p",{children:e("localAccessAllowedHostsDescription")})]}),r.jsx("input",{type:"text",className:"settings-input",placeholder:e("localAccessAllowedHostsPlaceholder"),value:ae,onChange:me=>{W(me.target.value),Ke({hostsText:me.target.value})}})]}),r.jsx("p",{className:"form-hint",children:e("localAccessAllowedHostsHint")}),!t.authDisabledByEnv&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessRequirePasswordTitle")}),r.jsx("p",{children:e("localAccessRequirePasswordDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:U,onChange:me=>{O(me.target.checked),Ke({requirePw:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),vt&&r.jsxs(r.Fragment,{children:[r.jsx("input",{type:"text",name:"username",autoComplete:"username",style:{position:"absolute",visibility:"hidden",pointerEvents:"none"},tabIndex:-1}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessPasswordTitle")}),r.jsx("p",{children:t.authEnabled?e("localAccessPasswordKeepCurrent"):e("localAccessPasswordMinLength")})]}),r.jsx("input",{type:"password",className:"settings-input",value:oe,onChange:me=>{K(me.target.value),Ke({password:me.target.value})},autoComplete:"new-password",placeholder:t.authEnabled?e("localAccessPasswordNewPlaceholder"):e("localAccessPasswordPlaceholder")})]}),oe.length>0&&r.jsxs("div",{className:"settings-item",children:[r.jsx("div",{className:"settings-item-info",children:r.jsx("strong",{children:e("localAccessConfirmPasswordTitle")})}),r.jsx("input",{type:"password",className:"settings-input",value:I,onChange:me=>B(me.target.value),autoComplete:"new-password",placeholder:e("localAccessConfirmPasswordPlaceholder")})]}),!t.authEnabled&&r.jsx("p",{className:"form-hint",children:e("localAccessPasswordResetHint")})]}),t.hasDesktopToken&&!U&&!t.authDisabledByEnv&&r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessLocalhostOpenTitle")}),r.jsx("p",{children:e("localAccessLocalhostOpenDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:z,onChange:me=>{q(me.target.checked),Ke({localhostOpen:me.target.checked})}}),r.jsx("span",{className:"toggle-slider"})]})]}),t.authDisabledByEnv&&r.jsx("p",{className:"form-warning",children:e("localAccessAuthDisabled")}),r.jsxs("div",{className:"settings-item",children:[Y&&r.jsx("p",{className:"form-error",children:Y}),r.jsx("button",{type:"submit",className:"settings-button",disabled:!ne||$||g,children:e($||g?"localAccessApplying":"localAccessApply")})]})]}),t.authEnabled&&t.isAuthenticated&&r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessLogoutTitle")}),r.jsx("p",{children:e("localAccessLogoutDescription")})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:t.logout,children:e("remoteAccessLogout")})]})})]})}return s?r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("settingsLocalAccessTitle")}),r.jsx("p",{className:"settings-section-description",children:e("localAccessRemoteDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessLogoutTitle")}),r.jsx("p",{children:e("localAccessRemoteLogoutDescription")})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>s.disconnect(),children:e("remoteAccessLogout")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("localAccessRelayDebugTitle")}),r.jsx("p",{children:e("localAccessRelayDebugDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:i,onChange:De=>l(De.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})]})]}):null}function FZ(){const{t:e}=xt(),{model:t,setModel:s,effortLevel:i,setEffortLevel:l}=au();return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("modelSettingsTitle")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("modelSettingsModelTitle")}),r.jsx("p",{children:e("modelSettingsModelDescription")})]}),r.jsx("div",{className:"font-size-selector",children:Yc.map(c=>r.jsx("button",{type:"button",className:`font-size-option ${t===c.value?"active":""}`,onClick:()=>s(c.value),children:c.label},c.value))})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("modelSettingsEffortTitle")}),r.jsx("p",{children:e("modelSettingsEffortDescription")})]}),r.jsx("div",{className:"font-size-selector",children:H9.map(c=>r.jsx("button",{type:"button",className:`font-size-option ${i===c.value?"active":""}`,onClick:()=>l(c.value),title:c.description,children:c.label},c.value))})]})]})]})}function vS(){const[e,t]=h.useState(()=>{const l=typeof window<"u"&&"Notification"in window,c=K9();return{isSupported:l&&!c,isMobile:c,permission:l?Notification.permission:"denied",isRequesting:!1}});h.useEffect(()=>{if(!e.isSupported)return;const l=()=>{const c=Notification.permission;c!==e.permission&&t(d=>({...d,permission:c}))};return window.addEventListener("focus",l),()=>window.removeEventListener("focus",l)},[e.isSupported,e.permission]);const s=h.useCallback(async()=>{if(e.isSupported&&e.permission!=="granted"){t(l=>({...l,isRequesting:!0}));try{const l=await Notification.requestPermission();t(c=>({...c,permission:l,isRequesting:!1}))}catch(l){console.error("[useBrowserNotifications] Permission request failed:",l),t(c=>({...c,isRequesting:!1}))}}},[e.isSupported,e.permission]),i=h.useCallback((l,c)=>{if(!e.isSupported||e.permission!=="granted")return!1;try{return new Notification(l,c),!0}catch(d){return console.error("[useBrowserNotifications] Failed to show notification:",d),!1}},[e.isSupported,e.permission]);return{...e,isEnabled:e.permission==="granted",isDenied:e.permission==="denied",requestPermission:s,showNotification:i}}function HZ(){const{t:e}=xt(),{isSupported:t,isMobile:s,isEnabled:i,isDenied:l,isRequesting:c,requestPermission:d,showNotification:f}=vS();if(s)return null;if(!t)return r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:"Desktop Notifications"}),r.jsx("p",{children:e("browserToggleUnsupported")})]})});if(l)return r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTitle")}),r.jsx("p",{className:"settings-warning",children:e("browserToggleBlocked")})]})});if(i){const m=()=>{f(e("browserToggleTestNotification"),{body:e("browserToggleTestBody"),icon:"/icon-192.png"})};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTitle")}),r.jsx("p",{children:e("browserToggleEnabled")})]}),r.jsx("span",{className:"settings-badge settings-badge-success",children:e("browserToggleEnabledBadge")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTestTitle")}),r.jsx("p",{children:e("browserToggleTestDescription")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:m,children:e("pushToggleSendTest")})]})]})}return r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("browserToggleTitle")}),r.jsx("p",{children:e("browserToggleDescription")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:d,disabled:c,children:e(c?"browserToggleRequesting":"browserToggleEnable")})]})}function qZ(){const{t:e}=xt(),{isSupported:t,isSubscribed:s,isLoading:i,error:l,permission:c,subscribe:d,unsubscribe:f,sendTest:m}=sm(),{notifyInApp:g,setNotifyInApp:v}=EF(),[b,w]=h.useState("normal"),_=async()=>{s?await f():await d()};if(!t){const C=l==null?void 0:l.includes("Service worker disabled in dev mode");return r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTitle")}),r.jsx("p",{children:l||e("pushToggleUnsupported")}),C&&r.jsxs("div",{className:"settings-info-box",style:{marginTop:"0.5rem"},children:[r.jsx("p",{children:e("pushToggleThisDeviceOnly")}),r.jsx("p",{children:e("pushToggleDevModeHint")})]}),r.jsx("p",{style:{marginTop:"0.5rem"},children:r.jsx("a",{href:"https://github.com/kzahel/yepanywhere/blob/main/docs/push-notifications.md",target:"_blank",rel:"noopener noreferrer",children:e("pushToggleTroubleshooting")})})]})})}return c==="denied"?r.jsx("div",{className:"settings-item",children:r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTitle")}),r.jsx("p",{className:"settings-warning",children:e("pushToggleBlocked")})]})}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTitle")}),r.jsx("p",{children:e("pushToggleDescription")}),l&&r.jsx("p",{className:"settings-error",children:l})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:s,onChange:_,disabled:i}),r.jsx("span",{className:"toggle-slider"})]})]}),s&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleNotifyInAppTitle")}),r.jsx("p",{children:e("pushToggleNotifyInAppDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:C=>v(C.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("pushToggleTestTitle")}),r.jsx("p",{children:e("pushToggleTestDescription")})]}),r.jsxs("div",{className:"settings-item-actions",children:[r.jsxs("select",{className:"settings-select",value:b,onChange:C=>w(C.target.value),disabled:i,children:[r.jsx("option",{value:"normal",children:e("pushToggleUrgencyNormal")}),r.jsx("option",{value:"persistent",children:e("pushToggleUrgencyPersistent")}),r.jsx("option",{value:"silent",children:e("pushToggleUrgencySilent")})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:()=>m(b),disabled:i,children:e(i?"pushToggleSending":"pushToggleSendTest")})]})]})]})]})}function VZ(){const[e,t]=h.useState({settings:null,isLoading:!0,error:null});h.useEffect(()=>{(async()=>{try{const{settings:l}=await Re.getNotificationSettings();t({settings:l,isLoading:!1,error:null})}catch(l){console.error("[useNotificationSettings] Failed to fetch:",l),t(c=>({...c,isLoading:!1,error:l instanceof Error?l.message:"Failed to load settings"}))}})()},[]);const s=h.useCallback(async(i,l)=>{t(c=>({...c,isLoading:!0,error:null}));try{const{settings:c}=await Re.updateNotificationSettings({[i]:l});t({settings:c,isLoading:!1,error:null})}catch(c){console.error("[useNotificationSettings] Failed to update:",c),t(d=>({...d,isLoading:!1,error:c instanceof Error?c.message:"Failed to update"}))}},[]);return{...e,updateSetting:s}}function WZ(){const[e,t]=h.useState({devices:[],isLoading:!0,error:null}),s=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{subscriptions:l}=await Re.getPushSubscriptions();t({devices:l,isLoading:!1,error:null})}catch(l){console.error("[useSubscribedDevices] Failed to fetch:",l),t(c=>({...c,isLoading:!1,error:l instanceof Error?l.message:"Failed to load devices"}))}},[]);h.useEffect(()=>{s()},[s]);const i=h.useCallback(async l=>{t(c=>({...c,isLoading:!0,error:null}));try{await Re.deletePushSubscription(l),await s()}catch(c){console.error("[useSubscribedDevices] Failed to remove:",c),t(d=>({...d,isLoading:!1,error:c instanceof Error?c.message:"Failed to remove device"}))}},[s]);return{...e,removeDevice:i,refetch:s}}function YZ(e,t){const s=e||"Unknown device";return t!=null&&t.includes("google")?{displayName:s,browserType:"(Android/Chrome)"}:t!=null&&t.includes("apple")||t!=null&&t.includes("push.apple")?{displayName:s,browserType:"(iOS/Safari)"}:t!=null&&t.includes("mozilla")||t!=null&&t.includes("push.services.mozilla")?{displayName:s,browserType:"(Firefox)"}:{displayName:s,browserType:""}}function ZZ(e,t){const s=new Date(e),l=new Date().getTime()-s.getTime(),c=Math.floor(l/(1e3*60*60*24));return c===0?new Date().toLocaleDateString():c===1?new Date(Date.now()-864e5).toLocaleDateString():c<7?t("hostPickerLastConnectedDays",{count:c}):s.toLocaleDateString()}function GZ(e,t,s){const i=new Map;for(const c of e){const{displayName:d,browserType:f}=YZ(c.deviceName,c.endpointDomain),m=t.get(c.browserProfileId);i.set(c.browserProfileId,{browserProfileId:c.browserProfileId,displayName:d,browserType:f,isSubscribed:!0,isConnected:!!m,tabCount:(m==null?void 0:m.connectionCount)??0,subscribedAt:c.createdAt,isCurrentDevice:c.browserProfileId===s})}for(const[c,d]of t)if(!i.has(c)){const f=c.slice(0,8);i.set(c,{browserProfileId:c,displayName:f,browserType:"",isSubscribed:!1,isConnected:!0,tabCount:d.connectionCount,isCurrentDevice:c===s})}const l=Array.from(i.values());return l.sort((c,d)=>c.isCurrentDevice&&!d.isCurrentDevice?-1:!c.isCurrentDevice&&d.isCurrentDevice?1:c.isConnected&&!d.isConnected?-1:!c.isConnected&&d.isConnected?1:c.isConnected&&d.isConnected?d.tabCount-c.tabCount:c.subscribedAt&&d.subscribedAt?new Date(d.subscribedAt).getTime()-new Date(c.subscribedAt).getTime():0),l}function KZ(){const{t:e}=xt(),{browserProfileId:t}=sm(),{isMobile:s}=vS(),{devices:i,isLoading:l,removeDevice:c}=WZ(),{connections:d,isLoading:f}=xS(),{settings:m,isLoading:g,updateSetting:v}=VZ(),b=i.length>0,w=l||f,_=GZ(i,d,t);return r.jsxs(r.Fragment,{children:[r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsServerTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsServerDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("notificationsToolApprovalsTitle")}),r.jsx("p",{children:e("notificationsToolApprovalsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.toolApproval)??!0,onChange:C=>v("toolApproval",C.target.checked),disabled:g||!b}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("notificationsQuestionsTitle")}),r.jsx("p",{children:e("notificationsQuestionsDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.userQuestion)??!0,onChange:C=>v("userQuestion",C.target.checked),disabled:g||!b}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("notificationsSessionHaltedTitle")}),r.jsx("p",{children:e("notificationsSessionHaltedDescription")})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(m==null?void 0:m.sessionHalted)??!0,onChange:C=>v("sessionHalted",C.target.checked),disabled:g||!b}),r.jsx("span",{className:"toggle-slider"})]})]}),!b&&!l&&r.jsx("p",{className:"settings-hint",children:e("notificationsNoSubscribedDevices")})]})]}),!s&&r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsDesktopTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsDesktopDescription")}),r.jsx("div",{className:"settings-group",children:r.jsx(HZ,{})})]}),r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsPushTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsPushDescription")}),r.jsx("div",{className:"settings-group",children:r.jsx(qZ,{})})]}),r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("notificationsDevicesTitle")}),r.jsx("p",{className:"settings-section-description",children:e("notificationsDevicesDescription")}),r.jsx("div",{className:"settings-group",children:w?r.jsx("p",{className:"settings-hint",children:e("notificationsLoadingDevices")}):_.length===0?r.jsx("p",{className:"settings-hint",children:e("notificationsNoDevices")}):r.jsx("div",{className:"device-list",children:_.map(C=>r.jsxs("div",{className:"device-list-item",children:[r.jsxs("div",{className:"device-list-info",children:[r.jsxs("strong",{children:[C.displayName,C.browserType&&` ${C.browserType}`,C.isCurrentDevice&&r.jsx("span",{className:"device-current-badge",children:e("notificationsThisDevice")})]}),r.jsxs("p",{children:[C.isConnected?r.jsx("span",{className:"device-status device-status-online",children:C.tabCount===1?e("notificationsOneTab"):e("notificationsTabs",{count:C.tabCount})}):r.jsx("span",{className:"device-status device-status-offline",children:e("notificationsOffline")}),!C.isSubscribed&&r.jsx("span",{className:"device-no-push",children:e("notificationsNoPush")}),C.subscribedAt&&r.jsx("span",{className:"device-subscribed-date",children:e("notificationsSubscribed",{date:ZZ(C.subscribedAt,e)})})]})]}),C.isSubscribed&&r.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>c(C.browserProfileId),title:C.isCurrentDevice?e("notificationsRemoveThisDevice"):e("notificationsRemoveDevice"),children:e("notificationsRemove")})]},C.browserProfileId))})})]})]})}const XZ="You are a helpful coding assistant. You help users with software engineering tasks. You have access to tools for reading files, editing files, running shell commands, and searching code. Use tools when needed to answer questions or make changes. Be concise and direct.";function QZ(){const{t:e}=xt(),{settings:t,updateSetting:s}=io(),[i,l]=h.useState(""),[c,d]=h.useState(!1),[f,m]=h.useState(!1),g=(t==null?void 0:t.ollamaUrl)??"";h.useEffect(()=>{t&&l(t.ollamaUrl??"")},[t]);const v=h.useCallback(async()=>{d(!0);try{await s("ollamaUrl",i.trim()||void 0),m(!1)}catch{}finally{d(!1)}},[i,s]);return r.jsxs("div",{style:{marginTop:"var(--space-2)",width:"100%"},children:[r.jsxs("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center"},children:[r.jsx("input",{type:"text",className:"settings-input",value:i,onChange:b=>{l(b.target.value),m(b.target.value!==g)},placeholder:"http://localhost:11434",style:{flex:1}}),r.jsx("button",{type:"button",className:"settings-button",disabled:!f||c,onClick:v,children:e(c?"providersSaving":"providersSave")})]}),r.jsx("span",{className:"settings-hint",children:e("providersOllamaUrlHint")})]})}function JZ(){const{t:e}=xt(),{settings:t,updateSetting:s}=io(),i=(t==null?void 0:t.ollamaUseFullSystemPrompt)??!1;return r.jsxs("label",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",marginTop:"var(--space-2)",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:i,onChange:l=>s("ollamaUseFullSystemPrompt",l.target.checked)}),r.jsx("span",{children:e("providersUseFullPrompt")}),r.jsx("span",{className:"settings-hint",style:{marginLeft:"auto"},children:e("providersUseFullPromptHint")})]})}function eG(){const{t:e}=xt(),{settings:t,updateSetting:s}=io(),[i,l]=h.useState(""),[c,d]=h.useState(!1),[f,m]=h.useState(!1),g=(t==null?void 0:t.ollamaSystemPrompt)??"";h.useEffect(()=>{t&&l(t.ollamaSystemPrompt??"")},[t]);const v=h.useCallback(async()=>{d(!0);try{await s("ollamaSystemPrompt",i.trim()||void 0),m(!1)}catch{}finally{d(!1)}},[i,s]);return r.jsxs("div",{style:{marginTop:"var(--space-2)",width:"100%"},children:[r.jsx("textarea",{className:"settings-textarea",value:i,onChange:b=>{l(b.target.value),m(b.target.value!==g)},placeholder:XZ,rows:4}),r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"var(--space-2)"},children:[r.jsx("span",{className:"settings-hint",children:e("providersOllamaPromptHint")}),r.jsx("button",{type:"button",className:"settings-button",disabled:!f||c,onClick:v,children:e(c?"providersSaving":"providersSave")})]})]})}function tG(){const{settings:e}=io(),t=(e==null?void 0:e.ollamaUseFullSystemPrompt)??!1;return r.jsxs(r.Fragment,{children:[r.jsx(QZ,{}),r.jsx(JZ,{}),!t&&r.jsx(eG,{})]})}function nG(){const{t:e}=xt(),{providers:t}=Yh(),i=hH().map(l=>{const c=t.find(d=>d.name===l.id);return{...l,installed:(c==null?void 0:c.installed)??!1,authenticated:(c==null?void 0:c.authenticated)??!1}});return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("providersSectionTitle")}),r.jsx("p",{className:"settings-section-description",children:e("providersSectionDescription")}),r.jsx("div",{className:"settings-group",children:i.map(l=>r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsxs("div",{className:"settings-item-header",children:[r.jsx("strong",{children:l.displayName}),l.installed?r.jsx("span",{className:"settings-status-badge settings-status-detected",children:e("providersDetected")}):r.jsx("span",{className:"settings-status-badge settings-status-not-detected",children:e("providersNotDetected")})]}),r.jsx("p",{children:l.metadata.description}),l.metadata.limitations.length>0&&r.jsx("ul",{className:"settings-limitations",children:l.metadata.limitations.map(c=>r.jsx("li",{children:c},c))}),l.id==="claude-ollama"&&r.jsx(tG,{})]}),l.metadata.website&&r.jsx("a",{href:l.metadata.website,target:"_blank",rel:"noopener noreferrer",className:"settings-link",children:e("providersWebsite")})]},l.id))})]})}function sG(){const[e,t]=h.useState(null),[s,i]=h.useState(null),[l,c]=h.useState(null),[d,f]=h.useState([]),[m,g]=h.useState(!0),[v,b]=h.useState(null),w=h.useCallback(async()=>{try{const[U,O,z,q]=await Promise.all([Ie("/remote-access/config"),Ie("/remote-access/relay"),Ie("/remote-access/relay/status"),Ie("/remote-access/sessions")]);t(U),i(O.relay),c(z),f(q.sessions),b(null)}catch(U){console.error("[useRemoteAccess] Failed to fetch config:",U),b(U instanceof Error?U.message:"Failed to fetch config")}},[]);h.useEffect(()=>{g(!0),w().finally(()=>g(!1))},[w]);const _=h.useCallback(async U=>{try{await Ie("/remote-access/configure",{method:"POST",body:JSON.stringify({password:U})}),await w()}catch(O){const z=O instanceof Error?O.message:"Failed to configure remote access";throw b(z),new Error(z)}},[w]),C=h.useCallback(async()=>{try{await Ie("/remote-access/enable",{method:"POST"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to enable remote access";throw b(O),new Error(O)}},[w]),S=h.useCallback(async()=>{try{await Ie("/remote-access/disable",{method:"POST"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to disable remote access";throw b(O),new Error(O)}},[w]),N=h.useCallback(async()=>{try{await Ie("/remote-access/clear",{method:"POST"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to clear remote access credentials";throw b(O),new Error(O)}},[w]),T=h.useCallback(async U=>{try{await Ie("/remote-access/relay",{method:"PUT",body:JSON.stringify(U)}),await w()}catch(O){const z=O instanceof Error?O.message:"Failed to update relay configuration";throw b(z),new Error(z)}},[w]),k=h.useCallback(async()=>{try{await Ie("/remote-access/relay",{method:"DELETE"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to clear relay configuration";throw b(O),new Error(O)}},[w]),A=h.useCallback(async U=>{try{await Ie(`/remote-access/sessions/${U}`,{method:"DELETE"}),await w()}catch(O){const z=O instanceof Error?O.message:"Failed to revoke session";throw b(z),new Error(z)}},[w]),P=h.useCallback(async()=>{try{await Ie("/remote-access/sessions",{method:"DELETE"}),await w()}catch(U){const O=U instanceof Error?U.message:"Failed to revoke all sessions";throw b(O),new Error(O)}},[w]);return{config:e,relayConfig:s,relayStatus:l,sessions:d,loading:m,error:v,configure:_,enable:C,disable:S,clearCredentials:N,updateRelayConfig:T,clearRelayConfig:k,revokeSession:A,revokeAllSessions:P,refresh:w}}var Ir=(e=>(e[e.Border=-1]="Border",e[e.Data=0]="Data",e[e.Function=1]="Function",e[e.Position=2]="Position",e[e.Timing=3]="Timing",e[e.Alignment=4]="Alignment",e))(Ir||{}),oG=Object.defineProperty,rG=(e,t,s)=>t in e?oG(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,Ac=(e,t,s)=>(rG(e,typeof t!="symbol"?t+"":t,s),s);const iG=[0,1],bS=[1,0],yS=[2,3],SS=[3,2],aG={L:iG,M:bS,Q:yS,H:SS},lG=/^[0-9]*$/,cG=/^[A-Z0-9 $%*+.\/:-]*$/,Vf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",om=1,rm=40,Ub=3,uG=3,Rc=40,dG=10,wS=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],jS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]];class fG{constructor(t,s,i,l){if(this.version=t,this.ecc=s,Ac(this,"size"),Ac(this,"mask"),Ac(this,"modules",[]),Ac(this,"types",[]),t<om||t>rm)throw new RangeError("Version value out of range");if(l<-1||l>7)throw new RangeError("Mask value out of range");this.size=t*4+17;const c=Array.from({length:this.size},()=>!1);for(let f=0;f<this.size;f++)this.modules.push(c.slice()),this.types.push(c.map(()=>0));this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),l===-1){let f=1e9;for(let m=0;m<8;m++){this.applyMask(m),this.drawFormatBits(m);const g=this.getPenaltyScore();g<f&&(l=m,f=g),this.applyMask(m)}}this.mask=l,this.applyMask(l),this.drawFormatBits(l)}getModule(t,s){return t>=0&&t<this.size&&s>=0&&s<this.size&&this.modules[s][t]}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2===0,Ir.Timing),this.setFunctionModule(i,6,i%2===0,Ir.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const t=this.getAlignmentPatternPositions(),s=t.length;for(let i=0;i<s;i++)for(let l=0;l<s;l++)i===0&&l===0||i===0&&l===s-1||i===s-1&&l===0||this.drawAlignmentPattern(t[i],t[l]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){const s=this.ecc[1]<<3|t;let i=s;for(let c=0;c<10;c++)i=i<<1^(i>>>9)*1335;const l=(s<<10|i)^21522;for(let c=0;c<=5;c++)this.setFunctionModule(8,c,Mo(l,c));this.setFunctionModule(8,7,Mo(l,6)),this.setFunctionModule(8,8,Mo(l,7)),this.setFunctionModule(7,8,Mo(l,8));for(let c=9;c<15;c++)this.setFunctionModule(14-c,8,Mo(l,c));for(let c=0;c<8;c++)this.setFunctionModule(this.size-1-c,8,Mo(l,c));for(let c=8;c<15;c++)this.setFunctionModule(8,this.size-15+c,Mo(l,c));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let t=this.version;for(let i=0;i<12;i++)t=t<<1^(t>>>11)*7973;const s=this.version<<12|t;for(let i=0;i<18;i++){const l=Mo(s,i),c=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(c,d,l),this.setFunctionModule(d,c,l)}}drawFinderPattern(t,s){for(let i=-4;i<=4;i++)for(let l=-4;l<=4;l++){const c=Math.max(Math.abs(l),Math.abs(i)),d=t+l,f=s+i;d>=0&&d<this.size&&f>=0&&f<this.size&&this.setFunctionModule(d,f,c!==2&&c!==4,Ir.Position)}}drawAlignmentPattern(t,s){for(let i=-2;i<=2;i++)for(let l=-2;l<=2;l++)this.setFunctionModule(t+l,s+i,Math.max(Math.abs(l),Math.abs(i))!==1,Ir.Alignment)}setFunctionModule(t,s,i,l=Ir.Function){this.modules[s][t]=i,this.types[s][t]=l}addEccAndInterleave(t){const s=this.version,i=this.ecc;if(t.length!==$c(s,i))throw new RangeError("Invalid argument");const l=jS[i[0]][s],c=wS[i[0]][s],d=Math.floor(hh(s)/8),f=l-d%l,m=Math.floor(d/l),g=[],v=SG(c);for(let w=0,_=0;w<l;w++){const C=t.slice(_,_+m-c+(w<f?0:1));_+=C.length;const S=wG(C,v);w<f&&C.push(0),g.push(C.concat(S))}const b=[];for(let w=0;w<g[0].length;w++)g.forEach((_,C)=>{(w!==m-c||C>=f)&&b.push(_[w])});return b}drawCodewords(t){if(t.length!==Math.floor(hh(this.version)/8))throw new RangeError("Invalid argument");let s=0;for(let i=this.size-1;i>=1;i-=2){i===6&&(i=5);for(let l=0;l<this.size;l++)for(let c=0;c<2;c++){const d=i-c,m=(i+1&2)===0?this.size-1-l:l;!this.types[m][d]&&s<t.length*8&&(this.modules[m][d]=Mo(t[s>>>3],7-(s&7)),s++)}}}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let s=0;s<this.size;s++)for(let i=0;i<this.size;i++){let l;switch(t){case 0:l=(i+s)%2===0;break;case 1:l=s%2===0;break;case 2:l=i%3===0;break;case 3:l=(i+s)%3===0;break;case 4:l=(Math.floor(i/3)+Math.floor(s/2))%2===0;break;case 5:l=i*s%2+i*s%3===0;break;case 6:l=(i*s%2+i*s%3)%2===0;break;case 7:l=((i+s)%2+i*s%3)%2===0;break;default:throw new Error("Unreachable")}!this.types[s][i]&&l&&(this.modules[s][i]=!this.modules[s][i])}}getPenaltyScore(){let t=0;for(let c=0;c<this.size;c++){let d=!1,f=0;const m=[0,0,0,0,0,0,0];for(let g=0;g<this.size;g++)this.modules[c][g]===d?(f++,f===5?t+=Ub:f>5&&t++):(this.finderPenaltyAddHistory(f,m),d||(t+=this.finderPenaltyCountPatterns(m)*Rc),d=this.modules[c][g],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,m)*Rc}for(let c=0;c<this.size;c++){let d=!1,f=0;const m=[0,0,0,0,0,0,0];for(let g=0;g<this.size;g++)this.modules[g][c]===d?(f++,f===5?t+=Ub:f>5&&t++):(this.finderPenaltyAddHistory(f,m),d||(t+=this.finderPenaltyCountPatterns(m)*Rc),d=this.modules[g][c],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,m)*Rc}for(let c=0;c<this.size-1;c++)for(let d=0;d<this.size-1;d++){const f=this.modules[c][d];f===this.modules[c][d+1]&&f===this.modules[c+1][d]&&f===this.modules[c+1][d+1]&&(t+=uG)}let s=0;for(const c of this.modules)s=c.reduce((d,f)=>d+(f?1:0),s);const i=this.size*this.size,l=Math.ceil(Math.abs(s*20-i*10)/i)-1;return t+=l*dG,t}getAlignmentPatternPositions(){if(this.version===1)return[];{const t=Math.floor(this.version/7)+2,s=this.version===32?26:Math.ceil((this.version*4+4)/(t*2-2))*2,i=[6];for(let l=this.size-7;i.length<t;l-=s)i.splice(1,0,l);return i}}finderPenaltyCountPatterns(t){const s=t[1],i=s>0&&t[2]===s&&t[3]===s*3&&t[4]===s&&t[5]===s;return(i&&t[0]>=s*4&&t[6]>=s?1:0)+(i&&t[6]>=s*4&&t[0]>=s?1:0)}finderPenaltyTerminateAndCount(t,s,i){return t&&(this.finderPenaltyAddHistory(s,i),s=0),s+=this.size,this.finderPenaltyAddHistory(s,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(t,s){s[0]===0&&(t+=this.size),s.pop(),s.unshift(t)}}function Lo(e,t,s){if(t<0||t>31||e>>>t)throw new RangeError("Value out of range");for(let i=t-1;i>=0;i--)s.push(e>>>i&1)}function Mo(e,t){return(e>>>t&1)!==0}class im{constructor(t,s,i){if(this.mode=t,this.numChars=s,this.bitData=i,s<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}getData(){return this.bitData.slice()}}const hG=[1,10,12,14],mG=[2,9,11,13],pG=[4,8,16,16];function ES(e,t){return e[Math.floor((t+7)/17)+1]}function NS(e){const t=[];for(const s of e)Lo(s,8,t);return new im(pG,e.length,t)}function gG(e){if(!_S(e))throw new RangeError("String contains non-numeric characters");const t=[];for(let s=0;s<e.length;){const i=Math.min(e.length-s,3);Lo(Number.parseInt(e.substring(s,s+i),10),i*3+1,t),s+=i}return new im(hG,e.length,t)}function xG(e){if(!CS(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");const t=[];let s;for(s=0;s+2<=e.length;s+=2){let i=Vf.indexOf(e.charAt(s))*45;i+=Vf.indexOf(e.charAt(s+1)),Lo(i,11,t)}return s<e.length&&Lo(Vf.indexOf(e.charAt(s)),6,t),new im(mG,e.length,t)}function vG(e){return e===""?[]:_S(e)?[gG(e)]:CS(e)?[xG(e)]:[NS(yG(e))]}function _S(e){return lG.test(e)}function CS(e){return cG.test(e)}function bG(e,t){let s=0;for(const i of e){const l=ES(i.mode,t);if(i.numChars>=1<<l)return Number.POSITIVE_INFINITY;s+=4+l+i.bitData.length}return s}function yG(e){e=encodeURI(e);const t=[];for(let s=0;s<e.length;s++)e.charAt(s)!=="%"?t.push(e.charCodeAt(s)):(t.push(Number.parseInt(e.substring(s+1,s+3),16)),s+=2);return t}function hh(e){if(e<om||e>rm)throw new RangeError("Version number out of range");let t=(16*e+128)*e+64;if(e>=2){const s=Math.floor(e/7)+2;t-=(25*s-10)*s-55,e>=7&&(t-=36)}return t}function $c(e,t){return Math.floor(hh(e)/8)-wS[t[0]][e]*jS[t[0]][e]}function SG(e){if(e<1||e>255)throw new RangeError("Degree out of range");const t=[];for(let i=0;i<e-1;i++)t.push(0);t.push(1);let s=1;for(let i=0;i<e;i++){for(let l=0;l<t.length;l++)t[l]=mh(t[l],s),l+1<t.length&&(t[l]^=t[l+1]);s=mh(s,2)}return t}function wG(e,t){const s=t.map(i=>0);for(const i of e){const l=i^s.shift();s.push(0),t.forEach((c,d)=>s[d]^=mh(c,l))}return s}function mh(e,t){if(e>>>8||t>>>8)throw new RangeError("Byte out of range");let s=0;for(let i=7;i>=0;i--)s=s<<1^(s>>>7)*285,s^=(t>>>i&1)*e;return s}function jG(e,t,s=1,i=40,l=-1,c=!0){if(!(om<=s&&s<=i&&i<=rm)||l<-1||l>7)throw new RangeError("Invalid value");let d,f;for(d=s;;d++){const b=$c(d,t)*8,w=bG(e,d);if(w<=b){f=w;break}if(d>=i)throw new RangeError("Data too long")}for(const b of[bS,yS,SS])c&&f<=$c(d,b)*8&&(t=b);const m=[];for(const b of e){Lo(b.mode[0],4,m),Lo(b.numChars,ES(b.mode,d),m);for(const w of b.getData())m.push(w)}const g=$c(d,t)*8;Lo(0,Math.min(4,g-m.length),m),Lo(0,(8-m.length%8)%8,m);for(let b=236;m.length<g;b^=253)Lo(b,8,m);const v=Array.from({length:Math.ceil(m.length/8)},()=>0);return m.forEach((b,w)=>v[w>>>3]|=b<<7-(w&7)),new fG(d,t,v,l)}function EG(e,t){const{ecc:s="L",boostEcc:i=!1,minVersion:l=1,maxVersion:c=40,maskPattern:d=-1,border:f=1}={},m=typeof e=="string"?vG(e):Array.isArray(e)?[NS(e)]:void 0;if(!m)throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);const g=jG(m,aG[s],l,c,d,i);return NG({version:g.version,maskPattern:g.mask,size:g.size,data:g.modules,types:g.types},f)}function NG(e,t=1){if(!t)return e;const{size:s}=e,i=s+t*2;e.size=i,e.data.forEach(c=>{for(let d=0;d<t;d++)c.unshift(!1),c.push(!1)});for(let c=0;c<t;c++)e.data.unshift(Array.from({length:i},d=>!1)),e.data.push(Array.from({length:i},d=>!1));const l=Ir.Border;e.types.forEach(c=>{for(let d=0;d<t;d++)c.unshift(l),c.push(l)});for(let c=0;c<t;c++)e.types.unshift(Array.from({length:i},d=>l)),e.types.push(Array.from({length:i},d=>l));return e}function _G({value:e,size:t=200,color:s="#000000",bgColor:i="#ffffff"}){const{data:l}=EG(e),c=l.length,d=t/c;let f="";for(let m=0;m<c;m++){const g=l[m];if(g){for(let v=0;v<c;v++)if(g[v]){const b=v*d,w=m*d;f+=`M${b},${w}h${d}v${d}h-${d}z`}}}return r.jsxs("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,xmlns:"http://www.w3.org/2000/svg",role:"img","aria-label":"QR code",children:[r.jsx("rect",{width:t,height:t,fill:i}),r.jsx("path",{d:f,fill:s})]})}const Ni="wss://relay.yepanywhere.com/ws",Wf="https://yepanywhere.com/remote/login/relay";function CG(e){return new Date(e).toLocaleDateString()}function Pb(e,t){const s=new Date(e),l=new Date().getTime()-s.getTime(),c=Math.floor(l/(1e3*60)),d=Math.floor(l/(1e3*60*60)),f=Math.floor(l/(1e3*60*60*24));return c<1?t("remoteSetupJustNow"):c<60?t("remoteSetupMinutesAgo",{count:c,suffix:c===1?"":"s"}):d<24?t("remoteSetupHoursAgo",{count:d,suffix:d===1?"":"s"}):f===1?t("remoteSetupYesterday"):f<7?t("hostPickerLastConnectedDays",{count:f}):CG(e)}function kG(e,t,s,i){if(!t)return{text:i("remoteSetupStatusDisabled"),className:"status-disabled"};if(!s)return{text:i("remoteSetupStatusNotConfigured"),className:"status-warning"};switch(e){case"waiting":return{text:i("remoteSetupStatusConnected"),className:"status-success"};case"connecting":return{text:i("remoteSetupStatusConnecting"),className:"status-pending"};case"registering":return{text:i("remoteSetupStatusRegistering"),className:"status-pending"};case"rejected":return{text:i("remoteSetupStatusUsernameTaken"),className:"status-error"};default:return{text:i("remoteSetupStatusDisconnected"),className:"status-warning"}}}function TG({title:e="Remote Access",description:t="Access your server from anywhere.",onSetupComplete:s}){const{t:i}=xt(),{config:l,relayConfig:c,relayStatus:d,sessions:f,loading:m,error:g,configure:v,enable:b,disable:w,updateRelayConfig:_,revokeSession:C,revokeAllSessions:S,refresh:N}=sG(),[T,k]=h.useState(""),[A,P]=h.useState(""),[U,O]=h.useState(""),[z,q]=h.useState("default"),[oe,K]=h.useState(""),[I,B]=h.useState(!1),[Z,Q]=h.useState(null),[ae,W]=h.useState(!1),[Y,V]=h.useState(!1),[ne,ge]=h.useState(null),[$,G]=h.useState(!1);h.useEffect(()=>{c&&(k(c.username),c.url===Ni?(q("default"),K("")):(q("custom"),K(c.url)))},[c]),h.useEffect(()=>{const $e=T!==((c==null?void 0:c.username)??""),Et=A.length>0,Oe=z==="default"?Ni:oe,Ot=(c==null?void 0:c.url)??Ni;V($e||Et||Oe!==Ot)},[T,A,z,oe,c]),h.useEffect(()=>{if((d==null?void 0:d.status)==="connecting"||(d==null?void 0:d.status)==="registering"){const $e=setInterval(N,2e3);return()=>clearInterval($e)}},[d==null?void 0:d.status,N]);const le=(l==null?void 0:l.enabled)??!1,fe=!!(l!=null&&l.username),ue=()=>z==="default"?Ni:oe,_e=async()=>{if(Q(null),!T.trim())return Q(i("remoteSetupErrorUsernameRequired")),!1;if(T.length<3)return Q(i("remoteSetupErrorUsernameShort")),!1;if(!fe&&!A)return Q(i("remoteSetupErrorPasswordRequired")),!1;if(A&&A.length<8)return Q(i("remoteSetupErrorPasswordShort")),!1;if(A&&A!==U)return Q(i("remoteSetupErrorPasswordMismatch")),!1;if(z==="custom"&&!oe.trim())return Q(i("remoteSetupErrorCustomRelayRequired")),!1;try{const $e=ue();return(T!==(c==null?void 0:c.username)||$e!==(c==null?void 0:c.url))&&await _({url:$e,username:T}),A&&(await v(A),ge(A)),P(""),O(""),V(!1),!0}catch($e){return Q($e instanceof Error?$e.message:i("remoteSetupErrorSaveFailed")),!1}},Ke=async $e=>{Q(null),B(!0);try{if($e)if(Y){if(!await _e()){B(!1);return}s==null||s()}else fe&&(await b(),s==null||s());else await w()}catch(Et){Q(Et instanceof Error?Et.message:i("remoteSetupErrorUpdateFailed"))}finally{B(!1)}},tt=async $e=>{$e.preventDefault(),B(!0),await _e()&&(s==null||s()),B(!1)},De=async $e=>{await navigator.clipboard.writeText($e),W(!0),setTimeout(()=>W(!1),2e3)};if(m)return r.jsxs("div",{className:"remote-access-setup",children:[r.jsx("div",{className:"remote-access-header",children:r.jsxs("div",{children:[r.jsx("h3",{children:e}),r.jsx("p",{children:t})]})}),r.jsx("div",{className:"remote-access-loading",children:i("remoteSetupLoading")})]});const vt=kG((d==null?void 0:d.status)??null,le,fe,i),me=(()=>{const $e=new URLSearchParams;T&&$e.set("u",T);const Et=ue();Et!==Ni&&$e.set("r",Et);const Oe=$e.toString();return Oe?`${Wf}?${Oe}`:Wf})(),We=(()=>{if(!ne||!T)return null;const $e=new URLSearchParams;$e.set("u",T),$e.set("p",ne);const Et=ue();return Et!==Ni&&$e.set("r",Et),`${Wf}#${$e.toString()}`})(),ot=le&&(d==null?void 0:d.status)==="waiting"&&We!==null,ut=fe||T&&A;return r.jsxs("div",{className:"remote-access-setup",children:[r.jsxs("div",{className:"remote-access-header",children:[r.jsxs("div",{children:[r.jsx("h3",{children:e}),r.jsx("p",{children:t})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:le,onChange:$e=>Ke($e.target.checked),disabled:I||!le&&!ut}),r.jsx("span",{className:"toggle-slider"})]})]}),r.jsxs("form",{onSubmit:tt,className:"remote-access-form",children:[r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"remote-username",children:i("remoteSetupUsername")}),r.jsx("input",{id:"remote-username",type:"text",value:T,onChange:$e=>k($e.target.value.toLowerCase()),placeholder:i("remoteSetupUsernamePlaceholder"),minLength:3,maxLength:32,pattern:"[a-z0-9][a-z0-9-]*[a-z0-9]|[a-z0-9]{1,2}",title:i("remoteSetupUsernameHint"),autoComplete:"username",disabled:I})]}),r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"remote-password",children:i(fe?"remoteSetupNewPassword":"remoteSetupPassword")}),r.jsx("input",{id:"remote-password",type:"password",value:A,onChange:$e=>P($e.target.value),placeholder:fe?"••••••••":"",minLength:8,autoComplete:"new-password",disabled:I})]}),A&&r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"remote-confirm",children:i("remoteSetupConfirmPassword")}),r.jsx("input",{id:"remote-confirm",type:"password",value:U,onChange:$e=>O($e.target.value),minLength:8,autoComplete:"new-password",disabled:I})]}),r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"relay-select",children:i("remoteSetupRelayServer")}),r.jsxs("select",{id:"relay-select",value:z,onChange:$e=>q($e.target.value),disabled:I,className:"form-select",children:[r.jsx("option",{value:"default",children:i("remoteSetupRelayDefault")}),r.jsx("option",{value:"custom",children:i("remoteSetupRelayCustom")})]})]}),z==="custom"&&r.jsxs("div",{className:"form-field",children:[r.jsx("label",{htmlFor:"custom-relay-url",children:i("remoteSetupCustomRelayUrl")}),r.jsx("input",{id:"custom-relay-url",type:"text",value:oe,onChange:$e=>K($e.target.value),placeholder:i("remoteSetupCustomRelayPlaceholder"),disabled:I})]}),r.jsxs("div",{className:"remote-access-status",children:[r.jsx("span",{className:"status-label",children:i("remoteSetupStatus")}),r.jsx("span",{className:`status-indicator ${vt.className}`,children:vt.text}),(d==null?void 0:d.error)&&r.jsx("span",{className:"status-error-detail",children:d.error})]}),(Z||g)&&r.jsx("p",{className:"form-error",children:Z||g}),le&&T&&r.jsxs("div",{className:"remote-access-connect",children:[r.jsx("span",{className:"connect-label",children:i("remoteSetupConnectFrom")}),r.jsxs("div",{className:"connect-url-row",children:[r.jsx("code",{className:"connect-url",children:me}),r.jsx("button",{type:"button",className:"copy-button",onClick:()=>De(me),title:i("remoteSetupCopyUrl"),children:i(ae?"remoteSetupCopied":"remoteSetupCopy")})]})]}),ot&&r.jsxs("div",{className:"remote-access-qr",children:[r.jsx("button",{type:"button",className:"qr-toggle-button",onClick:()=>G(!$),children:i($?"remoteSetupHideQr":"remoteSetupShowQr")}),$&&We&&r.jsxs("div",{className:"qr-code-container",children:[r.jsx(_G,{value:We,size:200}),r.jsx("p",{className:"qr-code-hint",children:i("remoteSetupQrHint")})]})]}),r.jsxs("div",{className:"remote-access-sessions",children:[r.jsxs("div",{className:"sessions-header",children:[r.jsx("span",{className:"sessions-title",children:i("remoteSetupSessions",{count:f.length})}),f.length>0&&r.jsx("button",{type:"button",className:"revoke-all-button",onClick:()=>S(),disabled:I,children:i("remoteSetupRevokeAll")})]}),f.length===0?r.jsx("p",{className:"sessions-empty",children:i("remoteSetupNoSessions")}):r.jsx("ul",{className:"sessions-list",children:f.map($e=>{const{browser:Et,os:Oe}=$e.userAgent?s0($e.userAgent):{browser:i("remoteSetupUnknownBrowser"),os:i("remoteSetupUnknownOs")},Ot=$e.userAgent||$e.origin;return r.jsxs("li",{className:"session-item",children:[r.jsx("div",{className:"session-info",children:Ot?r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"session-device",children:[Et," · ",Oe]}),$e.origin&&r.jsx("code",{className:"session-origin",children:$e.origin}),r.jsxs("span",{className:"session-dates",children:[i("remoteSetupCreated",{date:Pb($e.createdAt,i)})," ","·"," ",i("remoteSetupLastUsed",{date:Pb($e.lastUsed,i)})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"session-created",children:[i("remoteSetupCreatedLabel")," ",new Date($e.createdAt).toLocaleDateString()]}),r.jsxs("span",{className:"session-last-used",children:[i("remoteSetupLastUsedLabel")," ",new Date($e.lastUsed).toLocaleDateString()]})]})}),r.jsx("button",{type:"button",className:"revoke-button",onClick:()=>C($e.sessionId),disabled:I,children:i("remoteSetupRevoke")})]},$e.sessionId)})})]}),r.jsx("div",{className:"remote-access-actions",children:r.jsx("button",{type:"submit",className:"settings-button",disabled:I||!Y,children:i(I?"remoteSetupSaving":"remoteSetupSave")})})]})]})}function AG(){const{t:e}=xt(),t=js(),s=Vi(),{settings:i,isLoading:l,error:c,updateSetting:d}=io(),f=()=>{s==null||s.disconnect(),t("/login")},m=r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("developmentPersistRemoteTitle")}),r.jsxs("p",{children:[e("developmentPersistRemoteDescriptionPrefix")," ",r.jsx("code",{children:"remote-sessions.json"})," so relay reconnect survives",e("developmentPersistRemoteDescriptionSuffix")]})]}),r.jsxs("label",{className:"toggle-switch",children:[r.jsx("input",{type:"checkbox",checked:(i==null?void 0:i.persistRemoteSessionsToDisk)??!1,disabled:l,onChange:g=>void d("persistRemoteSessionsToDisk",g.target.checked)}),r.jsx("span",{className:"toggle-slider"})]})]})}),c&&r.jsx("p",{className:"settings-warning",children:c})]});if(s){const g=s.currentHostId?pR(s.currentHostId):null,v=(g==null?void 0:g.displayName)||s.storedUsername||e("remoteAccessDefaultHost");return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("remoteAccessConnectedTitle")}),r.jsx("p",{className:"settings-section-description",children:e("remoteAccessConnectedDescription")}),r.jsxs("div",{className:"settings-group",children:[r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessCurrentHostTitle")}),r.jsx("p",{children:v})]}),r.jsx("button",{type:"button",className:"settings-button",onClick:f,children:e("sidebarSwitchHost")})]}),r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteAccessLogoutTitle")}),r.jsx("p",{children:e("remoteAccessLogoutDescription")})]}),r.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>s.disconnect(),children:e("remoteAccessLogout")})]})]}),m]})}return r.jsxs("section",{className:"settings-section",children:[r.jsx(TG,{title:e("remoteAccessConnectedTitle"),description:e("remoteAccessSetupDescription")}),m]})}function RG(){const{t:e}=xt(),{executors:t,loading:s,addExecutor:i,removeExecutor:l,testExecutor:c}=I0(),[d,f]=h.useState(""),[m,g]=h.useState(!1),[v,b]=h.useState(null),[w,_]=h.useState({}),C=async()=>{if(!(!d.trim()||m)){g(!0),b(null);try{await i(d.trim()),f("")}catch(k){b(k instanceof Error?k.message:e("remoteExecutorsAddFailed"))}finally{g(!1)}}},S=async k=>{try{await l(k),_(A=>{const{[k]:P,...U}=A;return U})}catch(A){console.error("Failed to remove executor:",A)}},N=async k=>{_(A=>({...A,[k]:{testing:!0}}));try{const A=await c(k);_(P=>({...P,[k]:{testing:!1,result:A}}))}catch(A){_(P=>({...P,[k]:{testing:!1,result:{success:!1,error:A instanceof Error?A.message:e("remoteExecutorsConnectionFailed")}}}))}},T=k=>{k.key==="Enter"&&(k.preventDefault(),C())};return r.jsxs("section",{className:"settings-section",children:[r.jsx("h2",{children:e("remoteExecutorsTitle")}),r.jsx("p",{className:"settings-section-description",children:e("remoteExecutorsDescription")}),r.jsx("div",{className:"settings-group",children:r.jsxs("div",{className:"settings-item",children:[r.jsxs("div",{className:"settings-item-info",children:[r.jsx("strong",{children:e("remoteExecutorsAddTitle")}),r.jsx("p",{children:e("remoteExecutorsAddDescription")})]}),r.jsxs("div",{className:"remote-executor-add",children:[r.jsx("input",{type:"text",value:d,onChange:k=>f(k.target.value),onKeyDown:T,placeholder:e("remoteExecutorsHostPlaceholder"),disabled:m,className:"remote-executor-input"}),r.jsx("button",{type:"button",onClick:C,disabled:!d.trim()||m,className:"remote-executor-add-button",children:e(m?"remoteExecutorsAdding":"remoteExecutorsAdd")})]}),v&&r.jsx("p",{className:"settings-error",children:v})]})}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("remoteExecutorsConfigured")}),s?r.jsx("p",{className:"settings-loading",children:e("loginLoading")}):t.length===0?r.jsx("p",{className:"settings-empty",children:e("remoteExecutorsEmpty")}):r.jsx("div",{className:"remote-executor-list",children:t.map(k=>{var P;const A=w[k];return r.jsxs("div",{className:"remote-executor-item",children:[r.jsxs("div",{className:"remote-executor-item-info",children:[r.jsx("span",{className:"remote-executor-host",children:k}),(A==null?void 0:A.result)&&r.jsx("span",{className:`settings-status-badge ${A.result.success?"settings-status-detected":"settings-status-not-detected"}`,children:A.result.success?e("remoteExecutorsConnected"):e("remoteExecutorsFailed")})]}),(A==null?void 0:A.result)&&!A.result.success&&r.jsx("p",{className:"settings-error remote-executor-error",children:A.result.error}),((P=A==null?void 0:A.result)==null?void 0:P.success)&&r.jsx("p",{className:"remote-executor-details",children:A.result.claudeAvailable?A.result.claudeVersion?e("remoteExecutorsClaudeVersion",{version:A.result.claudeVersion}):e("remoteExecutorsClaudeAvailable"):e("remoteExecutorsClaudeMissing")}),r.jsxs("div",{className:"remote-executor-actions",children:[r.jsx("button",{type:"button",onClick:()=>N(k),disabled:A==null?void 0:A.testing,className:"remote-executor-test-button",children:A!=null&&A.testing?e("remoteExecutorsTesting"):e("remoteExecutorsTestConnection")}),r.jsx("button",{type:"button",onClick:()=>S(k),className:"remote-executor-remove-button",children:e("remoteExecutorsRemove")})]})]},k)})})]}),r.jsxs("div",{className:"settings-group",children:[r.jsx("h3",{children:e("remoteExecutorsSetupRequirements")}),r.jsxs("ul",{className:"settings-requirements",children:[r.jsx("li",{children:e("remoteExecutorsRequirementSshConfig")}),r.jsx("li",{children:e("remoteExecutorsRequirementKeyAuth")}),r.jsx("li",{children:e("remoteExecutorsRequirementClaude")}),r.jsx("li",{children:e("remoteExecutorsRequirementPaths")})]})]})]})}const MG={appearance:NZ,model:FZ,"agent-context":EZ,notifications:KZ,webhooks:IZ,devices:RZ,"local-access":BZ,remote:AG,providers:nG,"remote-executors":RG,emulator:OZ,about:jZ,development:_Z};function Ib({category:e,isActive:t,onClick:s}){return r.jsxs("button",{type:"button",className:`settings-category-item ${t?"active":""}`,onClick:s,children:[r.jsx("span",{className:"settings-category-icon",children:e.icon}),r.jsxs("div",{className:"settings-category-text",children:[r.jsx("span",{className:"settings-category-label",children:e.label}),r.jsx("span",{className:"settings-category-description",children:e.description})]}),r.jsx("span",{className:"settings-category-chevron",children:"›"})]})}function zb(){var N;const{t:e}=xt(),{category:t}=tu(),s=js(),i=mo(),{openSidebar:l,isWideScreen:c,toggleSidebar:d,isSidebarCollapsed:f}=Io(),{isManualReloadMode:m}=Bh(),{version:g}=il(),v=(g==null?void 0:g.capabilities)??[],b=[...bZ(T=>e(T))];if(v.includes("deviceBridge")||v.includes("deviceBridge-download")||v.includes("deviceBridge-available")){const T=b.findIndex(k=>k.id==="about");b.splice(T>=0?T:b.length,0,yZ(k=>e(k)))}m&&b.push(SZ(T=>e(T)));const w=t||(c?(N=b[0])==null?void 0:N.id:void 0),_=T=>{s(`${i}/settings/${T}`)},C=()=>{s(`${i}/settings`)},S=w?MG[w]:null;if(!c){if(!t)return r.jsx("div",{className:"main-content-mobile",children:r.jsxs("div",{className:"main-content-mobile-inner",children:[r.jsx(ro,{title:e("pageTitleSettings"),onOpenSidebar:l,onToggleSidebar:d,isWideScreen:c,isSidebarCollapsed:f}),r.jsx("main",{className:"page-scroll-container",children:r.jsx("div",{className:"page-content-inner",children:r.jsx("div",{className:"settings-category-list",children:b.map(k=>r.jsx(Ib,{category:k,isActive:!1,onClick:()=>_(k.id)},k.id))})})})]})});const T=b.find(k=>k.id===t);return r.jsx("div",{className:"main-content-mobile",children:r.jsxs("div",{className:"main-content-mobile-inner",children:[r.jsx(ro,{title:(T==null?void 0:T.label)||e("pageTitleSettings"),onOpenSidebar:l,showBack:!0,onBack:C}),r.jsx("main",{className:"page-scroll-container",children:r.jsx("div",{className:"page-content-inner",children:S&&r.jsx(S,{})})})]})})}return r.jsx("div",{className:"main-content-wrapper",children:r.jsxs("div",{className:"main-content-constrained",children:[r.jsx(ro,{title:e("pageTitleSettings"),onOpenSidebar:l,onToggleSidebar:d,isWideScreen:c,isSidebarCollapsed:f}),r.jsx("main",{className:"page-scroll-container",children:r.jsxs("div",{className:"settings-two-column",children:[r.jsx("nav",{className:"settings-category-nav",children:r.jsx("div",{className:"settings-category-list",children:b.map(T=>r.jsx(Ib,{category:T,isActive:w===T.id,onClick:()=>_(T.id)},T.id))})}),r.jsx("div",{className:"settings-content-panel",children:S&&r.jsx(S,{})})]})})]})})}const DG=h.Fragment;iF();$F();HF();const LG="/".replace(/\/$/,"")||void 0,kS=document.getElementById("root");if(!kS)throw new Error("Root element not found");Hj.createRoot(kS).render(r.jsx(DG,{children:r.jsx(UF,{children:r.jsx(mE,{basename:LG,children:r.jsx(OF,{children:r.jsxs(H1,{children:[r.jsx(us,{path:"/",element:r.jsx(tv,{to:"/projects",replace:!0})}),r.jsx(us,{path:"/login",element:r.jsx(W7,{})}),r.jsxs(us,{element:r.jsx(vH,{}),children:[r.jsx(us,{path:"/projects",element:r.jsx(eq,{})}),r.jsx(us,{path:"/sessions",element:r.jsx(B7,{})}),r.jsx(us,{path:"/agents",element:r.jsx(PH,{})}),r.jsx(us,{path:"/inbox",element:r.jsx(V7,{})}),r.jsx(us,{path:"/settings",element:r.jsx(zb,{})}),r.jsx(us,{path:"/settings/:category",element:r.jsx(zb,{})}),r.jsx(us,{path:"/projects/:projectId",element:r.jsx(tv,{to:"/sessions",replace:!0})}),r.jsx(us,{path:"/git-status",element:r.jsx(M7,{})}),r.jsx(us,{path:"/devices",element:r.jsx(Gv,{})}),r.jsx(us,{path:"/devices/:deviceId",element:r.jsx(Gv,{})}),r.jsx(us,{path:"/new-session",element:r.jsx(X7,{})}),r.jsx(us,{path:"/projects/:projectId/sessions/:sessionId",element:r.jsx(hZ,{})})]}),r.jsx(us,{path:"/projects/:projectId/file",element:r.jsx(k7,{})}),r.jsx(us,{path:"/activity",element:r.jsx(NH,{})})]})})})})}));
@@ -27,7 +27,7 @@
27
27
  document.documentElement.setAttribute('data-theme', theme);
28
28
  })();
29
29
  </script>
30
- <script type="module" crossorigin src="/assets/index-Cy0SYugM.js"></script>
30
+ <script type="module" crossorigin src="/assets/index-Dl3KP_uH.js"></script>
31
31
  <link rel="stylesheet" crossorigin href="/assets/index-B3erjAgD.css">
32
32
  </head>
33
33
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yepanywhere",
3
- "version": "0.4.27",
3
+ "version": "0.4.28",
4
4
  "description": "A mobile-first supervisor for Claude Code agents",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@agentclientprotocol/sdk": "^0.12.0",
21
- "@anthropic-ai/claude-agent-sdk": "^0.2.90",
21
+ "@anthropic-ai/claude-agent-sdk": "^0.2.111",
22
22
  "@hono/node-server": "^1.19.9",
23
23
  "@hono/node-ws": "^1.2.0",
24
24
  "@openai/codex-sdk": "^0.77.0",