UNPKG

decocms

Version:

Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools

49 lines • 117 kB
import{c as $,r as z,j as l,g9 as be,b as U,av as De,m as K,a_ as gt,gc as Ve,aJ as Oe,aK as Ne,bn as ns,a6 as me,q as xt,L as lt,K as pe,gd as ot,an as as,e as ls,t as Be,i as ht,ak as os,R as rs,h as is,B as ye,b9 as bt,aj as cs,ge as us,gf as yt,a9 as ds,F as fs,C as Je,d as Qe,dO as ms,gg as rt,ew as ps,gh as gs}from"./index-ztdGKvBm.js";import{e as xs,A as Xe,ax as hs,a7 as bs,a as it,ay as ys,k as js,Z as vs,az as Ss,aA as jt,aB as ks,a6 as Ue,aC as Ns,aD as vt,aE as de,aF as we,g as ws,b as _s,aw as Ts,aG as Cs}from"./agent-icon-BYWtutu9.js";import{t as Ie,f as Is,b as $s}from"./Tool01-BCJ5kyrz.js";import{i as St}from"./ArrowRight-mzMrxxYI.js";import{b as Ms,C as As,a as Ps}from"./collapsible-CadTVXY4.js";import{u as Es}from"./use-copy-DT4_uVrH.js";import{h as kt,i as Ls,j as $e,k as Rs,P as zs,a as Fs,C as Ds,l as Os,n as Bs,F as Us,E as Hs,o as Ks}from"./usage-stats-B0_Yl-r0.js";import{h as Nt}from"./UserCheck01-k-4bTA2h.js";import{t as qs}from"./task-key-Bt60Ndov.js";import{a as Gs}from"./use-task-board-items-D2aUd0HA.js";import{l as Ws}from"./config-LEYSFIMn.js";import{t as Vs}from"./task-route-C3cK6F8S.js";import{a as Js}from"./repository-binding-D_Xc1yRH.js";import{u as Me,t as Qs,g as ge}from"./utils-CVEq3hMx.js";import{i as Xs,s as Ys}from"./UserSquare-CafFh5_d.js";import{l as Zs,c as en,r as tn,m as sn}from"./thread-intent-DyZ5A9F9.js";import{f as je,y as nn,u as ve,z as an,b as ln,B as wt,E as on,F as Ae,G as rn,H as cn}from"./chat-context-DFEln8mI.js";import{a as Ye,u as un,b as dn}from"./shell-layout-UF80oiAz.js";import{c as fn}from"./content-blocks-o63cs2vh.js";import{M as mn}from"./mcp-app-renderer-DU6s3Olv.js";import{g as _t}from"./types-5-cDe_8u.js";import{o as pn}from"./omit-server-managed-metadata-L5IhjRZB.js";import{T as Tt,a as Ct,c as It}from"./tooltip-Bm0P1gm_.js";import{c as gn,u as xn,a as hn}from"./use-mcp-client-2MG3LveS.js";import{s as $t,g as Mt,a as At}from"./gateway-client-B4qzR3sF.js";import{i as Pt}from"./AlertCircle-BlMH0XE7.js";import{s as bn}from"./Eye-kjjhS0vP.js";import{s as yn}from"./XClose-CmTuu4UN.js";import{n as He}from"./BookOpen01-DU-B3R7s.js";import{s as jn}from"./File02-DaYek2y9.js";import{i as vn}from"./SearchMd-BD2qldmS.js";import{a as Ze}from"./use-panel-navigate-0z93k6Ut.js";import{a as _e}from"./Image01-BcIZ5mtf.js";import{b as Et}from"./use-entitlements-Gn1rhCN5.js";import{I as Sn,M as Lt}from"./markdown-CJR_ooUO.js";import{c as kn,S as Nn,a as wn,b as _n}from"./sheet-C-umRrOH.js";import{I as Se}from"./integration-icon-Bo-3z9o3.js";import{u as Rt}from"./use-connection-CcG4QE1K.js";import{u as zt}from"./use-navigate-to-agent-Cw8_3uU5.js";import{g as Tn}from"./use-mcp-prompts-qJSiAdA5.js";import{t as Cn}from"./ChevronDown-XsLJSrfl.js";import{i as In}from"./Monitor01-DMFbvudn.js";import{a as $n}from"./use-thread-outputs-BK5BfLdO.js";import{F as Mn}from"./file-type-icon-CdjLDWdN.js";const Ft=[{delay:0},{delay:100},{delay:200},{delay:100},{delay:200},{delay:200},{delay:300},{delay:300},{delay:400}];function An(){const s=$.c(5),[e]=z.useState(Pn);let t;s[0]===Symbol.for("react.memo_cache_sentinel")?(t={gridTemplateColumns:"repeat(3, 3px)",gap:"1.5px",width:"fit-content"},s[0]=t):t=s[0];let n;s[1]!==e?(n=Ft.map((o,c)=>{const{delay:i}=o;return l.jsx("div",{className:"rounded-[1px]",style:{width:3,height:3,"--cell-color":e[c],animation:"grid-ripple 1s ease infinite",animationDelay:`${i}ms`}},c)}),s[1]=e,s[2]=n):n=s[2];let a;return s[3]!==n?(a=l.jsx("div",{className:"grid",style:t,children:n}),s[3]=n,s[4]=a):a=s[4],a}function Pn(){const s=`var(--chart-${Math.ceil(Math.random()*5)})`;return Ft.map(()=>Math.random()<.6?"color-mix(in srgb, var(--muted-foreground) 25%, transparent)":s)}const En={damping:.7,stiffness:.05,mass:1.25},Ln=70,Rn=1e3/60,zn=350;let Pe=!1;globalThis.document?.addEventListener("mousedown",()=>{Pe=!0});globalThis.document?.addEventListener("mouseup",()=>{Pe=!1});globalThis.document?.addEventListener("click",()=>{Pe=!1});const Fn=(s={})=>{const[e,t]=z.useState(!1),[n,a]=z.useState(s.initial!==!1),[o,c]=z.useState(!1),i=z.useRef(null);i.current=s;const u=z.useCallback(()=>{if(!Pe)return!1;const b=window.getSelection();if(!b||!b.rangeCount)return!1;const N=b.getRangeAt(0);return N.commonAncestorContainer.contains(h.current)||h.current?.contains(N.commonAncestorContainer)},[]),r=z.useCallback(b=>{d.isAtBottom=b,a(b)},[]),m=z.useCallback(b=>{d.escapedFromLock=b,t(b)},[]),d=z.useMemo(()=>{let b;return{escapedFromLock:e,isAtBottom:n,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return h.current?.scrollTop??0},set scrollTop(N){if(h.current){const{scrollBehavior:j}=getComputedStyle(h.current);j!=="auto"&&(h.current.style.scrollBehavior="auto"),h.current.scrollTop=N,d.ignoreScrollToTop=h.current.scrollTop,j!=="auto"&&(h.current.style.scrollBehavior=j)}},get targetScrollTop(){return!h.current||!y.current?0:h.current.scrollHeight-1-h.current.clientHeight},get calculatedTargetScrollTop(){if(!h.current||!y.current)return 0;const{targetScrollTop:N}=this;if(!s.targetScrollTop)return N;if(b?.targetScrollTop===N)return b.calculatedScrollTop;const j=Math.max(Math.min(s.targetScrollTop(N,{scrollElement:h.current,contentElement:y.current}),N),0);return b={targetScrollTop:N,calculatedScrollTop:j},requestAnimationFrame(()=>{b=void 0}),j},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Ln}}},[]),f=z.useCallback((b={})=>{typeof b=="string"&&(b={animation:b}),b.preserveScrollPosition||r(!0);const N=Date.now()+(Number(b.wait)||0),j=Re(i.current,b.animation),{ignoreEscapes:w=!1}=b;let k,S=d.calculatedTargetScrollTop;b.duration instanceof Promise?b.duration.finally(()=>{k=Date.now()}):k=N+(b.duration??0);const v=async()=>{const _=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;const{scrollTop:T}=d,M=performance.now(),P=(M-(d.lastTick??M))/Rn;if(d.animation||(d.animation={behavior:j,promise:_,ignoreEscapes:w}),d.animation.behavior===j&&(d.lastTick=M),u()||N>Date.now())return v();if(T<Math.min(S,d.calculatedTargetScrollTop)){if(d.animation?.behavior===j){if(j==="instant")return d.scrollTop=d.calculatedTargetScrollTop,v();d.velocity=(j.damping*d.velocity+j.stiffness*d.scrollDifference)/j.mass,d.accumulated+=d.velocity*P,d.scrollTop+=d.accumulated,d.scrollTop!==T&&(d.accumulated=0)}return v()}return k>Date.now()?(S=d.calculatedTargetScrollTop,v()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Re(i.current,i.current.resize),ignoreEscapes:w,duration:Math.max(0,k-Date.now())||void 0}):d.isAtBottom)});return _.then(T=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),T))};return b.wait!==!0&&(d.animation=void 0),d.animation?.behavior===j?d.animation.promise:v()},[r,u,d]),p=z.useCallback(()=>{m(!0),r(!1)},[m,r]),g=z.useCallback(({target:b})=>{if(b!==h.current)return;const{scrollTop:N,ignoreScrollToTop:j}=d;let{lastScrollTop:w=N}=d;d.lastScrollTop=N,d.ignoreScrollToTop=void 0,j&&j>N&&(w=j),c(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||N===j)return;if(u()){m(!0),r(!1);return}const k=N>w,S=N<w;if(d.animation?.ignoreEscapes){d.scrollTop=w;return}S&&(m(!0),r(!1)),k&&m(!1),!d.escapedFromLock&&d.isNearBottom&&r(!0)},1)},[m,r,u,d]),x=z.useCallback(({target:b,deltaY:N})=>{let j=b;for(;!["scroll","auto"].includes(getComputedStyle(j).overflow);){if(!j.parentElement)return;j=j.parentElement}j===h.current&&N<0&&h.current.scrollHeight>h.current.clientHeight&&!d.animation?.ignoreEscapes&&(m(!0),r(!1))},[m,r,d]),h=ct(b=>{h.current?.removeEventListener("scroll",g),h.current?.removeEventListener("wheel",x),b?.addEventListener("scroll",g,{passive:!0}),b?.addEventListener("wheel",x,{passive:!0})},[]),y=ct(b=>{if(d.resizeObserver?.disconnect(),d.resizeObserver=void 0,!b)return;let N;d.resizeObserver=new ResizeObserver(([j])=>{const{height:w}=j.contentRect,k=w-(N??w);if(d.resizeDifference=k,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),c(d.isNearBottom),k>=0){const S=Re(i.current,N?i.current.resize:i.current.initial);f({animation:S,wait:!0,preserveScrollPosition:!0,duration:S==="instant"?void 0:zn})}else d.isNearBottom&&(m(!1),r(!0));N=w,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===k&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(b)},[]);return{contentRef:y,scrollRef:h,scrollToBottom:f,stopScroll:p,isAtBottom:n||o,isNearBottom:o,escapedFromLock:e,state:d}};function ct(s,e){const t=z.useCallback(n=>(t.current=n,s(n)),e);return t}const Le=new Map;function Re(...s){const e={...En};let t=!1;for(const a of s){if(a==="instant"){t=!0;continue}typeof a=="object"&&(t=!1,e.damping=a.damping??e.damping,e.stiffness=a.stiffness??e.stiffness,e.mass=a.mass??e.mass)}const n=JSON.stringify(e);return Le.has(n)||Le.set(n,Object.freeze(e)),t?"instant":Le.get(n)}function Y({icon:s,title:e,usage:t,summary:n,state:a,detail:o,detailVariant:c="code",forceOpen:i,variant:u="default",trailing:r,iconDestructive:m,alwaysChevron:d,defaultOpen:f,children:p}){const g=U(),[x,h]=z.useState(f??!1),{handleCopy:y,copied:b}=Es(),N=a==="loading",j=a==="error",w=!!(o&&o.trim()),k=w||!!p,S=u==="subtask",v=(i??!1)||x,_=Fn({initial:N?"instant":!1}),T=l.jsxs(Ms,{open:v,onOpenChange:i?void 0:h,className:"min-w-0",children:[l.jsxs(As,{disabled:!k,className:K("group/tool flex items-center gap-2 w-full py-1.5 text-left transition-colors",!k&&"cursor-default"),"aria-disabled":!k,children:[l.jsx("div",{className:"relative shrink-0 size-4 flex items-center justify-center",children:d?l.jsx(De,{className:K("size-4 text-foreground/60 transition-transform duration-200 ease-in-out",v&&"rotate-90")}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:K("absolute inset-0 flex items-center justify-center [&>svg]:size-4 transition-opacity duration-150",m?"[&>svg]:text-destructive/70":j?"[&>svg]:text-warning/70":"[&>svg]:text-muted-foreground/75",k&&(v?"opacity-0":"[@media(hover:hover)]:group-hover/tool:opacity-0")),children:s}),k&&l.jsx("div",{className:K("absolute inset-0 flex items-center justify-center transition-opacity duration-150",v?"opacity-100":"opacity-0 [@media(hover:hover)]:group-hover/tool:opacity-100"),children:l.jsx(De,{className:K("size-4 text-foreground/60 transition-transform duration-200 ease-in-out",v&&"rotate-90")})})]})}),l.jsx("span",{className:K("shrink-0 text-sm font-normal transition-colors",j?"text-warning/80":v?"text-foreground":"text-muted-foreground [@media(hover:hover)]:group-hover/tool:text-foreground",N&&"shimmer"),children:e}),n&&!(v&&w)?l.jsx("span",{className:K("min-w-0 flex-1 truncate text-sm text-muted-foreground/60",N&&"shimmer"),children:n}):l.jsx("div",{className:"flex-1"}),r&&l.jsx("div",{className:"shrink-0 flex items-center gap-1 [&_svg]:size-3.5 [&_svg]:text-muted-foreground/50",children:r}),l.jsx(kt,{usage:t})]}),k&&l.jsx(Ps,{className:"data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden",children:p||(c==="prose"?l.jsx("div",{className:"ml-[7px] mb-1 border-l border-border pl-[17px]",children:l.jsx("div",{ref:_.scrollRef,className:"max-h-60 overflow-y-auto",children:l.jsx("p",{ref:_.contentRef,className:"text-sm text-muted-foreground whitespace-pre-wrap leading-relaxed wrap-break-word",children:o})})}):l.jsx("div",{className:"ml-[20px] pl-3 border-l border-border/30 mt-0.5 pb-1",children:l.jsx("div",{ref:_.scrollRef,className:"flex flex-col max-h-48 overflow-y-auto",children:l.jsxs("div",{ref:_.contentRef,className:"flex items-start justify-between gap-2",children:[l.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:l.jsx("pre",{className:"text-xs font-mono text-muted-foreground/70 whitespace-pre-wrap wrap-break-word",children:o})}),l.jsx("button",{type:"button",onClick:()=>y(o),className:"shrink-0 p-1.5 rounded-lg text-muted-foreground/50 [@media(hover:hover)]:hover:text-foreground [@media(hover:hover)]:hover:bg-accent transition-colors active:scale-[0.97]","aria-label":g("common.copy"),children:b?l.jsx(gt,{className:"size-3.5"}):l.jsx(xs,{className:"size-3.5"})})]})})}))})]});return S?l.jsx("div",{className:"pl-4 border-l border-border/40 ml-1.5",children:T}):T}function fe(s){const e=$.c(4),{latency:t}=s;if(t==null||t<=0)return null;let n;e[0]!==t?(n=be(t),e[0]=t,e[1]=n):n=e[1];let a;return e[2]!==n?(a=l.jsx("span",{className:"text-2xs font-mono tabular-nums text-muted-foreground",children:n}),e[2]=n,e[3]=a):a=e[3],a}const Dt=4;function Ot(s){const e=$.c(8),{count:t,noun:n,onClick:a}=s,o=U();let c;e[0]!==t||e[1]!==n||e[2]!==o?(c=o("common.seeAll",{count:t,noun:n}),e[0]=t,e[1]=n,e[2]=o,e[3]=c):c=e[3];let i;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=l.jsx(St,{className:"size-4 transition-transform group-hover:translate-x-0.5","aria-hidden":"true"}),e[4]=i):i=e[4];let u;return e[5]!==a||e[6]!==c?(u=l.jsxs("button",{type:"button",onClick:a,className:"group flex w-full items-center justify-center gap-1.5 rounded-lg border border-border bg-card px-3 py-2.5 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground cursor-pointer",children:[c,i]}),e[5]=a,e[6]=c,e[7]=u):u=e[7],u}function et(s){const e=$.c(12),{message:t,className:n}=s,a=t.created_at??t.metadata?.created_at??null;let o,c,i,u;if(e[0]!==n||e[1]!==a){u=Symbol.for("react.early_return_sentinel");e:{const m=Ve(a);if(m===null){u=null;break e}const d=new Date(m);o=d.toLocaleString(),e[6]!==n?(c=K("text-sm text-muted-foreground select-none",n),e[6]=n,e[7]=c):c=e[7],i=d.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}e[0]=n,e[1]=a,e[2]=o,e[3]=c,e[4]=i,e[5]=u}else o=e[2],c=e[3],i=e[4],u=e[5];if(u!==Symbol.for("react.early_return_sentinel"))return u;let r;return e[8]!==o||e[9]!==c||e[10]!==i?(r=l.jsx("span",{title:o,className:c,children:i}),e[8]=o,e[9]=c,e[10]=i,e[11]=r):r=e[11],r}const Dn=Oe({item:Oe({id:Ne(),title:Ne(),status:Ne(),keySeq:ns().nullable(),virtualMcpId:Ne().nullable()})});function On(s){if(s.state!=="output-available")return null;const e=Dn.safeParse(Me(s.output)??s.output);return e.success?e.data.item:null}function Bn(s){const e=$.c(17),{task:t}=s,n=U(),{org:a,locator:o}=me(),c=xt(),{items:i}=Gs();let u;e[0]!==t?(u=M=>M.id===t.id,e[0]=t,e[1]=u):u=e[1];const r=i.find(u),m=r??t,d=()=>{r||c.invalidateQueries({queryKey:pe.taskBoardItems(o)})},f=Js(m.virtualMcpId),p=Ws(m.status,n),g=p.visual.icon,x=qs(a.slug,m.keySeq),h=Vs(a.slug,m);let y;e[2]!==f?(y=f?l.jsx(Xe,{icon:f.icon??null,name:f.title,size:"sm"}):l.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:l.jsx(Nt,{size:16})}),e[2]=f,e[3]=y):y=e[3];const b="mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground",N=K("size-3.5 shrink-0",p.visual.iconClassName);let j;e[4]!==g||e[5]!==N?(j=l.jsx(g,{className:N,"aria-hidden":!0}),e[4]=g,e[5]=N,e[6]=j):j=e[6];let w;e[7]!==p.label?(w=l.jsx("span",{className:"shrink-0",children:p.label}),e[7]=p.label,e[8]=w):w=e[8];const k=f?.title;let S;e[9]!==x||e[10]!==k?(S=[x,k].filter(Boolean).map(Un),e[9]=x,e[10]=k,e[11]=S):S=e[11];let v;e[12]!==j||e[13]!==w||e[14]!==S?(v=l.jsxs("span",{className:b,children:[j,w,S]}),e[12]=j,e[13]=w,e[14]=S,e[15]=v):v=e[15];let _;e[16]===Symbol.for("react.memo_cache_sentinel")?(_=l.jsx(De,{size:16,"aria-hidden":!0,className:"shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-foreground"}),e[16]=_):_=e[16];const T=l.jsxs(l.Fragment,{children:[y,l.jsxs("span",{className:"min-w-0 flex-1",children:[l.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:m.title}),v]}),_]});return m.virtualMcpId?l.jsx(lt,{to:"/$org/projects/$agentId/tasks/{-$taskKey}",params:{org:a.slug,agentId:m.virtualMcpId,taskKey:h},className:"group my-2 flex items-center gap-3 rounded-xl border border-border bg-card px-3 py-2.5 shadow-xs transition-colors hover:bg-accent/50 focus-ring",onClick:d,children:T}):l.jsx(lt,{to:"/$org/tasks/{-$taskKey}",params:{org:a.slug,taskKey:h},className:"group my-2 flex items-center gap-3 rounded-xl border border-border bg-card px-3 py-2.5 shadow-xs transition-colors hover:bg-accent/50 focus-ring",onClick:d,children:T})}function Un(s){return l.jsx("span",{className:"truncate before:mr-1.5 before:content-['·']",children:s},s)}function Ke(s){const e=$.c(9),{since:t}=s;let n;e[0]!==t?(n=()=>ot(t,Date.now()),e[0]=t,e[1]=n):n=e[1];const[a,o]=z.useState(n);let c,i;e[2]!==t?(c=()=>{const d=setInterval(()=>o(ot(t,Date.now())),100);return()=>clearInterval(d)},i=[t],e[2]=t,e[3]=c,e[4]=i):(c=e[3],i=e[4]),z.useEffect(c,i);const u=a/1e3;let r;e[5]!==u?(r=be(u),e[5]=u,e[6]=r):r=e[6];let m;return e[7]!==r?(m=l.jsx("span",{className:"tabular-nums text-sm font-mono text-muted-foreground/50",children:r}),e[7]=r,e[8]=m):m=e[8],m}function Hn(s){return{planning:{icon:l.jsx(Xs,{className:"text-muted-foreground shrink-0 animate-pulse",size:14}),label:s("chat.thinkingIndicator.planningLabel"),detail:s("chat.thinkingIndicator.planningDetail")},thinking:{icon:l.jsx(Ie,{className:"text-muted-foreground shrink-0 animate-pulse",size:14}),label:s("chat.thinkingIndicator.thinkingLabel"),detail:s("chat.thinkingIndicator.thinkingDetail")}}}const Kn=1200;function qe(s){const e=$.c(8),{icon:t,title:n,summary:a,detail:o,state:c,detailVariant:i,trailing:u}=s,r=i===void 0?"prose":i;let m;return e[0]!==o||e[1]!==r||e[2]!==t||e[3]!==c||e[4]!==a||e[5]!==n||e[6]!==u?(m=l.jsx(Y,{icon:t,title:n,summary:a,detail:o,state:c,detailVariant:r,trailing:u}),e[0]=o,e[1]=r,e[2]=t,e[3]=c,e[4]=a,e[5]=n,e[6]=u,e[7]=m):m=e[7],m}function qn(s){const e=$.c(22),{startedAt:t}=s,n=U(),a=je()?.runStatusStage??null,[o,c]=z.useState("planning");let i,u;if(e[0]!==a?(i=()=>{if(a!==null)return;const x=setTimeout(()=>{c("thinking")},Kn);return()=>{clearTimeout(x)}},u=[a],e[0]=a,e[1]=i,e[2]=u):(i=e[1],u=e[2]),z.useEffect(i,u),a!==null){let x;e[3]!==a||e[4]!==n?(x=Zs(n,a),e[3]=a,e[4]=n,e[5]=x):x=e[5];const h=x;let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=l.jsx(Ie,{className:"size-4"}),e[6]=y):y=e[6];const b=`${h.label}...`;let N;e[7]!==t?(N=t!==null&&l.jsx(Ke,{since:t}),e[7]=t,e[8]=N):N=e[8];let j;return e[9]!==h.detail||e[10]!==b||e[11]!==N?(j=l.jsx(qe,{icon:y,title:b,summary:h.detail,state:"loading",trailing:N}),e[9]=h.detail,e[10]=b,e[11]=N,e[12]=j):j=e[12],j}let r;e[13]!==n?(r=Hn(n),e[13]=n,e[14]=r):r=e[14];const d=r[o],f=`${d.label}...`;let p;e[15]!==t?(p=t!==null&&l.jsx(Ke,{since:t}),e[15]=t,e[16]=p):p=e[16];let g;return e[17]!==d.detail||e[18]!==d.icon||e[19]!==f||e[20]!==p?(g=l.jsx(qe,{icon:d.icon,title:f,summary:d.detail,state:"loading",trailing:p}),e[17]=d.detail,e[18]=d.icon,e[19]=f,e[20]=p,e[21]=g):g=e[21],g}function Gn(s){const e=$.c(3),{startedAt:t}=s;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=l.jsx(An,{}),e[0]=n):n=e[0];let a;return e[1]!==t?(a=l.jsxs("div",{className:"flex items-center gap-2.5 mt-1 pb-1 text-muted-foreground/40 select-none",children:[n,l.jsx(Ke,{since:t})]}),e[1]=t,e[2]=a):a=e[2],a}const Wn=2e4;function Vn(s){const e=$.c(9),{startedAt:t}=s,n=U(),a=Ye(1e3),o=je(),i=(t!==null?a-t:0)>=Wn;let u;e[0]!==t?(u=l.jsx(qn,{startedAt:t}),e[0]=t,e[1]=u):u=e[1];let r;e[2]!==i||e[3]!==o||e[4]!==n?(r=i&&o?.stop&&l.jsxs("div",{className:"flex items-center gap-2 pb-1 text-sm text-muted-foreground/60",children:[l.jsx("span",{children:n("chat.thinkingIndicator.takingLonger")}),l.jsx("button",{type:"button",onClick:()=>o.stop(),className:"text-muted-foreground hover:text-foreground underline underline-offset-2",children:n("chat.thinkingIndicator.cancel")})]}),e[2]=i,e[3]=o,e[4]=n,e[5]=r):r=e[5];let m;return e[6]!==u||e[7]!==r?(m=l.jsxs("div",{className:"flex flex-col gap-0.5",children:[u,r]}),e[6]=u,e[7]=r,e[8]=m):m=e[8],m}function Jn(s){const e=$.c(24),{duration:t,parts:n,isStreaming:a}=s,o=U();let c;e[0]!==n?(c=n.every(Yn),e[0]=n,e[1]=c):c=e[1];const i=c;let u;e[2]!==t||e[3]!==o?(u=t&&t/1e3>1?o("chat.thinkingIndicator.thoughtFor",{duration:be(t/1e3)}):o("chat.thinkingIndicator.thought"),e[2]=t,e[3]=o,e[4]=u):u=e[4];const r=u;let m;if(e[5]!==i||e[6]!==a||e[7]!==n){const N=n.map(Xn).join(`
`).trim().split(`
`).filter(Boolean),j=a?N[N.length-1]??"":N[0]??"";m=!i&&j?j.length>100?j.slice(0,100)+"…":j:void 0,e[5]=i,e[6]=a,e[7]=n,e[8]=m}else m=e[8];const d=m;let f;if(e[9]!==i||e[10]!==n){const b=n.map(Qn).join(`

`);f=!i&&b.trim()?b.trim():null,e[9]=i,e[10]=n,e[11]=f}else f=e[11];const p=f;let g;e[12]!==a?(g=a?l.jsx(Ie,{className:"size-4"}):l.jsx(hs,{className:"size-4"}),e[12]=a,e[13]=g):g=e[13];let x;e[14]!==a||e[15]!==o||e[16]!==r?(x=a?o("chat.thinkingIndicator.thinking"):r,e[14]=a,e[15]=o,e[16]=r,e[17]=x):x=e[17];const h=a?"loading":"idle";let y;return e[18]!==p||e[19]!==d||e[20]!==g||e[21]!==x||e[22]!==h?(y=l.jsx(qe,{icon:g,title:x,summary:d,detail:p,state:h,detailVariant:"prose"}),e[18]=p,e[19]=d,e[20]=g,e[21]=x,e[22]=h,e[23]=y):y=e[23],y}function Qn(s){return s.text??""}function Xn(s){return s.text??""}function Yn(s){return s.text?.includes("REDACTED")}function Zn(s){const e=$.c(24),{org:t}=me(),n=xt(),a=en(),o=as();let c;e[0]!==o||e[1]!==s?(c=async x=>{if(!s)throw new Error("useTaskExpandedTools: no task in context");const y=(await o.call("COLLECTION_THREADS_GET",{id:s})).item?.metadata??{},N=(y.expanded_tools??[]).filter(w=>w.toolName!==x.toolName);N.push({...x,expandedAt:new Date().toISOString()});const j={...pn(y),expanded_tools:N};return await o.call("COLLECTION_THREADS_UPDATE",{id:s,data:{metadata:j}}),N},e[0]=o,e[1]=s,e[2]=c):c=e[2];let i,u,r;e[3]!==t||e[4]!==n||e[5]!==s?(i=async x=>{const h=pe.ensureTask(t.id,s??"");await n.cancelQueries({queryKey:h});const y=n.getQueryData(h),N=(y?.metadata?.expanded_tools??[]).filter(j=>j.toolName!==x.toolName);return N.push({...x,expandedAt:new Date().toISOString()}),n.setQueryData(h,j=>j&&{...j,metadata:{...j.metadata??{},expanded_tools:N}}),{previous:y}},u=()=>{n.invalidateQueries({queryKey:pe.ensureTask(t.id,s??"")})},r=(x,h,y)=>{const b=pe.ensureTask(t.id,s??"");y?.previous===void 0?n.removeQueries({queryKey:b,exact:!0}):n.setQueryData(b,y.previous),Be.error(x instanceof Error?x.message:"Failed to expand tool")},e[3]=t,e[4]=n,e[5]=s,e[6]=i,e[7]=u,e[8]=r):(i=e[6],u=e[7],r=e[8]);let m;e[9]!==c||e[10]!==i||e[11]!==u||e[12]!==r?(m={mutationFn:c,onMutate:i,onSuccess:u,onError:r},e[9]=c,e[10]=i,e[11]=u,e[12]=r,e[13]=m):m=e[13];const d=ls(m);let f;e[14]!==a||e[15]!==d||e[16]!==t||e[17]!==n||e[18]!==s?(f=x=>{if(!s||!a)return;const h=pe.ensureTask(t.id,s),y=n.getQueryData(h),N=(y?.metadata?.expanded_tools??[]).filter(w=>w.toolName!==x.toolName);N.push({...x,expandedAt:new Date().toISOString()});const j={...y?.metadata??{},expanded_tools:N};n.setQueryData(h,w=>w&&{...w,metadata:j}),a.patchThread({id:s,metadata:j}),d.mutate(x)},e[14]=a,e[15]=d,e[16]=t,e[17]=n,e[18]=s,e[19]=f):f=e[19];const p=f;let g;return e[20]!==p||e[21]!==d.isPending||e[22]!==d.mutate?(g={addOrReplace:d.mutate,addOrReplaceEager:p,isPending:d.isPending},e[20]=p,e[21]=d.isPending,e[22]=d.mutate,e[23]=g):g=e[23],g}function ea(s){if(s<1024)return`${s} B`;if(s<1024*1024){const t=s/1024;return t<10?`${t.toFixed(1)} KB`:`${Math.round(t)} KB`}const e=s/(1024*1024);return e<10?`${e.toFixed(1)} MB`:`${Math.round(e)} MB`}function ta(s,e,t,n){const{data:a,isLoading:o}=ht({queryKey:pe.toolDefinitionLookup(e,t,s),queryFn:async()=>{if(!s||!e)return null;const c=await gn({connectionId:e,orgId:t,orgSlug:n});try{const{tools:i}=await c.listTools(),u=$t(s);return i.find(r=>r.name===u)??null}finally{await c.close().catch(()=>{})}},enabled:!!s&&!!e,staleTime:6e4,gcTime:3e5,retry:!1});return{toolDef:a??void 0,isLoading:o}}const sa={read:{icon:it,labelKey:"chat.generic.tool.read"},write:{icon:$s,labelKey:"chat.generic.tool.write"},edit:{icon:vs,labelKey:"chat.generic.tool.edit"},grep:{icon:vn,labelKey:"chat.generic.tool.grep"},glob:{icon:js,labelKey:"chat.generic.tool.glob"},bash:{icon:ys,labelKey:"chat.generic.tool.bash"},read_tool_output:{icon:it,labelKey:"chat.generic.tool.readToolOutput"},read_resource:{icon:jn,labelKey:"chat.generic.tool.readResource"},read_prompt:{icon:He,labelKey:"chat.generic.tool.readPrompt"},skill:{icon:He,labelKey:"chat.generic.tool.skill"},enable_tool:{icon:Is,labelKey:"chat.generic.tool.enableTool"},open_in_agent:{icon:os,labelKey:"chat.generic.tool.openInAgent"},sandbox:{icon:bs,labelKey:"chat.generic.tool.sandbox"}},Bt="studio:bash-sleep-start:v1",na=200;function aa(s,e,t,n=na){const a=s.filter(([o])=>o!==e);for(a.push([e,t]);a.length>n;)a.shift();return a}function la(){try{const s=sessionStorage.getItem(Bt);if(!s)return[];const e=JSON.parse(s);return Array.isArray(e)?e.filter(t=>Array.isArray(t)&&t.length===2&&typeof t[0]=="string"&&Number.isFinite(t[1])):[]}catch{return[]}}function oa(s){try{const e=la(),t=e.find(([a])=>a===s);if(t)return t[1];const n=Date.now();return sessionStorage.setItem(Bt,JSON.stringify(aa(e,s,n))),n}catch{return Date.now()}}function Ut(s,e){const t=$.c(2);let n;t[0]!==s?(n=()=>oa(s),t[0]=s,t[1]=n):n=t[1];const a=z.useState(n)[0];return e??a}function Ht(s){const e=Math.ceil(s/1e3);if(e<60)return`${e}s`;const t=Math.floor(e/60),n=e%60;return n?`${t}m ${n}s`:`${t}m`}function ra(s){const e=$.c(5),{toolCallId:t,durationMs:n,anchorMs:a}=s,o=U(),c=Ye(1e3),u=Ut(t,a)+n-c;let r;e[0]!==u||e[1]!==o?(r=u>0?o("chat.generic.waitingFor",{duration:Ht(u)}):o("chat.generic.wrappingUp"),e[0]=u,e[1]=o,e[2]=r):r=e[2];let m;return e[3]!==r?(m=l.jsx("span",{className:"tabular-nums",children:r}),e[3]=r,e[4]=m):m=e[4],m}const ia=1e4;function ca(s){const e=$.c(7),{toolCallId:t,anchorMs:n}=s,a=U(),o=Ye(1e3),c=Ut(t,n),i=o-c;if(i<ia){let m;return e[0]!==a?(m=a("chat.generic.preparing"),e[0]=a,e[1]=m):m=e[1],m}let u;e[2]!==i||e[3]!==a?(u=a("chat.generic.runningFor",{elapsed:Ht(i)}),e[2]=i,e[3]=a,e[4]=u):u=e[4];let r;return e[5]!==u?(r=l.jsx("span",{className:"tabular-nums",children:u}),e[5]=u,e[6]=r):r=e[6],r}const ua={s:1e3,m:6e4,h:36e5,d:864e5};function da(s){const e=/(?:^|[\s;&|(])sleep((?:\s+[\d.]+[smhd]?)+)/g;let t=0,n=!1;for(const a of s.matchAll(e))for(const o of a[1].trim().split(/\s+/)){const c=/^([\d.]+)([smhd]?)$/.exec(o);if(!c)continue;const i=Number.parseFloat(c[1]);Number.isFinite(i)&&(t+=i*(ua[c[2]||"s"]??1e3),n=!0)}return n?t:null}function Ee(s,e="An unknown error occurred"){return"errorText"in s&&typeof s.errorText=="string"?s.errorText:e}function xe(s){if(s==null)return"";try{return JSON.stringify(s)}catch{return"[Non-serializable value]"}}function Ce(s){const e=xe(s);if(e===""||e==="[Non-serializable value]")return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}const fa=s=>s.type==="dynamic-tool"||s.type.startsWith("tool-");function ma(s){if(!s||typeof s!="object")return null;const e=s;if(!Array.isArray(e.parts))return null;const t=[];for(const n of e.parts)if(n.type==="text"&&typeof n.text=="string")t.push(n.text);else if(n.type==="reasoning")t.push(`## Reasoning
${n.text}`);else if(n.type==="source-url")t.push(`## Source URL
${n.url}`);else if(n.type==="source-document")t.push(`## Source Document
${n.title}`);else if(n.type==="file")t.push(`## File
${n.filename??n.url}`);else if(n.type!=="step-start"){if(fa(n)){const a=n.type.startsWith("tool-")?n.type.slice(5):n.toolName;if(n.state==="input-streaming")t.push(`## ${a}
Input streaming...`);else if(n.state==="input-available"){const o=xe(n.input).slice(0,20);t.push(`## ${a}
### Input
${o||"[No input]"}...`)}else if(n.state==="approval-requested")t.push(`## ${a}
Approval requested...`);else if(n.state==="approval-responded")t.push(`## ${a}
Approval responded...`);else if(n.state==="output-available"){const o=xe(n.input).slice(0,40),c=xe(n.output).slice(0,40);t.push(n.output!=null?`## ${a}
Input: ${o||"[No input]"}...
Output: ${c||"[No output]"}...`:`## ${a}
Input: ${o||"[No input]"}...
Output: Tool responded with no output`)}else if(n.state==="output-error"){const o=xe(n.input).slice(0,40);t.push(n.errorText?`## ${a}
Input: ${o||"[No input]"}...
Error: ${n.errorText}`:`## ${a}
Input: ${o||"[No input]"}...
Error: Tool responded with an error`)}else if(n.state==="output-denied"){const o=xe(n.input).slice(0,40);t.push(`## ${a}
Input: ${o||"[No input]"}...
Output: Tool execution was denied`)}}}return t.length>0?t.join(`

`):null}function ut(s){const e=s&&typeof s=="object"&&"created_at"in s?s.created_at:void 0;return typeof e=="string"||e instanceof Date?Ve(e):null}function pa(s){const e=s&&typeof s=="object"&&"timeout"in s?s.timeout:void 0;return Math.min(typeof e=="number"?e:3e4,12e4)}function Te(s){const e=$.c(7),{icon:t,label:n}=s;let a;e[0]!==t?(a=l.jsx(Tt,{asChild:!0,children:l.jsx("span",{className:"flex items-center",children:t})}),e[0]=t,e[1]=a):a=e[1];let o;e[2]!==n?(o=l.jsx(Ct,{side:"top",children:n}),e[2]=n,e[3]=o):o=e[3];let c;return e[4]!==a||e[5]!==o?(c=l.jsxs(It,{children:[a,o]}),e[4]=a,e[5]=o,e[6]=c):c=e[6],c}function ga(s){const e=$.c(19),{annotations:t,toolMeta:n}=s,a=U();let o;e[0]!==n?(o=_t(n),e[0]=n,e[1]=o):o=e[1];const c=!!o;if(!t&&!c)return null;let i;e[2]!==c||e[3]!==a?(i=c&&l.jsx(Te,{icon:l.jsx(jt,{}),label:a("chat.generic.annotation.interactive")}),e[2]=c,e[3]=a,e[4]=i):i=e[4];let u;e[5]!==t?.readOnlyHint||e[6]!==a?(u=t?.readOnlyHint&&l.jsx(Te,{icon:l.jsx(bn,{}),label:a("chat.generic.annotation.readOnly")}),e[5]=t?.readOnlyHint,e[6]=a,e[7]=u):u=e[7];let r;e[8]!==t?.destructiveHint||e[9]!==a?(r=t?.destructiveHint&&l.jsx(Te,{icon:l.jsx(Pt,{}),label:a("chat.generic.annotation.destructive")}),e[8]=t?.destructiveHint,e[9]=a,e[10]=r):r=e[10];let m;e[11]!==t?.openWorldHint||e[12]!==a?(m=t?.openWorldHint&&l.jsx(Te,{icon:l.jsx(Ue,{}),label:a("chat.generic.annotation.openWorld")}),e[11]=t?.openWorldHint,e[12]=a,e[13]=m):m=e[13];let d;return e[14]!==i||e[15]!==u||e[16]!==r||e[17]!==m?(d=l.jsxs(l.Fragment,{children:[i,u,r,m]}),e[14]=i,e[15]=u,e[16]=r,e[17]=m,e[18]=d):d=e[18],d}function xa(s){return s<1?`${Math.round(s*1e3)}ms`:s<10?`${s.toFixed(1)}s`:`${Math.round(s)}s`}function ha(s){const e=$.c(13),{latency:t,outputBytes:n}=s,a=typeof t=="number"&&t>0,o=typeof n=="number"&&n>=0;if(!a&&!o)return null;let c;e[0]!==a||e[1]!==t?(c=a&&l.jsx("span",{children:xa(t)}),e[0]=a,e[1]=t,e[2]=c):c=e[2];let i;e[3]!==o||e[4]!==a?(i=a&&o&&l.jsx("span",{className:"text-muted-foreground/30",children:"·"}),e[3]=o,e[4]=a,e[5]=i):i=e[5];let u;e[6]!==o||e[7]!==n?(u=o&&l.jsx("span",{children:ea(n)}),e[6]=o,e[7]=n,e[8]=u):u=e[8];let r;return e[9]!==c||e[10]!==i||e[11]!==u?(r=l.jsxs("span",{className:"inline-flex items-center gap-1.5 text-2xs font-mono tabular-nums text-muted-foreground/60 px-1 leading-none",children:[c,i,u]}),e[9]=c,e[10]=i,e[11]=u,e[12]=r):r=e[12],r}function ba(s,e,t,n){switch(s){case"input-streaming":case"input-available":return n?n("chat.generic.preparing"):"Preparing...";case"approval-requested":return n?n("chat.generic.waitingForApproval"):"Waiting for your approval";case"output-denied":return n?n("chat.generic.cancelled"):"Cancelled";case"output-error":return t??(n?n("chat.generic.failed"):"Failed");case"output-available":{if(e==null)return n?n("chat.generic.done"):"Done";if(typeof e=="string"){const a=e.trim();return a.length>100?a.slice(0,100)+"…":a}if(typeof e=="object"){for(const a of Object.keys(e)){const o=e[a];if(typeof o=="string"&&o.trim()){const c=o.trim();return c.length>100?c.slice(0,100)+"…":c}}return""}return String(e).slice(0,100)}default:return""}}function dt(s){const e=$.c(76),{part:t,annotations:n,latency:a,outputBytes:o,isLastMessage:c,toolMeta:i}=s,u=U(),r="toolName"in t&&typeof t.toolName=="string"?t.toolName:t.type==="dynamic-tool"?u("chat.generic.dynamicTool"):t.type.replace("tool-","")||"Tool",m=$t(r),d=je(),f=nn(),{org:p}=me(),{openSidePanel:g}=un(),x=ve()?.taskId??null,{addOrReplaceEager:h}=Zn(x),{openPanel:y}=Ze(),b=i&&typeof i=="object"&&i!==null&&"connectionId"in i&&i.connectionId!=null&&i.connectionId!==""?String(i.connectionId):f?.selectedVirtualMcp?.id??null,{toolDef:N}=ta(b?r:null,b,p.id,p.slug),j=N?._meta??i,w=Mt(j),k=At(m,w),S=sa[k],v=N?.title??(S?.labelKey?u(S.labelKey):void 0)??Qs(k);let _;e[0]!==j?(_=_t(j),e[0]=j,e[1]=_):_=e[1];const T=_,M=!!T&&t.state==="output-available",P=b?`${b}:${r}`:null,L=!!n?.destructiveHint,A=M&&!!b&&!L&&!!x;let I;e[2]!==h||e[3]!==b||e[4]!==y||e[5]!==t||e[6]!==r?(I=()=>{if(!b)return;const J="input"in t&&t.input&&typeof t.input=="object"?t.input:{};h({toolName:r,appId:b,args:J}),y(cs(b,r))},e[2]=h,e[3]=b,e[4]=y,e[5]=t,e[6]=r,e[7]=I):I=e[7];const E=I;let C;e[8]!==A||e[9]!==E?(C=J=>J==="fullscreen"&&A?(E(),"fullscreen"):"inline",e[8]=A,e[9]=E,e[10]=C):C=e[10];const R=C;let D;e[11]!==d||e[12]!==g?(D=J=>{const se=fn(J.content);se.content.length>0&&(g(),d?.sendMessage(se))},e[11]=d,e[12]=g,e[13]=D):D=e[13];const B=D,H=t.state==="approval-requested"&&c===!1,G=t.state==="output-denied"||H,W=t.state==="output-available"&&typeof t.output=="object"&&t.output!=null&&"isError"in t.output&&t.output.isError===!0;let Q;e[14]!==t.state?(Q=ge(t.state),e[14]=t.state,e[15]=Q):Q=e[15];const te=Q,X=H||te==="approval"?"idle":W?"error":te;let Z,le;if(e[16]!==X||e[17]!==W||e[18]!==H||e[19]!==t||e[20]!==u||e[21]!==k){Z=t.state==="output-error"?Ee(t):void 0;const J=k==="bash"&&X==="loading"&&t.input&&typeof t.input=="object"&&typeof t.input.command=="string"?t.input.command:null;let se;e[24]!==J?(se=J!==null?da(J):null,e[24]=J,e[25]=se):se=e[25];const ne=se;let ke;e[26]!==t.input||e[27]!==ne?(ke=ne!==null?Math.min(ne,pa(t.input)):null,e[26]=t.input,e[27]=ne,e[28]=ke):ke=e[28];const nt=ke,at="toolCallId"in t?t.toolCallId:"";le=nt!==null?l.jsx(ra,{toolCallId:at,durationMs:nt,anchorMs:ut(t)}):X==="loading"?l.jsx(ca,{toolCallId:at,anchorMs:ut(t)}):H?u("chat.generic.cancelled"):W?u("chat.generic.failed"):ba(t.state,t.output,Z,u),e[16]=X,e[17]=W,e[18]=H,e[19]=t,e[20]=u,e[21]=k,e[22]=Z,e[23]=le}else Z=e[22],le=e[23];const ee=le;let V="";t.input!==void 0&&(V=`# Input
`+Ce(t.input)),t.state==="output-error"?(V&&(V=V+`

`),V=V+(`# Error
`+(Z??""))):t.output!==void 0&&!M&&(V&&(V=V+`

`),V=V+(`# Output
`+Ce(t.output)));let ae;e:{if(G){let ne;e[29]===Symbol.for("react.memo_cache_sentinel")?(ne=l.jsx(yn,{}),e[29]=ne):ne=e[29],ae=ne;break e}if(M){let ne;e[30]===Symbol.for("react.memo_cache_sentinel")?(ne=l.jsx(jt,{className:"size-4 text-muted-foreground"}),e[30]=ne):ne=e[30],ae=ne;break e}const J=S?.icon;if(J){let ne;e[31]!==J?(ne=l.jsx(J,{className:"size-4 text-muted-foreground"}),e[31]=J,e[32]=ne):ne=e[32],ae=ne;break e}let se;e[33]===Symbol.for("react.memo_cache_sentinel")?(se=l.jsx(ks,{className:"size-4 text-muted-foreground"}),e[33]=se):se=e[33],ae=se}let F;e[34]!==n||e[35]!==i?(F=l.jsx(ga,{annotations:n,toolMeta:i}),e[34]=n,e[35]=i,e[36]=F):F=e[36];let O;e[37]!==a||e[38]!==o?(O=l.jsx(ha,{latency:a,outputBytes:o}),e[37]=a,e[38]=o,e[39]=O):O=e[39];let q;e[40]!==F||e[41]!==O?(q=l.jsxs(l.Fragment,{children:[F,O]}),e[40]=F,e[41]=O,e[42]=q):q=e[42];const oe=V||null;let re;e[43]!==X||e[44]!==v||e[45]!==G||e[46]!==ee||e[47]!==q||e[48]!==oe||e[49]!==ae?(re=l.jsx(Y,{icon:ae,iconDestructive:G,trailing:q,title:v,summary:ee,state:X,detail:oe}),e[43]=X,e[44]=v,e[45]=G,e[46]=ee,e[47]=q,e[48]=oe,e[49]=ae,e[50]=re):re=e[50];let ue;e[51]!==A||e[52]!==E||e[53]!==u?(ue=A&&l.jsx("div",{className:"flex justify-end mt-1.5 mb-1",children:l.jsxs("button",{type:"button",onClick:E,className:"flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground rounded-lg [@media(hover:hover)]:hover:bg-accent [@media(hover:hover)]:hover:text-foreground transition-colors",children:[l.jsx(Ss,{className:"size-3.5"}),u("chat.generic.openInPanel")]})}),e[51]=A,e[52]=E,e[53]=u,e[54]=ue):ue=e[54];let ie;e[55]!==A||e[56]!==f||e[57]!==b||e[58]!==v||e[59]!==B||e[60]!==R||e[61]!==M||e[62]!==j||e[63]!==p.id||e[64]!==p.slug||e[65]!==t.input||e[66]!==t.output||e[67]!==P||e[68]!==u||e[69]!==k||e[70]!==T?(ie=M&&T&&b&&p?.id&&l.jsx(l.Fragment,{children:l.jsx(rs,{fallback:J=>{const{resetError:se}=J;return l.jsxs("div",{className:"mt-2 flex items-center gap-2 px-3 py-2.5 border border-dashed border-destructive/30 bg-destructive/5 rounded-lg",children:[l.jsx(Pt,{size:16,className:"shrink-0 text-destructive"}),l.jsx("span",{className:"flex-1 text-xs text-destructive font-medium",children:u("chat.generic.failedToLoad",{toolName:v})}),l.jsxs(ye,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1.5 shrink-0",onClick:se,children:[l.jsx(bt,{className:"size-3.5"}),u("chat.generic.retry")]})]})},children:l.jsx(z.Suspense,{fallback:l.jsx("div",{className:"mt-2 flex items-center justify-center h-12 border border-border/75 rounded-lg overflow-hidden p-3",children:l.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[l.jsx(is,{className:"size-4"}),l.jsx("span",{className:"text-sm",children:u("chat.generic.loadingApp")})]})}),children:l.jsx(va,{uiResourceUri:T,connectionId:b,orgId:p.id,orgSlug:p.slug,toolName:k,toolInput:t.input,toolResult:t.output,toolMeta:j,onMessage:B,onUpdateModelContext:P&&f?J=>f.setAppContext(P,J):void 0,onTeardown:P&&f?()=>f.clearAppContext(P):void 0,onRequestDisplayMode:A?R:void 0})})})}),e[55]=A,e[56]=f,e[57]=b,e[58]=v,e[59]=B,e[60]=R,e[61]=M,e[62]=j,e[63]=p.id,e[64]=p.slug,e[65]=t.input,e[66]=t.output,e[67]=P,e[68]=u,e[69]=k,e[70]=T,e[71]=ie):ie=e[71];let ce;return e[72]!==re||e[73]!==ue||e[74]!==ie?(ce=l.jsxs("div",{children:[re,ue,ie]}),e[72]=re,e[73]=ue,e[74]=ie,e[75]=ce):ce=e[75],ce}function Kt(s){return typeof s=="object"&&s!=null&&"type"in s&&s.type==="mcpToolCall"}function ya(s){if(s!=null)return Kt(s)?s.arguments??void 0:s}function ja(s){if(s==null)return;if(Kt(s)&&s.result!=null)return s.result;if(typeof s=="object"&&"content"in s&&Array.isArray(s.content)){const t=s.content;if(t.length>0&&typeof t[0]=="object"&&t[0]!=null&&"type"in t[0])return s}const e=typeof s=="string"?s:JSON.stringify(s);return{structuredContent:typeof s=="object"&&!Array.isArray(s)?s:void 0,content:[{type:"text",text:e}]}}function va(s){const e=$.c(27),{uiResourceUri:t,connectionId:n,orgId:a,orgSlug:o,toolName:c,toolInput:i,toolResult:u,toolMeta:r,onMessage:m,onUpdateModelContext:d,onTeardown:f,onRequestDisplayMode:p}=s;let g;e[0]!==n||e[1]!==a||e[2]!==o?(g={connectionId:n,orgId:a,orgSlug:o},e[0]=n,e[1]=a,e[2]=o,e[3]=g):g=e[3];const x=xn(g);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={type:"object"},e[4]=h):h=e[4];let y;e[5]!==r?(y=r!=null&&{_meta:r},e[5]=r,e[6]=y):y=e[6];let b;e[7]!==y||e[8]!==c?(b={name:c,inputSchema:h,...y},e[7]=y,e[8]=c,e[9]=b):b=e[9];const N=b;let j;e[10]!==N?(j={tool:N},e[10]=N,e[11]=j):j=e[11];let w;e[12]!==i?(w=ya(i),e[12]=i,e[13]=w):w=e[13];let k;e[14]!==u?(k=ja(u),e[14]=u,e[15]=k):k=e[15];let S;return e[16]!==x||e[17]!==m||e[18]!==p||e[19]!==f||e[20]!==d||e[21]!==a||e[22]!==j||e[23]!==w||e[24]!==k||e[25]!==t?(S=l.jsx("div",{className:"mt-2 border border-border/75 rounded-lg overflow-hidden p-3",children:l.jsx(mn,{resourceURI:t,orgId:a,toolInfo:j,toolInput:w,toolResult:k,client:x,onMessage:m,onUpdateModelContext:d,onTeardown:f,onRequestDisplayMode:p})}),e[16]=x,e[17]=m,e[18]=p,e[19]=f,e[20]=d,e[21]=a,e[22]=j,e[23]=w,e[24]=k,e[25]=t,e[26]=S):S=e[26],S}const ft="studio-storage://",mt="mesh-storage://";function tt(s){return s.startsWith(ft)?s.slice(ft.length):s.startsWith(mt)?s.slice(mt.length):null}function qt(s,e){const t=tt(s);return t!==null?`/api/${e}/files/${t}`:s}function Gt(s){const e=$.c(7),{srcs:t,alt:n}=s;let a;if(e[0]!==n||e[1]!==t){let c;e[3]!==n?(c=i=>l.jsx(Sn,{src:i,alt:n,children:l.jsx("img",{src:i,alt:n,className:"max-w-sm max-h-80 object-contain rounded-lg border border-border hover:border-foreground/20 transition-colors"})},i),e[3]=n,e[4]=c):c=e[4],a=t.map(c),e[0]=n,e[1]=t,e[2]=a}else a=e[2];let o;return e[5]!==a?(o=l.jsx("div",{className:"flex flex-wrap gap-2",children:a}),e[5]=a,e[6]=o):o=e[6],o}const Sa=Oe({image_url:us({protocol:/^https$/})});function ka(s){if(typeof s!="string")return null;try{const e=Sa.safeParse(JSON.parse(s.split(`
`,1)[0]??""));return e.success?e.data.image_url:null}catch{return null}}function Na(s){return Array.isArray(s?.images)?s.images:void 0}function wa(s){if(!s?.usage)return null;const e=s.usage.inputTokens??0,t=s.usage.outputTokens??0,n=e+t;return n?{inputTokens:e,outputTokens:t,reasoningTokens:0,totalTokens:n,cost:0,cacheReadTokens:0,cacheWriteTokens:0}:null}function _a(s){const e=$.c(14),{uri:t,orgSlug:n}=s,a=U();let o;e[0]!==n||e[1]!==t?(o=qt(t,n),e[0]=n,e[1]=t,e[2]=o):o=e[2];const c=o;let i;e[3]!==a||e[4]!==t?(i=tt(t)!==null?t.slice(t.lastIndexOf("/")+1):a("chat.generateImage.reference"),e[3]=a,e[4]=t,e[5]=i):i=e[5];const u=i;let r;e[6]!==u?(r=l.jsx(Tt,{asChild:!0,children:l.jsx("span",{className:"inline-flex items-center gap-1 px-1 py-0.5 rounded bg-muted text-muted-foreground text-xs cursor-default select-none",children:u})}),e[6]=u,e[7]=r):r=e[7];let m;e[8]!==u||e[9]!==c?(m=l.jsx(Ct,{side:"top",className:"max-w-sm p-1.5",children:l.jsx("img",{src:c,alt:u,className:"max-w-full max-h-64 object-contain rounded"})}),e[8]=u,e[9]=c,e[10]=m):m=e[10];let d;return e[11]!==r||e[12]!==m?(d=l.jsxs(It,{children:[r,m]}),e[11]=r,e[12]=m,e[13]=d):d=e[13],d}function Ta(s){const e=$.c(64),{part:t,latency:n}=s,a=U(),o=yt();let c;e[0]!==t.state?(c=ge(t.state),e[0]=t.state,e[1]=c):c=e[1];const i=c,u=t.input,r=t.output,m=Na(r);let d;e[2]!==r?(d=wa(r),e[2]=r,e[3]=d):d=e[3];const f=d,g=Et()?r?.model:void 0,x=Array.isArray(u?.referenceImages)?u.referenceImages.filter(Ca):void 0;let h;e[4]!==n?(h=n!=null&&n>0?l.jsx("span",{className:"text-2xs font-mono tabular-nums text-muted-foreground/60",children:be(n)}):null,e[4]=n,e[5]=h):h=e[5];const y=h;if(i==="loading"){let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=l.jsx(_e,{size:14}),e[6]=I):I=e[6];let E;e[7]!==a?(E=a("chat.generateImage.generatingImage"),e[7]=a,e[8]=E):E=e[8];let C;e[9]!==u?(C=u?.prompt?`"${u.prompt.slice(0,80)}…"`:void 0,e[9]=u,e[10]=C):C=e[10];let R;return e[11]!==E||e[12]!==C?(R=l.jsx(Y,{icon:I,title:E,summary:C,state:"loading"}),e[11]=E,e[12]=C,e[13]=R):R=e[13],R}if(r?.background){let I;e[14]===Symbol.for("react.memo_cache_sentinel")?(I=l.jsx(_e,{size:14}),e[14]=I):I=e[14];let E;e[15]!==a?(E=a("chat.generateImage.imageQueuedGeneratingInBackground"),e[15]=a,e[16]=E):E=e[16];let C;e[17]!==u?(C=u?.prompt?`"${u.prompt.slice(0,80)}…"`:void 0,e[17]=u,e[18]=C):C=e[18];let R;return e[19]!==E||e[20]!==C?(R=l.jsx(Y,{icon:I,title:E,summary:C,state:"idle"}),e[19]=E,e[20]=C,e[21]=R):R=e[21],R}if(i==="error"||!m||m.length===0){let I;e[22]!==t||e[23]!==i?(I=i==="error"?Ee(t):void 0,e[22]=t,e[23]=i,e[24]=I):I=e[24];const E=I;let C="";u!==void 0&&(C=`# Input
`+Ce(u)),E?(C&&(C=C+`

`),C=C+(`# Error
`+E)):r!==void 0&&(C&&(C=C+`

`),C=C+(`# Output
`+Ce(r)));let R;e[25]===Symbol.for("react.memo_cache_sentinel")?(R=l.jsx(_e,{size:14}),e[25]=R):R=e[25];let D;e[26]!==a?(D=a("chat.generateImage.imageGeneration"),e[26]=a,e[27]=D):D=e[27];let B;e[28]!==i||e[29]!==a?(B=a(i==="error"?"chat.generateImage.failed":"chat.generateImage.noImagesGenerated"),e[28]=i,e[29]=a,e[30]=B):B=e[30];const H=i==="error"?"error":"idle",G=C||null;let W;return e[31]!==y||e[32]!==D||e[33]!==B||e[34]!==H||e[35]!==G||e[36]!==f?(W=l.jsx(Y,{icon:R,title:D,summary:B,state:H,usage:f,trailing:y,detail:G}),e[31]=y,e[32]=D,e[33]=B,e[34]=H,e[35]=G,e[36]=f,e[37]=W):W=e[37],W}const b="flex flex-col gap-2";let N;e[38]===Symbol.for("react.memo_cache_sentinel")?(N=l.jsx(_e,{size:14,className:"text-special"}),e[38]=N):N=e[38];let j;e[39]!==a?(j=a("chat.generateImage.generatedImage"),e[39]=a,e[40]=j):j=e[40];let w;e[41]!==u?(w=u?.prompt&&l.jsx("p",{className:"text-xs text-muted-foreground/70 whitespace-pre-wrap wrap-break-word",children:u.prompt}),e[41]=u,e[42]=w):w=e[42];const k=x&&x.length>0&&l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[l.jsx("span",{className:"text-2xs text-muted-foreground/50",children:a("chat.generateImage.references")}),x.map((I,E)=>{const C=I.uri??I.url;return l.jsx(_a,{uri:C,orgSlug:o.slug},E)})]});let S;e[43]!==w||e[44]!==k?(S=l.jsxs("div",{className:"flex flex-col gap-1 pb-2 pl-6",children:[w,k]}),e[43]=w,e[44]=k,e[45]=S):S=e[45];let v;e[46]!==y||e[47]!==g||e[48]!==j||e[49]!==S||e[50]!==f?(v=l.jsx(Y,{icon:N,title:j,summary:g,state:"idle",usage:f,trailing:y,children:S}),e[46]=y,e[47]=g,e[48]=j,e[49]=S,e[50]=f,e[51]=v):v=e[51];const _=Gt;let T;e[52]!==o?(T=I=>{const E=I.uri??I.url;return E?[qt(E,o.slug)]:[]},e[52]=o,e[53]=T):T=e[53];const M=m.flatMap(T);let P;e[54]!==u?.prompt||e[55]!==a?(P=u?.prompt??a("chat.generateImage.generatedImageAlt"),e[54]=u?.prompt,e[55]=a,e[56]=P):P=e[56];let L;e[57]!==_||e[58]!==M||e[59]!==P?(L=l.jsx(_,{srcs:M,alt:P}),e[57]=_,e[58]=M,e[59]=P,e[60]=L):L=e[60];let A;return e[61]!==v||e[62]!==L?(A=l.jsxs("div",{className:b,children:[v,L]}),e[61]=v,e[62]=L,e[63]=A):A=e[63],A}function Ca(s){return s.uri??s.url}function Ia(s,e){const t=tt(s);return t!==null?`/api/${e}/files/${t}`:s}function $a(s){if(!s?.usage)return null;const e=s.usage.inputTokens??0,t=s.usage.outputTokens??0,n=e+t;if(!n)return null;const a={providerMetadata:s.usage.providerMetadata};return{inputTokens:e,outputTokens:t,reasoningTokens:0,totalTokens:n,cost:an(a),cacheReadTokens:0,cacheWriteTokens:0}}function Ma(s){try{return new URL(s).hostname.replace(/^www\./,"")}catch{return s}}function Aa(s){try{return`${new URL(s).origin}/favicon.ico`}catch{return""}}function Pa(s){const e=$.c(16),{citation:t,index:n}=s;let a;e[0]!==t.url?(a=Ma(t.url),e[0]=t.url,e[1]=a):a=e[1];const o=a;let c;e[2]!==t.url?(c=Aa(t.url),e[2]=t.url,e[3]=c):c=e[3];const i=c,u=t.title||o;let r;e[4]!==i?(r=l.jsx("img",{src:i,alt:"",className:"size-3.5 rounded-sm shrink-0",onError:Ea}),e[4]=i,e[5]=r):r=e[5];let m;e[6]!==u?(m=l.jsx("span",{className:"truncate max-w-[180px]",children:u}),e[6]=u,e[7]=m):m=e[7];const d=n+1;let f;e[8]!==d?(f=l.jsxs("span",{className:"text-2xs text-muted-foreground/50 tabular-nums shrink-0",children:["[",d,"]"]}),e[8]=d,e[9]=f):f=e[9];let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=l.jsx(ds,{size:10,className:"shrink-0 opacity-0 group-hover/src:opacity-100 transition-opacity"}),e[10]=p):p=e[10];let g;return e[11]!==t.url||e[12]!==r||e[13]!==m||e[14]!==f?(g=l.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"group/src inline-flex items-center gap-1.5 rounded-md border border-border/50 bg-muted/30 px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:border-border hover:text-foreground",children:[r,m,f,p]}),e[11]=t.url,e[12]=r,e[13]=m,e[14]=f,e[15]=g):g=e[15],g}function Ea(s){s.target.style.display="none"}function La(s,e){return s.replace(/\[(\d+)\]/g,(t,n)=>{const a=parseInt(n,10)-1,o=e[a];return o?`[\\[${n}\\]](${o.url})`:t})}const ze=5;function Ra(s){const e=$.c(13),{citations:t}=s,n=U(),[a,o]=z.useState(!1),c=t.length>ze;let i;e[0]!==t||e[1]!==a?(i=a?t:t.slice(0,ze),e[0]=t,e[1]=a,e[2]=i):i=e[2];const u=i;let r;e[3]!==u?(r=u.map(Fa),e[3]=u,e[4]=r):r=e[4];let m;e[5]!==t.length||e[6]!==a||e[7]!==c||e[8]!==n?(m=c&&l.jsx("button",{type:"button",onClick:()=>o(za),className:"inline-flex items-center rounded-lg border border-border/50 bg-muted/30 px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:border-border hover:text-foreground",children:a?n("chat.webSearch.showLess"):n("chat.webSearch.showMore",{count:t.length-ze})}),e[5]=t.length,e[6]=a,e[7]=c,e[8]=n,e[9]=m):m=e[9];let d;return e[10]!==r||e[11]!==m?(d=l.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[r,m]}),e[10]=r,e[11]=m,e[12]=d):d=e[12],d}function za(s){return!s}function Fa(s,e){return l.jsx(Pa,{citation:s,index:e},s.url)}function Da(s){const e=$.c(61),{part:t,latency:n,streamingText:a}=s,o=U(),c=yt();let i;e[0]!==t.state?(i=ge(t.state),e[0]=t.state,e[1]=i):i=e[1];const u=i,r=t.input,m=t.output;let d,f,p;e[2]!==c||e[3]!==m?(d=m?.uri?Ia(m.uri,c.slug):void 0,p=ht,f=pe.webSearchBlob(d??""),e[2]=c,e[3]=m,e[4]=d,e[5]=f,e[6]=p):(d=e[4],f=e[5],p=e[6]);let g;e[7]!==d?(g=async()=>{const Q=await fetch(d);if(!Q.ok)throw new Error(`Failed to fetch: ${Q.status}`);return Q.text()},e[7]=d,e[8]=g):g=e[8];const x=!!d;let h;e[9]!==f||e[10]!==g||e[11]!==x?(h={queryKey:f,queryFn:g,enabled:x,staleTime:1/0},e[9]=f,e[10]=g,e[11]=x,e[12]=h):h=e[12];const{data:y}=p(h),b=u==="loading",N=u!=="loading"&&u!=="error",j=Et(),w=m?.citations;let k;e[13]!==m?(k=$a(m),e[13]=m,e[14]=k):k=e[14];const S=k,v=m?.content??y??a;let _;e[15]!==w||e[16]!==v?(_=v&&w?.length?La(v,w):v,e[15]=w,e[16]=v,e[17]=_):_=e[17];const T=_;let M;e[18]!==n?(M=n!=null&&n>0?l.jsx("span",{className:"text-2xs font-mono tabular-nums text-muted-foreground/60",children:be(n)}):null,e[18]=n,e[19]=M):M=e[19];const P=M;if(u==="error"){let Q;e[20]===Symbol.for("react.memo_cache_sentinel")?(Q=l.jsx(Ue,{size:14}),e[20]=Q):Q=e[20];let te;e[21]!==o?(te=o("chat.webSearch.title"),e[21]=o,e[22]=te):te=e[22];let X;e[23]!==o?(X=o("chat.webSearch.failed"),e[23]=o,e[24]=X):X=e[24];let Z;return e[25]!==P||e[26]!==te||e[27]!==X||e[28]!==S?(Z=l.jsx(Y,{icon:Q,title:te,summary:X,state:"error",usage:S,trailing:P}),e[25]=P,e[26]=te,e[27]=X,e[28]=S,e[29]=Z):Z=e[29],Z}const L=b?"animate-pulse":"text-brand-blue";let A;e[30]!==L?(A=K(L),e[30]=L,e[31]=A):A=e[31];let I;e[32]!==A?(I=l.jsx(Ue,{size:14,className:A}),e[32]=A,e[33]=I):I=e[33];let E;e[34]!==b||e[35]!==o?(E=o(b?"chat.webSearch.researching":"chat.webSearch.title"),e[34]=b,e[35]=o,e[36]=E):E=e[36];let C;e[37]!==r||e[38]!==N||e[39]!==m?.model||e[40]!==j?(C=N?(j?m?.model:void 0)??r?.query?.slice(0,60):r?.query?`"${r.query.slice(0,80)}"`:void 0,e[37]=r,e[38]=N,e[39]=m?.model,e[40]=j,e[41]=C):C=e[41];const R=b?"loading":"idle";let D;e[42]!==r?(D=r?.query&&l.jsx("p",{className:"text-xs text-muted-foreground/70 whitespace-pre-wrap wrap-break-word",children:r.query}),e[42]=r,e[43]=D):D=e[43];let B;e[44]!==T||e[45]!==t.toolCallId?(B=T?l.jsx("div",{className:"max-h-96 overflow-y-auto overflow-x-hidden rounded-lg border border-border/40 bg-muted/20 px-4 py-3 min-w-0",children:l.jsx("div",{className:"prose prose-sm prose-neutral dark:prose-invert max-w-none text-sm leading-relaxed break-words",children:l.jsx(Lt,{id:t.toolCallId,text:T})})}):l.jsx("div",{className:"rounded-lg border border-border/40 bg-muted/20 px-4 py-3",children:l.jsxs("div",{className:"space-y-2 animate-pulse",children:[l.jsx("div",{className:"h-3 rounded bg-muted-foreground/10 w-3/4"}),l.jsx("div",{className:"h-3 rounded bg-muted-foreground/10 w-1/2"})]})}),e[44]=T,e[45]=t.toolCallId,e[46]=B):B=e[46];let H;e[47]!==w?(H=w&&w.length>0&&l.jsx(Ra,{citations:w}),e[47]=w,e[48]=H):H=e[48];let G;e[49]!==D||e[50]!==B||e[51]!==H?(G=l.jsxs("div",{className:"pl-6 pb-3 flex flex-col gap-1 min-w-0",children:[D,B,H]}),e[49]=D,e[50]=B,e[51]=H,e[52]=G):G=e[52];let W;return e[53]!==P||e[54]!==I||e[55]!==E||e[56]!==C||e[57]!==R||e[58]!==G||e[59]!==S?(W=l.jsx(Y,{icon:I,title:E,summary:C,state:R,usage:S,trailing:P,defaultOpen:!0,children:G}),e[53]=P,e[54]=I,e[55]=E,e[56]=C,e[57]=R,e[58]=G,e[59]=S,e[60]=W):W=e[60],W}function Oa(s){const e=$.c(16),{part:t}=s,n=U();if(!t.state.startsWith("output-"))return null;let a;e[0]!==t.input?.prompt||e[1]!==n?(a=t.input?.prompt?.trim()||n("chat.userAskQuestion.question"),e[0]=t.input?.prompt,e[1]=n,e[2]=a):a=e[2];const o=a,c=t.state==="output-error"||t.state==="output-denied",i=t.state==="output-denied";let u;e[3]!==i||e[4]!==t||e[5]!==n?(u=i?n("chat.userAskQuestion.skippedAnswer"):t.state==="output-error"?Ee(t)??n("chat.subtask.errorLabel"):t.output?.response??"",e[3]=i,e[4]=t,e[5]=n,e[6]=u):u=e[6];const r=u;let m;e[7]===Symbol.for("react.memo_cache_sentinel")?(m=l.jsx(Ns,{className:"size-4 text-muted-foreground/50 shrink-0 mt-0.5"}),e[7]=m):m=e[7];let d;e[8]!==o?(d=l.jsxs("div",{className:"flex items-start gap-2",children:[m,l.jsx("span",{className:"text-sm text-muted-foreground leading-snug",children:o})]}),e[8]=o,e[9]=d):d=e[9];let f;e[10]!==r||e[11]!==c?(f=r&&l.jsx("div",{className:"ml-6 pl-2 border-l border-border/50",children:l.jsx("span",{className:K("text-sm leading-snug",c?"text-muted-foreground/50 italic":"text-foreground/70"),children:r})}),e[10]=r,e[11]=c,e[12]=f):f=e[12];let p;return e[13]!==d||e[14]!==f?(p=l.jsxs("div",{className:"my-1.5 flex flex-col gap-1",children:[d,f]}),e[13]=d,e[14]=f,e[15]=p):p=e[15],p}function Ba(s){const e=$.c(14),{part:t}=s,n=U();if(!t.state.startsWith("output-")||Ls(t))return null;const a=t.output?.accepted===!0;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l.jsx(Nt,{className:"size-4 text-muted-foreground/50 shrink-0 mt-0.5"}),e[0]=o):o=e[0];const c=t.input?.title;let i;e[1]!==c?(i=l.jsx("span",{className:"text-sm leading-snug text-muted-foreground",children:c}),e[1]=c,e[2]=i):i=e[2];const u=a?"text-foreground/70":"text-muted-foreground/50 italic";let r;e[3]!==u?(r=K("text-sm leading-snug shrink-0",u),e[3]=u,e[4]=r):r=e[4];let m;e[5]!==a||e[6]!==n?(m=n(a?"chat.suggestTask.accepted":"chat.suggestTask.declined"),e[5]=a,e[6]=n,e[7]=m):m=e[7];let d;e[8]!==r||e[9]!==m?(d=l.jsx("span",{className:r,children:m}),e[8]=r,e[9]=m,e[10]=d):d=e[10];let f;return e[11]!==i||e[12]!==d?(f=l.jsxs("div",{className:"my-1.5 flex items-start gap-2",children:[o,i,d]}),e[11]=i,e[12]=d,e[13]=f):f=e[13],f}const Wt=z.createContext(new Map);function Lo(s){const e=$.c(5),{messages:t,children:n}=s;let a;if(e[0]!==t){a=new Map;for(const c of t){const i=c.metadata?.subtaskJobId;if(!i)continue;const u=a.get(i);u?u.push(c):a.set(i,[c])}e[0]=t,e[1]=a}else a=e[1];let o;return e[2]!==a||e[3]!==n?(o=l.jsx(Wt.Provider,{value:a,children:n}),e[2]=a,e[3]=n,e[4]=o):o=e[4],o}function Ua(s){const e=$.c(3),t=z.useContext(Wt);let n;return e[0]!==s||e[1]!==t?(n=s?t.get(s)??[]:[],e[0]=s,e[1]=t,e[2]=n):n=e[2],n}function Ha(s){return new ReadableStream({async start(e){const t=s.getReader(),n=new TextDecoder;let a="";try{for(;;){const{done:o,value:c}=await t.read();if(o)break;a+=n.decode(c,{stream:!0});let i;for(;(i=a.indexOf(`

`))!==-1;){const u=a.slice(0,i);a=a.slice(i+2);const r=u.split(`
`).filter(m=>m.startsWith("data:")).map(m=>m.slice(5).trim()).join(`
`);if(r)try{e.enqueue(JSON.parse(r))}catch{}}}}finally{t.releaseLock(),e.close()}}})}function Ka(s){const{orgSlug:e,threadId:t,jobId:n,enabled:a}=s,[o,c]=z.useState([]),[i,u]=z.useState(!1);return z.useEffect(()=>{if(!a||!n||!t)return;const r=new AbortController;return c([]),u(!0),(async()=>{try{const m=await fetch(`/api/${encodeURIComponent(e)}/decopilot/threads/${encodeURIComponent(t)}/jobs/${encodeURIComponent(n)}/stream`,{headers:{accept:"text/event-stream"},credentials:"include",signal:r.signal});if(!m.ok||!m.body)return;for await(const d of tn({stream:sn(Ha(m.body),void 0)})){if(r.signal.aborted)return;c([d])}}catch{}finally{r.signal.aborted||u(!1)}})(),()=>r.abort()},[a,n,t,e]),{messages:o,streaming:i}}function qa(s,e){if(s&&typeof s=="object"&&!Array.isArray(s)){const t=s;if(typeof t.text=="string"||typeof t.error=="string"||typeof t.finishReason=="string"){if(typeof t.error=="string"&&t.error.length>0)return e("chat.subtask.failedWithError",{error:t.error});const a=typeof t.text=="string"?t.text.trim():"",o=t.finishReason==="length";return a?(o?`${e("chat.subtask.stepLimitPartial")}

`:"")+a:e(o?"chat.subtask.stepLimitNoOutput":"chat.subtask.completedNoOutput")}}return ma(s)}function Vt(s){return!!s&&typeof s=="object"&&s.background===!0}function Jt({part:s,subtaskMeta:e},t){const n=s.state==="input-streaming"||s.state==="input-available",a=s.state==="output-available"&&s.preliminary===!0,o=s.state==="output-available"&&!s.preliminary,c=s.state==="output-error",i=ge(s.state,"preliminary"in s?s.preliminary:!1),u=i==="approval"?"idle":i,r=t(n?"chat.subtask.startingEllipsis":a?"chat.subtask.runningEllipsis":o?"chat.subtask.completedTitle":c?"chat.subtask.failedTitle":"chat.subtask.subtaskNoun"),m=s.input?.prompt??"",d=s.state==="approval-requested"?t("chat.subtask.awaitingApproval"):m.length>120?m.slice(0,120)+"…":m;return{fallbackTitle:r,summary:d,usage:e?.usage,state:u}}function Qt(s){return s.state==="input-available"?!0:s.state==="output-available"?"preliminary"in s&&s.preliminary===!0:!1}function Xt(s){const e=$.c(4),t=ve()?.taskId??null,{org:n}=me();if(!t)return null;let a;return e[0]!==n||e[1]!==t||e[2]!==s?(a=async()=>{if(t===null)return;const o=await fetch(`/api/${encodeURIComponent(n.slug)}/decopilot/flip/${encodeURIComponent(t)}`,{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({toolCallId:s})});if(!o.ok)throw new Error(`flip failed: ${o.status}`)},e[0]=n,e[1]=t,e[2]=s,e[3]=a):a=e[3],a}function Ga(s){const e=$.c(10),{onFlip:t}=s,n=U(),[a,o]=z.useState(!1);let c;e[0]!==t?(c=async m=>{m.stopPropagation(),o(!0);try{await t()}catch{o(!1)}},e[0]=t,e[1]=c):c=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=K("shrink-0 text-xs text-muted-foreground/70 px-2 py-1 rounded-lg transition-colors","[@media(hover:hover)]:hover:text-foreground [@media(hover:hover)]:hover:bg-accent","disabled:opacity-50"),e[2]=i):i=e[2];let u;e[3]!==a||e[4]!==n?(u=n(a?"chat.subtask.flipping":"chat.subtask.flipToBackground"),e[3]=a,e[4]=n,e[5]=u):u=e[5];let r;return e[6]!==a||e[7]!==c||e[8]!==u?(r=l.jsx("button",{type:"button",disabled:a,onClick:c,className:i,children:u}),e[6]=a,e[7]=c,e[8]=u,e[9]=r):r=e[9],r}function st(s){const e=$.c(54),{icon:t,title:n,summary:a,state:o,usage:c,latency:i,onOpenChange:u,onFlip:r,children:m}=s,[d,f]=z.useState(!1);let p;e[0]!==u?(p=W=>{f(W),u?.(W)},e[0]=u,e[1]=p):p=e[1];const g=p,x=o==="loading",h=o==="error";let y;e[2]!==g?(y=()=>g(!0),e[2]=g,e[3]=y):y=e[3];let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b=K("group/tool flex items-center gap-2 flex-1 min-w-0 py-2.5 text-left rounded-lg transition-colors","[@media(hover:hover)]:hover:bg-accent"),e[4]=b):b=e[4];const N=h?"[&>svg]:text-warning/70":"[&>svg]:text-muted-foreground/75";let j;e[5]!==N?(j=K("relative shrink-0 size-4 flex items-center justify-center [&>svg]:size-4",N),e[5]=N,e[6]=j):j=e[6];let w;e[7]!==t||e[8]!==j?(w=l.jsx("div",{className:j,children:t}),e[7]=t,e[8]=j,e[9]=w):w=e[9];const k=h?"text-warning/80":"text-foreground",S=x&&"shimmer";let v;e[10]!==k||e[11]!==S?(v=K("shrink-0 text-sm font-normal",k,S),e[10]=k,e[11]=S,e[12]=v):v=e[12];let _;e[13]!==v||e[14]!==n?(_=l.jsx("span",{className:v,children:n}),e[13]=v,e[14]=n,e[15]=_):_=e[15];let T;e[16]!==x||e[17]!==a?(T=a?l.jsx("span",{className:"min-w-0 flex-1 truncate",children:l.jsx("span",{className:"text-xs text-muted-foreground/60 bg-muted/50 rounded-[3px] px-1 py-px leading-none",children:l.jsx("span",{className:K(x&&"shimmer"),children:a})})}):l.jsx("div",{className:"flex-1"}),e[16]=x,e[17]=a,e[18]=T):T=e[18];let M;e[19]===Symbol.for("react.memo_cache_sentinel")?(M=l.jsx(fs,{className:"size-3.5 shrink-0 text-muted-foreground/40 opacity-0 transition-opacity [@media(hover:hover)]:group-hover/tool:opacity-100"}),e[19]=M):M=e[19];let P;e[20]!==i?(P=l.jsx(fe,{latency:i}),e[20]=i,e[21]=P):P=e[21];let L;e[22]!==c?(L=l.jsx(kt,{usage:c}),e[22]=c,e[23]=L):L=e[23];let A;e[24]!==_||e[25]!==T||e[26]!==P||e[27]!==L||e[28]!==y||e[29]!==w?(A=l.jsxs("button",{type:"button",onClick:y,className:b,children:[w,_,T,M,P,L]}),e[24]=_,e[25]=T,e[26]=P,e[27]=L,e[28]=y,e[29]=w,e[30]=A):A=e[30];let I;e[31]!==x||e[32]!==r?(I=r&&x?l.jsx(Ga,{onFlip:r}):null,e[31]=x,e[32]=r,e[33]=I):I=e[33];let E;e[34]!==A||e[35]!==I?(E=l.jsxs("div",{className:"flex items-center gap-1 w-full",children:[A,I]}),e[34]=A,e[35]=I,e[36]=E):E=e[36];let C;e[37]!==t?(C=l.jsx("span",{className:"flex items-center [&>svg]:size-4 [&>svg]:text-muted-foreground/75",children:t}),e[37]=t,e[38]=C):C=e[38];let R;e[39]!==C||e[40]!==n?(R=l.jsx(kn,{className:"px-4 py-3 border-b border-border shrink-0",children:l.jsxs(Nn,{className:"flex items-center gap-2 text-sm font-medium",children:[C,n]})}),e[39]=C,e[40]=n,e[41]=R):R=e[41];let D;e[42]!==m?(D=l.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-4",children:m}),e[42]=m,e[43]=D):D=e[43];let B;e[44]!==R||e[45]!==D?(B=l.jsxs(wn,{side:"right",className:"w-full sm:max-w-2xl flex flex-col p-0 gap-0",children:[R,D]}),e[44]=R,e[45]=D,e[46]=B):B=e[46];let H;e[47]!==d||e[48]!==g||e[49]!==B?(H=l.jsx(_n,{open:d,onOpenChange:g,children:B}),e[47]=d,e[48]=g,e[49]=B,e[50]=H):H=e[50];let G;return e[51]!==E||e[52]!==H?(G=l.jsxs(l.Fragment,{children:[E,H]}),e[51]=E,e[52]=H,e[53]=G):G=e[53],G}function Yt(s){const e=$.c(22),{part:t}=s,n=U(),a=t.state==="output-error";let o;e[0]!==t.input?.prompt||e[1]!==n?(o=t.input?.prompt??n("chat.subtask.noPromptProvided"),e[0]=t.input?.prompt,e[1]=n,e[2]=o):o=e[2];const c=o;let i;if(e[3]!==a||e[4]!==t||e[5]!==c||e[6]!==n){const u=a?Ee(t):qa(t.output,n)??"";let r;e[8]!==n?(r=n("chat.subtask.taskLabel"),e[8]=n,e[9]=r):r=e[9];let m;e[10]!==r?(m=l.jsx("h3",{className:"text-xs font-medium text-muted-foreground/70 mb-1.5",children:r}),e[10]=r,e[11]=m):m=e[11];let d;e[12]!==c?(d=l.jsx("p",{className:"text-sm text-foreground/90 whitespace-pre-wrap wrap-break-word",children:c}),e[12]=c,e[13]=d):d=e[13];let f;e[14]!==m||e[15]!==d?(f=l.jsxs("section",{children:[m,d]}),e[14]=m,e[15]=d,e[16]=f):f=e[16];let p;e[17]!==a||e[18]!==n?(p=n(a?"chat.subtask.errorLabel":"chat.subtask.resultLabel"),e[17]=a,e[18]=n,e[19]=p):p=e[19];let g;e[20]!==p?(g=l.jsx("h3",{className:"text-xs font-medium text-muted-foreground/70 mb-1.5",children:p}),e[20]=p,e[21]=g):g=e[21],i=l.jsxs("div",{className:"flex flex-col gap-4",children:[f,l.jsxs("section",{children:[g,u.trim()?l.jsx(Lt,{id:`${t.toolCallId}-result`,text:u}):l.jsx("p",{className:"text-sm text-muted-foreground/60 italic",children:n("chat.subtask.running")})]})]}),e[3]=a,e[4]=t,e[5]=c,e[6]=n,e[7]=i}else i=e[7];return i}const Fe=600;function Wa(s){const e=$.c(12),{part:t}=s,n=t.type??"";let a;e[0]!==t.toolName||e[1]!==n?(a=n==="dynamic-tool"?t.toolName??"tool":n.slice(5),e[0]=t.toolName,e[1]=n,e[2]=a):a=e[2];const o=a;let c;if(e[3]!==t.input){const f=t.input!=null?JSON.stringify(t.input):"";c=f.length>80?`${f.slice(0,80)}…`:f||void 0,e[3]=t.input,e[4]=c}else c=e[4];const i=c;let u;if(e[5]!==t.input){const f=t.input!=null?JSON.stringify(t.input,null,2):null;u=f&&f.length>Fe?`${f.slice(0,Fe)}
… (${f.length-Fe} more characters)`:f,e[5]=t.input,e[6]=u}else u=e[6];const r=u;let m;e[7]===Symbol.for("react.memo_cache_sentinel")?(m=l.jsx(vt,{}),e[7]=m):m=e[7];let d;return e[8]!==r||e[9]!==o||e[10]!==i?(d=l.jsx(Y,{icon:m,title:o,summary:i,state:"idle",detail:r,detailVariant:"code"}),e[8]=r,e[9]=o,e[10]=i,e[11]=d):d=e[11],d}function Va(s){const e=$.c(19),{jobId:t,prompt:n,items:a,streaming:o}=s,c=U();let i;e[0]!==c?(i=c("chat.subtask.taskLabel"),e[0]=c,e[1]=i):i=e[1];let u;e[2]!==i?(u=l.jsx("h3",{className:"text-xs font-medium text-muted-foreground/70 mb-1.5",children:i}),e[2]=i,e[3]=u):u=e[3];let r;e[4]!==n?(r=l.jsx("p",{className:"text-sm text-foreground/90 whitespace-pre-wrap wrap-break-word",children:n}),e[4]=n,e[5]=r):r=e[5];let m;e[6]!==u||e[7]!==r?(m=l.jsxs("section",{children:[u,r]}),e[6]=u,e[7]=r,e[8]=m):m=e[8];let d;e[9]!==a||e[10]!==t||e[11]!==o||e[12]!==c?(d=a.length===0?l.jsx("p",{className:"text-sm text-muted-foreground/60 italic py-1",children:c("chat.subtask.runningInBackground")}):a.map((g,x)=>{const h=g,y=h.type??"";return y==="text"?h.text?.trim()?l.jsx($e,{id:`${t}-sub-${x}`,part:g,animate:o},`${t}-sub-${x}`):null:y==="dynamic-tool"||y.startsWith("tool-")&&y!=="tool-todo_write"&&y!=="tool-update_interests"?l.jsx(Wa,{part:h},`${t}-sub-${x}`):null}),e[9]=a,e[10]=t,e[11]=o,e[12]=c,e[13]=d):d=e[13];let f;e[14]!==d?(f=l.jsx("section",{className:"flex flex-col gap-3 sm:gap-2",children:d}),e[14]=d,e[15]=f):f=e[15];let p;return e[16]!==m||e[17]!==f?(p=l.jsxs("div",{className:"flex flex-col gap-4",children:[m,f]}),e[16]=m,e[17]=f,e[18]=p):p=e[18],p}function Zt(s){const e=$.c(32),{part:t}=s,n=U(),a=t.output?.jobId,o=ve()?.taskId??null,{org:c}=me(),[i,u]=z.useState(!1),r=Ua(a),m=o??"",d=i&&!!o;let f;e[0]!==a||e[1]!==c.slug||e[2]!==m||e[3]!==d?(f={orgSlug:c.slug,threadId:m,jobId:a,enabled:d},e[0]=a,e[1]=c.slug,e[2]=m,e[3]=d,e[4]=f):f=e[4];const p=Ka(f);let g;e[5]!==p.messages?(g=p.messages.flatMap(Qa),e[5]=p.messages,e[6]=g):g=e[6];const x=g;let h;e[7]!==r?(h=r.flatMap(Ja),e[7]=r,e[8]=h):h=e[8];const y=h,b=x.length>0?x:y;let N;e[9]!==t.input?.prompt||e[10]!==n?(N=t.input?.prompt??n("chat.subtask.noPromptProvided"),e[9]=t.input?.prompt,e[10]=n,e[11]=N):N=e[11];const j=N;let w;e[12]!==j?(w=j.length>120?`${j.slice(0,120)}…`:j,e[12]=j,e[13]=w):w=e[13];const k=w,S=r.length===0;let v;e[14]!==n?(v=n("chat.subtask.subtaskNoun"),e[14]=n,e[15]=v):v=e[15];let _;e[16]===Symbol.for("react.memo_cache_sentinel")?(_=l.jsx(Je,{}),e[16]=_):_=e[16];let T;e[17]!==v?(T=l.jsx(Se,{icon:void 0,name:v,size:"2xs",className:"rounded-xs",fallbackIcon:_}),e[17]=v,e[18]=T):T=e[18];let M;e[19]!==n?(M=n("chat.subtask.subtaskNoun"),e[19]=n,e[20]=M):M=e[20];const P=S?"loading":"idle",L=p.streaming||S;let A;e[21]!==b||e[22]!==a||e[23]!==j||e[24]!==L?(A=l.jsx(Va,{jobId:a,prompt:j,items:b,streaming:L}),e[21]=b,e[22]=a,e[23]=j,e[24]=L,e[25]=A):A=e[25];let I;return e[26]!==k||e[27]!==T||e[28]!==M||e[29]!==P||e[30]!==A?(I=l.jsx(st,{icon:T,title:M,summary:k,state:P,onOpenChange:u,children:A}),e[26]=k,e[27]=T,e[28]=M,e[29]=P,e[30]=A,e[31]=I):I=e[31],I}function Ja(s){return s.parts??[]}function Qa(s){return s.parts??[]}function Xa(s){const e=$.c(24),t=U(),n=Xt(s.part.toolCallId);if(Vt(s.part.output)){let x;return e[0]!==s?(x=l.jsx(Zt,{...s}),e[0]=s,e[1]=x):x=e[1],x}let a;e[2]!==s||e[3]!==t?(a=Jt(s,t),e[2]=s,e[3]=t,e[4]=a):a=e[4];const{fallbackTitle:o,summary:c,usage:i,state:u}=a;let r;e[5]!==t?(r=t("chat.subtask.subtaskNoun"),e[5]=t,e[6]=r):r=e[6];let m;e[7]===Symbol.for("react.memo_cache_sentinel")?(m=l.jsx(Je,{}),e[7]=m):m=e[7];let d;e[8]!==r?(d=l.jsx(Se,{icon:void 0,name:r,size:"2xs",className:"rounded-xs",fallbackIcon:m}),e[8]=r,e[9]=d):d=e[9];let f;e[10]!==n||e[11]!==s.part?(f=n&&Qt(s.part)?n:void 0,e[10]=n,e[11]=s.part,e[12]=f):f=e[12];let p;e[13]!==s.part?(p=l.jsx(Yt,{part:s.part}),e[13]=s.part,e[14]=p):p=e[14];let g;return e[15]!==o||e[16]!==s.latency||e[17]!==u||e[18]!==c||e[19]!==d||e[20]!==f||e[21]!==p||e[22]!==i?(g=l.jsx(st,{icon:d,title:o,summary:c,state:u,usage:i,latency:s.latency,onFlip:f,children:p}),e[15]=o,e[16]=s.latency,e[17]=u,e[18]=c,e[19]=d,e[20]=f,e[21]=p,e[22]=i,e[23]=g):g=e[23],g}function Ya(s){const e=$.c(26),t=U(),n=Rt(s.part.input?.agent_id),a=Xt(s.part.toolCallId);if(Vt(s.part.output)){let b;return e[0]!==s?(b=l.jsx(Zt,{...s}),e[0]=s,e[1]=b):b=e[1],b}let o;e[2]!==s||e[3]!==t?(o=Jt(s,t),e[2]=s,e[3]=t,e[4]=o):o=e[4];const{fallbackTitle:c,summary:i,usage:u,state:r}=o,m=n?.icon;let d;e[5]!==t||e[6]!==n?.title?(d=n?.title??t("chat.subtask.subtaskNoun"),e[5]=t,e[6]=n?.title,e[7]=d):d=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=l.jsx(Je,{}),e[8]=f):f=e[8];let p;e[9]!==m||e[10]!==d?(p=l.jsx(Se,{icon:m,name:d,size:"2xs",className:"rounded-xs",fallbackIcon:f}),e[9]=m,e[10]=d,e[11]=p):p=e[11];const g=n?.title??c;let x;e[12]!==a||e[13]!==s.part?(x=a&&Qt(s.part)?a:void 0,e[12]=a,e[13]=s.part,e[14]=x):x=e[14];let h;e[15]!==s.part?(h=l.jsx(Yt,{part:s.part}),e[15]=s.part,e[16]=h):h=e[16];let y;return e[17]!==s.latency||e[18]!==r||e[19]!==i||e[20]!==p||e[21]!==g||e[22]!==x||e[23]!==h||e[24]!==u?(y=l.jsx(st,{icon:p,title:g,summary:i,state:r,usage:u,latency:s.latency,onFlip:x,children:h}),e[17]=s.latency,e[18]=r,e[19]=i,e[20]=p,e[21]=g,e[22]=x,e[23]=h,e[24]=u,e[25]=y):y=e[25],y}function Za(s){const e=$.c(28),{part:t}=s,n=U();if(!t.state.startsWith("output-"))return null;const a=t.input?.plan??"",c=t.output?.approved===!0;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=l.jsx(He,{className:"size-4 text-special shrink-0"}),e[0]=i):i=e[0];let u;e[1]!==n?(u=n("chat.proposePlan.implementationPlan"),e[1]=n,e[2]=u):u=e[2];let r;e[3]!==u?(r=l.jsx("span",{className:"text-sm font-medium text-foreground/80",children:u}),e[3]=u,e[4]=r):r=e[4];let m;e[5]!==c||e[6]!==n?(m=c&&l.jsxs("span",{className:"flex items-center gap-1 text-xs text-success bg-success/10 px-1.5 py-0.5 rounded-md",children:[l.jsx(gt,{size:12}),n("chat.proposePlan.approved")]}),e[5]=c,e[6]=n,e[7]=m):m=e[7];let d;e[8]!==c||e[9]!==t.state||e[10]!==n?(d=!c&&t.state==="output-available"&&l.jsx("span",{className:"text-xs text-muted-foreground/70 italic",children:n("chat.proposePlan.rejected")}),e[8]=c,e[9]=t.state,e[10]=n,e[11]=d):d=e[11];let f;e[12]!==r||e[13]!==m||e[14]!==d?(f=l.jsxs("div",{className:"flex items-center gap-2",children:[i,r,m,d]}),e[12]=r,e[13]=m,e[14]=d,e[15]=f):f=e[15];let p;e[16]!==n?(p=n("chat.proposePlan.viewPlan"),e[16]=n,e[17]=p):p=e[17];let g;e[18]!==p?(g=l.jsx("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground transition-colors",children:p}),e[18]=p,e[19]=g):g=e[19];let x;e[20]!==a?(x=l.jsx("div",{className:"mt-1 pl-2 border-l-2 border-special/30 prose prose-sm max-w-none text-sm",children:l.jsx($e,{id:"plan-content",part:{type:"text",text:a}})}),e[20]=a,e[21]=x):x=e[21];let h;e[22]!==g||e[23]!==x?(h=l.jsxs("details",{className:"ml-6",children:[g,x]}),e[22]=g,e[23]=x,e[24]=h):h=e[24];let y;return e[25]!==h||e[26]!==f?(y=l.jsxs("div",{className:"my-1.5 flex flex-col gap-1",children:[f,h]}),e[25]=h,e[26]=f,e[27]=y):y=e[27],y}function Ge(s){const e=$.c(4),{connection_id:t,iconSize:n}=s,a=n===void 0?"xs":n,o=Rt(t);if(!o)return null;let c;return e[0]!==o.icon||e[1]!==o.title||e[2]!==a?(c=l.jsx("div",{className:"shrink-0 bg-background ring-1 ring-background rounded-lg",children:l.jsx(Se,{icon:o.icon,name:o.title,size:a})}),e[0]=o.icon,e[1]=o.title,e[2]=a,e[3]=c):c=e[3],c}Ge.Fallback=function({iconSize:e="xs"}){const t=e==="sm"?"size-6":"size-5";return l.jsx("div",{className:"shrink-0 bg-background ring-1 ring-background rounded-lg",children:l.jsx("div",{className:K(t,"rounded bg-muted animate-pulse")})})};function he(s){const e=$.c(18),{connectionIds:t,maxVisibleIcons:n,iconSize:a,className:o}=s,c=n===void 0?2:n,i=a===void 0?"xs":a;if(t.length===0)return null;let u,r,m;if(e[0]!==o||e[1]!==t||e[2]!==i||e[3]!==c){const p=t.slice(0,c);u=t.length-c,e[7]!==o?(r=K("flex items-center justify-end -space-x-2",o),e[7]=o,e[8]=r):r=e[8];let g;e[9]!==i?(g=x=>l.jsx(z.Suspense,{fallback:l.jsx(Ge.Fallback,{iconSize:i}),children:l.jsx(Ge,{connection_id:x,iconSize:i})},x),e[9]=i,e[10]=g):g=e[10],m=p.map(g),e[0]=o,e[1]=t,e[2]=i,e[3]=c,e[4]=u,e[5]=r,e[6]=m}else u=e[4],r=e[5],m=e[6];let d;e[11]!==i||e[12]!==u?(d=u>0&&l.jsx("div",{className:K("shrink-0 bg-background ring-1 ring-background border border-border rounded-lg flex items-center justify-center",i==="sm"?"size-8":"size-6"),children:l.jsxs("span",{className:K(i==="sm"?"text-sm":"text-xs","font-medium text-muted-foreground"),"aria-label":`and ${u} more`,children:["+",u]})}),e[11]=i,e[12]=u,e[13]=d):d=e[13];let f;return e[14]!==r||e[15]!==m||e[16]!==d?(f=l.jsxs("div",{className:r,children:[m,d]}),e[14]=r,e[15]=m,e[16]=d,e[17]=f):f=e[17],f}he.Fallback=function({maxVisibleIcons:e=2,totalCount:t,iconSize:n="xs"}){const a=n==="sm"?"size-6":"size-5",o=n==="sm"?"size-8":"size-6",c=t!==void 0&&t>e;return l.jsxs("div",{className:"flex items-center -space-x-2",children:[Array.from({length:e}).map((i,u)=>l.jsx("div",{className:"shrink-0 bg-background ring-1 ring-background rounded-lg",children:l.jsx("div",{className:K(a,"rounded bg-muted animate-pulse")})},u)),c&&l.jsx("div",{className:K("shrink-0 bg-background ring-1 ring-background border border-border rounded-lg flex items-center justify-center",o),children:l.jsx("div",{className:K(n==="sm"?"h-3.5 w-5":"h-3 w-4","rounded bg-muted animate-pulse")})})]})};const el="This document certifies that the bearer agent has been granted authorized access to the tools and capabilities described herein. The agent is permitted to operate within the scope defined by its instructions and shall act in accordance with the constraints set forth by the issuing organization. This credential remains valid for the duration of the agent's active status. Unauthorized modification of this agent's permissions or scope is prohibited. The issuing authority reserves the right to revoke access at any time. All actions performed by this agent are subject to audit and review by the organization administrator. ",pt=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(prefers-reduced-motion: reduce)"):null;function tl(s){const e=$.c(105),{part:t,latency:n}=s,a=U(),o=zt(),c=ge(t.state),i=z.useRef(null),u=z.useRef(null),r=z.useRef(null),m=z.useRef(null),d=z.useRef(null);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{pt?.matches||(d.current=i.current?.getBoundingClientRect()??null,i.current&&(i.current.style.willChange="transform"))},e[0]=f):f=e[0];const p=f;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=F=>{if(pt?.matches)return;const O=d.current,q=i.current;if(!O||!q)return;const oe=(F.clientX-O.left)/O.width*100,re=(F.clientY-O.top)/O.height*100;q.style.transform=`perspective(800px) rotateY(${(oe-50)*.05}deg) rotateX(${(re-50)*-.05}deg)`,u.current&&(u.current.style.opacity="1",u.current.style.transform=`translate(${(oe-50)*.15}px, ${(re-50)*.15}px)`),r.current&&(r.current.style.opacity="0.45"),m.current&&(m.current.style.opacity="0.45")},e[1]=g):g=e[1];const x=g;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const F=i.current;F&&(F.style.transform="none",F.style.willChange="auto"),u.current&&(u.current.style.opacity="0.4",u.current.style.transform="translate(0, 0)"),r.current&&(r.current.style.opacity="0.3"),m.current&&(m.current.style.opacity="0.3"),d.current=null},e[2]=h):h=e[2];const y=h;if(c==="loading"){let F;e[3]===Symbol.for("react.memo_cache_sentinel")?(F=l.jsx(de,{className:"animate-pulse"}),e[3]=F):F=e[3];let O;e[4]!==a?(O=a("chat.agentCreate.creating"),e[4]=a,e[5]=O):O=e[5];let q;return e[6]!==O?(q=l.jsx(Y,{icon:F,title:O,state:"loading",defaultOpen:!0}),e[6]=O,e[7]=q):q=e[7],q}if(c==="approval"){let F;e[8]===Symbol.for("react.memo_cache_sentinel")?(F=l.jsx(de,{}),e[8]=F):F=e[8];let O;e[9]!==a?(O=a("chat.agentCreate.createAgent"),e[9]=a,e[10]=O):O=e[10];let q;return e[11]!==O?(q=l.jsx(Y,{icon:F,title:O,state:"idle"}),e[11]=O,e[12]=q):q=e[12],q}if(c==="error"){let F;e[13]===Symbol.for("react.memo_cache_sentinel")?(F=l.jsx(de,{}),e[13]=F):F=e[13];let O;e[14]!==t.state||e[15]!==a?(O=t.state==="output-denied"?a("chat.agentCreate.cancelled"):a("chat.agentCreate.couldntCreate"),e[14]=t.state,e[15]=a,e[16]=O):O=e[16];let q;e[17]!==n?(q=l.jsx(fe,{latency:n}),e[17]=n,e[18]=q):q=e[18];let oe;return e[19]!==O||e[20]!==q?(oe=l.jsx(Y,{icon:F,title:O,state:"error",trailing:q}),e[19]=O,e[20]=q,e[21]=oe):oe=e[21],oe}let b,N,j,w,k,S,v,_,T,M,P,L,A,I,E,C,R,D,B,H,G,W,Q;if(e[22]!==n||e[23]!==o||e[24]!==t.output||e[25]!==a){R=Symbol.for("react.early_return_sentinel");e:{const F=Me(t.output)?.item;if(!F?.id||!F?.title){let ie;e[49]===Symbol.for("react.memo_cache_sentinel")?(ie=l.jsx(de,{}),e[49]=ie):ie=e[49];let ce;e[50]!==a?(ce=a("chat.agentCreate.created"),e[50]=a,e[51]=ce):ce=e[51];let J;e[52]!==n?(J=l.jsx(fe,{latency:n}),e[52]=n,e[53]=J):J=e[53];let se;e[54]!==ce||e[55]!==J?(se=l.jsx(Y,{icon:ie,title:ce,state:"idle",trailing:J}),e[54]=ce,e[55]=J,e[56]=se):se=e[56],R=se;break e}const O=(F.connections??[]).map(sl);let q;e[57]===Symbol.for("react.memo_cache_sentinel")?(q=l.jsx(de,{className:"text-success"}),e[57]=q):q=e[57];let oe;e[58]!==n?(oe=l.jsx(fe,{latency:n}),e[58]=n,e[59]=oe):oe=e[59],C=l.jsx(Y,{icon:q,title:a("chat.agentCreate.agentCreated",{name:F.title}),state:"idle",trailing:oe}),E="mt-2 overflow-hidden surface p-2.5",j=i,w="relative overflow-hidden rounded-lg bg-accent/25 p-2",e[60]===Symbol.for("react.memo_cache_sentinel")?(k={transition:"transform 0.3s ease-out"},e[60]=k):k=e[60],S=p,v=x,_=y,e[61]===Symbol.for("react.memo_cache_sentinel")?(T=l.jsx("div",{ref:u,className:"pointer-events-none absolute inset-[-20%] z-[1] select-none rounded-lg",style:{background:"linear-gradient(135deg, hsla(280, 60%, 80%, 0.35) 0%, transparent 35%), linear-gradient(315deg, hsla(190, 70%, 80%, 0.35) 0%, transparent 35%), linear-gradient(225deg, hsla(140, 55%, 80%, 0.3) 0%, transparent 30%), linear-gradient(45deg, hsla(320, 55%, 82%, 0.3) 0%, transparent 30%)",opacity:.4,transition:"opacity 0.3s ease, transform 0.3s ease-out"},"aria-hidden":"true"}),e[61]=T):T=e[61];let re;e[62]===Symbol.for("react.memo_cache_sentinel")?(re={textAlign:"justify",wordBreak:"break-all"},e[62]=re):re=e[62],e[63]===Symbol.for("react.memo_cache_sentinel")?(M=l.jsx("p",{className:"pointer-events-none absolute inset-0 z-[1] select-none overflow-hidden text-[6px] font-light leading-[1.5] tracking-[0.06px] text-background opacity-50 mix-blend-overlay",style:re,"aria-hidden":"true",children:el.repeat(6)}),P=l.jsx("img",{src:"/stamp.svg",alt:"",className:"pointer-events-none absolute -right-10 -top-10 size-[140px] opacity-50 select-none","aria-hidden":"true"}),e[63]=M,e[64]=P):(M=e[63],P=e[64]),e[65]===Symbol.for("react.memo_cache_sentinel")?(L=l.jsx("img",{ref:r,src:"/left-guilloche.png",alt:"",className:"pointer-events-none absolute inset-y-0 left-0 h-full w-auto select-none z-[1] mix-blend-overlay",style:{opacity:.3,transition:"opacity 0.3s ease"},"aria-hidden":"true"}),e[65]=L):L=e[65],e[66]===Symbol.for("react.memo_cache_sentinel")?(A=l.jsx("img",{ref:m,src:"/right-guilloche.png",alt:"",className:"pointer-events-none absolute inset-y-0 right-0 h-full w-auto select-none z-[1] mix-blend-overlay",style:{opacity:.3,transition:"opacity 0.3s ease"},"aria-hidden":"true"}),e[66]=A):A=e[66],I=l.jsxs("div",{className:"relative",children:[l.jsxs("div",{className:"flex items-center gap-2.5 p-2",children:[l.jsx(Xe,{icon:F.icon,name:F.title,size:"md"}),l.jsx("div",{className:"flex-1 min-w-0",children:l.jsx("h3",{className:"text-sm font-medium text-foreground truncate",children:F.title})})]}),F.description&&l.jsx("div",{className:"px-2 pt-1 pr-16",children:l.jsx("p",{className:"text-sm leading-snug text-muted-foreground line-clamp-2",children:F.description})})]}),Q="relative z-[3] flex items-center gap-2.5 px-2 pt-6 pb-1";const ue=O.length>0&&l.jsx(z.Suspense,{fallback:l.jsx(he.Fallback,{iconSize:"xs",maxVisibleIcons:3,totalCount:O.length}),children:l.jsx(he,{connectionIds:O,iconSize:"xs",maxVisibleIcons:3,className:"flex items-center justify-start -space-x-1"})});e[67]!==ue?(N=l.jsx("div",{className:"flex-1 min-w-0",children:ue}),e[67]=ue,e[68]=N):N=e[68],W="flex items-center gap-2 shrink-0",b=ye,D="sm",B="h-7",H=()=>o(F.id),G=a("chat.agentCreate.seeAgentLabel",{name:F.title})}e[22]=n,e[23]=o,e[24]=t.output,e[25]=a,e[26]=b,e[27]=N,e[28]=j,e[29]=w,e[30]=k,e[31]=S,e[32]=v,e[33]=_,e[34]=T,e[35]=M,e[36]=P,e[37]=L,e[38]=A,e[39]=I,e[40]=E,e[41]=C,e[42]=R,e[43]=D,e[44]=B,e[45]=H,e[46]=G,e[47]=W,e[48]=Q}else b=e[26],N=e[27],j=e[28],w=e[29],k=e[30],S=e[31],v=e[32],_=e[33],T=e[34],M=e[35],P=e[36],L=e[37],A=e[38],I=e[39],E=e[40],C=e[41],R=e[42],D=e[43],B=e[44],H=e[45],G=e[46],W=e[47],Q=e[48];if(R!==Symbol.for("react.early_return_sentinel"))return R;let te;e[69]!==a?(te=a("chat.agentCreate.seeAgent"),e[69]=a,e[70]=te):te=e[70];let X;e[71]!==b||e[72]!==te||e[73]!==D||e[74]!==B||e[75]!==H||e[76]!==G?(X=l.jsx(b,{size:D,className:B,onClick:H,"aria-label":G,children:te}),e[71]=b,e[72]=te,e[73]=D,e[74]=B,e[75]=H,e[76]=G,e[77]=X):X=e[77];let Z;e[78]!==X||e[79]!==W?(Z=l.jsx("div",{className:W,children:X}),e[78]=X,e[79]=W,e[80]=Z):Z=e[80];let le;e[81]!==N||e[82]!==Z||e[83]!==Q?(le=l.jsxs("div",{className:Q,children:[N,Z]}),e[81]=N,e[82]=Z,e[83]=Q,e[84]=le):le=e[84];let ee;e[85]!==j||e[86]!==w||e[87]!==k||e[88]!==S||e[89]!==v||e[90]!==_||e[91]!==T||e[92]!==M||e[93]!==P||e[94]!==L||e[95]!==A||e[96]!==I||e[97]!==le?(ee=l.jsxs("div",{ref:j,className:w,style:k,onMouseEnter:S,onMouseMove:v,onMouseLeave:_,children:[T,M,P,L,A,I,le]}),e[85]=j,e[86]=w,e[87]=k,e[88]=S,e[89]=v,e[90]=_,e[91]=T,e[92]=M,e[93]=P,e[94]=L,e[95]=A,e[96]=I,e[97]=le,e[98]=ee):ee=e[98];let V;e[99]!==E||e[100]!==ee?(V=l.jsx("div",{className:E,children:ee}),e[99]=E,e[100]=ee,e[101]=V):V=e[101];let ae;return e[102]!==C||e[103]!==V?(ae=l.jsxs(l.Fragment,{children:[C,V]}),e[102]=C,e[103]=V,e[104]=ae):ae=e[104],ae}function sl(s){return s.connection_id}function nl(s){const e=$.c(24),{agent:t}=s,n=zt();if(!t.id)return null;let a;e[0]!==t.connections?(a=t.connections??[],e[0]=t.connections,e[1]=a):a=e[1];let o;e[2]!==a?(o=a.map(al),e[2]=a,e[3]=o):o=e[3];const c=o;let i;e[4]!==t.id||e[5]!==n?(i=()=>n(t.id),e[4]=t.id,e[5]=n,e[6]=i):i=e[6];let u;e[7]!==t.icon||e[8]!==t.title?(u=l.jsx(Xe,{icon:t.icon,name:t.title,size:"sm"}),e[7]=t.icon,e[8]=t.title,e[9]=u):u=e[9];let r;e[10]!==t.title?(r=l.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:t.title}),e[10]=t.title,e[11]=r):r=e[11];let m;e[12]!==t.description?(m=t.description&&l.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.description}),e[12]=t.description,e[13]=m):m=e[13];let d;e[14]!==r||e[15]!==m?(d=l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col leading-tight",children:[r,m]}),e[14]=r,e[15]=m,e[16]=d):d=e[16];let f;e[17]!==c?(f=c.length>0&&l.jsx(z.Suspense,{fallback:l.jsx(he.Fallback,{iconSize:"xs",maxVisibleIcons:3,totalCount:c.length}),children:l.jsx(he,{connectionIds:c,iconSize:"xs",maxVisibleIcons:3})}),e[17]=c,e[18]=f):f=e[18];let p;return e[19]!==i||e[20]!==u||e[21]!==d||e[22]!==f?(p=l.jsxs("button",{type:"button",onClick:i,className:"group flex w-full items-center gap-3 rounded-lg border border-border bg-card px-3 py-2.5 text-left transition-colors hover:bg-accent cursor-pointer",children:[u,d,f]}),e[19]=i,e[20]=u,e[21]=d,e[22]=f,e[23]=p):p=e[23],p}function al(s){return s.connection_id}function ll(s){const e=$.c(59),{part:t,latency:n}=s,a=U(),o=Qe(),{org:c}=me();let i;e[0]!==t.state?(i=ge(t.state),e[0]=t.state,e[1]=i):i=e[1];const u=i;let r,m,d,f,p,g;if(e[2]!==n||e[3]!==t.output||e[4]!==t.state||e[5]!==u||e[6]!==a){g=Symbol.for("react.early_return_sentinel");e:{const b=Me(t.output);if(m=Array.isArray(b?.items)?b.items.filter(ms):[],u==="loading"){let k;e[13]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(de,{className:"animate-pulse"}),e[13]=k):k=e[13];let S;e[14]!==a?(S=a("chat.agentList.loading"),e[14]=a,e[15]=S):S=e[15];let v;e[16]!==S?(v=l.jsx(Y,{icon:k,title:S,state:"loading"}),e[16]=S,e[17]=v):v=e[17],g=v;break e}if(u==="approval"){let k;e[18]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(de,{}),e[18]=k):k=e[18];let S;e[19]!==a?(S=a("chat.agentList.listAgents"),e[19]=a,e[20]=S):S=e[20];let v;e[21]!==S?(v=l.jsx(Y,{icon:k,title:S,state:"idle"}),e[21]=S,e[22]=v):v=e[22],g=v;break e}if(u==="error"){let k;e[23]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(de,{}),e[23]=k):k=e[23];let S;e[24]!==t.state||e[25]!==a?(S=t.state==="output-denied"?a("chat.agentList.unavailable"):a("chat.agentList.couldntLoad"),e[24]=t.state,e[25]=a,e[26]=S):S=e[26];let v;e[27]!==n?(v=l.jsx(fe,{latency:n}),e[27]=n,e[28]=v):v=e[28];let _;e[29]!==S||e[30]!==v?(_=l.jsx(Y,{icon:k,title:S,state:"error",trailing:v}),e[29]=S,e[30]=v,e[31]=_):_=e[31],g=_;break e}if(m.length===0){let k;e[32]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(de,{}),e[32]=k):k=e[32];let S;e[33]!==a?(S=a("chat.agentList.noAgents"),e[33]=a,e[34]=S):S=e[34];let v;e[35]!==a?(v=a("chat.agentList.noAgentsDesc"),e[35]=a,e[36]=v):v=e[36];let _;e[37]!==n?(_=l.jsx(fe,{latency:n}),e[37]=n,e[38]=_):_=e[38];let T;e[39]!==S||e[40]!==v||e[41]!==_?(T=l.jsx(Y,{icon:k,title:S,summary:v,state:"idle",trailing:_}),e[39]=S,e[40]=v,e[41]=_,e[42]=T):T=e[42],g=T;break e}const N=m.slice(0,Dt);r=m.length-N.length;let j;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=l.jsx(de,{className:"text-success"}),e[43]=j):j=e[43];let w;e[44]!==n?(w=l.jsx(fe,{latency:n}),e[44]=n,e[45]=w):w=e[45],p=l.jsx(Y,{icon:j,title:m.length===1?a("chat.agentList.oneAgent"):a("chat.agentList.multiAgents",{count:m.length}),state:"idle",trailing:w}),d="mt-2 flex flex-col gap-1.5",f=N.map(ol)}e[2]=n,e[3]=t.output,e[4]=t.state,e[5]=u,e[6]=a,e[7]=r,e[8]=m,e[9]=d,e[10]=f,e[11]=p,e[12]=g}else r=e[7],m=e[8],d=e[9],f=e[10],p=e[11],g=e[12];if(g!==Symbol.for("react.early_return_sentinel"))return g;let x;e[46]!==r||e[47]!==m||e[48]!==o||e[49]!==c||e[50]!==a?(x=r>0&&l.jsx(Ot,{count:m.length,noun:a("chat.agentList.agentsNoun"),onClick:()=>o({to:"/$org/settings/projects",params:{org:c.slug}})}),e[46]=r,e[47]=m,e[48]=o,e[49]=c,e[50]=a,e[51]=x):x=e[51];let h;e[52]!==d||e[53]!==f||e[54]!==x?(h=l.jsxs("div",{className:d,children:[f,x]}),e[52]=d,e[53]=f,e[54]=x,e[55]=h):h=e[55];let y;return e[56]!==p||e[57]!==h?(y=l.jsxs(l.Fragment,{children:[p,h]}),e[56]=p,e[57]=h,e[58]=y):y=e[58],y}function ol(s){return l.jsx(nl,{agent:s},s.id)}const rl={active:"bg-success",inactive:"bg-muted-foreground",error:"bg-destructive"};function il(s){const e=$.c(27),{connection:t}=s,n=Qe(),{org:a}=me(),o=t.slug,c=t.description||t.app_name,i=!o||void 0;let u;e[0]!==n||e[1]!==a||e[2]!==o?(u=()=>o&&n({to:"/$org/settings/connections/$appSlug",params:{org:a.slug,appSlug:o}}),e[0]=n,e[1]=a,e[2]=o,e[3]=u):u=e[3];let r;e[4]!==t.icon||e[5]!==t.title?(r=l.jsx(Se,{icon:t.icon,name:t.title,size:"sm"}),e[4]=t.icon,e[5]=t.title,e[6]=r):r=e[6];let m;e[7]!==t.title?(m=l.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:t.title}),e[7]=t.title,e[8]=m):m=e[8];let d;e[9]!==c?(d=c&&l.jsx("span",{className:"truncate text-xs text-muted-foreground",children:c}),e[9]=c,e[10]=d):d=e[10];let f;e[11]!==m||e[12]!==d?(f=l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col leading-tight",children:[m,d]}),e[11]=m,e[12]=d,e[13]=f):f=e[13];const p=rl[t.status]??"bg-muted-foreground";let g;e[14]!==p?(g=K("size-2 shrink-0 rounded-full",p),e[14]=p,e[15]=g):g=e[15];let x;e[16]!==g?(x=l.jsx("span",{className:g,"aria-hidden":"true"}),e[16]=g,e[17]=x):x=e[17];let h;e[18]!==t.status?(h=l.jsx("span",{className:"sr-only",children:t.status}),e[18]=t.status,e[19]=h):h=e[19];let y;return e[20]!==i||e[21]!==h||e[22]!==u||e[23]!==r||e[24]!==f||e[25]!==x?(y=l.jsxs("button",{type:"button","aria-disabled":i,onClick:u,className:"group flex w-full items-center gap-3 rounded-lg border border-border bg-card px-3 py-2.5 text-left transition-colors hover:bg-accent cursor-pointer aria-disabled:cursor-default aria-disabled:hover:bg-card",children:[r,f,x,h]}),e[20]=i,e[21]=h,e[22]=u,e[23]=r,e[24]=f,e[25]=x,e[26]=y):y=e[26],y}function cl(s){const e=$.c(54),{part:t,latency:n}=s,a=U(),o=Qe(),{org:c}=me();let i;e[0]!==t.state?(i=ge(t.state),e[0]=t.state,e[1]=i):i=e[1];const u=i;let r,m,d,f,p,g;if(e[2]!==n||e[3]!==t.output||e[4]!==t.state||e[5]!==u||e[6]!==a){g=Symbol.for("react.early_return_sentinel");e:{const b=Me(t.output);if(m=(Array.isArray(b?.items)?b.items:[]).filter(dl),u==="loading"||u==="approval"){let k;e[13]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(we,{className:"animate-pulse"}),e[13]=k):k=e[13];let S;e[14]!==a?(S=a("chat.connectionList.loadingTitle"),e[14]=a,e[15]=S):S=e[15];let v;e[16]!==S?(v=l.jsx(Y,{icon:k,title:S,state:"loading"}),e[16]=S,e[17]=v):v=e[17],g=v;break e}if(u==="error"){let k;e[18]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(we,{}),e[18]=k):k=e[18];let S;e[19]!==t.state||e[20]!==a?(S=t.state==="output-denied"?a("chat.connectionList.unavailableTitle"):a("chat.connectionList.errorTitle"),e[19]=t.state,e[20]=a,e[21]=S):S=e[21];let v;e[22]!==n?(v=l.jsx(fe,{latency:n}),e[22]=n,e[23]=v):v=e[23];let _;e[24]!==S||e[25]!==v?(_=l.jsx(Y,{icon:k,title:S,state:"error",trailing:v}),e[24]=S,e[25]=v,e[26]=_):_=e[26],g=_;break e}if(m.length===0){let k;e[27]===Symbol.for("react.memo_cache_sentinel")?(k=l.jsx(we,{}),e[27]=k):k=e[27];let S;e[28]!==a?(S=a("chat.connectionList.emptyTitle"),e[28]=a,e[29]=S):S=e[29];let v;e[30]!==a?(v=a("chat.connectionList.emptySummary"),e[30]=a,e[31]=v):v=e[31];let _;e[32]!==n?(_=l.jsx(fe,{latency:n}),e[32]=n,e[33]=_):_=e[33];let T;e[34]!==S||e[35]!==v||e[36]!==_?(T=l.jsx(Y,{icon:k,title:S,summary:v,state:"idle",trailing:_}),e[34]=S,e[35]=v,e[36]=_,e[37]=T):T=e[37],g=T;break e}const N=m.slice(0,Dt);r=m.length-N.length;let j;e[38]===Symbol.for("react.memo_cache_sentinel")?(j=l.jsx(we,{className:"text-success"}),e[38]=j):j=e[38];let w;e[39]!==n?(w=l.jsx(fe,{latency:n}),e[39]=n,e[40]=w):w=e[40],p=l.jsx(Y,{icon:j,title:m.length===1?a("chat.connectionList.singleConnection"):a("chat.connectionList.multipleConnections",{count:m.length}),state:"idle",trailing:w}),d="mt-2 flex flex-col gap-1.5",f=N.map(ul)}e[2]=n,e[3]=t.output,e[4]=t.state,e[5]=u,e[6]=a,e[7]=r,e[8]=m,e[9]=d,e[10]=f,e[11]=p,e[12]=g}else r=e[7],m=e[8],d=e[9],f=e[10],p=e[11],g=e[12];if(g!==Symbol.for("react.early_return_sentinel"))return g;let x;e[41]!==r||e[42]!==m||e[43]!==o||e[44]!==c||e[45]!==a?(x=r>0&&l.jsx(Ot,{count:m.length,noun:a("chat.connectionList.connectionNoun"),onClick:()=>o({to:"/$org/settings/connections",params:{org:c.slug}})}),e[41]=r,e[42]=m,e[43]=o,e[44]=c,e[45]=a,e[46]=x):x=e[46];let h;e[47]!==d||e[48]!==f||e[49]!==x?(h=l.jsxs("div",{className:d,children:[f,x]}),e[47]=d,e[48]=f,e[49]=x,e[50]=h):h=e[50];let y;return e[51]!==p||e[52]!==h?(y=l.jsxs(l.Fragment,{children:[p,h]}),e[51]=p,e[52]=h,e[53]=y):y=e[53],y}function ul(s){return l.jsx(il,{connection:s},s.id)}function dl(s){return s.connection_type!=="VIRTUAL"}function fl(){const s=$.c(46),e=U(),t=ve(),{sendMessage:n,isStreaming:a,messages:o}=ln(),{org:c}=me(),i=t?.virtualMcpId,{prompts:u}=dn(c.slug),r=i??null;let m;s[0]!==c.id||s[1]!==c.slug||s[2]!==r?(m={connectionId:r,orgId:c.id,orgSlug:c.slug},s[0]=c.id,s[1]=c.slug,s[2]=r,s[3]=m):m=s[3];let d;s[4]!==i?(d=!!i&&rt(i),s[4]=i,s[5]=d):d=s[5];let f;s[6]!==d?(f={enabled:d},s[6]=d,s[7]=f):f=s[7];const p=hn(m,f),[g,x]=z.useState(null);if(!i||a||!rt(i)||!o.some(ml))return null;let y;if(s[8]!==u||s[9]!==i){let C;s[11]!==i?(C=R=>R.agentId===i&&R.promptName,s[11]=i,s[12]=C):C=s[12],y=u.find(C),s[8]=u,s[9]=i,s[10]=y}else y=s[10];const b=y;if(!b)return null;let N;s[13]!==p||s[14]!==n||s[15]!==e?(N=async(C,R)=>{if(!p){Be.error(e("chat.nextActionChip.mcpClientNotAvailable"));return}try{const D=await Tn(p,C.name,R);await n({type:"doc",content:[{type:"paragraph",content:[Rs({id:C.name,name:At(C.name,Mt(C._meta)),metadata:D.messages,char:"/",kind:"prompt",args:R}),{type:"text",text:" "}]}]})}catch(D){console.error("[next-action-chip] failed",D),Be.error(e("chat.nextActionChip.failedLoadPrompt"))}},s[13]=p,s[14]=n,s[15]=e,s[16]=N):N=s[16];const j=N;let w;s[17]!==b._meta||s[18]!==b.arguments||s[19]!==b.description||s[20]!==b.promptName||s[21]!==b.title||s[22]!==j?(w=()=>{const C={name:b.promptName,title:b.title,description:b.description,arguments:b.arguments,_meta:b._meta};if(C.arguments&&C.arguments.length>0){x(C);return}j(C)},s[17]=b._meta,s[18]=b.arguments,s[19]=b.description,s[20]=b.promptName,s[21]=b.title,s[22]=j,s[23]=w):w=s[23];const k=w;let S;s[24]===Symbol.for("react.memo_cache_sentinel")?(S=l.jsx(Ys,{className:"size-3 shrink-0 text-special"}),s[24]=S):S=s[24];let v;s[25]!==e?(v=e("chat.nextActionChip.next"),s[25]=e,s[26]=v):v=s[26];let _;s[27]!==v?(_=l.jsx("span",{className:"font-medium text-foreground/80",children:v}),s[27]=v,s[28]=_):_=s[28];let T;s[29]!==b.title?(T=l.jsx("span",{className:"truncate",children:b.title}),s[29]=b.title,s[30]=T):T=s[30];let M;s[31]===Symbol.for("react.memo_cache_sentinel")?(M=l.jsx(St,{className:"size-3 shrink-0 transition-transform duration-150 group-hover:translate-x-0.5"}),s[31]=M):M=s[31];let P;s[32]!==k||s[33]!==T||s[34]!==_?(P=l.jsxs(ye,{type:"button",variant:"outline",size:"sm",onClick:k,className:"group mt-3 self-start text-muted-foreground",children:[S,_,T,M]}),s[32]=k,s[33]=T,s[34]=_,s[35]=P):P=s[35];let L;s[36]===Symbol.for("react.memo_cache_sentinel")?(L=C=>x(C),s[36]=L):L=s[36];let A;s[37]!==g||s[38]!==j?(A=async C=>{const R=g;x(null),R&&await j(R,C)},s[37]=g,s[38]=j,s[39]=A):A=s[39];let I;s[40]!==g||s[41]!==A?(I=l.jsx(zs,{prompt:g,setPrompt:L,onSubmit:A}),s[40]=g,s[41]=A,s[42]=I):I=s[42];let E;return s[43]!==P||s[44]!==I?(E=l.jsxs(l.Fragment,{children:[P,I]}),s[43]=P,s[44]=I,s[45]=E):E=s[45],E}function ml(s){return s.role==="user"||s.parts.some(pl)}function pl(s){return s.type==="tool-user_ask"&&s.state==="output-available"}function gl(s){const e=$.c(25),{event:t}=s,n=U(),[a,o]=z.useState(!1);let c;e[0]!==t.data?(c=JSON.stringify(t.data,null,2),e[0]=t.data,e[1]=c):c=e[1];const i=c;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=()=>o(xl),e[2]=u):u=e[2];let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=l.jsx(ws,{className:"size-4 shrink-0 text-muted-foreground"}),e[3]=r):r=e[3];let m;e[4]!==n?(m=n("chat.triggerEventPart.triggeredByEvent"),e[4]=n,e[5]=m):m=e[5];let d;e[6]!==m?(d=l.jsx("span",{className:"font-medium",children:m}),e[6]=m,e[7]=d):d=e[7];let f;e[8]!==t.type?(f=l.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:t.type}),e[8]=t.type,e[9]=f):f=e[9];const p=a&&"rotate-180";let g;e[10]!==p?(g=K("ml-auto size-4 shrink-0 text-muted-foreground transition-transform",p),e[10]=p,e[11]=g):g=e[11];let x;e[12]!==g?(x=l.jsx(Cn,{className:g}),e[12]=g,e[13]=x):x=e[13];let h;e[14]!==d||e[15]!==f||e[16]!==x?(h=l.jsxs("button",{type:"button",onClick:u,className:"flex w-full items-center gap-2 px-3 py-2 text-sm cursor-pointer",children:[r,d,f,x]}),e[14]=d,e[15]=f,e[16]=x,e[17]=h):h=e[17];let y;e[18]!==t.source||e[19]!==a||e[20]!==i?(y=a&&l.jsxs("div",{className:"border-t border-border/60 px-3 py-2",children:[l.jsx("div",{className:"mb-2 text-xs text-muted-foreground",children:t.source}),l.jsx("pre",{className:"overflow-auto whitespace-pre-wrap break-words text-xs text-foreground",children:i})]}),e[18]=t.source,e[19]=a,e[20]=i,e[21]=y):y=e[21];let b;return e[22]!==h||e[23]!==y?(b=l.jsxs("div",{className:"rounded-lg border border-border/60 bg-background overflow-hidden text-left",children:[h,y]}),e[22]=h,e[23]=y,e[24]=b):b=e[24],b}function xl(s){return!s}const hl=[Os,Bs,Us];function bl(s){const e=$.c(6),{tiptapDoc:t}=s;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={attributes:{class:"prose prose-sm max-w-none text-[14px]! focus:outline-none"}},e[0]=n):n=e[0];let a;e[1]!==t?(a={extensions:hl,content:t,editable:!1,editorProps:n},e[1]=t,e[2]=a):a=e[2];const o=Fs(a);if(!o)return null;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=K(Ds,"[&_.ProseMirror]:outline-none [&_.ProseMirror]:cursor-text"),e[3]=c):c=e[3];let i;return e[4]!==o?(i=l.jsx(Hs,{editor:o,className:c}),e[4]=o,e[5]=i):i=e[5],i}function es(s){const e=$.c(35),{message:t,className:n,onScrollToPair:a}=s,{id:o,parts:c,metadata:i}=t,[u,r]=z.useState(!1),[m,d]=z.useState(!1),f=z.useRef(!1);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=L=>{L&&!f.current&&(f.current=!0,d(L.scrollHeight>L.clientHeight))},e[0]=p):p=e[0];const g=p;if(!c||c.length===0)return null;let x;e[1]!==a?(x=()=>{r(!0),a?.()},e[1]=a,e[2]=x):x=e[2];const h=x,y=i?.tiptapDoc;let b;e[3]!==n?(b=K("message-block flex w-full min-w-0 flex-col items-end px-2.5 text-foreground",n),e[3]=n,e[4]=b):b=e[4];let N,j;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=()=>r(!0),j=()=>r(!1),e[5]=N,e[6]=j):(N=e[5],j=e[6]);let w;e[7]!==u||e[8]!==m?(w=K("px-4 py-2.5 transition-[max-height,opacity] duration-300 ease-out",u?"max-h-[50vh] overflow-auto opacity-100":K("max-h-[168px] overflow-hidden opacity-99",m&&"mask-b-from-1%")),e[7]=u,e[8]=m,e[9]=w):w=e[9];let k;if(e[10]!==o||e[11]!==c){let L;e[13]!==o?(L=(A,I)=>A.type==="data-trigger-event"?l.jsx(gl,{event:A.data},`${o}-${I}`):null,e[13]=o,e[14]=L):L=e[14],k=c.map(L),e[10]=o,e[11]=c,e[12]=k}else k=e[12];let S;e[15]!==y||e[16]!==o||e[17]!==i||e[18]!==c?(S=y?l.jsx(bl,{tiptapDoc:i.tiptapDoc}):c.map((L,A)=>L.type==="text"?c[A-1]?.type==="data-trigger-event"?null:l.jsx($e,{id:o,part:L},`${o}-${A}`):null),e[15]=y,e[16]=o,e[17]=i,e[18]=c,e[19]=S):S=e[19];let v;e[20]!==k||e[21]!==S?(v=l.jsxs("div",{className:"flex flex-col gap-2",children:[k,S]}),e[20]=k,e[21]=S,e[22]=v):v=e[22];let _;e[23]!==w||e[24]!==v?(_=l.jsx("div",{ref:g,className:w,children:v}),e[23]=w,e[24]=v,e[25]=_):_=e[25];let T;e[26]!==h||e[27]!==_?(T=l.jsx("div",{tabIndex:0,onClick:h,onFocus:N,onBlur:j,className:"max-w-[85%] min-w-0 cursor-pointer rounded-2xl bg-muted text-sm wrap-break-word overflow-wrap-anywhere outline-none",children:_}),e[26]=h,e[27]=_,e[28]=T):T=e[28];let M;e[29]!==t?(M=l.jsx(et,{message:t,className:"mt-1 mr-1"}),e[29]=t,e[30]=M):M=e[30];let P;return e[31]!==T||e[32]!==M||e[33]!==b?(P=l.jsx(l.Fragment,{children:l.jsxs("div",{className:b,children:[T,M]})}),e[31]=T,e[32]=M,e[33]=b,e[34]=P):P=e[34],P}function ts(s){const e=$.c(10),{message:t,pending:n}=s,a=U();let o;e[0]!==n||e[1]!==a?(o=a(n?"chat.liveMessage.pending":"chat.liveMessage.readByAgent"),e[0]=n,e[1]=a,e[2]=o):o=e[2];let c;e[3]!==o?(c=l.jsx("span",{className:"self-end px-3 text-xs text-muted-foreground",children:o}),e[3]=o,e[4]=c):c=e[4];let i;e[5]!==t?(i=l.jsx(es,{message:t}),e[5]=t,e[6]=i):i=e[6];let u;return e[7]!==c||e[8]!==i?(u=l.jsxs("div",{className:"flex flex-col gap-1 py-1",children:[c,i]}),e[7]=c,e[8]=i,e[9]=u):u=e[9],u}function yl(s){const e=$.c(5),{part:t}=s,{read:n}=wt();let a;if(e[0]!==t||e[1]!==n){const i=on(t);a=i?n.get(i):void 0,e[0]=t,e[1]=n,e[2]=a}else a=e[2];const o=a;if(!o)return null;let c;return e[3]!==o?(c=l.jsx(ts,{message:o,pending:!1}),e[3]=o,e[4]=c):c=e[4],c}function jl(s){const e=new Map;for(let t=s.length-1;t>=0;t--){const n=s[t]?.parts;if(n)for(const a of n){const o=a;if(o.type!=="data-deck-updated")continue;const c=o.data;if(!c?.path)continue;const i=`deck:${c.path}`;e.has(i)||e.set(i,{tabId:ps(c.path),label:c.name||c.path,kind:c.kind==="page"?"page":"deck"})}}return Array.from(e.values())}function vl(){const s=$.c(9),e=U(),{openPanel:t}=Ze(),n=je()?.messages??[],a=jl(n);if(a.length===0)return null;const o=a.some(kl),c=a.some(Sl),i=e(o?c?"chat.threadHtmlPreviews.slidesAndPages":"chat.threadHtmlPreviews.slides":"chat.threadHtmlPreviews.pages"),u="flex flex-col gap-1.5 py-2";let r;s[0]!==i?(r=l.jsx("div",{className:"text-xs text-muted-foreground/70",children:i}),s[0]=i,s[1]=r):r=s[1];const m="flex flex-wrap gap-2";let d;s[2]!==t?(d=x=>l.jsxs(ye,{type:"button",variant:"outline",className:"max-w-full",onClick:()=>t(x.tabId),children:[x.kind==="deck"?l.jsx(In,{className:"size-3.5 shrink-0 text-muted-foreground"}):l.jsx(_s,{className:"size-3.5 shrink-0 text-muted-foreground"}),l.jsx("span",{className:"truncate font-medium text-foreground",children:x.label})]},x.tabId),s[2]=t,s[3]=d):d=s[3];const f=a.map(d);let p;s[4]!==f?(p=l.jsx("div",{className:m,children:f}),s[4]=f,s[5]=p):p=s[5];let g;return s[6]!==r||s[7]!==p?(g=l.jsxs("div",{className:u,children:[r,p]}),s[6]=r,s[7]=p,s[8]=g):g=s[8],g}function Sl(s){return s.kind==="page"}function kl(s){return s.kind==="deck"}function Nl(s){const e=$.c(29),{file:t}=s,n=U(),{openPanel:a}=Ze();let o;e[0]!==t.key||e[1]!==a?(o=()=>a(gs(t.key)),e[0]=t.key,e[1]=a,e[2]=o):o=e[2];const c=o;let i;e[3]!==t.filename?(i=l.jsx(Mn,{filename:t.filename,className:"h-5 w-4 shrink-0"}),e[3]=t.filename,e[4]=i):i=e[4];let u;e[5]!==t.filename||e[6]!==c?(u=l.jsx("button",{type:"button",onClick:c,className:"min-w-0 flex-1 truncate text-left text-sm font-medium text-foreground hover:underline",title:t.filename,children:t.filename}),e[5]=t.filename,e[6]=c,e[7]=u):u=e[7];const r=t.downloadUrl,m=t.filename;let d;e[8]!==n?(d=n("chat.outputFileRow.download"),e[8]=n,e[9]=d):d=e[9];let f;e[10]!==t.filename||e[11]!==n?(f=n("chat.outputFileRow.downloadFile",{filename:t.filename}),e[10]=t.filename,e[11]=n,e[12]=f):f=e[12];let p;e[13]===Symbol.for("react.memo_cache_sentinel")?(p=l.jsx(Ts,{className:"size-3.5"}),e[13]=p):p=e[13];let g;e[14]!==t.downloadUrl||e[15]!==t.filename||e[16]!==d||e[17]!==f?(g=l.jsx("a",{href:r,download:m,className:"hidden shrink-0 text-muted-foreground hover:text-foreground group-hover:block group-focus-within:block",title:d,"aria-label":f,children:p}),e[14]=t.downloadUrl,e[15]=t.filename,e[16]=d,e[17]=f,e[18]=g):g=e[18];let x;e[19]!==n?(x=n("chat.outputFileRow.open"),e[19]=n,e[20]=x):x=e[20];let h;e[21]!==c||e[22]!==x?(h=l.jsx(ye,{variant:"outline",size:"sm",className:"h-7 shrink-0 px-2.5 text-xs",onClick:c,children:x}),e[21]=c,e[22]=x,e[23]=h):h=e[23];let y;return e[24]!==h||e[25]!==i||e[26]!==u||e[27]!==g?(y=l.jsxs("div",{className:"group flex items-center gap-2 rounded-lg border border-border bg-background px-3 py-2",children:[i,u,g,h]}),e[24]=h,e[25]=i,e[26]=u,e[27]=g,e[28]=y):y=e[28],y}function wl(s){return s.split("/").pop()??s}const _l=/(^|\/)output\//;function Tl(s){const e=new Set;for(const t of s.parts??[]){const n=t;if(n.state==="output-available"&&n.type==="tool-write"){const a=n.input?.path;a&&_l.test(a)&&e.add(wl(a))}}return e}function Cl(s){const e=$.c(4),{threadId:t,message:n}=s,a=Tl(n),o=a.size>0;let c;e[0]!==o?(c={enabled:o},e[0]=o,e[1]=c):c=e[1];const{data:i}=$n(t,c);if(a.size===0)return null;const u=(i??[]).filter(f=>a.has(f.filename));if(u.length===0)return null;const r="flex flex-col gap-1.5 py-2",m=u.map(Il);let d;return e[2]!==m?(d=l.jsx("div",{className:r,children:m}),e[2]=m,e[3]=d):d=e[3],d}function Il(s){return l.jsx(Nl,{file:s},s.key)}function $l(s){return s.type==="reasoning"}function Ml(s){const e=[],t=new Set,n=new Map,a=new Map,o=new Map;if(s){let i=null;for(let u=0;u<s.parts.length;u++){const r=s.parts[u];if($l(r)){i||(i={parts:[],startIndex:u},e.push(i)),i.parts.push(r),t.add(u);continue}if(i=null,r.type==="data-tool-metadata"&&"id"in r&&"data"in r){const m=r.data,d={};m.annotations&&(d.annotations=m.annotations),typeof m.latencyMs=="number"&&Number.isFinite(m.latencyMs)&&(d.latencySeconds=m.latencyMs/1e3),typeof m.outputBytes=="number"&&Number.isFinite(m.outputBytes)&&m.outputBytes>=0&&(d.outputBytes=m.outputBytes),m._meta&&typeof m._meta=="object"&&(d._meta=m._meta),n.set(r.id,d);continue}if(r.type==="data-tool-subtask-metadata"&&"id"in r){a.set(r.id,r.data);continue}if(r.type==="data-web-search"&&"id"in r&&"data"in r){const m=r.id,d=r.data;o.set(m,d.text??"");continue}}}const c=[];if(s)for(let i=0;i<s.parts.length;i++){const u=s.parts[i];if(u.type!=="step-start"){if(t.has(i)){const r=e.find(m=>m.startIndex===i);r&&c.push({kind:"reasoning-group",group:r});continue}u.type.startsWith("data-")&&u.type!==Ae||c.push({kind:"part",index:i})}}return{reasoningGroups:e,renderOrder:c,dataParts:{toolMetadata:n,toolSubtaskMetadata:a,webSearchStreaming:o}}}const Al=3;function Pl(s,e){let t=-1;for(let o=s.length-1;o>=0;o--){const c=s[o];if(c.kind==="part"&&e[c.index]?.type==="text"){t=o;break}}if(t===-1)return{collapsed:[],tail:s};const n=s.findLastIndex(o=>o.kind==="part"&&e[o.index]?.type===Ae),a=n!==-1&&n<t?n:t;return{collapsed:s.slice(0,a),tail:s.slice(a)}}function We(s,e){return s.kind==="part"&&e[s.index]?.type!==Ae}function El(s,e){let t=0,n=0;for(const a of s)if(a.kind==="reasoning-group")n++;else{const o=e[a.index]?.type;o==="text"?n++:(o==="dynamic-tool"||o?.startsWith("tool-"))&&o!=="tool-todo_write"&&o!=="tool-update_interests"&&t++}return{toolCalls:t,messages:n}}function Ll(s){const e=$.c(10),{toolCalls:t,messages:n}=s,a=U();let o;e[0]!==n||e[1]!==a||e[2]!==t?(o=t>0&&l.jsxs(l.Fragment,{children:[l.jsx(vt,{className:"size-3.5 shrink-0"}),l.jsxs("span",{children:[a("chat.assistant.toolCallPlural",{count:t}),n>0?",":""]})]}),e[0]=n,e[1]=a,e[2]=t,e[3]=o):o=e[3];let c;e[4]!==n||e[5]!==a?(c=n>0&&l.jsxs(l.Fragment,{children:[l.jsx(Cs,{className:"size-3.5 shrink-0"}),l.jsx("span",{children:a("chat.assistant.messagePlural",{count:n})})]}),e[4]=n,e[5]=a,e[6]=c):c=e[6];let i;return e[7]!==o||e[8]!==c?(i=l.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[o,c]}),e[7]=o,e[8]=c,e[9]=i):i=e[9],i}function Rl(s){const e=$.c(28),{items:t,message:n,reasoningGroups:a,isReasoningActive:o,totalDuration:c,dataParts:i,isLoading:u,isLast:r}=s;let m;e[0]!==t||e[1]!==n.parts?(m=El(t,n.parts),e[0]=t,e[1]=n.parts,e[2]=m):m=e[2];const{toolCalls:d,messages:f}=m;if(d===0&&f===0)return null;let p;e[3]!==f||e[4]!==d?(p=l.jsx(Ll,{toolCalls:d,messages:f}),e[3]=f,e[4]=d,e[5]=p):p=e[5];let g;if(e[6]!==i||e[7]!==r||e[8]!==u||e[9]!==o||e[10]!==t||e[11]!==n||e[12]!==a||e[13]!==c){let y;e[15]!==i||e[16]!==r||e[17]!==u||e[18]!==o||e[19]!==n||e[20]!==a||e[21]!==c?(y=(b,N)=>ss({item:b,renderIndex:N,message:n,reasoningGroups:a,isReasoningActive:o,totalDuration:c,dataParts:i,isLoading:u,isLast:r,isLastVisiblePart:!1}),e[15]=i,e[16]=r,e[17]=u,e[18]=o,e[19]=n,e[20]=a,e[21]=c,e[22]=y):y=e[22],g=t.map(y),e[6]=i,e[7]=r,e[8]=u,e[9]=o,e[10]=t,e[11]=n,e[12]=a,e[13]=c,e[14]=g}else g=e[14];let x;e[23]!==g?(x=l.jsx("div",{className:"flex flex-col gap-3 sm:gap-2 pt-1",children:g}),e[23]=g,e[24]=x):x=e[24];let h;return e[25]!==p||e[26]!==x?(h=l.jsx(Y,{icon:null,alwaysChevron:!0,title:p,state:"idle",children:x}),e[25]=p,e[26]=x,e[27]=h):h=e[27],h}function ss({item:s,renderIndex:e,message:t,reasoningGroups:n,isReasoningActive:a,totalDuration:o,dataParts:c,isLoading:i,isLast:u,isLastVisiblePart:r,renderOrder:m}){if(s.kind==="reasoning-group"){const{group:g}=s,x=g===n[n.length-1],h=a&&x;if(!g.parts.some(N=>N.text?.trim())&&!h)return null;const b=n.length===1?o:null;return l.jsx(Jn,{duration:b,parts:g.parts,isStreaming:h},`${t.id}-reasoning-${g.startIndex}`)}const d=t.parts[s.index],f=r||(m?m.findLastIndex(g=>We(g,t.parts))===e:!1),p=f?rn(cn(),t.metadata?.usage):null;return l.jsx(zl,{part:d,id:t.id,usageStats:f&&l.jsx(Ks,{usage:p,duration:o,timestamp:!i&&l.jsx(et,{message:t})}),dataParts:c,isLoading:i,isLastMessage:u},`${t.id}-${s.index}`)}function zl(s){const e=$.c(118),{part:t,id:n,usageStats:a,dataParts:o,isLoading:c,isLastMessage:i}=s;let u;e[0]!==o.toolMetadata?(u=f=>o.toolMetadata.get(f),e[0]=o.toolMetadata,e[1]=u):u=e[1];const r=u;let m;e[2]!==o.toolSubtaskMetadata?(m=f=>o.toolSubtaskMetadata.get(f),e[2]=o.toolSubtaskMetadata,e[3]=m):m=e[3];const d=m;switch(t.type){case"dynamic-tool":{let f;e[4]!==r||e[5]!==t.toolCallId?(f=r(t.toolCallId)?.annotations,e[4]=r,e[5]=t.toolCallId,e[6]=f):f=e[6];let p;e[7]!==r||e[8]!==t.toolCallId?(p=r(t.toolCallId)?.latencySeconds,e[7]=r,e[8]=t.toolCallId,e[9]=p):p=e[9];let g;e[10]!==r||e[11]!==t.toolCallId?(g=r(t.toolCallId)?.outputBytes,e[10]=r,e[11]=t.toolCallId,e[12]=g):g=e[12];let x;e[13]!==r||e[14]!==t.toolCallId?(x=r(t.toolCallId)?._meta,e[13]=r,e[14]=t.toolCallId,e[15]=x):x=e[15];let h;return e[16]!==i||e[17]!==t||e[18]!==f||e[19]!==p||e[20]!==g||e[21]!==x?(h=l.jsx(dt,{part:t,annotations:f,latency:p,outputBytes:g,isLastMessage:i,toolMeta:x}),e[16]=i,e[17]=t,e[18]=f,e[19]=p,e[20]=g,e[21]=x,e[22]=h):h=e[22],h}case"tool-todo_write":return null;case"tool-update_interests":return null;case"tool-user_ask":{let f;e[23]!==r||e[24]!==t.toolCallId?(f=r(t.toolCallId)?.latencySeconds,e[23]=r,e[24]=t.toolCallId,e[25]=f):f=e[25];let p;return e[26]!==t||e[27]!==f?(p=l.jsx(Oa,{part:t,latency:f}),e[26]=t,e[27]=f,e[28]=p):p=e[28],p}case"tool-suggest_task":{let f;return e[29]!==t?(f=l.jsx(Ba,{part:t}),e[29]=t,e[30]=f):f=e[30],f}case"tool-propose_plan":{let f;return e[31]!==t?(f=l.jsx(Za,{part:t}),e[31]=t,e[32]=f):f=e[32],f}case"tool-generate_image":{let f;e[33]!==r||e[34]!==t.toolCallId?(f=r(t.toolCallId)?.latencySeconds,e[33]=r,e[34]=t.toolCallId,e[35]=f):f=e[35];let p;return e[36]!==t||e[37]!==f?(p=l.jsx(Ta,{part:t,latency:f}),e[36]=t,e[37]=f,e[38]=p):p=e[38],p}case"tool-web_search":case"tool-deep_research":{let f;e[39]!==r||e[40]!==t.toolCallId?(f=r(t.toolCallId)?.latencySeconds,e[39]=r,e[40]=t.toolCallId,e[41]=f):f=e[41];let p;e[42]!==o.webSearchStreaming||e[43]!==t.toolCallId?(p=o.webSearchStreaming.get(t.toolCallId),e[42]=o.webSearchStreaming,e[43]=t.toolCallId,e[44]=p):p=e[44];let g;return e[45]!==t||e[46]!==f||e[47]!==p?(g=l.jsx(Da,{part:t,latency:f,streamingText:p}),e[45]=t,e[46]=f,e[47]=p,e[48]=g):g=e[48],g}case"tool-subtask":{let f;e[49]!==d||e[50]!==t.toolCallId?(f=d(t.toolCallId),e[49]=d,e[50]=t.toolCallId,e[51]=f):f=e[51];let p;e[52]!==r||e[53]!==t.toolCallId?(p=r(t.toolCallId)?.annotations,e[52]=r,e[53]=t.toolCallId,e[54]=p):p=e[54];let g;e[55]!==r||e[56]!==t.toolCallId?(g=r(t.toolCallId)?.latencySeconds,e[55]=r,e[56]=t.toolCallId,e[57]=g):g=e[57];let x;e[58]!==t||e[59]!==f||e[60]!==p||e[61]!==g?(x={part:t,subtaskMeta:f,annotations:p,latency:g},e[58]=t,e[59]=f,e[60]=p,e[61]=g,e[62]=x):x=e[62];const h=x;let y;return e[63]!==h?(y=l.jsx(z.Suspense,{fallback:l.jsx(Xa,{...h}),children:l.jsx(Ya,{...h})}),e[63]=h,e[64]=y):y=e[64],y}case"text":{const f=!!a&&!c,p=c&&i;let g;return e[65]!==n||e[66]!==t||e[67]!==f||e[68]!==p||e[69]!==a?(g=l.jsx($e,{id:n,part:t,extraActions:a,copyable:!0,alwaysShowActions:f,animate:p}),e[65]=n,e[66]=t,e[67]=f,e[68]=p,e[69]=a,e[70]=g):g=e[70],g}case"reasoning":return null;case"step-start":case"file":case"source-url":case"source-document":return null;case"data-tool-metadata":case"data-tool-subtask-metadata":case"data-generate-image":case"data-web-search":return null;default:{const f=t;if(f.type==="tool-COLLECTION_VIRTUAL_MCP_CREATE"){let p;e[71]!==f.toolCallId||e[72]!==r?(p=r(f.toolCallId)?.latencySeconds,e[71]=f.toolCallId,e[72]=r,e[73]=p):p=e[73];let g;return e[74]!==f||e[75]!==p?(g=l.jsx(tl,{part:f,latency:p}),e[74]=f,e[75]=p,e[76]=g):g=e[76],g}if(f.type==="tool-TASK_BOARD_ITEM_CREATE"){let p;e[77]!==f?(p=On(f),e[77]=f,e[78]=p):p=e[78];const g=p;if(g){let x;return e[79]!==g?(x=l.jsx(Bn,{task:g}),e[79]=g,e[80]=x):x=e[80],x}}if(f.type==="tool-COLLECTION_VIRTUAL_MCP_LIST"){let p;e[81]!==f.toolCallId||e[82]!==r?(p=r(f.toolCallId)?.latencySeconds,e[81]=f.toolCallId,e[82]=r,e[83]=p):p=e[83];let g;return e[84]!==f||e[85]!==p?(g=l.jsx(ll,{part:f,latency:p}),e[84]=f,e[85]=p,e[86]=g):g=e[86],g}if(f.type==="tool-COLLECTION_CONNECTIONS_LIST"){let p;e[87]!==f.toolCallId||e[88]!==r?(p=r(f.toolCallId)?.latencySeconds,e[87]=f.toolCallId,e[88]=r,e[89]=p):p=e[89];let g;return e[90]!==f||e[91]!==p?(g=l.jsx(cl,{part:f,latency:p}),e[90]=f,e[91]=p,e[92]=g):g=e[92],g}if(f.type.startsWith("tool-")){const p=f;let g;e[93]!==o.toolMetadata||e[94]!==p.toolCallId?(g=o.toolMetadata.get(p.toolCallId),e[93]=o.toolMetadata,e[94]=p.toolCallId,e[95]=g):g=e[95];const x=g;let h;e[96]!==f.type||e[97]!==p.output?(h=f.type.endsWith("__get_screenshot")?ka(p.output):null,e[96]=f.type,e[97]=p.output,e[98]=h):h=e[98];const y=h,b=x?.annotations,N=x?.latencySeconds,j=x?.outputBytes,w=x?._meta;let k;e[99]!==f||e[100]!==i||e[101]!==b||e[102]!==N||e[103]!==j||e[104]!==w?(k=l.jsx(dt,{part:f,annotations:b,latency:N,outputBytes:j,isLastMessage:i,toolMeta:w}),e[99]=f,e[100]=i,e[101]=b,e[102]=N,e[103]=j,e[104]=w,e[105]=k):k=e[105];const S=k;if(!y)return S;let v;e[106]!==y?(v=[y],e[106]=y,e[107]=v):v=e[107];let _;e[108]!==p.type?(_=p.type.slice(5),e[108]=p.type,e[109]=_):_=e[109];let T;e[110]!==v||e[111]!==_?(T=l.jsx(Gt,{srcs:v,alt:_}),e[110]=v,e[111]=_,e[112]=T):T=e[112];let M;return e[113]!==S||e[114]!==T?(M=l.jsxs("div",{className:"flex flex-col gap-2",children:[S,T]}),e[113]=S,e[114]=T,e[115]=M):M=e[115],M}if(t.type===Ae){let p;return e[116]!==t?(p=l.jsx(yl,{part:t}),e[116]=t,e[117]=p):p=e[117],p}return f.type.startsWith("data-")||console.warn(`[chat] unknown message part type: ${f.type}`),null}}}function Fl(s){const e=$.c(3),{pending:t,children:n}=s;if(!t||t.length===0)return n;let a;return e[0]!==n||e[1]!==t?(a=l.jsxs("div",{className:"flex flex-col gap-3 sm:gap-2",children:[n,t]}),e[0]=n,e[1]=t,e[2]=a):a=e[2],a}function Dl(s){const e=$.c(9),{isRunInProgress:t}=s,n=U();if(t){let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=l.jsx(Ie,{className:"text-muted-foreground shrink-0 animate-pulse",size:14}),e[0]=c):c=e[0];let i;e[1]!==n?(i=n("chat.assistant.resumingTask"),e[1]=n,e[2]=i):i=e[2];let u;return e[3]!==i?(u=l.jsx("div",{className:"flex items-center gap-1.5 py-2 opacity-60",children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[c,l.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:i})]})}),e[3]=i,e[4]=u):u=e[4],u}let a;e[5]!==n?(a=n("chat.assistant.noResponseGenerated"),e[5]=n,e[6]=a):a=e[6];let o;return e[7]!==a?(o=l.jsx("div",{className:"text-sm text-muted-foreground/60 py-2",children:a}),e[7]=a,e[8]=o):o=e[8],o}function Ol(s){const e=$.c(7),{className:t,children:n}=s;let a;e[0]!==t?(a=K("w-full min-w-0 group relative flex items-start gap-4 px-4 z-20 text-foreground flex-row",t),e[0]=t,e[1]=a):a=e[1];let o;e[2]!==n?(o=l.jsx("div",{className:"flex flex-col min-w-0 w-full items-start",children:l.jsx("div",{className:"w-full min-w-0 not-only:rounded-2xl text-sm wrap-break-word overflow-wrap-anywhere bg-transparent",children:n})}),e[2]=n,e[3]=o):o=e[3];let c;return e[4]!==a||e[5]!==o?(c=l.jsx("div",{className:a,children:o}),e[4]=a,e[5]=o,e[6]=c):c=e[6],c}function Bl(s){const e=$.c(18),{message:t,turnStartedAt:n,status:a,className:o,isLast:c}=s,i=c===void 0?!1:c,u=U(),{isRunInProgress:r}=je()??{},m=r===void 0?!1:r,d=ve()?.taskId??null,f=a==="streaming",g=f||a==="submitted";let x;e[0]!==n?(x=Ve(n),e[0]=n,e[1]=x):x=e[1];const h=x;let y;e[2]!==g?(y=()=>g?Date.now():null,e[2]=g,e[3]=y):y=e[3];const[b,N]=z.useState(y),[j,w]=z.useState(g);j!==g&&(w(g),N(()=>g?Date.now():null));const k=h??b,{reasoningGroups:S,renderOrder:v,dataParts:_}=Ml(t),T=t!==null&&v.length>0,M=t&&t.parts.length>0?t.parts[t.parts.length-1]:null,P=f&&M?.type==="reasoning";let L;if(e[4]!==t){const ee=t?.metadata?.reasoning_start_at?new Date(t.metadata.reasoning_start_at):null,V=t?.metadata?.reasoning_end_at?new Date(t.metadata.reasoning_end_at):new Date;L=ee!==null?V.getTime()-ee.getTime():null,e[4]=t,e[5]=L}else L=e[5];const A=L;let I;e[6]!==i||e[7]!==t?(I=!i||!t||!t.parts.some(Hl),e[6]=i,e[7]=t,e[8]=I):I=e[8];const E=I,C=!g&&T&&E&&(()=>{let ee=0;for(const V of v)if(V.kind==="part"){const ae=t.parts[V.index]?.type;(ae==="dynamic-tool"||ae?.startsWith("tool-"))&&ee++}return ee>=Al})(),{collapsed:R,tail:D}=C?Pl(v,t.parts):{collapsed:[],tail:v};let B;e[9]!==t?(B=ee=>t?We(ee,t.parts):!1,e[9]=t,e[10]=B):B=e[10];const H=D.findLast(B),G=!!t&&H?.kind==="part"&&t.parts[H.index]?.type==="text",{pending:W}=wt();let Q;e[11]!==i||e[12]!==W?(Q=i?W.map(Ul):null,e[11]=i,e[12]=W,e[13]=Q):Q=e[13];const te=Q,X=Ol,Z=T?l.jsxs("div",{className:"flex flex-col gap-3 sm:gap-2",children:[t.metadata?.resumedFromBackground&&l.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground/60 select-none",children:[l.jsx(bt,{className:"size-3 shrink-0"}),l.jsx("span",{children:u("chat.assistant.resumedBackgroundTask")})]}),R.length>0&&l.jsx(Rl,{items:R,message:t,reasoningGroups:S,isReasoningActive:P,totalDuration:A,dataParts:_,isLoading:g,isLast:i}),D.map((ee,V)=>{const ae=R.length+V,F=D.findLastIndex(O=>We(O,t.parts))===V;return ss({item:ee,renderIndex:ae,message:t,reasoningGroups:S,isReasoningActive:P,totalDuration:A,dataParts:_,isLoading:g,isLast:i,isLastVisiblePart:F,renderOrder:v})}),d&&l.jsx(Cl,{threadId:d,message:t}),te,i&&(g||m)&&k!==null&&l.jsx(Gn,{startedAt:k}),i&&!g&&d&&l.jsxs(l.Fragment,{children:[l.jsx(vl,{}),E&&l.jsx(fl,{})]}),!g&&!G&&l.jsx(et,{message:t})]}):l.jsx(Fl,{pending:te,children:g?l.jsx(Vn,{startedAt:k}):l.jsx(Dl,{isRunInProgress:i&&m})});let le;return e[14]!==X||e[15]!==o||e[16]!==Z?(le=l.jsx(X,{className:o,children:Z}),e[14]=X,e[15]=o,e[16]=Z,e[17]=le):le=e[17],le}function Ul(s){return l.jsx(ts,{message:s,pending:!0},s.id)}function Hl(s){const e=s.type;if(e!=="dynamic-tool"&&!e?.startsWith("tool-"))return!1;const t=s.state;return t==="input-streaming"||t==="input-available"||t==="approval-requested"}function Ro(s){const e=[],t=s.filter(n=>n.role!=="system"&&!n.metadata?.internal&&!n.metadata?.subtaskJobId);for(let n=0;n<t.length;n++){const a=t[n];if(a)if(a.role==="user"){const o=t[n+1];o&&o.role==="assistant"?(e.push({user:a,assistant:o}),n++):e.push({user:a,assistant:null})}else a.role==="assistant"&&e.push({user:null,assistant:a})}return e}function zo(s){const e=$.c(19),{pair:t,isLastPair:n,status:a}=s,o=z.useRef(null),c=z.useRef(!1);let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{o.current&&o.current.scrollIntoView({behavior:"smooth",block:"start"})},e[0]=i):i=e[0];const u=i;let r;e[1]!==n||e[2]!==t.assistant?.metadata?.resumedFromBackground||e[3]!==a?(r=y=>{if(o.current=y,!n||!y||c.current||(c.current=!0,t.assistant?.metadata?.resumedFromBackground))return;if(a==="submitted"||a==="streaming"){y.scrollIntoView({behavior:"smooth",block:"start"});return}const b=y.closest("[data-chat-scroller]");b?b.scrollTop=b.scrollHeight:y.scrollIntoView({behavior:"instant",block:"start"})},e[1]=n,e[2]=t.assistant?.metadata?.resumedFromBackground,e[3]=a,e[4]=r):r=e[4];const m=r,d=!t.user&&"pt-8 sm:pt-6";let f;e[5]!==d?(f=K("flex flex-col pb-2 sm:pb-2",d),e[5]=d,e[6]=f):f=e[6];let p;e[7]!==t.user?(p=t.user&&l.jsx("div",{className:"mt-4 mb-6",children:l.jsx(es,{message:t.user,onScrollToPair:u})}),e[7]=t.user,e[8]=p):p=e[8];const g=t.user?.created_at??null;let x;e[9]!==n||e[10]!==t.assistant||e[11]!==a||e[12]!==g?(x=l.jsx(Bl,{message:t.assistant,turnStartedAt:g,status:a,isLast:n}),e[9]=n,e[10]=t.assistant,e[11]=a,e[12]=g,e[13]=x):x=e[13];let h;return e[14]!==m||e[15]!==f||e[16]!==p||e[17]!==x?(h=l.jsxs("div",{ref:m,className:f,children:[p,x]}),e[14]=m,e[15]=f,e[16]=p,e[17]=x,e[18]=h):h=e[18],h}export{An as G,zo as M,Nl as O,Lo as S,Fn as a,ea as f,Ro as u};