PageSourceSearch

https://shajinjoseph-template.hf.space/assets/eventSelection.xdAX3598.js

js shajinjoseph-template.hf.space collected 2026-10-03 17:22:45 UTC 211,579 bytes, 19 lines download raw bytes

1import{a as e}from"./rolldown-runtime.B0Z9INg1.js";import{at as t,rt as n}from"./advanced-inputs.0gHsBjsU.js";import{$n as r,Bi as i,Cr as a,Ct as o,Di as s,Dt as c,En as l,Et as u,Fn as d,Fo as f,Fr as p,Gr as m,Gt as h,Hn as g,Ii as _,Li as v,Lo as y,Mo as b,Ni as x,Nn as S,Nt as C,Po as w,Pr as T,Ra as E,Ti as D,Wr as O,Xn as k,Yr as A,Yt as j,Zn as M,Zr as N,Zt as P,_ as F,_i as I,ai as L,br as ee,ci as R,co as z,fo as te,ii as ne,ji as B,jr as re,jt as ie,mi as ae,mr as V,nr as H,qn as oe,sn as se,tr as ce,uo as le,ur as ue,wt as de,x as fe,yn as pe,za as me,zi as he,zt as ge}from"./vendor.DMhDOqx5.js";import{t as _e}from"./i18n.CenFdT2j.js";import{r as ve}from"./query-devtools.DIz6FZCX.js";import{v as ye}from"./tanstack-vendor.2R6Ja_-H.js";import{$d as be,$r as xe,$u as Se,Af as Ce,Ag as we,Ai as Te,Ao as Ee,Ar as De,At as Oe,Bf as ke,Bg as Ae,Bn as je,Br as Me,C_ as Ne,Cr as Pe,Ct as Fe,Dl as Ie,Dp as Le,Dr as Re,Dt as ze,Ep as Be,Er as Ve,Fn as He,Fo as Ue,Fr as We,Fs as Ge,Gf as Ke,Gi as qe,Gn as Je,Gp as Ye,Gr as Xe,Gu as Ze,Hg as U,Ho as Qe,Hr as $e,If as et,Ii as tt,Ip as nt,Ir as rt,Jf as it,Jh as at,Jr as ot,Ju as st,K_ as ct,Kf as lt,Kh as W,Kn as ut,Kr as dt,Ku as ft,Li as pt,Lp as mt,Lr as ht,Lt as gt,Ma as _t,Mr as vt,N_ as yt,Na as bt,Nu as xt,Of as St,Og as Ct,Ol as wt,Op as Tt,Ot as Et,Ou as Dt,Ph as Ot,Pn as kt,Pp as At,Pr as jt,Ps as Mt,Qn as Nt,Qu as Pt,Ri as Ft,Rp as It,Rr as Lt,Rt,Ru as G,So as zt,Sr as Bt,Tr as Vt,Tu as Ht,U_ as Ut,Ui as Wt,Up as Gt,Ur as Kt,Us as qt,Uu as Jt,V_ as Yt,Vf as Xt,Vi as Zt,Vl as Qt,Vr as $t,Vu as en,Wh as tn,Wi as nn,Wn as rn,Wo as an,Wr as on,Ws as sn,Xn as cn,Xr as ln,Xu as un,Yh as dn,Yr as fn,Yu as pn,Zu as mn,_d as hn,_i as gn,_n,_r as vn,_s as yn,ad as bn,ai as xn,ap as Sn,b as Cn,bf as wn,bi as Tn,br as En,bu as Dn,cg as On,ci as kn,cl as An,cm as jn,co as Mn,cs as K,dd as Nn,dg as Pn,di as Fn,ed as In,ef as Ln,eg as Rn,ei as zn,f_ as q,fd as Bn,fh as Vn,fi as Hn,fs as Un,g_ as Wn,gi as Gn,gr as Kn,hd as qn,hi as Jn,hn as Yn,ia as Xn,id as Zn,ii as Qn,jg as $n,ji as er,jl as tr,kd as nr,kf as rr,kg as ir,ko as ar,kt as or,ld as sr,lm as cr,ln as lr,m_ as ur,mf as dr,mi as fr,mp as pr,nd as mr,ni as hr,od as gr,oi as _r,om as vr,p_ as J,pa as yr,pd as br,pi as xr,pn as Sr,qf as Cr,qn as wr,qr as Tr,qu as Er,rd as Dr,ri as Or,sd as kr,sg as Ar,si as jr,sm as Mr,t_ as Nr,ta as Pr,td as Fr,tg as Ir,ti as Lr,ui as Rr,um as zr,uv as Br,vf as Vr,vg as Hr,vi as Ur,vr as Wr,wr as Gr,wt as Kr,xh as qr,xo as Jr,xp as Y,xr as Yr,y as Xr,yg as Zr,yi as Qr,yr as $r,z_ as ei,zd as ti,zg as X,zi as ni,zl as ri,zr as ii}from"./hooks.B1NLB7i6.js";import{n as ai}from"./animations.BHEQrG-H.js";import{a as oi,i as si,s as ci,t as li}from"./SetKeyDialog.CjfHrHkh.js";import{o as ui}from"./markdown-processing.CjMf2xPH.js";import{n as di,r as fi}from"./markdown.N65uYq6U.js";import{i as pi}from"./forms.DQMwNapF.js";var Z=e(t(),1),Q=n(),mi=e=>e===`failed`||e===`interrupted`||e===`cancelled`,hi=e=>e===`completed`?B:e===`failed`||e===`interrupted`?x:e===`cancelled`?s:D,gi=e=>({dispatched:`com_ui_subagent_thread_status_dispatched`,running:`com_ui_subagent_thread_status_running`,completed:`com_ui_subagent_thread_status_completed`,failed:`com_ui_subagent_thread_status_failed`,interrupted:`com_ui_subagent_thread_status_interrupted`,cancelled:`com_ui_subagent_thread_status_cancelled`})[e],_i=e=>e===`completed`?`bg-status-success`:e===`running`?`bg-status-info`:e===`failed`||e===`interrupted`?`bg-status-error`:e===`cancelled`?`bg-status-warning`:`bg-text-tertiary`,vi=e=>e===`running`||e===`dispatched`;function yi(e){let t=[],n=new Map;for(let r of e??[]){let e=r.workspaceChange;if(e?.profile!==`stateful`||!r.filepath){t.push(r);continue}let i=r,a=i.file_id??`${i.agentId??``}:${e.path}`;n.delete(a),n.set(a,r)}return{inlineAttachments:t,workspaceChanges:Array.from(n.values())}}var bi=(0,Z.memo)(({attachment:e})=>{let t=K(),n=e,r=e.workspaceChange.path,i=r.split(`/`).pop()||r,{handleDownload:a}=Wt({href:e.filepath??``,filename:i,file_id:n.file_id,user:n.user,source:n.source});return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 rounded-lg bg-surface-secondary px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate text-sm font-medium text-text-primary`,title:i,children:i}),r!==i&&(0,Q.jsx)(`div`,{className:`truncate text-xs text-text-secondary`,title:r,children:r})]}),(0,Q.jsx)(zr,{onClick:e=>void a(e),label:`${t(`com_ui_download`)} ${i}`,title:t(`com_ui_download`),variant:`ghost`,size:`sm`,shape:`square`,className:`text-text-secondary`,children:(0,Q.jsx)(ae,{className:`size-4`,"aria-hidden":`true`})})]})});bi.displayName=`WorkspaceChange`;function xi({attachments:e}){let t=K(),n=(0,Z.useId)(),[r,i]=(0,Z.useState)(!1),{style:a,ref:o}=Et(r),s=e.length,c=t(s===1?`com_ui_one_file_changed`:`com_ui_n_files_changed`,{0:String(s)}),l=(0,Z.useMemo)(()=>e.map(e=>
1e.workspaceChange.path).join(`, `),[e]);return s===0?null:(0,Q.jsxs)(`div`,{className:`my-2 max-w-xl`,children:[(0,Q.jsxs)(Y,{variant:`ghost`,"aria-expanded":r,"aria-controls":n,"aria-label":`${t(`com_ui_workspace_changes`)}: ${c}`,onClick:()=>i(e=>!e),className:`h-auto max-w-full justify-start py-1 pl-0 pr-2 font-normal text-text-secondary`,children:[(0,Q.jsx)(O,{className:`size-4 shrink-0`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`shrink-0 font-medium`,children:t(`com_ui_workspace_changes`)}),(0,Q.jsxs)(`span`,{className:`min-w-0 truncate text-xs`,title:l,children:[`— `,c]}),(0,Q.jsx)(he,{className:G(`size-4 shrink-0 transition-transform duration-200 ease-out`,r&&`rotate-180`),"aria-hidden":`true`})]}),(0,Q.jsx)(`div`,{id:n,style:a,inert:r?void 0:``,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:o,"aria-hidden":!r,children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 pt-2`,children:e.map(e=>(0,Q.jsx)(bi,{attachment:e},`${e.filepath}:${e.workspaceChange.path}`))})})})]})}var Si=e=>e?.[q.memory]!=null&&!e.toolCallId,Ci=e=>e?.some(Si)??!1;function wi({attachments:e}){let t=(0,Z.useId)(),n=K(),[r,i]=(0,Z.useState)(!1),{style:a,ref:o}=Et(r),{hasErrors:s,memoryArtifacts:c}=(0,Z.useMemo)(()=>{let t=!1,n=[];if(!e||e.length===0)return{hasErrors:t,memoryArtifacts:n};for(let r of e)Si(r)&&(n.push(r[q.memory]),!t&&r[q.memory].type===`error`&&(t=!0));return{hasErrors:t,memoryArtifacts:n}},[e]);return c.length===0?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`relative my-1 flex h-5 shrink-0 items-center gap-2.5`,children:(0,Q.jsxs)(Y,{variant:`ghost`,className:G(`group/disclosure h-auto w-full justify-start gap-2 rounded-none p-0 font-normal hover:bg-transparent`,s?`text-status-error`:`text-text-secondary`),onClick:()=>i(e=>!e),"aria-expanded":r,"aria-controls":t,"aria-label":n(`com_ui_memory_updated`),children:[(0,Q.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,className:`size-4 shrink-0`,"aria-hidden":`true`,children:[(0,Q.jsx)(`path`,{d:`M6 3C4.89543 3 4 3.89543 4 5V13C4 14.1046 4.89543 15 6 15L6 3Z`,fill:`currentColor`}),(0,Q.jsx)(`path`,{d:`M7 3V15H8.18037L8.4899 13.4523C8.54798 13.1619 8.69071 12.8952 8.90012 12.6858L12.2931 9.29289C12.7644 8.82153 13.3822 8.58583 14 8.58578V3.5C14 3.22386 13.7761 3 13.5 3H7Z`,fill:`currentColor`}),(0,Q.jsx)(`path`,{d:`M11.3512 15.5297L9.73505 15.8529C9.38519 15.9229 9.07673 15.6144 9.14671 15.2646L9.46993 13.6484C9.48929 13.5517 9.53687 13.4628 9.60667 13.393L12.9996 10C13.5519 9.44771 14.4473 9.44771 14.9996 10C15.5519 10.5523 15.5519 11.4477 14.9996 12L11.6067 15.393C11.5369 15.4628 11.448 15.5103 11.3512 15.5297Z`,fill:`currentColor`})]}),(0,Q.jsx)(`span`,{className:`tool-status-text font-medium`,children:n(s?`com_ui_memory_error`:`com_ui_memory_updated`)}),(0,Q.jsx)(he,{className:G(Ot({expanded:r}),`size-4 translate-y-[1px]`),"aria-hidden":`true`})]})}),(0,Q.jsx)(`div`,{id:t,style:a,role:`group`,"aria-label":n(`com_ui_memory_updated`),"aria-hidden":!r||void 0,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:o,children:(0,Q.jsx)(`div`,{className:G(fn,`overflow-hidden rounded-lg border border-border-light bg-surface-secondary`),children:r&&(0,Q.jsx)(Yr,{memoryArtifacts:c},`memory-info`)})})})]})}function Ti(){let e=K();return(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-lg border border-border-medium bg-surface-secondary p-4 text-center`,role:`alert`,"aria-live":`polite`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-sm text-text-secondary`,children:`Sources temporarily unavailable`}),(0,Q.jsx)(Y,{variant:`outline`,size:`sm`,onClick:()=>window.location.reload(),"aria-label":e(`com_ui_reload_page`),children:e(`com_ui_refresh`)})]})}var Ei=class extends Z.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error(`Sources error:`,e),this.props.onError?.(e,t)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:(0,Q.jsx)(Ti,{}):this.props.children}};function Di({source:e,expanded:t=!1}){let n=K(),r=pt(e.link);return t?(0,Q.jsxs)(`a`,{href:e.link,target:`_blank`,rel:`noopener noreferrer`,className:`flex w-full flex-col rounded-lg bg-surface-primary-contrast px-3 py-2 text-sm transition-all duration-300 hover:bg-surface-tertiary`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(tt,{domain:r}),(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:r})]}),(0,Q.jsxs)(`div`,{className:`mt-1`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 text-sm font-medium text-text-primary md:line-clamp-3`,children:e.title||e.link}),`snippet`in e&&e.snippet&&(0,Q.jsx)(`span`,{className:`mt-1 line-clamp-2 text-xs text-text-secondary md:line-clamp-3`,children:e.snippet})]})]}):(0,Q.jsx)(`span`,{className:`not-prose relative inline-block h-full w-full`,children:(0,Q.jsx)(E,{showTimeout:150,hideTimeout:150,children:(0,Q.jsxs)(`div`,{className:`flex h-full items-center`,children:[(0,Q.jsx)(z,{render:(0,Q.jsxs)(`a`,{href:e.link,target:`_blank`,rel:`noopener noreferrer`,className:`flex h-full w-full flex-col rounded-lg bg-surface-primary-contrast px-3 py-2 text-sm transition-all duration-300 hover:bg-surface-tertiary`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(tt,{domain:r}),(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:r})]}),(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(`span`,{className:`line-clamp-2 text-sm font-medium text-text-primary md:line-clamp-3`,children:e.title||e.link})})]})}
1),(0,Q.jsxs)(me,{className:`absolute right-2 rounded-full text-text-primary focus:outline-none focus:ring-2 focus:ring-text-primary`,children:[(0,Q.jsx)(te,{children:n(`com_citation_more_details`,{label:r})}),(0,Q.jsx)(he,{className:`icon-sm`,"aria-hidden":`true`})]}),(0,Q.jsx)(le,{gutter:16,className:G(`z-[999] w-[320px] max-w-[calc(100vw-2rem)] rounded-xl border border-border-medium bg-surface-secondary p-3 text-text-primary shadow-lg`,`origin-top-left scale-95 opacity-0 transition-[opacity,transform] duration-150 ease-out`,`data-[enter]:scale-100 data-[enter]:opacity-100`,`data-[leave]:scale-95 data-[leave]:opacity-0`),portal:!0,unmountOnHide:!0,children:(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`mb-1.5 overflow-hidden text-sm`,children:[(0,Q.jsx)(tt,{domain:r,className:`float-left mr-2 mt-0.5`}),(0,Q.jsx)(`span`,{className:`float-right ml-2 max-w-[40%] truncate text-xs text-text-secondary`,children:r}),(0,Q.jsx)(`a`,{href:e.link,target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-text-primary hover:underline`,children:e.title||e.link})]}),`snippet`in e&&e.snippet&&(0,Q.jsx)(`p`,{className:`line-clamp-4 break-words text-xs text-text-secondary md:text-sm`,children:e.snippet})]}),`imageUrl`in e&&e.imageUrl&&(0,Q.jsx)(`div`,{className:`size-24 shrink-0 overflow-hidden rounded-md`,children:(0,Q.jsx)(`img`,{src:e.imageUrl,alt:e.title||n(`com_sources_image_alt`),className:`size-full object-cover`})})]})})]})})})}function Oi({image:e}){let t=K();return(0,Q.jsx)(`a`,{href:e.imageUrl,target:`_blank`,rel:`noopener noreferrer`,className:`group overflow-hidden rounded-lg bg-surface-secondary transition-all duration-300 hover:bg-surface-tertiary`,children:e.imageUrl&&(0,Q.jsxs)(`div`,{className:`relative aspect-square w-full overflow-hidden`,children:[(0,Q.jsx)(`img`,{src:e.imageUrl,alt:e.title||t(`com_sources_image_alt`),className:`size-full object-cover`}),e.title&&(0,Q.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 w-full border-none bg-gray-900/80 p-1 text-xs font-medium text-white backdrop-blur-sm`,children:(0,Q.jsx)(`span`,{className:`truncate`,children:e.title})})]})})}function ki(e,t){return!t||Object.keys(t).length===0?e:[...e].sort((e,n)=>{let r=t[e]||0;return(t[n]||0)-r})}var Ai=Z.memo(function({file:e,messageId:t,conversationId:n,expanded:r=!1}){let i=K(),a=w(Dn.user),{showToast:o}=tn(),{refetch:s}=wt(a?.id??``,e.file_id,{source:e.source});(0,Z.useCallback)(e=>{let t=JSON.stringify(e),n=e;return e?.message?.includes(`local files`)||n?.response?.data?.error?.includes(`local files`)||n?.response?.status===403||t.includes(`local files`)||t.includes(`403`)?i(`com_sources_download_local_unavailable`):i(`com_sources_download_failed`)},[i]);let c=e.metadata?.storageType===`local`,l=(0,Z.useCallback)(async t=>{if(t.preventDefault(),t.stopPropagation(),!c)try{let t=await s();if(t.data==null||t.data===``){console.error(`Error downloading file: No data found`),o({status:`error`,message:i(`com_ui_download_error`)});return}hn(t.data,e.filename)}catch(e){console.error(`Error downloading file:`,e)}},[s,e.filename,c,i,o]),u=(0,Z.useMemo)(()=>{let t=e.type?.toLowerCase()||``;return t.includes(`pdf`)?`📄`:t.includes(`image`)?`🖼️`:t.includes(`text`)?`📝`:t.includes(`word`)||t.includes(`doc`)?`📄`:t.includes(`excel`)||t.includes(`sheet`)?`📊`:t.includes(`powerpoint`)||t.includes(`presentation`)?`📈`:`📎`},[e.type]),d=i(`com_sources_download_aria_label`,{filename:e.filename,status:``});return r?(0,Q.jsxs)(`button`,{onClick:c?void 0:l,disabled:!1,className:`flex w-full flex-col rounded-lg bg-surface-primary-contrast px-3 py-2 text-sm transition-all duration-300 disabled:opacity-50 ${c?`cursor-default`:`hover:bg-surface-tertiary`}`,"aria-label":c?i(`com_sources_download_local_unavailable`):d,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-base`,children:u}),(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:i(`com_sources_agent_file`)}),!c&&(0,Q.jsx)(ae,{className:`ml-auto size-3`,"aria-hidden":`true`})]}),(0,Q.jsxs)(`div`,{className:`mt-1 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 break-words text-left text-sm font-medium text-text-primary md:line-clamp-3`,children:e.filename}),e.pages&&e.pages.length>0&&(0,Q.jsxs)(`span`,{className:`mt-1 line-clamp-1 text-left text-xs text-text-secondary`,children:[i(`com_sources_pages`),`:`,` `,ki(e.pages,e.pageRelevance).join(`, `)]}),e.bytes&&(0,Q.jsxs)(`span`,{className:`mt-1 line-clamp-1 text-xs text-text-secondary`,children:[(e.bytes/1024).toFixed(1),` KB`]})]}),null]}):(0,Q.jsxs)(`button`,{onClick:c?void 0:l,disabled:!1,className:`flex h-full w-full flex-col rounded-lg bg-surface-primary-contrast px-3 py-2 text-sm transition-all duration-300 disabled:opacity-50 ${c?`cursor-default`:`hover:bg-surface-tertiary`}`,"aria-label":c?i(`com_sources_download_local_unavailable`):d,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-base`,children:u}),(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:i(`com_sources_agent_file`)}),!c&&(0,Q.jsx)(ae,{className:`ml-auto size-3`,"aria-hidden":`true`})]}),(0,Q.jsxs)(`div`,{className:`mt-1 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 break-words text-left text-sm font-medium text-text-primary md:line-clamp-3`,children:e.filename}),e.pages&&e.pages.length>0&&(0,Q.jsxs)(`span`,{className:`mt-1 line-clamp-1 text-left text-xs text-text-secondary`,children:[i(`com_sources_pages`),`:`,` `,ki(e.pages,e.pageRelevance).join(`, `)]})]}),null]})});function ji({sources:e,start:t=0,end:n=3}){let r=[t,n];return t<0&&(r=[t]),(0,Q.jsx)(`div`,{className:`relative flex`,children:e.slice(...r).map((e,t)=>(0,Q.jsx)(tt,{domain:pt(e.link),className:t>0?`ml-[-6px]`:``},`icon-${t}`))})}var Mi=Z.memo(function({sources:e,limit:t=3}){let n=K(),{visibleSources:r,remainingSources:i,hasMoreSources:a}=(0,Z.useMemo)(()=>{let n=e.slice(0,t),r=e.slice(t);return{visibleSources:n,remainingSources:r,hasMoreSources:r.length>0}},[e,t]);return(0,Q.jsx)(`div`,{className:`scrollbar-none grid w-full grid-cols-4 gap-2 overflow-x-auto`,children:(0,Q.jsxs)(nt,{children:[r.map((e,t)=>(0,Q.jsx)(`div`,{className:`w-full min-w-[120px]`,children:(0,Q.jsx)(Di,{source:e})},`source-${t}`)),a&&(0,Q.jsx)(Ye,{className:`flex flex-col rounded-lg bg-surface-primary-contrast px-3 py-2 text-sm transition-all duration-300 hover:bg-surface-tertiary`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ji,{sources:i}),(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:n(`com_sources_more_sources`,{count:i.length})})]})}),(0,Q.jsxs)(It,{className:`flex max-h-[80vh] max-w-full flex-col overflow-hidden rounded-lg bg-surface-dialog p-0 md:max-w-[600px]`,children:[(0,Q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between border-b border-border-light bg-surface-dialog px-3 py-2`,children:[(0,Q.jsx)(Gt,{className:`text-base font-medium`,children:n(`com_sources_title`)}),(0,Q.jsx)(mt,{className:`rounded-full p-1 text-text-secondary hover:bg-surface-tertiary hover:text-text-primary`,"aria-label":n(`com_ui_close`),children:(0,Q.jsx)(C,{className:`size-4`,"aria-hidden":`true`})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:[...r,...i].map((e,t)=>(0,Q.jsxs)(`a`,{href:e.link,target:`_blank`,rel:`noopener noreferrer`,className:`flex gap-2 rounded-lg px-2 py-2 transition-colors hover:bg-surface-tertiary`,children:[(0,Q.jsx)(tt,{domain:pt(e.link),className:`h-5 w-5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`h3`,{className:`mb-0.5 truncate text-sm font-medium text-text-primary`,children:e.title||e.link}),`snippet`in e&&e.snippet&&(0,Q.jsx)(`p`,{className:`mb-1 line-clamp-2 text-xs text-text-secondary md:line-clamp-3`,children:e.snippet}),(0,Q.jsx)(`span`,{className:`text-xs text-text-secondary-alt`,children:pt(e.link)})]}
1),`imageUrl`in e&&e.imageUrl&&(0,Q.jsx)(`div`,{className:`hidden h-12 w-12 flex-shrink-0 overflow-hidden rounded-md sm:block`,children:(0,Q.jsx)(`img`,{src:e.imageUrl,alt:e.title||n(`com_sources_image_alt`),className:`h-full w-full object-cover`})})]},`more-source-${t}`))})})]})]})})});function Ni({files:e,messageId:t,conversationId:n,limit:r=3}){let i=K(),a=e.length<=r+1?e.length:r,o=e.slice(0,a),s=e.slice(a),c=s.length>0;return(0,Q.jsx)(`div`,{className:`scrollbar-none grid w-full grid-cols-4 gap-2 overflow-x-auto`,children:(0,Q.jsxs)(nt,{children:[o.map((e,r)=>(0,Q.jsx)(`div`,{className:`w-full min-w-[120px]`,children:(0,Q.jsx)(Ai,{file:e,messageId:t,conversationId:n})},`file-${r}`)),c&&(0,Q.jsx)(Ye,{className:`flex flex-col rounded-lg bg-surface-primary-contrast px-3 py-2 text-sm transition-all duration-300 hover:bg-surface-tertiary`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`relative flex`,children:s.slice(0,3).map((e,t)=>(0,Q.jsx)(m,{className:`size-4 ${t>0?`ml-[-6px]`:``}`},`file-icon-${t}`))}),(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-text-secondary`,children:i(`com_sources_more_files`,{count:s.length})})]})}),(0,Q.jsxs)(It,{className:`flex max-h-[80vh] max-w-full flex-col overflow-hidden rounded-lg bg-surface-dialog p-0 md:max-w-[600px]`,children:[(0,Q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between border-b border-border-light bg-surface-dialog px-3 py-2`,children:[(0,Q.jsx)(Gt,{className:`text-base font-medium`,children:i(`com_sources_agent_files`)}),(0,Q.jsx)(mt,{className:`rounded-full p-1 text-text-secondary hover:bg-surface-tertiary hover:text-text-primary`,"aria-label":i(`com_ui_close`),children:(0,Q.jsx)(C,{className:`size-4`,"aria-hidden":`true`})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:[...o,...s].map((e,r)=>(0,Q.jsx)(Ai,{file:e,messageId:t,conversationId:n,expanded:!0},`more-file-${r}`))})})]})]})})}function Pi({label:e,icon:t}){return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md px-3 py-1 text-sm transition-colors hover:bg-surface-tertiary hover:text-text-primary`,children:[Z.cloneElement(t,{size:14,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:e})]})}function Fi({messageId:e,conversationId:t}={}){let n=K(),{searchResults:r}=zt(),{organicSources:i,topStories:o,images:s,hasAnswerBox:c,agentFiles:l}=(0,Z.useMemo)(()=>{let t=new Map,n=new Map,i=new Map,a=new Map,o=!1;if(!r)return{organicSources:[],topStories:[],images:[],hasAnswerBox:!1,agentFiles:[]};for(let s of Object.values(r))s&&(s.organic?.forEach(e=>{e.link&&t.set(e.link,e)}),s.references?.forEach(n=>{if(n.type===`image`)i.set(n.link,{...n,imageUrl:n.link});else if(n.type===`file`){let t=n.fileId||`unknown`,r=n.title||`Unknown File`,i=`${t}_${r}`;if(a.has(i)){let e=a.get(i),t=e.pages||[],r=n.pages||[];e.pages=[...new Set([...t,...r])].sort((e,t)=>e-t),e.relevance=Math.max(e.relevance||0,n.relevance||0),e.pageRelevance={...e.pageRelevance,...n.pageRelevance}}else{let o={type:q.file_search,file_id:t,filename:r,bytes:void 0,metadata:n.metadata,pages:n.pages,relevance:n.relevance,pageRelevance:n.pageRelevance,messageId:e||``,toolCallId:`file_search_results`};a.set(i,o)}}else n.link&&t.set(n.link,n)}),s.topStories?.forEach(e=>{e.link&&n.set(e.link,e)}),s.images?.forEach(e=>{e.imageUrl&&i.set(e.imageUrl,e)}),s.answerBox&&(o=!0));return{organicSources:Array.from(t.values()),topStories:Array.from(n.values()),images:Array.from(i.values()),hasAnswerBox:o,agentFiles:Array.from(a.values())}},[r,e]),u=(0,Z.useMemo)(()=>{let r=[];return(i.length||o.length||c)&&r.push({label:(0,Q.jsx)(Pi,{label:n(`com_sources_tab_all`),icon:(0,Q.jsx)(re,{})}),content:(0,Q.jsx)(Mi,{sources:[...i,...o]})}),o.length&&r.push({label:(0,Q.jsx)(Pi,{label:n(`com_sources_tab_news`),icon:(0,Q.jsx)(g,{})}),content:(0,Q.jsx)(Mi,{sources:o,limit:3})}),s.length&&r.push({label:(0,Q.jsx)(Pi,{label:n(`com_sources_tab_images`),icon:(0,Q.jsx)(a,{})}),content:(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5`,children:s.map((e,t)=>(0,Q.jsx)(Oi,{image:e},`image-${t}`))})}),l.length&&e&&t&&r.push({label:(0,Q.jsx)(Pi,{label:n(`com_sources_tab_files`),icon:(0,Q.jsx)(m,{})}),content:(0,Q.jsx)(Ni,{files:l,messageId:e,conversationId:t,limit:3})}),r},[i,o,s,c,l,e,t,n]);return u.length?(0,Q.jsx)(`div`,{role:`region`,"aria-label":n(`com_sources_region_label`),children:(0,Q.jsx)(pr,{tabs:u,containerClassName:`flex min-w-full mb-4`,tabListClassName:`flex items-center mb-2 border-b border-border-light overflow-x-auto`,tabPanelClassName:`w-full overflow-x-auto scrollbar-none md:mx-0 md:px-0`,tabClassName:`flex items-center whitespace-nowrap text-xs font-medium text-token-text-secondary px-1 pt-2 pb-1 border-b-2 border-transparent data-[state=active]:text-text-primary outline-none focus:ring-2 focus:ring-text-primary focus:ring-offset-2`})}):null}function Ii(e){let t=K(),n=(e,t)=>{console.error(`Sources component error:`,{error:e,errorInfo:t})},r=(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-lg border border-border-medium bg-surface-secondary p-4 text-center`,role:`alert`,"aria-live":`polite`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-sm text-text-secondary`,children:t(`com_sources_error_fallback`)}),(0,Q.jsx)(Y,{variant:`outline`,size:`sm`,onClick:()=>window.location.reload(),className:`rounded-md bg-surface-primary px-3 py-1 text-sm text-text-primary hover:bg-surface-hover`,"aria-label":t(`com_sources_reload_page`),children:t(`com_ui_refresh`)})]});
1return(0,Q.jsx)(Ei,{onError:n,fallback:r,showDetails:!1,children:(0,Q.jsx)(Fi,{...e})})}function Li({agentId:e,messageId:t,createdAt:n,conversationId:r,isSubmitting:i}){let a=Un(),o=K(),{showToast:s}=tn(),c=fi(r??null,{onSuccess:()=>{s({message:o(`com_ui_branch_created`),status:`success`})},onError:()=>{s({message:o(`com_ui_branch_error`),status:`error`})}}),l=()=>{!t||!e||i||c.isLoading||c.mutate({messageId:t,agentId:e})},{displayName:u,displayEndpoint:d,displayModel:f,agent:p}=(0,Z.useMemo)(()=>{if(e){let t=Ct(e),n=a?.[t];if(n)return{displayName:n.name,displayEndpoint:Ae.agents,displayModel:n.model,agent:n};let r=Hr(e);return r?{displayName:r.sender||r.model||`AI`,displayEndpoint:r.endpoint,displayModel:r.model,agent:void 0}:{displayName:t,displayEndpoint:Ae.agents,displayModel:void 0,agent:void 0}}return{displayName:`Agent`,displayEndpoint:Ae.agents,displayModel:void 0,agent:void 0}},[e,a]);return(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 border-b border-border-light pb-2`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center overflow-hidden rounded-full`,children:(0,Q.jsx)(Gr,{message:{endpoint:d,model:f,isCreatedByUser:!1},agent:p||void 0})}),(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium text-text-primary`,children:u}),(0,Q.jsx)(Je,{value:n})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:l,disabled:!t||!e||i||c.isLoading,className:G(`flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md`,`text-text-secondary transition-colors hover:bg-surface-hover hover:text-text-primary`,`focus:outline-none focus:ring-2 focus:ring-border-medium focus:ring-offset-1`,`disabled:cursor-not-allowed disabled:opacity-50`,(!t||!e||i)&&`invisible`),"aria-label":o(`com_ui_branch_message`),title:o(`com_ui_branch_message`),children:(0,Q.jsx)(T,{className:`h-4 w-4`,"aria-hidden":`true`})})]})}function Ri({skills:e,source:t=`manual`}){let n=K();return!e||e.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 py-0.5`,role:`list`,"aria-label":n(t===`always-apply`?`c
1om_ui_skills_always_apply_invoked`:`com_ui_skills_manual_invoked`),children:e.map(e=>(0,Q.jsxs)(`span`,{role:`listitem`,"data-skill-source":t,className:`inline-flex items-center gap-1 rounded-full border border-border-light bg-surface-secondary px-2 py-1 text-xs text-text-secondary`,children:[t===`always-apply`?(0,Q.jsx)(S,{className:`h-3 w-3 text-status-info`,"aria-hidden":`true`}):(0,Q.jsx)(pe,{className:`h-3 w-3 text-status-info`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`max-w-[12rem] truncate`,children:e})]},e))})}var zi=(0,Z.memo)(Ri),Bi=(0,Z.memo)(({message:e})=>{let t=Qe(),{shareId:n}=an(),r=(0,Z.useMemo)(()=>et(e?.files,void 0,n?void 0:t),[e?.files,t,n]),i=(0,Z.useMemo)(()=>r?.filter(Xt)||[],[r]),a=(0,Z.useMemo)(()=>r?.filter(e=>!Xt(e))||[],[r]),[o,s]=(0,Z.useState)(null),c=(0,Z.useCallback)(e=>{e||s(null)},[]);return(0,Q.jsxs)(Q.Fragment,{children:[a.length>0&&a.map(e=>(0,Q.jsx)(qe,{file:e,onClick:()=>s(e)},e.file_id)),i.length>0&&i.map(e=>(0,Q.jsx)(nn,{alignRight:!0,imagePath:e.preview??e.filepath??``,height:e.height??1920,width:e.width??1080,altText:e.filename??`Uploaded Image`},e.file_id)),(0,Q.jsx)(Qn,{open:o!==null,onOpenChange:c,fileName:o?.filename??``,fileId:o?.file_id,filePath:o?.filepath,fileType:o?.type??void 0,fileSource:o?.source,fileSize:o?.bytes,deliveryPath:o?.llmDeliveryPath})]})}),Vi=({children:e,message:t})=>(0,Q.jsxs)(`div`,{className:`text-message flex min-h-[20px] flex-col items-start gap-3 overflow-visible [.text-message+&]:mt-5`,dir:`auto`,children:[t?.isCreatedByUser===!0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(rn,{quotes:t.quotes}),(0,Q.jsx)(Bi,{message:t}),(0,Q.jsx)(zi,{skills:t.alwaysAppliedSkills,source:`always-apply`}),(0,Q.jsx)(zi,{skills:t.manualSkills,source:`manual`})]}),e]});function Hi(e,t=0,n,r){if(!e)return{parallelSections:[],sequentialParts:[]};let i=new Map,a=new Map,o=[];e.forEach((e,r)=>{if(!e)return;let s=n?.[r]??r+t,{groupId:c}=e,l=e.agentId;if(c!=null){if(!e.type&&l){a.has(c)||a.set(c,new Set),a.get(c).add(l);return}i.has(c)||i.set(c,[]),i.get(c).push({part:e,idx:s})}else o.push({part:e,idx:s})});let s=new Set([...i.keys(),...a.keys()]),c=[];for(let e of s){let t=new Map,n=i.get(e)??[];for(let{part:e,idx:r}of n){let n=e.agentId??`unknown`;t.has(n)||t.set(n,[]),t.get(n).push({part:e,idx:r})}let s=a.get(e);if(s)for(let e of s)t.has(e)||t.set(e,[]);let l=Array.from(t.keys()).sort((e,t)=>{let n=e.includes(`____`),r=t.includes(`____`);return n&&!r?1:!n&&r?-1:0}).map(e=>({agentId:e,parts:t.get(e)}));if(l.filter(({agentId:e,parts:t})=>e!==`unknown`&&(t.length===0||t.some(({part:e})=>!Bn(e)))).length<2&&r?.has(e)!==!0){for(let e of l)o.push(...e.parts);continue}c.push({groupId:e,columns:l})}return c.sort((e,t)=>{let n=e.columns.flatMap(e=>e.parts.map(e=>e.idx)),r=t.columns.flatMap(e=>e.parts.map(e=>e.idx));return(n.length>0?Math.min(...n):1/0)-(r.length>0?Math.min(...r):1/0)}),o.sort((e,t)=>e.idx-t.idx),{parallelSections:c,sequentialParts:o}}var Ui=(0,Z.memo)(function({columns:e,groupId:t,messageId:n,createdAt:r,conversationId:i,isSubmitting:a,lastContentIdx:o,renderPart:s}){return(0,Q.jsx)(`div`,{className:G(`flex w-full flex-col gap-3 md:flex-row`,`sibling-content-group`),children:e.map(({agentId:e,parts:c},l)=>{let u=c.filter(({part:e})=>e?.type!==W.ACTIVITY_LABEL||bn(Zn(e)).length>0),d=Wi(u),f=a&&u.length===0;return(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 rounded-lg border border-border-light p-3`,children:[(0,Q.jsx)(Li,{agentId:e,messageId:n,createdAt:r,isSubmitting:a,conversationId:i}),f?(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{})}):u.map(({part:e,idx:t})=>s(e,t,t===d&&t===o))]},`column-${n}-${t}-${e||l}`)})})});function Wi(e){let t=sr(e.map(({part:e})=>e));return t<0?-1:e[t]?.idx??-1}var Gi=(0,Z.memo)(function({content:e,messageId:t,createdAt:n,conversationId:r,attachments:i,searchResults:a,isSubmitting:o,renderPart:s,renderResumeAttribution:c,showDecorations:l=!0,contentIndexOffset:u=0,contentIndices:d,laneGroups:f}){let{parallelSections:p,sequentialParts:m}=(0,Z.useMemo)(()=>Hi(e,u,d,f),[e,u,d,f]),h=sr(e),g=h<0?-1:d?.[h]??h+u,{blocks:_,trailing:v}=(0,Z.useMemo)(()=>{let e=[],t=0;for(let n of p){let r=n.columns.flatMap(e=>e.parts.map(e=>e.idx)),i=r.length>0?Math.min(...r):1/0,a=[];for(;t<m.length&&m[t].idx<i;)a.push(m[t]),t+=1;e.push({leading:a,section:n})}return{blocks:e,trailing:m.slice(t)}},[p,m]),y=({part:e,idx:t})=>{let n=c?.(t,Ln(e,t)),r=s(e,t,t===g);return n==null?[r]:[n,r]};return(0,Q.jsxs)(Jr.Provider,{value:{searchResults:a},children:[l&&(0,Q.jsx)(wi,{attachments:i}),l&&(0,Q.jsx)(Ii,{messageId:t,conversationId:r||void 0}),_.map(({leading:e,section:{groupId:i,columns:a}})=>(0,Q.jsxs)(Z.Fragment,{children:[e.flatMap(y),(0,Q.jsx)(Ui,{columns:a,groupId:i,messageId:t,createdAt:n,renderPart:s,isSubmitting:o,conversationId:r,lastContentIdx:g})]},`parallel-block-${t}-${i}`)),v.flatMap(y)]})});function Ki({skillName:e,loaded:t}){let n=K()(t?`com_ui_skill_finished`:`com_ui_skill_running`,{0:e});return(0,Q.jsx)(`div`,{className:bt,children:(0,Q.jsx)(`div`,{className:`progress-text-wrapper text-token-text-secondary relative -mt-[0.75px] h-5 w-full leading-5`,children:(0,Q.jsx)(`div`,{className:`progress-text-content absolute left-0 right-0 top-0 max-w-full overflow-visible whitespace-nowrap`,style:{opacity:1,transform:`none`},children:(0,Q.jsxs)(`div`,{className:`inline-flex w-full items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:_t,"aria-hidden":`true`,children:(0,Q.jsx)(pe,{className:G(`size-4 shrink-0 text-text-secondary`,!t&&`animate-pulse`)})}),(0,Q.jsx)(`span`,{className:G(!t&&`shimmer`,`min-w-0 truncate font-medium`),children:n})]})})})})}function qi(e){if(e.length>64e3||!e.includes(`
2`))return e;let t=e.split(`
3`);return t.length>500?e:t.map(e=>{let t=e.trim();if(t.length<2||t.length>8e3||!(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`)))return e;try{let n=JSON.parse(t);if(typeof n!=`object`||!n)return e;let r=e.slice(0,e.length-e.trimStart().length);return`${r}${JSON.stringify(n,null,2).replace(/\n/g,`\n${r}`)}`}catch{return e}}).join(`
4`)}var Ji=new Set([`delivery_scheduled`,`result_persisting`]);function Yi(e){if(e==null)return;if(e.kind===`notice`)return e.status===`cancelled`?`cancelled`:Ji.has(e.status)?void 0:`failed`;if(e.kind===`list`)return e.partial||e.warning?`failed`:void 0;let t=e.task.status;return t===`cancelled`?`cancelled`:t===`error`||t===`failed`||t===`interrupted`||t===`not_running`||t===`control_not_found`?`failed`:void 0}var Xi=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Zi=e=>e===void 0||typeof e==`string`,Qi=e=>e===`cancellation_requested`?`stopping`:e===`running`||e===`accepted`||e===`claimed`||e===`
4not_running`||e===`control_not_found`||e===`completed`||e===`error`||e===`cancelled`||e===`dispatched`||e===`failed`||e===`interrupted`?e:null,$i=e=>e===void 0||e===`pending`||e===`failed`||e===`delivered`;function ea(e){if(!Xi(e))return null;let t=Qi(e.status);return typeof e.background_task_id!=`string`||e.background_task_id===``||typeof e.tool!=`string`||e.tool===``||t==null||!Zi(e.result)||!Zi(e.error)||!Zi(e.note)||!Zi(e.message)||!Zi(e.subagent_type)||e.result_available!=null&&typeof e.result_available!=`boolean`||e.result_claimed!=null&&typeof e.result_claimed!=`boolean`||!$i(e.delivery)?null:{taskId:e.background_task_id,toolName:e.tool,status:t===`running`&&e.cancellation_requested===!0?`stopping`:t,...typeof e.result==`string`?{result:e.result}:{},...typeof e.error==`string`?{error:e.error}:{},...typeof e.note==`string`?{note:e.note}:{},...typeof e.message==`string`?{message:e.message}:{},...typeof e.subagent_type==`string`?{subagentType:e.subagent_type}:{},...e.result_available===!0?{resultAvailable:!0}:{},...e.result_claimed===!0?{resultClaimed:!0}:{},...e.delivery==null?{}:{delivery:e.delivery}}}function ta(e){if(!e||e.length>2e6)return null;let t=e.trim();if(!t.startsWith(`{`)||!t.endsWith(`}`))return null;let n;try{n=JSON.parse(t)}catch{return null}if(!Xi(n)||`tasks`in n&&!Array.isArray(n.tasks))return null;if(Array.isArray(n.tasks)){let e=n.tasks.map(ea);return e.some(e=>e==null)?null:{kind:`list`,tasks:e,partial:n.partial===!0,...typeof n.warning==`string`?{warning:n.warning}:{},...typeof n.message==`string`?{message:n.message}:{}}}let r=ea(n);return r==null?typeof n.status==`string`&&typeof n.message==`string`?{kind:`notice`,status:n.status,message:n.message}:null:{kind:`task`,task:r}}var na=new Set([`py`,`python`]);function ra(e,t){if(e===X.BASH_PROGRAMMATIC_TOOL_CALLING)return!0;if(e!==X.PROGRAMMATIC_TOOL_CALLING)return!1;let n=Jn(t,`lang`)||Jn(t,`runtime`)||Jn(t,`language`);return!na.has(n.toLowerCase())}
4function ia(e){return typeof e==`string`&&Qr(e)}function aa(e,t,n){return e===`create_file`&&n?.startsWith(`Updated `)?`edit_file`:ra(e,t)?q.bash_tool:e}function oa(e,t,n){if(e==null)return{hasOutput:t,failed:n,cancelled:!1};let r=en({runStepStatus:e,displayProgress:1,reportedProgress:1,isSubmitting:!1,hasError:n});return{hasOutput:r!==`running`,failed:r===`failed`,cancelled:r===`cancelled`}}function sa(e,t,n){if(e.type!==W.TOOL_CALL)return null;let r=e[W.TOOL_CALL];if(!r)return null;let i=r.runStepStatus;if(`args`in r&&(!r.type||r.type===Ir.TOOL_CALL)){let e=r,a=!!e.output||e.progress===1,o=e.name??``,s=aa(o,e.args,e.output),c=lt(t?.[e.id??``],e.agentId,r.stepId,r.stepId==null?n:void 0),l=o===`set_memory`||o===`delete_memory`?En(o,e.output??``)||(c??[]).some(e=>e[q.memory]?.type===`error`):ia(e.output),u=Lt(e.output),{backgroundStatus:d,fileAttachments:f}=ii(c,e.id),p=d!=null||(f?.length??0)>0,m=u!=null&&d===`error`,h=Yi(o===X.CHECK_BACKGROUND_TASK?ta(e.output):null),g=e.backgroundTask?.cancelled===!0||u!=null&&d===`cancelled`||h===`cancelled`;return{name:o,iconName:s,...u!=null&&{background:p?`finished`:`running`},...oa(g?`cancelled`:i,a,l||m||h===`failed`)}}if(r.type===Ir.CODE_INTERPRETER){let e=r.code_interpreter;return{name:`code_interpreter`,iconName:`code_interpreter`,...oa(i,(e?.outputs?.length??0)>0,!1)}}if(r.type===Ir.RETRIEVAL||r.type===Ir.FILE_SEARCH){let e=r.output;return{name:`file_search`,iconName:`file_search`,...oa(i,!!e,ia(e))}}if(r.type===Ir.FUNCTION&&Ir.FUNCTION in r){let e=r.function;return{name:e.name,iconName:e.name,...oa(i,!!e.output,ia(e.output))}}return null}function ca({failed:e,cancelled:t}){if(e>0)return`failed`;if(t>0)return`cancelled`}var la=new WeakMap,ua=e=>{let t=e[W.TOOL_CALL];return{id:t?.id??``,stepId:t?.stepId}};function da(e,t){let n,r=r=>{if(t?.[r]!=null){if(n==null){n=new Map;for(let t of e){if(t?.type!==W.TOOL_CALL)continue;let e=ua(t);if(e.id===``||e.stepId==null)continue;let r=n.get(e.id)??new Set;r.add(e.stepId),n.set(e.id,r)}}return n.get(r)}},i=e=>{if(e.type!==W.TOOL_CALL)return null;let{id:n}=ua(e),i=t?.[n],a=r(n),o=a==null?``:Array.from(a).join(`|`),s=la.get(e);if(s!=null&&s.attachments===i&&s.siblings===o)return s.meta;let c=sa(e,t,a);return la.set(e,{attachments:i,siblings:o,meta:c}),c},a=0,o=0,s=0,c=0,l;for(let t of e){t?.type===W.AGENT_UPDATE&&(l=void 0,c=0);let e=t==null?null:i(t);e!=null&&(s+=1,c=e.iconName===l?c+1:1,l=e.iconName),e?.failed===!0&&(a+=1),e?.cancelled===!0&&(o+=1)}return{failed:a,cancelled:o,total:s,trailingToolCount:c,metaOf:i}}var fa=e=>{if(e.type!==W.TOOL_CALL)return;let t=e[W.TOOL_CALL];return t!=null&&`args`in t?t:void 0};function pa(e){if(e==null)return!1;if(mr(e)||Dr(e))return!0;let t=fa(e);return t==null?!1:t.name===`ask_user_question`?(t.output?.length??0)===0&&st(t.id)===void 0:Array.isArray(t.subagent_content)&&t.subagent_content.some(pa)}function ma(e,t,n,r,i){let a=xr(t.args),o=Se(t.name??``,n,r),s=i.metaOf(e);if(s?.cancelled===!0)return{text:n(`com_ui_cancelled`),generic:!1};if(s?.failed===!0){let e=a??o;return{text:e?n(`com_ui_failed_subject`,{0:e}):n(`com_ui_failed`),generic:!1}}return s?.background==null?a==null?t.name===X.CHECK_BACKGROUND_TASK?{text:n(s?.hasOutput===!0?`com_ui_background_tasks_checked`:`com_ui_background_tasks_checking`),generic:!0}:o?{text:n(s?.hasOutput===!0?`com_assistants_completed_function`:`com_assistants_running_var`,{0:o}),generic:!0}:{text:n(`com_assistants_running_action`),generic:!0}:{text:a,generic:!1}:{text:n(s.background===`running`?`com_ui_background_running`:`com_ui_background_finished`),generic:!1}}var ha=1e3;function ga(e){let t=e.slice(-1200).replace(/^\s*<think>\s*/,``).replace(/\s*<\/think>\s*$/,``).trimEnd();if(!t)return;let n=/[.!?](?:\s+|$)|[。!?]\s*/g,r=0,i;for(let e=n.exec(t);e!=null;e=n.exec(t))i=t.slice(r,e.index+1),r=e.index+e[0].length;return i==null?void 0:Hn(i)}function _a(e){let t=fa(e);return t?.name===X.SUBAGENT&&(t.output?.length??0)===0&&t.progress!==1&&t.runStepStatus==null}function va(e){return e==null?!1:pa(e)||_a(e)}var ya=4,ba=24;function xa(e){let t=new Set,n=Math.max(0,e.length-ba);for(let r=e.length-1;r>=n&&t.size!==ya;--r){let n=e[r],i=n==null?void 0:fa(n);if(i!=null){let e=i.name??``;t.add(aa(e,i.args,i.output));continue}let a=n==null?null:sa(n);a!=null&&t.add(a.iconName)}return Array.from(t).reverse()}function Sa(e,t,n){let r=n.metaOf(e);return t.id!=null&&r!=null&&!r.hasOutput&&!r.failed&&!r.cancelled&&r.background==null&&xr(t.args)==null}function Ca(e,t,n,r,i){for(let a=e.length-1;a>=0;--a){let o=e[a];if(o==null)continue;if(o.type===W.THINK){let e=typeof o.think==`string`?o.think:o.think?.value??``,n=o.reasoning_label?.trim();if(i){if(n)return{text:n,source:`think:${a}`,comboCount:1};continue}let r=ga(e);if(r!=null)return{text:r,source:`think:${a}`,comboCount:1};if(n||e.trim())return{text:n||t(`com_ui_thinking`),source:`think:${a}`,comboCount:1};continue}if(o.type===W.TEXT){let e=typeof o.text==`string`?o.text:o.text?.value??``,t=i?void 0:Hn(e);if(t!=null)return{text:t,source:`text:${a}`,comboCount:1};continue}let s=bn(gr(o));if(s)return{text:s,source:`label:${a}`,comboCount:1};let c=fa(o);if(!(c!=null&&i)&&c!=null){let e=ma(o,c,t,n,r);return{text:e.text,source:`tool:${c.id??``}:${a}`,comboCount:e.generic?Math.max(1,r.trailingToolCount):1,...c.name===X.CHECK_BACKGROUND_TASK&&{isBackgroun
4dTaskCheck:!0},...Sa(o,c,r)&&{pendingToolCallId:c.id}}}}return i&&e.some(e=>e!=null)?{text:t(`com_ui_running`),source:`running`,comboCount:1}:{text:``,source:``,comboCount:1}}function wa(e,t,n,r,i=!1){let a=da(e,r);return{...Ca(e,t,n,a,i),outcome:{failed:a.failed,cancelled:a.cancelled},total:a.total,iconNames:xa(e)}}var Ta=/^Error processing tool:?\s*/i,Ea=/^Error:\s*/i;function Da(e){if(!e||!Qr(e))return``;let t=$n(e).replace(Ta,``).replace(Ea,``).trim(),n=t.indexOf(`
5`);return n===-1?t:t.slice(0,n).trim()}function Oa(e,t,n,r){let i=da(e,r),a=[];for(let r of e){if(r==null)continue;let e=i.metaOf(r),o=fa(r);if(e?.failed!==!0||o==null)continue;let s=In(o.name??``,n),c=xr(o.args)??(s.mcpServer?s.toolName:Se(s.raw,t,n)),l=o.backgroundTask?.settledAt??(e.background!=null||o.backgrounded?void 0:o.runStepClosedAt);a.push({text:c?t(`com_ui_failed_subject`,{0:c}):t(`com_ui_failed`),detail:Da(o.output),iconName:e.iconName,...l!=null&&{failedAt:l}})}return a}function ka(e){let t=new Map;for(let n of Object.values(e))n&&(n.organic?.forEach(e=>{e.link&&t.set(e.link,e)}),n.topStories?.forEach(e=>{e.link&&t.set(e.link,e)}));return Array.from(t.values())}function Aa(e,t){let n=new Set,r=[];for(let i of e){let e=pt(i.link);if(!n.has(e)&&(n.add(e),r.push(i),r.length>=t))break}return r}var ja=[];function Ma(e,t){let n={};for(let t of e??[]){let e=t.type===q.web_search?t[q.web_search]:void 0;if(e!=null){let r=JSON.stringify([t.toolCallId,t.agentId,t.stepId,e.turn??0]);n[r]=e}}let r=Aa(ka(n),t);return r.length===0?ja:r.map(e=>pt(e.link))}var Na=e=>e!=null&&di(e)?e:void 0,Pa=e=>Na(e.thumbnailUrl)??Na(e.imageUrl),Fa=e=>Na(e.link)??Na(e.googleUrl)??Na(e.imageUrl),Ia=8,La=5;function Ra(e){let t=[e.name,e.address].filter(Boolean).join(`, `),n=e.latitude!=null&&e.longitude!=null?`${e.latitude},${e.longitude}`:``;if(Mn){let e=new URLSearchParams;return t&&e.set(`q`,t),n&&e.set(`ll`,n),`https://maps.apple.com/?${e.toString()}`}return`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(t||n)}`}function za(e){let t=[],n=[],r=[];for(let i of e??[]){let e=i.type===q.web_search?i[q.web_search]:void 0;if(e){for(let n of e.images??[])Pa(n)&&Fa(n)&&t.push(n);for(let t of e.shopping??[])Na(t.link)&&t.title&&n.push(t);for(let t of e.places??[])(t.name||t.address)&&r.push(t)}}return{images:t,shopping:n,places:r}}function Ba({rating:e,ratingCount:t}){return e==null?null:(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-text-secondary`,children:[(0,Q.jsx)(P,{className:`size-3 fill-current`,"aria-hidden":`true`}),e,t!=null&&(0,Q.jsxs)(`span`,{className:`text-text-secondary`,children:[`(`,t,`)`]})]})}function Va({images:e,label:t}){return(0,Q.jsx)(`ul`,{className:`flex list-none gap-2 overflow-x-auto pb-1`,"aria-label":t,children:e.slice(0,Ia).map((e,n)=>{let r=Fa(e),i=e.thumbnailWidth&&e.thumbnailHeight?`${e.thumbnailWidth} / ${e.thumbnailHeight}`:`1 / 1`;return(0,Q.jsx)(`li`,{className:`shrink-0`,children:(0,Q.jsx)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,"aria-label":e.title||e.domain||t,className:`block h-28 overflow-hidden rounded-xl border border-border-light no-underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy`,style:{aspectRatio:i},children:(0,Q.jsx)(`img`,{src:Pa(e),alt:e.title||``,className:`h-full w-full object-cover`,loading:`lazy`})})},`${Pa(e)??``}|${r??``}|${n}`)})})}function Ha({items:e,label:t}){return(0,Q.jsx)(`ul`,{className:`flex list-none gap-2.5 overflow-x-auto pb-1`,"aria-label":t,children:e.slice(0,Ia).map((e,t)=>(0,Q.jsx)(`li`,{className:`flex w-40 shrink-0`,children:(0,Q.jsxs)(`a`,{href:Na(e.link),target:`_blank`,rel:`noopener noreferrer`,className:`flex w-full flex-col rounded-xl border border-border-light p-2 no-underline transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy`,children:[Na(e.imageUrl)&&(0,Q.jsx)(`div`,{className:`mb-2 aspect-square w-full shrink-0 overflow-hidden rounded-lg bg-surface-tertiary`,children:(0,Q.jsx)(`img`,{src:Na(e.imageUrl),alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),(0,Q.jsx)(`span`,{className:`mt-auto block truncate text-xs font-medium text-text-primary`,children:e.title}),(e.price||e.source)&&(0,Q.jsx)(`span`,{className:`mt-0.5 block truncate text-[11px] text-text-secondary`,children:[e.price,e.source].filter(
5Boolean).join(` · `)}),e.delivery&&(0,Q.jsx)(`span`,{className:`block truncate text-[11px] text-text-secondary`,children:e.delivery}),(0,Q.jsx)(`span`,{className:`mt-0.5 block`,children:(0,Q.jsx)(Ba,{rating:e.rating,ratingCount:e.ratingCount})})]})},`${e.productId??``}|${Na(e.link)??``}|${t}`))})}function Ua({places:e,label:t}){return(0,Q.jsx)(`ul`,{className:`list-none overflow-hidden rounded-lg border border-border-light`,"aria-label":t,children:e.slice(0,La).map((e,t)=>(0,Q.jsx)(`li`,{className:G(t>0&&`border-t border-border-light`),children:(0,Q.jsxs)(`a`,{href:Ra(e),target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2.5 px-3 py-2 no-underline transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy`,children:[(0,Q.jsx)(H,{className:`size-4 shrink-0 text-text-secondary`,"aria-hidden":`true`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-xs font-medium text-text-primary`,children:e.name}),(e.category||e.address)&&(0,Q.jsx)(`span`,{className:`block truncate text-[11px] text-text-secondary`,children:[e.category,e.address].filter(Boolean).join(` · `)})]}),(0,Q.jsx)(`span`,{className:`shrink-0`,children:(0,Q.jsx)(Ba,{rating:e.rating,ratingCount:e.ratingCount})})]})},`${e.identifier||`${e.name??``}|${e.address??``}`}|${t}`))})}function Wa({attachments:e}){let t=K(),{images:n,shopping:r,places:i}=za(e);return n.length===0&&r.length===0&&i.length===0?null:(0,Q.jsxs)(`div`,{className:`my-1.5 space-y-2`,children:[n.length>0&&(0,Q.jsx)(Va,{images:n,label:t(`com_ui_web_search_images`)}),r.length>0&&(0,Q.jsx)(Ha,{items:r,label:t(`com_ui_web_search_shopping`)}),i.length>0&&(0,Q.jsx)(Ua,{places:i,label:t(`com_ui_web_search_places`)})]})}var Ga=`duration-300 [animation-timing-function:cubic-bezier(0.16,1,0.3,1)]`;function Ka(e){let t;return t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>{t=void 0,e()})}),()=>{t!=null&&(window.cancelAnimationFrame(t),t=void 0)}}function qa({failed:e}){let t=e?h:i;return(0,Q.jsx)(`span`,{className:G(_t,e?`text-text-warning`:`text-text-secondary`),"aria-hidden":`true`,children:(0,Q.jsx)(t,{size:14})})}function Ja({text:e}){return(0,Q.jsx)(`span`,{className:`shimmer max-w-full truncate align-top`,children:e})}var Ya=(0,Z.memo)(function({text:e,animate:t,failed:n,source:r,live:i=!1,grow:a=!0,lineId:o}){let[s,c]=(0,Z.useState)({current:e,retired:null,entered:!1,source:r});if(s.current!==e||s.source!==r){let n=r==null||r!==s.source,i=t&&s.current.length>0&&n;c({current:e,retired:i?s.current:null,entered:i||s.entered&&r!=null&&r===s.source,source:r})}let l=(0,Z.useCallback)(()=>{c(e=>e.retired==null?e:{...e,retired:null})},[]);return(0,Q.jsxs)(`span`,{className:G(`tool-status-text relative block min-w-0 overflow-hidden text-left`,a&&`flex-1`),title:e,children:[s.retired!=null&&(0,Q.jsx)(`span`,{className:G(`absolute inset-x-0 top-0 block truncate`,`animate-out fade-out-0 slide-out-to-top-5 fill-mode-forwards`,Ga,n&&`text-text-warning`),onAnimationEnd:e=>e.target===e.currentTarget&&l(),"aria-hidden":`true`,children:i?(0,Q.jsx)(Ja,{text:s.retired}):s.retired},`retired-${s.retired}`),(0,Q.jsx)(`span`,{id:o,className:G(`block truncate`,s.entered&&`animate-in fade-in-0 slide-in-from-bottom-5 ${Ga}`,n&&`text-text-warning`),children:i?(0,Q.jsx)(Ja,{text:s.current}):s.current},`current-${r??s.current}`)]})}),Xa=4,Za=3;function Qa({parts:e,attachments:t}){let n=Te(),r=(0,Z.useMemo)(()=>xa(e),[e]),i=(0,Z.useMemo)(()=>da(e,Cr(t??[])),[e,t]),a=(0,Z.useMemo)(()=>Ma(t,Za),[t]);return r.length===0&&i.failed===0&&i.cancelled===0?(0,Q.jsx)(qa,{failed:!1}):(0,Q.jsx)(`span`,{className:G(_t,`text-text-secondary`),"aria-hidden":`true`,children:(0,Q.jsx)(Tn,{toolNames:r,mcpIconMap:n,maxIcons:Xa,sourceDomains:a,status:ca(i)})})}function $a({parts:e,animate:t,expanded:n,lineId:r,comboId:i,detailId:a,attachments:o,onAnnounce:s}){let c=K(),l=Te(),u=er(),d=(0,Z.useMemo)(()=>Cr(o??[]),[o]),f=(0,Z.useMemo)(()=>wa(e,c,u,d,n),[e,c,u,d,n]),p=de(Ht(f.pendingToolCallId??``))&&f.pendingToolCallId!=null,m=p?c(`com_ui_sandbox_starting`):f.text,h=p?1:f.comboCount,{source:g}=f,_=(0,Z.useMemo)(()=>
5({text:m,source:g,comboCount:h,isBackgroundTaskCheck:f.isBackgroundTaskCheck}),[m,g,h,f.isBackgroundTaskCheck]),v=Fe(_,g.startsWith(`think:`)?ha:500),y=f.iconNames.join(`|`),b=(0,Z.useMemo)(()=>y?y.split(`|`):[],[y]),x=(0,Z.useMemo)(()=>Ma(o,Za),[o]),{failed:S,cancelled:C}=f.outcome,w=f.total,T=``;v.comboCount>1&&(T=v.isBackgroundTaskCheck?`· ${c(`com_ui_background_tasks_n_checks`,{0:String(v.comboCount)})}`:`×${v.comboCount}`);let E=S>0?c(`com_ui_n_of_n_actions_failed`,{0:String(S),1:String(w)}):``,D=C>0?c(C===1?`com_ui_one_action_cancelled`:`com_ui_n_actions_cancelled`,{0:String(C)}):``,O=[E,D].filter(Boolean).join(` · `),k=(0,Z.useRef)({source:v.source,text:v.text,detail:``});return(0,Z.useEffect)(()=>{let e=k.current;O!==e.detail&&O?s(O):v.source!==e.source&&e.text&&s(e.text),k.current={source:v.source,text:v.text,detail:O}},[v,O,s]),(0,Q.jsxs)(Q.Fragment,{children:[b.length===0?(0,Q.jsx)(`span`,{className:G(_t,`animate-pulse text-text-primary`),"aria-hidden":`true`,"data-testid":`live-phase-thinking`,children:(0,Q.jsx)(V,{size:14})}):(0,Q.jsx)(`span`,{className:_t,"aria-hidden":`true`,children:(0,Q.jsx)(Tn,{toolNames:b,mcpIconMap:l,maxIcons:Xa,sourceDomains:x,status:ca(f.outcome),isAnimating:!0})}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,Q.jsx)(Ya,{text:v.text,source:v.source,failed:!1,animate:t,live:!0,grow:T===``,lineId:r}),T!==``&&(0,Q.jsx)(`span`,{id:i,className:`shrink-0 text-xs font-normal text-text-secondary`,"data-testid":`live-phase-combo`,children:T})]}),O!==``&&(0,Q.jsxs)(`span`,{id:a,className:`shrink-0 text-xs font-normal text-text-warning`,"data-testid":`live-phase-outcome`,children:[E!==``&&(0,Q.jsxs)(`span`,{className:`sr-only`,children:[`· `,E]}),D!==``&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`mr-1 text-text-secondary`,children:`·`}),(0,Q.jsx)(`span`,{children:D})]})]})]})}function eo({failedAt:e}){ut();let{i18n:t}=_e(),n=wr(),r=new Date(e);if(!Number.isFinite(r.getTime())||r.getTime()>Date.now())return null;let i=be(r.toISOString(),t.language,n);return i==null?null:(0,Q.jsx)(`time`,{dateTime:i.iso,title:i.absolute,className:`min-w-0 shrink truncate text-xs text-text-secondary`,"data-testid":`activity-phase-failed-time`,children:i.relative})}function to({parts:e,attachmentsById:t,count:n,onReveal:r}){let i=K(),a=er(),o=(0,Z.useMemo)(()=>Oa(e,i,a,t)[0],[e,i,a,t]);return o==null?null:(0,Q.jsxs)(`button`,{type:`button`,className:G(bt,`w-full pl-6 text-left text-text-secondary hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-border-heavy`),onClick:r,"data-testid":`activity-phase-failed-peek`,children:[(0,Q.jsx)(`span`,{className:G(_t,`text-status-error`),"aria-hidden":`true`,children:(0,Q.jsx)(h,{size:14})}),(0,Q.jsxs)(`span`,{className:`tool-status-text flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 max-w-full shrink-0 truncate font-medium text-status-error`,children:o.text}),o.detail!==``&&(0,Q.jsx)(`span`,{className:`min-w-0 shrink truncate font-normal`,children:o.detail})]}),o.failedAt!=null&&(0,Q.jsx)(eo,{failedAt:o.failedAt}),n>1&&(0,Q.jsx)(`span`,{className:`shrink-0 text-xs font-normal`,children:i(`com_ui_plus_n_more`,{0:String(n-1)})}),(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 text-xs font-medium underline underline-offset-2`,children:i(`com_ui_show_error`)})]})}function no({labelPart:e,children:t,hasContent:n,attachments:r,showCursor:i=!1,animateEntrance:a=!1,hasPendingApproval:o=!1,liveParts:s,spanParts:c,onExpansionChange:l}){let u=s!=null,d=bn(e),f=e.status===`failed`||e.status===`partial`,p=c??s,m=(0,Z.useMemo)(()=>Cr(r??[]),[r]),{failed:h,total:g}=(0,Z.useMemo)(()=>p==null?{failed:0,total:0}:da(p,m),[p,m]),_=kn(),[v]=(0,Z.useState)(_&&a&&d.length>0),y=v&&n,[b,x]=(0,Z.useState)(y),[S,C]=(0,Z.useState)(!y),w=(0,Z.useRef)(null),T=(0,Z.useId)(),E=(0,Z.useId)(),D=(0,Z.useId)(),O=(0,Z.useId)(),[k,A]=(0,Z.useState)(``),j=(0,Z.useRef)({isLive:u,label:d});(0,Z.useEffect)(()=>{let e=j.current;j.current={isLive:u,label:d},!u&&d&&(e.isLive||e.label!==d)&&A(d)},[u,d]);let M=(0,Z.useRef)(null),N=(0,Z.useRef)(null),P=(0,Z.useRef)(b),F=(0,Z.useRef)(!1),{style:I,ref:L}=Et(b),{shouldRenderBody:ee,mountBody:R,handleTransitionEnd:z}=Kr(b,o),{value:te,requestReveal:ne}=ht(b&&ee);(0,Z.useEffect)(()=>
5{if(!(!y||F.current))return M.current=Ka(()=>{M.current=null,!F.current&&(C(!0),x(!1))}),()=>{M.current?.(),M.current=null}},[y]),(0,Z.useEffect)(()=>{let e=P.current;P.current=b,e&&!b&&(N.current?.(),N.current=or(w.current))},[b]),(0,Z.useEffect)(()=>()=>{N.current?.()},[]);let B=(0,Z.useCallback)(()=>{F.current=!0,M.current?.(),M.current=null,R(),C(!0),l?.(!b),x(!b)},[R,b,l]),re=(0,Z.useCallback)(()=>{F.current=!0,M.current?.(),M.current=null,R(),C(!0),b||(l?.(!0),x(!0)),ne()},[R,b,l,ne]),ie=u&&(!b||d.length===0),ae=n&&!b&&h>0&&p!=null?(0,Q.jsx)(to,{parts:p,attachmentsById:m,count:h,onReveal:re}):null,V=(0,Z.useMemo)(()=>{if(y)return{display:`grid`,gridTemplateRows:S?`1fr`:`0fr`,transition:ze,opacity:+!!S}},[y,S]),H=(0,Z.useMemo)(()=>{if(!u||b||s==null)return``;let e=s[s.length-1];return e?.type===W.THINK?typeof e.think==`string`?e.think:e.think?.value??``:``},[u,b,s]),oe=H.trim()===``?null:(0,Q.jsx)(on,{text:H}),se=i&&oe==null?(0,Q.jsx)(`div`,{className:bt,"data-testid":`activity-phase-cursor`,children:(0,Q.jsx)(`span`,{className:G(_t,`submitting`),"aria-hidden":`true`,children:(0,Q.jsx)(`span`,{className:`result-thinking block after:!static`})})}):null,ce=r!=null&&r.length>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Wa,{attachments:r}),(0,Q.jsx)(Zt,{attachments:r})]}):null;if(!d&&!u)return(0,Q.jsxs)(Q.Fragment,{children:[t,ce]});let le=n?(0,Q.jsxs)(`div`,{className:`mb-2 mt-1 w-full`,ref:w,"data-testid":`activity-phase-card`,children:[(0,Q.jsx)(`span`,{className:`sr-only`,role:`status`,"data-testid":`activity-phase-announcer`,children:k}),(0,Q.jsx)(`div`,{style:V,className:G(b&&`sticky top-0 z-[1] bg-presentation`),children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 overflow-hidden`,children:[(0,Q.jsxs)(Y,{variant:`ghost`,type:`button`,className:G(`flex h-auto min-h-7 min-w-0 flex-1 items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-left font-medium text-text-secondary hover:bg-transparent hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-border-heavy focus-visible:ring-offset-0`,b&&`font-semibold text-text-primary`),onClick:B,"aria-expanded":b,"aria-controls":T,"aria-label":ie?void 0:d,"aria-labelledby":ie?`${E} ${D} ${O}`:void 0,children:[ie?(0,Q.jsx)($a,{parts:s,animate:_,expanded:b,lineId:E,comboId:D,detailId:O,attachments:r,onAnnounce:A}):(0,Q.jsxs)(Q.Fragment,{children:[p!=null&&!f?(0,Q.jsx)(Qa,{parts:p,attachments:r}):(0,Q.jsx)(qa,{failed:f}),(0,Q.jsx)(Ya,{text:d,failed:f,animate:_})]}),(0,Q.jsx)(he,{className:G(`size-4 shrink-0 transition-transform duration-200 ease-out motion-reduce:transition-none`,b&&`rotate-180`),"aria-hidden":`true`})]}),(0,Q.jsx)(We,{count:h,total:g,onReveal:re})]})}),ae,(0,Q.jsx)(`div`,{id:T,style:I,onTransitionEnd:z,"aria-hidden":!b,"data-testid":`activity-phase-panel`,children:ee&&(0,Q.jsx)(`div`,{className:G(`overflow-hidden`,`relative pl-6 before:absolute before:bottom-1.5 before:left-[11px] before:top-0.5 before:w-px before:bg-border-medium before:content-['']`),ref:L,children:(0,Q.jsx)(jt.Provider,{value:te,children:t})})})]}):(0,Q.jsxs)(`div`,{className:G(`mb-2 mt-1 flex min-h-7 w-full items-center gap-2 py-1 text-text-secondary`,v&&`animate-in fade-in-0 motion-reduce:animate-none ${Ga}`),"data-testid":`activity-phase-card`,children:[(0,Q.jsx)(qa,{failed:f}),(0,Q.jsx)(`span`,{className:G(`tool-status-text min-w-0 flex-1 truncate text-left font-medium`,f&&`text-text-warning`),role:`status`,title:d,children:d})]});return(0,Q.jsxs)(Q.Fragment,{children:[le,oe,ce,se]})}var ro=e=>{if(e.type===W.TEXT)return e.text;if(e.type===W.THINK)return e.think},io=e=>{let t=ro(e);return typeof t==`string`?t:t?.value},ao=(e,t)=>{let n=ro(e);return typeof n==`object`&&n?{...n,value:t}:t},oo=e=>{if(!e.includes(`artifact`))return!1;try{return Or(e).some(e=>e.artifactCount>0)}catch{return!1}},so=e=>{if(!e||e.type!==W.TEXT&&e.type!==W.THINK||e.type===W.TEXT&&e.tool_call_ids!=null)return!1;let t=io(e);return t!=null&&!oo(t)},co=e=>{let t=e?.content;return!Array.isArray(t)||t.some(so)},lo=(e,t)=>{let n=Ar(e,t);return n?.isCreatedByUser===!0?n:void 0};function uo({content:e,contentIndexOffset:t=0,messageId:n,isSubmitting:r,enterEdit:i,siblingIdx:a,setSiblingIdx:o,renderReadOnlyPart:s}){let c=K(),l=w(Dn.chatDirection).toLowerCase()===`rtl`,{conversation:u}=Sr(),{ask:d,getMessages:f,setMessages:p}=Yn(),m=gt(),h=(0,Z.useRef)(null),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),b=Mt(u?.conversationId??``),x=(0,Z.useMemo)(()=>{let n=[];return e.forEach((e,r)=>{if(!e||!so(e))return;let i=io(e);i!=null&&n.push({index:r+t,localIndex:r,type:e.type,original:i})}),n},[e,t]),[S,C]=(0,Z.useState)(()=>Object.fromEntries(x.map(e=>[e.index,e.original]))),T=(0,Z.useMemo)(()=>new Map(x.map(e=>[e.localIndex,e])),[x]),E=(0,Z.useMemo)(()=>x.filter(e=>S[e.index]!==e.original),[S,x]),D=(0,Z.useMemo)(()=>E.some(e=>(S[e.index]??``).trim()===``),[E,S]),O=Ar(f(),n),k=r||v,A=O?.isCreatedByUser===!0||lo(f(),O?.parentMessageId)!=null,j=A&&O?.isCreatedByUser!==!0&&E.length>1;(0,Z.useEffect)(()=>{let e=h.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},[]);let M=(0,Z.useCallback)(e=>{let t=f();if(!t||e.length===0)return;let r=new Map(e.map(e=>[e.localIndex,{type:e.type,text:S[e.index]}]));p(t.map(e=>e.messageId!==n||!Array.isArray(e.content)?e:{...e,content:e.content.map((e,t)=>{let n=r.get(t);if(!e||!n||e.type!==n.type)return e;let i={...e,[n.type]:ao(e,n.text)};return n.type===W.THINK?we(i):i})}))},[S,f,n,p]),N=(0,Z.useCallback)(async()=>
5{if(E.length===0||D||k)return;y(!0),_(!1);let e=[];try{for(let t of E)await b.mutateAsync({index:t.index,conversationId:u?.conversationId??``,text:S[t.index],messageId:n}),e.push(t)}catch{_(!0)}finally{M(e),y(!1)}e.length===E.length&&i(!0)},[M,E,u?.conversationId,S,i,D,k,n,b]),P=(0,Z.useCallback)(()=>{if(!O||j||D||k)return;let e=E[0],t=f(),r=!1,s=!1;if(O.isCreatedByUser===!0){let e=x.filter(e=>e.type===W.TEXT).map(e=>S[e.index]).join(`
6`);if(e.trim()===``&&(O.files?.length??0)===0)return;r=d({text:e,parentMessageId:O.parentMessageId,conversationId:O.conversationId},{overrideFiles:O.files,overrideManualSkills:O.manualSkills,overrideQuotes:O.quotes,addedConvo:m()||void 0})===!1}else{let i=lo(t,O.parentMessageId);if(!i)return;if(!e)s=!0,r=d({...i},{isRegenerate:!0,targetResponseMessageId:n,overrideManualSkills:i.manualSkills,overrideQuotes:i.quotes,addedConvo:m()||void 0})===!1;else{let t=e.type===W.THINK?{index:e.index,type:W.THINK,[W.THINK]:S[e.index]}:{index:e.index,type:W.TEXT,[W.TEXT]:S[e.index]};r=d({...i},{editedContent:t,editedMessageId:n,isRegenerate:!0,isEdited:!0,overrideManualSkills:i.manualSkills,overrideQuotes:i.quotes,addedConvo:m()||void 0})===!1}}r||(s||o((a??0)-1),i(!0))},[d,E,S,O,x,i,m,f,D,k,n,j,o,a]),F=(0,Z.useCallback)(e=>{if(e.key===`Escape`){e.preventDefault(),i(!0);return}if(A&&e.key===`Enter`&&(e.ctrlKey||e.metaKey)){e.preventDefault(),P();return}e.key.toLowerCase()===`s`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),N())},[A,i,N,P]);return(0,Q.jsxs)(`section`,{"aria-label":c(`com_ui_edit_message`),className:`flex w-full min-w-0 flex-col gap-2`,children:[g&&(0,Q.jsx)(Sn,{variant:`error`,children:c(`com_ui_save_message_error`)}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:e.map((r,i)=>{if(!r)return null;let a=T.get(i),o=i+t;if(!a)return(0,Q.jsx)(`div`,{className:`min-w-0`,children:s(r,o,i===e.length-1)},`read-only-${n}-${o}`);let u=a.type===W.THINK?c(`com_ui_thoughts`):c(`com_ui_response`);return(0,Q.jsxs)(`label`,{dir:l?`rtl`:`ltr`,className:`flex min-w-0 flex-col gap-1.5 text-xs font-medium text-text-secondary`,children:[u,(0,Q.jsx)(Vn,{ref:a===x[0]?h:void 0,value:S[o],onChange:e=>C(t=>({...t,[o]:e.target.value})),onKeyDown:F,"aria-label":`${c(`com_ui_editable_message`)}: ${u}`,"aria-keyshortcuts":A?`Control+Enter Meta+Enter Control+S Meta+S Escape`:`Control+S Meta+S Escape`,disabled:k,minRows:3,dir:l?`rtl`:`ltr`,className:G(`message-editor-text max-h-[65vh] min-h-24 w-full resize-y rounded-lg`,`border border-border-medium bg-surface-tertiary-alt px-3 py-2`,`font-normal text-text-primary`,`focus-visible:outline-none`,l?`text-right`:`text-left`,`disabled:opacity-50 md:max-h-[75vh]`)})]},`editor-${n}-${o}`)})}),(0,Q.jsxs)(`footer`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 min-w-0 flex-1 text-xs text-text-secondary`,"aria-live":`polite`,children:D?c(`com_ui_message_part_empty`):j?c(`com_ui_save_before_rerun`):E.length>0?c(`com_ui_unsaved_changes`):A?``:c(`com_ui_rerun_needs_user_turn`)}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,Q.jsx)(Y,{size:`sm`,variant:`outline`,onClick:()=>i(!0),disabled:v,children:c(`com_ui_cancel`)}),(0,Q.jsx)(Y,{size:`sm`,variant:`outline`,onClick:()=>void N(),disabled:E.length===0||D||k,children:c(v?`com_ui_saving`:`com_ui_save`)}),A&&(0,Q.jsx)(Y,{size:`sm`,variant:`submit`,onClick:P,disabled:j||D||k,children:E.length>0?c(`com_ui_update_rerun`):c(`com_ui_rerun`)})]})]})]})}var fo=c([]),po=c(null),mo=c([]),ho=c({}),go=c({}),_o=c({}),vo=(0,Z.createContext)(!1);function yo({saveDrafts:e,children:t}){return(0,Q.jsx)(vo.Provider,{value:e,children:t})}function bo(){return(0,Z.useContext)(vo)}function xo(){let[e,t]=o(_o);return{getAskStatus:(0,Z.useCallback)(t=>e[t]??`idle`,[e]),setAskStatus:(0,Z.useCallback)((e,n)=>t(t=>({...t,[e]:n})),[t])}}var So=(0,Z.createContext)(null),Co=()=>(0,Z.useContext)(So)??wo,wo={version:0,setDecision:()=>void 0,getDecision:()=>void 0,getDecisionDraft:()=>void 0,setDecisionDraft:()=>void 0,getDecisions:()=>[],registerToolCall:()=>void 0,unregisterToolCall:()=>void 0,getLeadToolCallId:()=>void 0,getRegisteredCount:()=>0,isReady:()=>!1,getStatus:()=>`idle`,setStatus:()=>void 0,beginToolSubmission:()=>!1,endToolSubmission:()=>void 0,getAskAnswerDraft:()=>``,setAskAnswerDraft:()=>void 0},To=e=>e?.response?.status===409;function Eo({children:e,pendingAction:t}){return(0,Z.useContext)(So)==null?(0,Q.jsx)(Do,{pendingAction:t,children:e}):(0,Q.jsx)(Q.Fragment,{children:e})}function Do({children:e,pendingAction:t}){let n=(0,Z.useRef)(new Map),r=(0,Z.useRef)(new Map),i=(0,Z.useRef)(new Map),a=(0,Z.useRef)(new Map),o=(0,Z.useRef)(null),s=(0,Z.useRef)(new Map),c=(0,Z.useRef)(new Set),[l,u]=(0,Z.useState)(0),d=(0,Z.useCallback)(()=>u(e=>e+1),[]),[f,p]=(0,Z.useState)({});(0,Z.useEffect)(()=>
6{if(t?.payload.type!==`tool_approval`){a.current.clear(),o.current=null,d();return}let{actionId:e}=t,s=Array.from(new Set(t.payload.action_requests.map(e=>e.tool_call_id)));o.current!==e&&(n.current.clear(),r.current.clear(),i.current.clear(),a.current.clear(),c.current.clear(),p({})),o.current=e,a.current.set(e,s),d()},[t,d]);let m=(0,Z.useCallback)((e,t)=>{let n=i.current.get(e)??new Map;n.set(t,(n.get(t)??0)+1),i.current.set(e,n),d()},[d]),h=(0,Z.useCallback)((e,t)=>{let n=i.current.get(e),r=n?.get(t);!n||r==null||(r>1?n.set(t,r-1):n.delete(t),n.size===0&&i.current.delete(e),d())},[d]),g=(0,Z.useCallback)(e=>a.current.get(e)?.[0]??i.current.get(e)?.keys().next().value,[]),_=(0,Z.useCallback)(e=>a.current.get(e)?.length??i.current.get(e)?.size??0,[]),v=(0,Z.useCallback)((e,t,r)=>{let i=n.current.get(e)??new Map;r==null?i.delete(t):i.set(t,r),n.current.set(e,i),d()},[d]),y=(0,Z.useCallback)((e,t)=>n.current.get(e)?.get(t),[]),b=(0,Z.useCallback)((e,t)=>r.current.get(e)?.get(t),[]),x=(0,Z.useCallback)((e,t,n)=>{let i=r.current.get(e)??new Map;i.set(t,n),r.current.set(e,i),d()},[d]),S=(0,Z.useCallback)(e=>{let t=a.current.get(e)??[...i.current.get(e)?.keys()??[]],r=n.current.get(e);return t.length===0||r==null?[]:t.flatMap(e=>{let t=r.get(e);return t==null?[]:[t]})},[]),C=(0,Z.useCallback)(e=>{let t=a.current.get(e)??[...i.current.get(e)?.keys()??[]],r=n.current.get(e);if(t.length===0)return!1;for(let e of t)if(!r?.has(e))return!1;return!0},[]),w=(0,Z.useCallback)(e=>f[e]??`idle`,[f]),T=(0,Z.useCallback)((e,t)=>{p(n=>({...n,[e]:t}))},[]),E=(0,Z.useCallback)(e=>!c.current.has(e)&&(c.current.add(e),!0),[]),D=(0,Z.useCallback)(e=>{c.current.delete(e)},[]),O=(0,Z.useCallback)(e=>s.current.get(e)??``,[]),k=(0,Z.useCallback)((e,t)=>{if(t.length===0){s.current.delete(e);return}s.current.set(e,t)},[]),A=(0,Z.useMemo)(()=>({version:l,setDecision:v,getDecision:y,getDecisionDraft:b,setDecisionDraft:x,getDecisions:S,registerToolCall:m,unregisterToolCall:h,getLeadToolCallId:g,getRegisteredCount:_,isReady:C,getStatus:w,setStatus:T,beginToolSubmission:E,endToolSubmission:D,getAskAnswerDraft:O,setAskAnswerDraft:k}),[l,v,y,b,x,S,m,h,g,_,C,w,T,E,D,O,k]);return(0,Q.jsx)(So.Provider,{value:A,children:e})}function Oo(){let e=u(),t=(0,Z.useContext)(yn),n=t?.conversation,r=Dt(),i=sn(),a=qt(),{getDecisions:o,isReady:s,setStatus:c,beginToolSubmission:l,endToolSubmission:d}=Co(),f=(0,Z.useRef)(new Set),{setAskStatus:p}=xo(),m=w(Dn.activeGenerationCreatedAtByConvoId(n?.conversationId??X.NEW_CONVO)),h=(0,Z.useCallback)(()=>{let e=n?.conversationId;return!e||e===X.NEW_CONVO||m==null?null:{conversationId:e,generationCreatedAt:m,endpoint:n?.endpoint,endpointType:n?.endpointType,agent_id:n?.agent_id,model:n?.model,spec:n?.spec,promptPrefix:n?.promptPrefix,ephemeralAgent:r(e)}},[n,r,m]);return{submitToolApproval:(0,Z.useCallback)(t=>{let n=h(),r=o(t);!n||r.length===0||!s(t)||l(t)&&(c(t,`submitting`),i.mutate({...n,actionId:t,decisions:r},{onSuccess:()=>{c(t,`submitted`);let r=Xr(n.conversationId);e.get(r)?.actionId===t&&e.set(r,null)},onError:e=>{let n=To(e);n||d(t),c(t,n?`expired`:`error`)}}))},[i,l,h,d,o,s,e,c]),submitAskAnswer:(0,Z.useCallback)((e,n,r)=>{let i=h(),o=typeof n!=`string`,s=o?Object.keys(n).length>0:n.length>0;!i||!s||f.current.has(e)||(f.current.add(e),p(e,`submitting`),a.mutate({...i,actionId:e,...o?{answers:n}:{answer:n}},{onSuccess:()=>{p(e,`submitted`);let i=t?.getMessages?.();if(i&&t?.setMessages){let r=!1,a=i.map(t=>{let i=mn(t,e,n);return i!==t&&(r=!0),i});r&&t.setMessages(a)}r?.onSuccess?.()},onError:t=>{let n=To(t);n||f.current.delete(e),p(e,n?`expired`:`error`)}}))},[a,h,p,t])}}var ko=(0,Z.createContext)(!1);function Ao({className:e}){let t=K();return(0,Z.useContext)(ko)?null:(0,Q.jsxs)(`p`,{className:G(`flex items-center text-xs text-text-warning`,e),children:[(0,Q.jsx)(h,{className:`mr-1.5 inline-block h-4 w-4`,"aria-hidden":`true`}),t(`com_assistants_allow_sites_you_trust`)]})}function jo({parts:e,isSubmitting:t,isLast:n,showThinking:i,renderPart:a,lastContentIdx:o,groupAttachments:s,sourceAttachments:c,initialExpansionState:l,onExpansionChange:u,labelPart:d,withinActivityPhase:f=!1,parentPhaseOwnsFailurePill:p=!1}){let m=K(),h=Te(),g=er(),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(!1),b=(0,Z.useMemo)(()=>Cr(c??s??[]),[c,s]),x=(0,Z.useMemo)(()=>{let t=da(e.map(({part:e})=>e),b);return e.map(({part:e})=>t.metaOf(e)).filter(e=>e!=null)},[e,b]),S=x.length,C=(0,Z.useMemo)(()=>e.some(({part:e})=>mr(e)),[e]),T=gr(d?.part),E=bn(T),D=T?.status===`failed`||T?.status===`partial`,O=E.length>0&&d?.part?.pending!==!0,k=(0,Z.useMemo)(()=>O||x.every(e=>e.hasOutput===!0),[x,O]),A=(0,Z.useMemo)(()=>Ma(c??s,3),[c,s]),j=(0,Z.useMemo)(()=>x.map(e=>e.iconName),[x]),M=(0,Z.useMemo)(()=>{let e=new Map,t=0,n=0,r=0,i=0,a=0,o=0,s=0;for(let c of x){if(c.name===q.web_search?t++:c.name===`file_search`||c.name===`retrieval`?n++:c.name===X.SUBAGENT?r++:c.name===`ask_user_question`?i++:c.name===X.CHECK_BACKGROUND_TASK&&a++,c.failed&&o++,c.cancelled&&s++,!c.name)continue;let l=Se(c.name,m,g);e.set(l,(e.get(l)??0)+1)}let c=Array.from(e,([e,t])=>t>1?`${e} ×${t}`:e),l=c.length<=3?c.join(`, `):`${c.slice(0,3).join(`, `)}, +${c.length-3}`;return{webSearchCount:t,fileSearchCount:n,subagentCount:r,askQuestionCount:i,taskCheckCount:a,failedCount:o,cancelledCount:s,toolNameSummary:l}},[x,m,g]),N=(0,Z.useMemo)(()=>e.some(e=>e.part.type===W.THINK),[e]),P=M.subagentCount>
60&&M.subagentCount===S,F=P&&(k||!t),I=M.askQuestionCount>0&&M.askQuestionCount===S,L=M.taskCheckCount>0&&M.taskCheckCount===S,ee=(0,Z.useMemo)(()=>e.every(({part:e})=>{if(e.type!==W.TOOL_CALL)return!0;let t=e[W.TOOL_CALL];return t?.name!==`ask_user_question`||(t.output?.length??0)>0||st(t.id)!==void 0}),[e]),R=k||!t,z=I&&(R||ee),te=I?!z:!R,ne=(0,Z.useMemo)(()=>{let e=Se(x[0]?.name??``,m,g);return e?e.charAt(0).toUpperCase()+e.slice(1):``},[x,m,g]),B=w(Dn.autoExpandTools),re=!B&&!(i&&N)&&k&&(S>=1||E.length>0),ie=f&&!C,ae=l?.userOverride===!0?l:null,[V,H]=(0,Z.useState)(ae?.isExpanded??(B||!re&&!ie)),[oe,se]=(0,Z.useState)(ae!=null),[ce,le]=(0,Z.useState)(V),de=(0,Z.useRef)(V),{style:fe,ref:pe}=Et(V),me=(0,Z.useCallback)(()=>{v.current?.(),v.current=or(_.current)},[]);(0,Z.useEffect)(()=>()=>{v.current?.()},[]),(0,Z.useEffect)(()=>{let e=de.current;de.current=V,e&&!V&&me()},[V,me]),(0,Z.useEffect)(()=>{re&&!oe&&H(!1)},[re,oe]);let _e=(0,Z.useCallback)(()=>{let e=!V;se(!0),e&&le(!0),H(e),u?.({isExpanded:e,userOverride:!0})},[V,u]),ve=(0,Z.useCallback)(()=>{se(!0),le(!0),H(!0),u?.({isExpanded:!0,userOverride:!0})},[u]),{value:ye,requestReveal:be}=ht(V&&ce),xe=(0,Z.useCallback)(()=>{ve(),be()},[ve,be]);rt(M.failedCount>0,xe);let Ce=(0,Z.useCallback)(e=>{if(e.target===e.currentTarget&&!V){if(C){y.current=!0;return}y.current=!1,le(!1),me()}},[C,V,me]);(0,Z.useEffect)(()=>{if(V){y.current=!1;return}!C&&y.current&&(y.current=!1,le(!1),me())},[C,V,me]);let we=M.webSearchCount+M.fileSearchCount,Ee=S>0&&we===S,De=E.length>0?E:P?S===1?m(F?`com_ui_subagent_complete`:`com_ui_subagent_running`):m(F?`com_ui_ran_n_agents`:`com_ui_running_n_agents`,{0:String(S)}):I?S===1?m(z?`com_ui_asked_one_question`:`com_ui_asking_one_question`):m(z?`com_ui_asked_n_questions`:`com_ui_asking_n_questions`,{0:String(S)}):L?m(R?`com_ui_background_tasks_checked`:`com_ui_background_tasks_checking`):M.webSearchCount===S?m(R?`com_ui_web_searched`:`com_ui_web_searching`):M.fileSearchCount===S?m(R?`com_ui_retrieved_files`:`com_ui_searching_files`):Ee?m(R?`com_ui_searched_web_and_files`:`com_ui_searching_web_and_files`):S===1?ne||m(`com_ui_used_one_tool`):m(R?`com_ui_ran_n_actions`:`com_ui_running_n_actions`,{0:String(S)}),Oe=[];Ee&&S>1?Oe.push(m(`com_ui_n_searches`,{0:String(S)})):L&&S>1?Oe.push(m(`com_ui_background_tasks_n_checks`,{0:String(S)})):!P&&!I&&S>1&&Oe.push(M.toolNameSummary);let ke=M.failedCount>0?m(`com_ui_n_of_n_actions_failed`,{0:String(M.failedCount),1:String(S)}):``;ke!==``&&Oe.push(ke),M.cancelledCount>0&&Oe.push(m(M.cancelledCount===1?`com_ui_one_action_cancelled`:`com_ui_n_actions_cancelled`,{0:String(M.cancelledCount)}));let Ae=Oe.filter(Boolean).join(` · `),je=[De,Ae,N?m(`com_ui_thoughts`):``].filter(
6Boolean).join(`, `),Me=!f&&!p&&M.failedCount>0?Oe.filter(e=>e&&e!==ke).join(` · `):Ae,Ne=ue;P?Ne=ge:I&&(Ne=r);let Pe=ca({failed:D?1:M.failedCount,cancelled:M.cancelledCount}),Fe=(0,Z.useMemo)(()=>t&&x.some(e=>e&&!e.hasOutput),[x,t]),Ie=(0,Z.useMemo)(()=>e.some(({part:e})=>Dr(e)),[e]);return(0,Z.useEffect)(()=>{Fe&&!oe&&!ie&&(le(!0),H(!0))},[Fe,oe,ie]),(0,Q.jsxs)(`div`,{className:`mb-2 mt-1`,ref:_,children:[(0,Q.jsxs)(`div`,{className:`flex w-full items-center gap-2`,children:[(0,Q.jsxs)(Y,{variant:`ghost`,type:`button`,className:G(`inline-flex h-auto min-w-0 flex-1 items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-text-secondary hover:bg-transparent hover:text-text-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy focus-visible:ring-offset-0`,V&&`text-text-primary hover:text-text-primary`),onClick:_e,"aria-expanded":V,"aria-label":je,children:[Pe==null&&(P||I||L)?(0,Q.jsx)(`div`,{className:G(_t,`text-text-secondary`,te&&`animate-pulse text-text-primary`),"aria-hidden":`true`,children:(0,Q.jsx)(Ne,{size:14})}):(0,Q.jsx)(`div`,{className:_t,"aria-hidden":`true`,children:(0,Q.jsx)(Tn,{toolNames:j,mcpIconMap:h,maxIcons:4,sourceDomains:A,status:Pe,isAnimating:te})}),(0,Q.jsx)(`span`,{className:G(`tool-status-text min-w-0 truncate font-medium`,D&&`text-text-warning`),role:`status`,title:De,children:De}),Me&&(0,Q.jsxs)(`span`,{className:`min-w-0 max-w-[40%] truncate text-xs font-normal text-text-secondary`,title:Me,children:[`· `,Me]}),(0,Q.jsx)(he,{className:G(`size-4 shrink-0 text-text-secondary transition-transform duration-200 ease-out`,V&&`rotate-180`),"aria-hidden":`true`})]}),!f&&!p&&(0,Q.jsx)(We,{count:M.failedCount,total:S,onReveal:xe})]}),(0,Q.jsx)(`div`,{style:fe,onTransitionEnd:Ce,"aria-hidden":!V,"data-testid":`tool-call-group-panel`,children:ce&&(0,Q.jsxs)(`div`,{className:G(`overflow-hidden`,`relative pl-6 before:absolute before:bottom-1.5 before:left-[11px] before:top-0.5 before:w-px before:bg-border-medium before:content-['']`),ref:pe,children:[(0,Q.jsx)(ko.Provider,{value:!0,children:(0,Q.jsx)(jt.Provider,{value:ye,children:(0,Q.jsx)(`div`,{className:`flex flex-col py-0.5`,children:e.map(({part:r,idx:s},c)=>{if(r.type===W.THINK){let l=r.think,u=typeof l==`string`?l:l?.value??``;if(u.trim()===``&&r.reasoning_unavailable===!0)return a(r,s,n&&s===o,ve);let d=t&&s===o,f=c>0&&e[c-1]?.part.type===W.TOOL_CALL,p=r.reasoning_label?.trim()||m(d?`com_ui_thinking`:`com_ui_thoughts`);return(0,Q.jsx)($e,{partKeyIndex:Ln(r,s),reasoning:u,label:p,showThinking:i,isAfterTool:f,isStreaming:d},`reasoning-${s}`)}return a(r,s,n&&s===o,ve)})})})}),Ie&&(0,Q.jsx)(Ao,{className:`mb-1 mt-2.5`})]})}),s&&s.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Wa,{attachments:s}),(0,Q.jsx)(Zt,{attachments:s})]})]})}var Mo=`com_ui_background_tasks_more_in_raw_details`,No={"Generated files were saved and attached to the tool call that dispatched this task.":`com_ui_background_tasks_files_attached`,"Output and any generated files are being attached to the tool call that dispatched this task.":`com_ui_background_tasks_files_attaching`,"The tool produced an artifact that is not included inline.":`com_ui_background_tasks_artifact_not_inline`,"Still running outside this turn; its result will arrive as a new turn when it finishes.":`com_ui_background_tasks_running_elsewhere`,"Finished, but its result has not been delivered; it will arrive as a new turn unless you poll or cancel it.":`com_ui_background_tasks_pending_delivery_note`,"Automatic delivery failed; this result will not arrive as a new turn. Poll it to collect the result.":`com_ui_background_tasks_failed_delivery_note`},Po={"Cancellation was requested. The task remains active until its executor settles; poll again for a terminal result.":`com_ui_background_tasks_cancellation_requested`,"Automatic completion delivery is enabled for this subagent task. Continue independent work if available; otherwise end this turn and the host will resume you when the task finishes. Do not repeatedly poll an unchanged running task. Use check_background_task only for explicit status or control, or as a fallback if automatic delivery is unavailable.":`com_ui_background_tasks_subagent_wakeup_guidance`},Fo={invalid:`com_ui_background_tasks_notice_invalid`,rejected:`com_ui_background_tasks_notice_rejected`,unavailable:`com_ui_background_tasks_notice_unavailable`,not_found:`com_ui_background_tasks_notice_not_found`,outcome_unknown:`com_ui_background_tasks_notice_outcome_unknown`,result_unavailable:`com_ui_background_tasks_notice_result_unavailable`,result_persisting:`com_ui_background_tasks_notice_result_persisting`,delivery_scheduled:`com_ui_background_tasks_notice_delivery_scheduled`,cancelled:`com_ui_background_tasks_result_discarded`,error:`com_ui_background_tasks_notice_error`},Io=e=>Object.hasOwn(No,e)?No[e]:Mo,Lo=e=>Object.hasOwn(Po,e)?Po[e]:Mo;
6function Ro(e,t){return e===`invalid`&&t===`Cancellation is not enabled for ordinary background tools.`?`com_ui_background_tasks_cancel_disabled`:e===`invalid`&&t===`This control action is supported only for subagent tasks.`?`com_ui_background_tasks_notice_subagent_only`:e===`unavailable`&&t.startsWith(`The pending result could not be discarded right now.`)?`com_ui_background_tasks_notice_discard_unavailable`:Object.hasOwn(Fo,e)?Fo[e]:Mo}function zo(e){if(!e.message)return[];let t=!1,n=!1,r=!1,i=!1;for(let a of e.tasks){if(a.toolName===`subagent`){r||=a.delivery===`pending`&&a.status!==`running`,i||=a.status===`running`;continue}t||=a.delivery===`pending`&&a.status!==`running`,n||=a.delivery===`failed`}let a=[];return t&&a.push(`com_ui_background_tasks_pending_delivery_guidance`),n&&a.push(`com_ui_background_tasks_failed_delivery_guidance`),r&&a.push(`com_ui_background_tasks_subagent_pending_guidance`),i&&e.message.includes(`Automatic completion delivery is enabled for this subagent task.`)&&a.push(`com_ui_background_tasks_subagent_wakeup_guidance`),a.length>0?a:[Mo]}var Bo={dispatched:{label:`com_ui_subagent_thread_status_dispatched`,dot:`bg-text-tertiary`},running:{label:`com_ui_background_tasks_running`,dot:`bg-status-info`},stopping:{label:`com_ui_background_tasks_stopping`,dot:`bg-status-warning`},accepted:{label:`com_ui_background_tasks_control_queued`,dot:`bg-status-info`},claimed:{label:`com_ui_background_tasks_result_claimed`,dot:`bg-text-tertiary`},not_running:{label:`com_ui_background_tasks_not_running`,dot:`bg-status-warning`},control_not_found:{label:`com_ui_background_tasks_control_not_found`,dot:`bg-status-warning`},completed:{label:`com_ui_background_tasks_completed`,dot:`bg-status-success`},error:{label:`com_ui_failed`,dot:`bg-status-error`},failed:{label:`com_ui_failed`,dot:`bg-status-error`},interrupted:{label:`com_ui_subagent_thread_status_interrupted`,dot:`bg-status-error`},cancelled:{label:`com_ui_cancelled`,dot:`bg-status-warning`}};function Vo({task:e,mcpIconMap:t,mcpServerNames:n}){let r=K(),i=e.toolName===`subagent`,a=In(e.toolName,n),o=a.mcpServer,s=Se(e.toolName,r,n);i?s=r(`com_ui_background_tasks_subagent`):o&&(s=a.toolName);let c=e.subagentType||o,l=o?t?.get(o):void 0,u=ni(e.toolName),d=u===`bash_tool`||u===`execute_code`,f=Bo[e.status],p=e.status===`error`||e.status===`failed`||e.status===`interrupted`,m=e.result?.trim()?e.result:void 0,h=e.error?.trim()&&e.error!==m?e.error:void 0,g=e.note?Io(e.note):void 0,_=e.message?Lo(e.message):void 0,v;return e.delivery===`pending`?v=r(`com_ui_background_tasks_result_pending`):e.delivery===`failed`&&(v=r(`com_ui_background_tasks_result_undelivered`)),(0,Q.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border-light bg-surface-secondary/50 p-3`,"data-testid":`background-task-card`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-surface-tertiary`,children:(0,Q.jsx)(Ft,{type:u,iconUrl:l,className:`text-text-primary`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 pt-0.5`,children:[(0,Q.jsx)(`div`,{className:`truncate text-sm font-semibold text-text-primary`,title:s,children:s}),c&&(0,Q.jsx)(`div`,{className:`truncate text-xs text-text-secondary`,children:c}),v&&(0,Q.jsx)(`div`,{className:G(`mt-0.5 text-xs`,e.delivery===`failed`?`text-status-warning`:`text-text-secondary`),children:v})]}),(0,Q.jsxs)(`span`,{className:G(`inline-flex shrink-0 items-center gap-1.5 rounded-full bg-surface-tertiary px-2 py-1 text-xs text-text-secondary`,p&&`text-status-error`),children:[(0,Q.jsx)(`span`,{className:G(`size-1.5 rounded-full`,f.dot),"aria-hidden":`true`}),r(f.label)]})]}),m&&(0,Q.jsxs)(`div`,{className:`mt-3 border-t border-border-light pt-2.5`,children:[(0,Q.jsx)(`div`,{className:G(`mb-1.5 text-xs font-medium`,p&&!h?`text-status-error`:`text-text-secondary`),children:r(p&&!h?`com_ui_error`:`com_ui_output`)}),(0,Q.jsx)(`div`,{className:`min-w-0 rounded-md bg-surface-primary p-2.5`,children:(0,Q.jsx)(Ur,{text:d?qi(m):m,copyText:m})})]}),h&&(0,Q.jsxs)(`div`,{className:`mt-3 border-t border-border-light pt-2.5`,children:[(0,Q.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-status-error`,children:r(`com_ui_error`)}),(0,Q.jsx)(`div`,{className:`min-w-0 rounded-md bg-surface-primary p-2.5`,children:(0,Q.jsx)(Ur,{text:d?qi(h):h,copyText:h})})]}),!m&&!h&&e.resultClaimed&&e.status!==`claimed`&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-text-secondary`,children:r(`com_ui_background_tasks_result_claimed`)}),!m&&!h&&e.resultAvailable&&!e.resultClaimed&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-text-secondary`,children:r(`com_ui_background_tasks_result_available`)}),g&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-text-secondary`,children:r(g)}),_&&_!==g&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-text-secondary`,children:r(_)}),!m&&!h&&!e.resultAvailable&&!e.resultClaimed&&e.result===``&&!e.note&&!e.message&&(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-text-secondary`,children:r(`com_ui_background_tasks_no_output`)})]})}function Ho(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.entries(e);return t.length===0||t.length>8?!1:t.every(([,e])=>e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)}function Uo({data:e}){return(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-xs`,children:Object.entries(e).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:e}),(0,Q.jsx)(`span`,{className:`rounded bg-surface-tertiary px-1.5 py-0.5 text-text-primary`,children:String(t??`null`)})]},e))})}function Wo(e){if(e==null)return``;if(typeof e==`string`)return e.length>200?e.slice(0,200)+`...`:e;if(typeof e!=`object`)return String(e);let t=JSON.stringify(e);return t.length>200?t.slice(0,200)+`...`:t}function Go({data:e}){return(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-xs`,children:Object.entries(e).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:e}),(0,Q.jsx)(`span`,{className:`max-w-[300px] overflow-hidden truncate rounded bg-surface-tertiary px-1.5 py-0.5 font-mono text-text-primary`,children:Wo(t)})]},e))})}function Ko({input:e}){if(!e||e.trim().length===0)return null;try{let t=JSON.parse(e);return Ho(t)?(0,Q.jsx)(Uo,{data:t}):typeof t==`object`&&t&&!Array.isArray(t)?(0,Q.jsx)(Go,{data:t}):(0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap text-xs text-text-primary`,children:typeof t==`string`?t:JSON.stringify(t,null,2)})}catch{return(0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap text-xs text-text-primary`,children:e})}}function qo({input:e,output:t,attachments:n}){let r=K(),{ask:i}=_n(),[a,o]=(0,Z.useState)(!1),{style:s,ref:c}=Et(a),l=(0,Z.useMemo)(()=>
6{if(!e||e.trim().length===0)return!1;try{let t=JSON.parse(e);if(typeof t==`object`&&t)return Object.keys(t).length>0}catch{}return e.trim().length>0},[e]),u=n?.filter(e=>e.type===q.ui_resources).flatMap(e=>e[q.ui_resources]).filter(jr)??[];return(0,Q.jsxs)(`div`,{className:`w-full px-3 py-3.5`,children:[t&&(0,Q.jsx)(Ur,{text:t}),t&&l&&(0,Q.jsx)(`div`,{className:`my-2 border-t border-border-light`}),l&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,className:G(`inline-flex items-center gap-1 text-xs text-text-secondary`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy`),onClick:()=>o(e=>!e),"aria-expanded":a,children:[(0,Q.jsx)(`span`,{children:r(`com_ui_parameters`)}),(0,Q.jsx)(he,{className:G(`size-3 shrink-0 transition-transform duration-200 ease-out`,a&&`rotate-180`),"aria-hidden":`true`})]}),(0,Q.jsx)(`div`,{style:s,children:(0,Q.jsx)(`div`,{className:`overflow-hidden pt-1`,ref:c,children:(0,Q.jsx)(Ko,{input:e})})})]}),u.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(l||t)&&(0,Q.jsx)(`div`,{className:`my-2 border-t border-border-light`}),u.length>1&&(0,Q.jsx)(xn,{uiResources:u}),u.length===1&&(0,Q.jsx)(_r,{resource:u[0],onUIAction:async e=>xt(e,i),htmlProps:{autoResizeIframe:{width:!0,height:!0}}})]})]})}function Jo({args:e,output:t=``,initialProgress:n=.1,isSubmitting:r,runStepStatus:i,runStepDurationMs:a,attachments:o,hideAttachments:s=!1,onExpand:c,toolCallId:l}){let u=K(),[d,f]=(0,Z.useState)(!1),p=Te(),m=er(),h=fr(e),g=(0,Z.useMemo)(()=>ta(t),[t]),_=(0,Z.useMemo)(()=>{if(typeof e==`string`)return e;try{return JSON.stringify(e??{})??``}catch{return``}},[e]),v=_.trim()!==``&&_.trim()!==`{}`,y=Yi(g),b=g?.kind===`notice`?u(Ro(g.status,g.message)):void 0,x=(0,Z.useMemo)(()=>g?.kind===`list`?zo(g):[],[g]),{showCode:S,toggleCode:C,expandStyle:w,expandRef:T,phase:E,hasContent:D}=Re({initialProgress:n,isSubmitting:r,output:t,hasInput:v||(o?.length??0)>0,onExpand:c,runStepStatus:i,extraError:y===`failed`,extraCancelled:y===`cancelled`}),{shouldRenderBody:O,mountBody:k,handleTransitionEnd:A}=Kr(S),j=(0,Z.useCallback)(()=>{k(),C()},[k,C]),M=h??u(`com_ui_background_tasks_checked`);E===`cancelled`?M=y===`cancelled`&&b!=null?b:u(`com_ui_cancelled`):E===`failed`&&y!==`failed`?M=h??u(`com_ui_background_tasks_checked`):b==null?g?.kind===`list`&&y===`failed`&&(M=u(`com_ui_background_tasks_incomplete`)):M=b;let N=M;return E===`running`?N=u(`com_ui_background_tasks_checking`):E===`failed`&&(b==null||y!==`failed`)&&(N=g?.kind===`list`?u(`com_ui_background_tasks_incomplete`):u(`com_ui_failed_subject`,{0:u(`com_ui_background_tasks`)})),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:N}),(0,Q.jsx)(`div`,{className:bt,"data-testid":`background-task-call`,"data-tool-call-id":l,children:(0,Q.jsx)(De,{phase:E,onClick:j,inProgressText:h??u(`com_ui_background_tasks_checking`),finishedText:M,durationMs:a,icon:(0,Q.jsx)(Ft,{type:`background_tasks`,isAnimating:E===`running`}),hasInput:D,isExpanded:S})}),(0,Q.jsx)(`div`,{style:w,onTransitionEnd:A,"data-tool-call-output-id":l,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:T,children:D&&O&&(0,Q.jsxs)(`div`,{className:G(`mb-2 mt-0`,`overflow-hidden rounded-lg border border-border-light bg-surface-secondary`),children:[g?.kind===`task`&&(0,Q.jsx)(`div`,{className:`p-2.5`,children:(0,Q.jsx)(Vo,{task:g.task,mcpIconMap:p,mcpServerNames:m})}),g?.kind===`list`&&(0,Q.jsxs)(`div`,{className:`p-2.5`,children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs font-medium text-text-secondary`,children:[u(`com_ui_background_tasks`),(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-tertiary px-1.5 tabular-nums`,children:g.tasks.length})]}),g.tasks.length>0?(0,Q.jsx)(`ul`,{tabIndex:0,"aria-label":u(`com_ui_background_tasks`),className:`flex max-h-96 flex-col gap-2 overflow-y-auto pr-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy`,children:g.tasks.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsx)(Vo,{task:e,mcpIconMap:p,mcpServerNames:m})},e.taskId))}):(0,Q.jsx)(`p`,{className:`text-sm text-text-secondary`,children:u(`com_ui_background_tasks_empty`)}),(g.partial||g.warning)&&(0,Q.jsx)(`p`,{role:`alert`,className:`mt-2 text-xs text-status-warning`,children:u(`com_ui_background_tasks_incomplete`)}),x.map(e=>(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-text-secondary`,children:u(e)},e))]}),g?.kind===`notice`&&(0,Q.jsx)(`p`,{className:G(`p-3 text-sm`,y===`failed`||g.status===`result_persisting`?`text-status-warning`:`text-text-secondary`),children:b}),(g==null||v)&&(0,Q.jsx)(`div`,{className:G(g!=null&&`border-t border-border-light`),children:(0,Q.jsx)(qo,{input:_,output:g==null?t:void 0,attachments:o})}),g!=null&&(0,Q.jsxs)(`details`,{className:`border-t border-border-light px-3 py-2`,onToggle:e=>f(e.currentTarget.open),children:[(0,Q.jsx)(`summary`,{className:`curs
6or-pointer rounded text-xs text-text-secondary hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy`,children:u(`com_ui_background_tasks_raw_details`)}),d&&(0,Q.jsx)(`div`,{className:`mt-2 rounded-md bg-surface-primary p-2.5`,children:(0,Q.jsx)(Ur,{text:t,copyText:t})})]})]})})}),!s&&o&&o.length>0&&(0,Q.jsx)(Zt,{attachments:o})]})}function Yo({args:e,toolCallId:t}){let n=K(),i=(0,Z.useContext)(yn)?.conversation?.conversationId,a=i!=null&&i!==`new`,{data:o}=Ie(a?i:``,{enabled:a,select:Ze}),s=Jn(e,`question`),c=(()=>{if(typeof e==`string`)return Gn(e,`question`)[0]??``;let t=e?.questions;if(!Array.isArray(t))return``;let n=t[0];if(typeof n!=`object`||!n)return``;let r=n.question;return typeof r==`string`?r:``})(),l=s||c;return o!=null&&(o.hasUnattributed||t!=null&&o.ids.includes(t))?null:(0,Q.jsxs)(`div`,{className:`my-2 flex w-full flex-col gap-1.5 rounded-lg border border-border-light bg-surface-secondary p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-text-secondary`,role:`status`,children:[(0,Q.jsx)(r,{className:`h-4 w-4 animate-pulse`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`shimmer`,children:n(`com_ui_asking`)})]}),l.length>0?(0,Q.jsx)(`p`,{className:`text-sm font-medium text-text-primary [overflow-wrap:anywhere]`,children:l}):(0,Q.jsx)(`div`,{className:`h-4 w-2/5 animate-pulse rounded bg-surface-tertiary`,"aria-hidden":`true`})]})}function Xo({args:e,output:t,toolCallId:n,isSubmitting:i=!1,runStepStatus:a,failed:o=!1,showCursor:s=!1,onExpand:c}){let l=K(),u=w(Dn.autoExpandTools),[d,f]=(0,Z.useState)(u),{style:p,ref:m}=Et(d);(0,Z.useEffect)(()=>{u&&f(!0)},[u]);let g=(0,Z.useCallback)(()=>{f(e=>{let t=!e;return t&&c?.(),t})},[c]),_=pn(e),v=un(e),y=t.length>0?t:st(n)??``,b=(()=>{if(v==null||y.length===0)return null;try{let e=JSON.parse(y);return e.answers!=null&&typeof e.answers==`object`?e.answers:null}catch{return null}})(),x=o||a===`failed`,S=!x&&(v==null?y.length>0:v.questions.every(e=>typeof b?.[e.id]==`string`));if(!S&&!x&&a==null&&i)return(0,Q.jsx)(Yo,{args:e,toolCallId:n});let C=i&&s?(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{})}):null,T=v?.questions.length??1,E=x?l(`com_ui_question_failed`):T>1?l(`com_ui_asked_n_questions`,{0:String(T)}):l(`com_ui_asked`),D=T>1?void 0:v?.questions[0]?.question??_?.question;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:bt,"data-testid":`ask-user-question-call`,children:(0,Q.jsx)(De,{phase:x?`failed`:`completed`,onClick:g,inProgressText:E,finishedText:E,subtitle:D,icon:x?(0,Q.jsx)(h,{className:`size-4 shrink-0 text-text-warning`,"aria-hidden":`true`}):(0,Q.jsx)(r,{className:`size-4 shrink-0 text-text-secondary`,"aria-hidden":`true`}),isExpanded:d})}),x&&(0,Q.jsx)(`span`,{className:`sr-only`,role:`status`,children:`${E}. ${l(`com_ui_question_failed_description`)}`}),(0,Q.jsx)(`div`,{style:p,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:m,children:(0,Q.jsxs)(`div`,{className:`my-2 flex w-full flex-col gap-4 roun
6ded-lg border border-border-light bg-surface-secondary p-4`,children:[v==null?(0,Q.jsx)(Zo,{question:_?.question??``,description:_?.description,answer:S?y:void 0,options:_?.options,multiSelect:_?.multiSelect,failed:x}):v.questions.map((e,t)=>(0,Q.jsxs)(`div`,{className:t>0?`border-t border-border-light pt-4`:void 0,children:[e.header!=null&&(0,Q.jsx)(`p`,{className:`mb-1 text-xs font-medium text-text-secondary`,children:e.header}),(0,Q.jsx)(Zo,{question:e.question,description:e.description,answer:b?.[e.id],options:e.options,multiSelect:e.multiSelect,failed:x})]},e.id)),x&&(0,Q.jsx)(`p`,{className:`text-sm leading-relaxed text-text-secondary`,children:l(`com_ui_question_failed_description`)})]})})}),C]})}function Zo({question:e,description:t,answer:n,options:r,multiSelect:i,failed:a}){let o=K();return(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[e.length>0&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-sm font-medium leading-relaxed text-text-primary [overflow-wrap:anywhere]`,children:e}),t!=null&&t.length>0&&(0,Q.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-sm leading-relaxed text-text-secondary [overflow-wrap:anywhere]`,children:t}),typeof n==`string`&&(0,Q.jsxs)(`div`,{className:`mt-2.5 border-l-2 border-border-medium pl-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-text-secondary`,children:o(`com_ui_you_answered`)}),(0,Q.jsx)(`p`,{className:`mt-0.5 whitespace-pre-wrap text-sm leading-relaxed text-text-primary [overflow-wrap:anywhere]`,children:Qo({question:e,options:r,multiSelect:i},n)})]}),typeof n!=`string`&&!a&&(0,Q.jsx)(`p`,{className:`mt-2.5 text-sm italic text-text-secondary`,children:o(`com_ui_question_unanswered`)})]})}function Qo(e,t){let n=e.options?.find(e=>e.value===t)?.label;if(n!=null||e.multiSelect!==!0||e.options==null)return n??t;let r=t.split(`, `).map(t=>e.options?.find(e=>e.value===t)?.label);return r.every(e=>e!=null)?r.join(`, `):t}var $o={INVALID_API_KEY:`invalid_api_key`,INSUFFICIENT_QUOTA:`insufficient_quota`};function $(e,t){let n=e?.[t];return typeof n==`string`&&n.length>0?n:void 0}function es(e,t){let n=e?.[t];if(typeof n==`number`&&Number.isFinite(n))return n;if(typeof n==`string`&&n.trim()!==``&&Number.isFinite(Number(n)))return Number(n)}function ts(e,t){let n=e?.[t];return typeof n==`object`&&n&&!Array.isArray(n)?n:void 0}var ns=e=>Wn[e]??e;function rs(e,t){let n=e?.[Ct(t)];if(n!=null)return{agent:n,endpoint:n.provider||void 0,model:n.model??void 0};let r=Pn(t)?Hr(t):void 0;return r==null?{}:{endpoint:r.endpoint,model:r.model}}function is(e,{partAgentId:t,rowModel:n,conversationAgentId:r}){let i=t??r;if(i!=null)return rs(e,i);if(n==null||n===X.EPHEMERAL_AGENT_ID)return{};let a=rs(e,n);return a.endpoint!=null||!Pn(n)?a:{model:n}}var as=e=>si(e)||e?.userProvideURL===!0;function os(e,t){return t==null?!1:e==null?void 0:as(e[t])}function ss(e,t){let n=(0,Z.useContext)(yn),r=Un(),i=n!=null,{data:a}=ri({enabled:i}),{data:o}=Qt({enabled:i}),s=e??n?.conversation??void 0,c=s?.endpoint??void 0,l=s?.model??void 0,u=e==null&&n?.conversation?.agent_id!==X.EPHEMERAL_AGENT_ID?n?.conversation?.agent_id??void 0:void 0,d=e?.partAgentId;return(0,Z.useMemo)(()=>{let e=d!=null||Yt(c),n=e?is(r,{partAgentId:d,rowModel:l,conversationAgentId:u}):void 0,s=e?n?.endpoint:c,f=t??s;return{endpoint:f,endpointType:f?yt(a,f,`type`):void 0,provider:f?ns(f):void 0,model:e?n?.model:l,agent:n?.agent,userProvidesCredentials:os(a,f),compactionAvailable:i&&o?.compactionEnabled===!0&&o.interface?.contextUsage!==!1&&Rt(c),endpointsConfig:a}},[i,c,l,u,d,t,r,a,o?.compactionEnabled,o?.interface?.contextUsage])}function cs({children:e}){return(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e})}function ls({label:e,children:t}){let[n,r]=(0,Z.useState)(!1),i=(0,Z.useId)(),{style:a,ref:o}=Et(n);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,"aria-controls":i,className:`flex items-center gap-1 rounded-md text-xs font-medium text-text-secondary transition-colors hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-text-primary`,children:[e,(0,Q.jsx)(v,{className:G(`size-3.5 transition-transform duration-300 [transition-timing-function:cubic-bezier(0.16,1,0.3,1)] motion-reduce:transition-none`,n&&`rotate-90`),"aria-hidden":`true`})]}),(0,Q.jsx)(`div`,{id:i,style:a,"aria-hidden":!n,children:(0,Q.jsx)(`div`,{ref:o,className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`mt-1 whitespace-pre-wrap break-words text-xs text-text-secondary`,children:t})})})]})}var us=240;function ds({headline:e,detail:t,label:n}){return t==null?(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`div`,{children:e}),t.length<=us&&!/[\r\n]/.test(t)?(0,Q.jsx)(`div`,{className:`text-text-secondary`,children:t}):(0,Q.jsx)(ls,{label:n,children:t})]})}function fs({children:e}){return(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}function ps({onClick:e,children:t}){return(0,Q.jsx)(Y,{type:`button`,size:`sm`,className:`rounded-md`,onClick:e,children:t})}var ms=e=>new Intl.NumberFormat().format(e),hs=e=>new Intl.NumberFormat(void 0,{maximumFractionDigits:2}).format(e),gs=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;function _s(e){if(typeof e==`string`&&!gs.test(e))return e;let t=new Date(e);return Number.isNaN(t.getTime())?String(e):new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}function vs(e){let t=Math.max(0,Math.ceil(e/1e3)),n=t%60,r=Math.floor(t/60)%60,i=Math.floor(t/3600),a=e=>e.toString().padStart(2,`0`);return i>0?`${i}:${a(r)}
6:${a(n)}`:`${r}:${a(n)}`}function ys(e){let t=K();if(e!=null)return e===1?t(`com_error_window_minute`):t(`com_error_window_minutes`,{0:ms(e)})}function bs(e,t){return t==null?e:(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`div`,{children:e}),(0,Q.jsx)(ls,{label:t.label,children:t.value})]})}function xs(e){return $(e,`info`)??$(ts(ts(e,`info`),`stop_details`),`explanation`)}function Ss(e){return $(e,`error`)??$(ts(e,`error`),`message`)}function Cs({json:e,message:t}){let n=K(),{provider:r,model:i}=ss(t),a=$(e,`code`)??$(e,`type`);if(a===U.REFUSAL){let t=i==null?n(`com_error_refusal_unknown`):n(`com_error_refusal`,{0:i}),r=xs(e);return r==null?t:bs(t,{label:n(`com_error_refusal_reason`),value:r})}if(a===U.GOOGLE_ERROR){let t=n(`com_error_google_error`),r=$(e,`info`);return r==null?t:bs(t,{label:n(`com_error_details_provider`),value:r})}if(a===U.INVALID_REQUEST){let t=r==null?n(`com_error_invalid_request_error_unknown`):n(`com_error_invalid_request_error`,{0:r}),i=[Ss(e),$(e,`message`),$(e,`info`)].filter(e=>e!=null).join(`
7
8`)||void 0;return i==null?t:bs(t,{label:n(`com_error_details_provider`),value:i})}return a===U.NO_SYSTEM_MESSAGES?r==null?n(`com_error_no_system_messages_unknown`):n(`com_error_no_system_messages`,{0:r}):(0,Q.jsx)(ws,{json:e,text:``,message:t})}function ws({json:e,text:t,message:n}){let r=K(),{provider:i}=ss(n),a=oi(t),o=Ss(e)??$(e,`message`)??$(e,`info`),s=a===``?t:t.replace(a,()=>o??``),c=ir(s).trim()||o,l=i==null?r(`com_error_upstream_model`):r(`com_error_provider_failed`,{0:i}),u=c==null&&e!=null?r(`com_error_unknown`):l;return(0,Q.jsx)(ds,{headline:u,detail:c,label:r(`com_error_details_provider`)})}var Ts={[U.NO_USER_KEY]:`com_error_user_key_add`,[U.NO_BASE_URL]:`com_error_user_url_add`,[U.INVALID_BASE_URL]:`com_error_user_url_update`};function Es({json:e,message:t}){let n=K(),[r,i]=(0,Z.useState)(!1),a=$(e,`code`)??$(e,`type`),{endpoint:o,endpointType:s,provider:c,userProvidesCredentials:l,endpointsConfig:u}=ss(t,a===U.EXPIRED_USER_KEY?$(e,`endpoint`):void 0),d=$(e,`expiredAt`),f=(e,t,r)=>c==null||l==null?n(e):n(l?t:r,{0:c}),p=(e,t)=>l===!0&&c!=null?n(t,{0:c}):n(e),m;switch(a){case U.NO_USER_KEY:m=f(`com_error_no_user_key_generic`,`com_error_no_user_key`,`com_error_no_user_key_admin`);break;case U.EXPIRED_USER_KEY:m=d==null?n(`com_error_invalid_user_key`):c==null?n(`com_error_expired_user_key_generic`,{0:_s(d)}):n(`com_error_expired_user_key`,{0:c,1:_s(d)});break;case U.INVALID_USER_KEY:m=p(`com_error_invalid_user_key`,`com_error_invalid_user_key_provider`);break;case U.NO_BASE_URL:m=p(`com_error_no_base_url`,`com_error_no_base_url_provider`);break;case U.INVALID_BASE_URL:m=p(`com_error_invalid_base_url`,`com_error_invalid_base_url_provider`);break;case $o.INVALID_API_KEY:m=f(`com_error_invalid_api_key_generic`,`com_error_invalid_api_key`,`
8com_error_invalid_api_key_admin`);break;case $o.INSUFFICIENT_QUOTA:m=f(`com_error_insufficient_quota_generic`,`com_error_insufficient_quota`,`com_error_insufficient_quota_admin`);break;default:m=n(`com_error_invalid_user_key`)}let h=l===!0&&o!=null,g=(a==null?void 0:Ts[a])??`com_error_user_key_update`;return(0,Q.jsxs)(cs,{children:[m,h&&(0,Q.jsx)(fs,{children:(0,Q.jsx)(ps,{onClick:()=>i(!0),children:n(g)})}),h&&r&&o!=null&&(0,Q.jsx)(li,{open:r,onOpenChange:i,endpoint:o,endpointType:s,userProvideURL:yt(u,o,`userProvideURL`),userProvideAccessKeyId:yt(u,o,`userProvideAccessKeyId`),userProvideSecretAccessKey:yt(u,o,`userProvideSecretAccessKey`),userProvideSessionToken:yt(u,o,`userProvideSessionToken`),userProvideBearerToken:yt(u,o,`userProvideBearerToken`)})]})}function Ds(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=$(e,`model`),n=es(e,`promptTokens`),r=es(e,`completionTokens`);if(t==null&&n==null&&r==null)return null;let i=[n==null?null:ms(n),r==null?null:ms(r)].filter(e=>e!=null);return{model:t??i.join(`, `),promptTokens:n==null?`—`:ms(n),completionTokens:r==null?`—`:ms(r)}}function Os({json:e}){let t=K(),n=es(e,`balance`),r=es(e,`tokenCost`),i=es(e,`promptTokens`),a=Array.isArray(e.generations)?e.generations.map(Ds).filter(e=>e!=null):[],o=r!=null&&n!=null?t(`com_error_token_balance`,{0:hs(r),1:hs(n)}):t(`com_error_limit_reached`);return(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`p`,{children:o}),i==null?null:(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:t(`com_error_token_balance_prompt`,{0:ms(i)})}),a.length>0?(0,Q.jsx)(ls,{label:t(`com_error_token_balance_generations`),children:(0,Q.jsx)(`ul`,{className:`list-none space-y-0.5`,children:a.map((e,n)=>(0,Q.jsx)(`li`,{children:t(`com_error_token_balance_generation`,{0:e.model,1:e.promptTokens,2:e.completionTokens})},n))})}):null]})}var ks=[`Message pruning removed all messages as none fit in the context window.`,`Please increase the context window size or make your message shorter.`],As={disabled:`com_error_compaction_disabled`,instructions_exceed_budget:`com_error_compaction_budget`,nothing_to_summarize:`com_error_compaction_nothing`};function js(e){if(e==null)return;let t=e.split(`/`).map(e=>e.trim());if(t.length!==2||t.some(e=>e===``))return;let n=t.map(Number);return n.every(e=>Number.isFinite(e)&&Number.isInteger(e))?n:void 0}function Ms(e){return e.replace(/\b\d+(?:\.\d+)?\b/g,e=>{let t=Number(e);return Number.isFinite(t)?ms(t):e})}function Ns(e){let t=e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);return t.length>1&&/^Token budget\s*:/i.test(t[0])&&t.every(e=>/\b\d+(?:\.\d+)?\b/.test(e))?(0,Q.jsx)(`ul`,{className:`list-none space-y-0.5`,children:t.map((e,t)=>(0,Q.jsx)(`li`,{children:Ms(e)},`${t}-${e}`))}):Ms(e)}function Ps(e,t,n){if(e==null||e.trim()===``)return!1;if(t==null||n==null)return!0;let r=js(e);return r==null||r[0]!==t||r[1]!==n}function Fs({json:e,message:t}){let n=K(),{compactionAvailable:r}=ss(t),i=$(e,`type`),a=n(r?`com_error_context_next_steps_compact`:`com_error_context_next_steps`);if(i===U.INPUT_LENGTH){let t=$(e,`info`),r=js(t),i=r==null?n(`com_error_input_length_unknown`):n(`com_error_input_length`,{0:ms(r[0]),1:ms(r[1])});return(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`p`,{children:i}),(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:n(`com_error_context_next_steps`)}),t!=null&&r==null&&(0,Q.jsx)(ls,{label:n(`com_error_context_token_budget`),children:t})]})}if(i===U.FINAL_CONTEXT_OVERFLOW){let t=es(e,`projectedMessageTokens`),r=es(e,`availableMessageTokens`),i=$(e,`info`),o=t!=null&&r!=null?n(`com_error_final_context_overflow`,{0:ms(t),1:ms(r)}):n(`com_error_final_context_overflow_unknown`);return(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`p`,{children:o}),(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:a}),Ps(i,t,r)&&(0,Q.jsx)(ls,{label:n(`com_error_context_token_budget`),children:i})]})}if(i===U.EMPTY_MESSAGES){let t=$(e,`info`),r=ks.reduce((e,t)=>e.replace(t,``),t??``).trim();return(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`p`,{children:n(`com_error_empty_messages`)}),(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:a}),r&&(0,Q.jsx)(ls,{label:n(`com_error_context_token_budget`),children:Ns(r)})]})}return i===U.COMPACTION_SKIPPED?n(As[$(e,`reason`)??``]??`com_error_compaction_failed`):n(`com_error_unknown`)}function Is({json:e,message:t}){let n=K(),{provider:r}=ss(t),i=$(e,`code`)??$(e,`type`),a=$(e,`info`),o=a==null?r:ns(a);if(i===U.MISSING_MODEL)return o==null?n(`com_error_models_not_loaded`):n(`com_error_missing_model`,{0:o});if(i===U.ENDPOINT_MODELS_NOT_LOADED)return o==null?n(`com_error_models_not_loaded`):n(`com_error_endpoint_models_not_loaded`,{0:o});if(i===J.ILLEGAL_MODEL_REQUEST){let[e,t]=a?.split(`|`)??[],i=e!=null&&e!==``?ns(e):r;return t==null||t===``||i==null?n(`com_error_model_not_found`):n(`com_error_illegal_model_request`,{0:t,1:i})}if(i===U.CODE_WORKSPACE_UNAVAILABLE){let t=$(e,`reason`);return Ut(t)?n(wn[t]):n(`com_error_code_workspace_unavailable`)}let s=es(e,`status`),c=s==null?n(`com_error_upstream_model`):n(`com_error_upstream_model_status`,{0:s});return(0,Q.jsx)(ds,{headline:c,detail:$(e,`message`),label:n(`com_error_details_provider`)})}function Ls(e){if(e==null)return;let t=e instanceof Date?e.getTime():new Date(e).getTime();return Number.isNaN(t)?void 0:t}function Rs({type:e,resetAt:t,retryAfterSeconds:n,createdAt:r,windowInMinutes:i}){if(e!==J.MESSAGE_LIMIT)return;let a=Ls(r),o=n!=null&&a!=null?a+n*1e3:t;if(!(o==null||!Number.isFinite(o))&&!(i!=null&&o>(a??Date.now())+i*60*1e3))return o}function zs(e){let[t,n]=(0,Z.useState)(()=>e==null?void 0:Math.max(0,e-Date.now()));if((0,Z.useEffect)(()=>
8{if(e==null){n(void 0);return}let t=()=>{let t=e-Date.now();return n(Math.max(0,t)),t};if(t()<=0)return;let r=setInterval(()=>{t()<=0&&clearInterval(r)},1e3);return()=>clearInterval(r)},[e]),e!=null)return t??Math.max(0,e-Date.now())}function Bs({json:e,message:t}){let n=K(),r=$(e,`type`),i=t?.createdAt,a=es(e,`max`),o=es(e,`limit`),s=es(e,`windowInMinutes`),c=ys(s),l=Rs({type:r,resetAt:es(e,`resetAt`),retryAfterSeconds:es(e,`retryAfterSeconds`),createdAt:i,windowInMinutes:s}),u=zs(l),d;switch(r){case J.MESSAGE_LIMIT:d=c==null?n(`com_error_limit_reached`):a===1?n(`com_error_message_limit_one`,{0:c}):a==null?n(`com_error_limit_reached`):n(`com_error_message_limit`,{0:ms(a),1:c});break;case J.CONCURRENT:d=o!=null&&o>1?n(`com_error_concurrent`,{0:ms(o)}):n(`com_error_concurrent_one`);break;case J.FILE_UPLOAD_LIMIT:d=a!=null&&c!=null?n(`com_error_file_upload_limit`,{0:ms(a),1:c}):n(`com_error_limit_reached`);break;case J.TTS_LIMIT:d=a!=null&&c!=null?n(`com_error_tts_limit`,{0:ms(a),1:c}):n(`com_error_limit_reached`);break;case J.STT_LIMIT:d=a!=null&&c!=null?n(`com_error_stt_limit`,{0:ms(a),1:c}):n(`com_error_limit_reached`);break;default:d=n(`com_error_limit_reached`)}return(0,Q.jsxs)(cs,{children:[(0,Q.jsx)(`p`,{children:d}),l!=null&&u!=null&&(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:u>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:n(`com_error_retry_countdown`,{0:vs(u)})}),(0,Q.jsx)(`span`,{className:`sr-only`,children:n(`com_error_retry_at`,{0:_s(l)})})]}):n(`com_error_retry_available`)})]})}function Vs({json:e,message:t}){let n=K(),{agent:r,provider:i,endpointsConfig:a}=ss(t),o=(0,Z.useContext)(He)?.user,s=kt({permissionType:at.AGENTS,permission:dn.USE}),c=kt({permissionType:at.AGENTS,permission:dn.CREATE}),l=$(e,`info`),u=l==null?i:ns(l),d=a?.[Ae.agents],f=d!=null&&d.disableBuilder!==!0&&s&&c,p=r!=null&&f&&(r.isEditable!==!1||o?.role===Rn.ADMIN),m=r?.support_contact?.name?.trim()??``,h=r?.support_contact?.email?.trim()??``,g=r?.owner_contact?.name?.trim()??``,_=m!==``||h!==``?m:g,v=!p&&_!==``?n(`com_error_invalid_agent_provider_owner`,{0:_}):n(p?`com_error_invalid_agent_provider_editable`:`com_error_invalid_agent_provider_admin`);return(0,Q.jsxs)(cs,{children:[u?(0,Q.jsx)(`div`,{children:n(`com_error_invalid_agent_provider`,{0:u})}):null,(0,Q.jsx)(`div`,{children:v}),h?(0,Q.jsx)(fs,{children:(0,Q.jsx)(`a`,{href:`mailto:${h}`,className:`text-link hover:underline`,children:n(`com_error_agent_contact_email`,{0:h})})}):null]})}var Hs={[U.MODERATION]:`com_error_moderation`,[U.INVALID_ACTION]:`com_error_invalid_action_error`,[U.MODELS_NOT_LOADED]:`com_error_models_not_loaded`,[U.GOOGLE_TOOL_CONFLICT]:`com_error_google_tool_conflict`,[U.GOOGLE_VIDEO_UNPROCESSABLE]:`com_error_google_video_unprocessable`,[U.RESOURCE_RECOVERY_REQUIRED]:`com_error_resource_recovery_required`,[U.STATEFUL_CODE_ENVIRONMENT_NOT_ALLOWED]:`com_error_stateful_code_environment_not_allowed`,[U.STREAM_EXPIRED]:`com_error_stream_expired`,[U.MODEL_NOT_FOUND]:`com_error_model_not_found`,[U.MODEL_RATE_LIMIT]:`com_error_model_rate_limit`,[U.MODEL_STREAM_CLOSED]:`com_error_model_stream_closed`,[U.MODEL_STREAM_STALLED]:`com_error_model_stream_stalled`,[U.COMPACTION_FAILED]:`com_error_compaction_failed`,[U.AUTH_FAILED]:`com_error_auth_failed`,[U.AUTH_RATE_LIMITED]:`com_error_auth_rate_limited`,[U.AUTH_BANNED]:`com_error_auth_banned`,[U.AUTH_CROSS_ORIGIN]:`com_auth_error_login_cross_origin`,[J.BAN]:`com_error_ban`,[J.CONVO_ACCESS]:`com_error_convo_access`,[J.TOOL_CALL_LIMIT]:`com_error_tool_call_limit`,[J.SHARE_LIMIT]:`com_error_share_limit`,[J.LOGINS]:`com_error_logins`,[J.REGISTRATIONS]:`com_error_registrations`,[J.RESET_PASSWORD_LIMIT]:`com_error_reset_password_limit`,[J.VERIFY_EMAIL_LIMIT]:`com_error_verify_email_limit`,[J.NON_BROWSER]:`com_error_non_browser`,[J.GENERAL]:`com_error_request_blocked`},Us={[U.NO_USER_KEY]:Es,[U.EXPIRED_USER_KEY]:Es,[U.INVALID_USER_KEY]:Es,[U.NO_BASE_URL]:Es,[U.INVALID_BASE_URL]:Es,[$o.INVALID_API_KEY]:Es,[$o.INSUFFICIENT_QUOTA]:Es,[U.INVALID_AGENT_PROVIDER]:Vs,[U.MISSING_MODEL]:Is,[U.ENDPOINT_MODELS_NOT_LOADED]:Is,[U.UPSTREAM_MODEL_ERROR]:Is,[U.CODE_WORKSPACE_UNAVAILABLE]:Is,[J.ILLEGAL_MODEL_REQUEST]:Is,[U.REFUSAL]:Cs,[U.GOOGLE_ERROR]:Cs,[U.INVALID_REQUEST]:Cs,[U.NO_SYSTEM_MESSAGES]:Cs,[U.INPUT_LENGTH]:Fs,[U.EMPTY_MESSAGES]:Fs,[U.FINAL_CONTEXT_OVERFLOW]:Fs,[U.COMPACTION_SKIPPED]:Fs,[J.TOKEN_BALANCE]:Os,[J.MESSAGE_LIMIT]:Bs,[J.CONCURRENT]:Bs,[J.FILE_UPLOAD_LIMIT]:Bs,[J.TTS_LIMIT]:Bs,[J.STT_LIMIT]:Bs},Ws=(0,Z.createContext)(void 0);function Gs(e){let t={handoffs:[],owners:{}};for(let n=0;n<(e?.length??0);n++){let r=e?.[n];if(r?.type===W.ERROR&&r.agentId){t.owners[n]=r.agentId;continue}if(r?.type!==W.AGENT_UPDATE)continue;let i=r[W.AGENT_UPDATE]?.agentId;i&&t.handoffs.push({index:n,agentId:i})}return t}function Ks({handoffs:e,owners:t},n){let r=t[n];if(r!=null)return r;let i;for(let t of e){if(t.index>=n)break;i=t.agentId}return i}function qs({message:e,children:t}){let{endpoint:n,model:r,createdAt:i,content:a}=e,o=(0,Z.useMemo)(()=>JSON.stringify(Gs(a)),[a]),s=(0,Z.useMemo)(()=>({source:{endpoint:n,model:r,createdAt:i},positions:JSON.parse(o)}),[n,r,i,o]);return(0,Q.jsx)(Ws.Provider,{value:s,children:t})}function Js(){let e=(0,Z.useContext)(Ws),{partIndex:t}=Ee();return(0,Z.useMemo)(()=>
8{if(e==null)return;let n=t==null?void 0:Ks(e.positions,t);return n==null?e.source:{...e.source,partAgentId:n}},[e,t])}var Ys={MODEL_NOT_FOUND:`com_error_model_not_found`,MODEL_RATE_LIMIT:`com_error_model_rate_limit`};function Xs(e){let t=Zr(e);return t==null?void 0:Ys[t]}var Zs=({text:e,message:t})=>{let n=K(),r=Js(),i=t??r,a=Xs(e);if(a!=null)return n(a);let o=oi(e);if(!ci(o))return(0,Q.jsx)(ws,{text:e,message:i});let s=JSON.parse(o),c=ts(s,`error`),l=$(s,`code`)??$(s,`type`),u=l==null?$(c,`code`)??$(c,`type`):void 0,d=u!=null&&c!=null?c:s,f=l??u;if(f!=null){let t=Us[f];if(t!=null)return(0,Q.jsx)(t,{json:d,text:e,message:i});let r=Hs[f];if(r!=null)return n(r)}return(0,Q.jsx)(ws,{json:s,text:e,message:i})};function Qs({message:e}){let t=K(),n=(0,Z.useId)(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(e.messageId);a!==e.messageId&&(o(e.messageId),i(!1));let s=(0,Z.useContext)(yn);if(r&&a===e.messageId)return null;let c=s?.ask!=null&&s.isSubmitting!==!0&&s.latestMessageId===e.messageId,l=e=>s?.ask({text:e},{overri
8deFiles:[],overrideManualSkills:[],overrideQuotes:[]});return(0,Q.jsxs)(`div`,{role:`group`,"aria-labelledby":n,className:`relative my-2 flex w-full flex-col rounded-xl border border-border-light bg-surface-secondary p-3`,children:[(0,Q.jsx)(qr,{description:t(`com_ui_tool_call_limit_dismiss`),side:`left`,render:(0,Q.jsx)(Y,{type:`button`,variant:`ghost`,size:`icon-xs`,"aria-label":t(`com_ui_tool_call_limit_dismiss`),className:`absolute right-1.5 top-1.5 text-text-secondary focus-visible:ring-inset focus-visible:ring-offset-0`,onClick:()=>i(!0),children:(0,Q.jsx)(C,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,Q.jsxs)(`p`,{id:n,className:`flex min-w-0 items-center gap-2 pr-8 text-sm font-medium text-text-primary`,children:[(0,Q.jsx)(p,{className:`h-4 w-4 shrink-0 text-text-secondary`,"aria-hidden":`true`}),t(`com_ui_tool_call_limit_title`)]}),(0,Q.jsx)(`p`,{className:`mb-3 mt-1 text-sm text-text-secondary`,children:t(`com_ui_tool_call_limit_body`)}),c&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(Y,{size:`sm`,variant:`submit`,onClick:()=>l(t(`com_ui_tool_call_limit_continue_prompt`)),children:[(0,Q.jsx)(R,{className:`icon-md shrink-0`,"aria-hidden":`true`}),t(`com_ui_tool_call_limit_continue`)]}),(0,Q.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>l(t(`com_ui_tool_call_limit_answer_prompt`)),children:[(0,Q.jsx)(M,{className:`icon-md shrink-0`,"aria-hidden":`true`}),t(`com_ui_tool_call_limit_answer`)]})]})]})}var $s=({text:e,message:t,isSubmitting:n,ask:r,enterEdit:i,siblingIdx:a,setSiblingIdx:o})=>{let s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(!1),{conversation:d}=Sr(),{getMessages:f,setMessages:p}=Yn(),m=(0,Z.useRef)(null),{conversationId:h,parentMessageId:g,messageId:_}=t,v=t.isCreatedByUser===!0,y=v||lo(f(),g)!=null,b=Ge(h??``),x=K(),S=w(Dn.chatDirection).toLowerCase()===`rtl`,C=gt(),{register:T,handleSubmit:E,setValue:D,formState:{isDirty:O,isValid:k}}=pi({mode:`onChange`,defaultValues:{text:e??``}});(0,Z.useEffect)(()=>{let e=m.current;if(e){let t=e.value.length;e.focus(),e.setSelectionRange(t,t)}},[]);let A=e=>{r({text:e.text,parentMessageId:g,conversationId:h},{overrideFiles:t.files,overrideManualSkills:t.manualSkills,overrideQuotes:t.quotes,addedConvo:C()||void 0})!==!1&&(o((a??0)-1),i(!0))},j=()=>{let e=lo(f(),g);e&&r({...e},{isRegenerate:!0,targetResponseMessageId:_,overrideManualSkills:e.manualSkills,overrideQuotes:e.quotes,addedConvo:C()||void 0})!==!1&&i(!0)},M=async e=>{u(!1);try{await b.mutateAsync({conversationId:h??``,model:d?.model??`gpt-3.5-turbo`,text:e.text,messageId:_});let n=f();if(!n){i(!0);return}n.some(e=>e.messageId===_)?p(n.map(t=>t.messageId===_?{...t,text:e.text}:t)):t.text=e.text,i(!0)}catch{u(!0)}},N=(0,Z.useCallback)(e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),c.current?.click()),e.key===`s`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),s.current?.click()),e.key===`Escape`&&(e.preventDefault(),i(!0))},[i]),{ref:P,...F}=T(`text`,{required:(t.files?.length??0)===0,onChange:e=>{D(`text`,e.target.value,{shouldDirty:!0,shouldValidate:!0})}}),I=()=>O?x(v||!y?`com_ui_unsaved_changes`:`com_ui_rerun_discards_changes`):y?``:x(`com_ui_rerun_needs_user_turn`);return(0,Q.jsx)(Vi,{message:t,children:(0,Q.jsxs)(`section`,{"aria-label":x(`com_ui_edit_message`),className:`mt-2 flex w-full flex-col gap-2`,children:[l&&(0,Q.jsx)(Sn,{variant:`error`,children:x(`com_ui_save_message_error`)}),(0,Q.jsx)(Vn,{...F,ref:e=>{P(e),m.current=e},onKeyDown:N,"data-testid":`message-text-editor`,className:G(`message-editor-text max-h-[65vh] min-h-24 w-full resize-y whitespace-pre-wrap`,`break-words rounded-lg border border-border-medium bg-surface-tertiary-alt`,`px-3 py-2 text-text-primary`,`focus-visible:outline-none`,S?`text-right`:`text-left`,`disabled:opacity-50 md:max-h-[75vh]`),"aria-label":x(`com_ui_message_input`),"aria-keyshortcuts":y?`Control+Enter Meta+Enter Control+S Meta+S Escape`:`Control+S Meta+S Escape`,disabled:n||b.isLoading,dir:S?`rtl`:`ltr`}),(0,Q.jsxs)(`footer`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 min-w-0 flex-1 text-xs text-text-secondary`,"aria-live":`polite`,children:I()}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,Q.jsx)(Y,{size:`sm`,variant:`outline`,onClick:()=>i(!0),disabled:b.isLoading,children:x(`com_ui_cancel`)}),(0,Q.jsx)(Y,{ref:s,size:`sm`,variant:`outline`,disabled:n||b.isLoading||!O||!k,onClick:E(M),children:b.isLoading?x(`com_ui_saving`):x(`com_ui_save`)}),y&&(0,Q.jsx)(Y,{ref:c,size:`sm`,variant:`submit`,disabled:n||b.isLoading||v&&O&&!k,onClick:v?E(A):j,children:x(O&&v?`com_ui_update_rerun`:`com_ui_rerun`)})]})]})]})})}
8,ec=`Error connecting to server, try refreshing the page.`,tc=5500,nc=250,rc=e=>{let t=e.match(/:::thinking([\s\S]*?):::/);return{thinkingContent:t?t[1].trim():``,regularContent:t?e.replace(/:::thinking[\s\S]*?:::/,``).trim():e}},ic=()=>(0,Q.jsx)(`div`,{className:`mb-[0.625rem]`,children:(0,Q.jsx)(Me,{underHeaderIcon:!0})}),ac=({children:e,className:t=``})=>(0,Q.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:G(`rounded-xl border border-status-error-border bg-status-error-subtle p-3 text-sm text-text-secondary`,t),children:e}),oc=({message:e})=>{let t=K();return(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(ic,{}),children:(0,Q.jsx)(At,{delay:tc,children:(0,Q.jsx)(Vi,{message:e,children:(0,Q.jsx)(Sn,{variant:`error`,icon:!1,className:`mt-2 text-text-secondary shadow-sm transition-all`,children:t(`com_ui_error_connection`)})})})})},sc=({text:e,message:t,className:n=``})=>e===ec?(0,Q.jsx)(oc,{message:t}):(0,Q.jsx)(Vi,{message:t,children:(0,Q.jsx)(ac,{className:n,children:(0,Q.jsx)(Zs,{text:e,message:t})})}),cc=({text:e,isCreatedByUser:t,message:n,showCursor:r})=>{let{isSubmitting:i=!1,isLatestMessage:a=!1}=Ee(),o=w(Dn.enableUserMsgMarkdown),s=w(Dn.collapseLongUserMessages),c=kn(),l=(0,Z.useMemo)(()=>r===!0&&i&&!(c&&!t),[r,i,c,t]),u=(0,Z.useMemo)(()=>t?o?(0,Q.jsx)(Rr,{content:e}):(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsx)(hr,{content:e,isLatestMessage:a}),[t,o,e,a]);return(0,Q.jsx)(Vi,{message:n,children:(0,Q.jsx)(Lr,{enabled:t&&s,children:(0,Q.jsx)(`div`,{className:G(`markdown prose message-content dark:prose-invert light w-full break-words`,i&&`submitting`,l&&e.length>0&&`result-streaming`,t&&!o&&`whitespace-pre-wrap`,`text-text-primary`),children:u})})})},lc=({message:e})=>{let t=K();return e.finish_reason===X.TOOL_CALL_LIMIT_FINISH_REASON?(0,Q.jsx)(Vi,{message:e,children:(0,Q.jsx)(Qs,{message:e})}):(0,Q.jsx)(Vi,{message:e,children:(0,Q.jsx)(ac,{children:t(`com_ui_response_incomplete`)})})},uc=(0,Z.memo)(({text:e,edit:t,error:n,unfinished:r,isSubmitting:i,isLast:a,...o})=>{let{message:s}=o,{messageId:c}=s,{thinkingContent:l,regularContent:u}=(0,Z.useMemo)(()=>rc(e),[e]),d=(0,Z.useMemo)(()=>a&&i,[a,i]),f=(0,Z.useMemo)(()=>!i&&r?(0,Q.jsx)(Z.Suspense,{children:(0,Q.jsx)(At,{delay:nc,children:(0,Q.jsx)(lc,{message:s})})}):null,[i,r,s]);return n?(0,Q.jsx)(sc,{message:s,text:e}):t?(0,Q.jsx)($s,{text:e,isSubmitting:i,...o}):(0,Q.jsxs)(Q.Fragment,{children:[l.length>0&&(0,Q.jsx)(ln,{children:l},`thinking-${c}`),(0,Q.jsx)(cc,{showCursor:d,text:u,...o},`display-${c}`),f]})});uc.displayName=`MessageContent`;function dc(e){let t=e!=null&&e!==`new`,{data:n}=Ie(t?e:``,{enabled:t,select:ft}),r=t?n??null:null,[i,a]=o(fo),[s,c]=o(po),[l,u]=o(mo),[d,f]=o(ho),[p,m]=o(go),h=bo(),{submitAskAnswer:g}=Oo(),{getAskStatus:_}=xo(),v=Ue(),y=(0,Z.useRef)({conversationId:e,actionId:r?.actionId,formContext:v});y.current={conversationId:e,actionId:r?.actionId,formContext:v};let b=(0,Z.useRef)(p);b.current=p;let x=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(x.current=!0,()=>{x.current=!1}),[]);let S=r==null?`idle`:_(r.actionId),C=S===`submitting`||S===`submitted`||S===`expired`,w=r!=null&&S!==`expired`&&S!==`submitted`,T=w&&i.includes(r.actionId),E=w&&!T,D=E,O=(r?.questions?.length??0)>0,k=E&&!O,A=D&&O,j=!O&&r!=null&&r.question.multiSelect===!0,M=E&&r!=null&&!O?dr(r.actionId):null,{choices:N,otherLabel:P}=(0,Z.useMemo)(()=>Pt(O?void 0:r?.question.options),[O,r]),F=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{let t=F.current;if(w&&r){let n=t!=null&&t.conversationId===e&&t.actionId===r.actionId,i=S===`submitting`;F.current={conversationId:e,actionId:r.actionId,submitting:i,composerText:n&&i&&t.submitting?t.composerText:v?.getValues(`text`)??``};return}F.current=null;let n=Object.entries(p).find(([,t])=>t.conversationId===e);if(!n)return;let[i,a]=n,o=v?.getValues(`text`)??``;(t!=null&&t.actionId===i?!t.submitting||o===t.composerText:o===``)&&v?.setValue(`text`,a.text),m(e=>{if(e[i]==null)return e;let t={...e};return delete t[i],t})},[w,e,r,S,v,p,m]);let I=r==null?``:d[r.actionId]??``,L=(0,Z.useCallback)(e=>{r&&!O&&(f(t=>({...t,[r.actionId]:e})),h&&Vr({id:dr(r.actionId),value:e}))},[O,r,h,f]);(0,Z.useEffect)(()=>{c(null),u([])},[r?.actionId,c,u]);let ee=(0,Z.useCallback)(e=>{if(O){e();return}St(e)},[O]),R=(0,Z.useCallback)(()=>
8{if(r){let e=O?``:v?.getValues(`text`)??I;ee(()=>{if(!O){f(t=>({...t,[r.actionId]:e}));let t=p[r.actionId];t?(v?.setValue(`text`,t.text),m(e=>{if(e[r.actionId]==null)return e;let t={...e};return delete t[r.actionId],t})):h||v?.reset()}a(e=>e.includes(r.actionId)?e:[...e,r.actionId])})}},[r,O,v,I,h,p,m,f,a,ee]),z=(0,Z.useCallback)(()=>{if(r){let t=!O&&!h?v?.getValues(`text`)??``:``;ee(()=>{!O&&!h?(t&&m(n=>({...n,[r.actionId]:{conversationId:e??null,text:t}})),v?.setValue(`text`,I)):!O&&I&&Vr({id:dr(r.actionId),value:I}),a(e=>e.filter(e=>e!==r.actionId))})}},[r,e,O,h,v,I,m,a,ee]),te=(0,Z.useCallback)(e=>{u(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[u]),ne=E&&!C&&(j?l.length>0:typeof s==`number`&&N[s]!=null),B=(0,Z.useCallback)((t,n=!1)=>{if(!r||C||t.length===0)return!1;let i=E,a=e,o=r.actionId,s=v?.getValues(`text`)??``;return g(r.actionId,t.join(`, `),{onSuccess:()=>{let e=y.current;if(!x.current||e.conversationId!==a||e.actionId!==o)return;c(null),u([]),f(e=>{if(e[o]==null)return e;let t={...e};return delete t[o],t});let t=b.current[o];e.formContext?.getValues(`text`)===s&&(t?e.formContext.setValue(`text`,t.text):(n||i&&h)&&e.formContext.reset()),m(e=>{if(e[o]==null)return e;let t={...e};return delete t[o],t})}}),!0},[r,C,E,h,e,m,v,g,c,u,f]),re=(0,Z.useCallback)(()=>l.map(e=>N[e]?.value).filter(e=>typeof e==`string`),[l,N]),ie=(0,Z.useCallback)(e=>{let t=N[e];return t?B([t.value]):!1},[N,B]),ae=(0,Z.useCallback)(e=>{let t=e?.trim()??``;if(j){let e=re();return t.length>0&&e.push(t),B(e,t.length>0)}return typeof s==`number`&&ie(s)},[j,re,s,B,ie]),V=(0,Z.useCallback)(e=>{if(!E||!r||O)return!1;let t=e.trim();return t.length>0&&B(j?[...re(),t]:[t],!0),!0},[E,r,O,j,re,B]);return{active:E,batchMode:O,liveAsk:r,options:N,collapsed:T,collapse:R,expand:z,popoverVisible:D,composerAnswers:k,composerLocked:A,multiSelect:j,locked:C,selected:s,setSelected:c,checked:l,toggleChecked:te,answerText:I,setAnswerText:L,canSubmit:ne,submit:ae,submitOption:ie,submitText:V,submitAnswer:(0,Z.useCallback)(e=>B(e),[B]),skip:(0,Z.useCallback)(()=>E?B([Jt]):!1,[E,B]),handleComposerKeyDown:(0,Z.useCallback)(e=>{if(!E||e.nativeEvent.isComposing||e.key===`Process`||e.keyCode===229)return!1;let t=e.currentTarget.value;if(t.trim().length>0)return e.key===`Enter`&&!e.shiftKey&&!O&&(e.preventDefault(),V(t));if(N.length===0||!D)return e.key===`Escape`&&(R(),!0);let n=Number.parseInt(e.key,10);return!Number.isNaN(n)&&n>=1&&n<=Math.min(N.length,9)?(e.preventDefault(),j?(c(n-1),te(n-1)):c(n-1),!0):e.key===`ArrowDown`?(e.preventDefault(),c(((s??-1)+1)%N.length),!0):e.key===`ArrowUp`?(e.preventDefault(),c(((s??0)-1+N.length)%N.length),!0):e.key===`Enter`&&!e.shiftKey&&ne?(e.preventDefault(),ae(),!0):e.key===`Escape`&&(R(),!0)},[E,N,s,O,j,D,ne,ae,V,te,R,c]),handlePopoverKeyDown:(0,Z.useCallback)(e=>{if(!E||C||N.length===0)return!1;let t=Number.parseInt(e.key,10);return Number.isNaN(t)||t<1||t>Math.min(N.length,9)?!1:(e.preventDefault(),j?te(t-1):ie(t-1),!0)},[E,C,N,j,te,ie]),errored:S===`error`,otherLabel:P,draftId:M}}function fc({options:e,multiSelect:t,checked:n,selected:r,locked:a,onActivate:o,optionRefs:s,listRef:c,className:l}){return(0,Q.jsx)(`div`,{ref:c,className:l,children:e.map((e,c)=>{let l=t&&n.includes(c);return(0,Q.jsxs)(Y,{ref:e=>{s&&(s.current[c]=e)},variant:`ghost`,role:t?`checkbox`:void 0,"aria-checked":t?l:void 0,disabled:a,className:G(`flex h-auto w-full justify-start gap-2.5 whitespace-normal px-2.5 py-2 text-left text-sm font-normal text-text-primary`,r===c&&`bg-surface-active hover:bg-surface-active`),onClick:()=>o(c),children:[(0,Q.jsx)(`span`,{className:G(`flex size-5 shrink-0 items-center justify-center rounded-md text-[11px] font-medium tabular-nums transition-colors`,l?`bg-surface-submit text-text-on-status`:`bg-surface-tertiary text-text-secondary`),children:l?(0,Q.jsx)(i,{className:`size-3.5`,"aria-hidden":`true`}):c+1}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 [overflow-wrap:anywhere]`,children:e.label})]},e.value)})})}var pc=b({key:`askQuestionsFormState`,default:{step:0,text:{},selected:{}}});function mc(e,t){return Object.hasOwn(e,t)?e[t]:void 0}function hc(e,t){let[n,r]=f(pc(e)),i=y(pc(e)),{submitAskAnswer:a}=Oo(),{getAskStatus:o}=xo(),s=o(e),c=s===`submitting`||s===`submitted`||s===`expired`,l=(0,Z.useCallback)((e,t)=>{r(n=>({...n,text:{...n.text,[e.id]:t},selected:e.multiSelect===!0||t.length===0?n.selected:{...n.selected,[e.id]:[]}}))},[r]),u=(0,Z.useCallback)((e,t)=>{r(n=>{let r=mc(n.selected,e.id)??[],i=[t];return e.multiSelect===!0&&(i=r.includes(t)?r.filter(e=>e!==t):[...r,t]),{...n,text:e.multiSelect===!0?n.text:{...n.text,[e.id]:``},selected:{...n.selected,[e.id]:i}}})},[r]),d=(0,Z.useCallback)(e=>{let n=Math.min(Math.max(e,0),Math.max(t.length-1,0));r(e=>e.step===n?e:{...e,step:n})},[t.length,r]),p=(0,Z.useMemo)(()=>{let e=Object.create(null);for(let r of t){let t=mc(n.text,r.id)?.trim()??``,i=mc(n.selected,r.id)??[],a=r.multiSelect===!0?[...i]:[];t.length>0?a.push(t):r.multiSelect!==!0&&i[0]!=null&&a.push(i[0]),a.length>0&&(e[r.id]=a.join(`, `))}return e},[t,n.text,n.selected]),m=!c&&t.every(e=>(mc(p,e.id)?.length??0)>0),h=(0,Z.useCallback)(()=>m?(a(e,p,{onSuccess:i}),!0):!1,[e,p,m,i,a]),g=(0,Z.useCallback)(()=>
8{if(c)return!1;let n=Object.fromEntries(t.map(e=>[e.id,Jt]));return a(e,n,{onSuccess:i}),!0},[e,c,t,i,a]);return{state:n,step:Math.min(n.step,Math.max(t.length-1,0)),status:s,locked:c,answers:p,canSubmit:m,setText:l,selectOption:u,goToStep:d,submit:h,skip:g}}function gc({actionId:e,questions:t,className:n,onExpand:r,onDismiss:a}){let o=K(),s=(0,Z.useId)(),c=hc(e,t),{goToStep:l,selectOption:u}=c,d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(!1),m=t.length,g=m>1,v=c.step,y=v===m-1,b=c.status===`submitting`,x=(0,Z.useMemo)(()=>{for(let e=0;e<t.length;e++)if(!Object.hasOwn(c.answers,t[e].id))return e;return-1},[t,c.answers]),S=(0,Z.useCallback)((e,t)=>{u(e,t),!(e.multiSelect===!0||v>=m-1)&&(p.current=!0,l(v+1))},[v,l,u,m]);if((0,Z.useEffect)(()=>{d.current!=null&&(d.current.scrollTop=0),p.current&&(p.current=!1,f.current?.focus())},[v]),c.status===`submitted`)return null;let w=t[v];if(w==null)return null;let{choices:T,otherLabel:E}=Pt(w.options),D=Object.hasOwn(c.state.selected,w.id)?c.state.selected[w.id]:[],O=Object.hasOwn(c.state.text,w.id)?c.state.text[w.id]:``,k=w.header??(g?null:o(`com_ui_question_number`,{0:1})),A=m-Object.keys(c.answers).length,j=g&&y&&!c.locked&&x>=0&&x!==v;return(0,Q.jsxs)(`div`,{className:G(`flex min-h-0 flex-col`,n),children:[(r!=null||a!=null)&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end border-b border-border-light px-2 py-1`,children:[r!=null&&(0,Q.jsx)(Y,{variant:`ghost`,size:`icon-sm`,"aria-label":o(`com_ui_expand`),className:`text-text-secondary`,onClick:r,children:(0,Q.jsx)(_,{className:`h-4 w-4`,"aria-hidden":`true`})}),a!=null&&(0,Q.jsx)(Y,{variant:`ghost`,size:`icon-sm`,"aria-label":o(`com_ui_close`),className:`text-text-secondary`,onClick:a,children:(0,Q.jsx)(C,{className:`h-4 w-4`,"aria-hidden":`true`})})]}),g&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border-light px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-text-secondary`,"aria-live":`polite`,children:o(`com_ui_question_step`,{0:v+1,1:m})}),(0,Q.jsx)(`div`,{role:`group`,"aria-label":o(`com_ui_question_navigation`),className:`flex flex-wrap items-center justify-end`,children:t.map((e,t)=>{let n=Object.hasOwn(c.answers,e.id),r=t===v;return(0,Q.jsx)(`button`,{type:`button`,disabled:b,"aria-current":r?`step`:void 0,"aria-label":o(n?`com_ui_question_step_answered`:`com_ui_question_step_unanswered`,{0:t+1}),className:`flex h-6 items-center justify-center px-1`,onClick:()=>l(t),children:(0,Q.jsx)(`span`,{className:G(`h-2 rounded-full`,r?`w-4`:`w-2`,n?`bg-surface-submit`:`bg-border-heavy`)})},e.id)})})]}),(0,Q.jsx)(`div`,{ref:d,className:`min-h-0 flex-1 overflow-y-auto px-3`,children:(0,Q.jsxs)(`fieldset`,{ref:f,tabIndex:-1,"aria-labelledby":s,className:G(`py-3 outline-none`,g&&`min-h-40`),children:[k!=null&&(0,Q.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-text-secondary`,children:k}),(0,Q.jsx)(`p`,{id:s,className:`text-sm font-medium text-text-primary [overflow-wrap:anywhere]`,children:w.question}),w.description!=null&&w.description.length>0&&(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-text-secondary [overflow-wrap:anywhere]`,children:w.description}),T.length>0&&(0,Q.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,role:`group`,children:T.map(e=>{let t=D.includes(e.value);return(0,Q.jsxs)(Y,{type:`button`,size:`sm`,variant:t?`submit`:`choice`,role:w.multiSelect===!0?`checkbox`:void 0,"aria-checked":w.multiSelect===!0?t:void 0,"aria-pressed":w.multiSelect===!0?void 0:t,disabled:c.locked,className:`h-auto min-h-9 max-w-full whitespace-normal py-1.5 text-left [overflow-wrap:anywhere]`,onClick:()=>S(w,e.value),children:[w.multiSelect===!0&&t&&(0,Q.jsx)(i,{className:`mr-1.5 h-4 w-4 shrink-0`,"aria-hidden":`true`}),e.label]},e.value)})}),(0,Q.jsx)(Vn,{value:O,disabled:c.locked,onChange:e=>c.setText(w,e.target.value),minRows:1,maxRows:6,placeholder:E??o(`com_ui_your_answer`),className:`mt-2 w-full resize-none rounded-md border border-border-xheavy bg-surface-primary p-2 text-sm text-text-primary`,"aria-label":`${w.question} ${o(`com_ui_your_answer`)}`})]})}),(c.status===`error`||c.status===`expired`)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1 text-xs text-text-warning`,children:[(0,Q.jsx)(h,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),c.status===`expired`?o(`com_ui_approval_expired`):o(`com_ui_ask_answer_error`)]}),j&&(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 px-3 py-1 text-left text-xs text-text-secondary hover:text-text-primary hover:underline`,onClick:()=>l(x),children:o(A===1?`com_ui_questions_remaining_one`:`com_ui_questions_remaining`,{0:A})}),(0,Q.jsxs)(`div`,{className:G(`flex shrink-0 items-center gap-2 border-t border-border-light p-3`,g?`justify-between`:`justify-end`),children:[(0,Q.jsx)(Y,{type:`button`,size:`sm`,variant:`outline`,disabled:c.locked,onClick:c.skip,children:o(`com_ui_skip`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[g&&(0,Q.jsx)(Y,{type:`button`,size:`sm`,variant:`outline`,disabled:b||v===0,onClick:()=>l(v-1),children:o(`com_ui_back`)}),y?(0,Q.jsx)(Y,{type:`button`,size:`sm`,variant:`submit`,disabled:!c.canSubmit,onClick:c.submit,children:c.status===`submitting`?o(`com_ui_submitting`):o(`com_ui_submit`)}):(0,Q.jsx)(Y,{type:`button`,size:`sm`,variant:`submit`,disabled:b,onClick:()=>l(v+1),children:o(`com_ui_next`)})]})]})]})}function _c({actionId:e,question:t,questions:n}){let r=(0,Z.useContext)(yn)?.conversation?.conversationId,i=dc(r),a=i.liveAsk?.actionId===e;return n!=null&&n.length>0?i.popoverVisible&&a?null:(0,Q.jsx)(gc,{actionId:e,questions:n,className:`my-2 max-h-[70vh] w-full rounded-lg border border-border-light bg-surface-secondary`,onExpand:i.collapsed&&a?i.expand:void 0}):(0,Q.jsx)(vc,{actionId:e,question:t,answerMode:i})}function vc({actionId:e,question:t,answerMode:n}){let i=K(),{getAskAnswerDraft:a,setAskAnswerDraft:o}=Co(),{getAskStatus:s}=xo(),{submitAskAnswer:c}=Oo(),[l,u]=(0,Z.useState)(()=>a(e)),[d,f]=(0,Z.useState)([]),{popoverVisible:p,collapsed:m,expand:g,liveAsk:v}=n,y=v?.actionId===e,{choices:b,otherLabel:x}=(0,Z.useMemo)(()=>Pt(t.options),[t.options]),S=s(e),C=S===`submitting`||S===`submitted`||S===`expired`,w=p&&y;if(S===`submitted`)return null;let T=t.multiSelect===!0,E=y?n.checked:d,D=y?n.answerText:l,O=e=>{if(y){n.setAnswerText(e);return}u(e)},k=e=>{if(y){n.toggleChecked(e);return}f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},A=D.trim(),j=T&&E.length>0||A.length>0,M=t=>{if(y){n.submitOption(t);return}let r=b[t]?.value;r!=null&&c(e,r)},N=(0,Q.jsxs)(`div`,{className:G(`my-2 flex w-full flex-col gap-2.5 rounded-xl border border-border-light bg-surface-secondary p-3`,w&&`invisible`),"aria-hidden":w||void 0,style:y&&!w?{viewTransitionName:`ask-question`}:void 0,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium text-text-primary [overflow-wrap:anywhere]`,children:t.question}),t.description!=null&&t.description.length>0&&(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-text-secondary [overflow-wrap:anywhere]`,children:t.description})]}),m&&y&&(0,Q.jsx)(qr,{description:i(`com_ui_ask_move_to_composer`),side:`top`,render:(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,"aria-label":i(`com_ui_ask_move_to_composer`),className:`size-auto rounded-md p-1 text-text-secondary`,onClick:g,children:(0,Q.jsx)(_,{className:`size-4`,"aria-hidden":`true`})})})]}),b.length>0&&(0,Q.jsx)(fc,{options:b,multiSelect:T,checked:E,locked:C,onActivate:e=>T?k(e):M(e)}),(0,Q.jsx)(Vn,{value:D,disabled:C,onChange:t=>{O(t.target.value),o(e,t.target.value)},minRows:2,maxRows:12,placeholder:x??i(`com_ui_your_answer`),className:`w-full resize-none rounded-lg border border-border-light bg-surface-chat px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-text-primary`,"aria-label":i(`com_ui_your_answer`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(Y,{size:`sm`,variant:`outline`,disabled:C,onClick:()=>
8{if(y){n.submitAnswer([Jt]);return}c(e,Jt)},children:i(`com_ui_skip`)}),(S===`expired`||S===`error`)&&(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center text-xs text-text-warning`,children:[(0,Q.jsx)(h,{className:`mr-1.5 size-4 shrink-0`,"aria-hidden":`true`}),i(S===`expired`?`com_ui_approval_expired`:`com_ui_approval_error`)]}),(0,Q.jsx)(Y,{size:`sm`,variant:`submit`,className:`ml-auto`,disabled:!j||C,onClick:()=>{let t=T?E.map(e=>b[e]?.value).filter(e=>typeof e==`string`):[];if(A.length>0&&t.push(A),t.length!==0){if(y){n.submitAnswer(t);return}c(e,t.join(`, `))}},children:i(S===`submitting`?`com_ui_submitting`:`com_ui_submit`)})]})]});return w?(0,Q.jsxs)(`div`,{className:`relative`,children:[N,(0,Q.jsxs)(`div`,{className:`absolute inset-x-0 top-0 my-1 flex h-5 items-center gap-2.5`,children:[(0,Q.jsx)(r,{className:`size-4 shrink-0 text-text-secondary`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`tool-status-text shimmer font-medium text-text-secondary`,children:i(`com_ui_asking`)})]})]}):N}function yc(e){if(!e)return[];let t=new Map;for(let n of e){if(n.type!==q.file_search||!n[q.file_search])continue;let e=n[q.file_search];if(e.sources)for(let n of e.sources){let e=n.fileId,r=t.get(e),i=n.metadata;r?(r.pages=[...new Set([...r.pages,...n.pages||[]])],r.relevance=Math.max(r.relevance,n.relevance||0),r.pageRelevance={...r.pageRelevance,...n.pageRelevance},n.content&&r.content?r.content+=`
9
10`+n.content:n.content&&(r.content=n.content)):t.set(e,{fileId:n.fileId,fileName:n.fileName,relevance:n.relevance||0,content:n.content||``,pages:n.pages||[],pageRelevance:n.pageRelevance||{},fileType:i?.fileType||void 0,fileBytes:i?.fileBytes||void 0,fileSource:i?.storageType||void 0,metadata:i})}}return Array.from(t.values()).sort((e,t)=>t.relevance-e.relevance)}function bc(e){return e.toLowerCase().replace(/[^a-z0-9.]/g,``)}function xc(e,t,n){if(!t)return;let r=bc(t);if(r.length===0)return;let i=e.get(r);if(!i){e.set(r,n);return}i.fileId!==n.fileId&&e.set(r,null)}function Sc(e,t){let n=new Map;for(let t of e)xc(n,t.fileName,{fileId:t.fileId,fileName:t.fileName,fileType:t.fileType,fileBytes:t.fileBytes,fileSource:t.fileSource});for(let e of t??[]){if(!e.file_id||!e.filename)continue;let t=bc(e.filename);n.has(t)||xc(n,e.filename,{fileId:e.file_id,fileName:e.filename,fileType:e.type??void 0,fileBytes:e.bytes,fileSource:e.source??void 0})}return n}function Cc(e,t,n){if(t.length===0)return e.map(e=>({fileId:e.fileId,fileName:e.fileName,relevance:e.relevance,content:e.content,pages:e.pages,pageRelevance:e.pageRelevance,fileType:e.fileType,fileBytes:e.fileBytes,fileSource:e.fileSource}));let r=Sc(e,n);return t.map(e=>{let t=bc(e.filename),n=r.get(t)??void 0;return{fileId:n?.fileId,fileName:n?.fileName??e.filename,relevance:e.relevance,content:e.content,fileType:n?.fileType,fileBytes:n?.fileBytes,fileSource:n?.fileSource}})}function wc(e){let t=e.split(`
11---
12`),n=[];for(let e of t){let t=e.trim();if(!t)continue;let r=``,i=0,a=[],o=!1;for(let e of t.split(`
13`)){if(o){a.push(e);continue}e.startsWith(`File: `)?r=e.slice(6).trim():e.startsWith(`Relevance: `)?i=parseFloat(e.slice(11).trim())||0:e.startsWith(`Content: `)&&(o=!0,a.push(e.slice(9)))}r&&n.push({filename:r,relevance:i,content:a.join(`
14`).trim()})}return n}function Tc(e){return e?e.includes(`spreadsheet`)||e.includes(`excel`)||e.includes(`csv`)?N:e.includes(`image`)?ne:e.includes(`javascript`)||e.includes(`typescript`)||e.includes(`json`)||e.includes(`xml`)||e.includes(`html`)?L:e.includes(`pdf`)||e.includes(`text`)||e.includes(`word`)?A:m:A}function Ec({fileName:e,relevance:t,pages:n,pageRelevance:r,fileType:i,onOpenPreview:a}){let o=K(),s=Tc(i),c=n&&r?ke(n,r):n;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,Q.jsx)(s,{className:`size-3.5 shrink-0 text-text-secondary`,"aria-hidden":`true`}),a?(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`min-w-0 truncate text-left text-xs font-medium text-text-primary underline decoration-border-medium underline-offset-2 transition-colors hover:text-text-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy focu
14s-visible:ring-offset-1`,"aria-label":`${o(`com_ui_preview`)}: ${e}`,children:e}):(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-xs font-medium text-text-primary`,children:e}),t>0&&(0,Q.jsx)(qr,{description:o(`com_ui_relevance`),side:`top`,className:`flex cursor-help items-center`,children:(0,Q.jsxs)(`span`,{className:`shrink-0 cursor-help rounded bg-surface-tertiary px-1.5 py-0.5 text-[11px] tabular-nums leading-none text-text-secondary`,"aria-label":`${o(`com_ui_relevance`)}: ${Math.round(t*100)}%`,children:[Math.round(t*100),`%`]})}),(0,Q.jsx)(`span`,{className:`flex-1`}),c&&c.length>0&&(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-text-secondary`,children:o(`com_file_pages`,{pages:c.join(`, `)})})]})}function Dc({initialProgress:e=.1,isSubmitting:t,args:n,output:r,attachments:i,onExpand:a,runStepStatus:o,runStepDurationMs:s}){let c=Oe(o==null?e:1),l=K(),u=fr(n),d=en({runStepStatus:o,displayProgress:c,reportedProgress:e,isSubmitting:t,hasError:typeof r==`string`&&Qr(r)}),f=!!r&&!Qr(r),p=w(Dn.autoExpandTools),m=(0,Z.useMemo)(()=>yc(i),[i]),h=(0,Z.useMemo)(()=>f&&r?wc(r):[],[f,r]),g=(0,Z.useMemo)(()=>new Set(m.map(e=>e.fileId).filter(Boolean)),[m]),{data:_=[]}=tr({enabled:f&&h.length>0&&g.size>0,select:e=>e.filter(e=>g.has(e.file_id))}),v=(0,Z.useMemo)(()=>Cc(m,h,_),[_,m,h]),y=v.length>0,b=d!==`failed`&&y,[x,S]=(0,Z.useState)(()=>p&&b),{style:C,ref:T}=Et(x),[E,D]=(0,Z.useState)(null),O=(0,Z.useCallback)(e=>{D(e)},[]),k=(0,Z.useCallback)(e=>{e||D(null)},[]),A=(0,Z.useMemo)(()=>{if(E===null)return null;let e=v[E];return e?.fileId?{fileName:e.fileName,fileId:e.fileId,relevance:e.relevance,pages:e.pages,pageRelevance:e.pageRelevance,fileType:e.fileType,fileSource:e.fileSource}:null},[v,E]);(0,Z.useEffect)(()=>{if(!b){S(!1);return}p&&S(!0)},[p,b]);let j=(0,Z.useCallback)(()=>{S(e=>{let t=!e;return t&&a?.(),t})},[a]);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:d===`running`?l(`com_ui_searching_files`):d===`cancelled`?l(`com_ui_cancelled`):d===`failed`?l(`com_ui_failed`):u??l(`com_ui_retrieved_files`)}),(0,Q.jsx)(`div`,{className:`relative my-1 flex h-5 shrink-0 items-center gap-2.5`,children:(0,Q.jsx)(De,{phase:d,onClick:b?j:void 0,inProgressText:u??l(`com_ui_searching_files`),finishedText:d===`cancelled`?l(`com_ui_cancelled`):u??l(`com_ui_retrieved_files`),durationMs:s,icon:(0,Q.jsx)(Ft,{type:`file_search`,isAnimating:d===`running`}),hasInput:b,isExpanded:x})}),(0,Q.jsx)(`div`,{style:C,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:T,children:b&&(0,Q.jsx)(`div`,{className:G(`mb-2 mt-0`,`flex flex-col gap-2`),children:v.map((e,t)=>(0,Q.jsxs)(`div`,{className:G(`overflow-hidden rounded-lg border border-border-light bg-surface-secondary`),children:[(0,Q.jsx)(Ec,{fileName:e.fileName,relevance:e.relevance,pages:e.pages,pageRelevance:e.pageRelevance,fileType:e.fileType,onOpenPreview:e.fileId?()=>O(t):void 0}),e.content&&(0,Q.jsx)(`div`,{className:`border-t border-border-light px-3 py-3`,children:(0,Q.jsx)(Ur,{text:e.content})})]},`${e.fileId??e.fileName}-${t}`))})})}),(0,Q.jsx)(Qn,{open:A!==null,onOpenChange:k,fileName:A?.fileName??``,fileId:A?.fileId,relevance:A?.relevance,pages:A?.pages,pageRelevance:A?.pageRelevance,fileType:A?.fileType,fileSource:A?.fileSource})]})}var Oc=16384,kc=200,Ac=65536,jc=1024,Mc=1024,Nc=256,Pc=/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u206f]/g;function Fc(e){return e.replace(Pc,e=>`\\u${e.codePointAt(0)?.toString(16).padStart(4,`0`)??`????`}`)}var Ic=/[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u206f]/g;function Lc(e,t){let n=e.replace(Ic,e=>`\\u${e.codePointAt(0)?.toString(16).padStart(4,`0`)??`????`}`);return{label:n.slice(0,t),truncated:n.length>t}}function Rc(e,t=Oc){let n=e.split(`
15`),r=n.length>kc?n.slice(0,kc):n,i=Fc(r.join(`
16`)),a=r.length<n.length,o=i.length>t;return o&&(i=i.slice(0,t)),{body:i,truncated:a||o}}function zc(e){if(typeof e==`object`&&e&&!Array.isArray(e))return e;if(typeof e==`string`)try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:void 0}catch{return}}function Bc(e,...t){for(let n of t){let t=e?.[n];if(typeof t==`string`)return t}return``}function Vc(e){if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Hc(e,t=Oc){let n=zc(e.arguments),r=`generic`,i,a=Vc(e.arguments);e.source===`librechat_code`&&e.name===`bash_tool`&&n&&n.environmentAction===void 0?(r=`command`,a=Bc(n,`command`)):e.source===`librechat_code`&&e.name===`create_file`&&n?(r=`create`,i=Bc(n,`path`,`file_path`)||void 0,a=Bc(n,`content`)||Vc(e.arguments)):e.source===`librechat_code`&&e.name===`edit_file`&&n&&(r=`edit`,i=Bc(n,`path`,`file_path`)||void 0,a=Vc(n.edits??n));let o=Math.max(0,t),s=Lc(e.name,Math.min(Nc,o)),c=Math.max(0,o-s.label.length),l=e.description==null?void 0:Lc(e.description,Math.min(Mc,c));c=Math.max(0,c-(l?.label.length??0));let u=i==null?void 0:Lc(i,Math.min(jc,c));c=Math.max(0,c-(u?.label.length??0));let d=Rc(a,c);return{kind:r,toolName:s.label,description:l?.label,target:u?.label,body:d.body,truncated:d.truncated||u?.truncated===!0||l?.truncated===!0||s.truncated}}function Uc(e){let t=Ac;return e.map(e=>{let n=Hc(e,Math.min(Oc,t));return t=Math.max(0,t-n.body.length-n.toolName.length-(n.description?.length??0)-(n.target?.length??0)),n})}function Wc(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Gc={approve:i,reject:C,edit:d,respond:k},Kc={approve:`com_ui_approve`,reject:`com_ui_reject`,edit:`com_ui_edit`,respond:`com_ui_respond`},qc=`w-full resize-none rounded-md border border-border-xheavy bg-surface-primary p-2 text-text-primary placeholder:text-text-secondary`;
16function Jc(e){if(e==null)return`{}`;if(typeof e==`string`)try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch(e){return it.error(`ToolApproval - failed to stringify args`,e),`{}`}}function Yc({approval:e,toolCallId:t,args:n,surface:r=`thread`}){let i=K(),{actionId:a,allowed_decisions:o,description:s}=e,c=(0,Z.useContext)(yn)?.conversation?.conversationId,l=Cn(c,a),u=r===`thread`&&l,{registerToolCall:d,unregisterToolCall:f,setDecision:p,getDecision:m,getDecisionDraft:g,setDecisionDraft:_,isReady:v,getStatus:y,getLeadToolCallId:b,getRegisteredCount:x}=Co(),{submitToolApproval:S}=Oo(),C=m(a,t),w=C!=null&&o.includes(C.decision)?C:void 0,T=w?.decision===`edit`?JSON.stringify(w.editedArguments,null,2)??`{}`:Jc(n),E=g(a,t)??{active:w?.decision??null,editText:T,responseText:w?.decision===`respond`?w.responseText??``:``,reason:w?.decision===`reject`?w.reason??``:``},{active:D,editText:O,responseText:k,reason:A}=E,j=e=>_(a,t,{...E,...e});(0,Z.useEffect)(()=>(d(a,t),()=>f(a,t)),[d,f,a,t]);let M=y(a),N=M===`submitting`||M===`submitted`||M===`expired`,P=s==null?void 0:Lc(s,1024).label;(0,Z.useEffect)(()=>{if(!N){if(D==null){p(a,t,null);return}if(D===`approve`){p(a,t,{tool_call_id:t,decision:`approve`});return}if(D===`reject`){p(a,t,{tool_call_id:t,decision:`reject`,reason:A.trim()||void 0});return}if(D===`respond`){let e=k.trim();p(a,t,e.length>0?{tool_call_id:t,decision:`respond`,responseText:e}:null);return}if(D===`edit`)try{let e=JSON.parse(O);p(a,t,Wc(e)?{tool_call_id:t,decision:`edit`,editedArguments:e}:null)}catch{p(a,t,null)}}},[D,O,k,A,N,p,a,t]);let F=(0,Z.useMemo)(()=>{if(D!==`edit`)return!0;try{return Wc(JSON.parse(O))}catch{return!1}},[D,O]),I=b(a)===t,L=x(a),ee=v(a),R=(0,Z.useMemo)(()=>M===`submitting`?i(`com_ui_submitting`):L>1?i(`com_ui_submit_decisions`,{0:L}):i(`com_ui_submit`),[M,L,i]);if(M===`submitted`)return null;let z=P!=null&&P.length>0&&(0,Q.jsx)(`p`,{className:`text-sm text-text-secondary`,children:P});return u?(0,Q.jsxs)(`div`,{className:`my-2 flex w-full flex-col gap-2 rounded-lg border border-border-light bg-surface-secondary p-3`,"data-testid":`tool-approval`,"data-tool-call-id":t,children:[z,(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-text-secondary`,children:[(0,Q.jsx)(se,{className:`size-4 shrink-0`,"aria-hidden":`true`}),i(`com_ui_approval_review_in_composer`)]})]}):(0,Q.jsxs)(`div`,{className:`my-2 flex w-full flex-col gap-2 rounded-lg border border-border-light bg-surface-secondary p-3`,"data-testid":`tool-approval`,"data-tool-call-id":t,children:[z,(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:o.map(e=>{let t=Gc[e];return(0,Q.jsxs)(Y,{size:`sm`,variant:D===e?`default`:`outline`,disabled:N,"aria-pressed":D===e,onClick:()=>j({active:D===e?null:e}),className:`inline-flex items-center gap-1.5`,children:[(0,Q.jsx)(t,{className:`h-4 w-4`,"aria-hidden":`true`}),i(Kc[e])]},e)})}),D===`edit`&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(Vn,{value:O,disabled:N,onChange:e=>j({editText:e.target.value}),minRows:3,maxRows:16,className:G(qc,`font-mono text-xs`,!F&&`border-red-500`),"aria-label":i(`com_ui_edit`)}),!F&&(0,Q.jsx)(`span`,{className:`text-xs text-text-warning`,children:i(`com_ui_invalid_json`)})]}),D===`respond`&&(0,Q.jsx)(Vn,{value:k,disabled:N,onChange:e=>j({responseText:e.target.value}),minRows:2,maxRows:12,placeholder:i(`com_ui_tool_response_placeholder`),className:G(qc,`text-sm`),"aria-label":i(`com_ui_respond`)}),D===`reject`&&(0,Q.jsx)(Vn,{value:A,disabled:N,onChange:e=>j({reason:e.target.value}),minRows:1,maxRows:6,placeholder:i(`com_ui_reject_reason_placeholder`),className:G(qc,`text-sm`),"aria-label":i(`com_ui_reject`)}),r===`thread`&&I&&(0,Q.jsxs)(`div`,{className:`mt-1 flex items-center gap-3`,children:[(0,Q.jsx)(Y,{size:`sm`,variant:`submit`,disabled:!ee||N,onClick:()=>S(a),children:R}),M===`expired`&&(0,Q.jsxs)(`span`,{className:`flex items-center text-xs text-text-warning`,children:[(0,Q.jsx)(h,{className:`mr-1.5 h-4 w-4`,"aria-hidden":`true`}),i(`com_ui_approval_expired`)]}),M===`error`&&(0,Q.jsxs)(`span`,{className:`flex items-center text-xs text-text-warning`,children:[(0,Q.jsx)(h,{className:`mr-1.5 h-4 w-4`,"aria-hidden":`true`}),i(`com_ui_approval_error`)]})]})]})}var Xc=e(fe(),1),Zc=/^\s*\{\s*"([^"\\]+)"\s*:\s*"((?:[^"\\]|\\.)*)/s;function Qc(e){if(typeof e==`string`)return e.trim();if(e==null)return``;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);try{return JSON.stringify(e,null,2)}catch{return``}}function $c(e){return Object.entries(e).reduce((e,[t,n])=>{let r=Qc(n);return r&&e.push({key:t,value:r}),e},[])}function el(e){if(typeof e!=`string`)return $c(e);let t=e.trim();if(!t)return[];try{let e=JSON.parse(t);if(typeof e==`object`&&e&&!Array.isArray(e))return $c(e);let n=Qc(e);return n?[{value:n}]:[]}catch{let e=t.match(Zc);if(e){let t=gn(e[2]);return t?[{key:e[1],value:t}]:[]}return t.startsWith(`{`)?[]:[{value:t}]}}var tl={instruction:`com_ui_handoff_field_instructions`,instructions:`com_ui_handoff_field_instructions`,context:`com_ui_handoff_field_context`};function nl(e,t){let n=tl[e.toLowerCase()];if(n)return t(n);let r=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim();return r?r.charAt(0).toUpperCase()+r.slice(1):e}var rl=({name:e,args:t=``})=>{let n=K(),r=Un(),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(!1),c=(0,Z.useRef)(),l=(0,Z.useId)(),u=`${l}-heading`,{style:d,ref:f}=Et(i);(0,Z.useEffect)(()=>()=>clearTimeout(c.current),[]);let p=(0,Z.useMemo)(()=>typeof e!=`string`||!e.startsWith(X.LC_TRANSFER_TO_)?null:e.replace(X.LC_TRANSFER_TO_,``),[e]),m=(0,Z.useMemo)(()=>!p||!r?null:r[p],[r,p]),h=(0,Z.useMemo)(()=>el(t),[t]),g=(0,Z.useMemo)(()=>h.length===1?h[0].value:h.map(({key:e,value:t})=>`${e?`${nl(e,n)}\n`:``}${t}`).join(`
17
18`),[h,n]),_=h.length>0,v=m?.name||n(`com_ui_agent`),y=(0,Z.useCallback)(()=>{(0,Xc.default)(g,{format:`text/plain`})&&(clearTimeout(c.current),s(!0),c.current=setTimeout(()=>s(!1),2e3))},[g]);return(0,Q.jsxs)(`div`,{className:`my-2`,children:[(0,Q.jsxs)(Y,{variant:`ghost`,className:G(`tool-status-text h-auto justify-start gap-2 rounded-none p-0 font-normal text-text-secondary hover:bg-transparent hover:text-text-primary`,!_&&`pointer-events-none disabled:opacity-100`),disabled:!_,onClick:_?()=>a(!i):void 0,"aria-expanded":_?i:void 0,"aria-controls":_?l:void 0,"aria-label":`${n(`com_ui_transferred_to`)} ${v}`,children:[(0,Q.jsx)(`div`,{className:`flex h-6 w-6 shrink-0 items-center justify-center overflow-hidden rounded-full ring-1 ring-border-light`,children:(0,Q.jsx)(Gr,{message:{endpoint:Ae.agents,isCreatedByUser:!1},agent:m||void 0})}),(0,Q.jsx)(`span`,{className:`select-none`,children:n(`com_ui_transferred_to`)}),(0,Q.jsx)(`span`,{className:`select-none font-medium text-text-primary`,children:v}),_&&(0,Q.jsx)(he,{className:G(`size-4 shrink-0 translate-y-[1px] text-text-secondary transition-transform duration-200 ease-out`,i&&`rotate-180`),"aria-hidden":`true`})]}),(0,Q.jsx)(`div`,{id:l,style:d,"aria-hidden":!i||void 0,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:f,children:_&&(0,Q.jsxs)(`section`,{"aria-labelledby":u,className:G(`mb-2 mt-0`,`group/handoff ml-8 max-w-3xl border-l-2 border-border-medium py-1 pl-4 pr-1`),children:[(0,Q.jsxs)(`div`,{className:`mb-1.5 flex min-h-5 items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{id:u,className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:n(`com_ui_handoff_instructions`)}),(0,Q.jsx)(yr,{isCopied:o,iconOnly:!0,onClick:y,label:n(`com_ui_copy_to_clipboard`),copiedLabel:n(`com_ui_copied_to_clipboard`),className:`shrink-0 opacity-60 focus-visible:opacity-100 group-focus-within/handoff:opacity-100 group-hover/handoff:opacity-100`})]}),h.length===1?(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm leading-6 text-text-primary`,children:h[0].value}):(0,Q.jsx)(`dl`,{className:`space-y-3`,children:h.map(({key:e,value:t},r)=>(0,Q.jsxs)(`div`,{children:[e&&(0,Q.jsx)(`dt`,{className:`mb-0.5 text-xs font-medium text-text-secondary`,children:nl(e,n)}),(0,Q.jsx)(`dd`,{className:`whitespace-pre-wrap break-words text-sm leading-6 text-text-primary`,children:t})]},`${e??`field`}-${r}`))})]})})})]})};function il({initialProgress:e=.1,code:t,outputs:n=[],onExpand:r}){let i=K(),a=Oe(e),o=w(Dn.autoExpandTools),[s,c]=(0,Z.useState)(o);(0,Z.useEffect)(()=>{o&&c(!0)},[o]);let l=()=>{c(e=>{let t=!e;return t&&r?.(),t})},u=n.reduce((e,t)=>
18t.logs?e+t.logs+`
19`:e,``),d=a<1?`running`:`completed`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:i(d===`running`?`com_ui_analyzing`:`com_ui_analyzing_finished`)}),(0,Q.jsx)(`div`,{className:`relative my-1 flex h-5 shrink-0 items-center gap-2.5`,children:(0,Q.jsx)(De,{phase:d,onClick:l,inProgressText:i(`com_ui_analyzing`),finishedText:i(`com_ui_analyzing_finished`),hasInput:!!t.length,isExpanded:s,icon:(0,Q.jsx)(j,{className:G(`size-4 shrink-0 text-text-secondary`,d===`running`&&`animate-pulse`),"aria-hidden":`true`})})}),s&&(0,Q.jsxs)(`div`,{className:`code-analyze-block mb-3 mt-0.5 overflow-hidden rounded-xl bg-black`,children:[(0,Q.jsx)(Rr,{content:t?`\`\`\`python\n${t}\n\`\`\``:``}),u&&(0,Q.jsxs)(`div`,{className:`bg-gray-700 p-4 text-xs`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-gray-400`,children:i(`com_ui_result`)}),(0,Q.jsx)(`div`,{className:`prose flex flex-col-reverse text-white`,style:{color:`white`},children:(0,Q.jsx)(`pre`,{className:`shrink-0`,children:u})})]})]})]})}function al({initialProgress:e=.1,isLast:t=!1,isSubmitting:n,toolCallId:r,name:i,args:a=``,output:o,attachments:s,auth:c,hideAttachments:l=!1,onExpand:u,runStepStatus:d,runStepDurationMs:f,toolPreparationStartedAt:p,toolDispatchedAt:m,toolPreparationDurationMs:h,toolExecutionDurationMs:g}){let _=K(),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(`pending`),S=w(Dn.autoExpandTools),C=(o?.length??0)>0,[T,E]=(0,Z.useState)(()=>S&&C),{style:D,ref:O}=Et(T),{shouldRenderBody:k,mountBody:A,handleTransitionEnd:j}=Kr(T);(0,Z.useEffect)(()=>{S&&C&&E(!0)},[S,C]);let M=(0,Z.useMemo)(()=>{if(!c)return null;try{return new URL(c)}catch{return null}},[c]),N=er(),{function_name:P,domain:F,isMCPToolCall:I,mcpServerName:L}=(0,Z.useMemo)(()=>{if(typeof i!=`string`)return{function_name:``,domain:null,isMCPToolCall:!1,mcpServerName:``};if(i.includes(X.mcp_delimiter)){let[e,t=``]=Br(i,N);return{function_name:(e===`oauth`?t:e)||``,domain:t&&(t.replaceAll(`---`,`.`)||null),isMCPToolCall:!0,mcpServerName:t||``}}if(M){let e=(M.searchParams.get(`redirect_uri`)||``).match(/\/api\/mcp\/([^/]+)\/oauth\/callback/);if(e?.[1])return{function_name:e[1],domain:null,isMCPToolCall:!0,mcpServerName:e[1]}}let[e,t]=i.includes(`_action_`)?i.split(ur):[i,``];return{function_name:e||``,domain:t&&(t.replaceAll(`---`,`.`)||null),isMCPToolCall:!1,mcpServerName:``}},[i,M,N]),ee=(0,Z.useMemo)(()=>ni(i),[i]),R=(0,Z.useMemo)(()=>I?P:Se(P,_,N),[P,I,_,N]),z=Te(),te=I?z.get(L):void 0,ne=(0,Z.useMemo)(()=>I||!M?``:(M.searchParams.get(`redirect_uri`)||``).match(/\/api\/actions\/([^/]+)\/oauth\/callback/)?.[1]||``,[M,I]),B=(0,Z.useCallback)(()=>{let e=I&&L.length>0;return!e&&!ne?null:(async()=>{e?await Ne.bindMCPOAuth(L):await Ne.bindActionOAuth(ne)})()}
19,[I,L,ne]),re=typeof o==`string`&&Qr(o)||d===`failed`,ie=d!=null,ae=(0,Z.useMemo)(()=>{if(typeof a==`string`)return a;try{return JSON.stringify(a,null,2)}catch(e){return it.error(`client/src/components/Chat/Messages/Content/ToolCall.tsx - Failed to stringify args`,e),``}},[a]),V=(0,Z.useMemo)(()=>(ae?.length??0)>0||(o?.length??0)>0,[ae,o]),H=(0,Z.useMemo)(()=>M?.hostname??``,[M]),oe=Oe(ie?1:e),se=en({runStepStatus:d,displayProgress:oe,reportedProgress:e,isSubmitting:n,hasError:re}),ce=!!c&&se===`running`;(0,Z.useEffect)(()=>{if(!ce)return;let e=B();if(e==null){x(`bound`);return}let t=!0;return x(`pending`),e.then(()=>{t&&x(`bound`)},e=>{it.error(`Failed to bind OAuth CSRF cookie`,e),t&&x(`failed`)}),()=>{t=!1}},[ce,c,B]);let le=(0,Z.useCallback)(()=>{if(!(!c||b===`pending`)){if(b===`bound`){y(null),ti(c),B()?.catch(e=>{it.error(`Failed to bind OAuth CSRF cookie`,e)});return}y(_(`com_ui_oauth_error_generic`)),x(`pending`),(B()??Promise.resolve()).then(()=>{x(`bound`),y(null)},e=>{it.error(`Failed to bind OAuth CSRF cookie`,e),x(`failed`)})}},[c,b,B,_]),ue=(0,Z.useCallback)(()=>{A(),T||u?.(),E(e=>!e)},[A,u,T]),de=(0,Z.useMemo)(()=>{let e=se===`failed`?Da(o):``;if(e.length>0)return e;if(I&&L)return _(`com_ui_via_server`,{0:L});if(F&&F.length!==X.ENCODED_DOMAIN_LENGTH)return _(`com_ui_via_server`,{0:F})},[se,o,I,L,F,_]),fe=fr(a),pe=fe??R,me=fe??(R?_(`com_assistants_running_var`,{0:R}):_(`com_assistants_running_action`));m==null?p!=null&&(me=_(`com_ui_tool_preparing`,{0:pe})):me=_(`com_ui_tool_calling`,{0:pe});let he=()=>{if(se===`cancelled`)return _(`com_ui_cancelled`);if(se===`failed`){let e=fe??R;return e?_(`com_ui_failed_subject`,{0:e}):_(`com_ui_failed`)}return fe??(I===!0?_(`com_assistants_completed_function`,{0:R}):F!=null&&F&&F.length!==X.ENCODED_DOMAIN_LENGTH?_(`com_assistants_completed_action`,{0:F}):_(`com_assistants_completed_function`,{0:R}))};return!t&&(!P||P.length===0)&&!o?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:se===`running`?m==null?p==null?R?_(`com_assistants_running_var`,{0:R}):_(`com_assistants_running_action`):_(`com_ui_tool_preparing`,{0:R}):_(`com_ui_tool_calling`,{0:R}):he()}),(0,Q.jsx)(`div`,{className:bt,"data-testid":`tool-call`,"data-tool-call-id":r,children:(0,Q.jsx)(De,{phase:se,onClick:ue,inProgressText:me,authText:se===`running`&&H.length>0?_(`com_ui_requires_auth`):void 0,finishedText:he(),subtitle:de,durationMs:f,toolPreparationDurationMs:h,toolExecutionDurationMs:g,phaseStartAt:m??p,icon:(0,Q.jsx)(Ft,{type:ee,iconUrl:te,isAnimating:se===`running`}),hasInput:V,isExpanded:T})}),(0,Q.jsx)(`div`,{style:D,onTransitionEnd:j,"data-tool-call-output-id":r,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:O,children:V&&k&&(0,Q.jsx)(`div`,{className:G(`mb-2 mt-0`,`overflow-hidden rounded-lg border border-border-light bg-surface-secondary`),children:(0,Q.jsx)(qo,{input:ae??``,output:o,attachments:s})})})}),ce&&(0,Q.jsxs)(`div`,{className:`flex w-full flex-col gap-2.5`,children:[(0,Q.jsx)(`div`,{className:`mb-1 mt-2`,children:(0,Q.jsx)(Y,{className:`inline-flex items-center justify-center rounded-xl px-4 py-2 text-sm font-medium`,variant:`default`,rel:`noopener noreferrer`,disabled:b===`pending`,"aria-busy":b===`pending`,onClick:le,children:_(`com_ui_sign_in_to_domain`,{0:H})})}),v&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-text-destructive`,children:v}),(0,Q.jsx)(Ao,{})]}),!l&&s&&s.length>0&&(0,Q.jsx)(Zt,{attachments:s})]})}var ol=3;function sl({sources:e}){let t=Aa(e,ol);return(0,Q.jsx)(`div`,{className:`flex items-center`,"aria-hidden":`true`,children:t.map((e,t)=>(0,Q.jsx)(`div`,{className:G(`relative flex items-center justify-center rounded-full border border-border-medium bg-surface-secondary`,`h-[22px] w-[22px]`,t>0&&`-ml-2.5`),style:{zIndex:ol-t},children:(0,Q.jsx)(tt,{domain:pt(e.link),className:`size-3 rounded-full`})},e.link))})}function cl({initialProgress:e=.1,isSubmitting:t,isLast:n,args:r,output:i,attachments:a,hideAttachments:o=!1,onExpand:s,runStepStatus:c}){let l=K(),u=fr(r),{searchResults:d}
19=zt(),f=typeof i==`string`&&Qr(i)||c===`failed`,p=!f&&typeof i==`string`&&i.toLowerCase().includes(`error processing`),m=c!=null,h=(0,Z.useMemo)(()=>a?.some(e=>e.type===q.web_search&&e[q.web_search])??!1,[a]),g=m||h&&!t?1:e,_=m?c===`cancelled`||p:!t&&g<1||p,v=!m&&t&&n&&g===1,y=m?!_:g===1&&!v&&(!n||!t),b=(0,Z.useMemo)(()=>{if(!a)return`0`;for(let e of a)if(e.type===q.web_search&&e[q.web_search]){let t=e[q.web_search].turn;return typeof t==`number`?String(t):`0`}return`0`},[a]),x=(0,Z.useMemo)(()=>{if(a!=null){let e={};for(let t of a)if(t.type===q.web_search&&t[q.web_search]){let n=t[q.web_search],r=typeof n.turn==`number`?String(n.turn):`0`;e[r]=n}return ka(e)}return d?.[b]?ka({[b]:d[b]}):[]},[d,a,b]),S=(0,Z.useMemo)(()=>{if(a)for(let e of a){let t=e.type===q.web_search?e[q.web_search]?.answerBox:void 0;if(t)return t}},[a]),C=(0,Z.useMemo)(()=>S?.snippet||S?.snippetHighlighted?.join(` `)||void 0,[S]),T=(0,Z.useMemo)(()=>y&&!v?[]:x,[x,y,v]),E=T.length>0,D=(0,Z.useMemo)(()=>{let e=b===`0`?`com_ui_web_searching`:`com_ui_web_searching_again`;return E&&(e=`com_ui_web_search_processing`),v&&(e=`com_ui_web_search_reading`),l(e)},[b,l,E,v]),O=u??D,k=w(Dn.autoExpandTools),A=x.length,[j,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(()=>k&&A>0),{style:F,ref:I}=Et(N),{shouldRenderBody:L,mountBody:R,handleTransitionEnd:z}=Kr(N);(0,Z.useEffect)(()=>{k&&A>0&&P(!0)},[k,A]);let te=()=>{R(),P(e=>{let t=!e;return t&&s?.(),t})};if(f&&c!==`cancelled`)return(0,Q.jsx)(al,{name:q.web_search,args:r??``,output:i,initialProgress:e,isSubmitting:t,isLast:n,runStepStatus:c,attachments:a,hideAttachments:o,onExpand:s});if(_)return null;if(y){let e=A>0,t=u??l(`com_ui_web_searched`),n=Jn(r,`query`),i=!!n||!!S;return(0,Q.jsxs)(`div`,{className:`group/websearch my-1`,children:[(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:t}),(0,Q.jsxs)(`div`,{className:`relative flex h-5 items-center gap-1.5`,children:[(0,Q.jsxs)(Y,{variant:`ghost`,className:G(`tool-status-text group/disclosure h-5 min-w-0 justify-start gap-2 rounded-full p-0 font-normal text-text-secondary hover:bg-transparent`,`transition-none`,!e&&`pointer-events-none disabled:opacity-100`),disabled:!e,onClick:e?te:void 0,"aria-expanded":e?N:void 0,"aria-label":e?`${t} - ${l(A===1?`com_ui_web_search_source`:`com_ui_web_search_sources`,{count:A})}`:t,children:[(0,Q.jsx)(`span`,{className:_t,"aria-hidden":`true`,children:e?(0,Q.jsx)(sl,{sources:x}):(0,Q.jsx)(re,{className:`size-4 shrink-0 text-text-secondary`})}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:t}),e&&(0,Q.jsx)(he,{className:G(Ot({expanded:N}),`size-3.5`),"aria-hidden":`true`})]}),i&&(0,Q.jsxs)(vr,{openDelay:50,open:j,onOpenChange:M,children:[(0,Q.jsx)(cr,{asChild:!0,children:(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:G(`ml-auto size-auto cursor-help rounded-md p-1 text-text-secondary opacity-0`,`group-focus-within/websearch:opacity-100 group-hover/websearch:opacity-100`,`focus-visible:opacity-100`),onFocus:()=>M(!0),onBlur:()=>M(!1),"aria-label":l(`com_ui_web_search_details`),children:(0,Q.jsx)(ee,{className:`size-3.5`,"aria-hidden":`true`})})}),(0,Q.jsx)(jn,{children:(0,Q.jsx)(Mr,{side:`top`,className:`z-[999] w-80`,children:(0,Q.jsxs)(`div`,{className:`max-h-[60vh] space-y-2 overflow-y-auto`,children:[n&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-text-secondary`,children:l(`com_ui_search_query`)}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-sm text-text-primary`,children:n})]}),(0,Q.jsx)(`div`,{className:`text-xs text-text-secondary`,children:l(A===1?`com_ui_web_search_source`:`com_ui_web_search_sources`,{count:A})}),S&&(S.title||C)&&(0,Q.jsxs)(`div`,{className:`border-t border-border-light pt-2`,children:[S.title&&(0,Q.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:S.title}),C&&(0,Q.jsx)(`div`,{className:`mt-1 text-xs leading-relaxed text-text-secondary`,children:C})]})]})})})]})]}),e&&(0,Q.jsx)(`div`,{style:F,onTransitionEnd:z,children:(0,Q.jsx)(`div`,{className:`overflow-hidden`,ref:I,children:L&&(0,Q.jsx)(`div`,{className:G(`mb-2 mt-0`,`mt-1.5 max-h-[280px] overflow-y-auto rounded-lg border border-border-light`),children:x.map((e,t)=>{let n=pt(e.link),r=`snippet`in e?e.snippet:void 0;return(0,Q.jsxs)(`a`,{href:e.link,target:`_blank`,rel:`noopener noreferrer`,className:G(`flex gap-2.5 px-3 py-2 transition-colors hover:bg-surface-hover`,r?`items-start`:`items-center`,t>0&&`border-t border-border-light`),children:[(0,Q.jsx)(tt,{domain:n,className:G(`size-4 shrink-0 rounded-sm`,r&&`mt-0.5`)}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-xs font-medium text-text-primary`,children:e.title||n}),r&&(0,Q.jsx)(`span`,{className:`mt-0.5 line-clamp-2 block text-[11px] leading-relaxed text-text-secondary`,children:r})]}),(0,Q.jsxs)(`span`,{className:`shrink-0 text-right`,children:[(0,Q.jsx)(`span`,{className:`block text-[11px] text-text-secondary`,children:n}),e.date&&(0,Q.jsx)(`span`,{className:`block text-[10px] text-text-secondary`,children:e.date})]})]},e.link)})})})}),!o&&(0,Q.jsx)(Wa,{attachments:a})]})}return(0,Q.jsxs)(`div`,{className:`relative my-1 flex h-5 shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:D}),(0,Q.jsxs)(`span`,{className:_t,"aria-hidden":`true`,children:[E&&(0,Q.jsx)(ji,{sources:T,start:-5}),(0,Q.jsx)(re,{className:`size-4 shrink-0 text-text-secondary`})]}),(0,Q.jsx)(`span`,{className:`tool-status-text shimmer min-w-0 truncate font-medium text-text-secondary`,children:O})]})}var ll=(e,t)=>
19t!==`cancelled`&&(t===`failed`||typeof e==`string`&&Qr(e)),ul=(0,Z.memo)(function({part:e,isSubmitting:t,attachments:n,isLast:r,showCursor:i,isCreatedByUser:a,hideAttachments:o,onToolExpand:s}){let{partIndex:c}=Ee();if(!e)return null;let l=Er(e);if(l)return(0,Q.jsx)(_c,{actionId:l.ask_user_question.actionId,question:l.ask_user_question.question,questions:l.ask_user_question.questions},l.ask_user_question.actionId);if(e.type===W.STEER)return(0,Q.jsx)(je,{steer:e[W.STEER],files:e.files,quotes:e.quotes,steerId:e.steerId,createdAt:e.createdAt,isSubmitting:t});if(e.type===W.ERROR)return(0,Q.jsx)(sc,{text:e[W.ERROR]??(typeof e[W.TEXT]==`string`?e[W.TEXT]:e.text?.value)??``,className:`my-2`});if(e.type===W.AGENT_UPDATE)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Pe,{currentAgentId:e[W.AGENT_UPDATE]?.agentId}),r&&i&&(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{})})]});if(e.type===W.TEXT){let t=typeof e.text==`string`?e.text:e.text?.value;if(typeof t!=`string`||e.tool_call_ids!=null&&!t)return null;if(t.length>0&&/^\s*$/.test(t)){if(r&&i)return(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{})});if(!r)return null}return(0,Q.jsx)(Vi,{children:(0,Q.jsx)(zn,{text:t,isCreatedByUser:a,showCursor:i})})}if(e.type===W.THINK){let t=typeof e.think==`string`?e.think:e.think?.value;return typeof t==`string`?t.trim()===``&&e.reasoning_unavailable===!0?(0,Q.jsx)(Kt,{label:e.reasoning_label}):(0,Q.jsx)($t,{partKeyIndex:Ln(e,c??0),reasoning:t,isLast:r??!1,reasoningLabel:e.reasoning_label}):null}if(e.type===W.SUMMARY)return(0,Q.jsx)(Vt,{content:e.content,model:e.model,provider:e.provider,tokenCount:e.tokenCount,initiatedBy:e.initiatedBy,summarizing:e.summarizing,failed:e.failed});if(e.type===W.ACTIVITY_LABEL){let t=bn(Zn(e));if(!t)return null;let n=e.status===`failed`||e.status===`partial`;return(0,Q.jsx)(`div`,{className:`my-1 break-words pl-1 text-sm italic ${n?`text-text-warning`:`text-text-secondary`}`,children:t})}if(e.type===W.TOOL_CALL){let c=e[W.TOOL_CALL];if(!c)return null;if(`args`in c&&(!c.type||c.type===Ir.TOOL_CALL)){let e=`id`in c&&typeof c.id==`string`?c.id:void 0,a=(()=>{if(ra(c.name,c.args))return(0,Q.jsx)(Kn,{args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,backgrounded:c.backgrounded,backgroundCancelled:c.backgroundTask?.cancelled===!0,attachments:n,commandField:`code`,hideAttachments:o,onExpand:s,toolCallId:e});if(c.name===q.execute_code||c.name===X.PROGRAMMATIC_TOOL_CALLING||c.name===X.BASH_PROGRAMMATIC_TOOL_CALLING)return(0,Q.jsx)(Ve,{attachments:n,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,backgrounded:c.backgrounded,backgroundCancelled:c.backgroundTask?.cancelled===!0,output:c.output??``,initialProgress:c.progress??.1,args:c.args,hideAttachments:o,onExpand:s,toolCallId:e});if(c.name===`image_gen_oai`||c.name===`image_edit_oai`||c.name===`gemini_image_gen`)return ll(c.output,c.runStepStatus)?(0,Q.jsx)(al,{name:c.name,args:c.args??``,output:c.output,initialProgress:c.progress??.1,isSubmitting:t,isLast:r,runStepStatus:c.runStepStatus,attachments:n,hideAttachments:o,onExpand:s}):(0,Q.jsx)(Fn,{initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,toolName:c.name,args:c.args??``,output:c.output??``,attachments:n,hideAttachments:o});if(c.name===`ask_user_question`)return(0,Q.jsx)(Xo,{args:c.args,output:typeof c.output==`string`?c.output:``,toolCallId:c.id,isSubmitting:t,runStepStatus:c.runStepStatus,showCursor:i,failed:`inputValidationError`in c&&c.inputValidationError===!0,onExpand:s});if(c.name===X.CHECK_BACKGROUND_TASK)return(0,Q.jsx)(Jo,{args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,attachments:n,hideAttachments:o,onExpand:s,toolCallId:e});if(c.name===`skill`)return(0,Q.jsx)(Bt,{args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,attachments:n,hideAttachments:o,onExpand:s});if(c.name===X.SUBAGENT){let e=c.subagent_content;return(0,Q.jsx)(cn,{toolCallId:c.id??``,args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,attachments:n,persistedContent:e,subagentIdentity:c.subagentIdentity,hideAttachments:o})}return c.name===`set_memory`||c.name===`delete_memory`?(0,Q.jsx)($r,{toolName:c.name,args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,attachments:n,hideAttachments:o,onExpand:s}):c.name===`read_file`?(0,Q.jsx)(Wr,{args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,attachments:n,hideAttachments:o,onExpand:s}):c.name===`create_file`||c.name===`edit_file`?(0,Q.jsx)(vn,{toolName:c.name,args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,attachments:n,hideAttachments:o,onExpand:s}):c.name===q.bash_tool?(0,Q.jsx)(Kn,{args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,backgrounded:c.backgrounded,backgroundCancelled:c.backgroundTask?.cancelled===!0,attachments:n,hideAttachments:o,onExpand:s,toolCallId:e}):c.name===q.web_search?(0,Q.jsx)(cl,{args:c.args,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,attachments:n,hideAttachments:o,isLast:r,onExpand:s}):c.name===`file_search`||c.name===`retrieval`?(0,Q.jsx)(Dc,{initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,args:c.args,output:c.output??void 0,attachments:n,onExpand:s}):c.name?.startsWith(X.LC_TRANSFER_TO_)?(0,Q.jsx)(rl,{args:c.args??``,name:c.name||``}):(0,Q.jsx)(al,{args:c.args??``,name:c.name||``,toolCallId:e,output:c.output??``,initialProgress:c.progress??.1,isSubmitting:t,attachments:n,auth:c.auth,isLast:r,hideAttachments:o,onExpand:s,runStepStatus:c.backgroundTask?.cancelled===!0?`cancelled`:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,toolPreparationStartedAt:c.toolPreparationStartedAt,toolDispatchedAt:c.toolDispatchedAt,toolPreparationDurationMs:c.toolPreparationDurationMs,toolExecutionDurationMs:c.toolExecutionDurationMs})})();return c.approval!=null&&(c.output?.length??0)===0?(0,Q.jsxs)(Q.Fragment,{children:[a,(0,Q.jsx)(Yc,{approval:c.approval,toolCallId:c.id??``,args:c.args})]}):a}
19if(c.type===Ir.CODE_INTERPRETER){let e=c[Ir.CODE_INTERPRETER];return(0,Q.jsx)(il,{initialProgress:c.progress??.1,code:e.input,outputs:e.outputs??[],onExpand:s})}if(c.type===Ir.RETRIEVAL||c.type===Ir.FILE_SEARCH)return(0,Q.jsx)(Dc,{initialProgress:c.progress??.1,isSubmitting:t,runStepStatus:c.runStepStatus,runStepDurationMs:c.runStepDurationMs,output:c.output,attachments:n,onExpand:s});if(c.type===Ir.FUNCTION&&Ir.FUNCTION in c&&ei.has(c.function.name))return ll(c.function.output,c.runStepStatus)?(0,Q.jsx)(al,{name:c.function.name,args:c.function.arguments,output:c.function.output,initialProgress:c.progress??.1,isSubmitting:t,isLast:r,runStepStatus:c.runStepStatus,attachments:n,hideAttachments:o,onExpand:s}):(0,Q.jsx)(Fn,{initialProgress:c.progress??.1,args:c.function.arguments,isSubmitting:t,runStepStatus:c.runStepStatus,toolName:c.function.name,output:c.function.output??``});if(c.type===Ir.FUNCTION&&Ir.FUNCTION in c)return ct(c)?t&&i?(0,Q.jsx)(Vi,{children:(0,Q.jsx)(zn,{text:``,isCreatedByUser:a,showCursor:i})}):null:(0,Q.jsx)(al,{initialProgress:c.progress??.1,isSubmitting:t,args:c.function.arguments,name:c.function.name,output:c.function.output,isLast:r,hideAttachments:o,onExpand:s})}else if(e.type===W.IMAGE_FILE){let t=e[W.IMAGE_FILE],n=t.file_id?qn(t.file_id):void 0;return(0,Q.jsx)(nn,{imagePath:n??t.filepath,altText:t.filename??`Uploaded Image`,alignRight:a,width:t.width,height:t.height})}return null});ul.displayName=`Part`;var dl=e=>e==null||e.type!==W.TEXT?!1:(typeof e.text==`string`?e.text:e.text?.value??``).length===0,fl=e=>e?.[W.TOOL_CALL]?.id??``,pl=e=>e?.agentId??e?.[W.TOOL_CALL]?.agentId,ml=e=>e?.[W.TOOL_CALL]?.stepId,hl=e=>{for(let{part:t,idx:n}of e)if(fl(t)||t?.type===W.TOOL_CALL)return n;return e[0]?.idx??-1},gl=(e,t)=>{if(ml(e)!=null)return;let n=fl(e),r=t.get(n);
19if(n===``||r==null)return;let i=pl(e),a=new Set;for(let e of r)(i==null||e.agentId==null||e.agentId===i)&&a.add(e.stepId);return a.size===0?void 0:a},_l=(e,t)=>{let n=e[0];if(!n)return`empty`;let r;for(let{part:t,idx:n}of e){let e=fl(t);if(e){let n=pl(t);return n==null?`tool:${e}`:`tool:${e}:${n}`}r===void 0&&t?.type===W.TOOL_CALL&&(r=Ln(t,n))}return`fallback:${t}:${r??Ln(n.part,n.idx)}`},vl=(0,Z.memo)(function({part:e,idx:t,isLastPart:n,messageId:r,conversationId:i,nextType:a,isSubmitting:o,isLatestMessage:s,isCreatedByUser:c,isLast:l,partAttachments:u,hideAttachments:d,onToolExpand:f}){let p=(0,Z.useMemo)(()=>({messageId:r,isExpanded:!0,conversationId:i,partIndex:t,nextType:a,isSubmitting:o,isLatestMessage:s}),[r,i,t,a,o,s]),m=n&&l,h=e.type===W.TOOL_CALL?JSON.stringify([pl(e)??``,fl(e),Ln(e,t)]):void 0;return(0,Q.jsx)(ar.Provider,{value:p,children:(0,Q.jsx)(Tr.Provider,{value:h,children:(0,Q.jsx)(ul,{part:e,attachments:u,isSubmitting:o,isCreatedByUser:c,isLast:m,showCursor:m,hideAttachments:d,onToolExpand:f},`part-${r}-${Ln(e,t)}`)})})}),yl=(0,Z.memo)(function e({edit:t,isLast:n,content:r,manualSkills:i,messageId:a,enterEdit:o,siblingIdx:s,attachments:c,isSubmitting:l,setSiblingIdx:d,searchResults:f,authorHeader:p,conversationId:m,isCreatedByUser:h,showThinking:g,isLatestMessage:_,createdAt:v,foldLiveActivity:y=!0,nestedActivityPhase:b=!1,withinActivityPhase:x=!1,parentPhaseOwnsFailurePill:S=!1,cursorOwnedElsewhere:C=!1,hideAttachments:w=!1,workspaceAttachmentsPartitioned:T=!1,contentIndexOffset:E=0,contentIndices:D,laneGroups:O,resumeAuthors:k,toolGroupExpansionState:A,toolGroupOccurrenceByIndex:j,toolCallStepOwnersById:M}){let{inlineAttachments:N,workspaceChanges:P}=(0,Z.useMemo)(()=>T?{inlineAttachments:c??[],workspaceChanges:[]}:yi(c),[c,T]),F=(0,Z.useMemo)(()=>Cr(N),[N]),I=(0,Z.useMemo)(()=>{if(M!=null)return M;let e=new Map;for(let t of r??[]){if(t==null)continue;let n=fl(t),r=ml(t);
19if(n===``||r==null)continue;let i=e.get(n)??[];i.push({stepId:r,agentId:pl(t)}),e.set(n,i)}return e},[M,r]),L=(0,Z.useCallback)(e=>lt(F[fl(e)],pl(e),ml(e),gl(e,I)),[F,I]),ee=u(),R=(0,Z.useContext)(Xe),z=_?l:!1,te=(0,Z.useRef)(new Map),ne=A??te.current,B=(0,Z.useRef)({messageId:a,scope:0}),re=(0,Z.useRef)(new Map),ie=(0,Z.useRef)(0);if(B.current.messageId!==a){z||(B.current.scope+=1,ne.clear()),ie.current+=1;for(let e of re.current.keys())(e.startsWith(`start:`)||e.startsWith(`key:fallback:`))&&re.current.delete(e);B.current.messageId=a}let ae=B.current.scope,V=(0,Z.useMemo)(()=>D==null?void 0:new Map(D.map((e,t)=>[e,t])),[D]),H=(0,Z.useCallback)(e=>D?.[e]??e+E,[E,D]),oe=(0,Z.useMemo)(()=>O??br(r),[O,r]),se=y&&n&&z,ce=(0,Z.useMemo)(()=>b?void 0:kr(r,oe,se),[b,r,oe,se]),le=(0,Z.useCallback)(e=>{let t=[],n=new Map;for(let r of e)if(r!=null)for(let e of L(r)??[]){let r=rr(e);if(r==null){t.push(e);continue}let i=n.get(r);if(i!=null){t[i]=e;continue}n.set(r,t.length),t.push(e)}return t.length>0?t:void 0},[L]),ue=(0,Z.useMemo)(()=>{let e=new Set,t=new Map,n=new Map;for(let r of ce??[]){if(r.type!==`phase`||r.synthesized===!0)continue;let i=bn(r.labelPart),a=(t.get(i)??0)+1;e.add(Ln(r.labelPart,r.labelIndex)),t.set(i,a),n.set(Ln(r.labelPart,r.labelIndex),a)}return{indices:e,labels:t,ordinals:n}},[ce]),de=(0,Z.useRef)(null),fe=de.current?.messageId===a?de.current:null,pe=(0,Z.useMemo)(()=>{if(fe==null)return!1;for(let e of fe.indices)if(!ue.indices.has(e))return!0;return!1},[fe,ue]);(0,Z.useEffect)(()=>{de.current={messageId:a,indices:ue.indices,labels:ue.labels}},[a,ue]);let me=(0,Z.useCallback)((e,t)=>{if(!t.userOverride){ne.delete(e);return}ne.set(e,t)},[ne]),he=(0,Z.useMemo)(()=>!h&&i!=null?i:[],[h,i]),ge=he.length>0,_e=(0,Z.useMemo)(()=>(r??[]).some(e=>e!=null&&!dl(e)),[r]),ve=()=>he.map(e=>(0,Q.jsx)(Ki,{skillName:e,loaded:_e},`pending-skill-${e}`)),ye=(0,Z.useCallback)((e,t,i)=>{let o=V?.get(t)??t-E;return(0,Q.jsx)(vl,{idx:t,part:e,isLast:n,messageId:a,isLastPart:i,conversationId:m,isLatestMessage:_,isCreatedByUser:h,nextType:r?.[o+1]?.type,isSubmitting:z,partAttachments:L(e),hideAttachments:w},`provider-${a}-${Ln(e,t)}`)},[L,r,E,V,m,z,w,h,n,_,a]),be=(0,Z.useCallback)((e,t,i,o)=>{let s=V?.get(t)??t-E;return(0,Q.jsx)(vl,{idx:t,part:e,isLast:n,messageId:a,isLastPart:i,conversationId:m,isLatestMessage:_,isCreatedByUser:h,nextType:r?.[s+1]?.type,isSubmitting:z,partAttachments:L(e),hideAttachments:!0,onToolExpand:o},`provider-${a}-${Ln(e,t)}`)},[L,r,E,V,m,z,h,n,_,a]),{sequentialParts:xe,detectedResumeAuthors:Se}=(0,Z.useMemo)(()=>{let e=[],t=new Map;if(!r)return{sequentialParts:e,detectedResumeAuthors:t};let n,i;return r.forEach((r,a)=>{if(!r)return;let o=H(a);n===W.STEER&&r.type!==W.STEER&&t.set(o,i),r.type===W.AGENT_UPDATE&&(i=r[W.AGENT_UPDATE]?.agentId||void 0),n=r.type,e.push({part:r,idx:o})}),{sequentialParts:e,detectedResumeAuthors:t}},[H,r]),Ce=k??Se,we=(0,Z.useMemo)(()=>{if(j!=null)return j;let e=new Map,t=new Map;for(let n of Fr(xe)){if(n.type===`single`)continue;let r=_l(n.parts,ae),i=(t.get(r)??0)+1;t.set(r,i),e.set(hl(n.parts),i)}return e},[j,xe,ae]),Te=(0,Z.useCallback)(e=>Fr(e).map(e=>{if(e.type===`single`)return e;let t=_l(e.parts,ae),n=we.get(hl(e.parts))??1,r=n===1?t:`${t}:occurrence:${n}`,i=new Set;for(let{part:t}of e.parts)for(let e of L(t)??[])i.add(e);let a=w?void 0:Array.from(i);return{...e,groupId:r,groupAttachments:a,sourceAttachments:Array.from(i)}}),[L,ae,w,we]),Ee=(0,Z.useMemo)(()=>ce==null?Te(xe):[],[ce,Te,xe]),De=(0,Z.useCallback)((e,t=e)=>{if(p==null||!Ce.has(e))return null;let n=Ce.get(e);return n==null?(0,Q.jsx)(Z.Fragment,{children:p},`author-${a}-${t}`):(0,Q.jsx)(Pe,{currentAgentId:n},`author-${a}-${t}`)},[p,Ce,a]);if(!r&&!ge&&P.length===0)return null;if(t===!0&&o&&d)return(0,Q.jsx)(Eo,{children:(0,Q.jsxs)(Jr.Provider,{value:{searchResults:f},children:[(0,Q.jsx)(wi,{attachments:c}),(0,Q.jsx)(uo,{content:r??[],contentIndexOffset:E,messageId:a,isSubmitting:l,enterEdit:o,siblingIdx:s??null,setSiblingIdx:d,renderReadOnlyPart:(e,t,n)=>ye(e,t,n)}),(0,Q.jsx)(xi,{attachments:P})]})});let Oe=r??[],ke=Oe.length===1&&dl(Oe[0]),Ae=(Oe.length===0||ke)&&z&&!C,je=sr(Oe),Ne=je<0?-1:H(je),Fe=(e,t)=>e.flatMap(e=>{let r=e.type===`single`?e.part:e.parts[0],i=r?.idx??-1,a=[],o=De(i,r?Ln(r.part,r.idx):i);if(o!=null&&a.push(o),e.type===`single`){let{part:n,idx:r}=e.part;return a.push(ye(n,r,r===t)),a}let{groupId:s}=e;return a.push((0,Q.jsx)(jo,{parts:e.parts,isSubmitting:z,isLast:n&&(e.parts.some(e=>e.idx===t)||e.labelPart?.idx===t),renderPart:be,lastContentIdx:t,groupAttachments:e.groupAttachments,sourceAttachments:e.sourceAttachments,initialExpansionState:ne.get(s),showThinking:g,onExpansionChange:e=>me(s,e),labelPart:e.labelPart,withinActivityPhase:x,parentPhaseOwnsFailurePill:S},`tool-group-${s}`)),a}),Ie=Nn(r,oe),Le;if(ce!=null){let t=e=>{for(let t=0;t<e.content.length;t++){let n=e.content[t];if(n!=null)return Ln(n,H(e.contentIndices[t]))}return H(e.startIndex)},r=e=>{for(let t=0;t<e.content.length;t+=1){let n=e.content[t],r=n==null?``:fl(n);if(r)return`${r}:${Ln(n,H(e.contentIndices[t]))}`}let n=e.hasContent?t(e):Ln(e.labelPart,e.labelIndex);return`fallback:${ie.current}:${n}`},i=e=>{let t=r(e),n=H(e.contentIndices[0]??e.startIndex),i=re.current,a=i.get(`key:${t}`)??i.get(`start:${n}`)??t;return i.set(`key:${t}`,a),i.set(`start:${n}`,a),a},o=n&&z&&ce.some(e=>e.type===`phase`?e.synthesized===!0?e.contentIndices.map(H).includes(Ne):H(e.labelIndex)===Ne:!1),s=(t,r,i,s,c=!1,u=!1,d=!1,y=!1)=>(0,Q.jsx)(e,{content:t,messageId:a,createdAt:v,authorHeader:p,conversationId:m,attachments:N,searchResults:f,isCreatedByUser:h,isLast:!u&&n&&i.includes(Ne),isSubmitting:l,isLatestMessage:_,nestedActivityPhase:!0,showThinking:g,withinActivityPhase:c,parentPhaseOwnsFailurePill:y,cursorOwnedElsewhere:o,hideAttachments:d,workspaceAttachmentsPartitioned:!0,contentIndexOffset:r,contentIndices:i,laneGroups:oe,resumeAuthors:Ce,toolGroupExpansionState:ne,toolGroupOccurrenceByIndex:we,toolCallStepOwnersById:I},s);Le=ce.flatMap(e=>{if(e.type!==`phase`){if(Ie)return s(e.content,H(e.startIndex),e.contentIndices.map(H),`phase-adjacent-${t(e)}`);let n=[];return e.content.forEach((t,r)=>{t!=null&&n.push({part:t,idx:H(e.contentIndices[r])})}),Fe(Te(n),Ne)}let r=e.synthesized===!0,a=e.live===!0,o=Ln(e.labelPart,e.labelIndex),c=i(e),l=bn(e.labelPart),u=e.contentIndices.map(H),d=r&&n&&z&&u.includes(Ne),f=e.content.some(e=>
19e!=null&&mr(e)),p=le(e.content),m=a&&g&&e.content.some(e=>e?.type===W.THINK),h=a?m||e.content.some(va):f;return r&&h?s(e.content,H(e.startIndex),u,`phase-awaiting-${c}`):(0,Q.jsx)(no,{labelPart:e.labelPart,hasContent:e.hasContent,attachments:p,hasPendingApproval:f,onExpansionChange:a&&R!=null&&!e.content.some(e=>e?.type===W.TOOL_CALL)?t=>{e.content.forEach((e,n)=>{if(e?.type!==W.THINK)return;let r=Ln(e,u[n]);ee.set(ot(R,r),t)})}:void 0,liveParts:a?e.content:void 0,spanParts:e.hasContent?e.content:void 0,animateEntrance:!r&&fe!=null&&!fe.indices.has(o)&&(!pe||(ue.ordinals.get(o)??1)>(fe.labels.get(l)??0)),showCursor:r?d&&!a:n&&z&&H(e.labelIndex)===Ne,children:s(e.content,H(e.startIndex),u,`phase-content-${c}`,!a,d,!0,!0)},`activity-phase-${c}`)})}if(Ie&&Le==null){let e=(0,Q.jsxs)(Q.Fragment,{children:[ve(),(0,Q.jsx)(Gi,{content:r,messageId:a,createdAt:v,conversationId:m,attachments:c,searchResults:f,isSubmitting:z,renderPart:ye,renderResumeAttribution:De,showDecorations:!b,contentIndexOffset:E,contentIndices:D,laneGroups:oe}),!b&&(0,Q.jsx)(xi,{attachments:P})]});return b?e:(0,Q.jsx)(Eo,{children:e})}let Re=(0,Q.jsxs)(Jr.Provider,{value:{searchResults:f},children:[!b&&(0,Q.jsx)(wi,{attachments:c}),Le!=null&&Ie&&(0,Q.jsx)(Ii,{messageId:a,conversationId:m||void 0}),!b&&ve(),Ae&&(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{underHeaderIcon:!b&&!ge&&!Ci(c)})}),!Ae&&(Le??Fe(Ee,Ne)),!b&&(0,Q.jsx)(xi,{attachments:P})]});return b?Re:(0,Q.jsx)(Eo,{children:Re})}),bl=(0,Z.memo)(function(e){let{attachments:t,messageId:n,conversationId:r,isSubmitting:i,isLatestMessage:a}=e,o=(0,Z.useMemo)(()=>({messageId:n,conversationId:r,isExpanded:!1,isSubmitting:a===!0&&i,isLatestMessage:a}),[n,r,i,a]),s=(0,Z.useRef)(null),c=s.current,l=c?.messageId.endsWith(`_`)===!0&&!n.endsWith(`_`)&&e.isLatestMessage===!0;c==null||c.conversationId!==r||c.messageId!==n&&!l?s.current={messageId:n,conversationId:r,disclosures:new Map}:c.messageId=n;let u=s.current.disclosures,d=(0,Z.useRef)(null);d.current?.messageId!==n&&(d.current={messageId:n,disclosures:new Map});let f=d.current.disclosures,p=(0,Z.useMemo)(()=>Ce(t),[t]),m=(0,Z.useMemo)(()=>({attachmentsByName:p}),[p]);return(0,Q.jsx)(ar.Provider,{value:o,children:(0,Q.jsx)(lr.Provider,{value:m,children:(0,Q.jsx)(Xe.Provider,{value:f,children:(0,Q.jsx)(dt.Provider,{value:u,children:(0,Q.jsx)(yl,{...e})})})})})}),xl=(0,Z.forwardRef)(({scrollHandler:e,maximizeChatSpace:t,overlayHeight:n=0,interactive:r=!1},i)=>{let a=K();return(0,Q.jsx)(`div`,{ref:i,className:`scrollbar-gutter-spacer pointer-events-none absolute inset-x-0 z-10`,style:{bottom:`calc(1.25rem + ${n}px)`},children:(0,Q.jsx)(`div`,{className:G(`mx-auto flex justify-end sm:px-2`,t?`max-w-full`:`md:max-w-3xl xl:max-w-4xl`),children:(0,Q.jsx)(Y,{type:`button`,variant:`outline`,size:`icon-theme`,shape:`round`,onClick:e,disabled:!r,"aria-label":a(`com_ui_scroll_to_bottom`),className:G(`me-2 bg-surface-chat/90 text-text-primary active:scale-[0.96] motion-reduce:active:scale-100`,`disabled:opacity-100`,r?`pointer-events-auto`:`pointer-events-none`),children:(0,Q.jsx)(he,{className:`size-4`,"aria-hidden":`true`})})})})});xl.displayName=`ScrollToBottom`;var Sl=120,Cl={steer:`com_ui_subagent_control_steer`,queue:`com_ui_subagent_control_queue`,interrupt:`com_ui_subagent_control_interrupt`,cancel:`com_ui_subagent_control_cancel`,cancel_message:`com_ui_subagent_control_cancel_message`},wl={submitted:`com_ui_subagent_control_status_submitted`,accepted:`com_ui_subagent_control_status_accepted`,applied:`com_ui_subagent_control_status_applied`,rejected:`com_ui_subagent_control_status_rejected`,failed:`com_ui_subagent_control_status_failed`},Tl={control_not_found:`com_ui_subagent_control_reason_control_not_found`,invalid_command:`com_ui_subagent_control_reason_invalid_command`,owner_unavailable:`com_ui_subagent_control_reason_owner_unavailable`,task_inaccessible:`com_ui_subagent_control_reason_task_inaccessible`,task_cancelled:`com_ui_subagent_control_reason_task_cancelled`,task_completed:`com_ui_subagent_control_reason_task_completed`,task_failed:`com_ui_subagent_control_reason_task_failed`,task_not_running:`com_ui_subagent_control_reason_task_not_running`,withdrawn:`com_ui_subagent_control_reason_withdrawn`};
19function El({controls:e,onCancelControl:t}){let n=K();if(e.length===0)return null;let r=e.map((e,t)=>({control:e,index:t})).sort((e,t)=>e.control.createdAt.localeCompare(t.control.createdAt)||e.index-t.index).map(({control:e})=>e);return(0,Q.jsx)(`section`,{"aria-label":n(`com_ui_subagent_control_history`),className:`mb-3 space-y-2`,children:r.map(e=>{let r=e.status===`submitted`||e.status===`accepted`,i=s;return r&&(i=D),e.status===`applied`&&(i=B),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-border-light bg-surface-secondary px-3 py-2 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(i,{size:14,"aria-hidden":!0,className:`shrink-0 text-text-secondary`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 font-medium`,children:n(Cl[e.action])}),(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-text-secondary`,"aria-live":`polite`,children:n(wl[e.status])}),e.status===`accepted`&&e.controlId!=null&&t!=null&&(0,Q.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 shrink-0 px-2 text-xs`,onClick:()=>t(e.controlId),children:n(`com_ui_subagent_control_withdraw`)})]}),e.message!=null&&e.message!==``&&(0,Q.jsxs)(`div`,{className:`mt-1 break-words text-text-secondary`,children:[e.message,e.messageTruncated===!0&&(0,Q.jsx)(`span`,{className:`ml-1 text-xs italic`,children:n(`com_ui_subagent_control_message_truncated`)})]}),e.reason!=null&&(0,Q.jsx)(`div`,{className:`mt-1 text-xs text-status-error`,children:n(Tl[e.reason]??`com_ui_subagent_control_reason_invalid_command`)})]},e.invocationId)})})}function Dl({children:e,padded:t=!0,headerInset:n=!1}){let r=(0,Z.useRef)(null),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(!1),{showScrollButton:u,maximizeChatSpace:d}=Nt();(0,Z.useEffect)(()=>{let e=r.current,t=i.current;if(e==null||t==null||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{o&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[o]);let f=(0,Z.useCallback)(e=>{let t=e.currentTarget;s(t.scrollHeight-t.scrollTop-t.clientHeight<=Sl)},[]),p=(0,Z.useCallback)(()=>{r.current?.scrollTo({top:r.current.scrollHeight,behavior:`smooth`}),s(!0)},[]);return(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsx)(`div`,{ref:r,onScroll:f,className:G(`min-h-0 flex-1 overflow-y-auto`,t&&`px-4 py-4`),"data-subagent-activity-scroll-surface":!0,children:(0,Q.jsx)(`div`,{ref:i,className:G(n&&`pt-[52px]`),children:e})}),(0,Q.jsx)(ai,{in:!o&&u,timeout:{enter:300,exit:180},classNames:`scroll-animation`,unmountOnExit:!0,appear:!0,nodeRef:a,onEntered:()=>l(!0),onExit:()=>l(!1),children:(0,Q.jsx)(xl,{ref:a,scrollHandler:p,maximizeChatSpace:d,interactive:c})})]})}var Ol=e=>e.type===`writing`?{type:W.TEXT,text:e.text,...e.phase==null?{}:{phase:e.phase}}:e.type===`reasoning`?e.text==null||e.text===``?{type:W.THINK,think:``,reasoning_unavailable:!0,...e.label==null?{}:{reasoning_label:e.label}}:{type:W.THINK,think:e.text,...e.label==null?{}:{reasoning_label:e.label}}:e.type===`activity_label`?{type:W.ACTIVITY_LABEL,[W.ACTIVITY_LABEL]:e.label,...e.labelType==null?{}:{activity_label_type:e.labelType},...e.toolCallIds==null?{}:{tool_call_ids:e.toolCallIds},...e.activityStartIndex==null?{}:{activity_start_index:e.activityStartIndex},...e.activityEndIndex==null?{}:{activity_end_index:e.activityEndIndex},...e.activityCount==null?{}:{activity_count:e.activityCount},...e.agentIds==null?{}:{agent_ids:e.agentIds},...e.status==null?{}:{status:e.status},...e.pending==null?{}:{pending:e.pending}}:{type:W.TOOL_CALL,[W.TOOL_CALL]:{id:e.toolCallId,name:e.name,args:e.input??``,output:e.output??``,progress:e.status===`running`?.1:1,...e.status===`running`?{}:{runStepStatus:e.status},...e.toolPreparationStartedAt==null?{}:{toolPreparationStartedAt:e.toolPreparationStartedAt},...e.toolDispatchedAt==null?{}:{toolDispatchedAt:e.toolDispatchedAt},...e.toolPreparationDurationMs==null?{}:{toolPreparationDurationMs:e.toolPreparationDurationMs},...e.toolExecutionDurationMs==null?{}:{toolExecutionDurationMs:e.toolExecutionDurationMs},...e.inputValidationError===!0?{inputValidationError:!0}:{},...e.approval==null?{}:{approval:e.approval}}};function kl({prompt:e}){let t=K(),[n,r]=(0,Z.useState)(!1),i=(0,Z.useId)(),a=(0,Z.useId)(),o=t(n?`com_ui_collapse`:`com_ui_expand`);return(0,Q.jsxs)(`section`,{"aria-labelledby":i,className:`mb-3 shrink-0 overflow-hidden rounded-lg border border-border-light bg-surface-secondary text-text-primary`,children:[(0,Q.jsxs)(`div`,{className:`flex min-h-[2.75rem] items-center justify-between gap-3 border-b border-border-light px-3 py-2`,children:[(0,Q.jsx)(`h3`,{id:i,className:`text-sm font-medium text-text-primary`,children:t(`com_ui_prompt`)}),(0,Q.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:()=>r(e=>!e),"aria-controls":a,"aria-expanded":n,"aria-label":o,title:o,className:`h-8 gap-1.5 rounded-md px-2 text-xs font-medium text-text-secondary transition hover:bg-surface-tertiary hover:text-text-primary focus:outline-none focus:ring-2 focus:ring-text-primary`,children:[n?(0,Q.jsx)(oe,{size:14,"aria-hidden":!0}):(0,Q.jsx)(ce,{size:14,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:o})]})]}),(0,Q.jsxs)(`div`,{id:a,className:G(`relative min-w-0 px-4 py-3`,n?`overflow-visible`:`max-h-32 overflow-hidden`),children:[(0,Q.jsx)(`div`,{className:`markdown prose prose-sm message-content light dark:prose-invert w-full max-w-none break-words text-text-primary`,children:(0,Q.jsx)(Rr,{content:e,codeExecution:!1})}),!n&&(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-0 h-12 bg-gradient-to-t from-surface-secondary to-transparent`,"aria-hidden":!0})]})]})}function Al({activity:e,activityId:t,state:n=`ready`,showPrompt:r=!0,conversationId:i=null,underHeaderIcon:a=!1,onCancelC
19ontrol:o}){let s=K(),c=de(xe),l=vi(e.status),u=(0,Z.useMemo)(()=>e.items.map(Ol),[e.items]),d;return d=n===`loading`?(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{underHeaderIcon:a})}):n===`error`?(0,Q.jsx)(`div`,{className:`rounded-lg border border-status-error-border bg-status-error-subtle p-3 text-sm text-status-error`,children:s(`com_ui_subagent_thread_load_error`)}):e.items.length===0?l?(0,Q.jsx)(Vi,{children:(0,Q.jsx)(Me,{underHeaderIcon:a})}):null:(0,Q.jsx)(bl,{content:u,messageId:t??`subagent-activity-panel`,conversationId:i,isCreatedByUser:!1,isLast:!0,isSubmitting:l,showThinking:c,isLatestMessage:l,foldLiveActivity:!1}),(0,Q.jsxs)(`div`,{className:`flex max-w-full flex-col gap-0`,children:[r&&e.prompt!=null&&(0,Q.jsx)(kl,{prompt:e.prompt}),(0,Q.jsx)(El,{controls:e.controls??[],onCancelControl:o}),e.controlsTruncated===!0&&(0,Q.jsx)(`div`,{className:`mb-3 text-xs italic text-text-secondary`,children:s(`com_ui_subagent_control_history_truncated`)}),d]})}function jl({activity:e}){let t=K(),n=hi(e.status);return(0,Q.jsxs)(`div`,{className:G(`flex items-center gap-1 text-xs text-text-secondary`,e.status===`failed`||e.status===`interrupted`?`text-status-error`:``),"aria-live":`polite`,children:[(0,Q.jsx)(n,{size:13,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:t(gi(e.status))})]})}function Ml({activity:e,activityId:t,state:n=`ready`,embedded:r=!1,showPrompt:i=!0,headerInset:a=!1,onCancelControl:o}){let s=mi(e.status)?(0,Q.jsx)(`div`,{className:`shrink-0 border-b border-border-light px-4 py-2`,children:(0,Q.jsx)(jl,{activity:e})}):null,c=(0,Q.jsx)(Al,{activity:e,activityId:t,state:n,showPrompt:i,onCancelControl:o});return r?(0,Q.jsxs)(`section`,{className:`border-b border-border-light last:border-b-0`,"data-subagent-thread-turn":!0,children:[s,(0,Q.jsx)(`div`,{className:`px-4 py-4`,children:c})]}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[s,(0,Q.jsx)(Dl,{headerInset:a,children:c})]})}function Nl({children:e}){return(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex size-5 shrink-0 items-center justify-center text-text-secondary`,children:e})}function Pl({icon:e,label:t,detail:n,expanded:r,warning:i=!1,live:a=!1}){return(0,Q.jsxs)(Q.Fragment,{children:[e,(0,Q.jsx)(`span`,{className:G(`tool-status-text min-w-0 truncate font-medium`,i&&`text-text-warning`),title:t,role:a?`status`:void 0,children:t}),n!=null&&n!==``&&(0,Q.jsxs)(`span`,{className:`min-w-0 max-w-[50%] truncate text-xs font-normal text-text-secondary`,children:[`· `,n]}),r!=null&&(0,Q.jsx)(he,{className:G(`ml-auto size-4 shrink-0 text-text-secondary transition-transform duration-200 ease-out motion-reduce:transition-none`,r&&`rotate-180`),"aria-hidden":`true`})]})}var Fl=`inline-flex h-auto w-full items-center justify-start gap-2 rounded-none bg-transparent p-0 py-1 text-sm text-text-secondary hover:bg-transparent hover:text-text-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-heavy focus-visible:ring-offset-0`,Il=`transition-[opacity,color,background-color] duration-theme-normal ease-out group-hover:opacity-100 group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100 motion-reduce:transition-none [@media(hover:hover)]:opacity-0`,Ll=`min-h-[31px] text-xs`,Rl=({isActive:e=!1,isLast:t=!1,className:n}={})=>G(`hover-button size-auto rounded-lg p-1.5 text-text-secondary-alt`,`hover:text-text-primary hover:bg-surface-hover`,`group-hover:visible group-focus-visible:visible group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:visible group-[.final-completion]:visible`,!t&&`transition-[opacity,color,background-color] duration-theme-normal ease-out group-hover:opacity-100 group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100 motion-reduce:transition-none [@media(hover:hover)]:opacity-0`,`group-has-[.hover-button-active]:visible group-has-[.hover-button-active]:opacity-100`,`focus-visible:ring-2 focus-visible:ring-text-primary focus-visible:outline-none`,e&&`hover-button-active active text-text-primary bg-surface-hover`,n),zl=[`agent_`,`asst_`];function Bl(...e){return e.find(e=>e!=null&&e!==``&&!zl.some(t=>e.startsWith(t)))}function Vl(e,...t){if(e!==!0)return Bl(...t)}var Hl=`[grid-area:1/1] truncate transition-[opacity,transform,filter] duration-theme-normal ease-out motion-reduce:transition-none motion-reduce:transform-none motion-reduce:blur-none`;function Ul({label:e,hoverLabel:t}){let n=K();return!t||t===e?(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e}):(0,Q.jsxs)(`span`,{className:`group/label inline-grid min-w-0 max-w-full`,children:[(0,Q.jsx)(`span`,{className:G(Hl,`group-hover/label:-translate-y-1 group-hover/label:opacity-0 group-hover/label:blur-[2px]`,`group-focus-visible:-translate-y-1 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:-translate-y-1`,`group-focus-visible:opacity-0 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-0`,`group-focus-visible:blur-[2px] group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:blur-[2px]`),children:e}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:G(Hl,`translate-y-1 opacity-0 blur-[2px]`,`group-hover/label:translate-y-0 group-hover/label:opacity-100 group-hover/label:blur-0`,`group-focus-visible:translate-y-0 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:translate-y-0`,`group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100`,`group-focus-visible:blur-0 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:blur-0`),children:t}),(0,Q.jsx)(`span`,{className:`sr-only`,children:n(`com_ui_message_model`,{0:t})})]})}function Wl({fullWidth:e=!1,hasParallelContent:t=!1}={}){return e?`w-full max-w-full sm:px-2`:t?`w-full sm:px-2 md:max-w-[58rem] xl:max-w-[70rem]`:`w-full sm:px-2 md:max-w-3xl xl:max-w-4xl`}
19function Gl({id:e,icon:t,label:n,hoverLabel:r,footer:i,children:a,timestamp:o,ariaLabel:s,className:c,headerPrefix:l,isCreatedByUser:u,hasParallelContent:d=!1,fullWidth:f=!1,isEditing:p=!1,systemLabel:m}){let h=Wl({fullWidth:f,hasParallelContent:d}),g=m!=null&&m!==``,_=u||g;return(0,Q.jsx)(`div`,{id:e,role:`group`,"aria-label":s,className:G(`message-render group mx-auto flex min-w-0 flex-1 font-theme-ui transition-[max-width] duration-theme-normal motion-reduce:transition-none`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-text-primary`,_?`justify-end`:`items-start`,h,c),children:(0,Q.jsxs)(`div`,{className:G(`relative flex min-w-0 flex-col`,_?`user-turn`:`agent-turn`,(d||p)&&`w-full`,!d&&_&&G(`ml-auto items-end`,!p&&`w-fit max-w-[90%] sm:max-w-[85%]`),!d&&!_&&!p&&`flex-1`),children:[g&&(0,Q.jsxs)(`h2`,{className:`mb-1 flex select-none items-center gap-1.5 pr-1.5 text-xs font-medium uppercase tracking-wide text-text-secondary`,children:[(0,Q.jsx)(ie,{size:12,"aria-hidden":`true`}),m,(0,Q.jsx)(`span`,{className:`sr-only`,children:(0,Q.jsx)(Je,{value:o})})]}),!d&&!g&&(u?(0,Q.jsxs)(`h2`,{className:`sr-only`,children:[l,n,(0,Q.jsx)(Je,{value:o})]}):(0,Q.jsxs)(`h2`,{className:`mb-1 flex min-h-7 w-full select-none items-center gap-2 text-sm font-semibold text-text-primary`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex size-6 flex-shrink-0 items-center justify-center overflow-hidden rounded-full`,children:t}),(0,Q.jsx)(`span`,{className:`sr-only`,children:l}),(0,Q.jsx)(Ul,{label:n,hoverLabel:r}),(0,Q.jsx)(Je,{value:o,className:`ml-auto shrink-0 font-normal`})]})),(0,Q.jsxs)(`div`,{className:G(`flex w-full flex-col gap-1`,_&&`items-end`),children:[(0,Q.jsx)(`div`,{className:G(`flex min-h-[20px] max-w-full flex-grow flex-col gap-0`,_&&!p?G(`w-fit rounded-theme-surface rounded-br-theme-control px-theme-normal`,g?`border border-border-medium py-1.5`:`bg-surface-tertiary py-2.5`):`w-full`),"data-testid":`message-body`,children:a}),(0,Q.jsx)(`div`,{className:G(`w-full`,_&&`flex justify-end`),children:i})]})]})})}function Kl(e,t){let n=[[e.iconData?.endpoint,t.iconData?.endpoint],[e.iconData?.model,t.iconData?.model],[e.iconData?.iconURL,t.iconData?.iconURL],[e.iconData?.modelLabel,t.iconData?.modelLabel],[e.iconData?.isCreatedByUser,t.iconData?.isCreatedByUser],[e.agent?.name,t.agent?.name],[e.agent?.avatar?.filepath,t.agent?.avatar?.filepath],[e.assistant?.name,t.assistant?.name],[e.assistant?.metadata?.avatar,t.assistant?.metadata?.avatar]];for(let[e,t]of n)if(e!==t)return!1;return!0}var ql=(0,Z.memo)(({iconData:e,assistant:t,agent:n})=>{let{data:r}=ri(),i=n?.name??``,a=n?.avatar?.filepath??``,o=t?.name??``,s=t?.metadata?.avatar??``,c=``;t?c=s:n&&(c=a);let l=e?.iconURL,u=(0,Z.useMemo)(()=>nr({endpointsConfig:r,iconURL:l,endpoint:e?.endpoint}),[r,l,e?.endpoint]),d=(0,Z.useMemo)(()=>yt(r,u,`iconURL`),[r,u]);return e?.isCreatedByUser!==!0&&Ke(l)?(0,Q.jsx)(Pr,{iconURL:l,modelLabel:e?.modelLabel,context:`message`,assistantAvatar:s,agentAvatar:a,assistantName:o,agentName:i}):(0,Q.jsx)(Xn,{isCreatedByUser:e?.isCreatedByUser??!1,endpoint:u,iconURL:c||d,endpointsConfig:r,model:e?.model,assistantName:o,agentName:i,size:28.8})},Kl);ql.displayName=`MessageIcon`;var Jl={parent_dispatch:`com_ui_subagent_trigger_parent_dispatch`,parent_continuation:`com_ui_subagent_trigger_parent_continuation`,external_event:`com_ui_subagent_trigger_external_event`};function Yl({kind:e}){return(0,Q.jsx)(Nl,{children:(0,Q.jsx)(e===`external_event`?l:I,{size:14})})}function Xl({turn:e,fullWidth:t}){let n=K(),[r,i]=(0,Z.useState)(!1),a=e.trigger.externalEvent,o=n(`com_ui_subagent_trigger_external_event`),s;return s=a==null?(0,Q.jsx)(`div`,{className:`flex items-center gap-2 py-1 text-sm text-text-secondary`,children:(0,Q.jsx)(Pl,{icon:(0,Q.jsx)(Yl,{kind:`external_event`}),label:o})}):(0,Q.jsxs)(Be,{open:r,onOpenChange:i,children:[(0,Q.jsx)(Tt,{asChild:!0,children:(0,Q.jsxs)(Y,{type:`button`,variant:`ghost`,className:Fl,children:[(0,Q.jsx)(Pl,{icon:(0,Q.jsx)(Yl,{kind:`external_event`}),label:o,detail:`${a.eventType} · ${a.sourceType}`,expanded:r}),(0,Q.jsx)(`span`,{className:`sr-only`,children:a.occurredAt})]})}),(0,Q.jsx)(Le,{className:`pb-1 pt-0.5 text-xs text-text-secondary`,children:(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-1`,children:[(0,Q.jsx)(`dt`,{children:n(`com_ui_subagent_event_type`)}),(0,Q.jsx)(`dd`,{className:`break-words text-text-primary`,children:a.eventType}),(0,Q.jsx)(`dt`,{children:n(`com_ui_subagent_event_source`)}),(0,Q.jsx)(`dd`,{className:`break-words text-text-primary`,children:a.sourceType}),(0,Q.jsx)(`dt`,{children:n(`com_ui_subagent_event_received`)}),(0,Q.jsx)(`dd`,{className:`break-words text-text-primary`,children:new Date(a.occurredAt).toLocaleStr
19ing()}),a.expectedActionToolName!=null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{children:n(`com_ui_subagent_event_expected_action`)}),(0,Q.jsx)(`dd`,{className:`break-words text-text-primary`,children:a.expectedActionToolName})]})]})})]}),(0,Q.jsx)(Gl,{id:`${e.taskId}:trigger`,icon:(0,Q.jsx)(Yl,{kind:`external_event`}),label:o,footer:null,timestamp:e.trigger.createdAt??a?.occurredAt,ariaLabel:o,headerPrefix:``,isCreatedByUser:!0,systemLabel:n(`com_ui_system_event`),fullWidth:t,children:s})}function Zl({turn:e,fullWidth:t}){let n=de(xe),r=K(),i=r(Jl[e.trigger.kind]),a=(0,Z.useMemo)(()=>e.trigger.summary===``?[]:[{type:W.TEXT,text:e.trigger.summary}],[e.trigger.summary]);return e.trigger.kind===`external_event`?(0,Q.jsx)(Xl,{turn:e,fullWidth:t}):(0,Q.jsxs)(Gl,{id:`${e.taskId}:trigger`,icon:(0,Q.jsx)(Yl,{kind:e.trigger.kind}),label:i,footer:null,timestamp:e.trigger.createdAt,ariaLabel:i,headerPrefix:``,isCreatedByUser:!0,systemLabel:r(`com_ui_system_event`),fullWidth:t,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2 py-1 text-sm text-text-secondary`,children:(0,Q.jsx)(Pl,{icon:(0,Q.jsx)(Yl,{kind:e.trigger.kind}),label:i})}),a.length>0&&(0,Q.jsx)(bl,{content:a,messageId:`${e.taskId}:trigger`,conversationId:null,isCreatedByUser:!0,showThinking:n,isLast:!1,isSubmitting:!1,isLatestMessage:!1}),e.trigger.summaryTruncated===!0&&(0,Q.jsx)(`div`,{className:`mt-1 text-xs italic text-text-secondary`,children:r(`com_ui_subagent_trigger_truncated`)})]})}function Ql({turn:e,state:t,agentId:n,conversationId:r,fullWidth:i,onCancelControl:a,detailState:o,onLoadDetails:s}){let c=K(),l=Un(),u=n==null?void 0:l?.[n],d=u?.name??e.activity.title,f=e.activity.activityTruncated===!0,p;p=f&&s!=null&&o!==`unavailable`?(0,Q.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:s,children:c(o===`error`?`com_ui_retry`:`com_ui_subagent_show_full_activity`)}):c(`com_ui_subagent_activity_details_unavailable`);let m=null;if(mi(e.activity.status))m=(0,Q.jsx)(jl,{activity:e.activity});else if(vi(e.activity.status)){let t=e.trigger.createdAt??e.trigger.externalEvent?.occurredAt,n=t==null?NaN:Date.parse(t);m=(0,Q.jsx)(vt,{start:Number.isFinite(n)?n:void 0})}let h=(0,Q.jsx)(`div`,{className:G(`mt-1 flex justify-start gap-3`,Ll),children:m}),g={endpoint:Ae.agents,modelLabel:d,isCreatedByUser:!1};return(0,Q.jsxs)(Gl,{id:`${e.taskId}:assistant`,icon:(0,Q.jsx)(ql,{iconData:g,agent:u}),label:d,footer:h,ariaLabel:d,headerPrefix:``,isCreatedByUser:!1,fullWidth:i,children:[(0,Q.jsx)(Al,{activity:e.activity,activityId:`${e.taskId}:assistant`,state:t,showPrompt:!1,conversationId:r,underHeaderIcon:!0,onCancelControl:a}),f&&o!==`loading`&&(0,Q.jsx)(`div`,{className:`mt-2 text-xs text-text-secondary`,children:p}),o===`loading`&&(0,Q.jsx)(`div`,{className:`mt-2 text-xs text-text-secondary`,"aria-live":`polite`,children:c(`com_ui_loading`)})]})}function $l({turns:e,agentId:t,conversationId:n,stateByTask:r,controllableTaskId:i,onCancelControl:a,detailStateByTask:o,onLoadTurnDetails:s}){let{maximizeChatSpace:c}=Nt();return(0,Q.jsx)(`div`,{className:`flex flex-col gap-6 py-4`,"data-subagent-conversation":!0,children:e.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,"data-subagent-thread-turn":e.taskId,children:[(0,Q.jsx)(`div`,{className:`px-4`,children:(0,Q.jsx)(Zl,{turn:e,fullWidth:c})}),(0,Q.jsx)(`div`,{className:`px-4`,children:(0,Q.jsx)(Ql,{turn:e,agentId:t,conversationId:n,fullWidth:c,state:r?.get(e.taskId)??`ready`,onCancelControl:a==null||e.taskId!==i?void 0:t=>a(e.taskId,t),detailState:o?.get(e.taskId),onLoadDetails:e.activity.activityTruncated!==!0||s==null?void 0:()=>s(e.taskId)})})]},e.taskId))})}var eu=e(F(),1),tu=typeof window<`u`&&window.__LIBRECHAT_CONFIG__?.hasConfiguredFooter===!0;function nu(){let{data:e,isSuccess:t}=Qt();return t?On(e):tu}function ru({className:e,startupConfig:t,configuredOnly:n=!1}){let r=t===void 0,{data:i}=Qt({enabled:r}),a=r?i:t,o=K(),s=a?.interface?.privacyPolicy,c=a?.interface?.termsOfService,l=s?.externalUrl!=null&&(0,Q.jsx)(`a`,{className:`text-text-muted underline`,href:s.externalUrl,rel:`noreferrer`,children:o(`com_ui_privacy_policy`)}),u=c?.externalUrl!=null&&(0,Q.jsx)(`a`,{className:`text-text-muted underline`,href:c.externalUrl,rel:`noreferrer`,children:o(`com_ui_terms_of_service`)}),d=typeof a?.customFooter==`string`?a.customFooter:null,f=n?``:`[LibreChat `+X.VERSION+`](https://librechat.ai) - `+
19o(`com_ui_latest_footer`),p=d??f,m=p===``?[]:p.split(`|`);(0,Z.useEffect)(()=>{if(a?.analyticsGtmId!=null&&window.google_tag_manager===void 0){let e={gtmId:a.analyticsGtmId};eu.default.initialize(e)}},[a?.analyticsGtmId]);let h=[...m.map((e,t)=>(0,Q.jsx)(Z.Fragment,{children:(0,Q.jsx)(ui,{components:{a:({node:e,href:t,children:n,...r})=>(0,Q.jsx)(`a`,{className:`text-text-muted underline`,href:t,target:`_blank`,rel:`noopener noreferrer`,...r,children:n}),p:({node:e,...t})=>(0,Q.jsx)(`span`,{...t})},children:e.trim()})},`main-content-part-${t}`)),l,u].filter(Boolean);return h.length===0?null:(0,Q.jsx)(`div`,{className:`relative w-full`,children:(0,Q.jsx)(`div`,{className:e??`absolute bottom-0 left-0 right-0 hidden items-center justify-center gap-2 px-2 py-2 text-center text-xs text-text-muted sm:flex md:px-[60px]`,children:h.map((e,t)=>{let n=t===h.length-1;return(0,Q.jsxs)(Z.Fragment,{children:[e,!n&&(0,Q.jsx)(`div`,{className:`h-2 border-r-[1px] border-border-medium`},`separator-${t}`)]},`footer-element-${t}`)})})})}var iu=(0,Z.memo)(ru);iu.displayName=`Footer`;var au=(0,Z.createContext)({conversationId:``,byMessageId:new Map,byThreadId:new Map,refresh:async()=>void 0,isError:!1,discoveryEnabled:!1});function ou({conversationId:e,enabled:t,isSubmitting:n=!1,children:r}){let i=ve(),{data:a=!1}=ye([Nr.messages,e],{enabled:!1,select:e=>e.some(e=>e.endpoint===Ae.agents)}),o=(i.getQueryData([Nr.backgroundTasks,e])?.tasks.length??0)>0||(i.getQueryData([Nr.parentSubagents,e])?.children.length??0)>0,s=t||a||o,[c,l]=(0,Z.useState)({conversationId:e,enabled:s}),u=c.conversationId===e&&c.enabled,d=e!==``&&e!==X.NEW_CONVO&&e!==X.PENDING_CONVO&&(u||s);(c.conversationId!==e||c.enabled!==d)&&l({conversationId:e,enabled:d});let{data:f,refetch:p,isError:m}=An(e,{enabled:d},n),h=(0,Z.useCallback)(async()=>(await p()).data,[p]),g=(0,Z.useMemo)(()=>{let t=new Map,n=new Map;for(let e of f?.children??[]){if(n.set(e.threadId,e),e.origin!==`event`)continue;let r=t.get(e.parentMessageId)??[];r.push(e),t.set(e.parentMessageId,r)}for(let e of t.values())e.sort((e,t)=>{let n=(t.updatedAt??``).localeCompare(e.updatedAt??``);return n===0?e.threadId.localeCompare(t.threadId):n});return{conversationId:e,byMessageId:t,byThreadId:n,refresh:h,isError:m,discoveryEnabled:d}},[e,f,h,m,d]);return(0,Q.jsx)(au.Provider,{value:g,children:r})}var su=()=>(0,Z.useContext)(au),cu=(e,t)=>`event-task:${e}:${t}`,lu=(e,t,n,r)=>{let i=r??t.latestTaskId;if(t.origin!==`event`||t.actorId==null||i==null)return null;let a=r!=null;return{host:`conversation`,parentConversationId:e,parentMessageId:t.parentMessageId,toolCallId:`event-thread:${t.threadId}`,partIndex:0,subagentType:t.subagentType,initialProgress:+(t.status===`completed`),isSubmitting:t.status===`running`,durable:{threadId:t.threadId,taskId:i},event:{actorId:t.actorId,progressKey:cu(t.threadId,i),...n==null?{}:{siblingParentMessageIds:n},...a?{pinnedTask:!0}:{}}}},uu=(e,t,n)=>{if(t.origin===`event`)return lu(e,t,void 0,n);let r=t.tasks.find(e=>e.taskId===n)?.status??t.status;return{host:`conversation`,parentConversationId:e,parentMessageId:t.parentMessageId,toolCallId:t.parentToolCallId??`subagent-thread:${t.threadId}`,partIndex:0,subagentType:t.subagentType,initialProgress:r===`running`?0:1,isSubmitting:r===`running`,durable:{threadId:t.threadId,taskId:n}}};export{uc as A,Vi as B,ul as C,fc as D,gc as E,Eo as F,_i as H,Co as I,Oo as L,Qs as M,qs as N,dc as O,Vo as P,yo as R,bl as S,Uc as T,hi as U,vi as V,gi as W,Nl as _,iu as a,Dl as b,ql as c,Vl as d,Bl as f,Pl as g,Il as h,su as i,lc as j,sc as k,Gl as l,Ll as m,lu as n,nu as o,Rl as p,ou as r,$l as s,uu as t,Wl as u,Fl as v,Yc as w,xl as x,Ml as y,co as z};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.