pi-web 0.3.4 → 0.3.5

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.
@@ -44,6 +44,6 @@ Error generating stack: `+o.message+`
44
44
  transition-transform duration-200
45
45
  ${D?"translate-x-0":"-translate-x-full"}
46
46
  md:translate-x-0
47
- `,children:[y.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-pi-border-muted",children:[y.jsxs("h1",{className:"text-base font-semibold text-pi-accent",children:["pi-web ",y.jsxs("span",{className:"text-pi-dim font-normal text-xs",children:["v","0.3.3"]})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("button",{onClick:Dc,title:"New session",className:"bg-pi-accent text-white p-1.5 rounded-lg hover:opacity-85 cursor-pointer",children:y.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"13"}),y.jsx("line",{x1:"3",y1:"8",x2:"13",y2:"8"})]})}),y.jsx("button",{onClick:()=>ue(!1),className:"md:hidden text-pi-muted p-1.5 cursor-pointer",children:y.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),y.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]})]}),y.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:Vc.map(m=>y.jsx(Cp,{folder:m,expanded:k.has(m.cwd),activeSessionFile:n,onToggle:()=>Ic(m.cwd),onNewSession:()=>{S(T=>new Set([...T,m.cwd])),ou(m.cwd),ue(!1)},onSelectSession:T=>{Fc(T),ue(!1)},onDeleteSession:Bc},m.cwd))})]}),y.jsxs("main",{className:"flex-1 flex flex-col min-h-0",children:[y.jsxs("div",{className:"md:hidden flex items-center gap-2 px-3 py-2 border-b border-pi-border-muted bg-pi-card-bg",children:[y.jsx("button",{onClick:()=>ue(!0),className:"text-pi-muted p-1 cursor-pointer",children:y.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"2",y1:"4",x2:"16",y2:"4"}),y.jsx("line",{x1:"2",y1:"9",x2:"16",y2:"9"}),y.jsx("line",{x1:"2",y1:"14",x2:"16",y2:"14"})]})}),y.jsx("span",{className:"text-pi-muted truncate",children:n?n.split("/").pop():"No session selected"})]}),y.jsx("div",{ref:Ae,className:"flex-1 overflow-y-auto px-4 py-4 md:px-6",children:l.length===0?y.jsx("div",{className:"flex items-center justify-center h-full text-pi-muted text-base",children:"Start a new session or select one from the list."}):l.filter(m=>m.role==="user"||m.parts.some(T=>(T.content??"").trim()||T.type==="toolCall")).map(m=>y.jsx(_p,{msg:m},m.id))}),y.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 border-t border-pi-border-muted bg-pi-card-bg text-xs text-pi-muted flex-wrap",children:[y.jsxs("span",{className:"flex items-center gap-1.5",children:[y.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${Hc}`}),s?"Streaming":i?"Connected":"Disconnected"]}),$.length>0&&y.jsxs("span",{className:"flex items-center gap-1.5",children:[y.jsx("select",{value:g,onChange:m=>Wc(m.target.value),disabled:s,className:"text-xs font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 max-w-[120px]",children:st.map(m=>y.jsx("option",{value:m,children:m},m))}),y.jsx("select",{value:(a==null?void 0:a.provider)===g?a.id:"",onChange:m=>Ac(m.target.value),disabled:s,className:"text-xs font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 max-w-[160px]",children:Rn.map(m=>y.jsx("option",{value:m.id,children:m.name},m.id))})]}),$.length===0&&a&&y.jsx("span",{children:a.name}),P&&y.jsxs("span",{className:"flex items-center gap-2 text-pi-dim ml-auto flex-wrap",children:[P.tokens.input>0&&y.jsxs("span",{children:["↑",Bn(P.tokens.input)]}),P.tokens.output>0&&y.jsxs("span",{children:["↓",Bn(P.tokens.output)]}),P.tokens.cacheRead>0&&y.jsxs("span",{children:["R",Bn(P.tokens.cacheRead)]}),P.tokens.cacheWrite>0&&y.jsxs("span",{children:["W",Bn(P.tokens.cacheWrite)]}),P.cost>0&&y.jsxs("span",{children:["$",P.cost.toFixed(3)]}),(a==null?void 0:a.contextWindow)&&et&&(()=>{const m=et/a.contextWindow*100,T=m>90?"text-pi-error":m>70?"text-pi-warning":"";return y.jsxs("span",{className:T,children:[m.toFixed(1),"%/",Bn(a.contextWindow)]})})()]}),s&&y.jsxs("span",{children:["responding",j.length>0?` · ${j.length} queued`:""]})]}),y.jsx("div",{className:"px-4 pb-4 pt-3 md:px-6 border-t border-pi-border-muted bg-pi-card-bg",children:y.jsxs("div",{className:"flex gap-2 items-center",children:[y.jsx("textarea",{ref:Be,rows:1,placeholder:p?"Send a message...":"Select a session to start",disabled:!p,value:v,onChange:m=>h(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),iu())},className:"flex-1 bg-white border border-pi-border-muted rounded-lg px-3 py-2.5 text-base md:text-sm font-mono resize-none min-h-[42px] max-h-[200px] outline-none focus:border-pi-accent disabled:opacity-50 disabled:cursor-default"}),y.jsxs("div",{className:"flex flex-row gap-1 flex-shrink-0",children:[y.jsxs("button",{onClick:iu,disabled:!i||!p,title:s?"Queue message":"Send",className:"relative bg-pi-accent text-white p-2 rounded-lg cursor-pointer disabled:opacity-40 disabled:cursor-default hover:opacity-85",children:[y.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("line",{x1:"2",y1:"9",x2:"16",y2:"9"}),y.jsx("polyline",{points:"10,3 16,9 10,15"})]}),j.length>0&&y.jsx("span",{className:"absolute -top-1.5 -right-1.5 bg-pi-warning text-white text-[10px] w-4 h-4 rounded-full flex items-center justify-center leading-none",children:j.length})]}),y.jsx("button",{onClick:Uc,disabled:!s||!p,title:"Stop",className:"bg-pi-error text-white p-2 rounded-lg cursor-pointer disabled:opacity-40 disabled:cursor-default hover:opacity-85",children:y.jsx("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"currentColor",children:y.jsx("rect",{x:"4",y:"4",width:"10",height:"10",rx:"1.5"})})})]})]})})]})]})}function _p({msg:e}){const t=e.role==="user";return y.jsxs("div",{className:"mb-4 min-w-0",children:[y.jsxs("div",{className:"flex items-center gap-2 mb-1 min-w-0",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-pi-muted shrink-0",children:t?"You":"Assistant"}),!t&&(e.model||e.provider)&&y.jsx("span",{className:"text-[10px] text-pi-dim truncate",children:[e.provider,e.model].filter(Boolean).join(" / ")}),e.timestamp!=null&&y.jsx("span",{className:"text-[10px] text-pi-dim ml-auto shrink-0",children:Tp(e.timestamp)})]}),y.jsx("div",{className:`rounded-lg px-4 py-3 min-w-0 overflow-hidden ${t?"bg-pi-user-bg":"bg-pi-card-bg border border-pi-border-muted"}`,children:y.jsx("div",{className:"text-xs md:text-sm leading-relaxed break-words min-w-0",children:e.parts.map((n,r)=>y.jsx(Np,{part:n},`${e.id}-${r}`))})})]})}function Cp({folder:e,expanded:t,activeSessionFile:n,onToggle:r,onNewSession:l,onSelectSession:o,onDeleteSession:i}){const u=e.sessions.some(s=>s.file===n);return y.jsxs("div",{className:"mb-1",children:[y.jsxs("div",{className:"flex items-center gap-1 rounded-lg",children:[y.jsxs("button",{onClick:r,className:`flex-1 flex items-center gap-1.5 text-left px-2 py-1.5 rounded-lg text-xs font-semibold hover:bg-pi-user-bg cursor-pointer min-w-0 ${u?"text-pi-accent":"text-gray-700"}`,children:[y.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:`text-pi-muted transition-transform duration-150 flex-shrink-0 ${t?"rotate-90":""}`,children:y.jsx("polyline",{points:"3,2 9,6 3,10"})}),y.jsx("span",{className:"flex-1 truncate min-w-0",children:e.label}),y.jsx("span",{className:"text-[11px] text-pi-dim font-normal flex-shrink-0",children:e.sessions.length})]}),y.jsx("button",{onClick:l,title:"New session here",className:"text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg p-1.5 rounded-lg cursor-pointer flex-shrink-0",children:y.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"6.5",y1:"1.5",x2:"6.5",y2:"11.5"}),y.jsx("line",{x1:"1.5",y1:"6.5",x2:"11.5",y2:"6.5"})]})})]}),t&&y.jsx("div",{className:"pl-3 mt-0.5",children:e.sessions.map(s=>{const c=s.file===n,v=s.firstPrompt||s.id.slice(0,8),h=s.timestamp?new Date(s.timestamp).toLocaleString():"";return y.jsxs("div",{onClick:()=>o(s.file),className:`group relative px-2.5 py-2 rounded-lg cursor-pointer mb-0.5 border ${c?"border-pi-accent bg-pi-user-bg":"border-transparent hover:bg-pi-user-bg"}`,children:[y.jsx("div",{className:"text-xs truncate pr-5",children:v}),y.jsxs("div",{className:"text-[11px] text-pi-dim mt-0.5",children:[s.messageCount," msgs · ",h]}),y.jsx("button",{onClick:p=>{p.stopPropagation(),i(s.file)},title:"Delete session",className:"absolute top-1/2 right-1.5 -translate-y-1/2 hidden group-hover:flex active:flex items-center justify-center w-5 h-5 rounded text-pi-muted bg-pi-user-bg hover:text-pi-error hover:bg-pi-tool-error cursor-pointer",children:y.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"1.5",y1:"1.5",x2:"8.5",y2:"8.5"}),y.jsx("line",{x1:"8.5",y1:"1.5",x2:"1.5",y2:"8.5"})]})})]},s.file)})})]})}function Np({part:e}){return e.type==="text"?y.jsx("div",{dangerouslySetInnerHTML:{__html:jp(e.content||"")}}):e.type==="thinking"?y.jsx("div",{className:"text-pi-muted italic border-l-2 border-pi-border-muted pl-3 my-1.5 text-xs",children:e.content}):e.type==="tool"?y.jsx(Pp,{part:e}):null}function Pp({part:e}){const[t,n]=O.useState(!1),r=e.args?typeof e.args=="string"?e.args:JSON.stringify(e.args,null,2):"",l=e.content||"",o=r||l;return y.jsxs("div",{className:"bg-pi-tool-success border border-pi-border-muted rounded-lg my-1.5 text-xs overflow-hidden",children:[y.jsxs("button",{onClick:()=>o&&n(i=>!i),className:`w-full flex items-center gap-2 px-3 py-2 text-left ${o?"cursor-pointer hover:brightness-95":"cursor-default"}`,children:[y.jsx("span",{className:"text-pi-success font-semibold",children:e.name}),!t&&r&&y.jsxs("span",{className:"text-pi-muted truncate flex-1",children:[r.slice(0,80),r.length>80?"…":""]}),o&&y.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:`ml-auto text-pi-dim flex-shrink-0 transition-transform duration-150 ${t?"rotate-180":""}`,children:y.jsx("polyline",{points:"1,3 5,7 9,3"})})]}),t&&y.jsxs("div",{className:"border-t border-pi-border-muted",children:[r&&y.jsxs("div",{className:"px-3 py-2 border-b border-pi-border-muted/40",children:[y.jsx("div",{className:"text-[10px] font-semibold text-pi-muted uppercase mb-1",children:"Input"}),y.jsx("pre",{className:"whitespace-pre-wrap break-all text-pi-muted font-mono",children:r})]}),l&&y.jsxs("div",{className:"px-3 py-2",children:[y.jsx("div",{className:"text-[10px] font-semibold text-pi-muted uppercase mb-1",children:"Output"}),y.jsx("pre",{className:"whitespace-pre-wrap break-all text-pi-tool-output max-h-48 overflow-y-auto font-mono",children:l})]})]})]})}function jp(e){const t=e.split(`
47
+ `,children:[y.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-pi-border-muted",children:[y.jsxs("h1",{className:"text-base font-semibold text-pi-accent",children:["pi-web ",y.jsxs("span",{className:"text-pi-dim font-normal text-xs",children:["v","0.3.4"]})]}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("button",{onClick:Dc,title:"New session",className:"bg-pi-accent text-white p-1.5 rounded-lg hover:opacity-85 cursor-pointer",children:y.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"13"}),y.jsx("line",{x1:"3",y1:"8",x2:"13",y2:"8"})]})}),y.jsx("button",{onClick:()=>ue(!1),className:"md:hidden text-pi-muted p-1.5 cursor-pointer",children:y.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),y.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]})]}),y.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:Vc.map(m=>y.jsx(Cp,{folder:m,expanded:k.has(m.cwd),activeSessionFile:n,onToggle:()=>Ic(m.cwd),onNewSession:()=>{S(T=>new Set([...T,m.cwd])),ou(m.cwd),ue(!1)},onSelectSession:T=>{Fc(T),ue(!1)},onDeleteSession:Bc},m.cwd))})]}),y.jsxs("main",{className:"flex-1 flex flex-col min-h-0",children:[y.jsxs("div",{className:"md:hidden flex items-center gap-2 px-3 py-2 border-b border-pi-border-muted bg-pi-card-bg",children:[y.jsx("button",{onClick:()=>ue(!0),className:"text-pi-muted p-1 cursor-pointer",children:y.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"2",y1:"4",x2:"16",y2:"4"}),y.jsx("line",{x1:"2",y1:"9",x2:"16",y2:"9"}),y.jsx("line",{x1:"2",y1:"14",x2:"16",y2:"14"})]})}),y.jsx("span",{className:"text-pi-muted truncate",children:n?n.split("/").pop():"No session selected"})]}),y.jsx("div",{ref:Ae,className:"flex-1 overflow-y-auto px-4 py-4 md:px-6",children:l.length===0?y.jsx("div",{className:"flex items-center justify-center h-full text-pi-muted text-base",children:"Start a new session or select one from the list."}):l.filter(m=>m.role==="user"||m.parts.some(T=>(T.content??"").trim()||T.type==="toolCall")).map(m=>y.jsx(_p,{msg:m},m.id))}),y.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 border-t border-pi-border-muted bg-pi-card-bg text-xs text-pi-muted flex-wrap",children:[y.jsxs("span",{className:"flex items-center gap-1.5",children:[y.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${Hc}`}),s?"Streaming":i?"Connected":"Disconnected"]}),$.length>0&&y.jsxs("span",{className:"flex items-center gap-1.5",children:[y.jsx("select",{value:g,onChange:m=>Wc(m.target.value),disabled:s,className:"text-xs font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 max-w-[120px]",children:st.map(m=>y.jsx("option",{value:m,children:m},m))}),y.jsx("select",{value:(a==null?void 0:a.provider)===g?a.id:"",onChange:m=>Ac(m.target.value),disabled:s,className:"text-xs font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 max-w-[160px]",children:Rn.map(m=>y.jsx("option",{value:m.id,children:m.name},m.id))})]}),$.length===0&&a&&y.jsx("span",{children:a.name}),P&&y.jsxs("span",{className:"flex items-center gap-2 text-pi-dim ml-auto flex-wrap",children:[P.tokens.input>0&&y.jsxs("span",{children:["↑",Bn(P.tokens.input)]}),P.tokens.output>0&&y.jsxs("span",{children:["↓",Bn(P.tokens.output)]}),P.tokens.cacheRead>0&&y.jsxs("span",{children:["R",Bn(P.tokens.cacheRead)]}),P.tokens.cacheWrite>0&&y.jsxs("span",{children:["W",Bn(P.tokens.cacheWrite)]}),P.cost>0&&y.jsxs("span",{children:["$",P.cost.toFixed(3)]}),(a==null?void 0:a.contextWindow)&&et&&(()=>{const m=et/a.contextWindow*100,T=m>90?"text-pi-error":m>70?"text-pi-warning":"";return y.jsxs("span",{className:T,children:[m.toFixed(1),"%/",Bn(a.contextWindow)]})})()]}),s&&y.jsxs("span",{children:["responding",j.length>0?` · ${j.length} queued`:""]})]}),y.jsx("div",{className:"px-4 pb-4 pt-3 md:px-6 border-t border-pi-border-muted bg-pi-card-bg",children:y.jsxs("div",{className:"flex gap-2 items-center",children:[y.jsx("textarea",{ref:Be,rows:1,placeholder:p?"Send a message...":"Select a session to start",disabled:!p,value:v,onChange:m=>h(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),iu())},className:"flex-1 bg-white border border-pi-border-muted rounded-lg px-3 py-2.5 text-base md:text-sm font-mono resize-none min-h-[42px] max-h-[200px] outline-none focus:border-pi-accent disabled:opacity-50 disabled:cursor-default"}),y.jsxs("div",{className:"flex flex-row gap-1 flex-shrink-0",children:[y.jsxs("button",{onClick:iu,disabled:!i||!p,title:s?"Queue message":"Send",className:"relative bg-pi-accent text-white p-2 rounded-lg cursor-pointer disabled:opacity-40 disabled:cursor-default hover:opacity-85",children:[y.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[y.jsx("line",{x1:"2",y1:"9",x2:"16",y2:"9"}),y.jsx("polyline",{points:"10,3 16,9 10,15"})]}),j.length>0&&y.jsx("span",{className:"absolute -top-1.5 -right-1.5 bg-pi-warning text-white text-[10px] w-4 h-4 rounded-full flex items-center justify-center leading-none",children:j.length})]}),y.jsx("button",{onClick:Uc,disabled:!s||!p,title:"Stop",className:"bg-pi-error text-white p-2 rounded-lg cursor-pointer disabled:opacity-40 disabled:cursor-default hover:opacity-85",children:y.jsx("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"currentColor",children:y.jsx("rect",{x:"4",y:"4",width:"10",height:"10",rx:"1.5"})})})]})]})})]})]})}function _p({msg:e}){const t=e.role==="user";return y.jsxs("div",{className:"mb-4 min-w-0",children:[y.jsxs("div",{className:"flex items-center gap-2 mb-1 min-w-0",children:[y.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-pi-muted shrink-0",children:t?"You":"Assistant"}),!t&&(e.model||e.provider)&&y.jsx("span",{className:"text-[10px] text-pi-dim truncate",children:[e.provider,e.model].filter(Boolean).join(" / ")}),e.timestamp!=null&&y.jsx("span",{className:"text-[10px] text-pi-dim ml-auto shrink-0",children:Tp(e.timestamp)})]}),y.jsx("div",{className:`rounded-lg px-4 py-3 min-w-0 overflow-hidden ${t?"bg-pi-user-bg":"bg-pi-card-bg border border-pi-border-muted"}`,children:y.jsx("div",{className:"text-xs md:text-sm leading-relaxed break-words min-w-0",children:e.parts.map((n,r)=>y.jsx(Np,{part:n},`${e.id}-${r}`))})})]})}function Cp({folder:e,expanded:t,activeSessionFile:n,onToggle:r,onNewSession:l,onSelectSession:o,onDeleteSession:i}){const u=e.sessions.some(s=>s.file===n);return y.jsxs("div",{className:"mb-1",children:[y.jsxs("div",{className:"flex items-center gap-1 rounded-lg",children:[y.jsxs("button",{onClick:r,className:`flex-1 flex items-center gap-1.5 text-left px-2 py-1.5 rounded-lg text-xs font-semibold hover:bg-pi-user-bg cursor-pointer min-w-0 ${u?"text-pi-accent":"text-gray-700"}`,children:[y.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:`text-pi-muted transition-transform duration-150 flex-shrink-0 ${t?"rotate-90":""}`,children:y.jsx("polyline",{points:"3,2 9,6 3,10"})}),y.jsx("span",{className:"flex-1 truncate min-w-0",children:e.label}),y.jsx("span",{className:"text-[11px] text-pi-dim font-normal flex-shrink-0",children:e.sessions.length})]}),y.jsx("button",{onClick:l,title:"New session here",className:"text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg p-1.5 rounded-lg cursor-pointer flex-shrink-0",children:y.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"6.5",y1:"1.5",x2:"6.5",y2:"11.5"}),y.jsx("line",{x1:"1.5",y1:"6.5",x2:"11.5",y2:"6.5"})]})})]}),t&&y.jsx("div",{className:"pl-3 mt-0.5",children:e.sessions.map(s=>{const c=s.file===n,v=s.firstPrompt||s.id.slice(0,8),h=s.timestamp?new Date(s.timestamp).toLocaleString():"";return y.jsxs("div",{onClick:()=>o(s.file),className:`group relative px-2.5 py-2 rounded-lg cursor-pointer mb-0.5 border ${c?"border-pi-accent bg-pi-user-bg":"border-transparent hover:bg-pi-user-bg"}`,children:[y.jsx("div",{className:"text-xs truncate pr-5",children:v}),y.jsxs("div",{className:"text-[11px] text-pi-dim mt-0.5",children:[s.messageCount," msgs · ",h]}),y.jsx("button",{onClick:p=>{p.stopPropagation(),i(s.file)},title:"Delete session",className:"absolute top-1/2 right-1.5 -translate-y-1/2 hidden group-hover:flex active:flex items-center justify-center w-5 h-5 rounded text-pi-muted bg-pi-user-bg hover:text-pi-error hover:bg-pi-tool-error cursor-pointer",children:y.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[y.jsx("line",{x1:"1.5",y1:"1.5",x2:"8.5",y2:"8.5"}),y.jsx("line",{x1:"8.5",y1:"1.5",x2:"1.5",y2:"8.5"})]})})]},s.file)})})]})}function Np({part:e}){return e.type==="text"?y.jsx("div",{dangerouslySetInnerHTML:{__html:jp(e.content||"")}}):e.type==="thinking"?y.jsx("div",{className:"text-pi-muted italic border-l-2 border-pi-border-muted pl-3 my-1.5 text-xs",children:e.content}):e.type==="tool"?y.jsx(Pp,{part:e}):null}function Pp({part:e}){const[t,n]=O.useState(!1),r=e.args?typeof e.args=="string"?e.args:JSON.stringify(e.args,null,2):"",l=e.content||"",o=r||l;return y.jsxs("div",{className:"bg-pi-tool-success border border-pi-border-muted rounded-lg my-1.5 text-xs overflow-hidden",children:[y.jsxs("button",{onClick:()=>o&&n(i=>!i),className:`w-full flex items-center gap-2 px-3 py-2 text-left ${o?"cursor-pointer hover:brightness-95":"cursor-default"}`,children:[y.jsx("span",{className:"text-pi-success font-semibold",children:e.name}),!t&&r&&y.jsxs("span",{className:"text-pi-muted truncate flex-1",children:[r.slice(0,80),r.length>80?"…":""]}),o&&y.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:`ml-auto text-pi-dim flex-shrink-0 transition-transform duration-150 ${t?"rotate-180":""}`,children:y.jsx("polyline",{points:"1,3 5,7 9,3"})})]}),t&&y.jsxs("div",{className:"border-t border-pi-border-muted",children:[r&&y.jsxs("div",{className:"px-3 py-2 border-b border-pi-border-muted/40",children:[y.jsx("div",{className:"text-[10px] font-semibold text-pi-muted uppercase mb-1",children:"Input"}),y.jsx("pre",{className:"whitespace-pre-wrap break-all text-pi-muted font-mono",children:r})]}),l&&y.jsxs("div",{className:"px-3 py-2",children:[y.jsx("div",{className:"text-[10px] font-semibold text-pi-muted uppercase mb-1",children:"Output"}),y.jsx("pre",{className:"whitespace-pre-wrap break-all text-pi-tool-output max-h-48 overflow-y-auto font-mono",children:l})]})]})]})}function jp(e){const t=e.split(`
48
48
  `),n=[];let r=0;for(;r<t.length;){const l=t[r];if(/^```/.test(l)){const i=l.slice(3).trim(),u=[];for(r++;r<t.length&&!/^```/.test(t[r]);)u.push(ai(t[r])),r++;n.push(`<pre class="bg-pi-page-bg border border-pi-border-muted rounded-lg p-3 overflow-x-auto my-2 text-xs font-mono text-pi-md-code-block"><code${i?` class="language-${ai(i)}"`:""}>${u.join(`
49
49
  `)}</code></pre>`),r++;continue}if(/^\|/.test(l)&&r+1<t.length&&/^\|[\s\-:|]+\|/.test(t[r+1])){const i=gs(t[r]),u=zp(t[r+1]);r+=2;const s=[];for(;r<t.length&&/^\|/.test(t[r]);)s.push(gs(t[r])),r++;const c=i.map((h,p)=>`<th class="border border-pi-border-muted px-3 py-1.5 bg-pi-page-bg font-semibold text-left" style="${ws(u[p])}">${Br(h)}</th>`).join(""),v=s.map(h=>`<tr>${h.map((p,x)=>`<td class="border border-pi-border-muted px-3 py-1.5" style="${ws(u[x])}">${Br(p)}</td>`).join("")}</tr>`).join("");n.push(`<div class="overflow-x-auto my-2"><table class="border-collapse text-xs w-full"><thead><tr>${c}</tr></thead><tbody>${v}</tbody></table></div>`);continue}const o=l.match(/^(#{1,6})\s+(.*)/);if(o){const i=o[1].length,u=["text-lg","text-base","text-sm","text-sm","text-xs","text-xs"];n.push(`<h${i} class="font-semibold ${u[i-1]} mt-3 mb-1 text-pi-md-heading">${Br(o[2])}</h${i}>`),r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(l.trim())){n.push('<hr class="border-t border-pi-border-muted my-3">'),r++;continue}if(l.trim()===""){n.push("<br>"),r++;continue}n.push(`<span>${Br(l)}</span><br>`),r++}return n.join("")}function gs(e){return e.replace(/^\||\|$/g,"").split("|").map(t=>t.trim())}function zp(e){return e.replace(/^\||\|$/g,"").split("|").map(t=>(t=t.trim(),t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"))}function ws(e){return`text-align:${e}`}function Br(e){let t=ai(e);return t=t.replace(/`([^`]+)`/g,'<code class="bg-pi-page-bg text-pi-md-code px-1 py-0.5 rounded text-xs font-mono">$1</code>'),t=t.replace(/\*\*\*([^*]+)\*\*\*/g,"<strong><em>$1</em></strong>"),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*([^*\n]+)\*/g,"<em>$1</em>"),t=t.replace(/~~([^~]+)~~/g,"<del class='opacity-60'>$1</del>"),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener" class="text-pi-md-link underline">$1</a>'),t}function ai(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Tp(e){return new Date(e).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}function Lp(e){if(!e)return 0;if(typeof e.totalTokens=="number"&&Number.isFinite(e.totalTokens))return e.totalTokens;const t=typeof e.input=="number"&&Number.isFinite(e.input)?e.input:0,n=typeof e.output=="number"&&Number.isFinite(e.output)?e.output:0,r=typeof e.cacheRead=="number"&&Number.isFinite(e.cacheRead)?e.cacheRead:0,l=typeof e.cacheWrite=="number"&&Number.isFinite(e.cacheWrite)?e.cacheWrite:0;return t+n+r+l}function xs(e){let t=0;for(const n of e.parts){if(n.type==="text"||n.type==="thinking"){t+=(n.content??"").length;continue}if(n.type==="tool"&&(t+=(n.name??"").length,t+=(n.content??"").length,n.args!=null))try{t+=JSON.stringify(n.args).length}catch{}}return Math.ceil(t/4)}function Rp(e){for(let n=e.length-1;n>=0;n--){const r=e[n];if(r.role!=="assistant")continue;const l=Lp(r.usage);if(l<=0)continue;let o=0;for(let i=n+1;i<e.length;i++)o+=xs(e[i]);return l+o}const t=e.reduce((n,r)=>n+xs(r),0);return t>0?t:null}function Bn(e){return e<1e3?String(e):e<1e4?`${(e/1e3).toFixed(1)}k`:e<1e6?`${Math.round(e/1e3)}k`:e<1e7?`${(e/1e6).toFixed(1)}M`:`${Math.round(e/1e6)}M`}vo.createRoot(document.getElementById("root")).render(y.jsx(sf.StrictMode,{children:y.jsx(Ep,{})}));
package/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>pi-web</title>
7
- <script type="module" crossorigin src="/assets/index-B93GSMoB.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-2miaZD9I.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-Cdcg6pFp.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "description": "Web UI for the pi coding agent",
6
6
  "repository": {