@timqi/pier 0.1.12 → 0.1.14
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/web/public/assets/{activity-CJtsniqS.js → activity-Ds6fCHnb.js} +1 -1
- package/dist/web/public/assets/activity-Ds6fCHnb.js.br +0 -0
- package/dist/web/public/assets/activity-Ds6fCHnb.js.gz +0 -0
- package/dist/web/public/assets/{boards-DyQtNqgv.js → boards-BKCj6EwK.js} +1 -1
- package/dist/web/public/assets/boards-BKCj6EwK.js.br +0 -0
- package/dist/web/public/assets/boards-BKCj6EwK.js.gz +0 -0
- package/dist/web/public/assets/{explorer-BQYNIR0V.js → explorer-DnTm975c.js} +1 -1
- package/dist/web/public/assets/explorer-DnTm975c.js.br +0 -0
- package/dist/web/public/assets/explorer-DnTm975c.js.gz +0 -0
- package/dist/web/public/assets/{index-CLNTSmYN.js → index-BQo-haPN.js} +2 -2
- package/dist/web/public/assets/index-BQo-haPN.js.br +0 -0
- package/dist/web/public/assets/index-BQo-haPN.js.gz +0 -0
- package/dist/web/public/assets/{runs-tYH577mL.js → runs-C_AthWcW.js} +1 -1
- package/dist/web/public/assets/runs-C_AthWcW.js.br +0 -0
- package/dist/web/public/assets/runs-C_AthWcW.js.gz +0 -0
- package/dist/web/public/assets/{settings-B42zHcpu.js → settings-DDaAtFlc.js} +1 -1
- package/dist/web/public/assets/settings-DDaAtFlc.js.br +0 -0
- package/dist/web/public/assets/settings-DDaAtFlc.js.gz +0 -0
- package/dist/web/public/assets/{task-runs-COIFbwwz.js → task-runs-0pvdITiV.js} +1 -1
- package/dist/web/public/assets/task-runs-0pvdITiV.js.br +0 -0
- package/dist/web/public/assets/task-runs-0pvdITiV.js.gz +0 -0
- package/dist/web/public/assets/{tasks-D1dGhkTZ.js → tasks-Bz29caHJ.js} +1 -1
- package/dist/web/public/assets/tasks-Bz29caHJ.js.br +0 -0
- package/dist/web/public/assets/tasks-Bz29caHJ.js.gz +0 -0
- package/dist/web/public/index.html +1 -1
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/dist/web/server.js +12 -3
- package/package.json +2 -2
- package/dist/web/public/assets/activity-CJtsniqS.js.br +0 -0
- package/dist/web/public/assets/activity-CJtsniqS.js.gz +0 -0
- package/dist/web/public/assets/boards-DyQtNqgv.js.br +0 -0
- package/dist/web/public/assets/boards-DyQtNqgv.js.gz +0 -0
- package/dist/web/public/assets/explorer-BQYNIR0V.js.br +0 -0
- package/dist/web/public/assets/explorer-BQYNIR0V.js.gz +0 -0
- package/dist/web/public/assets/index-CLNTSmYN.js.br +0 -0
- package/dist/web/public/assets/index-CLNTSmYN.js.gz +0 -0
- package/dist/web/public/assets/runs-tYH577mL.js.br +0 -0
- package/dist/web/public/assets/runs-tYH577mL.js.gz +0 -0
- package/dist/web/public/assets/settings-B42zHcpu.js.br +0 -0
- package/dist/web/public/assets/settings-B42zHcpu.js.gz +0 -0
- package/dist/web/public/assets/task-runs-COIFbwwz.js.br +0 -0
- package/dist/web/public/assets/task-runs-COIFbwwz.js.gz +0 -0
- package/dist/web/public/assets/tasks-D1dGhkTZ.js.br +0 -0
- package/dist/web/public/assets/tasks-D1dGhkTZ.js.gz +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$ as e,C as t,F as n,H as r,K as i,O as a,Q as o,X as s,Y as c,ot as l,t as u,tt as d,u as f}from"./index-
|
|
1
|
+
import{$ as e,C as t,F as n,H as r,K as i,O as a,Q as o,X as s,Y as c,ot as l,t as u,tt as d,u as f}from"./index-BQo-haPN.js";var p=[[`path`,{d:`M3 5h.01`}],[`path`,{d:`M3 12h.01`}],[`path`,{d:`M3 19h.01`}],[`path`,{d:`M8 5h13`}],[`path`,{d:`M8 12h13`}],[`path`,{d:`M8 19h13`}]],m=[[`path`,{d:`m10.586 5.414-5.172 5.172`}],[`path`,{d:`m18.586 13.414-5.172 5.172`}],[`path`,{d:`M6 12h12`}],[`circle`,{cx:`12`,cy:`20`,r:`2`}],[`circle`,{cx:`12`,cy:`4`,r:`2`}],[`circle`,{cx:`20`,cy:`12`,r:`2`}],[`circle`,{cx:`4`,cy:`12`,r:`2`}]],h=(e,t={})=>{let n=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);return n},g=e=>e===null?`-`:c(Date.now()-e),_={invocation:{stroke:`stroke-neutral-400`,fill:`fill-neutral-400`},callback:{stroke:`stroke-cyan-500`,fill:`fill-cyan-500`,dash:`6 5`},message:{stroke:`stroke-amber-500`,fill:`fill-amber-500`,dash:`2 5`}},v={scheduler:`border-violet-200 bg-violet-50 text-violet-700`,console:`border-indigo-200 bg-indigo-50 text-indigo-700`,task:`border-amber-200 bg-amber-50 text-amber-700`,process:`border-dashed border-neutral-300 bg-neutral-50 text-neutral-500`,streaming:`border-emerald-200 bg-white font-medium text-neutral-800`,idle:`border-neutral-200 bg-white font-medium text-neutral-600`},y=300,b=4;function x(e,t){let n,r=null,i=!1,a=!1,o=()=>{clearTimeout(n),n=setTimeout(()=>{i||a||!r||r.dataset.closing!==void 0||(f(),r=null)},120)};e.onpointerenter=s=>{s.pointerType!==`touch`&&(i=!0,clearTimeout(n),!(r?.isConnected&&r.dataset.closing===void 0)&&(n=setTimeout(()=>{!e.isConnected||!i||(r=u(e,t),r.onpointerenter=()=>{a=!0,clearTimeout(n)},r.onpointerleave=()=>{a=!1,o()})},y)))},e.onpointerleave=()=>{i=!1,o()},e.onpointerdown=()=>clearTimeout(n)}function S(e){let t,n=!1;e.classList.add(`cursor-grab`),e.onpointerdown=r=>{n=!1,!(r.button!==0||r.pointerType===`touch`||r.target.closest(`[data-node], path`))&&(t={x:r.clientX,y:r.clientY,left:e.scrollLeft,top:e.scrollTop},e.setPointerCapture(r.pointerId),e.classList.add(`cursor-grabbing`,`select-none`))},e.onpointermove=r=>{if(!t)return;let i=r.clientX-t.x,a=r.clientY-t.y;(Math.abs(i)>b||Math.abs(a)>b)&&(n=!0),e.scrollLeft=t.left-i,e.scrollTop=t.top-a};let r=()=>{t=void 0,e.classList.remove(`cursor-grabbing`,`select-none`)};e.onpointerup=r,e.onpointercancel=r,e.addEventListener(`click`,e=>{n&&(e.stopPropagation(),e.preventDefault())},!0)}function C(c,u,f){let y=`sessions`,b=`active`,C={sessions:[],runs:[],messages:[]},w=``,T=e(async()=>{let e=b,t=await d(`/api/activity?scope=${e}`,`Failed to load activity`);if(!t.ok){w=``,c.replaceChildren(s(`p`,`p-4 text-[13px] text-red-600`,t.error));return}if(e!==b)return;let n=JSON.stringify(t.value);if(`${e}:${n}`===w)return;w=`${e}:${n}`;let r=t.value;C={...r,sessions:r.sessions.map(e=>({...e,title:l(e.title)}))},E()});function E(){let e=r(n([[`Sessions`,`sessions`,p],[`Relationships`,`dependencies`,m]],y,e=>{y=e,E()}),s(`span`,`ml-auto text-[11.5px] text-neutral-400`,`${C.sessions.length} sessions · ${C.runs.length} runs`),n([[`Current`,`active`],[`Last 24h`,`recent`]],b,e=>{b=e,E(),T()})),t=s(`div`,`automation-list min-h-0 flex-1 overflow-auto`);y===`sessions`?D(t):k(t),c.replaceChildren(e,t)}function D(e){let t=document.createElement(`table`);t.className=`w-full table-fixed text-left text-[12.5px]`,t.innerHTML=`<thead class="sticky top-0 bg-neutral-50 text-[10.5px] uppercase tracking-wide text-neutral-400 shadow-[inset_0_-1px_0_var(--color-neutral-200)]"><tr>
|
|
2
2
|
<th class="w-[50%] px-4 py-2 font-semibold md:w-[34%]">Session</th>
|
|
3
3
|
<th class="hidden w-[38%] px-2 py-2 font-semibold md:table-cell">Project</th>
|
|
4
4
|
<th class="px-2 py-2 font-semibold md:w-[14%]">State</th>
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as e,K as t,M as n,O as r,P as i,V as a,X as o,Z as s,at as c,et as l,it as u,q as d,tt as f,w as p}from"./index-
|
|
1
|
+
import{E as e,K as t,M as n,O as r,P as i,V as a,X as o,Z as s,at as c,et as l,it as u,q as d,tt as f,w as p}from"./index-BQo-haPN.js";var m=e=>e.public&&e.token?`/p/${e.slug}-${e.token}/`:`/boards/${e.slug}/`;function h(h,g){let _=[],v=``,y=o(`header`,`pagehead sticky top-[-8px] z-30 max-md:hidden`,n(`Boards`)),b=o(`div`,`px-4 pb-5 pt-1`);h.append(o(`div`,`min-h-0 flex-1 overflow-y-auto`,y,b));async function x(e,t){let n=await c(`/api/boards/${e.slug}`,{public:t},`PATCH`);if(n.ok)return e.token=(await n.json().catch(()=>({}))).token??``,T();v=await l(n,`Could not change ${e.slug}`),await E()}async function S(e){v=await u(`/api/boards/${e}`,`DELETE`,`Could not delete ${e}`)??``,await E()}function C(e){let t=o(`div`,`group flex flex-col gap-1 py-2.5`),n=document.createElement(`a`);n.className=`min-w-0 flex-1 truncate text-[13px] font-medium text-neutral-800 hover:text-indigo-700 max-md:basis-full`,n.href=m(e),n.target=`_blank`,n.rel=`noreferrer`,n.textContent=e.title;let r=o(`div`,`flex flex-wrap items-center gap-x-2 gap-y-1`,n),c=a(``,``,e.public,t=>{e.public=t,x(e,t)});c.className=`flex flex-none cursor-pointer items-center gap-1.5 text-[11.5px] text-neutral-500`,c.append(o(`span`,``,`Public`));let l=p(`Delete`,i());l.title=`Renames the folder on disk; nothing is erased`,l.onclick=()=>void S(e.slug);let u=d(i(`hover:text-indigo-600`),()=>`${location.origin}${m(e)}`);u.title=`Copy the board's link`,r.append(o(`div`,`ml-auto flex flex-none items-center gap-2`,c,u,l)),t.append(r);let f=o(`div`,`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11.5px] text-neutral-500`);f.append(o(`span`,`min-w-0 break-all font-mono text-neutral-400`,e.slug)),e.description&&f.append(o(`span`,`min-w-0 truncate`,e.description)),f.append(o(`span`,`flex-none text-neutral-400`,s(Date.parse(e.updatedAt))));for(let t of e.sessions){let e=p(t.slice(0,8),`flex-none cursor-pointer font-mono text-indigo-600 hover:underline`);e.title=`Open session ${t}`,e.onclick=()=>g(t),f.append(e)}if(e.public&&e.token){let t=o(`span`,`min-w-0 break-all font-mono text-neutral-400`,m(e));t.title=`Public URL — anyone holding this link can read the board, no password`,f.append(t)}return t.append(f),t}let w=[{title:`Public`,hint:`Readable at /p/<slug>-<token>/ by anyone holding the link.`,wanted:!0},{title:`Private`,hint:`Opened from here; the address that opens is a temporary link, good for 8 hours.`,wanted:!1}];function T(){let t=o(`div`,`mx-auto flex w-full max-w-3xl flex-col gap-4`);_.length===0&&t.append(r(`No boards yet. Ask an agent to build one — it writes a folder under ~/.pier/boards.`));for(let{title:n,hint:r,wanted:i}of w){let a=_.filter(e=>e.public===i);a.length!==0&&t.append(e(n,r,o(`div`,`flex flex-col divide-y divide-neutral-200/70`,...a.map(C))))}b.replaceChildren(...v?[o(`p`,`mb-3 text-[13px] text-red-600`,v)]:[],t)}async function E(){let e=await f(`/api/boards`,`Could not load boards`);if(!e.ok)return v=e.error,T();_=e.value,T(),v=``}let D=t(h,()=>void E());return window.addEventListener(`focus`,()=>{D.visible&&E()}),D}export{h as createBoardsView};
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as e,J as t,K as n,M as r,O as i,X as a,Z as o,a as s,ct as c,f as l,g as u,h as d,ht as f,l as p,lt as m,m as h,mt as ee,nt as g,p as _,u as te,v as ne,w as re,y as ie}from"./index-
|
|
1
|
+
import{G as e,J as t,K as n,M as r,O as i,X as a,Z as o,a as s,ct as c,f as l,g as u,h as d,ht as f,l as p,lt as m,m as h,mt as ee,nt as g,p as _,u as te,v as ne,w as re,y as ie}from"./index-BQo-haPN.js";var ae=[[`path`,{d:`M12 5v14`}],[`path`,{d:`m19 12-7 7-7-7`}]],oe=[[`path`,{d:`M12 22v-6`}],[`path`,{d:`M12 8V2`}],[`path`,{d:`M4 12H2`}],[`path`,{d:`M10 12H8`}],[`path`,{d:`M16 12h-2`}],[`path`,{d:`M22 12h-2`}],[`path`,{d:`m15 19-3-3-3 3`}],[`path`,{d:`m15 5-3 3-3-3`}]],se=[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`}]],ce=[[`path`,{d:`M15 6a9 9 0 0 0-9 9V3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`}],[`circle`,{cx:`6`,cy:`18`,r:`3`}]],v=[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}],[`path`,{d:`M3 3v5h5`}]],y=e=>{let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`},le=e=>[e.subject,e.body,[[e.author,e.email?`<${e.email}>`:``].filter(Boolean).join(` `),e.at?y(e.at):``].filter(Boolean).join(` · `)].filter(Boolean).join(`
|
|
2
2
|
|
|
3
3
|
`),b=null;function x(){b&&(b.remove(),b=null,document.removeEventListener(`pointerdown`,x,!0),window.removeEventListener(`scroll`,x,!0))}function ue(e,t){e.onmouseenter=()=>{x();let n=t();if(!n)return;b=a(`div`,`pointer-events-none fixed z-50 max-w-96 whitespace-pre-wrap rounded-lg bg-neutral-800/95 px-3 py-2 font-sans text-[11.5px] leading-snug text-neutral-100 shadow-lg`),b.textContent=n,document.body.append(b),document.addEventListener(`pointerdown`,x,!0),window.addEventListener(`scroll`,x,!0);let r=e.getBoundingClientRect();b.style.left=`${Math.max(8,Math.min(r.left,window.innerWidth-b.offsetWidth-8))}px`,b.style.top=r.bottom+6+b.offsetHeight>window.innerHeight?`${r.top-b.offsetHeight-6}px`:`${r.bottom+6}px`},e.onmouseleave=x}function S(e,t,n){let r=a(`button`,`flex w-full cursor-pointer items-center gap-1.5 px-2 py-1 text-left hover:bg-neutral-100`,c(ee,`h-3 w-3 text-indigo-600 ${e.value===t?``:`invisible`}`),a(`span`,`inline-flex flex-none items-center gap-1.5 font-mono text-[11.5px] text-neutral-800`,e.label??e.value));return e.subject&&r.append(a(`span`,`min-w-0 truncate text-[11px] text-neutral-400`,e.subject)),e.author&&r.append(a(`span`,`ml-auto flex-none pl-1.5 text-[10.5px] text-neutral-400`,`${e.author} · ${e.at?o(e.at):``}`)),ue(r,()=>le(e)),r.onclick=()=>n(e.value),r}function de(e,t,n,r,i){let{base:o,head:s}=n,u=()=>s&&o===`${s}~1`?s:``,d=u()?`commit`:`compare`,f=t.commits[0],p=e=>[...e?[{value:``,label:`Working tree`,subject:`the files on disk, uncommitted changes included`}]:[],{...f,value:`HEAD`},...t.refs.map(e=>({value:e.name,subject:e.subject})),...t.commits.map(e=>({...e,value:e.hash}))],m=a(`div`,`flex w-[38rem] max-w-full flex-col`);function h(){let e=(e,t)=>{let n=a(`button`,`cursor-pointer rounded-full px-2.5 py-0.5 text-[11.5px] ${d===t?`bg-indigo-50 font-medium text-indigo-700`:`text-neutral-500 hover:bg-neutral-100`}`,e);return n.onclick=()=>{d=t,h()},n},n=(e,t,n,r)=>a(`div`,`flex min-w-0 flex-1 flex-col`,a(`div`,`flex-none px-2 pb-0.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),a(`div`,`min-h-0 flex-1 overflow-y-auto`,...t.map(e=>S(e,n,r)))),l=d===`compare`?a(`div`,`flex h-72 min-h-0 divide-x divide-neutral-200 pb-1`,n(`base`,p(!1),o,e=>{o=e,h(),r(o,s)}),n(`to`,p(!0),s,e=>{s=e,h(),r(o,s)})):a(`div`,`flex h-72 min-h-0 flex-col overflow-y-auto pb-1`,...t.commits.map(e=>S({value:e.hash,...e},u(),e=>{o=`${e}~1`,s=e,te(),r(o,s)}))),f=a(`div`,`flex-none border-t border-neutral-200`,S({value:i,label:`${i} ↔ Working tree`,subject:`back to the default: the main line's tip vs the files on disk`},o===i&&s===``?i:``,()=>{o=i,s=``,h(),r(o,s)}));f.querySelector(`button > span`).prepend(c(v)),m.replaceChildren(a(`div`,`flex flex-none items-center gap-1 border-b border-neutral-200 px-2 py-1.5`,e(`Compare two points`,`compare`),e(`One commit`,`commit`)),l,...d===`compare`?[f]:[])}h(),l(e,m)}var fe=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,C={A:`text-emerald-600`,M:`text-amber-600`,D:`text-red-600`},pe=30,w=`pier.filesPrefs`,T=50,E=()=>{try{let e=JSON.parse(localStorage.getItem(w)??`{}`);return e&&typeof e==`object`?e:{}}catch{return{}}},me=e=>{let t=e?E()[e]:void 0;return typeof t?.cwd==`string`&&typeof t.base==`string`&&typeof t.head==`string`?{cwd:t.cwd,base:t.base,head:t.head}:null},he=(e,t)=>{let n=E();delete n[e],n[e]=t;let r=Object.keys(n);for(let e of r.slice(0,Math.max(0,r.length-T)))delete n[e];try{localStorage.setItem(w,JSON.stringify(n))}catch(e){console.warn(`Files: could not remember this folder`,e)}},ge=`flex min-w-0 flex-none items-center gap-1.5 rounded-full px-2.5 py-1 font-mono text-[11.5px]`,_e=(e,t=`indigo`)=>re(e,`${ge} cursor-pointer truncate text-left ${t===`indigo`?`bg-indigo-50 font-medium text-indigo-700 hover:bg-indigo-100`:`bg-neutral-100 text-neutral-600 hover:bg-neutral-200`}`);function D(o,l,ee,te){let v=``,y=``,b={branch:null,refs:[],commits:[],worktrees:[]},x=`HEAD`,S=``,w=new Map,T=!0,E=!1,D=[],O=new Set,k=null,A=null,j=null,ve=a(`header`,`pagehead flex-nowrap`),M=a(`div`,`${u} flex-col items-stretch gap-1.5 px-3 py-2.5`),N=a(`div`,`min-h-0 flex-1 overflow-y-auto px-1.5 py-1.5`),ye=a(`aside`,`${ie} w-64 flex-none text-[12.5px] leading-5 max-md:h-1/2 max-md:w-full`,M,N),P=a(`div`,`${u} flex-wrap gap-2 px-4 py-2.5 font-mono text-[11.5px] text-neutral-500`),F=a(`div`,`h-full min-w-0 overflow-auto`),I=a(`div`,`pointer-events-none absolute inset-y-1 right-0.5 z-20 hidden w-2`),be=a(`div`,`relative min-h-0 flex-1`,F,I),xe=a(`section`,`${ie} min-h-0 min-w-0 flex-1`,P,be);o.append(ve,a(`div`,`flex min-h-0 flex-1 gap-3 px-4 pb-4 pt-1 max-md:flex-col`,ye,xe));let L=(e,t)=>`/api/explorer/${e}?${new URLSearchParams({root:v,...t})}`,R=(e,t)=>`/api/fs/${e}?${new URLSearchParams({root:v,...t})}`,z=(e,t=`text-neutral-400`)=>a(`p`,`px-3 py-2 text-[12.5px] ${t}`,e),B=e=>a(`div`,`flex h-full items-center justify-center p-6`,i(e)),Se=()=>T&&b.branch!==null,Ce=e=>{let t=0;for(let n of w.keys())n.startsWith(`${e}/`)&&t++;return t};function we(e,t){let n=new Set(t.map(e=>e.name)),r=e?`${e}/`:``;for(let[e,i]of w){if(i.status!==`D`||!e.startsWith(r))continue;let a=e.slice(r.length).split(`/`)[0];n.has(a)||(n.add(a),t.push({name:a,dir:e.slice(r.length).includes(`/`)}))}let i=t;return Se()&&(i=t.filter(e=>e.dir?Ce(`${r}${e.name}`)>0:w.has(`${r}${e.name}`))),i.sort((e,t)=>Number(t.dir)-Number(e.dir)||e.name.localeCompare(t.name)),i.map(e=>e.dir?Ee(`${r}${e.name}`,e.name):De(`${r}${e.name}`,e.name))}async function Te(e,t){try{let{entries:n}=await g(R(`ls`,{path:t}),`could not list this folder`);e.replaceChildren(...we(t,n)),e.childElementCount||e.append(z(Se()?`No changes.`:`Empty.`))}catch(n){let r=we(t,[]);r.length?e.replaceChildren(...r):e.replaceChildren(z(String(n),`text-red-600`))}}function Ee(e,n){let r=Ce(e),i=[a(`span`,`truncate`,n)];r&&i.push(a(`span`,`ml-auto flex-none rounded-full bg-amber-100/80 px-1.5 font-mono text-[10px] font-semibold text-amber-700`,String(r)));let{el:o,summary:s}=t(``,i);s.className+=` rounded-lg px-2 py-1 transition-colors hover:bg-neutral-100`;let c=a(`div`,`pl-3`);o.append(c);let l=!1,u=()=>{l||(l=!0,c.append(z(`…`)),Te(c,e))};return o.ontoggle=()=>{O[o.open?`add`:`delete`](e),o.open&&u()},((b.branch?T:!e.includes(`/`))&&!E||O.has(e))&&(o.open=!0,u()),o}function V(e){A?.classList.remove(`bg-indigo-50`,`font-medium`,`text-indigo-700`),A=e,e.classList.add(`bg-indigo-50`,`font-medium`,`text-indigo-700`)}function De(e,t){let n=w.get(e)?.status,r=a(`button`,`flex w-full cursor-pointer items-center gap-1.5 rounded-lg py-1 pl-6 pr-2 text-left transition-colors hover:bg-neutral-100`,a(`span`,`truncate`,t));return n&&r.append(a(`span`,`ml-auto flex-none font-mono text-[10.5px] font-semibold ${C[n]??`text-neutral-500`}`,n)),r.title=e,e===k&&V(r),e===j&&(j=null,k=e,V(r),J(e)),r.onclick=()=>{V(r),k=e,J(e)},r}let H=()=>void Te(N,``),U=(e,t)=>[...e?[a(`span`,`flex-none font-mono text-[10.5px] font-semibold text-emerald-600`,`+${e}`)]:[],...t?[a(`span`,`flex-none font-mono text-[10.5px] font-semibold text-red-600`,`−${t}`)]:[]];function W(t,n=!1,r){if(P.classList.toggle(`hidden`,!t),P.classList.toggle(`flex`,!!t),!t)return P.replaceChildren();let i=w.get(t),o=[a(`span`,`min-w-0 truncate`,t)];i&&(o.push(a(`span`,`flex-none font-semibold ${C[i.status]??``}`,i.status)),o.push(...U(i.add,i.del)));let s=a(`div`,`ml-auto flex flex-none items-center gap-2`);if(r&&s.append(r),n){let n=document.createElement(`a`);n.className=`btn flex-none text-[12px]`,n.href=R(`file`,{path:t}),n.download=e(t),n.textContent=`Download`,s.append(n)}P.replaceChildren(...o,s)}function Oe(e){let t=0;for(;t<e.length;){if(e[t].tone!==`del`){t++;continue}let n=t;for(;t<e.length&&e[t].tone===`del`;)t++;let r=t;for(;t<e.length&&e[t].tone===`add`;)t++;let i=Math.min(r-n,t-r);for(let t=0;t<i;t++){let i=e[n+t],a=e[r+t],o=Math.min(i.text.length,a.text.length),s=0;for(;s<o&&i.text[s]===a.text[s];)s++;let c=0;for(;c<o-s&&i.text[i.text.length-1-c]===a.text[a.text.length-1-c];)c++;s+c!==0&&(i.mark=[s,i.text.length-c],a.mark=[s,a.text.length-c])}}}let G=Ie();function K(){I.classList.add(`hidden`),I.replaceChildren(),G.set([],[])}let ke=0,q=e=>e===ke;function J(e){let t=++ke;return w.has(e)?Le(e,t):Ae(e,t)}async function Ae(e,t){if(!q(t))return;K();let n=R(`file`,{path:e}),r=a(`div`,`min-w-0`);if(F.classList.remove(`flex`,`flex-col`),W(e,!0),F.replaceChildren(r),fe.test(e)){let e=a(`img`,`max-w-full p-4`);e.src=n,e.onerror=()=>r.replaceChildren(z(`Could not load image.`,`text-red-600`)),r.append(e);return}if(e.toLowerCase().endsWith(`.pdf`)){let e=document.createElement(`iframe`);e.className=`h-full w-full`,e.src=n,F.replaceChildren(e),F.classList.add(`flex`,`flex-col`);return}r.append(z(`…`));let i=await fetch(n);if(!q(t))return;if(!i.ok){let{error:e}=await i.json().catch(()=>({}));r.replaceChildren(z(e??`HTTP ${i.status}`,`text-red-600`));return}if(!(i.headers.get(`content-type`)??``).startsWith(`text/plain`)){r.replaceChildren(z(`Binary file — use Download.`));return}let o=h(await i.text());if(!q(t))return;let s=await d(e);q(t)&&r.replaceChildren(_(o,s))}function je(e){let t=[],n=0,r=0,i=!1,a=e.split(`
|
|
4
4
|
`);a.at(-1)===``&&a.pop();for(let e of a){let a=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);if(a){i&&t.push({nums:[``,``],text:`⋯`,tone:``}),[n,r]=[Number(a[1]),Number(a[2])],i=!0;continue}!i||e.startsWith(`\\`)||(e.startsWith(`+`)?t.push({nums:[``,r++],text:e.slice(1),tone:`add`}):e.startsWith(`-`)?t.push({nums:[n++,``],text:e.slice(1),tone:`del`}):t.push({nums:[n++,r++],text:e.slice(1),tone:``}))}return t}function Me(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].tone;if(!r)continue;let i=t.at(-1);i&&i.end===n-1?(i.end=n,(r===`add`&&i.tone===`del`||r===`del`&&i.tone===`add`)&&(i.tone=`mixed`)):t.push({start:n,end:n,tone:r})}return t}let Ne={add:`bg-emerald-400`,del:`bg-red-400`,mixed:`bg-amber-400`};function Pe(e,t,n){I.replaceChildren(...e.map(e=>{let r=a(`button`,`map-mark pointer-events-auto absolute left-1/2 w-1 -translate-x-1/2 cursor-pointer rounded-full ${Ne[e.tone]}`);return r.style.top=`${e.start/t*100}%`,r.style.height=`${Math.max(.4,(e.end-e.start+1)/t*100)}%`,r.title=`line ${Fe(n,e.start)}`,r.onclick=()=>n[e.start].scrollIntoView({block:`center`}),r})),I.classList.remove(`hidden`)}let Fe=(e,t)=>e[t]?.querySelector(`span`)?.textContent?.trim()||String(t+1);function Ie(){let e=[],t=[],n=-1,r=a(`span`,`flex-none text-[10.5px] text-neutral-400`),i=i=>{e.length&&(n=(n+i+e.length)%e.length,t[e[n].start].scrollIntoView({block:`center`}),r.textContent=`${n+1}/${e.length}`)},l=()=>e.length>0&&!o.classList.contains(`hidden`),u=(e,t,n,r)=>{let o=a(`button`,`icon-btn flex-none`,c(e));return o.onclick=()=>i(t),s(o,r,n,()=>i(t),l),o};return{el:a(`div`,`flex flex-none items-center gap-1`,r,u(f,-1,`Previous change`,[`p`,`k`]),u(ae,1,`Next change`,[`n`,`j`])),set(i,a){e=i,t=a,n=-1,r.textContent=`${i.length} change${i.length===1?``:`s`}`}}}async function Le(e,t){K(),F.classList.remove(`flex`,`flex-col`);let n=w.get(e)?.status!==`D`;W(e,n),F.replaceChildren(z(`…`));try{let{diff:r}=await g(L(`diff`,{base:x,head:S,file:e,context:`99999`}),`could not read this diff`);if(!q(t))return;if(!r||/^Binary files /m.test(r))return Ae(e,t);let i=je(r);Oe(i);let a=await d(e);if(!q(t))return;let o=_(i,a),s=[...o.children],c=Me(i);G.set(c,s),W(e,n,G.el),F.replaceChildren(o),Pe(c,i.length,s)}catch(n){if(!q(t))return;W(e),F.replaceChildren(z(String(n),`text-red-600`))}}let Y=()=>S&&x===`${S}~1`?S:``,Re=()=>b.commits.find(e=>e.hash===Y())?.subject??``,ze=()=>Y()?`${Y()} — ${Re()||`commit`}`:`${x} ↔ ${S||`working tree`}`,Be=(e,t,n,r)=>{let i=a(`button`,`icon-btn ${n?`bg-indigo-50 text-indigo-700 hover:bg-indigo-100 hover:text-indigo-700`:``}`);return i.append(c(e)),i.title=t,i.setAttribute(`aria-label`,t),i.setAttribute(`aria-pressed`,String(n)),i.onclick=r,i};function X(){let e=Be(se,`Show only files that differ`,T,()=>{T=!T,X(),H()}),t=Be(oe,E?`Restore folders`:`Collapse all folders`,E,()=>{if(E=!E,E)D=[...O],O.clear();else for(let e of D)O.add(e);X(),H()});if(!b.branch){M.replaceChildren(a(`div`,`flex items-center gap-1.5`,a(`span`,`min-w-0 flex-1 text-[11px] leading-snug text-neutral-400`,`Not a git repository — nothing to compare.`),t));return}let n=re(ze(),`${ne} font-mono`);if(Y()){let e=b.commits.find(e=>e.hash===Y());ue(n,()=>e?le(e):``)}else n.title=`Choose what to diff`;n.onclick=async()=>{await We(),de(n,b,{base:x,head:S},(e,t)=>{x=e,S=t,Z()},$())};let[r,i]=[0,0];for(let e of w.values())r+=e.add,i+=e.del;M.replaceChildren(n,a(`div`,`flex items-center gap-1.5 pl-0.5`,a(`span`,`text-[11px] text-neutral-400`,`${w.size} changed file${w.size===1?``:`s`}`),...U(r,i),a(`span`,`ml-auto`),e,t))}let Ve=()=>{y&&v&&he(y,{cwd:v,base:x,head:S})},He=e=>{let t=e.replace(/~\d+$/,``);return!t||t===`HEAD`||b.refs.some(e=>e.name===t)||b.commits.some(e=>e.hash===t)};async function Ue(){if(w=new Map,!b.branch)return;let{files:e}=await g(L(`diff`,{base:x,head:S}),`could not read what changed`);for(let t of e)w.set(t.path,{status:t.status,add:t.add,del:t.del});if(w.size<=pe)for(let e of w.keys()){let t=e.split(`/`);for(let e=1;e<t.length;e++)O.add(t.slice(0,e).join(`/`))}}async function Z(){Ve();try{await Ue()}catch(e){X(),N.replaceChildren(z(String(e),`text-red-600`));return}X(),H(),k&&J(k)}function Q(){let t=_e(``,`neutral`);t.className+=` max-w-72`,t.append(a(`span`,`truncate max-md:hidden`,v||`Choose a folder…`),a(`span`,`truncate md:hidden`,v?e(v):`Choose a folder…`)),t.title=v?`${v} — switch folder`:`Choose a folder`,t.onclick=()=>p(t,b.worktrees.map(e=>({path:e.path,...e.branch?{hint:e.branch}:{}})),v||void 0,ee);let n=a(`button`,`icon-btn ml-auto`,c(m));n.type=`button`,n.title=`Close Files`,n.setAttribute(`aria-label`,`Close Files`),n.onclick=te;let i=b.branch?[a(`span`,`${ge} bg-neutral-100 text-neutral-600`,c(ce),a(`span`,`truncate`,b.branch))]:[];ve.replaceChildren(r(`Files`),t,...i,n)}async function We(){if(v)try{b=await g(L(`git`,{}),`could not read this repository`),Q()}catch(e){F.replaceChildren(B(String(e)))}}let $=()=>b.refs.some(e=>e.name===`main`)?`main`:b.refs.some(e=>e.name===`master`)?`master`:`HEAD`;async function Ge(e){if(Q(),k=null,A=null,O.clear(),j=e||null,e){T=!1;let t=e.split(`/`);for(let e=1;e<t.length;e++)O.add(t.slice(0,e).join(`/`))}if(K(),F.classList.remove(`flex`,`flex-col`),W(),F.replaceChildren(B(`Select a file.`)),!v){M.replaceChildren(),N.replaceChildren(),F.replaceChildren(B(`No folder yet — pick one from the chip above.`));return}try{b=await g(L(`git`,{}),`could not read this repository`)}catch(e){b={branch:null,refs:[],commits:[],worktrees:[]},F.replaceChildren(B(String(e)))}let t=me(y),n=t&&t.cwd===v&&He(t.base)&&He(t.head)?t:null;x=n?.base??$(),S=n?.head??``,Q(),await Z()}return n(o,(e,t)=>{let n=l(),r=n?.id??``,i=new URLSearchParams(t).get(`select`)??void 0,a=e?.startsWith(`/`)?e:(r===y?v:``)||me(r)?.cwd||n?.cwd||``;if(a===v&&r===y&&N.childElementCount&&(!i||i===k)){Q(),We().then(Z);return}y=r,v=a,Ge(i)},()=>{K(),F.classList.remove(`flex`,`flex-col`),W(),F.replaceChildren(B(`Select a file.`))})}export{D as createExplorerView};
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/tasks-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/tasks-Bz29caHJ.js","assets/task-runs-0pvdITiV.js","assets/runs-C_AthWcW.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},t=([e,n,r])=>{let i=document.createElementNS(`http://www.w3.org/2000/svg`,e);return Object.keys(n).forEach(e=>{i.setAttribute(e,String(n[e]))}),r?.length&&r.forEach(e=>{let n=t(e);i.appendChild(n)}),i},n=(n,r={})=>t([`svg`,{...e,...r},n]),r=[[`path`,{d:`m12 19-7-7 7-7`}],[`path`,{d:`M19 12H5`}]],i=[[`path`,{d:`M7 7h10v10`}],[`path`,{d:`M7 17 17 7`}]],a=[[`path`,{d:`m5 12 7-7 7 7`}],[`path`,{d:`M12 19V5`}]],o=[[`path`,{d:`M20 6 9 17l-5-5`}]],s=[[`path`,{d:`m6 9 6 6 6-6`}]],c=[[`path`,{d:`m15 18-6-6 6-6`}]],l=[[`path`,{d:`m9 18 6-6-6-6`}]],u=[[`circle`,{cx:`12`,cy:`12`,r:`10`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`}],[`path`,{d:`M12 17h.01`}]],d=[[`circle`,{cx:`12`,cy:`12`,r:`10`}],[`path`,{d:`M12 6v6l4 2`}]],f=[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`}],[`path`,{d:`m9 10-5 5 5 5`}]],p=[[`path`,{d:`M12 15V3`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}],[`path`,{d:`m7 10 5 5 5-5`}]],m=[[`circle`,{cx:`12`,cy:`12`,r:`1`}],[`circle`,{cx:`19`,cy:`12`,r:`1`}],[`circle`,{cx:`5`,cy:`12`,r:`1`}]],ee=[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]],te=[[`path`,{d:`M12 10v6`}],[`path`,{d:`M9 13h6`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`}]],ne=[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`}]],re=[[`path`,{d:`M13 5h8`}],[`path`,{d:`M13 12h8`}],[`path`,{d:`M13 19h8`}],[`path`,{d:`m3 17 2 2 4-4`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`}]],h=[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`}]],ie=[[`path`,{d:`M4 5h16`}],[`path`,{d:`M4 12h16`}],[`path`,{d:`M4 19h16`}]],ae=[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`}]],oe=[[`path`,{d:`M5 12h14`}]],se=[[`rect`,{width:`20`,height:`14`,x:`2`,y:`3`,rx:`2`}],[`line`,{x1:`8`,x2:`16`,y1:`21`,y2:`21`}],[`line`,{x1:`12`,x2:`12`,y1:`17`,y2:`21`}]],g=[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`}]],ce=[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`}]],le=[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`}],[`path`,{d:`m15 5 4 4`}]],ue=[[`path`,{d:`M5 12h14`}],[`path`,{d:`M12 5v14`}]],de=[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`}],[`path`,{d:`M21 3v5h-5`}]],fe=[[`path`,{d:`m21 21-4.34-4.34`}],[`circle`,{cx:`11`,cy:`11`,r:`8`}]],pe=[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]],me=[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}]],he=[[`circle`,{cx:`12`,cy:`12`,r:`4`}],[`path`,{d:`M12 2v2`}],[`path`,{d:`M12 20v2`}],[`path`,{d:`m4.93 4.93 1.41 1.41`}],[`path`,{d:`m17.66 17.66 1.41 1.41`}],[`path`,{d:`M2 12h2`}],[`path`,{d:`M20 12h2`}],[`path`,{d:`m6.34 17.66-1.41 1.41`}],[`path`,{d:`m19.07 4.93-1.41 1.41`}]],ge=[[`path`,{d:`M9 14 4 9l5-5`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`}]],_e=[[`path`,{d:`M18 6 6 18`}],[`path`,{d:`m6 6 12 12`}]],_=(e,t=`h-3.5 w-3.5`)=>n(e,{class:`flex-none ${t}`,"aria-hidden":`true`,focusable:`false`});function ve(){let e={ArrowUp:a,ChevronLeft:c,ChevronRight:l,Clock:d,Ellipsis:m,LayoutDashboard:ne,ListTodo:re,Menu:ie,Plus:ue,RotateCw:de,Search:fe,Settings:pe,Square:me,Undo2:ge,X:_e};for(let t of document.querySelectorAll(`[data-icon]`)){let n=e[t.dataset.icon];if(!n)throw Error(`Unknown shell icon: ${t.dataset.icon}`);t.replaceChildren(_(n,`h-full w-full`))}let t=_(s);t.setAttribute(`stroke`,`#737373`),document.documentElement.style.setProperty(`--select-chevron`,`url("data:image/svg+xml,${encodeURIComponent(t.outerHTML)}")`)}var ye=/[\u201c\u201d"\u2018\u2019'()\uff08\uff09\u300c\u300d\u300e\u300f\u3010\u3011\u300a\u300b\u3008\u3009[\]]/;function be(e){let t=[],n=e=>`\uE010${t.push(e)-1}\uE011`,r=e.replace(/```[\s\S]*?```/g,e=>n(e)).replace(/`[^`\n]+`/g,e=>n(e));return r=r.replace(/\*\*(\S|\S[\s\S]*?\S)\*\*/g,(e,t)=>{let n=``,r=``,i=t;for(;i.length>1&&ye.test(i[0]);)n+=i[0],i=i.slice(1);for(;i.length>1&&ye.test(i.at(-1));)r=i.at(-1)+r,i=i.slice(0,-1);return n||r?`${n}**${i}**${r}`:e}),r.replace(/\uE010(\d+)\uE011/g,(e,n)=>t[Number(n)]??``)}var v=e=>!e.text.trim()&&e.suggestions.length===0,xe=e=>e===`xhigh`?`Extra high`:e[0].toUpperCase()+e.slice(1),Se=e=>{if(e<1e3)return String(e);let t=e/1e3;return t>=9.95?`${Math.round(t)}K`:`${t.toFixed(1)}K`},Ce=/(?:^|\n)[ \t]*-{3,}[ \t]*\r?\n((?:[ \t]*\[[^\]\r\n]+\][ \t]*(?:[||][ \t]*)?)+)\s*$/,we=/\[([^\]\r\n]+)\]/g,Te=5,Ee=String.raw`[\u200B-\u200D\u2060\uFEFF]*`,De=e=>e.split(``).join(Ee),Oe=RegExp(`${De(`<silent>`)}([\\s\\S]*?)${De(`</silent>`)}`,`gi`),ke=RegExp(`<(\\/?)${De(`silent>`)}`,`gi`);function y(e){let t=[...e.matchAll(Oe)].map(e=>(e[1]??``).trim()).filter(Boolean);return t.length?t.join(` · `):void 0}function Ae(e,t){let n=b(e),r=y(e),i=Ce.exec(n);if(!i?.[1])return{text:n,suggestions:[],meta:t,silence:r};let a=[...i[1].matchAll(we)].map(e=>(e[1]??``).trim()).filter(Boolean).slice(0,Te);return a.length?{text:n.slice(0,i.index).trimEnd(),suggestions:a,meta:t,silence:r}:{text:n,suggestions:[],meta:t,silence:r}}var b=e=>be(e.replace(Oe,``).trim()),je=/^(?:\s|[-*+>]|\d+[.)])/;function Me(e,t=0){let n=e.lastIndexOf(`
|
|
3
3
|
`)+1,r=``,i=!1,a=t,o=-1,s=``;for(let c=t;c<n;){let t=e.indexOf(`
|
|
4
4
|
`,c),n=e.slice(c,t);c=t+1;let l=/^\s*(`{3,}|~{3,})(.*)$/.exec(n);if(!r&&!i&&!n.trim()){o<0&&s&&(o=c);continue}!r&&!i&&o>=0&&!(je.test(s)&&je.test(n))&&(a=o);let u=l?.[1]??``;if(!r&&u&&!i?r=u:r&&u[0]===r[0]&&u.length>=r.length&&!l?.[2]?.trim()&&(r=``),!r&&(!u||i))for(let e of n.matchAll(ke))i=!e[1];o=-1,s=n}return a}var Ne=String.raw`(?<when>(?:\d{4}-\d{2}-\d{2} )?\d{1,2}:\d{2})`,Pe=new RegExp(String.raw`^\[(?:(?<name>[^\n[\]<>]*)<(?<id>[^\n[\]<>]+)>)? ?${Ne}? ?(?<where>[a-z]+:[^\s[\]<>]+)?\]\n`),Fe=new RegExp(String.raw`^\[(?<name>[^\n[\]<>]*?) ${Ne}(?: (?<where>[a-z]+))?\]\n`);function Ie(e){let t=Pe.exec(e),{id:n,when:r,where:i}=t?.groups??{},a=n||r||i?t:Fe.exec(e);return a?.groups?{...a.groups.name?{name:a.groups.name}:{},...a.groups.id?{id:a.groups.id}:{},...a.groups.when?{when:a.groups.when}:{},...a.groups.where?{where:a.groups.where}:{},text:e.slice(a[0].length)}:{text:e}}var Le=/(?:\n\[[^\]\n]*(?:\]\(\s*<?file:\/\/[^\n]*|$))+$/,Re=/^\s*`[^`\n]{40,}`\s+(\S[\s\S]*)$/;function ze(e){if(!e)return e;let{text:t}=Ie(e);return t===e?e:t.replace(Le,``).replace(Re,`$1`).replace(/\s+/g,` `).trim()||e}var Be=e=>[...new Set([...e].sort((e,t)=>t.createdAt-e.createdAt).map(e=>e.cwd))];function Ve(e){let t=Be(e),n=new Set(t);return t.filter(e=>{let t=e.lastIndexOf(`/`),r=e.indexOf(`.`,t+2);return r<0||!n.has(e.slice(0,r))})}function He(e){let t,n=!1;return()=>(n=!0,t??=(async()=>{for(;n;)n=!1,await e()})().finally(()=>{t=void 0}))}var Ue=(e,t)=>({method:t,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),x=(e,t,n=`POST`)=>fetch(e,Ue(t,n)),We=(e,t,n,r=`POST`)=>C(e,n,Ue(t,r));async function S(e,t){return(await e.json().catch(()=>({}))).error??`${t} (${e.status})`}async function C(e,t,n){let r;try{r=await fetch(e,n)}catch(e){return{ok:!1,error:`${t}: ${String(e)}`}}if(!r.ok)return{ok:!1,error:await S(r,t)};try{return{ok:!0,value:await r.json()}}catch(e){return{ok:!1,error:`${t}: ${String(e)}`}}}async function Ge(e,t,n){let r=await C(e,t,n);if(!r.ok)throw Error(r.error);return r.value}async function Ke(e,t,n){try{let r=await fetch(e,{method:t});return r.ok?void 0:await S(r,n)}catch(e){return`${n}: ${String(e)}`}}function qe(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Je(e){if(Array.isArray(e))return e}function Ye(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Xe(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
@@ -82,4 +82,4 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
|
|
|
82
82
|
`),o=K.sessionState()===`idle`&&e===`auto`;o?K.setState(`streaming`):Tl(),(o||e===`steer`)&&(Cl(a),W(`user`,a,!1,Date.now()),Is(!0));let s=await x(`/api/sessions/${i}/messages`,{text:a,mode:e});if(!s.ok){let e=await S(s,`send failed`);await K.reload(i),W(`error`,e)}}finally{t===void 0&&(Hl=!1)}}}async function Wl(e){let t=K.sessionId();if(!t)return;Ol([],[]);let n=await x(`/api/sessions/${t}/queue/deliver`,{mode:e});if(!n.ok){let r=await S(n,`Queue ${e} failed`);await K.reload(t),K.sessionId()===t&&W(`error`,r)}}async function Gl(){let e=K.sessionId();if(!e||gl.has(e))return;gl.add(e);let t=hl,n=Il,r=document.activeElement;try{zl();let i=await fetch(`/api/sessions/${e}/queue/recall`,{method:`POST`});if(!i.ok){let t=await S(i,`Could not recall queued messages`);K.sessionId()===e&&W(`error`,t);return}let{messages:a}=await i.json(),o=K.sessionId()===e;if(a.length)try{let t=o?q.value:sessionStorage.getItem(Fl(e))??``,i=(t?[t,...a]:a).join(`
|
|
83
83
|
`);o&&(q.value=i,Vl(),n===Il&&K.chatVisible()&&document.activeElement===r&&q.focus()),zl(e,i)}catch(t){W(`error`,`Could not save recalled messages for session ${e}: ${String(t)}\nRecalled messages (not saved):\n${a.join(`
|
|
84
84
|
`)}`)}o&&t===hl&&Ol([],[])}finally{gl.delete(e)}}function Kl(e){K=e,Ll(),yl(),bl();let t=()=>{let e=K.sessionId();e&&fetch(`/api/sessions/${e}/abort`,{method:`POST`})};sl.onclick=t,$c(sl,`Stop the running turn`,t,()=>K.sessionState()===`streaming`&&K.chatVisible()),F(`#queue-steer`).onclick=()=>void Wl(`steer`),F(`#queue-restart`).onclick=()=>void Wl(`restart`),F(`#queue-recall`).onclick=()=>void Gl(),rl.onsubmit=e=>{e.preventDefault(),Ul(`auto`)},tl(q,[`/`],`Write a message`,xl,K.chatVisible),q.onfocus=Fs,q.oninput=()=>{Vl(),zl()};let n=!matchMedia(`(pointer: coarse)`).matches;q.onkeydown=e=>{e.isComposing||e.keyCode===229||n&&e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ul(`auto`))},q.onpaste=e=>{for(let t of e.clipboardData?.items??[]){let e=t.kind===`file`?t.getAsFile():null;e&&jl(e)}let t=e.clipboardData?.getData(`text/plain`)??``,n=t.trim();!n||n===t||(e.preventDefault(),q.setRangeText(n,q.selectionStart??0,q.selectionEnd??0,`end`),Vl(),zl())},U.ondragover=e=>e.preventDefault(),U.ondrop=e=>{e.preventDefault();for(let t of e.dataTransfer?.files??[])jl(t)},F(`#attach`).onclick=()=>pl.click(),pl.onchange=()=>{for(let e of pl.files??[])jl(e);pl.value=``},Tl()}var ql=`pier.push`,Jl=`/app/sw.js`,Yl=()=>/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.maxTouchPoints>1&&/Macintosh/.test(navigator.userAgent),Xl=()=>matchMedia(`(display-mode: standalone)`).matches||navigator.standalone===!0;function Zl(){return window.isSecureContext?Yl()&&!Xl()?`On iPhone and iPad, notifications work only from the installed app: Share → Add to Home Screen, then open Pier from that icon.`:!(`serviceWorker`in navigator)||!(`PushManager`in window)||!(`Notification`in window)?`This browser has no Web Push support.`:``:`Notifications need HTTPS. Reach this Pier through its public URL, not over plain http.`}var Ql=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/Macintosh/,`Mac`],[/Windows/,`Windows`]],$l=[[/Edg\//,`Edge`],[/Chrome\//,`Chrome`],[/Firefox\//,`Firefox`],[/Safari\//,`Safari`]];function eu(){let e=navigator.userAgent,t=(t,n)=>t.find(([t])=>t.test(e))?.[1]??n;return`${t(Ql,`Linux`)} · ${t($l,`browser`)}${Xl()?` (installed)`:``}`}var tu=e=>{let t=atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},nu=null;async function ru(){return!(`serviceWorker`in navigator)||!window.isSecureContext?null:(nu??=await navigator.serviceWorker.register(Jl,{scope:`/app/`}).catch(e=>(console.warn(`service worker registration failed`,e),null)),nu)}var iu=(e,t)=>{let n=e?new Uint8Array(e):null;return n?.length===t.length&&n.every((e,n)=>e===t[n])};async function au(e){let{publicKey:t}=await Ge(`/api/push`,`Could not read this instance's push key`),n=tu(t),r=await e.pushManager.getSubscription();if(r){if(iu(r.options.applicationServerKey,n))return r;await r.unsubscribe()}return e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:n})}async function ou(e){return x(`/api/push/subscribe`,{...e.toJSON(),label:eu()})}async function su(){uu();let e=await ru();if(!(!e||localStorage.getItem(ql)!==`on`)&&!(!(`Notification`in window)||Notification.permission!==`granted`))try{await ou(await au(e))}catch(e){console.warn(`re-registering this browser for notifications failed`,e)}}var cu=null,lu=null;function uu(){window.addEventListener(`beforeinstallprompt`,e=>{e.preventDefault(),cu=e,lu?.()}),window.addEventListener(`appinstalled`,()=>{cu=null,lu?.()})}function du(e){let t=navigator;(e>0?t.setAppBadge?.(e):t.clearAppBadge?.())?.catch(()=>{})}function fu(){let e=I(`span`,`text-[11.5px]`,``),t=di(`Send a test notification`),n=I(`div`,`flex items-center gap-3`,t,e),r=I(`div`,`flex flex-col gap-4`),i=()=>localStorage.getItem(ql)===`on`,a=I(`div`,`flex flex-col gap-2`),o=I(`span`,`text-[11.5px]`,``),s=I(`div`,`flex flex-col gap-2`,a,o);async function c(e){R(o,`saving`,`removing…`);try{let t=await x(`/api/push/unsubscribe`,{endpoint:e.endpoint});if(!t.ok)R(o,`failed`,await S(t,`Could not remove it`));else{let t=await(await ru())?.pushManager.getSubscription();t?.endpoint===e.endpoint&&(localStorage.setItem(ql,`off`),await t.unsubscribe(),p()),R(o,`saved`,`Removed.`)}}catch(e){R(o,`failed`,`Could not remove it: ${String(e)}`)}await l()}async function l(){let e=await C(`/api/push/subscriptions`,`Could not load subscribed devices`);if(!e.ok)return R(o,`failed`,e.error);if(!e.value.devices.length){a.replaceChildren(Pi(`No device is subscribed.`));return}a.replaceChildren(...e.value.devices.map(e=>{let t=di(`Remove`);return t.onclick=()=>{t.disabled=!0,c(e)},Ni(e.label,`subscribed ${Xr(e.createdAt)}`,t,{tag:e.current?ji(`This browser`,`bg-neutral-50 text-neutral-500 ring-neutral-200`):void 0})}))}async function u(){R(e,`saving`,`asking this browser…`);let t=await Notification.requestPermission();if(t!==`granted`)return localStorage.setItem(ql,`off`),p(),R(e,`failed`,t===`denied`?`Notifications are blocked for this site — allow them in the browser's site settings, then try again.`:`No answer to the permission prompt.`);let n=await ru();if(!n)return R(e,`failed`,`This browser refused to register a service worker.`);try{let t=await ou(await au(n));if(!t.ok)return R(e,`failed`,await S(t,`Could not register this browser`));localStorage.setItem(ql,`on`),p(),R(e,`saved`,`This browser will be notified when a turn finishes unseen.`),l()}catch(t){R(e,`failed`,`Could not subscribe: ${String(t)}`)}}async function d(){localStorage.setItem(ql,`off`),p();let t=await(await ru())?.pushManager.getSubscription();t&&(await x(`/api/push/unsubscribe`,{endpoint:t.endpoint}),await t.unsubscribe()),R(e,`idle`,`This browser will not be notified.`),l()}t.onclick=()=>{R(e,`saving`,`sending…`),(async()=>{let t=await x(`/api/push/test`,{});if(!t.ok)return R(e,`failed`,await S(t,`Could not send`));let{sent:n,failed:r}=await t.json();R(e,r?`failed`:`saved`,`Handed ${String(n)} device(s) to their push service${r?`, ${String(r)} refused`:``}.`)})()};function f(){if(!cu)return[];let e=di(`Install Pier`,!0);return e.onclick=()=>{let e=cu;e&&e.prompt().then(()=>e.userChoice).finally(()=>{cu=null,p()})},[I(`div`,`flex items-center gap-3`,e,I(`span`,`text-[11.5px] leading-snug text-neutral-500`,`Its own window and icon — and where notifications look like an app's.`))]}function p(){let e=Zl();if(e){r.replaceChildren(...f(),I(`p`,`text-[12.5px] leading-snug text-neutral-500`,e),s);return}let a=i()&&Notification.permission===`granted`;t.disabled=!a,r.replaceChildren(...f(),ki(`Notify this device`,`A turn that finishes while nobody is looking at it becomes a notification here. Per browser — each device is enabled on its own.`,a,e=>void(e?u():d())),n,s)}return lu=p,p(),{el:xi(`Notifications`,`Web Push, so a finished turn reaches you with the workbench closed. Installed — Chrome's address-bar icon, or Share → Add to Home Screen on iOS — Pier notifies you the way an app does.`,r),load:()=>{R(o,`idle`,``),l()}}}var J=F(`#sidebar`),pu=F(`#drawer-scrim`),mu=F(`#mobile-title`),hu=F(`#mobile-menu`),gu=F(`#session-meta`);function _u(){delete J.dataset.open,pu.classList.add(`hidden`),Tu()}function vu(e,t){mu.textContent=e,mu.classList.toggle(`cursor-pointer`,t),hu.classList.toggle(`hidden`,!t)}var yu=`pier.railClosed`;localStorage.getItem(yu)===`1`&&(document.body.dataset.rail=`closed`);function bu(e){document.body.dataset.rail=e?`closed`:``,localStorage.setItem(yu,e?`1`:`0`),Tu()}function xu(){if(J.dataset.open!==void 0)return _u();J.dataset.open=``,pu.classList.remove(`hidden`),Tu()}var Su=window.matchMedia(`(width < 48rem)`),Cu=()=>Su.matches;function wu(){Cu()?F(`#mobile-bar`).append(gu):F(`#chat-menu`).before(gu)}function Tu(){let e=Cu()&&J.dataset.open!==void 0,t=F(`main`);t.inert=e,J.inert=Cu()?!e:document.body.dataset.rail===`closed`,F(`#drawer-toggle`).setAttribute(`aria-expanded`,String(e)),e&&!J.contains(document.activeElement)&&F(`#new-session`).focus(),J.inert&&J.contains(document.activeElement)&&F(Cu()?`#drawer-toggle`:`#rail-toggle`).focus()}var Eu=[F(`#rail-toggle`),F(`#drawer-toggle`)],Du=`attention absolute -right-0.5 -top-0.5 rounded-full bg-amber-500`,Ou=e=>e===1?I(`span`,`${Du} h-2 w-2`):I(`span`,`${Du} flex h-3.5 min-w-3.5 items-center justify-center px-0.5 text-[9px] font-semibold text-white`,e>9?`9+`:String(e));function ku(e){for(let t of Eu)t.querySelector(`.attention`)?.remove(),e&&t.append(Ou(e))}var Au=20,ju=.35,Mu=8;function Nu(){let e=-1,t=0,n=!1,r=!1,i=1,a=e=>{J.style.transition=`none`,J.style.transform=`translateX(${String(e-i)}px)`,pu.style.transition=`none`,pu.classList.remove(`hidden`),pu.style.opacity=String(e/i)},o=t=>{J.style.transition=``,J.style.transform=``,pu.style.transition=``,pu.style.opacity=``,t?(J.dataset.open=``,pu.classList.remove(`hidden`),Tu()):_u(),e=-1,r=!1};window.addEventListener(`touchstart`,a=>{if(r||(e=-1,!Cu()||a.touches.length!==1))return;let o=a.touches[0],s=J.dataset.open!==void 0;if(i=J.offsetWidth||1,s){if(o.clientX>i)return}else{if(o.clientX>Au||a.target?.closest(`button, a, input, textarea, select`))return;a.preventDefault()}e=o.clientX,t=o.clientY,n=!s},{passive:!1}),window.addEventListener(`touchmove`,o=>{if(e<0)return;let s=o.touches[0],c=s.clientX-e;if(!r){if(Math.abs(s.clientY-t)>Math.abs(c))return void(e=-1);if(Math.abs(c)<Mu)return;r=!0}o.preventDefault(),a(Math.max(0,Math.min(i,n?c:i+c)))},{passive:!1});let s=()=>{if(e<0)return;if(!r)return void(e=-1);let t=J.getBoundingClientRect().right;o(n?t>i*ju:t>i*.65)};window.addEventListener(`touchend`,s),window.addEventListener(`touchcancel`,s)}function Pu(e){Nu(),Tu(),wu(),Su.addEventListener(`change`,()=>{_u(),wu()}),F(`#drawer-toggle`).setAttribute(`aria-controls`,`sidebar`),J.addEventListener(`keydown`,e=>{if(!(!Cu()||J.dataset.open===void 0||e.defaultPrevented||e.isComposing)){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),_u();else if(e.key===`Tab`){let t=[...J.querySelectorAll(`button, a[href], summary`)].filter(e=>e.getClientRects().length&&!e.matches(`:disabled`)),n=e.shiftKey?t.at(-1):t[0],r=e.shiftKey?t[0]:t.at(-1);document.activeElement===r&&(e.preventDefault(),n?.focus())}}}),F(`#drawer-toggle`).onclick=xu,pu.onclick=_u,hu.onclick=()=>e.sessionMenu(hu),mu.onclick=()=>{hu.classList.contains(`hidden`)||e.sessionInfo(mu)};let t=F(`#rail-toggle`);t.onclick=()=>bu(document.body.dataset.rail!==`closed`),Qc(t,`meta+b`,`Toggle sidebar`,()=>Cu()?xu():bu(document.body.dataset.rail!==`closed`))}var Y,Fu=F(`#session-list`),Iu=F(`#new-session`),Lu=e=>e.modified??e.createdAt;function Ru(e){return{top:e.filter(e=>e.rank!==void 0).sort((e,t)=>(e.rank??0)-(t.rank??0)),rest:e.filter(e=>e.rank===void 0).sort((e,t)=>t.createdAt-e.createdAt)}}function zu(e,t){let{top:n,rest:r}=Ru(e),i=[...n,...r].slice(0,t);return{rows:i,hidden:e.length-i.length}}function Bu(e,t,n){let{top:r,rest:i}=Ru(e),a=[...r,...i];if(!a.length)return;let o=a.findIndex(e=>e.id===t),s=o<0?a[0]:a[(o+n+a.length)%a.length];return s&&s.id!==t?s.id:void 0}var Vu=8,Hu=`session-more hidden h-7 w-7 flex-none cursor-pointer items-center justify-center rounded-lg text-neutral-400 hover:bg-neutral-200 hover:text-neutral-700`,Uu=e=>e.unread,Wu=e=>`${e} subagent${e>1?`s`:``} running`,Gu=e=>e.state===`streaming`||Uu(e)||e.activeRuns>0;function Ku(e){if(!Gu(e))return[];let t=e.state===`streaming`?[`bg-green-500 animate-pulse`,`working…`]:Uu(e)?[`bg-amber-500`,`turn finished — not viewed yet`]:[`bg-sky-500`,Wu(e.activeRuns)],n=I(`span`,`h-2 w-2 flex-none rounded-full ${t[0]}`);return n.title=t[1],[n]}async function qu(e){let t=window.prompt(`Session name — empty resets it to the first message`,e.title??``);if(t===null)return;let n=e.title,r=t=>{e.title=t,ed(),Y.onTitleChanged()};r(t.trim()||void 0),(await x(`/api/sessions/${e.id}/rename`,{name:t})).ok||r(n)}var Ju=`flex-none text-xs font-medium uppercase leading-5 text-neutral-500`,Yu=e=>e.channel&&e.channel!==`web`?[I(`span`,Ju,e.channel[0]??``)]:[];function Xu(e,t=I(`button`,Hu,_(m))){let n=e.id===Y.currentId(),r=I(`li`,`flex items-center gap-1 hover:bg-neutral-100 ${n?`bg-indigo-50 hover:bg-indigo-50`:``}`);t.setAttribute(`type`,`button`),t.setAttribute(`aria-label`,`Session actions: ${e.title??`untitled`}`),t.title=`Session actions`,t.onclick=n=>{n.stopPropagation(),Y.sessionMenu(t,e)};let i=I(`button`,`session-open flex min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-lg text-left`,I(`span`,`min-w-0 flex-1 truncate`,e.title??`untitled`),...Ku(e));return i.setAttribute(`type`,`button`),n&&i.setAttribute(`aria-current`,`page`),i.onclick=()=>Y.select(e.id),r.dataset.sessionId=e.id,r.append(i,...Yu(e),t),r.title=[e.cwd,`active ${Yr(Lu(e))} ago · created ${new Date(e.createdAt).toLocaleDateString()}`,...e.channel&&e.channel!==`web`?[`answering ${e.channel}`]:[]].join(`
|
|
85
|
-
`),r}var Zu=()=>`${Y.currentId()??``}\n${$u}\n${JSON.stringify(Y.sessions())}`,Qu=``,$u=20;function ed(){let e=Zu();if(e===Qu)return;Qu=e;let t=Y.sessions(),n=t.filter(Uu);ku(n.length),du(n.length);let{rows:r,hidden:i}=zu(t,$u),a=Fu.querySelector(`.session-more[aria-expanded='true']`),o=a?.closest(`[data-session-id]`)?.dataset.sessionId,s=r.map(e=>Xu(e,e.id===o?a:void 0));if(i>0){let e=I(`button`,`session-open w-full cursor-pointer rounded-lg text-left text-sm text-neutral-500`,`Load more (${i})`);e.id=`session-load-more`,e.setAttribute(`type`,`button`),e.onclick=()=>{$u+=20,ed(),Fu.querySelectorAll(`.session-open`)[r.length]?.focus()},s.push(I(`li`,`hover:bg-neutral-100`,e))}let c=document.activeElement,l=c?.closest(`[data-session-id]`)?.dataset.sessionId,u=c?.classList.contains(`session-more`)?`.session-more`:`.session-open`;if(Fu.replaceChildren(...s.length?[I(`ul`,`pb-1`,...s)]:[I(`p`,`px-3 py-2 text-sm leading-normal text-neutral-500`,`No sessions yet — create one.`)]),l){let e=[...Fu.querySelectorAll(`[data-session-id]`)].find(e=>e.dataset.sessionId===l);e?.querySelector(`.session-open`)?.focus({preventScroll:!0}),u===`.session-more`&&e?.querySelector(u)?.focus({preventScroll:!0})}else c?.id===`session-load-more`&&(Fu.querySelector(`#session-load-more`)??Fu.querySelector(`.session-open`)??F(`#new-session`)).focus({preventScroll:!0});Nd()}function td(){if(Iu.getAttribute(`aria-expanded`)===`true`)return B();let e=Y.sessions().find(e=>e.id===Y.currentId())?.cwd,t=Ve(Y.sessions()).slice(0,Vu);if(e&&!t.includes(e)&&t.unshift(e),!t.length)return Da(Iu,void 0,Y.createSession);Oa(Iu,t.map(e=>({path:e,hint:Zr(e)})),e,Y.createSession)}function nd(e){Y=e,Iu.onclick=td,Qc(Iu,`shift+o`,`New session`,td,Jc);let t=e=>{let t=Bu(Y.sessions(),Y.currentId(),e);t&&Y.select(t)};nl(`shift+[`,()=>t(-1),Jc),nl(`shift+]`,()=>t(1),Jc)}var rd,id=F(`#palette`),ad=F(`#palette-input`),od=F(`#palette-list`),sd=F(`#palette-count`),cd=[{name:`tasks`,icon:re,label:`Tasks`,detail:`Automation — task definitions and schedules`},{name:`runs`,icon:re,label:`Runs`,detail:`Automation — executions, subagents and callbacks`},{name:`activity`,icon:re,label:`Activity`,detail:`Automation — sessions and relationships`},{name:`boards`,icon:ne,label:`Boards`,detail:`Console — the static pages Pier publishes`},{name:`settings`,icon:pe,label:`Settings`,detail:`Console — models and providers, agent files and extensions, channels, password, sign out, security`}],ld=7,ud=3,dd=8,fd=80,pd=``,md,hd,gd;function _d(e){pd!==e&&(clearTimeout(gd),hd?.abort(),hd=void 0,pd=e,md=void 0,e&&(gd=setTimeout(()=>{let t=hd=new AbortController;C(`/api/search?q=${encodeURIComponent(e)}`,`Search unavailable`,{signal:t.signal}).then(n=>{t.signal.aborted||pd!==e||(hd=void 0,md=n.ok?{hits:n.value.hits}:{error:n.error},id.open&&Md())})},fd)))}var vd=[],yd=0;function bd(e){if(vd.length){yd=(e+vd.length)%vd.length;for(let[e,{el:t}]of vd.entries())t.classList.toggle(`bg-indigo-50`,e===yd),t.setAttribute(`aria-selected`,String(e===yd));vd[yd]?.el.scrollIntoView({block:`nearest`})}}var xd=e=>e.hit?.at??e.session?.createdAt;function Sd(e){let t=I(`span`,`min-w-0 flex-1 truncate text-neutral-500`);for(let n of e.replaceAll(/\s+/g,` `).split(``)){let[e=``,r]=n.split(``,2);r===void 0?t.append(e):t.append(I(`span`,`font-medium text-neutral-800`,e),r)}return t}var Cd=`flex min-w-0 flex-1 items-baseline gap-2`,wd=`shrink-0 truncate`,Td=`min-w-[2.5em] truncate text-[0.8125rem] text-neutral-400`,Ed=`flex-none text-[0.75rem] tabular-nums text-neutral-400`,Dd=`flex h-7 w-7 flex-none items-center justify-center rounded-[8px] bg-neutral-100 text-neutral-500`;function Od(e){let t=I(`li`,`palette-row flex cursor-pointer items-center gap-3 rounded-[10px] px-2 leading-5 ${e.hit?`py-1.5`:`min-h-10`}`);t.setAttribute(`role`,`option`),t.append(I(`span`,Dd,_(e.icon,`h-4 w-4`)));let n=I(`div`,`flex min-w-0 flex-1 flex-col`),r=I(`div`,`flex items-center gap-2`);e.session&&r.append(...Ku(e.session));let i=I(`span`,Cd,I(`span`,`${wd} ${e.detail?`max-w-[calc(100%-3em)]`:`max-w-full`}`,e.label));e.detail&&i.append(I(`span`,Td,e.detail)),r.append(i);let a=xd(e);return a!==void 0&&r.append(I(`span`,Ed,Yr(a))),n.append(r),e.hit&&n.append(I(`div`,`flex items-baseline gap-2 text-[0.8125rem] leading-5`,I(`span`,`flex-none text-[0.75rem] text-neutral-400`,e.hit.role===`user`?`You`:`Agent`),Sd(e.hit.snippet))),t.append(n),t.onclick=e.open,t}var kd=e=>I(`li`,`px-2 pb-1.5 pt-4 text-[0.6875rem] font-semibold leading-4 tracking-[0.02em] text-neutral-400 first:pt-2`,e);function Ad(e,t){let n=I(`li`,`px-2 py-2 pl-12 text-[0.8125rem] leading-5 text-neutral-400`,e);return t&&(n.title=t),n}var jd=e=>e.channel&&e.channel!==`web`?e.channel:``;function Md(){let e=ad.value.trim(),t=e.toLowerCase().split(/\s+/).filter(Boolean),n=e=>{let n=e.toLowerCase();return t.every(e=>n.includes(e))},r=e=>()=>{id.close(),e()},i=rd.sessions(),a=new Map(i.map(e=>[e.id,e])),{top:o,rest:s}=Ru(i),c=[...o,...s],l=e=>({icon:ae,label:e.title??Qr(e.cwd),detail:[Zr(e.cwd),jd(e)].filter(Boolean).join(` · `),open:r(()=>void rd.select(e.id)),session:e}),u=e=>({icon:te,label:Qr(e),detail:e,open:r(()=>void rd.createSession(e))}),d=cd.filter(t=>!e||n(`${t.label} ${t.detail}`)).map(({name:e,icon:t,label:n,detail:i})=>({icon:t,label:n,detail:i,open:r(()=>rd.openConsole(e))})),f={icon:te,label:`New session in…`,detail:`Pick a directory`,open:r(td)},p=[];if(e){let t=Ve(i).filter(e=>n(Zr(e))).slice(0,ud),o=c.filter(e=>n(`${e.title??``} ${e.cwd} ${jd(e)}`)).slice(0,dd),s=new Set(o.map(e=>e.id)),m=o.map(l);if(pd!==e||!md)m.push(Ad(`Searching messages…`));else if(`error`in md)m.push(Ad(`Message search unavailable`,md.error));else{for(let e of md.hits){if(m.length>=dd)break;let t=a.get(e.sessionId);!t||s.has(t.id)||m.push({...l(t),hit:e,open:r(()=>void rd.select(t.id).then(()=>Rs(e.role,e.at)))})}m.length||m.push(Ad(`No sessions match`))}p.push([`Actions`,[...t.map(u),...n(f.label)?[f]:[],...d]],[`Sessions`,m])}else{let e=a.get(rd.currentId()??``);p.push([`Running`,c.filter(Gu).map(l)],[`Recent`,c.filter(e=>!Gu(e)).slice(0,ld).map(l)],[`Actions`,[...e?[u(e.cwd)]:[],f]],[`Console`,d])}vd=[];let m=[];for(let[e,t]of p)if(t.length){m.push(kd(e));for(let e of t){if(e instanceof HTMLElement){m.push(e);continue}let t=Od(e);vd.push({el:t,open:e.open}),m.push(t)}}od.replaceChildren(...m.length?m:[Ad(`Nothing matches`)]),sd.textContent=`${vd.length} ${vd.length===1?`row`:`rows`}`,bd(Math.min(yd,Math.max(0,vd.length-1)))}function Nd(){id.open&&Md()}function Pd(){if(id.open)return id.close();ad.value=``,yd=0,_d(``),Md(),id.showModal(),ad.focus(),rd.loadSessions().then(Nd)}function Fd(e){rd=e;let t=F(`#open-palette`);t.onclick=Pd,Qc(t,`k`,`Search sessions, messages and Console`,Pd,()=>id.open||la()),id.onclick=e=>{e.target===id&&id.close()},id.onclose=()=>_d(``),ad.oninput=()=>{yd=0,_d(ad.value.trim()),Md()},ad.onkeydown=e=>{let t=ua(e);if(t!==void 0){e.preventDefault(),bd(yd+t);return}e.key===`Enter`&&!e.ctrlKey&&(e.preventDefault(),vd[yd]?.open())}}var Id=0,Ld=e=>`${e.provider}/${e.id}`,Rd=null;async function zd(){let{modelMenu:e}=await Ge(`/api/settings`,`Could not read the pinned model menu`);return e}function Bd(e){let t=I(`button`,`flex w-full min-w-0 cursor-pointer items-center gap-2 px-3 py-1.5 text-left hover:bg-neutral-100`,_(o,`h-3 w-3 text-indigo-600 ${e.checked?``:`invisible`}`),I(`span`,`truncate`,e.label));return e.hint&&t.append(I(`span`,`ml-auto flex-none text-[11.5px] text-neutral-400`,e.hint)),e.title&&(t.title=e.title),t.onclick=()=>e.onSelect(),t}function Vd({models:e,current:t,thinkingLevel:n,thinkingLevels:r,onPick:i,onThinkingPick:a}){let o=n,s=I(`div`,`flex w-full min-w-0 flex-col sm:min-w-72`),c=I(`div`,`flex flex-col gap-2 border-b border-neutral-200 px-2 py-2`),u=document.createElement(`input`);if(u.type=`search`,u.placeholder=`Search models`,u.setAttribute(`aria-label`,`Search models`),u.className=`w-full rounded-md border border-neutral-300 px-2 py-1.5 text-[12.5px] focus:border-indigo-400 focus:outline-none`,c.append(u),r.length){let e=document.createElement(`details`),t=I(`span`,`ml-auto font-medium text-indigo-700`,xe(o)),n=I(`summary`,`flex min-h-11 cursor-pointer list-none items-center gap-2 rounded-xl px-3 text-sm text-neutral-700 hover:bg-neutral-100 [&::-webkit-details-marker]:hidden`,I(`span`,`font-medium`,`Reasoning effort`),t,_(l,`chev h-3 w-3 text-neutral-400`)),i=I(`fieldset`,`grid grid-cols-2 gap-1 rounded-xl bg-neutral-50 p-1`);i.append(I(`legend`,`sr-only`,`Reasoning effort`));let s=`reasoning-${++Id}`;for(let e of r){let n=document.createElement(`input`);n.type=`radio`,n.name=s,n.value=e,n.checked=e===o,n.className=`peer sr-only`,n.onchange=()=>{n.checked&&(o=e,t.textContent=xe(o),m(u.value),a(o))},i.append(I(`label`,`relative cursor-pointer`,n,I(`span`,`flex min-h-11 items-center rounded-lg border border-transparent px-3 text-sm text-neutral-700 hover:bg-neutral-100 peer-checked:border-indigo-200 peer-checked:bg-indigo-50 peer-checked:font-semibold peer-checked:text-indigo-700 peer-focus-visible:outline-2 peer-focus-visible:outline-indigo-500`,xe(e))))}e.append(n,i),c.append(e)}let d=I(`div`,`max-h-72 overflow-y-auto py-1`),f=new Map(e.map(e=>[Ld(e),e])),p=e=>{let n=(Rd??[]).map(e=>({e,model:f.get(Ld(e))})).filter(t=>!!t.model&&(!e||Ld(t.model).toLowerCase().includes(e)));n.length&&d.append(I(`div`,`px-3 pb-0.5 pt-1 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,`Pinned`),...n.map(({e,model:n})=>Bd({label:n.id,hint:xe(e.thinking),title:e.note,checked:!!t&&Ld(t)===Ld(n)&&o===e.thinking,onSelect:()=>i(n,e.thinking)})),I(`div`,`my-1 border-t border-neutral-100`))},m=n=>{d.replaceChildren();let r=n.trim().toLowerCase();p(r);let a=new Map;for(let t of e){if(r&&!Ld(t).toLowerCase().includes(r))continue;let e=a.get(t.provider);e?e.push(t):a.set(t.provider,[t])}if(!a.size){d.append(I(`div`,`px-3 py-2 text-[12.5px] text-neutral-400`,e.length?`No matching models.`:`No models available.`));return}for(let[e,n]of a){let a=n.some(e=>!!t&&Ld(t)===Ld(e)),o=document.createElement(`details`);o.open=a||r.length>0;let s=I(`summary`,`flex cursor-pointer select-none items-center gap-1.5 px-3 py-1 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400 hover:bg-neutral-100`,_(l,`chev h-3 w-3`),I(`span`,`truncate`,e),I(`span`,`ml-auto flex-none normal-case text-neutral-300`,String(n.length)));o.append(s,...n.map(e=>Bd({label:e.id,checked:!!t&&Ld(t)===Ld(e),onSelect:()=>i(e)}))),d.append(o)}};return u.oninput=()=>m(u.value),m(``),zd().then(e=>{let t=JSON.stringify(e)!==JSON.stringify(Rd);Rd=e,t&&m(u.value)}).catch(e=>Lc(`model menu unavailable`,e)),s.append(c,d),queueMicrotask(()=>u.focus()),s}function Hd(e,t,n,r){let i=L(t.model?`${t.model.id}${t.thinking?` · ${xe(t.thinking)}`:``}`:t.thinking?`Pi default · ${xe(t.thinking)}`:`Pi default`,`${wi} flex items-center gap-1.5 ${t.model?`text-neutral-700`:`text-neutral-400`}`);return i.title=t.model?`${t.model.provider}/${t.model.id}`:`Whatever the project and Pi pick`,i.onclick=()=>{let e=Vd({models:n,current:t.model,thinkingLevel:t.thinking??`medium`,thinkingLevels:[...No],onPick:(e,n)=>{B(),r({model:e,thinking:n??t.thinking})},onThinkingPick:e=>{t={...t,thinking:e},r(t)}}),a=L(`Pi default`,`w-full cursor-pointer px-3 py-1.5 text-left text-[12.5px] text-neutral-500 hover:bg-neutral-100`);a.onclick=()=>{B(),r({model:null,thinking:null})};let o=I(`div`,`flex flex-col`);o.append(e,I(`div`,`border-t border-neutral-200`),a),va(i,o)},Si(e,i)}var X;function Ud(e){X=e,nl(Wd,()=>{X.currentSession()&&(B(),X.toggleFiles())},Jc)}var Wd=`i`,Gd=F(`#chat-title`),Kd=F(`#chat-menu`),qd=F(`#session-meta`),Jd=null,Yd=new Map,Xd=e=>`${e.provider}/${e.id}`,Z=null,Zd=null,Qd=null,$d=null;function ef(){Z=null,Zd=null,Qd=null,$d=null,uf()}function tf(e,t,n,r){Z=e,Zd=t,Qd=n,$d=r,of()}function nf(e){$d=e.completedAt,Zd&&={...Zd,tokens:e.tokens},uf()}var rf=null;function af(e){rf=e===null?null:Qr(e),of()}function of(){let e=X.currentSession();e&&(rf=null),Gd.textContent=e?e.title??Qr(e.cwd):rf??X.currentId()??`no session`,Gd.classList.toggle(`cursor-pointer`,!!e),Gd.title=e?`Session info`:``,Gd.onclick=e?()=>df(Gd,e):null,Kd.classList.toggle(`hidden`,!e),e&&(Kd.onclick=()=>vf(Kd,e)),uf(),X.syncBar()}var sf=70,cf=(e,t)=>Math.min(100,Math.round(e/t.contextWindow*100)),lf=e=>e.tokens===null?`?/${Se(e.contextWindow)}`:`${Se(e.tokens)}/${Se(e.contextWindow)} · ${100-cf(e.tokens,e)}% left`;function uf(){let e=Zd,t=e?.tokens??null,n=X.currentId(),r=X.currentSession()?.activeRuns??0,i=[];if(r>0){let e=I(`button`,`flex flex-none cursor-pointer items-center gap-1 rounded bg-sky-50 px-1.5 py-px font-medium text-sky-700 hover:bg-sky-100`,_(h,`spinner h-3 w-3`),`${r} running`);e.title=`${Wu(r)} · show the newest`,e.onclick=()=>{zs()||W(`error`,`no run card left in this transcript — reload the session to see it`)},i.push(e)}if(!n&&rf&&i.push(I(`span`,`flex flex-none items-center gap-1.5 text-neutral-500`,_(h,`spinner`),`starting…`)),n){let e=(e,t)=>{let r=I(`button`,`cursor-pointer font-mono ${t}`,e);return r.title=`Change model or reasoning`,r.onclick=()=>void ff(r,n),r};Z&&i.push(e(Z.id,`min-w-0 truncate rounded bg-indigo-50 px-1.5 py-px font-medium text-indigo-700 hover:bg-indigo-100`)),Qd&&i.push(e(Qd,`flex-none text-neutral-500 hover:text-indigo-700`))}let a=0;if(e&&t!==null){a=cf(t,e);let n=a>=90?`text-red-700`:a>=sf?`text-amber-700`:`text-neutral-500`;i.push(I(`span`,`flex-none font-mono ${n}`,Se(t).toLowerCase()))}let o=i.flatMap((e,t)=>t===0?[e]:[I(`span`,`flex-none text-neutral-300`,`·`),e]);qd.replaceChildren(...o),qd.classList.toggle(`hidden`,i.length===0),qd.classList.toggle(`flex`,i.length>0),qd.toggleAttribute(`data-urgent`,!n&&!!rf||r>0||a>=sf)}function df(e,t,n){let i=[[`Directory`,t.cwd],[`Session`,t.id]],a=t.id===X.currentId();if(a&&(i.push([`Model`,Z?.id??`—`]),i.push([`Reasoning`,Qd??`—`]),i.push([`Context`,Zd?lf(Zd):`—`])),i.push([`Created`,$r(t.createdAt),Xr(t.createdAt)]),a){let e=$d;i.push(e===null?[`Last reply`,`—`]:[`Last reply`,$r(e),Xr(e)])}let o=I(`div`,`w-[min(26rem,calc(100vw-2rem))] max-sm:w-full rounded-xl bg-white px-3 py-3 font-sans text-[15px] leading-normal`),s=I(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,_(_e));s.setAttribute(`aria-label`,`Close session info`),s.onclick=B;let c=I(`div`,`sticky top-0 z-10 flex items-start gap-2 bg-white pb-2`,I(`div`,`min-w-0 flex-1`,I(`div`,`text-sm font-medium text-neutral-500`,`Session info`),I(`h2`,`mt-1 [overflow-wrap:anywhere] text-lg leading-7 font-semibold text-neutral-900`,t.title??Qr(t.cwd))),s);if(n){let e=I(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,_(r));e.setAttribute(`aria-label`,`Back to session actions`),e.onclick=n,c.prepend(e)}o.append(c);let l=I(`dl`,``);for(let[e,t,n]of i){let r=e===`Directory`||e===`Session`,i=I(`dd`,`min-w-0 flex items-start gap-2 text-neutral-700 ${r?`font-mono text-sm leading-6`:``}`,I(`span`,`min-w-0 flex-1 [overflow-wrap:anywhere]`,t));if(r){let n=ai(`min-h-11 min-w-11 sm:min-h-8 shrink-0 cursor-pointer rounded-lg px-2 py-1 text-[13px] font-sans text-neutral-500 hover:bg-neutral-100 focus-visible:outline-2`,()=>t);n.setAttribute(`aria-label`,`Copy ${e.toLowerCase()}`),i.append(n)}n&&i.firstElementChild?.append(I(`span`,`ml-2 inline-block font-sans text-[13px] leading-5 text-neutral-500`,n));let a=e===`Model`||e===`Created`;l.append(I(`div`,`grid gap-1 py-1.5 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-3 ${a?`mt-2 border-t border-neutral-200 pt-2.5`:``}`,I(`dt`,`text-[15px] text-neutral-500`,e===`Session`?`Session ID`:e),i))}return o.append(l),va(e,o)}async function ff(e,t,n){let r=I(`div`,`px-3 py-3 text-[15px] text-neutral-500`,`Loading models…`),i=I(`div`,`w-[min(24rem,calc(100vw-2rem))] min-w-0 max-sm:w-full`,r),a=r;n&&i.prepend(gf(e,n,`Close model picker`)),va(e,i);let o=()=>a.isConnected&&!a.closest(`[inert]`),s=``,c=(n,r,o)=>{let c=JSON.stringify([n,r,o]);if(c===s)return;s=c;let l=Vd({models:n,current:t===X.currentId()?Z:null,thinkingLevel:r,thinkingLevels:o,onPick:(e,n)=>{B(),pf(t,e,n)},onThinkingPick:e=>void hf(t,e)});a.replaceWith(l),a=l,va(e,i)},l=t===X.currentId()&&Z?Yd.get(Xd(Z)):void 0;Jd&&l&&Qd&&c(Jd,Qd,l);try{let[e,n]=await Promise.all([Ge(`/api/sessions/${t}/models`,`Could not load models`),Ge(`/api/sessions/${t}/thinking`,`Could not read the reasoning level`)]);if(Jd=e,t===X.currentId()&&Z&&Yd.set(Xd(Z),n.levels),!o())return;c(e,n.level,n.levels)}catch(e){s?W(`error`,`model options are stale: ${String(e)}`):o()?(r.textContent=`Could not load models: ${String(e)}`,r.setAttribute(`role`,`alert`)):W(`error`,`model options failed: ${String(e)}`)}}async function pf(e,t,n){await mf(e,t)&&n&&await hf(e,n)}async function mf(e,t){let n=Z;e===X.currentId()&&(Z=t,of());let r=await x(`/api/sessions/${e}/model`,t);if(!r.ok){let{error:t}=await r.json().catch(()=>({}));return e===X.currentId()&&(Z=n,of()),W(`error`,`model change failed: ${t??r.status}`),!1}let{model:i}=await r.json();return e===X.currentId()&&i&&(Z=i,of()),!0}async function hf(e,t){let n=await x(`/api/sessions/${e}/thinking`,{level:t});if(!n.ok){W(`error`,`reasoning change failed: ${n.status}`);return}let{level:r}=await n.json();e===X.currentId()&&(Qd=r,uf())}function gf(e,t,n){let i=I(`button`,`icon-btn h-11 w-11`,_(r));i.setAttribute(`aria-label`,`Back to session actions`),i.onclick=()=>vf(e,t);let a=I(`button`,`icon-btn h-11 w-11`,_(_e));a.setAttribute(`aria-label`,n),a.onclick=B;let o=I(`span`,`min-w-0 flex-1 truncate text-sm font-medium`,t.title??Qr(t.cwd));return o.title=o.textContent??``,I(`div`,`flex items-center gap-2 border-b border-neutral-200 pb-2 mb-2`,i,o,a)}async function _f(e,t){let n=I(`p`,`px-3 py-2 text-[15px] text-neutral-500`,`Loading chats…`),r=I(`div`,`w-[min(24rem,calc(100vw-2rem))] min-w-0 max-sm:w-full`,gf(e,t,`Close chat picker`),I(`div`,`px-3 pb-1 text-sm font-medium text-neutral-500`,`Continue in a direct message`),I(`p`,`px-3 pb-2 text-[13px] text-neutral-500`,`DMs the bot has seen. A DM appears here after its first message to the bot.`),n);va(e,r);let i=await C(`/api/handoff/targets`,`Could not list chats`);if(!r.isConnected)return;if(!i.ok){n.textContent=i.error,n.setAttribute(`role`,`alert`);return}if(!i.value.targets.length){n.textContent=`No DMs yet — message the bot once in Lark or Slack, then come back.`;return}let a=I(`p`,`hidden px-3 pt-1 text-[13px] text-red-600`);a.setAttribute(`role`,`alert`);let o=I(`div`,``);o.dataset.list=``;for(let e of i.value.targets){let n=I(`button`,`flex w-full min-h-10 cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-left transition-colors hover:bg-indigo-50 hover:text-indigo-700 active:bg-indigo-100`,I(`span`,`min-w-0 truncate`,`${e.platform[0].toUpperCase()}${e.platform.slice(1)} · ${e.name||e.chatId}`));n.onclick=async()=>{let n=await x(`/api/handoff`,{sessionId:t.id,platform:e.platform,chatId:e.chatId});if(n.ok)return B();a.textContent=(await n.json().catch(()=>({}))).error??`handoff failed: ${String(n.status)}`,a.classList.remove(`hidden`)},o.append(n)}n.replaceWith(o,a),o.querySelector(`button`)?.focus({preventScroll:!0})}function vf(e,t){let n=t.id===X.currentId();ba(e,[{label:`Rename…`,onSelect:()=>{B(),qu(t)}},{label:`Session info`,onSelect:()=>df(e,t,()=>vf(e,t))},{label:`New session here`,separatorBefore:!0,hint:Zr(t.cwd),onSelect:()=>{B(),X.createSession(t.cwd)}},{label:`Browse files`,hint:n?qc(Wd):``,onSelect:()=>{B(),X.openFiles(n?void 0:t.cwd)}},{label:`Continue in Lark/Slack…`,...t.channel&&t.channel!==`web`?{hint:`answers in ${t.channel}`,disabled:!0}:{},onSelect:()=>void _f(e,t)},{label:`Model & reasoning…`,separatorBefore:!0,hint:n?Z?.id??`…`:``,onSelect:()=>void ff(e,t.id,t)}],t.title??Qr(t.cwd))}var yf=`pier.theme`,bf=[`system`,`light`,`dark`],xf=window.matchMedia(`(prefers-color-scheme: dark)`),Sf={system:se,light:he,dark:g},Cf=()=>{let e=null;try{e=localStorage.getItem(yf)}catch{return`system`}return e===`light`||e===`dark`?e:`system`},wf=()=>{let e=Cf();return e===`system`?xf.matches?`dark`:`light`:e};function Tf(){let e=wf();document.documentElement.dataset.theme=e;let t=getComputedStyle(document.documentElement).getPropertyValue(`--workbench-canvas`).trim();F(`meta[name="theme-color"]`).setAttribute(`content`,t),window.dispatchEvent(new Event(`pier:theme`))}function Ef(){let e=F(`#theme-toggle`),t=()=>{let t=Cf();e.title=`Theme: ${t}${t===`system`?` (${wf()})`:``}`,e.replaceChildren(_(Sf[t])),e.setAttribute(`aria-label`,e.title),Tf()};e.onclick=()=>{let e=bf[(bf.indexOf(Cf())+1)%bf.length];try{e===`system`?localStorage.removeItem(yf):localStorage.setItem(yf,e)}catch{}t()},xf.addEventListener(`change`,t),t()}var Df=`https://github.com/timqi/pier`,Of=[`text-neutral-400`,`hover:text-neutral-700`],kf=[`rounded-full`,`bg-emerald-50`,`px-1.5`,`text-emerald-700`,`ring-1`,`ring-inset`,`ring-emerald-600/20`,`hover:bg-emerald-100`],Af=18e5,jf=null,Mf=F(`#version`);function Nf(e){let t=jf?.available===!0&&jf.latest!==null;Mf.textContent=`v${e}`,Mf.title=t?`Pier ${jf?.latest} is out`:``,Mf.classList.remove(...t?Of:kf),Mf.classList.add(...t?kf:Of)}var Pf=(e,t=`px-3 py-1 text-[12px] leading-snug text-neutral-500`)=>I(`p`,t,e);function Ff(){let e=I(`div`,`flex w-72 flex-col gap-1 py-1`);if(!jf)return e.append(Pf(`Checking the registry…`)),e;let{current:t,latest:n,available:r,canApply:i,problem:a}=jf,o=I(`span`,``,``),s=(e,t)=>R(o,e?`failed`:`idle`,t),c=I(`div`,`flex items-center gap-2 px-3 py-1.5`);if(e.append(Pf(r?`Pier ${n} is out`:`Pier ${t}`,`px-3 py-1 text-[12.5px] font-medium text-neutral-700`),Pf(r?`You are running ${t}.`:n===null?`The registry could not be reached, so this may not be the latest.`:`This is the latest release.`)),a&&e.append(Pf(a,`mx-3 my-1 rounded-md bg-red-50 px-2 py-1.5 text-[11.5px] leading-snug text-red-700`)),r&&i&&!a){let e=di(`Update now`,!0);e.onclick=()=>void(async()=>{e.disabled=!0,s(!1,`starting the updater…`);let t=await x(`/api/update`,{});if(!t.ok)return e.disabled=!1,s(!0,await S(t,`Could not update`));let{draining:n}=await t.json();s(!1,n?`Waiting for running work to finish — Pier then installs and restarts.`:`Installing — Pier restarts once it is on disk, and this page reconnects on its own.`)})(),c.append(e)}c.append(Object.assign(I(`a`,`btn text-[12.5px] no-underline`,`Source`),{href:r?`${Df}/releases`:Df,target:`_blank`,rel:`noreferrer`,title:`Pier is free software (AGPL-3.0)`})),e.append(c,I(`div`,`px-3`,o)),r&&!i&&!a&&e.append(Pf(`No service manager owns this Pier, so it cannot restart itself — update it with: pier update`));let l=ki(`Update automatically`,i?`Installs a new release once nothing is running — no turn in flight, no task run.`:`Needs the systemd service (pier service install); nothing here can restart Pier.`,jf.autoUpdate,e=>void(async()=>{jf&&(jf.autoUpdate=e);let t=await x(`/api/settings`,{autoUpdate:e},`PUT`);t.ok||(jf&&(jf.autoUpdate=!e),u&&(u.checked=!e),s(!0,await S(t,`Could not save`)))})()),u=l.querySelector(`input`);return u&&(u.disabled=!i),e.append(I(`div`,`mt-1 border-t border-neutral-200 px-3 pb-1 pt-2`,l)),e}async function If(e){let t=await C(`/api/update`,`Update check failed`);t.ok&&Nf((jf=t.value).current||e)}function Lf(e){Nf(e),Mf.onclick=e=>{e.preventDefault(),va(Mf,Ff())};let t=()=>void If(e);t(),setInterval(t,Af)}var Q,Rf=F(`#chat-header`),zf=F(`#chat-title`),Bf=[Rf,U,F(`#composer`)],Vf=()=>Jf===null,Hf,Uf,Wf,Gf=new Map,Kf=new Map,qf=new Map,Jf=null,Yf=0,Xf=[`files`],Zf=new Map,Qf={tasks:`Tasks`,runs:`Runs`,activity:`Activity`,boards:`Boards`,settings:`Settings`,files:`Files`},$f=[`tasks`,`runs`,`activity`],ep=`Automation`,tp=F(`#automation-view`),np=F(`#automation-tabs`),rp=e=>$f.includes(e)?`tasks`:e;function ip(e,t){let n=e!==null&&$f.includes(e);if(tp.classList.toggle(`hidden`,!n),tp.classList.toggle(`flex`,n),!n)return;let r=[];if(e===`tasks`&&!t){let e=di(`New task`,!0);e.classList.add(`ml-auto`),e.disabled=!Hf,e.onclick=()=>Hf?.create(),r.push(e)}np.replaceChildren(fi(ep),...$f.map(t=>gi(Qf[t],t===e,()=>lp(t))),...r)}var ap=e=>Hf?.refresh(e),op=()=>Uf?.refresh(),sp=()=>Wf?.refresh();function cp(){Jf?vu($f.includes(Jf)?ep:Qf[Jf],!1):vu(zf.textContent??``,Q.currentSession()!==void 0)}function lp(e,t,n){if(Xf.includes(e)){let t=xp();t&&(t.kind!==`console`||t.name!==e)&&Zf.set(e,t)}Cp({kind:`console`,name:e,arg:t,query:n}),_u(),Jf=e;for(let e of Bf)e.classList.add(`hidden`);El();for(let[t,n]of Gf)t!==e&&n.hide();for(let[t,n]of qf)n.classList.toggle(`bg-indigo-50`,t===rp(e));ip(e,t),cp(),up(e,t,n,++Yf)}async function up(e,t,n,r){let i=Gf.get(e);if(!i){let t=Kf.get(e);if(!t){let n=F(`#${e}-view`);t=Ep[e](n).catch(t=>(console.warn(`${e} view failed to load`,t),ti(n,()=>n.replaceChildren(I(`p`,`p-4 text-[13px] text-red-600`,`Could not load ${Qf[e]} — reload the page.`))))),Kf.set(e,t)}i=await t,Gf.set(e,i),Kf.delete(e)}Jf===e&&r===Yf&&(i.show(t,n),e===`tasks`&&ip(e,t))}var dp=e=>lp(`tasks`,e),fp=(e={},t)=>lp(`runs`,t,new URLSearchParams(e).toString()),pp=e=>fp({},e),mp=(e,t)=>lp(`files`,e,t?new URLSearchParams({select:t}).toString():void 0),hp=(e,t)=>{Jf===e?_p(e):lp(e,t)},gp=e=>hp(`files`,e);function _p(e){let t=Q.currentId(),n=Zf.get(e)??(t?{kind:`session`,id:t}:null);Zf.delete(e),n?Cp(n):(history.replaceState(null,``,`#/`),vp())}function vp(){if(Jf){Jf=null;for(let e of Gf.values())e.hide();for(let e of qf.values())e.classList.remove(`bg-indigo-50`);ip(null);for(let e of Bf)e.classList.remove(`hidden`);El(),cp(),Q.maybeAckRead()}}var yp=e=>e.kind===`session`?`#/session/${encodeURIComponent(e.id)}`:`#/${e.name}${e.arg?`/${encodeURIComponent(e.arg)}`:``}${e.query?`?${e.query}`:``}`,bp={config:`files`,channels:`channels`,providers:`models`};function xp(){let e=location.hash.replace(/^#\/?/,``),t=e.indexOf(`?`),[n=``,r]=(t<0?e:e.slice(0,t)).split(`/`),i=t<0?void 0:e.slice(t+1)||void 0,a;try{a=r?decodeURIComponent(r):void 0}catch{return null}return bp[n]?{kind:`console`,name:`settings`,arg:bp[n]}:Object.hasOwn(Qf,n)?{kind:`console`,name:n,arg:a,query:i}:n===`session`&&a?{kind:`session`,id:a}:null}var Sp=!1;function Cp(e,t=!1){if(Sp)return;let n=yp(e);location.hash!==n&&(t?history.replaceState(null,``,n):location.hash=n)}var wp=e=>Cp({kind:`session`,id:e});function Tp(){let e=xp(),t=Q.sessions(),n=Q.currentId(),r=e?.kind===`session`?e.id:null,{top:i,rest:a}=Ru(t),o=r??n??(i[0]??a[0])?.id??null;Sp=!0;try{o&&o!==n&&Q.select(o),e?.kind===`console`?lp(e.name,e.arg,e.query):vp(),o||of()}finally{Sp=!1}e?.kind!==`console`&&o&&Cp({kind:`session`,id:o},!0)}var Ep={tasks:async e=>Hf=(await Ki(async()=>{let{createTasksView:e}=await import(`./tasks-D1dGhkTZ.js`);return{createTasksView:e}},__vite__mapDeps([0,1]))).createTasksView(e,()=>Q.sessions().map(({id:e,cwd:t,title:n})=>({id:e,cwd:t,title:n})),Q.loadSessions,Q.select,()=>Q.currentId(),fp,dp),runs:async e=>Uf=(await Ki(async()=>{let{createRunsView:e}=await import(`./runs-tYH577mL.js`);return{createRunsView:e}},__vite__mapDeps([2,1]))).createRunsView(e,Q.select,fp,dp),activity:async e=>Wf=(await Ki(async()=>{let{createActivityView:e}=await import(`./activity-CJtsniqS.js`);return{createActivityView:e}},[])).createActivityView(e,Q.select,pp),boards:async e=>(await Ki(async()=>{let{createBoardsView:e}=await import(`./boards-DyQtNqgv.js`);return{createBoardsView:e}},[])).createBoardsView(e,Q.select),files:async e=>(await Ki(async()=>{let{createExplorerView:e}=await import(`./explorer-BQYNIR0V.js`);return{createExplorerView:e}},[])).createExplorerView(e,()=>Q.currentSession(),e=>lp(`files`,e),()=>_p(`files`)),settings:async e=>(await Ki(async()=>{let{createSettingsView:e}=await import(`./settings-B42zHcpu.js`);return{createSettingsView:e}},[])).createSettingsView(e,()=>Ve(Q.sessions()),e=>lp(`settings`,e),mp)};function Dp(e){Q=e;for(let e of[`tasks`,`boards`,`settings`]){let t=F(`#open-${e}`);qf.set(e,t),t.onclick=()=>lp(e)}let t=F(`#console-section`);t.open=localStorage.getItem(`pier.consoleCollapsed`)!==`1`,t.ontoggle=()=>localStorage.setItem(`pier.consoleCollapsed`,t.open?`0`:`1`),window.onhashchange=Tp}var Op=[],kp=null,Ap=0,jp=0,Mp=!1,$=null,Np=`idle`,Pp=null,Fp=0,Ip=!1,Lp=!1;async function Rp(e){let t=++Ap;++jp,Mp=!1,vp(),_u(),$=null,Pp?.close(),Pp=null,Oc(),Dl([]),ef(),af(e),kc(!0),Lp=!0,Tl();let n=await x(`/api/sessions`,{cwd:e});if(t!==Ap)return;if(Lp=!1,!n.ok){kc(!1),af(null),Tl(),W(`error`,`session create failed: ${n.status}`);return}let{id:r}=await n.json();t===Ap&&(Op.unshift({id:r,cwd:e,createdAt:Date.now(),state:`idle`,unread:!1,channel:`web`,activeRuns:0}),await Yp(r),$===r&&xl())}function zp(e){Op=e.map(e=>({...e,title:ze(e.title)})),Op.sort((e,t)=>t.createdAt-e.createdAt),ed(),of(),Vp()}var Bp=He(async()=>{zp(await Ge(`/api/sessions`,`Could not load sessions`))});function Vp(){if(document.hidden||!document.hasFocus()||!Vf())return;let e=Op.find(e=>e.id===$);e?.unread&&(e.unread=!1,ed(),fetch(`/api/sessions/${e.id}/read`,{method:`POST`}))}function Hp(){return Op.find(e=>e.id===$)??(kp&&kp.id===$?kp:void 0)}async function Up(e){let t=await C(`/api/sessions/${e}`,`failed to load session`);$!==e||!t.ok||(kp={...t.value,title:ze(t.value.title)},of())}function Wp(e,t){let n=Op.find(t=>t.id===e);!n||n.title||!t.trim()||(n.title=t.trim().slice(0,80),ed(),of())}function Gp(e){Np=e;let t=Op.find(e=>e.id===$);t&&(t.state=e),ed(),of(),Tl(),e===`idle`&&Bp()}function Kp(e){if(!(e.sessionId!==$||e.seq<=Fp))switch(Fp=e.seq,e.type){case`turn-start`:Ip=!0;break;case`system-input`:wc(),Xs(e.text,e.origin);break;case`task-status`:qo(e.run);break;case`user-message`:{let t=Ie(e.text).text;if(Wp(e.sessionId,t),Sl(t))break;wc(),W(`user`,e.text,!1,e.ts),Is();break}case`text-start`:wc();break;case`text-delta`:Cc(e.text);break;case`thinking-delta`:wc(),Ss(e.ts,e.text);break;case`tool-start`:wc(),ys(e.ts,e.toolCallId,e.toolName,e.args);break;case`tool-end`:xs(e.toolCallId,e.isError,e.output);break;case`turn-end`:Ip=!1,Ec(e.text,e.meta),e.meta&&nf(e.meta);break;case`queue-state`:Ol(e.steering,e.followUp);break;case`queue-recovery`:Dl(e.batches,e.uncertain);break;case`context-compacted`:wc(),W(`system`,`Context compacted — ${Se(e.before)} → ${Se(e.after)}`,!1,e.ts),Is();break;case`error`:_s(),W(`error`,e.message);break;case`state`:e.state===`idle`&&Ip&&(Ip=!1,Dc()),e.state===`idle`&&Ol([],[]),Gp(e.state)}}function qp(){let e=new EventSource(`/api/events`);e.onopen=()=>{Bp(),ap(),op(),sp()},e.onerror=()=>Hc(e,`Workspace`),e.onmessage=e=>{let t=JSON.parse(e.data);if(t.type===`sessions-changed`){Bp();return}if(t.type===`tasks-changed`||t.type===`task-run-changed`||t.type===`task-message-changed`||t.type===`task-group-changed`){ap(t.type===`task-run-changed`?t.taskId:void 0),op(),sp(),t.type===`task-run-changed`&&Bp();return}if(sp(),t.sessionId===$)return;let n=Op.find(e=>e.id===t.sessionId);n&&(n.state=t.state,ed())}}function Jp(e,t,n){Pp?.close();let r=new EventSource(`/api/sessions/${e}/events?after=${t}`),i=()=>Pp===r&&$===e&&n===jp;r.onmessage=e=>{i()&&Kp(JSON.parse(e.data))},r.addEventListener(`reset`,()=>{i()&&Xp(e)}),r.onerror=()=>{i()&&Hc(r,`Session`)},Pp=r}async function Yp(e){vp(),_u(),wp(e),!(e===$&&(Pp||Mp))&&(++Ap,++jp,Lp=!1,zl(),$=e,kp=null,Op.some(t=>t.id===e)||Up(e),Np=Op.find(t=>t.id===e)?.state??`idle`,Bl(e),ed(),of(),Vp(),await Xp(e))}async function Xp(e){if($!==e)return;let t=++jp;Pp?.close(),Pp=null,Mp=!0,Oc(),Ol([],[]),Dl([]),ef(),Ip=!1,wl(),Fp=0,kc(!0);let n=await C(`/api/sessions/${e}/history`,`failed to load session`);if($!==e||t!==jp)return;if(Mp=!1,!n.ok){kc(!1),W(`error`,n.error);return}let r=n.value;Ac(r.turns,r.state,r.backgroundRuns),Fp=r.lastSeq,Ip=r.state===`streaming`,Gp(r.state),Ol(r.queue.steering,r.queue.followUp),Dl(r.queueRecovery,r.queueUncertain);let i=r.turns.reduce((e,t)=>t.meta?.completedAt??e,null);tf(r.model,r.context,r.thinkingLevel,i),Jp(e,`${r.epoch}:${r.lastSeq}`,t)}Rc(),ve(),Vc(),Ef();var Zp=async e=>{$===e&&await Xp(e)};Os({sessionId:()=>$,sessionCwd:()=>Hp()?.cwd??null,sessionChannel:()=>Hp()?.channel??null,sessionState:()=>Np,select:e=>void Yp(e),showRun:pp,send:(e,t)=>void Ul(e,t),ownTurn:e=>{Cl(e),Gp(`streaming`)},reload:Zp}),Kl({sessionId:()=>$,starting:()=>Lp,sessionState:()=>Np,chatVisible:Vf,setState:Gp,reload:Zp}),Pu({sessionMenu:e=>{let t=Hp();t&&vf(e,t)},sessionInfo:e=>{let t=Hp();t&&df(e,t)}}),nd({sessions:()=>Op,currentId:()=>$,select:e=>void Yp(e),sessionMenu:vf,createSession:Rp,onTitleChanged:of}),Fd({sessions:()=>Op,loadSessions:Bp,currentId:()=>$,select:Yp,createSession:Rp,openConsole:lp}),Ud({currentId:()=>$,currentSession:Hp,createSession:e=>void Rp(e),syncBar:cp,openFiles:mp,toggleFiles:gp}),Dp({sessions:()=>Op,loadSessions:Bp,currentId:()=>$,currentSession:Hp,select:e=>void Yp(e),maybeAckRead:Vp}),Lf(`0.1.12`),su(),document.addEventListener(`gesturestart`,e=>e.preventDefault()),document.addEventListener(`visibilitychange`,Vp),window.addEventListener(`focus`,Vp),qp(),Bp().then(Tp);export{He as $,Fi as A,Oi as B,ji as C,Ni as D,xi as E,mi as F,Zr as G,pi as H,Di as I,ui as J,ti as K,R as L,fi as M,gi as N,Pi as O,Mi as P,Qr as Q,hi as R,Ai as S,di as T,Ii as U,ki as V,Xr as W,I as X,ei as Y,Yr as Z,Ci as _,tl as a,x as at,_i as b,ja as c,_ as ct,ba as d,h as dt,S as et,va as f,l as ft,bi as g,Qi as h,a as ht,fu as i,Ke as it,Ei as j,Si as k,Oa as l,_e as lt,ta as m,o as mt,Hd as n,Ge as nt,No as o,ze as ot,na as p,s as pt,ai as q,Vd as r,We as rt,Po as s,xe as st,df as t,C as tt,B as u,ue as ut,wi as v,L as w,vi as x,yi as y,Ti as z};
|
|
85
|
+
`),r}var Zu=()=>`${Y.currentId()??``}\n${$u}\n${JSON.stringify(Y.sessions())}`,Qu=``,$u=20;function ed(){let e=Zu();if(e===Qu)return;Qu=e;let t=Y.sessions(),n=t.filter(Uu);ku(n.length),du(n.length);let{rows:r,hidden:i}=zu(t,$u),a=Fu.querySelector(`.session-more[aria-expanded='true']`),o=a?.closest(`[data-session-id]`)?.dataset.sessionId,s=r.map(e=>Xu(e,e.id===o?a:void 0));if(i>0){let e=I(`button`,`session-open w-full cursor-pointer rounded-lg text-left text-sm text-neutral-500`,`Load more (${i})`);e.id=`session-load-more`,e.setAttribute(`type`,`button`),e.onclick=()=>{$u+=20,ed(),Fu.querySelectorAll(`.session-open`)[r.length]?.focus()},s.push(I(`li`,`hover:bg-neutral-100`,e))}let c=document.activeElement,l=c?.closest(`[data-session-id]`)?.dataset.sessionId,u=c?.classList.contains(`session-more`)?`.session-more`:`.session-open`;if(Fu.replaceChildren(...s.length?[I(`ul`,`pb-1`,...s)]:[I(`p`,`px-3 py-2 text-sm leading-normal text-neutral-500`,`No sessions yet — create one.`)]),l){let e=[...Fu.querySelectorAll(`[data-session-id]`)].find(e=>e.dataset.sessionId===l);e?.querySelector(`.session-open`)?.focus({preventScroll:!0}),u===`.session-more`&&e?.querySelector(u)?.focus({preventScroll:!0})}else c?.id===`session-load-more`&&(Fu.querySelector(`#session-load-more`)??Fu.querySelector(`.session-open`)??F(`#new-session`)).focus({preventScroll:!0});Nd()}function td(){if(Iu.getAttribute(`aria-expanded`)===`true`)return B();let e=Y.sessions().find(e=>e.id===Y.currentId())?.cwd,t=Ve(Y.sessions()).slice(0,Vu);if(e&&!t.includes(e)&&t.unshift(e),!t.length)return Da(Iu,void 0,Y.createSession);Oa(Iu,t.map(e=>({path:e,hint:Zr(e)})),e,Y.createSession)}function nd(e){Y=e,Iu.onclick=td,Qc(Iu,`shift+o`,`New session`,td,Jc);let t=e=>{let t=Bu(Y.sessions(),Y.currentId(),e);t&&Y.select(t)};nl(`shift+[`,()=>t(-1),Jc),nl(`shift+]`,()=>t(1),Jc)}var rd,id=F(`#palette`),ad=F(`#palette-input`),od=F(`#palette-list`),sd=F(`#palette-count`),cd=[{name:`tasks`,icon:re,label:`Tasks`,detail:`Automation — task definitions and schedules`},{name:`runs`,icon:re,label:`Runs`,detail:`Automation — executions, subagents and callbacks`},{name:`activity`,icon:re,label:`Activity`,detail:`Automation — sessions and relationships`},{name:`boards`,icon:ne,label:`Boards`,detail:`Console — the static pages Pier publishes`},{name:`settings`,icon:pe,label:`Settings`,detail:`Console — models and providers, agent files and extensions, channels, password, sign out, security`}],ld=7,ud=3,dd=8,fd=80,pd=``,md,hd,gd;function _d(e){pd!==e&&(clearTimeout(gd),hd?.abort(),hd=void 0,pd=e,md=void 0,e&&(gd=setTimeout(()=>{let t=hd=new AbortController;C(`/api/search?q=${encodeURIComponent(e)}`,`Search unavailable`,{signal:t.signal}).then(n=>{t.signal.aborted||pd!==e||(hd=void 0,md=n.ok?{hits:n.value.hits}:{error:n.error},id.open&&Md())})},fd)))}var vd=[],yd=0;function bd(e){if(vd.length){yd=(e+vd.length)%vd.length;for(let[e,{el:t}]of vd.entries())t.classList.toggle(`bg-indigo-50`,e===yd),t.setAttribute(`aria-selected`,String(e===yd));vd[yd]?.el.scrollIntoView({block:`nearest`})}}var xd=e=>e.hit?.at??e.session?.createdAt;function Sd(e){let t=I(`span`,`min-w-0 flex-1 truncate text-neutral-500`);for(let n of e.replaceAll(/\s+/g,` `).split(``)){let[e=``,r]=n.split(``,2);r===void 0?t.append(e):t.append(I(`span`,`font-medium text-neutral-800`,e),r)}return t}var Cd=`flex min-w-0 flex-1 items-baseline gap-2`,wd=`shrink-0 truncate`,Td=`min-w-[2.5em] truncate text-[0.8125rem] text-neutral-400`,Ed=`flex-none text-[0.75rem] tabular-nums text-neutral-400`,Dd=`flex h-7 w-7 flex-none items-center justify-center rounded-[8px] bg-neutral-100 text-neutral-500`;function Od(e){let t=I(`li`,`palette-row flex cursor-pointer items-center gap-3 rounded-[10px] px-2 leading-5 ${e.hit?`py-1.5`:`min-h-10`}`);t.setAttribute(`role`,`option`),t.append(I(`span`,Dd,_(e.icon,`h-4 w-4`)));let n=I(`div`,`flex min-w-0 flex-1 flex-col`),r=I(`div`,`flex items-center gap-2`);e.session&&r.append(...Ku(e.session));let i=I(`span`,Cd,I(`span`,`${wd} ${e.detail?`max-w-[calc(100%-3em)]`:`max-w-full`}`,e.label));e.detail&&i.append(I(`span`,Td,e.detail)),r.append(i);let a=xd(e);return a!==void 0&&r.append(I(`span`,Ed,Yr(a))),n.append(r),e.hit&&n.append(I(`div`,`flex items-baseline gap-2 text-[0.8125rem] leading-5`,I(`span`,`flex-none text-[0.75rem] text-neutral-400`,e.hit.role===`user`?`You`:`Agent`),Sd(e.hit.snippet))),t.append(n),t.onclick=e.open,t}var kd=e=>I(`li`,`px-2 pb-1.5 pt-4 text-[0.6875rem] font-semibold leading-4 tracking-[0.02em] text-neutral-400 first:pt-2`,e);function Ad(e,t){let n=I(`li`,`px-2 py-2 pl-12 text-[0.8125rem] leading-5 text-neutral-400`,e);return t&&(n.title=t),n}var jd=e=>e.channel&&e.channel!==`web`?e.channel:``;function Md(){let e=ad.value.trim(),t=e.toLowerCase().split(/\s+/).filter(Boolean),n=e=>{let n=e.toLowerCase();return t.every(e=>n.includes(e))},r=e=>()=>{id.close(),e()},i=rd.sessions(),a=new Map(i.map(e=>[e.id,e])),{top:o,rest:s}=Ru(i),c=[...o,...s],l=e=>({icon:ae,label:e.title??Qr(e.cwd),detail:[Zr(e.cwd),jd(e)].filter(Boolean).join(` · `),open:r(()=>void rd.select(e.id)),session:e}),u=e=>({icon:te,label:Qr(e),detail:e,open:r(()=>void rd.createSession(e))}),d=cd.filter(t=>!e||n(`${t.label} ${t.detail}`)).map(({name:e,icon:t,label:n,detail:i})=>({icon:t,label:n,detail:i,open:r(()=>rd.openConsole(e))})),f={icon:te,label:`New session in…`,detail:`Pick a directory`,open:r(td)},p=[];if(e){let t=Ve(i).filter(e=>n(Zr(e))).slice(0,ud),o=c.filter(e=>n(`${e.title??``} ${e.cwd} ${jd(e)}`)).slice(0,dd),s=new Set(o.map(e=>e.id)),m=o.map(l);if(pd!==e||!md)m.push(Ad(`Searching messages…`));else if(`error`in md)m.push(Ad(`Message search unavailable`,md.error));else{for(let e of md.hits){if(m.length>=dd)break;let t=a.get(e.sessionId);!t||s.has(t.id)||m.push({...l(t),hit:e,open:r(()=>void rd.select(t.id).then(()=>Rs(e.role,e.at)))})}m.length||m.push(Ad(`No sessions match`))}p.push([`Actions`,[...t.map(u),...n(f.label)?[f]:[],...d]],[`Sessions`,m])}else{let e=a.get(rd.currentId()??``);p.push([`Running`,c.filter(Gu).map(l)],[`Recent`,c.filter(e=>!Gu(e)).slice(0,ld).map(l)],[`Actions`,[...e?[u(e.cwd)]:[],f]],[`Console`,d])}vd=[];let m=[];for(let[e,t]of p)if(t.length){m.push(kd(e));for(let e of t){if(e instanceof HTMLElement){m.push(e);continue}let t=Od(e);vd.push({el:t,open:e.open}),m.push(t)}}od.replaceChildren(...m.length?m:[Ad(`Nothing matches`)]),sd.textContent=`${vd.length} ${vd.length===1?`row`:`rows`}`,bd(Math.min(yd,Math.max(0,vd.length-1)))}function Nd(){id.open&&Md()}function Pd(){if(id.open)return id.close();ad.value=``,yd=0,_d(``),Md(),id.showModal(),ad.focus(),rd.loadSessions().then(Nd)}function Fd(e){rd=e;let t=F(`#open-palette`);t.onclick=Pd,Qc(t,`k`,`Search sessions, messages and Console`,Pd,()=>id.open||la()),id.onclick=e=>{e.target===id&&id.close()},id.onclose=()=>_d(``),ad.oninput=()=>{yd=0,_d(ad.value.trim()),Md()},ad.onkeydown=e=>{let t=ua(e);if(t!==void 0){e.preventDefault(),bd(yd+t);return}e.key===`Enter`&&!e.ctrlKey&&(e.preventDefault(),vd[yd]?.open())}}var Id=0,Ld=e=>`${e.provider}/${e.id}`,Rd=null;async function zd(){let{modelMenu:e}=await Ge(`/api/settings`,`Could not read the pinned model menu`);return e}function Bd(e){let t=I(`button`,`flex w-full min-w-0 cursor-pointer items-center gap-2 px-3 py-1.5 text-left hover:bg-neutral-100`,_(o,`h-3 w-3 text-indigo-600 ${e.checked?``:`invisible`}`),I(`span`,`truncate`,e.label));return e.hint&&t.append(I(`span`,`ml-auto flex-none text-[11.5px] text-neutral-400`,e.hint)),e.title&&(t.title=e.title),t.onclick=()=>e.onSelect(),t}function Vd({models:e,current:t,thinkingLevel:n,thinkingLevels:r,onPick:i,onThinkingPick:a}){let o=n,s=I(`div`,`flex w-full min-w-0 flex-col sm:min-w-72`),c=I(`div`,`flex flex-col gap-2 border-b border-neutral-200 px-2 py-2`),u=document.createElement(`input`);if(u.type=`search`,u.placeholder=`Search models`,u.setAttribute(`aria-label`,`Search models`),u.className=`w-full rounded-md border border-neutral-300 px-2 py-1.5 text-[12.5px] focus:border-indigo-400 focus:outline-none`,c.append(u),r.length){let e=document.createElement(`details`),t=I(`span`,`ml-auto font-medium text-indigo-700`,xe(o)),n=I(`summary`,`flex min-h-11 cursor-pointer list-none items-center gap-2 rounded-xl px-3 text-sm text-neutral-700 hover:bg-neutral-100 [&::-webkit-details-marker]:hidden`,I(`span`,`font-medium`,`Reasoning effort`),t,_(l,`chev h-3 w-3 text-neutral-400`)),i=I(`fieldset`,`grid grid-cols-2 gap-1 rounded-xl bg-neutral-50 p-1`);i.append(I(`legend`,`sr-only`,`Reasoning effort`));let s=`reasoning-${++Id}`;for(let e of r){let n=document.createElement(`input`);n.type=`radio`,n.name=s,n.value=e,n.checked=e===o,n.className=`peer sr-only`,n.onchange=()=>{n.checked&&(o=e,t.textContent=xe(o),m(u.value),a(o))},i.append(I(`label`,`relative cursor-pointer`,n,I(`span`,`flex min-h-11 items-center rounded-lg border border-transparent px-3 text-sm text-neutral-700 hover:bg-neutral-100 peer-checked:border-indigo-200 peer-checked:bg-indigo-50 peer-checked:font-semibold peer-checked:text-indigo-700 peer-focus-visible:outline-2 peer-focus-visible:outline-indigo-500`,xe(e))))}e.append(n,i),c.append(e)}let d=I(`div`,`max-h-72 overflow-y-auto py-1`),f=new Map(e.map(e=>[Ld(e),e])),p=e=>{let n=(Rd??[]).map(e=>({e,model:f.get(Ld(e))})).filter(t=>!!t.model&&(!e||Ld(t.model).toLowerCase().includes(e)));n.length&&d.append(I(`div`,`px-3 pb-0.5 pt-1 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,`Pinned`),...n.map(({e,model:n})=>Bd({label:n.id,hint:xe(e.thinking),title:e.note,checked:!!t&&Ld(t)===Ld(n)&&o===e.thinking,onSelect:()=>i(n,e.thinking)})),I(`div`,`my-1 border-t border-neutral-100`))},m=n=>{d.replaceChildren();let r=n.trim().toLowerCase();p(r);let a=new Map;for(let t of e){if(r&&!Ld(t).toLowerCase().includes(r))continue;let e=a.get(t.provider);e?e.push(t):a.set(t.provider,[t])}if(!a.size){d.append(I(`div`,`px-3 py-2 text-[12.5px] text-neutral-400`,e.length?`No matching models.`:`No models available.`));return}for(let[e,n]of a){let a=n.some(e=>!!t&&Ld(t)===Ld(e)),o=document.createElement(`details`);o.open=a||r.length>0;let s=I(`summary`,`flex cursor-pointer select-none items-center gap-1.5 px-3 py-1 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400 hover:bg-neutral-100`,_(l,`chev h-3 w-3`),I(`span`,`truncate`,e),I(`span`,`ml-auto flex-none normal-case text-neutral-300`,String(n.length)));o.append(s,...n.map(e=>Bd({label:e.id,checked:!!t&&Ld(t)===Ld(e),onSelect:()=>i(e)}))),d.append(o)}};return u.oninput=()=>m(u.value),m(``),zd().then(e=>{let t=JSON.stringify(e)!==JSON.stringify(Rd);Rd=e,t&&m(u.value)}).catch(e=>Lc(`model menu unavailable`,e)),s.append(c,d),queueMicrotask(()=>u.focus()),s}function Hd(e,t,n,r){let i=L(t.model?`${t.model.id}${t.thinking?` · ${xe(t.thinking)}`:``}`:t.thinking?`Pi default · ${xe(t.thinking)}`:`Pi default`,`${wi} flex items-center gap-1.5 ${t.model?`text-neutral-700`:`text-neutral-400`}`);return i.title=t.model?`${t.model.provider}/${t.model.id}`:`Whatever the project and Pi pick`,i.onclick=()=>{let e=Vd({models:n,current:t.model,thinkingLevel:t.thinking??`medium`,thinkingLevels:[...No],onPick:(e,n)=>{B(),r({model:e,thinking:n??t.thinking})},onThinkingPick:e=>{t={...t,thinking:e},r(t)}}),a=L(`Pi default`,`w-full cursor-pointer px-3 py-1.5 text-left text-[12.5px] text-neutral-500 hover:bg-neutral-100`);a.onclick=()=>{B(),r({model:null,thinking:null})};let o=I(`div`,`flex flex-col`);o.append(e,I(`div`,`border-t border-neutral-200`),a),va(i,o)},Si(e,i)}var X;function Ud(e){X=e,nl(Wd,()=>{X.currentSession()&&(B(),X.toggleFiles())},Jc)}var Wd=`i`,Gd=F(`#chat-title`),Kd=F(`#chat-menu`),qd=F(`#session-meta`),Jd=null,Yd=new Map,Xd=e=>`${e.provider}/${e.id}`,Z=null,Zd=null,Qd=null,$d=null;function ef(){Z=null,Zd=null,Qd=null,$d=null,uf()}function tf(e,t,n,r){Z=e,Zd=t,Qd=n,$d=r,of()}function nf(e){$d=e.completedAt,Zd&&={...Zd,tokens:e.tokens},uf()}var rf=null;function af(e){rf=e===null?null:Qr(e),of()}function of(){let e=X.currentSession();e&&(rf=null),Gd.textContent=e?e.title??Qr(e.cwd):rf??X.currentId()??`no session`,Gd.classList.toggle(`cursor-pointer`,!!e),Gd.title=e?`Session info`:``,Gd.onclick=e?()=>df(Gd,e):null,Kd.classList.toggle(`hidden`,!e),e&&(Kd.onclick=()=>vf(Kd,e)),uf(),X.syncBar()}var sf=70,cf=(e,t)=>Math.min(100,Math.round(e/t.contextWindow*100)),lf=e=>e.tokens===null?`?/${Se(e.contextWindow)}`:`${Se(e.tokens)}/${Se(e.contextWindow)} · ${100-cf(e.tokens,e)}% left`;function uf(){let e=Zd,t=e?.tokens??null,n=X.currentId(),r=X.currentSession()?.activeRuns??0,i=[];if(r>0){let e=I(`button`,`flex flex-none cursor-pointer items-center gap-1 rounded bg-sky-50 px-1.5 py-px font-medium text-sky-700 hover:bg-sky-100`,_(h,`spinner h-3 w-3`),`${r} running`);e.title=`${Wu(r)} · show the newest`,e.onclick=()=>{zs()||W(`error`,`no run card left in this transcript — reload the session to see it`)},i.push(e)}if(!n&&rf&&i.push(I(`span`,`flex flex-none items-center gap-1.5 text-neutral-500`,_(h,`spinner`),`starting…`)),n){let e=(e,t)=>{let r=I(`button`,`cursor-pointer font-mono ${t}`,e);return r.title=`Change model or reasoning`,r.onclick=()=>void ff(r,n),r};Z&&i.push(e(Z.id,`min-w-0 truncate rounded bg-indigo-50 px-1.5 py-px font-medium text-indigo-700 hover:bg-indigo-100`)),Qd&&i.push(e(Qd,`flex-none text-neutral-500 hover:text-indigo-700`))}let a=0;if(e&&t!==null){a=cf(t,e);let n=a>=90?`text-red-700`:a>=sf?`text-amber-700`:`text-neutral-500`;i.push(I(`span`,`flex-none font-mono ${n}`,Se(t).toLowerCase()))}let o=i.flatMap((e,t)=>t===0?[e]:[I(`span`,`flex-none text-neutral-300`,`·`),e]);qd.replaceChildren(...o),qd.classList.toggle(`hidden`,i.length===0),qd.classList.toggle(`flex`,i.length>0),qd.toggleAttribute(`data-urgent`,!n&&!!rf||r>0||a>=sf)}function df(e,t,n){let i=[[`Directory`,t.cwd],[`Session`,t.id]],a=t.id===X.currentId();if(a&&(i.push([`Model`,Z?.id??`—`]),i.push([`Reasoning`,Qd??`—`]),i.push([`Context`,Zd?lf(Zd):`—`])),i.push([`Created`,$r(t.createdAt),Xr(t.createdAt)]),a){let e=$d;i.push(e===null?[`Last reply`,`—`]:[`Last reply`,$r(e),Xr(e)])}let o=I(`div`,`w-[min(26rem,calc(100vw-2rem))] max-sm:w-full rounded-xl bg-white px-3 py-3 font-sans text-[15px] leading-normal`),s=I(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,_(_e));s.setAttribute(`aria-label`,`Close session info`),s.onclick=B;let c=I(`div`,`sticky top-0 z-10 flex items-start gap-2 bg-white pb-2`,I(`div`,`min-w-0 flex-1`,I(`div`,`text-sm font-medium text-neutral-500`,`Session info`),I(`h2`,`mt-1 [overflow-wrap:anywhere] text-lg leading-7 font-semibold text-neutral-900`,t.title??Qr(t.cwd))),s);if(n){let e=I(`button`,`icon-btn h-11 w-11 sm:h-8 sm:w-8`,_(r));e.setAttribute(`aria-label`,`Back to session actions`),e.onclick=n,c.prepend(e)}o.append(c);let l=I(`dl`,``);for(let[e,t,n]of i){let r=e===`Directory`||e===`Session`,i=I(`dd`,`min-w-0 flex items-start gap-2 text-neutral-700 ${r?`font-mono text-sm leading-6`:``}`,I(`span`,`min-w-0 flex-1 [overflow-wrap:anywhere]`,t));if(r){let n=ai(`min-h-11 min-w-11 sm:min-h-8 shrink-0 cursor-pointer rounded-lg px-2 py-1 text-[13px] font-sans text-neutral-500 hover:bg-neutral-100 focus-visible:outline-2`,()=>t);n.setAttribute(`aria-label`,`Copy ${e.toLowerCase()}`),i.append(n)}n&&i.firstElementChild?.append(I(`span`,`ml-2 inline-block font-sans text-[13px] leading-5 text-neutral-500`,n));let a=e===`Model`||e===`Created`;l.append(I(`div`,`grid gap-1 py-1.5 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-3 ${a?`mt-2 border-t border-neutral-200 pt-2.5`:``}`,I(`dt`,`text-[15px] text-neutral-500`,e===`Session`?`Session ID`:e),i))}return o.append(l),va(e,o)}async function ff(e,t,n){let r=I(`div`,`px-3 py-3 text-[15px] text-neutral-500`,`Loading models…`),i=I(`div`,`w-[min(24rem,calc(100vw-2rem))] min-w-0 max-sm:w-full`,r),a=r;n&&i.prepend(gf(e,n,`Close model picker`)),va(e,i);let o=()=>a.isConnected&&!a.closest(`[inert]`),s=``,c=(n,r,o)=>{let c=JSON.stringify([n,r,o]);if(c===s)return;s=c;let l=Vd({models:n,current:t===X.currentId()?Z:null,thinkingLevel:r,thinkingLevels:o,onPick:(e,n)=>{B(),pf(t,e,n)},onThinkingPick:e=>void hf(t,e)});a.replaceWith(l),a=l,va(e,i)},l=t===X.currentId()&&Z?Yd.get(Xd(Z)):void 0;Jd&&l&&Qd&&c(Jd,Qd,l);try{let[e,n]=await Promise.all([Ge(`/api/sessions/${t}/models`,`Could not load models`),Ge(`/api/sessions/${t}/thinking`,`Could not read the reasoning level`)]);if(Jd=e,t===X.currentId()&&Z&&Yd.set(Xd(Z),n.levels),!o())return;c(e,n.level,n.levels)}catch(e){s?W(`error`,`model options are stale: ${String(e)}`):o()?(r.textContent=`Could not load models: ${String(e)}`,r.setAttribute(`role`,`alert`)):W(`error`,`model options failed: ${String(e)}`)}}async function pf(e,t,n){await mf(e,t)&&n&&await hf(e,n)}async function mf(e,t){let n=Z;e===X.currentId()&&(Z=t,of());let r=await x(`/api/sessions/${e}/model`,t);if(!r.ok){let{error:t}=await r.json().catch(()=>({}));return e===X.currentId()&&(Z=n,of()),W(`error`,`model change failed: ${t??r.status}`),!1}let{model:i}=await r.json();return e===X.currentId()&&i&&(Z=i,of()),!0}async function hf(e,t){let n=await x(`/api/sessions/${e}/thinking`,{level:t});if(!n.ok){W(`error`,`reasoning change failed: ${n.status}`);return}let{level:r}=await n.json();e===X.currentId()&&(Qd=r,uf())}function gf(e,t,n){let i=I(`button`,`icon-btn h-11 w-11`,_(r));i.setAttribute(`aria-label`,`Back to session actions`),i.onclick=()=>vf(e,t);let a=I(`button`,`icon-btn h-11 w-11`,_(_e));a.setAttribute(`aria-label`,n),a.onclick=B;let o=I(`span`,`min-w-0 flex-1 truncate text-sm font-medium`,t.title??Qr(t.cwd));return o.title=o.textContent??``,I(`div`,`flex items-center gap-2 border-b border-neutral-200 pb-2 mb-2`,i,o,a)}async function _f(e,t){let n=I(`p`,`px-3 py-2 text-[15px] text-neutral-500`,`Loading chats…`),r=I(`div`,`w-[min(24rem,calc(100vw-2rem))] min-w-0 max-sm:w-full`,gf(e,t,`Close chat picker`),I(`div`,`px-3 pb-1 text-sm font-medium text-neutral-500`,`Continue in a direct message`),I(`p`,`px-3 pb-2 text-[13px] text-neutral-500`,`DMs the bot has seen. A DM appears here after its first message to the bot.`),n);va(e,r);let i=await C(`/api/handoff/targets`,`Could not list chats`);if(!r.isConnected)return;if(!i.ok){n.textContent=i.error,n.setAttribute(`role`,`alert`);return}if(!i.value.targets.length){n.textContent=`No DMs yet — message the bot once in Lark or Slack, then come back.`;return}let a=I(`p`,`hidden px-3 pt-1 text-[13px] text-red-600`);a.setAttribute(`role`,`alert`);let o=I(`div`,``);o.dataset.list=``;for(let e of i.value.targets){let n=I(`button`,`flex w-full min-h-10 cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-left transition-colors hover:bg-indigo-50 hover:text-indigo-700 active:bg-indigo-100`,I(`span`,`min-w-0 truncate`,`${e.platform[0].toUpperCase()}${e.platform.slice(1)} · ${e.name||e.chatId}`));n.onclick=async()=>{let n=await x(`/api/handoff`,{sessionId:t.id,platform:e.platform,chatId:e.chatId});if(n.ok)return B();a.textContent=(await n.json().catch(()=>({}))).error??`handoff failed: ${String(n.status)}`,a.classList.remove(`hidden`)},o.append(n)}n.replaceWith(o,a),o.querySelector(`button`)?.focus({preventScroll:!0})}function vf(e,t){let n=t.id===X.currentId();ba(e,[{label:`Rename…`,onSelect:()=>{B(),qu(t)}},{label:`Session info`,onSelect:()=>df(e,t,()=>vf(e,t))},{label:`New session here`,separatorBefore:!0,hint:Zr(t.cwd),onSelect:()=>{B(),X.createSession(t.cwd)}},{label:`Browse files`,hint:n?qc(Wd):``,onSelect:()=>{B(),X.openFiles(n?void 0:t.cwd)}},{label:`Continue in Lark/Slack…`,...t.channel&&t.channel!==`web`?{hint:`answers in ${t.channel}`,disabled:!0}:{},onSelect:()=>void _f(e,t)},{label:`Model & reasoning…`,separatorBefore:!0,hint:n?Z?.id??`…`:``,onSelect:()=>void ff(e,t.id,t)}],t.title??Qr(t.cwd))}var yf=`pier.theme`,bf=[`system`,`light`,`dark`],xf=window.matchMedia(`(prefers-color-scheme: dark)`),Sf={system:se,light:he,dark:g},Cf=()=>{let e=null;try{e=localStorage.getItem(yf)}catch{return`system`}return e===`light`||e===`dark`?e:`system`},wf=()=>{let e=Cf();return e===`system`?xf.matches?`dark`:`light`:e};function Tf(){let e=wf();document.documentElement.dataset.theme=e;let t=getComputedStyle(document.documentElement).getPropertyValue(`--workbench-canvas`).trim();F(`meta[name="theme-color"]`).setAttribute(`content`,t),window.dispatchEvent(new Event(`pier:theme`))}function Ef(){let e=F(`#theme-toggle`),t=()=>{let t=Cf();e.title=`Theme: ${t}${t===`system`?` (${wf()})`:``}`,e.replaceChildren(_(Sf[t])),e.setAttribute(`aria-label`,e.title),Tf()};e.onclick=()=>{let e=bf[(bf.indexOf(Cf())+1)%bf.length];try{e===`system`?localStorage.removeItem(yf):localStorage.setItem(yf,e)}catch{}t()},xf.addEventListener(`change`,t),t()}var Df=`https://github.com/timqi/pier`,Of=[`text-neutral-400`,`hover:text-neutral-700`],kf=[`rounded-full`,`bg-emerald-50`,`px-1.5`,`text-emerald-700`,`ring-1`,`ring-inset`,`ring-emerald-600/20`,`hover:bg-emerald-100`],Af=18e5,jf=null,Mf=F(`#version`);function Nf(e){let t=jf?.available===!0&&jf.latest!==null;Mf.textContent=`v${e}`,Mf.title=t?`Pier ${jf?.latest} is out`:``,Mf.classList.remove(...t?Of:kf),Mf.classList.add(...t?kf:Of)}var Pf=(e,t=`px-3 py-1 text-[12px] leading-snug text-neutral-500`)=>I(`p`,t,e);function Ff(){let e=I(`div`,`flex w-72 flex-col gap-1 py-1`);if(!jf)return e.append(Pf(`Checking the registry…`)),e;let{current:t,latest:n,available:r,canApply:i,problem:a}=jf,o=I(`span`,``,``),s=(e,t)=>R(o,e?`failed`:`idle`,t),c=I(`div`,`flex items-center gap-2 px-3 py-1.5`);if(e.append(Pf(r?`Pier ${n} is out`:`Pier ${t}`,`px-3 py-1 text-[12.5px] font-medium text-neutral-700`),Pf(r?`You are running ${t}.`:n===null?`The registry could not be reached, so this may not be the latest.`:`This is the latest release.`)),a&&e.append(Pf(a,`mx-3 my-1 rounded-md bg-red-50 px-2 py-1.5 text-[11.5px] leading-snug text-red-700`)),r&&i&&!a){let e=di(`Update now`,!0);e.onclick=()=>void(async()=>{e.disabled=!0,s(!1,`starting the updater…`);let t=await x(`/api/update`,{});if(!t.ok)return e.disabled=!1,s(!0,await S(t,`Could not update`));let{draining:n}=await t.json();s(!1,n?`Waiting for running work to finish — Pier then installs and restarts.`:`Installing — Pier restarts once it is on disk, and this page reconnects on its own.`)})(),c.append(e)}c.append(Object.assign(I(`a`,`btn text-[12.5px] no-underline`,`Source`),{href:r?`${Df}/releases`:Df,target:`_blank`,rel:`noreferrer`,title:`Pier is free software (AGPL-3.0)`})),e.append(c,I(`div`,`px-3`,o)),r&&!i&&!a&&e.append(Pf(`No service manager owns this Pier, so it cannot restart itself — update it with: pier update`));let l=ki(`Update automatically`,i?`Installs a new release once nothing is running — no turn in flight, no task run.`:`Needs the systemd service (pier service install); nothing here can restart Pier.`,jf.autoUpdate,e=>void(async()=>{jf&&(jf.autoUpdate=e);let t=await x(`/api/settings`,{autoUpdate:e},`PUT`);t.ok||(jf&&(jf.autoUpdate=!e),u&&(u.checked=!e),s(!0,await S(t,`Could not save`)))})()),u=l.querySelector(`input`);return u&&(u.disabled=!i),e.append(I(`div`,`mt-1 border-t border-neutral-200 px-3 pb-1 pt-2`,l)),e}async function If(e){let t=await C(`/api/update`,`Update check failed`);t.ok&&Nf((jf=t.value).current||e)}function Lf(e){Nf(e),Mf.onclick=e=>{e.preventDefault(),va(Mf,Ff())};let t=()=>void If(e);t(),setInterval(t,Af)}var Q,Rf=F(`#chat-header`),zf=F(`#chat-title`),Bf=[Rf,U,F(`#composer`)],Vf=()=>Jf===null,Hf,Uf,Wf,Gf=new Map,Kf=new Map,qf=new Map,Jf=null,Yf=0,Xf=[`files`],Zf=new Map,Qf={tasks:`Tasks`,runs:`Runs`,activity:`Activity`,boards:`Boards`,settings:`Settings`,files:`Files`},$f=[`tasks`,`runs`,`activity`],ep=`Automation`,tp=F(`#automation-view`),np=F(`#automation-tabs`),rp=e=>$f.includes(e)?`tasks`:e;function ip(e,t){let n=e!==null&&$f.includes(e);if(tp.classList.toggle(`hidden`,!n),tp.classList.toggle(`flex`,n),!n)return;let r=[];if(e===`tasks`&&!t){let e=di(`New task`,!0);e.classList.add(`ml-auto`),e.disabled=!Hf,e.onclick=()=>Hf?.create(),r.push(e)}np.replaceChildren(fi(ep),...$f.map(t=>gi(Qf[t],t===e,()=>lp(t))),...r)}var ap=e=>Hf?.refresh(e),op=()=>Uf?.refresh(),sp=()=>Wf?.refresh();function cp(){Jf?vu($f.includes(Jf)?ep:Qf[Jf],!1):vu(zf.textContent??``,Q.currentSession()!==void 0)}function lp(e,t,n){if(Xf.includes(e)){let t=xp();t&&(t.kind!==`console`||t.name!==e)&&Zf.set(e,t)}Cp({kind:`console`,name:e,arg:t,query:n}),_u(),Jf=e;for(let e of Bf)e.classList.add(`hidden`);El();for(let[t,n]of Gf)t!==e&&n.hide();for(let[t,n]of qf)n.classList.toggle(`bg-indigo-50`,t===rp(e));ip(e,t),cp(),up(e,t,n,++Yf)}async function up(e,t,n,r){let i=Gf.get(e);if(!i){let t=Kf.get(e);if(!t){let n=F(`#${e}-view`);t=Ep[e](n).catch(t=>(console.warn(`${e} view failed to load`,t),ti(n,()=>n.replaceChildren(I(`p`,`p-4 text-[13px] text-red-600`,`Could not load ${Qf[e]} — reload the page.`))))),Kf.set(e,t)}i=await t,Gf.set(e,i),Kf.delete(e)}Jf===e&&r===Yf&&(i.show(t,n),e===`tasks`&&ip(e,t))}var dp=e=>lp(`tasks`,e),fp=(e={},t)=>lp(`runs`,t,new URLSearchParams(e).toString()),pp=e=>fp({},e),mp=(e,t)=>lp(`files`,e,t?new URLSearchParams({select:t}).toString():void 0),hp=(e,t)=>{Jf===e?_p(e):lp(e,t)},gp=e=>hp(`files`,e);function _p(e){let t=Q.currentId(),n=Zf.get(e)??(t?{kind:`session`,id:t}:null);Zf.delete(e),n?Cp(n):(history.replaceState(null,``,`#/`),vp())}function vp(){if(Jf){Jf=null;for(let e of Gf.values())e.hide();for(let e of qf.values())e.classList.remove(`bg-indigo-50`);ip(null);for(let e of Bf)e.classList.remove(`hidden`);El(),cp(),Q.maybeAckRead()}}var yp=e=>e.kind===`session`?`#/session/${encodeURIComponent(e.id)}`:`#/${e.name}${e.arg?`/${encodeURIComponent(e.arg)}`:``}${e.query?`?${e.query}`:``}`,bp={config:`files`,channels:`channels`,providers:`models`};function xp(){let e=location.hash.replace(/^#\/?/,``),t=e.indexOf(`?`),[n=``,r]=(t<0?e:e.slice(0,t)).split(`/`),i=t<0?void 0:e.slice(t+1)||void 0,a;try{a=r?decodeURIComponent(r):void 0}catch{return null}return bp[n]?{kind:`console`,name:`settings`,arg:bp[n]}:Object.hasOwn(Qf,n)?{kind:`console`,name:n,arg:a,query:i}:n===`session`&&a?{kind:`session`,id:a}:null}var Sp=!1;function Cp(e,t=!1){if(Sp)return;let n=yp(e);location.hash!==n&&(t?history.replaceState(null,``,n):location.hash=n)}var wp=e=>Cp({kind:`session`,id:e});function Tp(){let e=xp(),t=Q.sessions(),n=Q.currentId(),r=e?.kind===`session`?e.id:null,{top:i,rest:a}=Ru(t),o=r??n??(i[0]??a[0])?.id??null;Sp=!0;try{o&&o!==n&&Q.select(o),e?.kind===`console`?lp(e.name,e.arg,e.query):vp(),o||of()}finally{Sp=!1}e?.kind!==`console`&&o&&Cp({kind:`session`,id:o},!0)}var Ep={tasks:async e=>Hf=(await Ki(async()=>{let{createTasksView:e}=await import(`./tasks-Bz29caHJ.js`);return{createTasksView:e}},__vite__mapDeps([0,1]))).createTasksView(e,()=>Q.sessions().map(({id:e,cwd:t,title:n})=>({id:e,cwd:t,title:n})),Q.loadSessions,Q.select,()=>Q.currentId(),fp,dp),runs:async e=>Uf=(await Ki(async()=>{let{createRunsView:e}=await import(`./runs-C_AthWcW.js`);return{createRunsView:e}},__vite__mapDeps([2,1]))).createRunsView(e,Q.select,fp,dp),activity:async e=>Wf=(await Ki(async()=>{let{createActivityView:e}=await import(`./activity-Ds6fCHnb.js`);return{createActivityView:e}},[])).createActivityView(e,Q.select,pp),boards:async e=>(await Ki(async()=>{let{createBoardsView:e}=await import(`./boards-BKCj6EwK.js`);return{createBoardsView:e}},[])).createBoardsView(e,Q.select),files:async e=>(await Ki(async()=>{let{createExplorerView:e}=await import(`./explorer-DnTm975c.js`);return{createExplorerView:e}},[])).createExplorerView(e,()=>Q.currentSession(),e=>lp(`files`,e),()=>_p(`files`)),settings:async e=>(await Ki(async()=>{let{createSettingsView:e}=await import(`./settings-DDaAtFlc.js`);return{createSettingsView:e}},[])).createSettingsView(e,()=>Ve(Q.sessions()),e=>lp(`settings`,e),mp)};function Dp(e){Q=e;for(let e of[`tasks`,`boards`,`settings`]){let t=F(`#open-${e}`);qf.set(e,t),t.onclick=()=>lp(e)}let t=F(`#console-section`);t.open=localStorage.getItem(`pier.consoleCollapsed`)!==`1`,t.ontoggle=()=>localStorage.setItem(`pier.consoleCollapsed`,t.open?`0`:`1`),window.onhashchange=Tp}var Op=[],kp=null,Ap=0,jp=0,Mp=!1,$=null,Np=`idle`,Pp=null,Fp=0,Ip=!1,Lp=!1;async function Rp(e){let t=++Ap;++jp,Mp=!1,vp(),_u(),$=null,Pp?.close(),Pp=null,Oc(),Dl([]),ef(),af(e),kc(!0),Lp=!0,Tl();let n=await x(`/api/sessions`,{cwd:e});if(t!==Ap)return;if(Lp=!1,!n.ok){kc(!1),af(null),Tl(),W(`error`,`session create failed: ${n.status}`);return}let{id:r}=await n.json();t===Ap&&(Op.unshift({id:r,cwd:e,createdAt:Date.now(),state:`idle`,unread:!1,channel:`web`,activeRuns:0}),await Yp(r),$===r&&xl())}function zp(e){Op=e.map(e=>({...e,title:ze(e.title)})),Op.sort((e,t)=>t.createdAt-e.createdAt),ed(),of(),Vp()}var Bp=He(async()=>{zp(await Ge(`/api/sessions`,`Could not load sessions`))});function Vp(){if(document.hidden||!document.hasFocus()||!Vf())return;let e=Op.find(e=>e.id===$);e?.unread&&(e.unread=!1,ed(),fetch(`/api/sessions/${e.id}/read`,{method:`POST`}))}function Hp(){return Op.find(e=>e.id===$)??(kp&&kp.id===$?kp:void 0)}async function Up(e){let t=await C(`/api/sessions/${e}`,`failed to load session`);$!==e||!t.ok||(kp={...t.value,title:ze(t.value.title)},of())}function Wp(e,t){let n=Op.find(t=>t.id===e);!n||n.title||!t.trim()||(n.title=t.trim().slice(0,80),ed(),of())}function Gp(e){Np=e;let t=Op.find(e=>e.id===$);t&&(t.state=e),ed(),of(),Tl(),e===`idle`&&Bp()}function Kp(e){if(!(e.sessionId!==$||e.seq<=Fp))switch(Fp=e.seq,e.type){case`turn-start`:Ip=!0;break;case`system-input`:wc(),Xs(e.text,e.origin);break;case`task-status`:qo(e.run);break;case`user-message`:{let t=Ie(e.text).text;if(Wp(e.sessionId,t),Sl(t))break;wc(),W(`user`,e.text,!1,e.ts),Is();break}case`text-start`:wc();break;case`text-delta`:Cc(e.text);break;case`thinking-delta`:wc(),Ss(e.ts,e.text);break;case`tool-start`:wc(),ys(e.ts,e.toolCallId,e.toolName,e.args);break;case`tool-end`:xs(e.toolCallId,e.isError,e.output);break;case`turn-end`:Ip=!1,Ec(e.text,e.meta),e.meta&&nf(e.meta);break;case`queue-state`:Ol(e.steering,e.followUp);break;case`queue-recovery`:Dl(e.batches,e.uncertain);break;case`context-compacted`:wc(),W(`system`,`Context compacted — ${Se(e.before)} → ${Se(e.after)}`,!1,e.ts),Is();break;case`error`:_s(),W(`error`,e.message);break;case`state`:e.state===`idle`&&Ip&&(Ip=!1,Dc()),e.state===`idle`&&Ol([],[]),Gp(e.state)}}function qp(){let e=new EventSource(`/api/events`);e.onopen=()=>{Bp(),ap(),op(),sp()},e.onerror=()=>Hc(e,`Workspace`),e.onmessage=e=>{let t=JSON.parse(e.data);if(t.type===`sessions-changed`){Bp();return}if(t.type===`tasks-changed`||t.type===`task-run-changed`||t.type===`task-message-changed`||t.type===`task-group-changed`){ap(t.type===`task-run-changed`?t.taskId:void 0),op(),sp(),t.type===`task-run-changed`&&Bp();return}if(sp(),t.sessionId===$)return;let n=Op.find(e=>e.id===t.sessionId);n&&(n.state=t.state,ed())}}function Jp(e,t,n){Pp?.close();let r=new EventSource(`/api/sessions/${e}/events?after=${t}`),i=()=>Pp===r&&$===e&&n===jp;r.onmessage=e=>{i()&&Kp(JSON.parse(e.data))},r.addEventListener(`reset`,()=>{i()&&Xp(e)}),r.onerror=()=>{i()&&Hc(r,`Session`)},Pp=r}async function Yp(e){vp(),_u(),wp(e),!(e===$&&(Pp||Mp))&&(++Ap,++jp,Lp=!1,zl(),$=e,kp=null,Op.some(t=>t.id===e)||Up(e),Np=Op.find(t=>t.id===e)?.state??`idle`,Bl(e),ed(),of(),Vp(),await Xp(e))}async function Xp(e){if($!==e)return;let t=++jp;Pp?.close(),Pp=null,Mp=!0,Oc(),Ol([],[]),Dl([]),ef(),Ip=!1,wl(),Fp=0,kc(!0);let n=await C(`/api/sessions/${e}/history`,`failed to load session`);if($!==e||t!==jp)return;if(Mp=!1,!n.ok){kc(!1),W(`error`,n.error);return}let r=n.value;Ac(r.turns,r.state,r.backgroundRuns),Fp=r.lastSeq,Ip=r.state===`streaming`,Gp(r.state),Ol(r.queue.steering,r.queue.followUp),Dl(r.queueRecovery,r.queueUncertain);let i=r.turns.reduce((e,t)=>t.meta?.completedAt??e,null);tf(r.model,r.context,r.thinkingLevel,i),Jp(e,`${r.epoch}:${r.lastSeq}`,t)}Rc(),ve(),Vc(),Ef();var Zp=async e=>{$===e&&await Xp(e)};Os({sessionId:()=>$,sessionCwd:()=>Hp()?.cwd??null,sessionChannel:()=>Hp()?.channel??null,sessionState:()=>Np,select:e=>void Yp(e),showRun:pp,send:(e,t)=>void Ul(e,t),ownTurn:e=>{Cl(e),Gp(`streaming`)},reload:Zp}),Kl({sessionId:()=>$,starting:()=>Lp,sessionState:()=>Np,chatVisible:Vf,setState:Gp,reload:Zp}),Pu({sessionMenu:e=>{let t=Hp();t&&vf(e,t)},sessionInfo:e=>{let t=Hp();t&&df(e,t)}}),nd({sessions:()=>Op,currentId:()=>$,select:e=>void Yp(e),sessionMenu:vf,createSession:Rp,onTitleChanged:of}),Fd({sessions:()=>Op,loadSessions:Bp,currentId:()=>$,select:Yp,createSession:Rp,openConsole:lp}),Ud({currentId:()=>$,currentSession:Hp,createSession:e=>void Rp(e),syncBar:cp,openFiles:mp,toggleFiles:gp}),Dp({sessions:()=>Op,loadSessions:Bp,currentId:()=>$,currentSession:Hp,select:e=>void Yp(e),maybeAckRead:Vp}),Lf(`0.1.14`),su(),document.addEventListener(`gesturestart`,e=>e.preventDefault()),document.addEventListener(`visibilitychange`,Vp),window.addEventListener(`focus`,Vp),qp(),Bp().then(Tp);export{He as $,Fi as A,Oi as B,ji as C,Ni as D,xi as E,mi as F,Zr as G,pi as H,Di as I,ui as J,ti as K,R as L,fi as M,gi as N,Pi as O,Mi as P,Qr as Q,hi as R,Ai as S,di as T,Ii as U,ki as V,Xr as W,I as X,ei as Y,Yr as Z,Ci as _,tl as a,x as at,_i as b,ja as c,_ as ct,ba as d,h as dt,S as et,va as f,l as ft,bi as g,Qi as h,a as ht,fu as i,Ke as it,Ei as j,Si as k,Oa as l,_e as lt,ta as m,o as mt,Hd as n,Ge as nt,No as o,ze as ot,na as p,s as pt,ai as q,Vd as r,We as rt,Po as s,xe as st,df as t,C as tt,B as u,ue as ut,wi as v,L as w,vi as x,yi as y,Ti as z};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e,I as t,K as n,O as r,T as i,X as a,_ as o,ct as s,ft as c,it as l,tt as u}from"./index-
|
|
1
|
+
import{$ as e,I as t,K as n,O as r,T as i,X as a,_ as o,ct as s,ft as c,it as l,tt as u}from"./index-BQo-haPN.js";import{c as d,i as f,n as p,o as m,s as h}from"./task-runs-0pvdITiV.js";function g(g,_,v,y){let b=new URLSearchParams,x=[],S=``,C=a(`div`,`automation-list min-h-0 flex-1 overflow-auto`),w,T={selectedId:null,rawOpen:!1,scrollTop:0,drawn:``},E=(e,t)=>v(Object.fromEntries(e),t),D=e=>{g.querySelector(`[role=alert]`)?.remove();let t=a(`p`,`p-4 text-[13px] text-red-600`,e);t.setAttribute(`role`,`alert`),g.append(t)},O={openSession:_,openTask:y,openRun:e=>E(b,e),mutate:async e=>{let t=await l(e,`POST`,`Run update failed`);t?D(t):await k()}},k=e(async()=>{let e=T.selectedId;if(e)return f(C,e,()=>E(b),O,T);let t=b.toString(),n=await u(`/api/task-runs?${t}`,`Could not load runs`);if(t!==b.toString()||T.selectedId)return;if(!n.ok)return D(n.error);g.querySelector(`[role=alert]`)?.remove();let r=JSON.stringify(n.value);S!==t+r&&(S=t+r,P(n.value))});function A(e,t){let n=new URLSearchParams(b);t?n.set(e,t):n.delete(e),n.delete(`cursor`),E(n)}function j(){if(S=``,C=a(`div`,`automation-list min-h-0 flex-1 overflow-auto`),w=void 0,T.selectedId){g.replaceChildren(C);return}g.replaceChildren(N(),C)}function M(){let e=x.map(e=>[e.name+(e.archived?` (archived)`:``),e.id]),t=b.get(`taskId`);return t&&!x.some(e=>e.id===t)&&e.push([t,t]),[[`All tasks`,``],...e]}function N(){let e=a(`div`,`automation-filters run-filters`),n=(n,r,i)=>{let o=t(i,b.get(r)??``);return o.dataset.active=String(!!b.get(r)),o.setAttribute(`aria-label`,n),o.onchange=()=>A(r,o.value),e.append(a(`label`,`filter-field ${r===`taskId`?`filter-wide`:``}`,a(`span`,``,n),o)),o};n(`State`,`state`,[[`All states`,``],...[`queued`,`running`,`succeeded`,`failed`,`cancelled`,`interrupted`,`skipped`].map(e=>[e,e])]),n(`Source`,`source`,[[`All sources`,``],...[`manual`,`agent`,`cron`,`watch`,`task`].map(e=>[e,e])]),w=n(`Task`,`taskId`,M());let r=a(`details`,`filter-dates`),l=Number(b.has(`since`))+Number(b.has(`until`));r.open=l>0,r.append(a(`summary`,`flex cursor-pointer items-center gap-1.5 py-1 text-[12px] text-neutral-600`,s(c,`chev h-3 w-3`),l?`Date range (${l})`:`Date range`));let u=a(`div`,`filter-date-fields`);for(let[e,t]of[[`From`,`since`],[`Through`,`until`]]){let n=a(`input`,o);n.type=`datetime-local`,n.setAttribute(`aria-label`,e);let r=b.get(t);if(r){let e=new Date(Number(r));Number.isFinite(e.getTime())&&(n.value=new Date(e.getTime()-e.getTimezoneOffset()*6e4).toISOString().slice(0,16))}n.dataset.active=String(!!n.value),n.onchange=()=>A(t,n.value?String(new Date(n.value).getTime()):``),u.append(a(`label`,`filter-field`,a(`span`,``,e),n))}r.append(u);let d=a(`input`,`h-4 w-4 flex-none`);d.type=`checkbox`,d.checked=b.get(`showUnmatched`)===`true`,d.onchange=()=>A(`showUnmatched`,d.checked?`true`:``);let f=a(`label`,`flex min-h-10 cursor-pointer items-center gap-2 text-[11.5px] text-neutral-500`,d,`Show unmatched probes`),p=[...b.keys()].filter(e=>e!==`cursor`).length,m=i(p?`Reset filters (${p})`:`Reset filters`);return m.classList.add(`filter-action`),m.disabled=!p,m.onclick=()=>v({}),e.append(r,a(`div`,`filter-footer`,f,m)),e}function P(e){let t=a(`div`,`divide-y divide-neutral-100`);for(let n of e.runs){let e=a(`div`,`px-4 py-3 text-[12px] transition-colors hover:bg-neutral-50`),r=a(`button`,`grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 text-left md:grid-cols-[minmax(0,1fr)_12rem_5rem]`);r.setAttribute(`type`,`button`),r.onclick=()=>E(b,n.id),r.append(a(`span`,`flex min-w-0 items-center gap-2`,h(n),a(`span`,`min-w-0 truncate font-medium text-neutral-800`,n.context.definition.name)),a(`span`,`text-right font-mono text-[11.5px] text-neutral-400 md:order-2`,d(n)),a(`span`,`col-span-2 text-neutral-500 md:order-1 md:col-span-1`,p(n.queuedAt)),a(`span`,`col-span-2 break-all font-mono text-[11px] text-neutral-400 md:order-3 md:col-span-3`,`${n.id} · ${n.triggerSource}`)),e.append(r);let i=m(n);i&&e.append(a(`p`,`mt-1.5 inline-block break-words rounded-md bg-amber-50 px-2 py-0.5 text-[11.5px] text-amber-700 ring-1 ring-amber-200`,i));let o=a(`div`,`mt-1.5 flex flex-wrap gap-1.5 text-[11px] text-neutral-500`),s=`max-w-full break-all rounded-md bg-neutral-100 px-1.5 py-0.5 text-left`,c=(e,t)=>{let n=a(`button`,`${s} cursor-pointer transition-colors hover:bg-neutral-200 hover:text-neutral-800`,e);n.setAttribute(`type`,`button`),n.onclick=t,o.append(n)};if(n.parentRunId&&c(`Parent ${n.parentRunId}`,()=>E(b,n.parentRunId)),n.resumedFromRunId&&c(`Resumed from ${n.resumedFromRunId}`,()=>E(b,n.resumedFromRunId)),n.result?.type===`task`){let e=n.result.runId;c(`Child result ${e}`,()=>E(b,e))}n.groupId&&o.append(a(`span`,s,`Group ${n.groupId}`)),o.childElementCount&&e.append(o),t.append(e)}e.runs.length||t.append(a(`div`,`p-4`,r(`No matching runs.`)));let n=a(`div`,`flex items-center gap-3 border-t border-neutral-200 p-4`);if(b.has(`cursor`)){let e=i(`Newest`);e.onclick=()=>A(`cursor`,``),n.append(e)}if(e.nextCursor){let t=i(`Older runs`);t.onclick=()=>{let t=new URLSearchParams(b);t.set(`cursor`,JSON.stringify(e.nextCursor)),E(t)},n.append(t)}let o=C.scrollTop;C.replaceChildren(t,n),C.scrollTop=o}async function F(){let e=await u(`/api/tasks?kind=task`,`Could not load task filters`);if(!e.ok)return D(e.error);JSON.stringify(x)!==JSON.stringify(e.value)&&(x=e.value,!T.selectedId&&w?.isConnected&&(w.replaceChildren(...M().map(([e,t])=>new Option(e,t))),w.value=b.get(`taskId`)??``))}let I=n(g,(e,t)=>{b=new URLSearchParams(t),T.selectedId!==(e||null)&&(T.rawOpen=!1,T.scrollTop=0),T.selectedId=e||null,j(),k(),e||F()});return Object.assign(I,{refresh(){I.visible&&k()}})}export{g as createRunsView};
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,I as s,K as c,L as l,M as u,N as d,O as f,P as p,R as m,S as h,T as g,U as _,V as v,W as y,X as b,_ as x,at as S,b as C,c as w,ct as T,d as E,dt as D,et as O,f as k,ft as A,g as j,h as M,i as ee,it as N,j as P,k as F,m as I,mt as L,n as R,o as z,p as te,pt as ne,q as B,r as V,rt as H,st as re,tt as U,u as W,ut as G,v as ie,w as K,x as ae,y as oe,z as q}from"./index-CLNTSmYN.js";var se=[[`path`,{d:`m18 15-6-6-6 6`}]],ce=[[`path`,{d:`M15 3h6v6`}],[`path`,{d:`M10 14 21 3`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`}]],J=[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`}],[`path`,{d:`M12 9v4`}],[`path`,{d:`M12 17h.01`}]],le={display_information:{name:`Pier`,description:`Coding agent sessions in Slack threads`,background_color:`#262626`},features:{bot_user:{display_name:`Pier`,always_online:!1},app_home:{messages_tab_enabled:!0,messages_tab_read_only_enabled:!1}},oauth_config:{scopes:{bot:[`chat:write`,`reactions:write`,`channels:history`,`channels:read`,`groups:history`,`groups:read`,`im:history`,`im:write`,`mpim:history`,`mpim:read`,`mpim:write`,`users:read`,`files:read`,`files:write`]}},settings:{event_subscriptions:{bot_events:[`message.channels`,`message.groups`,`message.im`,`message.mpim`]},interactivity:{is_enabled:!0},socket_mode_enabled:!0,token_rotation_enabled:!1}},ue=()=>`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(JSON.stringify(le))}`;function Y(){let t=g(`Create Slack app`,!0);t.append(T(ce)),t.classList.add(`inline-flex`,`items-center`,`gap-1.5`),t.classList.add(`mt-1`,`w-fit`),t.onclick=()=>window.open(ue(),`_blank`,`noreferrer`);let n=B(`btn w-fit text-[12.5px]`,()=>JSON.stringify(le,null,2));return e(`Creating a Slack app`,[_(`Opens Slack with every scope, event and Socket Mode already filled in. Pick your workspace → Create.`,t),"`Install to Workspace` → allow. Then `OAuth & Permissions` → copy the bot token (`xoxb-…`) into the field above.","`Basic Information` → `App-Level Tokens` → `Generate` with scope `connections:write`. Paste that `xapp-…` token below. The manifest cannot mint this one for you.","In Slack, invite the bot where you want it: `/invite @Pier`. It answers in threads only, so it never adds noise to the channel.",_(`Prefer to paste it yourself? Create the app from a manifest and use this:`,n)])}var de=()=>e(`How Slack threads work here`,[`Pier never posts in a channel's main flow. A message in the channel is answered in *its own thread*; a message in a thread is answered in that thread.`,`Each thread is its own Pi session, so one channel hosts many parallel sessions.`,`The same applies in a DM: every new message you send there starts its own thread and its own session. Reply *inside* a thread to continue that conversation.`,"Inside a thread Pier already owns, no `@mention` is needed — continuing that thread is addressing it.","Commands are bare words after a mention: `@bot settings`, `@bot stop`, `@bot bind <code>`. `@bot s <question>`, as the first message of a thread, drafts a session — directory, model, reasoning — and Start runs the question in it. Slack's client swallows an unregistered `/command` before it ever reaches an app."]),fe=()=>e(`Creating a Feishu app`,["On [open.feishu.cn](https://open.feishu.cn/app) create a 企业自建应用 (custom app). `Credentials & Basic Info` shows the App ID (`cli_…`) and App Secret — paste both here.","`Add Features` → enable **Bot** (机器人).","`Permissions` (权限管理), add: `im:message` (read messages), `im:message:send_as_bot` (send), `im:resource` (attachments, both directions), `im:message.reactions:create` + `:read` + `:delete` (the 👀 receipt), `im:chat:readonly` (chat names for this page), `contact:user.base:readonly` (speaker names).","`Events & Callbacks` → set the mode to **长连接 (long connection)** — no public URL needed. Under Events subscribe `im.message.receive_v1` (接收消息); Callbacks gain `card.action.trigger` automatically once cards are sent, add it if listed.",`**Publish a version** (版本管理与发布 → 创建版本 → 申请发布). Nothing above takes effect until this is approved — the usual reason a configured bot stays silent.`,`Add the bot to a group (群设置 → 群机器人), or DM it directly.`]),pe=()=>e(`How Lark topics work here`,[`Pier never posts in a chat's main flow. A message in the chat is answered in *its own topic* (话题); a message inside a topic is answered there.`,`Each topic is its own Pi session, so one group hosts many parallel sessions.`,`The same applies in a DM: every new message starts its own topic and its own session. Reply *inside* a topic to continue that conversation.`,`Inside a topic Pier already owns, no @mention is needed — continuing that topic is addressing it.`,"Commands are slash words: `/stop`, `/settings`, `/bind <code>`. `/s <question>` or `s <question>`, outside any topic, drafts a session — directory, model, reasoning — and Start runs the question in it. A bare @mention with nothing else also opens the settings panel."]),X=[[`slack`,`Slack`],[`lark`,`Lark`]],me={dm:`bg-sky-50 text-sky-700 ring-sky-200`,group:`bg-neutral-100 text-neutral-600 ring-neutral-200`},he=`Discovered from inbound traffic — no platform reliably lists every chat a bot is in.`,ge=`pier.channelsPlatform`;function _e(e){let t=localStorage.getItem(ge),r=X.some(([e])=>e===t)?t:`slack`,o=null,s=[],l=b(`div`,`ml-auto flex items-center gap-1.5 text-[11.5px]`),u=b(`div`,`pagehead pagehead-hug sticky top-[-8px] z-30`,l),d=b(`div`,`px-4 pb-5 pt-4`);e.append(b(`div`,`min-h-0 flex-1 overflow-y-auto`,u,d));function m(){u.replaceChildren(a(X.map(([e,t])=>[t,e]),r,e=>{_&&A(),r=e,localStorage.setItem(ge,e),j()}),l)}let _,y=!1,x=null;function C(e){if(l.replaceChildren(),e!==`clean`){if(l.className=`ml-auto flex items-center gap-1.5 text-[11.5px] ${h[e]}`,e===`saving`)l.append(T(D,`spinner`),b(`span`,``,`Saving…`));else if(e===`saved`)l.append(T(L),b(`span`,``,`Saved`)),setTimeout(()=>{l.textContent?.includes(`Saved`)&&C(`clean`)},2e3);else{let e=K(`Retry`,`cursor-pointer underline`);e.onclick=A,l.append(T(J),b(`span`,``,`Save failed`),e)}}}function E(){C(`saving`),clearTimeout(_),_=setTimeout(A,500)}let O=e=>t=>{e(t),E()};async function k(e){y=!0,C(`saving`);try{C((await S(`/api/channels/${e.platform}`,e.config,`PUT`)).ok?`saved`:`failed`)}catch{C(`failed`)}finally{y=!1;let e=x;x=null,e&&k(e)}}function A(){if(clearTimeout(_),_=void 0,!o)return;let e={platform:r,config:o};y?x=e:k(e)}async function j(){if(!s.length){let e=await U(`/api/models`,`Could not load the model catalog`);e.ok&&(s=e.value)}let e=await U(`/api/channels/${r}`,`Failed to load`);if(!e.ok){o=null,m(),d.replaceChildren(f(e.error));return}o=e.value,C(`clean`),z()}function M(e){let t=r===`lark`,n=q(e.token,t?`cli_…`:`xoxb-…`,O(t=>e.token=t),!0),a=q(e.appToken,t?``:`xapp-…`,O(t=>e.appToken=t),!0),o=w(e.cwd,`(pier process cwd)`,O(t=>e.cwd=t));return i(`Connection`,t?`Pier connects over Feishu's WebSocket long connection; no public URL or webhook needed.`:`Pier connects over Socket Mode; no public URL or webhook needed.`,v(`Enabled`,`Start the adapter when Pier boots.`,e.enabled,O(t=>{e.enabled=t,m()})),F(t?`App ID`:`Bot token`,n,{hint:`Stored locally, shown masked once saved.`,help:t?fe():Y()}),t?F(`App Secret`,a,{hint:`From Credentials & Basic Info, beside the App ID.`}):F(`App-level token`,a,{hint:`Opens the Socket Mode connection. Needs connections:write.`}),F(`Default working directory`,o.el,{hint:`Where sessions this channel opens start.`}),b(`span`,`flex items-center gap-1.5 text-[13px] text-neutral-400`,b(`span`,``,t?`Every topic is its own session.`:`Every thread is its own session.`),t?pe():de()))}function ee(e){return i(`Defaults for new chats`,`Copied into a group the first time the bot sees it; changing them here never touches a group that already exists. DMs are always bound-users-only.`,v(`Require mention in groups`,`Ignore group messages that do not @mention or reply to the bot.`,e.requireMention,O(t=>e.requireMention=t)),v(`Require bound user`,`Only users bound with a code below can drive the agent.`,e.requireBind,O(t=>e.requireBind=t)),R(`Model & reasoning`,e,s,O(t=>{e.model=t.model,e.thinking=t.thinking,z()})))}function N(e){let t=b(`span`,`font-mono text-[15px] font-semibold tracking-widest`),n=b(`div`,`hidden items-center gap-2 rounded-lg bg-indigo-50 px-3 py-2 text-[12.5px] text-indigo-800`,t,b(`span`,`text-[11.5px] text-indigo-500`,`DM the bot /bind <code> · expires in 10 min`)),a=g(`Generate bind code`);a.onclick=async()=>{let e=await fetch(`/api/channels/${r}/bind-code`,{method:`POST`});if(!e.ok)return;let{code:i}=await e.json();t.textContent=i,n.classList.replace(`hidden`,`flex`)};let o=b(`div`,`flex flex-col`);e.users.length||o.append(f(`No bound users yet.`));for(let t of e.users){let e=K(`Remove`,p());e.onclick=async()=>{await fetch(`/api/channels/${r}/users/${encodeURIComponent(t.id)}`,{method:`DELETE`}),await j()},o.append(b(`div`,`group flex items-center gap-2.5 border-b border-neutral-100 py-2 last:border-0`,b(`span`,`flex h-6 w-6 flex-none items-center justify-center rounded-full bg-neutral-100 text-[11px] font-semibold text-neutral-500`,(t.name[0]??`?`).toUpperCase()),b(`span`,`min-w-0 flex-1 truncate text-[13px] text-neutral-700`,t.name),b(`span`,`flex-none font-mono text-[11.5px] text-neutral-400`,t.id),e))}return i(`Bound users`,`A code is single-use and expires; redeeming it in a DM binds that account.`,o,b(`div`,`flex flex-col gap-2`,a,n))}function P(e,t){let i=b(`div`,`group rounded-xl border px-3.5 py-3 transition-colors ${t.enabled?`border-neutral-200 bg-white`:`border-neutral-200 bg-neutral-50/60`}`),a=t.botId!==e.botId,o=K(`Remove`,p());o.onclick=async()=>{let e=t.name||t.id;window.confirm(`Remove ${e}? Threads in it lose their sessions; a chat the bot can still reach comes back on its next message.`)&&(await fetch(`/api/channels/${r}/chats/${encodeURIComponent(t.id)}`,{method:`DELETE`}),await j())};let c=b(`div`,`flex flex-wrap items-center gap-2`,b(`span`,`min-w-0 flex-1 basis-full truncate text-[13px] font-medium sm:basis-0 ${t.enabled?`text-neutral-800`:`text-neutral-400`}`,t.name||t.id),n(t.kind,me[t.kind]),...a?[n(t.botId?`other bot`:`no bot`,`bg-amber-50 text-amber-700 ring-amber-200`)]:[],b(`span`,`flex-none font-mono text-[11px] text-neutral-400`,t.id),o),l=v(``,``,t.enabled,O(e=>{t.enabled=e,z()}));l.classList.add(`flex-none`,`items-center`),c.append(l);let u=b(`div`,`mt-3 flex flex-wrap items-center gap-x-6 gap-y-2`);t.kind===`dm`?u.append(b(`span`,`text-[13px] text-neutral-400`,`Direct message · bound users only, mention not applicable`)):u.append(v(`Require mention`,``,t.requireMention,O(e=>t.requireMention=e)),v(`Require bind`,``,t.requireBind,O(e=>t.requireBind=e))),a&&u.append(b(`span`,`w-full text-[12.5px] text-amber-700`,t.botId?`Last seen under bot ${t.botId}${e.botId?`, not the current ${e.botId}`:``} — remove it if nothing arrives here.`:`No message since Pier started recording bot identities — remove it if nothing arrives here.`));let d=w(t.cwd,``,O(e=>t.cwd=e)),f=b(`div`,`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2`,F(`Working directory`,d.el),R(`Model & reasoning`,t,s,O(e=>{t.model=e.model,t.thinking=e.thinking,z()})));return i.append(c,u,f),i}function I(e){let t=b(`div`,`flex flex-col gap-2.5`);return e.chats.length?t.append(...e.chats.map(t=>P(e,t))):t.append(f(`None yet. Chats appear here after the bot sees a message in them.`)),i(r===`slack`?`Channels`:`Chats`,e.botId?`${he} Current bot: ${e.botId}.`:he,t)}function z(){if(!o)return;m();let e=b(`div`,`mx-auto flex max-w-3xl flex-col gap-4`);e.append(M(o),ee(o),N(o),I(o)),d.replaceChildren(e)}return c(e,()=>void j(),()=>{_&&A()})}function ve(){let e=b(`div`,`min-h-0 min-w-0 flex-1 overflow-y-auto p-4`),t=b(`div`,`mx-auto flex max-w-3xl min-w-0 flex-col gap-4`),n=b(`p`,`text-[12px] break-words`),r=b(`section`,`flex min-w-0 flex-col gap-3 border-b border-neutral-200 pb-4`),i=b(`section`,`flex min-w-0 flex-col gap-3`);t.append(b(`h2`,`text-[14px] font-semibold text-neutral-700`,`Configuration sync`),n,r,i),e.append(t);let a=null,o=!1,s=!1,c=0,u=``,d=!1,f=e=>e?new Date(e).toLocaleString():`Never`;async function p(){let e=c,t=await U(`/api/config-sync`,`Could not load configuration sync`,{cache:`no-store`});if(!(s||e!==c)){if(!t.ok){l(n,`failed`,t.error);return}a=t.value,d||(u=a.sourceUrl),_()}}async function m(e){if(!o){++c,o=!0,_(),l(n,`saving`,`Working...`);try{let t=await S(`/api/config-sync`,{action:e,...e===`subscribe`?{url:u}:{}});if(!t.ok)throw Error(await O(t,`Configuration sync failed`));let r=await t.json();a=r,d=!1,u=r.sourceUrl,l(n,`saved`,r.result??`Saved`)}catch(e){l(n,`failed`,e instanceof Error?e.message:`Configuration sync failed`),await p()}finally{o=!1,s||_()}}}function h(e,t){let n=g(e);return n.disabled=o,n.onclick=()=>{m(t)},n}function _(){if(!a||s)return;if(r.replaceChildren(b(`h3`,`text-[13px] font-medium text-neutral-700`,`Publish`)),a.publishedPath){let e=`${a.publicUrl||window.location.origin}${a.publishedPath}`,t=q(e,``,()=>{},!0);t.readOnly=!0,t.setAttribute(`aria-label`,`Sharing URL`),r.append(t,b(`div`,`flex flex-wrap items-center gap-2`,B(`btn text-[12px]`,()=>e),h(`Revoke link`,`revoke`)))}else r.append(b(`div`,``,h(`Generate link`,`publish`)));r.append(b(`p`,`text-[12px] text-neutral-500`,`Anyone with the link can read shared prompts, model definitions, the default model and its reasoning effort. API keys, headers and endpoints stay private.`));let e=q(u,`https://example.com/config-sync/...`,e=>{u=e,d=!0},!0);e.type=`url`,e.setAttribute(`aria-label`,`Configuration source URL`),e.disabled=o||a.enabled;let t=v(`Automatic sync`,``,a.enabled,e=>{m(e?`subscribe`:`pause`)});t.querySelector(`input`).disabled=o;let n=b(`div`,`flex flex-wrap items-center gap-3`,t);a.enabled&&n.append(h(`Sync now`,`sync`)),i.replaceChildren(b(`h3`,`text-[13px] font-medium text-neutral-700`,`Source`),F(`Source URL`,e),n);let c=b(`dl`,`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 text-[12px]`);for(let[e,t]of[[`Last checked`,f(a.lastChecked)],[`Last applied`,f(a.lastApplied)],[`Next check`,a.enabled?f(a.nextRunAt):`Paused`]])c.append(b(`dt`,`text-neutral-500`,e),b(`dd`,`min-w-0 break-words text-neutral-700`,t));if(i.append(c),a.error&&i.append(b(`p`,`text-[12px] break-words text-red-600`,a.error)),a.needsReload&&i.append(b(`p`,`text-[12px] text-amber-700`,`Reload pending; retry synchronization.`)),a.taskId){let e=b(`a`,`text-[12px] text-indigo-600 hover:underline`,`Sync task history`);e.href=`#/tasks/${encodeURIComponent(a.taskId)}`,i.append(e)}}p();let y=setInterval(()=>{!o&&!d&&p()},15e3);return{el:e,dispose:()=>{s=!0,clearInterval(y)}}}var ye=`text-[11.5px] text-neutral-400`,Z=`bg-neutral-50 text-neutral-500 ring-neutral-200`,Q=`bg-amber-50 text-amber-700 ring-amber-100`,be=`Pi packages run with full system access: an extension executes arbitrary code, and a skill can instruct the model to run anything. Review the source before installing.`,xe=e=>e===`pier`||e===`local`?e:e.replace(/^(npm|git):/,``).replace(/\.git$/,``).replace(/@[^@/]*$/,``).split(`/`).filter(Boolean).pop()??e,Se=e=>e.startsWith(`npm:`)?`npm`:/^(git:|(https?|ssh|git):\/\/)/.test(e)?`git`:`path`,Ce=e=>e.kind===`pier`||e.kind===`local`,we=e=>e.slice(0,e.lastIndexOf(`/`))||`/`;function Te(e){let t=null,r=``,i=()=>{let t=e.cwd();return t?`?cwd=${encodeURIComponent(t)}`:``},a=t=>!Ce(t)&&t.scope===`global`&&e.cwd()===void 0;async function s(){let e=await U(`/api/packages${i()}`,`packages could not be loaded`,{cache:`no-store`});t=e.ok?e.value:null,r=e.ok?``:e.error}let c=(e,n)=>t?.packages.find(t=>t.source===e&&t.scope===n),u=(e,n,r)=>{for(let i of t?.packages.filter(t=>t.source===e)??[]){let e=i.resources.find(e=>e.kind===n&&e.path===r);if(e)return{pkg:i,resource:e}}};async function d(t,n,r){let i=e.cwd(),a=await H(`/api/packages/resource`,{source:t.source,kind:n.kind,path:n.path,enabled:r,...i?{cwd:i}:{}},`could not save`,`PUT`);return a.ok?(t.resources=t.resources.map(e=>e.kind===n.kind&&e.path===n.path?a.value:e),e.changed(),{state:`saved`,text:`Saved — sessions take it on their next message.`}):{state:`failed`,text:a.error}}let p=t=>{e.pane.replaceChildren(b(`p`,`px-4 py-3 text-[12.5px] leading-relaxed text-red-600`,t))},m=(...e)=>b(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,...e),h=(e,t,n=!0)=>[b(`dt`,`text-[12px] text-neutral-500`,e),b(`dd`,`text-[12px] leading-snug text-neutral-700 ${n?`font-mono break-all`:``}`,t)],g=(t,n)=>{let r=K(`Browse files`,`btn text-[12px]`);return r.onclick=()=>e.browse(t,n),r},_=(e,t,n,r,i)=>{let a=v(n,r,t.enabled,n=>void d(e,t,n).then(i));if(t.locked)for(let e of a.querySelectorAll(`input`))e.disabled=!0;return a};function x(t,r,i){let a=K(r.name,`font-mono text-[13px] text-neutral-700 hover:text-indigo-600 hover:underline`);a.onclick=()=>{let n={type:`resource`,source:t.source,kind:r.kind,path:r.path};e.select(n),w(n.source,n.kind,n.path)};let o=b(`div`,`flex min-w-0 flex-1 flex-col gap-0.5`,b(`span`,`flex flex-wrap items-center gap-2`,a,n(r.kind,Z)),...r.state?[b(`span`,`text-[11.5px] leading-snug text-amber-700`,r.state)]:[]);return b(`div`,`flex max-w-2xl items-start gap-3 border-b border-neutral-100 py-2.5 last:border-0`,o,_(t,r,``,``,i))}function S(r,i,o){let u=e.claim(),d=c(r,i);if(!d)return p(`unknown package: ${r}`);let _=b(`span`,ye,``);o&&l(_,o.state,o.text);let v=t?.busy===d.source;v&&!o&&l(_,`saving`,`${d.installedPath?`updating`:`installing`}…`);let C=t=>{e.live(u)&&S(r,i,t)},w=[...h(`Source`,d.source),...h(`Kind`,d.kind===`pier`?`built in — ships with Pier`:d.kind===`local`?`the agent directory's own files`:d.kind,!1),...d.version?h(`Version`,d.version):[],...d.installedPath===null?Ce(d)?[]:h(`Installed at`,`not installed`,!1):h(`Installed at`,b(`span`,`flex flex-wrap items-center gap-2`,b(`span`,`font-mono break-all`,d.installedPath),g(d.installedPath)),!1)],T=[];if(a(d)&&d.kind!==`path`){let n=t?.checkedAt?`checked ${y(Date.parse(t.checkedAt))}`:`not checked yet`,a=K(`Check for updates`,`btn text-[12px]`);a.disabled=v,a.onclick=()=>{a.disabled=!0,l(_,`saving`,`checking…`),H(`/api/packages/check`,{},`update check failed`).then(n=>{n.ok&&(t=n.value),e.changed();let a=c(r,i);C(n.ok?{state:`saved`,text:a?.updateAvailable?`Checked — an update is available.`:`Checked — up to date.`}:{state:`failed`,text:n.error})})},w.push(...h(`Updates`,b(`span`,`flex flex-wrap items-center gap-2`,b(`span`,d.updateAvailable?`text-emerald-700`:``,d.updateAvailable?`update available (${n})`:n),a),!1));let o=K(`Update`,`btn text-[12.5px]`);o.disabled=v,o.onclick=()=>{o.disabled=!0,t&&={...t,busy:d.source},e.changed(),C({state:`saved`,text:`updating…`}),H(`/api/packages/update`,{source:d.source},`update failed`).then(async t=>{await s(),e.changed();let n=t.ok?t.value.packages.find(e=>e.source===d.source):void 0;C(t.ok?{state:`saved`,text:`Updated${n?.version?` to ${n.version}`:``} — sessions take it on their next message.`}:{state:`failed`,text:t.error})})},T.push(o)}if(a(d)){let t=K(`Remove`,`btn text-[12.5px] text-neutral-600 hover:text-red-600`);t.disabled=v,t.onclick=()=>{let n=d.kind===`path`?`settings.json forgets it; the directory stays.`:`Its files are deleted and settings.json forgets it.`;window.confirm(`Remove ${d.source}? ${n}`)&&(t.disabled=!0,l(_,`saving`,`removing…`),H(`/api/packages/remove`,{source:d.source},`remove failed`).then(async t=>{if(!t.ok)return C({state:`failed`,text:t.error});await s(),e.select(null),e.live(u)&&e.pane.replaceChildren(b(`div`,`flex min-h-0 flex-1 items-center justify-center p-6`,f(`Removed ${d.source}.`)))}))},T.push(t)}e.pane.replaceChildren(e.paneBar(xe(d.source),n(d.kind,Z),...d.scope===`project`?[n(`project`,Q)]:[],...T.length?[b(`div`,`ml-auto flex flex-none items-center gap-2`,...T)]:[]),m(b(`dl`,`grid max-w-2xl grid-cols-[auto_1fr] gap-x-4 gap-y-1.5`,...w),d.resources.length?b(`div`,`flex max-w-2xl flex-col`,...d.resources.map(e=>x(d,e,C))):f(d.installedPath?`No extensions or skills.`:`Not installed — nothing to load.`),_))}let C=(t,n)=>n.locked?`Switch it under Tools: the tool's install writes this file and its uninstall removes it.`:t.kind===`pier`?n.kind===`skill`?`Pier's own skill. Off, no session is offered it.`:`Loaded from inside Pier — nothing installed, nothing to update. A session mid-turn keeps the tools it started with.`:`Written to ${e.cwd()?`this project's .pi/settings.json`:`settings.json`} as +path / −path for ${xe(t.source)}; sessions pick it up on their next open.`;async function w(t,r,i,a){let s=e.claim(),c=u(t,r,i);if(!c)return p(`unknown ${r}: ${i}`);let{pkg:d,resource:f}=c,m=b(`span`,ye,``);a&&l(m,a.state,a.text);let h=b(`div`,`min-h-0 flex-1 overflow-auto`),v=i.startsWith(`/`);if(e.pane.replaceChildren(e.paneBar(f.name,n(xe(d.source),Z),n(f.kind,Z),b(`span`,`ml-auto flex flex-wrap items-center gap-2`,b(`span`,`font-mono text-[11px] text-neutral-400 break-all`,f.path),...v?[g(we(i),o(i))]:[])),b(`div`,`flex flex-none flex-col gap-2 border-b border-neutral-200 px-4 py-3`,_(d,f,`Enabled`,C(d,f),n=>{e.live(s)&&w(t,r,i,n)}),...f.state?[b(`p`,`text-[12px] text-amber-700`,f.state)]:[],m),h),i.startsWith(`<inline:`)){h.append(b(`p`,`px-4 py-3 text-[12.5px] text-neutral-400`,`Loaded from inside Pier — there is no file to show.`));return}let y=await T(i);if(!e.live(s))return;if(!y.ok)return h.append(b(`p`,`px-4 py-3 text-[12.5px] text-red-600`,y.error));let x=await M(i);e.live(s)&&h.append(te(I(y.value),x))}async function T(e){let t=`/api/fs/file?root=${encodeURIComponent(we(e))}&path=${encodeURIComponent(o(e))}`,n;try{n=await fetch(t,{cache:`no-store`})}catch(t){return{ok:!1,error:`could not read ${e}: ${String(t)}`}}return n.ok?{ok:!0,value:await n.text()}:{ok:!1,error:await O(n,`could not read ${e}`)}}function E(n,r=``){let i=e.claim(),a=b(`span`,ye,``);n&&l(a,n.state,n.text);let o=r,c=q(r,`npm:@scope/name · git:github.com/owner/repo · /path/to/package`,e=>o=e,!0),u=K(`Install`,`btn btn-primary text-[12.5px]`),d=()=>{let n=o.trim();if(!n)return l(a,`failed`,`A package source is required.`);u.disabled=!0,l(a,`saving`,`installing ${n}…`),t&&(t={...t,busy:n,packages:[...t.packages,{source:n,kind:Se(n),scope:`global`,version:null,installedPath:null,updateAvailable:!1,resources:[]}]},e.changed()),H(`/api/packages`,{source:n},`install failed`).then(async t=>{if(await s(),e.changed(),!e.live(i))return;if(!t.ok)return E({state:`failed`,text:t.error},n);let{package:r}=t.value;e.select({type:`package`,source:r.source,scope:r.scope}),S(r.source,r.scope,{state:`saved`,text:`Installed ${r.source} — sessions take it on their next message.`})})};u.onclick=d,c.onkeydown=e=>{e.key===`Enter`&&d()},e.pane.replaceChildren(e.paneBar(`Add package`),m(b(`div`,`flex max-w-2xl flex-col gap-3`,F(`Source`,c,{hint:"What `pi install` takes: an npm package, a git URL (both may pin @version), or a directory on this machine."}),b(`p`,`text-[12.5px] leading-relaxed text-amber-800`,be),b(`div`,`flex items-center gap-3`,u,a)))),c.focus()}return{get registry(){return t},get error(){return r},load:s,openPackage:S,openResource:w,openAdd:E}}async function Ee(e,t){let n;try{n=await S(`/api/settings`,e,`PUT`)}catch(e){return{outcome:{state:`failed`,text:`Could not save: ${String(e)}`}}}if(!n.ok)return{outcome:{state:`failed`,text:await O(n,`could not save`)}};let r;try{r=await n.json()}catch(e){return{outcome:{state:`failed`,text:`Saved, but the answer could not be read: ${String(e)}`}}}return r.toolsSync?.state===`refused`?{outcome:{state:`failed`,text:`Saved, but nothing will install it: ${r.toolsSync.reason}`},answer:r}:r.toolsSync?.state===`waiting`?{outcome:{state:`saved`,text:`Saved — a sync is already running; this change goes in the run right after it.`},answer:r}:{outcome:{state:`saved`,text:t},answer:r}}function De(e,t){return e.enabled?{body:{tool:{name:e.name,on:!1}},saved:`Switched ${e.name} off — the next run uninstalls it. Remove it again once its binary is gone.`}:{body:{customTools:t.filter(t=>t.name!==e.name)},saved:`Removed ${e.name}.`}}function Oe(e,t,r){let i=`global`,a=null,s=0,u=0,d=``,p=()=>d?`Global (${d})`:`Global`,m=null,h=[],g=``,_=null,y=null,C=()=>{y?.dispose(),y=null},w=()=>{C(),++u,y=ve(),z.replaceChildren(y.el)},D=[],k=e=>e.custom===!0,ee=b(`span`,`min-w-0 flex-1 truncate`),N=b(`button`,`${ie} flex items-center gap-1.5`,ee,T(ne,`h-3.5 w-3.5 text-neutral-500`));N.setAttribute(`aria-haspopup`,`true`),N.onclick=()=>{if(N.getAttribute(`aria-expanded`)===`true`)return W();E(N,[{label:p(),checked:i===`global`,onSelect:()=>Se(`global`)},...t().map(e=>({label:e,hint:o(e),checked:i===e,onSelect:()=>Se(e)}))],`Scope`)};let P=b(`div`,`${j} flex-col items-stretch gap-1.5 px-3 py-2.5`);P.append(b(`span`,`field-label`,`Scope`),N);let L=b(`div`,`min-h-0 flex-1 overflow-y-auto py-1.5`),R=b(`nav`,`${oe} w-64 flex-none text-[13px] leading-5 max-md:max-h-48 max-md:w-full`);R.append(P,L);let z=b(`div`,`${oe} min-w-0 flex-1`),B=b(`div`,`flex min-h-0 flex-1 gap-3 px-4 pb-4 pt-1 max-md:flex-col`);B.append(R,z),e.append(B);let V=(e,...t)=>b(`div`,`${j} flex-wrap gap-3 px-4 py-2.5`,b(`span`,`font-mono text-[12.5px] text-neutral-500`,e),...t),H=Te({pane:z,paneBar:V,claim:()=>++u,live:e=>e===u,cwd:()=>i===`global`?void 0:i,changed:()=>X(m),browse:r,select:e=>{a=e,e?.type===`resource`&&de.set(e.source,!0),X(m)}}),re=(e=``)=>`?scope=${encodeURIComponent(i)}${e}`;async function G(){if(i!==`global`){h=[],g=``;return}let e=await U(`/api/settings`,`could not be loaded`,{cache:`no-store`});if(!e.ok){h=[],g=e.error;return}ae(e.value),g=``}function ae(e){h=e.catalog,D=e.customTools,_=e.toolsTaskId}async function se(e,t){let{outcome:n,answer:r}=await Ee(e,t);return r&&(ae(r),X(m)),n}async function ce(){let e=++s;u++;let[t]=await Promise.all([U(`/api/config${re()}`,`failed to load config`,{cache:`no-store`}),G(),H.load()]);if(e!==s)return;if(!t.ok){X(null),he(t.error);return}let n=t.value;i===`global`&&n.dir&&(d=n.dir,we()),m=n,X(n),a?a.type===`sync`&&w():me()}function J(e,t){return b(`div`,`flex items-center justify-between gap-2 px-3 pb-1 pt-3 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,b(`span`,``,e),...t?[t]:[])}let le=e=>b(`span`,`flex-none rounded bg-neutral-100 px-1 text-[10px] font-semibold uppercase tracking-wide text-neutral-500`,e),ue=()=>b(`span`,`flex-none rounded bg-emerald-50 px-1 text-[10px] font-semibold uppercase tracking-wide text-emerald-700`,`on`);function Y(e,t,n,r,i={}){let a=b(`button`,`config-row flex w-full cursor-pointer items-center gap-1.5 py-1.5 pr-3 text-left transition-colors hover:bg-neutral-100 ${t?`bg-indigo-50 font-medium hover:bg-indigo-50`:``} ${n?`text-neutral-400`:``}`),o=b(`span`,`truncate`,e);if(i.note){let e=b(`span`,`truncate text-[11px] font-normal leading-4 text-amber-700`,i.note);e.title=i.note,a.append(b(`span`,`flex min-w-0 flex-1 flex-col`,o,e))}else a.append(o);return a.append(...i.tags??[]),a.style.paddingLeft=`${i.flush?0:20+(i.depth??0)*14}px`,a.title=e,a.onclick=r,a}let de=new Map,fe=e=>de.get(e.source)??(e.kind===`pier`||e.kind===`local`);function pe(e,t,n){let r={type:`package`,source:e.source,scope:e.scope},i=[];H.registry?.busy===e.source?i.push(b(`span`,`flex-none text-[11px] text-neutral-400`,e.installedPath?`updating…`:`installing…`)):e.resources.some(e=>e.enabled)&&i.push(ue()),e.scope===`project`&&i.push(le(`project`));let a=e.installedPath===null&&!Ce(e),o=fe(e),s=b(`button`,`flex w-5 flex-none cursor-pointer items-center justify-center self-stretch text-neutral-500 hover:bg-neutral-100`,T(A,`chev h-3 w-3`));o&&s.classList.add(`chev-open`),s.title=`${o?`Collapse`:`Expand`} ${xe(e.source)}`,s.setAttribute(`aria-label`,s.title),s.setAttribute(`aria-expanded`,String(o)),s.onclick=()=>{de.set(e.source,!o),X(m)};let c=Y(xe(e.source),t(r),a,()=>n(r),{tags:i,flush:!0}),l=[b(`div`,`flex items-stretch ${t(r)?`bg-indigo-50`:``}`,s,c)];if(!o)return l;let u=e.resources.map(e=>e.name),d=new Set(u.filter((e,t)=>u.indexOf(e)!==t));for(let[r,i]of[[`extensions`,`extension`],[`skills`,`skill`]]){let a=e.resources.filter(e=>e.kind===i);if(!a.length)continue;let o=b(`div`,`py-0.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,r);o.style.paddingLeft=`34px`,l.push(o);for(let r of a){let a={type:`resource`,source:e.source,kind:i,path:r.path};l.push(Y(r.name,t(a),!r.enabled,()=>n(a),{depth:2,note:r.state,tags:d.has(r.name)?[le(i)]:[]}))}}return l}function X(e){if(!e){L.replaceChildren();return}let t=e=>JSON.stringify(e)===JSON.stringify(a),n=t=>{C(),a=t,X(e),t.type===`file`?ge(t.name,t.readonly):t.type===`tools`?Q():t.type===`sync`?w():t.type===`package`?H.openPackage(t.source,t.scope):t.type===`resource`?H.openResource(t.source,t.kind,t.path):H.openAdd()},r=[];if(i===`global`){let e={type:`sync`};r.push(J(`Instance`),Y(`Configuration sync`,t(e),!1,()=>n(e)))}r.push(J(`Files`));for(let i of e.files){let e={type:`file`,name:i.name,readonly:i.readonly};r.push(Y(i.name,t(e),!i.exists,()=>n(e)))}let o={type:`add`},s=K(`Add package`,`normal-case tracking-normal hover:underline ${t(o)?`text-indigo-700`:`text-indigo-600`}`);s.onclick=()=>n(o),r.push(J(`Packages`,i===`global`?s:void 0)),H.error&&r.push(b(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-red-600`,H.error));for(let e of H.registry?.packages??[])r.push(...pe(e,t,n));if(i===`global`){if(r.push(J(`Tools`)),g)r.push(b(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-red-600`,g));else{let e={type:`tools`},i=h.filter(e=>e.enabled).length;r.push(Y(`command-line tools`,t(e),!1,()=>n(e),{tags:i?[ue()]:[]}))}}L.replaceChildren(...r)}function me(){z.replaceChildren(b(`div`,`flex min-h-0 flex-1 items-center justify-center p-6`,f(`Select a file to edit, or a package, extension or skill to switch.`)))}function he(e){z.replaceChildren(b(`p`,`px-4 py-3 text-[12.5px] leading-relaxed text-red-600`,e))}async function ge(e,t){let n=++u,r=await U(`/api/config/files/${encodeURIComponent(e)}${re()}`,`failed to load ${e}`,{cache:`no-store`});if(!r.ok){n===u&&he(r.error);return}if(n!==u)return;let{content:i}=r.value,a=i,o=b(`span`,`text-[11.5px] text-neutral-400`,``),s=b(`button`,`btn btn-primary text-[12.5px]`,`Save`),c=document.createElement(`textarea`);c.className=`block min-h-0 flex-1 resize-none bg-white p-4 font-mono text-[13px] leading-relaxed focus:outline-none`,c.spellcheck=!1,c.value=i;let d=async()=>{if(s.disabled)return;let t=c.value;s.disabled=!0,l(o,`saving`,`saving…`);try{let n=await S(`/api/config/files/${encodeURIComponent(e)}${re()}`,{content:t,expected:a},`PUT`);if(!n.ok)return l(o,`failed`,await O(n,`save failed`));let r=await n.json();a=r.content,c.value===t?(c.value=r.content,l(o,`saved`,`saved — applies to new sessions`)):l(o,`idle`,`saved; newer changes are unsaved`)}catch(e){l(o,`failed`,`save failed: ${String(e)}`)}finally{s.disabled=!1}},f=b(`button`,`btn text-[12.5px]`,`Edit`),p=b(`button`,`btn text-[12.5px]`,`View`),m=(...e)=>b(`div`,`ml-auto flex flex-none items-center gap-2`,...e),h=()=>{z.replaceChildren(V(e,o,m(p,s)),c),c.focus()},g=async()=>{let r=await M(e);n===u&&z.replaceChildren(t?V(e,b(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`read-only`)):V(e,o,m(f)),...t?[b(`p`,`border-b border-neutral-200 px-4 py-2 text-[12.5px] leading-relaxed text-neutral-500`,`Pier manages this file: the default model is set in Settings → Models; other keys are edited on disk, then pier reload.`)]:[],b(`div`,`min-h-0 flex-1 overflow-auto`,te(I(c.value),r)))};f.onclick=h,p.onclick=()=>void g(),s.onclick=()=>void d(),c.onkeydown=e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),d())},c.oninput=()=>{l(o,`idle`,`unsaved changes`)},await g()}function _e(e){if(!_)return null;let t=b(`a`,`text-indigo-600 hover:underline`,e);return t.href=`#/tasks/${encodeURIComponent(_)}`,t}let ye=()=>{let e=b(`a`,`text-indigo-600 hover:underline`,`ubix`);return e.href=`https://github.com/timqi/ubix`,e.target=`_blank`,e.rel=`noreferrer`,e};function Z(e){let{spec:t,error:n,installed:r,version:i,path:a}=e.binary;return n?`${t} — ${n}`:r?`${t} — ${i??`unknown version`} at ${a??`an unknown path`}`:`${t} — not installed`}function Q(e,t={name:``,toml:``}){u++;let r=b(`span`,`text-[11.5px] text-neutral-400`,``);e&&l(r,e.state,e.text);let i=_e(`the update task`),a=e=>{let t=b(`div`,`flex min-w-0 flex-1 flex-col gap-0.5`,b(`span`,`flex items-center gap-2 text-[13px] text-neutral-700`,b(`span`,`font-mono`,e.name),...k(e)?[n(`yours`,`bg-neutral-50 text-neutral-500 ring-neutral-200`)]:[]),b(`span`,`text-[11.5px] leading-snug text-neutral-400`,e.summary||Z(e)),...e.summary?[b(`span`,`font-mono text-[11px] leading-snug ${e.binary.error?`text-red-600`:`text-neutral-400`}`,Z(e))]:[]),r=v(``,``,e.enabled,t=>void be(e.name,t,e=>Q(e))),i=b(`button`,`btn text-[12px] text-neutral-500 hover:text-red-600`,`Remove`);return i.onclick=()=>{i.disabled=!0;let t=De(e,D);se(t.body,t.saved).then(e=>Q(e))},b(`div`,`flex max-w-2xl items-start gap-3 border-b border-neutral-100 py-2.5 last:border-0`,t,...k(e)?[i]:[],r)},o={...t},s=b(`span`,`font-mono text-[12px] text-neutral-500`,`[tools.<name>]`),c=q(o.name,`claude`,e=>{o.name=e,s.textContent=`[tools.${e.trim()||`<name>`}]`},!0),d=document.createElement(`textarea`);d.className=`${x} h-24 resize-y font-mono leading-snug`,d.spellcheck=!1,d.value=o.toml,d.placeholder=`spec = "github:owner/repo"
|
|
1
|
+
import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,I as s,K as c,L as l,M as u,N as d,O as f,P as p,R as m,S as h,T as g,U as _,V as v,W as y,X as b,_ as x,at as S,b as C,c as w,ct as T,d as E,dt as D,et as O,f as k,ft as A,g as j,h as M,i as ee,it as N,j as P,k as F,m as I,mt as L,n as R,o as z,p as te,pt as ne,q as B,r as V,rt as H,st as re,tt as U,u as W,ut as G,v as ie,w as K,x as ae,y as oe,z as q}from"./index-BQo-haPN.js";var se=[[`path`,{d:`m18 15-6-6-6 6`}]],ce=[[`path`,{d:`M15 3h6v6`}],[`path`,{d:`M10 14 21 3`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`}]],J=[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`}],[`path`,{d:`M12 9v4`}],[`path`,{d:`M12 17h.01`}]],le={display_information:{name:`Pier`,description:`Coding agent sessions in Slack threads`,background_color:`#262626`},features:{bot_user:{display_name:`Pier`,always_online:!1},app_home:{messages_tab_enabled:!0,messages_tab_read_only_enabled:!1}},oauth_config:{scopes:{bot:[`chat:write`,`reactions:write`,`channels:history`,`channels:read`,`groups:history`,`groups:read`,`im:history`,`im:write`,`mpim:history`,`mpim:read`,`mpim:write`,`users:read`,`files:read`,`files:write`]}},settings:{event_subscriptions:{bot_events:[`message.channels`,`message.groups`,`message.im`,`message.mpim`]},interactivity:{is_enabled:!0},socket_mode_enabled:!0,token_rotation_enabled:!1}},ue=()=>`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(JSON.stringify(le))}`;function Y(){let t=g(`Create Slack app`,!0);t.append(T(ce)),t.classList.add(`inline-flex`,`items-center`,`gap-1.5`),t.classList.add(`mt-1`,`w-fit`),t.onclick=()=>window.open(ue(),`_blank`,`noreferrer`);let n=B(`btn w-fit text-[12.5px]`,()=>JSON.stringify(le,null,2));return e(`Creating a Slack app`,[_(`Opens Slack with every scope, event and Socket Mode already filled in. Pick your workspace → Create.`,t),"`Install to Workspace` → allow. Then `OAuth & Permissions` → copy the bot token (`xoxb-…`) into the field above.","`Basic Information` → `App-Level Tokens` → `Generate` with scope `connections:write`. Paste that `xapp-…` token below. The manifest cannot mint this one for you.","In Slack, invite the bot where you want it: `/invite @Pier`. It answers in threads only, so it never adds noise to the channel.",_(`Prefer to paste it yourself? Create the app from a manifest and use this:`,n)])}var de=()=>e(`How Slack threads work here`,[`Pier never posts in a channel's main flow. A message in the channel is answered in *its own thread*; a message in a thread is answered in that thread.`,`Each thread is its own Pi session, so one channel hosts many parallel sessions.`,`The same applies in a DM: every new message you send there starts its own thread and its own session. Reply *inside* a thread to continue that conversation.`,"Inside a thread Pier already owns, no `@mention` is needed — continuing that thread is addressing it.","Commands are bare words after a mention: `@bot settings`, `@bot stop`, `@bot bind <code>`. `@bot s <question>`, as the first message of a thread, drafts a session — directory, model, reasoning — and Start runs the question in it. Slack's client swallows an unregistered `/command` before it ever reaches an app."]),fe=()=>e(`Creating a Feishu app`,["On [open.feishu.cn](https://open.feishu.cn/app) create a 企业自建应用 (custom app). `Credentials & Basic Info` shows the App ID (`cli_…`) and App Secret — paste both here.","`Add Features` → enable **Bot** (机器人).","`Permissions` (权限管理), add: `im:message` (read messages), `im:message:send_as_bot` (send), `im:resource` (attachments, both directions), `im:message.reactions:create` + `:read` + `:delete` (the 👀 receipt), `im:chat:readonly` (chat names for this page), `contact:user.base:readonly` (speaker names).","`Events & Callbacks` → set the mode to **长连接 (long connection)** — no public URL needed. Under Events subscribe `im.message.receive_v1` (接收消息); Callbacks gain `card.action.trigger` automatically once cards are sent, add it if listed.",`**Publish a version** (版本管理与发布 → 创建版本 → 申请发布). Nothing above takes effect until this is approved — the usual reason a configured bot stays silent.`,`Add the bot to a group (群设置 → 群机器人), or DM it directly.`]),pe=()=>e(`How Lark topics work here`,[`Pier never posts in a chat's main flow. A message in the chat is answered in *its own topic* (话题); a message inside a topic is answered there.`,`Each topic is its own Pi session, so one group hosts many parallel sessions.`,`The same applies in a DM: every new message starts its own topic and its own session. Reply *inside* a topic to continue that conversation.`,`Inside a topic Pier already owns, no @mention is needed — continuing that topic is addressing it.`,"Commands are slash words: `/stop`, `/settings`, `/bind <code>`. `/s <question>` or `s <question>`, outside any topic, drafts a session — directory, model, reasoning — and Start runs the question in it. A bare @mention with nothing else also opens the settings panel."]),X=[[`slack`,`Slack`],[`lark`,`Lark`]],me={dm:`bg-sky-50 text-sky-700 ring-sky-200`,group:`bg-neutral-100 text-neutral-600 ring-neutral-200`},he=`Discovered from inbound traffic — no platform reliably lists every chat a bot is in.`,ge=`pier.channelsPlatform`;function _e(e){let t=localStorage.getItem(ge),r=X.some(([e])=>e===t)?t:`slack`,o=null,s=[],l=b(`div`,`ml-auto flex items-center gap-1.5 text-[11.5px]`),u=b(`div`,`pagehead pagehead-hug sticky top-[-8px] z-30`,l),d=b(`div`,`px-4 pb-5 pt-4`);e.append(b(`div`,`min-h-0 flex-1 overflow-y-auto`,u,d));function m(){u.replaceChildren(a(X.map(([e,t])=>[t,e]),r,e=>{_&&A(),r=e,localStorage.setItem(ge,e),j()}),l)}let _,y=!1,x=null;function C(e){if(l.replaceChildren(),e!==`clean`){if(l.className=`ml-auto flex items-center gap-1.5 text-[11.5px] ${h[e]}`,e===`saving`)l.append(T(D,`spinner`),b(`span`,``,`Saving…`));else if(e===`saved`)l.append(T(L),b(`span`,``,`Saved`)),setTimeout(()=>{l.textContent?.includes(`Saved`)&&C(`clean`)},2e3);else{let e=K(`Retry`,`cursor-pointer underline`);e.onclick=A,l.append(T(J),b(`span`,``,`Save failed`),e)}}}function E(){C(`saving`),clearTimeout(_),_=setTimeout(A,500)}let O=e=>t=>{e(t),E()};async function k(e){y=!0,C(`saving`);try{C((await S(`/api/channels/${e.platform}`,e.config,`PUT`)).ok?`saved`:`failed`)}catch{C(`failed`)}finally{y=!1;let e=x;x=null,e&&k(e)}}function A(){if(clearTimeout(_),_=void 0,!o)return;let e={platform:r,config:o};y?x=e:k(e)}async function j(){if(!s.length){let e=await U(`/api/models`,`Could not load the model catalog`);e.ok&&(s=e.value)}let e=await U(`/api/channels/${r}`,`Failed to load`);if(!e.ok){o=null,m(),d.replaceChildren(f(e.error));return}o=e.value,C(`clean`),z()}function M(e){let t=r===`lark`,n=q(e.token,t?`cli_…`:`xoxb-…`,O(t=>e.token=t),!0),a=q(e.appToken,t?``:`xapp-…`,O(t=>e.appToken=t),!0),o=w(e.cwd,`(pier process cwd)`,O(t=>e.cwd=t));return i(`Connection`,t?`Pier connects over Feishu's WebSocket long connection; no public URL or webhook needed.`:`Pier connects over Socket Mode; no public URL or webhook needed.`,v(`Enabled`,`Start the adapter when Pier boots.`,e.enabled,O(t=>{e.enabled=t,m()})),F(t?`App ID`:`Bot token`,n,{hint:`Stored locally, shown masked once saved.`,help:t?fe():Y()}),t?F(`App Secret`,a,{hint:`From Credentials & Basic Info, beside the App ID.`}):F(`App-level token`,a,{hint:`Opens the Socket Mode connection. Needs connections:write.`}),F(`Default working directory`,o.el,{hint:`Where sessions this channel opens start.`}),b(`span`,`flex items-center gap-1.5 text-[13px] text-neutral-400`,b(`span`,``,t?`Every topic is its own session.`:`Every thread is its own session.`),t?pe():de()))}function ee(e){return i(`Defaults for new chats`,`Copied into a group the first time the bot sees it; changing them here never touches a group that already exists. DMs are always bound-users-only.`,v(`Require mention in groups`,`Ignore group messages that do not @mention or reply to the bot.`,e.requireMention,O(t=>e.requireMention=t)),v(`Require bound user`,`Only users bound with a code below can drive the agent.`,e.requireBind,O(t=>e.requireBind=t)),R(`Model & reasoning`,e,s,O(t=>{e.model=t.model,e.thinking=t.thinking,z()})))}function N(e){let t=b(`span`,`font-mono text-[15px] font-semibold tracking-widest`),n=b(`div`,`hidden items-center gap-2 rounded-lg bg-indigo-50 px-3 py-2 text-[12.5px] text-indigo-800`,t,b(`span`,`text-[11.5px] text-indigo-500`,`DM the bot /bind <code> · expires in 10 min`)),a=g(`Generate bind code`);a.onclick=async()=>{let e=await fetch(`/api/channels/${r}/bind-code`,{method:`POST`});if(!e.ok)return;let{code:i}=await e.json();t.textContent=i,n.classList.replace(`hidden`,`flex`)};let o=b(`div`,`flex flex-col`);e.users.length||o.append(f(`No bound users yet.`));for(let t of e.users){let e=K(`Remove`,p());e.onclick=async()=>{await fetch(`/api/channels/${r}/users/${encodeURIComponent(t.id)}`,{method:`DELETE`}),await j()},o.append(b(`div`,`group flex items-center gap-2.5 border-b border-neutral-100 py-2 last:border-0`,b(`span`,`flex h-6 w-6 flex-none items-center justify-center rounded-full bg-neutral-100 text-[11px] font-semibold text-neutral-500`,(t.name[0]??`?`).toUpperCase()),b(`span`,`min-w-0 flex-1 truncate text-[13px] text-neutral-700`,t.name),b(`span`,`flex-none font-mono text-[11.5px] text-neutral-400`,t.id),e))}return i(`Bound users`,`A code is single-use and expires; redeeming it in a DM binds that account.`,o,b(`div`,`flex flex-col gap-2`,a,n))}function P(e,t){let i=b(`div`,`group rounded-xl border px-3.5 py-3 transition-colors ${t.enabled?`border-neutral-200 bg-white`:`border-neutral-200 bg-neutral-50/60`}`),a=t.botId!==e.botId,o=K(`Remove`,p());o.onclick=async()=>{let e=t.name||t.id;window.confirm(`Remove ${e}? Threads in it lose their sessions; a chat the bot can still reach comes back on its next message.`)&&(await fetch(`/api/channels/${r}/chats/${encodeURIComponent(t.id)}`,{method:`DELETE`}),await j())};let c=b(`div`,`flex flex-wrap items-center gap-2`,b(`span`,`min-w-0 flex-1 basis-full truncate text-[13px] font-medium sm:basis-0 ${t.enabled?`text-neutral-800`:`text-neutral-400`}`,t.name||t.id),n(t.kind,me[t.kind]),...a?[n(t.botId?`other bot`:`no bot`,`bg-amber-50 text-amber-700 ring-amber-200`)]:[],b(`span`,`flex-none font-mono text-[11px] text-neutral-400`,t.id),o),l=v(``,``,t.enabled,O(e=>{t.enabled=e,z()}));l.classList.add(`flex-none`,`items-center`),c.append(l);let u=b(`div`,`mt-3 flex flex-wrap items-center gap-x-6 gap-y-2`);t.kind===`dm`?u.append(b(`span`,`text-[13px] text-neutral-400`,`Direct message · bound users only, mention not applicable`)):u.append(v(`Require mention`,``,t.requireMention,O(e=>t.requireMention=e)),v(`Require bind`,``,t.requireBind,O(e=>t.requireBind=e))),a&&u.append(b(`span`,`w-full text-[12.5px] text-amber-700`,t.botId?`Last seen under bot ${t.botId}${e.botId?`, not the current ${e.botId}`:``} — remove it if nothing arrives here.`:`No message since Pier started recording bot identities — remove it if nothing arrives here.`));let d=w(t.cwd,``,O(e=>t.cwd=e)),f=b(`div`,`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2`,F(`Working directory`,d.el),R(`Model & reasoning`,t,s,O(e=>{t.model=e.model,t.thinking=e.thinking,z()})));return i.append(c,u,f),i}function I(e){let t=b(`div`,`flex flex-col gap-2.5`);return e.chats.length?t.append(...e.chats.map(t=>P(e,t))):t.append(f(`None yet. Chats appear here after the bot sees a message in them.`)),i(r===`slack`?`Channels`:`Chats`,e.botId?`${he} Current bot: ${e.botId}.`:he,t)}function z(){if(!o)return;m();let e=b(`div`,`mx-auto flex max-w-3xl flex-col gap-4`);e.append(M(o),ee(o),N(o),I(o)),d.replaceChildren(e)}return c(e,()=>void j(),()=>{_&&A()})}function ve(){let e=b(`div`,`min-h-0 min-w-0 flex-1 overflow-y-auto p-4`),t=b(`div`,`mx-auto flex max-w-3xl min-w-0 flex-col gap-4`),n=b(`p`,`text-[12px] break-words`),r=b(`section`,`flex min-w-0 flex-col gap-3 border-b border-neutral-200 pb-4`),i=b(`section`,`flex min-w-0 flex-col gap-3`);t.append(b(`h2`,`text-[14px] font-semibold text-neutral-700`,`Configuration sync`),n,r,i),e.append(t);let a=null,o=!1,s=!1,c=0,u=``,d=!1,f=e=>e?new Date(e).toLocaleString():`Never`;async function p(){let e=c,t=await U(`/api/config-sync`,`Could not load configuration sync`,{cache:`no-store`});if(!(s||e!==c)){if(!t.ok){l(n,`failed`,t.error);return}a=t.value,d||(u=a.sourceUrl),_()}}async function m(e){if(!o){++c,o=!0,_(),l(n,`saving`,`Working...`);try{let t=await S(`/api/config-sync`,{action:e,...e===`subscribe`?{url:u}:{}});if(!t.ok)throw Error(await O(t,`Configuration sync failed`));let r=await t.json();a=r,d=!1,u=r.sourceUrl,l(n,`saved`,r.result??`Saved`)}catch(e){l(n,`failed`,e instanceof Error?e.message:`Configuration sync failed`),await p()}finally{o=!1,s||_()}}}function h(e,t){let n=g(e);return n.disabled=o,n.onclick=()=>{m(t)},n}function _(){if(!a||s)return;if(r.replaceChildren(b(`h3`,`text-[13px] font-medium text-neutral-700`,`Publish`)),a.publishedPath){let e=`${a.publicUrl||window.location.origin}${a.publishedPath}`,t=q(e,``,()=>{},!0);t.readOnly=!0,t.setAttribute(`aria-label`,`Sharing URL`),r.append(t,b(`div`,`flex flex-wrap items-center gap-2`,B(`btn text-[12px]`,()=>e),h(`Revoke link`,`revoke`)))}else r.append(b(`div`,``,h(`Generate link`,`publish`)));r.append(b(`p`,`text-[12px] text-neutral-500`,`Anyone with the link can read shared prompts, model definitions, the default model and its reasoning effort. API keys, headers and endpoints stay private.`));let e=q(u,`https://example.com/config-sync/...`,e=>{u=e,d=!0},!0);e.type=`url`,e.setAttribute(`aria-label`,`Configuration source URL`),e.disabled=o||a.enabled;let t=v(`Automatic sync`,``,a.enabled,e=>{m(e?`subscribe`:`pause`)});t.querySelector(`input`).disabled=o;let n=b(`div`,`flex flex-wrap items-center gap-3`,t);a.enabled&&n.append(h(`Sync now`,`sync`)),i.replaceChildren(b(`h3`,`text-[13px] font-medium text-neutral-700`,`Source`),F(`Source URL`,e),n);let c=b(`dl`,`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 text-[12px]`);for(let[e,t]of[[`Last checked`,f(a.lastChecked)],[`Last applied`,f(a.lastApplied)],[`Next check`,a.enabled?f(a.nextRunAt):`Paused`]])c.append(b(`dt`,`text-neutral-500`,e),b(`dd`,`min-w-0 break-words text-neutral-700`,t));if(i.append(c),a.error&&i.append(b(`p`,`text-[12px] break-words text-red-600`,a.error)),a.needsReload&&i.append(b(`p`,`text-[12px] text-amber-700`,`Reload pending; retry synchronization.`)),a.taskId){let e=b(`a`,`text-[12px] text-indigo-600 hover:underline`,`Sync task history`);e.href=`#/tasks/${encodeURIComponent(a.taskId)}`,i.append(e)}}p();let y=setInterval(()=>{!o&&!d&&p()},15e3);return{el:e,dispose:()=>{s=!0,clearInterval(y)}}}var ye=`text-[11.5px] text-neutral-400`,Z=`bg-neutral-50 text-neutral-500 ring-neutral-200`,Q=`bg-amber-50 text-amber-700 ring-amber-100`,be=`Pi packages run with full system access: an extension executes arbitrary code, and a skill can instruct the model to run anything. Review the source before installing.`,xe=e=>e===`pier`||e===`local`?e:e.replace(/^(npm|git):/,``).replace(/\.git$/,``).replace(/@[^@/]*$/,``).split(`/`).filter(Boolean).pop()??e,Se=e=>e.startsWith(`npm:`)?`npm`:/^(git:|(https?|ssh|git):\/\/)/.test(e)?`git`:`path`,Ce=e=>e.kind===`pier`||e.kind===`local`,we=e=>e.slice(0,e.lastIndexOf(`/`))||`/`;function Te(e){let t=null,r=``,i=()=>{let t=e.cwd();return t?`?cwd=${encodeURIComponent(t)}`:``},a=t=>!Ce(t)&&t.scope===`global`&&e.cwd()===void 0;async function s(){let e=await U(`/api/packages${i()}`,`packages could not be loaded`,{cache:`no-store`});t=e.ok?e.value:null,r=e.ok?``:e.error}let c=(e,n)=>t?.packages.find(t=>t.source===e&&t.scope===n),u=(e,n,r)=>{for(let i of t?.packages.filter(t=>t.source===e)??[]){let e=i.resources.find(e=>e.kind===n&&e.path===r);if(e)return{pkg:i,resource:e}}};async function d(t,n,r){let i=e.cwd(),a=await H(`/api/packages/resource`,{source:t.source,kind:n.kind,path:n.path,enabled:r,...i?{cwd:i}:{}},`could not save`,`PUT`);return a.ok?(t.resources=t.resources.map(e=>e.kind===n.kind&&e.path===n.path?a.value:e),e.changed(),{state:`saved`,text:`Saved — sessions take it on their next message.`}):{state:`failed`,text:a.error}}let p=t=>{e.pane.replaceChildren(b(`p`,`px-4 py-3 text-[12.5px] leading-relaxed text-red-600`,t))},m=(...e)=>b(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,...e),h=(e,t,n=!0)=>[b(`dt`,`text-[12px] text-neutral-500`,e),b(`dd`,`text-[12px] leading-snug text-neutral-700 ${n?`font-mono break-all`:``}`,t)],g=(t,n)=>{let r=K(`Browse files`,`btn text-[12px]`);return r.onclick=()=>e.browse(t,n),r},_=(e,t,n,r,i)=>{let a=v(n,r,t.enabled,n=>void d(e,t,n).then(i));if(t.locked)for(let e of a.querySelectorAll(`input`))e.disabled=!0;return a};function x(t,r,i){let a=K(r.name,`font-mono text-[13px] text-neutral-700 hover:text-indigo-600 hover:underline`);a.onclick=()=>{let n={type:`resource`,source:t.source,kind:r.kind,path:r.path};e.select(n),w(n.source,n.kind,n.path)};let o=b(`div`,`flex min-w-0 flex-1 flex-col gap-0.5`,b(`span`,`flex flex-wrap items-center gap-2`,a,n(r.kind,Z)),...r.state?[b(`span`,`text-[11.5px] leading-snug text-amber-700`,r.state)]:[]);return b(`div`,`flex max-w-2xl items-start gap-3 border-b border-neutral-100 py-2.5 last:border-0`,o,_(t,r,``,``,i))}function S(r,i,o){let u=e.claim(),d=c(r,i);if(!d)return p(`unknown package: ${r}`);let _=b(`span`,ye,``);o&&l(_,o.state,o.text);let v=t?.busy===d.source;v&&!o&&l(_,`saving`,`${d.installedPath?`updating`:`installing`}…`);let C=t=>{e.live(u)&&S(r,i,t)},w=[...h(`Source`,d.source),...h(`Kind`,d.kind===`pier`?`built in — ships with Pier`:d.kind===`local`?`the agent directory's own files`:d.kind,!1),...d.version?h(`Version`,d.version):[],...d.installedPath===null?Ce(d)?[]:h(`Installed at`,`not installed`,!1):h(`Installed at`,b(`span`,`flex flex-wrap items-center gap-2`,b(`span`,`font-mono break-all`,d.installedPath),g(d.installedPath)),!1)],T=[];if(a(d)&&d.kind!==`path`){let n=t?.checkedAt?`checked ${y(Date.parse(t.checkedAt))}`:`not checked yet`,a=K(`Check for updates`,`btn text-[12px]`);a.disabled=v,a.onclick=()=>{a.disabled=!0,l(_,`saving`,`checking…`),H(`/api/packages/check`,{},`update check failed`).then(n=>{n.ok&&(t=n.value),e.changed();let a=c(r,i);C(n.ok?{state:`saved`,text:a?.updateAvailable?`Checked — an update is available.`:`Checked — up to date.`}:{state:`failed`,text:n.error})})},w.push(...h(`Updates`,b(`span`,`flex flex-wrap items-center gap-2`,b(`span`,d.updateAvailable?`text-emerald-700`:``,d.updateAvailable?`update available (${n})`:n),a),!1));let o=K(`Update`,`btn text-[12.5px]`);o.disabled=v,o.onclick=()=>{o.disabled=!0,t&&={...t,busy:d.source},e.changed(),C({state:`saved`,text:`updating…`}),H(`/api/packages/update`,{source:d.source},`update failed`).then(async t=>{await s(),e.changed();let n=t.ok?t.value.packages.find(e=>e.source===d.source):void 0;C(t.ok?{state:`saved`,text:`Updated${n?.version?` to ${n.version}`:``} — sessions take it on their next message.`}:{state:`failed`,text:t.error})})},T.push(o)}if(a(d)){let t=K(`Remove`,`btn text-[12.5px] text-neutral-600 hover:text-red-600`);t.disabled=v,t.onclick=()=>{let n=d.kind===`path`?`settings.json forgets it; the directory stays.`:`Its files are deleted and settings.json forgets it.`;window.confirm(`Remove ${d.source}? ${n}`)&&(t.disabled=!0,l(_,`saving`,`removing…`),H(`/api/packages/remove`,{source:d.source},`remove failed`).then(async t=>{if(!t.ok)return C({state:`failed`,text:t.error});await s(),e.select(null),e.live(u)&&e.pane.replaceChildren(b(`div`,`flex min-h-0 flex-1 items-center justify-center p-6`,f(`Removed ${d.source}.`)))}))},T.push(t)}e.pane.replaceChildren(e.paneBar(xe(d.source),n(d.kind,Z),...d.scope===`project`?[n(`project`,Q)]:[],...T.length?[b(`div`,`ml-auto flex flex-none items-center gap-2`,...T)]:[]),m(b(`dl`,`grid max-w-2xl grid-cols-[auto_1fr] gap-x-4 gap-y-1.5`,...w),d.resources.length?b(`div`,`flex max-w-2xl flex-col`,...d.resources.map(e=>x(d,e,C))):f(d.installedPath?`No extensions or skills.`:`Not installed — nothing to load.`),_))}let C=(t,n)=>n.locked?`Switch it under Tools: the tool's install writes this file and its uninstall removes it.`:t.kind===`pier`?n.kind===`skill`?`Pier's own skill. Off, no session is offered it.`:`Loaded from inside Pier — nothing installed, nothing to update. A session mid-turn keeps the tools it started with.`:`Written to ${e.cwd()?`this project's .pi/settings.json`:`settings.json`} as +path / −path for ${xe(t.source)}; sessions pick it up on their next open.`;async function w(t,r,i,a){let s=e.claim(),c=u(t,r,i);if(!c)return p(`unknown ${r}: ${i}`);let{pkg:d,resource:f}=c,m=b(`span`,ye,``);a&&l(m,a.state,a.text);let h=b(`div`,`min-h-0 flex-1 overflow-auto`),v=i.startsWith(`/`);if(e.pane.replaceChildren(e.paneBar(f.name,n(xe(d.source),Z),n(f.kind,Z),b(`span`,`ml-auto flex flex-wrap items-center gap-2`,b(`span`,`font-mono text-[11px] text-neutral-400 break-all`,f.path),...v?[g(we(i),o(i))]:[])),b(`div`,`flex flex-none flex-col gap-2 border-b border-neutral-200 px-4 py-3`,_(d,f,`Enabled`,C(d,f),n=>{e.live(s)&&w(t,r,i,n)}),...f.state?[b(`p`,`text-[12px] text-amber-700`,f.state)]:[],m),h),i.startsWith(`<inline:`)){h.append(b(`p`,`px-4 py-3 text-[12.5px] text-neutral-400`,`Loaded from inside Pier — there is no file to show.`));return}let y=await T(i);if(!e.live(s))return;if(!y.ok)return h.append(b(`p`,`px-4 py-3 text-[12.5px] text-red-600`,y.error));let x=await M(i);e.live(s)&&h.append(te(I(y.value),x))}async function T(e){let t=`/api/fs/file?root=${encodeURIComponent(we(e))}&path=${encodeURIComponent(o(e))}`,n;try{n=await fetch(t,{cache:`no-store`})}catch(t){return{ok:!1,error:`could not read ${e}: ${String(t)}`}}return n.ok?{ok:!0,value:await n.text()}:{ok:!1,error:await O(n,`could not read ${e}`)}}function E(n,r=``){let i=e.claim(),a=b(`span`,ye,``);n&&l(a,n.state,n.text);let o=r,c=q(r,`npm:@scope/name · git:github.com/owner/repo · /path/to/package`,e=>o=e,!0),u=K(`Install`,`btn btn-primary text-[12.5px]`),d=()=>{let n=o.trim();if(!n)return l(a,`failed`,`A package source is required.`);u.disabled=!0,l(a,`saving`,`installing ${n}…`),t&&(t={...t,busy:n,packages:[...t.packages,{source:n,kind:Se(n),scope:`global`,version:null,installedPath:null,updateAvailable:!1,resources:[]}]},e.changed()),H(`/api/packages`,{source:n},`install failed`).then(async t=>{if(await s(),e.changed(),!e.live(i))return;if(!t.ok)return E({state:`failed`,text:t.error},n);let{package:r}=t.value;e.select({type:`package`,source:r.source,scope:r.scope}),S(r.source,r.scope,{state:`saved`,text:`Installed ${r.source} — sessions take it on their next message.`})})};u.onclick=d,c.onkeydown=e=>{e.key===`Enter`&&d()},e.pane.replaceChildren(e.paneBar(`Add package`),m(b(`div`,`flex max-w-2xl flex-col gap-3`,F(`Source`,c,{hint:"What `pi install` takes: an npm package, a git URL (both may pin @version), or a directory on this machine."}),b(`p`,`text-[12.5px] leading-relaxed text-amber-800`,be),b(`div`,`flex items-center gap-3`,u,a)))),c.focus()}return{get registry(){return t},get error(){return r},load:s,openPackage:S,openResource:w,openAdd:E}}async function Ee(e,t){let n;try{n=await S(`/api/settings`,e,`PUT`)}catch(e){return{outcome:{state:`failed`,text:`Could not save: ${String(e)}`}}}if(!n.ok)return{outcome:{state:`failed`,text:await O(n,`could not save`)}};let r;try{r=await n.json()}catch(e){return{outcome:{state:`failed`,text:`Saved, but the answer could not be read: ${String(e)}`}}}return r.toolsSync?.state===`refused`?{outcome:{state:`failed`,text:`Saved, but nothing will install it: ${r.toolsSync.reason}`},answer:r}:r.toolsSync?.state===`waiting`?{outcome:{state:`saved`,text:`Saved — a sync is already running; this change goes in the run right after it.`},answer:r}:{outcome:{state:`saved`,text:t},answer:r}}function De(e,t){return e.enabled?{body:{tool:{name:e.name,on:!1}},saved:`Switched ${e.name} off — the next run uninstalls it. Remove it again once its binary is gone.`}:{body:{customTools:t.filter(t=>t.name!==e.name)},saved:`Removed ${e.name}.`}}function Oe(e,t,r){let i=`global`,a=null,s=0,u=0,d=``,p=()=>d?`Global (${d})`:`Global`,m=null,h=[],g=``,_=null,y=null,C=()=>{y?.dispose(),y=null},w=()=>{C(),++u,y=ve(),z.replaceChildren(y.el)},D=[],k=e=>e.custom===!0,ee=b(`span`,`min-w-0 flex-1 truncate`),N=b(`button`,`${ie} flex items-center gap-1.5`,ee,T(ne,`h-3.5 w-3.5 text-neutral-500`));N.setAttribute(`aria-haspopup`,`true`),N.onclick=()=>{if(N.getAttribute(`aria-expanded`)===`true`)return W();E(N,[{label:p(),checked:i===`global`,onSelect:()=>Se(`global`)},...t().map(e=>({label:e,hint:o(e),checked:i===e,onSelect:()=>Se(e)}))],`Scope`)};let P=b(`div`,`${j} flex-col items-stretch gap-1.5 px-3 py-2.5`);P.append(b(`span`,`field-label`,`Scope`),N);let L=b(`div`,`min-h-0 flex-1 overflow-y-auto py-1.5`),R=b(`nav`,`${oe} w-64 flex-none text-[13px] leading-5 max-md:max-h-48 max-md:w-full`);R.append(P,L);let z=b(`div`,`${oe} min-w-0 flex-1`),B=b(`div`,`flex min-h-0 flex-1 gap-3 px-4 pb-4 pt-1 max-md:flex-col`);B.append(R,z),e.append(B);let V=(e,...t)=>b(`div`,`${j} flex-wrap gap-3 px-4 py-2.5`,b(`span`,`font-mono text-[12.5px] text-neutral-500`,e),...t),H=Te({pane:z,paneBar:V,claim:()=>++u,live:e=>e===u,cwd:()=>i===`global`?void 0:i,changed:()=>X(m),browse:r,select:e=>{a=e,e?.type===`resource`&&de.set(e.source,!0),X(m)}}),re=(e=``)=>`?scope=${encodeURIComponent(i)}${e}`;async function G(){if(i!==`global`){h=[],g=``;return}let e=await U(`/api/settings`,`could not be loaded`,{cache:`no-store`});if(!e.ok){h=[],g=e.error;return}ae(e.value),g=``}function ae(e){h=e.catalog,D=e.customTools,_=e.toolsTaskId}async function se(e,t){let{outcome:n,answer:r}=await Ee(e,t);return r&&(ae(r),X(m)),n}async function ce(){let e=++s;u++;let[t]=await Promise.all([U(`/api/config${re()}`,`failed to load config`,{cache:`no-store`}),G(),H.load()]);if(e!==s)return;if(!t.ok){X(null),he(t.error);return}let n=t.value;i===`global`&&n.dir&&(d=n.dir,we()),m=n,X(n),a?a.type===`sync`&&w():me()}function J(e,t){return b(`div`,`flex items-center justify-between gap-2 px-3 pb-1 pt-3 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,b(`span`,``,e),...t?[t]:[])}let le=e=>b(`span`,`flex-none rounded bg-neutral-100 px-1 text-[10px] font-semibold uppercase tracking-wide text-neutral-500`,e),ue=()=>b(`span`,`flex-none rounded bg-emerald-50 px-1 text-[10px] font-semibold uppercase tracking-wide text-emerald-700`,`on`);function Y(e,t,n,r,i={}){let a=b(`button`,`config-row flex w-full cursor-pointer items-center gap-1.5 py-1.5 pr-3 text-left transition-colors hover:bg-neutral-100 ${t?`bg-indigo-50 font-medium hover:bg-indigo-50`:``} ${n?`text-neutral-400`:``}`),o=b(`span`,`truncate`,e);if(i.note){let e=b(`span`,`truncate text-[11px] font-normal leading-4 text-amber-700`,i.note);e.title=i.note,a.append(b(`span`,`flex min-w-0 flex-1 flex-col`,o,e))}else a.append(o);return a.append(...i.tags??[]),a.style.paddingLeft=`${i.flush?0:20+(i.depth??0)*14}px`,a.title=e,a.onclick=r,a}let de=new Map,fe=e=>de.get(e.source)??(e.kind===`pier`||e.kind===`local`);function pe(e,t,n){let r={type:`package`,source:e.source,scope:e.scope},i=[];H.registry?.busy===e.source?i.push(b(`span`,`flex-none text-[11px] text-neutral-400`,e.installedPath?`updating…`:`installing…`)):e.resources.some(e=>e.enabled)&&i.push(ue()),e.scope===`project`&&i.push(le(`project`));let a=e.installedPath===null&&!Ce(e),o=fe(e),s=b(`button`,`flex w-5 flex-none cursor-pointer items-center justify-center self-stretch text-neutral-500 hover:bg-neutral-100`,T(A,`chev h-3 w-3`));o&&s.classList.add(`chev-open`),s.title=`${o?`Collapse`:`Expand`} ${xe(e.source)}`,s.setAttribute(`aria-label`,s.title),s.setAttribute(`aria-expanded`,String(o)),s.onclick=()=>{de.set(e.source,!o),X(m)};let c=Y(xe(e.source),t(r),a,()=>n(r),{tags:i,flush:!0}),l=[b(`div`,`flex items-stretch ${t(r)?`bg-indigo-50`:``}`,s,c)];if(!o)return l;let u=e.resources.map(e=>e.name),d=new Set(u.filter((e,t)=>u.indexOf(e)!==t));for(let[r,i]of[[`extensions`,`extension`],[`skills`,`skill`]]){let a=e.resources.filter(e=>e.kind===i);if(!a.length)continue;let o=b(`div`,`py-0.5 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,r);o.style.paddingLeft=`34px`,l.push(o);for(let r of a){let a={type:`resource`,source:e.source,kind:i,path:r.path};l.push(Y(r.name,t(a),!r.enabled,()=>n(a),{depth:2,note:r.state,tags:d.has(r.name)?[le(i)]:[]}))}}return l}function X(e){if(!e){L.replaceChildren();return}let t=e=>JSON.stringify(e)===JSON.stringify(a),n=t=>{C(),a=t,X(e),t.type===`file`?ge(t.name,t.readonly):t.type===`tools`?Q():t.type===`sync`?w():t.type===`package`?H.openPackage(t.source,t.scope):t.type===`resource`?H.openResource(t.source,t.kind,t.path):H.openAdd()},r=[];if(i===`global`){let e={type:`sync`};r.push(J(`Instance`),Y(`Configuration sync`,t(e),!1,()=>n(e)))}r.push(J(`Files`));for(let i of e.files){let e={type:`file`,name:i.name,readonly:i.readonly};r.push(Y(i.name,t(e),!i.exists,()=>n(e)))}let o={type:`add`},s=K(`Add package`,`normal-case tracking-normal hover:underline ${t(o)?`text-indigo-700`:`text-indigo-600`}`);s.onclick=()=>n(o),r.push(J(`Packages`,i===`global`?s:void 0)),H.error&&r.push(b(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-red-600`,H.error));for(let e of H.registry?.packages??[])r.push(...pe(e,t,n));if(i===`global`){if(r.push(J(`Tools`)),g)r.push(b(`p`,`py-1 pl-5 pr-3 text-[12.5px] text-red-600`,g));else{let e={type:`tools`},i=h.filter(e=>e.enabled).length;r.push(Y(`command-line tools`,t(e),!1,()=>n(e),{tags:i?[ue()]:[]}))}}L.replaceChildren(...r)}function me(){z.replaceChildren(b(`div`,`flex min-h-0 flex-1 items-center justify-center p-6`,f(`Select a file to edit, or a package, extension or skill to switch.`)))}function he(e){z.replaceChildren(b(`p`,`px-4 py-3 text-[12.5px] leading-relaxed text-red-600`,e))}async function ge(e,t){let n=++u,r=await U(`/api/config/files/${encodeURIComponent(e)}${re()}`,`failed to load ${e}`,{cache:`no-store`});if(!r.ok){n===u&&he(r.error);return}if(n!==u)return;let{content:i}=r.value,a=i,o=b(`span`,`text-[11.5px] text-neutral-400`,``),s=b(`button`,`btn btn-primary text-[12.5px]`,`Save`),c=document.createElement(`textarea`);c.className=`block min-h-0 flex-1 resize-none bg-white p-4 font-mono text-[13px] leading-relaxed focus:outline-none`,c.spellcheck=!1,c.value=i;let d=async()=>{if(s.disabled)return;let t=c.value;s.disabled=!0,l(o,`saving`,`saving…`);try{let n=await S(`/api/config/files/${encodeURIComponent(e)}${re()}`,{content:t,expected:a},`PUT`);if(!n.ok)return l(o,`failed`,await O(n,`save failed`));let r=await n.json();a=r.content,c.value===t?(c.value=r.content,l(o,`saved`,`saved — applies to new sessions`)):l(o,`idle`,`saved; newer changes are unsaved`)}catch(e){l(o,`failed`,`save failed: ${String(e)}`)}finally{s.disabled=!1}},f=b(`button`,`btn text-[12.5px]`,`Edit`),p=b(`button`,`btn text-[12.5px]`,`View`),m=(...e)=>b(`div`,`ml-auto flex flex-none items-center gap-2`,...e),h=()=>{z.replaceChildren(V(e,o,m(p,s)),c),c.focus()},g=async()=>{let r=await M(e);n===u&&z.replaceChildren(t?V(e,b(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`read-only`)):V(e,o,m(f)),...t?[b(`p`,`border-b border-neutral-200 px-4 py-2 text-[12.5px] leading-relaxed text-neutral-500`,`Pier manages this file: the default model is set in Settings → Models; other keys are edited on disk, then pier reload.`)]:[],b(`div`,`min-h-0 flex-1 overflow-auto`,te(I(c.value),r)))};f.onclick=h,p.onclick=()=>void g(),s.onclick=()=>void d(),c.onkeydown=e=>{(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),d())},c.oninput=()=>{l(o,`idle`,`unsaved changes`)},await g()}function _e(e){if(!_)return null;let t=b(`a`,`text-indigo-600 hover:underline`,e);return t.href=`#/tasks/${encodeURIComponent(_)}`,t}let ye=()=>{let e=b(`a`,`text-indigo-600 hover:underline`,`ubix`);return e.href=`https://github.com/timqi/ubix`,e.target=`_blank`,e.rel=`noreferrer`,e};function Z(e){let{spec:t,error:n,installed:r,version:i,path:a}=e.binary;return n?`${t} — ${n}`:r?`${t} — ${i??`unknown version`} at ${a??`an unknown path`}`:`${t} — not installed`}function Q(e,t={name:``,toml:``}){u++;let r=b(`span`,`text-[11.5px] text-neutral-400`,``);e&&l(r,e.state,e.text);let i=_e(`the update task`),a=e=>{let t=b(`div`,`flex min-w-0 flex-1 flex-col gap-0.5`,b(`span`,`flex items-center gap-2 text-[13px] text-neutral-700`,b(`span`,`font-mono`,e.name),...k(e)?[n(`yours`,`bg-neutral-50 text-neutral-500 ring-neutral-200`)]:[]),b(`span`,`text-[11.5px] leading-snug text-neutral-400`,e.summary||Z(e)),...e.summary?[b(`span`,`font-mono text-[11px] leading-snug ${e.binary.error?`text-red-600`:`text-neutral-400`}`,Z(e))]:[]),r=v(``,``,e.enabled,t=>void be(e.name,t,e=>Q(e))),i=b(`button`,`btn text-[12px] text-neutral-500 hover:text-red-600`,`Remove`);return i.onclick=()=>{i.disabled=!0;let t=De(e,D);se(t.body,t.saved).then(e=>Q(e))},b(`div`,`flex max-w-2xl items-start gap-3 border-b border-neutral-100 py-2.5 last:border-0`,t,...k(e)?[i]:[],r)},o={...t},s=b(`span`,`font-mono text-[12px] text-neutral-500`,`[tools.<name>]`),c=q(o.name,`claude`,e=>{o.name=e,s.textContent=`[tools.${e.trim()||`<name>`}]`},!0),d=document.createElement(`textarea`);d.className=`${x} h-24 resize-y font-mono leading-snug`,d.spellcheck=!1,d.value=o.toml,d.placeholder=`spec = "github:owner/repo"
|
|
2
2
|
exe = "tool"`,d.oninput=()=>o.toml=d.value;let f=b(`button`,`btn btn-primary text-[12.5px]`,`Add`);f.onclick=()=>{let e={name:o.name.trim(),toml:o.toml.trim()};if(!e.name||!e.toml)return l(r,`failed`,`A custom tool needs a name and a block with a spec line.`);f.disabled=!0,se({customTools:[...D,e],tool:{name:e.name,on:!0}},`Added ${e.name} — installing now.`).then(e=>Q(e,e.state===`failed`?o:void 0))},z.replaceChildren(V(`command-line tools`,b(`span`,`ml-auto text-[11px] uppercase tracking-wide text-neutral-400`,`installed by Pier`)),b(`div`,`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4`,b(`p`,`max-w-2xl text-[12.5px] leading-relaxed text-neutral-500`,`Pier writes no downloader: `,ye(),` does the work — a declarative installer that resolves a spec like `,b(`span`,`font-mono text-[11.5px]`,`github:owner/repo`),` to the right release asset for this machine, verifies it, and upgrades in place. Pier bootstraps it, generates its config from the switches below, and keeps its files under Pier's own directory — your own ubix setup is untouched.`),g?b(`p`,`max-w-2xl text-[12.5px] text-red-600`,g):b(`div`,`flex max-w-2xl flex-col`,...h.map(a)),b(`div`,`flex max-w-2xl flex-col gap-2 border-t border-neutral-200 pt-4`,b(`span`,`text-[12.5px] font-medium text-neutral-600`,`Add one of your own`),F(`Name`,c),F(`The block Pier writes under the header`,d,{hint:`A line that opens a section of its own is refused, because it could rewrite the rest of the file.`}),b(`div`,`flex items-center gap-3`,s,f)),b(`p`,`max-w-2xl text-[12px] leading-snug text-neutral-400`,...i?[`Installs and daily updates run as `,i,` — output, failures and all.`]:[`Switching one on creates the daily task that installs it and keeps it current.`]),r))}async function be(e,t,n){n(await se({tool:{name:e,on:t}},t?`Saved — installing now; watch the run.`:`Saved — uninstalling in the next run.`))}function Se(e){W(),e!==i&&(C(),i=e,a=null,we(),ce())}function we(){i!==`global`&&!t().includes(i)&&(i=`global`),ee.textContent=i===`global`?p():o(i),N.title=i===`global`?d:i}return c(e,()=>{we(),ce()},C)}var ke=`medium`,$=e=>`${e.provider}/${e.id}`,Ae=e=>({model:e.defaultModel,thinking:e.defaultThinkingLevel}),je=`Off — the first message is the title`,Me=[`hardest reasoning — architecture, gnarly debugging`,`long autonomous implementation runs`,`balanced default — implementation, review`,`cheap & fast — listings, extraction, simple checks`,`cross-vendor second opinion`];function Ne(){let e=[],t=[],n=!1,r,a={model:null,thinking:null},o=null,c=b(`span`,`text-[11.5px]`,``),u=b(`span`,`text-[11.5px]`,``),d=b(`div`,`flex items-center gap-3`),p=b(`span`,`text-[11.5px]`,``),m=b(`div`,`flex flex-col gap-1.5`),h=g(`Save menu`,!0),_=b(`div`,`flex min-w-0 flex-col gap-2`),v=b(`div`,`flex items-center gap-2`),y=b(`div`,`mx-auto flex w-full max-w-3xl min-w-0 flex-col gap-6`);function x(){n=!0,l(c,`idle`,`unsaved changes`)}function C(t,n,r,i){let a=e.indexOf(t),s=a+n,c=K(``,`icon-btn max-md:h-11 max-md:w-11 disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent`);return c.append(T(r)),c.title=i,c.setAttribute(`aria-label`,`${i}: ${$(t)}`),c.disabled=s<0||s>=e.length,c.onclick=()=>{e.splice(s,0,...e.splice(a,1)),o={at:$(t),step:n},x(),M()},c}function w(t){let n=P(t.note??``);n.classList.remove(`w-full`),n.classList.add(`min-w-0`,`flex-1`),n.placeholder=`why this one — pick a preset or write your own`,n.setAttribute(`list`,`model-menu-notes`),n.oninput=()=>{t.note=n.value,x()};let r=s(z.map(e=>[`thinking: ${re(e)}`,e]),t.thinking);r.classList.replace(`w-full`,`w-44`),r.classList.add(`flex-none`),r.onchange=()=>{t.thinking=r.value,x()};let i=g(`Remove`);i.classList.add(`flex-none`),i.onclick=()=>{e=e.filter(e=>e!==t),x(),M()};let a=b(`span`,`w-52 flex-none truncate font-mono text-[12px] text-neutral-700`,$(t));a.title=$(t);let c=C(t,-1,se,`Move up`),l=C(t,1,ne,`Move down`);if(o?.at===$(t)){let[e,t]=o.step===-1?[c,l]:[l,c];o=null,queueMicrotask(()=>(e.disabled?t:e).focus())}return b(`div`,`flex min-w-0 items-center gap-2 rounded-lg border border-neutral-200 bg-white px-3 py-2 shadow-2xs max-md:flex-wrap`,b(`span`,`flex flex-none items-center`,c,l),a,r,n,i)}function E(){let n=t.filter(t=>!e.some(e=>$(e)===$(t))),r=g(`Pin model`);r.prepend(T(G)),r.classList.add(`inline-flex`,`items-center`,`gap-1.5`,`flex-none`,`whitespace-nowrap`),r.disabled=n.length===0,r.onclick=()=>{let t=ke;k(r,V({models:n,current:null,thinkingLevel:t,thinkingLevels:[...z],onThinkingPick:e=>{t=e},onPick:n=>{W(),e.push({provider:n.provider,id:n.id,thinking:t}),x(),M()}}))},v.replaceChildren(r)}function D(){let e=r,n=e&&!t.some(t=>$(t)===$(e))?[e,...t]:t,i=K(e?e.id:je,`${ie} flex min-w-0 flex-1 items-center ${e?`text-neutral-700`:`text-neutral-400`}`);e&&(i.title=$(e));let a=e=>{W(),(async()=>{l(u,`saving`,`saving…`);let t=await S(`/api/settings`,{titleModel:e&&{provider:e.provider,id:e.id}},`PUT`);if(!t.ok)return l(u,`failed`,await O(t,`Could not save`)),D();r=(await t.json()).titleModel,l(u,`saved`,r?`Saved — names the next new session after its first reply.`:`Off.`),D()})()};i.onclick=()=>{let t=V({models:n,current:e,thinkingLevel:`medium`,thinkingLevels:[],onThinkingPick:()=>{},onPick:a}),r=K(je,`w-full cursor-pointer px-3 py-1.5 text-left text-[12.5px] text-neutral-500 hover:bg-neutral-100`);r.onclick=()=>a(null);let o=b(`div`,`flex flex-col`);o.append(t,b(`div`,`border-t border-neutral-200`),r),k(i,o)},d.replaceChildren(i,u)}function A(){m.replaceChildren(R(`Default model`,a,t,e=>void j(e)),p)}async function j(e){l(p,`saving`,`saving…`);let t=await S(`/api/config/defaults`,{defaultModel:e.model,defaultThinkingLevel:e.thinking},`PUT`);if(!t.ok)return l(p,`failed`,await O(t,`Could not save`)),A();a=Ae(await t.json()),l(p,`saved`,a.model||a.thinking?`Saved — the next new session starts on it.`:`Pi default.`),A()}function M(){_.replaceChildren(...e.length?e.map(w):[f(`Nothing pinned — every picker shows the curated catalog as is.`)]),E(),A(),D()}async function ee(){l(c,`saving`,`saving…`);let t=e.map(({provider:e,id:t,thinking:n,note:r})=>({provider:e,id:t,thinking:n,...r?.trim()?{note:r.trim()}:{}})),r=await S(`/api/settings`,{modelMenu:t},`PUT`);if(!r.ok)return l(c,`failed`,await O(r,`Could not save`));e=(await r.json()).modelMenu,n=!1,l(c,`saved`,`Saved — agents see it on their next models call.`),M()}h.onclick=()=>void ee();function N(){n||(async()=>{let[n,i,o]=await Promise.all([U(`/api/settings`,`Could not load the menu`),U(`/api/models`,`Could not load the model catalog`),U(`/api/config/defaults`,`Could not read the default model`)]);if(!n.ok)return l(c,`failed`,n.error);e=n.value.modelMenu,r=n.value.titleModel,t=i.ok?i.value:[],o.ok?(a=Ae(o.value),p.textContent=``):l(p,`failed`,o.error),c.textContent=``,M()})()}let I=b(`datalist`,``);return I.id=`model-menu-notes`,I.append(...Me.map(e=>new Option(e))),y.append(i(`Model menu`,`Which few models this deployment favors, each with a usual reasoning level and one line of intent. Pinned entries lead every model picker, and agents delegating work match your notes against the task instead of guessing ids.`,F(`Pinned models`,_,{hint:"The note is what an agent matches a task against — say when to reach for it, not what it is, and keep every note distinct: two pins reading alike are refused as ambiguous. The arrows set the order pickers and `pier task --model ?` list."}),F(`Add`,v,{hint:`The list is the live catalog — only models that exist right now can be pinned.`}),b(`div`,`flex items-center gap-3`,h,c),I),i(`New sessions`,`The model and reasoning effort a session starts on when nothing names one — a channel, chat or task with its own launch choice overrides it. Pi default leaves the pick to Pi. Stored in settings.json; applies to sessions opened from now on.`,m),i(`Session titles`,`A session is titled by its first message unless a model names it: one short request after the first reply, on the model picked here — a small, cheap one is plenty. A failed request is reported in the session and the first message stays the title.`,F(`Title model`,d))),{el:y,load:N}}var Pe=e=>Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`)),e=>e.charCodeAt(0)),Fe=e=>btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``);function Ie(){let e=b(`div`,`flex flex-col gap-2`),t=b(`span`,`text-[11.5px]`,``),n=P();n.placeholder=`Label, e.g. MacBook Touch ID`,n.autocomplete=`off`,n.maxLength=80;let a=g(`Add a passkey`,!0),o=b(`div`,`flex flex-wrap items-center gap-3`,n,a,t),s=b(`p`,`hidden text-[12.5px] leading-snug text-neutral-600`),c=b(`p`,`hidden text-[12px] text-neutral-400`);function u(n){if(c.textContent=n.reason??``,c.classList.toggle(`hidden`,n.enabled),o.classList.toggle(`hidden`,!n.enabled),s.textContent=`Password sign-in is off while a passkey is registered; remove every passkey to turn it back on.`,s.classList.toggle(`hidden`,!n.passkeys.length),!n.passkeys.length){e.replaceChildren(f(`No passkey is registered.`));return}e.replaceChildren(...n.passkeys.map(e=>{let n=g(`Remove`);n.onclick=()=>{n.disabled=!0,(async()=>{let n=await N(`/api/passkeys/${encodeURIComponent(e.id)}`,`DELETE`,`Could not remove it`);n?l(t,`failed`,n):l(t,`saved`,`Removed.`),await p()})()};let i=e.lastUsedAt?`last used ${y(e.lastUsedAt)}`:`never used`,a=e.transports.length?` · ${e.transports.join(`, `)}`:``;return r(e.label,`added ${y(e.createdAt)} · ${i}${a}`,n)}))}async function d(){if(!window.PublicKeyCredential)return l(t,`failed`,`This browser has no passkey support.`);a.disabled=!0,l(t,`saving`,`asking this browser…`);try{let e=await H(`/api/passkeys/register/options`,{},`Could not start`);if(!e.ok)return l(t,`failed`,e.error);let r={...e.value,challenge:Pe(e.value.challenge),user:{...e.value.user,id:Pe(e.value.user.id)},excludeCredentials:e.value.excludeCredentials.map(e=>({...e,id:Pe(e.id),transports:e.transports}))},i=await navigator.credentials.create({publicKey:r});if(!i)return l(t,`failed`,`No passkey was created.`);let a=i.response,o=await S(`/api/passkeys/register/verify`,{id:i.id,type:i.type,label:n.value,response:{clientDataJSON:Fe(a.clientDataJSON),attestationObject:Fe(a.attestationObject),transports:a.getTransports?.()??[]}});if(!o.ok)return l(t,`failed`,await O(o,`Could not register it`));n.value=``,u(await o.json()),l(t,`saved`,`Added. The password is off until every passkey is removed.`)}catch(e){let n=e instanceof DOMException&&e.name===`NotAllowedError`;l(t,`failed`,n?`The prompt was dismissed or timed out.`:`Could not add it: ${String(e)}`)}finally{a.disabled=!1}}a.onclick=()=>void d();async function p(){let t=await U(`/api/passkeys`,`Could not load passkeys`);return t.ok?(u(t.value),t.value.passkeys.length>0):(e.replaceChildren(f(t.error)),!1)}return{el:i(`Passkeys`,`Sign in with Touch ID, Windows Hello, a phone or a security key instead of the password. Bound to the public URL's host.`,e,s,c,o),load:p}}var Le=(e,t)=>{let n;try{n=new URL(e)}catch{return null}if(n.protocol!==`http:`&&n.protocol!==`https:`)return null;let r=b(`a`,`text-indigo-600 hover:underline`,t);return r.href=n.href,r.target=`_blank`,r.rel=`noreferrer`,r};function Re(e,t,n,r){let i=document.createElement(`dialog`);i.className=`m-auto w-[min(32rem,92vw)] rounded-lg border border-neutral-200 bg-white p-0 shadow-xl backdrop:bg-black/30`;let a=b(`div`,`flex flex-col gap-2`),o=b(`div`,`flex flex-col gap-2`),s=b(`p`,`text-[12.5px] text-neutral-400`,`Starting…`),c=g(`Cancel`),l=(e,t)=>{s.className=`text-[12.5px] ${h[e]}`,s.textContent=t};i.append(b(`div`,`border-b border-neutral-200 px-4 py-2.5 text-[14px] font-semibold`,t),b(`div`,`flex max-h-[65vh] flex-col gap-3 overflow-y-auto px-4 py-3`,a,o,s),b(`div`,`flex justify-end border-t border-neutral-200 px-4 py-2.5`,c)),document.body.append(i),i.showModal();let u=e.id,d=e.state,f,p,m=new Set,_=!1,v=!1,y=async e=>{if(!v){if(e&&d===`running`){v=!0,c.disabled=!0;try{let e=await S(`/api/providers/flows/${u}/cancel`,{});if(!e.ok&&e.status!==404){l(`failed`,await O(e,`Could not cancel authentication flow`));return}}catch(e){l(`failed`,`Could not cancel authentication flow: ${String(e)}`);return}finally{v=!1,c.disabled=!1}}clearTimeout(f),i.close()}};c.onclick=()=>void y(!0),i.oncancel=e=>{e.preventDefault(),y(!0)},i.onclose=()=>{_=!0,clearTimeout(f),i.remove()};let x=e=>{if(e.type===`auth_url`){let t=b(`div`,`flex flex-col gap-1 text-[12.5px] text-neutral-600`);return e.instructions&&t.append(b(`p`,``,e.instructions)),t.append(Le(e.url,`Open authorization page`)??b(`span`,`text-red-600`,`Invalid authorization URL`)),t}if(e.type===`device_code`){let t=b(`div`,`flex flex-col gap-2 text-[12.5px] text-neutral-600`);return t.append(b(`div`,`flex items-center gap-2`,b(`code`,`font-mono text-[17px] font-semibold text-neutral-800`,e.userCode),B(`btn text-[11px]`,()=>e.userCode))),t.append(Le(e.verificationUri,`Open verification page`)??b(`span`,`text-red-600`,`Invalid verification URL`)),t}let t=b(`div`,`text-[12.5px] text-neutral-600`,e.message);if(e.type===`info`)for(let n of e.links??[]){let e=Le(n.url,n.label??n.url);e&&t.append(` `,e)}return t},C=(e,t)=>{p=t.id;let n;if(t.type===`select`){let e=document.createElement(`select`);e.append(...t.options.map(e=>new Option(e.description?`${e.label} — ${e.description}`:e.label,e.id))),n=e}else{let e=P(``,t.type===`secret`?`password`:`text`);e.placeholder=t.placeholder??``,e.autocomplete=`off`,n=e}n.className=`${n.tagName===`SELECT`?`select `:``}w-full rounded-lg border border-neutral-300 bg-white px-2.5 py-1.5 text-[12.5px] focus:border-indigo-400 focus:outline-none`;let r=g(`Continue`,!0);r.type=`submit`;let i=b(`form`,`flex flex-col gap-2`,b(`label`,`text-[12.5px] font-medium text-neutral-700`,t.message),n,b(`div`,`flex justify-end`,r));i.onsubmit=i=>{i.preventDefault(),r.disabled=!0,(async()=>{try{let r=await S(`/api/providers/flows/${e.id}/respond`,{promptId:t.id,value:n.value});if(_)return;if(!r.ok){l(`failed`,await O(r,`Could not submit response`));return}m.add(t.id),p=void 0,o.replaceChildren(),l(`saving`,`Waiting for provider…`)}catch(e){_||l(`failed`,`Could not submit response: ${String(e)}`)}finally{r.disabled=!1}})()},o.replaceChildren(i),n.focus()},w=e=>{d=e.state,a.replaceChildren(...e.events.map(x));let t=e.prompt&&!m.has(e.prompt.id)?e.prompt:void 0;if(t?.id!==p&&(t?C(e,t):(p=void 0,o.replaceChildren())),e.state===`running`){l(`saving`,t?`Waiting for your response.`:`Waiting for provider…`);return}clearTimeout(f),o.replaceChildren(),e.state===`succeeded`?l(`saved`,`${n} configured.`):l(`failed`,e.state===`cancelled`?`Cancelled.`:e.error??`Authentication failed.`),c.textContent=`Close`,c.onclick=()=>void y(!1),e.state===`succeeded`&&r()},T=async()=>{if(!(_||d!==`running`))try{let e=await fetch(`/api/providers/flows/${u}`,{cache:`no-store`});if(_)return;if(!e.ok){l(`failed`,await O(e,`Authentication status unavailable`)),e.status===404?d=`failed`:f=setTimeout(()=>void T(),1e3);return}w(await e.json()),d===`running`&&(f=setTimeout(()=>void T(),500))}catch(e){if(_)return;l(`failed`,`Authentication status unavailable: ${String(e)}`),f=setTimeout(()=>void T(),1e3)}};w(e),d===`running`&&(f=setTimeout(()=>void T(),500))}var ze=[`anthropic`,`openai`,`openai-codex`,`google`,`openrouter`,`deepseek`],Be=[[`OpenAI Chat Completions`,`openai-completions`],[`OpenAI Responses`,`openai-responses`],[`Anthropic Messages`,`anthropic-messages`],[`Google Generative AI`,`google-generative-ai`]],Ve=`__custom__`;async function He(e){let t=g(`Add provider`,!0);t.classList.add(`ml-auto`);let r=b(`div`,`flex flex-none items-center gap-3 rounded-t-3xl ${ae} px-4 py-2`,b(`h2`,`text-[13px] font-semibold text-neutral-700`,`Providers`),t),i=b(`div`,`min-h-0 flex-1 overflow-y-auto`);e.replaceChildren(r,i);let a=[],o=``,c=async()=>{i.replaceChildren(b(`p`,`px-4 py-3 text-[13px] text-neutral-400`,`Loading…`));try{let[e,n]=await Promise.all([U(`/api/providers`,`Could not load providers`,{cache:`no-store`}),U(`/api/models`,`the model catalog could not be read`,{cache:`no-store`})]);if(a=n.ok?n.value:[],o=n.ok?``:n.error,!e.ok){i.replaceChildren(f(e.error));return}let r=e.value;t.onclick=()=>We(r,void 0,c),h(r)}catch(e){i.replaceChildren(f(`Could not load providers: ${String(e)}`))}},u=async e=>{if(window.confirm(`Remove the stored credential for ${e.name}?`))try{let t=await S(`/api/providers/${encodeURIComponent(e.id)}/logout`,{});if(!t.ok){window.alert(await O(t,`Could not remove credential`));return}await c()}catch(e){window.alert(`Could not remove credential: ${String(e)}`)}},d=e=>[...new Set([...(e.models??[]).map(e=>e.id),...a.filter(t=>t.provider===e.id).map(e=>e.id)])],p=(e,t)=>b(`div`,`flex flex-col gap-1`,b(`span`,`text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),b(`pre`,`max-h-56 overflow-auto whitespace-pre-wrap break-all rounded-md bg-neutral-50 p-2 font-mono text-[11.5px] leading-relaxed text-neutral-600`,t)),m=async(e,t)=>{try{let n=await S(`/api/providers/${encodeURIComponent(e)}/check`,{model:t});return n.ok?await n.json():await O(n,`Could not test`)}catch(e){return`Could not test: ${String(e)}`}},h=e=>{let t=e.filter(e=>e.configured);if(!t.length){i.replaceChildren(f(`No providers configured.`));return}i.replaceChildren(...t.map(t=>{let r=b(`div`,`min-w-0 flex-1`,b(`div`,`truncate text-[13px] font-medium text-neutral-700`,t.name),b(`div`,`truncate font-mono text-[11px] text-neutral-400`,t.id)),i=t.stored===`api_key`?`API key`:t.stored===`oauth`?`OAuth`:t.source??`configured`,a=t.endpoint??`Default endpoint`,f=b(`div`,`flex min-w-32 flex-col items-start gap-1`,n(`configured`,`bg-emerald-50 text-emerald-700 ring-emerald-200`),b(`span`,`max-w-48 truncate text-[11px] text-neutral-500`,i),b(`span`,`max-w-48 truncate text-[11px] text-neutral-400`,a));f.title=a;let h=b(`span`,`text-[11.5px]`,``),_=b(`div`,`hidden flex-col gap-2 px-4 pb-3`,h),v=b(`div`,`flex flex-wrap justify-end gap-1.5`),y=d(t);if(!y.length)l(h,`idle`,o||`No models to test: none are configured here.`),_.classList.replace(`hidden`,`flex`);else{let e=s([[`Model to test…`,``],...y.map(e=>[e,e])],``);e.classList.add(`max-w-52`,`text-[12px]`);let n=g(`Test`);n.disabled=!0,e.onchange=()=>n.disabled=!e.value,n.onclick=()=>{let r=e.value;n.disabled=!0,_.replaceChildren(h),_.classList.replace(`hidden`,`flex`),l(h,`saving`,`asking ${r}…`),m(t.id,r).then(e=>{if(n.disabled=!1,typeof e==`string`)return l(h,`failed`,e);l(h,e.ok?`saved`:`failed`,`${e.model} ${e.ok?`answered`:`did not answer`} in ${e.ms} ms`),_.append(p(`sent`,e.request||`(the request was never made)`),p(e.ok?`answered`:`replied`,e.response))})},v.append(e,n)}if(t.builtin||t.api&&t.models){let n=g(`Edit`);n.onclick=()=>We(e,t,c),v.append(n)}if(t.stored){let e=g(`Remove credential`);e.onclick=()=>void u(t),v.append(e)}return b(`div`,`border-b border-neutral-100`,b(`div`,`grid grid-cols-[minmax(8rem,1fr)_minmax(8rem,auto)_minmax(9rem,auto)] items-center gap-3 px-4 py-2.5 max-sm:grid-cols-[1fr_auto]`,r,f,v),_)}))};await c()}function Ue(e,t){let n=t.filter(e=>!e.configured&&e.methods.length&&(e.builtin||e.api!==void 0&&e.models!==void 0)),r=(t,n)=>{if(!n.length)return;let r=document.createElement(`optgroup`);r.label=t,r.append(...n.map(e=>new Option(e.name,e.id))),e.append(r)};r(`Common`,ze.flatMap(e=>n.filter(t=>t.id===e))),r(`More providers`,n.filter(e=>e.builtin&&!ze.includes(e.id)).sort((e,t)=>e.name.localeCompare(t.name))),r(`Custom providers`,n.filter(e=>!e.builtin).sort((e,t)=>e.name.localeCompare(t.name))),e.append(new Option(`Custom provider…`,Ve))}function We(e,n,r){let i=document.createElement(`dialog`);i.className=`m-auto w-[min(32rem,92vw)] rounded-lg border border-neutral-200 bg-white p-0 shadow-xl backdrop:bg-black/30`;let a=document.createElement(`select`);a.className=`${x} select`,n||Ue(a,e);let o=P(),c=P(),l=P(),u=document.createElement(`select`);u.className=`${x} select`,u.append(...Be.map(([e,t])=>new Option(e,t)));let d=t(``,4);d.placeholder=`model-id
|
|
3
3
|
another-model-id`;let f=document.createElement(`input`);f.type=`checkbox`;let p=s([[`Up to High`,`high`],[`Up to Extra high`,`xhigh`],[`Up to Max`,`max`]],`high`);p.classList.replace(`w-full`,`w-48`),f.onchange=()=>{p.disabled=!f.checked};let m=document.createElement(`select`);m.className=`${x} select`;let h=b(`div`,`flex flex-col gap-4`),_=b(`span`,`text-[11.5px] text-red-600`,``),v=g(`Cancel`),y=g(n?`Save`:`Add`,!0);y.type=`submit`;let C=()=>n??e.find(e=>e.id===a.value),w=()=>{let e=C(),t=e?!e.builtin:a.value===Ve;o.value=e?.id??``,o.disabled=n!==void 0,c.value=e?.name??``,l.value=e?.endpoint??``,u.value=e?.api??`openai-completions`,d.value=e?.models?.map(e=>e.id).join(`
|
|
4
4
|
`)??``;let r=e?.models?.map(e=>e.reasoning)??[];f.checked=r.length?r.every(Boolean):!e,f.indeterminate=r.some(Boolean)&&!r.every(Boolean);let i=new Set((e?.models??[]).filter(e=>e.reasoning).map(e=>e.effort??`high`)),s=i.size>1;p.replaceChildren(...s?[new Option(`Keep as configured`,``)]:[],new Option(`Up to High`,`high`),new Option(`Up to Extra high`,`xhigh`),new Option(`Up to Max`,`max`)),p.value=s?``:[...i][0]??`high`,p.disabled=!f.checked&&!f.indeterminate;let g=[];e?.configured&&g.push(new Option(`Keep current authentication`,``));let _=e?.methods??[{type:`api_key`,name:`API key`}];for(let t of _.filter(t=>e?.builtin!==!1||t.type===`api_key`))g.push(new Option(t.name,t.type));m.replaceChildren(...g);let v=[];n||v.push(F(`Provider`,a)),t?v.push(F(`Provider ID`,o),F(`Display name`,c),F(`Endpoint`,l),F(`API format`,u),F(`Models`,d),F(`Model capabilities`,b(`div`,`flex flex-wrap items-center gap-3`,b(`label`,`flex items-center gap-2 text-[12.5px] text-neutral-600`,f,b(`span`,``,`Reasoning`)),p),{hint:`Extra high and Max reach the model only if it accepts them; every reasoning model has High.`})):(l.placeholder=`Provider default`,v.push(F(`Endpoint`,l))),v.push(F(`Authentication`,m)),h.replaceChildren(...v)};a.onchange=w,w();let T=b(`form`,`flex flex-col gap-4 px-4 py-3`,h,b(`div`,`flex items-center justify-end gap-2`,_,v,y)),E=!1;v.onclick=()=>{E||i.close()},i.oncancel=e=>{E&&e.preventDefault()},T.onsubmit=e=>{if(e.preventDefault(),E)return;_.textContent=``;let t=C(),n=(t?!t.builtin:a.value===Ve)?{kind:`custom`,id:o.value.trim(),...c.value.trim()?{name:c.value.trim()}:{},endpoint:l.value.trim(),api:u.value,models:[...new Set(d.value.split(`
|
|
Binary file
|
|
Binary file
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{C as e,H as t,O as n,T as r,X as i,Y as a,ct as o,ft as s,tt as c}from"./index-
|
|
1
|
+
import{C as e,H as t,O as n,T as r,X as i,Y as a,ct as o,ft as s,tt as c}from"./index-BQo-haPN.js";var l=e=>e===null?`-`:new Date(e).toLocaleString(),u=e=>e.startedAt===null?`-`:a((e.finishedAt??Date.now())-e.startedAt),d=e=>e.state===`succeeded`&&e.matched===!1?`No match`:e.state,f={queued:`bg-neutral-100 text-neutral-600 ring-neutral-200`,running:`bg-sky-50 text-sky-700 ring-sky-200`,succeeded:`bg-emerald-50 text-emerald-700 ring-emerald-200`,failed:`bg-red-50 text-red-700 ring-red-200`,cancelled:`bg-amber-50 text-amber-700 ring-amber-200`,interrupted:`bg-amber-50 text-amber-700 ring-amber-200`,skipped:`bg-neutral-100 text-neutral-600 ring-neutral-200`};function p(t){let n=d(t);return e(n,n===`No match`?f.skipped:f[t.state],t.state===`running`?`animate-pulse bg-sky-500`:void 0)}function m(t){return t.archived?e(`Archived`,`bg-neutral-50 text-neutral-400 ring-neutral-200`):t.trigger.type===`manual`?e(`Manual`,`bg-neutral-100 text-neutral-600 ring-neutral-200`):t.enabled?e(`Enabled`,`bg-emerald-50 text-emerald-700 ring-emerald-200`):e(`Paused`,`bg-amber-50 text-amber-700 ring-amber-200`)}var h=`px-4 pt-4 text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,g=`m-4 mt-2 whitespace-pre-wrap break-words rounded-lg border border-black/[0.06] bg-black/[0.025] px-3 py-2 font-mono text-[12px] leading-snug dark:border-neutral-200 dark:bg-neutral-100`,_=e=>e.trigger.type===`manual`?`Manual`:e.trigger.type===`cron`?`${e.trigger.expression} (${e.trigger.timezone})`:`Every ${e.trigger.intervalSeconds}s · ${e.trigger.mode}`,v=e=>e.action.type===`agent`?`Agent · ${e.action.session.mode}`:e.action.type===`bash`?`Bash`:e.action.type===`system`?`System`:`Task`;function y(e,t){let n=i(`div`,`grid max-w-4xl grid-cols-[6rem_minmax(0,1fr)] gap-x-5 gap-y-3.5 p-4 text-[13px] md:grid-cols-[9.375rem_minmax(0,1fr)]`),a=[[`Status`,e.archived?`Archived`:e.trigger.type===`manual`?`Manual`:e.enabled?`Enabled`:`Paused`],[`Trigger`,_(e)],[`Action`,v(e)],[`Timeout`,`${e.timeoutSeconds}s`],[`Next run`,l(e.nextRunAt)],[`Revision`,String(e.revision)],[`Created by`,e.createdBySessionId??e.creator],[`Callback`,e.callback.type===`session`?e.callback.sessionId:e.callback.type],[`Description`,e.description||`-`]];e.action.type===`agent`&&(a.push([`Session policy`,e.action.session.mode]),e.action.session.mode===`reuse`&&a.push([`Session`,e.action.session.sessionId]),`cwd`in e.action.session&&a.push([`Directory`,e.action.session.cwd]),e.action.launch?.model&&a.push([`Model`,`${e.action.launch.model.provider}/${e.action.launch.model.id}`]),e.action.launch?.thinking&&a.push([`Thinking`,e.action.launch.thinking]),a.push([`Prompt`,e.action.prompt])),e.action.type===`bash`&&a.push([`Directory`,e.action.cwd],[`Script`,e.action.script]),e.action.type===`task`&&a.push([`Target task`,e.action.taskId]),e.action.type===`system`&&a.push([`System action`,e.action.name]),e.trigger.type===`watch`&&a.push([`Probe`,e.trigger.script]);for(let[e,t]of a)n.append(i(`span`,`pt-px text-[10.5px] font-semibold uppercase tracking-wide text-neutral-400`,e),i(`pre`,`whitespace-pre-wrap break-words font-mono text-[12.5px] leading-snug`,t));if(e.action.type===`agent`&&e.action.session.mode===`reuse`){let{sessionId:a}=e.action.session,o=r(`Open session`);o.onclick=()=>t(a),n.append(i(`span`,``,``),o)}return n}function b(e){return[e.callbackState&&e.callbackState!==`delivered`?`Callback not delivered (${e.callbackState})`:``,e.groupCallbackState&&e.groupCallbackState!==`delivered`?`Group callback not delivered (${e.groupCallbackState})`:``].filter(Boolean).join(` · `)}function x(e,t,r,a){let o=i(`div`,`divide-y divide-neutral-100`);for(let e of t){let t=i(`button`,`grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 px-4 py-2.5 text-left text-[12.5px] transition-colors hover:bg-neutral-50 md:grid-cols-[7.5rem_minmax(0,1fr)_7.5rem_6.25rem]`);t.setAttribute(`type`,`button`),t.append(i(`span`,`flex`,p(e)),i(`span`,`truncate text-neutral-500`,l(e.queuedAt)),i(`span`,`text-neutral-500`,e.triggerSource),i(`span`,`text-right font-mono text-[11.5px] text-neutral-400`,u(e))),t.onclick=()=>r(e.id),o.append(t)}t.length||o.append(i(`div`,`p-4`,n(`No runs yet.`))),e.replaceChildren(o),e.scrollTop=a.top,e.onscroll=()=>{a.top=e.scrollTop}}var S=e=>`Exit code: ${e.exitCode??`-`}\nstdout:\n${e.stdout}${e.stdoutTruncated?`
|
|
2
2
|
[stdout truncated]`:``}\nstderr:\n${e.stderr}${e.stderrTruncated?`
|
|
3
3
|
[stderr truncated]`:``}`;async function C(e,n,a,d,f){let m=String(Number(e.dataset.runRequest??0)+1);e.dataset.runRequest=m,e.onscroll=()=>{f.scrollTop=e.scrollTop};let _=r(`Runs`);_.className=`cursor-pointer text-neutral-500 hover:text-neutral-800 hover:underline`,_.onclick=()=>{f.selectedId=null,f.scrollTop=0,a()};let v=t(_,o(s,`h-3.5 w-3.5 text-neutral-400`),i(`span`,`min-w-0 truncate font-mono text-[12px] text-neutral-500`,n)),C=e.dataset.runId!==n;C&&(e.dataset.runId=n,e.replaceChildren(v,i(`p`,`p-4 text-[13px] text-neutral-500`,`Loading run...`)));let[w,T]=await Promise.all([c(`/api/task-runs/${n}`,`Could not load the run`),c(`/api/task-runs/${n}/messages`,`Could not load the run's messages`)]);if(!e.isConnected||e.dataset.runRequest!==m||f.selectedId!==n)return;if(!w.ok){let t=await c(`/api/task-groups/${n}`,w.error);if(!e.isConnected||e.dataset.runRequest!==m||f.selectedId!==n)return;if(f.drawn=``,!t.ok){e.replaceChildren(v,i(`p`,`p-4 text-[13px] text-red-600`,w.error));return}let{group:r,members:a}=t.value,o=i(`div`,`min-w-0`);e.replaceChildren(v,i(`div`,`border-b border-neutral-100 bg-neutral-50/60 px-4 py-3 text-[12.5px] text-neutral-600`,[`Task group \u00b7 join ${r.join}`,`${String(a.length)} runs`,r.callbackState?`callback ${r.callbackState}`:``].filter(Boolean).join(` · `)),o),x(o,a,d.openRun,{top:0});return}let E=w.value,D=T.ok?T.value:[],O=JSON.stringify([E,T]);if(!C&&f.drawn===O)return;if(f.drawn=O,E.targetSessionId){let e=r(`Open session`);e.classList.add(`ml-auto`),e.onclick=()=>d.openSession(E.targetSessionId),v.append(e)}if(E.state===`queued`||E.state===`running`){let e=r(`Stop run`);e.onclick=()=>{window.confirm(`Stop this run of "${E.context.definition.name}"?`)&&d.mutate(`/api/task-runs/${E.id}/cancel`)},v.append(e)}let k=i(`div`,`min-w-0`),A=b(E);k.append(i(`div`,`flex flex-wrap items-center gap-x-5 gap-y-2 border-b border-neutral-100 bg-neutral-50/60 px-4 py-3 text-[12.5px]`,i(`span`,`flex items-center gap-2`,p(E),i(`span`,`font-medium`,E.context.definition.name)),...A?[i(`span`,`rounded-md bg-amber-50 px-2 py-0.5 text-[12px] text-amber-700 ring-1 ring-amber-200`,A)]:[],i(`span`,`text-neutral-500`,l(E.queuedAt)),i(`span`,`text-neutral-500`,E.triggerSource),i(`span`,`font-mono text-[11.5px] text-neutral-400`,u(E))));let j=i(`div`,`flex flex-wrap items-center gap-2 border-b border-neutral-100 px-4 py-3 text-[12px]`),M=(e,t)=>{let n=r(e);n.classList.add(`max-w-full`,`break-all`,`!whitespace-normal`),n.onclick=t,j.append(n)};if(E.context.definition.kind===`task`&&M(`Task: ${E.context.definition.name}`,()=>d.openTask(E.taskId)),E.parentRunId&&M(`Parent: ${E.parentRunId}`,()=>d.openRun(E.parentRunId)),E.resumedFromRunId&&M(`Resumed from: ${E.resumedFromRunId}`,()=>d.openRun(E.resumedFromRunId)),E.result?.type===`task`){let e=E.result.runId;M(`Child result: ${e}`,()=>d.openRun(e))}E.groupId&&j.append(i(`span`,`break-all font-mono text-[11.5px] text-neutral-500`,`Group: ${E.groupId}`)),k.append(j);for(let e of[E.error,E.skipReason,E.callbackError])e&&k.append(i(`p`,`m-4 whitespace-pre-wrap break-words rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-[12.5px] text-red-700`,e));if(E.result){let e=E.result,t=e.type===`agent`||e.type===`system`?e.text:e.type===`bash`?S(e):e.type===`task`?`Child run: ${e.runId}`:`Watch did not match.`;k.append(i(`h3`,h,`Result`),i(`pre`,g,t||`No output.`))}E.probe&&k.append(i(`h3`,h,`Watch probe: ${E.matched===null?`not evaluated`:E.matched?`matched`:`not matched`}`),i(`pre`,g,S(E.probe)));let N=i(`details`,`border-t border-neutral-200`);if(N.append(i(`summary`,`flex cursor-pointer items-center gap-1.5 px-4 py-3 text-[12px] text-neutral-500 hover:text-neutral-800`,o(s,`chev h-3 w-3`),`Configuration snapshot (revision ${E.taskRevision})`),y(E.context.definition,d.openSession)),k.append(N),T.ok||k.append(i(`p`,`m-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-[12.5px] text-red-700`,T.error)),D.length){let e=i(`div`,`mt-2 divide-y divide-neutral-100 border-t border-neutral-100`);for(let t of D){let n=i(`div`,`grid grid-cols-[auto_1fr] gap-3 px-4 py-2 text-[12px] md:grid-cols-[6.25rem_6.25rem_minmax(0,1fr)]`);n.append(i(`span`,`font-medium`,t.kind),i(`span`,`text-neutral-500`,t.state),i(`span`,`col-span-2 whitespace-pre-wrap break-words md:col-span-1`,t.content)),t.error&&n.append(i(`span`,`col-span-2 break-words text-red-600 md:col-span-3`,t.error)),e.append(n)}k.append(i(`div`,`border-t border-neutral-200`,i(`div`,h,`Messages`),e))}let P=i(`details`,`border-t border-neutral-200`);P.open=f.rawOpen,P.ontoggle=()=>{P.isConnected&&(f.rawOpen=P.open)},P.append(i(`summary`,`flex cursor-pointer items-center gap-1.5 px-4 py-3 text-[12px] text-neutral-500 hover:text-neutral-800`,o(s,`chev h-3 w-3`),`Raw record`),i(`pre`,g,JSON.stringify(E,null,2))),k.append(P),e.replaceChildren(v,k),e.scrollTop=f.scrollTop,e.onscroll=()=>{f.scrollTop=e.scrollTop}}export{x as a,u as c,C as i,m as l,l as n,b as o,y as r,p as s,v as t,_ as u};
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$ as e,B as t,C as n,F as r,H as i,I as a,K as o,O as s,T as c,X as l,_ as u,at as d,ct as f,et as p,ft as m,it as h,j as g,k as _,o as v,s as y,st as b,tt as x}from"./index-
|
|
1
|
+
import{$ as e,B as t,C as n,F as r,H as i,I as a,K as o,O as s,T as c,X as l,_ as u,at as d,ct as f,et as p,ft as m,it as h,j as g,k as _,o as v,s as y,st as b,tt as x}from"./index-BQo-haPN.js";import{a as S,c as C,l as w,n as T,r as E,s as D,t as O,u as k}from"./task-runs-0pvdITiV.js";function A(e,t){let n=e.map(e=>[`${e.title??`Untitled`} · ${e.cwd}`,e.id]);return t&&!n.some(([,e])=>e===t)&&n.push([`Current session · ${t}`,t]),n}function j(e,n){let r=document.createElement(`dialog`);r.className=`m-auto w-[38.75rem] max-w-[94vw] rounded-lg border border-neutral-200 p-0 shadow-xl backdrop:bg-black/20`;let i=document.createElement(`form`);i.className=`flex max-h-[88vh] flex-col`;let o=l(`span`,`mr-auto text-[12px] text-red-600`),s=l(`header`,`flex h-11 flex-none items-center border-b border-neutral-200 px-4 font-medium`,n?`Edit task`:`New task`),u=l(`div`,`grid min-h-0 flex-1 grid-cols-2 gap-3 overflow-y-auto p-4`),d=g(n?.name??``);d.required=!0;let f=g(n?.description??``),p=g(String(n?.timeoutSeconds??3600),`number`);p.min=`1`,p.max=`86400`;let m=a([[`Manual`,`manual`],[`Scheduled`,`cron`],[`Watch`,`watch`]],n?.trigger.type??`manual`),h=a([[`Bash`,`bash`],[`Agent`,`agent`],[`Task`,`task`]],n?.action.type??`bash`),x=a([[`No callback`,`none`],[`Invoking session`,`origin`],[`Specific session`,`session`]],n?.callback.type??`none`),S=n?.callback.type===`session`?n.callback.sessionId:null,C=a(A(e.sessions(),S),S??``),w=_(`Callback session`,C);w.classList.toggle(`hidden`,x.value!==`session`),x.onchange=()=>w.classList.toggle(`hidden`,x.value!==`session`),u.append(_(`Name`,d),_(`Description`,f),_(`Trigger`,m),_(`Action`,h),_(`Callback`,x),w,_(`Timeout (seconds)`,p));let T=l(`div`,`col-span-2 grid grid-cols-2 gap-3 border-t border-neutral-200 pt-3`);u.append(T);let E=()=>{T.replaceChildren();let s,c,u,S,w,E;if(m.value===`cron`)s=g(n?.trigger.type===`cron`?n.trigger.expression:`0 9 * * *`),c=g(n?.trigger.type===`cron`?n.trigger.timezone:Intl.DateTimeFormat().resolvedOptions().timeZone),T.append(_(`Cron`,s),_(`Timezone`,c));else if(m.value===`watch`){u=t(n?.trigger.type===`watch`?n.trigger.script:``,4),E=g(n?.trigger.type===`watch`?n.trigger.cwd:e.sessions()[0]?.cwd??``),S=g(String(n?.trigger.type===`watch`?n.trigger.intervalSeconds:60),`number`),w=a([[`Continue after matches`,`repeat`],[`Stop after first match`,`once`]],n?.trigger.type===`watch`?n.trigger.mode:`repeat`);let r=_(`Probe script (0=match, 1=no match)`,u);r.classList.add(`col-span-2`),T.append(r,_(`Probe directory`,E),_(`Interval (seconds)`,S),_(`Mode`,w))}let D,O,k,j,N,P,F,I,L,R;if(h.value===`bash`){O=g(n?.action.type===`bash`?n.action.cwd:e.sessions()[0]?.cwd??``),D=t(n?.action.type===`bash`?n.action.script:``,6);let r=_(`Bash script`,D);r.classList.add(`col-span-2`),T.append(_(`Working directory`,O),l(`span`,``),r)}else if(h.value===`agent`){let r=e.sessions(),i=n?.action.type===`agent`?n.action:null,o=i?.session.mode===`reuse`?i.session.sessionId:``,s=A(r,o||null);k=a([[`Reuse session`,`reuse`],[`Fresh child per run`,`fresh`]],i?.session.mode===`reuse`?`reuse`:`fresh`),j=a(s,o||s[0]?.[1]||``);let c=i&&`cwd`in i.session?i.session.cwd??``:``;N=g(c||r[0]?.cwd||``),P=t(i?.prompt??``,6),F=a([[`Project default`,``],...v.map(e=>[b(e),e])],i?.launch?.thinking??``),I=g(i?.launch?.model?.provider??``),L=g(i?.launch?.model?.id??``);let l=_(`Session`,j),u=_(`Child directory`,N),d=[_(`Thinking`,F),_(`Model provider (optional)`,I),_(`Model id (optional)`,L)],f=()=>{let e=k?.value===`reuse`;l.classList.toggle(`hidden`,!e),u.classList.toggle(`hidden`,e);for(let t of d)t.classList.toggle(`hidden`,e)};k.onchange=f,f();let p=_(`Prompt`,P);p.classList.add(`col-span-2`),T.append(_(`Session policy`,k),l,u,...d,p)}else R=a(e.tasks().filter(e=>e.id!==n?.id&&!e.archived).map(e=>[e.name,e.id]),n?.action.type===`task`?n.action.taskId:``),T.append(_(`Target task`,R));i.onsubmit=t=>{t.preventDefault();let i=m.value===`manual`?{type:`manual`}:m.value===`cron`?{type:`cron`,expression:s.value,timezone:c.value}:{type:`watch`,script:u.value,cwd:E.value,intervalSeconds:Number(S.value),mode:w.value},a=h.value===`agent`&&k.value!==`reuse`?{...y(F.value)?{thinking:F.value}:{},...I.value.trim()&&L.value.trim()?{model:{provider:I.value.trim(),id:L.value.trim()}}:{}}:void 0,l=h.value===`bash`?{type:`bash`,cwd:O.value,script:D.value}:h.value===`agent`?{type:`agent`,prompt:P.value,session:k.value===`reuse`?{mode:`reuse`,sessionId:j.value}:{mode:`fresh`,cwd:N.value},...a?{launch:a}:{}}:{type:`task`,taskId:R.value},g=x.value===`origin`?{type:`origin`}:x.value===`session`?{type:`session`,sessionId:C.value}:{type:`none`},_={name:d.value,description:f.value,trigger:i,action:l,callback:g,timeoutSeconds:Number(p.value)};o.textContent=``,M(n?.id,_,r,o,e.onSaved)}};m.onchange=E,h.onchange=E,E();let D=c(`Cancel`);D.onclick=()=>r.close();let O=c(`Save`,!0);O.type=`submit`;let k=l(`footer`,`flex flex-none justify-end gap-2 border-t border-neutral-200 px-4 py-3`);k.append(o,D,O),i.append(s,u,k),r.append(i),r.addEventListener(`close`,()=>r.remove()),document.body.append(r),r.showModal(),d.focus()}async function M(e,t,n,r,i){let a=await d(e?`/api/tasks/${e}`:`/api/tasks`,t,e?`PATCH`:`POST`);if(!a.ok){r.textContent=(await a.json()).error??`Task save failed`;return}let o=await a.json(),s=`task`in o?o.task:o;n.close(),i(s.id)}function N(t,g,_,v,y,b,A){let M=[],N=[],P=null,F=`active`,I=`all`,L=``,R=`runs`,z={top:0},B=0,V=0,H=``,U=e(async()=>{if(P||!$.visible)return;let e=B,t=`${F}:${I}`,n=await x(`/api/tasks?state=${F}&kind=task`,`Failed to load tasks`);if(!$.visible||e!==B||t!==`${F}:${I}`)return;if(!n.ok)return H=``,K(n.error);let r=JSON.stringify(n.value);t+r!==H&&(H=t+r,M=n.value,I!==`all`&&(M=M.filter(e=>e.trigger.type===I)),X())}),W=e(async()=>{P&&$.visible&&await ae(P)});function G(){return P?W():U()}function K(e){t.querySelector(`[role=alert]`)?.remove();let n=l(`p`,`flex-none p-4 text-[13px] text-red-600`,e);n.setAttribute(`role`,`alert`),t.append(n)}async function q(){let e=P,t=await x(`/api/tasks?state=active`,`Failed to load tasks`);return!t.ok&&$.visible&&P===e&&K(t.error),t.ok?t.value:N}let J={sessions:g,tasks:()=>N,onSaved:e=>{Y(e),R=`definition`,A(e)}},ee=(e,t)=>i(...e,l(`div`,`ml-auto flex flex-wrap items-center gap-2 max-md:w-full`,...t));function Y(e){P=e,B++,R=`runs`,z.top=0}function te(){P=null,B++,X()}function ne(){!$.visible||P!==null||Promise.all([_(),q()]).then(([,e])=>{!$.visible||P!==null||(N=e,j(J))})}function X(){let e=[],n=(t,n,r,i)=>{let o=a(n,r);o.setAttribute(`aria-label`,t),o.dataset.active=String(r!==n[0]?.[1]),o.onchange=()=>{o.dataset.active=String(o.value!==n[0]?.[1]),i(o.value),V=0,G()},e.push(l(`label`,`filter-field`,l(`span`,``,t),o))},r=l(`input`,u);r.type=`search`,r.placeholder=`Search tasks`,r.setAttribute(`aria-label`,`Search tasks`),r.value=L,r.dataset.active=String(!!L),r.oninput=()=>{L=r.value,r.dataset.active=String(!!L),c()},e.push(l(`label`,`filter-field filter-search`,l(`span`,``,`Search`),r)),n(`Status`,[[`Current`,`active`],[`Archived`,`archived`]],F,e=>{F=e}),n(`Trigger`,[[`All triggers`,`all`],[`Manual`,`manual`],[`Scheduled`,`cron`],[`Watching`,`watch`]],I,e=>{I=e});let i=document.createElement(`table`);i.className=`w-full table-fixed text-left text-[12.5px]`,i.innerHTML=`<thead class="sticky top-0 bg-neutral-50 text-[10.5px] uppercase tracking-wide text-neutral-400 shadow-[inset_0_-1px_0_var(--color-neutral-200)]"><tr>
|
|
2
2
|
<th class="w-[42%] px-4 py-2 font-semibold md:w-[24%]">Name</th><th class="hidden w-[10%] px-2 py-2 font-semibold md:table-cell">Action</th>
|
|
3
3
|
<th class="hidden w-[23%] px-2 py-2 font-semibold md:table-cell">Trigger</th><th class="hidden w-[17%] px-2 py-2 font-semibold md:table-cell">Next</th>
|
|
4
4
|
<th class="px-2 py-2 font-semibold md:w-[14%]">Last result</th><th class="w-[6rem] px-2 py-2 font-semibold"></th></tr></thead>`;let o=document.createElement(`tbody`),c=()=>{let e=M.filter(e=>`${e.name} ${e.description??``}`.toLowerCase().includes(L.toLowerCase()));o.replaceChildren(...e.map(re)),d.classList.toggle(`hidden`,e.length>0)};i.append(o);let d=l(`div`,`p-4`,s(`No matching tasks.`)),f=l(`div`,`automation-list min-h-0 flex-1 overflow-auto`,i,d);c(),f.onscroll=()=>{V=f.scrollTop},t.replaceChildren(l(`div`,`automation-filters task-filters`,...e),f),f.scrollTop=V}function re(e){let t=document.createElement(`tr`);t.className=`cursor-pointer border-b border-neutral-100 transition-colors hover:bg-neutral-50`,t.onclick=()=>A(e.id);let n=c(e.name);n.className=`min-w-0 cursor-pointer truncate text-left font-medium text-neutral-800`,n.title=e.name,t.append(l(`td`,`py-2.5 pl-4 pr-2`,l(`div`,`flex flex-wrap items-center gap-x-2 gap-y-1`,n,w(e),...ie(e)),l(`div`,`truncate text-[11px] text-neutral-400`,e.description||``),l(`div`,`truncate text-[11px] text-neutral-400 md:hidden`,k(e))));for(let n of[O(e),k(e),T(e.nextRunAt)]){let e=l(`td`,`hidden truncate px-2 py-2.5 text-neutral-600 md:table-cell`,n);e.title=n,t.append(e)}t.append(l(`td`,`px-2 py-2.5`,e.lastRun?l(`div`,`flex`,D(e.lastRun)):l(`div`,`text-neutral-400`,`–`),l(`div`,`mt-0.5 font-mono text-[11px] text-neutral-400`,e.lastRun?C(e.lastRun):``)));let r=c(`Run now`);return r.disabled=e.archived,r.onclick=t=>{t.stopPropagation(),Z(e.id)},t.append(l(`td`,`px-2 py-1 text-right`,r)),t}function ie(e){if(!e.createdBySessionId)return[];let t=n(`agent`,`bg-violet-50 text-violet-700 ring-violet-200`);return t.title=`Created by session ${e.createdBySessionId}`,[t]}async function ae(e){let n=++B,a=t.querySelector(`[data-task-detail]`),[o,s]=await Promise.all([x(`/api/tasks/${e}`,`Failed to load task`),x(`/api/tasks/${e}/runs`,`Failed to load the task's runs`)]);if(!$.visible||n!==B||P!==e)return;if(!o.ok)return K(o.error);if(!s.ok)return K(s.error);let u=o.value,d=s.value,p=c(`Tasks`);p.className=`cursor-pointer text-neutral-500 hover:text-neutral-800 hover:underline`,p.onclick=()=>A();let h=l(`span`,`flex min-w-0 items-center gap-2`,p,f(m,`h-3.5 w-3.5 text-neutral-400`),l(`span`,`truncate font-medium`,u.name),w(u)),g=c(`Run now`,!0);g.disabled=u.archived,g.onclick=()=>void Z(u.id);let y=c(u.enabled?`Pause schedule`:`Resume schedule`);y.disabled=u.archived||u.action.type===`system`||u.trigger.type===`manual`,y.onclick=()=>void Q(`/api/tasks/${u.id}/${u.enabled?`pause`:`resume`}`);let C=c(`Edit`);C.disabled=u.archived||u.action.type===`system`,C.onclick=()=>{!$.visible||P!==u.id||Promise.all([_(),q()]).then(([,e])=>{!$.visible||P!==u.id||(N=e,j(J,u))})};let T=c(`Archive`);T.disabled=u.archived||u.action.type===`system`,T.onclick=()=>void Q(`/api/tasks/${u.id}/archive`);let D=i(),O=l(`div`,`automation-list min-h-0 flex-1 overflow-auto`);O.dataset.taskDetail=e;let k=c(`All runs`);k.onclick=()=>b({taskId:u.id});let M=()=>{D.replaceChildren(r([[`Recent runs (${d.length})`,`runs`],[`Definition`,`definition`]],R,e=>{R=e,M()}),l(`span`,`ml-auto`,k)),R===`runs`?S(O,d,e=>b({},e),z):(O.onscroll=null,O.replaceChildren(E(u,v)))},F=a?.scrollTop??0;t.replaceChildren(ee([h],[g,...u.trigger.type===`manual`?[]:[y],C,T]),D,O),M(),O.scrollTop=F}async function Z(e){try{let t=await d(`/api/tasks/${e}/run`,{sourceSessionId:y()});if(!t.ok)return K(await p(t,`Failed to run task`));b({},(await t.json()).runId)}catch(e){K(`Failed to run task: ${String(e)}`)}}async function Q(e){let t=await h(e,`POST`,`Task update failed`);if(t)return K(t);await G()}let $=o(t,e=>{e&&e!==P&&Y(e),e||te(),t.childElementCount||X(),G()});return Object.assign($,{create:ne,refresh(e){$.visible&&(!P||!e||P===e)&&G()}})}export{N as createTasksView};
|
|
Binary file
|
|
Binary file
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
which style.css pays for with the safe-area inset. -->
|
|
39
39
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
40
40
|
<title>Pier</title>
|
|
41
|
-
<script type="module" crossorigin src="/app/assets/index-
|
|
41
|
+
<script type="module" crossorigin src="/app/assets/index-BQo-haPN.js"></script>
|
|
42
42
|
<link rel="stylesheet" crossorigin href="/app/assets/index-DiHj0w1i.css">
|
|
43
43
|
</head>
|
|
44
44
|
<!-- The document never scrolls: this is a fixed-viewport workbench, and every
|
|
Binary file
|
|
Binary file
|
package/dist/web/server.js
CHANGED
|
@@ -554,8 +554,11 @@ export function createServer({ factory, router, hub, sessions: state, config, pa
|
|
|
554
554
|
const prefix = tabPrefix(process.env.PIER_TITLE, hostname().split(".")[0] ?? "");
|
|
555
555
|
let shell = null;
|
|
556
556
|
const serveShell = async (c, next) => {
|
|
557
|
-
// A cached index must not name bundles a release has replaced
|
|
558
|
-
|
|
557
|
+
// A cached index must not name bundles a release has replaced: the build
|
|
558
|
+
// replaces `public/assets`, so an old shell's hashes are 404s and the page
|
|
559
|
+
// renders unstyled. `no-store`, not `no-cache` — Safari restores a
|
|
560
|
+
// no-cache document from its cache without revalidating it.
|
|
561
|
+
c.header("cache-control", "private, no-store");
|
|
559
562
|
if (shell === null) {
|
|
560
563
|
try {
|
|
561
564
|
shell = withTabPrefix(await readFile(join(bundle, "index.html"), "utf8"), prefix);
|
|
@@ -600,9 +603,15 @@ export function createServer({ factory, router, hub, sessions: state, config, pa
|
|
|
600
603
|
});
|
|
601
604
|
// Hashed bundles never change under their name; without this the auth
|
|
602
605
|
// layer's bare `private` costs a revalidation round trip per bundle per open.
|
|
606
|
+
// Never on a miss: a build replaces `public/assets`, and a year-long 404 is a
|
|
607
|
+
// stale shell's blank page that no longer even reaches the server.
|
|
603
608
|
app.get("/app/assets/*", async (c, next) => {
|
|
604
|
-
c.header("cache-control", "private, max-age=31536000, immutable");
|
|
605
609
|
await next();
|
|
610
|
+
if (c.res.status === 200 || c.res.status === 206) {
|
|
611
|
+
c.header("cache-control", "private, max-age=31536000, immutable");
|
|
612
|
+
}
|
|
613
|
+
else
|
|
614
|
+
c.header("cache-control", "private, no-store");
|
|
606
615
|
});
|
|
607
616
|
// The build writes `.br`/`.gz` siblings (vite.config.ts). serveStatic sets
|
|
608
617
|
// Vary only when it selects one; identity must carry it too, or a cache can
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timqi/pier",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "A self-hosted workspace for coding agents: web workbench and IM channels in front of Pi sessions",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": "github:timqi/pier",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"vitest": "^4.1.11"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
46
|
+
"@earendil-works/pi-coding-agent": "^0.87.1",
|
|
47
47
|
"@hono/node-server": "^2.1.1",
|
|
48
48
|
"@larksuiteoapi/node-sdk": "^1.73.0",
|
|
49
49
|
"croner": "^10.0.1",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|