remote-codex 0.11.28 → 0.11.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -682,14 +682,12 @@ import{l as $,R as Di,I as Bi,C as Gi,S as As,H as Fi,T as Hi,a as Oi,b as Ui,c
682
682
  color: var(--theme-fg-muted);
683
683
  }
684
684
  .thread-ui-shell .thread-graph-history-button,
685
- .thread-ui-shell .thread-graph-turn-index,
686
- .thread-ui-shell .thread-graph-turn-collapse {
685
+ .thread-ui-shell .thread-graph-turn-index {
687
686
  border-color: var(--theme-border);
688
687
  background: var(--theme-panel);
689
688
  color: var(--theme-fg-muted);
690
689
  }
691
- .thread-ui-shell .thread-graph-history-button:hover,
692
- .thread-ui-shell .thread-graph-turn-collapse:hover {
690
+ .thread-ui-shell .thread-graph-history-button:hover {
693
691
  background: var(--theme-hover);
694
692
  color: var(--theme-fg);
695
693
  }
@@ -3658,14 +3656,14 @@ args = ["-y", "your-mcp-server"]
3658
3656
  `,as="MCP entry written to provider config. Restart the backend if it does not appear immediately.";function Cm({hostConfigFilesAvailable:e,onReadProviderConfig:r,onWriteProviderConfig:n,setMcpPanelMode:a,onOpenMcp:o}){const[s,l]=c.useState(""),[i,d]=c.useState(""),[h,u]=c.useState(""),[m,f]=c.useState(null),[p,g]=c.useState(!1),[b,w]=c.useState(null),[x,j]=c.useState(null),k=c.useCallback(()=>{w(null),j(null)},[]),y=c.useCallback(async()=>{if(!e||!r)throw new Error("Provider config editing is unavailable for this thread.");const z=await r();return f(z.path),z},[e,r]),v=c.useCallback(async z=>{if(!e||!n)throw new Error("Provider config editing is unavailable for this thread.");const V=await n(z);return f(V.path),V},[e,n]),N=c.useCallback(async()=>{const z=xu(s),V=i.trim();if(!z){w("MCP name must use only letters, numbers, underscore, or hyphen.");return}if(!/^https?:\/\//i.test(V)){w("HTTP MCP URL must start with http:// or https://");return}g(!0),w(null),j(null);try{const F=await y(),B=Za(F.content,z,vu(z,V));await v(B),j(as),a("list"),l(""),d(""),o==null||o()}catch(F){w(F instanceof Error?F.message:"Unable to update provider config.")}finally{g(!1)}},[y,s,i,o,a,v]),S=c.useCallback(async()=>{g(!0),w(null),j(null);try{await y(),u(z=>z||Nm),a("stdio")}catch(z){w(z instanceof Error?z.message:"Unable to load provider config.")}finally{g(!1)}},[y,a]),L=c.useCallback(async()=>{const z=bu(h);if(!z){w("The raw MCP block must start with a header like [mcp_servers.name].");return}g(!0),w(null),j(null);try{const V=await y(),F=Za(V.content,z,h);await v(F),j(as),a("list"),o==null||o()}catch(V){w(V instanceof Error?V.message:"Unable to update provider config.")}finally{g(!1)}},[y,h,o,a,v]);return{mcpHttpName:s,mcpHttpUrl:i,mcpRawBlock:h,mcpConfigPath:m,mcpConfigBusy:p,mcpConfigError:b,mcpConfigSuccess:x,setMcpHttpName:l,setMcpHttpUrl:d,setMcpRawBlock:u,clearMcpConfigStatus:k,prepareRawMcpBlock:S,saveHttpMcp:N,saveRawMcpBlock:L}}function Sm({openMenu:e,setOpenMenu:r,slashPanelView:n,setSlashPanelView:a,setMcpPanelMode:o,clearMcpConfigStatus:s,clearHookConfigStatus:l}){const[i,d]=c.useState(null);c.useEffect(()=>{e!=="slash"&&(a("root"),o("list"),s(),l())},[l,s,e,o,a]),c.useEffect(()=>{n!=="mcp"&&(o("list"),s())},[s,o,n]),c.useEffect(()=>{if(!i)return;const u=window.setTimeout(()=>{d(m=>m===i?null:m)},1400);return()=>{window.clearTimeout(u)}},[i]),c.useEffect(()=>{function u(m){(typeof m.composedPath=="function"?m.composedPath():[]).some(g=>g instanceof HTMLElement&&(g.dataset.composerMenuSurface==="true"||g.dataset.composerMenuTrigger==="true"))||e&&r(null)}if(e)return window.addEventListener("pointerdown",u),()=>{window.removeEventListener("pointerdown",u)}},[e,r]);const h=c.useCallback(async u=>{try{await navigator.clipboard.writeText(`$${u}`),d(u)}catch{d(null)}},[]);return{copiedSkillName:i,copySkillInvokeName:h}}function Tm(e,r){const{attachment:n}=e,a=document.createElement("span");if(a.dataset.segmentType="attachment",a.dataset.clientId=n.clientId,a.dataset.placeholder=n.placeholder,a.contentEditable="false",a.className="thread-composer-attachment-chip mx-[0.12rem] inline-flex max-w-full align-baseline",n.kind==="photo"){a.classList.add("thread-composer-attachment-chip-photo","rounded-[0.95rem]","border","border-sky-300/35","bg-sky-300/10","p-1","shadow-sm","shadow-stone-950/20");const l=r[n.clientId];if(l){const d=document.createElement("img");d.src=l,d.alt=n.originalName||"Pasted image",d.className="thread-composer-attachment-thumb h-[4.5rem] w-[6rem] rounded-[0.7rem] bg-stone-950 object-contain",d.draggable=!1,a.append(d)}else{const d=document.createElement("span");d.className="thread-composer-attachment-thumb inline-block h-[4.5rem] w-[6rem] rounded-[0.7rem] bg-stone-900/80",d.setAttribute("aria-hidden","true"),a.append(d)}const i=document.createElement("span");return i.className="thread-composer-attachment-caption ml-2 inline-flex max-w-[8rem] items-center text-[10px] font-medium tracking-[0.08em] text-sky-50",i.textContent=Qa(n),a.append(i),a}a.classList.add("items-center","gap-2","rounded-[0.95rem]","border","border-emerald-300/35","bg-emerald-300/10","px-2.5","py-2","text-[10px]","font-medium","tracking-[0.08em]","text-emerald-50","shadow-sm","shadow-stone-950/20");const o=document.createElement("span");o.className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-emerald-200/25 bg-emerald-300/12 text-[9px]",o.textContent="FILE";const s=document.createElement("span");return s.className="inline-flex max-w-[10rem] truncate",s.textContent=Qa(n),a.append(o,s),a}function Em(e,r){const n=document.createDocumentFragment();for(const a of e){if(a.type==="text"){n.append(document.createTextNode(a.text===" "?" ":a.text));continue}n.append(Tm(a,r))}return n}function Lm({promptRef:e,isShellView:r,prompt:n,promptSegments:a,attachmentPreviewUrls:o,previewSignature:s,editorSanitizeNonce:l,pendingSelectionRef:i,pendingInsertedAttachmentIdsRef:d,selectionSnapshotRef:h,renderedPreviewSignatureRef:u,renderedSanitizeNonceRef:m,serializeEditorPrompt:f,restoreSelection:p}){c.useLayoutEffect(()=>{const g=e.current;if(!g||r)return;const b=i.current,w=f()!==n||u.current!==s||m.current!==l;w&&(g.replaceChildren(Em(a,o)),u.current=s,m.current=l),b!==null?(g.focus(),Xu(g,d.current)||p(b),h.current=b):document.activeElement===g&&w&&p(h.current),i.current=null,d.current=[]},[o,l,r,s,n,e,a,d,i,u,m,p,h,f])}function Pm({tokenBudget:e,error:r,onTokenBudgetChange:n,onCancel:a}){return t.jsxs("div",{className:"thread-goal-compose-card relative z-20 mb-1.5 flex flex-wrap items-center gap-2 rounded-2xl border px-3 py-2 text-xs shadow-sm",children:[t.jsx("span",{className:"thread-goal-compose-label font-medium uppercase tracking-[0.16em]",children:"Goal"}),t.jsxs("label",{className:"thread-goal-compose-field flex items-center gap-2",children:[t.jsx("span",{children:"Max tokens (k)"}),t.jsx("input",{"aria-label":"Goal token budget",value:e,onChange:o=>n(o.target.value),inputMode:"numeric",placeholder:"Optional",className:"thread-goal-compose-input h-7 w-24 rounded-full border px-3 text-xs outline-none"})]}),r?t.jsx("span",{className:"thread-goal-compose-error min-w-0 flex-1",children:r}):null,t.jsx("button",{type:"button",onClick:a,className:"thread-goal-compose-cancel rounded-full border px-2.5 py-1 text-[11px] transition",children:"Cancel"})]})}function zm({promptRef:e,prompt:r,disabled:n,promptPlaceholder:a,canInterrupt:o,interruptLabel:s,composerPromptRegionClassName:l,graphChatInputClassName:i,onInterrupt:d,onInput:h,onPaste:u,onKeyDown:m,onKeyUp:f,onMouseUp:p,onBlur:g,onDragEnter:b,onDragOver:w,onDragLeave:x,onDrop:j}){return t.jsxs("div",{"data-slot":"input-group-control",className:`${l} relative w-full`,children:[t.jsxs("div",{className:i,children:[r.length===0&&t.jsx("span",{className:`pointer-events-none absolute left-3 top-3 truncate text-slate-500 sm:left-4 sm:top-4 dark:text-slate-400 ${o?"right-12":"right-3 sm:right-4"}`,children:a}),t.jsx("div",{ref:e,role:"textbox","aria-label":"Prompt","aria-multiline":"true",contentEditable:!n,suppressContentEditableWarning:!0,onInput:h,onPaste:u,onKeyDown:m,onKeyUp:f,onMouseUp:p,onBlur:g,onDragEnter:b,onDragOver:w,onDragLeave:x,onDrop:j,className:`relative z-[1] min-h-[4.25rem] whitespace-pre-wrap break-words pb-2 outline-none sm:min-h-[4.25rem] ${o?"pr-12":""} ${n?"cursor-not-allowed text-slate-500":""}`})]}),o?t.jsx(kt,{type:"button",variant:"ghost",size:"icon-xs","aria-label":s,title:s,onClick:k=>{k.preventDefault(),d==null||d()},className:"thread-graph-composer-stop-button ui-action-danger absolute right-2 top-2 z-30 h-8 w-8 rounded-full text-sm font-medium",children:t.jsx("span",{"aria-hidden":"true",className:"block h-2.5 w-2.5 rounded-[2px] bg-current"})}):null]})}function Im({prompt:e,promptPlaceholder:r,promptRegionClassName:n,promptInputClassName:a,interruptLabel:o,canInterrupt:s,sendButtonLabel:l,sendButtonClassName:i,sendDisabled:d,onPromptChange:h,onPromptKeyDown:u,onInterrupt:m}){return t.jsxs("div",{className:`${n} relative`,children:[t.jsx("textarea",{"aria-label":"Prompt",disabled:!1,value:e,onChange:f=>h(f.target.value),onKeyDown:u,rows:2,placeholder:r,className:`${a} resize-y pb-10`}),t.jsx("button",{type:"button","aria-label":o,title:o,onClick:()=>void(m==null?void 0:m()),disabled:!s,className:`absolute right-2.5 top-2.5 inline-flex h-8 w-8 items-center justify-center rounded-full border transition ${s?"border-rose-300/55 bg-rose-300/[0.14] text-rose-50 shadow-lg shadow-rose-950/20 hover:bg-rose-300/[0.22]":"cursor-not-allowed border-stone-700/30 bg-stone-400/[0.02] text-stone-500/55 opacity-55"}`,children:t.jsx("span",{"aria-hidden":"true",className:"block h-2.5 w-2.5 rounded-[2px] bg-current"})}),t.jsx("button",{type:"submit","aria-label":"Send Shell Input",onMouseDown:f=>{f.preventDefault()},onPointerDown:f=>{f.preventDefault()},onTouchStart:f=>{f.preventDefault()},disabled:d,className:`absolute bottom-2.5 right-2.5 rounded-full px-3.5 py-1.5 text-sm font-medium shadow-lg shadow-stone-950/30 transition disabled:cursor-not-allowed disabled:bg-stone-700 disabled:text-stone-300 ${i}`,children:l})]})}function Rm({isShellView:e,promptRef:r,prompt:n,disabled:a,promptPlaceholder:o,canInterrupt:s,interruptLabel:l,composerPromptRegionClassName:i,graphChatInputClassName:d,promptInputClassName:h,goalComposeMode:u,goalTokenBudget:m,goalLocalError:f,goalBusy:p,busy:g,sendButtonLabel:b,sendButtonClassName:w,onInterrupt:x,onPromptInput:j,onPromptPaste:k,onPromptKeyDown:y,onPromptKeyUp:v,onPromptMouseUp:N,onPromptBlur:S,onPromptDragEnter:L,onPromptDragOver:z,onPromptDragLeave:V,onPromptDrop:F,onGoalTokenBudgetChange:B,onCancelGoal:J,onShellPromptChange:Z}){return{promptSlot:e?null:t.jsx(zm,{promptRef:r,prompt:n,disabled:a,promptPlaceholder:o,canInterrupt:s,interruptLabel:l,composerPromptRegionClassName:i,graphChatInputClassName:d,onInterrupt:x,onInput:j,onPaste:k,onKeyDown:y,onKeyUp:v,onMouseUp:N,onBlur:S,onDragEnter:L,onDragOver:z,onDragLeave:V,onDrop:F}),goalSlot:u&&!e?t.jsx(Pm,{tokenBudget:m,error:f,onTokenBudgetChange:B,onCancel:J}):null,shellPromptSlot:e?t.jsx(Im,{prompt:n,promptPlaceholder:o,promptRegionClassName:i,promptInputClassName:h,interruptLabel:l,canInterrupt:s,sendButtonLabel:b,sendButtonClassName:w,sendDisabled:p||g,onPromptChange:Z,onPromptKeyDown:y,onInterrupt:x}):null}}function Am({collaborationMode:e,onUpdateSettings:r,closeMenu:n}){const[a,o]=c.useState(null),s=a??e;c.useEffect(()=>{o(null)},[e]);const l=c.useCallback(async i=>{const d=pu({nextMode:i.collaborationMode,previousOptimisticMode:a});d.optimisticMode&&o(d.optimisticMode);try{await(r==null?void 0:r(i)),d.closeMenuOnSuccess&&n()}catch(h){throw d.shouldRollbackMode&&o(d.rollbackMode),h}},[n,r,a]);return{displayedCollaborationMode:s,updateSettings:l}}function _m({isShellView:e,canToggleShellView:r,isMobileShell:n,shellPromptLabel:a,openMenu:o,toolbarClassName:s,iconButtonClassName:l,menuClassName:i,menuItemClassName:d,panelButtonClassName:h,chipButtonClassName:u,inlineToggleClassName:m,planToggleActiveClassName:f,sendButtonBaseClassName:p,slashPanelView:g,availableToolboxItems:b,busy:w,settingsBusy:x,compactBusy:j,forkBusy:k,fastMode:y,goalComposeMode:v,goalBusy:N,goalStatus:S,activeView:L,disabled:z,model:V,modelOptions:F,modelContextTitle:B,contextUsage:J,reasoningEffort:Z,supportedEfforts:D,displayedCollaborationMode:ee,sandboxMode:oe,sendButtonLabel:A,sendButtonClassName:Q,modelControlsDisabled:R,effortControlsDisabled:q,effortControlTitle:O,forkTurnOptionsState:T,skillsState:U,copiedSkillName:H,hooksPanelMode:C,hooksState:E,hookConfigBusy:X,hookConfigError:Y,hookConfigSuccess:ie,editingHookTarget:K,hookScope:le,hookEventName:te,hookMatcher:ge,hookCommand:de,hookTimeoutSec:be,hookStatusMessage:ze,mcpPanelMode:se,mcpState:ye,mcpConfigPath:je,mcpConfigError:G,mcpConfigSuccess:me,mcpConfigBusy:fe,mcpHttpName:we,mcpHttpUrl:Me,mcpRawBlock:Ae,capabilities:Le,shellControlState:$e,onToggleView:_,onDismissPromptFocus:ue,onSetOpenMenu:ve,onToolboxItemClick:P,onSetSlashPanelView:M,onOpenForkTurns:ne,onForkLatest:ke,onForkTurn:Ne,onCopySkillInvokeName:Ce,onResetHookForm:_e,onSetHooksPanelMode:De,onClearHookConfigStatus:Ue,onSetEditingHookTarget:ot,onSetHookScope:et,onSetHookEventName:ut,onSetHookMatcher:at,onSetHookCommand:We,onSetHookTimeoutSec:Ge,onSetHookStatusMessage:Ve,onSaveHook:tt,onStartEditingHook:I,onTrustHook:W,onUntrustHook:pe,onSetMcpPanelMode:Pe,onClearMcpConfigStatus:re,onSetMcpHttpName:Fe,onSetMcpHttpUrl:Oe,onSetMcpRawBlock:He,onPrepareRawMcpBlock:Xe,onSaveHttpMcp:dt,onSaveRawMcpBlock:xt,onPickPhoto:lt,onPickFile:wt,onUpdateSettings:yt,onPasteShell:jt,onCopyShell:xe,onClearShell:Ie,onShellControl:rt}){const Ze=e?null:{open:o==="slash",slashPanelView:g,availableToolboxItems:b,busy:w,forkBusy:k,forkTurnOptionsState:T,skillsState:U,copiedSkillName:H,hooksPanelMode:C,hooksState:E,hostConfigFilesAvailable:Le.hostConfigFiles,hookTrustAvailable:Le.hookTrust,hookConfigBusy:X,hookConfigError:Y,hookConfigSuccess:ie,editingHookTarget:K,hookScope:le,hookEventName:te,hookMatcher:ge,hookCommand:de,hookTimeoutSec:be,hookStatusMessage:ze,mcpPanelMode:se,mcpState:ye,mcpConfigEditing:Le.mcpConfigEditing,mcpConfigPath:je,mcpConfigError:G,mcpConfigSuccess:me,mcpConfigBusy:fe,mcpHttpName:we,mcpHttpUrl:Me,mcpRawBlock:Ae,iconButtonClassName:l,menuClassName:i,menuItemClassName:d,panelButtonClassName:h,chipButtonClassName:u,onToggle:()=>ve(ct=>ct==="slash"?null:"slash"),onToolboxItemClick:P,toolboxItemDisabled:ct=>Ou(ct,{settingsBusy:x,compactBusy:j,busy:w,forkBusy:k}),toolboxItemClassName:ct=>Uu(ct,{fastMode:y,goalComposeMode:v,goalStatus:S,menuItemClassName:d}),toolboxItemStatus:ct=>Hu(ct,{fastMode:y,compactBusy:j,goalComposeMode:v,goalStatus:S,busy:w}),onSetSlashPanelView:M,onOpenForkTurns:ne,onForkLatest:ke,onForkTurn:Ne,onCopySkillInvokeName:Ce,onResetHookForm:_e,onSetHooksPanelMode:De,onClearHookConfigStatus:Ue,onSetEditingHookTarget:ot,onSetHookScope:et,onSetHookEventName:ut,onSetHookMatcher:at,onSetHookCommand:We,onSetHookTimeoutSec:Ge,onSetHookStatusMessage:Ve,onSaveHook:tt,onStartEditingHook:I,onTrustHook:W,onUntrustHook:pe,onSetMcpPanelMode:Pe,onClearMcpConfigStatus:re,onSetMcpHttpName:Fe,onSetMcpHttpUrl:Oe,onSetMcpRawBlock:He,onPrepareRawMcpBlock:Xe,onSaveHttpMcp:dt,onSaveRawMcpBlock:xt},Ut=e?null:{open:o==="attachments",iconButtonClassName:l,menuClassName:i,menuItemClassName:d,onToggle:()=>ve(ct=>ct==="attachments"?null:"attachments"),onPickPhoto:lt,onPickFile:wt},Wt=e?null:{openMenu:o,model:V,modelOptions:F,modelContextTitle:B,contextUsage:J,reasoningEffort:Z,supportedEfforts:D,displayedCollaborationMode:ee,sandboxMode:oe,planModeAvailable:Le.planMode,sandboxModeAvailable:Le.sandboxMode,settingsBusy:x,goalComposeMode:v,goalBusy:N,activeView:L,disabled:z,fastMode:y,sendButtonLabel:A,sendButtonClassName:Q,modelControlsDisabled:R,effortControlsDisabled:q,effortControlTitle:O,inlineToggleClassName:m,menuItemClassName:d,planToggleActiveClassName:f,sendButtonBaseClassName:p,onSetOpenMenu:ve,onUpdateSettings:yt};return{isShellView:e,canToggleShellView:r,isMobileShell:n,shellPromptLabel:a,openMenu:o,toolbarClassName:s,iconButtonClassName:l,slashToolboxProps:Ze,attachmentMenuProps:Ut,settingsToolbarProps:Wt,shellToolsPanelProps:o==="shellTools"?{busy:w,shellControlState:$e,onPaste:jt,onCopy:xe,onClear:Ie,onShellControl:rt}:null,shellControlState:$e,onToggleView:_,onDismissPromptFocus:ue,onSetOpenMenu:ve}}function Dn({activeView:e,edgeToEdgeMobile:r=!1,busy:n=!1,settingsBusy:a=!1,compactBusy:o=!1,error:s,model:l=null,reasoningEffort:i=null,fastMode:d=!1,collaborationMode:h="default",sandboxMode:u=null,hideSandboxModeControl:m=!1,modelOptions:f=[],contextUsage:p=null,capabilities:g=null,toolboxItems:b=null,hookCommandTemplates:w=null,mcpConfigFormat:x="none",followTail:j=!1,threadConnected:k=!0,shellAvailable:y=!0,disabled:v=!1,disabledPlaceholder:N,shellControlState:S=null,draftPrompt:L,draftAttachments:z,onPickAttachment:V,skillsState:F={status:"idle",data:null,error:null},mcpState:B={status:"idle",data:null,error:null},hooksState:J={status:"idle",data:null,error:null},goalState:Z={status:"idle",data:null,error:null},forkTurnOptionsState:D={status:"idle",data:null,error:null},onDraftChange:ee,onSubmit:oe,onInterrupt:A,onCompact:Q,onOpenSkills:R,onOpenMcp:q,onOpenHooks:O,onCreateHook:T,onUpdateHook:U,onTrustHook:H,onUntrustHook:C,onOpenGoal:E,onUpdateGoal:X,onOpenForkTurns:Y,onForkLatest:ie,onForkTurn:K,onReadProviderConfig:le,onWriteProviderConfig:te,onToggleFollow:ge,onUpdateSettings:de,onToggleView:be,onShellCopy:ze,onShellControl:se,canInterrupt:ye=!1}){var ba;const[je,G]=c.useState(null),[me,fe]=c.useState("root"),[we,Me]=c.useState("list"),Ae=c.useMemo(()=>({fast:(g==null?void 0:g.controls.performanceMode)??!1,compact:(g==null?void 0:g.turns.compact)??!1,goal:(g==null?void 0:g.controls.goals)??!1,fork:(g==null?void 0:g.branching.fork)??!1,skills:(g==null?void 0:g.management.skills)??!1,mcp:(g==null?void 0:g.management.mcpStatus)??!1,hooks:(g==null?void 0:g.management.hooks)??!1,hostConfigFiles:(g==null?void 0:g.management.hostConfigFiles)??!1,mcpConfigEditing:x==="codex-toml"&&!!(g!=null&&g.management.hostConfigFiles)&&!!le&&!!te,hookTrust:(g==null?void 0:g.management.hookTrust)??!1,planMode:(g==null?void 0:g.controls.planMode)??!1,sandboxMode:(g==null?void 0:g.controls.sandboxMode)??!1}),[g,x,le,te]),Le=c.useMemo(()=>Gu(b,Ae),[Ae,b]),$e=c.useRef(null),_=c.useRef(null),ue=c.useRef(null),ve=c.useRef(null),P=c.useRef(null),M=c.useRef([]),ne=c.useRef(null),ke=c.useRef(""),Ne=c.useRef(0),Ce=e==="shell",_e=y||Ce,De=!!(Ce&&(S!=null&&S.isMobileShell)),Ue=(S==null?void 0:S.promptLabel)??null,[ot,et]=c.useState(!1),[ut,at]=c.useState(0),{prompt:We,attachments:Ge,isDraftControlled:Ve,updateDraft:tt,flushControlledDraftToHost:I}=vm({isShellView:Ce,draftPrompt:L,draftAttachments:z,onDraftChange:ee}),W=xm({attachments:Ge,isShellView:Ce}),{displayedCollaborationMode:pe,updateSettings:Pe}=Am({collaborationMode:h,onUpdateSettings:de,closeMenu:()=>G(null)}),{forkBusy:re,forkLatest:Fe,forkTurn:Oe}=km({slashPanelView:me,onForkLatest:ie,onForkTurn:K,closeMenu:()=>G(null)}),{hooksPanelMode:He,hookScope:Xe,hookEventName:dt,hookMatcher:xt,hookCommand:lt,hookTimeoutSec:wt,hookStatusMessage:yt,editingHookTarget:jt,hookConfigBusy:xe,hookConfigError:Ie,hookConfigSuccess:rt,setHooksPanelMode:Ze,setEditingHookTarget:Ut,setHookScope:Wt,setHookEventName:ia,setHookMatcher:ct,setHookCommand:jl,setHookTimeoutSec:Nl,setHookStatusMessage:Cl,clearHookConfigStatus:da,resetHookForm:Sl,startEditingHook:Tl,saveHook:El,trustHook:Ll,untrustHook:Pl}=jm({slashPanelView:me,hookCommandTemplates:w,onCreateHook:T,onUpdateHook:U,onTrustHook:H,onUntrustHook:C}),{goalComposeMode:sr,goalTokenBudget:zl,goalBusy:tn,goalLocalError:Il,setGoalTokenBudget:Rl,submitGoal:Al,enterGoalComposeMode:_l,exitGoalComposeMode:ca}=wm({prompt:We,goalTokenBudgetSource:Z.data,promptRef:_,onOpenGoal:E,onUpdateGoal:X,updateDraft:tt,closeMenu:()=>G(null),resetSlashPanel:()=>fe("root")}),{mcpHttpName:Ml,mcpHttpUrl:$l,mcpRawBlock:Dl,mcpConfigPath:Bl,mcpConfigBusy:Gl,mcpConfigError:Fl,mcpConfigSuccess:Hl,setMcpHttpName:Ol,setMcpHttpUrl:Ul,setMcpRawBlock:Wl,clearMcpConfigStatus:ha,prepareRawMcpBlock:Vl,saveHttpMcp:Kl,saveRawMcpBlock:ql}=Cm({hostConfigFilesAvailable:Ae.hostConfigFiles,onReadProviderConfig:le,onWriteProviderConfig:te,setMcpPanelMode:Me,onOpenMcp:q}),{copiedSkillName:Xl,copySkillInvokeName:Yl}=Sm({openMenu:je,setOpenMenu:G,slashPanelView:me,setSlashPanelView:fe,setMcpPanelMode:Me,clearMcpConfigStatus:ha,clearHookConfigStatus:da}),Zl=c.useCallback(ae=>{tt(Se=>{if(typeof ae=="function"){const Re=ae(Se.prompt,Se.attachments);return{prompt:Re.prompt,attachments:Re.attachments??Se.attachments}}return{prompt:ae,attachments:Se.attachments}})},[tt]),rn=c.useMemo(()=>f.find(ae=>ae.model===l)??null,[l,f]),Jl=ku(l,p),ua=(rn==null?void 0:rn.supportedReasoningEfforts)??[],Ql=c.useMemo(()=>su(We,Ge),[Ge,We]),ei=c.useMemo(()=>Object.entries(W).sort(([ae],[Se])=>ae.localeCompare(Se)).map(([ae,Se])=>`${ae}:${Se}`).join("|"),[W]);function ti(ae,Se){Se.stopPropagation();const Re=Fu(ae,{fastMode:d,goalComposeMode:sr});switch(Re.type){case"toggleFast":Pe({fastMode:Re.fastMode});break;case"runCompact":G(null),Q==null||Q();break;case"enterGoalCompose":_l();break;case"exitGoalCompose":ca(),G(null);break;case"openPanel":fe(Re.panel),Re.panel==="skills"?R==null||R():Re.panel==="mcp"?q==null||q():Re.panel==="hooks"&&(O==null||O());break;case"insertPrompt":sn(Re.text),fe("root"),G(null);break}}function Vt(){const ae=_.current;return ae?Ku(ae):null}const ri=c.useCallback(ae=>{const Se=_.current;!Se||!ae||qu(Se,ae)},[]),nn=c.useCallback(()=>{const ae=_.current;return ae?Qo(ae):We},[We]),{appendAttachments:an,appendDroppedAttachments:ma}=gm({prompt:We,attachments:Ge,updateDraft:tt,getSelection:Vt,selectionSnapshotRef:ne,pendingSelectionRef:P,pendingInsertedAttachmentIdsRef:M,onInserted:()=>G(null)}),pa=c.useCallback((ae,Se)=>{var Re;if(zt(),V){V({kind:ae,appendAttachments:(Je,st=ae)=>an(Je,st),defaultPick:()=>{var Je;return(Je=Se.current)==null?void 0:Je.click()}});return}(Re=Se.current)==null||Re.click()},[an,zt,V]);function sn(ae){if(!ae)return;const Se=Vt()??ne.current,Re=(Se==null?void 0:Se.start)??We.length,Je=(Se==null?void 0:Se.end)??Re,st=au(ae),Kt=`${We.slice(0,Re)}${st}${We.slice(Je)}`;tt($i=>({prompt:Kt,attachments:$i.attachments}));const It=Re+st.length;P.current={start:It,end:It},ne.current={start:It,end:It}}Lm({promptRef:_,isShellView:Ce,prompt:We,promptSegments:Ql,attachmentPreviewUrls:W,previewSignature:ei,editorSanitizeNonce:ut,pendingSelectionRef:P,pendingInsertedAttachmentIdsRef:M,selectionSnapshotRef:ne,renderedPreviewSignatureRef:ke,renderedSanitizeNonceRef:Ne,serializeEditorPrompt:nn,restoreSelection:ri});function zt(){var ae;(ae=_.current)==null||ae.blur(),document.activeElement instanceof HTMLElement&&document.activeElement!==document.body&&document.activeElement.blur()}async function ni(){var ae;if(zt(),G(null),!!((ae=navigator.clipboard)!=null&&ae.readText))try{const Se=await navigator.clipboard.readText();sn(Se)}catch{return}}async function fa(){if(Ve&&I(),sr&&!Ce){await Al();return}const ae=cu({prompt:We,attachments:Ge,isShellView:Ce});!ae||await oe(ae)===!1||tt(()=>({prompt:"",attachments:[]}))}async function ai(ae){ae.preventDefault(),await fa()}function si(){const ae=nn(),Se=Vt();ne.current=Se;const Re=_.current;(Re?Vu(Re):!1)&&(P.current=Se,at(st=>st+1)),tt(st=>({prompt:ae,attachments:st.attachments.filter(Kt=>ae.includes(Kt.placeholder))}),"deferred")}function oi(ae){var Je,st,Kt,It;const Se=Mn((Je=ae.clipboardData)==null?void 0:Je.items,(st=ae.clipboardData)==null?void 0:st.files),Re=hu({files:Se,plainText:((Kt=ae.clipboardData)==null?void 0:Kt.getData("text/plain"))??"",htmlText:((It=ae.clipboardData)==null?void 0:It.getData("text/html"))??"",htmlToText:Wu});Re.preventDefault&&ae.preventDefault(),Re.type==="insert-text"?sn(Re.text):Re.type==="append-files"&&ma(Re.files)}function li(ae){var Re,Je;const Se=Xa(Ja((Re=ae.dataTransfer)==null?void 0:Re.items,(Je=ae.dataTransfer)==null?void 0:Je.files));Se.preventDefault&&ae.preventDefault(),Se.activateDragTarget&&et(!0)}function ii(ae){var Re,Je;const Se=Xa(Ja((Re=ae.dataTransfer)==null?void 0:Re.items,(Je=ae.dataTransfer)==null?void 0:Je.files));Se.preventDefault&&ae.preventDefault(),Se.activateDragTarget&&ae.dataTransfer&&(ae.dataTransfer.dropEffect="copy"),Se.activateDragTarget&&et(!0)}function di(ae){ae.currentTarget.contains(ae.relatedTarget)||et(!1)}function ci(ae){var Je,st;const Se=Mn((Je=ae.dataTransfer)==null?void 0:Je.items,(st=ae.dataTransfer)==null?void 0:st.files),Re=uu(Se);Re.preventDefault&&ae.preventDefault(),Re.type==="accept-files"&&(et(!1),ma(Re.files??[]))}function hi(ae){if(e==="chat"&&ae.key==="/"&&!ae.metaKey&&!ae.ctrlKey&&!ae.altKey&&!n&&!v&&Le.length>0&&nn().trim().length===0){ae.preventDefault(),fe("root"),G("slash");return}const Se=mu({key:ae.key,metaKey:ae.metaKey,ctrlKey:ae.ctrlKey,busy:n,disabled:v});Se.preventDefault&&ae.preventDefault(),Se.submit&&fa()}const{promptPlaceholder:ui,interruptLabel:mi,sendButtonLabel:ga,sendButtonClassName:xa,modelControlsDisabled:pi,effortControlsDisabled:fi,effortControlTitle:gi}=Nu({goalComposeMode:sr,goalBusy:tn,threadConnected:k,busy:n,isShellView:Ce,disabledPlaceholder:N,settingsBusy:a,supportedEffortCount:ua.length,fastMode:d}),{composerLayerClassName:xi,formClassName:bi,composerShellClassName:vi,composerToolbarClassName:ki,composerIconButtonClassName:wi,composerMenuClassName:yi,composerMenuItemClassName:ji,composerInlineToggleClassName:Ni,composerPanelButtonClassName:Ci,composerChipButtonClassName:Si,composerPlanToggleActiveClassName:Ti,composerSendButtonClassName:Ei,composerPromptRegionClassName:Li,promptInputClassName:Pi,graphChatInputGroupClassName:zi,graphChatInputClassName:Ii}=Cu({isShellView:Ce,edgeToEdgeMobile:r,isMobileShell:De,openMenu:je!==null,isDragTargetActive:ot,busy:n}),Ri=_m({isShellView:Ce,canToggleShellView:_e,isMobileShell:De,shellPromptLabel:Ue,openMenu:je,toolbarClassName:ki,iconButtonClassName:wi,menuClassName:yi,menuItemClassName:ji,panelButtonClassName:Ci,chipButtonClassName:Si,inlineToggleClassName:Ni,planToggleActiveClassName:Ti,sendButtonBaseClassName:Ei,slashPanelView:me,availableToolboxItems:Le,busy:n,settingsBusy:a,compactBusy:o,forkBusy:re,fastMode:d,goalComposeMode:sr,goalBusy:tn,goalStatus:(ba=Z.data)==null?void 0:ba.status,activeView:e,disabled:v,model:l,modelOptions:f,modelContextTitle:Jl,contextUsage:p,reasoningEffort:i,supportedEfforts:ua,displayedCollaborationMode:pe,sandboxMode:u,sendButtonLabel:ga,sendButtonClassName:xa,modelControlsDisabled:pi,effortControlsDisabled:fi,effortControlTitle:gi,forkTurnOptionsState:D,skillsState:F,copiedSkillName:Xl,hooksPanelMode:He,hooksState:J,hookConfigBusy:xe,hookConfigError:Ie,hookConfigSuccess:rt,editingHookTarget:jt,hookScope:Xe,hookEventName:dt,hookMatcher:xt,hookCommand:lt,hookTimeoutSec:wt,hookStatusMessage:yt,mcpPanelMode:we,mcpState:B,mcpConfigPath:Bl,mcpConfigError:Fl,mcpConfigSuccess:Hl,mcpConfigBusy:Gl,mcpHttpName:Ml,mcpHttpUrl:$l,mcpRawBlock:Dl,capabilities:{hostConfigFiles:Ae.hostConfigFiles,hookTrust:Ae.hookTrust,mcpConfigEditing:Ae.mcpConfigEditing,planMode:Ae.planMode,sandboxMode:m?!1:Ae.sandboxMode},shellControlState:S,onToggleView:be,onDismissPromptFocus:zt,onSetOpenMenu:G,onToolboxItemClick:ti,onSetSlashPanelView:fe,onOpenForkTurns:()=>Y==null?void 0:Y(),onForkLatest:Fe,onForkTurn:Oe,onCopySkillInvokeName:Yl,onResetHookForm:Sl,onSetHooksPanelMode:Ze,onClearHookConfigStatus:da,onSetEditingHookTarget:Ut,onSetHookScope:Wt,onSetHookEventName:ia,onSetHookMatcher:ct,onSetHookCommand:jl,onSetHookTimeoutSec:Nl,onSetHookStatusMessage:Cl,onSaveHook:El,onStartEditingHook:Tl,onTrustHook:Ll,onUntrustHook:Pl,onSetMcpPanelMode:Me,onClearMcpConfigStatus:ha,onSetMcpHttpName:Ol,onSetMcpHttpUrl:Ul,onSetMcpRawBlock:Wl,onPrepareRawMcpBlock:Vl,onSaveHttpMcp:Kl,onSaveRawMcpBlock:ql,onPickPhoto:()=>pa("photo",ue),onPickFile:()=>pa("file",ve),onUpdateSettings:ae=>void Pe(ae),onPasteShell:()=>void ni(),onCopyShell:()=>{zt(),G(null),ze==null||ze()},onClearShell:()=>{zt(),G(null),oe({prompt:"clear"})},onShellControl:ae=>{zt(),G(null),se==null||se(ae)}}),{promptSlot:Ai,goalSlot:_i,shellPromptSlot:Mi}=Rm({isShellView:Ce,promptRef:_,prompt:We,disabled:v,promptPlaceholder:ui,canInterrupt:ye,interruptLabel:mi,composerPromptRegionClassName:Li,graphChatInputClassName:Ii,promptInputClassName:Pi,goalComposeMode:sr,goalTokenBudget:zl,goalLocalError:Il,goalBusy:tn,busy:n,sendButtonLabel:ga,sendButtonClassName:xa,onInterrupt:A,onPromptInput:si,onPromptPaste:oi,onPromptKeyDown:hi,onPromptKeyUp:()=>{ne.current=Vt()},onPromptMouseUp:()=>{ne.current=Vt()},onPromptBlur:()=>{ne.current=Vt(),et(!1),Ve&&I()},onPromptDragEnter:li,onPromptDragOver:ii,onPromptDragLeave:di,onPromptDrop:ci,onGoalTokenBudgetChange:Rl,onCancelGoal:ca,onShellPromptChange:Zl});return t.jsx(nm,{activeView:e,layerClassName:xi,formClassName:bi,shellClassName:vi,inputGroupClassName:zi,error:s,followTail:j,photoInputRef:ue,fileInputRef:ve,onAppendAttachments:an,onToggleFollow:ge,onSubmit:ai,formRef:$e,promptSlot:Ai,toolbarSlot:t.jsx(mm,{...Ri}),goalSlot:_i,shellPromptSlot:Mi})}var Mm=c.createContext(null);function tl(){return c.useContext(Mm)}function ft(e){return e?new Date(e).toLocaleString([],{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit"}):"Time unavailable"}function Gt(e){return e?new Date(e).toLocaleString():"Time unavailable"}function $m(e){switch(e){case"idle":return"Idle";case"running":return"Running";case"interrupted":return"Interrupted";case"failed":return"Failed";case"not_loaded":return"Not Loaded";case"system_error":return"System Error"}}function Dm(e){switch(e){case"idle":return"ui-status-neutral";case"running":return"ui-status-info";case"interrupted":return"ui-status-warning";case"failed":case"system_error":return"ui-status-danger";case"not_loaded":return"ui-status-neutral"}}function rl(e){switch(e){case"sending":return"Sending";case"completed":return"Completed";case"interrupted":return"Interrupted";case"failed":return"Failed";case"inProgress":return"Running"}}function Bm({open:e,title:r,label:n,value:a,busy:o=!1,onChange:s,onCancel:l,onSubmit:i}){if(c.useEffect(()=>{if(!e)return;function h(u){u.key==="Escape"&&!o&&l()}return window.addEventListener("keydown",h),()=>{window.removeEventListener("keydown",h)}},[o,l,e]),!e)return null;function d(h){h.preventDefault(),i()}return Or.createPortal(t.jsxs("div",{className:"fixed inset-0 z-[95] flex items-center justify-center p-4 sm:p-6",children:[t.jsx("button",{type:"button","aria-label":"Close rename dialog",onClick:l,disabled:o,className:"absolute inset-0 bg-stone-950/78 backdrop-blur-sm disabled:cursor-not-allowed"}),t.jsxs("form",{role:"dialog","aria-modal":"true","aria-label":r,onSubmit:d,className:"relative z-[1] w-full max-w-md rounded-[1.6rem] border border-stone-700 bg-stone-900 p-5 shadow-2xl shadow-stone-950/40 sm:p-6",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"text-sm font-medium text-stone-100",children:r}),t.jsx("p",{className:"mt-1 text-sm text-stone-500",children:"Changes are saved only after confirmation."})]}),t.jsx("button",{type:"button","aria-label":"Close dialog",onClick:l,disabled:o,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-stone-700 text-stone-300 transition hover:bg-stone-800 disabled:cursor-not-allowed disabled:opacity-60",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-current",children:t.jsx("path",{d:"M3.22 2.47 8 7.25l4.78-4.78 1.06 1.06L9.06 8.31l4.78 4.78-1.06 1.06L8 9.37l-4.78 4.78-1.06-1.06 4.78-4.78-4.78-4.78 1.06-1.06Z"})})})]}),t.jsxs("div",{className:"mt-5",children:[t.jsx("label",{htmlFor:"rename-dialog-input",className:"text-sm font-medium text-stone-200",children:n}),t.jsx("input",{id:"rename-dialog-input","aria-label":n,autoFocus:!0,value:a,onChange:h=>s(h.target.value),className:"mt-2 w-full rounded-2xl border border-stone-700 bg-stone-950 px-4 py-3 text-stone-100 outline-none transition focus:border-amber-300"})]}),t.jsxs("div",{className:"mt-5 flex items-center justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:l,disabled:o,className:"rounded-full border border-stone-700 px-4 py-2 text-sm font-medium text-stone-300 transition hover:bg-stone-800 disabled:cursor-not-allowed disabled:opacity-60",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:o||!a.trim(),className:"ui-action-success rounded-full px-4 py-2 text-sm font-medium transition disabled:cursor-not-allowed",children:"Save"})]})]})]}),document.body)}function Gm({children:e,effectiveTheme:r,layoutMode:n,themeMode:a,viewportConstrained:o}){return t.jsx("div",{className:`thread-ui-shell ${r==="dark"?"thread-ui-theme-dark dark":""} ${o?"thread-ui-viewport-constrained":""} ${o?"h-[100svh] max-h-[100svh] min-h-0 overflow-hidden overscroll-none":"min-h-[100svh] overflow-hidden"} bg-[#f6f8fb] text-slate-900 transition-colors duration-200 sm:p-2`,"data-theme-effective":r,"data-theme-mode":a??r,"data-thread-layout":n,children:e})}function Fm({children:e,roomsRailCollapsed:r}){return t.jsx("div",{className:`thread-shell-frame relative h-full min-h-0 ${r?"is-rail-collapsed sm:grid-cols-[56px_minmax(0,1fr)]":"sm:grid-cols-[264px_minmax(0,1fr)]"}`,children:e})}function Hm({onClose:e,open:r}){return r?t.jsx("button",{type:"button","aria-hidden":"true",tabIndex:-1,className:"thread-mobile-only-block thread-mobile-scrim fixed inset-0 z-40 bg-slate-950/35 backdrop-blur-[1px]",onClick:e}):null}function Om({children:e,collapsed:r,mobileOpen:n}){return t.jsx("aside",{className:`thread-graph-rooms-surface thread-rooms-rail fixed inset-y-0 left-0 z-50 flex min-h-0 min-w-0 w-[min(20rem,calc(100vw-2rem))] flex-col overflow-x-hidden border-r border-slate-200/80 bg-white shadow-[0_20px_50px_rgba(15,23,42,0.18)] transition-transform duration-200 ease-out sm:static sm:z-auto sm:w-auto sm:translate-x-0 sm:rounded-[12px] sm:border sm:shadow-[0_10px_30px_rgba(15,23,42,0.04)] ${n?"translate-x-0":"pointer-events-none -translate-x-full sm:pointer-events-auto"} ${r?"thread-ui-rail-collapsed sm:items-center":""}`,style:{paddingTop:"var(--android-safe-area-top, 0px)"},children:e})}function Um({children:e}){return t.jsx("main",{className:"thread-shell-main h-full min-h-0 min-w-0 overflow-hidden",children:t.jsx("div",{className:"thread-main-panel thread-shell-card flex h-full min-h-0 flex-col overflow-hidden bg-white shadow-[0_10px_30px_rgba(15,23,42,0.04)] sm:rounded-[12px] sm:border sm:border-slate-200/80",children:e})})}function Wm({children:e}){return t.jsx("div",{className:"thread-topbar-surface flex shrink-0 flex-col border-b border-slate-200 bg-white pt-[env(safe-area-inset-top)] sm:pt-0",children:e})}function Vm({children:e}){return t.jsx("div",{className:"thread-split-region min-h-0 flex-1 overflow-hidden p-0 sm:p-2",children:e})}jo();Pt();function ss({...e}){return t.jsx(Oi,{"data-slot":"dialog",...e})}function os({...e}){return t.jsx(Ui,{"data-slot":"dialog-trigger",...e})}function Km({...e}){return t.jsx(Xi,{"data-slot":"dialog-portal",...e})}function qm({className:e,...r}){return t.jsx(Yi,{"data-slot":"dialog-overlay",className:nt("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...r})}function ls({children:e,className:r,showCloseButton:n=!0,...a}){return t.jsxs(Km,{"data-slot":"dialog-portal",children:[t.jsx(qm,{}),t.jsxs(Wi,{"data-slot":"dialog-content",className:nt("fixed left-[50%] top-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",r),...a,children:[e,n?t.jsxs(Vi,{"data-slot":"dialog-close",className:"absolute right-4 top-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx($.XIcon,{}),t.jsx("span",{className:"sr-only",children:"Close"})]}):null]})]})}function is({className:e,...r}){return t.jsx("div",{"data-slot":"dialog-header",className:nt("flex flex-col gap-2 text-center sm:text-left",e),...r})}function ds({className:e,...r}){return t.jsx(Ki,{"data-slot":"dialog-title",className:nt("text-lg font-semibold leading-none",e),...r})}function cs({className:e,...r}){return t.jsx(qi,{"data-slot":"dialog-description",className:nt("text-sm text-muted-foreground",e),...r})}var Xm=[{value:"system",label:"Follow system",icon:$.Monitor},{value:"dark",label:"Dark",icon:$.Moon},{value:"light",label:"Light",icon:$.Sun}];function Ym({thread:e,currentThreadId:r,currentWorkspaceId:n,workspaceLabels:a={},onOpenThread:o,getThreadHref:s,renderThreadLink:l,onBeginRenameThread:i,onDeleteThread:d,showDeleteButton:h=!1,showSessionCopyButton:u=!1,collapsed:m=!1}){const[f,p]=c.useState("idle"),g=c.useRef(null),b=a[e.workspaceId],w=b&&!n?b:null,x=r===e.id;c.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current)},[]);async function j(){const S=e.providerSessionId;if(S)try{await navigator.clipboard.writeText(S),p("copied"),g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>p("idle"),1200)}catch{p("failed"),g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>p("idle"),1600)}}const k=()=>o(e.id),y=`thread-graph-room-card group flex w-full items-center gap-3 rounded-xl border text-left transition ${x?"is-active":""} ${m?"justify-center px-2 py-2":"px-3 py-2.5"}`,v=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`thread-graph-room-card-icon flex h-8 w-8 shrink-0 items-center justify-center rounded-full ${x?"is-active":""}`,children:t.jsx($.MessageSquare,{className:"h-4 w-4"})}),t.jsxs("div",{className:`min-w-0 flex-1 ${m?"thread-desktop-collapsed-hidden":""}`,children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[t.jsx("p",{className:"thread-graph-room-card-title min-w-0 flex-1 truncate text-sm font-medium",title:e.title,children:e.title}),i&&!m?t.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),S.preventDefault(),i(e)},"aria-label":`Rename thread ${e.title}`,title:"Rename thread",className:"thread-card-quiet-button inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full transition",children:t.jsx($.Pencil,{className:"h-3 w-3"})}):null,u&&e.providerSessionId?t.jsx("button",{type:"button","aria-label":"Copy session ID",title:f==="copied"?"Copied":f==="failed"?"Copy failed":"Copy session ID",onClick:S=>{S.stopPropagation(),S.preventDefault(),j()},className:"thread-card-quiet-button thread-card-session-copy-button inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition",children:t.jsx($.Copy,{className:"h-3.5 w-3.5"})}):null]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2",children:[w?t.jsx("p",{className:"thread-graph-room-card-meta min-w-0 flex-1 truncate text-[11px] text-[var(--theme-fg-muted)]",title:w,children:w}):t.jsx("span",{className:"min-w-0 flex-1","aria-hidden":"true"}),t.jsx("span",{className:`shrink-0 rounded-full border px-1.5 py-0.5 text-[9px] uppercase tracking-normal ${Dm(e.status)}`,children:$m(e.status)}),t.jsx("time",{className:"shrink-0 text-[11px] text-[var(--theme-fg-muted)]",dateTime:e.lastTurnStartedAt??e.updatedAt,children:ft(e.lastTurnStartedAt??e.updatedAt)})]})]}),h&&d&&!m?t.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),S.preventDefault(),d(e)},"aria-label":`Delete thread ${e.title}`,className:"thread-card-danger-button shrink-0 rounded-full p-1 transition",title:"Delete thread",children:t.jsx($.Trash2,{className:"h-3.5 w-3.5"})}):null]}),N=s==null?void 0:s(e.id);return l?t.jsx(t.Fragment,{children:l({thread:e,children:v,className:y,onClick:k})}):N?t.jsx("a",{href:N,onClick:S=>{S.preventDefault(),k()},title:m?e.title:void 0,className:y,children:v}):t.jsx("div",{role:"link",tabIndex:0,onClick:k,onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),k())},title:m?e.title:void 0,className:y,children:v})}function Zm({threads:e,currentThreadId:r,currentWorkspaceId:n,workspaceLabels:a={},onOpenThread:o,getThreadHref:s,renderThreadLink:l,onBeginRenameThread:i,onDeleteThread:d,scrollable:h=!1,maxHeightClassName:u="max-h-full",showDeleteButton:m=!1,showSessionCopyButton:f=!1,collapsed:p=!1}){const g=h?`min-h-0 min-w-0 overflow-x-hidden overflow-y-auto overscroll-contain pr-1 ${u}`:"";return t.jsx("div",{className:g,children:t.jsx("div",{className:"min-w-0 space-y-1",children:e.map(b=>t.jsx(Ym,{thread:b,currentThreadId:r,currentWorkspaceId:n,workspaceLabels:a,onOpenThread:o,showDeleteButton:m,showSessionCopyButton:f,collapsed:p,...s?{getThreadHref:s}:{},...l?{renderThreadLink:l}:{},...i?{onBeginRenameThread:i}:{},...d?{onDeleteThread:d}:{}},b.id))})})}function Jm({threads:e,status:r,loading:n=!1,error:a,viewportConstrained:o=!1,layoutMode:s="responsive",effectiveTheme:l,themeMode:i,onThemeModeChange:d,showMobileNewThreadShortcut:h=!0,settingsDialogOpen:u,onSettingsDialogOpenChange:m,mobileHeaderAction:f,currentThreadId:p,currentThreadLabel:g=null,currentWorkspaceId:b=null,currentWorkspaceLabel:w=null,sessionLabel:x=null,usageLabel:j=null,threadActionsButton:k,topbarActions:y,metaContent:v,settingsContent:N,globalSettingsContent:S,workspaceLabels:L={},workspaceReturnHref:z,onWorkspaceReturn:V,getThreadHref:F,onOpenThread:B,getNewThreadHref:J,newThreadHref:Z,newThreadLabel:D="New Chat",onNewThread:ee,onNewThreadTitle:oe,renderNewThreadDialogContent:A,renderThreadLink:Q,onCloseAppNavigation:R,onRenameThread:q,onDeleteThread:O,workspaceContent:T,workspaceTitle:U="Workspace",workspaceActions:H,children:C}){const E=tl(),X=typeof window<"u"?window.matchMedia("(max-width: 639px)").matches:s==="mobile",[Y,ie]=c.useState(()=>typeof window<"u"?window.matchMedia("(prefers-color-scheme: dark)").matches:!1),K=i??(E==null?void 0:E.themeMode)??"system",le=l??(E==null?void 0:E.effectiveTheme)??(K==="system"?Y?"dark":"light":K),[te,ge]=c.useState(!1),[de,be]=c.useState(!1),[ze,se]=c.useState(!X),[ye,je]=c.useState(X),[G,me]=c.useState("chat"),[fe,we]=c.useState(null),[Me,Ae]=c.useState(""),[Le,$e]=c.useState(null),[_,ue]=c.useState(!1),[ve,P]=c.useState(""),[M,ne]=c.useState(!1),[ke,Ne]=c.useState(!1),[Ce,_e]=c.useState("session");c.useEffect(()=>{if(typeof window>"u")return;const xe=window.matchMedia("(max-width: 639px)"),Ie=()=>{je(xe.matches)};return Ie(),xe.addEventListener("change",Ie),()=>{xe.removeEventListener("change",Ie)}},[]),c.useEffect(()=>{if(typeof window>"u")return;const xe=window.matchMedia("(prefers-color-scheme: dark)"),Ie=()=>{ie(xe.matches)};return Ie(),xe.addEventListener("change",Ie),()=>{xe.removeEventListener("change",Ie)}},[]);const De=c.useMemo(()=>[...b?e.filter(Ie=>Ie.workspaceId===b):e].sort((Ie,rt)=>{if(Ie.id===p)return-1;if(rt.id===p)return 1;const Ze=Date.parse(Ie.lastTurnStartedAt??Ie.updatedAt);return Date.parse(rt.lastTurnStartedAt??rt.updatedAt)-Ze}),[p,b,e]),Ue=Z??(J==null?void 0:J(b)),ot=w??b??"all",et=x??g??p??"default_session",ut=j??(r!=null&&r.state?`runtime ${r.state}`:"waiting for agent usage"),at=d??(E==null?void 0:E.setThemeMode),We=!!at,Ge=()=>{ge(!1),R==null||R()};async function Ve(xe){if(!q)return;const Ie=Me.trim();if(Ie){$e(xe);try{await q(xe,Ie),we(null),Ae("")}finally{$e(null)}}}function tt(xe){we(xe.id),Ae(xe.title)}function I(){we(null),Ae("")}function W(xe){B==null||B(xe),Ge()}function pe(){ue(!1),P("")}function Pe(xe){if(!Ue||!xe.trim())return Ue;try{const Ie=new URL(Ue,window.location.origin);return Ie.searchParams.set("title",xe.trim()),`${Ie.pathname}${Ie.search}${Ie.hash}`}catch{const Ie=Ue.includes("?")?"&":"?";return`${Ue}${Ie}title=${encodeURIComponent(xe.trim())}`}}async function re(){const xe=ve.trim();ne(!0);try{if(xe&&oe){await oe(xe),P(""),ue(!1),Ge();return}if(Ue){window.location.assign(Pe(xe)??Ue);return}await(ee==null?void 0:ee()),P(""),ue(!1),Ge()}finally{ne(!1)}}function Fe(xe,Ie=!1){const rt=Ie?t.jsxs(t.Fragment,{children:[t.jsx($.Plus,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:D})]}):t.jsxs(t.Fragment,{children:[t.jsx($.Plus,{className:"h-4 w-4"}),t.jsx("span",{children:D})]});return t.jsxs(ss,{open:_,onOpenChange:Ze=>{M||ue(Ze)},children:[t.jsx(os,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":Ie?D:void 0,title:D,className:xe,children:rt})}),t.jsx(ls,{"data-testid":"create-thread-dialog","data-theme-effective":le,"data-theme-mode":K,className:"thread-graph-create-thread-dialog thread-graph-dialog max-h-[min(86vh,42rem)] overflow-hidden p-4 sm:max-w-[34rem]",children:A?A({close:pe,closeNavigation:Ge,currentWorkspaceId:b}):t.jsxs(t.Fragment,{children:[t.jsxs(is,{children:[t.jsx(ds,{children:"Create New Chat"}),t.jsx(cs,{children:"Name the room so it is easy to find later."})]}),t.jsxs("div",{className:"grid gap-3",children:[t.jsx("input",{id:"thread-graph-create-thread-title",name:"thread-title",value:ve,onChange:Ze=>P(Ze.target.value),onKeyDown:Ze=>{Ze.key==="Enter"&&(Ze.preventDefault(),re())},placeholder:"Chat name","aria-label":"Chat name",autoComplete:"off",className:"thread-graph-create-thread-input h-10 rounded-md border px-3 text-sm outline-none transition"}),t.jsx("button",{type:"button",onClick:()=>void re(),disabled:M,className:"thread-graph-create-thread-submit inline-flex h-10 items-center justify-center rounded-md px-4 text-sm font-medium transition disabled:cursor-not-allowed disabled:opacity-60",children:M?"Creating...":"Create"})]})]})})]})}function Oe(){if(!N&&!v&&!S&&!We)return null;const xe=!!(N||v),Ie=!!S,rt=Ce==="global"&&Ie||!xe&&Ie?"global":"session";return t.jsxs(ss,{...u!==void 0?{open:u}:{},...m?{onOpenChange:m}:{},children:[t.jsx(os,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":"Open settings",title:"Settings",className:"thread-icon-button inline-flex h-10 w-10 items-center justify-center rounded-full sm:h-9 sm:w-9",children:t.jsx($.Settings,{className:"h-4 w-4"})})}),t.jsxs(ls,{"data-testid":"settings-dialog","data-theme-effective":le,"data-theme-mode":K,className:"thread-graph-settings-dialog thread-graph-dialog",children:[t.jsxs(is,{children:[t.jsx(ds,{children:"Settings"}),t.jsx(cs,{children:"Manage this session and host-wide preferences."})]}),We?t.jsx("div",{className:"thread-graph-settings-card rounded-lg border p-3",children:t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-medium text-[var(--theme-fg)]",children:"Appearance"}),t.jsxs("p",{className:"mt-1 text-xs leading-5 text-[var(--theme-fg-muted)]",children:["Current theme: ",le]})]}),t.jsx("div",{className:"thread-graph-theme-mode-group grid grid-cols-3 gap-1 rounded-lg border p-1",role:"group","aria-label":"Theme mode",children:Xm.map(Ze=>{const Ut=Ze.icon,Wt=K===Ze.value;return t.jsxs("button",{type:"button","data-testid":`theme-mode-${Ze.value}`,"aria-pressed":Wt,disabled:!We,onClick:()=>at==null?void 0:at(Ze.value),className:`thread-graph-theme-mode-button inline-flex min-h-9 items-center justify-center gap-1.5 rounded-md px-2 text-xs font-medium transition ${Wt?"is-selected":""}`,children:[t.jsx(Ut,{className:"h-3.5 w-3.5"}),t.jsx("span",{className:"truncate",children:Ze.label})]},Ze.value)})})]})}):null,t.jsxs("div",{className:"thread-graph-settings-tabs grid grid-cols-2 gap-1 rounded-lg border p-1",children:[t.jsx("button",{type:"button","aria-pressed":rt==="session",onClick:()=>_e("session"),className:`thread-graph-settings-tab-button rounded-md px-3 py-2 text-sm font-medium transition ${rt==="session"?"is-active":""}`,children:"Session"}),t.jsx("button",{type:"button","aria-pressed":rt==="global",disabled:!Ie,onClick:()=>_e("global"),className:`thread-graph-settings-tab-button rounded-md px-3 py-2 text-sm font-medium transition ${rt==="global"?"is-active":""}`,children:"Global"})]}),t.jsx("div",{className:"thread-graph-settings-body mt-4 min-h-0 overflow-y-auto pr-1 text-sm",children:rt==="session"?t.jsxs("div",{className:"grid gap-4",children:[N?t.jsx("div",{className:"thread-graph-settings-card rounded-lg border p-3",children:N}):null,v?t.jsx("div",{className:"thread-graph-settings-card rounded-lg border p-3",children:v}):null,xe?null:t.jsx("div",{className:"thread-graph-settings-card rounded-lg border p-3 text-[var(--theme-fg-muted)]",children:"No session settings are available."})]}):t.jsx("div",{className:"thread-graph-settings-global-content",children:S})})]})]})}function He(xe=!1){return t.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:t.jsxs("section",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs("div",{className:`mb-3 flex items-center gap-2 px-2 text-xs font-medium tracking-normal text-[var(--theme-fg-muted)] ${xe?"justify-center":""}`,children:[t.jsx($.Rows3,{className:"h-3.5 w-3.5"}),t.jsx("span",{className:xe?"sr-only":"",children:"Rooms"}),!xe&&n?t.jsx("span",{className:"ml-auto text-xs text-[var(--theme-fg-muted)]",children:"Refreshing..."}):null]}),t.jsxs("div",{className:"min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto px-1",children:[a?t.jsx("div",{className:"rounded-xl border border-rose-500/30 bg-rose-500/10 px-3 py-3 text-sm text-rose-900 dark:text-rose-100",children:a}):null,!a&&De.length===0&&!n?t.jsx("div",{className:"rounded-xl border border-dashed border-[var(--theme-border)] bg-[var(--theme-surface)] px-4 py-6 text-sm text-[var(--theme-fg-muted)]",children:"No threads available in this view."}):null,De.length>0?t.jsx(Zm,{threads:De,currentThreadId:p,currentWorkspaceId:b,workspaceLabels:L,onOpenThread:W,collapsed:xe,...q?{onBeginRenameThread:tt}:{},showDeleteButton:!!O,...F?{getThreadHref:F}:{},...Q?{renderThreadLink:Q}:{},...O?{onDeleteThread:O}:{}}):null]})]})})}function Xe(){return T?t.jsxs("div",{className:"thread-workspace-panel relative flex h-full min-h-0 flex-col overflow-hidden rounded-[12px] border",children:[t.jsx("button",{type:"button",onClick:()=>se(!0),className:"thread-workspace-collapse-tab thread-desktop-only-inline-flex",title:"Collapse workspace","aria-label":"Collapse workspace",children:t.jsx($.ChevronsRight,{className:"h-4 w-4"})}),H?t.jsx("div",{className:"pointer-events-none absolute right-12 top-2 z-20 flex items-center gap-1",children:t.jsx("div",{className:"pointer-events-auto",children:H})}):null,t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:T})]}):t.jsxs("div",{className:"thread-workspace-panel flex h-full min-h-0 flex-col overflow-hidden rounded-[12px] border",children:[t.jsxs("div",{className:"thread-workspace-panel-header flex h-12 shrink-0 items-center justify-between gap-3 border-b border-[var(--theme-border)] px-3 sm:h-[60px] sm:px-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate text-base font-semibold text-[var(--theme-fg)] sm:text-[18px]",children:U}),t.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:w??b??"Current context"})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[H,t.jsx("button",{type:"button",onClick:()=>se(!0),className:"thread-workspace-small-toggle thread-desktop-only-inline-flex",title:"Collapse workspace","aria-label":"Collapse workspace",children:t.jsx($.ChevronsRight,{className:"h-4 w-4"})})]})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:T??t.jsxs("div",{className:"grid h-full min-h-0 gap-3 overflow-y-auto p-3 text-sm text-[var(--theme-fg-soft)]",children:[t.jsxs("div",{className:"thread-workspace-card rounded-lg border p-3",children:[t.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:"Runtime"}),t.jsx("p",{className:"mt-2 text-[var(--theme-fg)]",children:(r==null?void 0:r.state)??"unknown"})]}),t.jsxs("div",{className:"thread-workspace-card rounded-lg border p-3",children:[t.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.14em] text-[var(--theme-fg-muted)]",children:"Workspace"}),t.jsx("p",{className:"mt-2 break-words text-[var(--theme-fg)]",children:w??b??"All threads"})]})]})})]})}const dt=!!T,xt=s==="mobile"||s==="responsive"&&ye,lt=xt,wt=lt&&!te,jt=!!(z||V)?t.jsx("a",{href:z??"#",onClick:xe=>{V&&(xe.preventDefault(),V())},className:"thread-icon-button inline-flex h-10 w-10 items-center justify-center rounded-full sm:h-9 sm:w-9",title:"Back to workspace","aria-label":"Back to workspace",children:t.jsx($.ArrowLeft,{className:"h-4 w-4"})}):null;return t.jsxs(t.Fragment,{children:[t.jsx(Gm,{effectiveTheme:le,layoutMode:s,themeMode:K,viewportConstrained:o,children:t.jsxs(Fm,{roomsRailCollapsed:de,children:[t.jsx(Hm,{open:te,onClose:()=>ge(!1)}),t.jsxs(Om,{collapsed:de,mobileOpen:te,children:[t.jsx("div",{className:`thread-rooms-rail-header flex h-[calc(3.75rem+env(safe-area-inset-top))] shrink-0 items-end border-b border-[var(--theme-border)] px-4 pb-3 sm:h-16 sm:items-center sm:pb-0 ${de?"sm:w-full sm:justify-center sm:px-2":""}`,children:t.jsxs("div",{className:`flex w-full items-center gap-3 ${de?"sm:justify-center":"justify-between"}`,children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.jsx("button",{type:"button",onClick:()=>be(xe=>!xe),className:"thread-icon-button thread-desktop-only-flex h-9 w-9 shrink-0 items-center justify-center rounded-full",title:de?"Expand rooms":"Collapse rooms","aria-label":de?"Expand rooms":"Collapse rooms",children:de?t.jsx($.PanelLeftOpen,{className:"h-4 w-4"}):t.jsx($.PanelLeftClose,{className:"h-4 w-4"})}),t.jsx("div",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-[var(--theme-accent-solid)] text-sm font-semibold text-[var(--theme-accent-solid-fg)] ${de?"thread-desktop-collapsed-hidden":""}`,children:(w??"R").charAt(0).toUpperCase()}),t.jsxs("div",{className:`min-w-0 ${de?"thread-desktop-collapsed-hidden":""}`,children:[t.jsx("p",{className:"truncate text-sm font-semibold text-[var(--theme-fg)]",children:w??"Remote Codex"}),t.jsx("p",{className:"truncate text-xs text-[var(--theme-fg-muted)]",children:b??"Thread workspace"})]})]}),t.jsxs("div",{className:`flex shrink-0 items-center gap-1 ${de?"thread-desktop-collapsed-hidden":""}`,children:[Oe(),jt,t.jsx("button",{type:"button",onClick:()=>ge(!1),"aria-label":"Close rooms",title:"Close rooms",className:"thread-icon-button thread-mobile-only-inline-flex h-10 w-10 items-center justify-center rounded-full",children:t.jsx($.X,{className:"h-4 w-4"})})]})]})}),t.jsx("div",{className:`thread-graph-new-room-strip flex shrink-0 items-center border-b ${de?"h-12 w-full justify-center px-2 sm:h-12":"h-[68px] px-4"}`,children:Fe(`thread-graph-new-room-button inline-flex items-center justify-center rounded-xl font-medium transition ${de?"h-9 w-9 p-0":"h-11 w-full gap-2 px-3 text-sm sm:h-9"}`,de)}),t.jsx("div",{className:`flex min-h-0 flex-1 flex-col ${de?"w-full px-2 py-2":"px-3 py-3"}`,children:He(de)})]}),t.jsxs(Um,{children:[t.jsx(Wm,{children:t.jsx("div",{className:"thread-topbar-row flex min-h-12 items-center px-3 py-1.5 sm:min-h-12 sm:px-4",children:t.jsxs("div",{className:"flex w-full items-center justify-between gap-3 sm:gap-4",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:gap-3",children:[wt?t.jsx("button",{type:"button",onClick:()=>ge(!0),"aria-label":"Open rooms",title:"Open rooms",className:"thread-icon-button thread-mobile-only-inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full",children:t.jsx($.Menu,{className:"h-4 w-4"})}):null,t.jsxs("div",{className:"min-w-0",children:[lt?t.jsx("h1",{className:"thread-mobile-only-block min-w-0 truncate text-sm font-semibold leading-none text-[var(--theme-fg)]",children:g??"Shared Workspace"}):null,t.jsxs("div",{className:"relative flex min-w-0 items-center gap-1.5",children:[t.jsxs("button",{type:"button",onClick:()=>{Ne(xe=>!xe)},"aria-expanded":ke,"aria-haspopup":"dialog",className:"thread-topbar-meta-row flex min-w-0 max-w-full items-center gap-1 text-left text-[11px] leading-none sm:text-xs",title:"Session and usage",children:[t.jsx("span",{className:"shrink-0",children:"Room"}),t.jsx("span",{className:"truncate font-mono",children:ot})]}),ke?t.jsxs("div",{className:"thread-topbar-details-popover absolute left-0 top-[calc(100%+0.5rem)] z-50 w-[min(28rem,calc(100vw-1.5rem))] rounded-lg border p-2.5 shadow-lg",role:"dialog","aria-label":"Session and usage",children:[t.jsxs("button",{type:"button",onClick:()=>{var xe;et&&((xe=navigator.clipboard)==null||xe.writeText(et))},className:"thread-topbar-meta-row flex min-w-0 max-w-full items-center gap-2 text-left text-xs leading-5",title:"Copy session ID",children:[t.jsx("span",{className:"w-14 shrink-0",children:"Session"}),t.jsx("span",{className:"truncate font-mono",children:et})]}),t.jsxs("div",{className:"thread-topbar-meta-row mt-1 flex min-w-0 max-w-full items-center gap-2 text-xs leading-5",title:"Session token usage and estimated cost",children:[t.jsx("span",{className:"w-14 shrink-0",children:"Usage"}),t.jsx("span",{className:"truncate font-mono",children:ut})]})]}):null]})]})]}),t.jsxs("div",{className:"relative z-[1] inline-flex shrink-0 items-center gap-2",children:[k||y?t.jsxs("div",{className:"thread-graph-topbar-actions thread-desktop-only-inline-flex items-center rounded-lg border p-0.5 shadow-none",children:[k,y]}):null,lt&&k?t.jsx("div",{className:"thread-mobile-only-inline-flex",children:k}):null,lt&&dt?t.jsx("button",{type:"button",onClick:()=>me(xe=>xe==="workspace"?"chat":"workspace"),"aria-label":G==="workspace"?"Show chat":"Show workspace",title:G==="workspace"?"Show chat":"Show workspace",className:"thread-icon-button thread-mobile-only-inline-flex h-10 w-10 items-center justify-center rounded-full",children:G==="workspace"?t.jsx($.MessageSquare,{className:"h-4 w-4"}):t.jsx($.Folder,{className:"h-4 w-4"})}):null,lt?f:null,lt&&h?Fe("thread-secondary-action inline-flex h-10 items-center justify-center gap-2 rounded-lg border px-3 text-sm font-medium sm:h-9"):null]})]})})}),t.jsx(Vm,{children:dt&&!ze?xt?t.jsxs("div",{className:"thread-split-container thread-graph-shell-mobile-split h-full min-h-0 overflow-hidden",children:[t.jsx("div",{className:`h-full min-h-0 overflow-hidden ${G==="chat"?"block":"thread-mobile-chat-hidden"}`,children:C}),t.jsx("div",{className:`h-full min-h-0 overflow-hidden ${G==="workspace"?"block":"thread-mobile-workspace-hidden"}`,children:Xe()})]}):t.jsxs(Tn,{direction:"horizontal",className:"thread-split-container thread-graph-shell-resizable thread-graph-shell-desktop-split h-full min-h-0 overflow-hidden",children:[t.jsx(er,{defaultSize:47,minSize:30,maxSize:75,className:"thread-split-chat-pane min-w-0 overflow-hidden",children:C}),t.jsx(En,{className:"thread-resize-handle w-2 bg-transparent after:w-px after:bg-slate-200/80 after:transition-colors hover:after:bg-slate-300 dark:after:bg-[#303642] dark:hover:after:bg-[#475063]"}),t.jsx(er,{defaultSize:53,minSize:30,maxSize:70,className:"thread-split-workspace-pane min-w-0 overflow-hidden",children:Xe()})]}):t.jsxs("div",{className:"thread-split-container relative h-full min-h-0 overflow-hidden",children:[dt&&ze?t.jsx("button",{type:"button",onClick:()=>se(!1),className:"thread-workspace-expand-fab thread-desktop-only-inline-flex",title:"Expand workspace","aria-label":"Expand workspace",children:t.jsx($.ChevronsLeft,{className:"h-4 w-4"})}):null,C]})})]})]})}),t.jsx(Bm,{open:fe!==null,title:"Rename Thread",label:"Thread Title",value:Me,busy:Le!==null,onChange:Ae,onCancel:I,onSubmit:()=>fe?Ve(fe):void 0})]})}function Qm({open:e,title:r,text:n,onClose:a}){return c.useEffect(()=>{if(!e)return;function o(s){s.key==="Escape"&&a()}return window.addEventListener("keydown",o),()=>{window.removeEventListener("keydown",o)}},[a,e]),e?Or.createPortal(t.jsxs("div",{className:"fixed inset-0 z-[90] flex items-center justify-center p-4 sm:p-6",children:[t.jsx("button",{type:"button","aria-label":"Close full text",onClick:a,className:"absolute inset-0 bg-stone-950/78 backdrop-blur-sm"}),t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":r,className:"relative z-[1] flex max-h-[min(82vh,52rem)] w-full max-w-4xl flex-col overflow-hidden rounded-[1.8rem] border border-stone-700 bg-stone-900 shadow-2xl shadow-stone-950/40",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-stone-800 px-4 py-3 sm:px-5",children:[t.jsx("p",{className:"truncate text-sm font-medium text-stone-100",children:r}),t.jsx("button",{type:"button","aria-label":"Close dialog",onClick:a,className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-stone-700 text-stone-300 transition hover:bg-stone-800",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-4 w-4 fill-current",children:t.jsx("path",{d:"M3.22 2.47 8 7.25l4.78-4.78 1.06 1.06L9.06 8.31l4.78 4.78-1.06 1.06L8 9.37l-4.78 4.78-1.06-1.06 4.78-4.78-4.78-4.78 1.06-1.06Z"})})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-4 py-4 sm:px-5",children:t.jsx("pre",{className:"whitespace-pre-wrap break-words text-sm leading-6 text-stone-200",children:n})})]})]}),document.body):null}var ep=[/^(?: {0,3})#{1,6}\s+\S/m,/^(?: {0,3})>{1,}\s*\S/m,/^(?: {0,3})(?:[-+*]|\d{1,9}[.)])\s+(?:\[[ xX]\]\s+)?\S/m,/^(?: {0,3})(?:```|~~~)/m,/^(?: {0,3})(?:[-*_]\s*){3,}$/m],tp=/^(?:\|?[^|\n]+\|[^|\n]+(?:\|[^|\n]+)*\|?\s*\n\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$)/m,rp=/!?\[[^\]\n]+\]\([^)]+\)/,np=/`[^`\n]+`/,ap=/(?:\*\*[^*\n]+\*\*|__[^_\n]+__)/,sp=/(^|[^\w])(?:\*[^*\n]+\*|_[^_\n]+_)(?=[^\w]|$)/,op=/~~[^~\n]+~~/;function lp(e){const r=e.trim();return r?ep.some(n=>n.test(r))||tp.test(r)?!0:/[`[\]*_~!]/.test(r)?rp.test(r)||np.test(r)||ap.test(r)||sp.test(r)||op.test(r):!1:!1}Xr();function Bn(e,r){const n=new Map(r.map(s=>[s.id,s])),a=e.map(s=>{var l,i;return{...s.manifest,enabled:((l=n.get(s.manifest.id))==null?void 0:l.enabled)??!0,source:((i=n.get(s.manifest.id))==null?void 0:i.source)??"builtin"}}),o=new Set(e.map(s=>s.manifest.id));for(const s of r)o.has(s.id)||a.push(s);return a}function ta(e=[]){const r=Bn(e,[]),n=e;return{plugins:r,loading:!1,error:null,async refresh(){},async importPluginManifest(){},async setPluginEnabled(){},async uninstallPlugin(){},renderArtifact:s=>{var i;const l=n.find(d=>d.renderArtifact&&d.manifest.capabilities.artifactTypes.some(h=>h.type===s.artifact.type));return((i=l==null?void 0:l.renderArtifact)==null?void 0:i.call(l,s))??null},renderInlineCode:s=>{for(const l of n)for(const i of l.inlineCodeRenderers??[]){if(!i.languages.includes(s.language.trim().toLowerCase()))continue;const d=i.render(s);if(d)return d}return null},hasRendererForArtifact:s=>n.some(l=>!!l.renderArtifact&&l.manifest.capabilities.artifactTypes.some(i=>i.type===s.type)),getThreadPanels:()=>n.flatMap(s=>s.threadPanels??[])}}var ra=c.createContext(ta());function na(){return c.useContext(ra)??ta()}jr();function nl(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function hs(e){return nl(e)?Object.entries(e):e==null||e===""?[]:[["value",e]]}function al(e){return typeof e=="string"?t.jsxs("span",{className:"thread-graph-tool-string",children:['"',e,'"']}):typeof e=="number"?t.jsx("span",{className:"thread-graph-tool-number",children:e}):typeof e=="boolean"?t.jsx("span",{className:"thread-graph-tool-boolean",children:String(e)}):e===null?t.jsx("span",{className:"thread-graph-tool-null",children:"null"}):typeof e=="object"?t.jsx("span",{className:"thread-graph-tool-object",children:JSON.stringify(e)}):t.jsx("span",{children:String(e)})}function ip(e,r){return typeof r=="string"&&(e==="stdout"||e==="stderr"||e==="result")?t.jsx("pre",{className:"thread-graph-tool-output",children:r||"(empty)"}):typeof r=="object"&&r!==null?t.jsx("pre",{className:"thread-graph-tool-output",children:JSON.stringify(r,null,2)}):al(r)}function us({callId:e,toolName:r,status:n,parameters:a,result:o}){const s=c.useMemo(()=>{switch(n){case"completed":return{className:"is-completed",icon:t.jsx($.CheckCircle2,{className:"h-3.5 w-3.5"}),label:"Completed"};case"failed":return{className:"is-failed",icon:t.jsx($.XCircle,{className:"h-3.5 w-3.5"}),label:"Failed"};default:return{className:"is-pending",icon:t.jsx($.Loader2,{className:"h-3.5 w-3.5 animate-spin"}),label:"Running"}}},[n]),l=c.useMemo(()=>hs(o),[o]),i=c.useMemo(()=>hs(a),[a]),d=c.useMemo(()=>typeof o=="string"?o.length>0:nl(o)?["stdout","stderr","result"].some(f=>{const p=o[f];return typeof p=="string"&&p.length>0}):!1,[o]),h=n==="pending"||d,[u,m]=c.useState(h?"item-1":void 0);return c.useEffect(()=>{h&&m("item-1")},[e,h]),t.jsx("div",{className:"thread-graph-tool-call my-2 w-full font-sans not-prose",children:t.jsx(kr,{type:"single",collapsible:!0,onValueChange:f=>m(f||void 0),className:"thread-graph-tool-accordion w-full overflow-hidden rounded-lg border",...u!==void 0?{value:u}:{},children:t.jsxs(wr,{value:"item-1",className:"border-0",children:[t.jsx(Yr,{className:"thread-graph-tool-trigger px-4 py-3 hover:no-underline",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx($.Wrench,{className:"h-4 w-4 shrink-0"}),t.jsx("span",{className:"min-w-0 truncate font-mono text-sm font-semibold",children:r}),t.jsxs("span",{className:`thread-graph-tool-badge ${s.className}`,title:s.label,"aria-label":`Status: ${s.label}`,children:[s.icon,t.jsx("span",{className:"thread-graph-status-label",children:s.label})]})]})}),t.jsxs(yr,{className:"thread-graph-tool-content px-4 pb-4 pt-1",children:[t.jsxs("section",{children:[t.jsx("h4",{children:"Parameters"}),t.jsxs("div",{className:"thread-graph-tool-json",children:["{",t.jsx("br",{}),i.length>0?i.map(([f,p],g)=>t.jsxs("div",{children:[t.jsxs("span",{className:"thread-graph-tool-key",children:['"',f,'"']}),t.jsx("span",{className:"thread-graph-tool-punctuation",children:": "}),al(p),g<i.length-1?t.jsx("span",{className:"thread-graph-tool-punctuation",children:","}):null]},f)):t.jsx("div",{children:t.jsx("span",{className:"thread-graph-tool-null",children:"empty"})}),"}"]})]}),l.length>0?t.jsxs("section",{children:[t.jsx("h4",{children:"Result"}),t.jsxs("div",{className:"thread-graph-tool-json",children:["{",t.jsx("br",{}),l.map(([f,p],g)=>t.jsxs("div",{children:[t.jsxs("span",{className:"thread-graph-tool-key",children:['"',f,'"']}),t.jsx("span",{className:"thread-graph-tool-punctuation",children:": "}),ip(f,p),g<l.length-1?t.jsx("span",{className:"thread-graph-tool-punctuation",children:","}):null]},f)),"}"]})]}):null]})]})})})}var ms=null;function dp(){return ms??(ms=Promise.all([qe(()=>import("./core-oEok_Crl.js"),__vite__mapDeps([0,1,2])),qe(()=>import("./engine-javascript-DBd1bXLz.js"),[]),qe(()=>import("./ayu-light-BA47KaF1.js"),[]),qe(()=>import("./ayu-dark-DYE7WIF3.js"),[]),qe(()=>import("./javascript-wDzz0qaB.js"),[]),qe(()=>import("./typescript-BPQ3VLAy.js"),[]),qe(()=>import("./tsx-COt5Ahok.js"),[]),qe(()=>import("./jsx-g9-lgVsj.js"),[]),qe(()=>import("./python-B6aJPvgy.js"),[]),qe(()=>import("./json-Cp-IABpG.js"),[]),qe(()=>import("./shellscript-CEILq0vU.js").then(e=>e.b),[]),qe(()=>import("./shellscript-CEILq0vU.js").then(e=>e.s),[]),qe(()=>import("./yaml-Buea-lGh.js"),[]),qe(()=>import("./toml-vGWfd6FD.js"),[]),qe(()=>import("./markdown-Cvjx9yec.js"),[]),qe(()=>import("./html-pp8916En.js"),__vite__mapDeps([3,4,5])),qe(()=>import("./css-CLj8gQPS.js"),[]),qe(()=>import("./sql-CRqJ_cUM.js"),[]),qe(()=>import("./csv-fuZLfV_i.js"),[])]).then(([{createHighlighterCore:e},{createJavaScriptRegexEngine:r},n,a,o,s,l,i,d,h,u,m,f,p,g,b,w,x,j])=>e({engine:r(),themes:[n.default,a.default],langs:[o.default,s.default,l.default,i.default,d.default,h.default,u.default,m.default,f.default,p.default,g.default,b.default,w.default,x.default,j.default]}))),ms}function Zr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Gn(e){if(!e)return{};if(Zr(e)&&Object.prototype.hasOwnProperty.call(e,"0"))try{const r=Object.keys(e).map(Number).filter(n=>Number.isFinite(n)).sort((n,a)=>n-a).map(n=>String(e[String(n)]??"")).join("");return JSON.parse(r)}catch{return e}if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}function Fn(){return{finalResult:null,stdout:"",stderr:""}}function cp(e){return typeof e=="string"?{result:e}:e}function sl(e){const r=Zr(e.finalResult)?{...e.finalResult}:e.finalResult!=null?{result:e.finalResult}:{};return e.stdout&&(r.stdout=e.stdout),e.stderr&&(r.stderr=e.stderr),!("status"in r)&&(e.stdout||e.stderr)&&(r.status="pending"),r}function ps(e){if(!e)return"pending";if(!Zr(e))return"completed";const r=e.status;return r==="stream"||r==="pending"||r==="running"?"pending":r==="failed"||r==="error"||r==="timed_out"||typeof e.exit_code=="number"&&e.exit_code!==0?"failed":"completed"}function hp(e){const r=new Map,n=/```tool-result\s*([\s\S]*?)\s*```/g,a=e.replace(n,(l,i)=>{try{const d=JSON.parse(i),h=d.call_id;if(typeof h!="string")return l;const u=cp(d.result),m=r.get(h)??Fn();return Zr(u)&&u.status==="stream"&&typeof u.chunk=="string"?u.stream==="stderr"?m.stderr+=u.chunk:m.stdout+=u.chunk:m.finalResult=u,r.set(h,m),""}catch{return l}}),o=/```tool-call\s*([\s\S]*?)\s*```/g;return{processedContent:a.replace(o,(l,i)=>{try{const d=JSON.parse(i),h=d.call_id,u=d.tool;if(typeof u!="string")return l;const m=Gn(d.args);if(typeof h=="string"&&r.has(h)){const f=sl(r.get(h)??Fn());return`\`\`\`tool-merged
3659
3657
  ${JSON.stringify({call:{tool:u,args:m,call_id:h},result:f},null,2)}
3660
3658
  \`\`\``}return l}catch{return l}}),resultMap:r}}var up=["/api/","/assets/","/control-plane","/devices/","/relay/","/relay-account","/relay-admin","/relay-devices","/relay-portal","/threads","/workspaces"];function fs(e){return e.replace(/background-color:[^;"]+;?/g,"background-color: transparent;").replace(/background:[^;"]+;?/g,"background: transparent;")}function gs(e){return Array.isArray(e)?e.map(r=>String(r)).join(""):String(e??"")}function mp(e){if(!e||typeof e!="object"||!("position"in e))return{startLine:void 0,endLine:void 0};const r=e.position;if(!r||typeof r!="object")return{startLine:void 0,endLine:void 0};const n=r.start,a=r.end,o=n&&typeof n=="object"?n.line:void 0,s=a&&typeof a=="object"?a.line:void 0;return{startLine:typeof o=="number"?o:void 0,endLine:typeof s=="number"?s:void 0}}function pp(e){if(!e)return null;let r=e.trim();if(!r)return null;try{if(typeof window>"u")return null;const s=new URL(r,window.location.origin);if(s.origin!==window.location.origin&&s.protocol!=="file:")return null;r=(s.protocol==="file:",s.pathname)}catch{}try{r=decodeURIComponent(r)}catch{}if(!r.startsWith("/")||up.some(s=>r===s||r.startsWith(s)))return null;const n=r.match(/:(\d+)(?::\d+)?$/),a=n?Number.parseInt(n[1]??"",10):void 0,o=n?r.slice(0,-n[0].length):r;return!o||o==="/"?null:{path:o,...Number.isFinite(a)?{line:a}:{}}}function fp({children:e,...r}){return gp(e)?t.jsx(t.Fragment,{children:e}):t.jsx("pre",{...r,children:e})}function gp(e){var n;if(!e||typeof e!="object"||!("props"in e))return!1;const r=(n=e.props)==null?void 0:n.className;return typeof r!="string"?!1:r.includes("language-tool-call")||r.includes("language-tool-merged")||r.includes("language-tool-result")}var xp=c.memo(function({className:r="thread-graph-markdown",content:n,onOpenWorkspaceFile:a}){const o=c.useRef(null),s=na(),[l,i]=c.useState(null),[d,h]=c.useState({}),[u,m]=c.useState(!1),{processedContent:f,resultMap:p}=c.useMemo(()=>hp(n),[n]);c.useEffect(()=>{let w=!0;return dp().then(x=>{w&&i(x)}).catch(()=>{}),()=>{w=!1}},[]),c.useEffect(()=>{const w=o.current,x=w==null?void 0:w.closest(".thread-ui-shell"),j=()=>x?x.getAttribute("data-theme-effective")==="dark"||x.classList.contains("dark")||x.classList.contains("thread-ui-theme-dark"):document.documentElement.classList.contains("dark");if(m(j()),!x)return;const k=new MutationObserver(()=>m(j()));return k.observe(x,{attributes:!0,attributeFilter:["class","data-theme-effective"]}),()=>k.disconnect()},[]);async function g(w,x){try{await navigator.clipboard.writeText(x),h(j=>({...j,[w]:"copied"})),window.setTimeout(()=>{h(j=>{const k={...j};return delete k[w],k})},1200)}catch{h(j=>({...j,[w]:"failed"}))}}const b=({children:w,className:x,inline:j,node:k,...y})=>{var B;const v=/language-(\w+(?:-\w+)*)/.exec(x||""),N=v?v[1]??"":"",S=gs(w).replace(/\n$/,""),{startLine:L,endLine:z}=mp(k),V=j===!1||!!x||S.includes(`
3661
- `)||L!==z;if(N==="tool-merged"){let J={call:{tool:"Unknown",args:{},call_id:void 0},result:null};try{J=JSON.parse(S)}catch{J={call:{tool:"Error",args:{raw:S}},result:{status:"failed"}}}const Z=typeof J.call.tool=="string"?J.call.tool:"Unknown",D=typeof J.call.call_id=="string"?J.call.call_id:void 0;return t.jsx(us,{callId:D,toolName:Z,status:ps(J.result),parameters:Gn(J.call.args),result:J.result})}if(N==="tool-call"){let J={tool:"Unknown",args:{},call_id:void 0};try{J=JSON.parse(S)}catch{J={tool:"Error",args:{raw:S}}}const Z=typeof J.call_id=="string"?J.call_id:void 0,D=Z&&p.has(Z)?sl(p.get(Z)??Fn()):void 0;return t.jsx(us,{callId:Z,toolName:typeof J.tool=="string"?J.tool:"Unknown",status:D?ps(D):"pending",parameters:Gn(J.args),result:D})}if(N==="tool-result")return null;if(["xyz","extxyz","cif","pdb"].includes(N)){const J=s.renderInlineCode({code:S,isIncomplete:!1,language:N});if(c.isValidElement(J))return J}if(V){const Z=(((B=l==null?void 0:l.getLoadedLanguages)==null?void 0:B.call(l))??[]).includes(N)?N:"text",D=u?"ayu-dark":"ayu-light",ee=`${N||"text"}:${S.length}:${S.slice(0,32)}`;let oe="";if(l)try{oe=fs(l.codeToHtml(S,{lang:Z,theme:D}))}catch{oe=fs(l.codeToHtml(S,{lang:"text",theme:D}))}return t.jsxs("div",{className:"thread-graph-code-block not-prose relative my-3 overflow-auto rounded-xl border p-3 text-sm shadow-sm",children:[t.jsx(br,{type:"button",onClick:()=>void g(ee,S),variant:"ghost",size:"sm",className:"thread-graph-code-copy absolute right-2 top-2 z-10 rounded-md p-1.5",title:d[ee]==="copied"?"Copied":d[ee]==="failed"?"Copy failed":"Copy","aria-label":"Copy code",children:t.jsx($.Copy,{className:"h-3.5 w-3.5"})}),oe?t.jsx("div",{dangerouslySetInnerHTML:{__html:oe}}):t.jsx("pre",{children:t.jsx("code",{className:"whitespace-pre",children:S})})]})}const F=gs(w).replace(/`+/g,"");return t.jsx("code",{className:`thread-graph-inline-code rounded px-1 py-0.5 font-mono font-normal text-[0.9em] ${x||""}`,...y,children:F})};return t.jsx("div",{ref:o,className:`thread-graph-message-markdown ${r}`,children:t.jsx(gd,{remarkPlugins:[bd,vd],rehypePlugins:[xd],components:{a({href:w,children:x,...j}){const k=pp(w);return k&&a?t.jsx("a",{...j,href:w,className:"thread-inline-link",onClick:y=>{y.preventDefault(),a(k)},children:x}):t.jsx("a",{...j,href:w,className:"thread-inline-link",children:x})},code:b,pre:fp},children:f})})}),xs=4e3,bp=/\b(?:https?:\/\/|www\.)[^\s<>"'`]+/gi,vp=/[),.;:!?]+$/;function kp(e){return e.startsWith("www.")?`https://${e}`:e}function bs(e){const r=e.replace(/[\\/]+$/,"").trim();return r?r.split(/[\\/]/).filter(Boolean).at(-1)??r:""}function wp(e){var s;if(!e)return[];const r=/\[(PHOTO|FILE)\s+([^\]]+)\]/g,n=[];let a=0,o=0;for(const l of e.matchAll(r)){const i=l.index??0;i>a&&(n.push({type:"text",key:`text-${o}`,text:e.slice(a,i)}),o+=1);const d=l[1],h=((s=l[2])==null?void 0:s.trim())??"";d==="PHOTO"&&h?n.push({type:"photo",key:`photo-${o}`,path:h}):d==="FILE"&&h?n.push({type:"file",key:`file-${o}`,path:h}):n.push({type:"text",key:`text-${o}`,text:l[0]}),o+=1,a=i+l[0].length}return a<e.length&&n.push({type:"text",key:`text-${o}`,text:e.slice(a)}),n}function rr({text:e}){var a;const r=[];let n=0;for(const o of e.matchAll(bp)){const s=o[0],l=o.index??0,i=((a=s.match(vp))==null?void 0:a[0])??"",d=i?s.slice(0,-i.length):s;d&&(l>n&&r.push(e.slice(n,l)),r.push(t.jsx("a",{href:kp(d),target:"_blank",rel:"noreferrer",className:"thread-inline-link",children:d},`${l}-${d}`)),i&&r.push(i),n=l+s.length)}return n<e.length&&r.push(e.slice(n)),t.jsx(t.Fragment,{children:r.length>0?r:e})}var ol=c.memo(function({text:r,scrollRootRef:n,streaming:a=!1,containerClassName:o="",plainTextClassName:s="thread-graph-plain-text whitespace-pre-wrap break-words text-[15px] leading-6",markdownClassName:l="thread-graph-markdown",onBeforeResize:i,onOpenWorkspaceFile:d}){const h=c.useRef(null),u=c.useRef(null),[m,f]=c.useState(!1),p=lp(r),g=!a&&r.length>xs,b=g&&!m?`${r.slice(0,xs).trimEnd()}
3659
+ `)||L!==z;if(N==="tool-merged"){let J={call:{tool:"Unknown",args:{},call_id:void 0},result:null};try{J=JSON.parse(S)}catch{J={call:{tool:"Error",args:{raw:S}},result:{status:"failed"}}}const Z=typeof J.call.tool=="string"?J.call.tool:"Unknown",D=typeof J.call.call_id=="string"?J.call.call_id:void 0;return t.jsx(us,{callId:D,toolName:Z,status:ps(J.result),parameters:Gn(J.call.args),result:J.result})}if(N==="tool-call"){let J={tool:"Unknown",args:{},call_id:void 0};try{J=JSON.parse(S)}catch{J={tool:"Error",args:{raw:S}}}const Z=typeof J.call_id=="string"?J.call_id:void 0,D=Z&&p.has(Z)?sl(p.get(Z)??Fn()):void 0;return t.jsx(us,{callId:Z,toolName:typeof J.tool=="string"?J.tool:"Unknown",status:D?ps(D):"pending",parameters:Gn(J.args),result:D})}if(N==="tool-result")return null;if(["xyz","extxyz","cif","pdb"].includes(N)){const J=s.renderInlineCode({code:S,isIncomplete:!1,language:N});if(c.isValidElement(J))return J}if(V){const Z=(((B=l==null?void 0:l.getLoadedLanguages)==null?void 0:B.call(l))??[]).includes(N)?N:"text",D=u?"ayu-dark":"ayu-light",ee=`${N||"text"}:${S.length}:${S.slice(0,32)}`;let oe="";if(l)try{oe=fs(l.codeToHtml(S,{lang:Z,theme:D}))}catch{oe=fs(l.codeToHtml(S,{lang:"text",theme:D}))}return t.jsxs("div",{className:"thread-graph-code-block not-prose relative my-3 overflow-auto rounded-xl border p-3 text-sm shadow-sm",children:[t.jsx(br,{type:"button",onClick:()=>void g(ee,S),variant:"ghost",size:"sm",className:"thread-graph-code-copy absolute right-2 top-2 z-10 rounded-md p-1.5",title:d[ee]==="copied"?"Copied":d[ee]==="failed"?"Copy failed":"Copy","aria-label":"Copy code",children:t.jsx($.Copy,{className:"h-3.5 w-3.5"})}),oe?t.jsx("div",{dangerouslySetInnerHTML:{__html:oe}}):t.jsx("pre",{children:t.jsx("code",{className:"whitespace-pre",children:S})})]})}const F=gs(w).replace(/`+/g,"");return t.jsx("code",{className:`thread-graph-inline-code rounded px-1 py-0.5 font-mono font-normal text-[0.9em] ${x||""}`,...y,children:F})};return t.jsx("div",{ref:o,className:`thread-graph-message-markdown ${r}`,children:t.jsx(gd,{remarkPlugins:[bd,vd],rehypePlugins:[xd],components:{a({href:w,children:x,...j}){const k=pp(w);return k&&a?t.jsx("a",{...j,href:w,className:"thread-inline-link",onClick:y=>{y.preventDefault(),a(k)},children:x}):t.jsx("a",{...j,href:w,className:"thread-inline-link",children:x})},code:b,pre:fp},children:f})})}),xs=2400,bp=/\b(?:https?:\/\/|www\.)[^\s<>"'`]+/gi,vp=/[),.;:!?]+$/;function kp(e){return e.startsWith("www.")?`https://${e}`:e}function bs(e){const r=e.replace(/[\\/]+$/,"").trim();return r?r.split(/[\\/]/).filter(Boolean).at(-1)??r:""}function wp(e){var s;if(!e)return[];const r=/\[(PHOTO|FILE)\s+([^\]]+)\]/g,n=[];let a=0,o=0;for(const l of e.matchAll(r)){const i=l.index??0;i>a&&(n.push({type:"text",key:`text-${o}`,text:e.slice(a,i)}),o+=1);const d=l[1],h=((s=l[2])==null?void 0:s.trim())??"";d==="PHOTO"&&h?n.push({type:"photo",key:`photo-${o}`,path:h}):d==="FILE"&&h?n.push({type:"file",key:`file-${o}`,path:h}):n.push({type:"text",key:`text-${o}`,text:l[0]}),o+=1,a=i+l[0].length}return a<e.length&&n.push({type:"text",key:`text-${o}`,text:e.slice(a)}),n}function rr({text:e}){var a;const r=[];let n=0;for(const o of e.matchAll(bp)){const s=o[0],l=o.index??0,i=((a=s.match(vp))==null?void 0:a[0])??"",d=i?s.slice(0,-i.length):s;d&&(l>n&&r.push(e.slice(n,l)),r.push(t.jsx("a",{href:kp(d),target:"_blank",rel:"noreferrer",className:"thread-inline-link",children:d},`${l}-${d}`)),i&&r.push(i),n=l+s.length)}return n<e.length&&r.push(e.slice(n)),t.jsx(t.Fragment,{children:r.length>0?r:e})}var ol=c.memo(function({text:r,scrollRootRef:n,streaming:a=!1,containerClassName:o="",plainTextClassName:s="thread-graph-plain-text whitespace-pre-wrap break-words text-[15px] leading-6",markdownClassName:l="thread-graph-markdown",onBeforeResize:i,onOpenWorkspaceFile:d}){const h=c.useRef(null),u=c.useRef(null),[m,f]=c.useState(!1),p=lp(r),g=!a&&r.length>xs,b=g&&!m?`${r.slice(0,xs).trimEnd()}
3662
3660
 
3663
3661
  ...`:r,[w,x]=c.useState(a||typeof IntersectionObserver>"u"),j=c.useCallback(()=>{const k=n.current,y=h.current,v=(y==null?void 0:y.getBoundingClientRect().top)??null;i==null||i(),u.current=k&&v!==null?{root:k,top:v}:null,f(N=>!N)},[i,n]);return c.useLayoutEffect(()=>{const k=u.current,y=h.current;if(!k||!y)return;u.current=null;const v=()=>{const S=y.getBoundingClientRect().top;k.root.scrollTop+=S-k.top};v();const N=window.requestAnimationFrame(v);return()=>{window.cancelAnimationFrame(N)}},[m]),c.useEffect(()=>{if(a||typeof IntersectionObserver>"u"){x(!0);return}if(w||!h.current)return;const k=new IntersectionObserver(y=>{for(const v of y)if(v.isIntersecting){x(!0),k.disconnect();break}},{root:n.current,threshold:0});return k.observe(h.current),()=>{k.disconnect()}},[w,n,a]),t.jsxs("div",{ref:h,className:o,children:[w&&p?t.jsx(xp,{content:b,className:l,onOpenWorkspaceFile:d}):t.jsx("p",{className:s,children:t.jsx(rr,{text:b})}),g?t.jsx("button",{type:"button",onClick:j,className:"thread-graph-show-more timeline-meta-text mt-1.5 flex w-full items-center justify-center rounded-md border border-[var(--theme-border)] px-2 py-0.5 text-[10px] leading-4 transition hover:bg-[var(--theme-hover)] hover:text-[var(--theme-fg)]",children:m?"Show less":`Show more (${r.length.toLocaleString()} chars)`}):null]})}),yp=c.memo(function({text:r,scrollRootRef:n,streaming:a=!1,onBeforeResize:o,onOpenWorkspaceFile:s}){return t.jsx(ol,{text:r,scrollRootRef:n,streaming:a,containerClassName:"thread-graph-message-prose",...o?{onBeforeResize:o}:{},...s?{onOpenWorkspaceFile:s}:{}})}),jp=c.memo(function({threadId:r,text:n,attachmentPreviewUrls:a,getImageAssetUrl:o}){const s=c.useMemo(()=>wp(n),[n]);return t.jsx("div",{className:"thread-graph-message-prose whitespace-pre-wrap break-words text-[15px] leading-6",children:s.map(l=>{if(l.type==="text")return t.jsx("span",{children:l.text},l.key);if(l.type==="photo"){const d=(a==null?void 0:a[l.path])??(r?(o==null?void 0:o({threadId:r,path:l.path}))??null:null),h=bs(l.path)||"Attached image";return t.jsx("span",{className:"mx-[0.14rem] inline-flex align-middle",children:t.jsxs("span",{className:"inline-flex max-w-full flex-col rounded-[1rem] border border-sky-300/28 bg-sky-300/[0.08] p-1.5 shadow-sm shadow-stone-950/20",children:[d?t.jsx("img",{src:d,alt:h,className:"h-[4.5rem] w-[6rem] rounded-[0.75rem] bg-stone-950 object-contain",loading:"lazy"}):t.jsx("span",{className:"inline-flex h-[4.5rem] w-[6rem] items-center justify-center rounded-[0.75rem] bg-stone-950 text-[10px] text-sky-100",children:"PHOTO"}),t.jsx("span",{className:"mt-1 max-w-[7rem] truncate text-[10px] font-medium tracking-[0.08em] text-sky-50",title:l.path,children:h})]})},l.key)}const i=bs(l.path)||"Attached file";return t.jsx("span",{className:"mx-[0.14rem] inline-flex align-middle",children:t.jsxs("span",{className:"inline-flex max-w-[12rem] items-center gap-2 rounded-[0.95rem] border border-emerald-300/28 bg-emerald-300/[0.08] px-2.5 py-2 text-[10px] font-medium tracking-[0.08em] text-emerald-50 shadow-sm shadow-stone-950/20",title:l.path,children:[t.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-emerald-200/20 bg-emerald-300/12 text-[9px]",children:"FILE"}),t.jsx("span",{className:"min-w-0 truncate",children:i})]})},l.key)})})});function Np(){return t.jsx("span",{className:"ml-1.5 inline-flex items-center gap-1","aria-hidden":"true",children:[0,1,2].map(e=>t.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-sky-200/90",style:{animationDelay:`${e*180}ms`}},e))})}function vs({status:e}){if(!e)return null;const r=e.toLowerCase(),n=r.includes("running")||r.includes("generating")||r.includes("steering"),a=r.includes("failed")||r.includes("error"),o=r.includes("accepted")||r.includes("complete"),s=n?"ui-status-warning":a?"ui-status-danger":o?"ui-status-success":"ui-status-neutral",l=n?t.jsx($.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):a?t.jsx($.XCircle,{className:"h-3.5 w-3.5"}):o?t.jsx($.CheckCircle2,{className:"h-3.5 w-3.5"}):t.jsx($.Circle,{className:"h-3.5 w-3.5"});return t.jsxs("span",{className:`thread-graph-message-status inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-normal ${s}`,title:e,"aria-label":`Status: ${e}`,children:[t.jsx("span",{className:"thread-graph-message-status-icon inline-flex shrink-0",children:n?t.jsx(Np,{}):l}),t.jsx("span",{className:"thread-graph-status-label",children:e})]})}function Cp({children:e,copyButton:r,kind:n,metaControl:a,reasoning:o,status:s,timeLabel:l,timeTitle:i}){const d=n==="userMessage",h=l?t.jsx("span",{title:i??void 0,className:"thread-graph-message-time text-[10px] leading-none sm:text-[11px]",children:l}):null;return t.jsx("div",{"data-testid":"chat-message","data-role":d?"user":"assistant",className:"thread-graph-message flex justify-start",children:t.jsxs("div",{className:`thread-graph-message-bubble min-w-0 w-full max-w-full ${d?"is-user":"is-assistant"}`,children:[d?null:t.jsxs("div",{className:"thread-graph-message-header mb-2 flex min-w-0 items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx("span",{className:"thread-graph-message-sender rounded-full px-2.5 py-1 text-xs font-semibold tracking-[0.02em]",children:"Assistant"}),t.jsx(vs,{status:s??"Complete"})]}),a?t.jsx("div",{className:"thread-graph-message-header-meta flex min-w-0 flex-1 justify-center",children:a}):null,r||h?t.jsxs("div",{className:"thread-graph-message-header-actions flex shrink-0 items-center gap-1.5 sm:gap-2",children:[r,h]}):null]}),o,t.jsx("div",{className:`thread-graph-message-content min-w-0 ${d?"is-user":"is-assistant"}`,children:e}),d&&(s||h)?t.jsxs("div",{className:"mt-1 flex items-center justify-end gap-2",children:[s?t.jsx(vs,{status:s}):null,h]}):null]})})}jr();function Sp(e){if(!e)return!1;const r=e.toLowerCase();return r.includes("running")||r.includes("inprogress")||r.includes("in_progress")}function Tp({tone:e="amber"}){const r=e==="sky"?"bg-sky-300/90":"bg-amber-200/90";return t.jsx("span",{className:"ml-1.5 inline-flex items-center gap-1","aria-hidden":"true",children:[0,1,2].map(n=>t.jsx("span",{className:`h-1.5 w-1.5 animate-pulse rounded-full ${r}`,style:{animationDelay:`${n*180}ms`}},n))})}var Et=c.memo(function({threadId:r,item:n,scrollRootRef:a,streaming:o=!1,adapter:s,timeLabel:l,timeTitle:i,onBeforeMessageResize:d}){const[h,u]=c.useState("idle"),[m,f]=c.useState(!1),p=c.useRef(null),g=n.kind==="agentMessage"?n.reasoningItems??[]:[],b=g.map(S=>S.text.trim()).filter(Boolean).join(`
3664
3662
 
3665
3663
  `),w=n.kind==="userMessage"&&(n.status==="Steering"||n.status==="Accepted"||n.status==="Awaiting response");c.useEffect(()=>()=>{p.current!==null&&window.clearTimeout(p.current)},[]);async function x(){try{await navigator.clipboard.writeText(n.text),u("copied"),p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>u("idle"),1200)}catch{u("failed"),p.current!==null&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>u("idle"),1600)}}function j(){d==null||d(),f(S=>!S)}const k=n.kind==="agentMessage"?t.jsx("button",{type:"button","aria-label":"Copy agent reply",title:h==="copied"?"Copied":h==="failed"?"Copy failed":"Copy agent reply",onClick:()=>void x(),className:`thread-graph-message-copy inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border transition ${h==="copied"?"ui-status-info":h==="failed"?"ui-status-danger":""}`,children:t.jsx($.Copy,{className:"h-3.5 w-3.5"})}):null,y=g.some(S=>Sp(S.status)),v=n.kind==="agentMessage"&&b?t.jsxs("button",{type:"button","aria-label":m?"Hide chain of thought":"Show chain of thought","aria-expanded":m,title:m?"Hide CoT":"Show CoT",onClick:j,className:`thread-graph-thinking-toggle inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md border px-2 text-xs font-medium transition ${m?"is-open":""}`,children:[t.jsx($.Brain,{className:`h-3.5 w-3.5 ${y?"animate-pulse":""}`}),t.jsx("span",{children:"CoT"}),y?t.jsx(Tp,{tone:"sky"}):null]}):null,N=n.kind==="agentMessage"&&b?t.jsx("div",{className:"thread-graph-message-thinking mb-3",children:t.jsx(kr,{type:"single",collapsible:!0,className:"thread-graph-thinking-accordion w-full border-none",onValueChange:S=>f(!!S),...m?{value:"thoughts"}:{},children:t.jsx(wr,{value:"thoughts",className:"border-b-0",children:t.jsx(yr,{className:"thread-graph-thinking-content pb-0",children:t.jsx("pre",{className:"thread-graph-thinking-body my-1 max-h-56 overflow-auto whitespace-pre-wrap break-words rounded-xl border p-3 text-[12px] leading-5",children:t.jsx(rr,{text:b})})})})})}):null;return t.jsx(Cp,{kind:n.kind,status:w||n.kind==="agentMessage"?n.status:null,copyButton:k,metaControl:v,reasoning:N,timeLabel:l,timeTitle:i,children:n.kind==="agentMessage"?t.jsx(yp,{text:n.text,scrollRootRef:a,streaming:o,...d?{onBeforeResize:d}:{},...s!=null&&s.onOpenWorkspaceFile?{onOpenWorkspaceFile:s.onOpenWorkspaceFile}:{}}):t.jsx(jp,{threadId:r,text:n.text,attachmentPreviewUrls:n.attachmentPreviewUrls,getImageAssetUrl:s==null?void 0:s.getImageAssetUrl})})});function ks(e){return e.replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&amp;/g,"&")}function ll(e){const r=e.trim().match(/^<hook_prompt(?:\s+hook_run_id="([^"]+)")?>([\s\S]*)<\/hook_prompt>$/);if(!r)return null;const n=r[1]?ks(r[1]):null,a=ks(r[2]??"").trim(),o=(n==null?void 0:n.split(":")[0])??"hook",s=o==="stop"?"Stop":o,l=(n==null?void 0:n.split(":").slice(2).join(":"))||null;return{id:`live-hook-prompt:${n??"unknown"}`,kind:"hook",text:`${s} hook`,previewText:a||`${s} hook`,detailText:a||null,status:"Completed",hookEventName:o,hookEventLabel:s,hookHandlerType:"command",hookScope:"turn",hookSource:l?"project":null,hookSourcePath:l,hookStatusMessage:null,hookOutputEntries:a?[{kind:"warning",text:a}]:[]}}function Ep(e){return e==="userMessage"||e==="agentMessage"}function Lp(e){return e==="commandExecution"||e==="webSearch"||e==="fileRead"||e==="fileChange"||e==="image"||e==="contextCompaction"}function Pp(e){return e==="agentMessage"||e==="reasoning"||e==="agentToolCall"||e==="skillToolCall"||e==="toolCall"||e==="plan"}function zp(e,r){if(!r)return e;const n=[...e],a=n.findIndex(s=>s.kind==="userMessage");if(a<0)return n;for(let s=a+1;s<n.length;s+=1){const l=n[s];if(!l||l.kind!=="userMessage")continue;let i=s+1;for(;i<n.length&&Lp(n[i].kind);)i+=1;if(i===s+1)continue;const[d]=n.splice(s,1);n.splice(i-1,0,d),s=i-1}let o=!1;return n.map((s,l)=>s.kind!=="userMessage"?s:o?n.slice(l+1).some(d=>Pp(d.kind))?s:{...s,status:"Awaiting response"}:(o=!0,s))}function Ct(e){return typeof e.sequence=="number"&&Number.isFinite(e.sequence)}function Lr(e){return Ct(e)?e.sequence:Number.POSITIVE_INFINITY}function ws(e){var h;const r=[];let n=0;for(;n<e.length&&((h=e[n])==null?void 0:h.kind)==="userMessage"&&!Ct(e[n]);)r.push(e[n]),n+=1;const a=e.slice(n);if(!a.some(Ct))return e;const o=a.map(u=>Lr(u)).filter(Number.isFinite),s=o.length>0?Math.max(...o):0,l=[];let i=0;for(;i<a.length;){const u=a[i];if(Ct(u)){l.push({item:u,index:i,order:Lr(u)}),i+=1;continue}const m=i;for(;i<a.length&&!Ct(a[i]);)i+=1;const f=a.slice(m,i),p=[...a.slice(0,m)].reverse().find(Ct),g=a.slice(i).find(Ct),b=p?Lr(p):null,w=g?Lr(g):null;f.forEach((x,j)=>{let k;if(b===null&&w!==null)k=w-(f.length-j)/(f.length+1);else if(b!==null&&w!==null&&w>b){const y=w-b;k=b+(j+1)/(f.length+1)*y}else k=s+1+j/(f.length+1);l.push({item:x,index:m+j,order:k})})}const d=l.sort((u,m)=>{const f=u.order-m.order;return f===0?u.index-m.index:f}).map(u=>u.item);return[...r,...d]}function Ip(e,r){if(!r||r.length===0)return ws(e);const n=new Map(r.map(s=>[s.id,s])),a=e.map(s=>{const l=n.get(s.id);if(!l)return s;n.delete(s.id);const i={...s,...l,text:l.text||s.text},d=l.detailText??s.detailText,h=l.previewText??s.previewText,u=l.status??s.status,m=l.sequence??s.sequence;return d!==void 0&&(i.detailText=d),h!==void 0&&(i.previewText=h),u!==void 0&&(i.status=u),m!==void 0&&(i.sequence=m),i}),o=[...n.values()];return o.length===0&&!a.some(Ct)||(a.push(...o),!a.some(s=>typeof s.sequence=="number"&&Number.isFinite(s.sequence)))?a:ws(a)}function Rp(e,r){if(!e)return"";const n=r.filter(d=>d.kind==="agentMessage").map(d=>d.text).filter(d=>d.length>0),a=n.at(-1)??"";if(a){const d=e.lastIndexOf(a);if(d>=0){const h=e.slice(d+a.length);return h.trim()?h:""}}const o=n.join("");if(!o)return e;const s=Math.min(e.length,o.length);let l=0;for(;l<s&&e[l]===o[l];)l+=1;if(l===0)return e;const i=e.slice(l);return i.trim()?i:""}function il(e){if(!e)return!1;const r=e.toLowerCase();return r.includes("running")||r.includes("inprogress")||r.includes("in_progress")}function mr(e){return e==="inProgress"||e==="sending"}function Ap(e){var a;const r=[];let n=0;for(;n<e.length;){const o=e[n];if(!o)break;if(o.kind!=="commandExecution"&&o.kind!=="fileChange"&&o.kind!=="webSearch"&&o.kind!=="fileRead"){r.push({kind:"item",key:o.id,item:o}),n+=1;continue}const s=[];for(;n<e.length&&((a=e[n])==null?void 0:a.kind)===o.kind;)s.push(e[n]),n+=1;if(s.length===1){r.push({kind:"item",key:s[0].id,item:s[0]});continue}const l=s.map(i=>i.id).join(":");if(o.kind==="commandExecution"){r.push({kind:"commandGroup",key:l,items:s});continue}if(o.kind==="fileChange"){r.push({kind:"fileChangeGroup",key:l,items:s});continue}if(o.kind==="fileRead"){r.push({kind:"fileReadGroup",key:l,items:s});continue}r.push({kind:"searchGroup",key:l,items:s})}return r}function dl(e,r){return[...e.map(n=>({id:n.id,startedAt:n.startedAt??""})),...r?[{id:r.id,startedAt:r.startedAt??""}]:[]]}function pr(e,r,n){const a=e.get(r)??[];a.push(n),e.set(r,a)}function cl(e,r){return e.find(n=>r&&n.startedAt&&r.localeCompare(n.startedAt)<=0)}function _p({answeredRequestNotes:e,pendingRequests:r,visibleTurns:n,optimisticTurn:a}){const o=new Set(n.map(p=>p.id)),s=new Map,l=new Map,i=[],d=[];for(const p of e)p.turnId&&o.has(p.turnId)?pr(s,p.turnId,p):i.push(p);for(const p of r)p.turnId&&o.has(p.turnId)?pr(l,p.turnId,p):d.push(p);const h=dl(n,a),u=new Map,m=[],f=[...i.map(p=>({kind:"note",id:p.id,createdAt:p.createdAt??"",note:p})),...d.map(p=>({kind:"request",id:p.id,createdAt:p.createdAt,request:p}))].sort((p,g)=>p.createdAt.localeCompare(g.createdAt));for(const p of f){const g=cl(h,p.createdAt);if(!g){m.push(p);continue}pr(u,g.id,p)}return{notesByTurnId:s,pendingRequestsByTurnId:l,beforeTurnId:u,trailing:m}}function Mp({activityNotes:e,visibleTurns:r,optimisticTurn:n}){const a=[...e].sort((m,f)=>m.createdAt.localeCompare(f.createdAt)),o=dl(r,n),s=[],l=new Map,i=new Map,d=[],u=o.map(m=>m.startedAt).filter(m=>!!m).sort().at(-1)??null;for(const m of a){if(m.anchorTurnId==="__leading__"){s.push(m);continue}if(m.anchorTurnId){o.some(p=>p.id===m.anchorTurnId)?pr(i,m.anchorTurnId,m):s.push(m);continue}const f=cl(o,m.createdAt);if(!f){!u||m.createdAt.localeCompare(u)<=0?s.push(m):d.push(m);continue}pr(l,f.id,m)}return{leading:s,beforeTurnId:l,afterTurnId:i,trailing:d}}function hl({request:e,busy:r=!1,onRespond:n}){const[a,o]=c.useState({}),[s,l]=c.useState({}),[i,d]=c.useState(null),h=e.questions[0]??null,u="__other__",m=e.kind==="planDecision"?"Plan":e.kind==="requestUserInput"?"Answer Required":e.title;function f(x){const j=/\s*\(recommended\)\s*$/i.test(x);return{rawLabel:x,displayLabel:x.replace(/\s*\(recommended\)\s*$/i,"").trim(),recommended:j}}function p(x){h&&(d(x),n==null||n(e.id,{answers:{[h.id]:{answers:[x]}}}))}function g(x){const j=a[x.id]??"";return Array.isArray(j)?j.map(k=>k===u?(s[x.id]??"").trim():k.trim()).filter(Boolean).join(", "):j===u?(s[x.id]??"").trim():j.trim()}function b(x){const j=a[x.id]??"";if(Array.isArray(j))return j.map(y=>y===u?(s[x.id]??"").trim():y.trim()).filter(Boolean);if(j===u){const y=(s[x.id]??"").trim();return y?[y]:[]}const k=j.trim();return k?[k]:[]}function w(x,j){o(k=>{const y=k[x],v=Array.isArray(y)?y:[],N=v.includes(j)?v.filter(S=>S!==j):[...v,j];return{...k,[x]:N}})}return t.jsxs("div",{className:"timeline-pending-card w-full rounded-[1rem] border px-3 py-3 sm:rounded-[1.2rem] sm:px-4",children:[t.jsx("div",{className:"flex items-center justify-between gap-3",children:t.jsxs("div",{children:[t.jsx("p",{className:"timeline-primary-text text-sm font-medium",children:m}),e.kind!=="planDecision"&&e.description&&t.jsx("p",{className:"timeline-soft-text mt-1 text-[13px] leading-5",children:e.description})]})}),t.jsx("div",{className:"mt-3 space-y-3",children:e.questions.map(x=>t.jsxs("div",{className:"timeline-question-section rounded-xl border p-2.5 sm:p-3",children:[t.jsx("p",{className:"timeline-meta-text text-xs uppercase tracking-[0.2em]",children:x.header}),t.jsx("p",{className:"timeline-primary-text mt-1 text-[13px] leading-5 sm:text-sm",children:x.question}),e.kind==="planDecision"&&x.options&&x.options.length>0?t.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:x.options.map((j,k)=>{const y=f(j.label),v=y.displayLabel.toLowerCase()==="implement";return t.jsxs("button",{type:"button",disabled:r,onClick:()=>p(j.label),className:`relative rounded-2xl border px-2.5 py-1.5 pr-6 text-[12px] leading-4 transition sm:text-[13px] ${k===0?"ui-action-info":"border-stone-700 text-stone-200 hover:bg-stone-800"} disabled:cursor-not-allowed disabled:opacity-60`,title:j.description,children:[y.recommended?t.jsx("span",{"aria-hidden":"true",className:"absolute right-1.5 top-1 inline-flex h-3.5 w-3.5 items-center justify-center rounded-full bg-white/18 text-[10px] leading-none text-current",children:"✦"}):null,r&&i===j.label?v?"Starting...":"Saving...":y.displayLabel]},j.label)})}):x.options&&x.options.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[x.options.map(j=>{const k=f(j.label),y=a[x.id];return t.jsxs("button",{type:"button",disabled:r,onClick:()=>x.multiSelect?w(x.id,j.label):o(v=>({...v,[x.id]:j.label})),className:`relative rounded-2xl border px-3 py-1.5 pr-6 text-[12px] leading-4 transition sm:text-[13px] ${(x.multiSelect?Array.isArray(y)&&y.includes(j.label):y===j.label)?"ui-status-warning":"border-stone-700 text-stone-300 hover:bg-stone-800"} disabled:cursor-not-allowed disabled:opacity-60`,title:j.description,children:[k.recommended?t.jsx("span",{"aria-hidden":"true",className:"absolute right-1.5 top-1 inline-flex h-3.5 w-3.5 items-center justify-center rounded-full bg-white/10 text-[10px] leading-none text-amber-100/90",children:"✦"}):null,k.displayLabel]},j.label)}),x.isOther&&(()=>{const j=a[x.id];return t.jsx("button",{type:"button",disabled:r,onClick:()=>x.multiSelect?w(x.id,u):o(k=>({...k,[x.id]:u})),className:`rounded-2xl border px-3 py-1.5 text-[12px] leading-4 transition sm:text-[13px] ${(x.multiSelect?Array.isArray(j)&&j.includes(u):j===u)?"ui-status-info":"border-stone-700 text-stone-300 hover:bg-stone-800"} disabled:cursor-not-allowed disabled:opacity-60`,children:"Not from above"})})()]}),x.isOther&&(()=>{const j=a[x.id];return(x.multiSelect?Array.isArray(j)&&j.includes(u):j===u)?t.jsx("input",{"aria-label":`${x.header} custom answer`,value:s[x.id]??"",onChange:y=>l(v=>({...v,[x.id]:y.target.value})),placeholder:"Enter a custom answer",className:"mt-3 w-full rounded-xl border border-stone-700 bg-stone-900 px-3 py-2 text-sm text-stone-100 outline-none transition focus:border-sky-300"}):null})()]}):t.jsx("input",{"aria-label":x.header,value:a[x.id]??"",onChange:j=>o(k=>({...k,[x.id]:j.target.value})),className:"mt-3 w-full rounded-xl border border-stone-700 bg-stone-900 px-3 py-2 text-sm text-stone-100 outline-none transition focus:border-amber-300"})]},x.id))}),e.kind!=="planDecision"&&t.jsx("div",{className:"mt-3 flex justify-end",children:t.jsx("button",{type:"button",disabled:r||e.questions.some(x=>!g(x)),onClick:()=>void(n==null?void 0:n(e.id,{answers:Object.fromEntries(e.questions.map(x=>[x.id,{answers:b(x)}]))})),className:"ui-action-info rounded-full px-4 py-2 text-sm font-medium transition disabled:cursor-not-allowed",children:r?"Submitting...":"Submit"})})]})}function ul({note:e}){return t.jsxs("div",{className:"timeline-note-card w-full rounded-2xl border px-3 py-2.5",children:[t.jsx("p",{className:"timeline-meta-text text-[11px] uppercase tracking-[0.2em]",children:e.title}),t.jsx("div",{className:"mt-1 space-y-1",children:e.summaryLines.map((r,n)=>t.jsxs("p",{className:"timeline-primary-text text-[13px] leading-5",children:["You selected ",r]},`${e.id}-${n}`))})]})}function ml({note:e,onOpenThread:r,onOpenLinkedThread:n}){const a=e.kind==="forkCreated"?"Fork":e.kind==="forkSource"?"Fork source":"System",o=e.kind==="forkCreated"?`Thread forked from Turn ${e.turnIndex??"?"}`:e.kind==="forkSource"?`Forked from ${e.linkedThreadTitle??"source thread"} at Turn ${e.turnIndex??"?"}`:e.text??"";return t.jsxs("div",{className:"timeline-activity-card w-full rounded-2xl border px-3 py-2.5",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("p",{className:"timeline-meta-text text-[11px] uppercase tracking-[0.2em]",children:a}),t.jsx("time",{dateTime:e.createdAt,title:Gt(e.createdAt),className:"timeline-meta-text text-[10px]",children:ft(e.createdAt)})]}),t.jsx("p",{className:"timeline-primary-text mt-1 text-[13px] leading-5",children:o}),e.linkedThreadId?t.jsx("button",{type:"button",onClick:()=>{const s=e.linkedThreadId;s&&(n==null||n(s),r==null||r(s))},className:"relative z-10 mt-2 inline-flex cursor-pointer rounded-full border border-amber-300/30 px-3 py-1.5 text-xs text-amber-100 transition hover:bg-amber-300/10",children:e.kind==="forkCreated"?"Open fork":"Back to source"}):null]})}function ir({notes:e,onOpenThread:r,onOpenLinkedThread:n}){return e.length===0?null:t.jsx("div",{className:"thread-graph-message-section space-y-3 px-3 py-4 sm:px-5",children:e.map(a=>t.jsx(ml,{note:a,onOpenThread:r,onOpenLinkedThread:n},a.id))})}function Hn({entries:e,respondingRequestId:r,onRespondToRequest:n}){return e.length===0?null:t.jsx("div",{className:"thread-graph-message-section space-y-3 px-3 py-4 sm:px-5",children:e.map(a=>a.kind==="note"?t.jsx(ul,{note:a.note},a.id):t.jsx(hl,{request:a.request,busy:r===a.request.id,onRespond:n},a.id))})}function $p({notes:e,requests:r,respondingRequestId:n,onRespondToRequest:a}){const o=[...e.map(s=>({kind:"note",id:s.id,createdAt:s.createdAt??"",note:s})),...r.map(s=>({kind:"request",id:s.id,createdAt:s.createdAt,request:s}))].sort((s,l)=>s.createdAt.localeCompare(l.createdAt));return t.jsx(Hn,{entries:o,respondingRequestId:n,onRespondToRequest:a})}function Dp({entries:e,respondingRequestId:r,onRespondToRequest:n,onOpenThread:a,onOpenLinkedThread:o}){return e.length===0?null:t.jsx("div",{className:"thread-graph-message-section space-y-3 px-3 py-4 sm:px-5",children:[...e].sort((s,l)=>s.createdAt.localeCompare(l.createdAt)).map(s=>s.kind==="activity"?t.jsx(ml,{note:s.note,onOpenThread:a,onOpenLinkedThread:o},s.id):s.kind==="note"?t.jsx(ul,{note:s.note},s.id):t.jsx(hl,{request:s.request,busy:r===s.request.id,onRespond:n},s.id))})}function Bp({entries:e,expandedGroups:r,onToggleGroupedItem:n,renderCommandGroup:a,renderFileChangeGroup:o,renderFileReadGroup:s,renderItem:l,renderSearchGroup:i}){return t.jsx(t.Fragment,{children:e.map(d=>{const h=r[d.key]??!1,u=()=>n(d.key);return d.kind==="commandGroup"?a(d,h,u):d.kind==="fileChangeGroup"?o(d,h,u):d.kind==="searchGroup"?i(d,h,u):d.kind==="fileReadGroup"?s(d,h,u):l(d)})})}function Jr({children:e,className:r,count:n,countBadgeClassName:a,desktopIconClassName:o,expanded:s,expandedListClassName:l,icon:i,onToggleExpanded:d,runningIndicator:h,summary:u,timeMeta:m,toggleAriaLabel:f,trailingSummary:p}){return t.jsx("div",{className:`thread-graph-history-group ${r} relative min-w-0 w-full overflow-hidden rounded-[0.9rem] border px-3 py-2.5`,children:t.jsxs("div",{className:"flex items-start gap-2.5",children:[t.jsxs("div",{className:"thread-graph-history-group-icon mt-0.5 flex shrink-0 items-center",children:[t.jsxs("span",{className:`relative inline-flex h-8 w-8 items-center justify-center rounded-[0.9rem] border shadow-sm shadow-stone-950/20 ${o}`,children:[i,t.jsx("span",{className:`absolute -right-1 -top-1 inline-flex min-w-[1.1rem] items-center justify-center rounded-full border bg-stone-950/90 px-1 text-[9px] font-semibold leading-4 ${a}`,children:n})]}),h]}),t.jsxs("div",{className:"thread-graph-history-group-card min-w-0 flex-1 rounded-[0.85rem] border px-3 py-2",children:[t.jsxs("button",{type:"button","aria-expanded":s,"aria-label":f,onClick:d,className:"thread-graph-history-group-toggle flex w-full min-w-0 items-center justify-between gap-3 text-left",children:[t.jsx("div",{className:"thread-graph-history-group-summary min-w-0 flex flex-1 flex-wrap items-center gap-2 pr-1",children:u}),p||m?t.jsxs("div",{className:"inline-flex shrink-0 items-center gap-2",children:[p,m]}):null]}),s?t.jsx("div",{className:`thread-graph-history-group-list mt-3 space-y-2 border-t pt-3 ${l}`,children:e}):null]})]})})}jr();Pt();var Gp=vr("inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-md border px-2 py-0.5 text-xs font-medium outline-none transition-[color,box-shadow] focus-visible:ring-[3px] [&>svg]:pointer-events-none [&>svg]:size-3",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-white",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Qr({asChild:e=!1,className:r,variant:n,...a}){const o=e?As:"span";return t.jsx(o,{"data-slot":"badge",className:nt(Gp({variant:n,className:r})),...a})}function aa(e){if(!e)return!1;const r=e.trim().toLowerCase();return r==="running"||r==="in_progress"||r==="in progress"||r==="pending"}function Fp(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M5 2.75h4l2 2v6.5a1.5 1.5 0 0 1-1.5 1.5h-4A1.5 1.5 0 0 1 4 11.25v-7A1.5 1.5 0 0 1 5.5 2.75Z"}),t.jsx("path",{d:"M9 2.75v2h2"}),t.jsx("path",{d:"M6.2 8h3.6"}),t.jsx("path",{d:"M6.2 10h1.7"})]})}function Hp(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M5 2.75h4l2 2v6.5a1.5 1.5 0 0 1-1.5 1.5h-4A1.5 1.5 0 0 1 4 11.25v-7A1.5 1.5 0 0 1 5.5 2.75Z"}),t.jsx("path",{d:"M9 2.75v2h2"}),t.jsx("path",{d:"M6.15 7.25h3.7"}),t.jsx("path",{d:"M6.15 9.25h2.8"}),t.jsx("path",{d:"m10.4 10.7 1.2 1.2"}),t.jsx("circle",{cx:"9.25",cy:"9.55",r:"1.45"})]})}function Op(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"2.75",y:"3",width:"8.5",height:"3",rx:"1.1"}),t.jsx("rect",{x:"4.25",y:"6.5",width:"8.5",height:"3",rx:"1.1"}),t.jsx("rect",{x:"5.75",y:"10",width:"7.5",height:"3",rx:"1.1"}),t.jsx("path",{d:"m6.25 4.5 1 1-1 1"}),t.jsx("path",{d:"M7.9 5.5h1.7"}),t.jsx("path",{d:"m7.75 8 1 1-1 1"}),t.jsx("path",{d:"M9.4 9h1.7"})]})}function Up(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"6",cy:"6",r:"2.3"}),t.jsx("path",{d:"m8 8 1.6 1.6"}),t.jsx("circle",{cx:"9.3",cy:"8.8",r:"2"}),t.jsx("path",{d:"m10.75 10.25 1.65 1.65"}),t.jsx("circle",{cx:"11.2",cy:"4.75",r:"1.8"}),t.jsx("path",{d:"m12.45 6 1.1 1.1"})]})}function Wp(e){const r=e.trim();if(!r)return"";const n=r.match(/(, \+\d+ more.*)$/),a=(n==null?void 0:n[1])??"",s=(a?r.slice(0,-a.length):r).replace(/\\/g,"/");if(!s.startsWith("/"))return`${s.replace(/^\.\//,"")}${a}`;const l=["/apps/","/packages/","/src/","/test/","/tests/","/docs/","/config/","/scripts/","/e2e/","/.agents/","/.codex/"];for(const i of l){const d=s.indexOf(i);if(d>=0)return`${s.slice(d+1)}${a}`}return r}function pl(e,r=42){const n=Wp(e);if(!n)return"";const a=n.match(/(, \+\d+ more.*)$/),o=(a==null?void 0:a[1])??"",s=o?n.slice(0,-o.length):n;if(s.length<=r)return`${s}${o}`;const i=s.replace(/\\/g,"/").split("/").filter(Boolean);if(i.length>1){const d=[];let h=o.length+4;for(let u=i.length-1;u>=0;u-=1){const m=i[u],f=h+m.length+(d.length>0?1:0);if(d.length>0&&f>r)break;d.unshift(m),h=f}if(d.length>0)return`.../${d.join("/")}${o}`}return`...${s.slice(-(r-o.length-3))}${o}`}function Vp(e){var a;const r=[];if(typeof e.changedFiles=="number"&&e.changedFiles>0&&r.push(`${e.changedFiles} ${e.changedFiles===1?"file":"files"}`),typeof e.addedLines=="number"&&e.addedLines>0&&r.push(`+${e.addedLines}`),typeof e.removedLines=="number"&&e.removedLines>0&&r.push(`-${e.removedLines}`),r.length>0)return r;const n=(a=e.previewText)==null?void 0:a.trim();return n?n.replace(/\bfiles changed\b/gi,"files").replace(/\bfile changed\b/gi,"file").split("·").map(o=>o.trim()).filter(Boolean):[]}function On({tone:e="amber"}){const r=e==="emerald"?"bg-sky-200/90":e==="sky"?"bg-sky-300/90":"bg-amber-200/90";return t.jsx("span",{className:"ml-1.5 inline-flex items-center gap-1","aria-hidden":"true",children:[0,1,2].map(n=>t.jsx("span",{className:`h-1.5 w-1.5 animate-pulse rounded-full ${r}`,style:{animationDelay:`${n*180}ms`}},n))})}function Kp(e){var n;const r=e.replace(/\r\n/g,`
3666
3664
  `).split(`
3667
3665
  `);for(;r.length>1&&((n=r.at(-1))==null?void 0:n.trim())==="";)r.pop();return r}function gt(e){const r=Kp(e);return r.length===1?{firstLine:r[0]??"",showGap:!1,isTruncated:!1}:{firstLine:r[0]??"",showGap:!0,isTruncated:!0}}function fl(e){const r=(e==null?void 0:e.trim().toLowerCase())??"";return r==="completed"||r==="complete"||r==="success"||r==="succeeded"?{className:"is-completed",icon:t.jsx($.CheckCircle2,{className:"h-3.5 w-3.5"}),label:"Completed"}:r==="failed"||r==="failure"||r==="error"||r==="errored"?{className:"is-failed",icon:t.jsx($.XCircle,{className:"h-3.5 w-3.5"}),label:"Failed"}:aa(e)?{className:"is-pending",icon:t.jsx($.Loader2,{className:"h-3.5 w-3.5 animate-spin"}),label:(e==null?void 0:e.trim())||"Running"}:{className:"is-neutral",icon:null,label:(e==null?void 0:e.trim())||"Event"}}function qp(e){switch(e){case"command":return"is-command";case"tool":return"is-tool";case"agent":return"is-agent";case"skill":return"is-skill";case"search":return"is-search";case"fileRead":return"is-file-read"}}function Xp(e){switch(e){case"plan":return"is-plan";case"context":return"is-context";case"generic":return"is-generic";case"image":return"is-image";case"fileChange":return"is-file-change";case"artifact":return"is-artifact";case"hook":return"is-hook"}}function Ot({actions:e,children:r,className:n,headerMeta:a,icon:o,item:s,timeMeta:l,title:i,tone:d}){const h=fl(s.status);return t.jsxs("div",{className:`thread-graph-event thread-graph-history-event ${Xp(d)} ${n??""}`,children:[t.jsx("div",{className:"thread-graph-history-event-icon","aria-hidden":"true",children:o}),t.jsxs("div",{className:"thread-graph-history-event-card",children:[t.jsxs("div",{className:"thread-graph-history-event-header",children:[t.jsxs("div",{className:"thread-graph-history-event-heading flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"thread-graph-history-event-title min-w-0 truncate font-mono text-sm font-semibold",children:i}),s.status?t.jsxs(Qr,{variant:"outline",className:`thread-graph-tool-badge ${h.className} rounded-full px-2 py-0.5 text-xs font-normal`,title:h.label,"aria-label":`Status: ${h.label}`,children:[h.icon,t.jsx("span",{className:"thread-graph-status-label",children:h.label})]}):null,a]}),e||l?t.jsxs("div",{className:"thread-graph-history-event-actions",children:[e,l]}):null]}),r?t.jsx("div",{className:"thread-graph-history-event-body",children:r}):null]})]})}function ar({actionLabel:e="Open details",actionTitle:r,autoOpen:n=!1,className:a,details:o,icon:s,item:l,onOpen:i,preview:d,timeMeta:h,title:u,tone:m}){const f=fl(l.status),[p,g]=c.useState(n?"item-1":void 0),b=c.useRef(n);return c.useLayoutEffect(()=>{n?g("item-1"):b.current&&g(void 0),b.current=n},[n,l.id]),t.jsx("div",{className:`thread-graph-event thread-graph-history-tool ${qp(m)} ${a??""}`,children:t.jsx(kr,{type:"single",collapsible:!0,onValueChange:w=>{g(w||void 0)},className:"thread-graph-tool-accordion thread-graph-history-tool-accordion w-full overflow-hidden rounded-lg border",value:p??"",children:t.jsxs(wr,{value:"item-1",className:"border-0",children:[t.jsxs(Yr,{"aria-label":`${p==="item-1"?"Collapse":"Expand"} ${u} history item`,className:"thread-graph-tool-trigger thread-graph-history-tool-trigger px-4 py-3 hover:no-underline",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("span",{className:"thread-graph-history-tool-icon shrink-0",children:s}),t.jsx("span",{className:"min-w-0 truncate font-mono text-sm font-semibold",children:u}),t.jsxs(Qr,{variant:"outline",className:`thread-graph-tool-badge ${f.className} ml-1 sm:ml-2 rounded-full px-2 py-0.5 text-xs font-normal`,title:f.label,"aria-label":`Status: ${f.label}`,children:[f.icon,t.jsx("span",{className:"thread-graph-status-label",children:f.label})]})]}),h?t.jsx("span",{className:"thread-graph-history-tool-time shrink-0",children:h}):null]}),t.jsxs(yr,{className:"thread-graph-tool-content thread-graph-history-tool-content px-4 pb-4 pt-1",children:[t.jsxs("section",{children:[t.jsx("h4",{children:"Summary"}),t.jsxs("div",{className:"thread-graph-history-tool-summary",children:[t.jsx(rr,{text:d.firstLine}),d.showGap?t.jsx("span",{className:"thread-graph-history-tool-ellipsis",children:"..."}):null]})]}),o?t.jsx("section",{children:o}):null,t.jsxs("button",{type:"button","aria-label":e,onClick:i,className:"thread-graph-history-tool-open inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm font-medium transition",children:[t.jsx($.ExternalLink,{className:"h-3.5 w-3.5"}),r]})]})]})})})}var Yp=c.memo(function({item:r,scrollRootRef:n,onBeforeResize:a,timeMeta:o}){return t.jsx(Ot,{className:"thread-graph-event-plan",icon:t.jsx($.ClipboardList,{className:"h-4 w-4"}),item:r,timeMeta:o,title:"plan",tone:"plan",children:t.jsx("div",{className:"thread-graph-history-event-prose",children:t.jsx(ol,{text:r.text,scrollRootRef:n,plainTextClassName:"thread-graph-plain-text whitespace-pre-wrap break-words text-sm leading-6",markdownClassName:"thread-graph-markdown text-sm",...a?{onBeforeResize:a}:{}})})})}),Zp=c.memo(function({item:r,timeMeta:n}){const a=aa(r.status)||r.text==="Compacting context",o=a?"Compacting context":"Context compacted",s=r.detailText&&r.detailText!==o?r.detailText:null;return t.jsxs(Ot,{className:"thread-graph-event-context",icon:t.jsx($.Archive,{className:"h-4 w-4"}),item:r,timeMeta:n,title:"context",tone:"context",children:[t.jsxs("div",{className:"thread-graph-history-event-line",children:[t.jsx("span",{className:"thread-graph-history-event-primary",children:o}),a?t.jsx(On,{tone:"emerald"}):null]}),s?t.jsx("p",{className:"thread-graph-history-event-secondary",title:s,children:s}):null]})}),Jp=c.memo(function({item:r,timeMeta:n}){return t.jsx(Ot,{className:"thread-graph-event-generic",icon:t.jsx($.Info,{className:"h-4 w-4"}),item:r,timeMeta:n,title:r.kind,tone:"generic",children:t.jsx("pre",{className:"thread-graph-history-event-pre",children:t.jsx(rr,{text:r.text})})})}),Qp=c.memo(function({autoOpen:r,item:n,onOpen:a,timeMeta:o}){const s=gt(n.previewText??n.text);return t.jsx(ar,{actionLabel:"Open full command",actionTitle:"Command Output",autoOpen:r,className:"thread-graph-event-command",icon:t.jsx($.Terminal,{className:"h-4 w-4"}),item:n,onOpen:()=>a(n,"Command Output"),preview:s,timeMeta:o,title:"command",tone:"command"})}),ef=c.memo(function({autoOpen:r,item:n,onOpen:a,timeMeta:o}){const s=gt(n.text);return t.jsx(ar,{actionLabel:"Open full tool call",actionTitle:"Tool Call Details",autoOpen:r,className:"thread-graph-event-tool",icon:t.jsx($.Wrench,{className:"h-4 w-4"}),item:n,onOpen:()=>a(n,"Tool Call Details"),preview:s,timeMeta:o,title:"tool_call",tone:"tool"})}),tf=c.memo(function({autoOpen:r,item:n,onOpen:a,timeMeta:o}){const s=gt(n.text);return t.jsx(ar,{actionLabel:"Open agent details",actionTitle:"Agent Details",autoOpen:r,className:"thread-graph-event-agent-tool",icon:t.jsx($.Bot,{className:"h-4 w-4"}),item:n,onOpen:()=>a(n,"Agent Details"),preview:s,timeMeta:o,title:"agent",tone:"agent"})}),rf=c.memo(function({autoOpen:r,item:n,onOpen:a,timeMeta:o}){const s=gt(n.text);return t.jsx(ar,{actionLabel:"Open skill details",actionTitle:"Skill Details",autoOpen:r,className:"thread-graph-event-skill-tool",icon:t.jsx($.Sparkles,{className:"h-4 w-4"}),item:n,onOpen:()=>a(n,"Skill Details"),preview:s,timeMeta:o,title:"skill",tone:"skill"})}),nf=c.memo(function({autoOpen:r,item:n,onOpen:a,timeMeta:o}){var d,h;const s=((d=n.previewText)==null?void 0:d.trim())||n.text||"Web search",l=((h=n.detailText)==null?void 0:h.trim())||n.text||"Web search",i=gt(s);return t.jsx(ar,{actionLabel:"Open full web search",actionTitle:"Web Search Details",autoOpen:r,className:"thread-graph-event-search",icon:t.jsx($.Search,{className:"h-4 w-4"}),item:n,onOpen:()=>a("Web Search Details",l),preview:i,timeMeta:o,title:"web_search",tone:"search"})}),af=c.memo(function({autoOpen:r,item:n,onOpen:a,timeMeta:o}){var d,h;const s=((d=n.previewText)==null?void 0:d.trim())||n.text||"File read",l=((h=n.detailText)==null?void 0:h.trim())||n.text||"File read",i=gt(s);return t.jsx(ar,{actionLabel:"Open full file read",actionTitle:"File Read Details",autoOpen:r,className:"thread-graph-event-file-read",icon:t.jsx($.FileText,{className:"h-4 w-4"}),item:n,onOpen:()=>a("File Read Details",l),preview:i,timeMeta:o,title:"file_read",tone:"fileRead"})}),sf=c.memo(function({threadId:r,item:n,onOpen:a,getImageAssetUrl:o,timeMeta:s}){const l=n.assetPath??n.detailText??null,i=r&&l?(o==null?void 0:o({threadId:r,path:l}))??null:null;return t.jsxs(Ot,{className:"thread-graph-event-image",icon:t.jsx($.Image,{className:"h-4 w-4"}),item:n,timeMeta:s,title:"image",tone:"image",children:[i?t.jsx("button",{type:"button",onClick:()=>a("Image Path",l??n.text),className:"block w-full text-left",children:t.jsx("img",{src:i,alt:n.text||"Image preview",className:"thread-graph-history-event-image",loading:"lazy"})}):t.jsx("div",{className:"thread-graph-history-event-summary",children:n.text}),l?t.jsx("button",{type:"button",onClick:()=>a("Image Path",l),className:"thread-graph-history-event-path",title:l,children:l}):null]})}),of=c.memo(function({item:r,onOpen:n,timeMeta:a}){var m,f,p;const o=(m=r.previewText)!=null&&m.trim()&&r.text.trim()!==r.previewText.trim()?r.text.trim():null,s=((f=r.detailText)==null?void 0:f.trim())||null,l=pl(o??((p=r.previewText)==null?void 0:p.trim())??r.text,48),i=Vp(r),d=!!(s||r.hasDeferredDetail),h=t.jsxs("div",{className:"thread-graph-event-line thread-graph-file-change-inline flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip text-sm",title:o??l,children:l}),i.length>0&&t.jsx("div",{className:"inline-flex shrink-0 items-center justify-end gap-1.5 text-xs",children:i.map(g=>t.jsx("span",{className:`thread-graph-history-delta-badge ${g.startsWith("+")?"is-add":g.startsWith("-")?"is-remove":"is-neutral"}`,children:g},g))})]}),u=d?t.jsx("button",{type:"button","aria-label":"Open file change details",onClick:()=>n("File Change Details",s??r.text),className:"thread-graph-file-change-inline-button min-w-0 flex-1 text-left",title:o??l,children:h}):h;return t.jsx(Ot,{className:"thread-graph-event-file-change",headerMeta:u,icon:t.jsx($.FilePenLine,{className:"h-4 w-4"}),item:r,timeMeta:a,title:"file_change",tone:"fileChange"})}),lf=c.memo(function({item:r,onSelect:n,timeMeta:a}){const o=na(),[s,l]=c.useState(!1),i=r.artifact,d=i?o.renderArtifact({artifact:i,expanded:s,onToggleExpanded:()=>l(h=>!h)}):null;return t.jsx(Ot,{actions:t.jsxs("span",{className:"inline-flex items-center gap-2",children:[i&&!o.hasRendererForArtifact(i)?t.jsx("span",{className:"thread-graph-history-event-secondary",children:"No renderer"}):null,i&&n?t.jsxs("button",{type:"button","aria-label":`Open artifact inspector for ${i.title}`,onClick:()=>n(r,i),className:"thread-graph-history-event-action",children:[t.jsx($.PackageOpen,{className:"h-3.5 w-3.5"}),"Inspect"]}):null]}),className:"thread-graph-event-artifact",icon:t.jsx($.PackageOpen,{className:"h-4 w-4"}),item:r,timeMeta:a,title:(i==null?void 0:i.type)??"artifact",tone:"artifact",children:d??t.jsxs("div",{className:"space-y-2",children:[t.jsxs("button",{type:"button",onClick:()=>l(h=>!h),className:"thread-graph-history-event-summary is-clickable flex w-full items-center justify-between gap-3 text-left",children:[t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"thread-graph-history-event-primary block truncate",children:(i==null?void 0:i.title)??r.text}),t.jsx("span",{className:"thread-graph-history-event-secondary mt-1 block truncate",children:(i==null?void 0:i.summaryText)??r.previewText??r.text})]}),t.jsx("span",{className:"thread-graph-history-event-pill",children:s?"Hide":"Open"})]}),s?t.jsx("pre",{className:"thread-graph-history-event-pre max-h-80 overflow-auto",children:JSON.stringify((i==null?void 0:i.payload)??r,null,2)}):null]})})}),df=c.memo(function({item:r,timeMeta:n}){var h,u;const a=((h=r.hookOutputEntries)==null?void 0:h.map(m=>m.text.trim()).filter(Boolean).join(`
3668
- `).trim())??"",o=r.hookEventLabel?`${r.hookEventLabel} hook`:r.text,s=((u=r.hookStatusMessage)==null?void 0:u.trim())||(r.previewText&&r.previewText!==r.hookStatusMessage?r.previewText.trim():"")||r.text.trim(),i=gt(a||(s&&s!==o?s:o)),d=!!(a&&i.showGap);return t.jsx(Ot,{className:"thread-graph-event-hook",icon:t.jsx($.Webhook,{className:"h-4 w-4"}),item:r,timeMeta:n,title:r.hookEventLabel?`${r.hookEventLabel}_hook`:"hook",tone:"hook",children:t.jsxs("div",{className:"thread-graph-history-event-line",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:a?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"thread-graph-history-event-secondary mr-2 font-sans text-[11px] uppercase",children:o}),t.jsx(rr,{text:i.firstLine})]}):t.jsx(rr,{text:i.firstLine&&i.firstLine!==o?`${o} · ${i.firstLine}`:o})}),d?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})})}),cf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.filter(d=>aa(d.status)).length,i=r.length===1?"1 command":`${r.length} commands`;return t.jsx(Jr,{className:"thread-graph-history-group-command",count:r.length,countBadgeClassName:"border-amber-200/35 text-amber-100",desktopIconClassName:"border-amber-300/30 bg-amber-300/[0.14] text-amber-100",expanded:n,expandedListClassName:"border-amber-300/12",icon:t.jsx(Op,{}),onToggleExpanded:a,runningIndicator:l>0?t.jsx(On,{}):null,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-amber-300/28 bg-amber-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-amber-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:i}),l>0?t.jsx("span",{className:"inline-flex items-center text-xs text-amber-100/90",children:t.jsx(On,{})}):null]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} command entries`,children:r.map((d,h)=>{const u=gt(d.text);return t.jsxs("button",{type:"button","aria-label":`Open grouped command ${h+1}`,onClick:()=>o(d,`Command Output ${h+1}`),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("span",{className:"rounded-full border border-amber-300/18 bg-amber-300/[0.07] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-amber-100",children:["Step ",h+1]}),d.status&&t.jsx("span",{className:"thread-graph-history-detail-meta text-xs",children:d.status})]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-sm leading-6",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:u.firstLine}),u.showGap?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})]},d.id)})})}),hf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.length===1?"1 search":`${r.length} searches`;return t.jsx(Jr,{className:"thread-graph-history-group-search",count:r.length,countBadgeClassName:"border-sky-200/35 text-sky-100",desktopIconClassName:"border-sky-300/30 bg-sky-300/[0.14] text-sky-100",expanded:n,expandedListClassName:"border-sky-300/12",icon:t.jsx(Up,{}),onToggleExpanded:a,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-sky-300/28 bg-sky-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-sky-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:l})]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} web search entries`,children:r.map((i,d)=>{var f,p;const h=((f=i.previewText)==null?void 0:f.trim())||i.text||"Web search",u=gt(h),m=((p=i.detailText)==null?void 0:p.trim())||i.text||"Web search";return t.jsxs("button",{type:"button","aria-label":`Open grouped web search ${d+1}`,onClick:()=>o(`Web Search ${d+1}`,m),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("span",{className:"rounded-full border border-sky-300/18 bg-sky-300/[0.07] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-sky-100",children:["Search ",d+1]}),i.status&&t.jsx("span",{className:"thread-graph-history-detail-meta text-xs",children:i.status})]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-sm leading-6",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:u.firstLine}),u.showGap?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})]},i.id)})})}),uf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.length===1?"1 file read":`${r.length} file reads`;return t.jsx(Jr,{className:"thread-graph-history-group-file-read",count:r.length,countBadgeClassName:"border-cyan-200/35 text-cyan-100",desktopIconClassName:"border-cyan-300/30 bg-cyan-300/[0.14] text-cyan-100",expanded:n,expandedListClassName:"border-cyan-300/12",icon:t.jsx(Hp,{}),onToggleExpanded:a,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-cyan-300/28 bg-cyan-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-cyan-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:l})]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} file read entries`,children:r.map((i,d)=>{var f,p;const h=((f=i.previewText)==null?void 0:f.trim())||i.text||"File read",u=gt(h),m=((p=i.detailText)==null?void 0:p.trim())||i.text||"File read";return t.jsxs("button",{type:"button","aria-label":`Open grouped file read ${d+1}`,onClick:()=>o(`File Read ${d+1}`,m),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("span",{className:"rounded-full border border-cyan-300/18 bg-cyan-300/[0.07] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-cyan-100",children:["Read ",d+1]}),i.status&&t.jsx("span",{className:"thread-graph-history-detail-meta text-xs",children:i.status})]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-sm leading-6",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:u.firstLine}),u.showGap?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})]},i.id)})})}),mf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.reduce((u,m)=>u+(m.changedFiles??0),0),i=r.reduce((u,m)=>u+(m.addedLines??0),0),d=r.reduce((u,m)=>u+(m.removedLines??0),0),h=r.length===1?"1 file change":`${r.length} file changes`;return t.jsx(Jr,{className:"thread-graph-history-group-file-change",count:r.length,countBadgeClassName:"border-lime-200/35 text-lime-100",desktopIconClassName:"border-lime-300/30 bg-lime-300/[0.14] text-lime-100",expanded:n,expandedListClassName:"border-lime-300/12",icon:t.jsx(Fp,{}),onToggleExpanded:a,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-lime-300/28 bg-lime-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-lime-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:h}),l>0?t.jsxs("span",{className:"thread-graph-history-detail-meta text-xs",children:[l," files"]}):null]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} file change entries`,trailingSummary:t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5",children:[i>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-add",children:["+",i]}):null,d>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-remove",children:["-",d]}):null]}),children:r.map((u,m)=>{var g,b,w,x;const f=((g=u.detailText)==null?void 0:g.trim())||((b=u.previewText)==null?void 0:b.trim())||u.text,p=(w=u.previewText)!=null&&w.trim()&&u.text.trim()!==u.previewText.trim()?u.text.trim():((x=u.previewText)==null?void 0:x.trim())||u.text;return t.jsx("button",{type:"button","aria-label":`Open grouped file change ${m+1}`,onClick:()=>o(`File Change ${m+1}`,f),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"thread-graph-history-detail-text min-w-0 flex-1 text-sm leading-6",title:p,children:pl(p,34)}),t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5",children:[(u.addedLines??0)>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-add",children:["+",u.addedLines]}):null,(u.removedLines??0)>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-remove",children:["-",u.removedLines]}):null]})]})},u.id)})})});function pf(e){const r=e.trim().toLowerCase();return r==="completed"||r==="done"||r==="complete"?"completed":r==="in_progress"||r==="in-progress"||r==="running"||r==="active"?"in_progress":r==="failed"||r==="error"||r==="cancelled"?"failed":r==="pending"||r==="todo"?"pending":"unknown"}function ff({status:e}){const r=pf(e),n=r==="completed"?"Plan step status: Completed":r==="in_progress"?"Plan step status: In progress":r==="pending"?"Plan step status: Pending":r==="failed"?"Plan step status: Failed":`Plan step status: ${e}`,a=r==="completed"?"thread-graph-plan-status is-completed":r==="in_progress"?"thread-graph-plan-status is-running":r==="pending"?"thread-graph-plan-status is-pending":r==="failed"?"thread-graph-plan-status is-failed":"thread-graph-plan-status is-unknown";return t.jsx(Qr,{"aria-label":n,title:n.replace("Plan step status: ",""),className:a,children:r==="completed"?t.jsx($.CheckCircle2,{className:"h-3.5 w-3.5"}):r==="in_progress"?t.jsx($.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):r==="pending"?t.jsx($.Clock3,{className:"h-3.5 w-3.5"}):r==="failed"?t.jsx($.XCircle,{className:"h-3.5 w-3.5"}):t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.14em]",children:"?"})})}function gf({livePlan:e}){return t.jsxs("div",{className:"thread-graph-plan-card rounded-xl border px-3 py-3",children:[t.jsxs("div",{className:"thread-graph-plan-header flex flex-wrap items-center justify-between gap-2",children:[t.jsx("p",{className:"text-sm font-semibold",children:"Plan update"}),t.jsx(Qr,{className:"thread-graph-plan-badge",children:"Live"})]}),e.explanation?t.jsx("p",{className:"thread-graph-plan-explanation mt-3 text-sm",children:e.explanation}):null,t.jsx("div",{className:"mt-3 space-y-2",children:e.plan.map((r,n)=>t.jsxs("div",{className:"thread-graph-plan-step flex items-center justify-between gap-3 rounded-lg border px-3 py-2 text-sm",children:[t.jsx("span",{className:"thread-graph-plan-step-text min-w-0 flex-1",children:r.step}),t.jsx(ff,{status:r.status})]},`${e.turnId}-${n}`))})]})}function xf({footer:e,history:r,liveHookPrompt:n,liveOutput:a,livePlan:o}){return t.jsxs(t.Fragment,{children:[r,o?t.jsx(gf,{livePlan:o}):null,n??a??null,e]})}function bf({absoluteIndex:e,body:r,collapsed:n,collapsedBody:a,error:o,footer:s,headerStatus:l,isActive:i=!1,onToggleCollapse:d,refCallback:h,startedAt:u,timeLabel:m,timeTitle:f,tokenSummary:p}){return t.jsxs("article",{ref:h,"data-testid":"chat-turn","data-turn-active":i?"true":"false",className:"thread-graph-turn px-3 py-2 sm:px-5 sm:py-3",children:[t.jsxs("div",{className:"thread-graph-turn-header flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0 flex flex-1 items-start gap-1.5",children:[t.jsxs("div",{className:"min-w-0 flex flex-1 items-center gap-1.5 overflow-hidden",children:[t.jsxs("span",{className:"thread-graph-turn-index rounded-[0.6rem] border px-1.5 py-0.5 text-[10px] uppercase tracking-[0.16em]",children:["Turn ",e]}),t.jsx("time",{dateTime:u??void 0,title:f,className:"thread-graph-turn-time shrink-0 text-[10px] sm:text-[11px]",children:m}),l,o?t.jsx("p",{className:"hidden truncate text-[11px] text-rose-200 sm:block",children:o}):null]}),p]}),t.jsx("button",{type:"button","aria-label":`${n?"Expand":"Collapse"} turn ${e}`,title:n?"Expand turn":"Collapse turn",onClick:d,className:"thread-graph-turn-collapse inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-md transition",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:n?t.jsx("path",{d:"m4.5 10 3.5-3.5L11.5 10"}):t.jsx("path",{d:"m4.5 6 3.5 3.5L11.5 6"})})})]}),o?t.jsx("p",{className:"mt-1 text-[11px] text-rose-200 sm:hidden",children:o}):null,t.jsxs("div",{className:"thread-graph-turn-body mt-2 space-y-2",children:[n?a:r,n?null:s]})]})}function vf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M8 2.75v8"}),t.jsx("path",{d:"m4.75 7.5 3.25 3.25L11.25 7.5"})]})}function kf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M8 13.25v-8"}),t.jsx("path",{d:"m11.25 8.5-3.25-3.25L4.75 8.5"})]})}function wf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.45",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M3.25 5.25 8 2.75l4.75 2.5L8 7.75l-4.75-2.5Z"}),t.jsx("path",{d:"M3.25 8 8 10.5 12.75 8"}),t.jsx("path",{d:"M3.25 10.75 8 13.25l4.75-2.5"}),t.jsx("path",{d:"M3.25 5.25v5.5"}),t.jsx("path",{d:"M12.75 5.25v5.5"})]})}function yf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.45",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M6.2 3.2a2.3 2.3 0 0 0-2.95 3.5A2.4 2.4 0 0 0 4.5 11h.2c.25 1.1 1.1 1.8 2.3 1.8h1.8c1.2 0 2.05-.7 2.3-1.8h.2A2.4 2.4 0 0 0 12.75 6.7 2.3 2.3 0 0 0 9.8 3.2"}),t.jsx("path",{d:"M6.3 6.15c.45-.42 1.02-.65 1.7-.65s1.25.23 1.7.65"}),t.jsx("path",{d:"M8 5.5v4.75"}),t.jsx("path",{d:"M6.75 9.05 8 10.25l1.25-1.2"})]})}function Pr(e){if(!Number.isFinite(e)||e<=0)return"0";if(e>=1e6){const r=e>=1e7?Math.round(e/1e6):e/1e6;return`${String(r.toFixed(1)).replace(/\.0$/,"")}m`}if(e>=1e3){const r=e>=1e4?Math.round(e/1e3):e/1e3;return`${String(r.toFixed(1)).replace(/\.0$/,"")}k`}return String(Math.round(e))}function sa(e){return!Number.isFinite(e)||e<=0?"$0":e>=100?`$${Math.round(e)}`:e>=10?`$${String(e.toFixed(1)).replace(/\.0$/,"")}`:e>=1?`$${String(e.toFixed(2)).replace(/0$/,"").replace(/\.$/,"")}`:e>=.1?`$${e.toFixed(2)}`:e>=.01?`$${e.toFixed(3)}`:e>=.001?`$${e.toFixed(4)}`:"<$0.001"}function ur(e){return!Number.isFinite(e)||e<=0?"$0.0000":`$${e.toFixed(4)}`}function zr(e,r,n){const a=e??null;return!Number.isFinite(a??NaN)||a===null||r<=0||n<=0?null:a*n/r}function gl(e){var i,d,h,u,m;const r=(i=e.tokenUsage)==null?void 0:i.total;if(!r)return[];const n=Math.max(r.inputTokens-r.cachedInputTokens,0),a=Math.max(r.cachedInputTokens,0),o=Math.max(r.reasoningOutputTokens,0),s=Math.max(r.outputTokens-o,0);return[n>0?{id:"in",label:"Input",tokenCompactValue:Pr(n),tokenRawValue:n,usdCompactValue:e.priceEstimate?ur(e.priceEstimate.inputUsd):"--",usdRawValue:((d=e.priceEstimate)==null?void 0:d.inputUsd)??null,className:"token-badge-in",icon:t.jsx(vf,{})}:null,a>0?{id:"cache",label:"Cached input",tokenCompactValue:Pr(a),tokenRawValue:a,usdCompactValue:e.priceEstimate?ur(e.priceEstimate.cachedInputUsd):"--",usdRawValue:((h=e.priceEstimate)==null?void 0:h.cachedInputUsd)??null,className:"token-badge-cache",icon:t.jsx(wf,{})}:null,s>0?{id:"out",label:"Output",tokenCompactValue:Pr(s),tokenRawValue:s,usdCompactValue:e.priceEstimate?ur(zr(e.priceEstimate.outputUsd,Math.max(r.outputTokens,0),s)??0):"--",usdRawValue:zr((u=e.priceEstimate)==null?void 0:u.outputUsd,Math.max(r.outputTokens,0),s),className:"token-badge-out",icon:t.jsx(kf,{})}:null,o>0?{id:"reason",label:"Reasoning",tokenCompactValue:Pr(o),tokenRawValue:o,usdCompactValue:e.priceEstimate?ur(zr(e.priceEstimate.outputUsd,Math.max(r.outputTokens,0),o)??0):"--",usdRawValue:zr((m=e.priceEstimate)==null?void 0:m.outputUsd,Math.max(r.outputTokens,0),o),className:"token-badge-reason",icon:t.jsx(yf,{})}:null].filter(f=>f!==null)}function jf(e){return gl(e).map(r=>({id:r.id,label:r.tokenCompactValue,title:`${r.label}: ${r.tokenRawValue} tokens`,className:r.className,icon:r.icon}))}function xl(e){return{label:e.priceEstimate?sa(e.priceEstimate.totalUsd):"--",title:e.priceEstimate===null||e.priceEstimate===void 0?"Price estimate unavailable for this model.":`Estimated cost: ${ur(e.priceEstimate.totalUsd)}`,className:e.priceEstimate?"token-badge-total":"token-badge-empty"}}var xn="inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-normal leading-none sm:text-[11px]";function Nf({turn:e}){const r=gl(e),n=xl(e),[a,o]=c.useState(!1),[s,l]=c.useState(!1),[i,d]=c.useState(0),h=c.useRef(null),u=c.useRef(null),m=c.useRef(null);if(c.useLayoutEffect(()=>{if(!a||r.length===0){d(0);return}const p=()=>{const g=h.current,b=m.current;if(!g||!b)return;const w=g.getBoundingClientRect(),x=b.offsetWidth||b.getBoundingClientRect().width;if(x<=0)return;const j=window.innerWidth||document.documentElement.clientWidth,k=12,y=w.left+w.width/2-x/2,v=k,N=Math.max(v,j-k-x),S=Math.min(Math.max(y,v),N);d(Math.round(S-y))};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[r.length,a]),c.useEffect(()=>{if(!a&&!s)return;const p=g=>{g.target instanceof Node&&(h.current&&!h.current.contains(g.target)&&o(!1),u.current&&!u.current.contains(g.target)&&l(!1))};return document.addEventListener("pointerdown",p),()=>{document.removeEventListener("pointerdown",p)}},[s,a]),!n&&r.length===0)return null;const f=()=>t.jsx("div",{className:"thread-token-popover min-w-[12rem] rounded-2xl border p-2.5 shadow-2xl shadow-black/20 backdrop-blur",children:t.jsx("div",{className:"space-y-1",children:r.map(p=>t.jsxs("div",{className:"thread-token-popover-row flex items-center justify-between gap-3 rounded-xl border px-2.5 py-1.5 text-[11px]",title:`${p.label}: ${p.tokenRawValue} tokens`,children:[t.jsxs("span",{className:"thread-token-popover-text inline-flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"inline-flex shrink-0",children:p.icon}),t.jsx("span",{className:"thread-token-popover-strong font-medium",children:p.usdCompactValue})]}),t.jsx("span",{className:"thread-token-popover-text shrink-0 font-medium",children:p.tokenCompactValue})]},p.id))})});return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"hidden shrink-0 items-center gap-1.5 md:inline-flex",children:[n?t.jsxs("div",{ref:u,className:"relative shrink-0",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),children:[t.jsx("button",{type:"button","aria-label":"Show token and price details","aria-expanded":s,onFocus:()=>l(!0),onBlur:()=>l(!1),className:`${xn} appearance-none whitespace-nowrap bg-transparent !text-[10px] !font-normal !leading-none transition hover:bg-[var(--theme-hover)] sm:!text-[11px] ${n.className}`,title:n.title,children:n.label}),s&&r.length>0?t.jsx("div",{className:"absolute left-1/2 top-full z-30 mt-1.5 -translate-x-1/2",children:f()}):null]}):null,r.map(p=>t.jsxs("span",{className:`${xn} ${p.className}`,title:`${p.label}: ${p.usdCompactValue}, ${p.tokenRawValue} tokens`,children:[p.icon,t.jsx("span",{className:"thread-token-badge-value font-medium",children:p.tokenCompactValue})]},p.id))]}),t.jsxs("div",{ref:h,className:"relative shrink-0 md:hidden",children:[n?t.jsx("button",{type:"button","aria-label":"Show token and price details","aria-expanded":a,onClick:()=>o(p=>!p),className:`${xn} appearance-none whitespace-nowrap bg-transparent !text-[10px] !font-normal !leading-none transition hover:bg-[var(--theme-hover)] sm:!text-[11px] ${n.className}`,title:n.title,children:n.label}):null,a&&r.length>0?t.jsx("div",{ref:m,className:"absolute left-1/2 top-full z-30 mt-1.5",style:{transform:`translateX(${i}px) translateX(-50%)`},children:f()}):null]})]})}function Cf({tone:e="amber"}){const r=e==="emerald"?"bg-sky-200/90":e==="sky"?"bg-sky-300/90":"bg-amber-200/90";return t.jsx("span",{className:"ml-1.5 inline-flex items-center gap-1","aria-hidden":"true",children:[0,1,2].map(n=>t.jsx("span",{className:`h-1.5 w-1.5 rounded-full animate-pulse ${r}`,style:{animationDelay:`${n*180}ms`}},n))})}function ys(e){const r=e.trim().toLowerCase();return r==="completed"||r==="done"||r==="complete"?"completed":r==="in_progress"||r==="in progress"||r==="inprogress"||r==="running"||r==="active"?"in_progress":r==="pending"||r==="todo"||r==="not_started"||r==="not started"||r==="queued"?"pending":r==="failed"||r==="error"?"failed":"other"}function Sf(e){switch(e.kind){case"fileChange":case"webSearch":case"image":case"contextCompaction":return!0;case"commandExecution":case"toolCall":return!il(e.status);default:return!1}}function Tf(e,r,n){if(!e||!mr(n))return e;const a=e.plan.findIndex(i=>ys(i.status)==="in_progress");if(a<0)return e;const o=e.plan.findIndex((i,d)=>d>a&&ys(i.status)==="pending");if(o<0||!r.some(i=>Sf(i)))return e;const l=e.plan.map((i,d)=>d===a?{...i,status:"completed"}:d===o?{...i,status:"in_progress"}:i);return{...e,plan:l}}function Ef(e){var a;const r=(a=e.model)!=null&&a.trim()?e.model.trim():"--";let n="--";return e.reasoningEffortAvailable===null||e.reasoningEffortAvailable===void 0?n="--":e.reasoningEffortAvailable===!1?n="-":n=e.reasoningEffort??"--",[r,n].join(" · ")}function js({status:e}){const r=rl(e);return e==="completed"?t.jsx("span",{"aria-label":r,title:r,className:"timeline-status-icon timeline-status-icon-success inline-flex h-4 w-4 items-center justify-center",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"m3.75 8.25 2.5 2.5 6-6"})})}):e==="failed"?t.jsx("span",{"aria-label":r,title:r,className:"timeline-status-icon timeline-status-icon-failed inline-flex h-4 w-4 items-center justify-center",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"m5 5 6 6M11 5l-6 6"})})}):e==="interrupted"?t.jsx("span",{"aria-label":r,title:r,className:"timeline-status-icon timeline-status-icon-warning inline-flex h-4 w-4 items-center justify-center",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M6 4.5v7M10 4.5v7"})})}):t.jsx("span",{"aria-label":r,title:r,className:"inline-flex min-w-[1.25rem] items-center justify-center text-sky-200",children:t.jsx(Cf,{tone:"emerald"})})}function Ns({turn:e,variant:r="header"}){const n=rl(e.status),a=Ef(e),o=jf(e),s=xl(e),l=mr(e.status),i=e.status==="failed"?"border-rose-300/20 bg-rose-300/[0.06] text-rose-100":l?"border-sky-300/22 bg-sky-300/[0.08] text-sky-100":"border-stone-700/90 bg-stone-900/70 text-stone-200";if(r==="footer")return t.jsxs("div",{className:`flex w-full flex-col gap-1.5 rounded-[0.95rem] border px-3 py-2 text-xs ${i}`,children:[t.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(js,{status:e.status}),t.jsx("span",{className:"timeline-soft-text min-w-0 truncate",children:a})]}),e.startedAt&&t.jsx("time",{dateTime:e.startedAt,title:Gt(e.startedAt),className:"timeline-meta-text shrink-0 text-[11px]",children:ft(e.startedAt)})]}),(s||o.length>0)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pl-6",children:[s?t.jsx("span",{className:`inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${s.className}`,title:s.title,children:s.label}):null,o.map(h=>t.jsxs("span",{className:`inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${h.className}`,title:h.title,children:[h.icon?t.jsx("span",{className:"mr-1",children:h.icon}):null,h.label]},h.id))]})]});const d=`${n} · ${a}`;return t.jsxs("span",{className:`inline-flex min-w-0 items-center gap-1.5 rounded-full border px-2 py-1 text-[10px] sm:text-[11px] ${i}`,title:d,children:[t.jsx(js,{status:e.status}),t.jsx("span",{className:"timeline-meta-text min-w-0 truncate",children:a})]})}function Lf(e,r){return e.createdAt??r}var oa=c.memo(function({threadId:r,item:n,scrollRootRef:a,onOpenExpandedText:o,onOpenCommandDetail:s,onOpenToolCallDetail:l,onOpenDeferredHistoryItemDetail:i,onSelectArtifact:d,onBeforeMessageResize:h,adapter:u,timeLabel:m,timeTitle:f,timeMeta:p,autoOpenToolDetails:g=!1}){var b,w,x;if(Ep(n.kind))return t.jsx(Et,{threadId:r,item:n,scrollRootRef:a,timeLabel:m,timeTitle:f,...h?{onBeforeMessageResize:h}:{},...u?{adapter:u}:{}});if(n.kind==="reasoning")return t.jsx(Et,{item:{...n,kind:"agentMessage",status:n.status??null},scrollRootRef:a,timeLabel:m,timeTitle:f,...h?{onBeforeMessageResize:h}:{}});if(n.kind==="artifact")return t.jsx(lf,{item:n,timeMeta:p,...d?{onSelect:(j,k)=>d({item:j,artifact:k})}:{}});if(n.kind==="commandExecution")return t.jsx(Qp,{autoOpen:g,item:n,onOpen:s,timeMeta:p});if(n.kind==="toolCall")return t.jsx(ef,{autoOpen:g,item:n,onOpen:l,timeMeta:p});if(n.kind==="agentToolCall")return t.jsx(tf,{autoOpen:g,item:n,onOpen:l,timeMeta:p});if(n.kind==="skillToolCall")return t.jsx(rf,{autoOpen:g,item:n,onOpen:l,timeMeta:p});if(n.kind==="webSearch"){const j=n,k=((b=j.detailText)==null?void 0:b.trim())||j.text||"Web search";return t.jsx(nf,{autoOpen:g,item:j,timeMeta:p,onOpen:()=>i(j,"Web Search Details",k,"Loading full web search details...","Unable to load full web search details.")})}if(n.kind==="fileRead"){const j=n,k=((w=j.detailText)==null?void 0:w.trim())||j.text||"File read";return t.jsx(af,{autoOpen:g,item:j,timeMeta:p,onOpen:()=>i(j,"File Read Details",k,"Loading full file read details...","Unable to load full file read details.")})}if(n.kind==="image")return t.jsx(sf,{threadId:r,item:n,onOpen:o,getImageAssetUrl:u==null?void 0:u.getImageAssetUrl,timeMeta:p});if(n.kind==="plan")return t.jsx(Yp,{item:n,scrollRootRef:a,timeMeta:p,...h?{onBeforeResize:h}:{}});if(n.kind==="fileChange"){const j=n,k=((x=j.detailText)==null?void 0:x.trim())||j.text||"File change";return t.jsx(of,{item:j,timeMeta:p,onOpen:()=>i(j,"File Change Details",k,"Loading full file change details...","Unable to load full file change details.")})}return n.kind==="contextCompaction"?t.jsx(Zp,{item:n,timeMeta:p}):n.kind==="hook"?t.jsx(df,{item:n,timeMeta:p}):t.jsx(Jp,{item:n,timeMeta:p})});function Cs(e){return e==="completed"||e==="failed"||e==="interrupted"}function Pf(e){const r=Date.parse(e.createdAt??"");return Number.isFinite(r)?r:null}function zf(e){let r=null;for(const n of e){const a=Pf(n);a!==null&&(r=r===null?a:Math.max(r,a))}return r}function If(e,r){const n=Date.parse(e??""),a=zf(r);if(!Number.isFinite(n)||a===null||a<n)return"Worked";const o=Math.max(1,Math.round((a-n)/1e3)),s=Math.floor(o/3600),l=Math.floor(o%3600/60),i=o%60;return s>0?`Worked for ${s}h ${l}m`:l>0?`Worked for ${l}m ${i}s`:`Worked for ${i}s`}function Rf(e,r){const n=Date.parse(e??""),a=Date.parse(r??"");if(!Number.isFinite(n)||!Number.isFinite(a))return r?ft(r):"Time unavailable";const o=Math.max(0,Math.round((a-n)/1e3)),s=Math.floor(o/3600),l=Math.floor(o%3600/60),i=o%60;return s>0?`${s}h ${l}m`:l>0?`${l}m ${i}s`:`${i}s`}function fr({absoluteLabel:e,className:r="",timestamp:n,turnStartedAt:a}){const[o,s]=c.useState(!1);if(!n)return null;const l=Gt(n),i=Rf(a,n),d=o?e:i;return t.jsx("span",{role:"button",tabIndex:0,className:`thread-graph-relative-time rounded-full px-1.5 py-0.5 text-[10px] leading-none transition sm:text-[11px] ${r}`,title:o?i:l,"aria-label":`Toggle timestamp, currently ${d}`,onClick:h=>{h.stopPropagation(),s(u=>!u)},onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),h.stopPropagation(),s(u=>!u))},children:t.jsx("time",{dateTime:n,children:d})})}function Ir(e){var r;return e.kind==="item"?e.item.createdAt??null:((r=e.items.find(n=>n.createdAt))==null?void 0:r.createdAt)??null}function Af(e){const r=e.filter(s=>s.kind==="item"),n=r.map(s=>s.item).filter(s=>s.kind==="userMessage"),a=r.map(s=>s.item).reverse().find(s=>s.kind==="agentMessage"&&s.text.trim().length>0),o=e.filter(s=>s.kind!=="item"?!0:s.item.kind!=="userMessage"&&s.item.id!==(a==null?void 0:a.id));return{users:n,finalAgent:a,hiddenEntries:o}}var bn=c.memo(function({threadId:r,adapter:n,turn:a,absoluteIndex:o,isCollapsed:s,livePlan:l,liveItems:i,liveOutput:d,forceActive:h=!1,onToggleCollapse:u,onOpenExpandedText:m,onOpenCommandDetail:f,onOpenToolCallDetail:p,onOpenDeferredHistoryItemDetail:g,onSelectArtifact:b,onBeforeMessageResize:w,scrollRootRef:x,articleRef:j,isLatestVisibleTurn:k=!1}){const y=!!l||!!d||!!(i&&i.length>0),v=h||mr(a.status)||y||k,N=v&&!mr(a.status)?{...a,status:"inProgress"}:a,S=c.useMemo(()=>Ip(a.items,i),[i,a.items]),L=c.useMemo(()=>Tf(l,S,a.status),[l,S,a.status]),z=c.useMemo(()=>Rp(d,S),[d,S]),V=c.useMemo(()=>zp(S,v),[v,S]),F=c.useMemo(()=>Ap(V),[V]),B=h||mr(a.status)||y,J=ft(a.startedAt),Z=Gt(a.startedAt),D=c.useMemo(()=>ll(z),[z]),[ee,oe]=c.useState({}),A=c.useCallback(K=>{oe(le=>({...le,[K]:!le[K]}))},[]),Q=t.jsx(_f,{entries:F,expandedGroups:ee,onToggleGroupedItem:A,threadId:r,scrollRootRef:x,onOpenExpandedText:m,onOpenCommandDetail:f,onOpenToolCallDetail:p,onOpenDeferredHistoryItemDetail:g,...w?{onBeforeMessageResize:w}:{},fallbackTimestamp:a.startedAt,fallbackTimeLabel:J,fallbackTimeTitle:Z,turnStartedAt:a.startedAt,autoOpenLatestToolDetails:B,...b?{onSelectArtifact:b}:{},...n?{adapter:n}:{}}),R=D?t.jsx(oa,{threadId:r,item:D,scrollRootRef:x,onOpenExpandedText:m,onOpenCommandDetail:f,onOpenToolCallDetail:p,onOpenDeferredHistoryItemDetail:g,timeLabel:a.startedAt?t.jsx(fr,{absoluteLabel:J,timestamp:a.startedAt,turnStartedAt:a.startedAt}):J,timeTitle:Z,timeMeta:null,...b?{onSelectArtifact:b}:{},...n?{adapter:n}:{}}):null,q=!D&&z?t.jsx(Et,{item:{id:"live-agent-message",kind:"agentMessage",text:z},scrollRootRef:x,timeLabel:a.startedAt?t.jsx(fr,{absoluteLabel:J,timestamp:a.startedAt,turnStartedAt:a.startedAt}):J,timeTitle:Z,streaming:!0,...w?{onBeforeMessageResize:w}:{}}):null,O=v?t.jsx(Ns,{turn:N,variant:"footer"}):null,T=c.useMemo(()=>Af(F),[F]),U=c.useMemo(()=>If(a.startedAt,S),[S,a.startedAt]),H=T.hiddenEntries.length>0,C=s&&H,X=Cs(a.status)&&H&&!C?t.jsxs("button",{type:"button",className:"thread-graph-worked-summary group flex w-full items-center gap-2 py-2 text-left text-sm transition",onClick:()=>u(a.id,!1),"aria-label":`${U}. Collapse turn ${o}`,children:[t.jsx("span",{className:"thread-graph-worked-label shrink-0",children:U}),t.jsx($.ChevronDown,{className:"h-4 w-4 shrink-0 transition group-hover:translate-y-0.5"}),t.jsx("span",{className:"thread-graph-worked-rule h-px min-w-0 flex-1","aria-hidden":"true"})]}):null,Y=Cs(a.status)&&H?t.jsxs("div",{className:"thread-graph-turn-collapsed-summary space-y-2",children:[T.users.map(K=>t.jsx(Et,{threadId:r,item:K,scrollRootRef:x,timeLabel:K.createdAt?ft(K.createdAt):J,timeTitle:K.createdAt?Gt(K.createdAt):Z,...w?{onBeforeMessageResize:w}:{},...n?{adapter:n}:{}},K.id)),t.jsxs("button",{type:"button",className:"thread-graph-worked-summary group flex w-full items-center gap-2 py-2 text-left text-sm transition",onClick:()=>u(a.id,!0),"aria-label":`${U}. Expand turn ${o}`,children:[t.jsx("span",{className:"thread-graph-worked-label shrink-0",children:U}),t.jsx($.ChevronRight,{className:"h-4 w-4 shrink-0 transition group-hover:translate-x-0.5"}),t.jsx("span",{className:"thread-graph-worked-rule h-px min-w-0 flex-1","aria-hidden":"true"})]}),T.finalAgent?t.jsx(Et,{threadId:r,item:T.finalAgent,scrollRootRef:x,timeLabel:T.finalAgent.createdAt?t.jsx(fr,{absoluteLabel:ft(T.finalAgent.createdAt),timestamp:T.finalAgent.createdAt,turnStartedAt:a.startedAt}):J,timeTitle:T.finalAgent.createdAt?Gt(T.finalAgent.createdAt):Z,...w?{onBeforeMessageResize:w}:{},...n?{adapter:n}:{}}):null]}):null,ie=t.jsx(xf,{footer:O,history:t.jsxs(t.Fragment,{children:[X,Q]}),liveHookPrompt:R,liveOutput:q,livePlan:L});return t.jsx(bf,{absoluteIndex:o,body:ie,collapsed:C,collapsedBody:Y,error:a.error,headerStatus:t.jsx(Ns,{turn:a}),isActive:v,onToggleCollapse:()=>u(a.id,C),refCallback:j,startedAt:a.startedAt,timeLabel:J,timeTitle:Z,tokenSummary:t.jsx(Nf,{turn:a})})});function _f({entries:e,expandedGroups:r,onToggleGroupedItem:n,threadId:a,scrollRootRef:o,onOpenExpandedText:s,onOpenCommandDetail:l,onOpenToolCallDetail:i,onOpenDeferredHistoryItemDetail:d,onSelectArtifact:h,onBeforeMessageResize:u,adapter:m,fallbackTimestamp:f,fallbackTimeLabel:p,fallbackTimeTitle:g,turnStartedAt:b,autoOpenLatestToolDetails:w=!1}){var k;const x=((k=e.at(-1))==null?void 0:k.key)??null,j=c.useCallback(y=>y?t.jsx(fr,{absoluteLabel:ft(y),timestamp:y,turnStartedAt:b??f}):null,[f,b]);return t.jsx(Bp,{entries:e,expandedGroups:r,onToggleGroupedItem:n,renderCommandGroup:(y,v,N)=>t.jsx(cf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:l,timeMeta:j(Ir(y))},y.key),renderFileChangeGroup:(y,v,N)=>t.jsx(mf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:s,timeMeta:j(Ir(y))},y.key),renderSearchGroup:(y,v,N)=>t.jsx(hf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:s,timeMeta:j(Ir(y))},y.key),renderFileReadGroup:(y,v,N)=>t.jsx(uf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:s,timeMeta:j(Ir(y))},y.key),renderItem:y=>{const v=Lf(y.item,f??null),S=y.item.kind==="userMessage"?y.item.createdAt?ft(v):p:y.item.createdAt?t.jsx(fr,{absoluteLabel:ft(v),timestamp:v,turnStartedAt:b??f}):p;return t.jsx(oa,{threadId:a,item:y.item,scrollRootRef:o,timeLabel:S,timeTitle:y.item.createdAt?Gt(v):g,timeMeta:j(v),autoOpenToolDetails:w&&y.key===x,onOpenExpandedText:s,onOpenCommandDetail:l,onOpenToolCallDetail:i,onOpenDeferredHistoryItemDetail:d,...u?{onBeforeMessageResize:u}:{},...h?{onSelectArtifact:h}:{},...m?{adapter:m}:{}},y.key)}})}var Ss=3,Mf=3,Un=80;function dr(e,r=Un){return e.scrollHeight-e.scrollTop-e.clientHeight<=r}function $f(e,r){const n=e.getBoundingClientRect(),a=r.getBoundingClientRect(),o=Math.max(n.top,a.top),s=Math.min(n.bottom,a.bottom);return Math.max(0,s-o)>0}function Df(e){return e.map(n=>{const a=n.createdAt;return typeof a=="string"&&a.trim()?a:null}).filter(n=>!!n).sort()[0]??null}function Bf(e,r){return{id:e,startedAt:Df(r),status:"inProgress",error:null,model:null,reasoningEffort:null,reasoningEffortAvailable:null,tokenUsage:null,priceEstimate:null,items:[]}}function Ts(e,r,n){return{id:e.id,kind:e.kind,title:r,text:n}}function Gf({loadHistoryItemDetail:e,onSelectHistoryItemDetail:r}){const n=c.useRef(0),a=c.useRef(new Map),[o,s]=c.useState(null),l=c.useCallback((p,g)=>{s({title:p,text:g})},[]),i=c.useCallback((p,g,b)=>{if(b&&r){r({item:p,detail:g});return}s({title:g.title,text:g.text})},[r]),d=c.useCallback(async({item:p,fallbackTitle:g,fallbackText:b,loadingText:w,errorText:x,useSelectionCallback:j})=>{if(!p.hasDeferredDetail||!e){i(p,Ts(p,g,b),j);return}const k=a.current.get(p.id);if(k){i(p,k,j);return}const y=n.current+1;n.current=y,j&&r||s({title:g,text:w});try{const v=await e(p.id);if(a.current.set(p.id,v),n.current!==y)return;i(p,v,j)}catch(v){if(n.current!==y)return;i(p,Ts(p,g,v instanceof Error?v.message:x),j)}},[e,r,i]),h=c.useCallback(async(p,g)=>{var b;await d({item:p,fallbackTitle:g,fallbackText:((b=p.detailText)==null?void 0:b.trim())||p.text||"Command output",loadingText:"Loading full command output...",errorText:"Unable to load full command output.",useSelectionCallback:!0})},[d]),u=c.useCallback(async(p,g)=>{var b;await d({item:p,fallbackTitle:g,fallbackText:((b=p.detailText)==null?void 0:b.trim())||p.text||"Tool call",loadingText:"Loading full tool call details...",errorText:"Unable to load full tool call details.",useSelectionCallback:!0})},[d]),m=c.useCallback(async(p,g,b,w,x)=>{await d({item:p,fallbackTitle:g,fallbackText:b,loadingText:w,errorText:x,useSelectionCallback:!1})},[d]),f=c.useCallback(()=>{n.current+=1,s(null)},[]);return{expandedText:o,openExpandedText:l,openCommandDetail:h,openToolCallDetail:u,openDeferredHistoryItemDetail:m,closeExpandedText:f}}function Ff(e){const r=c.useRef(null),n=c.useRef(0),a=r.current;return(a===null||a.length!==e.length||e.some((s,l)=>!Object.is(s,a[l])))&&(n.current+=1,r.current=e),n.current}function Hf({threadId:e,turnsLength:r,totalTurnCount:n,loadingEarlier:a,onLoadEarlier:o,scrollRequestKey:s,bottomSpacer:l,onTailVisibilityChange:i,contentRevisionInputs:d}){const h=c.useRef(null),u=c.useRef(null),m=c.useRef(s),f=c.useRef(null),p=c.useRef(l),g=c.useRef(0),b=c.useRef(0),w=c.useRef(null),x=c.useRef(null),j=c.useRef(null),k=c.useRef(!0),y=c.useRef(!0),v=c.useRef(!1),N=c.useRef(!1),S=c.useRef(!1),L=c.useRef(!1),z=c.useRef(null),V=c.useRef(0),[F,B]=c.useState(Ss),[J,Z]=c.useState(0),[D,ee]=c.useState(!0),oe=Ff(d),A=typeof o=="function"||n!==void 0,Q=n??r,R=A?0:Math.max(0,r-F),O=(A?Math.max(0,Q-r):0)+R,T=A?r:r-R,U=A?0:r-T,H=A?Math.max(0,Q-r):0,C=A?H+U:U,E=!A&&C>0&&J>=2,X=A&&H>0&&U===0&&typeof o=="function",Y=c.useCallback(()=>{const G=h.current;if(!G){w.current=null;return}w.current={scrollHeight:G.scrollHeight,scrollTop:G.scrollTop}},[]),ie=c.useCallback(()=>!X||a||S.current?!1:(Y(),S.current=!0,L.current=!1,V.current=0,o==null||o(),!0),[X,a,o,Y]),K=c.useCallback(()=>{const G=h.current,me=x.current;if(!G)return;const fe=me?$f(G,me):dr(G);k.current=fe,ee(we=>we===fe?we:fe)},[]),le=c.useCallback(()=>{const G=h.current;if(G){N.current=!0;const me=G.scrollTop,fe=b.current,we=me-fe;b.current=me,dr(G,1)?(v.current=!1,y.current=!0):we<-1?(v.current=!0,y.current=!1):we>1&&(y.current=!v.current&&dr(G,Un)),me<=0&&N.current?L.current=!0:me>0&&(L.current=!1,V.current=0)}K()},[K]),te=c.useCallback(()=>{const G=h.current;G&&(G.scrollTop=G.scrollHeight,b.current=G.scrollTop,g.current=G.scrollHeight,k.current=!0,ee(me=>me||!0),v.current=!1,y.current=!0)},[]),ge=c.useCallback(()=>{const G=h.current;G&&(b.current=G.scrollTop,g.current=G.scrollHeight,y.current=!1,v.current=!0)},[]),de=c.useCallback(()=>{if(A&&U===0){ie();return}B(G=>Math.min(r,G+Mf)),Z(G=>G+1)},[U,A,ie,r]),be=c.useCallback(G=>{const me=h.current;if(!(!me||G.deltaY>=-8||me.scrollTop>0||!X)){if(!L.current){L.current=!0;return}ie()}},[X,ie]),ze=c.useCallback(G=>{var me;z.current=((me=G.touches.item(0))==null?void 0:me.clientY)??null,V.current=0},[]),se=c.useCallback(G=>{var Ae;const me=h.current,fe=((Ae=G.touches.item(0))==null?void 0:Ae.clientY)??null,we=z.current;if(z.current=fe,!me||fe===null||we===null||me.scrollTop>0||!X){V.current=0;return}const Me=fe-we;if(Me<=0){V.current=0;return}if(!L.current){L.current=!0,V.current=0;return}V.current+=Me,V.current>=28&&ie()},[X,ie]),ye=c.useCallback(()=>{z.current=null,V.current=0},[]),je=c.useCallback(()=>{B(r)},[r]);return c.useLayoutEffect(()=>{const G=window.requestAnimationFrame(()=>{te()});return()=>{window.cancelAnimationFrame(G)}},[e,te]),c.useEffect(()=>{S.current=!1,N.current=!1,L.current=!1,w.current=null},[e]),c.useEffect(()=>{a||(S.current=!1)},[a,r]),c.useLayoutEffect(()=>{const G=w.current,me=h.current;if(!G||!me||a)return;w.current=null;const fe=me.scrollHeight-G.scrollHeight;if(fe<=0){g.current=me.scrollHeight,b.current=me.scrollTop;return}const we=G.scrollTop+fe;me.scrollTop=we,b.current=we,g.current=me.scrollHeight,v.current=!0,y.current=!1,L.current=!1},[a,r]),c.useEffect(()=>{B(G=>G>=r-1?r:Math.max(G,Ss))},[r]),c.useEffect(()=>{const G=h.current;G&&(g.current=G.scrollHeight,b.current=G.scrollTop,dr(G,1)?(v.current=!1,y.current=!0):(v.current||!dr(G,Un))&&(y.current=!1)),K()},[oe,K,F]),c.useEffect(()=>{const G=s!==m.current,me=f.current!==oe;if(f.current=oe,!(G||me&&y.current&&!v.current))return;const we=window.requestAnimationFrame(()=>{te()});return s!==m.current&&(m.current=s),()=>{window.cancelAnimationFrame(we)}},[oe,D,te,s]),c.useEffect(()=>{const G=h.current,me=u.current;if(!G||!me||typeof ResizeObserver>"u")return;g.current=G.scrollHeight;const fe=new ResizeObserver(()=>{const we=G.scrollHeight,Me=g.current;if(g.current=we,we<=Me)return;const Ae=Me>0&&Me-G.scrollTop-G.clientHeight<=1;v.current||!(y.current||Ae||k.current)||window.requestAnimationFrame(()=>{te()})});return fe.observe(me),()=>{fe.disconnect()}},[te]),c.useEffect(()=>{if(!y.current||v.current){p.current=l;return}if(l===p.current)return;p.current=l;const G=window.requestAnimationFrame(()=>{te()});return()=>{window.cancelAnimationFrame(G)}},[l,te]),c.useEffect(()=>{i==null||i(D)},[D,i]),{scrollContainerRef:h,scrollContentRef:u,tailSentinelRef:x,topSentinelRef:j,isTailVisible:D,handleScroll:le,handleWheel:be,handleTouchStart:ze,handleTouchMove:se,handleTouchEnd:ye,preserveScrollPositionForResize:ge,serverManagedHistory:A,effectiveTotalTurnCount:Q,startIndex:R,visibleTurnAbsoluteOffset:O,hiddenCount:C,loadedHiddenCount:U,unloadedHiddenCount:H,showLoadAll:E,handleLoadEarlierClick:de,handleLoadAllClick:je}}function Of(e){return e==="completed"||e==="failed"||e==="interrupted"}function Uf(e,r){if(!r||r.id!==e.id||r.items.length===0)return e;const n=new Set(e.items.map(o=>o.id)),a=r.items.filter(o=>!n.has(o.id));return a.length===0?e:{...e,items:[...a,...e.items]}}function Wf({threadId:e,turns:r,totalTurnCount:n,pendingRequests:a=[],activeTurnId:o=null,threadRunning:s=!1,pendingSteers:l=[],livePlan:i=null,liveItems:d=null,respondingRequestId:h=null,onRespondToRequest:u,liveOutput:m,scrollRequestKey:f=0,bottomSpacer:p=0,className:g="",onTailVisibilityChange:b,loadingEarlier:w=!1,onLoadEarlier:x,ephemeralUserNote:j=null,answeredRequestNotes:k=[],activityNotes:y=[],optimisticSteers:v=[],optimisticTurn:N=null,onLoadHistoryItemDetail:S,onOpenThread:L,onSelectArtifact:z,onSelectHistoryItemDetail:V,adapter:F,autoCollapseCompletedTurns:B}){var tt,I,W,pe,Pe;const J=tl(),Z=B??(J==null?void 0:J.autoCollapseCompletedTurns)??!1,[D,ee]=c.useState({}),[oe,A]=c.useState(()=>new Set),Q=(F==null?void 0:F.onLoadHistoryItemDetail)??S,R=F==null?void 0:F.onOpenLinkedThread,{expandedText:q,openExpandedText:O,openCommandDetail:T,openToolCallDetail:U,openDeferredHistoryItemDetail:H,closeExpandedText:C}=Gf({loadHistoryItemDetail:Q,onSelectHistoryItemDetail:V}),{scrollContainerRef:E,scrollContentRef:X,tailSentinelRef:Y,topSentinelRef:ie,handleScroll:K,handleWheel:le,handleTouchStart:te,handleTouchMove:ge,handleTouchEnd:de,preserveScrollPositionForResize:be,serverManagedHistory:ze,effectiveTotalTurnCount:se,startIndex:ye,visibleTurnAbsoluteOffset:je,hiddenCount:G,loadedHiddenCount:me,unloadedHiddenCount:fe,showLoadAll:we,handleLoadEarlierClick:Me,handleLoadAllClick:Ae}=Hf({threadId:e,turnsLength:r.length,totalTurnCount:n,loadingEarlier:w,onLoadEarlier:x,scrollRequestKey:f,bottomSpacer:p,onTailVisibilityChange:b,contentRevisionInputs:[r,a,l,v,m,i,d,N,k,y,j,p]}),Le=c.useCallback((re,Fe)=>{ee(Oe=>({...Oe,[re]:!Fe}))},[]),$e=c.useCallback((re,Fe)=>{const Oe=D[re.id];return Oe!==void 0?Oe:!!(Z&&Of(re.status)&&!Fe.forceActive&&!Fe.hasLiveActivity)},[D,Z]),_=ze?r:r.slice(ye),ue=se+1,ve=s&&(!o||!_.some(re=>re.id===o)&&(N==null?void 0:N.id)!==o),P=(N==null?void 0:N.id)??((tt=_.at(-1))==null?void 0:tt.id)??null,M=ve&&P!==null,ne=!!d&&(_.some(re=>re.id===d.turnId)||(N==null?void 0:N.id)===d.turnId),ke=d&&ne?d.turnId:d&&M?P:null,Ne=N&&ke===N.id?(d==null?void 0:d.items)??null:null,Ce=((d==null?void 0:d.items.length)??0)>0,_e=d&&ke===null?d.items:null,De=c.useMemo(()=>d&&ke===null&&d.items.length>0?Bf(d.turnId,d.items):null,[d,ke]),Ue=Math.max(1,se+(N?1:0)),ot=!!m&&!!N&&N.status!=="failed"&&!Ne,et=m&&_.length>0?o&&_.some(re=>re.id===o)?o:((I=_.findLast(re=>il(re.status)))==null?void 0:I.id)??(M?P:null):null,ut=!!et,at=c.useMemo(()=>ll(m),[m]),We=[...l.map(re=>({id:re.id,prompt:re.prompt,status:"Accepted",createdAt:re.createdAt,canCancel:!0})),...v.map(re=>({id:re.id,prompt:re.prompt,status:re.status==="steering"?"Steering":null,createdAt:re.createdAt,canCancel:!1}))].sort((re,Fe)=>re.createdAt.localeCompare(Fe.createdAt)),Ge=c.useMemo(()=>_p({answeredRequestNotes:k,pendingRequests:a,visibleTurns:_,optimisticTurn:N}),[k,N,a,_]),Ve=c.useMemo(()=>Mp({activityNotes:y,visibleTurns:_,optimisticTurn:N}),[y,N,_]);return t.jsxs(t.Fragment,{children:[t.jsx("section",{className:`flex min-h-0 flex-1 flex-col ${g}`.trim(),children:t.jsx("div",{ref:E,"data-testid":"thread-scroll-container",onScroll:K,onWheel:le,onTouchStart:te,onTouchMove:ge,onTouchEnd:de,onTouchCancel:de,className:"thread-graph-scroll-container min-h-0 flex-1 overflow-y-auto overscroll-contain",style:p>0?{paddingBottom:p}:void 0,children:t.jsxs("div",{ref:X,className:"thread-graph-scroll-content",children:[t.jsx("div",{ref:ie,"aria-hidden":"true",className:"h-px"}),r.length>0&&t.jsx("div",{className:"thread-graph-history-control px-3 pb-1 pt-2 sm:px-5 sm:pb-1.5 sm:pt-3",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 text-xs sm:text-sm",children:[G>0&&t.jsx("button",{type:"button",onClick:Me,disabled:w,className:"thread-graph-history-button rounded-full border px-2.5 py-1.5 transition",children:w?"Loading earlier...":"Load 3 earlier"}),we&&t.jsx("button",{type:"button",onClick:Ae,className:"rounded-full border border-amber-300/40 px-2.5 py-1.5 text-amber-200 transition hover:bg-amber-300/10",children:"Load full history"}),t.jsxs("p",{className:"timeline-meta-text",children:["Showing ",_.length," of ",se," turns",G>0?` · ${G} earlier hidden${me>0&&fe>0?` (${me} loaded)`:""}`:""]})]})}),r.length===0&&!m&&!N&&t.jsx("div",{className:"thread-graph-empty-state px-3 py-8 text-sm sm:px-5",children:"Send the first prompt to start the thread."}),(_.length>0||N||Ve.leading.length>0||Ve.trailing.length>0)&&t.jsxs("div",{className:"thread-graph-message-list",children:[Ve.leading.length>0?t.jsx(ir,{notes:Ve.leading,onOpenThread:L,onOpenLinkedThread:R}):null,_.map((re,Fe)=>{var Oe,He,Xe,dt,xt;return t.jsxs("div",{children:[(((Oe=Ve.beforeTurnId.get(re.id))==null?void 0:Oe.length)??0)>0?t.jsx(ir,{notes:Ve.beforeTurnId.get(re.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null,(((He=Ge.beforeTurnId.get(re.id))==null?void 0:He.length)??0)>0?t.jsx(Hn,{entries:Ge.beforeTurnId.get(re.id)??[],respondingRequestId:h,onRespondToRequest:u??void 0}):null,(()=>{const lt=Uf(re,N),wt=(i==null?void 0:i.turnId)===re.id?i:null,yt=ke===re.id?(d==null?void 0:d.items)??null:null,jt=et===re.id?m:"",xe=o===re.id||M&&P===re.id,Ie=!!wt||!!jt||!!(yt&&yt.length>0),rt=$e(lt,{forceActive:xe,hasLiveActivity:Ie});return t.jsx(bn,{threadId:e,...F?{adapter:F}:{},turn:lt,absoluteIndex:je+Fe+1,isCollapsed:rt,livePlan:wt,liveItems:yt,liveOutput:jt,forceActive:xe,onToggleCollapse:Le,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},scrollRootRef:E,articleRef:void 0})})(),(((Xe=Ve.afterTurnId.get(re.id))==null?void 0:Xe.length)??0)>0?t.jsx(ir,{notes:Ve.afterTurnId.get(re.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null,(dt=Ge.notesByTurnId.get(re.id))!=null&&dt.length||(xt=Ge.pendingRequestsByTurnId.get(re.id))!=null&&xt.length?t.jsx($p,{notes:Ge.notesByTurnId.get(re.id)??[],requests:Ge.pendingRequestsByTurnId.get(re.id)??[],respondingRequestId:h,onRespondToRequest:u??void 0}):null]},re.id)}),N&&_.every(re=>re.id!==N.id)&&t.jsxs(t.Fragment,{children:[(((W=Ve.beforeTurnId.get(N.id))==null?void 0:W.length)??0)>0?t.jsx(ir,{notes:Ve.beforeTurnId.get(N.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null,(((pe=Ge.beforeTurnId.get(N.id))==null?void 0:pe.length)??0)>0?t.jsx(Hn,{entries:Ge.beforeTurnId.get(N.id)??[],respondingRequestId:h,onRespondToRequest:u??void 0}):null,(()=>{const re=ot?m:"",Fe=o===N.id||M&&P===N.id,Oe=!!(Ne&&Ne.length>0)||!!re,He=$e(N,{forceActive:Fe,hasLiveActivity:Oe});return t.jsx(bn,{threadId:e,...F?{adapter:F}:{},turn:N,absoluteIndex:ue,isCollapsed:He,livePlan:null,liveItems:Ne,liveOutput:re,forceActive:Fe,onToggleCollapse:Le,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},scrollRootRef:E})})(),(((Pe=Ve.afterTurnId.get(N.id))==null?void 0:Pe.length)??0)>0?t.jsx(ir,{notes:Ve.afterTurnId.get(N.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null]})]}),We.length>0&&t.jsx("div",{className:"thread-graph-message-section space-y-3 px-3 py-4 sm:px-5",children:We.map(re=>t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(Et,{threadId:e,item:{id:re.id,kind:"userMessage",text:re.prompt,status:re.status},scrollRootRef:E,onBeforeMessageResize:be,...F?{adapter:F}:{}}),e&&re.canCancel&&(F!=null&&F.cancelPendingSteer)?t.jsx("div",{className:"flex justify-end px-1",children:t.jsx("button",{type:"button",className:"thread-graph-history-button rounded-full border px-2.5 py-1 text-xs transition disabled:cursor-not-allowed disabled:opacity-60",disabled:oe.has(re.id),onClick:()=>{var Fe;A(Oe=>new Set(Oe).add(re.id)),Promise.resolve((Fe=F.cancelPendingSteer)==null?void 0:Fe.call(F,e,re.id)).catch(()=>{}).finally(()=>{A(Oe=>{const He=new Set(Oe);return He.delete(re.id),He})})},children:oe.has(re.id)?"Canceling...":"Cancel"})}):null]},re.id))}),(Ge.trailing.length>0||Ve.trailing.length>0)&&t.jsx(Dp,{entries:[...Ve.trailing.map(re=>({kind:"activity",id:re.id,createdAt:re.createdAt,note:re})),...Ge.trailing],respondingRequestId:h,onRespondToRequest:u??void 0,onOpenThread:L,onOpenLinkedThread:R}),j&&t.jsx("div",{className:"thread-graph-message-section px-3 py-2.5 sm:px-5",children:t.jsx(Et,{threadId:e,item:{id:"ephemeral-plan-decision-note",kind:"userMessage",text:j},scrollRootRef:E,onBeforeMessageResize:be})}),De&&_e&&_e.length>0&&t.jsx(bn,{threadId:e,...F?{adapter:F}:{},turn:De,absoluteIndex:Ue,isCollapsed:D[De.id]??!1,livePlan:(i==null?void 0:i.turnId)===De.id?i:null,liveItems:_e,liveOutput:"",forceActive:!0,onToggleCollapse:Le,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},scrollRootRef:E}),m&&!ut&&!ot&&!Ce&&t.jsx("div",{className:"thread-graph-message-section px-3 py-2.5 sm:px-5",children:at?t.jsx(oa,{threadId:e,item:at,scrollRootRef:E,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},...F?{adapter:F}:{}}):t.jsx(Et,{threadId:e,item:{id:"live-agent-message-fallback",kind:"agentMessage",text:m},scrollRootRef:E,streaming:!0,onBeforeMessageResize:be,...F?{adapter:F}:{}})}),t.jsx("div",{ref:Y,"aria-hidden":"true",className:"h-px w-full"})]})})}),t.jsx(Qm,{open:q!==null,title:(q==null?void 0:q.title)??"Full text",text:(q==null?void 0:q.text)??"",onClose:C})]})}var bl=c.memo(Wf);function Vf(e){return/^[a-z]$/i.test(e)?String.fromCharCode(e.toUpperCase().charCodeAt(0)-64):null}function Wn(e){return e.replace(/\r\n/g,`
3666
+ `).trim())??"",o=r.hookEventLabel?`${r.hookEventLabel} hook`:r.text,s=((u=r.hookStatusMessage)==null?void 0:u.trim())||(r.previewText&&r.previewText!==r.hookStatusMessage?r.previewText.trim():"")||r.text.trim(),i=gt(a||(s&&s!==o?s:o)),d=!!(a&&i.showGap);return t.jsx(Ot,{className:"thread-graph-event-hook",icon:t.jsx($.Webhook,{className:"h-4 w-4"}),item:r,timeMeta:n,title:r.hookEventLabel?`${r.hookEventLabel}_hook`:"hook",tone:"hook",children:t.jsxs("div",{className:"thread-graph-history-event-line",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:a?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"thread-graph-history-event-secondary mr-2 font-sans text-[11px] uppercase",children:o}),t.jsx(rr,{text:i.firstLine})]}):t.jsx(rr,{text:i.firstLine&&i.firstLine!==o?`${o} · ${i.firstLine}`:o})}),d?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})})}),cf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.filter(d=>aa(d.status)).length,i=r.length===1?"1 command":`${r.length} commands`;return t.jsx(Jr,{className:"thread-graph-history-group-command",count:r.length,countBadgeClassName:"border-amber-200/35 text-amber-100",desktopIconClassName:"border-amber-300/30 bg-amber-300/[0.14] text-amber-100",expanded:n,expandedListClassName:"border-amber-300/12",icon:t.jsx(Op,{}),onToggleExpanded:a,runningIndicator:l>0?t.jsx(On,{}):null,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-amber-300/28 bg-amber-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-amber-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:i}),l>0?t.jsx("span",{className:"inline-flex items-center text-xs text-amber-100/90",children:t.jsx(On,{})}):null]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} command entries`,children:r.map((d,h)=>{const u=gt(d.text);return t.jsxs("button",{type:"button","aria-label":`Open grouped command ${h+1}`,onClick:()=>o(d,`Command Output ${h+1}`),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("span",{className:"rounded-full border border-amber-300/18 bg-amber-300/[0.07] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-amber-100",children:["Step ",h+1]}),d.status&&t.jsx("span",{className:"thread-graph-history-detail-meta text-xs",children:d.status})]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-sm leading-6",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:u.firstLine}),u.showGap?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})]},d.id)})})}),hf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.length===1?"1 search":`${r.length} searches`;return t.jsx(Jr,{className:"thread-graph-history-group-search",count:r.length,countBadgeClassName:"border-sky-200/35 text-sky-100",desktopIconClassName:"border-sky-300/30 bg-sky-300/[0.14] text-sky-100",expanded:n,expandedListClassName:"border-sky-300/12",icon:t.jsx(Up,{}),onToggleExpanded:a,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-sky-300/28 bg-sky-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-sky-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:l})]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} web search entries`,children:r.map((i,d)=>{var f,p;const h=((f=i.previewText)==null?void 0:f.trim())||i.text||"Web search",u=gt(h),m=((p=i.detailText)==null?void 0:p.trim())||i.text||"Web search";return t.jsxs("button",{type:"button","aria-label":`Open grouped web search ${d+1}`,onClick:()=>o(`Web Search ${d+1}`,m),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("span",{className:"rounded-full border border-sky-300/18 bg-sky-300/[0.07] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-sky-100",children:["Search ",d+1]}),i.status&&t.jsx("span",{className:"thread-graph-history-detail-meta text-xs",children:i.status})]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-sm leading-6",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:u.firstLine}),u.showGap?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})]},i.id)})})}),uf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.length===1?"1 file read":`${r.length} file reads`;return t.jsx(Jr,{className:"thread-graph-history-group-file-read",count:r.length,countBadgeClassName:"border-cyan-200/35 text-cyan-100",desktopIconClassName:"border-cyan-300/30 bg-cyan-300/[0.14] text-cyan-100",expanded:n,expandedListClassName:"border-cyan-300/12",icon:t.jsx(Hp,{}),onToggleExpanded:a,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-cyan-300/28 bg-cyan-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-cyan-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:l})]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} file read entries`,children:r.map((i,d)=>{var f,p;const h=((f=i.previewText)==null?void 0:f.trim())||i.text||"File read",u=gt(h),m=((p=i.detailText)==null?void 0:p.trim())||i.text||"File read";return t.jsxs("button",{type:"button","aria-label":`Open grouped file read ${d+1}`,onClick:()=>o(`File Read ${d+1}`,m),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("span",{className:"rounded-full border border-cyan-300/18 bg-cyan-300/[0.07] px-2 py-0.5 text-[10px] uppercase tracking-[0.18em] text-cyan-100",children:["Read ",d+1]}),i.status&&t.jsx("span",{className:"thread-graph-history-detail-meta text-xs",children:i.status})]}),t.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-sm leading-6",children:[t.jsx("p",{className:"thread-graph-history-detail-text min-w-0 flex-1 overflow-hidden whitespace-nowrap text-clip",children:u.firstLine}),u.showGap?t.jsx("span",{className:"thread-graph-history-detail-meta shrink-0 text-[11px] font-medium tracking-[0.28em]",children:"..."}):null]})]},i.id)})})}),mf=c.memo(function({items:r,expanded:n,onToggleExpanded:a,onOpen:o,timeMeta:s}){const l=r.reduce((u,m)=>u+(m.changedFiles??0),0),i=r.reduce((u,m)=>u+(m.addedLines??0),0),d=r.reduce((u,m)=>u+(m.removedLines??0),0),h=r.length===1?"1 file change":`${r.length} file changes`;return t.jsx(Jr,{className:"thread-graph-history-group-file-change",count:r.length,countBadgeClassName:"border-lime-200/35 text-lime-100",desktopIconClassName:"border-lime-300/30 bg-lime-300/[0.14] text-lime-100",expanded:n,expandedListClassName:"border-lime-300/12",icon:t.jsx(Fp,{}),onToggleExpanded:a,summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"rounded-full border border-lime-300/28 bg-lime-300/12 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.24em] text-lime-100",children:"Batch"}),t.jsx("span",{className:"rounded-full border border-stone-700/90 bg-stone-900/80 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.16em] text-stone-300",children:h}),l>0?t.jsxs("span",{className:"thread-graph-history-detail-meta text-xs",children:[l," files"]}):null]}),timeMeta:s,toggleAriaLabel:`${n?"Collapse":"Expand"} ${r.length} file change entries`,trailingSummary:t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5",children:[i>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-add",children:["+",i]}):null,d>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-remove",children:["-",d]}):null]}),children:r.map((u,m)=>{var g,b,w,x;const f=((g=u.detailText)==null?void 0:g.trim())||((b=u.previewText)==null?void 0:b.trim())||u.text,p=(w=u.previewText)!=null&&w.trim()&&u.text.trim()!==u.previewText.trim()?u.text.trim():((x=u.previewText)==null?void 0:x.trim())||u.text;return t.jsx("button",{type:"button","aria-label":`Open grouped file change ${m+1}`,onClick:()=>o(`File Change ${m+1}`,f),className:"thread-graph-history-detail-row block w-full rounded-md border px-3 py-2 text-left transition",children:t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"thread-graph-history-detail-text min-w-0 flex-1 text-sm leading-6",title:p,children:pl(p,34)}),t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5",children:[(u.addedLines??0)>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-add",children:["+",u.addedLines]}):null,(u.removedLines??0)>0?t.jsxs("span",{className:"thread-graph-history-delta-badge is-remove",children:["-",u.removedLines]}):null]})]})},u.id)})})});function pf(e){const r=e.trim().toLowerCase();return r==="completed"||r==="done"||r==="complete"?"completed":r==="in_progress"||r==="in-progress"||r==="running"||r==="active"?"in_progress":r==="failed"||r==="error"||r==="cancelled"?"failed":r==="pending"||r==="todo"?"pending":"unknown"}function ff({status:e}){const r=pf(e),n=r==="completed"?"Plan step status: Completed":r==="in_progress"?"Plan step status: In progress":r==="pending"?"Plan step status: Pending":r==="failed"?"Plan step status: Failed":`Plan step status: ${e}`,a=r==="completed"?"thread-graph-plan-status is-completed":r==="in_progress"?"thread-graph-plan-status is-running":r==="pending"?"thread-graph-plan-status is-pending":r==="failed"?"thread-graph-plan-status is-failed":"thread-graph-plan-status is-unknown";return t.jsx(Qr,{"aria-label":n,title:n.replace("Plan step status: ",""),className:a,children:r==="completed"?t.jsx($.CheckCircle2,{className:"h-3.5 w-3.5"}):r==="in_progress"?t.jsx($.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):r==="pending"?t.jsx($.Clock3,{className:"h-3.5 w-3.5"}):r==="failed"?t.jsx($.XCircle,{className:"h-3.5 w-3.5"}):t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.14em]",children:"?"})})}function gf({livePlan:e}){return t.jsxs("div",{className:"thread-graph-plan-card rounded-xl border px-3 py-3",children:[t.jsxs("div",{className:"thread-graph-plan-header flex flex-wrap items-center justify-between gap-2",children:[t.jsx("p",{className:"text-sm font-semibold",children:"Plan update"}),t.jsx(Qr,{className:"thread-graph-plan-badge",children:"Live"})]}),e.explanation?t.jsx("p",{className:"thread-graph-plan-explanation mt-3 text-sm",children:e.explanation}):null,t.jsx("div",{className:"mt-3 space-y-2",children:e.plan.map((r,n)=>t.jsxs("div",{className:"thread-graph-plan-step flex items-center justify-between gap-3 rounded-lg border px-3 py-2 text-sm",children:[t.jsx("span",{className:"thread-graph-plan-step-text min-w-0 flex-1",children:r.step}),t.jsx(ff,{status:r.status})]},`${e.turnId}-${n}`))})]})}function xf({footer:e,history:r,liveHookPrompt:n,liveOutput:a,livePlan:o}){return t.jsxs(t.Fragment,{children:[r,o?t.jsx(gf,{livePlan:o}):null,n??a??null,e]})}function bf({absoluteIndex:e,body:r,collapsed:n,collapsedBody:a,error:o,footer:s,headerStatus:l,isActive:i=!1,refCallback:d,startedAt:h,timeLabel:u,timeTitle:m,tokenSummary:f}){return t.jsxs("article",{ref:d,"data-testid":"chat-turn","data-turn-active":i?"true":"false",className:"thread-graph-turn px-3 py-2 sm:px-5 sm:py-3",children:[t.jsx("div",{className:"thread-graph-turn-header flex items-start justify-between gap-2",children:t.jsxs("div",{className:"min-w-0 flex flex-1 items-start gap-1.5",children:[t.jsxs("div",{className:"min-w-0 flex flex-1 items-center gap-1.5 overflow-hidden",children:[t.jsxs("span",{className:"thread-graph-turn-index rounded-[0.6rem] border px-1.5 py-0.5 text-[10px] uppercase tracking-[0.16em]",children:["Turn ",e]}),t.jsx("time",{dateTime:h??void 0,title:m,className:"thread-graph-turn-time shrink-0 text-[10px] sm:text-[11px]",children:u}),l,o?t.jsx("p",{className:"hidden truncate text-[11px] text-rose-200 sm:block",children:o}):null]}),f]})}),o?t.jsx("p",{className:"mt-1 text-[11px] text-rose-200 sm:hidden",children:o}):null,t.jsxs("div",{className:"thread-graph-turn-body mt-2 space-y-2",children:[n?a:r,n?null:s]})]})}function vf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M8 2.75v8"}),t.jsx("path",{d:"m4.75 7.5 3.25 3.25L11.25 7.5"})]})}function kf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M8 13.25v-8"}),t.jsx("path",{d:"m11.25 8.5-3.25-3.25L4.75 8.5"})]})}function wf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.45",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M3.25 5.25 8 2.75l4.75 2.5L8 7.75l-4.75-2.5Z"}),t.jsx("path",{d:"M3.25 8 8 10.5 12.75 8"}),t.jsx("path",{d:"M3.25 10.75 8 13.25l4.75-2.5"}),t.jsx("path",{d:"M3.25 5.25v5.5"}),t.jsx("path",{d:"M12.75 5.25v5.5"})]})}function yf(){return t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.45",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M6.2 3.2a2.3 2.3 0 0 0-2.95 3.5A2.4 2.4 0 0 0 4.5 11h.2c.25 1.1 1.1 1.8 2.3 1.8h1.8c1.2 0 2.05-.7 2.3-1.8h.2A2.4 2.4 0 0 0 12.75 6.7 2.3 2.3 0 0 0 9.8 3.2"}),t.jsx("path",{d:"M6.3 6.15c.45-.42 1.02-.65 1.7-.65s1.25.23 1.7.65"}),t.jsx("path",{d:"M8 5.5v4.75"}),t.jsx("path",{d:"M6.75 9.05 8 10.25l1.25-1.2"})]})}function Pr(e){if(!Number.isFinite(e)||e<=0)return"0";if(e>=1e6){const r=e>=1e7?Math.round(e/1e6):e/1e6;return`${String(r.toFixed(1)).replace(/\.0$/,"")}m`}if(e>=1e3){const r=e>=1e4?Math.round(e/1e3):e/1e3;return`${String(r.toFixed(1)).replace(/\.0$/,"")}k`}return String(Math.round(e))}function sa(e){return!Number.isFinite(e)||e<=0?"$0":e>=100?`$${Math.round(e)}`:e>=10?`$${String(e.toFixed(1)).replace(/\.0$/,"")}`:e>=1?`$${String(e.toFixed(2)).replace(/0$/,"").replace(/\.$/,"")}`:e>=.1?`$${e.toFixed(2)}`:e>=.01?`$${e.toFixed(3)}`:e>=.001?`$${e.toFixed(4)}`:"<$0.001"}function ur(e){return!Number.isFinite(e)||e<=0?"$0.0000":`$${e.toFixed(4)}`}function zr(e,r,n){const a=e??null;return!Number.isFinite(a??NaN)||a===null||r<=0||n<=0?null:a*n/r}function gl(e){var i,d,h,u,m;const r=(i=e.tokenUsage)==null?void 0:i.total;if(!r)return[];const n=Math.max(r.inputTokens-r.cachedInputTokens,0),a=Math.max(r.cachedInputTokens,0),o=Math.max(r.reasoningOutputTokens,0),s=Math.max(r.outputTokens-o,0);return[n>0?{id:"in",label:"Input",tokenCompactValue:Pr(n),tokenRawValue:n,usdCompactValue:e.priceEstimate?ur(e.priceEstimate.inputUsd):"--",usdRawValue:((d=e.priceEstimate)==null?void 0:d.inputUsd)??null,className:"token-badge-in",icon:t.jsx(vf,{})}:null,a>0?{id:"cache",label:"Cached input",tokenCompactValue:Pr(a),tokenRawValue:a,usdCompactValue:e.priceEstimate?ur(e.priceEstimate.cachedInputUsd):"--",usdRawValue:((h=e.priceEstimate)==null?void 0:h.cachedInputUsd)??null,className:"token-badge-cache",icon:t.jsx(wf,{})}:null,s>0?{id:"out",label:"Output",tokenCompactValue:Pr(s),tokenRawValue:s,usdCompactValue:e.priceEstimate?ur(zr(e.priceEstimate.outputUsd,Math.max(r.outputTokens,0),s)??0):"--",usdRawValue:zr((u=e.priceEstimate)==null?void 0:u.outputUsd,Math.max(r.outputTokens,0),s),className:"token-badge-out",icon:t.jsx(kf,{})}:null,o>0?{id:"reason",label:"Reasoning",tokenCompactValue:Pr(o),tokenRawValue:o,usdCompactValue:e.priceEstimate?ur(zr(e.priceEstimate.outputUsd,Math.max(r.outputTokens,0),o)??0):"--",usdRawValue:zr((m=e.priceEstimate)==null?void 0:m.outputUsd,Math.max(r.outputTokens,0),o),className:"token-badge-reason",icon:t.jsx(yf,{})}:null].filter(f=>f!==null)}function jf(e){return gl(e).map(r=>({id:r.id,label:r.tokenCompactValue,title:`${r.label}: ${r.tokenRawValue} tokens`,className:r.className,icon:r.icon}))}function xl(e){return{label:e.priceEstimate?sa(e.priceEstimate.totalUsd):"--",title:e.priceEstimate===null||e.priceEstimate===void 0?"Price estimate unavailable for this model.":`Estimated cost: ${ur(e.priceEstimate.totalUsd)}`,className:e.priceEstimate?"token-badge-total":"token-badge-empty"}}var xn="inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-normal leading-none sm:text-[11px]";function Nf({turn:e}){const r=gl(e),n=xl(e),[a,o]=c.useState(!1),[s,l]=c.useState(!1),[i,d]=c.useState(0),h=c.useRef(null),u=c.useRef(null),m=c.useRef(null);if(c.useLayoutEffect(()=>{if(!a||r.length===0){d(0);return}const p=()=>{const g=h.current,b=m.current;if(!g||!b)return;const w=g.getBoundingClientRect(),x=b.offsetWidth||b.getBoundingClientRect().width;if(x<=0)return;const j=window.innerWidth||document.documentElement.clientWidth,k=12,y=w.left+w.width/2-x/2,v=k,N=Math.max(v,j-k-x),S=Math.min(Math.max(y,v),N);d(Math.round(S-y))};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[r.length,a]),c.useEffect(()=>{if(!a&&!s)return;const p=g=>{g.target instanceof Node&&(h.current&&!h.current.contains(g.target)&&o(!1),u.current&&!u.current.contains(g.target)&&l(!1))};return document.addEventListener("pointerdown",p),()=>{document.removeEventListener("pointerdown",p)}},[s,a]),!n&&r.length===0)return null;const f=()=>t.jsx("div",{className:"thread-token-popover min-w-[12rem] rounded-2xl border p-2.5 shadow-2xl shadow-black/20 backdrop-blur",children:t.jsx("div",{className:"space-y-1",children:r.map(p=>t.jsxs("div",{className:"thread-token-popover-row flex items-center justify-between gap-3 rounded-xl border px-2.5 py-1.5 text-[11px]",title:`${p.label}: ${p.tokenRawValue} tokens`,children:[t.jsxs("span",{className:"thread-token-popover-text inline-flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"inline-flex shrink-0",children:p.icon}),t.jsx("span",{className:"thread-token-popover-strong font-medium",children:p.usdCompactValue})]}),t.jsx("span",{className:"thread-token-popover-text shrink-0 font-medium",children:p.tokenCompactValue})]},p.id))})});return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"hidden shrink-0 items-center gap-1.5 md:inline-flex",children:[n?t.jsxs("div",{ref:u,className:"relative shrink-0",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),children:[t.jsx("button",{type:"button","aria-label":"Show token and price details","aria-expanded":s,onFocus:()=>l(!0),onBlur:()=>l(!1),className:`${xn} appearance-none whitespace-nowrap bg-transparent !text-[10px] !font-normal !leading-none transition hover:bg-[var(--theme-hover)] sm:!text-[11px] ${n.className}`,title:n.title,children:n.label}),s&&r.length>0?t.jsx("div",{className:"absolute left-1/2 top-full z-30 mt-1.5 -translate-x-1/2",children:f()}):null]}):null,r.map(p=>t.jsxs("span",{className:`${xn} ${p.className}`,title:`${p.label}: ${p.usdCompactValue}, ${p.tokenRawValue} tokens`,children:[p.icon,t.jsx("span",{className:"thread-token-badge-value font-medium",children:p.tokenCompactValue})]},p.id))]}),t.jsxs("div",{ref:h,className:"relative shrink-0 md:hidden",children:[n?t.jsx("button",{type:"button","aria-label":"Show token and price details","aria-expanded":a,onClick:()=>o(p=>!p),className:`${xn} appearance-none whitespace-nowrap bg-transparent !text-[10px] !font-normal !leading-none transition hover:bg-[var(--theme-hover)] sm:!text-[11px] ${n.className}`,title:n.title,children:n.label}):null,a&&r.length>0?t.jsx("div",{ref:m,className:"absolute left-1/2 top-full z-30 mt-1.5",style:{transform:`translateX(${i}px) translateX(-50%)`},children:f()}):null]})]})}function Cf({tone:e="amber"}){const r=e==="emerald"?"bg-sky-200/90":e==="sky"?"bg-sky-300/90":"bg-amber-200/90";return t.jsx("span",{className:"ml-1.5 inline-flex items-center gap-1","aria-hidden":"true",children:[0,1,2].map(n=>t.jsx("span",{className:`h-1.5 w-1.5 rounded-full animate-pulse ${r}`,style:{animationDelay:`${n*180}ms`}},n))})}function ys(e){const r=e.trim().toLowerCase();return r==="completed"||r==="done"||r==="complete"?"completed":r==="in_progress"||r==="in progress"||r==="inprogress"||r==="running"||r==="active"?"in_progress":r==="pending"||r==="todo"||r==="not_started"||r==="not started"||r==="queued"?"pending":r==="failed"||r==="error"?"failed":"other"}function Sf(e){switch(e.kind){case"fileChange":case"webSearch":case"image":case"contextCompaction":return!0;case"commandExecution":case"toolCall":return!il(e.status);default:return!1}}function Tf(e,r,n){if(!e||!mr(n))return e;const a=e.plan.findIndex(i=>ys(i.status)==="in_progress");if(a<0)return e;const o=e.plan.findIndex((i,d)=>d>a&&ys(i.status)==="pending");if(o<0||!r.some(i=>Sf(i)))return e;const l=e.plan.map((i,d)=>d===a?{...i,status:"completed"}:d===o?{...i,status:"in_progress"}:i);return{...e,plan:l}}function Ef(e){var a;const r=(a=e.model)!=null&&a.trim()?e.model.trim():"--";let n="--";return e.reasoningEffortAvailable===null||e.reasoningEffortAvailable===void 0?n="--":e.reasoningEffortAvailable===!1?n="-":n=e.reasoningEffort??"--",[r,n].join(" · ")}function js({status:e}){const r=rl(e);return e==="completed"?t.jsx("span",{"aria-label":r,title:r,className:"timeline-status-icon timeline-status-icon-success inline-flex h-4 w-4 items-center justify-center",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"m3.75 8.25 2.5 2.5 6-6"})})}):e==="failed"?t.jsx("span",{"aria-label":r,title:r,className:"timeline-status-icon timeline-status-icon-failed inline-flex h-4 w-4 items-center justify-center",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"m5 5 6 6M11 5l-6 6"})})}):e==="interrupted"?t.jsx("span",{"aria-label":r,title:r,className:"timeline-status-icon timeline-status-icon-warning inline-flex h-4 w-4 items-center justify-center",children:t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 16 16",className:"h-3.5 w-3.5 fill-none stroke-current",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M6 4.5v7M10 4.5v7"})})}):t.jsx("span",{"aria-label":r,title:r,className:"inline-flex min-w-[1.25rem] items-center justify-center text-sky-200",children:t.jsx(Cf,{tone:"emerald"})})}function Ns({turn:e,variant:r="header"}){const n=rl(e.status),a=Ef(e),o=jf(e),s=xl(e),l=mr(e.status),i=e.status==="failed"?"border-rose-300/20 bg-rose-300/[0.06] text-rose-100":l?"border-sky-300/22 bg-sky-300/[0.08] text-sky-100":"border-stone-700/90 bg-stone-900/70 text-stone-200";if(r==="footer")return t.jsxs("div",{className:`flex w-full flex-col gap-1.5 rounded-[0.95rem] border px-3 py-2 text-xs ${i}`,children:[t.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(js,{status:e.status}),t.jsx("span",{className:"timeline-soft-text min-w-0 truncate",children:a})]}),e.startedAt&&t.jsx("time",{dateTime:e.startedAt,title:Gt(e.startedAt),className:"timeline-meta-text shrink-0 text-[11px]",children:ft(e.startedAt)})]}),(s||o.length>0)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pl-6",children:[s?t.jsx("span",{className:`inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${s.className}`,title:s.title,children:s.label}):null,o.map(h=>t.jsxs("span",{className:`inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${h.className}`,title:h.title,children:[h.icon?t.jsx("span",{className:"mr-1",children:h.icon}):null,h.label]},h.id))]})]});const d=`${n} · ${a}`;return t.jsxs("span",{className:`inline-flex min-w-0 items-center gap-1.5 rounded-full border px-2 py-1 text-[10px] sm:text-[11px] ${i}`,title:d,children:[t.jsx(js,{status:e.status}),t.jsx("span",{className:"timeline-meta-text min-w-0 truncate",children:a})]})}function Lf(e,r){return e.createdAt??r}var oa=c.memo(function({threadId:r,item:n,scrollRootRef:a,onOpenExpandedText:o,onOpenCommandDetail:s,onOpenToolCallDetail:l,onOpenDeferredHistoryItemDetail:i,onSelectArtifact:d,onBeforeMessageResize:h,adapter:u,timeLabel:m,timeTitle:f,timeMeta:p,autoOpenToolDetails:g=!1}){var b,w,x;if(Ep(n.kind))return t.jsx(Et,{threadId:r,item:n,scrollRootRef:a,timeLabel:m,timeTitle:f,...h?{onBeforeMessageResize:h}:{},...u?{adapter:u}:{}});if(n.kind==="reasoning")return t.jsx(Et,{item:{...n,kind:"agentMessage",status:n.status??null},scrollRootRef:a,timeLabel:m,timeTitle:f,...h?{onBeforeMessageResize:h}:{}});if(n.kind==="artifact")return t.jsx(lf,{item:n,timeMeta:p,...d?{onSelect:(j,k)=>d({item:j,artifact:k})}:{}});if(n.kind==="commandExecution")return t.jsx(Qp,{autoOpen:g,item:n,onOpen:s,timeMeta:p});if(n.kind==="toolCall")return t.jsx(ef,{autoOpen:g,item:n,onOpen:l,timeMeta:p});if(n.kind==="agentToolCall")return t.jsx(tf,{autoOpen:g,item:n,onOpen:l,timeMeta:p});if(n.kind==="skillToolCall")return t.jsx(rf,{autoOpen:g,item:n,onOpen:l,timeMeta:p});if(n.kind==="webSearch"){const j=n,k=((b=j.detailText)==null?void 0:b.trim())||j.text||"Web search";return t.jsx(nf,{autoOpen:g,item:j,timeMeta:p,onOpen:()=>i(j,"Web Search Details",k,"Loading full web search details...","Unable to load full web search details.")})}if(n.kind==="fileRead"){const j=n,k=((w=j.detailText)==null?void 0:w.trim())||j.text||"File read";return t.jsx(af,{autoOpen:g,item:j,timeMeta:p,onOpen:()=>i(j,"File Read Details",k,"Loading full file read details...","Unable to load full file read details.")})}if(n.kind==="image")return t.jsx(sf,{threadId:r,item:n,onOpen:o,getImageAssetUrl:u==null?void 0:u.getImageAssetUrl,timeMeta:p});if(n.kind==="plan")return t.jsx(Yp,{item:n,scrollRootRef:a,timeMeta:p,...h?{onBeforeResize:h}:{}});if(n.kind==="fileChange"){const j=n,k=((x=j.detailText)==null?void 0:x.trim())||j.text||"File change";return t.jsx(of,{item:j,timeMeta:p,onOpen:()=>i(j,"File Change Details",k,"Loading full file change details...","Unable to load full file change details.")})}return n.kind==="contextCompaction"?t.jsx(Zp,{item:n,timeMeta:p}):n.kind==="hook"?t.jsx(df,{item:n,timeMeta:p}):t.jsx(Jp,{item:n,timeMeta:p})});function Cs(e){return e==="completed"||e==="failed"||e==="interrupted"}function Pf(e){const r=Date.parse(e.createdAt??"");return Number.isFinite(r)?r:null}function zf(e){let r=null;for(const n of e){const a=Pf(n);a!==null&&(r=r===null?a:Math.max(r,a))}return r}function If(e,r){const n=Date.parse(e??""),a=zf(r);if(!Number.isFinite(n)||a===null||a<n)return"Worked";const o=Math.max(1,Math.round((a-n)/1e3)),s=Math.floor(o/3600),l=Math.floor(o%3600/60),i=o%60;return s>0?`Worked for ${s}h ${l}m`:l>0?`Worked for ${l}m ${i}s`:`Worked for ${i}s`}function Rf(e,r){const n=Date.parse(e??""),a=Date.parse(r??"");if(!Number.isFinite(n)||!Number.isFinite(a))return r?ft(r):"Time unavailable";const o=Math.max(0,Math.round((a-n)/1e3)),s=Math.floor(o/3600),l=Math.floor(o%3600/60),i=o%60;return s>0?`${s}h ${l}m`:l>0?`${l}m ${i}s`:`${i}s`}function fr({absoluteLabel:e,className:r="",timestamp:n,turnStartedAt:a}){const[o,s]=c.useState(!1);if(!n)return null;const l=Gt(n),i=Rf(a,n),d=o?e:i;return t.jsx("span",{role:"button",tabIndex:0,className:`thread-graph-relative-time rounded-full px-1.5 py-0.5 text-[10px] leading-none transition sm:text-[11px] ${r}`,title:o?i:l,"aria-label":`Toggle timestamp, currently ${d}`,onClick:h=>{h.stopPropagation(),s(u=>!u)},onKeyDown:h=>{h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),h.stopPropagation(),s(u=>!u))},children:t.jsx("time",{dateTime:n,children:d})})}function Ir(e){var r;return e.kind==="item"?e.item.createdAt??null:((r=e.items.find(n=>n.createdAt))==null?void 0:r.createdAt)??null}function Af(e){const r=e.filter(s=>s.kind==="item"),n=r.map(s=>s.item).filter(s=>s.kind==="userMessage"),a=r.map(s=>s.item).reverse().find(s=>s.kind==="agentMessage"&&s.text.trim().length>0),o=e.filter(s=>s.kind!=="item"?!0:s.item.kind!=="userMessage"&&s.item.id!==(a==null?void 0:a.id));return{users:n,finalAgent:a,hiddenEntries:o}}var bn=c.memo(function({threadId:r,adapter:n,turn:a,absoluteIndex:o,isCollapsed:s,livePlan:l,liveItems:i,liveOutput:d,forceActive:h=!1,onToggleCollapse:u,onOpenExpandedText:m,onOpenCommandDetail:f,onOpenToolCallDetail:p,onOpenDeferredHistoryItemDetail:g,onSelectArtifact:b,onBeforeMessageResize:w,scrollRootRef:x,articleRef:j,isLatestVisibleTurn:k=!1}){const y=!!l||!!d||!!(i&&i.length>0),v=h||mr(a.status)||y||k,N=v&&!mr(a.status)?{...a,status:"inProgress"}:a,S=c.useMemo(()=>Ip(a.items,i),[i,a.items]),L=c.useMemo(()=>Tf(l,S,a.status),[l,S,a.status]),z=c.useMemo(()=>Rp(d,S),[d,S]),V=c.useMemo(()=>zp(S,v),[v,S]),F=c.useMemo(()=>Ap(V),[V]),B=h||mr(a.status)||y,J=ft(a.startedAt),Z=Gt(a.startedAt),D=c.useMemo(()=>ll(z),[z]),[ee,oe]=c.useState({}),A=c.useCallback(K=>{oe(le=>({...le,[K]:!le[K]}))},[]),Q=t.jsx(_f,{entries:F,expandedGroups:ee,onToggleGroupedItem:A,threadId:r,scrollRootRef:x,onOpenExpandedText:m,onOpenCommandDetail:f,onOpenToolCallDetail:p,onOpenDeferredHistoryItemDetail:g,...w?{onBeforeMessageResize:w}:{},fallbackTimestamp:a.startedAt,fallbackTimeLabel:J,fallbackTimeTitle:Z,turnStartedAt:a.startedAt,autoOpenLatestToolDetails:B,...b?{onSelectArtifact:b}:{},...n?{adapter:n}:{}}),R=D?t.jsx(oa,{threadId:r,item:D,scrollRootRef:x,onOpenExpandedText:m,onOpenCommandDetail:f,onOpenToolCallDetail:p,onOpenDeferredHistoryItemDetail:g,timeLabel:a.startedAt?t.jsx(fr,{absoluteLabel:J,timestamp:a.startedAt,turnStartedAt:a.startedAt}):J,timeTitle:Z,timeMeta:null,...b?{onSelectArtifact:b}:{},...n?{adapter:n}:{}}):null,q=!D&&z?t.jsx(Et,{item:{id:"live-agent-message",kind:"agentMessage",text:z},scrollRootRef:x,timeLabel:a.startedAt?t.jsx(fr,{absoluteLabel:J,timestamp:a.startedAt,turnStartedAt:a.startedAt}):J,timeTitle:Z,streaming:!0,...w?{onBeforeMessageResize:w}:{}}):null,O=v?t.jsx(Ns,{turn:N,variant:"footer"}):null,T=c.useMemo(()=>Af(F),[F]),U=c.useMemo(()=>If(a.startedAt,S),[S,a.startedAt]),H=T.hiddenEntries.length>0,C=s&&H,X=Cs(a.status)&&H&&!C?t.jsxs("button",{type:"button",className:"thread-graph-worked-summary group flex w-full items-center gap-2 py-2 text-left text-sm transition",onClick:()=>u(a.id,!1),"aria-label":`${U}. Collapse turn ${o}`,children:[t.jsx("span",{className:"thread-graph-worked-label shrink-0",children:U}),t.jsx($.ChevronDown,{className:"h-4 w-4 shrink-0 transition group-hover:translate-y-0.5"}),t.jsx("span",{className:"thread-graph-worked-rule h-px min-w-0 flex-1","aria-hidden":"true"})]}):null,Y=Cs(a.status)&&H?t.jsxs("div",{className:"thread-graph-turn-collapsed-summary space-y-2",children:[T.users.map(K=>t.jsx(Et,{threadId:r,item:K,scrollRootRef:x,timeLabel:K.createdAt?ft(K.createdAt):J,timeTitle:K.createdAt?Gt(K.createdAt):Z,...w?{onBeforeMessageResize:w}:{},...n?{adapter:n}:{}},K.id)),t.jsxs("button",{type:"button",className:"thread-graph-worked-summary group flex w-full items-center gap-2 py-2 text-left text-sm transition",onClick:()=>u(a.id,!0),"aria-label":`${U}. Expand turn ${o}`,children:[t.jsx("span",{className:"thread-graph-worked-label shrink-0",children:U}),t.jsx($.ChevronRight,{className:"h-4 w-4 shrink-0 transition group-hover:translate-x-0.5"}),t.jsx("span",{className:"thread-graph-worked-rule h-px min-w-0 flex-1","aria-hidden":"true"})]}),T.finalAgent?t.jsx(Et,{threadId:r,item:T.finalAgent,scrollRootRef:x,timeLabel:T.finalAgent.createdAt?t.jsx(fr,{absoluteLabel:ft(T.finalAgent.createdAt),timestamp:T.finalAgent.createdAt,turnStartedAt:a.startedAt}):J,timeTitle:T.finalAgent.createdAt?Gt(T.finalAgent.createdAt):Z,...w?{onBeforeMessageResize:w}:{},...n?{adapter:n}:{}}):null]}):null,ie=t.jsx(xf,{footer:O,history:t.jsxs(t.Fragment,{children:[X,Q]}),liveHookPrompt:R,liveOutput:q,livePlan:L});return t.jsx(bf,{absoluteIndex:o,body:ie,collapsed:C,collapsedBody:Y,error:a.error,headerStatus:t.jsx(Ns,{turn:a}),isActive:v,refCallback:j,startedAt:a.startedAt,timeLabel:J,timeTitle:Z,tokenSummary:t.jsx(Nf,{turn:a})})});function _f({entries:e,expandedGroups:r,onToggleGroupedItem:n,threadId:a,scrollRootRef:o,onOpenExpandedText:s,onOpenCommandDetail:l,onOpenToolCallDetail:i,onOpenDeferredHistoryItemDetail:d,onSelectArtifact:h,onBeforeMessageResize:u,adapter:m,fallbackTimestamp:f,fallbackTimeLabel:p,fallbackTimeTitle:g,turnStartedAt:b,autoOpenLatestToolDetails:w=!1}){var k;const x=((k=e.at(-1))==null?void 0:k.key)??null,j=c.useCallback(y=>y?t.jsx(fr,{absoluteLabel:ft(y),timestamp:y,turnStartedAt:b??f}):null,[f,b]);return t.jsx(Bp,{entries:e,expandedGroups:r,onToggleGroupedItem:n,renderCommandGroup:(y,v,N)=>t.jsx(cf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:l,timeMeta:j(Ir(y))},y.key),renderFileChangeGroup:(y,v,N)=>t.jsx(mf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:s,timeMeta:j(Ir(y))},y.key),renderSearchGroup:(y,v,N)=>t.jsx(hf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:s,timeMeta:j(Ir(y))},y.key),renderFileReadGroup:(y,v,N)=>t.jsx(uf,{items:y.items,expanded:v,onToggleExpanded:N,onOpen:s,timeMeta:j(Ir(y))},y.key),renderItem:y=>{const v=Lf(y.item,f??null),S=y.item.kind==="userMessage"?y.item.createdAt?ft(v):p:y.item.createdAt?t.jsx(fr,{absoluteLabel:ft(v),timestamp:v,turnStartedAt:b??f}):p;return t.jsx(oa,{threadId:a,item:y.item,scrollRootRef:o,timeLabel:S,timeTitle:y.item.createdAt?Gt(v):g,timeMeta:j(v),autoOpenToolDetails:w&&y.key===x,onOpenExpandedText:s,onOpenCommandDetail:l,onOpenToolCallDetail:i,onOpenDeferredHistoryItemDetail:d,...u?{onBeforeMessageResize:u}:{},...h?{onSelectArtifact:h}:{},...m?{adapter:m}:{}},y.key)}})}var Ss=3,Mf=3,Un=80;function dr(e,r=Un){return e.scrollHeight-e.scrollTop-e.clientHeight<=r}function $f(e,r){const n=e.getBoundingClientRect(),a=r.getBoundingClientRect(),o=Math.max(n.top,a.top),s=Math.min(n.bottom,a.bottom);return Math.max(0,s-o)>0}function Df(e){return e.map(n=>{const a=n.createdAt;return typeof a=="string"&&a.trim()?a:null}).filter(n=>!!n).sort()[0]??null}function Bf(e,r){return{id:e,startedAt:Df(r),status:"inProgress",error:null,model:null,reasoningEffort:null,reasoningEffortAvailable:null,tokenUsage:null,priceEstimate:null,items:[]}}function Ts(e,r,n){return{id:e.id,kind:e.kind,title:r,text:n}}function Gf({loadHistoryItemDetail:e,onSelectHistoryItemDetail:r}){const n=c.useRef(0),a=c.useRef(new Map),[o,s]=c.useState(null),l=c.useCallback((p,g)=>{s({title:p,text:g})},[]),i=c.useCallback((p,g,b)=>{if(b&&r){r({item:p,detail:g});return}s({title:g.title,text:g.text})},[r]),d=c.useCallback(async({item:p,fallbackTitle:g,fallbackText:b,loadingText:w,errorText:x,useSelectionCallback:j})=>{if(!p.hasDeferredDetail||!e){i(p,Ts(p,g,b),j);return}const k=a.current.get(p.id);if(k){i(p,k,j);return}const y=n.current+1;n.current=y,j&&r||s({title:g,text:w});try{const v=await e(p.id);if(a.current.set(p.id,v),n.current!==y)return;i(p,v,j)}catch(v){if(n.current!==y)return;i(p,Ts(p,g,v instanceof Error?v.message:x),j)}},[e,r,i]),h=c.useCallback(async(p,g)=>{var b;await d({item:p,fallbackTitle:g,fallbackText:((b=p.detailText)==null?void 0:b.trim())||p.text||"Command output",loadingText:"Loading full command output...",errorText:"Unable to load full command output.",useSelectionCallback:!0})},[d]),u=c.useCallback(async(p,g)=>{var b;await d({item:p,fallbackTitle:g,fallbackText:((b=p.detailText)==null?void 0:b.trim())||p.text||"Tool call",loadingText:"Loading full tool call details...",errorText:"Unable to load full tool call details.",useSelectionCallback:!0})},[d]),m=c.useCallback(async(p,g,b,w,x)=>{await d({item:p,fallbackTitle:g,fallbackText:b,loadingText:w,errorText:x,useSelectionCallback:!1})},[d]),f=c.useCallback(()=>{n.current+=1,s(null)},[]);return{expandedText:o,openExpandedText:l,openCommandDetail:h,openToolCallDetail:u,openDeferredHistoryItemDetail:m,closeExpandedText:f}}function Ff(e){const r=c.useRef(null),n=c.useRef(0),a=r.current;return(a===null||a.length!==e.length||e.some((s,l)=>!Object.is(s,a[l])))&&(n.current+=1,r.current=e),n.current}function Hf({threadId:e,turnsLength:r,totalTurnCount:n,loadingEarlier:a,onLoadEarlier:o,scrollRequestKey:s,bottomSpacer:l,onTailVisibilityChange:i,contentRevisionInputs:d}){const h=c.useRef(null),u=c.useRef(null),m=c.useRef(s),f=c.useRef(null),p=c.useRef(l),g=c.useRef(0),b=c.useRef(0),w=c.useRef(null),x=c.useRef(null),j=c.useRef(null),k=c.useRef(!0),y=c.useRef(!0),v=c.useRef(!1),N=c.useRef(!1),S=c.useRef(!1),L=c.useRef(!1),z=c.useRef(null),V=c.useRef(0),[F,B]=c.useState(Ss),[J,Z]=c.useState(0),[D,ee]=c.useState(!0),oe=Ff(d),A=typeof o=="function"||n!==void 0,Q=n??r,R=A?0:Math.max(0,r-F),O=(A?Math.max(0,Q-r):0)+R,T=A?r:r-R,U=A?0:r-T,H=A?Math.max(0,Q-r):0,C=A?H+U:U,E=!A&&C>0&&J>=2,X=A&&H>0&&U===0&&typeof o=="function",Y=c.useCallback(()=>{const G=h.current;if(!G){w.current=null;return}w.current={scrollHeight:G.scrollHeight,scrollTop:G.scrollTop}},[]),ie=c.useCallback(()=>!X||a||S.current?!1:(Y(),S.current=!0,L.current=!1,V.current=0,o==null||o(),!0),[X,a,o,Y]),K=c.useCallback(()=>{const G=h.current,me=x.current;if(!G)return;const fe=me?$f(G,me):dr(G);k.current=fe,ee(we=>we===fe?we:fe)},[]),le=c.useCallback(()=>{const G=h.current;if(G){N.current=!0;const me=G.scrollTop,fe=b.current,we=me-fe;b.current=me,dr(G,1)?(v.current=!1,y.current=!0):we<-1?(v.current=!0,y.current=!1):we>1&&(y.current=!v.current&&dr(G,Un)),me<=0&&N.current?L.current=!0:me>0&&(L.current=!1,V.current=0)}K()},[K]),te=c.useCallback(()=>{const G=h.current;G&&(G.scrollTop=G.scrollHeight,b.current=G.scrollTop,g.current=G.scrollHeight,k.current=!0,ee(me=>me||!0),v.current=!1,y.current=!0)},[]),ge=c.useCallback(()=>{const G=h.current;G&&(b.current=G.scrollTop,g.current=G.scrollHeight,y.current=!1,v.current=!0)},[]),de=c.useCallback(()=>{if(A&&U===0){ie();return}B(G=>Math.min(r,G+Mf)),Z(G=>G+1)},[U,A,ie,r]),be=c.useCallback(G=>{const me=h.current;if(!(!me||G.deltaY>=-8||me.scrollTop>0||!X)){if(!L.current){L.current=!0;return}ie()}},[X,ie]),ze=c.useCallback(G=>{var me;z.current=((me=G.touches.item(0))==null?void 0:me.clientY)??null,V.current=0},[]),se=c.useCallback(G=>{var Ae;const me=h.current,fe=((Ae=G.touches.item(0))==null?void 0:Ae.clientY)??null,we=z.current;if(z.current=fe,!me||fe===null||we===null||me.scrollTop>0||!X){V.current=0;return}const Me=fe-we;if(Me<=0){V.current=0;return}if(!L.current){L.current=!0,V.current=0;return}V.current+=Me,V.current>=28&&ie()},[X,ie]),ye=c.useCallback(()=>{z.current=null,V.current=0},[]),je=c.useCallback(()=>{B(r)},[r]);return c.useLayoutEffect(()=>{const G=window.requestAnimationFrame(()=>{te()});return()=>{window.cancelAnimationFrame(G)}},[e,te]),c.useEffect(()=>{S.current=!1,N.current=!1,L.current=!1,w.current=null},[e]),c.useEffect(()=>{a||(S.current=!1)},[a,r]),c.useLayoutEffect(()=>{const G=w.current,me=h.current;if(!G||!me||a)return;w.current=null;const fe=me.scrollHeight-G.scrollHeight;if(fe<=0){g.current=me.scrollHeight,b.current=me.scrollTop;return}const we=G.scrollTop+fe;me.scrollTop=we,b.current=we,g.current=me.scrollHeight,v.current=!0,y.current=!1,L.current=!1},[a,r]),c.useEffect(()=>{B(G=>G>=r-1?r:Math.max(G,Ss))},[r]),c.useEffect(()=>{const G=h.current;G&&(g.current=G.scrollHeight,b.current=G.scrollTop,dr(G,1)?(v.current=!1,y.current=!0):(v.current||!dr(G,Un))&&(y.current=!1)),K()},[oe,K,F]),c.useEffect(()=>{const G=s!==m.current,me=f.current!==oe;if(f.current=oe,!(G||me&&y.current&&!v.current))return;const we=window.requestAnimationFrame(()=>{te()});return s!==m.current&&(m.current=s),()=>{window.cancelAnimationFrame(we)}},[oe,D,te,s]),c.useEffect(()=>{const G=h.current,me=u.current;if(!G||!me||typeof ResizeObserver>"u")return;g.current=G.scrollHeight;const fe=new ResizeObserver(()=>{const we=G.scrollHeight,Me=g.current;if(g.current=we,we<=Me)return;const Ae=Me>0&&Me-G.scrollTop-G.clientHeight<=1;v.current||!(y.current||Ae||k.current)||window.requestAnimationFrame(()=>{te()})});return fe.observe(me),()=>{fe.disconnect()}},[te]),c.useEffect(()=>{if(!y.current||v.current){p.current=l;return}if(l===p.current)return;p.current=l;const G=window.requestAnimationFrame(()=>{te()});return()=>{window.cancelAnimationFrame(G)}},[l,te]),c.useEffect(()=>{i==null||i(D)},[D,i]),{scrollContainerRef:h,scrollContentRef:u,tailSentinelRef:x,topSentinelRef:j,isTailVisible:D,handleScroll:le,handleWheel:be,handleTouchStart:ze,handleTouchMove:se,handleTouchEnd:ye,preserveScrollPositionForResize:ge,serverManagedHistory:A,effectiveTotalTurnCount:Q,startIndex:R,visibleTurnAbsoluteOffset:O,hiddenCount:C,loadedHiddenCount:U,unloadedHiddenCount:H,showLoadAll:E,handleLoadEarlierClick:de,handleLoadAllClick:je}}function Of(e){return e==="completed"||e==="failed"||e==="interrupted"}function Uf(e,r){if(!r||r.id!==e.id||r.items.length===0)return e;const n=new Set(e.items.map(o=>o.id)),a=r.items.filter(o=>!n.has(o.id));return a.length===0?e:{...e,items:[...a,...e.items]}}function Wf({threadId:e,turns:r,totalTurnCount:n,pendingRequests:a=[],activeTurnId:o=null,threadRunning:s=!1,pendingSteers:l=[],livePlan:i=null,liveItems:d=null,respondingRequestId:h=null,onRespondToRequest:u,liveOutput:m,scrollRequestKey:f=0,bottomSpacer:p=0,className:g="",onTailVisibilityChange:b,loadingEarlier:w=!1,onLoadEarlier:x,ephemeralUserNote:j=null,answeredRequestNotes:k=[],activityNotes:y=[],optimisticSteers:v=[],optimisticTurn:N=null,onLoadHistoryItemDetail:S,onOpenThread:L,onSelectArtifact:z,onSelectHistoryItemDetail:V,adapter:F,autoCollapseCompletedTurns:B}){var tt,I,W,pe,Pe;const J=tl(),Z=B??(J==null?void 0:J.autoCollapseCompletedTurns)??!1,[D,ee]=c.useState({}),[oe,A]=c.useState(()=>new Set),Q=(F==null?void 0:F.onLoadHistoryItemDetail)??S,R=F==null?void 0:F.onOpenLinkedThread,{expandedText:q,openExpandedText:O,openCommandDetail:T,openToolCallDetail:U,openDeferredHistoryItemDetail:H,closeExpandedText:C}=Gf({loadHistoryItemDetail:Q,onSelectHistoryItemDetail:V}),{scrollContainerRef:E,scrollContentRef:X,tailSentinelRef:Y,topSentinelRef:ie,handleScroll:K,handleWheel:le,handleTouchStart:te,handleTouchMove:ge,handleTouchEnd:de,preserveScrollPositionForResize:be,serverManagedHistory:ze,effectiveTotalTurnCount:se,startIndex:ye,visibleTurnAbsoluteOffset:je,hiddenCount:G,loadedHiddenCount:me,unloadedHiddenCount:fe,showLoadAll:we,handleLoadEarlierClick:Me,handleLoadAllClick:Ae}=Hf({threadId:e,turnsLength:r.length,totalTurnCount:n,loadingEarlier:w,onLoadEarlier:x,scrollRequestKey:f,bottomSpacer:p,onTailVisibilityChange:b,contentRevisionInputs:[r,a,l,v,m,i,d,N,k,y,j,p]}),Le=c.useCallback((re,Fe)=>{ee(Oe=>({...Oe,[re]:!Fe}))},[]),$e=c.useCallback((re,Fe)=>{const Oe=D[re.id];return Oe!==void 0?Oe:!!(Z&&Of(re.status)&&!Fe.forceActive&&!Fe.hasLiveActivity)},[D,Z]),_=ze?r:r.slice(ye),ue=se+1,ve=s&&(!o||!_.some(re=>re.id===o)&&(N==null?void 0:N.id)!==o),P=(N==null?void 0:N.id)??((tt=_.at(-1))==null?void 0:tt.id)??null,M=ve&&P!==null,ne=!!d&&(_.some(re=>re.id===d.turnId)||(N==null?void 0:N.id)===d.turnId),ke=d&&ne?d.turnId:d&&M?P:null,Ne=N&&ke===N.id?(d==null?void 0:d.items)??null:null,Ce=((d==null?void 0:d.items.length)??0)>0,_e=d&&ke===null?d.items:null,De=c.useMemo(()=>d&&ke===null&&d.items.length>0?Bf(d.turnId,d.items):null,[d,ke]),Ue=Math.max(1,se+(N?1:0)),ot=!!m&&!!N&&N.status!=="failed"&&!Ne,et=m&&_.length>0?o&&_.some(re=>re.id===o)?o:((I=_.findLast(re=>il(re.status)))==null?void 0:I.id)??(M?P:null):null,ut=!!et,at=c.useMemo(()=>ll(m),[m]),We=[...l.map(re=>({id:re.id,prompt:re.prompt,status:"Accepted",createdAt:re.createdAt,canCancel:!0})),...v.map(re=>({id:re.id,prompt:re.prompt,status:re.status==="steering"?"Steering":null,createdAt:re.createdAt,canCancel:!1}))].sort((re,Fe)=>re.createdAt.localeCompare(Fe.createdAt)),Ge=c.useMemo(()=>_p({answeredRequestNotes:k,pendingRequests:a,visibleTurns:_,optimisticTurn:N}),[k,N,a,_]),Ve=c.useMemo(()=>Mp({activityNotes:y,visibleTurns:_,optimisticTurn:N}),[y,N,_]);return t.jsxs(t.Fragment,{children:[t.jsx("section",{className:`flex min-h-0 flex-1 flex-col ${g}`.trim(),children:t.jsx("div",{ref:E,"data-testid":"thread-scroll-container",onScroll:K,onWheel:le,onTouchStart:te,onTouchMove:ge,onTouchEnd:de,onTouchCancel:de,className:"thread-graph-scroll-container min-h-0 flex-1 overflow-y-auto overscroll-contain",style:p>0?{paddingBottom:p}:void 0,children:t.jsxs("div",{ref:X,className:"thread-graph-scroll-content",children:[t.jsx("div",{ref:ie,"aria-hidden":"true",className:"h-px"}),r.length>0&&t.jsx("div",{className:"thread-graph-history-control px-3 pb-1 pt-2 sm:px-5 sm:pb-1.5 sm:pt-3",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 text-xs sm:text-sm",children:[G>0&&t.jsx("button",{type:"button",onClick:Me,disabled:w,className:"thread-graph-history-button rounded-full border px-2.5 py-1.5 transition",children:w?"Loading earlier...":"Load 3 earlier"}),we&&t.jsx("button",{type:"button",onClick:Ae,className:"rounded-full border border-amber-300/40 px-2.5 py-1.5 text-amber-200 transition hover:bg-amber-300/10",children:"Load full history"}),t.jsxs("p",{className:"timeline-meta-text",children:["Showing ",_.length," of ",se," turns",G>0?` · ${G} earlier hidden${me>0&&fe>0?` (${me} loaded)`:""}`:""]})]})}),r.length===0&&!m&&!N&&t.jsx("div",{className:"thread-graph-empty-state px-3 py-8 text-sm sm:px-5",children:"Send the first prompt to start the thread."}),(_.length>0||N||Ve.leading.length>0||Ve.trailing.length>0)&&t.jsxs("div",{className:"thread-graph-message-list",children:[Ve.leading.length>0?t.jsx(ir,{notes:Ve.leading,onOpenThread:L,onOpenLinkedThread:R}):null,_.map((re,Fe)=>{var Oe,He,Xe,dt,xt;return t.jsxs("div",{children:[(((Oe=Ve.beforeTurnId.get(re.id))==null?void 0:Oe.length)??0)>0?t.jsx(ir,{notes:Ve.beforeTurnId.get(re.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null,(((He=Ge.beforeTurnId.get(re.id))==null?void 0:He.length)??0)>0?t.jsx(Hn,{entries:Ge.beforeTurnId.get(re.id)??[],respondingRequestId:h,onRespondToRequest:u??void 0}):null,(()=>{const lt=Uf(re,N),wt=(i==null?void 0:i.turnId)===re.id?i:null,yt=ke===re.id?(d==null?void 0:d.items)??null:null,jt=et===re.id?m:"",xe=o===re.id||M&&P===re.id,Ie=!!wt||!!jt||!!(yt&&yt.length>0),rt=$e(lt,{forceActive:xe,hasLiveActivity:Ie});return t.jsx(bn,{threadId:e,...F?{adapter:F}:{},turn:lt,absoluteIndex:je+Fe+1,isCollapsed:rt,livePlan:wt,liveItems:yt,liveOutput:jt,forceActive:xe,onToggleCollapse:Le,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},scrollRootRef:E,articleRef:void 0})})(),(((Xe=Ve.afterTurnId.get(re.id))==null?void 0:Xe.length)??0)>0?t.jsx(ir,{notes:Ve.afterTurnId.get(re.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null,(dt=Ge.notesByTurnId.get(re.id))!=null&&dt.length||(xt=Ge.pendingRequestsByTurnId.get(re.id))!=null&&xt.length?t.jsx($p,{notes:Ge.notesByTurnId.get(re.id)??[],requests:Ge.pendingRequestsByTurnId.get(re.id)??[],respondingRequestId:h,onRespondToRequest:u??void 0}):null]},re.id)}),N&&_.every(re=>re.id!==N.id)&&t.jsxs(t.Fragment,{children:[(((W=Ve.beforeTurnId.get(N.id))==null?void 0:W.length)??0)>0?t.jsx(ir,{notes:Ve.beforeTurnId.get(N.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null,(((pe=Ge.beforeTurnId.get(N.id))==null?void 0:pe.length)??0)>0?t.jsx(Hn,{entries:Ge.beforeTurnId.get(N.id)??[],respondingRequestId:h,onRespondToRequest:u??void 0}):null,(()=>{const re=ot?m:"",Fe=o===N.id||M&&P===N.id,Oe=!!(Ne&&Ne.length>0)||!!re,He=$e(N,{forceActive:Fe,hasLiveActivity:Oe});return t.jsx(bn,{threadId:e,...F?{adapter:F}:{},turn:N,absoluteIndex:ue,isCollapsed:He,livePlan:null,liveItems:Ne,liveOutput:re,forceActive:Fe,onToggleCollapse:Le,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},scrollRootRef:E})})(),(((Pe=Ve.afterTurnId.get(N.id))==null?void 0:Pe.length)??0)>0?t.jsx(ir,{notes:Ve.afterTurnId.get(N.id)??[],onOpenThread:L,onOpenLinkedThread:R}):null]})]}),We.length>0&&t.jsx("div",{className:"thread-graph-message-section space-y-3 px-3 py-4 sm:px-5",children:We.map(re=>t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(Et,{threadId:e,item:{id:re.id,kind:"userMessage",text:re.prompt,status:re.status},scrollRootRef:E,onBeforeMessageResize:be,...F?{adapter:F}:{}}),e&&re.canCancel&&(F!=null&&F.cancelPendingSteer)?t.jsx("div",{className:"flex justify-end px-1",children:t.jsx("button",{type:"button",className:"thread-graph-history-button rounded-full border px-2.5 py-1 text-xs transition disabled:cursor-not-allowed disabled:opacity-60",disabled:oe.has(re.id),onClick:()=>{var Fe;A(Oe=>new Set(Oe).add(re.id)),Promise.resolve((Fe=F.cancelPendingSteer)==null?void 0:Fe.call(F,e,re.id)).catch(()=>{}).finally(()=>{A(Oe=>{const He=new Set(Oe);return He.delete(re.id),He})})},children:oe.has(re.id)?"Canceling...":"Cancel"})}):null]},re.id))}),(Ge.trailing.length>0||Ve.trailing.length>0)&&t.jsx(Dp,{entries:[...Ve.trailing.map(re=>({kind:"activity",id:re.id,createdAt:re.createdAt,note:re})),...Ge.trailing],respondingRequestId:h,onRespondToRequest:u??void 0,onOpenThread:L,onOpenLinkedThread:R}),j&&t.jsx("div",{className:"thread-graph-message-section px-3 py-2.5 sm:px-5",children:t.jsx(Et,{threadId:e,item:{id:"ephemeral-plan-decision-note",kind:"userMessage",text:j},scrollRootRef:E,onBeforeMessageResize:be})}),De&&_e&&_e.length>0&&t.jsx(bn,{threadId:e,...F?{adapter:F}:{},turn:De,absoluteIndex:Ue,isCollapsed:D[De.id]??!1,livePlan:(i==null?void 0:i.turnId)===De.id?i:null,liveItems:_e,liveOutput:"",forceActive:!0,onToggleCollapse:Le,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},scrollRootRef:E}),m&&!ut&&!ot&&!Ce&&t.jsx("div",{className:"thread-graph-message-section px-3 py-2.5 sm:px-5",children:at?t.jsx(oa,{threadId:e,item:at,scrollRootRef:E,onOpenExpandedText:O,onOpenCommandDetail:T,onOpenToolCallDetail:U,onOpenDeferredHistoryItemDetail:H,onBeforeMessageResize:be,...z?{onSelectArtifact:z}:{},...F?{adapter:F}:{}}):t.jsx(Et,{threadId:e,item:{id:"live-agent-message-fallback",kind:"agentMessage",text:m},scrollRootRef:E,streaming:!0,onBeforeMessageResize:be,...F?{adapter:F}:{}})}),t.jsx("div",{ref:Y,"aria-hidden":"true",className:"h-px w-full"})]})})}),t.jsx(Qm,{open:q!==null,title:(q==null?void 0:q.title)??"Full text",text:(q==null?void 0:q.text)??"",onClose:C})]})}var bl=c.memo(Wf);function Vf(e){return/^[a-z]$/i.test(e)?String.fromCharCode(e.toUpperCase().charCodeAt(0)-64):null}function Wn(e){return e.replace(/\r\n/g,`
3669
3667
  `)}function Es(e){const r=Wn(e),n=r.split(`
3670
3668
  `);return r.endsWith(`
3671
3669
  `)&&n.at(-1)===""&&n.pop(),n}function Kf(e){const r=e.trim();return r?/(?:[$%#>])\s*$/.test(r):!1}function qf(e,r){const n=r.trim();if(!n||e.length===0)return e;const[a,...o]=e;if(a===void 0)return e;const s=a.trim();return s===n||s.endsWith(` ${n}`)||s.endsWith(`$ ${n}`)||s.endsWith(`% ${n}`)||s.endsWith(`# ${n}`)||s.endsWith(`> ${n}`)?o:e}function Xf(e,r,n){var d,h;const a=Es(e),o=Es(r);let s=0;for(;s<a.length&&s<o.length&&a[s]===o[s];)s+=1;let l=0;for(;l<a.length-s&&l<o.length-s&&a[a.length-1-l]===o[o.length-1-l];)l+=1;let i=o.slice(s,o.length-l);for(i=qf(i,n);i.length>0&&((d=i[0])==null?void 0:d.trim())==="";)i.shift();for(;i.length>0&&(((h=i.at(-1))==null?void 0:h.trim())===""||Kf(i.at(-1)??""));)i.pop();return i.join(`