tmux-weblink 2.2.48 → 2.2.50
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 +26 -26
- package/dist/browser/bots-client.js +6 -6
- package/dist/browser/shell-client.js +13 -13
- package/dist/lib/icons.js +1 -1
- package/dist/lib/pages/shell.js +59 -23
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const d={catalog:null,templates:[],bots:[],approvals:[],activeId:null,items:new Map,ws:null,pollTimer:0,renderQueued:!1};function D(){try{return localStorage.getItem("tmux-web-token")||""}catch{return""}}async function f(t,e){const o=await fetch(t,{...e,headers:{"content-type":"application/json",Authorization:`Bearer ${D()}`,...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 tt(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 j(){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 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(),A()}),e?.addEventListener("click",()=>{i(),ut()}),o?.addEventListener("click",()=>{i(),Q()})}function nt(){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 l=n("span","bv-status");l.id="bv-status",o.append(i,s,l);const a=n("div","bv-actions"),p=n("div","bv-mode"),r=n("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";const u=n("div","bv-mode-menu");u.id="bv-mode-menu",u.hidden=!0;for(const[b,h,M]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=n("button");c.dataset.mode=b,c.innerHTML=`<b>${h}</b><span>${M}</span>`,c.onclick=()=>{u.hidden=!0,ot(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=n("button","btn","Allow all");m.id="bv-allow-all",m.title="Approve every pending request for this bot",m.onclick=()=>{if(!d.activeId)return;const b=d.approvals.filter(h=>h.botId===d.activeId);Promise.all(b.map(h=>f(`/api/bots/${h.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:h.id,allow:!0})}))).finally(()=>void S(!0))};const v=n("button","btn","Needs you "),I=n("span");I.id="bv-inbox-count",v.appendChild(I),v.onclick=()=>void Q();const x=n("button","btn","Resume");x.onclick=()=>void z(b=>f(`/api/bots/${b}/resume`,{method:"POST"}).then(()=>S(!0)));const C=n("button","btn danger","Stop");C.onclick=()=>void z(b=>f(`/api/bots/${b}/stop`,{method:"POST"}).then(()=>S(!0)));const y=n("button","btn","Delete");y.onclick=()=>{d.activeId&&confirm("Delete this bot and its session?")&&f(`/api/bots/${d.activeId}`,{method:"DELETE"}).then(()=>{_(),S(!0)})};const E=n("button","btn","\u2715");E.onclick=()=>_(),a.append(p,m,v,x,C,y,E),e.append(o,a);const O=n("div","bots-messages");O.id="bots-messages";const $=n("div","bots-composer"),w=n("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 P=n("button","btn primary","Send");P.onclick=()=>void F(),$.append(w,P),t.append(e,O,$),document.querySelector(".main-area")?.appendChild(t),document.getElementById("bots-modal")||ct()}async function F(){const t=document.getElementById("bots-input");if(!t||!d.activeId||!t.value.trim())return;const e=t.value;t.value="";try{await f(`/api/bots/${d.activeId}/input`,{method:"POST",body:JSON.stringify({text:e})})}catch(o){B({kind:"notice",level:"error",text:o instanceof Error?o.message:String(o)})}}function z(t){d.activeId&&t(d.activeId).catch(e=>B({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)}))}function _(){d.activeId=null;const t=document.getElementById("bots-view");t&&(t.hidden=!0);try{d.ws?.close()}catch{}d.ws=null,j();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 G(t){d.activeId=t,d.items.set(t,[]);const e=document.getElementById("bots-view");e&&(e.hidden=!1);const o=document.getElementById("main-placeholder");o&&(o.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(),H();try{d.ws?.close()}catch{}const l=location.protocol==="https:"?"wss:":"ws:",a=new WebSocket(`${l}//${location.host}/ws/bots/${encodeURIComponent(t)}?token=${encodeURIComponent(D())}`);d.ws=a,a.onmessage=p=>{try{V(JSON.parse(String(p.data)))}catch{}},a.onclose=()=>{d.activeId===t&&setTimeout(()=>{d.activeId===t&&S(!0)},1500)},await S(!0)}function R(){return d.bots.find(t=>t.id===d.activeId)||null}function q(){const t=R();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&&t.runtimeMode&&(s.textContent=`${K[t.runtimeMode]||t.runtimeMode} \u25BE`);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"),a=d.approvals.filter(p=>p.botId===t.id).length;l&&(l.hidden=a===0,l.textContent=`Allow all (${a})`),i&&(i.style.background=tt(t.status))}const K={supervised:"\u9ED8\u8BA4","parent-supervised":"\u76D1\u7BA1","full-access":"\u5168\u653E\u884C"};async function ot(t){if(d.activeId)try{await f(`/api/bots/${d.activeId}/mode`,{method:"POST",body:JSON.stringify({mode:t})});const e=R();e&&(e.runtimeMode=t),q(),B({kind:"notice",level:"info",text:`\u5BA1\u6279\u6A21\u5F0F\uFF1A${K[t]||t}`})}catch(e){B({kind:"notice",level:"error",text:e instanceof Error?e.message:String(e)})}}function B(t,e=d.activeId){if(!e)return;const o=d.items.get(e)||[];o.push(t),d.items.set(e,o),e===d.activeId&&T()}function T(){d.renderQueued||(d.renderQueued=!0,requestAnimationFrame(()=>{d.renderQueued=!1,H()}))}function H(){const t=document.getElementById("bots-messages");if(!t||!d.activeId)return;const e=d.items.get(d.activeId)||[];t.textContent="";let o=null;for(const i of e)if(i.kind==="user"){const s=n("div","bv-msg bv-user");s.textContent=i.text,t.appendChild(s),o=null}else if(i.kind==="assistant"){const s=n("div","bv-msg bv-assistant");if(i.thinking){const a=n("details","bv-thinking");a.appendChild(n("summary",void 0,"thinking")),a.appendChild(n("div",void 0,i.thinking)),s.appendChild(a)}const l=n("div","bv-text");l.textContent=i.text,s.appendChild(l),t.appendChild(s),o=l}else if(i.kind==="tool")t.appendChild(it(i)),o=null;else if(i.kind==="approval")t.appendChild(st(i)),o=null;else if(i.kind==="notice"){const s=n("div",`bv-notice bv-notice-${i.level}`,i.text);t.appendChild(s)}o&&(o.scrollTop=o.scrollHeight),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 st(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"),l=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 p=n("button","btn danger","Deny"),r=async(u,m=!1)=>{try{await f(`/api/bots/${o.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:o.id,allow:u,always:m,reason:i.value||void 0})}),t.decided=u?"allowed":"denied",T(),S(!0)}catch(v){B({kind:"notice",level:"error",text:v instanceof Error?v.message:String(v)})}};return l.onclick=()=>void r(!0),a.onclick=()=>void r(!0,!0),p.onclick=()=>void r(!1),s.append(i,l,a,p),e.appendChild(s),e}function V(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({kind:"user",text:String(t.text||"")});else if(e==="status"){const s=R();s&&(s.status=String(t.status||s.status)),q(),lt()}else if(e==="message"){const s=t.message;if(!s||String(s.role||"")!=="assistant")return;const a=at(s),p=dt(s),r=i[i.length-1];r&&r.kind==="assistant"?(r.text=a||r.text,r.thinking=p||r.thinking):i.push({kind:"assistant",text:a,thinking:p}),d.items.set(o,i),T()}else if(e==="delta"){const s=String(t.kind||""),l=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+=l:s==="thinking"&&(a.thinking+=l)),d.items.set(o,i),T()}else if(e==="tool"){const s=String(t.callId||""),l=i.find(p=>p.kind==="tool"&&p.callId===s),a=String(t.phase||"start");l?(l.phase=a,a==="update"&&t.output&&(l.output=String(t.output)),a==="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:a}),d.items.set(o,i),T()}else if(e==="approval"){const s=t.approval;if(!s)return;const l=i;for(let a=l.length-1;a>=0;a--){const p=l[a];if(p.kind==="approval"&&p.approval.id===s.id){p.approval=s,s.state!=="pending"&&(p.decided=s.state==="allowed"?"allowed":"denied"),d.items.set(o,l),T();return}}l.push({kind:"approval",approval:s}),d.items.set(o,l),T()}else e==="notice"&&B({kind:"notice",level:String(t.level||"info"),text:String(t.text||"")})}function at(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 dt(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 S(t=!1){try{const[e,o]=await Promise.all([f("/api/bots"),f("/api/bots/approvals")]);if(d.bots=e,d.approvals=o,j(),q(),t&&d.activeId){const i=await f(`/api/bots/${d.activeId}/events?limit=300`);rt(i)}}catch{}}async function lt(){try{d.bots=await f("/api/bots"),j()}catch{}}function rt(t){if(d.activeId){d.items.set(d.activeId,[]);for(const e of t)V(e);H()}}function ct(){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","\u2715");s.onclick=()=>J(),o.append(i,s);const l=n("div","bots-modal-body");l.id="bots-modal-body",e.append(o,l),t.appendChild(e),t.onclick=a=>{a.target===t&&J()},document.body.appendChild(t)}function W(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 J(){const t=document.getElementById("bots-modal");t&&(t.hidden=!0)}async function pt(){return d.catalog||(d.catalog=await f("/api/bots/catalog")),d.catalog}async function Y(){return d.templates=await f("/api/bots/templates"),d.templates}async function A(){const t=W("Bot templates"),[e,o]=await Promise.all([pt(),Y()]),i=n("div","bv-template-list");for(const r of o){const u=n("div","bv-template-row");u.appendChild(n("span","bv-template-name",r.manifest.name)),u.appendChild(n("span","bv-template-desc",r.manifest.description||""));const m=n("button","btn","Edit");m.onclick=()=>X(t,e,r);const v=n("button","btn","Copy");v.title="Duplicate this template",v.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=n("button","btn danger","Delete");I.onclick=()=>{confirm(`Delete template ${r.manifest.name}?`)&&f(`/api/bots/templates/${r.id}`,{method:"DELETE"}).then(()=>A())};const x=n("span","bv-template-actions");x.append(m,v,I),u.appendChild(x),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"),l=n("button","btn primary","New template");l.onclick=()=>X(t,e,null);const a=n("button","btn","Export");a.title="Download templates + library as JSON",a.onclick=()=>{(async()=>{try{const r=await fetch("/api/bots/export",{headers:{Authorization:`Bearer ${D()}`}});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=n("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()),v=await f("/api/bots/import",{method:"POST",body:JSON.stringify(m)});alert(`Imported ${v.templates} templates, ${v.files} library files (${v.skipped} kept)`),await A()}catch(m){alert(m instanceof Error?m.message:String(m))}})()},r.click()},s.append(l,a,p),t.appendChild(s)}function U(t,e,o){const i=n("div","bv-field");i.appendChild(n("label","bv-label",t));const s=n("div","bv-check-grid"),l=[];for(const a of e){const p=n("label","bv-check"),r=document.createElement("input");r.type="checkbox",r.checked=o.includes(a.id),p.append(r,n("span",void 0,a.label)),a.hint&&(p.title=a.hint),s.appendChild(p),l.push({id:a.id,input:r})}return i.appendChild(s),{element:i,get:()=>l.filter(a=>a.input.checked).map(a=>a.id)}}function X(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 l=n("input","bv-input");l.value=i.description||"",l.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 p=U("Skills",e.skills.map(c=>({id:c.id,label:c.name,hint:c.description})),i.skills||[]),r=U("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=U("Prompt templates",e.prompts.map(c=>({id:c.id,label:c.name})),i.prompts||[]),m=n("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 v=n("div","bv-field");v.appendChild(n("label","bv-label","Tools (allow list; deny always blocks)"));const I=n("div","bv-check-grid"),x=[];for(const c of e.tools){const N=n("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,n("span",void 0,c.name)),I.appendChild(N),x.push({name:c.name,input:k})}v.appendChild(I);const C=n("input","bv-input");C.value=(i.tools?.deny||[]).join(", "),C.placeholder="Always deny (comma separated), e.g. bash, write";const y=n("textarea","bv-textarea");y.rows=2,y.value=(i.packages||[]).join(`
|
|
2
|
-
`),y.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";const
|
|
3
|
-
${c.model}`));i.model?.provider&&i.model?.id&&(
|
|
4
|
-
${i.model.id}`);const O=
|
|
5
|
-
`),k=e.mcp.find(g=>g.id===m.value),
|
|
6
|
-
`).map(g=>g.trim()).filter(Boolean),mcp:k?{mcpServers:k.servers}:void 0,tools:{allow:
|
|
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
|
+
`),y.placeholder="Pi packages, one per line (npm:@scope/pkg@1.2.3, git:..., ./path)";const x=o("select","bv-input");x.appendChild(new Option("default (Pi settings)",""));for(const c of e.models)x.appendChild(new Option(`${c.provider}/${c.model}`,`${c.provider}
|
|
3
|
+
${c.model}`));i.model?.provider&&i.model?.id&&(x.value=`${i.model.provider}
|
|
4
|
+
${i.model.id}`);const O=o("select","bv-input");for(const c of["","off","minimal","low","medium","high","xhigh","max"])O.appendChild(new Option(c||"default",c));i.model?.thinking&&(O.value=i.model.thinking);const B=o("select","bv-input");for(const c of["supervised","auto-accept-edits","full-access"])B.appendChild(new Option(c,c));B.value=i.permissions?.runtimeMode||"supervised";const w=o("select","bv-input");w.appendChild(new Option("ignore project .pi (recommended)","ignore")),w.appendChild(new Option("inherit project .pi (needs trust)","inherit")),w.value=i.projectResources||"ignore";const $=o("label","bv-check"),b=document.createElement("input");b.type="checkbox",b.checked=!!i.orchestrator,$.append(b,o("span",void 0,"Super bot: gets orchestration tools (create/stop/status child bots)"));const v=(c,N)=>{const k=o("div","bv-field");return k.appendChild(o("label","bv-label",c)),k.appendChild(N),k};t.append(v("Name",s),v("Description",l),v("System prompt",d),p.element,r.element,u.element,v("MCP preset",m),h,v("Always deny tools",C),v("Packages",y),v("Model",x),v("Thinking level",O),v("Approval mode",B),v("Project resources",w),$);const L=o("button","btn primary",n?"Save template":"Create template");L.onclick=async()=>{const[c,N]=x.value.split(`
|
|
5
|
+
`),k=e.mcp.find(g=>g.id===m.value),et={name:s.value.trim()||"bot",description:l.value.trim()||void 0,system:d.value.trim()||void 0,skills:p.get(),extensions:r.get().map(g=>(g.startsWith("builtin:"),g)),prompts:u.get(),packages:y.value.split(`
|
|
6
|
+
`).map(g=>g.trim()).filter(Boolean),mcp:k?{mcpServers:k.servers}:void 0,tools:{allow:E.filter(g=>g.input.checked).map(g=>g.name),deny:C.value.split(",").map(g=>g.trim()).filter(Boolean)},model:c?{provider:c,id:N,thinking:O.value||void 0}:void 0,permissions:{runtimeMode:B.value},projectResources:w.value==="inherit"?"inherit":"ignore",orchestrator:b.checked||void 0};try{await f("/api/bots/templates",{method:"POST",body:JSON.stringify({id:n?.id,manifest:et})}),J(),await A()}catch(g){alert(g instanceof Error?g.message:String(g))}},t.appendChild(L)}async function bt(){return ft("")}async function ft(t){const e=V("New bot"),n=await Z();if(n.length===0){e.appendChild(o("div","bots-empty","No templates yet \u2014 create one with \u201CNew template\u201D."));return}const i=o("select","bv-input");for(const u of n)i.appendChild(new Option(u.manifest.name,u.id));const s=o("input","bv-input");s.placeholder="Title (defaults to template name)";const l=o("input","bv-input");l.placeholder="/path/to/project";const d=t||a.bots[0]?.projectPath||"";l.value=d;const p=o("select","bv-input");p.appendChild(new Option("shared \u2014 run in the project folder","shared")),p.appendChild(new Option("worktree \u2014 isolated git worktree","worktree")),e.append(_("Template",i),_("Title",s),_("Project path",l),_("Workspace",p));const r=o("button","btn primary","Create bot");r.onclick=async()=>{try{const u=await f("/api/bots",{method:"POST",body:JSON.stringify({templateId:i.value,title:s.value.trim()||void 0,projectPath:l.value.trim()||void 0,isolation:p.value})});J(),await S(!0),await K(u.id)}catch(u){alert(u instanceof Error?u.message:String(u))}},e.appendChild(r)}function _(t,e){const n=o("div","bv-field");return n.appendChild(o("label","bv-label",t)),n.appendChild(e),n}async function Q(){const t=V("Needs you");if(a.approvals=await f("/api/bots/approvals"),a.approvals.length===0){t.appendChild(o("div","bots-empty","Nothing waiting."));return}for(const e of a.approvals){const n=o("div","bv-approval");n.appendChild(o("div","bv-approval-title",`${e.botTitle}: ${e.title}`)),e.message&&n.appendChild(o("pre","bv-pre",e.message));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 danger","Deny"),p=async r=>{await f(`/api/bots/${e.botId}/approve`,{method:"POST",body:JSON.stringify({requestId:e.id,allow:r,reason:i.value||void 0})}),await S(!0),await Q()};l.onclick=()=>void p(!0),d.onclick=()=>void p(!1),s.append(i,l,d),n.appendChild(s),t.appendChild(n)}}function vt(){window.__botsInited||(window.__botsInited=!0,it(),ot(),window.__openBot=K,document.addEventListener("click",t=>{const e=t.target;e&&(e.closest(".session-item.bot-item")||e.closest(".session-item")&&a.activeId&&setTimeout(()=>H(),0))},!0),S(!0),a.pollTimer=window.setInterval(()=>{document.hidden||S()},6e3),window.addEventListener("beforeunload",()=>window.clearInterval(a.pollTimer)))}export{vt as initBots,ft as openNewBotForPath};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import{initTerminal as
|
|
1
|
+
import{initTerminal as nt}from"./terminal-core.js";import{initBots as st,openNewBotForPath as it}from"./bots-client.js";import{icon as Q}from"../lib/icons.js";const j=window.__TMUX_WEB_SHELL__;let f=null,u=null;const O=typeof window.__TMUX_WEB_SCOPE__?.agentId=="string"?window.__TMUX_WEB_SCOPE__.agentId:null;let h=O;window.__tmuxWebScopeAgent=O;let he="sessions",T="",ee="",te="",Te="";function g(e){return h?"/a/"+encodeURIComponent(h)+e:e}const d=document.getElementById("sidebar-content"),R=document.getElementById("main-placeholder"),w=document.getElementById("terminal-container"),U=document.getElementById("file-editor"),ot=document.getElementById("fe-path"),E=document.getElementById("fe-status"),W=document.getElementById("fe-content"),_=document.getElementById("fe-save"),at=document.getElementById("fe-delete"),lt=document.getElementById("fe-back"),xe=document.getElementById("fe-new-name"),ct=document.getElementById("fe-new-btn"),be=document.getElementById("settings-backdrop"),Me=document.getElementById("settings-popover"),He=document.querySelector(".sidebar"),Ne="tmux-web-force-narrow";function ne(){try{return localStorage.getItem(Ne)==="1"}catch{return!1}}function Re(){document.documentElement.classList.toggle("force-narrow",ne()),ne()&&_e()&&z()}function _e(){return ne()?!0:window.matchMedia("(max-width: 640px)").matches}function z(){_e()&&He.classList.add("collapsed")}function $e(){He.classList.remove("collapsed")}window.__collapseSidebar=z,document.getElementById("mode-sessions").addEventListener("click",()=>{$e(),Ae("sessions")}),document.getElementById("mode-files").addEventListener("click",()=>{$e(),Ae("files")});function Ae(e){he=e,document.querySelectorAll(".mode-btn").forEach(n=>n.classList.remove("active"));const t=document.getElementById(e==="sessions"?"mode-sessions":"mode-files");t&&t.classList.add("active"),e==="sessions"?(we="",x()):kt()}let we="";async function x(){if(he!=="sessions")return;try{const n=await(await fetch("/api/sidebar/sessions")).json(),s=(window.__botsSnapshot||[]).map(o=>[o.id,o.title,o.status,o.projectPath]),i=JSON.stringify({recent:n.recent,agents:n.agents,tombstones:n.tombstones,bots:s});if(i===we)return;we=i,mt(n)}catch{d.innerHTML+='<div class="file-tree-empty">Failed to load sessions</div>'}const e=document.getElementById("ns-btn");e&&e.addEventListener("click",()=>{const t=window.__openNewSessionModal;typeof t=="function"?t():document.getElementById("new-session-modal")?.classList.add("open")}),Ie()}const Pe="tmux-web-sidebar-group-collapsed";function De(){try{return new Set(JSON.parse(localStorage.getItem(Pe)||"[]"))}catch{return new Set}}function rt(e){try{localStorage.setItem(Pe,JSON.stringify([...e]))}catch{}}function dt(e,t,n){if(!e)return"\u2026";const s=n&&(e===n||e.startsWith(n+"/"))?"~"+e.slice(n.length):e,i=s.split("/").filter(Boolean);if(i.length===0)return e;for(let o=1;o<=i.length;o++){const a=i.slice(-o).join("/");if(!t.some(c=>!c||c===e?!1:(n&&(c===n||c.startsWith(n+"/"))?"~"+c.slice(n.length):c).split("/").filter(Boolean).slice(-o).join("/")===a))return a}return s}function pt(e){const t=document.createElement("div");t.className="session-item bot-item",t.setAttribute("data-bot-id",e.id),t.title=`Bot \xB7 ${e.projectPath}`;const n=e.status==="running"?"var(--panel-success)":e.status==="waiting_approval"||e.status==="waiting_input"?"#e0a23c":e.status==="failed"?"var(--panel-danger, #e5534b)":"var(--panel-muted)";return t.innerHTML=`${Q("bot",'class="bot-icon"')}<span>${p(e.title)}</span><span class="bot-status-dot" style="background:${n}"></span>`,t.addEventListener("click",s=>{s.stopPropagation(),window.__openBot?.(e.id)}),t}function je(e,t,n,s=!0){const i=new Map;for(const r of e){const v=r.path||"";i.has(v)||i.set(v,[]),i.get(v).push(r)}const o=n?[]:window.__botsSnapshot||[],a=new Map;for(const r of o)i.has(r.projectPath)||i.set(r.projectPath,[]),a.has(r.projectPath)||a.set(r.projectPath,[]),a.get(r.projectPath).push(r);const l=[...i.keys()],c=De();for(const[r,v]of i){const H=dt(r,l,t),N=c.has(r),I=document.createElement("div");if(I.className="session-group-header"+(N?" collapsed":""),I.title=r||"No working directory",I.innerHTML=`<span class="sg-folder">📁</span><span class="sg-label">${p(H)}</span>`,!n&&r){const y=document.createElement("button");y.className="sg-add-bot",y.innerHTML=Q("add",'width="12" height="12"'),y.title=`New bot in ${r}`,y.addEventListener("click",Z=>{Z.stopPropagation(),Ee(r)}),I.appendChild(y)}I.addEventListener("click",()=>{const y=De(),Z=I.nextElementSibling;y.has(r)?(y.delete(r),I.classList.remove("collapsed"),Z?.classList.remove("collapsed")):(y.add(r),I.classList.add("collapsed"),Z?.classList.add("collapsed")),rt(y)});const X=document.createElement("div");X.className="session-group-body"+(N?" collapsed":"");for(const y of v)X.appendChild(n?ft(y,n,s):ut(y));for(const y of a.get(r)||[])X.appendChild(pt(y));d.appendChild(I),d.appendChild(X)}}function ft(e,t,n){const s=document.createElement("div");s.className="session-item"+(e.name===u&&h===t?" active":"")+(n?"":" session-offline"),s.setAttribute("data-session",e.name),s.setAttribute("data-agent",t),s.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${e.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
2
2
|
<span>${p(e.name)}</span>${n?"":'<span class="meta">offline</span>'}
|
|
3
|
-
<button class="session-edit-btn" data-session="${p(e.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,n&&s.addEventListener("click",o=>{o.target.closest(".session-edit-btn")||
|
|
3
|
+
<button class="session-edit-btn" data-session="${p(e.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,n&&s.addEventListener("click",o=>{o.target.closest(".session-edit-btn")||F(e.name,t)});const i=s.querySelector(".session-edit-btn");return i&&i.addEventListener("click",o=>{o.stopPropagation(),fe(e.name,i,{agentId:t})}),s}function ut(e){const t=document.createElement("div");t.className="session-item"+(e.name===u&&!h?" active":""),t.setAttribute("data-session",e.name),t.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="${e.attached?"M19 4H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 14H5V6h14v12z":"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"}"></svg>
|
|
4
4
|
<span>${p(e.name)}</span>
|
|
5
5
|
<button class="session-edit-btn" data-session="${p(e.name)}" title="Edit session"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>
|
|
6
|
-
`,t.addEventListener("click",s=>{s.target.closest(".session-edit-btn")||
|
|
6
|
+
`,t.addEventListener("click",s=>{s.target.closest(".session-edit-btn")||F(e.name)});const n=t.querySelector(".session-edit-btn");return n&&n.addEventListener("click",s=>{s.stopPropagation(),fe(e.name,n)}),t}function mt(e){d.innerHTML='<button class="new-session-sidebar-btn" id="ns-btn">+ New Session</button>';const t=e.recent||[],n=document.createElement("div");n.className="sidebar-section-label"+(O?" clickable":""),n.textContent=O?"\u2190 \u8FD4\u56DE\u672C\u673A":"\u672C\u673A",O&&(n.title="Back to hub",n.addEventListener("click",()=>{window.location.href="/"})),d.appendChild(n),je(t,e.home);const s=e.agents||[];for(const o of s){if(!o.sessions||o.sessions.length===0)continue;const a=o.agentId===h,l=document.createElement("div");l.className="sidebar-section-label machine-label"+(o.online?"":" agent-offline-label")+(!a&&o.online?" clickable":""),l.textContent=o.agentName+(o.online?"":" (offline)"),!a&&o.online&&(l.title="\u6253\u5F00 "+o.agentName,l.addEventListener("click",()=>{window.location.href="/a/"+encodeURIComponent(o.agentId)+"/"})),d.appendChild(l),je(o.sessions,e.home,o.agentId,o.online)}const i=e.tombstones||[];if(i.length>0){const o=document.createElement("div");o.className="sidebar-section-label tombstone-label",o.textContent="\u5931\u6548\u4F1A\u8BDD",d.appendChild(o);for(const a of i){const l=document.createElement("div");l.className="session-item session-tombstone",l.setAttribute("data-session",a.name),a.agentId&&l.setAttribute("data-agent",a.agentId);const c=a.agentId?a.agentOnline?" (agent)":" (agent \u79BB\u7EBF)":"";l.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z"></svg>
|
|
7
7
|
<span>${p(a.name)}</span><span class="meta">\u5931\u6548${c}</span>
|
|
8
|
-
<button class="session-edit-btn" data-session="${p(a.name)}" title="\u6062\u590D\u4F1A\u8BDD"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,l.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",l.addEventListener("click",()=>{
|
|
8
|
+
<button class="session-edit-btn" data-session="${p(a.name)}" title="\u6062\u590D\u4F1A\u8BDD"><svg viewBox="0 0 24 24" fill="currentColor" width="14" height="14"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 000-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg></button>`,l.title="\u5931\u6548\u4F1A\u8BDD\uFF1A\u70B9\u51FB\u7BA1\u7406\uFF08\u91CD\u5EFA/\u91CD\u547D\u540D/\u5220\u9664\uFF09",l.addEventListener("click",()=>{fe(a.name,l,{tombstone:!0,agentId:a.agentId})});const r=l.querySelector(".session-edit-btn");r&&r.addEventListener("click",v=>{v.stopPropagation(),fe(a.name,r,{tombstone:!0,agentId:a.agentId})}),d.appendChild(l)}}}function p(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function F(e,t){if(u===e&&f&&h===(t||null))return;U.style.display="none",R.style.display="none",w.style.display="",w.classList.add("terminal-pending"),z(),f&&(de(),f.destroy(),f=null),u=e,h=t||null,window.__tmuxWebScopeAgent=h,window.__tmuxWebCurrentSession=u,jt(e,t);const n=Be(e,t);et.set(n,Date.now()+Pt);const s=D.get(n);if(s&&s.state==="working"){s.state="idle",s.doneUntil=void 0,s.unread=!1;const i=d.querySelector(t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])');i&&ye(i,n,s)}for(const i of d.querySelectorAll(".session-item"))i.classList.toggle("active",i.getAttribute("data-session")===e&&(i.getAttribute("data-agent")||null)===h);try{f=await nt(w,e,{terminal:j.terminal,scrollback:j.scrollback,theme:j.theme,wsBase:h?"/ws/a/"+encodeURIComponent(h):j.wsBase||"/ws"}),Ke()}catch(i){console.error("[shell] terminal init failed:",i);const o=i&&typeof i=="object"&&"message"in i?i.message:String(i);w.textContent="Failed to open terminal for "+e+": "+o,w.classList.remove("terminal-pending")}}let se=[],m=null,Oe=!1;function gt(e){if(!m||!m.files.length)return null;const t=m.repoRoot;if(!t||!e.startsWith(t))return null;const n=e.slice(t.length+1);for(const s of m.files)if(s.path===n)return s.status;return null}async function vt(e){Oe=!0;try{const t=await fetch(g("/api/git/status?path="+encodeURIComponent(e)));t.ok?m=await t.json():m=null}catch{m=null}finally{Oe=!1}}function yt(){if(!m||!m.branch)return"";const{branch:e,linesAdded:t,linesRemoved:n}=m;let s=`<div class="sidebar-git"><div class="git-branch-badge">
|
|
9
9
|
<svg viewBox="0 0 16 16" fill="currentColor"><path d="M11.63 1.22a.75.75 0 00-1.06 0L5.99 5.8 4.12 3.93a.75.75 0 10-1.06 1.06L4.93 6.87A3.5 3.5 0 003 10.09v3.16a.75.75 0 001 0v-3.16a2.5 2.5 0 012.5-2.5h.27l-1.06 1.06a.75.75 0 001.06 1.06l2.37-2.38a.75.75 0 000-1.06L7.59 5.27l4.04-4.05a.75.75 0 000-1.06L11.63 1.22zM3.25 13.94a.75.75 0 01-.75-.75v-.69a.75.75 0 011.5 0v.69c0 .414-.336.75-.75.75z"/></svg>
|
|
10
|
-
${p(e)}</div>`;return(t>0||n>0)&&(s+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${n}</span></div>`),s+"</div>"}d.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&A&&m&&(e.stopPropagation(),
|
|
10
|
+
${p(e)}</div>`;return(t>0||n>0)&&(s+=`<div class="git-diff-stats">+<span class="add">${t}</span> <span class="del">-${n}</span></div>`),s+"</div>"}d.addEventListener("click",e=>{e.target.closest(".sidebar-git")&&A&&m&&(e.stopPropagation(),Ge())});const G=document.getElementById("header-git"),Ue=document.getElementById("git-diff-view"),We=document.getElementById("gd-path"),ie=document.getElementById("gd-status"),oe=document.getElementById("gd-content"),ht=document.getElementById("gd-back");let A=null;function q(e){if(!e||!e.branch){G.style.display="none",A=null;return}A=e.repoRoot;const{branch:t,linesAdded:n,linesRemoved:s}=e;let i=`<span class="branch">${p(t)}</span>`;(n>0||s>0)&&(i+=`<span class="sep">\xB7</span>+<span class="diff-add">${n}</span> <span class="diff-del">-${s}</span>`),G.innerHTML=i,G.style.display="block"}G.addEventListener("click",e=>{A&&m&&(e.stopPropagation(),Ge())});const b=document.getElementById("git-popover"),ae=document.getElementById("git-popover-backdrop");function Le(){const e=G.getBoundingClientRect();b.style.top=e.bottom+4+"px",b.style.left=Math.max(8,Math.min(e.left,window.innerWidth-400))+"px"}function ze(){const e=A,t=document.getElementById("git-popover-browse");t&&t.addEventListener("click",()=>{if(ce(),e){he="files",document.querySelectorAll(".mode-btn").forEach(s=>s.classList.remove("active"));const n=document.getElementById("mode-files");n&&n.classList.add("active"),M(e)}})}let Fe="";function Ge(){if(!m)return;const e=m.files||[];if(!e.length)b.innerHTML=`<div class="git-popover-header">No changes \u2014 clean working tree</div>
|
|
11
11
|
<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>`;else{let t=`<div class="git-popover-header">${e.length} file${e.length>1?"s":""} changed</div>`;for(let n=0;n<e.length;n++){const s=e[n],i=s.additions||0,o=s.deletions||0;let a="";switch(s.status){case"M":a='<span class="git-file-status M">M</span>';break;case"A":a='<span class="git-file-status A">A</span>';break;case"D":a='<span class="git-file-status D">D</span>';break;case"?":a='<span class="git-file-status ?">?</span>';break;case"R":a='<span class="git-file-status R">R</span>';break}t+=`<div class="git-popover-item" data-idx="${n}">
|
|
12
12
|
${a}<span class="file-path">${p(s.path)}</span>
|
|
13
13
|
<span class="file-add">${i>0?"+"+i:""}</span>
|
|
14
14
|
<span class="file-del">${o>0?"-"+o:""}</span>
|
|
15
|
-
</div>`}t+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',
|
|
15
|
+
</div>`}t+='<div class="git-popover-footer"><button id="git-popover-browse">Browse repository \u2192</button></div>',Fe=t,b.innerHTML=t,b.querySelectorAll(".git-popover-item").forEach(n=>{const s=parseInt(n.dataset.idx||"0",10),i=e[s];!i||i.status==="D"||(n.classList.add("clickable"),n.style.cursor="pointer",n.addEventListener("click",()=>Ve(i.path)))})}Le(),b.classList.add("open"),ae.classList.add("open"),ze()}function bt(){return window.innerWidth>=1024}function qe(e,t){const s=(e+(t&&e?`
|
|
16
16
|
`:"")+t).split(`
|
|
17
|
-
`);let i="",o=0,a=0;for(const l of s){const c=l;if(c.startsWith("@@")){const r=c.match(/@@\s+-(\d+)[^+]*\+(\d+)/);r&&(o=parseInt(r[1],10)-1,a=parseInt(r[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${p(c)}</span></div>`;continue}if(c.startsWith("diff --git")||c.startsWith("index ")||c.startsWith("--- ")||c.startsWith("+++ ")||c.startsWith("new file")||c.startsWith("deleted file")){c.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${p(c)}</span></div>`);continue}if(c.startsWith("+"))a++,i+=`<div class="diff-line add"><span class="ln-no">${a}</span><span class="ln-body">${p(c)}</span></div>`;else if(c.startsWith("-"))o++,i+=`<div class="diff-line del"><span class="ln-no">${o}</span><span class="ln-body">${p(c)}</span></div>`;else if(c.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${p(c)}</span></div>`;else{if(!c&&!o&&!a)continue;o++,a++,i+=`<div class="diff-line"><span class="ln-no">${o}</span><span class="ln-no" style="margin-right:12px">${a}</span><span class="ln-body">${p(c)}</span></div>`}}return{html:i,lineCount:s.length}}let
|
|
17
|
+
`);let i="",o=0,a=0;for(const l of s){const c=l;if(c.startsWith("@@")){const r=c.match(/@@\s+-(\d+)[^+]*\+(\d+)/);r&&(o=parseInt(r[1],10)-1,a=parseInt(r[2],10)-1),i+=`<div class="diff-line hunk"><span class="ln-body">${p(c)}</span></div>`;continue}if(c.startsWith("diff --git")||c.startsWith("index ")||c.startsWith("--- ")||c.startsWith("+++ ")||c.startsWith("new file")||c.startsWith("deleted file")){c.startsWith("diff --git")&&(i+=`<div class="diff-line header"><span class="ln-body">${p(c)}</span></div>`);continue}if(c.startsWith("+"))a++,i+=`<div class="diff-line add"><span class="ln-no">${a}</span><span class="ln-body">${p(c)}</span></div>`;else if(c.startsWith("-"))o++,i+=`<div class="diff-line del"><span class="ln-no">${o}</span><span class="ln-body">${p(c)}</span></div>`;else if(c.startsWith("\\"))i+=`<div class="diff-line"><span class="ln-body">${p(c)}</span></div>`;else{if(!c&&!o&&!a)continue;o++,a++,i+=`<div class="diff-line"><span class="ln-no">${o}</span><span class="ln-no" style="margin-right:12px">${a}</span><span class="ln-body">${p(c)}</span></div>`}}return{html:i,lineCount:s.length}}let le=null;async function Ve(e){const t=A;if(t)if(ce(),bt()){w.style.display="none",f&&(de(),f.destroy(),f=null,le=u,u=null),q(null),U.style.display="none",R.style.display="none",Ue.style.display="flex",We.textContent=e,ie.textContent="Loading\u2026",oe.innerHTML="";try{const n=await fetch(g("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!n.ok)throw new Error(await n.text());const s=await n.json();Lt(e,s.diff,s.stagedDiff)}catch(n){const s=n instanceof Error?n.message:String(n);ie.textContent="Error",oe.innerHTML=`<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">Error: ${p(s)}</div>`}}else{b.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
18
18
|
<button class="diff-back">\u2190 Back</button>
|
|
19
19
|
<span class="diff-filename">${p(e)}</span>
|
|
20
20
|
<span class="diff-loading">Loading\u2026</span>
|
|
21
|
-
</div></div>`,
|
|
21
|
+
</div></div>`,Le(),b.classList.add("open"),ae.classList.add("open");try{const n=await fetch(g("/api/git/diff?path="+encodeURIComponent(t)+"&file="+encodeURIComponent(e)));if(!n.ok)throw new Error(await n.text());const s=await n.json();wt(e,s.diff,s.stagedDiff)}catch(n){const s=n instanceof Error?n.message:String(n);b.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
22
22
|
<button class="diff-back">\u2190 Back</button>
|
|
23
23
|
<span class="diff-filename">${p(e)}</span>
|
|
24
|
-
</div><div class="diff-empty">Error loading diff: ${p(s)}</div></div>`}}}function
|
|
24
|
+
</div><div class="diff-empty">Error loading diff: ${p(s)}</div></div>`}}}function wt(e,t,n){if(!t&&!n){b.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
25
25
|
<button class="diff-back">\u2190 Back</button>
|
|
26
26
|
<span class="diff-filename">${p(e)}</span>
|
|
27
|
-
</div><div class="diff-empty">No diff content available</div></div>`;return}const{html:s,lineCount:i}=
|
|
27
|
+
</div><div class="diff-empty">No diff content available</div></div>`;return}const{html:s,lineCount:i}=qe(t,n);b.innerHTML=`<div class="git-diff-view"><div class="diff-header">
|
|
28
28
|
<button class="diff-back">\u2190 Back</button>
|
|
29
29
|
<span class="diff-filename">${p(e)}</span>
|
|
30
30
|
<span class="diff-filesize">${i} lines</span>
|
|
31
|
-
</div><div class="diff-content">${s}</div></div>`,b.querySelector(".diff-back")?.addEventListener("click",()=>{b.innerHTML=
|
|
31
|
+
</div><div class="diff-content">${s}</div></div>`,b.querySelector(".diff-back")?.addEventListener("click",()=>{b.innerHTML=Fe,Le(),m&&b.querySelectorAll(".git-popover-item").forEach(o=>{const a=parseInt(o.dataset.idx||"0",10),l=m.files[a];!l||l.status==="D"||(o.style.cursor="pointer",o.addEventListener("click",()=>Ve(l.path)))}),ze()})}function Lt(e,t,n){if(!t&&!n){ie.textContent="No diff",oe.innerHTML='<div class="diff-empty" style="padding:24px;text-align:center;color:var(--panel-muted)">No diff content available</div>';return}const{html:s,lineCount:i}=qe(t,n);We.textContent=e,ie.textContent=i+" lines",oe.innerHTML=s}function Et(){Ue.style.display="none",le?(w.style.display="",w.classList.add("terminal-pending"),F(le),le=null):u?(w.style.display="",w.classList.add("terminal-pending"),Ke()):R.style.display="flex"}ht.addEventListener("click",Et);function ce(){b.classList.remove("open"),ae.classList.remove("open")}ae.addEventListener("click",ce),document.addEventListener("keydown",e=>{e.key==="Escape"&&(ce(),ve())});async function Je(e){try{const n=await(await fetch("/api/fs/session-path?session="+encodeURIComponent(e))).json();if(n.path){const s=await fetch("/api/git/status?path="+encodeURIComponent(n.path));if(s.ok){const i=await s.json();m=i,q(i);return}}}catch{}m=null,q(null)}let re=null;function Ke(){de(),u&&(Je(u),re=setInterval(()=>{u&&Je(u)},3e4))}function de(){re&&(clearInterval(re),re=null)}async function Ee(e){let t=e;if(t.startsWith("~"))try{const s=await(await fetch(g("/api/fs/list?path="+encodeURIComponent(t)))).json();typeof s.path=="string"&&s.path&&(t=s.path)}catch{}t=t.replace(/\/+$/,"")||"/",it(t)}function Ye(e,t){const n=document.createElement("button");n.className="file-tree-bot-btn",n.innerHTML=Q("add",'width="12" height="12"'),n.title=`Create bot in ${t}`,n.setAttribute("aria-label",`Create bot in ${t}`),n.addEventListener("click",s=>{s.preventDefault(),s.stopPropagation(),Ee(t)}),e.appendChild(n)}function kt(){if(se=j.fsRoots||[],se.length===0){if(u){St(u);return}M("");return}d.innerHTML="";for(const e of se){const t=document.createElement("div");t.className="file-tree-item",t.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${p(e)}`,t.addEventListener("click",()=>M(e)),Ye(t,e),d.appendChild(t)}}async function St(e){d.innerHTML='<div class="file-tree-empty">Loading...</div>';try{const n=await(await fetch(g("/api/fs/session-path?session="+encodeURIComponent(e)))).json();n.path?M(n.path):d.innerHTML='<div class="file-tree-info">Could not determine session directory.</div>'}catch{d.innerHTML='<div class="file-tree-error">Failed to get session directory</div>'}}async function M(e){T=e,d.innerHTML='<div class="file-tree-empty">Loading...</div>';const t=vt(e);try{const s=await(await fetch(g("/api/fs/list?path="+encodeURIComponent(e)))).json(),i=typeof s.path=="string"&&s.path?s.path:e;if(i&&(T=i),await t,d.innerHTML="",i){const l=document.createElement("div");l.className="file-tree-item file-tree-create-bot",l.innerHTML=`<span class="file-tree-bot-plus">${Q("add",'width="11" height="11"')}</span> Create bot in this folder`,l.title=`Create bot in ${i}`,l.addEventListener("click",()=>void Ee(i)),d.appendChild(l)}q(m),d.innerHTML+=yt();const o=Ct(i||e);if(o&&!se.some(c=>i===c)){const c=document.createElement("div");c.className="file-tree-item",c.innerHTML="..",c.addEventListener("click",()=>M(o)),d.appendChild(c)}if(s.dirs)for(const l of s.dirs){const c=l.split("/").pop()||l.split("\\").pop(),r=document.createElement("div");r.className="file-tree-item",r.innerHTML=`<svg viewBox="0 0 24 24" fill="currentColor" class="file-icon"><path d="M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg> ${p(c)}`,r.addEventListener("click",()=>M(l)),Ye(r,l),d.appendChild(r)}else d.innerHTML="";const a=s.files||[];for(const l of a){const c=l.split("/").pop()||l.split("\\").pop(),r=gt(l);let v="",H="";if(r)switch(r){case"M":v="git-mod",H='<span class="git-file-status M">M</span>';break;case"A":v="git-add",H='<span class="git-file-status A">A</span>';break;case"D":v="git-del",H='<span class="git-file-status D">D</span>';break;case"?":v="git-untracked",H='<span class="git-file-status ?">?</span>';break;case"R":v="git-mod",H='<span class="git-file-status R">R</span>';break}const N=document.createElement("div");N.className="file-tree-item file"+(v?" "+v:""),N.innerHTML=`<span class="file-icon">\u{1F4C4}</span> ${H}${p(c)}`,N.addEventListener("click",()=>Bt(l)),d.appendChild(N)}}catch{d.innerHTML='<div class="file-tree-error">Failed to load directory</div>'}}function Ct(e){const t=e.lastIndexOf("/");return t<=0?null:e.substring(0,t)}async function Bt(e){ee=e,w.style.display="none",f&&(de(),f.destroy(),f=null,u=null),q(null),z(),R.style.display="none",U.style.display="flex",ot.textContent=e,E.textContent="Loading...",_.style.display="none";try{const t=await fetch(g("/api/file?path="+encodeURIComponent(e)));if(!t.ok){const s=await t.json();E.textContent=s.error||"Failed to load",W.value="";return}const n=await t.json();W.value=n.content,te=n.content,Te=n.content,E.textContent=n.size+" bytes",_.style.display=""}catch{E.textContent="Failed to load",W.value=""}}W.addEventListener("input",()=>{te=W.value}),_.addEventListener("click",async()=>{_.textContent="Saving...",_.disabled=!0;try{const e=await fetch(g("/api/file"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:ee,content:te})});if(!e.ok){const t=await e.json();E.textContent=t.error||"Save failed";return}Te=te,E.textContent="Saved"}catch{E.textContent="Save failed"}finally{_.disabled=!1,_.textContent="Save"}}),at.addEventListener("click",async()=>{if(confirm("Delete "+ee+"?"))try{const e=await fetch(g("/api/file/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:ee})});if(!e.ok){const t=await e.json();E.textContent=t.error||"Delete failed";return}U.style.display="none",R.style.display="flex",T&&M(T)}catch{E.textContent="Delete failed"}}),lt.addEventListener("click",()=>{U.style.display="none",R.style.display="flex",T&&M(T)}),ct.addEventListener("click",async()=>{const e=xe.value.trim();if(!e)return;const t=T+"/"+e;try{const n=await fetch(g("/api/file/touch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!n.ok){const s=await n.json();E.textContent=s.error||"Create failed";return}xe.value="",T&&M(T)}catch{E.textContent="Create failed"}});const pe=document.getElementById("force-narrow-toggle");pe&&(pe.checked=ne(),pe.addEventListener("change",()=>{try{localStorage.setItem(Ne,pe.checked?"1":"0")}catch{}Re(),x()})),Re(),document.getElementById("mode-settings").addEventListener("click",()=>{const e=Me.classList.toggle("open");be.classList.toggle("open",e)}),be.addEventListener("click",()=>{Me.classList.remove("open"),be.classList.remove("open")});let L="",k=!1,S;const V=document.createElement("div");V.className="session-popover-backdrop",document.body.appendChild(V);const C=document.createElement("div");C.id="session-popover",C.className="session-popover",C.style.display="none",C.innerHTML=`<div class="sp-field">
|
|
32
32
|
<label>Rename session</label>
|
|
33
33
|
<input type="text" id="sp-name" />
|
|
34
34
|
</div>
|
|
@@ -38,5 +38,5 @@ import{initTerminal as tt}from"./terminal-core.js";import{initBots as nt,openNew
|
|
|
38
38
|
<button class="btn danger sp-delete" id="sp-delete">Delete</button>
|
|
39
39
|
</div>
|
|
40
40
|
<hr class="sp-divider" id="sp-divider" />
|
|
41
|
-
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(
|
|
42
|
-
`).length;B.rows=Math.min(e,4)}),B.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),
|
|
41
|
+
<button class="btn primary" id="sp-rebuild" style="display:none">\u91CD\u5EFA\u540C\u540D\u540C\u8DEF\u5F84 session</button>`,document.body.appendChild(C);function It(e){const t=e.getBoundingClientRect(),n=window.innerHeight,s=C.offsetHeight||240;let i=t.bottom+4;i+s>n-8&&(i=Math.max(8,t.top-s-4)),C.style.top=i+"px",C.style.left=Math.max(8,Math.min(t.left,window.innerWidth-240))+"px"}let zt="";function fe(e,t,n){L=e,k=!!n?.tombstone,S=n?.agentId;const s=document.getElementById("sp-name");s.value=e;const i=C.querySelector(".sp-field label");i.textContent=k?"\u91CD\u547D\u540D (\u4EC5\u8BB0\u5F55\uFF0C\u4E0D\u91CD\u5EFA)":"Rename session";const o=document.getElementById("sp-rebuild");o.style.display=k?"":"none";const a=document.getElementById("sp-delete");a.textContent=k?"\u5220\u9664\u8BB0\u5F55":"Delete",a.title=k?"\u5220\u9664\u5931\u6548\u8BB0\u5F55\uFF08\u5893\u7891\u6D88\u5931\uFF09":"Delete session";const l=document.getElementById("sp-divider");l&&(l.style.display=k?"":"none");const c=document.getElementById("sp-save");c.textContent=k?"\u91CD\u547D\u540D":"Save",V.classList.add("open"),C.style.display="block",It(t),setTimeout(()=>s.focus(),50)}function $(){V.classList.remove("open"),C.style.display="none"}V.addEventListener("click",$),document.getElementById("sp-save").addEventListener("click",async()=>{const e=document.getElementById("sp-name").value.trim();if(!e||e===L){$();return}try{const t=k?{oldName:L,newName:e,agentId:S}:{oldName:L,newName:e,...S?{agentId:S}:{}};if(!(await fetch(g(k?"/api/sessions/rename-tombstone":"/api/sessions/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok)return;$(),x(),!k&&u===L&&(S??null)===h&&F(e,S)}catch{}}),document.getElementById("sp-rebuild").addEventListener("click",async()=>{if(confirm('\u91CD\u5EFA\u4F1A\u8BDD "'+L+'" (\u540C\u540D\u540C\u8DEF\u5F84\uFF0C\u5185\u5BB9\u4E3A\u7A7A)\uFF1F'))try{const e=await fetch(g("/api/sessions/rebuild"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:L,agentId:S})});if(!e.ok){const t=await e.json();alert(t.error||"\u91CD\u5EFA\u5931\u8D25");return}$(),x()}catch{}}),document.getElementById("sp-delete").addEventListener("click",async()=>{if(k){if(!confirm('\u5220\u9664\u5931\u6548\u8BB0\u5F55 "'+L+'"\uFF1F'))return;try{if(!(await fetch(g("/api/sessions/dismiss"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:L,agentId:S})})).ok)return;$(),x()}catch{}return}if(confirm('Delete session "'+L+'"?'))try{if(!(await fetch(g("/api/sessions/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:L,...S?{agentId:S}:{}})})).ok)return;$(),u===L&&(S??null)===h&&(f&&(f.destroy(),f=null),u=null,w.style.display="none",R.style.display="flex"),x()}catch{}}),document.getElementById("sp-cancel").addEventListener("click",$);const Xe={esc:"\x1B",tab:" ","s-tab":"\x1B[Z",up:"\x1B[A",down:"\x1B[B",left:"\x1B[D",right:"\x1B[C",space:" ",enter:"\r","ctrl-r":"","ctrl-c":"",btw:"/btw ",yes:"yes\r"},ue=document.getElementById("mobile-keys"),Tt=new Set(["up","down","left","right","tab","s-tab","space"]),xt=400,Mt=80;let J=0,me=0,ge=!1;function Ht(){J&&(clearTimeout(J),J=0),me&&(clearInterval(me),me=0)}ue.addEventListener("mousedown",e=>{e.target.closest("button[data-key]")&&e.preventDefault()}),ue.addEventListener("pointerdown",e=>{const t=e.target.closest("button[data-key]");if(!t)return;const n=t.dataset.key;Tt.has(n)&&(ge=!1,J=setTimeout(()=>{J=0,ge=!0,me=setInterval(()=>{const s=Xe[n];s&&f&&f.sendInput(s)},Mt)},xt))});for(const e of["pointerup","pointercancel","pointerleave"])ue.addEventListener(e,Ht);ue.addEventListener("click",e=>{const t=e.target.closest("button[data-key]");if(!t||!f)return;if(ge){ge=!1;return}const n=Xe[t.dataset.key];n&&(f.sendInput(n),f.focus())});const B=document.getElementById("mk-input"),Ze=document.getElementById("mk-send");function Qe(){if(!B||!f)return;const e=B.value;e&&(f.sendInput(e+"\r"),B.value="",B.rows=1,f.focus())}if(B&&(B.addEventListener("input",()=>{B.rows=1;const e=B.value.split(`
|
|
42
|
+
`).length;B.rows=Math.min(e,4)}),B.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Qe())})),Ze&&Ze.addEventListener("click",Qe),window.visualViewport){const e=document.querySelector(".app-layout"),t=()=>{e&&(e.style.height=window.visualViewport.height+"px"),window.scrollTo(0,0),document.documentElement.scrollTop=0,document.body.scrollTop=0};window.visualViewport.addEventListener("resize",t),window.addEventListener("orientationchange",()=>setTimeout(t,100)),document.addEventListener("touchstart",()=>{(window.scrollY>0||document.documentElement.scrollTop>0)&&window.scrollTo(0,0)},{passive:!0})}const ke=document.getElementById("process-panel"),K=document.getElementById("proc-list"),Nt=document.getElementById("proc-close"),Se=document.getElementById("proc-backdrop"),Rt=document.getElementById("header-ram");function _t(){K.innerHTML='<div class="proc-empty">Loading\u2026</div>',fetch(g("/api/system/processes")).then(e=>e.json()).then(e=>{if(!Array.isArray(e)||!e.length){K.innerHTML='<div class="proc-empty">No processes</div>';return}let t="";for(const n of e){const s=n.rss,i=s<1048576?(s/1024).toFixed(0)+"K":(s/1048576).toFixed(1)+"M";t+='<div class="proc-row" data-pid="'+n.pid+'"><span class="proc-mem">'+n.mem+'%</span><span class="proc-rss">'+i+'</span><span class="proc-cmd" title="'+p(n.command)+'">'+p(n.command)+'</span><button class="proc-kill" title="Kill PID '+n.pid+'">×</button></div>'}K.innerHTML=t;for(const n of K.querySelectorAll(".proc-row")){const s=n.querySelector(".proc-kill");s&&s.addEventListener("click",i=>{const o=i.target.closest(".proc-row");!o||!confirm("Kill PID "+o.dataset.pid+"?")||fetch(g("/api/system/kill"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:parseInt(o.dataset.pid,10)})}).then(a=>a.json()).then(a=>{a.ok?o.style.opacity="0.3":alert("Failed: "+(a.error||"unknown"))}).catch(()=>alert("Network error"))})}}).catch(()=>{K.innerHTML='<div class="proc-empty">Failed to load</div>'})}function $t(){ke.classList.add("open"),Se.classList.add("open"),_t()}function ve(){ke.classList.remove("open"),Se.classList.remove("open")}Rt.addEventListener("click",e=>{e.stopPropagation(),ke.classList.contains("open")?ve():$t()}),Nt.addEventListener("click",ve),Se.addEventListener("click",ve);const At=2e3;let Y=null,Ce=null;const P=new Map,D=new Map,Pt=5e3,et=new Map;function Be(e,t){return(t?"a:"+t+":":"l:")+e}function Dt(e,t,n){const s=Be(e,t);if(n==="working"){const r=et.get(s);if(r&&Date.now()<r)return}const i=D.get(s),o=e===u&&(t??null)===h,a=n==="idle"&&i?.state==="working";D.set(s,{session:e,agentId:t,state:n,doneUntil:a?Date.now()+At:void 0,unread:a?!o:!1});const l=t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',c=d.querySelector(l);c&&ye(c,s,D.get(s))}function ye(e,t,n){const s=P.get(t);s&&(clearTimeout(s),P.delete(t)),e.classList.remove("working","just-done");const i=n.session===u&&(n.agentId??null)===h;n.state==="working"?e.classList.add("working"):i&&n.doneUntil&&Date.now()<n.doneUntil?(e.classList.add("just-done"),P.set(t,setTimeout(()=>{e.classList.remove("just-done"),P.delete(t)},Math.max(0,n.doneUntil-Date.now())))):!i&&n.unread&&e.classList.add("just-done")}function Ie(){for(const[e,t]of D){const n=t.agentId?'.session-item[data-agent="'+CSS.escape(t.agentId)+'"][data-session="'+CSS.escape(t.session)+'"]':'.session-item[data-session="'+CSS.escape(t.session)+'"]:not([data-agent])',s=d.querySelector(n);s&&ye(s,e,t)}}function jt(e,t){const n=Be(e,t),s=D.get(n);if(!s)return;const i=P.get(n);i&&(clearTimeout(i),P.delete(n)),s.doneUntil=void 0,s.unread=!1;const o=t?'.session-item[data-agent="'+CSS.escape(t)+'"][data-session="'+CSS.escape(e)+'"]':'.session-item[data-session="'+CSS.escape(e)+'"]:not([data-agent])',a=d.querySelector(o);a&&ye(a,n,s)}function tt(){if(Y||Ce)return;const e=localStorage.getItem("tmux-web-token");let n=(location.protocol==="https:"?"wss:":"ws:")+"//"+location.host+"/ws/activity";e&&(n+="?token="+encodeURIComponent(e));try{const s=new WebSocket(n);Y=s,s.onmessage=i=>{try{const o=JSON.parse(String(i.data));o&&o.type==="session.activity"&&typeof o.session=="string"&&Dt(o.session,o.agentId||void 0,o.state==="working"?"working":"idle")}catch{}},s.onclose=()=>{Y===s&&(Y=null,Ce=setTimeout(()=>{Ce=null,tt()},5e3))},s.onerror=()=>{try{s.close()}catch{}}}catch{Y=null}}window.__openSession=F,window.__refreshSidebar=x,x(),z(),Ie(),tt(),document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Ie()}),setInterval(()=>{document.visibilityState==="visible"&&x()},1e4),st();
|
package/dist/lib/icons.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const a={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function l(h){return a[h]??a.menu}function c(h,v=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${v?" "+v:""}><path d="${l(h)}"/></svg>`}function H(h){return`<path d="${l(h)}"/>`}const m={};function
|
|
1
|
+
const a={menu:"M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z",close:"M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7a1 1 0 1 0-1.41 1.41L10.59 12l-4.89 4.89a1 1 0 1 0 1.41 1.41L12 13.41l4.89 4.89a1 1 0 1 0 1.41-1.41L13.41 12l4.89-4.89a1 1 0 0 0 0-1.4z",search:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z",refresh:"M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 1 0 8 8h-2a6 6 0 1 1-6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19zm13.66-12.83a1 1 0 0 0 0-1.41l-1.34-1.34a1 1 0 0 0-1.41 0l-1.05 1.05 2.75 2.75 1.05-1.05z",delete:"M15 4V3H9v1H4v2h1.5l.81 13.05A2 2 0 0 0 8.3 21h7.4a2 2 0 0 0 1.99-1.95L18.5 6H20V4h-5zm-5.5 2h5l-.75 12h-3.5L9.5 6z",check:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z",sessions:"M4 6h16v2H4V6zm0 5h16v2H4v-2zm0 5h16v2H4v-2z",notes:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",schedule:"M19 4h-1V2h-2v2H8V2H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2zm0 16H5V10h14v10zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z",agents:"M12 2a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm-7 13v-2a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v2h2v-2a7 7 0 0 0-7-7H10a7 7 0 0 0-7 7v2h2z",history:"M13 3a9 9 0 0 0-9 9H1l4 4 4-4H6a7 7 0 1 1 7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.96 8.96 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.25 2.55.75-1.23-3.5-2.08V8H12z","quick-commands":"M13 3 4 14h7l-1 7 9-11h-7l1-7z",windows:"M4 6h16v2H4V6zm0 5h10v2H4v-2zm0 5h16v2H4v-2z",terminal:"M4 17.6 6.4 20l8-8-8-8L4 6.4 11.6 12 4 17.6zM20 18h-8v2h8v-2z",microphone:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z",keyboard:"M20 5H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-9 3h2v2h-2V8zm0 3h2v2h-2v-2zM8 8h2v2H8V8zm0 3h2v2H8v-2zm-1 2H5v-2h2v2zm0-3H5V8h2v2zm9 7H8v-2h8v2zm0-4h-2v-2h2v2zm0-3h-2V8h2v2zm3 3h-2v-2h2v2zm0-3h-2V8h2v2z",bot:"M11 2h2v3h2a3 3 0 0 1 3 3v1h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-1v1a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3v-1H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2h1V8a3 3 0 0 1 3-3h2V2zm-2 6v1h6V8H9zm-2 5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm10 0a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z",layers:"M12 2 2 7l10 5 10-5-10-5zm0 7.5L4.5 5.8 12 2l7.5 3.8L12 9.5zM2 12l10 5 10-5-1.9-.95L12 14.9l-8.1-3.85L2 12zm0 4.5 10 5 10-5-1.9-.95L12 19.4l-8.1-3.85-1.9.95z",inbox:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5v-3h3.6a3.5 3.5 0 0 0 6.8 0H19v3zm0-5h-4.7a3.5 3.5 0 0 1-6.6 0H5V5h14v9z","chevron-down":"M7.4 8.6 12 13.2l4.6-4.6L18 10l-6 6-6-6 1.4-1.4z",settings:"M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6a3.6 3.6 0 1 1 0-7.2 3.6 3.6 0 0 1 0 7.2z",pin:"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4z","pin-outline":"M16 12V4h1V2H7v2h1v8l-4 4v2h5.2v6h1.6v-6H20v-2l-4-4zm-4.8 7.2V11l2-2V4h1.6v5l2 2v5.2H11.2z",folder:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z",file:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zm-1 2 5 5h-5V4zM6 20V4h5v7h7v9H6z",worktree:"M6 3a3 3 0 0 0-1 5.83v6.34a3 3 0 1 0 2 0V8.83A3 3 0 0 0 6 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm0 12a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM18 3a3 3 0 0 0-1 5.83V9a4 4 0 0 1-4 4h-2a3 3 0 1 0 0 2h2a6 6 0 0 0 6-6v-.17A3 3 0 0 0 18 3zm0 2a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM9 13a1 1 0 1 1 0 2 1 1 0 0 1 0-2z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",export:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",chevronRight:"M9.29 6.71a1 1 0 0 0 0 1.41L13.17 12l-3.88 3.88a1 1 0 1 0 1.41 1.41l4.59-4.59a1 1 0 0 0 0-1.41L10.7 6.7a1 1 0 0 0-1.41.01z",lightning:"M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.33.51-.89.73-1.27L13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15c-.22.46-.58 1.18-.78 1.58L11 21z","git-branch":"M13.5 7a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zm0 10a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0zM11 9.5v5.1a4.03 4.03 0 0 0-3-.1V9.4a4.03 4.03 0 0 0 3 .1z",external:"M14 3h7v7h-2V6l-9.29 9.29-1.41-1.41L17.59 4.5H14V3zm4 16H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7h-2v7z",play:"M8 5v14l11-7L8 5z",stop:"M6 6h12v12H6V6z",warning:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z",info:"M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z",spinner:"M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z",dots:"M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"};function l(h){return a[h]??a.menu}function c(h,v=""){return`<svg viewBox="0 0 24 24" fill="currentColor"${v?" "+v:""}><path d="${l(h)}"/></svg>`}function H(h){return`<path d="${l(h)}"/>`}const m={};function V(h,v){const z=m[h];return z?c(z):v?.trim().startsWith("<svg")?v:`<span style="font-size:18px;line-height:1">${v??""}</span>`}export{V as extIcon,c as icon,l as iconPath,H as iconPathString};
|