yepanywhere 0.3.1 → 0.3.2
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.
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ A polished web interface for managing Claude and Codex agents. Works great on mo
|
|
|
26
26
|
|
|
27
27
|
## What is this?
|
|
28
28
|
|
|
29
|
-
If you use Claude Code from the terminal, this gives you a better interface. Auto-detects your installed CLI tools and provides:
|
|
29
|
+
If you use Claude Code or Codex from the terminal, this gives you a better interface. Auto-detects your installed CLI tools and provides:
|
|
30
30
|
|
|
31
31
|
- **Interop first** — View sessions running in Claude CLI, VS Code, or other tools in real time, or resume them later from your phone. No new database — just a tiny JSON cache and optional metadata for starring/archiving
|
|
32
32
|
- **Multi-session dashboard** — See all your agents at a glance, easy multitasking
|
|
@@ -46,9 +46,7 @@ No database, no cloud, no accounts, no hidden gimmicks. 100% open source. Piggyb
|
|
|
46
46
|
| Provider | Edit Visibility | Local Models | Approval Flow | Notes |
|
|
47
47
|
|----------|-----------------|--------------|---------------|-------|
|
|
48
48
|
| Claude Code | Full | No | Yes (per-tool) | Primary provider, full mobile supervision |
|
|
49
|
-
| Codex |
|
|
50
|
-
| Codex-OSS | Full | Yes | No | Local models struggle with 6k system prompt |
|
|
51
|
-
| Gemini | N/A (read-only) | No | N/A | Analysis only, no write tools |
|
|
49
|
+
| Codex | Full | No | Yes (per-tool) | Full support — diffs, approvals, streaming |
|
|
52
50
|
| OpenCode | ? | ? | ? | Early integration, approvals not implemented |
|
|
53
51
|
|
|
54
52
|
## Screenshots
|
|
@@ -73,7 +71,7 @@ No database, no cloud, no accounts, no hidden gimmicks. 100% open source. Piggyb
|
|
|
73
71
|
|
|
74
72
|
## Getting Started
|
|
75
73
|
|
|
76
|
-
If you can install Claude
|
|
74
|
+
If you can install Claude Code or Codex, you can install this. Minimal dependencies.
|
|
77
75
|
|
|
78
76
|
```
|
|
79
77
|
npm i -g yepanywhere
|
|
@@ -117,7 +115,7 @@ See [DEVELOPMENT.md](DEVELOPMENT.md) for build instructions, configuration optio
|
|
|
117
115
|
- **No file uploads** — can't share screenshots, photos, PDFs, or other files with your agent
|
|
118
116
|
- No voice input
|
|
119
117
|
- No multi-session overview
|
|
120
|
-
- This gives you
|
|
118
|
+
- This gives you a polished UI, but self-hosted and editing your code
|
|
121
119
|
|
|
122
120
|
## License
|
|
123
121
|
|
|
@@ -154,4 +154,4 @@ ${r.map(({path:f,message:p})=>`- \`${f}\`: ${p}`).join(`
|
|
|
154
154
|
${u}`})})})},renderToolResult(e,t,r){const i=Vv(e),l=Gv(i);return l.output.trim()?a.jsx("div",{className:`bash-result ${t?"bash-result-error":""}`,children:a.jsx("pre",{className:`code-block ${t?"code-block-error":""}`,children:a.jsx("code",{children:l.output})})}):l.exitCode!==void 0?a.jsx("div",{className:"bash-empty",children:`Command exited with code ${l.exitCode}`}):a.jsx("div",{className:"bash-empty",children:"No output"})},getUseSummary(e){const t=Fv(e),r=qv(e),i=Zv(e),l=i&&i.length>60?`${i.slice(0,57)}...`:i;return r===void 0||r.length===0?l||"waiting for output":l?`${l} (input)`:`sent input (${t})`},getResultSummary(e,t){if(t)return"Error";const r=Vv(e),i=Gv(r);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(`
|
|
155
155
|
`).filter(Boolean).length} lines`:"No output"}},Yv={shell_command:"Bash",exec_command:"Bash",write_stdin:"WriteStdin",update_plan:"UpdatePlan",apply_patch:"Edit",web_search_call:"WebSearch",search_query:"WebSearch"};function x5(e){return Yv[e]??Yv[e.toLowerCase()]??e}class v5{constructor(t){Ie(this,"tools",new Map);Ie(this,"fallback");this.fallback=t}register(t){this.tools.set(t.tool,t)}get(t){const r=x5(t);return this.tools.get(r)||this.fallback}renderToolUse(t,r,i){return this.get(t).renderToolUse(r,i)}renderToolResult(t,r,i,l,u){return this.get(t).renderToolResult(r,i,l,u)}hasInteractiveSummary(t){return typeof this.get(t).renderInteractiveSummary=="function"}hasCollapsedPreview(t){return typeof this.get(t).renderCollapsedPreview=="function"}renderCollapsedPreview(t,r,i,l,u){const d=this.get(t);return d.renderCollapsedPreview?d.renderCollapsedPreview(r,i,l,u):null}renderInteractiveSummary(t,r,i,l,u){const d=this.get(t);return d.renderInteractiveSummary?d.renderInteractiveSummary(r,i,l,u):null}hasInlineRenderer(t){return typeof this.get(t).renderInline=="function"}renderInline(t,r,i,l,u,d){const f=this.get(t);return f.renderInline?f.renderInline(r,i,l,u,d):null}getDisplayName(t){return this.get(t).displayName||t}}const b5={tool:"__fallback__",renderToolUse(e,t){return a.jsx("pre",{className:"tool-fallback",children:a.jsx("code",{children:JSON.stringify(e,null,2)})})},renderToolResult(e,t,r){return a.jsx("pre",{className:`tool-fallback ${t?"tool-fallback-error":""}`,children:a.jsx("code",{children:JSON.stringify(e,null,2)})})}},Kt=new v5(b5);Kt.register(PR);Kt.register(SA);Kt.register(tA);Kt.register(f5);Kt.register(oA);Kt.register(hA);Kt.register(GA);Kt.register(HA);Kt.register(a5);Kt.register(n5);Kt.register(TR);Kt.register(sA);Kt.register(JA);Kt.register(g5);Kt.register(zR);Kt.register(NA);Kt.register(gA);function yf(e){try{return e()}catch{return}}function fy(e,t,r,i){const l=Kt.get(e);if(i==="pending"||i==="aborted"){if(l.getUseSummary){const f=yf(()=>{var p;return(p=l.getUseSummary)==null?void 0:p.call(l,t)});if(f!==void 0)return f}return Sf(e,t)}let u;l.getUseSummary?u=yf(()=>{var p;return(p=l.getUseSummary)==null?void 0:p.call(l,t)})??Sf(e,t):u=Sf(e,t);let d;return l.getResultSummary?d=yf(()=>{var p;return(p=l.getResultSummary)==null?void 0:p.call(l,r==null?void 0:r.structured,(r==null?void 0:r.isError)??!1,t)})??Wv(e,r,i):d=Wv(e,r,i),e==="Glob"||e==="Grep"?`${u} → ${d}`:e==="Bash"?u:d}function Sf(e,t){if(!t||typeof t!="object")return"...";const r=t;switch(e){case"Read":case"Write":case"Edit":if(typeof r.file_path=="string")return S5(r.file_path);break;case"Bash":if(typeof r.command=="string")return bi(r.command,40);if(typeof r.cmd=="string")return bi(r.cmd,40);break;case"Glob":if(typeof r.pattern=="string")return r.pattern;break;case"Grep":if(typeof r.pattern=="string")return`"${r.pattern}"`;break;case"Task":if(typeof r.description=="string")return bi(r.description,30);break;case"WebSearch":if(typeof r.query=="string")return bi(r.query,30);break;case"WebFetch":if(typeof r.url=="string")return bi(r.url,40);break}return y5(r)}function y5(e){for(const t of Object.values(e))if(typeof t=="string"&&t.length>0&&t.length<100)return bi(t,40);return"..."}function Wv(e,t,r){if(r==="error")return"failed";if(!t)return"done";const l=(typeof t.content=="string"?t.content:"").split(`
|
|
156
156
|
`).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 bi(e,t){return e.length<=t?e:`${e.slice(0,t-3)}...`}function S5(e){return e.split("/").pop()||e}const j5=h.memo(function({id:t,toolName:r,toolInput:i,toolResult:l,status:u}){const d=Kt.hasInlineRenderer(r),f=Kt.hasInteractiveSummary(r),p=Kt.hasCollapsedPreview(r),x=f||p,[v,y]=h.useState(!x&&(r==="Edit"||r==="TodoWrite")),S=h.useMemo(()=>fy(r,i,l,u),[r,i,l,u]),w=()=>{x||y(!v)},E=h.useMemo(()=>({isStreaming:u==="pending",theme:"dark",toolUseId:t}),[u,t]),_=(l==null?void 0:l.structured)??(l==null?void 0:l.content);return d?a.jsx("div",{className:"tool-inline timeline-item",children:Kt.renderInline(r,i,_,(l==null?void 0:l.isError)??!1,u,E)}):a.jsxs("div",{className:`tool-row timeline-item ${v?"expanded":"collapsed"} status-${u} ${x?"interactive":""}`,children:[a.jsxs("div",{className:`tool-row-header ${x?"non-expandable":""}`,onClick:x?void 0:w,onKeyDown:x?void 0:C=>C.key==="Enter"&&w(),role:x?"presentation":"button",tabIndex:x?void 0:0,children:[u==="pending"&&a.jsx("span",{className:"tool-spinner","aria-label":"Running",children:a.jsx(_5,{})}),u==="aborted"&&a.jsx("span",{className:"tool-aborted-icon","aria-label":"Interrupted",children:"⨯"}),a.jsx("span",{className:"tool-name",children:Kt.getDisplayName(r)}),f&&u==="complete"?a.jsx("span",{className:"tool-summary interactive-summary",children:Kt.renderInteractiveSummary(r,i,_,(l==null?void 0:l.isError)??!1,E)}):a.jsxs("span",{className:"tool-summary",children:[S,u==="aborted"&&a.jsx("span",{className:"tool-aborted-label",children:" (interrupted)"})]}),!x&&a.jsx("span",{className:"expand-chevron","aria-hidden":"true",children:v?"▾":"▸"})]}),p&&a.jsx("div",{className:"tool-row-collapsed-preview",children:Kt.renderCollapsedPreview(r,i,_,(l==null?void 0:l.isError)??!1,E)}),v&&!x&&a.jsx("div",{className:"tool-row-content",children:u==="pending"||u==="aborted"?a.jsx(w5,{toolName:r,toolInput:i,context:E}):a.jsx(N5,{toolName:r,toolInput:i,toolResult:l,context:E})})]})});function w5({toolName:e,toolInput:t,context:r}){return a.jsx("div",{className:"tool-use-expanded",children:Kt.renderToolUse(e,t,r)})}function N5({toolName:e,toolInput:t,toolResult:r,context:i}){if(!r)return a.jsx("div",{className:"tool-no-result",children:"No result data"});const l=r.structured??r.content;return a.jsx("div",{className:"tool-result-expanded",children:Kt.renderToolResult(e,l,r.isError,i,t)})}function _5(){return a.jsx("svg",{className:"spinner",viewBox:"0 0 16 16",width:"12",height:"12","aria-hidden":"true",children:a.jsx("circle",{cx:"8",cy:"8",r:"6",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeDasharray:"24",strokeDashoffset:"8"})})}const Pf=h.memo(function({item:t,isStreaming:r,thinkingExpanded:i,toggleThinkingExpanded:l}){const u=h.useCallback(f=>{const p=window.getSelection();p&&p.toString().length>0||f.shiftKey&&!f.ctrlKey&&!f.metaKey&&(f.preventDefault(),f.stopPropagation(),console.log("[DEBUG] RenderItem:",t),console.log("[DEBUG] Source JSONL entries:",t.sourceMessages))},[t]),d=()=>{switch(t.type){case"text":return a.jsx(bR,{text:t.text,isStreaming:t.isStreaming,augmentHtml:t.augmentHtml});case"thinking":return a.jsx(jR,{thinking:t.thinking,status:t.status,isExpanded:i,onToggle:l});case"tool_call":return a.jsx(j5,{id:t.id,toolName:t.toolName,toolInput:t.toolInput,toolResult:t.toolResult,status:t.status});case"user_prompt":return a.jsx(Xb,{content:t.content});case"session_setup":return a.jsx(pR,{title:t.title,prompts:t.prompts});case"system":{const f=t.subtype==="status"&&t.status==="compacting",p=t.subtype==="error",x=p?"!":"⟳";return a.jsxs("div",{className:`system-message ${f?"system-message-compacting":""} ${p?"system-message-error":""}`,children:[a.jsx("span",{className:`system-message-icon ${f?"spinning":""}`,children:x}),a.jsx("span",{className:"system-message-text",children:t.content})]})}default:return null}};return a.jsx("div",{className:t.isSubagent?"subagent-item":void 0,"data-render-type":t.type,"data-render-id":t.id,onClick:u,children:d()})});function E5(e){const t=[];let r=[];for(const i of e)i.type==="user_prompt"||i.type==="session_setup"?(r.length>0&&(t.push({isUserPrompt:!1,items:r}),r=[]),t.push({isUserPrompt:!0,items:[i]})):r.push(i);return r.length>0&&t.push({isUserPrompt:!1,items:r}),t}const C5=h.memo(function({messages:t,isStreaming:r=!1,isProcessing:i=!1,isCompacting:l=!1,scrollTrigger:u=0,pendingMessages:d=[],deferredMessages:f=[],onCancelDeferred:p,markdownAugments:x,activeToolApproval:v}){const y=h.useRef(null),S=h.useRef(!0),w=h.useRef(!0),E=h.useRef(!1),_=h.useRef(0),C=h.useRef(null),[k,O]=h.useState(!1),L=h.useCallback(H=>{E.current=!0,H.scrollTop=H.scrollHeight-H.clientHeight,_.current=H.scrollHeight,requestAnimationFrame(()=>{E.current=!1}),C.current!==null&&clearTimeout(C.current),C.current=setTimeout(()=>{C.current=null,S.current&&(E.current=!0,H.scrollTop=H.scrollHeight-H.clientHeight,_.current=H.scrollHeight,requestAnimationFrame(()=>{E.current=!1}))},50)},[]),P=h.useMemo(()=>yh(t,{markdown:x,activeToolApproval:v}),[t,x,v]),U=h.useMemo(()=>E5(P),[P]),A=h.useCallback(()=>{O(H=>!H)},[]),$=h.useCallback(()=>{var de;if(E.current)return;const H=(de=y.current)==null?void 0:de.parentElement;if(!H)return;const F=100,ee=H.scrollHeight-H.scrollTop-H.clientHeight;S.current=ee<F},[]);return h.useEffect(()=>{var F;const H=(F=y.current)==null?void 0:F.parentElement;if(H)return H.addEventListener("scroll",$),()=>{H.removeEventListener("scroll",$)}},[$]),h.useEffect(()=>{var de;const H=(de=y.current)==null?void 0:de.parentElement;if(!H)return;const F=H;_.current=F.scrollHeight;const ee=new ResizeObserver(()=>{const Y=F.scrollHeight;Y>_.current&&S.current?L(F):_.current=Y});return y.current&&ee.observe(y.current),()=>{ee.disconnect(),C.current!==null&&clearTimeout(C.current)}},[L]),h.useEffect(()=>{var H;if(u>0){S.current=!0;const F=(H=y.current)==null?void 0:H.parentElement;F&&L(F)}},[u,L]),h.useEffect(()=>{var H;if(w.current&&P.length>0){const F=(H=y.current)==null?void 0:H.parentElement;F&&L(F),w.current=!1}},[P.length,L]),a.jsxs("div",{className:"message-list",ref:y,children:[U.map(H=>{if(H.isUserPrompt){const ee=H.items[0];return ee?a.jsx(Pf,{item:ee,isStreaming:r,thinkingExpanded:k,toggleThinkingExpanded:A},ee.id):null}const F=H.items[0];return F?a.jsx("div",{className:"assistant-turn",children:H.items.map(ee=>a.jsx(Pf,{item:ee,isStreaming:r,thinkingExpanded:k,toggleThinkingExpanded:A},ee.id))},`turn-${F.id}`):null}),d.map(H=>a.jsxs("div",{className:"pending-message",children:[a.jsx("div",{className:"message-user-prompt pending-message-bubble",children:H.content}),a.jsx("div",{className:"pending-message-status",children:"Sending..."})]},H.tempId)),f.map((H,F)=>a.jsxs("div",{className:"deferred-message",children:[a.jsx("div",{className:"message-user-prompt deferred-message-bubble",children:H.content}),a.jsxs("div",{className:"deferred-message-footer",children:[a.jsx("span",{className:"deferred-message-status",children:F===0?"Queued (next)":`Queued (#${F+1})`}),H.tempId&&p&&a.jsx("button",{type:"button",className:"deferred-message-cancel",onClick:()=>p(H.tempId),"aria-label":"Cancel queued message",children:"×"})]})]},H.tempId??`deferred-${F}`)),l&&a.jsxs("div",{className:"system-message system-message-compacting",children:[a.jsx("span",{className:"system-message-icon spinning",children:"⟳"}),a.jsx("span",{className:"system-message-text",children:"Compacting context..."})]}),a.jsx(eR,{isProcessing:i})]})});function k5(e){return e?e>=1e3?`${Math.round(e/1e3)}K tokens`:`${e} tokens`:"Disabled"}function T5(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/1e3),u=Math.floor(l/60),d=Math.floor(u/60),f=Math.floor(d/24);return f>0?`${f}d ${d%24}h`:d>0?`${d}h ${u%60}m`:u>0?`${u}m ${l%60}s`:`${l}s`}function jf(e){return new Date(e).toLocaleString()}function R5(e){if(!e)return"Never";const t=Math.floor((Date.now()-e)/1e3);if(t<5)return"Just now";if(t<60)return`${t}s ago`;const r=Math.floor(t/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ${r%60}m ago`}function A5(e){if(!e)return null;const t=[];return e.networkAccess!==void 0&&t.push(`network ${e.networkAccess?"on":"off"}`),e.excludeTmpdirEnvVar!==void 0&&t.push(`$TMPDIR ${e.excludeTmpdirEnvVar?"excluded":"included"}`),e.excludeSlashTmp!==void 0&&t.push(`/tmp ${e.excludeSlashTmp?"excluded":"included"}`),t.length===0?e.type:`${e.type} (${t.join(", ")})`}function Xt({label:e,value:t,mono:r=!1}){return t==null?null:a.jsxs("div",{className:"process-info-row",children:[a.jsx("span",{className:"process-info-label",children:e}),a.jsx("span",{className:`process-info-value ${r?"mono":""}`,children:t})]})}function Ao({title:e,children:t}){return a.jsxs("div",{className:"process-info-section",children:[a.jsx("h3",{className:"process-info-section-title",children:e}),t]})}function M5({sessionId:e,provider:t,model:r,status:i,processState:l,contextUsage:u,originator:d,cliVersion:f,sessionSource:p,approvalPolicy:x,sandboxPolicy:v,sessionStreamConnected:y,lastSessionEventAt:S,onClose:w}){const[E,_]=h.useState(null),[C,k]=h.useState(!1),[O,L]=h.useState(null),{connected:P,connectionState:U}=ih();h.useEffect(()=>{i.owner==="self"&&(k(!0),L(null),ze.getProcessInfo(e).then(H=>{_(H.process)}).catch(H=>{L(H.message||"Failed to fetch process info")}).finally(()=>{k(!1)}))},[e,i.owner]);const A=H=>H.split("-").map(F=>F.charAt(0).toUpperCase()+F.slice(1)).join(" "),$=H=>{switch(H){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 H}};return a.jsx(ts,{title:"Session Info",onClose:w,children:a.jsxs("div",{className:"process-info-content",children:[a.jsxs(Ao,{title:"Session",children:[a.jsx(Xt,{label:"Session ID",value:e,mono:!0}),a.jsx(Xt,{label:"Provider",value:$(t)}),a.jsx(Xt,{label:"Model",value:r||"Default",mono:!0}),a.jsx(Xt,{label:"Ownership",value:A(i.owner)}),a.jsx(Xt,{label:"Activity",value:A(l)}),a.jsx(Xt,{label:"Originator",value:d}),a.jsx(Xt,{label:"CLI version",value:f,mono:!0}),a.jsx(Xt,{label:"Session source",value:p}),a.jsx(Xt,{label:"Approval policy",value:x,mono:!0}),a.jsx(Xt,{label:"Sandbox policy",value:A5(v),mono:!0})]}),a.jsxs(Ao,{title:"Connection",children:[a.jsx(Xt,{label:"Activity stream",value:P?"Connected":"Disconnected"}),a.jsx(Xt,{label:"Connection state",value:U}),a.jsx(Xt,{label:i.owner==="external"?"Session watch":"Session stream",value:i.owner==="none"?"Not subscribed":y?"Connected":"Disconnected"}),i.owner==="self"&&S&&a.jsx(Xt,{label:"Last session event",value:R5(new Date(S).getTime())}),i.owner==="external"&&a.jsx(Xt,{label:"Subscription mode",value:"Focused file watch"})]}),u&&a.jsxs(Ao,{title:"Token Usage",children:[a.jsx(Xt,{label:"Input tokens",value:u.inputTokens.toLocaleString()}),u.outputTokens!==void 0&&a.jsx(Xt,{label:"Output tokens",value:u.outputTokens.toLocaleString()}),a.jsx(Xt,{label:"Context used",value:`${u.percentage.toFixed(1)}%`}),u.cacheReadTokens!==void 0&&a.jsx(Xt,{label:"Cache read",value:u.cacheReadTokens.toLocaleString()}),u.cacheCreationTokens!==void 0&&a.jsx(Xt,{label:"Cache created",value:u.cacheCreationTokens.toLocaleString()})]}),a.jsx(Ao,{title:"Process",children:i.owner==="self"?a.jsxs(a.Fragment,{children:[C&&a.jsx("div",{className:"process-info-loading",children:"Loading..."}),O&&a.jsx("div",{className:"process-info-error",children:O}),E&&a.jsxs(a.Fragment,{children:[a.jsx(Xt,{label:"Process ID",value:E.id,mono:!0}),a.jsx(Xt,{label:"Started",value:jf(E.startedAt)}),a.jsx(Xt,{label:"Uptime",value:T5(E.startedAt)}),a.jsx(Xt,{label:"Queue depth",value:E.queueDepth}),a.jsx(Xt,{label:"Extended thinking",value:k5(E.maxThinkingTokens)}),E.idleSince&&a.jsx(Xt,{label:"Idle since",value:jf(E.idleSince)}),E.holdSince&&a.jsx(Xt,{label:"Hold since",value:jf(E.holdSince)})]}),!C&&!E&&!O&&a.jsx("div",{className:"process-info-loading",children:"No process data"})]}):i.owner==="external"?a.jsx("div",{className:"process-info-muted",children:"Session controlled by external process (VS Code, CLI)"}):a.jsx("div",{className:"process-info-muted",children:"No active process"})}),E&&a.jsxs(Ao,{title:"Project",children:[a.jsx(Xt,{label:"Name",value:E.projectName}),a.jsx(Xt,{label:"Path",value:E.projectPath,mono:!0}),a.jsx(Xt,{label:"Remote host",value:E.executor,mono:!0})]})]})})}const O5={claude:"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)"},z5={claude:"Claude",codex:"Codex","codex-oss":"CodexOSS",gemini:"Gemini","gemini-acp":"Gemini ACP",opencode:"OpenCode"};function L5({provider:e,compact:t=!1,model:r,isThinking:i=!1,className:l=""}){const u=O5[e],d=z5[e],p=(y=>{if(!y||y==="default")return null;const S=Uf.find(E=>E.value===y);if(S&&S.value!=="default")return S.label;const w=y.match(/claude-(\w+)-/);if(w!=null&&w[1]){const E=w[1],_=Uf.find(C=>C.value===E);return _?_.label:E.charAt(0).toUpperCase()+E.slice(1)}return y.charAt(0).toUpperCase()+y.slice(1)})(r);if(t)return a.jsx("span",{className:`provider-badge-stripe ${l}`,style:{backgroundColor:u},title:p?`${d} (${p})`:d,"aria-label":`Provider: ${d}${p?` (${p})`:""}`});const x=i?"provider-badge-dot-inline thinking":"provider-badge-dot-inline",v=i?{backgroundColor:"var(--thinking-color)"}:{backgroundColor:u};return a.jsxs("span",{className:`provider-badge ${l}`,style:{borderColor:u,color:u},children:[a.jsx("span",{className:x,style:v}),a.jsx("span",{className:"provider-badge-label",children:d}),p&&a.jsx("span",{className:"provider-badge-model",children:p})]})}const hy="draft-tool-prompt-";function U5(e){const t=`${hy}${e}-toolApprovalFeedback`,[r,i]=h.useState(()=>{try{return localStorage.getItem(t)??""}catch{return""}}),l=h.useCallback(d=>{i(d);try{d?localStorage.setItem(t,d):localStorage.removeItem(t)}catch{}},[t]),u=h.useCallback(()=>{i("");try{localStorage.removeItem(t)}catch{}},[t]);return[r,l,u]}function D5(e){const t=`${hy}${e}-questionOther`,[r,i]=h.useState(()=>{try{const d=localStorage.getItem(t);return d?JSON.parse(d):{}}catch{return{}}}),l=h.useCallback((d,f)=>{i(p=>{const x={...p};f?x[d]=f:delete x[d];try{Object.keys(x).length>0?localStorage.setItem(t,JSON.stringify(x)):localStorage.removeItem(t)}catch{}return x})},[t]),u=h.useCallback(()=>{i({});try{localStorage.removeItem(t)}catch{}},[t]);return[r,l,u]}function B5({request:e,sessionId:t,onSubmit:r,onDeny:i}){const l=e.toolInput,u=(l==null?void 0:l.questions)||[],[d,f]=h.useState(0),[p,x]=h.useState({}),[v,y,S]=D5(t),[w,E]=h.useState(!1),[_,C]=h.useState(!1),k=h.useRef(null),O=u[d],L=d===u.length-1,P=O?p[O.question]:void 0,U=P==="__other__",A=u.every(Y=>{const te=p[Y.question];return te?te==="__other__"?(v[Y.question]||"").trim().length>0:!0:!1});h.useEffect(()=>{U&&k.current&&(k.current.focus(),setTimeout(()=>{var Y;(Y=k.current)==null||Y.scrollIntoView({behavior:"smooth",block:"center"})},100))},[U]);const $=h.useCallback(Y=>{O&&x(te=>({...te,[O.question]:Y}))},[O]),H=h.useCallback(Y=>{O&&y(O.question,Y)},[O,y]),F=h.useCallback(()=>{L||f(Y=>Y+1)},[L]),ee=h.useCallback(async()=>{if(!A||w)return;const Y={};for(const te of u){const be=p[te.question];be==="__other__"?Y[te.question]=v[te.question]||"":be&&(Y[te.question]=be)}E(!0);try{await r(Y),S()}finally{E(!1)}},[A,w,u,p,v,r,S]),de=h.useCallback(async()=>{E(!0);try{await i()}finally{E(!1)}},[i]);return h.useEffect(()=>{const Y=te=>{if(!w){if(te.key==="Escape"){te.preventDefault(),de();return}if(te.key==="Enter"&&!te.shiftKey){const be=P&&P!=="__other__",Ce=P==="__other__"&&(v[(O==null?void 0:O.question)||""]||"").trim().length>0;(be||Ce)&&(te.preventDefault(),L&&A?ee():F())}te.key==="Tab"&&!U&&(te.preventDefault(),te.shiftKey?f(be=>Math.max(0,be-1)):f(be=>Math.min(u.length-1,be+1)))}};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[w,P,O,v,L,A,U,u.length,de,ee,F]),u.length?a.jsxs("div",{className:"question-panel-wrapper",children:[a.jsx("button",{type:"button",className:"question-panel-toggle",onClick:()=>C(!_),"aria-label":_?"Expand question panel":"Collapse question panel","aria-expanded":!_,children:a.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:_?"chevron-up":"chevron-down","aria-hidden":"true",children:a.jsx("polyline",{points:"6 9 12 15 18 9"})})}),!_&&a.jsxs("div",{className:"question-panel",children:[a.jsx("div",{className:"question-tabs",children:u.map((Y,te)=>{const be=te===d,Ce=!!p[Y.question];return a.jsxs("button",{type:"button",className:`question-tab ${be?"active":""} ${Ce?"answered":""}`,onClick:()=>f(te),children:[Ce&&a.jsx("span",{className:"question-tab-check",children:"✓"}),Y.header]},Y.question)})}),O&&a.jsxs("div",{className:"question-content",children:[a.jsx("div",{className:"question-text",children:O.question}),a.jsxs("div",{className:"question-options-list",children:[O.options.map(Y=>{const te=P===Y.label;return a.jsxs("button",{type:"button",className:`question-option-btn ${te?"selected":""}`,onClick:()=>$(Y.label),children:[a.jsx("span",{className:"question-option-radio",children:O.multiSelect?te?"☑":"☐":te?"●":"○"}),a.jsxs("div",{className:"question-option-text",children:[a.jsx("span",{className:"question-option-label",children:Y.label}),Y.description&&a.jsx("span",{className:"question-option-desc",children:Y.description})]})]},Y.label)}),a.jsxs("button",{type:"button",className:`question-option-btn other ${U?"selected":""}`,onClick:()=>$("__other__"),children:[a.jsx("span",{className:"question-option-radio",children:U?"●":"○"}),a.jsx("div",{className:"question-option-text",children:a.jsx("span",{className:"question-option-label",children:"Other"})})]}),U&&a.jsx("div",{className:"question-other-input",children:a.jsx("input",{ref:k,type:"text",placeholder:"Type your answer...",value:v[O.question]||"",onChange:Y=>H(Y.target.value)})})]})]}),a.jsxs("div",{className:"question-actions",children:[a.jsxs("button",{type:"button",className:"question-btn deny",onClick:de,disabled:w,children:["Cancel",a.jsx("kbd",{children:"esc"})]}),L?a.jsxs("button",{type:"button",className:"question-btn submit",onClick:ee,disabled:!A||w,children:["Submit",a.jsx("kbd",{children:"↵"})]}):a.jsxs("button",{type:"button",className:"question-btn next",onClick:F,disabled:!P||w,children:["Next",a.jsx("kbd",{children:"↵"})]})]})]})]}):a.jsx("div",{className:"question-panel-wrapper",children:a.jsx("div",{className:"question-panel",children:a.jsx("div",{className:"question-panel-empty",children:"No questions to answer"})})})}const Xv=10;function I5(e){const t=Date.now(),r=new Date(e).getTime(),i=t-r,l=Math.floor(i/6e4),u=Math.floor(i/36e5),d=Math.floor(i/864e5);return l<1?"now":l<60?`${l}m`:u<24?`${u}h`:d<7?`${d}d`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function $5(e){return e.customTitle||e.title||"Untitled"}function P5({session:e}){if(e.activity==="in-turn")return a.jsx(Rr,{});if(e.pendingInputType){const r=e.pendingInputType==="tool-approval"?"Appr":"Q";return a.jsx("span",{className:"recent-sessions-badge needs-input",children:r})}return e.ownership.owner==="external"?a.jsx("span",{className:"recent-sessions-badge external",children:"Ext"}):null}function H5({currentSessionId:e,isOpen:t,onClose:r,onNavigate:i,triggerRef:l,basePath:u=""}){var S;const d=h.useRef(null),{sessions:f}=kc({limit:Xv+5}),p=f.filter(w=>w.id!==e&&!w.isArchived).slice(0,Xv);if(h.useEffect(()=>{if(!t)return;const w=_=>{const C=_.target;d.current&&!d.current.contains(C)&&l.current&&!l.current.contains(C)&&r()},E=_=>{_.key==="Escape"&&r()};return document.addEventListener("mousedown",w),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",E)}},[t,r,l]),h.useEffect(()=>{if(!t)return;const w=()=>r();return window.addEventListener("scroll",w,{passive:!0}),()=>window.removeEventListener("scroll",w)},[t,r]),!t)return null;const x=(S=l.current)==null?void 0:S.getBoundingClientRect(),v=x?{position:"fixed",top:x.bottom+4,left:Math.max(8,x.left-100),width:"min(830px, calc(100vw - 32px))"}:{},y=a.jsxs("div",{ref:d,className:"recent-sessions-dropdown",style:v,children:[a.jsx("div",{className:"recent-sessions-header",children:"Recent Sessions"}),p.length===0?a.jsx("div",{className:"recent-sessions-empty",children:"No other sessions"}):a.jsx("div",{className:"recent-sessions-list",children:p.map(w=>a.jsxs(Gs,{to:`${u}/projects/${w.projectId}/sessions/${w.id}`,className:`recent-session-item${w.hasUnread?" unread":""}`,onClick:()=>{i(w.id,w.projectId),r()},children:[a.jsxs("div",{className:"recent-session-content",children:[a.jsxs("span",{className:"recent-session-title",children:[w.isStarred&&a.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:a.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"})}),a.jsx("span",{className:"recent-session-title-text",children:$5(w)})]}),a.jsx("span",{className:"recent-session-project",children:w.projectName})]}),a.jsxs("div",{className:"recent-session-meta",children:[a.jsx(P5,{session:w}),a.jsx("span",{className:"recent-session-time",children:I5(w.updatedAt)})]})]},w.id))})]});return Ai.createPortal(y,document.body)}const F5=["Edit","Write","NotebookEdit"],wf=e=>e==="ExitPlanMode",q5=150;function Z5({request:e,sessionId:t,onApprove:r,onDeny:i,onApproveAcceptEdits:l,onDenyWithFeedback:u,collapsed:d=!1,onCollapsedChange:f}){const[p,x]=h.useState(!1),[v,y]=h.useState(!1),[S,w,E]=U5(t),[_,C]=h.useState(()=>S.length>0),k=h.useRef(null);h.useEffect(()=>{y(!1);const H=setTimeout(()=>y(!0),q5);return()=>clearTimeout(H)},[e.id]);const O=e.toolName&&F5.includes(e.toolName),L=h.useCallback(async()=>{x(!0);try{await r()}finally{x(!1)}},[r]),P=h.useCallback(async()=>{if(l){x(!0);try{await l()}finally{x(!1)}}},[l]),U=h.useCallback(async()=>{x(!0);try{await i()}finally{x(!1)}},[i]),A=h.useCallback(async()=>{if(!(!u||!S.trim())){x(!0);try{await u(S.trim()),E(),C(!1)}finally{x(!1)}}},[u,S,E]);h.useEffect(()=>{_&&k.current&&k.current.focus()},[_]),h.useEffect(()=>{const H=F=>{if(p||!v)return;if(_){F.key==="Escape"?(F.preventDefault(),C(!1),E()):F.key==="Enter"&&S.trim()&&(F.preventDefault(),A());return}wf(e.toolName)?F.key==="1"&&l?(F.preventDefault(),P()):F.key==="2"?(F.preventDefault(),L()):F.key==="3"?(F.preventDefault(),U()):F.key==="Enter"&&!F.shiftKey&&l?(F.preventDefault(),P()):F.key==="Escape"&&(F.preventDefault(),U()):F.key==="1"?(F.preventDefault(),L()):F.key==="2"&&O&&l?(F.preventDefault(),P()):F.key==="3"||F.key==="2"&&(!O||!l)?(F.preventDefault(),U()):F.key==="Enter"&&!F.shiftKey?(F.preventDefault(),L()):F.key==="Escape"&&(F.preventDefault(),U())};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[L,P,U,A,p,v,_,S,E,O,l,e.toolName]);const $=e.toolName?fy(e.toolName,e.toolInput,void 0,"pending"):e.prompt;return a.jsxs("div",{className:"tool-approval-wrapper",children:[a.jsx("button",{type:"button",className:`tool-approval-toggle ${d?"has-pending":""}`,onClick:()=>f==null?void 0:f(!d),"aria-label":d?"Expand approval panel":"Collapse approval panel","aria-expanded":!d,children:a.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:a.jsx("polyline",{points:"6 9 12 15 18 9"})})}),!d&&a.jsxs("div",{className:"tool-approval-panel",children:[a.jsx("div",{className:"tool-approval-header",children:wf(e.toolName)?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"tool-approval-title",children:"Accept this plan?"}),a.jsx("span",{className:"tool-approval-subtitle",children:"Review the plan above and decide whether to proceed"})]}):a.jsxs("span",{className:"tool-approval-question",children:["Allow"," ",a.jsx("span",{className:"tool-approval-name",children:e.toolName})," ",$,"?"]})}),a.jsxs("div",{className:"tool-approval-options",children:[wf(e.toolName)?a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"tool-approval-option primary",onClick:P,disabled:!v||p||!l,children:[a.jsx("kbd",{children:"1"}),a.jsx("span",{children:"Yes, and auto-accept"})]}),a.jsxs("button",{type:"button",className:"tool-approval-option",onClick:L,disabled:!v||p,children:[a.jsx("kbd",{children:"2"}),a.jsx("span",{children:"Yes, and manually approve edits"})]}),a.jsxs("button",{type:"button",className:"tool-approval-option",onClick:U,disabled:!v||p,children:[a.jsx("kbd",{children:"3"}),a.jsx("span",{children:"No, keep planning"})]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"tool-approval-option primary",onClick:L,disabled:!v||p,children:[a.jsx("kbd",{children:"1"}),a.jsx("span",{children:"Yes"})]}),O&&l&&a.jsxs("button",{type:"button",className:"tool-approval-option",onClick:P,disabled:!v||p,children:[a.jsx("kbd",{children:"2"}),a.jsx("span",{children:"Yes, and don't ask again"})]}),a.jsxs("button",{type:"button",className:"tool-approval-option",onClick:U,disabled:!v||p,children:[a.jsx("kbd",{children:O&&l?"3":"2"}),a.jsx("span",{children:"No"})]})]}),u&&!_&&a.jsx("button",{type:"button",className:"tool-approval-option feedback-toggle",onClick:()=>C(!0),disabled:!v||p,children:a.jsx("span",{children:"Tell Claude what to do instead"})}),u&&_&&a.jsxs("div",{className:"tool-approval-feedback",children:[a.jsx("input",{ref:k,type:"text",placeholder:"Tell Claude what to do instead...",value:S,onChange:H=>w(H.target.value),disabled:!v||p,className:"tool-approval-feedback-input"}),a.jsx("button",{type:"button",className:"tool-approval-feedback-submit",onClick:A,disabled:!v||p||!S.trim(),children:"Send"})]})]})]})]})}const V5=3e4,Kv=2e3;function G5(e){const{sessionId:t,activityAt:r,updatedAt:i,lastSeenAt:l,hasUnread:u=!1,enabled:d=!0}=e,f=h.useRef(Date.now()),p=h.useRef(null),x=h.useRef(null),v=h.useRef(!0),y=h.useRef(!0),S=h.useCallback(()=>r?l?r>l||u:!0:!1,[r,l,u]),w=h.useCallback(()=>{const C=document.hasFocus(),k=Date.now()-f.current<V5;return C&&k},[]),E=h.useCallback(()=>{!d||!v.current||!r||!i||p.current!==r&&w()&&S()&&(x.current&&clearTimeout(x.current),x.current=setTimeout(async()=>{if(v.current)try{await ze.markSessionSeen(t,i),p.current=r}catch(C){console.warn("[useEngagementTracking] Failed to mark session as seen:",C)}},Kv))},[d,t,r,i,w,S]);return h.useEffect(()=>{if(!d)return;const C=()=>{f.current=Date.now(),S()&&w()&&E()},k=["mousemove","keydown","scroll","click","touchstart"];for(const O of k)window.addEventListener(O,C,{passive:!0});return()=>{for(const O of k)window.removeEventListener(O,C)}},[d,S,w,E]),h.useEffect(()=>{if(!d)return;const C=()=>{document.visibilityState==="visible"&&S()&&w()&&E()},k=()=>{f.current=Date.now(),S()&&w()&&E()};return document.addEventListener("visibilitychange",C),window.addEventListener("focus",k),()=>{document.removeEventListener("visibilitychange",C),window.removeEventListener("focus",k)}},[d,S,w,E]),h.useEffect(()=>{d&&(!r||!i||y.current&&(y.current=!1,S()&&(x.current&&clearTimeout(x.current),x.current=setTimeout(async()=>{if(v.current&&p.current!==r)try{await ze.markSessionSeen(t,i),p.current=r}catch(C){console.warn("[useEngagementTracking] Failed to mark session as seen:",C)}},Kv))))},[d,t,r,i,S]),h.useEffect(()=>(v.current=!0,()=>{v.current=!1,x.current&&clearTimeout(x.current)}),[]),{forceMarkSeen:h.useCallback(async()=>{if(!(!d||!i))try{await ze.markSessionSeen(t,i),p.current=r}catch(C){console.warn("[useEngagementTracking] Failed to force mark session as seen:",C)}},[d,t,r,i]),isEngaged:w}}function Y5(e,t){ze.recordVisit(e,t).catch(r=>{console.error("Failed to record session visit:",r)})}function W5(e){var i;const t=new Map,r=new Set;for(const l of e){const u=((i=l.message)==null?void 0:i.content)??l.content;if(Array.isArray(u))for(const d of u){if(d.type==="tool_use"&&d.name==="Task"&&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"&&r.add(d.tool_use_id)}}return[...t.entries()].filter(([l])=>!r.has(l)).map(([l,{description:u,subagentType:d}])=>({toolUseId:l,description:u,subagentType:d}))}function X5(e){const t=e.relativePath.split(/[\\/]/).pop();if(!t)return null;let r=t;if(r.endsWith(".jsonl")?r=r.slice(0,-6):r.endsWith(".json")&&(r=r.slice(0,-5)),e.provider==="codex"){const i=r.match(/([0-9a-fA-F-]{36})$/);if(i)return i[1]??null}return r}function K5(e){const{projectId:t,sessionId:r,onLoadComplete:i,onLoadError:l}=e,[u,d]=h.useState([]),[f,p]=h.useState({}),[x,v]=h.useState(()=>new Map),[y,S]=h.useState(!0),[w,E]=h.useState(null),_=h.useRef([]),C=h.useRef(!1),k=h.useRef(void 0),O=h.useRef(void 0);h.useEffect(()=>{const Y=u[u.length-1];Y&&(O.current=qn(Y))},[u]);const L=h.useCallback(Y=>{d(te=>x3(te,Y).messages)},[]),P=h.useCallback((Y,te)=>{p(be=>{const Ce=be[te]??{messages:[],status:"running"},D=qn(Y);return Ce.messages.some(Z=>qn(Z)===D)?be:{...be,[te]:{...Ce,messages:[...Ce.messages,Y],status:"running"}}})},[]),U=h.useCallback(()=>{const Y=_.current;_.current=[];for(const te of Y)te.type==="message"?L(te.msg):P(te.msg,te.agentId)},[L,P]);h.useEffect(()=>{C.current=!1,_.current=[],S(!0),p({}),ze.getSession(t,r).then(Y=>{E(Y.session),k.current=Y.session.provider;const te=Y.messages.map(Ce=>({...Ce,_source:"jsonl"}));d(te);const be=te[te.length-1];be&&(O.current=qn(be)),C.current=!0,U(),S(!1),i==null||i({session:Y.session,status:Y.ownership,pendingInputRequest:Y.pendingInputRequest})}).catch(Y=>{S(!1),l==null||l(Y)})},[t,r,i,l,U]);const A=h.useCallback((Y,te)=>{const be=qn(Y);if(be){if(te){p(Ce=>{const D=Ce[te]??{messages:[],status:"running"},Z=D.messages.findIndex(V=>qn(V)===be);if(Z>=0){const V=[...D.messages];return V[Z]=Y,{...Ce,[te]:{...D,messages:V}}}return{...Ce,[te]:{...D,messages:[...D.messages,Y]}}});return}d(Ce=>{const D=Ce.findIndex(Z=>qn(Z)===be);if(D>=0){const Z=[...Ce];return Z[D]=Y,Z}return[...Ce,Y]})}},[]),$=h.useCallback(Y=>{if(!C.current){_.current.push({type:"message",msg:Y});return}L(Y)},[L]),H=h.useCallback((Y,te)=>{if(!C.current){_.current.push({type:"subagent",msg:Y,agentId:te});return}P(Y,te)},[P]),F=h.useCallback((Y,te)=>{v(be=>{if(be.has(Y))return be;const Ce=new Map(be);return Ce.set(Y,te),Ce})},[]),ee=h.useCallback(async()=>{try{const Y=await ze.getSession(t,r,O.current);Y.messages.length>0&&d(te=>g3(te,Y.messages,{skipDagOrdering:!Db(Y.session.provider).capabilities.supportsDag}).messages),E(te=>te?{...te,...Y.session,messages:te.messages}:Y.session)}catch{}},[t,r]),de=h.useCallback(async()=>{try{const Y=await ze.getSessionMetadata(t,r);E(te=>te?{...te,...Y.session,messages:te.messages}:{...Y.session,messages:[]})}catch{}},[t,r]);return{messages:u,agentContent:f,toolUseToAgent:x,loading:y,session:w,setSession:E,handleStreamingUpdate:A,handleStreamMessageEvent:$,handleStreamSubagentMessage:H,registerToolUseAgent:F,setAgentContent:p,setToolUseToAgent:v,setMessages:d,fetchNewMessages:ee,fetchSessionMetadata:de}}function J5(e,t){const[r,i]=h.useState(!1),l=h.useRef(null),u=h.useRef(null),d=h.useRef(t);d.current=t;const f=h.useRef(null),p=h.useRef(!1),x=h.useCallback(()=>{if(!e){f.current=null;return}l.current||f.current!==e&&(f.current=e,v(e,Io()))},[e]),v=h.useCallback((y,S)=>{if(l.current){const C=l.current;l.current=null,C.close()}let w=null;const E=()=>w!==null&&l.current!==w,_={onEvent:(C,k,O)=>{if(kn.recordEvent(),C==="heartbeat"){kn.recordHeartbeat();return}k&&(u.current=k),d.current.onMessage({...O,eventType:C})},onOpen:()=>{var C,k;E()||(i(!0),kn.markConnected(),(k=(C=d.current).onOpen)==null||k.call(C))},onError:C=>{var k,O;if(!E()){if(i(!1),l.current=null,f.current=null,(O=(k=d.current).onError)==null||O.call(k,new Event("error")),Uo(C)){console.warn("[useSessionStream] Non-retryable error, not reconnecting:",C.message);return}kn.handleError(C)}},onClose:()=>{p.current||E()||(i(!1),l.current=null,f.current=null)}};w=S.subscribeSession(y,_,u.current??void 0),l.current=w},[]);return h.useEffect(()=>kn.on("stateChange",y=>{if(y==="reconnecting"||y==="disconnected"){if(l.current){const S=l.current;l.current=null,S.close()}i(!1),f.current=null}y==="connected"&&e&&!l.current&&x()}),[e,x]),h.useEffect(()=>(x(),()=>{var y;p.current=!0,(y=l.current)==null||y.close(),l.current=null,f.current=null,p.current=!1}),[x]),{connected:r}}function Q5(e,t){const[r,i]=h.useState(!1),l=h.useRef(null),u=h.useRef(t);u.current=t;const d=h.useRef(null),f=h.useRef(!1),p=h.useCallback(()=>{if(!e){d.current=null;return}const v=`${e.projectId}:${e.sessionId}`;l.current||d.current!==v&&(d.current=v,x(e,Io()))},[e]),x=h.useCallback((v,y)=>{if(l.current){const _=l.current;l.current=null,_.close()}let S=null;const w=()=>S!==null&&l.current!==S,E={onEvent:(_,C,k)=>{if(kn.recordEvent(),_==="heartbeat"){kn.recordHeartbeat();return}_==="session-watch-change"&&u.current.onChange()},onOpen:()=>{var _,C;w()||(i(!0),kn.markConnected(),(C=(_=u.current).onOpen)==null||C.call(_))},onError:_=>{var C,k;if(!w()){if(i(!1),l.current=null,d.current=null,(k=(C=u.current).onError)==null||k.call(C,new Event("error")),Uo(_)){console.warn("[useSessionWatchStream] Non-retryable error, not reconnecting:",_.message);return}kn.handleError(_)}},onClose:()=>{f.current||w()||(i(!1),l.current=null,d.current=null)}};S=y.subscribeSessionWatch(v.sessionId,E,{projectId:v.projectId,provider:v.provider}),l.current=S},[]);return h.useEffect(()=>kn.on("stateChange",v=>{if(v==="reconnecting"||v==="disconnected"){if(l.current){const y=l.current;l.current=null,y.close()}i(!1),d.current=null}v==="connected"&&e&&!l.current&&p()}),[e,p]),h.useEffect(()=>(p(),()=>{var v;f.current=!0,(v=l.current)==null||v.close(),l.current=null,d.current=null,f.current=!1}),[p]),{connected:r}}function my(){const e=localStorage.getItem(ls.streamingEnabled);return e===null?!0:e==="true"}function e8(e){localStorage.setItem(ls.streamingEnabled,String(e))}function t8(){const[e,t]=h.useState(my),r=h.useCallback(i=>{t(i),e8(i)},[]);return{streamingEnabled:e,setStreamingEnabled:r}}function n8(){return my()}const s8=50;function r8(e){const{onUpdateMessage:t,streamingMarkdownCallbacks:r,onToolUseMapping:i,onAgentContextUsage:l,contextWindowSize:u}=e,d=h.useRef(new Map),f=h.useRef(null),p=h.useRef(null),x=h.useRef({timer:null,pendingIds:new Set}),v=h.useCallback(C=>{const k=d.current.get(C);if(!k)return;const O={id:C,type:"assistant",role:"assistant",message:{role:"assistant",content:k.blocks},_isStreaming:!0,_source:"sdk"};t(O,k.agentId)},[t]),y=h.useCallback(C=>{const k=x.current;k.pendingIds.add(C),k.timer||(k.timer=setTimeout(()=>{for(const O of k.pendingIds)v(O);k.pendingIds.clear(),k.timer=null},s8))},[v]),S=h.useCallback(C=>{var H,F;if(C.type!=="stream_event"||!n8())return!1;const O=C.event;if(!O)return!0;const L=O.type,U=C.isSubagent&&typeof C.parentToolUseId=="string"?C.parentToolUseId:void 0;if(U&&i&&i(U,U),L==="message_start"){const ee=O.message;if(ee!=null&&ee.id&&(f.current=ee.id,p.current=U??null,(H=r==null?void 0:r.setCurrentMessageId)==null||H.call(r,ee.id),U&&l)){const de=ee.usage;if(de!=null&&de.input_tokens){const Y=de.input_tokens,te=typeof ee.model=="string"?ee.model:void 0,be=typeof ee.model_context_window=="number"?ee.model_context_window:void 0,Ce=be&&be>0?be:te?Rf(te):u??Rf(void 0),D=Y/Ce*100;l(U,{inputTokens:Y,percentage:D})}}return!0}const A=f.current??`stream-${Date.now()}`,$=p.current??U;if(L==="content_block_start"){const ee=O.index,de=O.content_block;if(de){const Y=d.current.get(A)??{blocks:[],isStreaming:!0,agentId:$};for(;Y.blocks.length<=ee;)Y.blocks.push({type:"text",text:""});Y.blocks[ee]={type:de.type??"text",text:de.text??"",thinking:de.thinking??void 0},d.current.set(A,Y),v(A)}}else if(L==="content_block_delta"){const ee=O.index,de=O.delta;if(de){const Y=d.current.get(A);if(Y!=null&&Y.blocks[ee]){const te=Y.blocks[ee],be=de.type;be==="text_delta"&&de.text?te.text=(te.text??"")+de.text:be==="thinking_delta"&&de.thinking&&(te.thinking=(te.thinking??"")+de.thinking),y(A)}}}else L==="content_block_stop"||L==="message_stop"&&(d.current.delete(A),(F=r==null?void 0:r.onStreamEnd)==null||F.call(r));return!0},[v,y,r,i,l,u]),w=h.useCallback(()=>{d.current.clear(),f.current=null,p.current=null},[]),E=h.useCallback(()=>p.current,[]),_=h.useCallback(()=>{x.current.timer&&(clearTimeout(x.current.timer),x.current.timer=null)},[]);return{handleStreamEvent:S,clearStreaming:w,cleanup:_,getCurrentAgentId:E}}const a8=500;function i8(e){const t=e.message,r=t==null?void 0:t.content;if(typeof r=="string"){const i=r.trim();return i.length>0?i:null}if(Array.isArray(r)){const i=r.map(u=>{if(!u||typeof u!="object")return"";const d=u.text;return typeof d=="string"?d:""}).filter(u=>u.length>0);if(i.length===0)return null;const l=i.join(`
|
|
157
|
-
`).trim();return l.length>0?l:null}return null}function o8(e,t,r,i){const[l,u]=h.useState(r??{owner:"none"}),[d,f]=h.useState(r?"in-turn":"idle"),[p,x]=h.useState(null),[v,y]=h.useState(null),[S,w]=h.useState(t),[E,_]=h.useState(null),[C,k]=h.useState([]),[O,L]=h.useState([]),[P,U]=h.useState(!1),[A,$]=h.useState({}),[H,F]=h.useState("default"),[ee,de]=h.useState("default"),[Y,te]=h.useState(0),be=h.useRef(!1);h.useEffect(()=>{be.current=!1},[t]);const[Ce,D]=h.useState([]),[Z,V]=h.useState([]),[ge,De]=h.useState([]),B=h.useRef(0),se=h.useCallback((Ue,St)=>{St>=B.current&&(B.current=St,de(Ue),F(Ue),te(St))},[]),me=h.useCallback(Ue=>{u(St=>St.owner==="self"&&Ue.status.owner!=="self"?St:Ue.status),Ue.status.owner==="self"&&Ue.status.permissionMode&&Ue.status.modeVersion!==void 0&&se(Ue.status.permissionMode,Ue.status.modeVersion),Ue.pendingInputRequest&&x(Ue.pendingInputRequest)},[se]),ie=h.useCallback(Ue=>{y(Ue)},[]),{messages:Ne,agentContent:Ae,toolUseToAgent:Ke,loading:$e,session:fe,setSession:Ze,handleStreamingUpdate:jt,handleStreamMessageEvent:ve,handleStreamSubagentMessage:_t,registerToolUseAgent:Me,setAgentContent:at,setToolUseToAgent:Ht,setMessages:gn,fetchNewMessages:ht}=K5({projectId:e,sessionId:t,onLoadComplete:me,onLoadError:ie}),Ft=h.useCallback(async Ue=>{if(F(Ue),l.owner==="self"||l.owner==="external")try{const St=await ze.setPermissionMode(t,Ue);St.modeVersion>=B.current&&(B.current=St.modeVersion,de(St.permissionMode),te(St.modeVersion))}catch(St){console.warn("Failed to sync permission mode:",St)}},[t,l.owner]),Cn=h.useCallback(async Ue=>{if(l.owner!=="self"&&l.owner!=="external"){console.warn("Cannot set hold: no active process");return}try{const St=await ze.setHold(t,Ue);St.state==="hold"?f("hold"):St.state==="in-turn"&&f("in-turn")}catch(St){console.warn("Failed to set hold:",St)}},[t,l.owner]),Dn=h.useRef({timer:null,pending:!1}),Se=h.useCallback(Ue=>{const St=`temp-${Date.now()}`;return k(cn=>[...cn,{tempId:St,content:Ue,timestamp:new Date().toISOString()}]),St},[]),J=h.useCallback(Ue=>{k(St=>St.filter(cn=>cn.tempId!==Ue))},[]),Re=h.useRef(null);h.useEffect(()=>{if($e||Re.current===t||Ne.length===0)return;(async()=>{Re.current=t;const St=W5(Ne);if(St.length!==0)try{const{mappings:cn}=await ze.getAgentMappings(e,t),yn=new Map(cn.map(ke=>[ke.toolUseId,ke.agentId]));Ht(ke=>{const Dt=new Map(ke);for(const[pn,Bn]of yn)Dt.has(pn)||Dt.set(pn,Bn);return Dt});for(const ke of St){const Dt=yn.get(ke.toolUseId);if(Dt)try{const pn=await ze.getAgentSession(e,t,Dt);at(Bn=>{const qt=Bn[Dt];if(qt&&qt.messages.length>0){const Bs=new Set(qt.messages.map(Gn=>qn(Gn))),un=pn.messages.filter(Gn=>!Bs.has(qn(Gn)));return{...Bn,[Dt]:{messages:[...qt.messages,...un],status:pn.status}}}return{...Bn,[Dt]:pn}})}catch{}}}catch{}})()},[$e,Ne,e,t,at,Ht]);const nt=h.useCallback(()=>{const Ue=Dn.current;Ue.timer?Ue.pending=!0:(ht(),Ue.timer=setTimeout(()=>{Ue.timer=null,Ue.pending&&(Ue.pending=!1,nt())},a8))},[ht]),xt=h.useCallback(Ue=>{Ue.fileType!=="session"&&Ue.fileType!=="agent-session"||X5(Ue)!==t||l.owner!=="self"&&nt()},[t,l.owner,nt]),hn=h.useCallback(Ue=>{Ue.sessionId===t&&Ze(St=>St&&{...St,...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,Ze]),kt=h.useCallback(Ue=>{Ue.sessionId===t&&u(Ue.ownership)},[t]),mn=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&&x(St=>St||(ze.getSessionMetadata(e,t).then(cn=>{cn.pendingInputRequest&&x(cn.pendingInputRequest)}),St)))},[e,t]),ss=h.useCallback(async()=>{ht();try{const Ue=await ze.getSessionMetadata(e,t);u(Ue.ownership),Ue.ownership.owner==="none"&&(f("idle"),x(null))}catch{}},[e,t,ht]);Li({onSessionStatusChange:kt,onFileChange:xt,onSessionUpdated:hn,onProcessStateChange:mn,onReconnect:ss});const yt=h.useCallback(()=>{l.owner!=="self"&&nt()},[l.owner,nt]),{connected:sn}=Q5(l.owner!=="self"?{sessionId:t,projectId:e,provider:fe==null?void 0:fe.provider}:null,{onChange:yt});h.useEffect(()=>()=>{Dn.current.timer&&clearTimeout(Dn.current.timer)},[]);const ln=h.useCallback((Ue,St)=>{at(cn=>{const yn=cn[Ue]??{messages:[],status:"running"};return{...cn,[Ue]:{...yn,contextUsage:St}}})},[at]),{handleStreamEvent:$t,clearStreaming:Qt,cleanup:Yt}=r8({onUpdateMessage:jt,onToolUseMapping:Me,onAgentContextUsage:ln,contextWindowSize:Rf(fe==null?void 0:fe.model,fe==null?void 0:fe.provider),streamingMarkdownCallbacks:i});h.useEffect(()=>()=>{Yt()},[Yt]);const cs=h.useCallback(Ue=>{var St,cn,yn;if(Ue.eventType==="message"){_(new Date().toISOString());const ke=Ue,Dt=ke.uuid,pn=ke.id,Bn=(typeof Dt=="string"?Dt:null)??(typeof pn=="string"?pn:null)??`msg-${Date.now()}`,qt=typeof ke.type=="string"?ke.type:void 0,Bs=ke.role;if(qt==="stream_event"&&$t(ke))return;if(qt==="assistant"){const R=ke.isSubagent&&typeof ke.parentToolUseId=="string"?ke.parentToolUseId:void 0;Qt(),R?at(T=>{const b=T[R];if(!b)return T;const z=b.messages.filter(W=>!W._isStreaming);return z.length===b.messages.length?T:{...T,[R]:{...b,messages:z}}}):gn(T=>T.filter(b=>!b._isStreaming))}const un={...ke,id:Bn,type:qt,role:Bs??(qt==="user"||qt==="assistant"?qt:void 0)};if(un.eventType=void 0,qt==="system"&&ke.subtype==="init"&&(Array.isArray(ke.slash_commands)&&D(ke.slash_commands),Array.isArray(ke.tools)&&V(ke.tools),Array.isArray(ke.mcp_servers)&&De(ke.mcp_servers)),qt==="system"&&ke.subtype==="status"){const N=ke.status;U(N==="compacting");return}qt==="system"&&ke.subtype==="compact_boundary"&&U(!1);const Gn=ke.tempId;if(qt==="user"&&Gn)J(Gn);else if(qt==="user"){const N=i8(ke);N&&k(R=>{const T=R.findIndex(b=>b.content.trim()===N);return T===-1?R:R.filter((b,z)=>z!==T)})}if(ke.isSubagent&&typeof ke.parentToolUseId=="string"){const N=ke.parentToolUseId;Me(N,N),_t(un,N);return}ve(un)}else if(Ue.eventType==="status"){const ke=Ue;(ke.state==="idle"||ke.state==="in-turn"||ke.state==="waiting-input"||ke.state==="hold")&&f(ke.state),ke.state==="waiting-input"&&ke.request?(x(ke.request),ke.request.sessionId&&ke.request.sessionId!==t&&w(ke.request.sessionId)):x(null)}else if(Ue.eventType==="deferred-queue")L(Ue.messages??[]);else if(Ue.eventType==="complete")f("idle"),u({owner:"none"}),x(null),L([]);else if(Ue.eventType==="connected"){const ke=Ue,Dt=ke.sessionId??((St=ke.request)==null?void 0:St.sessionId);Dt&&Dt!==t&&w(Dt),(ke.state==="idle"||ke.state==="in-turn"||ke.state==="waiting-input"||ke.state==="hold")&&f(ke.state),ke.state==="waiting-input"&&ke.request?x(ke.request):x(null),ke.permissionMode&&ke.modeVersion!==void 0&&se(ke.permissionMode,ke.modeVersion);const pn=ke.provider,Bn=ke.model;pn&&Ze(Gn=>Gn&&{...Gn,provider:Gn.provider||pn,...Bn&&{model:Bn}}),L(ke.deferredMessages??[]);const qt=ke.provider??(fe==null?void 0:fe.provider),Bs=qt==="codex"||qt==="codex-oss",un=!be.current;be.current=!0,un&&Bs||ht()}else if(Ue.eventType==="mode-change"){const ke=Ue;ke.permissionMode&&ke.modeVersion!==void 0&&se(ke.permissionMode,ke.modeVersion)}else if(Ue.eventType==="markdown-augment"){const ke=Ue;ke.messageId&&ke.blockIndex===void 0&&ke.html?$(Dt=>({...Dt,[ke.messageId]:{html:ke.html}})):ke.blockIndex!==void 0&&((cn=i==null?void 0:i.onAugment)==null||cn.call(i,{blockIndex:ke.blockIndex,html:ke.html,type:ke.type??"text",messageId:ke.messageId}))}else if(Ue.eventType==="pending"){const ke=Ue;(yn=i==null?void 0:i.onPending)==null||yn.call(i,{html:ke.html})}else if(Ue.eventType==="session-id-changed"){const ke=Ue;ke.newSessionId&&ke.newSessionId!==t&&(w(ke.newSessionId),x(Dt=>Dt&&Dt.sessionId===ke.oldSessionId?{...Dt,sessionId:ke.newSessionId}:Dt))}},[se,t,$t,Qt,J,i,ve,_t,Me,at,gn,Ze,ht,fe==null?void 0:fe.provider]),Xs=h.useCallback(async()=>{try{(await ze.getSessionMetadata(e,t)).ownership.owner!=="self"&&(u({owner:"none"}),f("idle"))}catch{u({owner:"none"}),f("idle")}},[e,t]),{connected:Cs}=J5(l.owner==="self"?t:null,{onMessage:cs,onError:Xs}),Ds=l.owner==="self"?Cs:l.owner==="external"?sn:!1;return{session:fe,messages:Ne,agentContent:Ae,setAgentContent:at,toolUseToAgent:Ke,markdownAugments:A,status:l,processState:d,isCompacting:P,isHeld:d==="hold",pendingInputRequest:p,actualSessionId:S,permissionMode:H,modeVersion:Y,loading:$e,error:v,connected:Cs,sessionWatchConnected:sn,sessionUpdatesConnected:Ds,lastStreamActivityAt:E,setStatus:u,setProcessState:f,setPermissionMode:Ft,setHold:Cn,pendingMessages:C,addPendingMessage:Se,removePendingMessage:J,deferredMessages:O,slashCommands:Ce,sessionTools:Z,mcpServers:ge}}function l8(){const{projectId:e,sessionId:t}=Ac();return!e||!t?a.jsx("div",{className:"error",children:"Invalid session URL"}):a.jsx(gR,{children:a.jsx(c8,{projectId:e,sessionId:t},t)})}function c8({projectId:e,sessionId:t}){const{openSidebar:r,isWideScreen:i,toggleSidebar:l,isSidebarCollapsed:u}=La(),d=or(),{project:f}=db(e),p=ds(),x=vs(),v=x.state,y=v==null?void 0:v.initialStatus,S=v==null?void 0:v.initialTitle,w=v==null?void 0:v.initialModel,E=v==null?void 0:v.initialProvider,_=Jb(),C=h.useMemo(()=>{if(_)return{onAugment:_.dispatchAugment,onPending:_.dispatchPending,onStreamEnd:_.dispatchStreamEnd,setCurrentMessageId:_.setCurrentMessageId,captureHtml:_.captureStreamingHtml}},[_]),{session:k,messages:O,agentContent:L,setAgentContent:P,toolUseToAgent:U,markdownAugments:A,status:$,processState:H,isCompacting:F,pendingInputRequest:ee,actualSessionId:de,permissionMode:Y,loading:te,error:be,sessionUpdatesConnected:Ce,lastStreamActivityAt:D,setStatus:Z,setProcessState:V,setPermissionMode:ge,setHold:De,isHeld:B,pendingMessages:se,addPendingMessage:me,removePendingMessage:ie,deferredMessages:Ne,slashCommands:Ae}=o8(e,t,y,C),{holdModeEnabled:Ke,showConnectionBars:$e}=zi(),{connectionState:fe}=ih(),Ze=$.owner==="self"||$.owner==="external",jt=!$e||!Ze?"idle":Ce?"connected":fe==="reconnecting"?"connecting":"disconnected",ve=(k==null?void 0:k.provider)??E,_t=(k==null?void 0:k.model)??w,[Me,at]=h.useState(0),Ht=h.useRef(null),gn=h.useCallback(ne=>{Ht.current=ne},[]),{showToast:ht}=gh(),Ft=Ib(),Cn=$b(),Dn=h.useMemo(()=>[...Ae,"login"],[Ae]),{providers:Se}=bh(),J=h.useMemo(()=>k!=null&&k.provider?Se.find(ne=>ne.name===k.provider)??null:null,[Se,k==null?void 0:k.provider]),Re=(J==null?void 0:J.supportsPermissionMode)??!0,nt=(J==null?void 0:J.supportsThinkingToggle)??!0,xt=(J==null?void 0:J.supportsSlashCommands)??!1,[hn,kt]=h.useState(!1),[mn,ss]=h.useState(""),[yt,sn]=h.useState(!1),ln=h.useRef(null),$t=h.useRef(!1),[Qt,Yt]=h.useState(!1),cs=h.useRef(null),[Xs,Cs]=h.useState(void 0),[Ds,Ue]=h.useState(void 0),[St,cn]=h.useState(void 0),[yn,ke]=h.useState(void 0);h.useEffect(()=>{Cs(void 0),Ue(void 0),cn(void 0),ke(void 0)},[t]),h.useEffect(()=>{Y5(t,e)},[t,e]),h.useEffect(()=>{de&&de!==t&&p(`${d}/projects/${e}/sessions/${de}`,{replace:!0,state:x.state})},[de,t,e,p,x.state,d]);const[Dt,pn]=h.useState([]),[Bn,qt]=h.useState([]),[Bs,un]=h.useState(!1),[Gn,N]=h.useState(!1),R=(k==null?void 0:k.updatedAt)??null,T=h.useMemo(()=>!R&&!D?null:R?D?R>D?R:D:R:D,[R,D]);G5({sessionId:t,activityAt:T,updatedAt:R,lastSeenAt:k==null?void 0:k.lastSeenAt,hasUnread:k==null?void 0:k.hasUnread,enabled:$.owner!=="external"});const b=async ne=>{var et,it,I;if(ne.trim()==="/login"){Ft.startLogin();return}const Le=me(ne);V("in-turn"),at(ot=>ot+1);const Ge=[...Dt];pn([]);try{if($.owner==="none"){const ot=(k==null?void 0:k.model)??Cc(),pt=Lo(),Rt=await ze.resumeSession(e,t,ne,{mode:Y,model:ot,thinking:pt,provider:ve,executor:k==null?void 0:k.executor},Ge.length>0?Ge:void 0,Le);Z({owner:"self",processId:Rt.processId})}else{const ot=Lo(),pt=await ze.queueMessage(t,ne,Y,Ge.length>0?Ge:void 0,Le,ot);pt.restarted&&pt.processId&&Z({owner:"self",processId:pt.processId})}(et=Ht.current)==null||et.clearDraft()}catch(ot){if(console.error("Failed to send:",ot),ot instanceof Error&&(ot.message.includes("404")||ot.message.includes("No active process")))try{const wt=(k==null?void 0:k.model)??Cc(),Mt=Lo(),Ct=await ze.resumeSession(e,t,ne,{mode:Y,model:wt,thinking:Mt,provider:ve,executor:k==null?void 0:k.executor},Ge.length>0?Ge:void 0,Le);Z({owner:"self",processId:Ct.processId}),(it=Ht.current)==null||it.clearDraft();return}catch(wt){console.error("Failed to resume session:",wt)}ie(Le),(I=Ht.current)==null||I.restoreFromStorage(),pn(Ge),V("idle");const Rt=ot instanceof Error?ot.message:"Unknown error";ht(`Failed to send message: ${Rt}`,"error")}},z=async ne=>{var et,it;const Le=me(ne);at(I=>I+1);const Ge=[...Dt];pn([]);try{const I=Lo();await ze.queueMessage(t,ne,Y,Ge.length>0?Ge:void 0,Le,I,!0),(et=Ht.current)==null||et.clearDraft()}catch(I){console.error("Failed to queue deferred message:",I),ie(Le),(it=Ht.current)==null||it.restoreFromStorage(),pn(Ge);const ot=I instanceof Error?I.message:"Unknown error";ht(`Failed to queue message: ${ot}`,"error")}},W=async()=>{if($.owner==="self"&&$.processId){try{if((await ze.interruptProcess($.processId)).interrupted)return}catch{}await ze.abortProcess($.processId)}},K=h.useCallback(async()=>{if(ee)try{await ze.respondToInput(t,ee.id,"approve")}catch(ne){const Le=ne.status,Ge=Le?`Error ${Le}`:"Failed to approve";ht(Ge,"error")}},[t,ee,ht]),he=h.useCallback(async()=>{if(ee)try{await ze.respondToInput(t,ee.id,"approve_accept_edits"),ge("acceptEdits")}catch(ne){const Le=ne.status,Ge=Le?`Error ${Le}`:"Failed to approve";ht(Ge,"error")}},[t,ee,ge,ht]),Oe=h.useCallback(async()=>{if(ee)try{await ze.respondToInput(t,ee.id,"deny")}catch(ne){const Le=ne.status,Ge=Le?`Error ${Le}`:"Failed to deny";ht(Ge,"error")}},[t,ee,ht]),Je=h.useCallback(async ne=>{if(ee)try{await ze.respondToInput(t,ee.id,"deny",void 0,ne)}catch(Le){const Ge=Le.status,et=Ge?`Error ${Ge}`:"Failed to send feedback";ht(et,"error")}},[t,ee,ht]),Fe=h.useCallback(async ne=>{if(ee)try{await ze.respondToInput(t,ee.id,"approve",ne)}catch(Le){const Ge=Le.status,et=Ge?`Error ${Ge}`:"Failed to submit answer";ht(et,"error")}},[t,ee,ht]),zt=h.useCallback(async ne=>{for(const Le of ne){const Ge=crypto.randomUUID();qt(et=>[...et,{fileId:Ge,fileName:Le.name,bytesUploaded:0,totalBytes:Le.size,percent:0}]);try{const et=await Cn.upload(e,t,Le,{onProgress:it=>{qt(I=>I.map(ot=>ot.fileId===Ge?{...ot,bytesUploaded:it,percent:Math.round(it/Le.size*100)}:ot))}});pn(it=>[...it,et])}catch(et){console.error("Upload failed:",et);const it=et instanceof Error?et.message:"Upload failed";ht(`Failed to upload ${Le.name}: ${it}`,"error")}finally{qt(et=>et.filter(it=>it.fileId!==Ge))}}},[e,t,ht,Cn]),Ye=h.useCallback(ne=>{pn(Le=>Le.filter(Ge=>Ge.id!==ne))},[]),ct=(ee==null?void 0:ee.toolName)==="AskUserQuestion",gt=H==="in-turn"||H==="waiting-input",vt=h.useMemo(()=>$.owner!=="none"?!1:yh(O).some(Le=>Le.type==="tool_call"&&Le.status==="pending"),[O,$.owner]),mt=Cr(k),lt=Xs??(mt!=="Untitled"?mt:null)??S??"Untitled",dt=Ds??(k==null?void 0:k.isArchived)??!1,Xe=St??(k==null?void 0:k.isStarred)??!1;qb(f==null?void 0:f.name,lt);const We=()=>{ss(lt),kt(!0),setTimeout(()=>{var ne,Le;(ne=ln.current)==null||ne.focus(),(Le=ln.current)==null||Le.select()},0)},st=()=>{$t.current||(kt(!1),ss(""))},Pe=()=>{if(!$t.current){if(!mn.trim()||mn.trim()===lt){st();return}Ve()}},Ve=async()=>{if(!(!mn.trim()||yt)){$t.current=!0,sn(!0);try{await ze.updateSessionMetadata(t,{title:mn.trim()}),Cs(mn.trim()),kt(!1),ht("Session renamed","success")}catch(ne){console.error("Failed to rename session:",ne),ht("Failed to rename session","error")}finally{sn(!1),$t.current=!1}}},Qe=ne=>{ne.key==="Enter"?(ne.preventDefault(),Ve()):ne.key==="Escape"&&(ne.preventDefault(),st())},He=async()=>{const ne=!dt;try{await ze.updateSessionMetadata(t,{archived:ne}),Ue(ne),ht(ne?"Session archived":"Session unarchived","success")}catch(Le){console.error("Failed to update archive status:",Le),ht("Failed to update archive status","error")}},le=async()=>{const ne=!Xe;try{await ze.updateSessionMetadata(t,{starred:ne}),cn(ne),ht(ne?"Session starred":"Session unstarred","success")}catch(Le){console.error("Failed to update star status:",Le),ht("Failed to update star status","error")}},ce=yn??(k==null?void 0:k.hasUnread)??!1,Ee=async()=>{const ne=!ce;ke(ne);try{ne?await ze.markSessionUnread(t):await ze.markSessionSeen(t),ht(ne?"Marked as unread":"Marked as read","success")}catch(Le){console.error("Failed to update read status:",Le),ke(void 0),ht("Failed to update read status","error")}},je=async()=>{if($.owner==="self"&&$.processId)try{await ze.abortProcess($.processId),ht("Session terminated","success")}catch(ne){console.error("Failed to terminate session:",ne);const Le=ne instanceof Error?ne.message:"Unknown error";ht(`Failed to terminate: ${Le}`,"error")}};if(be)return a.jsxs("div",{className:"error",children:["Error: ",be.message]});const xe=()=>a.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:[a.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),a.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]});return a.jsx("div",{className:i?"main-content-wrapper":"main-content-mobile",children:a.jsxs("div",{className:i?"main-content-constrained":"main-content-mobile-inner",children:[a.jsx("header",{className:"session-header",children:a.jsxs("div",{className:"session-header-inner",children:[a.jsxs("div",{className:"session-header-left",children:[!(i&&u)&&a.jsx("button",{type:"button",className:"sidebar-toggle",onClick:i?l:r,title:i?"Toggle sidebar":"Open sidebar","aria-label":i?"Toggle sidebar":"Open sidebar",children:a.jsx(xe,{})}),(f==null?void 0:f.name)&&a.jsx(Gs,{to:`${d}/sessions?project=${e}`,className:"project-breadcrumb",title:f.name,children:f.name.length>12?`${f.name.slice(0,12)}...`:f.name}),a.jsxs("div",{className:"session-title-row",children:[Xe&&a.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":"Starred",children:[a.jsx("title",{children:"Starred"}),a.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"})]}),te?a.jsx("span",{className:"session-title-skeleton"}):hn?a.jsx("input",{ref:ln,type:"text",className:"session-title-input",value:mn,onChange:ne=>ss(ne.target.value),onKeyDown:Qe,onBlur:Pe,disabled:yt}):a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:cs,type:"button",className:"session-title session-title-dropdown-trigger",onClick:()=>Yt(!Qt),title:(k==null?void 0:k.fullTitle)??lt,children:[a.jsx("span",{className:"session-title-text",children:lt}),a.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:a.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),a.jsx(H5,{currentSessionId:t,isOpen:Qt,onClose:()=>Yt(!1),onNavigate:()=>Yt(!1),triggerRef:cs,basePath:d})]}),!te&&dt&&a.jsx("span",{className:"archived-badge",children:"Archived"}),!te&&a.jsx(Bb,{sessionId:t,projectId:e,isStarred:Xe,isArchived:dt,hasUnread:ce,provider:k==null?void 0:k.provider,processId:$.owner==="self"?$.processId:void 0,onToggleStar:le,onToggleArchive:He,onToggleRead:Ee,onRename:We,onClone:ne=>{p(`${d}/projects/${e}/sessions/${ne}`)},onTerminate:je,useFixedPositioning:!0,useEllipsisIcon:!0})]})]}),a.jsx("div",{className:"session-header-right",children:!te&&ve&&a.jsx("button",{type:"button",className:"provider-badge-button",onClick:()=>N(!0),title:"View session info",children:a.jsx(L5,{provider:ve,model:_t,isThinking:H==="in-turn"})})})]})}),Gn&&k&&a.jsx(M5,{sessionId:de,provider:k.provider,model:k.model,status:$,processState:H,contextUsage:k.contextUsage,originator:k.originator,cliVersion:k.cliVersion,sessionSource:k.source,approvalPolicy:k.approvalPolicy,sandboxPolicy:k.sandboxPolicy,sessionStreamConnected:Ce,lastSessionEventAt:D,onClose:()=>N(!1)}),$.owner==="external"&&a.jsx("div",{className:"external-session-warning",children:"External session active - enter messages at your own risk!"}),vt&&a.jsx("div",{className:"external-session-warning pending-tool-warning",children:"This session may be waiting for input in another process (VS Code, CLI). Check there before sending a message."}),a.jsx("main",{className:"session-messages",children:te?a.jsx("div",{className:"loading",children:"Loading session..."}):a.jsx(HR,{projectId:e,projectPath:(f==null?void 0:f.path)??null,sessionId:t,children:a.jsx(_A,{agentContent:L,setAgentContent:P,toolUseToAgent:U,projectId:e,sessionId:t,children:a.jsx(C5,{messages:O,isProcessing:$.owner==="self"&&H==="in-turn",isCompacting:F,scrollTrigger:Me,pendingMessages:se,deferredMessages:Ne,onCancelDeferred:ne=>ze.cancelDeferredMessage(t,ne),markdownAugments:A,activeToolApproval:gt})})})}),a.jsxs("footer",{className:"session-input",children:[a.jsx("div",{className:`session-connection-bar session-connection-${jt}`}),a.jsxs("div",{className:"session-input-inner",children:[ee&&ee.sessionId===de&&ct&&a.jsx(B5,{request:ee,sessionId:de,onSubmit:Fe,onDeny:Oe}),ee&&ee.sessionId===de&&!ct&&a.jsxs(a.Fragment,{children:[a.jsx(Z5,{request:ee,sessionId:de,onApprove:K,onDeny:Oe,onApproveAcceptEdits:he,onDenyWithFeedback:Je,collapsed:Bs,onCollapsedChange:un}),a.jsx(Zb,{mode:Y,onModeChange:ge,isHeld:Ke?B:void 0,onHoldChange:Ke?De:void 0,supportsPermissionMode:Re,supportsThinkingToggle:nt,contextUsage:k==null?void 0:k.contextUsage,isRunning:$.owner==="self",isThinking:H==="in-turn",onStop:W,pendingApproval:Bs?{type:"tool-approval",onExpand:()=>un(!1)}:void 0})]}),!(ee&&ee.sessionId===de&&!ct)&&a.jsx(U4,{onSend:b,onQueue:$.owner!=="none"&&H!=="idle"?z:void 0,placeholder:$.owner==="external"?"External session - send at your own risk...":H==="idle"?"Send a message to resume...":"Queue a message...",mode:Y,onModeChange:ge,isHeld:Ke?B:void 0,onHoldChange:Ke?De:void 0,supportsPermissionMode:Re,supportsThinkingToggle:nt,isRunning:$.owner==="self",isThinking:H==="in-turn",onStop:W,draftKey:`draft-message-${t}`,onDraftControlsReady:gn,collapsed:!!(ee&&ee.sessionId===de),contextUsage:k==null?void 0:k.contextUsage,projectId:e,sessionId:t,attachments:Dt,onAttach:zt,onRemoveAttachment:Ye,uploadProgress:Bn,slashCommands:xt&&$.owner==="self"?Dn:[]})]})]}),Ft.isOpen&&a.jsx(Fb,{authMethod:Ft.authMethod,onSelectMethod:Ft.selectMethod,url:Ft.url,statusMessage:Ft.statusMessage,startupError:Ft.error,onSuccess:Ft.handleSuccess,onCancel:Ft.handleCancel})]})})}let Ca=null;function u8(){const[e,t]=h.useState(!1),[r,i]=h.useState(!1);h.useEffect(()=>{if(window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0){i(!0);return}Ca&&t(!0);const d=p=>{p.preventDefault(),Ca=p,t(!0)},f=()=>{i(!0),t(!1),Ca=null};return window.addEventListener("beforeinstallprompt",d),window.addEventListener("appinstalled",f),()=>{window.removeEventListener("beforeinstallprompt",d),window.removeEventListener("appinstalled",f)}},[]);const l=h.useCallback(async()=>{if(!Ca)return!1;await Ca.prompt();const{outcome:u}=await Ca.userChoice;return u==="accepted"?(t(!1),Ca=null,!0):!1},[]);return{canInstall:e,isInstalled:r,install:l}}function d8(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),d=h.useRef(!1),f=h.useCallback(async()=>{i(!0),u(null);try{const p=await ze.getVersion();t(p)}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{i(!1)}},[]);return h.useEffect(()=>{d.current||(d.current=!0,f())},[f]),{version:e,loading:r,error:l,refetch:f}}function f8(){const{canInstall:e,isInstalled:t,install:r}=u8(),{version:i}=d8(),{resetOnboarding:l}=Tb(),{remoteLogCollectionEnabled:u,setRemoteLogCollectionEnabled:d}=zi(),[f,p]=h.useState(!1),[x,v]=h.useState(0);h.useEffect(()=>{Be("/status/workers").then(S=>v(S.activeWorkers)).catch(()=>{})},[]),h.useEffect(()=>{if(f)return fn.on("reconnect",()=>{p(!1)})},[f]);const y=h.useCallback(async()=>{p(!0);try{await ze.restartServer()}catch{}},[]);return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"About"}),a.jsxs("div",{className:"settings-group",children:[(e||t)&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Install App"}),a.jsx("p",{children:t?"Yep Anywhere is installed on your device.":"Add Yep Anywhere to your home screen for quick access."})]}),t?a.jsx("span",{className:"settings-status-badge",children:"Installed"}):a.jsx("button",{type:"button",className:"settings-button",onClick:r,children:"Install"})]}),a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Version"}),a.jsxs("p",{children:["Server:"," ",i?a.jsxs(a.Fragment,{children:["v",i.current,i.updateAvailable&&i.latest?a.jsxs("span",{className:"settings-update-available",children:[" ","(v",i.latest," available)"]}):i.latest?a.jsx("span",{className:"settings-up-to-date",children:" (up to date)"}):null]}):"Loading..."]}),a.jsxs("p",{children:["Client: v","0.3.1"]}),(i==null?void 0:i.updateAvailable)&&a.jsxs("p",{className:"settings-update-hint",children:["Run ",a.jsx("code",{children:"npm i -g yepanywhere"})," to update"]})]})}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Restart Server"}),a.jsx("p",{children:"Restart the backend server process."}),x>0&&!f&&a.jsxs("p",{className:"settings-warning",children:[x," active session",x!==1?"s":""," will be interrupted"]})]}),a.jsx("button",{type:"button",className:`settings-button ${x>0?"settings-button-danger":""}`,onClick:y,disabled:f,children:f?"Restarting...":x>0?"Restart Anyway":"Restart Server"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Report a Bug"}),a.jsx("p",{children:"Found an issue? Report it on GitHub to help improve Yep Anywhere."})]}),a.jsx("a",{href:"https://github.com/kzahel/yepanywhere/issues",target:"_blank",rel:"noopener noreferrer",className:"settings-button",children:"Report Bug"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Setup Wizard"}),a.jsx("p",{children:"Run the initial setup wizard again to configure theme and remote access."})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:l,children:"Launch Wizard"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Connection Diagnostics"}),a.jsx("p",{children:"Capture connection logs and send to server for debugging."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:u,onChange:S=>d(S.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]})]})}function h8(){const{fontSize:e,setFontSize:t}=u3(),{theme:r,setTheme:i}=jb(),{streamingEnabled:l,setStreamingEnabled:u}=t8(),{funPhrasesEnabled:d,setFunPhrasesEnabled:f}=Y4(),{showConnectionBars:p,setShowConnectionBars:x}=zi();return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Appearance"}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Theme"}),a.jsx("p",{children:"Choose your preferred color scheme."})]}),a.jsx("div",{className:"font-size-selector",children:hh.map(v=>a.jsx("button",{type:"button",className:`font-size-option ${r===v?"active":""}`,onClick:()=>i(v),children:bb(v)},v))})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Font Size"}),a.jsx("p",{children:"Adjust the text size throughout the application."})]}),a.jsx("div",{className:"font-size-selector",children:Mb.map(v=>a.jsx("button",{type:"button",className:`font-size-option ${e===v?"active":""}`,onClick:()=>t(v),children:l3(v)},v))})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Response Streaming"}),a.jsx("p",{children:"Show responses as they are generated, token by token. Disable for better performance on slower devices."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:v=>u(v.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Fun Phrases"}),a.jsx("p",{children:'Show playful status messages while waiting for responses. Disable to show only "Thinking..."'})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:d,onChange:v=>f(v.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Connection Bars"}),a.jsx("p",{children:"Show colored status bars for relay and session connections (green/orange/red)."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:p,onChange:v=>x(v.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]})]})}function py(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),d=h.useCallback(async()=>{try{i(!0),u(null);const p=await ze.getServerSettings();t(p.settings)}catch(p){console.error("[useServerSettings] Failed to fetch settings:",p),u(p instanceof Error?p.message:"Failed to load settings")}finally{i(!1)}},[]);h.useEffect(()=>{d()},[d]);const f=h.useCallback(async(p,x)=>{try{u(null);const v=await ze.updateServerSettings({[p]:x});t(v.settings)}catch(v){throw console.error("[useServerSettings] Failed to update setting:",v),u(v instanceof Error?v.message:"Failed to update setting"),v}},[]);return{settings:e,isLoading:r,error:l,updateSetting:f,refetch:d}}function m8(){const{isManualReloadMode:e,pendingReloads:t,connected:r,reloadBackend:i,unsafeToRestart:l,workerActivity:u}=xh(),{settings:d,setEnabled:f}=_b(),{holdModeEnabled:p,setHoldModeEnabled:x}=zi(),{ignoredTools:v,clearIgnoredTools:y}=Vn(),{settings:S,updateSetting:w}=py(),[E,_]=h.useState(!1);h.useEffect(()=>{E&&r&&_(!1)},[E,r]);const C=async()=>{_(!0),await i()};return e?a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Development"}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Schema Validation"}),a.jsx("p",{children:"Validate tool results against expected schemas. Shows toast notifications and logs errors to console."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:d.enabled,onChange:k=>f(k.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),v.length>0&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Ignored Tools"}),a.jsx("p",{children:"Tools with validation errors you chose to ignore. They will not show toast notifications."}),a.jsx("div",{className:"ignored-tools-list",children:v.map(k=>a.jsx("span",{className:"ignored-tool-badge",children:k},k))})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-secondary",onClick:y,children:"Clear Ignored"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Hold Mode"}),a.jsx("p",{children:"Show hold/resume option in the mode selector. Pauses execution at the next yield point (experimental)."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:p,onChange:k=>x(k.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Service Worker"}),a.jsx("p",{children:"Enable service worker for push notifications. Disabling can help with page reload issues during development. Requires restart."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(S==null?void 0:S.serviceWorkerEnabled)??!0,onChange:k=>w("serviceWorkerEnabled",k.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]}),a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Restart Server"}),a.jsxs("p",{children:["Restart the backend server to pick up code changes.",t.backend&&a.jsx("span",{className:"settings-pending",children:" (changes pending)"})]}),l&&a.jsxs("p",{className:"settings-warning",children:[u.activeWorkers," active session",u.activeWorkers!==1?"s":""," will be interrupted"]})]}),a.jsx("button",{type:"button",className:`settings-button ${l?"settings-button-danger":""}`,onClick:C,disabled:E,children:E?"Restarting...":l?"Restart Anyway":"Restart Server"})]})})]}):null}function p8(){const[e,t]=h.useState({profiles:[],isLoading:!0,error:null}),r=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{profiles:l}=await ze.getBrowserProfiles();t({profiles:l,isLoading:!1,error:null})}catch(l){console.error("[useBrowserProfiles] Failed to fetch:",l),t(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to load profiles"}))}},[]);h.useEffect(()=>{r()},[r]);const i=h.useCallback(async l=>{t(u=>({...u,isLoading:!0,error:null}));try{await ze.deleteBrowserProfile(l),await r()}catch(u){console.error("[useBrowserProfiles] Failed to delete:",u),t(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to delete profile"}))}},[r]);return{...e,deleteProfile:i,refetch:r}}function gy(){const[e,t]=h.useState({connections:new Map,isLoading:!0,error:null}),r=h.useCallback(async()=>{t(i=>({...i,isLoading:!0,error:null}));try{const{connections:i}=await ze.getConnections(),l=new Map;for(const u of i)l.set(u.browserProfileId,u);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(()=>{r()},[r]),h.useEffect(()=>{const i=fn.on("browser-tab-connected",f=>{t(p=>{var v;const x=new Map(p.connections);return x.set(f.browserProfileId,{browserProfileId:f.browserProfileId,connectionCount:f.tabCount,connectedAt:f.timestamp,deviceName:(v=p.connections.get(f.browserProfileId))==null?void 0:v.deviceName}),{...p,connections:x}})}),l=fn.on("browser-tab-disconnected",f=>{t(p=>{const x=new Map(p.connections);if(f.tabCount===0)x.delete(f.browserProfileId);else{const v=x.get(f.browserProfileId);v&&x.set(f.browserProfileId,{...v,connectionCount:f.tabCount})}return{...p,connections:x}})}),u=fn.on("reconnect",()=>{r()}),d=fn.on("refresh",()=>{r()});return()=>{i(),l(),u(),d()}},[r]),{...e,connectionList:Array.from(e.connections.values()),refetch:r}}const g8="/sw.js";function wh(){const[e,t]=h.useState({isSupported:!1,isSubscribed:!1,isLoading:!0,error:null,permission:"default",browserProfileId:null}),[r,i]=h.useState(null),l=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;h.useEffect(()=>{(async()=>{if(!l){const y=ia("browserProfileId",xs.browserProfileId);t(S=>({...S,isSupported:!1,isLoading:!1,error:"Push notifications not supported in this browser",browserProfileId:y}));return}try{const y=await navigator.serviceWorker.register(g8);i(y),await navigator.serviceWorker.ready;const S=await y.pushManager.getSubscription(),w=Oo();t({isSupported:!0,isSubscribed:!!S,isLoading:!1,error:null,permission:Notification.permission,browserProfileId:w})}catch(y){console.error("[usePushNotifications] Init error:",y),t(S=>({...S,isSupported:!0,isLoading:!1,error:y instanceof Error?y.message:"Failed to initialize"}))}})()},[l]);const u=h.useCallback(async()=>{if(!r){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await Notification.requestPermission();if(t(C=>({...C,permission:v})),v!=="granted"){t(C=>({...C,isLoading:!1,error:"Notification permission denied"}));return}const{publicKey:y}=await ze.getPushPublicKey(),S=x8(y),w=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:S.buffer}),E=Oo(),_=w.toJSON();await ze.subscribePush(E,_,v8()),t(C=>({...C,isSubscribed:!0,isLoading:!1,error:null,browserProfileId:E}))}catch(v){console.error("[usePushNotifications] Subscribe error:",v),t(y=>({...y,isLoading:!1,error:v instanceof Error?v.message:"Failed to subscribe"}))}},[r]),d=h.useCallback(async()=>{if(!r){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await r.pushManager.getSubscription();v&&await v.unsubscribe();const y=Oo();await ze.unsubscribePush(y),t(S=>({...S,isSubscribed:!1,isLoading:!1,error:null}))}catch(v){console.error("[usePushNotifications] Unsubscribe error:",v),t(y=>({...y,isLoading:!1,error:v instanceof Error?v.message:"Failed to unsubscribe"}))}},[r]),f=h.useCallback(async(v="normal")=>{const y=Oo();t(S=>({...S,isLoading:!0,error:null}));try{await ze.testPush(y,void 0,v),t(S=>({...S,isLoading:!1}))}catch(S){console.error("[usePushNotifications] Test push error:",S),t(w=>({...w,isLoading:!1,error:S instanceof Error?S.message:"Failed to send test"}))}},[]),p=h.useCallback(async()=>{var y;const v=(y=navigator.serviceWorker)==null?void 0:y.controller;return v?new Promise(S=>{const w=new MessageChannel;w.port1.onmessage=E=>{var _;S(((_=E.data)==null?void 0:_.logs)||[])},v.postMessage({type:"get-sw-logs"},[w.port2]),setTimeout(()=>S([]),2e3)}):(console.warn("[usePushNotifications] No active service worker"),[])},[]),x=h.useCallback(async()=>{var y;const v=(y=navigator.serviceWorker)==null?void 0:y.controller;if(v)return new Promise(S=>{const w=new MessageChannel;w.port1.onmessage=()=>S(),v.postMessage({type:"clear-sw-logs"},[w.port2]),setTimeout(S,1e3)})},[]);return{...e,subscribe:u,unsubscribe:d,sendTest:f,getSwLogs:p,clearSwLogs:x}}function x8(e){const t="=".repeat((4-e.length%4)%4),r=(e+t).replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(r),l=new Uint8Array(i.length);for(let u=0;u<i.length;++u)l[u]=i.charCodeAt(u);return l}function v8(){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 Jv(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/(1e3*60)),u=Math.floor(i/(1e3*60*60)),d=Math.floor(i/(1e3*60*60*24));return l<1?"just now":l<60?`${l} minute${l===1?"":"s"} ago`:u<24?`${u} hour${u===1?"":"s"} ago`:d===1?"yesterday":d<7?`${d} days ago`:t.toLocaleDateString()}function b8(){const{profiles:e,isLoading:t,error:r,deleteProfile:i}=p8(),{browserProfileId:l}=wh(),{connections:u}=gy();return a.jsx(a.Fragment,{children:a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Browser Profiles"}),a.jsx("p",{className:"settings-section-description",children:"Devices that have connected to this server, with their access origins. Each browser profile may connect from multiple URLs (localhost, Tailscale, etc.)."}),r&&a.jsx("p",{className:"form-error",children:r}),a.jsx("div",{className:"settings-group",children:t?a.jsx("p",{className:"settings-hint",children:"Loading profiles..."}):e.length===0?a.jsx("p",{className:"settings-hint",children:"No browser profiles recorded yet. Connect from a browser to see profiles here."}):a.jsx("div",{className:"device-list",children:e.map(d=>{const f=d.browserProfileId===l,p=u.has(d.browserProfileId),x=d.deviceName||`${d.browserProfileId.slice(0,8)}...`;return a.jsxs("div",{className:"device-list-item device-profile-item",children:[a.jsxs("div",{className:"device-list-info",children:[a.jsxs("strong",{children:[a.jsx("span",{className:`device-status ${p?"device-status-online":"device-status-offline"}`,title:p?"Connected":"Disconnected"}),x,f&&a.jsx("span",{className:"device-current-badge",children:"This device"})]}),a.jsx("div",{className:"device-origins",children:d.origins.map(v=>{const{browser:y,os:S}=vb(v.userAgent);return a.jsxs("div",{className:"device-origin",children:[a.jsx("code",{className:"device-origin-url",children:v.origin}),a.jsxs("span",{className:"device-origin-details",children:[y," · ",S]}),a.jsxs("span",{className:"device-origin-time",children:["Last seen ",Jv(v.lastSeen)]})]},v.origin)})}),a.jsxs("p",{className:"device-profile-meta",children:["First seen ",Jv(d.createdAt)]})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>i(d.browserProfileId),title:"Forget this device",children:"Forget"})]},d.browserProfileId)})})})]})})}function y8(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),[d,f]=h.useState(!1),p=h.useRef(!1),x=h.useCallback(async()=>{i(!0),u(null);try{const S=await ze.getNetworkBinding();t(S)}catch(S){u(S instanceof Error?S:new Error(String(S)))}finally{i(!1)}},[]);h.useEffect(()=>{p.current||(p.current=!0,x())},[x]);const v=h.useCallback(async S=>{f(!0),u(null);try{const w=await ze.setNetworkBinding(S);if(!w.success)throw new Error(w.error??"Failed to update binding");return await x(),{redirectUrl:w.redirectUrl}}catch(w){const E=w instanceof Error?w:new Error(String(w));throw u(E),E}finally{f(!1)}},[x]),y=h.useCallback(async()=>{f(!0),u(null);try{const S=await ze.disableNetworkBinding();if(!S.success)throw new Error(S.error??"Failed to disable network socket");await x()}catch(S){const w=S instanceof Error?S:new Error(String(S));throw u(w),w}finally{f(!1)}},[x]);return{binding:e,loading:r,error:l,applying:d,updateBinding:v,disableNetwork:y,refetch:x}}function S8(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),d=h.useRef(!1),f=h.useCallback(async()=>{i(!0),u(null);try{const p=await ze.getServerInfo();t(p)}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{i(!1)}},[]);return h.useEffect(()=>{d.current||(d.current=!0,f())},[f]),{serverInfo:e,loading:r,error:l,refetch:f}}function j8(){const e=zT(),t=Bc(),{relayDebugEnabled:r,setRelayDebugEnabled:i}=zi(),{serverInfo:l,loading:u}=S8(),{binding:d,loading:f,applying:p,updateBinding:x}=y8(),{settings:v,isLoading:y}=py(),[S,w]=h.useState(""),[E,_]=h.useState(!1),[C,k]=h.useState(""),[O,L]=h.useState(""),[P,U]=h.useState(!1),[A,$]=h.useState(""),[H,F]=h.useState(""),[ee,de]=h.useState(!1),[Y,te]=h.useState(""),[be,Ce]=h.useState(null),[D,Z]=h.useState(!1),[V,ge]=h.useState(!1),[De,B]=h.useState(!1);if(d&&e&&v&&!De){w(String(d.localhost.port)),_(d.network.enabled),k(d.network.host??""),U(e.authEnabled);const Ae=v.allowedHosts;Ae==="*"?(de(!0),te("")):(de(!1),te(Ae??"")),B(!0)}const se=(Ae,Ke)=>Ae?"*":Ke.trim()||void 0,me=(Ae,Ke,$e,fe,Ze,jt,ve)=>{if(!d||!e||!v)return!1;const _t=Ae!==String(d.localhost.port),Me=Ke!==d.network.enabled,at=$e!==(d.network.host??""),Ht=fe!==e.authEnabled,gn=Ze.length>0,ht=se(jt,ve),Ft=v.allowedHosts;return _t||Me||at||Ht||gn||(ht??"")!==(Ft??"")},ie=Ae=>{Z(me(Ae.port??S,Ae.networkEnabled??E,Ae.iface??C,Ae.requirePw??P,Ae.password??A,Ae.allowAll??ee,Ae.hostsText??Y))},Ne=async()=>{if(!e)return;Ce(null);const Ae=Number.parseInt(S,10);if(Number.isNaN(Ae)||Ae<1||Ae>65535){Ce("Port must be a number between 1 and 65535");return}const Ke=P&&!e.authEnabled,$e=P&&e.authEnabled&&A.length>0;if(Ke||$e){if(A.length<6){Ce("Password must be at least 6 characters");return}if(A!==H){Ce("Passwords do not match");return}}const fe=C==="custom"?O:C;ge(!0);try{const Ze=await x({localhostPort:Ae,network:{enabled:E,host:E?fe:void 0}});Ke?(await e.enableAuth(A),$(""),F("")):$e?(await e.changePassword(A),$(""),F("")):!P&&e.authEnabled&&await e.disableAuth();const jt=se(ee,Y);if(await ze.updateServerSettings({allowedHosts:jt??""}),Ze.redirectUrl){const ve=new URL(Ze.redirectUrl);ve.pathname=window.location.pathname,ve.search=window.location.search,window.location.href=ve.toString()}else Z(!1)}catch(Ze){Ce(Ze instanceof Error?Ze.message:"Failed to apply changes")}finally{ge(!1)}};if(e){if(u||f||y||e.isLoading||!De)return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Local Access"}),a.jsx("p",{className:"settings-section-description",children:"Loading..."})]});const Ke=P;return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Local Access"}),a.jsx("p",{className:"settings-section-description",children:"Control how this server is accessed on your local network."}),a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Status"}),a.jsx("p",{children:l?(()=>{const $e=d==null?void 0:d.network.host,fe=(d==null?void 0:d.network.port)??l.port,Ze=$e==="0.0.0.0"||$e==="::",jt=fe===l.port;return d!=null&&d.network.enabled&&Ze&&jt?a.jsxs(a.Fragment,{children:["Listening on"," ",a.jsxs("code",{children:[$e,":",fe]})]}):a.jsxs(a.Fragment,{children:["Listening on"," ",a.jsxs("code",{children:[l.host,":",l.port]}),(d==null?void 0:d.network.enabled)&&$e&&a.jsxs(a.Fragment,{children:[" ","and"," ",a.jsxs("code",{children:[$e,":",fe]})]})]})})():"Unable to fetch server info"})]}),(l==null?void 0:l.localhostOnly)&&!(d!=null&&d.network.enabled)&&a.jsx("span",{className:"settings-status-badge settings-status-detected",children:"Local Only"}),((l==null?void 0:l.boundToAllInterfaces)||(d==null?void 0:d.network.enabled))&&!e.authEnabled&&a.jsx("span",{className:"settings-status-badge settings-status-warning",children:"Network Exposed"})]})}),a.jsxs("form",{className:"settings-group",onSubmit:$e=>{$e.preventDefault(),Ne()},children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Listening Port"}),a.jsx("p",{children:"Port used for all network access"})]}),d!=null&&d.localhost.overriddenByCli?a.jsxs("span",{className:"settings-value-readonly",children:[d.localhost.port," ",a.jsx("span",{className:"settings-hint",children:"(set via --port)"})]}):a.jsx("input",{type:"number",className:"settings-input-small",value:S,onChange:$e=>{w($e.target.value),ie({port:$e.target.value})},min:1,max:65535,autoComplete:"off"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Local Network Access"}),a.jsx("p",{children:"Allow access from other devices on your network"})]}),d!=null&&d.network.overriddenByCli?a.jsxs("span",{className:"settings-value-readonly",children:[d.network.host,":",d.network.port," ",a.jsx("span",{className:"settings-hint",children:"(set via --host)"})]}):a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:E,onChange:$e=>{_($e.target.checked),ie({networkEnabled:$e.target.checked})}}),a.jsx("span",{className:"toggle-slider"})]})]}),E&&!(d!=null&&d.network.overriddenByCli)&&d&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Interface"}),a.jsx("p",{children:"Select which network interface to bind to"})]}),a.jsx(Ra,{label:"Interface",placeholder:"Select interface...",multiSelect:!1,align:"right",options:[...d.interfaces.map($e=>({value:$e.address,label:$e.displayName})),{value:"0.0.0.0",label:"All interfaces (0.0.0.0)"},{value:"custom",label:"Custom IP..."}],selected:C?[C]:[],onChange:$e=>{const fe=$e[0]??"";k(fe),ie({iface:fe})}})]}),E&&!(d!=null&&d.network.overriddenByCli)&&C==="custom"&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Custom IP"}),a.jsx("p",{children:"Enter the IP address to bind to"})]}),a.jsx("input",{type:"text",className:"settings-input",placeholder:"192.168.1.100",value:O,onChange:$e=>L($e.target.value)})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Allow All Hostnames"}),a.jsx("p",{children:"Accept requests from any hostname (disables DNS rebinding protection)"})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:ee,onChange:$e=>{de($e.target.checked),ie({allowAll:$e.target.checked})}}),a.jsx("span",{className:"toggle-slider"})]})]}),!ee&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Allowed Hostnames"}),a.jsx("p",{children:"Comma-separated list of additional allowed hostnames"})]}),a.jsx("input",{type:"text",className:"settings-input",placeholder:"mydomain.com, other.example.com",value:Y,onChange:$e=>{te($e.target.value),ie({hostsText:$e.target.value})}})]}),a.jsx("p",{className:"form-hint",children:"localhost, private IPs, and *.ts.net are always allowed."}),!e.authDisabledByEnv&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Require Password"}),a.jsx("p",{children:"Require a password to access this server"})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:P,onChange:$e=>{U($e.target.checked),ie({requirePw:$e.target.checked})}}),a.jsx("span",{className:"toggle-slider"})]})]}),Ke&&a.jsxs(a.Fragment,{children:[a.jsx("input",{type:"text",name:"username",autoComplete:"username",style:{position:"absolute",visibility:"hidden",pointerEvents:"none"},tabIndex:-1}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Password"}),a.jsx("p",{children:e.authEnabled?"Leave blank to keep current":"At least 6 characters"})]}),a.jsx("input",{type:"password",className:"settings-input",value:A,onChange:$e=>{$($e.target.value),ie({password:$e.target.value})},autoComplete:"new-password",placeholder:e.authEnabled?"New password":"Enter password"})]}),A.length>0&&a.jsxs("div",{className:"settings-item",children:[a.jsx("div",{className:"settings-item-info",children:a.jsx("strong",{children:"Confirm Password"})}),a.jsx("input",{type:"password",className:"settings-input",value:H,onChange:$e=>F($e.target.value),autoComplete:"new-password",placeholder:"Confirm password"})]}),!e.authEnabled&&a.jsxs("p",{className:"form-hint",children:["If you forget your password, restart with"," ",a.jsx("code",{children:"--auth-disable"})," to bypass auth."]})]}),e.authDisabledByEnv&&a.jsx("p",{className:"form-warning",children:"Authentication is bypassed by --auth-disable flag."}),a.jsxs("div",{className:"settings-item",children:[be&&a.jsx("p",{className:"form-error",children:be}),a.jsx("button",{type:"submit",className:"settings-button",disabled:!D||V||p,children:V||p?"Applying...":"Apply Changes"})]})]}),e.authEnabled&&e.isAuthenticated&&a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Logout"}),a.jsx("p",{children:"Sign out on this device"})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:e.logout,children:"Logout"})]})})]})}return t?a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Local Access"}),a.jsx("p",{className:"settings-section-description",children:"You are connected to a remote server via relay."}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Logout"}),a.jsx("p",{children:"Disconnect from the remote server."})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>t.disconnect(),children:"Logout"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Relay Debug Logging"}),a.jsx("p",{children:"Log relay requests and responses to the browser console. Useful for debugging connection timeouts."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:r,onChange:Ae=>i(Ae.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]})]}):null}function w8(){const{model:e,setModel:t,thinkingLevel:r,setThinkingLevel:i}=Ic();return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Model"}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Model"}),a.jsx("p",{children:"Select which Claude model to use for new sessions."})]}),a.jsx("div",{className:"font-size-selector",children:Uf.map(l=>a.jsx("button",{type:"button",className:`font-size-option ${e===l.value?"active":""}`,onClick:()=>t(l.value),children:l.label},l.value))})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Thinking Level"}),a.jsx("p",{children:"Token budget for extended thinking. Higher levels enable deeper reasoning but use more tokens."})]}),a.jsx("div",{className:"font-size-selector",children:hT.map(l=>a.jsxs("button",{type:"button",className:`font-size-option ${r===l.value?"active":""}`,onClick:()=>i(l.value),title:l.description,children:[l.label," (",l.description,")"]},l.value))})]})]})]})}function xy(){const[e,t]=h.useState(()=>{const l=typeof window<"u"&&"Notification"in window,u=yT();return{isSupported:l&&!u,isMobile:u,permission:l?Notification.permission:"denied",isRequesting:!1}});h.useEffect(()=>{if(!e.isSupported)return;const l=()=>{const u=Notification.permission;u!==e.permission&&t(d=>({...d,permission:u}))};return window.addEventListener("focus",l),()=>window.removeEventListener("focus",l)},[e.isSupported,e.permission]);const r=h.useCallback(async()=>{if(e.isSupported&&e.permission!=="granted"){t(l=>({...l,isRequesting:!0}));try{const l=await Notification.requestPermission();t(u=>({...u,permission:l,isRequesting:!1}))}catch(l){console.error("[useBrowserNotifications] Permission request failed:",l),t(u=>({...u,isRequesting:!1}))}}},[e.isSupported,e.permission]),i=h.useCallback((l,u)=>{if(!e.isSupported||e.permission!=="granted")return!1;try{return new Notification(l,u),!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:r,showNotification:i}}function N8(){const{isSupported:e,isMobile:t,isEnabled:r,isDenied:i,isRequesting:l,requestPermission:u,showNotification:d}=xy();if(t)return null;if(!e)return a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{children:"Notifications are not supported in this browser."})]})});if(i)return a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{className:"settings-warning",children:"Notifications are blocked. Enable them in your browser settings to receive desktop alerts."})]})});if(r){const f=()=>{d("Test Notification",{body:"Desktop notifications are working!",icon:"/icon-192.png"})};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{children:"Enabled. You'll receive notifications when sessions need attention (while the tab is open)."})]}),a.jsx("span",{className:"settings-badge settings-badge-success",children:"Enabled"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Test Desktop Notification"}),a.jsx("p",{children:"Send a test notification to verify it's working."})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:f,children:"Send Test"})]})]})}return a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{children:"Get notified when sessions need your attention. Works while the tab is open in the background."})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:u,disabled:l,children:l?"Requesting...":"Enable"})]})}function _8(){const{isSupported:e,isSubscribed:t,isLoading:r,error:i,permission:l,subscribe:u,unsubscribe:d,sendTest:f}=wh(),{notifyInApp:p,setNotifyInApp:x}=GT(),[v,y]=h.useState("normal"),S=async()=>{t?await d():await u()};if(!e){const w=i==null?void 0:i.includes("Service worker disabled in dev mode");return a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Push Notifications"}),a.jsx("p",{children:i||"Push notifications are not supported in this browser."}),w&&a.jsxs("div",{className:"settings-info-box",style:{marginTop:"0.5rem"},children:[a.jsxs("p",{children:["This only affects ",a.jsx("strong",{children:"this device"}),". Other subscribed devices will still receive notifications from the server."]}),a.jsxs("p",{children:["To enable push on this device in dev mode, restart with"," ",a.jsx("code",{children:"VITE_ENABLE_SW=true"}),"."]})]}),a.jsx("p",{style:{marginTop:"0.5rem"},children:a.jsx("a",{href:"https://github.com/kzahel/yepanywhere/blob/main/docs/push-notifications.md",target:"_blank",rel:"noopener noreferrer",children:"Troubleshooting guide"})})]})})}return l==="denied"?a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Push Notifications"}),a.jsx("p",{className:"settings-warning",children:"Notifications are blocked. Enable them in your browser settings to receive push notifications."})]})}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Push Notifications"}),a.jsx("p",{children:"Receive notifications when a session needs your attention, even when the app is in the background."}),i&&a.jsx("p",{className:"settings-error",children:i})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:t,onChange:S,disabled:r}),a.jsx("span",{className:"toggle-slider"})]})]}),t&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Notify When In App"}),a.jsx("p",{children:"Show notifications even when the app is open, as long as you're not viewing that session."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:p,onChange:w=>x(w.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Test Notification"}),a.jsx("p",{children:"Send a test notification to verify push is working."})]}),a.jsxs("div",{className:"settings-item-actions",children:[a.jsxs("select",{className:"settings-select",value:v,onChange:w=>y(w.target.value),disabled:r,children:[a.jsx("option",{value:"normal",children:"Normal (auto-dismiss)"}),a.jsx("option",{value:"persistent",children:"Persistent (stays visible)"}),a.jsx("option",{value:"silent",children:"Silent (no sound)"})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:()=>f(v),disabled:r,children:r?"Sending...":"Send Test"})]})]})]})]})}function E8(){const[e,t]=h.useState({settings:null,isLoading:!0,error:null});h.useEffect(()=>{(async()=>{try{const{settings:l}=await ze.getNotificationSettings();t({settings:l,isLoading:!1,error:null})}catch(l){console.error("[useNotificationSettings] Failed to fetch:",l),t(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to load settings"}))}})()},[]);const r=h.useCallback(async(i,l)=>{t(u=>({...u,isLoading:!0,error:null}));try{const{settings:u}=await ze.updateNotificationSettings({[i]:l});t({settings:u,isLoading:!1,error:null})}catch(u){console.error("[useNotificationSettings] Failed to update:",u),t(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to update"}))}},[]);return{...e,updateSetting:r}}function C8(){const[e,t]=h.useState({devices:[],isLoading:!0,error:null}),r=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{subscriptions:l}=await ze.getPushSubscriptions();t({devices:l,isLoading:!1,error:null})}catch(l){console.error("[useSubscribedDevices] Failed to fetch:",l),t(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to load devices"}))}},[]);h.useEffect(()=>{r()},[r]);const i=h.useCallback(async l=>{t(u=>({...u,isLoading:!0,error:null}));try{await ze.deletePushSubscription(l),await r()}catch(u){console.error("[useSubscribedDevices] Failed to remove:",u),t(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to remove device"}))}},[r]);return{...e,removeDevice:i,refetch:r}}function k8(e,t){const r=e||"Unknown device";return t!=null&&t.includes("google")?{displayName:r,browserType:"(Android/Chrome)"}:t!=null&&t.includes("apple")||t!=null&&t.includes("push.apple")?{displayName:r,browserType:"(iOS/Safari)"}:t!=null&&t.includes("mozilla")||t!=null&&t.includes("push.services.mozilla")?{displayName:r,browserType:"(Firefox)"}:{displayName:r,browserType:""}}function T8(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/(1e3*60*60*24));return l===0?"today":l===1?"yesterday":l<7?`${l} days ago`:t.toLocaleDateString()}function R8(e,t,r){const i=new Map;for(const u of e){const{displayName:d,browserType:f}=k8(u.deviceName,u.endpointDomain),p=t.get(u.browserProfileId);i.set(u.browserProfileId,{browserProfileId:u.browserProfileId,displayName:d,browserType:f,isSubscribed:!0,isConnected:!!p,tabCount:(p==null?void 0:p.connectionCount)??0,subscribedAt:u.createdAt,isCurrentDevice:u.browserProfileId===r})}for(const[u,d]of t)if(!i.has(u)){const f=u.slice(0,8);i.set(u,{browserProfileId:u,displayName:f,browserType:"",isSubscribed:!1,isConnected:!0,tabCount:d.connectionCount,isCurrentDevice:u===r})}const l=Array.from(i.values());return l.sort((u,d)=>u.isCurrentDevice&&!d.isCurrentDevice?-1:!u.isCurrentDevice&&d.isCurrentDevice?1:u.isConnected&&!d.isConnected?-1:!u.isConnected&&d.isConnected?1:u.isConnected&&d.isConnected?d.tabCount-u.tabCount:u.subscribedAt&&d.subscribedAt?new Date(d.subscribedAt).getTime()-new Date(u.subscribedAt).getTime():0),l}function A8(){const{browserProfileId:e}=wh(),{isMobile:t}=xy(),{devices:r,isLoading:i,removeDevice:l}=C8(),{connections:u,isLoading:d}=gy(),{settings:f,isLoading:p,updateSetting:x}=E8(),v=r.length>0,y=i||d,S=R8(r,u,e);return a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Server Notification Types"}),a.jsx("p",{className:"settings-section-description",children:"Control what types of events trigger push notifications to all devices."}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Tool Approvals"}),a.jsx("p",{children:"Notify when Claude needs permission to run a tool (file edits, commands, etc.)"})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.toolApproval)??!0,onChange:w=>x("toolApproval",w.target.checked),disabled:p||!v}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"User Questions"}),a.jsx("p",{children:"Notify when Claude asks a question and needs your response."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.userQuestion)??!0,onChange:w=>x("userQuestion",w.target.checked),disabled:p||!v}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Session Halted"}),a.jsx("p",{children:"Notify when a session completes, errors out, or becomes idle."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.sessionHalted)??!0,onChange:w=>x("sessionHalted",w.target.checked),disabled:p||!v}),a.jsx("span",{className:"toggle-slider"})]})]}),!v&&!i&&a.jsx("p",{className:"settings-hint",children:"No devices subscribed. Enable push notifications below to use these settings."})]})]}),!t&&a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Desktop Notifications"}),a.jsx("p",{className:"settings-section-description",children:"Get browser notifications when sessions need attention. Works while the tab is open."}),a.jsx("div",{className:"settings-group",children:a.jsx(N8,{})})]}),a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Push Notifications"}),a.jsx("p",{className:"settings-section-description",children:"Receive push notifications even when the browser is closed or you're on another device."}),a.jsx("div",{className:"settings-group",children:a.jsx(_8,{})})]}),a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Devices"}),a.jsx("p",{className:"settings-section-description",children:"All devices connected to or subscribed to this server."}),a.jsx("div",{className:"settings-group",children:y?a.jsx("p",{className:"settings-hint",children:"Loading devices..."}):S.length===0?a.jsx("p",{className:"settings-hint",children:"No devices connected or subscribed. Enable push notifications above."}):a.jsx("div",{className:"device-list",children:S.map(w=>a.jsxs("div",{className:"device-list-item",children:[a.jsxs("div",{className:"device-list-info",children:[a.jsxs("strong",{children:[w.displayName,w.browserType&&` ${w.browserType}`,w.isCurrentDevice&&a.jsx("span",{className:"device-current-badge",children:"This device"})]}),a.jsxs("p",{children:[w.isConnected?a.jsx("span",{className:"device-status device-status-online",children:w.tabCount===1?"1 tab":`${w.tabCount} tabs`}):a.jsx("span",{className:"device-status device-status-offline",children:"Offline"}),!w.isSubscribed&&a.jsx("span",{className:"device-no-push",children:"No push"}),w.subscribedAt&&a.jsxs("span",{className:"device-subscribed-date",children:["Subscribed ",T8(w.subscribedAt)]})]})]}),w.isSubscribed&&a.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>l(w.browserProfileId),title:w.isCurrentDevice?"Unsubscribe this device":"Remove this device",children:"Remove"})]},w.browserProfileId))})})]})]})}function M8(){const{providers:e}=bh(),r=k3().map(i=>{const l=e.find(u=>u.name===i.id);return{...i,installed:(l==null?void 0:l.installed)??!1,authenticated:(l==null?void 0:l.authenticated)??!1}});return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Providers"}),a.jsx("p",{className:"settings-section-description",children:"AI providers are auto-detected when their CLI is installed."}),a.jsx("div",{className:"settings-group",children:r.map(i=>a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsxs("div",{className:"settings-item-header",children:[a.jsx("strong",{children:i.displayName}),i.installed?a.jsx("span",{className:"settings-status-badge settings-status-detected",children:"Detected"}):a.jsx("span",{className:"settings-status-badge settings-status-not-detected",children:"Not Detected"})]}),a.jsx("p",{children:i.metadata.description}),i.metadata.limitations.length>0&&a.jsx("ul",{className:"settings-limitations",children:i.metadata.limitations.map(l=>a.jsx("li",{children:l},l))})]}),i.metadata.website&&a.jsx("a",{href:i.metadata.website,target:"_blank",rel:"noopener noreferrer",className:"settings-link",children:"Website"})]},i.id))})]})}function O8(){const[e,t]=h.useState(null),[r,i]=h.useState(null),[l,u]=h.useState(null),[d,f]=h.useState([]),[p,x]=h.useState(!0),[v,y]=h.useState(null),S=h.useCallback(async()=>{try{const[U,A,$,H]=await Promise.all([Be("/remote-access/config"),Be("/remote-access/relay"),Be("/remote-access/relay/status"),Be("/remote-access/sessions")]);t(U),i(A.relay),u($),f(H.sessions),y(null)}catch(U){console.error("[useRemoteAccess] Failed to fetch config:",U),y(U instanceof Error?U.message:"Failed to fetch config")}},[]);h.useEffect(()=>{x(!0),S().finally(()=>x(!1))},[S]);const w=h.useCallback(async U=>{try{await Be("/remote-access/configure",{method:"POST",body:JSON.stringify({password:U})}),await S()}catch(A){const $=A instanceof Error?A.message:"Failed to configure remote access";throw y($),new Error($)}},[S]),E=h.useCallback(async()=>{try{await Be("/remote-access/enable",{method:"POST"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to enable remote access";throw y(A),new Error(A)}},[S]),_=h.useCallback(async()=>{try{await Be("/remote-access/disable",{method:"POST"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to disable remote access";throw y(A),new Error(A)}},[S]),C=h.useCallback(async()=>{try{await Be("/remote-access/clear",{method:"POST"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to clear remote access credentials";throw y(A),new Error(A)}},[S]),k=h.useCallback(async U=>{try{await Be("/remote-access/relay",{method:"PUT",body:JSON.stringify(U)}),await S()}catch(A){const $=A instanceof Error?A.message:"Failed to update relay configuration";throw y($),new Error($)}},[S]),O=h.useCallback(async()=>{try{await Be("/remote-access/relay",{method:"DELETE"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to clear relay configuration";throw y(A),new Error(A)}},[S]),L=h.useCallback(async U=>{try{await Be(`/remote-access/sessions/${U}`,{method:"DELETE"}),await S()}catch(A){const $=A instanceof Error?A.message:"Failed to revoke session";throw y($),new Error($)}},[S]),P=h.useCallback(async()=>{try{await Be("/remote-access/sessions",{method:"DELETE"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to revoke all sessions";throw y(A),new Error(A)}},[S]);return{config:e,relayConfig:r,relayStatus:l,sessions:d,loading:p,error:v,configure:w,enable:E,disable:_,clearCredentials:C,updateRelayConfig:k,clearRelayConfig:O,revokeSession:L,revokeAllSessions:P,refresh:S}}var ka=(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))(ka||{}),z8=Object.defineProperty,L8=(e,t,r)=>t in e?z8(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,xc=(e,t,r)=>(L8(e,typeof t!="symbol"?t+"":t,r),r);const U8=[0,1],vy=[1,0],by=[2,3],yy=[3,2],D8={L:U8,M:vy,Q:by,H:yy},B8=/^[0-9]*$/,I8=/^[A-Z0-9 $%*+.\/:-]*$/,Nf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Nh=1,_h=40,Qv=3,$8=3,vc=40,P8=10,Sy=[[-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]],jy=[[-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 H8{constructor(t,r,i,l){if(this.version=t,this.ecc=r,xc(this,"size"),xc(this,"mask"),xc(this,"modules",[]),xc(this,"types",[]),t<Nh||t>_h)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 u=Array.from({length:this.size},()=>!1);for(let f=0;f<this.size;f++)this.modules.push(u.slice()),this.types.push(u.map(()=>0));this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),l===-1){let f=1e9;for(let p=0;p<8;p++){this.applyMask(p),this.drawFormatBits(p);const x=this.getPenaltyScore();x<f&&(l=p,f=x),this.applyMask(p)}}this.mask=l,this.applyMask(l),this.drawFormatBits(l)}getModule(t,r){return t>=0&&t<this.size&&r>=0&&r<this.size&&this.modules[r][t]}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2===0,ka.Timing),this.setFunctionModule(i,6,i%2===0,ka.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const t=this.getAlignmentPatternPositions(),r=t.length;for(let i=0;i<r;i++)for(let l=0;l<r;l++)i===0&&l===0||i===0&&l===r-1||i===r-1&&l===0||this.drawAlignmentPattern(t[i],t[l]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){const r=this.ecc[1]<<3|t;let i=r;for(let u=0;u<10;u++)i=i<<1^(i>>>9)*1335;const l=(r<<10|i)^21522;for(let u=0;u<=5;u++)this.setFunctionModule(8,u,Er(l,u));this.setFunctionModule(8,7,Er(l,6)),this.setFunctionModule(8,8,Er(l,7)),this.setFunctionModule(7,8,Er(l,8));for(let u=9;u<15;u++)this.setFunctionModule(14-u,8,Er(l,u));for(let u=0;u<8;u++)this.setFunctionModule(this.size-1-u,8,Er(l,u));for(let u=8;u<15;u++)this.setFunctionModule(8,this.size-15+u,Er(l,u));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 r=this.version<<12|t;for(let i=0;i<18;i++){const l=Er(r,i),u=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(u,d,l),this.setFunctionModule(d,u,l)}}drawFinderPattern(t,r){for(let i=-4;i<=4;i++)for(let l=-4;l<=4;l++){const u=Math.max(Math.abs(l),Math.abs(i)),d=t+l,f=r+i;d>=0&&d<this.size&&f>=0&&f<this.size&&this.setFunctionModule(d,f,u!==2&&u!==4,ka.Position)}}drawAlignmentPattern(t,r){for(let i=-2;i<=2;i++)for(let l=-2;l<=2;l++)this.setFunctionModule(t+l,r+i,Math.max(Math.abs(l),Math.abs(i))!==1,ka.Alignment)}setFunctionModule(t,r,i,l=ka.Function){this.modules[r][t]=i,this.types[r][t]=l}addEccAndInterleave(t){const r=this.version,i=this.ecc;if(t.length!==jc(r,i))throw new RangeError("Invalid argument");const l=jy[i[0]][r],u=Sy[i[0]][r],d=Math.floor(Hf(r)/8),f=l-d%l,p=Math.floor(d/l),x=[],v=K8(u);for(let S=0,w=0;S<l;S++){const E=t.slice(w,w+p-u+(S<f?0:1));w+=E.length;const _=J8(E,v);S<f&&E.push(0),x.push(E.concat(_))}const y=[];for(let S=0;S<x[0].length;S++)x.forEach((w,E)=>{(S!==p-u||E>=f)&&y.push(w[S])});return y}drawCodewords(t){if(t.length!==Math.floor(Hf(this.version)/8))throw new RangeError("Invalid argument");let r=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 u=0;u<2;u++){const d=i-u,p=(i+1&2)===0?this.size-1-l:l;!this.types[p][d]&&r<t.length*8&&(this.modules[p][d]=Er(t[r>>>3],7-(r&7)),r++)}}}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let r=0;r<this.size;r++)for(let i=0;i<this.size;i++){let l;switch(t){case 0:l=(i+r)%2===0;break;case 1:l=r%2===0;break;case 2:l=i%3===0;break;case 3:l=(i+r)%3===0;break;case 4:l=(Math.floor(i/3)+Math.floor(r/2))%2===0;break;case 5:l=i*r%2+i*r%3===0;break;case 6:l=(i*r%2+i*r%3)%2===0;break;case 7:l=((i+r)%2+i*r%3)%2===0;break;default:throw new Error("Unreachable")}!this.types[r][i]&&l&&(this.modules[r][i]=!this.modules[r][i])}}getPenaltyScore(){let t=0;for(let u=0;u<this.size;u++){let d=!1,f=0;const p=[0,0,0,0,0,0,0];for(let x=0;x<this.size;x++)this.modules[u][x]===d?(f++,f===5?t+=Qv:f>5&&t++):(this.finderPenaltyAddHistory(f,p),d||(t+=this.finderPenaltyCountPatterns(p)*vc),d=this.modules[u][x],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,p)*vc}for(let u=0;u<this.size;u++){let d=!1,f=0;const p=[0,0,0,0,0,0,0];for(let x=0;x<this.size;x++)this.modules[x][u]===d?(f++,f===5?t+=Qv:f>5&&t++):(this.finderPenaltyAddHistory(f,p),d||(t+=this.finderPenaltyCountPatterns(p)*vc),d=this.modules[x][u],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,p)*vc}for(let u=0;u<this.size-1;u++)for(let d=0;d<this.size-1;d++){const f=this.modules[u][d];f===this.modules[u][d+1]&&f===this.modules[u+1][d]&&f===this.modules[u+1][d+1]&&(t+=$8)}let r=0;for(const u of this.modules)r=u.reduce((d,f)=>d+(f?1:0),r);const i=this.size*this.size,l=Math.ceil(Math.abs(r*20-i*10)/i)-1;return t+=l*P8,t}getAlignmentPatternPositions(){if(this.version===1)return[];{const t=Math.floor(this.version/7)+2,r=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-=r)i.splice(1,0,l);return i}}finderPenaltyCountPatterns(t){const r=t[1],i=r>0&&t[2]===r&&t[3]===r*3&&t[4]===r&&t[5]===r;return(i&&t[0]>=r*4&&t[6]>=r?1:0)+(i&&t[6]>=r*4&&t[0]>=r?1:0)}finderPenaltyTerminateAndCount(t,r,i){return t&&(this.finderPenaltyAddHistory(r,i),r=0),r+=this.size,this.finderPenaltyAddHistory(r,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(t,r){r[0]===0&&(t+=this.size),r.pop(),r.unshift(t)}}function kr(e,t,r){if(t<0||t>31||e>>>t)throw new RangeError("Value out of range");for(let i=t-1;i>=0;i--)r.push(e>>>i&1)}function Er(e,t){return(e>>>t&1)!==0}class Eh{constructor(t,r,i){if(this.mode=t,this.numChars=r,this.bitData=i,r<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}getData(){return this.bitData.slice()}}const F8=[1,10,12,14],q8=[2,9,11,13],Z8=[4,8,16,16];function wy(e,t){return e[Math.floor((t+7)/17)+1]}function Ny(e){const t=[];for(const r of e)kr(r,8,t);return new Eh(Z8,e.length,t)}function V8(e){if(!_y(e))throw new RangeError("String contains non-numeric characters");const t=[];for(let r=0;r<e.length;){const i=Math.min(e.length-r,3);kr(Number.parseInt(e.substring(r,r+i),10),i*3+1,t),r+=i}return new Eh(F8,e.length,t)}function G8(e){if(!Ey(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");const t=[];let r;for(r=0;r+2<=e.length;r+=2){let i=Nf.indexOf(e.charAt(r))*45;i+=Nf.indexOf(e.charAt(r+1)),kr(i,11,t)}return r<e.length&&kr(Nf.indexOf(e.charAt(r)),6,t),new Eh(q8,e.length,t)}function Y8(e){return e===""?[]:_y(e)?[V8(e)]:Ey(e)?[G8(e)]:[Ny(X8(e))]}function _y(e){return B8.test(e)}function Ey(e){return I8.test(e)}function W8(e,t){let r=0;for(const i of e){const l=wy(i.mode,t);if(i.numChars>=1<<l)return Number.POSITIVE_INFINITY;r+=4+l+i.bitData.length}return r}function X8(e){e=encodeURI(e);const t=[];for(let r=0;r<e.length;r++)e.charAt(r)!=="%"?t.push(e.charCodeAt(r)):(t.push(Number.parseInt(e.substring(r+1,r+3),16)),r+=2);return t}function Hf(e){if(e<Nh||e>_h)throw new RangeError("Version number out of range");let t=(16*e+128)*e+64;if(e>=2){const r=Math.floor(e/7)+2;t-=(25*r-10)*r-55,e>=7&&(t-=36)}return t}function jc(e,t){return Math.floor(Hf(e)/8)-Sy[t[0]][e]*jy[t[0]][e]}function K8(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 r=1;for(let i=0;i<e;i++){for(let l=0;l<t.length;l++)t[l]=Ff(t[l],r),l+1<t.length&&(t[l]^=t[l+1]);r=Ff(r,2)}return t}function J8(e,t){const r=t.map(i=>0);for(const i of e){const l=i^r.shift();r.push(0),t.forEach((u,d)=>r[d]^=Ff(u,l))}return r}function Ff(e,t){if(e>>>8||t>>>8)throw new RangeError("Byte out of range");let r=0;for(let i=7;i>=0;i--)r=r<<1^(r>>>7)*285,r^=(t>>>i&1)*e;return r}function Q8(e,t,r=1,i=40,l=-1,u=!0){if(!(Nh<=r&&r<=i&&i<=_h)||l<-1||l>7)throw new RangeError("Invalid value");let d,f;for(d=r;;d++){const y=jc(d,t)*8,S=W8(e,d);if(S<=y){f=S;break}if(d>=i)throw new RangeError("Data too long")}for(const y of[vy,by,yy])u&&f<=jc(d,y)*8&&(t=y);const p=[];for(const y of e){kr(y.mode[0],4,p),kr(y.numChars,wy(y.mode,d),p);for(const S of y.getData())p.push(S)}const x=jc(d,t)*8;kr(0,Math.min(4,x-p.length),p),kr(0,(8-p.length%8)%8,p);for(let y=236;p.length<x;y^=253)kr(y,8,p);const v=Array.from({length:Math.ceil(p.length/8)},()=>0);return p.forEach((y,S)=>v[S>>>3]|=y<<7-(S&7)),new H8(d,t,v,l)}function eM(e,t){const{ecc:r="L",boostEcc:i=!1,minVersion:l=1,maxVersion:u=40,maskPattern:d=-1,border:f=1}={},p=typeof e=="string"?Y8(e):Array.isArray(e)?[Ny(e)]:void 0;if(!p)throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);const x=Q8(p,D8[r],l,u,d,i);return tM({version:x.version,maskPattern:x.mask,size:x.size,data:x.modules,types:x.types},f)}function tM(e,t=1){if(!t)return e;const{size:r}=e,i=r+t*2;e.size=i,e.data.forEach(u=>{for(let d=0;d<t;d++)u.unshift(!1),u.push(!1)});for(let u=0;u<t;u++)e.data.unshift(Array.from({length:i},d=>!1)),e.data.push(Array.from({length:i},d=>!1));const l=ka.Border;e.types.forEach(u=>{for(let d=0;d<t;d++)u.unshift(l),u.push(l)});for(let u=0;u<t;u++)e.types.unshift(Array.from({length:i},d=>l)),e.types.push(Array.from({length:i},d=>l));return e}function nM({value:e,size:t=200,color:r="#000000",bgColor:i="#ffffff"}){const{data:l}=eM(e),u=l.length,d=t/u;let f="";for(let p=0;p<u;p++){const x=l[p];if(x){for(let v=0;v<u;v++)if(x[v]){const y=v*d,S=p*d;f+=`M${y},${S}h${d}v${d}h-${d}z`}}}return a.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:[a.jsx("rect",{width:t,height:t,fill:i}),a.jsx("path",{d:f,fill:r})]})}const gi="wss://relay.yepanywhere.com/ws",_f="https://yepanywhere.com/remote/login/relay";function e0(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/(1e3*60)),u=Math.floor(i/(1e3*60*60)),d=Math.floor(i/(1e3*60*60*24));return l<1?"just now":l<60?`${l} minute${l===1?"":"s"} ago`:u<24?`${u} hour${u===1?"":"s"} ago`:d===1?"yesterday":d<7?`${d} days ago`:t.toLocaleDateString()}function sM(e,t,r){if(!t)return{text:"Disabled",className:"status-disabled"};if(!r)return{text:"Not configured",className:"status-warning"};switch(e){case"waiting":return{text:"Connected",className:"status-success"};case"connecting":return{text:"Connecting...",className:"status-pending"};case"registering":return{text:"Registering...",className:"status-pending"};case"rejected":return{text:"Username taken",className:"status-error"};default:return{text:"Disconnected",className:"status-warning"}}}function rM({title:e="Remote Access",description:t="Access your server from anywhere.",onSetupComplete:r}){const{config:i,relayConfig:l,relayStatus:u,sessions:d,loading:f,error:p,configure:x,enable:v,disable:y,updateRelayConfig:S,revokeSession:w,revokeAllSessions:E,refresh:_}=O8(),[C,k]=h.useState(""),[O,L]=h.useState(""),[P,U]=h.useState(""),[A,$]=h.useState("default"),[H,F]=h.useState(""),[ee,de]=h.useState(!1),[Y,te]=h.useState(null),[be,Ce]=h.useState(!1),[D,Z]=h.useState(!1),[V,ge]=h.useState(null),[De,B]=h.useState(!1);h.useEffect(()=>{l&&(k(l.username),l.url===gi?($("default"),F("")):($("custom"),F(l.url)))},[l]),h.useEffect(()=>{const Me=C!==((l==null?void 0:l.username)??""),at=O.length>0,Ht=A==="default"?gi:H,gn=(l==null?void 0:l.url)??gi;Z(Me||at||Ht!==gn)},[C,O,A,H,l]),h.useEffect(()=>{if((u==null?void 0:u.status)==="connecting"||(u==null?void 0:u.status)==="registering"){const Me=setInterval(_,2e3);return()=>clearInterval(Me)}},[u==null?void 0:u.status,_]);const se=(i==null?void 0:i.enabled)??!1,me=!!(i!=null&&i.username),ie=()=>A==="default"?gi:H,Ne=async()=>{if(te(null),!C.trim())return te("Username is required"),!1;if(C.length<3)return te("Username must be at least 3 characters"),!1;if(!me&&!O)return te("Password is required"),!1;if(O&&O.length<8)return te("Password must be at least 8 characters"),!1;if(O&&O!==P)return te("Passwords do not match"),!1;if(A==="custom"&&!H.trim())return te("Custom relay URL is required"),!1;try{const Me=ie();return(C!==(l==null?void 0:l.username)||Me!==(l==null?void 0:l.url))&&await S({url:Me,username:C}),O&&(await x(O),ge(O)),L(""),U(""),Z(!1),!0}catch(Me){return te(Me instanceof Error?Me.message:"Failed to save"),!1}},Ae=async Me=>{te(null),de(!0);try{if(Me)if(D){if(!await Ne()){de(!1);return}r==null||r()}else me&&(await v(),r==null||r());else await y()}catch(at){te(at instanceof Error?at.message:"Failed to update")}finally{de(!1)}},Ke=async Me=>{Me.preventDefault(),de(!0),await Ne()&&(r==null||r()),de(!1)},$e=async Me=>{await navigator.clipboard.writeText(Me),Ce(!0),setTimeout(()=>Ce(!1),2e3)};if(f)return a.jsxs("div",{className:"remote-access-setup",children:[a.jsx("div",{className:"remote-access-header",children:a.jsxs("div",{children:[a.jsx("h3",{children:e}),a.jsx("p",{children:t})]})}),a.jsx("div",{className:"remote-access-loading",children:"Loading..."})]});const fe=sM((u==null?void 0:u.status)??null,se,me),Ze=(()=>{const Me=new URLSearchParams;C&&Me.set("u",C);const at=ie();at!==gi&&Me.set("r",at);const Ht=Me.toString();return Ht?`${_f}?${Ht}`:_f})(),jt=(()=>{if(!V||!C)return null;const Me=new URLSearchParams;Me.set("u",C),Me.set("p",V);const at=ie();return at!==gi&&Me.set("r",at),`${_f}#${Me.toString()}`})(),ve=se&&(u==null?void 0:u.status)==="waiting"&&jt!==null,_t=me||C&&O;return a.jsxs("div",{className:"remote-access-setup",children:[a.jsxs("div",{className:"remote-access-header",children:[a.jsxs("div",{children:[a.jsx("h3",{children:e}),a.jsx("p",{children:t})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:se,onChange:Me=>Ae(Me.target.checked),disabled:ee||!se&&!_t}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("form",{onSubmit:Ke,className:"remote-access-form",children:[a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"remote-username",children:"Username"}),a.jsx("input",{id:"remote-username",type:"text",value:C,onChange:Me=>k(Me.target.value.toLowerCase()),placeholder:"my-server",minLength:3,maxLength:32,pattern:"[a-z0-9][a-z0-9-]*[a-z0-9]|[a-z0-9]{1,2}",title:"Lowercase letters, numbers, and hyphens only",autoComplete:"username",disabled:ee})]}),a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"remote-password",children:me?"New Password (leave blank to keep)":"Password"}),a.jsx("input",{id:"remote-password",type:"password",value:O,onChange:Me=>L(Me.target.value),placeholder:me?"••••••••":"",minLength:8,autoComplete:"new-password",disabled:ee})]}),O&&a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"remote-confirm",children:"Confirm Password"}),a.jsx("input",{id:"remote-confirm",type:"password",value:P,onChange:Me=>U(Me.target.value),minLength:8,autoComplete:"new-password",disabled:ee})]}),a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"relay-select",children:"Relay Server"}),a.jsxs("select",{id:"relay-select",value:A,onChange:Me=>$(Me.target.value),disabled:ee,className:"form-select",children:[a.jsx("option",{value:"default",children:"Default"}),a.jsx("option",{value:"custom",children:"Custom"})]})]}),A==="custom"&&a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"custom-relay-url",children:"Custom Relay URL"}),a.jsx("input",{id:"custom-relay-url",type:"text",value:H,onChange:Me=>F(Me.target.value),placeholder:"wss://your-relay.example.com/ws",disabled:ee})]}),a.jsxs("div",{className:"remote-access-status",children:[a.jsx("span",{className:"status-label",children:"Status:"}),a.jsx("span",{className:`status-indicator ${fe.className}`,children:fe.text}),(u==null?void 0:u.error)&&a.jsx("span",{className:"status-error-detail",children:u.error})]}),(Y||p)&&a.jsx("p",{className:"form-error",children:Y||p}),se&&C&&a.jsxs("div",{className:"remote-access-connect",children:[a.jsx("span",{className:"connect-label",children:"Connect from:"}),a.jsxs("div",{className:"connect-url-row",children:[a.jsx("code",{className:"connect-url",children:Ze}),a.jsx("button",{type:"button",className:"copy-button",onClick:()=>$e(Ze),title:"Copy URL",children:be?"Copied!":"Copy"})]})]}),ve&&a.jsxs("div",{className:"remote-access-qr",children:[a.jsx("button",{type:"button",className:"qr-toggle-button",onClick:()=>B(!De),children:De?"Hide QR Code":"Show QR Code"}),De&&jt&&a.jsxs("div",{className:"qr-code-container",children:[a.jsx(nM,{value:jt,size:200}),a.jsx("p",{className:"qr-code-hint",children:"Scan to connect and auto-login from your phone"})]})]}),a.jsxs("div",{className:"remote-access-sessions",children:[a.jsxs("div",{className:"sessions-header",children:[a.jsxs("span",{className:"sessions-title",children:["Sessions (",d.length,")"]}),d.length>0&&a.jsx("button",{type:"button",className:"revoke-all-button",onClick:()=>E(),disabled:ee,children:"Revoke All"})]}),d.length===0?a.jsx("p",{className:"sessions-empty",children:"No sessions"}):a.jsx("ul",{className:"sessions-list",children:d.map(Me=>{const{browser:at,os:Ht}=Me.userAgent?vb(Me.userAgent):{browser:"Unknown",os:"Unknown"},gn=Me.userAgent||Me.origin;return a.jsxs("li",{className:"session-item",children:[a.jsx("div",{className:"session-info",children:gn?a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"session-device",children:[at," · ",Ht]}),Me.origin&&a.jsx("code",{className:"session-origin",children:Me.origin}),a.jsxs("span",{className:"session-dates",children:["Created ",e0(Me.createdAt)," · Last used ",e0(Me.lastUsed)]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"session-created",children:["Created:"," ",new Date(Me.createdAt).toLocaleDateString()]}),a.jsxs("span",{className:"session-last-used",children:["Last used:"," ",new Date(Me.lastUsed).toLocaleDateString()]})]})}),a.jsx("button",{type:"button",className:"revoke-button",onClick:()=>w(Me.sessionId),disabled:ee,children:"Revoke"})]},Me.sessionId)})})]}),a.jsx("div",{className:"remote-access-actions",children:a.jsx("button",{type:"submit",className:"settings-button",disabled:ee||!D,children:ee?"Saving...":"Save"})})]})]})}function aM(){const e=ds(),t=Bc(),r=()=>{t==null||t.disconnect(),e("/login")};if(t){const i=t.currentHostId?dT(t.currentHostId):null,l=(i==null?void 0:i.displayName)||t.storedUsername||"Remote server";return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Remote Access"}),a.jsx("p",{className:"settings-section-description",children:"You are connected to a remote server via relay."}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Current Host"}),a.jsx("p",{children:l})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:r,children:"Switch Host"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Logout"}),a.jsx("p",{children:"Disconnect from the remote server"})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>t.disconnect(),children:"Logout"})]})]})]})}return a.jsx("section",{className:"settings-section",children:a.jsx(rM,{title:"Remote Access",description:"Access your yepanywhere server from anywhere through an encrypted relay connection."})})}function iM(){const{executors:e,loading:t,addExecutor:r,removeExecutor:i,testExecutor:l}=Hb(),[u,d]=h.useState(""),[f,p]=h.useState(!1),[x,v]=h.useState(null),[y,S]=h.useState({}),w=async()=>{if(!(!u.trim()||f)){p(!0),v(null);try{await r(u.trim()),d("")}catch(k){v(k instanceof Error?k.message:"Failed to add executor")}finally{p(!1)}}},E=async k=>{try{await i(k),S(O=>{const{[k]:L,...P}=O;return P})}catch(O){console.error("Failed to remove executor:",O)}},_=async k=>{S(O=>({...O,[k]:{testing:!0}}));try{const O=await l(k);S(L=>({...L,[k]:{testing:!1,result:O}}))}catch(O){S(L=>({...L,[k]:{testing:!1,result:{success:!1,error:O instanceof Error?O.message:"Connection failed"}}}))}},C=k=>{k.key==="Enter"&&(k.preventDefault(),w())};return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Remote Executors"}),a.jsx("p",{className:"settings-section-description",children:"Run Claude sessions on remote machines via SSH. Add SSH host aliases from your ~/.ssh/config file."}),a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Add Remote Executor"}),a.jsx("p",{children:'Enter an SSH host alias (e.g., "devbox", "gpu-server")'})]}),a.jsxs("div",{className:"remote-executor-add",children:[a.jsx("input",{type:"text",value:u,onChange:k=>d(k.target.value),onKeyDown:C,placeholder:"SSH host alias",disabled:f,className:"remote-executor-input"}),a.jsx("button",{type:"button",onClick:w,disabled:!u.trim()||f,className:"remote-executor-add-button",children:f?"Adding...":"Add"})]}),x&&a.jsx("p",{className:"settings-error",children:x})]})}),a.jsxs("div",{className:"settings-group",children:[a.jsx("h3",{children:"Configured Executors"}),t?a.jsx("p",{className:"settings-loading",children:"Loading..."}):e.length===0?a.jsx("p",{className:"settings-empty",children:"No remote executors configured. Add one above to run sessions on remote machines."}):a.jsx("div",{className:"remote-executor-list",children:e.map(k=>{var L;const O=y[k];return a.jsxs("div",{className:"remote-executor-item",children:[a.jsxs("div",{className:"remote-executor-item-info",children:[a.jsx("span",{className:"remote-executor-host",children:k}),(O==null?void 0:O.result)&&a.jsx("span",{className:`settings-status-badge ${O.result.success?"settings-status-detected":"settings-status-not-detected"}`,children:O.result.success?"Connected":"Failed"})]}),(O==null?void 0:O.result)&&!O.result.success&&a.jsx("p",{className:"settings-error remote-executor-error",children:O.result.error}),((L=O==null?void 0:O.result)==null?void 0:L.success)&&a.jsx("p",{className:"remote-executor-details",children:O.result.claudeAvailable?"Claude CLI available":"Claude CLI not found"}),a.jsxs("div",{className:"remote-executor-actions",children:[a.jsx("button",{type:"button",onClick:()=>_(k),disabled:O==null?void 0:O.testing,className:"remote-executor-test-button",children:O!=null&&O.testing?"Testing...":"Test Connection"}),a.jsx("button",{type:"button",onClick:()=>E(k),className:"remote-executor-remove-button",children:"Remove"})]})]},k)})})]}),a.jsxs("div",{className:"settings-group",children:[a.jsx("h3",{children:"Setup Requirements"}),a.jsxs("ul",{className:"settings-requirements",children:[a.jsx("li",{children:"SSH host alias configured in ~/.ssh/config"}),a.jsx("li",{children:"SSH key-based authentication (no password prompts)"}),a.jsx("li",{children:"Claude CLI installed on the remote machine"}),a.jsx("li",{children:"Project paths must be the same on local and remote machines (e.g., ~/code/project)"})]})]})]})}const t0=[{id:"appearance",label:"Appearance",icon:"🎨",description:"Theme, font size, streaming"},{id:"model",label:"Model",icon:"🧠",description:"Claude model and thinking settings"},{id:"notifications",label:"Notifications",icon:"🔔",description:"Push notification preferences"},{id:"devices",label:"Devices",icon:"📱",description:"Browser profiles and connection origins"},{id:"local-access",label:"Local Access",icon:"🔒",description:"Network binding and authentication"},{id:"remote",label:"Remote Access",icon:"🌐",description:"Relay server configuration"},{id:"providers",label:"Providers",icon:"🔌",description:"AI provider integrations"},{id:"remote-executors",label:"Remote Executors",icon:"🖥️",description:"Run sessions on remote machines"},{id:"about",label:"About",icon:"ℹ️",description:"Version and support"}],oM={id:"development",label:"Development",icon:"🛠️",description:"Developer tools and debugging"},lM={appearance:h8,model:w8,notifications:A8,devices:b8,"local-access":j8,remote:aM,providers:M8,"remote-executors":iM,about:f8,development:m8};function n0({category:e,isActive:t,onClick:r}){return a.jsxs("button",{type:"button",className:`settings-category-item ${t?"active":""}`,onClick:r,children:[a.jsx("span",{className:"settings-category-icon",children:e.icon}),a.jsxs("div",{className:"settings-category-text",children:[a.jsx("span",{className:"settings-category-label",children:e.label}),a.jsx("span",{className:"settings-category-description",children:e.description})]}),a.jsx("span",{className:"settings-category-chevron",children:"›"})]})}function s0(){var w;const{category:e}=Ac(),t=ds(),r=or(),{openSidebar:i,isWideScreen:l,toggleSidebar:u,isSidebarCollapsed:d}=La(),{isManualReloadMode:f}=xh(),p=f?[...t0,oM]:t0,x=e||(l?(w=p[0])==null?void 0:w.id:void 0),v=E=>{t(`${r}/settings/${E}`)},y=()=>{t(`${r}/settings`)},S=x?lM[x]:null;if(!l){if(!e)return a.jsx("div",{className:"main-content-mobile",children:a.jsxs("div",{className:"main-content-mobile-inner",children:[a.jsx(Ar,{title:"Settings",onOpenSidebar:i,onToggleSidebar:u,isWideScreen:l,isSidebarCollapsed:d}),a.jsx("main",{className:"page-scroll-container",children:a.jsx("div",{className:"page-content-inner",children:a.jsx("div",{className:"settings-category-list",children:p.map(_=>a.jsx(n0,{category:_,isActive:!1,onClick:()=>v(_.id)},_.id))})})})]})});const E=p.find(_=>_.id===e);return a.jsx("div",{className:"main-content-mobile",children:a.jsxs("div",{className:"main-content-mobile-inner",children:[a.jsx(Ar,{title:(E==null?void 0:E.label)||"Settings",onOpenSidebar:i,showBack:!0,onBack:y}),a.jsx("main",{className:"page-scroll-container",children:a.jsx("div",{className:"page-content-inner",children:S&&a.jsx(S,{})})})]})})}return a.jsx("div",{className:"main-content-wrapper",children:a.jsxs("div",{className:"main-content-constrained",children:[a.jsx(Ar,{title:"Settings",onOpenSidebar:i,onToggleSidebar:u,isWideScreen:l,isSidebarCollapsed:d}),a.jsx("main",{className:"page-scroll-container",children:a.jsxs("div",{className:"settings-two-column",children:[a.jsx("nav",{className:"settings-category-nav",children:a.jsx("div",{className:"settings-category-list",children:p.map(E=>a.jsx(n0,{category:E,isActive:x===E.id,onClick:()=>v(E.id)},E.id))})}),a.jsx("div",{className:"settings-content-panel",children:S&&a.jsx(S,{})})]})})]})})}const cM=h.Fragment;TT();d3();const uM="/".replace(/\/$/,"")||void 0,Cy=document.getElementById("root");if(!Cy)throw new Error("Root element not found");HS.createRoot(Cy).render(a.jsx(cM,{children:a.jsx(a3,{children:a.jsx(hw,{basename:uM,children:a.jsx(r3,{children:a.jsxs(Hj,{children:[a.jsx(ps,{path:"/",element:a.jsx(yx,{to:"/projects",replace:!0})}),a.jsx(ps,{path:"/login",element:a.jsx(y4,{})}),a.jsxs(ps,{element:a.jsx(O3,{}),children:[a.jsx(ps,{path:"/projects",element:a.jsx(A4,{})}),a.jsx(ps,{path:"/sessions",element:a.jsx(p4,{})}),a.jsx(ps,{path:"/agents",element:a.jsx(J3,{})}),a.jsx(ps,{path:"/inbox",element:a.jsx(b4,{})}),a.jsx(ps,{path:"/settings",element:a.jsx(s0,{})}),a.jsx(ps,{path:"/settings/:category",element:a.jsx(s0,{})}),a.jsx(ps,{path:"/projects/:projectId",element:a.jsx(yx,{to:"/sessions",replace:!0})}),a.jsx(ps,{path:"/new-session",element:a.jsx(k4,{})}),a.jsx(ps,{path:"/projects/:projectId/sessions/:sessionId",element:a.jsx(l8,{})})]}),a.jsx(ps,{path:"/projects/:projectId/file",element:a.jsx(d4,{})}),a.jsx(ps,{path:"/activity",element:a.jsx($3,{})})]})})})})}));
|
|
157
|
+
`).trim();return l.length>0?l:null}return null}function o8(e,t,r,i){const[l,u]=h.useState(r??{owner:"none"}),[d,f]=h.useState(r?"in-turn":"idle"),[p,x]=h.useState(null),[v,y]=h.useState(null),[S,w]=h.useState(t),[E,_]=h.useState(null),[C,k]=h.useState([]),[O,L]=h.useState([]),[P,U]=h.useState(!1),[A,$]=h.useState({}),[H,F]=h.useState("default"),[ee,de]=h.useState("default"),[Y,te]=h.useState(0),be=h.useRef(!1);h.useEffect(()=>{be.current=!1},[t]);const[Ce,D]=h.useState([]),[Z,V]=h.useState([]),[ge,De]=h.useState([]),B=h.useRef(0),se=h.useCallback((Ue,St)=>{St>=B.current&&(B.current=St,de(Ue),F(Ue),te(St))},[]),me=h.useCallback(Ue=>{u(St=>St.owner==="self"&&Ue.status.owner!=="self"?St:Ue.status),Ue.status.owner==="self"&&Ue.status.permissionMode&&Ue.status.modeVersion!==void 0&&se(Ue.status.permissionMode,Ue.status.modeVersion),Ue.pendingInputRequest&&x(Ue.pendingInputRequest)},[se]),ie=h.useCallback(Ue=>{y(Ue)},[]),{messages:Ne,agentContent:Ae,toolUseToAgent:Ke,loading:$e,session:fe,setSession:Ze,handleStreamingUpdate:jt,handleStreamMessageEvent:ve,handleStreamSubagentMessage:_t,registerToolUseAgent:Me,setAgentContent:at,setToolUseToAgent:Ht,setMessages:gn,fetchNewMessages:ht}=K5({projectId:e,sessionId:t,onLoadComplete:me,onLoadError:ie}),Ft=h.useCallback(async Ue=>{if(F(Ue),l.owner==="self"||l.owner==="external")try{const St=await ze.setPermissionMode(t,Ue);St.modeVersion>=B.current&&(B.current=St.modeVersion,de(St.permissionMode),te(St.modeVersion))}catch(St){console.warn("Failed to sync permission mode:",St)}},[t,l.owner]),Cn=h.useCallback(async Ue=>{if(l.owner!=="self"&&l.owner!=="external"){console.warn("Cannot set hold: no active process");return}try{const St=await ze.setHold(t,Ue);St.state==="hold"?f("hold"):St.state==="in-turn"&&f("in-turn")}catch(St){console.warn("Failed to set hold:",St)}},[t,l.owner]),Dn=h.useRef({timer:null,pending:!1}),Se=h.useCallback(Ue=>{const St=`temp-${Date.now()}`;return k(cn=>[...cn,{tempId:St,content:Ue,timestamp:new Date().toISOString()}]),St},[]),J=h.useCallback(Ue=>{k(St=>St.filter(cn=>cn.tempId!==Ue))},[]),Re=h.useRef(null);h.useEffect(()=>{if($e||Re.current===t||Ne.length===0)return;(async()=>{Re.current=t;const St=W5(Ne);if(St.length!==0)try{const{mappings:cn}=await ze.getAgentMappings(e,t),yn=new Map(cn.map(ke=>[ke.toolUseId,ke.agentId]));Ht(ke=>{const Dt=new Map(ke);for(const[pn,Bn]of yn)Dt.has(pn)||Dt.set(pn,Bn);return Dt});for(const ke of St){const Dt=yn.get(ke.toolUseId);if(Dt)try{const pn=await ze.getAgentSession(e,t,Dt);at(Bn=>{const qt=Bn[Dt];if(qt&&qt.messages.length>0){const Bs=new Set(qt.messages.map(Gn=>qn(Gn))),un=pn.messages.filter(Gn=>!Bs.has(qn(Gn)));return{...Bn,[Dt]:{messages:[...qt.messages,...un],status:pn.status}}}return{...Bn,[Dt]:pn}})}catch{}}}catch{}})()},[$e,Ne,e,t,at,Ht]);const nt=h.useCallback(()=>{const Ue=Dn.current;Ue.timer?Ue.pending=!0:(ht(),Ue.timer=setTimeout(()=>{Ue.timer=null,Ue.pending&&(Ue.pending=!1,nt())},a8))},[ht]),xt=h.useCallback(Ue=>{Ue.fileType!=="session"&&Ue.fileType!=="agent-session"||X5(Ue)!==t||l.owner!=="self"&&nt()},[t,l.owner,nt]),hn=h.useCallback(Ue=>{Ue.sessionId===t&&Ze(St=>St&&{...St,...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,Ze]),kt=h.useCallback(Ue=>{Ue.sessionId===t&&u(Ue.ownership)},[t]),mn=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&&x(St=>St||(ze.getSessionMetadata(e,t).then(cn=>{cn.pendingInputRequest&&x(cn.pendingInputRequest)}),St)))},[e,t]),ss=h.useCallback(async()=>{ht();try{const Ue=await ze.getSessionMetadata(e,t);u(Ue.ownership),Ue.ownership.owner==="none"&&(f("idle"),x(null))}catch{}},[e,t,ht]);Li({onSessionStatusChange:kt,onFileChange:xt,onSessionUpdated:hn,onProcessStateChange:mn,onReconnect:ss});const yt=h.useCallback(()=>{l.owner!=="self"&&nt()},[l.owner,nt]),{connected:sn}=Q5(l.owner!=="self"?{sessionId:t,projectId:e,provider:fe==null?void 0:fe.provider}:null,{onChange:yt});h.useEffect(()=>()=>{Dn.current.timer&&clearTimeout(Dn.current.timer)},[]);const ln=h.useCallback((Ue,St)=>{at(cn=>{const yn=cn[Ue]??{messages:[],status:"running"};return{...cn,[Ue]:{...yn,contextUsage:St}}})},[at]),{handleStreamEvent:$t,clearStreaming:Qt,cleanup:Yt}=r8({onUpdateMessage:jt,onToolUseMapping:Me,onAgentContextUsage:ln,contextWindowSize:Rf(fe==null?void 0:fe.model,fe==null?void 0:fe.provider),streamingMarkdownCallbacks:i});h.useEffect(()=>()=>{Yt()},[Yt]);const cs=h.useCallback(Ue=>{var St,cn,yn;if(Ue.eventType==="message"){_(new Date().toISOString());const ke=Ue,Dt=ke.uuid,pn=ke.id,Bn=(typeof Dt=="string"?Dt:null)??(typeof pn=="string"?pn:null)??`msg-${Date.now()}`,qt=typeof ke.type=="string"?ke.type:void 0,Bs=ke.role;if(qt==="stream_event"&&$t(ke))return;if(qt==="assistant"){const R=ke.isSubagent&&typeof ke.parentToolUseId=="string"?ke.parentToolUseId:void 0;Qt(),R?at(T=>{const b=T[R];if(!b)return T;const z=b.messages.filter(W=>!W._isStreaming);return z.length===b.messages.length?T:{...T,[R]:{...b,messages:z}}}):gn(T=>T.filter(b=>!b._isStreaming))}const un={...ke,id:Bn,type:qt,role:Bs??(qt==="user"||qt==="assistant"?qt:void 0)};if(un.eventType=void 0,qt==="system"&&ke.subtype==="init"&&(Array.isArray(ke.slash_commands)&&D(ke.slash_commands),Array.isArray(ke.tools)&&V(ke.tools),Array.isArray(ke.mcp_servers)&&De(ke.mcp_servers)),qt==="system"&&ke.subtype==="status"){const N=ke.status;U(N==="compacting");return}qt==="system"&&ke.subtype==="compact_boundary"&&U(!1);const Gn=ke.tempId;if(qt==="user"&&Gn)J(Gn);else if(qt==="user"){const N=i8(ke);N&&k(R=>{const T=R.findIndex(b=>b.content.trim()===N);return T===-1?R:R.filter((b,z)=>z!==T)})}if(ke.isSubagent&&typeof ke.parentToolUseId=="string"){const N=ke.parentToolUseId;Me(N,N),_t(un,N);return}ve(un)}else if(Ue.eventType==="status"){const ke=Ue;(ke.state==="idle"||ke.state==="in-turn"||ke.state==="waiting-input"||ke.state==="hold")&&f(ke.state),ke.state==="waiting-input"&&ke.request?(x(ke.request),ke.request.sessionId&&ke.request.sessionId!==t&&w(ke.request.sessionId)):x(null)}else if(Ue.eventType==="deferred-queue")L(Ue.messages??[]);else if(Ue.eventType==="complete")f("idle"),u({owner:"none"}),x(null),L([]);else if(Ue.eventType==="connected"){const ke=Ue,Dt=ke.sessionId??((St=ke.request)==null?void 0:St.sessionId);Dt&&Dt!==t&&w(Dt),(ke.state==="idle"||ke.state==="in-turn"||ke.state==="waiting-input"||ke.state==="hold")&&f(ke.state),ke.state==="waiting-input"&&ke.request?x(ke.request):x(null),ke.permissionMode&&ke.modeVersion!==void 0&&se(ke.permissionMode,ke.modeVersion);const pn=ke.provider,Bn=ke.model;pn&&Ze(Gn=>Gn&&{...Gn,provider:Gn.provider||pn,...Bn&&{model:Bn}}),L(ke.deferredMessages??[]);const qt=ke.provider??(fe==null?void 0:fe.provider),Bs=qt==="codex"||qt==="codex-oss",un=!be.current;be.current=!0,un&&Bs||ht()}else if(Ue.eventType==="mode-change"){const ke=Ue;ke.permissionMode&&ke.modeVersion!==void 0&&se(ke.permissionMode,ke.modeVersion)}else if(Ue.eventType==="markdown-augment"){const ke=Ue;ke.messageId&&ke.blockIndex===void 0&&ke.html?$(Dt=>({...Dt,[ke.messageId]:{html:ke.html}})):ke.blockIndex!==void 0&&((cn=i==null?void 0:i.onAugment)==null||cn.call(i,{blockIndex:ke.blockIndex,html:ke.html,type:ke.type??"text",messageId:ke.messageId}))}else if(Ue.eventType==="pending"){const ke=Ue;(yn=i==null?void 0:i.onPending)==null||yn.call(i,{html:ke.html})}else if(Ue.eventType==="session-id-changed"){const ke=Ue;ke.newSessionId&&ke.newSessionId!==t&&(w(ke.newSessionId),x(Dt=>Dt&&Dt.sessionId===ke.oldSessionId?{...Dt,sessionId:ke.newSessionId}:Dt))}},[se,t,$t,Qt,J,i,ve,_t,Me,at,gn,Ze,ht,fe==null?void 0:fe.provider]),Xs=h.useCallback(async()=>{try{(await ze.getSessionMetadata(e,t)).ownership.owner!=="self"&&(u({owner:"none"}),f("idle"))}catch{u({owner:"none"}),f("idle")}},[e,t]),{connected:Cs}=J5(l.owner==="self"?t:null,{onMessage:cs,onError:Xs}),Ds=l.owner==="self"?Cs:l.owner==="external"?sn:!1;return{session:fe,messages:Ne,agentContent:Ae,setAgentContent:at,toolUseToAgent:Ke,markdownAugments:A,status:l,processState:d,isCompacting:P,isHeld:d==="hold",pendingInputRequest:p,actualSessionId:S,permissionMode:H,modeVersion:Y,loading:$e,error:v,connected:Cs,sessionWatchConnected:sn,sessionUpdatesConnected:Ds,lastStreamActivityAt:E,setStatus:u,setProcessState:f,setPermissionMode:Ft,setHold:Cn,pendingMessages:C,addPendingMessage:Se,removePendingMessage:J,deferredMessages:O,slashCommands:Ce,sessionTools:Z,mcpServers:ge}}function l8(){const{projectId:e,sessionId:t}=Ac();return!e||!t?a.jsx("div",{className:"error",children:"Invalid session URL"}):a.jsx(gR,{children:a.jsx(c8,{projectId:e,sessionId:t},t)})}function c8({projectId:e,sessionId:t}){const{openSidebar:r,isWideScreen:i,toggleSidebar:l,isSidebarCollapsed:u}=La(),d=or(),{project:f}=db(e),p=ds(),x=vs(),v=x.state,y=v==null?void 0:v.initialStatus,S=v==null?void 0:v.initialTitle,w=v==null?void 0:v.initialModel,E=v==null?void 0:v.initialProvider,_=Jb(),C=h.useMemo(()=>{if(_)return{onAugment:_.dispatchAugment,onPending:_.dispatchPending,onStreamEnd:_.dispatchStreamEnd,setCurrentMessageId:_.setCurrentMessageId,captureHtml:_.captureStreamingHtml}},[_]),{session:k,messages:O,agentContent:L,setAgentContent:P,toolUseToAgent:U,markdownAugments:A,status:$,processState:H,isCompacting:F,pendingInputRequest:ee,actualSessionId:de,permissionMode:Y,loading:te,error:be,sessionUpdatesConnected:Ce,lastStreamActivityAt:D,setStatus:Z,setProcessState:V,setPermissionMode:ge,setHold:De,isHeld:B,pendingMessages:se,addPendingMessage:me,removePendingMessage:ie,deferredMessages:Ne,slashCommands:Ae}=o8(e,t,y,C),{holdModeEnabled:Ke,showConnectionBars:$e}=zi(),{connectionState:fe}=ih(),Ze=$.owner==="self"||$.owner==="external",jt=!$e||!Ze?"idle":Ce?"connected":fe==="reconnecting"?"connecting":"disconnected",ve=(k==null?void 0:k.provider)??E,_t=(k==null?void 0:k.model)??w,[Me,at]=h.useState(0),Ht=h.useRef(null),gn=h.useCallback(ne=>{Ht.current=ne},[]),{showToast:ht}=gh(),Ft=Ib(),Cn=$b(),Dn=h.useMemo(()=>[...Ae,"login"],[Ae]),{providers:Se}=bh(),J=h.useMemo(()=>k!=null&&k.provider?Se.find(ne=>ne.name===k.provider)??null:null,[Se,k==null?void 0:k.provider]),Re=(J==null?void 0:J.supportsPermissionMode)??!0,nt=(J==null?void 0:J.supportsThinkingToggle)??!0,xt=(J==null?void 0:J.supportsSlashCommands)??!1,[hn,kt]=h.useState(!1),[mn,ss]=h.useState(""),[yt,sn]=h.useState(!1),ln=h.useRef(null),$t=h.useRef(!1),[Qt,Yt]=h.useState(!1),cs=h.useRef(null),[Xs,Cs]=h.useState(void 0),[Ds,Ue]=h.useState(void 0),[St,cn]=h.useState(void 0),[yn,ke]=h.useState(void 0);h.useEffect(()=>{Cs(void 0),Ue(void 0),cn(void 0),ke(void 0)},[t]),h.useEffect(()=>{Y5(t,e)},[t,e]),h.useEffect(()=>{de&&de!==t&&p(`${d}/projects/${e}/sessions/${de}`,{replace:!0,state:x.state})},[de,t,e,p,x.state,d]);const[Dt,pn]=h.useState([]),[Bn,qt]=h.useState([]),[Bs,un]=h.useState(!1),[Gn,N]=h.useState(!1),R=(k==null?void 0:k.updatedAt)??null,T=h.useMemo(()=>!R&&!D?null:R?D?R>D?R:D:R:D,[R,D]);G5({sessionId:t,activityAt:T,updatedAt:R,lastSeenAt:k==null?void 0:k.lastSeenAt,hasUnread:k==null?void 0:k.hasUnread,enabled:$.owner!=="external"});const b=async ne=>{var et,it,I;if(ne.trim()==="/login"){Ft.startLogin();return}const Le=me(ne);V("in-turn"),at(ot=>ot+1);const Ge=[...Dt];pn([]);try{if($.owner==="none"){const ot=(k==null?void 0:k.model)??Cc(),pt=Lo(),Rt=await ze.resumeSession(e,t,ne,{mode:Y,model:ot,thinking:pt,provider:ve,executor:k==null?void 0:k.executor},Ge.length>0?Ge:void 0,Le);Z({owner:"self",processId:Rt.processId})}else{const ot=Lo(),pt=await ze.queueMessage(t,ne,Y,Ge.length>0?Ge:void 0,Le,ot);pt.restarted&&pt.processId&&Z({owner:"self",processId:pt.processId})}(et=Ht.current)==null||et.clearDraft()}catch(ot){if(console.error("Failed to send:",ot),ot instanceof Error&&(ot.message.includes("404")||ot.message.includes("No active process")))try{const wt=(k==null?void 0:k.model)??Cc(),Mt=Lo(),Ct=await ze.resumeSession(e,t,ne,{mode:Y,model:wt,thinking:Mt,provider:ve,executor:k==null?void 0:k.executor},Ge.length>0?Ge:void 0,Le);Z({owner:"self",processId:Ct.processId}),(it=Ht.current)==null||it.clearDraft();return}catch(wt){console.error("Failed to resume session:",wt)}ie(Le),(I=Ht.current)==null||I.restoreFromStorage(),pn(Ge),V("idle");const Rt=ot instanceof Error?ot.message:"Unknown error";ht(`Failed to send message: ${Rt}`,"error")}},z=async ne=>{var et,it;const Le=me(ne);at(I=>I+1);const Ge=[...Dt];pn([]);try{const I=Lo();await ze.queueMessage(t,ne,Y,Ge.length>0?Ge:void 0,Le,I,!0),(et=Ht.current)==null||et.clearDraft()}catch(I){console.error("Failed to queue deferred message:",I),ie(Le),(it=Ht.current)==null||it.restoreFromStorage(),pn(Ge);const ot=I instanceof Error?I.message:"Unknown error";ht(`Failed to queue message: ${ot}`,"error")}},W=async()=>{if($.owner==="self"&&$.processId){try{if((await ze.interruptProcess($.processId)).interrupted)return}catch{}await ze.abortProcess($.processId)}},K=h.useCallback(async()=>{if(ee)try{await ze.respondToInput(t,ee.id,"approve")}catch(ne){const Le=ne.status,Ge=Le?`Error ${Le}`:"Failed to approve";ht(Ge,"error")}},[t,ee,ht]),he=h.useCallback(async()=>{if(ee)try{await ze.respondToInput(t,ee.id,"approve_accept_edits"),ge("acceptEdits")}catch(ne){const Le=ne.status,Ge=Le?`Error ${Le}`:"Failed to approve";ht(Ge,"error")}},[t,ee,ge,ht]),Oe=h.useCallback(async()=>{if(ee)try{await ze.respondToInput(t,ee.id,"deny")}catch(ne){const Le=ne.status,Ge=Le?`Error ${Le}`:"Failed to deny";ht(Ge,"error")}},[t,ee,ht]),Je=h.useCallback(async ne=>{if(ee)try{await ze.respondToInput(t,ee.id,"deny",void 0,ne)}catch(Le){const Ge=Le.status,et=Ge?`Error ${Ge}`:"Failed to send feedback";ht(et,"error")}},[t,ee,ht]),Fe=h.useCallback(async ne=>{if(ee)try{await ze.respondToInput(t,ee.id,"approve",ne)}catch(Le){const Ge=Le.status,et=Ge?`Error ${Ge}`:"Failed to submit answer";ht(et,"error")}},[t,ee,ht]),zt=h.useCallback(async ne=>{for(const Le of ne){const Ge=crypto.randomUUID();qt(et=>[...et,{fileId:Ge,fileName:Le.name,bytesUploaded:0,totalBytes:Le.size,percent:0}]);try{const et=await Cn.upload(e,t,Le,{onProgress:it=>{qt(I=>I.map(ot=>ot.fileId===Ge?{...ot,bytesUploaded:it,percent:Math.round(it/Le.size*100)}:ot))}});pn(it=>[...it,et])}catch(et){console.error("Upload failed:",et);const it=et instanceof Error?et.message:"Upload failed";ht(`Failed to upload ${Le.name}: ${it}`,"error")}finally{qt(et=>et.filter(it=>it.fileId!==Ge))}}},[e,t,ht,Cn]),Ye=h.useCallback(ne=>{pn(Le=>Le.filter(Ge=>Ge.id!==ne))},[]),ct=(ee==null?void 0:ee.toolName)==="AskUserQuestion",gt=H==="in-turn"||H==="waiting-input",vt=h.useMemo(()=>$.owner!=="none"?!1:yh(O).some(Le=>Le.type==="tool_call"&&Le.status==="pending"),[O,$.owner]),mt=Cr(k),lt=Xs??(mt!=="Untitled"?mt:null)??S??"Untitled",dt=Ds??(k==null?void 0:k.isArchived)??!1,Xe=St??(k==null?void 0:k.isStarred)??!1;qb(f==null?void 0:f.name,lt);const We=()=>{ss(lt),kt(!0),setTimeout(()=>{var ne,Le;(ne=ln.current)==null||ne.focus(),(Le=ln.current)==null||Le.select()},0)},st=()=>{$t.current||(kt(!1),ss(""))},Pe=()=>{if(!$t.current){if(!mn.trim()||mn.trim()===lt){st();return}Ve()}},Ve=async()=>{if(!(!mn.trim()||yt)){$t.current=!0,sn(!0);try{await ze.updateSessionMetadata(t,{title:mn.trim()}),Cs(mn.trim()),kt(!1),ht("Session renamed","success")}catch(ne){console.error("Failed to rename session:",ne),ht("Failed to rename session","error")}finally{sn(!1),$t.current=!1}}},Qe=ne=>{ne.key==="Enter"?(ne.preventDefault(),Ve()):ne.key==="Escape"&&(ne.preventDefault(),st())},He=async()=>{const ne=!dt;try{await ze.updateSessionMetadata(t,{archived:ne}),Ue(ne),ht(ne?"Session archived":"Session unarchived","success")}catch(Le){console.error("Failed to update archive status:",Le),ht("Failed to update archive status","error")}},le=async()=>{const ne=!Xe;try{await ze.updateSessionMetadata(t,{starred:ne}),cn(ne),ht(ne?"Session starred":"Session unstarred","success")}catch(Le){console.error("Failed to update star status:",Le),ht("Failed to update star status","error")}},ce=yn??(k==null?void 0:k.hasUnread)??!1,Ee=async()=>{const ne=!ce;ke(ne);try{ne?await ze.markSessionUnread(t):await ze.markSessionSeen(t),ht(ne?"Marked as unread":"Marked as read","success")}catch(Le){console.error("Failed to update read status:",Le),ke(void 0),ht("Failed to update read status","error")}},je=async()=>{if($.owner==="self"&&$.processId)try{await ze.abortProcess($.processId),ht("Session terminated","success")}catch(ne){console.error("Failed to terminate session:",ne);const Le=ne instanceof Error?ne.message:"Unknown error";ht(`Failed to terminate: ${Le}`,"error")}};if(be)return a.jsxs("div",{className:"error",children:["Error: ",be.message]});const xe=()=>a.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:[a.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),a.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]});return a.jsx("div",{className:i?"main-content-wrapper":"main-content-mobile",children:a.jsxs("div",{className:i?"main-content-constrained":"main-content-mobile-inner",children:[a.jsx("header",{className:"session-header",children:a.jsxs("div",{className:"session-header-inner",children:[a.jsxs("div",{className:"session-header-left",children:[!(i&&u)&&a.jsx("button",{type:"button",className:"sidebar-toggle",onClick:i?l:r,title:i?"Toggle sidebar":"Open sidebar","aria-label":i?"Toggle sidebar":"Open sidebar",children:a.jsx(xe,{})}),(f==null?void 0:f.name)&&a.jsx(Gs,{to:`${d}/sessions?project=${e}`,className:"project-breadcrumb",title:f.name,children:f.name.length>12?`${f.name.slice(0,12)}...`:f.name}),a.jsxs("div",{className:"session-title-row",children:[Xe&&a.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":"Starred",children:[a.jsx("title",{children:"Starred"}),a.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"})]}),te?a.jsx("span",{className:"session-title-skeleton"}):hn?a.jsx("input",{ref:ln,type:"text",className:"session-title-input",value:mn,onChange:ne=>ss(ne.target.value),onKeyDown:Qe,onBlur:Pe,disabled:yt}):a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:cs,type:"button",className:"session-title session-title-dropdown-trigger",onClick:()=>Yt(!Qt),title:(k==null?void 0:k.fullTitle)??lt,children:[a.jsx("span",{className:"session-title-text",children:lt}),a.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:a.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),a.jsx(H5,{currentSessionId:t,isOpen:Qt,onClose:()=>Yt(!1),onNavigate:()=>Yt(!1),triggerRef:cs,basePath:d})]}),!te&&dt&&a.jsx("span",{className:"archived-badge",children:"Archived"}),!te&&a.jsx(Bb,{sessionId:t,projectId:e,isStarred:Xe,isArchived:dt,hasUnread:ce,provider:k==null?void 0:k.provider,processId:$.owner==="self"?$.processId:void 0,onToggleStar:le,onToggleArchive:He,onToggleRead:Ee,onRename:We,onClone:ne=>{p(`${d}/projects/${e}/sessions/${ne}`)},onTerminate:je,useFixedPositioning:!0,useEllipsisIcon:!0})]})]}),a.jsx("div",{className:"session-header-right",children:!te&&ve&&a.jsx("button",{type:"button",className:"provider-badge-button",onClick:()=>N(!0),title:"View session info",children:a.jsx(L5,{provider:ve,model:_t,isThinking:H==="in-turn"})})})]})}),Gn&&k&&a.jsx(M5,{sessionId:de,provider:k.provider,model:k.model,status:$,processState:H,contextUsage:k.contextUsage,originator:k.originator,cliVersion:k.cliVersion,sessionSource:k.source,approvalPolicy:k.approvalPolicy,sandboxPolicy:k.sandboxPolicy,sessionStreamConnected:Ce,lastSessionEventAt:D,onClose:()=>N(!1)}),$.owner==="external"&&a.jsx("div",{className:"external-session-warning",children:"External session active - enter messages at your own risk!"}),vt&&a.jsx("div",{className:"external-session-warning pending-tool-warning",children:"This session may be waiting for input in another process (VS Code, CLI). Check there before sending a message."}),a.jsx("main",{className:"session-messages",children:te?a.jsx("div",{className:"loading",children:"Loading session..."}):a.jsx(HR,{projectId:e,projectPath:(f==null?void 0:f.path)??null,sessionId:t,children:a.jsx(_A,{agentContent:L,setAgentContent:P,toolUseToAgent:U,projectId:e,sessionId:t,children:a.jsx(C5,{messages:O,isProcessing:$.owner==="self"&&H==="in-turn",isCompacting:F,scrollTrigger:Me,pendingMessages:se,deferredMessages:Ne,onCancelDeferred:ne=>ze.cancelDeferredMessage(t,ne),markdownAugments:A,activeToolApproval:gt})})})}),a.jsxs("footer",{className:"session-input",children:[a.jsx("div",{className:`session-connection-bar session-connection-${jt}`}),a.jsxs("div",{className:"session-input-inner",children:[ee&&ee.sessionId===de&&ct&&a.jsx(B5,{request:ee,sessionId:de,onSubmit:Fe,onDeny:Oe}),ee&&ee.sessionId===de&&!ct&&a.jsxs(a.Fragment,{children:[a.jsx(Z5,{request:ee,sessionId:de,onApprove:K,onDeny:Oe,onApproveAcceptEdits:he,onDenyWithFeedback:Je,collapsed:Bs,onCollapsedChange:un}),a.jsx(Zb,{mode:Y,onModeChange:ge,isHeld:Ke?B:void 0,onHoldChange:Ke?De:void 0,supportsPermissionMode:Re,supportsThinkingToggle:nt,contextUsage:k==null?void 0:k.contextUsage,isRunning:$.owner==="self",isThinking:H==="in-turn",onStop:W,pendingApproval:Bs?{type:"tool-approval",onExpand:()=>un(!1)}:void 0})]}),!(ee&&ee.sessionId===de&&!ct)&&a.jsx(U4,{onSend:b,onQueue:$.owner!=="none"&&H!=="idle"?z:void 0,placeholder:$.owner==="external"?"External session - send at your own risk...":H==="idle"?"Send a message to resume...":"Queue a message...",mode:Y,onModeChange:ge,isHeld:Ke?B:void 0,onHoldChange:Ke?De:void 0,supportsPermissionMode:Re,supportsThinkingToggle:nt,isRunning:$.owner==="self",isThinking:H==="in-turn",onStop:W,draftKey:`draft-message-${t}`,onDraftControlsReady:gn,collapsed:!!(ee&&ee.sessionId===de),contextUsage:k==null?void 0:k.contextUsage,projectId:e,sessionId:t,attachments:Dt,onAttach:zt,onRemoveAttachment:Ye,uploadProgress:Bn,slashCommands:xt&&$.owner==="self"?Dn:[]})]})]}),Ft.isOpen&&a.jsx(Fb,{authMethod:Ft.authMethod,onSelectMethod:Ft.selectMethod,url:Ft.url,statusMessage:Ft.statusMessage,startupError:Ft.error,onSuccess:Ft.handleSuccess,onCancel:Ft.handleCancel})]})})}let Ca=null;function u8(){const[e,t]=h.useState(!1),[r,i]=h.useState(!1);h.useEffect(()=>{if(window.matchMedia("(display-mode: standalone)").matches||"standalone"in navigator&&navigator.standalone===!0){i(!0);return}Ca&&t(!0);const d=p=>{p.preventDefault(),Ca=p,t(!0)},f=()=>{i(!0),t(!1),Ca=null};return window.addEventListener("beforeinstallprompt",d),window.addEventListener("appinstalled",f),()=>{window.removeEventListener("beforeinstallprompt",d),window.removeEventListener("appinstalled",f)}},[]);const l=h.useCallback(async()=>{if(!Ca)return!1;await Ca.prompt();const{outcome:u}=await Ca.userChoice;return u==="accepted"?(t(!1),Ca=null,!0):!1},[]);return{canInstall:e,isInstalled:r,install:l}}function d8(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),d=h.useRef(!1),f=h.useCallback(async()=>{i(!0),u(null);try{const p=await ze.getVersion();t(p)}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{i(!1)}},[]);return h.useEffect(()=>{d.current||(d.current=!0,f())},[f]),{version:e,loading:r,error:l,refetch:f}}function f8(){const{canInstall:e,isInstalled:t,install:r}=u8(),{version:i}=d8(),{resetOnboarding:l}=Tb(),{remoteLogCollectionEnabled:u,setRemoteLogCollectionEnabled:d}=zi(),[f,p]=h.useState(!1),[x,v]=h.useState(0);h.useEffect(()=>{Be("/status/workers").then(S=>v(S.activeWorkers)).catch(()=>{})},[]),h.useEffect(()=>{if(f)return fn.on("reconnect",()=>{p(!1)})},[f]);const y=h.useCallback(async()=>{p(!0);try{await ze.restartServer()}catch{}},[]);return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"About"}),a.jsxs("div",{className:"settings-group",children:[(e||t)&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Install App"}),a.jsx("p",{children:t?"Yep Anywhere is installed on your device.":"Add Yep Anywhere to your home screen for quick access."})]}),t?a.jsx("span",{className:"settings-status-badge",children:"Installed"}):a.jsx("button",{type:"button",className:"settings-button",onClick:r,children:"Install"})]}),a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Version"}),a.jsxs("p",{children:["Server:"," ",i?a.jsxs(a.Fragment,{children:["v",i.current,i.updateAvailable&&i.latest?a.jsxs("span",{className:"settings-update-available",children:[" ","(v",i.latest," available)"]}):i.latest?a.jsx("span",{className:"settings-up-to-date",children:" (up to date)"}):null]}):"Loading..."]}),a.jsxs("p",{children:["Client: v","0.3.2"]}),(i==null?void 0:i.updateAvailable)&&a.jsxs("p",{className:"settings-update-hint",children:["Run ",a.jsx("code",{children:"npm i -g yepanywhere"})," to update"]})]})}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Restart Server"}),a.jsx("p",{children:"Restart the backend server process."}),x>0&&!f&&a.jsxs("p",{className:"settings-warning",children:[x," active session",x!==1?"s":""," will be interrupted"]})]}),a.jsx("button",{type:"button",className:`settings-button ${x>0?"settings-button-danger":""}`,onClick:y,disabled:f,children:f?"Restarting...":x>0?"Restart Anyway":"Restart Server"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Report a Bug"}),a.jsx("p",{children:"Found an issue? Report it on GitHub to help improve Yep Anywhere."})]}),a.jsx("a",{href:"https://github.com/kzahel/yepanywhere/issues",target:"_blank",rel:"noopener noreferrer",className:"settings-button",children:"Report Bug"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Setup Wizard"}),a.jsx("p",{children:"Run the initial setup wizard again to configure theme and remote access."})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:l,children:"Launch Wizard"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Connection Diagnostics"}),a.jsx("p",{children:"Capture connection logs and send to server for debugging."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:u,onChange:S=>d(S.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]})]})}function h8(){const{fontSize:e,setFontSize:t}=u3(),{theme:r,setTheme:i}=jb(),{streamingEnabled:l,setStreamingEnabled:u}=t8(),{funPhrasesEnabled:d,setFunPhrasesEnabled:f}=Y4(),{showConnectionBars:p,setShowConnectionBars:x}=zi();return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Appearance"}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Theme"}),a.jsx("p",{children:"Choose your preferred color scheme."})]}),a.jsx("div",{className:"font-size-selector",children:hh.map(v=>a.jsx("button",{type:"button",className:`font-size-option ${r===v?"active":""}`,onClick:()=>i(v),children:bb(v)},v))})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Font Size"}),a.jsx("p",{children:"Adjust the text size throughout the application."})]}),a.jsx("div",{className:"font-size-selector",children:Mb.map(v=>a.jsx("button",{type:"button",className:`font-size-option ${e===v?"active":""}`,onClick:()=>t(v),children:l3(v)},v))})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Response Streaming"}),a.jsx("p",{children:"Show responses as they are generated, token by token. Disable for better performance on slower devices."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:v=>u(v.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Fun Phrases"}),a.jsx("p",{children:'Show playful status messages while waiting for responses. Disable to show only "Thinking..."'})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:d,onChange:v=>f(v.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Connection Bars"}),a.jsx("p",{children:"Show colored status bars for relay and session connections (green/orange/red)."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:p,onChange:v=>x(v.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]})]})}function py(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),d=h.useCallback(async()=>{try{i(!0),u(null);const p=await ze.getServerSettings();t(p.settings)}catch(p){console.error("[useServerSettings] Failed to fetch settings:",p),u(p instanceof Error?p.message:"Failed to load settings")}finally{i(!1)}},[]);h.useEffect(()=>{d()},[d]);const f=h.useCallback(async(p,x)=>{try{u(null);const v=await ze.updateServerSettings({[p]:x});t(v.settings)}catch(v){throw console.error("[useServerSettings] Failed to update setting:",v),u(v instanceof Error?v.message:"Failed to update setting"),v}},[]);return{settings:e,isLoading:r,error:l,updateSetting:f,refetch:d}}function m8(){const{isManualReloadMode:e,pendingReloads:t,connected:r,reloadBackend:i,unsafeToRestart:l,workerActivity:u}=xh(),{settings:d,setEnabled:f}=_b(),{holdModeEnabled:p,setHoldModeEnabled:x}=zi(),{ignoredTools:v,clearIgnoredTools:y}=Vn(),{settings:S,updateSetting:w}=py(),[E,_]=h.useState(!1);h.useEffect(()=>{E&&r&&_(!1)},[E,r]);const C=async()=>{_(!0),await i()};return e?a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Development"}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Schema Validation"}),a.jsx("p",{children:"Validate tool results against expected schemas. Shows toast notifications and logs errors to console."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:d.enabled,onChange:k=>f(k.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),v.length>0&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Ignored Tools"}),a.jsx("p",{children:"Tools with validation errors you chose to ignore. They will not show toast notifications."}),a.jsx("div",{className:"ignored-tools-list",children:v.map(k=>a.jsx("span",{className:"ignored-tool-badge",children:k},k))})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-secondary",onClick:y,children:"Clear Ignored"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Hold Mode"}),a.jsx("p",{children:"Show hold/resume option in the mode selector. Pauses execution at the next yield point (experimental)."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:p,onChange:k=>x(k.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Service Worker"}),a.jsx("p",{children:"Enable service worker for push notifications. Disabling can help with page reload issues during development. Requires restart."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(S==null?void 0:S.serviceWorkerEnabled)??!0,onChange:k=>w("serviceWorkerEnabled",k.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]}),a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Restart Server"}),a.jsxs("p",{children:["Restart the backend server to pick up code changes.",t.backend&&a.jsx("span",{className:"settings-pending",children:" (changes pending)"})]}),l&&a.jsxs("p",{className:"settings-warning",children:[u.activeWorkers," active session",u.activeWorkers!==1?"s":""," will be interrupted"]})]}),a.jsx("button",{type:"button",className:`settings-button ${l?"settings-button-danger":""}`,onClick:C,disabled:E,children:E?"Restarting...":l?"Restart Anyway":"Restart Server"})]})})]}):null}function p8(){const[e,t]=h.useState({profiles:[],isLoading:!0,error:null}),r=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{profiles:l}=await ze.getBrowserProfiles();t({profiles:l,isLoading:!1,error:null})}catch(l){console.error("[useBrowserProfiles] Failed to fetch:",l),t(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to load profiles"}))}},[]);h.useEffect(()=>{r()},[r]);const i=h.useCallback(async l=>{t(u=>({...u,isLoading:!0,error:null}));try{await ze.deleteBrowserProfile(l),await r()}catch(u){console.error("[useBrowserProfiles] Failed to delete:",u),t(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to delete profile"}))}},[r]);return{...e,deleteProfile:i,refetch:r}}function gy(){const[e,t]=h.useState({connections:new Map,isLoading:!0,error:null}),r=h.useCallback(async()=>{t(i=>({...i,isLoading:!0,error:null}));try{const{connections:i}=await ze.getConnections(),l=new Map;for(const u of i)l.set(u.browserProfileId,u);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(()=>{r()},[r]),h.useEffect(()=>{const i=fn.on("browser-tab-connected",f=>{t(p=>{var v;const x=new Map(p.connections);return x.set(f.browserProfileId,{browserProfileId:f.browserProfileId,connectionCount:f.tabCount,connectedAt:f.timestamp,deviceName:(v=p.connections.get(f.browserProfileId))==null?void 0:v.deviceName}),{...p,connections:x}})}),l=fn.on("browser-tab-disconnected",f=>{t(p=>{const x=new Map(p.connections);if(f.tabCount===0)x.delete(f.browserProfileId);else{const v=x.get(f.browserProfileId);v&&x.set(f.browserProfileId,{...v,connectionCount:f.tabCount})}return{...p,connections:x}})}),u=fn.on("reconnect",()=>{r()}),d=fn.on("refresh",()=>{r()});return()=>{i(),l(),u(),d()}},[r]),{...e,connectionList:Array.from(e.connections.values()),refetch:r}}const g8="/sw.js";function wh(){const[e,t]=h.useState({isSupported:!1,isSubscribed:!1,isLoading:!0,error:null,permission:"default",browserProfileId:null}),[r,i]=h.useState(null),l=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;h.useEffect(()=>{(async()=>{if(!l){const y=ia("browserProfileId",xs.browserProfileId);t(S=>({...S,isSupported:!1,isLoading:!1,error:"Push notifications not supported in this browser",browserProfileId:y}));return}try{const y=await navigator.serviceWorker.register(g8);i(y),await navigator.serviceWorker.ready;const S=await y.pushManager.getSubscription(),w=Oo();t({isSupported:!0,isSubscribed:!!S,isLoading:!1,error:null,permission:Notification.permission,browserProfileId:w})}catch(y){console.error("[usePushNotifications] Init error:",y),t(S=>({...S,isSupported:!0,isLoading:!1,error:y instanceof Error?y.message:"Failed to initialize"}))}})()},[l]);const u=h.useCallback(async()=>{if(!r){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await Notification.requestPermission();if(t(C=>({...C,permission:v})),v!=="granted"){t(C=>({...C,isLoading:!1,error:"Notification permission denied"}));return}const{publicKey:y}=await ze.getPushPublicKey(),S=x8(y),w=await r.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:S.buffer}),E=Oo(),_=w.toJSON();await ze.subscribePush(E,_,v8()),t(C=>({...C,isSubscribed:!0,isLoading:!1,error:null,browserProfileId:E}))}catch(v){console.error("[usePushNotifications] Subscribe error:",v),t(y=>({...y,isLoading:!1,error:v instanceof Error?v.message:"Failed to subscribe"}))}},[r]),d=h.useCallback(async()=>{if(!r){t(v=>({...v,error:"Service worker not ready"}));return}t(v=>({...v,isLoading:!0,error:null}));try{const v=await r.pushManager.getSubscription();v&&await v.unsubscribe();const y=Oo();await ze.unsubscribePush(y),t(S=>({...S,isSubscribed:!1,isLoading:!1,error:null}))}catch(v){console.error("[usePushNotifications] Unsubscribe error:",v),t(y=>({...y,isLoading:!1,error:v instanceof Error?v.message:"Failed to unsubscribe"}))}},[r]),f=h.useCallback(async(v="normal")=>{const y=Oo();t(S=>({...S,isLoading:!0,error:null}));try{await ze.testPush(y,void 0,v),t(S=>({...S,isLoading:!1}))}catch(S){console.error("[usePushNotifications] Test push error:",S),t(w=>({...w,isLoading:!1,error:S instanceof Error?S.message:"Failed to send test"}))}},[]),p=h.useCallback(async()=>{var y;const v=(y=navigator.serviceWorker)==null?void 0:y.controller;return v?new Promise(S=>{const w=new MessageChannel;w.port1.onmessage=E=>{var _;S(((_=E.data)==null?void 0:_.logs)||[])},v.postMessage({type:"get-sw-logs"},[w.port2]),setTimeout(()=>S([]),2e3)}):(console.warn("[usePushNotifications] No active service worker"),[])},[]),x=h.useCallback(async()=>{var y;const v=(y=navigator.serviceWorker)==null?void 0:y.controller;if(v)return new Promise(S=>{const w=new MessageChannel;w.port1.onmessage=()=>S(),v.postMessage({type:"clear-sw-logs"},[w.port2]),setTimeout(S,1e3)})},[]);return{...e,subscribe:u,unsubscribe:d,sendTest:f,getSwLogs:p,clearSwLogs:x}}function x8(e){const t="=".repeat((4-e.length%4)%4),r=(e+t).replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(r),l=new Uint8Array(i.length);for(let u=0;u<i.length;++u)l[u]=i.charCodeAt(u);return l}function v8(){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 Jv(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/(1e3*60)),u=Math.floor(i/(1e3*60*60)),d=Math.floor(i/(1e3*60*60*24));return l<1?"just now":l<60?`${l} minute${l===1?"":"s"} ago`:u<24?`${u} hour${u===1?"":"s"} ago`:d===1?"yesterday":d<7?`${d} days ago`:t.toLocaleDateString()}function b8(){const{profiles:e,isLoading:t,error:r,deleteProfile:i}=p8(),{browserProfileId:l}=wh(),{connections:u}=gy();return a.jsx(a.Fragment,{children:a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Browser Profiles"}),a.jsx("p",{className:"settings-section-description",children:"Devices that have connected to this server, with their access origins. Each browser profile may connect from multiple URLs (localhost, Tailscale, etc.)."}),r&&a.jsx("p",{className:"form-error",children:r}),a.jsx("div",{className:"settings-group",children:t?a.jsx("p",{className:"settings-hint",children:"Loading profiles..."}):e.length===0?a.jsx("p",{className:"settings-hint",children:"No browser profiles recorded yet. Connect from a browser to see profiles here."}):a.jsx("div",{className:"device-list",children:e.map(d=>{const f=d.browserProfileId===l,p=u.has(d.browserProfileId),x=d.deviceName||`${d.browserProfileId.slice(0,8)}...`;return a.jsxs("div",{className:"device-list-item device-profile-item",children:[a.jsxs("div",{className:"device-list-info",children:[a.jsxs("strong",{children:[a.jsx("span",{className:`device-status ${p?"device-status-online":"device-status-offline"}`,title:p?"Connected":"Disconnected"}),x,f&&a.jsx("span",{className:"device-current-badge",children:"This device"})]}),a.jsx("div",{className:"device-origins",children:d.origins.map(v=>{const{browser:y,os:S}=vb(v.userAgent);return a.jsxs("div",{className:"device-origin",children:[a.jsx("code",{className:"device-origin-url",children:v.origin}),a.jsxs("span",{className:"device-origin-details",children:[y," · ",S]}),a.jsxs("span",{className:"device-origin-time",children:["Last seen ",Jv(v.lastSeen)]})]},v.origin)})}),a.jsxs("p",{className:"device-profile-meta",children:["First seen ",Jv(d.createdAt)]})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>i(d.browserProfileId),title:"Forget this device",children:"Forget"})]},d.browserProfileId)})})})]})})}function y8(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),[d,f]=h.useState(!1),p=h.useRef(!1),x=h.useCallback(async()=>{i(!0),u(null);try{const S=await ze.getNetworkBinding();t(S)}catch(S){u(S instanceof Error?S:new Error(String(S)))}finally{i(!1)}},[]);h.useEffect(()=>{p.current||(p.current=!0,x())},[x]);const v=h.useCallback(async S=>{f(!0),u(null);try{const w=await ze.setNetworkBinding(S);if(!w.success)throw new Error(w.error??"Failed to update binding");return await x(),{redirectUrl:w.redirectUrl}}catch(w){const E=w instanceof Error?w:new Error(String(w));throw u(E),E}finally{f(!1)}},[x]),y=h.useCallback(async()=>{f(!0),u(null);try{const S=await ze.disableNetworkBinding();if(!S.success)throw new Error(S.error??"Failed to disable network socket");await x()}catch(S){const w=S instanceof Error?S:new Error(String(S));throw u(w),w}finally{f(!1)}},[x]);return{binding:e,loading:r,error:l,applying:d,updateBinding:v,disableNetwork:y,refetch:x}}function S8(){const[e,t]=h.useState(null),[r,i]=h.useState(!0),[l,u]=h.useState(null),d=h.useRef(!1),f=h.useCallback(async()=>{i(!0),u(null);try{const p=await ze.getServerInfo();t(p)}catch(p){u(p instanceof Error?p:new Error(String(p)))}finally{i(!1)}},[]);return h.useEffect(()=>{d.current||(d.current=!0,f())},[f]),{serverInfo:e,loading:r,error:l,refetch:f}}function j8(){const e=zT(),t=Bc(),{relayDebugEnabled:r,setRelayDebugEnabled:i}=zi(),{serverInfo:l,loading:u}=S8(),{binding:d,loading:f,applying:p,updateBinding:x}=y8(),{settings:v,isLoading:y}=py(),[S,w]=h.useState(""),[E,_]=h.useState(!1),[C,k]=h.useState(""),[O,L]=h.useState(""),[P,U]=h.useState(!1),[A,$]=h.useState(""),[H,F]=h.useState(""),[ee,de]=h.useState(!1),[Y,te]=h.useState(""),[be,Ce]=h.useState(null),[D,Z]=h.useState(!1),[V,ge]=h.useState(!1),[De,B]=h.useState(!1);if(d&&e&&v&&!De){w(String(d.localhost.port)),_(d.network.enabled),k(d.network.host??""),U(e.authEnabled);const Ae=v.allowedHosts;Ae==="*"?(de(!0),te("")):(de(!1),te(Ae??"")),B(!0)}const se=(Ae,Ke)=>Ae?"*":Ke.trim()||void 0,me=(Ae,Ke,$e,fe,Ze,jt,ve)=>{if(!d||!e||!v)return!1;const _t=Ae!==String(d.localhost.port),Me=Ke!==d.network.enabled,at=$e!==(d.network.host??""),Ht=fe!==e.authEnabled,gn=Ze.length>0,ht=se(jt,ve),Ft=v.allowedHosts;return _t||Me||at||Ht||gn||(ht??"")!==(Ft??"")},ie=Ae=>{Z(me(Ae.port??S,Ae.networkEnabled??E,Ae.iface??C,Ae.requirePw??P,Ae.password??A,Ae.allowAll??ee,Ae.hostsText??Y))},Ne=async()=>{if(!e)return;Ce(null);const Ae=Number.parseInt(S,10);if(Number.isNaN(Ae)||Ae<1||Ae>65535){Ce("Port must be a number between 1 and 65535");return}const Ke=P&&!e.authEnabled,$e=P&&e.authEnabled&&A.length>0;if(Ke||$e){if(A.length<6){Ce("Password must be at least 6 characters");return}if(A!==H){Ce("Passwords do not match");return}}const fe=C==="custom"?O:C;ge(!0);try{const Ze=await x({localhostPort:Ae,network:{enabled:E,host:E?fe:void 0}});Ke?(await e.enableAuth(A),$(""),F("")):$e?(await e.changePassword(A),$(""),F("")):!P&&e.authEnabled&&await e.disableAuth();const jt=se(ee,Y);if(await ze.updateServerSettings({allowedHosts:jt??""}),Ze.redirectUrl){const ve=new URL(Ze.redirectUrl);ve.pathname=window.location.pathname,ve.search=window.location.search,window.location.href=ve.toString()}else Z(!1)}catch(Ze){Ce(Ze instanceof Error?Ze.message:"Failed to apply changes")}finally{ge(!1)}};if(e){if(u||f||y||e.isLoading||!De)return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Local Access"}),a.jsx("p",{className:"settings-section-description",children:"Loading..."})]});const Ke=P;return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Local Access"}),a.jsx("p",{className:"settings-section-description",children:"Control how this server is accessed on your local network."}),a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Status"}),a.jsx("p",{children:l?(()=>{const $e=d==null?void 0:d.network.host,fe=(d==null?void 0:d.network.port)??l.port,Ze=$e==="0.0.0.0"||$e==="::",jt=fe===l.port;return d!=null&&d.network.enabled&&Ze&&jt?a.jsxs(a.Fragment,{children:["Listening on"," ",a.jsxs("code",{children:[$e,":",fe]})]}):a.jsxs(a.Fragment,{children:["Listening on"," ",a.jsxs("code",{children:[l.host,":",l.port]}),(d==null?void 0:d.network.enabled)&&$e&&a.jsxs(a.Fragment,{children:[" ","and"," ",a.jsxs("code",{children:[$e,":",fe]})]})]})})():"Unable to fetch server info"})]}),(l==null?void 0:l.localhostOnly)&&!(d!=null&&d.network.enabled)&&a.jsx("span",{className:"settings-status-badge settings-status-detected",children:"Local Only"}),((l==null?void 0:l.boundToAllInterfaces)||(d==null?void 0:d.network.enabled))&&!e.authEnabled&&a.jsx("span",{className:"settings-status-badge settings-status-warning",children:"Network Exposed"})]})}),a.jsxs("form",{className:"settings-group",onSubmit:$e=>{$e.preventDefault(),Ne()},children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Listening Port"}),a.jsx("p",{children:"Port used for all network access"})]}),d!=null&&d.localhost.overriddenByCli?a.jsxs("span",{className:"settings-value-readonly",children:[d.localhost.port," ",a.jsx("span",{className:"settings-hint",children:"(set via --port)"})]}):a.jsx("input",{type:"number",className:"settings-input-small",value:S,onChange:$e=>{w($e.target.value),ie({port:$e.target.value})},min:1,max:65535,autoComplete:"off"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Local Network Access"}),a.jsx("p",{children:"Allow access from other devices on your network"})]}),d!=null&&d.network.overriddenByCli?a.jsxs("span",{className:"settings-value-readonly",children:[d.network.host,":",d.network.port," ",a.jsx("span",{className:"settings-hint",children:"(set via --host)"})]}):a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:E,onChange:$e=>{_($e.target.checked),ie({networkEnabled:$e.target.checked})}}),a.jsx("span",{className:"toggle-slider"})]})]}),E&&!(d!=null&&d.network.overriddenByCli)&&d&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Interface"}),a.jsx("p",{children:"Select which network interface to bind to"})]}),a.jsx(Ra,{label:"Interface",placeholder:"Select interface...",multiSelect:!1,align:"right",options:[...d.interfaces.map($e=>({value:$e.address,label:$e.displayName})),{value:"0.0.0.0",label:"All interfaces (0.0.0.0)"},{value:"custom",label:"Custom IP..."}],selected:C?[C]:[],onChange:$e=>{const fe=$e[0]??"";k(fe),ie({iface:fe})}})]}),E&&!(d!=null&&d.network.overriddenByCli)&&C==="custom"&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Custom IP"}),a.jsx("p",{children:"Enter the IP address to bind to"})]}),a.jsx("input",{type:"text",className:"settings-input",placeholder:"192.168.1.100",value:O,onChange:$e=>L($e.target.value)})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Allow All Hostnames"}),a.jsx("p",{children:"Accept requests from any hostname (disables DNS rebinding protection)"})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:ee,onChange:$e=>{de($e.target.checked),ie({allowAll:$e.target.checked})}}),a.jsx("span",{className:"toggle-slider"})]})]}),!ee&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Allowed Hostnames"}),a.jsx("p",{children:"Comma-separated list of additional allowed hostnames"})]}),a.jsx("input",{type:"text",className:"settings-input",placeholder:"mydomain.com, other.example.com",value:Y,onChange:$e=>{te($e.target.value),ie({hostsText:$e.target.value})}})]}),a.jsx("p",{className:"form-hint",children:"localhost, private IPs, and *.ts.net are always allowed."}),!e.authDisabledByEnv&&a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Require Password"}),a.jsx("p",{children:"Require a password to access this server"})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:P,onChange:$e=>{U($e.target.checked),ie({requirePw:$e.target.checked})}}),a.jsx("span",{className:"toggle-slider"})]})]}),Ke&&a.jsxs(a.Fragment,{children:[a.jsx("input",{type:"text",name:"username",autoComplete:"username",style:{position:"absolute",visibility:"hidden",pointerEvents:"none"},tabIndex:-1}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Password"}),a.jsx("p",{children:e.authEnabled?"Leave blank to keep current":"At least 6 characters"})]}),a.jsx("input",{type:"password",className:"settings-input",value:A,onChange:$e=>{$($e.target.value),ie({password:$e.target.value})},autoComplete:"new-password",placeholder:e.authEnabled?"New password":"Enter password"})]}),A.length>0&&a.jsxs("div",{className:"settings-item",children:[a.jsx("div",{className:"settings-item-info",children:a.jsx("strong",{children:"Confirm Password"})}),a.jsx("input",{type:"password",className:"settings-input",value:H,onChange:$e=>F($e.target.value),autoComplete:"new-password",placeholder:"Confirm password"})]}),!e.authEnabled&&a.jsxs("p",{className:"form-hint",children:["If you forget your password, restart with"," ",a.jsx("code",{children:"--auth-disable"})," to bypass auth."]})]}),e.authDisabledByEnv&&a.jsx("p",{className:"form-warning",children:"Authentication is bypassed by --auth-disable flag."}),a.jsxs("div",{className:"settings-item",children:[be&&a.jsx("p",{className:"form-error",children:be}),a.jsx("button",{type:"submit",className:"settings-button",disabled:!D||V||p,children:V||p?"Applying...":"Apply Changes"})]})]}),e.authEnabled&&e.isAuthenticated&&a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Logout"}),a.jsx("p",{children:"Sign out on this device"})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:e.logout,children:"Logout"})]})})]})}return t?a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Local Access"}),a.jsx("p",{className:"settings-section-description",children:"You are connected to a remote server via relay."}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Logout"}),a.jsx("p",{children:"Disconnect from the remote server."})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>t.disconnect(),children:"Logout"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Relay Debug Logging"}),a.jsx("p",{children:"Log relay requests and responses to the browser console. Useful for debugging connection timeouts."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:r,onChange:Ae=>i(Ae.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]})]})]}):null}function w8(){const{model:e,setModel:t,thinkingLevel:r,setThinkingLevel:i}=Ic();return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Model"}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Model"}),a.jsx("p",{children:"Select which Claude model to use for new sessions."})]}),a.jsx("div",{className:"font-size-selector",children:Uf.map(l=>a.jsx("button",{type:"button",className:`font-size-option ${e===l.value?"active":""}`,onClick:()=>t(l.value),children:l.label},l.value))})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Thinking Level"}),a.jsx("p",{children:"Token budget for extended thinking. Higher levels enable deeper reasoning but use more tokens."})]}),a.jsx("div",{className:"font-size-selector",children:hT.map(l=>a.jsxs("button",{type:"button",className:`font-size-option ${r===l.value?"active":""}`,onClick:()=>i(l.value),title:l.description,children:[l.label," (",l.description,")"]},l.value))})]})]})]})}function xy(){const[e,t]=h.useState(()=>{const l=typeof window<"u"&&"Notification"in window,u=yT();return{isSupported:l&&!u,isMobile:u,permission:l?Notification.permission:"denied",isRequesting:!1}});h.useEffect(()=>{if(!e.isSupported)return;const l=()=>{const u=Notification.permission;u!==e.permission&&t(d=>({...d,permission:u}))};return window.addEventListener("focus",l),()=>window.removeEventListener("focus",l)},[e.isSupported,e.permission]);const r=h.useCallback(async()=>{if(e.isSupported&&e.permission!=="granted"){t(l=>({...l,isRequesting:!0}));try{const l=await Notification.requestPermission();t(u=>({...u,permission:l,isRequesting:!1}))}catch(l){console.error("[useBrowserNotifications] Permission request failed:",l),t(u=>({...u,isRequesting:!1}))}}},[e.isSupported,e.permission]),i=h.useCallback((l,u)=>{if(!e.isSupported||e.permission!=="granted")return!1;try{return new Notification(l,u),!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:r,showNotification:i}}function N8(){const{isSupported:e,isMobile:t,isEnabled:r,isDenied:i,isRequesting:l,requestPermission:u,showNotification:d}=xy();if(t)return null;if(!e)return a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{children:"Notifications are not supported in this browser."})]})});if(i)return a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{className:"settings-warning",children:"Notifications are blocked. Enable them in your browser settings to receive desktop alerts."})]})});if(r){const f=()=>{d("Test Notification",{body:"Desktop notifications are working!",icon:"/icon-192.png"})};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{children:"Enabled. You'll receive notifications when sessions need attention (while the tab is open)."})]}),a.jsx("span",{className:"settings-badge settings-badge-success",children:"Enabled"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Test Desktop Notification"}),a.jsx("p",{children:"Send a test notification to verify it's working."})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:f,children:"Send Test"})]})]})}return a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Desktop Notifications"}),a.jsx("p",{children:"Get notified when sessions need your attention. Works while the tab is open in the background."})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:u,disabled:l,children:l?"Requesting...":"Enable"})]})}function _8(){const{isSupported:e,isSubscribed:t,isLoading:r,error:i,permission:l,subscribe:u,unsubscribe:d,sendTest:f}=wh(),{notifyInApp:p,setNotifyInApp:x}=GT(),[v,y]=h.useState("normal"),S=async()=>{t?await d():await u()};if(!e){const w=i==null?void 0:i.includes("Service worker disabled in dev mode");return a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Push Notifications"}),a.jsx("p",{children:i||"Push notifications are not supported in this browser."}),w&&a.jsxs("div",{className:"settings-info-box",style:{marginTop:"0.5rem"},children:[a.jsxs("p",{children:["This only affects ",a.jsx("strong",{children:"this device"}),". Other subscribed devices will still receive notifications from the server."]}),a.jsxs("p",{children:["To enable push on this device in dev mode, restart with"," ",a.jsx("code",{children:"VITE_ENABLE_SW=true"}),"."]})]}),a.jsx("p",{style:{marginTop:"0.5rem"},children:a.jsx("a",{href:"https://github.com/kzahel/yepanywhere/blob/main/docs/push-notifications.md",target:"_blank",rel:"noopener noreferrer",children:"Troubleshooting guide"})})]})})}return l==="denied"?a.jsx("div",{className:"settings-item",children:a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Push Notifications"}),a.jsx("p",{className:"settings-warning",children:"Notifications are blocked. Enable them in your browser settings to receive push notifications."})]})}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Push Notifications"}),a.jsx("p",{children:"Receive notifications when a session needs your attention, even when the app is in the background."}),i&&a.jsx("p",{className:"settings-error",children:i})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:t,onChange:S,disabled:r}),a.jsx("span",{className:"toggle-slider"})]})]}),t&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Notify When In App"}),a.jsx("p",{children:"Show notifications even when the app is open, as long as you're not viewing that session."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:p,onChange:w=>x(w.target.checked)}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Test Notification"}),a.jsx("p",{children:"Send a test notification to verify push is working."})]}),a.jsxs("div",{className:"settings-item-actions",children:[a.jsxs("select",{className:"settings-select",value:v,onChange:w=>y(w.target.value),disabled:r,children:[a.jsx("option",{value:"normal",children:"Normal (auto-dismiss)"}),a.jsx("option",{value:"persistent",children:"Persistent (stays visible)"}),a.jsx("option",{value:"silent",children:"Silent (no sound)"})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:()=>f(v),disabled:r,children:r?"Sending...":"Send Test"})]})]})]})]})}function E8(){const[e,t]=h.useState({settings:null,isLoading:!0,error:null});h.useEffect(()=>{(async()=>{try{const{settings:l}=await ze.getNotificationSettings();t({settings:l,isLoading:!1,error:null})}catch(l){console.error("[useNotificationSettings] Failed to fetch:",l),t(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to load settings"}))}})()},[]);const r=h.useCallback(async(i,l)=>{t(u=>({...u,isLoading:!0,error:null}));try{const{settings:u}=await ze.updateNotificationSettings({[i]:l});t({settings:u,isLoading:!1,error:null})}catch(u){console.error("[useNotificationSettings] Failed to update:",u),t(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to update"}))}},[]);return{...e,updateSetting:r}}function C8(){const[e,t]=h.useState({devices:[],isLoading:!0,error:null}),r=h.useCallback(async()=>{t(l=>({...l,isLoading:!0,error:null}));try{const{subscriptions:l}=await ze.getPushSubscriptions();t({devices:l,isLoading:!1,error:null})}catch(l){console.error("[useSubscribedDevices] Failed to fetch:",l),t(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to load devices"}))}},[]);h.useEffect(()=>{r()},[r]);const i=h.useCallback(async l=>{t(u=>({...u,isLoading:!0,error:null}));try{await ze.deletePushSubscription(l),await r()}catch(u){console.error("[useSubscribedDevices] Failed to remove:",u),t(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to remove device"}))}},[r]);return{...e,removeDevice:i,refetch:r}}function k8(e,t){const r=e||"Unknown device";return t!=null&&t.includes("google")?{displayName:r,browserType:"(Android/Chrome)"}:t!=null&&t.includes("apple")||t!=null&&t.includes("push.apple")?{displayName:r,browserType:"(iOS/Safari)"}:t!=null&&t.includes("mozilla")||t!=null&&t.includes("push.services.mozilla")?{displayName:r,browserType:"(Firefox)"}:{displayName:r,browserType:""}}function T8(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/(1e3*60*60*24));return l===0?"today":l===1?"yesterday":l<7?`${l} days ago`:t.toLocaleDateString()}function R8(e,t,r){const i=new Map;for(const u of e){const{displayName:d,browserType:f}=k8(u.deviceName,u.endpointDomain),p=t.get(u.browserProfileId);i.set(u.browserProfileId,{browserProfileId:u.browserProfileId,displayName:d,browserType:f,isSubscribed:!0,isConnected:!!p,tabCount:(p==null?void 0:p.connectionCount)??0,subscribedAt:u.createdAt,isCurrentDevice:u.browserProfileId===r})}for(const[u,d]of t)if(!i.has(u)){const f=u.slice(0,8);i.set(u,{browserProfileId:u,displayName:f,browserType:"",isSubscribed:!1,isConnected:!0,tabCount:d.connectionCount,isCurrentDevice:u===r})}const l=Array.from(i.values());return l.sort((u,d)=>u.isCurrentDevice&&!d.isCurrentDevice?-1:!u.isCurrentDevice&&d.isCurrentDevice?1:u.isConnected&&!d.isConnected?-1:!u.isConnected&&d.isConnected?1:u.isConnected&&d.isConnected?d.tabCount-u.tabCount:u.subscribedAt&&d.subscribedAt?new Date(d.subscribedAt).getTime()-new Date(u.subscribedAt).getTime():0),l}function A8(){const{browserProfileId:e}=wh(),{isMobile:t}=xy(),{devices:r,isLoading:i,removeDevice:l}=C8(),{connections:u,isLoading:d}=gy(),{settings:f,isLoading:p,updateSetting:x}=E8(),v=r.length>0,y=i||d,S=R8(r,u,e);return a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Server Notification Types"}),a.jsx("p",{className:"settings-section-description",children:"Control what types of events trigger push notifications to all devices."}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Tool Approvals"}),a.jsx("p",{children:"Notify when Claude needs permission to run a tool (file edits, commands, etc.)"})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.toolApproval)??!0,onChange:w=>x("toolApproval",w.target.checked),disabled:p||!v}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"User Questions"}),a.jsx("p",{children:"Notify when Claude asks a question and needs your response."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.userQuestion)??!0,onChange:w=>x("userQuestion",w.target.checked),disabled:p||!v}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Session Halted"}),a.jsx("p",{children:"Notify when a session completes, errors out, or becomes idle."})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.sessionHalted)??!0,onChange:w=>x("sessionHalted",w.target.checked),disabled:p||!v}),a.jsx("span",{className:"toggle-slider"})]})]}),!v&&!i&&a.jsx("p",{className:"settings-hint",children:"No devices subscribed. Enable push notifications below to use these settings."})]})]}),!t&&a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Desktop Notifications"}),a.jsx("p",{className:"settings-section-description",children:"Get browser notifications when sessions need attention. Works while the tab is open."}),a.jsx("div",{className:"settings-group",children:a.jsx(N8,{})})]}),a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Push Notifications"}),a.jsx("p",{className:"settings-section-description",children:"Receive push notifications even when the browser is closed or you're on another device."}),a.jsx("div",{className:"settings-group",children:a.jsx(_8,{})})]}),a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Devices"}),a.jsx("p",{className:"settings-section-description",children:"All devices connected to or subscribed to this server."}),a.jsx("div",{className:"settings-group",children:y?a.jsx("p",{className:"settings-hint",children:"Loading devices..."}):S.length===0?a.jsx("p",{className:"settings-hint",children:"No devices connected or subscribed. Enable push notifications above."}):a.jsx("div",{className:"device-list",children:S.map(w=>a.jsxs("div",{className:"device-list-item",children:[a.jsxs("div",{className:"device-list-info",children:[a.jsxs("strong",{children:[w.displayName,w.browserType&&` ${w.browserType}`,w.isCurrentDevice&&a.jsx("span",{className:"device-current-badge",children:"This device"})]}),a.jsxs("p",{children:[w.isConnected?a.jsx("span",{className:"device-status device-status-online",children:w.tabCount===1?"1 tab":`${w.tabCount} tabs`}):a.jsx("span",{className:"device-status device-status-offline",children:"Offline"}),!w.isSubscribed&&a.jsx("span",{className:"device-no-push",children:"No push"}),w.subscribedAt&&a.jsxs("span",{className:"device-subscribed-date",children:["Subscribed ",T8(w.subscribedAt)]})]})]}),w.isSubscribed&&a.jsx("button",{type:"button",className:"settings-button settings-button-danger-subtle",onClick:()=>l(w.browserProfileId),title:w.isCurrentDevice?"Unsubscribe this device":"Remove this device",children:"Remove"})]},w.browserProfileId))})})]})]})}function M8(){const{providers:e}=bh(),r=k3().map(i=>{const l=e.find(u=>u.name===i.id);return{...i,installed:(l==null?void 0:l.installed)??!1,authenticated:(l==null?void 0:l.authenticated)??!1}});return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Providers"}),a.jsx("p",{className:"settings-section-description",children:"AI providers are auto-detected when their CLI is installed."}),a.jsx("div",{className:"settings-group",children:r.map(i=>a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsxs("div",{className:"settings-item-header",children:[a.jsx("strong",{children:i.displayName}),i.installed?a.jsx("span",{className:"settings-status-badge settings-status-detected",children:"Detected"}):a.jsx("span",{className:"settings-status-badge settings-status-not-detected",children:"Not Detected"})]}),a.jsx("p",{children:i.metadata.description}),i.metadata.limitations.length>0&&a.jsx("ul",{className:"settings-limitations",children:i.metadata.limitations.map(l=>a.jsx("li",{children:l},l))})]}),i.metadata.website&&a.jsx("a",{href:i.metadata.website,target:"_blank",rel:"noopener noreferrer",className:"settings-link",children:"Website"})]},i.id))})]})}function O8(){const[e,t]=h.useState(null),[r,i]=h.useState(null),[l,u]=h.useState(null),[d,f]=h.useState([]),[p,x]=h.useState(!0),[v,y]=h.useState(null),S=h.useCallback(async()=>{try{const[U,A,$,H]=await Promise.all([Be("/remote-access/config"),Be("/remote-access/relay"),Be("/remote-access/relay/status"),Be("/remote-access/sessions")]);t(U),i(A.relay),u($),f(H.sessions),y(null)}catch(U){console.error("[useRemoteAccess] Failed to fetch config:",U),y(U instanceof Error?U.message:"Failed to fetch config")}},[]);h.useEffect(()=>{x(!0),S().finally(()=>x(!1))},[S]);const w=h.useCallback(async U=>{try{await Be("/remote-access/configure",{method:"POST",body:JSON.stringify({password:U})}),await S()}catch(A){const $=A instanceof Error?A.message:"Failed to configure remote access";throw y($),new Error($)}},[S]),E=h.useCallback(async()=>{try{await Be("/remote-access/enable",{method:"POST"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to enable remote access";throw y(A),new Error(A)}},[S]),_=h.useCallback(async()=>{try{await Be("/remote-access/disable",{method:"POST"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to disable remote access";throw y(A),new Error(A)}},[S]),C=h.useCallback(async()=>{try{await Be("/remote-access/clear",{method:"POST"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to clear remote access credentials";throw y(A),new Error(A)}},[S]),k=h.useCallback(async U=>{try{await Be("/remote-access/relay",{method:"PUT",body:JSON.stringify(U)}),await S()}catch(A){const $=A instanceof Error?A.message:"Failed to update relay configuration";throw y($),new Error($)}},[S]),O=h.useCallback(async()=>{try{await Be("/remote-access/relay",{method:"DELETE"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to clear relay configuration";throw y(A),new Error(A)}},[S]),L=h.useCallback(async U=>{try{await Be(`/remote-access/sessions/${U}`,{method:"DELETE"}),await S()}catch(A){const $=A instanceof Error?A.message:"Failed to revoke session";throw y($),new Error($)}},[S]),P=h.useCallback(async()=>{try{await Be("/remote-access/sessions",{method:"DELETE"}),await S()}catch(U){const A=U instanceof Error?U.message:"Failed to revoke all sessions";throw y(A),new Error(A)}},[S]);return{config:e,relayConfig:r,relayStatus:l,sessions:d,loading:p,error:v,configure:w,enable:E,disable:_,clearCredentials:C,updateRelayConfig:k,clearRelayConfig:O,revokeSession:L,revokeAllSessions:P,refresh:S}}var ka=(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))(ka||{}),z8=Object.defineProperty,L8=(e,t,r)=>t in e?z8(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,xc=(e,t,r)=>(L8(e,typeof t!="symbol"?t+"":t,r),r);const U8=[0,1],vy=[1,0],by=[2,3],yy=[3,2],D8={L:U8,M:vy,Q:by,H:yy},B8=/^[0-9]*$/,I8=/^[A-Z0-9 $%*+.\/:-]*$/,Nf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Nh=1,_h=40,Qv=3,$8=3,vc=40,P8=10,Sy=[[-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]],jy=[[-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 H8{constructor(t,r,i,l){if(this.version=t,this.ecc=r,xc(this,"size"),xc(this,"mask"),xc(this,"modules",[]),xc(this,"types",[]),t<Nh||t>_h)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 u=Array.from({length:this.size},()=>!1);for(let f=0;f<this.size;f++)this.modules.push(u.slice()),this.types.push(u.map(()=>0));this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),l===-1){let f=1e9;for(let p=0;p<8;p++){this.applyMask(p),this.drawFormatBits(p);const x=this.getPenaltyScore();x<f&&(l=p,f=x),this.applyMask(p)}}this.mask=l,this.applyMask(l),this.drawFormatBits(l)}getModule(t,r){return t>=0&&t<this.size&&r>=0&&r<this.size&&this.modules[r][t]}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2===0,ka.Timing),this.setFunctionModule(i,6,i%2===0,ka.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const t=this.getAlignmentPatternPositions(),r=t.length;for(let i=0;i<r;i++)for(let l=0;l<r;l++)i===0&&l===0||i===0&&l===r-1||i===r-1&&l===0||this.drawAlignmentPattern(t[i],t[l]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(t){const r=this.ecc[1]<<3|t;let i=r;for(let u=0;u<10;u++)i=i<<1^(i>>>9)*1335;const l=(r<<10|i)^21522;for(let u=0;u<=5;u++)this.setFunctionModule(8,u,Er(l,u));this.setFunctionModule(8,7,Er(l,6)),this.setFunctionModule(8,8,Er(l,7)),this.setFunctionModule(7,8,Er(l,8));for(let u=9;u<15;u++)this.setFunctionModule(14-u,8,Er(l,u));for(let u=0;u<8;u++)this.setFunctionModule(this.size-1-u,8,Er(l,u));for(let u=8;u<15;u++)this.setFunctionModule(8,this.size-15+u,Er(l,u));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 r=this.version<<12|t;for(let i=0;i<18;i++){const l=Er(r,i),u=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(u,d,l),this.setFunctionModule(d,u,l)}}drawFinderPattern(t,r){for(let i=-4;i<=4;i++)for(let l=-4;l<=4;l++){const u=Math.max(Math.abs(l),Math.abs(i)),d=t+l,f=r+i;d>=0&&d<this.size&&f>=0&&f<this.size&&this.setFunctionModule(d,f,u!==2&&u!==4,ka.Position)}}drawAlignmentPattern(t,r){for(let i=-2;i<=2;i++)for(let l=-2;l<=2;l++)this.setFunctionModule(t+l,r+i,Math.max(Math.abs(l),Math.abs(i))!==1,ka.Alignment)}setFunctionModule(t,r,i,l=ka.Function){this.modules[r][t]=i,this.types[r][t]=l}addEccAndInterleave(t){const r=this.version,i=this.ecc;if(t.length!==jc(r,i))throw new RangeError("Invalid argument");const l=jy[i[0]][r],u=Sy[i[0]][r],d=Math.floor(Hf(r)/8),f=l-d%l,p=Math.floor(d/l),x=[],v=K8(u);for(let S=0,w=0;S<l;S++){const E=t.slice(w,w+p-u+(S<f?0:1));w+=E.length;const _=J8(E,v);S<f&&E.push(0),x.push(E.concat(_))}const y=[];for(let S=0;S<x[0].length;S++)x.forEach((w,E)=>{(S!==p-u||E>=f)&&y.push(w[S])});return y}drawCodewords(t){if(t.length!==Math.floor(Hf(this.version)/8))throw new RangeError("Invalid argument");let r=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 u=0;u<2;u++){const d=i-u,p=(i+1&2)===0?this.size-1-l:l;!this.types[p][d]&&r<t.length*8&&(this.modules[p][d]=Er(t[r>>>3],7-(r&7)),r++)}}}applyMask(t){if(t<0||t>7)throw new RangeError("Mask value out of range");for(let r=0;r<this.size;r++)for(let i=0;i<this.size;i++){let l;switch(t){case 0:l=(i+r)%2===0;break;case 1:l=r%2===0;break;case 2:l=i%3===0;break;case 3:l=(i+r)%3===0;break;case 4:l=(Math.floor(i/3)+Math.floor(r/2))%2===0;break;case 5:l=i*r%2+i*r%3===0;break;case 6:l=(i*r%2+i*r%3)%2===0;break;case 7:l=((i+r)%2+i*r%3)%2===0;break;default:throw new Error("Unreachable")}!this.types[r][i]&&l&&(this.modules[r][i]=!this.modules[r][i])}}getPenaltyScore(){let t=0;for(let u=0;u<this.size;u++){let d=!1,f=0;const p=[0,0,0,0,0,0,0];for(let x=0;x<this.size;x++)this.modules[u][x]===d?(f++,f===5?t+=Qv:f>5&&t++):(this.finderPenaltyAddHistory(f,p),d||(t+=this.finderPenaltyCountPatterns(p)*vc),d=this.modules[u][x],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,p)*vc}for(let u=0;u<this.size;u++){let d=!1,f=0;const p=[0,0,0,0,0,0,0];for(let x=0;x<this.size;x++)this.modules[x][u]===d?(f++,f===5?t+=Qv:f>5&&t++):(this.finderPenaltyAddHistory(f,p),d||(t+=this.finderPenaltyCountPatterns(p)*vc),d=this.modules[x][u],f=1);t+=this.finderPenaltyTerminateAndCount(d,f,p)*vc}for(let u=0;u<this.size-1;u++)for(let d=0;d<this.size-1;d++){const f=this.modules[u][d];f===this.modules[u][d+1]&&f===this.modules[u+1][d]&&f===this.modules[u+1][d+1]&&(t+=$8)}let r=0;for(const u of this.modules)r=u.reduce((d,f)=>d+(f?1:0),r);const i=this.size*this.size,l=Math.ceil(Math.abs(r*20-i*10)/i)-1;return t+=l*P8,t}getAlignmentPatternPositions(){if(this.version===1)return[];{const t=Math.floor(this.version/7)+2,r=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-=r)i.splice(1,0,l);return i}}finderPenaltyCountPatterns(t){const r=t[1],i=r>0&&t[2]===r&&t[3]===r*3&&t[4]===r&&t[5]===r;return(i&&t[0]>=r*4&&t[6]>=r?1:0)+(i&&t[6]>=r*4&&t[0]>=r?1:0)}finderPenaltyTerminateAndCount(t,r,i){return t&&(this.finderPenaltyAddHistory(r,i),r=0),r+=this.size,this.finderPenaltyAddHistory(r,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(t,r){r[0]===0&&(t+=this.size),r.pop(),r.unshift(t)}}function kr(e,t,r){if(t<0||t>31||e>>>t)throw new RangeError("Value out of range");for(let i=t-1;i>=0;i--)r.push(e>>>i&1)}function Er(e,t){return(e>>>t&1)!==0}class Eh{constructor(t,r,i){if(this.mode=t,this.numChars=r,this.bitData=i,r<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}getData(){return this.bitData.slice()}}const F8=[1,10,12,14],q8=[2,9,11,13],Z8=[4,8,16,16];function wy(e,t){return e[Math.floor((t+7)/17)+1]}function Ny(e){const t=[];for(const r of e)kr(r,8,t);return new Eh(Z8,e.length,t)}function V8(e){if(!_y(e))throw new RangeError("String contains non-numeric characters");const t=[];for(let r=0;r<e.length;){const i=Math.min(e.length-r,3);kr(Number.parseInt(e.substring(r,r+i),10),i*3+1,t),r+=i}return new Eh(F8,e.length,t)}function G8(e){if(!Ey(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");const t=[];let r;for(r=0;r+2<=e.length;r+=2){let i=Nf.indexOf(e.charAt(r))*45;i+=Nf.indexOf(e.charAt(r+1)),kr(i,11,t)}return r<e.length&&kr(Nf.indexOf(e.charAt(r)),6,t),new Eh(q8,e.length,t)}function Y8(e){return e===""?[]:_y(e)?[V8(e)]:Ey(e)?[G8(e)]:[Ny(X8(e))]}function _y(e){return B8.test(e)}function Ey(e){return I8.test(e)}function W8(e,t){let r=0;for(const i of e){const l=wy(i.mode,t);if(i.numChars>=1<<l)return Number.POSITIVE_INFINITY;r+=4+l+i.bitData.length}return r}function X8(e){e=encodeURI(e);const t=[];for(let r=0;r<e.length;r++)e.charAt(r)!=="%"?t.push(e.charCodeAt(r)):(t.push(Number.parseInt(e.substring(r+1,r+3),16)),r+=2);return t}function Hf(e){if(e<Nh||e>_h)throw new RangeError("Version number out of range");let t=(16*e+128)*e+64;if(e>=2){const r=Math.floor(e/7)+2;t-=(25*r-10)*r-55,e>=7&&(t-=36)}return t}function jc(e,t){return Math.floor(Hf(e)/8)-Sy[t[0]][e]*jy[t[0]][e]}function K8(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 r=1;for(let i=0;i<e;i++){for(let l=0;l<t.length;l++)t[l]=Ff(t[l],r),l+1<t.length&&(t[l]^=t[l+1]);r=Ff(r,2)}return t}function J8(e,t){const r=t.map(i=>0);for(const i of e){const l=i^r.shift();r.push(0),t.forEach((u,d)=>r[d]^=Ff(u,l))}return r}function Ff(e,t){if(e>>>8||t>>>8)throw new RangeError("Byte out of range");let r=0;for(let i=7;i>=0;i--)r=r<<1^(r>>>7)*285,r^=(t>>>i&1)*e;return r}function Q8(e,t,r=1,i=40,l=-1,u=!0){if(!(Nh<=r&&r<=i&&i<=_h)||l<-1||l>7)throw new RangeError("Invalid value");let d,f;for(d=r;;d++){const y=jc(d,t)*8,S=W8(e,d);if(S<=y){f=S;break}if(d>=i)throw new RangeError("Data too long")}for(const y of[vy,by,yy])u&&f<=jc(d,y)*8&&(t=y);const p=[];for(const y of e){kr(y.mode[0],4,p),kr(y.numChars,wy(y.mode,d),p);for(const S of y.getData())p.push(S)}const x=jc(d,t)*8;kr(0,Math.min(4,x-p.length),p),kr(0,(8-p.length%8)%8,p);for(let y=236;p.length<x;y^=253)kr(y,8,p);const v=Array.from({length:Math.ceil(p.length/8)},()=>0);return p.forEach((y,S)=>v[S>>>3]|=y<<7-(S&7)),new H8(d,t,v,l)}function eM(e,t){const{ecc:r="L",boostEcc:i=!1,minVersion:l=1,maxVersion:u=40,maskPattern:d=-1,border:f=1}={},p=typeof e=="string"?Y8(e):Array.isArray(e)?[Ny(e)]:void 0;if(!p)throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);const x=Q8(p,D8[r],l,u,d,i);return tM({version:x.version,maskPattern:x.mask,size:x.size,data:x.modules,types:x.types},f)}function tM(e,t=1){if(!t)return e;const{size:r}=e,i=r+t*2;e.size=i,e.data.forEach(u=>{for(let d=0;d<t;d++)u.unshift(!1),u.push(!1)});for(let u=0;u<t;u++)e.data.unshift(Array.from({length:i},d=>!1)),e.data.push(Array.from({length:i},d=>!1));const l=ka.Border;e.types.forEach(u=>{for(let d=0;d<t;d++)u.unshift(l),u.push(l)});for(let u=0;u<t;u++)e.types.unshift(Array.from({length:i},d=>l)),e.types.push(Array.from({length:i},d=>l));return e}function nM({value:e,size:t=200,color:r="#000000",bgColor:i="#ffffff"}){const{data:l}=eM(e),u=l.length,d=t/u;let f="";for(let p=0;p<u;p++){const x=l[p];if(x){for(let v=0;v<u;v++)if(x[v]){const y=v*d,S=p*d;f+=`M${y},${S}h${d}v${d}h-${d}z`}}}return a.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:[a.jsx("rect",{width:t,height:t,fill:i}),a.jsx("path",{d:f,fill:r})]})}const gi="wss://relay.yepanywhere.com/ws",_f="https://yepanywhere.com/remote/login/relay";function e0(e){const t=new Date(e),i=new Date().getTime()-t.getTime(),l=Math.floor(i/(1e3*60)),u=Math.floor(i/(1e3*60*60)),d=Math.floor(i/(1e3*60*60*24));return l<1?"just now":l<60?`${l} minute${l===1?"":"s"} ago`:u<24?`${u} hour${u===1?"":"s"} ago`:d===1?"yesterday":d<7?`${d} days ago`:t.toLocaleDateString()}function sM(e,t,r){if(!t)return{text:"Disabled",className:"status-disabled"};if(!r)return{text:"Not configured",className:"status-warning"};switch(e){case"waiting":return{text:"Connected",className:"status-success"};case"connecting":return{text:"Connecting...",className:"status-pending"};case"registering":return{text:"Registering...",className:"status-pending"};case"rejected":return{text:"Username taken",className:"status-error"};default:return{text:"Disconnected",className:"status-warning"}}}function rM({title:e="Remote Access",description:t="Access your server from anywhere.",onSetupComplete:r}){const{config:i,relayConfig:l,relayStatus:u,sessions:d,loading:f,error:p,configure:x,enable:v,disable:y,updateRelayConfig:S,revokeSession:w,revokeAllSessions:E,refresh:_}=O8(),[C,k]=h.useState(""),[O,L]=h.useState(""),[P,U]=h.useState(""),[A,$]=h.useState("default"),[H,F]=h.useState(""),[ee,de]=h.useState(!1),[Y,te]=h.useState(null),[be,Ce]=h.useState(!1),[D,Z]=h.useState(!1),[V,ge]=h.useState(null),[De,B]=h.useState(!1);h.useEffect(()=>{l&&(k(l.username),l.url===gi?($("default"),F("")):($("custom"),F(l.url)))},[l]),h.useEffect(()=>{const Me=C!==((l==null?void 0:l.username)??""),at=O.length>0,Ht=A==="default"?gi:H,gn=(l==null?void 0:l.url)??gi;Z(Me||at||Ht!==gn)},[C,O,A,H,l]),h.useEffect(()=>{if((u==null?void 0:u.status)==="connecting"||(u==null?void 0:u.status)==="registering"){const Me=setInterval(_,2e3);return()=>clearInterval(Me)}},[u==null?void 0:u.status,_]);const se=(i==null?void 0:i.enabled)??!1,me=!!(i!=null&&i.username),ie=()=>A==="default"?gi:H,Ne=async()=>{if(te(null),!C.trim())return te("Username is required"),!1;if(C.length<3)return te("Username must be at least 3 characters"),!1;if(!me&&!O)return te("Password is required"),!1;if(O&&O.length<8)return te("Password must be at least 8 characters"),!1;if(O&&O!==P)return te("Passwords do not match"),!1;if(A==="custom"&&!H.trim())return te("Custom relay URL is required"),!1;try{const Me=ie();return(C!==(l==null?void 0:l.username)||Me!==(l==null?void 0:l.url))&&await S({url:Me,username:C}),O&&(await x(O),ge(O)),L(""),U(""),Z(!1),!0}catch(Me){return te(Me instanceof Error?Me.message:"Failed to save"),!1}},Ae=async Me=>{te(null),de(!0);try{if(Me)if(D){if(!await Ne()){de(!1);return}r==null||r()}else me&&(await v(),r==null||r());else await y()}catch(at){te(at instanceof Error?at.message:"Failed to update")}finally{de(!1)}},Ke=async Me=>{Me.preventDefault(),de(!0),await Ne()&&(r==null||r()),de(!1)},$e=async Me=>{await navigator.clipboard.writeText(Me),Ce(!0),setTimeout(()=>Ce(!1),2e3)};if(f)return a.jsxs("div",{className:"remote-access-setup",children:[a.jsx("div",{className:"remote-access-header",children:a.jsxs("div",{children:[a.jsx("h3",{children:e}),a.jsx("p",{children:t})]})}),a.jsx("div",{className:"remote-access-loading",children:"Loading..."})]});const fe=sM((u==null?void 0:u.status)??null,se,me),Ze=(()=>{const Me=new URLSearchParams;C&&Me.set("u",C);const at=ie();at!==gi&&Me.set("r",at);const Ht=Me.toString();return Ht?`${_f}?${Ht}`:_f})(),jt=(()=>{if(!V||!C)return null;const Me=new URLSearchParams;Me.set("u",C),Me.set("p",V);const at=ie();return at!==gi&&Me.set("r",at),`${_f}#${Me.toString()}`})(),ve=se&&(u==null?void 0:u.status)==="waiting"&&jt!==null,_t=me||C&&O;return a.jsxs("div",{className:"remote-access-setup",children:[a.jsxs("div",{className:"remote-access-header",children:[a.jsxs("div",{children:[a.jsx("h3",{children:e}),a.jsx("p",{children:t})]}),a.jsxs("label",{className:"toggle-switch",children:[a.jsx("input",{type:"checkbox",checked:se,onChange:Me=>Ae(Me.target.checked),disabled:ee||!se&&!_t}),a.jsx("span",{className:"toggle-slider"})]})]}),a.jsxs("form",{onSubmit:Ke,className:"remote-access-form",children:[a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"remote-username",children:"Username"}),a.jsx("input",{id:"remote-username",type:"text",value:C,onChange:Me=>k(Me.target.value.toLowerCase()),placeholder:"my-server",minLength:3,maxLength:32,pattern:"[a-z0-9][a-z0-9-]*[a-z0-9]|[a-z0-9]{1,2}",title:"Lowercase letters, numbers, and hyphens only",autoComplete:"username",disabled:ee})]}),a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"remote-password",children:me?"New Password (leave blank to keep)":"Password"}),a.jsx("input",{id:"remote-password",type:"password",value:O,onChange:Me=>L(Me.target.value),placeholder:me?"••••••••":"",minLength:8,autoComplete:"new-password",disabled:ee})]}),O&&a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"remote-confirm",children:"Confirm Password"}),a.jsx("input",{id:"remote-confirm",type:"password",value:P,onChange:Me=>U(Me.target.value),minLength:8,autoComplete:"new-password",disabled:ee})]}),a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"relay-select",children:"Relay Server"}),a.jsxs("select",{id:"relay-select",value:A,onChange:Me=>$(Me.target.value),disabled:ee,className:"form-select",children:[a.jsx("option",{value:"default",children:"Default"}),a.jsx("option",{value:"custom",children:"Custom"})]})]}),A==="custom"&&a.jsxs("div",{className:"form-field",children:[a.jsx("label",{htmlFor:"custom-relay-url",children:"Custom Relay URL"}),a.jsx("input",{id:"custom-relay-url",type:"text",value:H,onChange:Me=>F(Me.target.value),placeholder:"wss://your-relay.example.com/ws",disabled:ee})]}),a.jsxs("div",{className:"remote-access-status",children:[a.jsx("span",{className:"status-label",children:"Status:"}),a.jsx("span",{className:`status-indicator ${fe.className}`,children:fe.text}),(u==null?void 0:u.error)&&a.jsx("span",{className:"status-error-detail",children:u.error})]}),(Y||p)&&a.jsx("p",{className:"form-error",children:Y||p}),se&&C&&a.jsxs("div",{className:"remote-access-connect",children:[a.jsx("span",{className:"connect-label",children:"Connect from:"}),a.jsxs("div",{className:"connect-url-row",children:[a.jsx("code",{className:"connect-url",children:Ze}),a.jsx("button",{type:"button",className:"copy-button",onClick:()=>$e(Ze),title:"Copy URL",children:be?"Copied!":"Copy"})]})]}),ve&&a.jsxs("div",{className:"remote-access-qr",children:[a.jsx("button",{type:"button",className:"qr-toggle-button",onClick:()=>B(!De),children:De?"Hide QR Code":"Show QR Code"}),De&&jt&&a.jsxs("div",{className:"qr-code-container",children:[a.jsx(nM,{value:jt,size:200}),a.jsx("p",{className:"qr-code-hint",children:"Scan to connect and auto-login from your phone"})]})]}),a.jsxs("div",{className:"remote-access-sessions",children:[a.jsxs("div",{className:"sessions-header",children:[a.jsxs("span",{className:"sessions-title",children:["Sessions (",d.length,")"]}),d.length>0&&a.jsx("button",{type:"button",className:"revoke-all-button",onClick:()=>E(),disabled:ee,children:"Revoke All"})]}),d.length===0?a.jsx("p",{className:"sessions-empty",children:"No sessions"}):a.jsx("ul",{className:"sessions-list",children:d.map(Me=>{const{browser:at,os:Ht}=Me.userAgent?vb(Me.userAgent):{browser:"Unknown",os:"Unknown"},gn=Me.userAgent||Me.origin;return a.jsxs("li",{className:"session-item",children:[a.jsx("div",{className:"session-info",children:gn?a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"session-device",children:[at," · ",Ht]}),Me.origin&&a.jsx("code",{className:"session-origin",children:Me.origin}),a.jsxs("span",{className:"session-dates",children:["Created ",e0(Me.createdAt)," · Last used ",e0(Me.lastUsed)]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"session-created",children:["Created:"," ",new Date(Me.createdAt).toLocaleDateString()]}),a.jsxs("span",{className:"session-last-used",children:["Last used:"," ",new Date(Me.lastUsed).toLocaleDateString()]})]})}),a.jsx("button",{type:"button",className:"revoke-button",onClick:()=>w(Me.sessionId),disabled:ee,children:"Revoke"})]},Me.sessionId)})})]}),a.jsx("div",{className:"remote-access-actions",children:a.jsx("button",{type:"submit",className:"settings-button",disabled:ee||!D,children:ee?"Saving...":"Save"})})]})]})}function aM(){const e=ds(),t=Bc(),r=()=>{t==null||t.disconnect(),e("/login")};if(t){const i=t.currentHostId?dT(t.currentHostId):null,l=(i==null?void 0:i.displayName)||t.storedUsername||"Remote server";return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Remote Access"}),a.jsx("p",{className:"settings-section-description",children:"You are connected to a remote server via relay."}),a.jsxs("div",{className:"settings-group",children:[a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Current Host"}),a.jsx("p",{children:l})]}),a.jsx("button",{type:"button",className:"settings-button",onClick:r,children:"Switch Host"})]}),a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Logout"}),a.jsx("p",{children:"Disconnect from the remote server"})]}),a.jsx("button",{type:"button",className:"settings-button settings-button-danger",onClick:()=>t.disconnect(),children:"Logout"})]})]})]})}return a.jsx("section",{className:"settings-section",children:a.jsx(rM,{title:"Remote Access",description:"Access your yepanywhere server from anywhere through an encrypted relay connection."})})}function iM(){const{executors:e,loading:t,addExecutor:r,removeExecutor:i,testExecutor:l}=Hb(),[u,d]=h.useState(""),[f,p]=h.useState(!1),[x,v]=h.useState(null),[y,S]=h.useState({}),w=async()=>{if(!(!u.trim()||f)){p(!0),v(null);try{await r(u.trim()),d("")}catch(k){v(k instanceof Error?k.message:"Failed to add executor")}finally{p(!1)}}},E=async k=>{try{await i(k),S(O=>{const{[k]:L,...P}=O;return P})}catch(O){console.error("Failed to remove executor:",O)}},_=async k=>{S(O=>({...O,[k]:{testing:!0}}));try{const O=await l(k);S(L=>({...L,[k]:{testing:!1,result:O}}))}catch(O){S(L=>({...L,[k]:{testing:!1,result:{success:!1,error:O instanceof Error?O.message:"Connection failed"}}}))}},C=k=>{k.key==="Enter"&&(k.preventDefault(),w())};return a.jsxs("section",{className:"settings-section",children:[a.jsx("h2",{children:"Remote Executors"}),a.jsx("p",{className:"settings-section-description",children:"Run Claude sessions on remote machines via SSH. Add SSH host aliases from your ~/.ssh/config file."}),a.jsx("div",{className:"settings-group",children:a.jsxs("div",{className:"settings-item",children:[a.jsxs("div",{className:"settings-item-info",children:[a.jsx("strong",{children:"Add Remote Executor"}),a.jsx("p",{children:'Enter an SSH host alias (e.g., "devbox", "gpu-server")'})]}),a.jsxs("div",{className:"remote-executor-add",children:[a.jsx("input",{type:"text",value:u,onChange:k=>d(k.target.value),onKeyDown:C,placeholder:"SSH host alias",disabled:f,className:"remote-executor-input"}),a.jsx("button",{type:"button",onClick:w,disabled:!u.trim()||f,className:"remote-executor-add-button",children:f?"Adding...":"Add"})]}),x&&a.jsx("p",{className:"settings-error",children:x})]})}),a.jsxs("div",{className:"settings-group",children:[a.jsx("h3",{children:"Configured Executors"}),t?a.jsx("p",{className:"settings-loading",children:"Loading..."}):e.length===0?a.jsx("p",{className:"settings-empty",children:"No remote executors configured. Add one above to run sessions on remote machines."}):a.jsx("div",{className:"remote-executor-list",children:e.map(k=>{var L;const O=y[k];return a.jsxs("div",{className:"remote-executor-item",children:[a.jsxs("div",{className:"remote-executor-item-info",children:[a.jsx("span",{className:"remote-executor-host",children:k}),(O==null?void 0:O.result)&&a.jsx("span",{className:`settings-status-badge ${O.result.success?"settings-status-detected":"settings-status-not-detected"}`,children:O.result.success?"Connected":"Failed"})]}),(O==null?void 0:O.result)&&!O.result.success&&a.jsx("p",{className:"settings-error remote-executor-error",children:O.result.error}),((L=O==null?void 0:O.result)==null?void 0:L.success)&&a.jsx("p",{className:"remote-executor-details",children:O.result.claudeAvailable?"Claude CLI available":"Claude CLI not found"}),a.jsxs("div",{className:"remote-executor-actions",children:[a.jsx("button",{type:"button",onClick:()=>_(k),disabled:O==null?void 0:O.testing,className:"remote-executor-test-button",children:O!=null&&O.testing?"Testing...":"Test Connection"}),a.jsx("button",{type:"button",onClick:()=>E(k),className:"remote-executor-remove-button",children:"Remove"})]})]},k)})})]}),a.jsxs("div",{className:"settings-group",children:[a.jsx("h3",{children:"Setup Requirements"}),a.jsxs("ul",{className:"settings-requirements",children:[a.jsx("li",{children:"SSH host alias configured in ~/.ssh/config"}),a.jsx("li",{children:"SSH key-based authentication (no password prompts)"}),a.jsx("li",{children:"Claude CLI installed on the remote machine"}),a.jsx("li",{children:"Project paths must be the same on local and remote machines (e.g., ~/code/project)"})]})]})]})}const t0=[{id:"appearance",label:"Appearance",icon:"🎨",description:"Theme, font size, streaming"},{id:"model",label:"Model",icon:"🧠",description:"Claude model and thinking settings"},{id:"notifications",label:"Notifications",icon:"🔔",description:"Push notification preferences"},{id:"devices",label:"Devices",icon:"📱",description:"Browser profiles and connection origins"},{id:"local-access",label:"Local Access",icon:"🔒",description:"Network binding and authentication"},{id:"remote",label:"Remote Access",icon:"🌐",description:"Relay server configuration"},{id:"providers",label:"Providers",icon:"🔌",description:"AI provider integrations"},{id:"remote-executors",label:"Remote Executors",icon:"🖥️",description:"Run sessions on remote machines"},{id:"about",label:"About",icon:"ℹ️",description:"Version and support"}],oM={id:"development",label:"Development",icon:"🛠️",description:"Developer tools and debugging"},lM={appearance:h8,model:w8,notifications:A8,devices:b8,"local-access":j8,remote:aM,providers:M8,"remote-executors":iM,about:f8,development:m8};function n0({category:e,isActive:t,onClick:r}){return a.jsxs("button",{type:"button",className:`settings-category-item ${t?"active":""}`,onClick:r,children:[a.jsx("span",{className:"settings-category-icon",children:e.icon}),a.jsxs("div",{className:"settings-category-text",children:[a.jsx("span",{className:"settings-category-label",children:e.label}),a.jsx("span",{className:"settings-category-description",children:e.description})]}),a.jsx("span",{className:"settings-category-chevron",children:"›"})]})}function s0(){var w;const{category:e}=Ac(),t=ds(),r=or(),{openSidebar:i,isWideScreen:l,toggleSidebar:u,isSidebarCollapsed:d}=La(),{isManualReloadMode:f}=xh(),p=f?[...t0,oM]:t0,x=e||(l?(w=p[0])==null?void 0:w.id:void 0),v=E=>{t(`${r}/settings/${E}`)},y=()=>{t(`${r}/settings`)},S=x?lM[x]:null;if(!l){if(!e)return a.jsx("div",{className:"main-content-mobile",children:a.jsxs("div",{className:"main-content-mobile-inner",children:[a.jsx(Ar,{title:"Settings",onOpenSidebar:i,onToggleSidebar:u,isWideScreen:l,isSidebarCollapsed:d}),a.jsx("main",{className:"page-scroll-container",children:a.jsx("div",{className:"page-content-inner",children:a.jsx("div",{className:"settings-category-list",children:p.map(_=>a.jsx(n0,{category:_,isActive:!1,onClick:()=>v(_.id)},_.id))})})})]})});const E=p.find(_=>_.id===e);return a.jsx("div",{className:"main-content-mobile",children:a.jsxs("div",{className:"main-content-mobile-inner",children:[a.jsx(Ar,{title:(E==null?void 0:E.label)||"Settings",onOpenSidebar:i,showBack:!0,onBack:y}),a.jsx("main",{className:"page-scroll-container",children:a.jsx("div",{className:"page-content-inner",children:S&&a.jsx(S,{})})})]})})}return a.jsx("div",{className:"main-content-wrapper",children:a.jsxs("div",{className:"main-content-constrained",children:[a.jsx(Ar,{title:"Settings",onOpenSidebar:i,onToggleSidebar:u,isWideScreen:l,isSidebarCollapsed:d}),a.jsx("main",{className:"page-scroll-container",children:a.jsxs("div",{className:"settings-two-column",children:[a.jsx("nav",{className:"settings-category-nav",children:a.jsx("div",{className:"settings-category-list",children:p.map(E=>a.jsx(n0,{category:E,isActive:x===E.id,onClick:()=>v(E.id)},E.id))})}),a.jsx("div",{className:"settings-content-panel",children:S&&a.jsx(S,{})})]})})]})})}const cM=h.Fragment;TT();d3();const uM="/".replace(/\/$/,"")||void 0,Cy=document.getElementById("root");if(!Cy)throw new Error("Root element not found");HS.createRoot(Cy).render(a.jsx(cM,{children:a.jsx(a3,{children:a.jsx(hw,{basename:uM,children:a.jsx(r3,{children:a.jsxs(Hj,{children:[a.jsx(ps,{path:"/",element:a.jsx(yx,{to:"/projects",replace:!0})}),a.jsx(ps,{path:"/login",element:a.jsx(y4,{})}),a.jsxs(ps,{element:a.jsx(O3,{}),children:[a.jsx(ps,{path:"/projects",element:a.jsx(A4,{})}),a.jsx(ps,{path:"/sessions",element:a.jsx(p4,{})}),a.jsx(ps,{path:"/agents",element:a.jsx(J3,{})}),a.jsx(ps,{path:"/inbox",element:a.jsx(b4,{})}),a.jsx(ps,{path:"/settings",element:a.jsx(s0,{})}),a.jsx(ps,{path:"/settings/:category",element:a.jsx(s0,{})}),a.jsx(ps,{path:"/projects/:projectId",element:a.jsx(yx,{to:"/sessions",replace:!0})}),a.jsx(ps,{path:"/new-session",element:a.jsx(k4,{})}),a.jsx(ps,{path:"/projects/:projectId/sessions/:sessionId",element:a.jsx(l8,{})})]}),a.jsx(ps,{path:"/projects/:projectId/file",element:a.jsx(d4,{})}),a.jsx(ps,{path:"/activity",element:a.jsx($3,{})})]})})})})}));
|
package/client-dist/index.html
CHANGED
|
@@ -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-
|
|
30
|
+
<script type="module" crossorigin src="/assets/index-j1Xn0kY4.js"></script>
|
|
31
31
|
<link rel="stylesheet" crossorigin href="/assets/index-BtEwQvna.css">
|
|
32
32
|
</head>
|
|
33
33
|
<body>
|