tmux-weblink 3.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/shell-client.js +78 -78
- package/dist/browser/bots-client.js +6 -6
- package/dist/lib/bots/store.js +3 -3
- package/dist/lib/pages/shell.js +109 -56
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{icon as H}from"../lib/icons.js";import{createMarkdownRenderer as bt}from"./markdown.js";const F=bt(document),l={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};let A=[],$=!0,vt=!1,it=0;function U(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function b(t,e){const o=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${U()}`,...e?.headers||{}}}),i=await o.text(),s=i?JSON.parse(i):null;if(!o.ok)throw new Error(s&&s.error||`HTTP ${o.status}`);return s}function n(t,e,o){const i=document.createElement(t);return e&&(i.className=e),o!==void 0&&(i.textContent=o),i}function gt(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function N(){z||(z=requestAnimationFrame(()=>{z=0,yt()}))}let z=0,R="";function yt(){const t=document.getElementById("bots-view");if(!t)return;const e=window.visualViewport,o=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(l.activeId&&e&&o&&!i){const s=document.querySelector(".fixed-header"),r=s?Math.round(s.getBoundingClientRect().height):0,a=Math.round(e.offsetTop)+r,c=Math.round(e.offsetLeft),d=Math.round(e.width),u=Math.max(120,Math.round(e.height)-r),h=`fixed|${a}|${c}|${d}|${u}`;if(h===R)return;R=h,t.style.position="fixed",t.style.top=`${a}px`,t.style.left=`${c}px`,t.style.width=`${d}px`,t.style.height=`${u}px`,t.style.right="auto",t.style.bottom="auto"}else{if(R==="")return;R="",t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}}window.visualViewport?.addEventListener("resize",N),window.visualViewport?.addEventListener("scroll",N),window.addEventListener("resize",N),document.addEventListener("click",N);const st=document.querySelector(".sidebar");st&&new MutationObserver(N).observe(st,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=N;function q(){const t=l.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));const o=document.getElementById("bv-inbox-count");o&&(o.textContent=t?`(${t})`:""),window.__botsSnapshot=l.bots,window.__refreshSidebar?.()}function wt(){const t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),o=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),D()}),e?.addEventListener("click",()=>{i(),Nt()}),o?.addEventListener("click",()=>{i(),ot()})}function kt(){const t=n("div","bots-view");t.id="bots-view",t.hidden=!0;const e=n("div","bots-view-head"),o=n("div","bv-title"),i=n("span","bots-dot");i.id="bv-dot";const s=n("span","bv-title-text");s.id="bv-title";const r=n("span","bv-status");r.id="bv-status",o.append(i,s,r);const a=n("div","bv-actions"),c=n("div","bv-mode"),d=n("button","bv-mode-btn");d.id="bv-mode-btn",d.type="button",d.setAttribute("aria-haspopup","menu"),d.setAttribute("aria-expanded","false"),ut(d,"supervised");const u=n("div","bv-mode-menu");u.id="bv-mode-menu",u.setAttribute("role","menu"),u.hidden=!0;for(const[m,x,v]of[["supervised","\u9ED8\u8BA4","\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09\u76F4\u63A5\u653E\u884C\uFF1Bbash\u3001edit\u3001write\u3001\u6269\u5C55/MCP \u5DE5\u5177\u4F1A\u95EE\u4F60"],["parent-supervised","\u76D1\u7BA1","\u5176\u4F59\u5DE5\u5177\u4EA4\u7ED9\u4E0A\u7EA7 bot \u51B3\u5B9A\uFF08\u5E26\u7406\u7531\uFF09\uFF1B\u4F60\u4ECD\u7136\u80FD\u770B\u5230\u5E76\u56DE\u7B54\uFF0C\u5148\u7B54\u5148\u5F97\uFF1B\u6CA1\u6709\u4E0A\u7EA7\u65F6\u56DE\u843D\u5230\u9ED8\u8BA4"],["full-access","\u5168\u653E\u884C","\u6240\u6709\u5DE5\u5177\u76F4\u63A5\u6267\u884C\uFF0C\u4E0D\u518D\u8BE2\u95EE\u3002\u6CE8\u610F\u8FD9\u4E0D\u662F\u6C99\u7BB1"]]){const _=n("button");_.dataset.mode=m,_.setAttribute("role","menuitemradio"),_.innerHTML=`<span class="bv-mode-row-icon">${H(pt[m],'width="14" height="14"')}</span><span class="bv-mode-row-text"><b>${x}</b><span>${v}</span></span><span class="bv-mode-row-check">${H("check",'width="13" height="13"')}</span>`,_.onclick=()=>{h(!1),St(m)},u.appendChild(_)}const h=m=>{u.hidden=!m,d.setAttribute("aria-expanded",m?"true":"false")};d.onclick=m=>{m.stopPropagation(),h(u.hidden)},c.append(d),document.addEventListener("click",m=>{const x=m.target;x&&!c.contains(x)&&!u.contains(x)&&h(!1)});const f=n("button","btn","Allow all");f.id="bv-allow-all",f.title="Approve every pending request for this bot",f.onclick=()=>{if(!l.activeId)return;const m=l.approvals.filter(x=>x.botId===l.activeId);Promise.all(m.map(x=>b(`/api/bots/${x.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:x.id,allow:!0})}))).finally(()=>void I(!0))};const B=n("button","btn","Needs you "),O=n("span");O.id="bv-inbox-count",B.appendChild(O),B.onclick=()=>void ot();const E=n("button","btn","Resume");E.onclick=()=>void dt(m=>b(`/api/bots/${m}/resume`,{method:"POST"}).then(()=>I(!0)));const C=n("button","btn danger","Stop");C.onclick=()=>void dt(m=>b(`/api/bots/${m}/stop`,{method:"POST"}).then(()=>I(!0)));const M=n("button","btn","Delete");M.onclick=()=>{l.activeId&&confirm("Delete this bot and its session?")&&b(`/api/bots/${l.activeId}`,{method:"DELETE"}).then(()=>{K(),I(!0)})},a.append(c,f,B,E,C,M),e.append(o,a);const g=n("div","bots-messages");g.id="bots-messages";const y=n("button","bv-jump");y.type="button",y.id="bv-jump",y.innerHTML=`${H("chevron-down",'width="14" height="14"')}<span>Latest</span>`,y.title="Jump to the latest message",y.hidden=!0,y.onclick=()=>{$=!0,g.scrollTop=g.scrollHeight,y.hidden=!0};const L=()=>{$=g.scrollHeight-g.scrollTop-g.clientHeight<48,y.hidden=$};g.addEventListener("scroll",L,{passive:!0}),g.addEventListener("touchmove",()=>{$=!1,y.hidden=g.scrollHeight-g.clientHeight<1},{passive:!0}),g.addEventListener("wheel",()=>{$=!1},{passive:!0});const J=n("div","bots-composer-wrap"),T=n("div","bv-composer-error");T.id="bv-composer-error",T.hidden=!0;const w=n("div","bots-composer"),k=n("textarea");k.id="bots-input",k.rows=1,k.placeholder="Message the bot\u2026",k.spellcheck=!1;const p=window.matchMedia("(pointer: coarse)").matches;p||(k.enterKeyHint="send"),k.onkeydown=m=>{m.key!=="Enter"||m.shiftKey||m.isComposing||p||m.keyCode===229||(m.preventDefault(),rt())},k.oninput=()=>Q(null);const S=n("button","btn primary");S.id="bv-send",S.title="Send",S.setAttribute("aria-label","Send"),S.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>',S.onclick=()=>void rt(),w.append(k,S),w.addEventListener("click",m=>{m.target?.closest("button")||document.activeElement!==k&&k.focus()}),J.append(T,w),t.append(e,g,y,J,u),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||Tt()}function Q(t){const e=document.getElementById("bv-composer-error");e&&(e.textContent=t??"",e.hidden=!t)}function at(t){const e=document.getElementById("bv-send");e&&(e.disabled=t,e.setAttribute("aria-busy",t?"true":"false"),e.title=t?"Sending\u2026":"Send")}async function rt(){const t=document.getElementById("bots-input");if(!t||!l.activeId||vt||!t.value.trim())return;const e=l.activeId,o=t.value;Q(null),at(!0);try{await b(`/api/bots/${e}/input`,{method:"POST",body:JSON.stringify({text:o})}),t.value===o&&(t.value=""),$=!0}catch(i){Q(i instanceof Error?i.message:String(i))}finally{at(!1)}}function dt(t){l.activeId&&t(l.activeId).catch(e=>P({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function K(){l.activeId=null,A=[],$=!0,N();const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{l.ws?.close()}catch{}l.ws=null,q();const e=document.getElementById("terminal-container"),o=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",o&&(o.style.display="none")):o&&(o.style.display="")}async function lt(t){l.activeId=t,A=[],$=!0;const e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),N(),l.items.set(t,[]);const o=document.getElementById("bots-view");o&&(o.hidden=!1);const i=document.getElementById("main-placeholder");i&&(i.style.display="none");const s=document.getElementById("terminal-container");s&&(s.style.display="none");const r=document.getElementById("file-editor");r&&(r.style.display="none"),q(),tt();try{l.ws?.close()}catch{}const a=location.protocol==="https:"?"wss:":"ws:",c=new WebSocket(`${a}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(U())}`);l.ws=c,c.onmessage=d=>{try{mt(JSON.parse(String(d.data)))}catch{}},c.onclose=()=>{l.activeId===t&&setTimeout(()=>{l.activeId===t&&I(!0)},1500)},await I(!0)}function G(){return l.bots.find(t=>t.id===l.activeId)||null}function Y(){const t=G();if(!t)return;const e=document.getElementById("bv-title"),o=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),o&&(o.textContent=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);const s=document.getElementById("bv-mode-btn");s&&ut(s,t.runtimeMode||"supervised");for(const c of document.querySelectorAll("#bv-mode-menu button")){const d=c.dataset.mode===t.runtimeMode;c.classList.toggle("active",d),c.setAttribute("aria-checked",d?"true":"false")}const r=document.getElementById("bv-allow-all"),a=l.approvals.filter(c=>c.botId===t.id).length;r&&(r.hidden=a===0,r.textContent=`Allow all (${a})`),i&&(i.style.background=gt(t.status))}const ct={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},pt={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function ut(t,e){const o=pt[e]??"shield";t.dataset.mode=e,t.innerHTML=H(o,'width="15" height="15"');const i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${ct[e]??e}`;t.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,t.setAttribute("aria-label",i)}async function St(t){if(l.activeId)try{await b(`/api/bots/${l.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});const e=G();e&&(e.runtimeMode=t),Y(),P({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${ct[t]||t}`})}catch(e){P({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function P(t,e=l.activeId){if(!e)return;const o=l.items.get(e)||[];o.push(t),l.items.set(e,o),e===l.activeId&&j()}function j(){if(l.renderQueued)return;l.renderQueued=!0;const t=Math.max(0,60-(performance.now()-it));window.setTimeout(()=>{l.renderQueued=!1,it=performance.now(),tt()},t)}function X(t){switch(t.kind){case"assistant":return{text:t.text,thinking:t.thinking};case"tool":return{phase:t.phase,output:t.output,error:t.isError,durationMs:t.durationMs};case"approval":return{decided:t.decided,approvalState:t.approval.state};default:return{}}}function xt(t,e){return t.text!==e.text||t.thinking!==e.thinking||t.phase!==e.phase||t.output!==e.output||t.error!==e.error||t.durationMs!==e.durationMs||t.decided!==e.decided||t.approvalState!==e.approvalState}function Z(t){if(t.kind==="user"){const e=n("div","bv-msg bv-user");return e.appendChild(F(t.text)),e}if(t.kind==="assistant"){const e=n("div","bv-msg bv-assistant");if(t.thinking){const i=n("details","bv-thinking");i.appendChild(n("summary",void 0,"thinking")),i.appendChild(n("div",void 0,t.thinking)),e.appendChild(i)}const o=n("div","bv-text");return o.appendChild(F(t.text)),e.appendChild(o),e}return t.kind==="tool"?It(t):t.kind==="approval"?Et(t):n("div",`bv-notice bv-notice-${t.level}`,t.text)}function Ct(t,e){const o=t.querySelector("details.bv-thinking");if(e.thinking)if(o){const s=o.querySelector("div");s&&s.textContent!==e.thinking&&(s.textContent=e.thinking)}else{const s=n("details","bv-thinking");s.appendChild(n("summary",void 0,"thinking")),s.appendChild(n("div",void 0,e.thinking)),t.prepend(s)}else o&&o.remove();const i=t.querySelector(".bv-text");i&&i.replaceChildren(F(e.text))}function tt(){const t=document.getElementById("bots-messages");if(!t||!l.activeId||document.getElementById("bots-view")?.hidden)return;const e=l.items.get(l.activeId)||[],o=$;if(e.length<A.length||e.some((s,r)=>A[r]?.item!==s))t.textContent="",A=e.map(s=>{const r=Z(s);return t.appendChild(r),{item:s,snapshot:X(s),node:r}});else{for(let s=A.length;s<e.length;s++){const r=e[s],a=Z(r);t.appendChild(a),A.push({item:r,snapshot:X(r),node:a})}for(let s=0;s<e.length;s++){const r=e[s],a=A[s],c=X(r);if(xt(a.snapshot,c)){if(r.kind==="assistant")Ct(a.node,r);else{const d=Z(r);a.node.replaceWith(d),a.node=d}a.snapshot=c}}}o&&(t.scrollTop=t.scrollHeight)}function It(t){const e=n("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;const o=n("summary"),i=n("span","bv-tool-name",t.name);if(o.appendChild(i),t.phase!=="end"&&o.appendChild(n("span","bv-tool-phase",t.phase)),t.isError&&o.appendChild(n("span","bv-tool-error","error")),typeof t.durationMs=="number"&&o.appendChild(n("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(o),t.args!==void 0){const s=n("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){const s=n("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function Et(t){const e=n("div","bv-approval"),o=t.approval;if(e.appendChild(n("div","bv-approval-title",o.title)),o.message&&e.appendChild(n("pre","bv-pre",o.message)),t.decided)return e.appendChild(n("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;const i=n("input","bv-reason");i.placeholder="reason (optional)";const s=n("div","bv-approval-actions"),r=n("button","btn primary","Allow"),a=n("button","btn",o.method==="confirm"&&/^Allow (.+?)\?$/.test(o.title)?`Always allow ${/^Allow (.+?)\?$/.exec(o.title)?.[1]}`:"Always allow");a.hidden=o.method!=="confirm";const c=n("button","btn danger","Deny"),d=async(u,h=!1)=>{try{await b(`/api/bots/${o.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:o.id,allow:u,always:h,reason:i.value||void 0})}),t.decided=u?"allowed":"denied",j(),I(!0)}catch(f){P({kind:"notice",level:"error",text:f instanceof Error?f.message:String(f)})}};return r.onclick=()=>void d(!0),a.onclick=()=>void d(!0,!0),c.onclick=()=>void d(!1),s.append(i,r,a,c),e.appendChild(s),e}function mt(t){const e=String(t.type||""),o=l.activeId;if(!o)return;const i=l.items.get(o)||[];if(e==="snapshot")l.items.set(o,[]);else if(e==="user")$=!0,P({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=G();s&&(s.status=String(t.status||s.status)),Y(),Ot()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const a=$t(s),c=Bt(s),d=i[i.length-1];d&&d.kind==="assistant"?(d.text=a||d.text,d.thinking=c||d.thinking):i.push({kind:"assistant",text:a,thinking:c}),l.items.set(o,i),j()}else if(e==="delta"){const s=String(t.kind||""),r=String(t.delta||"");let a=i[i.length-1];(!a||a.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),a=i[i.length-1]),a.kind==="assistant"&&(s==="text"?a.text+=r:s==="thinking"&&(a.thinking+=r)),l.items.set(o,i),j()}else if(e==="tool"){const s=String(t.callId||""),r=i.find(c=>c.kind==="tool"&&c.callId===s),a=String(t.phase||"start");r?(r.phase=a,a==="update"&&t.output&&(r.output=String(t.output)),a==="end"&&(t.output&&(r.output=String(t.output)),r.isError=t.isError===!0,typeof t.durationMs=="number"&&(r.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:a}),l.items.set(o,i),j()}else if(e==="approval"){const s=t.approval;if(!s)return;const r=i;for(let a=r.length-1;a>=0;a--){const c=r[a];if(c.kind==="approval"&&c.approval.id===s.id){c.approval=s,s.state!=="pending"&&(c.decided=s.state==="allowed"?"allowed":"denied"),l.items.set(o,r),j();return}}r.push({kind:"approval",approval:s}),l.items.set(o,r),j()}else e==="notice"&&P({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function $t(t){const e=t.content;return Array.isArray(e)?e.map(o=>o&&typeof o=="object"&&o.type==="text"?String(o.text||""):"").join(""):String(t.text||"")}function Bt(t){const e=t.content;return Array.isArray(e)?e.map(o=>o&&typeof o=="object"&&o.type==="thinking"?String(o.thinking||""):"").join(""):""}async function I(t=!1){try{const[e,o]=await Promise.all([b("/api/bots"),b("/api/bots/approvals")]);if(l.bots=e,l.approvals=o,q(),Y(),t&&l.activeId){const i=await b(`/api/bots/${l.activeId}/events?limit=300`);Mt(i)}}catch{}}async function Ot(){try{l.bots=await b("/api/bots"),q()}catch{}}function Mt(t){if(l.activeId){l.items.set(l.activeId,[]);for(const e of t)mt(e);tt()}}function Tt(){const t=n("div","bots-modal");t.id="bots-modal",t.hidden=!0;const e=n("div","bots-modal-card"),o=n("div","bots-modal-head"),i=n("span");i.id="bots-modal-title";const s=n("button","btn");s.innerHTML=H("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>V(),o.append(i,s);const r=n("div","bots-modal-body");r.id="bots-modal-body",e.append(o,r),t.appendChild(e),t.onclick=a=>{a.target===t&&V()},document.body.appendChild(t)}function et(t){const e=document.getElementById("bots-modal"),o=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return o&&(o.textContent=t),i.textContent="",e.hidden=!1,i}function V(){const t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function At(){return l.catalog||(l.catalog=await b("/api/bots/catalog")),l.catalog}async function ht(){return l.templates=await b("/api/bots/templates"),l.templates}async function D(){const t=et("Bot templates"),[e,o]=await Promise.all([At(),ht()]),i=n("div","bv-template-list");for(const d of o){const u=n("div","bv-template-row");u.appendChild(n("span","bv-template-name",d.manifest.name)),u.appendChild(n("span","bv-template-desc",d.manifest.description||""));const h=n("button","btn","Edit");h.onclick=()=>ft(t,e,d);const f=n("button","btn","Copy");f.title="Duplicate this template",f.onclick=()=>{const E=JSON.parse(JSON.stringify(d.manifest));E.name=`${d.manifest.name} copy`,b("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:E})}).then(()=>D()).catch(C=>alert(C instanceof Error?C.message:String(C)))};const B=n("button","btn danger","Delete");B.onclick=()=>{confirm(`Delete template ${d.manifest.name}?`)&&b(`/api/bots/templates/${d.id}`,{method:"DELETE"}).then(()=>D())};const O=n("span","bv-template-actions");O.append(h,f,B),u.appendChild(O),i.appendChild(u)}o.length===0&&i.appendChild(n("div","bots-empty","No templates yet")),t.appendChild(i);const s=n("div","bv-template-actions"),r=n("button","btn primary","New template");r.onclick=()=>ft(t,e,null);const a=n("button","btn","Export");a.title="Download templates + library as JSON",a.onclick=()=>{(async()=>{try{const d=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${U()}`}});if(!d.ok)throw new Error(`HTTP ${d.status}`);const u=await d.blob(),h=document.createElement("a");h.href=URL.createObjectURL(u),h.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,h.click(),setTimeout(()=>URL.revokeObjectURL(h.href),2e3)}catch(d){alert(d instanceof Error?d.message:String(d))}})()};const c=n("button","btn","Import");c.title="Restore templates from a JSON bundle",c.onclick=()=>{const d=document.createElement("input");d.type="file",d.accept="application/json,.json",d.onchange=()=>{const u=d.files?.[0];u&&(async()=>{try{const h=JSON.parse(await u.text()),f=await b("/api/bots/import",{method:"POST",body:JSON.stringify(h)});alert(`Imported ${f.templates} templates, ${f.files} library files (${f.skipped} kept)`),await D()}catch(h){alert(h instanceof Error?h.message:String(h))}})()},d.click()},s.append(r,a,c),t.appendChild(s)}function nt(t,e,o){const i=n("div","bv-field");i.appendChild(n("label","bv-label",t));const s=n("div","bv-check-grid"),r=[];for(const a of e){const c=n("label","bv-check"),d=document.createElement("input");d.type="checkbox",d.checked=o.includes(a.id),c.append(d,n("span",void 0,a.label)),a.hint&&(c.title=a.hint),s.appendChild(c),r.push({id:a.id,input:d})}return i.appendChild(s),{element:i,get:()=>r.filter(a=>a.input.checked).map(a=>a.id)}}function ft(t,e,o){t.textContent="";const i=o?JSON.parse(JSON.stringify(o.manifest)):{name:"new-bot",description:""},s=n("input","bv-input");s.value=i.name,s.placeholder="Template name";const r=n("input","bv-input");r.value=i.description||"",r.placeholder="One line description";const a=n("textarea","bv-textarea");a.rows=6,a.value=i.system||"",a.placeholder="System prompt for this bot (written to SYSTEM.md)";const c=nt("Skills",e.skills.map(p=>({id:p.id,label:p.name,hint:p.description})),i.skills||[]),d=nt("Extensions (Pi builtins + library)",e.extensions.map(p=>({id:p.id,label:`${p.name}${p.kind==="builtin"?" (builtin)":""}`,hint:p.description})),(i.extensions||[]).map(p=>p.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),u=nt("Prompt templates",e.prompts.map(p=>({id:p.id,label:p.name})),i.prompts||[]),h=n("select","bv-input");h.appendChild(new Option("none",""));for(const p of e.mcp)h.appendChild(new Option(p.name,p.id));i.mcp&&(h.value=e.mcp.find(p=>JSON.stringify(p.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");const f=n("div","bv-field");f.appendChild(n("label","bv-label","Tools (allow list; deny always blocks)"));const B=n("div","bv-check-grid"),O=[];for(const p of e.tools){const S=n("label","bv-check"),m=document.createElement("input");m.type="checkbox",m.checked=(i.tools?.allow||[]).includes(p.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(p.name),S.append(m,n("span",void 0,p.name)),B.appendChild(S),O.push({name:p.name,input:m})}f.appendChild(B);const E=n("input","bv-input");E.value=(i.tools?.deny||[]).join(", "),E.placeholder="Always deny (comma separated), e.g. bash, write";const C=n("textarea","bv-textarea");C.rows=2,C.value=(i.packages||[]).join(`
|
|
2
|
-
`),
|
|
3
|
-
${
|
|
4
|
-
${i.model.id}`);const
|
|
5
|
-
`),
|
|
6
|
-
`).map(
|
|
1
|
+
import{icon as P}from"../lib/icons.js";import{createMarkdownRenderer as St}from"./markdown.js";const G=St(document),l={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};let A=[],M=!0,Ct=!1,ct=0;function Y(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function k(t,e){const o=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${Y()}`,...e?.headers||{}}}),i=await o.text(),s=i?JSON.parse(i):null;if(!o.ok)throw new Error(s&&s.error||`HTTP ${o.status}`);return s}function n(t,e,o){const i=document.createElement(t);return e&&(i.className=e),o!==void 0&&(i.textContent=o),i}function pt(t){return t==="running"?"var(--panel-success)":t==="waiting_approval"||t==="waiting_input"?"#e0a23c":t==="failed"?"var(--panel-danger, #e5534b)":t==="completed"?"var(--panel-accent)":"var(--panel-muted)"}function L(){X||(X=requestAnimationFrame(()=>{X=0,It()}))}let X=0,U="";function It(){const t=document.getElementById("bots-view");if(!t)return;const e=window.visualViewport,o=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(l.activeId&&e&&o&&!i){const s=document.querySelector(".fixed-header"),a=s?Math.round(s.getBoundingClientRect().height):0,r=Math.round(e.offsetTop)+a,c=Math.round(e.offsetLeft),d=Math.round(e.width),p=Math.max(120,Math.round(e.height)-a),m=`fixed|${r}|${c}|${d}|${p}`;if(m===U)return;U=m,t.style.position="fixed",t.style.top=`${r}px`,t.style.left=`${c}px`,t.style.width=`${d}px`,t.style.height=`${p}px`,t.style.right="auto",t.style.bottom="auto"}else{if(U==="")return;U="",t.style.position="",t.style.top="",t.style.left="",t.style.width="",t.style.height="",t.style.right="",t.style.bottom=""}}window.visualViewport?.addEventListener("resize",L),window.visualViewport?.addEventListener("scroll",L),window.addEventListener("resize",L),document.addEventListener("click",L);const ut=document.querySelector(".sidebar");ut&&new MutationObserver(L).observe(ut,{attributes:!0,attributeFilter:["class"]}),window.__syncBotsViewport=L;function F(){const t=l.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));const o=document.getElementById("bv-inbox-count");o&&(o.textContent=t?`(${t})`:""),window.__botsSnapshot=l.bots,window.__refreshSidebar?.()}function Et(){const t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),o=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),V()}),e?.addEventListener("click",()=>{i(),Rt()}),o?.addEventListener("click",()=>{i(),dt()})}function $t(){const t=n("div","bots-view");t.id="bots-view",t.hidden=!0;const e=n("div","bots-view-head"),o=n("div","bv-title"),i=n("span","bots-dot");i.id="bv-dot";const s=n("span","bv-title-text");s.id="bv-title";const a=n("span","bv-status");a.id="bv-status",o.append(i,s,a);const r=n("div","bv-actions"),c=n("div","bv-mode"),d=n("button","bv-mode-btn");d.id="bv-mode-btn",d.type="button",d.setAttribute("aria-haspopup","menu"),d.setAttribute("aria-expanded","false"),yt(d,"supervised");const p=n("div","bv-menu bv-mode-menu");p.id="bv-mode-menu",p.setAttribute("role","menu"),p.hidden=!0;for(const[b,C,K]of[["supervised","\u9ED8\u8BA4","\u53EA\u8BFB\u5DE5\u5177\uFF08read/grep/find/ls\uFF09\u76F4\u63A5\u653E\u884C\uFF1Bbash\u3001edit\u3001write\u3001\u6269\u5C55/MCP \u5DE5\u5177\u4F1A\u95EE\u4F60"],["parent-supervised","\u76D1\u7BA1","\u5176\u4F59\u5DE5\u5177\u4EA4\u7ED9\u4E0A\u7EA7 bot \u51B3\u5B9A\uFF08\u5E26\u7406\u7531\uFF09\uFF1B\u4F60\u4ECD\u7136\u80FD\u770B\u5230\u5E76\u56DE\u7B54\uFF0C\u5148\u7B54\u5148\u5F97\uFF1B\u6CA1\u6709\u4E0A\u7EA7\u65F6\u56DE\u843D\u5230\u9ED8\u8BA4"],["full-access","\u5168\u653E\u884C","\u6240\u6709\u5DE5\u5177\u76F4\u63A5\u6267\u884C\uFF0C\u4E0D\u518D\u8BE2\u95EE\u3002\u6CE8\u610F\u8FD9\u4E0D\u662F\u6C99\u7BB1"]]){const j=n("button","bv-menu-item");j.dataset.mode=b,j.setAttribute("role","menuitemradio"),j.innerHTML=`<span class="bv-menu-icon">${P(gt[b],'width="15" height="15"')}</span><span class="bv-menu-text"><b>${C}</b><span>${K}</span></span><span class="bv-menu-check">${P("check",'width="13" height="13"')}</span>`,j.onclick=()=>{m(!1),Mt(b)},p.appendChild(j)}const m=b=>{b&&O(!1),p.hidden=!b,d.setAttribute("aria-expanded",b?"true":"false")};d.onclick=b=>{b.stopPropagation(),m(p.hidden)},c.append(d);const f=n("button","btn bv-inbox");f.id="bv-inbox",f.title="Requests waiting for you";const y=n("span",void 0,"Needs you"),E=n("span","bv-inbox-count");E.id="bv-inbox-count",f.append(y,E),f.onclick=()=>void dt();const v=n("button","bv-icon-btn");v.id="bv-more-btn",v.type="button",v.title="More actions",v.setAttribute("aria-label","More actions"),v.setAttribute("aria-haspopup","menu"),v.setAttribute("aria-expanded","false"),v.innerHTML=P("dots",'width="16" height="16"');const w=n("div","bv-menu");w.id="bv-more-menu",w.setAttribute("role","menu"),w.hidden=!0;const x=(b,C,K,j)=>{const D=n("button",`bv-menu-item${b?` ${b}`:""}`);return D.type="button",D.setAttribute("role","menuitem"),D.innerHTML=`<span class="bv-menu-icon">${P(C,'width="15" height="15"')}</span><span class="bv-menu-text"><b>${K}</b></span>`,D.onclick=()=>{O(!1),j()},D},B=x("","check","Allow all",()=>{if(!l.activeId)return;const b=l.approvals.filter(C=>C.botId===l.activeId);Promise.all(b.map(C=>k(`/api/bots/${C.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:C.id,allow:!0})}))).finally(()=>void $(!0))});B.id="bv-allow-all",B.title="Approve every pending request for this bot";const H=x("","refresh","Resume bot",()=>ht(b=>k(`/api/bots/${b}/resume`,{method:"POST"}).then(()=>$(!0)))),N=x("","stop","Stop run",()=>ht(b=>k(`/api/bots/${b}/stop`,{method:"POST"}).then(()=>$(!0)))),W=x("danger","delete","Delete bot",()=>{l.activeId&&confirm("Delete this bot and its session?")&&k(`/api/bots/${l.activeId}`,{method:"DELETE"}).then(()=>{tt(),$(!0)})});w.append(B,H,N,n("div","bv-menu-sep"),W);const O=b=>{b&&m(!1),w.hidden=!b,v.setAttribute("aria-expanded",b?"true":"false")};v.onclick=b=>{b.stopPropagation(),O(w.hidden)},document.addEventListener("click",b=>{const C=b.target;C&&(!c.contains(C)&&!p.contains(C)&&m(!1),!v.contains(C)&&!w.contains(C)&&O(!1))}),r.append(c,f,v),e.append(o,r);const g=n("div","bots-messages");g.id="bots-messages";const I=n("button","bv-jump");I.type="button",I.id="bv-jump",I.innerHTML=`${P("chevron-down",'width="14" height="14"')}<span>Latest</span>`,I.title="Jump to the latest message",I.hidden=!0,I.onclick=()=>{M=!0,g.scrollTop=g.scrollHeight,I.hidden=!0};const u=()=>{M=g.scrollHeight-g.scrollTop-g.clientHeight<48,I.hidden=M};g.addEventListener("scroll",u,{passive:!0}),g.addEventListener("touchmove",()=>{M=!1,I.hidden=g.scrollHeight-g.clientHeight<1},{passive:!0}),g.addEventListener("wheel",()=>{M=!1},{passive:!0});const T=n("div","bots-composer-wrap"),S=n("div","bv-composer-error");S.id="bv-composer-error",S.hidden=!0;const q=n("div","bots-composer"),h=n("textarea");h.id="bots-input",h.rows=1,h.placeholder="Message the bot\u2026",h.spellcheck=!1;const lt=window.matchMedia("(pointer: coarse)").matches;lt||(h.enterKeyHint="send"),h.onkeydown=b=>{b.key!=="Enter"||b.shiftKey||b.isComposing||lt||b.keyCode===229||(b.preventDefault(),bt())},h.oninput=()=>Z(null);const R=n("button","btn primary");R.id="bv-send",R.title="Send",R.setAttribute("aria-label","Send"),R.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>',R.onclick=()=>void bt(),q.append(h,R),q.addEventListener("click",b=>{b.target?.closest("button")||document.activeElement!==h&&h.focus()}),T.append(S,q),t.append(e,g,I,T,p,w),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||Jt()}function Z(t){const e=document.getElementById("bv-composer-error");e&&(e.textContent=t??"",e.hidden=!t)}function mt(t){const e=document.getElementById("bv-send");e&&(e.disabled=t,e.setAttribute("aria-busy",t?"true":"false"),e.title=t?"Sending\u2026":"Send")}async function bt(){const t=document.getElementById("bots-input");if(!t||!l.activeId||Ct||!t.value.trim())return;const e=l.activeId,o=t.value;Z(null),mt(!0);try{await k(`/api/bots/${e}/input`,{method:"POST",body:JSON.stringify({text:o})}),t.value===o&&(t.value=""),M=!0}catch(i){Z(i instanceof Error?i.message:String(i))}finally{mt(!1)}}function ht(t){l.activeId&&t(l.activeId).catch(e=>_({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function tt(){l.activeId=null,A=[],M=!0,L();const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{l.ws?.close()}catch{}l.ws=null,F();const e=document.getElementById("terminal-container"),o=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",o&&(o.style.display="none")):o&&(o.style.display="")}async function ft(t){l.activeId=t,A=[],M=!0;const e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),L(),l.items.set(t,[]);const o=document.getElementById("bots-view");o&&(o.hidden=!1);const i=document.getElementById("main-placeholder");i&&(i.style.display="none");const s=document.getElementById("terminal-container");s&&(s.style.display="none");const a=document.getElementById("file-editor");a&&(a.style.display="none"),F(),st();try{l.ws?.close()}catch{}const r=location.protocol==="https:"?"wss:":"ws:",c=new WebSocket(`${r}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(Y())}`);l.ws=c,c.onmessage=d=>{try{wt(JSON.parse(String(d.data)))}catch{}},c.onclose=()=>{l.activeId===t&&setTimeout(()=>{l.activeId===t&&$(!0)},1500)},await $(!0)}function et(){return l.bots.find(t=>t.id===l.activeId)||null}function nt(){const t=et();if(!t)return;const e=document.getElementById("bv-title"),o=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),o&&(o.textContent=Bt[t.status]??t.status.replace(/_/g," "),o.dataset.status=t.status,o.style.color=pt(t.status),o.title=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);const s=document.getElementById("bv-mode-btn");s&&yt(s,t.runtimeMode||"supervised");for(const c of document.querySelectorAll("#bv-mode-menu button")){const d=c.dataset.mode===t.runtimeMode;c.classList.toggle("active",d),c.setAttribute("aria-checked",d?"true":"false")}const a=document.getElementById("bv-allow-all"),r=l.approvals.filter(c=>c.botId===t.id).length;if(a){a.hidden=r===0;const c=a.querySelector(".bv-menu-text b");c&&(c.textContent=`Allow all (${r})`)}i&&(i.style.background=pt(t.status))}const Bt={queued:"queued",starting:"starting",running:"running",waiting_input:"waiting",waiting_approval:"approval",completed:"done",failed:"failed",cancelled:"stopped",stale:"stale"},vt={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"},gt={supervised:"shield","parent-supervised":"shield-up","full-access":"shield-alert"};function yt(t,e){const o=gt[e]??"shield";t.dataset.mode=e,t.innerHTML=P(o,'width="15" height="15"');const i=`\u5BA1\u6279\u6A21\u5F0F\uFF1A${vt[e]??e}`;t.title=`${i}\uFF08\u70B9\u5F00\u53EF\u5207\u6362\uFF09`,t.setAttribute("aria-label",i)}async function Mt(t){if(l.activeId)try{await k(`/api/bots/${l.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});const e=et();e&&(e.runtimeMode=t),nt(),_({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${vt[t]||t}`})}catch(e){_({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function _(t,e=l.activeId){if(!e)return;const o=l.items.get(e)||[];o.push(t),l.items.set(e,o),e===l.activeId&&J()}function J(){if(l.renderQueued)return;l.renderQueued=!0;const t=Math.max(0,60-(performance.now()-ct));window.setTimeout(()=>{l.renderQueued=!1,ct=performance.now(),st()},t)}function ot(t){switch(t.kind){case"assistant":return{text:t.text,thinking:t.thinking};case"tool":return{phase:t.phase,output:t.output,error:t.isError,durationMs:t.durationMs};case"approval":return{decided:t.decided,approvalState:t.approval.state};default:return{}}}function Ot(t,e){return t.text!==e.text||t.thinking!==e.thinking||t.phase!==e.phase||t.output!==e.output||t.error!==e.error||t.durationMs!==e.durationMs||t.decided!==e.decided||t.approvalState!==e.approvalState}function it(t){if(t.kind==="user"){const e=n("div","bv-msg bv-user");return e.appendChild(G(t.text)),e}if(t.kind==="assistant"){const e=n("div","bv-msg bv-assistant");if(t.thinking){const i=n("details","bv-thinking");i.appendChild(n("summary",void 0,"thinking")),i.appendChild(n("div",void 0,t.thinking)),e.appendChild(i)}const o=n("div","bv-text");return o.appendChild(G(t.text)),e.appendChild(o),e}return t.kind==="tool"?At(t):t.kind==="approval"?Lt(t):n("div",`bv-notice bv-notice-${t.level}`,t.text)}function Tt(t,e){const o=t.querySelector("details.bv-thinking");if(e.thinking)if(o){const s=o.querySelector("div");s&&s.textContent!==e.thinking&&(s.textContent=e.thinking)}else{const s=n("details","bv-thinking");s.appendChild(n("summary",void 0,"thinking")),s.appendChild(n("div",void 0,e.thinking)),t.prepend(s)}else o&&o.remove();const i=t.querySelector(".bv-text");i&&i.replaceChildren(G(e.text))}function st(){const t=document.getElementById("bots-messages");if(!t||!l.activeId||document.getElementById("bots-view")?.hidden)return;const e=l.items.get(l.activeId)||[],o=M;if(e.length<A.length||e.some((s,a)=>A[a]?.item!==s))t.textContent="",A=e.map(s=>{const a=it(s);return t.appendChild(a),{item:s,snapshot:ot(s),node:a}});else{for(let s=A.length;s<e.length;s++){const a=e[s],r=it(a);t.appendChild(r),A.push({item:a,snapshot:ot(a),node:r})}for(let s=0;s<e.length;s++){const a=e[s],r=A[s],c=ot(a);if(Ot(r.snapshot,c)){if(a.kind==="assistant")Tt(r.node,a);else{const d=it(a);r.node.replaceWith(d),r.node=d}r.snapshot=c}}}o&&(t.scrollTop=t.scrollHeight)}function At(t){const e=n("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;const o=n("summary"),i=n("span","bv-tool-name",t.name);if(o.appendChild(i),t.phase!=="end"&&o.appendChild(n("span","bv-tool-phase",t.phase)),t.isError&&o.appendChild(n("span","bv-tool-error","error")),typeof t.durationMs=="number"&&o.appendChild(n("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(o),t.args!==void 0){const s=n("pre","bv-pre");s.textContent=typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2),e.appendChild(s)}if(t.output){const s=n("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function Lt(t){const e=n("div","bv-approval"),o=t.approval;if(e.appendChild(n("div","bv-approval-tag","Needs approval")),e.appendChild(n("div","bv-approval-title",o.title)),o.message){const y=n("pre","bv-pre bv-approval-detail");y.textContent=o.message,e.appendChild(y)}if(t.decided)return e.appendChild(n("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;const i=n("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");const s=n("div","bv-approval-actions"),a=n("button","btn primary","Allow once"),r=/^Allow (.+?)\?$/.exec(o.title)?.[1],c=o.method==="confirm"?r&&r.length<=24?`Always allow ${r}`:"Always allow this tool":"Allow for this session",d=n("button","btn",c);d.hidden=o.method!=="confirm";const p=n("button","btn danger","Deny"),m=[a,d,p],f=async(y,E,v)=>{const w=v.textContent??"";for(const x of m)x.disabled=!0;v.textContent=y?"Allowing\u2026":"Denying\u2026";try{await k(`/api/bots/${o.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:o.id,allow:y,always:E,reason:i.value||void 0})}),t.decided=y?"allowed":"denied",J(),$(!0)}catch(x){for(const B of m)B.disabled=!1;v.textContent=w,_({kind:"notice",level:"error",text:x instanceof Error?x.message:String(x)})}};return a.onclick=()=>void f(!0,!1,a),d.onclick=()=>void f(!0,!0,d),p.onclick=()=>void f(!1,!1,p),s.append(i,a,d,p),e.appendChild(s),e}function wt(t){const e=String(t.type||""),o=l.activeId;if(!o)return;const i=l.items.get(o)||[];if(e==="snapshot")l.items.set(o,[]);else if(e==="user")M=!0,_({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=et();s&&(s.status=String(t.status||s.status)),nt(),Pt()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const r=Nt(s),c=jt(s),d=i[i.length-1];d&&d.kind==="assistant"?(d.text=r||d.text,d.thinking=c||d.thinking):i.push({kind:"assistant",text:r,thinking:c}),l.items.set(o,i),J()}else if(e==="delta"){const s=String(t.kind||""),a=String(t.delta||"");let r=i[i.length-1];(!r||r.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),r=i[i.length-1]),r.kind==="assistant"&&(s==="text"?r.text+=a:s==="thinking"&&(r.thinking+=a)),l.items.set(o,i),J()}else if(e==="tool"){const s=String(t.callId||""),a=i.find(c=>c.kind==="tool"&&c.callId===s),r=String(t.phase||"start");a?(a.phase=r,r==="update"&&t.output&&(a.output=String(t.output)),r==="end"&&(t.output&&(a.output=String(t.output)),a.isError=t.isError===!0,typeof t.durationMs=="number"&&(a.durationMs=t.durationMs))):i.push({kind:"tool",callId:s,name:String(t.name||"tool"),args:t.args,output:t.output?String(t.output):void 0,isError:t.isError===!0,durationMs:typeof t.durationMs=="number"?t.durationMs:void 0,phase:r}),l.items.set(o,i),J()}else if(e==="approval"){const s=t.approval;if(!s)return;const a=i;for(let r=a.length-1;r>=0;r--){const c=a[r];if(c.kind==="approval"&&c.approval.id===s.id){c.approval=s,s.state!=="pending"&&(c.decided=s.state==="allowed"?"allowed":"denied"),l.items.set(o,a),J();return}}a.push({kind:"approval",approval:s}),l.items.set(o,a),J()}else e==="notice"&&_({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function Nt(t){const e=t.content;return Array.isArray(e)?e.map(o=>o&&typeof o=="object"&&o.type==="text"?String(o.text||""):"").join(""):String(t.text||"")}function jt(t){const e=t.content;return Array.isArray(e)?e.map(o=>o&&typeof o=="object"&&o.type==="thinking"?String(o.thinking||""):"").join(""):""}async function $(t=!1){try{const[e,o]=await Promise.all([k("/api/bots"),k("/api/bots/approvals")]);if(l.bots=e,l.approvals=o,F(),nt(),t&&l.activeId){const i=await k(`/api/bots/${l.activeId}/events?limit=300`);_t(i)}}catch{}}async function Pt(){try{l.bots=await k("/api/bots"),F()}catch{}}function _t(t){if(l.activeId){l.items.set(l.activeId,[]);for(const e of t)wt(e);st()}}function Jt(){const t=n("div","bots-modal");t.id="bots-modal",t.hidden=!0;const e=n("div","bots-modal-card"),o=n("div","bots-modal-head"),i=n("span");i.id="bots-modal-title";const s=n("button","btn");s.innerHTML=P("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>z(),o.append(i,s);const a=n("div","bots-modal-body");a.id="bots-modal-body",e.append(o,a),t.appendChild(e),t.onclick=r=>{r.target===t&&z()},document.body.appendChild(t)}function at(t){const e=document.getElementById("bots-modal"),o=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return o&&(o.textContent=t),i.textContent="",e.hidden=!1,i}function z(){const t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function Ht(){return l.catalog||(l.catalog=await k("/api/bots/catalog")),l.catalog}async function kt(){return l.templates=await k("/api/bots/templates"),l.templates}async function V(){const t=at("Bot templates"),[e,o]=await Promise.all([Ht(),kt()]),i=n("div","bv-template-list");for(const d of o){const p=n("div","bv-template-row");p.appendChild(n("span","bv-template-name",d.manifest.name)),p.appendChild(n("span","bv-template-desc",d.manifest.description||""));const m=n("button","btn","Edit");m.onclick=()=>xt(t,e,d);const f=n("button","btn","Copy");f.title="Duplicate this template",f.onclick=()=>{const v=JSON.parse(JSON.stringify(d.manifest));v.name=`${d.manifest.name} copy`,k("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:v})}).then(()=>V()).catch(w=>alert(w instanceof Error?w.message:String(w)))};const y=n("button","btn danger","Delete");y.onclick=()=>{confirm(`Delete template ${d.manifest.name}?`)&&k(`/api/bots/templates/${d.id}`,{method:"DELETE"}).then(()=>V())};const E=n("span","bv-template-actions");E.append(m,f,y),p.appendChild(E),i.appendChild(p)}o.length===0&&i.appendChild(n("div","bots-empty","No templates yet")),t.appendChild(i);const s=n("div","bv-template-actions"),a=n("button","btn primary","New template");a.onclick=()=>xt(t,e,null);const r=n("button","btn","Export");r.title="Download templates + library as JSON",r.onclick=()=>{(async()=>{try{const d=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${Y()}`}});if(!d.ok)throw new Error(`HTTP ${d.status}`);const p=await d.blob(),m=document.createElement("a");m.href=URL.createObjectURL(p),m.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,m.click(),setTimeout(()=>URL.revokeObjectURL(m.href),2e3)}catch(d){alert(d instanceof Error?d.message:String(d))}})()};const c=n("button","btn","Import");c.title="Restore templates from a JSON bundle",c.onclick=()=>{const d=document.createElement("input");d.type="file",d.accept="application/json,.json",d.onchange=()=>{const p=d.files?.[0];p&&(async()=>{try{const m=JSON.parse(await p.text()),f=await k("/api/bots/import",{method:"POST",body:JSON.stringify(m)});alert(`Imported ${f.templates} templates, ${f.files} library files (${f.skipped} kept)`),await V()}catch(m){alert(m instanceof Error?m.message:String(m))}})()},d.click()},s.append(a,r,c),t.appendChild(s)}function rt(t,e,o){const i=n("div","bv-field");i.appendChild(n("label","bv-label",t));const s=n("div","bv-check-grid"),a=[];for(const r of e){const c=n("label","bv-check"),d=document.createElement("input");d.type="checkbox",d.checked=o.includes(r.id),c.append(d,n("span",void 0,r.label)),r.hint&&(c.title=r.hint),s.appendChild(c),a.push({id:r.id,input:d})}return i.appendChild(s),{element:i,get:()=>a.filter(r=>r.input.checked).map(r=>r.id)}}function xt(t,e,o){t.textContent="";const i=o?JSON.parse(JSON.stringify(o.manifest)):{name:"new-bot",description:""},s=n("input","bv-input");s.value=i.name,s.placeholder="Template name";const a=n("input","bv-input");a.value=i.description||"",a.placeholder="One line description";const r=n("textarea","bv-textarea");r.rows=6,r.value=i.system||"",r.placeholder="System prompt for this bot (written to SYSTEM.md)";const c=rt("Skills",e.skills.map(u=>({id:u.id,label:u.name,hint:u.description})),i.skills||[]),d=rt("Extensions (Pi builtins + library)",e.extensions.map(u=>({id:u.id,label:`${u.name}${u.kind==="builtin"?" (builtin)":""}`,hint:u.description})),(i.extensions||[]).map(u=>u.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),p=rt("Prompt templates",e.prompts.map(u=>({id:u.id,label:u.name})),i.prompts||[]),m=n("select","bv-input");m.appendChild(new Option("none",""));for(const u of e.mcp)m.appendChild(new Option(u.name,u.id));i.mcp&&(m.value=e.mcp.find(u=>JSON.stringify(u.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");const f=n("div","bv-field");f.appendChild(n("label","bv-label","Tools (allow list; deny always blocks)"));const y=n("div","bv-check-grid"),E=[];for(const u of e.tools){const T=n("label","bv-check"),S=document.createElement("input");S.type="checkbox",S.checked=(i.tools?.allow||[]).includes(u.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(u.name),T.append(S,n("span",void 0,u.name)),y.appendChild(T),E.push({name:u.name,input:S})}f.appendChild(y);const v=n("input","bv-input");v.value=(i.tools?.deny||[]).join(", "),v.placeholder="Always deny (comma separated), e.g. bash, write";const w=n("textarea","bv-textarea");w.rows=2,w.value=(i.packages||[]).join(`
|
|
2
|
+
`),w.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";const x=n("select","bv-input");x.appendChild(new Option("default (Pi settings)",""));for(const u of e.models)x.appendChild(new Option(`${u.provider}/${u.model}`,`${u.provider}
|
|
3
|
+
${u.model}`));i.model?.provider&&i.model?.id&&(x.value=`${i.model.provider}
|
|
4
|
+
${i.model.id}`);const B=n("select","bv-input");for(const u of["","off","minimal","low","medium","high","xhigh","max"])B.appendChild(new Option(u||"default",u));i.model?.thinking&&(B.value=i.model.thinking);const H=n("select","bv-input");for(const u of["supervised","auto-accept-edits","full-access"])H.appendChild(new Option(u,u));H.value=i.permissions?.runtimeMode||"supervised";const N=n("select","bv-input");N.appendChild(new Option("ignore project .pi (recommended)","ignore")),N.appendChild(new Option("inherit project .pi (needs trust)","inherit")),N.value=i.projectResources||"ignore";const W=n("label","bv-check"),O=document.createElement("input");O.type="checkbox",O.checked=!!i.orchestrator,W.append(O,n("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));const g=(u,T)=>{const S=n("div","bv-field");return S.appendChild(n("label","bv-label",u)),S.appendChild(T),S};t.append(g("Name",s),g("Description",a),g("System prompt",r),c.element,d.element,p.element,g("MCP preset",m),f,g("Always deny tools",v),g("Packages",w),g("Model",x),g("Thinking level",B),g("Approval mode",H),g("Project resources",N),W);const I=n("button","btn primary",o?"Save template":"Create template");I.onclick=async()=>{const[u,T]=x.value.split(`
|
|
5
|
+
`),S=e.mcp.find(h=>h.id===m.value),q={name:s.value.trim()||"bot",description:a.value.trim()||void 0,system:r.value.trim()||void 0,skills:c.get(),extensions:d.get().map(h=>(h.startsWith("builtin:"),h)),prompts:p.get(),packages:w.value.split(`
|
|
6
|
+
`).map(h=>h.trim()).filter(Boolean),mcp:S?{mcpServers:S.servers}:void 0,tools:{allow:E.filter(h=>h.input.checked).map(h=>h.name),deny:v.value.split(",").map(h=>h.trim()).filter(Boolean)},model:u?{provider:u,id:T,thinking:B.value||void 0}:void 0,permissions:{runtimeMode:H.value},projectResources:N.value==="inherit"?"inherit":"ignore",orchestrator:O.checked||void 0};try{await k("/api/bots/templates",{method:"POST",body:JSON.stringify({id:o?.id,manifest:q})}),z(),await V()}catch(h){alert(h instanceof Error?h.message:String(h))}},t.appendChild(I)}async function Rt(){return qt("")}async function qt(t){const e=at("New bot"),o=await kt();if(o.length===0){e.appendChild(n("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}const i=n("select","bv-input");for(const p of o)i.appendChild(new Option(p.manifest.name,p.id));const s=n("input","bv-input");s.placeholder="Title (defaults to template name)";const a=n("input","bv-input");a.placeholder="/path/to/project";const r=t||l.bots[0]?.projectPath||"";a.value=r;const c=n("select","bv-input");c.appendChild(new Option("shared \u2014 run in the project folder","shared")),c.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(Q("Template",i),Q("Title",s),Q("Project path",a),Q("Workspace",c));const d=n("button","btn primary","Create bot");d.onclick=async()=>{try{const p=await k("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:a.value.trim()||void 0,isolation:c.value})});z(),await $(!0),await ft(p.id)}catch(p){alert(p instanceof Error?p.message:String(p))}},e.appendChild(d)}function Q(t,e){const o=n("div","bv-field");return o.appendChild(n("label","bv-label",t)),o.appendChild(e),o}async function dt(){const t=at("Needs you");if(l.approvals=await k("/api/bots/approvals"),l.approvals.length===0){t.appendChild(n("div","bots-empty","Nothing waiting."));return}for(const e of l.approvals){const o=n("div","bv-approval");if(o.appendChild(n("div","bv-approval-tag",e.botTitle)),o.appendChild(n("div","bv-approval-title",e.title)),e.message){const p=n("pre","bv-pre bv-approval-detail");p.textContent=e.message,o.appendChild(p)}const i=n("input","bv-reason");i.placeholder="reason (optional)",i.setAttribute("aria-label","Reason (optional)");const s=n("div","bv-approval-actions"),a=n("button","btn primary","Allow once"),r=n("button","btn danger","Deny"),c=[a,r],d=async(p,m)=>{const f=m.textContent??"";for(const y of c)y.disabled=!0;m.textContent=p?"Allowing\u2026":"Denying\u2026";try{await k(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:p,reason:i.value||void 0})}),await $(!0),await dt()}catch(y){for(const E of c)E.disabled=!1;m.textContent=f,_({kind:"notice",level:"error",text:y instanceof Error?y.message:String(y)})}};a.onclick=()=>void d(!0,a),r.onclick=()=>void d(!1,r),s.append(i,a,r),o.appendChild(s),t.appendChild(o)}}function Wt(){window.__botsInited||(window.__botsInited=!0,$t(),Et(),window.__openBot=ft,document.addEventListener("click",t=>{const e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&l.activeId&&setTimeout(()=>tt(),0))},!0),document.addEventListener("click",t=>{const e=t.target;!e||!l.activeId||(e.closest("#mode-files")||e.closest(".file-tree-item")||e.closest(".file-roots-list li"))&&tt()}),$(!0),l.pollTimer=window.setInterval(()=>{document.hidden||$()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(l.pollTimer)))}export{Wt as initBots,qt as openNewBotForPath};
|
package/dist/lib/bots/store.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{existsSync as o,mkdirSync as
|
|
2
|
-
`,{mode:384})}catch{}}readEvents(t,e=2e3){const s=n.join(this.instanceDir(t),"events.jsonl");if(!o(s))return[];const r=
|
|
3
|
-
`).filter(Boolean).slice(-e),l=[];for(const
|
|
1
|
+
import{existsSync as o,mkdirSync as c,readFileSync as u,writeFileSync as h,readdirSync as m,rmSync as p,appendFileSync as S,copyFileSync as D}from"node:fs";import n from"node:path";import{randomBytes as j,randomUUID as y}from"node:crypto";import{getDataRoot as g}from"../state-paths.js";class v{root;instancesFile;instances=new Map;token;constructor(t){this.root=t||process.env.TMUX_WEB_BOTS_DIR||n.join(g(),"bots"),c(this.root,{recursive:!0,mode:448}),c(n.join(this.root,"templates"),{recursive:!0,mode:448}),c(n.join(this.root,"templates",".history"),{recursive:!0,mode:448}),c(n.join(this.root,"instances"),{recursive:!0,mode:448}),this.instancesFile=n.join(this.root,"instances.json"),this.loadInstances(),this.token=this.loadOrCreateToken()}loadOrCreateToken(){const t=n.join(this.root,"api-token");if(o(t)){const s=u(t,"utf8").trim();if(s)return s}const e=j(24).toString("hex");return h(t,e,{mode:384}),e}templatesDir=()=>n.join(this.root,"templates");listTemplates(){const t=this.templatesDir();if(!o(t))return[];const e=[];for(const s of m(t))if(s.endsWith(".json"))try{const i=JSON.parse(u(n.join(t,s),"utf8"));i&&i.id&&i.manifest&&e.push(i)}catch{}return e.sort((s,i)=>s.manifest.name.localeCompare(i.manifest.name))}getTemplate(t){const e=n.join(this.templatesDir(),`${t}.json`);if(!o(e))return null;try{return JSON.parse(u(e,"utf8"))}catch{return null}}saveTemplate(t){const e=new Date().toISOString(),s=t.id||`${Date.now().toString(36)}-${j(3).toString("hex")}`,i=this.getTemplate(s);i&&this.snapshotTemplate(n.join(this.templatesDir(),`${s}.json`),s);const r={id:s,manifest:{...t.manifest,schema:1},createdAt:i?.createdAt||e,updatedAt:e};return h(n.join(this.templatesDir(),`${s}.json`),JSON.stringify(r,null,2),{mode:384}),r}deleteTemplate(t){const e=n.join(this.templatesDir(),`${t}.json`);return o(e)?(this.snapshotTemplate(e,t),p(e),!0):!1}snapshotTemplate(t,e){try{const s=n.join(this.templatesDir(),".history",e);c(s,{recursive:!0,mode:448});const i=new Date().toISOString().replace(/[:.]/g,"-");let r="";for(let a=1;a<1e3;a++){const d=`${i}-${String(a).padStart(3,"0")}`;if(!o(n.join(s,`${d}.json`))){r=d;break}}if(!r)return;D(t,n.join(s,`${r}.json`));const l=m(s).sort();for(const a of l.slice(0,Math.max(0,l.length-10)))p(n.join(s,a),{force:!0})}catch{}}listTemplateHistory(t){const e=n.join(this.templatesDir(),".history",t);return o(e)?m(e).sort():[]}loadInstances(){if(o(this.instancesFile))try{const t=JSON.parse(u(this.instancesFile,"utf8"));for(const e of t)this.instances.set(e.id,e)}catch{}}persistInstances(){h(this.instancesFile,JSON.stringify([...this.instances.values()],null,2),{mode:384})}listInstances(){return[...this.instances.values()].sort((t,e)=>t.createdAt.localeCompare(e.createdAt))}getInstance(t){return this.instances.get(t)||null}saveInstance(t){t.updatedAt=new Date().toISOString(),this.instances.set(t.id,t),this.persistInstances()}deleteInstance(t){this.instances.delete(t),this.persistInstances(),p(this.instanceDir(t),{recursive:!0,force:!0})}instanceDir(t){return n.join(this.root,"instances",t)}agentDir(t){return n.join(this.instanceDir(t),"agent")}sessionsDir(t){return n.join(this.instanceDir(t),"sessions")}appendEvent(t,e){try{c(this.instanceDir(t),{recursive:!0,mode:448}),S(n.join(this.instanceDir(t),"events.jsonl"),`${JSON.stringify(e)}
|
|
2
|
+
`,{mode:384})}catch{}}readEvents(t,e=2e3){const s=n.join(this.instanceDir(t),"events.jsonl");if(!o(s))return[];const r=u(s,"utf8").split(`
|
|
3
|
+
`).filter(Boolean).slice(-e),l=[];for(const a of r)try{l.push(JSON.parse(a))}catch{}return l}newId(){return y()}}let f=null;function F(){return f||(f=new v),f}export{v as BotStore,F as getBotStore};
|
package/dist/lib/pages/shell.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSessionModalHTML as x,newSessionModalScript as g,reducedMotion as f}from"../shared-layout.js";import{icon as o}from"../icons.js";function m(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function
|
|
1
|
+
import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSessionModalHTML as x,newSessionModalScript as g,reducedMotion as f}from"../shared-layout.js";import{icon as o}from"../icons.js";function m(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function n(e="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${e}; outline: none;`}function y(e){const{theme:t,fsRoots:r,terminalCfg:i,scrollback:p,wsBase:s}=e,a=e.version?m(e.version):"",l=`
|
|
2
2
|
*, *::before, *::after { box-sizing: border-box; }
|
|
3
3
|
html, body {
|
|
4
4
|
background: var(--page-bg); color: var(--page-fg);
|
|
@@ -30,7 +30,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
30
30
|
user-select: none;
|
|
31
31
|
}
|
|
32
32
|
.fixed-header .brand:active { background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
|
|
33
|
-
.fixed-header .brand:focus-visible { ${
|
|
33
|
+
.fixed-header .brand:focus-visible { ${n()} }
|
|
34
34
|
.fixed-header .brand span { color: var(--panel-accent); font-weight: 500; }
|
|
35
35
|
.fixed-header .brand a { color: inherit; text-decoration: none; }
|
|
36
36
|
#header-git {
|
|
@@ -98,7 +98,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
98
98
|
}
|
|
99
99
|
.sidebar-footer .mode-btn:hover { color: var(--panel-accent); background: color-mix(in srgb, var(--panel-accent) 8%, transparent); }
|
|
100
100
|
.sidebar-footer .mode-btn.active { color: var(--panel-accent); background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
|
|
101
|
-
.sidebar-footer .mode-btn:focus-visible { ${
|
|
101
|
+
.sidebar-footer .mode-btn:focus-visible { ${n()} }
|
|
102
102
|
|
|
103
103
|
/* \u2500\u2500 Sidebar session mode \u2500\u2500 */
|
|
104
104
|
.session-item {
|
|
@@ -126,7 +126,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
126
126
|
.session-edit-btn { display: flex; align-items: center; opacity: 0.7; }
|
|
127
127
|
.session-item.active .session-edit-btn { opacity: 1; color: var(--panel-accent); }
|
|
128
128
|
}
|
|
129
|
-
.session-edit-btn:focus-visible { ${
|
|
129
|
+
.session-edit-btn:focus-visible { ${n()} }
|
|
130
130
|
|
|
131
131
|
.sidebar-section-label {
|
|
132
132
|
font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em;
|
|
@@ -171,7 +171,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
171
171
|
color: var(--panel-accent); border-color: var(--panel-accent);
|
|
172
172
|
background: color-mix(in srgb, var(--panel-accent) 6%, transparent);
|
|
173
173
|
}
|
|
174
|
-
.new-session-sidebar-btn:focus-visible { ${
|
|
174
|
+
.new-session-sidebar-btn:focus-visible { ${n()} }
|
|
175
175
|
.new-session-sidebar-btn svg { width: 16px; height: 16px; fill: currentColor; }
|
|
176
176
|
|
|
177
177
|
/* \u2500\u2500 Sidebar files mode \u2500\u2500 */
|
|
@@ -225,8 +225,8 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
225
225
|
}
|
|
226
226
|
.session-group-header:hover .sg-add-bot { opacity: 1; color: var(--panel-accent); border-color: var(--panel-accent); }
|
|
227
227
|
@media (hover: none) { .session-group-header .sg-add-bot { opacity: 0.85; } }
|
|
228
|
-
.bv-mode {
|
|
229
|
-
.bv-mode-btn {
|
|
228
|
+
.bv-mode { display: inline-flex; }
|
|
229
|
+
.bv-mode-btn, .bv-icon-btn {
|
|
230
230
|
display: inline-flex; align-items: center; justify-content: center;
|
|
231
231
|
width: 28px; height: 28px; padding: 0; flex: 0 0 auto;
|
|
232
232
|
background: var(--page-bg); color: var(--panel-muted);
|
|
@@ -234,37 +234,46 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
234
234
|
cursor: pointer; touch-action: manipulation;
|
|
235
235
|
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
|
236
236
|
}
|
|
237
|
-
.bv-mode-btn:hover { border-color: var(--panel-accent); color: var(--panel-accent); }
|
|
238
|
-
.bv-mode-btn[aria-expanded="true"]
|
|
237
|
+
.bv-mode-btn:hover, .bv-icon-btn:hover { border-color: var(--panel-accent); color: var(--panel-accent); }
|
|
238
|
+
.bv-mode-btn[aria-expanded="true"], .bv-icon-btn[aria-expanded="true"] {
|
|
239
|
+
border-color: var(--panel-accent); color: var(--panel-accent);
|
|
240
|
+
background: color-mix(in srgb, var(--panel-accent) 10%, transparent);
|
|
241
|
+
}
|
|
239
242
|
/* The shield glyph carries the mode: plain = supervised, arrow = delegated,
|
|
240
243
|
exclamation = everyone runs unattended. */
|
|
241
244
|
.bv-mode-btn[data-mode="parent-supervised"] { color: var(--panel-accent); }
|
|
242
245
|
.bv-mode-btn[data-mode="full-access"] { color: #e0a23c; border-color: color-mix(in srgb, #e0a23c 45%, var(--panel-border)); }
|
|
243
|
-
|
|
246
|
+
/* One menu component for the mode picker and the overflow actions. */
|
|
247
|
+
.bv-menu {
|
|
244
248
|
position: absolute; right: 12px; top: 46px; z-index: 20;
|
|
245
249
|
width: min(320px, calc(100vw - 24px));
|
|
246
250
|
background: var(--panel-bg); border: 1px solid var(--panel-border);
|
|
247
251
|
border-radius: 10px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
|
|
248
252
|
box-shadow: 0 8px 24px rgba(0,0,0,0.35);
|
|
249
253
|
}
|
|
250
|
-
.bv-
|
|
251
|
-
.bv-
|
|
254
|
+
.bv-menu[hidden] { display: none; }
|
|
255
|
+
.bv-menu-item {
|
|
252
256
|
display: grid; grid-template-columns: 18px minmax(0, 1fr) 14px;
|
|
253
|
-
align-items: start; gap: 8px;
|
|
254
|
-
|
|
257
|
+
align-items: start; gap: 8px; text-align: left;
|
|
258
|
+
background: none; border: none; border-radius: 8px; padding: 8px 9px;
|
|
255
259
|
color: var(--page-fg); cursor: pointer; font: inherit; touch-action: manipulation;
|
|
256
260
|
}
|
|
257
|
-
.bv-
|
|
258
|
-
.bv-
|
|
259
|
-
.bv-
|
|
260
|
-
.bv-
|
|
261
|
-
.bv-
|
|
262
|
-
.bv-
|
|
263
|
-
.bv-
|
|
264
|
-
.bv-
|
|
265
|
-
.bv-
|
|
266
|
-
.bv-
|
|
267
|
-
.bv-
|
|
261
|
+
.bv-menu-item:hover { background: color-mix(in srgb, var(--panel-accent) 8%, transparent); }
|
|
262
|
+
.bv-menu-item.active { background: color-mix(in srgb, var(--panel-accent) 12%, transparent); }
|
|
263
|
+
.bv-menu-item:disabled { opacity: 0.45; cursor: default; }
|
|
264
|
+
.bv-menu-icon { color: var(--panel-muted); padding-top: 1px; }
|
|
265
|
+
.bv-menu-item.active .bv-menu-icon { color: var(--panel-accent); }
|
|
266
|
+
.bv-menu-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
267
|
+
.bv-menu-text b { font-size: 12.5px; font-weight: 600; }
|
|
268
|
+
.bv-menu-text span { font-size: 11px; color: var(--panel-muted); line-height: 1.45; }
|
|
269
|
+
.bv-menu-check { color: var(--panel-accent); visibility: hidden; padding-top: 2px; }
|
|
270
|
+
.bv-menu-item.active .bv-menu-check { visibility: visible; }
|
|
271
|
+
.bv-menu-item.danger { color: var(--panel-danger, #e5534b); }
|
|
272
|
+
.bv-menu-item.danger .bv-menu-icon { color: inherit; }
|
|
273
|
+
.bv-menu-sep { height: 1px; margin: 2px 4px; background: var(--panel-border); }
|
|
274
|
+
/* Action rows have a single line of text: centre them in the row. */
|
|
275
|
+
.bv-menu:not(.bv-mode-menu) .bv-menu-item { align-items: center; grid-template-columns: 18px minmax(0, 1fr); }
|
|
276
|
+
.bv-menu:not(.bv-mode-menu) .bv-menu-text b { font-size: 13px; font-weight: 500; }
|
|
268
277
|
.bv-actions .btn {
|
|
269
278
|
height: 28px; min-height: 28px; padding: 0 10px;
|
|
270
279
|
font-size: 11.5px; border-radius: 8px;
|
|
@@ -529,7 +538,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
529
538
|
color: var(--page-fg); transition: opacity 0.15s; text-decoration: none;
|
|
530
539
|
}
|
|
531
540
|
.btn:hover { opacity: 0.85; }
|
|
532
|
-
.btn:focus-visible { ${
|
|
541
|
+
.btn:focus-visible { ${n()} }
|
|
533
542
|
.btn.primary { background: var(--panel-accent); border-color: var(--panel-accent); color: var(--panel-accent-on); font-weight: 500; }
|
|
534
543
|
.btn.primary:hover { opacity: 0.9; }
|
|
535
544
|
.btn.danger { color: #b91c1c; border-color: color-mix(in srgb, #b91c1c 30%, transparent); }
|
|
@@ -765,11 +774,22 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
765
774
|
|
|
766
775
|
.bots-view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--page-bg); z-index: 6; }
|
|
767
776
|
.bots-view[hidden] { display: none; }
|
|
768
|
-
.bots-view-head { display: flex; align-items: center; justify-content: space-between; gap:
|
|
769
|
-
.bv-title { display: flex; align-items: center; gap:
|
|
777
|
+
.bots-view-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--panel-border); flex-shrink: 0; }
|
|
778
|
+
.bv-title { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1 1 auto; }
|
|
770
779
|
.bv-title-text { font-family: var(--font-mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
771
|
-
|
|
780
|
+
/* A pill carries the run state (colour + word); the template and path live in
|
|
781
|
+
its tooltip so the header stays one row on a phone. */
|
|
782
|
+
.bv-status {
|
|
783
|
+
flex: 0 0 auto; max-width: 42%; padding: 0 7px; border-radius: 999px;
|
|
784
|
+
font-size: 10.5px; line-height: 1.7; white-space: nowrap;
|
|
785
|
+
overflow: hidden; text-overflow: ellipsis;
|
|
786
|
+
border: 1px solid color-mix(in srgb, currentColor 32%, transparent);
|
|
787
|
+
background: color-mix(in srgb, currentColor 12%, transparent);
|
|
788
|
+
}
|
|
772
789
|
.bv-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
|
|
790
|
+
.bv-inbox-count { margin-left: 5px; font-size: 10.5px; color: var(--panel-accent); }
|
|
791
|
+
.bv-inbox-count:empty { display: none; }
|
|
792
|
+
.bots-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: var(--panel-muted); }
|
|
773
793
|
|
|
774
794
|
.bots-messages {
|
|
775
795
|
flex: 1; overflow-y: auto; padding: 14px 16px;
|
|
@@ -859,11 +879,26 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
859
879
|
.bv-pre { margin: 0; padding: 8px 10px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; border-top: 1px solid var(--panel-border); color: var(--panel-muted); }
|
|
860
880
|
.bv-output { color: var(--page-fg); }
|
|
861
881
|
|
|
862
|
-
.bv-approval {
|
|
863
|
-
|
|
864
|
-
|
|
882
|
+
.bv-approval {
|
|
883
|
+
border: 1px solid color-mix(in srgb, #e0a23c 55%, var(--panel-border));
|
|
884
|
+
border-radius: 12px; padding: 12px;
|
|
885
|
+
background: color-mix(in srgb, #e0a23c 7%, transparent);
|
|
886
|
+
display: flex; flex-direction: column; gap: 9px;
|
|
887
|
+
}
|
|
888
|
+
.bv-approval-tag { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: #e0a23c; }
|
|
889
|
+
.bv-approval-title { font-size: 13px; font-weight: 600; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
|
|
890
|
+
.bv-approval-detail {
|
|
891
|
+
margin: 0; padding: 8px 10px; max-height: 160px; overflow: auto;
|
|
892
|
+
border: 1px solid var(--panel-border); border-top: 1px solid var(--panel-border);
|
|
893
|
+
border-radius: 8px; background: var(--page-bg); color: var(--panel-muted);
|
|
894
|
+
}
|
|
895
|
+
/* Stacked, full-width buttons: the primary answer is reachable with a thumb and
|
|
896
|
+
long tool names cannot squeeze the row. */
|
|
897
|
+
.bv-approval-actions { display: flex; flex-direction: column; gap: 8px; }
|
|
898
|
+
.bv-approval-actions .btn { width: 100%; min-height: 40px; padding: 0 12px; justify-content: center; }
|
|
865
899
|
.bv-approval-decided { font-size: 11px; color: var(--panel-muted); }
|
|
866
|
-
.bv-reason {
|
|
900
|
+
.bv-reason { width: 100%; min-width: 0; background: var(--page-bg); color: var(--page-fg); border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 10px; font-size: 12px; }
|
|
901
|
+
.bv-reason::placeholder { color: var(--panel-muted); opacity: 0.6; }
|
|
867
902
|
|
|
868
903
|
.bv-notice { font-size: 11.5px; color: var(--panel-muted); }
|
|
869
904
|
.bv-notice-warn { color: #e0a23c; }
|
|
@@ -933,34 +968,41 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
933
968
|
${b()}
|
|
934
969
|
@media (max-width: 640px) {
|
|
935
970
|
.app-layout { flex-direction: column; }
|
|
936
|
-
/* Bots chat on phones:
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
.
|
|
940
|
-
.
|
|
941
|
-
.bv-actions { flex:
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
.bv-
|
|
945
|
-
.bv-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
.bv-
|
|
949
|
-
/* Full-width bottom sheet: anything less leaves a strip of the composer
|
|
950
|
-
(and its placeholder) visible around the panel. */
|
|
971
|
+
/* Bots chat on phones: one header row (title + status pill + three thumb-sized
|
|
972
|
+
controls), menus as bottom sheets, and a 16px composer so iOS does not zoom
|
|
973
|
+
the page on focus. */
|
|
974
|
+
.bots-view-head { flex-wrap: nowrap; row-gap: 0; padding: 4px 10px; }
|
|
975
|
+
.bots-dot { display: none; }
|
|
976
|
+
.bv-actions { flex: 0 0 auto; overflow: visible; }
|
|
977
|
+
.bv-actions .btn, .bv-mode-btn, .bv-icon-btn { height: 44px; min-height: 44px; }
|
|
978
|
+
.bv-actions .btn { padding: 0 12px; font-size: 12px; }
|
|
979
|
+
.bv-mode-btn, .bv-icon-btn { width: 44px; padding: 0; }
|
|
980
|
+
.bv-mode-btn svg, .bv-icon-btn svg { width: 18px; height: 18px; }
|
|
981
|
+
/* Full-width bottom sheet: anything less leaves a strip of the composer
|
|
982
|
+
(and its placeholder) visible around the panel. */
|
|
983
|
+
.bv-menu {
|
|
951
984
|
position: fixed; left: 0; right: 0; top: auto; bottom: 0;
|
|
952
|
-
width: auto; max-height:
|
|
985
|
+
width: auto; max-height: 70vh; overflow-y: auto;
|
|
953
986
|
border-radius: 12px 12px 0 0;
|
|
954
987
|
border-left: none; border-right: none; border-bottom: none;
|
|
955
988
|
padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
|
|
956
989
|
box-shadow: 0 -8px 28px rgba(0,0,0,0.45);
|
|
957
990
|
}
|
|
991
|
+
.bv-menu-item { padding: 12px 10px; }
|
|
992
|
+
.bv-menu-text b { font-size: 13.5px; }
|
|
993
|
+
.bv-menu-text span { font-size: 12px; }
|
|
958
994
|
.bots-messages { padding: 10px; }
|
|
959
|
-
.bv-msg { max-width: 100%; }
|
|
995
|
+
.bv-msg { max-width: 100%; font-size: 14px; }
|
|
996
|
+
.bv-text code, .bv-user code { font-size: 12.5px; }
|
|
997
|
+
.bv-code code { font-size: 12px; }
|
|
998
|
+
.bv-text table { font-size: 13px; }
|
|
999
|
+
.bv-tool { font-size: 12px; }
|
|
1000
|
+
.bv-pre { font-size: 11.5px; }
|
|
1001
|
+
.bv-tool > summary { min-height: 44px; padding: 6px 10px; }
|
|
1002
|
+
.bv-approval { padding: 12px; }
|
|
1003
|
+
.bv-approval-actions .btn { min-height: 44px; }
|
|
960
1004
|
/* Keep the field clear of the home-indicator gesture bar. */
|
|
961
1005
|
.bots-composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px; gap: 6px; }
|
|
962
|
-
.bv-approval-actions { flex-wrap: wrap; }
|
|
963
|
-
.bv-reason { flex: 1 1 100%; }
|
|
964
1006
|
.sidebar { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--panel-border); transition: max-height 0.2s; }
|
|
965
1007
|
/* An expanded list must leave room for the terminal/chat below it; without a
|
|
966
1008
|
cap a long session list pushed the main area off-screen. */
|
|
@@ -980,6 +1022,17 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
980
1022
|
}
|
|
981
1023
|
}
|
|
982
1024
|
|
|
1025
|
+
/* A finger needs 44px targets regardless of width: landscape phones and
|
|
1026
|
+
tablets lay out like desktop but are still touched. */
|
|
1027
|
+
@media (pointer: coarse) {
|
|
1028
|
+
.bv-actions .btn, .bv-mode-btn, .bv-icon-btn { height: 44px; min-height: 44px; }
|
|
1029
|
+
.bv-actions .btn { padding: 0 12px; font-size: 12px; }
|
|
1030
|
+
.bv-mode-btn, .bv-icon-btn { width: 44px; }
|
|
1031
|
+
.bv-mode-btn svg, .bv-icon-btn svg { width: 18px; height: 18px; }
|
|
1032
|
+
.bv-approval-actions .btn { min-height: 44px; }
|
|
1033
|
+
.bv-tool > summary { min-height: 44px; }
|
|
1034
|
+
}
|
|
1035
|
+
|
|
983
1036
|
/* Forced narrow layout (settings toggle): same rules as the 640px
|
|
984
1037
|
breakpoint, applied unconditionally when the html has .force-narrow. */
|
|
985
1038
|
html.force-narrow .app-layout { flex-direction: column; }
|
|
@@ -994,12 +1047,12 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
994
1047
|
display: flex; flex-wrap: nowrap; gap: 4px;
|
|
995
1048
|
overflow-x: auto; overscroll-behavior-x: contain;
|
|
996
1049
|
}
|
|
997
|
-
`,v=JSON.stringify(t.terminal).replace(/</g,"\\u003c"),d=JSON.stringify({terminal:i,scrollback:
|
|
1050
|
+
`,v=JSON.stringify(t.terminal).replace(/</g,"\\u003c"),d=JSON.stringify({terminal:i,scrollback:p,theme:t.terminal,fsRoots:r,wsBase:s||""}).replace(/</g,"\\u003c");return`<!DOCTYPE html>
|
|
998
1051
|
<html lang="en">
|
|
999
1052
|
<head>
|
|
1000
1053
|
<meta charset="UTF-8" />
|
|
1001
1054
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
1002
|
-
<meta name="tw-build" content="${
|
|
1055
|
+
<meta name="tw-build" content="${a}" />
|
|
1003
1056
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
1004
1057
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
1005
1058
|
<meta name="apple-mobile-web-app-title" content="tmux-web" />
|
|
@@ -1106,7 +1159,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
1106
1159
|
<!-- Settings popover -->
|
|
1107
1160
|
<div class="popover-backdrop" id="settings-backdrop"></div>
|
|
1108
1161
|
<div class="settings-popover" id="settings-popover">
|
|
1109
|
-
<div style="padding:1px 2px 6px;font-size:10px;color:var(--panel-muted);opacity:.8;font-family:var(--font-mono)">tmux-weblink v${
|
|
1162
|
+
<div style="padding:1px 2px 6px;font-size:10px;color:var(--panel-muted);opacity:.8;font-family:var(--font-mono)">tmux-weblink v${a}</div>
|
|
1110
1163
|
<div style="padding:4px 0">
|
|
1111
1164
|
<button class="theme-option" data-theme="vscode" title="VS Code"><span class="theme-dot" style="background:#007acc"></span>VS Code${t.template==="vscode"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
1112
1165
|
<button class="theme-option" data-theme="ghostty" title="Ghostty"><span class="theme-dot" style="background:#ff5f00"></span>Ghostty${t.template==="ghostty"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
@@ -1277,4 +1330,4 @@ if ('serviceWorker' in navigator) {
|
|
|
1277
1330
|
}
|
|
1278
1331
|
</script>
|
|
1279
1332
|
</body>
|
|
1280
|
-
</html>`}export{
|
|
1333
|
+
</html>`}export{y as renderShell};
|