claude-simple 0.2.33 → 0.2.34

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.
@@ -30,7 +30,7 @@ var Ld=Object.defineProperty;var W=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(
30
30
  </div>
31
31
  </button>`).join(""),Yi()}}function ln(){i("notifications-menu")?.classList.add("hidden"),i("notifications-backdrop")?.classList.add("hidden"),i("btn-notifications")?.setAttribute("aria-expanded","false")}function ou(){el(),i("notifications-menu")?.classList.remove("hidden"),i("notifications-backdrop")?.classList.remove("hidden"),i("btn-notifications")?.setAttribute("aria-expanded","true")}function tl(){let e=i("notifications-menu");e&&(e.classList.contains("hidden")?ou():ln())}function Xi(e){let t=new Map;for(let n of e||[])n?.id&&t.set(String(n.id),n);Pe=[...t.values()].sort((n,s)=>(B(s.createdAt)||0)-(B(n.createdAt)||0)),rn=Pe.reduce((n,s)=>n+(s.unread?1:0),0),xs()}async function ya(){try{let e=await x("GET","/api/notifications?limit=80");Pe=Array.isArray(e?.notifications)?e.notifications:[],rn=Number(e?.unreadCount)||Pe.reduce((t,n)=>t+(n.unread?1:0),0),xs()}catch{Pe=[],rn=0,xs()}}async function Zi(e=null){let t=await x("POST","/api/notifications/read",e?.length?{ids:e}:{});Pe=Array.isArray(t?.notifications)?t.notifications:Pe.map(n=>!e||e.includes(n.id)?{...n,unread:!1}:n),rn=Number(t?.unreadCount)||Pe.reduce((n,s)=>n+(s.unread?1:0),0),xs()}function ru(e){if(!(typeof Notification>"u")&&document.visibilityState!=="visible"&&Notification.permission==="granted")try{let t=new Notification(e.title||"Session done",{body:e.body||e.projectName||e.sessionId||"",tag:e.id});t.onclick=()=>{window.focus(),t.close()}}catch{}}function wa(e){if(!e?.id)return;if(Pe.find(n=>n.id===e.id)){Xi([e,...Pe.filter(n=>n.id!==e.id)]);return}Xi([e,...Pe]),ru(e)}function nl(e={}){ir=typeof e.openSession=="function"?e.openSession:null,xs(),ya(),typeof Notification<"u"&&Notification.permission==="default"&&document.addEventListener("click",()=>{try{Notification.requestPermission().catch(()=>{})}catch{}},{once:!0}),b.on("click","#notifications-backdrop",t=>{t.preventDefault(),t.stopPropagation(),ln()}),b.on("click","#btn-notifications-read-all",async t=>{t.preventDefault(),t.stopPropagation(),await Zi()}),b.on("click","[data-notification-id]",async(t,n)=>{let s=n.dataset.notificationId;s&&(await Zi([s]),ln(),!(!ir||!n.dataset.notificationSession)&&ir(n.dataset.notificationSession,n.dataset.notificationCwd||null,null,n.dataset.notificationAgent||"claude",n.dataset.notificationMachine||null))}),document.addEventListener("click",t=>{let n=i("notifications-menu"),s=i("btn-notifications"),a=t.target;!n||n.classList.contains("hidden")||n.contains(a)||s?.contains(a)||ln()}),window.addEventListener("resize",()=>{i("notifications-menu")&&!i("notifications-menu").classList.contains("hidden")&&el()})}var Pe,rn,ir,ka=W(()=>{K();ce();Nt();Pe=[],rn=0,ir=null});function ys(e,t=80){return e?e.scrollHeight-e.scrollTop-e.clientHeight<t:!0}function iu(e,t){return e<0?!1:t}function lu({force:e=!1,following:t=!0,userScrolling:n=!1}={}){return e?!0:n?!1:t}function $a(e){let t=!0,n=!1,s=0,a=()=>{t=ys(e),n=!1},o=u=>{t=iu(u.deltaY,t),u.deltaY<0&&(n=!0)},r=u=>{s=u.touches?.[0]?.clientY||0},d=u=>{(u.touches?.[0]?.clientY||0)-s>8&&(t=!1,n=!0)};return e.addEventListener("scroll",a,{passive:!0}),e.addEventListener("wheel",o,{passive:!0}),e.addEventListener("touchstart",r,{passive:!0}),e.addEventListener("touchmove",d,{passive:!0}),{stick(u=!1){lu({force:u,following:t,userScrolling:n})&&(e.scrollTop=e.scrollHeight,t=!0)},setFollowing(u){t=!!u},isFollowing(){return t},destroy(){e.removeEventListener("scroll",a),e.removeEventListener("wheel",o),e.removeEventListener("touchstart",r),e.removeEventListener("touchmove",d)}}}var lr=W(()=>{});function cu(){return Z[$.peek()]||"Assistant"}function du(e){let t=String(e||"").trim();return/remote compact task|error decoding response body/i.test(t)?"Codex \u4F1A\u8BDD\u538B\u7F29\u5931\u8D25\uFF08\u7F51\u7EDC\u4E2D\u65AD\uFF09\u3002\u518D\u53D1\u4E00\u6761\u6D88\u606F\u91CD\u8BD5\uFF0C\u6216\u5F00\u65B0\u4F1A\u8BDD\u3002":t||"\u53D1\u9001\u5931\u8D25"}function ll(e){return e?(cn&&cn.el===e||(cn?.destroy?.(),cn=$a(e),cn.el=e),cn):null}function He(e,t){if(!e||e.dataset.historyPainting==="1")return;ll(e).stick(!!t)}function Da(){try{Fe.length?sessionStorage.setItem(pr,JSON.stringify(Fe.slice(-30))):sessionStorage.removeItem(pr)}catch{}}function pu(){let e=St(),t=Fe.filter(n=>n.key===e).length;t&&!ol.has(e)&&(ol.add(e),C(`\u231B Restored ${t} queued prompt${t===1?"":"s"} in this browser tab`))}function cl(e=l.sessionId,t=l.agent,n=l.machineId){return e?`${n||""}:${t||"claude"}:${e}`:""}function fu(e={}){let t=cl(e.sessionId,e.agent,e.machineId);if(!t)return 0;try{return Number(JSON.parse(localStorage.getItem(ur)||"{}")[t])||0}catch{return 0}}function mu(e){let t=Number(e?.hubSeq)||0;if(!t)return!0;let n=cl(e.sessionId||l.sessionId,e.agent||l.agent,l.machineId);if(!n)return!0;let s={};try{s=JSON.parse(localStorage.getItem(ur)||"{}")||{}}catch{}let a=Number(s[n])||0;if(t<=a)return!1;s[n]=t;let o=Object.keys(s);o.length>500&&o.sort((r,d)=>Number(s[d])-Number(s[r])).slice(500).forEach(r=>delete s[r]);try{localStorage.setItem(ur,JSON.stringify(s))}catch{}return!0}function St({sessionId:e=l.sessionId,agent:t=l.agent,machineId:n=l.machineId}={}){return e?`${n||""}:${t||"claude"}:${e}`:null}function Kn(e){let t=St(e),n=i("chat-input");!t||!n||(n.value?dn.set(t,n.value):dn.delete(t))}function zn(e){let t=i("chat-input");t&&(t.value=dn.get(St(e))||"",Es(t),Ls(t.value))}function Jn(e){let t=St(e);if(!t)return;let n=Fe.filter(a=>a.key===t);if(!n.length)return;Fe=Fe.filter(a=>a.key!==t),Da();let s=dn.get(t)||"";dn.set(t,[s,...n.map(a=>a.text)].filter(Boolean).join(`
32
32
 
33
- `))}function Qn(){P.peek()&&(P.value=!1,un())}function hu(){sl||(sl=!0,document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible"&&(ut=400,Un({probe:!0}),l.ws?.readyState===WebSocket.OPEN&&l.sessionId))try{l.ws.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}}),window.addEventListener("online",()=>{ut=400,Un({force:!0})}),window.addEventListener("pageshow",e=>{e.persisted?Un({force:!0}):Un({probe:!0})}),window.addEventListener("focus",()=>Un({probe:!0})),navigator.connection?.addEventListener?.("change",()=>{ut=400,Un({probe:!0})}))}function La(){let e=i("conn-dot");if(!e)return;let t=me.peek();e.classList.remove("bg-success","bg-warning","bg-error","bg-base-content/30","animate-pulse"),t==="open"?(e.classList.add("bg-success"),e.title="\u5DF2\u8FDE\u63A5"):t==="connecting"||t==="reconnecting"?(e.classList.add("bg-warning","animate-pulse"),e.title=t==="connecting"?"\u8FDE\u63A5\u4E2D\u2026":"\u91CD\u8FDE\u4E2D\u2026"):t==="offline"?(e.classList.add("bg-error"),e.title="\u79BB\u7EBF"):(e.classList.add("bg-base-content/30"),e.title="\u672A\u8FDE\u63A5")}function Un(e={}){let t=l.ws?.readyState;if(e.force){ut=400,Ht({quiet:!0});return}if(t===WebSocket.OPEN){if(e.probe&&$t&&Date.now()-$t>45e3)try{l.ws.close()}catch{}else if(e.probe&&l.ws.readyState===WebSocket.OPEN)try{l.ws.send(JSON.stringify({type:"ping"}))}catch{}return}t!==WebSocket.CONNECTING&&(ut=Math.min(ut,800),Ht({quiet:!0}))}function gu(){Fn||(me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",La(),Fn=setTimeout(()=>{Fn=null,Ht({quiet:!0})},ut),ut=Math.min(Math.round(ut*1.8),15e3))}function dl(){Sa&&(clearInterval(Sa),Sa=null)}function bu(e,t){dl(),Sa=setInterval(()=>{if(!(t!==ks||e.readyState!==WebSocket.OPEN)){if($t&&Date.now()-$t>7e4){try{e.close()}catch{}return}if(!(typeof document<"u"&&document.visibilityState==="hidden")&&$t&&Date.now()-$t>4e4)try{e.send(JSON.stringify({type:"ping"}))}catch{}}},3e4)}function un(){let e=P.peek()||!!E.peek()&&me.peek()==="open";xa(e)}function Ca(){return(l.role||"editor")==="viewer"?"\u53EA\u8BFB\u8D26\u53F7\uFF0C\u65E0\u6CD5\u8F93\u5165":l.lock?.foreign?`\u4F1A\u8BDD\u7531 ${l.lock.holder&&l.lock.holder!=="viewer"?l.lock.holder:"\u5176\u4ED6\u7528\u6237"} \u5360\u7528\uFF08\u9501\uFF09`:"\u5F53\u524D\u65E0\u6CD5\u8F93\u5165"}function Gn(){let e=an();l.externalSessionReadOnly=!e;let t=i("chat-input"),n=i("send-btn"),s=i("btn-attach"),a=i("session-lock-banner");if(t&&(t.disabled=!e,t.readOnly=!e,e?P.peek()?t.placeholder="\u56DE\u590D\u4E2D\u2026 \u53EF\u5148\u5199\u597D\u4E0B\u4E00\u6761\uFF0C\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u9001 \xB7 \u6216\u70B9 \u25A0 \u505C\u6B62":Ls(t.value||""):t.placeholder=Ca()),n&&(n.disabled=!e),s&&(s.disabled=!e),a)if(!e)a.classList.remove("hidden"),a.textContent=Ca();else{let o=l.nativeRunNotice?.sessionId===l.sessionId?l.nativeRunNotice.message:"";a.classList.toggle("hidden",!o),a.textContent=o}}function _a(e){Gn()}function Ht(e={}){hu(),Fn&&(clearTimeout(Fn),Fn=null),e.quiet&&(dr=!0);let t=l.machineId||(typeof localStorage<"u"?localStorage.getItem("machineId"):null);al!==t&&(ua(),al=t);let n=++ks;try{l.ws?.close()}catch{}me.value="connecting",La();let s=location.protocol==="https:"?"wss":"ws",a=new URLSearchParams;l.token&&a.set("token",l.token),t&&a.set("machine",t),l.sessionId&&a.set("sessionId",l.sessionId),l.agent&&a.set("agent",l.agent);let o=fu();o&&a.set("lastSeq",String(o));let r=new WebSocket(`${s}://${location.host}/ws/chat?${a}`);l.ws=r,r.addEventListener("open",()=>{if(n===ks){if(ut=1e3,$t=Date.now(),me.value="open",La(),l.sessionId)try{r.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}da(),pu(),bu(r,n),un(),cr&&!dr&&C(t?`\u5DF2\u91CD\u8FDE \xB7 ${t}`:"\u5DF2\u91CD\u8FDE"),cr=!1,dr=!1}}),r.addEventListener("message",d=>{if(n!==ks)return;let u;try{u=JSON.parse(d.data)}catch{return}if(mu(u)){if(u.type==="pong"){$t=Date.now();return}if(u.type==="ping"){if($t=Date.now(),r.readyState===WebSocket.OPEN)try{r.send(JSON.stringify({type:"pong"}))}catch{}return}if(u.type==="run-status"){if(u.sessionId&&u.sessionId!==l.sessionId)return;if(typeof u.running!="boolean"){l.nativeRunNotice={sessionId:l.sessionId,message:u.message||"\u7EC8\u7AEF\u4F1A\u8BDD\u672A\u786E\u8BA4\u7ED3\u675F"},Gn();return}l.nativeRunNotice=null,Gn(),u.running?P.value=!0:(P.peek()&&(P.value=!1),fr()),un();return}pl(u)}}),r.addEventListener("close",()=>{n===ks&&(dl(),cr=!0,me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",La(),gu())}),r.addEventListener("error",()=>{})}function fr(){if(!Fe.length||P.peek())return;let e=St(),t=Fe.findIndex(a=>a.key===e);if(t<0)return;let[n]=Fe.splice(t,1);Da();let s=i("chat-input");s&&(s.value=n.text,Es(s)),setTimeout(()=>{if(n.key!==St()||P.peek()){dn.set(n.key,n.text);return}Is()},0)}function $s(){P.value=!1,un(),fr()}function hr(){return ul}function pl(e){if(!(e?.sessionId&&l.sessionId&&e.sessionId!==l.sessionId)){if(e&&typeof e.type=="string"&&(e.type==="note.added"||e.type==="note.updated"||e.type==="note.removed"||e.type==="queue.item.added"||e.type==="queue.item.updated"||e.type==="queue.item.removed"||e.type==="queue.item.moved"||e.type==="queue.item.sending")){window.dispatchEvent(new CustomEvent("hub-ws-message",{detail:e}));let t={"note.added":"hub:note-added","note.updated":"hub:note-updated","note.removed":"hub:note-removed"}[e.type];t&&window.dispatchEvent(new CustomEvent(t,{detail:e}))}if(e._hubReplay===!0){document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="batch"&&Array.isArray(e.items)){for(let t of e.items)pl(t);return}if(["assistant","assistant_stream_start","assistant_delta","thought_delta","tool_use"].includes(e.type)&&ul++,e.type==="session-created"){let t=N.peek();l.sessionId=e.sessionId,e.agent&&e.agent!==$.peek()&&Ne(e.agent),se(t,e.agent||$.peek(),e.sessionId),document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-sessions-changed"){document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-session-updated"){document.dispatchEvent(new CustomEvent("sessions-changed")),document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="notification"&&e.notification){wa(e.notification);return}if(e.type==="grok-queue-status"){Mu(e);return}if(e.type==="result"){Ss(),ws(),pt();let t=e.usage;if(t){let n={input_tokens:t.inputTokens??t.input_tokens,output_tokens:t.outputTokens??t.output_tokens,cache_read_input_tokens:t.cacheReadInputTokens??t.cache_read_input_tokens,cache_creation_input_tokens:t.cacheCreationInputTokens??t.cache_creation_input_tokens,total_tokens:t.totalTokens??t.total_tokens,reasoning_tokens:t.reasoningTokens??t.reasoning_tokens,costUSD:t.costUSD??t.cost_usd};l.lastUsage=n,l.sessionId&&(l.lastUsageSessionId=l.sessionId),Wn(n)}e.is_error||C("\u2713 Done"),$s();return}if(e.type==="complete"){Ss(),ws(),pt(),!e.aborted&&e.agent==="claude"?C("\u2713 Done"):!e.aborted&&e.agent&&e.agent!=="claude"&&!e.error||(!e.aborted&&!e.agent?C("\u2713 Done"):e.aborted&&C("\u5DF2\u505C\u6B62")),$s();return}if(e.type==="error"){Ss(),ws(),(e.code===423||/locked/i.test(String(e.message||"")))&&(l.lock={...l.lock||{},held:!1,foreign:!0,holder:e.lock?.holder||l.lock?.holder||"another user"},Gn()),qt("error","Error",du(e.message)),$s();return}if(e.type==="shell-start"){l.shellBubble=null;return}if(e.type==="shell-output"){l.shellBubble||(l.shellBubble=ju(e.stream==="stderr"?"shell-err":"shell")),Du(l.shellBubble,e.data);return}if(e.type==="shell-exit"){l.shellBubble=null,C(e.code===0?"\u2713 Exit 0":`\u2717 Exit ${e.code}${e.error?": "+e.error:""}`),$s();return}if(e.type==="assistant"){ws();for(let t of e.message?.content||[])t.type==="text"&&t.text?(pt(),qt("assistant",cu(),t.text,{ts:e.ts||Date.now()})):t.type==="tool_use"&&xr(t,{ts:e.ts||Date.now()});return}if(e.type==="assistant_stream_start"){P.peek()||(P.value=!0,un()),fl(e.ts);return}if(e.type==="assistant_delta"){P.peek()||(P.value=!0,un()),vu(e.data||"");return}if(e.type==="assistant_stream_end"){ws();return}if(e.type==="thought_stream_start"){ml();return}if(e.type==="thought_delta"){xu(e.data||"");return}if(e.type==="thought_stream_end"){Ss();return}if(e.type==="status"){let t=i("stream-status");if(t)t.textContent=e.message||"";else{let n=i("messages");n&&e.message&&(n.insertAdjacentHTML("beforeend",`<div id="stream-status" class="text-center text-[10px] text-base-content/35 py-0.5">${p(e.message)}</div>`),He(n))}return}if(e.type==="permission_resolved"){let t=e.requestId||e.request_id;t&&i(`perm-${t}`)?.remove();return}(e.type==="permission_request"||e.request_id&&e.tool_name)&&Pu(e)}}function fl(e){let t=i("messages");if(!t||(pt(),Ss(),Xe&&t.contains(Xe)))return;let n=Ma(e||Date.now()),s=Aa(e||Date.now());t.insertAdjacentHTML("beforeend",`
33
+ `))}function Qn(){P.peek()&&(P.value=!1,un())}function hu(){sl||(sl=!0,document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible"&&(ut=400,Un({probe:!0}),l.ws?.readyState===WebSocket.OPEN&&l.sessionId))try{l.ws.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}}),window.addEventListener("online",()=>{ut=400,Un({force:!0})}),window.addEventListener("pageshow",e=>{e.persisted?Un({force:!0}):Un({probe:!0})}),window.addEventListener("focus",()=>Un({probe:!0})),navigator.connection?.addEventListener?.("change",()=>{ut=400,Un({probe:!0})}))}function La(){let e=i("conn-dot");if(!e)return;let t=me.peek();e.classList.remove("bg-success","bg-warning","bg-error","bg-base-content/30","animate-pulse"),t==="open"?(e.classList.add("bg-success"),e.title="\u5DF2\u8FDE\u63A5"):t==="connecting"||t==="reconnecting"?(e.classList.add("bg-warning","animate-pulse"),e.title=t==="connecting"?"\u8FDE\u63A5\u4E2D\u2026":"\u91CD\u8FDE\u4E2D\u2026"):t==="offline"?(e.classList.add("bg-error"),e.title="\u79BB\u7EBF"):(e.classList.add("bg-base-content/30"),e.title="\u672A\u8FDE\u63A5")}function Un(e={}){let t=l.ws?.readyState;if(e.force){ut=400,Ht({quiet:!0});return}if(t===WebSocket.OPEN){if(e.probe&&$t&&Date.now()-$t>45e3)try{l.ws.close()}catch{}else if(e.probe&&l.ws.readyState===WebSocket.OPEN)try{l.ws.send(JSON.stringify({type:"ping"}))}catch{}return}t!==WebSocket.CONNECTING&&(ut=Math.min(ut,800),Ht({quiet:!0}))}function gu(){Fn||(me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",La(),Fn=setTimeout(()=>{Fn=null,Ht({quiet:!0})},ut),ut=Math.min(Math.round(ut*1.8),15e3))}function dl(){Sa&&(clearInterval(Sa),Sa=null)}function bu(e,t){dl(),Sa=setInterval(()=>{if(!(t!==ks||e.readyState!==WebSocket.OPEN)){if($t&&Date.now()-$t>7e4){try{e.close()}catch{}return}if(!(typeof document<"u"&&document.visibilityState==="hidden")&&$t&&Date.now()-$t>4e4)try{e.send(JSON.stringify({type:"ping"}))}catch{}}},3e4)}function un(){let e=P.peek()||!!E.peek()&&me.peek()==="open";xa(e)}function Ca(){return(l.role||"editor")==="viewer"?"\u53EA\u8BFB\u8D26\u53F7\uFF0C\u65E0\u6CD5\u8F93\u5165":l.lock?.foreign?`\u4F1A\u8BDD\u7531 ${l.lock.holder&&l.lock.holder!=="viewer"?l.lock.holder:"\u5176\u4ED6\u7528\u6237"} \u5360\u7528\uFF08\u9501\uFF09`:"\u5F53\u524D\u65E0\u6CD5\u8F93\u5165"}function Gn(){let e=an();l.externalSessionReadOnly=!e;let t=i("chat-input"),n=i("send-btn"),s=i("btn-attach"),a=i("session-lock-banner");if(t&&(t.disabled=!e,t.readOnly=!e,e?P.peek()?t.placeholder="\u56DE\u590D\u4E2D\u2026 \u53EF\u5148\u5199\u597D\u4E0B\u4E00\u6761\uFF0C\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u9001 \xB7 \u6216\u70B9 \u25A0 \u505C\u6B62":Ls(t.value||""):t.placeholder=Ca()),n&&(n.disabled=!e),s&&(s.disabled=!e),a)if(!e)a.classList.remove("hidden"),a.textContent=Ca();else{let o=l.nativeRunNotice?.sessionId===l.sessionId?l.nativeRunNotice.message:"";a.classList.toggle("hidden",!o),a.textContent=o}}function _a(e){Gn()}function Ht(e={}){hu(),Fn&&(clearTimeout(Fn),Fn=null),e.quiet&&(dr=!0);let t=l.machineId||(typeof localStorage<"u"?localStorage.getItem("machineId"):null);al!==t&&(ua(),al=t);let n=++ks;try{l.ws?.close()}catch{}me.value="connecting",La();let s=location.protocol==="https:"?"wss":"ws",a=new URLSearchParams;l.token&&a.set("token",l.token),t&&a.set("machine",t),l.sessionId&&a.set("sessionId",l.sessionId),l.agent&&a.set("agent",l.agent);let o=fu();o&&a.set("lastSeq",String(o));let r=new WebSocket(`${s}://${location.host}/ws/chat?${a}`);l.ws=r,r.addEventListener("open",()=>{if(n===ks){if(ut=1e3,$t=Date.now(),me.value="open",La(),l.sessionId)try{r.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}da(),pu(),bu(r,n),un(),cr&&!dr&&C(t?`\u5DF2\u91CD\u8FDE \xB7 ${t}`:"\u5DF2\u91CD\u8FDE"),cr=!1,dr=!1}}),r.addEventListener("message",d=>{if(n!==ks)return;let u;try{u=JSON.parse(d.data)}catch{return}if(mu(u)){if(u.type==="pong"){$t=Date.now();return}if(u.type==="ping"){if($t=Date.now(),r.readyState===WebSocket.OPEN)try{r.send(JSON.stringify({type:"pong"}))}catch{}return}if(u.type==="run-status"){if(u._hubReplay||u.sessionId&&u.sessionId!==l.sessionId)return;if(typeof u.running!="boolean"){l.nativeRunNotice={sessionId:l.sessionId,message:u.message||"\u7EC8\u7AEF\u4F1A\u8BDD\u672A\u786E\u8BA4\u7ED3\u675F"},Gn();return}l.nativeRunNotice=null,Gn(),u.running?P.value=!0:(P.peek()&&(P.value=!1),fr()),un();return}pl(u)}}),r.addEventListener("close",()=>{n===ks&&(dl(),cr=!0,me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",La(),gu())}),r.addEventListener("error",()=>{})}function fr(){if(!Fe.length||P.peek())return;let e=St(),t=Fe.findIndex(a=>a.key===e);if(t<0)return;let[n]=Fe.splice(t,1);Da();let s=i("chat-input");s&&(s.value=n.text,Es(s)),setTimeout(()=>{if(n.key!==St()||P.peek()){dn.set(n.key,n.text);return}Is()},0)}function $s(){P.value=!1,un(),fr()}function hr(){return ul}function pl(e){if(!(e?.sessionId&&l.sessionId&&e.sessionId!==l.sessionId)){if(e&&typeof e.type=="string"&&(e.type==="note.added"||e.type==="note.updated"||e.type==="note.removed"||e.type==="queue.item.added"||e.type==="queue.item.updated"||e.type==="queue.item.removed"||e.type==="queue.item.moved"||e.type==="queue.item.sending")){window.dispatchEvent(new CustomEvent("hub-ws-message",{detail:e}));let t={"note.added":"hub:note-added","note.updated":"hub:note-updated","note.removed":"hub:note-removed"}[e.type];t&&window.dispatchEvent(new CustomEvent(t,{detail:e}))}if(e._hubReplay===!0){document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="batch"&&Array.isArray(e.items)){for(let t of e.items)pl(t);return}if(["assistant","assistant_stream_start","assistant_delta","thought_delta","tool_use"].includes(e.type)&&ul++,e.type==="session-created"){let t=N.peek();l.sessionId=e.sessionId,e.agent&&e.agent!==$.peek()&&Ne(e.agent),se(t,e.agent||$.peek(),e.sessionId),document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-sessions-changed"){document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-session-updated"){document.dispatchEvent(new CustomEvent("sessions-changed")),document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="notification"&&e.notification){wa(e.notification);return}if(e.type==="grok-queue-status"){Mu(e);return}if(e.type==="result"){Ss(),ws(),pt();let t=e.usage;if(t){let n={input_tokens:t.inputTokens??t.input_tokens,output_tokens:t.outputTokens??t.output_tokens,cache_read_input_tokens:t.cacheReadInputTokens??t.cache_read_input_tokens,cache_creation_input_tokens:t.cacheCreationInputTokens??t.cache_creation_input_tokens,total_tokens:t.totalTokens??t.total_tokens,reasoning_tokens:t.reasoningTokens??t.reasoning_tokens,costUSD:t.costUSD??t.cost_usd};l.lastUsage=n,l.sessionId&&(l.lastUsageSessionId=l.sessionId),Wn(n)}e.is_error||C("\u2713 Done"),$s();return}if(e.type==="complete"){Ss(),ws(),pt(),!e.aborted&&e.agent==="claude"?C("\u2713 Done"):!e.aborted&&e.agent&&e.agent!=="claude"&&!e.error||(!e.aborted&&!e.agent?C("\u2713 Done"):e.aborted&&C("\u5DF2\u505C\u6B62")),$s();return}if(e.type==="error"){Ss(),ws(),(e.code===423||/locked/i.test(String(e.message||"")))&&(l.lock={...l.lock||{},held:!1,foreign:!0,holder:e.lock?.holder||l.lock?.holder||"another user"},Gn()),qt("error","Error",du(e.message)),$s();return}if(e.type==="shell-start"){l.shellBubble=null;return}if(e.type==="shell-output"){l.shellBubble||(l.shellBubble=ju(e.stream==="stderr"?"shell-err":"shell")),Du(l.shellBubble,e.data);return}if(e.type==="shell-exit"){l.shellBubble=null,C(e.code===0?"\u2713 Exit 0":`\u2717 Exit ${e.code}${e.error?": "+e.error:""}`),$s();return}if(e.type==="assistant"){ws();for(let t of e.message?.content||[])t.type==="text"&&t.text?(pt(),qt("assistant",cu(),t.text,{ts:e.ts||Date.now()})):t.type==="tool_use"&&xr(t,{ts:e.ts||Date.now()});return}if(e.type==="assistant_stream_start"){P.peek()||(P.value=!0,un()),fl(e.ts);return}if(e.type==="assistant_delta"){P.peek()||(P.value=!0,un()),vu(e.data||"");return}if(e.type==="assistant_stream_end"){ws();return}if(e.type==="thought_stream_start"){ml();return}if(e.type==="thought_delta"){xu(e.data||"");return}if(e.type==="thought_stream_end"){Ss();return}if(e.type==="status"){let t=i("stream-status");if(t)t.textContent=e.message||"";else{let n=i("messages");n&&e.message&&(n.insertAdjacentHTML("beforeend",`<div id="stream-status" class="text-center text-[10px] text-base-content/35 py-0.5">${p(e.message)}</div>`),He(n))}return}if(e.type==="permission_resolved"){let t=e.requestId||e.request_id;t&&i(`perm-${t}`)?.remove();return}(e.type==="permission_request"||e.request_id&&e.tool_name)&&Pu(e)}}function fl(e){let t=i("messages");if(!t||(pt(),Ss(),Xe&&t.contains(Xe)))return;let n=Ma(e||Date.now()),s=Aa(e||Date.now());t.insertAdjacentHTML("beforeend",`
34
34
  <div class="msg-row assistant px-2 live-stream" data-ts="${p(s)}">
35
35
  <div class="max-w-[88%] rounded-2xl rounded-tl-sm px-3 py-2 text-sm bg-base-200 break-words md">
36
36
  <div class="msg-stream-body whitespace-pre-wrap"></div>
@@ -1144,7 +1144,7 @@ ${t}`:"",n.length?n.join(`
1144
1144
  ${(g.id===null?!m:m===g.configDir)?"border-primary text-primary":"border-transparent text-base-content/50 hover:text-base-content"}"
1145
1145
  data-ws-tab="${p(g.configDir||"")}">
1146
1146
  ${p(g.name)}
1147
- </button>`).join("")}),je(()=>{_t.value,Zt.value,gt.value,rt.value,T.value;let c=i("session-list");if(!c||c.querySelector(".session-rename-input"))return;let f=Jr();if(c._lastHtml===f){Bs();return}let m=c.scrollTop;c.innerHTML=f,c._lastHtml=f,c.scrollTop=m,Bs()}),je(()=>{bt.value,Bs()}),je(()=>{ne.value,ye.value,_.value,M.value;let c=i("welcome");c&&(document.documentElement.classList.contains("boot-restore")||document.documentElement.classList.contains("boot-pending")||c.classList.contains("hidden")||c.style.display==="none"||wn())}),De(ke,c=>{let f=i("session-filter-badge");f&&(f.style.display=c?"inline":"none",f.title=c||"")}),je(()=>{let c=E.value;if(c&&c.path)$c(c.path);else{let f=i("project-notes-bar");f&&(f.style.display="none")}}),De(X,c=>{document.querySelectorAll("[data-tab]").forEach(m=>{let g=m.dataset.tab===c;m.classList.toggle("text-primary",g),m.classList.toggle("border-primary",g),m.classList.toggle("text-base-content/50",!g),m.classList.toggle("border-transparent",!g)});let f=i("project-view");f&&!f.classList.contains("hidden")&&(f.style.display="flex",f.style.flexDirection="column",f.style.minHeight="0",f.style.flex="1"),["chat","files","git","shell","memory"].forEach(m=>{let g=i(`tab-${m}`);if(!g)return;let w=m===c;g.classList.toggle("hidden",!w),w?(g.style.display="flex",g.style.flexDirection="column",g.style.flex="1 1 0",g.style.minHeight="0",g.style.overflow="hidden"):g.style.display="none"}),c==="memory"&&no(),c==="shell"&&requestAnimationFrame(()=>{document.dispatchEvent(new CustomEvent("shell-tab-shown"))}),Ee()}),Pc(),Nc(),nl({openSession:nt});let s=c=>{i("app")?.classList.toggle("chat-chrome-collapsed",c),i("btn-expand-chat-chrome")?.classList.toggle("hidden",!c),localStorage.setItem("chatChromeCollapsed",c?"1":"0")};s(localStorage.getItem("chatChromeCollapsed")==="1");let a=null;document.addEventListener("sessions-changed",()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null,We({waitFresh:!1})},1200)}),document.addEventListener("router:home",fo),document.addEventListener("router:session",async({detail:{id:c,tab:f,machineId:m,agent:g}})=>{let w=ne.peek().find(A=>A.sessionId===c),y=tn();await nt(c,w?.cwd||(y?.sessionId===c?y.cwd:null)||null,w?.configDir||(y?.sessionId===c?y.configDir:null)||null,g||w?.agent||(y?.sessionId===c?y.agent:null)||null,m||w?.machineId||(y?.sessionId===c?y.machineId:null)||null,{tab:f||"chat"})}),b.on("click","#btn-home",fo),b.on("click","#btn-share-session, #btn-share-session-current",async(c,f)=>{let m=El();if(m)try{await navigator.clipboard.writeText(m),f.classList.add("is-copied"),f.title="\u5DF2\u590D\u5236\u5206\u4EAB\u94FE\u63A5",setTimeout(()=>{f.classList.remove("is-copied"),f.title="\u590D\u5236\u5F53\u524D\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5"},1400)}catch{window.prompt("\u590D\u5236\u4F1A\u8BDD\u94FE\u63A5\uFF1A",m)}}),b.on("click","#auth-btn",ii),b.on("submit","#auth-form",c=>{c.preventDefault(),ii()}),b.on("keydown","#auth-username, #auth-password",c=>{c.key==="Enter"&&ii()}),b.on("click","#hamburger",()=>i("sidebar").classList.contains("open")?Ks():Dc()),b.on("click","#sidebar-overlay",Ks),document.addEventListener("keydown",c=>{c.key==="Escape"&&window.innerWidth<=640&&i("sidebar")?.classList.contains("open")&&(c.preventDefault(),Ks())}),b.on("input","#session-search",(c,f)=>{$e.value=f.value,to(f.value)}),b.on("click","#sidebar-filter-toggle",()=>{let c=i("sidebar-filter-menu");if(!c)return;let f=c.classList.toggle("hidden");i("sidebar-filter-toggle")?.setAttribute("aria-expanded",String(!f))}),b.on("change","[data-agent-option]",(c,f)=>{let m=new Set(Vt.peek());f.checked?m.add(f.dataset.agentOption):m.delete(f.dataset.agentOption);let g=[...m];Vt.value=g,localStorage.setItem("agentFilters",JSON.stringify(g)),ye.value=g.length===1?g[0]:"all"}),b.on("change","#filter-favorites",(c,f)=>{ze.value=f.checked,localStorage.setItem("favoritesOnly",f.checked?"1":"0")}),b.on("change","#filter-hidden",(c,f)=>{Je.value=f.checked,localStorage.setItem("showHiddenOnly",f.checked?"1":"0")}),b.on("click","#filter-clear",()=>{Vt.value=[],ye.value="all",ze.value=!1,Je.value=!1,localStorage.setItem("agentFilters","[]"),localStorage.setItem("favoritesOnly","0"),localStorage.setItem("showHiddenOnly","0"),document.querySelectorAll("[data-agent-option]").forEach(c=>{c.checked=!1}),i("filter-favorites")&&(i("filter-favorites").checked=!1),i("filter-hidden")&&(i("filter-hidden").checked=!1)}),b.on("click","#session-filter-badge",()=>{ke.value=null}),b.on("click","[data-ws-tab]",(c,f)=>{ke.value=f.dataset.wsTab||null}),b.on("click","#sidebar-refresh",()=>{We(),$e.peek().trim()&&eo($e.peek())}),b.on("click","[data-view]",(c,f)=>{gt.value=f.dataset.view,localStorage.setItem("sidebarView",f.dataset.view)}),b.on("click","[data-agent-filter]",(c,f)=>{ye.value=f.dataset.agentFilter,localStorage.setItem("agentFilter",f.dataset.agentFilter),$e.peek().trim()&&to($e.peek())}),b.on("dblclick","[data-project-cwd]",(c,f)=>{let m=f.dataset.projectCwd;if(!m)return;let g=m.split("/").filter(Boolean).pop()||m;ti({id:g,name:g,path:m}),C(`Project \xB7 ${m}`)}),b.on("click","#btn-pwa-install",async()=>{await Bi()||kp()}),document.addEventListener("pwa-installable",()=>{document.getElementById("btn-pwa-install")?.classList.remove("hidden")}),b.on("click","#btn-settings",Ba),b.on("click","#btn-notes",()=>Oa()),b.on("click","#btn-collapse-chat-chrome",()=>s(!0)),b.on("click","#btn-expand-chat-chrome",()=>s(!1)),b.on("click","#btn-meta-agent",()=>Ql()),b.on("click","#btn-meta-agent-welcome",()=>Pr("chat")),b.on("click","#btn-theme",si),b.on("click","[data-sidebar-action]",(c,f)=>{let m=f.dataset.sidebarAction;m==="new"&&ai(),m==="theme"&&si(),m==="settings"&&Ba(),m==="logout"&&(l.token=null,localStorage.removeItem("token"),Le(null),it.value=!1,location.reload())}),b.on("click","#btn-cal-prev",()=>{Fr(-1),wn(yn())}),b.on("click","#btn-cal-next",()=>{Fr(1),wn(yn())}),b.on("click","[data-cal-date]",(c,f)=>{fc(f.dataset.calDate),wn(yn())}),b.on("click","[data-session-id]",(c,f)=>{c.target.closest("[data-fav-toggle]")||c.target.closest("[data-hide-toggle]")||c.target.closest("[data-rename-session]")||c.target.closest(".session-rename-input")||c.target.closest(".session-title-wrap.session-rename-active")||(nt(f.dataset.sessionId,f.dataset.sessionCwd||null,f.dataset.sessionConfigDir||null,f.dataset.sessionAgent||"claude",f.dataset.sessionMachine||null),_c())}),b.on("click","[data-rename-session]",(c,f)=>{c.preventDefault(),c.stopPropagation();let m=f.closest(".session-title-wrap")||f,g=m.dataset.renameSessionId||m.dataset.sessionId;g&&Yr({sessionId:g,agent:m.dataset.renameSessionAgent||"claude",machineId:m.dataset.renameSessionMachine||null,fallbackDisplay:m.dataset.renameSessionDisplay||"",mountEl:m})}),b.on("click","[data-rename-bar]",(c,f)=>{if(c.preventDefault(),c.stopPropagation(),!l.sessionId)return;let m=document.getElementById("session-title-display")||f;Yr({sessionId:l.sessionId,agent:l.agent||$.peek()||"claude",machineId:l.machineId||null,mountEl:m})}),b.on("click","[data-folder]",(c,f)=>{let m=f.dataset.folder,w=f.querySelector("span")?.textContent.trim()==="\u25BE",y=new Set(jn.peek()),A=new Set(Dn.peek());w?(y.delete(m),A.add(m)):(y.add(m),A.delete(m)),xe(()=>{jn.value=y,Dn.value=A})}),b.on("click","#memory-refresh",no),b.on("click","[data-memory-file]",c=>Qr(c.dataset.memoryFile,c.dataset.memoryAgent)),b.on("click","[data-tab]",(c,f)=>Ct(f.dataset.tab));let o=async(c,f)=>{let m=i(c),g=m?.value.trim();if(!g){f.value="";return}try{let w=await x("POST","/api/resolve-path",{path:g});if(w.isDir===!1)throw new Error("Path is not a directory on the target machine");f.value=w.path,m.value=w.path;let y=E.peek();y&&(E.value={...y,path:w.path})}catch(w){m.style.color="oklch(var(--er))",m.title=w.message,setTimeout(()=>{m.style.color="",m.title=""},2e3)}};b.on("click","#files-root-btn",()=>o("files-root-input",ie)),b.on("click","#git-root-btn",()=>o("git-root-input",Se)),b.on("keydown","#files-root-input",c=>{c.key==="Enter"&&o("files-root-input",ie)}),b.on("keydown","#git-root-input",c=>{c.key==="Enter"&&o("git-root-input",Se)}),b.on("click","#btn-opts",()=>{i("chat-opts").classList.toggle("hidden"),Ee()}),b.on("change","#sel-agent",(c,f)=>{let m=$.peek(),g=f.value;m!==g&&(l.sessionId=null,Ne(g),se(Oe(g)||N.peek()),i("sel-permission").value=ue.peek(),et(),C(`Agent \u2192 ${Z[g]||g} \xB7 model ${N.peek()} \xB7 new session`))}),b.on("change","#sel-convert-agent",async(c,f)=>{let m=f.value;if(!m)return;let g=l.sessionId;if(!g){alert("No active session to convert."),f.value="";return}let w=l.agent||$.peek()||"claude";if(w===m){alert("Cannot convert to the same agent."),f.value="";return}f.disabled=!0,C(`Converting session ${g.slice(0,8)} from ${w} to ${m}...`);try{let y=await x("POST",`/api/sessions/${g}/convert`,{targetAgent:m,sourceAgent:w});y&&y.success?(C(`\u2713 Converted successfully. New session: ${y.targetSessionId.slice(0,8)}`),await We(),await nt(y.targetSessionId,E.peek()?.path||null,null,y.targetAgent),Ts()):C("Failed to convert session.")}catch(y){C(`Error converting session: ${y.message}`),alert(`Error converting session: ${y.message}`)}finally{f.disabled=!1,f.value=""}}),b.on("change","#sel-model",(c,f)=>{se(f.value),Xa()}),b.on("click","#btn-model-add",()=>Za({editCurrent:!1})),b.on("click","#btn-model-edit",()=>Za({editCurrent:!0})),b.on("change","#sel-effort",(c,f)=>{te.value=f.value}),b.on("change","#sel-permission",(c,f)=>{ue.value=f.value}),b.on("change","#sel-density",(c,f)=>{Ko(f.value),C(`Density \u2192 ${f.value} (applies to new tool calls; reload session to re-group history)`)}),document.addEventListener("agent-changed",et),b.on("click","#btn-new-session, #btn-new-session-current, #btn-new-session-welcome",ai),b.on("click","#new-session-cancel",()=>i("modal-new-session").close()),b.on("click","#new-session-start",ri),b.on("change","#new-session-agent",oi),b.on("keydown","#new-session-path",c=>{c.key==="Enter"&&ri()}),b.on("click","#send-btn",Is),b.on("click","#stop-btn",hl),b.on("click","#btn-logout",()=>{l.token=null,localStorage.removeItem("token"),Le(null),it.value=!1,location.reload()}),b.on("click","[data-pick-machine]",async(c,f)=>{let m=f.dataset.pickMachine;if(!m||m===_.peek()){Ln();return}await Zr(m,{forceReload:!0}),ya()});let r=async()=>{let c=i("machine-picker-status");if(c&&(c.textContent="\u5237\u65B0\u4E2D\u2026"),await $n(),lo(),Fs(),Ot(),c){let f=(le.peek()||[]).filter(m=>m.online!==!1).length;c.textContent=`${f} online`}};b.on("click","#btn-refresh-machines",r),b.on("click","#btn-refresh-machines-menu",async c=>{c.stopPropagation(),await r()}),b.on("click","#btn-machine-menu",async c=>{c.stopPropagation(),kn(),ln();let f=i("machine-menu");f&&(f.classList.contains("hidden")?(await $n(),Fs(),f.classList.remove("hidden")):f.classList.add("hidden"))}),b.on("click","#btn-recent-sessions",c=>{c.preventDefault(),c.stopPropagation(),Ln(),ln(),pc();let f=!i("recent-menu")?.classList.contains("hidden"),m=i("btn-recent-sessions");m&&m.setAttribute("aria-expanded",f?"true":"false")}),b.on("click","#recent-menu-backdrop",c=>{c.preventDefault(),c.stopPropagation(),kn(),i("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),document.addEventListener("click",c=>{let f=i("machine-menu-wrap");f&&!f.contains(c.target)&&Ln();let m=i("recent-menu"),g=i("btn-recent-sessions"),w=c.target;if(m&&!m.classList.contains("hidden")){if(m.contains(w)||g?.contains(w))return;kn(),g?.setAttribute("aria-expanded","false")}}),b.on("click","#btn-notifications",c=>{c.preventDefault(),c.stopPropagation(),Ln(),kn(),tl()}),window.addEventListener("resize",()=>{i("recent-menu")&&!i("recent-menu").classList.contains("hidden")&&Or()}),b.on("click","#recent-menu [data-session-id]",()=>{kn(),i("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),b.on("click","[data-dismiss-recent-session]",(c,f)=>{c.preventDefault(),c.stopPropagation(),dc({sessionId:f.dataset.dismissRecentSession,agent:f.dataset.dismissRecentAgent||"claude",machineId:f.dataset.dismissRecentMachine||null})}),b.on("click","#btn-edit-project-notes, #project-goal-text, #project-notes-text",()=>{Sc()}),b.on("click","#btn-cancel-project-notes",()=>{as()});let d=async()=>{let c=i("project-goal-input")?.value?.trim()??"",f=i("project-notes-input")?.value?.trim()??"",m=E.peek();if(!(!m||!m.path))try{let g=await x("POST","/api/projects/notes",{root:m.path,goal:c,notes:f});kc(g.goal||"",g.notes||""),as()}catch(g){alert(`Error saving project notes: ${g.message}`)}};b.on("click","#btn-save-project-notes",d),b.on("keydown","#project-goal-input",c=>{c.key==="Enter"&&d(),c.key==="Escape"&&as()}),b.on("keydown","#project-notes-input",c=>{c.key==="Escape"&&as()}),b.on("click","[data-fav-toggle]",(c,f)=>{c.stopPropagation(),c.preventDefault();let m=f.dataset.favSessionMachine||l.machineId;m&&(l.machineId=m,localStorage.setItem("machineId",m)),Ic(f.dataset.favSessionId,f.dataset.favSessionAgent||"claude",{machineId:m||null})}),b.on("click","[data-hide-toggle]",(c,f)=>{c.stopPropagation(),c.preventDefault();let m=f.dataset.hideSessionMachine||l.machineId;m&&(l.machineId=m,localStorage.setItem("machineId",m)),Tc(f.dataset.hideSessionId,f.dataset.hideSessionAgent||"claude",{machineId:m||null})}),b.on("click","#btn-edit-session-notes, #session-notes-text",()=>{Lc()}),b.on("click","#btn-cancel-session-notes",()=>tt()),b.on("click","#btn-save-session-notes",async()=>{let c=i("session-notes-input")?.value?.trim()||"";if(!l.sessionId)return;let f=l.agent||$.peek()||"claude";await Vr(l.sessionId,f,c)&&tt()}),b.on("keydown","#session-notes-input",async c=>{if(c.key==="Escape"&&tt(),c.key==="Enter"){let f=c.target.value.trim();if(!l.sessionId)return;let m=l.agent||$.peek()||"claude";await Vr(l.sessionId,m,f)&&tt()}}),b.on("click","#btn-fav-filter",()=>{let c=!ze.peek();ze.value=c,localStorage.setItem("favoritesOnly",c?"1":"0"),i("btn-fav-filter")?.classList.toggle("active",c),c&&Je.peek()&&(Je.value=!1,localStorage.setItem("showHiddenOnly","0"),i("btn-hidden-filter")?.classList.remove("active"))}),b.on("click","#btn-hidden-filter",()=>{let c=!Je.peek();Je.value=c,localStorage.setItem("showHiddenOnly",c?"1":"0"),i("btn-hidden-filter")?.classList.toggle("active",c),c&&ze.peek()&&(ze.value=!1,localStorage.setItem("favoritesOnly","0"),i("btn-fav-filter")?.classList.remove("active"))}),et(),je(()=>{M.value,_.value,l.token&&ya()}),i("sel-permission").value=ue.peek(),yl();let u=i("sel-density");u&&(u.value=_e.peek()||"normal"),document.querySelectorAll("[data-agent-option]").forEach(c=>{c.checked=Vt.peek().includes(c.dataset.agentOption)}),i("filter-favorites")&&(i("filter-favorites").checked=ze.peek()),i("filter-hidden")&&(i("filter-hidden").checked=Je.peek()),document.querySelectorAll("[data-agent-filter]").forEach(c=>{c.classList.toggle("active",c.dataset.agentFilter===ye.peek())}),i("btn-fav-filter")?.classList.toggle("active",ze.peek()),i("btn-hidden-filter")?.classList.toggle("active",Je.peek()),document.querySelectorAll("[data-view]").forEach(c=>{let f=c.dataset.view===gt.peek();c.classList.toggle("bg-primary/15",f),c.classList.toggle("text-primary",f),c.classList.toggle("font-medium",f),c.classList.toggle("text-base-content/50",!f)})}K();tr();G();ce();bs();rr();ka();Hn();nn();sn();lr();Nt();Nt();function $p(){return Z[$.peek()]||"Assistant"}function Sp(e){let t=String(e||"").trim();return/remote compact task|error decoding response body/i.test(t)?"Codex \u4F1A\u8BDD\u538B\u7F29\u5931\u8D25\uFF08\u7F51\u7EDC\u4E2D\u65AD\uFF09\u3002\u518D\u53D1\u4E00\u6761\u6D88\u606F\u91CD\u8BD5\uFF0C\u6216\u5F00\u65B0\u4F1A\u8BDD\u3002":t||"\u53D1\u9001\u5931\u8D25"}var En=null;function Lp(e){return ys(e)}function Gc(e){return e?(En&&En.el===e||(En?.destroy?.(),En=$a(e),En.el=e),En):null}function Re(e,t){if(!e||e.dataset.historyPainting==="1")return;Gc(e).stick(!!t)}var Js=0,jt=null,at=1e3,At=0,bo=null,qc=!1,vo=!1,Rc=null,xo=!1,ui="hubStreamCursors",Io=new Map,Ep=0,pi=new Set,fi="pendingUserTexts",In=(()=>{try{let e=JSON.parse(sessionStorage.getItem(fi)||"[]");return Array.isArray(e)?e.filter(t=>t?.key&&t?.text).slice(-30):[]}catch{return[]}})(),Bc=new Set,Kc=new Map;function zc(){try{In.length?sessionStorage.setItem(fi,JSON.stringify(In.slice(-30))):sessionStorage.removeItem(fi)}catch{}}function Ip(){let e=Zs(),t=In.filter(n=>n.key===e).length;t&&!Bc.has(e)&&(Bc.add(e),H(`\u231B Restored ${t} queued prompt${t===1?"":"s"} in this browser tab`))}function Jc(e=l.sessionId,t=l.agent,n=l.machineId){return e?`${n||""}:${t||"claude"}:${e}`:""}function Tp(e={}){let t=Jc(e.sessionId,e.agent,e.machineId);if(!t)return 0;try{return Number(JSON.parse(localStorage.getItem(ui)||"{}")[t])||0}catch{return 0}}function Cp(e){let t=Number(e?.hubSeq)||0;if(!t)return!0;let n=Jc(e.sessionId||l.sessionId,e.agent||l.agent,l.machineId);if(!n)return!0;let s={};try{s=JSON.parse(localStorage.getItem(ui)||"{}")||{}}catch{}let a=Number(s[n])||0;if(t<=a)return!1;s[n]=t;let o=Object.keys(s);o.length>500&&o.sort((r,d)=>Number(s[d])-Number(s[r])).slice(500).forEach(r=>delete s[r]);try{localStorage.setItem(ui,JSON.stringify(s))}catch{}return!0}function Zs({sessionId:e=l.sessionId,agent:t=l.agent,machineId:n=l.machineId}={}){return e?`${n||""}:${t||"claude"}:${e}`:null}function Mp(){qc||(qc=!0,document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible"&&(at=400,rs({probe:!0}),l.ws?.readyState===WebSocket.OPEN&&l.sessionId))try{l.ws.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}}),window.addEventListener("online",()=>{at=400,rs({force:!0})}),window.addEventListener("pageshow",e=>{e.persisted?rs({force:!0}):rs({probe:!0})}),window.addEventListener("focus",()=>rs({probe:!0})),navigator.connection?.addEventListener?.("change",()=>{at=400,rs({probe:!0})}))}function Vs(){let e=i("conn-dot");if(!e)return;let t=me.peek();e.classList.remove("bg-success","bg-warning","bg-error","bg-base-content/30","animate-pulse"),t==="open"?(e.classList.add("bg-success"),e.title="\u5DF2\u8FDE\u63A5"):t==="connecting"||t==="reconnecting"?(e.classList.add("bg-warning","animate-pulse"),e.title=t==="connecting"?"\u8FDE\u63A5\u4E2D\u2026":"\u91CD\u8FDE\u4E2D\u2026"):t==="offline"?(e.classList.add("bg-error"),e.title="\u79BB\u7EBF"):(e.classList.add("bg-base-content/30"),e.title="\u672A\u8FDE\u63A5")}function rs(e={}){let t=l.ws?.readyState;if(e.force){at=400,$o({quiet:!0});return}if(t===WebSocket.OPEN){if(e.probe&&At&&Date.now()-At>45e3)try{l.ws.close()}catch{}else if(e.probe&&l.ws.readyState===WebSocket.OPEN)try{l.ws.send(JSON.stringify({type:"ping"}))}catch{}return}t!==WebSocket.CONNECTING&&(at=Math.min(at,800),$o({quiet:!0}))}function Ap(){jt||(me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Vs(),jt=setTimeout(()=>{jt=null,$o({quiet:!0})},at),at=Math.min(Math.round(at*1.8),15e3))}function Qc(){bo&&(clearInterval(bo),bo=null)}function jp(e,t){Qc(),bo=setInterval(()=>{if(!(t!==Js||e.readyState!==WebSocket.OPEN)){if(At&&Date.now()-At>7e4){try{e.close()}catch{}return}if(!(typeof document<"u"&&document.visibilityState==="hidden")&&At&&Date.now()-At>4e4)try{e.send(JSON.stringify({type:"ping"}))}catch{}}},3e4)}function Dt(){let e=P.peek()||!!E.peek()&&me.peek()==="open";xa(e)}function ko(){return(l.role||"editor")==="viewer"?"\u53EA\u8BFB\u8D26\u53F7\uFF0C\u65E0\u6CD5\u8F93\u5165":l.lock?.foreign?`\u4F1A\u8BDD\u7531 ${l.lock.holder&&l.lock.holder!=="viewer"?l.lock.holder:"\u5176\u4ED6\u7528\u6237"} \u5360\u7528\uFF08\u9501\uFF09`:"\u5F53\u524D\u65E0\u6CD5\u8F93\u5165"}function Wt(){let e=an();l.externalSessionReadOnly=!e;let t=i("chat-input"),n=i("send-btn"),s=i("btn-attach"),a=i("session-lock-banner");if(t&&(t.disabled=!e,t.readOnly=!e,e?P.peek()?t.placeholder="\u56DE\u590D\u4E2D\u2026 \u53EF\u5148\u5199\u597D\u4E0B\u4E00\u6761\uFF0C\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u9001 \xB7 \u6216\u70B9 \u25A0 \u505C\u6B62":Ys(t.value||""):t.placeholder=ko()),n&&(n.disabled=!e),s&&(s.disabled=!e),a)if(!e)a.classList.remove("hidden"),a.textContent=ko();else{let o=l.nativeRunNotice?.sessionId===l.sessionId?l.nativeRunNotice.message:"";a.classList.toggle("hidden",!o),a.textContent=o}}function Dp(){at=400,jt&&(clearTimeout(jt),jt=null),xo=!1;let e=l.ws?.readyState;if(e===WebSocket.OPEN||e===WebSocket.CONNECTING)try{l.ws?.close()}catch{}$o({quiet:!1}),H("\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5\u5E76\u540C\u6B65\u2026")}function $o(e={}){Mp(),jt&&(clearTimeout(jt),jt=null),e.quiet&&(xo=!0);let t=l.machineId||(typeof localStorage<"u"?localStorage.getItem("machineId"):null);Rc!==t&&(ua(),Rc=t);let n=++Js;try{l.ws?.close()}catch{}me.value="connecting",Vs();let s=location.protocol==="https:"?"wss":"ws",a=new URLSearchParams;l.token&&a.set("token",l.token),t&&a.set("machine",t),l.sessionId&&a.set("sessionId",l.sessionId),l.agent&&a.set("agent",l.agent);let o=Tp();o&&a.set("lastSeq",String(o));let r=new WebSocket(`${s}://${location.host}/ws/chat?${a}`);l.ws=r,r.addEventListener("open",()=>{if(n===Js){if(at=1e3,At=Date.now(),me.value="open",Vs(),l.sessionId)try{r.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}da(),Ip(),jp(r,n),Dt(),vo&&!xo&&H(t?`\u5DF2\u91CD\u8FDE \xB7 ${t}`:"\u5DF2\u91CD\u8FDE"),vo=!1,xo=!1}}),r.addEventListener("message",d=>{if(n!==Js)return;let u;try{u=JSON.parse(d.data)}catch{return}if(Cp(u)){if(u.type==="pong"){At=Date.now();return}if(u.type==="ping"){if(At=Date.now(),r.readyState===WebSocket.OPEN)try{r.send(JSON.stringify({type:"pong"}))}catch{}return}if(u.type==="run-status"){if(u.sessionId&&u.sessionId!==l.sessionId)return;if(typeof u.running!="boolean"){l.nativeRunNotice={sessionId:l.sessionId,message:u.message||"\u7EC8\u7AEF\u4F1A\u8BDD\u672A\u786E\u8BA4\u7ED3\u675F"},Wt();return}l.nativeRunNotice=null,Wt(),u.running?P.value=!0:(P.peek()&&(P.value=!1),mi()),Dt();return}Vc(u)}}),r.addEventListener("close",()=>{n===Js&&(Qc(),vo=!0,me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Vs(),Ap())}),r.addEventListener("error",()=>{})}function mi(){if(!In.length||P.peek())return;let e=Zs(),t=In.findIndex(a=>a.key===e);if(t<0)return;let[n]=In.splice(t,1);zc();let s=i("chat-input");s&&(s.value=n.text,Xs(s)),setTimeout(()=>{if(n.key!==Zs()||P.peek()){Kc.set(n.key,n.text);return}ea()},0)}function ho(){P.value=!1,Dt(),mi()}var _p=0;function Vc(e){if(!(e?.sessionId&&l.sessionId&&e.sessionId!==l.sessionId)){if(e&&typeof e.type=="string"&&(e.type==="note.added"||e.type==="note.updated"||e.type==="note.removed"||e.type==="queue.item.added"||e.type==="queue.item.updated"||e.type==="queue.item.removed"||e.type==="queue.item.moved"||e.type==="queue.item.sending")){window.dispatchEvent(new CustomEvent("hub-ws-message",{detail:e}));let t={"note.added":"hub:note-added","note.updated":"hub:note-updated","note.removed":"hub:note-removed"}[e.type];t&&window.dispatchEvent(new CustomEvent(t,{detail:e}))}if(e._hubReplay===!0){document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="batch"&&Array.isArray(e.items)){for(let t of e.items)Vc(t);return}if(["assistant","assistant_stream_start","assistant_delta","thought_delta","tool_use"].includes(e.type)&&_p++,e.type==="session-created"){let t=N.peek();l.sessionId=e.sessionId,e.agent&&e.agent!==$.peek()&&Ne(e.agent),se(t,e.agent||$.peek(),e.sessionId),document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-sessions-changed"){document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-session-updated"){document.dispatchEvent(new CustomEvent("sessions-changed")),document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="notification"&&e.notification){wa(e.notification);return}if(e.type==="grok-queue-status"){ef(e);return}if(e.type==="result"){Qs(),zs(),is();let t=e.usage;if(t){let n={input_tokens:t.inputTokens??t.input_tokens,output_tokens:t.outputTokens??t.output_tokens,cache_read_input_tokens:t.cacheReadInputTokens??t.cache_read_input_tokens,cache_creation_input_tokens:t.cacheCreationInputTokens??t.cache_creation_input_tokens,total_tokens:t.totalTokens??t.total_tokens,reasoning_tokens:t.reasoningTokens??t.reasoning_tokens,costUSD:t.costUSD??t.cost_usd};l.lastUsage=n,l.sessionId&&(l.lastUsageSessionId=l.sessionId),yo(n)}e.is_error||H("\u2713 Done"),ho();return}if(e.type==="complete"){Qs(),zs(),is(),!e.aborted&&e.agent==="claude"?H("\u2713 Done"):!e.aborted&&e.agent&&e.agent!=="claude"&&!e.error||(!e.aborted&&!e.agent?H("\u2713 Done"):e.aborted&&H("\u5DF2\u505C\u6B62")),ho();return}if(e.type==="error"){Qs(),zs(),(e.code===423||/locked/i.test(String(e.message||"")))&&(l.lock={...l.lock||{},held:!1,foreign:!0,holder:e.lock?.holder||l.lock?.holder||"another user"},Wt()),ls("error","Error",Sp(e.message)),ho();return}if(e.type==="shell-start"){l.shellBubble=null;return}if(e.type==="shell-output"){l.shellBubble||(l.shellBubble=sf(e.stream==="stderr"?"shell-err":"shell")),af(l.shellBubble,e.data);return}if(e.type==="shell-exit"){l.shellBubble=null,H(e.code===0?"\u2713 Exit 0":`\u2717 Exit ${e.code}${e.error?": "+e.error:""}`),ho();return}if(e.type==="assistant"){zs();for(let t of e.message?.content||[])t.type==="text"&&t.text?(is(),ls("assistant",$p(),t.text,{ts:e.ts||Date.now()})):t.type==="tool_use"&&lf(t,{ts:e.ts||Date.now()});return}if(e.type==="assistant_stream_start"){P.peek()||(P.value=!0,Dt()),Yc(e.ts);return}if(e.type==="assistant_delta"){P.peek()||(P.value=!0,Dt()),Np(e.data||"");return}if(e.type==="assistant_stream_end"){zs();return}if(e.type==="thought_stream_start"){Xc();return}if(e.type==="thought_delta"){Pp(e.data||"");return}if(e.type==="thought_stream_end"){Qs();return}if(e.type==="status"){let t=i("stream-status");if(t)t.textContent=e.message||"";else{let n=i("messages");n&&e.message&&(n.insertAdjacentHTML("beforeend",`<div id="stream-status" class="text-center text-[10px] text-base-content/35 py-0.5">${p(e.message)}</div>`),Re(n))}return}if(e.type==="permission_resolved"){let t=e.requestId||e.request_id;t&&i(`perm-${t}`)?.remove();return}(e.type==="permission_request"||e.request_id&&e.tool_name)&&cf(e)}}var st=null,Ge=null,Ft=null,ht=null;function Yc(e){let t=i("messages");if(!t||(is(),Qs(),st&&t.contains(st)))return;let n=So(e||Date.now()),s=Lo(e||Date.now());t.insertAdjacentHTML("beforeend",`
1147
+ </button>`).join("")}),je(()=>{_t.value,Zt.value,gt.value,rt.value,T.value;let c=i("session-list");if(!c||c.querySelector(".session-rename-input"))return;let f=Jr();if(c._lastHtml===f){Bs();return}let m=c.scrollTop;c.innerHTML=f,c._lastHtml=f,c.scrollTop=m,Bs()}),je(()=>{bt.value,Bs()}),je(()=>{ne.value,ye.value,_.value,M.value;let c=i("welcome");c&&(document.documentElement.classList.contains("boot-restore")||document.documentElement.classList.contains("boot-pending")||c.classList.contains("hidden")||c.style.display==="none"||wn())}),De(ke,c=>{let f=i("session-filter-badge");f&&(f.style.display=c?"inline":"none",f.title=c||"")}),je(()=>{let c=E.value;if(c&&c.path)$c(c.path);else{let f=i("project-notes-bar");f&&(f.style.display="none")}}),De(X,c=>{document.querySelectorAll("[data-tab]").forEach(m=>{let g=m.dataset.tab===c;m.classList.toggle("text-primary",g),m.classList.toggle("border-primary",g),m.classList.toggle("text-base-content/50",!g),m.classList.toggle("border-transparent",!g)});let f=i("project-view");f&&!f.classList.contains("hidden")&&(f.style.display="flex",f.style.flexDirection="column",f.style.minHeight="0",f.style.flex="1"),["chat","files","git","shell","memory"].forEach(m=>{let g=i(`tab-${m}`);if(!g)return;let w=m===c;g.classList.toggle("hidden",!w),w?(g.style.display="flex",g.style.flexDirection="column",g.style.flex="1 1 0",g.style.minHeight="0",g.style.overflow="hidden"):g.style.display="none"}),c==="memory"&&no(),c==="shell"&&requestAnimationFrame(()=>{document.dispatchEvent(new CustomEvent("shell-tab-shown"))}),Ee()}),Pc(),Nc(),nl({openSession:nt});let s=c=>{i("app")?.classList.toggle("chat-chrome-collapsed",c),i("btn-expand-chat-chrome")?.classList.toggle("hidden",!c),localStorage.setItem("chatChromeCollapsed",c?"1":"0")};s(localStorage.getItem("chatChromeCollapsed")==="1");let a=null;document.addEventListener("sessions-changed",()=>{a&&clearTimeout(a),a=setTimeout(()=>{a=null,We({waitFresh:!1})},1200)}),document.addEventListener("router:home",fo),document.addEventListener("router:session",async({detail:{id:c,tab:f,machineId:m,agent:g}})=>{let w=ne.peek().find(A=>A.sessionId===c),y=tn();await nt(c,w?.cwd||(y?.sessionId===c?y.cwd:null)||null,w?.configDir||(y?.sessionId===c?y.configDir:null)||null,g||w?.agent||(y?.sessionId===c?y.agent:null)||null,m||w?.machineId||(y?.sessionId===c?y.machineId:null)||null,{tab:f||"chat"})}),b.on("click","#btn-home",fo),b.on("click","#btn-share-session, #btn-share-session-current",async(c,f)=>{let m=El();if(m)try{await navigator.clipboard.writeText(m),f.classList.add("is-copied"),f.title="\u5DF2\u590D\u5236\u5206\u4EAB\u94FE\u63A5",setTimeout(()=>{f.classList.remove("is-copied"),f.title="\u590D\u5236\u5F53\u524D\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5"},1400)}catch{window.prompt("\u590D\u5236\u4F1A\u8BDD\u94FE\u63A5\uFF1A",m)}}),b.on("click","#auth-btn",ii),b.on("submit","#auth-form",c=>{c.preventDefault(),ii()}),b.on("keydown","#auth-username, #auth-password",c=>{c.key==="Enter"&&ii()}),b.on("click","#hamburger",()=>i("sidebar").classList.contains("open")?Ks():Dc()),b.on("click","#sidebar-overlay",Ks),document.addEventListener("keydown",c=>{c.key==="Escape"&&window.innerWidth<=640&&i("sidebar")?.classList.contains("open")&&(c.preventDefault(),Ks())}),b.on("input","#session-search",(c,f)=>{$e.value=f.value,to(f.value)}),b.on("click","#sidebar-filter-toggle",()=>{let c=i("sidebar-filter-menu");if(!c)return;let f=c.classList.toggle("hidden");i("sidebar-filter-toggle")?.setAttribute("aria-expanded",String(!f))}),b.on("change","[data-agent-option]",(c,f)=>{let m=new Set(Vt.peek());f.checked?m.add(f.dataset.agentOption):m.delete(f.dataset.agentOption);let g=[...m];Vt.value=g,localStorage.setItem("agentFilters",JSON.stringify(g)),ye.value=g.length===1?g[0]:"all"}),b.on("change","#filter-favorites",(c,f)=>{ze.value=f.checked,localStorage.setItem("favoritesOnly",f.checked?"1":"0")}),b.on("change","#filter-hidden",(c,f)=>{Je.value=f.checked,localStorage.setItem("showHiddenOnly",f.checked?"1":"0")}),b.on("click","#filter-clear",()=>{Vt.value=[],ye.value="all",ze.value=!1,Je.value=!1,localStorage.setItem("agentFilters","[]"),localStorage.setItem("favoritesOnly","0"),localStorage.setItem("showHiddenOnly","0"),document.querySelectorAll("[data-agent-option]").forEach(c=>{c.checked=!1}),i("filter-favorites")&&(i("filter-favorites").checked=!1),i("filter-hidden")&&(i("filter-hidden").checked=!1)}),b.on("click","#session-filter-badge",()=>{ke.value=null}),b.on("click","[data-ws-tab]",(c,f)=>{ke.value=f.dataset.wsTab||null}),b.on("click","#sidebar-refresh",()=>{We(),$e.peek().trim()&&eo($e.peek())}),b.on("click","[data-view]",(c,f)=>{gt.value=f.dataset.view,localStorage.setItem("sidebarView",f.dataset.view)}),b.on("click","[data-agent-filter]",(c,f)=>{ye.value=f.dataset.agentFilter,localStorage.setItem("agentFilter",f.dataset.agentFilter),$e.peek().trim()&&to($e.peek())}),b.on("dblclick","[data-project-cwd]",(c,f)=>{let m=f.dataset.projectCwd;if(!m)return;let g=m.split("/").filter(Boolean).pop()||m;ti({id:g,name:g,path:m}),C(`Project \xB7 ${m}`)}),b.on("click","#btn-pwa-install",async()=>{await Bi()||kp()}),document.addEventListener("pwa-installable",()=>{document.getElementById("btn-pwa-install")?.classList.remove("hidden")}),b.on("click","#btn-settings",Ba),b.on("click","#btn-notes",()=>Oa()),b.on("click","#btn-collapse-chat-chrome",()=>s(!0)),b.on("click","#btn-expand-chat-chrome",()=>s(!1)),b.on("click","#btn-meta-agent",()=>Ql()),b.on("click","#btn-meta-agent-welcome",()=>Pr("chat")),b.on("click","#btn-theme",si),b.on("click","[data-sidebar-action]",(c,f)=>{let m=f.dataset.sidebarAction;m==="new"&&ai(),m==="theme"&&si(),m==="settings"&&Ba(),m==="logout"&&(l.token=null,localStorage.removeItem("token"),Le(null),it.value=!1,location.reload())}),b.on("click","#btn-cal-prev",()=>{Fr(-1),wn(yn())}),b.on("click","#btn-cal-next",()=>{Fr(1),wn(yn())}),b.on("click","[data-cal-date]",(c,f)=>{fc(f.dataset.calDate),wn(yn())}),b.on("click","[data-session-id]",(c,f)=>{c.target.closest("[data-fav-toggle]")||c.target.closest("[data-hide-toggle]")||c.target.closest("[data-rename-session]")||c.target.closest(".session-rename-input")||c.target.closest(".session-title-wrap.session-rename-active")||(nt(f.dataset.sessionId,f.dataset.sessionCwd||null,f.dataset.sessionConfigDir||null,f.dataset.sessionAgent||"claude",f.dataset.sessionMachine||null),_c())}),b.on("click","[data-rename-session]",(c,f)=>{c.preventDefault(),c.stopPropagation();let m=f.closest(".session-title-wrap")||f,g=m.dataset.renameSessionId||m.dataset.sessionId;g&&Yr({sessionId:g,agent:m.dataset.renameSessionAgent||"claude",machineId:m.dataset.renameSessionMachine||null,fallbackDisplay:m.dataset.renameSessionDisplay||"",mountEl:m})}),b.on("click","[data-rename-bar]",(c,f)=>{if(c.preventDefault(),c.stopPropagation(),!l.sessionId)return;let m=document.getElementById("session-title-display")||f;Yr({sessionId:l.sessionId,agent:l.agent||$.peek()||"claude",machineId:l.machineId||null,mountEl:m})}),b.on("click","[data-folder]",(c,f)=>{let m=f.dataset.folder,w=f.querySelector("span")?.textContent.trim()==="\u25BE",y=new Set(jn.peek()),A=new Set(Dn.peek());w?(y.delete(m),A.add(m)):(y.add(m),A.delete(m)),xe(()=>{jn.value=y,Dn.value=A})}),b.on("click","#memory-refresh",no),b.on("click","[data-memory-file]",c=>Qr(c.dataset.memoryFile,c.dataset.memoryAgent)),b.on("click","[data-tab]",(c,f)=>Ct(f.dataset.tab));let o=async(c,f)=>{let m=i(c),g=m?.value.trim();if(!g){f.value="";return}try{let w=await x("POST","/api/resolve-path",{path:g});if(w.isDir===!1)throw new Error("Path is not a directory on the target machine");f.value=w.path,m.value=w.path;let y=E.peek();y&&(E.value={...y,path:w.path})}catch(w){m.style.color="oklch(var(--er))",m.title=w.message,setTimeout(()=>{m.style.color="",m.title=""},2e3)}};b.on("click","#files-root-btn",()=>o("files-root-input",ie)),b.on("click","#git-root-btn",()=>o("git-root-input",Se)),b.on("keydown","#files-root-input",c=>{c.key==="Enter"&&o("files-root-input",ie)}),b.on("keydown","#git-root-input",c=>{c.key==="Enter"&&o("git-root-input",Se)}),b.on("click","#btn-opts",()=>{i("chat-opts").classList.toggle("hidden"),Ee()}),b.on("change","#sel-agent",(c,f)=>{let m=$.peek(),g=f.value;m!==g&&(l.sessionId=null,Ne(g),se(Oe(g)||N.peek()),i("sel-permission").value=ue.peek(),et(),C(`Agent \u2192 ${Z[g]||g} \xB7 model ${N.peek()} \xB7 new session`))}),b.on("change","#sel-convert-agent",async(c,f)=>{let m=f.value;if(!m)return;let g=l.sessionId;if(!g){alert("No active session to convert."),f.value="";return}let w=l.agent||$.peek()||"claude";if(w===m){alert("Cannot convert to the same agent."),f.value="";return}f.disabled=!0,C(`Converting session ${g.slice(0,8)} from ${w} to ${m}...`);try{let y=await x("POST",`/api/sessions/${g}/convert`,{targetAgent:m,sourceAgent:w});y&&y.success?(C(`\u2713 Converted successfully. New session: ${y.targetSessionId.slice(0,8)}`),await We(),await nt(y.targetSessionId,E.peek()?.path||null,null,y.targetAgent),Ts()):C("Failed to convert session.")}catch(y){C(`Error converting session: ${y.message}`),alert(`Error converting session: ${y.message}`)}finally{f.disabled=!1,f.value=""}}),b.on("change","#sel-model",(c,f)=>{se(f.value),Xa()}),b.on("click","#btn-model-add",()=>Za({editCurrent:!1})),b.on("click","#btn-model-edit",()=>Za({editCurrent:!0})),b.on("change","#sel-effort",(c,f)=>{te.value=f.value}),b.on("change","#sel-permission",(c,f)=>{ue.value=f.value}),b.on("change","#sel-density",(c,f)=>{Ko(f.value),C(`Density \u2192 ${f.value} (applies to new tool calls; reload session to re-group history)`)}),document.addEventListener("agent-changed",et),b.on("click","#btn-new-session, #btn-new-session-current, #btn-new-session-welcome",ai),b.on("click","#new-session-cancel",()=>i("modal-new-session").close()),b.on("click","#new-session-start",ri),b.on("change","#new-session-agent",oi),b.on("keydown","#new-session-path",c=>{c.key==="Enter"&&ri()}),b.on("click","#send-btn",Is),b.on("click","#stop-btn",hl),b.on("click","#btn-logout",()=>{l.token=null,localStorage.removeItem("token"),Le(null),it.value=!1,location.reload()}),b.on("click","[data-pick-machine]",async(c,f)=>{let m=f.dataset.pickMachine;if(!m||m===_.peek()){Ln();return}await Zr(m,{forceReload:!0}),ya()});let r=async()=>{let c=i("machine-picker-status");if(c&&(c.textContent="\u5237\u65B0\u4E2D\u2026"),await $n(),lo(),Fs(),Ot(),c){let f=(le.peek()||[]).filter(m=>m.online!==!1).length;c.textContent=`${f} online`}};b.on("click","#btn-refresh-machines",r),b.on("click","#btn-refresh-machines-menu",async c=>{c.stopPropagation(),await r()}),b.on("click","#btn-machine-menu",async c=>{c.stopPropagation(),kn(),ln();let f=i("machine-menu");f&&(f.classList.contains("hidden")?(await $n(),Fs(),f.classList.remove("hidden")):f.classList.add("hidden"))}),b.on("click","#btn-recent-sessions",c=>{c.preventDefault(),c.stopPropagation(),Ln(),ln(),pc();let f=!i("recent-menu")?.classList.contains("hidden"),m=i("btn-recent-sessions");m&&m.setAttribute("aria-expanded",f?"true":"false")}),b.on("click","#recent-menu-backdrop",c=>{c.preventDefault(),c.stopPropagation(),kn(),i("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),document.addEventListener("click",c=>{let f=i("machine-menu-wrap");f&&!f.contains(c.target)&&Ln();let m=i("recent-menu"),g=i("btn-recent-sessions"),w=c.target;if(m&&!m.classList.contains("hidden")){if(m.contains(w)||g?.contains(w))return;kn(),g?.setAttribute("aria-expanded","false")}}),b.on("click","#btn-notifications",c=>{c.preventDefault(),c.stopPropagation(),Ln(),kn(),tl()}),window.addEventListener("resize",()=>{i("recent-menu")&&!i("recent-menu").classList.contains("hidden")&&Or()}),b.on("click","#recent-menu [data-session-id]",()=>{kn(),i("btn-recent-sessions")?.setAttribute("aria-expanded","false")}),b.on("click","[data-dismiss-recent-session]",(c,f)=>{c.preventDefault(),c.stopPropagation(),dc({sessionId:f.dataset.dismissRecentSession,agent:f.dataset.dismissRecentAgent||"claude",machineId:f.dataset.dismissRecentMachine||null})}),b.on("click","#btn-edit-project-notes, #project-goal-text, #project-notes-text",()=>{Sc()}),b.on("click","#btn-cancel-project-notes",()=>{as()});let d=async()=>{let c=i("project-goal-input")?.value?.trim()??"",f=i("project-notes-input")?.value?.trim()??"",m=E.peek();if(!(!m||!m.path))try{let g=await x("POST","/api/projects/notes",{root:m.path,goal:c,notes:f});kc(g.goal||"",g.notes||""),as()}catch(g){alert(`Error saving project notes: ${g.message}`)}};b.on("click","#btn-save-project-notes",d),b.on("keydown","#project-goal-input",c=>{c.key==="Enter"&&d(),c.key==="Escape"&&as()}),b.on("keydown","#project-notes-input",c=>{c.key==="Escape"&&as()}),b.on("click","[data-fav-toggle]",(c,f)=>{c.stopPropagation(),c.preventDefault();let m=f.dataset.favSessionMachine||l.machineId;m&&(l.machineId=m,localStorage.setItem("machineId",m)),Ic(f.dataset.favSessionId,f.dataset.favSessionAgent||"claude",{machineId:m||null})}),b.on("click","[data-hide-toggle]",(c,f)=>{c.stopPropagation(),c.preventDefault();let m=f.dataset.hideSessionMachine||l.machineId;m&&(l.machineId=m,localStorage.setItem("machineId",m)),Tc(f.dataset.hideSessionId,f.dataset.hideSessionAgent||"claude",{machineId:m||null})}),b.on("click","#btn-edit-session-notes, #session-notes-text",()=>{Lc()}),b.on("click","#btn-cancel-session-notes",()=>tt()),b.on("click","#btn-save-session-notes",async()=>{let c=i("session-notes-input")?.value?.trim()||"";if(!l.sessionId)return;let f=l.agent||$.peek()||"claude";await Vr(l.sessionId,f,c)&&tt()}),b.on("keydown","#session-notes-input",async c=>{if(c.key==="Escape"&&tt(),c.key==="Enter"){let f=c.target.value.trim();if(!l.sessionId)return;let m=l.agent||$.peek()||"claude";await Vr(l.sessionId,m,f)&&tt()}}),b.on("click","#btn-fav-filter",()=>{let c=!ze.peek();ze.value=c,localStorage.setItem("favoritesOnly",c?"1":"0"),i("btn-fav-filter")?.classList.toggle("active",c),c&&Je.peek()&&(Je.value=!1,localStorage.setItem("showHiddenOnly","0"),i("btn-hidden-filter")?.classList.remove("active"))}),b.on("click","#btn-hidden-filter",()=>{let c=!Je.peek();Je.value=c,localStorage.setItem("showHiddenOnly",c?"1":"0"),i("btn-hidden-filter")?.classList.toggle("active",c),c&&ze.peek()&&(ze.value=!1,localStorage.setItem("favoritesOnly","0"),i("btn-fav-filter")?.classList.remove("active"))}),et(),je(()=>{M.value,_.value,l.token&&ya()}),i("sel-permission").value=ue.peek(),yl();let u=i("sel-density");u&&(u.value=_e.peek()||"normal"),document.querySelectorAll("[data-agent-option]").forEach(c=>{c.checked=Vt.peek().includes(c.dataset.agentOption)}),i("filter-favorites")&&(i("filter-favorites").checked=ze.peek()),i("filter-hidden")&&(i("filter-hidden").checked=Je.peek()),document.querySelectorAll("[data-agent-filter]").forEach(c=>{c.classList.toggle("active",c.dataset.agentFilter===ye.peek())}),i("btn-fav-filter")?.classList.toggle("active",ze.peek()),i("btn-hidden-filter")?.classList.toggle("active",Je.peek()),document.querySelectorAll("[data-view]").forEach(c=>{let f=c.dataset.view===gt.peek();c.classList.toggle("bg-primary/15",f),c.classList.toggle("text-primary",f),c.classList.toggle("font-medium",f),c.classList.toggle("text-base-content/50",!f)})}K();tr();G();ce();bs();rr();ka();Hn();nn();sn();lr();Nt();Nt();function $p(){return Z[$.peek()]||"Assistant"}function Sp(e){let t=String(e||"").trim();return/remote compact task|error decoding response body/i.test(t)?"Codex \u4F1A\u8BDD\u538B\u7F29\u5931\u8D25\uFF08\u7F51\u7EDC\u4E2D\u65AD\uFF09\u3002\u518D\u53D1\u4E00\u6761\u6D88\u606F\u91CD\u8BD5\uFF0C\u6216\u5F00\u65B0\u4F1A\u8BDD\u3002":t||"\u53D1\u9001\u5931\u8D25"}var En=null;function Lp(e){return ys(e)}function Gc(e){return e?(En&&En.el===e||(En?.destroy?.(),En=$a(e),En.el=e),En):null}function Re(e,t){if(!e||e.dataset.historyPainting==="1")return;Gc(e).stick(!!t)}var Js=0,jt=null,at=1e3,At=0,bo=null,qc=!1,vo=!1,Rc=null,xo=!1,ui="hubStreamCursors",Io=new Map,Ep=0,pi=new Set,fi="pendingUserTexts",In=(()=>{try{let e=JSON.parse(sessionStorage.getItem(fi)||"[]");return Array.isArray(e)?e.filter(t=>t?.key&&t?.text).slice(-30):[]}catch{return[]}})(),Bc=new Set,Kc=new Map;function zc(){try{In.length?sessionStorage.setItem(fi,JSON.stringify(In.slice(-30))):sessionStorage.removeItem(fi)}catch{}}function Ip(){let e=Zs(),t=In.filter(n=>n.key===e).length;t&&!Bc.has(e)&&(Bc.add(e),H(`\u231B Restored ${t} queued prompt${t===1?"":"s"} in this browser tab`))}function Jc(e=l.sessionId,t=l.agent,n=l.machineId){return e?`${n||""}:${t||"claude"}:${e}`:""}function Tp(e={}){let t=Jc(e.sessionId,e.agent,e.machineId);if(!t)return 0;try{return Number(JSON.parse(localStorage.getItem(ui)||"{}")[t])||0}catch{return 0}}function Cp(e){let t=Number(e?.hubSeq)||0;if(!t)return!0;let n=Jc(e.sessionId||l.sessionId,e.agent||l.agent,l.machineId);if(!n)return!0;let s={};try{s=JSON.parse(localStorage.getItem(ui)||"{}")||{}}catch{}let a=Number(s[n])||0;if(t<=a)return!1;s[n]=t;let o=Object.keys(s);o.length>500&&o.sort((r,d)=>Number(s[d])-Number(s[r])).slice(500).forEach(r=>delete s[r]);try{localStorage.setItem(ui,JSON.stringify(s))}catch{}return!0}function Zs({sessionId:e=l.sessionId,agent:t=l.agent,machineId:n=l.machineId}={}){return e?`${n||""}:${t||"claude"}:${e}`:null}function Mp(){qc||(qc=!0,document.addEventListener("visibilitychange",()=>{if(document.visibilityState==="visible"&&(at=400,rs({probe:!0}),l.ws?.readyState===WebSocket.OPEN&&l.sessionId))try{l.ws.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}}),window.addEventListener("online",()=>{at=400,rs({force:!0})}),window.addEventListener("pageshow",e=>{e.persisted?rs({force:!0}):rs({probe:!0})}),window.addEventListener("focus",()=>rs({probe:!0})),navigator.connection?.addEventListener?.("change",()=>{at=400,rs({probe:!0})}))}function Vs(){let e=i("conn-dot");if(!e)return;let t=me.peek();e.classList.remove("bg-success","bg-warning","bg-error","bg-base-content/30","animate-pulse"),t==="open"?(e.classList.add("bg-success"),e.title="\u5DF2\u8FDE\u63A5"):t==="connecting"||t==="reconnecting"?(e.classList.add("bg-warning","animate-pulse"),e.title=t==="connecting"?"\u8FDE\u63A5\u4E2D\u2026":"\u91CD\u8FDE\u4E2D\u2026"):t==="offline"?(e.classList.add("bg-error"),e.title="\u79BB\u7EBF"):(e.classList.add("bg-base-content/30"),e.title="\u672A\u8FDE\u63A5")}function rs(e={}){let t=l.ws?.readyState;if(e.force){at=400,$o({quiet:!0});return}if(t===WebSocket.OPEN){if(e.probe&&At&&Date.now()-At>45e3)try{l.ws.close()}catch{}else if(e.probe&&l.ws.readyState===WebSocket.OPEN)try{l.ws.send(JSON.stringify({type:"ping"}))}catch{}return}t!==WebSocket.CONNECTING&&(at=Math.min(at,800),$o({quiet:!0}))}function Ap(){jt||(me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Vs(),jt=setTimeout(()=>{jt=null,$o({quiet:!0})},at),at=Math.min(Math.round(at*1.8),15e3))}function Qc(){bo&&(clearInterval(bo),bo=null)}function jp(e,t){Qc(),bo=setInterval(()=>{if(!(t!==Js||e.readyState!==WebSocket.OPEN)){if(At&&Date.now()-At>7e4){try{e.close()}catch{}return}if(!(typeof document<"u"&&document.visibilityState==="hidden")&&At&&Date.now()-At>4e4)try{e.send(JSON.stringify({type:"ping"}))}catch{}}},3e4)}function Dt(){let e=P.peek()||!!E.peek()&&me.peek()==="open";xa(e)}function ko(){return(l.role||"editor")==="viewer"?"\u53EA\u8BFB\u8D26\u53F7\uFF0C\u65E0\u6CD5\u8F93\u5165":l.lock?.foreign?`\u4F1A\u8BDD\u7531 ${l.lock.holder&&l.lock.holder!=="viewer"?l.lock.holder:"\u5176\u4ED6\u7528\u6237"} \u5360\u7528\uFF08\u9501\uFF09`:"\u5F53\u524D\u65E0\u6CD5\u8F93\u5165"}function Wt(){let e=an();l.externalSessionReadOnly=!e;let t=i("chat-input"),n=i("send-btn"),s=i("btn-attach"),a=i("session-lock-banner");if(t&&(t.disabled=!e,t.readOnly=!e,e?P.peek()?t.placeholder="\u56DE\u590D\u4E2D\u2026 \u53EF\u5148\u5199\u597D\u4E0B\u4E00\u6761\uFF0C\u7ED3\u675F\u540E\u81EA\u52A8\u53D1\u9001 \xB7 \u6216\u70B9 \u25A0 \u505C\u6B62":Ys(t.value||""):t.placeholder=ko()),n&&(n.disabled=!e),s&&(s.disabled=!e),a)if(!e)a.classList.remove("hidden"),a.textContent=ko();else{let o=l.nativeRunNotice?.sessionId===l.sessionId?l.nativeRunNotice.message:"";a.classList.toggle("hidden",!o),a.textContent=o}}function Dp(){at=400,jt&&(clearTimeout(jt),jt=null),xo=!1;let e=l.ws?.readyState;if(e===WebSocket.OPEN||e===WebSocket.CONNECTING)try{l.ws?.close()}catch{}$o({quiet:!1}),H("\u6B63\u5728\u91CD\u65B0\u8FDE\u63A5\u5E76\u540C\u6B65\u2026")}function $o(e={}){Mp(),jt&&(clearTimeout(jt),jt=null),e.quiet&&(xo=!0);let t=l.machineId||(typeof localStorage<"u"?localStorage.getItem("machineId"):null);Rc!==t&&(ua(),Rc=t);let n=++Js;try{l.ws?.close()}catch{}me.value="connecting",Vs();let s=location.protocol==="https:"?"wss":"ws",a=new URLSearchParams;l.token&&a.set("token",l.token),t&&a.set("machine",t),l.sessionId&&a.set("sessionId",l.sessionId),l.agent&&a.set("agent",l.agent);let o=Tp();o&&a.set("lastSeq",String(o));let r=new WebSocket(`${s}://${location.host}/ws/chat?${a}`);l.ws=r,r.addEventListener("open",()=>{if(n===Js){if(at=1e3,At=Date.now(),me.value="open",Vs(),l.sessionId)try{r.send(JSON.stringify({type:"subscribe",sessionId:l.sessionId,agent:l.agent}))}catch{}da(),Ip(),jp(r,n),Dt(),vo&&!xo&&H(t?`\u5DF2\u91CD\u8FDE \xB7 ${t}`:"\u5DF2\u91CD\u8FDE"),vo=!1,xo=!1}}),r.addEventListener("message",d=>{if(n!==Js)return;let u;try{u=JSON.parse(d.data)}catch{return}if(Cp(u)){if(u.type==="pong"){At=Date.now();return}if(u.type==="ping"){if(At=Date.now(),r.readyState===WebSocket.OPEN)try{r.send(JSON.stringify({type:"pong"}))}catch{}return}if(u.type==="run-status"){if(u._hubReplay||u.sessionId&&u.sessionId!==l.sessionId)return;if(typeof u.running!="boolean"){l.nativeRunNotice={sessionId:l.sessionId,message:u.message||"\u7EC8\u7AEF\u4F1A\u8BDD\u672A\u786E\u8BA4\u7ED3\u675F"},Wt();return}l.nativeRunNotice=null,Wt(),u.running?P.value=!0:(P.peek()&&(P.value=!1),mi()),Dt();return}Vc(u)}}),r.addEventListener("close",()=>{n===Js&&(Qc(),vo=!0,me.value=typeof navigator<"u"&&navigator.onLine===!1?"offline":"reconnecting",Vs(),Ap())}),r.addEventListener("error",()=>{})}function mi(){if(!In.length||P.peek())return;let e=Zs(),t=In.findIndex(a=>a.key===e);if(t<0)return;let[n]=In.splice(t,1);zc();let s=i("chat-input");s&&(s.value=n.text,Xs(s)),setTimeout(()=>{if(n.key!==Zs()||P.peek()){Kc.set(n.key,n.text);return}ea()},0)}function ho(){P.value=!1,Dt(),mi()}var _p=0;function Vc(e){if(!(e?.sessionId&&l.sessionId&&e.sessionId!==l.sessionId)){if(e&&typeof e.type=="string"&&(e.type==="note.added"||e.type==="note.updated"||e.type==="note.removed"||e.type==="queue.item.added"||e.type==="queue.item.updated"||e.type==="queue.item.removed"||e.type==="queue.item.moved"||e.type==="queue.item.sending")){window.dispatchEvent(new CustomEvent("hub-ws-message",{detail:e}));let t={"note.added":"hub:note-added","note.updated":"hub:note-updated","note.removed":"hub:note-removed"}[e.type];t&&window.dispatchEvent(new CustomEvent(t,{detail:e}))}if(e._hubReplay===!0){document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="batch"&&Array.isArray(e.items)){for(let t of e.items)Vc(t);return}if(["assistant","assistant_stream_start","assistant_delta","thought_delta","tool_use"].includes(e.type)&&_p++,e.type==="session-created"){let t=N.peek();l.sessionId=e.sessionId,e.agent&&e.agent!==$.peek()&&Ne(e.agent),se(t,e.agent||$.peek(),e.sessionId),document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-sessions-changed"){document.dispatchEvent(new CustomEvent("sessions-changed"));return}if(e.type==="external-session-updated"){document.dispatchEvent(new CustomEvent("sessions-changed")),document.dispatchEvent(new CustomEvent("external-session-updated",{detail:e}));return}if(e.type==="notification"&&e.notification){wa(e.notification);return}if(e.type==="grok-queue-status"){ef(e);return}if(e.type==="result"){Qs(),zs(),is();let t=e.usage;if(t){let n={input_tokens:t.inputTokens??t.input_tokens,output_tokens:t.outputTokens??t.output_tokens,cache_read_input_tokens:t.cacheReadInputTokens??t.cache_read_input_tokens,cache_creation_input_tokens:t.cacheCreationInputTokens??t.cache_creation_input_tokens,total_tokens:t.totalTokens??t.total_tokens,reasoning_tokens:t.reasoningTokens??t.reasoning_tokens,costUSD:t.costUSD??t.cost_usd};l.lastUsage=n,l.sessionId&&(l.lastUsageSessionId=l.sessionId),yo(n)}e.is_error||H("\u2713 Done"),ho();return}if(e.type==="complete"){Qs(),zs(),is(),!e.aborted&&e.agent==="claude"?H("\u2713 Done"):!e.aborted&&e.agent&&e.agent!=="claude"&&!e.error||(!e.aborted&&!e.agent?H("\u2713 Done"):e.aborted&&H("\u5DF2\u505C\u6B62")),ho();return}if(e.type==="error"){Qs(),zs(),(e.code===423||/locked/i.test(String(e.message||"")))&&(l.lock={...l.lock||{},held:!1,foreign:!0,holder:e.lock?.holder||l.lock?.holder||"another user"},Wt()),ls("error","Error",Sp(e.message)),ho();return}if(e.type==="shell-start"){l.shellBubble=null;return}if(e.type==="shell-output"){l.shellBubble||(l.shellBubble=sf(e.stream==="stderr"?"shell-err":"shell")),af(l.shellBubble,e.data);return}if(e.type==="shell-exit"){l.shellBubble=null,H(e.code===0?"\u2713 Exit 0":`\u2717 Exit ${e.code}${e.error?": "+e.error:""}`),ho();return}if(e.type==="assistant"){zs();for(let t of e.message?.content||[])t.type==="text"&&t.text?(is(),ls("assistant",$p(),t.text,{ts:e.ts||Date.now()})):t.type==="tool_use"&&lf(t,{ts:e.ts||Date.now()});return}if(e.type==="assistant_stream_start"){P.peek()||(P.value=!0,Dt()),Yc(e.ts);return}if(e.type==="assistant_delta"){P.peek()||(P.value=!0,Dt()),Np(e.data||"");return}if(e.type==="assistant_stream_end"){zs();return}if(e.type==="thought_stream_start"){Xc();return}if(e.type==="thought_delta"){Pp(e.data||"");return}if(e.type==="thought_stream_end"){Qs();return}if(e.type==="status"){let t=i("stream-status");if(t)t.textContent=e.message||"";else{let n=i("messages");n&&e.message&&(n.insertAdjacentHTML("beforeend",`<div id="stream-status" class="text-center text-[10px] text-base-content/35 py-0.5">${p(e.message)}</div>`),Re(n))}return}if(e.type==="permission_resolved"){let t=e.requestId||e.request_id;t&&i(`perm-${t}`)?.remove();return}(e.type==="permission_request"||e.request_id&&e.tool_name)&&cf(e)}}var st=null,Ge=null,Ft=null,ht=null;function Yc(e){let t=i("messages");if(!t||(is(),Qs(),st&&t.contains(st)))return;let n=So(e||Date.now()),s=Lo(e||Date.now());t.insertAdjacentHTML("beforeend",`
1148
1148
  <div class="msg-row assistant px-2 live-stream" data-ts="${p(s)}">
1149
1149
  <div class="max-w-[88%] rounded-2xl rounded-tl-sm px-3 py-2 text-sm bg-base-200 break-words md">
1150
1150
  <div class="msg-stream-body whitespace-pre-wrap"></div>
package/dist/index.html CHANGED
@@ -4,13 +4,13 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
6
6
  <title>Claude Code</title>
7
- <link rel="stylesheet" href="/style.0.2.33.min.css">
7
+ <link rel="stylesheet" href="/style.0.2.34.min.css">
8
8
  <link rel="stylesheet" href="/highlight.min.css">
9
9
  <script src="/marked.min.js"></script>
10
10
  <script src="/highlight.min.js"></script>
11
11
  </head>
12
12
  <body class="h-dvh overflow-hidden flex flex-col bg-base-100 text-base-content">
13
13
  <div id="root" class="flex flex-col flex-1 overflow-hidden"></div>
14
- <script type="module" src="/app.0.2.33.min.js"></script>
14
+ <script type="module" src="/app.0.2.34.min.js"></script>
15
15
  </body>
16
16
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-simple",
3
- "version": "0.2.33",
3
+ "version": "0.2.34",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "claude-simple": "server.js",
package/public/chat.js CHANGED
@@ -394,6 +394,7 @@ export function connectWS(opts = {}) {
394
394
  return;
395
395
  }
396
396
  if (msg.type === 'run-status') {
397
+ if (msg._hubReplay) return;
397
398
  if (msg.sessionId && msg.sessionId !== ctx.sessionId) return;
398
399
  if (typeof msg.running !== 'boolean') {
399
400
  ctx.nativeRunNotice = { sessionId: ctx.sessionId, message: msg.message || '终端会话未确认结束' };
package/public/index.html CHANGED
@@ -85,7 +85,7 @@
85
85
  <script src="/vendor/mermaid.min.js"></script>
86
86
  <link rel="stylesheet" href="/vendor/katex.min.css">
87
87
  <script src="/vendor/katex.min.js"></script>
88
- <link rel="stylesheet" href="style.css?v=ui-27">
88
+ <link rel="stylesheet" href="style.css?v=ui-28">
89
89
  </head>
90
90
  <body class="h-dvh overflow-hidden flex flex-col bg-base-100 text-base-content">
91
91
  <div id="root" class="flex flex-col flex-1 overflow-hidden"></div>
@@ -101,6 +101,6 @@
101
101
  }
102
102
  }, 10000);
103
103
  </script>
104
- <script type="module" src="app.js?v=ui-27"></script>
104
+ <script type="module" src="app.js?v=ui-28"></script>
105
105
  </body>
106
106
  </html>
package/public/sw.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /* Agent UI service worker — cache shell assets only.
2
2
  * Never intercepts WebSocket or mutates API semantics beyond offline fallback.
3
3
  * Bump CACHE when shipping UI that must invalidate old shells. */
4
- const CACHE = 'agent-ui-shell-v36';
4
+ const CACHE = 'agent-ui-shell-v37';
5
5
  const PRECACHE = [
6
6
  '/',
7
7
  '/index.html',
8
8
  '/manifest.webmanifest',
9
- '/style.css?v=ui-27',
9
+ '/style.css?v=ui-28',
10
10
  '/style.css',
11
11
  '/ui.min.css',
12
12
  '/vendor/mini-react.min.js',
@@ -16,7 +16,7 @@ const PRECACHE = [
16
16
  '/vendor/mermaid.min.js',
17
17
  '/vendor/katex.min.js',
18
18
  '/vendor/katex.min.css',
19
- '/app.js?v=ui-27',
19
+ '/app.js?v=ui-28',
20
20
  '/icons/icon-192.png',
21
21
  '/icons/icon-512.png',
22
22
  '/icons/icon-maskable-512.png',