1import{j as o,A as tt,m as nt}from"./vendor-motion-hRg_q8lq.js";import{du as w}from"./vendor-fa-Bn2dnpnC.js";import{r as l}from"./vendor-react-E98sgxjj.js";import{u as X,b0 as Jt,d as y,b1 as Zt,l as Qt,cS as en,cT as He,cU as ot,cV as rt,cW as st,bO as tn,cX as nn,bP as Et,cY as on,cZ as rn,bR as sn,c_ as cn,c$ as an,d0 as ln,d1 as un}from"./index-BKzE8EQ8.js";import{M as jt}from"./Markdown-BgzYVg9N.js";import{T as dn}from"./Tooltip-C8AvPGtA.js";import{J as fn,K as mn,L as hn}from"./StudioContext-C1fnzqLL.js";import{a as xn}from"./useOrchestrationEnabled-BWYxrOff.js";import{S as vt}from"./StreamingWords-Ds3Ch0UQ.js";import{A as _e}from"./ActivityGrid-DDQeSjer.js";function pn(e){const[t,n]=l.useState(()=>Date.now());return l.useEffect(()=>{const r=setInterval(()=>n(Date.now()),6e4);return()=>clearInterval(r)},[]),l.useMemo(()=>{if(!e)return null;const r=Date.parse(e);if(Number.isNaN(r))return null;const c=Math.max(0,r-t),s=Math.floor(c/6e4),i=Math.floor(s/60),a=s%60;return i>=1?`${i}h ${a}m`:`${a}m`},[e,t])}function Ko({isFreeUser:e,usage:t,onUpgrade:n,className:r,align:c="center"}){const{t:s}=X("studio"),i=pn(t?.daily_resets_at??null);if(!e)return null;const a=Jt(t),m=a<=0,d=a>0&&a<Zt,h=t?.daily_credits_enabled!==!1,x=!h&&(t?.bonus_credits??0)>0;let u,f;return x?(f=d||m?"clock":"rocket",m?u=s("upsell.topupOutOfCredits"):d?u=s("upsell.topupLowCredits"):u=s("upsell.topupPlentyCredits")):h?m?(f="clock",u=i?s("upsell.outOfCredits",{countdown:i}):s("upsell.outOfCreditsNoCountdown")):d?(f="clock",u=i?s("upsell.lowCredits",{countdown:i}):s("upsell.lowCreditsNoCountdown")):(f="rocket",u=s("upsell.proUnlock")):(f="lock",u=s("upsell.proUnlockNormal")),o.jsxs("p",{className:y("text-sm text-muted-foreground",c==="center"?"text-center":"text-left",r),children:[o.jsx(w,{icon:["far",f],className:"mr-1.5"}),u,o.jsx("button",{type:"button",onClick:n,className:"text-foreground underline hover:text-foreground/80 cursor-pointer transition-all ml-2",children:s("upsell.upgradeCta")})]})}function gn({info:e,guideModel:t,className:n}){if(!xn()||!e?.route)return null;const c=fn(e,{guideModel:t});return o.jsx(dn,{content:c.length?o.jsx("div",{className:"text-left space-y-0.5",children:c.map(s=>o.jsx("div",{children:s},s))}):null,delay:150,children:o.jsx("span",{"data-testid":"route-badge",className:y("inline-flex items-center rounded-full border px-2 py-0.5","text-[10px] font-medium leading-none whitespace-nowrap","text-violet-400 bg-violet-400/10 border-violet-400/30",n),children:mn(e,{guideModel:t})})})}function zo({answer:e,proposal:t,proposalLabel:n,orchestration:r,guideModel:c,onPropose:s,onDismiss:i,disabled:a=!1,variant:m="chat",className:d}){const{t:h}=X("studio"),x=!!t&&!!s,u=o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"text-sm text-foreground",children:o.jsx(jt,{className:"leading-relaxed chat-panel-markdown answer-markdown",children:e})}),x||r?o.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[x&&o.jsxs("button",{type:"button","data-testid":"answer-proposal",disabled:a,onClick:()=>s(t),title:t,className:"h-8 max-w-full px-3 rounded-md bg-foreground text-background text-sm hover:opacity-80 transition-opacity disabled:opacity-30 cursor-pointer flex items-center gap-2",children:[o.jsx(w,{icon:["far","hammer"],className:"text-xs shrink-0"}),o.jsx("span",{className:"truncate",children:n?.trim()||h("autoRoute.proposalHint","Build this change")})]}),o.jsx(gn,{info:r,guideModel:c})]}):null]});return m==="chat"?o.jsx("div",{"data-testid":"answer",className:y("mb-6 animate-chat-fadeIn",d),children:u}):o.jsxs("div",{"data-testid":"answer-card",className:y("rounded-md border border-border bg-card shadow-md overflow-hidden animate-chat-fadeIn",d),children:[o.jsxs("div",{className:"px-4 py-3 flex items-center gap-2.5 border-b border-border",children:[o.jsx(w,{icon:["far","compass"],className:"text-sm text-violet-400"}),o.jsx("span",{className:"text-sm font-medium text-foreground flex-1",children:h("autoRoute.guideTitle","Answer")}),i&&o.jsx("button",{type:"button",onClick:i,"aria-label":h("autoRoute.dismiss","Dismiss"),className:"h-7 w-7 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-foreground
1/6 transition-colors cursor-pointer",children:o.jsx(w,{icon:["far","xmark"],className:"text-sm"})})]}),o.jsx("div",{className:"px-4 py-3 max-h-[320px] overflow-y-auto",children:u})]})}const bn=100,kn=20,Oe=[];function yn({gameId:e,sessionId:t,enabled:n=!0,agentId:r=null,direction:c="backward",autoAdvance:s=!1}){const[i,a]=l.useState(Oe),[m,d]=l.useState(!1),[h,x]=l.useState(!1),u=n&&!!e&&!!t,[f,j]=l.useState(()=>!u),[k,_]=l.useState(null),v=l.useRef(null),C=l.useRef(!1),S=l.useRef(!1),R=l.useRef(0),b=l.useRef(""),E=c==="backward",V=l.useCallback(async N=>{if(!e||!t||C.current)return;const z=`${e}:${t}:${r||""}:${c}`;C.current=!0,x(!0);try{const I=await Qt.getActivity(e,t,r||en,N,bn);if(b.current!==z)return;const T=I?.entries||[];if(T.length>0){const F=T.reduce((W,ne)=>{const G=He(ne);return G===null?W:W===null?G:E?Math.min(W,G):Math.max(W,G)},null);F!==null&&(v.current=E?ot(v.current,F):rt(v.current,F)),a(W=>W===Oe?T:[...T,...W])}R.current+=1;const Y=!!I?.has_more&&T.length>0;S.current=!Y,d(Y)}catch{b.current===z&&(S.current=!0,d(!1))}finally{C.current=!1,b.current===z&&(x(!1),j(!0))}},[e,t,r,c,E]);l.useEffect(()=>{const N=u?`${e}:${t}:${r||""}:${c}`:"";b.current=N,v.current=null,S.current=!1,C.current=!1,R.current=0,a(Oe),_(null),d(!1),x(!1),j(!u),u&&V(E?st:{dir:"after",seq:0})},[u,e,t,r,c,E,V]);const te=l.useCallback(N=>{_(N)},[]),$=l.useCallback(()=>{if(E){const N=ot(v.current,k);return N===null?st:{dir:"before",seq:N}}return{dir:"after",seq:rt(v.current,k)??0}},[E,k]),K=l.useCallback(()=>{!u||S.current||C.current||V($())},[u,V,$]),ee=E?m&&(k===null||k>1):m;return l.useEffect(()=>{!s||E||!u||!m||h||C.current||R.current>=kn||V({dir:"after",seq:v.current??0})},[s,E,u,m,h,i,V]),{entries:i,hasMore:ee,isLoading:h,settled:f,loadMore:K,setRenderedEdgeSeq:te}}const wn={icon:"folder",color:"#90A4AE"},En={icon:"folder-open",color:"#FFCA28"},it={icon:"file",color:"#90A4AE"},jn={".gd":{icon:"file-code",color:"#FF8C00"},".gdshader":{icon:"file-code",color:"#EC407A"},".gdshaderinc":{icon:"file-code",color:"#EC407A"},".tscn":{icon:"cubes",color:"#478CBF"},".tres":{icon:"cube",color:"#478CBF"},".res":{icon:"cube",color:"#478CBF"},".godot":{icon:"gear",color:"#478CBF"},".uid":{icon:"key",color:"#26C6DA"},".gdignore":{icon:"key",color:"#78909C"},".import":{icon:"gear",color:"#78909C"},".py":{icon:"file-code",color:"#3776AB"},".ts":{icon:"file-code",color:"#3178C6"},".js":{icon:"file-code",color:"#F7DF1E"},".tsx":{icon:"file-code",color:"#3178C6"},".jsx":{icon:"file-code",color:"#F7DF1E"},".glb":{icon:"cube",color:"#AB47BC"},".gltf":{icon:"cube",color:"#AB47BC"},".fbx":{icon:"cube",color:"#AB47BC"},".obj":{icon:"cube",color:"#AB47BC"},".png":{icon:"file-image",color:"#26A69A"},".jpg":{icon:"file-image",color:"#26A69A"},".jpeg":{icon:"file-image",color:"#26A69A"},".webp":{icon:"file-image",color:"#26A69A"},".gif":{icon:"file-image",color:"#26A69A"},".svg":{icon:"vector-square",color:"#FFB300"},".mp3":{icon:"file-audio",color:"#EF5350"},".wav":{icon:"file-audio",color:"#EF5350"},".ogg":{icon:"file-audio",color:"#EF5350"},".flac":{icon:"file-audio",color:"#EF5350"},".json":{icon:"brackets-curly",color:"#FBC02D"},".yaml":{icon:"brackets-curly",color:"#FBC02D"},".yml":{icon:"brackets-curly",color:"#FBC02D"},".toml":{icon:"brackets-curly",color:"#FBC02D"},".cfg":{icon:"gear",color:"#9E9E9E"},".ini":{icon:"gear",color:"#9E9E9E"},".md":{icon:"file-lines",color:"#42A5F5"},".txt":{icon:"file-lines",color:"#90A4AE"},".csv":{icon:"file-lines",color:"#66BB6A"},".ttf":{icon:"font",color:"#7E57C2"},".otf":{icon:"font",color:"#7E57C2"},".woff":{icon:"font",color:"#7E57C2"},".woff2":{icon:"font",color:"#7E57C2"},".bin":{icon:"file",color:"#9E9E9E"},".dat":{icon:"file",color:"#9E9E9E"}};function vn(e){const t=e.toLowerCase();if(t.endsWith(".tesana_meta.json"))return{icon:"gear",color:"#FF6B9D"};const n=t.lastIndexOf(".");if(n===-1)return it;const r=t.slice(n);return jn[r]??it}function Yo(e){return e?En:wn}function _n(e){const t=e.replace(/\/$/,""),n=t.lastIndexOf("/");return n===-1?t:t.slice(n+1)}const Nn=l.memo(function({entry:t,onOpenDiff:n,fromChatPanel:r}){const{t:c}=X("studio"),s=t.status,i=t.is_error||s==="error",a=!i&&s==="in_progress",m=!i&&!a&&s==="complete",d=t.file_diff,h=d?.file_path??"",x=h?_n(h):"",u=h?vn(h):null,f=(t.message||"").trim()||(x?c("writeDiffCard.writingFile",{defaultValue:"Writing {{filename}}",filename:x}):c("writeDiffCard.writing",{defaultValue:"Writingâ¦"})),j=!!(d&&n&&h),k=j?"button":"div",_=j?{type:"button",onClick:()=>n(h),"aria-label":c("writeDiffCard.openInChanges",{defaultValue:"Open diff in Changes view"})}:{};return o.jsx("div",{className:"py-1",children:o.jsxs(k,{..._,className:y("w-full flex items-center gap-2 px-3 h-9 rounded-md border bg-card text-left transition-all duration-150 animate-chat-fadeIn",i?"border-destructive/40 bg-destructive/5":"border-border",j&&"hover:border-border-hover hover:bg-foreground
1/[0.04] cursor-pointer","gottaborder "),children:[i?o.jsx(w,{icon:["far","circle-xmark"],className:"text-xs text-destructive flex-shrink-0"}):u?o.jsx(w,{icon:["far",u.icon],style:{color:u.color},className:"text-xs flex-shrink-0"}):o.jsx(w,{icon:["far","file"],className:"text-xs text-muted-foreground/70 flex-shrink-0"}),o.jsx("span",{className:y("flex-1 min-w-0 truncate text-sm",i?"text-destructive":a?"text-muted-foreground":"text-foreground/90"),title:h?`${f} â ${h}`:f,children:i?c("writeDiffCard.failed",{defaultValue:"Write failed"}):f}),!i&&x&&!r&&o.jsx("span",{className:"hidden sm:inline text-[11px] text-muted-foreground/60 truncate flex-shrink-0 max-w-[40%]",title:h,children:x}),!a&&!i&&d&&o.jsx(o.Fragment,{children:d.binary?o.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground/70 flex-shrink-0",children:c("writeDiffCard.binary",{defaultValue:"binary"})}):o.jsxs(o.Fragment,{children:[d.additions>0&&o.jsxs("span",{className:"text-xs tabular-nums text-emerald-500 flex-shrink-0",children:["+",d.additions]}),d.deletions>0&&o.jsxs("span",{className:"text-xs tabular-nums text-destructive flex-shrink-0",children:["-",d.deletions]}),d.additions===0&&d.deletions===0&&o.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground/60 flex-shrink-0",children:c("writeDiffCard.unchanged",{defaultValue:"no change"})})]})}),a?o.jsx(w,{icon:["far","spinner-third"],className:"text-xs text-muted-foreground/70 animate-spin flex-shrink-0"}):j&&m?o.jsx(w,{icon:["far","arrow-up-right"],className:"text-xs text-muted-foreground/40 flex-shrink-0"}):null]})})}),de="#9E9E9E",Fe="#9E9E9E",Cn="#9E9E9E",we="#9E9E9E",Ee="#9E9E9E",ct="#9E9E9E",Ae="#9E9E9E",Be="#9E9E9E",_t="#9E9E9E",Z="#9E9E9E",Nt="#9E9E9E",U="#9E9E9E",Pe="#9E9E9E",at="#9E9E9E",ke="#9E9E9E",oe="#9E9E9E",Me="#9E9E9E",Ct="#9E9E9E",lt={"3d_models":{icon:"cubes",color:de},audio:{icon:"music",color:Fe},assets:{icon:"palette",color:Ct},compacting:{icon:"brain",color:_t},discovery:{icon:"magnifying-glass",color:Z},subagent:{icon:"robot",color:Be},code:{icon:"file-code",color:we},knowledge:{icon:"book",color:Ee},system:{icon:"gear",color:Nt},planning:{icon:"list-check",color:U},testing:{icon:"flask",color:Pe}},Le={"ð§±":{icon:"cubes",color:de},"ð§":{icon:"cube",color:de},"ð§":{icon:"user",color:ct},"ðª":{icon:"cube",color:de},"ðï¸":{icon:"mountain",color:Ae},"ðï¸":{icon:"mountain",color:Ae},"ð":{icon:"music",color:Fe},"ðµ":{icon:"music",color:Fe},"ð¨":{icon:"palette",color:Ct},"ðï¸":{icon:"paintbrush",color:Cn},"ð":{icon:"image",color:Ae},"ðï¸":{icon:"sliders",color:Z},"ð":{icon:"file-code",color:we},"âï¸":{icon:"pen",color:we},"ð":{icon:"folder",color:Z},"ð":{icon:"book",color:Ee},"ð¨":{icon:"hammer",color:Pe},"âï¸":{icon:"gear",color:Nt},"ð§ª":{icon:"flask",color:Pe},"ð§ ":{icon:"brain",color:_t},"ð":{icon:"comment-dots",color:oe},"ð¬":{icon:"comment",color:oe},"ð":{icon:"magnifying-glass",color:Z},"ð":{icon:"magnifying-glass",color:Z},"ðï¸":{icon:"eye",color:Ee},"ð»":{icon:"terminal",color:Z},"ð":{icon:"globe",color:Me},"ð§":{icon:"wrench",color:Z},"ð¤":{icon:"robot",color:Be},"â
":{icon:"circle-check",color:at},"â":{icon:"circle-xmark",color:ke},"â":{icon:"circle-question",color:oe},"â":{icon:"circle-plus",color:U},"â¡ï¸":{icon:"circle-arrow-right",color:U},"â¶ï¸":{icon:"circle-arrow-right",color:U},"ð":{icon:"clipboard-list",color:U},"ð¬":{icon:"film",color:oe},"ð®":{icon:"gamepad-modern",color:Be},"ð":{icon:"rocket",color:we},"â¨":{icon:"sparkles",color:U},"ðï¸":{icon:"building-columns",color:Z},"ð«":{icon:"gun",color:ke},"âï¸":{icon:"sword",color:ke},"ð":{icon:"car",color:"#FFB300"},"ð":{icon:"person-running",color:ct},"ð":{icon:"earth-americas",color:Me},"ð":{icon:"earth-americas",color:Me},"ð¦":{icon:"cube",color:de},"ð":{icon:"chart-bar",color:Ee},"ð°":{icon:"sack-dollar",color:U},"ðµ":{icon:"sack-dollar",color:U},"â¸ï¸":{icon:"pause",color:oe},"â ï¸":{icon:"circle-exclamation",color:U},"ð§":{icon:"circle-exclamation",color:U},"ð":{icon:"thumbtack",color:U},"ð":{icon:"paperclip",color:oe},"ð":{icon:"arrow-rotate-right",color:Z},"â":{icon:"circle-check",color:at},"â":{icon:"circle-xmark",color:ke}},ut=/[\uFE0F\uFE0E]/g;function Tn(e){if(!e)return null;const t=e.trim();if(!t)return null;const n=Le[t];if(n)return n;const r=t.replace(ut,"");if(r!==t){const c=Le[r];if(c)return c}for(const[c,s]of Object.entries(Le))if(c.replace(ut,"")===r)return s;return null}function Ne({emoji:e,category:t,fallbackCategory:n,className:r,color:c,noColor:s}){const i=Tn(e)??(t?lt[t.toLowerCase()]:null)??(n?lt[n.toLowerCase()]:null)??null;if(!i)return null;const a=s?void 0:c??i.color;
1return o.jsx(w,{icon:["far",i.icon],className:r,style:a?{color:a}:void 0})}function Sn(e){const t=Math.max(1,Math.round(e/1e3));if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return`${n}m${r.toString().padStart(2,"0")}s`}const Tt=l.memo(function({entry:t,simple:n}){const{t:r}=X("studio"),c=t.status,s=t.is_error||c==="error",i=!s&&c==="in_progress",a=!s&&!i&&c==="complete",m=n?((t.message||"").trim()||r("toolCard.fallback",{defaultValue:"Workingâ¦"})).replace("Creating 3D prop: ","").replace("Creating 3D environment: ","").replace("Creating 3D character: ","").replace("Creating sound effect: ","").replace("Creating background: ","").replace("Creating item sprite: ","").replace("Generating ",""):(t.message||"").trim()||r("toolCard.fallback",{defaultValue:"Workingâ¦"}),d=(t.tool_result_excerpt||"").trim(),h=s&&d.length>0;return o.jsx("div",{className:n?"":"py-1",children:o.jsxs("div",{className:y("w-full flex flex-col px-3 rounded-md border bg-card transition-colors duration-150 animate-chat-fadeIn",h?"py-1.5":"h-9 justify-center",s?"border-destructive/30 bg-card":"border-border",n?"mt-2":"","gottaborder "),children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Ne,{emoji:t.icon,category:t.category,fallbackCategory:t.category,className:"text-xs flex-shrink-0"}),o.jsx("span",{className:y("flex-1 min-w-0 truncate text-sm",s||i?"text-muted-foreground":"text-foreground/90"),title:d||m,children:m}),t.duration_ms!=null&&!i?o.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground flex-shrink-0",children:Sn(t.duration_ms)}):null,i?o.jsx(w,{icon:["far","spinner-third"],className:"text-xs text-muted-foreground/70 animate-spin flex-shrink-0"}):a?o.jsx(w,{icon:["far","check"],className:"text-xs text-emerald-500 flex-shrink-0"}):s?o.jsx(w,{icon:["far","xmark"],className:"text-xs text-destructive flex-shrink-0"}):null]}),h&&o.jsx("p",{className:"mt-0.5 pl-6 text-xs text-destructive/80 truncate",title:d,children:d})]})})});function Rn(e){const t=Math.max(1,Math.round(e/1e3));if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return`${n}m${r.toString().padStart(2,"0")}s`}const On=l.memo(function({entry:t}){const{t:n}=X("studio"),{currentGame:r}=hn(),c=t.status,s=t.is_error||c==="error",i=!s&&c==="in_progress",a=!s&&!i&&c==="complete",m=(t.message||"").trim()||n("testingCard.fallback",{defaultValue:"Play-testing the gameâ¦"}),d=l.useMemo(()=>{const h=(r?.engine_play_url||tn).replace(/\/$/,"");return(t.attachments||[]).filter(x=>x.kind==="screenshot"&&x.url).map(x=>x.url.startsWith("http")?x.url:`${h}${x.url}`)},[t.attachments,r?.engine_play_url]);return o.jsx("div",{className:"py-1",children:o.jsxs("div",{className:y("w-full flex flex-col px-3 py-1.5 rounded-md border bg-card transition-colors duration-150 animate-chat-fadeIn",s?"border-destructive/40 bg-destructive/5":"border-border","gottaborder "),children:[o.jsxs("div",{className:"flex items-center gap-2 min-h-[1.5rem]",children:[o.jsx(Ne,{emoji:t.icon,category:t.category||"testing",fallbackCategory:"testing",className:"text-xs flex-shrink-0"}),o.jsx("span",{className:y("flex-1 min-w-0 truncate text-sm",s?"text-destructive":i?"text-muted-foreground":"text-foreground/90"),title:m,children:m}),t.duration_ms!=null&&!i?o.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground flex-shrink-0",children:Rn(t.duration_ms)}):null,i?o.jsx(w,{icon:["far","spinner-third"],className:"text-xs text-muted-foreground/70 animate-spin flex-shrink-0"}):a?o.jsx(w,{icon:["far","check"],className:"text-xs text-emerald-500 flex-shrink-0"}):s?o.jsx(w,{icon:["far","xmark"],className:"text-xs text-destructive flex-shrink-0"}):null]}),d.length>0&&o.jsx("div",{className:"mt-1.5 mb-1 flex gap-1.5 overflow-x-auto",children:d.map((h,x)=>o.jsx("a",{href:h,target:"_blank",rel:"noreferrer",className:"flex-shrink-0 rounded border border-border overflow-hidden hover:ring-1 hover:ring-primary/50 transition-shadow",title:n("testingCard.openScreenshot",{defaultValue:"Open play-test screenshot {{n}}",n:x+1}),children:o.jsx("img",{src:h,alt:`Play-test screenshot ${x+1}`,loading:"lazy",className:"h-16 w-auto object-cover"})},h))})]})})});function St(e){const t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:`${n}m${r.toString().padStart(2,"0")}s`}function An(e,t=!0){const[n,r]=l.useState(()=>Date.now()),c=l.useRef(null);if(l.useEffect(()=>{if(!t)return;const i=setInterval(()=>r(Date.now()),1e3);return()=>clearInterval(i)},[t]),!e||!t)return null;const s=Date.parse(e);return Number.isNaN(s)?null:((c.current===null||s<c.current)&&(c.current=s),St(n-c.current))}
1const Mn=l.memo(function({entry:t,record:n,onOpen:r}){const c=n?.status??(t.status==="complete"?"completed":t.status==="error"?"error":"running"),s=c==="launching"||c==="running",i=c==="error",a=c==="stopped",m=An(n?.started_at,s),d=(n?.description||t.message||"Specialized agent").trim(),h=n?.usage,x=h?.duration_ms!=null?St(h.duration_ms):null;let u;s?u=[n?.current_action||"Working",m].filter(Boolean).join(" · "):i?u=["Errored",x].filter(Boolean).join(" · "):a?u=["Stopped",x].filter(Boolean).join(" · "):u=["Completed",x,h?.tool_uses!=null?`${h.tool_uses} tools`:null].filter(Boolean).join(" · ");const f=!!(r&&(n?.entries?.length||n?.entry_count||n?.result_summary));return o.jsx("div",{className:"py-1",children:o.jsxs("button",{type:"button",onClick:f?()=>r?.(n?.key||t.tool_use_id||""):void 0,className:y("w-full text-left px-3 py-2 rounded-md border bg-card transition-colors duration-150 animate-chat-fadeIn",i?"border-destructive/40 bg-destructive/5":"border-border",f?"cursor-pointer hover:border-border-hover hover:bg-foreground
1/[0.04]":"cursor-default","gottaborder "),children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:y("w-2 h-2 rounded-full flex-shrink-0",s&&"bg-amber-400 animate-pulse",c==="completed"&&"bg-emerald-500",i&&"bg-destructive",a&&"bg-muted-foreground/50")}),o.jsx("span",{className:"flex-1 min-w-0 truncate text-sm text-foreground/90",title:d,children:d}),n?.mode==="async"?o.jsx("span",{className:"text-[10px] uppercase tracking-wide px-1.5 py-0.5 rounded bg-muted text-muted-foreground/80 flex-shrink-0",children:"async"}):null,f?o.jsx(w,{icon:["far","chevron-right"],className:"text-xs text-muted-foreground/60 flex-shrink-0 mt-0.25"}):null]}),o.jsx("div",{className:y("mt-0.5 pl-4 truncate text-xs",i?"text-destructive/90":"text-muted-foreground"),title:u,children:u})]})})}),Ln=48;function Rt(e,t){const n=l.useRef(null),r=l.useRef(!0),c=()=>{const s=n.current;s&&(r.current=s.scrollHeight-s.scrollTop-s.clientHeight<=Ln)};return l.useLayoutEffect(()=>{t&&(r.current=!0)},[t]),l.useLayoutEffect(()=>{const s=n.current;!s||!t||!r.current||(s.scrollTop=s.scrollHeight)},[e,t]),{ref:n,onScroll:c}}const Ie="tesana:thinking-open";let De=!1;const In="tesana.activity.thinkingOpen.v1";if(typeof window<"u")try{window.localStorage.removeItem(In)}catch{}function Ot(){const[e,t]=l.useState(De);l.useEffect(()=>{const r=()=>t(De);return window.addEventListener(Ie,r),()=>window.removeEventListener(Ie,r)},[]);const n=l.useCallback(r=>{De=r,t(r),window.dispatchEvent(new Event(Ie))},[]);return[e,n]}const ue={thinking:!0,discovery:!0,skill:!1,taskMarkers:!0,knowledge:!0},Dn="tesana.activity.phaseFold.v1",$n=new Set(["Write","Edit","NotebookEdit"]),Fn=new Set(["AskUserQuestion","Compact","Agent"]),Bn=new Set(["subagent","testing","assets","3d_models","audio","compacting","build"]),dt=new Set(["TodoWrite","TaskCreate","TaskUpdate","TaskList","TaskGet","TaskStop"]),Pn=new Set(["Read","Glob","NotebookRead","LSP"]),Vn=new Set(["Grep","WebSearch","WebFetch"]);function Wn(){if(typeof window>"u")return{};try{const e=window.localStorage.getItem(Dn);if(!e)return{};const t=JSON.parse(e);return t&&typeof t=="object"?t:{}}catch{return{}}}function Gn(){const e=Wn();return{thinking:e.thinking??ue.thinking,discovery:e.discovery??ue.discovery,skill:e.skill??ue.skill,taskMarkers:e.taskMarkers??ue.taskMarkers,knowledge:e.knowledge??ue.knowledge}}function ft(e,t=Gn()){if(e.type==="thinking")return t.thinking;if(e.type==="text"||e.type==="system"||e.type==="todo"||e.type!=="tool_use")return!1;const n=e.tool_name||"",r=(e.category||"").toLowerCase();return $n.has(n)?!1:n==="Skill"?t.skill:Fn.has(n)||Bn.has(r)||r==="system"?!1:dt.has(n)?t.taskMarkers:r==="discovery"?t.discovery:r==="knowledge"?t.knowledge:r==="planning"&&dt.has(n)?t.taskMarkers:!0}function At(e){if(e.type==="thinking")return null;const t=e.tool_name||"";return Pn.has(t)?"files":Vn.has(t)?"searches":t==="Bash"||t==="PowerShell"?"commands":e.type==="tool_use"?"other":null}function Hn(e){let t=0,n=0,r=0,c=0;for(const i of e){const a=At(i);a==="files"?t+=1:a==="searches"?n+=1:a==="commands"?r+=1:a==="other"&&(c+=1)}const s=[];return t>0&&s.push(t===1?"1 file":`${t} files`),n>0&&s.push(n===1?"1 search":`${n} searches`),r>0&&s.push(r===1?"1 command":`${r} commands`),c>0&&s.length===0&&s.push(c===1?"1 action":`${c} actions`),{files:t,searches:n,commands:r,other:c,exploring:s.join(", ")}}function qn(e){let t=null;for(const n of e){const r=At(n);if(r!=="files"&&r!=="searches"&&r!=="commands")return null;if(t===null)t=r;else if(t!==r)return null}return t}function Ve(e,t){return e.entry_id||e.block_id||`${e.timestamp}-${t}`}function Un(e,t){for(let n=e.length-1;n>=0;n--){const r=e[n];if(r.type==="tool_use"&&r.status==="in_progress"&&r.message)return r.message}return null}function Kn(e,t){if(e.duration_ms!=null)return Math.max(1,Math.round(e.duration_ms/1e3));if(e.timestamp&&t){const n=new Date(e.timestamp).getTime()-new Date(t).getTime();return Math.max(1,Math.round(n/1e3))}return 1}const mt=220,zn=3e3,ht={label:null,heldIds:new Set};function Yn({ids:e,describe:t,enabled:n,suppressed:r}){const[c,s]=l.useState(ht),i=l.useRef(e);i.current=e;const a=l.useRef(t);a.current=t;const m=l.useRef(c);m.current=c;const d=l.useRef(null),h=l.useRef(0),x=l.useRef(null),u=l.useRef(null),f=l.useRef(null),j=e.join("\0");return l.useEffect(()=>{const k=()=>{u.current!==null&&(clearTimeout(u.current),u.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null)},_=()=>{k(),x.current=null,m.current.label!==null&&s(ht)},v=E=>{k(),x.current=null,h.current=Date.now(),s({label:E.label,heldIds:new Set(E.ids)}),f.current=setTimeout(_,zn)},C=d.current;
1if(d.current=new Set(i.current),!n||r){_();return}if(C===null)return;const S=i.current.filter(E=>!C.has(E));if(S.length===0)return;const R=a.current(S);if(R===null)return;const b=Date.now()-h.current;if(m.current.label===null||b>=mt){v(R);return}x.current=R,u.current!==null&&clearTimeout(u.current),u.current=setTimeout(()=>{u.current=null;const E=x.current;E!==null&&v(E)},mt-b)},[j,n,r]),l.useEffect(()=>()=>{u.current!==null&&clearTimeout(u.current),f.current!==null&&clearTimeout(f.current)},[]),c}const Xn=500,re=new Map;function Jn(e,t){if(!(!e||re.has(e))){if(re.size>=Xn){const n=re.keys().next();n.done||re.delete(n.value)}re.set(e,t)}}function Mt(e){return e?re.get(e):void 0}function xt({entries:e,liveThinking:t=null,isLive:n=!1,planningLabel:r,anchorTs:c}){const{t:s}=X("studio"),[i,a]=l.useState(!1),[m,d]=Ot(),[h]=l.useState(m),[x,u]=l.useState({}),f=t?.blockId,k=!!f&&e.some(p=>p.block_id===f)?null:t??null,_=Hn(e),v=Zn(k),C=Qn(e,c,v),S=k?.status==="streaming"&&k.text||"",R=k?.status==="streaming",b=!_.exploring;l.useEffect(()=>{v&&Jn(v.blockId,v.seconds)},[v?.blockId,v?.seconds]);const E=Un(e),V=l.useMemo(()=>e.reduce((p,H,O)=>(H.status!=="in_progress"&&p.push(Ve(H,O)),p),[]),[e]),te=l.useCallback(p=>{const H=new Map;e.forEach((L,q)=>H.set(Ve(L,q),L));const O=[];for(const L of p){const q=H.get(L);!q||q.type!=="tool_use"||(q.message||"").trim()&&O.push({id:L,entry:q})}if(O.length===0)return null;if(O.length===1)return{label:(O[0].entry.message||"").trim(),ids:[O[0].id]};const B=qn(O.map(L=>L.entry));if(B===null){const L=O[O.length-1];return{label:(L.entry.message||"").trim(),ids:[L.id]}}const J=O.length;return{label:B==="files"?s("chat.phase.batchFiles",{defaultValue:`Reading ${J} files`,n:J}):B==="searches"?s("chat.phase.batchSearches",{defaultValue:`Searching ${J} sources`,n:J}):s("chat.phase.batchCommands",{defaultValue:`Running ${J} commands`,n:J}),ids:O.map(L=>L.id)}},[e,s]),$=Yn({ids:V,describe:te,enabled:n,suppressed:!!R||E!==null}),K=n?R?"Thinking":E??$.label??r:null,ee=_.exploring?n?s("chat.phase.exploring",{defaultValue:`Exploring ${_.exploring}`,detail:_.exploring}):s("chat.phase.explored",{defaultValue:`Explored ${_.exploring}`,detail:_.exploring}):"",N="live",z="thought-only",I=b&&R&&!n,T=to(C.filter(p=>p.kind==="thinking")),Y=b&&!R&&C.length>0?"thought":I?s("chat.thinking",{defaultValue:"Thinking..."}):"",F=ee||Y,W=$.heldIds.size===0?C:C.filter(p=>!$.heldIds.has(p.id)),ne=b?[]:W,G=(b?0:C.length)>0||!!ee&&R,M=p=>Object.prototype.hasOwnProperty.call(x,p)?x[p]:p===N?h:!1,A=(p,H=!1)=>{const O=!M(p);u(B=>({...B,[p]:O})),H&&d(O)};if(!F&&!K&&!R)return null;const fe=R&&M(N)&&!i,se=i&&R;return o.jsxs("div",{className:"flex flex-col py-1 gottaborder",children:[F&&o.jsxs("button",{type:"button",onClick:()=>{I?A(N,!0):b?A(z):G&&a(p=>!p)},className:"text-sm text-muted-foreground group cursor-pointer select-none text-left",children:[ee?o.jsx(ye,{lead:n?s("chat.phase.exploringVerb",{defaultValue:"Exploring"}):s("chat.phase.exploredVerb",{defaultValue:"Explored"}),rest:_.exploring}):Y==="thought"?o.jsx(ye,{lead:s("chat.phase.thought",{defaultValue:"Thought"}),rest:`${T}s`}):F,(G||b||I)&&o.jsxs(o.Fragment,{children:[" ",o.jsx(We,{open:I?M(N):b?M(z):i})]})]}),b&&!I&&M(z)&&o.jsx(je,{text:C.filter(p=>p.kind==="thinking").map(p=>p.text).join(` 2 3`),streaming:!1}),I&&M(N)&&o.jsx(je,{text:S,streaming:!0}),i&&G&&o.jsx("div",{className:"gottaborder relative mt-1",children:o.jsxs("div",{className:"mt-2 space-y-3",children:[o.jsx(tt,{initial:!1,children:ne.map(p=>o.jsx(nt.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.22,ease:[.22,1,.36,1]},children:p.kind==="thinking"?o.jsx(pt,{label:o.jsx(ye,{lead:s("chat.phase.thought",{defaultValue:"Thought"}),rest:`${p.seconds}s`}),text:p.text,streaming:!1,open:M(p.id),onToggle:()=>A(p.id)}):o.jsx("p",{className:y("text-sm",p.error?"text-destructive":"text-muted-foreground"),children:o.jsx(ye,{...no(p.message)})})},p.id))}),se&&o.jsx(pt,{label:s("chat.thinking",{defaultValue:"Thinking..."}),text:S,streaming:!0,open:M(N),onToggle:()=>A(N,!0)})]})}),K&&o.jsxs("div",{className:`flex items-center gap-2.5 ${F?"mt-4":"mt-0"} overflow-hidden`,children:[n&&o.jsx(_e,{state:"working"}),o.jsx("span",{className:"relative block flex-1",children:o.jsx(tt,{initial:!1,mode:"popLayout",children:o.jsx(nt.span,{initial:{opacity:0,y:8}
3,animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.22,ease:[.22,1,.36,1]},className:"block",children:K==="Thinking"?o.jsxs("button",{type:"button",onClick:()=>S&&A(N,!0),className:y("text-sm text-left select-none block",S?"cursor-pointer group":"cursor-default",n?"text-shimmer":"text-muted-foreground"),children:[s("chat.thinking",{defaultValue:"Thinking..."}),S&&o.jsxs(o.Fragment,{children:[" ",o.jsx(We,{open:M(N)})]})]}):o.jsx("p",{className:y("text-sm",n?"text-shimmer":"text-muted-foreground"),children:K})},K)})})]}),fe&&o.jsx(je,{text:S,streaming:!0})]})}function Zn(e){if(!e||e.type!=="thinking"||e.status!=="final")return null;const t=(e.text||"").trim();if(!t)return null;const n=e.startedAt&&e.finalizedAt?Math.round((e.finalizedAt-e.startedAt)/1e3):1;return{blockId:e.blockId,text:t,seconds:Mt(e.blockId)??Math.max(1,n),seq:e.seq}}function Qn(e,t,n){const r=[],c=[];for(let s=0;s<e.length;s++){const i=e[s],a=Ve(i,s),m=typeof i.seq=="number"?i.seq:null;if(i.type==="thinking"){const h=(i.content||i.message||"").trim();if(!h)continue;const x=s>0?e[s-1].timestamp:t,u=Mt(i.block_id)??Kn(i,x);r.push({kind:"thinking",id:a,text:h,seconds:u}),c.push(m);continue}const d=(i.message||"").trim();d&&(r.push({kind:"tool",id:a,message:d,error:!!(i.is_error||i.status==="error")}),c.push(m))}return n&&r.splice(eo(c,n.seq),0,{kind:"thinking",id:n.blockId,text:n.text,seconds:n.seconds}),r}function eo(e,t){if(typeof t!="number")return e.length;for(let n=0;n<e.length;n++){const r=e[n];if(r!==null&&r>t)return n}return e.length}function to(e){return Math.max(1,e.reduce((t,n)=>n.kind==="thinking"?t+n.seconds:t,0))}function ye({lead:e,rest:t}){return o.jsxs(o.Fragment,{children:[e,t?o.jsxs(o.Fragment,{children:[" ",o.jsx("span",{className:"text-muted-foreground/50",children:t})]}):null]})}function no(e){const t=e.indexOf(" ");return t<0?{lead:e}:{lead:e.slice(0,t),rest:e.slice(t+1)}}function We({open:e}){return o.jsx(w,{icon:["far","chevron-down"],className:y("opacity-0 group-hover:opacity-100 transition-all duration-200 text-xs",e?"rotate-180 opacity-100":"mb-0.25")})}function pt({label:e,text:t,streaming:n,open:r,onToggle:c}){return o.jsxs("div",{className:"",children:[o.jsxs("button",{type:"button",onClick:c,disabled:!t,className:"text-sm text-muted-foreground group cursor-pointer select-none text-left disabled:cursor-default block",style:{margin:"0 0",padding:"0 0"},children:[e,t&&o.jsxs(o.Fragment,{children:[" ",o.jsx(We,{open:r})]})]}),r&&t&&o.jsx(je,{text:t,streaming:n})]})}function je({text:e,streaming:t}){const{ref:n,onScroll:r}=Rt(e,!0);return e?o.jsx("div",{ref:n,onScroll:r,className:"gottaborder pr-4 mt-3 opacity-70",children:o.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line",children:o.jsx(vt,{text:e,streaming:t})})}):null}const oo=l.memo(function({text:t,streaming:n,totalTime:r=null}){const{t:c}=X("studio"),[s,i]=Ot(),[a,m]=l.useState(n&&s),d=l.useMemo(()=>Math.floor(Math.random()*5)+2,[]),{ref:h,onScroll:x}=Rt(t,a),u=l.useRef(null);!n&&u.current===null&&r!=null&&(u.current=r);const f=u.current??r??d,j=l.useRef(n);l.useEffect(()=>{j.current&&!n&&!s&&m(!1),j.current=n},[n,s]);const k=!!t;return o.jsxs("div",{className:"gottaborder flex flex-col py-1 animate-chat-fadeIn",children:[o.jsxs("div",{className:"flex items-center gap-2.5",children:[n&&o.jsx(_e,{state:"working"}),o.jsxs("p",{className:y("text-sm group cursor-pointer",n?"text-shimmer":"text-muted-foreground"),onClick:()=>{if(!k)return;const _=!a;m(_),n&&i(_)},children:[n?c("chat.thinking"):c("chat.thoughtForSeconds",{count:f})+" ",k&&o.jsx(w,{icon:["far","chevron-down"],className:y("opacity-0 group-hover:opacity-100 transition-all duration-200 text-xs",a?"rotate-180":"mb-0.25")})]})]}),k&&a&&o.jsxs("div",{className:"relative",children:[o.jsx("div",{ref:h,onScroll:x,className:"max-h-40 overflow-y-auto pr-4 py-4",children:o.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line",children:o.jsx(vt,{text:t,streaming:n})})}),o.jsx("div",{className:"absolute top-0 w-full h-4 bg-gradient-to-b from-background to-transparent"}),o.jsx("div",{className:"absolute bottom-0 w-full h-4 bg-gradient-to-t from-background to-transparent"})]})]})}),ro=l.memo(function({text:t,isError:n}){return o.jsxs("div",{className:"flex items-start gap-2 py-2 animate-chat-fadeIn",children:[o.jsx(w,{icon:["far",n?"circle-exclamation":"circle-check"],className:y("text-xs mt-[3px]",n?"text-destructive":"text-emerald-400")}),o.jsx("span",{className:y("text-sm leading-relaxed",n?"text-destructive":"text-emerald-400/90"),children:t})]})}),gt=l.memo(function({text:t,streaming:n,isError:r=!1}){return o.jsx("div",{className:y("flex items-start gap-2 text-sm leading-relaxed whitespace-pre-line animate-chat-fadeIn-soft",r?"text-destructive":"text-foreground","gottaborder"),children:o.jsx("span",{className:"flex-1",children:o.jsx(jt,{className:"leading-relaxed whitespace-pre-line chat-panel-markdown",streaming:n,children:t})})})});function so(e){return e.type==="tool_use"&&(e.tool_name==="Write"||e.tool_name==="Edit")}const io=new Set(["assets","3d_models","audio"]);function bt(e){return e.type==="tool_use"&&!!e.tool_use_id&&io.has((e.category||"").toLowerCase())}const co=/\n\n---\n\n#{1,4}\s/,ao=/\n\n---\n\n\*\*.*?\*\*/,lo=/^#{1,6}\s/,uo=/^\*\*.+?\*\*/,fo=/^\s*(BUILD|BUTTON):.*$/gm,mo=/\n\s*B(U(I(L(D)?)?)?|UT(T(O(N)?)?)?)?\s*$/;function Lt(e){return e.replace(fo,"").replace(mo,"").trim()}function It(e,t,n=!1){const r=n?Lt(e.content||""):e.content||"";if(!r.trim())return"";if(t){const c=r.replace(/^\s+/,"");if(lo.test(c)||uo.test(c))return"";const s=co.exec(r);if(s)return r.slice(0,s.index).trim();const i=ao.exec(r);if(i)return r.slice(0,i.index).trim()}return r.trim()}function kt(e){return e.content}function $e(e){return e==="completed"?o.jsx(w,{icon:["fas","circle-check"],className:"text-base text-green-500"}):e==="in_progress"?o.jsx(w,{icon:["far","circle"],className:"animate-spin text-base text-muted-foreground"}):o.jsx(w,{icon:["far","circle"],className:"text-base text-muted-foreground
3/30"})}function ho({entry:e}){const{t}=X("studio"),n=e.todos||[],r=n.slice(0,4),c=n.slice(4),s=c.length;return o.jsx("div",{className:"py-1",children:o.jsxs("div",{className:"rounded-md border border-border bg-card shadow-card animate-chat-fadeIn gottaborder ",children:[o.jsx("div",{className:"flex items-center justify-between gap-2.5 px-4 py-3",children:o.jsx("p",{className:"text-sm text-foreground/95",children:t("chat.todo")})}),o.jsxs("div",{className:"space-y-2.5 border-t border-border px-4 py-3",children:[r.map((i,a)=>o.jsxs("div",{className:"flex items-center gap-3",children:[$e(i.status),o.jsx("span",{className:`min-w-0 flex-1 text-sm leading-relaxed truncate ${i.status==="completed"||i.status==="in_progress"?"text-foreground":"text-muted-foreground"}`,children:kt(i)})]},`${i.content}-${a}`)),s>0&&o.jsx("div",{className:"flex items-center",children:o.jsxs("div",{className:"relative flex items-center gap-3 text-muted-foreground group",children:[$e(c[0].status),o.jsx("button",{type:"button",className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:t("chat.moreCount",{count:s})}),o.jsxs("div",{className:"absolute left-8 top-full mt-1 z-20 w-[250px] md:w-[320px] rounded-md border border-border bg-card p-3 shadow-card opacity-0 scale-95 group-hover:scale-100 group-hover:opacity-100 transition-all duration-150 pointer-events-none",children:[o.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:t("chat.hiddenTodos")}),o.jsx("div",{className:"space-y-2 max-h-56 overflow-auto",children:c.map((i,a)=>o.jsxs("div",{className:"flex items-center gap-3",children:[$e(i.status),o.jsx("span",{className:`min-w-0 flex-1 text-sm leading-relaxed truncate ${i.status==="completed"||i.status==="in_progress"?"text-foreground":"text-muted-foreground"}`,children:kt(i)})]},`${i.content}-${a}`))})]})]})})]})]})})}function xo({entries:e,title:t}){const[n,r]=l.useState(!1),c=e.length;return o.jsxs("div",{className:"gottaborder flex flex-col py-1 animate-chat-fadeIn",children:[o.jsx("div",{className:"flex items-center",children:o.jsxs("p",{className:"text-sm text-muted-foreground group cursor-pointer select-none",onClick:()=>r(!n),children:[t," (",c,")"," ",o.jsx(w,{icon:["far","chevron-down"],className:y("opacity-0 group-hover:opacity-100 transition-all duration-200 text-xs",n?"rotate-180 opacity-100":"mb-0.25")})]})}),n&&o.jsxs("div",{className:"relative",children:[o.jsx("div",{className:"max-h-40 overflow-y-auto scroll-smooth pr-4 py-3",children:o.jsx("div",{className:"space-y-2",children:e.map(s=>{const i=(s.message||"").trim();if(!i)return null;const a=s.is_error||s.status==="error";return o.jsx("p",{className:y("text-sm flex items-center gap-1.5",a?"text-destructive":"text-muted-foreground/70"),children:o.jsx("span",{children:i})},s.entry_id||s.timestamp)})})}),o.jsx("div",{className:"absolute top-0 w-full h-3 bg-gradient-to-b from-background to-transparent"}),o.jsx("div",{className:"absolute bottom-0 w-full h-3 bg-gradient-to-t from-background to-transparent"})]})]})}function po({entry:e,hasLaterActivity:t=!1}){const n=e.is_error||e.status==="error",r=!n&&e.status!=="complete"&&!t,[c,s]=l.useState(()=>Date.now());l.useEffect(()=>{if(!r)return;const u=setInterval(()=>s(Date.now()),1e3);return()=>clearInterval(u)},[r]);const i=u=>{const f=Math.max(0,Math.round(u/1e3)),j=Math.floor(f/60),k=f%60;return j===0?`${k}s`:`${j}m${k.toString().padStart(2,"0")}s`};let a=null;if(r&&e.timestamp){const u=Date.parse(e.timestamp);Number.isNaN(u)||(a=i(c-u))}const m=e.duration_ms!=null?i(e.duration_ms):null,d=(e.tool_result_excerpt||"").trim(),h=n?d||"Continuing with the full conversation.":r?null:[d,m].filter(Boolean).join(" · "),x=!r&&!n&&e.status!=="complete"?"Conversation summarized.":e.message;return o.jsx("div",{className:"py-1",children:o.jsxs("div",{className:y("w-full px-3 py-2.5 rounded-md border bg-card transition-colors duration-150 animate-chat-fadeIn",n?"border-destructive/40 bg-destructive/5":"border-border","gottaborder "),children:[o.jsxs("div",{className:"flex items-start gap-2",children:[o.jsx(Ne,{emoji:e.icon,category:e.category,fallbackCategory:"compacting",className:"text-xs flex-shrink-0 mt-[3.625px]"}),o.jsx("span",{className:y("flex-1 min-w-0 text-sm leading-snug",n?"text-destructive":r?"text-muted-foreground":"text-foreground
3/90"),children:x}),r&&a&&o.jsx("span",{className:"text-[11px] tabular-nums text-muted-foreground flex-shrink-0 mt-[1.375px]",children:a}),!r&&!n&&o.jsx(w,{icon:["far","check"],className:"text-xs text-emerald-500 flex-shrink-0 mt-[3.625px]"}),n&&o.jsx(w,{icon:["far","xmark"],className:"text-xs text-destructive flex-shrink-0 mt-[3.625px]"})]}),r&&o.jsx("div",{className:"mt-2 h-1 rounded-full bg-muted overflow-hidden ml-[23px]",children:o.jsx("div",{className:"compact-sweep h-full w-[28%] rounded-full bg-foreground/30"})}),h&&o.jsx("p",{className:y("mt-1 pl-6 text-xs",n?"text-destructive/80":"text-muted-foreground"),children:h})]})})}const go={"3d_models":"3D models",assets:"images",audio:"audio clips"};function bo({entries:e}){const{t}=X("studio"),[n,r]=l.useState(!1),c=e.length,s=e.filter(u=>u.status==="complete"||u.status==="error").length,i=e.some(u=>u.is_error||u.status==="error"),a=s<c,m=(e[0].category||"").toLowerCase(),d=go[m]||t("chat.batch.genericLabel",{defaultValue:"assets"}),h=t("chat.batch.title",{count:c,label:d,defaultValue:"Creating {{count}} {{label}}"}),x=t("chat.batch.progress",{done:s,total:c,defaultValue:"{{done}}/{{total}} done"});return o.jsx("div",{className:"py-1",children:o.jsxs("div",{className:y("w-full rounded-md border bg-card transition-colors duration-150 animate-chat-fadeIn",i&&!a?"border-destructive/40 bg-destructive/5":"border-border","gottaborder "),children:[o.jsxs("button",{type:"button",onClick:()=>r(u=>!u),className:"w-full flex items-center gap-2 px-3 h-9 cursor-pointer",children:[o.jsx(Ne,{emoji:e[0].icon,category:e[0].category,fallbackCategory:e[0].category,className:"text-xs flex-shrink-0"}),o.jsx("span",{className:y("flex-1 min-w-0 truncate text-sm text-left",a?"text-muted-foreground":"text-foreground/90"),children:h}),x&&o.jsx("span",{className:y("text-[11px] tabular-nums px-1.5 py-0.5 rounded",a?"bg-muted text-muted-foreground":"bg-emerald-500/15 text-emerald-500","flex-shrink-0"),children:x}),o.jsx(w,{icon:["far","chevron-down"],className:y("text-[10px] text-muted-foreground/60 transition-transform duration-150 flex-shrink-0",n&&"rotate-180")})]}),o.jsxs("div",{className:y("px-2 pb-2 -mt-1",n?"":"overflow-hidden max-h-32 relative"),children:[e.map((u,f)=>o.jsx(Tt,{entry:u,simple:!0},u.entry_id||`${u.timestamp}-${f}`)),!n&&o.jsx("div",{className:"absolute bottom-0 left-0 w-full h-10 bg-gradient-to-t from-background to-transparent rounded-b-md"})]})]})})}function ko(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if(ft(r)){const c=n,s=[];for(;n<e.length&&ft(e[n]);)s.push(e[n]),n+=1;const i=s[0],a=i.entry_id||i.block_id||i.tool_use_id||`${i.timestamp}-${c}`;t.push({kind:"phase_group",key:`phase-${a}`,entries:s,anchorTs:c>0?e[c-1].timestamp:void 0});continue}if(r.type==="thinking"){const c=n,s=[];for(;n<e.length&&e[n].type==="thinking";)s.push(e[n]),n+=1;const i=s[0];t.push({kind:"thinking_group",key:`think-${i.block_id||i.entry_id||`${i.timestamp}-${c}`}`,entries:s,anchorTs:c>0?e[c-1].timestamp:void 0});continue}if(r.type!=="tool_use"){t.push({kind:"entry",key:r.entry_id||`entry-${r.timestamp}-${n}`,entry:r}),n+=1;continue}if(so(r)){t.push({kind:"write_diff",key:`write-${r.entry_id||r.tool_use_id||`${r.timestamp}-${n}`}`,entry:r}),n+=1;continue}if(bt(r)){const c=n,s=r.tool_use_id,i=[];for(;n<e.length&&bt(e[n])&&e[n].tool_use_id===s;)i.push(e[n]),n+=1;if(i.length>=2){const a=i[0].entry_id||`${i[0].timestamp}-${c}`;t.push({kind:"batch_group",key:`batch-${a}`,entries:i});continue}t.push({kind:"tool_inline",key:`tool-${i[0].entry_id||s||`${i[0].timestamp}-${c}`}`,entry:i[0]});continue}t.push({kind:"tool_inline",key:`tool-${r.entry_id||r.tool_use_id||`${r.timestamp}-${n}`}`,entry:r}),n+=1}return t}function yo(e,t,n=!1){if(e.kind!=="entry")return!0;const r=e.entry;return r.type==="todo"&&(r.todos||[]).length>0?!0:!!It(r,t,n)}function wo(e){if(e.kind==="thinking_group")return e.entries[0].block_id||e.key;if(e.kind==="phase_group"){const t=e.entries[0];return t?.type==="thinking"&&t.block_id?t.block_id:e.key}return e.kind==="entry"&&e.entry.block_id||e.key}function Eo(e,t){if(t.length===0)return e;const n=[],r=[];for(const a of t)(typeof a.seq=="number"&&a.seq>0?n:r).push(a);const c=a=>({row:"ghost",key:a.blockId,ghost:a});if(n.length===0)return[...e,...r.map(c)];n.sort((a,m)=>a.seq-m.seq);const s=[];let i=0;for(const a of e){const m=a.row==="block"?qe(a.block):null;for(;i<n.length&&m!==null&&n[i].seq<m;)s.push(c(n[i])),i+=1;s.push(a)}for(;i<n.length;i+=1)s.push(c(n[i]));return[...s,...r.map(c)]}function jo(e,{isCancelling:t,tailIsPhase:n}){return!t||n?e:e.filter(r=>r.type!=="thinking")}function vo(e,t){const n=new Map,r=[],c=e.length>
30?e[e.length-1]:null,s=c?.row==="block"&&c.block.kind==="phase_group"?c.key:null;for(const i of t){if(i.type!=="thinking"){r.push(i);continue}const a=_o(e,i,s);a!==null&&!n.has(a)?n.set(a,i):r.push(i)}return{adopted:n,standalone:r}}function _o(e,t,n){const r=t.seq;if(typeof r!="number"||r<=0)return n;let c=null;for(const s of e){if(s.row!=="block")continue;const i=qe(s.block),a=Dt(s.block);if(i!==null&&a!==null&&r>=i&&r<=a)return s.block.kind==="phase_group"?s.key:null;if(i!==null&&i>r)return c?.row==="block"&&c.block.kind==="phase_group"?c.key:s.block.kind==="phase_group"?s.key:null;c=s}return c?.row==="block"&&c.block.kind==="phase_group"?c.key:null}function qe(e){switch(e.kind){case"entry":case"tool_inline":case"write_diff":return He(e.entry);default:return ln(e.entries)}}function Dt(e){switch(e.kind){case"entry":case"tool_inline":case"write_diff":return He(e.entry);default:return un(e.entries)}}const yt=300,wt=200,Ge=1500;function No(e,t,n="newest"){const r=Math.min(yt+t,Ge),c=Math.max(0,yt+t-Ge),s=n==="oldest"?Math.min(c,Math.max(0,e.length-r)):Math.max(0,Math.max(r,e.length-c)-r),i=n==="oldest"?Math.min(e.length,s+r):Math.max(r,e.length-c),a=s,m=Math.max(0,e.length-i);return{visibleRows:a===0&&m===0?e:e.slice(s,i),hiddenOlder:a,hiddenNewer:m}}const Co=Ge;function ve(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function To(e,t){if(e===t)return!0;if(e.kind!==t.kind||e.key!==t.key)return!1;switch(e.kind){case"thinking_group":{const n=t;return e.anchorTs===n.anchorTs&&ve(e.entries,n.entries)}case"phase_group":{const n=t;return e.anchorTs===n.anchorTs&&ve(e.entries,n.entries)}case"discovery_group":case"batch_group":{const n=t;return ve(e.entries,n.entries)}default:{const n=t;return e.entry===n.entry}}}function So(e,t){return e===t?!0:e.row!==t.row?!1:e.row==="ghost"?e.ghost===t.ghost:To(e.block,t.block)}function Ro(e,t,n=!1){const r=[];for(const c of ko(e))yo(c,t,n)&&r.push({row:"block",key:wo(c),block:c});return r}function Oo(){return{rows:new Map,subagents:new Map}}function Ao(e,t){const n=t.rows,r=new Map;let c=null;for(let s=0;s<e.length;s++){const i=e[s],a=n.get(i.key),m=a!==void 0&&So(a,i)?a:i;c===null&&m!==i&&(c=e.slice(0,s)),c!==null&&c.push(m),r.size<Co&&r.set(i.key,m)}return t.rows=r,c??e}function Mo(e,t,n){const r=n.subagents,c=new Map,s={};for(const[i,a]of Object.entries(e)){const m=Et([],...an(a).map(x=>t[x])),d=r.get(i);
3if(d!==void 0&&d.record===a&&ve(d.entries,m)){s[i]=d.joined,c.set(i,d);continue}const h=m.length>0?{...a,entries:m}:a;s[i]=h,c.set(i,{record:a,entries:m,joined:h})}return n.subagents=c,s}const Lo=l.memo(function({item:t,isTail:n,isLive:r,liveThinking:c,planningLabel:s,subagentRecord:i,nextIsPlan:a,talk:m=!1,messageTimestamp:d,fromChatPanel:h,onOpenDiff:x,onOpenSubagent:u}){if(t.row==="ghost"){const{ghost:k}=t;return k.type==="thinking"?o.jsx(xt,{entries:[],liveThinking:k,isLive:r&&n,planningLabel:s,anchorTs:d}):o.jsx(gt,{text:m?Lt(k.text):k.text,streaming:k.status==="streaming"})}const f=t.block;if(f.kind==="tool_inline")return f.entry.tool_name==="Compact"?o.jsx(po,{entry:f.entry,hasLaterActivity:!n}):f.entry.category==="subagent"?o.jsx(Mn,{entry:f.entry,record:i,onOpen:u}):f.entry.category==="testing"||f.entry.attachments?.length?o.jsx(On,{entry:f.entry}):o.jsx(Tt,{entry:f.entry});if(f.kind==="write_diff")return o.jsx(Nn,{entry:f.entry,onOpenDiff:x,fromChatPanel:h});if(f.kind==="phase_group")return o.jsx(xt,{entries:f.entries,liveThinking:c,isLive:r&&n,planningLabel:s,anchorTs:f.anchorTs||d});if(f.kind==="discovery_group")return o.jsx(xo,{entries:f.entries,title:s});if(f.kind==="batch_group")return o.jsx(bo,{entries:f.entries});if(f.kind==="thinking_group"){const k=f.entries[f.entries.length-1],_=f.entries.map(S=>(S.content||S.message||"").trim()).filter(Boolean).join(` 4 5`);let v=null;const C=f.anchorTs||d;return C&&k.timestamp&&(v=Math.max(1,Math.round((new Date(k.timestamp).getTime()-new Date(C).getTime())/1e3))),o.jsx(oo,{text:_,streaming:!1,totalTime:v})}const j=f.entry;return j.type==="todo"&&(j.todos||[]).length>0?o.jsx(ho,{entry:j}):j.type==="system"?o.jsx(ro,{text:j.content||j.message,isError:!!j.is_error}):o.jsx(gt,{text:It(j,a,m),streaming:!1,isError:j.is_error||j.status==="error"})}),Io=new Set(["TodoWrite","TaskCreate","TaskUpdate","TaskList","TaskGet","TaskStop"]);function Do(e){return e.type==="todo"||e.tool_name&&Io.has(e.tool_name)?!0:/^\s*Task list\b/i.test(e.message||"")}const Xo=l.memo(function({metadata:t,isLast:n,isGenerating:r,messageTimestamp:c,nextMessageType:s,onOpenDiff:i,liveItems:a,liveSubagents:m,isCancelling:d,remixSetup:h,onTailAffordanceChange:x,onOpenSubagent:u,fromChatPanel:f,mode:j,gameId:k,sessionId:_,bookendRows:v,slice:C,emptyLabel:S,onEntriesChange:R}){const{t:b}=X("studio"),E=j??"tail",V=E==="bookends",te=V?null:_??t.session_id??null,$=C??nn,K=$.kind==="agent"?$.ids[0]??null:null,ee=!V&&($.kind==="main"||$.ids.length>0),N=E==="forward"?"oldest":"newest",{entries:z,hasMore:I,isLoading:T,settled:Y,loadMore:F,setRenderedEdgeSeq:W}=yn({gameId:V?null:k,sessionId:te,agentId:K,enabled:ee,direction:E==="tail"?"backward":"forward",autoAdvance:E==="full"}),ne=l.useMemo(()=>(a||[]).filter(g=>g.kind==="entry").map(g=>g.entry),[a]),G=l.useMemo(()=>(a||[]).filter(g=>g.kind==="block").map(g=>g.block),[a]),M=l.useMemo(()=>Et(z,t.activity_log,v,ne),[z,t.activity_log,v,ne]),A=l.useMemo(()=>on(M,$),[M,$]);l.useEffect(()=>{R?.({entries:M,settled:Y,hasMore:I})},[M,Y,I,R]);const fe=l.useMemo(()=>rn(M),[M]),se=l.useRef(null);se.current===null&&(se.current=Oo());const p=se.current,H=s==="plan",O=!!t?.talk,B=l.useMemo(()=>Ro(A,H,O),[A,H,O]),J=l.useMemo(()=>sn(t.subagents,m),[t.subagents,m]),me=l.useMemo(()=>Mo(J,fe,p),[J,fe,p]),L=l.useMemo(()=>{const g=new Set;return A.forEach(P=>{P.block_id&&g.add(P.block_id)}),g},[A]),q=l.useMemo(()=>G.filter(g=>!L.has(g.blockId)),[G,L]),Ue=B.length>0?B[B.length-1]:null,he=Ue?.row==="block"&&Ue.block.kind==="phase_group",Ke=l.useMemo(()=>jo(q,{isCancelling:!!d,tailIsPhase:he}),[d,he,q]),{adopted:$t,standalone:ze}=l.useMemo(()=>vo(B,Ke),[B,Ke]),ie=l.useMemo(()=>Eo(B,ze),[B,ze]),[Ye,ce]=l.useState(0);l.useEffect(()=>{ce(0)},[te,K]);const Ce=l.useMemo(()=>No(ie,Ye,N),[ie,Ye,N]),{hiddenOlder:xe,hiddenNewer:pe}=Ce,ae=l.useMemo(()=>Ao(Ce.visibleRows,p),[Ce,p]),Xe=l.useMemo(()=>{const g=E==="tail";for(let P=0;P<ae.length;P++){const D=ae[g?P:ae.length-1-P];if(D.row!=="block")continue;const Q=g?qe(D.block):Dt(D.block);if(Q!==null)return Q}return null},[ae,E]);l.useEffect(()=>{W(Xe)},[Xe,W]);const Je=l.useMemo(()=>{const g=A.length>0?A[A.length-1]:void 0,P=Object.values(me).filter(D=>D.status==="running"||D.status==="launching");if(P.length===1){if(g?.category==="subagent"&&g.tool_use_id&&g.tool_use_id===P[0].key)return null;const D=(P[0].description||"").trim();return D?b("chat.waitingOnAgent",{defaultValue:"Waiting on: {{task}}â¦",task:D}):b("chat.waitingOnAgentGeneric",{defaultValue:"Waiting on a background agentâ¦"})}if(P.length>1)return b("chat.waitingOnAgents",{defaultValue:"Waiting on {{count}} background agentsâ¦",count:P.length});for(let D=A.length-1;D>=0;D--){const Q=A[D];if(Q.status==="in_progress"&&Q.type==="tool_use"&&Q.message&&!Do(Q))return D===A.length-1?null:b("chat.waitingOnTool",{defaultValue:"Waiting on: {{task}}â¦",task:Q.message})}return b("chat.planningNextMoves",{defaultValue:"Planning next movesâ¦"})},[me,A,b]),Ft=l.useRef(null),Te=E==="tail"&&I,Se=E==="forward"&&I,Bt=l.useCallback(()=>
5{if(xe>0){ce(g=>g+wt);return}Te&&!T&&F()},[xe,Te,T,F]),Pt=l.useCallback(()=>{if(pe>0){ce(g=>g+wt);return}Se&&!T&&F()},[pe,Se,T,F]),ge=N==="oldest",Vt=!ge&&(xe>0||Te),Wt=ge&&(pe>0||Se),Gt=!ge&&pe>0,Ht=ge&&xe>0,qt=ie.length>0?ie[ie.length-1].key:null,Re=l.useRef({onOpenDiff:i,onOpenSubagent:u});Re.current={onOpenDiff:i,onOpenSubagent:u};const Ut=l.useCallback(g=>Re.current.onOpenDiff?.(g),[]),Kt=l.useCallback(g=>Re.current.onOpenSubagent?.(g),[]),zt=i?Ut:void 0,Yt=u?Kt:void 0,Xt=l.useMemo(()=>b("chat.planningNextMoves",{defaultValue:"Planning next movesâ¦"}),[b]),be=A.length===0&&q.length===0,le=n&&r,Ze=!be&&le&&!he&&(d||q.length===0&&Je!==null),Qe=!be&&le&&(Ze||he);l.useEffect(()=>{x?.(Qe)},[Qe,x]);const et=be?le?h?b("chat.settingUpRemix","Setting up your copy â copying the game filesâ¦"):b("chat.gettingStarted"):Y?S??null:b("chat.loadingActivity",{defaultValue:"Loading activityâ¦"}):null;return o.jsx(cn,{id:"ActivityFeed",children:o.jsxs("div",{ref:Ft,className:be?void 0:"mt-3 space-y-2 gottaborder",children:[et!==null&&o.jsxs("div",{className:"flex items-center w-full gap-2.5 py-2",children:[o.jsx(_e,{state:"working"}),o.jsx("p",{className:y("text-sm text-muted-foreground",(le||!Y)&&"animate-pulse"),children:et})]}),Vt&&o.jsxs("button",{type:"button",onClick:Bt,disabled:T,"aria-busy":T,className:"w-full flex items-center justify-center gap-2 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer disabled:cursor-default",children:[T&&o.jsx(w,{icon:["far","spinner-third"],className:"text-[10px] animate-spin"}),T?b("chat.loadingEarlierActivity",{defaultValue:"Loading earlier activityâ¦"}):b("chat.loadEarlierActivity",{defaultValue:"Load earlier activity"})]}),Ht&&o.jsxs("button",{type:"button",onClick:()=>ce(0),className:"w-full flex items-center justify-center gap-2 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[o.jsx(w,{icon:["far","arrow-up"],className:"text-[10px]"}),b("chat.jumpToSessionStart",{defaultValue:"Jump to the start"})]}),ae.map(g=>o.jsx("div",{children:o.jsx(Lo,{item:g,isTail:g.key===qt,isLive:le,liveThinking:$t.get(g.key)??null,planningLabel:Xt,subagentRecord:g.row==="block"&&g.block.kind==="tool_inline"&&g.block.entry.category==="subagent"?me[g.block.entry.tool_use_id||""]:void 0,nextIsPlan:H,talk:O,messageTimestamp:c,fromChatPanel:f,onOpenDiff:zt,onOpenSubagent:Yt})},g.key)),Gt&&o.jsxs("button",{type:"button",onClick:()=>ce(0),className:"w-full flex items-center justify-center gap-2 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[o.jsx(w,{icon:["far","arrow-down"],className:"text-[10px]"}),b("chat.jumpToLatestActivity",{defaultValue:"Jump to latest activity"})]}),Wt&&o.jsxs("button",{type:"button",onClick:Pt,disabled:T,"aria-busy":T,className:"w-full flex items-center justify-center gap-2 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer disabled:cursor-default",children:[T&&o.jsx(w,{icon:["far","spinner-third"],className:"text-[10px] animate-spin"}),T?b("chat.loadingMoreActivity",{defaultValue:"Loading more activityâ¦"}):b("chat.loadMoreActivity",{defaultValue:"Load more activity"})]}),Ze&&o.jsxs("div",{className:"flex items-center gap-2.5 py-1",children:[o.jsx(_e,{state:"working"}),o.jsx("span",{className:"text-sm text-shimmer",children:d?b("chat.cancelStopping",{defaultValue:"Gracefully stopping the agentâ¦"}):Je})]})]})})});export{zo as A,gn as R,oo as T,Ko as U,Xo as a,Yo as b,vn as g,An as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.