pi-web 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,6 @@ ${JSON.stringify(s,null,2)}`}catch{b+=`
42
42
 
43
43
  [unable to serialise args]`}return f&&(b+=`
44
44
 
45
- ${f}`),b}function yp(){const i=ah(),r=Bl(),[s,f]=E.useState([]),[d,m]=E.useState([]),[b,M]=E.useState(!1),[S,y]=E.useState(!1),[C,R]=E.useState(""),[L,V]=E.useState(!1),[q,K]=E.useState(op),[Y,P]=E.useState(null),[ct,tt]=E.useState([]),[_t,Tt]=E.useState(!1),[jt,nt]=E.useState(null),[gt,ne]=E.useState([]),[Ut,de]=E.useState(null),[qt,me]=E.useState("off"),[ae,Lt]=E.useState(""),[N,Q]=E.useState([]),[W,bt]=E.useState(null),[Rt,g]=E.useState(!1),j=E.useMemo(()=>r.pathname.split("/").filter(Boolean),[r.pathname]),G=j[0],Z=j[1],at=j.length>2,X=E.useMemo(()=>Lm(G),[G]),lt=E.useMemo(()=>Z==null||Z===zr?null:Lm(Z),[Z]),Qt=j.length===0,Mt=j.length===1,Ae=j.length===2,Pt=Z===zr,vn=E.useMemo(()=>{const v=new URLSearchParams(r.search).get("cwd");if(!v)return null;const T=v.trim();return T.length>0?T:null},[r.search]),pn=E.useRef(null),Me=E.useRef(null),be=E.useRef(null),ke=E.useRef(null),_a=E.useRef(null),Se=E.useRef(null),wl=E.useRef([]),al=E.useRef(null),ul=E.useRef([]),qn=E.useRef(null),Ll=E.useRef(!1),Zt=E.useRef(null),ql=E.useRef(new Map),gn=E.useRef(!1),ve=E.useRef(null),il=E.useRef(null),za=E.useRef(!1),Aa=E.useRef(!1),Be=E.useRef(null),We=E.useRef(null),we=E.useRef(!1),ue=E.useRef(null);E.useEffect(()=>{ul.current=s},[s]),E.useEffect(()=>{qn.current=lt},[lt]),E.useEffect(()=>{Ll.current=L},[L]),E.useEffect(()=>{Aa.current=S},[S]),E.useEffect(()=>{wl.current=gt},[gt]),E.useEffect(()=>{al.current=Ut},[Ut]),E.useEffect(()=>{il.current=X},[X]),E.useEffect(()=>{gn.current=Pt},[Pt]),E.useEffect(()=>{Pt||ql.current.clear()},[Pt]),E.useEffect(()=>{Qt&&K(v=>v===vn?v:vn)},[vn,Qt]),E.useEffect(()=>(bn(),Ie(),()=>{_a.current&&window.clearTimeout(_a.current),Se.current&&window.clearTimeout(Se.current),Be.current&&window.clearInterval(Be.current),Be.current=null,We.current?.abort(),We.current=null,we.current=!1,pn.current?.close()}),[]),E.useEffect(()=>{Mt&&Ie()},[Mt,X]),E.useEffect(()=>{if(!Mt)return;const v=window.setInterval(()=>{Ie()},wm);return()=>window.clearInterval(v)},[Mt,X]),E.useEffect(()=>{Me.current&&requestAnimationFrame(()=>{Me.current&&(Me.current.scrollTop=Me.current.scrollHeight)})},[d,gt.length,Ut?.id,Ut?.provider]),E.useEffect(()=>{be.current&&(be.current.style.height="auto",be.current.style.height=`${Math.min(be.current.scrollHeight,200)}px`)},[C]),E.useEffect(()=>{!Ae||!L||requestAnimationFrame(()=>{const v=be.current;!v||v.disabled||v.focus()})},[lt,L,Ae,Pt,X]),E.useEffect(()=>{Ae||Ll.current&&uc()},[Ae]),E.useEffect(()=>{at&&i("/",{replace:!0})},[at,i]),E.useEffect(()=>{G!=null&&X==null&&i("/",{replace:!0})},[i,G,X]),E.useEffect(()=>{G==null||Z==null||Pt||X!=null&&lt==null&&i(xu(X),{replace:!0})},[lt,Pt,i,G,X,Z]),E.useEffect(()=>{if(!X||!lt||Z==null||Pt)return;!s.some(T=>T.cwd===X&&T.file===lt)&&Rt&&i(xu(X),{replace:!0})},[lt,Rt,Pt,i,X,Z,s]);const cl=E.useMemo(()=>Array.from(new Set(gt.map(v=>v.provider))),[gt]),pe=E.useMemo(()=>gt.filter(v=>v.provider===ae),[gt,ae]),nc=Ut?.provider===ae?Ut.id:"",ac=E.useMemo(()=>{const v=Ut?.reasoning===!1?["off"]:dh;return v.includes(qt)?v:[qt,...v.filter(T=>T!==qt)]},[Ut?.reasoning,qt]),Cu=E.useMemo(()=>Rp(d),[d]),Yn=E.useMemo(()=>!q||!Y?!1:q!==Y,[q,Y]),Gn=E.useMemo(()=>X?s.filter(v=>v.cwd===X):[],[X,s]);function bn(){const v=new WebSocket(cp);pn.current=v,v.onopen=()=>{if(M(!0),Zt.current){const T=Zt.current;fl(T.cwd,T.sessionFile??null)&&(ce(),Fe());return}if(qn.current||Ll.current){const T=qn.current,H=T?ul.current.find($=>$.file===T)?.cwd:il.current??ul.current[0]?.cwd;if(!T&&!H)return;fl(H,T??null)&&(ce(),Fe())}},v.onmessage=T=>{let H;try{H=JSON.parse(T.data)}catch{return}H.type==="rpc_event"&&Ca(H.event),H.type==="error"&&(console.error("[pi-web]",H.message),typeof H.message=="string"&&H.message.includes("no active session")&&(Ll.current||Zt.current)&&(ce(150),Fe())),H.type==="session_ended"&&(y(!1),V(!1),ve.current=null,Ie())},v.onclose=()=>{M(!1),y(!1),V(!1),Zt.current=null,ql.current.clear(),ve.current=null,_a.current=window.setTimeout(bn,2e3)}}function Yt(v){return pn.current?.readyState===WebSocket.OPEN?(pn.current.send(JSON.stringify(v)),!0):!1}function Sn(v,T=12){const H=`route-sync-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;ql.current.set(H,{cwd:v,attemptsLeft:T});const $=Yt({type:"rpc_command",command:{type:"get_state",id:H}});return $||ql.current.delete(H),$}function fl(v,T){return Yt({type:"start_session",sessionFile:T??void 0,cwd:v})?(Zt.current=null,ve.current={cwd:v,sessionFile:T??null},V(!0),Ie(),!0):(Zt.current={cwd:v,sessionFile:T},ve.current=null,V(!1),!1)}function uc(){Yt({type:"detach_session"}),Zt.current=null,ve.current=null,V(!1),y(!1),bt(null),Ie()}function Nu(){const v=Yt({type:"rpc_command",command:{type:"get_available_models",id:"get_models"}}),T=Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}});return v&&T}function Fe(){Yt({type:"rpc_command",command:{type:"get_session_stats",id:"get_session_stats"}})}function ce(v=800){Se.current&&window.clearTimeout(Se.current),Se.current=window.setTimeout(()=>{Nu()||ce(v)},v)}async function Ie(){try{const v=await fetch("/api/sessions");f(await v.json())}catch{}finally{g(!0)}}E.useEffect(()=>{if(!Qt)return;const v=new AbortController,T=q?`?cwd=${encodeURIComponent(q)}`:"";return Tt(!0),nt(null),fetch(`/api/folders${T}`,{signal:v.signal}).then(async H=>{if(!H.ok)throw new Error("failed to load folders");return await H.json()}).then(H=>{v.signal.aborted||(K(H.cwd),P(H.root),tt(Array.isArray(H.folders)?H.folders:[]),nt(H.error??null))}).catch(()=>{v.signal.aborted||(tt([]),nt("unable to load folders"))}).finally(()=>{v.signal.aborted||Tt(!1)}),()=>v.abort()},[q,Qt]),E.useEffect(()=>{if(!Ae||!X||!lt||Pt){Be.current&&window.clearInterval(Be.current),Be.current=null,We.current?.abort(),We.current=null,we.current=!1;return}let v=!1;const T=async()=>{if(v||we.current||Aa.current&&ve.current?.cwd===X&&ve.current?.sessionFile===lt)return;we.current=!0;const $=new AbortController;We.current=$;try{await Uu(X,lt,$.signal)}catch{}finally{We.current===$&&(We.current=null),we.current=!1}};return T(),Be.current=window.setInterval(()=>{T()},wm),()=>{v=!0,Be.current&&window.clearInterval(Be.current),Be.current=null,We.current?.abort(),We.current=null,we.current=!1}},[lt,Ae,Pt,X]);function Xn(v,T){if(typeof v=="string"){T.push({type:"text",content:v,done:!0});return}if(Array.isArray(v)){for(const H of v)if(H.type==="text"&&H.text)T.push({type:"text",content:H.text,done:!0});else if(H.type==="thinking"&&H.thinking)T.push({type:"thinking",content:H.thinking,done:!0});else if(H.type==="toolCall"||H.type==="tool_call"||H.type==="tool_use"){const $=H.result!==void 0||H.output!==void 0,ft=_u(H.result??H.output??""),I=hn(H.result);T.push({type:"tool",name:H.name||H.toolName||"tool",args:H.args||H.arguments||H.input,content:ft.text,details:ft.details,done:$,id:H.id,isError:!!(H.isError??I?.isError)})}}}function Ma(v){return v.map(T=>{const H=[];T.content&&Xn(T.content,H);const $=T.timestamp?Number(T.timestamp):void 0;return{id:T.id||crypto.randomUUID(),role:T.role||"unknown",parts:H,model:T.model,provider:T.provider,timestamp:Number.isFinite($)?$:void 0,usage:T.usage}})}function Oa(v){if(v.length===0)return"0";let T=0,H=0,$=0;for(const ut of v){T+=ut.parts.length;for(const rt of ut.parts)typeof rt.content=="string"&&(H+=rt.content.length),rt.type==="tool"&&$++}const ft=v[v.length-1],I=ft.parts.map(ut=>`${ut.type}:${ut.done?1:0}:${ut.name||""}:${typeof ut.content=="string"?ut.content.length:0}`).join("|");return[v.length,T,H,$,ft.role,ft.timestamp??"",I].join("::")}function Yl(v){if(v.length===0)return null;if(ke.current){const T=v.findIndex(H=>H.id===ke.current);return T<0?null:{target:v[T],index:T}}for(let T=v.length-1;T>=0;T--)if(v[T].role==="assistant")return{target:v[T],index:T};return null}function Ca(v){if(v?.type)switch(v.type){case"response":{if(v.command==="get_available_models"){const T=(v.data?.models??[]).map(H=>({id:H.id,name:H.name,provider:H.provider,contextWindow:H.contextWindow,reasoning:H.reasoning}));T.length>0?(ne(T),wl.current=T,Se.current&&window.clearTimeout(Se.current),al.current||ce()):ce(),Fe()}if(v.command==="get_state"){const T=v.data??{},H=T.model;if(H){const ut={id:H.id,name:H.name,provider:H.provider,contextWindow:H.contextWindow,reasoning:H.reasoning};de(ut),al.current=ut,Lt(H.provider),Se.current&&window.clearTimeout(Se.current),wl.current.length===0&&ce()}else ce();const $=Tu(T.thinkingLevel);$&&me($);const ft=typeof v.id=="string"?v.id:"",I=ft?ql.current.get(ft):void 0;if(I){ql.current.delete(ft);const ut=typeof T.sessionFile=="string"?T.sessionFile.split("/").pop()??"":"",rt=typeof T.messageCount=="number"?T.messageCount:0;ut&&rt>0&&gn.current&&il.current===I.cwd?(f(ht=>ht.some($t=>$t.file===ut)?ht:[{id:typeof T.sessionId=="string"&&T.sessionId?T.sessionId:ut,file:ut,cwd:I.cwd,timestamp:new Date().toISOString(),messageCount:Math.max(rt,1)},...ht]),za.current=!0,i(qm(I.cwd,ut),{replace:!0})):I.attemptsLeft>0&&gn.current&&il.current===I.cwd&&window.setTimeout(()=>{gn.current&&il.current===I.cwd&&Sn(I.cwd,I.attemptsLeft-1)},250)}}if(v.command==="set_model"&&v.success){const T=v.data;if(T){const H={id:T.id,name:T.name,provider:T.provider,contextWindow:T.contextWindow,reasoning:T.reasoning};de(H),al.current=H}Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}})}if(v.command==="set_thinking_level"&&v.success){const T=Tu(v.data?.level);T&&me(T),Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}})}if(v.command==="cycle_thinking_level"&&v.success){const T=Tu(v.data?.level);T&&me(T),Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}})}v.command==="get_session_stats"&&v.success&&bt(v.data);break}case"agent_start":y(!0),Ie();break;case"agent_end":y(!1),ke.current=null,Ie(),Fe(),(wl.current.length===0||!al.current)&&ce(),Q(T=>{if(T.length===0)return T;const[H,...$]=T;return Yt({type:"rpc_command",command:{type:"prompt",message:H,id:`web-${Date.now()}`}}),$});break;case"message_start":{const T=v.message;if(!T)break;const H=T.id||crypto.randomUUID(),$=T.role||"assistant";if($==="toolResult"||$==="tool_result"||$==="tool")break;const ft=[];T.content&&Xn(T.content,ft);const I={id:H,role:$,parts:ft,model:T.model,provider:T.provider,timestamp:typeof T.timestamp=="number"?T.timestamp:void 0,usage:T.usage};$==="assistant"&&(ke.current=H),m(ut=>ut.some(rt=>rt.id===H)?ut:[...ut,I]);break}case"message_update":{const T=v.assistantMessageEvent,H=T?.type==="thinking_delta",$=T?.type==="text_delta"||T?.type==="thinking_delta"?T.delta:void 0;if(!$)break;m(ft=>{const I=Yl(ft);if(!I)return ft;const ut=[...I.target.parts],rt=H?"thinking":"text";let ht=ut.find($t=>$t.type===rt&&!$t.done);ht||(ht={type:rt,content:""},ut.push(ht)),ht.content=`${ht.content||""}${$}`;const Le=[...ft];return Le[I.index]={...I.target,parts:ut},Le});break}case"message_end":{const T=v.message;if(T?.role&&T.role!=="assistant")break;const H=typeof T?.timestamp=="number"?T.timestamp:void 0,$=ke.current;m(ft=>ft.map(I=>{if(I.id!==$)return I;const ut=H??I.timestamp;if(T?.content){const rt=[];return Xn(T.content,rt),{...I,parts:rt,model:T.model??I.model,provider:T.provider??I.provider,timestamp:ut,usage:T.usage??I.usage}}return{...I,parts:I.parts.map(rt=>({...rt,done:!0})),timestamp:ut,usage:T?.usage??I.usage}}));break}case"tool_execution_start":{const T=v.toolCallId||v.id;m(H=>{const $=Yl(H);if(!$)return H;const ft=[...$.target.parts],I=ft.findIndex(rt=>rt.type==="tool"&&rt.id&&T&&rt.id===T);if(I>=0){const rt=ft[I];ft[I]={...rt,type:"tool",name:v.toolName||v.name||rt.name||"tool",args:v.args??rt.args,content:rt.content??"",done:!1,id:T,details:rt.details,isError:!1}}else ft.push({type:"tool",name:v.toolName||v.name||"tool",args:v.args,content:"",done:!1,id:T,isError:!1});const ut=[...H];return ut[$.index]={...$.target,parts:ft},ut});break}case"tool_execution_update":{const T=v.toolCallId||v.id,H=v.partialResult!==void 0,$=_u(H?v.partialResult:v.output);m(ft=>{const I=Yl(ft);if(!I)return ft;const ut=[...I.target.parts],rt=[...ut].reverse(),ht=rt.find($t=>$t.type==="tool"&&!$t.done&&(!T||$t.id===T))||rt.find($t=>$t.type==="tool"&&!$t.done);ht&&(v.args!==void 0&&(ht.args=v.args),H?ht.content=$.text:$.text&&(ht.content=`${yn(ht.content)}${$.text}`),$.details!==void 0&&(ht.details=$.details));const Le=[...ft];return Le[I.index]={...I.target,parts:ut},Le});break}case"tool_execution_end":{const T=v.toolCallId||v.id,H=_u(v.result??v.output??""),$=v.result!==void 0||v.output!==void 0;m(ft=>{const I=Yl(ft);if(!I)return ft;const ut=[...I.target.parts],rt=[...ut].reverse(),ht=rt.find($t=>$t.type==="tool"&&!$t.done&&(!T||$t.id===T))||rt.find($t=>$t.type==="tool"&&!$t.done);ht&&(v.args!==void 0&&(ht.args=v.args),ht.done=!0,ht.isError=!!v.isError,$&&(ht.content=H.text),H.details!==void 0&&(ht.details=H.details));const Le=[...ft];return Le[I.index]={...I.target,parts:ut},Le});break}case"model_changed":{const T=v.model;if(T){const $={id:T.id,name:T.name,provider:T.provider,contextWindow:T.contextWindow,reasoning:T.reasoning};de($),al.current=$}const H=Tu(v.thinkingLevel??v.level);H&&me(H);break}}}async function Du(v,T){try{const H=await fetch(`/api/session?cwd=${encodeURIComponent(v)}&filename=${encodeURIComponent(T)}`);if(!H.ok)return;const $=await H.json(),ft=Ma($);ue.current=Oa(ft),m(ft)}catch{}}async function Uu(v,T,H){const $=await fetch(`/api/session?cwd=${encodeURIComponent(v)}&filename=${encodeURIComponent(T)}`,{signal:H});if(!$.ok)return;const ft=await $.json(),I=Ma(ft),ut=Oa(I);ut!==ue.current&&(ue.current=ut,m(I),Ie())}function Pe(){m([]),R(""),ke.current=null,y(!1),bt(null),ue.current=null,Se.current&&window.clearTimeout(Se.current)}async function te(v,T){if(Ll.current&&ve.current?.sessionFile===T&&ve.current?.cwd===v){be.current?.focus();return}Pe(),await Du(v,T),fl(v,T)&&(ce(120),Fe()),be.current?.focus()}function he(v){if(Ll.current&&ve.current?.sessionFile===null&&ve.current?.cwd===v){be.current?.focus();return}Pe(),fl(v,null)&&(ce(120),Fe()),be.current?.focus()}E.useEffect(()=>{if(!X||Z==null)return;if(Pt){he(X);return}if(!(!lt||!s.some(T=>T.cwd===X&&T.file===lt))){if(za.current){za.current=!1,ve.current={cwd:X,sessionFile:lt};return}te(X,lt)}},[lt,Pt,X,Z,s]);function Gl(v){const T=ul.current.find(H=>H.file===v)?.cwd;T&&i(qm(T,v))}function Na(v){i(rp(v))}function ic(v){i(xu(v))}function cc(v){i($i(v))}function ju(){if(!q||!Y||q===Y)return;const v=q.split("/").filter(Boolean),T=v.length<=1?"/":`/${v.slice(0,-1).join("/")}`;i($i(T))}function En(){q&&ic(q)}function Qn(){i($i(X??q))}function Xl(){if(!X){i($i(q));return}i(xu(X))}function yl(){const v=C.trim();if(!v||!b||!L)return;if(R(""),S){Q(H=>[...H,v]);return}Yt({type:"rpc_command",command:{type:"prompt",message:v,id:`web-${Date.now()}`}})&&Pt&&X&&Sn(X)}function xn(){Yt({type:"rpc_command",command:{type:"abort",id:`abort-${Date.now()}`}})}function Ql(v){Lt(v)}function Jt(v){const T=gt.find(H=>H.id===v&&H.provider===ae);T&&Yt({type:"rpc_command",command:{type:"set_model",provider:T.provider,modelId:T.id,id:"set_model"}})}function Hu(v){const T=Tu(v);T&&(me(T),Yt({type:"rpc_command",command:{type:"set_thinking_level",level:T,id:"set_thinking_level"}}))}async function Bu(v){const T=ul.current.find($=>$.file===v)?.cwd??X??"";try{await fetch(`/api/session?cwd=${encodeURIComponent(T)}&filename=${encodeURIComponent(v)}`,{method:"DELETE"})}catch{}f($=>$.filter(ft=>ft.file!==v));const H=X??ul.current.find($=>$.file===v)?.cwd;qn.current===v&&(m([]),R(""),ke.current=null,y(!1),V(!1),bt(null),i(H?xu(H):"/"))}const vl=S?"streaming response":"session status";return w.jsxs("div",{className:"flex flex-col h-full bg-pi-page-bg text-gray-900 text-sm font-mono overflow-hidden",children:[Qt&&w.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-5 md:px-6",children:w.jsx(pp,{cwd:q,folders:ct,isLoading:_t,error:jt,canNavigateUp:Yn,onBrowseIntoFolder:cc,onBrowseToParent:ju,onOpenCurrentFolder:En})}),Mt&&X&&w.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-5 md:px-6",children:w.jsx(gp,{projectCwd:X,sessions:Gn,onBack:Qn,onCreateSession:()=>Na(X),onSelectSession:Gl,onDeleteSession:Bu})}),Mt&&!X&&w.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-5 md:px-6",children:w.jsxs("div",{className:"mx-auto max-w-3xl rounded-xl border border-pi-border-muted bg-pi-card-bg p-4",children:[w.jsx("div",{className:"text-sm text-pi-muted mb-3",children:"no folder selected"}),w.jsx("button",{onClick:Qn,className:"px-3 py-1.5 rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:"choose folder"})]})}),Ae&&w.jsxs("main",{className:"flex-1 flex flex-col min-h-0",children:[w.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 md:px-6 border-b border-pi-border-muted bg-pi-card-bg",children:[w.jsxs("div",{className:"min-w-0",children:[w.jsx("div",{className:"text-[11px] text-pi-dim truncate",children:X?fp(X):"folder not selected"}),w.jsx("div",{className:"text-xs truncate text-pi-muted",children:lt?lt.split("/").pop():"new session"})]}),w.jsx("button",{onClick:Xl,title:"back to sessions",className:"ml-auto inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w.jsx("polyline",{points:"10.5,3 5,8 10.5,13"})})})]}),w.jsx("div",{ref:Me,className:"flex-1 overflow-y-auto px-4 py-2 md:px-6",children:d.length===0?w.jsx("div",{className:"flex items-center justify-center h-full text-pi-muted text-base",children:"choose a session and start prompting."}):d.filter(v=>(v.role==="user"||v.role==="assistant")&&(v.role==="user"||v.parts.some(T=>T.type==="tool"||T.type==="text"&&(T.content??"").trim()))).map(v=>w.jsx(vp,{msg:v},v.id))}),w.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 md:px-6 border-t border-pi-border-muted bg-pi-card-bg text-xs text-pi-muted flex-wrap",children:[gt.length>0&&w.jsxs("span",{className:"flex items-center gap-1.5",children:[w.jsx("select",{value:ae,onChange:v=>Ql(v.target.value),disabled:S,className:"font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 select-fit-content",children:cl.map(v=>w.jsx("option",{value:v,children:v},v))}),w.jsx("select",{value:nc,onChange:v=>Jt(v.target.value),disabled:S,className:"font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 select-fit-content",children:pe.map(v=>w.jsx("option",{value:v.id,children:v.id},v.id))})]}),gt.length===0&&Ut&&w.jsx("span",{children:Ut.id}),L&&(gt.length>0||Ut)&&w.jsx("select",{value:qt,onChange:v=>Hu(v.target.value),disabled:!b||S||Ut?.reasoning===!1,"aria-label":"thinking level",title:"thinking level",className:"font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 select-fit-content",children:ac.map(v=>w.jsx("option",{value:v,children:v},v))}),W&&w.jsxs("span",{className:"flex items-center gap-2 text-pi-dim ml-auto flex-wrap",children:[W.tokens.input>0&&w.jsxs("span",{children:["↑",Ru(W.tokens.input)]}),W.tokens.output>0&&w.jsxs("span",{children:["↓",Ru(W.tokens.output)]}),W.tokens.cacheRead>0&&w.jsxs("span",{children:["r",Ru(W.tokens.cacheRead)]}),W.tokens.cacheWrite>0&&w.jsxs("span",{children:["w",Ru(W.tokens.cacheWrite)]}),W.cost>0&&w.jsxs("span",{children:["$",W.cost.toFixed(3)]}),Ut?.contextWindow&&Cu&&(()=>{const v=Cu/Ut.contextWindow*100,T=v>90?"text-pi-error":v>70?"text-pi-warning":"";return w.jsxs("span",{className:T,children:[v.toFixed(1),"%/",Ru(Ut.contextWindow)]})})()]}),S&&w.jsxs("span",{children:["responding",N.length>0?` · ${N.length} queued`:""]})]}),w.jsx("div",{className:"px-4 pb-4 pt-3 md:px-6 border-t border-pi-border-muted bg-pi-card-bg",children:w.jsxs("div",{className:"flex gap-2 items-center",children:[w.jsx("span",{className:"sr-only","aria-live":"polite",children:vl}),w.jsx("textarea",{ref:be,rows:1,placeholder:L?"send a message...":"create or select a session",disabled:!L,value:C,onChange:v=>R(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),yl())},className:"prompt-input flex-1 bg-white border border-pi-border-muted rounded-lg px-3 py-2.5 font-mono resize-none min-h-[42px] max-h-[200px] outline-none focus:border-pi-accent disabled:opacity-50 disabled:cursor-default"}),w.jsxs("div",{className:"flex flex-row gap-1 flex-shrink-0",children:[w.jsxs("button",{onClick:yl,disabled:!b||!L,title:S?"queue message":"send",className:"relative h-[42px] aspect-square inline-flex items-center justify-center flex-shrink-0 rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:[w.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 18 18",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[w.jsx("line",{x1:"2",y1:"9",x2:"16",y2:"9"}),w.jsx("polyline",{points:"10,3 16,9 10,15"})]}),N.length>0&&w.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:N.length})]}),w.jsx("button",{onClick:xn,disabled:!S||!L,title:"stop",className:"h-[42px] aspect-square inline-flex items-center justify-center flex-shrink-0 rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:w.jsx("svg",{width:"20",height:"20",viewBox:"0 0 18 18",fill:"currentColor",children:w.jsx("rect",{x:"4",y:"4",width:"10",height:"10",rx:"1.5"})})})]})]})})]})]})}function vp({msg:i}){const r=i.role==="user",s=i.parts.some(m=>m.type==="text"&&!!(m.content??"").trim()),f=i.parts.some(m=>m.type==="tool"),d=!r&&f&&!s;return w.jsx("div",{className:"mb-2 min-w-0",children:w.jsx("div",{className:`rounded-lg ${d?"p-0":"px-2 py-1.5"} min-w-0 overflow-hidden ${r?"bg-pi-user-bg":"bg-pi-card-bg border border-pi-border-muted"}`,children:w.jsx("div",{className:"text-xs md:text-sm leading-relaxed break-words min-w-0",children:i.parts.map((m,b)=>w.jsx(bp,{part:m},`${i.id}-${b}`))})})})}function pp({cwd:i,folders:r,isLoading:s,error:f,canNavigateUp:d,onBrowseIntoFolder:m,onBrowseToParent:b,onOpenCurrentFolder:M}){return w.jsxs("div",{className:"mx-auto max-w-3xl",children:[w.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[w.jsxs("div",{className:"min-w-0",children:[w.jsx("h1",{className:"text-base md:text-lg font-semibold text-pi-accent",children:"browse folders"}),w.jsx("p",{className:"text-pi-muted mt-1 truncate",title:i??"",children:i?Ta(i):"loading…"})]}),w.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[w.jsx("button",{onClick:M,disabled:!i,title:"open current folder","aria-label":"open current folder",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:w.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[w.jsx("path",{d:"M1.5 6.1V4.8a1 1 0 0 1 1-1h3l1.3 1.3h6.7a1 1 0 0 1 1 1v.8"}),w.jsx("path",{d:"M1.5 6.9h13l-1.2 5.2a1 1 0 0 1-1 .8H3.7a1 1 0 0 1-1-.8L1.5 6.9Z"})]})}),w.jsx("button",{onClick:b,disabled:!d,title:"back",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:w.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w.jsx("polyline",{points:"10.5,3 5,8 10.5,13"})})})]})]}),w.jsxs("div",{className:"rounded-xl border border-pi-border-muted bg-pi-card-bg",children:[s&&w.jsx("div",{className:"px-4 py-6 text-center text-pi-muted",children:"loading folders…"}),!s&&f&&w.jsx("div",{className:"px-4 py-6 text-center text-pi-error",children:f}),!s&&!f&&r.length===0&&w.jsx("div",{className:"px-4 py-6 text-center text-pi-muted",children:"no visible folders here."}),!s&&!f&&r.length>0&&w.jsx("div",{className:"divide-y divide-pi-border-muted",children:r.map(S=>w.jsx("button",{onClick:()=>m(S.path),className:"w-full text-left px-4 py-3 hover:bg-pi-user-bg cursor-pointer",title:S.path,children:w.jsx("div",{className:"text-sm text-gray-800 truncate",children:S.name})},S.path))})]})]})}function gp({projectCwd:i,sessions:r,onBack:s,onCreateSession:f,onSelectSession:d,onDeleteSession:m}){return w.jsxs("div",{className:"mx-auto max-w-3xl",children:[w.jsxs("div",{className:"mb-4 flex items-start gap-3 justify-between",children:[w.jsxs("div",{className:"min-w-0",children:[w.jsx("h1",{className:"text-base md:text-lg font-semibold text-pi-accent",children:"choose a session"}),w.jsx("p",{className:"text-pi-muted mt-1 truncate",title:i,children:i})]}),w.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[w.jsx("button",{onClick:f,title:"new session",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[w.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"13"}),w.jsx("line",{x1:"3",y1:"8",x2:"13",y2:"8"})]})}),w.jsx("button",{onClick:s,title:"back to folders",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w.jsx("polyline",{points:"10.5,3 5,8 10.5,13"})})})]})]}),r.length===0?w.jsx("div",{className:"rounded-xl border border-dashed border-pi-border-muted bg-pi-card-bg px-4 py-6 text-center text-pi-muted",children:"no sessions in this folder yet."}):w.jsx("div",{className:"space-y-2",children:r.map(b=>{const M=b.firstPrompt||b.id.slice(0,8),S=b.timestamp?new Date(b.timestamp).toLocaleString():"",y=!!b.isWorking,C=!!b.isActive,R=y?"working":C?"active":"idle",L=y?"bg-pi-success animate-pulse-dot":C?"bg-pi-accent":"bg-pi-border-muted";return w.jsxs("div",{className:"group relative w-full text-left rounded-xl border border-pi-border-muted bg-pi-card-bg px-4 py-3 hover:bg-pi-user-bg",children:[w.jsxs("button",{onClick:()=>d(b.file),className:"w-full text-left cursor-pointer",children:[w.jsx("div",{className:"text-sm text-gray-800 truncate pr-8",children:M}),w.jsxs("div",{className:"text-[11px] text-pi-muted mt-1 flex items-center gap-1.5 flex-wrap",children:[w.jsxs("span",{children:[b.messageCount," msgs"]}),w.jsx("span",{children:"·"}),w.jsx("span",{children:S}),w.jsx("span",{children:"·"}),w.jsxs("span",{className:"inline-flex items-center gap-1",children:[w.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${L}`}),R]})]})]}),w.jsx("button",{onClick:()=>m(b.file),title:"delete session",className:"absolute top-3 right-3 hidden group-hover:inline-flex items-center justify-center w-6 h-6 rounded text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[w.jsx("line",{x1:"1.5",y1:"1.5",x2:"8.5",y2:"8.5"}),w.jsx("line",{x1:"8.5",y1:"1.5",x2:"1.5",y2:"8.5"})]})})]},b.file)})})]})}function bp({part:i}){return i.type==="text"?w.jsx("div",{dangerouslySetInnerHTML:{__html:Ep(i.content||"")}}):i.type==="thinking"?null:i.type==="tool"?w.jsx(Sp,{part:i}):null}function Sp({part:i}){const r=E.useMemo(()=>hp(i),[i]),s=i.name==="edit"?"":"max-h-64",f=i.name==="edit"?"overflow-x-auto":"overflow-auto";return w.jsx("div",{className:`my-0 px-1.5 py-1 text-xs overflow-hidden ${i.done?i.isError?"bg-pi-tool-error":"bg-pi-tool-success":"bg-pi-tool-pending"}`,children:w.jsx("pre",{className:`tool-io-pre ${s} ${f} ${i.isError?"text-pi-error":"text-pi-tool-output"}`,children:r})})}function Ep(i){const r=i.split(`
45
+ ${f}`),b}function yp(){const i=ah(),r=Bl(),[s,f]=E.useState([]),[d,m]=E.useState([]),[b,M]=E.useState(!1),[S,y]=E.useState(!1),[C,R]=E.useState(""),[L,V]=E.useState(!1),[q,K]=E.useState(op),[Y,P]=E.useState(null),[ct,tt]=E.useState([]),[_t,Tt]=E.useState(!1),[jt,nt]=E.useState(null),[gt,ne]=E.useState([]),[Ut,de]=E.useState(null),[qt,me]=E.useState("off"),[ae,Lt]=E.useState(""),[N,Q]=E.useState([]),[W,bt]=E.useState(null),[Rt,g]=E.useState(!1),j=E.useMemo(()=>r.pathname.split("/").filter(Boolean),[r.pathname]),G=j[0],Z=j[1],at=j.length>2,X=E.useMemo(()=>Lm(G),[G]),lt=E.useMemo(()=>Z==null||Z===zr?null:Lm(Z),[Z]),Qt=j.length===0,Mt=j.length===1,Ae=j.length===2,Pt=Z===zr,vn=E.useMemo(()=>{const v=new URLSearchParams(r.search).get("cwd");if(!v)return null;const T=v.trim();return T.length>0?T:null},[r.search]),pn=E.useRef(null),Me=E.useRef(null),be=E.useRef(null),ke=E.useRef(null),_a=E.useRef(null),Se=E.useRef(null),wl=E.useRef([]),al=E.useRef(null),ul=E.useRef([]),qn=E.useRef(null),Ll=E.useRef(!1),Zt=E.useRef(null),ql=E.useRef(new Map),gn=E.useRef(!1),ve=E.useRef(null),il=E.useRef(null),za=E.useRef(!1),Aa=E.useRef(!1),Be=E.useRef(null),We=E.useRef(null),we=E.useRef(!1),ue=E.useRef(null);E.useEffect(()=>{ul.current=s},[s]),E.useEffect(()=>{qn.current=lt},[lt]),E.useEffect(()=>{Ll.current=L},[L]),E.useEffect(()=>{Aa.current=S},[S]),E.useEffect(()=>{wl.current=gt},[gt]),E.useEffect(()=>{al.current=Ut},[Ut]),E.useEffect(()=>{il.current=X},[X]),E.useEffect(()=>{gn.current=Pt},[Pt]),E.useEffect(()=>{Pt||ql.current.clear()},[Pt]),E.useEffect(()=>{Qt&&K(v=>v===vn?v:vn)},[vn,Qt]),E.useEffect(()=>(bn(),Ie(),()=>{_a.current&&window.clearTimeout(_a.current),Se.current&&window.clearTimeout(Se.current),Be.current&&window.clearInterval(Be.current),Be.current=null,We.current?.abort(),We.current=null,we.current=!1,pn.current?.close()}),[]),E.useEffect(()=>{Mt&&Ie()},[Mt,X]),E.useEffect(()=>{if(!Mt)return;const v=window.setInterval(()=>{Ie()},wm);return()=>window.clearInterval(v)},[Mt,X]),E.useEffect(()=>{Me.current&&requestAnimationFrame(()=>{Me.current&&(Me.current.scrollTop=Me.current.scrollHeight)})},[d,gt.length,Ut?.id,Ut?.provider]),E.useEffect(()=>{be.current&&(be.current.style.height="auto",be.current.style.height=`${Math.min(be.current.scrollHeight,200)}px`)},[C]),E.useEffect(()=>{!Ae||!L||requestAnimationFrame(()=>{const v=be.current;!v||v.disabled||v.focus()})},[lt,L,Ae,Pt,X]),E.useEffect(()=>{Ae||Ll.current&&uc()},[Ae]),E.useEffect(()=>{at&&i("/",{replace:!0})},[at,i]),E.useEffect(()=>{G!=null&&X==null&&i("/",{replace:!0})},[i,G,X]),E.useEffect(()=>{G==null||Z==null||Pt||X!=null&&lt==null&&i(xu(X),{replace:!0})},[lt,Pt,i,G,X,Z]),E.useEffect(()=>{if(!X||!lt||Z==null||Pt)return;!s.some(T=>T.cwd===X&&T.file===lt)&&Rt&&i(xu(X),{replace:!0})},[lt,Rt,Pt,i,X,Z,s]);const cl=E.useMemo(()=>Array.from(new Set(gt.map(v=>v.provider))),[gt]),pe=E.useMemo(()=>gt.filter(v=>v.provider===ae),[gt,ae]),nc=Ut?.provider===ae?Ut.id:"",ac=E.useMemo(()=>{const v=Ut?.reasoning===!1?["off"]:dh;return v.includes(qt)?v:[qt,...v.filter(T=>T!==qt)]},[Ut?.reasoning,qt]),Cu=E.useMemo(()=>Rp(d),[d]),Yn=E.useMemo(()=>!q||!Y?!1:q!==Y,[q,Y]),Gn=E.useMemo(()=>X?s.filter(v=>v.cwd===X):[],[X,s]);function bn(){const v=new WebSocket(cp);pn.current=v,v.onopen=()=>{if(M(!0),Zt.current){const T=Zt.current;fl(T.cwd,T.sessionFile??null)&&(ce(),Fe());return}if(qn.current||Ll.current){const T=qn.current,H=T?ul.current.find($=>$.file===T)?.cwd:il.current??ul.current[0]?.cwd;if(!T&&!H)return;fl(H,T??null)&&(ce(),Fe())}},v.onmessage=T=>{let H;try{H=JSON.parse(T.data)}catch{return}H.type==="rpc_event"&&Ca(H.event),H.type==="error"&&(console.error("[pi-web]",H.message),typeof H.message=="string"&&H.message.includes("no active session")&&(Ll.current||Zt.current)&&(ce(150),Fe())),H.type==="session_ended"&&(y(!1),V(!1),ve.current=null,Ie())},v.onclose=()=>{M(!1),y(!1),V(!1),Zt.current=null,ql.current.clear(),ve.current=null,_a.current=window.setTimeout(bn,2e3)}}function Yt(v){return pn.current?.readyState===WebSocket.OPEN?(pn.current.send(JSON.stringify(v)),!0):!1}function Sn(v,T=12){const H=`route-sync-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;ql.current.set(H,{cwd:v,attemptsLeft:T});const $=Yt({type:"rpc_command",command:{type:"get_state",id:H}});return $||ql.current.delete(H),$}function fl(v,T){return Yt({type:"start_session",sessionFile:T??void 0,cwd:v})?(Zt.current=null,ve.current={cwd:v,sessionFile:T??null},V(!0),Ie(),!0):(Zt.current={cwd:v,sessionFile:T},ve.current=null,V(!1),!1)}function uc(){Yt({type:"detach_session"}),Zt.current=null,ve.current=null,V(!1),y(!1),bt(null),Ie()}function Nu(){const v=Yt({type:"rpc_command",command:{type:"get_available_models",id:"get_models"}}),T=Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}});return v&&T}function Fe(){Yt({type:"rpc_command",command:{type:"get_session_stats",id:"get_session_stats"}})}function ce(v=800){Se.current&&window.clearTimeout(Se.current),Se.current=window.setTimeout(()=>{Nu()||ce(v)},v)}async function Ie(){try{const v=await fetch("/api/sessions");f(await v.json())}catch{}finally{g(!0)}}E.useEffect(()=>{if(!Qt)return;const v=new AbortController,T=q?`?cwd=${encodeURIComponent(q)}`:"";return Tt(!0),nt(null),fetch(`/api/folders${T}`,{signal:v.signal}).then(async H=>{if(!H.ok)throw new Error("failed to load folders");return await H.json()}).then(H=>{v.signal.aborted||(K(H.cwd),P(H.root),tt(Array.isArray(H.folders)?H.folders:[]),nt(H.error??null))}).catch(()=>{v.signal.aborted||(tt([]),nt("unable to load folders"))}).finally(()=>{v.signal.aborted||Tt(!1)}),()=>v.abort()},[q,Qt]),E.useEffect(()=>{if(!Ae||!X||!lt||Pt){Be.current&&window.clearInterval(Be.current),Be.current=null,We.current?.abort(),We.current=null,we.current=!1;return}let v=!1;const T=async()=>{if(v||we.current||Aa.current&&ve.current?.cwd===X&&ve.current?.sessionFile===lt)return;we.current=!0;const $=new AbortController;We.current=$;try{await Uu(X,lt,$.signal)}catch{}finally{We.current===$&&(We.current=null),we.current=!1}};return T(),Be.current=window.setInterval(()=>{T()},wm),()=>{v=!0,Be.current&&window.clearInterval(Be.current),Be.current=null,We.current?.abort(),We.current=null,we.current=!1}},[lt,Ae,Pt,X]);function Xn(v,T){if(typeof v=="string"){T.push({type:"text",content:v,done:!0});return}if(Array.isArray(v)){for(const H of v)if(H.type==="text"&&H.text)T.push({type:"text",content:H.text,done:!0});else if(H.type==="thinking"&&H.thinking)T.push({type:"thinking",content:H.thinking,done:!0});else if(H.type==="toolCall"||H.type==="tool_call"||H.type==="tool_use"){const $=H.result!==void 0||H.output!==void 0,ft=_u(H.result??H.output??""),I=hn(H.result);T.push({type:"tool",name:H.name||H.toolName||"tool",args:H.args||H.arguments||H.input,content:ft.text,details:ft.details,done:$,id:H.id,isError:!!(H.isError??I?.isError)})}}}function Ma(v){return v.map(T=>{const H=[];T.content&&Xn(T.content,H);const $=T.timestamp?Number(T.timestamp):void 0;return{id:T.id||crypto.randomUUID(),role:T.role||"unknown",parts:H,model:T.model,provider:T.provider,timestamp:Number.isFinite($)?$:void 0,usage:T.usage}})}function Oa(v){if(v.length===0)return"0";let T=0,H=0,$=0;for(const ut of v){T+=ut.parts.length;for(const rt of ut.parts)typeof rt.content=="string"&&(H+=rt.content.length),rt.type==="tool"&&$++}const ft=v[v.length-1],I=ft.parts.map(ut=>`${ut.type}:${ut.done?1:0}:${ut.name||""}:${typeof ut.content=="string"?ut.content.length:0}`).join("|");return[v.length,T,H,$,ft.role,ft.timestamp??"",I].join("::")}function Yl(v){if(v.length===0)return null;if(ke.current){const T=v.findIndex(H=>H.id===ke.current);return T<0?null:{target:v[T],index:T}}for(let T=v.length-1;T>=0;T--)if(v[T].role==="assistant")return{target:v[T],index:T};return null}function Ca(v){if(v?.type)switch(v.type){case"response":{if(v.command==="get_available_models"){const T=(v.data?.models??[]).map(H=>({id:H.id,name:H.name,provider:H.provider,contextWindow:H.contextWindow,reasoning:H.reasoning}));T.length>0?(ne(T),wl.current=T,Se.current&&window.clearTimeout(Se.current),al.current||ce()):ce(),Fe()}if(v.command==="get_state"){const T=v.data??{},H=T.model;if(H){const ut={id:H.id,name:H.name,provider:H.provider,contextWindow:H.contextWindow,reasoning:H.reasoning};de(ut),al.current=ut,Lt(H.provider),Se.current&&window.clearTimeout(Se.current),wl.current.length===0&&ce()}else ce();const $=Tu(T.thinkingLevel);$&&me($);const ft=typeof v.id=="string"?v.id:"",I=ft?ql.current.get(ft):void 0;if(I){ql.current.delete(ft);const ut=typeof T.sessionFile=="string"?T.sessionFile.split("/").pop()??"":"",rt=typeof T.messageCount=="number"?T.messageCount:0;ut&&rt>0&&gn.current&&il.current===I.cwd?(f(ht=>ht.some($t=>$t.file===ut)?ht:[{id:typeof T.sessionId=="string"&&T.sessionId?T.sessionId:ut,file:ut,cwd:I.cwd,timestamp:new Date().toISOString(),messageCount:Math.max(rt,1)},...ht]),za.current=!0,i(qm(I.cwd,ut),{replace:!0})):I.attemptsLeft>0&&gn.current&&il.current===I.cwd&&window.setTimeout(()=>{gn.current&&il.current===I.cwd&&Sn(I.cwd,I.attemptsLeft-1)},250)}}if(v.command==="set_model"&&v.success){const T=v.data;if(T){const H={id:T.id,name:T.name,provider:T.provider,contextWindow:T.contextWindow,reasoning:T.reasoning};de(H),al.current=H}Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}})}if(v.command==="set_thinking_level"&&v.success){const T=Tu(v.data?.level);T&&me(T),Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}})}if(v.command==="cycle_thinking_level"&&v.success){const T=Tu(v.data?.level);T&&me(T),Yt({type:"rpc_command",command:{type:"get_state",id:"get_state"}})}v.command==="get_session_stats"&&v.success&&bt(v.data);break}case"agent_start":y(!0),Ie();break;case"agent_end":y(!1),ke.current=null,Ie(),Fe(),(wl.current.length===0||!al.current)&&ce(),Q(T=>{if(T.length===0)return T;const[H,...$]=T;return Yt({type:"rpc_command",command:{type:"prompt",message:H,id:`web-${Date.now()}`}}),$});break;case"message_start":{const T=v.message;if(!T)break;const H=T.id||crypto.randomUUID(),$=T.role||"assistant";if($==="toolResult"||$==="tool_result"||$==="tool")break;const ft=[];T.content&&Xn(T.content,ft);const I={id:H,role:$,parts:ft,model:T.model,provider:T.provider,timestamp:typeof T.timestamp=="number"?T.timestamp:void 0,usage:T.usage};$==="assistant"&&(ke.current=H),m(ut=>ut.some(rt=>rt.id===H)?ut:[...ut,I]);break}case"message_update":{const T=v.assistantMessageEvent,H=T?.type==="thinking_delta",$=T?.type==="text_delta"||T?.type==="thinking_delta"?T.delta:void 0;if(!$)break;m(ft=>{const I=Yl(ft);if(!I)return ft;const ut=[...I.target.parts],rt=H?"thinking":"text";let ht=ut.find($t=>$t.type===rt&&!$t.done);ht||(ht={type:rt,content:""},ut.push(ht)),ht.content=`${ht.content||""}${$}`;const Le=[...ft];return Le[I.index]={...I.target,parts:ut},Le});break}case"message_end":{const T=v.message;if(T?.role&&T.role!=="assistant")break;const H=typeof T?.timestamp=="number"?T.timestamp:void 0,$=ke.current;m(ft=>ft.map(I=>{if(I.id!==$)return I;const ut=H??I.timestamp;if(T?.content){const rt=[];return Xn(T.content,rt),{...I,parts:rt,model:T.model??I.model,provider:T.provider??I.provider,timestamp:ut,usage:T.usage??I.usage}}return{...I,parts:I.parts.map(rt=>({...rt,done:!0})),timestamp:ut,usage:T?.usage??I.usage}}));break}case"tool_execution_start":{const T=v.toolCallId||v.id;m(H=>{const $=Yl(H);if(!$)return H;const ft=[...$.target.parts],I=ft.findIndex(rt=>rt.type==="tool"&&rt.id&&T&&rt.id===T);if(I>=0){const rt=ft[I];ft[I]={...rt,type:"tool",name:v.toolName||v.name||rt.name||"tool",args:v.args??rt.args,content:rt.content??"",done:!1,id:T,details:rt.details,isError:!1}}else ft.push({type:"tool",name:v.toolName||v.name||"tool",args:v.args,content:"",done:!1,id:T,isError:!1});const ut=[...H];return ut[$.index]={...$.target,parts:ft},ut});break}case"tool_execution_update":{const T=v.toolCallId||v.id,H=v.partialResult!==void 0,$=_u(H?v.partialResult:v.output);m(ft=>{const I=Yl(ft);if(!I)return ft;const ut=[...I.target.parts],rt=[...ut].reverse(),ht=rt.find($t=>$t.type==="tool"&&!$t.done&&(!T||$t.id===T))||rt.find($t=>$t.type==="tool"&&!$t.done);ht&&(v.args!==void 0&&(ht.args=v.args),H?ht.content=$.text:$.text&&(ht.content=`${yn(ht.content)}${$.text}`),$.details!==void 0&&(ht.details=$.details));const Le=[...ft];return Le[I.index]={...I.target,parts:ut},Le});break}case"tool_execution_end":{const T=v.toolCallId||v.id,H=_u(v.result??v.output??""),$=v.result!==void 0||v.output!==void 0;m(ft=>{const I=Yl(ft);if(!I)return ft;const ut=[...I.target.parts],rt=[...ut].reverse(),ht=rt.find($t=>$t.type==="tool"&&!$t.done&&(!T||$t.id===T))||rt.find($t=>$t.type==="tool"&&!$t.done);ht&&(v.args!==void 0&&(ht.args=v.args),ht.done=!0,ht.isError=!!v.isError,$&&(ht.content=H.text),H.details!==void 0&&(ht.details=H.details));const Le=[...ft];return Le[I.index]={...I.target,parts:ut},Le});break}case"model_changed":{const T=v.model;if(T){const $={id:T.id,name:T.name,provider:T.provider,contextWindow:T.contextWindow,reasoning:T.reasoning};de($),al.current=$}const H=Tu(v.thinkingLevel??v.level);H&&me(H);break}}}async function Du(v,T){try{const H=await fetch(`/api/session?cwd=${encodeURIComponent(v)}&filename=${encodeURIComponent(T)}`);if(!H.ok)return;const $=await H.json(),ft=Ma($);ue.current=Oa(ft),m(ft)}catch{}}async function Uu(v,T,H){const $=await fetch(`/api/session?cwd=${encodeURIComponent(v)}&filename=${encodeURIComponent(T)}`,{signal:H});if(!$.ok)return;const ft=await $.json(),I=Ma(ft),ut=Oa(I);ut!==ue.current&&(ue.current=ut,m(I),Ie())}function Pe(){m([]),R(""),ke.current=null,y(!1),bt(null),ue.current=null,Se.current&&window.clearTimeout(Se.current)}async function te(v,T){if(Ll.current&&ve.current?.sessionFile===T&&ve.current?.cwd===v){be.current?.focus();return}Pe(),await Du(v,T),fl(v,T)&&(ce(120),Fe()),be.current?.focus()}function he(v){if(Ll.current&&ve.current?.sessionFile===null&&ve.current?.cwd===v){be.current?.focus();return}Pe(),fl(v,null)&&(ce(120),Fe()),be.current?.focus()}E.useEffect(()=>{if(!X||Z==null)return;if(Pt){he(X);return}if(!(!lt||!s.some(T=>T.cwd===X&&T.file===lt))){if(za.current){za.current=!1,ve.current={cwd:X,sessionFile:lt};return}te(X,lt)}},[lt,Pt,X,Z,s]);function Gl(v){const T=ul.current.find(H=>H.file===v)?.cwd;T&&i(qm(T,v))}function Na(v){i(rp(v))}function ic(v){i(xu(v))}function cc(v){i($i(v))}function ju(){if(!q||!Y||q===Y)return;const v=q.split("/").filter(Boolean),T=v.length<=1?"/":`/${v.slice(0,-1).join("/")}`;i($i(T))}function En(){q&&ic(q)}function Qn(){i($i(X??q))}function Xl(){if(!X){i($i(q));return}i(xu(X))}function yl(){const v=C.trim();if(!v||!b||!L)return;if(R(""),S){Q(H=>[...H,v]);return}Yt({type:"rpc_command",command:{type:"prompt",message:v,id:`web-${Date.now()}`}})&&Pt&&X&&Sn(X)}function xn(){Yt({type:"rpc_command",command:{type:"abort",id:`abort-${Date.now()}`}})}function Ql(v){Lt(v)}function Jt(v){const T=gt.find(H=>H.id===v&&H.provider===ae);T&&Yt({type:"rpc_command",command:{type:"set_model",provider:T.provider,modelId:T.id,id:"set_model"}})}function Hu(v){const T=Tu(v);T&&(me(T),Yt({type:"rpc_command",command:{type:"set_thinking_level",level:T,id:"set_thinking_level"}}))}async function Bu(v){const T=ul.current.find($=>$.file===v)?.cwd??X??"";try{await fetch(`/api/session?cwd=${encodeURIComponent(T)}&filename=${encodeURIComponent(v)}`,{method:"DELETE"})}catch{}f($=>$.filter(ft=>ft.file!==v));const H=X??ul.current.find($=>$.file===v)?.cwd;qn.current===v&&(m([]),R(""),ke.current=null,y(!1),V(!1),bt(null),i(H?xu(H):"/"))}const vl=S?"streaming response":"session status";return w.jsxs("div",{className:"flex flex-col h-full bg-pi-page-bg text-gray-900 text-sm font-mono overflow-hidden",children:[Qt&&w.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-5 md:px-6",children:w.jsx(pp,{cwd:q,folders:ct,isLoading:_t,error:jt,canNavigateUp:Yn,onBrowseIntoFolder:cc,onBrowseToParent:ju,onOpenCurrentFolder:En})}),Mt&&X&&w.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-5 md:px-6",children:w.jsx(gp,{projectCwd:X,sessions:Gn,onBack:Qn,onCreateSession:()=>Na(X),onSelectSession:Gl,onDeleteSession:Bu})}),Mt&&!X&&w.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-5 md:px-6",children:w.jsxs("div",{className:"mx-auto max-w-3xl rounded-xl border border-pi-border-muted bg-pi-card-bg p-4",children:[w.jsx("div",{className:"text-sm text-pi-muted mb-3",children:"no folder selected"}),w.jsx("button",{onClick:Qn,className:"px-3 py-1.5 rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:"choose folder"})]})}),Ae&&w.jsxs("main",{className:"flex-1 flex flex-col min-h-0",children:[w.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 md:px-6 border-b border-pi-border-muted bg-pi-card-bg",children:[w.jsxs("div",{className:"min-w-0",children:[w.jsx("div",{className:"text-[11px] text-pi-dim truncate",children:X?fp(X):"folder not selected"}),w.jsx("div",{className:"text-xs truncate text-pi-muted",children:lt?lt.split("/").pop():"new session"})]}),w.jsx("button",{onClick:Xl,title:"back to sessions",className:"ml-auto inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w.jsx("polyline",{points:"10.5,3 5,8 10.5,13"})})})]}),w.jsx("div",{ref:Me,className:"flex-1 overflow-y-auto px-4 py-2 md:px-6",children:d.length===0?w.jsx("div",{className:"flex items-center justify-center h-full text-pi-muted text-base",children:"choose a session and start prompting."}):d.filter(v=>(v.role==="user"||v.role==="assistant")&&(v.role==="user"||v.parts.some(T=>T.type==="tool"||T.type==="text"&&(T.content??"").trim()))).map(v=>w.jsx(vp,{msg:v},v.id))}),w.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 md:px-6 border-t border-pi-border-muted bg-pi-card-bg text-xs text-pi-muted flex-wrap",children:[gt.length>0&&w.jsxs("span",{className:"flex items-center gap-1.5",children:[w.jsx("select",{value:ae,onChange:v=>Ql(v.target.value),disabled:S,className:"font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 select-fit-content",children:cl.map(v=>w.jsx("option",{value:v,children:v},v))}),w.jsx("select",{value:nc,onChange:v=>Jt(v.target.value),disabled:S,className:"font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 select-fit-content",children:pe.map(v=>w.jsx("option",{value:v.id,children:v.id},v.id))})]}),gt.length===0&&Ut&&w.jsx("span",{children:Ut.id}),L&&(gt.length>0||Ut)&&w.jsx("select",{value:qt,onChange:v=>Hu(v.target.value),disabled:!b||S||Ut?.reasoning===!1,"aria-label":"thinking level",title:"thinking level",className:"font-mono text-gray-700 bg-white border border-pi-border-muted rounded px-1 py-0.5 cursor-pointer disabled:opacity-50 select-fit-content",children:ac.map(v=>w.jsx("option",{value:v,children:v},v))}),W&&w.jsxs("span",{className:"flex items-center gap-2 text-pi-dim ml-auto flex-wrap",children:[W.tokens.input>0&&w.jsxs("span",{children:["↑",Ru(W.tokens.input)]}),W.tokens.output>0&&w.jsxs("span",{children:["↓",Ru(W.tokens.output)]}),W.tokens.cacheRead>0&&w.jsxs("span",{children:["r",Ru(W.tokens.cacheRead)]}),W.tokens.cacheWrite>0&&w.jsxs("span",{children:["w",Ru(W.tokens.cacheWrite)]}),W.cost>0&&w.jsxs("span",{children:["$",W.cost.toFixed(3)]}),Ut?.contextWindow&&Cu&&(()=>{const v=Cu/Ut.contextWindow*100,T=v>90?"text-pi-error":v>70?"text-pi-warning":"";return w.jsxs("span",{className:T,children:[v.toFixed(1),"%/",Ru(Ut.contextWindow)]})})()]}),S&&w.jsxs("span",{children:["responding",N.length>0?` · ${N.length} queued`:""]})]}),w.jsx("div",{className:"px-4 pb-4 pt-3 md:px-6 border-t border-pi-border-muted bg-pi-card-bg",children:w.jsxs("div",{className:"flex gap-2 items-center",children:[w.jsx("span",{className:"sr-only","aria-live":"polite",children:vl}),w.jsx("textarea",{ref:be,rows:1,placeholder:L?"send a message...":"create or select a session",disabled:!L,value:C,onChange:v=>R(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),yl())},className:"prompt-input flex-1 bg-white border border-pi-border-muted rounded-lg px-3 py-2.5 font-mono resize-none min-h-[42px] max-h-[200px] outline-none focus:border-pi-accent disabled:opacity-50 disabled:cursor-default"}),w.jsxs("div",{className:"flex flex-row gap-1 flex-shrink-0",children:[w.jsxs("button",{onClick:yl,disabled:!b||!L,title:S?"queue message":"send","aria-label":S?"queue message":"send message",className:"relative h-[42px] aspect-square inline-flex items-center justify-center flex-shrink-0 rounded-lg bg-pi-accent text-white cursor-pointer hover:opacity-90 disabled:opacity-40 disabled:cursor-default disabled:bg-pi-border-muted",children:[w.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[w.jsx("line",{x1:"2",y1:"9",x2:"16",y2:"9"}),w.jsx("polyline",{points:"10,3 16,9 10,15"})]}),N.length>0&&w.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:N.length})]}),w.jsx("button",{onClick:xn,disabled:!S||!L,title:"stop",className:"h-[42px] aspect-square inline-flex items-center justify-center flex-shrink-0 rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:w.jsx("svg",{width:"20",height:"20",viewBox:"0 0 18 18",fill:"currentColor",children:w.jsx("rect",{x:"4",y:"4",width:"10",height:"10",rx:"1.5"})})})]})]})})]})]})}function vp({msg:i}){const r=i.role==="user",s=i.parts.some(m=>m.type==="text"&&!!(m.content??"").trim()),f=i.parts.some(m=>m.type==="tool"),d=!r&&f&&!s;return w.jsx("div",{className:"mb-2 min-w-0",children:w.jsx("div",{className:`rounded-lg ${d?"p-0":"px-2 py-1.5"} min-w-0 overflow-hidden ${r?"bg-pi-user-bg":"bg-pi-card-bg border border-pi-border-muted"}`,children:w.jsx("div",{className:"text-xs md:text-sm leading-relaxed break-words min-w-0",children:i.parts.map((m,b)=>w.jsx(bp,{part:m},`${i.id}-${b}`))})})})}function pp({cwd:i,folders:r,isLoading:s,error:f,canNavigateUp:d,onBrowseIntoFolder:m,onBrowseToParent:b,onOpenCurrentFolder:M}){return w.jsxs("div",{className:"mx-auto max-w-3xl",children:[w.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[w.jsxs("div",{className:"min-w-0",children:[w.jsx("h1",{className:"text-base md:text-lg font-semibold text-pi-accent",children:"browse folders"}),w.jsx("p",{className:"text-pi-muted mt-1 truncate",title:i??"",children:i?Ta(i):"loading…"})]}),w.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[w.jsx("button",{onClick:M,disabled:!i,title:"open current folder","aria-label":"open current folder",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:w.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[w.jsx("path",{d:"M1.5 6.1V4.8a1 1 0 0 1 1-1h3l1.3 1.3h6.7a1 1 0 0 1 1 1v.8"}),w.jsx("path",{d:"M1.5 6.9h13l-1.2 5.2a1 1 0 0 1-1 .8H3.7a1 1 0 0 1-1-.8L1.5 6.9Z"})]})}),w.jsx("button",{onClick:b,disabled:!d,title:"back",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer disabled:opacity-40 disabled:cursor-default",children:w.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w.jsx("polyline",{points:"10.5,3 5,8 10.5,13"})})})]})]}),w.jsxs("div",{className:"rounded-xl border border-pi-border-muted bg-pi-card-bg",children:[s&&w.jsx("div",{className:"px-4 py-6 text-center text-pi-muted",children:"loading folders…"}),!s&&f&&w.jsx("div",{className:"px-4 py-6 text-center text-pi-error",children:f}),!s&&!f&&r.length===0&&w.jsx("div",{className:"px-4 py-6 text-center text-pi-muted",children:"no visible folders here."}),!s&&!f&&r.length>0&&w.jsx("div",{className:"divide-y divide-pi-border-muted",children:r.map(S=>w.jsx("button",{onClick:()=>m(S.path),className:"w-full text-left px-4 py-3 hover:bg-pi-user-bg cursor-pointer",title:S.path,children:w.jsx("div",{className:"text-sm text-gray-800 truncate",children:S.name})},S.path))})]})]})}function gp({projectCwd:i,sessions:r,onBack:s,onCreateSession:f,onSelectSession:d,onDeleteSession:m}){return w.jsxs("div",{className:"mx-auto max-w-3xl",children:[w.jsxs("div",{className:"mb-4 flex items-start gap-3 justify-between",children:[w.jsxs("div",{className:"min-w-0",children:[w.jsx("h1",{className:"text-base md:text-lg font-semibold text-pi-accent",children:"choose a session"}),w.jsx("p",{className:"text-pi-muted mt-1 truncate",title:i,children:i})]}),w.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[w.jsx("button",{onClick:f,title:"new session",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[w.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"13"}),w.jsx("line",{x1:"3",y1:"8",x2:"13",y2:"8"})]})}),w.jsx("button",{onClick:s,title:"back to folders",className:"inline-flex items-center justify-center h-10 w-10 shrink-0 aspect-square rounded-lg border border-pi-border-muted text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsx("svg",{width:"18",height:"18",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w.jsx("polyline",{points:"10.5,3 5,8 10.5,13"})})})]})]}),r.length===0?w.jsx("div",{className:"rounded-xl border border-dashed border-pi-border-muted bg-pi-card-bg px-4 py-6 text-center text-pi-muted",children:"no sessions in this folder yet."}):w.jsx("div",{className:"space-y-2",children:r.map(b=>{const M=b.firstPrompt||b.id.slice(0,8),S=b.timestamp?new Date(b.timestamp).toLocaleString():"",y=!!b.isWorking,C=!!b.isActive,R=y?"working":C?"active":"idle",L=y?"bg-pi-success animate-pulse-dot":C?"bg-pi-accent":"bg-pi-border-muted";return w.jsxs("div",{className:"group relative w-full text-left rounded-xl border border-pi-border-muted bg-pi-card-bg px-4 py-3 hover:bg-pi-user-bg",children:[w.jsxs("button",{onClick:()=>d(b.file),className:"w-full text-left cursor-pointer",children:[w.jsx("div",{className:"text-sm text-gray-800 truncate pr-8",children:M}),w.jsxs("div",{className:"text-[11px] text-pi-muted mt-1 flex items-center gap-1.5 flex-wrap",children:[w.jsxs("span",{children:[b.messageCount," msgs"]}),w.jsx("span",{children:"·"}),w.jsx("span",{children:S}),w.jsx("span",{children:"·"}),w.jsxs("span",{className:"inline-flex items-center gap-1",children:[w.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${L}`}),R]})]})]}),w.jsx("button",{onClick:()=>m(b.file),title:"delete session",className:"absolute top-3 right-3 hidden group-hover:inline-flex items-center justify-center w-6 h-6 rounded text-pi-muted hover:text-pi-accent hover:bg-pi-user-bg cursor-pointer",children:w.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[w.jsx("line",{x1:"1.5",y1:"1.5",x2:"8.5",y2:"8.5"}),w.jsx("line",{x1:"8.5",y1:"1.5",x2:"1.5",y2:"8.5"})]})})]},b.file)})})]})}function bp({part:i}){return i.type==="text"?w.jsx("div",{dangerouslySetInnerHTML:{__html:Ep(i.content||"")}}):i.type==="thinking"?null:i.type==="tool"?w.jsx(Sp,{part:i}):null}function Sp({part:i}){const r=E.useMemo(()=>hp(i),[i]),s=i.name==="edit"?"":"max-h-64",f=i.name==="edit"?"overflow-x-auto":"overflow-auto";return w.jsx("div",{className:`my-0 px-1.5 py-1 text-xs overflow-hidden ${i.done?i.isError?"bg-pi-tool-error":"bg-pi-tool-success":"bg-pi-tool-pending"}`,children:w.jsx("pre",{className:`tool-io-pre ${s} ${f} ${i.isError?"text-pi-error":"text-pi-tool-output"}`,children:r})})}function Ep(i){const r=i.split(`
46
46
  `),s=[];let f=0;for(;f<r.length;){const d=r[f];if(/^```/.test(d)){const b=d.slice(3).trim(),M=[];for(f++;f<r.length&&!/^```/.test(r[f]);)M.push(Ar(r[f])),f++;s.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${b?` class="language-${Ar(b)}"`:""}>${M.join(`
47
47
  `)}</code></pre>`),f++;continue}if(/^\|/.test(d)&&f+1<r.length&&/^\|[\s\-:|]+\|/.test(r[f+1])){const b=Qm(r[f]),M=xp(r[f+1]);f+=2;const S=[];for(;f<r.length&&/^\|/.test(r[f]);)S.push(Qm(r[f])),f++;const y=b.map((R,L)=>`<th class="border border-pi-border-muted px-3 py-1.5 bg-pi-page-bg font-semibold text-left" style="${Zm(M[L])}">${ki(R)}</th>`).join(""),C=S.map(R=>`<tr>${R.map((L,V)=>`<td class="border border-pi-border-muted px-3 py-1.5" style="${Zm(M[V])}">${ki(L)}</td>`).join("")}</tr>`).join("");s.push(`<div class="overflow-x-auto my-2"><table class="border-collapse text-xs w-full"><thead><tr>${y}</tr></thead><tbody>${C}</tbody></table></div>`);continue}const m=d.match(/^(#{1,6})\s+(.*)/);if(m){const b=m[1].length,M=["text-lg","text-base","text-sm","text-sm","text-xs","text-xs"];s.push(`<h${b} class="font-semibold ${M[b-1]} mt-3 mb-1 text-pi-md-heading">${ki(m[2])}</h${b}>`),f++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(d.trim())){s.push('<hr class="border-t border-pi-border-muted my-3">'),f++;continue}if(d.trim()===""){s.push("<br>"),f++;continue}s.push(`<span>${ki(d)}</span><br>`),f++}return s.join("")}function Qm(i){return i.replace(/^\||\|$/g,"").split("|").map(r=>r.trim())}function xp(i){return i.replace(/^\||\|$/g,"").split("|").map(r=>(r=r.trim(),r.startsWith(":")&&r.endsWith(":")?"center":r.endsWith(":")?"right":"left"))}function Zm(i){return`text-align:${i}`}function ki(i){let r=Ar(i);return r=r.replace(/`([^`]+)`/g,'<code class="bg-pi-page-bg text-pi-md-code px-1 py-0.5 rounded text-xs font-mono">$1</code>'),r=r.replace(/\*\*\*([^*]+)\*\*\*/g,"<strong><em>$1</em></strong>"),r=r.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),r=r.replace(/\*([^*\n]+)\*/g,"<em>$1</em>"),r=r.replace(/~~([^~]+)~~/g,"<del class='opacity-60'>$1</del>"),r=r.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener" class="text-pi-md-link underline">$1</a>'),r}function Ar(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Tp(i){if(!i)return 0;if(typeof i.totalTokens=="number"&&Number.isFinite(i.totalTokens))return i.totalTokens;const r=typeof i.input=="number"&&Number.isFinite(i.input)?i.input:0,s=typeof i.output=="number"&&Number.isFinite(i.output)?i.output:0,f=typeof i.cacheRead=="number"&&Number.isFinite(i.cacheRead)?i.cacheRead:0,d=typeof i.cacheWrite=="number"&&Number.isFinite(i.cacheWrite)?i.cacheWrite:0;return r+s+f+d}function Vm(i){let r=0;for(const s of i.parts){if(s.type==="text"||s.type==="thinking"){r+=(s.content??"").length;continue}if(s.type==="tool"&&(r+=(s.name??"").length,r+=(s.content??"").length,s.args!=null))try{r+=JSON.stringify(s.args).length}catch{}}return Math.ceil(r/4)}function Rp(i){for(let s=i.length-1;s>=0;s--){const f=i[s];if(f.role!=="assistant")continue;const d=Tp(f.usage);if(d<=0)continue;let m=0;for(let b=s+1;b<i.length;b++)m+=Vm(i[b]);return d+m}const r=i.reduce((s,f)=>s+Vm(f),0);return r>0?r:null}function Ru(i){return i<1e3?String(i):i<1e4?`${(i/1e3).toFixed(1)}k`:i<1e6?`${Math.round(i/1e3)}k`:i<1e7?`${(i/1e6).toFixed(1)}m`:`${Math.round(i/1e6)}m`}N0.createRoot(document.getElementById("root")).render(w.jsx(T0.StrictMode,{children:w.jsx(Fv,{children:w.jsx(yp,{})})}));
@@ -1 +1 @@
1
- @import"https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap";@layer components;@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-gray-700:oklch(37.3% .034 259.733);--color-gray-800:oklch(27.8% .033 256.848);--color-gray-900:oklch(21% .034 264.665);--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75 / 1.125);--font-weight-semibold:600;--leading-relaxed:1.625;--radius-lg:.5rem;--radius-xl:.75rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-pi-accent:#5a8080;--color-pi-border-muted:#b0b0b0;--color-pi-success:#588458;--color-pi-error:#a55;--color-pi-warning:#9a7326;--color-pi-muted:#6c6c6c;--color-pi-dim:#767676;--color-pi-user-bg:#e8e8e8;--color-pi-tool-pending:#e8e8f0;--color-pi-tool-success:#e8f0e8;--color-pi-tool-error:#f0e8e8;--color-pi-md-heading:#9a7326;--color-pi-md-link:#547da7;--color-pi-md-code:#5a8080;--color-pi-md-code-block:#588458;--color-pi-tool-output:#6c6c6c;--color-pi-page-bg:#f8f8f8;--color-pi-card-bg:#fff}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer utilities{.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.relative{position:relative}.start{inset-inline-start:var(--spacing)}.-top-1\.5{top:calc(var(--spacing) * -1.5)}.top-3{top:calc(var(--spacing) * 3)}.-right-1\.5{right:calc(var(--spacing) * -1.5)}.right-3{right:calc(var(--spacing) * 3)}.mx-auto{margin-inline:auto}.my-0{margin-block:calc(var(--spacing) * 0)}.my-2{margin-block:calc(var(--spacing) * 2)}.my-3{margin-block:calc(var(--spacing) * 3)}.mt-1{margin-top:calc(var(--spacing) * 1)}.mt-3{margin-top:calc(var(--spacing) * 3)}.mb-1{margin-bottom:calc(var(--spacing) * 1)}.mb-2{margin-bottom:calc(var(--spacing) * 2)}.mb-3{margin-bottom:calc(var(--spacing) * 3)}.mb-4{margin-bottom:calc(var(--spacing) * 4)}.ml-auto{margin-left:auto}.block{display:block}.contents{display:contents}.flex{display:flex}.hidden{display:none}.inline-flex{display:inline-flex}.aspect-square{aspect-ratio:1}.h-1\.5{height:calc(var(--spacing) * 1.5)}.h-4{height:calc(var(--spacing) * 4)}.h-6{height:calc(var(--spacing) * 6)}.h-10{height:calc(var(--spacing) * 10)}.h-\[42px\]{height:42px}.h-full{height:100%}.max-h-64{max-height:calc(var(--spacing) * 64)}.max-h-\[200px\]{max-height:200px}.min-h-0{min-height:calc(var(--spacing) * 0)}.min-h-\[42px\]{min-height:42px}.w-1\.5{width:calc(var(--spacing) * 1.5)}.w-4{width:calc(var(--spacing) * 4)}.w-6{width:calc(var(--spacing) * 6)}.w-10{width:calc(var(--spacing) * 10)}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.min-w-0{min-width:calc(var(--spacing) * 0)}.flex-1{flex:1}.flex-shrink-0,.shrink-0{flex-shrink:0}.border-collapse{border-collapse:collapse}.cursor-pointer{cursor:pointer}.resize-none{resize:none}.flex-col{flex-direction:column}.flex-row{flex-direction:row}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-1{gap:calc(var(--spacing) * 1)}.gap-1\.5{gap:calc(var(--spacing) * 1.5)}.gap-2{gap:calc(var(--spacing) * 2)}.gap-3{gap:calc(var(--spacing) * 3)}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)))}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px * var(--tw-divide-y-reverse));border-bottom-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-pi-border-muted>:not(:last-child)){border-color:var(--color-pi-border-muted)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-xl{border-radius:var(--radius-xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-pi-border-muted{border-color:var(--color-pi-border-muted)}.bg-pi-accent{background-color:var(--color-pi-accent)}.bg-pi-border-muted{background-color:var(--color-pi-border-muted)}.bg-pi-card-bg{background-color:var(--color-pi-card-bg)}.bg-pi-page-bg{background-color:var(--color-pi-page-bg)}.bg-pi-success{background-color:var(--color-pi-success)}.bg-pi-tool-error{background-color:var(--color-pi-tool-error)}.bg-pi-tool-pending{background-color:var(--color-pi-tool-pending)}.bg-pi-tool-success{background-color:var(--color-pi-tool-success)}.bg-pi-user-bg{background-color:var(--color-pi-user-bg)}.bg-pi-warning{background-color:var(--color-pi-warning)}.bg-white{background-color:var(--color-white)}.p-0{padding:calc(var(--spacing) * 0)}.p-3{padding:calc(var(--spacing) * 3)}.p-4{padding:calc(var(--spacing) * 4)}.px-1{padding-inline:calc(var(--spacing) * 1)}.px-1\.5{padding-inline:calc(var(--spacing) * 1.5)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.py-0\.5{padding-block:calc(var(--spacing) * .5)}.py-1{padding-block:calc(var(--spacing) * 1)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-2\.5{padding-block:calc(var(--spacing) * 2.5)}.py-3{padding-block:calc(var(--spacing) * 3)}.py-5{padding-block:calc(var(--spacing) * 5)}.py-6{padding-block:calc(var(--spacing) * 6)}.pt-3{padding-top:calc(var(--spacing) * 3)}.pr-8{padding-right:calc(var(--spacing) * 8)}.pb-4{padding-bottom:calc(var(--spacing) * 4)}.text-center{text-align:center}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.leading-none{--tw-leading:1;line-height:1}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.break-words{overflow-wrap:break-word}.text-gray-700{color:var(--color-gray-700)}.text-gray-800{color:var(--color-gray-800)}.text-gray-900{color:var(--color-gray-900)}.text-pi-accent{color:var(--color-pi-accent)}.text-pi-dim{color:var(--color-pi-dim)}.text-pi-error{color:var(--color-pi-error)}.text-pi-md-code{color:var(--color-pi-md-code)}.text-pi-md-code-block{color:var(--color-pi-md-code-block)}.text-pi-md-heading{color:var(--color-pi-md-heading)}.text-pi-md-link{color:var(--color-pi-md-link)}.text-pi-muted{color:var(--color-pi-muted)}.text-pi-tool-output{color:var(--color-pi-tool-output)}.text-pi-warning{color:var(--color-pi-warning)}.text-white{color:var(--color-white)}.underline{text-decoration-line:underline}.opacity-60{opacity:.6}.outline-none{--tw-outline-style:none;outline-style:none}@media(hover:hover){.group-hover\:inline-flex:is(:where(.group):hover *){display:inline-flex}.hover\:bg-pi-user-bg:hover{background-color:var(--color-pi-user-bg)}.hover\:text-pi-accent:hover{color:var(--color-pi-accent)}}.focus\:border-pi-accent:focus{border-color:var(--color-pi-accent)}.disabled\:cursor-default:disabled{cursor:default}.disabled\:opacity-40:disabled{opacity:.4}.disabled\:opacity-50:disabled{opacity:.5}@media(min-width:48rem){.md\:px-6{padding-inline:calc(var(--spacing) * 6)}.md\:text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.md\:text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}}}html,body,#root{height:100dvh;overflow:hidden}*,:before,:after{font-family:JetBrains Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace!important;font-size:14px!important}@supports (-webkit-touch-callout:none){.prompt-input{font-size:16px!important}}@keyframes pulse-dot{0%,to{opacity:1}50%{opacity:.4}}.animate-pulse-dot{animation:1s infinite pulse-dot}.select-fit-content{field-sizing:content}.tool-io-pre{white-space:pre;tab-size:4;margin:0;line-height:1.3;overflow-x:auto}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}
1
+ @import"https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap";@layer components;@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-gray-700:oklch(37.3% .034 259.733);--color-gray-800:oklch(27.8% .033 256.848);--color-gray-900:oklch(21% .034 264.665);--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75 / 1.125);--font-weight-semibold:600;--leading-relaxed:1.625;--radius-lg:.5rem;--radius-xl:.75rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono);--color-pi-accent:#5a8080;--color-pi-border-muted:#b0b0b0;--color-pi-success:#588458;--color-pi-error:#a55;--color-pi-warning:#9a7326;--color-pi-muted:#6c6c6c;--color-pi-dim:#767676;--color-pi-user-bg:#e8e8e8;--color-pi-tool-pending:#e8e8f0;--color-pi-tool-success:#e8f0e8;--color-pi-tool-error:#f0e8e8;--color-pi-md-heading:#9a7326;--color-pi-md-link:#547da7;--color-pi-md-code:#5a8080;--color-pi-md-code-block:#588458;--color-pi-tool-output:#6c6c6c;--color-pi-page-bg:#f8f8f8;--color-pi-card-bg:#fff}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer utilities{.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.relative{position:relative}.start{inset-inline-start:var(--spacing)}.-top-1\.5{top:calc(var(--spacing) * -1.5)}.top-3{top:calc(var(--spacing) * 3)}.-right-1\.5{right:calc(var(--spacing) * -1.5)}.right-3{right:calc(var(--spacing) * 3)}.mx-auto{margin-inline:auto}.my-0{margin-block:calc(var(--spacing) * 0)}.my-2{margin-block:calc(var(--spacing) * 2)}.my-3{margin-block:calc(var(--spacing) * 3)}.mt-1{margin-top:calc(var(--spacing) * 1)}.mt-3{margin-top:calc(var(--spacing) * 3)}.mb-1{margin-bottom:calc(var(--spacing) * 1)}.mb-2{margin-bottom:calc(var(--spacing) * 2)}.mb-3{margin-bottom:calc(var(--spacing) * 3)}.mb-4{margin-bottom:calc(var(--spacing) * 4)}.ml-auto{margin-left:auto}.block{display:block}.contents{display:contents}.flex{display:flex}.hidden{display:none}.inline-flex{display:inline-flex}.aspect-square{aspect-ratio:1}.h-1\.5{height:calc(var(--spacing) * 1.5)}.h-4{height:calc(var(--spacing) * 4)}.h-6{height:calc(var(--spacing) * 6)}.h-10{height:calc(var(--spacing) * 10)}.h-\[42px\]{height:42px}.h-full{height:100%}.max-h-64{max-height:calc(var(--spacing) * 64)}.max-h-\[200px\]{max-height:200px}.min-h-0{min-height:calc(var(--spacing) * 0)}.min-h-\[42px\]{min-height:42px}.w-1\.5{width:calc(var(--spacing) * 1.5)}.w-4{width:calc(var(--spacing) * 4)}.w-6{width:calc(var(--spacing) * 6)}.w-10{width:calc(var(--spacing) * 10)}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.min-w-0{min-width:calc(var(--spacing) * 0)}.flex-1{flex:1}.flex-shrink-0,.shrink-0{flex-shrink:0}.border-collapse{border-collapse:collapse}.cursor-pointer{cursor:pointer}.resize-none{resize:none}.flex-col{flex-direction:column}.flex-row{flex-direction:row}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-1{gap:calc(var(--spacing) * 1)}.gap-1\.5{gap:calc(var(--spacing) * 1.5)}.gap-2{gap:calc(var(--spacing) * 2)}.gap-3{gap:calc(var(--spacing) * 3)}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)))}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px * var(--tw-divide-y-reverse));border-bottom-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-pi-border-muted>:not(:last-child)){border-color:var(--color-pi-border-muted)}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.rounded{border-radius:.25rem}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-xl{border-radius:var(--radius-xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-pi-border-muted{border-color:var(--color-pi-border-muted)}.bg-pi-accent{background-color:var(--color-pi-accent)}.bg-pi-border-muted{background-color:var(--color-pi-border-muted)}.bg-pi-card-bg{background-color:var(--color-pi-card-bg)}.bg-pi-page-bg{background-color:var(--color-pi-page-bg)}.bg-pi-success{background-color:var(--color-pi-success)}.bg-pi-tool-error{background-color:var(--color-pi-tool-error)}.bg-pi-tool-pending{background-color:var(--color-pi-tool-pending)}.bg-pi-tool-success{background-color:var(--color-pi-tool-success)}.bg-pi-user-bg{background-color:var(--color-pi-user-bg)}.bg-pi-warning{background-color:var(--color-pi-warning)}.bg-white{background-color:var(--color-white)}.p-0{padding:calc(var(--spacing) * 0)}.p-3{padding:calc(var(--spacing) * 3)}.p-4{padding:calc(var(--spacing) * 4)}.px-1{padding-inline:calc(var(--spacing) * 1)}.px-1\.5{padding-inline:calc(var(--spacing) * 1.5)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.py-0\.5{padding-block:calc(var(--spacing) * .5)}.py-1{padding-block:calc(var(--spacing) * 1)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-2\.5{padding-block:calc(var(--spacing) * 2.5)}.py-3{padding-block:calc(var(--spacing) * 3)}.py-5{padding-block:calc(var(--spacing) * 5)}.py-6{padding-block:calc(var(--spacing) * 6)}.pt-3{padding-top:calc(var(--spacing) * 3)}.pr-8{padding-right:calc(var(--spacing) * 8)}.pb-4{padding-bottom:calc(var(--spacing) * 4)}.text-center{text-align:center}.text-left{text-align:left}.font-mono{font-family:var(--font-mono)}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.leading-none{--tw-leading:1;line-height:1}.leading-relaxed{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.break-words{overflow-wrap:break-word}.text-gray-700{color:var(--color-gray-700)}.text-gray-800{color:var(--color-gray-800)}.text-gray-900{color:var(--color-gray-900)}.text-pi-accent{color:var(--color-pi-accent)}.text-pi-dim{color:var(--color-pi-dim)}.text-pi-error{color:var(--color-pi-error)}.text-pi-md-code{color:var(--color-pi-md-code)}.text-pi-md-code-block{color:var(--color-pi-md-code-block)}.text-pi-md-heading{color:var(--color-pi-md-heading)}.text-pi-md-link{color:var(--color-pi-md-link)}.text-pi-muted{color:var(--color-pi-muted)}.text-pi-tool-output{color:var(--color-pi-tool-output)}.text-pi-warning{color:var(--color-pi-warning)}.text-white{color:var(--color-white)}.underline{text-decoration-line:underline}.opacity-60{opacity:.6}.outline-none{--tw-outline-style:none;outline-style:none}@media(hover:hover){.group-hover\:inline-flex:is(:where(.group):hover *){display:inline-flex}.hover\:bg-pi-user-bg:hover{background-color:var(--color-pi-user-bg)}.hover\:text-pi-accent:hover{color:var(--color-pi-accent)}.hover\:opacity-90:hover{opacity:.9}}.focus\:border-pi-accent:focus{border-color:var(--color-pi-accent)}.disabled\:cursor-default:disabled{cursor:default}.disabled\:bg-pi-border-muted:disabled{background-color:var(--color-pi-border-muted)}.disabled\:opacity-40:disabled{opacity:.4}.disabled\:opacity-50:disabled{opacity:.5}@media(min-width:48rem){.md\:px-6{padding-inline:calc(var(--spacing) * 6)}.md\:text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.md\:text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}}}html,body,#root{height:100dvh;overflow:hidden}*,:before,:after{font-family:JetBrains Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace!important;font-size:14px!important}@supports (-webkit-touch-callout:none){.prompt-input{font-size:16px!important}}@keyframes pulse-dot{0%,to{opacity:1}50%{opacity:.4}}.animate-pulse-dot{animation:1s infinite pulse-dot}.select-fit-content{field-sizing:content}.tool-io-pre{white-space:pre;tab-size:4;margin:0;line-height:1.3;overflow-x:auto}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}
package/dist/index.html CHANGED
@@ -4,8 +4,8 @@
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-D-KYGr4y.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-CMCFrtRl.css">
7
+ <script type="module" crossorigin src="/assets/index-B-29upR4.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/assets/index-o3qAYI0D.css">
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": "^24"