@co0ontty/wand 4.1.0 → 4.2.0

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.
@@ -45,7 +45,7 @@
45
45
  `,n=e.split(t),i=[],a=!1,u=0;u<n.length;u++){var o=n[u],s=o.trim();if(!(!a&&!s)){if(a=!0,s.indexOf("\u23FA")===0&&s.length>2){i.push(s.slice(1).trim());continue}if(s.indexOf("\u25CF")===0){if(s=s.slice(1).trim(),!s)continue;o=s}i.push(o)}}for(;i.length>0&&!i[i.length-1].trim();)i.pop();for(var l=[],d={},f=0;f<i.length;f++){var c=i[f].replace(/\s+/g,"");c.length>5&&d[c]||(c.length>5&&(d[c]=!0),l.push(i[f]))}return l.join(t)}function Hl(e){var t=`
46
46
  `,n=e.split(t),i=[],a=0;function u(g){var y=g.trim();return y.charAt(0)==="|"&&(y=y.slice(1)),y.charAt(y.length-1)==="|"&&(y=y.slice(0,-1)),y.split("|")}function o(g){return g?' style="text-align:'+g+'"':""}function s(g,y,B){var E="<thead><tr>"+g.map(function(D,F){return"<th"+o(y[F])+">"+D.trim()+"</th>"}).join("")+"</tr></thead>",C=B.length?"<tbody>"+B.map(function(D){return"<tr>"+D.map(function(F,L){return"<td"+o(y[L])+">"+F.trim()+"</td>"}).join("")+"</tr>"}).join("")+"</tbody>":"";return'<div class="md-table-wrap"><table class="md-table">'+E+C+"</table></div>"}for(;a<n.length;){var l=n[a];if(l.indexOf("|")!==-1&&a+1<n.length){var d=n[a+1].trim();if(/^\|?\s*:?-+:?(\s*\|\s*:?-+:?)+\s*\|?$/.test(d)){for(var f=u(l),c=u(d).map(function(g){var y=g.trim(),B=y.charAt(0)===":",E=y.charAt(y.length-1)===":";return B&&E?"center":E?"right":B?"left":""}),v=[],h=a+2;h<n.length;){var m=n[h].trim();if(!m||m.indexOf("|")===-1)break;v.push(u(n[h])),h+=1}i.push("",s(f,c,v),""),a=h;continue}}i.push(l),a+=1}return i.join(t)}function xu(e){if(!e)return"";var t=p(e),n="`",i=`
47
47
  `;function a(O,P,_,Q){for(var $=0;;){var ie=O.indexOf(P,$);if(ie===-1)break;var ge=O.indexOf(P,ie+P.length);if(ge===-1)break;var ae=O.slice(ie+P.length,ge);if(!ae){$=ge+P.length;continue}var ue=_+ae+Q;O=O.slice(0,ie)+ue+O.slice(ge+P.length),$=ie+ue.length}return O}function u(O){return O>=48&&O<=57||O>=65&&O<=90||O>=97&&O<=122||O===95}function o(O,P,_){for(var Q=0;Q<O.length;){var $=O.indexOf("_",Q);if($===-1)break;var ie=$>0?O.charCodeAt($-1):0;if(u(ie)){Q=$+1;continue}for(var ge=$+1,ae=-1;ge<O.length;){var ue=O.indexOf("_",ge);if(ue===-1)break;var ze=ue+1,Te=ze<O.length?O.charCodeAt(ze):0;if(!u(Te)){ae=ue;break}ge=ue+1}if(ae===-1)break;var Fe=O.slice($+1,ae);if(!Fe){Q=ae+1;continue}var Le=P+Fe+_;O=O.slice(0,$)+Le+O.slice(ae+1),Q=$+Le.length}return O}function s(O,P,_,Q){return O.split(i).map(function($){return $.indexOf(P)!==0?$:_+$.slice(P.length)+Q}).join(i)}function l(O){return O.split(i).map(function(P){var _=P.indexOf(". ");if(_<=0)return P;for(var Q=0;Q<_;Q+=1){var $=P.charCodeAt(Q);if($<48||$>57)return P}return"<li>"+P.slice(_+2)+"</li>"}).join(i)}function d(O){return O.split(i+i).map(function(P){var _=P.trim();return _?_.indexOf("<div")===0||_.indexOf("<h1")===0||_.indexOf("<h2")===0||_.indexOf("<h3")===0||_.indexOf("<h4")===0||_.indexOf("<h5")===0||_.indexOf("<h6")===0||_.indexOf("<ul")===0||_.indexOf("<ol")===0||_.indexOf("<li")===0||_.indexOf("<blockquote")===0||_.indexOf("<pre")===0?_:"<p>"+_.split(i).join("<br>")+"</p>":""}).join("")}for(var f=0;;){var c=t.indexOf(n+n+n,f);if(c===-1)break;var v=t.indexOf(n+n+n,c+3);if(v===-1)break;var h=t.slice(c+3,v),m=h.indexOf(i),g="",y=h;if(m!==-1&&m<30){for(var B=h.slice(0,m).trim(),E=B.length>0,C=0;C<B.length;C+=1){var D=B.charCodeAt(C),F=D>=48&&D<=57,L=D>=65&&D<=90,S=D>=97&&D<=122;if(!F&&!L&&!S){E=!1;break}}E&&(g=B,y=h.slice(m+1))}var N=Nm(y.trim(),g),J=N.replace(/_/g,"&#95;").replace(/\*/g,"&#42;"),W='<div class="code-block"><div class="code-block-header"><span class="code-lang">'+(g||"code")+'</span><button class="code-copy">Copy</button></div><pre><code>'+J+"</code></pre></div>";t=t.slice(0,c)+W+t.slice(v+3),f=c+W.length}for(f=0;;){var k=t.indexOf(n,f);if(k===-1)break;var I=t.indexOf(n,k+1);if(I===-1)break;if(I===k+1){f=I+1;continue}var T=t.slice(k+1,I),Y=T.replace(/_/g,"&#95;").replace(/\*/g,"&#42;"),j='<code class="code-inline">'+Y+"</code>";t=t.slice(0,k)+j+t.slice(I+1),f=k+j.length}t=a(t,"**","<strong>","</strong>"),t=a(t,"*","<em>","</em>"),t=o(t,"<em>","</em>"),t=s(t,"### ","<h3>","</h3>"),t=s(t,"## ","<h2>","</h2>"),t=s(t,"# ","<h1>","</h1>"),t=s(t,"&gt; ","<blockquote>","</blockquote>"),t=s(t,"- ","<li>","</li>"),t=s(t,"* ","<li>","</li>"),t=l(t),t=Hl(t);var G=t.split(i),M=[],te=[];function ne(){te.length&&(M.push("<ul>"+te.join("")+"</ul>"),te=[])}return G.forEach(function(O){if(O.indexOf("<li>")===0&&O.lastIndexOf("</li>")===O.length-5){te.push(O);return}ne(),M.push(O)}),ne(),t=d(M.join(i)),'<div class="markdown-content">'+t+"</div>"}function Nm(e,t){return e=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),e}function lr(e){var t=String(e||"").trim();return t.length<=24?t||"\u672A\u9009\u62E9\u4F1A\u8BDD":t.slice(0,21)+"..."}function Su(e){return String(e||"").replace(/\r\r\n/g,`\r
48
- `).replace(/\u0000/g,"")}function jm(){var e=document.getElementById("login-cert-hint");e&&e.classList.remove("hidden");var t=document.getElementById("login-cert-http-link");t&&(t.href="http://"+location.host+location.pathname,t.style.display=location.protocol==="https:"?"":"none")}function Rm(){var e=document.getElementById("login-cert-hint");e&&e.classList.add("hidden")}function Iu(){if(!r.loginPending){var e=document.getElementById("password"),t=document.getElementById("login-button"),n=document.getElementById("login-error");!e||!t||!n||(Ti(n),Rm(),e.dataset.error="false",e.setAttribute("aria-invalid","false"),r.loginPending=!0,t.disabled=!0,t.textContent="\u767B\u5F55\u4E2D...",fetch("/api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:e.value}),credentials:"same-origin"}).then(function(i){return i.status===429?(Oe(n,"\u767B\u5F55\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002"),Promise.reject("handled")):i.ok?fetch("/api/config",{credentials:"same-origin"}):(e.dataset.error="true",e.setAttribute("aria-invalid","true"),Oe(n,"\u5BC6\u7801\u9519\u8BEF\uFF0C\u8BF7\u91CD\u8BD5\u3002"),Promise.reject("handled"))}).then(function(i){return i.ok?i.json():(location.protocol==="https:"?jm():Oe(n,"\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"),Promise.reject("handled"))}).then(function(i){r.config=i;var a=document.getElementById("status-dot"),u=document.getElementById("status-text");return a&&a.classList.add("active"),u&&(u.textContent="\u5DF2\u767B\u5F55"),_t()}).then(function(){ns(),Zt()}).catch(function(i){i!=="handled"&&(console.error("[wand] Login error:",i),Oe(n,"\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"))}).finally(function(){r.loginPending=!1,t.disabled=!1,t.textContent="\u8FDB\u5165\u63A7\u5236\u53F0"}))}}function Tu(){return typeof WandNative<"u"&&typeof WandNative.switchServer=="function"}function _l(){if(Tu())try{WandNative.switchServer()}catch{}}function Wm(){return typeof WandNative<"u"&&typeof WandNative.backToNative=="function"?!0:typeof window.__wandBackToNative=="function"}function zm(){try{if(typeof WandNative<"u"&&typeof WandNative.backToNative=="function"){WandNative.backToNative();return}typeof window.__wandBackToNative=="function"&&window.__wandBackToNative()}catch{}}function Nl(){fetch("/api/logout",{method:"POST",credentials:"same-origin"}).catch(function(){}),ss(),Kn(!1),lu(),Mr(),r.config=null,r.selectedId=null,Ee(),r.sessions=[],r.claudeHistory=[],r.claudeHistoryLoaded=!1,r.claudeHistoryExpanded=!1,r.claudeHistoryExpandedDirs={},r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),Zt()}function _t(){return nn()}function Lu(e){return e==="full-access"?"\u5168\u6743\u9650":e==="default"?"\u9ED8\u8BA4":e==="native"?"\u539F\u751F":e==="auto-edit"?"\u81EA\u52A8\u7F16\u8F91":e==="managed"?"\u6258\u7BA1":e}function $e(){return r.sessionTool||r.preferredCommand||"claude"}function Vm(){var e=r.sessions.find(function(t){return t.id===r.selectedId});return e&&e.provider||r.preferredCommand||"claude"}function jl(e,t){return t?"\u952E\u76D8\u8F93\u5165\u5C06\u53D1\u9001\u5230\u7EC8\u7AEF":e&&(e.status==="exited"||e.status==="failed"||e.status==="stopped")?au(e)?"\u8F93\u5165\u6D88\u606F\u4EE5\u7EE7\u7EED\u4F1A\u8BDD":"\u4F1A\u8BDD\u5DF2\u7ED3\u675F":se(e)&&e.structuredState&&e.structuredState.inFlight?"\u56DE\u590D\u4E2D\uFF0C\u53EF\u7EE7\u7EED\u8F93\u5165":"\u8F93\u5165\u6D88\u606F"}function Rl(e,t){return e==="codex"?"Codex \u652F\u6301 PTY \u7EC8\u7AEF\u4E0E\u7ED3\u6784\u5316\uFF08JSONL\uFF09\u4E24\u79CD\u4F1A\u8BDD\uFF0C\u7ED3\u6784\u5316\u6A21\u5F0F\u6309 full-access \u542F\u52A8\u3002":e==="opencode"?t==="full-access"||t==="managed"||t==="auto-edit"?"OpenCode \u5C06\u81EA\u52A8\u6279\u51C6\u672A\u663E\u5F0F\u62D2\u7EDD\u7684\u6743\u9650\uFF1B\u652F\u6301 TUI \u4E0E JSON \u7ED3\u6784\u5316\u4F1A\u8BDD\u3002":"OpenCode \u4F7F\u7528\u81EA\u8EAB\u6743\u9650\u914D\u7F6E\uFF1B\u7ED3\u6784\u5316\u6A21\u5F0F\u4F1A\u81EA\u52A8\u62D2\u7EDD\u672A\u6279\u51C6\u7684\u6743\u9650\u8BF7\u6C42\u3002":t==="full-access"?"\u81EA\u52A8\u786E\u8BA4\u6743\u9650\u8BF7\u6C42\u4E0E\u9AD8\u6743\u9650\u64CD\u4F5C\uFF0C\u9002\u5408\u4F60\u786E\u8BA4\u73AF\u5883\u5B89\u5168\u540E\u7684\u8FDE\u7EED\u4FEE\u6539\u3002":t==="auto-edit"?"\u4FDD\u7559\u4EA4\u4E92\u5F0F\u4F1A\u8BDD\uFF0C\u540C\u65F6\u66F4\u504F\u5411\u76F4\u63A5\u7F16\u8F91\u4EE3\u7801\u3002":t==="native"?"\u8C03\u7528 Claude \u539F\u751F API \u8F93\u51FA\uFF0C\u9002\u5408\u5FEB\u901F\u95EE\u7B54\u6216\u4E00\u6B21\u6027\u751F\u6210\u3002":t==="managed"?"AI \u81EA\u52A8\u5B8C\u6210\u6240\u6709\u5DE5\u4F5C\uFF0C\u65E0\u9700\u4E2D\u9014\u786E\u8BA4\uFF0C\u9002\u5408\u6709\u660E\u786E\u76EE\u6807\u7684\u4EFB\u52A1\u3002":"\u4FDD\u7559\u6807\u51C6\u4EA4\u4E92\u6D41\u7A0B\uFF0C\u9002\u5408\u624B\u52A8\u786E\u8BA4\u6BCF\u4E00\u6B65\u3002"}function Mu(e){return e==="codex"?["full-access"]:e==="opencode"?["default","full-access","managed"]:["default","full-access","auto-edit","native","managed"]}function dt(e,t){var n=Mu(e);if(n.indexOf(t)!==-1)return t;var i=r.config&&r.config.defaultMode?r.config.defaultMode:"default";return n.indexOf(i)!==-1?i:n[0]}function Kh(e,t){return Mu(e).map(function(n){var i=Wl(n);return'<option value="'+p(n)+'"'+(n===t?" selected":"")+' title="'+i+'">'+p(Lu(n))+"</option>"}).join("")}function Wl(e){var t={default:"\u6807\u51C6\u6A21\u5F0F - \u9700\u8981\u786E\u8BA4\u6587\u4EF6\u4FEE\u6539","full-access":"\u5B8C\u5168\u8BBF\u95EE - \u81EA\u52A8\u786E\u8BA4\u6743\u9650\u4E0E\u64CD\u4F5C","auto-edit":"\u81EA\u52A8\u7F16\u8F91 - \u81EA\u52A8\u786E\u8BA4\u6587\u4EF6\u4FEE\u6539",native:"\u539F\u751F\u6A21\u5F0F - \u8FD4\u56DE\u7ED3\u6784\u5316\u8F93\u51FA",managed:"\u6258\u7BA1\u6A21\u5F0F - AI \u81EA\u52A8\u5B8C\u6210\u6240\u6709\u5DE5\u4F5C"};return t[e]||""}function Um(e){var t=e&&e.provider?e.provider:"claude";return(se(e)?"\u7ED3\u6784\u5316":"\u7EC8\u7AEF")+" \xB7 "+t}function Km(e){return se(e)?"\u7ED3\u6784\u5316 \xB7 \u5757\u7EA7\u8BB0\u5F55":e&&e.provider==="codex"?"\u7EC8\u7AEF \xB7 Codex PTY\uFF08chat \u4E3A\u89E3\u6790\u89C6\u56FE\uFF09":"\u7EC8\u7AEF \xB7 PTY \u4F1A\u8BDD"}function zl(e){return e?se(e)||e.provider==="codex":!1}function Vl(e,t){if(!e||!e.is_error||!t||t.is_error)return!1;var n=Bn(e.content).toLowerCase(),i=Bn(t.content).toLowerCase();return n?n.indexOf("invalid pages parameter")!==-1&&i.length>0:!1}function se(e){return!!e&&(e.sessionKind==="structured"||e.runner==="claude-cli-print")}function Qi(){r.chatMode=dt("claude",r.chatMode);var e=document.getElementById("mode-hint");e&&(e.textContent=Wl(r.chatMode)),tn()}var Ul=Object.create(null),$i=Object.create(null),Xi=Object.create(null);function Kl(e){return e&&Xi[e]||null}function Zi(e,t,n){if(e){var i=Xi[e]||(Xi[e]={});i[t]=n}}function Jl(e){e&&delete Xi[e]}function Ou(e,t){var n=($i[e]||0)+1;$i[e]=n;var i=Ul[e]||Promise.resolve(),a=i.catch(function(){}).then(t);return Ul[e]=a.catch(function(){}),a.then(function(u){return{data:u,latest:$i[e]===n}},function(u){return Promise.reject({error:u,latest:$i[e]===n})})}function Jr(e,t){Jl(e),Promise.resolve(nn()).catch(function(){}).finally(function(){tn()}),x(t,"error")}function Pu(e,t){if(!t.latest)return!1;var n=t.data;return n&&n.error?(Jr(e,n.error),!1):!n||!n.id?(Jr(e,"\u4F1A\u8BDD\u8BBE\u7F6E\u66F4\u65B0\u5931\u8D25"),!1):(ee(n),Jl(e),tn(),!0)}function Jm(e,t){t=t||{};var n=t.kind==="compact"||t.kind==="popover"?t.kind:"dropdown",i=$e(),a=r.chatMode||"default",u=$r(e)||"",o=ea(u,e),s=ra(e);function l(d,f,c,v){var h=n==="compact"?"":'<span class="chat-mode-trio-tag">'+p(f)+"</span>";return'<span class="composer-text-pill chat-mode-trio-pill" data-mode-control-pill="'+d+'" title="'+p(f)+'">'+h+'<span class="composer-text-label">'+p(c)+'</span><select class="composer-text-hidden-select" data-mode-control="'+d+'" aria-label="'+p(f)+'">'+v+"</select></span>"}return'<div class="chat-mode-trio chat-mode-trio-'+n+'" role="group" aria-label="\u4F1A\u8BDD\u8BBE\u7F6E">'+l("mode","\u6A21\u5F0F",a,ta(i,a))+'<span class="composer-text-sep" aria-hidden="true">\xB7</span>'+l("model","\u6A21\u578B",o,$l(u,e))+'<span class="composer-text-sep" aria-hidden="true">\xB7</span>'+l("thinking","\u601D\u8003",Jn(s,e),qu(s,e))+"</div>"}function Jn(e,t){var n=$m(e,t);return n==="low"?"\u4F4E":n==="medium"?"\u4E2D":n==="high"?"\u9AD8":n==="xhigh"?"\u8D85\u9AD8":n==="max"?"\u6781\u9AD8":n==="ultra"?"\u6781\u9650":"\u81EA\u52A8"}function Gr(e,t){var n=e||"",i=_u(t);if(!n||n==="default"){for(var a=0;a<i.length;a++)if(i[a].id==="default")return i[a].label||i[a].id;return"\u9ED8\u8BA4"}for(var u=0;u<i.length;u++)if(i[u].id===n)return i[u].label||i[u].id;return n}function ea(e,t){var n=Gr(e,t);if(!n||n==="\u8DDF\u968F\u670D\u52A1\u7AEF\u9ED8\u8BA4")return"\u9ED8\u8BA4";var i=n.search(/[((]/);i>0&&(n=n.slice(0,i).trim());var a=n.lastIndexOf("/");a>=0&&a<n.length-1&&(n=n.slice(a+1).trim());var u=n.toLowerCase();return u.indexOf("opus")!==-1?"Opus":u.indexOf("sonnet")!==-1?"Sonnet":u.indexOf("haiku")!==-1?"Haiku":u.indexOf("gpt-5.5")!==-1?"GPT-5.5":u.indexOf("gpt-5")!==-1?"GPT-5":u.indexOf("gpt-4")!==-1?"GPT-4":n.length>12?n.slice(0,10)+"\u2026":n}function qu(e,t){var n=Zr(t),i=n.some(function(a){return a.id===e})?e:"off";return n.map(function(a){var u=a.id==="off"?"\u81EA\u52A8\uFF08\u6A21\u578B\u9ED8\u8BA4\uFF09":Jn(a.id,t);return'<option value="'+p(a.id)+'"'+(a.id===i?" selected":"")+">"+p(u)+"</option>"}).join("")}function Gl(e,t,n){var i=e.querySelector('[data-mode-control="thinking"]');i&&(i.innerHTML=qu(t,n),i.value=Zr(n).some(function(a){return a.id===t})?t:"off")}function Yl(e){var t=$e(),n=r.chatMode||"default",i=$r(e)||"",a=ra(e),u=Lu(n),o=ea(i,e),s=Jn(a,e),l="\u6A21\u5F0F "+u+" \xB7 \u6A21\u578B "+o+" \xB7 \u601D\u8003 "+s;return'<div class="composer-config-controls" role="group" aria-label="\u4F1A\u8BDD\u8BBE\u7F6E" title="'+p(l)+'"><span class="composer-config-chip composer-config-chip-mode" data-mode-control-pill="mode" title="\u6A21\u5F0F\uFF1A'+p(u)+'">'+V("shield",{size:13,strokeWidth:1.8,cls:"composer-config-icon"})+'<span class="composer-config-label">'+p(u)+'</span><select class="composer-text-hidden-select" data-mode-control="mode" aria-label="\u6A21\u5F0F">'+ta(t,n)+'</select></span><span class="composer-config-chip composer-config-model" data-mode-control-pill="model" title="\u6A21\u578B\uFF1A'+p(o)+'">'+V("cpu",{size:13,strokeWidth:1.8,cls:"composer-config-icon"})+'<span class="composer-config-label">'+p(o)+'</span><select class="composer-text-hidden-select" data-mode-control="model" aria-label="\u6A21\u578B">'+Ql(i,e)+'</select></span><span class="composer-config-chip composer-config-thinking" data-mode-control-pill="thinking" data-thinking="'+p(a)+'" title="\u601D\u8003\u6DF1\u5EA6\uFF1A'+p(s)+'">'+V("brain",{size:13,strokeWidth:1.8,cls:"composer-config-icon"})+'<span class="composer-config-label">'+p(s)+'</span><select class="composer-text-hidden-select" data-mode-control="thinking" aria-label="\u601D\u8003\u6DF1\u5EA6">'+qu(a,e)+"</select></span></div>"}function tn(){var e=Xe(),t=$e(),n=r.chatMode||"default",i=$r(e)||"",a=ea(i,e),u=ra(e),o=document.querySelectorAll(".chat-mode-trio");o.forEach(function(s){function l(d,f,c,v){var h=s.querySelector('[data-mode-control-pill="'+d+'"]');if(h){var m=h.querySelector(".composer-text-label");if(m&&(m.textContent=v||f),d==="thinking"){Gl(h,f,e);return}var g=h.querySelector('[data-mode-control="'+d+'"]');g&&(c&&(g.innerHTML=c),g.value!==f&&(g.value=f))}}l("mode",n,ta(t,n)),l("model",i,$l(i,e),a),l("thinking",u,"",Jn(u,e))}),Gm(e,n,$r(e)||"",u)}function Gm(e,t,n,i){var a=$e(),u=Lu(t),o=ea(n,e),s=Jn(i,e),l=document.querySelectorAll(".composer-config-controls");l.forEach(function(d){var f="\u6A21\u5F0F "+u+" \xB7 \u6A21\u578B "+o+" \xB7 \u601D\u8003 "+s;d.setAttribute("title",f);function c(E,C,D){var F=E.querySelector("[data-mode-control]");F&&(F.innerHTML=D,F.value=C)}var v=d.querySelector('[data-mode-control-pill="mode"]');if(v){var h=v.querySelector(".composer-config-label");h&&(h.textContent=u),v.setAttribute("title","\u6A21\u5F0F\uFF1A"+u),c(v,t,ta(a,t))}var m=d.querySelector('[data-mode-control-pill="model"]');if(m){var g=m.querySelector(".composer-config-label");g&&(g.textContent=o),m.setAttribute("title","\u6A21\u578B\uFF1A"+o),c(m,n,Ql(n,e))}var y=d.querySelector('[data-mode-control-pill="thinking"]');if(y){var B=y.querySelector(".composer-config-label");B&&(B.textContent=s),y.setAttribute("data-thinking",i),y.setAttribute("title","\u601D\u8003\u6DF1\u5EA6\uFF1A"+s),Gl(y,i,e)}})}function ta(e,t){return Mu(e).map(function(n){return'<option value="'+p(n)+'"'+(n===t?" selected":"")+">"+p(n)+"</option>"}).join("")}function ct(e){return e==="codex"||e==="opencode"?e:"claude"}function Yr(e){return ct(e&&e.provider||r.sessionTool||"claude")}function Hu(){var e=r.config&&r.config.defaultModels&&typeof r.config.defaultModels=="object"?r.config.defaultModels:{};return{claude:typeof e.claude=="string"?e.claude:r.config&&r.config.defaultModel||"",codex:typeof e.codex=="string"?e.codex:r.config&&r.config.defaultCodexModel||"",opencode:typeof e.opencode=="string"?e.opencode:r.config&&r.config.defaultOpenCodeModel||""}}function Ym(e){var t=Hu(),n=ct(e);return n==="codex"?t.codex||"":n==="opencode"?t.opencode||"":t.claude||""}function Qr(e){var t=ct(e),n=r.chatModels&&typeof r.chatModels[t]=="string"?r.chatModels[t]:"";return!n&&t==="claude"&&(n=r.chatModel||""),n||""}function na(e,t){var n=ct(e),i=(t||"").trim();r.chatModels||(r.chatModels={claude:"",codex:"",opencode:""}),r.chatModels[n]=i,r.chatModel=i;try{localStorage.setItem("wand-chat-model-"+n,i),localStorage.removeItem("wand-chat-model")}catch{}}function $r(e){var t=e&&e.id?Kl(e.id):null;if(t&&Object.prototype.hasOwnProperty.call(t,"model"))return t.model||"";if(e&&e.selectedModel)return e.selectedModel;var n=Yr(e),i=Qr(n);return i||Ym(n)||""}function _u(e){var t=e&&e.provider||r.sessionTool||"claude";return t==="codex"?r.availableCodexModels||[]:t==="opencode"?r.availableOpenCodeModels||[]:r.availableModels||[]}function Ql(e,t){for(var n=_u(t),i=e==="default"?"":e||"",a='<option value=""'+(i?"":" selected")+">\u9ED8\u8BA4 \xB7 "+p(Gr("",t))+"</option>",u=0;u<n.length;u++){var o=n[u];if(o.id!=="default"){var s=o.label||o.id,l=Yr(t)==="claude"?o.availability==="verified"?" \xB7 \u5DF2\u9A8C\u8BC1":o.availability==="stale"?" \xB7 \u5F85\u5237\u65B0":o.source==="models-api"?" \xB7 API \u5019\u9009":" \xB7 \u5019\u9009":"";a+='<option value="'+p(o.id)+'"'+(o.id===i?" selected":"")+">"+p(s+l)+"</option>"}}return i&&!n.some(function(d){return d.id===i})&&(a+='<option value="'+p(i)+'" selected>'+p(i)+"\uFF08\u81EA\u5B9A\u4E49\uFF09</option>"),a}function $l(e,t){for(var n=_u(t),i=e==="default"?"":e||"",a='<option value=""'+(i?"":" selected")+">"+p(Gr("",t))+"</option>",u=0;u<n.length;u++){var o=n[u];if(o.id!=="default"){var s=Yr(t)==="claude"?o.availability==="verified"?" \xB7 verified":o.availability==="stale"?" \xB7 stale":o.source==="models-api"?" \xB7 API candidate":" \xB7 candidate":"";a+='<option value="'+p(o.id)+'"'+(o.id===i?" selected":"")+">"+p(o.id+s)+"</option>"}}return i&&!n.some(function(l){return l.id===i})&&(a+='<option value="'+p(i)+'" selected>'+p(i)+"</option>"),a}function dr(e){tn()}var Xr=[{id:"off",label:"auto",hint:"\u4F7F\u7528 provider / \u6A21\u578B\u9ED8\u8BA4\u601D\u8003\u6863\u4F4D"},{id:"standard",label:"low",hint:"Claude/Codex: low \xB7 OpenCode variant: low"},{id:"deep",label:"medium",hint:"Claude/Codex: medium \xB7 OpenCode variant: high"},{id:"max",label:"max",hint:"Claude: max \xB7 Codex: xhigh \xB7 OpenCode variant: max"}];function Qm(e){return e==="low"?"standard":e==="medium"?"deep":e==="xhigh"?"max":"codex:"+e}function Zr(e){if(Yr(e)!=="codex")return Xr;var t=$r(e)||"default",n=r.availableCodexModels||[],i=n.find(function(o){return o.id===t})||n.find(function(o){return o.id==="default"}),a=i&&Array.isArray(i.reasoningEfforts)?i.reasoningEfforts:[];if(!a.length)return Xr;var u=i.defaultReasoningEffort||"";return[{id:"off",label:"auto",hint:u?"\u4F7F\u7528\u6A21\u578B\u9ED8\u8BA4\u6863\u4F4D\uFF08"+u+"\uFF09":"\u4F7F\u7528\u6A21\u578B\u9ED8\u8BA4\u6863\u4F4D"}].concat(a.map(function(o){var s=String(o.effort||"").toLowerCase();return{id:Qm(s),label:s,hint:o.description||s}}).filter(function(o){return o.label}))}function $m(e,t){for(var n=Zr(t),i=0;i<n.length;i++)if(n[i].id===e)return n[i].label;if(typeof e=="string"&&e.indexOf("codex:")===0)return e.slice(6);for(var a=0;a<Xr.length;a++)if(Xr[a].id===e)return Xr[a].label;return"auto"}function ra(e){var t=e&&e.id?Kl(e.id):null;return t&&Object.prototype.hasOwnProperty.call(t,"thinking")?t.thinking||"off":e&&e.thinkingEffort?e.thinkingEffort:r.chatThinking?r.chatThinking:"off"}function Jh(e){tn()}function Xl(e){r.chatThinking=e;try{localStorage.setItem("wand-thinking-effort",e)}catch{}}function Zl(e,t,n,i){return Ou(e.id,function(){return i&&!i.ok?{error:i.error||"\u5207\u6362\u6A21\u578B\u5931\u8D25"}:fetch("/api/sessions/"+encodeURIComponent(e.id)+"/thinking-effort",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({thinkingEffort:t})}).then(function(a){return a.json()})}).then(function(a){Pu(e.id,a)&&typeof x=="function"&&x(n||"\u5DF2\u5207\u6362\u601D\u8003\u6DF1\u5EA6 \u2192 "+Jn(t,Xe()),"success")}).catch(function(a){a&&a.latest&&Jr(e.id,"\u5207\u6362\u601D\u8003\u6DF1\u5EA6\u5931\u8D25")})}function Xm(e){var t=(e||"off").trim(),n=Xe(),i=Zr(n).some(function(a){return a.id===t});i||(t="off"),Xl(t),n&&Zi(n.id,"thinking",t),tn(),n&&Zl(n,t,"\u5DF2\u5207\u6362\u601D\u8003\u6DF1\u5EA6 \u2192 "+Jn(t,n))}function ed(e){if(!e)return!1;var t=e.mode;return t==="managed"||t==="full-access"}function Zm(e){if(!e||ed(e))return"";var t=!!e.autoApprovePermissions;return t?'<button id="auto-approve-toggle" class="composer-pill composer-pill-chip auto-approve-indicator active" type="button" aria-pressed="true" aria-label="\u81EA\u52A8\u6279\u51C6\u5DF2\u542F\u7528\uFF0C\u70B9\u51FB\u5173\u95ED" title="\u81EA\u52A8\u6279\u51C6\u5DF2\u542F\u7528 \u2014 \u70B9\u51FB\u5173\u95ED">'+V("shieldCheck",{size:12,strokeWidth:1.7,cls:"composer-pill-icon"})+'<span class="composer-pill-label">\u81EA\u52A8</span></button>':'<button id="auto-approve-toggle" class="composer-pill composer-pill-chip auto-approve-indicator" type="button" aria-pressed="false" aria-label="\u81EA\u52A8\u6279\u51C6\u5DF2\u5173\u95ED\uFF0C\u70B9\u51FB\u5F00\u542F" title="\u81EA\u52A8\u6279\u51C6\u5DF2\u5173\u95ED \u2014 \u70B9\u51FB\u5F00\u542F">'+V("shield",{size:12,strokeWidth:1.7,cls:"composer-pill-icon"})+'<span class="composer-pill-label">\u624B\u52A8</span></button>'}function td(){return fetch("/api/models",{credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){return e&&Array.isArray(e.models)&&(r.availableModels=e.models,r.availableCodexModels=Array.isArray(e.codexModels)?e.codexModels:[],r.availableOpenCodeModels=Array.isArray(e.opencodeModels)?e.opencodeModels:[],dr(Xe()),ua(e),aa(!1)),e}).catch(function(){return null})}function nd(){if(r.modelsRefreshing)return Promise.resolve(null);r.modelsRefreshing=!0;var e=document.querySelectorAll("#cfg-default-model-refresh, #cfg-commit-model-refresh");return e.forEach(function(t){var n=t,i=n.querySelector("span");n.disabled=!0,n.classList.add("is-loading"),n.setAttribute("aria-busy","true"),i&&(i.textContent="\u68C0\u6D4B\u4E2D")}),fetch("/api/models/refresh",{method:"POST",credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(t&&Array.isArray(t.models)&&(r.availableModels=t.models,r.availableCodexModels=Array.isArray(t.codexModels)?t.codexModels:[],r.availableOpenCodeModels=Array.isArray(t.opencodeModels)?t.opencodeModels:[],dr(Xe()),ua(t),aa(!1),typeof x=="function")){var n=t.models.filter(function(a){return a.availability==="verified"}).length,i="\u6A21\u578B\u5217\u8868\u5DF2\u5237\u65B0"+(t.claudeVersion?"\uFF08claude "+t.claudeVersion+"\uFF09":"");n&&(i+="\uFF1B\u5DF2\u9A8C\u8BC1 "+n+" \u4E2A"),x(i,"success")}return t}).catch(function(){return typeof x=="function"&&x("\u5237\u65B0\u6A21\u578B\u5217\u8868\u5931\u8D25","error"),null}).finally(function(){r.modelsRefreshing=!1,e.forEach(function(t){var n=t,i=n.querySelector("span");n.disabled=!1,n.classList.remove("is-loading"),n.removeAttribute("aria-busy"),i&&(i.textContent="\u5237\u65B0\u5217\u8868")})})}function eg(){var e=document.getElementById("env-preview-modal");if(!e){e=document.createElement("section"),e.id="env-preview-modal",e.className="modal-backdrop hidden",e.innerHTML='<div class="modal env-preview-modal" role="dialog" aria-labelledby="env-preview-title" aria-modal="true"><div class="modal-header"><div><h2 class="modal-title" id="env-preview-title">\u5C06\u6CE8\u5165\u5B50\u8FDB\u7A0B\u7684\u73AF\u5883\u53D8\u91CF</h2><p class="modal-subtitle" id="env-preview-subtitle">\u8FD9\u4E9B\u53D8\u91CF\u4F1A\u88AB\u4F20\u7ED9 claude / codex / opencode\uFF08PTY \u4E0E\u7ED3\u6784\u5316\u8FD0\u884C\u5668\u4E00\u81F4\uFF09\u3002</p></div><button id="env-preview-close" class="btn btn-ghost btn-icon modal-close-btn" type="button" aria-label="\u5173\u95ED"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><line x1="6" y1="6" x2="18" y2="18"/><line x1="18" y1="6" x2="6" y2="18"/></svg></button></div><div class="modal-body env-preview-body"><div class="env-preview-toolbar"><div class="env-preview-meta" id="env-preview-meta">\u52A0\u8F7D\u4E2D\u2026</div><div class="env-preview-controls"><input id="env-preview-search" class="env-preview-search" type="search" placeholder="\u641C\u7D22\u53D8\u91CF\u540D\u2026" /><label class="env-preview-reveal"><input id="env-preview-reveal-toggle" type="checkbox" /><span>\u663E\u793A\u654F\u611F\u503C</span></label></div></div><div class="env-preview-list" id="env-preview-list" tabindex="0"><div class="env-preview-loading">\u52A0\u8F7D\u4E2D\u2026</div></div></div><div class="modal-footer env-preview-footer"><span class="env-preview-hint">\u654F\u611F\u5B57\u6BB5\uFF08\u542B KEY/TOKEN/SECRET \u7B49\uFF09\u9ED8\u8BA4\u63A9\u7801\uFF0C\u53EF\u52FE\u9009\u300C\u663E\u793A\u654F\u611F\u503C\u300D\u4E34\u65F6\u8FD8\u539F\u3002</span><button id="env-preview-close-2" class="btn btn-secondary btn-sm" type="button">\u5173\u95ED</button></div></div>',document.body.appendChild(e),e.addEventListener("click",function(s){s.target===e&&Nu()});var t=e.querySelector("#env-preview-close");t&&t.addEventListener("click",Nu);var n=e.querySelector("#env-preview-close-2");n&&n.addEventListener("click",Nu);var a=e.querySelector("#env-preview-search");a&&a.addEventListener("input",function(){id()});var i=e.querySelector("#env-preview-reveal-toggle");i&&i.addEventListener("change",function(){rd(i.checked)})}e.classList.remove("closing"),e.classList.remove("hidden");var i=e.querySelector("#env-preview-reveal-toggle");i&&(i.checked=!1);var a=e.querySelector("#env-preview-search");a&&(a.value=""),rd(!1)}function Nu(){var e=document.getElementById("env-preview-modal");e&&Vu(e)}function rd(e){var t=document.getElementById("env-preview-list"),n=document.getElementById("env-preview-meta");t&&(t.innerHTML='<div class="env-preview-loading">\u52A0\u8F7D\u4E2D\u2026</div>'),n&&(n.textContent="\u52A0\u8F7D\u4E2D\u2026");var i="/api/settings/env-preview"+(e?"?reveal=1":"");fetch(i,{credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(!a||!Array.isArray(a.entries)){t&&(t.innerHTML='<div class="env-preview-empty">\u8BFB\u53D6\u5931\u8D25\u3002</div>'),n&&(n.textContent="\u8BFB\u53D6\u5931\u8D25");return}if(r._envPreview=a,n){var u=a.inheritEnv?"\u7EE7\u627F\u7236\u8FDB\u7A0B":"\u6700\u5C0F\u767D\u540D\u5355";n.innerHTML='<span class="env-preview-pill '+(a.inheritEnv?"is-inherit":"is-minimal")+'">'+u+'</span><span class="env-preview-count">\u5171 '+a.total+" \u9879</span>"}id()}).catch(function(){t&&(t.innerHTML='<div class="env-preview-empty">\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002</div>'),n&&(n.textContent="\u8BFB\u53D6\u5931\u8D25")})}function id(){var e=document.getElementById("env-preview-list");if(e){var t=r._envPreview;if(!t||!Array.isArray(t.entries)){e.innerHTML='<div class="env-preview-empty">\u5C1A\u672A\u52A0\u8F7D\u3002</div>';return}for(var n=document.getElementById("env-preview-search"),i=(n&&n.value||"").trim().toLowerCase(),a="",u=0,o=0;o<t.entries.length;o++){var s=t.entries[o];if(!(i&&s.name.toLowerCase().indexOf(i)===-1)){u++;var l=typeof s.value=="string"&&s.value.charAt(0)==="<"&&s.value.charAt(s.value.length-1)===">";a+='<div class="env-preview-row'+(s.sensitive?" is-sensitive":"")+'"><div class="env-preview-name">'+p(s.name)+(s.sensitive?'<span class="env-preview-badge" title="\u88AB\u8BC6\u522B\u4E3A\u654F\u611F\u5B57\u6BB5">\u654F\u611F</span>':"")+(l?'<span class="env-preview-badge env-preview-badge-runtime" title="\u6309\u4F1A\u8BDD\u52A8\u6001\u6CE8\u5165">\u8FD0\u884C\u65F6</span>':"")+'</div><div class="env-preview-value'+(l?" is-runtime":"")+'" title="'+p(String(s.value))+'">'+p(String(s.value))+'</div><div class="env-preview-len">'+s.length+" \u5B57\u7B26</div></div>"}}u===0&&(a='<div class="env-preview-empty">\u6CA1\u6709\u5339\u914D\u7684\u53D8\u91CF\u3002</div>'),e.innerHTML=a}}function ad(e){return e==="codex"?r.availableCodexModels||[]:e==="opencode"?r.availableOpenCodeModels||[]:r.availableModels||[]}function ud(e){if(e){var t=ct(e.getAttribute("data-provider")),n=e.querySelector(".model-combobox-input"),i=e.closest(".settings-model-field"),a=i?i.querySelector("[data-model-status]"):null;if(!(!n||!a)){for(var u=(n.value||"").trim(),o=ad(t),s=null,l=0;l<o.length;l++)if(o[l].id===u){s=o[l];break}if(a.classList.remove("is-custom","is-known"),!u){a.textContent="\u8DDF\u968F CLI \u9ED8\u8BA4";return}if(s){s.availability==="verified"?a.textContent="\u5DF2\u7531 Claude Code \u9A8C\u8BC1":s.availability==="stale"?a.textContent="\u9A8C\u8BC1\u8BB0\u5F55\u5F85\u5237\u65B0":s.source==="models-api"?a.textContent="API \u5019\u9009\uFF0C\u5C1A\u672A\u9A8C\u8BC1":a.textContent="\u5DF2\u68C0\u6D4B\u5230\uFF0C\u5C1A\u672A\u9A8C\u8BC1",a.classList.add("is-known");return}a.textContent="\u81EA\u5B9A\u4E49\u540D\u79F0",a.classList.add("is-custom")}}}function cr(e){if(e){var t=ct(e.getAttribute("data-provider")),n=e.querySelector(".model-combobox-input"),i=e.querySelector(".model-combobox-menu");if(!(!n||!i)){for(var a=n.value||"",u=a.trim(),o=e.classList.contains("is-filtering")?u.toLowerCase():"",s=ad(t),l=null,d=!1,f=[],c=0;c<s.length;c++){var v=s[c];if(v.id==="default"){l=v;continue}v.id===u&&(d=!0);var h=v.label||v.id;if(!(o&&v.id.toLowerCase().indexOf(o)===-1&&h.toLowerCase().indexOf(o)===-1)){var m=t!=="claude"?h===v.id?"\u5DF2\u68C0\u6D4B\u6A21\u578B":v.id:v.availability==="verified"?"\u5DF2\u7531 Claude Code \u9A8C\u8BC1":v.availability==="stale"?"\u9A8C\u8BC1\u8BB0\u5F55\u5F85\u5237\u65B0":v.source==="models-api"?"API \u5019\u9009\uFF0C\u5C1A\u672A\u9A8C\u8BC1":v.note||"\u5C1A\u672A\u9A8C\u8BC1";f.push({value:v.id,label:h,meta:m,custom:!1})}}var g=t==="codex"?"\u8DDF\u968F Codex \u9ED8\u8BA4":t==="opencode"?"\u8DDF\u968F OpenCode \u9ED8\u8BA4":"\u8DDF\u968F Claude Code \u9ED8\u8BA4",y=l&&l.label?l.label:"\u4E0D\u4F20 --model \u53C2\u6570",B="";(!o||g.toLowerCase().indexOf(o)!==-1||y.toLowerCase().indexOf(o)!==-1)&&(B+='<button type="button" class="model-combobox-option'+(u?"":" is-selected")+'" role="option" aria-selected="'+(u?"false":"true")+'" data-model-value=""><span class="model-combobox-option-check" aria-hidden="true"><svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 4 4L19 6"/></svg></span><span class="model-combobox-option-copy"><span class="model-combobox-option-label">'+p(g)+'</span><span class="model-combobox-option-meta">'+p(y)+"</span></span></button>");for(var E=0;E<f.length;E++){var C=f[E],D=C.value===u;B+='<button type="button" class="model-combobox-option'+(D?" is-selected":"")+'" role="option" aria-selected="'+(D?"true":"false")+'" data-model-value="'+p(C.value)+'"><span class="model-combobox-option-check" aria-hidden="true"><svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 4 4L19 6"/></svg></span><span class="model-combobox-option-copy"><span class="model-combobox-option-label">'+p(C.label)+'</span><span class="model-combobox-option-meta">'+p(C.meta)+"</span></span></button>"}u&&!d&&(B+='<button type="button" class="model-combobox-option model-combobox-option-custom is-selected" role="option" aria-selected="true" data-model-value="'+p(u)+'"><span class="model-combobox-option-custom-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z"/></svg></span><span class="model-combobox-option-copy"><span class="model-combobox-option-label">\u4F7F\u7528\u81EA\u5B9A\u4E49\u540D\u79F0</span><span class="model-combobox-option-meta">'+p(u)+"</span></span></button>"),B||(B='<div class="model-combobox-empty">\u6CA1\u6709\u5339\u914D\u7684\u6A21\u578B\uFF0C\u53EF\u4EE5\u7EE7\u7EED\u8F93\u5165\u81EA\u5B9A\u4E49\u540D\u79F0\u3002</div>'),i.innerHTML=B;for(var F=i.querySelectorAll(".model-combobox-option"),L=-1,S=0;S<F.length;S++)if(F[S].getAttribute("aria-selected")==="true"){L=S;break}e._wandModelActiveIndex=L>=0?L:F.length?0:-1,od(e),ud(e)}}}function od(e){if(e){var t=e.querySelector(".model-combobox-menu"),n=e.querySelector(".model-combobox-input");if(!(!t||!n)){for(var i=t.querySelectorAll(".model-combobox-option"),a=typeof e._wandModelActiveIndex=="number"?e._wandModelActiveIndex:-1,u=0;u<i.length;u++)i[u].classList.toggle("is-active",u===a),u===a&&(i[u].id||(i[u].id=(t.id||"model-listbox")+"-option-"+u),n.setAttribute("aria-activedescendant",i[u].id));a<0&&n.removeAttribute("aria-activedescendant")}}}function ia(e){if(e){var t=e.querySelector(".model-combobox-input"),n=e.querySelector(".model-combobox-menu");!t||!n||(document.querySelectorAll(".model-combobox.is-open").forEach(function(i){i!==e&&Dn(i)}),cr(e),e.classList.add("is-open"),n.classList.remove("hidden"),t.setAttribute("aria-expanded","true"))}}function Dn(e){if(e){var t=e.querySelector(".model-combobox-input"),n=e.querySelector(".model-combobox-menu");e.classList.remove("is-open"),e.classList.remove("is-filtering"),n&&n.classList.add("hidden"),t&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"))}}function sd(e,t){if(e){var n=e.querySelector(".model-combobox-input");if(n){var i=document.activeElement===n;n.value=t||"",n.dataset.modelInitialized="true",n.dataset.modelDirty="true",e.classList.remove("is-filtering"),ud(e),Dn(e),i&&n.focus()}}}function tg(){window.__wandSettingsModelOutsideBound||(window.__wandSettingsModelOutsideBound=!0,document.addEventListener("click",function(t){var n=t.target;document.querySelectorAll(".model-combobox.is-open").forEach(function(i){(!n||!i.contains(n))&&Dn(i)})}));var e=document.querySelectorAll(".model-combobox");e.forEach(function(t){if(t.dataset.bound!=="true"){t.dataset.bound="true";var n=t.querySelector(".model-combobox-input"),i=t.querySelector(".model-combobox-toggle"),a=t.querySelector(".model-combobox-menu");!n||!i||!a||(n.addEventListener("focus",function(){ia(t)}),n.addEventListener("input",function(){n.dataset.modelInitialized="true",n.dataset.modelDirty="true",t.classList.add("is-filtering"),ia(t)}),n.addEventListener("keydown",function(u){if(u.key==="Escape"){u.preventDefault(),Dn(t);return}if(!(u.key!=="ArrowDown"&&u.key!=="ArrowUp"&&u.key!=="Enter")){if(!t.classList.contains("is-open")){if(u.key==="Enter")return;ia(t)}var o=a.querySelectorAll(".model-combobox-option");if(o.length){u.preventDefault();var s=typeof t._wandModelActiveIndex=="number"?t._wandModelActiveIndex:-1;if(u.key==="ArrowDown"&&(s=s<o.length-1?s+1:0),u.key==="ArrowUp"&&(s=s>0?s-1:o.length-1),t._wandModelActiveIndex=s,od(t),u.key==="Enter"){var l=o[s];l&&sd(t,l.getAttribute("data-model-value")||"")}else{var d=o[s];d&&typeof d.scrollIntoView=="function"&&d.scrollIntoView({block:"nearest"})}}}}),i.addEventListener("mousedown",function(u){u.preventDefault()}),i.addEventListener("click",function(){t.classList.contains("is-open")?Dn(t):ia(t)}),a.addEventListener("mousedown",function(u){u.preventDefault()}),a.addEventListener("click",function(u){var o=u.target.closest(".model-combobox-option");o&&sd(t,o.getAttribute("data-model-value")||"")}),t.addEventListener("focusout",function(){setTimeout(function(){t.contains(document.activeElement)||Dn(t)},0)}),cr(t))}})}function aa(e){var t=document.getElementById("cfg-commit-cli"),n=document.getElementById("cfg-commit-model-combobox"),i=document.getElementById("cfg-commit-model"),a=document.getElementById("cfg-commit-model-provider");if(!(!t||!n||!i)){var u=ct(t.value);n.setAttribute("data-provider",u),i.placeholder=u==="codex"?"\u8DDF\u968F Codex \u9ED8\u8BA4":u==="opencode"?"\u8DDF\u968F OpenCode \u9ED8\u8BA4":"\u8DDF\u968F Claude Code \u9ED8\u8BA4",a&&(a.textContent=u==="codex"?"Codex CLI":u==="opencode"?"OpenCode CLI":"Claude Code"),e&&(i.value="",i.dataset.modelDirty="true"),cr(n)}}function ua(e){var t=Hu(),n=document.getElementById("cfg-default-model");if(n){n.dataset.modelInitialized!=="true"&&(n.value=r.configDefaultModels&&r.configDefaultModels.claude||t.claude||"",n.dataset.modelInitialized="true");var i=n.closest(".model-combobox");i&&cr(i)}var a=document.getElementById("cfg-default-codex-model");if(a){a.dataset.modelInitialized!=="true"&&(a.value=r.configDefaultModels&&r.configDefaultModels.codex||t.codex||"",a.dataset.modelInitialized="true");var u=a.closest(".model-combobox");u&&cr(u)}var o=document.getElementById("cfg-default-opencode-model");if(o){o.dataset.modelInitialized!=="true"&&(o.value=r.configDefaultModels&&r.configDefaultModels.opencode||t.opencode||"",o.dataset.modelInitialized="true");var s=o.closest(".model-combobox");s&&cr(s)}var l=document.getElementById("cfg-default-model-version");l&&e&&(l.textContent=e.claudeVersion?"\u5DF2\u68C0\u6D4B\u5230 Claude CLI "+e.claudeVersion+"\uFF1B\u5217\u8868\u5DF2\u540C\u6B65 Codex \u4E0E OpenCode \u53EF\u7528\u6A21\u578B\u3002":"\u672A\u8BFB\u53D6\u5230 Claude CLI \u7248\u672C\uFF1B\u4ECD\u53EF\u76F4\u63A5\u8F93\u5165\u81EA\u5B9A\u4E49\u6A21\u578B\u540D\u79F0\u3002")}function Xe(){if(!r.selectedId)return null;for(var e=0;e<r.sessions.length;e++)if(r.sessions[e].id===r.selectedId)return r.sessions[e];return null}function ng(e){var t=(e||"").trim(),n=Xe(),i=Yr(n);na(i,t),n&&Zi(n.id,"model",t);var a=!1;if(Zr(n).some(function(s){return s.id===ra(n)})||(a=!0,Xl("off"),n&&Zi(n.id,"thinking","off")),tn(),!!n){var u={ok:!1,error:""};if(Ou(n.id,function(){return fetch("/api/sessions/"+encodeURIComponent(n.id)+"/model",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({model:t||null})}).then(function(s){return s.json()}).then(function(s){return u.ok=!!(s&&s.id&&!s.error),u.error=s&&s.error?s.error:"",s})}).then(function(s){if(!a&&Pu(n.id,s)&&typeof x=="function"){var l=Gr(t,Xe()||n),d=n.provider==="codex"?"\uFF08\u4E0B\u6B21\u5BF9\u8BDD\u751F\u6548\uFF09":"";x("\u5DF2\u5207\u6362\u6A21\u578B \u2192 "+l+d,"success")}}).catch(function(s){u.ok=!1,!a&&s&&s.latest&&Jr(n.id,"\u5207\u6362\u6A21\u578B\u5931\u8D25")}),a){var o=Gr(t,n);Zl(n,"off","\u5DF2\u5207\u6362\u6A21\u578B \u2192 "+o+"\uFF1B\u601D\u8003\u6DF1\u5EA6\u5DF2\u56DE\u843D\u4E3A\u81EA\u52A8",u)}}}function rg(e){var t=dt($e(),(e||"default").trim());r.chatMode=t,tn();var n=Xe();if(!n||!n.id){x&&x("\u65B0\u4F1A\u8BDD\u6A21\u5F0F\uFF1A"+t,"info");return}Zi(n.id,"mode",t),Ou(n.id,function(){return fetch("/api/sessions/"+encodeURIComponent(n.id)+"/mode",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({mode:t})}).then(function(i){return i.json()})}).then(function(i){if(Pu(n.id,i)&&typeof x=="function"){var a=r.sessions.find(function(s){return s.id===n.id})||n,u=a.mode||t;r.chatMode=dt(a.provider||$e(),u),tn();var o=n.provider==="codex"?"\uFF08Codex \u56FA\u5B9A\u5168\u6743\u9650\uFF09":"";x("\u5DF2\u5207\u6362\u6A21\u5F0F \u2192 "+u+o,"success")}}).catch(function(i){i&&i.latest&&Jr(n.id,"\u5207\u6362\u6A21\u5F0F\u5931\u8D25")})}function ld(e,t,n,i){var a=ct(r.sessionTool),u=Qr(a),o=r.chatThinking||"off",s={cwd:t||Qe(),mode:n||r.chatMode||r.config&&r.config.defaultMode||"default",provider:a,runner:a==="codex"?"codex-cli-exec":a==="opencode"?"opencode-cli-run":r.config&&r.config.structuredRunner==="sdk"?"claude-sdk":r.structuredRunner||"claude-cli-print",prompt:e||void 0,worktreeEnabled:i===!0,model:u||void 0,thinkingEffort:o,sessionSource:"interactive"};return fetch("/api/structured-sessions",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(s)}).then(function(l){return l.json()}).then(function(l){if(l.error)throw new Error(l.error);return r.selectedId=l.id,Ee(),r.drafts[l.id]="",Dt(),ee(l),pe(),jr(l.id),Gn(l.id),kn(l.id).then(function(){return l})})}function oa(){var e=!!r.selectedId,t=document.getElementById("output"),n=document.getElementById("chat-output"),i=document.getElementById("blank-chat"),a=r.sessions.find(function(l){return l.id===r.selectedId}),u=se(a),o=e&&!u&&r.currentView==="terminal",s=e&&(u||r.currentView!=="terminal");u?r.currentView="chat":e||(r.currentView="terminal"),t&&(t.classList.toggle("active",o),t.classList.toggle("hidden",!o)),n&&(n.classList.toggle("active",s),n.classList.toggle("hidden",!s)),i&&i.classList.toggle("hidden",e),n&&s&&yu(n),Er(),Ge(),Rr()}function fr(){var e=document.getElementById("mode-description"),t=document.getElementById("session-kind-description"),n=r.sessionTool||"claude",i=r.sessionCreateKind||"structured";r.sessionTool=n,r.modeValue=dt(n,r.modeValue||r.chatMode||"default");var a=document.querySelectorAll("#provider-cards .provider-card");a.length&&a.forEach(function(s){var l=s.getAttribute("data-provider");s.classList.toggle("active",l===n),s.classList.remove("disabled")});var u=document.querySelectorAll("#session-kind-cards .session-kind-card");u.length&&u.forEach(function(s){var l=s.getAttribute("data-session-kind"),d=!1;s.classList.toggle("active",l===i),s.classList.toggle("disabled",d)});var o=document.querySelectorAll("#mode-cards .mode-card");o.length&&o.forEach(function(s){s.classList.toggle("active",s.getAttribute("data-mode")===r.modeValue)}),t&&(t.textContent=Ko(i)),e&&(e.textContent=Rl(n,r.modeValue))}function ee(e){if(!(!e||!e.id)){var t=r.sessions.find(function(s){return s.id===e.id})||null,n=Gd(e,t);if(Array.isArray(n.messages)&&typeof n.messageOffset=="number"){var i=zd(t,n.messages,n.messageOffset,n.messageTotal);n.messages=i.messages,n.messageOffset=i.messageOffset,n.messageTotal=i.messageTotal}var a=!1,u=null;r.sessions=r.sessions.map(function(s){return s.id!==n.id?s:(u=s,a=!0,Object.assign({},s,n))}),a||r.sessions.unshift(n);var o=r.sessions.find(function(s){return s.id===n.id})||n;o&&Array.isArray(o.queuedMessages)&&n.id===r.selectedId&&(vi(o),fo(),Fn()),n.id===r.selectedId&&(du(),$t()),n.status&&n.status!=="running"&&r.crossSessionQueue.length>0&&setTimeout(Pi,0)}}function Gn(e){!e||!r.ws||r.ws.readyState!==WebSocket.OPEN||r.ws.send(JSON.stringify({type:"subscribe",sessionId:e}))}function ig(e,t){if(!e)return t;var n=Object.assign({},e,t),i=e.output||"",a=t.output||"",u=i.length>a.length,o=e.structuredState||null,s=t.structuredState||null,l=e.sessionKind==="structured"||t.sessionKind==="structured",d=!!(e.messages&&e.messages.length&&(function(){var g=e.messages[e.messages.length-1];return g&&g.role==="assistant"&&Array.isArray(g.content)&&g.content.some(function(y){return y&&y.__processing})})()),f=Array.isArray(e.messages)?l?Cr(e.messages):e.messages:[],c=Array.isArray(t.messages)?l?Cr(t.messages):t.messages:[],v=c.length>0&&(function(){var g=c[c.length-1];return g&&g.role==="assistant"&&Array.isArray(g.content)&&!g.content.some(function(y){return y&&y.__processing})})(),h=e.sessionKind==="structured"&&!!o&&o.inFlight===!0&&(!s||s.inFlight!==!0)&&d&&!!o.activeRequestId&&!!s&&!!s.activeRequestId&&s.activeRequestId===o.activeRequestId&&!v,m=f.length>c.length||f.length>0&&c.length>0&&JSON.stringify(f[f.length-1])!==JSON.stringify(c[c.length-1])&&JSON.stringify(f).length>JSON.stringify(c).length;return u&&(n.output=i),h&&(n.status=e.status||n.status,n.structuredState=Object.assign({},s||{},o,{inFlight:!0}),n.messages=e.messages),m&&(n.messages=f),e.id===r.selectedId&&(e.permissionBlocked&&t.permissionBlocked===!1||e.permissionBlocked&&!t.permissionBlocked&&(n.permissionBlocked=!0),e.pendingEscalation&&!t.pendingEscalation&&t.permissionBlocked!==!1&&(n.pendingEscalation=e.pendingEscalation),e.messages&&e.messages.length>0&&(!t.messages||t.messages.length===0)&&(n.messages=e.messages)),n}function Ze(e,t,n){if(e&&e.messages&&e.messages.length>0)return e.messages;if(e&&e.sessionKind==="structured")return[];if(!n)return[];var i=typeof t=="string"?t:e&&e.output||"";return i?nm(i,e&&e.command):[]}function ag(e){if(!e||!e.length)return null;if(r.selectedId){var t=e.find(function(a){return a.id===r.selectedId});return t?t.id:null}var n=e.find(function(a){return a.status==="running"});if(n)return n.id;var i=e.find(function(a){return!a.archived});return i?i.id:e[0].id}function nn(e){var t=e||{};return fetch("/api/sessions",{credentials:"same-origin"}).then(function(n){if(n.status===401){Nl();return}return n.json()}).then(function(n){var i=n||[],a=new Set(i.map(function(c){return c.id}));Object.keys(r.drafts).forEach(function(c){a.has(c)||delete r.drafts[c]}),r.sessions=i.map(function(c){var v=r.sessions.find(function(h){return h.id===c.id});return ig(v,c)});var u=ag(r.sessions);if(u!==void 0&&(r.selectedId=u),vo(),Fn(),r.bootstrapping=!1,Ee(),r.modalOpen)pe();else{var o=document.getElementById("sessions-list"),s=Ma();if(o&&o.innerHTML===s){var l=document.getElementById("session-count");l&&(l.textContent=String(r.sessions.length))}else{o&&(o.innerHTML=s,Wt(o));var l=document.getElementById("session-count");l&&(l.textContent=String(r.sessions.length))}}ei(),r.selectedId&&r.gitStatusSessionId!==r.selectedId&&Hn(r.selectedId);var d=Promise.resolve();if(!t.skipSelectedOutputReload&&r.selectedId)d=kn(r.selectedId);else if(r.selectedId){var f=r.sessions.find(function(c){return c.id===r.selectedId});se(f)&&(Dt({preserveStickState:!0}),hu(!0))}return d.then(function(){r.crossSessionQueue.length>0&&Pi(),At(),Za()})}).catch(function(n){var i=n&&n.message||"",a=i==="Failed to fetch"||i==="NetworkError when attempting to fetch resource."||i==="Load failed"||/aborted|aborterror|networkerror|failed to fetch/i.test(i);a||console.error("[wand] loadSessions failed:",n)})}var ju=null;function Ru(){ju||(ju=setTimeout(function(){ju=null,pe()},200))}function pe(){var e=document.getElementById("sessions-list"),t=document.getElementById("session-count");e&&(e.innerHTML=Ma(),Wt(e)),t&&(t.textContent=String(r.sessions.length)),typeof rn=="function"&&rn(),ei(),r.crossSessionQueue.length>0&&At()}function ei(){var e=r.sessions.find(function(m){return m.id===r.selectedId});e||(Kn(!1),lu(),rl());var t=e?lr(e.command):"Wand",n=e?Dr(e):"\u5F00\u59CB\u5BF9\u8BDD",i=document.querySelector(".session-summary-value"),a=document.getElementById("terminal-title"),u=document.getElementById("terminal-info"),o=document.querySelector(".topbar-session-title, .topbar-tagline");o&&e&&(o.classList.remove("topbar-tagline"),o.classList.add("topbar-session-title"),o.textContent=e.title||lr(e.command),o.setAttribute("title",e.description||e.command||""));var s=document.getElementById("blank-chat"),l=document.getElementById("output"),d=document.getElementById("chat-output"),f=document.getElementById("stop-button");i&&i.textContent!==t&&(i.textContent=t),a&&a.textContent!==t&&(a.textContent=t),u&&(u.textContent=e?n+" \xB7 "+Km(e):n);var c=document.getElementById("session-kind-display"),v=e?Um(e):"\u7EC8\u7AEF";c&&c.textContent!==v&&(c.textContent=v),os(),!r.terminal&&l&&e&&ur(),r.terminal&&l&&!l.contains(r.terminal.element)&&(Mr(),ur()),e||(r.terminalSessionId=null,r.terminalOutput="",r.terminalOutputMarker=0),r.terminal&&e&&r.currentView==="terminal"&&yt("view");var h=document.querySelector(".input-panel");e?(s&&s.classList.add("hidden"),l&&l.classList.remove("hidden"),d&&d.classList.remove("hidden"),h&&h.classList.remove("hidden")):(s&&s.classList.remove("hidden"),l&&l.classList.add("hidden"),d&&d.classList.add("hidden"),f&&f.classList.add("hidden"),h&&h.classList.add("hidden")),Qi(),dr(Xe()),oa(),du()}function kn(e){r.chatRenderTimer&&(clearTimeout(r.chatRenderTimer),r.chatRenderTimer=null);var t=r.sessions.find(function(i){return i.id===e}),n="/api/sessions/"+e;return zl(t)&&(n+="?format=chat"),fetch(n,{credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i.error){r.selectedId===e&&(r.selectedId=null,Ee()),nn();return}if(ee(i),ei(),r.terminal&&e===r.selectedId&&i.output!==void 0){var a=!!r.ws&&(r.ws.readyState===WebSocket.OPEN||r.ws.readyState===WebSocket.CONNECTING);a?Ye("session-switch"):(Si(e,i.output,{mode:"append"}),Ye("session-switch",{forceReplay:!0}))}var u=r.sessions.find(function(o){return o.id===e});r.currentMessages=Re(u,Ze(u,i.output,!1)),We(!1)})}var Wu=!1;function ug(){if(Wu)return!1;var e=r.selectedId;if(!e)return!1;var t=r.sessions.find(function(o){return o.id===e});if(!t)return!1;var n=typeof t.messageOffset=="number"?t.messageOffset:0;if(n<=0)return!1;var i=40,a=Math.max(0,n-i),u=n-a;return Wu=!0,fetch("/api/sessions/"+encodeURIComponent(e)+"/messages?offset="+a+"&limit="+u,{credentials:"same-origin"}).then(function(o){return o.json()}).then(function(o){if(o&&Array.isArray(o.messages)&&t.messageOffset===n){var s=Array.isArray(t.messages)?t.messages:[];t.messages=o.messages.concat(s),t.messageOffset=a,typeof o.total=="number"&&(t.messageTotal=o.total),e===r.selectedId&&(r.currentMessages=Re(t,Ze(t,t.output,!1)),r.chatRenderedCount=r.currentMessages.length,We(!0))}}).catch(function(){}).finally(function(){Wu=!1}),!0}function Nt(e){var t=r.sessions.find(function(o){return o.id===e});if(t){r.selectedId!==e&&Mr(),r.selectedId=e,Ee(),r.toolContentCache={},r.messageQueue=[],r.pendingMessages=[],vi(t),vo(),Fn(),Dt(),r.currentMessages=[],r.chatRenderTimer&&(clearTimeout(r.chatRenderTimer),r.chatRenderTimer=null);var n=document.getElementById("todo-progress");n&&n.classList.add("hidden");var i=document.querySelector(".structured-status-bar");i&&i.remove(),r._statusBarTimerId&&(clearInterval(r._statusBarTimerId),r._statusBarTimerId=null),r._statusBarStartTime=0;var a=document.querySelector(".input-composer");a&&a.classList.remove("in-flight");var u=t;r.preferredCommand=$e(),r.chatMode=dt("claude",u&&u.mode?u.mode:r.chatMode),r.terminalInteractive&&u&&u.status!=="running"&&Kn(!1),pe(),jr(e),r.filePanelOpen&&(Zd(u),Mt()),kn(e).then(function(){Ht(!0)}),Gn(e),r.gitStatus=null,r.gitStatusSessionId=null,xa(),Hn(e,{force:!0})}}function og(){var e=document.getElementById("sessions-drawer"),t=document.querySelector(".main-layout"),n=Ne(),i=!!r.sidebarPinned&&!!r.sidebarCollapsed,a=i||!n&&(!!r.sidebarPinned||!!r.sessionsDrawerOpen);e&&(e.classList.toggle("pinned",a),e.classList.toggle("collapsed",i)),t&&(t.classList.toggle("sidebar-pinned",a),t.classList.toggle("sidebar-collapsed",i));var u=document.getElementById("sidebar-pin-btn");u&&(u.classList.toggle("pinned",!!r.sidebarPinned),u.title=r.sidebarPinned?"\u5DF2\u56FA\u5B9A\u5E38\u9A7B\uFF08\u70B9\u51FB\u89E3\u9664\u9501\u5B9A\uFF09":"\u56FA\u5B9A\u4FA7\u680F\u5E38\u9A7B",u.setAttribute("aria-label",r.sidebarPinned?"\u89E3\u9664\u56FA\u5B9A\u5E38\u9A7B":"\u56FA\u5B9A\u4FA7\u680F\u5E38\u9A7B"),u.setAttribute("aria-pressed",r.sidebarPinned?"true":"false"))}function ti(){var e=document.getElementById("sessions-drawer"),t=document.getElementById("sessions-drawer-backdrop"),n=document.querySelector(".main-layout");e&&e.classList.toggle("open",r.sessionsDrawerOpen),t&&t.classList.toggle("open",bo()),n&&n.classList.toggle("sidebar-open",r.sessionsDrawerOpen);var i=document.getElementById("sessions-toggle-button");i&&i.classList.toggle("active",r.sessionsDrawerOpen),og()}function sg(){var e=Ne();if(!e){var t=r.sidebarPinned?!1:!r.sessionsDrawerOpen;r.sessionsDrawerOpen=t,t&&(r.sidebarCollapsed=!1,we("wand-sidebar-collapsed",!1)),we("wand-sidebar-open",r.sessionsDrawerOpen),hn(),ri();return}if(r.sessionsDrawerOpen=!r.sessionsDrawerOpen,we("wand-sidebar-open",r.sessionsDrawerOpen),r.sessionsDrawerOpen){r.filePanelOpen=!1;try{localStorage.setItem("wand-file-panel-open","false")}catch{}}hn()}function ni(){var e=Ne();if(!e){if(!r.sidebarPinned&&!r.sessionsDrawerOpen)return;Vr(),r.sidebarPinned=!1,r.sessionsDrawerOpen=!1,we("wand-sidebar-pinned",!1),we("wand-sidebar-open",!1),hn(),ri();return}r.sessionsDrawerOpen&&(Vr(),r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),hn())}function lg(){if(Ne()){ni();return}r.sidebarPinned||r.sidebarCollapsed||!r.sessionsDrawerOpen||(Vr(),r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),hn(),ri())}function dd(e){var t=document.getElementById("composer-plus-popover"),n=document.getElementById("attach-btn");r.plusPopoverOpen=!!e,t&&t.classList.toggle("hidden",!e),n&&(n.classList.toggle("active",!!e),n.setAttribute("aria-expanded",e?"true":"false"))}function dg(){dd(!r.plusPopoverOpen)}function sa(){r.plusPopoverOpen&&dd(!1)}function jt(){Ne()&&r.sessionsDrawerOpen&&ni()}function ri(){var e=document.querySelector(".main-layout");if(e){var t=function(n){n.propertyName==="padding-left"&&(e.removeEventListener("transitionend",t),Pt(!0))};e.addEventListener("transitionend",t)}setTimeout(function(){Pt(!0)},350)}var Rt=null;function cg(){return Rt&&document.body.contains(Rt)||(Rt=document.createElement("div"),Rt.className="sidebar-tile-bubble",Rt.setAttribute("role","tooltip"),document.body.appendChild(Rt)),Rt}function rn(){Rt&&Rt.classList.remove("visible")}function fg(e,t){if(!t){rn();return}var n=cg();n.textContent=t.length>400?t.slice(0,400)+"\u2026":t;var i=e.getBoundingClientRect();n.classList.add("visible");var a=n.getBoundingClientRect(),u=i.top+i.height/2,o=u-a.height/2,s=8,l=window.innerHeight-a.height-8;o<s&&(o=s),o>l&&(o=Math.max(s,l)),n.style.left=i.right+12+"px",n.style.top=o+"px",n.style.setProperty("--bubble-tail-y",u-o+"px")}function pg(e){if(e.dataset.collapsedSessionId){var t=r.sessions.find(function(a){return a.id===e.dataset.collapsedSessionId});if(!t)return"";var n=Mc(t);return n||t.summary||t.command||""}if(e.dataset.collapsedHistoryId){var i=r.claudeHistory.find(function(a){return a.claudeSessionId===e.dataset.collapsedHistoryId});if(i&&i.firstUserMessage)return i.firstUserMessage}return""}function vg(e){var t=e.target;if(!(!t||!(t instanceof Element))){var n=t.closest(".sidebar-collapsed-tile");if(!n){rn();return}var i=pg(n);if(!i){rn();return}fg(n,i)}}function mg(e){var t=e.relatedTarget;t&&t instanceof Element&&t.closest(".sidebar-collapsed-tile")||rn()}function gg(){var e=Ne();r.sidebarPinned||(r.sidebarPinned=!0,we("wand-sidebar-pinned",!0)),r.sidebarCollapsed=!r.sidebarCollapsed,we("wand-sidebar-collapsed",r.sidebarCollapsed),r.sidebarCollapsed?r.sessionsDrawerOpen=!1:e?(r.sidebarPinned=!1,r.sessionsDrawerOpen=!0,we("wand-sidebar-pinned",!1)):r.sessionsDrawerOpen=!0,we("wand-sidebar-open",r.sessionsDrawerOpen),hn(),pe(),yg(),rn(),ri()}function hg(){Ne()||(r.sidebarPinned=!r.sidebarPinned,r.sessionsDrawerOpen=!0,we("wand-sidebar-pinned",r.sidebarPinned),we("wand-sidebar-open",!0),hn(),ri())}function yg(){var e=document.getElementById("sidebar-collapse-btn");if(e){var t=!!r.sidebarPinned&&!!r.sidebarCollapsed;e.classList.toggle("collapsed",t),e.title=t?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4E3A\u7A84\u6761",e.setAttribute("aria-label",t?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4E3A\u7A84\u6761"),e.innerHTML=t?'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="10 6 16 12 10 18"/><line x1="20" y1="5" x2="20" y2="19"/></svg>':'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="14 6 8 12 14 18"/><line x1="4" y1="5" x2="4" y2="19"/></svg>'}}function bg(e){if(e){e.style.left="",e.style.right="";var t=e.offsetParent||e.parentElement;if(t){var n=8,i=t.getBoundingClientRect(),a=e.getBoundingClientRect(),u=window.innerWidth;a.left<n?(e.style.right="auto",e.style.left=n-i.left+"px"):a.right>u-n&&(e.style.left="auto",e.style.right=i.right-(u-n)+"px")}}}function Eg(e){if(!(!e||typeof e!="object")){r.config=e;var t=ct(e.defaultProvider);r.sessionTool=t,r.preferredCommand=t,r.sessionCreateKind=e.defaultSessionKind==="pty"?"pty":"structured",r.modeValue=dt(t,e.defaultMode||"default")}}var la=Promise.resolve();function da(e){return!e||typeof e!="object"?Promise.resolve():(la=la.catch(function(){}).then(function(){return fetch("/api/settings/config",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(e)})}).then(function(t){return t.json().then(function(n){if(!t.ok||n.error)throw new Error(n.error||"\u4FDD\u5B58\u65B0\u5EFA\u4F1A\u8BDD\u504F\u597D\u5931\u8D25");return n.config&&(r.config=n.config),n})}).catch(function(t){console.warn("[wand] Failed to persist new-session defaults",t)}),la)}function zu(){vr(),r.modalOpen=!0,r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),ti();var e=document.getElementById("session-modal");e&&(e._wandCloseTimer&&(clearTimeout(e._wandCloseTimer),e._wandCloseTimer=null),e.classList.remove("closing"),e.classList.remove("hidden"),r.lastFocusedElement=document.activeElement,r.sessionTool=ct(r.config&&r.config.defaultProvider),r.preferredCommand=r.sessionTool,r.sessionCreateKind=r.config&&r.config.defaultSessionKind==="pty"?"pty":"structured",r.sessionCreateWorktree=!1,r.modeValue=dt(r.sessionTool,r.config&&r.config.defaultMode?r.config.defaultMode:"default"),fr(),la.then(function(){return fetch("/api/config",{credentials:"same-origin"})}).then(function(t){return t.ok?t.json():null}).then(function(t){!t||!r.modalOpen||(Eg(t),fr())}).catch(function(){}),Kg(),setTimeout(function(){var t=document.getElementById("mode-cards");t&&t.focus()},20),ca(e))}function An(){r.modalOpen=!1;var e=document.getElementById("session-modal");e&&(r.focusTrapHandler&&(document.removeEventListener("keydown",r.focusTrapHandler),r.focusTrapHandler=null),r.lastFocusedElement&&typeof r.lastFocusedElement.focus=="function"&&r.lastFocusedElement.focus(),Vu(e)),gr()}function Vu(e){if(e&&!e.classList.contains("hidden")){var t=!1;try{t=window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch{}if(t||document.hidden){e.classList.remove("closing"),e.classList.add("hidden");return}e._wandCloseTimer&&(clearTimeout(e._wandCloseTimer),e._wandCloseTimer=null),e.classList.add("closing"),e._wandCloseTimer=setTimeout(function(){e.classList.remove("closing"),e.classList.add("hidden"),e._wandCloseTimer=null},170)}}function ca(e){r.focusTrapHandler&&document.removeEventListener("keydown",r.focusTrapHandler);var t='button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])';r.focusTrapHandler=function(n){if(n.key==="Tab"){var i=e.querySelectorAll(t),a=i[0],u=i[i.length-1];!a||!u||(n.shiftKey?document.activeElement===a&&(n.preventDefault(),u.focus()):document.activeElement===u&&(n.preventDefault(),a.focus()))}},document.addEventListener("keydown",r.focusTrapHandler)}function Fg(){return r.activeWorktreeMergeSessionId&&r.sessions.find(function(e){return e.id===r.activeWorktreeMergeSessionId})||null}function ii(){var e=document.getElementById("worktree-merge-content"),t=document.getElementById("worktree-merge-confirm-button"),n=document.getElementById("worktree-merge-error"),i=Fg(),a=r.worktreeMergeCheckResult;if(!(!e||!t)){if(!i||!i.worktree){e.innerHTML='<p class="field-hint">\u672A\u627E\u5230\u53EF\u5408\u5E76\u7684 worktree \u4F1A\u8BDD\u3002</p>',t.disabled=!0;return}n&&(r.worktreeMergeError?Oe(n,r.worktreeMergeError):Ti(n));var u=['<div class="worktree-merge-row"><span>\u6765\u6E90\u5206\u652F</span><strong>'+p(i.worktree.branch||"-")+"</strong></div>",'<div class="worktree-merge-row"><span>\u5DE5\u4F5C\u76EE\u5F55</span><strong>'+p(i.worktree.path||"-")+"</strong></div>"];a?(u.push('<div class="worktree-merge-row"><span>\u76EE\u6807\u5206\u652F</span><strong>'+p(a.targetBranch||"-")+"</strong></div>"),u.push('<div class="worktree-merge-row"><span>\u5F85\u5408\u5E76\u63D0\u4EA4</span><strong>'+p(String(a.aheadCount||0))+"</strong></div>"),u.push('<div class="worktree-merge-row"><span>\u672A\u63D0\u4EA4\u6539\u52A8</span><strong>'+p(a.hasUncommittedChanges?"\u6709":"\u65E0")+"</strong></div>"),u.push('<div class="worktree-merge-row"><span>\u51B2\u7A81\u98CE\u9669</span><strong>'+p(a.hasConflicts?"\u6709":"\u65E0")+"</strong></div>"),a.reason&&u.push('<p class="field-hint">'+p(a.reason)+"</p>")):r.worktreeMergeLoading&&u.push('<p class="field-hint">\u6B63\u5728\u68C0\u67E5 worktree \u5408\u5E76\u72B6\u6001\u2026</p>'),e.innerHTML=u.join(""),t.disabled=r.worktreeMergeLoading||r.worktreeMergeSubmitting||!a||a.ok!==!0,t.textContent=r.worktreeMergeSubmitting?"\u5408\u5E76\u4E2D...":"\u786E\u8BA4\u5408\u5E76\u5E76\u6E05\u7406"}}function cd(e){r.activeWorktreeMergeSessionId=e,r.worktreeMergeCheckResult=null,r.worktreeMergeLoading=!0,r.worktreeMergeSubmitting=!1,r.worktreeMergeError="",An(),vr();var t=document.getElementById("worktree-merge-modal");t&&(t.classList.remove("hidden"),r.lastFocusedElement=document.activeElement,ca(t)),ii(),fetch("/api/sessions/"+encodeURIComponent(e)+"/worktree/merge/check",{method:"POST",credentials:"same-origin"}).then(function(n){return n.json()}).then(function(n){if(n&&n.error)throw new Error(n.error);n&&n.session&&ee(n.session),r.worktreeMergeCheckResult=n.result||null,r.worktreeMergeError=""}).catch(function(n){r.worktreeMergeError=n&&n.message||"\u65E0\u6CD5\u68C0\u67E5 worktree \u5408\u5E76\u72B6\u6001\u3002"}).finally(function(){r.worktreeMergeLoading=!1,ii()})}function pr(){var e=document.getElementById("worktree-merge-modal");r.activeWorktreeMergeSessionId=null,r.worktreeMergeCheckResult=null,r.worktreeMergeLoading=!1,r.worktreeMergeSubmitting=!1,r.worktreeMergeError="",e&&e.classList.add("hidden"),r.focusTrapHandler&&(document.removeEventListener("keydown",r.focusTrapHandler),r.focusTrapHandler=null),r.lastFocusedElement&&typeof r.lastFocusedElement.focus=="function"&&r.lastFocusedElement.focus()}function Cg(){!r.activeWorktreeMergeSessionId||r.worktreeMergeSubmitting||(r.worktreeMergeSubmitting=!0,r.worktreeMergeError="",ii(),fetch("/api/sessions/"+encodeURIComponent(r.activeWorktreeMergeSessionId)+"/worktree/merge",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}).then(function(e){return e.json()}).then(function(e){if(e&&e.error)throw new Error(e.error);return e&&e.session&&ee(e.session),x("\u5DF2\u5408\u5E76\u5230 "+p(e.result&&e.result.targetBranch||"\u4E3B\u5206\u652F")+(e.result&&e.result.cleanupDone===!1?"\uFF0C\u4F46\u5DE5\u4F5C\u6811\u5F85\u6E05\u7406\u3002":"\u3002"),"info"),pr(),_t()}).catch(function(e){r.worktreeMergeError=e&&e.message||"\u65E0\u6CD5\u5408\u5E76 worktree\u3002",ii()}).finally(function(){r.worktreeMergeSubmitting=!1,ii()}))}function fd(e){fetch("/api/sessions/"+encodeURIComponent(e)+"/worktree/cleanup",{method:"POST",credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(t&&t.error)throw new Error(t.error);return t&&t.session&&ee(t.session),x("\u5DF2\u5B8C\u6210 worktree \u6E05\u7406\u3002","info"),_t()}).catch(function(t){x(t&&t.message||"\u65E0\u6CD5\u6E05\u7406 worktree\u3002","error")})}function wg(){An();var e=document.getElementById("settings-modal");if(e){e._wandCloseTimer&&(clearTimeout(e._wandCloseTimer),e._wandCloseTimer=null),e.classList.remove("closing"),e.classList.remove("hidden"),r.lastFocusedElement=document.activeElement;var t=document.getElementById("new-password"),n=document.getElementById("confirm-password");t&&(t.value=""),n&&(n.value=""),pd(),ca(e),Dg(),e.querySelectorAll(".model-combobox-input").forEach(function(c){c.dataset.modelDirty="false",c.dataset.modelInitialized="false"}),Uu("about"),Sg();var i=document.getElementById("cfg-notif-sound"),a=document.getElementById("cfg-notif-bubble");i&&(i.checked=r.notifSound),a&&(a.checked=r.notifBubble);var u=document.getElementById("cfg-notif-volume"),o=document.getElementById("cfg-notif-volume-val");if(u){u.value=r.notifVolume,o&&(o.textContent=r.notifVolume+"%");try{u.dispatchEvent(new Event("input",{bubbles:!0}))}catch{}}var s=document.getElementById("notif-volume-field");if(s&&(s.style.display=r.notifSound?"":"none"),Sn(),typeof WandNative<"u"&&typeof WandNative.getAppIcon=="function")try{yd(WandNative.getAppIcon()||"shorthair")}catch{}if(je&&typeof WandNative.getNotificationSound=="function")try{var l=document.getElementById("native-sound-select");l&&(l.value=WandNative.getNotificationSound())}catch{}if(je&&typeof WandNative.getNotificationVolume=="function")try{var d=WandNative.getNotificationVolume();if(r.notifVolume=d,u&&(u.value=String(d)),o&&(o.textContent=d+"%"),u)try{u.dispatchEvent(new Event("input",{bubbles:!0}))}catch{}try{localStorage.setItem("wand-notif-volume",String(d))}catch{}}catch{}if(je&&typeof WandNative.isHapticEnabled=="function")try{var f=document.getElementById("cfg-haptic-enabled");f&&(f.checked=WandNative.isHapticEnabled())}catch{}}}function vr(){var e=document.getElementById("settings-modal");e&&(e.querySelectorAll(".model-combobox.is-open").forEach(function(t){Dn(t)}),r.focusTrapHandler&&(document.removeEventListener("keydown",r.focusTrapHandler),r.focusTrapHandler=null),r.lastFocusedElement&&typeof r.lastFocusedElement.focus=="function"&&r.lastFocusedElement.focus(),Vu(e))}function pd(){var e=document.getElementById("settings-error"),t=document.getElementById("settings-success");e&&e.classList.add("hidden"),t&&t.classList.add("hidden")}function Bg(){var e=document.getElementById("new-password").value,t=document.getElementById("confirm-password").value,n=document.getElementById("settings-error"),i=document.getElementById("settings-success");if(pd(),!e||e.length<6){n.textContent="\u5BC6\u7801\u957F\u5EA6\u81F3\u5C11\u4E3A 6 \u4E2A\u5B57\u7B26\u3002",n.classList.remove("hidden");return}if(e!==t){n.textContent="\u4E24\u6B21\u8F93\u5165\u7684\u5BC6\u7801\u4E0D\u4E00\u81F4\u3002",n.classList.remove("hidden");return}fetch("/api/set-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:e}),credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(a.error){n.textContent=a.error,n.classList.remove("hidden");return}i.textContent="\u5BC6\u7801\u4FEE\u6539\u6210\u529F\uFF01",i.classList.remove("hidden"),document.getElementById("new-password").value="",document.getElementById("confirm-password").value=""}).catch(function(){n.textContent="Failed to save password.",n.classList.remove("hidden")})}function Uu(e){document.querySelectorAll(".model-combobox.is-open").forEach(function(s){Dn(s)});for(var t=document.querySelectorAll(".settings-tab"),n=document.querySelectorAll(".settings-panel"),i=0;i<t.length;i++){var a=t[i].getAttribute("data-tab")===e;a?t[i].classList.add("active"):t[i].classList.remove("active"),t[i].setAttribute("aria-selected",a?"true":"false"),t[i].setAttribute("tabindex",a?"0":"-1")}for(var u=0;u<n.length;u++){var o=n[u].id==="settings-tab-"+e;o?(n[u].classList.add("active"),n[u].removeAttribute("hidden")):(n[u].classList.remove("active"),n[u].setAttribute("hidden","hidden"))}}function vd(e){if(e&&!(e.key!=="ArrowUp"&&e.key!=="ArrowDown"&&e.key!=="ArrowLeft"&&e.key!=="ArrowRight"&&e.key!=="Home"&&e.key!=="End")){var t=Array.prototype.slice.call(document.querySelectorAll(".settings-tab"));if(t.length){var n=e.currentTarget&&e.currentTarget.closest?e.currentTarget.closest(".settings-tabs"):null,i=n&&n.getAttribute("aria-orientation")==="horizontal";if(!(i&&(e.key==="ArrowUp"||e.key==="ArrowDown"))&&!(!i&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))){var a=t.indexOf(e.currentTarget);if(a!==-1){e.preventDefault();var u=a;(e.key==="ArrowUp"||e.key==="ArrowLeft")&&(u=a>0?a-1:t.length-1),(e.key==="ArrowDown"||e.key==="ArrowRight")&&(u=a<t.length-1?a+1:0),e.key==="Home"&&(u=0),e.key==="End"&&(u=t.length-1);var o=t[u];if(o){var s=o.getAttribute("data-tab");s&&Uu(s),typeof o.focus=="function"&&o.focus()}}}}}}function Dg(){var e=document.querySelector(".settings-tabs");if(e){var t=!1;try{t=!!(window.matchMedia&&window.matchMedia("(max-width: 760px)").matches)}catch{}e.setAttribute("aria-orientation",t?"horizontal":"vertical")}for(var n=document.querySelectorAll(".settings-tab"),i=0;i<n.length;i++)n[i].removeEventListener("keydown",vd),n[i].addEventListener("keydown",vd)}function kg(e){if(e){var t=e.config||{},n={about:e.version?"\u5F53\u524D v"+e.version:"\u7248\u672C\u4E0E\u66F4\u65B0\u4FE1\u606F",general:[t.defaultMode||"default",t.language||"\u81EA\u52A8\u8BED\u8A00"].filter(Boolean).join(" \xB7 "),notifications:r.notifSound?"\u63D0\u793A\u97F3 "+r.notifVolume+"%":"\u63D0\u793A\u97F3\u5DF2\u5173\u95ED",security:e.hasCert?"\u5DF2\u5B89\u88C5 SSL \u8BC1\u4E66":"\u5BC6\u7801\u4E0E\u8BC1\u4E66\u7BA1\u7406",presets:t.commandPresets&&t.commandPresets.length?t.commandPresets.length+" \u6761\u9884\u8BBE":"\u6682\u65E0\u9884\u8BBE",display:"\u63A7\u5236\u5361\u7247\u9ED8\u8BA4\u5C55\u5F00"};for(var i in n)if(Object.prototype.hasOwnProperty.call(n,i)){var a=document.querySelector('.settings-tab[data-tab="'+i+'"] .settings-tab-meta');a&&(a.textContent=n[i]||"")}}}function Ag(e){var t=document.getElementById("android-connect-qr"),n=document.getElementById("android-connect-qr-empty"),i=window.QRCodeLib;if(t){if(!i||typeof i.toCanvas!="function"){n&&(n.textContent="\u4E8C\u7EF4\u7801\u5E93\u672A\u52A0\u8F7D");return}try{i.toCanvas(t,e,{width:220,margin:1,errorCorrectionLevel:"M",color:{dark:"#1f1b17",light:"#ffffff00"}},function(a){if(a){n&&(n.textContent="\u4E8C\u7EF4\u7801\u751F\u6210\u5931\u8D25",n.style.display=""),t.style.visibility="hidden";return}n&&(n.style.display="none"),t.style.visibility="visible"})}catch{n&&(n.textContent="\u4E8C\u7EF4\u7801\u751F\u6210\u5931\u8D25",n.style.display=""),t.style.visibility="hidden"}}}function xg(e){var t=window.QRCodeLib;if(!t||typeof t.toCanvas!="function")return;var n=document.getElementById("connect-qr-modal");n&&n.remove();var i=document.createElement("div");i.id="connect-qr-modal",i.className="connect-qr-modal-overlay",i.innerHTML='<div class="connect-qr-modal-card"><canvas id="connect-qr-modal-canvas"></canvas><p class="connect-qr-modal-hint">\u7528 Wand App \u626B\u4E00\u626B\uFF0C\u8FDE\u63A5\u5F53\u524D\u670D\u52A1\u5668</p><button type="button" class="btn btn-secondary btn-sm connect-qr-modal-close">\u5173\u95ED</button></div>',document.body.appendChild(i);var a=i.querySelector("#connect-qr-modal-canvas"),u=Math.min(window.innerWidth,window.innerHeight)*.7;u<240&&(u=240),u>480&&(u=480);try{t.toCanvas(a,e,{width:u,margin:2,errorCorrectionLevel:"M",color:{dark:"#1f1b17",light:"#ffffff"}})}catch{}function o(){i.remove()}i.addEventListener("click",function(l){l.target===i&&o()});var s=i.querySelector(".connect-qr-modal-close");s&&s.addEventListener("click",o)}function ai(e,t,n){if(!e)return;function i(){if(or("light"),n){n();return}if(t){var a=t.textContent;t.textContent="\u5DF2\u590D\u5236",setTimeout(function(){t.textContent=a},1500)}}if(je&&typeof WandNative.copyToClipboard=="function")try{if(WandNative.copyToClipboard(e)==="ok"){i();return}}catch{}navigator.clipboard.writeText(e).then(i).catch(function(){var a=document.createElement("textarea");a.value=e,a.style.position="fixed",a.style.opacity="0",document.body.appendChild(a),a.select(),document.execCommand("copy"),document.body.removeChild(a),i()})}function xn(e){if(typeof e!="number"||!isFinite(e)||e<0)return"-";if(e<1024)return e+" B";for(var t=["KB","MB","GB","TB"],n=e/1024,i=0;n>=1024&&i<t.length-1;)n=n/1024,i+=1;var a=n>=10?n.toFixed(0):n.toFixed(1);return a+" "+t[i]}function Sg(){var e=!r.config||r.config.canManageSettings!==!1,t=e?"/api/settings":"/api/settings/about";fetch(t,{credentials:"same-origin"}).then(function(n){if(n.ok)return n.json();if(n.status===403&&t==="/api/settings")return fetch("/api/settings/about",{credentials:"same-origin"}).then(function(i){if(!i.ok)throw new Error("\u65E0\u6CD5\u52A0\u8F7D\u5173\u4E8E\u4FE1\u606F (HTTP "+i.status+")");return i.json()});throw new Error("\u65E0\u6CD5\u52A0\u8F7D\u8BBE\u7F6E (HTTP "+n.status+")")}).then(function(n){var i=n.settingsAccess!=="read-only",a=document.getElementById("settings-about-access-note");a&&a.classList.toggle("hidden",i);var u=document.getElementById("provider-cli-update-section");u&&u.classList.toggle("hidden",!i);var o=document.getElementById("android-connect-section");o&&o.classList.toggle("hidden",!i),["check-update-button","do-update-button","do-restart-button"].forEach(function(K){var ve=document.getElementById(K),me=ve&&ve.closest(".settings-update-actions");me&&me.classList.toggle("hidden",!i)}),["beta-channel-toggle","auto-update-web-toggle"].forEach(function(K){var ve=document.getElementById(K),me=ve&&ve.closest(".settings-toggle-row");me&&me.classList.toggle("hidden",!i)}),kg(n);var s=document.getElementById("settings-pkg-name"),l=document.getElementById("settings-version"),d=document.getElementById("settings-node-req"),f=document.getElementById("settings-repo-url");s&&(s.textContent=n.packageName||"-"),l&&(l.textContent=n.version||"-"),d&&(d.textContent=n.nodeVersion||"-"),f&&n.repoUrl&&(f.innerHTML='<a href="'+p(n.repoUrl)+'" target="_blank" rel="noopener">'+p(n.repoUrl)+"</a>");var c=document.getElementById("settings-latest-version"),v=document.getElementById("do-update-button");n.latestVersion&&c&&(c.textContent=n.latestVersion,n.updateAvailable&&v&&v.classList.remove("hidden"));var h=document.getElementById("beta-channel-toggle");h&&(h.checked=n.updateChannel==="beta");var m=n.autoUpdate||{},g=document.getElementById("auto-update-web-toggle");g&&(g.checked=!!m.web);var y=document.getElementById("auto-update-apk-toggle");y&&(y.checked=!!zn&&!!m.apk);var B=document.getElementById("auto-update-dmg-toggle");B&&(B.checked=!!bn&&!!m.dmg);var E=document.getElementById("auto-update-cli-toggle");E&&(E.checked=!!m.cli),i&&hd(!1);function C(K,ve){As(K,{type:ve==="error"?"danger":"info"})}function D(K,ve,me){var st=me?me.textContent:"";me&&(me.disabled=!0,me.textContent="\u4E0B\u8F7D\u4E2D\u2026");function mt(){me&&(me.disabled=!1,me.textContent=st)}fetch(K,{method:"HEAD",credentials:"same-origin"}).then(function(_e){if(!_e.ok){C(_e.status===404?"\u4E0B\u8F7D\u672A\u542F\u7528\u6216\u6587\u4EF6\u5DF2\u79FB\u9664":"\u4E0B\u8F7D\u5931\u8D25 (HTTP "+_e.status+")","error"),mt();return}var Je=document.createElement("a");Je.href=K,Je.download=ve||"",document.body.appendChild(Je),Je.click(),document.body.removeChild(Je),C("\u5DF2\u5F00\u59CB\u4E0B\u8F7D\uFF0C\u8BF7\u5728\u901A\u77E5\u680F/\u4E0B\u8F7D\u7BA1\u7406\u4E2D\u67E5\u770B","info"),mt()}).catch(function(_e){C("\u4E0B\u8F7D\u5931\u8D25: "+(_e&&_e.message?_e.message:_e),"error"),mt()})}function F(K,ve){function me(Mn){var Yn=String(Mn||"").replace(/^v/,""),pn=Yn.indexOf("-"),Qn=pn>=0?Yn.slice(0,pn):Yn,ce=pn>=0?Yn.slice(pn+1):"";return{parts:Qn.split(".").map(function(si){return parseInt(si,10)||0}),pre:ce,isDebug:ce.indexOf("debug")===0}}for(var st=me(K),mt=me(ve),_e=0;_e<3;_e++){var Je=(st.parts[_e]||0)-(mt.parts[_e]||0);if(Je!==0)return Je>0?1:-1}if(st.isDebug!==mt.isDebug)return st.isDebug?1:-1;if(st.isDebug&&mt.isDebug)for(var Tn=st.pre.split("."),Ln=mt.pre.split("."),gt=0;gt<Math.max(Tn.length,Ln.length);gt++){if(Tn[gt]===void 0)return-1;if(Ln[gt]===void 0)return 1;var yr=parseInt(Tn[gt],10),ke=parseInt(Ln[gt],10);if(!isNaN(yr)&&!isNaN(ke)){if(yr!==ke)return yr>ke?1:-1}else if(Tn[gt]!==Ln[gt])return Tn[gt]>Ln[gt]?1:-1}return 0}function L(K,ve,me,st,mt,_e){K.classList.remove("hidden"),K.disabled=!1,ve>0?K.textContent="\u5347\u7EA7":ve===0?(K.textContent="\u5DF2\u662F\u6700\u65B0",K.disabled=!0):_e?K.textContent="\u91CD\u65B0\u5B89\u88C5":(K.textContent="\u7248\u672C\u8F83\u65E7",K.disabled=!0),K.onclick=K.disabled?null:function(){try{WandNative.downloadUpdate(me,st,mt)}catch(Je){C("\u8C03\u7528\u4E0B\u8F7D\u5931\u8D25: "+(Je&&Je.message?Je.message:Je),"error")}}}var S=document.getElementById("android-apk-section"),N=document.getElementById("android-apk-current-row"),J=document.getElementById("settings-android-apk-current"),W=document.getElementById("android-apk-github-row"),k=document.getElementById("settings-android-apk-github"),I=document.getElementById("download-github-apk-btn"),T=document.getElementById("android-apk-local-row"),Y=document.getElementById("settings-android-apk-local"),j=document.getElementById("download-local-apk-btn"),G=document.getElementById("android-apk-message"),M=n.androidApk||{},te=!!zn,ne=M.enabled!==!1,O=te||ne&&(!!M.github||!!M.local);if(S&&(O?S.classList.remove("hidden"):S.classList.add("hidden")),te){if(N&&J&&(J.textContent="v"+zn,N.classList.remove("hidden")),M.github&&W&&k){var P=M.github.version?"v"+M.github.version:M.github.fileName;if(typeof M.github.size=="number"&&(P+=" \xB7 "+xn(M.github.size)),k.textContent=P,W.classList.remove("hidden"),I){var _=M.github.version?F(M.github.version,zn):1;L(I,_,M.github.downloadUrl,M.github.fileName||"wand-update.apk","github",!1)}}if(M.local&&T&&Y){var Q=M.local.version?"v"+M.local.version:M.local.fileName;if(typeof M.local.size=="number"&&(Q+=" \xB7 "+xn(M.local.size)),Y.textContent=Q,T.classList.remove("hidden"),j){var $=M.local.version?F(M.local.version,zn):1;L(j,$,M.local.downloadUrl,M.local.fileName||"wand-update.apk","local",!1)}}!M.github&&!M.local&&G&&(G.textContent="\u6682\u65E0\u53EF\u7528\u66F4\u65B0",G.classList.remove("hidden"));var ie=document.getElementById("android-auto-update-row"),ge=document.getElementById("android-auto-update-hint");ie&&ie.classList.toggle("hidden",!i),ge&&ge.classList.toggle("hidden",!i)}else{if(M.github&&W&&k){var ae=M.github.version?"v"+M.github.version:M.github.fileName;typeof M.github.size=="number"&&(ae+=" \xB7 "+xn(M.github.size)),k.textContent=ae,W.classList.remove("hidden"),I&&(I.textContent="\u4E0B\u8F7D",I.classList.remove("hidden"),I.onclick=function(){window.open(M.github.downloadUrl,"_blank"),C("\u6B63\u5728\u6253\u5F00\u4E0B\u8F7D\u9875\u2026","info")})}if(M.local&&T&&Y){var ue=M.local.version?"v"+M.local.version:M.local.fileName;typeof M.local.size=="number"&&(ue+=" \xB7 "+xn(M.local.size)),Y.textContent=ue,T.classList.remove("hidden"),j&&(j.textContent="\u4E0B\u8F7D",j.classList.remove("hidden"),j.onclick=function(){D(M.local.downloadUrl,M.local.fileName||"wand-update.apk",j)})}!M.github&&!M.local&&G&&(G.textContent=ne?"\u5728\u7EBF\u7248\u672C\u6682\u65F6\u83B7\u53D6\u5931\u8D25\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5":"Android \u4E0B\u8F7D\u672A\u5728\u670D\u52A1\u7AEF\u542F\u7528",G.classList.remove("hidden"))}var ze=document.getElementById("macos-dmg-section"),Te=document.getElementById("macos-dmg-current-row"),Fe=document.getElementById("settings-macos-dmg-current"),Le=document.getElementById("macos-dmg-github-row"),at=document.getElementById("settings-macos-dmg-github"),De=document.getElementById("download-github-dmg-btn"),X=document.getElementById("macos-dmg-local-row"),he=document.getElementById("settings-macos-dmg-local"),fe=document.getElementById("download-local-dmg-btn"),oe=document.getElementById("macos-dmg-message"),q=n.macosDmg||{},ye=!!bn,pt=q.enabled!==!1,zt=ye||pt&&(!!q.github||!!q.local);if(ze&&(zt?ze.classList.remove("hidden"):ze.classList.add("hidden")),ye){if(Te&&Fe&&(Fe.textContent="v"+bn,Te.classList.remove("hidden")),q.github&&Le&&at){var Ue=q.github.version?"v"+q.github.version:q.github.fileName;if(typeof q.github.size=="number"&&(Ue+=" \xB7 "+xn(q.github.size)),at.textContent=Ue,Le.classList.remove("hidden"),De){var ut=q.github.version?F(q.github.version,bn):1;L(De,ut,q.github.downloadUrl,q.github.fileName||"wand-update.dmg","github",!0)}}if(q.local&&X&&he){var Vt=q.local.version?"v"+q.local.version:q.local.fileName;if(typeof q.local.size=="number"&&(Vt+=" \xB7 "+xn(q.local.size)),he.textContent=Vt,X.classList.remove("hidden"),fe){var xt=q.local.version?F(q.local.version,bn):1;L(fe,xt,q.local.downloadUrl,q.local.fileName||"wand-update.dmg","local",!0)}}!q.github&&!q.local&&oe&&(oe.textContent="\u6682\u65E0\u53EF\u7528\u66F4\u65B0",oe.classList.remove("hidden"));var tt=document.getElementById("macos-auto-update-row"),Me=document.getElementById("macos-auto-update-hint");tt&&tt.classList.toggle("hidden",!i),Me&&Me.classList.toggle("hidden",!i)}else{if(q.github&&Le&&at){var Pe=q.github.version?"v"+q.github.version:q.github.fileName;typeof q.github.size=="number"&&(Pe+=" \xB7 "+xn(q.github.size)),at.textContent=Pe,Le.classList.remove("hidden"),De&&(De.textContent="\u4E0B\u8F7D",De.classList.remove("hidden"),De.onclick=function(){window.open(q.github.downloadUrl,"_blank"),C("\u6B63\u5728\u6253\u5F00\u4E0B\u8F7D\u9875\u2026","info")})}if(q.local&&X&&he){var Ce=q.local.version?"v"+q.local.version:q.local.fileName;typeof q.local.size=="number"&&(Ce+=" \xB7 "+xn(q.local.size)),he.textContent=Ce,X.classList.remove("hidden"),fe&&(fe.textContent="\u4E0B\u8F7D",fe.classList.remove("hidden"),fe.onclick=function(){D(q.local.downloadUrl,q.local.fileName||"wand-update.dmg",fe)})}!q.github&&!q.local&&oe&&(oe.textContent=pt?"\u5728\u7EBF\u7248\u672C\u6682\u65F6\u83B7\u53D6\u5931\u8D25\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5":"macOS \u4E0B\u8F7D\u672A\u5728\u670D\u52A1\u7AEF\u542F\u7528",oe.classList.remove("hidden"))}var w=document.getElementById("android-connect-code"),St=document.getElementById("android-connect-qr"),qe=document.getElementById("android-connect-qr-empty"),nt=document.getElementById("android-connect-qr-wrap");if(w&&i){w.textContent="\u52A0\u8F7D\u4E2D...",qe&&(qe.textContent="\u751F\u6210\u4E2D\u2026"),St&&(St.style.visibility="hidden");var an="/api/app-connect-code";window.location&&window.location.origin&&(an+="?origin="+encodeURIComponent(window.location.origin)),fetch(an,{credentials:"same-origin"}).then(function(K){return K.json()}).then(function(K){K.code?(w.textContent=K.code,r.androidConnectCode=K.code,Ag(K.code)):(w.textContent="\u751F\u6210\u5931\u8D25",qe&&(qe.textContent="\u751F\u6210\u5931\u8D25"))}).catch(function(){w.textContent="\u83B7\u53D6\u5931\u8D25",qe&&(qe.textContent="\u83B7\u53D6\u5931\u8D25")})}nt&&!nt.dataset.bound&&(nt.dataset.bound="1",nt.addEventListener("click",function(){r.androidConnectCode&&xg(r.androidConnectCode)}));var re=n.config||{},Ut=document.getElementById("cfg-host"),Kt=document.getElementById("cfg-port"),Se=document.getElementById("cfg-https"),rt=document.getElementById("cfg-mode"),Ve=document.getElementById("cfg-cwd"),Jt=document.getElementById("cfg-shell");Ut&&(Ut.value=re.host||""),Kt&&(Kt.value=re.port||""),Se&&(Se.checked=re.https===!0),rt&&(rt.value=re.defaultMode||"default"),Ve&&(Ve.value=re.defaultCwd||""),Jt&&(Jt.value=re.shell||"");var un=document.getElementById("cfg-language");un&&(un.value=re.language||"");var on=document.getElementById("cfg-structured-runner");on&&(on.value=re.structuredRunner||"cli");var In=document.getElementById("cfg-inherit-env");In&&(In.checked=re.inheritEnv!==!1);var It=document.getElementById("cfg-commit-cli"),sn=document.getElementById("cfg-commit-model");It&&(It.value=ct(re.commitCli)),sn&&(sn.value=re.commitModel||"",sn.dataset.modelInitialized="true",sn.dataset.modelDirty="false"),aa(!1);var Ke=re.defaultModels&&typeof re.defaultModels=="object"?re.defaultModels:{claude:re.defaultModel||"",codex:re.defaultCodexModel||"",opencode:re.defaultOpenCodeModel||""};r.configDefaultModels={claude:Ke.claude||"",codex:Ke.codex||"",opencode:Ke.opencode||""},r.configDefaultModel=r.configDefaultModels.claude;var le=document.getElementById("cfg-default-model"),ln=document.getElementById("cfg-default-codex-model"),He=document.getElementById("cfg-default-opencode-model");le&&le.dataset.modelDirty!=="true"&&(le.dataset.modelInitialized="false"),ln&&ln.dataset.modelDirty!=="true"&&(ln.dataset.modelInitialized="false"),He&&He.dataset.modelDirty!=="true"&&(He.dataset.modelInitialized="false"),ua(),td().then(function(){ua()}).catch(function(){});var dn=document.getElementById("cert-status");dn&&(dn.textContent=n.hasCert?"\u5DF2\u5B89\u88C5 SSL \u8BC1\u4E66":"\u672A\u5B89\u88C5\u8BC1\u4E66\uFF08\u4F7F\u7528\u81EA\u7B7E\u540D\u6216 HTTP\uFF09",dn.style.color=n.hasCert?"var(--success)":"var(--text-secondary)");var cn=document.getElementById("presets-list");if(cn&&re.commandPresets){for(var Gt="",fn=0;fn<re.commandPresets.length;fn++){var ot=re.commandPresets[fn];Gt+='<div class="preset-item"><span class="preset-label">'+p(ot.label)+'</span><span class="preset-detail">'+p(ot.command)+(ot.mode?" ("+p(ot.mode)+")":"")+"</span></div>"}Gt||(Gt='<div class="empty-state-compact"><span class="empty-icon">\u2699</span><span>\u6CA1\u6709\u547D\u4EE4\u9884\u8BBE</span><span class="hint">\u5728 config.json \u7684 commandPresets \u4E2D\u914D\u7F6E</span></div>'),cn.innerHTML=Gt}var Tt=re.cardDefaults||{},vt=document.getElementById("cfg-card-edit"),U=document.getElementById("cfg-card-inline"),R=document.getElementById("cfg-card-terminal"),Z=document.getElementById("cfg-card-thinking"),de=document.getElementById("cfg-card-toolgroup");vt&&(vt.checked=Tt.editCards===!0),U&&(U.checked=Tt.inlineTools===!0),R&&(R.checked=Tt.terminal===!0),Z&&(Z.checked=Tt.thinking===!0),de&&(de.checked=Tt.toolGroup===!0)}).catch(function(n){var i=document.getElementById("settings-about-access-note");i&&(i.textContent=n&&n.message||"\u5173\u4E8E\u4FE1\u606F\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",i.style.color="var(--error)",i.classList.remove("hidden"))})}function Ig(){var e=document.getElementById("config-message");e&&(e.classList.add("hidden"),e.textContent="");var t=((document.getElementById("cfg-default-model")||{}).value||"").trim(),n=((document.getElementById("cfg-default-codex-model")||{}).value||"").trim(),i=((document.getElementById("cfg-default-opencode-model")||{}).value||"").trim(),a=((document.getElementById("cfg-commit-model")||{}).value||"").trim(),u={host:(document.getElementById("cfg-host")||{}).value,port:Number((document.getElementById("cfg-port")||{}).value),https:(document.getElementById("cfg-https")||{}).checked,defaultMode:(document.getElementById("cfg-mode")||{}).value,defaultCwd:(document.getElementById("cfg-cwd")||{}).value,shell:(document.getElementById("cfg-shell")||{}).value,language:(document.getElementById("cfg-language")||{}).value||"",defaultModel:t,defaultCodexModel:n,defaultOpenCodeModel:i,defaultModels:{claude:t,codex:n,opencode:i},commitCli:ct((document.getElementById("cfg-commit-cli")||{}).value),commitModel:a,structuredRunner:(document.getElementById("cfg-structured-runner")||{}).value||"cli",inheritEnv:(document.getElementById("cfg-inherit-env")||{}).checked!==!1},o=Hu(),s=u.defaultModel||"",l=u.defaultCodexModel||"",d=u.defaultOpenCodeModel||"";fetch("/api/settings/config",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(u)}).then(function(f){return f.json()}).then(function(f){if(e&&(f.error?(e.textContent=f.error,e.style.color="var(--error)"):(e.textContent=f.restartRequired?"\u914D\u7F6E\u5DF2\u4FDD\u5B58\uFF0C\u90E8\u5206\u90E8\u7F72\u5B57\u6BB5\uFF08host/port/https/shell\uFF09\u9700\u8981\u91CD\u542F\u670D\u52A1\u624D\u751F\u6548\u3002":"\u914D\u7F6E\u5DF2\u4FDD\u5B58\u3002",e.style.color="var(--success)"),e.classList.remove("hidden")),!f||!f.error){r.config&&(r.config.defaultModel=s,r.config.defaultCodexModel=l,r.config.defaultOpenCodeModel=d,r.config.defaultModels={claude:s,codex:l,opencode:d},r.config.commitCli=u.commitCli,r.config.commitModel=u.commitModel),r.configDefaultModels={claude:s,codex:l,opencode:d},r.configDefaultModel=s;var c=document.getElementById("cfg-default-model"),v=document.getElementById("cfg-default-codex-model"),h=document.getElementById("cfg-default-opencode-model");c&&(c.dataset.modelDirty="false"),v&&(v.dataset.modelDirty="false"),h&&(h.dataset.modelDirty="false");var m=document.getElementById("cfg-commit-model");m&&(m.dataset.modelDirty="false"),s!==o.claude&&na("claude",""),l!==o.codex&&na("codex",""),d!==o.opencode&&na("opencode",""),(s!==o.claude||l!==o.codex||d!==o.opencode)&&dr(Xe())}}).catch(function(){e&&(e.textContent="\u4FDD\u5B58\u5931\u8D25\u3002",e.style.color="var(--error)",e.classList.remove("hidden"))})}function Tg(){var e=document.getElementById("display-message");e&&(e.classList.add("hidden"),e.textContent="");var t={cardDefaults:{editCards:!!(document.getElementById("cfg-card-edit")||{}).checked,inlineTools:!!(document.getElementById("cfg-card-inline")||{}).checked,terminal:!!(document.getElementById("cfg-card-terminal")||{}).checked,thinking:!!(document.getElementById("cfg-card-thinking")||{}).checked,toolGroup:!!(document.getElementById("cfg-card-toolgroup")||{}).checked}};fetch("/api/settings/config",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(t)}).then(function(n){return n.json()}).then(function(n){e&&(n.error?(e.textContent=n.error,e.style.color="var(--error)"):(e.textContent="\u663E\u793A\u8BBE\u7F6E\u5DF2\u4FDD\u5B58",e.style.color="var(--success)"),e.classList.remove("hidden")),!n.error&&r.config&&(r.config.cardDefaults=t.cardDefaults)}).catch(function(){e&&(e.textContent="\u4FDD\u5B58\u5931\u8D25\u3002",e.style.color="var(--error)",e.classList.remove("hidden"))})}function Lg(){var e=document.getElementById("cert-key-file"),t=document.getElementById("cert-cert-file"),n=document.getElementById("cert-message");if(n&&(n.classList.add("hidden"),n.textContent=""),!e||!e.files||!e.files[0]||!t||!t.files||!t.files[0]){n&&(n.textContent="\u8BF7\u9009\u62E9\u79C1\u94A5\u548C\u8BC1\u4E66\u6587\u4EF6\u3002",n.style.color="var(--error)",n.classList.remove("hidden"));return}var i=new FileReader;i.onload=function(){var a=i.result,u=new FileReader;u.onload=function(){var o=u.result;fetch("/api/settings/upload-cert",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({key:a,cert:o})}).then(function(s){return s.json()}).then(function(s){if(n){if(s.error)n.textContent=s.error,n.style.color="var(--error)";else{n.textContent="\u8BC1\u4E66\u5DF2\u4E0A\u4F20\uFF0C\u91CD\u542F\u540E\u751F\u6548\u3002",n.style.color="var(--success)";var l=document.getElementById("cert-status");l&&(l.textContent="\u5DF2\u5B89\u88C5 SSL \u8BC1\u4E66",l.style.color="var(--success)")}n.classList.remove("hidden")}}).catch(function(){n&&(n.textContent="\u4E0A\u4F20\u5931\u8D25\u3002",n.style.color="var(--error)",n.classList.remove("hidden"))})},u.readAsText(t.files[0])},i.readAsText(e.files[0])}function md(){var e=document.getElementById("settings-latest-version"),t=document.getElementById("do-update-button"),n=document.getElementById("update-message");e&&(e.textContent="\u68C0\u67E5\u4E2D..."),n&&n.classList.add("hidden"),t&&t.classList.add("hidden"),fetch("/api/check-update",{credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i.error){e&&(e.textContent="\u68C0\u67E5\u5931\u8D25");return}var a=i.channel==="beta";if(e&&(e.textContent=i.latest||(a?"beta \u672A\u53D1\u5E03":"-")),!i.latest){n&&(n.textContent=a?"\u65E0\u6CD5\u8BFB\u53D6 npm beta \u7248\u672C\u3002":"\u65E0\u6CD5\u8FDE\u63A5\u5230 npm registry\u3002",n.style.color="var(--error)",n.classList.remove("hidden"));return}t&&(t.textContent=i.updateAvailable?a?"\u66F4\u65B0\u5230 Beta":"\u66F4\u65B0\u5230\u6700\u65B0\u7248":a?"\u91CD\u65B0\u5B89\u88C5 Beta":"\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248",t.classList.remove("hidden")),!i.updateAvailable&&n&&(n.textContent=a?"\u5DF2\u662F\u6700\u65B0 Beta \u7248\u672C\u3002":"\u5DF2\u662F\u6700\u65B0\u7248\u672C\u3002",n.style.color="var(--success)",n.classList.remove("hidden"))}).catch(function(){e&&(e.textContent="\u68C0\u67E5\u5931\u8D25")})}function gd(e){var t=e&&Array.isArray(e.items)?e.items:[],n=0;["claude","codex","opencode"].forEach(function(u){var o=document.getElementById("provider-cli-status-"+u);if(o){var s=t.find(function(d){return d.id===u});if(!s){o.textContent="\u68C0\u6D4B\u5931\u8D25";return}if(o.setAttribute("title",s.error||s.executable||""),!s.installed){o.textContent="\u672A\u5B89\u88C5";return}var l=s.currentVersion||"\u672A\u77E5\u7248\u672C";if(s.updateAvailable&&s.updateSupported){n++,o.textContent=l+" \u2192 "+(s.latestVersion||"\u6700\u65B0\u7248");return}if(s.updateAvailable&&!s.updateSupported){o.textContent=l+" \xB7 \u9700\u8FC1\u79FB";return}o.textContent=s.latestVersion?l+" \xB7 \u6700\u65B0":l+" \xB7 \u672A\u8BFB\u53D6\u5230\u6700\u65B0\u7248"}});var i=document.getElementById("update-provider-clis");i&&(i.classList.toggle("hidden",n===0),i.textContent=n>0?"\u5FEB\u901F\u66F4\u65B0 ("+n+")":"\u5FEB\u901F\u66F4\u65B0");var a=document.getElementById("auto-update-cli-toggle");a&&typeof e.autoUpdate=="boolean"&&(a.checked=e.autoUpdate)}function hd(e){var t=document.getElementById("check-provider-cli-updates"),n=document.getElementById("provider-cli-update-message");return t&&(t.disabled=!0,t.textContent="\u68C0\u6D4B\u4E2D\u2026"),fetch("/api/provider-cli-updates"+(e?"?refresh=1":""),{credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i.error)throw new Error(i.error);return gd(i),n&&e&&(n.textContent="CLI \u7248\u672C\u68C0\u67E5\u5B8C\u6210\u3002",n.style.color="var(--success)",n.classList.remove("hidden")),i}).catch(function(i){return n&&(n.textContent=i&&i.message||"CLI \u7248\u672C\u68C0\u67E5\u5931\u8D25\u3002",n.style.color="var(--error)",n.classList.remove("hidden")),null}).finally(function(){t&&(t.disabled=!1,t.textContent="\u68C0\u67E5\u66F4\u65B0")})}function Mg(){var e=document.getElementById("update-provider-clis"),t=document.getElementById("check-provider-cli-updates"),n=document.getElementById("provider-cli-update-message");e&&(e.disabled=!0,e.textContent="\u66F4\u65B0\u4E2D\u2026"),t&&(t.disabled=!0),n&&(n.textContent="\u6B63\u5728\u4F9D\u6B21\u66F4\u65B0 CLI\uFF0C\u8BF7\u52FF\u5173\u95ED\u670D\u52A1\u2026",n.style.color="var(--text-secondary)",n.classList.remove("hidden")),fetch("/api/provider-cli-updates",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({})}).then(function(i){return i.json()}).then(function(i){if(i.error)throw new Error(i.error);gd(i);var a=Array.isArray(i.results)?i.results:[],u=a.filter(function(o){return!o.ok});n&&(n.textContent=a.map(function(o){return o.message}).join(" ")||"\u6CA1\u6709\u9700\u8981\u66F4\u65B0\u7684 CLI\u3002",n.style.color=u.length?"var(--warning)":"var(--success)")}).catch(function(i){n&&(n.textContent=i&&i.message||"CLI \u66F4\u65B0\u5931\u8D25\u3002",n.style.color="var(--error)")}).finally(function(){e&&(e.disabled=!1),t&&(t.disabled=!1)})}function Og(){var e=document.getElementById("update-message"),t=document.getElementById("do-update-button");if(t){var n=t.textContent||"\u66F4\u65B0\u5230\u6700\u65B0\u7248",i=function(){t.disabled=!1,t.textContent=n,t.removeAttribute("aria-busy")};t.disabled=!0,t.textContent="\u66F4\u65B0\u4E2D...",t.setAttribute("aria-busy","true"),e&&(e.textContent="\u6B63\u5728\u66F4\u65B0\uFF0C\u8BF7\u7A0D\u5019...",e.style.color="var(--text-secondary)",e.classList.remove("hidden")),fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(a.error){e&&(e.textContent=a.error,e.style.color="var(--error)",e.classList.remove("hidden")),i();return}if(e&&(e.textContent=(a.message||"\u66F4\u65B0\u5B8C\u6210")+"\uFF0C\u6B63\u5728\u91CD\u542F\u670D\u52A1\u2026",e.style.color="var(--success)",e.classList.remove("hidden")),t.removeAttribute("aria-busy"),t.classList.add("hidden"),a.detachedUpdate)En(a.previousInstanceId||null,a.version||null);else if(a.restartRequired!==!1)Os(null,e);else{var u=document.getElementById("do-restart-button");u&&u.classList.remove("hidden")}}).catch(function(){e&&(e.textContent="\u66F4\u65B0\u5931\u8D25\u3002",e.style.color="var(--error)",e.classList.remove("hidden")),i()})}}function Pg(){var e=document.getElementById("do-restart-button"),t=document.getElementById("update-message");Os(e,t)}function qg(){fetch("/api/auto-update",{credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){if(e.apk)return fetch("/api/android-apk-update?currentVersion="+encodeURIComponent(zn),{credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(!(!t.updateAvailable||!t.downloadUrl))try{WandNative.downloadUpdate(t.downloadUrl,t.fileName||"wand-update.apk",t.source||"local")}catch{}})}).catch(function(){})}function Hg(){bn&&fetch("/api/auto-update",{credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){if(e.dmg)return fetch("/api/macos-dmg-update?currentVersion="+encodeURIComponent(bn),{credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(!(!t.updateAvailable||!t.downloadUrl))try{WandNative.downloadUpdate(t.downloadUrl,t.fileName||"wand-update.dmg",t.source||"local")}catch{}})}).catch(function(){})}function fa(e,t){var n={};n[e]=t,fetch("/api/auto-update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(n)}).then(function(i){return i.json()}).then(function(i){var a=document.getElementById("auto-update-web-toggle"),u=document.getElementById("auto-update-apk-toggle"),o=document.getElementById("auto-update-dmg-toggle"),s=document.getElementById("auto-update-cli-toggle");a&&(a.checked=!!i.web),u&&(u.checked=!!i.apk),o&&(o.checked=!!i.dmg),s&&(s.checked=!!i.cli)}).catch(function(){var i=document.getElementById("auto-update-"+e+"-toggle");i&&(i.checked=!t)})}function _g(e){fetch("/api/update-channel",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({channel:e})}).then(function(t){return t.json()}).then(function(t){var n=document.getElementById("beta-channel-toggle");n&&(n.checked=t.channel==="beta"),md()}).catch(function(){var t=document.getElementById("beta-channel-toggle");t&&(t.checked=e!=="beta")})}function yd(e){for(var t=document.querySelectorAll(".settings-app-icon-option"),n=0;n<t.length;n++){var i=t[n].getAttribute("data-icon")===e;t[n].classList.toggle("selected",i),t[n].setAttribute("aria-pressed",i?"true":"false")}}function Sn(){var e=document.getElementById("notification-permission-status"),t=document.getElementById("notification-request-btn"),n=document.getElementById("notification-reset-btn"),i=document.getElementById("notification-test-message");if(e){var a=Li();if(a===null){if(typeof Notification>"u"){e.textContent="\u4E0D\u652F\u6301",e.style.color="var(--fg-muted)",t&&t.classList.add("hidden"),n&&n.classList.add("hidden");return}a=Notification.permission}a==="granted"?(e.textContent="\u5DF2\u6388\u6743 \u2713",e.style.color="var(--success)",t&&t.classList.add("hidden"),n&&n.classList.add("hidden")):a==="denied"?(e.textContent="\u5DF2\u62D2\u7EDD",e.style.color="var(--danger)",t&&t.classList.add("hidden"),n&&n.classList.remove("hidden")):(e.textContent="\u672A\u6388\u6743",e.style.color="var(--warning)",t&&t.classList.remove("hidden"),n&&n.classList.remove("hidden"))}}function Ng(){var e=document.getElementById("notification-test-message");if(je){window._onNativePermissionResult=function(t){Sn(),e&&(t==="granted"?(e.textContent="\u2713 \u5DF2\u6388\u6743",e.style.color="var(--success)"):(e.textContent="\u2717 \u672A\u6388\u6743\uFF0C\u8BF7\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u4E2D\u5F00\u542F Wand \u7684\u901A\u77E5\u6743\u9650",e.style.color="var(--danger)"),e.classList.remove("hidden")),delete window._onNativePermissionResult};try{WandNative.requestPermission()}catch{}return}typeof Notification>"u"||Notification.requestPermission().then(function(t){if(Sn(),t==="granted")e&&(e.textContent="\u2713 \u5DF2\u6388\u6743",e.style.color="var(--success)",e.classList.remove("hidden"));else if(t==="denied"&&e){var n=location.origin;e.innerHTML='\u6D4F\u89C8\u5668\u5DF2\u62E6\u622A\u6388\u6743\u5F39\u7A97\uFF0C\u8BF7\u624B\u52A8\u91CD\u7F6E\uFF1A<br><span style="display:inline-flex;align-items:center;gap:4px;margin:4px 0">\u2460 \u70B9\u51FB\u5730\u5740\u680F\u5DE6\u4FA7\u7684 <span style="display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border-radius:50%;border:1px solid var(--border);font-size:11px;vertical-align:middle">i</span> \u6216\u9501\u56FE\u6807</span><br>\u2461 \u627E\u5230\u300C\u901A\u77E5\u300D\u2192 \u6539\u4E3A\u300C\u5141\u8BB8\u300D<br>\u2462 \u5237\u65B0\u9875\u9762\u5373\u53EF',e.style.color="var(--fg-muted)",e.classList.remove("hidden")}})}function bd(){var e=document.getElementById("notification-test-delay-btn");e&&(e.disabled=!1,e.textContent="10 \u79D2\u540E\u53D1\u9001")}function jg(){var e=document.getElementById("notification-test-message");r.delayedNotificationTimer&&(clearTimeout(r.delayedNotificationTimer),r.delayedNotificationTimer=null);var t=document.getElementById("notification-test-delay-btn");t&&(t.disabled=!0,t.textContent="\u5DF2\u5B89\u6392\uFF0810s\uFF09"),e&&(e.innerHTML="\u5DF2\u5B89\u6392 10 \u79D2\u540E\u53D1\u9001\u6D4B\u8BD5\u901A\u77E5\uFF0C\u8BF7\u5207\u5230\u540E\u53F0\u7B49\u5F85\u3002",e.style.color="var(--text-secondary)",e.classList.remove("hidden")),r.delayedNotificationTimer=setTimeout(function(){r.delayedNotificationTimer=null,bd(),Ed()},1e4)}function Ed(){var e=document.getElementById("notification-test-message"),t=[];r.delayedNotificationTimer&&(clearTimeout(r.delayedNotificationTimer),r.delayedNotificationTimer=null,bd());var n=Bp();t.push(n?"\u2713 \u63D0\u793A\u97F3":"\u2717 \u63D0\u793A\u97F3\uFF08\u65E0\u6CD5\u64AD\u653E\uFF09");var i=r.notifBubble;if($a({title:"\u6D4B\u8BD5\u901A\u77E5",body:"\u8FD9\u662F\u4E00\u6761\u6D4B\u8BD5\u901A\u77E5\u3002",type:"info",icon:"\u266A",duration:5e3,playSound:!1}),t.push(i?"\u2713 \u5E94\u7528\u5185\u6C14\u6CE1":"\u2013 \u5E94\u7528\u5185\u6C14\u6CE1\uFF08\u5DF2\u5173\u95ED\uFF09"),je){var a=Li();if(a==="granted")try{WandNative.sendNotification("Wand \u6D4B\u8BD5\u901A\u77E5","\u7CFB\u7EDF\u901A\u77E5\u5DF2\u6B63\u5E38\u5DE5\u4F5C\u3002","wand-test"),t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5")}catch{t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u53D1\u9001\u5931\u8D25\uFF09")}else if(a==="denied")t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u62D2\u7EDD\uFF0C\u8BF7\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u4E2D\u5F00\u542F\uFF09");else{window._onNativePermissionResult=function(s){if(Sn(),s==="granted")try{WandNative.sendNotification("Wand \u6D4B\u8BD5\u901A\u77E5","\u7CFB\u7EDF\u901A\u77E5\u5DF2\u6B63\u5E38\u5DE5\u4F5C\u3002","wand-test"),t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u6388\u6743\uFF09")}catch{t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u53D1\u9001\u5931\u8D25\uFF09")}else t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u672A\u6388\u6743\uFF09");mr(e,t),delete window._onNativePermissionResult};try{WandNative.requestPermission()}catch{}return}mr(e,t);return}if(typeof Notification>"u"){t.push("\u2013 \u7CFB\u7EDF\u901A\u77E5\uFF08\u4E0D\u652F\u6301\uFF09"),mr(e,t);return}var u=Notification.permission;if(u==="granted"){try{var o=new Notification("Wand \u6D4B\u8BD5\u901A\u77E5",{body:"\u7CFB\u7EDF\u901A\u77E5\u5DF2\u6B63\u5E38\u5DE5\u4F5C\u3002",icon:"/favicon.ico",tag:"wand-test"});setTimeout(function(){o.close()},5e3),t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5")}catch{t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u53D1\u9001\u5931\u8D25\uFF0C\u53EF\u80FD\u9700\u8981 HTTPS\uFF09")}mr(e,t)}else u==="denied"?(t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u62D2\u7EDD\uFF09"),mr(e,t)):Notification.requestPermission().then(function(s){Sn(),s==="granted"?t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u6388\u6743\uFF09"):t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u672A\u6388\u6743\uFF09"),mr(e,t)})}function mr(e,t){if(e){e.innerHTML=t.map(function(i){return p(i)}).join("<br>");var n=t.every(function(i){return i.indexOf("\u2713")===0||i.indexOf("\u2013")===0});e.style.color=n?"var(--success)":"var(--warning)",e.classList.remove("hidden")}}function ft(e){if(!e||typeof e!="object"||!r.terminal)return e;try{typeof r.terminal.remeasure=="function"&&r.terminal.remeasure()}catch{}var t=r.terminal.cols,n=r.terminal.rows;return typeof t=="number"&&typeof n=="number"&&Number.isFinite(t)&&Number.isFinite(n)&&t>0&&n>0&&(e.cols=t,e.rows=n),e}function Fd(){return r.terminal&&r.terminal.cols?Promise.resolve():new Promise(function(e){var t=!1,n=function(){t||(t=!0,e())},i=setTimeout(n,2e3);try{ur()}catch{}requestAnimationFrame(function(){requestAnimationFrame(function(){r.terminal&&r.terminal.cols&&(clearTimeout(i),n())})})})}function Ku(){var e=$e(),t=Qe(),n=dt(e,r.config&&r.config.defaultMode?r.config.defaultMode:"default");r.preferredCommand=e,r.chatMode=dt(e,r.chatMode),Fd().then(function(){return fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(ft({command:e,provider:e,cwd:t,mode:n,sessionSource:"interactive"}))})}).then(function(i){return i.json()}).then(function(i){if(i.error){x(i.error,"error");return}return r.selectedId=i.id,Ee(),r.drafts[i.id]="",Dt(),_t()}).then(function(){Ht(!0)}).catch(function(){x("\u65E0\u6CD5\u542F\u52A8\u4F1A\u8BDD\u3002","error")})}var ui=!1;function Rg(){if(!ui){var e=document.getElementById("cwd"),t=document.getElementById("modal-error"),n=$e(),i=r.sessionCreateKind||"structured",a=r.sessionCreateWorktree===!0;Ti(t);var u=Qe(),o=(e?e.value.trim():"")||u,s=dt(n,r.modeValue);if(da({defaultProvider:n,defaultSessionKind:i,defaultMode:s}),i==="structured"){Wg(o,s,a,t);return}zg(n,o,s,a,t)}}function Wg(e,t,n,i){var a=ct(r.sessionTool);return ui=!0,r.modeValue=t,r.chatMode=t,r.sessionTool=a,r.preferredCommand=a,Qi(),dr(Xe()),ld(void 0,e,t,n).then(function(u){return Xt(e),An(),jt(),u}).then(function(){Ht(!0)}).catch(function(u){Oe(i,u&&u.message||"\u65E0\u6CD5\u542F\u52A8\u7ED3\u6784\u5316\u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 Claude \u5DF2\u6B63\u786E\u5B89\u88C5\u3002")}).finally(function(){ui=!1})}function zg(e,t,n,i,a){ui=!0,r.modeValue=n,r.chatMode=n,r.sessionTool=e,r.preferredCommand=e,Qi(),Fd().then(function(){return fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(ft({command:e,provider:e,cwd:t,mode:n,worktreeEnabled:i,sessionSource:"interactive"}))})}).then(function(u){return u.json()}).then(function(u){if(u.error){Oe(a,u.error);return}return r.selectedId=u.id,Ee(),Xt(t),r.drafts[u.id]="",Dt(),An(),jt(),_t()}).then(function(){r.selectedId?Nt(r.selectedId):Ht(!0)}).catch(function(){Oe(a,e==="codex"?"\u65E0\u6CD5\u542F\u52A8 Codex \u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 codex \u5DF2\u6B63\u786E\u5B89\u88C5\u5E76\u53EF\u5728\u7EC8\u7AEF\u4E2D\u6267\u884C\u3002":e==="opencode"?"\u65E0\u6CD5\u542F\u52A8 OpenCode \u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 opencode-ai \u5DF2\u6B63\u786E\u5B89\u88C5\u3002":"\u65E0\u6CD5\u542F\u52A8 Claude \u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 Claude \u5DF2\u6B63\u786E\u5B89\u88C5\u3002")}).finally(function(){ui=!1})}function Vg(){var e=document.getElementById("blank-chat-cwd");e&&(e.addEventListener("click",Cd),e.addEventListener("keydown",function(t){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),Cd())}),document.addEventListener("click",function(t){var n=document.getElementById("blank-chat-cwd-dropdown");if(!(!n||n.classList.contains("hidden"))&&!t.target.closest(".blank-chat-cwd-wrap")){n.classList.add("hidden");var i=document.getElementById("blank-chat-cwd-arrow");i&&(i.textContent="\u25BC")}}))}function Cd(){var e=document.getElementById("blank-chat-cwd-dropdown"),t=document.getElementById("blank-chat-cwd-arrow");if(e){var n=e.classList.contains("hidden");n?(Ug(e),e.classList.remove("hidden"),t&&(t.textContent="\u25B2")):(e.classList.add("hidden"),t&&(t.textContent="\u25BC"))}}function Ug(e){var t=gn();e.innerHTML='<div class="blank-chat-cwd-loading">\u52A0\u8F7D\u4E2D...</div>',Wa(function(n){var i="",a=r.workingDir||t;if(i+='<div class="blank-chat-cwd-item'+(a===t?" active":"")+'" data-path="'+p(t)+'"><span class="blank-chat-cwd-item-label">\u9ED8\u8BA4</span>'+Et(t,"blank-chat-cwd-item-path")+"</div>",n.length){var u={};u[t]=!0,n.forEach(function(o){u[o.path]||(u[o.path]=!0,i+='<div class="blank-chat-cwd-item'+(a===o.path?" active":"")+'" data-path="'+p(o.path)+'">'+Et(o.path,"blank-chat-cwd-item-path")+"</div>")})}e.innerHTML=i,Wt(e),e.querySelectorAll(".blank-chat-cwd-item").forEach(function(o){o.addEventListener("click",function(s){s.stopPropagation();var l=o.dataset.path;r.workingDir=l;try{localStorage.setItem("wand-working-dir",l)}catch{}var d=document.getElementById("blank-chat-cwd-path");eo(d,l),e.classList.add("hidden");var f=document.getElementById("blank-chat-cwd-arrow");f&&(f.textContent="\u25BC");var c=document.getElementById("folder-picker-input");c&&(c.value=l)})})})}function Kg(){var e=document.getElementById("recent-paths-bubbles");e&&Wa(function(t){if(!t.length){e.innerHTML="";return}e.innerHTML=t.map(function(n){return'<button class="recent-path-bubble" data-path="'+p(n.path)+'" title="'+p(n.path)+'">'+Et(n.path,"recent-path-bubble-path")+"</button>"}).join(""),Wt(e),e.querySelectorAll(".recent-path-bubble").forEach(function(n){n.addEventListener("click",function(){var i=document.getElementById("cwd");i&&(i.value=n.dataset.path||"",r.cwdValue=n.dataset.path||"")})})})}function wd(){r.suggestionTimer&&clearTimeout(r.suggestionTimer),r.suggestionTimer=setTimeout(Jg,120)}function Jg(){var e=document.getElementById("session-modal");if(e&&e.classList.contains("hidden")){gr();return}var t=document.getElementById("cwd");t&&fetch("/api/path-suggestions?q="+encodeURIComponent(t.value.trim()),{credentials:"same-origin"}).then(function(n){return n.json()}).then(Gg).catch(gr)}function Gg(e){var t=document.getElementById("cwd-suggestions");if(!t||!e.length){gr();return}t.innerHTML=e.map(function(n){return'<button class="suggestion-item" data-path="'+p(n.path)+'"><strong>'+p(n.name)+"</strong><small>"+Et(n.path,"suggestion-item-path")+"</small></button>"}).join(""),Wt(t),t.querySelectorAll(".suggestion-item").forEach(function(n){n.addEventListener("click",function(){document.getElementById("cwd").value=n.dataset.path||"",r.cwdValue=n.dataset.path||"",gr()})}),t.classList.remove("hidden")}function gr(){var e=document.getElementById("cwd-suggestions");e&&(e.classList.add("hidden"),e.innerHTML="")}function Yg(e){if(!e.isComposing){if(Zs(e)){cu(e);return}if(e.key==="Enter"){if(e.shiftKey){e.preventDefault();var t=document.getElementById("input-box");if(t){var n=t.selectionStart||0,i=t.value,a=i.slice(0,n)+`
48
+ `).replace(/\u0000/g,"")}function jm(){var e=document.getElementById("login-cert-hint");e&&e.classList.remove("hidden");var t=document.getElementById("login-cert-http-link");t&&(t.href="http://"+location.host+location.pathname,t.style.display=location.protocol==="https:"?"":"none")}function Rm(){var e=document.getElementById("login-cert-hint");e&&e.classList.add("hidden")}function Iu(){if(!r.loginPending){var e=document.getElementById("password"),t=document.getElementById("login-button"),n=document.getElementById("login-error");!e||!t||!n||(Ti(n),Rm(),e.dataset.error="false",e.setAttribute("aria-invalid","false"),r.loginPending=!0,t.disabled=!0,t.textContent="\u767B\u5F55\u4E2D...",fetch("/api/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:e.value}),credentials:"same-origin"}).then(function(i){return i.status===429?(Oe(n,"\u767B\u5F55\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002"),Promise.reject("handled")):i.ok?fetch("/api/config",{credentials:"same-origin"}):(e.dataset.error="true",e.setAttribute("aria-invalid","true"),Oe(n,"\u5BC6\u7801\u9519\u8BEF\uFF0C\u8BF7\u91CD\u8BD5\u3002"),Promise.reject("handled"))}).then(function(i){return i.ok?i.json():(location.protocol==="https:"?jm():Oe(n,"\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"),Promise.reject("handled"))}).then(function(i){r.config=i;var a=document.getElementById("status-dot"),u=document.getElementById("status-text");return a&&a.classList.add("active"),u&&(u.textContent="\u5DF2\u767B\u5F55"),_t()}).then(function(){ns(),Zt()}).catch(function(i){i!=="handled"&&(console.error("[wand] Login error:",i),Oe(n,"\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"))}).finally(function(){r.loginPending=!1,t.disabled=!1,t.textContent="\u8FDB\u5165\u63A7\u5236\u53F0"}))}}function Tu(){return typeof WandNative<"u"&&typeof WandNative.switchServer=="function"}function _l(){if(Tu())try{WandNative.switchServer()}catch{}}function Wm(){return typeof WandNative<"u"&&typeof WandNative.backToNative=="function"?!0:typeof window.__wandBackToNative=="function"}function zm(){try{if(typeof WandNative<"u"&&typeof WandNative.backToNative=="function"){WandNative.backToNative();return}typeof window.__wandBackToNative=="function"&&window.__wandBackToNative()}catch{}}function Nl(){fetch("/api/logout",{method:"POST",credentials:"same-origin"}).catch(function(){}),ss(),Kn(!1),lu(),Mr(),r.config=null,r.selectedId=null,Ee(),r.sessions=[],r.claudeHistory=[],r.claudeHistoryLoaded=!1,r.claudeHistoryExpanded=!1,r.claudeHistoryExpandedDirs={},r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),Zt()}function _t(){return nn()}function Lu(e){return e==="full-access"?"\u5168\u6743\u9650":e==="default"?"\u9ED8\u8BA4":e==="native"?"\u539F\u751F":e==="auto-edit"?"\u81EA\u52A8\u7F16\u8F91":e==="managed"?"\u6258\u7BA1":e}function $e(){return r.sessionTool||r.preferredCommand||"claude"}function Vm(){var e=r.sessions.find(function(t){return t.id===r.selectedId});return e&&e.provider||r.preferredCommand||"claude"}function jl(e,t){return t?"\u952E\u76D8\u8F93\u5165\u5C06\u53D1\u9001\u5230\u7EC8\u7AEF":e&&(e.status==="exited"||e.status==="failed"||e.status==="stopped")?au(e)?"\u8F93\u5165\u6D88\u606F\u4EE5\u7EE7\u7EED\u4F1A\u8BDD":"\u4F1A\u8BDD\u5DF2\u7ED3\u675F":se(e)&&e.structuredState&&e.structuredState.inFlight?"\u56DE\u590D\u4E2D\uFF0C\u53EF\u7EE7\u7EED\u8F93\u5165":"\u8F93\u5165\u6D88\u606F"}function Rl(e,t){return e==="codex"?"Codex \u652F\u6301 PTY \u7EC8\u7AEF\u4E0E\u7ED3\u6784\u5316\uFF08JSONL\uFF09\u4E24\u79CD\u4F1A\u8BDD\uFF0C\u7ED3\u6784\u5316\u6A21\u5F0F\u6309 full-access \u542F\u52A8\u3002":e==="opencode"?t==="full-access"||t==="managed"||t==="auto-edit"?"OpenCode \u5C06\u81EA\u52A8\u6279\u51C6\u672A\u663E\u5F0F\u62D2\u7EDD\u7684\u6743\u9650\uFF1B\u652F\u6301 TUI \u4E0E JSON \u7ED3\u6784\u5316\u4F1A\u8BDD\u3002":"OpenCode \u4F7F\u7528\u81EA\u8EAB\u6743\u9650\u914D\u7F6E\uFF1B\u7ED3\u6784\u5316\u6A21\u5F0F\u4F1A\u81EA\u52A8\u62D2\u7EDD\u672A\u6279\u51C6\u7684\u6743\u9650\u8BF7\u6C42\u3002":t==="full-access"?"\u81EA\u52A8\u786E\u8BA4\u6743\u9650\u8BF7\u6C42\u4E0E\u9AD8\u6743\u9650\u64CD\u4F5C\uFF0C\u9002\u5408\u4F60\u786E\u8BA4\u73AF\u5883\u5B89\u5168\u540E\u7684\u8FDE\u7EED\u4FEE\u6539\u3002":t==="auto-edit"?"\u4FDD\u7559\u4EA4\u4E92\u5F0F\u4F1A\u8BDD\uFF0C\u540C\u65F6\u66F4\u504F\u5411\u76F4\u63A5\u7F16\u8F91\u4EE3\u7801\u3002":t==="native"?"\u8C03\u7528 Claude \u539F\u751F API \u8F93\u51FA\uFF0C\u9002\u5408\u5FEB\u901F\u95EE\u7B54\u6216\u4E00\u6B21\u6027\u751F\u6210\u3002":t==="managed"?"AI \u81EA\u52A8\u5B8C\u6210\u6240\u6709\u5DE5\u4F5C\uFF0C\u65E0\u9700\u4E2D\u9014\u786E\u8BA4\uFF0C\u9002\u5408\u6709\u660E\u786E\u76EE\u6807\u7684\u4EFB\u52A1\u3002":"\u4FDD\u7559\u6807\u51C6\u4EA4\u4E92\u6D41\u7A0B\uFF0C\u9002\u5408\u624B\u52A8\u786E\u8BA4\u6BCF\u4E00\u6B65\u3002"}function Mu(e){return e==="codex"?["full-access"]:e==="opencode"?["default","full-access","managed"]:["default","full-access","auto-edit","native","managed"]}function dt(e,t){var n=Mu(e);if(n.indexOf(t)!==-1)return t;var i=r.config&&r.config.defaultMode?r.config.defaultMode:"default";return n.indexOf(i)!==-1?i:n[0]}function Kh(e,t){return Mu(e).map(function(n){var i=Wl(n);return'<option value="'+p(n)+'"'+(n===t?" selected":"")+' title="'+i+'">'+p(Lu(n))+"</option>"}).join("")}function Wl(e){var t={default:"\u6807\u51C6\u6A21\u5F0F - \u9700\u8981\u786E\u8BA4\u6587\u4EF6\u4FEE\u6539","full-access":"\u5B8C\u5168\u8BBF\u95EE - \u81EA\u52A8\u786E\u8BA4\u6743\u9650\u4E0E\u64CD\u4F5C","auto-edit":"\u81EA\u52A8\u7F16\u8F91 - \u81EA\u52A8\u786E\u8BA4\u6587\u4EF6\u4FEE\u6539",native:"\u539F\u751F\u6A21\u5F0F - \u8FD4\u56DE\u7ED3\u6784\u5316\u8F93\u51FA",managed:"\u6258\u7BA1\u6A21\u5F0F - AI \u81EA\u52A8\u5B8C\u6210\u6240\u6709\u5DE5\u4F5C"};return t[e]||""}function Um(e){var t=e&&e.provider?e.provider:"claude";return(se(e)?"\u7ED3\u6784\u5316":"\u7EC8\u7AEF")+" \xB7 "+t}function Km(e){return se(e)?"\u7ED3\u6784\u5316 \xB7 \u5757\u7EA7\u8BB0\u5F55":e&&e.provider==="codex"?"\u7EC8\u7AEF \xB7 Codex PTY\uFF08chat \u4E3A\u89E3\u6790\u89C6\u56FE\uFF09":"\u7EC8\u7AEF \xB7 PTY \u4F1A\u8BDD"}function zl(e){return e?se(e)||e.provider==="codex":!1}function Vl(e,t){if(!e||!e.is_error||!t||t.is_error)return!1;var n=Bn(e.content).toLowerCase(),i=Bn(t.content).toLowerCase();return n?n.indexOf("invalid pages parameter")!==-1&&i.length>0:!1}function se(e){return!!e&&(e.sessionKind==="structured"||e.runner==="claude-cli-print")}function Qi(){r.chatMode=dt("claude",r.chatMode);var e=document.getElementById("mode-hint");e&&(e.textContent=Wl(r.chatMode)),tn()}var Ul=Object.create(null),$i=Object.create(null),Xi=Object.create(null);function Kl(e){return e&&Xi[e]||null}function Zi(e,t,n){if(e){var i=Xi[e]||(Xi[e]={});i[t]=n}}function Jl(e){e&&delete Xi[e]}function Ou(e,t){var n=($i[e]||0)+1;$i[e]=n;var i=Ul[e]||Promise.resolve(),a=i.catch(function(){}).then(t);return Ul[e]=a.catch(function(){}),a.then(function(u){return{data:u,latest:$i[e]===n}},function(u){return Promise.reject({error:u,latest:$i[e]===n})})}function Jr(e,t){Jl(e),Promise.resolve(nn()).catch(function(){}).finally(function(){tn()}),x(t,"error")}function Pu(e,t){if(!t.latest)return!1;var n=t.data;return n&&n.error?(Jr(e,n.error),!1):!n||!n.id?(Jr(e,"\u4F1A\u8BDD\u8BBE\u7F6E\u66F4\u65B0\u5931\u8D25"),!1):(ee(n),Jl(e),tn(),!0)}function Jm(e,t){t=t||{};var n=t.kind==="compact"||t.kind==="popover"?t.kind:"dropdown",i=$e(),a=r.chatMode||"default",u=$r(e)||"",o=ea(u,e),s=ra(e);function l(d,f,c,v){var h=n==="compact"?"":'<span class="chat-mode-trio-tag">'+p(f)+"</span>";return'<span class="composer-text-pill chat-mode-trio-pill" data-mode-control-pill="'+d+'" title="'+p(f)+'">'+h+'<span class="composer-text-label">'+p(c)+'</span><select class="composer-text-hidden-select" data-mode-control="'+d+'" aria-label="'+p(f)+'">'+v+"</select></span>"}return'<div class="chat-mode-trio chat-mode-trio-'+n+'" role="group" aria-label="\u4F1A\u8BDD\u8BBE\u7F6E">'+l("mode","\u6A21\u5F0F",a,ta(i,a))+'<span class="composer-text-sep" aria-hidden="true">\xB7</span>'+l("model","\u6A21\u578B",o,$l(u,e))+'<span class="composer-text-sep" aria-hidden="true">\xB7</span>'+l("thinking","\u601D\u8003",Jn(s,e),qu(s,e))+"</div>"}function Jn(e,t){var n=$m(e,t);return n==="low"?"\u4F4E":n==="medium"?"\u4E2D":n==="high"?"\u9AD8":n==="xhigh"?"\u8D85\u9AD8":n==="max"?"\u6781\u9AD8":n==="ultra"?"\u6781\u9650":"\u81EA\u52A8"}function Gr(e,t){var n=e||"",i=_u(t);if(!n||n==="default"){for(var a=0;a<i.length;a++)if(i[a].id==="default")return i[a].label||i[a].id;return"\u9ED8\u8BA4"}for(var u=0;u<i.length;u++)if(i[u].id===n)return i[u].label||i[u].id;return n}function ea(e,t){var n=Gr(e,t);if(!n||n==="\u8DDF\u968F\u670D\u52A1\u7AEF\u9ED8\u8BA4")return"\u9ED8\u8BA4";var i=n.search(/[((]/);i>0&&(n=n.slice(0,i).trim());var a=n.lastIndexOf("/");a>=0&&a<n.length-1&&(n=n.slice(a+1).trim());var u=n.toLowerCase();return u.indexOf("opus")!==-1?"Opus":u.indexOf("sonnet")!==-1?"Sonnet":u.indexOf("haiku")!==-1?"Haiku":u.indexOf("gpt-5.5")!==-1?"GPT-5.5":u.indexOf("gpt-5")!==-1?"GPT-5":u.indexOf("gpt-4")!==-1?"GPT-4":n.length>12?n.slice(0,10)+"\u2026":n}function qu(e,t){var n=Zr(t),i=n.some(function(a){return a.id===e})?e:"off";return n.map(function(a){var u=a.id==="off"?"\u81EA\u52A8\uFF08\u6A21\u578B\u9ED8\u8BA4\uFF09":Jn(a.id,t);return'<option value="'+p(a.id)+'"'+(a.id===i?" selected":"")+">"+p(u)+"</option>"}).join("")}function Gl(e,t,n){var i=e.querySelector('[data-mode-control="thinking"]');i&&(i.innerHTML=qu(t,n),i.value=Zr(n).some(function(a){return a.id===t})?t:"off")}function Yl(e){var t=$e(),n=r.chatMode||"default",i=$r(e)||"",a=ra(e),u=Lu(n),o=ea(i,e),s=Jn(a,e),l="\u6A21\u5F0F "+u+" \xB7 \u6A21\u578B "+o+" \xB7 \u601D\u8003 "+s;return'<div class="composer-config-controls" role="group" aria-label="\u4F1A\u8BDD\u8BBE\u7F6E" title="'+p(l)+'"><span class="composer-config-chip composer-config-chip-mode" data-mode-control-pill="mode" title="\u6A21\u5F0F\uFF1A'+p(u)+'">'+V("shield",{size:13,strokeWidth:1.8,cls:"composer-config-icon"})+'<span class="composer-config-label">'+p(u)+'</span><select class="composer-text-hidden-select" data-mode-control="mode" aria-label="\u6A21\u5F0F">'+ta(t,n)+'</select></span><span class="composer-config-chip composer-config-model" data-mode-control-pill="model" title="\u6A21\u578B\uFF1A'+p(o)+'">'+V("cpu",{size:13,strokeWidth:1.8,cls:"composer-config-icon"})+'<span class="composer-config-label">'+p(o)+'</span><select class="composer-text-hidden-select" data-mode-control="model" aria-label="\u6A21\u578B">'+Ql(i,e)+'</select></span><span class="composer-config-chip composer-config-thinking" data-mode-control-pill="thinking" data-thinking="'+p(a)+'" title="\u601D\u8003\u6DF1\u5EA6\uFF1A'+p(s)+'">'+V("brain",{size:13,strokeWidth:1.8,cls:"composer-config-icon"})+'<span class="composer-config-label">'+p(s)+'</span><select class="composer-text-hidden-select" data-mode-control="thinking" aria-label="\u601D\u8003\u6DF1\u5EA6">'+qu(a,e)+"</select></span></div>"}function tn(){var e=Xe(),t=$e(),n=r.chatMode||"default",i=$r(e)||"",a=ea(i,e),u=ra(e),o=document.querySelectorAll(".chat-mode-trio");o.forEach(function(s){function l(d,f,c,v){var h=s.querySelector('[data-mode-control-pill="'+d+'"]');if(h){var m=h.querySelector(".composer-text-label");if(m&&(m.textContent=v||f),d==="thinking"){Gl(h,f,e);return}var g=h.querySelector('[data-mode-control="'+d+'"]');g&&(c&&(g.innerHTML=c),g.value!==f&&(g.value=f))}}l("mode",n,ta(t,n)),l("model",i,$l(i,e),a),l("thinking",u,"",Jn(u,e))}),Gm(e,n,$r(e)||"",u)}function Gm(e,t,n,i){var a=$e(),u=Lu(t),o=ea(n,e),s=Jn(i,e),l=document.querySelectorAll(".composer-config-controls");l.forEach(function(d){var f="\u6A21\u5F0F "+u+" \xB7 \u6A21\u578B "+o+" \xB7 \u601D\u8003 "+s;d.setAttribute("title",f);function c(E,C,D){var F=E.querySelector("[data-mode-control]");F&&(F.innerHTML=D,F.value=C)}var v=d.querySelector('[data-mode-control-pill="mode"]');if(v){var h=v.querySelector(".composer-config-label");h&&(h.textContent=u),v.setAttribute("title","\u6A21\u5F0F\uFF1A"+u),c(v,t,ta(a,t))}var m=d.querySelector('[data-mode-control-pill="model"]');if(m){var g=m.querySelector(".composer-config-label");g&&(g.textContent=o),m.setAttribute("title","\u6A21\u578B\uFF1A"+o),c(m,n,Ql(n,e))}var y=d.querySelector('[data-mode-control-pill="thinking"]');if(y){var B=y.querySelector(".composer-config-label");B&&(B.textContent=s),y.setAttribute("data-thinking",i),y.setAttribute("title","\u601D\u8003\u6DF1\u5EA6\uFF1A"+s),Gl(y,i,e)}})}function ta(e,t){return Mu(e).map(function(n){return'<option value="'+p(n)+'"'+(n===t?" selected":"")+">"+p(n)+"</option>"}).join("")}function ct(e){return e==="codex"||e==="opencode"?e:"claude"}function Yr(e){return ct(e&&e.provider||r.sessionTool||"claude")}function Hu(){var e=r.config&&r.config.defaultModels&&typeof r.config.defaultModels=="object"?r.config.defaultModels:{};return{claude:typeof e.claude=="string"?e.claude:r.config&&r.config.defaultModel||"",codex:typeof e.codex=="string"?e.codex:r.config&&r.config.defaultCodexModel||"",opencode:typeof e.opencode=="string"?e.opencode:r.config&&r.config.defaultOpenCodeModel||""}}function Ym(e){var t=Hu(),n=ct(e);return n==="codex"?t.codex||"":n==="opencode"?t.opencode||"":t.claude||""}function Qr(e){var t=ct(e),n=r.chatModels&&typeof r.chatModels[t]=="string"?r.chatModels[t]:"";return!n&&t==="claude"&&(n=r.chatModel||""),n||""}function na(e,t){var n=ct(e),i=(t||"").trim();r.chatModels||(r.chatModels={claude:"",codex:"",opencode:""}),r.chatModels[n]=i,r.chatModel=i;try{localStorage.setItem("wand-chat-model-"+n,i),localStorage.removeItem("wand-chat-model")}catch{}}function $r(e){var t=e&&e.id?Kl(e.id):null;if(t&&Object.prototype.hasOwnProperty.call(t,"model"))return t.model||"";if(e&&e.selectedModel)return e.selectedModel;var n=Yr(e),i=Qr(n);return i||Ym(n)||""}function _u(e){var t=e&&e.provider||r.sessionTool||"claude";return t==="codex"?r.availableCodexModels||[]:t==="opencode"?r.availableOpenCodeModels||[]:r.availableModels||[]}function Ql(e,t){for(var n=_u(t),i=e==="default"?"":e||"",a='<option value=""'+(i?"":" selected")+">\u9ED8\u8BA4 \xB7 "+p(Gr("",t))+"</option>",u=0;u<n.length;u++){var o=n[u];if(o.id!=="default"){var s=o.label||o.id,l=Yr(t)==="claude"?o.availability==="verified"?" \xB7 \u5DF2\u9A8C\u8BC1":o.availability==="stale"?" \xB7 \u5F85\u5237\u65B0":o.source==="models-api"?" \xB7 API \u5019\u9009":" \xB7 \u5019\u9009":"";a+='<option value="'+p(o.id)+'"'+(o.id===i?" selected":"")+">"+p(s+l)+"</option>"}}return i&&!n.some(function(d){return d.id===i})&&(a+='<option value="'+p(i)+'" selected>'+p(i)+"\uFF08\u81EA\u5B9A\u4E49\uFF09</option>"),a}function $l(e,t){for(var n=_u(t),i=e==="default"?"":e||"",a='<option value=""'+(i?"":" selected")+">"+p(Gr("",t))+"</option>",u=0;u<n.length;u++){var o=n[u];if(o.id!=="default"){var s=Yr(t)==="claude"?o.availability==="verified"?" \xB7 verified":o.availability==="stale"?" \xB7 stale":o.source==="models-api"?" \xB7 API candidate":" \xB7 candidate":"";a+='<option value="'+p(o.id)+'"'+(o.id===i?" selected":"")+">"+p(o.id+s)+"</option>"}}return i&&!n.some(function(l){return l.id===i})&&(a+='<option value="'+p(i)+'" selected>'+p(i)+"</option>"),a}function dr(e){tn()}var Xr=[{id:"off",label:"auto",hint:"\u4F7F\u7528 provider / \u6A21\u578B\u9ED8\u8BA4\u601D\u8003\u6863\u4F4D"},{id:"standard",label:"low",hint:"Claude/Codex: low \xB7 OpenCode variant: low"},{id:"deep",label:"medium",hint:"Claude/Codex: medium \xB7 OpenCode variant: high"},{id:"max",label:"max",hint:"Claude: max \xB7 Codex: xhigh \xB7 OpenCode variant: max"}];function Qm(e){return e==="low"?"standard":e==="medium"?"deep":e==="xhigh"?"max":"codex:"+e}function Zr(e){if(Yr(e)!=="codex")return Xr;var t=$r(e)||"default",n=r.availableCodexModels||[],i=n.find(function(o){return o.id===t})||n.find(function(o){return o.id==="default"}),a=i&&Array.isArray(i.reasoningEfforts)?i.reasoningEfforts:[];if(!a.length)return Xr;var u=i.defaultReasoningEffort||"";return[{id:"off",label:"auto",hint:u?"\u4F7F\u7528\u6A21\u578B\u9ED8\u8BA4\u6863\u4F4D\uFF08"+u+"\uFF09":"\u4F7F\u7528\u6A21\u578B\u9ED8\u8BA4\u6863\u4F4D"}].concat(a.map(function(o){var s=String(o.effort||"").toLowerCase();return{id:Qm(s),label:s,hint:o.description||s}}).filter(function(o){return o.label}))}function $m(e,t){for(var n=Zr(t),i=0;i<n.length;i++)if(n[i].id===e)return n[i].label;if(typeof e=="string"&&e.indexOf("codex:")===0)return e.slice(6);for(var a=0;a<Xr.length;a++)if(Xr[a].id===e)return Xr[a].label;return"auto"}function ra(e){var t=e&&e.id?Kl(e.id):null;return t&&Object.prototype.hasOwnProperty.call(t,"thinking")?t.thinking||"off":e&&e.thinkingEffort?e.thinkingEffort:r.chatThinking?r.chatThinking:"off"}function Jh(e){tn()}function Xl(e){r.chatThinking=e;try{localStorage.setItem("wand-thinking-effort",e)}catch{}}function Zl(e,t,n,i){return Ou(e.id,function(){return i&&!i.ok?{error:i.error||"\u5207\u6362\u6A21\u578B\u5931\u8D25"}:fetch("/api/sessions/"+encodeURIComponent(e.id)+"/thinking-effort",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({thinkingEffort:t})}).then(function(a){return a.json()})}).then(function(a){Pu(e.id,a)&&typeof x=="function"&&x(n||"\u5DF2\u5207\u6362\u601D\u8003\u6DF1\u5EA6 \u2192 "+Jn(t,Xe()),"success")}).catch(function(a){a&&a.latest&&Jr(e.id,"\u5207\u6362\u601D\u8003\u6DF1\u5EA6\u5931\u8D25")})}function Xm(e){var t=(e||"off").trim(),n=Xe(),i=Zr(n).some(function(a){return a.id===t});i||(t="off"),Xl(t),n&&Zi(n.id,"thinking",t),tn(),n&&Zl(n,t,"\u5DF2\u5207\u6362\u601D\u8003\u6DF1\u5EA6 \u2192 "+Jn(t,n))}function ed(e){if(!e)return!1;var t=e.mode;return t==="managed"||t==="full-access"}function Zm(e){if(!e||ed(e))return"";var t=!!e.autoApprovePermissions;return t?'<button id="auto-approve-toggle" class="composer-pill composer-pill-chip auto-approve-indicator active" type="button" aria-pressed="true" aria-label="\u81EA\u52A8\u6279\u51C6\u5DF2\u542F\u7528\uFF0C\u70B9\u51FB\u5173\u95ED" title="\u81EA\u52A8\u6279\u51C6\u5DF2\u542F\u7528 \u2014 \u70B9\u51FB\u5173\u95ED">'+V("shieldCheck",{size:12,strokeWidth:1.7,cls:"composer-pill-icon"})+'<span class="composer-pill-label">\u81EA\u52A8</span></button>':'<button id="auto-approve-toggle" class="composer-pill composer-pill-chip auto-approve-indicator" type="button" aria-pressed="false" aria-label="\u81EA\u52A8\u6279\u51C6\u5DF2\u5173\u95ED\uFF0C\u70B9\u51FB\u5F00\u542F" title="\u81EA\u52A8\u6279\u51C6\u5DF2\u5173\u95ED \u2014 \u70B9\u51FB\u5F00\u542F">'+V("shield",{size:12,strokeWidth:1.7,cls:"composer-pill-icon"})+'<span class="composer-pill-label">\u624B\u52A8</span></button>'}function td(){return fetch("/api/models",{credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){return e&&Array.isArray(e.models)&&(r.availableModels=e.models,r.availableCodexModels=Array.isArray(e.codexModels)?e.codexModels:[],r.availableOpenCodeModels=Array.isArray(e.opencodeModels)?e.opencodeModels:[],dr(Xe()),ua(e),aa(!1)),e}).catch(function(){return null})}function nd(){if(r.modelsRefreshing)return Promise.resolve(null);r.modelsRefreshing=!0;var e=document.querySelectorAll("#cfg-default-model-refresh, #cfg-commit-model-refresh");return e.forEach(function(t){var n=t,i=n.querySelector("span");n.disabled=!0,n.classList.add("is-loading"),n.setAttribute("aria-busy","true"),i&&(i.textContent="\u68C0\u6D4B\u4E2D")}),fetch("/api/models/refresh",{method:"POST",credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(t&&Array.isArray(t.models)&&(r.availableModels=t.models,r.availableCodexModels=Array.isArray(t.codexModels)?t.codexModels:[],r.availableOpenCodeModels=Array.isArray(t.opencodeModels)?t.opencodeModels:[],dr(Xe()),ua(t),aa(!1),typeof x=="function")){var n=t.models.filter(function(a){return a.availability==="verified"}).length,i="\u6A21\u578B\u5217\u8868\u5DF2\u5237\u65B0"+(t.claudeVersion?"\uFF08claude "+t.claudeVersion+"\uFF09":"");n&&(i+="\uFF1B\u5DF2\u9A8C\u8BC1 "+n+" \u4E2A"),x(i,"success")}return t}).catch(function(){return typeof x=="function"&&x("\u5237\u65B0\u6A21\u578B\u5217\u8868\u5931\u8D25","error"),null}).finally(function(){r.modelsRefreshing=!1,e.forEach(function(t){var n=t,i=n.querySelector("span");n.disabled=!1,n.classList.remove("is-loading"),n.removeAttribute("aria-busy"),i&&(i.textContent="\u5237\u65B0\u5217\u8868")})})}function eg(){var e=document.getElementById("env-preview-modal");if(!e){e=document.createElement("section"),e.id="env-preview-modal",e.className="modal-backdrop hidden",e.innerHTML='<div class="modal env-preview-modal" role="dialog" aria-labelledby="env-preview-title" aria-modal="true"><div class="modal-header"><div><h2 class="modal-title" id="env-preview-title">\u5C06\u6CE8\u5165\u5B50\u8FDB\u7A0B\u7684\u73AF\u5883\u53D8\u91CF</h2><p class="modal-subtitle" id="env-preview-subtitle">\u8FD9\u4E9B\u53D8\u91CF\u4F1A\u88AB\u4F20\u7ED9 claude / codex / opencode\uFF08PTY \u4E0E\u7ED3\u6784\u5316\u8FD0\u884C\u5668\u4E00\u81F4\uFF09\u3002</p></div><button id="env-preview-close" class="btn btn-ghost btn-icon modal-close-btn" type="button" aria-label="\u5173\u95ED"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><line x1="6" y1="6" x2="18" y2="18"/><line x1="18" y1="6" x2="6" y2="18"/></svg></button></div><div class="modal-body env-preview-body"><div class="env-preview-toolbar"><div class="env-preview-meta" id="env-preview-meta">\u52A0\u8F7D\u4E2D\u2026</div><div class="env-preview-controls"><input id="env-preview-search" class="env-preview-search" type="search" placeholder="\u641C\u7D22\u53D8\u91CF\u540D\u2026" /><label class="env-preview-reveal"><input id="env-preview-reveal-toggle" type="checkbox" /><span>\u663E\u793A\u654F\u611F\u503C</span></label></div></div><div class="env-preview-list" id="env-preview-list" tabindex="0"><div class="env-preview-loading">\u52A0\u8F7D\u4E2D\u2026</div></div></div><div class="modal-footer env-preview-footer"><span class="env-preview-hint">\u654F\u611F\u5B57\u6BB5\uFF08\u542B KEY/TOKEN/SECRET \u7B49\uFF09\u9ED8\u8BA4\u63A9\u7801\uFF0C\u53EF\u52FE\u9009\u300C\u663E\u793A\u654F\u611F\u503C\u300D\u4E34\u65F6\u8FD8\u539F\u3002</span><button id="env-preview-close-2" class="btn btn-secondary btn-sm" type="button">\u5173\u95ED</button></div></div>',document.body.appendChild(e),e.addEventListener("click",function(s){s.target===e&&Nu()});var t=e.querySelector("#env-preview-close");t&&t.addEventListener("click",Nu);var n=e.querySelector("#env-preview-close-2");n&&n.addEventListener("click",Nu);var a=e.querySelector("#env-preview-search");a&&a.addEventListener("input",function(){id()});var i=e.querySelector("#env-preview-reveal-toggle");i&&i.addEventListener("change",function(){rd(i.checked)})}e.classList.remove("closing"),e.classList.remove("hidden");var i=e.querySelector("#env-preview-reveal-toggle");i&&(i.checked=!1);var a=e.querySelector("#env-preview-search");a&&(a.value=""),rd(!1)}function Nu(){var e=document.getElementById("env-preview-modal");e&&Vu(e)}function rd(e){var t=document.getElementById("env-preview-list"),n=document.getElementById("env-preview-meta");t&&(t.innerHTML='<div class="env-preview-loading">\u52A0\u8F7D\u4E2D\u2026</div>'),n&&(n.textContent="\u52A0\u8F7D\u4E2D\u2026");var i="/api/settings/env-preview"+(e?"?reveal=1":"");fetch(i,{credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(!a||!Array.isArray(a.entries)){t&&(t.innerHTML='<div class="env-preview-empty">\u8BFB\u53D6\u5931\u8D25\u3002</div>'),n&&(n.textContent="\u8BFB\u53D6\u5931\u8D25");return}if(r._envPreview=a,n){var u=a.inheritEnv?"\u7EE7\u627F\u7236\u8FDB\u7A0B":"\u6700\u5C0F\u767D\u540D\u5355";n.innerHTML='<span class="env-preview-pill '+(a.inheritEnv?"is-inherit":"is-minimal")+'">'+u+'</span><span class="env-preview-count">\u5171 '+a.total+" \u9879</span>"}id()}).catch(function(){t&&(t.innerHTML='<div class="env-preview-empty">\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002</div>'),n&&(n.textContent="\u8BFB\u53D6\u5931\u8D25")})}function id(){var e=document.getElementById("env-preview-list");if(e){var t=r._envPreview;if(!t||!Array.isArray(t.entries)){e.innerHTML='<div class="env-preview-empty">\u5C1A\u672A\u52A0\u8F7D\u3002</div>';return}for(var n=document.getElementById("env-preview-search"),i=(n&&n.value||"").trim().toLowerCase(),a="",u=0,o=0;o<t.entries.length;o++){var s=t.entries[o];if(!(i&&s.name.toLowerCase().indexOf(i)===-1)){u++;var l=typeof s.value=="string"&&s.value.charAt(0)==="<"&&s.value.charAt(s.value.length-1)===">";a+='<div class="env-preview-row'+(s.sensitive?" is-sensitive":"")+'"><div class="env-preview-name">'+p(s.name)+(s.sensitive?'<span class="env-preview-badge" title="\u88AB\u8BC6\u522B\u4E3A\u654F\u611F\u5B57\u6BB5">\u654F\u611F</span>':"")+(l?'<span class="env-preview-badge env-preview-badge-runtime" title="\u6309\u4F1A\u8BDD\u52A8\u6001\u6CE8\u5165">\u8FD0\u884C\u65F6</span>':"")+'</div><div class="env-preview-value'+(l?" is-runtime":"")+'" title="'+p(String(s.value))+'">'+p(String(s.value))+'</div><div class="env-preview-len">'+s.length+" \u5B57\u7B26</div></div>"}}u===0&&(a='<div class="env-preview-empty">\u6CA1\u6709\u5339\u914D\u7684\u53D8\u91CF\u3002</div>'),e.innerHTML=a}}function ad(e){return e==="codex"?r.availableCodexModels||[]:e==="opencode"?r.availableOpenCodeModels||[]:r.availableModels||[]}function ud(e){if(e){var t=ct(e.getAttribute("data-provider")),n=e.querySelector(".model-combobox-input"),i=e.closest(".settings-model-field"),a=i?i.querySelector("[data-model-status]"):null;if(!(!n||!a)){for(var u=(n.value||"").trim(),o=ad(t),s=null,l=0;l<o.length;l++)if(o[l].id===u){s=o[l];break}if(a.classList.remove("is-custom","is-known"),!u){a.textContent="\u8DDF\u968F CLI \u9ED8\u8BA4";return}if(s){s.availability==="verified"?a.textContent="\u5DF2\u7531 Claude Code \u9A8C\u8BC1":s.availability==="stale"?a.textContent="\u9A8C\u8BC1\u8BB0\u5F55\u5F85\u5237\u65B0":s.source==="models-api"?a.textContent="API \u5019\u9009\uFF0C\u5C1A\u672A\u9A8C\u8BC1":a.textContent="\u5DF2\u68C0\u6D4B\u5230\uFF0C\u5C1A\u672A\u9A8C\u8BC1",a.classList.add("is-known");return}a.textContent="\u81EA\u5B9A\u4E49\u540D\u79F0",a.classList.add("is-custom")}}}function cr(e){if(e){var t=ct(e.getAttribute("data-provider")),n=e.querySelector(".model-combobox-input"),i=e.querySelector(".model-combobox-menu");if(!(!n||!i)){for(var a=n.value||"",u=a.trim(),o=e.classList.contains("is-filtering")?u.toLowerCase():"",s=ad(t),l=null,d=!1,f=[],c=0;c<s.length;c++){var v=s[c];if(v.id==="default"){l=v;continue}v.id===u&&(d=!0);var h=v.label||v.id;if(!(o&&v.id.toLowerCase().indexOf(o)===-1&&h.toLowerCase().indexOf(o)===-1)){var m=t!=="claude"?h===v.id?"\u5DF2\u68C0\u6D4B\u6A21\u578B":v.id:v.availability==="verified"?"\u5DF2\u7531 Claude Code \u9A8C\u8BC1":v.availability==="stale"?"\u9A8C\u8BC1\u8BB0\u5F55\u5F85\u5237\u65B0":v.source==="models-api"?"API \u5019\u9009\uFF0C\u5C1A\u672A\u9A8C\u8BC1":v.note||"\u5C1A\u672A\u9A8C\u8BC1";f.push({value:v.id,label:h,meta:m,custom:!1})}}var g=t==="codex"?"\u8DDF\u968F Codex \u9ED8\u8BA4":t==="opencode"?"\u8DDF\u968F OpenCode \u9ED8\u8BA4":"\u8DDF\u968F Claude Code \u9ED8\u8BA4",y=l&&l.label?l.label:"\u4E0D\u4F20 --model \u53C2\u6570",B="";(!o||g.toLowerCase().indexOf(o)!==-1||y.toLowerCase().indexOf(o)!==-1)&&(B+='<button type="button" class="model-combobox-option'+(u?"":" is-selected")+'" role="option" aria-selected="'+(u?"false":"true")+'" data-model-value=""><span class="model-combobox-option-check" aria-hidden="true"><svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 4 4L19 6"/></svg></span><span class="model-combobox-option-copy"><span class="model-combobox-option-label">'+p(g)+'</span><span class="model-combobox-option-meta">'+p(y)+"</span></span></button>");for(var E=0;E<f.length;E++){var C=f[E],D=C.value===u;B+='<button type="button" class="model-combobox-option'+(D?" is-selected":"")+'" role="option" aria-selected="'+(D?"true":"false")+'" data-model-value="'+p(C.value)+'"><span class="model-combobox-option-check" aria-hidden="true"><svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 4 4L19 6"/></svg></span><span class="model-combobox-option-copy"><span class="model-combobox-option-label">'+p(C.label)+'</span><span class="model-combobox-option-meta">'+p(C.meta)+"</span></span></button>"}u&&!d&&(B+='<button type="button" class="model-combobox-option model-combobox-option-custom is-selected" role="option" aria-selected="true" data-model-value="'+p(u)+'"><span class="model-combobox-option-custom-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z"/></svg></span><span class="model-combobox-option-copy"><span class="model-combobox-option-label">\u4F7F\u7528\u81EA\u5B9A\u4E49\u540D\u79F0</span><span class="model-combobox-option-meta">'+p(u)+"</span></span></button>"),B||(B='<div class="model-combobox-empty">\u6CA1\u6709\u5339\u914D\u7684\u6A21\u578B\uFF0C\u53EF\u4EE5\u7EE7\u7EED\u8F93\u5165\u81EA\u5B9A\u4E49\u540D\u79F0\u3002</div>'),i.innerHTML=B;for(var F=i.querySelectorAll(".model-combobox-option"),L=-1,S=0;S<F.length;S++)if(F[S].getAttribute("aria-selected")==="true"){L=S;break}e._wandModelActiveIndex=L>=0?L:F.length?0:-1,od(e),ud(e)}}}function od(e){if(e){var t=e.querySelector(".model-combobox-menu"),n=e.querySelector(".model-combobox-input");if(!(!t||!n)){for(var i=t.querySelectorAll(".model-combobox-option"),a=typeof e._wandModelActiveIndex=="number"?e._wandModelActiveIndex:-1,u=0;u<i.length;u++)i[u].classList.toggle("is-active",u===a),u===a&&(i[u].id||(i[u].id=(t.id||"model-listbox")+"-option-"+u),n.setAttribute("aria-activedescendant",i[u].id));a<0&&n.removeAttribute("aria-activedescendant")}}}function ia(e){if(e){var t=e.querySelector(".model-combobox-input"),n=e.querySelector(".model-combobox-menu");!t||!n||(document.querySelectorAll(".model-combobox.is-open").forEach(function(i){i!==e&&Dn(i)}),cr(e),e.classList.add("is-open"),n.classList.remove("hidden"),t.setAttribute("aria-expanded","true"))}}function Dn(e){if(e){var t=e.querySelector(".model-combobox-input"),n=e.querySelector(".model-combobox-menu");e.classList.remove("is-open"),e.classList.remove("is-filtering"),n&&n.classList.add("hidden"),t&&(t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-activedescendant"))}}function sd(e,t){if(e){var n=e.querySelector(".model-combobox-input");if(n){var i=document.activeElement===n;n.value=t||"",n.dataset.modelInitialized="true",n.dataset.modelDirty="true",e.classList.remove("is-filtering"),ud(e),Dn(e),i&&n.focus()}}}function tg(){window.__wandSettingsModelOutsideBound||(window.__wandSettingsModelOutsideBound=!0,document.addEventListener("click",function(t){var n=t.target;document.querySelectorAll(".model-combobox.is-open").forEach(function(i){(!n||!i.contains(n))&&Dn(i)})}));var e=document.querySelectorAll(".model-combobox");e.forEach(function(t){if(t.dataset.bound!=="true"){t.dataset.bound="true";var n=t.querySelector(".model-combobox-input"),i=t.querySelector(".model-combobox-toggle"),a=t.querySelector(".model-combobox-menu");!n||!i||!a||(n.addEventListener("focus",function(){ia(t)}),n.addEventListener("input",function(){n.dataset.modelInitialized="true",n.dataset.modelDirty="true",t.classList.add("is-filtering"),ia(t)}),n.addEventListener("keydown",function(u){if(u.key==="Escape"){u.preventDefault(),Dn(t);return}if(!(u.key!=="ArrowDown"&&u.key!=="ArrowUp"&&u.key!=="Enter")){if(!t.classList.contains("is-open")){if(u.key==="Enter")return;ia(t)}var o=a.querySelectorAll(".model-combobox-option");if(o.length){u.preventDefault();var s=typeof t._wandModelActiveIndex=="number"?t._wandModelActiveIndex:-1;if(u.key==="ArrowDown"&&(s=s<o.length-1?s+1:0),u.key==="ArrowUp"&&(s=s>0?s-1:o.length-1),t._wandModelActiveIndex=s,od(t),u.key==="Enter"){var l=o[s];l&&sd(t,l.getAttribute("data-model-value")||"")}else{var d=o[s];d&&typeof d.scrollIntoView=="function"&&d.scrollIntoView({block:"nearest"})}}}}),i.addEventListener("mousedown",function(u){u.preventDefault()}),i.addEventListener("click",function(){t.classList.contains("is-open")?Dn(t):ia(t)}),a.addEventListener("mousedown",function(u){u.preventDefault()}),a.addEventListener("click",function(u){var o=u.target.closest(".model-combobox-option");o&&sd(t,o.getAttribute("data-model-value")||"")}),t.addEventListener("focusout",function(){setTimeout(function(){t.contains(document.activeElement)||Dn(t)},0)}),cr(t))}})}function aa(e){var t=document.getElementById("cfg-commit-cli"),n=document.getElementById("cfg-commit-model-combobox"),i=document.getElementById("cfg-commit-model"),a=document.getElementById("cfg-commit-model-provider");if(!(!t||!n||!i)){var u=ct(t.value);n.setAttribute("data-provider",u),i.placeholder=u==="codex"?"\u8DDF\u968F Codex \u9ED8\u8BA4":u==="opencode"?"\u8DDF\u968F OpenCode \u9ED8\u8BA4":"\u8DDF\u968F Claude Code \u9ED8\u8BA4",a&&(a.textContent=u==="codex"?"Codex CLI":u==="opencode"?"OpenCode CLI":"Claude Code"),e&&(i.value="",i.dataset.modelDirty="true"),cr(n)}}function ua(e){var t=Hu(),n=document.getElementById("cfg-default-model");if(n){n.dataset.modelInitialized!=="true"&&(n.value=r.configDefaultModels&&r.configDefaultModels.claude||t.claude||"",n.dataset.modelInitialized="true");var i=n.closest(".model-combobox");i&&cr(i)}var a=document.getElementById("cfg-default-codex-model");if(a){a.dataset.modelInitialized!=="true"&&(a.value=r.configDefaultModels&&r.configDefaultModels.codex||t.codex||"",a.dataset.modelInitialized="true");var u=a.closest(".model-combobox");u&&cr(u)}var o=document.getElementById("cfg-default-opencode-model");if(o){o.dataset.modelInitialized!=="true"&&(o.value=r.configDefaultModels&&r.configDefaultModels.opencode||t.opencode||"",o.dataset.modelInitialized="true");var s=o.closest(".model-combobox");s&&cr(s)}var l=document.getElementById("cfg-default-model-version");l&&e&&(l.textContent=e.claudeVersion?"\u5DF2\u68C0\u6D4B\u5230 Claude CLI "+e.claudeVersion+"\uFF1B\u5217\u8868\u5DF2\u540C\u6B65 Codex \u4E0E OpenCode \u53EF\u7528\u6A21\u578B\u3002":"\u672A\u8BFB\u53D6\u5230 Claude CLI \u7248\u672C\uFF1B\u4ECD\u53EF\u76F4\u63A5\u8F93\u5165\u81EA\u5B9A\u4E49\u6A21\u578B\u540D\u79F0\u3002")}function Xe(){if(!r.selectedId)return null;for(var e=0;e<r.sessions.length;e++)if(r.sessions[e].id===r.selectedId)return r.sessions[e];return null}function ng(e){var t=(e||"").trim(),n=Xe(),i=Yr(n);na(i,t),n&&Zi(n.id,"model",t);var a=!1;if(Zr(n).some(function(s){return s.id===ra(n)})||(a=!0,Xl("off"),n&&Zi(n.id,"thinking","off")),tn(),!!n){var u={ok:!1,error:""};if(Ou(n.id,function(){return fetch("/api/sessions/"+encodeURIComponent(n.id)+"/model",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({model:t||null})}).then(function(s){return s.json()}).then(function(s){return u.ok=!!(s&&s.id&&!s.error),u.error=s&&s.error?s.error:"",s})}).then(function(s){if(!a&&Pu(n.id,s)&&typeof x=="function"){var l=Gr(t,Xe()||n),d=n.provider==="codex"?"\uFF08\u4E0B\u6B21\u5BF9\u8BDD\u751F\u6548\uFF09":"";x("\u5DF2\u5207\u6362\u6A21\u578B \u2192 "+l+d,"success")}}).catch(function(s){u.ok=!1,!a&&s&&s.latest&&Jr(n.id,"\u5207\u6362\u6A21\u578B\u5931\u8D25")}),a){var o=Gr(t,n);Zl(n,"off","\u5DF2\u5207\u6362\u6A21\u578B \u2192 "+o+"\uFF1B\u601D\u8003\u6DF1\u5EA6\u5DF2\u56DE\u843D\u4E3A\u81EA\u52A8",u)}}}function rg(e){var t=dt($e(),(e||"default").trim());r.chatMode=t,tn();var n=Xe();if(!n||!n.id){x&&x("\u65B0\u4F1A\u8BDD\u6A21\u5F0F\uFF1A"+t,"info");return}Zi(n.id,"mode",t),Ou(n.id,function(){return fetch("/api/sessions/"+encodeURIComponent(n.id)+"/mode",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({mode:t})}).then(function(i){return i.json()})}).then(function(i){if(Pu(n.id,i)&&typeof x=="function"){var a=r.sessions.find(function(s){return s.id===n.id})||n,u=a.mode||t;r.chatMode=dt(a.provider||$e(),u),tn();var o=n.provider==="codex"?"\uFF08Codex \u56FA\u5B9A\u5168\u6743\u9650\uFF09":"";x("\u5DF2\u5207\u6362\u6A21\u5F0F \u2192 "+u+o,"success")}}).catch(function(i){i&&i.latest&&Jr(n.id,"\u5207\u6362\u6A21\u5F0F\u5931\u8D25")})}function ld(e,t,n,i){var a=ct(r.sessionTool),u=Qr(a),o=r.chatThinking||"off",s={cwd:t||Qe(),mode:n||r.chatMode||r.config&&r.config.defaultMode||"default",provider:a,runner:a==="codex"?"codex-cli-exec":a==="opencode"?"opencode-cli-run":r.config&&r.config.structuredRunner==="sdk"?"claude-sdk":r.structuredRunner||"claude-cli-print",prompt:e||void 0,worktreeEnabled:i===!0,model:u||void 0,thinkingEffort:o,sessionSource:"interactive"};return fetch("/api/structured-sessions",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(s)}).then(function(l){return l.json()}).then(function(l){if(l.error)throw new Error(l.error);return r.selectedId=l.id,Ee(),r.drafts[l.id]="",Dt(),ee(l),pe(),jr(l.id),Gn(l.id),kn(l.id).then(function(){return l})})}function oa(){var e=!!r.selectedId,t=document.getElementById("output"),n=document.getElementById("chat-output"),i=document.getElementById("blank-chat"),a=r.sessions.find(function(l){return l.id===r.selectedId}),u=se(a),o=e&&!u&&r.currentView==="terminal",s=e&&(u||r.currentView!=="terminal");u?r.currentView="chat":e||(r.currentView="terminal"),t&&(t.classList.toggle("active",o),t.classList.toggle("hidden",!o)),n&&(n.classList.toggle("active",s),n.classList.toggle("hidden",!s)),i&&i.classList.toggle("hidden",e),n&&s&&yu(n),Er(),Ge(),Rr()}function fr(){var e=document.getElementById("mode-description"),t=document.getElementById("session-kind-description"),n=r.sessionTool||"claude",i=r.sessionCreateKind||"structured";r.sessionTool=n,r.modeValue=dt(n,r.modeValue||r.chatMode||"default");var a=document.querySelectorAll("#provider-cards .provider-card");a.length&&a.forEach(function(s){var l=s.getAttribute("data-provider");s.classList.toggle("active",l===n),s.classList.remove("disabled")});var u=document.querySelectorAll("#session-kind-cards .session-kind-card");u.length&&u.forEach(function(s){var l=s.getAttribute("data-session-kind"),d=!1;s.classList.toggle("active",l===i),s.classList.toggle("disabled",d)});var o=document.querySelectorAll("#mode-cards .mode-card");o.length&&o.forEach(function(s){s.classList.toggle("active",s.getAttribute("data-mode")===r.modeValue)}),t&&(t.textContent=Ko(i)),e&&(e.textContent=Rl(n,r.modeValue))}function ee(e){if(!(!e||!e.id)){var t=r.sessions.find(function(s){return s.id===e.id})||null,n=Gd(e,t);if(Array.isArray(n.messages)&&typeof n.messageOffset=="number"){var i=zd(t,n.messages,n.messageOffset,n.messageTotal);n.messages=i.messages,n.messageOffset=i.messageOffset,n.messageTotal=i.messageTotal}var a=!1,u=null;r.sessions=r.sessions.map(function(s){return s.id!==n.id?s:(u=s,a=!0,Object.assign({},s,n))}),a||r.sessions.unshift(n);var o=r.sessions.find(function(s){return s.id===n.id})||n;o&&Array.isArray(o.queuedMessages)&&n.id===r.selectedId&&(vi(o),fo(),Fn()),n.id===r.selectedId&&(du(),$t()),n.status&&n.status!=="running"&&r.crossSessionQueue.length>0&&setTimeout(Pi,0)}}function Gn(e){!e||!r.ws||r.ws.readyState!==WebSocket.OPEN||r.ws.send(JSON.stringify({type:"subscribe",sessionId:e}))}function ig(e,t){if(!e)return t;var n=Object.assign({},e,t),i=e.output||"",a=t.output||"",u=i.length>a.length,o=e.structuredState||null,s=t.structuredState||null,l=e.sessionKind==="structured"||t.sessionKind==="structured",d=!!(e.messages&&e.messages.length&&(function(){var g=e.messages[e.messages.length-1];return g&&g.role==="assistant"&&Array.isArray(g.content)&&g.content.some(function(y){return y&&y.__processing})})()),f=Array.isArray(e.messages)?l?Cr(e.messages):e.messages:[],c=Array.isArray(t.messages)?l?Cr(t.messages):t.messages:[],v=c.length>0&&(function(){var g=c[c.length-1];return g&&g.role==="assistant"&&Array.isArray(g.content)&&!g.content.some(function(y){return y&&y.__processing})})(),h=e.sessionKind==="structured"&&!!o&&o.inFlight===!0&&(!s||s.inFlight!==!0)&&d&&!!o.activeRequestId&&!!s&&!!s.activeRequestId&&s.activeRequestId===o.activeRequestId&&!v,m=f.length>c.length||f.length>0&&c.length>0&&JSON.stringify(f[f.length-1])!==JSON.stringify(c[c.length-1])&&JSON.stringify(f).length>JSON.stringify(c).length;return u&&(n.output=i),h&&(n.status=e.status||n.status,n.structuredState=Object.assign({},s||{},o,{inFlight:!0}),n.messages=e.messages),m&&(n.messages=f),e.id===r.selectedId&&(e.permissionBlocked&&t.permissionBlocked===!1||e.permissionBlocked&&!t.permissionBlocked&&(n.permissionBlocked=!0),e.pendingEscalation&&!t.pendingEscalation&&t.permissionBlocked!==!1&&(n.pendingEscalation=e.pendingEscalation),e.messages&&e.messages.length>0&&(!t.messages||t.messages.length===0)&&(n.messages=e.messages)),n}function Ze(e,t,n){if(e&&e.messages&&e.messages.length>0)return e.messages;if(e&&e.sessionKind==="structured")return[];if(!n)return[];var i=typeof t=="string"?t:e&&e.output||"";return i?nm(i,e&&e.command):[]}function ag(e){if(!e||!e.length)return null;if(r.selectedId){var t=e.find(function(a){return a.id===r.selectedId});return t?t.id:null}var n=e.find(function(a){return a.status==="running"});if(n)return n.id;var i=e.find(function(a){return!a.archived});return i?i.id:e[0].id}function nn(e){var t=e||{};return fetch("/api/sessions",{credentials:"same-origin"}).then(function(n){if(n.status===401){Nl();return}return n.json()}).then(function(n){var i=n||[],a=new Set(i.map(function(c){return c.id}));Object.keys(r.drafts).forEach(function(c){a.has(c)||delete r.drafts[c]}),r.sessions=i.map(function(c){var v=r.sessions.find(function(h){return h.id===c.id});return ig(v,c)});var u=ag(r.sessions);if(u!==void 0&&(r.selectedId=u),vo(),Fn(),r.bootstrapping=!1,Ee(),r.modalOpen)pe();else{var o=document.getElementById("sessions-list"),s=Ma();if(o&&o.innerHTML===s){var l=document.getElementById("session-count");l&&(l.textContent=String(r.sessions.length))}else{o&&(o.innerHTML=s,Wt(o));var l=document.getElementById("session-count");l&&(l.textContent=String(r.sessions.length))}}ei(),r.selectedId&&r.gitStatusSessionId!==r.selectedId&&Hn(r.selectedId);var d=Promise.resolve();if(!t.skipSelectedOutputReload&&r.selectedId)d=kn(r.selectedId);else if(r.selectedId){var f=r.sessions.find(function(c){return c.id===r.selectedId});se(f)&&(Dt({preserveStickState:!0}),hu(!0))}return d.then(function(){r.crossSessionQueue.length>0&&Pi(),At(),Za()})}).catch(function(n){var i=n&&n.message||"",a=i==="Failed to fetch"||i==="NetworkError when attempting to fetch resource."||i==="Load failed"||/aborted|aborterror|networkerror|failed to fetch/i.test(i);a||console.error("[wand] loadSessions failed:",n)})}var ju=null;function Ru(){ju||(ju=setTimeout(function(){ju=null,pe()},200))}function pe(){var e=document.getElementById("sessions-list"),t=document.getElementById("session-count");e&&(e.innerHTML=Ma(),Wt(e)),t&&(t.textContent=String(r.sessions.length)),typeof rn=="function"&&rn(),ei(),r.crossSessionQueue.length>0&&At()}function ei(){var e=r.sessions.find(function(m){return m.id===r.selectedId});e||(Kn(!1),lu(),rl());var t=e?lr(e.command):"Wand",n=e?Dr(e):"\u5F00\u59CB\u5BF9\u8BDD",i=document.querySelector(".session-summary-value"),a=document.getElementById("terminal-title"),u=document.getElementById("terminal-info"),o=document.querySelector(".topbar-session-title, .topbar-tagline");o&&e&&(o.classList.remove("topbar-tagline"),o.classList.add("topbar-session-title"),o.textContent=e.title||lr(e.command),o.setAttribute("title",e.description||e.command||""));var s=document.getElementById("blank-chat"),l=document.getElementById("output"),d=document.getElementById("chat-output"),f=document.getElementById("stop-button");i&&i.textContent!==t&&(i.textContent=t),a&&a.textContent!==t&&(a.textContent=t),u&&(u.textContent=e?n+" \xB7 "+Km(e):n);var c=document.getElementById("session-kind-display"),v=e?Um(e):"\u7EC8\u7AEF";c&&c.textContent!==v&&(c.textContent=v),os(),!r.terminal&&l&&e&&ur(),r.terminal&&l&&!l.contains(r.terminal.element)&&(Mr(),ur()),e||(r.terminalSessionId=null,r.terminalOutput="",r.terminalOutputMarker=0),r.terminal&&e&&r.currentView==="terminal"&&yt("view");var h=document.querySelector(".input-panel");e?(s&&s.classList.add("hidden"),l&&l.classList.remove("hidden"),d&&d.classList.remove("hidden"),h&&h.classList.remove("hidden")):(s&&s.classList.remove("hidden"),l&&l.classList.add("hidden"),d&&d.classList.add("hidden"),f&&f.classList.add("hidden"),h&&h.classList.add("hidden")),Qi(),dr(Xe()),oa(),du()}function kn(e){r.chatRenderTimer&&(clearTimeout(r.chatRenderTimer),r.chatRenderTimer=null);var t=r.sessions.find(function(i){return i.id===e}),n="/api/sessions/"+e;return zl(t)&&(n+="?format=chat"),fetch(n,{credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i.error){r.selectedId===e&&(r.selectedId=null,Ee()),nn();return}if(ee(i),ei(),r.terminal&&e===r.selectedId&&i.output!==void 0){var a=!!r.ws&&(r.ws.readyState===WebSocket.OPEN||r.ws.readyState===WebSocket.CONNECTING);a?Ye("session-switch"):(Si(e,i.output,{mode:"append"}),Ye("session-switch",{forceReplay:!0}))}var u=r.sessions.find(function(o){return o.id===e});r.currentMessages=Re(u,Ze(u,i.output,!1)),We(!1)})}var Wu=!1;function ug(){if(Wu)return!1;var e=r.selectedId;if(!e)return!1;var t=r.sessions.find(function(o){return o.id===e});if(!t)return!1;var n=typeof t.messageOffset=="number"?t.messageOffset:0;if(n<=0)return!1;var i=40,a=Math.max(0,n-i),u=n-a;return Wu=!0,fetch("/api/sessions/"+encodeURIComponent(e)+"/messages?offset="+a+"&limit="+u,{credentials:"same-origin"}).then(function(o){return o.json()}).then(function(o){if(o&&Array.isArray(o.messages)&&t.messageOffset===n){var s=Array.isArray(t.messages)?t.messages:[];t.messages=o.messages.concat(s),t.messageOffset=a,typeof o.total=="number"&&(t.messageTotal=o.total),e===r.selectedId&&(r.currentMessages=Re(t,Ze(t,t.output,!1)),r.chatRenderedCount=r.currentMessages.length,We(!0))}}).catch(function(){}).finally(function(){Wu=!1}),!0}function Nt(e){var t=r.sessions.find(function(o){return o.id===e});if(t){r.selectedId!==e&&Mr(),r.selectedId=e,Ee(),r.toolContentCache={},r.messageQueue=[],r.pendingMessages=[],vi(t),vo(),Fn(),Dt(),r.currentMessages=[],r.chatRenderTimer&&(clearTimeout(r.chatRenderTimer),r.chatRenderTimer=null);var n=document.getElementById("todo-progress");n&&n.classList.add("hidden");var i=document.querySelector(".structured-status-bar");i&&i.remove(),r._statusBarTimerId&&(clearInterval(r._statusBarTimerId),r._statusBarTimerId=null),r._statusBarStartTime=0;var a=document.querySelector(".input-composer");a&&a.classList.remove("in-flight");var u=t;r.preferredCommand=$e(),r.chatMode=dt("claude",u&&u.mode?u.mode:r.chatMode),r.terminalInteractive&&u&&u.status!=="running"&&Kn(!1),pe(),jr(e),r.filePanelOpen&&(Zd(u),Mt()),kn(e).then(function(){Ht(!0)}),Gn(e),r.gitStatus=null,r.gitStatusSessionId=null,xa(),Hn(e,{force:!0})}}function og(){var e=document.getElementById("sessions-drawer"),t=document.querySelector(".main-layout"),n=Ne(),i=!!r.sidebarPinned&&!!r.sidebarCollapsed,a=i||!n&&(!!r.sidebarPinned||!!r.sessionsDrawerOpen);e&&(e.classList.toggle("pinned",a),e.classList.toggle("collapsed",i)),t&&(t.classList.toggle("sidebar-pinned",a),t.classList.toggle("sidebar-collapsed",i));var u=document.getElementById("sidebar-pin-btn");u&&(u.classList.toggle("pinned",!!r.sidebarPinned),u.title=r.sidebarPinned?"\u5DF2\u56FA\u5B9A\u5E38\u9A7B\uFF08\u70B9\u51FB\u89E3\u9664\u9501\u5B9A\uFF09":"\u56FA\u5B9A\u4FA7\u680F\u5E38\u9A7B",u.setAttribute("aria-label",r.sidebarPinned?"\u89E3\u9664\u56FA\u5B9A\u5E38\u9A7B":"\u56FA\u5B9A\u4FA7\u680F\u5E38\u9A7B"),u.setAttribute("aria-pressed",r.sidebarPinned?"true":"false"))}function ti(){var e=document.getElementById("sessions-drawer"),t=document.getElementById("sessions-drawer-backdrop"),n=document.querySelector(".main-layout");e&&e.classList.toggle("open",r.sessionsDrawerOpen),t&&t.classList.toggle("open",bo()),n&&n.classList.toggle("sidebar-open",r.sessionsDrawerOpen);var i=document.getElementById("sessions-toggle-button");i&&i.classList.toggle("active",r.sessionsDrawerOpen),og()}function sg(){var e=Ne();if(!e){var t=r.sidebarPinned?!1:!r.sessionsDrawerOpen;r.sessionsDrawerOpen=t,t&&(r.sidebarCollapsed=!1,we("wand-sidebar-collapsed",!1)),we("wand-sidebar-open",r.sessionsDrawerOpen),hn(),ri();return}if(r.sessionsDrawerOpen=!r.sessionsDrawerOpen,we("wand-sidebar-open",r.sessionsDrawerOpen),r.sessionsDrawerOpen){r.filePanelOpen=!1;try{localStorage.setItem("wand-file-panel-open","false")}catch{}}hn()}function ni(){var e=Ne();if(!e){if(!r.sidebarPinned&&!r.sessionsDrawerOpen)return;Vr(),r.sidebarPinned=!1,r.sessionsDrawerOpen=!1,we("wand-sidebar-pinned",!1),we("wand-sidebar-open",!1),hn(),ri();return}r.sessionsDrawerOpen&&(Vr(),r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),hn())}function lg(){if(Ne()){ni();return}r.sidebarPinned||r.sidebarCollapsed||!r.sessionsDrawerOpen||(Vr(),r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),hn(),ri())}function dd(e){var t=document.getElementById("composer-plus-popover"),n=document.getElementById("attach-btn");r.plusPopoverOpen=!!e,t&&t.classList.toggle("hidden",!e),n&&(n.classList.toggle("active",!!e),n.setAttribute("aria-expanded",e?"true":"false"))}function dg(){dd(!r.plusPopoverOpen)}function sa(){r.plusPopoverOpen&&dd(!1)}function jt(){Ne()&&r.sessionsDrawerOpen&&ni()}function ri(){var e=document.querySelector(".main-layout");if(e){var t=function(n){n.propertyName==="padding-left"&&(e.removeEventListener("transitionend",t),Pt(!0))};e.addEventListener("transitionend",t)}setTimeout(function(){Pt(!0)},350)}var Rt=null;function cg(){return Rt&&document.body.contains(Rt)||(Rt=document.createElement("div"),Rt.className="sidebar-tile-bubble",Rt.setAttribute("role","tooltip"),document.body.appendChild(Rt)),Rt}function rn(){Rt&&Rt.classList.remove("visible")}function fg(e,t){if(!t){rn();return}var n=cg();n.textContent=t.length>400?t.slice(0,400)+"\u2026":t;var i=e.getBoundingClientRect();n.classList.add("visible");var a=n.getBoundingClientRect(),u=i.top+i.height/2,o=u-a.height/2,s=8,l=window.innerHeight-a.height-8;o<s&&(o=s),o>l&&(o=Math.max(s,l)),n.style.left=i.right+12+"px",n.style.top=o+"px",n.style.setProperty("--bubble-tail-y",u-o+"px")}function pg(e){if(e.dataset.collapsedSessionId){var t=r.sessions.find(function(a){return a.id===e.dataset.collapsedSessionId});if(!t)return"";var n=Mc(t);return n||t.summary||t.command||""}if(e.dataset.collapsedHistoryId){var i=r.claudeHistory.find(function(a){return a.claudeSessionId===e.dataset.collapsedHistoryId});if(i&&i.firstUserMessage)return i.firstUserMessage}return""}function vg(e){var t=e.target;if(!(!t||!(t instanceof Element))){var n=t.closest(".sidebar-collapsed-tile");if(!n){rn();return}var i=pg(n);if(!i){rn();return}fg(n,i)}}function mg(e){var t=e.relatedTarget;t&&t instanceof Element&&t.closest(".sidebar-collapsed-tile")||rn()}function gg(){var e=Ne();r.sidebarPinned||(r.sidebarPinned=!0,we("wand-sidebar-pinned",!0)),r.sidebarCollapsed=!r.sidebarCollapsed,we("wand-sidebar-collapsed",r.sidebarCollapsed),r.sidebarCollapsed?r.sessionsDrawerOpen=!1:e?(r.sidebarPinned=!1,r.sessionsDrawerOpen=!0,we("wand-sidebar-pinned",!1)):r.sessionsDrawerOpen=!0,we("wand-sidebar-open",r.sessionsDrawerOpen),hn(),pe(),yg(),rn(),ri()}function hg(){Ne()||(r.sidebarPinned=!r.sidebarPinned,r.sessionsDrawerOpen=!0,we("wand-sidebar-pinned",r.sidebarPinned),we("wand-sidebar-open",!0),hn(),ri())}function yg(){var e=document.getElementById("sidebar-collapse-btn");if(e){var t=!!r.sidebarPinned&&!!r.sidebarCollapsed;e.classList.toggle("collapsed",t),e.title=t?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4E3A\u7A84\u6761",e.setAttribute("aria-label",t?"\u5C55\u5F00\u4FA7\u680F":"\u6536\u8D77\u4E3A\u7A84\u6761"),e.innerHTML=t?'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="10 6 16 12 10 18"/><line x1="20" y1="5" x2="20" y2="19"/></svg>':'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="14 6 8 12 14 18"/><line x1="4" y1="5" x2="4" y2="19"/></svg>'}}function bg(e){if(e){e.style.left="",e.style.right="";var t=e.offsetParent||e.parentElement;if(t){var n=8,i=t.getBoundingClientRect(),a=e.getBoundingClientRect(),u=window.innerWidth;a.left<n?(e.style.right="auto",e.style.left=n-i.left+"px"):a.right>u-n&&(e.style.left="auto",e.style.right=i.right-(u-n)+"px")}}}function Eg(e){if(!(!e||typeof e!="object")){r.config=e;var t=ct(e.defaultProvider);r.sessionTool=t,r.preferredCommand=t,r.sessionCreateKind=e.defaultSessionKind==="pty"?"pty":"structured",r.modeValue=dt(t,e.defaultMode||"default")}}var la=Promise.resolve();function da(e){return!e||typeof e!="object"?Promise.resolve():(la=la.catch(function(){}).then(function(){return fetch("/api/settings/config",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(e)})}).then(function(t){return t.json().then(function(n){if(!t.ok||n.error)throw new Error(n.error||"\u4FDD\u5B58\u65B0\u5EFA\u4F1A\u8BDD\u504F\u597D\u5931\u8D25");return n.config&&(r.config=n.config),n})}).catch(function(t){console.warn("[wand] Failed to persist new-session defaults",t)}),la)}function zu(){vr(),r.modalOpen=!0,r.sessionsDrawerOpen=!1,we("wand-sidebar-open",!1),ti();var e=document.getElementById("session-modal");e&&(e._wandCloseTimer&&(clearTimeout(e._wandCloseTimer),e._wandCloseTimer=null),e.classList.remove("closing"),e.classList.remove("hidden"),r.lastFocusedElement=document.activeElement,r.sessionTool=ct(r.config&&r.config.defaultProvider),r.preferredCommand=r.sessionTool,r.sessionCreateKind=r.config&&r.config.defaultSessionKind==="pty"?"pty":"structured",r.sessionCreateWorktree=!1,r.modeValue=dt(r.sessionTool,r.config&&r.config.defaultMode?r.config.defaultMode:"default"),fr(),la.then(function(){return fetch("/api/config",{credentials:"same-origin"})}).then(function(t){return t.ok?t.json():null}).then(function(t){!t||!r.modalOpen||(Eg(t),fr())}).catch(function(){}),Kg(),setTimeout(function(){var t=document.getElementById("mode-cards");t&&t.focus()},20),ca(e))}function An(){r.modalOpen=!1;var e=document.getElementById("session-modal");e&&(r.focusTrapHandler&&(document.removeEventListener("keydown",r.focusTrapHandler),r.focusTrapHandler=null),r.lastFocusedElement&&typeof r.lastFocusedElement.focus=="function"&&r.lastFocusedElement.focus(),Vu(e)),gr()}function Vu(e){if(e&&!e.classList.contains("hidden")){var t=!1;try{t=window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch{}if(t||document.hidden){e.classList.remove("closing"),e.classList.add("hidden");return}e._wandCloseTimer&&(clearTimeout(e._wandCloseTimer),e._wandCloseTimer=null),e.classList.add("closing"),e._wandCloseTimer=setTimeout(function(){e.classList.remove("closing"),e.classList.add("hidden"),e._wandCloseTimer=null},170)}}function ca(e){r.focusTrapHandler&&document.removeEventListener("keydown",r.focusTrapHandler);var t='button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])';r.focusTrapHandler=function(n){if(n.key==="Tab"){var i=e.querySelectorAll(t),a=i[0],u=i[i.length-1];!a||!u||(n.shiftKey?document.activeElement===a&&(n.preventDefault(),u.focus()):document.activeElement===u&&(n.preventDefault(),a.focus()))}},document.addEventListener("keydown",r.focusTrapHandler)}function Fg(){return r.activeWorktreeMergeSessionId&&r.sessions.find(function(e){return e.id===r.activeWorktreeMergeSessionId})||null}function ii(){var e=document.getElementById("worktree-merge-content"),t=document.getElementById("worktree-merge-confirm-button"),n=document.getElementById("worktree-merge-error"),i=Fg(),a=r.worktreeMergeCheckResult;if(!(!e||!t)){if(!i||!i.worktree){e.innerHTML='<p class="field-hint">\u672A\u627E\u5230\u53EF\u5408\u5E76\u7684 worktree \u4F1A\u8BDD\u3002</p>',t.disabled=!0;return}n&&(r.worktreeMergeError?Oe(n,r.worktreeMergeError):Ti(n));var u=['<div class="worktree-merge-row"><span>\u6765\u6E90\u5206\u652F</span><strong>'+p(i.worktree.branch||"-")+"</strong></div>",'<div class="worktree-merge-row"><span>\u5DE5\u4F5C\u76EE\u5F55</span><strong>'+p(i.worktree.path||"-")+"</strong></div>"];a?(u.push('<div class="worktree-merge-row"><span>\u76EE\u6807\u5206\u652F</span><strong>'+p(a.targetBranch||"-")+"</strong></div>"),u.push('<div class="worktree-merge-row"><span>\u5F85\u5408\u5E76\u63D0\u4EA4</span><strong>'+p(String(a.aheadCount||0))+"</strong></div>"),u.push('<div class="worktree-merge-row"><span>\u672A\u63D0\u4EA4\u6539\u52A8</span><strong>'+p(a.hasUncommittedChanges?"\u6709":"\u65E0")+"</strong></div>"),u.push('<div class="worktree-merge-row"><span>\u51B2\u7A81\u98CE\u9669</span><strong>'+p(a.hasConflicts?"\u6709":"\u65E0")+"</strong></div>"),a.reason&&u.push('<p class="field-hint">'+p(a.reason)+"</p>")):r.worktreeMergeLoading&&u.push('<p class="field-hint">\u6B63\u5728\u68C0\u67E5 worktree \u5408\u5E76\u72B6\u6001\u2026</p>'),e.innerHTML=u.join(""),t.disabled=r.worktreeMergeLoading||r.worktreeMergeSubmitting||!a||a.ok!==!0,t.textContent=r.worktreeMergeSubmitting?"\u5408\u5E76\u4E2D...":"\u786E\u8BA4\u5408\u5E76\u5E76\u6E05\u7406"}}function cd(e){r.activeWorktreeMergeSessionId=e,r.worktreeMergeCheckResult=null,r.worktreeMergeLoading=!0,r.worktreeMergeSubmitting=!1,r.worktreeMergeError="",An(),vr();var t=document.getElementById("worktree-merge-modal");t&&(t.classList.remove("hidden"),r.lastFocusedElement=document.activeElement,ca(t)),ii(),fetch("/api/sessions/"+encodeURIComponent(e)+"/worktree/merge/check",{method:"POST",credentials:"same-origin"}).then(function(n){return n.json()}).then(function(n){if(n&&n.error)throw new Error(n.error);n&&n.session&&ee(n.session),r.worktreeMergeCheckResult=n.result||null,r.worktreeMergeError=""}).catch(function(n){r.worktreeMergeError=n&&n.message||"\u65E0\u6CD5\u68C0\u67E5 worktree \u5408\u5E76\u72B6\u6001\u3002"}).finally(function(){r.worktreeMergeLoading=!1,ii()})}function pr(){var e=document.getElementById("worktree-merge-modal");r.activeWorktreeMergeSessionId=null,r.worktreeMergeCheckResult=null,r.worktreeMergeLoading=!1,r.worktreeMergeSubmitting=!1,r.worktreeMergeError="",e&&e.classList.add("hidden"),r.focusTrapHandler&&(document.removeEventListener("keydown",r.focusTrapHandler),r.focusTrapHandler=null),r.lastFocusedElement&&typeof r.lastFocusedElement.focus=="function"&&r.lastFocusedElement.focus()}function Cg(){!r.activeWorktreeMergeSessionId||r.worktreeMergeSubmitting||(r.worktreeMergeSubmitting=!0,r.worktreeMergeError="",ii(),fetch("/api/sessions/"+encodeURIComponent(r.activeWorktreeMergeSessionId)+"/worktree/merge",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}).then(function(e){return e.json()}).then(function(e){if(e&&e.error)throw new Error(e.error);return e&&e.session&&ee(e.session),x("\u5DF2\u5408\u5E76\u5230 "+p(e.result&&e.result.targetBranch||"\u4E3B\u5206\u652F")+(e.result&&e.result.cleanupDone===!1?"\uFF0C\u4F46\u5DE5\u4F5C\u6811\u5F85\u6E05\u7406\u3002":"\u3002"),"info"),pr(),_t()}).catch(function(e){r.worktreeMergeError=e&&e.message||"\u65E0\u6CD5\u5408\u5E76 worktree\u3002",ii()}).finally(function(){r.worktreeMergeSubmitting=!1,ii()}))}function fd(e){fetch("/api/sessions/"+encodeURIComponent(e)+"/worktree/cleanup",{method:"POST",credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(t&&t.error)throw new Error(t.error);return t&&t.session&&ee(t.session),x("\u5DF2\u5B8C\u6210 worktree \u6E05\u7406\u3002","info"),_t()}).catch(function(t){x(t&&t.message||"\u65E0\u6CD5\u6E05\u7406 worktree\u3002","error")})}function wg(){An();var e=document.getElementById("settings-modal");if(e){e._wandCloseTimer&&(clearTimeout(e._wandCloseTimer),e._wandCloseTimer=null),e.classList.remove("closing"),e.classList.remove("hidden"),r.lastFocusedElement=document.activeElement;var t=document.getElementById("new-password"),n=document.getElementById("confirm-password");t&&(t.value=""),n&&(n.value=""),pd(),ca(e),Dg(),e.querySelectorAll(".model-combobox-input").forEach(function(c){c.dataset.modelDirty="false",c.dataset.modelInitialized="false"}),Uu("about"),Sg();var i=document.getElementById("cfg-notif-sound"),a=document.getElementById("cfg-notif-bubble");i&&(i.checked=r.notifSound),a&&(a.checked=r.notifBubble);var u=document.getElementById("cfg-notif-volume"),o=document.getElementById("cfg-notif-volume-val");if(u){u.value=r.notifVolume,o&&(o.textContent=r.notifVolume+"%");try{u.dispatchEvent(new Event("input",{bubbles:!0}))}catch{}}var s=document.getElementById("notif-volume-field");if(s&&(s.style.display=r.notifSound?"":"none"),Sn(),typeof WandNative<"u"&&typeof WandNative.getAppIcon=="function")try{yd(WandNative.getAppIcon()||"shorthair")}catch{}if(je&&typeof WandNative.getNotificationSound=="function")try{var l=document.getElementById("native-sound-select");l&&(l.value=WandNative.getNotificationSound())}catch{}if(je&&typeof WandNative.getNotificationVolume=="function")try{var d=WandNative.getNotificationVolume();if(r.notifVolume=d,u&&(u.value=String(d)),o&&(o.textContent=d+"%"),u)try{u.dispatchEvent(new Event("input",{bubbles:!0}))}catch{}try{localStorage.setItem("wand-notif-volume",String(d))}catch{}}catch{}if(je&&typeof WandNative.isHapticEnabled=="function")try{var f=document.getElementById("cfg-haptic-enabled");f&&(f.checked=WandNative.isHapticEnabled())}catch{}}}function vr(){var e=document.getElementById("settings-modal");e&&(e.querySelectorAll(".model-combobox.is-open").forEach(function(t){Dn(t)}),r.focusTrapHandler&&(document.removeEventListener("keydown",r.focusTrapHandler),r.focusTrapHandler=null),r.lastFocusedElement&&typeof r.lastFocusedElement.focus=="function"&&r.lastFocusedElement.focus(),Vu(e))}function pd(){var e=document.getElementById("settings-error"),t=document.getElementById("settings-success");e&&e.classList.add("hidden"),t&&t.classList.add("hidden")}function Bg(){var e=document.getElementById("new-password").value,t=document.getElementById("confirm-password").value,n=document.getElementById("settings-error"),i=document.getElementById("settings-success");if(pd(),!e||e.length<6){n.textContent="\u5BC6\u7801\u957F\u5EA6\u81F3\u5C11\u4E3A 6 \u4E2A\u5B57\u7B26\u3002",n.classList.remove("hidden");return}if(e!==t){n.textContent="\u4E24\u6B21\u8F93\u5165\u7684\u5BC6\u7801\u4E0D\u4E00\u81F4\u3002",n.classList.remove("hidden");return}fetch("/api/set-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:e}),credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(a.error){n.textContent=a.error,n.classList.remove("hidden");return}i.textContent="\u5BC6\u7801\u4FEE\u6539\u6210\u529F\uFF01",i.classList.remove("hidden"),document.getElementById("new-password").value="",document.getElementById("confirm-password").value=""}).catch(function(){n.textContent="Failed to save password.",n.classList.remove("hidden")})}function Uu(e){document.querySelectorAll(".model-combobox.is-open").forEach(function(s){Dn(s)});for(var t=document.querySelectorAll(".settings-tab"),n=document.querySelectorAll(".settings-panel"),i=0;i<t.length;i++){var a=t[i].getAttribute("data-tab")===e;a?t[i].classList.add("active"):t[i].classList.remove("active"),t[i].setAttribute("aria-selected",a?"true":"false"),t[i].setAttribute("tabindex",a?"0":"-1")}for(var u=0;u<n.length;u++){var o=n[u].id==="settings-tab-"+e;o?(n[u].classList.add("active"),n[u].removeAttribute("hidden")):(n[u].classList.remove("active"),n[u].setAttribute("hidden","hidden"))}}function vd(e){if(e&&!(e.key!=="ArrowUp"&&e.key!=="ArrowDown"&&e.key!=="ArrowLeft"&&e.key!=="ArrowRight"&&e.key!=="Home"&&e.key!=="End")){var t=Array.prototype.slice.call(document.querySelectorAll(".settings-tab"));if(t.length){var n=e.currentTarget&&e.currentTarget.closest?e.currentTarget.closest(".settings-tabs"):null,i=n&&n.getAttribute("aria-orientation")==="horizontal";if(!(i&&(e.key==="ArrowUp"||e.key==="ArrowDown"))&&!(!i&&(e.key==="ArrowLeft"||e.key==="ArrowRight"))){var a=t.indexOf(e.currentTarget);if(a!==-1){e.preventDefault();var u=a;(e.key==="ArrowUp"||e.key==="ArrowLeft")&&(u=a>0?a-1:t.length-1),(e.key==="ArrowDown"||e.key==="ArrowRight")&&(u=a<t.length-1?a+1:0),e.key==="Home"&&(u=0),e.key==="End"&&(u=t.length-1);var o=t[u];if(o){var s=o.getAttribute("data-tab");s&&Uu(s),typeof o.focus=="function"&&o.focus()}}}}}}function Dg(){var e=document.querySelector(".settings-tabs");if(e){var t=!1;try{t=!!(window.matchMedia&&window.matchMedia("(max-width: 760px)").matches)}catch{}e.setAttribute("aria-orientation",t?"horizontal":"vertical")}for(var n=document.querySelectorAll(".settings-tab"),i=0;i<n.length;i++)n[i].removeEventListener("keydown",vd),n[i].addEventListener("keydown",vd)}function kg(e){if(e){var t=e.config||{},n={about:e.version?"\u5F53\u524D v"+e.version:"\u7248\u672C\u4E0E\u66F4\u65B0\u4FE1\u606F",general:[t.defaultMode||"default",t.language||"\u81EA\u52A8\u8BED\u8A00"].filter(Boolean).join(" \xB7 "),notifications:r.notifSound?"\u63D0\u793A\u97F3 "+r.notifVolume+"%":"\u63D0\u793A\u97F3\u5DF2\u5173\u95ED",security:e.hasCert?"\u5DF2\u5B89\u88C5 SSL \u8BC1\u4E66":"\u5BC6\u7801\u4E0E\u8BC1\u4E66\u7BA1\u7406",presets:t.commandPresets&&t.commandPresets.length?t.commandPresets.length+" \u6761\u9884\u8BBE":"\u6682\u65E0\u9884\u8BBE",display:"\u63A7\u5236\u5361\u7247\u9ED8\u8BA4\u5C55\u5F00"};for(var i in n)if(Object.prototype.hasOwnProperty.call(n,i)){var a=document.querySelector('.settings-tab[data-tab="'+i+'"] .settings-tab-meta');if(a){var u=n[i]||"";a.textContent=u,a.setAttribute("title",u)}}}}function Ag(e){var t=document.getElementById("android-connect-qr"),n=document.getElementById("android-connect-qr-empty"),i=window.QRCodeLib;if(t){if(!i||typeof i.toCanvas!="function"){n&&(n.textContent="\u4E8C\u7EF4\u7801\u5E93\u672A\u52A0\u8F7D");return}try{i.toCanvas(t,e,{width:220,margin:1,errorCorrectionLevel:"M",color:{dark:"#1f1b17",light:"#ffffff00"}},function(a){if(a){n&&(n.textContent="\u4E8C\u7EF4\u7801\u751F\u6210\u5931\u8D25",n.style.display=""),t.style.visibility="hidden";return}n&&(n.style.display="none"),t.style.visibility="visible"})}catch{n&&(n.textContent="\u4E8C\u7EF4\u7801\u751F\u6210\u5931\u8D25",n.style.display=""),t.style.visibility="hidden"}}}function xg(e){var t=window.QRCodeLib;if(!t||typeof t.toCanvas!="function")return;var n=document.getElementById("connect-qr-modal");n&&n.remove();var i=document.createElement("div");i.id="connect-qr-modal",i.className="connect-qr-modal-overlay",i.innerHTML='<div class="connect-qr-modal-card"><canvas id="connect-qr-modal-canvas"></canvas><p class="connect-qr-modal-hint">\u7528 Wand App \u626B\u4E00\u626B\uFF0C\u8FDE\u63A5\u5F53\u524D\u670D\u52A1\u5668</p><button type="button" class="btn btn-secondary btn-sm connect-qr-modal-close">\u5173\u95ED</button></div>',document.body.appendChild(i);var a=i.querySelector("#connect-qr-modal-canvas"),u=Math.min(window.innerWidth,window.innerHeight)*.7;u<240&&(u=240),u>480&&(u=480);try{t.toCanvas(a,e,{width:u,margin:2,errorCorrectionLevel:"M",color:{dark:"#1f1b17",light:"#ffffff"}})}catch{}function o(){i.remove()}i.addEventListener("click",function(l){l.target===i&&o()});var s=i.querySelector(".connect-qr-modal-close");s&&s.addEventListener("click",o)}function ai(e,t,n){if(!e)return;function i(){if(or("light"),n){n();return}if(t){var a=t.textContent;t.textContent="\u5DF2\u590D\u5236",setTimeout(function(){t.textContent=a},1500)}}if(je&&typeof WandNative.copyToClipboard=="function")try{if(WandNative.copyToClipboard(e)==="ok"){i();return}}catch{}navigator.clipboard.writeText(e).then(i).catch(function(){var a=document.createElement("textarea");a.value=e,a.style.position="fixed",a.style.opacity="0",document.body.appendChild(a),a.select(),document.execCommand("copy"),document.body.removeChild(a),i()})}function xn(e){if(typeof e!="number"||!isFinite(e)||e<0)return"-";if(e<1024)return e+" B";for(var t=["KB","MB","GB","TB"],n=e/1024,i=0;n>=1024&&i<t.length-1;)n=n/1024,i+=1;var a=n>=10?n.toFixed(0):n.toFixed(1);return a+" "+t[i]}function Sg(){var e=!r.config||r.config.canManageSettings!==!1,t=e?"/api/settings":"/api/settings/about";fetch(t,{credentials:"same-origin"}).then(function(n){if(n.ok)return n.json();if(n.status===403&&t==="/api/settings")return fetch("/api/settings/about",{credentials:"same-origin"}).then(function(i){if(!i.ok)throw new Error("\u65E0\u6CD5\u52A0\u8F7D\u5173\u4E8E\u4FE1\u606F (HTTP "+i.status+")");return i.json()});throw new Error("\u65E0\u6CD5\u52A0\u8F7D\u8BBE\u7F6E (HTTP "+n.status+")")}).then(function(n){var i=n.settingsAccess!=="read-only",a=document.getElementById("settings-about-access-note");a&&a.classList.toggle("hidden",i);var u=document.getElementById("provider-cli-update-section");u&&u.classList.toggle("hidden",!i);var o=document.getElementById("android-connect-section");o&&o.classList.toggle("hidden",!i),["check-update-button","do-update-button","do-restart-button"].forEach(function(K){var ve=document.getElementById(K),me=ve&&ve.closest(".settings-update-actions");me&&me.classList.toggle("hidden",!i)}),["beta-channel-toggle","auto-update-web-toggle"].forEach(function(K){var ve=document.getElementById(K),me=ve&&ve.closest(".settings-toggle-row");me&&me.classList.toggle("hidden",!i)}),kg(n);var s=document.getElementById("settings-pkg-name"),l=document.getElementById("settings-version"),d=document.getElementById("settings-node-req"),f=document.getElementById("settings-repo-url");s&&(s.textContent=n.packageName||"-"),l&&(l.textContent=n.version||"-"),d&&(d.textContent=n.nodeVersion||"-"),f&&n.repoUrl&&(f.innerHTML='<a href="'+p(n.repoUrl)+'" target="_blank" rel="noopener">'+p(n.repoUrl)+"</a>");var c=document.getElementById("settings-latest-version"),v=document.getElementById("do-update-button");n.latestVersion&&c&&(c.textContent=n.latestVersion,n.updateAvailable&&v&&v.classList.remove("hidden"));var h=document.getElementById("beta-channel-toggle");h&&(h.checked=n.updateChannel==="beta");var m=n.autoUpdate||{},g=document.getElementById("auto-update-web-toggle");g&&(g.checked=!!m.web);var y=document.getElementById("auto-update-apk-toggle");y&&(y.checked=!!zn&&!!m.apk);var B=document.getElementById("auto-update-dmg-toggle");B&&(B.checked=!!bn&&!!m.dmg);var E=document.getElementById("auto-update-cli-toggle");E&&(E.checked=!!m.cli),i&&hd(!1);function C(K,ve){As(K,{type:ve==="error"?"danger":"info"})}function D(K,ve,me){var st=me?me.textContent:"";me&&(me.disabled=!0,me.textContent="\u4E0B\u8F7D\u4E2D\u2026");function mt(){me&&(me.disabled=!1,me.textContent=st)}fetch(K,{method:"HEAD",credentials:"same-origin"}).then(function(_e){if(!_e.ok){C(_e.status===404?"\u4E0B\u8F7D\u672A\u542F\u7528\u6216\u6587\u4EF6\u5DF2\u79FB\u9664":"\u4E0B\u8F7D\u5931\u8D25 (HTTP "+_e.status+")","error"),mt();return}var Je=document.createElement("a");Je.href=K,Je.download=ve||"",document.body.appendChild(Je),Je.click(),document.body.removeChild(Je),C("\u5DF2\u5F00\u59CB\u4E0B\u8F7D\uFF0C\u8BF7\u5728\u901A\u77E5\u680F/\u4E0B\u8F7D\u7BA1\u7406\u4E2D\u67E5\u770B","info"),mt()}).catch(function(_e){C("\u4E0B\u8F7D\u5931\u8D25: "+(_e&&_e.message?_e.message:_e),"error"),mt()})}function F(K,ve){function me(Mn){var Yn=String(Mn||"").replace(/^v/,""),pn=Yn.indexOf("-"),Qn=pn>=0?Yn.slice(0,pn):Yn,ce=pn>=0?Yn.slice(pn+1):"";return{parts:Qn.split(".").map(function(si){return parseInt(si,10)||0}),pre:ce,isDebug:ce.indexOf("debug")===0}}for(var st=me(K),mt=me(ve),_e=0;_e<3;_e++){var Je=(st.parts[_e]||0)-(mt.parts[_e]||0);if(Je!==0)return Je>0?1:-1}if(st.isDebug!==mt.isDebug)return st.isDebug?1:-1;if(st.isDebug&&mt.isDebug)for(var Tn=st.pre.split("."),Ln=mt.pre.split("."),gt=0;gt<Math.max(Tn.length,Ln.length);gt++){if(Tn[gt]===void 0)return-1;if(Ln[gt]===void 0)return 1;var yr=parseInt(Tn[gt],10),ke=parseInt(Ln[gt],10);if(!isNaN(yr)&&!isNaN(ke)){if(yr!==ke)return yr>ke?1:-1}else if(Tn[gt]!==Ln[gt])return Tn[gt]>Ln[gt]?1:-1}return 0}function L(K,ve,me,st,mt,_e){K.classList.remove("hidden"),K.disabled=!1,ve>0?K.textContent="\u5347\u7EA7":ve===0?(K.textContent="\u5DF2\u662F\u6700\u65B0",K.disabled=!0):_e?K.textContent="\u91CD\u65B0\u5B89\u88C5":(K.textContent="\u7248\u672C\u8F83\u65E7",K.disabled=!0),K.onclick=K.disabled?null:function(){try{WandNative.downloadUpdate(me,st,mt)}catch(Je){C("\u8C03\u7528\u4E0B\u8F7D\u5931\u8D25: "+(Je&&Je.message?Je.message:Je),"error")}}}var S=document.getElementById("android-apk-section"),N=document.getElementById("android-apk-current-row"),J=document.getElementById("settings-android-apk-current"),W=document.getElementById("android-apk-github-row"),k=document.getElementById("settings-android-apk-github"),I=document.getElementById("download-github-apk-btn"),T=document.getElementById("android-apk-local-row"),Y=document.getElementById("settings-android-apk-local"),j=document.getElementById("download-local-apk-btn"),G=document.getElementById("android-apk-message"),M=n.androidApk||{},te=!!zn,ne=M.enabled!==!1,O=te||ne&&(!!M.github||!!M.local);if(S&&(O?S.classList.remove("hidden"):S.classList.add("hidden")),te){if(N&&J&&(J.textContent="v"+zn,N.classList.remove("hidden")),M.github&&W&&k){var P=M.github.version?"v"+M.github.version:M.github.fileName;if(typeof M.github.size=="number"&&(P+=" \xB7 "+xn(M.github.size)),k.textContent=P,W.classList.remove("hidden"),I){var _=M.github.version?F(M.github.version,zn):1;L(I,_,M.github.downloadUrl,M.github.fileName||"wand-update.apk","github",!1)}}if(M.local&&T&&Y){var Q=M.local.version?"v"+M.local.version:M.local.fileName;if(typeof M.local.size=="number"&&(Q+=" \xB7 "+xn(M.local.size)),Y.textContent=Q,T.classList.remove("hidden"),j){var $=M.local.version?F(M.local.version,zn):1;L(j,$,M.local.downloadUrl,M.local.fileName||"wand-update.apk","local",!1)}}!M.github&&!M.local&&G&&(G.textContent="\u6682\u65E0\u53EF\u7528\u66F4\u65B0",G.classList.remove("hidden"));var ie=document.getElementById("android-auto-update-row"),ge=document.getElementById("android-auto-update-hint");ie&&ie.classList.toggle("hidden",!i),ge&&ge.classList.toggle("hidden",!i)}else{if(M.github&&W&&k){var ae=M.github.version?"v"+M.github.version:M.github.fileName;typeof M.github.size=="number"&&(ae+=" \xB7 "+xn(M.github.size)),k.textContent=ae,W.classList.remove("hidden"),I&&(I.textContent="\u4E0B\u8F7D",I.classList.remove("hidden"),I.onclick=function(){window.open(M.github.downloadUrl,"_blank"),C("\u6B63\u5728\u6253\u5F00\u4E0B\u8F7D\u9875\u2026","info")})}if(M.local&&T&&Y){var ue=M.local.version?"v"+M.local.version:M.local.fileName;typeof M.local.size=="number"&&(ue+=" \xB7 "+xn(M.local.size)),Y.textContent=ue,T.classList.remove("hidden"),j&&(j.textContent="\u4E0B\u8F7D",j.classList.remove("hidden"),j.onclick=function(){D(M.local.downloadUrl,M.local.fileName||"wand-update.apk",j)})}!M.github&&!M.local&&G&&(G.textContent=ne?"\u5728\u7EBF\u7248\u672C\u6682\u65F6\u83B7\u53D6\u5931\u8D25\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5":"Android \u4E0B\u8F7D\u672A\u5728\u670D\u52A1\u7AEF\u542F\u7528",G.classList.remove("hidden"))}var ze=document.getElementById("macos-dmg-section"),Te=document.getElementById("macos-dmg-current-row"),Fe=document.getElementById("settings-macos-dmg-current"),Le=document.getElementById("macos-dmg-github-row"),at=document.getElementById("settings-macos-dmg-github"),De=document.getElementById("download-github-dmg-btn"),X=document.getElementById("macos-dmg-local-row"),he=document.getElementById("settings-macos-dmg-local"),fe=document.getElementById("download-local-dmg-btn"),oe=document.getElementById("macos-dmg-message"),q=n.macosDmg||{},ye=!!bn,pt=q.enabled!==!1,zt=ye||pt&&(!!q.github||!!q.local);if(ze&&(zt?ze.classList.remove("hidden"):ze.classList.add("hidden")),ye){if(Te&&Fe&&(Fe.textContent="v"+bn,Te.classList.remove("hidden")),q.github&&Le&&at){var Ue=q.github.version?"v"+q.github.version:q.github.fileName;if(typeof q.github.size=="number"&&(Ue+=" \xB7 "+xn(q.github.size)),at.textContent=Ue,Le.classList.remove("hidden"),De){var ut=q.github.version?F(q.github.version,bn):1;L(De,ut,q.github.downloadUrl,q.github.fileName||"wand-update.dmg","github",!0)}}if(q.local&&X&&he){var Vt=q.local.version?"v"+q.local.version:q.local.fileName;if(typeof q.local.size=="number"&&(Vt+=" \xB7 "+xn(q.local.size)),he.textContent=Vt,X.classList.remove("hidden"),fe){var xt=q.local.version?F(q.local.version,bn):1;L(fe,xt,q.local.downloadUrl,q.local.fileName||"wand-update.dmg","local",!0)}}!q.github&&!q.local&&oe&&(oe.textContent="\u6682\u65E0\u53EF\u7528\u66F4\u65B0",oe.classList.remove("hidden"));var tt=document.getElementById("macos-auto-update-row"),Me=document.getElementById("macos-auto-update-hint");tt&&tt.classList.toggle("hidden",!i),Me&&Me.classList.toggle("hidden",!i)}else{if(q.github&&Le&&at){var Pe=q.github.version?"v"+q.github.version:q.github.fileName;typeof q.github.size=="number"&&(Pe+=" \xB7 "+xn(q.github.size)),at.textContent=Pe,Le.classList.remove("hidden"),De&&(De.textContent="\u4E0B\u8F7D",De.classList.remove("hidden"),De.onclick=function(){window.open(q.github.downloadUrl,"_blank"),C("\u6B63\u5728\u6253\u5F00\u4E0B\u8F7D\u9875\u2026","info")})}if(q.local&&X&&he){var Ce=q.local.version?"v"+q.local.version:q.local.fileName;typeof q.local.size=="number"&&(Ce+=" \xB7 "+xn(q.local.size)),he.textContent=Ce,X.classList.remove("hidden"),fe&&(fe.textContent="\u4E0B\u8F7D",fe.classList.remove("hidden"),fe.onclick=function(){D(q.local.downloadUrl,q.local.fileName||"wand-update.dmg",fe)})}!q.github&&!q.local&&oe&&(oe.textContent=pt?"\u5728\u7EBF\u7248\u672C\u6682\u65F6\u83B7\u53D6\u5931\u8D25\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5":"macOS \u4E0B\u8F7D\u672A\u5728\u670D\u52A1\u7AEF\u542F\u7528",oe.classList.remove("hidden"))}var w=document.getElementById("android-connect-code"),St=document.getElementById("android-connect-qr"),qe=document.getElementById("android-connect-qr-empty"),nt=document.getElementById("android-connect-qr-wrap");if(w&&i){w.textContent="\u52A0\u8F7D\u4E2D...",qe&&(qe.textContent="\u751F\u6210\u4E2D\u2026"),St&&(St.style.visibility="hidden");var an="/api/app-connect-code";window.location&&window.location.origin&&(an+="?origin="+encodeURIComponent(window.location.origin)),fetch(an,{credentials:"same-origin"}).then(function(K){return K.json()}).then(function(K){K.code?(w.textContent=K.code,r.androidConnectCode=K.code,Ag(K.code)):(w.textContent="\u751F\u6210\u5931\u8D25",qe&&(qe.textContent="\u751F\u6210\u5931\u8D25"))}).catch(function(){w.textContent="\u83B7\u53D6\u5931\u8D25",qe&&(qe.textContent="\u83B7\u53D6\u5931\u8D25")})}nt&&!nt.dataset.bound&&(nt.dataset.bound="1",nt.addEventListener("click",function(){r.androidConnectCode&&xg(r.androidConnectCode)}));var re=n.config||{},Ut=document.getElementById("cfg-host"),Kt=document.getElementById("cfg-port"),Se=document.getElementById("cfg-https"),rt=document.getElementById("cfg-mode"),Ve=document.getElementById("cfg-cwd"),Jt=document.getElementById("cfg-shell");Ut&&(Ut.value=re.host||""),Kt&&(Kt.value=re.port||""),Se&&(Se.checked=re.https===!0),rt&&(rt.value=re.defaultMode||"default"),Ve&&(Ve.value=re.defaultCwd||""),Jt&&(Jt.value=re.shell||"");var un=document.getElementById("cfg-language");un&&(un.value=re.language||"");var on=document.getElementById("cfg-structured-runner");on&&(on.value=re.structuredRunner||"cli");var In=document.getElementById("cfg-inherit-env");In&&(In.checked=re.inheritEnv!==!1);var It=document.getElementById("cfg-commit-cli"),sn=document.getElementById("cfg-commit-model");It&&(It.value=ct(re.commitCli)),sn&&(sn.value=re.commitModel||"",sn.dataset.modelInitialized="true",sn.dataset.modelDirty="false"),aa(!1);var Ke=re.defaultModels&&typeof re.defaultModels=="object"?re.defaultModels:{claude:re.defaultModel||"",codex:re.defaultCodexModel||"",opencode:re.defaultOpenCodeModel||""};r.configDefaultModels={claude:Ke.claude||"",codex:Ke.codex||"",opencode:Ke.opencode||""},r.configDefaultModel=r.configDefaultModels.claude;var le=document.getElementById("cfg-default-model"),ln=document.getElementById("cfg-default-codex-model"),He=document.getElementById("cfg-default-opencode-model");le&&le.dataset.modelDirty!=="true"&&(le.dataset.modelInitialized="false"),ln&&ln.dataset.modelDirty!=="true"&&(ln.dataset.modelInitialized="false"),He&&He.dataset.modelDirty!=="true"&&(He.dataset.modelInitialized="false"),ua(),td().then(function(){ua()}).catch(function(){});var dn=document.getElementById("cert-status");dn&&(dn.textContent=n.hasCert?"\u5DF2\u5B89\u88C5 SSL \u8BC1\u4E66":"\u672A\u5B89\u88C5\u8BC1\u4E66\uFF08\u4F7F\u7528\u81EA\u7B7E\u540D\u6216 HTTP\uFF09",dn.style.color=n.hasCert?"var(--success)":"var(--text-secondary)");var cn=document.getElementById("presets-list");if(cn&&re.commandPresets){for(var Gt="",fn=0;fn<re.commandPresets.length;fn++){var ot=re.commandPresets[fn];Gt+='<div class="preset-item"><span class="preset-label">'+p(ot.label)+'</span><span class="preset-detail">'+p(ot.command)+(ot.mode?" ("+p(ot.mode)+")":"")+"</span></div>"}Gt||(Gt='<div class="empty-state-compact"><span class="empty-icon">\u2699</span><span>\u6CA1\u6709\u547D\u4EE4\u9884\u8BBE</span><span class="hint">\u5728 config.json \u7684 commandPresets \u4E2D\u914D\u7F6E</span></div>'),cn.innerHTML=Gt}var Tt=re.cardDefaults||{},vt=document.getElementById("cfg-card-edit"),U=document.getElementById("cfg-card-inline"),R=document.getElementById("cfg-card-terminal"),Z=document.getElementById("cfg-card-thinking"),de=document.getElementById("cfg-card-toolgroup");vt&&(vt.checked=Tt.editCards===!0),U&&(U.checked=Tt.inlineTools===!0),R&&(R.checked=Tt.terminal===!0),Z&&(Z.checked=Tt.thinking===!0),de&&(de.checked=Tt.toolGroup===!0)}).catch(function(n){var i=document.getElementById("settings-about-access-note");i&&(i.textContent=n&&n.message||"\u5173\u4E8E\u4FE1\u606F\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",i.style.color="var(--error)",i.classList.remove("hidden"))})}function Ig(){var e=document.getElementById("config-message");e&&(e.classList.add("hidden"),e.textContent="");var t=((document.getElementById("cfg-default-model")||{}).value||"").trim(),n=((document.getElementById("cfg-default-codex-model")||{}).value||"").trim(),i=((document.getElementById("cfg-default-opencode-model")||{}).value||"").trim(),a=((document.getElementById("cfg-commit-model")||{}).value||"").trim(),u={host:(document.getElementById("cfg-host")||{}).value,port:Number((document.getElementById("cfg-port")||{}).value),https:(document.getElementById("cfg-https")||{}).checked,defaultMode:(document.getElementById("cfg-mode")||{}).value,defaultCwd:(document.getElementById("cfg-cwd")||{}).value,shell:(document.getElementById("cfg-shell")||{}).value,language:(document.getElementById("cfg-language")||{}).value||"",defaultModel:t,defaultCodexModel:n,defaultOpenCodeModel:i,defaultModels:{claude:t,codex:n,opencode:i},commitCli:ct((document.getElementById("cfg-commit-cli")||{}).value),commitModel:a,structuredRunner:(document.getElementById("cfg-structured-runner")||{}).value||"cli",inheritEnv:(document.getElementById("cfg-inherit-env")||{}).checked!==!1},o=Hu(),s=u.defaultModel||"",l=u.defaultCodexModel||"",d=u.defaultOpenCodeModel||"";fetch("/api/settings/config",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(u)}).then(function(f){return f.json()}).then(function(f){if(e&&(f.error?(e.textContent=f.error,e.style.color="var(--error)"):(e.textContent=f.restartRequired?"\u914D\u7F6E\u5DF2\u4FDD\u5B58\uFF0C\u90E8\u5206\u90E8\u7F72\u5B57\u6BB5\uFF08host/port/https/shell\uFF09\u9700\u8981\u91CD\u542F\u670D\u52A1\u624D\u751F\u6548\u3002":"\u914D\u7F6E\u5DF2\u4FDD\u5B58\u3002",e.style.color="var(--success)"),e.classList.remove("hidden")),!f||!f.error){r.config&&(r.config.defaultModel=s,r.config.defaultCodexModel=l,r.config.defaultOpenCodeModel=d,r.config.defaultModels={claude:s,codex:l,opencode:d},r.config.commitCli=u.commitCli,r.config.commitModel=u.commitModel),r.configDefaultModels={claude:s,codex:l,opencode:d},r.configDefaultModel=s;var c=document.getElementById("cfg-default-model"),v=document.getElementById("cfg-default-codex-model"),h=document.getElementById("cfg-default-opencode-model");c&&(c.dataset.modelDirty="false"),v&&(v.dataset.modelDirty="false"),h&&(h.dataset.modelDirty="false");var m=document.getElementById("cfg-commit-model");m&&(m.dataset.modelDirty="false"),s!==o.claude&&na("claude",""),l!==o.codex&&na("codex",""),d!==o.opencode&&na("opencode",""),(s!==o.claude||l!==o.codex||d!==o.opencode)&&dr(Xe())}}).catch(function(){e&&(e.textContent="\u4FDD\u5B58\u5931\u8D25\u3002",e.style.color="var(--error)",e.classList.remove("hidden"))})}function Tg(){var e=document.getElementById("display-message");e&&(e.classList.add("hidden"),e.textContent="");var t={cardDefaults:{editCards:!!(document.getElementById("cfg-card-edit")||{}).checked,inlineTools:!!(document.getElementById("cfg-card-inline")||{}).checked,terminal:!!(document.getElementById("cfg-card-terminal")||{}).checked,thinking:!!(document.getElementById("cfg-card-thinking")||{}).checked,toolGroup:!!(document.getElementById("cfg-card-toolgroup")||{}).checked}};fetch("/api/settings/config",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(t)}).then(function(n){return n.json()}).then(function(n){e&&(n.error?(e.textContent=n.error,e.style.color="var(--error)"):(e.textContent="\u663E\u793A\u8BBE\u7F6E\u5DF2\u4FDD\u5B58",e.style.color="var(--success)"),e.classList.remove("hidden")),!n.error&&r.config&&(r.config.cardDefaults=t.cardDefaults)}).catch(function(){e&&(e.textContent="\u4FDD\u5B58\u5931\u8D25\u3002",e.style.color="var(--error)",e.classList.remove("hidden"))})}function Lg(){var e=document.getElementById("cert-key-file"),t=document.getElementById("cert-cert-file"),n=document.getElementById("cert-message");if(n&&(n.classList.add("hidden"),n.textContent=""),!e||!e.files||!e.files[0]||!t||!t.files||!t.files[0]){n&&(n.textContent="\u8BF7\u9009\u62E9\u79C1\u94A5\u548C\u8BC1\u4E66\u6587\u4EF6\u3002",n.style.color="var(--error)",n.classList.remove("hidden"));return}var i=new FileReader;i.onload=function(){var a=i.result,u=new FileReader;u.onload=function(){var o=u.result;fetch("/api/settings/upload-cert",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({key:a,cert:o})}).then(function(s){return s.json()}).then(function(s){if(n){if(s.error)n.textContent=s.error,n.style.color="var(--error)";else{n.textContent="\u8BC1\u4E66\u5DF2\u4E0A\u4F20\uFF0C\u91CD\u542F\u540E\u751F\u6548\u3002",n.style.color="var(--success)";var l=document.getElementById("cert-status");l&&(l.textContent="\u5DF2\u5B89\u88C5 SSL \u8BC1\u4E66",l.style.color="var(--success)")}n.classList.remove("hidden")}}).catch(function(){n&&(n.textContent="\u4E0A\u4F20\u5931\u8D25\u3002",n.style.color="var(--error)",n.classList.remove("hidden"))})},u.readAsText(t.files[0])},i.readAsText(e.files[0])}function md(){var e=document.getElementById("settings-latest-version"),t=document.getElementById("do-update-button"),n=document.getElementById("update-message");e&&(e.textContent="\u68C0\u67E5\u4E2D..."),n&&n.classList.add("hidden"),t&&t.classList.add("hidden"),fetch("/api/check-update",{credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i.error){e&&(e.textContent="\u68C0\u67E5\u5931\u8D25");return}var a=i.channel==="beta";if(e&&(e.textContent=i.latest||(a?"beta \u672A\u53D1\u5E03":"-")),!i.latest){n&&(n.textContent=a?"\u65E0\u6CD5\u8BFB\u53D6 npm beta \u7248\u672C\u3002":"\u65E0\u6CD5\u8FDE\u63A5\u5230 npm registry\u3002",n.style.color="var(--error)",n.classList.remove("hidden"));return}t&&(t.textContent=i.updateAvailable?a?"\u66F4\u65B0\u5230 Beta":"\u66F4\u65B0\u5230\u6700\u65B0\u7248":a?"\u91CD\u65B0\u5B89\u88C5 Beta":"\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248",t.classList.remove("hidden")),!i.updateAvailable&&n&&(n.textContent=a?"\u5DF2\u662F\u6700\u65B0 Beta \u7248\u672C\u3002":"\u5DF2\u662F\u6700\u65B0\u7248\u672C\u3002",n.style.color="var(--success)",n.classList.remove("hidden"))}).catch(function(){e&&(e.textContent="\u68C0\u67E5\u5931\u8D25")})}function gd(e){var t=e&&Array.isArray(e.items)?e.items:[],n=0;["claude","codex","opencode"].forEach(function(u){var o=document.getElementById("provider-cli-status-"+u);if(o){var s=t.find(function(d){return d.id===u});if(!s){o.textContent="\u68C0\u6D4B\u5931\u8D25";return}if(o.setAttribute("title",s.error||s.executable||""),!s.installed){o.textContent="\u672A\u5B89\u88C5";return}var l=s.currentVersion||"\u672A\u77E5\u7248\u672C";if(s.updateAvailable&&s.updateSupported){n++,o.textContent=l+" \u2192 "+(s.latestVersion||"\u6700\u65B0\u7248");return}if(s.updateAvailable&&!s.updateSupported){o.textContent=l+" \xB7 \u9700\u8FC1\u79FB";return}o.textContent=s.latestVersion?l+" \xB7 \u6700\u65B0":l+" \xB7 \u672A\u8BFB\u53D6\u5230\u6700\u65B0\u7248"}});var i=document.getElementById("update-provider-clis");i&&(i.classList.toggle("hidden",n===0),i.textContent=n>0?"\u5FEB\u901F\u66F4\u65B0 ("+n+")":"\u5FEB\u901F\u66F4\u65B0");var a=document.getElementById("auto-update-cli-toggle");a&&typeof e.autoUpdate=="boolean"&&(a.checked=e.autoUpdate)}function hd(e){var t=document.getElementById("check-provider-cli-updates"),n=document.getElementById("provider-cli-update-message");return t&&(t.disabled=!0,t.textContent="\u68C0\u6D4B\u4E2D\u2026"),fetch("/api/provider-cli-updates"+(e?"?refresh=1":""),{credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i.error)throw new Error(i.error);return gd(i),n&&e&&(n.textContent="CLI \u7248\u672C\u68C0\u67E5\u5B8C\u6210\u3002",n.style.color="var(--success)",n.classList.remove("hidden")),i}).catch(function(i){return n&&(n.textContent=i&&i.message||"CLI \u7248\u672C\u68C0\u67E5\u5931\u8D25\u3002",n.style.color="var(--error)",n.classList.remove("hidden")),null}).finally(function(){t&&(t.disabled=!1,t.textContent="\u68C0\u67E5\u66F4\u65B0")})}function Mg(){var e=document.getElementById("update-provider-clis"),t=document.getElementById("check-provider-cli-updates"),n=document.getElementById("provider-cli-update-message");e&&(e.disabled=!0,e.textContent="\u66F4\u65B0\u4E2D\u2026"),t&&(t.disabled=!0),n&&(n.textContent="\u6B63\u5728\u4F9D\u6B21\u66F4\u65B0 CLI\uFF0C\u8BF7\u52FF\u5173\u95ED\u670D\u52A1\u2026",n.style.color="var(--text-secondary)",n.classList.remove("hidden")),fetch("/api/provider-cli-updates",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({})}).then(function(i){return i.json()}).then(function(i){if(i.error)throw new Error(i.error);gd(i);var a=Array.isArray(i.results)?i.results:[],u=a.filter(function(o){return!o.ok});n&&(n.textContent=a.map(function(o){return o.message}).join(" ")||"\u6CA1\u6709\u9700\u8981\u66F4\u65B0\u7684 CLI\u3002",n.style.color=u.length?"var(--warning)":"var(--success)")}).catch(function(i){n&&(n.textContent=i&&i.message||"CLI \u66F4\u65B0\u5931\u8D25\u3002",n.style.color="var(--error)")}).finally(function(){e&&(e.disabled=!1),t&&(t.disabled=!1)})}function Og(){var e=document.getElementById("update-message"),t=document.getElementById("do-update-button");if(t){var n=t.textContent||"\u66F4\u65B0\u5230\u6700\u65B0\u7248",i=function(){t.disabled=!1,t.textContent=n,t.removeAttribute("aria-busy")};t.disabled=!0,t.textContent="\u66F4\u65B0\u4E2D...",t.setAttribute("aria-busy","true"),e&&(e.textContent="\u6B63\u5728\u66F4\u65B0\uFF0C\u8BF7\u7A0D\u5019...",e.style.color="var(--text-secondary)",e.classList.remove("hidden")),fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(a.error){e&&(e.textContent=a.error,e.style.color="var(--error)",e.classList.remove("hidden")),i();return}if(e&&(e.textContent=(a.message||"\u66F4\u65B0\u5B8C\u6210")+"\uFF0C\u6B63\u5728\u91CD\u542F\u670D\u52A1\u2026",e.style.color="var(--success)",e.classList.remove("hidden")),t.removeAttribute("aria-busy"),t.classList.add("hidden"),a.detachedUpdate)En(a.previousInstanceId||null,a.version||null);else if(a.restartRequired!==!1)Os(null,e);else{var u=document.getElementById("do-restart-button");u&&u.classList.remove("hidden")}}).catch(function(){e&&(e.textContent="\u66F4\u65B0\u5931\u8D25\u3002",e.style.color="var(--error)",e.classList.remove("hidden")),i()})}}function Pg(){var e=document.getElementById("do-restart-button"),t=document.getElementById("update-message");Os(e,t)}function qg(){fetch("/api/auto-update",{credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){if(e.apk)return fetch("/api/android-apk-update?currentVersion="+encodeURIComponent(zn),{credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(!(!t.updateAvailable||!t.downloadUrl))try{WandNative.downloadUpdate(t.downloadUrl,t.fileName||"wand-update.apk",t.source||"local")}catch{}})}).catch(function(){})}function Hg(){bn&&fetch("/api/auto-update",{credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){if(e.dmg)return fetch("/api/macos-dmg-update?currentVersion="+encodeURIComponent(bn),{credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(!(!t.updateAvailable||!t.downloadUrl))try{WandNative.downloadUpdate(t.downloadUrl,t.fileName||"wand-update.dmg",t.source||"local")}catch{}})}).catch(function(){})}function fa(e,t){var n={};n[e]=t,fetch("/api/auto-update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(n)}).then(function(i){return i.json()}).then(function(i){var a=document.getElementById("auto-update-web-toggle"),u=document.getElementById("auto-update-apk-toggle"),o=document.getElementById("auto-update-dmg-toggle"),s=document.getElementById("auto-update-cli-toggle");a&&(a.checked=!!i.web),u&&(u.checked=!!i.apk),o&&(o.checked=!!i.dmg),s&&(s.checked=!!i.cli)}).catch(function(){var i=document.getElementById("auto-update-"+e+"-toggle");i&&(i.checked=!t)})}function _g(e){fetch("/api/update-channel",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({channel:e})}).then(function(t){return t.json()}).then(function(t){var n=document.getElementById("beta-channel-toggle");n&&(n.checked=t.channel==="beta"),md()}).catch(function(){var t=document.getElementById("beta-channel-toggle");t&&(t.checked=e!=="beta")})}function yd(e){for(var t=document.querySelectorAll(".settings-app-icon-option"),n=0;n<t.length;n++){var i=t[n].getAttribute("data-icon")===e;t[n].classList.toggle("selected",i),t[n].setAttribute("aria-pressed",i?"true":"false")}}function Sn(){var e=document.getElementById("notification-permission-status"),t=document.getElementById("notification-request-btn"),n=document.getElementById("notification-reset-btn"),i=document.getElementById("notification-test-message");if(e){var a=Li();if(a===null){if(typeof Notification>"u"){e.textContent="\u4E0D\u652F\u6301",e.style.color="var(--fg-muted)",t&&t.classList.add("hidden"),n&&n.classList.add("hidden");return}a=Notification.permission}a==="granted"?(e.textContent="\u5DF2\u6388\u6743 \u2713",e.style.color="var(--success)",t&&t.classList.add("hidden"),n&&n.classList.add("hidden")):a==="denied"?(e.textContent="\u5DF2\u62D2\u7EDD",e.style.color="var(--danger)",t&&t.classList.add("hidden"),n&&n.classList.remove("hidden")):(e.textContent="\u672A\u6388\u6743",e.style.color="var(--warning)",t&&t.classList.remove("hidden"),n&&n.classList.remove("hidden"))}}function Ng(){var e=document.getElementById("notification-test-message");if(je){window._onNativePermissionResult=function(t){Sn(),e&&(t==="granted"?(e.textContent="\u2713 \u5DF2\u6388\u6743",e.style.color="var(--success)"):(e.textContent="\u2717 \u672A\u6388\u6743\uFF0C\u8BF7\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u4E2D\u5F00\u542F Wand \u7684\u901A\u77E5\u6743\u9650",e.style.color="var(--danger)"),e.classList.remove("hidden")),delete window._onNativePermissionResult};try{WandNative.requestPermission()}catch{}return}typeof Notification>"u"||Notification.requestPermission().then(function(t){if(Sn(),t==="granted")e&&(e.textContent="\u2713 \u5DF2\u6388\u6743",e.style.color="var(--success)",e.classList.remove("hidden"));else if(t==="denied"&&e){var n=location.origin;e.innerHTML='\u6D4F\u89C8\u5668\u5DF2\u62E6\u622A\u6388\u6743\u5F39\u7A97\uFF0C\u8BF7\u624B\u52A8\u91CD\u7F6E\uFF1A<br><span style="display:inline-flex;align-items:center;gap:4px;margin:4px 0">\u2460 \u70B9\u51FB\u5730\u5740\u680F\u5DE6\u4FA7\u7684 <span style="display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border-radius:50%;border:1px solid var(--border);font-size:11px;vertical-align:middle">i</span> \u6216\u9501\u56FE\u6807</span><br>\u2461 \u627E\u5230\u300C\u901A\u77E5\u300D\u2192 \u6539\u4E3A\u300C\u5141\u8BB8\u300D<br>\u2462 \u5237\u65B0\u9875\u9762\u5373\u53EF',e.style.color="var(--fg-muted)",e.classList.remove("hidden")}})}function bd(){var e=document.getElementById("notification-test-delay-btn");e&&(e.disabled=!1,e.textContent="10 \u79D2\u540E\u53D1\u9001")}function jg(){var e=document.getElementById("notification-test-message");r.delayedNotificationTimer&&(clearTimeout(r.delayedNotificationTimer),r.delayedNotificationTimer=null);var t=document.getElementById("notification-test-delay-btn");t&&(t.disabled=!0,t.textContent="\u5DF2\u5B89\u6392\uFF0810s\uFF09"),e&&(e.innerHTML="\u5DF2\u5B89\u6392 10 \u79D2\u540E\u53D1\u9001\u6D4B\u8BD5\u901A\u77E5\uFF0C\u8BF7\u5207\u5230\u540E\u53F0\u7B49\u5F85\u3002",e.style.color="var(--text-secondary)",e.classList.remove("hidden")),r.delayedNotificationTimer=setTimeout(function(){r.delayedNotificationTimer=null,bd(),Ed()},1e4)}function Ed(){var e=document.getElementById("notification-test-message"),t=[];r.delayedNotificationTimer&&(clearTimeout(r.delayedNotificationTimer),r.delayedNotificationTimer=null,bd());var n=Bp();t.push(n?"\u2713 \u63D0\u793A\u97F3":"\u2717 \u63D0\u793A\u97F3\uFF08\u65E0\u6CD5\u64AD\u653E\uFF09");var i=r.notifBubble;if($a({title:"\u6D4B\u8BD5\u901A\u77E5",body:"\u8FD9\u662F\u4E00\u6761\u6D4B\u8BD5\u901A\u77E5\u3002",type:"info",icon:"\u266A",duration:5e3,playSound:!1}),t.push(i?"\u2713 \u5E94\u7528\u5185\u6C14\u6CE1":"\u2013 \u5E94\u7528\u5185\u6C14\u6CE1\uFF08\u5DF2\u5173\u95ED\uFF09"),je){var a=Li();if(a==="granted")try{WandNative.sendNotification("Wand \u6D4B\u8BD5\u901A\u77E5","\u7CFB\u7EDF\u901A\u77E5\u5DF2\u6B63\u5E38\u5DE5\u4F5C\u3002","wand-test"),t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5")}catch{t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u53D1\u9001\u5931\u8D25\uFF09")}else if(a==="denied")t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u62D2\u7EDD\uFF0C\u8BF7\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u4E2D\u5F00\u542F\uFF09");else{window._onNativePermissionResult=function(s){if(Sn(),s==="granted")try{WandNative.sendNotification("Wand \u6D4B\u8BD5\u901A\u77E5","\u7CFB\u7EDF\u901A\u77E5\u5DF2\u6B63\u5E38\u5DE5\u4F5C\u3002","wand-test"),t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u6388\u6743\uFF09")}catch{t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u53D1\u9001\u5931\u8D25\uFF09")}else t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u672A\u6388\u6743\uFF09");mr(e,t),delete window._onNativePermissionResult};try{WandNative.requestPermission()}catch{}return}mr(e,t);return}if(typeof Notification>"u"){t.push("\u2013 \u7CFB\u7EDF\u901A\u77E5\uFF08\u4E0D\u652F\u6301\uFF09"),mr(e,t);return}var u=Notification.permission;if(u==="granted"){try{var o=new Notification("Wand \u6D4B\u8BD5\u901A\u77E5",{body:"\u7CFB\u7EDF\u901A\u77E5\u5DF2\u6B63\u5E38\u5DE5\u4F5C\u3002",icon:"/favicon.ico",tag:"wand-test"});setTimeout(function(){o.close()},5e3),t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5")}catch{t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u53D1\u9001\u5931\u8D25\uFF0C\u53EF\u80FD\u9700\u8981 HTTPS\uFF09")}mr(e,t)}else u==="denied"?(t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u62D2\u7EDD\uFF09"),mr(e,t)):Notification.requestPermission().then(function(s){Sn(),s==="granted"?t.push("\u2713 \u7CFB\u7EDF\u901A\u77E5\uFF08\u5DF2\u6388\u6743\uFF09"):t.push("\u2717 \u7CFB\u7EDF\u901A\u77E5\uFF08\u672A\u6388\u6743\uFF09"),mr(e,t)})}function mr(e,t){if(e){e.innerHTML=t.map(function(i){return p(i)}).join("<br>");var n=t.every(function(i){return i.indexOf("\u2713")===0||i.indexOf("\u2013")===0});e.style.color=n?"var(--success)":"var(--warning)",e.classList.remove("hidden")}}function ft(e){if(!e||typeof e!="object"||!r.terminal)return e;try{typeof r.terminal.remeasure=="function"&&r.terminal.remeasure()}catch{}var t=r.terminal.cols,n=r.terminal.rows;return typeof t=="number"&&typeof n=="number"&&Number.isFinite(t)&&Number.isFinite(n)&&t>0&&n>0&&(e.cols=t,e.rows=n),e}function Fd(){return r.terminal&&r.terminal.cols?Promise.resolve():new Promise(function(e){var t=!1,n=function(){t||(t=!0,e())},i=setTimeout(n,2e3);try{ur()}catch{}requestAnimationFrame(function(){requestAnimationFrame(function(){r.terminal&&r.terminal.cols&&(clearTimeout(i),n())})})})}function Ku(){var e=$e(),t=Qe(),n=dt(e,r.config&&r.config.defaultMode?r.config.defaultMode:"default");r.preferredCommand=e,r.chatMode=dt(e,r.chatMode),Fd().then(function(){return fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(ft({command:e,provider:e,cwd:t,mode:n,sessionSource:"interactive"}))})}).then(function(i){return i.json()}).then(function(i){if(i.error){x(i.error,"error");return}return r.selectedId=i.id,Ee(),r.drafts[i.id]="",Dt(),_t()}).then(function(){Ht(!0)}).catch(function(){x("\u65E0\u6CD5\u542F\u52A8\u4F1A\u8BDD\u3002","error")})}var ui=!1;function Rg(){if(!ui){var e=document.getElementById("cwd"),t=document.getElementById("modal-error"),n=$e(),i=r.sessionCreateKind||"structured",a=r.sessionCreateWorktree===!0;Ti(t);var u=Qe(),o=(e?e.value.trim():"")||u,s=dt(n,r.modeValue);if(da({defaultProvider:n,defaultSessionKind:i,defaultMode:s}),i==="structured"){Wg(o,s,a,t);return}zg(n,o,s,a,t)}}function Wg(e,t,n,i){var a=ct(r.sessionTool);return ui=!0,r.modeValue=t,r.chatMode=t,r.sessionTool=a,r.preferredCommand=a,Qi(),dr(Xe()),ld(void 0,e,t,n).then(function(u){return Xt(e),An(),jt(),u}).then(function(){Ht(!0)}).catch(function(u){Oe(i,u&&u.message||"\u65E0\u6CD5\u542F\u52A8\u7ED3\u6784\u5316\u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 Claude \u5DF2\u6B63\u786E\u5B89\u88C5\u3002")}).finally(function(){ui=!1})}function zg(e,t,n,i,a){ui=!0,r.modeValue=n,r.chatMode=n,r.sessionTool=e,r.preferredCommand=e,Qi(),Fd().then(function(){return fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(ft({command:e,provider:e,cwd:t,mode:n,worktreeEnabled:i,sessionSource:"interactive"}))})}).then(function(u){return u.json()}).then(function(u){if(u.error){Oe(a,u.error);return}return r.selectedId=u.id,Ee(),Xt(t),r.drafts[u.id]="",Dt(),An(),jt(),_t()}).then(function(){r.selectedId?Nt(r.selectedId):Ht(!0)}).catch(function(){Oe(a,e==="codex"?"\u65E0\u6CD5\u542F\u52A8 Codex \u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 codex \u5DF2\u6B63\u786E\u5B89\u88C5\u5E76\u53EF\u5728\u7EC8\u7AEF\u4E2D\u6267\u884C\u3002":e==="opencode"?"\u65E0\u6CD5\u542F\u52A8 OpenCode \u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 opencode-ai \u5DF2\u6B63\u786E\u5B89\u88C5\u3002":"\u65E0\u6CD5\u542F\u52A8 Claude \u4F1A\u8BDD\uFF0C\u8BF7\u786E\u8BA4 Claude \u5DF2\u6B63\u786E\u5B89\u88C5\u3002")}).finally(function(){ui=!1})}function Vg(){var e=document.getElementById("blank-chat-cwd");e&&(e.addEventListener("click",Cd),e.addEventListener("keydown",function(t){(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),Cd())}),document.addEventListener("click",function(t){var n=document.getElementById("blank-chat-cwd-dropdown");if(!(!n||n.classList.contains("hidden"))&&!t.target.closest(".blank-chat-cwd-wrap")){n.classList.add("hidden");var i=document.getElementById("blank-chat-cwd-arrow");i&&(i.textContent="\u25BC")}}))}function Cd(){var e=document.getElementById("blank-chat-cwd-dropdown"),t=document.getElementById("blank-chat-cwd-arrow");if(e){var n=e.classList.contains("hidden");n?(Ug(e),e.classList.remove("hidden"),t&&(t.textContent="\u25B2")):(e.classList.add("hidden"),t&&(t.textContent="\u25BC"))}}function Ug(e){var t=gn();e.innerHTML='<div class="blank-chat-cwd-loading">\u52A0\u8F7D\u4E2D...</div>',Wa(function(n){var i="",a=r.workingDir||t;if(i+='<div class="blank-chat-cwd-item'+(a===t?" active":"")+'" data-path="'+p(t)+'"><span class="blank-chat-cwd-item-label">\u9ED8\u8BA4</span>'+Et(t,"blank-chat-cwd-item-path")+"</div>",n.length){var u={};u[t]=!0,n.forEach(function(o){u[o.path]||(u[o.path]=!0,i+='<div class="blank-chat-cwd-item'+(a===o.path?" active":"")+'" data-path="'+p(o.path)+'">'+Et(o.path,"blank-chat-cwd-item-path")+"</div>")})}e.innerHTML=i,Wt(e),e.querySelectorAll(".blank-chat-cwd-item").forEach(function(o){o.addEventListener("click",function(s){s.stopPropagation();var l=o.dataset.path;r.workingDir=l;try{localStorage.setItem("wand-working-dir",l)}catch{}var d=document.getElementById("blank-chat-cwd-path");eo(d,l),e.classList.add("hidden");var f=document.getElementById("blank-chat-cwd-arrow");f&&(f.textContent="\u25BC");var c=document.getElementById("folder-picker-input");c&&(c.value=l)})})})}function Kg(){var e=document.getElementById("recent-paths-bubbles");e&&Wa(function(t){if(!t.length){e.innerHTML="";return}e.innerHTML=t.map(function(n){return'<button class="recent-path-bubble" data-path="'+p(n.path)+'" title="'+p(n.path)+'">'+Et(n.path,"recent-path-bubble-path")+"</button>"}).join(""),Wt(e),e.querySelectorAll(".recent-path-bubble").forEach(function(n){n.addEventListener("click",function(){var i=document.getElementById("cwd");i&&(i.value=n.dataset.path||"",r.cwdValue=n.dataset.path||"")})})})}function wd(){r.suggestionTimer&&clearTimeout(r.suggestionTimer),r.suggestionTimer=setTimeout(Jg,120)}function Jg(){var e=document.getElementById("session-modal");if(e&&e.classList.contains("hidden")){gr();return}var t=document.getElementById("cwd");t&&fetch("/api/path-suggestions?q="+encodeURIComponent(t.value.trim()),{credentials:"same-origin"}).then(function(n){return n.json()}).then(Gg).catch(gr)}function Gg(e){var t=document.getElementById("cwd-suggestions");if(!t||!e.length){gr();return}t.innerHTML=e.map(function(n){return'<button class="suggestion-item" data-path="'+p(n.path)+'"><strong>'+p(n.name)+"</strong><small>"+Et(n.path,"suggestion-item-path")+"</small></button>"}).join(""),Wt(t),t.querySelectorAll(".suggestion-item").forEach(function(n){n.addEventListener("click",function(){document.getElementById("cwd").value=n.dataset.path||"",r.cwdValue=n.dataset.path||"",gr()})}),t.classList.remove("hidden")}function gr(){var e=document.getElementById("cwd-suggestions");e&&(e.classList.add("hidden"),e.innerHTML="")}function Yg(e){if(!e.isComposing){if(Zs(e)){cu(e);return}if(e.key==="Enter"){if(e.shiftKey){e.preventDefault();var t=document.getElementById("input-box");if(t){var n=t.selectionStart||0,i=t.value,a=i.slice(0,n)+`
49
49
  `+i.slice(n);t.value=a,t.selectionStart=n+1,t.selectionEnd=n+1,et(a,!0),kt(t)}return}e.preventDefault();var u=!!(e.metaKey||e.ctrlKey);Us(u?{interrupt:!0}:void 0);return}if(e.key==="Backspace"){setTimeout(function(){var g=document.getElementById("input-box");g&&et(g.value,!0)},0);return}if(e.key==="Tab"){e.preventDefault();var t=document.getElementById("input-box");if(t){var n=t.selectionStart||0,i=t.value,a=i.slice(0,n)+" "+i.slice(n);t.value=a,et(a,!0)}return}if(e.key==="Escape"){e.preventDefault();var o=Xe();se(o)?o&&o.structuredState&&o.structuredState.inFlight&&fu():bt(Wr("escape"),"escape");return}if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="c"){var s=document.getElementById("input-box"),l=s&&s.selectionStart!==s.selectionEnd||_i();if(l)return;var d=Xe();if(se(d)){e.preventDefault(),d&&d.structuredState&&d.structuredState.inFlight&&fu();return}e.preventDefault(),bt(Wr("ctrl_c"),"ctrl_c");return}if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="d"){var f=document.getElementById("input-box"),c=f&&f.selectionStart!==f.selectionEnd||_i();if(c)return;var v=Xe();if(se(v)){e.preventDefault();return}e.preventDefault(),bt(Wr("ctrl_d"),"ctrl_d");return}if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="l"){e.preventDefault();var h=Xe();if(se(h))return;bt(Wr("ctrl_l"),"ctrl_l");return}if(!((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="a")&&!((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="v")){if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==="x"){var t=document.getElementById("input-box"),m=t&&t.selectionStart!==t.selectionEnd;if(m)return;e.preventDefault(),bt("","ctrl_x");return}e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&setTimeout(function(){var g=document.getElementById("input-box");g&&et(g.value)},0)}}}var Qg=10*1024*1024;function $g(e){return e<1024?e+" B":e<1024*1024?(e/1024).toFixed(1)+" KB":(e/(1024*1024)).toFixed(1)+" MB"}function Xg(e){return/^image\/(png|jpe?g|gif|webp|bmp|svg\+xml)/.test(e)}function Ju(e){if(e){if(e.size>Qg){x("\u6587\u4EF6\u8FC7\u5927\uFF08\u4E0A\u9650 10 MB\uFF09: "+e.name,"error");return}var t={file:e,name:e.name,size:e.size,previewUrl:null};Xg(e.type)&&(t.previewUrl=URL.createObjectURL(e)),r.pendingAttachments.push(t),Gu()}}function Zg(e){var t=r.pendingAttachments.splice(e,1);t.length&&t[0].previewUrl&&URL.revokeObjectURL(t[0].previewUrl),Gu()}function eh(){r.pendingAttachments.forEach(function(e){e.previewUrl&&URL.revokeObjectURL(e.previewUrl)}),r.pendingAttachments=[],Gu()}function Gu(){var e=document.getElementById("attachment-preview");if(e){var t=r.pendingAttachments;if(t.length===0){e.classList.add("hidden"),e.innerHTML="";return}e.classList.remove("hidden");for(var n="",i=0;i<t.length;i++){var a=t[i],u=a.previewUrl?'<img src="'+p(a.previewUrl)+'" alt="">':'<span class="att-icon">'+V("file",{size:13,strokeWidth:1.7})+"</span>";n+='<span class="attachment-pill" data-index="'+i+'">'+u+'<span class="att-name" title="'+p(a.name)+'">'+p(a.name)+'</span><span class="att-size">'+$g(a.size)+'</span><button class="att-remove" data-index="'+i+'" title="\u79FB\u9664">\xD7</button></span>'}e.innerHTML=n,e.querySelectorAll(".att-remove").forEach(function(o){o.addEventListener("click",function(s){s.preventDefault(),s.stopPropagation(),Zg(parseInt(o.getAttribute("data-index"),10))})})}}function th(e){if(!r.pendingAttachments.length)return Promise.resolve([]);var t=new FormData;return r.pendingAttachments.forEach(function(n){t.append("files",n.file,n.name)}),fetch("/api/sessions/"+encodeURIComponent(e)+"/upload",{method:"POST",body:t,credentials:"same-origin"}).then(function(n){return n.ok?n.json():n.json().then(function(i){throw new Error(i.error||"\u4E0A\u4F20\u5931\u8D25")})}).then(function(n){return n.files||[]})}function nh(e){if(!e||!e.length)return"";var t=e.map(function(n){return n.savedPath});return`[\u9644\u4EF6\u5DF2\u4E0A\u4F20\uFF0C\u8BF7\u67E5\u770B\u4EE5\u4E0B\u6587\u4EF6:
50
50
  `+t.join(`
51
51
  `)+`]