@co0ontty/wand 4.10.2 → 4.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
- "commit": "f617af6046253e048946f61275832fb6185364d9",
3
- "builtAt": "2026-07-17T05:25:50.543Z",
4
- "version": "4.10.2",
2
+ "commit": "f95b8e7018d6c81a50bae385c3d7ed3cb5b39109",
3
+ "builtAt": "2026-07-17T05:30:24.232Z",
4
+ "version": "4.10.3",
5
5
  "channel": "stable"
6
6
  }
@@ -2835,7 +2835,7 @@ Error generating stack: `+l.message+`
2835
2835
 
2836
2836
  `+a:t||a,o=Array.isArray(e.buttons)&&e.buttons.length?e.buttons:[{label:"\u597D",value:!0,kind:"primary"}];if(e.input)return Promise.resolve(window.prompt(i,e.inputValue==null?"":String(e.inputValue)));if(o.length<=1)return window.alert(i),Promise.resolve(o[0]?.value);var c=window.confirm(i);if(!c)return Promise.resolve(e.cancelValue!==void 0?e.cancelValue:!1);var d=o.find(function(f){return f.kind==="primary"||f.kind==="danger"})||o[o.length-1];return Promise.resolve(d.value)}function Jj(e,t){return t=t||{},jl({title:t.title||"\u63D0\u793A",message:typeof e=="string"?e:String(e??""),type:t.type||"info",dismissable:t.dismissable,buttons:[{label:t.okLabel||"\u597D",value:void 0,kind:"primary",autofocus:!0}]})}function Ah(e,t){t=t||{};var a=!!t.danger||t.type==="danger";return jl({title:t.title||(a?"\u786E\u8BA4\u64CD\u4F5C":"\u8BF7\u786E\u8BA4"),message:typeof e=="string"?e:String(e??""),type:t.type||(a?"danger":"question"),cancelValue:!1,dismissable:t.dismissable,buttons:[{label:t.cancelLabel||"\u53D6\u6D88",value:!1,kind:"secondary"},{label:t.okLabel||(a?"\u5220\u9664":"\u786E\u5B9A"),value:!0,kind:a?"danger":"primary",autofocus:!a}]}).then(function(i){return i===!0})}function $j(e,t,a){return a=a||{},jl({title:a.title||"\u8BF7\u8F93\u5165",message:typeof e=="string"?e:String(e??""),type:a.type||"question",input:!0,inputValue:t==null?"":String(t),inputPlaceholder:a.placeholder||"",cancelValue:null,dismissable:a.dismissable,buttons:[{label:a.cancelLabel||"\u53D6\u6D88",value:null,kind:"secondary"},{label:a.okLabel||"\u786E\u5B9A",value:void 0,kind:"primary"}]})}window.wandAlert=Jj,window.wandConfirm=Ah,window.wandPrompt=$j,window.openWandDialog=jl,window.showToast=he;var Pr=[],ix=0,eM=6,tM=16;function Sh(e){if((e.actionLabel||e.playSound)&&px(),!s.notifBubble)return{dismiss:function(){}};var t=++ix,a=e.type||"info",i=e.icon||(a==="warning"?"!":a==="success"?"\u2713":"i"),o=e.duration!==void 0?e.duration:8e3,c=document.createElement("div");c.className="notification-bubble",c.setAttribute("data-nid",String(t));var d='<div class="notification-bubble-header"><span class="notification-bubble-icon '+a+'">'+i+'</span><span class="notification-bubble-title">'+L(e.title)+'</span><button class="notification-bubble-close" title="\u5173\u95ED">\xD7</button></div>',f=e.body?'<div class="notification-bubble-body">'+L(e.body).replace(/\n/g,"<br>")+"</div>":"",m=e.actionLabel?'<div class="notification-bubble-actions"><button class="primary">'+L(e.actionLabel)+"</button></div>":"";c.innerHTML=d+f+m,document.body.appendChild(c);var h={id:t,el:c};Pr.push(h),Bh();var g=c.querySelector(".notification-bubble-close");if(g&&(g.onclick=function(){Ml(t)}),e.actionLabel&&e.action){var y=c.querySelector(".notification-bubble-actions button");y&&(y.onclick=function(){e.action(),Ml(t)})}var b=null;return o>0&&(b=setTimeout(function(){Ml(t)},o)),{dismiss:function(){Ml(t)}}}function Ml(e){for(var t=-1,a=0;a<Pr.length;a++)if(Pr[a].id===e){t=a;break}if(t!==-1){var i=Pr[t];i.el.classList.add("slide-out"),Pr.splice(t,1),Bh(),setTimeout(function(){i.el.parentNode&&i.el.parentNode.removeChild(i.el)},300)}}function Bh(){for(var e=tM,t=0;t<Pr.length;t++)Pr[t].el.style.top=e+"px",e+=Pr[t].el.offsetHeight+eM}try{ux=navigator.userAgent.match(/WandPlatform\/macOS/),kh=window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.wandNative||null,ux&&kh&&typeof window.WandNative>"u"&&(window.WandNative={downloadUpdate:function(e,t,a){try{kh.postMessage({type:"downloadUpdate",url:String(e||""),fileName:String(t||"wand-update.dmg"),source:String(a||"local")})}catch{}}})}catch{}var ux,kh,Mi=typeof WandNative<"u"&&typeof WandNative.sendNotification=="function",Ol=navigator.userAgent.match(/WandApp\/([^\s]+)/),ox=/WandPlatform\/macOS/.test(navigator.userAgent),nM=!!Ol&&!ox,sx=Ol&&nM?Ol[1]:null,Th=Ol&&ox?Ol[1]:null;function _l(e){if(!(!Mi||typeof WandNative.vibrate!="function"))try{WandNative.vibrate(e||"light")}catch{}}function jh(){if(Mi){var e=s.sessions.some(function(t){return!t.archived&&(t.status==="running"||t.status==="thinking"||t.status==="initializing")});if(typeof WandNative.setKeepScreenOn=="function")try{WandNative.setKeepScreenOn(e)}catch{}if(e){if(typeof WandNative.startKeepAlive=="function")try{WandNative.startKeepAlive()}catch{}}else if(typeof WandNative.stopKeepAlive=="function")try{WandNative.stopKeepAlive()}catch{}}}function lx(){if(Mi&&typeof WandNative.getPermission=="function")try{return WandNative.getPermission()}catch{}return null}function aM(){if(Mi){var e=lx();if(e==="default"||e==="denied")try{WandNative.requestPermission()}catch{}return}typeof Notification<"u"&&Notification.permission==="default"&&Notification.requestPermission()}function rM(e){var t=e||{};return!(t.onlyWhenHidden&&!document.hidden||t.skipWhenSelectedSessionId&&t.skipWhenSelectedSessionId===s.selectedId&&!document.hidden)}function iM(e,t){if(!e||!t||t<=0)return!1;var a=s.notificationHistory[e]||0,i=Date.now();return i-a<t?!0:(s.notificationHistory[e]=i,!1)}function yf(e,t,a){var i=a||{},o=i.tag||"";if(rM(i)&&!iM(o,i.minIntervalMs||0)){if(Mi){var c=lx();if(c!=="granted")return;try{var d=o;i.kind&&(d=i.kind+(o?":"+o:"")),WandNative.sendNotification(e||"Wand",t||"",d||"")}catch{}return}if(!(typeof Notification>"u"||Notification.permission!=="granted")&&document.hidden)try{var f=new Notification(e,{body:t||"",icon:i.icon||"/favicon.ico",tag:o||void 0});f.onclick=function(){window.focus(),f.close(),i.onClick&&i.onClick()},setTimeout(function(){f.close()},1e4)}catch{}}}function uM(e,t){if(!(!t||!t.title)){var a=s.sessions.find(function(o){return o.id===e});if(a){var i=a.summary||a.command||e;yf("\u4EFB\u52A1\u8FDB\u884C\u4E2D",i+`
2837
2837
  `+t.title,{kind:"task",tag:"wand-task-"+e+"-"+t.title,minIntervalMs:9e4,onlyWhenHidden:!0,skipWhenSelectedSessionId:e,onClick:function(){e!==s.selectedId&&tr(e)}})}}}function cx(e,t){fM(e||"-",t||"-"),yf("Wand \u53D1\u73B0\u65B0\u7248\u672C","\u5F53\u524D "+(e||"-")+" \u2192 \u6700\u65B0 "+(t||"-"),{kind:"update",tag:"wand-update",minIntervalMs:3e5})}function oM(e,t){yf("\u9700\u8981\u4F60\u7684\u6388\u6743",t,{kind:"permission",tag:"wand-perm-"+e,minIntervalMs:6e4,onlyWhenHidden:!0,skipWhenSelectedSessionId:e,onClick:function(){e!==s.selectedId&&tr(e)}})}function sM(e,t,a){yf(t,a,{kind:"task-ended",tag:"wand-ended-"+e,minIntervalMs:1e4,onClick:function(){e!==s.selectedId&&tr(e)}})}var Hu={},lM=30;function dx(e){if(!e)return"";var t=String(e).replace(/^#+\s+/gm,"").replace(/\*\*/g,"").replace(/`/g,"").trim(),a=t.split(`
2838
- `)[0].trim();return a.length>100&&(a=a.slice(0,100)+"\u2026"),a}function Mh(e){!Mi||typeof WandNative.updateSessionProgress!="function"||e&&(Hu[e]&&clearTimeout(Hu[e]),Hu[e]=setTimeout(function(){delete Hu[e],cM(e)},lM))}function cM(e){var t=s.sessions.find(function(k){return k.id===e});if(t){var a=t.summary||t.command||e,i=t.status||"running";if(i==="idle"||i==="archived"||i==="exited"){fx(e);return}for(var o=null,c="",d="",f=[],m=t.messages||[],h=m.length-1;h>=0;h--){var g=m[h];if(!(!g.content||!Array.isArray(g.content))){if(!d&&g.role==="assistant")for(var y=g.content.length-1;y>=0;y--){var b=g.content[y];if(b&&b.type==="text"&&b.text&&b.text.trim()){d=dx(b.text);break}}if(g.role==="user"){var C=g.content.some(function(k){return k&&k.__queued});if(!C)for(var w=0;w<g.content.length;w++){var x=g.content[w];if(x&&x.type==="text"&&x.text&&x.text.trim()){var F=dx(x.text);c||(c=F),f.length<4&&f.push(F);break}}}if(!o)for(var A=g.content.length-1;A>=0;A--){var D=g.content[A];if(D&&D.type==="tool_use"&&D.name==="TodoWrite"&&D.input&&D.input.todos){o=D.input.todos;break}}if(o&&f.length>=4&&d)break}}f.reverse();var B="";e===s.selectedId&&s.currentTask&&s.currentTask.title&&(B=s.currentTask.title);var T={sessionLabel:a,status:i,currentTask:B,latestUserText:c,latestAssistantText:d,todos:o||[],recentUserTexts:f};try{WandNative.updateSessionProgress(e,JSON.stringify(T))}catch{}}}function fx(e){if(!(!Mi||typeof WandNative.clearSessionProgress!="function")){Hu[e]&&(clearTimeout(Hu[e]),delete Hu[e]);try{WandNative.clearSessionProgress(e)}catch{}}}window.handleNativeBack=function(){if(Nu.isOpen())return!0;var e=window.__wandReactUi;if(e&&typeof e.closeTopmost=="function")try{if(e.closeTopmost())return!0}catch{}var t=window.__wandReactFilePreview;if(t&&typeof t.closeTopmost=="function")try{if(t.closeTopmost())return!0}catch{}var a=window.__wandReactQuickCommit;if(a&&typeof a.closeTopmost=="function")try{if(a.closeTopmost())return!0}catch{}var i=window.__wandReactNewSession;if(i&&typeof i.closeTopmost=="function")try{if(i.closeTopmost())return!0}catch{}var o=window.__wandReactFolderPicker;if(o&&typeof o.closeTopmost=="function")try{if(o.closeTopmost())return!0}catch{}var c=window.__wandReactWorktreeMerge;if(c&&typeof c.closeTopmost=="function")try{if(c.closeTopmost())return!0}catch{}var d=window.__wandReactSettings;if(d&&typeof d.closeTopmost=="function")try{if(d.closeTopmost())return!0}catch{}return s.filePanelOpen&&wn()?(Jm(!1),!0):s.sessionsDrawerOpen&&wn()?(as(),!0):wn()&&s.selectedId?(s.selectedId=null,Vt(),s.sessionsDrawerOpen=!0,kt("wand-sidebar-open",!0),ji(),!0):!1};function px(){s.notifSound&&dM()}function dM(){try{let o=function(c,d,f){var m=a.createOscillator(),h=a.createGain();m.type="sine",m.frequency.value=c,h.gain.setValueAtTime(0,a.currentTime+d),h.gain.linearRampToValueAtTime(.5*i,a.currentTime+d+.04),h.gain.exponentialRampToValueAtTime(.001,a.currentTime+d+f),m.connect(h),h.connect(a.destination),m.start(a.currentTime+d),m.stop(a.currentTime+d+f)};var e=o,t=window.AudioContext||window.webkitAudioContext;if(!t)return!1;var a=new t;a.state==="suspended"&&a.resume();var i=(s.notifVolume||0)/100;return o(523,0,.25),o(659,.12,.3),setTimeout(function(){a.close()},600),!0}catch{return!1}}function fM(e,t){if(s._updateBubbleShown)return;s._updateBubbleShown=!0,px();var a=++ix,i=document.createElement("div");i.className="notification-bubble update-card",i.setAttribute("data-nid",String(a)),i.innerHTML='<div class="update-card-shine" aria-hidden="true"></div><div class="update-card-header"><div class="update-card-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5"/><path d="M5 12l7-7 7 7"/></svg></div><div class="update-card-heading"><div class="update-card-title">\u53D1\u73B0\u65B0\u7248\u672C</div><div class="update-card-subtitle" id="update-card-subtitle">\u70B9\u51FB\u4E0B\u65B9\u6309\u94AE\u4E00\u952E\u66F4\u65B0</div></div><button class="update-card-close" title="\u7A0D\u540E\u63D0\u9192" aria-label="\u5173\u95ED"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6L6 18"/><path d="M6 6l12 12"/></svg></button></div><div class="update-card-version"><span class="update-card-version-chip update-card-version-current">v'+L(String(e).replace(/^v/,""))+'</span><svg class="update-card-version-arrow" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M13 5l7 7-7 7"/></svg><span class="update-card-version-chip update-card-version-latest">v'+L(String(t).replace(/^v/,""))+'</span></div><div class="update-card-progress" id="update-card-progress" aria-hidden="true"><div class="update-card-progress-track"><div class="update-card-progress-fill"></div></div></div><div class="update-card-status hidden" id="update-card-status"></div><div class="update-card-actions"><button class="update-card-action update-card-action-primary" id="update-bubble-action" type="button"><span class="update-card-action-label">\u7ACB\u5373\u66F4\u65B0</span></button></div>',document.body.appendChild(i);var o={id:a,el:i};Pr.push(o),Bh();var c=i.querySelector(".update-card-close");c&&(c.onclick=function(){Ml(a),s._updateBubbleShown=!1});var d=i.querySelector("#update-bubble-action"),f=i.querySelector(".update-card-action-label"),m=i.querySelector("#update-card-subtitle"),h=i.querySelector("#update-card-status"),g=i.querySelector("#update-card-progress");function y(w,x){if(h){if(h.textContent=w||"",h.classList.remove("hidden","error","success"),!w){h.classList.add("hidden");return}x&&h.classList.add(x)}}function b(w){m&&(m.textContent=w||"")}function C(w){g&&g.classList.toggle("active",!!w)}d&&(d.onclick=function(){d.disabled=!0,i.classList.add("is-busy"),f&&(f.textContent="\u66F4\u65B0\u4E2D\u2026"),b("\u6B63\u5728\u4E0B\u8F7D\u5E76\u5B89\u88C5\u65B0\u7248\u672C\u2026"),C(!0),y(""),fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin"}).then(function(w){return w.json()}).then(function(w){if(w.error){C(!1),i.classList.remove("is-busy"),b("\u66F4\u65B0\u672A\u5B8C\u6210"),y(w.error,"error"),d.disabled=!1,f&&(f.textContent="\u91CD\u8BD5");return}if(i.classList.add("is-success"),b((w.message||"\u66F4\u65B0\u5B8C\u6210")+"\uFF0C\u6B63\u5728\u91CD\u542F\u670D\u52A1\u2026"),y(""),f&&(f.textContent="\u6B63\u5728\u91CD\u542F\u2026"),w.detachedUpdate){Nl();return}if(w.restartRequired===!1){C(!1),i.classList.remove("is-busy"),d.disabled=!1,f&&(f.textContent="\u5DF2\u5B8C\u6210");return}pM(d,f,m,h,g)}).catch(function(){C(!1),i.classList.remove("is-busy"),b("\u66F4\u65B0\u672A\u5B8C\u6210"),y("\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u540E\u91CD\u8BD5","error"),d.disabled=!1,f&&(f.textContent="\u91CD\u8BD5")})})}function pM(e,t,a,i,o){fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin"}).then(function(c){return c.json()}).then(function(){Nl()}).catch(function(){Nl()})}function Nl(e,t){g9(e,t)}function vM(e,t,a){y9(e,t,a)}var Ot={recording:!1,canceling:!1,transcript:"",startY:0},mM=60;function hM(e){Ot.transcript=e||"";var t=document.getElementById("voice-transcript-text");t&&(t.textContent=Ot.transcript);var a=document.getElementById("voice-transcript-bubble");a&&a.classList.toggle("has-text",!!Ot.transcript)}function gM(e){if(!(s.terminalInteractive||Ot.recording)){if(e){e.preventDefault(),Ot.startY=typeof e.clientY=="number"?e.clientY:0;try{e.pointerId!==void 0&&e.currentTarget&&e.currentTarget.setPointerCapture&&e.currentTarget.setPointerCapture(e.pointerId)}catch{}}Ot.recording=!0,Ot.canceling=!1,Ot.transcript="";var t=document.getElementById("voice-record-btn");if(t){t.classList.add("is-recording"),t.setAttribute("aria-pressed","true"),t.setAttribute("title","\u677E\u5F00\u7ED3\u675F \xB7 \u4E0A\u6ED1\u53D6\u6D88");var a=t.querySelector(".voice-record-label");a&&(a.textContent="\u677E\u5F00 \u53D1\u9001")}var i=document.getElementById("voice-transcript-bubble");i&&i.classList.remove("hidden","is-canceling","has-text"),hM("");var o=document.getElementById("voice-transcript-status");o&&(o.textContent="\u7F51\u9875\u7AEF\u6682\u4E0D\u652F\u6301\u8BED\u97F3\u8F93\u5165\uFF0C\u8BF7\u4F7F\u7528 App")}}function yM(e){if(!(!Ot.recording||!e)){var t=Ot.startY-(typeof e.clientY=="number"?e.clientY:Ot.startY),a=t>mM;if(a!==Ot.canceling){Ot.canceling=a;var i=document.getElementById("voice-transcript-bubble");i&&i.classList.toggle("is-canceling",a);var o=document.getElementById("voice-record-btn"),c=o&&o.querySelector(".voice-record-label");c&&(c.textContent=a?"\u677E\u5F00 \u53D6\u6D88":"\u677E\u5F00 \u53D1\u9001");var d=document.getElementById("voice-transcript-status");d&&(d.textContent=a?"\u677E\u5F00\u624B\u6307 \u53D6\u6D88":"\u6B63\u5728\u8046\u542C\u2026\u4E0A\u6ED1\u53D6\u6D88")}}}function vx(e){if(Ot.recording){e&&e.preventDefault(),Ot.recording=!1;var t=!Ot.canceling&&!!Ot.transcript.trim(),a=Ot.transcript;mx(),t&&wM(a)}}function bM(e){Ot.recording&&(Ot.canceling=!0,vx(e))}function mx(){Ot.canceling=!1;var e=document.getElementById("voice-record-btn");if(e){e.classList.remove("is-recording"),e.setAttribute("aria-pressed","false"),e.setAttribute("title","\u6309\u4F4F\u8BED\u97F3\u8F93\u5165");var t=e.querySelector(".voice-record-label");t&&(t.textContent="\u6309\u4F4F \u8BF4\u8BDD")}var a=document.getElementById("voice-transcript-bubble");a&&a.classList.add("hidden")}function wM(e){var t=(e||"").trim();if(t){var a=document.getElementById("input-box");if(a){var i=a.value||"",o=i?i.replace(/\s+$/,"")+" "+t:t;a.value=o,Kn(o,!0),sa(a);try{a.setSelectionRange(o.length,o.length)}catch{}}}}function sa(e){if(e){var t=36,a=parseFloat(window.getComputedStyle(e).maxHeight||""),i=Number.isFinite(a)?Math.max(t,a):120,o=Pl();if(!e.value||e.value.trim()===""){e.style.height=t+"px",e.style.minHeight=t+"px",e.style.overflowY=o?"auto":"hidden",e.scrollTop=0,e.classList.remove("has-multiline-draft","has-clipped-draft"),Uf(e);return}var c=e.style.overflowY;e.style.overflowY="hidden",e.style.height=t+"px";var d=e.scrollHeight,f=Math.max(t,Math.min(d,i)),m=d>i,h=d>t+1;e.style.height=f+"px",e.style.minHeight=t+"px",e.style.overflowY=m||o?"auto":"hidden",e.classList.toggle("has-multiline-draft",h),e.classList.toggle("has-clipped-draft",m),m?kf(e):e.scrollTop=0,Uf(e)}}function xM(){if(!s.selectedId)return!1;var e=s.sessions.find(function(t){return t.id===s.selectedId});return yt(e)?!!(e.structuredState&&e.structuredState.inFlight):!!e&&e.status==="running"}var Rl=!1;function hx(e){return!e||e.archived?!1:yt(e)?!!(e.structuredState&&e.structuredState.inFlight):e.status==="running"}function Oh(){return s.sessions.some(hx)}function EM(){var e=s.sessions.filter(hx);if(e.length===0)return null;if(s.selectedId){var t=e.find(function(a){return a.id===s.selectedId});if(t)return t}return e.sort(function(a,i){return(Date.parse(i.startedAt)||0)-(Date.parse(a.startedAt)||0)}),e[0]}function gx(e){if(!e)return"";for(var t=Array.isArray(e.queuedMessages)?e.queuedMessages:[],a=t.length-1;a>=0;a--){var i=typeof t[a]=="string"?t[a].trim():"";if(i)return i}for(var o=Array.isArray(e.messages)?e.messages:[],c=o.length-1;c>=0;c--){var d=o[c];if(!(!d||d.role!=="user"||!Array.isArray(d.content))){var f=d.content.filter(function(g){return g&&g.type==="text"&&typeof g.text=="string"}).map(function(g){return g.text});if(f.length)return f.join(`
2838
+ `)[0].trim();return a.length>100&&(a=a.slice(0,100)+"\u2026"),a}function Mh(e){!Mi||typeof WandNative.updateSessionProgress!="function"||e&&(Hu[e]&&clearTimeout(Hu[e]),Hu[e]=setTimeout(function(){delete Hu[e],cM(e)},lM))}function cM(e){var t=s.sessions.find(function(k){return k.id===e});if(t){var a=t.summary||t.command||e,i=t.status||"running";if(i==="idle"||i==="archived"||i==="exited"){fx(e);return}for(var o=null,c="",d="",f=[],m=t.messages||[],h=m.length-1;h>=0;h--){var g=m[h];if(!(!g.content||!Array.isArray(g.content))){if(!d&&g.role==="assistant")for(var y=g.content.length-1;y>=0;y--){var b=g.content[y];if(b&&b.type==="text"&&b.text&&b.text.trim()){d=dx(b.text);break}}if(g.role==="user"){var C=g.content.some(function(k){return k&&k.__queued});if(!C)for(var w=0;w<g.content.length;w++){var x=g.content[w];if(x&&x.type==="text"&&x.text&&x.text.trim()){var F=dx(x.text);c||(c=F),f.length<4&&f.push(F);break}}}if(!o)for(var A=g.content.length-1;A>=0;A--){var D=g.content[A];if(D&&D.type==="tool_use"&&D.name==="TodoWrite"&&D.input&&D.input.todos){o=D.input.todos;break}}if(o&&f.length>=4&&d)break}}f.reverse();var B="";e===s.selectedId&&s.currentTask&&s.currentTask.title&&(B=s.currentTask.title);var T={sessionLabel:a,status:i,currentTask:B,latestUserText:c,latestAssistantText:d,todos:o||[],recentUserTexts:f};try{WandNative.updateSessionProgress(e,JSON.stringify(T))}catch{}}}function fx(e){if(!(!Mi||typeof WandNative.clearSessionProgress!="function")){Hu[e]&&(clearTimeout(Hu[e]),delete Hu[e]);try{WandNative.clearSessionProgress(e)}catch{}}}window.handleNativeBack=function(){if(Nu.isOpen())return!0;var e=window.__wandReactUi;if(e&&typeof e.closeTopmost=="function")try{if(e.closeTopmost())return!0}catch{}var t=window.__wandReactFilePreview;if(t&&typeof t.closeTopmost=="function")try{if(t.closeTopmost())return!0}catch{}var a=window.__wandReactQuickCommit;if(a&&typeof a.closeTopmost=="function")try{if(a.closeTopmost())return!0}catch{}var i=window.__wandReactNewSession;if(i&&typeof i.closeTopmost=="function")try{if(i.closeTopmost())return!0}catch{}var o=window.__wandReactFolderPicker;if(o&&typeof o.closeTopmost=="function")try{if(o.closeTopmost())return!0}catch{}var c=window.__wandReactWorktreeMerge;if(c&&typeof c.closeTopmost=="function")try{if(c.closeTopmost())return!0}catch{}var d=window.__wandReactSettings;if(d&&typeof d.closeTopmost=="function")try{if(d.closeTopmost())return!0}catch{}return s.filePanelOpen&&wn()?(Jm(!1),!0):s.sessionsDrawerOpen&&wn()?(as(),!0):wn()&&s.selectedId?(s.selectedId=null,Vt(),s.sessionsDrawerOpen=!0,kt("wand-sidebar-open",!0),ji(),!0):!1};function px(){s.notifSound&&dM()}function dM(){try{let o=function(c,d,f){var m=a.createOscillator(),h=a.createGain();m.type="sine",m.frequency.value=c,h.gain.setValueAtTime(0,a.currentTime+d),h.gain.linearRampToValueAtTime(.5*i,a.currentTime+d+.04),h.gain.exponentialRampToValueAtTime(.001,a.currentTime+d+f),m.connect(h),h.connect(a.destination),m.start(a.currentTime+d),m.stop(a.currentTime+d+f)};var e=o,t=window.AudioContext||window.webkitAudioContext;if(!t)return!1;var a=new t;a.state==="suspended"&&a.resume();var i=(s.notifVolume||0)/100;return o(523,0,.25),o(659,.12,.3),setTimeout(function(){a.close()},600),!0}catch{return!1}}function fM(e,t){if(s._updateBubbleShown)return;s._updateBubbleShown=!0,px();var a=++ix,i=document.createElement("div");i.className="notification-bubble update-card",i.setAttribute("data-nid",String(a)),i.innerHTML='<div class="update-card-shine" aria-hidden="true"></div><div class="update-card-header"><div class="update-card-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5"/><path d="M5 12l7-7 7 7"/></svg></div><div class="update-card-heading"><div class="update-card-title">\u53D1\u73B0\u65B0\u7248\u672C</div><div class="update-card-subtitle" id="update-card-subtitle">\u70B9\u51FB\u4E0B\u65B9\u6309\u94AE\u4E00\u952E\u66F4\u65B0</div></div><button class="update-card-close" title="\u7A0D\u540E\u63D0\u9192" aria-label="\u5173\u95ED"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6L6 18"/><path d="M6 6l12 12"/></svg></button></div><div class="update-card-version"><span class="update-card-version-chip update-card-version-current">v'+L(String(e).replace(/^v/,""))+'</span><svg class="update-card-version-arrow" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="M13 5l7 7-7 7"/></svg><span class="update-card-version-chip update-card-version-latest">v'+L(String(t).replace(/^v/,""))+'</span></div><div class="update-card-progress" id="update-card-progress" aria-hidden="true"><div class="update-card-progress-track"><div class="update-card-progress-fill"></div></div></div><div class="update-card-status hidden" id="update-card-status"></div><div class="update-card-actions"><button class="update-card-action update-card-action-primary" id="update-bubble-action" type="button"><span class="update-card-action-label">\u7ACB\u5373\u66F4\u65B0</span></button></div>',document.body.appendChild(i);var o={id:a,el:i};Pr.push(o),Bh();var c=i.querySelector(".update-card-close");c&&(c.onclick=function(){Ml(a),s._updateBubbleShown=!1});var d=i.querySelector("#update-bubble-action"),f=i.querySelector(".update-card-action-label"),m=i.querySelector("#update-card-subtitle"),h=i.querySelector("#update-card-status"),g=i.querySelector("#update-card-progress");function y(w,x){if(h){if(h.textContent=w||"",h.classList.remove("hidden","error","success"),!w){h.classList.add("hidden");return}x&&h.classList.add(x)}}function b(w){m&&(m.textContent=w||"")}function C(w){g&&g.classList.toggle("active",!!w)}d&&(d.onclick=function(){d.disabled=!0,i.classList.add("is-busy"),f&&(f.textContent="\u66F4\u65B0\u4E2D\u2026"),b("\u6B63\u5728\u4E0B\u8F7D\u5E76\u5B89\u88C5\u65B0\u7248\u672C\u2026"),C(!0),y(""),fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin"}).then(function(w){return w.json()}).then(function(w){if(w.error){C(!1),i.classList.remove("is-busy"),b("\u66F4\u65B0\u672A\u5B8C\u6210"),y(w.error,"error"),d.disabled=!1,f&&(f.textContent="\u91CD\u8BD5");return}if(i.classList.add("is-success"),b((w.message||"\u66F4\u65B0\u5B8C\u6210")+"\uFF0C\u6B63\u5728\u91CD\u542F\u670D\u52A1\u2026"),y(""),f&&(f.textContent="\u6B63\u5728\u91CD\u542F\u2026"),w.detachedUpdate){Nl();return}if(w.restartRequired===!1){C(!1),i.classList.remove("is-busy"),d.disabled=!1,f&&(f.textContent="\u5DF2\u5B8C\u6210");return}pM(d,f,m,h,g)}).catch(function(){C(!1),i.classList.remove("is-busy"),b("\u66F4\u65B0\u672A\u5B8C\u6210"),y("\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u540E\u91CD\u8BD5","error"),d.disabled=!1,f&&(f.textContent="\u91CD\u8BD5")})})}function pM(e,t,a,i,o){fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin"}).then(function(c){return c.json()}).then(function(){Nl()}).catch(function(){Nl()})}function Nl(e,t){g9(e,t)}function vM(e,t,a){y9(e,t,a)}var Ot={recording:!1,canceling:!1,transcript:"",startY:0},mM=60;function hM(e){Ot.transcript=e||"";var t=document.getElementById("voice-transcript-text");t&&(t.textContent=Ot.transcript);var a=document.getElementById("voice-transcript-bubble");a&&a.classList.toggle("has-text",!!Ot.transcript)}function gM(e){if(!(s.terminalInteractive||Ot.recording)){if(e){e.preventDefault(),Ot.startY=typeof e.clientY=="number"?e.clientY:0;try{e.pointerId!==void 0&&e.currentTarget&&e.currentTarget.setPointerCapture&&e.currentTarget.setPointerCapture(e.pointerId)}catch{}}Ot.recording=!0,Ot.canceling=!1,Ot.transcript="";var t=document.getElementById("voice-record-btn");if(t){t.classList.add("is-recording"),t.setAttribute("aria-pressed","true"),t.setAttribute("title","\u677E\u5F00\u7ED3\u675F \xB7 \u4E0A\u6ED1\u53D6\u6D88");var a=t.querySelector(".voice-record-label");a&&(a.textContent="\u677E\u5F00 \u53D1\u9001")}var i=document.getElementById("voice-transcript-bubble");i&&i.classList.remove("hidden","is-canceling","has-text"),hM("");var o=document.getElementById("voice-transcript-status");o&&(o.textContent="\u7F51\u9875\u7AEF\u6682\u4E0D\u652F\u6301\u8BED\u97F3\u8F93\u5165\uFF0C\u8BF7\u4F7F\u7528 App")}}function yM(e){if(!(!Ot.recording||!e)){var t=Ot.startY-(typeof e.clientY=="number"?e.clientY:Ot.startY),a=t>mM;if(a!==Ot.canceling){Ot.canceling=a;var i=document.getElementById("voice-transcript-bubble");i&&i.classList.toggle("is-canceling",a);var o=document.getElementById("voice-record-btn"),c=o&&o.querySelector(".voice-record-label");c&&(c.textContent=a?"\u677E\u5F00 \u53D6\u6D88":"\u677E\u5F00 \u53D1\u9001");var d=document.getElementById("voice-transcript-status");d&&(d.textContent=a?"\u677E\u5F00\u624B\u6307 \u53D6\u6D88":"\u6B63\u5728\u8046\u542C\u2026\u4E0A\u6ED1\u53D6\u6D88")}}}function vx(e){if(Ot.recording){e&&e.preventDefault(),Ot.recording=!1;var t=!Ot.canceling&&!!Ot.transcript.trim(),a=Ot.transcript;mx(),t&&wM(a)}}function bM(e){Ot.recording&&(Ot.canceling=!0,vx(e))}function mx(){Ot.canceling=!1;var e=document.getElementById("voice-record-btn");if(e){e.classList.remove("is-recording"),e.setAttribute("aria-pressed","false"),e.setAttribute("title","\u6309\u4F4F\u8BED\u97F3\u8F93\u5165");var t=e.querySelector(".voice-record-label");t&&(t.textContent="\u6309\u4F4F \u8BF4\u8BDD")}var a=document.getElementById("voice-transcript-bubble");a&&a.classList.add("hidden")}function wM(e){var t=(e||"").trim();if(t){var a=document.getElementById("input-box");if(a){var i=a.value||"",o=i?i.replace(/\s+$/,"")+" "+t:t;a.value=o,Kn(o,!0),sa(a);try{a.setSelectionRange(o.length,o.length)}catch{}}}}function sa(e){if(e){var t=36,a=parseFloat(window.getComputedStyle(e).maxHeight||""),i=Number.isFinite(a)?Math.max(t,a):120,o=Pl();if(!e.value||e.value.trim()===""){e.style.height=t+"px",e.style.minHeight=t+"px",e.style.overflowY=o?"auto":"hidden",e.scrollTop=0,e.classList.remove("has-multiline-draft","has-clipped-draft"),e.closest(".input-composer")?.classList.remove("is-expanded"),Uf(e);return}var c=e.style.overflowY;e.style.overflowY="hidden",e.style.height=t+"px";var d=e.scrollHeight,f=Math.max(t,Math.min(d,i)),m=d>i,h=d>t+1;e.style.height=f+"px",e.style.minHeight=t+"px",e.style.overflowY=m||o?"auto":"hidden",e.classList.toggle("has-multiline-draft",h),e.classList.toggle("has-clipped-draft",m),e.closest(".input-composer")?.classList.toggle("is-expanded",h),m?kf(e):e.scrollTop=0,Uf(e)}}function xM(){if(!s.selectedId)return!1;var e=s.sessions.find(function(t){return t.id===s.selectedId});return yt(e)?!!(e.structuredState&&e.structuredState.inFlight):!!e&&e.status==="running"}var Rl=!1;function hx(e){return!e||e.archived?!1:yt(e)?!!(e.structuredState&&e.structuredState.inFlight):e.status==="running"}function Oh(){return s.sessions.some(hx)}function EM(){var e=s.sessions.filter(hx);if(e.length===0)return null;if(s.selectedId){var t=e.find(function(a){return a.id===s.selectedId});if(t)return t}return e.sort(function(a,i){return(Date.parse(i.startedAt)||0)-(Date.parse(a.startedAt)||0)}),e[0]}function gx(e){if(!e)return"";for(var t=Array.isArray(e.queuedMessages)?e.queuedMessages:[],a=t.length-1;a>=0;a--){var i=typeof t[a]=="string"?t[a].trim():"";if(i)return i}for(var o=Array.isArray(e.messages)?e.messages:[],c=o.length-1;c>=0;c--){var d=o[c];if(!(!d||d.role!=="user"||!Array.isArray(d.content))){var f=d.content.filter(function(g){return g&&g.type==="text"&&typeof g.text=="string"}).map(function(g){return g.text});if(f.length)return f.join(`
2839
2839
  `).trim();for(var m=0;m<d.content.length;m++){var h=d.content[m];if(h&&h.type==="tool_result"&&typeof h.content=="string")return h.content.trim()}return""}}return""}function FM(e,t){var a=typeof t=="string"?t.trim():"";if(a&&gx(e)===a)return he("\u4E0E\u4E0A\u4E00\u6761\u6D88\u606F\u76F8\u540C\uFF0C\u5DF2\u5FFD\u7565\uFF0C\u4E0D\u4F1A\u52A0\u5165\u6392\u961F\u3002","warning"),Promise.resolve();var i=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():Date.now().toString(36)+"-"+Math.random().toString(36).slice(2,10),o=Array.isArray(e.queuedMessages)?e.queuedMessages.slice():[],c=o.slice();c.push(t),at({id:e.id,queuedMessages:c}),e.id===s.selectedId&&Gn();var d=e.title||es(e.command)||"\u5F53\u524D\u4F1A\u8BDD";return he("\u5DF2\u52A0\u5165\u300C"+d+"\u300D\u7684\u6392\u961F\uFF0C\u56DE\u590D\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u9001\uFF08\u542B\u4E0A\u4E0B\u6587\uFF09\u3002","info"),fetch("/api/structured-sessions/"+e.id+"/messages",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({input:t,idempotencyKey:i})}).then(function(f){return f.ok?f.json():f.json().catch(function(){return{error:"\u8BF7\u6C42\u5931\u8D25"}}).then(function(m){throw new Error(m&&m.error||"\u65E0\u6CD5\u6392\u961F\u6D88\u606F\u3002")})}).then(function(f){f&&f.id&&(at(f),f.id===s.selectedId&&Gn())}).catch(function(f){at({id:e.id,queuedMessages:o}),e.id===s.selectedId&&Gn(),he(f&&f.message||"\u6392\u961F\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002","error")})}function yx(e){var t=EM();if(t&&yt(t)){FM(t,e);return}if(s.crossSessionQueue.length>=10){he("\u6392\u961F\u6D88\u606F\u5DF2\u6EE1\uFF08\u6700\u591A 10 \u6761\uFF09\uFF0C\u8BF7\u7B49\u5F85\u5F53\u524D\u4F1A\u8BDD\u5B8C\u6210\u3002","warning");return}var a="csq-"+Date.now()+"-"+Math.random().toString(36).slice(2,8);s.crossSessionQueue.push({id:a,text:e,cwd:Hr(),mode:s.chatMode||"managed",tool:er(),queuedAt:Date.now()}),Dr(),$a(),he("\u5DF2\u6392\u961F\uFF0C\u5C06\u5728\u7A7A\u95F2\u540E\u81EA\u52A8\u5F00\u59CB\u65B0\u4F1A\u8BDD\u3002","info")}function CM(e){Rl||(Rl=!0,fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({command:e.tool,cwd:e.cwd,mode:e.mode,initialInput:e.text}))}).then(function(t){return t.json()}).then(function(t){return Rl=!1,t.error?(he(t.error,"error"),s.crossSessionQueue.unshift(e),Dr(),$a(),null):Af(t)}).catch(function(t){Rl=!1,he(t&&t.message||"\u65E0\u6CD5\u542F\u52A8\u6392\u961F\u4F1A\u8BDD\u3002","error"),s.crossSessionQueue.unshift(e),Dr(),$a()}))}function DM(e){var t=s.crossSessionQueue.findIndex(function(i){return i.id===e});if(!(t<0)){var a=s.crossSessionQueue.splice(t,1)[0];Dr(),$a(),fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({command:a.tool,cwd:a.cwd,mode:a.mode,initialInput:a.text}))}).then(function(i){return i.json()}).then(function(i){return i.error?(he(i.error,"error"),s.crossSessionQueue.splice(t,0,a),Dr(),$a(),null):Af(i)}).catch(function(i){he(i&&i.message||"\u65E0\u6CD5\u542F\u52A8\u6392\u961F\u4F1A\u8BDD\u3002","error"),s.crossSessionQueue.splice(t,0,a),Dr(),$a()})}}function AM(e){var t=s.crossSessionQueue.findIndex(function(a){return a.id===e});t<0||(s.crossSessionQueue.splice(t,1),Dr(),$a(),s.crossSessionQueue.length===0&&he("\u6392\u961F\u5DF2\u6E05\u7A7A\u3002","info"))}function bf(){if(s.crossSessionQueue.length!==0&&!Oh()&&!Rl){var e=s.crossSessionQueue.shift();$a(),CM(e)}}function bx(e){var t=Math.floor((Date.now()-e)/1e3);if(t<60)return t+"s";var a=Math.floor(t/60);return a<60?a+"m":Math.floor(a/60)+"h"}function $a(){var e=document.querySelector(".cross-session-queue"),t=document.querySelector(".input-panel"),a=document.querySelector(".structured-status-bar"),i=document.querySelector(".input-composer"),o=document.getElementById("cross-session-queue-host");if(s.crossSessionQueue.length===0){e&&e.remove(),Dr();return}var c=t&&!t.classList.contains("hidden"),d=c?t:o,f=c?a||i:null;if(d){e&&e.parentNode!==d&&(e.remove(),e=null),e?c&&f&&e.nextSibling!==f&&d.insertBefore(e,f):(e=document.createElement("div"),e.className="cross-session-queue",f?d.insertBefore(e,f):d.appendChild(e));var m=s.crossSessionQueue.length,h=s.crossSessionQueue.map(function(y,b){var C=y.text.length>60?y.text.slice(0,60)+"\u2026":y.text,w=bx(y.queuedAt);return'<div class="queue-item" data-queue-id="'+L(y.id)+'"><span class="queue-item-dot"></span><span class="queue-item-text" title="'+L(y.text)+'">'+L(C)+'</span><span class="queue-item-age">'+w+'</span><button class="queue-item-send-now" data-queue-id="'+L(y.id)+'" title="\u7ACB\u5373\u53D1\u9001" type="button">\u53D1\u9001</button><button class="queue-item-cancel" data-queue-id="'+L(y.id)+'" title="\u53D6\u6D88" type="button">\xD7</button></div>'}).join(""),g=m>1?'<div class="queue-header"><span class="queue-header-label">\u6392\u961F '+m+' \u6761</span><button class="queue-header-clear" id="queue-clear-all" type="button" title="\u6E05\u7A7A\u6392\u961F">\u6E05\u7A7A</button></div>':"";e.innerHTML=g+h}}setInterval(function(){if(s.crossSessionQueue.length>0){var e=document.querySelectorAll(".queue-item-age");s.crossSessionQueue.forEach(function(t,a){e[a]&&(e[a].textContent=bx(t.queuedAt))}),bf()}},5e3),document.addEventListener("click",function(e){var t=e.target;if(t.closest("#queue-clear-all")){e.preventDefault(),s.crossSessionQueue=[],Dr(),$a(),he("\u6392\u961F\u5DF2\u6E05\u7A7A\u3002","info");return}var a=t.closest(".queue-item-send-now");if(a){e.preventDefault(),DM(a.dataset.queueId);return}var i=t.closest(".queue-item-cancel");if(i){e.preventDefault(),AM(i.dataset.queueId);return}});function wx(){var e=document.getElementById("welcome-input"),t=e?e.value.trim():"";if(t){if(Oh()){e.value="",yx(t);return}var a=document.getElementById("todo-progress");a&&a.classList.add("hidden"),e.value="",e.placeholder="\u6B63\u5728\u542F\u52A8\u2026",e.disabled=!0;var i=s.chatMode||"managed",o=Hr(),c=er();fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({command:c,provider:c,cwd:o,mode:i,initialInput:t}))}).then(function(d){return d.json()}).then(function(d){if(d.error){he(d.error,"error"),e.placeholder="\u8F93\u5165\u6D88\u606F",e.disabled=!1;return}s.selectedId=d.id,Vt(),s.drafts[d.id]="",Da(),at(d),Ct(),Il(d.id),Gu(d.id),zi(d.id).then(function(){e.placeholder="\u8F93\u5165\u6D88\u606F",e.disabled=!1,yr(!0)})}).catch(function(d){he(d&&d.message||(c==="codex"?"\u65E0\u6CD5\u542F\u52A8 Codex \u4F1A\u8BDD\u3002":"\u65E0\u6CD5\u542F\u52A8 Claude \u4F1A\u8BDD\u3002"),"error"),e.placeholder="\u8F93\u5165\u6D88\u606F",e.disabled=!1})}}function SM(e){e=e||{};var t=document.getElementById("welcome-input"),a=document.getElementById("input-box"),i=t&&t.value.trim()?t.value.trim():a?a.value.trim():"";if(s.selectedId){i&&xx(e);return}if(i&&Oh()){a&&(a.value=""),t&&(t.value=""),Uf(a),yx(i);return}var o=s.chatMode||"managed",c=Hr(),d=er();fetch("/api/commands",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({command:d,provider:d,cwd:c,mode:o,initialInput:i||void 0}))}).then(function(f){return f.json()}).then(function(f){return f.error?(he(f.error,"error"),null):(s.selectedId=f.id,Vt(),s.drafts[f.id]="",Da(),a&&(a.value=""),t&&(t.value=""),at(f),Ct(),Il(f.id),Gu(f.id),zi(f.id))}).catch(function(f){he(f&&f.message||(d==="codex"?"\u65E0\u6CD5\u542F\u52A8 Codex \u4F1A\u8BDD\u3002":"\u65E0\u6CD5\u542F\u52A8 Claude \u4F1A\u8BDD\u3002"),"error")})}function Il(e){var t=Ft(),a=s.sessions.find(function(C){return C.id===e}),i=document.getElementById("blank-chat"),o=document.getElementById("output"),c=document.getElementById("chat-output"),d=document.getElementById("stop-button"),f=document.getElementById("terminal-title"),m=document.getElementById("terminal-info"),h=document.querySelector(".session-summary-value"),g=yt(a);!t&&i&&i.classList.add("hidden"),!t&&o&&o.classList.toggle("hidden",g),!t&&c&&c.classList.remove("hidden"),g?s.currentView="chat":s.currentView="terminal";var y=a?es(a.command):"Wand",b=a?bl(a):"\u5F00\u59CB\u5BF9\u8BDD";f&&(f.textContent=y),m&&(m.textContent=b),h&&(h.textContent=y),g||s.terminal||Zo(),f0(),yr(!0),g||Ln("view-switch",{forceReplay:!0}),Ea("session:view")}function xx(e){e=e||{};var t=!!e.interrupt,a=document.documentElement.classList.contains("is-wand-embed-terminal");if(s.terminalInteractive&&!a)return he("\u7EC8\u7AEF\u4EA4\u4E92\u6A21\u5F0F\u5F00\u542F\u65F6\uFF0C\u8BF7\u76F4\u63A5\u5728\u7EC8\u7AEF\u4E2D\u8F93\u5165\u3002","info"),Promise.resolve();var i=document.getElementById("input-box"),o=i?i.value:"",c=_i(),d=s.pendingAttachments.length>0;if(o||d){var f=d&&s.selectedId?SN(s.selectedId).catch(function(m){he("\u9644\u4EF6\u4E0A\u4F20\u5931\u8D25: "+(m&&m.message||m),"error");var h=m instanceof Error?m:new Error(String(m));throw h.__wandToasted=!0,h}):Promise.resolve([]);return f.then(function(m){var h=BN(m),g=h+(o||(m.length?"\u8BF7\u67E5\u770B\u9644\u4EF6\u3002":""));m.length&&AN();var y=document.getElementById("todo-progress");if(y&&y.classList.add("hidden"),yt(c))return BM(g,i,c,{interrupt:t});var b=VM(c,g),C=!s.wsConnected;return C?(KM(b),i&&(i.value="",sa(i)),Kn(""),Promise.resolve()):UM(c).then(function(w){if(!w)return null;var x=s.currentView;if(w&&w.provider==="codex"&&s.selectedId!==w.id)throw new Error("Codex session changed before input send.");return q5(),YM(b,"enter_text",30,x).then(function(){i&&i.value===o&&(i.value="",sa(i)),Kn("")})}).catch(function(w){throw he(Ax(w),"error"),w&&(w.__wandToasted=!0),w})}).catch(function(m){throw m&&m.__wandToasted||he(Ax(m),"error"),m})}return Promise.resolve()}var Ex={},Fx=350;function BM(e,t,a,i){i=i||{};var o=!!i.interrupt;if(!s.selectedId||!e)return Promise.resolve();if(!a)return he("\u4F1A\u8BDD\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6216\u65B0\u5EFA\u4F1A\u8BDD\u3002","error"),Promise.resolve();var c=!!(a.structuredState&&a.structuredState.inFlight&&a.status==="running");if(c&&!o&&gx(a)===e.trim())return t&&(t.value="",sa(t)),Kn(""),he("\u4E0E\u4E0A\u4E00\u6761\u6D88\u606F\u76F8\u540C\uFF0C\u5DF2\u5FFD\u7565\uFF0C\u4E0D\u4F1A\u52A0\u5165\u6392\u961F\u3002","warning"),Pu("Enter \u53D1\u9001 \xB7 Shift+Enter \u6362\u884C"),Promise.resolve();var d=Date.now(),f=Ex[a.id]||0;if(d-f<Fx)return console.log("[wand] postStructuredInput: duplicate submit (within "+Fx+"ms) ignored for session",a.id),Promise.resolve();Ex[a.id]=d;var m=c&&o,h=c&&!o,g=Ks(Array.isArray(a.messages)?a.messages.slice():[]),y;if(h){var b=Array.isArray(a.queuedMessages)?a.queuedMessages.slice():[];b.push(e),y={id:a.id,queuedMessages:b},at(y);var C=s.sessions.find(function(D){return D.id===a.id})||a;s.currentMessages=Mn(C,Wn(C,C.output,!1)),Pu("\u5DF2\u52A0\u5165\u6392\u961F\u2026"),xn(!0),Oi(),he(b.length>1?"\u5DF2\u52A0\u5165\u6392\u961F\uFF08\u5171 "+b.length+" \u6761\u7B49\u5F85\uFF09":"\u5DF2\u52A0\u5165\u6392\u961F\uFF0C\u7B49\u5F53\u524D\u56DE\u590D\u5B8C\u6210\u4F1A\u81EA\u52A8\u53D1\u9001\u3002","info")}else{var w={role:"user",content:[{type:"text",text:e}]};g.push(w);var x=Object.assign({},a.structuredState||{},{inFlight:!0});at({id:a.id,status:"running",messages:g,structuredState:x}),s.currentMessages=Mn(Object.assign({},a,{status:"running",messages:g,structuredState:x}),g),Pu(m?"\u5DF2\u4E2D\u65AD\uFF0C\u6B63\u5728\u5904\u7406\u65B0\u6D88\u606F\u2026":"\u601D\u8003\u4E2D\u2026"),q5(),xn(!0),m&&he("\u5DF2\u4E2D\u65AD\u4E0A\u4E00\u6761\u56DE\u590D\uFF0C\u6B63\u5728\u5904\u7406\u65B0\u6D88\u606F\u2026","info")}t&&(t.value="",sa(t)),Kn("");var F=s.queueEpoch,A=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():Date.now().toString(36)+"-"+Math.random().toString(36).slice(2,10);return fetch("/api/structured-sessions/"+a.id+"/messages",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({input:e,interrupt:m||void 0,idempotencyKey:A})}).then(function(D){return D.ok?D.json():D.json().catch(function(){return{error:"\u8BF7\u6C42\u5931\u8D25"}}).then(function(B){var T=new Error(B&&B.error||"\u65E0\u6CD5\u53D1\u9001\u7ED3\u6784\u5316\u6D88\u606F\u3002");throw T.errorCode=B&&B.errorCode,T.httpStatus=D.status,T})}).then(function(D){if(D&&D.error)throw new Error(D.error);if(D&&D.id&&(s.queueEpoch>F&&D.queuedMessages&&delete D.queuedMessages,at(D),D.id===s.selectedId)){var B=s.sessions.find(function(T){return T.id===D.id})||D;s.currentMessages=Mn(B,Wn(B,D.output,!1)),xn(!0),Oi()}}).catch(function(D){if(D&&D.errorCode==="duplicate_idempotency_key"){he(D.message||"\u68C0\u6D4B\u5230\u91CD\u590D\u53D1\u9001\uFF0C\u5DF2\u62E6\u622A\u3002","warning"),Pu("Enter \u53D1\u9001 \xB7 Shift+Enter \u6362\u884C");return}if(h){var B=Array.isArray(a.queuedMessages)?a.queuedMessages.slice():[];if(at({id:a.id,queuedMessages:B}),a.id===s.selectedId){var T=s.sessions.find(function(I){return I.id===a.id})||a;s.currentMessages=Mn(T,Wn(T,T.output,!1)),xn(!0),Oi()}}else{var k=g.slice(0,-1);at({id:a.id,status:a.status,messages:k,structuredState:Object.assign({},a.structuredState||{},{inFlight:!1})}),a.id===s.selectedId&&(s.currentMessages=Mn(Object.assign({},a,{messages:k,structuredState:Object.assign({},a.structuredState||{},{inFlight:!1})}),k),xn(!0))}var j=D&&D.message||"",N=j==="Failed to fetch"||j==="NetworkError when attempting to fetch resource."||j==="Load failed"||/aborted|aborterror|networkerror|failed to fetch/i.test(j);N||he(D&&D.message||"\u65E0\u6CD5\u53D1\u9001\u7ED3\u6784\u5316\u6D88\u606F\u3002","error"),Pu("Enter \u53D1\u9001 \xB7 Shift+Enter \u6362\u884C")})}function Pu(e){var t=document.querySelector(".input-hint");t&&(t.textContent=e)}function Oi(){Gn()}var kM=10,Cx=26;function TM(e){if(typeof e!="string")return"";var t=e.replace(/\s+/g," ").trim();return t.length<=Cx?t:t.slice(0,Cx)+"\u2026"}function jM(){return!!s.queueBarExpanded}function MM(e){if(!!s.queueBarExpanded!=!!e){s.queueBarExpanded=!!e;var t=document.querySelector(".queue-bar");t&&t.classList.toggle("expanded",!!e)}}function OM(e,t,a){var i=e.length,o="queue-bar";a&&(o+=" queue-bar-capacity"),t&&(o+=" queue-bar-inflight");for(var c=t?"\u4E2D\u65AD\u5F53\u524D\u56DE\u590D\uFF0C\u7ACB\u5373\u53D1\u9001\u8FD9\u6761":"\u7ACB\u5373\u53D1\u9001\u8FD9\u6761",d="",f=0;f<i;f++){var m=e[f]==null?"":String(e[f]),h=TM(m),g=m+"\uFF08\u6309\u4F4F\u53EF\u62D6\u52A8\u8C03\u5E8F\uFF09";d+='<li class="queue-bar-item" data-index="'+f+'" data-action="drag" title="'+L(g)+'"><span class="queue-bar-item-index" aria-hidden="true">'+(f+1)+'</span><span class="queue-bar-item-text">'+L(h)+'</span><button type="button" class="queue-bar-item-promote" data-action="promote-item" title="'+L(c)+'" aria-label="\u7ACB\u5373\u53D1\u9001\u7B2C '+(f+1)+' \u6761"><svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M13 2 L4 14 L11 14 L10 22 L20 9 L13 9 Z"/></svg></button><button type="button" class="queue-bar-item-delete" data-action="delete" aria-label="\u5220\u9664\u7B2C '+(f+1)+' \u6761\u6392\u961F\u6D88\u606F" title="\u5220\u9664"><svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="6" y1="6" x2="18" y2="18"/><line x1="6" y1="18" x2="18" y2="6"/></svg></button></li>'}var y="";return i>=2&&(y='<div class="queue-bar-head"><span class="queue-bar-head-count">'+i+' \u6761\u6392\u961F</span><button type="button" class="queue-bar-clear-all" data-action="clear-all" title="\u6E05\u7A7A\u5168\u90E8\u6392\u961F" aria-label="\u6E05\u7A7A\u5168\u90E8 '+i+' \u6761\u6392\u961F\u6D88\u606F">\u6E05\u7A7A</button></div>'),'<div class="'+o+'" data-queue-bar="1" title="\u6392\u961F '+i+' \u6761\uFF08\u6309\u4F4F\u6C14\u6CE1\u53EF\u8C03\u5E8F\uFF09">'+y+'<ol class="queue-bar-list" data-queue-list="1">'+d+"</ol></div>"}function Gn(){var e=document.getElementById("queue-bar-host");if(e){var t=s.sessions.find(function(d){return d.id===s.selectedId}),a=t&&t.sessionKind==="structured",i=a?dv(t):[];if(i=Array.isArray(i)?i:[],!a||i.length===0){e.hidden=!0,e.innerHTML="",s.queueBarExpanded=!1;return}if(!s.queueBarDrag){e.hidden=!1;var o=!!(t.structuredState&&t.structuredState.inFlight&&t.status==="running"),c=i.length>=kM;e.innerHTML=OM(i,o,c)}}}function wf(e,t){at({id:e.id,queuedMessages:t});var a=s.sessions.find(function(i){return i.id===e.id})||e;s.currentMessages=Mn(a,Wn(a,a.output,!1)),xn(!0),Gn()}function _M(e){var t=s.sessions.find(function(d){return d.id===s.selectedId});if(t){var a=Array.isArray(t.queuedMessages)?t.queuedMessages.slice():[];if(!(e<0||e>=a.length)){var i=a.slice(),o=a.slice(0,e).concat(a.slice(e+1));at({id:t.id,queuedMessages:o});var c=s.sessions.find(function(d){return d.id===t.id})||t;s.currentMessages=Mn(c,Wn(c,c.output,!1)),xn(!0),Gn(),fetch("/api/structured-sessions/"+t.id+"/queued/"+e,{method:"DELETE",credentials:"same-origin"}).then(function(d){if(!d.ok)return d.json().catch(function(){return{}}).then(function(f){throw new Error(f&&f.error||"\u5220\u9664\u5931\u8D25")})}).catch(function(d){wf(t,i),he(d&&d.message||"\u5220\u9664\u6392\u961F\u6D88\u606F\u5931\u8D25\u3002","error")})}}}function NM(){var e=s.sessions.find(function(i){return i.id===s.selectedId});if(e){var t=Array.isArray(e.queuedMessages)?e.queuedMessages.slice():[];if(t.length!==0){s.queueBarExpanded=!1,at({id:e.id,queuedMessages:[]});var a=s.sessions.find(function(i){return i.id===e.id})||e;s.currentMessages=Mn(a,Wn(a,a.output,!1)),xn(!0),Gn(),fetch("/api/structured-sessions/"+e.id+"/queued",{method:"DELETE",credentials:"same-origin"}).then(function(i){if(!i.ok)return i.json().catch(function(){return{}}).then(function(o){throw new Error(o&&o.error||"\u6E05\u7A7A\u5931\u8D25")});he("\u5DF2\u6E05\u7A7A "+t.length+" \u6761\u6392\u961F\u6D88\u606F\u3002","info")}).catch(function(i){wf(e,t),he(i&&i.message||"\u6E05\u7A7A\u6392\u961F\u6D88\u606F\u5931\u8D25\u3002","error")})}}}function RM(e){if(!s.queueBarPromoting){var t=s.sessions.find(function(m){return m.id===s.selectedId});if(t){var a=Array.isArray(t.queuedMessages)?t.queuedMessages.slice():[];if(!(e<0||e>=a.length)){var i=a[e],o=a.slice(0,e).concat(a.slice(e+1)),c=a.slice(),d=!!(t.structuredState&&t.structuredState.inFlight&&t.status==="running");s.queueBarPromoting=!0,o.length===0&&(s.queueBarExpanded=!1),at({id:t.id,queuedMessages:o});var f=typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():Date.now().toString(36)+"-"+Math.random().toString(36).slice(2,10);he(d?"\u5DF2\u8BF7\u6C42\u4E2D\u65AD\u5F53\u524D\u56DE\u590D\uFF0C\u7ACB\u5373\u53D1\u9001\u8FD9\u6761\u3002":"\u5DF2\u7ACB\u5373\u53D1\u9001\u8FD9\u6761\u6D88\u606F\u3002","info"),fetch("/api/structured-sessions/"+t.id+"/queued/"+e+"/promote",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({expectedText:i,idempotencyKey:f})}).then(function(m){return m.ok?m.json():m.json().catch(function(){return{}}).then(function(h){throw new Error(h&&h.error||"\u7ACB\u5373\u53D1\u9001\u5931\u8D25")})}).then(function(m){if(m&&m.id&&(at(m),m.id===s.selectedId)){var h=s.sessions.find(function(g){return g.id===m.id})||m;s.currentMessages=Mn(h,Wn(h,m.output,!1)),xn(!0),Gn()}s.queueBarPromoting=!1}).catch(function(m){s.queueBarPromoting=!1,wf(t,c),he(m&&m.message||"\u7ACB\u5373\u53D1\u9001\u5931\u8D25\u3002","error")})}}}}function IM(e,t){var a=s.sessions.find(function(y){return y.id===s.selectedId});if(a){var i=Array.isArray(a.queuedMessages)?a.queuedMessages.slice():[];if(!(i.length<=1)&&t){var o=t.parentElement;if(o){var c=Number(t.getAttribute("data-index")),d=Array.prototype.slice.call(o.children),f=d.map(function(y){return y.getBoundingClientRect()}),m=3;f.length>=2&&(m=Math.max(0,f[1].top-f[0].top-f[0].height)),e.preventDefault();try{t.setPointerCapture(e.pointerId)}catch{}if(navigator&&navigator.vibrate)try{navigator.vibrate(8)}catch{}s.queueBarDrag={pointerId:e.pointerId,handleEl:t,itemEl:t,listEl:o,siblings:d,rects:f,origIndex:c,targetIndex:c,startY:e.clientY,gap:m,queueSnapshot:i},t.classList.add("dragging"),d.forEach(function(y){y!==t&&y.classList.add("queue-bar-item-sliding")});var h=function(y){zM(y)},g=function(y){HM(y)};s.queueBarDrag.moveHandler=h,s.queueBarDrag.upHandler=g,t.addEventListener("pointermove",h),t.addEventListener("pointerup",g),t.addEventListener("pointercancel",g)}}}}function LM(e,t,a,i){for(var o=a.length,c=[],d=0;d<o;d++)c.push(d);c.splice(e,1),c.splice(t,0,e);for(var f=a[0].top,m=a[0].top,h=1;h<o;h++)a[h].top<m&&(m=a[h].top);for(var g={},y=m,b=0;b<o;b++){var C=c[b];g[C]=y,y+=a[C].height+i}return g}function zM(e){var t=s.queueBarDrag;if(!(!t||e.pointerId!==t.pointerId)){e.preventDefault();var a=e.clientY-t.startY;t.itemEl.style.transform="translateY("+a+"px)";for(var i=t.rects[t.origIndex].top+t.rects[t.origIndex].height/2+a,o=t.origIndex,c=0;c<t.rects.length;c++)if(c!==t.origIndex){var d=t.rects[c].top+t.rects[c].height/2;c<t.origIndex&&i<d?o=Math.min(o,c):c>t.origIndex&&i>d&&(o=Math.max(o,c))}if(o!==t.targetIndex){t.targetIndex=o;var f=LM(t.origIndex,o,t.rects,t.gap);t.siblings.forEach(function(m,h){if(h!==t.origIndex){var g=f[h]-t.rects[h].top;m.style.transform=g?"translateY("+g+"px)":""}})}}}function HM(e){var t=s.queueBarDrag;if(!(!t||e&&e.pointerId!==t.pointerId)){try{t.handleEl.releasePointerCapture(t.pointerId)}catch{}t.handleEl.removeEventListener("pointermove",t.moveHandler),t.handleEl.removeEventListener("pointerup",t.upHandler),t.handleEl.removeEventListener("pointercancel",t.upHandler);var a=t.origIndex,i=t.targetIndex,o=t.queueSnapshot;if(t.siblings.forEach(function(h){h.style.transform="",h.classList.remove("queue-bar-item-sliding")}),t.itemEl.classList.remove("dragging"),s.queueBarDrag=null,a===i){Gn();return}for(var c=[],d=0;d<o.length;d++)c.push(d);c.splice(a,1),c.splice(i,0,a);var f=c.map(function(h){return o[h]}),m=s.sessions.find(function(h){return h.id===s.selectedId});if(!m){Gn();return}at({id:m.id,queuedMessages:f}),Gn(),fetch("/api/structured-sessions/"+m.id+"/queued",{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({order:c})}).then(function(h){if(!h.ok)return h.json().catch(function(){return{}}).then(function(g){throw new Error(g&&g.error||"\u6392\u5E8F\u5931\u8D25")})}).catch(function(h){wf(m,o),he(h&&h.message||"\u8C03\u6574\u6392\u961F\u987A\u5E8F\u5931\u8D25\u3002","error")})}}function PM(){var e=document.getElementById("queue-bar-host");!e||e.__queueDelegated||(e.__queueDelegated=!0,e.addEventListener("click",function(t){var a=t.target,i=a&&a.closest?a.closest("[data-action]"):null;if(i&&e.contains(i)){var o=i.getAttribute("data-action");if(o==="drag")return;if(t.preventDefault(),t.stopPropagation(),o==="promote-item"){var c=i.closest(".queue-bar-item");c&&RM(Number(c.getAttribute("data-index")))}else if(o==="delete"){var d=i.closest(".queue-bar-item");d&&_M(Number(d.getAttribute("data-index")))}else o==="clear-all"&&NM();return}}),e.addEventListener("pointerdown",function(t){if(!(t.button!==void 0&&t.button!==0)){var a=t.target;if(!(a&&a.closest&&a.closest('[data-action="delete"], [data-action="promote-item"], [data-action="clear-all"], [data-action="expand"]'))){var i=a&&a.closest?a.closest(".queue-bar-item"):null;i&&IM(t,i)}}}),e.addEventListener("keydown",function(t){t.key==="Escape"&&jM()&&(t.stopPropagation(),MM(!1))}))}function Mn(e,t){var a=Array.isArray(t)?Ks(t):[],i=Array.isArray(a)?a.slice():[];if(!e||e.sessionKind!=="structured")return i;if(e.structuredState&&e.structuredState.inFlight){var o=i[i.length-1];(!o||o.role!=="assistant")&&i.push({role:"assistant",content:[{type:"text",text:"",__processing:!0}]})}return i}function Dx(){var e=s.sessions.find(function(t){return t.id===s.selectedId});Jc(e),Oi()}function Ax(e){var t=_i(),a=t&&t.provider==="codex";return e&&(e.errorCode==="SESSION_NOT_RUNNING"||e.errorCode==="SESSION_NO_PTY")?a?"Codex \u4F1A\u8BDD\u5DF2\u7ED3\u675F\uFF1B\u82E5\u5B58\u5728 Codex \u5386\u53F2\u4F1A\u8BDD\uFF0C\u5C06\u5728\u4F60\u4E0B\u6B21\u53D1\u9001\u6D88\u606F\u65F6\u81EA\u52A8\u6062\u590D\u3002":"\u4F1A\u8BDD\u5DF2\u7ED3\u675F\uFF1B\u82E5\u5B58\u5728 Claude \u5386\u53F2\u4F1A\u8BDD\uFF0C\u5C06\u5728\u4F60\u4E0B\u6B21\u53D1\u9001\u6D88\u606F\u65F6\u81EA\u52A8\u6062\u590D\u3002":e&&e.errorCode==="SESSION_NOT_FOUND"?"\u4F1A\u8BDD\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6216\u65B0\u5EFA\u4F1A\u8BDD\u3002":e&&e.message||(a?"Codex \u4F1A\u8BDD\u6682\u4E0D\u53EF\u7528\uFF1B\u82E5\u5B58\u5728 Codex \u5386\u53F2\u4F1A\u8BDD\uFF0C\u5C06\u81EA\u52A8\u5C1D\u8BD5\u6062\u590D\u3002":"\u4F1A\u8BDD\u6682\u4E0D\u53EF\u7528\uFF1B\u82E5\u5B58\u5728 Claude \u5386\u53F2\u4F1A\u8BDD\uFF0C\u5C06\u81EA\u52A8\u5C1D\u8BD5\u6062\u590D\u3002")}function Sx(e){var t=new Error(e&&e.error||"\u4F1A\u8BDD\u5DF2\u7ED3\u675F\u3002");return e&&typeof e=="object"&&(t.errorCode=e.errorCode||null,t.sessionId=e.sessionId||s.selectedId||null,t.sessionStatus=Object.prototype.hasOwnProperty.call(e,"sessionStatus")?e.sessionStatus:null),t}function Bx(e){return e&&(e.errorCode==="SESSION_NOT_RUNNING"||e.errorCode==="SESSION_NO_PTY"||e.errorCode==="SESSION_NOT_FOUND")}function qM(e,t){e&&at({id:e,status:t||"exited"})}function _h(e){return!!(e&&!yt(e)&&(e.provider==="claude"||e.provider==="codex")&&e.status!=="running"&&e.claudeSessionId)}function UM(e,t){if(!e)return he("\u4F1A\u8BDD\u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6216\u65B0\u5EFA\u4F1A\u8BDD\u3002","error"),Promise.resolve(null);if(e.status==="running")return Promise.resolve(e);if(!_h(e)){var a=e&&e.provider==="codex"?"Codex":"Claude";return he("\u8BE5\u4F1A\u8BDD\u6CA1\u6709\u53EF\u6062\u590D\u7684 "+a+" \u5386\u53F2\u4E0A\u4E0B\u6587\uFF0C\u8BF7\u65B0\u5EFA\u4F1A\u8BDD\u3002","error"),Promise.resolve(null)}return Lx(e.id,t).then(function(i){return i?(at(i),Ct(),Gu(i.id),zi(i.id).then(function(){return yr(!0),i})):null})}function VM(e,t){return[t,"\r"]}function YM(e,t,a,i){var o=Array.isArray(e)?e.filter(function(d){return!!d}):[];if(o.length===0)return Promise.resolve();var c=typeof a=="number"?a:0;return o.reduce(function(d,f,m){return d.then(function(){return m>0&&c>0?new Promise(function(h){setTimeout(h,c)}).then(function(){return gr(f,m===o.length-1?t:void 0,i)}):gr(f,m===o.length-1?t:void 0,i)})},Promise.resolve())}var GM=5e3,WM=100;function Nh(e){e&&(s.pendingMessages.length>=WM&&s.pendingMessages.shift(),s.pendingMessages.push({input:e,at:Date.now()}))}function KM(e){var t=Array.isArray(e)?e.filter(function(a){return!!a}):[];t.forEach(function(a){Nh(a)})}function QM(e){if(!(typeof e!="string"||!e)){var t=e.replace(/\x1b\[200~/g,"").replace(/\x1b\[201~/g,"");/(?:^|\n)\s*\/clear\s*(?:\r|\n|$)/.test(t)&&typeof s<"u"&&s&&(s.terminalOutputMarker=(s.terminalOutput&&s.terminalOutput.length)|0)}}function gr(e,t,a){return!e||!s.selectedId?Promise.resolve():(QM(e),s.messageQueue.push(e),s.inputQueue=s.inputQueue.then(function(){return XM(e,t,a).finally(function(){var i=s.messageQueue.indexOf(e);i>-1&&s.messageQueue.splice(i,1)})}),s.inputQueue)}function XM(e,t,a){if(!s.selectedId)return Promise.resolve();var i=s.selectedId,o=a||s.currentView;return xM()?s.wsConnected?fetch("/api/sessions/"+i+"/input",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({input:e,view:o,shortcutKey:t||void 0})}).then(function(c){return c.ok?c.json():c.json().catch(function(){return{error:"\u8BF7\u6C42\u5931\u8D25"}}).then(function(d){var f=Sx(d);throw f.httpStatus=c.status,console.error("[wand] postInput: request failed",{status:c.status,errorCode:f.errorCode,message:f.message,sessionId:i}),Bx(f)&&qM(i,f.sessionStatus||"exited"),f})}).then(function(c){return c&&c.id&&(at(c),c.id===s.selectedId&&(c.messages&&c.messages.length>0&&(s.currentMessages=c.messages),xn(!0))),c}):(Nh(e),console.log("[wand] postInput: WebSocket disconnected, queued message",{sessionId:s.selectedId,inputLength:e.length}),Promise.resolve()):s.wsConnected?(console.warn("[wand] postInput: session not running, skipping send",{sessionId:s.selectedId}),he("\u4F1A\u8BDD\u672A\u8FD0\u884C\uFF0C\u6B63\u5728\u7B49\u5F85\u81EA\u52A8\u6062\u590D\u540E\u91CD\u8BD5\u3002","info"),Promise.resolve()):(Nh(e),console.log("[wand] postInput: session not running, queued for reconnect",{sessionId:s.selectedId,inputLength:e.length}),Promise.resolve())}function _i(){return s.sessions.find(function(e){return e.id===s.selectedId})||null}function Rh(){return!!s.selectedId&&s.currentView==="terminal"}function ZM(e){return!(!s.terminal||!e||e!==s.selectedId||s.terminalSessionId&&s.terminalSessionId!==e)}function kx(e){if(!s.terminalInteractive||!Rh()||e.defaultPrevented||e.isComposing)return!1;var t=e.target;return t?!(document.documentElement.classList.contains("is-wand-embed-terminal")&&t.closest&&t.closest("#input-box")||t.closest&&t.closest("#mini-keyboard")||rO(t)):!0}var JM={Esc:"escape",ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",Enter:"enter",Tab:"tab",Backspace:"backspace",Home:"home",End:"end",PageUp:"pageup",PageDown:"pagedown",Delete:"delete",Insert:"insert"," ":"space"},$M={space:" ",tab:" ",shift_tab:"\x1B[Z",backspace:"\x7F",home:"\x1B[H",end:"\x1B[F",pageup:"\x1B[5~",pagedown:"\x1B[6~",delete:"\x1B[3~",insert:"\x1B[2~"},Tx={" ":0,"[":27,"\\":28,"]":29,"^":30,_:31},eO=400,tO=10,nO=8,xf=54,Ni=8,Ih=[{key:"enter",label:"Enter"},{key:"ctrl_c",label:"Ctrl+C"},{key:"escape",label:"Esc"},{key:"shift_tab",label:"Shift+Tab"}],aO=new Set(["mini-keyboard-fab","mini-keyboard-toggle","terminal-interactive-toggle"]);function rO(e){return e?aO.has(e.id)?!0:!!(e.closest&&e.closest('[role="dialog"], [role="alertdialog"]')):!1}var iO=new Set(["ctrl","alt","shift"]);function jx(e){return iO.has(e)}function uO(e){return $M[e]||""}function oO(e){var t=e.toLowerCase();return t>="a"&&t<="z"?String.fromCharCode(t.charCodeAt(0)-96):Object.prototype.hasOwnProperty.call(Tx,t)?String.fromCharCode(Tx[t]):""}function sO(e){return JM[e.key]||e.key}function lO(e,t){return{ctrl:e.ctrlKey,alt:e.altKey,shift:e.shiftKey&&(t.length===1||t==="tab"),meta:e.metaKey}}function Mx(e,t){e&&gr(e,t).catch(function(){})}function cO(){Yx()}function Lh(e){s.keyboardPopupOpen=!1,e!==!1&&Cf(),pO()}function dO(){Rh()&&Jo(!s.terminalInteractive)}function Jo(e){var t=!!e&&Rh();s.terminalInteractive!==t&&(s.terminalInteractive=t,t?(mO(),Lh(!1),cO(),he("\u7EC8\u7AEF\u4EA4\u4E92\u6A21\u5F0F\u5DF2\u5F00\u542F","info")):(hO(),Cf()),Ef())}function Ox(){var e=s.sessions.find(function(a){return a.id===s.selectedId}),t=!e||e.status!=="running"||s.currentView!=="terminal";if(t&&s.terminalInteractive){Jo(!1);return}(!e||s.currentView!=="terminal")&&s.keyboardPopupOpen&&(s.keyboardPopupOpen=!1),Ef()}function Ef(){var e=s.sessions.find(function(F){return F.id===s.selectedId}),t=yt(e),a=e&&e.provider==="codex",i=t?!!(e&&e.structuredState&&e.structuredState.inFlight):!!e&&e.status==="running",o=document.getElementById("input-box"),c=["terminal-interactive-toggle-top"];c.forEach(function(F){var A=document.getElementById(F);if(A){A.classList.toggle("active",s.terminalInteractive),A.classList.toggle("is-on",s.terminalInteractive),A.classList.toggle("hidden",t||s.currentView!=="terminal"||!e),A.setAttribute("aria-pressed",s.terminalInteractive?"true":"false");var D=A.querySelector(".plus-popover-toggle-state");D&&(D.textContent=s.terminalInteractive?"\u5F00":"\u5173")}});var d=document.querySelector(".input-hint");d&&(d.classList.toggle("hidden",t?!0:s.currentView==="terminal"),!t&&e&&(d.textContent=a?"Enter \u53D1\u9001 \xB7 chat \u4E3A\u89E3\u6790\u89C6\u56FE\uFF0Cterminal \u4E3A\u539F\u59CB\u8F93\u51FA":"Enter \u53D1\u9001 \xB7 Shift+Enter \u6362\u884C"));var f=!t&&!i&&_h(e);o&&(o.placeholder=yE(e,s.terminalInteractive),o.disabled=!t&&!!e&&!i&&!f,o.setAttribute("aria-disabled",o.disabled?"true":"false"),o.readOnly=!1,o.classList.toggle("is-terminal-passthrough",!!s.terminalInteractive&&!document.documentElement.classList.contains("is-wand-embed-terminal")));var m=document.getElementById("voice-record-btn");m&&(m.disabled=s.terminalInteractive,m.setAttribute("aria-disabled",m.disabled?"true":"false")),s.terminalInteractive&&Ot.recording&&(Ot.recording=!1,mx());var h=document.getElementById("send-input-button"),g=t&&i;h&&(h.disabled=!t&&!!e&&!i&&!f,h.setAttribute("title",t?g?"\u6392\u961F\u53D1\u9001\uFF08\u5F53\u524D\u56DE\u590D\u7ED3\u675F\u540E\u5904\u7406\uFF09":"\u53D1\u9001":a?i?"\u53D1\u9001\u7ED9 Codex":"Codex \u4F1A\u8BDD\u5DF2\u7ED3\u675F":!e||i||f?"\u53D1\u9001":"\u4F1A\u8BDD\u5DF2\u7ED3\u675F"),h.classList.toggle("queue-mode",g));var y=document.getElementById("stop-button");if(y){var b=E0(e);y.classList.toggle("hidden",!b.active)}var C=document.getElementById("stop-button");if(C){var w=E0(e);C.classList.toggle("hidden",!w.active)}var x=document.getElementById("output");x&&x.classList.toggle("interactive",!t&&s.terminalInteractive),G6()}function Ff(){var e=window.getSelection&&window.getSelection();if(!e||e.isCollapsed)return!1;var t=document.getElementById("output");if(!t)return!1;var a=e.anchorNode;return a&&a.nodeType===3&&(a=a.parentNode),!!(a&&t.contains(a))}function zh(e){if(kx(e)&&!e.metaKey){var t=sO(e);if(t){var a=lO(e,t);if(!jx(t)&&!(a.ctrl&&t.length===1&&t.toLowerCase()==="c"&&Ff())){var i=_x(t,a);i&&(e.preventDefault(),Mx(i,t))}}}}function fO(){s.terminal&&Bj(500)}function pO(){Al()}function vO(){s.keyboardPopupOpen=!1,Ef()}function mO(){document.addEventListener("keydown",zh,!0)}function hO(){document.removeEventListener("keydown",zh,!0)}function _x(e,t){var a=t||{ctrl:!1,alt:!1,shift:!1};if(jx(e))return"";if(e==="tab"&&a.shift)return"\x1B[Z";var i=uO(e);if(i)return i;if(e.indexOf("ctrl_")===0)return String.fromCharCode(e.charCodeAt(e.length-1)-96);var o=Ll(e);if(o)return o;if(!e)return"";var c=e.length===1?e:"";return c?(a.shift&&(c=c.toUpperCase()),a.ctrl?oO(c):a.alt?"\x1B"+c:c):""}function Cf(){s.modifiers.ctrl=!1,s.modifiers.alt=!1,s.modifiers.shift=!1,gO()}function gO(){var e=document.getElementById("mini-keyboard");e&&["ctrl","alt","shift"].forEach(function(t){var a=e.querySelector('[data-key="'+t+'"]');a&&a.classList.toggle("active",!!s.modifiers[t])})}function Ll(e){switch(e){case"yes":return"y\r";case"no":return"n\r";case"up":return"\x1B[A";case"down":return"\x1B[B";case"left":return"\x1B[D";case"right":return"\x1B[C";case"enter":return"\r";case"ctrl_c":return"";case"ctrl_d":return"";case"ctrl_l":return"\f";case"ctrl_u":return"";case"ctrl_k":return"\v";case"ctrl_w":return"";case"ctrl_z":return"";case"escape":return"\x1B";default:return""}}function yO(){if(s.pendingMessages.length!==0){var e=_i();if(yt(e)){s.pendingMessages=[];return}var t=Date.now(),a=[],i=0;s.pendingMessages.forEach(function(c){if(typeof c=="string"){a.push(c);return}if(!(!c||typeof c.input!="string")){if(t-(c.at||0)>GM){i++;return}a.push(c.input)}}),s.pendingMessages=[],i>0&&console.log("[wand] flushPendingMessages: dropped "+i+" stale input(s)");var o=Promise.resolve();a.forEach(function(c){o=o.then(function(){return bO(c).catch(function(){})})})}}function bO(e){if(!e||!s.selectedId)return Promise.resolve();var t=s.selectedId;return fetch("/api/sessions/"+t+"/input",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({input:e,view:s.currentView})}).then(function(a){return a.ok?a.json():a.json().catch(function(){return{error:"\u8BF7\u6C42\u5931\u8D25"}}).then(function(i){var o=Sx(i);if(o.httpStatus=a.status,Bx(o))return console.log("[wand] sendInputDirect: session unavailable, dropping",{sessionId:t,errorCode:o.errorCode}),null;throw o})}).then(function(a){return a&&a.id&&(at(a),a.id===s.selectedId&&(a.messages&&a.messages.length>0&&(s.currentMessages=a.messages),xn(!0))),a})}function Hh(){if(s.selectedId){var e=s.selectedId;Ah(Nn("stop.confirm.message"),{title:Nn("stop.confirm.title"),danger:!0,okLabel:Nn("stop.confirm.ok"),cancelLabel:Nn("stop.confirm.cancel")}).then(function(t){t&&s.selectedId===e&&fetch("/api/sessions/"+e+"/stop",{method:"POST",credentials:"same-origin"}).then(Ii)})}}function Df(e){var t=Ft()?null:document.querySelector('.session-item[data-session-id="'+e+'"]'),a=s.sessions.find(function(o){return o.id===e}),i=a&&a.claudeSessionId;t&&t.classList.add("deleting"),setTimeout(function(){fetch("/api/sessions/"+e,{method:"DELETE",credentials:"same-origin"}).then(function(o){return o.json()}).then(function(o){if(o&&o.error)throw new Error(o.error);return s.selectedId===e&&(s.selectedId=null,Vt()),i&&(s.claudeHistory=s.claudeHistory.filter(function(c){return c.claudeSessionId!==i}),s.codexHistory=s.codexHistory.filter(function(c){return c.claudeSessionId!==i})),Ii()}).catch(function(){t&&t.classList.remove("deleting");var o=document.getElementById("action-error");Ja(o,"\u65E0\u6CD5\u5220\u9664\u4F1A\u8BDD\u3002")})},250)}function Nx(e,t){t&&t.classList.add("deleting"),setTimeout(function(){fetch("/api/claude-history/"+encodeURIComponent(e),{method:"DELETE",credentials:"same-origin"}).then(function(a){return a.json()}).then(function(a){if(a&&a.error)throw new Error(a.error);s.claudeHistory=s.claudeHistory.filter(function(i){return i.claudeSessionId!==e}),delete s.selectedClaudeHistoryIds[e],Ct()}).catch(function(){t&&t.classList.remove("deleting");var a=document.getElementById("action-error");Ja(a,"\u65E0\u6CD5\u5220\u9664\u4F1A\u8BDD\u3002")})},250)}function wO(e,t){Nx(e,t)}function xO(e,t,a){e&&fetch("/api/claude-history?cwd="+encodeURIComponent(e),{method:"DELETE",credentials:"same-origin"}).then(function(i){return i.json()}).then(function(i){if(i&&i.error)throw new Error(i.error);s.claudeHistory=s.claudeHistory.filter(function(o){return o.cwd!==e}),Ct()}).catch(function(){Rx(a,!1);var i=document.getElementById("action-error");Ja(i,"\u65E0\u6CD5\u6E05\u7406\u8BE5\u76EE\u5F55\u7684\u5386\u53F2\u4F1A\u8BDD\u3002")})}function Rx(e,t){e.forEach(function(a){a.classList.toggle("deleting",t)})}function EO(e){return Array.prototype.slice.call(document.querySelectorAll('.claude-history-item[data-cwd="'+window.CSS.escape(String(e))+'"]'))}var Ix=null,zl=null;function Hl(){if(zl){zl.classList.remove("swiped");var e=zl.querySelector(".session-item-content");e&&(e.style.transform=""),zl=null}}function FO(e){Ix=null,zl=null}var Ph=!1;function Lx(e,t){return!e||Ph?Promise.resolve(null):(Ph=!0,fetch("/api/sessions/"+encodeURIComponent(e)+"/resume",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({mode:s.chatMode||s.config.defaultMode||"default"}))}).then(function(a){return a.json()}).then(function(a){return a.error?(t?Ja(t,a.error):he(a.error,"error"),null):(s.selectedId=a.id,Vt(),s.drafts[a.id]="",a)}).catch(function(a){var i=a&&a.message||"\u65E0\u6CD5\u6062\u590D\u4F1A\u8BDD\u3002";return t?Ja(t,i):he(i,"error"),null}).finally(function(){Ph=!1}))}function Af(e){return!e||!e.id?Promise.resolve():(s.selectedId=e.id,Vt(),s.currentMessages=[],Sl(),Da(),Il(e.id),at(e),Ct(),Gu(e.id),zi(e.id).then(function(){yr(!0)}))}function qh(e){return Lx(e).then(function(t){return t?(t.claudeSessionId&&(t.provider==="codex"?s.codexHistory=s.codexHistory.filter(function(a){return a.claudeSessionId!==t.claudeSessionId}):s.claudeHistory=s.claudeHistory.filter(function(a){return a.claudeSessionId!==t.claudeSessionId})),Af(t).then(function(){return t})):null})}function CO(e){e.disabled=!0,qh(e.dataset.sessionId).finally(function(){e.disabled=!1})}function DO(e){var t=e.dataset.claudeSessionId,a=e.dataset.cwd;t&&(e.disabled=!0,Uh("codex",t,a).finally(function(){e.disabled=!1}))}function Sf(e,t){return fetch("/api/codex-sessions/"+encodeURIComponent(e)+"/resume",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({mode:s.chatMode||s.config&&s.config.defaultMode||"default",cwd:t}))}).then(function(a){return a.json()}).then(function(a){return a.error?(he(a.error,"error"),null):a}).catch(function(a){return he(a&&a.message||"\u65E0\u6CD5\u6062\u590D\u4F1A\u8BDD\u3002","error"),null})}function AO(e){var t=e.dataset.claudeSessionId;t&&Ti("\u786E\u8BA4\u5220\u9664\u8FD9\u6761 Codex \u4F1A\u8BDD\u5417\uFF1F",{title:"\u5220\u9664\u4F1A\u8BDD"}).then(function(a){if(a){var i=e.closest(".session-item");i&&(i.style.opacity="0.5"),zx(t).catch(function(){i&&(i.style.opacity="1")})}})}function SO(e){var t=e.dataset.claudeSessionId,a=e.dataset.cwd;t&&(e.disabled=!0,Uh("claude",t,a).finally(function(){e.disabled=!1}))}function Bf(e,t){return fetch("/api/claude-sessions/"+encodeURIComponent(e)+"/resume",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(Pi({mode:s.chatMode||s.config&&s.config.defaultMode||"default",cwd:t}))}).then(function(a){return a.json()}).then(function(a){return a.error?(he(a.error,"error"),null):a}).catch(function(a){return he(a&&a.message||"\u65E0\u6CD5\u6062\u590D\u4F1A\u8BDD\u3002","error"),null})}function Uh(e,t,a){var i=e==="codex"?Sf(t,a):Bf(t,a);return i.then(function(o){return!o||!o.id?null:(e==="codex"?s.codexHistory=s.codexHistory.filter(function(c){return c.claudeSessionId!==t}):s.claudeHistory=s.claudeHistory.filter(function(c){return c.claudeSessionId!==t}),s.selectedId=o.id,Vt(),s.drafts[o.id]="",Af(o).then(function(){return nr(),o}))})}function zx(e){return fetch("/api/codex-history/"+encodeURIComponent(e),{method:"DELETE",credentials:"same-origin"}).then(function(t){return t.json()}).then(function(t){if(!t||t.ok!==!0)throw new Error(t&&t.error||"\u65E0\u6CD5\u5220\u9664\u4F1A\u8BDD\u3002");return s.codexHistory=s.codexHistory.filter(function(a){return a.claudeSessionId!==e}),Ct(),t})}function Pl(){return"ontouchstart"in window||navigator.maxTouchPoints>0}function yr(e){if(!s.terminalInteractive){var t=document.getElementById("input-box");!t||!s.selectedId||document.activeElement!==t&&(e&&Pl()||Ux(t))}}function BO(){var e=document.querySelector(".input-panel");e&&e.style.removeProperty("--keyboard-offset")}function kO(){var e=document.querySelector(".input-panel");e&&e.style.removeProperty("--keyboard-offset")}function Hx(e){if(e){var t=e.selectionStart,a=e.selectionEnd;kf(e),typeof t=="number"&&typeof a=="number"&&e.setSelectionRange(t,a)}}function Px(e){!e||e.dataset.touchScrollBound==="true"||(e.dataset.touchScrollBound="true",e.addEventListener("touchstart",function(){e.scrollHeight<=e.clientHeight+1||(e.scrollTop<=0?e.scrollTop=1:e.scrollTop+e.clientHeight>=e.scrollHeight&&(e.scrollTop=Math.max(1,e.scrollHeight-e.clientHeight-1)))},{passive:!0}))}function qx(e){e&&(sa(e),Hx(e))}function TO(e){var t=e&&e.target?e.target:document.getElementById("input-box");t&&(BO(),qx(t))}function jO(e){var t=e&&e.target?e.target:document.getElementById("input-box");kO(),t&&sa(t),z6(2200,t);var a=[80,200,380,620,900];a.forEach(function(i,o){setTimeout(function(){Wo(!1),t&&t.value&&sa(t),o===1&&Pl()&&(Ln("keyboard-blur",{forceReplay:!0}),Ca("keyboard"))},i)})}function MO(e){e&&(e.setSelectionRange(e.value.length,e.value.length),Hx(e))}function Ux(e){e&&(e.focus({preventScroll:!0}),MO(e))}function OO(e){Px(e),qx(e)}function _O(e){OO(e)}function NO(e,t){if(!e||!t||document.activeElement!==t)return!1;var a=window.innerHeight-e.height-e.offsetTop;if(a<=50)return!1;var i=t.getBoundingClientRect();return i.bottom>e.height-12}function kf(e){if(e){var t=e.scrollHeight>e.clientHeight+1;if(!t){e.scrollTop=0;return}e.scrollTop=e.scrollHeight}}function Vx(){if(s.terminalInteractive){Yx();return}if(!Pl()){var e=document.getElementById("input-box");!e||!s.selectedId||document.activeElement===e||Ux(e)}}function Yx(){var e=document.getElementById("output");e&&(e.setAttribute("tabindex","0"),e.focus(),s.terminal&&s.terminal.focus&&s.terminal.focus())}function RO(){var e=document.querySelector(".input-panel"),t=document.querySelector(".chat-messages");if("virtualKeyboard"in navigator){var a=navigator.virtualKeyboard;a.addEventListener("geometrychange",function(){e&&e.style.removeProperty("padding-bottom")})}var i=document.getElementById("output");i&&i.addEventListener("click",function(){Vx()}),t&&t.addEventListener("click",function(o){var c=o.target;c.tagName!=="A"&&c.tagName!=="BUTTON"&&!c.closest("button")&&!c.closest("[data-tool-toggle]")&&Vx()}),document.addEventListener("click",function(o){if(Pl()){var c=document.getElementById("input-box");if(!(!c||document.activeElement!==c)){var d=o.target;!d||typeof d.closest!="function"||d.closest(".input-panel")||d.closest("#mini-keyboard")||d.closest("#mini-keyboard-fab")||d.closest("#mini-keyboard-toggle")||d.closest("#terminal-interactive-toggle")||d.closest(".wand-joystick-root")||c.blur()}}},!0)}function Vh(){try{window.scrollTo(0,0)}catch{}document.scrollingElement&&(document.scrollingElement.scrollTop=0),document.documentElement&&(document.documentElement.scrollTop=0),document.body&&(document.body.scrollTop=0)}function xn(e){s.renderPending&&!e||(s.renderPending=!0,e?(Tf(!0),s.renderPending=!1):requestAnimationFrame(function(){Tf(!1),s.renderPending=!1}))}s.chatRenderTimer=null;function Yh(e){if(!(s.chatRenderTimer&&!e)){if(s.chatRenderTimer&&clearTimeout(s.chatRenderTimer),e){s.chatRenderTimer=null,xn();return}try{window.__scheduleChatRender=function(){Yh(!0)}}catch{}var t=s.sessions.find(function(o){return o.id===s.selectedId}),a=t&&t.status==="running"&&t.sessionKind!=="structured",i=a?J6:$6;s.chatRenderTimer=setTimeout(function(){s.chatRenderTimer=null;var o=s.sessions.find(function(c){return c.id===s.selectedId});o&&(s.currentMessages=Mn(o,Wn(o,o.output,!0))),xn()},i)}}function IO(e,t){if(!e||!t||t.length===0)return[];function a(A){return A.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g,"")}for(var i=a(e),o=[],c=[],d=0;d<t.length;d++)if(t[d].role==="user"){var f="",m=t[d].content;if(typeof m=="string")f=m;else if(Array.isArray(m)){for(var h=0;h<m.length;h++)if(m[h].type==="text"){f=m[h].text;break}}f&&c.push({text:f,index:d})}for(var g=0,d=0;d<c.length;d++){var y=c[d],b=i.indexOf("\u276F "+y.text,g);if(b===-1&&(b=i.indexOf(`
2840
2840
  \u276F `+y.text,g),b!==-1&&(b+=1)),b>g){for(var C=i.substring(g,b),w=C.split(`
2841
2841
  `),x=[],h=0;h<w.length;h++){var F=w[h].trim();!F||F.startsWith("\u2500\u2500\u2500\u2500")||F==="\u276F"||F==="?"||F===""||F.includes("Claude Code v")||F.includes("Opus")&&F.includes("with")||F.includes("Sonnet")&&F.includes("with")||F.includes("API Usage")||F.includes("Billing")||F.includes("for shortcuts")||F.includes("/effort")||F.match(/^[▸▐▝▘▗▖█▌▍▎▏▔▁▂▃▄▅▆▇██]/)||F.match(/^[▸▐▝▘▗▖█▌▍▎▏▔▁▂▃▄▅▆▇██]{3,}/)||F.length>3&&x.push(F)}x.length>0&&o.push({beforeMessage:y.index,content:x.join(`