const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/RenderedNestedSessionTimeline-D8keK9V0.js","assets/rolldown-runtime-B1FJdls4.js","assets/index-BvvB7abB.js","assets/preload-helper-Bf_JiD2A.js","assets/axisEvents-Dhd0R1o7.js","assets/issueStore-B3ra7txM.js","assets/vendor-dnd-C1cICjTT.js","assets/vendor-zustand-XkaRs3NT.js","assets/browserWindowFocus-CmAEq05h.js","assets/sessionStore-DocB1wnw.js","assets/queryKeys-1VqzQyJo.js","assets/api-DwzfFfgX.js","assets/vendor-misc-z3YbaCT0.js","assets/vendor-markdown-Db1-9wH7.js","assets/serverStorage-7ZBX37kd.js","assets/posthog-DWJXNaJG.js","assets/projectPaths-CJsPUl9Q.js","assets/terminalPreloader-0zGxxbOd.js","assets/vendor-react-DKm7cazq.js","assets/index-Bx5DM-63.css","assets/RenderedTurnTranscript-DInKDJSt.js","assets/useSessionMessages-BA02D90e.js"])))=>i.map(i=>d[i]);
import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t,p as n}from"./vendor-dnd-C1cICjTT.js";import{$ as r,B as i,C as a,H as o,I as s,O as c,S as l,Y as u,b as d,h as f,nt as ee,rt as p,x as te}from"./vendor-misc-z3YbaCT0.js";import{n as m,r as h,s as g}from"./vendor-markdown-Db1-9wH7.js";import{i as _}from"./api-DwzfFfgX.js";import{t as v}from"./preload-helper-Bf_JiD2A.js";import{w as y}from"./index-BvvB7abB.js";import{t as ne}from"./ZoomablePane-ho7KGGJs.js";var re=`[axis-reference-context]`,b=`[/axis-reference-context]`,ie=[{id:`btw`,kind:`command`,label:`/btw`,detail:`Open a linked consultation agent in the right pane`,insertText:`/btw`}];function x(e,t){if(e?.kind!==`command`)return!1;let n=`/${e.query.trim()}`.toLowerCase();return t.some(e=>e.kind===`command`&&e.insertText?.trim().toLowerCase()===n)}function ae(e,t){return e?.kind===`command`&&(t===` `||t===`Spacebar`)}function oe(e){let t=e.replace(/\x1b\[200~/g,``).replace(/\x1b\[201~/g,``).replace(/\r\n?/g,`
`).trim().match(/^\/([a-z0-9_-]+)(?:[ \t]+([\s\S]*))?$/i);return t?{name:t[1].toLowerCase(),prompt:(t[2]??``).trim()}:null}function S(e,t){let n=Math.max(0,Math.min(typeof t==`number`?t:e.length,e.length)),r=e.slice(0,n),i=r.lastIndexOf(`
`)+1,a=r.slice(i),o=a.match(/^\s*\/([^\s\n]*)$/);if(o){let e=a.indexOf(`/`);return{kind:`command`,query:o[1].trimStart(),start:i+e,end:n}}let s=a.lastIndexOf(`@`);if(s<0)return null;let c=s===0?``:a[s-1];if(c&&!/\s/.test(c))return null;let l=a.slice(s+1);return l.includes(`@`)?null:{kind:`reference`,query:l.trimStart(),start:i+s,end:n}}function se(e,t,n){if(!n.insertText)return C(e,t);let r=e.slice(0,t.start),i=e.slice(t.end),a=i.length===0||!/^\s/.test(i),o=`${n.insertText}${a?` `:``}`;return{text:`${r}${o}${i}`,caret:r.length+o.length}}function C(e,t){let n=e.slice(0,t.start);return{text:`${n}${e.slice(t.end)}`,caret:n.length}}function ce(e,t){let n=ue(e).trimEnd();if(t.length===0)return n;let r=JSON.stringify({references:t.map(({kind:e,label:t,detail:n,target:r,annotation:i})=>({kind:e,display_label:t,display_detail:n,target:r,...e===`session`?{pi_session_id:r}:{},...e===`project`?{project_path:r}:{},...e===`file`?{file_path:r}:{},...e===`artifact`?{artifact_target:r}:{},annotation:i}))});return`${n}${n?`

`:``}${re}\n${r}\n${b}`}function le(e){if(!e)return[];let t=[];for(let n of e.matchAll(de()))try{let e=JSON.parse(n[1]);for(let n of e.references??[]){if(!n||typeof n!=`object`)continue;let e=n;if(!fe(e.kind)||typeof e.target!=`string`||typeof e.display_label!=`string`)continue;let r=e.target;t.push({id:`${e.kind}:${r}`,kind:e.kind,label:e.display_label,detail:typeof e.display_detail==`string`?e.display_detail:r,target:r,annotation:typeof e.annotation==`string`?e.annotation:`Referenced ${e.kind}`})}}catch{}return t}function ue(e){return e?e.replace(de(),``).trimEnd():``}function de(){return/\[axis-reference-context\]\s*([\s\S]*?)\s*\[\/axis-reference-context\]/g}function fe(e){return e===`project`||e===`session`||e===`file`||e===`artifact`}function pe(e,t){let n=w(t);return n?w(`${e.label} ${e.detail}`).includes(n):!0}function w(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,` `).replace(/\s+/g,` `)}var T=`[a-z0-9][a-z0-9._-]*\\.(?:png|jpe?g|webp|gif|avif)`,E=RegExp(`^/tmp/(?:[^/\\s'")]+/)?axis-images/(${T})$`,`i`),me=T,D=RegExp(`^/tmp/(?:[^/\\s'")]+/)?axis-workspace-screenshots/(${me})$`,`i`),O=RegExp(`^/api/terminal/workspace/screenshot/file/(${me})(?:[?#].*)?$`,`i`),k=`(?:\\.axis/artifacts|\\.pi/(?:mission-control-artifacts|axis-artifacts))`,he=RegExp(`^/home/[^/\\s]+/${k}/([^/\\s'")]+)/(${T})$`,`i`),A=`[a-z0-9][a-z0-9._-]*\\.(?:mp4|webm|mov|m4v)`,ge=RegExp(`^/home/[^/\\s]+/${k}/([^/\\s'")]+)/(${A})$`,`i`),_e=RegExp(`^/api/artifacts/([^/\\s'")]+)/(${A})(?:[?#].*)?$`,`i`);function ve(){return RegExp(`/tmp/(?:[^/\\s)'"]+/)?axis-images/${T}`,`gi`)}function ye(){return RegExp(`/tmp/(?:[^/\\s)'"]+/)?axis-workspace-screenshots/${me}`,`gi`)}function be(){return RegExp(`/api/terminal/workspace/screenshot/file/${me}`,`gi`)}function xe(){return RegExp(`/home/[^/\\s]+/${k}/[^/\\s)'"]+/${T}`,`gi`)}function Se(){return RegExp(`/home/[^/\\s]+/${k}/[^/\\s)'"]+/${A}`,`gi`)}function Ce(){return RegExp(`/api/artifacts/[^/\\s)'"]+/${A}`,`gi`)}function j(e){return e.trim().replace(/[),.;:!?]+$/g,``)}function we(e){let t=j(e).match(E);if(t)return`/api/upload-image/file/${encodeURIComponent(t[1])}`}function Te(e){let t=j(e),n=t.match(D);if(n)return`/api/terminal/workspace/screenshot/file/${encodeURIComponent(n[1])}`;let r=t.match(O);if(r)return`/api/terminal/workspace/screenshot/file/${encodeURIComponent(decodeURIComponent(r[1]))}`}function Ee(e){let t=j(e).match(he);if(t)return`/api/artifacts/${encodeURIComponent(t[1])}/${encodeURIComponent(t[2])}`}function De(e){return we(e)??Te(e)??Ee(e)}function Oe(e){let t=j(e),n=t.match(ge);if(n)return`/api/artifacts/${encodeURIComponent(n[1])}/${encodeURIComponent(n[2])}`;let r=t.match(_e);if(r)return`/api/artifacts/${encodeURIComponent(decodeURIComponent(r[1]))}/${encodeURIComponent(decodeURIComponent(r[2]))}`}function ke(e){let t=[Se(),Ce()].flatMap(t=>Array.from(e.matchAll(t),e=>({value:j(e[0]),index:e.index??0}))).sort((e,t)=>e.index-t.index),n=new Set,r=[];for(let e of t)n.has(e.value)||(n.add(e.value),r.push(e.value));return r}function Ae(e){return Array.from(e.matchAll(ve()),e=>j(e[0]))}function je(e){let t=[ve(),ye(),be(),xe()].flatMap(t=>Array.from(e.matchAll(t),e=>({value:j(e[0]),index:e.index??0}))).sort((e,t)=>e.index-t.index),n=new Set,r=[];for(let e of t)n.has(e.value)||(n.add(e.value),r.push(e.value));return r}function Me(e,t){return t.reduce((e,t)=>e.replace(t,``),e).replace(/[ \t]+\n/g,`
`).replace(/\n[ \t]+/g,`
`).replace(/[ \t]{2,}/g,` `).replace(/\n{3,}/g,`

`).trim()}function Ne(e){return Me(e,[ve()])}function Pe(e){return Me(e,[ve(),ye(),be(),xe(),Se(),Ce()])}function Fe(e){if(!e)return;let t=e.match(/^\/api\/upload-image\/file\/([^?#]+)([?#].*)?$/i);if(!t)return e;let n=decodeURIComponent(t[1]).match(/^([a-z0-9][a-z0-9._-]*?)(?:-64|-128|-384)?\.(png|jpe?g|webp|avif)$/i);return n?`/api/upload-image/file/${encodeURIComponent(`${n[1]}-384.webp`)}`:e}function Ie(e){return Fe(we(e))}function Le(e){return e.sourceUrl?.startsWith(`/api/upload-image/file/`)?e.sourceUrl:e.previewUrl}var Re=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function ze(e){return typeof e==`string`&&Re.includes(e)}function Be(e){return e.replace(/^\[Axis [^\]]+\]\s*/i,``)}var M=g(),Ve={project:`Project`,session:`Pi session`,file:`File`,artifact:`Artifact`},He={project:`⌂`,session:`◌`,file:`⌘`,artifact:`◇`};function Ue({references:e,onRemove:t,compact:n=!1}){return e.length===0?null:(0,M.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5 ${n?`mb-2`:`px-2 pb-1 pt-0.5`}`,"data-testid":t?`pi-composer-reference-pills`:`pi-message-reference-pills`,children:e.map(e=>{let r=`${Ve[e.kind]} · ${e.detail}\n${e.target}\n${e.annotation}`;return(0,M.jsxs)(`span`,{className:`group/reference inline-flex max-w-full items-center rounded-full border border-terminal-cyan/25 bg-terminal-cyan/[0.08] text-terminal-cyan shadow-sm shadow-black/10 ${n?`h-6 gap-1 px-2 text-[10px]`:`h-7 gap-1.5 pl-2.5 pr-1 text-[11px]`}`,title:r,"data-reference-kind":e.kind,"data-reference-target":e.target,children:[(0,M.jsx)(`span`,{className:`shrink-0 text-terminal-cyan/70`,"aria-hidden":`true`,children:He[e.kind]}),(0,M.jsx)(`span`,{className:`min-w-0 max-w-[240px] truncate font-medium`,children:e.label}),t?(0,M.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`grid h-5 w-5 shrink-0 place-items-center rounded-full text-terminal-muted/70 transition-colors hover:bg-terminal-cyan/15 hover:text-terminal-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-terminal-cyan/60`,"aria-label":`Remove ${e.label} reference`,title:`Remove ${e.label}`,"data-testid":`pi-composer-reference-remove`,children:(0,M.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,M.jsx)(`path`,{d:`m3 3 6 6M9 3 3 9`})})}):null]},e.id)})})}var N=e(t(),1);function We(e){return e.status===`aborted`||e.status===`stopping`||e.status===`stop_failed`}function Ge(e){return e.status===`aborted`?{label:/stopped/i.test(e.lastError??``)?`Current process stopped`:`Agent operation aborted`,detail:e.lastError??`Press Continue to resume.`,tone:`red`}:e.status===`stopping`?{label:`Stopping agent`,detail:e.lastError??`Sending Pi interrupt…`,tone:`yellow`}:e.status===`stop_failed`?{label:`Stop failed`,detail:e.lastError??`Could not deliver Pi interrupt.`,tone:`red`}:{label:`Agent unavailable`,detail:e.lastError??`The agent stopped unexpectedly.`,tone:`red`}}function Ke(e){return e===`red`?{text:`text-terminal-red/85`,dot:`bg-terminal-red animate-pulse shadow-[0_0_8px_rgba(239,68,68,0.55)]`,border:`border-terminal-red/35`,bg:`bg-terminal-red/[0.06]`}:e===`green`?{text:`text-terminal-green/80`,dot:`bg-terminal-green shadow-[0_0_8px_rgba(34,197,94,0.55)]`,border:`border-terminal-green/25`,bg:`bg-terminal-green/[0.04]`}:e===`cyan`?{text:`text-terminal-cyan/80`,dot:`bg-terminal-cyan animate-pulse shadow-[0_0_8px_rgba(34,211,238,0.55)]`,border:`border-terminal-cyan/25`,bg:`bg-terminal-cyan/[0.04]`}:{text:`text-terminal-yellow/80`,dot:`bg-terminal-yellow animate-pulse shadow-[0_0_8px_rgba(234,179,8,0.55)]`,border:`border-terminal-yellow/25`,bg:`bg-terminal-yellow/[0.04]`}}var qe=N.memo(function({state:e}){let t=Ge(e),n=Ke(t.tone);return We(e)?(0,M.jsx)(`div`,{className:`mr-auto flex max-w-full flex-wrap items-center gap-2 px-1 py-0.5 font-mono text-[10px] font-bold uppercase tracking-[0.16em] ${n.text}`,"data-testid":`pi-rendered-live-input-status`,"data-status":e.status,"data-intent-status":e.intentStatus,"aria-live":`polite`,title:t.detail,children:(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,M.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${n.dot}`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`shrink-0 text-terminal-muted/70`,children:t.label}),(0,M.jsx)(`span`,{className:`truncate text-terminal-muted/60 normal-case font-normal tracking-normal`,children:t.detail})]})}):null},(e,t)=>e.state.status===t.state.status&&e.state.pendingCount===t.state.pendingCount&&e.state.lastError===t.state.lastError&&e.state.intentStatus===t.state.intentStatus);function Je(e){let t=(e??``).replace(/\r/g,`
`).split(`
`).map(e=>e.trim()).filter(Boolean).at(-1)??``;return/^(?:[✕×x!\s-]*)?(?:agent |pi )?(?:operation |request |generation )?aborted\.?$/i.test(t)?t:null}function Ye({abortState:e,onContinue:t,compact:n=!1}){let r=/stopped/i.test(e.message);return(0,M.jsxs)(`div`,{className:`${n?`mr-auto max-w-full`:`mx-auto my-auto max-w-xl`} flex items-center gap-3 px-1 py-1 font-mono text-[11px]`,"data-testid":`pi-rendered-abort-notice`,"aria-live":`assertive`,title:e.message,children:[(0,M.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-terminal-yellow animate-pulse`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`font-bold uppercase tracking-[0.14em] text-terminal-yellow`,children:r?`Current process stopped`:`Agent operation aborted`}),(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`shrink-0 rounded-md border border-terminal-yellow/40 px-2 py-1 text-[10px] font-bold uppercase tracking-[0.12em] text-terminal-yellow transition-colors hover:bg-terminal-yellow/10 active:scale-95`,"data-testid":`pi-rendered-continue-after-abort`,children:`Continue`})]})}function Xe(e=[],t=[]){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(!r||!i||r.id!==i.id||r.name!==i.name||r.path!==i.path||r.previewUrl!==i.previewUrl||r.mimeType!==i.mimeType||r.uploadStatus!==i.uploadStatus||r.uploadProgress!==i.uploadProgress||r.error!==i.error||r.processingError!==i.processingError||r.analysis!==i.analysis||JSON.stringify(r.keyframes??[])!==JSON.stringify(i.keyframes??[]))return!1}return!0}var Ze=n();function Qe(e){return De(e)??null}function $e(e){let t=e.trim().replace(/[),.;:!?]+$/g,``).match(/^\/tmp\/axis-videos\/(pi-video-[^\s/'\")]+\.(?:mp4|mpeg|mpg|mov|webm))$/i);return t?`/api/upload-video/file/${encodeURIComponent(t[1])}`:null}function P(e){return e.split(`/`).pop()||`pasted image`}function et(e){let t=e.split(`.`).pop()?.toLowerCase();return t===`jpg`||t===`jpeg`?`image/jpeg`:t?`image/${t}`:`image/png`}function tt(e){let t=e.split(`.`).pop()?.toLowerCase();return t===`mov`?`video/quicktime`:t===`webm`?`video/webm`:t===`mpeg`||t===`mpg`?`video/mpeg`:`video/mp4`}function nt(e,t){let n=e.replace(/[),.;:!?]+$/g,``),r=Qe(n);return r?{kind:`attachment`,id:`${t}-${n}`,name:P(n),size:0,path:n,mimeType:et(n),previewUrl:r,sourceUrl:r,uploadStatus:`ready`}:null}function rt(e){let t=e.textContent??``,n=new Map;for(let e of je(t)){let t=nt(e,`inline-proof-image`);!t?.previewUrl||n.has(t.previewUrl)||n.set(t.previewUrl,t)}for(let e of ke(t)){let t=e.replace(/[),.;:!?]+$/g,``),r=Oe(t);!r||n.has(r)||n.set(r,{kind:`attachment`,id:`inline-proof-video-${t}`,name:P(t),size:0,path:t,mimeType:tt(t),previewUrl:r,sourceUrl:r,uploadStatus:`ready`})}return[...n.values()]}function it(e){let t=new Map,n=[];for(let r of e.optimisticAttachments??[])r.path?t.set(r.path,r):(r.previewUrl||r.uploadStatus||r.mimeType?.startsWith(`image/`)||r.mimeType?.startsWith(`video/`))&&n.push(r);let r=e.textContent??``,i=Ae(r);for(let e of i){let n=e.replace(/[),.;:!?]+$/g,``);if(t.has(n))continue;let r=Qe(n);r&&t.set(n,{kind:`attachment`,id:`jsonl-image-${n}`,name:P(n),size:0,path:n,mimeType:et(n),previewUrl:r})}let a=r.match(/\/tmp\/axis-videos\/pi-video-[^\s)'\"]+\.(?:mp4|mpeg|mpg|mov|webm)/gi)??[];for(let e of a){let n=e.replace(/[),.;:!?]+$/g,``);if(t.has(n))continue;let r=$e(n);r&&t.set(n,{kind:`attachment`,id:`jsonl-video-${n}`,name:P(n),size:0,path:n,mimeType:tt(n),previewUrl:r,uploadStatus:`ready`})}let o=[...r.matchAll(/\[video\]([\s\S]*?)\[\/video\]/gi)];for(let e of o){let n=e[1]??``,r=n.match(/^path:\s*(.+)$/im)?.[1]?.trim();if(!r)continue;let i=t.get(r);if(!i)continue;let a=n.match(/^name:\s*(.+)$/im)?.[1]?.trim()||i.name,o=n.match(/^model:\s*(.+)$/im)?.[1]?.trim()||i.model,s=n.match(/transcript_or_analysis:\s*\n?([\s\S]*?)(?:\nprocessing_error:|$)/i),c=n.match(/processing_error:\s*\n?([\s\S]*?)$/i);t.set(r,{...i,name:a,model:o,analysis:s?.[1]?.trim()||i.analysis,processingError:c?.[1]?.trim()||i.processingError,uploadStatus:`ready`})}let s=new Set(t.keys()),c=[...t.values()],l=new Set,u=e=>{if(e.path||e.uploadStatus===`error`)return!1;let t=e.mimeType?.split(`/`)[0]??``,n=c.findIndex((n,r)=>l.has(r)||t&&!n.mimeType?.startsWith(`${t}/`)?!1:n.name===e.name||n.mimeType===e.mimeType||t===`image`||t===`video`);return n<0?!1:(l.add(n),!0)};return[...n.filter(e=>e.path?!s.has(e.path):!u(e)),...c]}var at=N.memo(function({attachment:e,fit:t=`cover`}){let n=Fe(e.previewUrl),[r,i]=(0,N.useState)(!1);return(0,N.useEffect)(()=>i(!1),[n]),(0,M.jsx)(`img`,{src:r?e.previewUrl:n,alt:e.name,className:`transition-transform duration-150 group-hover/image:scale-[1.015] ${t===`natural`?`h-auto w-full object-contain`:t===`contain`?`h-full w-full object-contain`:`h-full w-full object-cover`}`,loading:`lazy`,decoding:`async`,draggable:!1,onError:()=>i(!0)})});function ot({attachment:e,canNavigate:t=!1,currentIndex:n=-1,totalCount:r=0,onPrevious:i,onNext:a,onClose:o}){(0,N.useEffect)(()=>{let e=e=>{e.key===`Escape`?(e.preventDefault(),o()):e.key===`ArrowLeft`&&t?(e.preventDefault(),i?.()):e.key===`ArrowRight`&&t&&(e.preventDefault(),a?.())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,o,a,i]),(0,N.useLayoutEffect)(()=>{let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[]);let s=Le(e),c=e.mimeType?.startsWith(`video/`)??!1;return s?(0,Ze.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[2147483647] flex flex-col bg-black/92 text-white backdrop-blur-sm`,role:`dialog`,"aria-modal":`true`,"aria-label":`${e.name} image preview`,onClick:e=>{e.target===e.currentTarget&&o()},"data-testid":`pi-rendered-image-preview-overlay`,children:[(0,M.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 border-b border-white/10 bg-black/55 px-3 sm:px-4`,children:[(0,M.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,M.jsx)(`div`,{className:`truncate font-mono text-xs font-bold text-white`,title:e.name,children:e.name}),(0,M.jsx)(`div`,{className:`truncate font-mono text-[10px] text-white/45`,title:e.path,children:e.path})]}),t?(0,M.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 font-mono text-[10px] text-white/60`,"data-testid":`pi-rendered-image-preview-nav`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),i?.()},className:`flex h-9 w-9 items-center justify-center rounded-full border border-white/15 bg-white/10 text-lg text-white transition-colors hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-terminal-cyan/80`,"aria-label":`Previous image`,title:`Previous image (Left arrow)`,"data-testid":`pi-rendered-image-preview-previous`,children:`←`}),(0,M.jsxs)(`span`,{className:`hidden min-w-[4.5rem] text-center sm:inline`,children:[n+1,` / `,r]}),(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),a?.()},className:`flex h-9 w-9 items-center justify-center rounded-full border border-white/15 bg-white/10 text-lg text-white transition-colors hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-terminal-cyan/80`,"aria-label":`Next image`,title:`Next image (Right arrow)`,"data-testid":`pi-rendered-image-preview-next`,children:`→`})]}):null,(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),o()},className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-white/20 bg-white/10 text-2xl leading-none text-white shadow-lg transition-colors hover:bg-white/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-terminal-cyan/80`,"aria-label":`Close image preview`,title:`Close`,"data-testid":`pi-rendered-image-preview-close`,children:`×`})]}),c?(0,M.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center bg-black p-3 sm:p-6`,children:(0,M.jsx)(`video`,{src:s,controls:!0,autoPlay:!0,playsInline:!0,className:`max-h-full max-w-full shadow-2xl shadow-black`,"data-testid":`pi-rendered-video-preview`})}):(0,M.jsx)(ne,{className:`min-h-0 flex-1 bg-black`,contentClassName:`flex items-center justify-center p-3 sm:p-6`,title:`Pinch/trackpad zoom, then drag to pan this image`,children:(0,M.jsx)(`img`,{src:s,alt:e.name,className:`max-h-full max-w-full select-none object-contain shadow-2xl shadow-black`,draggable:!1})})]}),document.body):null}var F=N.memo(function({attachments:e,onRemove:t,variant:n=`grid`}){let[r,i]=(0,N.useState)(null),a=(0,N.useMemo)(()=>e.filter(e=>e.mimeType?.startsWith(`image/`)&&e.previewUrl),[e]),o=(0,N.useCallback)(e=>{i(e)},[]),s=(0,N.useCallback)(e=>{i(t=>{if(!t||a.length<2)return t;let n=a.findIndex(e=>e.id===t.id);return a[n>=0?(n+e+a.length)%a.length:0]??t})},[a]);if(e.length===0)return null;let c=n===`proof`,l=n===`message`;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:c?`mb-3 flex flex-wrap gap-2`:l?`mb-2 flex max-w-full flex-wrap justify-end gap-2`:`mb-3 grid grid-cols-2 gap-2 sm:grid-cols-3`,"data-testid":c?`pi-rendered-proof-image-grid`:l?`pi-rendered-message-attachment-strip`:`pi-rendered-attachment-grid`,children:e.map(e=>{let n=e.mimeType?.startsWith(`image/`)&&e.previewUrl,r=e.mimeType?.startsWith(`video/`)&&e.previewUrl,i=e.path&&e.uploadStatus&&e.uploadStatus!==`error`&&e.uploadStatus!==`processing`?`ready`:e.uploadStatus;return(0,M.jsxs)(`div`,{className:`relative overflow-hidden ${c?`w-full max-w-[420px] rounded-lg`:l?`h-32 w-32 shrink-0 rounded-2xl border border-terminal-border/70 bg-terminal-bg/60 shadow-sm sm:h-40 sm:w-40`:`rounded-lg border border-terminal-cyan/20 bg-terminal-bg/60`}`,children:[n?(0,M.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),o(e)},className:`group/image relative block w-full overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-terminal-cyan/70 ${c?``:l?`h-full bg-black/10`:`h-24`}`,title:`Open ${e.name} image preview`,"aria-label":`Open ${e.name} image preview`,"data-testid":c?`pi-rendered-proof-image-thumbnail`:`pi-rendered-image-thumbnail`,children:(0,M.jsx)(at,{attachment:e,fit:c?`natural`:`cover`})}):r?(0,M.jsxs)(`div`,{className:`group/video relative`,children:[(0,M.jsx)(`video`,{src:e.previewUrl,controls:!0,muted:!0,preload:`metadata`,className:`${c?`h-56 sm:h-72`:l?`h-full`:`h-24`} w-full bg-black object-contain`,"data-testid":`pi-rendered-video-thumbnail`}),(0,M.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),o(e)},className:`absolute right-1.5 top-1.5 z-10 flex h-7 w-7 items-center justify-center rounded-full border border-white/20 bg-black/70 text-xs text-white opacity-0 transition-opacity focus-visible:opacity-100 focus-visible:outline-none group-hover/video:opacity-100`,title:`Expand ${e.name}`,"aria-label":`Expand ${e.name}`,"data-testid":`pi-rendered-video-expand`,children:`⤢`})]}):(0,M.jsx)(`div`,{className:`flex items-center justify-center text-2xl text-terminal-muted ${l?`h-full`:`h-24`}`,children:`📎`}),t&&(0,M.jsx)(`button`,{type:`button`,onClick:n=>{n.preventDefault(),n.stopPropagation(),t(e.id)},className:`absolute right-1.5 top-1.5 z-10 flex h-6 w-6 items-center justify-center rounded-full border border-black/50 bg-black/75 shadow-lg transition-colors hover:bg-terminal-red`,title:`Remove ${e.name}`,"aria-label":`Remove ${e.name}`,"data-testid":`pi-rendered-remove-attachment`,children:(0,M.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`#fff`,strokeOpacity:`0.92`,strokeWidth:`1.5`,strokeLinecap:`round`,"aria-hidden":`true`,children:(0,M.jsx)(`path`,{d:`M7 7l10 10M17 7 7 17`})})}),!l&&!c&&(0,M.jsxs)(`div`,{className:`space-y-0.5 border-t border-terminal-cyan/10 px-2 py-1.5`,children:[(0,M.jsx)(`div`,{className:`truncate font-mono text-[10px] text-terminal-text`,title:e.name,children:e.name}),(0,M.jsx)(`div`,{className:`truncate font-mono text-[9px] text-terminal-muted`,title:e.path,children:e.path}),i&&i!==`ready`&&(0,M.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 rounded border px-2 py-1 font-mono text-[9px] ${i===`error`?`border-red-500/30 bg-red-500/10 text-red-300`:`border-terminal-cyan/20 bg-terminal-cyan/10 text-terminal-cyan/80`}`,children:[(0,M.jsx)(`span`,{className:`truncate`,children:i===`error`?e.error||e.processingError||`Upload failed`:i===`processing`?e.mimeType?.startsWith(`video/`)?`Processing with AI…`:`Processing…`:`Uploading${e.mimeType?.startsWith(`video/`)?` video`:e.mimeType?.startsWith(`image/`)?` image`:``}${typeof e.uploadProgress==`number`&&!e.mimeType?.startsWith(`image/`)?` ${e.uploadProgress}%`:``}…`}),i===`error`&&e.onRetry&&(0,M.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),e.onRetry?.()},className:`shrink-0 rounded border border-red-400/40 px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-wider text-red-200 hover:bg-red-400/15`,title:`Retry upload`,"aria-label":`Retry ${e.name} upload`,children:`↻ Retry`}),i===`uploading`&&typeof e.uploadProgress==`number`&&!e.mimeType?.startsWith(`image/`)&&(0,M.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-1 bg-terminal-cyan/10`,"aria-hidden":`true`,children:(0,M.jsx)(`div`,{className:`h-full rounded-r-full bg-terminal-cyan transition-[width] duration-150 ease-out`,style:{width:`${Math.max(1,Math.min(100,e.uploadProgress))}%`}})})]}),e.mimeType?.startsWith(`video/`)&&e.keyframes&&e.keyframes.length>0&&(0,M.jsx)(`div`,{className:`mt-1 grid grid-cols-3 gap-1`,children:e.keyframes.slice(0,6).map((t,n)=>(0,M.jsxs)(`button`,{type:`button`,onClick:r=>{r.preventDefault(),r.stopPropagation(),o({...e,id:`${e.id}-keyframe-${n}`,name:`${e.name} keyframe ${n+1} (${t.timestampSec}s)`,path:t.path,previewUrl:t.previewUrl,mimeType:`image/jpeg`})},className:`relative h-12 overflow-hidden rounded border border-terminal-cyan/15 bg-black focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-terminal-cyan/70`,title:`Open keyframe ${n+1} at ${t.timestampSec}s`,children:[(0,M.jsx)(`img`,{src:t.previewUrl,alt:`Keyframe ${n+1}`,className:`h-full w-full object-cover`,loading:`lazy`,draggable:!1}),(0,M.jsxs)(`span`,{className:`absolute bottom-0 right-0 bg-black/75 px-1 font-mono text-[8px] text-white/80`,children:[t.timestampSec,`s`]})]},`${t.path}-${n}`))}),e.mimeType?.startsWith(`video/`)&&e.analysis&&(0,M.jsxs)(`div`,{className:`mt-1 max-h-24 overflow-y-auto whitespace-pre-wrap rounded border border-terminal-cyan/15 bg-terminal-cyan/[0.04] px-2 py-1 font-mono text-[9px] text-terminal-cyan/80`,title:e.analysis,children:[`Transcript / analysis:\\n`,e.analysis]}),e.mimeType?.startsWith(`video/`)&&e.processingError&&!e.error&&(0,M.jsx)(`div`,{className:`mt-1 truncate font-mono text-[9px] text-amber-300`,title:e.processingError,children:e.processingError})]})]},e.id)})}),r?(0,M.jsx)(ot,{attachment:r,canNavigate:a.length>1&&a.some(e=>e.id===r.id),currentIndex:a.findIndex(e=>e.id===r.id),totalCount:a.length,onPrevious:()=>s(-1),onNext:()=>s(1),onClose:()=>i(null)}):null]})},(e,t)=>e.onRemove===t.onRemove&&e.variant===t.variant&&Xe(e.attachments,t.attachments)),st=N.memo(function({attachments:e,onRemove:t}){return(0,M.jsxs)(`div`,{className:`ml-auto max-w-[92%] rounded-xl border border-terminal-cyan/25 bg-terminal-cyan/[0.035] px-4 py-3 shadow-sm`,"data-testid":`pi-rendered-attachment-draft`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-mono text-[10px] font-bold uppercase tracking-wider text-terminal-cyan`,children:[(0,M.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-terminal-cyan animate-pulse`}),(0,M.jsx)(`span`,{children:`Attached — add text, then Send`})]}),(0,M.jsx)(F,{attachments:e,onRemove:t})]})},(e,t)=>e.onRemove===t.onRemove&&Xe(e.attachments,t.attachments));function ct(e){return(e?.name??``).split(`.`).pop()?.replace(/[^a-z0-9]/gi,``).toLowerCase()??``}function lt(e){let t=ct(e);return t===`askclaude`?`claude`:t===`askgpt`?`gpt`:null}function ut(e){return lt(e)!==null}function dt(e,t,n){return t.id?.trim()||`${e}:${n}`}function I(e,t){if(typeof e!=`string`)return;let n=e.replace(/\s+/g,` `).trim();if(n)return n.length>t?`${n.slice(0,t-1).trim()}…`:n}function ft(e){return e.nativeStatus===`running`?`active`:e.nativeStatus===`failed`?`failed`:e.nativeStatus===`completed`?`completed`:e.isError?`failed`:e.result!==void 0||e.resultText!==void 0?`completed`:`active`}var pt=/<!-- mc-consultation-session:(\{[^\n]+\}) -->/;function mt(e){return!e.result||typeof e.result!=`object`||Array.isArray(e.result)?null:e.result}function ht(e){let t=mt(e);if(!t)return null;let n=t.details;return n&&typeof n==`object`&&!Array.isArray(n)?n:t}function gt(e){let t=typeof e.resultText==`string`?e.resultText.match(pt):null;if(t?.[1])try{let e=JSON.parse(t[1]);if(e&&typeof e==`object`)return e}catch{}let n=ht(e);return{sessionId:I(n?.sessionId,80),sessionFilePath:I(n?.sessionFilePath,500),cwd:I(n?.cwd,500)}}function _t(e){if(typeof e.resultText==`string`&&e.resultText.trim())return e.resultText.replace(pt,``).trim();if(typeof e.result==`string`&&e.result.trim())return e.result.trim();let t=ht(e)?.output;if(typeof t==`string`&&t.trim())return t.trim();let n=mt(e)?.content;if(Array.isArray(n)){let e=n.flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.text;return typeof t==`string`?[t]:[]}).join(`
`).trim();if(e)return e}if(!(e.result===void 0||e.result===null))try{let t=JSON.stringify(e.result,null,2);return t===`{}`?void 0:t}catch{return String(e.result)}}function vt(e,t,n,r){let i=lt(n);if(!i)return null;let a=dt(e,n,r),o=gt(n),s=ht(n),c=typeof n.arguments?.prompt==`string`&&n.arguments.prompt.trim()||void 0,l=I(c,180),u=`[Consultation] ${i===`claude`?`Claude`:`GPT`}${l?` · ${l.slice(0,72)}`:``}`;return{id:a,messageId:e,toolCallId:a,provider:i,title:I(s?.sessionTitle,180)??u,prompt:c,promptPreview:l,response:_t(n),sessionId:o.sessionId,sessionFilePath:o.sessionFilePath,cwd:o.cwd,model:I(n.arguments?.model,64)??I(s?.model,64),mode:I(n.arguments?.mode,32)??I(s?.mode,32),status:ft(n),createdAt:t}}function yt(e){let t=[];for(let n of e)for(let[e,r]of(n.toolCalls??[]).entries()){let i=vt(n.id,n.timestamp,r,e);i&&t.push(i)}return t}function bt(e){return{displayText:e.text,revealing:!1}}var xt=new Set,St=new Set,Ct=new Set;function wt(e){return Ct.add(e),()=>{Ct.delete(e)}}function Tt(e){return e.startsWith(`narration:`)?e:`narration:${e}`}function Et(e){let{enabled:t,messageId:n,text:r,timestamp:i,now:a=Date.now()}=e;if(!t||!n||xt.has(n)||r.trim().length<24)return!1;if(i!=null){let e=typeof i==`number`?i:Date.parse(String(i));if(Number.isFinite(e)&&a-e>45e3)return xt.add(n),!1}return!0}function Dt(e){let t=Tt(e.messageId);return xt.has(t)?!1:St.has(t)?!0:Et({enabled:e.enabled,messageId:t,text:e.text,timestamp:e.timestamp,now:e.now})}function Ot(e,t){if(!t.enabled||e.length===0)return e;let n=[];for(let r of e){if(r.kind===`narration`){if(n.push(r),Dt({enabled:t.enabled,messageId:String(r.messageId??``),text:String(r.text??``),timestamp:typeof r.timestamp==`string`?r.timestamp:void 0,now:t.now}))break;continue}n.push(r)}return n}function kt(){return(0,M.jsx)(`span`,{className:`mc-reveal-caret ml-px inline-block w-[2px] shrink-0 bg-terminal-cyan/85 align-[-0.18em]`,style:{height:`1.05em`},"aria-hidden":`true`,"data-testid":`pi-rendered-assistant-reveal-caret`})}var At=(0,N.lazy)(()=>v(()=>import(`./RenderedNestedSessionTimeline-D8keK9V0.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])));function jt(e,t){let n=e[0],r=e.flatMap(e=>e.kind===`message`?[e.message]:e.messages),i=e.flatMap(e=>e.toolCalls);return{kind:`toolGroup`,id:t,timestamp:n?n.kind===`message`?n.message.timestamp:n.timestamp:new Date(0).toISOString(),previousTimestamp:n?.previousTimestamp,messages:r,toolCalls:i}}function Mt(e){let t=(e?.name??``).toLowerCase();return t===`axis_handoff`||t.endsWith(`.axis_handoff`)}function Nt(e){let t=(e?.name??``).toLowerCase();return t===`axis_spawn_subagents`||t.endsWith(`.axis_spawn_subagents`)}function Pt(e){return Mt(e)||Nt(e)}function L(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():null}function Ft(e,t){let n=t?.arguments,r=L(n,`issue_id`);if(r&&e.issue_id===r)return!0;let i=L(n,`cwd`)??L(n,`project_path`);if(i&&e.cwd===i)return!0;let a=L(n,`issue_title`);if(a&&e.title.toLowerCase().includes(a.toLowerCase().slice(0,30)))return!0;let o=L(n,`initial_prompt`);return o&&e.lastActivitySummary?.toLowerCase().includes(o.toLowerCase().slice(0,40))?!0:!r&&!i&&!a&&!o}function It(e){let t=e?.arguments?.slices;return Array.isArray(t)?t.flatMap(e=>{if(typeof e==`string`)return[e];if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e;return[L(t,`title`),L(t,`prompt`),L(t,`task`),L(t,`description`)].filter(e=>!!e)}):[]}function Lt(e,t){let n=`${e.title} ${e.lastActivitySummary??``} ${e.recommended_next_step??``}`.toLowerCase();return It(t).some(e=>{let t=e.toLowerCase().replace(/\s+/g,` `).trim().slice(0,42);return t.length>=8&&n.includes(t)})}function Rt(e){if(e.role!==`assistant`||(e.optimisticAttachments?.length??0)>0)return!1;let t=e.toolCalls??[];return t.length===0?!1:!t.some(Pt)}function zt(e){let t=e?.trim()??``;if(!t)return!1;let n=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),r=/^```/.test(t)||/^[{[]/.test(t)||/^(?:import|export|const|let|var|function|class|interface|type|expect)\b/.test(n[0]??``);if(n.filter(e=>/^\|.*\|$/.test(e)).length>=2)return!0;if(r)return!1;let i=t.replace(/!\[[^\]]*\]\([^)]*\)/g,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/[`*_>#~]+/g,` `).replace(/\s+/g,` `).trim(),a=i.split(/\s+/).filter(Boolean).length,o=(i.match(/[.!?](?:\s|$)/g)??[]).length;return a>=28||i.length>=220||/\n\s*\n/.test(t)&&a>=18||o>=2&&a>=22}function Bt(e){let t=zt(e.thinking),n=zt(e.textContent);if(!t&&!n)return null;let r=[t?e.thinking?.trim():``,n?e.textContent?.trim():``].filter(Boolean).join(`

`);return{visibleMessage:{...e,thinking:``,textContent:r,toolCalls:[]},workMessage:{...e,thinking:t?``:e.thinking,textContent:n?``:e.textContent}}}function Vt(e){return typeof e.arguments?.action==`string`?e.arguments.action.toLowerCase():null}function Ht(e){let t=e.arguments?.id;return typeof t==`number`&&Number.isFinite(t)?t:typeof t==`string`&&t.trim()&&Number.isFinite(Number(t))?Number(t):null}function Ut(e){return((e.name??``).toLowerCase().split(`.`).pop()??``)===`todo`}function Wt(e){let t=[],n=[],r,i=new Map,a=1,o=e=>(e.toolCalls??[]).map((t,n)=>{let r=Ut(t)?Vt(t):null,o=Ht(t),s=typeof t.arguments?.text==`string`?t.arguments.text.trim():``,c={tc:t,messageId:e.id,index:n,timestamp:e.timestamp,todoTitle:r===`add`?s||void 0:o?i.get(o):void 0};return Ut(t)&&(r===`clear`?(i.clear(),a=1):r===`add`?(s&&i.set(a,s),a+=1):r===`update`&&o&&s?i.set(o,s):r===`remove`&&o&&i.delete(o)),c}),s=()=>{if(n.length===0)return;let e=n.map(e=>e.message),r=n.flatMap(e=>e.toolCalls);t.push({kind:`toolGroup`,id:`tool-group-${e[0].id||t.length}`,timestamp:e[0].timestamp,previousTimestamp:n[0].previousTimestamp,messages:e,toolCalls:r}),n=[]};for(let i of e){let e=o(i),a={kind:`message`,previousTimestamp:r,message:i,toolCalls:e};if(r=i.timestamp,Rt(i)){let r=Bt(i);if(r){s(),t.push({kind:`message`,previousTimestamp:a.previousTimestamp,message:r.visibleMessage,toolCalls:[],promotedNarration:!0}),n.push({kind:`message`,previousTimestamp:i.timestamp,message:r.workMessage,toolCalls:e});continue}n.push(a);continue}s(),t.push(a)}return s(),t}function Gt(e,t){let n=new Map;if(t.length===0)return n;let r=[...t].sort((e,t)=>(new Date(e.startedAt).getTime()||0)-(new Date(t.startedAt).getTime()||0)),i=new Set;for(let t of e){let e=(t.toolCalls??[]).filter(Pt);if(e.length===0)continue;let a=new Date(t.timestamp).getTime()||0,o=[];for(let t of e){let e=Nt(t),n=r.find(n=>{if(i.has(n.id))return!1;let r=new Date(n.startedAt).getTime()||0;return!a||!r||r>=a-3e4?e?Lt(n,t):Ft(n,t):!1})??r.find(e=>{if(i.has(e.id))return!1;let t=new Date(e.startedAt).getTime()||0;return!a||!t||t>=a-3e4});n&&(i.add(n.id),o.push(n))}o.length>0&&n.set(t.id,o)}return n}function Kt(e=[],t=[]){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.id!==i.id||r.title!==i.title||r.filePath!==i.filePath||r.lastActivity!==i.lastActivity||r.lastActivitySummary!==i.lastActivitySummary||r.status!==i.status||r.task_status!==i.task_status||r.recommended_next_step!==i.recommended_next_step||JSON.stringify(r.agent_hypothesis??null)!==JSON.stringify(i.agent_hypothesis??null)||r.agent_hypothesis_updated_at!==i.agent_hypothesis_updated_at||r.awaiting_approval!==i.awaiting_approval||r.awaiting_approval_question!==i.awaiting_approval_question||r.issue_id!==i.issue_id||r.messageCount!==i.messageCount)return!1}return!0}function R(e){return e.split(`.`).pop()?.replace(/_/g,` `)||e.replace(/_/g,` `)}function z(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():null}function qt(e,t){let n=e?.[t];return Array.isArray(n)?n.length:0}function Jt(e){let t=z(e,`user_problem`)||z(e,`user_intent`)||z(e,`problem`);if(t)return t;let n=e?.task_level??e?.taskLevel,r=z(e,`delegation_decision`)||z(e,`decision`),i=[typeof n==`number`?`level ${n}`:typeof n==`string`?n:null,r?r.replace(/_/g,` `):null].filter(e=>!!e);return i.length>0?i.join(` · `):null}function B(e,t=150){let n=(e??``).replace(/\s+/g,` `).trim();if(n)return n.length>t?`${n.slice(0,t-1).trim()}…`:n}function Yt(e){let t=e.trim();return t?t.replace(/^['"]|['"]$/g,``):``}function Xt(e){return(e.match(/"[^"]*"|'[^']*'|\S+/g)??[]).map(Yt).filter(Boolean)}function Zt(e){let t=[],n=new Set([`-g`,`--glob`,`-t`,`--type`,`-T`,`--type-not`,`-e`,`--regexp`,`-f`,`--file`,`--iglob`]);for(let r=1;r<e.length;r+=1){let i=e[r];if(!(!i||i===`--`)){if(n.has(i)){r+=1;continue}i.startsWith(`-`)||t.push(i)}}return t.slice(1,3).join(` `)||null}function Qt(e,t){let n=[],r=new Set([`-n`,`--lines`,`-c`,`--bytes`,`-s`,`--separator`,`-w`,`--number-width`,`-v`,`--starting-line-number`]);for(let e=1;e<t.length;e+=1){let i=t[e];if(!(!i||i===`--`)){if(r.has(i)){e+=1;continue}i.startsWith(`-`)||n.push(i)}}return(e===`sed`&&/^[0-9,$~+\-;]+[a-z]?$/i.test(n[0]??``)?n.slice(1):n).slice(0,2).join(` `)||null}function $t(e){let t=B(e,180),n=e?.trim();if(!n)return null;let r=n.toLowerCase(),i=Xt(n),a=i[0]?.toLowerCase()??``,o=a===`timeout`&&i.length>2?i.slice(2):i,s=o[0]?.toLowerCase()??a,c=t&&t.length<=90?t:void 0;if(s===`rg`||s===`ripgrep`){let e=Zt(o);return{icon:`$`,tone:`yellow`,title:e?`Searched ${e}`:`Searched code`,detail:B(n,120)}}if([`sed`,`cat`,`nl`,`head`,`tail`,`less`].includes(s)){let e=Qt(s,o);return{icon:`$`,tone:`green`,title:e?`Read ${e}`:`Read file context`,detail:c}}if(s===`git`){let e=o[1]?.toLowerCase()??``;return[`status`,`diff`,`show`].includes(e)?{icon:`$`,tone:`yellow`,title:`Checked git changes`,detail:c}:[`log`,`branch`].includes(e)?{icon:`$`,tone:`yellow`,title:`Inspected git history`,detail:c}:{icon:`$`,tone:`yellow`,title:`Ran git command`,detail:c}}if(s===`npx`&&o.some(e=>e.toLowerCase()===`tsc`)){let e=o.findIndex(e=>e===`-p`||e===`--project`);return{icon:`$`,tone:`yellow`,title:`Checked TypeScript`,detail:B((e>=0?o[e+1]:null)??n,120)}}return r.includes(`vite build`)?{icon:`$`,tone:`yellow`,title:`Built client`,detail:B(n,120)}:r.includes(`vitest`)?{icon:`$`,tone:`yellow`,title:`Ran tests`,detail:B(n,120)}:r.includes(`playwright test`)?{icon:`$`,tone:`yellow`,title:`Ran browser tests`,detail:B(n,120)}:r.includes(`npm run build`)||r.includes(`pnpm build`)||r.includes(`yarn build`)?{icon:`$`,tone:`yellow`,title:`Built project`,detail:B(n,120)}:r.includes(`npm test`)||r.includes(`pnpm test`)||r.includes(`yarn test`)?{icon:`$`,tone:`yellow`,title:`Ran tests`,detail:B(n,120)}:[`mkdir`,`mv`,`cp`,`rm`].includes(s)?{icon:`$`,tone:`yellow`,title:`Updated filesystem`,detail:c}:{icon:`$`,tone:`yellow`,title:t?`Ran ${t}`:`Ran command`}}function en(e){return e.resultText??(typeof e.result==`string`?e.result:``)}function V(e){if(e.isError)return!0;let t=K(e.result)??K(q(e.resultText));if(t?.ok===!1||t?.success===!1||t?.status===`error`||t?.status===`failed`)return!0;let n=en(e).replace(/^[^a-z0-9]+/i,``).trim().toLowerCase().slice(0,280);return/^(?:failed|error|could not|unable|command failed|timed out|socket hang up)\b/.test(n)||/^(?:error|failed):/m.test(n)}function H(e,t){return B(en(e)||t||`Tool failed`,180)}function tn(e){if(V(e))return!1;let t=(e.name??``).toLowerCase(),n=Z(e),r=z(e.arguments??{},`command`),i=en(e),a=`${t}\n${r??``}\n${i}`.toLowerCase();return!!((n===`bash`||t.includes(`exec`))&&!r||t.includes(`repl`)||a.includes(`repl loop`)||/\b(polling|heartbeat|keepalive|keep-alive|no-op|noop)\b/.test(a)||r&&/^(?:while\s+true|for\s+\(\(|watch\s+|.*wait-log\.mjs\b)/i.test(r.trim())||n===`bash`&&r&&/^(?:true|:|continue)\s*$/i.test(r.trim()))}var nn=new Set([`axis_set_hypothesis`,`axis_set_next_step`,`axis_title_session`,`axis_comment_issue`,`axis_link_session`,`axis_update_session_status`,`axis_update_issue`,`axis_ask`]);function rn(e){if(V(e))return!1;let t=(e.name??``).toLowerCase().split(`.`).pop()??``;return nn.has(t)}function an(e){let t=Z(e);return t.includes(`screenshot`)?`screenshot`:t.includes(`crop`)?`crop`:t.includes(`observation`)||t.includes(`observe`)?`observation`:t.includes(`image`)&&(t.includes(`view`)||t.includes(`overview`)||t.includes(`inspect`)||t.includes(`analyze`)||t.includes(`describe`))?`overview`:null}function on(e){return e===`crop`?`Crop evidence`:e===`observation`?`Saved observation`:e===`screenshot`?`Screenshot proof`:`Image overview`}function sn(e){let t=e.trim().replace(/[),.;:!?]+$/g,``);return t&&(/^\/api\/terminal\/workspace\/screenshot\/file\/[^?#]+\.(?:png|jpe?g|webp|gif|avif)(?:[?#].*)?$/i.test(t)||/^(?:\/|~\/|https?:\/\/|file:\/\/).+\.(?:png|jpe?g|webp|gif|avif)(?:[?#].*)?$/i.test(t))?t:null}function U(e,t,n=0){if(e==null||n>5)return;if(typeof e==`string`){for(let n of je(e))t.add(n);let n=sn(e);n&&t.add(n);return}if(Array.isArray(e)){for(let r of e)U(r,t,n+1);return}let r=K(e);if(r)for(let e of Object.values(r))U(e,t,n+1)}function cn(e,t=0){if(e==null||t>4||typeof e==`string`)return;if(Array.isArray(e)){for(let n of e){let e=cn(n,t+1);if(e)return e}return}let n=K(e);if(n){for(let e of[`observation`,`observations`,`analysis`,`summary`,`description`,`caption`,`note`,`text`]){let t=n[e];if(typeof t==`string`&&t.trim())return t.trim()}for(let e of Object.values(n)){let n=cn(e,t+1);if(n)return n}}}function W(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()&&Number.isFinite(Number(e)))return Number(e)}function ln(e){let t={x:W(e.x),y:W(e.y),width:W(e.width??e.w),height:W(e.height??e.h),left:W(e.left),top:W(e.top),right:W(e.right),bottom:W(e.bottom)};return Object.values(t).some(e=>typeof e==`number`)?t:null}function G(e,t=0){if(e==null||t>4)return;if(Array.isArray(e)){if(e.length>=4&&e.slice(0,4).every(e=>W(e)!==void 0)){let[t,n,r,i]=e.map(W);return{x:t,y:n,width:r,height:i}}for(let n of e){let e=G(n,t+1);if(e)return e}return}let n=K(e);if(!n)return;let r=ln(n);if(r)return r;for(let e of[`crop`,`region`,`rect`,`bbox`,`box`,`selection`]){let r=G(n[e],t+1);if(r)return r}for(let e of Object.values(n)){let n=G(e,t+1);if(n)return n}}function un(e){let t=an(e);if(!t)return null;let n=new Set;U(e.arguments,n),U(e.result,n),U(q(e.resultText),n),U(e.resultText,n);let r=new Map,i=[];for(let e of n){let n=nt(e,`tool-${t}-image`);if(n?.previewUrl){r.has(n.previewUrl)||r.set(n.previewUrl,n);continue}i.push(e)}let a=cn(e.result)??cn(q(e.resultText))??cn(e.arguments),o=t===`crop`?G(e.result)??G(q(e.resultText))??G(e.arguments):void 0;return{kind:t,label:on(t),attachments:[...r.values()],referencedPaths:i,observation:a,crop:o}}function dn(e){return(e.toLowerCase().split(`.`).pop()??e.toLowerCase()).startsWith(`axis_graph_`)}function K(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function fn(e){if(Array.isArray(e))return[{label:`Results`,items:e}];let t=K(e);return t?[[`sessions`,`Sessions`],[`results`,`Results`],[`keywordFallback`,`Keyword fallback`],[`chunks`,`Chunks`],[`nodes`,`Nodes`],[`edges`,`Edges`],[`insights`,`Insights`],[`top_sessions`,`Top sessions`],[`topSessions`,`Top sessions`],[`evidence`,`Evidence`]].flatMap(([e,n])=>Array.isArray(t[e])?[{label:n,items:t[e]}]:[]):[]}function pn(e){return e.result!==void 0||!!e.resultText?.trim()}function mn(e){if(e.result!==void 0&&e.result!==null)return e.result;let t=e.resultText?.trim();if(!t||!t.startsWith(`{`)&&!t.startsWith(`[`))return e.result;try{return JSON.parse(t)}catch{return e.result}}function hn(e){let t=fn(e);if(t.length>0)return t.reduce((e,t)=>e+t.items.length,0);let n=K(e);if(!n)return null;for(let e of[`count`,`total`,`totalCount`,`matched`,`matches`]){let t=n[e];if(typeof t==`number`&&Number.isFinite(t))return t}return null}function gn(e,t){if(!e||typeof e!=`object`)return null;let n=e;if(t!==null){let e=n.id??n.todoId??n.todo_id;if(e!==void 0&&Number(e)!==t)return null}for(let e of[`text`,`title`,`task`,`description`,`body`,`name`]){let t=n[e];if(typeof t==`string`&&t.trim())return t.trim()}return null}var _n=/\s+\((pending|todo|not_started|in_progress|blocked|cancelled|canceled|completed|done)\)\s*$/i;function vn(e,t){for(let n of e.split(`
`)){let e=n.trim(),r=e.match(/^(Added|Updated|Removed)\s+todo\s+#(\d+):\s*(.+)$/i),i=e.match(/^\[[^\]]*\]\s*#(\d+):\s*(.+)$/i);if(!(r??i))continue;let a=Number(r?r[2]:i?.[1]);if(!Number.isFinite(a)||t!==null&&a!==t)continue;let o=(r?r[3]:i?.[2]??``).trim(),s=o.match(_n);return{id:a,item:o.replace(_n,``).trim()||null,action:r?r[1].toLowerCase().replace(`added`,`add`).replace(`updated`,`update`).replace(`removed`,`remove`):`list`,status:s?.[1]?.toLowerCase()??null}}return null}function yn(e,t){if(typeof e==`string`)return vn(e,t)?.item??null;let n=gn(e,t);if(n)return n;let r=K(e);if(!r)return null;for(let e of[`todo`,`item`,`updated`,`removed`,`created`]){let n=gn(r[e],t);if(n)return n}for(let e of[`todos`,`items`,`list`]){let n=r[e];if(Array.isArray(n))for(let e of n){let n=gn(e,t);if(n)return n}}return null}function bn(e){let t=Ht(e),n=[e.result,q(e.resultText),e.resultText];for(let e of n){if(typeof e!=`string`)continue;let n=vn(e,t);if(n)return n}return null}function xn(e,t){let n=e.arguments??{},r=Ht(e);return z(n,`text`)||t||yn(e.result,r)||yn(q(e.resultText),r)||yn(e.resultText,r)||(r===null?`Todo item`:`Todo #${r}`)}function q(e){let t=e?.trim();if(!(!t||!t.startsWith(`{`)&&!t.startsWith(`[`)))try{return JSON.parse(t)}catch{return}}function Sn(e){return e?e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()):null}function Cn(e,t){let n=e.arguments??{},r=bn(e),i=z(n,`action`)?.toLowerCase()??r?.action??null,a=z(n,`status`)?.toLowerCase()??r?.status??null,o=xn(e,t);if(i===`clear`)return{icon:`✓`,tone:`cyan`,title:`Cleared todos`};if(i===`add`)return{icon:`+`,tone:`cyan`,title:`Added: ${o}`};if(i===`remove`)return{icon:`−`,tone:`cyan`,title:`Removed: ${o}`};if(i===`list`)return{icon:`☷`,tone:`cyan`,title:`Listed todos`};if(i===`update`){if(a===`in_progress`)return{icon:`▶`,tone:`cyan`,title:`Started: ${o}`};if(a===`completed`)return{icon:`✓`,tone:`cyan`,title:`Completed: ${o}`};let e=Sn(a);return{icon:`↻`,tone:`cyan`,title:`Updated: ${o}`,detail:B(e??void 0)}}return{icon:`☷`,tone:`cyan`,title:`Todo update: ${o}`,detail:B(i)}}function wn(e){let t=e.tc.arguments??{},n=bn(e.tc),r=z(t,`action`)?.toLowerCase()??n?.action??null,i=z(t,`status`)?.toLowerCase()??n?.status??null,a=xn(e.tc,e.todoTitle);return r===`remove`?{label:a,statusLabel:`Removed`,state:`removed`}:r===`clear`?{label:`All to-dos`,statusLabel:`Cleared`,state:`neutral`}:r===`list`?{label:a,statusLabel:i?Sn(i):null,state:i===`completed`||i===`done`?`completed`:`pending`}:i===`completed`||i===`done`?{label:a,statusLabel:`Done`,state:`completed`}:i===`in_progress`?{label:a,statusLabel:`In progress`,state:`in_progress`}:r===`add`||i===`pending`||i===`todo`||i===`not_started`?{label:a,statusLabel:`To do`,state:`pending`}:{label:a,statusLabel:Sn(i),state:`neutral`}}function J(e,t){let n=e.name??`tool`,r=n.toLowerCase().split(`.`).pop()??n.toLowerCase(),i=e.arguments??{},a=V(e),o=an(e);if(dn(n)){let t=hn(mn(e)),r=z(i,`question`)||z(i,`query`)||z(i,`search`)||z(i,`topic`);return!e.isError&&!pn(e)?{icon:`◇`,tone:`cyan`,title:`${R(n)} · searching…`,detail:B(r||`Searching Axis graph`,180)}:{icon:`◇`,tone:`cyan`,title:t===null?R(n):`${R(n)} · ${t} result${t===1?``:`s`}`,detail:B(e.isError?e.resultText??`Tool returned an error`:r,180)}}if(r===`axis_set_hypothesis`)return a?{icon:`!`,tone:`yellow`,title:`Hypothesis not saved`,detail:H(e,Jt(i))}:{icon:`⟡`,tone:`purple`,title:`Set hypothesis`,detail:B(Jt(i))};if(r===`axis_set_next_step`)return a?{icon:`!`,tone:`yellow`,title:`Next step not saved`,detail:H(e,z(i,`next_step`))}:{icon:`↪`,tone:`purple`,title:`Set next step`,detail:B(z(i,`next_step`))};if(r===`axis_title_session`)return a?{icon:`!`,tone:`yellow`,title:`Session title not saved`,detail:H(e,z(i,`title`))}:{icon:`✎`,tone:`purple`,title:`Named session`,detail:B(z(i,`title`))};if(r===`axis_comment_issue`)return a?{icon:`!`,tone:`yellow`,title:`Issue update failed`,detail:H(e,z(i,`comment`))}:{icon:`☰`,tone:`purple`,title:`Updated issue thread`,detail:B(z(i,`comment`))};if(r===`axis_get_workspace`){if(a)return{icon:`!`,tone:`yellow`,title:`Workspace unavailable`,detail:H(e,`Axis workspace context`)};let t=(e.resultText??(typeof e.result==`string`?e.result:``)).match(/\*\*Available projects:\*\*\n([\s\S]*?)(?:\n\n\*\*|$)/)?.[1]?.split(`
`).filter(e=>e.trim().startsWith(`- `)).length??null;return{icon:`⌘`,tone:`purple`,title:`Inspected workspace`,detail:B(t?`${t} projects visible to agent`:`Current tabs, panes, services, projects`)}}if(r===`axis_get_children`)return{icon:`↳`,tone:`purple`,title:`Checked child agents`,detail:B(e.resultText??(typeof e.result==`string`?e.result:void 0),180)};if(r===`axis_switch_project`){let t=z(i,`project_path`);return a?{icon:`!`,tone:`yellow`,title:`Project switch failed`,detail:H(e,t)}:{icon:`↪`,tone:`purple`,title:`Switched main project`,detail:B(t||z(i,`reason`))}}if(r===`axis_open_workspace`){let t=qt(i,`tabs`);return a?{icon:`!`,tone:`yellow`,title:`Workspace not opened`,detail:H(e,z(i,`reason`))}:{icon:`▤`,tone:`purple`,title:t>0?`Opened ${t} workspace pane${t===1?``:`s`}`:`Opened workspace`,detail:B(z(i,`reason`))}}if(r===`axis_render_artifact`)return a?{icon:`!`,tone:`yellow`,title:`Artifact not rendered`,detail:H(e,z(i,`title`)||z(i,`file_path`))}:{icon:`◈`,tone:`purple`,title:`Rendered artifact`,detail:B(z(i,`title`)||z(i,`file_path`))};if(r===`axis_capture_workspace_screenshot`)return{icon:`📸`,tone:`purple`,title:`Captured workspace pane`,detail:B(z(i,`target`)||z(i,`pane_key`)||z(i,`url`)||`Local browser/preview pane`)};if(o===`crop`)return{icon:`▧`,tone:`cyan`,title:`Cropped image region`,detail:B(z(i,`path`)||z(i,`image_path`)||z(i,`sourceImagePath`)||z(i,`source_image_path`))};if(o===`observation`)return{icon:`◉`,tone:`cyan`,title:`Saved image observation`,detail:B(z(i,`observation`)||z(i,`text`)||z(i,`note`),180)};if(o===`overview`)return{icon:`◰`,tone:`cyan`,title:`Reviewed image`,detail:B(z(i,`path`)||z(i,`image_path`)||z(i,`imagePath`))};if(o===`screenshot`)return{icon:`📸`,tone:`cyan`,title:`Captured screenshot`,detail:B(z(i,`path`)||z(i,`url`)||z(i,`target`))};if(r===`axis_spawn_subagents`){let e=qt(i,`slices`),t=z(i,`rationale`);return{icon:`🤖`,tone:`purple`,title:e>0?`Spawned ${e} sub-agent${e===1?``:`s`}`:`Spawned sub-agents`,detail:B(t||z(i,`parent_context`),180)}}if(r===`todo`)return Cn(e,t);if(r===`bash`)return $t(z(i,`command`))??{icon:`$`,tone:`muted`,title:`Internal command wrapper`,detail:B(en(e),120)};if(r===`apply_patch`)return{icon:`±`,tone:`green`,title:`Updated files`,detail:B(z(i,`patch`)||z(i,`input`),120)};if(r===`read`)return{icon:`◰`,tone:`green`,title:`Read file`,detail:B(z(i,`path`))};if(r===`edit`){let e=z(i,`path`),t=qt(i,`edits`);return{icon:`±`,tone:`green`,title:t>1?`Edited ${t} regions`:`Edited file`,detail:B(e)}}return r===`write`?{icon:`▣`,tone:`green`,title:`Wrote file`,detail:B(z(i,`path`))}:r.startsWith(`browser_`)||r.startsWith(`web_`)?{icon:`🌐`,tone:`cyan`,title:R(n),detail:B(z(i,`url`)||z(i,`query`)||z(i,`task`))}:{icon:`⚙`,tone:`muted`,title:R(n),detail:B(z(i,`path`)||z(i,`command`)||z(i,`title`)||z(i,`text`))}}function Tn(e){let t=e.tc.name??`tool`,n=Z(e.tc);return n===`todo`?`todo`:n===`bash`?`command`:n===`read`?`read`:n===`edit`||n===`write`?`edit`:dn(t)?`graph`:n===`axis_capture_workspace_screenshot`?`screenshot`:an(e.tc)?`image`:n.startsWith(`browser_`)||n.startsWith(`web_`)?`web`:n.startsWith(`axis_`)?`mc`:`other`}function Y(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function En(e){let t=B(e.detail,80);return t&&e.title===`Read file`?`Read ${t}`:t&&e.title===`Edited file`?`Edited ${t}`:t&&e.title===`Wrote file`?`Wrote ${t}`:t&&e.title===`Rendered artifact`?`Rendered ${t}`:e.title}var Dn=/\n\n…\[truncated \d+ chars from fast tail payload\]\s*$/;function On(e){return(e??``).replace(Dn,``).trimEnd()}function kn(e,t){let n=new Map;for(let e of t){let t=n.get(e.messageId)??[];t.push(e),n.set(e.messageId,t)}let r=[];for(let t of e){let e=[t.thinking,t.textContent].map(e=>On(e)).filter(e=>e.trim().length>0).join(`

`).trim();e&&r.push({kind:`narration`,messageId:t.id,timestamp:t.timestamp,text:e,streaming:t.nativeStreaming===!0});for(let e of n.get(t.id)??[])r.push({kind:`tool`,entry:e});n.delete(t.id)}for(let e of t)n.has(e.messageId)&&r.push({kind:`tool`,entry:e});return r}function X(e){let t=e.tc.name??``,n=Z(e.tc);return n===`bash`||n.includes(`exec`)||n===`apply_patch`?n===`apply_patch`?`edit`:`command`:an(e.tc)?`image`:n===`read`?`read`:n===`edit`||n===`write`?`edit`:dn(t)||n.includes(`search`)?`search`:n.startsWith(`browser_`)||n.startsWith(`web_`)?`web`:n===`todo`?`todo`:n===`axis_spawn_subagents`||n===`axis_get_children`||n===`axis_handoff`?`agent`:`tool`}function An(e){let t=J(e.tc,e.todoTitle).detail?.replace(/\s+/g,` `).trim();if(!t)return null;if(X(e)===`read`||X(e)===`edit`)return t.split(/[\\/]/).filter(Boolean).at(-1)??t;if(X(e)===`web`)try{return new URL(t).hostname||t}catch{return null}return null}function jn(e){if(e)try{let t=new URL(e),n=t.pathname===`/`?``:t.pathname;return B(`${t.hostname}${n}`,110)}catch{return B(e,110)}}function Mn(e,t=0){if(t>3)return null;let n=K(e);if(!n)return null;let r=[`liveUrl`,`live_url`,`viewerUrl`,`viewer_url`].map(e=>n[e]).find(e=>typeof e==`string`&&e.trim().length>0);if(r)try{let e=new URL(r);if(e.protocol!==`http:`&&e.protocol!==`https:`)return null;let t=e=>e.map(e=>n[e]).find(e=>typeof e==`string`&&e.trim().length>0)?.trim();return{liveUrl:e.toString(),id:t([`id`,`sessionId`,`session_id`]),title:t([`title`,`name`]),status:t([`status`,`state`]),output:t([`output`,`summary`,`result`])}}catch{return null}for(let e of[`live`,`browser`,`session`,`data`,`result`]){let r=Mn(n[e],t+1);if(r)return r}return null}function Nn(e){return Mn(e.result)??Mn(q(e.resultText))}function Pn(e){let t=Z(e.tc),n=e.tc.arguments??{},r=B(z(n,`selector`)||z(n,`target`)||z(n,`element`)||z(n,`aria_label`),100),i=jn(z(n,`url`));if(t.includes(`navigate`)||t===`web_fetch`)return{label:t===`web_fetch`?`Fetched page`:`Navigated`,detail:i};if(t.includes(`click`))return{label:`Clicked`,detail:r??`Page control`};if(t.includes(`fill`))return{label:`Filled field`,detail:r};if(t.includes(`type`))return{label:`Typed in field`,detail:r};if(t.includes(`evaluate`)||t.includes(`script`))return{label:`Evaluated page state`};if(t.includes(`html`))return{label:`Read page HTML`,detail:r};if(t.includes(`screenshot`))return{label:`Captured screenshot`};if(t.includes(`scroll`))return{label:`Scrolled page`,detail:B(z(n,`direction`),60)};if(t.includes(`wait`)){let e=n.ms;return{label:`Waited`,detail:typeof e==`number`&&Number.isFinite(e)?`${Math.max(0,e)/1e3}s`:void 0}}return t.includes(`search`)?{label:`Searched web`,detail:B(z(n,`query`),110)}:{label:R(e.tc.name??`Browser action`),detail:i??r}}function Fn(e){if(X(e)===`web`)return Pn(e);let t=J(e.tc,e.todoTitle);return{label:B(t.title,100)??`Tool action`,detail:B(t.detail,140)}}function In(e,t,n){let r=t.length,i=r===1?An(t[0]):null;if(e===`command`){if(n&&r===1){let e=B(z(t[0].tc.arguments??{},`command`),120);return e?`Running ${e}`:J(t[0].tc,t[0].todoTitle).title.replace(/^Ran\b/i,`Running`)}return n?`Running commands`:r===1?`Ran command`:`Ran commands`}if(e===`image`)return n?r===1?`Viewing image`:`Viewing ${r} images`:r===1?`Viewed image`:`Viewed ${r} images`;if(e===`read`)return n?`Reading ${i??(r===1?`file`:`${r} files`)}`:`Read ${i??(r===1?`file`:`${r} files`)}`;if(e===`edit`)return n?`Updating ${i??(r===1?`file`:`${r} files`)}`:`Updated ${i??(r===1?`file`:`${r} files`)}`;if(e===`web`){let e=t.map(An).filter(e=>!!e),r=[...new Set(e)],a=r.length===1?r[0]:i;return n?`Browsing ${a??`web`}`:`Browsed ${a??`web`}`}return e===`search`?n?`Searching`:`Searched`:e===`todo`?n?`Updating tasks`:`Updated tasks`:e===`agent`?n?`Checking agents`:`Checked agents`:J(t[t.length-1].tc,t[t.length-1].todoTitle).title}function Ln(e,t){let n=[];for(let t of e){if(t.kind===`narration`){n.push(t);continue}let e=X(t.entry),r=n[n.length-1];r?.kind===`action`&&r.bucket===e?r.entries.push(t.entry):n.push({kind:`action`,bucket:e,entries:[t.entry],label:``,current:!1})}let r=-1;for(let e=n.length-1;e>=0;--e)if(n[e].kind===`action`){r=e;break}return n.map((e,n)=>{if(e.kind===`narration`)return e;let i=e.entries.some(e=>e.tc.nativeStatus===`running`),a=e.entries.every(e=>e.tc.nativeStatus===`completed`||e.tc.nativeStatus===`failed`),o=i||t&&n===r&&!a;return{...e,current:o,label:In(e.bucket,e.entries,o)}})}function Rn(e,t){let n=[],r=null,i=e=>Hn(e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).at(-1)??e,150),a=e=>e.replace(/\s+/g,` `).trim().toLocaleLowerCase(),o=(e,t)=>{let n=a(e.title),r=a(t.title);return n===r?!0:!(e.narration?.streaming||t.narration?.streaming)||Math.min(n.length,r.length)<12?!1:n.startsWith(r)||r.startsWith(n)},s=e=>`${Z(e.tc)}:${JSON.stringify(e.tc.arguments??{})}`,c=(e,t)=>!!e.tc.id&&!!t.tc.id&&e.tc.id===t.tc.id||s(e)===s(t),l=(e,t)=>{for(let n of t){let t=e.find(e=>e.bucket===n.bucket);if(!t){e.push({...n,entries:[...n.entries]});continue}for(let e of n.entries){let n=t.entries.findIndex(t=>c(t,e));n>=0?t.entries[n]=e:t.entries.push(e)}t.label=n.label,t.current=n.current}},u=e=>e.at(-1)?.entries.at(-1)?.timestamp,d=e=>{if(!r)return;r.endedAt=e??u(r.actions)??r.startedAt,r.current=!!r.narration?.streaming||r.actions.some(e=>e.current),r.toolCount=r.actions.reduce((e,t)=>e+t.entries.length,0);let t=n.at(-1);t&&o(t,r)?(l(t.actions,r.actions),t.title=r.title,t.narration=r.narration??t.narration,t.endedAt=r.endedAt,t.current=!!t.narration?.streaming||t.actions.some(e=>e.current),t.toolCount=t.actions.reduce((e,t)=>e+t.entries.length,0)):n.push(r),r=null};for(let a of e){if(a.kind===`narration`){if(r&&r.actions.length===0){r.title=i(a.text),r.narration=a,r.endedAt=a.timestamp,r.current=!!a.streaming;continue}d(a.timestamp),r={id:`phase-${a.messageId}-${n.length}`,title:i(a.text),narration:a,actions:[],startedAt:a.timestamp,endedAt:a.timestamp,current:!!a.streaming,toolCount:0};continue}r?r.narration||(r.title=a.label):r={id:`phase-action-${a.entries[0]?.messageId??`none`}-${n.length}`,title:a.label,narration:null,actions:[],startedAt:n.length===0?t??a.entries[0]?.timestamp:a.entries[0]?.timestamp,endedAt:a.entries.at(-1)?.timestamp,current:!1,toolCount:0},r.actions.push(a)}return d(),n}function zn(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`+${t}s`;let n=Math.floor(t/60),r=t%60;if(n<60)return r>0?`+${n}m ${String(r).padStart(2,`0`)}s`:`+${n}m`;let i=Math.floor(n/60),a=n%60;return a>0?`+${i}h ${String(a).padStart(2,`0`)}m`:`+${i}h`}function Bn({timestamp:e,previousTimestamp:t,live:n=!1,className:r=``}){let[i,a]=(0,N.useState)(()=>Date.now());(0,N.useEffect)(()=>{if(!n)return;let e=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(e)},[n]);let o=Date.parse(e??``),s=Date.parse(t??``);if(!Number.isFinite(o)||!Number.isFinite(s))return null;let c=zn((n?i:o)-s);return(0,M.jsx)(`span`,{title:`${c} since the previous event${n?` · counting`:``}`,className:`shrink-0 font-mono text-[9px] font-normal tabular-nums tracking-tight text-terminal-muted/55 ${r}`,"data-testid":`pi-rendered-event-elapsed`,"data-live":n?`true`:void 0,children:c})}function Vn({text:e,messageId:t,timestamp:n,streaming:r=!1}){let{displayText:i,revealing:a}=bt({messageId:t?`narration:${t}`:``,text:e,timestamp:n}),o=a?i:e;return(0,M.jsx)(`div`,{className:`flex w-fit max-w-full min-w-0 items-start gap-2.5 bg-transparent px-1 py-1.5`,"data-testid":`pi-rendered-tool-narration`,"data-streaming":r?`true`:void 0,"data-assistant-revealing":a?`true`:void 0,children:a?(0,M.jsxs)(`div`,{className:`min-w-0 whitespace-pre-wrap break-words text-[11px] font-normal leading-[1.75] text-terminal-text/95`,"data-testid":`pi-rendered-assistant-revealing`,"data-rendered-writing":`1`,children:[o,(0,M.jsx)(kt,{})]}):(0,M.jsx)(`div`,{className:`min-w-0 text-[11px] font-normal leading-[1.75] text-terminal-text/95 [overflow-wrap:anywhere] [&_p]:my-0 [&_p]:bg-transparent [&_p]:leading-[1.75] [&_p]:text-terminal-text/95 [&_strong]:font-semibold [&_strong]:text-terminal-text [&_ul]:my-1.5 [&_ul]:pl-5 [&_ol]:my-1.5 [&_ol]:pl-5 [&_li]:my-0.5 [&_table]:my-2 [&_table]:w-auto [&_table]:max-w-full [&_table]:border-collapse [&_table]:border [&_table]:border-terminal-border/55 [&_table]:bg-transparent [&_th]:border [&_th]:border-terminal-border/55 [&_th]:px-3 [&_th]:py-1.5 [&_th]:text-left [&_th]:font-semibold [&_th]:leading-[1.6] [&_th]:text-terminal-text/95 [&_td]:border [&_td]:border-terminal-border/45 [&_td]:px-3 [&_td]:py-1 [&_td]:leading-[1.6] [&_td]:text-terminal-text/90 [&_pre]:max-w-full [&_pre]:whitespace-pre-wrap [&_pre]:break-words [&_pre]:overflow-x-hidden [&_pre]:bg-transparent`,children:(0,M.jsx)(h,{remarkPlugins:[m],children:o})})})}function Hn(e,t=160){let n=On(e).trim();if(!n)return`Receiving response…`;let r=n.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),i=/^[{[]/.test(n)||/^```/.test(n)||/^(?:import|export|const|let|var|function|class|interface|type|expect)\b/.test(r[0]??``),a=r.filter(e=>/^(?:import|export|const|let|var|function|class|interface|type|expect)\b/.test(e)||/^[{}[\]();]+$/.test(e)).length;if(i||a>=2||r.length>6&&/[{};]/.test(n))return`Receiving live tool output…`;let o=n.replace(/!\[[^\]]*\]\([^)]*\)/g,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/[`*_>#~]+/g,` `).replace(/\s+/g,` `).trim();return o?o.length>t?`${o.slice(0,t-1).trimEnd()}…`:o:`Receiving response…`}var Un={command:te,image:o,read:p,edit:s,web:u,search:c,todo:i,agent:ee,tool:f};function Wn(e){let t=e.trim().split(`
`),n=t.slice(Math.max(0,t.length-80)).join(`
`);return n.length>6e3?`${n.slice(0,5999)}…`:n}function Gn({preview:e}){let t=e.status?.replace(/_/g,` `)??`connected`;return(0,M.jsxs)(`div`,{className:`min-w-0 overflow-hidden rounded-lg border border-terminal-border/40 bg-black/20`,"data-testid":`pi-rendered-browser-session-preview`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 border-b border-terminal-border/30 px-2.5 py-1.5 text-[10px]`,children:[(0,M.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-terminal-green`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`min-w-0 truncate text-terminal-text/80`,children:e.title??`Connected browser`}),(0,M.jsx)(`span`,{className:`shrink-0 text-terminal-muted/55`,children:t}),(0,M.jsx)(`a`,{href:e.liveUrl,target:`_blank`,rel:`noreferrer noopener`,className:`ml-auto shrink-0 text-terminal-muted/65 transition-colors hover:text-terminal-text focus-visible:outline-none focus-visible:text-terminal-text`,children:`Open browser`})]}),(0,M.jsx)(`div`,{className:`aspect-video min-h-44 max-h-[22rem] bg-black`,children:(0,M.jsx)(`iframe`,{src:e.liveUrl,title:e.title??`Connected browser session`,className:`h-full w-full border-0 bg-black`,sandbox:`allow-scripts allow-forms allow-same-origin allow-popups allow-downloads allow-presentation`,allow:`clipboard-read; clipboard-write`,referrerPolicy:`no-referrer-when-downgrade`,loading:`lazy`})}),e.id&&(0,M.jsxs)(`div`,{className:`truncate border-t border-terminal-border/25 px-2.5 py-1 font-mono text-[9px] text-terminal-muted/45`,title:e.id,children:[`Browser session · `,e.id]})]})}function Kn({entries:e,cwd:t,onOpenFileAsArtifact:n}){let r=e.flatMap(e=>{let t=vt(e.messageId,e.timestamp??new Date().toISOString(),e.tc,e.index);return t?[t]:[]});return(0,M.jsx)(`div`,{className:`min-w-0 space-y-3 py-1`,"data-testid":`pi-rendered-consultation-details`,children:r.map(e=>{let r=e.status===`active`,i=e.provider===`claude`?`Claude`:`GPT`,a=[i,e.model,e.mode].filter(Boolean).join(` · `);return e.sessionId?(0,M.jsx)(N.Suspense,{fallback:(0,M.jsx)(`div`,{className:`text-[10px] text-terminal-muted/55`,children:`Loading agent transcript…`}),children:(0,M.jsx)(At,{sessionId:e.sessionId,sessionFilePath:e.sessionFilePath,cwd:e.cwd??t,title:e.title.replace(/^\[Consultation\]\s*/i,``),subtitle:a,parentReportedActive:r,onOpenFileAsArtifact:n})},e.id):(0,M.jsx)(`div`,{className:`min-w-0 text-[10px] text-terminal-muted/60`,"data-consultation-state":e.status,children:r?`Starting ${i}…`:`${i} did not record a session.`},e.id)})})}function qn({entry:e,cwd:t,onOpenFileAsArtifact:n}){let{tc:r}=e,i=Z(r),a=X(e),o=nr(r).slice(0,4),s=kr(r),c=Wn(en(r)),l=a===`web`?Pn(e):null,u=a===`web`?Nn(r):null;return ut(r)?(0,M.jsx)(Kn,{entries:[e],cwd:t,onOpenFileAsArtifact:n}):l?(0,M.jsxs)(`div`,{className:`min-w-0 space-y-2 py-1 text-[10px] leading-relaxed text-terminal-muted/65`,"data-testid":`pi-rendered-minimal-tool-evidence`,children:[u&&(0,M.jsx)(Gn,{preview:u}),(0,M.jsxs)(`div`,{className:`space-y-1 px-0.5`,"data-testid":`pi-rendered-browser-action-details`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`span`,{className:`text-terminal-muted/45`,children:`Action`}),` `,(0,M.jsx)(`span`,{className:`ml-2 text-terminal-text/75`,children:l.label})]}),l.detail&&(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`span`,{className:`text-terminal-muted/45`,children:`Target`}),` `,(0,M.jsx)(`span`,{className:`ml-2 text-terminal-text/75`,children:l.detail})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`span`,{className:`text-terminal-muted/45`,children:`Status`}),` `,(0,M.jsx)(`span`,{className:`ml-2 ${V(r)?`text-terminal-red/80`:`text-terminal-text/75`}`,children:V(r)?`Failed`:r.nativeStatus===`running`?`Running`:pn(r)?`Completed`:`Running`})]})]}),u?.output&&(0,M.jsx)(Q,{value:Wn(u.output),path:`browser-result.md`,label:`Browser result`})]}):(0,M.jsxs)(`div`,{className:`min-w-0 space-y-2 py-1`,"data-testid":`pi-rendered-minimal-tool-evidence`,children:[o.map((e,t)=>(0,M.jsx)(rr,{oldText:e.oldText,newText:e.newText,label:e.label},`${e.label??`diff`}-${t}`)),(0,M.jsx)(Or,{tc:r,todoTitle:e.todoTitle,diffs:o,cwd:t}),i===`bash`&&c&&(0,M.jsx)(Q,{value:c,path:`output.txt`,label:`Output`}),(a===`tool`||a===`command`)&&i!==`bash`&&i!==`apply_patch`&&!i.startsWith(`axis_`)&&!dn(r.name)&&o.length===0&&c&&(0,M.jsx)(Q,{value:c,path:`result.txt`,label:`Result`}),s.length>0&&n&&(0,M.jsx)(`div`,{className:`flex min-w-0 flex-wrap gap-x-3 gap-y-1`,children:s.map(e=>{let t=e.split(/[\\/]/).filter(Boolean).at(-1)??e;return(0,M.jsxs)(`button`,{type:`button`,className:`flex min-w-0 items-center gap-1.5 py-0.5 text-left text-[10px] text-terminal-muted/65 transition-colors hover:text-terminal-text/90 focus-visible:outline-none focus-visible:text-terminal-text/90`,onClick:()=>n(e,t),title:`Open ${e} in artifact pane`,"data-openable-file":`true`,children:[(0,M.jsx)(p,{className:`h-3.5 w-3.5 shrink-0`,strokeWidth:1.7,"aria-hidden":`true`}),(0,M.jsxs)(`span`,{className:`truncate`,children:[`Open `,t,` in Artifact`]})]},e)})})]})}function Jn({entries:e}){let t=e.map(e=>Nn(e.tc)).find(e=>!!e)??null;return(0,M.jsxs)(`div`,{className:`min-w-0 space-y-2 py-1`,"data-testid":`pi-rendered-browser-group-details`,children:[t&&(0,M.jsx)(Gn,{preview:t}),(0,M.jsx)(`div`,{className:`space-y-1`,"aria-label":`Browser actions`,children:e.map((e,t)=>{let n=Pn(e),r=V(e.tc);return(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 px-1 py-0.5 text-[10px] ${r?`text-terminal-red/80`:`text-terminal-text/75`}`,children:[(0,M.jsx)(`span`,{className:`h-1 w-1 shrink-0 rounded-full ${r?`bg-terminal-red/70`:`bg-terminal-muted/45`}`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`shrink-0`,children:n.label}),n.detail&&(0,M.jsx)(`span`,{className:`min-w-0 truncate text-terminal-muted/55`,children:n.detail})]},`${e.messageId}-${e.index}-${e.tc.id??t}`)})}),t?.output&&(0,M.jsx)(Q,{value:Wn(t.output),path:`browser-result.md`,label:`Browser result`})]})}function Yn({entries:e}){let t=e.map(e=>un(e.tc)).filter(e=>!!e),n=[...new Map(t.flatMap(e=>e.attachments).filter(e=>e.previewUrl).map(e=>[e.previewUrl,e])).values()],r=[...new Set(t.flatMap(e=>e.referencedPaths))];return(0,M.jsx)(`div`,{className:`min-w-0 py-1`,"data-testid":`pi-rendered-image-group-details`,children:n.length>0?(0,M.jsx)(F,{attachments:n}):(0,M.jsxs)(`div`,{className:`rounded-md border border-terminal-yellow/25 bg-terminal-yellow/[0.06] px-2.5 py-2 text-[10px] leading-relaxed text-terminal-yellow/85`,children:[`These image actions did not record a locally previewable image.`,r.length>0&&(0,M.jsx)(`span`,{className:`mt-1 block break-all text-terminal-muted/70`,children:r.join(`
`)})]})})}function Xn({entry:e,cwd:t,onOpenFileAsArtifact:n}){let i=Fn(e),a=V(e.tc),[o,s]=(0,N.useState)(!1);return(0,M.jsxs)(`details`,{open:o,onToggle:e=>s(e.currentTarget.open),className:`group/minimal-step min-w-0`,"data-testid":`pi-rendered-minimal-tool-step`,"data-secondary-disclosure":`true`,children:[(0,M.jsxs)(`summary`,{className:`flex w-fit max-w-full min-w-0 cursor-pointer list-none items-start gap-2 px-1.5 py-1.5 text-[10px] leading-[1.6] text-terminal-text/90 marker:hidden focus-visible:outline-none [&::-webkit-details-marker]:hidden`,title:i.detail?`${i.label}: ${i.detail}`:i.label,children:[(0,M.jsx)(`span`,{className:`mt-[0.42rem] h-1 w-1 shrink-0 rounded-full ${a?`bg-terminal-red/70`:`bg-terminal-muted/45`}`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`shrink-0 ${a?`text-terminal-red/95`:`text-terminal-text/95`}`,children:i.label}),(0,M.jsx)(r,{className:`mt-0.5 h-3 w-3 shrink-0 opacity-0 transition-[opacity,transform] group-hover/minimal-step:opacity-100 group-focus-within/minimal-step:opacity-100 group-open/minimal-step:rotate-90 group-open/minimal-step:opacity-100`,strokeWidth:1.7,"aria-hidden":`true`}),i.detail&&(0,M.jsx)(`span`,{className:`min-w-0 truncate text-terminal-muted/75`,children:i.detail})]}),o&&(0,M.jsx)(`div`,{className:`ml-3 min-w-0 border-l border-terminal-border/20 pb-1 pl-3 pr-1`,children:(0,M.jsx)(qn,{entry:e,cwd:t,onOpenFileAsArtifact:n})})]})}function Zn({entries:e}){return(0,M.jsx)(`div`,{className:`min-w-0 space-y-0.5 py-0.5`,"data-testid":`pi-rendered-todo-steps`,children:e.map((e,t)=>{let n=wn(e),r=n.state===`completed`?a:n.state===`removed`?l:d,i=V(e.tc),o=i?`text-terminal-red/90`:n.state===`completed`?`text-terminal-green/85`:n.state===`in_progress`?`text-terminal-cyan/90`:`text-terminal-muted/70`;return(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 px-1.5 py-1.5 text-[10px] leading-[1.6] ${i?`text-terminal-red/90`:`text-terminal-text/90`}`,"data-todo-state":n.state,title:n.statusLabel?`${n.label} — ${n.statusLabel}`:n.label,children:[(0,M.jsxs)(`span`,{className:`relative mt-0.5 h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`,children:[(0,M.jsx)(r,{className:`h-3.5 w-3.5 ${o}`,strokeWidth:1.8}),n.state===`in_progress`&&(0,M.jsx)(`span`,{className:`absolute inset-[4px] rounded-full bg-terminal-cyan animate-pulse`})]}),(0,M.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere] ${n.state===`completed`?`text-terminal-text/70`:``}`,children:n.label}),n.statusLabel&&(0,M.jsx)(`span`,{className:`shrink-0 text-[9px] ${n.state===`in_progress`?`text-terminal-cyan/80`:`text-terminal-muted/60`}`,children:n.statusLabel})]},`${e.messageId}-${e.index}-${e.tc.id??t}`)})})}function Qn({item:e,cwd:t,onOpenFileAsArtifact:n}){return e.bucket===`todo`?(0,M.jsx)(Zn,{entries:e.entries}):e.entries.every(e=>ut(e.tc))?(0,M.jsx)(Kn,{entries:e.entries,cwd:t,onOpenFileAsArtifact:n}):e.bucket===`image`?(0,M.jsx)(Yn,{entries:e.entries}):e.entries.length===1?(0,M.jsx)(qn,{entry:e.entries[0],cwd:t,onOpenFileAsArtifact:n}):e.bucket===`web`?(0,M.jsx)(Jn,{entries:e.entries}):e.entries.map((e,r)=>(0,M.jsx)(Xn,{entry:e,cwd:t,onOpenFileAsArtifact:n},`${e.messageId}-${e.index}-${e.tc.id??e.tc.name??r}`))}function $n({item:e,cwd:t,onOpenFileAsArtifact:n}){let i=Un[e.bucket],a=e.current,o=e.entries.some(e=>V(e.tc)),s=e.entries.map(e=>{let t=J(e.tc,e.todoTitle);return t.detail?`${t.title}: ${t.detail}`:t.title}).join(`
`),c=`flex w-fit max-w-full min-w-0 items-center gap-2 px-1 py-1.5 text-left text-[11px] leading-[1.6] text-terminal-text/95 ${a?`mc-rendered-current-action`:``}`,[l,u]=(0,N.useState)(!1),d=e.entries.filter(e=>ut(e.tc)).map(e=>dt(e.messageId,e.tc,e.index)).join(` `),f=(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(i,{className:`h-4 w-4 shrink-0 ${o?`text-terminal-red/95`:`text-terminal-text/80`}`,strokeWidth:1.7,"aria-hidden":`true`}),(0,M.jsx)(`span`,{className:`min-w-0 truncate font-normal text-terminal-text/95`,children:e.label}),(0,M.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 opacity-0 transition-[opacity,transform] group-hover/minimal-action:opacity-100 group-focus-within/minimal-action:opacity-100 group-open/minimal-action:rotate-90 group-open/minimal-action:opacity-100`,strokeWidth:1.7,"aria-hidden":`true`})]});return(0,M.jsxs)(`details`,{open:l,onToggle:e=>u(e.currentTarget.open),className:`group/minimal-action min-w-0`,"data-testid":`pi-rendered-minimal-tool-action`,"data-tool-bucket":e.bucket,"data-current":a?`true`:void 0,"data-rendered-consultation-ids":d||void 0,"aria-label":s,"data-expandable-details":`true`,children:[(0,M.jsx)(`summary`,{className:`${c} cursor-pointer list-none transition-colors marker:hidden hover:text-terminal-text/85 focus-visible:outline-none focus-visible:text-terminal-text/90 [&::-webkit-details-marker]:hidden`,children:f}),l&&(0,M.jsx)(`div`,{className:`ml-6 min-w-0 space-y-0.5 border-l border-terminal-border/25 py-0.5 pl-2`,"data-testid":`pi-rendered-minimal-tool-details`,"data-live-action":a?`true`:void 0,"aria-live":a?`polite`:void 0,children:(0,M.jsx)(Qn,{item:e,cwd:t,onOpenFileAsArtifact:n})})]})}function er({phase:e,cwd:t,onOpenFileAsArtifact:n}){let r=e.actions.length>0;return(0,M.jsxs)(`div`,{className:`mc-rendered-turn-event min-w-0`,"data-rendered-turn-event":`phase`,"data-current":e.current?`true`:void 0,"data-testid":`pi-rendered-tool-phase`,children:[(0,M.jsx)(Bn,{timestamp:e.endedAt,previousTimestamp:e.startedAt,live:e.current,className:`mc-rendered-turn-event-elapsed`}),(0,M.jsxs)(`div`,{className:`min-w-0 py-0.5`,children:[e.narration&&(0,M.jsx)(`div`,{className:`min-w-0 font-normal`,"data-testid":`pi-rendered-tool-phase-reasoning`,"data-phase-streaming":e.narration.streaming?`true`:void 0,children:(0,M.jsx)(Vn,{text:e.narration.text,messageId:e.narration.messageId,timestamp:e.narration.timestamp,streaming:e.narration.streaming})}),r&&(0,M.jsx)(`div`,{className:`${e.narration?`ml-4 border-l border-terminal-border/30 pl-3`:``} min-w-0 space-y-0.5 pb-1`,"data-testid":`pi-rendered-tool-phase-actions`,"data-phase-tool-count":e.toolCount,children:e.actions.map((r,i)=>(0,M.jsx)($n,{item:r,cwd:t,onOpenFileAsArtifact:n},`${e.id}-${r.bucket}-${r.entries[0]?.messageId??i}-${i}`))})]})]})}function tr(e){let t=e.filter(e=>tn(e.tc)).length,n=e.filter(e=>!tn(e.tc)).map(e=>En(J(e.tc,e.todoTitle))).filter((e,t,n)=>n.indexOf(e)===t).slice(0,3);if(n.length>0){let e=t>0?` · ${t} internal event${t===1?``:`s`} folded`:``;return`${n.join(` · `)}${e}`}if(t>0)return`Internal loop activity hidden · ${t} low-value progress event${t===1?``:`s`}`;let r=new Map;for(let t of e){let e=Tn(t);r.set(e,(r.get(e)??0)+1)}return[[`todo`,`Updated ${Y(r.get(`todo`)??0,`todo`)}`],[`command`,`Ran ${Y(r.get(`command`)??0,`command`)}`],[`read`,`Read ${Y(r.get(`read`)??0,`file`)}`],[`edit`,`Edited ${Y(r.get(`edit`)??0,`file`)}`],[`web`,`Used ${Y(r.get(`web`)??0,`browser/web tool`)}`],[`graph`,`Searched ${Y(r.get(`graph`)??0,`graph tool`)}`],[`screenshot`,`Captured ${Y(r.get(`screenshot`)??0,`screenshot`)}`],[`image`,`Reviewed ${Y(r.get(`image`)??0,`image tool`)}`],[`mc`,`Ran ${Y(r.get(`mc`)??0,`Axis action`)}`],[`other`,`Used ${Y(r.get(`other`)??0,`tool`)}`]].filter(([e])=>(r.get(e)??0)>0).map(([,e])=>e).slice(0,4).join(` · `)||`Tool activity`}function nr(e){let t=e.arguments??{};if(Z(e)===`apply_patch`){let e=z(t,`patch`)||z(t,`input`)||``,n=[],r,i=[],a=[],o=()=>{(i.length>0||a.length>0)&&n.push({oldText:i.join(`
`),newText:a.join(`
`),label:r}),i=[],a=[]};for(let t of e.split(`
`)){let e=t.match(/^\*\*\* (?:Add|Update|Delete) File:\s*(.+)$/);if(e){o(),r=e[1].trim();continue}if(t.startsWith(`@@`)){o();continue}t.startsWith(`-`)&&!t.startsWith(`---`)&&i.push(t.slice(1)),t.startsWith(`+`)&&!t.startsWith(`+++`)&&a.push(t.slice(1))}return o(),n}let n=Array.isArray(t.edits)?t.edits:[],r=[],i=z(t,`path`)||void 0;for(let e of n){if(!e||typeof e!=`object`)continue;let t=e,n=typeof t.oldText==`string`?t.oldText:typeof t.old_text==`string`?t.old_text:``,a=typeof t.newText==`string`?t.newText:typeof t.new_text==`string`?t.new_text:``;(n||a)&&r.push({oldText:n,newText:a,label:i})}return r}function rr({oldText:e,newText:t,label:n}){let r=e.split(`
`).slice(0,18),i=t.split(`
`).slice(0,18),a=e.split(`
`).length>18||t.split(`
`).length>18;return(0,M.jsxs)(`div`,{className:`mt-2 overflow-hidden rounded-md border border-terminal-border/50 bg-terminal-bg/65 font-mono text-[10px] leading-snug`,children:[n&&(0,M.jsx)(`div`,{className:`truncate border-b border-terminal-border/30 px-2 py-1 text-[9px] text-terminal-muted/55`,title:n,children:n}),r.map((e,t)=>(0,M.jsxs)(`div`,{className:`flex min-w-0 gap-2 border-l-2 border-terminal-red/70 bg-terminal-red/[0.08] px-2 py-0.5 text-terminal-red/80`,children:[(0,M.jsx)(`span`,{className:`w-3 shrink-0 select-none text-terminal-red/70`,children:`−`}),(0,M.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:e||` `})]},`old-${t}`)),i.map((e,t)=>(0,M.jsxs)(`div`,{className:`flex min-w-0 gap-2 border-l-2 border-terminal-green/70 bg-terminal-green/[0.08] px-2 py-0.5 text-terminal-green/85`,children:[(0,M.jsx)(`span`,{className:`w-3 shrink-0 select-none text-terminal-green/70`,children:`+`}),(0,M.jsx)(`span`,{className:`min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:e||` `})]},`new-${t}`)),a&&(0,M.jsx)(`div`,{className:`px-2 py-1 text-terminal-muted/60`,children:`Diff preview truncated — raw arguments still available below.`})]})}function Z(e){return e.name.toLowerCase().split(`.`).pop()??e.name.toLowerCase()}function ir(e){let t=(e??``).split(`/`).pop()??``,n=t.lastIndexOf(`.`);return n>=0?t.slice(n+1).toLowerCase():``}function ar(e){let t=ir(e);return{ts:`ts`,tsx:`tsx`,js:`js`,jsx:`jsx`,json:`json`,css:`css`,html:`html`,md:`md`,markdown:`md`,py:`py`,mjs:`js`,cjs:`js`,sh:`sh`,sql:`sql`,yaml:`yaml`,yml:`yaml`,svg:`xml`,xml:`xml`}[t]??(t||`text`)}function or(e){let t=ir(e);return t===`md`||t===`markdown`}function sr(e,t){if(!/^(?:ts|tsx|js|jsx|json|css|html|xml|py|sh|sql|yaml)$/i.test(t)||!e)return e||` `;let n=t===`json`?/\b(?:true|false|null)\b/g:/\b(?:const|let|var|function|return|if|else|for|while|class|interface|type|import|export|from|async|await|try|catch|new|true|false|null|undefined|case|switch|break|continue|extends|implements)\b/g,r=/(\/\/.*$|#.*$|`(?:\\.|[^`])*`|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"|\b\d+(?:\.\d+)?\b)/g,i=[],a=0,o=(e,t)=>{let r=0;for(let a of e.matchAll(n)){let n=a.index??0;n>r&&i.push(e.slice(r,n)),i.push((0,M.jsx)(`span`,{className:`text-terminal-purple/90`,children:a[0]},`${t}-kw-${n}`)),r=n+a[0].length}r<e.length&&i.push(e.slice(r))};for(let t of e.matchAll(r)){let n=t.index??0;n>a&&o(e.slice(a,n),`p-${a}`);let r=t[0],s=r.startsWith(`//`)||r.startsWith(`#`)?`text-terminal-muted/65 italic`:/^['"`]/.test(r)?`text-terminal-green/85`:`text-terminal-yellow/85`;i.push((0,M.jsx)(`span`,{className:s,children:r},`tok-${n}`)),a=n+r.length}return a<e.length&&o(e.slice(a),`p-${a}`),i.length>0?i:e||` `}function Q({value:e,path:t,label:n,startLine:r=1}){let i=ar(t),a=e.split(`
`),o=a.slice(0,120),s=a.length>120;return(0,M.jsxs)(`div`,{className:`min-w-0 overflow-hidden rounded-lg border border-terminal-border/45 bg-terminal-bg/75`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2 border-b border-terminal-border/35 px-2.5 py-1.5 font-mono text-[9px] uppercase tracking-[0.12em] text-terminal-muted/70`,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:n??t??`content`}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-current/20 px-1.5 py-0.5`,children:i})]}),(0,M.jsx)(`div`,{className:`language-${i} max-h-80 overflow-y-auto overflow-x-hidden p-2.5 font-mono text-[10px] leading-relaxed text-terminal-text/85`,children:o.map((e,t)=>(0,M.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:[(0,M.jsx)(`span`,{className:`w-6 shrink-0 select-none text-right text-terminal-muted/35`,children:r+t}),(0,M.jsx)(`code`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:sr(e,i)})]},t))}),s&&(0,M.jsx)(`div`,{className:`border-t border-terminal-border/25 px-2.5 py-1 font-mono text-[9px] text-terminal-muted/60`,children:`Preview truncated at 120 lines.`})]})}function cr({rows:e}){let t=e.filter(e=>e.value!==void 0&&e.value!==null&&String(e.value).trim());return t.length===0?null:(0,M.jsx)(`dl`,{className:`grid min-w-0 gap-1.5 rounded-lg border border-terminal-border/35 bg-terminal-bg/45 px-2.5 py-2 font-mono text-[10px] sm:grid-cols-2`,children:t.map(e=>(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`dt`,{className:`text-[8px] font-bold uppercase tracking-[0.14em] text-terminal-muted/55`,children:e.label}),(0,M.jsx)(`dd`,{className:`whitespace-pre-wrap break-words text-terminal-text/80 [overflow-wrap:anywhere]`,title:String(e.value),children:String(e.value)})]},e.label))})}function lr(e){if(typeof e==`string`)return e;let t=K(e);if(!t)return JSON.stringify(e);for(let e of[`title`,`session_title`,`name`,`id`,`session_id`,`path`]){let n=t[e];if(typeof n==`string`&&n.trim())return n.trim()}return JSON.stringify(e)}function ur(e){let t=K(e);if(!t)return null;let n=[];for(let e of[`score`,`date`,`timestamp`,`project_path`,`topic`,`kind`]){let r=t[e];typeof r==`number`&&Number.isFinite(r)&&n.push(`${e}: ${r.toFixed(e===`score`?3:0)}`),typeof r==`string`&&r.trim()&&n.push(r.trim())}return n.length>0?n.slice(0,3).join(` · `):null}function dr(e){if(typeof e==`string`)return null;let t=K(e);if(!t)return null;for(let e of[`snippet`,`summary`,`text`,`content`,`body`,`reason`,`answer`]){let n=t[e];if(typeof n==`string`&&n.trim())return n.trim()}return null}function fr(e){return e.replace(/^[-•]\s*/,``).replace(/\*\*/g,``).trim()}function pr(e){let t=[],n=null,r=()=>{n&&(n.summary||n.lines.length>0)&&t.push(n)};for(let t of e.split(`
`)){let e=t.trim();if(!e)continue;let i=e.match(/^\*\*(.+?):\*\*\s*(.*)$/);if(i){r(),n={key:i[1].toLowerCase().replace(/[^a-z0-9]+/g,`-`),title:i[1],summary:fr(i[2]??``),lines:[]};continue}n||={key:`workspace`,title:`Workspace`,lines:[]},n.lines.push(fr(e))}return r(),t}function mr(e){let t=e.toLowerCase();return t.includes(`session`)?{icon:`●`,accent:`text-terminal-purple/85`,label:`Current context`}:t.includes(`modal`)||t.includes(`tab`)?{icon:`▤`,accent:`text-terminal-cyan/85`,label:`Open workspace`}:t.includes(`window`)||t.includes(`pane`)?{icon:`◫`,accent:`text-terminal-yellow/85`,label:`Attached panes`}:t.includes(`project`)?{icon:`◆`,accent:`text-terminal-green/85`,label:`Projects`}:t.includes(`service`)||t.includes(`preview`)?{icon:`⚡`,accent:`text-terminal-cyan/85`,label:`Runtime`}:t.includes(`browser`)?{icon:`🌐`,accent:`text-terminal-cyan/85`,label:`Browsers`}:t.includes(`child`)?{icon:`↳`,accent:`text-terminal-purple/85`,label:`Agents`}:t.includes(`artifact`)?{icon:`◈`,accent:`text-terminal-yellow/85`,label:`Artifacts`}:{icon:`•`,accent:`text-terminal-muted/80`,label:`Details`}}function hr({resultText:e}){let t=pr(e);if(t.length===0)return null;let n=[`This session`,`Live modal`,`Open tabs`,`Active tabs`],r=t.filter(e=>n.includes(e.title)),i=t.filter(e=>!n.includes(e.title));return(0,M.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-terminal-purple/25 bg-terminal-purple/[0.04] px-2.5 py-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 font-mono text-[9px] font-bold uppercase tracking-[0.14em] text-terminal-purple/75`,children:[(0,M.jsx)(`span`,{children:`Workspace inspection`}),(0,M.jsxs)(`span`,{className:`text-terminal-muted/55`,children:[i.length,` groups`]})]}),r.length>0&&(0,M.jsx)(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:r.map(e=>(0,M.jsxs)(`div`,{className:`min-w-0 rounded-md border border-terminal-border/35 bg-terminal-bg/45 px-2 py-1.5`,children:[(0,M.jsx)(`div`,{className:`font-mono text-[8px] font-bold uppercase tracking-[0.13em] text-terminal-muted/55`,children:e.title}),(0,M.jsx)(`div`,{className:`mt-0.5 whitespace-pre-wrap break-words text-[10px] leading-relaxed text-terminal-text/85 [overflow-wrap:anywhere]`,children:e.summary||e.lines.slice(0,2).join(`
`)||`none`})]},e.key))}),(0,M.jsx)(`div`,{className:`grid gap-2 lg:grid-cols-2`,children:i.slice(0,10).map(e=>{let t=mr(e.title),n=e.lines.slice(0,e.title===`Preview services`?8:6),r=Math.max(0,e.lines.length-n.length);return(0,M.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-terminal-border/35 bg-terminal-bg/45 px-2.5 py-2`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`min-w-0 font-mono text-[9px] font-bold uppercase tracking-[0.13em] text-terminal-muted/70`,children:[(0,M.jsx)(`span`,{className:t.accent,children:t.icon}),` `,e.title]}),(0,M.jsx)(`div`,{className:`shrink-0 rounded border border-terminal-border/35 px-1.5 py-0.5 font-mono text-[8px] uppercase tracking-[0.1em] text-terminal-muted/50`,children:t.label})]}),e.summary&&(0,M.jsx)(`div`,{className:`mt-1 text-[10px] leading-relaxed text-terminal-text/80 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:e.summary}),n.length>0&&(0,M.jsx)(`div`,{className:`mt-1.5 space-y-1`,children:n.map((e,t)=>(0,M.jsx)(`div`,{className:`min-w-0 rounded border border-terminal-border/25 bg-terminal-bg/45 px-2 py-1 text-[10px] leading-relaxed text-terminal-text/75 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:e},t))}),r>0&&(0,M.jsxs)(`div`,{className:`mt-1.5 font-mono text-[9px] text-terminal-muted/55`,children:[`+ `,r,` more — expand raw result for the full list.`]})]},e.key)})}),i.length>10&&(0,M.jsxs)(`div`,{className:`font-mono text-[9px] text-terminal-muted/55`,children:[`+ `,i.length-10,` more groups in raw result.`]})]})}function gr(e){let t=[];if(typeof e.resultText==`string`&&t.push(e.resultText),typeof e.result==`string`)t.push(e.result);else if(e.result!==void 0&&e.result!==null)try{t.push(JSON.stringify(e.result))}catch{}let n=new Map,r=t.join(`
`);for(let e of je(r)){let t=nt(e,`tool-proof-image`);!t?.previewUrl||n.has(t.previewUrl)||n.set(t.previewUrl,t)}for(let e of ke(r)){let t=e.replace(/[),.;:!?]+$/g,``),r=Oe(t);!r||n.has(r)||n.set(r,{kind:`attachment`,id:`tool-proof-video-${t}`,name:P(t),size:0,path:t,mimeType:tt(t),previewUrl:r,sourceUrl:r,uploadStatus:`ready`})}return[...n.values()]}function _r({attachments:e}){return e.length===0?null:(0,M.jsx)(`div`,{"data-testid":`pi-rendered-tool-proof-images`,children:(0,M.jsx)(F,{attachments:e,variant:`proof`})})}function vr(e){return e?[{label:`X`,value:e.x},{label:`Y`,value:e.y},{label:`Width`,value:e.width},{label:`Height`,value:e.height},{label:`Left`,value:e.left},{label:`Top`,value:e.top},{label:`Right`,value:e.right},{label:`Bottom`,value:e.bottom}]:[]}function yr(e){if(!e)return null;let t=e.x??e.left,n=e.y??e.top,r=e.width??(e.right!==void 0&&t!==void 0?e.right-t:void 0),i=e.height??(e.bottom!==void 0&&n!==void 0?e.bottom-n:void 0);if([t,n,r,i].some(e=>e===void 0||!Number.isFinite(e)))return null;let a={x:t,y:n,width:r,height:i};return a.x<0||a.y<0||a.width<=0||a.height<=0||a.x+a.width>100||a.y+a.height>100?null:{left:`${a.x}%`,top:`${a.y}%`,width:`${a.width}%`,height:`${a.height}%`}}function br({evidence:e}){let t=yr(e.crop),n=e.attachments[0];return(0,M.jsxs)(`div`,{className:`space-y-2`,"data-testid":`pi-rendered-image-evidence`,children:[e.attachments.length>0?(0,M.jsx)(F,{attachments:e.attachments,variant:`proof`}):(0,M.jsx)(`div`,{className:`rounded-md border border-terminal-yellow/25 bg-terminal-yellow/[0.06] px-2.5 py-2 text-[10px] leading-relaxed text-terminal-yellow/85`,children:`Image evidence referenced, but no local preview is available.`}),t&&n?(0,M.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-terminal-cyan/20 bg-black/20`,"data-testid":`pi-rendered-crop-region-overlay`,children:[(0,M.jsx)(`div`,{className:`border-b border-terminal-cyan/15 px-2 py-1 font-mono text-[8px] font-bold uppercase tracking-[0.13em] text-terminal-cyan/70`,children:`Highlighted crop region`}),(0,M.jsxs)(`div`,{className:`relative aspect-video max-h-72 bg-terminal-bg`,children:[(0,M.jsx)(`img`,{src:n.previewUrl,alt:`${n.name} crop source`,className:`h-full w-full object-contain opacity-80`,loading:`lazy`,decoding:`async`}),(0,M.jsx)(`div`,{className:`absolute border-2 border-terminal-yellow bg-terminal-yellow/15 shadow-[0_0_0_9999px_rgba(0,0,0,0.32)]`,style:t})]})]}):null,e.observation?(0,M.jsx)(`div`,{className:`rounded-md border border-terminal-border/35 bg-terminal-bg/45 px-2.5 py-2 text-[11px] leading-relaxed text-terminal-text/85 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,"data-testid":`pi-rendered-image-observation`,children:e.observation}):null,(0,M.jsx)(cr,{rows:[...vr(e.crop),...e.referencedPaths.slice(0,4).map((e,t)=>({label:t===0?`Referenced image`:`Reference ${t+1}`,value:e}))]})]})}function xr({tc:e}){let t=e.resultText??(typeof e.result==`string`?e.result:``),n=K(e.result),r=Z(e),i=e.arguments??{},a=z(i,`next_step`)||z(i,`comment`)||z(i,`title`)||z(i,`question`),o=r===`axis_capture_workspace_screenshot`||r===`axis_render_artifact`?gr(e):[];return e.isError?(0,M.jsx)(`div`,{className:`rounded-lg border border-terminal-red/30 bg-terminal-red/[0.06] px-2.5 py-2 text-[11px] leading-relaxed text-terminal-red/80 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:B(t,1200)||`Axis tool returned an error.`}):o.length>0?(0,M.jsx)(_r,{attachments:o}):t.trim()?r===`axis_get_workspace`?(0,M.jsx)(hr,{resultText:t}):(0,M.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-terminal-purple/25 bg-terminal-purple/[0.04] px-2.5 py-2`,children:[(0,M.jsx)(`div`,{className:`font-mono text-[9px] font-bold uppercase tracking-[0.14em] text-terminal-purple/75`,children:`Axis result`}),(0,M.jsx)(`div`,{className:`max-h-80 overflow-y-auto whitespace-pre-wrap break-words text-[11px] leading-relaxed text-terminal-text/80 [overflow-wrap:anywhere]`,children:B(t,1200)})]}):n?(0,M.jsx)(Q,{value:JSON.stringify(n,null,2),path:`axis-result.json`,label:`Axis result`}):a?(0,M.jsx)(`div`,{className:`rounded-lg border border-terminal-border/35 bg-terminal-bg/45 px-2.5 py-2 text-[11px] leading-relaxed text-terminal-text/80 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:a}):(0,M.jsx)(`div`,{className:`rounded-lg border border-terminal-purple/20 bg-terminal-purple/[0.035] px-2.5 py-2 font-mono text-[10px] text-terminal-muted/75`,children:`Axis action completed. No structured result payload was recorded.`})}function Sr({tc:e}){let t=fn(mn(e)),n=B(e.resultText,1200),r=z(e.arguments,`question`)||z(e.arguments,`query`)||z(e.arguments,`search`)||z(e.arguments,`topic`);return e.isError?(0,M.jsx)(`div`,{className:`rounded-lg border border-terminal-red/30 bg-terminal-red/[0.06] px-2.5 py-2 text-[11px] leading-relaxed text-terminal-red/80 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:n||`Graph tool returned an error.`}):pn(e)?t.length===0?(0,M.jsx)(`div`,{className:`rounded-lg border border-terminal-cyan/25 bg-terminal-cyan/[0.05] px-2.5 py-2 text-[11px] leading-relaxed text-terminal-text/80 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:n||`Graph tool completed; no structured result payload was recorded.`}):(0,M.jsx)(`div`,{className:`space-y-2 rounded-lg border border-terminal-cyan/25 bg-terminal-cyan/[0.04] px-2.5 py-2`,children:t.slice(0,3).map(e=>(0,M.jsxs)(`div`,{className:`min-w-0 space-y-1.5`,children:[(0,M.jsxs)(`div`,{className:`font-mono text-[9px] font-bold uppercase tracking-[0.14em] text-terminal-cyan/75`,children:[e.label,` · `,e.items.length]}),e.items.slice(0,5).map((e,t)=>{let n=B(lr(e),180)??`Result`,r=B(ur(e),180),i=B(dr(e),320);return(0,M.jsxs)(`div`,{className:`min-w-0 rounded-md border border-terminal-border/35 bg-terminal-bg/45 px-2 py-1.5`,children:[(0,M.jsx)(`div`,{className:`font-mono text-[10px] font-semibold text-terminal-text/90 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:n}),r&&(0,M.jsx)(`div`,{className:`mt-0.5 font-mono text-[9px] text-terminal-muted/65 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:r}),i&&(0,M.jsx)(`div`,{className:`mt-1 text-[10px] leading-relaxed text-terminal-text/75 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:i})]},t)}),e.items.length>5&&(0,M.jsxs)(`div`,{className:`font-mono text-[9px] text-terminal-muted/60`,children:[`+`,e.items.length-5,` more in raw result`]})]},e.label))}):(0,M.jsxs)(`div`,{className:`rounded-lg border border-terminal-cyan/25 bg-terminal-cyan/[0.05] px-2.5 py-2 text-[11px] leading-relaxed text-terminal-text/80`,"data-testid":`pi-rendered-graph-searching`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 font-mono text-[10px] font-bold uppercase tracking-[0.14em] text-terminal-cyan/80`,children:[(0,M.jsx)(`span`,{className:`h-2 w-2 shrink-0 animate-pulse rounded-full bg-terminal-cyan`,"aria-hidden":`true`}),(0,M.jsx)(`span`,{children:`Searching Axis graph…`})]}),(0,M.jsx)(`div`,{className:`mt-1 whitespace-pre-wrap break-words text-terminal-muted/75 [overflow-wrap:anywhere]`,children:r?`Looking for: ${r}`:`Retrieving sessions, codebase context, and reranked matches. Results will appear here when the tool finishes.`})]})}function Cr(e,t){return e?e.startsWith(`/`)||e.startsWith(`~`)||!t?e:`${t.replace(/\/+$/g,``)}/${e.replace(/^\.\//,``)}`:null}function wr(e){return!!e&&/\.(?:png|jpe?g|gif|webp|avif)$/i.test(e.split(/[?#]/,1)[0]??e)}function Tr(e){return!!e&&/\.(?:svg|pdf|mp4|mov|webm)$/i.test(e.split(/[?#]/,1)[0]??e)}function Er({path:e,previewUrl:t}){let n=(0,N.useMemo)(()=>({kind:`attachment`,id:`read-image-${e}`,name:P(e),size:0,path:e,mimeType:et(e),previewUrl:t,sourceUrl:t,uploadStatus:`ready`}),[e,t]);return(0,M.jsxs)(`div`,{className:`rounded-lg border border-terminal-cyan/25 bg-terminal-cyan/[0.04] px-2.5 py-2`,"data-testid":`pi-rendered-read-image-preview`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 font-mono text-[9px] uppercase tracking-[0.12em] text-terminal-cyan/75`,children:[(0,M.jsx)(`span`,{className:`truncate`,title:e,children:`Image preview`}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-current/20 px-1.5 py-0.5`,children:`click to open`})]}),(0,M.jsx)(F,{attachments:[n]})]})}function Dr({path:e,offset:t,limit:n,cwd:r}){let[i,a]=(0,N.useState)({loading:!0}),o=(0,N.useMemo)(()=>Cr(e,r),[r,e]),s=(0,N.useMemo)(()=>o&&wr(o)?Qe(o):null,[o]),c=typeof t==`number`&&Number.isFinite(t)&&t>0?Math.floor(t):1,l=typeof n==`number`&&Number.isFinite(n)&&n>0?Math.floor(n):80;if((0,N.useEffect)(()=>{if(!o){a({loading:!1,error:`No file path provided.`});return}if(s){a({loading:!1,resolvedPath:o});return}if(wr(o)){a({loading:!1,error:`Image preview is only available for Axis uploaded images.`,resolvedPath:o});return}if(Tr(o)){a({loading:!1,error:`Binary preview skipped to avoid noisy text fetches.`,resolvedPath:o});return}let e=!1;a({loading:!0,resolvedPath:o});let t=new URLSearchParams({path:o});return fetch(`/api/read-file?${t}`,{cache:`no-store`}).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||t.message||`HTTP ${e.status}`);return t}).then(t=>{e||a({loading:!1,content:t.content??``,resolvedPath:t.path??o})}).catch(t=>{e||a({loading:!1,error:t instanceof Error?t.message:String(t),resolvedPath:o})}),()=>{e=!0}},[s,o]),s&&o)return(0,M.jsx)(Er,{path:o,previewUrl:s});if(i.loading)return(0,M.jsx)(`div`,{className:`rounded-lg border border-terminal-border/35 bg-terminal-bg/45 px-2.5 py-2 font-mono text-[10px] text-terminal-muted/70`,children:`Loading file context…`});if(i.error)return(0,M.jsxs)(`div`,{className:`rounded-lg border border-terminal-red/30 bg-terminal-red/[0.06] px-2.5 py-2 font-mono text-[10px] text-terminal-red/80`,children:[`Could not load file context: `,i.error]});let u=(i.content??``).split(`
`),d=Math.max(0,c-1),f=Math.min(u.length,d+l),ee=u.slice(d,f).join(`
`),p=`${e??i.resolvedPath??`file`} · lines ${d+1}-${f}`;return(0,M.jsx)(Q,{value:ee,path:i.resolvedPath??e,label:p,startLine:d+1})}function Or({tc:e,todoTitle:t,diffs:n,cwd:r}){let i=e.arguments??{},a=Z(e),o=z(i,`path`),s=z(i,`content`),c=z(i,`command`),l=un(e);return a===`write`&&s!==null?or(o)?(0,M.jsxs)(`div`,{className:`rounded-lg border border-terminal-border/45 bg-terminal-bg/65 px-3 py-2`,children:[(0,M.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 font-mono text-[9px] uppercase tracking-[0.12em] text-terminal-muted/65`,children:[(0,M.jsx)(`span`,{className:`truncate`,children:o??`Markdown content`}),(0,M.jsx)(`span`,{className:`shrink-0 rounded border border-current/20 px-1.5 py-0.5`,children:`markdown`})]}),(0,M.jsx)(`div`,{className:`markdown-body max-h-96 overflow-y-auto overflow-x-hidden break-words text-[12px] leading-relaxed text-terminal-text/90 [overflow-wrap:anywhere] [&_code]:[overflow-wrap:anywhere] [&_pre]:whitespace-pre-wrap [&_pre]:break-words [&_pre]:overflow-x-hidden [&_pre]:[overflow-wrap:anywhere]`,children:(0,M.jsx)(h,{remarkPlugins:[m],children:s})})]}):(0,M.jsx)(Q,{value:s,path:o,label:o??`Written file`}):a===`bash`&&c?(0,M.jsx)(Q,{value:c,path:`script.sh`,label:`Command`}):a===`todo`?(0,M.jsx)(cr,{rows:[{label:`Todo`,value:t??z(i,`text`)??(i.id?`Todo #${String(i.id)}`:null)},{label:`Action`,value:z(i,`action`)},{label:`Status`,value:z(i,`status`)}]}):a===`read`?(0,M.jsxs)(`div`,{className:`space-y-2`,children:[(0,M.jsx)(cr,{rows:[{label:`File`,value:o},{label:`Offset`,value:typeof i.offset==`number`?i.offset:null},{label:`Limit`,value:typeof i.limit==`number`?i.limit:null}]}),(0,M.jsx)(Dr,{path:o,offset:i.offset,limit:i.limit,cwd:r})]}):l?(0,M.jsx)(br,{evidence:l}):dn(e.name)?(0,M.jsx)(Sr,{tc:e}):a.startsWith(`axis_`)?(0,M.jsx)(xr,{tc:e}):n.length>0?null:(0,M.jsx)(cr,{rows:Object.entries(i).slice(0,6).map(([e,t])=>({label:e,value:typeof t==`string`||typeof t==`number`?t:JSON.stringify(t)}))})}function kr(e){let t=e.arguments??{},n=Z(e),r=e=>typeof t[e]==`string`?t[e].trim():``;if(n===`read`||n===`edit`||n===`write`){let e=r(`path`)||r(`file_path`);return e?[e]:[]}if(n===`apply_patch`)return[...(r(`patch`)||r(`input`)).matchAll(/^\*\*\* (?:Add|Update|Delete) File:\s*(.+)$/gm)].map(e=>e[1].trim()).filter(Boolean);if(n===`axis_render_artifact`||e.name===`axis_render_artifact`){let e=r(`file_path`)||r(`path`);return e?[e]:[]}return[]}var Ar=N.memo(function({item:e,isLatest:t,isWorking:n=!1,nestedInTurn:i=!1,phaseView:a=`all`,cwd:o,onOpenFileAsArtifact:s}){let c=e.toolCalls.filter(e=>!tn(e.tc)&&!rn(e.tc)),l=tr(c),u=Ln(kn(e.messages,c),n&&t),d=Rn(u,e.previousTimestamp??e.timestamp),f=a===`current`?d.length>0?[{...d[d.length-1],current:n&&t}]:[]:d,[ee,p]=(0,N.useState)(t),[te,m]=(0,N.useState)(0);(0,N.useEffect)(()=>wt(()=>m(e=>e+1)),[]);let h=(0,N.useMemo)(()=>Ot(u,{enabled:!1}),[u,te]),g=e.previousTimestamp??e.timestamp,_=(0,M.jsx)(M.Fragment,{children:h.map((e,t)=>{let n=e.kind===`narration`?e.timestamp:e.entries[0]?.timestamp,r=g;g=(e.kind===`narration`?e.timestamp:e.entries[e.entries.length-1]?.timestamp)??n??g;let a=e.kind===`action`&&e.current;return(0,M.jsxs)(`div`,{className:i?`mc-rendered-turn-event min-w-0`:`min-w-0`,"data-rendered-turn-event":e.kind,"data-current":a?`true`:void 0,children:[i&&(0,M.jsx)(Bn,{timestamp:n,previousTimestamp:r,live:a,className:`mc-rendered-turn-event-elapsed`}),e.kind===`narration`?(0,M.jsx)(Vn,{text:e.text,messageId:e.messageId,timestamp:e.timestamp,streaming:e.streaming}):(0,M.jsx)($n,{item:e,cwd:o,onOpenFileAsArtifact:s})]},e.kind===`narration`?`narration-${e.messageId}-${t}`:`action-${t}-${e.bucket}`)})});return!i&&c.length===0?null:i?(0,M.jsx)(`div`,{className:`min-w-0 space-y-1`,"data-testid":`pi-rendered-tool-group`,"data-nested-in-turn":`true`,"data-phase-view":a,children:f.map(e=>(0,M.jsx)(er,{phase:e,cwd:o,onOpenFileAsArtifact:s},e.id))}):h.length===0?null:(0,M.jsxs)(`details`,{open:ee,onToggle:e=>p(e.currentTarget.open),className:`group/work mr-auto min-w-0 max-w-full text-terminal-text/95`,"data-testid":`pi-rendered-tool-group`,"data-rendered-tool-layout":`minimal`,"data-collapsed":ee?void 0:`true`,children:[(0,M.jsxs)(`summary`,{className:`flex w-fit max-w-full min-w-0 cursor-pointer list-none items-center gap-1.5 py-1 font-mono text-[11px] leading-[1.6] marker:hidden hover:text-terminal-text focus-visible:outline-none [&::-webkit-details-marker]:hidden`,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate font-normal text-terminal-text`,title:l,children:l}),(0,M.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 opacity-0 transition-[opacity,transform] duration-150 group-hover/work:opacity-100 group-focus-within/work:opacity-100 group-open/work:rotate-90 group-open/work:opacity-100`,"aria-hidden":`true`}),(0,M.jsxs)(`span`,{className:`shrink-0 text-[9px] text-terminal-muted/75`,children:[c.length,` step`,c.length===1?``:`s`]})]}),(0,M.jsx)(`div`,{className:`mt-1.5 min-w-0 space-y-1 pl-0.5`,children:_})]})});function jr(e,t){try{let n=JSON.parse(e),r=Array.isArray(n)?n:[n],i=[];for(let e of r){if(!e||typeof e!=`object`)continue;let n=e,r=typeof n.type==`string`?n.type.trim():``;r&&(t?.taskLauncherOnly&&r.toLowerCase()!==`task_launcher`||i.push(n))}return i.length>0?i:null}catch{return null}}function Mr(e){let t=[],n=e.replace(/```(?:mc-ui|generative-ui)\s*\n([\s\S]*?)```/gi,(e,n)=>{let r=jr(n);return r?(t.push(...r),``):e});return n=n.replace(/```(?:json)?\s*\n([\s\S]*?)```/gi,(e,n)=>{let r=jr(n,{taskLauncherOnly:!0});return r?(t.push(...r),``):e}),{markdown:n.trim(),blocks:t}}function $(e){return typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):``}function Nr(e){let t=(e??``).toLowerCase();return[`done`,`success`,`green`].includes(t)?{border:`border-terminal-green/25`,bg:`bg-terminal-green/[0.07]`,text:`text-terminal-green/90`,dot:`bg-terminal-green`}:[`blocked`,`danger`,`error`,`red`].includes(t)?{border:`border-terminal-red/30`,bg:`bg-terminal-red/[0.07]`,text:`text-terminal-red/90`,dot:`bg-terminal-red`}:[`warning`,`pending`,`yellow`].includes(t)?{border:`border-terminal-yellow/30`,bg:`bg-terminal-yellow/[0.07]`,text:`text-terminal-yellow/90`,dot:`bg-terminal-yellow`}:[`purple`,`idea`].includes(t)?{border:`border-terminal-purple/30`,bg:`bg-terminal-purple/[0.07]`,text:`text-terminal-purple/90`,dot:`bg-terminal-purple`}:{border:`border-terminal-cyan/25`,bg:`bg-terminal-cyan/[0.06]`,text:`text-terminal-cyan/90`,dot:`bg-terminal-cyan`}}function Pr(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(120,Math.min(720,e)):320}function Fr({className:e}){return(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,M.jsx)(`polyline`,{points:`15 3 21 3 21 9`}),(0,M.jsx)(`polyline`,{points:`9 21 3 21 3 15`}),(0,M.jsx)(`line`,{x1:`21`,y1:`3`,x2:`14`,y2:`10`}),(0,M.jsx)(`line`,{x1:`3`,y1:`21`,x2:`10`,y2:`14`})]})}function Ir({className:e}){return(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,M.jsx)(`polyline`,{points:`4 14 10 14 10 20`}),(0,M.jsx)(`polyline`,{points:`20 10 14 10 14 4`}),(0,M.jsx)(`line`,{x1:`14`,y1:`10`,x2:`21`,y2:`3`}),(0,M.jsx)(`line`,{x1:`3`,y1:`21`,x2:`10`,y2:`14`})]})}function Lr({children:e,title:t,onClose:n}){let r=(0,N.useRef)(null);return(0,N.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[n]),(0,M.jsxs)(`div`,{ref:r,className:`fixed inset-0 z-[9999] flex flex-col bg-slate-950/95 backdrop-blur-sm`,onClick:e=>{e.target===r.current&&n()},children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-terminal-border/30 px-4 py-3 sm:px-6`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,M.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full bg-terminal-purple shadow-[0_0_8px_rgba(168,85,247,0.5)]`}),(0,M.jsx)(`span`,{className:`font-mono text-xs font-bold uppercase tracking-wider text-terminal-purple/90 truncate`,children:t})]}),(0,M.jsx)(`button`,{type:`button`,onClick:n,className:`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-terminal-border/40 bg-terminal-surface/30 text-terminal-muted hover:border-terminal-red/40 hover:text-terminal-red transition-colors`,"aria-label":`Close fullscreen`,children:(0,M.jsx)(Ir,{})})]}),(0,M.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-6`,children:e})]})}function Rr({onClick:e}){return(0,M.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e()},className:`inline-flex h-6 w-6 items-center justify-center rounded-md border border-terminal-border/40 bg-terminal-bg/60 text-terminal-muted/60 opacity-0 transition-[color,background-color,border-color,box-shadow,opacity,transform] duration-150 hover:border-terminal-purple/50 hover:text-terminal-purple hover:opacity-100 group-hover/gui:opacity-80`,"aria-label":`Expand to fullscreen`,title:`Expand`,children:(0,M.jsx)(Fr,{})})}function zr(e){return Array.isArray(e)?e.map(e=>$(e)).filter(Boolean):[]}function Br({block:e}){let t=y(e=>e.open),n=Array.isArray(e.tasks)?e.tasks:[],r=(0,N.useMemo)(()=>n.slice(0,24).map((e,t)=>({id:$(e.id)||`task-${t+1}`,title:$(e.title)||`Task ${t+1}`,sourceNodeIds:zr(e.sourceNodeIds),summary:$(e.summary),plan:$(e.plan),suggestedFiles:zr(e.suggestedFiles),validation:$(e.validation),prompt:$(e.prompt)})),[n]),[i,a]=(0,N.useState)(()=>Object.fromEntries(r.map(e=>[e.id,e.prompt]))),[o,s]=(0,N.useState)({}),[c,l]=(0,N.useState)({}),u=$(e.projectPath);(0,N.useEffect)(()=>{a(e=>{let t={...e};for(let e of r)t[e.id]??(t[e.id]=e.prompt);return t})},[r]);let d=(0,N.useCallback)(async e=>{let n=i[e.id]?.trim();if(!u||!n){l(t=>({...t,[e.id]:{ok:!1,message:u?`Prompt is empty.`:`Task launcher block is missing projectPath.`}}));return}s(t=>({...t,[e.id]:!0})),l(t=>({...t,[e.id]:{ok:!0,message:`Launching…`}}));try{let r=`🧭 ${e.title}`.slice(0,120),i=await fetch(`/api/terminal/launch-agent-session`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({cwd:u,prompt:n,title:r,userInitiated:!0})}),a=await i.json().catch(()=>({}));if(!i.ok||!a.ok||!a.sessionId)throw Error(a.error||`Launch failed (${i.status})`);t({requestId:`task-launcher-${e.id}-${a.sessionId}`,cwd:u,title:r,existingPtyId:a.sessionId,spawnPi:!0,sessionType:`pi`,wasIdle:!0}),l(t=>({...t,[e.id]:{ok:!0,message:`Launched session ${a.sessionId}`,sessionId:a.sessionId}}))}catch(t){l(n=>({...n,[e.id]:{ok:!1,message:t instanceof Error?t.message:String(t)}}))}finally{s(t=>({...t,[e.id]:!1}))}},[t,u,i]);return r.length===0?null:(0,M.jsx)(`section`,{className:`group/gui my-3`,"data-testid":`pi-rendered-generative-ui`,"data-generative-ui-type":`task_launcher`,children:(0,M.jsx)(`div`,{className:`space-y-3`,children:r.map(e=>{let t=i[e.id]??e.prompt,n=c[e.id],r=o[e.id]===!0;return(0,M.jsxs)(`article`,{className:`rounded-xl border border-terminal-border/45 bg-terminal-bg/55 p-3 shadow-sm`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`rounded-full border border-terminal-cyan/25 bg-terminal-cyan/10 px-2 py-0.5 font-mono text-[10px] uppercase tracking-[0.12em] text-terminal-cyan`,children:e.id}),(0,M.jsx)(`h3`,{className:`min-w-0 flex-1 text-sm font-semibold leading-snug text-terminal-text`,children:e.title})]}),e.summary?(0,M.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-[12px] leading-relaxed text-terminal-muted`,children:e.summary}):null]}),(0,M.jsx)(`button`,{type:`button`,disabled:r||!u||!t.trim(),onClick:()=>void d(e),className:`rounded-lg border border-terminal-cyan/50 bg-terminal-cyan/12 px-3 py-1.5 font-mono text-[11px] font-bold uppercase tracking-[0.12em] text-terminal-cyan transition hover:bg-terminal-cyan/20 disabled:cursor-not-allowed disabled:opacity-45`,children:r?`Launching…`:`Launch session`})]}),(0,M.jsxs)(`div`,{className:`mt-3 grid gap-2 text-[11px] text-terminal-muted sm:grid-cols-3`,children:[e.sourceNodeIds.length?(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`span`,{className:`font-mono text-terminal-cyan/80`,children:`Source:`}),` `,e.sourceNodeIds.join(`, `)]}):null,e.suggestedFiles.length?(0,M.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,M.jsx)(`span`,{className:`font-mono text-terminal-cyan/80`,children:`Files:`}),` `,e.suggestedFiles.join(`, `)]}):null,e.validation?(0,M.jsxs)(`div`,{className:`sm:col-span-3`,children:[(0,M.jsx)(`span`,{className:`font-mono text-terminal-cyan/80`,children:`Validate:`}),` `,e.validation]}):null]}),e.plan?(0,M.jsxs)(`details`,{className:`mt-3 rounded-lg border border-terminal-border/35 bg-terminal-surface/20 px-3 py-2`,children:[(0,M.jsx)(`summary`,{className:`cursor-pointer font-mono text-[11px] uppercase tracking-[0.12em] text-terminal-muted hover:text-terminal-cyan`,children:`Plan`}),(0,M.jsx)(`div`,{className:`mt-2 whitespace-pre-wrap text-[12px] leading-relaxed text-terminal-text/82`,children:e.plan})]}):null,(0,M.jsxs)(`label`,{className:`mt-3 block`,children:[(0,M.jsx)(`span`,{className:`mb-1 block font-mono text-[10px] font-bold uppercase tracking-[0.16em] text-terminal-muted`,children:`Editable launch prompt`}),(0,M.jsx)(`textarea`,{value:t,onChange:t=>a(n=>({...n,[e.id]:t.target.value})),rows:8,className:`w-full resize-y rounded-lg border border-terminal-border/55 bg-terminal-bg px-3 py-2 font-mono text-[11px] leading-relaxed text-terminal-text outline-none focus:border-terminal-cyan/60`})]}),n?(0,M.jsx)(`div`,{className:`mt-2 rounded-md border px-2 py-1.5 font-mono text-[11px] ${n.ok?`border-terminal-green/25 bg-terminal-green/10 text-terminal-green`:`border-terminal-red/30 bg-terminal-red/10 text-terminal-red`}`,children:n.message}):null]},e.id)})})})}function Vr({block:e}){let[t,n]=(0,N.useState)(!1),r=(0,N.useCallback)(()=>n(!1),[]),i=e.type.toLowerCase(),a=$(e.title)||(i===`html`?`Generated interface`:`Generated UI`);if(e.subtitle,i===`task_launcher`)return(0,M.jsx)(Br,{block:e});if(i===`vision_inspection`){let i=Array.isArray(e.crops)?(e.crops??[]).map(e=>({...e,title:e.title||e.label||e.crop_id,imagePath:e.imagePath||e.image_path||e.output_path||e.path,imageUrl:e.imageUrl||e.image_url||e.url})):[],o=Array.isArray(e.observations)?e.observations??[]:[],s=(Array.isArray(e.items)&&e.items.length>0?e.items:i).slice(0,12).map(e=>{if(e.observation||!e.crop_id)return e;let t=o.find(t=>t.crop_id===e.crop_id||t.label===e.label);return t?{...e,observation:t.observation,importance:e.importance||t.importance}:e});if(s.length===0)return null;let c=e=>(0,M.jsx)(`div`,{className:e?`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`:`grid gap-2 sm:grid-cols-2`,children:s.map((t,n)=>{let r=$(t.title||t.label||t.region||`Region ${n+1}`),i=$(t.observation||t.detail||t.description),a=$(t.importance||t.badge||t.status),o=$(t.region),s=$(t.imagePath||t.path),c=$(t.imageUrl||t.url)||(s?De(s):``),l=Nr(a||$(t.tone));return(0,M.jsxs)(`article`,{className:`overflow-hidden rounded-xl border ${l.border} ${l.bg}`,children:[c?(0,M.jsxs)(`div`,{className:`relative border-b border-terminal-border/30 bg-black/35`,children:[(0,M.jsx)(`img`,{src:c,alt:r,loading:`lazy`,className:e?`h-56 w-full object-contain`:`h-32 w-full object-contain`}),a?(0,M.jsx)(`span`,{className:`absolute right-2 top-2 rounded-full border ${l.border} bg-slate-950/80 px-2 py-0.5 font-mono text-[9px] uppercase tracking-[0.12em] ${l.text}`,children:a}):null]}):null,(0,M.jsxs)(`div`,{className:e?`p-4`:`p-3`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 font-mono ${e?`text-sm`:`text-[11px]`}`,children:[(0,M.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${l.dot}`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-bold ${l.text}`,children:r})]}),i?(0,M.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap break-words leading-relaxed text-terminal-text/82 ${e?`text-sm`:`text-[11px]`}`,children:i}):null,o?(0,M.jsxs)(`div`,{className:`mt-2 rounded-md border border-terminal-border/30 bg-terminal-bg/35 px-2 py-1 font-mono text-[10px] text-terminal-muted/75`,children:[`region: `,o]}):null,s?(0,M.jsx)(`div`,{className:`mt-1 truncate font-mono text-[9px] text-terminal-muted/55`,title:s,children:s}):null]})]},`${r}-${n}`)})});return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`section`,{className:`group/gui relative my-3`,"data-testid":`pi-rendered-generative-ui`,"data-generative-ui-type":`vision_inspection`,children:[(0,M.jsx)(`div`,{className:`absolute right-0 top-0 z-10`,children:(0,M.jsx)(Rr,{onClick:()=>n(!0)})}),c(!1)]}),t&&(0,M.jsx)(Lr,{title:a||`Vision inspection`,onClose:r,children:(0,M.jsx)(`section`,{className:`rounded-xl border border-terminal-cyan/25 bg-gradient-to-br from-terminal-cyan/[0.07] to-terminal-purple/[0.045] p-3 sm:p-4`,children:c(!0)})})]})}if(i===`html`&&typeof e.html==`string`&&e.html.trim()){let i=`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>
*{box-sizing:border-box;margin:0;padding:0}
body{background:#020617;color:#e5e7eb;font-family:Inter,-apple-system,BlinkMacSystemFont,'SF Pro Text','Segoe UI',system-ui,sans-serif;padding:16px;overflow-x:hidden}
h1,h2,h3{font-weight:700;letter-spacing:-0.02em}
h1{font-size:clamp(1.4rem,4vw,2rem)}
h2{font-size:clamp(1.1rem,3vw,1.5rem)}
h3{font-size:clamp(0.95rem,2.5vw,1.2rem)}
@media(max-width:480px){body{padding:12px;font-size:14px}}
</style></head><body>${e.html}</body></html>`,o=Pr(e.height);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`section`,{className:`group/gui relative my-3 overflow-hidden rounded-xl`,"data-testid":`pi-rendered-generative-ui`,"data-generative-ui-type":`html`,children:[(0,M.jsx)(`div`,{className:`absolute right-1 top-1 z-10`,children:(0,M.jsx)(Rr,{onClick:()=>n(!0)})}),(0,M.jsx)(`iframe`,{title:a,sandbox:`allow-scripts`,srcDoc:i,className:`w-full bg-slate-950`,style:{height:o,minHeight:120}})]}),t&&(0,M.jsx)(Lr,{title:a,onClose:r,children:(0,M.jsx)(`iframe`,{title:a,sandbox:`allow-scripts`,srcDoc:i,className:`w-full h-full rounded-xl border border-terminal-purple/20 bg-slate-950`,style:{minHeight:`70vh`}})})]})}if(i===`table`&&Array.isArray(e.columns)&&Array.isArray(e.rows)){let i=t=>(0,M.jsx)(`div`,{className:`overflow-x-auto`,children:(0,M.jsxs)(`table`,{className:`min-w-full border-collapse font-mono ${t?`text-sm`:`text-[11px] sm:text-xs`}`,children:[(0,M.jsx)(`thead`,{children:(0,M.jsx)(`tr`,{children:e.columns.map(e=>(0,M.jsx)(`th`,{className:`border-b border-terminal-cyan/15 px-2 sm:px-3 py-2 text-left text-terminal-cyan/75 ${t?`px-4 py-3`:``}`,children:e},e))})}),(0,M.jsx)(`tbody`,{children:e.rows.slice(0,80).map((n,r)=>(0,M.jsx)(`tr`,{className:`border-b border-terminal-border/25 last:border-0`,children:e.columns.map(e=>(0,M.jsx)(`td`,{className:`max-w-[22rem] px-2 sm:px-3 py-2 text-terminal-text/85 align-top ${t?`px-4 py-3`:``}`,children:(0,M.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:$(n[e])})},e))},r))})]})});return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`section`,{className:`group/gui relative my-3 overflow-hidden rounded-xl`,"data-testid":`pi-rendered-generative-ui`,"data-generative-ui-type":`table`,children:[(0,M.jsx)(`div`,{className:`absolute right-0 top-0 z-10`,children:(0,M.jsx)(Rr,{onClick:()=>n(!0)})}),i(!1)]}),t&&(0,M.jsx)(Lr,{title:a,onClose:r,children:(0,M.jsx)(`section`,{className:`rounded-xl border border-terminal-cyan/25 bg-terminal-cyan/[0.045] overflow-hidden`,children:i(!0)})})]})}let o=Array.isArray(e.items)?e.items:[];if(o.length===0)return null;let s=i===`timeline`,c=e=>(0,M.jsx)(`div`,{className:s?`space-y-2`:e?`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`:`space-y-2 sm:space-y-0 sm:grid sm:gap-2 sm:grid-cols-2`,children:o.slice(0,24).map((t,n)=>{let r=Nr($(t.tone||t.status)),i=$(t.title||t.label||t.step)||`Item ${n+1}`,a=$(t.detail||t.description||t.next||t.value),o=$(t.badge||t.status||t.kind);return(0,M.jsxs)(`div`,{className:`rounded-lg border ${r.border} ${r.bg} px-3 py-2 ${e?`px-4 py-3`:``}`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 font-mono ${e?`text-sm`:`text-[11px]`}`,children:[(0,M.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${r.dot}`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-bold ${r.text}`,children:i}),o&&(0,M.jsx)(`span`,{className:`shrink-0 rounded-full border ${r.border} px-1.5 py-0.5 text-[9px] uppercase tracking-wider ${r.text}`,children:o})]}),a&&(0,M.jsx)(`div`,{className:`mt-1 whitespace-pre-wrap break-words leading-relaxed text-terminal-text/78 ${e?`text-sm`:`text-[11px]`}`,children:a})]},`${i}-${n}`)})});return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`section`,{className:`group/gui relative my-3`,"data-testid":`pi-rendered-generative-ui`,"data-generative-ui-type":i,children:[(0,M.jsx)(`div`,{className:`absolute right-0 top-0 z-10`,children:(0,M.jsx)(Rr,{onClick:()=>n(!0)})}),c(!1)]}),t&&(0,M.jsx)(Lr,{title:a,onClose:r,children:(0,M.jsx)(`section`,{className:`rounded-xl border border-terminal-purple/25 bg-terminal-purple/[0.035] p-3 sm:p-4`,children:c(!0)})})]})}var Hr={to:`To`,cc:`Cc`,bcc:`Bcc`,from:`From`,subject:`Subject`,title:`Title`,channel:`Channel`,recipient:`To`,platform:`Platform`};function Ur(e,t){let n=e.replace(/^\n+/,``).replace(/\s+$/,``),r=[],i=n.split(`
`),a=0;for(;a<i.length;a+=1){let e=i[a];if(!e.trim())continue;let t=/^([A-Za-z][A-Za-z ]{0,20}):\s*(.*)$/.exec(e),n=t?t[1].trim().toLowerCase():``;if(!t||!Hr[n])break;r.push({label:Hr[n],value:t[2].trim()})}return{fields:r,body:i.slice(a).join(`
`).replace(/^\s*---+\s*\n?/,``).replace(/^\n+/,``),streaming:t}}function Wr(e){let t=[],n=/```mc-draft[^\n]*\n([\s\S]*?)(?:```|$)/gi,r=0,i;for(;(i=n.exec(e))!==null;){let n=e.slice(r,i.index);n.trim()&&t.push({kind:`markdown`,text:n.trim()});let a=i[0].trimEnd().endsWith("```");t.push({kind:`draft`,draft:Ur(i[1],!a)}),r=i.index+i[0].length}let a=e.slice(r);return(a.trim()||t.length===0)&&t.push({kind:`markdown`,text:a.trim()}),t}function Gr(e,t){let n=e.fields.map(e=>`${e.label}: ${e.value}`).join(`
`);return n?`${n}\n\n${t}`:t}function Kr(){return(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,M.jsx)(`rect`,{x:`9`,y:`9`,width:`11`,height:`11`,rx:`2`}),(0,M.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})}function qr(){return(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,M.jsx)(`path`,{d:`M12 20h9`}),(0,M.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}function Jr({draft:e}){let[t,n]=(0,N.useState)(!1),[r,i]=(0,N.useState)(null),[a,o]=(0,N.useState)(!1),s=r??e.body;(0,N.useEffect)(()=>{if(!a)return;let e=window.setTimeout(()=>o(!1),1600);return()=>window.clearTimeout(e)},[a]);let c=(0,N.useCallback)(()=>{navigator.clipboard?.writeText(Gr(e,s)).then(()=>o(!0)).catch(()=>void 0)},[s,e]),l=(0,N.useMemo)(()=>s.replace(/(\S)\n(?!\n)/g,`$1  
`),[s]);return(0,M.jsxs)(`div`,{className:`my-3 overflow-hidden rounded-2xl border border-terminal-border/45 bg-terminal-bg/40`,"data-rendered-draft":e.streaming?`streaming`:`complete`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`inline-flex items-center gap-1.5 rounded-full border border-terminal-border/50 px-2.5 py-1 text-[11px] text-terminal-muted transition-colors hover:border-terminal-border hover:text-terminal-text`,children:[(0,M.jsx)(qr,{}),t?`Done`:`Edit`]}),(0,M.jsxs)(`button`,{type:`button`,onClick:c,title:`Copy draft`,"aria-label":`Copy draft`,className:`inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-[11px] text-terminal-muted transition-colors hover:text-terminal-text`,children:[(0,M.jsx)(Kr,{}),a?`Copied`:null]})]}),e.fields.length>0&&(0,M.jsx)(`div`,{className:`border-t border-terminal-border/35`,children:e.fields.map(e=>(0,M.jsxs)(`div`,{className:`border-b border-terminal-border/25 px-4 py-2.5 text-[13px] last:border-b-0`,children:[(0,M.jsx)(`span`,{className:`mr-2 text-terminal-muted/70`,children:e.label}),(0,M.jsx)(`span`,{className:`text-terminal-text/95`,children:e.value})]},e.label))}),(0,M.jsx)(`div`,{className:`border-t border-terminal-border/35 px-4 py-3`,children:t?(0,M.jsx)(`textarea`,{value:s,onChange:e=>i(e.target.value),rows:Math.min(24,Math.max(6,s.split(`
`).length+1)),className:`w-full resize-y rounded-lg border border-terminal-border/45 bg-transparent p-2 font-mono text-[12.5px] leading-[1.7] text-terminal-text/95 outline-none focus:border-terminal-cyan/50`}):(0,M.jsx)(`div`,{className:`markdown-body text-[13px] leading-[1.75] text-terminal-text/95 [overflow-wrap:anywhere]`,children:(0,M.jsx)(h,{remarkPlugins:[m],children:l})})})]})}var Yr=/\.(?:html?|svg|png|jpe?g|gif|webp|pdf|json|txt|md|markdown)$/i;function Xr(e){let t=e.trim();if(!t||t.length>4e3||/[\r\n]/.test(t)||/^https?:\/\//i.test(t)||!(t.startsWith(`/`)||t.startsWith(`./`)||t.startsWith(`../`)||t.startsWith(`~/`))&&!/^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+$/.test(t))return null;let n=t.split(/[?#]/,1)[0];return Yr.test(n)?t:null}function Zr(e){if(!e)return[];let t=[],n=new Set;for(let r of e.matchAll(/`([^`\n]{1,4000})`/g)){let e=Xr(r[1]);!e||n.has(e)||(n.add(e),t.push(e))}return t}function Qr(e){return e.split(/[?#]/,1)[0].split(/[\\/]/).filter(Boolean).at(-1)||`Artifact`}var $r=`[Axis ask-block answers]`;function ei(e){return e.role===`user`&&e.textContent?.trimStart().startsWith($r)===!0}function ti(e){try{let t=JSON.parse(e.sections_json);return Array.isArray(t)?t:[]}catch{return[]}}function ni(e){if(!e)return{};try{let t=JSON.parse(e),n={};for(let e of t.sections??[])for(let t of e.answers??[])n[t.questionId]=t.value;return n}catch{return{}}}function ri(e){return ni(e?.answers_json)}function ii(e){return ni(e?.answers_json)}function ai(e){return`/api/sessions/${encodeURIComponent(e)}/ask-blocks`}function oi(e,t){return`${ai(e)}?anchorId=${encodeURIComponent(t)}`}function si(e,t){return`${ai(e)}/${encodeURIComponent(t)}`}function ci(e,t){return`${si(e,t)}/draft`}function li(e,t){return`${si(e,t)}/submit`}async function ui(e){let t=await e.json().catch(()=>null);if(!e.ok){let n=t?.error??t?.message??`HTTP ${e.status}`;throw Error(n)}return t}async function di(e,t){let n=await ui(await fetch(ai(e),{cache:`no-store`,signal:t}));return Array.isArray(n.askBlocks)?n.askBlocks:[]}async function fi(e,t,n){let r=await ui(await fetch(oi(e,t),{cache:`no-store`,signal:n}));return r.askBlock?{askBlock:r.askBlock,draft:r.draft??null,submission:r.submission??null}:null}async function pi(e,t,n,r={}){return ui(await fetch(ci(e,t),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({answers:n,writerId:r.writerId,mutationId:r.mutationId})}))}async function mi(e,t,n,r){return ui(await fetch(li(e,t),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({answers:n,clientRequestId:r})}))}function hi(e){return e.role!==`user`||!(e.textContent?.trimStart()??``).startsWith(`Ralph Loop wake-up`)?null:`Woken up by Ralph Loop`}function gi(e,t){if(e===t)return!0;let n=e??[],r=t??[];if(n.length!==r.length)return!1;for(let e=0;e<n.length;e+=1){let t=n[e],i=r[e];if(t.id!==i.id||t.name!==i.name||t.path!==i.path||t.previewUrl!==i.previewUrl||t.uploadStatus!==i.uploadStatus||t.processingError!==i.processingError)return!1}return!0}function _i(e,t){if(e===t)return!0;let n=e??[],r=t??[];if(n.length!==r.length)return!1;for(let e=0;e<n.length;e+=1){let t=n[e],i=r[e];if(t.name!==i.name||JSON.stringify(t.arguments??{})!==JSON.stringify(i.arguments??{}))return!1}return!0}function vi(e,t){return e===t?!0:e.id===t.id&&e.role===t.role&&e.timestamp===t.timestamp&&e.textContent===t.textContent&&e.nativeStreaming===t.nativeStreaming&&e.thinking===t.thinking&&e.stopReason===t.stopReason&&e.errorMessage===t.errorMessage&&e.optimistic===t.optimistic&&e.optimisticAccepted===t.optimisticAccepted&&e.optimisticFailed===t.optimisticFailed&&e.optimisticIntentLedgerId===t.optimisticIntentLedgerId&&e.optimisticIntentStatus===t.optimisticIntentStatus&&e.optimisticIntentError===t.optimisticIntentError&&e.model===t.model&&gi(e.optimisticAttachments,t.optimisticAttachments)&&_i(e.toolCalls,t.toolCalls)}function yi(e){let t=[],n=Ci(e.textContent??``),r=(e.role===`user`?Be(ue(n)):n).trim();r&&t.push(r);let i=Ci(e.thinking??``).trim();i&&t.push(`Thinking:\n${i}`);let a=e.errorMessage?.trim();return a&&t.push(`Error: ${a}`),e.optimisticAttachments?.length&&t.push(e.optimisticAttachments.map(e=>e.path||e.name).filter(Boolean).join(`
`)),e.toolCalls?.length&&t.push(e.toolCalls.map(e=>{let t=JSON.stringify(e.arguments??{},null,2);return t&&t!==`{}`?`Tool: ${e.name}\n${t}`:`Tool: ${e.name}`}).join(`

`)),t.filter(Boolean).join(`

`).trim()}function bi(e){let t=e.errorMessage?.trim()??``;return e.role!==`assistant`||!t||!/error|fail|exception/i.test(e.stopReason??``)?null:/context window|context length|too many tokens|maximum context/i.test(t)?{title:`Context limit reached`,summary:`This task exceeded the model’s available context. Run /compact or start a new task before continuing. Any queued message stays queued; press Enter in the empty composer when you are ready to steer it.`,detail:t}:{title:`Agent stopped`,summary:`The model stopped before it could finish this turn. The queued message has not been sent.`,detail:t}}async function xi(e){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(e);return}let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,`true`),t.style.position=`fixed`,t.style.left=`-9999px`,t.style.top=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`)}finally{t.remove()}}var Si=/\n\n…\[truncated \d+ chars from fast tail payload\]\s*$/;function Ci(e){return e.replace(Si,``).trimEnd()}function wi(e){return e.includes(`
`)||e.includes(`\r`)}function Ti(e){return Be(ue(e)).replace(/\r\n/g,`
`).replace(/\s+/g,` `).trim()}function Ei(e,t){let n=new Date(e.timestamp).getTime();return Number.isFinite(n)?Di(e,t)?!0:t.some(e=>{if(e.role!==`user`&&e.role!==`assistant`)return!1;let t=new Date(e.timestamp).getTime();return Number.isFinite(t)&&t>=n-1e3}):!1}function Di(e,t){let n=new Date(e.timestamp).getTime();if(!Number.isFinite(n))return null;let r=Ti(e.textContent?.trim()),i=e.optimisticAttachments?.map(e=>e.path).filter(Boolean)??[];for(let e of t){if(e.role!==`user`)continue;let t=new Date(e.timestamp).getTime();if(!Number.isFinite(t)||t<n-5e3)continue;let a=e.textContent?.trim()??``,o=Ti(a);if(r&&(o.includes(r)||r.includes(o))||i.length>0&&i.every(e=>a.includes(e)))return e}return null}function Oi(e,t,n){let r=[];for(let e of t){if(e.role!==`user`)continue;let t=new Date(e.timestamp).getTime();Number.isFinite(t)&&r.push({id:e.id,kind:`optimistic`,at:t,text:e.textContent??``,attachmentPaths:e.optimisticAttachments?.map(e=>e.path).filter(Boolean)??[]})}for(let t of e){let e=new Date(t.createdAt??``).getTime();Number.isFinite(e)&&r.push({id:t.id,kind:`queue`,at:e,text:t.text,attachmentPaths:t.attachments?.map(e=>e.path).filter(Boolean)??[]})}r.sort((e,t)=>e.at-t.at||(e.kind===`optimistic`?-1:1));let i=n.filter(e=>e.role===`user`&&Number.isFinite(new Date(e.timestamp).getTime())).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),a=new Set,o=new Set;for(let e of r){let t=Ti(e.text),n=e.at-(e.kind===`optimistic`?5e3:0),r=i.find(r=>{if(a.has(r.id)||new Date(r.timestamp).getTime()<n)return!1;let i=r.textContent?.trim()??``,o=Ti(i);return!!(t&&o&&(o.includes(t)||t.includes(o))||e.attachmentPaths.length>0&&e.attachmentPaths.every(e=>i.includes(e)))});r&&(a.add(r.id),e.kind===`queue`&&o.add(e.id))}return o}function ki(e){if(!wi(e))return null;let t=e.replace(/\r/g,`
`).split(`
`).map(e=>e.trim()).filter(Boolean).join(`
`).replace(/\u001b\[[0-9;]*[A-Za-z]/g,``).replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g,``).trim();return t.length>=2?t:null}function Ai(e,t){let n=e.replace(/!\[[^\]]*\]\([^)]*\)/g,``).replace(/\[[^\]]*\]\(([^)]*)\)/g,`$1`).replace(/[`*_>#~-]+/g,` `).replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1).trim()}…`:n}function ji(e,t=Date.now()){let n=new Date(e).getTime()-t;if(!Number.isFinite(n))return`time unknown`;if(n<=0)return`due now`;let r=Math.ceil(n/1e3),i=Math.floor(r/60),a=r%60;if(i<1)return`${a}s`;if(i<60)return`${i}m ${a.toString().padStart(2,`0`)}s`;let o=Math.floor(i/60),s=i%60;return o<24?`${o}h ${s}m`:`${Math.floor(o/24)}d ${o%24}h`}var Mi=N.memo(function({message:e,isLatest:t,assistantActionsEnabled:n=!0,handoffAgents:r=[],onOpenHandoffAgent:i,onForkMessage:a,cwd:o,onOpenFileAsArtifact:s}){let c=e.role===`user`,l=t?bi(e):null,[u,d]=(0,N.useState)(!1),[f,ee]=(0,N.useState)(!1),[p,te]=(0,N.useState)(!1),g=(0,N.useRef)(null),_=(0,N.useRef)(!1),v=(0,N.useRef)(null),y=(0,N.useMemo)(()=>yi(e),[e]),ne=(0,N.useMemo)(()=>c?le(e.textContent):[],[c,e.textContent]),re=(0,N.useMemo)(()=>c?it(e):[],[c,e]),b=(0,N.useMemo)(()=>c?[]:rt(e),[c,e]),ie=(0,N.useMemo)(()=>Ci(e.thinking??``),[e.thinking]),x=(0,N.useMemo)(()=>{let t=Ci(e.textContent??``),n=c?Be(ue(t)):t;return c?re.length===0?n:Ne(n.replace(/\[video\][\s\S]*?\[\/video\]/gi,``).trim()):b.length>0?Pe(n):n},[re.length,c,e.textContent,b.length]),ae=!c&&!l&&!/tool[_-]?use/i.test(e.stopReason??``),{displayText:oe,revealing:S}=bt({messageId:e.id,text:x,timestamp:e.timestamp,isLatest:!!(t&&ae),enabled:ae}),se=ae?oe:x,C=(0,N.useMemo)(()=>Mr(se),[se]),ce=(0,N.useMemo)(()=>c?[{kind:`markdown`,text:C.markdown}]:Wr(C.markdown),[C.markdown,c]),de=ce.some(e=>e.kind===`draft`),fe=(0,N.useMemo)(()=>({code({children:e,className:t,node:n,...r}){let i=String(e??``).replace(/\n$/,``),a=!n?.position||n.position.start.line===n.position.end.line,o=!c&&!t&&a?Xr(i):null;if(!o||!s)return(0,M.jsx)(`code`,{className:t,...r,children:e});let l=Qr(o);return(0,M.jsxs)(`button`,{type:`button`,className:`group/artifact-path inline-flex max-w-full items-center gap-1 rounded border border-terminal-cyan/25 bg-terminal-cyan/[0.055] px-1.5 py-0.5 align-baseline font-mono text-[0.92em] text-terminal-cyan transition-colors hover:border-terminal-cyan/55 hover:bg-terminal-cyan/10`,onClick:e=>{e.preventDefault(),e.stopPropagation(),s(o,l)},title:`Open ${o} as a session artifact`,"aria-label":`Open ${l} as an artifact`,"data-rendered-artifact-path":o,children:[(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:i}),(0,M.jsx)(`span`,{"aria-hidden":`true`,className:`shrink-0 text-[9px] opacity-55 transition-opacity group-hover/artifact-path:opacity-100`,children:`↗`})]})}}),[c,s]),pe=(0,N.useMemo)(()=>hi(e),[e]),w=c&&(x.length>700||x.split(`
`).length>10),T=!e.optimistic&&!!e.id&&!!a,E=c||n,me=n&&e.nativeStreaming!==!0&&ae&&!S&&!!y.trim(),D=(0,N.useCallback)(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null),v.current=null},[]);(0,N.useEffect)(()=>D,[D]);let O=(0,N.useCallback)(()=>{_.current=!1,te(!1)},[]);(0,N.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&O()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O,p]),(0,N.useEffect)(()=>{!E&&p&&O()},[E,O,p]);let k=(0,N.useCallback)(async()=>{if(y.trim())try{await xi(y),d(!0),window.setTimeout(()=>d(!1),1200)}catch(e){console.warn(`[PiSessionRenderedView] failed to copy message`,e)}},[y]),he=(0,N.useCallback)(e=>{E&&y.trim()&&(e.pointerType!==`touch`&&e.pointerType!==`pen`||e.target.closest(`button, a, summary, input, textarea, select, [contenteditable]`)||(D(),_.current=!1,v.current={x:e.clientX,y:e.clientY,pointerId:e.pointerId},g.current=window.setTimeout(()=>{g.current=null,v.current=null,_.current=!0,window.navigator.vibrate?.(12),te(!0)},500)))},[E,D,y]),A=(0,N.useCallback)(e=>{let t=v.current;!t||t.pointerId!==e.pointerId||Math.hypot(e.clientX-t.x,e.clientY-t.y)>10&&D()},[D]),ge=(0,N.useCallback)(()=>{D()},[D]),_e=!!(x.trim()||l||b.length>0||r.length>0||ie.trim()&&e.nativeStreaming!==!0&&/tool[_-]?use/i.test(e.stopReason??``));return!c&&!_e||ei(e)?null:pe?(0,M.jsxs)(`div`,{className:`my-1 flex items-center gap-1.5 pl-1 text-[11px] text-terminal-muted/70`,"data-testid":`pi-rendered-automation-wake`,"data-rendered-message-id":e.id||void 0,title:x,children:[(0,M.jsx)(`span`,{"aria-hidden":`true`,children:`↻`}),(0,M.jsx)(`span`,{children:pe})]}):(0,M.jsxs)(`article`,{className:`group/message relative min-w-0 select-text touch-pan-y ${c?`ml-auto max-w-[92%] overflow-visible`:`mr-auto max-w-full overflow-visible border-0 bg-transparent px-1 py-2 pr-10 text-terminal-text/95 shadow-none md:py-1`}`,title:E&&y?`Long press for message actions`:void 0,"data-testid":`pi-rendered-message-card`,"data-rendered-message-id":e.id||void 0,"data-rendered-message-role":e.role,"data-rendered-message-layout":c?`user-bubble`:`assistant-plain`,"data-copied":u?`true`:void 0,onPointerDown:he,onPointerMove:A,onPointerUp:ge,onPointerCancel:ge,onLostPointerCapture:D,onClickCapture:e=>{_.current&&=(e.preventDefault(),e.stopPropagation(),!1)},onContextMenu:e=>{(p||_.current)&&e.preventDefault()},children:[p&&typeof document<`u`&&(0,Ze.createPortal)((0,M.jsx)(`div`,{className:`fixed inset-0 z-[10050] flex items-end bg-black/35 p-3 md:hidden`,role:`presentation`,onClick:O,"data-testid":`pi-rendered-message-action-backdrop`,children:(0,M.jsxs)(`div`,{className:`w-full rounded-2xl border border-terminal-border/75 bg-terminal-surface p-2 pb-[max(0.5rem,env(safe-area-inset-bottom))] shadow-2xl`,role:`menu`,"aria-label":`Message actions`,onClick:e=>e.stopPropagation(),"data-testid":`pi-rendered-message-action-menu`,children:[(0,M.jsx)(`div`,{className:`mx-auto mb-2 h-1 w-9 rounded-full bg-terminal-muted/35`,"aria-hidden":`true`}),(0,M.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex min-h-12 w-full items-center gap-3 rounded-xl px-3 text-left text-sm text-terminal-text active:bg-terminal-border/50`,onClick:()=>{k(),O()},children:[(0,M.jsx)(`span`,{"aria-hidden":`true`,children:`⧉`}),(0,M.jsx)(`span`,{children:u?`Copied`:`Copy message`})]}),T&&(c||n)&&(0,M.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`flex min-h-12 w-full items-center gap-3 rounded-xl px-3 text-left text-sm text-terminal-text active:bg-terminal-border/50`,onClick:()=>{a?.(e),O()},children:[(0,M.jsx)(`span`,{"aria-hidden":`true`,children:`⑂`}),(0,M.jsx)(`span`,{children:c?`Branch from this message`:`Start new thread`})]}),(0,M.jsx)(`button`,{type:`button`,className:`mt-1 min-h-12 w-full rounded-xl border-t border-terminal-border/50 px-3 text-sm text-terminal-muted active:bg-terminal-border/50`,onClick:O,children:`Cancel`})]})}),document.body),c&&re.length>0?(0,M.jsx)(F,{attachments:re,variant:`message`}):null,(0,M.jsxs)(`div`,{className:c?`overflow-hidden rounded-xl border border-transparent bg-transparent px-4 py-4 text-terminal-muted shadow-sm md:py-3`:`contents`,"data-testid":c?`pi-rendered-user-bubble`:void 0,children:[c&&ne.length>0?(0,M.jsx)(Ue,{references:ne,compact:!0}):null,l?(0,M.jsx)(`div`,{className:`rounded-xl border border-red-500/35 bg-red-50 px-4 py-3 text-red-950 shadow-sm dark:border-red-400/35 dark:bg-red-500/[0.08] dark:text-red-100`,role:`alert`,"data-testid":`pi-rendered-provider-error`,children:(0,M.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,M.jsx)(`span`,{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full bg-red-600 shadow-[0_0_8px_rgba(220,38,38,0.3)] dark:bg-red-400 dark:shadow-[0_0_10px_rgba(248,113,113,0.55)]`,"aria-hidden":`true`}),(0,M.jsxs)(`div`,{className:`min-w-0`,children:[(0,M.jsx)(`div`,{className:`text-sm font-semibold text-red-950 dark:text-red-100`,children:l.title}),(0,M.jsx)(`div`,{className:`mt-1 text-[13px] leading-relaxed text-red-900 dark:text-red-100/90`,children:l.summary}),(0,M.jsx)(`div`,{className:`mt-2 break-words font-mono text-[11px] leading-relaxed text-red-800 dark:text-red-200/75`,children:l.detail})]})]})}):null,!c&&ie.trim()&&(/tool[_-]?use/i.test(e.stopReason??``)||e.nativeStreaming===!0)&&(0,M.jsx)(Vn,{text:ie,messageId:e.id,timestamp:e.timestamp,streaming:e.nativeStreaming===!0}),se.trim()||S?(0,M.jsxs)(`div`,{className:`relative`,"data-assistant-revealing":S?`true`:void 0,"data-testid":S?`pi-rendered-assistant-revealing`:void 0,"data-rendered-writing":S?`1`:void 0,children:[S&&!de?(0,M.jsxs)(`div`,{className:`whitespace-pre-wrap break-words text-[13px] leading-[1.75] [overflow-wrap:anywhere] text-terminal-text/95`,children:[se,(0,M.jsx)(kt,{})]}):(0,M.jsxs)(`div`,{className:`markdown-body text-[13px] leading-[1.75] break-words [overflow-wrap:anywhere] [&_code]:[overflow-wrap:anywhere] [&_pre]:whitespace-pre-wrap [&_pre]:break-words [&_pre]:overflow-x-hidden [&_pre]:[overflow-wrap:anywhere] ${c?`text-terminal-muted`:`text-terminal-text/95`} ${w&&!f?`max-h-52 overflow-hidden`:``}`,children:[ce.map((t,n)=>t.kind===`draft`&&!c?(0,M.jsx)(Jr,{draft:t.draft},`${e.id}-draft-${n}`):(0,M.jsx)(h,{remarkPlugins:[m],components:fe,children:t.kind===`markdown`?t.text:``},`${e.id}-md-${n}`)),!c&&C.blocks.map((t,n)=>(0,M.jsx)(Vr,{block:t},`${e.id}-gui-${n}`))]}),w&&!f&&(0,M.jsx)(`div`,{"aria-hidden":`true`,className:`text-[13px] leading-[1.75] text-terminal-muted`,children:`…`}),w&&(0,M.jsxs)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),ee(e=>!e)},className:`mt-1 inline-flex items-center gap-1 text-[13px] text-terminal-muted/70 transition-colors hover:text-terminal-text`,"data-testid":`pi-rendered-long-message-toggle`,children:[(0,M.jsx)(`span`,{children:f?`Show less`:`Show more`}),(0,M.jsx)(`span`,{"aria-hidden":`true`,className:`text-[10px]`,children:f?`⌃`:`⌄`})]})]}):null]}),c&&(y.trim()||T)&&(0,M.jsxs)(`div`,{className:`mt-1 hidden h-7 items-center justify-end gap-1 text-terminal-muted opacity-0 transition-opacity duration-150 group-hover/message:opacity-60 focus-within:opacity-100 md:flex ${u?`!opacity-100`:``}`,"data-testid":`pi-rendered-user-actions`,children:[(0,M.jsx)(`time`,{className:`mr-1 font-mono text-[10px]`,dateTime:e.timestamp,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}),y.trim()&&(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),k()},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition-colors hover:bg-terminal-border/30 hover:text-terminal-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-terminal-text/35`,"aria-label":u?`Message copied`:`Copy message`,title:u?`Copied`:`Copy message`,children:u?(0,M.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,M.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}):(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,M.jsx)(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`}),(0,M.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})}),T&&(0,M.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a?.(e)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition-colors hover:bg-terminal-border/30 hover:text-terminal-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-terminal-text/35`,"aria-label":`Fork from this user message`,title:`Fork from this user message`,"data-testid":`pi-rendered-fork-message`,children:(0,M.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,M.jsx)(`circle`,{cx:`6`,cy:`6`,r:`3`}),(0,M.jsx)(`circle`,{cx:`18`,cy:`18`,r:`3`}),(0,M.jsx)(`path`,{d:`M8.2 8.2 15.8 15.8`}),(0,M.jsx)(`path`,{d:`M6 9v3a6 6 0 0 0 6 6h3`})]})})]}),me&&(0,M.jsxs)(`div`,{className:`mt-2 flex items-center gap-1 transition-opacity duration-150 ${t?`opacity-60`:`opacity-0 group-hover/message:opacity-60 focus-within:opacity-100`}`,"data-testid":`pi-rendered-assistant-actions`,"data-actions-visible":t?`latest`:`hover`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),k()},className:`inline-flex h-8 w-8 items-center justify-center rounded-md text-terminal-muted transition-colors hover:bg-terminal-border/30 hover:text-terminal-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-terminal-text/35`,"aria-label":u?`Message copied`:`Copy message`,title:u?`Copied`:`Copy message`,children:u?(0,M.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,M.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}):(0,M.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,M.jsx)(`rect`,{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`}),(0,M.jsx)(`path`,{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`})]})}),T&&(0,M.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a?.(e)},className:`inline-flex h-8 w-8 items-center justify-center rounded-md text-terminal-muted transition-colors hover:bg-terminal-border/30 hover:text-terminal-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-terminal-text/35`,"aria-label":`Start new thread from this reply`,title:`Start new thread`,"data-testid":`pi-rendered-start-thread`,children:(0,M.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,M.jsx)(`path`,{d:`M16 3h5v5`}),(0,M.jsx)(`path`,{d:`M4 20 21 3`}),(0,M.jsx)(`path`,{d:`M21 16v5h-5`}),(0,M.jsx)(`path`,{d:`m15 15 6 6`}),(0,M.jsx)(`path`,{d:`M4 4l5 5`})]})}),(0,M.jsx)(`time`,{className:`ml-1 text-[13px] leading-none text-terminal-muted`,dateTime:e.timestamp,title:new Date(e.timestamp).toLocaleString(),children:new Date(e.timestamp).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})})]}),!c&&b.length>0?(0,M.jsx)(`div`,{className:`mt-3`,"data-testid":`pi-rendered-inline-proof-images`,children:(0,M.jsx)(F,{attachments:b,variant:`proof`})}):null,!c&&r.length>0&&(0,M.jsx)(Pi,{agents:r,onOpen:i})]})},(e,t)=>e.isLatest===t.isLatest&&e.assistantActionsEnabled===t.assistantActionsEnabled&&e.onOpenHandoffAgent===t.onOpenHandoffAgent&&e.onOpenFileAsArtifact===t.onOpenFileAsArtifact&&e.cwd===t.cwd&&vi(e.message,t.message)&&Kt(e.handoffAgents,t.handoffAgents));function Ni(e){return e.awaiting_approval?{label:`waiting on you`,dot:`bg-blue-400 animate-pulse`,text:`text-blue-300`}:e.status===`active`?{label:`active`,dot:`bg-terminal-green animate-pulse`,text:`text-terminal-green`}:e.task_status===`done`?{label:`done`,dot:`bg-terminal-green`,text:`text-terminal-green`}:e.task_status===`in_review`?{label:`in review`,dot:`bg-blue-400`,text:`text-blue-300`}:e.status===`completed`?{label:`idle`,dot:`bg-terminal-muted/60`,text:`text-terminal-muted`}:{label:e.task_status?.replace(/_/g,` `)||`connected`,dot:`bg-terminal-cyan`,text:`text-terminal-cyan`}}var Pi=N.memo(function({agents:e,onOpen:t}){return(0,M.jsxs)(`div`,{className:`mt-3 space-y-2`,"data-testid":`pi-rendered-handoff-agents`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 font-mono text-[10px] font-bold uppercase tracking-[0.16em] text-terminal-purple/80`,children:[(0,M.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-terminal-purple shadow-[0_0_8px_rgba(168,85,247,0.5)]`,"aria-hidden":`true`}),(0,M.jsxs)(`span`,{children:[`Connected child agent`,e.length>1?`s`:``]})]}),e.map(e=>{let n=Ni(e),r=e.awaiting_approval_question||e.recommended_next_step||e.lastActivitySummary||`${e.messageCount??0} messages`;return(0,M.jsxs)(`button`,{type:`button`,onClick:n=>{n.preventDefault(),n.stopPropagation(),t?.(e)},className:`group/handoff flex w-full items-start gap-3 rounded-xl border border-terminal-purple/25 bg-terminal-purple/[0.055] px-3 py-2.5 text-left shadow-sm shadow-black/10 transition-[color,background-color,border-color,box-shadow,opacity,transform] hover:border-terminal-purple/55 hover:bg-terminal-purple/[0.11] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-terminal-purple/60`,title:`Open child agent session`,"data-testid":`pi-rendered-handoff-agent-card`,"data-session-id":e.id,children:[(0,M.jsx)(`span`,{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${n.dot}`,"aria-hidden":`true`}),(0,M.jsxs)(`span`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,M.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,M.jsx)(`span`,{className:`truncate text-[12px] font-semibold text-terminal-text/90`,children:e.title}),(0,M.jsx)(`span`,{className:`shrink-0 rounded-full border border-current/20 px-1.5 py-0.5 font-mono text-[8px] font-bold uppercase tracking-[0.12em] ${n.text}`,children:n.label})]}),r&&(0,M.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-terminal-muted/75`,children:r}),(0,M.jsxs)(`span`,{className:`block truncate font-mono text-[9px] text-terminal-muted/45`,children:[_(e.lastActivity),` · `,e.cwd]})]}),(0,M.jsx)(`span`,{className:`mt-0.5 shrink-0 rounded-md border border-terminal-purple/25 px-2 py-1 font-mono text-[9px] font-bold uppercase tracking-[0.12em] text-terminal-purple/80 transition-colors group-hover/handoff:bg-terminal-purple/15`,children:`Open ↗`})]},e.id)})]})},(e,t)=>e.onOpen===t.onOpen&&Kt(e.agents,t.agents));export{pe as $,yt as A,Ie as B,Wt as C,jt as D,tn as E,Ue as F,le as G,ie as H,Re as I,oe as J,se as K,ze as L,Ye as M,qe as N,Z as O,Je as P,ue as Q,Be as R,Gt as S,rn as T,ce as U,we as V,S as W,ae as X,C as Y,x as Z,mi as _,wi as a,Ar as b,Ei as c,di as d,ei as f,pi as g,ii as h,ji as i,st as j,J as k,Di as l,ti as m,Ai as n,Ti as o,ri as p,w as q,ki as r,Oi as s,Mi as t,fi as u,Zr as v,Hn as w,Bn as x,Qr as y,Le as z};