tmux-weblink 2.2.50 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/shell-client.js +114 -37
- package/dist/browser/bots-client.js +6 -6
- package/dist/browser/markdown.js +2 -0
- package/dist/lib/bots/manager.js +3 -3
- package/dist/lib/pages/shell.js +130 -11
- package/package.json +3 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{icon as D}from"../lib/icons.js";const a={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};function R(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function f(t,e){const n=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${R()}`,...e?.headers||{}}}),i=await n.text(),s=i?JSON.parse(i):null;if(!n.ok)throw new Error(s&&s.error||`HTTP ${n.status}`);return s}function o(t,e,n){const i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function nt(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 P(){const t=document.getElementById("bots-view");if(!t)return;const e=window.visualViewport,n=window.matchMedia("(max-width: 640px)").matches,i=!document.querySelector(".sidebar")?.classList.contains("collapsed");if(a.activeId&&e&&n&&!i){const s=document.querySelector(".fixed-header"),l=s?Math.round(s.getBoundingClientRect().height):0;t.style.position="fixed",t.style.top=`${Math.round(e.offsetTop)+l}px`,t.style.left=`${Math.round(e.offsetLeft)}px`,t.style.width=`${Math.round(e.width)}px`,t.style.height=`${Math.max(120,Math.round(e.height)-l)}px`,t.style.right="auto",t.style.bottom="auto"}else 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",P),window.visualViewport?.addEventListener("scroll",P),window.addEventListener("resize",P),document.addEventListener("click",()=>setTimeout(P,0));function j(){const t=a.approvals.length,e=document.getElementById("bots-inbox-badge");e&&(e.style.display=t?"inline-block":"none",e.textContent=String(t));const n=document.getElementById("bv-inbox-count");n&&(n.textContent=t?`(${t})`:""),window.__botsSnapshot=a.bots,window.__refreshSidebar?.()}function ot(){const t=document.getElementById("set-bot-templates"),e=document.getElementById("set-bot-new"),n=document.getElementById("set-bot-inbox"),i=()=>{document.getElementById("settings-popover")?.classList.remove("open"),document.getElementById("settings-backdrop")?.classList.remove("open")};t?.addEventListener("click",()=>{i(),A()}),e?.addEventListener("click",()=>{i(),bt()}),n?.addEventListener("click",()=>{i(),Q()})}function it(){const t=o("div","bots-view");t.id="bots-view",t.hidden=!0;const e=o("div","bots-view-head"),n=o("div","bv-title"),i=o("span","bots-dot");i.id="bv-dot";const s=o("span","bv-title-text");s.id="bv-title";const l=o("span","bv-status");l.id="bv-status",n.append(i,s,l);const d=o("div","bv-actions"),p=o("div","bv-mode"),r=o("button","bv-mode-btn");r.id="bv-mode-btn",r.type="button",r.title="\u5BA1\u6279\u6A21\u5F0F\uFF08\u70B9\u5F00\u770B\u8BF4\u660E\uFF09",r.innerHTML=`<span id="bv-mode-label"></span>${D("chevron-down",'width="12" height="12"')}`;const u=o("div","bv-mode-menu");u.id="bv-mode-menu",u.hidden=!0;for(const[b,v,L]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 c=o("button");c.dataset.mode=b,c.innerHTML=`<b>${v}</b><span>${L}</span>`,c.onclick=()=>{u.hidden=!0,st(b)},u.appendChild(c)}r.onclick=b=>{b.stopPropagation(),u.hidden=!u.hidden},p.append(r,u),document.addEventListener("click",b=>{p.contains(b.target)||(u.hidden=!0)});const m=o("button","btn","Allow all");m.id="bv-allow-all",m.title="Approve every pending request for this bot",m.onclick=()=>{if(!a.activeId)return;const b=a.approvals.filter(v=>v.botId===a.activeId);Promise.all(b.map(v=>f(`/api/bots/${v.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:v.id,allow:!0})}))).finally(()=>void S(!0))};const h=o("button","btn","Needs you "),I=o("span");I.id="bv-inbox-count",h.appendChild(I),h.onclick=()=>void Q();const E=o("button","btn","Resume");E.onclick=()=>void G(b=>f(`/api/bots/${b}/resume`,{method:"POST"}).then(()=>S(!0)));const C=o("button","btn danger","Stop");C.onclick=()=>void G(b=>f(`/api/bots/${b}/stop`,{method:"POST"}).then(()=>S(!0)));const y=o("button","btn","Delete");y.onclick=()=>{a.activeId&&confirm("Delete this bot and its session?")&&f(`/api/bots/${a.activeId}`,{method:"DELETE"}).then(()=>{H(),S(!0)})};const x=o("button","btn");x.innerHTML=D("close",'width="14" height="14"'),x.title="Close bot view",x.onclick=()=>H(),d.append(p,m,h,E,C,y,x),e.append(n,d);const O=o("div","bots-messages");O.id="bots-messages";const B=o("div","bots-composer"),w=o("textarea");w.id="bots-input",w.rows=1,w.placeholder="Message the bot\u2026 (Enter to send, Shift+Enter for newline)",w.onkeydown=b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),F())};const $=o("button","btn primary");$.title="Send",$.setAttribute("aria-label","Send"),$.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>',$.onclick=()=>void F(),B.append(w,$),t.append(e,O,B),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||ut()}async function F(){const t=document.getElementById("bots-input");if(!t||!a.activeId||!t.value.trim())return;const e=t.value;t.value="";try{await f(`/api/bots/${a.activeId}/input`,{method:"POST",body:JSON.stringify({text:e})})}catch(n){T({kind:"notice",level:"error",text:n instanceof Error?n.message:String(n)})}}function G(t){a.activeId&&t(a.activeId).catch(e=>T({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function H(){a.activeId=null,P();const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{a.ws?.close()}catch{}a.ws=null,j();const e=document.getElementById("terminal-container"),n=document.getElementById("main-placeholder"),i=!!document.querySelector(".session-item.active:not(.bot-item)");e&&i?(e.style.display="",n&&(n.style.display="none")):n&&(n.style.display="")}async function K(t){a.activeId=t,window.__collapseSidebar?.(),P(),a.items.set(t,[]);const e=document.getElementById("bots-view");e&&(e.hidden=!1);const n=document.getElementById("main-placeholder");n&&(n.style.display="none");const i=document.getElementById("terminal-container");i&&(i.style.display="none");const s=document.getElementById("file-editor");s&&(s.style.display="none"),j(),U();try{a.ws?.close()}catch{}const l=location.protocol==="https:"?"wss:":"ws:",d=new WebSocket(`${l}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(R())}`);a.ws=d,d.onmessage=p=>{try{X(JSON.parse(String(p.data)))}catch{}},d.onclose=()=>{a.activeId===t&&setTimeout(()=>{a.activeId===t&&S(!0)},1500)},await S(!0)}function q(){return a.bots.find(t=>t.id===a.activeId)||null}function W(){const t=q();if(!t)return;const e=document.getElementById("bv-title"),n=document.getElementById("bv-status"),i=document.getElementById("bv-dot");e&&(e.textContent=t.title),n&&(n.textContent=`${t.status.replace(/_/g," ")} \xB7 ${t.templateId} \xB7 ${t.projectPath}`);const s=document.getElementById("bv-mode-label");s&&t.runtimeMode&&(s.textContent=Y[t.runtimeMode]||t.runtimeMode);for(const p of document.querySelectorAll("#bv-mode-menu button"))p.classList.toggle("active",p.dataset.mode===t.runtimeMode);const l=document.getElementById("bv-allow-all"),d=a.approvals.filter(p=>p.botId===t.id).length;l&&(l.hidden=d===0,l.textContent=`Allow all (${d})`),i&&(i.style.background=nt(t.status))}const Y={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"};async function st(t){if(a.activeId)try{await f(`/api/bots/${a.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});const e=q();e&&(e.runtimeMode=t),W(),T({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${Y[t]||t}`})}catch(e){T({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function T(t,e=a.activeId){if(!e)return;const n=a.items.get(e)||[];n.push(t),a.items.set(e,n),e===a.activeId&&M()}function M(){a.renderQueued||(a.renderQueued=!0,requestAnimationFrame(()=>{a.renderQueued=!1,U()}))}function U(){const t=document.getElementById("bots-messages");if(!t||!a.activeId)return;const e=a.items.get(a.activeId)||[];t.textContent="";let n=null;for(const i of e)if(i.kind==="user"){const s=o("div","bv-msg bv-user");s.textContent=i.text,t.appendChild(s),n=null}else if(i.kind==="assistant"){const s=o("div","bv-msg bv-assistant");if(i.thinking){const d=o("details","bv-thinking");d.appendChild(o("summary",void 0,"thinking")),d.appendChild(o("div",void 0,i.thinking)),s.appendChild(d)}const l=o("div","bv-text");l.textContent=i.text,s.appendChild(l),t.appendChild(s),n=l}else if(i.kind==="tool")t.appendChild(at(i)),n=null;else if(i.kind==="approval")t.appendChild(dt(i)),n=null;else if(i.kind==="notice"){const s=o("div",`bv-notice bv-notice-${i.level}`,i.text);t.appendChild(s)}n&&(n.scrollTop=n.scrollHeight),t.scrollTop=t.scrollHeight}function at(t){const e=o("details","bv-tool");e.open=t.phase!=="end"||!!t.isError;const n=o("summary"),i=o("span","bv-tool-name",t.name);if(n.appendChild(i),t.phase!=="end"&&n.appendChild(o("span","bv-tool-phase",t.phase)),t.isError&&n.appendChild(o("span","bv-tool-error","error")),typeof t.durationMs=="number"&&n.appendChild(o("span","bv-tool-meta",`${Math.round(t.durationMs)}ms`)),e.appendChild(n),t.args!==void 0){const s=o("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=o("pre","bv-pre bv-output");s.textContent=t.output,e.appendChild(s)}return e}function dt(t){const e=o("div","bv-approval"),n=t.approval;if(e.appendChild(o("div","bv-approval-title",n.title)),n.message&&e.appendChild(o("pre","bv-pre",n.message)),t.decided)return e.appendChild(o("div","bv-approval-decided",t.decided==="allowed"?"Allowed":"Denied")),e;const i=o("input","bv-reason");i.placeholder="reason (optional)";const s=o("div","bv-approval-actions"),l=o("button","btn primary","Allow"),d=o("button","btn",n.method==="confirm"&&/^Allow (.+?)\?$/.test(n.title)?`Always allow ${/^Allow (.+?)\?$/.exec(n.title)?.[1]}`:"Always allow");d.hidden=n.method!=="confirm";const p=o("button","btn danger","Deny"),r=async(u,m=!1)=>{try{await f(`/api/bots/${n.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:n.id,allow:u,always:m,reason:i.value||void 0})}),t.decided=u?"allowed":"denied",M(),S(!0)}catch(h){T({kind:"notice",level:"error",text:h instanceof Error?h.message:String(h)})}};return l.onclick=()=>void r(!0),d.onclick=()=>void r(!0,!0),p.onclick=()=>void r(!1),s.append(i,l,d,p),e.appendChild(s),e}function X(t){const e=String(t.type||""),n=a.activeId;if(!n)return;const i=a.items.get(n)||[];if(e==="snapshot")a.items.set(n,[]);else if(e==="user")T({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=q();s&&(s.status=String(t.status||s.status)),W(),ct()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const d=lt(s),p=rt(s),r=i[i.length-1];r&&r.kind==="assistant"?(r.text=d||r.text,r.thinking=p||r.thinking):i.push({kind:"assistant",text:d,thinking:p}),a.items.set(n,i),M()}else if(e==="delta"){const s=String(t.kind||""),l=String(t.delta||"");let d=i[i.length-1];(!d||d.kind!=="assistant")&&(i.push({kind:"assistant",text:"",thinking:""}),d=i[i.length-1]),d.kind==="assistant"&&(s==="text"?d.text+=l:s==="thinking"&&(d.thinking+=l)),a.items.set(n,i),M()}else if(e==="tool"){const s=String(t.callId||""),l=i.find(p=>p.kind==="tool"&&p.callId===s),d=String(t.phase||"start");l?(l.phase=d,d==="update"&&t.output&&(l.output=String(t.output)),d==="end"&&(t.output&&(l.output=String(t.output)),l.isError=t.isError===!0,typeof t.durationMs=="number"&&(l.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:d}),a.items.set(n,i),M()}else if(e==="approval"){const s=t.approval;if(!s)return;const l=i;for(let d=l.length-1;d>=0;d--){const p=l[d];if(p.kind==="approval"&&p.approval.id===s.id){p.approval=s,s.state!=="pending"&&(p.decided=s.state==="allowed"?"allowed":"denied"),a.items.set(n,l),M();return}}l.push({kind:"approval",approval:s}),a.items.set(n,l),M()}else e==="notice"&&T({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function lt(t){const e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="text"?String(n.text||""):"").join(""):String(t.text||"")}function rt(t){const e=t.content;return Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&n.type==="thinking"?String(n.thinking||""):"").join(""):""}async function S(t=!1){try{const[e,n]=await Promise.all([f("/api/bots"),f("/api/bots/approvals")]);if(a.bots=e,a.approvals=n,j(),W(),t&&a.activeId){const i=await f(`/api/bots/${a.activeId}/events?limit=300`);pt(i)}}catch{}}async function ct(){try{a.bots=await f("/api/bots"),j()}catch{}}function pt(t){if(a.activeId){a.items.set(a.activeId,[]);for(const e of t)X(e);U()}}function ut(){const t=o("div","bots-modal");t.id="bots-modal",t.hidden=!0;const e=o("div","bots-modal-card"),n=o("div","bots-modal-head"),i=o("span");i.id="bots-modal-title";const s=o("button","btn");s.innerHTML=D("close",'width="14" height="14"'),s.title="Close",s.onclick=()=>J(),n.append(i,s);const l=o("div","bots-modal-body");l.id="bots-modal-body",e.append(n,l),t.appendChild(e),t.onclick=d=>{d.target===t&&J()},document.body.appendChild(t)}function V(t){const e=document.getElementById("bots-modal"),n=document.getElementById("bots-modal-title"),i=document.getElementById("bots-modal-body");if(!e||!i)throw new Error("modal missing");return n&&(n.textContent=t),i.textContent="",e.hidden=!1,i}function J(){const t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function mt(){return a.catalog||(a.catalog=await f("/api/bots/catalog")),a.catalog}async function Z(){return a.templates=await f("/api/bots/templates"),a.templates}async function A(){const t=V("Bot templates"),[e,n]=await Promise.all([mt(),Z()]),i=o("div","bv-template-list");for(const r of n){const u=o("div","bv-template-row");u.appendChild(o("span","bv-template-name",r.manifest.name)),u.appendChild(o("span","bv-template-desc",r.manifest.description||""));const m=o("button","btn","Edit");m.onclick=()=>tt(t,e,r);const h=o("button","btn","Copy");h.title="Duplicate this template",h.onclick=()=>{const C=JSON.parse(JSON.stringify(r.manifest));C.name=`${r.manifest.name} copy`,f("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:C})}).then(()=>A()).catch(y=>alert(y instanceof Error?y.message:String(y)))};const I=o("button","btn danger","Delete");I.onclick=()=>{confirm(`Delete template ${r.manifest.name}?`)&&f(`/api/bots/templates/${r.id}`,{method:"DELETE"}).then(()=>A())};const E=o("span","bv-template-actions");E.append(m,h,I),u.appendChild(E),i.appendChild(u)}n.length===0&&i.appendChild(o("div","bots-empty","No templates yet")),t.appendChild(i);const s=o("div","bv-template-actions"),l=o("button","btn primary","New template");l.onclick=()=>tt(t,e,null);const d=o("button","btn","Export");d.title="Download templates + library as JSON",d.onclick=()=>{(async()=>{try{const r=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${R()}`}});if(!r.ok)throw new Error(`HTTP ${r.status}`);const u=await r.blob(),m=document.createElement("a");m.href=URL.createObjectURL(u),m.download=`tmux-weblink-bots-${new Date().toISOString().slice(0,10)}.json`,m.click(),setTimeout(()=>URL.revokeObjectURL(m.href),2e3)}catch(r){alert(r instanceof Error?r.message:String(r))}})()};const p=o("button","btn","Import");p.title="Restore templates from a JSON bundle",p.onclick=()=>{const r=document.createElement("input");r.type="file",r.accept="application/json,.json",r.onchange=()=>{const u=r.files?.[0];u&&(async()=>{try{const m=JSON.parse(await u.text()),h=await f("/api/bots/import",{method:"POST",body:JSON.stringify(m)});alert(`Imported ${h.templates} templates, ${h.files} library files (${h.skipped} kept)`),await A()}catch(m){alert(m instanceof Error?m.message:String(m))}})()},r.click()},s.append(l,d,p),t.appendChild(s)}function z(t,e,n){const i=o("div","bv-field");i.appendChild(o("label","bv-label",t));const s=o("div","bv-check-grid"),l=[];for(const d of e){const p=o("label","bv-check"),r=document.createElement("input");r.type="checkbox",r.checked=n.includes(d.id),p.append(r,o("span",void 0,d.label)),d.hint&&(p.title=d.hint),s.appendChild(p),l.push({id:d.id,input:r})}return i.appendChild(s),{element:i,get:()=>l.filter(d=>d.input.checked).map(d=>d.id)}}function tt(t,e,n){t.textContent="";const i=n?JSON.parse(JSON.stringify(n.manifest)):{name:"new-bot",description:""},s=o("input","bv-input");s.value=i.name,s.placeholder="Template name";const l=o("input","bv-input");l.value=i.description||"",l.placeholder="One line description";const d=o("textarea","bv-textarea");d.rows=6,d.value=i.system||"",d.placeholder="System prompt for this bot (written to SYSTEM.md)";const p=z("Skills",e.skills.map(c=>({id:c.id,label:c.name,hint:c.description})),i.skills||[]),r=z("Extensions (Pi builtins + library)",e.extensions.map(c=>({id:c.id,label:`${c.name}${c.kind==="builtin"?" (builtin)":""}`,hint:c.description})),(i.extensions||[]).map(c=>c.replace(/^.*\//,"").replace(/\.(js|ts)$/,""))),u=z("Prompt templates",e.prompts.map(c=>({id:c.id,label:c.name})),i.prompts||[]),m=o("select","bv-input");m.appendChild(new Option("none",""));for(const c of e.mcp)m.appendChild(new Option(c.name,c.id));i.mcp&&(m.value=e.mcp.find(c=>JSON.stringify(c.servers)===JSON.stringify(i.mcp?.mcpServers))?.id||"");const h=o("div","bv-field");h.appendChild(o("label","bv-label","Tools (allow list; deny always blocks)"));const I=o("div","bv-check-grid"),E=[];for(const c of e.tools){const N=o("label","bv-check"),k=document.createElement("input");k.type="checkbox",k.checked=(i.tools?.allow||[]).includes(c.name)||!i.tools?.allow?.length&&["read","grep","find","ls","edit","write","bash"].includes(c.name),N.append(k,o("span",void 0,c.name)),I.appendChild(N),E.push({name:c.name,input:k})}h.appendChild(I);const C=o("input","bv-input");C.value=(i.tools?.deny||[]).join(", "),C.placeholder="Always deny (comma separated), e.g. bash, write";const y=o("textarea","bv-textarea");y.rows=2,y.value=(i.packages||[]).join(`
|
|
2
|
-
`),
|
|
3
|
-
${
|
|
4
|
-
${i.model.id}`);const
|
|
5
|
-
`),
|
|
6
|
-
`).map(
|
|
1
|
+
import{icon as D}from"../lib/icons.js";import{createMarkdownRenderer as ht}from"./markdown.js";const F=ht(document),d={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};let L=[],B=!0,bt=!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 ft(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,vt()}))}let z=0,R="";function vt(){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(d.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),l=Math.round(e.width),u=Math.max(120,Math.round(e.height)-r),h=`fixed|${a}|${c}|${l}|${u}`;if(h===R)return;R=h,t.style.position="fixed",t.style.top=`${a}px`,t.style.left=`${c}px`,t.style.width=`${l}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=d.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=d.bots,window.__refreshSidebar?.()}function gt(){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(),H()}),e?.addEventListener("click",()=>{i(),Tt()}),o?.addEventListener("click",()=>{i(),ot()})}function yt(){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"),l=n("button","bv-mode-btn");l.id="bv-mode-btn",l.type="button",l.title="\u5BA1\u6279\u6A21\u5F0F\uFF08\u70B9\u5F00\u770B\u8BF4\u660E\uFF09",l.innerHTML=`<span id="bv-mode-label"></span>${D("chevron-down",'width="12" height="12"')}`;const u=n("div","bv-mode-menu");u.id="bv-mode-menu",u.hidden=!0;for(const[m,$,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,_.innerHTML=`<b>${$}</b><span>${v}</span>`,_.onclick=()=>{u.hidden=!0,wt(m)},u.appendChild(_)}l.onclick=m=>{m.stopPropagation(),u.hidden=!u.hidden},c.append(l,u),document.addEventListener("click",m=>{c.contains(m.target)||(u.hidden=!0)});const h=n("button","btn","Allow all");h.id="bv-allow-all",h.title="Approve every pending request for this bot",h.onclick=()=>{if(!d.activeId)return;const m=d.approvals.filter($=>$.botId===d.activeId);Promise.all(m.map($=>b(`/api/bots/${$.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:$.id,allow:!0})}))).finally(()=>void C(!0))};const f=n("button","btn","Needs you "),O=n("span");O.id="bv-inbox-count",f.appendChild(O),f.onclick=()=>void ot();const M=n("button","btn","Resume");M.onclick=()=>void dt(m=>b(`/api/bots/${m}/resume`,{method:"POST"}).then(()=>C(!0)));const I=n("button","btn danger","Stop");I.onclick=()=>void dt(m=>b(`/api/bots/${m}/stop`,{method:"POST"}).then(()=>C(!0)));const x=n("button","btn","Delete");x.onclick=()=>{d.activeId&&confirm("Delete this bot and its session?")&&b(`/api/bots/${d.activeId}`,{method:"DELETE"}).then(()=>{K(),C(!0)})};const E=n("button","btn");E.innerHTML=D("close",'width="14" height="14"'),E.title="Close bot view",E.onclick=()=>K(),a.append(c,h,f,M,I,x,E),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=`${D("chevron-down",'width="14" height="14"')}<span>Latest</span>`,y.title="Jump to the latest message",y.hidden=!0,y.onclick=()=>{B=!0,g.scrollTop=g.scrollHeight,y.hidden=!0};const j=()=>{B=g.scrollHeight-g.scrollTop-g.clientHeight<48,y.hidden=B};g.addEventListener("scroll",j,{passive:!0}),g.addEventListener("touchmove",()=>{B=!1,y.hidden=g.scrollHeight-g.clientHeight<1},{passive:!0}),g.addEventListener("wheel",()=>{B=!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),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||Ot()}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||!d.activeId||bt||!t.value.trim())return;const e=d.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=""),B=!0}catch(i){Q(i instanceof Error?i.message:String(i))}finally{at(!1)}}function dt(t){d.activeId&&t(d.activeId).catch(e=>P({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function K(){d.activeId=null,L=[],B=!0,N();const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{d.ws?.close()}catch{}d.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){d.activeId=t,L=[],B=!0;const e=document.getElementById("bv-jump");e&&(e.hidden=!0),window.__collapseSidebar?.(),N(),d.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{d.ws?.close()}catch{}const a=location.protocol==="https:"?"wss:":"ws:",c=new WebSocket(`${a}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(U())}`);d.ws=c,c.onmessage=l=>{try{pt(JSON.parse(String(l.data)))}catch{}},c.onclose=()=>{d.activeId===t&&setTimeout(()=>{d.activeId===t&&C(!0)},1500)},await C(!0)}function G(){return d.bots.find(t=>t.id===d.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-label");s&&t.runtimeMode&&(s.textContent=ct[t.runtimeMode]||t.runtimeMode);for(const c of document.querySelectorAll("#bv-mode-menu button"))c.classList.toggle("active",c.dataset.mode===t.runtimeMode);const r=document.getElementById("bv-allow-all"),a=d.approvals.filter(c=>c.botId===t.id).length;r&&(r.hidden=a===0,r.textContent=`Allow all (${a})`),i&&(i.style.background=ft(t.status))}const ct={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"};async function wt(t){if(d.activeId)try{await b(`/api/bots/${d.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=d.activeId){if(!e)return;const o=d.items.get(e)||[];o.push(t),d.items.set(e,o),e===d.activeId&&A()}function A(){if(d.renderQueued)return;d.renderQueued=!0;const t=Math.max(0,60-(performance.now()-it));window.setTimeout(()=>{d.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 kt(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"?xt(t):t.kind==="approval"?Ct(t):n("div",`bv-notice bv-notice-${t.level}`,t.text)}function St(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||!d.activeId||document.getElementById("bots-view")?.hidden)return;const e=d.items.get(d.activeId)||[],o=B;if(e.length<L.length||e.some((s,r)=>L[r]?.item!==s))t.textContent="",L=e.map(s=>{const r=Z(s);return t.appendChild(r),{item:s,snapshot:X(s),node:r}});else{for(let s=L.length;s<e.length;s++){const r=e[s],a=Z(r);t.appendChild(a),L.push({item:r,snapshot:X(r),node:a})}for(let s=0;s<e.length;s++){const r=e[s],a=L[s],c=X(r);if(kt(a.snapshot,c)){if(r.kind==="assistant")St(a.node,r);else{const l=Z(r);a.node.replaceWith(l),a.node=l}a.snapshot=c}}}o&&(t.scrollTop=t.scrollHeight)}function xt(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 Ct(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"),l=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",A(),C(!0)}catch(f){P({kind:"notice",level:"error",text:f instanceof Error?f.message:String(f)})}};return r.onclick=()=>void l(!0),a.onclick=()=>void l(!0,!0),c.onclick=()=>void l(!1),s.append(i,r,a,c),e.appendChild(s),e}function pt(t){const e=String(t.type||""),o=d.activeId;if(!o)return;const i=d.items.get(o)||[];if(e==="snapshot")d.items.set(o,[]);else if(e==="user")B=!0,P({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=G();s&&(s.status=String(t.status||s.status)),Y(),Bt()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const a=It(s),c=Et(s),l=i[i.length-1];l&&l.kind==="assistant"?(l.text=a||l.text,l.thinking=c||l.thinking):i.push({kind:"assistant",text:a,thinking:c}),d.items.set(o,i),A()}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)),d.items.set(o,i),A()}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}),d.items.set(o,i),A()}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"),d.items.set(o,r),A();return}}r.push({kind:"approval",approval:s}),d.items.set(o,r),A()}else e==="notice"&&P({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function It(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 Et(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 C(t=!1){try{const[e,o]=await Promise.all([b("/api/bots"),b("/api/bots/approvals")]);if(d.bots=e,d.approvals=o,q(),Y(),t&&d.activeId){const i=await b(`/api/bots/${d.activeId}/events?limit=300`);$t(i)}}catch{}}async function Bt(){try{d.bots=await b("/api/bots"),q()}catch{}}function $t(t){if(d.activeId){d.items.set(d.activeId,[]);for(const e of t)pt(e);tt()}}function Ot(){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=D("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 Mt(){return d.catalog||(d.catalog=await b("/api/bots/catalog")),d.catalog}async function ut(){return d.templates=await b("/api/bots/templates"),d.templates}async function H(){const t=et("Bot templates"),[e,o]=await Promise.all([Mt(),ut()]),i=n("div","bv-template-list");for(const l of o){const u=n("div","bv-template-row");u.appendChild(n("span","bv-template-name",l.manifest.name)),u.appendChild(n("span","bv-template-desc",l.manifest.description||""));const h=n("button","btn","Edit");h.onclick=()=>mt(t,e,l);const f=n("button","btn","Copy");f.title="Duplicate this template",f.onclick=()=>{const I=JSON.parse(JSON.stringify(l.manifest));I.name=`${l.manifest.name} copy`,b("/api/bots/templates",{method:"POST",body:JSON.stringify({manifest:I})}).then(()=>H()).catch(x=>alert(x instanceof Error?x.message:String(x)))};const O=n("button","btn danger","Delete");O.onclick=()=>{confirm(`Delete template ${l.manifest.name}?`)&&b(`/api/bots/templates/${l.id}`,{method:"DELETE"}).then(()=>H())};const M=n("span","bv-template-actions");M.append(h,f,O),u.appendChild(M),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=()=>mt(t,e,null);const a=n("button","btn","Export");a.title="Download templates + library as JSON",a.onclick=()=>{(async()=>{try{const l=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${U()}`}});if(!l.ok)throw new Error(`HTTP ${l.status}`);const u=await l.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(l){alert(l instanceof Error?l.message:String(l))}})()};const c=n("button","btn","Import");c.title="Restore templates from a JSON bundle",c.onclick=()=>{const l=document.createElement("input");l.type="file",l.accept="application/json,.json",l.onchange=()=>{const u=l.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 H()}catch(h){alert(h instanceof Error?h.message:String(h))}})()},l.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"),l=document.createElement("input");l.type="checkbox",l.checked=o.includes(a.id),c.append(l,n("span",void 0,a.label)),a.hint&&(c.title=a.hint),s.appendChild(c),r.push({id:a.id,input:l})}return i.appendChild(s),{element:i,get:()=>r.filter(a=>a.input.checked).map(a=>a.id)}}function mt(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||[]),l=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 O=n("div","bv-check-grid"),M=[];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)),O.appendChild(S),M.push({name:p.name,input:m})}f.appendChild(O);const I=n("input","bv-input");I.value=(i.tools?.deny||[]).join(", "),I.placeholder="Always deny (comma separated), e.g. bash, write";const x=n("textarea","bv-textarea");x.rows=2,x.value=(i.packages||[]).join(`
|
|
2
|
+
`),x.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";const E=n("select","bv-input");E.appendChild(new Option("default (Pi settings)",""));for(const p of e.models)E.appendChild(new Option(`${p.provider}/${p.model}`,`${p.provider}
|
|
3
|
+
${p.model}`));i.model?.provider&&i.model?.id&&(E.value=`${i.model.provider}
|
|
4
|
+
${i.model.id}`);const g=n("select","bv-input");for(const p of["","off","minimal","low","medium","high","xhigh","max"])g.appendChild(new Option(p||"default",p));i.model?.thinking&&(g.value=i.model.thinking);const y=n("select","bv-input");for(const p of["supervised","auto-accept-edits","full-access"])y.appendChild(new Option(p,p));y.value=i.permissions?.runtimeMode||"supervised";const j=n("select","bv-input");j.appendChild(new Option("ignore project .pi (recommended)","ignore")),j.appendChild(new Option("inherit project .pi (needs trust)","inherit")),j.value=i.projectResources||"ignore";const J=n("label","bv-check"),T=document.createElement("input");T.type="checkbox",T.checked=!!i.orchestrator,J.append(T,n("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));const w=(p,S)=>{const m=n("div","bv-field");return m.appendChild(n("label","bv-label",p)),m.appendChild(S),m};t.append(w("Name",s),w("Description",r),w("System prompt",a),c.element,l.element,u.element,w("MCP preset",h),f,w("Always deny tools",I),w("Packages",x),w("Model",E),w("Thinking level",g),w("Approval mode",y),w("Project resources",j),J);const k=n("button","btn primary",o?"Save template":"Create template");k.onclick=async()=>{const[p,S]=E.value.split(`
|
|
5
|
+
`),m=e.mcp.find(v=>v.id===h.value),$={name:s.value.trim()||"bot",description:r.value.trim()||void 0,system:a.value.trim()||void 0,skills:c.get(),extensions:l.get().map(v=>(v.startsWith("builtin:"),v)),prompts:u.get(),packages:x.value.split(`
|
|
6
|
+
`).map(v=>v.trim()).filter(Boolean),mcp:m?{mcpServers:m.servers}:void 0,tools:{allow:M.filter(v=>v.input.checked).map(v=>v.name),deny:I.value.split(",").map(v=>v.trim()).filter(Boolean)},model:p?{provider:p,id:S,thinking:g.value||void 0}:void 0,permissions:{runtimeMode:y.value},projectResources:j.value==="inherit"?"inherit":"ignore",orchestrator:T.checked||void 0};try{await b("/api/bots/templates",{method:"POST",body:JSON.stringify({id:o?.id,manifest:$})}),V(),await H()}catch(v){alert(v instanceof Error?v.message:String(v))}},t.appendChild(k)}async function Tt(){return Lt("")}async function Lt(t){const e=et("New bot"),o=await ut();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 u of o)i.appendChild(new Option(u.manifest.name,u.id));const s=n("input","bv-input");s.placeholder="Title (defaults to template name)";const r=n("input","bv-input");r.placeholder="/path/to/project";const a=t||d.bots[0]?.projectPath||"";r.value=a;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(W("Template",i),W("Title",s),W("Project path",r),W("Workspace",c));const l=n("button","btn primary","Create bot");l.onclick=async()=>{try{const u=await b("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:r.value.trim()||void 0,isolation:c.value})});V(),await C(!0),await lt(u.id)}catch(u){alert(u instanceof Error?u.message:String(u))}},e.appendChild(l)}function W(t,e){const o=n("div","bv-field");return o.appendChild(n("label","bv-label",t)),o.appendChild(e),o}async function ot(){const t=et("Needs you");if(d.approvals=await b("/api/bots/approvals"),d.approvals.length===0){t.appendChild(n("div","bots-empty","Nothing waiting."));return}for(const e of d.approvals){const o=n("div","bv-approval");o.appendChild(n("div","bv-approval-title",`${e.botTitle}: ${e.title}`)),e.message&&o.appendChild(n("pre","bv-pre",e.message));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 danger","Deny"),c=async l=>{await b(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:l,reason:i.value||void 0})}),await C(!0),await ot()};r.onclick=()=>void c(!0),a.onclick=()=>void c(!1),s.append(i,r,a),o.appendChild(s),t.appendChild(o)}}function At(){window.__botsInited||(window.__botsInited=!0,yt(),gt(),window.__openBot=lt,document.addEventListener("click",t=>{const e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&d.activeId&&setTimeout(()=>K(),0))},!0),C(!0),d.pollTimer=window.setInterval(()=>{document.hidden||C()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(d.pollTimer)))}export{At as initBots,Lt as openNewBotForPath};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{marked as R}from"marked";const H=new Set(["http:","https:","mailto:"]);function x(a){const s=(a??"").trim();if(!s||s.startsWith("//"))return null;if(!/^[a-z][a-z0-9+.-]*:/i.test(s))return s;try{return H.has(new URL(s).protocol)?s:null}catch{return null}}const y=a=>/^[a-z][a-z0-9+.-]*:/i.test(a)&&!a.startsWith("mailto:"),w=4e5,M=200;function z(a){const s=new Map;let E=0;function N(n,e){const t=n.length+M;if(!(t>w/4)){s.set(n,{fragment:e,chars:t}),E+=t;for(const r of s.keys()){if(E<=w)break;const c=s.get(r);c&&(s.delete(r),E-=c.chars)}}}function g(n,e){e.split(`
|
|
2
|
+
`).forEach((r,c)=>{c>0&&n.appendChild(a.createElement("br")),r&&n.appendChild(a.createTextNode(r))})}function o(n,e){switch(e.type){case"text":{if(e.tokens?.length){for(const t of e.tokens)o(n,t);return}g(n,e.text??e.raw??"");return}case"escape":n.appendChild(a.createTextNode(e.text??""));return;case"strong":case"em":case"del":{const t=a.createElement(e.type==="strong"?"strong":e.type==="em"?"em":"del");for(const r of e.tokens??[])o(t,r);n.appendChild(t);return}case"codespan":{const t=a.createElement("code");t.textContent=e.text??"",n.appendChild(t);return}case"br":n.appendChild(a.createElement("br"));return;case"link":{const t=e.tokens??[],r=x(e.href);if(!r){for(const l of t)o(n,l);return}const c=a.createElement("a");c.href=r,c.rel="noreferrer noopener",e.title&&(c.title=e.title),y(r)&&(c.target="_blank");for(const l of t)o(c,l);n.appendChild(c);return}case"image":{const t=x(e.href),r=e.text?.trim()||e.href||"image";if(!t){n.appendChild(a.createTextNode(r));return}const c=a.createElement("a");c.href=t,c.textContent=r,c.rel="noreferrer noopener",y(t)&&(c.target="_blank"),n.appendChild(c);return}case"html":n.appendChild(a.createTextNode(e.raw??e.text??""));return;default:if(e.tokens?.length){for(const t of e.tokens)o(n,t);return}g(n,e.text??e.raw??"")}}function v(n){const e=a.createElement("div");e.className="bv-code";const t=a.createElement("div");t.className="bv-code-head";const r=(n.lang??"").trim().split(/\s+/)[0]??"",c=a.createElement("span");c.className="bv-code-lang",c.textContent=r||"text";const l=a.createElement("button");l.type="button",l.className="bv-code-copy",l.textContent="Copy";const f=n.text??"";l.addEventListener("click",()=>{const i=navigator.clipboard?.writeText(f);i&&i.then(()=>{l.textContent="Copied",window.setTimeout(()=>{l.textContent="Copy"},1200)},()=>{})}),t.append(c,l);const p=a.createElement("pre"),d=a.createElement("code");return r&&(d.className=`language-${r}`),d.textContent=f,p.appendChild(d),e.append(t,p),e}function T(n,e){const t=a.createElement("div");t.className="bv-table";const r=a.createElement("table"),c=a.createElement("thead"),l=a.createElement("tr"),f=e.align??[],p=(i,h,C)=>{const u=a.createElement(i);f[C]&&(u.style.textAlign=f[C]);for(const A of h.tokens??[])o(u,A);return u};(e.header??[]).forEach((i,h)=>l.appendChild(p("th",i,h))),c.appendChild(l);const d=a.createElement("tbody");for(const i of e.rows??[]){const h=a.createElement("tr");i.forEach((C,u)=>h.appendChild(p("td",C,u))),d.appendChild(h)}r.append(c,d),t.appendChild(r),n.appendChild(t)}function b(n,e){const t=a.createElement("li");if(e.task){const r=a.createElement("input");r.type="checkbox",r.disabled=!0,r.checked=e.checked===!0,t.appendChild(r)}for(const r of e.tokens??[])if(r.type==="text")o(t,r);else if(r.type==="paragraph")for(const c of r.tokens??[])o(t,c);else m(t,r);n.appendChild(t)}function m(n,e){switch(e.type){case"space":return;case"heading":{const t=Math.min(Math.max(e.depth??1,1),6),r=a.createElement(`h${t}`);for(const c of e.tokens??[])o(r,c);n.appendChild(r);return}case"paragraph":{const t=a.createElement("p");for(const r of e.tokens??[])o(t,r);n.appendChild(t);return}case"text":o(n,e);return;case"code":n.appendChild(v(e));return;case"blockquote":{const t=a.createElement("blockquote");for(const r of e.tokens??[])m(t,r);n.appendChild(t);return}case"list":{const t=e.items??e.tokens??[];if(e.ordered){const r=a.createElement("ol");typeof e.start=="number"&&e.start!==1&&(r.start=e.start);for(const c of t)b(r,c);n.appendChild(r)}else{const r=a.createElement("ul");for(const c of t)b(r,c);n.appendChild(r)}return}case"table":T(n,e);return;case"hr":n.appendChild(a.createElement("hr"));return;case"html":case"escape":n.appendChild(a.createTextNode(e.raw??e.text??""));return;default:if(e.tokens?.length){for(const t of e.tokens)m(n,t);return}e.text&&n.appendChild(a.createTextNode(e.text))}}function _(n){const e=a.createDocumentFragment();try{const t=R.lexer(n);for(const r of t)m(e,r)}catch{e.replaceChildren(a.createTextNode(n))}return e}return n=>{const e=s.get(n);if(e)return s.delete(n),s.set(n,e),e.fragment.cloneNode(!0);const t=_(n);return N(n,t),t.cloneNode(!0)}}export{z as createMarkdownRenderer,x as safeHref};
|
package/dist/lib/bots/manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{execFileSync as v}from"node:child_process";import{mkdirSync as m,readFileSync as w,rmSync as x,writeFileSync as I}from"node:fs";import p from"node:path";import k from"node:os";import{getBotStore as A}from"./store.js";import{materialize as B}from"./materialize.js";import{PiRpc as M}from"./rpc.js";import{buildCatalog as O,ORCHESTRATION_TOOLS as j,READONLY_TOOLS as D}from"./catalog.js";import{TERMINAL_STATUSES as d}from"./types.js";const f=4,
|
|
2
|
-
`);this.input(h.id,T,"steer").catch(()=>{this.emit(t,{type:"notice",level:"warn",text:"Could not reach the supervising bot; waiting for the user.",at:n})})}}this.setStatus(t,"waiting_approval"),this.emit(t,{type:"approval",approval:
|
|
1
|
+
import{execFileSync as v}from"node:child_process";import{mkdirSync as m,readFileSync as w,rmSync as x,writeFileSync as I}from"node:fs";import p from"node:path";import k from"node:os";import{getBotStore as A}from"./store.js";import{materialize as B}from"./materialize.js";import{PiRpc as M}from"./rpc.js";import{buildCatalog as O,ORCHESTRATION_TOOLS as j,READONLY_TOOLS as D}from"./catalog.js";import{TERMINAL_STATUSES as d}from"./types.js";const f=4,_=8,P=["starting","running","waiting_input","waiting_approval"];class b{store=A();token;apiBase;runtimes=new Map;sockets=new Map;listeners=new Set;approvals=new Map;recent=new Map;streaming=new Set;constructor(t){this.token=this.store.token,this.apiBase=`http://127.0.0.1:${t}/api/bots`;for(const e of this.store.listInstances()){let s=!1;!d.includes(e.status)&&e.status!=="queued"&&(e.status="stale",s=!0);const n=g(e.runtimeMode);n!==e.runtimeMode&&(e.runtimeMode=n,s=!0),s&&this.store.saveInstance(e)}}listTemplates(){return this.store.listTemplates()}getTemplate(t){return this.store.getTemplate(t)}saveTemplate(t){return this.store.saveTemplate(t)}deleteTemplate(t){return this.store.deleteTemplate(t)}catalog(){return O()}listBots(t={}){return this.store.listInstances().filter(s=>!(t.project&&s.projectPath!==t.project||t.parentBotId&&s.parentBotId!==t.parentBotId||t.status&&s.status!==t.status))}getBot(t){return this.store.getInstance(t)}children(t){return this.store.listInstances().filter(e=>e.parentBotId===t)}createInstance(t){const e=this.getTemplate(t.templateId);if(!e)throw new Error(`unknown template: ${t.templateId}`);let s=null;if(t.parentBotId){if(s=this.getBot(t.parentBotId),!s)throw new Error("parent bot not found");if(s.depth+1>f)throw new Error(`nesting depth limit is ${f}`)}let n=t.projectPath||s?.projectPath||process.env.HOME||"/";n==="~"?n=k.homedir():n.startsWith("~/")&&(n=p.join(k.homedir(),n.slice(2)));const r=p.resolve(n),o=this.store.newId(),i=t.isolation||"shared";let u=r;if(i==="worktree"){const h=p.join(this.store.root,"worktrees",o);try{m(p.dirname(h),{recursive:!0,mode:448}),v("git",["-C",r,"worktree","add","-b",`tw-bot/${o.slice(0,8)}`,h],{timeout:2e4,stdio:"ignore"}),u=h}catch{u=r}}const a=new Date().toISOString(),c={id:o,templateId:e.id,title:t.title||e.manifest.name,projectPath:r,workspacePath:u,isolation:i,parentBotId:s?.id,depth:s?s.depth+1:0,runtimeMode:g(t.runtimeMode||e.manifest.permissions?.runtimeMode),projectResources:e.manifest.projectResources||"ignore",status:"queued",sessionFile:p.join(this.store.sessionsDir(o),`${o}.jsonl`),createdAt:a,updatedAt:a,model:e.manifest.model};return m(this.store.sessionsDir(o),{recursive:!0,mode:448}),this.store.saveInstance(c),this.emit(c.id,{type:"status",status:"queued",at:a}),this.pump(),c}activeInProject(t){return this.store.listInstances().filter(e=>e.projectPath===t&&!d.includes(e.status)&&e.status!=="queued").length}pump(){for(const t of this.store.listInstances())t.status==="queued"&&(this.activeInProject(t.projectPath)>=_||this.start(t))}start(t){const e=this.getTemplate(t.templateId);if(!e){this.setStatus(t.id,"failed","template disappeared");return}const s=B(e,t,{apiBase:this.apiBase,token:this.token}),n=e.manifest.binaryPath||"pi",r=new M({command:n,args:s.args,cwd:t.workspacePath,env:s.env,onEvent:o=>this.handleEvent(t.id,o),onStderr:o=>{/error|failed/i.test(o)&&this.emit(t.id,{type:"notice",level:"warn",text:o.slice(0,500),at:new Date().toISOString()})},onExit:()=>{this.runtimes.delete(t.id),this.streaming.delete(t.id);const o=this.store.getInstance(t.id);o&&!d.includes(o.status)&&this.setStatus(t.id,"failed","pi exited unexpectedly"),this.pump()}});this.runtimes.set(t.id,r),t.status="starting",t.pid=void 0,this.store.saveInstance(t),this.emit(t.id,{type:"status",status:"starting",at:new Date().toISOString()}),r.start()}handleEvent(t,e){const s=String(e.type||""),n=new Date().toISOString();switch(s){case"agent_start":this.streaming.add(t),this.setStatus(t,"running");break;case"agent_end":break;case"agent_settled":this.streaming.delete(t),this.setStatus(t,e.aborted===!0?"cancelled":"completed");break;case"message_start":case"message_end":{const r=e.message;if(r){if(s==="message_end"&&r.role==="assistant"){const o=this.store.getInstance(t),i=N(r);o&&i&&(o.lastText=i,this.store.saveInstance(o))}this.emit(t,{type:"message",message:r,at:n})}break}case"message_update":{const r=e.assistantMessageEvent;if(!r)break;const o=r.type==="text_delta"?"text":r.type==="thinking_delta"?"thinking":r.type==="toolcall_delta"?"tool-args":null;if(!o)break;const i=e.message;this.emit(t,{type:"delta",kind:o,delta:String(r.delta||""),contentIndex:typeof r.contentIndex=="number"?r.contentIndex:void 0,messageId:typeof i?.id=="string"?i.id:void 0,at:n});break}case"tool_execution_start":this.emit(t,{type:"tool",phase:"start",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),args:e.args,at:n});break;case"tool_execution_update":this.emit(t,{type:"tool",phase:"update",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),output:E(e.partialResult),at:n});break;case"tool_execution_end":this.emit(t,{type:"tool",phase:"end",callId:String(e.toolCallId||""),name:String(e.toolName||"tool"),output:E(e.result),isError:e.isError===!0,durationMs:typeof e.durationMs=="number"?e.durationMs:void 0,at:n});break;case"extension_ui_request":this.handleUiRequest(t,e);break;default:break}}handleUiRequest(t,e){const s=String(e.method||""),n=new Date().toISOString(),r=this.store.getInstance(t);if(s==="notify"){this.emit(t,{type:"notice",level:e.notifyType==="error"?"error":e.notifyType==="warning"?"warn":"info",text:String(e.message||""),at:n});return}if(!["confirm","select","input","editor"].includes(s))return;const o=String(e.id||""),i=o?this.approvals.get(t)?.get(o):void 0;if(i&&i.state==="pending")return;const u=String(e.title||"Approval required"),a=/^Allow (.+?)\?$/.exec(u),c={id:String(e.id||""),botId:t,botTitle:r?.title||t,kind:s==="confirm"?"tool":"question",method:s,title:u,toolName:a?a[1]:void 0,message:typeof e.message=="string"?e.message:void 0,options:Array.isArray(e.options)?e.options.map(String):void 0,state:"pending",createdAt:n};if(this.approvals.has(t)||this.approvals.set(t,new Map),this.approvals.get(t).set(c.id,c),r&&r.runtimeMode==="parent-supervised"&&r.parentBotId){const h=this.store.getInstance(r.parentBotId);if(h){c.escalatedTo=h.id;const S=c.message?c.message.slice(0,500):"",T=[`Child bot "${r.title}" (${r.id}) needs approval: ${c.title}`,S?`Arguments: ${S}`:"",`Decide with bot_approve({ botId: "${r.id}", requestId: "${c.id}", allow: true|false, reason: "..." }).`,"If you do nothing the user will answer it."].filter(Boolean).join(`
|
|
2
|
+
`);this.input(h.id,T,"steer").catch(()=>{this.emit(t,{type:"notice",level:"warn",text:"Could not reach the supervising bot; waiting for the user.",at:n})})}}this.setStatus(t,"waiting_approval"),this.emit(t,{type:"approval",approval:c,at:n})}allowTool(t,e){if(!this.store.getInstance(t))throw new Error("bot not found");const n=p.join(this.store.agentDir(t),".allowed-tools");let r=[];try{r=JSON.parse(w(n,"utf8")),Array.isArray(r)||(r=[])}catch{r=[]}return r.includes(e)||r.push(e),m(p.dirname(n),{recursive:!0,mode:448}),I(n,`${JSON.stringify(r)}
|
|
3
3
|
`,{mode:384}),r}allowedTools(t){try{const e=JSON.parse(w(p.join(this.store.agentDir(t),".allowed-tools"),"utf8"));return Array.isArray(e)?e.map(String):[]}catch{return[]}}setRuntimeMode(t,e){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");s.runtimeMode=g(e),this.store.saveInstance(s);const n=p.join(this.store.agentDir(t),".runtime-mode");m(p.dirname(n),{recursive:!0,mode:448}),I(n,`${s.runtimeMode}
|
|
4
|
-
`,{mode:384}),this.emit(t,{type:"notice",level:"info",text:`Approval mode: ${e}`,at:new Date().toISOString()})}respondApproval(t,e,s,n,r="human",o=!1){const i=this.approvals.get(t)?.get(e);if(!i)throw new Error("approval not found");const
|
|
4
|
+
`,{mode:384}),this.emit(t,{type:"notice",level:"info",text:`Approval mode: ${e}`,at:new Date().toISOString()})}respondApproval(t,e,s,n,r="human",o=!1){const i=this.approvals.get(t)?.get(e);if(!i)throw new Error("approval not found");const u=this.runtimes.get(t);if(!u)throw new Error("bot is not running");const a={type:"extension_ui_response",id:e};i.method==="confirm"?a.confirmed=s:i.method==="select"?a.value=s?i.options?.[0]:i.options?.[1]||i.options?.[0]:s?a.value=n||"":a.cancelled=!0,u.send(a),s&&o&&i.toolName&&this.allowTool(t,i.toolName),i.state=s?"allowed":"denied",i.decidedBy=r,i.reason=n,i.decidedAt=new Date().toISOString();try{this.store.appendEvent(t,{type:"approval",approval:i,at:i.decidedAt})}catch{}return this.broadcast(t,{type:"approval",approval:i,at:i.decidedAt}),this.setStatus(t,"running"),i}listApprovals(){const t=[];for(const[,e]of this.approvals)for(const s of e.values())s.state==="pending"&&t.push(s);return t.sort((e,s)=>e.createdAt.localeCompare(s.createdAt))}async input(t,e,s){const n=this.store.getInstance(t);if(!n)throw new Error("bot not found");if(!this.runtimes.has(t)){this.resume(t);const a=Date.now()+1e4;for(;!this.runtimes.has(t)&&Date.now()<a;)await new Promise(c=>setTimeout(c,150))}const r=this.runtimes.get(t);if(!r){const a=this.store.getInstance(t)?.status;throw new Error(a==="queued"?"bot is queued behind other bots in this project; send again once it starts":"bot is still starting; send again in a moment")}const o=new Date().toISOString();this.emit(t,{type:"user",text:e,at:o});const i={type:"prompt",message:e},u=this.streaming.has(t)||P.includes(n.status);s==="follow_up"?i.streamingBehavior="followUp":(s==="steer"||u)&&(i.streamingBehavior="steer");try{await r.request(i,3e4)}catch(a){const c=a instanceof Error?a.message:String(a);if(!i.streamingBehavior&&/stream/i.test(c)){await r.request({...i,streamingBehavior:"steer"},3e4);return}throw a}}stop(t,e=!0){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");if(e)for(const n of this.children(t))this.stop(n.id,!0);try{this.runtimes.get(t)?.kill()}catch{}this.runtimes.delete(t),this.streaming.delete(t),d.includes(s.status)||this.setStatus(t,"cancelled"),this.pump()}resume(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");this.runtimes.has(t)||(e.status="queued",this.store.saveInstance(e),this.emit(t,{type:"status",status:"queued",at:new Date().toISOString()}),this.pump())}deleteBot(t,e=!0){const s=this.store.getInstance(t);if(!s)throw new Error("bot not found");if(e)for(const n of this.children(t))this.deleteBot(n.id,!0);try{this.runtimes.get(t)?.kill()}catch{}if(this.runtimes.delete(t),this.streaming.delete(t),this.store.deleteInstance(t),this.approvals.delete(t),this.recent.delete(t),s.isolation==="worktree"){try{v("git",["-C",s.projectPath,"worktree","remove","--force",s.workspacePath],{timeout:2e4,stdio:"ignore"})}catch{}x(s.workspacePath,{recursive:!0,force:!0})}this.pump()}status(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");const s=[...this.approvals.get(t)?.values()||[]].filter(n=>n.state==="pending");return{...e,pendingApprovals:s.length,lastText:e.lastText?.slice(0,4e3)}}result(t){const e=this.store.getInstance(t);if(!e)throw new Error("bot not found");return{botId:t,status:e.status,text:e.lastText||"",title:e.title}}async waitFor(t,e=45e3){const s=Date.now()+Math.min(e,45e3),n=new Set(t);for(;Date.now()<s;){const r=[...n].filter(o=>{const i=this.store.getInstance(o);return!i||d.includes(i.status)});if(r.length)return{bots:r.map(o=>this.result(o))};await new Promise(o=>setTimeout(o,250))}return{timeout:!0,bots:t.map(r=>{const o=this.store.getInstance(r);return{botId:r,status:o?.status||"missing",title:o?.title}})}}attachSocket(t,e){this.sockets.has(t)||this.sockets.set(t,new Set),this.sockets.get(t).add(e);const s=this.store.getInstance(t);e.send(JSON.stringify({type:"snapshot",bot:s,approvals:this.listApprovals().filter(n=>n.botId===t)}));for(const n of this.store.readEvents(t,400))e.send(JSON.stringify(n));e.on("close",()=>this.sockets.get(t)?.delete(e))}broadcast(t,e){const s=JSON.stringify(e);for(const n of this.sockets.get(t)||[])if(n.readyState===1)try{n.send(s)}catch{}}emit(t,e){this.store.appendEvent(t,e);const s=this.recent.get(t)||[];s.push(e),s.length>800&&s.splice(0,s.length-800),this.recent.set(t,s),this.broadcast(t,e);for(const n of this.listeners)try{n(e)}catch{}}onEvent(t){return this.listeners.add(t),()=>this.listeners.delete(t)}setStatus(t,e,s){const n=this.store.getInstance(t);n&&(n.status=e,s&&(n.lastError=s),this.store.saveInstance(n),this.emit(t,{type:"status",status:e,at:new Date().toISOString(),error:s}),d.includes(e)&&this.pump())}}function g(l){return l==="full-access"?"full-access":l==="parent-supervised"?"parent-supervised":"supervised"}function N(l){const t=l.content;return Array.isArray(t)?t.map(e=>e&&typeof e=="object"&&e.type==="text"?String(e.text||""):"").join("").trim():""}function E(l){if(l==null)return"";if(typeof l=="string")return l;try{return JSON.stringify(l).slice(0,4e3)}catch{return String(l)}}let y=null;function z(){if(!y){const l=Number(process.env.PORT)||21e3;y=new b(l)}return y}export{b as BotManager,_ as MAX_CONCURRENT_PER_PROJECT,f as MAX_DEPTH,j as ORCHESTRATION_TOOLS,D as READONLY_TOOLS,z as getBotManager};
|
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 a(e="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${e}; outline: none;`}function w(e){const{theme:t,fsRoots:r,terminalCfg:i,scrollback:
|
|
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 a(e="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${e}; outline: none;`}function w(e){const{theme:t,fsRoots:r,terminalCfg:i,scrollback:p,wsBase:s}=e,n=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);
|
|
@@ -21,7 +21,16 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
21
21
|
.fixed-header .brand {
|
|
22
22
|
font-size: var(--text-base); font-weight: 600; color: var(--page-fg);
|
|
23
23
|
flex-shrink: 0;
|
|
24
|
+
/* The logo is the session-list toggle on a phone, so it needs a real touch
|
|
25
|
+
target (44px) rather than the height of the text itself. */
|
|
26
|
+
display: inline-flex; align-items: center;
|
|
27
|
+
min-height: 44px; padding: 0 6px; margin-left: -6px;
|
|
28
|
+
border-radius: 8px; cursor: pointer;
|
|
29
|
+
touch-action: manipulation; -webkit-tap-highlight-color: transparent;
|
|
30
|
+
user-select: none;
|
|
24
31
|
}
|
|
32
|
+
.fixed-header .brand:active { background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
|
|
33
|
+
.fixed-header .brand:focus-visible { ${a()} }
|
|
25
34
|
.fixed-header .brand span { color: var(--panel-accent); font-weight: 500; }
|
|
26
35
|
.fixed-header .brand a { color: inherit; text-decoration: none; }
|
|
27
36
|
#header-git {
|
|
@@ -96,6 +105,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
96
105
|
display: flex; align-items: center; gap: 8px;
|
|
97
106
|
padding: 10px 12px; border-radius: 10px;
|
|
98
107
|
cursor: pointer; font-size: var(--text-sm); color: var(--page-fg);
|
|
108
|
+
touch-action: manipulation;
|
|
99
109
|
text-decoration: none; margin-bottom: 2px;
|
|
100
110
|
transition: background 0.1s;
|
|
101
111
|
}
|
|
@@ -497,6 +507,9 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
497
507
|
display: inline-flex; align-items: center; justify-content: center;
|
|
498
508
|
min-height: 36px; padding: 6px 14px; border-radius: 8px;
|
|
499
509
|
font-size: var(--text-sm); font-family: inherit; cursor: pointer;
|
|
510
|
+
/* No double-tap zoom on iOS: a second tap should press the button again,
|
|
511
|
+
not zoom the page. */
|
|
512
|
+
touch-action: manipulation;
|
|
500
513
|
border: 1px solid var(--panel-border); background: var(--panel-bg);
|
|
501
514
|
color: var(--page-fg); transition: opacity 0.15s; text-decoration: none;
|
|
502
515
|
}
|
|
@@ -744,15 +757,85 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
744
757
|
.bv-actions { display: flex; gap: 6px; flex-shrink: 0; }
|
|
745
758
|
.bv-actions .btn { padding: 4px 10px; font-size: 11px; }
|
|
746
759
|
|
|
747
|
-
.bots-messages {
|
|
760
|
+
.bots-messages {
|
|
761
|
+
flex: 1; overflow-y: auto; padding: 14px 16px;
|
|
762
|
+
display: flex; flex-direction: column; gap: 10px;
|
|
763
|
+
/* The transcript is its own scroll surface: momentum scrolling, and the
|
|
764
|
+
gesture never chains to the page (which would move the pinned view). */
|
|
765
|
+
-webkit-overflow-scrolling: touch;
|
|
766
|
+
overscroll-behavior: contain;
|
|
767
|
+
}
|
|
768
|
+
/* Shown only while the reader is away from the tail during streaming. */
|
|
769
|
+
.bv-jump {
|
|
770
|
+
position: absolute; right: 14px; bottom: calc(70px + env(safe-area-inset-bottom, 0px));
|
|
771
|
+
z-index: 7; min-width: 44px; height: 44px; padding: 0 12px;
|
|
772
|
+
border-radius: 22px; border: 1px solid var(--panel-border);
|
|
773
|
+
background: color-mix(in srgb, var(--panel-bg) 92%, transparent);
|
|
774
|
+
color: var(--page-fg); font-size: 12px; font-family: var(--font-mono);
|
|
775
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 4px;
|
|
776
|
+
cursor: pointer; touch-action: manipulation;
|
|
777
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
|
|
778
|
+
}
|
|
779
|
+
.bv-jump[hidden] { display: none; }
|
|
780
|
+
.bv-jump:hover { border-color: var(--panel-accent); color: var(--panel-accent); }
|
|
748
781
|
.bv-msg { max-width: min(860px, 100%); font-size: 13px; line-height: 1.55; }
|
|
749
|
-
.bv-user { align-self: flex-end; background: color-mix(in srgb, var(--panel-accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--panel-accent) 30%, transparent); padding: 8px 12px; border-radius: 10px;
|
|
782
|
+
.bv-user { align-self: flex-end; background: color-mix(in srgb, var(--panel-accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--panel-accent) 30%, transparent); padding: 8px 12px; border-radius: 10px; }
|
|
750
783
|
.bv-assistant { align-self: flex-start; }
|
|
751
|
-
.bv-text {
|
|
784
|
+
.bv-text { word-break: break-word; overflow-wrap: anywhere; }
|
|
752
785
|
.bv-thinking { margin-bottom: 6px; color: var(--panel-muted); font-size: 12px; }
|
|
753
786
|
.bv-thinking summary { cursor: pointer; opacity: 0.8; }
|
|
754
787
|
.bv-thinking div { white-space: pre-wrap; border-left: 2px solid var(--panel-border); padding-left: 8px; margin-top: 4px; }
|
|
755
788
|
|
|
789
|
+
/* \u2500\u2500 Rendered markdown in a message \u2500\u2500 */
|
|
790
|
+
.bv-text > :first-child, .bv-user > :first-child { margin-top: 0; }
|
|
791
|
+
.bv-text > :last-child, .bv-user > :last-child { margin-bottom: 0; }
|
|
792
|
+
.bv-text p, .bv-user p { margin: 0 0 8px; }
|
|
793
|
+
.bv-text h1, .bv-text h2, .bv-text h3, .bv-text h4, .bv-text h5, .bv-text h6 {
|
|
794
|
+
margin: 14px 0 6px; line-height: 1.3; font-weight: 600;
|
|
795
|
+
}
|
|
796
|
+
.bv-text h1 { font-size: 17px; }
|
|
797
|
+
.bv-text h2 { font-size: 15.5px; }
|
|
798
|
+
.bv-text h3 { font-size: 14px; }
|
|
799
|
+
.bv-text h4, .bv-text h5, .bv-text h6 { font-size: 13px; color: var(--panel-muted); }
|
|
800
|
+
.bv-text ul, .bv-text ol { margin: 0 0 8px; padding-left: 20px; }
|
|
801
|
+
.bv-text li { margin: 2px 0; }
|
|
802
|
+
.bv-text li > ul, .bv-text li > ol { margin: 2px 0; }
|
|
803
|
+
.bv-text li > input[type="checkbox"] { margin: 0 5px 0 -16px; vertical-align: middle; }
|
|
804
|
+
.bv-text a, .bv-user a { color: var(--panel-accent); text-decoration: underline; text-underline-offset: 2px; }
|
|
805
|
+
.bv-text code, .bv-user code {
|
|
806
|
+
font-family: var(--font-mono); font-size: 11.5px;
|
|
807
|
+
background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 55%);
|
|
808
|
+
border: 1px solid var(--panel-border); border-radius: 4px; padding: 0 4px;
|
|
809
|
+
}
|
|
810
|
+
.bv-text blockquote {
|
|
811
|
+
margin: 0 0 8px; padding: 1px 10px;
|
|
812
|
+
border-left: 2px solid var(--panel-border); color: var(--panel-muted);
|
|
813
|
+
}
|
|
814
|
+
.bv-text hr { border: none; border-top: 1px solid var(--panel-border); margin: 12px 0; }
|
|
815
|
+
.bv-table { max-width: 100%; overflow-x: auto; margin: 0 0 8px; }
|
|
816
|
+
.bv-text table { border-collapse: collapse; font-size: 12px; }
|
|
817
|
+
.bv-text th, .bv-text td { border: 1px solid var(--panel-border); padding: 4px 8px; vertical-align: top; }
|
|
818
|
+
.bv-text th { background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 55%); font-weight: 600; }
|
|
819
|
+
.bv-code {
|
|
820
|
+
margin: 0 0 8px; border: 1px solid var(--panel-border); border-radius: 8px;
|
|
821
|
+
background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 45%); overflow: hidden;
|
|
822
|
+
}
|
|
823
|
+
.bv-code-head {
|
|
824
|
+
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
|
825
|
+
padding: 3px 8px; border-bottom: 1px solid var(--panel-border);
|
|
826
|
+
font-family: var(--font-mono); font-size: 10px; color: var(--panel-muted);
|
|
827
|
+
}
|
|
828
|
+
.bv-code-copy {
|
|
829
|
+
background: none; border: none; color: var(--panel-muted); cursor: pointer;
|
|
830
|
+
font-family: inherit; font-size: 10px; padding: 2px 4px; border-radius: 4px;
|
|
831
|
+
}
|
|
832
|
+
.bv-code-copy:hover { color: var(--panel-accent); background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
|
|
833
|
+
.bv-code pre { margin: 0; padding: 8px 10px; overflow-x: auto; }
|
|
834
|
+
.bv-code code {
|
|
835
|
+
font-family: var(--font-mono); font-size: 11.5px; line-height: 1.5;
|
|
836
|
+
background: none; border: none; padding: 0; white-space: pre;
|
|
837
|
+
}
|
|
838
|
+
|
|
756
839
|
.bv-tool { border: 1px solid var(--panel-border); border-radius: 8px; background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 45%); font-family: var(--font-mono); font-size: 11.5px; }
|
|
757
840
|
.bv-tool > summary { padding: 6px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
|
|
758
841
|
.bv-tool-name { color: var(--panel-accent); }
|
|
@@ -773,16 +856,28 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
773
856
|
.bv-notice-error { color: var(--panel-danger, #e5534b); }
|
|
774
857
|
|
|
775
858
|
/* Same look and metrics as the terminal's mobile input row (.mk-input). */
|
|
776
|
-
.bots-composer {
|
|
859
|
+
.bots-composer-wrap { flex-shrink: 0; border-top: 1px solid var(--panel-border); background: var(--panel-bg); }
|
|
860
|
+
.bv-composer-error {
|
|
861
|
+
padding: 6px 10px; font-size: 11.5px; line-height: 1.45; word-break: break-word;
|
|
862
|
+
color: var(--panel-danger, #e5534b);
|
|
863
|
+
}
|
|
864
|
+
.bv-composer-error[hidden] { display: none; }
|
|
865
|
+
.bots-composer { display: flex; gap: 4px; padding: 6px 8px; align-items: stretch; }
|
|
866
|
+
.bots-composer .btn.primary[aria-busy="true"] { opacity: 0.55; cursor: default; }
|
|
867
|
+
.bots-composer .btn.primary:disabled { filter: none; }
|
|
777
868
|
.bots-composer textarea {
|
|
778
869
|
flex: 1; resize: none; box-sizing: border-box;
|
|
779
870
|
min-height: 38px; max-height: 80px;
|
|
871
|
+
/* Focus on the first tap: no double-tap zoom and no 300ms click delay. */
|
|
872
|
+
touch-action: manipulation;
|
|
780
873
|
background: color-mix(in srgb, var(--page-bg), var(--panel-bg) 50%);
|
|
781
874
|
color: var(--page-fg); border: 1px solid var(--panel-border);
|
|
782
875
|
border-radius: 8px; padding: 6px 10px;
|
|
783
876
|
font-family: var(--font-mono); font-size: var(--text-base); line-height: 1.4; outline: none;
|
|
784
877
|
}
|
|
785
878
|
.bots-composer textarea:focus { border-color: var(--panel-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--panel-accent) 15%, transparent); }
|
|
879
|
+
/* Same muted placeholder as the terminal's mobile input row. */
|
|
880
|
+
.bots-composer textarea::placeholder { color: var(--panel-muted); opacity: 0.6; }
|
|
786
881
|
.bots-composer .btn.primary {
|
|
787
882
|
min-width: 44px; padding: 0 12px; border: none; color: white;
|
|
788
883
|
background: var(--panel-success); border-radius: 8px; cursor: pointer;
|
|
@@ -834,10 +929,14 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
834
929
|
.bv-mode-menu { position: fixed; left: 10px; right: 10px; top: auto; bottom: 10px; width: auto; max-height: 60vh; overflow-y: auto; }
|
|
835
930
|
.bots-messages { padding: 10px; }
|
|
836
931
|
.bv-msg { max-width: 100%; }
|
|
837
|
-
|
|
932
|
+
/* Keep the field clear of the home-indicator gesture bar. */
|
|
933
|
+
.bots-composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px; gap: 6px; }
|
|
838
934
|
.bv-approval-actions { flex-wrap: wrap; }
|
|
839
935
|
.bv-reason { flex: 1 1 100%; }
|
|
840
936
|
.sidebar { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--panel-border); transition: max-height 0.2s; }
|
|
937
|
+
/* An expanded list must leave room for the terminal/chat below it; without a
|
|
938
|
+
cap a long session list pushed the main area off-screen. */
|
|
939
|
+
.sidebar:not(.collapsed) { max-height: 62dvh; }
|
|
841
940
|
.sidebar.collapsed .sidebar-content { display: none; }
|
|
842
941
|
.sidebar.collapsed .sidebar-footer { display: none; }
|
|
843
942
|
.sidebar.collapsed { max-height: 48px; overflow: hidden; }
|
|
@@ -857,6 +956,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
857
956
|
breakpoint, applied unconditionally when the html has .force-narrow. */
|
|
858
957
|
html.force-narrow .app-layout { flex-direction: column; }
|
|
859
958
|
html.force-narrow .sidebar { flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--panel-border); transition: max-height 0.2s; }
|
|
959
|
+
html.force-narrow .sidebar:not(.collapsed) { max-height: 62dvh; }
|
|
860
960
|
html.force-narrow .sidebar.collapsed .sidebar-content { display: none; }
|
|
861
961
|
html.force-narrow .sidebar.collapsed .sidebar-footer { display: none; }
|
|
862
962
|
html.force-narrow .sidebar.collapsed { max-height: 48px; overflow: hidden; }
|
|
@@ -866,7 +966,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
866
966
|
display: flex; flex-wrap: nowrap; gap: 4px;
|
|
867
967
|
overflow-x: auto; overscroll-behavior-x: contain;
|
|
868
968
|
}
|
|
869
|
-
`,v=JSON.stringify(t.terminal).replace(/</g,"\\u003c"),d=JSON.stringify({terminal:i,scrollback:
|
|
969
|
+
`,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>
|
|
870
970
|
<html lang="en">
|
|
871
971
|
<head>
|
|
872
972
|
<meta charset="UTF-8" />
|
|
@@ -904,7 +1004,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
904
1004
|
</script>
|
|
905
1005
|
|
|
906
1006
|
<header class="fixed-header">
|
|
907
|
-
<div class="brand" id="brand-toggle">tmux<span>-weblink</span></div>
|
|
1007
|
+
<div class="brand" id="brand-toggle" role="button" tabindex="0" aria-label="Toggle session list" aria-expanded="true" title="Toggle session list">tmux<span>-weblink</span></div>
|
|
908
1008
|
<div class="header-actions">
|
|
909
1009
|
</div>
|
|
910
1010
|
<div id="header-git" title="Click to browse repository"></div>
|
|
@@ -1086,13 +1186,32 @@ ${g("__onSessionCreated")}
|
|
|
1086
1186
|
</script>
|
|
1087
1187
|
<script>
|
|
1088
1188
|
(function(){
|
|
1089
|
-
/* Logo
|
|
1189
|
+
/* Logo toggles the session list. It is the main way out of the bot chat on a
|
|
1190
|
+
phone, so it acts on pointerdown (a tap during heavy streaming output still
|
|
1191
|
+
lands) and a double tap in quick succession cannot undo itself. */
|
|
1090
1192
|
var brand = document.getElementById('brand-toggle');
|
|
1091
1193
|
var sbar = document.querySelector('.sidebar');
|
|
1092
1194
|
if (brand && sbar) {
|
|
1093
|
-
|
|
1094
|
-
sbar.classList.toggle('collapsed');
|
|
1195
|
+
var setExpanded = function(expanded) {
|
|
1196
|
+
sbar.classList.toggle('collapsed', !expanded);
|
|
1197
|
+
brand.setAttribute('aria-expanded', expanded ? 'true' : 'false');
|
|
1198
|
+
/* Unpin/repin the bot chat before the next paint, so the list is never
|
|
1199
|
+
drawn underneath the pinned chat view. */
|
|
1200
|
+
if (window.__syncBotsViewport) window.__syncBotsViewport();
|
|
1201
|
+
};
|
|
1202
|
+
var lastToggle = 0;
|
|
1203
|
+
var toggle = function(e) {
|
|
1204
|
+
if (e) e.preventDefault();
|
|
1205
|
+
var now = Date.now();
|
|
1206
|
+
if (now - lastToggle < 350) return;
|
|
1207
|
+
lastToggle = now;
|
|
1208
|
+
setExpanded(sbar.classList.contains('collapsed'));
|
|
1209
|
+
};
|
|
1210
|
+
brand.addEventListener('pointerdown', toggle);
|
|
1211
|
+
brand.addEventListener('keydown', function(e) {
|
|
1212
|
+
if (e.key === 'Enter' || e.key === ' ') toggle(e);
|
|
1095
1213
|
});
|
|
1214
|
+
brand.setAttribute('aria-expanded', sbar.classList.contains('collapsed') ? 'false' : 'true');
|
|
1096
1215
|
}
|
|
1097
1216
|
|
|
1098
1217
|
/* Mobile keys: collapsible strip, expanded by tapping the space under the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tmux-weblink",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Access your tmux sessions from the browser. A continuation of tmux-web and persalink.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
"@types/ws": "^8.5.0",
|
|
60
60
|
"@vitest/coverage-v8": "^2.1.9",
|
|
61
61
|
"esbuild": "^0.25.0",
|
|
62
|
+
"linkedom": "^0.18.15",
|
|
63
|
+
"marked": "^18.4.0",
|
|
62
64
|
"tsx": "^4.21.0",
|
|
63
65
|
"typescript": "^5.7.0",
|
|
64
66
|
"vitest": "^2.1.9"
|