1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,127923,e=>{"use strict";var t=e.i(178761);e.s(["Popover",0,t])},172782,e=>{"use strict";var t=e.i(843476),a=e.i(500932);e.i(785269);var s=e.i(322831),n=e.i(964053),l=e.i(35842),i=e.i(244002),r=e.i(434163),o=e.i(372428);function d(e,t){return t?e(`plans.${t.id}`,{defaultValue:t.name}):e("plans.free",{defaultValue:"Free"})}e.s(["PlanUsageDialog",0,function(e){let c,u,m,h,p,g,f,x,b,v,j,y,w,k=(0,a.c)(48),{open:N,onOpenChange:C,data:S}=e,{t:_,i18n:T}=(0,s.useTranslation)("paletteOs"),{openRoute:E}=(0,l.useOsActions)(),A=S?.plan,R=S?.usage,D=A?.id==="free",M=A?.plan_type==="company",I=R?.monthly_limit??null;k[0]!==I||k[1]!==R?.monthly_used?(c=I?Math.min(100,Math.round((R?.monthly_used??0)/I*100)):0,k[0]=I,k[1]=R?.monthly_used,k[2]=c):c=k[2];let O=c,P=R?.usage_state??"normal",L=R?.pool_state??P,F=M?R?.seat:null;k[3]!==M||k[4]!==S||k[5]!==D||k[6]!==C||k[7]!==E?(u=()=>{(C(!1),M&&S?.contact_sales_url)?window.open(S.contact_sales_url,"_blank","noopener,noreferrer"):E(`/settings?section=billing${D?"&tab=plans":""}`)},k[3]=M,k[4]=S,k[5]=D,k[6]=C,k[7]=E,k[8]=u):u=k[8];let $=u;return k[9]===Symbol.for("react.memo_cache_sentinel")?(m={display:"contents"},h=(0,t.jsx)(n.Dialog.Overlay,{className:"ssSearchBd"}),k[9]=m,k[10]=h):(m=k[9],h=k[10]),k[11]!==_?(p=_("usage.dialogTitle","Plan & usage"),k[11]=_,k[12]=p):p=k[12],k[13]!==p?(g=(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:p})}),k[13]=p,k[14]=g):g=k[14],k[15]!==_?(f=_("shell.close","Close"),k[15]=_,k[16]=f):f=k[16],k[17]===Symbol.for("react.memo_cache_sentinel")?(x=(0,t.jsx)(i.Glyph,{name:"h_close"}),k[17]=x):x=k[17],k[18]!==f?(b=(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":f,children:x})}),k[18]=f,k[19]=b):b=k[19],k[20]!==g||k[21]!==b?(v=(0,t.jsxs)("div",{className:"ssSearchHead",children:[g,b]}),k[20]=g,k[21]=b,k[22]=v):v=k[22],k[23]!==M||k[24]!==S||k[25]!==D||k[26]!==$||k[27]!==T||k[28]!==I||k[29]!==O||k[30]!==A||k[31]!==L||k[32]!==F||k[33]!==P||k[34]!==_||k[35]!==R?.monthly_used||k[36]!==R?.rollover||k[37]!==R?.topup_balance||k[38]!==R?.topup_usable||k[39]!==R?.welcome_balance?(j=(0,t.jsx)("div",{className:"ssSearchBody ssDlgBody poPlanBody",children:S?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"poPlanRow",children:[(0,t.jsx)("span",{className:`poPlanTag ${D?"free":"paid"}`,children:d(_,A)}),(0,t.jsx)("strong",{children:_("usage.planName",{defaultValue:"{{plan}} plan",plan:d(_,A)})}),S.subscription.scheduled_change_type&&(0,t.jsx)("span",{className:"poPlanScheduled",children:"cancel_to_free"===S.subscription.scheduled_change_type?_("usage.scheduledCancel",{defaultValue:"Switches to Free on {{date}}",date:(0,o.formatDate)(S.subscription.scheduled_change_at,T.language)}):_("usage.scheduledDowngrade",{defaultValue:"Changes to {{plan}} on {{date}}",plan:d(_,{id:S.subscription.scheduled_plan_id??"",name:S.subscription.scheduled_plan_name??""}),date:(0,o.formatDate)(S.subscription.scheduled_change_at,T.language)})})]}),(0,t.jsx)(r.MemberLimitNotice,{data:S}),(0,t.jsxs)("div",{className:"poPlanMetric",children:[(0,t.jsx)("span",{children:M?_("usage.poolUsage","Monthly credit pool"):_("usage.monthlyUsage","Monthly usage")}),(0,t.jsx)("strong",{children:null===I?_("usage.negotiated","Negotiated"):_("usage.credits",{defaultValue:"{{used}} / {{limit}} credits",used:(0,o.formatCredits)(R?.monthly_used,T.language),limit:(0,o.formatCredits)(I,T.language)})})]}),(0,t.jsx)("div",{className:`poPlanProgress ${L}`,role:"progressbar","aria-valuenow":O,"aria-valuemin":0,"aria-valuemax":100,children:(0,t.jsx)("span",{style:{width:`${O}%`}})}),F&&(0,t.jsxs)("div",{className:"poPlanMetric",children:[(0,t.jsx)("span",{children:_("usage.seatCredits")}),(0,t.jsx)("strong",{children:_("usage.credits",{defaultValue:"{{used}} / {{limit}} credits",used:(0,o.formatCredits)(F.used,T.language),limit:(0,o.formatCredits)(F.credits,T.language)})})]}),(0,t.jsxs)("div",{className:"poPlanSub",children:[(R?.rollover??0)>0&&(0,t.jsx)("span",{children:_("usage.rollover",{defaultValue:"Rolled over {{amount}} credits",amount:(0,o.formatCredits)(R?.rollover,T.language)})}),(R?.welcome_balance??0)>
10&&(0,t.jsx)("span",{children:_("usage.welcome",{defaultValue:"Welcome credits {{amount}}",amount:(0,o.formatCredits)(R?.welcome_balance,T.language)})}),!D&&(R?.topup_balance??0)>0&&(0,t.jsx)("span",{children:_("usage.topup",{defaultValue:"Top-up credits {{amount}}",amount:(0,o.formatCredits)(R?.topup_balance,T.language)})}),(0,t.jsx)("span",{children:_("usage.renews",{defaultValue:"Renews {{date}}",date:(0,o.formatDate)(S.subscription.cycle_ends_at,T.language)})})]}),"warning"===P&&(0,t.jsx)("p",{className:"poPlanNote warn",children:D?_("usage.warningFree","Your free usage is running low."):_("usage.warningPaid",{defaultValue:"Your {{plan}} monthly allowance is running low.",plan:d(_,A)})}),"exhausted"===P&&(0,t.jsx)("p",{className:"poPlanNote danger",children:F?_("usage.seatExhausted"):D?_("usage.exhaustedFree","You've used all of your available free credits for this cycle."):_("usage.exhaustedPaid",{defaultValue:"You've used all {{plan}} credits for this cycle.",plan:d(_,A)})}),"topup"===P&&(0,t.jsx)("p",{className:"poPlanNote",children:_("usage.topupInUse",{defaultValue:"Monthly allowance used. Running on {{amount}} extra credits.",amount:(0,o.formatCredits)((R?.rollover??0)+(R?.welcome_balance??0)+(R?.topup_usable?R?.topup_balance??0:0),T.language)})}),"expired"===P&&(0,t.jsx)("p",{className:"poPlanNote danger",children:"pending"===S.subscription.status?_("workspaceSettings:subscription.pendingNote"):_("usage.expired","This workspace's subscription has ended. Contact sales to reactivate.")}),S.permissions.view&&(0,t.jsx)("div",{className:"poPlanActions",children:(0,t.jsx)("button",{type:"button",className:"cdUsageBtn pri",onClick:$,children:M?_("usage.contactSales","Contact sales"):D||!S.permissions.change_plan?_("usage.viewPlans","View plans"):_("usage.changePlan","Change plan")})})]}):(0,t.jsx)("p",{className:"ssDlgP small",children:_("usage.loading","Loading usageâ¦")})}),k[23]=M,k[24]=S,k[25]=D,k[26]=$,k[27]=T,k[28]=I,k[29]=O,k[30]=A,k[31]=L,k[32]=F,k[33]=P,k[34]=_,k[35]=R?.monthly_used,k[36]=R?.rollover,k[37]=R?.topup_balance,k[38]=R?.topup_usable,k[39]=R?.welcome_balance,k[40]=j):j=k[40],k[41]!==v||k[42]!==j?(y=(0,t.jsx)(n.Dialog.Portal,{container:"u">typeof document?document.fullscreenElement??void 0:void 0,children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:m,children:[h,(0,t.jsxs)(n.Dialog.Content,{className:"ssSearchDlg ssDlg poPlanDlg","aria-describedby":void 0,children:[v,j]})]})}),k[41]=v,k[42]=j,k[43]=y):y=k[43],k[44]!==C||k[45]!==N||k[46]!==y?(w=(0,t.jsx)(n.Dialog.Root,{open:N,onOpenChange:C,children:y}),k[44]=C,k[45]=N,k[46]=y,k[47]=w):w=k[47],w},"planLabel",0,d])},640457,748317,917870,127536,527939,169673,161873,602725,198197,455435,430172,752044,510798,413163,151002,e=>{"use strict";var t=e.i(843476),a=e.i(500932),s=e.i(271645),n=e.i(964053);e.i(785269);var l=e.i(322831),i=e.i(13080),r=e.i(988985),o=e.i(244002),d=e.i(96213);function c({onClose:e,onReview:a}){let{t:i}=(0,l.useTranslation)("paletteOs"),{loops:d,loading:u,error:m,refetch:h}
1=(0,r.useLoops)(),[p,g]=(0,s.useState)(!1),[f,x]=(0,s.useState)(""),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)("09:00"),[w]=(0,s.useState)(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"),[k,N]=(0,s.useState)(null),C=(0,s.useRef)(null),S=(0,s.useRef)(!1),_=(0,s.useRef)(!1),T=(0,s.useRef)(null),[E,A]=(0,s.useState)(!1),[R,D]=(0,s.useState)(""),[M]=(0,s.useState)(()=>document.activeElement),I=d.filter(e=>!!e.schedule_cron&&"archived"!==e.status),O=()=>{S.current||e()},P=t=>{_.current=!0,e(),a(t)},L=async e=>{if(S.current)return;S.current=!0,A(!0),D("");let t=document.activeElement;try{await e(),await h(),requestAnimationFrame(()=>{t?.isConnected||T.current?.focus()})}catch(e){D(e instanceof Error?e.message:i("scheduledTasks.saveError"))}finally{S.current=!1,A(!1)}};return(0,t.jsx)(n.Dialog.Root,{open:!0,onOpenChange:e=>{e||O()},children:(0,t.jsx)(n.Dialog.Portal,{children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:{display:"contents"},children:[(0,t.jsx)(n.Dialog.Overlay,{className:"ssSearchBd"}),(0,t.jsxs)(n.Dialog.Content,{className:"ssSearchDlg ssDlg ssScheduledTasks",onEscapeKeyDown:e=>{S.current&&e.preventDefault()},onPointerDownOutside:e=>{S.current&&e.preventDefault()},onCloseAutoFocus:e=>{e.preventDefault(),!_.current&&M?.isConnected&&M.focus()},children:[(0,t.jsxs)("div",{className:"ssSearchHead",children:[(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:i(p?"scheduledTasks.addTitle":"scheduledTasks.title")})}),(0,t.jsx)("button",{type:"button",className:"ssSearchClose",disabled:E,onClick:O,"aria-label":i("shell.close"),children:(0,t.jsx)(o.Glyph,{name:"h_close"})})]}),(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody",children:[(0,t.jsx)(n.Dialog.Description,{className:"ssDlgP",children:i(p?"scheduledTasks.createNote":"scheduledTasks.listNote")}),R&&(0,t.jsx)("p",{role:"alert",className:"ssTaskError",children:R}),p?(0,t.jsxs)("form",{onSubmit:e=>{e.preventDefault(),L(async()=>{if(!f.trim()||!b.trim()||!/^([01]\d|2[0-3]):[0-5]\d$/.test(j))throw Error(i("scheduledTasks.required"));let e=null===C.current?(await (0,r.generateLoop)(b.trim())).loop:await (0,r.fetchLoop)(C.current);C.current=e.id,N(e.id),await (0,r.updateLoop)(e.id,{title:f.trim()});let[t,a]=j.split(":").map(Number);if((await (0,r.setLoopSchedule)(e.id,`${a} ${t} * * *`,w)).schedule_timezone!==w)throw Error(i("scheduledTasks.timezoneUnsupported"));"draft"===e.status&&await (0,r.finalizeLoop)(e.id),g(!1),C.current=null,N(null)})},children:[(0,t.jsxs)("label",{className:"ssTaskField",children:[i("scheduledTasks.name"),(0,t.jsx)("input",{autoFocus:!0,required:!0,maxLength:255,value:f,disabled:E,onChange:e=>x(e.target.value),placeholder:i("scheduledTasks.namePlaceholder")})]}),(0,t.jsxs)("label",{className:"ssTaskField",children:[i("scheduledTasks.prompt"),(0,t.jsx)("textarea",{required:!0,rows:3,maxLength:2e4,value:b,disabled:E||null!==k,onChange:e=>v(e.target.value)})]}),(0,t.jsxs)("label",{className:"ssTaskField",children:[i("scheduledTasks.time"),(0,t.jsx)("input",{required:!0,type:"time",value:j,disabled:E,onChange:e=>y(e.target.value)})]}),(0,t.jsx)("p",{className:"ssTaskTimezone",children:i("scheduledTasks.timezone",{timezone:w})}),null!==k&&(0,t.jsx)("p",{className:"ssDlgNote",children:i("scheduledTasks.preparedNote")}),(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:E,onClick:()=>{g(!1),D(""),h(),requestAnimationFrame(()=>T.current?.focus())},children:i("scheduledTasks.back")}),null!==k&&(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:E,onClick:()=>P(k),children:i("scheduledTasks.review")}),(0,t.jsx)("button",{type:"submit",className:"cfBtn cfPrimary",disabled:E||!f.trim()||!b.trim(),children:i(E?"scheduledTasks.saving":null===k?"scheduledTasks.save":"scheduledTasks.retry")})]})]}):(0,t.jsxs)(t.Fragment,{children:[u&&(0,t.jsx)("p",{role:"status",className:"ssDlgP",children:i("scheduledTasks.loading")}),m&&(0,t.jsxs)("div",{role:"alert",children:[(0,t.jsx)("p",{className:"ssDlgP",children:i("scheduledTasks.loadError")}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>void h(),children:i("scheduledTasks.retry")})})]}),!u&&!m&&!I.length&&(0,t.jsx)("div",{className:"ssTaskEmpty",children:i("scheduledTasks.empty")}),I.map(e=>{let a,s,n;return(0,t.jsxs)("div",{className:"ssTaskRow",children:[(0,t.jsx)(o.Glyph,{name:"h_clock"}),(0,t.jsxs)("div",{className:"ssTaskRowText",children:[e.title,(0,t.jsx)("small",{children:(s=(a=/^(\d{1,2}) (\d{1,2}) \* \* \*$/.exec(e.schedule_cron??""))?i("scheduledTasks.daily",{time:`${a[2].padStart(2,"0")}:${a[1].padStart(2,"0")}`}
1):e.schedule_cron,n="paused"===e.status?i("scheduledTasks.paused"):"draft"===e.status?i("scheduledTasks.needsSetup"):i("scheduledTasks.scheduled"),`${s} \xb7 ${e.schedule_timezone??i("scheduledTasks.serverTime")} \xb7 ${n}`)})]}),"draft"===e.status?(0,t.jsx)("button",{type:"button",className:"ssDlgIcon",disabled:E,"aria-label":i("scheduledTasks.reviewTask",{name:e.title}),onClick:()=>P(e.id),children:(0,t.jsx)(o.Glyph,{name:"h_external"})}):(0,t.jsx)("button",{type:"button",className:"ssDlgIcon",disabled:E,"aria-label":i("paused"===e.status?"scheduledTasks.resumeTask":"scheduledTasks.pauseTask",{name:e.title}),onClick:()=>void L(()=>(0,r.updateLoop)(e.id,{status:"paused"===e.status?"active":"paused"})),children:(0,t.jsx)(o.Glyph,{name:"paused"===e.status?"h_play":"h_stop"})}),(0,t.jsx)("button",{type:"button",className:"ssDlgIcon",disabled:E,"aria-label":i("scheduledTasks.deleteTask",{name:e.title}),onClick:()=>void L(()=>(0,r.setLoopSchedule)(e.id,null)),children:(0,t.jsx)(o.Glyph,{name:"h_trash"})})]},e.id)}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",ref:T,className:"cfBtn cfPrimary",disabled:E,onClick:()=>{g(!0),D(""),null===C.current&&(x(""),v(""),y("09:00"))},children:i(null===C.current?"scheduledTasks.add":"scheduledTasks.continue")})})]})]})]})]})})})}e.s(["ScheduledTasksDialog",0,function(){let e,s,n,l=(0,a.c)(8),{scheduledTasksOpen:r,setScheduledTasksOpen:o,openSurface:u}=(0,d.useViewContext)(),{user:m}=(0,i.useAuth)();if(!r)return null;let h=`${m?.id}:${m?.organization_id}`;return l[0]!==o?(e=()=>o(!1),l[0]=o,l[1]=e):e=l[1],l[2]!==u?(s=e=>u("/loops",{subRoute:`?loop=${e}`}),l[2]=u,l[3]=s):s=l[3],l[4]!==h||l[5]!==e||l[6]!==s?(n=(0,t.jsx)(c,{onClose:e,onReview:s},h),l[4]=h,l[5]=e,l[6]=s,l[7]=n):n=l[7],n}],640457);var u=e.i(236643),m=e.i(846696),h=e.i(713967);let p="po:session-projects";function g(e){try{let t=JSON.parse(e??"[]");if(!Array.isArray(t))return[];let a=new Set,s=new Set;return t.flatMap(e=>{if(!e||"string"!=typeof e.id||!e.id||a.has(e.id)||"string"!=typeof e.name||!e.name.trim())return[];a.add(e.id);let t=Array.isArray(e.conversations)?e.conversations.filter(e=>!("string"!=typeof e||!e||s.has(e))&&(s.add(e),!0)):[];return[{id:e.id,name:e.name.trim().slice(0,200),conversations:t}]})}catch{return[]}}function f(){var e,t;let{user:a}=(0,i.useAuth)(),n=a?(e=a.id,t=a.organization_id,`palette_session_projects_v1:${t??"personal"}:${e}`):null,l=(0,s.useCallback)(()=>{try{return n?localStorage.getItem(n):null}catch{return null}},[n]),r=(0,s.useCallback)(e=>{let t=t=>{t.detail===n&&e()},a=t=>{(t.key===n||null===t.key)&&e()};return window.addEventListener(p,t),window.addEventListener("storage",a),()=>{window.removeEventListener(p,t),window.removeEventListener("storage",a)}},[n]),o=(0,s.useSyncExternalStore)(r,l,()=>null),d=(0,s.useMemo)(()=>g(o),[o]),c=(0,s.useCallback)(e=>{if(!n)throw Error("Sign in to manage projects");localStorage.setItem(n,JSON.stringify(e(g(localStorage.getItem(n))))),window.dispatchEvent(new CustomEvent(p,{detail:n}))},[n]),u=(0,s.useCallback)((e,t)=>{let a=e.trim().slice(0,200);if(!a)throw Error("Enter a project name");let s=t??crypto.randomUUID();return c(e=>{if(t&&!e.some(e=>e.id===t))throw Error("Project no longer exists");return t?e.map(e=>e.id===t?{...e,name:a}:e):[...e,{id:s,name:a,conversations:[]}]}),s},[c]);return{projects:d,saveProject:u,removeProject:(0,s.useCallback)(e=>c(t=>t.filter(t=>t.id!==e)),[c]),assignConversation:(0,s.useCallback)((e,t)=>c(a=>{if(t&&!a.some(e=>e.id===t))throw Error("Project no longer exists");return a.map(a=>({...a,conversations:[...a.conversations.filter(t=>t!==e),...a.id===t?[e]:[]]}))}),[c])}}function x(e){let n,i,r,o,c,u,p,g,x,b,v=(0,a.c)(42),{conversationId:j,anchor:y,returnFocus:w}=e,{t:k}=(0,l.useTranslation)("paletteOs"),{setProjectDialog:N}=(0,d.useViewContext)(),{projects:C,assignConversation:S}=f(),_=(0,s.useRef)(w??(document.activeElement instanceof HTMLElement?document.activeElement:void 0));v[0]!==y?(n=()=>{let e=document.activeElement?.getBoundingClientRect();return y??{x:e?.left??16,y:(e?.bottom??16)+4}},v[0]=y,v[1]=n):n=v[1];
1let[T]=(0,s.useState)(n);v[2]!==S||v[3]!==j||v[4]!==k?(i=e=>{try{S(j,e)}catch{m.toast.error(k("projects.saveFailed","Could not save projects in this browser. Your conversations are unchanged."))}},v[2]=S,v[3]=j,v[4]=k,v[5]=i):i=v[5];let E=i;if(v[6]!==k?(r=k("projects.recent","Move to Recent"),v[6]=k,v[7]=r):r=v[7],v[8]!==E?(o=()=>E(null),v[8]=E,v[9]=o):o=v[9],v[10]!==r||v[11]!==o?(c={label:r,icon:"h_chat",on:o},v[10]=r,v[11]=o,v[12]=c):c=v[12],v[13]!==E||v[14]!==j||v[15]!==T||v[16]!==C||v[17]!==N||v[18]!==k||v[19]!==c){let e,t,a,s;v[21]!==E?(e=e=>({id:e.id,label:e.name,icon:"h_folder",on:()=>E(e.id)}),v[21]=E,v[22]=e):e=v[22];let n=C.map(e);v[23]!==k?(t=k("projects.add","Add project"),v[23]=k,v[24]=t):t=v[24],v[25]!==j||v[26]!==T||v[27]!==N?(a=()=>setTimeout(()=>N({conversationId:j,create:!0,anchor:T,returnFocus:_.current}),60),v[25]=j,v[26]=T,v[27]=N,v[28]=a):a=v[28],v[29]!==a||v[30]!==t?(s={label:t,icon:"h_plus",on:a},v[29]=a,v[30]=t,v[31]=s):s=v[31],u=[c,...n,s],v[13]=E,v[14]=j,v[15]=T,v[16]=C,v[17]=N,v[18]=k,v[19]=c,v[20]=u}else u=v[20];let A=u;return v[32]!==A?(p=[A],v[32]=A,v[33]=p):p=v[33],v[34]!==T||v[35]!==p?(g={...T,sections:p},v[34]=T,v[35]=p,v[36]=g):g=v[36],v[37]!==N?(x=()=>N(null),v[37]=N,v[38]=x):x=v[38],v[39]!==g||v[40]!==x?(b=(0,t.jsx)(h.PoContextMenu,{ctx:g,onClose:x}),v[39]=g,v[40]=x,v[41]=b):b=v[41],b}function b(e){let i,r,c,m,h,p,g,x,b,v,j,y,w,k,N,C,S=(0,a.c)(52),{conversationId:_,create:T,returnFocus:E}=e,{t:A}=(0,l.useTranslation)("paletteOs"),{setProjectDialog:R,openSession:D}=(0,d.useViewContext)(),{projects:M,saveProject:I,removeProject:O,assignConversation:P}=f(),L=(0,u.useIsViewer)(),F=(0,s.useRef)(E??(document.activeElement instanceof HTMLElement?document.activeElement:null));S[0]!==T?(i=T?{name:""}:null,S[0]=T,S[1]=i):i=S[1];
1let[$,B]=(0,s.useState)(i),[H,z]=(0,s.useState)(null),[U,G]=(0,s.useState)("");S[2]!==A?(r=e=>{try{e(),G("")}catch{G(A("projects.saveFailed","Could not save projects in this browser. Your conversations are unchanged."))}},S[2]=A,S[3]=r):r=S[3];let W=r;S[4]!==_||S[5]!==$||S[6]!==H||S[7]!==A?(c=H?A("projects.delete","Delete project"):$?$.id?A("projects.rename","Rename project"):A("projects.new","New project"):_?A("projects.move","Move to project"):A("projects.title","Projects"),S[4]=_,S[5]=$,S[6]=H,S[7]=A,S[8]=c):c=S[8];let K=c;return S[9]!==$?(m=$?{"aria-describedby":void 0}:{},S[9]=$,S[10]=m):m=S[10],S[11]!==E?(h=()=>{F.current=E??(document.activeElement instanceof HTMLElement?document.activeElement:null)},S[11]=E,S[12]=h):h=S[12],S[13]===Symbol.for("react.memo_cache_sentinel")?(p=e=>{e.preventDefault(),F.current?.isConnected&&F.current.focus()},S[13]=p):p=S[13],S[14]!==K?(g=(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:K})}),S[14]=K,S[15]=g):g=S[15],S[16]!==A?(x=A("shell.close","Close"),S[16]=A,S[17]=x):x=S[17],S[18]===Symbol.for("react.memo_cache_sentinel")?(b=(0,t.jsx)(o.Glyph,{name:"h_close"}),S[18]=b):b=S[18],S[19]!==x?(v=(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":x,children:b})}),S[19]=x,S[20]=v):v=S[20],S[21]!==v||S[22]!==g?(j=(0,t.jsxs)("div",{className:"ssSearchHead",children:[g,v]}),S[21]=v,S[22]=g,S[23]=j):j=S[23],S[24]!==$||S[25]!==H||S[26]!==A?(y=!$&&(0,t.jsx)(n.Dialog.Description,{asChild:!0,children:(0,t.jsx)("p",{className:"ssDlgP",children:H?A("projects.deleteNote","Only the group is deleted. Conversations stay in Recent."):A("projects.note","Group conversations by project. Groups are stored in this browser for your account and workspace, separately from Drive folders.")})}),S[24]=$,S[25]=H,S[26]=A,S[27]=y):y=S[27],S[28]!==U?(w=U&&(0,t.jsx)("p",{className:"ssProjectError",role:"alert",children:U}),S[28]=U,S[29]=w):w=S[29],S[30]!==P||S[31]!==_||S[32]!==$||S[33]!==L||S[34]!==D||S[35]!==W||S[36]!==M||S[37]!==H||S[38]!==O||S[39]!==I||S[40]!==R||S[41]!==A?(k=H?(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>z(null),children:A("shell.cancel","Cancel")}),(0,t.jsx)("button",{type:"button",className:"cfBtn cfDanger",onClick:()=>W(()=>{O(H),z(null)}),children:A("projects.delete","Delete project")})]}):$?(0,t.jsxs)("form",{className:"ssProjectForm",onSubmit:e=>{e.preventDefault(),W(()=>{let e=I($.name,$.id);_&&!$.id&&P(_,e),R(null)})},children:[(0,t.jsxs)("label",{children:[A("session.rename.field","Name / value"),(0,t.jsx)("input",{autoFocus:!0,required:!0,maxLength:200,value:$.name,onChange:e=>B({...$,name:e.target.value})})]}),(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>R(null),children:A("shell.cancel","Cancel")}),(0,t.jsx)("button",{type:"submit",className:"cfBtn cfPrimary",disabled:!$.name.trim(),children:A("session.rename.save","Save")})]})]}):(0,t.jsxs)(t.Fragment,{children:[!M.length&&(0,t.jsx)("div",{className:"ssSearchEmpty",children:A("projects.empty","No projects yet.")}),M.map(e=>(0,t.jsxs)("div",{className:"ssDlgRow ssProjectRow",children:[(0,t.jsx)(o.Glyph,{name:"h_folder"}),(0,t.jsx)("span",{className:"ssProjectName",children:e.name}),(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:L,onClick:()=>{R(null),D({newThread:!0,projectId:e.id})},children:A("projects.newChat","New chat")}),(0,t.jsx)("button",{type:"button",className:"ssDlgIcon","aria-label":A("projects.rename","Rename project"),onClick:()=>B({id:e.id,name:e.name}),children:(0,t.jsx)(o.Glyph,{name:"h_pencil"})}),(0,t.jsx)("button",{type:"button",className:"ssDlgIcon","aria-label":A("projects.delete","Delete project"),onClick:()=>z(e.id),children:(0,t.jsx)(o.Glyph,{name:"h_trash"})})]},e.id)),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn cfPrimary",onClick:()=>B({name:""}),children:A("projects.add","Add project")})})]}),S[30]=P,S[31]=_,S[32]=$,S[33]=L,S[34]=D,S[35]=W,S[36]=M,S[37]=H,S[38]=O,S[39]=I,S[40]=R,S[41]=A,S[42]=k):k=S[42],S[43]!==y||S[44]!==w||S[45]!==k?(N=(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody",children:[y,w,k]}),S[43]=y,S[44]=w,S[45]=k,S[46]=N):N=S[46],S[47]!==j||S[48]!==N||S[49]!==m||S[50]!==h?(C=(0,t.jsxs)(n.Dialog.Content,{className:"ssSearchDlg ssDlg",...m,onOpenAutoFocus:h,onCloseAutoFocus:p,children:[j,N]}),S[47]=j,S[48]=N,S[49]=m,S[50]=h,S[51]=C):C=S[51],C}e.s(["useSessionProjects",0,f],748317),e.s(["ProjectsDialog",0,function(){let e,s,l,i,r,o,c=(0,a.c)(16),{projectDialog:u,setProjectDialog:m}=(0,d.useViewContext)();if(u?.conversationId&&!u.create){let e;return c[0]!==u.anchor||c[1]!==u.conversationId||c[2]!==u.returnFocus?(e=(0,t.jsx)(x,{conversationId:u.conversationId,anchor:u.anchor,returnFocus:u.returnFocus}),c[0]=u.anchor,c[1]=u.conversationId,c[2]=u.returnFocus,c[3]=e):e=c[3],e}let h=null!==u;return c[4]!==m?(e=e=>{e||m(null)},c[4]=m,c[5]=e):e=c[5],c[6]===Symbol.for("react.memo_cache_sentinel")?(s={display:"contents"},l=(0,t.jsx)(n.Dialog.Overlay,{className:"ssSearchBd"}
1),c[6]=s,c[7]=l):(s=c[6],l=c[7]),c[8]!==u?(i=u&&(0,t.jsx)(b,{conversationId:u.conversationId,create:u.create,returnFocus:u.returnFocus}),c[8]=u,c[9]=i):i=c[9],c[10]!==i?(r=(0,t.jsx)(n.Dialog.Portal,{children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:s,children:[l,i]})}),c[10]=i,c[11]=r):r=c[11],c[12]!==h||c[13]!==e||c[14]!==r?(o=(0,t.jsx)(n.Dialog.Root,{open:h,onOpenChange:e,children:r}),c[12]=h,c[13]=e,c[14]=r,c[15]=o):o=c[15],o}],917870);var v=e.i(363178);let j="light",y="cell";function w(e){return e?"dark":j}function k(){let e,t,s,n=(0,a.c)(7),{resolvedTheme:l,setTheme:i}=(0,v.useTheme)();n[0]!==i?(e=e=>{i("dark"===e?"dark":"light")},n[0]=i,n[1]=e):e=n[1];let r=e,o="dark"===l;return n[2]!==o?(t=w(o),n[2]=o,n[3]=t):t=n[3],n[4]!==r||n[5]!==t?(s={canvas:t,gridMode:y,pickCanvas:r,pickGridMode:N},n[4]=r,n[5]=t,n[6]=s):s=n[6],s}function N(){}e.s(["applyPaletteTheme",0,function(){"u">typeof document&&function(e=function(){try{return"dark"===localStorage.getItem("theme")?"dark":j}catch{return j}}()){if("u"<typeof document)return;let t="dark"===e?"dark":j,a=document.documentElement;a.setAttribute("data-canvas",t),a.removeAttribute("data-acc"),window.dispatchEvent(new CustomEvent("palette:theme-change",{detail:{themeId:"palette-os",canvas:t,gridMode:y,colorMode:t}}))}(w(document.documentElement.classList.contains("dark")))},"canvasForMode",0,w,"usePaletteTheme",0,k],127536);let C=[["newChat","New chat","Ctrl Shift O"],["search","Search conversations","Ctrl K"],["toggleList","Collapse / expand the list","Ctrl B"],["rename","Rename","Alt Ctrl R"],["pin","Pin / unpin","Alt Ctrl P"],["reorderPinned","Move pinned conversation","Alt â / â"],["archive","Archive the conversation","Ctrl Shift A"],["sideChat","Side chat","Alt Ctrl S"],["focusComposer","Focus message input","Ctrl L"],["newline","New line","Shift Enter"],["escape","Close popup / work panel","Esc"],["resizeList","Resize list (focus the edge)","â / â · Shift"],["resizePanel","Resize work panel","â / â · Home / End"],["menuMove","Move between menu items","â / â / Home / End"]];function S(e){let i,r,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,S,_,T=(0,a.c)(40);T[0]!==e?(i=void 0===e?{}:e,T[0]=e,T[1]=i):i=T[1];let{open:E,onOpenChange:A}=i,{t:R}=(0,l.useTranslation)("paletteOs"),[D,M]=(0,s.useState)(!1),I=E??D,O=A??M,P=(0,s.useRef)(null);return T[2]!==E||T[3]!==O?(r=()=>{if(void 0!==E)return;let e=()=>{P.current=document.activeElement instanceof HTMLElement?document.activeElement:null,O(!0)};return window.addEventListener("po:shortcuts",e),()=>window.removeEventListener("po:shortcuts",e)},d=[E,O],T[2]=E,T[3]=O,T[4]=r,T[5]=d):(r=T[4],d=T[5]),(0,s.useEffect)(r,d),T[6]===Symbol.for("react.memo_cache_sentinel")?(c={display:"contents"},u=(0,t.jsx)(n.Dialog.Overlay,{className:"ssSearchBd"}),T[6]=c,T[7]=u):(c=T[6],u=T[7]),T[8]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{P.current=document.activeElement instanceof HTMLElement?document.activeElement:null},h=e=>{e.preventDefault(),P.current?.isConnected&&P.current.focus()},T[8]=m,T[9]=h):(m=T[8],h=T[9]),T[10]!==R?(p=R("shortcuts.title","Keyboard shortcuts"),T[10]=R,T[11]=p):p=T[11],T[12]!==p?(g=(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:p})}),T[12]=p,T[13]=g):g=T[13],T[14]!==R?(f=R("shell.close","Close"),T[14]=R,T[15]=f):f=T[15],T[16]===Symbol.for("react.memo_cache_sentinel")?(x=(0,t.jsx)(o.Glyph,{name:"h_close"}),T[16]=x):x=T[16],T[17]!==f?(b=(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":f,children:x})}),T[17]=f,T[18]=b):b=T[18],T[19]!==b||T[20]!==g?(v=(0,t.jsxs)("div",{className:"ssSearchHead",children:[g,b]}),T[19]=b,T[20]=g,T[21]=v):v=T[21],T[22]!==R?(j=C.map(e=>{let[a,s,n]=e;return(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:R(`shortcuts.${a}`,s)}),(0,t.jsx)("td",{children:(0,t.jsx)("kbd",{children:n})})]},a)}),T[22]=R,T[23]=j):j=T[23],T[24]!==j?(y=(0,t.jsx)("table",{className:"ssKeyTable",children:(0,t.jsx)("tbody",{children:j})}),T[24]=j,T[25]=y):y=T[25],T[26]!==R?(w=R("shortcuts.note","Browser / OS shortcuts may take precedence. Input commands: /plan, /help, /new."),T[26]=R,T[27]=w):w=T[27],T[28]!==w?(k=(0,t.jsx)(n.Dialog.Description,{asChild:!0,children:(0,t.jsx)("p",{className:"ssDlgP small",children:w})}),T[28]=w,T[29]=k):k=T[29],T[30]!==y||T[31]!==k?(N=(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody",children:[y,k]}),T[30]=y,T[31]=k,T[32]=N):N=T[32],T[33]!==v||T[34]!==N?(S=(0,t.jsx)(n.Dialog.Portal,{container:"u">typeof document?document.fullscreenElement??void 0:void 0,children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:c,children:[u,(0,t.jsxs)(n.Dialog.Content,{className:"ssSearchDlg ssDlg",onOpenAutoFocus:m,onCloseAutoFocus:h,children:[v,N]})]})}),T[33]=v,T[34]=N,T[35]=S):S=T[35],T[36]!==I||T[37]!==O||T[38]!==S?(_=(0,t.jsx)(n.Dialog.Root,{open:I,onOpenChange:O,children:S}),T[36]=I,T[37]=O,T[38]=S,T[39]=_):_=T[39],_}e.s(["ShortcutsDialog",0,S],527939);let _="palette_session_preferences_v1",T="po:session-preferences",E={density:"comfortable",enterSend:!0,autoPanel:!0};function A(e){let t=e&&"object"==typeof e?e:{};return{density:"compact"===t.density||"normal"===t.density||"comfortable"===t.density?t.density:E.density,enterSend:"boolean"==typeof t.enterSend?t.enterSend:E.enterSend,autoPanel:"boolean"==typeof t.autoPanel?t.autoPanel:E.autoPanel}}function R(){try{return A(JSON.parse(localStorage.getItem(_)??"null"))}catch{return{...E}}}
1function D(){let e,t,n,l,i=(0,a.c)(5),[r,o]=(0,s.useState)(R);i[0]===Symbol.for("react.memo_cache_sentinel")?(e=()=>{let e=e=>o(A(e.detail)),t=e=>{(e.key===_||null===e.key)&&o(R())};return window.addEventListener(T,e),window.addEventListener("storage",t),()=>{window.removeEventListener(T,e),window.removeEventListener("storage",t)}},t=[],i[0]=e,i[1]=t):(e=i[0],t=i[1]),(0,s.useEffect)(e,t),i[2]===Symbol.for("react.memo_cache_sentinel")?(n=e=>{let t=A(e);try{localStorage.setItem(_,JSON.stringify(t))}catch{}o(t),window.dispatchEvent(new CustomEvent(T,{detail:t}))},i[2]=n):n=i[2];let d=n;return i[3]!==r?(l={preferences:r,updatePreferences:d},i[3]=r,i[4]=l):l=i[4],l}e.s(["DEFAULT_SESSION_PREFERENCES",0,E,"shouldSendComposerKey",0,function(e,t){return t&&"Enter"===e.key&&!e.shiftKey&&!e.isComposing&&229!==e.keyCode},"useSessionPreferences",0,D],169673),e.s(["SessionSettingsDialog",0,function(){let e,i,r,c,u,m,h,p,g,f,x,b,v,j,y,w,N,C,_,T,A,R,M,I,O,P,L,F,$,B,H,z,U,G,W,K,V,Y,q,J,X,Z,Q,ee,et,ea,es,en,el,ei,er,eo,ed,ec,eu,em,eh,ep,eg,ef,ex,eb,ev,ej,ey,ew,ek,eN,eC,eS,e_,eT,eE=(0,a.c)(178),{t:eA}=(0,l.useTranslation)("paletteOs"),{settingsOpen:eR,setSettingsOpen:eD,setView:eM}=(0,d.useViewContext)(),{canvas:eI,pickCanvas:eO}=k(),{preferences:eP,updatePreferences:eL}=D(),eF=(0,s.useRef)(null),[e$,eB]=(0,s.useState)(!1);eE[0]!==eP?(e=()=>{let e=URL.createObjectURL(new Blob([JSON.stringify(eP,null,2)],{type:"application/json"})),t=document.createElement("a");t.href=e,t.download="palette-browser-preferences.json",t.click(),setTimeout(()=>URL.revokeObjectURL(e),1e3)},eE[0]=eP,eE[1]=e):e=eE[1];let eH=e;eE[2]===Symbol.for("react.memo_cache_sentinel")?(i={display:"contents"},r=(0,t.jsx)(n.Dialog.Overlay,{className:"ssSearchBd"}),eE[2]=i,eE[3]=r):(i=eE[2],r=eE[3]),eE[4]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{eF.current=document.activeElement instanceof HTMLElement?document.activeElement:null},u=e=>{e.preventDefault(),eF.current?.isConnected&&eF.current.focus()},eE[4]=c,eE[5]=u):(c=eE[4],u=eE[5]),eE[6]!==eA?(m=eA("sessionSettings.title","Settings"),eE[6]=eA,eE[7]=m):m=eE[7],eE[8]!==m?(h=(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:m})}),eE[8]=m,eE[9]=h):h=eE[9],eE[10]!==eA?(p=eA("shell.close","Close"),eE[10]=eA,eE[11]=p):p=eE[11],eE[12]===Symbol.for("react.memo_cache_sentinel")?(g=(0,t.jsx)(o.Glyph,{name:"h_close"}),eE[12]=g):g=eE[12],eE[13]!==p?(f=(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":p,children:g})}),eE[13]=p,eE[14]=f):f=eE[14],eE[15]!==h||eE[16]!==f?(x=(0,t.jsxs)("div",{className:"ssSearchHead",children:[h,f]}),eE[15]=h,eE[16]=f,eE[17]=x):x=eE[17],eE[18]!==eA?(b=eA("sessionSettings.theme","Theme"),eE[18]=eA,eE[19]=b):b=eE[19],eE[20]!==b?(v=(0,t.jsx)("strong",{children:b}),eE[20]=b,eE[21]=v):v=eE[21],eE[22]!==eA?(j=eA("sessionSettings.lightNote","Choose a light or dark appearance."),eE[22]=eA,eE[23]=j):j=eE[23],eE[24]!==j?(y=(0,t.jsx)("small",{children:j}),eE[24]=j,eE[25]=y):y=eE[25],eE[26]!==v||eE[27]!==y?(w=(0,t.jsxs)("div",{children:[v,y]}),eE[26]=v,eE[27]=y,eE[28]=w):w=eE[28],eE[29]!==eA?(N=eA("sessionSettings.theme","Theme"),eE[29]=eA,eE[30]=N):N=eE[30],eE[31]!==eO?(C=e=>eO(e.target.value),eE[31]=eO,eE[32]=C):C=eE[32],eE[33]!==eA?(_=eA("sessionSettings.light","Light"),eE[33]=eA,eE[34]=_):_=eE[34],eE[35]!==_?(T=(0,t.jsx)("option",{value:"light",children:_}),eE[35]=_,eE[36]=T):T=eE[36],eE[37]!==eA?(A=eA("sessionSettings.dark","Dark"),eE[37]=eA,eE[38]=A):A=eE[38],eE[39]!==A?(R=(0,t.jsx)("option",{value:"dark",children:A}),eE[39]=A,eE[40]=R):R=eE[40],eE[41]!==eI||eE[42]!==N||eE[43]!==C||eE[44]!==T||eE[45]!==R?(M=(0,t.jsxs)("select",{"aria-label":N,value:eI,onChange:C,children:[T,R]}),eE[41]=eI,eE[42]=N,eE[43]=C,eE[44]=T,eE[45]=R,eE[46]=M):M=eE[46],eE[47]!==w||eE[48]!==M?(I=(0,t.jsxs)("div",{className:"ssSettingRow",children:[w,M]}),eE[47]=w,eE[48]=M,eE[49]=I):I=eE[49],eE[50]!==eA?(O=eA("sessionSettings.density","Conversation list density"),eE[50]=eA,eE[51]=O):O=eE[51],eE[52]!==O?(P=(0,t.jsx)("div",{children:(0,t.jsx)("strong",{children:O})}),eE[52]=O,eE[53]=P):P=eE[53],eE[54]!==eA?(L=eA("sessionSettings.density","Conversation list density"),eE[54]=eA,eE[55]=L):L=eE[55];let ez=eP.density;return eE[56]!==eP||eE[57]!==eL?(F=e=>eL({...eP,density:e.target.value}),eE[56]=eP,eE[57]=eL,eE[58]=F):F=eE[58],eE[59]!==eA?($=["compact","normal","comfortable"].map(e=>(0,t.jsx)("option",{value:e,children:eA(`sessionSettings.${e}`,e)},e)),eE[59]=eA,eE[60]=$):$=eE[60],eE[61]!==eP.density||eE[62]!==L||eE[63]!==F||eE[64]!==$?(B=(0,t.jsx)("select",{"aria-label":L,value:ez,onChange:F,children:$}),eE[61]=eP.density,eE[62]=L,eE[63]=F,eE[64]=$,eE[65]=B):B=eE[65],eE[66]!==P||eE[67]!==B?(H=(0,t.jsxs)("div",{className:"ssSettingRow",children:[P,B]}),eE[66]=P,eE[67]=B,eE[68]=H):H=eE[68],eE[69]!==eA?(z=eA("sessionSettings.enterSend","Send with Enter"),eE[69]=eA,eE[70]=z):z=eE[70],eE[71]!==z?(U=(0,t.jsx)("strong",{children:z}),eE[71]=z,eE[72]=U):U=eE[72],eE[73]!==eA?(G=eA("sessionSettings.enterNote","Shift + Enter inserts a new line."),eE[73]=eA,eE[74]=G):G=eE[74],eE[75]!==G?(W=(0,t.jsx)("small",{children:G}),eE[75]=G,eE[76]=W):W=eE[76],eE[77]!==U||eE[78]!==W?(K=(0,t.jsxs)("span",{children:[U,W]}),eE[77]=U,eE[78]=W,eE[79]=K):K=eE[79],eE[80]!==eP||eE[81]!==eL?(V=e=>eL({...eP,enterSend:e.target.checked}),eE[80]=eP,eE[81]=eL,eE[82]=V):V=eE[82],eE[83]!==eP.enterSend||eE[84]!==V?(Y=(0,t.jsx)("input",{type:"checkbox",className:"ssSettingSwitch",checked:eP.enterSend,onChange:V}),eE[83]=eP.enterSend,eE[84]=V,eE[85]=Y):Y=eE[85],eE[86]!==K||eE[87]!==Y?(q=(0,t.jsxs)("label",{className:"ssSettingRow",children:[K,Y]}),eE[86]=K,eE[87]=Y,eE[88]=q):q=eE[88],eE[89]!==eA?(J=eA("sessionSettings.autoPanel","Open output panel automatically"),eE[89]=eA,eE[90]=J):J=eE[90],eE[91]!==J?(X=(0,t.jsx)("strong",{children:J}),eE[91]=J,eE[92]=X):X=eE[92],eE[93]!==eA?(Z=eA("sessionSettings.autoNote","On by default. Open the panel when an output is generated."),eE[93]=eA,eE[94]=Z):Z=eE[94],eE[95]!==Z?(Q=(0,t.jsx)("small",{children:Z}),eE[95]=Z,eE[96]=Q):Q=eE[96],eE[97]!==X||eE[98]!==Q?(ee=(0,t.jsxs)("span",{children:[X,Q]}),eE[97]=X,eE[98]=Q,eE[99]=ee):ee=eE[99],eE[100]!==eP||eE[101]!==eL?(et=e=>eL({...eP,autoPanel:e.target.checked}),eE[100]=eP,eE[101]=eL,eE[102]=et):et=eE[102],eE[103]!==eP.autoPanel||eE[104]!==et?(ea=(0,t.jsx)("input",{type:"checkbox",className:"ssSettingSwitch",checked:eP.autoPanel,onChange:et}),eE[103]=eP.autoPanel,eE[104]=et,eE[105]=ea):ea=eE[105],eE[106]!==ee||eE[107]!==ea?(es=(0,t.jsxs)("label",{className:"ssSettingRow",children:[ee,ea]}),eE[106]=ee,eE[107]=ea,eE[108]=es):es=eE[108],eE[109]!==eA?(en=eA("sessionSettings.local","Browser preferences"),eE[109]=eA,eE[110]=en):en=eE[110],eE[111]!==en?(el=(0,t.jsx)("strong",{children:en}),eE[111]=en,eE[112]=el):el=eE[112],eE[113]!==eA?(ei=eA("sessionSettings.localNote","Only these preferences are backed up or reset. Your conversations and files are kept."),eE[113]=eA,eE[114]=ei):ei=eE[114],eE[115]!==ei?(er=(0,t.jsx)("small",{children:ei}),eE[115]=ei,eE[116]=er):er=eE[116],eE[117]!==el||eE[118]!==er?(eo=(0,t.jsxs)("div",{children:[el,er]}),eE[117]=el,eE[118]=er,eE[119]=eo):eo=eE[119],eE[120]!==eA?(ed=eA("sessionSettings.backup","Back up"),eE[120]=eA,eE[121]=ed):ed=eE[121],eE[122]!==eH||eE[123]!==ed?(ec=(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:eH,children:ed}),eE[122]=eH,eE[123]=ed,eE[124]=ec):ec=eE[124],eE[125]!==eL?(eu=()=>eL({...E}),eE[125]=eL,eE[126]=eu):eu=eE[126],eE[127]!==eA?(em=eA("sessionSettings.reset","Reset"),eE[127]=eA,eE[128]=em):em=eE[128],eE[129]!==eu||eE[130]!==em?(eh=(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:eu,children:em}),eE[129]=eu,eE[130]=em,eE[131]=eh):eh=eE[131],eE[132]!==eo||eE[133]!==ec||eE[134]!==eh?(ep=(0,t.jsxs)("div",{className:"ssSettingRow",children:[eo,ec,eh]}),eE[132]=eo,eE[133]=ec,eE[134]=eh,eE[135]=ep):ep=eE[135],eE[136]!==eD?(eg=()=>{eD(!1),setTimeout(()=>eB(!0),60)},eE[136]=eD,eE[137]=eg):eg=eE[137],eE[138]!==eA?(ef=eA("shortcuts.title","Keyboard shortcuts"),eE[138]=eA,eE[139]=ef):ef=eE[139],eE[140]!==eg||eE[141]!==ef?(ex=(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:eg,children:ef}),eE[140]=eg,eE[141]=ef,eE[142]=ex):ex=eE[142],eE[143]!==eD||eE[144]!==eM?(eb=()=>{eD(!1),eM("setting")},eE[143]=eD,eE[144]=eM,eE[145]=eb):eb=eE[145],eE[146]!==eA?(ev=eA("sessionSettings.all","All settings"),eE[146]=eA,eE[147]=ev):ev=eE[147],eE[148]!==eb||eE[149]!==ev?(ej=(0,t.jsx)("button",{type:"button",className:"cfBtn cfPrimary",onClick:eb,children:ev}),eE[148]=eb,eE[149]=ev,eE[150]=ej):ej=eE[150],eE[151]!==ex||eE[152]!==ej?(ey=(0,t.jsxs)("div",{className:"ssDlgActions",children:[ex,ej]}
1),eE[151]=ex,eE[152]=ej,eE[153]=ey):ey=eE[153],eE[154]!==eA?(ew=eA("sessionSettings.saved","Preferences are saved in this browser."),eE[154]=eA,eE[155]=ew):ew=eE[155],eE[156]!==ew?(ek=(0,t.jsx)(n.Dialog.Description,{asChild:!0,children:(0,t.jsx)("p",{className:"ssDlgP small",children:ew})}),eE[156]=ew,eE[157]=ek):ek=eE[157],eE[158]!==I||eE[159]!==H||eE[160]!==q||eE[161]!==es||eE[162]!==ep||eE[163]!==ey||eE[164]!==ek?(eN=(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody",children:[I,H,q,es,ep,ey,ek]}),eE[158]=I,eE[159]=H,eE[160]=q,eE[161]=es,eE[162]=ep,eE[163]=ey,eE[164]=ek,eE[165]=eN):eN=eE[165],eE[166]!==x||eE[167]!==eN?(eC=(0,t.jsx)(n.Dialog.Portal,{children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:i,children:[r,(0,t.jsxs)(n.Dialog.Content,{className:"ssSearchDlg ssDlg",onOpenAutoFocus:c,onCloseAutoFocus:u,children:[x,eN]})]})}),eE[166]=x,eE[167]=eN,eE[168]=eC):eC=eE[168],eE[169]!==eD||eE[170]!==eR||eE[171]!==eC?(eS=(0,t.jsx)(n.Dialog.Root,{open:eR,onOpenChange:eD,children:eC}),eE[169]=eD,eE[170]=eR,eE[171]=eC,eE[172]=eS):eS=eE[172],eE[173]!==e$?(e_=(0,t.jsx)(S,{open:e$,onOpenChange:eB}),eE[173]=e$,eE[174]=e_):e_=eE[174],eE[175]!==eS||eE[176]!==e_?(eT=(0,t.jsxs)(t.Fragment,{children:[eS,e_]}),eE[175]=eS,eE[176]=e_,eE[177]=eT):eT=eE[177],eT}],161873);var M=e.i(209165),I=e.i(702107);function O({onNote:e,icon:a,disabled:n,dictation:i}){let{t:r}=(0,l.useTranslation)("paletteOs"),d=(0,s.useRef)(null),c=(0,s.useRef)([]),u=(0,s.useRef)(!0),h=(0,s.useRef)(!0),p=(0,s.useRef)(null),g=(0,s.useRef)(!1),[f,x]=(0,s.use
1State)(!1),[b,v]=(0,s.useState)(!1),[j,y]=(0,s.useState)(0);(0,s.useEffect)(()=>{if(!b)return;let e=Date.now(),t=window.setInterval(()=>y(Math.floor((Date.now()-e)/1e3)),250);return()=>window.clearInterval(t)},[b]),(0,s.useEffect)(()=>(h.current=!0,()=>{h.current=!1,u.current=!1,d.current&&"inactive"!==d.current.state&&d.current.stop(),p.current?.getTracks().forEach(e=>e.stop())}),[]);let w=async()=>{if(!g.current&&!n){g.current=!0,x(!0);try{let t=await navigator.mediaDevices.getUserMedia({audio:!0});if(!h.current)return void t.getTracks().forEach(e=>e.stop());p.current=t;let a="u"<typeof MediaRecorder||!MediaRecorder.isTypeSupported?null:[{mimeType:"audio/webm;codecs=opus",extension:"webm"},{mimeType:"audio/webm",extension:"webm"},{mimeType:"audio/mp4;codecs=mp4a.40.2",extension:"m4a"},{mimeType:"audio/mp4",extension:"m4a"}].find(e=>MediaRecorder.isTypeSupported(e.mimeType))??null,s=new MediaRecorder(t,a?{mimeType:a.mimeType}:void 0);c.current=[],u.current=!0,s.ondataavailable=e=>{e.data.size&&c.current.push(e.data)},s.onstop=()=>{if(t.getTracks().forEach(e=>e.stop()),p.current=null,d.current=null,!h.current||(v(!1),!u.current||0===c.current.length))return;let n=s.mimeType||a?.mimeType||"audio/webm",l=a?.extension??(n.includes("mp4")?"m4a":"webm"),i=new Blob(c.current,{type:n});e(new File([i],`voice-note.${l}`,{type:n}))},s.onerror=()=>{u.current=!1,"inactive"!==s.state&&s.stop(),t.getTracks().forEach(e=>e.stop()),h.current&&(v(!1),m.toast.error(r("voice.micDenied","Microphone unavailable")))},d.current=s,y(0),v(!0),s.start()}catch{p.current?.getTracks().forEach(e=>e.stop()),p.current=null,d.current=null,h.current&&(v(!1),m.toast.error(r("voice.micDenied","Microphone unavailable")))}finally{g.current=!1,h.current&&x(!1)}}},k=e=>{let t=d.current;t&&"inactive"!==t.state&&(u.current=e,t.stop())};return"MediaRecorder"in window?b?(0,t.jsxs)("span",{className:"tlRec",children:[(0,t.jsx)("span",{className:"tlRecDot","aria-hidden":!0}),(0,t.jsx)("span",{className:"tlRecTime",children:`${String(Math.floor(j/60)).padStart(2,"0")}:${String(j%60).padStart(2,"0")}`}),(0,t.jsx)("button",{className:"tlRecBtn",title:r("voice.discard","Discard"),"aria-label":r("voice.discard","Discard"),onClick:()=>k(!1),children:(0,t.jsx)(o.Glyph,{name:"h_close",className:"tlRecorderGlyph"})}),(0,t.jsx)("button",{className:"tlRecBtn tlRecStop",title:i?r("voice.useRecording","Use recording"):r("voice.stopAndSend","Stop and send"),"aria-label":i?r("voice.useRecording","Use recording"):r("voice.stopAndSend","Stop and send"),onClick:()=>k(!0),children:(0,t.jsx)(o.Glyph,{name:i?"h_check":"h_arrowUp",className:"tlRecorderGlyph"})})]}):(0,t.jsx)("button",{type:"button",className:i?"btn primary":"cdIcon cdMic",title:r(f?"voice.starting":i?"voice.startMicrophone":"voice.record"),"aria-label":r(f?"voice.starting":i?"voice.startMicrophone":"voice.record"),disabled:n||f,"aria-busy":f,onClick:()=>void w(),children:i?r(f?"voice.starting":"voice.startMicrophone"):a??(0,t.jsx)(o.Glyph,{name:"h_mic",className:"tlRecorderGlyph"})}):null}e.s(["MicButton",0,O],602725),e.s(["VoiceInput",0,function({onText:e}){let{t:a}=(0,l.useTranslation)("paletteOs"),[i,r]=(0,s.useState)(!1),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!1),[h,p]=(0,s.use
1State)(!1),g=(0,s.useRef)(null),f="MediaRecorder"in window&&!!navigator.mediaDevices?.getUserMedia;(0,s.useEffect)(()=>()=>g.current?.abort(),[]);let x=e=>{e||(g.current?.abort(),g.current=null,m(!1),c(null),p(!1)),r(e)},b=async t=>{if(g.current)return;let a=new AbortController;g.current=a,c(t),m(!0),p(!1);try{let s=new FormData;s.append("file",t);let n=await (0,M.apiFetch)("/api/v1/general-chat/transcribe",{method:"POST",body:s,signal:a.signal});if(!n.ok)throw Error("Transcription failed");let l=await n.json(),i=l&&"object"==typeof l&&"transcript"in l&&"string"==typeof l.transcript?l.transcript.trim():"";if(!i)throw Error("No speech recognized");if(a.signal.aborted)return;e(i),x(!1)}catch{a.signal.aborted||p(!0)}finally{g.current===a&&(g.current=null,m(!1))}};return(0,t.jsxs)(n.Dialog.Root,{open:i,onOpenChange:x,children:[(0,t.jsx)(n.Dialog.Trigger,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"cdIcon cdMic","aria-label":a("voice.input"),title:a("voice.input"),children:(0,t.jsx)(o.Glyph,{name:"h_mic"})})}),(0,t.jsxs)(I.OverlayPortal,{children:[(0,t.jsx)(n.Dialog.Overlay,{className:"ssSearchBd"}),(0,t.jsxs)(n.Dialog.Content,{className:"ssSearchDlg ssDlg",children:[(0,t.jsxs)("div",{className:"ssSearchHead",children:[(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:a("voice.input")})}),(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":a("shell.close","Close"),children:(0,t.jsx)(o.Glyph,{name:"h_close"})})})]}),(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody",children:[(0,t.jsx)(n.Dialog.Description,{className:"ssDlgP",children:a(f?"voice.inputDescription":"voice.unsupported")}),u&&(0,t.jsx)("p",{className:"ssDlgP",role:"status",children:a("voice.transcribing")}),h&&(0,t.jsx)("p",{className:"ssDlgP",role:"alert",children:a("voice.transcriptionFailed")}),d&&!u&&(0,t.jsx)("button",{type:"button",className:"btn primary",onClick:()=>void b(d),children:a("voice.retryTranscription")}),f&&!d&&(0,t.jsx)(O,{dictation:!0,onNote:e=>void b(e)})]})]})]})]})}],198197);let P="palette_list_w_px";function L(){try{let e=localStorage.getItem(P),t=e?.trim()?Number(e):NaN;return Number.isFinite(t)?Math.max(220,Math.min(420,Math.round(t))):null}catch{return null}}e.s(["SidebarResizer",0,function(e){let n,i,r,o,d=(0,a.c)(10),{open:c,label:u}=e,{t:m}=(0,l.useTranslation)("paletteOs"),h=(0,s.useRef)(null);d[0]!==c||d[1]!==m?(n=()=>{let e=h.current,t=e?.parentElement,a=e?.closest(".po-root");if(!e||!t||!a)return;let s=a.querySelector(".sessionWorkspace"),n=L(),l=null,i=0,r=()=>window.innerWidth>760&&a.getBoundingClientRect().width>760,o=()=>{var e,t,n;let l;return e=a.getBoundingClientRect().width,t=a.querySelector(".po-rail")?.getBoundingClientRect().width??0,n=a.getBoundingClientRect().width>1100&&!!s?.querySelector(":scope > aside")&&!s?.querySelector(":scope > .spvExpanded"),l=Math.max(.3,Math.min(.65,(s?parseFloat(getComputedStyle(s).getPropertyValue("--work-width"))/100:.5786)||.5786)),{min:220,max:Math.max(220,Math.min(420,Math.floor(e-t-(n?Math.max(680,300/(1-l)):360))))}},d=t=>{let s=void 0===t?n:t;if(e.hidden=!c||!r(),!r())return void a.style.removeProperty("--po-list-w");let l=o(),i=parseFloat(getComputedStyle(a).getPropertyValue("--list-width"))||259,d=Math.round(Math.max(l.min,Math.min(l.max,s??i)));a.style.setProperty("--po-list-w",`${d}px`),e.setAttribute("aria-valuemin",String(l.min)),e.setAttribute("aria-valuemax",String(l.max)),e.setAttribute("aria-valuenow",String(d)),e.setAttribute("aria-valuetext",m("sidebarResize.pixels",{defaultValue:"{{width}} pixels",width:d}))},u=e=>{n=e;try{null===e?localStorage.removeItem(P):localStorage.setItem(P,String(e))}catch{}},p=t=>{if(!l)return;let s=l;l=null,a.classList.remove("sidebar-resizing"),e.hasPointerCapture(s.id)&&e.releasePointerCapture(s.id),t&&s.moved&&s.width!==s.start&&u(s.width),d()},g=()=>{i||(i=requestAnimationFrame(()=>{i=0,d(l?.width??n)}))},f=s=>{if(l||e.hidden||!r()||0!==s.button||!1===s.isPrimary)return;s.preventDefault(),e.focus({preventScroll:!0});let n=t.getBoundingClientRect().width;l={id:s.pointerId,x:s.clientX,start:n,width:n,moved:!1},e.setPointerCapture(s.pointerId),a.classList.add("sidebar-resizing")},x=e=>{if(!l||l.id!==e.pointerId)return;let t=e.clientX-l.x;if(!l.moved&&2>Math.abs(t))return;e.preventDefault(),l.moved=!0;let a=o();l.width=Math.round(Math.max(a.min,Math.min(a.max,l.start+t))),d(l.width)},b=e=>{l?.id===e.pointerId&&p(!0)},v=e=>{l?.id===e.pointerId&&p(!1)},j=()=>p(!1),y=()=>{p(!1),g()},w=()=>{document.hidden&&p(!1)},k=e=>{"Escape"===e.key&&l&&(e.preventDefault(),e.stopImmediatePropagation(),p(!1))},N=()=>{p(!1),u(null),d()},C=e=>{if(!r()||!["ArrowLeft","ArrowRight","Home","End","Enter"].includes(e.ke
1y))return;if(e.preventDefault(),e.stopPropagation(),p(!1),"Enter"===e.key)return void N();let a=o(),s=t.getBoundingClientRect().width,n="Home"===e.key?a.min:"End"===e.key?a.max:Math.max(a.min,Math.min(a.max,s+("ArrowRight"===e.key?1:-1)*(e.shiftKey?24:8)));n!==s&&u(n),d()},S=e=>{(e.key===P||null===e.key)&&(p(!1),n=L(),d())};e.addEventListener("pointerdown",f),e.addEventListener("lostpointercapture",j),e.addEventListener("dblclick",N),e.addEventListener("keydown",C),window.addEventListener("pointermove",x,{passive:!1}),window.addEventListener("pointerup",b),window.addEventListener("pointercancel",v),window.addEventListener("blur",j),window.addEventListener("resize",y),window.addEventListener("keydown",k,!0),window.addEventListener("storage",S),document.addEventListener("visibilitychange",w);let _=new MutationObserver(e=>{e.some(e=>e.target===s||e.target instanceof HTMLElement&&e.target.parentElement===s&&"ASIDE"===e.target.tagName)&&g()});s&&_.observe(s,{attributes:!0,subtree:!0,attributeFilter:["class","style"],childList:!0});let T="u"<typeof ResizeObserver?null:new ResizeObserver(y);return T?.observe(a),d(),()=>{p(!1),cancelAnimationFrame(i),_.disconnect(),T?.disconnect(),e.removeEventListener("pointerdown",f),e.removeEventListener("lostpointercapture",j),e.removeEventListener("dblclick",N),e.removeEventListener("keydown",C),window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",b),window.removeEventListener("pointercancel",v),window.removeEventListener("blur",j),window.removeEventListener("resize",y),window.removeEventListener("keydown",k,!0),window.removeEventListener("storage",S),document.removeEventListener("visibilitychange",w),a.style.removeProperty("--po-list-w")}},i=[c,m],d[0]=c,d[1]=m,d[2]=n,d[3]=i):(n=d[2],i=d[3]),(0,s.useEffect)(n,i);let p=!c;return d[4]!==u||d[5]!==m?(r=u??m("sidebarResize.title","Resize conversation list"),d[4]=u,d[5]=m,d[6]=r):r=d[6],d[7]!==p||d[8]!==r?(o=(0,t.jsx)("div",{ref:h,className:"poSidebarResizer",hidden:p,role:"separator","aria-orientation":"vertical","aria-label":r,tabIndex:0}),d[7]=p,d[8]=r,d[9]=o):o=d[9],o}],455435);var F=e.i(309789);e.s(["PanelRightOpen",()=>F.default],430172);var $=e.i(621847);e.s(["Square",()=>$.default],752044),e.s(["MessageFeedback",0,function({messageId:e,surface:a,rating:n,onChange:i,image:r=!1}){let{t:d}=(0,l.useTranslation)("paletteOs"),[c,u]=(0,s.useState)(!1),h=(0,s.useRef)(!1),p=r?d("session.msg.likeImage","Good image"):d("session.msg.like","Good response"),g=r?d("session.msg.dislikeImage","Poor image"):d("session.msg.dislike","Poor response"),f=async t=>{if(h.current)return;h.current=!0,u(!0);let s=n===t?null:t;try{await (0,M.apiFetch)("/api/v1/general-chat/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message_id:e,rating:s??"clear",surface:a})}),i(s),m.toast.success(s?d("session.msg.feedbackSaved","Feedback saved"):d("session.msg.feedbackCleared","Feedback removed"))}catch{m.toast.error(d("session.msg.feedbackFailed","Could not save feedback. Your previous vote is unchanged."))}finally{h.current=!1,u(!1)}};return(0,t.jsxs)("span",{className:"ssFeedback","aria-busy":c,children:[(0,t.jsx)("button",{type:"button",disabled:c,"aria-pressed":"up"===n,onClick:()=>void f("up"),title:p,"aria-label":p,children:(0,t.jsx)(o.Glyph,{name:"h_responseLike"})}),(0,t.jsx)("button",{type:"button",disabled:c,"aria-pressed":"down"===n,onClick:()=>void f("down"),title:g,"aria-label":g,children:(0,t.jsx)(o.Glyph,{name:"h_responseDislike"})})]})}],510798);var B=e.i(452726);e.s(["useSmartSuggestions",0,function({surface:e,enabled:t,threadId:a,dataRoomContext:n,localFiles:l,count:i=3}){let[r,o]=s.useState([]),[d,c]=s.useState(!1),u=s.useRef(0),m=n?`${n.roomId}:${n.kind}:${n.targetId??""}`:"",h=(l??[]).join("\0");return s.useEffect(()=>{let s=++u.current;if(o([]),c(!1),!t)return;let r=new AbortController,d=setTimeout(()=>r.abort(),6400),m=setTimeout(async()=>{try{let t=await (0,M.apiFetch)("/api/v1/general-chat/suggestions",{method:"POST",headers:{"Content-Type":"application/json"},signal:r.signal,body:JSON.stringify({surface:e,thread_id:a||null,data_room_context:n?{room_id:n.roomId,kind:n.kind,target_id:n.targetId,target_name:n.targetName??null}:null,local_files:l??[],locale:(0,B.getPreferredLanguage)(),count:i})});if(s!==u.current)return;if(!t.ok)return void c(!0);let d=await t.json();if(s!==u.current)return;let m=d?.source!=="fallback"&&Array.isArray(d?.suggestions)?d.suggestions.filter(e=>e?.message):[];o(m),c(!0)}catch{s===u.current&&c(!0)}},400);return()=>{clearTimeout(m),clearTimeout(d),r.abort()}},[e,t,a,m,h,i]),{suggestions:r,ready:d}}],413163);var H=e.i(56688);let z=` 2.plogModalBd{position:fixed;inset:0;z-index:9000;background:#151b2438;backdrop-filter:blur(3px)} 3.plogModal{ 4 position:fixed;z-index:9001;top:50%;left:50%;transform:translate(-50%,-50%); 5 box-sizing:border-box;width:min(590px,calc(100vw - 32px));max-height:calc(100dvh - 32px);overflow:auto; 6 padding:56px 110px;border:0;border-radius:24px;background:#f3f1ee;color:#172126; 7 box-shadow:0 24px 100px #0003,0 2px 6px #0000001a; 8} 9.plogModal:focus{outline:none} 10.plogModalClose{ 11 position:absolute;top:22px;right:22px;display:grid;place-items:center;width:32px;height:32px; 12 padding:0;border:0;border-radius:8px;background:transparent;color:#484e52;cursor:pointer; 13} 14.plogModalClose:hover{background:#eeede9} 15.plogModalClose:focus-visible{outline:none;box-shadow:0 0 0 3px rgb(0 111 156 / 22%)} 16.plogModalClose svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round} 17@media (max-width:640px){.plogModal{padding:56px 24px 40px;border-radius:20px}} 18@media (prefers-reduced-motion:no-preference){ 19 .plogModal[data-state="open"]{animation:plogModalIn 220ms cubic-bezier(.2,.8,.2,1)} 20 @keyframes plogModalIn{from{opacity:0;transform:translate(-50%,calc(-50% + 8px))}to{opacity:1;transform:translate(-50%,-50%)}} 21} 22`;e.s(["AuthGate",0,function(e){let s,n,l,r=(0,a.c)(6),{children:o}=e,{requireAuth:d}=(0,i.useAuth)();r[0]!==d?(s=e=>{"key"in e&&"Enter"!==e.key&&" "!==e.key||d()||(e.preventDefault(),e.stopPropagation())},r[0]=d,r[1]=s):s=r[1];let c=s;return r[2]===Symbol.for("react.memo_cache_sentinel")?(n={display:"contents"},r[2]=n):n=r[2],r[3]!==o||r[4]!==c?(l=(0,t.jsx)("span",{style:n,onPointerDownCapture:c,onClickCapture:c,onKeyDownCapture:c,children:o}),r[3]=o,r[4]=c,r[5]=l):l=r[5],l},"LoginModal",0,function(){let e,s,r,o,d,c,u,m,h,p,g,f,x=(0,a.c)(24),{authModalOpen:b,closeAuthModal:v}=(0,i.useAuth)();x[0]===Symbol.for("react.memo_cache_sentinel")?(e=["auth","paletteOs"],x[0]=e):e=x[0];let{t:j}=(0,l.useTranslation)(e);return x[1]!==v?(s=e=>{e||v()},x[1]=v,x[2]=s):s=x[2],x[3]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)("style",{children:z}),o=(0,t.jsx)(n.Dialog.Overlay,{className:"plogModalBd"}),x[3]=r,x[4]=o):(r=x[3],o=x[4]),x[5]!==j?(d=j("auth:signIn"),x[5]=j,x[6]=d):d=x[6],x[7]!==d?(c=(0,t.jsx)(n.Dialog.Title,{className:"sr-only",children:d}),x[7]=d,x[8]=c):c=x[8],x[9]!==j?(u=j("paletteOs:shell.close","Close"),x[9]=j,x[10]=u):u=x[10],x[11]===Symbol.for("react.memo_cache_sentinel")?(m=(0,t.jsx)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M6 6l12 12M18 6L6 18"})}),x[11]=m):m=x[11],x[12]!==u?(h=(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"plogModalClose","aria-label":u,children:m})}
22),x[12]=u,x[13]=h):h=x[13],x[14]!==v?(p=(0,t.jsx)(H.default,{initialMode:"login",embedded:!0,onDone:v}),x[14]=v,x[15]=p):p=x[15],x[16]!==c||x[17]!==h||x[18]!==p?(g=(0,t.jsxs)(n.Dialog.Portal,{children:[r,o,(0,t.jsxs)(n.Dialog.Content,{className:"plogModal","aria-describedby":void 0,children:[c,h,p]})]}),x[16]=c,x[17]=h,x[18]=p,x[19]=g):g=x[19],x[20]!==b||x[21]!==s||x[22]!==g?(f=(0,t.jsx)(n.Dialog.Root,{open:b,onOpenChange:s,children:g}),x[20]=b,x[21]=s,x[22]=g,x[23]=f):f=x[23],f}],151002)},883639,854247,783169,572204,889741,611695,98443,11029,783786,860189,186804,766544,808308,219760,e=>{"use strict";var t=e.i(843476),a=e.i(500932);e.i(785269);var s=e.i(322831),n=e.i(35842),l=e.i(244002),i=e.i(372428),r=e.i(172782),o=e.i(434163);e.s(["UsageBanner",0,function(e){let d,c,u,m,h,p,g,f,x,b,v,j=(0,a.c)(66),{data:y,onViewPlan:w}=e,{t:k,i18n:N}=(0,s.useTranslation)("paletteOs"),{openRoute:C}=(0,n.useOsActions)();if(!y)return null;let{usage:S,plan:_}=y,T=S.usage_state;if("expired"!==T&&"exhausted"!==T&&(S.member_limit?.blocked||S.member_limit?.warning)){let e;return j[0]!==y?(e=(0,t.jsx)(o.MemberLimitNotice,{data:y}),j[0]=y,j[1]=e):e=j[1],e}if("normal"===T)return null;let E="free"===_.id,A="company"===_.plan_type,R=A?S.seat:null;if(j[2]!==A||j[3]!==y.contact_sales_url||j[4]!==y.subscription||j[5]!==E||j[6]!==N.language||j[7]!==C||j[8]!==_||j[9]!==R||j[10]!==T||j[11]!==k||j[12]!==S.monthly_limit||j[13]!==S.monthly_used||j[14]!==S.rollover||j[15]!==S.topup_balance||j[16]!==S.topup_usable||j[17]!==S.welcome_balance){let e,t,a=(0,r.planLabel)(k,_),s=(0,i.formatCredits)(S.monthly_used,N.language),n=(0,i.formatCredits)(S.monthly_limit,N.language),l=(0,i.formatCredits)(S.rollover+S.welcome_balance+(S.topup_usable?S.topup_balance:0),N.language);if(j[23]!==C?(e=e=>C(`/settings?section=billing${e?`&tab=${e}`:""}`),j[23]=C,j[24]=e):e=j[24],u=e,j[25]!==y.contact_sales_url?(t=()=>window.open(y.contact_sales_url,"_blank","noopener,noreferrer"),j[25]=y.contact_sales_url,j[26]=t):t=j[26],d=t,m="",c="",h="info","warning"===T)h="warn",m=E?k("usage.warningFree","Your free usage is running low."):k("usage.warningPaid",{defaultValue:"Your {{plan}} monthly allowance is running low.",plan:a}),c=k("usage.thisMonth",{defaultValue:"This month {{used}} / {{limit}} credits",used:s,limit:n});else if("exhausted"===T&&R){let e,t;h="danger",j[27]!==k?(e=k("usage.seatExhausted"),j[27]=k,j[28]=e):e=j[28],m=e,j[29]!==N.language||j[30]!==R.credits||j[31]!==k?(t=k("usage.seatExhaustedMeta",{amount:(0,i.formatCredits)(R.credits,N.language)}),j[29]=N.language,j[30]=R.credits,j[31]=k,j[32]=t):t=j[32],c=t}else if("exhausted"===T){let e;h="danger",m=E?k("usage.exhaustedFree","You've used all of your available free credits for this cycle."):k("usage.exhaustedPaid",{defaultValue:"You've used all {{plan}} credits for this cycle.",plan:a}),j[33]!==A||j[34]!==E||j[35]!==k?(e=E?k("usage.exhaustedFreeMeta","You can use it again after the next renewal. Upgrade to a paid plan to continue using it now."):A?k("usage.exhaustedCompanyMeta","Contact sales to add credits or seats."):k("usage.exhaustedPaidMeta","Buy extra credits or change your plan to continue now."),j[33]=A,j[34]=E,j[35]=k,j[36]=e):e=j[36],c=e}else if("topup"===T)m=R?k("usage.seatTopupTitle"):k("usage.topupTitle",{defaultValue:"{{plan}} monthly allowance is used up.",plan:a}),c=k("usage.topupInUse",{defaultValue:"Monthly allowance used. Running on {{amount}} extra credits.",amount:l});else if("expired"===T){let e,t;h="danger";let a="pending"===y.subscription.status;j[37]!==a||j[38]!==k?(e=a?k("workspaceSettings:subscription.pendingNote"):k("usage.expired","This workspace's subscription has ended. Contact sales to reactivate."),j[37]=a,j[38]=k,j[39]=e):e=j[39],m=e,j[40]!==a||j[41]!==k?(t=a?"":k("usage.expiredMeta","Existing conversations and files stay available."),j[40]=a,j[41]=k,j[42]=t):t=j[42],c=t}j[2]=A,j[3]=y.contact_sales_url,j[4]=y.subscription,j[5]=E,j[6]=N.language,j[7]=C,j[8]=_,j[9]=R,j[10]=T,j[11]=k,j[12]=S.monthly_limit,j[13]=S.monthly_used,j[14]=S.rollover,j[15]=S.topup_balance,j[16]=S.topup_usable,j[17]=S.welcome_balance,j[18]=d,j[19]=c,j[20]=u,j[21]=m,j[22]=h}else d=j[18],c=j[19],u=j[20],m=j[21],h=j[22];let D=`cdUsageBanner ${h}`,M="danger"===h?"h_stop":"h_bell";return j[43]!==M?(p=(0,t.jsx)("span",{className:"cdUsageIcon","aria-hidden":"true",children:(0,t.jsx)(l.Glyph,{name:M,strokeWidth:1.8})}),j[43]=M,j[44]=p):p=j[44],j[45]!==m?(g=(0,t.jsx)("div",{className:"cdUsageTitle",children:m}),j[45]=m,j[46]=g):g=j[46],j[47]!==c?(f=c&&(0,t.jsx)("div",{className:"cdUsageMeta",children:c}),j[47]=c,j[48]=f):f=j[48],j[49]!==g||j[50]!==f?(x=(0,t.jsxs)("div",{className:"cdUsageBody",children:[g,f]}),j[49]=g,j[50]=f,j[51]=x):x=j[51],j[52]!==A||j[53]!==d||j[54]!==y.permissions||j[55]!==E||j[56]!==w||j[57]!==u||j[58]!==T||j[59]!==k?(b=(0,t.jsx)("div",{className:"cdUsageActions",children:A?(0,t.jsx)("button",{type:"button",className:"cdUsageBtn pri",onClick:d,children:k("usage.contactSales","Contact sales")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",className:"cdUsageBtn",onClick:w,children:k("usage.viewPlan","View plan")}),"exhausted"===T&&E&&y.permissions.change_plan&&(0,t.jsx)("button",{type:"button",className:"cdUsageBtn pri",onClick:()=>u("plans"),children:k("usage.subscribe","Subscribe")}),"exhausted"===T&&!E&&y.permissions.topup&&(0,t.jsx)("button",{type:"button",className:"cdUsageBtn pri",onClick:()=>u("billing"),children:k("usage.buyCredits","Buy credits")})]})}),j[52]=A,j[53]=d,j[54]=y.permissions,j[55]=E,j[56]=w,j[57]=u,j[58]=T,j[59]=k,j[60]=b):b=j[60],j[61]!==D||j[62]!==p||j[63]!==x||j[64]!==b?(v=(0,t.jsxs)("div",{className:D,role:"status","aria-live":"polite",children:[p,x,b]}),j[61]=D,j[62]=p,j[63]=x,j[64]=b,j[65]=v):v=j[65],v}],883639);let d=[{provider:"OPENAI",models:[{id:"gpt-6.1-sol",label:"GPT-6.1 Sol"},{id:"gpt-6-astra",label:"GPT-6 Astra"},{id:"gpt-6-sol",label:"GPT-6 Sol"},{id:"gpt-6-luna",label:"GPT-6 Luna"},{id:"gpt-5.6-sol",label:"GPT-5.6 Sol"},{id:"gpt-5.6-luna",label:"GPT-5.6 Luna"},{id:"gpt-5.6-terra",label:"GPT-5.6 Terra"},{id:"gpt-5.5",label:"GPT-5.5"},{id:"gpt-5.5-pro",label:"GPT-5.5 Pro"},{id:"gpt-5.4",label:"GPT-5.4"},{id:"gpt-5.4-pro",label:"GPT-5.4 Pro"},{id:"gpt-5.4-mini",label:"GPT-5.4 Mini"},{id:"gpt-5.4-nano",label:"GPT-5.4 Nano"},{id:"gpt-4o",label:"GPT-4o"},{id:"gpt-4o-mini",label:"GPT-4o Mini"}]},{provider:"ANTHROPIC",models:[{id:"claude-fable-5-1",label:"Claude Fable 5.1"},{id:"claude-fable-5",label:"Claude Fable 5"},{id:"claude-opus-5-5",label:"Claude Opus 5.5"},{id:"claude-opus-5",label:"Claude Opus 5"},{id:"claude-opus-4-8",label:"Claude Opus 4.8"},{id:"claude-opus-4-7",label:"Claude Opus 4.7"},{id:"claude-opus-4-6",label:"Claude Opus 4.6"},{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5"},{id:"claude-sonnet-5",label:"Claude Sonnet 5"},{id:"claude-sonnet-4-6",label:"Claude Sonnet 4.6"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5"}]}
22,{provider:"GOOGLE",models:[{id:"gemini-3.1-pro-preview",label:"Gemini 3.1 Pro"},{id:"gemini-3.8-flash",label:"Gemini 3.8 Flash"},{id:"gemini-3.7-flash",label:"Gemini 3.7 Flash"},{id:"gemini-3.6-flash",label:"Gemini 3.6 Flash"},{id:"gemini-3.5-flash",label:"Gemini 3.5 Flash"},{id:"gemini-3.5-flash-lite",label:"Gemini 3.5 Flash Lite"},{id:"gemini-3.1-flash-lite",label:"Gemini 3.1 Flash Lite"},{id:"gemini-2.5-pro",label:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",label:"Gemini 2.5 Flash"}]}],c={id:"",label:"Palette Smart"},u=[c,...d.flatMap(e=>e.models)],m={id:"",label:"PALETTE LLM"};e.s(["ALL_MODELS",0,u,"AUTO_MODEL",0,c,"MODEL_GROUPS",0,d,"PALETTE_MODEL",0,m,"autoModelFor",0,e=>e?m:c,"modelGroupsFor",0,e=>e?[]:d],854247);var h=e.i(271645);let p="palette_work_width_pct";function g(e){try{localStorage.setItem(p,String(e))}catch{}}e.s(["WorkPanelDivider",0,function({workspace:e}){let{t:a}=(0,s.useTranslation)("paletteOs"),[n,l]=(0,h.useState)(57.86),i=(0,h.useRef)(57.86),r=(0,h.useRef)(null),o=(0,h.useCallback)(t=>{let a=Math.min(65,Math.max(30,t));i.current=a,e.current?.style.setProperty("--work-width",`${a}%`),l(a)},[e]);(0,h.useEffect)(()=>{let t=57.86;try{let e=Number(localStorage.getItem(p));Number.isFinite(e)&&e>=30&&e<=65&&(t=e)}catch{}o(t);let a=e.current;return()=>{null!==r.current&&g(i.current),a?.classList.remove("work-resizing"),a?.style.removeProperty("--work-width")}},[o,e]);let d=()=>{null!==r.current&&(r.current=null,e.current?.classList.remove("work-resizing"),g(i.current))};return(0,t.jsx)("div",{className:"ssWorkDivider",role:"separator","aria-orientation":"vertical","aria-label":a("session.preview.resize","Resize work panel"),"aria-valuemin":30,"aria-valuemax":65,"aria-valuenow":Math.round(n),"aria-valuetext":a("session.preview.widthPercent",{defaultValue:"{{width}}% of workspace",width:Math.round(n)}),tabIndex:0,onPointerDown:t=>{0===t.button&&null===r.current&&(t.preventDefault(),t.currentTarget.dataset.pointer="",t.currentTarget.focus(),t.currentTarget.setPointerCapture(t.pointerId),r.current=t.pointerId,e.current?.classList.add("work-resizing"))},onPointerMove:t=>{if(r.current!==t.pointerId)return;let a=e.current?.getBoundingClientRect();a?.width&&o((a.right-t.clientX)/a.width*100)},onPointerUp:e=>{r.current===e.pointerId&&(d(),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},onPointerCancel:e=>{r.current===e.pointerId&&d()},onLostPointerCapture:e=>{r.current===e.pointerId&&d()},onDoubleClick:()=>{o(57.86),g(57.86)},onBlur:e=>{delete e.currentTarget.dataset.pointer},onKeyDown:e=>{delete e.currentTarget.dataset.pointer,["ArrowLeft","ArrowRight","Home","End"].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),o("Home"===e.key?30:"End"===e.key?65:i.current+("ArrowLeft"===e.key?2:-2)),g(i.current))}})}],783169);var f=e.i(964053),x=e.i(529682),b=e.i(30728),v=e.i(774498),j=e.i(794933);let y=["https://www.googleapis.com/auth/drive.readonly"];e.s(["PluginConnectionsDialog",0,function({returnFocus:e,onClose:a,onManage:n}){let{t:i}=(0,s.useTranslation)("paletteOs"),r=(0,x.useServiceConnections)(),o=(0,j.usePoConnect)(),d=(0,b.useIsOwnerOrAdmin)(),[c,u]=(0,h.useState)(null),[m,p]=(0,h.useState)(""),[g,w]=(0,h.useState)(!1),k=(0,h.useRef)(!1),N=(0,h.useRef)(null),[C,S]=(0,h.useState)(""),_=[...(r.error?[]:r.connections).map(e=>{let t=e.tools.filter(e=>e.name.startsWith("drive."));return{key:`service:${e.provider}`,name:"google"===e.provider?"Google Drive":e.display_name,icon:"google"===e.provider?"h_folder":"notion"===e.provider?"h_file":"h_plug",connected:"connected"===e.status&&("google"!==e.provider||t.length>0&&t.every(e=>e.scope_granted)),service:e}}),...(o.error?[]:o.connectors).map(e=>({key:`mcp:${e.slug}`,name:e.name,icon:e.slug.includes("figma")?"h_grid":"h_plug",connected:"active"===e.status,connector:e})),...(o.error?[]:o.presets).filter(e=>!o.connectors.some(t=>t.slug===e.slug)).map(e=>({key:`mcp:${e.slug}`,name:e.name,icon:e.slug.includes("figma")?"h_grid":"h_plug",connected:!1,preset:e}))],T=_.find(e=>e.key===c);(0,h.useEffect)(()=>{c&&N.current?.focus()},[c]);let E=r.loading||o.loading,A=!!(r.error||o.error),R=T?.service?.auth_type==="bot_token"||!!T?.preset,D=T?.service?T.service.available&&!T.connected&&["oauth2","bot_token"].includes(T.service.auth_type):!!(T?.preset&&d),M=()=>{k.current||a()},I=e=>e.connected?i("pluginDialog.connected"):e.service?.status==="expired"?i("pluginDialog.expired"):e.service?.status==="error"||e.connector?.status==="error"?i("pluginDialog.connectionError"):e.connector?.status==="disabled"?i("pluginDialog.disabled"):e.service?.available===!1?i("pluginDialog.unavailable"):i("pluginDialog.notConnected"),O=async()=>
22{if(T&&D&&!k.current&&(!R||m.trim())){k.current=!0,w(!0),S("");try{if(T.service?.auth_type==="oauth2"){let e=await (0,v.openConnectPopup)(T.service.provider,{redirectOnBlocked:!1,scopes:"google"===T.service.provider?y:void 0});if("connected"!==e)throw Error("Connection not completed");await r.refetch()}else if(T.service)await r.connectWithToken(T.service.provider,m.trim());else if(T.preset){let e=T.preset;await o.addConnector({slug:e.slug,name:e.name,server_url:e.server_url,transport:e.transport,auth_type:e.auth_type,header:e.header??void 0,token:m.trim()})}p("")}catch{S(i(T.service?.auth_type==="oauth2"?"pluginDialog.connectError":"pluginDialog.tokenError"))}finally{k.current=!1,w(!1)}}};return(0,t.jsx)(f.Dialog.Root,{open:!0,onOpenChange:e=>{e||M()},children:(0,t.jsx)(f.Dialog.Portal,{children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:{display:"contents"},children:[(0,t.jsx)(f.Dialog.Overlay,{className:"ssSearchBd"}),(0,t.jsxs)(f.Dialog.Content,{className:"ssSearchDlg ssDlg ssPluginDialog",onEscapeKeyDown:e=>{k.current&&e.preventDefault()},onPointerDownOutside:e=>{k.current&&e.preventDefault()},onCloseAutoFocus:t=>{t.preventDefault(),e?.isConnected&&e.focus()},children:[(0,t.jsxs)("div",{className:"ssSearchHead",children:[(0,t.jsx)(f.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{tabIndex:-1,ref:N,children:T?.name??i("pluginDialog.title")})}),(0,t.jsx)("button",{type:"button",className:"ssSearchClose",disabled:g,onClick:M,"aria-label":i("shell.close"),children:(0,t.jsx)(l.Glyph,{name:"h_close"})})]}),(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody",children:[(0,t.jsx)(f.Dialog.Description,{className:"ssDlgP",children:i(T?"pluginDialog.detailNote":"pluginDialog.description")}),A&&(0,t.jsxs)("div",{role:"alert",children:[(0,t.jsx)("p",{className:"ssDlgP",children:i("pluginDialog.loadError")}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:g,onClick:()=>void Promise.all([r.refetch(),o.refresh()]),children:i("pluginDialog.retry")})})]}),T?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("p",{className:"ssDlgNote",role:"status",children:[I(T),T.service?.account_label&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("br",{}),T.service.account_label]})]}),T.preset&&(0,t.jsx)("p",{className:"ssDlgP",children:T.preset.auth_hint}),T.preset&&!d&&(0,t.jsx)("p",{className:"ssDlgP",children:i("pluginDialog.adminRequired")}),R&&D&&(0,t.jsxs)("label",{className:"ssPluginToken",children:[i("pluginDialog.token"),(0,t.jsx)("input",{type:"password",autoComplete:"new-password",value:m,disabled:g,onChange:e=>p(e.target.value)})]}),C&&(0,t.jsx)("p",{role:"alert",className:"ssPluginError",children:C}),(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:g,onClick:()=>{k.current||(u(null),p(""),S(""),requestAnimationFrame(()=>[...document.querySelectorAll("[data-connection-key]")].find(e=>e.dataset.connectionKey===c)?.focus()))},children:i("pluginDialog.back")}),D?(0,t.jsx)("button",{type:"button",className:"cfBtn cfPrimary",disabled:g||R&&!m.trim(),onClick:()=>void O(),children:i(g?"pluginDialog.connecting":"pluginDialog.connect")}):(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:g,onClick:()=>{M(),n()},children:i("pluginDialog.manage")})]})]}):(0,t.jsxs)(t.Fragment,{children:[E&&(0,t.jsx)("p",{role:"status",className:"ssDlgP",children:i("pluginDialog.loading")}),_.map(e=>(0,t.jsxs)("button",{type:"button","data-connection-key":e.key,className:"ssPluginRow",onClick:()=>u(e.key),children:[(0,t.jsx)(l.Glyph,{name:e.icon}),(0,t.jsxs)("span",{children:[e.name,(0,t.jsx)("small",{children:I(e)})]}),(0,t.jsx)(l.Glyph,{name:"h_chevronRight"})]},e.key)),!E&&!A&&!_.length&&(0,t.jsx)("p",{className:"ssDlgP",children:i("pluginDialog.empty")}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>{M(),n()},children:i("pluginDialog.manage")})})]})]})]})]})})})}],572204);var w=e.i(371662);e.s(["SideChatDialog",0,function({threadId:e,blocked:a,onClose:n,onBranch:i}){let{t:r}=(0,s.useTranslation)("paletteOs"),{duplicateConversation:o,loadMessages:d}=(0,w.useGeneralChat)(),[c,u]=(0,h.useState)(""),[m,p]=(0,h.useState)(!1),[g,x]=(0,h.useState)(""),b=(0,h.useRef)(!1),v=(0,h.useRef)(null),j=(0,h.useRef)(!1),y=(0,h.useRef)("u">typeof document&&document.activeElement instanceof HTMLElement?document.activeElement:null),k=async()=>{let t=c.trim();if(t&&!a&&!b.current){b.current=!0,p(!0),x("");try{let a=v.current??await o(e);v.current=a;let s=await d(a);if("loaded"!==s)throw"missing"===s&&(v.current=null),Error("Could not load copied conversation");j.current=!0,i(a,t),n()}catch{x(r("sideChat.failed","Could not open the branch. Your message is kept here; try again."))}finally{b.current=!1,p(!1)}}};return(0,t.jsx)(f.Dialog.Root,{open:!0,onOpenChange:e=>{e||b.current||n()},children:(0,t.jsx)(f.Dialog.Portal,{children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:{display:"contents"},children:[(0,t.jsx)(f.Dialog.Overlay,{className:"ssSearchBd"}),(0,t.jsxs)(f.Dialog.Content,{className:"ssSearchDlg ssDlg",onEscapeKeyDown:e=>{b.current&&e.preventDefault()},onPointerDownOutside:e=>{b.current&&e.preventDefault()},onCloseAutoFocus:e=>{e.preventDefault(),!j.current&&y.current?.isConnected&&y.current.focus()},children:[(0,t.jsxs)("div",{className:"ssSearchHead",children:[(0,t.jsx)(f.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:r("sideChat.title","Side chat")})}),(0,t.jsx)(f.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose",disabled:m,"aria-label":r("shell.close","Close"),children:(0,t.jsx)(l.Glyph,{name:"h_close"})})})]}),(0,t.jsxs)("form",{className:"ssSearchBody ssDlgBody ssSideChatForm",onSubmit:e=>{e.preventDefault(),k()},children:[(0,t.jsx)(f.Dialog.Description,{asChild:!0,children:(0,t.jsx)("p",{className:"ssDlgP",children:r("sideChat.de
22scription","Copy this conversationâs context and continue in a new branch. The original conversation stays unchanged.")})}),(0,t.jsx)("textarea",{autoFocus:!0,rows:4,value:c,disabled:m,onChange:e=>u(e.target.value),"aria-label":r("sideChat.prompt","Message for the new branch"),placeholder:r("sideChat.placeholder","Ask what you would like to explore further in this conversation")}),a&&(0,t.jsx)("p",{className:"ssDlgP small",role:"status",children:r("sideChat.wait","Wait for the current response to finish before sending.")}),g&&(0,t.jsx)("p",{className:"ssProjectError",role:"alert",children:g}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"submit",className:"cfBtn cfPrimary",disabled:a||m||!c.trim(),"aria-busy":m,children:m?r("sideChat.preparing","Preparing branchâ¦"):r("sideChat.send","Send to new branch")})})]})]})]})})})}],889741);var k=e.i(778085),N=e.i(670378);function C(e,a,s,n){let i=function(e){try{let t=new URL(e);return["https:","http:"].includes(t.protocol)?t.href:void 0}catch{return}}(a),r=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(l.Glyph,{name:s}),(0,t.jsxs)("span",{children:[e,i&&(0,t.jsx)("small",{children:new URL(i).hostname})]}),i&&(0,t.jsx)(l.Glyph,{name:"h_external"})]});return i?(0,t.jsx)("a",{className:"ssResponseSource",href:i,target:"_blank",rel:"noopener noreferrer",children:r},n):(0,t.jsx)("div",{className:"ssResponseSource",children:r},n)}function S(e){return"artifact"===e.kind?[e.title]:"file"===e.kind?[e.filename]:[]}function _(e){return[e.file_url,e]}function T(e){return"sources"===e.kind?e.items:[]}e.s(["MessageDialog",0,function(e){let n,i,r,o,d,c,u,m,h,p,g,x,b,v,j,y,w,E,A,R,D=(0,a.c)(83),{message:M,request:I,mode:O,returnFocus:P,onClose:L,onDownload:F}=e,{t:$}=(0,s.useTranslation)("paletteOs"),{copied:B,copy:H}=(0,k.useCopyToClipboard)();D[0]!==M.role||D[1]!==O||D[2]!==$?(n="sources"===O?$("messageDialog.sources","View sources"):"user"===M.role?$("messageDialog.share","Share message"):$("messageDialog.shareResponse","Share response"),D[0]=M.role,D[1]=O,D[2]=$,D[3]=n):n=D[3];let z=n;if(D[4]!==B||D[5]!==H||D[6]!==M.actions||D[7]!==M.content||D[8]!==M.role||D[9]!==O||D[10]!==L||D[11]!==F||D[12]!==I?.attachments||D[13]!==P||D[14]!==$||D[15]!==z){let e,a,s,n,y,w,k,E=(M.actions??[]).flatMap(T),A=[...new Map((I?.attachments??[]).map(_)).values()];if(D[30]!==M.actions||D[31]!==M.content||D[32]!==M.role||D[33]!==$){let t=(M.actions??[]).flatMap(S);D[36]!==M.content||D[37]!==M.role?(e="user"===M.role?M.content:(0,N.stripPanelBlocks)(M.content),D[36]=M.content,D[37]=M.role,D[38]=e):e=D[38],a=t.length?` 23 24${$("messageDialog.outputNote",{defaultValue:"Outputs: {{names}}. Original files are not included.",names:[...new Set(t)].join(", ")})}`:"",D[30]=M.actions,D[31]=M.content,D[32]=M.role,D[33]=$,D[34]=e,D[35]=a}else e=D[34],a=D[35];let R=e+a;o=f.Dialog.Root,c=!0,D[39]!==L?(u=e=>{e||L()},D[39]=L,D[40]=u):u=D[40],r=f.Dialog.Portal,v="palette-os",D[41]===Symbol.for("react.memo_cache_sentinel")?(j={display:"contents"},d=(0,t.jsx)(f.Dialog.Overlay,{className:"ssSearchBd"}),D[41]=d,D[42]=j):(d=D[41],j=D[42]),i=f.Dialog.Content,g="ssSearchDlg ssDlg",D[43]!==P?(x=e=>{e.preventDefault(),P?.isConnected&&P.focus()},D[43]=P,D[44]=x):x=D[44],D[45]!==z?(s=(0,t.jsx)(f.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:z})}),D[45]=z,D[46]=s):s=D[46],D[47]!==$?(n=$("shell.close","Close"),D[47]=$,D[48]=n):n=D[48],D[49]===Symbol.for("react.memo_cache_sentinel")?(y=(0,t.jsx)(l.Glyph,{name:"h_close"}),D[49]=y):y=D[49],D[50]!==n?(w=(0,t.jsx)(f.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":n,children:y})}),D[50]=n,D[51]=w):w=D[51],D[52]!==s||D[53]!==w?(b=(0,t.jsxs)("div",{className:"ssSearchHead",children:[s,w]}),D[52]=s,D[53]=w,D[54]=b):b=D[54],m="ssSearchBody ssDlgBody ssResponseDialog",D[55]!==O||D[56]!==$?(k="sources"===O?$("messageDialog.sourceNote","Only sources recorded for this response and attachments from its request are shown."):$("messageDialog.shareNote","Only this message is included. Earlier and later messages are not shared."),D[55]=O,D[56]=$,D[57]=k):k=D[57],D[58]!==k?(h=(0,t.jsx)(f.Dialog.Description,{asChild:!0,children:(0,t.jsx)("p",{className:"ssResponseNote",children:k})}),D[58]=k,D[59]=h):h=D[59],p="sources"===O?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("h3",{children:$("messageDialog.recordedSources","Sources recorded for this response")}),E.length?E.map((e,t)=>C(e.title||e.url,e.url,"h_responseBook",`${t}`)):(0,t.jsx)("p",{className:"ssResponseEmpty",children:$("messageDialog.noSources","N
24o sources were recorded for this response.")}),!!A.length&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("h3",{children:$("messageDialog.attachments","Attachments from this request")}),(0,t.jsx)("p",{className:"ssResponseNote",children:$("messageDialog.attachmentNote","These files were attached to the request. This does not mean the response cited them.")}),A.map(e=>C(e.filename,e.file_url,"h_file",e.file_url))]})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"ssResponseSharePreview",children:R}),(0,t.jsx)("p",{className:"ssResponseNote",children:$("messageDialog.exportNote","Copy the text or save it as Markdown. Download original outputs separately from the work panel.")}),(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsxs)("button",{type:"button",className:"cfBtn",onClick:()=>F(R),children:[(0,t.jsx)(l.Glyph,{name:"h_download"}),$("messageDialog.save","Save Markdown")]}),(0,t.jsxs)("button",{type:"button",className:"cfBtn cfPrimary","aria-live":"polite",onClick:()=>void H(R),children:[(0,t.jsx)(l.Glyph,{name:"h_responseCopy"}),B?$("messageDialog.copied","Copied"):$("messageDialog.copy","Copy content")]})]})]}),D[4]=B,D[5]=H,D[6]=M.actions,D[7]=M.content,D[8]=M.role,D[9]=O,D[10]=L,D[11]=F,D[12]=I?.attachments,D[13]=P,D[14]=$,D[15]=z,D[16]=i,D[17]=r,D[18]=o,D[19]=d,D[20]=c,D[21]=u,D[22]=m,D[23]=h,D[24]=p,D[25]=g,D[26]=x,D[27]=b,D[28]=v,D[29]=j}else i=D[16],r=D[17],o=D[18],d=D[19],c=D[20],u=D[21],m=D[22],h=D[23],p=D[24],g=D[25],x=D[26],b=D[27],v=D[28],j=D[29];return D[60]!==m||D[61]!==h||D[62]!==p?(y=(0,t.jsxs)("div",{className:m,children:[h,p]}),D[60]=m,D[61]=h,D[62]=p,D[63]=y):y=D[63],D[64]!==i||D[65]!==y||D[66]!==g||D[67]!==x||D[68]!==b?(w=(0,t.jsxs)(i,{className:g,onCloseAutoFocus:x,children:[b,y]}),D[64]=i,D[65]=y,D[66]=g,D[67]=x,D[68]=b,D[69]=w):w=D[69],D[70]!==d||D[71]!==w||D[72]!==v||D[73]!==j?(E=(0,t.jsxs)("div",{"data-theme":v,style:j,children:[d,w]}),D[70]=d,D[71]=w,D[72]=v,D[73]=j,D[74]=E):E=D[74],D[75]!==r||D[76]!==E?(A=(0,t.jsx)(r,{children:E}),D[75]=r,D[76]=E,D[77]=A):A=D[77],D[78]!==o||D[79]!==c||D[80]!==u||D[81]!==A?(R=(0,t.jsx)(o,{open:c,onOpenChange:u,children:A}),D[78]=o,D[79]=c,D[80]=u,D[81]=A,D[82]=R):R=D[82],R}],611695);var E=e.i(209165),A=e.i(416317);function R(e){return e+1}function D(e){return e.json()}e.s(["ResponseHistoryDialog",0,function(e){let n,i,r,o,d,c,u,m,p,g,x,b,v,j,y,w,k,C,S,_,T,M,I,O=(0,a.c)(67),{threadId:P,returnFocus:L,onClose:F}=e,{t:$}=(0,s.useTranslation)("paletteOs");O[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],O[0]=n):n=O[0];let[B,H]=(0,h.useState)(n),[z,U]=(0,h.useState)(0),[G,W]=(0,h.useState)(0),[K,V]=(0,h.useState)(!0),[Y,q]=(0,h.useState)(!1),[J,X]=(0,h.useState)(!1);if(O[1]!==z||O[2]!==P?(i=()=>{let e=new AbortController;return V(!0),q(!1),(0,E.apiFetch)(`/api/v1/general-chat/threads/${P}/response-history?offset=${z}&limit=50`,{signal:e.signal}).then(D).then(t=>{if(!e.signal.aborted){if(!Array.isArray(t.items))throw Error("Invalid response history");H(e=>0===z?t.items:[...e,...t.items]),X(t.has_more)}}).catch(()=>{e.signal.aborted||q(!0)}).finally(()=>{e.signal.aborted||V(!1)}),()=>e.abort()},O[1]=z,O[2]=P,O[3]=i):i=O[3],O[4]!==z||O[5]!==G||O[6]!==P?(r=[P,z,G],O[4]=z,O[5]=G,O[6]=P,O[7]=r):r=O[7],(0,h.useEffect)(i,r),O[8]!==F?(o=e=>{e||F()},O[8]=F,O[9]=o):o=O[9],O[10]===Symbol.for("react.memo_cache_sentinel")?(d={display:"contents"},c=(0,t.jsx)(f.Dialog.Overlay,{className:"ssSearchBd"}),O[10]=d,O[11]=c):(d=O[10],c=O[11]),O[12]!==L?(u=e=>{e.preventDefault(),L?.isConnected&&L.focus()},O[12]=L,O[13]=u):u=O[13],O[14]!==$?(m=$("responseHistory.title","Previous generated answers"),O[14]=$,O[15]=m):m=O[15],O[16]!==m?(p=(0,t.jsx)(f.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:m})}),O[16]=m,O[17]=p):p=O[17],O[18]!==$?(g=$("shell.close","Close"),O[18]=$,O[19]=g):g=O[19],O[20]===Symbol.for("react.memo_cache_sentinel")?(x=(0,t.jsx)(l.Glyph,{name:"h_close"}),O[20]=x):x=O[20],O[21]!==g?(b=(0,t.jsx)(f.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":g,children:x})}),O[21]=g,O[22]=b):b=O[22],O[23]!==b||O[24]!==p?(v=(0,t.jsxs)("div",{className:"ssSearchHead",children:[p,b]}),O[23]=b,O[24]=p,O[25]=v):v=O[25],O[26]!==$?(j=$("responseHistory.description","Earlier answers saved when you regenerate a response in this conversation."),O[26]=$,O[27]=j):j=O[27],O[28]!==j?(y=(0,t.jsx)(f.Dialog.Description,{className:"sr-only",children:j}),O[28]=j,O[29]=y):y=O[29],O[30]!==B||O[31]!==$){let e;O[33]!==$?(e=(e,a)=>(0,t.jsxs)("details",{className:"ssResponseHistoryEntry",children:[(0,t.jsx)("summary",{children:$("responseHistory.entry",{defaultValue:"Previous answer {{number}}",number:a+1})}),(0,t.jsx)(A.ChatMarkdown,{compact:!0,citations:e.sources,children:(0,N.stripPanelBlocks)(e.content)})]},e.id),O[33]=$,O[34]=e):e=O[34],w=B.map(e),O[30]=B,O[31]=$,O[32]=w}else w=O[32];return O[35]!==K||O[36]!==$?(k=K&&(0,t.jsx)("p",{className:"ssResponseEmpty",role:"status",children:$("responseHistory.loading","Loading previous answersâ¦")}),O[35]=K,O[36]=$,O[37]=k):k=O[37],O[38]!==Y||O[39]!==$?(C=Y&&(0,t.jsxs)("div",{role:"alert",children:[(0,t.jsx)("p",{className:"ssProjectError",children:$("responseHistory.failed","Could not load previous answers.")}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>W(R),children:$("responseHistory.retry","Try again")})})]}),O[38]=Y,O[39]=$,O[40]=C):C=O[40],O[41]!==B.length||O[42]!==Y||O[43]!==K||O[44]!==$?(S=!K&&!Y&&0===B.length&&(0,t.jsx)("p",{className:"ssResponseEmpty",children:$("responseHistory.empty","There are no saved previous answers.")}),O[41]=B.length,O[42]=Y,O[43]=K,O[44]=$,O[45]=S):S=O[45],O[46]!==B.length||O[47]!==Y||O[48]!==J||O[49]!==K||O[50]!==$?(_=!K&&!Y&&J&&(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>U(B.length),children:$("responseHistory.more","Load more")})}),O[46]=B.length,O[47]=Y,O[48]=J,O[49]=K,O[50]=$,O[51]=_):_=O[51],O[52]!==K||O[53]!==y||O[54]!==w||O[55]!==k||O[56]!==C||O[57]!==S||O[58]!==_?(T=(0,t.jsxs)("div",{className:"ssSearchBody ssDlgBody","aria-busy":K,children:[y,w,k,C,S,_]}),O[52]=K,O[53]=y,O[54]=w,O[55]=k,O[56]=C,O[57]=S,O[58]=_,O[59]=T):T=O[59],O[60]!==v||O[61]!==T||O[62]!==u?(M=(0,t.jsx)(f.Dialog.Portal,{children:(0,t.jsxs)("div",{"data-theme":"palette-os",style:d,children:[c,(0,t.jsxs)(f.Dialog.Content,{className:"ssSearchDlg ssDlg",onCloseAutoFocus:u,children:[v,T]})]})}),O[60]=v,O[61]=T,O[62]=u,O[63]=M):M=O[63],O[64]!==M||O[65]!==o?(I=(0,t.jsx)(f.Dialog.Root,{open:!0,onOpenChange:o,children:M}),O[64]=M,O[65]=o,O[66]=I):I=O[66],I}],98443),e.s(["InlineMessageEditor",0,function({threadId:e,messageId:a,initialText:n,blocked:l,onCancel:i,onBranch:r}){let{t:o}=(0,s.useTranslation)("paletteOs"),{duplicateConversation:d,loadMessages:c}=(0,w.useGeneralChat)(),[u,m]=(0,h.useState)(n),[p,g]=(0,h.useState)(!1),[f,x]=(0,h.useState)(!1),b=(0,h.useRef)(!1),v=(0,h.useRef)(null),j=(0,h.useRef)(!0),y=(0,h.useId)();(0,h.useEffect)(()=>(j.current=!0,()=>{j.current=!1}),[]);let k=async()=>{let t=u.trim();if(t&&!l&&!b.current){b.current=!0,g(!0),x(!1);try{let s=v.current??await d(e,a,"before");if(v.current=s,!j.current)return;let n=await c(s);if(!j.current)return;if("loaded"!==n)throw"missing"===n&&(v.current=null),Error("Could not load edit branch");r(s,t)}catch{j.current&&x(!0)}finally{b.current=!1,j.current&&g(!1)}}};return(0,t.jsxs)("form",{className:"ssInlineEdit",onSubmit:e=>{e.preventDefault(),k()},onKeyDown:e=>{"Escape"===e.key&&!e.nativeEvent.isComposing&&(e.stopPropagation(),b.current||i())},children:[(0,t.jsx)("textarea",{autoFocus:!0,value:u,onChange:e=>m(e.target.value),disabled:p,"aria-label":o("inlineEdit.label","Edit request"),"aria-describedby":y}),(0,t.jsx)("small",{id:y,children:o("inlineEdit.note","The original conversation stays unchanged. Your edited request continues in a new branch.")}),f&&(0,t.jsx)("p",{className:"ssProjectError",role:"alert",children:o("inlineEdit.failed","Could not prepare the branch. Your edit is kept here; try again.")}),(0,t.jsxs)("div",{className:"ssInlineEditActions",children:[(0,t.jsx)("button",{type:"button",disabled:p,onClick:i,children:o("inlineEdit.cancel","Cancel")}),(0,t.jsx)("button",{type:"submit",className:"primary",disabled:l||p||!u.trim(),"aria-busy":p,children:p?o("inlineEdit.preparing","Preparing branchâ¦"):o("inlineEdit.send","Send edited request")})]})]})}],11029);var M=e.i(295692),I=e.i(602725);e.s(["ComposerDock",0,function({onDeviceFiles:e,onDataRoom:a,onVoiceNote:n,menu:i,onAddLink:r,onConnectPlugins:o,voiceInput:d}){let{t:c}=(0,s.useTranslation)("paletteOs"),[u,m]=(0,h.useState)(!1),p=(0,h.useRef)(null),g=c("session.composer.addContent","Add files and tools"),f=c("session.composer.dataRoom","Palette Drive"),x=c("session.composer.deviceFiles","My de
24sktop");if(i){let s=[{k:"device",glyph:"h_desktop",title:x,desc:c("session.composer.deviceFilesDesc","Load files from this computer"),run:e},{k:"drive",glyph:"h_cloudCheck",title:f,desc:c("session.composer.dataRoomDesc","Load material saved in Palette"),run:a},{k:"web",glyph:"h_globe",title:c("session.composer.webLink","Web"),desc:c("session.composer.webLinkDesc","Add a web link or page"),run:r},{k:"plugins",glyph:"h_plug",title:c("session.composer.plugins","Connect plugins"),desc:c("session.composer.pluginsDesc","Connect external apps and services"),run:o?()=>o(p.current):void 0}];return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"cdAttachWrap",children:(0,t.jsxs)(M.DropdownMenu.Root,{open:u,onOpenChange:m,modal:!1,children:[(0,t.jsx)(M.DropdownMenu.Trigger,{asChild:!0,children:(0,t.jsx)("button",{ref:p,type:"button",className:"cdIcon cdAttach","aria-label":g,title:g,children:(0,t.jsx)(l.Glyph,{name:"h_plus"})})}),(0,t.jsx)(M.DropdownMenu.Portal,{container:p.current?.closest(".po-root")??void 0,children:(0,t.jsx)(M.DropdownMenu.Content,{className:"cdAttachMenu",side:"top",align:"start",sideOffset:6,collisionPadding:12,loop:!0,"aria-labelledby":void 0,"aria-label":g,onCloseAutoFocus:e=>{document.activeElement?.closest('[role="dialog"]')&&e.preventDefault()},children:s.filter(e=>e.run).map(e=>(0,t.jsx)(M.DropdownMenu.Item,{asChild:!0,onSelect:()=>e.run?.(),children:(0,t.jsxs)("button",{type:"button",className:"cdAttachItem",children:[(0,t.jsx)(l.Glyph,{name:e.glyph,strokeWidth:1.6}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e.title}),(0,t.jsx)("small",{children:e.desc})]})]})},e.k))})})]})}),d??(n&&(0,t.jsx)(I.MicButton,{onNote:n,icon:(0,t.jsx)(l.Glyph,{name:"h_mic"})}))]})}return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",className:"cdIcon cdAttach","aria-label":g,title:g,onClick:e,children:(0,t.jsx)(l.Glyph,{name:"h_plus"})}),(0,t.jsx)("button",{type:"button",className:"cdIcon cdDrive","aria-label":f,title:f,onClick:a,children:(0,t.jsx)(l.Glyph,{name:"h_folder"})}),d??(n&&(0,t.jsx)(I.MicButton,{onNote:n,icon:(0,t.jsx)(l.Glyph,{name:"h_mic"})}))]})}],783786),e.s(["useConversationTitleOverflow",0,function(e){let t,s,n=(0,a.c)(3);n[0]!==e?(t=()=>{let t=e.current;if(!t)return;let a=0,s=!1,n=new Set,l=()=>{s||a||(a=requestAnimationFrame(r))},i="u"<typeof ResizeObserver?null:new ResizeObserver(l);function r(){a=0;let e=[...t.querySelectorAll(".clTitleViewport")],s=new Set,l=e.flatMap(e=>{let t=e.firstElementChild;return t?(s.add(e),s.add(t),[{viewport:e,distance:Math.max(0,Math.ceil(t.getBoundingClientRect().width-e.clientWidth))}]):[]});for(let e of n)s.has(e)||(i?.unobserve(e),n.delete(e));for(let{viewport:e,distance:t}of l)e.classList.toggle("is-overflowing",t>1),e.style.setProperty("--thread-pan-offset",`calc(-${t}px - var(--thread-fade-width,18px))`),e.style.setProperty("--thread-pan-duration",`${Math.max(6,2+t/22*2)}s`);for(let e of s)n.has(e)||(i?.observe(e),n.add(e))}let o=new MutationObserver(l);for(let e of(o.observe(t,{childList:!0,characterData:!0,subtree:!0}),["pointerover","pointerout","focusin","focusout"]))t.addEventListener(e,l);return window.addEventListener("resize",l),document.fonts?.ready.then(l),l(),()=>{for(let e of(s=!0,cancelAnimationFrame(a),o.disconnect(),i?.disconnect(),["pointerover","pointerout","focusin","focusout"]))t.removeEventListener(e,l);window.removeEventListener("resize",l)}},s=[e],n[0]=e,n[1]=t,n[2]=s):(t=n[1],s=n[2]),(0,h.useEffect)(t,s)}],860189);let O="palette_session_pinned_v1";function P(e,t,a,s){if(t===a||!e.includes(t)||!e.includes(a))return e;let n=e.filter(e=>e!==t);return n.splice(n.indexOf(a)+Number(s),0,t),n.every((t,a)=>t===e[a])?e:n}e.s(["usePinnedConversations",0,function(e,t){let{t:a}=(0,s.useTranslation)("paletteOs"),[n,l]=(0,h.useState)([]),i=(0,h.useRef)(null),r=(0,h.useRef)(null),o=(0,h.useRef)(!1),d=(0,h.useRef)(null),c=(0,h.useRef)(void 0);(0,h.useEffect)(()=>{try{let e=JSON.parse(localStorage.getItem(O)??"[]");Array.isArray(e)&&l([...new Set(e.filter(e=>"string"==typeof e&&!!e))])}catch{}return()=>clearTimeout(c.current)},[]);let u=(0,h.useCallback)(e=>l(t=>{let a=e(t);if(a!==t)try{localStorage.setItem(O,JSON.stringify(a))}catch{}return a}),[]),m=(0,h.useCallback)(e=>u(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),[u]),p=n.filter(t=>e.includes(t)).join("\0");return(0,h.useEffect)(()=>{let e=i.current,s=r.current;if(!e||!s||!t)return;let n=new Set(p.split("\0")),l=e.closest(".po-root"),m=()=>[...e.querySelectorAll("[data-reorder-pinned]")].filter(e=>n.has(e.dataset.threadId));d.current&&(m().find(e=>e.dataset.threadId===d.current)?.querySelector(".clT")?.focus({preventScroll:!0}),d.current=null);let h=(e,t,n)=>{s.textContent=a("pinnedOrder.position",{defaultValue:"{{title}}, pinned {{position}} of {{count}}
24",title:e.querySelector(".clTx")?.textContent??"",position:t+1,count:n})},g=null,f=0,x=t=>{let n=g;if(!n||(g=null,cancelAnimationFrame(f),f=0,!n.active))return;for(let e of(n.portal?.remove(),n.row.classList.remove("poPinnedSource"),n.rows))e.style.removeProperty("transform");l?.classList.remove("poPinnedDragging"),n.row.querySelector(".clT")?.focus({preventScroll:!0}),e.hasPointerCapture(n.pointerId)&&e.releasePointerCapture(n.pointerId),o.current=!0,clearTimeout(c.current),c.current=setTimeout(()=>{o.current=!1},0);let i=n.order.indexOf(n.row),r=n.rows.indexOf(n.row);if(t&&n.inside&&n.row.isConnected&&i!==r){let e=n.order[i-1],t=n.order[i+1],a=e??t;d.current=n.row.dataset.threadId,u(t=>P(t,n.row.dataset.threadId,a.dataset.threadId,!!e)),h(n.row,i,n.order.length)}else s.textContent=a(t&&n.inside?"pinnedOrder.unchanged":"pinnedOrder.cancelled",t&&n.inside?"Order unchanged.":"Move cancelled.")},b=()=>{let t=g;if(!t?.active)return;if(!t.row.isConnected)return void x(!1);let a=e.getBoundingClientRect(),s=t.scroll-e.scrollTop,n=t.rects[0],l=t.rects.at(-1);if(t.inside=t.x>=a.left-6&&t.x<=a.right+6&&t.y>=Math.max(a.top,n.top+s)-6&&t.y<=Math.min(a.bottom,l.bottom+s)+6,t.ghost.style.transform=`translate(${Math.max(-12,Math.min(12,t.x-t.startX))}px, ${t.y-t.startY}px)`,t.ghost.classList.toggle("is-outside",!t.inside),!t.inside)return;let i=t.rows.filter(e=>e!==t.row),r=i.findIndex(e=>{let a=t.rects[t.rows.indexOf(e)];return t.y<a.top+s+a.height/2});for(let[e,a]of(t.order=[...i],t.order.splice(r<0?i.length:r,0,t.row),t.rows.entries()))a.style.transform=`translateY(${t.rects[t.order.indexOf(a)].top-t.rects[e].top}px)`},v=()=>{f=0;let t=g;if(!t?.active)return;let a=e.getBoundingClientRect();if(t.inside&&t.y>=a.top&&t.y<=a.bottom){let s=t.y<a.top+24?-5:5*(t.y>a.bottom-24);s&&(e.scrollTop+=s,b())}f=requestAnimationFrame(v)},j=t=>{if(g||0!==t.button||!1===t.isPrimary||"touch"===t.pointerType||t.ctrlKey||t.metaKey||t.altKey)return;let a=t.target.closest(".clT")?.closest("[data-reorder-pinned]");a&&e.contains(a)&&n.has(a.dataset.threadId)&&!(m().length<2)&&(g={row:a,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,x:t.clientX,y:t.clientY,active:!1,inside:!1,scroll:0,rows:[],rects:[],order:[]})},y=t=>{let n=g;n&&n.pointerId===t.pointerId&&(n.x=t.clientX,n.y=t.clientY,!n.active&&Math.hypot(n.x-n.startX,n.y-n.startY)>=6&&(()=>{let t=g;if(!t||t.active||!t.row.isConnected)return;t.active=!0,t.rows=m(),t.rects=t.rows.map(e=>e.getBoundingClientRect()),t.order=[...t.rows],t.scroll=e.scrollTop;let n=t.row.getBoundingClientRect(),i=t.row.querySelector(".clT");t.portal=document.createElement("div"),t.portal.dataset.theme="palette-os",t.portal.style.display="contents",t.ghost=document.createElement("div"),t.ghost.className="poPinnedGhost",t.ghost.setAttribute("aria-hidden","true");let r=document.createElement("span");r.textContent=i.textContent,t.ghost.append(r),Object.assign(t.ghost.style,{left:`${n.left}px`,top:`${n.top}px`,width:`${n.width}px`,height:`${n.height}px`,font:getComputedStyle(i).font,letterSpacing:getComputedStyle(i).letterSpacing}),t.portal.append(t.ghost),document.body.append(t.portal),t.row.classList.add("poPinnedSource"),l?.classList.add("poPinnedDragging"),e.setPointerCapture(t.pointerId),s.textContent=a("pinnedOrder.moving","Move within the pinned list. Press Escape to cancel."),f=requestAnimationFrame(v)})(),n.active&&(t.preventDefault(),b()))},w=e=>{g?.pointerId===e.pointerId&&(g.active&&(g.x=e.clientX,g.y=e.clientY,b(),e.preventDefault()),x(!0))},k=e=>{g?.pointerId===e.pointerId&&x(!1)},N=()=>x(!1),C=()=>{document.hidden&&x(!1)},S=e=>{if("Escape"===e.key&&g){e.preventDefault(),e.stopImmediatePropagation(),x(!1);return}if(g||e.isComposing||!e.altKey||e.ctrlKey||e.metaKey||!["ArrowUp","ArrowDown"].includes(e.key))return;let t=e.target.closest(".clT")?.closest("[data-reorder-pinned]"),a=m(),s=t?a.indexOf(t):-1;if(s<0)return;e.preventDefault(),e.stopImmediatePropagation();let n=s+("ArrowUp"===e.key?-1:1),l=a[n];l&&(d.current=t.dataset.threadId,u(e=>P(e,t.dataset.threadId,l.dataset.threadId,n>s)),h(t,n,a.length))},_=e=>{e.target.closest("[data-reorder-pinned]")&&e.preventDefault()};return e.addEventListener("pointerdown",j),e.addEventListener("lostpointercapture",N),e.addEventListener("dragstart",_),window.addEventListener("pointermove",y,{passive:!1}),window.addEventListener("pointerup",w),window.addEventListener("pointercancel",k),window.addEventListener("blur",N),window.addEventListener("resize",N),document.addEventListener("visibilitychange",C),document.addEventListener("keydown",S,!0),()=>{x(!1),e.isConnected||clearTimeout(c.current),e.removeEventListener("pointerdown",j),e.removeEventListener("lostpointercapture",N),e.removeEventListener("dragstart",_),window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",w),window.removeEventListener("pointercancel",k),window.removeEventListener("blur",N),window.removeEventListener("resize",N),document.removeEventListener("visibilitychange",C),document.removeEventListener("keydown",S,!0)}},[p,t,a,u]),{pinned:n,togglePin:m,listRef:i,statusRef:r,onClickCapture:e=>{o.current&&0!==e.detail&&(e.preventDefault(),e.stopPropagation())}}}],186804);let L=[50,75,84,100,125,150,200];function F(e){let t={};try{let a=e?JSON.parse(localStorage.getItem(e)??"null"):null;a&&"object"==typeof a&&(t=a)}catch{}let a=Array.isArray(t.hist?.ids)?t.hist.ids.filter(e=>"string"==typeof e).slice(-50):[],s=t.hist?.cur;return{open:!0===t.open,activeId:"string"==typeof t.activeId?t.activeId:null,closedTabs:Array.isArray(t.closedTabs)?[...new Set(t.closedTabs.filter(e=>"string"==typeof e))]:[],hist:{ids:a,cur:"number"==typeof s&&Number.isInteger(s)?Math.max(-1,Math.min(a.length-1,s)):a.length-1},page:"number"==typeof t.page&&Number.isSafeInteger(t.page)&&t.page>=0?t.page:0,zoom:"number"==typeof t.zoom&&L.includes(t.zoom)?t.zoom:"fit",notesOpen:!0===t.notesOpen}}e.s(["WORK_ZOOMS",0,L,"useWorkPanelState",0,function(e){let t,s,n,l,i,r,o=(0,a.c)(22),d=e?`po-work-panel:${e}`:null;o[0]!==d?(t=()=>({key:d,state:F(d)}),o[0]=d,o[1]=t):t=o[1];let[c,u]=(0,h.useState)(t),m=c;if(c.key!==d){let e,t;o[2]!==d?(e=F(d),o[2]=d,o[3]=e):e=o[3],o[4]!==d||o[5]!==e?(t={key:d,state:e},o[4]=d,o[5]=e,o[6]=t):t=o[6],u(m=t)}o[7]!==d||o[8]!==c.key||o[9]!==c.state?(s=()=>
24{if(d&&c.key===d)try{localStorage.setItem(d,JSON.stringify(c.state))}catch{}},o[7]=d,o[8]=c.key,o[9]=c.state,o[10]=s):s=o[10],o[11]!==d||o[12]!==c?(n=[d,c],o[11]=d,o[12]=c,o[13]=n):n=o[13],(0,h.useEffect)(s,n),o[14]!==d?(l=e=>{u(t=>{let a=t.key===d?t.state:F(d),s=e(a);return s===a&&t.key===d?t:{key:d,state:s}})},o[14]=d,o[15]=l):l=o[15];let p=l;o[16]!==p?(i=e=>p(t=>{if(t.activeId===e&&(!e||!t.closedTabs.includes(e)&&t.hist.ids[t.hist.cur]===e))return t;let a=e&&t.hist.ids[t.hist.cur]!==e?[...t.hist.ids.slice(0,t.hist.cur+1),e].slice(-50):t.hist.ids;return{...t,activeId:e,page:t.activeId===e?t.page:0,closedTabs:t.closedTabs.filter(t=>t!==e),hist:{ids:a,cur:a===t.hist.ids?t.hist.cur:a.length-1}}}),o[16]=p,o[17]=i):i=o[17];let g=i;return o[18]!==m.state||o[19]!==g||o[20]!==p?(r={state:m.state,update:p,select:g},o[18]=m.state,o[19]=g,o[20]=p,o[21]=r):r=o[21],r}],766544);var $=e.i(846696);e.s(["useResponseSpeech",0,function(e){let{t,i18n:a}=(0,s.useTranslation)("paletteOs"),[n,l]=(0,h.useState)(null),i=(0,h.useRef)(null),r=(0,h.useCallback)(()=>{let e=i.current;i.current=null,l(null),e&&window.speechSynthesis?.cancel()},[]);return(0,h.useEffect)(()=>(window.addEventListener("pagehide",r),()=>{window.removeEventListener("pagehide",r),r()}),[e,r]),{speakingId:n,read:(e,s)=>{if(n===e)return void r();r();let o=()=>$.toast.error(t("session.msg.speechFailed","Could not play speech. Check your browserâs voice settings."));if(!("speechSynthesis"in window)||"u"<typeof SpeechSynthesisUtterance)return void o();try{window.speechSynthesis.cancel();let t=new SpeechSynthesisUtterance(s);t.lang=a.language||document.documentElement.lang||"ko-KR",i.current=t,l(e),t.onend=()=>{i.current===t&&(i.current=null,l(null))},t.onerror=e=>{i.current===t&&(i.current=null,l(null),"canceled"!==e.error&&"interrupted"!==e.error&&o())},window.speechSynthesis.speak(t)}catch{r(),o()}},stop:r}}],808308);var B=e.i(572723),H=e.i(96213);let z={session:".sessionView",talk:".tlBody",memory:".drSplit"};function U(e){return!e}e.s(["usePaletteSidebar",0,function(e){let t,s,n,l,i,r,o,d,c=(0,a.c)(23),{isShell:u}=(0,H.useViewContext)(),m=(0,B.useIsPaletteDesktopViewport)()||!u,p=m?"desktop":"compact";c[0]===Symbol.for("react.memo_cache_sentinel")?(t={desktop:!0,compact:!1},c[0]=t):t=c[0];let[g,f]=(0,h.useState)(t),x=g[p];c[1]!==p?(s=e=>{f(t=>({...t,[p]:"function"==typeof e?e(t[p]):e}))},c[1]=p,c[2]=s):s=c[2];let b=s;c[3]!==m||c[4]!==b?(n=()=>{m||b(!1)},c[3]=m,c[4]=b,c[5]=n):n=c[5];let v=n;return c[6]!==m||c[7]!==u||c[8]!==x||c[9]!==e?(l=()=>{u&&window.dispatchEvent(new CustomEvent("po:list-state",{detail:{view:e,open:x&&!m}}))},i=[e,x,m,u],c[6]=m,c[7]=u,c[8]=x,c[9]=e,c[10]=l,c[11]=i):(l=c[10],i=c[11]),(0,h.useEffect)(l,i),c[12]!==m||c[13]!==u||c[14]!==x||c[15]!==b||c[16]!==e?(r=()=>{let t=t=>{u&&t.detail===e&&b(U)},a=t=>{"Escape"!==t.key||t.defaultPrevented||m||!x||t.target instanceof Element&&t.target.closest('[role="dialog"], [role="menu"], [data-radix-popper-content-wrapper]')||(b(!1),document.querySelector(`.po-shell .railCell[data-view="${e}"]`)?.focus())},s=t=>{!m&&x&&t.target instanceof Element&&t.target.matches(`.po-shell ${z[e]}`)&&b(!1)};return window.addEventListener("po:toggle-list",t),window.addEventListener("keydown",a),window.addEventListener("click",s),()=>{window.removeEventListener("po:toggle-list",t),window.removeEventListener("keydown",a),window.removeEventListener("click",s)}},o=[e,u,m,x,b],c[12]=m,c[13]=u,c[14]=x,c[15]=b,c[16]=e,c[17]=r,c[18]=o):(r=c[17],o=c[18]),(0,h.useEffect)(r,o),c[19]!==v||c[20]!==x||c[21]!==b?(d={open:x,setOpen:b,closeOnMobile:v},c[19]=v,c[20]=x,c[21]=b,c[22]=d):d=c[22],d}],219760)},121158,e=>{"use strict";var t=e.i(843476),a=e.i(271645);e.i(785269);var s=e.i(322831),n=e.i(711404),l=e.i(37398),i=e.i(709382),r=e.i(244002),o=e.i(310373),d=e.i(645182),c=e.i(713967),u=e.i(96213),m=e.i(521135),h=e.i(209165);let p="palette_agents_board_v1",g={free:[],folders:[],nextFolder:1,names:{},paused:[]};function f(e){return e&&"object"==typeof e&&Array.isArray(e.free)&&Array.isArray(e.folders)?{free:e.free,folders:e.folders,nextFolder:"number"==typeof e.nextFolder?e.nextFolder:e.folders.length+1,names:e.names&&"object"==typeof e.names?e.names:{},paused:Array.isArray(e.paused)?e.paused:[]}:null}function x(){try{return f(JSON.parse(localStorage.getItem(p)??"null"))}catch{return null}}function b(e){try{localStorage.setItem(p,JSON.stringify(e))}catch{}}let v="palette_app_colors_v1",j=Math.floor(1.5),y="NEW STACK";function w(e,t){return{left:e-j,top:t,width:3,height:2}}function k(e,t){return e.left<t.left+t.width&&e.left+e.width>t.left&&e.top<t.top+t.height&&e.top+e.height>t.top}function N(e){let t=function(e){var t,a;let[s,n]=(t=e).open?[5,1+Math.min(t.members.length,6)]:(a=Math.max(t.members.length,2))<=4?[2,2]:a<=6?[3,2]:a<=8?[4,2]:a<=9?[3,3]:a<=12?[4,3]:[4,4];return{left:e.gx,top:e.gy,width:s,height:n}}(e);return e.open?t:{...t,height:t.height+1}}function C(e,t,a,s){for(let s of e.free)if(s.id!==a&&k(t,w(s.gx,s.gy)))return!0;for(let a of e.folders)if(a.id!==s&&k(t,N(a)))return!0;return!1}function S(e,t,a,s,n,l=null){return function(e,t,a,s,n,l,i=null){for(let r=0;r<32;r+=1)for(let o=-r;o<=r;o+=1)for(let d=-r;d<=r;d+=1){if(Math.max(Math.abs(d),Math.abs(o))!==r)continue;let c=t+d,u=a+o;if(c<j||u<1)continue;let m=s(c,u);if((!i||m.left>=0&&m.top>=1&&m.left+m.width<=i.cols&&m.top+m.height<=i.rows)&&!C(e,m,n,l))return[c,u]}return[t,a]}(e,t,a,w,s,n,l)}function _(e,t,a,s,n=null){let l=s??(n?Math.max(1,Math.floor((n.rows-a)/2)):8),i=[...e.free],r=0;for(let s of t){let[t,o]=S({...e,free:i},j+3*Math.floor(r/l),a+r%l*2,s,void 0,n);i.push({id:s,gx:t,gy:o}),r+=1}return i}e.s(["AgentsView",0,function(){let{t:e}=(0,s.useTranslation)("paletteOs"),{openConfirm:p,openSurface:k,setView:T,urlSync:E,surface:A,closeSurface:R}=(0,u.useViewContext)(),{apps:D,uninstall:M,isInstalled:I,loading:O,appStoreEnabled:P}=(0,m.usePoInstalledApps)(),{agents:L,loading:F}=(0,l.useBuilderAgents)(),{board:$,hydrated:B,commitBoard:H}=function(){let[e,t]=(0,a.useState)(()=>x()??g),[s,n]=(0,a.useState)(!1),[l,i]=(0,a.useState)(null),r=(0,a.useRef)(e),o=(0,a.useRef)(null),d=(0,a.useRef)(!1),c=(0,a.useCallback)(async()=>{let e=r.current;
24try{let t=await (0,h.apiFetch)("/api/v1/dashboard/workspace",{method:"PATCH",body:JSON.stringify(e)});if(!t.ok)throw Error((await t.json().catch(()=>({})))?.detail??`save failed (${t.status})`);i(null),d.current=r.current!==e}catch(e){d.current=!0,i(e instanceof Error?e.message:"save failed")}},[]),u=(0,a.useCallback)(()=>{d.current=!0,o.current&&window.clearTimeout(o.current),o.current=window.setTimeout(()=>{c()},800)},[c]);return(0,a.useEffect)(()=>{let e=!1;return(async()=>{try{let a=await (0,h.apiFetch)("/api/v1/dashboard"),s=await a.json(),n=f((s?.config??{}).workspace);if(e)return;if(n)r.current=n,t(n),b(n);else{let e=x();e&&(r.current=e,t(e),c())}}catch{}finally{e||n(!0)}})(),()=>{e=!0}},[c]),(0,a.useEffect)(()=>()=>{o.current&&window.clearTimeout(o.current),d.current&&c()},[c]),{board:e,hydrated:s,saveError:l,commitBoard:(0,a.useCallback)((e,a=!1)=>{let s=r.current,n=e(s);n!==s&&(r.current=n,t(n),b(n),a?c():u())},[c,u])}}(),z=(0,a.useRef)(null),U=(0,a.useRef)(!1),[G,W]=(0,a.useState)({}),[K,V]=(0,a.useState)(null),[Y,q]=(0,a.useState)(null),[J,X]=(0,a.useState)(null),Z=(0,a.useRef)(g);Z.current=$;let Q=(0,a.useRef)({x:0,y:0}),ee=(0,a.useMemo)(()=>L.filter(e=>e.is_mine||"app"===e.ui_type&&"published"===e.app_status),[L]),et=(0,a.useMemo)(()=>new Map(ee.map(e=>[`builder-agent:${e.agent_id}`,e])),[ee]),ea=(0,a.useMemo)(()=>ee.map(t=>({id:`builder-agent:${t.agent_id}`,name:t.name,tagline:t.is_mine?t.field??e("agents.privateAgent","Private agent"):e("agents.sharedBy","Shared by {{name}}",{name:t.owner_name||e("agents.sharedApp","Shared app")}),description:t.description,category:"AI Assistants",route:(0,i.agentLaunchTarget)(t).route,gradient:{bg:t.color??"#6366F1",text:"#fff"},icon:n.Robot,developer:t.is_mine?e("agents.you","You"):t.owner_name||e("agents.sharedApp","Shared app"),version:"",rating:0,reviews:0})),[ee,e]),es=(0,a.useMemo)(()=>[...ea,...D],[ea,D]),en=(0,a.useMemo)(()=>new Map(es.map(e=>[e.id,e])),[es]),el=O||F;(0,a.useEffect)(()=>{W(function(){try{return JSON.parse(localStorage.getItem(v)??"{}")}catch{return{}}}())},[]),(0,a.useEffect)(()=>{!el&&B&&H(e=>{let t=function(e,t,a=null){let s=new Set(t?.paused??[]),n=new Set(e.filter(e=>!s.has(e.id)).map(e=>e.id)),l=(t?.free??[]).filter(e=>n.has(e.id)),i=[],r=new Set;for(let e of t?.folders??[]){let t=e.members.filter(e=>n.has(e));if(1===t.length){l.some(e=>e.id===t[0])||l.push({id:t[0],gx:e.gx+j,gy:e.gy});continue}i.push(function(e,t){if(!t)return e;let a=N(e),s=Math.min(Math.max(e.gx,0),Math.max(0,t.cols-a.width)),n=Math.min(Math.max(e.gy,1),Math.max(1,t.rows-a.height));return s===e.gx&&n===e.gy?e:{...e,gx:s,gy:n}}({...e,members:t},a)),t.forEach(e=>r.add(e))}let o=[];for(let e of l){let s={free:o,folders:i,nextFolder:t?.nextFolder??1},[n,l]=function(e,t,a){let s=a?a.cols-3+j:1/0;return[Math.min(Math.max(e,j),Math.max(j,s)),Math.min(Math.max(t,1),Math.max(1,a?a.rows-2:1/0))]}(e.gx,e.gy,a),[r,d]=C(s,w(n,l))?S(s,n,l,void 0,void 0,a):[n,l];o.push({...e,gx:r,gy:d})}let d=new Set([...o.map(e=>
24e.id),...r]),c=e.filter(e=>!d.has(e.id)&&!s.has(e.id)).map(e=>e.id),u={free:o,folders:i,nextFolder:t?.nextFolder??1},m=new Set(e.map(e=>e.id)),h=Object.fromEntries(Object.entries(t?.names??{}).filter(([e])=>m.has(e)));return{free:c.length?_(u,c,1,void 0,a):o,folders:i,nextFolder:Math.max(t?.nextFolder??1,i.length+1),names:h,paused:(t?.paused??[]).filter(e=>m.has(e))}}(es,e);return JSON.stringify(e)===JSON.stringify(t)?e:t},!0)},[es,el,B,H]);let ei=(0,a.useCallback)(e=>{let t=et.get(e.id);return t?(0,i.agentLaunchTarget)(t):{route:e.route,subRoute:""}},[et]),er=(0,a.useCallback)(e=>$.names[e.id]||e.name,[$.names]),eo=(0,a.useCallback)(e=>{q(null);let t=ei(e);k(t.route,{title:er(e),subRoute:t.subRoute||void 0})},[er,ei,k]),ed=(0,a.useCallback)(e=>{if(!A)return!1;let t=ei(e);return A.route===t.route&&(A.subRoute??"")===t.subRoute},[ei,A]),ec=(0,a.useCallback)(t=>{(q(null),E)?(T("plugin"),t&&window.history.replaceState(null,"",`/connect?section=${t}`)):k("/connect",{title:e("agents.connect","Connect")})},[T,E,k,e]),eu=(0,a.useCallback)((e,t,a)=>{let s=[...e.folders],n=[...e.free],l=s.findIndex(e=>e.id===t);if(l<0)return e;let i=s[l],r=i.members.filter(e=>e!==a);if(r.length<=1){if(1===r.length){let[a,l]=S({...e,folders:s.filter(e=>e.id!==t),free:n},i.gx+j,i.gy,r[0],t);n.push({id:r[0],gx:a,gy:l})}s.splice(l,1)}else s[l]={...i,members:r};return{...e,free:n,folders:s}},[]),em=(0,a.useCallback)(e=>{H(t=>({...t,folders:t.folders.map(t=>t.id===e?{...t,open:!t.open}:t)}),!0),q(null)},[H]),eh=(0,a.useCallback)((e,t)=>{H(a=>{let s={...a,free:[...a.free],folders:a.folders.map(e=>({...e,members:[...e.members]}))};for(let a of t){let t=s.folders.findIndex(t=>t.id===e);if(t<0)break;let n=s.folders[t];if(n.members.includes(a)||n.members.length>=16)continue;s.folders[t]={...n,members:[...n.members,a]};let l=s.folders.find(t=>t.id!==e&&t.members.includes(a));l?s=eu(s,l.id,a):s.free=s.free.filter(e=>e.id!==a)}return s},!0),q(null)},[H,eu]),ep=(0,a.useCallback)(e=>{H(t=>{let a=e.filter(e=>en.has(e)).slice(0,16),s=t.free.filter(e=>a.includes(e.id)),n=s.length?Math.max(0,Math.min(...s.map(e=>e.gx))-j):1,l=s.length?Math.min(...s.map(e=>e.gy)):1,i={...t,free:[...t.free],folders:t.folders.map(e=>({...e,members:[...e.members]}))};for(let e of a){let t=i.folders.find(t=>t.members.includes(e));t&&(i=eu(i,t.id,e)),i.free=i.free.filter(t=>t.id!==e)}return{...i,folders:[...i.folders,{id:`f${i.nextFolder}`,name:y,gx:n,gy:l,members:a}],nextFolder:i.nextFolder+1}},!0),q(null)},[en,H,eu]),eg=(0,a.useCallback)(()=>{H(e=>({...e,folders:[...e.folders,{id:`f${e.nextFolder}`,name:y,gx:0,gy:1,members:[]}],nextFolder:e.nextFolder+1}),!0),q(null)},[H]),ef=(0,a.useCallback)(e=>{H(t=>{let a=t.folders.filter(t=>t.id!==e.id),s=[...t.free],n=0;for(let l of e.members){let[i,r]=S({...t,folders:a,free:s},e.gx+j+3*n,e.gy,l,e.id);s.push({id:l,gx:i,gy:r}),n+=1}return{...t,folders:a,free:s}},!0),q(null)},[H]),ex=(0,a.useCallback)((e,t)=>{H(a=>{let s=a.folders.find(e=>e.id===t);if(!s)return a;let n=eu({...a,free:[...a.free],folders:a.folders.map(e=>({...e,members:[...e.members]}))},t,e);if(n.free.some(t=>t.id===e))return n;let[l,i]=S(n,s.gx+j,s.gy,e,t);return{...n,free:[...n.free,{id:e,gx:l,gy:i}]}},!0),q(null)},[H,eu]),eb=(0,a.useCallback)((t,a)=>{q(null),p({title:e("agents.uninstallTitle","Uninstall application"),desc:e("agents.uninstallDesc","{{name}} will be removed from your account. Your app data is kept for reinstalling later.",{name:er(t)}),danger:!0,confirmLabel:e("agents.uninstall","Uninstall"),onConfirm:async()=>
24{let e=await M(t.id);return e.ok||console.error("Uninstall failed:",e.error),a?.(e.ok),e.ok}})},[er,p,e,M]),[ev,ej]=(0,a.useState)(null),ey=(0,a.useCallback)(e=>{q(null),ej(e)},[]),ew=(0,a.useCallback)(e=>{q(null),X({kind:"folder",id:e.id,value:e.name})},[]),ek=(0,a.useCallback)((e,t)=>{q(null);let a=t?Z.current.folders.find(e=>e.id===t):void 0;a&&!a.open&&em(a.id),X({kind:"app",id:e.id,value:er(e)})},[er,em]),eN=(0,a.useCallback)(()=>{if(X(null),!J)return;let e=J.value.trim().slice(0,64);H(t=>{if("folder"===J.kind)return{...t,folders:t.folders.map(t=>t.id===J.id?{...t,name:e||t.name}:t)};let a={...t.names};return e?a[J.id]=e:delete a[J.id],{...t,names:a}},!0)},[H,J]),eC=(0,a.useCallback)(e=>{q(null),e.length&&H(t=>({...t,free:t.free.filter(t=>!e.includes(t.id)),folders:t.folders.map(t=>({...t,members:t.members.filter(t=>!e.includes(t))})),paused:[...t.paused,...e.filter(e=>!t.paused.includes(e))]}),!0)},[H]),eS=(0,a.useCallback)(e=>{q(null),H(t=>{let a=e.filter(e=>en.has(e)&&!t.free.some(t=>t.id===e));return{...t,paused:t.paused.filter(t=>!e.includes(t)),free:a.length?_(t,a,1):t.free}},!0)},[en,H]),e_=(0,a.useCallback)((e,t,a)=>{let s=e.clientX,n=e.clientY;if(!s&&!n&&"currentTarget"in e&&e.currentTarget instanceof HTMLElement){let t=e.currentTarget.getBoundingClientRect();s=t.left,n=t.bottom+4}Q.current={x:s,y:n},q({x:s,y:n,head:t,variant:"dark",sections:a})},[]),eT=(0,a.useCallback)((e,t)=>{q({...Q.current,head:e,variant:"dark",sections:[t]})},[]),eE=(0,a.useCallback)(t=>[...Z.current.folders.map(e=>({label:e.name,on:()=>eh(e.id,t)})),{label:`ï¼ ${e("agents.newGroup","New group")}`,on:()=>ep(t)}],[eh,ep,e]),eA=(0,a.useCallback)(t=>{let a=Z.current.free.map(e=>en.get(e.id)).filter(e=>!!e).filter(e=>!t.members.includes(e.id)).sort((e,t)=>e.name.localeCompare(t.name)).slice(0,6);return a.length?a.map(e=>({label:er(e),on:()=>eh(t.id,[e.id])})):[{label:e("agents.nothingToAdd","Nothing to add"),disabled:!0,on:()=>{}}]},[eh,en,er,e]),eR=(0,a.useCallback)(()=>{let t=Z.current.paused;return[...t.map(e=>({label:Z.current.names[e]||en.get(e)?.name||e,id:e,on:()=>eS([e])})),{label:e("agents.resumeAll","Resume all"),id:"all",on:()=>eS(t.slice())}]},[en,eS,e]),eD=(0,a.useCallback)((t,a)=>{let s=[{label:`${e("agents.addToGroup","Add to group")} âº`,on:()=>eT(e("agents.addToGroup","Add to group"),eE([t.id]))},{label:e("agents.rename","Rename"),on:()=>ek(t,a)}],n=et.has(t.id),l=et.get(t.id);return n||s.push({label:e("agents.setting","Setting"),on:()=>ey(t)}),l?.is_mine&&s.push({label:e("agents.share","Shareâ¦"),on:()=>{q(null),k("/connect",{title:e("agents.connect","Connect"),subRoute:`?section=private&agent=${l.agent_id}`})}}),a&&s.push({label:e("agents.removeFromGroup","Delete from group"),on:()=>ex(t.id,a)}),[[{label:`⸠${e("agents.runNow","Run now")}`,on:()=>eo(t)},{label:e("agents.close","Close"),disabled:!ed(t),on:()=>{q(null),R()}}],s,[{label:e("agents.pause","Pause"),on:()=>eC([t.id])},...n?[]:[{label:e("agents.uninstall","Uninstall"),danger:!0,on:()=>eb(t)}]]]},[eb,R,eT,eE,ed,eo,ey,k,eC,et,ex,ek,e]),eM=(0,a.useCallback)(t=>[[{label:t.open?e("agents.collapse","Collapse"):e("agents.expand","Expand"),on:()=>em(t.id)}],[{label:`ï¼ ${e("agents.addAgent","Add agent")} âº`,on:()=>eT(e("agents.addAgent","Add agent"),eA(t))}],[{label:e("agents.rename","Rename"),on:()=>ew(t)}],[{label:e("agents.dissolve","Dissolve"),danger:!0,on:()=>ef(t)}]],[eA,ef,eT,ew,e,em]),eI=(0,a.useCallback)(()=>[[{label:`ï¼ ${e("agents.appStore","App Store")}`,disabled:!P,on:()=>ec("agents")},{label:e("agents.newGroup","New group"),on:eg}],Z.current.paused.length?[{label:`${e("agents.paused","Paused")} (${Z.current.paused.length}) âº`,on:()=>eT(e("agents.paused","Paused"),eR())}
24]:[]],[P,eT,eg,ec,eR,e]),eO=(e,t)=>{0===t.button&&(t.preventDefault(),t.stopPropagation(),t.currentTarget instanceof HTMLElement&&t.currentTarget.focus(),U.current=!1,z.current=e)},eP=(0,a.useCallback)(e=>{if("folder"===e.kind)return void em(e.id);let t=en.get(e.id);t&&eo(t)},[en,eo,em]),eL=(0,a.useCallback)(e=>{let t=document.elementFromPoint(e.x,e.y)?.closest("[data-tile-id]"),a=t?.dataset.tileId,s=t?.dataset.tileKind;if("folder"!==e.kind){if("folder"===s&&a&&a!==e.folderId)return void eh(a,[e.id]);if("agent"===s&&a&&a!==e.id){let s=t?.closest("[data-group-id]")?.dataset.groupId;s?eh(s,[e.id]):ep([a,e.id]);return}e.folderId&&!t?.closest("[data-group-id]")&&ex(e.id,e.folderId)}},[eh,ep,ex]);(0,a.useEffect)(()=>{let e=e=>{let t=z.current;if(t||K){if(t&&!K){if(5>=Math.hypot(e.clientX-t.cx,e.clientY-t.cy))return;U.current=!0,q(null),V({...t,x:e.clientX,y:e.clientY});return}K&&V({...K,x:e.clientX,y:e.clientY})}},t=()=>{if(z.current=null,K){eL(K),V(null);return}};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",t),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",t)}},[K,eL]),(0,a.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(q(null),X(null),z.current&&(U.current=!0),z.current=null,V(null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let eF=e=>{if(U.current){U.current=!1;return}eP(e)},e$=(e,t)=>{t.target===t.currentTarget&&("Enter"===t.key||" "===t.key)&&(t.preventDefault(),eP(e))},eB=e=>(0,o.appFace)(e.id,G[e.id]?.ac??e.gradient?.bg),eH=e=>{let a=(0,r.sealForKey)(e),s=G[e];return(0,t.jsx)(r.Seal,{glyph:a.glyph,container:a.container,bg:s?.ac??"var(--ink)",fg:s?.af??"var(--paper)"})},ez=a=>(0,t.jsx)("input",{className:a,autoFocus:!0,value:J?.value??"",maxLength:64,"aria-label":J?.kind==="app"?e("agents.appName","App name"):e("agents.groupName","Group name"),onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),onChange:e=>X(t=>t&&{...t,value:e.target.value}),onBlur:eN,onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),eN()),"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),X(null))}}),eU=(a,s)=>{let n={kind:"agent",id:a.id,folderId:s,cx:0,cy:0},l=K?.kind==="agent"&&K.id===a.id;return(0,t.jsxs)("div",{"data-tile-id":a.id,"data-tile-kind":"agent","data-app-id":a.id,className:`myAppTile${l?" dragging":""}`,role:"button",tabIndex:0,"aria-label":e("agents.tileAria","Open {{name}}",{name:er(a)}),onMouseDown:e=>eO({...n,cx:e.clientX,cy:e.clientY},e),onClick:()=>eF(n),onKeyDown:e=>e$(n,e),onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),e_(e,er(a),eD(a,s))},children:[(0,t.jsx)(o.AppLogo,{id:a.id,face:eB(a),className:"myAppLogo",style:{color:G[a.id]?.af??"var(--white)"}}),J?.kind==="app"&&J.id===a.id?ez("myAppName myAppRename"):(0,t.jsx)("span",{className:"myAppName",children:er(a)}),(0,t.jsx)("span",{className:"myAppDesc",children:a.tagline||a.description||a.category})]},a.id)},eG=a=>{let s={kind:"folder",id:a.id,cx:0,cy:0},n=a.members.map(e=>en.get(e)).filter(e=>!!e),l=e=>{e.preventDefault(),e.stopPropagation(),e_(e,a.name,eM(a))};return a.open?(0,t.jsxs)("section",{className:"myAppGroup","data-group-id":a.id,"data-tile-id":a.id,"data-tile-kind":"folder",onContextMenu:l,children:[(0,t.jsxs)("div",{className:"myAppGroupHead",children:[(0,t.jsx)(o.AppLogo,{id:a.id,className:"myAppGroupMark",face:"var(--surface-hover)",children:(0,t.jsx)("span",{className:"myAppMosaic",children:n.slice(0,4).map(e=>(0,t.jsx)("i",{children:eH(e.id)},e.id))})}),J?.kind==="folder"&&J.id===a.id?ez("myAppGroupRename"):(0,t.jsx)("h3",{children:a.name}),(0,t.jsx)("span",{className:"myAppGroupCount",children:e("agents.groupApps","{{count}} apps",{count:n.length})}),(0,t.jsx)("button",{type:"button",className:"myAppGroupBtn","aria-label":e("agents.groupOptions","Group options"),onClick:l,children:(0,t.jsx)(r.Glyph,{name:"h_more"})}),(0,t.jsx)("button",{type:"button",className:"myAppGroupBtn","aria-label":e("agents.collapse","Collapse"),onClick:()=>em(a.id),children:(0,t.jsx)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,t.jsx)("path",{d:"m6 15 6-6 6 6"})})})]}),(0,t.jsxs)("div",{className:"myAppGroupGrid",children:[n.map(e=>eU(e,a.id)),!n.length&&(0,t.jsx)("p",{className:"myAppsEmptyInline",children:e("agents.nothingToAdd","Nothing to add")})]})]},a.id):(0,t.jsxs)("div",{"data-tile-id":a.id,"data-tile-kind":"folder",className:"myAppTile myAppFolder",role:"button",tabIndex:0,"aria-label":e("agents.expandHint","Click to expand"),onMouseDown:e=>eO({...s,cx:e.clientX,cy:e.clientY},e),onClick:()=>eF(s),onKeyDown:e=>e$(s,e),onContextMenu:l,children:[(0,t.jsxs)(o.AppLogo,{id:a.id,className:"myAppLogo",face:"rgb(var(--white-rgb) / .55)",children:[(0,t.jsx)("span",{className:"myAppMosaic",children:n.slice(0,4).map(e=>(0,t.jsx)("i",{children:eH(e.id)},e.id))}),(0,t.jsx)("span",{className:"myAppFolderBadge",children:n.length})]}),J?.kind==="folder"&&J.id===a.id?ez("myAppName myAppRename"):(0,t.jsx)("span",{className:"myAppName",children:a.name}),(0,t.jsx)("span",{className:"myAppDesc",children:e("agents.groupApps","{{count}} apps",{count:n.length})})]},a.id)},eW=$.folders.filter(e=>e.open),eK=$.folders.filter(e=>!e.open),eV=$.free.map(e=>en.get(e.id)).filter(e=>!!e),eY=!el&&B&&0===es.length,eq=K?.kind==="agent"?en.get(K.id):null;return(0,t.jsxs)("div",{className:"viewPane agentsView transparent myApps",children:[(0,t.jsxs)("header",{className:"myAppsHead",children:[(0,t.jsx)("h1",{children:e("agents.title","My Apps")}),P&&(0,t.jsxs)("button",{type:"button",className:"myAppsStoreLink",onClick:()=>ec(),children:[e("agents.browseStore","Browse the Store"),(0,t.jsx)(r.Glyph,{name:"h_arrowRight"})]})]}),(0,t.jsx)("div",{className:"myAppsStage",onContextMenu:t=>{t.target===t.currentTarget&&(t.preventDefault(),e_(t,e("agents.title","My Apps"),eI()))},children:eY?(0,t.jsxs)("div",{className:"storeEmpty",children:[(0,t.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,t.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,t.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,t.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,t.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1.5"})]}),(0,t.jsx)("h2",{children:e("agents.emptyTitle","No apps in use yet")}),(0,t.jsx)("p",{children:P?e("agents.emptyNoApps","Add the apps you need from the Store."):e("agents.emptyStoreDisabled","The App Store is disabled for this workspace.")}),P&&(0,t.jsx)("button",{type:"button",className:"storeBtn primary",onClick:()=>ec(),children:e("agents.findApps","Find apps")})]}):(0,t.jsxs)("div",{className:"myAppsGrid",onContextMenu:t=>{t.target===t.currentTarget&&(t.preventDefault(),e_(t,e("agents.title","My Apps"),eI()))},children:[eW.map(eG),eK.map(eG),eV.map(e=>eU(e))]})}),K&&eq&&(0,t.jsx)("div",{className:"myAppDragGhost",style:{left:K.x,top:K.y},children:(0,t.jsx)(o.AppLogo,{id:eq.id,face:eB(eq),style:{color:G[eq.id]?.af??"var(--white)"}})}
24),ev&&(0,t.jsx)(d.AppInfoDialog,{app:ev,installed:I(ev.id),color:G[ev.id]??null,returnFocus:[...document.querySelectorAll("[data-app-id]")].find(e=>e.dataset.appId===ev.id)??document.querySelector(".myAppsStoreLink"),onClose:()=>ej(null),onOpen:()=>eo(ev),onApplyColor:e=>{var t;let a;return t=ev.id,a={...G},void(e?a[t]=e:delete a[t],localStorage.setItem(v,JSON.stringify(a)),W(a))},onUninstall:async()=>(await M(ev.id)).ok},ev.id),Y&&(0,t.jsx)(c.PoContextMenu,{ctx:Y,onClose:()=>q(null)})]})}],121158)},827995,e=>{"use strict";var t=e.i(843476),a=e.i(271645),s=e.i(618566);e.i(785269);var n=e.i(322831),l=e.i(846696),i=e.i(778085),r=e.i(819789),o=e.i(209165);let d=["newest","oldest","name","largest"],c={q:"",kinds:[],origins:[],from:"",to:"",favorite:!1,sort:"newest"};function u(e){let t=e.id.indexOf(":");return t<0?e.id:e.id.slice(t+1)}function m(e){return"artifact"===e.source?`${o.BASE}/api/v1/history/artifacts/${u(e)}/download`:null!=e.room_id&&null!=e.file_id?`${o.BASE}/api/v1/data-rooms/${e.room_id}/files/${e.file_id}/download`:null}var h=e.i(713967),p=e.i(706347),g=e.i(244002);let f=["images","videos","documents","web","data","design"],x={images:["image"],videos:["video"],documents:["document","markdown","report","newsletter"],web:["html"],data:["dashboard"],design:["svg","carousel"]};function b(e){let t=["preview"];"session"===e.origin&&e.thread_id?t.push("openChat"):"messenger"===e.origin?t.push(e.channel_id?"openTalk":"openFile"):"drive"===e.origin&&null!=e.room_id&&t.push("openDrive");let a=[];return m(e)&&a.push("download"),"session"===e.origin&&e.thread_id&&e.artifact_slug?a.push("share"):"messenger"===e.origin&&e.url&&a.push("copyLink"),[t,a,["favorite"],["delete"]].filter(e=>e.length>0)}let v=["grid","wall","list"],j=["s","m","l"],y={view:"grid",density:"m",group:!0},w="po.history.prefs";var k=e.i(96213),N=e.i(500932);let C=(e,t)=>e(`history.kind.${t}`,t),S=(e,t)=>e(`history.origin.${t}`,t.toUpperCase()),_={image:"image",video:"video",markdown:"doc",document:"doc",report:"doc",newsletter:"doc",html:"web",dashboard:"sheet",svg:"swatch",carousel:"swatch"};function T(e){let s,l,i,r,o,d,c=(0,N.c)(30),{item:u,natural:m}=e,{t:h}=(0,n.useTranslation)("paletteOs"),p=_[u.kind]??"doc",[g,f]=(0,a.useState)(null);if(u.thumbnail_url&&u.thumbnail_url!==g){let e,a,s,n,l=`hsThumb hs-${p} hs-pic${m?" natural":""}`;return c[0]!==u.thumbnail_url?(e=()=>f(u.thumbnail_url),c[0]=u.thumbnail_url,c[1]=e):e=c[1],c[2]!==u.thumbnail_url||c[3]!==e?(a=(0,t.jsx)("img",{src:u.thumbnail_url,alt:"",loading:"lazy",onError:e}),c[2]=u.thumbnail_url,c[3]=e,c[4]=a):a=c[4],c[5]!==p?(s="video"===p&&(0,t.jsx)("span",{className:"hsPlay","aria-hidden":!0}),c[5]=p,c[6]=s):s=c[6],c[7]!==l||c[8]!==a||c[9]!==s?(n=(0,t.jsxs)("div",{className:l,children:[a,s]}),c[7]=l,c[8]=a,c[9]=s,c[10]=n):n=c[10],n}let x=`hsThumb hs-${p}`;return c[11]!==p?(s="video"===p&&(0,t.jsx)("span",{className:"hsPlay","aria-hidden":!0}),c[11]=p,c[12]=s):s=c[12],c[13]!==u.kind||c[14]!==p||c[15]!==h?(l="image"===p&&(0,t.jsx)("span",{className:"hsPlateTxt",children:C(h,u.kind)}),c[13]=u.kind,c[14]=p,c[15]=h,c[16]=l):l=c[16],c[17]!==p?(i="doc"===p&&(0,t.jsxs)("div",{className:"hsSkel","aria-hidden":!0,children:[(0,t.jsx)("span",{}),(0,t.jsx)("span",{}),(0,t.jsx)("span",{}),(0,t.jsx)("span",{}),(0,t.jsx)("span",{})]}),c[17]=p,c[18]=i):i=c[18],c[19]!==p?(r="web"===p&&(0,t.jsxs)("div",{className:"hsWeb","aria-hidden":!0,children:[(0,t.jsxs)("div",{className:"hsWebBar",children:[(0,t.jsx)("i",{}),(0,t.jsx)("i",{}),(0,t.jsx)("i",{})]}),(0,t.jsxs)("div",{className:"hsWebBody",children:[(0,t.jsx)("div",{className:"a"}),(0,t.jsxs)("div",{className:"b",children:[(0,t.jsx)("i",{}),(0,t.jsx)("i",{className:"sig"})]})]})]}),c[19]=p,c[20]=r):r=c[20],c[21]!==p?(o="swatch"===p&&(0,t.jsxs)("div",{className:"hsSwatch","aria-hidden":!0,children:[(0,t.jsx)("i",{}),(0,t.jsx)("i",{className:"sig"}),(0,t.jsx)("i",{className:"pap"}),(0,t.jsx)("i",{className:"mid"})]}),c[21]=p,c[22]=o):o=c[22],c[23]!==x||c[24]!==s||c[25]!==l||c[26]!==i||c[27]!==r||c[28]!==o?(d=(0,t.jsxs)("div",{className:x,children:[s,l,i,r,o]}),c[23]=x,c[24]=s,c[25]=l,c[26]=i,c[27]=r,c[28]=o,c[29]=d):d=c[29],d}function E(e){let a,s,l,i,r,o,d,c,u,m,h,p,f,x=(0,N.c)(40),{item:v,actions:j,className:y}=e,{t:w}=(0,n.useTranslation)("paletteOs");x[0]!==j||x[1]!==v?(a=e=>{e.stopPropagation();let t=e.currentTarget.getBoundingClientRect();j.menu(v,{x:Math.max(8,t.right-240),y:t.bottom+4})},x[0]=j,x[1]=v,x[2]=a):a=x[2];let k=a;
24x[3]!==v?(s=b(v).flat().includes("download"),x[3]=v,x[4]=s):s=x[4];let C=s,S=y??"hsActs",_=`hsIco hsStar${v.is_favorite?" on":""}`;return x[5]!==v.is_favorite||x[6]!==w?(l=v.is_favorite?w("history.action.unfavorite","Remove from favorites"):w("history.action.favorite","Favorite"),x[5]=v.is_favorite,x[6]=w,x[7]=l):l=x[7],x[8]!==v.is_favorite||x[9]!==w?(i=v.is_favorite?w("history.action.unfavorite","Remove from favorites"):w("history.action.favorite","Favorite"),x[8]=v.is_favorite,x[9]=w,x[10]=i):i=x[10],x[11]!==j||x[12]!==v?(r=()=>j.toggleFavorite(v),x[11]=j,x[12]=v,x[13]=r):r=x[13],x[14]===Symbol.for("react.memo_cache_sentinel")?(o=(0,t.jsx)(g.Glyph,{name:"h_star"}),x[14]=o):o=x[14],x[15]!==v.is_favorite||x[16]!==_||x[17]!==l||x[18]!==i||x[19]!==r?(d=(0,t.jsx)("button",{type:"button",className:_,"aria-pressed":v.is_favorite,"aria-label":l,title:i,onClick:r,children:o}),x[15]=v.is_favorite,x[16]=_,x[17]=l,x[18]=i,x[19]=r,x[20]=d):d=x[20],x[21]!==j||x[22]!==C||x[23]!==v||x[24]!==w?(c=C&&(0,t.jsx)("button",{type:"button",className:"hsIco","aria-label":w("history.action.download","Download"),title:w("history.action.download","Download"),onClick:()=>j.download(v),children:(0,t.jsx)(g.Glyph,{name:"h_download"})}),x[21]=j,x[22]=C,x[23]=v,x[24]=w,x[25]=c):c=x[25],x[26]!==w?(u=w("history.action.more","More actions"),x[26]=w,x[27]=u):u=x[27],x[28]!==w?(m=w("history.action.more","More actions"),x[28]=w,x[29]=m):m=x[29],x[30]===Symbol.for("react.memo_cache_sentinel")?(h=(0,t.jsx)(g.Glyph,{name:"h_more"}),x[30]=h):h=x[30],x[31]!==k||x[32]!==u||x[33]!==m?(p=(0,t.jsx)("button",{type:"button",className:"hsIco","aria-label":u,title:m,onClick:k,children:h}),x[31]=k,x[32]=u,x[33]=m,x[34]=p):p=x[34],x[35]!==c||x[36]!==p||x[37]!==S||x[38]!==d?(f=(0,t.jsxs)("div",{className:S,onClick:A,children:[d,c,p]}),x[35]=c,x[36]=p,x[37]=S,x[38]=d,x[39]=f):f=x[39],f}function A(e){return e.stopPropagation()}function R(e){let a,s,l,i,r,o,d,c,u,m,h,p,g,f=(0,N.c)(42),{item:x,actions:b,natural:v}=e,{t:j}=(0,n.useTranslation)("paletteOs");f[0]!==b||f[1]!==x?(a=e=>{e.preventDefault(),b.menu(x,{x:e.clientX,y:e.clientY})},f[0]=b,f[1]=x,f[2]=a):a=f[2];let y=a,w=`hsCard${x.is_favorite?" fav":""}`,k=x.kind;f[3]!==b||f[4]!==x?(s=()=>b.preview(x),f[3]=b,f[4]=x,f[5]=s):s=f[5],f[6]!==j?(l=j("history.action.preview","Preview"),f[6]=j,f[7]=l):l=f[7];let _=`${l} â ${x.title}`;f[8]!==x||f[9]!==v?(i=(0,t.jsx)(T,{item:x,natural:v}),f[8]=x,f[9]=v,f[10]=i):i=f[10],f[11]!==x.title?(r=(0,t.jsx)("strong",{className:"hsName",title:x.title,children:x.title}),f[11]=x.title,f[12]=r):r=f[12],f[13]!==x.origin||f[14]!==x.origin_label||f[15]!==j?(o=x.origin_label||S(j,x.origin),f[13]=x.origin,f[14]=x.origin_label,f[15]=j,f[16]=o):o=f[16],f[17]!==x.kind||f[18]!==j?(d=C(j,x.kind),f[17]=x.kind,f[18]=j,f[19]=d):d=f[19],f[20]!==d||f[21]!==o?(c=[o,d].filter(Boolean),f[20]=d,f[21]=o,f[22]=c):c=f[22];let A=c.join(" · ");return f[23]!==A?(u=(0,t.jsx)("small",{className:"hsCaption",children:A}),f[23]=A,f[24]=u):u=f[24],f[25]!==u||f[26]!==r?(m=(0,t.jsxs)("span",{className:"hsBody",children:[r,u]}),f[25]=u,f[26]=r,f[27]=m):m=f[27],f[28]!==m||f[29]!==s||f[30]!==_||f[31]!==i?(h=(0,t.jsxs)("button",{type:"button",className:"hsOpen",onClick:s,"aria-label":_,children:[i,m]}),f[28]=m,f[29]=s,f[30]=_,f[31]=i,f[32]=h):h=f[32],f[33]!==b||f[34]!==x?(p=(0,t.jsx)(E,{item:x,actions:b}),f[33]=b,f[34]=x,f[35]=p):p=f[35],f[36]!==x.kind||f[37]!==y||f[38]!==h||f[39]!==p||f[40]!==w?(g=(0,t.jsxs)("article",{className:w,onContextMenu:y,"data-kind":k,children:[h,p]}),f[36]=x.kind,f[37]=y,f[38]=h,f[39]=p,f[40]=w,f[41]=g):g=f[41],g}function D(e){let a,s,l,i,r,o,d,c,u,m,h,p,g=(0,N.c)(37),{item:f,actions:x}=e,{t:b}=(0,n.useTranslation)("paletteOs");g[0]!==x||g[1]!==f?(a=e=>{e.preventDefault(),x.menu(f,{x:e.clientX,y:e.clientY})},g[0]=x,g[1]=f,g[2]=a):a=g[2];let v=a,j=`hsRow${f.is_favorite?" fav":""}`;g[3]!==x||g[4]!==f?(s=()=>x.preview(f),g[3]=x,g[4]=f,g[5]=s):s=g[5],g[6]!==f?(l=(0,t.jsx)("span",{className:"hsRowThumb",children:(0,t.jsx)(T,{item:f})}),g[6]=f,g[7]=l):l=g[7],g[8]!==f.title?(i=(0,t.jsx)("strong",{className:"hsRowName",children:f.title}),g[8]=f.title,g[9]=i):i=g[9],g[10]!==f.origin||g[11]!==f.origin_label||g[12]!==b?(r=f.origin_label||S(b,f.origin),g[10]=f.origin,g[11]=f.origin_label,g[12]=b,g[13]=r):r=g[13],g[14]!==f.kind||g[15]!==b?(o=C(b,f.kind),g[14]=f.kind,g[15]=b,g[16]=o):o=g[16],g[17]!==r||g[18]!==o?(d=[r,o].filter(
24Boolean),g[17]=r,g[18]=o,g[19]=d):d=g[19];let y=d.join(" · ");return g[20]!==y?(c=(0,t.jsx)("small",{className:"hsRowSub",children:y}),g[20]=y,g[21]=c):c=g[21],g[22]!==c||g[23]!==i?(u=(0,t.jsxs)("span",{className:"hsRowCap",children:[i,c]}),g[22]=c,g[23]=i,g[24]=u):u=g[24],g[25]!==u||g[26]!==s||g[27]!==l?(m=(0,t.jsxs)("button",{type:"button",className:"hsRowMain",onClick:s,children:[l,u]}),g[25]=u,g[26]=s,g[27]=l,g[28]=m):m=g[28],g[29]!==x||g[30]!==f?(h=(0,t.jsx)(E,{item:f,actions:x,className:"hsRowActs"}),g[29]=x,g[30]=f,g[31]=h):h=g[31],g[32]!==v||g[33]!==m||g[34]!==h||g[35]!==j?(p=(0,t.jsxs)("div",{className:j,onContextMenu:v,children:[m,h]}),g[32]=v,g[33]=m,g[34]=h,g[35]=j,g[36]=p):p=g[36],p}function M(){let e,a,s=(0,N.c)(2);return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,t.jsx)("div",{className:"hsThumb"}),s[0]=e):e=s[0],s[1]===Symbol.for("react.memo_cache_sentinel")?(a=(0,t.jsxs)("div",{className:"hsCard hsSkelCard","aria-hidden":!0,children:[e,(0,t.jsxs)("div",{className:"hsBody",children:[(0,t.jsx)("span",{className:"hsSkLine w60"}),(0,t.jsx)("span",{className:"hsSkLine w35"})]})]}),s[1]=a):a=s[1],a}let I={preview:["history.action.preview","Preview"],openChat:["history.action.openChat","Open chat"],openTalk:["history.action.openTalk","Open in Talk"],openDrive:["history.action.openDrive","Open in Drive"],openFile:["history.action.openFile","Open file"],download:["history.action.download","Download"],share:["history.action.share","Share"],copyLink:["history.action.copyLink","Copy asset link"],favorite:["history.action.favorite","Favorite"],delete:["history.action.delete","Delete from History"]};function O(e,t){let[a,s]=I[t];return e(a,s)}function P(e,t,a){let s={preview:()=>t.preview(e),openChat:()=>t.openOrigin(e),openTalk:()=>t.openOrigin(e),openDrive:()=>t.openOrigin(e),openFile:()=>t.openOrigin(e),download:()=>t.download(e),share:()=>t.share(e),copyLink:()=>t.share(e),favorite:()=>t.toggleFavorite(e),delete:()=>t.remove(e)};return b(e).map(t=>t.map(t=>({id:t,label:O(a,t),on:s[t],..."favorite"===t?{checked:e.is_favorite}:{},..."delete"===t?{danger:!0}:{}})))}var L=e.i(590637),F=e.i(675696),$=e.i(173623),B=e.i(549127);let H=new Set(["html","report","dashboard","carousel","newsletter","svg","markdown"]);function z(e){let s,l,i,r,o,d,c,u,m,h,p,f,x,v,j,y,w,k,_,T,E,A,R=(0,N.c)(147),{items:D,index:M,onIndex:I,onClose:L,actions:F,fallbackFocus:H}=e,{t:z,i18n:K}=(0,n.useTranslation)("paletteOs"),V=D[M],Y=(0,a.useId)(),[q,J]=(0,a.useState)(!1);if(R[0]===Symbol.for("react.memo_cache_sentinel")?(s=[],R[0]=s):s=R[0],(0,a.useEffect)(G,s),!V)return null;if(R[1]!==F||R[2]!==Y||R[3]!==q||R[4]!==H||R[5]!==K.language||R[6]!==M||R[7]!==V||R[8]!==D.length||R[9]!==L||R[10]!==I||R[11]!==z){let e,a,s,n,N,_,T,E,A,G,X,Z,Q,ee,et,ea,es,en,el,ei,er,eo,ed,ec,eu,em,eh,ep=b(V).flat(),eg=b(V)[0].find(e=>"preview"!==e)??null,ef=ep.includes("download")&&("image"===V.kind||!eg)?"download":eg,ex=P(V,F,z).flat().filter(e=>"preview"!==e.id&&e.id!==ef);R[29]!==K.language||R[30]!==V.created_at?(e=new Intl.DateTimeFormat(K.language,{dateStyle:"medium",timeStyle:"short"}).format(new Date(V.created_at)),R[29]=K.language,R[30]=V.created_at,R[31]=e):e=R[31];let eb=e;l=$.ConversationDialog,c=V.title,u=L,m=H,h=!0,i="hsPreview",R[32]!==M||R[33]!==D.length||R[34]!==I?(r=e=>{if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.target.closest("input, textarea, select, video, audio, [contenteditable='true']"))return;let t="ArrowLeft"===e.key?M-1:"ArrowRight"===e.key?M+1:M;t!==M&&t>=0&&t<D.length&&(e.preventDefault(),I(t))},R[32]=M,R[33]=D.length,R[34]=I,R[35]=r):r=R[35];let ev=`hsLbStage${"image"===V.kind?" hsPreviewImage":""}`;R[36]!==V?(a=(0,t.jsx)(W,{item:V},V.id),R[36]=V,R[37]=a):a=R[37],R[38]!==ev||R[39]!==a?(o=(0,t.jsx)("div",{className:ev,children:a}),R[38]=ev,R[39]=a,R[40]=o):o=R[40],R[41]!==V.kind||R[42]!==z?(s=C(z,V.kind),R[41]=V.kind,R[42]=z,R[43]=s):s=R[43];let ej=V.origin_label?` \xb7 ${V.origin_label}`:"";R[44]!==s||R[45]!==ej?(n=(0,t.jsxs)("span",{children:[s,ej]}),R[44]=s,R[45]=ej,R[46]=n):n=R[46],R[47]===Symbol.for("react.memo_cache_sentinel")?(N=()=>J(U),_=(0,t.jsx)(g.Glyph,{name:"h_more"}),R[47]=N,R[48]=_):(N=R[47],_=R[48]),R[49]!==z?(T=z("history.action.more","More actions"),R[49]=z,R[50]=T):T=R[50],R[51]!==Y||R[52]!==q||R[53]!==T?(E=(0,t.jsxs)("button",{type:"button",className:"cfBtn","aria-expanded":q,"aria-controls":Y,onClick:N,children:[_,T]}),R[51]=Y,R[52]=q,R[53]=T,R[54]=E):E=R[54],R[55]!==z?(A=z("shell.close","Close"),R[55]=z,R[56]=A):A=R[56],R[57]!==L||R[58]!==A?(G=(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:L,children:A}),R[57]=L,R[58]=A,R[59]=G):G=R[59];let ey=ef&&(0,t.jsxs)("button",{type:"button",className:`cfBtn${"download"===ef?"":" cfPrimary"}`,onClick:()=>"download"===ef?F.download(V):F.openOrigin(V),children:["download"===ef&&(0,t.jsx)(g.Glyph,{name:"h_download"}),O(z,ef)]});R[60]!==E||R[61]!==G||R[62]!==ey?(X=(0,t.jsxs)("div",{className:"ssDlgActions",children:[E,G,ey]}),R[60]=E,R[61]=G,R[62]=ey,R[63]=X):X=R[63],R[64]!==n||R[65]!==X?(d=(0,t.jsxs)("div",{className:"hsPreviewFooter",children:[n,X]}),R[64]=n,R[65]=X,R[66]=d):d=R[66],x=Y,v="hsPreviewDetails",j=!q,R[67]!==z?(y=z("history.action.more","More actions"),R[67]=z,R[68]=y):y=R[68],R[69]!==M||R[70]!==D.length||R[71]!==I||R[72]!==z?(w=D.length>1&&(0,t.jsxs)("div",{className:"hsPreviewNavigation ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:0===M,onClick:()=>I(M-1),children:z("history.preview.prev","Previous")}),(0,t.jsxs)("span",{"aria-live":"polite",children:[M+1," / ",D.length]}),(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:M>=D.length-1,onClick:()=>I(M+1),children:z("history.preview.next","Next")})]}),R[69]=M,R[70]=D.length,R[71]=I,R[72]=z,R[73]=w):w=R[73],R[74]!==z?(Z=z("history.colSource","SOURCE"),R[74]=z,R[75]=Z):Z=R[75],R[76]!==Z?(Q=(0,t.jsx)("dt",{children:Z}),R[76]=Z,R[77]=Q):Q=R[77],R[78]!==V.origin||R[79]!==z?(ee=S(z,V.origin),R[78]=V.origin,R[79]=z,R[80]=ee):ee=R[80];let ew=V.origin_label?` \xb7 ${V.origin_label}`:"";R[81]!==ee||R[82]!==ew?(et=(0,t.jsxs)("dd",{children:[ee,ew]}),R[81]=ee,R[82]=ew,R[83]=et):et=R[83],R[84]!==Q||R[85]!==et?(ea=(0,t.jsxs)("div",{children:[Q,et]}),R[84]=Q,R[85]=et,R[86]=ea):ea=R[86],R[87]!==z?(es=z("history.preview.created","CREATED"),R[87]=z,R[88]=es):es=R[88],R[89]!==es?(en=(0,t.jsx)("dt",{children:es}),R[89]=es,R[90]=en):en=R[90],R[91]!==eb?(el=(0,t.jsx)("dd",{children:eb}
24),R[91]=eb,R[92]=el):el=R[92],R[93]!==en||R[94]!==el?(ei=(0,t.jsxs)("div",{children:[en,el]}),R[93]=en,R[94]=el,R[95]=ei):ei=R[95],R[96]!==V.size_bytes||R[97]!==z?(er=V.size_bytes>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("dt",{children:z("history.preview.size","SIZE")}),(0,t.jsx)("dd",{children:(0,B.fmtSize)(V.size_bytes)})]}),R[96]=V.size_bytes,R[97]=z,R[98]=er):er=R[98],R[99]!==V.revision||R[100]!==V.revisions||R[101]!==V.source||R[102]!==z?(eo="artifact"===V.source&&null!=V.revision&&(0,t.jsxs)("div",{children:[(0,t.jsx)("dt",{children:z("history.preview.revision","REVISION")}),(0,t.jsxs)("dd",{children:[z("history.revisionBadge",{n:V.revision})," · ",z("history.preview.revisions",{count:V.revisions})]})]}),R[99]=V.revision,R[100]=V.revisions,R[101]=V.source,R[102]=z,R[103]=eo):eo=R[103],R[104]!==V.source||R[105]!==z?(ed="file"===V.source?z("history.preview.filename","FILE"):z("history.preview.slug","ID"),R[104]=V.source,R[105]=z,R[106]=ed):ed=R[106],R[107]!==ed?(ec=(0,t.jsx)("dt",{children:ed}),R[107]=ed,R[108]=ec):ec=R[108];let ek="file"===V.source?V.title:V.artifact_slug;R[109]!==ek?(eu=(0,t.jsx)("dd",{children:ek}),R[109]=ek,R[110]=eu):eu=R[110],R[111]!==ec||R[112]!==eu?(em=(0,t.jsxs)("div",{children:[ec,eu]}),R[111]=ec,R[112]=eu,R[113]=em):em=R[113],R[114]!==ea||R[115]!==ei||R[116]!==er||R[117]!==eo||R[118]!==em?(k=(0,t.jsxs)("dl",{children:[ea,ei,er,eo,em]}),R[114]=ea,R[115]=ei,R[116]=er,R[117]=eo,R[118]=em,R[119]=k):k=R[119],p="ssDlgActions",R[120]!==V.is_favorite||R[121]!==z?(eh=e=>(0,t.jsx)("button",{type:"button",className:`cfBtn${e.danger?" cfDanger":""}`,"aria-pressed":e.checked,onClick:e.on,children:"favorite"===e.id&&V.is_favorite?z("history.action.unfavorite","Remove from favorites"):e.label},e.id),R[120]=V.is_favorite,R[121]=z,R[122]=eh):eh=R[122],f=ex.map(eh),R[1]=F,R[2]=Y,R[3]=q,R[4]=H,R[5]=K.language,R[6]=M,R[7]=V,R[8]=D.length,R[9]=L,R[10]=I,R[11]=z,R[12]=l,R[13]=i,R[14]=r,R[15]=o,R[16]=d,R[17]=c,R[18]=u,R[19]=m,R[20]=h,R[21]=p,R[22]=f,R[23]=x,R[24]=v,R[25]=j,R[26]=y,R[27]=w,R[28]=k}else l=R[12],i=R[13],r=R[14],o=R[15],d=R[16],c=R[17],u=R[18],m=R[19],h=R[20],p=R[21],f=R[22],x=R[23],v=R[24],j=R[25],y=R[26],w=R[27],k=R[28];return R[123]!==p||R[124]!==f?(_=(0,t.jsx)("div",{className:p,children:f}),R[123]=p,R[124]=f,R[125]=_):_=R[125],R[126]!==_||R[127]!==x||R[128]!==v||R[129]!==j||R[130]!==y||R[131]!==w||R[132]!==k?(T=(0,t.jsxs)("section",{id:x,className:v,hidden:j,"aria-label":y,children:[w,k,_]}),R[126]=_,R[127]=x,R[128]=v,R[129]=j,R[130]=y,R[131]=w,R[132]=k,R[133]=T):T=R[133],R[134]!==i||R[135]!==r||R[136]!==o||R[137]!==d||R[138]!==T?(E=(0,t.jsxs)("div",{className:i,onKeyDown:r,children:[o,d,T]}),R[134]=i,R[135]=r,R[136]=o,R[137]=d,R[138]=T,R[139]=E):E=R[139],R[140]!==l||R[141]!==c||R[142]!==u||R[143]!==m||R[144]!==h||R[145]!==E?(A=(0,t.jsx)(l,{title:c,onClose:u,fallbackFocus:m,wide:h,children:E}),R[140]=l,R[141]=c,R[142]=u,R[143]=m,R[144]=h,R[145]=E,R[146]=A):A=R[146],A}function U(e){return!e}function G(){let e=document.title;return()=>{document.title=e}}function W(e){let a,s=(0,N.c)(19),{item:n}=e;if("artifact"===n.source){let e;if("image"===n.kind&&n.url){let e;return s[0]!==n.title||s[1]!==n.url?(e=(0,t.jsx)("img",{className:"hsLbMedia",src:n.url,alt:n.title}),s[0]=n.title,s[1]=n.url,s[2]=e):e=s[2],e}if("video"===n.kind&&n.url){let e;return s[3]!==n.url?(e=(0,t.jsx)("video",{className:"hsLbMedia",src:n.url,controls:!0,preload:"metadata"}),s[3]=n.url,s[4]=e):e=s[4],e}if(n.thread_id&&n.artifact_slug&&H.has(n.kind)){let e,a=`/api/v1/general-chat/threads/${encodeURIComponent(n.thread_id)}/artifacts/${encodeURIComponent(n.artifact_slug)}/payload`;return s[5]!==a?(e=(0,t.jsx)(L.ArtifactShareViewer,{endpoint:a}),s[5]=a,s[6]=e):e=s[6],e}return s[7]!==n?(e=(0,t.jsx)(K,{item:n}),s[7]=n,s[8]=e):e=s[8],e}let l=n.mime_type??"",i=null!=n.room_id&&null!=n.file_id?`${o.BASE}/api/v1/data-rooms/${n.room_id}/files/${n.file_id}/preview`:null;if("application/pdf"===l&&i){let e;return s[9]!==i||s[10]!==n.title?(e=(0,t.jsx)("iframe",{className:"hsLbFrame",src:i,title:n.title}),s[9]=i,s[10]=n.title,s[11]=e):e=s[11],e}if(l.startsWith("image/")&&(n.url||i)){let e,a=n.url??i??"";return s[12]!==n.title||s[13]!==a?(e=(0,t.jsx)("img",{className:"hsLbMedia",src:a,alt:n.title}),s[12]=n.title,s[13]=a,s[14]=e):e=s[14],e}if(l.startsWith("video/")&&i){let e;return s[15]!==i?(e=(0,t.jsx)("video",{className:"hsLbMedia",src:i,controls:!0,preload:"metadata"}),s[15]=i,s[16]=e):e=s[16],e}return s[17]!==n?(a=(0,t.jsx)(K,{item:n}),s[17]=n,s[18]=a):a=s[18],a}function K(e){let a,s,l,i,r,o=(0,N.c)(12),{item:d}=e,{t:c}=(0,n.useTranslation)("paletteOs");return o[0]!==d?(a=(0,t.jsx)("div",{className:"hsLbPlate",children:(0,t.jsx)(T,{item:d})}),o[0]=d,o[1]=a):a=o[1],o[2]!==c?(s=c("history.preview.unavailable","No preview for this output"),o[2]=c,o[3]=s):s=o[3],o[4]!==s?(l=(0,t.jsx)("span",{className:"hsEmptyTag",children:s}),o[4]=s,o[5]=l):l=o[5],o[6]!==d?(i="file"===d.source&&(0,t.jsx)(F.AttachmentTile,{name:d.title,mime:d.mime_type??"",size:d.size_bytes||void 0,href:m(d)??void 0}),o[6]=d,o[7]=i):i=o[7],o[8]!==a||o[9]!==l||o[10]!==i?(r=(0,t.jsxs)("div",{className:"hsLbNone",children:[a,l,i]}),o[8]=a,o[9]=l,o[10]=i,o[11]=r):r=o[11],r}let V=["grid","list"],Y={grid:"h_grid",list:"h_list"},q={newest:["history.sortNewest","NEWEST"],oldest:["history.sortOldest","OLDEST"],name:["history.sortName","NAME"],largest:["history.sortLargest","LARGEST"]};e.s(["HistoryView",0,function(){let{t:e}=(0,n.useTranslation)("paletteOs"),b=(0,k.useViewContext)(),{openConfirm:N,openSession:S}=b,_=(0,s.useRouter)(),{copy:T}=(0,i.useCopyToClipboard)(),[E,A]=(0,a.useState)(""),[I,O]=(0,a.useState)("images"),[L,F]=(0,a.useState)({...c,kinds:x.images}),$=(0,a.useCallback)(e=>{O(e),F(t=>({...t,kinds:x[e]}))},[]);(0,a.useEffect)(()=>{let e=window.setTimeout(()=>F(e=>e.q===E?e:{...e,q:E}),250);return()=>window.clearTimeout(e)},[E]);
24let[B,H]=(0,a.useState)(y);(0,a.useEffect)(()=>{H(function(){try{let e=localStorage.getItem(w);if(!e)return y;let t=JSON.parse(e);return{view:v.includes(t.view)?t.view:y.view,density:j.includes(t.density)?t.density:y.density,group:"boolean"==typeof t.group?t.group:y.group}}catch{return y}}())},[]);let U=(0,a.useCallback)((e,t)=>{H(a=>{let s={...a,[e]:t};try{localStorage.setItem(w,JSON.stringify(s))}catch{}return s})},[]),{items:G,loading:W,loadingMore:K,error:J,hasMore:X,loadMore:Z,refetch:Q,toggleFavorite:ee,remove:et}=function(e,t){let[s,n]=(0,a.useState)([]),[i,r]=(0,a.useState)(0),[d,c]=(0,a.useState)(!0),[m,h]=(0,a.useState)(!1),[p,g]=(0,a.useState)(!1),f=(0,a.useRef)(0),x=(0,a.useCallback)(async t=>{let a=++f.current;t?h(!0):c(!0);try{let s=await (0,o.apiFetch)(`/api/v1/history?${function(e,t){let a=new URLSearchParams;for(let t of(e.q.trim()&&a.set("q",e.q.trim()),e.kinds))a.append("kind",t);for(let t of e.origins)a.append("origin",t);return e.from&&a.set("from",e.from),e.to&&a.set("to",e.to),e.favorite&&a.set("favorite","1"),"newest"!==e.sort&&a.set("sort",e.sort),a.set("limit",String(60)),t&&a.set("offset",String(t)),a.toString()}(e,t)}`),l=await s.json();if(a!==f.current)return;n(e=>t?[...e,...l.items]:l.items),r(l.total),g(!1)}catch{if(a!==f.current)return;g(!0),t||(n([]),r(0))}finally{a===f.current&&(c(!1),h(!1))}},[e]);(0,a.useEffect)(()=>{x(0)},[x]);let b=(0,a.useCallback)(()=>{x(s.length)},[x,s.length]),v=(0,a.useCallback)(()=>{x(0)},[x]),j=(0,a.useCallback)(async a=>{let s=!a.is_favorite,i=e=>n(t=>t.map(t=>t.id===a.id?{...t,is_favorite:e}:t));!s&&e.favorite?(n(e=>e.filter(e=>e.id!==a.id)),r(e=>Math.max(0,e-1))):i(s);try{"artifact"===a.source?await (0,o.apiFetch)(`/api/v1/history/artifacts/${u(a)}/favorite`,{method:s?"PUT":"DELETE"}):s?await (0,o.apiFetch)(`/api/v1/data-rooms/${a.room_id}/favorites`,{method:"POST",body:JSON.stringify({item_type:"file",item_id:a.file_id})}):await (0,o.apiFetch)(`/api/v1/data-rooms/${a.room_id}/favorites?item_type=file&item_id=${a.file_id}`,{method:"DELETE"})}catch{!s&&e.favorite?x(0):i(!s),l.toast.error(t.favoriteFailed)}},[e.favorite,x,t.favoriteFailed]),y=(0,a.useCallback)(async e=>{n(t=>t.filter(t=>t.id!==e.id)),r(e=>Math.max(0,e-1));try{return"artifact"===e.source?await (0,o.apiFetch)(`/api/v1/history/artifacts/${u(e)}`,{method:"DELETE"}):await (0,o.apiFetch)(`/api/v1/data-rooms/${e.room_id}/files/${e.file_id}`,{method:"DELETE"}),!0}catch{return l.toast.error(t.deleteFailed),x(0),!1}},[x,t.deleteFailed]);return{items:s,total:i,loading:d,loadingMore:m,error:p,hasMore:s.length<i,loadMore:b,refetch:v,toggleFavorite:j,remove:y}}(L,(0,a.useMemo)(()=>({favoriteFailed:e("history.toast.favoriteFailed","Couldn't update favorite"),deleteFailed:e("history.toast.deleteFailed","Couldn't delete")}),[e])),[ea,es]=(0,a.useState)(null),[en,el]=(0,a.useState)(null),[ei,er]=(0,a.useState)(null),eo=(0,a.useCallback)(()=>es(null),[]),ed=(0,a.useRef)(null),ec=(0,a.useCallback)(e=>{if("session"===e.origin&&e.thread_id)return void(b.urlSync?S({threadId:e.thread_id}):_.push(`/general-chat/${e.thread_id}`));if("messenger"===e.origin)return void(e.channel_id?b.urlSync?(b.setTalkSeed(e.channel_id),b.setView("talk")):_.push(`/talk/${e.channel_id}`):e.url&&window.open(e.url,"_blank","noopener,noreferrer"));if(null!=e.room_id&&b.urlSync){b.setDriveRoomSeed(e.room_id),b.setView("memory");return}e.url&&window.open(e.url,"_blank","noopener,noreferrer")},[b,S,_]),eu=(0,a.useMemo)(()=>({preview:e=>el(G.findIndex(t=>t.id===e.id)),openOrigin:ec,download:e=>(function(e){let t=m(e);if(!t)return;let a=document.createElement("a");a.href=t,a.download=e.title,document.body.appendChild(a),a.click(),document.body.removeChild(a)})(e),share:t=>{"session"===t.origin&&t.thread_id&&t.artifact_slug?er({threadId:t.thread_id,slug:t.artifact_slug,revision:t.revision??1}):t.url&&(T(t.url),l.toast.success(e("history.toast.linkCopied","Asset link copied")))},toggleFavorite:e=>{ee(e)},remove:t=>{el(null);let a="file"===t.source;N({danger:!0,title:a?e("history.confirm.deleteFileTitle","Move file to trash?"):e("history.confirm.deleteArtifactTitle","Delete from History?"),desc:a?e("history.confirm.deleteFileDesc",'"{{name}}" moves to Drive Trash.',{name:t.title}):e("history.confirm.deleteArtifactDesc",'"{{name}}" leaves History. The chat keeps its copy; any share link is revoked.',{name:t.title}),confirmLabel:e("history.confirm.deleteIt","Delete"),onConfirm:async()=>{let a=await et(t);return a&&l.toast.success(e("history.toast.deleted","Removed from History")),a}})},menu:(t,a)=>es({x:a.x,y:a.y,head:C(e,t.kind),sections:P(t,ed.current,e)})}),[G,ec,T,e,ee,N,et]);ed.current=eu;let em=(0,a.useRef)(null),eh=(0,a.useRef)(null);return(0,a.useEffect)(()=>{let e=eh.current;if(!e||!X||"u"<typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{!e.some(e=>e.isIntersecting)||W||K||Z()},{root:em.current,rootMargin:"480px 0px"});return t.observe(e),()=>t.disconnect()},[X,W,K,Z]),(0,t.jsx)(p.TipHost,{children:(0,t.jsxs)("div",{className:"viewPane hsView",children:[(0,t.jsxs)("div",{className:"lpHead",children:[(0,t.jsxs)("div",{className:"lpTitleRow",children:[(0,t.jsx)("span",{className:"lpTitle",children:e("history.title","History")}),(0,t.jsxs)("div",{className:"hsTools",children:[(0,t.jsx)(p.Tip,{label:e("history.sortReg","Sort by"),children:(0,t.jsx)("button",{type:"button",className:`hsFnCell hsSortCell${"newest"!==L.sort?" set":""}`,"aria-haspopup":"menu","aria-label":e("history.sortReg","Sort by"),onClick:t=>{var a,s;let n;return a=e("history.sortReg","Sort by"),s=[d.map(t=>({id:t,label:e(q[t][0],q[t][1]),checked:L.sort===t,on:()=>F(e=>({...e,sort:t}))}))],void es({x:(n=t.currentTarget.getBoundingClientRect()).left,y:n.bottom+4,head:a,sections:s})},children:(0,t.jsx)(g.Glyph,{name:"h_sliders"})})}),(0,t.jsx)("span",{className:"hsToolDivider","aria-hidden":!0}),(0,t.jsx)("div",{className:"hsViewCtl",role:"group",children:V.map(a=>(0,t.jsx)(p.Tip,{label:e(`history.view${a[0].toUpperCase()}${a.slice(1)}`,a),children:(0,t.jsx)("button",{type:"button",className:`hsFnCell hsFnView${B.view===a?" on":""}`,"aria-pressed":B.view===a,"aria-label":e(`history.view${a[0].toUpperCase()}${a.slice(1)}`,a),onClick:()=>U("view",a),children:(0,t.jsx)(g.Glyph,{name:Y[a]})})},a))}),(0,t.jsxs)("div",{className:"lpSearchBox poSearch",role:"search",children:[(0,t.jsx)(g.Glyph,{name:"h_search"}),(0,t.jsx)("input",{type:"search",value:E,onChange:e=>A(e.target.value),onKeyDown:e=>{"Escape"===e.key&&E&&(e.preventDefault(),A(""))},placeholder:e("history.searchPlaceholder","Search history"),"aria-label":e("history.searchPlaceholder","Search history")})]})]})]}),(0,t.jsx)("div",{className:"hsChips",role:"tablist","aria-label":e("history.colKind","TYPE"),onKeyDown:e=>
24{if(!["ArrowLeft","ArrowRight","Home","End"].includes(e.key))return;e.preventDefault();let t=f.indexOf(I),a="Home"===e.key?0:"End"===e.key?f.length-1:(t+("ArrowRight"===e.key?1:-1)+f.length)%f.length;$(f[a]);let s=e.currentTarget.children[a];s?.focus()},children:f.map(a=>(0,t.jsx)("button",{type:"button",role:"tab",className:`lpChip${I===a?" on":""}`,"aria-selected":I===a,tabIndex:I===a?0:-1,onClick:()=>$(a),children:e(`history.family.${a}`,a)},a))})]}),(0,t.jsxs)("div",{className:"lpScroll hsScroll",ref:em,tabIndex:-1,children:[W?(0,t.jsx)("div",{className:"hsGrid","aria-busy":"true","aria-label":e("history.loading","Loading outputsâ¦"),children:Array.from({length:8},(e,a)=>(0,t.jsx)(M,{},a))}):0===G.length?(0,t.jsxs)("div",{className:"hsEmpty",children:[(0,t.jsx)(g.Glyph,{name:L.q?"h_search":"h_folder"}),(0,t.jsx)("h2",{children:J?e("history.errorTag","Couldn't load"):L.q?e("history.empty.searchTitle","No results"):e("history.empty.kindTitle",{defaultValue:"No {{kind}} items yet",kind:e(`history.family.${I}`,I)})}),(0,t.jsx)("p",{children:J?e("history.errorDesc","History didn't answer. Check the connection and retry."):L.q?e("history.empty.searchDesc","Try another name or keyword."):e("history.empty.kindDesc","Nothing is stored under this category yet.")}),J?(0,t.jsx)("button",{type:"button",className:"hsEmptyBtn",onClick:Q,children:e("history.action.retry","Retry")}):L.q?(0,t.jsx)("button",{type:"button",className:"hsEmptyBtn",onClick:()=>{A(""),F({...c,kinds:x[I]})},children:e("history.empty.clearSearch","Clear search")}):null]}):"list"===B.view?(0,t.jsx)("div",{className:"hsList",children:G.map(e=>(0,t.jsx)(D,{item:e,actions:eu},e.id))}):(0,t.jsx)("div",{className:"hsGrid",children:G.map(e=>(0,t.jsx)(R,{item:e,actions:eu},e.id))}),!W&&G.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{ref:eh,className:"hsSentinel","aria-hidden":!0}),X&&(0,t.jsx)("div",{className:"hsMore",children:(0,t.jsx)("button",{type:"button",className:"hsMoreBtn",disabled:K,onClick:Z,children:e("history.loadMore","Load more")})})]}),!W&&(0,t.jsx)("p",{className:"hsSourceNote",children:e("history.sourceNote","Results from chats, Messenger and Drive · synced with this workspace")})]}),ea&&(0,t.jsx)(h.PoContextMenu,{ctx:ea,onClose:eo}),null!=en&&G[en]&&(0,t.jsx)(z,{fallbackFocus:em,items:G,index:en,onIndex:el,onClose:()=>el(null),actions:eu}),(0,t.jsx)(r.ShareArtifactDialog,{paletteOs:!0,fallbackFocus:em,open:null!==ei,onOpenChange:e=>{e||er(null)},threadId:ei?.threadId??"",target:ei?{artifactSlug:ei.slug,revision:ei.revision}:null})]})})}],827995)},971962,441276,891936,e=>{"use strict";var t=e.i(843476),a=e.i(500932),s=e.i(271645),n=e.i(39891),l=e.i(301575),i=e.i(72039),r=e.i(702102),o=e.i(587583),d=e.i(630233),c=e.i(27871),u=e.i(550857),m=e.i(448486),h=e.i(293437),p=e.i(851465),g=e.i(253942),f=e.i(422187),x=e.i(710596),b=e.i(829045),v=e.i(51790),j=e.i(975157),y=e.i(988985),w=e.i(522016),k=e.i(817389),N=e.i(750562),C=e.i(266378),S=e.i(813702),_=e.i(11518),T=e.i(243578),E=e.i(552075),A=e.i(150975),R=e.i(161652),D=e.i(231880),M=e.i(294909),I=e.i(297634),O=e.i(48292),P=e.i(755146),L=e.i(776639);e.i(785269);var F=e.i(322831);function $(e){if(!e)return"never";let t=Math.round((Date.now()-new Date(e).getTime())/6e4);if(t<1)return"just now";if(t<60)return`${t}m ago`;let a=Math.round(t/60);return a<24?`${a}h ago`:`${Math.round(a/24)}d ago`}let B={running:{label:"running",cls:"bg-blue-500/15 text-blue-600"},waiting_decision:{label:"needs you",cls:"bg-amber-500/15 text-amber-600"},completed:{label:"completed",cls:"bg-emerald-500/15 text-emerald-600"},failed:{label:"failed",cls:"bg-destructive/15 text-destructive"},cancelled:{label:"cancelled",cls:"bg-muted text-muted-foreground"}};function H(e){let n,l,r,o,u,m,h,f,x,b,v,y,w,k,C,_,T,E,A,D,M,I,O,H,z,U,G,W,K,V,Y,q,J,X,Z,Q,ee,et,ea,es=(0,a.c)(90),{loop:en,onOpen:el,onDelete:ei}=e,{t:er}=(0,F.useTranslation)(),[eo,ed]=(0,s.useState)(!1),ec=`Open ${en.title}`;es[0]===Symbol.for("react.memo_cache_sentinel")?(n=(0,t.jsx)("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-sky-500 to-cyan-600 text-white",children:(0,t.jsx)(i.ArrowsClockwise,{size:18,weight:"fill","aria-hidden":"true"})}),es[0]=n):n=es[0],es[1]!==en.title?(l=(0,t.jsx)("span",{className:"block truncate text-[14px] font-semibold text-foreground",children:en.title}),es[1]=en.title,es[2]=l):l=es[2];let eu=en.latest_run_status?`last run ${B[en.latest_run_status].label}`:"not run yet";es[3]!==eu?(r=(0,t.jsx)("span",{className:"block truncate text-[12px] text-muted-foreground",children:eu}),es[3]=eu,es[4]=r):r=es[4],es[5]!==l||es[6]!==r?(o=(0,t.jsxs)("span",{className:"flex items-start gap-3",children:[n,(0,t.jsxs)("span",{className:"min-w-0 flex-1",children:[l,r]})]}),es[5]=l,es[6]=r,es[7]=o):o=es[7];let em="active"===en.status?"bg-emerald-500/15 text-emerald-600":"draft"===en.status?"bg-amber-500/15 text-amber-600":"bg-muted text-muted-foreground";es[8]!==em?(u=(0,j.cn)("rounded-full px-2 py-0.5 font-medium",em),es[8]=em,es[9]=u):u=es[9],es[10]!==en.status||es[11]!==u?(m=(0,t.jsx)("span",{className:u,children:en.status}),es[10]=en.status,es[11]=u,es[12]=m):m=es[12],es[13]!==en.pending_decisions?(h=en.pending_decisions>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-500/15 px-2 py-0.5 font-medium text-amber-600",children:[(0,t.jsx)(g.Question,{size:12,weight:"fill","aria-hidden":"true"}),en.pending_decisions," waiting on you"]}),es[13]=en.pending_decisions,es[14]=h):h=es[14],es[15]!==en.missing_connections?(f=en.missing_connections>0&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full bg-orange-500/15 px-2 py-0.5 font-medium text-orange-600",children:[(0,t.jsx)(p.Plug,{size:12,"aria-hidden":"true"}),en.missing_connections," to connect"]}),es[15]=en.missing_connections,es[16]=f):f=es[16],es[17]===Symbol.for("react.memo_cache_sentinel")?(x=(0,t.jsx)(c.Lightning,{size:12,"aria-hidden":"true"}),es[17]=x):x=es[17],es[18]!==en.last_run_at?(b=$(en.last_run_at),es[18]=en.last_run_at,es[19]=b):b=es[19],es[20]!==b?(v=(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[x,b]}),es[20]=b,es[21]=v):v=es[21],es[22]!==en.schedule_cron?(y=en.schedule_cron&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,t.jsx)(d.
24Clock,{size:12,"aria-hidden":"true"}),"scheduled"]}),es[22]=en.schedule_cron,es[23]=y):y=es[23],es[24]!==h||es[25]!==f||es[26]!==v||es[27]!==y||es[28]!==m?(w=(0,t.jsxs)("span",{className:"mt-3 flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[m,h,f,v,y]}),es[24]=h,es[25]=f,es[26]=v,es[27]=y,es[28]=m,es[29]=w):w=es[29],es[30]!==el||es[31]!==ec||es[32]!==w||es[33]!==o?(k=(0,t.jsxs)("button",{type:"button",onClick:el,className:"block w-full rounded-xl p-4 pr-12 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","aria-label":ec,children:[o,w]}),es[30]=el,es[31]=ec,es[32]=w,es[33]=o,es[34]=k):k=es[34];let eh=`Actions for ${en.title}`;return es[35]===Symbol.for("react.memo_cache_sentinel")?(C=(0,t.jsx)(N.DotsThree,{size:18,weight:"bold","aria-hidden":"true"}),es[35]=C):C=es[35],es[36]!==eh?(_=(0,t.jsx)(P.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"absolute right-2 top-2 z-10 flex size-9 items-center justify-center rounded-md text-muted-foreground opacity-100 outline-none hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100","aria-label":eh,children:C})}),es[36]=eh,es[37]=_):_=es[37],es[38]===Symbol.for("react.memo_cache_sentinel")?(T=(0,t.jsx)(S.PencilSimple,{size:14,"aria-hidden":"true"}),es[38]=T):T=es[38],es[39]!==er?(E=er("notifications.open"),es[39]=er,es[40]=E):E=es[40],es[41]!==el||es[42]!==E?(A=(0,t.jsxs)(P.DropdownMenuItem,{onSelect:el,children:[T,E]}),es[41]=el,es[42]=E,es[43]=A):A=es[43],es[44]===Symbol.for("react.memo_cache_sentinel")?(D=()=>ed(!0),M=(0,t.jsx)(R.Trash,{size:14,"aria-hidden":"true"}),es[44]=D,es[45]=M):(D=es[44],M=es[45]),es[46]!==er?(I=er("actions.delete"),es[46]=er,es[47]=I):I=es[47],es[48]!==I?(O=(0,t.jsxs)(P.DropdownMenuItem,{variant:"destructive",onSelect:D,children:[M,I]}),es[48]=I,es[49]=O):O=es[49],es[50]!==A||es[51]!==O?(H=(0,t.jsxs)(P.DropdownMenuContent,{align:"end",className:"w-32",children:[A,O]}),es[50]=A,es[51]=O,es[52]=H):H=es[52],es[53]!==_||es[54]!==H?(z=(0,t.jsxs)(P.DropdownMenu,{children:[_,H]}),es[53]=_,es[54]=H,es[55]=z):z=es[55],es[56]!==er?(U=er("messages:builderUi.loopComponents.deleteLoop"),es[56]=er,es[57]=U):U=es[57],es[58]!==U?(G=(0,t.jsx)(L.DialogTitle,{children:U}),es[58]=U,es[59]=G):G=es[59],es[60]!==en.title?(W=(0,t.jsxs)(L.DialogDescription,{children:["â",en.title,"â and its run history will be permanently deleted."]}),es[60]=en.title,es[61]=W):W=es[61],es[62]!==G||es[63]!==W?(K=(0,t.jsxs)(L.DialogHeader,{children:[G,W]}),es[62]=G,es[63]=W,es[64]=K):K=es[64],es[65]===Symbol.for("react.memo_cache_sentinel")?(V=()=>ed(!1),es[65]=V):V=es[65],es[66]!==er?(Y=er("actions.cancel"),es[66]=er,es[67]=Y):Y=es[67],es[68]!==Y?(q=(0,t.jsx)("button",{type:"button",onClick:V,className:"rounded-md border border-border px-3 py-2 text-sm font-medium hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:Y}),es[68]=Y,es[69]=q):q=es[69],es[70]!==ei?(J=()=>{ed(!1),ei()},es[70]=ei,es[71]=J):J=es[71],es[72]!==er?(X=er("messages:builderUi.loopComponents.deleteLoop2"),es[72]=er,es[73]=X):X=es[73],es[74]!==J||es[75]!==X?(Z=(0,t.jsx)("button",{type:"button",onClick:J,className:"rounded-md bg-destructive px-3 py-2 text-sm font-medium text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",children:X}),es[74]=J,es[75]=X,es[76]=Z):Z=es[76],es[77]!==q||es[78]!==Z?(Q=(0,t.jsxs)(L.DialogFooter,{children:[q,Z]}),es[77]=q,es[78]=Z,es[79]=Q):Q=es[79],es[80]!==K||es[81]!==Q?(ee=(0,t.jsxs)(L.DialogContent,{className:"sm:max-w-md",children:[K,Q]}),es[80]=K,es[81]=Q,es[82]=ee):ee=es[82],es[83]!==eo||es[84]!==ee?(et=(0,t.jsx)(L.Dialog,{open:eo,onOpenChange:ed,children:ee}),es[83]=eo,es[84]=ee,es[85]=et):et=es[85],es[86]!==k||es[87]!==z||es[88]!==et?(ea=(0,t.jsxs)("div",{className:"group relative rounded-xl border border-border bg-background transition-shadow hover:shadow-md focus-within:shadow-md",children:[k,z,et]}),es[86]=k,es[87]=z,es[88]=et,es[89]=ea):ea=es[89],ea}let z=/\b(send|approve|confirm|yes|go\s*ahead|looks?\s*good|ship|sounds good)\b/i;function U(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,y,w=(0,a.c)(57),{draft:k,editable:N,onChange:S}=e,{t:_}=(0,F.useTranslation)();if(!N){let e,a,s,n,l;w[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,t.jsx)(C.EnvelopeSimple,{size:13}),w[0]=e):e=w[0];let i=k.to||"â",r=k.cc?` \xb7 Cc ${k.cc}`:"";w[1]!==i||w[2]!==r?(a=(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[e,(0,t.jsxs)("span",{className:"truncate",children:["To ",i,r]})]}),w[1]=i,w[2]=r,w[3]=a):a=w[3];let o=k.subject||"(no subject)";return w[4]!==o?(s=(0,t.jsx)("p",{className:"mt-1 truncate text-[12.5px] font-semibold text-foreground",children:o}),w[4]=o,w[5]=s):s=w[5],w[6]!==k.body?(n=(0,t.jsx)("p",{className:"mt-1 max-h-40 overflow-y-auto whitespace-pre-wrap text-[12px] leading-relaxed text-muted-foreground",children:k.body}
24),w[6]=k.body,w[7]=n):n=w[7],w[8]!==a||w[9]!==s||w[10]!==n?(l=(0,t.jsxs)("div",{className:"rounded-lg border border-border bg-background/70 p-2.5",children:[a,s,n]}),w[8]=a,w[9]=s,w[10]=n,w[11]=l):l=w[11],l}return w[12]===Symbol.for("react.memo_cache_sentinel")?(s=(0,t.jsx)(C.EnvelopeSimple,{size:13}),w[12]=s):s=w[12],w[13]!==_?(n=_("messages:builderUi.loopComponents.draft"),w[13]=_,w[14]=n):n=w[14],w[15]!==n?(l=(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[s," ",n]}),w[15]=n,w[16]=l):l=w[16],w[17]!==_?(i=_("messages:builderUi.loopComponents.to"),w[17]=_,w[18]=i):i=w[18],w[19]!==i?(r=(0,t.jsx)("span",{className:"w-12 shrink-0",children:i}),w[19]=i,w[20]=r):r=w[20],w[21]!==S?(o=e=>S?.({to:e.target.value}),w[21]=S,w[22]=o):o=w[22],w[23]!==k.to||w[24]!==o?(d=(0,t.jsx)("input",{className:"w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-400/60",value:k.to,onChange:o}),w[23]=k.to,w[24]=o,w[25]=d):d=w[25],w[26]!==r||w[27]!==d?(c=(0,t.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[r,d]}),w[26]=r,w[27]=d,w[28]=c):c=w[28],w[29]!==k.cc||w[30]!==S||w[31]!==_?(u=(k.cc||""===k.cc)&&(0,t.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{className:"w-12 shrink-0",children:_("messages:builderUi.loopComponents.cc")}),(0,t.jsx)("input",{className:"w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-400/60",value:k.cc??"",onChange:e=>S?.({cc:e.target.value})})]}),w[29]=k.cc,w[30]=S,w[31]=_,w[32]=u):u=w[32],w[33]!==_?(m=_("messages:builderUi.loopComponents.subject"),w[33]=_,w[34]=m):m=w[34],w[35]!==m?(h=(0,t.jsx)("span",{className:"w-12 shrink-0",children:m}),w[35]=m,w[36]=h):h=w[36],w[37]!==S?(p=e=>S?.({subject:e.target.value}),w[37]=S,w[38]=p):p=w[38],w[39]!==k.subject||w[40]!==p?(g=(0,t.jsx)("input",{className:"w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-400/60",value:k.subject,onChange:p}),w[39]=k.subject,w[40]=p,w[41]=g):g=w[41],w[42]!==h||w[43]!==g?(f=(0,t.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[h,g]}),w[42]=h,w[43]=g,w[44]=f):f=w[44],w[45]===Symbol.for("react.memo_cache_sentinel")?(x=(0,j.cn)("w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-400/60","min-h-32 resize-y leading-relaxed"),w[45]=x):x=w[45],w[46]!==S?(b=e=>S?.({body:e.target.value}),w[46]=S,w[47]=b):b=w[47],w[48]!==k.body||w[49]!==b?(v=(0,t.jsx)("textarea",{className:x,value:k.body,onChange:b}),w[48]=k.body,w[49]=b,w[50]=v):v=w[50],w[51]!==f||w[52]!==v||w[53]!==l||w[54]!==c||w[55]!==u?(y=(0,t.jsxs)("div",{className:"space-y-1.5 rounded-lg border border-border bg-background p-2.5",children:[l,c,u,f,v]}),w[51]=f,w[52]=v,w[53]=l,w[54]=c,w[55]=u,w[56]=y):y=w[56],y}function G({decision:e,highlighted:a,onAnswer:n,onUpdateDraft:l}){let{t:i}
24=(0,F.useTranslation)(),[r,d]=(0,s.useState)(""),[c,u]=(0,s.useState)(!1),[m,h]=(0,s.useState)(null),p="pending"===e.status,f=(0,s.useMemo)(()=>e.preview?.items??[],[e.preview]),[x,b]=(0,s.useState)(()=>Object.fromEntries((e.preview?.items??[]).map(e=>[e.draft_id,{...e}]))),v=(0,s.useMemo)(()=>Object.fromEntries(f.map(e=>[e.draft_id,JSON.stringify(e)])),[f]),y=async()=>{if(l)for(let e of f){let t=x[e.draft_id];t&&JSON.stringify(t)!==v[e.draft_id]&&await l(e.draft_id,{to:t.to,cc:t.cc,subject:t.subject,body:t.body})}},w=async(e,t=!1)=>{if(!c){u(!0),h(null);try{t&&await y(),await n(e)}catch(e){h(e instanceof Error?e.message:i("messages:builderUi.loopComponents.answerFailed","Failed to answer"))}finally{u(!1)}}};return(0,t.jsxs)("div",{className:(0,j.cn)("rounded-xl border p-4",p?"border-amber-400/50 bg-amber-500/[0.06]":"border-border bg-muted/20",a&&p&&"ring-2 ring-amber-400/60"),children:[(0,t.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,t.jsx)("span",{className:(0,j.cn)("mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-lg",p?"bg-amber-500/20 text-amber-600":"bg-muted text-muted-foreground"),children:(0,t.jsx)(g.Question,{size:16,weight:"fill"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("p",{className:"text-[13.5px] font-semibold text-foreground",children:e.question}),e.context&&(0,t.jsx)("p",{className:"mt-1 text-[12px] leading-relaxed text-muted-foreground",children:e.context}),!p&&(0,t.jsx)("p",{className:"mt-2 text-[12px] text-muted-foreground",children:"answered"===e.status?(0,t.jsxs)(t.Fragment,{children:[i("messages:builderUi.loopComponents.answered")," ",(0,t.jsx)("span",{className:"font-medium text-foreground",children:e.answered_option||e.answer})]}):"expired"===e.status?i("messages:builderUi.loopComponents.expiredUnanswered","Expired unanswered"):i("status.cancelled")})]}),p&&(0,t.jsxs)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:["expires ",$(e.expires_at).replace("ago","").trim()&&new Date(e.expires_at).toLocaleDateString()]})]}),f.length>0&&(0,t.jsx)("div",{className:"mt-3 space-y-2",children:f.map(e=>(0,t.jsx)(U,{draft:p?x[e.draft_id]??e:e,editable:p,onChange:t=>{let a;return a=e.draft_id,b(e=>({...e,[a]:{...e[a],...t}}))}},e.draft_id))}),p&&(0,t.jsxs)("div",{className:"mt-3 space-y-2",children:[(e.options??[]).length>0&&(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:(e.options??[]).map(e=>{let a=z.test(`${e.id} ${e.label}`);return(0,t.jsx)("button",{onClick:()=>w({option_id:e.id,answer:r.trim()||void 0},a),disabled:c,title:e.description??void 0,className:"rounded-lg border border-amber-400/50 bg-background px-3 py-1.5 text-[12.5px] font-medium text-foreground hover:bg-amber-500/10 disabled:opacity-50",children:e.label},e.id)})}),e.allow_free_text&&(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("input",{value:r,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key&&r.trim()&&w({answer:r.trim()})},disabled:c,placeholder:i("messages:builderUi.loopComponents.typeAnswer"),className:"flex-1 rounded-lg border border-input bg-background px-3 py-1.5 text-[12.5px] placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-400/60 disabled:opacity-50"}),(0,t.jsx)("button",{onClick:()=>w({answer:r.trim()}),disabled:c||!r.trim(),className:"rounded-lg bg-primary px-3 py-1.5 text-[12.5px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:c?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):i("componentsUi.chatActionCards.send")})]}),m&&(0,t.jsx)("p",{className:"text-[12px] text-destructive",children:m})]})]})}function W({approval:e,onApprove:a,onDeny:n,onEdit:l,onRevise:i}){let{t:r}=(0,F.useTranslation)(),d=e.preview,c=d?.kind==="email",[u,m]=(0,s.useState)("view"),[h,p]=(0,s.use
24State)(!1),[g,f]=(0,s.useState)(null),[x,b]=(0,s.useState)({to:"",cc:"",subject:"",body:""}),[v,y]=(0,s.useState)(""),w=async e=>{if(!h){p(!0),f(null);try{await e()}catch(e){f(e instanceof Error?e.message:r("messages:builderUi.loopComponents.actionFailed","Action failed"))}finally{p(!1)}}},k=c&&"draft"===d.action?r("messages:builderUi.loopComponents.approveGmailDraft","Approve â Gmail draft"):"Approve & Send",N="w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-400/60",C="rounded-lg px-3 py-1.5 text-[12.5px] font-medium disabled:opacity-50";return(0,t.jsxs)("div",{className:"rounded-xl border border-amber-400/50 bg-amber-500/[0.06] p-3",children:[e.loop_title&&(0,t.jsx)("p",{className:"mb-1.5 truncate text-[11px] font-medium text-muted-foreground",children:e.loop_title}),"edit"===u&&c?(0,t.jsxs)("div",{className:"space-y-1.5 rounded-lg border border-border bg-background p-2.5",children:[(0,t.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{className:"w-12 shrink-0",children:r("messages:builderUi.loopComponents.to")}),(0,t.jsx)("input",{className:N,value:x.to,onChange:e=>b(t=>({...t,to:e.target.value}))})]}),(0,t.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{className:"w-12 shrink-0",children:r("messages:builderUi.loopComponents.cc")}),(0,t.jsx)("input",{className:N,value:x.cc,onChange:e=>b(t=>({...t,cc:e.target.value}))})]}),(0,t.jsxs)("label",{className:"flex items-center gap-2 text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{className:"w-12 shrink-0",children:r("messages:builderUi.loopComponents.subject")}),(0,t.jsx)("input",{className:N,value:x.subject,onChange:e=>b(t=>({...t,subject:e.target.value}))})]}),(0,t.jsx)("textarea",{className:(0,j.cn)(N,"min-h-32 resize-y leading-relaxed"),value:x.body,onChange:e=>b(t=>({...t,body:e.target.value}))})]}):d&&(0,t.jsx)(O.ActionPreviewBlock,{preview:d}),"ai"===u&&(0,t.jsx)("textarea",{className:(0,j.cn)(N,"mt-2 min-h-16 resize-y"),placeholder:r("messages:builderUi.loopComponents.revisePlaceholder","Tell the AI what to change (e.g. more formal, mention the invoice)â¦"),value:v,onChange:e=>y(e.target.value)}),g&&(0,t.jsx)("p",{className:"mt-2 text-[12px] text-destructive",children:g}),(0,t.jsxs)("div",{className:"mt-2.5 flex flex-wrap items-center gap-2",children:["view"===u&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{onClick:()=>w(a),disabled:h,className:(0,j.cn)(C,"bg-primary text-primary-foreground hover:bg-primary/90"),children:h?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):k}),c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{onClick:()=>{d?.kind==="email"&&b({to:d.to,cc:d.cc??"",subject:d.subject,body:d.body}),m("edit")},disabled:h,className:(0,j.cn)(C,"border border-border text-foreground hover:bg-accent"),children:r("actions.edit")}),(0,t.jsx)("button",{onClick:()=>m("ai"),disabled:h,className:(0,j.cn)(C,"border border-border text-foreground hover:bg-accent"),children:r("messages:builderUi.loopComponents.askAi")})]}),(0,t.jsx)("button",{onClick:()=>w(n),disabled:h,className:(0,j.cn)(C,"text-muted-foreground hover:text-destructive"),children:r("messages:builderUi.loopComponents.reject")})]}),"edit"===u&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{onClick:()=>w(async()=>{await l(x),m("view")}),disabled:h,className:(0,j.cn)(C,"bg-primary text-primary-foreground hover:bg-primary/90"),children:h?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):r("actions.save")}),(0,t.jsx)("button",{onClick:()=>{m("view"),f(null)},disabled:h,className:(0,j.cn)(C,"text-muted-foreground hover:text-foreground"),children:r("actions.cancel")})]}),"ai"===u&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{onClick:()=>w(async()=>{await i(v),y(""),m("view")}),disabled:h||!v.trim(),className:(0,j.cn)(C,"bg-primary text-primary-foreground hover:bg-primary/90"),children:h?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):r("messages:builderUi.loopComponents.askAiRedo")}),(0,t.jsx)("button",{onClick:()=>{m("view"),f(null)},disabled:h,className:(0,j.cn)(C,"text-muted-foreground hover:text-foreground"),children:r("actions.cancel")})]})]})]})}let K={run_started:(0,t.jsx)(c.Lightning,{size:13,weight:"fill"}),iteration:(0,t.jsx)(i.ArrowsClockwise,{size:13}),tool_call:(0,t.jsx)(p.Plug,{size:13}),tool_result:(0,t.jsx)(k.CheckCircle,{size:13}),decision_requested:(0,t.jsx)(g.Question,{size:13,weight:"fill"}),decision_answered:(0,t.jsx)(I.ChatCircleDots,{size:13,weight:"fill"}),run_completed:(0,t.jsx)(k.CheckCircle,{size:13,weight:"fill"}),error:(0,t.jsx)(M.XCircle,{size:13,weight:"fill"})};function V(e){let s,n,l=(0,a.c)(8),{steps:i}=e,{t:r}=(0,F.useTranslation)();if(0===i.length){let e,a;return l[0]!==r?(e=r("messages:builderUi.loopComponents.noStepsRecordedYet"),l[0]=r,l[1]=e):e=l[1],l[2]!==e?(a=(0,t.jsx)("p",{className:"py-3 text-center text-[12px] text-muted-foreground",children:e}),l[2]=e,l[3]=a):a=l[3],a}return l[4]!==i?(s=i.map(Y),l[4]=i,l[5]=s):s=l[5],l[6]!==s?(n=(0,t.jsx)("ol",{className:"space-y-1.5",children:s}),l[6]=s,l[7]=n):n=l[7],n}function Y(e){let a=e.payload?.draft??null;return(0,t.jsxs)("li",{className:"flex items-start gap-2",children:[(0,t.jsx)("span",{className:(0,j.cn)("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full","error"===e.kind?"bg-destructive/15 text-destructive":"decision_requested"===e.kind?"bg-amber-500/15 text-amber-600":"run_completed"===e.kind?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:K[e.kind]??(0,t.jsx)(i.ArrowsClockwise,{size:13})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 pb-1",children:[(0,t.jsx)("p",{className:"text-[12.5px] font-medium text-foreground",children:e.title}),a?.draft_id?(0,t.jsx)("div",{className:"mt-1",children:(0,t.jsx)(U,{draft:
24a})}):e.detail&&(0,t.jsx)("p",{className:"mt-0.5 whitespace-pre-wrap text-[12px] leading-relaxed text-muted-foreground",children:e.detail})]})]},`${e.run_id}-${e.seq}`)}function q({run:e,expanded:a,steps:n,onToggle:l,onFeedback:i,onCancel:r}){let{t:d}=(0,F.useTranslation)(),c=B[e.status],[u,m]=(0,s.useState)(null),[h,p]=(0,s.useState)(""),[g,f]=(0,s.useState)(!1),x="running"===e.status||"waiting_decision"===e.status,b=async e=>{f(!0);try{await i(e,h.trim()||void 0),m(null),p("")}finally{f(!1)}};return(0,t.jsxs)("div",{className:"rounded-xl border border-border",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 px-3.5 py-2.5",children:[(0,t.jsxs)("button",{onClick:l,className:"flex min-w-0 flex-1 items-center gap-3 text-left",children:[(0,t.jsx)("span",{className:(0,j.cn)("rounded-full px-2 py-0.5 text-[11px] font-medium",c.cls),children:c.label}),(0,t.jsx)("span",{className:"text-[12px] text-muted-foreground",children:"schedule"===e.trigger?"scheduled":"manual"}),(0,t.jsx)("span",{className:"text-[12px] text-muted-foreground",children:$(e.started_at)}),"running"===e.status&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-[12px] text-blue-600",children:[(0,t.jsx)(o.CircleNotch,{size:12,className:"animate-spin"}),e.progress,"%"]}),e.error&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 truncate text-[12px] text-destructive",children:[(0,t.jsx)(D.Warning,{size:12}),e.error]})]}),x&&r&&(0,t.jsx)("button",{onClick:r,className:"rounded-md px-2 py-1 text-[11.5px] text-muted-foreground hover:bg-accent hover:text-destructive",children:d("dataRoom:askAi.stop")}),!x&&(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("button",{onClick:()=>m(e=>"up"===e?null:"up"),className:(0,j.cn)("rounded-md p-1.5 hover:bg-accent","up"===e.my_feedback?"text-emerald-600":"text-muted-foreground"),title:d("messages:builderUi.loopComponents.goodResult"),children:(0,t.jsx)(A.ThumbsUp,{size:15,weight:"up"===e.my_feedback?"fill":"regular"})}),(0,t.jsx)("button",{onClick:()=>m(e=>"down"===e?null:"down"),className:(0,j.cn)("rounded-md p-1.5 hover:bg-accent","down"===e.my_feedback?"text-destructive":"text-muted-foreground"),title:d("messages:builderUi.loopComponents.needsImprovement"),children:(0,t.jsx)(E.ThumbsDown,{size:15,weight:"down"===e.my_feedback?"fill":"regular"})})]})]}),u&&(0,t.jsxs)("div",{className:"flex gap-2 border-t border-border px-3.5 py-2.5",children:[(0,t.jsx)("input",{value:h,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&b(u)},placeholder:"up"===u?d("messages:builderUi.loopComponents.lessonPlaceholder","What worked well? (optional â teaches the loop)"):d("messages:builderUi.loopComponents.whatShouldChangeNextTime"),className:"flex-1 rounded-lg border border-input bg-background px-3 py-1.5 text-[12.5px] placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"}),(0,t.jsx)("button",{onClick:()=>b(u),disabled:g,className:"rounded-lg bg-primary px-3 py-1.5 text-[12.5px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:g?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):d("actions.save")})]}),a&&(0,t.jsxs)("div",{className:"border-t border-border px-3.5 py-3",children:[null===n?(0,t.jsx)("p",{className:"py-2 text-center text-[12px] text-muted-foreground",children:(0,t.jsx)(o.CircleNotch,{size:14,className:"mx-auto animate-spin"})}):(0,t.jsx)(V,{steps:n}),e.summary&&(0,t.jsxs)("div",{className:"mt-3 rounded-lg bg-muted/40 p-3",children:[(0,t.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:d("messages:builderUi.loopComponents.result")}),(0,t.jsx)("p",{className:"mt-1 whitespace-pre-wrap text-[12.5px] leading-relaxed text-foreground",children:e.summary})]})]})]})}function J({lesson:e,onUpdate:a,onDelete:n}){let{t:l}=(0,F.useTranslation)(),[i,r]=(0,s.useState)(!1),[o,d]=(0,s.useState)(e.text),[c,u]=(0,s.useState)(!1),m=async()=>{if(o.trim()&&!c){u(!0);try{await a({text:o.trim()}),r(!1)}finally{u(!1)}}};return(0,t.jsxs)("div",{className:"group flex items-start gap-2 rounded-lg border border-border bg-background px-3 py-2",children:[(0,t.jsx)("button",{onClick:()=>a({pinned:!e.pinned}),className:(0,j.cn)("mt-0.5 shrink-0",e.pinned?"text-amber-500":"text-muted-foreground
24/40 hover:text-muted-foreground"),title:e.pinned?l("messages:builderUi.loopComponents.unpin","Unpin (can be evicted)"):l("messages:builderUi.loopComponents.pin","Pin (never evicted)"),children:e.pinned?(0,t.jsx)(_.PushPin,{size:14,weight:"fill"}):(0,t.jsx)(T.PushPinSlash,{size:14})}),i?(0,t.jsx)("input",{value:o,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key&&m(),"Escape"===e.key&&r(!1)},autoFocus:!0,className:"flex-1 rounded border border-input bg-background px-2 py-1 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"}):(0,t.jsx)("p",{className:"flex-1 text-[12.5px] leading-relaxed text-foreground",children:e.text}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-1 opacity-0 group-hover:opacity-100",children:[i?(0,t.jsx)("button",{onClick:m,disabled:c,className:"rounded p-1 text-emerald-600 hover:bg-accent",children:(0,t.jsx)(k.CheckCircle,{size:14})}):(0,t.jsx)("button",{onClick:()=>{d(e.text),r(!0)},className:"rounded p-1 text-muted-foreground hover:bg-accent",children:(0,t.jsx)(S.PencilSimple,{size:14})}),(0,t.jsx)("button",{onClick:()=>void n(),className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-destructive",children:(0,t.jsx)(R.Trash,{size:14})})]})]})}let X=[{id:"weekday8",label:"Every weekday 8am",cron:"0 8 * * 1-5"},{id:"daily9",label:"Daily 9am",cron:"0 9 * * *"},{id:"monday9",label:"Every Monday 9am",cron:"0 9 * * 1"},{id:"hourly",label:"Hourly",cron:"0 * * * *"}];function Z({loopId:e,focusDecisionId:a,autoRunToken:k,onBack:N}){let{t:C}=(0,F.useTranslation)(),[S,_]=(0,s.useState)(null),[T,E]=(0,s.useState)([]),[A,R]=(0,s.use
24State)([]),[D,M]=(0,s.useState)(null),[I,O]=(0,s.useState)({}),[P,L]=(0,s.useState)(!1),[B,H]=(0,s.useState)(null),[z,U]=(0,s.useState)(!1),[W,K]=(0,s.useState)(""),[V,Y]=(0,s.useState)([]),[Q,ee]=(0,s.useState)(!1),[et,ea]=(0,s.useState)(!1),[es,en]=(0,s.useState)(!1),el=(0,s.useRef)(null),ei=(0,s.useRef)(null),er=(0,s.useCallback)(async()=>{try{let[t,a,s]=await Promise.all([(0,y.fetchLoop)(e),(0,y.fetchRuns)(e),(0,y.fetchDecisions)(e)]);_(t),E(a),R(s),K(t.schedule_cron??""),Y(e=>(t.clarifications_json??[]).map((t,a)=>t.answer??e[a]??""))}catch(e){H(e instanceof Error?e.message:"Failed to load loop")}},[e]);(0,s.useEffect)(()=>{er()},[er]),(0,s.useEffect)(()=>{let t=(0,y.openLoopStream)(e,e=>{"step"===e.type&&e.step.run_id===D&&O(t=>{let a=t[e.step.run_id]??[];return a.some(t=>t.seq===e.step.seq)?t:{...t,[e.step.run_id]:[...a,e.step]}}),el.current&&clearTimeout(el.current),el.current=setTimeout(()=>void er(),600)});return()=>{t(),el.current&&clearTimeout(el.current)}},[e,er,D]);let eo=(0,s.useMemo)(()=>T.find(e=>"running"===e.status||"waiting_decision"===e.status)??null,[T]),ed=A.filter(e=>"pending"===e.status),ec=(S?.connections_json?.required??[]).filter(e=>!e.connected),eu=(S?.connections_json?.apps??[]).filter(e=>!e.installed),em=S?.memory_json?.lessons??[],eh=S?.plan_json?.steps??[],ep=(S?.clarifications_json??[]).filter(e=>!e.answer),eg=S?.status==="draft",ef=0===ep.length&&0===ec.length&&(0===eu.length||es),ex=async t=>{if(D===t)return void M(null);if(M(t),!I[t]){let a=await (0,y.fetchRunSteps)(e,t);O(e=>({...e,[t]:a}))}},eb=async()=>{if(!P){L(!0),H(null);try{let{run_id:t}=await (0,y.runLoop)(e);M(t),O(e=>({...e,[t]:[]})),await er()}catch(e){H(e instanceof Error?e.message:C("messages:builderUi.loopDetail.runStartFailed","Run failed to start"))}finally{L(!1)}}},ev=async()=>{if(!et){ea(!0),H(null);try{_(await (0,y.finalizeLoop)(e,{skipMissingApps:es}))}catch(e){H(e instanceof Error?e.message:C("messages:builderUi.loopDetail.finalizeFailed","Failed to finalize")),await er()}finally{ea(!1)}}};(0,s.useEffect)(()=>{!k||ei.current===k||!S||(ei.current=k,"paused"===S.status||"draft"===S.status||ec.length>0||eo||eb())},[k,S,eo,ec.length]);let ej=async()=>{if(!S)return;let t="paused"===S.status?"ready":"paused";_(await (0,y.updateLoop)(e,{status:t}))},ey=async t=>{try{_(await (0,y.setLoopSchedule)(e,t)),U(!1)}catch(e){H(e instanceof Error?e.message:C("messages:builderUi.loopDetail.invalidSchedule","Invalid schedule"))}},ew=async()=>{if(!Q){ee(!0),H(null);try{let t=(S?.clarifications_json??[]).map((e,t)=>({answered:!!e.answer,value:V[t]??""})).filter(e=>!e.answered).map(e=>e.value);_(await (0,y.clarifyLoop)(e,t))}catch(e){H(e instanceof Error?e.message:C("messages:builderUi.loopDetail.refineFailed","Failed to refine"))}finally{ee(!1)}}};return S?(0,t.jsx)("div",{className:"h-full overflow-y-auto bg-background",children:(0,t.jsxs)("div",{className:"mx-auto max-w-4xl px-4 py-6 sm:px-6",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,t.jsx)("button",{onClick:N,"aria-label":C("actions.back","Back"),className:"rounded-lg p-1.5 text-muted-foreground hover:bg-accent",children:(0,t.jsx)(l.ArrowLeft,{size:18})}),(0,t.jsx)("span",{className:"flex size-10 shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-sky-500 to-cyan-600 text-white",children:(0,t.jsx)(i.ArrowsClockwise,{size:20,weight:"fill"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("h1",{className:"truncate text-lg font-bold text-foreground",children:S.title}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-[12px] text-muted-foreground",children:[(0,t.jsx)("span",{className:(0,j.cn)("rounded-full px-2 py-0.5 text-[11px] font-medium","active"===S.status?"bg-emerald-500/15 text-emerald-600":"draft"===S.status?"bg-amber-500/15 text-amber-600":"bg-muted"),children:S.status}),(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,t.jsx)(c.Lightning,{size:12}),"last run ",$(S.last_run_at)]}),S.schedule_cron&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,t.jsx)(d.
24Clock,{size:12}),S.schedule_cron,S.schedule_timezone&&` \xb7 ${S.schedule_timezone}`]})]})]}),(0,t.jsxs)("div",{className:"relative flex w-full flex-wrap items-center gap-2 sm:w-auto",children:[(0,t.jsxs)("button",{onClick:()=>U(e=>!e),className:"flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-[12.5px] font-medium text-foreground hover:bg-accent",children:[(0,t.jsx)(d.Clock,{size:14}),C("messages:builderUi.loopDetail.schedule")]}),!eg&&(0,t.jsx)("button",{onClick:ej,className:"flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-[12.5px] font-medium text-foreground hover:bg-accent",children:"paused"===S.status?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(h.Play,{size:14}),C("messages:builderUi.loopDetail.resume")]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(m.Pause,{size:14}),C("messages:builderUi.loopDetail.pause")]})}),eg?(0,t.jsxs)("button",{onClick:ev,disabled:et||!ef,className:"flex items-center gap-1.5 rounded-lg bg-primary px-3.5 py-1.5 text-[12.5px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",title:ef?void 0:C("messages:builderUi.loopDetail.answerQuestionsConnectRequiredServices"),children:[et?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):(0,t.jsx)(x.Sparkle,{size:14,weight:"fill"}),"Finalize plan"]}):(0,t.jsxs)("button",{onClick:eb,disabled:P||!!eo||"paused"===S.status||ec.length>0,className:"flex items-center gap-1.5 rounded-lg bg-primary px-3.5 py-1.5 text-[12.5px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",title:eo?C("messages:builderUi.loopDetail.runIsAlreadyProgress"):void 0,children:[P?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):(0,t.jsx)(h.Play,{size:14,weight:"fill"}),"Run now"]}),z&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"fixed inset-0 z-10",onClick:()=>U(!1)}),(0,t.jsxs)("div",{className:"absolute right-0 top-full z-20 mt-1 w-64 rounded-xl border border-border bg-popover p-3 shadow-xl",children:[(0,t.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:C("messages:builderUi.loopDetail.runOnSchedule")}),(0,t.jsx)("p",{className:"text-[12px] text-muted-foreground",children:S.schedule_timezone??C("paletteOs:scheduledTasks.serverTime")}),(0,t.jsx)("div",{className:"mt-2 space-y-1",children:X.map(e=>(0,t.jsxs)("button",{onClick:()=>ey(e.cron),className:"flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-[12.5px] hover:bg-accent",children:[(0,t.jsx)("span",{children:C(`messages:builderUi.loopDetail.schedulePresets.${e.id}`,{defaultValue:e.label})}),(0,t.jsx)("code",{className:"text-[10.5px] text-muted-foreground",children:e.cron})]},e.cron))}),(0,t.jsxs)("div",{className:"mt-2 flex gap-1.5",children:[(0,t.jsx)("input",{value:W,onChange:e=>K(e.target.value),placeholder:C("messages:builderUi.loopDetail.customCron"),className:"min-w-0 flex-1 rounded-lg border border-input bg-background px-2 py-1 text-[12px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"}),(0,t.jsx)("button",{onClick:()=>ey(W.trim()||null),className:"rounded-lg bg-primary px-2.5 py-1 text-[12px] font-medium text-primary-foreground",children:C("messages:builderUi.loopDetail.set")})]}),S.schedule_cron&&(0,t.jsx)("button",{onClick:()=>ey(null),className:"mt-2 w-full rounded-lg border border-border px-2 py-1 text-[12px] text-muted-foreground hover:bg-accent",children:C("messages:builderUi.loopDetail.clearSchedule")})]})]})]})]}),B&&(0,t.jsx)("p",{className:"mt-3 rounded-lg bg-destructive/10 px-3 py-2 text-[12.5px] text-destructive",children:B}),ec.length>0&&(0,t.jsxs)("div",{className:"mt-4 rounded-xl border border-orange-400/40 bg-orange-500/[0.06] p-4",children:[(0,t.jsxs)("p",{className:"flex items-center gap-1.5 text-[13px] font-semibold text-foreground",children:[(0,t.jsx)(p.Plug,{size:15,className:"text-orange-500"}),C("messages:builderUi.loopDetail.connectTheseServicesRunLoop")]}),(0,t.jsx)("div",{className:"mt-2 space-y-1.5",children:ec.map(e=>(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 text-[12.5px]",children:[(0,t.jsxs)("span",{children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:e.display_name}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:[" â ",e.reason||e.tools.join(", ")
24]})]}),e.connect_available?(0,t.jsx)(w.default,{href:"/connect?section=apps",className:"shrink-0 rounded-lg bg-primary px-2.5 py-1 text-[12px] font-medium text-primary-foreground hover:bg-primary/90",children:C("messages:builder.config.services.connect")}):(0,t.jsx)("span",{className:"shrink-0 text-[11.5px] text-muted-foreground",children:"coming soon"})]},e.provider))})]}),eu.length>0&&(0,t.jsxs)("div",{className:"mt-4 rounded-xl border border-sky-400/40 bg-sky-500/[0.06] p-4",children:[(0,t.jsxs)("p",{className:"flex items-center gap-1.5 text-[13px] font-semibold text-foreground",children:[(0,t.jsx)(b.SquaresFour,{size:15,className:"text-sky-500"}),C("messages:builderUi.loopDetail.appsLoopUses")]}),(0,t.jsx)("div",{className:"mt-2 space-y-1.5",children:eu.map(e=>(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 text-[12.5px]",children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:e.name}),(0,t.jsx)(w.default,{href:e.store_route,className:"shrink-0 rounded-lg bg-primary px-2.5 py-1 text-[12px] font-medium text-primary-foreground hover:bg-primary/90",children:C("devUi.developerAppDetail.install")})]},e.app_id))}),eg&&(0,t.jsxs)("label",{className:"mt-3 flex items-center gap-2 text-[12px] text-muted-foreground",children:[(0,t.jsx)("input",{type:"checkbox",checked:es,onChange:e=>en(e.target.checked)}),C("messages:builderUi.loopDetail.finalizeWithoutTheseApps")]})]}),S.gates?.note&&(0,t.jsxs)("div",{className:"mt-4 flex items-start gap-2 rounded-xl border border-border bg-muted/40 p-3.5 text-[12.5px] text-muted-foreground",children:[(0,t.jsx)(f.ShieldCheck,{size:15,className:"mt-0.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{children:S.gates.note})]}),ep.length>0&&(0,t.jsxs)("div",{className:"mt-4 rounded-xl border border-violet-400/40 bg-violet-500/[0.06] p-4",children:[(0,t.jsxs)("p",{className:"flex items-center gap-1.5 text-[13px] font-semibold text-foreground",children:[(0,t.jsx)(x.Sparkle,{size:15,className:"text-violet-500"}),C("messages:builderUi.loopDetail.questionsHint","A few questions to sharpen this loop")]}),(0,t.jsx)("div",{className:"mt-2 space-y-2",children:(S.clarifications_json??[]).map((e,a)=>(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-[12.5px] text-foreground",children:e.question}),(0,t.jsx)("input",{value:V[a]??"",onChange:e=>Y(t=>t.map((t,s)=>s===a?e.target.value:t)),disabled:!!e.answer,placeholder:C("messages:builderUi.loopDetail.answer"),className:"mt-1 w-full rounded-lg border border-input bg-background px-3 py-1.5 text-[12.5px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-violet-400/60 disabled:opacity-60"})]},a))}),(0,t.jsxs)("button",{onClick:ew,disabled:Q||V.every(e=>!e.trim()),className:"mt-3 flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-[12.5px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[Q?(0,t.jsx)(o.CircleNotch,{size:14,className:"animate-spin"}):(0,t.jsx)(x.Sparkle,{size:14,weight:"fill"}),"Refine loop"]})]}),ed.length>0&&(0,t.jsxs)("div",{className:"mt-5",children:[(0,t.jsxs)("h2",{className:"flex items-center gap-1.5 text-[12px] font-semibold uppercase tracking-wide text-amber-600",children:[(0,t.jsx)(g.Question,{size:14,weight:"fill"}),C("messages:agentRun.details.status.waiting_input")]}),(0,t.jsx)("div",{className:"mt-2 space-y-2",children:ed.map(s=>(0,t.jsx)(G,{decision:s,highlighted:a===s.id,onUpdateDraft:async(t,a)=>{await (0,y.updateLoopDraft)(e,s.id,{draft_id:t,...a})},onAnswer:async t=>{await (0,y.answerDecision)(e,s.id,t),await er()}},s.id))})]}),(0,t.jsxs)("div",{className:"mt-6 grid gap-5 lg:grid-cols-[1fr_260px]",children:[(0,t.jsxs)("div",{className:"min-w-0 space-y-6",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-[12px] font-semibold uppercase tracking-wide text-muted-foreground",children:C("messages:builderUi.loopDetail.goal")}),(0,t.jsx)("p",{className:"mt-1.5 whitespace-pre-wrap text-[13px] leading-relaxed text-foreground",children:S.goal})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-[12px] font-semibold uppercase tracking-wide text-muted-foreground",children:C("messages:builder.config.tabs.runs")}),0===T.length?(0,t.jsx)("p",{className:"mt-2 rounded-xl border border-dashed border-border py-6 text-center text-[12.5px] text-muted-foreground",children:C("messages:builderUi.loopDetail.noRuns",'No runs yet â hit "Run now" or set a schedule.')}):(0,t.jsx)("div",{className:"mt-2 space-y-2",children:T.map(a=>(0,t.jsxs)("div",{children:[(0,t.jsx)(q,{run:a,expanded:D===a.id,steps:D===a.id?I[a.id]??null:null,onToggle:()=>void ex(a.id),onFeedback:async(t,s)=>{await (0,y.submitFeedback)(e,a.id,t,s),await er()},onCancel:"running"===a.status||"waiting_decision"===a.status?()=>{(0,y.cancelRun)(e,a.id).then(er)}:void 0}),a.resume_job_id&&(0,t.jsx)(n.ResumeJobButton,{jobId:a.resume_job_id,onResumed:er})]},a.id))})]})]}),(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)("div",{className:"rounded-xl border border-border p-3.5",children:[(0,t.jsxs)("h3",{className:"flex items-center gap-1.5 text-[12px] font-semibold uppercase tracking-wide text-muted-foreground",children:[(0,t.jsx)(u.ListChecks,{size:14}),C("messages:builderUi.loopDetail.plan")]}),0===eh.length?(0,t.jsx)("p",{className:"mt-2 text-[12px] text-muted-foreground",children:C("messages:builderUi.loopDetail.workerPlansOnItsFirst")}):(0,t.jsx)("ol",{className:"mt-2 space-y-2",children:eh.map((e,a)=>(0,t.jsxs)("li",{className:"flex gap-2",children:[(0,t.jsx)("span",{className:"flex size-5 shrink-0 items-center justify-center rounded-full bg-muted text-[10.5px] font-semibold text-muted-foreground",children:a+1}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-[12.5px] font-medium text-foreground",children:e.title}),e.description&&(0,t.jsx)("p",{className:"text-[11.5px] leading-snug text-muted-foreground",children:e.description})]})]},e.id??a))})]}),S.required_tools.length>0&&(0,t.jsxs)("div",{className:"rounded-xl border border-border p-3.5",children:[(0,t.jsxs)("h3",{className:"flex items-center gap-1.5 text-[12px] font-semibold uppercase tracking-wide text-muted-foreground",children:[(0,t.jsx)(v.Wrench,{size:14}),C("messages:builder.config.tabs.tools")]}),(0,t.jsx)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:S.required_tools.map(e=>(0,t.jsx)("code",{className:"rounded-md bg-muted px-1.5 py-0.5 text-[10.5px] text-muted-foreground",children:e.replace(/^conn__/,"").replace(/__/g," · ").replace(/_/g,".")},e))})]}),(0,t.jsxs)("div",{className:"rounded-xl border border-border p-3.5",children:[(0,t.jsxs)("h3",{className:"flex items-center gap-1.5 text-[12px] font-semibold uppercase tracking-wide text-muted-foreground",children:[(0,t.jsx)(r.Brain,{size:14}),C("messages:builderUi.loopDetail.learnedFromFeedback")]}),0===em.length?(0,t.jsx)("p",{className:"mt-2 text-[12px] text-muted-foreground",children:C("messages:builderUi.loopDetail.rateRunsWithNoteLoop")}):(0,t.jsx)("div",{className:"mt-2 space-y-1.5",children:em.map(a=>(0,t.jsx)(J,{lesson:a,onUpdate:async t=>{let s=await (0,y.updateLesson)(e,a.id,t);_(e=>e?{...e,memory_json:s}:e)},onDelete:async()=>{let t=await (0,y.deleteLesson)(e,a.id);_(e=>e?{...e,memory_json:t}:e)}},a.id))})]})]})]})]})}):(0,t.jsx)("div",{className:"flex h-full items-center justify-center bg-background",children:B?(0,t.jsx)("p",{className:"text-[13px] text-destructive",children:B}):(0,t.jsx)(o.CircleNotch,{size:24,className:"animate-spin text-muted-foreground"})})}var Q=e.i(846696),ee=e.i(980376);function et({open:e,onClose:a,onOpenLoop:n,returnFocusRef:l,embedded:r=!1}){let{t:o}=(0,F.useTranslation)(),{loops:d,loading:c,error:u,refetch:m,deleteLoop:h}
24=(0,y.useLoops)(),[p,g]=(0,s.useState)([]),[f,x]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),j=(0,s.useCallback)(async()=>{try{g(await (0,y.fetchLoopApprovals)("pending")),x(null)}catch(e){x(e instanceof Error?e.message:o("messages:builderUi.loopsDrawer.approvalsLoadFailed","Could not load approvals"))}},[]),w=(0,s.useCallback)(async()=>{v(!0);try{await Promise.all([m(),j()])}finally{v(!1)}},[j,m]);(0,s.useEffect)(()=>{if(!e)return;w();let t=()=>{w()},a=window.setInterval(()=>{w()},15e3);return window.addEventListener("focus",t),()=>{window.clearInterval(a),window.removeEventListener("focus",t)}},[e,w]);let k=(0,s.useMemo)(()=>d.filter(e=>e.pending_decisions>0),[d]),N=(0,s.useMemo)(()=>d.filter(e=>0===e.pending_decisions),[d]),C=p.length>0||k.length>0,S=(0,s.useCallback)(async(e,t)=>{try{await t(),g(t=>t.filter(t=>t.id!==e)),await m()}catch(e){Q.toast.error(e instanceof Error?e.message:o("messages:builderUi.loopsDrawer.approvalUpdateFailed","Could not update approval")),await j()}},[j,m]),_=(0,s.useCallback)(async e=>{try{await h(e),Q.toast.success(o("messages:builderUi.loopsDrawer.loopDeleted","Loop deleted"))}catch(e){Q.toast.error(e instanceof Error?e.message:o("messages:builderUi.loopsDrawer.loopDeleteFailed","Could not delete loop")),await m()}},[h,m]),T=e=>(0,t.jsx)(H,{loop:e,onOpen:()=>n(e.id),onDelete:()=>{_(e.id)}},e.id),E=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(ee.SheetHeader,{className:"border-b border-border px-4 py-3 pr-12",children:[(0,t.jsxs)(ee.SheetTitle,{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)(i.ArrowsClockwise,{size:16,className:"text-muted-foreground","aria-hidden":"true"}),o("messages:builderUi.loopsDrawer.loops")]}),(0,t.jsx)(ee.SheetDescription,{className:"sr-only",children:o("messages:builderUi.loopsDrawer.reviewLoopsPendingDecisionsActions")})]}),(0,t.jsxs)("div",{className:"min-h-0 flex-1 space-y-4 overflow-y-auto p-4",children:[(0,t.jsx)("p",{className:"sr-only","aria-live":"polite",children:b?o("messages:builderUi.loopsDrawer.refreshing","Refreshing loops"):o("messages:builderUi.loopsDrawer.upToDate","Loops are up to date")}),(u||f)&&(0,t.jsxs)("div",{role:"alert",className:"flex items-start gap-2 rounded-lg border border-destructive/30 bg-destructive/5 p-3 text-xs text-destructive",children:[(0,t.jsx)(D.Warning,{size:16,className:"mt-0.5 shrink-0","aria-hidden":"true"}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("p",{children:o("messages:builderUi.loopsDrawer.someLoopInformationCouldNot")}),(0,t.jsx)("button",{type:"button",onClick:()=>{w()},className:"mt-1 font-semibold underline underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:o("messages:builder.versions.retry")})]})]}),C&&(0,t.jsxs)("section",{"aria-labelledby":"loops-waiting-heading",children:[(0,t.jsx)("h3",{id:"loops-waiting-heading",className:"mb-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:o("messages:agentRun.details.status.waiting_input")}),(0,t.jsxs)("div",{className:"space-y-2",children:[p.map(e=>(0,t.jsx)(W,{approval:e,onApprove:()=>S(e.id,()=>(0,y.approveLoopApproval)(e.id)),onDeny:()=>S(e.id,()=>(0,y.denyLoopApproval)(e.id)),onEdit:async t=>{try{await (0,y.editLoopApproval)(e.id,t),await j()}catch(e){Q.toast.error(e instanceof Error?e.message:o("messages:builderUi.loopsDrawer.approvalEditFailed","Could not edit approval"))}},onRevise:async t=>{try{await (0,y.reviseLoopApproval)(e.id,t),await j()}catch(e){Q.toast.error(e instanceof Error?e.message:o("messages:builderUi.loopsDrawer.approvalReviseFailed","Could not revise approval"))}}},e.id)),k.map(T)]})]}),(0,t.jsxs)("section",{"aria-labelledby":"all-loops-heading",children:[(0,t.jsx)("h3",{id:"all-loops-heading",className:C?"mb-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground":"sr-only",children:o("messages:builderUi.loopsDrawer.allLoops")}),c&&0===d.length?(0,t.jsx)("p",{className:"py-8 text-center text-xs text-muted-foreground",children:o("sharedThread.loading")}):0!==d.length||u?(0,t.jsx)("div",{className:"space-y-2",children:(C?N:d).map(T)}):(0,t.jsx)("p",{className:"py-8 text-center text-xs text-muted-foreground",children:"No loops yet â ask the agent for recurring or autonomous work (for example, âevery morning read support emails and draft repliesâ)."})]})]})]});return(0,t.jsx)(ee.Sheet,{open:e,onOpenChange:e=>{e||a()},children:r?(0,t.jsx)("section",{className:"mx-auto flex w-full max-w-4xl flex-col",children:E}):(0,t.jsx)(ee.SheetContent,{side:"right",className:"w-full gap-0 p-0 sm:max-w-md",onCloseAutoFocus:e=>{l?.current&&(e.preventDefault(),l.current.focus())},children:E})})}var ea=e.i(589861),es=e.i(197144);function en(){}e.s(["LoopsView",0,function(){let e,n,l,i,r,o=(0,a.c)(16),{isInMacWindow:d,subRoute:c,search:u,n
24avigateTo:m}=(0,es.useWindowNavigation)();o[0]!==d||o[1]!==u||o[2]!==c?(e=()=>(0,ea.readLoopLocation)(d?u||c:window.location.search),o[0]=d,o[1]=u,o[2]=c,o[3]=e):e=o[3];let[h,p]=(0,s.useState)(e);o[4]!==d||o[5]!==u||o[6]!==c?(n=()=>{let e=()=>p((0,ea.readLoopLocation)(d?u||c:window.location.search));return e(),window.addEventListener("popstate",e),window.addEventListener(ea.LOOP_LOCATION_EVENT,e),()=>{window.removeEventListener("popstate",e),window.removeEventListener(ea.LOOP_LOCATION_EVENT,e)}},l=[d,c,u],o[4]=d,o[5]=u,o[6]=c,o[7]=n,o[8]=l):(n=o[7],l=o[8]),(0,s.useEffect)(n,l),o[9]!==d||o[10]!==m?(i=e=>{p({loopId:e,decisionId:null}),d?m(e?`/loops?loop=${e}`:"/loops"):(0,ea.syncLoopLocation)(e)},o[9]=d,o[10]=m,o[11]=i):i=o[11];let g=i;return o[12]!==g||o[13]!==h.decisionId||o[14]!==h.loopId?(r=(0,t.jsx)("div",{className:"viewPane overflow-y-auto",children:h.loopId?(0,t.jsx)(Z,{loopId:h.loopId,focusDecisionId:h.decisionId,onBack:()=>g(null)},h.loopId):(0,t.jsx)(et,{open:!0,embedded:!0,onClose:en,onOpenLoop:e=>g(e)})}),o[12]=g,o[13]=h.decisionId,o[14]=h.loopId,o[15]=r):r=o[15],r}],971962);var el=e.i(154920),ei=e.i(455435),er=e.i(209165),eo=e.i(484188),ed=e.i(494202),ec=e.i(96213),eu=e.i(219760),em=e.i(549127),eh=e.i(649714),ep=e.i(513550),eg=e.i(566141),ef=e.i(154057);let ex=["grid","list","columns","gallery"],eb="palette_drive_view_v1";var ev=e.i(569377),ej=e.i(216606),ey=e.i(244002);let ew='<path d="M3 6a2 2 0 0 1 2-2h5l3 3h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6Z"/>',ek={folder:ew,audio:'<path d="M6 9H9L13 5V19L9 15H6Z"/><path d="M16 8.5C18 10.5 18 13.5 16 15.5"/>',memory:'<circle cx="12" cy="12" r="3"/><circle cx="12" cy="4.5" r="1.6"/><circle cx="5" cy="17" r="1.6"/><circle cx="19" cy="17" r="1.6"/><path d="M12 9V6M10 14l-3.6 2M14 14l3.6 2"/>',duplicate:'<path d="M8 8h11v11H8Z"/><path d="M5 16V5h11"/>',graph:'<circle cx="6" cy="6" r="2.5"/><circle cx="18" cy="6" r="2.5"/><circle cx="12" cy="18" r="2.5"/><path d="M8 7l3 9M16 7l-3 9"/>',columns:'<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M9 4v16M15 4v16"/>',gallery:'<rect x="3" y="3.5" width="18" height="11.5" rx="2"/><rect x="3" y="17.5" width="4.5" height="3" rx="1"/><rect x="9.75" y="17.5" width="4.5" height="3" rx="1"/><rect x="16.5" y="17.5" width="4.5" height="3" rx="1"/>'};function eN(e){let s,n,l=(0,a.c)(8),{name:i,className:r}=e,o=`drvIco${r?` ${r}`:""}`;if(`h_${i}`in ey.GLYPH_PATHS){let e,a=`h_${i}`;return l[0]!==o||l[1]!==a?(e=(0,t.jsx)(ey.Glyph,{name:a,className:o,strokeWidth:1.6}),l[0]=o,l[1]=a,l[2]=e):e=l[2],e}let d=ek[i]??ew;return l[3]!==d?(s={__html:d},l[3]=d,l[4]=s):s=l[4],l[5]!==o||l[6]!==s?(n=(0,t.jsx)("svg",{className:o,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",dangerouslySetInnerHTML:s}),l[5]=o,l[6]=s,l[7]=n):n=l[7],n}let eC={folder:"folder",slides:"layers",image:"image",document:"file",video:"play",data:"grid",audio:"audio"};function eS(e,t){let a=(0,ev.glyphFor)(e);return"image"===a||"video"===a||"audio"===a?a:"sheet"===a?"data":/\.(html?|pptx?|key)$/i.test(t)?"slides":"document"}let e_=["name","owner","modified","size"],eT=e=>"modified"===e||"size"===e?"desc":"asc";function eE(e,t,a){let s="asc"===a?1:-1;return[...e].sort((e,a)=>"folder"===e.kind!=("folder"===a.kind)?"folder"===e.kind?-1:1:("size"===t?(e.size??-1)-(a.size??-1):"modified"===t?(e.modified??"").localeCompare(a.modified??""):"owner"===t?e.owner.localeCompare(a.owner):e.name.localeCompare(a.name,void 0,{numeric:!0}))*s||e.name.localeCompare(a.name,void 0,{numeric:!0}))}let eA={ko:"ko-KR",ja:"ja-JP",en:"en-US"};function eR(e,t){if(!e)return"â";let a=new Date(e).getTime();return Number.isNaN(a)?"â":new Intl.DateTimeFormat(eA[t.slice(0,2)]??t,{year:"numeric",month:"2-digit",day:"2-digit"}).format(a)}function eD(e){let s,n,l=(0,a.c)(5),{kind:i,className:r}=e,o=`drvKind kind-${i}${r?` ${r}`:""}`,d=eC[i];return l[0]!==d?(s=(0,t.jsx)(eN,{name:d}),l[0]=d,l[1]=s):s=l[1],l[2]!==o||l[3]!==s?(n=(0,t.jsx)("span",{className:o,children:s}),l[2]=o,l[3]=s,l[4]=n):n=l[4],n}function eM(e){let n,l,i,r,o,d,c=(0,a.c)(17),{rows:u,selection:m,onToggleAll:h,label:p}=e,g=(0,s.useRef)(null);if(c[0]!==u||c[1]!==m){let e;n=u.filter(eI),c[4]!==m?(e=e=>m.has(e.key),c[4]=m,c[5]=e):e=c[5],l=n.filter(e),c[0]=u,c[1]=m,c[2]=n,c[3]=l}else n=c[2],l=c[3];let f=l.length,x=n.length>0&&f===n.length;c[6]!==x||c[7]!==f?(i=()=>{g.current&&(g.current.indeterminate=f>0&&!x)},r=[f,x],c[6]=x,c[7]=f,c[8]=i,c[9]=r):(i=c[8],r=c[9]),(0,s.useEffect)(i,r);let b=!n.length;return c[10]!==h?(o=e=>h(e.target.checked),c[10]=h,c[11]=o):o=c[11],c[12]!==x||c[13]!==p||c[14]!==b||c[15]!==o?(d=(0,t.jsx)("input",{ref:g,type:"checkbox",className:"drvChk","aria-label":p,checked:x,disabled:b,onChange:o}),c[12]=x,c[13]=p,c[14]=b,c[15]=o,c[16]=d):d=c[16],d}function eI(e){return!1!==e.selectable}function eO(e){let s,n,l,i=(0,a.c)(9),{row:r}=e,{t:o}=(0,F.useTranslation)("paletteOs");return i[0]!==r.starred||i[1]!==o?(s=r.starred&&(0,t.jsx)("span",{className:"drvStar",role:"img","aria-label":o("drive.h.starredMark","Starred"),children:(0,t.jsx)(eN,{name:"star"})}),i[0]=r.starred,i[1]=o,i[2]=s):s=i[2],i[3]!==r.shared||i[4]!==o?(n=r.shared&&(0,t.jsx)("span",{className:"drvShared",role:"img","aria-label":o("drive.h.sharedMark","Shared"),children:(0,t.jsx)(eN,{name:"users"})}),i[3]=r.shared,i[4]=o,i[5]=n):n=i[5],i[6]!==s||i[7]!==n?(l=(0,t.jsxs)(t.Fragment,{children:[s,n]}),i[6]=s,i[7]=n,i[8]=l):l=i[8],l}function eP(e){let n,l,i,r=(0,a.c)(8),{row:o,large:d}
24=e,[c,u]=(0,s.useState)(0);if(r[0]!==d||r[1]!==o.thumbs){let e=o.thumbs??[];n=d?[...e].reverse():e,r[0]=d,r[1]=o.thumbs,r[2]=n}else n=r[2];let m=n[c];if(!m){let e;return r[3]!==o.kind?(e=(0,t.jsx)(eD,{kind:o.kind}),r[3]=o.kind,r[4]=e):e=r[4],e}return r[5]===Symbol.for("react.memo_cache_sentinel")?(l=()=>u(eL),r[5]=l):l=r[5],r[6]!==m?(i=(0,t.jsx)("img",{src:m,alt:"",loading:"lazy",decoding:"async",onError:l}),r[6]=m,r[7]=i):i=r[7],i}function eL(e){return e+1}function eF(e){let s,n,l,i,r,o=(0,a.c)(13),{empty:d}=e;return o[0]!==d.icon?(s=(0,t.jsx)(eN,{name:d.icon}),o[0]=d.icon,o[1]=s):s=o[1],o[2]!==d.title?(n=(0,t.jsx)("h2",{children:d.title}),o[2]=d.title,o[3]=n):n=o[3],o[4]!==d.note?(l=d.note&&(0,t.jsx)("p",{children:d.note}),o[4]=d.note,o[5]=l):l=o[5],o[6]!==d.action?(i=d.action&&(0,t.jsx)("button",{type:"button",className:"drvBtn",onClick:d.action.on,children:d.action.label}),o[6]=d.action,o[7]=i):i=o[7],o[8]!==s||o[9]!==n||o[10]!==l||o[11]!==i?(r=(0,t.jsxs)("div",{className:"drvEmpty",children:[s,n,l,i]}),o[8]=s,o[9]=n,o[10]=l,o[11]=i,o[12]=r):r=o[12],r}function e$(e){let s,n,l,i,r,o=(0,a.c)(13),{row:d,onMenu:c}=e,{t:u}=(0,F.useTranslation)("paletteOs");return o[0]!==d.name||o[1]!==u?(s=u("drive.h.fileMenu","{{name}} menu",{name:d.name}),o[0]=d.name,o[1]=u,o[2]=s):s=o[2],o[3]!==u?(n=u("drive.h.more","More"),o[3]=u,o[4]=n):n=o[4],o[5]!==c||o[6]!==d?(l=e=>{e.stopPropagation(),c(d,e.currentTarget.getBoundingClientRect())},o[5]=c,o[6]=d,o[7]=l):l=o[7],o[8]===Symbol.for("react.memo_cache_sentinel")?(i=(0,t.jsx)(eN,{name:"more"}),o[8]=i):i=o[8],o[9]!==s||o[10]!==n||o[11]!==l?(r=(0,t.jsx)("button",{type:"button",className:"drvIconBtn drvMore","aria-label":s,title:n,"aria-haspopup":"menu",onClick:l,children:i}),o[9]=s,o[10]=n,o[11]=l,o[12]=r):r=o[12],r}function eB(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f=(0,a.c)(34),{row:x,location:b}=e,{t:v,i18n:j}=(0,F.useTranslation)("paletteOs");f[0]!==v?(s=v("drive.h.colOwner","Owner"),f[0]=v,f[1]=s):s=f[1],f[2]!==s?(n=(0,t.jsx)("dt",{children:s}),f[2]=s,f[3]=n):n=f[3];let y=x.owner||"â";return f[4]!==y?(l=(0,t.jsx)("dd",{children:y}),f[4]=y,f[5]=l):l=f[5],f[6]!==v?(i=v("drive.h.colModified","Modified"),f[6]=v,f[7]=i):i=f[7],f[8]!==i?(r=(0,t.jsx)("dt",{children:i}),f[8]=i,f[9]=r):r=f[9],f[10]!==j.language||f[11]!==x.modified?(o=eR(x.modified,j.language),f[10]=j.language,f[11]=x.modified,f[12]=o):o=f[12],f[13]!==o?(d=(0,t.jsx)("dd",{children:o}),f[13]=o,f[14]=d):d=f[14],f[15]!==v?(c=v("drive.h.colSize","Size"),f[15]=v,f[16]=c):c=f[16],f[17]!==c?(u=(0,t.jsx)("dt",{children:c}),f[17]=c,f[18]=u):u=f[18],f[19]!==x.size?(m=null==x.size?"â":(0,em.fmtSize)(x.size),f[19]=x.size,f[20]=m):m=f[20],f[21]!==m?(h=(0,t.jsx)("dd",{children:m}),f[21]=m,f[22]=h):h=f[22],f[23]!==b||f[24]!==v?(p=null!=b&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("dt",{children:v("drive.h.breadcrumb","Location")}),(0,t.jsx)("dd",{children:b})]}),f[23]=b,f[24]=v,f[25]=p):p=f[25],f[26]!==u||f[27]!==h||f[28]!==p||f[29]!==n||f[30]!==l||f[31]!==r||f[32]!==d?(g=(0,t.jsxs)(t.Fragment,{children:[n,l,r,d,u,h,p]}),f[26]=u,f[27]=h,f[28]=p,f[29]=n,f[30]=l,f[31]=r,f[32]=d,f[33]=g):g=f[33],g}function eH(e){let s,n,l,i,r,o,d,c,u,m,h,p,g=(0,a.c)(40),{row:f,hero:x,location:b,onOpen:v,onMenu:j}=e,y=void 0===x||x,{t:w}=(0,F.useTranslation)("paletteOs"),k=f.target,N="folder"===k.kind?k.folder.files_count+k.folder.folders_count:"room"===k.kind?k.room.files_count+k.room.folders_count:null;g[0]!==N||g[1]!==f.kind||g[2]!==f.name||g[3]!==w?(s=null!=N?w("drive.h.items","{{n}} items",{n:N}):"folder"===f.kind?null:/\.([^./]+)$/.exec(f.name)?.[1].toUpperCase(),g[0]=N,g[1]=f.kind,g[2]=f.name,g[3]=w,g[4]=s):s=g[4];let C=s;return g[5]!==y||g[6]!==f?(n=y&&(0,t.jsx)("div",{className:"drvPaneHero",children:(0,t.jsx)(eP,{row:f,large:!0},f.key)}),g[5]=y,g[6]=f,g[7]=n):n=g[7],g[8]!==f.name?(l=(0,t.jsx)("h3",{children:f.name}),g[8]=f.name,g[9]=l):l=g[9],g[10]!==C?(i=C&&(0,t.jsx)("p",{className:"drvPaneKind",children:C}),g[10]=C,g[11]=i):i=g[11],g[12]!==f.tags?(r=f.tags&&f.tags.length>0&&(0,t.jsx)("span",{className:"drvTags",children:f.tags.map(ez)}),g[12]=f.tags,g[13]=r):r=g[13],g[14]!==b||g[15]!==f?(o=(0,t.jsx)("dl",{className:"drvPaneInfo",children:(0,t.jsx)(eB,{row:f,location:b})}),g[14]=b,g[15]=f,g[16]=o):o=g[16],g[17]!==v||g[18]!==f?(d=()=>v(f),g[17]=v,g[18]=f,g[19]=d):d=g[19],g[20]!==f.kind||g[21]!==w?(c="folder"===f.kind?w("drive.h.openFolder","Open folder"):w("drive.contextMenu.open","Open"),g[20]=f.kind,g[21]=w,g[22]=c):c=g[22],g[23]!==d||g[24]!==c?(u=(0,t.jsx)("button",{type:"button",className:"drvBtn",onClick:d,children:c}),g[23]=d,g[24]=c,g[25]=u):u=g[25],g[26]!==j||g[27]!==f?(m=(0,t.jsx)(e$,{row:f,onMenu:j}),g[26]=j,g[27]=f,g[28]=m):m=g[28],g[29]!==u||g[30]!==m?(h=(0,t.jsxs)("div",{className:"drvPaneActs",children:[u,m]}),g[29]=u,g[30]=m,g[31]=h):h=g[31],g[32]!==f.name||g[33]!==h||g[34]!==n||g[35]!==l||g[36]!==i||g[37]!==r||g[38]!==o?(p=(0,t.jsxs)("section",{className:"drvPane","aria-label":f.name,children:[n,l,i,r,o,h]}),g[32]=f.name,g[33]=h,g[34]=n,g[35]=l,g[36]=i,g[37]=r,g[38]=o,g[39]=p):p=g[39],p}function ez(e){return(0,t.jsx)("span",{className:"drvTag",style:{background:ej.TAG_HEX[e]}},e)}
24function eU(e){let n,l,i,r,o,d,c,u,m,h=(0,a.c)(32),{rows:p,selection:g,toggleSelect:f,onOpen:x,onMenu:b,onContext:v,locate:j}=e,[y,w]=(0,s.useState)(null),k=(0,s.useRef)(null);if(h[0]!==y||h[1]!==p){let e;h[3]!==y?(e=e=>e.key===y,h[3]=y,h[4]=e):e=h[4],n=p.findIndex(e),h[0]=y,h[1]=p,h[2]=n}else n=h[2];let N=Math.max(0,n),C=p[N];h[5]!==C||h[6]!==x?(l=()=>x(C),h[5]=C,h[6]=x,h[7]=l):l=h[7],h[8]!==C||h[9]!==v?(i=e=>v(C,e),h[8]=C,h[9]=v,h[10]=i):i=h[10],h[11]!==C?(r=(0,t.jsx)(eP,{row:C,large:!0},C.key),h[11]=C,h[12]=r):r=h[12],h[13]!==l||h[14]!==i||h[15]!==r?(o=(0,t.jsx)("div",{className:"drvGalStage",onDoubleClick:l,onContextMenu:i,children:r}),h[13]=l,h[14]=i,h[15]=r,h[16]=o):o=h[16],h[17]!==C||h[18]!==j?(d=j?.(C),h[17]=C,h[18]=j,h[19]=d):d=h[19],h[20]!==C||h[21]!==b||h[22]!==x||h[23]!==d?(c=(0,t.jsx)(eH,{row:C,hero:!1,location:d,onOpen:x,onMenu:b}),h[20]=C,h[21]=b,h[22]=x,h[23]=d,h[24]=c):c=h[24];let S=p.map((e,a)=>(0,t.jsx)("li",{children:(0,t.jsx)("button",{type:"button",className:`drvGalThumb${g.has(e.key)?" is-selected":""}`,"aria-label":e.name,title:e.name,"aria-current":a===N?"true":void 0,tabIndex:a===N?0:-1,onClick:t=>{(t.metaKey||t.ctrlKey)&&!1!==e.selectable?f(e.key):w(e.key)},onDoubleClick:()=>x(e),onKeyDown:e=>((e,t)=>{if("Enter"===e.key){e.preventDefault(),x(p[t]);return}let a={ArrowRight:t+1,ArrowLeft:t-1,Home:0,End:p.length-1}[e.key];null!=a&&p[a]&&(e.preventDefault(),w(p[a].key),k.current?.querySelectorAll(".drvGalThumb")[a]?.focus())})(e,a),onContextMenu:t=>v(e,t),children:(0,t.jsx)(eP,{row:e})})},e.key));return h[25]!==k||h[26]!==S?(u=(0,t.jsx)("ul",{className:"drvGalStrip",ref:k,children:S}),h[25]=k,h[26]=S,h[27]=u):u=h[27],h[28]!==u||h[29]!==o||h[30]!==c?(m=(0,t.jsxs)("div",{className:"drvGallery",children:[o,c,u]}),h[28]=u,h[29]=o,h[30]=c,h[31]=m):m=h[31],m}function eG(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S=(0,a.c)(105),{rows:_,view:T,selection:E,toggleSelect:A,onToggleAll:R,onOpen:D,onMenu:M,onContext:I,sort:O,onSort:P,empty:L,locate:$}=e,{t:B,i18n:H}=(0,F.useTranslation)("paletteOs"),z=H.language;S[0]!==B?(s=B("drive.h.colName","Name"),S[0]=B,S[1]=s):s=S[1],S[2]!==s?(n=["name",s],S[2]=s,S[3]=n):n=S[3],S[4]!==B?(l=B("drive.h.colOwner","Owner"),S[4]=B,S[5]=l):l=S[5],S[6]!==l?(i=["owner",l],S[6]=l,S[7]=i):i=S[7],S[8]!==B?(r=B("drive.h.colModified","Modified"),S[8]=B,S[9]=r):r=S[9],S[10]!==r?(o=["modified",r],S[10]=r,S[11]=o):o=S[11],S[12]!==B?(d=B("drive.h.colSize","Size"),S[12]=B,S[13]=d):d=S[13],S[14]!==d?(c=["size",d],S[14]=d,S[15]=c):c=S[15],S[16]!==n||S[17]!==i||S[18]!==o||S[19]!==c?(u=[n,i,o,c],S[16]=n,S[17]=i,S[18]=o,S[19]=c,S[20]=u):u=S[20];let U=u;S[21]!==L?(m=(0,t.jsx)(eF,{empty:L}),S[21]=L,S[22]=m):m=S[22];let G=m;S[23]!==M?(h=e=>(0,t.jsx)(e$,{row:e,onMenu:M}),S[23]=M,S[24]=h):h=S[24];let W=h;S[25]!==E||S[26]!==B||S[27]!==A?(p=e=>!1===e.selectable?null:(0,t.jsx)("input",{type:"checkbox",className:"drvChk","aria-label":B("drive.h.selectItem","Select {{name}}",{name:e.name}),checked:E.has(e.key),onClick:eK,onChange:()=>A(e.key)}),S[25]=E,S[26]=B,S[27]=A,S[28]=p):p=S[28];let K=p;if("gallery"===T){let e;return S[29]!==G||S[30]!==$||S[31]!==I||S[32]!==M||S[33]!==D||S[34]!==_||S[35]!==E||S[36]!==A?(e=_.length?(0,t.jsx)(eU,{rows:_,selection:E,toggleSelect:A,onOpen:D,onMenu:M,onContext:I,locate:$}):G,S[29]=G,S[30]=$,S[31]=I,S[32]=M,S[33]=D,S[34]=_,S[35]=E,S[36]=A,S[37]=e):e=S[37],e}if("grid"===T){let e,a,s,n,l,i;return S[38]!==B?(e=B("drive.h.selectAllVisible","Select all shown files"),S[38]=B,S[39]=e):e=S[39],S[40]!==R||S[41]!==_||S[42]!==E||S[43]!==e?(a=(0,t.jsx)(eM,{rows:_,selection:E,onToggleAll:R,label:e}),S[40]=R,S[41]=_,S[42]=E,S[43]=e,S[44]=a):a=S[44],S[45]!==B?(s=B("drive.h.selectAll","Select all"),S[45]=B,S[46]=s):s=S[46],S[47]!==a||S[48]!==s?(n=(0,t.jsx)("div",{className:"drvGridSel",children:(0,t.jsxs)("label",{children:[a,s]})}),S[47]=a,S[48]=s,S[49]=n):n=S[49],S[50]!==K||S[51]!==G||S[52]!==z||S[53]!==W||S[54]!==I||S[55]!==D||S[56]!==_||S[57]!==E?(l=_.length?(0,t.jsx)("ul",{className:"drvGrid",children:_.map(e=>(0,t.jsxs)("li",{className:`drvCard${E.has(e.key)?" is-selected":""}`,onContextMenu:t=>I(e,t),children:[(0,t.jsxs)("div",{className:"drvCardTop",children:[K(e),(0,t.jsx)("span",{className:"drvCardMarks",children:(0,t.jsx)(eO,{row:e})}),W(e)]}),(0,t.jsxs)("button",{type:"button",className:"drvCardOpen",title:e.name,onClick:()=>D(e),children:[(0,t.jsx)("span",{className:"drvCardPreview",children:(0,t.jsx)(eP,{row:e})}),(0,t.jsx)("span",{className:"drvCardName",children:e.name})]}),(0,t.jsxs)("div",{className:"drvCardMeta",children:[(0,t.jsx)("span",{children:e.owner}),(0,t.jsx)("span",{children:null==e.size?"â":(0,em.fmtSize)(e.size)}),(0,t.jsx)("time",{children:eR(e.modified,z)})]})]},e.key))}):G,S[50]=K,S[51]=G,S[52]=z,S[53]=W,S[54]=I,S[55]=D,S[56]=_,S[57]=E,S[58]=l):l=S[58],S[59]!==n||S[60]!==l?(i=(0,t.jsxs)(t.Fragment,{children:[n,l]}),S[59]=n,S[60]=l,S[61]=i):i=S[61],i}if(S[62]===Symbol.for("react.memo_cache_sentinel")?(g=(0,t.jsxs)("colgroup",{children:[(0,t.jsx)("col",{className:"cCheck"}),(0,t.jsx)("col",{}),(0,t.jsx)("col",{className:"cOwner"}),(0,t.jsx)("col",{className:"cDate"}),(0,t.jsx)("col",{className:"cSize"}),(0,t.jsx)("col",{className:"cMore"})]}),S[62]=g):g=S[62],S[63]!==B?(f=B("drive.h.selectAllVisible","Select all shown files"),S[63]=B,S[64]=f):f=S[64],S[65]!==R||S[66]!==_||S[67]!==E||S[68]!==f?(x=(0,t.jsx)("th",{scope:"col",children:(0,t.jsx)(eM,{rows:_,selection:E,onToggleAll:R,label:f})}),S[65]=R,S[66]=_,S[67]=E,S[68]=f,S[69]=x):x=S[69],S[70]!==U||S[71]!==P||S[72]!==O?(b=U.map(e=>{let[a,s]=e;return(0,t.jsx)("th",{scope:"col","aria-sort":O.key===a?"asc"===O.dir?"ascending":"descending":"none",children:(0,t.jsxs)("button",{type:"button",onClick:()=>P(a),children:[s,O.key===a&&(0,t.jsx)(eN,{name:"asc"===O.dir?"arrowUp":"arrowDown"})]})},a)}),S[70]=U,S[71]=P,S[72]=O,S[73]=b):b=S[73],S[74]!==B?(v=B("drive.h.fileMenuCol","File menu"),S[74]=B,S[75]=v):v=S[75],S[76]!==v?(j=(0,t.jsx)("th",{scope:"col",children:(0,t.jsx)("span",{className:"drvSr",children:v})}),S[76]=v,S[77]=j):j=S[77],S[78]!==x||S[79]!==b||S[80]!==j?(y=(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[x,b,j]})}),S[78]=x,S[79]=b,S[80]=j,S[81]=y):y=S[81],S[82]!==K||S[83]!==z||S[84]!==W||S[85]!==I||S[86]!==D||S[87]!==_||S[88]!==E){let e;S[90]!==K||S[91]!==z||S[92]!==W||S[93]!==I||S[94]!==D||S[95]!==E?(e=e=>(0,t.jsxs)("tr",{className:E.has(e.key)?"is-selected":void 0,onClick:()=>D(e),onContextMenu:t=>I(e,t),children:[(0,t.jsx)("td",{children:K(e)}),(0,t.jsx)("td",{children:(0,t.jsxs)("div",{className:"drvNameCell",children:[(0,t.jsxs)("button",{type:"button",className:"drvFileName",title:e.name,onClick:t=>{t.stopPropagation(),D(e)},children:[(0,t.jsx)(eD,{kind:e.kind}),(0,t.jsx)("span",{children:e.name})]}),(0,t.jsx)(eO,{row:e}),e.tags&&e.tags.length>0&&(0,t.jsx)("span",{className:"drvTags",children:e.tags.slice(0,4).map(eW)})]})}),(0,t.jsx)("td",{children:(0,t.jsxs)("span",{className:"drvOwner",children:[(0,t.jsx)("span",{className:"drvAvatar","aria-hidden":"true",children:e.owner.slice(0,1)}),e.owner]})}),(0,t.jsx)("td",{className:"drvDate",children:eR(e.modified,z)}),(0,t.jsx)("td",{className:"drvSize",children:null==e.size?"â":(0,em.fmtSize)(e.size)}),(0,t.jsx)("td",{children:W(e)})]},e.key),S[90]=K,S[91]=z,S[92]=W,S[93]=I,S[94]=D,S[95]=E,S[96]=e):e=S[96],w=_.map(e),S[82]=K,S[83]=z,S[84]=W,S[85]=I,S[86]=D,S[87]=_,S[88]=E,S[89]=w}else w=S[89];S[97]!==w?(k=(0,t.jsx)("tbody",{children:w}),S[97]=w,S[98]=k):k=S[98],S[99]!==y||S[100]!==k?(N=(0,t.jsxs)("table",{className:"drvTable",children:[g,y,k]}),S[99]=y,S[100]=k,S[101]=N):N=S[101];let V=0===_.length&&G;return S[102]!==N||S[103]!==V?(C=(0,t.jsxs)(t.Fragment,{children:[N,V]}),S[102]=N,S[103]=V,S[104]=C):C=S[104],C}function eW(e){return(0,t.jsx)("span",{className:"drvTag",style:{background:ej.TAG_HEX[e]}},e)}function eK(e){return e.stopPropagation()}function eV(e){let n,l,i,r,o,d,c,u,m,h=(0,a.c)(33),{columns:p,preview:g,selection:f,toggleSelect:x,onPick:b,onOpen:v,onMenu:j,onContext:y,onRetry:w,empty:k,locate:N}=e,{t:C}=(0,F.useTranslation)("paletteOs"),S=(0,s.useRef)(null);h[0]!==p||h[1]!==g?.key?(n=[...p.map(eY),g?.key],h[0]=p,h[1]=g?.key,h[2]=n):n=h[2];let _=n.join("|");h[3]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{let e=S.current;e?.scrollTo?.({left:e.scrollWidth,behavior:"smooth"})},h[3]=l):l=h[3],h[4]!==_?(i=[_],h[4]=_,h[5]=i):i=h[5],(0,s.useEffect)(l,i);let T=1===p.length?p[0]:null;if(T&&!T.error&&T.rows?.length===0){let e;return h[6]!==k?(e=(0,t.jsx)(eF,{empty:k}),h[6]=k,h[7]=e):e=h[7],e}return h[8]!==p?(r=-1,p.forEach((e,t)=>{e.rows?.some(t=>t.key===e.active)&&(r=t)}),h[8]=p,h[9]=r):r=h[9],h[10]!==p||h[11]!==r||h[12]!==y||h[13]!==j||h[14]!==v||h[15]!==b||h[16]!==w||h[17]!==f||h[18]!==C||h[19]!==x?(o="drvCols",d=S,c=p.map((e,a)=>{let s=e.rows,n=s?.some(t=>t.key===e.active)?e.active:s?.[0]?.key;return(0,t.jsx)("ul",{className:`drvCol${e.current?" is-current":""}`,"data-col":a,"aria-busy":null===s,children:e.error?(0,t.jsxs)("li",{className:"drvColNote",role:"alert",children:[(0,t.jsx)("p",{children:C("drive.h.loadFailed")}),(0,t.jsx)("button",{type:"button",className:"drvBtn",onClick:()=>w(e),children:C("drive.share.retry","Retry")})]}):null===s?(0,t.jsx)("li",{className:"drvColNote",role:"status",children:C("drive.loading","Loadingâ¦")}):s.length?s.map((s,l)=>{let i=s.key===e.active;return(0,t.jsxs)("li",{onContextMenu:e=>y(s,e),className:`drvColItem${i?a===r?" is-lead":" is-active":""}${f.has(s.key)?" is-selected":""}`,children:[(0,t.jsxs)("button",{type:"button",className:"drvColRow",title:s.name,tabIndex:s.key===n?0:-1,"aria-current":i?"true":void 0,onClick:t=>{(t.metaKey||t.ctrlKey)&&e.current&&!1!==s.selectable?x(s.key):b(s,e)},onDoubleClick:()=>{"folder"!==s.kind&&v(s)},onKeyDown:e=>((e,t,a)=>{let s=p[t],n=s.rows?.[a];if(!n)return;if("Enter"===e.key){e.preventDefault(),"folder"===n.kind?b(n,s):v(n);return}let l=p[t-1],[i,r]="ArrowDown"===e.key?[t,a+1]:"ArrowUp"===e.key?[t,a-1]:"ArrowRight"===e.key&&n.key===s.active?[t+1,0]:"ArrowLeft"===e.key&&l?[t-1,l.rows?.findIndex(e=>e.key===l.active)??-1]:[-1,-1],o=p[i]?.rows?.[r];o&&(e.preventDefault(),b(o,p[i]),S.current?.querySelectorAll(`[data-col="${i}"] .drvColRow`)[r]?.focus())})(e,a,l),children:[(0,t.jsx)(eD,{kind:s.kind}),(0,t.jsx)("span",{className:"drvColName",children:s.name}),(0,t.jsx)(eO,{row:s})]}),"folder"===s.kind&&(0,t.jsx)(eN,{name:"chevronRight",className:"drvColChev"}),(0,t.jsx)(e$,{row:s,onMenu:j})]},s.key)}):(0,t.jsx)("li",{className:"drvColNote",children:C("drive.empty.folder","This folder is empty.")})},e.key)}),h[10]=p,h[11]=r,h[12]=y,h[13]=j,h[14]=v,h[15]=b,h[16]=w,h[17]=f,h[18]=C,h[19]=x,h[20]=o,h[21]=d,h[22]=c):(o=h[20],d=h[21],c=h[22]),h[23]!==N||h[24]!==j||h[25]!==v||h[26]!==g?(u=g&&(0,t.jsx)(eH,{row:g,location:N?.(g),onOpen:v,onMenu:j}),h[23]=N,h[24]=j,h[25]=v,h[26]=g,h[27]=u):u=h[27],h[28]!==o||h[29]!==d||h[30]!==c||h[31]!==u?(m=(0,t.jsxs)("div",{className:o,ref:d,children:[c,u]}),h[28]=o,h[29]=d,h[30]=c,h[31]=u,h[32]=m):m=h[32],m}function eY(e){return e.key}var eq=e.i(562436);function eJ(e){let n,l,i,r,o,d,c,u,m,h,p,g,f=(0,a.c)(31),{menu:x,onClose:b}=e,{t:v}=(0,F.useTranslation)("paletteOs"),j=(0,s.useRef)(null),[y]=(0,s.use
24State)(eQ),[w,k]=(0,s.useState)(null),N=x.sections.filter(eZ);f[0]!==x.anchor?(n=()=>{let e=j.current;if(!e)return;let t=e.getBoundingClientRect(),a=x.anchor,s=void 0!==a.width,n=s?a.x+(a.width??0)-t.width:a.x,l=s?a.y+(a.height??0)+10:a.y;k({left:n=Math.max(8,Math.min(n,window.innerWidth-t.width-8)),top:l=Math.max(8,Math.min(l,window.innerHeight-t.height-8))});let i=e.querySelector("[aria-checked='true']:not(:disabled)")??e.querySelector("button:not(:disabled)");i?.focus({preventScroll:!0})},f[0]=x.anchor,f[1]=n):n=f[1],f[2]!==x?(l=[x],f[2]=x,f[3]=l):l=f[3],(0,s.useLayoutEffect)(n,l),f[4]!==y?(i=()=>{let e=j.current;return()=>{y?.isConnected&&(document.activeElement===document.body||e?.contains(document.activeElement))&&y.focus()}},r=[y],f[4]=y,f[5]=i,f[6]=r):(i=f[5],r=f[6]),(0,s.useLayoutEffect)(i,r),f[7]!==b?(o=()=>{let e=e=>{j.current?.contains(e.target)||b()},t=e=>{"Escape"===e.key&&(e.stopPropagation(),b())};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t,!0)}},d=[b],f[7]=b,f[8]=o,f[9]=d):(o=f[8],d=f[9]),(0,s.useEffect)(o,d),f[10]===Symbol.for("react.memo_cache_sentinel")?(c=e=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;e.preventDefault();let t=Array.from(j.current?.querySelectorAll(".drvMenuItem:not(:disabled)")??[]),a=t.indexOf(document.activeElement),s="Home"===e.key?0:"End"===e.key?t.length-1:(a+("ArrowDown"===e.key?1:-1)+t.length)%t.length;t[s]?.focus()},f[10]=c):c=f[10];let C=c,S=w?.left??x.anchor.x,_=w?.top??x.anchor.y,T=w?"visible":"hidden";f[11]!==S||f[12]!==_||f[13]!==T?(u={left:S,top:_,visibility:T},f[11]=S,f[12]=_,f[13]=T,f[14]=u):u=f[14],f[15]!==x.label?(m=x.label&&(0,t.jsx)("div",{className:"drvMenuLabel",children:x.label}),f[15]=x.label,f[16]=m):m=f[16],f[17]!==b||f[18]!==y?(h=(e,a)=>(0,t.jsxs)("div",{role:"group",children:[a>0&&(0,t.jsx)("div",{className:"drvMenuSep",role:"separator"}),e.map(e=>(0,t.jsxs)("button",{type:"button",role:void 0===e.checked?"menuitem":"menuitemradio","aria-checked":e.checked,disabled:e.disabled,className:`drvMenuItem${e.danger?" danger":""}`,onClick:()=>{b(),y?.isConnected&&y.focus(),e.on?.()},children:[void 0!==e.checked?(0,t.jsx)(eN,{name:e.checked?"check":e.icon??"list"}):e.icon?(0,t.jsx)(eN,{name:e.icon}):(0,t.jsx)("span",{className:"drvMenuNoIcon"}),(0,t.jsx)("span",{children:e.label})]},e.id??e.label))]},a),f[17]=b,f[18]=y,f[19]=h):h=f[19];let E=N.map(h);return f[20]!==x.tagRow||f[21]!==b||f[22]!==v?(p=x.tagRow&&(0,t.jsxs)("div",{role:"group",children:[(0,t.jsx)("div",{className:"drvMenuSep",role:"separator"}),(0,t.jsxs)("div",{className:"poCtxTags",children:[(0,t.jsx)("span",{className:"poCtxTagsLbl",children:v("drive.tags","Tags")}),eq.TAG_COLORS.map(e=>{let a=x.tagRow.tags.includes(e);return(0,t.jsx)("button",{type:"button",title:v(`drive.tagColor.${e}`,e),className:`poCtxTag${a?" on":""}`,"aria-pressed":a,style:{background:ej.TAG_HEX[e]},onClick:()=>{x.tagRow.onSet(a?x.tagRow.tags.filter(t=>t!==e):[...x.tagRow.tags,e]),b()}},e)})]})]}),f[20]=x.tagRow,f[21]=b,f[22]=v,f[23]=p):p=f[23],f[24]!==C||f[25]!==u||f[26]!==eX||f[27]!==m||f[28]!==E||f[29]!==p?(g=(0,t.jsxs)("div",{ref:j,role:"menu",className:"drvMenu",style:u,onKeyDown:C,onContextMenu:eX,children:[m,E,p]}),f[24]=C,f[25]=u,f[26]=eX,f[27]=m,f[28]=E,f[29]=p,f[30]=g):g=f[30],g}function eX(e){return e.preventDefault()}function eZ(e){return e.length}function eQ(){return document.activeElement}function e0(e){let s,n,l,i,r,o,d,c,u,m=(0,a.c)(29),{transfers:h,onCancel:p,onRetry:g,onClear:f}=e,{t:x}=(0,F.useTranslation)("paletteOs");if(0===h.length)return null;if(m[0]!==x||m[1]!==h){let e=h.filter(e1).length;l="drTransfers noDrag",n="drTrHead",s=x("drive.transfers.tag","TRANSFERS · {{status}}",{status:e?x("drive.transfers.uploadingCount","{{count}} uploading",{count:e}):x("drive.transfers.done","done")}),m[0]=x,m[1]=h,m[2]=s,m[3]=n,m[4]=l}else s=m[2],n=m[3],l=m[4];if(m[5]!==s?(i=(0,t.jsx)("span",{children:s}),m[5]=s,m[6]=i):i=m[6],m[7]!==x?(r=x("drive.clear","Clear"),m[7]=x,m[8]=r):r=m[8],m[9]!==f||m[10]!==r?(o=(0,t.jsx)("button",{onClick:f,children:r}),m[9]=f,m[10]=r,m[11]=o):o=m[11],m[12]!==n||m[13]!==i||m[14]!==o?(d=(0,t.jsxs)("div",{className:n,children:[i,o]}),m[12]=n,m[13]=i,m[14]=o,m[15]=d):d=m[15],m[16]!==p||m[17]!==g||m[18]!==x||m[19]!==h){let e;m[21]!==p||m[22]!==g||m[23]!==x?(e=e=>(0,t.jsxs)("div",{className:`drTrRow ${e.status}`,children:[(0,t.jsx)("span",{className:"drTrName",children:e.filename}),(0,t.jsx)("span",{className:"drTrSize",children:(0,em.fmtSize)(e.f
24ileSize)}),("uploading"===e.status||"queued"===e.status)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"drTrBar",children:(0,t.jsx)("span",{style:{width:`${e.progress}%`,animation:"none"}})}),(0,t.jsx)("span",{className:"drTrSize",children:"queued"===e.status?x("drive.transfers.queued","queued"):`${e.progress}%`}),(0,t.jsx)("button",{onClick:()=>p(e.id),children:x("drive.cancel","Cancel")})]}),"done"===e.status&&(0,t.jsx)("span",{className:"drTrOk",style:{display:"inline-block",width:7,height:7,background:"var(--ink)"}}),"error"===e.status&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"drTrErr",title:e.errorMessage??void 0,children:x("drive.transfers.failed","failed")}),(0,t.jsx)("button",{onClick:()=>g(e.id),children:x("drive.retry","Retry")})]})]},e.id),m[21]=p,m[22]=g,m[23]=x,m[24]=e):e=m[24],c=h.map(e),m[16]=p,m[17]=g,m[18]=x,m[19]=h,m[20]=c}else c=m[20];return m[25]!==l||m[26]!==d||m[27]!==c?(u=(0,t.jsxs)("div",{className:l,children:[d,c]}),m[25]=l,m[26]=d,m[27]=c,m[28]=u):u=m[28],u}function e1(e){return"uploading"===e.status||"queued"===e.status}var e2=e.i(770633),e3=e.i(907915);let e4={fontSize:12,fontWeight:300,opacity:.55},e5={fontSize:11,fontWeight:300,opacity:.5,lineHeight:1.4};function e6(e){let s,n,l,i=(0,a.c)(6),{tags:r}=e;if(!r.length){let e;return i[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,t.jsx)("span",{style:e4,children:"â"}),i[0]=e):e=i[0],e}return i[1]===Symbol.for("react.memo_cache_sentinel")?(s={display:"inline-flex",gap:4},i[1]=s):s=i[1],i[2]!==r?(n=r.map(e7),i[2]=r,i[3]=n):n=i[3],i[4]!==n?(l=(0,t.jsx)("span",{style:s,children:n}),i[4]=n,i[5]=l):l=i[5],l}function e7(e){return(0,t.jsx)("span",{style:{width:8,height:8,borderRadius:99,background:ej.TAG_HEX[e],display:"inline-block"}},e)}function e8(e){let s,n,l=(0,a.c)(3),{children:i}=e;return l[0]===Symbol.for("react.memo_cache_sentinel")?(s={padding:"14px 0",...e4},l[0]=s):s=l[0],l[1]!==i?(n=(0,t.jsx)("div",{style:s,children:i}),l[1]=i,l[2]=n):n=l[2],n}function e9({roomId:e,file:a}){let{t:n}=(0,F.useTranslation)("paletteOs"),l=(0,e2.useDataRoomAI)(),[i,r]=(0,s.useState)(null),[o,d]=(0,s.useState)(!0),[c,u]=(0,s.useState)(null),m=(0,s.useCallback)(async t=>{d(!0),u(null);try{r(await l.summarizeFile(e,a.id,t))}catch{u(n("drive.ai.summaryFailed","Summary failed. The file may not be indexed yet."))}finally{d(!1)}},[l,e,a.id,n]);return(0,s.useEffect)(()=>{let t=!0;return l.fetchSummary(e,a.id).then(e=>{t&&(e?.summary?(r(e),d(!1)):m(!1))}).catch(()=>{t&&m(!1)}),()=>{t=!1}},[e,a.id]),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dTag",children:[(0,t.jsx)("span",{children:n("drive.ai.summaryTag","AI · SUMMARY")}),(0,t.jsx)("span",{className:"idx",children:(0,em.fmtSize)(a.file_size)})]}),(0,t.jsxs)("div",{className:"dBody",children:[(0,t.jsx)("h3",{style:{fontSize:15,fontWeight:600,lineHeight:1.3,wordBreak:"break-all"},children:a.original_filename}),o&&(0,t.jsx)(e8,{children:n("drive.ai.summarising","Summarisingâ¦")}),c&&(0,t.jsx)(e8,{children:c}),!o&&i&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{style:{fontSize:13,fontWeight:300,lineHeight:1.6,whiteSpace:"pre-wrap"},children:i.summary}),(0,t.jsxs)("div",{style:e4,children:[i.cached?n("drive.ai.cached","cached"):n("drive.ai.fresh","fresh")," · ",i.model]})]}),(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn po-btn--ghost",disabled:o,onClick:()=>void m(!0),children:n("drive.regenerate","Regenerate")})})]})]})}function te({roomId:e,file:a,onRename:n}){let{t:l}=(0,F.useTranslation)("paletteOs"),i=(0,e2.useDataRoomAI)(),{closeDrawer:r}=(0,ec.useViewContext)(),[o,d]=(0,s.useState)(null),[c,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0),[p,g]=(0,s.useState)(null);(0,s.useEffect)(()=>{let t=!0;return i.suggestRenames(e,[a.id]).then(e=>{if(!t)return;let a=e[0]??null;d(a),u(a?.suggested_name??""),h(!1)}).catch(()=>{t&&(g(l("drive.ai.suggestionFailed","Suggestion failed.")),h(!1))}),()=>{t=!1}},[e,a.id]);let f=async()=>{let e=c.trim();if(e){h(!0);try{await n(e),r()}finally{h(!1)}}};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"dTag",children:(0,t.jsx)("span",{children:l("drive.ai.renameTag","AI · RENAME")})}),(0,t.jsxs)("div",{className:"dBody",children:[(0,t.jsx)("div",{style:e4,children:l("drive.ai.current","Current")}),(0,t.jsx)("div",{style:{fontSize:13,wordBreak:"break-all"},children:a.original_filename}),m&&!o&&(0,t.jsx)(e8,{children:l("drive.ai.thinking","Thinkingâ¦")}),p&&(0,t.jsx)(e8,{children:p}),o&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{style:{...e4,marginTop:10},children:l("drive.ai.suggested","Suggested")}),(0,t.jsx)("input",{className:"poInput",value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&f()}}),(0,t.jsx)("p",{style:e5,children:o.reason}),(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn",disabled:m||!c.trim(),onClick:()=>void f(),children:l("drive.contextMenu.rename","Rename")})})]}
24),!m&&!p&&!o&&(0,t.jsx)(e8,{children:l("drive.ai.noSuggestion","No suggestion â the name looks fine.")})]})]})}function tt({roomId:e,fileIds:a,folderIds:n,onApply:l,onDone:i}){let{t:r}=(0,F.useTranslation)("paletteOs"),o=(0,e2.useDataRoomAI)(),{closeDrawer:d}=(0,ec.useViewContext)(),[c,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(!0),[f,x]=(0,s.useState)(null);(0,s.useEffect)(()=>{let t=!0;return o.suggestTags(e,a,n,!1).then(e=>{t&&(u(e),h(new Set(e.suggestions.map(e=>`${e.item_type}:${e.item_id}`))),g(!1))}).catch(()=>{t&&(x(r("drive.ai.tagsFailed","Tag suggestion failed.")),g(!1))}),()=>{t=!1}},[e]);let b=async()=>{if(c){g(!0);try{for(let e of c.suggestions)m.has(`${e.item_type}:${e.item_id}`)&&await l(e.item_type,e.item_id,e.suggested_tags);i(),d()}finally{g(!1)}}};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"dTag",children:(0,t.jsx)("span",{children:r("drive.ai.tagsTag","AI · TAGS")})}),(0,t.jsxs)("div",{className:"dBody",children:[p&&!c&&(0,t.jsx)(e8,{children:r("drive.ai.readingContents","Reading contentsâ¦")}),f&&(0,t.jsx)(e8,{children:f}),c?.suggestions.map(e=>{let a=`${e.item_type}:${e.item_id}`,s=m.has(a);return(0,t.jsxs)("label",{style:{display:"flex",gap:10,alignItems:"flex-start",borderBottom:"1px solid var(--line)",padding:"8px 0",cursor:"pointer"},children:[(0,t.jsx)("input",{type:"checkbox",className:"drChk",checked:s,onChange:()=>h(e=>{let t=new Set(e);return s?t.delete(a):t.add(a),t})}),(0,t.jsxs)("span",{style:{minWidth:0},children:[(0,t.jsx)("span",{style:{fontSize:12.5,display:"block",wordBreak:"break-all"},children:e.name}),(0,t.jsxs)("span",{style:{display:"flex",gap:8,alignItems:"center",marginTop:3},children:[(0,t.jsx)(e6,{tags:e.current_tags}),(0,t.jsx)("span",{style:e4,children:"â"}),(0,t.jsx)(e6,{tags:e.suggested_tags})]}),(0,t.jsx)("span",{style:e5,children:e.reason})]})]},a)}),c&&0===c.suggestions.length&&(0,t.jsx)(e8,{children:r("drive.ai.nothingToTag","Nothing to tag.")}),c&&c.suggestions.length>0&&(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn",disabled:p||0===m.size,onClick:()=>void b(),children:1===m.size?r("drive.ai.applySuggestionsOne","Apply {{count}} suggestion",{count:m.size}):r("drive.ai.applySuggestions","Apply {{count}} suggestions",{count:m.size})})})]})]})}function ta({roomId:e,folderId:a,canEdit:n,onTrash:l,onDone:i}){let{t:r}=(0,F.useTranslation)("paletteOs"),o=(0,e2.useDataRoomAI)(),{closeDrawer:d,openConfirm:c}=(0,ec.useViewContext)(),[u,m]=(0,s.useState)(null),[h,p]=(0,s.use
24State)(new Set),[g,f]=(0,s.useState)(!0),[x,b]=(0,s.useState)(null);(0,s.useEffect)(()=>{let t=!0;return o.findDuplicates(e,a).then(e=>{t&&(m(e),p(new Set(e.exact.flatMap(e=>e.files.slice(1).map(e=>e.id)))),f(!1))}).catch(()=>{t&&(b(r("drive.ai.duplicatesFailed","Duplicate scan failed.")),f(!1))}),()=>{t=!1}},[e,a]);let v=(e,a)=>(0,t.jsxs)("div",{style:{borderBottom:"1px solid var(--line)",padding:"8px 0"},children:[(0,t.jsx)("div",{style:{...e4,marginBottom:4},children:e}),a.map(e=>(0,t.jsxs)("label",{style:{display:"flex",gap:10,alignItems:"center",padding:"3px 0",cursor:n?"pointer":"default"},children:[n&&(0,t.jsx)("input",{type:"checkbox",className:"drChk",checked:h.has(e.id),onChange:()=>{let t;return t=e.id,p(e=>{let a=new Set(e);return a.has(t)?a.delete(t):a.add(t),a})}}),(0,t.jsx)("span",{style:{fontSize:12.5,flex:1,minWidth:0,wordBreak:"break-all"},children:e.original_filename}),(0,t.jsx)("span",{style:e4,children:(0,em.fmtSize)(e.file_size)})]},e.id))]});return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"dTag",children:(0,t.jsx)("span",{children:r("drive.ai.duplicatesTag","AI · DUPLICATES")})}),(0,t.jsxs)("div",{className:"dBody",children:[g&&(0,t.jsx)(e8,{children:r("drive.ai.scanning","Scanningâ¦")}),x&&(0,t.jsx)(e8,{children:x}),u&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{style:e4,children:r("drive.ai.scanSummary","{{scanned}} scanned · {{exact}} exact group(s) · {{similar}} similar group(s)",{scanned:u.scanned,exact:u.exact.length,similar:u.similar.length})}),u.exact.map(e=>(0,t.jsx)("div",{children:v(r("drive.ai.exactMatch","Exact match · {{size}}",{size:(0,em.fmtSize)(e.file_size)}),e.files)},e.hash)),u.similar.map((e,a)=>(0,t.jsx)("div",{children:v(e.reason,e.files)},a)),0===u.exact.length&&0===u.similar.length&&(0,t.jsx)(e8,{children:r("drive.ai.noDuplicates","No duplicates found.")}),n&&h.size>0&&(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn po-btn--danger",onClick:()=>{c({title:r("drive.confirm.trashDuplicatesTitle","Trash duplicates?"),desc:r("drive.confirm.trashFilesDesc","{{count}} file(s) move to Trash.",{count:h.size}),danger:!0,confirmLabel:r("drive.confirm.trash","Trash"),onConfirm:async()=>{await l([...h]),i(),d()}})},children:r("drive.ai.trashSelected","Trash {{count}} selected",{count:h.size})})})]})]})]})}function ts({roomId:e,folderId:a,scopeName:n,onOpenDuplicates:l,onOpenDigest:i}){let{t:r}=(0,F.useTranslation)("paletteOs"),[o,d]=(0,s.useState)(null),[c,u]=(0,s.useState)(null);(0,s.useEffect)(()=>{let t=!0,s=null==a?"":`?folder_id=${a}`;return(0,er.apiFetch)(`/api/v1/data-rooms/${e}/ai/health${s}`).then(e=>e.json()).then(e=>{t&&d(e)}).catch(()=>{t&&u(r("drive.ai.healthFailed","Health check failed."))}),()=>{t=!1}},[e,a]);let m=(e,a)=>(0,t.jsxs)("div",{className:"drRow",children:[(0,t.jsx)("span",{style:{flex:1},children:e}),(0,t.jsx)("span",{style:{fontFamily:"var(--mono)",fontSize:12},children:a})]});return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dTag",children:[(0,t.jsx)("span",{children:r("drive.ai.healthTag","AI · HEALTH")}),(0,t.jsx)("span",{className:"idx",children:n})]}),(0,t.jsxs)("div",{className:"dBody",children:[!o&&!c&&(0,t.jsx)(e8,{children:r("drive.ai.checking","Checkingâ¦")}),c&&(0,t.jsx)(e8,{children:c}),o&&(0,t.jsxs)(t.Fragment,{children:[m(r("drive.ai.totalFiles","Total files"),o.total_files),m(r("drive.ai.duplicates","Duplicates"),o.duplicates),m(r("drive.ai.poorNames","Poor names"),o.poor_names),m(r("drive.ai.untagged","Untagged"),o.untagged),m(r("drive.ai.unsummarized","Unsummarized"),o.unsummarized),m(r("drive.ai.indexingFailed","Indexing failed"),o.indexing_failed),(0,t.jsxs)("div",{style:{display:"flex",gap:8,marginTop:14,flexWrap:"wrap"},children:[(0,t.jsx)("button",{className:"po-btn po-btn--ghost",onClick:l,children:r("drive.ai.duplicatesLink","Duplicates â")}),(0,t.jsx)("button",{className:"po-btn po-btn--ghost",onClick:i,children:r("drive.ai.digestLink","Digest â")})]})]})]})]})}function tn({roomId:e,folderId:a,scopeName:n}){let{t:l}=(0,F.useTranslation)("paletteOs"),i=(0,e2.useDataRoomAI)(),[r,o]=(0,s.use
24State)(null),[d,c]=(0,s.useState)(!0),[u,m]=(0,s.useState)(null),h=(0,s.useCallback)(async t=>{c(!0),m(null);try{o(await i.createDigest(e,a,t))}catch{m(l("drive.ai.digestFailed","Digest failed. Files may still be indexing."))}finally{c(!1)}},[i,e,a,l]);(0,s.useEffect)(()=>{let t=!0;return i.fetchDigest(e,a).then(e=>{t&&(e?.summary?(o(e),c(!1)):h(!1))}).catch(()=>{t&&h(!1)}),()=>{t=!1}},[e,a]);let p=(e,a)=>a.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{style:{...e4,marginTop:10},children:e}),a.map((e,a)=>(0,t.jsxs)("div",{style:{fontSize:12.5,fontWeight:300,lineHeight:1.5,padding:"2px 0"},children:["· ",e]},a))]});return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dTag",children:[(0,t.jsx)("span",{children:l("drive.ai.digestTag","AI · DIGEST")}),(0,t.jsx)("span",{className:"idx",children:n})]}),(0,t.jsxs)("div",{className:"dBody",children:[d&&(0,t.jsx)(e8,{children:l("drive.ai.readingRoom","Reading the driveâ¦")}),u&&(0,t.jsx)(e8,{children:u}),!d&&r&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{style:{fontSize:13,fontWeight:300,lineHeight:1.6,whiteSpace:"pre-wrap"},children:r.summary}),r.key_documents.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{style:{...e4,marginTop:10},children:l("drive.ai.keyDocuments","Key documents")}),r.key_documents.map(e=>(0,t.jsxs)("div",{style:{borderBottom:"1px solid var(--line)",padding:"6px 0"},children:[(0,t.jsx)("div",{style:{fontSize:12.5,wordBreak:"break-all"},children:e.name}),(0,t.jsx)("div",{style:e5,children:e.summary})]},e.file_id))]}),p(l("drive.ai.risks","Risks"),r.risks),p(l("drive.ai.suggestedActions","Suggested actions"),r.suggested_actions),(0,t.jsxs)("div",{style:{...e4,marginTop:8},children:[r.cached?l("drive.ai.cached","cached"):l("drive.ai.fresh","fresh")," · ",new Date(r.generated_at).toLocaleString()]}),(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn po-btn--ghost",onClick:()=>void h(!0),children:l("drive.regenerate","Regenerate")})})]})]})]})}function tl({roomId:e,folderId:a,folderName:n,onApplied:l}){let{t:i}=(0,F.useTranslation)("paletteOs"),r=(0,e3.useAIOrganise)(e),{closeDrawer:o}=(0,ec.useViewContext)(),[d,c]=(0,s.useState)(""),u=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{u.current||(u.current=!0,r.open({folderId:a,folderName:n}))},[]),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dTag",children:[(0,t.jsx)("span",{children:i("drive.ai.organiseTag","AI · ORGANISE")}),(0,t.jsx)("span",{className:"idx",children:n??i("drive.ai.wholeRoomScope","Whole drive")}
24)]}),(0,t.jsxs)("div",{className:"dBody",children:["configure"===r.phase&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{style:e4,children:i("drive.ai.organiseIntro","AI reads the files in scope and proposes folder moves. Nothing moves until you apply.")}),(0,t.jsx)("div",{style:{...e4,marginTop:8},children:i("drive.ai.instructionsOptional","Instructions (optional)")}),(0,t.jsx)("textarea",{className:"poInput",rows:3,value:d,onChange:e=>c(e.target.value),placeholder:i("drive.ai.instructionsPlaceholder","e.g. group by client, keep contracts together"),style:{resize:"none"}}),(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn",onClick:()=>void r.start({instructions:d.trim()||void 0}),children:i("drive.ai.analyse","Analyse")})})]}),"analysing"===r.phase&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(e8,{children:[i("drive.ai.analysing","Analysingâ¦")," ",r.total>0?`${r.progress}/${r.total}`:""]}),(0,t.jsx)("button",{className:"po-btn po-btn--ghost",onClick:()=>void r.cancel(),children:i("drive.cancel","Cancel")})]}),"review"===r.phase&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{style:e4,children:i("drive.ai.proposedMoves","{{count}} proposed move(s) â untick to skip.",{count:r.moves.length})}),r.moves.map(e=>{let a=r.selected.has(e.file_id);return(0,t.jsxs)("label",{style:{display:"flex",gap:10,alignItems:"flex-start",borderBottom:"1px solid var(--line)",padding:"8px 0",cursor:"pointer"},children:[(0,t.jsx)("input",{type:"checkbox",className:"drChk",checked:a,onChange:()=>r.toggleMove(e.file_id)}),(0,t.jsxs)("span",{style:{minWidth:0},children:[(0,t.jsx)("span",{style:{fontSize:12.5,display:"block",wordBreak:"break-all"},children:e.file_name}),(0,t.jsxs)("span",{style:{...e4,display:"block"},children:["â ",e.new_folder_name??e.target_folder_path??"?"," · ",e.confidence]}),(0,t.jsx)("span",{style:e5,children:e.reason})]})]},e.file_id)}),0===r.moves.length&&(0,t.jsx)(e8,{children:i("drive.ai.nothingToMove","Nothing to move â already organised.")}),r.moves.length>0&&(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn",disabled:0===r.selected.size,onClick:()=>void r.apply(),children:1===r.selected.size?i("drive.ai.applyMovesOne","Apply {{count}} move",{count:r.selected.size}):i("drive.ai.applyMoves","Apply {{count}} moves",{count:r.selected.size})})})]}),"applying"===r.phase&&(0,t.jsx)(e8,{children:i("drive.ai.movingFiles","Moving filesâ¦")}),"done"===r.phase&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e8,{children:(r.result?.folders_created.length??0)>0?i("drive.ai.movedFilesCreated","Moved {{count}} file(s), created {{folders}} folder(s).",{count:r.result?.moved??0,folders:r.result.folders_created.length}):i("drive.ai.movedFiles","Moved {{count}} file(s).",{count:r.result?.moved??0})}),(0,t.jsx)("button",{className:"po-btn",onClick:()=>{l(),o()},children:i("drive.done","Done")})]}),"error"===r.phase&&(0,t.jsx)(e8,{children:r.error??i("drive.ai.organiseFailed","Organise failed.")})]})]})}function ti({roomId:e,fileIds:a,onApplied:n}){let{t:l}=(0,F.useTranslation)("paletteOs"),i=(0,e2.useDataRoomAI)(),{closeDrawer:r}=(0,ec.useViewContext)(),[o,d]=(0,s.useState)(null),[c,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(null),[f,x]=(0,s.use
24State)(!1);(0,s.useEffect)(()=>{let t=!0,s=null,n=async a=>{try{let i=await (0,er.apiFetch)(`/api/v1/data-rooms/${e}/ai/jobs/${a}`),r=await i.json();if(!t)return;if(d(r),"completed"===r.status){let e=r.result;u(e),h(new Set(e.items.filter(e=>e.rename||e.tags||e.summary_suggested).map(e=>e.file.id)))}else"failed"===r.status?g(r.error??l("drive.ai.reviewFailed","Review failed.")):s=setTimeout(()=>void n(a),2e3)}catch{t&&g(l("drive.ai.reviewFailed","Review failed."))}};return i.createIngestionReview(e,a,null).then(e=>{t&&(d(e),n(e.job_id))}).catch(()=>{t&&g(l("drive.ai.reviewFailed","Review failed."))}),()=>{t=!1,s&&clearTimeout(s)}},[e]);let b=async()=>{if(c&&o){x(!0);try{let t=c.items.filter(e=>m.has(e.file.id)).map(e=>({file_id:e.file.id,rename_to:e.rename?.suggested_name??null,tags:e.tags?.suggested_tags??null,generate_summary:e.summary_suggested}));await i.applyIngestionReview(e,o.job_id,t),n(),r()}catch{g(l("drive.ai.applyFailed","Apply failed."))}finally{x(!1)}}};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"dTag",children:(0,t.jsx)("span",{children:l("drive.ai.reviewTag","AI · REVIEW")})}),(0,t.jsxs)("div",{className:"dBody",children:[!c&&!p&&(0,t.jsxs)(e8,{children:[l("drive.ai.reviewing","Reviewing {{count}} file(s)â¦",{count:a.length})," ",o&&o.total>0?`${o.progress}/${o.total}`:""]}),p&&(0,t.jsx)(e8,{children:p}),c?.items.map(e=>{let a=m.has(e.file.id),s=[e.rename?l("drive.ai.changeRename","rename â {{name}}",{name:e.rename.suggested_name}):null,e.tags?l("drive.ai.changeTags","tags"):null,e.summary_suggested?l("drive.ai.changeSummary","summary"):null].filter(Boolean).join(" · ");return(0,t.jsxs)("label",{style:{display:"flex",gap:10,alignItems:"flex-start",borderBottom:"1px solid var(--line)",padding:"8px 0",cursor:"pointer"},children:[(0,t.jsx)("input",{type:"checkbox",className:"drChk",checked:a,disabled:!s,onChange:()=>h(t=>{let s=new Set(t);return a?s.delete(e.file.id):s.add(e.file.id),s})}),(0,t.jsxs)("span",{style:{minWidth:0},children:[(0,t.jsx)("span",{style:{fontSize:12.5,display:"block",wordBreak:"break-all"},children:e.file.original_filename}),(0,t.jsx)("span",{style:{...e4,display:"block"},children:s||l("drive.ai.nothingToDo","nothing to do")}),e.summary&&(0,t.jsx)("span",{style:e5,children:e.summary})]})]},e.file.id)}),c&&(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("button",{className:"po-btn",disabled:f||0===m.size,onClick:()=>void b(),children:1===m.size?l("drive.ai.applyToFilesOne","Apply to {{count}} file",{count:m.size}):l("drive.ai.applyToFiles","Apply to {{count}} files",{count:m.size})})})]})]})}var tr=e.i(464319);function to(e){let s,n,l,i,r,o=(0,a.c)(9),{roomId:d,roomName:c}=e;return o[0]!==c?(s=(0,t.jsx)("div",{className:"dTag",children:(0,t.jsxs)("span",{children:["DRIVE · KNOWLEDGE GRAPH · ",c]})}),o[0]=c,o[1]=s):s=o[1],o[2]===Symbol.for("react.memo_cache_sentinel")?(n={display:"flex",flexDirection:"column",flex:1,minHeight:0},l={flex:1,minHeight:480},o[2]=n,o[3]=l):(n=o[2],l=o[3]),o[4]!==d?(i=(0,t.jsx)("div",{className:"dBody",style:n,children:(0,t.jsx)("div",{style:l,children:(0,t.jsx)(tr.GraphView,{roomId:d})})}),o[4]=d,o[5]=i):i=o[5],o[6]!==s||o[7]!==i?(r=(0,t.jsxs)(t.Fragment,{children:[s,i]}),o[6]=s,o[7]=i,o[8]=r):r=o[8],r}function td({roomId:e,roomName:a,onClose:n}){let{t:l}=(0,F.useTranslation)("paletteOs"),{openDrawer:i,setView:r}=(0,ec.useViewContext)(),[o,d]=(0,s.useState)(null),[c,u]=(0,s.useState)("loading");(0,s.useEffect)(()=>{if(null==e){d(null),u("ready");return}let t=!1;return u("loading"),(async()=>{try{let a=await (0,er.apiFetch)(`/api/v1/data-rooms/${e}/graph`);if(!a.ok)throw Error(String(a.status));let s=await a.json();t||(d(s),u("ready"))}catch{t||u("error")}})(),()=>{t=!0}},[e]);let m=o?.nodes??[];return(0,t.jsxs)("aside",{className:"drMemPanel","aria-label":l("drive.memTitle","Knowledge graph for this drive"),children:[(0,t.jsxs)("div",{className:"drMemHead",children:[(0,t.jsx)(ey.Glyph,{name:"memory2"}),(0,t.jsx)("span",{className:"drMemHeadT",children:l("drive.memHead","Memory")}),(0,t.jsx)("button",{type:"button",className:"drMemX",onClick:n,"aria-label":l("drive.close","Close"),children:"Ã"})]}),(0,t.jsxs)("div",{className:"drMemCtx",children:[(0,t.jsx)("div",{className:"drMemCtxLbl",children:l("drive.memContext","CONTEXT")}),(0,t.jsxs)("div",{className:"drMemCtxRow",children:[(0,t.jsx)("span",{className:"drMemCtxName",children:a}),(0,t.jsx)("span",{className:"drMemRel",children:o?l("drive.memRel","{{count}} REL",{count:o.stats.relationships}):"â"})]})]}),(0,t.jsxs)("div",{className:"drMemBody",children:["loading"===c&&(0,t.jsx)("div",{className:"drMemEmpty",children:l("drive.loading","Loadingâ¦")}),"error"===c&&(0,t.jsx)("div",{className:"drMemEmpty",children:l("drive.memError","The graph could not be loaded for this drive.")}),"ready"===c&&null==e&&(0,t.jsx)("div",{className:"drMemEmpty",children:l("drive.memNoRoom","Pick a drive to see its knowledge graph.")}),"ready"===c&&null!=e&&!m.length&&(0,t.jsx)("div",{className:"drMemEmpty",children:l("drive.memEmpty","Nothing indexed yet â upload files and their entities appear here.")}),m.slice(0,60).map(s=>{let n;return(0,t.jsxs)("button",{type:"button",className:"drMemNode",onClick:()=>{null!=e&&i({content:(0,t.jsx)(to,{roomId:e,roomName:a}),wide:!0})},children:[(0,t.jsx)("span",{className:`drMemKind${"file"===s.kind?" file":""}`,children:"file"===s.kind?l("drive.memKindFile","DOC"):l("drive.memKindEntity","ENT")}),(0,t.jsxs)("span",{className:"drMemNodeMain",children:[(0,t.jsx)("span",{className:"drMemNodeT",children:s.label}),(0,t.jsx)("span",{className:"drMemNodeN",children:s.summary||l("drive.memNoSummary","No summary")}
24)]}),(0,t.jsx)("span",{className:"drMemLinks",children:(n=s.id,(o?.links??[]).filter(e=>e.source===n||e.target===n).length)})]},s.id)})]}),(0,t.jsx)("div",{className:"drMemFoot",children:(0,t.jsx)("button",{type:"button",className:"drMemFull",onClick:()=>r("memory2"),children:l("drive.memFull","OPEN FULL GRAPH")})})]})}var tc=e.i(13080),tu=e.i(993253),tm=e.i(762603),th=e.i(173623);let tp=["view","upload","edit"],tg=e=>e.trim().split(/[\s@._-]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join("")||"?";function tf(e){let s,n,l,i,r=(0,a.c)(11),{value:o,onChange:d}=e,{t:c}=(0,F.useTranslation)("paletteOs");return r[0]!==d?(s=e=>d(e.target.value),r[0]=d,r[1]=s):s=r[1],r[2]!==c?(n=c("drive.share.permission","Permission"),r[2]=c,r[3]=n):n=r[3],r[4]!==c?(l=tp.map(e=>(0,t.jsx)("option",{value:e,children:c(`dataRoom:share.permission.${e}`)},e)),r[4]=c,r[5]=l):l=r[5],r[6]!==s||r[7]!==n||r[8]!==l||r[9]!==o?(i=(0,t.jsx)("select",{className:"poInput drShareSel",value:o,onChange:s,"aria-label":n,children:l}),r[6]=s,r[7]=n,r[8]=l,r[9]=o,r[10]=i):i=r[10],i}function tx({roomId:e,roomName:a,onClose:n,onChanged:l,fallbackFocus:i}){let{t:r}=(0,F.useTranslation)("paletteOs"),{user:o}=(0,tc.useAuth)(),{shares:d,loading:c,error:u,fetchShares:m,addShare:h,updateShare:p,removeShare:g}=(0,tu.useDataRoomShares)(),{members:f,loading:x,error:b,refetch:v}=(0,tm.useOrgMembers)(),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)("view"),[N,C]=(0,s.useState)(null),S=(0,s.useRef)(null),_=(0,s.useRef)(!1),T=(0,s.useRef)(!1),E=(0,s.useRef)(!0),[A,R]=(0,s.use
24State)(!1);(0,s.useEffect)(()=>(E.current=!0,()=>{E.current=!1}),[]),(0,s.useEffect)(()=>{!A&&_.current&&(_.current=!1,S.current?.focus())},[A]);let D=()=>{T.current||n()};(0,s.useEffect)(()=>{m(e)},[e,m]);let M=d.find(e=>null===e.user_id),I=d.filter(e=>null!==e.user_id),O=new Set(I.map(e=>e.user_id)),P=j.trim().toLowerCase(),L=P?f.filter(e=>e.is_active&&e.id!==o?.id&&!O.has(e.id)&&(e.name.toLowerCase().includes(P)||e.email.toLowerCase().includes(P))).slice(0,8):[],$=async(e,t=!1)=>{if(!T.current&&!c&&!u){T.current=!0,R(!0),C(null);try{await e(),E.current&&(t&&(y(""),_.current=!0),l?.())}catch{E.current&&C(r("drive.share.failed"))}finally{T.current=!1,E.current&&R(!1)}}};return(0,t.jsx)(th.ConversationDialog,{title:r("dataRoom:share.title",{name:a}),onClose:D,fallbackFocus:i,initialFocus:S,busy:A,children:(0,t.jsxs)("div",{className:"drShare","aria-busy":A||c,children:[(0,t.jsx)("div",{className:"drShareLegend",children:tp.map(e=>(0,t.jsxs)("div",{className:"drShareTier",children:[(0,t.jsx)("b",{children:r(`dataRoom:share.permission.${e}`)}),(0,t.jsx)("span",{children:r(`drive.share.tier.${e}`)})]},e))}),c?(0,t.jsx)("p",{className:"ssDlgP",role:"status",children:r("drive.share.loading")}):u?(0,t.jsxs)("div",{role:"alert",children:[(0,t.jsx)("p",{className:"ssDlgP",children:r("drive.share.loadFailed")}),(0,t.jsx)("button",{className:"cfBtn",onClick:()=>{m(e)},children:r("drive.share.retry")})]}):(0,t.jsxs)("fieldset",{disabled:A,className:"drShareControls",children:[(0,t.jsxs)("section",{className:"drShareSec",children:[(0,t.jsx)("div",{className:"drShareSecHd",children:r("dataRoom:share.orgWideAccess")}),(0,t.jsxs)("div",{className:"drShareRow",children:[(0,t.jsx)("div",{className:"drShareAv org",children:(0,t.jsx)(ey.Glyph,{name:"h_globe"})}),(0,t.jsxs)("div",{className:"drShareWho",children:[(0,t.jsx)("b",{children:r("dataRoom:share.orgWideToggle")}),(0,t.jsx)("span",{children:M?r("drive.share.orgOn","Every member of your workspace can open this drive."):r("drive.share.orgOff","Only you and the people listed below have access.")})]}),M&&(0,t.jsx)(tf,{value:M.permission,onChange:t=>{$(()=>p(e,M.id,t))}}),(0,t.jsx)("button",{className:"cfBtn",onClick:()=>{$(()=>M?g(e,M.id):h(e,null,"view"))},children:M?r("drive.share.remove","Remove"):r("drive.share.add","Share")})]})]}),(0,t.jsxs)("section",{className:"drShareSec",children:[(0,t.jsx)("div",{className:"drShareSecHd",children:r("dataRoom:share.shareWithPeople")}),(0,t.jsxs)("div",{className:"drShareFind",children:[(0,t.jsxs)("div",{className:"drShareFindBox poSearch",children:[(0,t.jsx)(ey.Glyph,{name:"h_search"}),(0,t.jsx)("input",{ref:S,"aria-label":r("dataRoom:share.searchPlaceholder"),disabled:x||b,placeholder:r("dataRoom:share.searchPlaceholder"),value:j,onChange:e=>y(e.target.value)})]}),(0,t.jsx)(tf,{value:w,onChange:k}),x&&(0,t.jsx)("p",{className:"ssDlgP",role:"status",children:r("drive.share.membersLoading")}),b&&(0,t.jsxs)("div",{role:"alert",children:[(0,t.jsx)("p",{className:"ssDlgP",children:r("drive.share.membersFailed")}),(0,t.jsx)("button",{className:"cfBtn",onClick:()=>{v()},children:r("drive.share.retry")})]}),P&&!x&&!b&&(0,t.jsxs)("div",{className:"drShareHits",children:[0===L.length&&(0,t.jsx)("div",{className:"drShareNone",children:r("dataRoom:share.noMembersFound")}),L.map(a=>(0,t.jsxs)("button",{type:"button",className:"drShareHit",onClick:()=>{$(()=>h(e,a.id,w),!0)},children:[(0,t.jsx)("span",{className:"drShareAv",children:tg(a.name||a.email)}),(0,t.jsxs)("span",{className:"drShareWho",children:[(0,t.jsx)("b",{children:a.name}),(0,t.jsx)("span",{children:a.email})]}),(0,t.jsx)("span",{className:"drShareHitAdd",children:r("drive.share.add","Share")})]},a.id))]})]}),(0,t.jsx)("div",{className:"drShareSecHd",style:{marginTop:6},children:r("dataRoom:share.peopleWithAccess")}),0===I.length&&(0,t.jsx)("p",{className:"ssDlgP",children:r("drive.share.nobody","No one else yet. Search above to add a member.")}),I.map(a=>(0,t.jsxs)("div",{className:"drShareRow",children:[(0,t.jsx)("div",{className:"drShareAv",children:tg(a.user_name??a.user_email??"?")}),(0,t.jsxs)("div",{className:"drShareWho",children:[(0,t.jsx)("b",{children:a.user_name??a.user_email}),(0,t.jsx)("span",{children:a.user_email})]}),(0,t.jsx)(tf,{value:a.permission,onChange:t=>{$(()=>p(e,a.id,t))}}),(0,t.jsx)("button",{className:"cfBtn",onClick:()=>{$(()=>g(e,a.id))},children:r("drive.share.remove","Remove")})]},a.id))]})]}),N&&(0,t.jsx)("p",{className:"ssProjectError",role:"alert",children:N}),(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{className:"cfBtn",disabled:A,onClick:D,children:r("drive.share.done","Done")})})]})})}function tb({title:e,current:a="",saveLabel:n,note:l,fallbackFocus:i,onSave:r,onClose:o}){let{t:d}=(0,F.useTranslation)("paletteOs"),c=(0,s.useId)(),u=(0,s.useRef)(null),m=(0,s.useRef)(!1),h=(0,s.useRef)(!0),[p,g]=(0,s.use
24State)(a),[f,x]=(0,s.useState)(!1),[b,v]=(0,s.useState)("");(0,s.useEffect)(()=>(h.current=!0,()=>{h.current=!1}),[]);let j=()=>{m.current||o()},y=async()=>{let e=p.trim();if(e&&!m.current){m.current=!0,x(!0),v("");try{await r(e),h.current&&o()}catch(e){h.current&&v(e instanceof Error&&e.message?e.message:d("drive.h.nameFailed","Could not save the name. Try again."))}finally{m.current=!1,h.current&&x(!1)}}};return(0,t.jsxs)(th.ConversationDialog,{title:e,onClose:j,fallbackFocus:i,initialFocus:u,busy:f,children:[l&&(0,t.jsx)("p",{className:"ssDlgP",children:l}),(0,t.jsxs)("form",{className:"ssProjectForm",onSubmit:e=>{e.preventDefault(),y()},children:[(0,t.jsx)("label",{htmlFor:c,children:d("drive.h.nameValue","Name / value")}),(0,t.jsx)("input",{ref:u,id:c,value:p,maxLength:255,required:!0,disabled:f,"aria-describedby":b?`${c}-error`:void 0,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.nativeEvent.isComposing||229===e.keyCode)&&e.preventDefault()}}),b&&(0,t.jsx)("p",{id:`${c}-error`,className:"ssProjectError",role:"alert",children:b}),(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:f,onClick:j,children:d("drive.cancel","Cancel")}),(0,t.jsx)("button",{type:"submit",className:"cfBtn cfPrimary",disabled:f||!p.trim(),"aria-busy":f,children:n})]})]})]})}function tv({row:e,location:a,onRestore:n,onClose:l,fallbackFocus:i}){let{t:r}=(0,F.useTranslation)("paletteOs"),o=(0,s.useRef)(!1),d=(0,s.useRef)(!0),[c,u]=(0,s.useState)(!1),[m,h]=(0,s.useState)("");(0,s.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]);let p=async()=>{if(n&&!o.current){o.current=!0,u(!0),h("");try{await n(),d.current&&l()}catch{d.current&&h(r("drive.h.restoreFailed","Could not restore this item. Try again."))}finally{o.current=!1,d.current&&u(!1)}}};return(0,t.jsxs)(th.ConversationDialog,{title:e.name,fallbackFocus:i,busy:c,onClose:()=>{o.current||l()},children:[(0,t.jsxs)("div",{className:"drvInfo",children:[(0,t.jsx)(eD,{kind:e.kind}),(0,t.jsxs)("dl",{children:[(0,t.jsx)("dt",{children:r("drive.h.colName","Name")}),(0,t.jsx)("dd",{children:e.name}),(0,t.jsx)(eB,{row:e,location:a})]})]}),m&&(0,t.jsx)("p",{className:"ssProjectError",role:"alert",children:m}),n&&(0,t.jsx)("div",{className:"ssDlgActions",children:(0,t.jsx)("button",{type:"button",className:"cfBtn",disabled:c,"aria-busy":c,onClick:()=>void p(),children:r("drive.trash.restore","Restore")})})]})}var tj=e.i(729995);let ty=[{id:"mine",icon:"folder",group:0},{id:"team",icon:"users",group:0},{id:"shared",icon:"share",group:1},{id:"recent",icon:"clock",group:1},{id:"starred",icon:"star",group:1},{id:"trash",icon:"trash",group:2},{id:"storage",icon:"cloudCheck",group:2}],tw="15 GB";e.s(["DriveView",0,function(){let e,{t:a}=(0,F.useTranslation)("paletteOs"),{openDrawer:n,openConfirm:l,openSession:i}=(0,ec.useViewContext)(),r=function(){let e=(0,eh.useDataRooms)(),t=(0,ep.useDataRoom)(),{fetchTrash:a,fetchRoot:n,fetchFolder:l}=t,{refetch:i}
24=e,[r,o]=(0,s.useState)({roomId:null,stack:[]}),{roomId:d,stack:c}=r,u=c.at(-1)?.id??null,m=(0,s.useRef)(r);m.current=r;let h=(0,s.useCallback)(e=>{o(t=>t.roomId===e?t:{roomId:e,stack:[]})},[]),[p,g]=(0,s.useState)("browse"),[f,x]=(0,s.useState)(new Set),[b,v]=(0,s.useState)("list"),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,_]=(0,s.useState)(!1),[T,E]=(0,s.useState)(!1),[A,R]=(0,s.useState)(null),D=(0,ef.useUpload)();(0,s.useEffect)(()=>{try{let e=ex.find(e=>e===localStorage.getItem(eb));e&&v(e)}catch{}},[]);let M=(0,s.useCallback)(e=>{v(e);try{localStorage.setItem(eb,e)}catch{}},[]);(0,s.useEffect)(()=>{null==d&&e.dataRooms.length&&h(e.dataRooms[0].id)},[e.dataRooms,d,h]);let{driveRoomSeed:I,setDriveRoomSeed:O}=(0,ec.useViewContext)();(0,s.useEffect)(()=>{null!=I&&(o({roomId:I,stack:[]}),g("browse"),O(null))},[I,O]),(0,s.useEffect)(()=>{if(null==d)return;let e=!0;return g("browse"),x(new Set),R(null),(async()=>{try{if(null==u)await n(d);else{let t=await l(d,u);e&&t?.name&&o(e=>e.roomId===d&&e.stack.at(-1)?.id===u?{...e,stack:e.stack.map(e=>e.id===u?{...e,name:t.name}:e)}:e)}}catch{}})(),()=>{e=!1}},[d,u,n,l]);let P=(0,s.useRef)(c);P.current=c;let L=(0,s.useCallback)(async(e=!0)=>{if(null==d||m.current.roomId!==d)return;let t=P.current.at(-1);try{t?await l(d,t.id,{silent:e}):await n(d,{silent:e})}catch(e){e?.status===404&&m.current.roomId===d&&m.current.stack.at(-1)?.id===t?.id&&o({roomId:d,stack:[]})}i()},[d,l,n,i]),F=(0,s.useRef)(null);(0,eg.useRoomEvents)(d,(0,s.useCallback)(e=>{"graph_build"!==e.type&&"ai_organise"!==e.type&&(F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{L(!0)},500))},[L])),(0,s.useEffect)(()=>()=>{F.current&&clearTimeout(F.current)},[d]);let $=(0,s.useCallback)(e=>{x(new Set),g("browse"),o(t=>({roomId:e.data_room_id,stack:[...t.roomId===e.data_room_id?t.stack:[],{id:e.id,name:e.name}]}))},[]),B=(0,s.useCallback)(e=>{x(new Set),g("browse");let t=e<0?[]:P.current.slice(0,e+1);t.at(-1)?.id===P.current.at(-1)?.id?L(!1):o(e=>({...e,stack:t}))},[L]),H=(0,s.useCallback)(async(e,t,a)=>{g("browse"),x(new Set);let s=null==t?[]:a?.length?a:[{id:t,name:"â¦"}];e===d&&t===u?await L(!1):o({roomId:e,stack:s})},[d,u,L]),z=(0,s.useRef)(null),U=(0,s.useRef)(0),G=(0,s.useCallback)(e=>{let t=++U.current;(y(e),C(!1),k(null),z.current&&clearTimeout(z.current),e.trim())?(g("search"),z.current=setTimeout(async()=>{try{let a=new URLSearchParams({q:e.trim()}),s=await (0,er.apiFetch)(`/api/v1/data-rooms/search?${a}`),n=await s.json();t===U.current&&k(n.results??[])}catch{t===U.current&&(k([]),C(!0))}},300)):g(e=>"search"===e?"browse":e)},[]),W=(0,s.useRef)(0),K=(0,s.useCallback)(async()=>{if(null==d)return;let e=++W.current;E(!0),_(!1),R(null);try{let t=await a(d);e===W.current&&(R(t),_(null===t),t&&i())}catch{e===W.current&&_(!0)}finally{e===W.current&&E(!1)}},[d,a,i]),V=(0,s.useCallback)(async()=>{null!=d&&(x(new Set),g("trash"),await K())},[d,K]);(0,s.useEffect)(()=>{"search"!==p&&(U.current+=1,z.current&&clearTimeout(z.current),y(""),k(null),C(!1)),"trash"!==p&&(W.current+=1,R(null),E(!1),_(!1))},[p,d]),(0,s.useEffect)(()=>()=>{U.current+=1,W.current+=1,z.current&&clearTimeout(z.current),F.current&&clearTimeout(F.current)},[]);let Y=(0,s.useCallback)(e=>{x(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})},[]),q=(0,s.useCallback)(()=>x(new Set),[]),J=(0,s.useCallback)(e=>x(new Set(e)),[]),X=(0,s.useMemo)(()=>{let e=[],t=[];for(let a of f){let[s,n]=a.split(":");"f"===s?e.push(Number(n)):"d"===s&&t.push(Number(n))}return{fileIds:e,folderIds:t}},[f]);(0,s.useEffect)(()=>{if(null!=d)return D.registerRefreshCallback(d,()=>{L(!0)})},[d,D,L]);let Z=(0,s.useCallback)((e,a)=>{let s=a??d;if(null==s||!e.length)return;let n=s===d?P.current[P.current.length-1]?.id??null:null;D.enqueueFiles(e,s,n,s===d?e=>t.upsertFileInContents(e):void 0)},[d,D.enqueueFiles,t.upsertFileInContents]),Q=(0,s.useCallback)(async(e,a)=>{let s=a??d;if(null==s||!e.length)return;let n=s===d?P.current[P.current.length-1]?.id??null:null,l=s===d?e=>t.upsertFileInContents(e):void 0;if(!e.some(e=>e.path.length))return void D.enqueueFiles(e.map(e=>e.file),s,n,l);let{byFolder:i,createdFolders:r}=await (0,ed.resolveDroppedFolders)(e,{baseFolderId:n,createFolder:(e,a)=>t.createFolder(s,e,a??void 0)});for(let[e,t]of i)D.enqueueFiles(t,s,e,l);r>0&&L(!0)},[d,L,D.enqueueFiles,t.createFolder,t.upsertFileInContents]),ee=(0,s.useMemo)(()=>D.items.filter(e=>"data-room"===e.uploadType&&e.roomId===d&&"cancelled"!==e.status),[D.items,d]),et=D.cancelUpload,ea=D.retryUpload,es=D.clearCompleted,en=(t.contents?.room.id===d?t.contents.room:null)??e.dataRooms.find(e=>e.id===d)??null,el=en&&"my_permission"in en?en.my_permission:"view";return{rooms:e,room:t,roomId:d,setRoomId:h,stack:c,mode:p,setMode:g,activeRoom:en,canUpload:"upload"===el||"edit"===el||"owner"===el,canEdit:"edit"===el||"owner"===el,openFolder:$,goCrumb:B,goToPath:H,refresh:L,selection:f,toggleSelect:Y,clearSelection:q,selectKeys:J,selectedIds:X,viewMode:b,setViewMode:M,searchQ:j,search:G,searchResults:w,searchError:N,trash:A,trashError:S,trashLoading:T,openTrash:V,reloadTrash:K,transfers:ee,startUploads:Z,startDroppedUploads:Q,cancelTransfer:et,retryTransfer:ea,clearDoneTransfers:es}}(),o=(0,s.useRef)(r);o.current=r;
24let d=(0,s.useRef)(!1),[c,u]=(0,s.useState)(!1),{room:m,rooms:h,roomId:p,openTrash:g}=r,f=(0,s.useRef)(null),[x,b]=(0,s.useState)("mine"),[v,j]=(0,s.useState)(!1),{open:y,setOpen:w,closeOnMobile:k}=(0,eu.usePaletteSidebar)("memory"),[N,C]=(0,s.useState)("modified"),[S,_]=(0,s.useState)("desc"),[T,E]=(0,s.useState)(null),[A,R]=(0,s.useState)(!1),[D,M]=(0,s.useState)(!1),[I,O]=(0,s.useState)(null),[P,L]=(0,s.useState)(null),$=(0,s.useRef)(null),[B,H]=(0,s.useState)(null),[z,U]=(0,s.useState)(null),[G,W]=(0,s.useState)(null),K=(0,s.useRef)(null),V=(0,s.useRef)(null),[Y,q]=(0,s.useState)(null),[J,X]=(0,s.useState)(!1),Z=(0,s.useRef)(0),[ee,et]=(0,s.useState)(null),[ea,es]=(0,s.useState)({}),[en,ev]=(0,s.useState)(0),ey=(0,s.useCallback)(()=>E(null),[]),ew=a("drive.h.me","Me"),ek=m.contents?.room.id===r.roomId?m.contents:null,eC=r.activeRoom?.name??a("drive.title","Drive"),eA=e=>a(`drive.h.section.${e}`,e),eR=(0,s.useCallback)(async(e,t,a)=>{let s=null==t?`/api/v1/data-rooms/${e}`:`/api/v1/data-rooms/${e}/folders/${t}`;try{let e=await (0,er.apiFetch)(s,{signal:a,timeoutMs:15e3}),t=await e.json();return{folders:t.folders??[],files:t.files??[]}}catch{return null}},[]),eD=e=>"owner"===e.my_permission&&!e.is_shared,eM=e=>"owner"===e.my_permission&&e.is_shared,eI=e=>h.dataRooms.filter("mine"===e?eD:"team"===e?eM:e=>"owner"!==e.my_permission),eO=!!((e=h.dataRooms.find(e=>e.id===r.roomId))?"owner"!==e.my_permission?a("drive.sharedWithYou","Shared with you"):e.is_shared?a("drive.shared","Shared"):null:null),[eP,eL]=(0,s.useState)([]),[eF,e$]=(0,s.useState)(!0),[eB,eH]=(0,s.use
24State)(!1),ez=(0,s.useRef)(0),eU=(0,s.useCallback)(async()=>{let e=++ez.current;e$(!0),eH(!1);let t=!1,a=[];for(let s of h.dataRooms){if(e!==ez.current)return;try{let e=await (0,er.apiFetch)(`/api/v1/data-rooms/${s.id}/all-files`,{timeoutMs:15e3});for(let t of(await e.json()))a.push({...t,room:s})}catch{t=!0}}e===ez.current&&(t||eL(a),eH(t),e$(!1))},[h.dataRooms]),eW=h.dataRooms.length;(0,s.useEffect)(()=>(eU(),()=>{ez.current+=1}),[eU]);let eK=(0,s.useCallback)(()=>{r.refresh(!0),eU(),ev(e=>e+1)},[r,eU]),eY=(0,s.useCallback)(()=>{K.current?.controller.abort(),K.current=null,W(null)},[]),eq=r.stack.at(-1)?.id;(0,s.useEffect)(()=>(eY(),()=>{K.current?.controller.abort()}),[x,r.mode,r.searchQ,r.roomId,eq,eY]);let eX=h.dataRooms.every(e=>"number"==typeof e.storage_bytes&&Number.isFinite(e.storage_bytes)&&e.storage_bytes>=0),eZ=eX?h.dataRooms.reduce((e,t)=>e+t.storage_bytes,0):eP.reduce((e,t)=>e+t.file_size,0),eQ=!h.loading&&!h.error&&(eX||!eF&&!eB),e1=(0,eo.useDataRoomFavorites)(),{toggleFavorite:e2,fetchFavorites:e3}=e1;(0,s.useEffect)(()=>{("starred"===x||"search"===r.mode)&&e3()},[x,r.mode,e3]);let e4=(0,s.useRef)(new Set);(0,s.useEffect)(()=>{"trash"===x&&null!=p&&g()},[x,p,g]);let e5=e=>{eY(),b(e),j(!1),r.clearSelection(),r.search(""),"trash"!==e&&"trash"===r.mode&&r.setMode("browse"),"recent"===e&&(C("modified"),_("desc"),eU()),"storage"===e&&(C("size"),_("desc"),eU())},e6=(0,s.useCallback)(e=>{eY(),U({file:e,source:{key:`${e.data_room_id}:${e.id}`,name:e.original_filename,mime:e.mime_type,size:e.file_size,url:e.file_url,pending:!1}})},[eY]),e7=(0,s.useCallback)(e=>{eY();let s=e.data_room_id;if(null==s)return;let l=h.dataRooms.find(e=>e.id===s),i=l?.my_permission==="edit"||l?.my_permission==="owner";n({wide:!0,content:(0,t.jsx)(ej.FileInspector,{file:e,roomId:s,roomName:l?.name??a("drive.title","Drive"),canEdit:i,ops:m,onChanged:eK,onDeleted:eK})})},[m,h.dataRooms,a,n,eK,eY]),e8=()=>{eK(),e3();let e=o.current;"search"===e.mode&&e.search(e.searchQ)},tr=(e,t,s,n)=>L({title:a("drive.h.rename","Rename"),current:n,onSave:async a=>{"file"===t?await m.renameFile(e,s,a):await m.renameFolder(e,s,a),e8()}}),tc=()=>L({title:a("drive.newFolder","New folder"),current:"",onSave:async e=>{await m.createFolder(r.roomId,e,r.stack[r.stack.length-1]?.id),eK()}}),tu=(e,t,s,n)=>l({title:a("drive.h.moveToTrash","Move to Trash"),desc:a("drive.confirm.bulkTrashDesc","{{count}} item(s) move to Trash.",{count:t.length}),danger:!0,confirmLabel:a("drive.confirm.trash","Trash"),onConfirm:async()=>{await m.bulkDelete(e,s,n),r.clearSelection(),e8()}}),tm=(e,t,s)=>l({title:a("drive.confirm.deleteForeverTitle","Delete forever"),desc:a("drive.confirm.deleteSelectedDesc","Selected items will be permanently removed."),danger:!0,typeToConfirm:"DELETE",confirmLabel:a("drive.contextMenu.deleteForever","Delete forever"),onConfirm:async()=>{await m.permanentDelete(e,t,s),r.clearSelection(),r.reloadTrash()}}),th=async(e,t,a)=>{await m.restoreItems(e,t,a),r.clearSelection(),r.reloadTrash(),eK()},tp=()=>l({title:a("drive.confirm.emptyTrashTitle","Empty trash?"),desc:a("drive.confirm.emptyTrashDesc","All items in Trash will be permanently removed."),danger:!0,typeToConfirm:"DELETE",confirmLabel:a("drive.contextMenu.emptyTrash","Empty trash"),onConfirm:async()=>{await m.emptyTrash(r.roomId),r.clearSelection(),r.reloadTrash()}}),tg=async(e,t,a,s)=>{"file"===t?await m.setFileTags(e,a,s):await m.setFolderTags(e,a,s),eK()},tf=(e,t,s)=>{let n=a(`drive.kind.${s.kind}`,s.kind),l="file"===s.kind?[a("drive.ai.suggestSummarizeFile","Summarize {{name}}",{name:s.name}),a("drive.ai.suggestNumbersFile","What are the important numbers or dates in {{name}}?",{name:s.name}),a("drive.ai.suggestRisksFile","What risks, decisions, or action items are in {{name}}?",{name:s.name})]:[a("drive.ai.suggestSummarizeScope","Summarize this {{kind}}",{kind:n}),a("drive.ai.suggestKeyDocsScope","What are the key documents in this {{kind}}?",{kind:n}),a("drive.ai.suggestRisksScope","What risks or action items should I know from this {{kind}}?",{kind:n})];i({newThread:!0,dataRoomContext:{kind:s.kind,roomId:e,roomName:t,targetId:s.id,targetName:s.name,suggestions:l}})},tk=(e,s,l,i,r)=>{let o=()=>n({content:(0,t.jsx)(ta,{roomId:e,folderId:s,canEdit:i,onTrash:async t=>{await m.bulkDelete(e,t,[])},onDone:r})}),d=()=>n({content:(0,t.jsx)(tn,{roomId:e,folderId:s,scopeName:l})});return[{label:a("drive.contextMenu.askAi","Ask AI"),icon:"spark",on:()=>tf(e,l,{kind:null==s?"room":"folder",id:s??e,name:l})},...i?[{label:a("drive.contextMenu.organiseAi","Organise (AI)"),on:()=>n({content:(0,t.jsx)(tl,{roomId:e,folderId:s,folderName:null==s?null:l,onApplied:r})})}]:[],...i&&null!=s?[{label:a("drive.contextMenu.suggestTagsAi","Suggest tags (AI)"),on:()=>tN(e,[],[s])}]:[],{label:a("drive.contextMenu.findDuplicatesAi","Find duplicates (AI)"),on:o},{label:a("drive.contextMenu.healthAi","Health (AI)"),on:()=>n({content:(0,t.jsx)(ts,{roomId:e,folderId:s,scopeName:l,onOpenDuplicates:o,onOpenDigest:d})})},{label:a("drive.contextMenu.digestAi","Digest (AI)"),on:d}]},tN=(e,a,s)=>n({content:(0,t.jsx)(tt,{roomId:e,fileIds:a,folderIds:s,onDone:eK,onApply:async(t,a,s)=>{"file"===t?await m.setFileTags(e,a,s):await m.setFolderTags(e,a,s)}})}),tC=(e,t)=>({key:`f:${e.id}`,name:e.original_filename,kind:eS(e.mime_type,e.original_filename),owner:e.owned_by_me?ew:e.owner_name||e.uploaded_by_name||"â",modified:e.updated_at,size:e.file_size,starred:e.is_favorite,tags:e.tags,thumbs:[e.thumbnail_url,e.mime_type.startsWith("image/")?e.file_url:null].filter(e=>!!e),target:{kind:"file",file:e},...t}),tS=e=>({key:`d:${e.id}`,name:e.name,kind:"folder",owner:e.owned_by_me?ew:e.owner_name||"â",modified:e.updated_at,size:null,starred:e.is_favorite,shared:eO,tags:e.tags,target:{kind:"folder",folder:e}}),t_=e=>({key:`r:${e.id}`,name:e.name,kind:"folder",owner:"owner"===e.my_permission?ew:e.owner_name||"â",modified:e.updated_at,size:null,starred:e.is_favorite,shared:e.is_shared||"owner"!==e.my_permission,target:{kind:"room",room:e}}),tT=e=>({key:`v:${e.item_type}:${e.item_id}`,name:e.name,kind:"file"===e.item_type?eS(e.mime_type??"",e.name):"folder",owner:e.owned_by_me?ew:e.owner_name||"â",modified:e.updated_at??null,size:e.file_size??null,starred:!0,selectable:"room"===e.item_type||null!=e.data_room_id,target:{kind:"fav",fav:e}}),tE=e=>({key:`s:${e.kind}:${e.id}`,name:e.name,kind:"file"===e.kind?eS(e.mime_type??"",e.name):"folder",owner:e.owned_by_me?ew:e.owner_name||"â",modified:e.updated_at,size:e.file_size,starred:e1.favorites.some(t=>t.item_type===e.kind&&t.item_id===e.id),target:{kind:"search",result:e}}),tA="search"===r.mode,tR=!tA&&["mine","team","shared"].includes(x)&&v,tD=(0,s.useMemo)(()=>eE(tA?(r.searchResults??[]).map(tE):"trash"===x?[...(r.trash?.folders??[]).map(tS),...(r.trash?.files??[]).map(e=>tC(e))]:"starred"===x?e1.favorites.map(tT):"recent"===x?eP.slice().sort((e,t)=>
24t.updated_at.localeCompare(e.updated_at)).slice(0,30).map(e=>tC(e)):"storage"===x?eP.map(e=>tC(e)):v?[...(ek?.folders??[]).map(tS),...(ek?.files??[]).map(e=>tC(e))]:eI(x).map(t_),N,S),[tA,r.searchResults,x,r.trash,e1.favorites,eP,v,h.dataRooms,ek,N,S,eO,ew]),tM=tD.filter(e=>!1!==e.selectable).map(e=>e.key),tI=tD.filter(e=>!1!==e.selectable&&r.selection.has(e.key)),tO=tI.length,tP=tI.map(e=>{let t=e.target;return"file"===t.kind?{key:e.key,kind:"file",id:t.file.id,roomId:t.file.data_room_id}:"folder"===t.kind?{key:e.key,kind:"folder",id:t.folder.id,roomId:t.folder.data_room_id}:"room"===t.kind?{key:e.key,kind:"room",id:t.room.id,roomId:t.room.id}:"search"===t.kind?{key:e.key,kind:t.result.kind,id:t.result.id,roomId:t.result.data_room_id}:{key:e.key,kind:t.fav.item_type,id:t.fav.item_id,roomId:"room"===t.fav.item_type?t.fav.item_id:t.fav.data_room_id}}),tL=new Map;for(let e of tP){if(null==e.roomId||"room"===e.kind)continue;let t=tL.get(e.roomId)??{fileIds:[],folderIds:[],keys:[]};t["file"===e.kind?"fileIds":"folderIds"].push(e.id),t.keys.push(e.key),tL.set(e.roomId,t)}let tF=tO>0&&tP.every(e=>"room"!==e.kind&&h.dataRooms.some(t=>t.id===e.roomId&&("owner"===t.my_permission||"edit"===t.my_permission))),t$=1===tL.size&&tP.every(e=>"room"!==e.kind)?[...tL][0]:null,tB=async e=>{if(d.current)return;d.current=!0,u(!0);let t=new Set;try{if("star"===e)for(let e of tP)null!=e.roomId&&(await e1.addFavorite(e.roomId,e.kind,e.id),t.add(e.key));else for(let[e,a]of tL)await m.bulkDelete(e,a.fileIds,a.folderIds),a.keys.forEach(e=>t.add(e))}catch{Q.toast.error(a("drive.h.selectionFailed","Could not update every item. Unfinished items remain selected."))}finally{let e=o.current;e.selectKeys([...e.selection].filter(e=>!t.has(e))),e8(),d.current=!1,u(!1)}},tH=async(e,t=!1)=>{if(K.current?.key===e.key)return;let a=e.target;if("fav"!==a.kind&&"search"!==a.kind)return;let s="fav"===a.kind?a.fav.data_room_id:a.result.data_room_id,n="fav"===a.kind?a.fav.folder_id:a.result.folder_id,l="fav"===a.kind?a.fav.item_id:a.result.id;if(eY(),t||(V.current=document.activeElement instanceof HTMLElement?document.activeElement:null),null==s)return void W({row:e,failed:!0});let i=new AbortController;K.current={key:e.key,controller:i},W({row:e,failed:!1});let r=await eR(s,n,i.signal);if(i.signal.aborted)return;K.current=null;let o=r?.files.find(e=>e.id===l);o?e6(o):W({row:e,failed:!0})},tz=e=>{if("trash"===x&&!tA)return void tG(e);let t=e.target;if("file"===t.kind)return void e6(t.file);if("folder"===t.kind){"trash"!==x&&r.openFolder(t.folder);return}if("room"===t.kind){var a;e5(eD(t.room)?"mine":eM(t.room)?"team":"shared"),a=t.room,j(!0),r.roomId===a.id?r.goCrumb(-1):r.setRoomId(a.id);return}if("fav"===t.kind){let a=t.fav;if("room"===a.item_type){let e=h.dataRooms.find(e=>e.id===a.item_id);e&&tz(t_(e));return}return"file"===a.item_type?void tH(e):void(null==a.data_room_id||(b("mine"),j(!0),r.goToPath(a.data_room_id,a.item_id)))}let s=t.result;if("room"===s.kind){let e=h.dataRooms.find(e=>e.id===s.id);e&&tz(t_(e));return}"file"===s.kind?tH(e):(r.search(""),b("mine"),j(!0),r.goToPath(s.data_room_id,s.id))},tU=e=>"trash"!==x||tA?"room"===e.target.kind?eA(eD(e.target.room)?"mine":eM(e.target.room)?"team":"shared"):function(e,t,a){let s=e.target;if("room"===s.kind)return"â";if("search"===s.kind)return s.result.path.at(-1)||s.result.data_room_name||"â";let n="file"===s.kind?s.file.data_room_id:"folder"===s.kind?s.folder.data_room_id:s.fav.data_room_id,l="file"===s.kind?s.file.folder_id:"folder"===s.kind?s.folder.parent_folder_id:"folder"===s.fav.item_type?s.fav.parent_folder_id:s.fav.folder_id;return null!=l?a.find(e=>e.id===l)?.name??"â":t.find(e=>e.id===n)?.name??("fav"===s.kind?s.fav.data_room_name:null)??"â"}(e,h.dataRooms,r.stack):eA("trash"),tG=e=>{eY();let t=e.target,a="trash"===x&&!tA,s="file"===t.kind?t.file.data_room_id:"folder"===t.kind?t.folder.data_room_id:null,n=h.dataRooms.find(e=>e.id===s)?.my_permission;H({row:e,location:tU(e),onRestore:a&&("owner"===n||"edit"===n)&&("file"===t.kind||"folder"===t.kind)?()=>th("file"===t.kind?t.file.data_room_id:t.folder.data_room_id,"file"===t.kind?[t.file.id]:[],"folder"===t.kind?[t.folder.id]:[]):void 0})},tW=e=>{let s=e.target,i="file"===s.kind?s.file.data_room_id:"folder"===s.kind?s.folder.data_room_id:"fav"===s.kind?"room"===s.fav.item_type?s.fav.item_id:s.fav.data_room_id:"search"===s.kind?s.result.data_room_id:s.room.id,o=h.dataRooms.find(e=>e.id===i),d=o?.name??a("drive.title","Drive"),c=o?.my_permission==="edit"||o?.my_permission==="owner",u=c||o?.my_permission==="upload",p={label:a("drive.h.fileInfo","File info"),icon:"file",on:()=>tG(e)},g=(e,t,n)=>({label:"search"===s.kind&&e1.error?a("drive.h.retryStarStatus","Retry star status"):e?a("drive.h.unstar","Remove star"):a("drive.h.star","Mark as important"),icon:"search"===s.kind&&e1.error?"refresh":"star",disabled:null==i||"search"===s.kind&&e1.loading,on:()=>
24{if("search"===s.kind&&e1.error)return void e3();let l=`${t}:${n}`;null==i||e4.current.has(l)||(e4.current.add(l),e2(i,t,n,e).then(eK).catch(()=>{Q.toast.error(a("drive.h.starFailed","Could not update the star. Try again."))}).finally(()=>e4.current.delete(l)))}});if("room"===s.kind){let i=s.room,o="edit"===i.my_permission||"owner"===i.my_permission;return{sections:[[{label:a("drive.h.openFolder","Open folder"),icon:"eye",on:()=>tz(e)},p,g(i.is_favorite,"room",i.id),..."owner"===i.my_permission?[{label:a("drive.contextMenu.deleteRoom","Delete drive"),icon:"trash",danger:!0,on:()=>l({title:a("drive.confirm.deleteRoomTitle","Delete drive?"),desc:a("drive.confirm.deleteRoomDesc",'"{{name}}" and its contents will be removed.',{name:i.name}),danger:!0,confirmLabel:a("drive.delete","Delete"),onConfirm:async()=>{await h.deleteRoom(i.id),r.roomId===i.id&&(r.setRoomId(null),r.clearSelection())}})}]:[]],[{label:a("drive.contextMenu.downloadZip","Download ZIP"),icon:"download",on:()=>{m.downloadRoomZip(i.id,i.name)}},..."owner"===i.my_permission?[{label:a("drive.contextMenu.share","Shareâ¦"),icon:"users",on:()=>O({id:i.id,name:i.name})}]:[],{label:a("drive.contextMenu.knowledgeGraph","Knowledge graph"),icon:"graph",on:()=>n({content:(0,t.jsx)(to,{roomId:i.id,roomName:i.name}),wide:!0})}],tk(i.id,null,i.name,o,()=>{r.roomId===i.id&&eK(),h.refetch(),eU()})]}}if("fav"===s.kind||"search"===s.kind){let t="fav"===s.kind?s.fav.item_type:s.result.kind,n="fav"===s.kind?s.fav.item_id:s.result.id;if("room"===t){let e=h.dataRooms.find(e=>e.id===n);if(e)return tW(t_(e))}return{sections:[[{label:"folder"===t?a("drive.h.openFolder","Open folder"):a("drive.contextMenu.open","Open"),icon:"eye",on:()=>tz(e)},p,...null!=i?[g(!!e.starred,t,n)]:[],...null!=i&&c&&"room"!==t?[{label:a("drive.h.rename","Rename"),icon:"pencil",on:()=>tr(i,t,n,e.name)},{label:a("drive.h.moveToTrash","Move to Trash"),icon:"trash",on:()=>tu(i,[e.name],"file"===t?[n]:[],"folder"===t?[n]:[])}]:[]]]}}if(null==i)return{sections:[]};if("trash"===x&&!tA){let t="file"===s.kind?[s.file.id]:[],n="folder"===s.kind?[s.folder.id]:[];return{sections:[[{label:"folder"===s.kind?a("drive.h.openFolder","Open folder"):a("drive.contextMenu.open","Open"),icon:"eye",on:()=>tG(e)},p,...c?[{label:a("drive.trash.restore","Restore"),icon:"refresh",on:()=>{th(i,t,n)}}]:[]],c?[{label:a("drive.contextMenu.deleteForever","Delete forever"),icon:"trash",danger:!0,on:()=>tm(i,t,n)}]:[]]}}if("file"===s.kind){let e=s.file;return{sections:[[{label:a("drive.contextMenu.open","Open"),icon:"eye",on:()=>e6(e)},p,g(e.is_favorite,"file",e.id),...c?[{label:a("drive.h.rename","Rename"),icon:"pencil",on:()=>tr(i,"file",e.id,e.original_filename)},{label:a("drive.h.moveToTrash","Move to Trash"),icon:"trash",on:()=>tu(i,[e.original_filename],[e.id],[])}]:[]],[{label:a("drive.contextMenu.download","Download"),icon:"download",on:()=>m.downloadFile(i,e.id,e.original_filename)},...u?[{label:a("drive.contextMenu.duplicate","Duplicate"),icon:"duplicate",on:()=>{m.duplicateFile(i,e.id).then(eK)}}]:[]],[{label:a("drive.h.fileTools"),icon:"settings",on:()=>e7(e)},{label:a("drive.contextMenu.askAi","Ask AI"),icon:"spark",on:()=>tf(i,d,{kind:"file",id:e.id,name:e.original_filename})},{label:a("drive.contextMenu.summarizeAi","Summarize (AI)"),on:()=>n({content:(0,t.jsx)(e9,{roomId:i,file:e})})},...c?[{label:a("drive.contextMenu.suggestRenameAi","Suggest rename (AI)"),on:()=>n({content:(0,t.jsx)(te,{roomId:i,file:e,onRename:async t=>{await m.renameFile(i,e.id,t),eK()}})})},{label:a("drive.contextMenu.suggestTagsAi","Suggest tags (AI)"),on:()=>tN(i,[e.id],[])},{label:a("drive.contextMenu.reviewAi","Review (AI)"),on:()=>n({content:(0,t.jsx)(ti,{roomId:i,fileIds:[e.id],onApplied:eK})})}]:[]]],tagRow:c?{tags:e.tags,onSet:t=>{tg(i,"file",e.id,t)}}:void 0}}let f=s.folder;return{sections:[[{label:a("drive.h.openFolder","Open folder"),icon:"eye",on:()=>r.openFolder(f)},p,g(f.is_favorite,"folder",f.id),...c?[{label:a("drive.h.rename","Rename"),icon:"pencil",on:()=>tr(i,"folder",f.id,f.name)},{label:a("drive.h.moveToTrash","Move to Trash"),icon:"trash",on:()=>tu(i,[f.name],[],[f.id])}]:[]],[{label:a("drive.contextMenu.downloadZip","Download ZIP"),icon:"download",on:()=>{m.downloadFolderZip(i,f.id,f.name)}
24},...o?.my_permission==="owner"?[{label:a("drive.contextMenu.share","Shareâ¦"),icon:"users",on:()=>O({id:i,name:o.name})}]:[]],tk(i,f.id,f.name,c,eK)],tagRow:c?{tags:f.tags,onSet:e=>{tg(i,"folder",f.id,e)}}:void 0}},tK=(e,t)=>{t.preventDefault(),t.stopPropagation(),tV(e,{x:t.clientX,y:t.clientY})},tV=(e,t)=>{let s=tW(e),n=s.sections.filter(e=>e.length);if(!n.length)return;let l={anchor:t,sections:[n[0]]};if(n.length>1||s.tagRow){let e={anchor:t,tagRow:s.tagRow,sections:[[{label:a("drive.h.backToMenu"),icon:"chevronLeft",on:()=>E(l)}],...n.slice(1)]};l.sections.push([{label:a("drive.h.moreActions"),icon:"more",on:()=>E(e)}])}E(l)},tY=async e=>{let t=await h.createRoom(e);$.current?.isConnected&&(b("mine"),j(!0),r.setRoomId(t.id),Y?.length&&r.startDroppedUploads(Y,t.id))},tq=e=>{if(e.length){if(null==r.roomId||!tR){q(e),M(!0);return}r.startDroppedUploads(e)}},tJ=null==r.roomId||r.canUpload&&tR||!tR,tX=tA?a("drive.h.searchResults","Search results"):tR?eC:eA(x),tZ=tA?{icon:"search",title:a("drive.h.emptySearch","No results"),note:a("drive.h.emptySearchNote","Search by file name, type or owner."),action:{label:a("drive.contextMenu.clearSearch","Clear search"),on:()=>r.search("")}}:"trash"===x?{icon:"trash",title:a("drive.h.emptyTrash","Trash is empty"),note:a("drive.h.emptyTrashNote","Items moved here can be restored.")}:"starred"===x?{icon:"folder",title:a("drive.h.emptyTitle","No documents yet"),note:a("drive.h.emptyStarredNote","Mark files as important from the file menu.")}:!tR&&["mine","team","shared"].includes(x)?{icon:"folder",title:a("drive.h.emptyDrives","No drives yet"),note:a("drive.h.emptyDrivesNote","Add a drive from New."),action:{label:a("drive.contextMenu.newDataRoom","New drive"),on:()=>M(!0)}}:{icon:"folder",title:a("drive.h.emptyTitle","No documents yet"),note:a("drive.h.emptyNote","Files added here will appear.")},tQ="recent"===x||"storage"===x,t0=tA?r.searchError:"trash"===x?r.trashError||null==r.roomId&&!!h.error:"starred"===x?e1.error:tQ?eB||!!h.error:tR?m.error:!!h.error,t1=()=>{tR?r.refresh(!1):tA?r.search(r.searchQ):"trash"===x&&null!=r.roomId?r.reloadTrash():"starred"===x?e3():tQ&&!h.error?eU():h.refetch()},t2=tA?null===r.searchResults:"trash"===x?r.trashLoading||null==r.roomId&&h.loading:tR?m.loading||!ek&&!m.error:"starred"===x?e1.loading:tQ&&eF||h.loading,t3=(ek?.files??[]).reduce((e,t)=>e+t.file_size,0),t4=r.transfers.filter(e=>"uploading"===e.status).length,t5="columns"===r.viewMode,t6=(e,t)=>`${e}:${t??"root"}`,t7=t5&&tR&&null!=r.roomId&&r.stack.length?[null,...r.stack.slice(0,-1).map(e=>e.id)]:[],t8=t7.map(e=>e??"root").join("/"),t9=(0,s.useRef)(ea);t9.current=ea;let ae=(0,s.useRef)(-1);(0,s.useEffect)(()=>{let e=r.roomId,t=ae.current!==en;if(ae.current=en,null!=e)for(let a of t7){let s=t6(e,a);(t||!t9.current[s])&&eR(e,a).then(e=>es(t=>({...t,[s]:e?[...e.folders.map(tS),...e.files.map(e=>tC(e))]:t[s]??"error"})))}},[r.roomId,t8,en]);let at=null==r.roomId?"":t6(r.roomId,eq??null),aa=(0,s.useRef)({contents:null,at:""});aa.current.contents!==m.contents&&(aa.current={contents:m.contents,at:at});let as=aa.current.at===at,an=tA?"search":["mine","team","shared"].includes(x)?`drives:${x}`:`flat:${x}`,al=e=>{let t=ea[e];return Array.isArray(t)?eE(t,N,S):null},ai={rows:t2?null:tD,error:!!t0,current:!0,active:ee},ar=t5?tR&&null!=r.roomId?[{key:an,rows:h.loading?null:eE(eI(x).map(t_),N,S),active:`r:${r.roomId}`},...[null,...r.stack.map(e=>e.id)].map((e,t)=>{let a=t6(r.roomId,e),s=r.stack[t];return s?{key:a,level:t,rows:al(a),error:"error"===ea[a],active:`d:${s.id}`}:{key:a,level:t,...ai,rows:(as?ai.rows:null)??al(a)}})]:[{key:an,...ai}]:[],ao="trash"===x&&!tA,ad=ar.find(e=>e.current)?.rows?.find(e=>e.key===ee&&("folder"!==e.kind||ao))??null,ac=tO>0&&(0,t.jsxs)("div",{className:"drvSel",role:"toolbar","aria-busy":c,children:[(0,t.jsx)("button",{type:"button",className:"drvIconBtn",title:a("drive.h.deselect","Deselect"),"aria-label":a("drive.h.deselect","Deselect"),onClick:r.clearSelection,children:(0,t.jsx)(eN,{name:"close"})}),(0,t.jsx)("span",{children:a("drive.h.selected","{{count}} selected",{count:tO})}),1===tI.length&&(0,t.jsx)("button",{type:"button",className:"drvIconBtn",title:a("drive.h.openSelected","Open selected"),"aria-label":a("drive.h.openSelected","Open selected"),onClick:()=>tz(tI[0]),children:(0,t.jsx)(eN,{name:"eye"})}),"trash"!==x||tA?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",className:"drvIconBtn",disabled:c,title:a("drive.h.starSelected","Star selected"),"aria-label":a("drive.h.starSelected","Star selected"),onClick:()=>void tB("star"),children:(0,t.jsx)(eN,{name:"star"})}),t$&&(0,t.jsx)("button",{type:"button",className:"drvIconBtn",disabled:c,title:a("drive.h.zipSelected","Download selection as ZIP"),"aria-label":a("drive.h.zipSelected","Download selection as ZIP"),onClick:()=>{m.downloadSelectionZip(t$[0],t$[1].fileIds,t$[1].folderIds,h.dataRooms.find(e=>e.id===t$[0])?.name??eC)},children:(0,t.jsx)(eN,{name:"download"})}),tF&&(0,t.jsx)("button",{type:"button",className:"drvIconBtn",disabled:c,title:a("drive.h.trashSelected","Move selected to Trash"),"aria-label":a("drive.h.trashSelected","Move selected to Trash"),onClick:()=>l({title:a("drive.h.moveToTrash","Move to Trash"),desc:a("drive.confirm.bulkTrashDesc","{{count}} item(s) move to Trash.",{count:tO}),danger:!0,confirmLabel:a("drive.confirm.trash","Trash"),onConfirm:()=>tB("trash")}),children:(0,t.jsx)(eN,{name:"trash"})})]}):(0,t.jsxs)(t.Fragment,{children:[tF&&t$&&(0,t.jsx)("button",{type:"button",className:"drvIconBtn",title:a("drive.h.restoreSelected","Restore selected"),"aria-label":a("drive.h.restoreSelected","Restore selected"),onClick:()=>{th(t$[0],t$[1].fileIds,t$[1].folderIds)},children:(0,t.jsx)(eN,{name:"refresh"})}),tF&&t$&&(0,t.jsx)("button",{type:"button",className:"drvIconBtn danger",title:a("drive.contextMenu.deleteForever","Delete forever"),"aria-label":a("drive.contextMenu.deleteForever","Delete forever"),onClick:()=>tm(t$[0],t$[1].fileIds,t$[1].folderIds),children:(0,t.jsx)(eN,{name:"trash"})})]})]});return(0,t.jsxs)("div",{className:`viewPane drWrap drv${y?"":" drv--closed"}`,onDragEnter:e=>{e.preventDefault(),Z.current+=1,tJ&&X(!0)},onDragOver:e=>e.preventDefault(),onDragLeave:()=>{Z.current-=1,Z.current<=0&&X(!1)},onDrop:e=>{e.preventDefault(),Z.current=0,X(!1),tJ&&(0,ed.extractDroppedItems)(e.dataTransfer).then(tq)},children:[(0,t.jsxs)("div",{className:"drSplit",children:[(0,t.jsxs)("aside",{inert:!y,className:"drTree drvSide","aria-label":a("drive.h.navLabel","Drive menu"),onContextMenu:e=>{e.target.closest("button")||(e.preventDefault(),E({anchor:{x:e.clientX,y:e.clientY},sections:[[{label:a("drive.contextMenu.newDataRoom","New drive"),icon:"folderPlus",on:()=>M(!0)},{label:a("drive.contextMenu.refreshRooms","Refresh drives"),icon:"refresh",on:()=>{h.refetch(),eU()}}]]}))},children:[(0,t.jsx)(ei.SidebarResizer,{open:y,label:a("sidebarResize.drive","Resize Drive menu")}),(0,t.jsxs)("div",{className:"drvSideTop",children:[(0,t.jsx)("span",{children:a("drive.h.docBox","Documents")}),(0,t.jsx)("button",{type:"button",className:"drvIconBtn",title:a("drive.h.collapse","Collapse list"),"aria-label":a("drive.h.collapse","Collapse list"),"aria-expanded":!0,onClick:()=>w(!1),children:(0,t.jsx)(eN,{name:"panelLeft"})})]}),(0,t.jsxs)("nav",{className:"drvNav",children:[ty.map((e,a)=>{let s=x===e.id&&!tA;return(0,t.jsxs)("button",{type:"button",className:`drvNavItem${s?" active":""}${a>0&&ty[a-1].group!==e.group?" group-start":""}`,"aria-current":s?"page":void 0,onClick:()=>{e5(e.id),k()},children:[(0,t.jsx)(eN,{name:e.icon}),(0,t.jsx)("span",{children:eA(e.id)})]},e.id)}),(0,t.jsxs)("button",{type:"button",className:`drvNavItem${A?" active":""}`,"aria-pressed":A,onClick:()=>R(e=>!e),children:[(0,t.jsx)(eN,{name:"memory"}),(0,t.jsx)("span",{children:a("drive.h.memory","Memory")})]})]}),(0,t.jsxs)("div",{className:"drvCap",children:[(0,t.jsx)("div",{className:"drvCapMeter",role:eQ?"meter":void 0,"aria-label":a("drive.h.capacity","Storage"),"aria-valuemin":eQ?0:void 0,"aria-valuemax":eQ?100:void 0,"aria-valuenow":eQ?Math.min(100,eZ/0x3c0000000*100):void 0,children:(0,t.jsx)("span",{hidden:!eQ,style:{width:`${Math.min(100,eZ/0x3c0000000*100)}%`}})}),(0,t.jsxs)("p",{children:[(0,t.jsx)("strong",{children:eQ?(0,em.fmtSize)(eZ):"â"})," / ",tw]}),(0,t.jsx)("small",{children:a("drive.h.capacityNote","All files in {{n}}
24 drives · nominal quota",{n:eW})})]})]}),(0,t.jsxs)("main",{className:"drMain drvMain",children:[(0,t.jsxs)("header",{className:"drvHead",children:[(0,t.jsx)("div",{className:"drvTitle",children:(0,t.jsx)("h1",{children:a("drive.title","Drive")})}),(0,t.jsxs)("div",{className:"drvTools",children:[(0,t.jsx)("button",{type:"button",className:"drvIconBtn drvSortBtn",title:a("drive.h.sortBy","Sort by"),"aria-label":a("drive.h.sortBy","Sort by"),"aria-haspopup":"menu",onClick:e=>E({anchor:e.currentTarget.getBoundingClientRect(),label:a("drive.h.sortBy","Sort by"),sections:[e_.map(e=>({id:e,label:a(`drive.h.col${e[0].toUpperCase()}${e.slice(1)}`,e),checked:N===e,on:()=>{N!==e&&_(eT(e)),C(e)}})),["asc","desc"].map(e=>({id:e,label:a(`drive.h.${e}`,e),checked:S===e,on:()=>_(e)}))]}),children:(0,t.jsx)(eN,{name:"sliders"})}),(0,t.jsx)("span",{className:"drvDivider","aria-hidden":"true"}),(0,t.jsx)("div",{className:"drvViewCtl",role:"group","aria-label":a("drive.h.viewMode","View"),children:ex.map(e=>{let s=a(`drive.h.view${e[0].toUpperCase()}${e.slice(1)}`,e);return(0,t.jsx)("button",{type:"button",className:"drvViewBtn",title:s,"aria-label":s,"aria-pressed":r.viewMode===e,onClick:()=>r.setViewMode(e),children:(0,t.jsx)(eN,{name:e})},e)})}),(0,t.jsxs)("div",{className:"drvSearch poSearch",role:"search",children:[(0,t.jsx)(eN,{name:"search"}),(0,t.jsx)("input",{type:"search",maxLength:160,autoComplete:"off",value:r.searchQ,placeholder:a("drive.h.search","Search drive"),"aria-label":a("drive.h.search","Search drive"),onChange:e=>{r.search(e.target.value),r.clearSelection()},onKeyDown:e=>{"Escape"===e.key&&r.searchQ&&(e.preventDefault(),r.search(""))}}),r.searchQ&&(0,t.jsx)("button",{type:"button",title:a("drive.contextMenu.clearSearch","Clear search"),"aria-label":a("drive.contextMenu.clearSearch","Clear search"),onClick:()=>r.search(""),children:(0,t.jsx)(eN,{name:"close"})})]}),(0,t.jsxs)("button",{ref:$,type:"button",className:"drvNew","aria-haspopup":"menu",onClick:e=>E({anchor:e.currentTarget.getBoundingClientRect(),sections:[[...tR&&r.canUpload?[{label:a("drive.newFolder","New folder"),icon:"folderPlus",on:tc}]:[],...!tR||r.canUpload?[{label:a("drive.h.addFiles","Add files"),icon:"upload",on:()=>f.current?.click()}]:[],{label:a("drive.contextMenu.newDataRoom","New drive"),icon:"folder",on:()=>M(!0)}],tR&&null!=r.roomId?[{label:a("drive.contextMenu.downloadZip","Download ZIP"),icon:"download",on:()=>{let e=r.stack[r.stack.length-1];e?m.downloadFolderZip(r.roomId,e.id,e.name):m.downloadRoomZip(r.roomId,eC)}}]:[]]}),children:[a("drive.h.new","New"),(0,t.jsx)(eN,{name:"chevronDown"})]})]})]}),(0,t.jsxs)("div",{className:"drvHeading",children:[(0,t.jsx)("h2",{children:tX}),!t2&&!t0&&(0,t.jsx)("span",{role:"status","aria-live":"polite",children:a("drive.h.items","{{n}} items",{n:tD.length})})]}),tR&&(0,t.jsxs)("nav",{className:"drvCrumb","aria-label":a("drive.h.breadcrumb","Location"),children:[(0,t.jsx)("button",{type:"button",onClick:()=>e5(x),children:eA(x)}),(0,t.jsx)(eN,{name:"chevronRight"}),(0,t.jsx)("button",{type:"button",onClick:()=>r.goCrumb(-1),children:eC}),r.stack.map((e,a)=>(0,t.jsxs)("span",{children:[(0,t.jsx)(eN,{name:"chevronRight"}),(0,t.jsx)("button",{type:"button",onClick:()=>r.goCrumb(a),children:e.name})]},e.id))]}),"storage"===x&&!tA&&(0,t.jsxs)("div",{className:"drvStorage",children:[(0,t.jsx)("strong",{children:eQ?(0,em.fmtSize)(eZ):"â"}),(0,t.jsx)("span",{children:a("drive.h.storageUsed","of {{total}} used · live files",{total:tw})}),(0,t.jsx)("small",{children:a("drive.h.storageNote","Files in {{n}} drives, including nested folders and excluding Trash.",{n:eW})})]}),"trash"===x&&!tA&&(0,t.jsxs)("div",{className:"drvTrashNote",children:[(0,t.jsx)("span",{children:a("drive.trash.note","Items in Trash are kept for 30 days.")}),r.canEdit&&tD.length>0&&(0,t.jsx)("button",{type:"button",onClick:tp,children:a("drive.contextMenu.emptyTrash","Empty trash")})]}),!t2&&!t0&&ac,G&&(0,t.jsxs)("div",{className:"drvOpenStatus",role:G.failed?"alert":"status",children:[(0,t.jsx)("p",{children:a(G.failed?"drive.h.openFileFailed":"drive.h.openingFile",{name:G.row.name})}),(0,t.jsxs)("div",{children:[G.failed&&(0,t.jsx)("button",{type:"button",className:"drvBtn",onClick:()=>{V.current?.focus({preventScroll:!0}),tH(G.row,!0)},children:a("drive.share.retry","Retry")}),(0,t.jsx)("button",{type:"button",className:"drvBtn",onClick:()=>{eY(),V.current?.focus({preventScroll:!0})},children:a("drive.cancel","Cancel")})]})]}),(0,t.jsx)("div",{className:`drvResults${"list"===r.viewMode?"":` is-${r.viewM
24ode}`}`,tabIndex:0,role:"region","aria-busy":!!t2,"aria-label":a("drive.h.resultsLabel","Drive files"),onContextMenu:e=>{e.preventDefault();let t={x:e.clientX,y:e.clientY},s=r.stack[r.stack.length-1]??null;"trash"===x&&null!=r.roomId?E({anchor:t,sections:[[{label:a("drive.contextMenu.refreshTrash","Refresh trash"),icon:"refresh",on:()=>{r.reloadTrash()}},...r.canEdit?[{label:a("drive.contextMenu.emptyTrash","Empty trash"),icon:"trash",danger:!0,disabled:0===tD.length,on:tp}]:[]]]}):tR&&null!=r.roomId?E({anchor:t,sections:[[...r.canUpload?[{label:a("drive.newFolder","New folder"),icon:"folderPlus",on:tc},{label:a("drive.h.addFiles","Add files"),icon:"upload",on:()=>f.current?.click()}]:[],{label:a("drive.selectAll","Select all"),on:()=>r.selectKeys(tM)},{label:a("drive.contextMenu.refresh","Refresh"),icon:"refresh",on:eK}],tk(r.roomId,s?.id??null,s?.name??eC,r.canEdit,eK)]}):E({anchor:t,sections:[[{label:a("drive.contextMenu.newDataRoom","New drive"),icon:"folderPlus",on:()=>M(!0)},{label:a("drive.contextMenu.refreshRooms","Refresh drives"),icon:"refresh",on:()=>{h.refetch(),eU()}}]]})},children:"columns"===r.viewMode?(0,t.jsx)(eV,{columns:ar,preview:ad,selection:r.selection,toggleSelect:r.toggleSelect,onPick:(e,t)=>{let a=e.target;if("folder"===a.kind&&null!=t.level&&null!=r.roomId){if(r.stack.at(-1)?.id===a.folder.id)return void et(null);let e=t.current?t.rows:null;return e&&es(a=>({...a,[t.key]:e})),void r.goToPath(r.roomId,a.folder.id,[...r.stack.slice(0,t.level),{id:a.folder.id,name:a.folder.name}])}"room"===a.kind&&tR&&r.roomId===a.room.id&&!r.stack.length?et(null):"folder"!==e.kind||ao?(et(e.key),null==t.level||t.current||r.goCrumb(t.level-1)):tz(e)},onOpen:tz,onMenu:tV,onContext:tK,onRetry:e=>{e.current?t1():ev(e=>e+1)},empty:tZ,locate:tU}):t2?(0,t.jsx)(el.PaletteLoader,{className:"h-full",label:a("drive.loading","Loadingâ¦")}):t0?(0,t.jsxs)("div",{className:"drvEmpty",role:"alert",children:[(0,t.jsx)(eN,{name:"folder"}),(0,t.jsx)("h2",{children:a("drive.h.loadFailed")}),(0,t.jsx)("p",{children:a("drive.h.loadFailedNote")}),(0,t.jsx)("button",{type:"button",className:"drvBtn",onClick:t1,children:a("drive.share.retry","Retry")})]}):(0,t.jsx)(eG,{rows:tD,view:r.viewMode,selection:r.selection,toggleSelect:r.toggleSelect,onToggleAll:e=>e?r.selectKeys(tM):r.clearSelection(),onOpen:tz,onMenu:tV,onContext:tK,sort:{key:N,dir:S},onSort:e=>{N===e?_("asc"===S?"desc":"asc"):(C(e),_(eT(e)))},empty:tZ,locate:tU})}),(0,t.jsx)(e0,{transfers:r.transfers,onCancel:r.cancelTransfer,onRetry:r.retryTransfer,onClear:r.clearDoneTransfers}),tR&&!t2&&!t0&&(0,t.jsxs)("p",{className:"drvNote",children:[a("drive.status.summary","{{folders}} folders · {{files}} files · {{size}}",{folders:(ek?.folders??[]).length,files:(ek?.files??[]).length,size:(0,em.fmtSize)(t3)}),t4>0&&` \xb7 ${a("drive.status.uploading","{{count}} uploading",{count:t4})}`]}),(0,t.jsx)("input",{ref:f,type:"file",multiple:!0,hidden:!0,onChange:e=>{tq((0,ed.asDroppedFiles)(Array.from(e.target.files??[]))),e.target.value=""}})]}),A&&(0,t.jsx)(td,{roomId:r.roomId,roomName:eC,onClose:()=>R(!1)})]}),J&&tJ&&(0,t.jsx)("div",{className:"drDropOverlay",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"drDropTitle",children:a("drive.drop.title","Add memory")}),(0,t.jsx)("div",{className:"drDropSub",children:null!=r.roomId&&tR?a("drive.drop.upload","Drop files or folders to upload & index"):a("drive.drop.noRoom","Drop files or folders â we'll create a drive first")})]})}),z&&(0,t.jsx)(tj.WorkSourceDialog,{source:z.source,fallbackFocus:V.current?.isConnected?V:$,onClose:()=>U(null),onDownload:()=>m.downloadFile(z.file.data_room_id,z.file.id,z.file.original_filename)},z.source.key),B&&(0,t.jsx)(tv,{...B,fallbackFocus:$,onClose:()=>H(null)}),P&&(0,t.jsx)(tb,{...P,saveLabel:a("drive.rename.save","Save"),fallbackFocus:$,onClose:()=>L(null)}),D&&(0,t.jsx)(tb,{title:a("drive.newRoom.title","Create a drive"),fallbackFocus:$,onClose:()=>{M(!1),q(null)},onSave:tY,saveLabel:Y?.length?a("drive.newRoom.createUpload","Create & upload"):a("drive.create","Create"),note:Y?.length?Y.length>1?a("drive.newRoom.pendingNote","{{count}} files waiting â the upload continues into this drive once it's created.",{count:Y.length}):a("drive.newRoom.pendingNoteOne","{{count}} file waiting â the upload continues into this drive once it's created.",{count:Y.length}):a("drive.newRoom.note","Drives hold your files, folders and their knowledge graph.")}),I&&(0,t.jsx)(tx,{fallbackFocus:$,roomId:I.id,roomName:I.name,onClose:()=>O(null),onChanged:()=>{h.refetch()}},I.id),T&&(0,t.jsx)(eJ,{menu:T,onClose:ey})]})}],441276);var tk=e.i(23701);e.s(["SettingView",0,function(){let e,s=(0,a.c)(1);return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,t.jsx)("div",{className:"viewPane settingsWrap",children:(0,t.jsx)(tk.default,{})}),s[0]=e):e=s[0],e}
24],891936)},576666,702748,168948,729995,e=>{"use strict";var t=e.i(843476),a=e.i(500932),s=e.i(198197),n=e.i(455435),l=e.i(39891),i=e.i(271645),r=e.i(975558),o=e.i(430172),d=e.i(752044);e.i(785269);var c=e.i(322831),u=e.i(846696),m=e.i(209165),h=e.i(371662),p=e.i(675696),g=e.i(416317),f=e.i(296505),x=e.i(510798),b=e.i(778085),v=e.i(236643),j=e.i(35842),y=e.i(413163),w=e.i(71647),k=e.i(372428),N=e.i(13080),C=e.i(151002),S=e.i(883639),_=e.i(172782),T=e.i(854247),E=e.i(798921),A=e.i(783169),R=e.i(173623),D=e.i(572204),M=e.i(889741),I=e.i(713967),O=e.i(611695),P=e.i(98443),L=e.i(11029),F=e.i(783786),$=e.i(244002),B=e.i(860189),H=e.i(186804),z=e.i(748317),U=e.i(169673),G=e.i(572723),W=e.i(766544),K=e.i(808308),V=e.i(219760),Y=e.i(127923);let q={OPENAI:"openai",ANTHROPIC:"anthropic",GOOGLE:"google"},J=new Map(T.MODEL_GROUPS.flatMap(e=>e.models.map(t=>[t.id,q[e.provider]??"auto"])));function X(e,t){return e?e.startsWith("byo:")?t&&(0,E.isDeviceKind)(t.kind)?"device":"key":J.get(e)??"auto":"auto"}function Z(e){if(!e)return[];try{let t=JSON.parse(localStorage.getItem(e)??"[]");return Array.isArray(t)?t.filter(e=>"string"==typeof e&&""!==e):[]}catch{return[]}}function Q(e,t,a,s){return 0!==t&&("ArrowDown"===e.key?(s((a+1)%t),!0):"ArrowUp"===e.key?(s((a-1+t)%t),!0):"Home"===e.key?(s(0),!0):"End"===e.key&&(s(t-1),!0))}let ee={PALETTE:"Palette",OPENAI:"ChatGPT",ANTHROPIC:"Claude",GOOGLE:"Gemini"},et={PALETTE:"/themes/palette-os/palette-logo-black.png",OPENAI:"/themes/palette-os/providers/chatgpt.svg",ANTHROPIC:"/themes/palette-os/providers/claude.svg",GOOGLE:"/themes/palette-os/providers/gemini.svg"};function ea({value:e,onPick:a,secure:s,byo:n,recentKey:l,className:r,layout:o="grouped",effort:d,onPickEffort:u}){let m,h,{t:p}=(0,c.useTranslation)("paletteOs"),[g,f]=(0,i.useState)(!1),[x,b]=(0,i.useState)(""),[v,j]=(0,i.useState)(0),[y,w]=(0,i.useState)("PALETTE"),k=(0,i.useRef)(null),N=(0,i.useRef)(null),C=(0,i.useRef)(null),S=(0,i.useRef)([]),_=(0,i.useId)(),A=`${_}-head`,R=`${_}-panel`,D=`${_}-tab-${encodeURIComponent(y)}`,M="tabbed"===o,I=(0,i.useMemo)(()=>s?[]:n??[],[n,s]),O=(0,i.useMemo)(()=>{let e=new Map;for(let t of I)for(let a of t.models)e.set(a.id,{kind:t.kind,status:t.status,isDefault:t.isDefault});return e},[I]),P=(0,i.useCallback)((e,t)=>{var a,s;return{id:e.id,label:e.label,mark:X(e.id,O.get(e.id)),register:(a=e.id,s=O.get(e.id),a?a.startsWith("byo:")?s?.status==="error"?"Error":s&&(0,E.isDeviceKind)(s.kind)?"Local":s?.isDefault?"Default":"Key":null:"Auto"),optId:`${_}-${encodeURIComponent(t)}-${encodeURIComponent(e.id||"auto")}`}},[_,O]),L=(0,T.autoModelFor)(s),F=(0,i.useMemo)(()=>[...(0,T.modelGroupsFor)(s),...I],[s,I]),B=(0,i.useMemo)(()=>F.find(t=>t.models.some(t=>t.id===e))?.provider??"PALETTE",[F,e]),H=["OPENAI","GOOGLE","ANTHROPIC"],z=(0,i.useMemo)(()=>[{key:"PALETTE",label:p("session.composer.provider.palette",ee.PALETTE),mark:"auto"},...[...F].sort((e,t)=>{let a=H.indexOf(e.provider),s=H.indexOf(t.provider);return(a<0?99:a)-(s<0?99:s)}).map(e=>({key:e.provider,label:ee[e.provider]?p(`session.composer.provider.${e.provider.toLowerCase()}`,ee[e.provider]):e.provider,mark:X(e.models[0]?.id??"",O.get(e.models[0]?.id??""))}))],[F,O,p]),U=(0,i.useMemo)(()=>{if(M){if("PALETTE"===y)return[{key:"auto",head:z[0].label,rows:[P(L,"auto")]}];let e=F.find(e=>e.provider===y)??F[0];if(!e)return[];let t=z.find(t=>t.key===e.provider)?.label??e.provider;return[{key:e.provider,head:t,rows:e.models.map(t=>P(t,e.provider))}]}let e=x.trim().toLowerCase(),t=(t,a)=>!e||`${t.label} ${a} ${t.id}`.toLowerCase().includes(e),a=[];if(t(L,"")&&a.push({key:"auto",head:null,rows:[P(L,"auto")]}),!e&&l){let e=new Map(F.flatMap(e=>e.models.map(e=>[e.id,e]))),t=Z(l).map(t=>e.get(t)).filter(e=>!!e).map(e=>P(e,"recent"));t.length&&a.push({key:"recent",head:p("session.composer.modelRecent","RECENT"),rows:t})}for(let e of F){let s=e.models.filter(a=>t(a,e.provider)).map(t=>P(t,e.provider));s.length&&a.push({key:e.provider,head:e.provider,rows:s})}return a},[x,l,F,L,P,p,M,y,z]),G=(0,i.useMemo)(()=>U.flatMap(e=>e.rows),[U]);(0,i.useEffect)(()=>{j(0)},[x]),(0,i.useEffect)(()=>{v>0&&v>=G.length&&j(0)},[v,G.length]),(0,i.useEffect)(()=>{g&&S.current[v]?.scrollIntoView?.({block:"nearest"})},[v,g]);let W=s?T.PALETTE_MODEL.label:T.ALL_MODELS.find(t=>
24t.id===e)?.label??I.flatMap(e=>e.models).find(t=>t.id===e)?.label??(e.startsWith("byo:")?e.split(":").slice(2).join(":"):T.AUTO_MODEL.label),K=e=>{if(l&&e)try{let t=[e,...Z(l).filter(t=>t!==e)].slice(0,3);localStorage.setItem(l,JSON.stringify(t))}catch{}a(e),f(!1)};return s?(0,t.jsxs)("button",{type:"button",className:r,disabled:!0,"aria-label":W,title:p("session.composer.secureModels","SECURE â ONLY PALETTE LLM · AI · TECH"),children:[(0,t.jsx)($.ModelMark,{name:"auto",className:"cdModelMark"}),(0,t.jsx)("span",{className:"cdModelName",children:W})]}):(0,t.jsxs)(Y.Popover.Root,{open:g,onOpenChange:e=>{f(e),e&&(b(""),w(B),j(0))},children:[(0,t.jsx)(Y.Popover.Trigger,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",ref:k,className:r,"aria-haspopup":M?"dialog":"listbox","aria-label":W,children:[(0,t.jsx)($.ModelMark,{name:X(e,O.get(e)),className:"cdModelMark"}),(0,t.jsx)("span",{className:"cdModelName",children:W}),(0,t.jsx)($.Glyph,{name:"h_chevronDown",className:`cdModelCaret${g?" open":""}`})]})}),(0,t.jsx)(Y.Popover.Portal,{container:k.current?.closest(".po-root")??void 0,children:(0,t.jsxs)(Y.Popover.Content,{className:`poModelPop${M?" tabbed":""}`,side:"top",align:"end",sideOffset:8,collisionPadding:8,onOpenAutoFocus:e=>{e.preventDefault(),M?document.getElementById(D)?.focus():N.current?.focus()},"aria-label":M?p("session.composer.modelPick","Select model"):void 0,"aria-labelledby":M?void 0:A,children:[M?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{id:A,className:"pmTabs",role:"tablist","aria-label":p("session.composer.modelProviders","Model providers"),onKeyDown:e=>{let t=z.findIndex(e=>e.key===y),a=-1;"ArrowRight"===e.key&&(a=(t+1)%z.length),"ArrowLeft"===e.key&&(a=(t-1+z.length)%z.length),"Home"===e.key&&(a=0),"End"===e.key&&(a=z.length-1),a<0||(e.preventDefault(),w(z[a].key),j(0),e.currentTarget.children[a]?.focus())},children:z.map(e=>(0,t.jsx)("button",{type:"button",role:"tab",id:`${_}-tab-${encodeURIComponent(e.key)}`,"aria-controls":R,"aria-selected":e.key===y,tabIndex:e.key===y?0:-1,className:`pmTab${e.key===y?" on":""}`,title:e.label,"aria-label":e.label,onClick:()=>{w(e.key),j(0)},children:(0,t.jsx)("span",{className:"pmProviderGlyph","data-provider":e.key,"aria-hidden":"true",children:et[e.key]?(0,t.jsx)("img",{className:"pmTabImg",src:et[e.key],alt:"",draggable:!1}):(0,t.jsx)($.ModelMark,{name:e.mark,className:"pmTabMark"})})},e.key))}),d&&u&&(m=Math.max(0,es.findIndex(e=>e.id===d)),h=`${_}-effort`,(0,t.jsxs)("div",{className:"pmEffort",children:[(0,t.jsx)("div",{id:h,className:"pmEffortHead",children:p("session.composer.effortHead","Reasoning effort")}),(0,t.jsx)("input",{type:"range",className:"pmRange",min:0,max:2,step:1,value:m,style:{"--pct":`${50*m}%`},"aria-labelledby":h,"aria-valuetext":p(`session.composer.effort.${d}`,es[m].label),onChange:e=>u(es[Number(e.target.value)]?.id??"high")}),(0,t.jsx)("div",{className:"pmEffortLabels",children:es.map(e=>(0,t.jsx)("button",{type:"button",tabIndex:-1,className:`pmEffortLbl${e.id===d?" on":""}`,"aria-pressed":e.id===d,onClick:()=>u(e.id),children:p(`session.composer.effort.${e.id}`,e.label)},e.id))})]}))]}):(0,t.jsx)("div",{id:A,className:"poModelHead",children:p("session.composer.modelHead","MODEL")}),!M&&(0,t.jsxs)("div",{className:"poModelFind poSearch",children:[(0,t.jsx)($.Glyph,{name:"h_search"}),(0,t.jsx)("input",{ref:N,role:"combobox","aria-expanded":"true","aria-controls":_,"aria-autocomplete":"list","aria-activedescendant":G[v]?.optId,"aria-label":p("session.composer.modelFilter","Filter models"),placeholder:p("session.composer.modelFilter","Filter models"),value:x,onChange:e=>b(e.target.value),onKeyDown:e=>{Q(e,G.length,v,j)?e.preventDefault():"Enter"===e.key&&G[v]&&(e.preventDefault(),K(G[v].id))}})]}),(0,t.jsx)("div",{className:"poModelPanel",id:M?R:void 0,role:M?"tabpanel":void 0,"aria-labelledby":M?D:void 0,children:(0,t.jsxs)("div",{id:_,ref:C,role:"listbox",className:"poModelList","aria-labelledby":M?D:A,tabIndex:M?0:void 0,"aria-activedescendant":M?G[v]?.optId:void 0,onKeyDown:M?e=>{Q(e,G.length,v,j)?e.preventDefault():("Enter"===e.key||" "===e.key)&&G[v]&&(e.preventDefault(),K(G[v].id))}:void 0,children:[U.map(a=>{let s=`${_}-h-${encodeURIComponent(a.key)}`;return(0,t.jsxs)("div",{role:"group","aria-labelledby":a.head?s:void 0,children:[a.head&&(0,t.jsxs)("div",{id:s,className:"poModelGroup",children:[a.head,M&&(0,t.jsx)("span",{className:"pmGroupHint",children:p("session.composer.modelPick","Select model")})]}),a.rows.map(a=>{let s=G.indexOf(a);return(0,t.jsxs)("div",{id:a.optId,ref:e=>{S.current[s]=e},role:"option","aria-selected":a.id===e,className:`poModelItem${a.id===e?" on":""}${s===v?" act":""}`,style:x?void 0:{"--i":s},onMouseMove:()=>j(s),onMouseDown:e=>e.preventDefault(),onClick:()=>K(a.id),children:[(0,t.jsx)($.ModelMark,{name:a.mark,className:"poModelMark"}),(0,t.jsx)("span",{className:"poModelName",children:a.label}),a.register&&(0,t.jsx)("span",{className:`poModelReg${"Error"===a.register?" err":""}`,children:p(`session.composer.reg${a.register}`)}),M&&a.id===e&&(0,t.jsx)($.Glyph,{name:"h_check",className:"pmCheck"})]},a.optId)})]},a.key)}),0===G.length&&(0,t.jsx)("div",{className:"poModelEmpty",role:"status","aria-live":"polite",children:p("session.composer.modelNone","No model matches")})]})})]})})]})}let es=[{id:"fast",label:"Low",glyph:"spark"},{id:"high",label:"Normal",glyph:"target"},{id:"max",label:"High",glyph:"orchestrator"}];var en=e.i(670378),el=e.i(266390),ei=e.i(423625),er=e.i(870691),eo=e.i(603869),ed=e.i(709382),ec=e.i(706347),eu=e.i(96213),em=e.i(549127),eh=e.i(964053),ep=e.i(702107);let eg={hash:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"5",y1:"9",x2:"19",y2:"9"}),(0,t.jsx)("line",{x1:"5",y1:"15",x2:"19",y2:"15"}),(0,t.jsx)("line",{x1:"10",y1:"4",x2:"8",y2:"20"}),(0,t.jsx)("line",{x1:"16",y1:"4",x2:"14",y2:"20"})]}),lock:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"5",y:"11",width:"14",height:"9"}),(0,t.jsx)("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]}),plus:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,t.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),send:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),(0,t.jsx)("polyline",{points:"6 11 12 5 18 11"})]}),reply:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("polyline",{points:"9 7 4 12 9 17"}),(0,t.jsx)("path",{d:"M4 12h9a6 6 0 0 1 6 6v1"})]}),bot:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),(0,t.jsx)("line",{x1:"12",y1:"4",x2:"12",y2:"8"}
24),(0,t.jsx)("circle",{cx:"9",cy:"14",r:"1.2",fill:"currentColor",stroke:"none"}),(0,t.jsx)("circle",{cx:"15",cy:"14",r:"1.2",fill:"currentColor",stroke:"none"})]}),pin:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"12",y1:"14",x2:"12",y2:"21"}),(0,t.jsx)("path",{d:"M8 4h8l-1 6 3 2v2H6v-2l3-2z"})]}),edit:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M4 20h4L19 9a2.1 2.1 0 0 0-3-3L5 17z"}),(0,t.jsx)("line",{x1:"14.5",y1:"6.5",x2:"17.5",y2:"9.5"})]}),bold:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M7 5h6a3.5 3.5 0 0 1 0 7H7z"}),(0,t.jsx)("path",{d:"M7 12h7a3.5 3.5 0 0 1 0 7H7z"})]}),italic:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"15",y1:"5",x2:"10",y2:"19"}),(0,t.jsx)("line",{x1:"11",y1:"5",x2:"18",y2:"5"}),(0,t.jsx)("line",{x1:"6",y1:"19",x2:"13",y2:"19"})]}),strike:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),(0,t.jsx)("path",{d:"M16 7.5A4 4 0 0 0 12.5 6h-1A3 3 0 0 0 9 10.5"}),(0,t.jsx)("path",{d:"M8 16.5A4 4 0 0 0 11.5 18h1a3 3 0 0 0 2.5-4.5"})]}),link:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M10.5 13.5a4 4 0 0 0 5.7 0l2.3-2.3a4 4 0 1 0-5.7-5.7L11.5 6.8"}),(0,t.jsx)("path",{d:"M13.5 10.5a4 4 0 0 0-5.7 0l-2.3 2.3a4 4 0 1 0 5.7 5.7l1.3-1.3"})]}),listUl:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"9",y1:"6",x2:"20",y2:"6"}),(0,t.jsx)("line",{x1:"9",y1:"12",x2:"20",y2:"12"}),(0,t.jsx)("line",{x1:"9",y1:"18",x2:"20",y2:"18"}),(0,t.jsx)("circle",{cx:"4.5",cy:"6",r:"1.2",fill:"currentColor",stroke:"none"}),(0,t.jsx)("circle",{cx:"4.5",cy:"12",r:"1.2",fill:"currentColor",stroke:"none"}),(0,t.jsx)("circle",{cx:"4.5",cy:"18",r:"1.2",fill:"currentColor",stroke:"none"})]}),listOl:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"10",y1:"6",x2:"20",y2:"6"}),(0,t.jsx)("line",{x1:"10",y1:"12",x2:"20",y2:"12"}),(0,t.jsx)("line",{x1:"10",y1:"18",x2:"20",y2:"18"}),(0,t.jsx)("path",{d:"M4 4.5h1.4V8"}),(0,t.jsx)("path",{d:"M3.6 10.6a1.2 1.2 0 0 1 2 .9c0 1-2 1.6-2 2.5h2.2"}),(0,t.jsx)("path",{d:"M3.7 16.4a1.1 1.1 0 1 1 1 1.6 1.1 1.1 0 1 1-1 1.6"})]}),quote:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"4",y1:"6",x2:"4",y2:"18"}),(0,t.jsx)("line",{x1:"9",y1:"8",x2:"20",y2:"8"}),(0,t.jsx)("line",{x1:"9",y1:"12",x2:"20",y2:"12"}),(0,t.jsx)("line",{x1:"9",y1:"16",x2:"16",y2:"16"})]}),code:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("polyline",{points:"9 7 4 12 9 17"}),(0,t.jsx)("polyline",{points:"15 7 20 12 15 17"})]}),codeBlock:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),(0,t.jsx)("polyline",{points:"9 10 7 12 9 14"}),(0,t.jsx)("polyline",{points:"14 10 16 12 14 14"})]}),at:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("circle",{cx:"12",cy:"12",r:"3.6"}),(0,t.jsx)("path",{d:"M15.6 8.4v4.8a2.6 2.6 0 0 0 5.2 0V12a8.8 8.8 0 1 0-3.4 6.9"})]}),compose:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M13 4H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7"}),(0,t.jsx)("path",{d:"M11.5 14.5H14L20.5 8a1.8 1.8 0 0 0-2.5-2.5L11.5 12z"})]}),bolt:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("polygon",{points:"13 3 5 13 11 13 10 21 19 11 13 11"})}),clock:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,t.jsx)("polyline",{points:"12 6 12 12 16.5 14.5"})]}),trash:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("polyline",{points:"4 7 20 7"}),(0,t.jsx)("path",{d:"M9 7V4h6v3"}),(0,t.jsx)("path",{d:"M6 7l1 13h10l1-13"})]}),inbox:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M3 13h5l1.5 3h5L16 13h5"}),(0,t.jsx)("path",{d:"M5 5h14l2 8v6H3v-6z"})]}),people:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("circle",{cx:"9",cy:"9",r:"3.2"}),(0,t.jsx)("path",{d:"M3 20a6 6 0 0 1 12 0"}),(0,t.jsx)("path",{d:"M16 6.2a3.2 3.2 0 0 1 0 5.6"}),(0,t.jsx)("path",{d:"M17 14.4A6 6 0 0 1 21 20"})]}),smile:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,t.jsx)("circle",{cx:"9",cy:"10",r:"1",fill:"currentColor",stroke:"none"}),(0,t.jsx)("circle",{cx:"15",cy:"10",r:"1",fill:"currentColor",stroke:"none"}),(0,t.jsx)("path",{d:"M8.5 14a4.5 4.5 0 0 0 7 0"})]}),clip:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("path",{d:"M20 11.5 12.3 19a4.6 4.6 0 0 1-6.5-6.5l7.6-7.6a3.1 3.1 0 0 1 4.4 4.4l-7.6 7.6a1.6 1.6 0 0 1-2.2-2.2l6.9-6.9"})}),x:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),(0,t.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"})]}),folder:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 3h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"})}),mic:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),(0,t.jsx)("path",{d:"M5 11a7 7 0 0 0 14 0"}),(0,t.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"21"})]}),micOff:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),(0,t.jsx)("path",{d:"M5 11a7 7 0 0 0 14 0"}),(0,t.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"21"}),(0,t.jsx)("line",{x1:"4",y1:"4",x2:"20",y2:"20"})]}),chev:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("polyline",{points:"9 6 15 12 9 18"})}),bell:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M6 16V11a6 6 0 0 1 12 0v5l2 3H4z"}),(0,t.jsx)("path",{d:"M10 19a2 2 0 0 0 4 0"})]}),bellOff:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M6 16V11a6 6 0 0 1 12 0v5l2 3H4z"}),(0,t.jsx)("path",{d:"M10 19a2 2 0 0 0 4 0"}),(0,t.jsx)("line",{x1:"4",y1:"4",x2:"20",y2:"20"})]}),headphones:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M4 14v-2a8 8 0 0 1 16 0v2"}),(0,t.jsx)("rect",{x:"2.5",y:"13",width:"4.5",height:"7",rx:"2"}),(0,t.jsx)("rect",{x:"17",y:"13",width:"4.5",height:"7",rx:"2"})]}),find:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("circle",{cx:"11",cy:"11",r:"6"}),(0,t.jsx)("line",{x1:"15.5",y1:"15.5",x2:"20",y2:"20"})]}),more:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("circle",{cx:"12",cy:"5",r:"1.3",fill:"
24currentColor",stroke:"none"}),(0,t.jsx)("circle",{cx:"12",cy:"12",r:"1.3",fill:"currentColor",stroke:"none"}),(0,t.jsx)("circle",{cx:"12",cy:"19",r:"1.3",fill:"currentColor",stroke:"none"})]}),thread:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("path",{d:"M4 6h16v9H9l-5 4z"}),(0,t.jsx)("line",{x1:"8",y1:"10.5",x2:"16",y2:"10.5"})]}),star:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("polygon",{points:"12 3.4 14.7 9.3 21.1 10.1 16.3 14.5 17.6 20.8 12 17.6 6.4 20.8 7.7 14.5 2.9 10.1 9.3 9.3"})}),hang:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("path",{d:"M3.5 10.5a13 13 0 0 1 17 0v3l-3.6.6-1-2.7a10 10 0 0 0-7.8 0l-1 2.7-3.6-.6z",transform:"rotate(135 12 12)"})}),call:(0,t.jsx)(t.Fragment,{children:(0,t.jsx)("path",{d:"M6 3h3l1.6 4-2 1.4a12 12 0 0 0 5 5l1.4-2 4 1.6v3a2 2 0 0 1-2.2 2A17 17 0 0 1 4 5.2 2 2 0 0 1 6 3z"})})};function ef(e){let s,n=(0,a.c)(5),{n:l,size:i,cls:r}=e,o=void 0===i?16:i,d=r?`tlIcon ${r}`:"tlIcon",c=31.200000000000003/o,u=eg[l];return n[0]!==o||n[1]!==d||n[2]!==c||n[3]!==u?(s=(0,t.jsx)("svg",{className:d,viewBox:"0 0 24 24",width:o,height:o,fill:"none",stroke:"currentColor",strokeWidth:c,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:u}),n[0]=o,n[1]=d,n[2]=c,n[3]=u,n[4]=s):s=n[4],s}Object.keys(eg),e.s(["TlIcon",0,ef],702748);let ex=e=>({filename:e.original_filename,file_url:e.file_url,mime_type:e.mime_type||"application/octet-stream",file_size:e.file_size||0});function eb(e,t,a){return{kind:"folder",roomId:e.id,roomName:e.name,targetId:t.id,targetName:t.name,suggestions:[a("contextPicker.folderSummarize","Summarize this folder"),a("c
24ontextPicker.folderKeyDocs","What are the key documents in this folder?"),a("contextPicker.folderRisks","What risks or action items should I know from this folder?")]}}function ev({onClose:e,onAttach:a,onUseContext:s,max:n=25}){let{t:l}=(0,c.useTranslation)("paletteOs"),[r,o]=(0,i.useState)([]),[d,h]=(0,i.useState)(null),[p,g]=(0,i.useState)([]),[f,x]=(0,i.useState)([]),[b,v]=(0,i.useState)([]),[j,y]=(0,i.useState)(new Map),[w,k]=(0,i.useState)(new Set),[N,C]=(0,i.useState)(new Map),[S,_]=(0,i.useState)(null),[T,E]=(0,i.useState)(!0),[A,R]=(0,i.useState)(!1),D=(0,i.useRef)(0),[M]=(0,i.useState)(()=>"u"<typeof document?null:document.activeElement),I=(0,i.useCallback)(async()=>{let e=++D.current;E(!0),R(!1);try{let t=await (0,m.apiFetch)("/api/v1/data-rooms");if(!t.ok)throw Error("Drive list unavailable");let a=await t.json();if(e!==D.current)return;o((Array.isArray(a)?a:[]).map(e=>({id:e.id,name:e.name})))}catch{e===D.current&&R(!0)}finally{e===D.current&&E(!1)}},[]);(0,i.useEffect)(()=>(I(),()=>{D.current+=1}),[I]);let O=async(e,t)=>{let a=++D.current;E(!0),R(!1),x([]),v([]);try{let s=await (0,m.apiFetch)(t?`/api/v1/data-rooms/${e}/folders/${t.id}`:`/api/v1/data-rooms/${e}`);if(!s.ok)throw Error("Drive contents unavailable");let n=await s.json();if(a!==D.current)return;x((n.folders??[]).map(e=>({id:e.id,name:e.name,files:e.files_count??0,subs:e.folders_count??0}))),v(n.files??[])}catch{a===D.current&&R(!0)}finally{a===D.current&&E(!1)}},P=async e=>{_(e.id);try{let t=await (0,m.apiFetch)(`/api/v1/data-rooms/${d.id}/folders/${e.id}/all-files`),a=await t.json(),s=a.filter(e=>!j.has(e.id)).slice(0,Math.max(0,n-j.size)),i=[...a.filter(e=>j.has(e.id)),...s].map(e=>e.id);if(i.length<a.length&&u.toast.warning(l("talk.pickCapped",{defaultValue:"Attached {{added}} of {{total}} files â the cap is {{max}}. Use USE AS CONTEXT for the whole folder.",added:i.length,total:a.length,max:n})),!i.length)return;y(e=>new Map([...e,...s.map(e=>[e.id,ex(e)])])),C(t=>new Map(t).set(e.id,{name:e.name,ids:i,total:a.length}))}catch{u.toast.error(l("talk.folderPickFailed","Could not read that folder"))}finally{_(null)}},L=b.length>0&&b.every(e=>j.has(e.id)),F=1===N.size&&0===w.size?[...N.entries()][0]:null,B=d?F?eb(d,{id:F[0],name:F[1].name},l):p.length?eb(d,p[p.length-1],l):{kind:"room",roomId:d.id,roomName:d.name,targetId:d.id,targetName:d.name,suggestions:[l("contextPicker.suggestSummarize","Summarize {{name}}",{name:d.name}),l("contextPicker.suggestKeyDocs","What are the key documents in {{name}}?",{name:d.name}),l("contextPicker.suggestRisks","What risks or action items should I know from {{name}}?",{name:d.name})]}:null,H=[{key:"root",name:l("talk.dataRoom","DRIVE"),go:()=>{h(null),g([]),x([]),v([]),I()}},...d?[{key:"room",name:d.name,go:()=>{g([]),O(d.id,null)}}]:[],...d?p.map((e,t)=>({key:`f${e.id}`,name:e.name,go:()=>{g(p.slice(0,t+1)),O(d.id,e)}})):[]],z=H.length>4?H.slice(2,H.length-2):[],U=z.length?[...H.slice(0,2),null,...H.slice(-2)]:H;return(0,t.jsx)(eh.Dialog.Root,{open:!0,onOpenChange:t=>{t||e()},children:(0,t.jsxs)(ep.OverlayPortal,{children:[(0,t.jsx)(eh.Dialog.Overlay,{className:"ssSearchBd"}),(0,t.jsxs)(eh.Dialog.Content,{className:"ssSearchDlg ssDlg roomPickDialog","aria-describedby":void 0,onCloseAutoFocus:e=>{e.preventDefault(),M?.isConnected?M.focus():document.querySelector(".po-root .chatComposer textarea, .po-root [contenteditable=true][role=textbox]")?.focus()},children:[(0,t.jsxs)("div",{className:"ssSearchHead",children:[(0,t.jsx)(eh.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:"Palette Drive"})}),(0,t.jsx)(eh.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{type:"button",className:"ssSearchClose","aria-label":l("talk.close","Close"),children:(0,t.jsx)($.Glyph,{name:"h_close"})})})]}),(0,t.jsx)("div",{className:"ssSearchBody ssDlgBody",children:(0,t.jsxs)("div",{className:"roomPick",children:[(0,t.jsxs)("header",{className:"roomPickHead",children:[a&&d&&b.length>0&&(0,t.jsx)("input",{className:"rlCheck",type:"checkbox",checked:L,onChange:()=>{if(L){let e=new Set(b.map(e=>e.id));y(t=>new Map([...t].filter(([t])=>!e.has(t)))),k(t=>new Set([...t].filter(t=>!e.has(t))));return}let e=b.filter(e=>!j.has(e.id)).slice(0,Math.max(0,n-j.size));e.length&&(y(t=>new Map([...t,...e.map(e=>[e.id,ex(e)])])),k(t=>new Set([...t,...e.map(e=>e.id)])))},title:l("talk.selectAllHere","Select every file in this folder"),"aria-label":l("talk.selectAllHere","Select every file in this folder")}),(0,t.jsx)("span",{className:"roomPickCrumb",children:U.map((e,a)=>(0,t.jsxs)(i.Fragment,{children:[a>0&&(0,t.jsx)(ef,{n:"chev",size:10}),e?(0,t.jsx)("button",{onClick:e.go,children:e.name}
24):(0,t.jsx)("button",{className:"roomPickGap",title:l("talk.crumbHidden",{defaultValue:"Go to {{name}}",name:z[z.length-1].name}),onClick:z[z.length-1].go,children:"â¦"})]},e?e.key:"gap"))})]}),(0,t.jsxs)("div",{className:"roomPickBody","aria-busy":T,children:[A&&(0,t.jsxs)("div",{className:"roomPickEmpty",role:"alert",children:[(0,t.jsx)("p",{children:l("talk.roomsFailed","Could not load drives")}),(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>{d?O(d.id,p.at(-1)??null):I()},children:l("talk.retry","Retry")})]}),T&&(0,t.jsx)("span",{className:"sr-only",role:"status",children:l("common:actions.loading","Loading...")}),!d&&!T&&!A&&r.map(e=>(0,t.jsxs)("button",{className:"roomPickRow",onClick:()=>{h(e),O(e.id,null)},children:[(0,t.jsx)($.Glyph,{name:"h_folder"}),(0,t.jsx)("span",{children:e.name})]},e.id)),!d&&!T&&!A&&0===r.length&&(0,t.jsx)("div",{className:"roomPickEmpty",children:l("talk.noRooms","No drives yet")}),T&&Array.from({length:5},(e,a)=>(0,t.jsxs)("div",{className:"roomPickSkel","aria-hidden":!0,children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${48+19*a%38}%`}})]},a)),d&&!T&&!A&&f.map(e=>{let s=N.get(e.id),n=0===e.files&&0===e.subs;return(0,t.jsxs)("div",{className:"roomPickRow roomPickRow--folder",children:[a&&(0,t.jsx)("input",{className:"rlCheck",type:"checkbox",disabled:n||S===e.id,checked:!!s,ref:e=>{e&&(e.indeterminate=!!s&&(s.ids.length<s.total||s.ids.some(e=>!j.has(e))))},onChange:()=>N.has(e.id)?(e=>{let t=N.get(e);if(!t)return;let a=new Set(w);for(let[t,s]of N)t!==e&&s.ids.forEach(e=>a.add(e));y(e=>{let s=new Map(e);for(let e of t.ids)a.has(e)||s.delete(e);return s}),C(t=>{let a=new Map(t);return a.delete(e),a})})(e.id):void P(e),"aria-label":l("talk.selectFolder",{defaultValue:"Select everything in {{name}}",name:e.name})}),(0,t.jsxs)("button",{className:"roomPickOpen",onClick:()=>{g([...p,e]),O(d.id,e)},children:[(0,t.jsx)($.Glyph,{name:"h_folder"}),(0,t.jsx)("span",{children:e.name})]}),(0,t.jsx)("span",{className:"roomPickCount",children:S===e.id?"â¦":e.files>0?`${e.files}${e.subs>0?"+":""}`:e.subs>0?"+":""})]},`f:${e.id}`)}),d&&!T&&!A&&b.map(i=>a?(0,t.jsxs)("label",{className:"roomPickRow roomPickRow--file",children:[(0,t.jsx)("input",{className:"rlCheck",type:"checkbox",checked:j.has(i.id),onChange:()=>{let e;((e=j.has(i.id))||!(j.size>=n))&&(y(t=>{let a=new Map(t);return e?a.delete(i.id):a.set(i.id,ex(i)),a}),k(t=>{let a=new Set(t);return e?a.delete(i.id):a.add(i.id),a}))}}),(0,t.jsx)($.Glyph,{name:"h_file"}),(0,t.jsx)("span",{children:i.original_filename})]},`d:${i.id}`):(0,t.jsxs)("button",{className:"roomPickRow",onClick:()=>{s?.({kind:"file",roomId:d.id,roomName:d.name,targetId:i.id,targetName:i.original_filename,suggestions:[l("contextPicker.suggestSummarize","Summarize {{name}}",{name:i.original_filename}),l("contextPicker.fileNumbers","What are the important numbers or dates in {{name}}?",{name:i.original_filename}),l("contextPicker.fileRisks","What risks, decisions, or action items are in {{name}}?",{name:i.original_filename})]}),e()},children:[(0,t.jsx)($.Glyph,{name:"h_file"}),(0,t.jsx)("span",{children:i.original_filename})]},`d:${i.id}`)),d&&!T&&!A&&0===f.length&&0===b.length&&(0,t.jsx)("div",{className:"roomPickEmpty",children:l("talk.emptyFolder","Nothing in here")})]}),(0,t.jsxs)("footer",{className:"roomPickFoot ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:e,children:l("common:actions.cancel","Cancel")}),s&&(0,t.jsx)("button",{className:"roomPickCtx cfBtn",disabled:!B,title:B?l("talk.useAsContextTarget",{defaultValue:"Scope this whole session to {{name}}",name:B.targetName}):l("talk.useAsContextTitle","Scope this whole session to what you are looking at"),onClick:()=>{B&&(s(B),e())},children:l("talk.useAsContext","USE AS CONTEXT")}),a&&(0,t.jsx)("button",{className:"cdSend cfBtn cfPrimary",disabled:0===j.size,onClick:()=>{a([...j.values()]),e()},children:l("talk.attachCount","ATTACH ({{count}})",{count:j.size})})]})]})})]})]})})}e.s(["ROOM_PICK_MAX",0,25,"RoomPicker",0,ev],168948);var ej=e.i(295692);function ey(e,t,a){let s=new Map;for(let t of e.flatMap(e=>e.attachments??[]))s.set(t.file_url,{key:t.file_url,name:t.filename,mime:t.mime_type,size:t.file_size,url:t.file_url,pending:!1});for(let e of t)s.has(e.file_url)||s.set(e.file_url,{key:e.file_url,name:e.filename,mime:e.mime_type,size:e.file_size,url:e.file_url,pending:!0});
24return[...s.values(),...[...new Set(a)].map((e,t)=>({key:`local:${t}:${e.name}:${e.size}:${e.lastModified}`,name:e.name,mime:e.type,size:e.size,file:e,pending:!0}))]}async function ew(e,t,a){if(e.file)return(await e.file.slice(0,2e5).text()).slice(0,5e4);if(!t)throw Error("Unavailable source");let s=await fetch(t,{signal:a});if(!s.ok||!s.body)throw Error("Preview unavailable");let n=s.body.getReader(),l=new TextDecoder,i="";try{for(;i.length<5e4;){let{value:e,done:t}=await n.read();if(t){i+=l.decode();break}i+=l.decode(e,{stream:!0})}return i.slice(0,5e4)}finally{await n.cancel()}}function ek(e){let s,n,l,r,o,d,u,m,h,p,g,f,x,b,v,j=(0,a.c)(75),{source:y,fallbackFocus:w,onClose:k,onDownload:N}=e,{t:C}=(0,c.useTranslation)("paletteOs");j[0]!==y.url?(s=function(e){if(!e)return null;try{let t=new URL(e,window.location.href);return["http:","https:"].includes(t.protocol)?t.href:null}catch{return null}}(y.url),j[0]=y.url,j[1]=s):s=j[1];let S=s;j[2]!==y.mime?(n=y.mime.startsWith("image/"),j[2]=y.mime,j[3]=n):n=j[3];let _=n;j[4]!==y.mime?(l=y.mime.startsWith("video/"),j[4]=y.mime,j[5]=l):l=j[5];let T=l;j[6]!==y.mime?(r=y.mime.startsWith("audio/"),j[6]=y.mime,j[7]=r):r=j[7];let E=r;j[8]!==y.mime||j[9]!==y.name?(o=y.mime.startsWith("text/")||/\.(md|csv|json)$/i.test(y.name),j[8]=y.mime,j[9]=y.name,j[10]=o):o=j[10];let A=o,[D,M]=(0,i.useState)(null),[I,O]=(0,i.useState)(null),[P,L]=(0,i.useState)(!1),[F,$]=(0,i.useState)(!0),[B,H]=(0,i.useState)(0);j[11]!==y.file?(d=()=>{if(!y.file)return;let e=URL.createObjectURL(y.file);return M(e),()=>{URL.revokeObjectURL(e)}},u=[y.file],j[11]=y.file,j[12]=d,j[13]=u):(d=j[12],u=j[13]),(0,i.useEffect)(d,u),j[14]!==S||j[15]!==y||j[16]!==A?(m=()=>{if(!A)return;let e=new AbortController;return O(null),L(!1),ew(y,S,e.signal).then(t=>{e.signal.aborted||O(t)}).catch(()=>{e.signal.aborted||L(!0)}),()=>e.abort()},j[14]=S,j[15]=y,j[16]=A,j[17]=m):m=j[17],j[18]!==B||j[19]!==S||j[20]!==y||j[21]!==A?(h=[y,S,A,B],j[18]=B,j[19]=S,j[20]=y,j[21]=A,j[22]=h):h=j[22],(0,i.useEffect)(m,h);let z=D??S,U=_||A||T;return j[23]!==B||j[24]!==E||j[25]!==P||j[26]!==z||j[27]!==y.name||j[28]!==T?(p=(T||E)&&z&&!P&&(T?(0,t.jsx)("video",{className:"ssSourceMedia",controls:!0,preload:"metadata",src:z,"aria-label":y.name,onError:()=>L(!0)},B):(0,t.jsx)("audio",{className:"ssSourceMedia",controls:!0,preload:"metadata",src:z,"aria-label":y.name,onError:()=>L(!0)},B)),j[23]=B,j[24]=E,j[25]=P,j[26]=z,j[27]=y.name,j[28]=T,j[29]=p):p=j[29],j[30]!==B||j[31]!==P||j[32]!==z||j[33]!==_||j[34]!==F||j[35]!==S||j[36]!==y.file||j[37]!==y.name||j[38]!==C||j[39]!==I||j[40]!==A?(g=_&&z&&!P?(0,t.jsx)("img",{className:"ssSourceImage",src:z,alt:y.name,hidden:F,onLoad:()=>$(!1),onError:()=>{L(!0),$(!1)}},B):A&&!P&&(y.file||S)?null===I?(0,t.jsx)("p",{className:"ssDlgP",role:"status",children:C("session.preview.sourceLoading")}):(0,t.jsx)("pre",{className:"ssSourceText",tabIndex:0,children:I}):null,j[30]=B,j[31]=P,j[32]=z,j[33]=_,j[34]=F,j[35]=S,j[36]=y.file,j[37]=y.name,j[38]=C,j[39]=I,j[40]=A,j[41]=g):g=j[41],j[42]!==P||j[43]!==_||j[44]!==F||j[45]!==S||j[46]!==y.file||j[47]!==C?(f=_&&!P&&F&&(y.file||S)&&(0,t.jsx)("p",{className:"ssDlgP",role:"status",children:C("session.preview.sourceLoading")}),j[42]=P,j[43]=_,j[44]=F,j[45]=S,j[46]=y.file,j[47]=C,j[48]=f):f=j[48],j[49]!==E||j[50]!==P||j[51]!==_||j[52]!==S||j[53]!==y.file||j[54]!==y.mime||j[55]!==y.size||j[56]!==C||j[57]!==A||j[58]!==T?(x=!P&&(y.file||S)?_||A||T||E?null:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("p",{className:"ssDlgP",children:[void 0===y.size?"â":`${(y.size/1024).toFixed(1)} KB`," · ",y.mime||C("session.preview.kindFile","File")]}),(0,t.jsx)("p",{className:"ssDlgP",children:C("session.preview.sourceUnsupported")})]}):(0,t.jsxs)("div",{role:"alert",children:[(0,t.jsx)("p",{className:"ssDlgP",children:C(y.file||S?"session.preview.sourceFailed":"session.preview.sourceUnavailable")}),(y.file||S)&&(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>{L(!1),$(!0),H(eN)},children:C("drive.share.retry","Retry")})]}),j[49]=E,j[50]=P,j[51]=_,j[52]=S,j[53]=y.file,j[54]=y.mime,j[55]=y.size,j[56]=C,j[57]=A,j[58]=T,j[59]=x):x=j[59],j[60]!==z||j[61]!==N||j[62]!==y.name||j[63]!==C?(b=(N||z)&&(0,t.jsx)("div",{className:"ssDlgActions",children:N?(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:N,children:C("session.preview.sourceDownload")}):(0,t.jsx)("a",{className:"cfBtn",href:z,download:y.name,target:"_blank",rel:"noopener noreferrer",children:C("session.preview.sourceDownload")})}),j[60]=z,j[61]=N,j[62]=y.name,j[63]=C,j[64]=b):b=j[64],j[65]!==w||j[66]!==k||j[67]!==y.name||j[68]!==U||j[69]!==p||j[70]!==g||j[71]!==f||j[72]!==x||j[73]!==b?(v=(0,t.jsxs)(R.ConversationDialog,{title:y.name,onClose:k,fallbackFocus:w,wide:U,children:[p,g,f,x,b]}),j[65]=w,j[66]=k,j[67]=y.name,j[68]=U,j[69]=p,j[70]=g,j[71]=f,j[72]=x,j[73]=b,j[74]=v):v=j[74],v}function eN(e){return e+1}e.s(["WorkSourceDialog",0,ek,"workSources",0,ey],729995);var eC=e.i(781623),eS=e.i(9979),e_=e.i(317230),eT=e.i(943094);function eE({artifact:e,threadId:a,studioActive:s,controls:n}){let{t:l}=(0,c.useTranslation)("paletteOs"),[r,o]=(0,i.useState)(null),[d,h]=(0,i.useState)(!1),[p,g]=(0,i.useState)(!1),[f,x]=(0,i.useState)(null),[b,v]=(0,i.useState)(!1),j=(0,i.useRef)(!1),y=(0,i.useRef)(null),[w,k]=(0,i.useState)(!1),N=async()=>
24{if(!s&&!j.current){j.current=!0,h(!0),g(!1),o(null);try{let t={kind:e.artifact_kind,content:e.content,structured:e.structured,url:e.url};if(!e.structured&&a){let s=await (0,m.apiFetch)(`/api/v1/general-chat/threads/${encodeURIComponent(a)}/artifacts/${encodeURIComponent(e.artifact_id)}/payload?revision=${e.revision??1}`);if(!s.ok)throw Error("artifact_payload_unavailable");let n=await s.json();if(n.revision!==(e.revision??1))throw Error("artifact_revision_mismatch");t=n}let s=t.content||"",n=(0,e_.validateStructured)(t.structured||(0,eS.openArtifactModel)(t.kind,s,e.title,t.url));o({title:e.title,artifactSlug:e.artifact_id,artifactKind:t.kind,structured:n,content:(0,e_.renderStructured)(n,s,e.title)})}catch(e){console.warn("Could not prepare artifact export:",e),g(!0)}finally{j.current=!1,h(!1)}}},C=async e=>{if(s){!n||n.disabled||n.exporting||await n.exportAs(e);return}if(r&&!j.current){j.current=!0,x(e);try{await (0,eT.exportStudioDraft)(e,{...r,transparent:b}),u.toast.success(l("session.preview.exportReady",{format:e.toUpperCase()}))}catch(t){console.warn("Artifact export failed:",t),u.toast.error(l("session.preview.exportFailed",{format:e.toUpperCase()}))}finally{j.current=!1,x(null)}}},S=s?n?.formats??[]:r?(0,eT.studioExportFormats)(r.structured.family):[],_=s?n?.exporting:f,T=(0,i.useRef)(!1);(0,i.useEffect)(()=>{T.current&&!_&&document.activeElement===document.body&&y.current?.focus(),T.current=!!_},[_]);let E=s?!n||n.disabled||!!_:d||!r||!!_,A=s?n?.transparent:r?.structured.deck?b:void 0;return(0,t.jsxs)(ej.DropdownMenu.Root,{open:w,onOpenChange:e=>{k(e),e&&!s&&N()},modal:!1,children:[(0,t.jsx)(ej.DropdownMenu.Trigger,{asChild:!0,children:(0,t.jsxs)("button",{ref:y,type:"button",className:"spvViewBtn spvExportMenuTrigger","aria-label":l("common:studio.export"),"aria-busy":!!_,disabled:!!_,children:[l(_?"common:studio.exporting":"common:studio.export"),(0,t.jsx)($.Glyph,{name:"h_chevronDown",className:"spvGlyph"})]})}),(0,t.jsx)(ej.DropdownMenu.Portal,{container:("u">typeof document?document.fullscreenElement:null)??y.current?.closest(".po-root")??void 0,children:(0,t.jsxs)(ej.DropdownMenu.Content,{className:"spvMenu",align:"end",sideOffset:6,collisionPadding:8,collisionBoundary:y.current?.closest(".sessPreview"),loop:!0,"aria-labelledby":void 0,"aria-label":l("common:studio.export"),children:[(d||s&&!n)&&(0,t.jsx)(ej.DropdownMenu.Item,{className:"spvMenuItem",disabled:!0,children:l("common:studio.loading")}),p&&!s&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{role:"alert",className:"spvMenuMessage",children:l("common:studio.loadFailed")}),(0,t.jsxs)(ej.DropdownMenu.Item,{className:"spvMenuItem",onSelect:e=>{e.preventDefault(),N()},children:[(0,t.jsx)($.Glyph,{name:"h_refresh",className:"spvGlyph"}),l("common:studio.retry")]})]}),void 0!==A&&(0,t.jsxs)(ej.DropdownMenu.CheckboxItem,{className:"spvMenuItem",checked:A,disabled:E,onSelect:e=>e.preventDefault(),onCheckedChange:e=>
24s?n?.setTransparent(e):v(e),children:[(0,t.jsx)("span",{className:"spvMenuCheck",children:(0,t.jsx)(ej.DropdownMenu.ItemIndicator,{children:(0,t.jsx)($.Glyph,{name:"h_check",className:"spvGlyph"})})}),l("common:studio.transparentExport")]}),S.map(e=>(0,t.jsxs)(ej.DropdownMenu.Item,{className:"spvMenuItem",disabled:E,onSelect:()=>void C(e),children:[(0,t.jsx)($.Glyph,{name:"h_download",className:"spvGlyph"}),e.toUpperCase()]},e)),s&&n?.disabled&&(0,t.jsx)("p",{role:"alert",className:"spvMenuMessage",children:l("common:studio.invalidContent")})]})})]})}var eA=e.i(655054),eR=e.i(47297),eD=e.i(819789),eM=e.i(430796);let eI="file:";function eO(e){return eI+e.url}let eP={fullscreen:"expand",dataRefresh:"refresh"};function eL(e){let s,n=(0,a.c)(2),{name:l}=e,i=`h_${eP[l]??l}`;return n[0]!==i?(s=(0,t.jsx)($.Glyph,{name:i,className:"spvGlyph",strokeWidth:1.6}),n[0]=i,n[1]=s):s=n[1],s}function eF(e,t){let a=[...e??[]].reverse().find(e=>"artifact"===e.kind);if(a)return a.artifact_id;let s=[...e??[]].reverse().find(e=>"file"===e.kind);return s?eO(s):t?.some(e=>"markdown"!==e.type)?ei.ARTIFACT_DATA_TAB:e?.some(e=>"app_plan"===e.kind||"app_build"===e.kind)?"app":null}function e$(e){return(0,f.isHtmlArtifactKind)(e)?"html":"svg"===e?"svg":"markdown"===e?"md":"video"===e?"mp4":"png"}function eB(e,t){let a=t.artifact_kind;return(0,f.isHtmlArtifactKind)(a)&&(0,eM.countArtifactSlides)(t.content??"")>=2?e("session.preview.kindSlides","HTML presentation"):"svg"===a?e("session.preview.kindSvg","SVG image"):"image"===a?e("session.preview.kindImage","Image"):"video"===a?e("session.preview.kindVideo","Video"):"dashboard"===a?e("session.preview.kindDashboard","Dashboard"):"report"===a?e("session.preview.kindReport","Report"):e("session.preview.kindDoc","Document")}let eH="section.slide, .slide";function ez(e){if(!["ArrowLeft","ArrowRight","Home","End"].includes(e.key))return;let t=e.currentTarget.closest('[role="tablist"], .spvOutputTabs'),a=Array.from(t?.querySelectorAll('button[role="tab"]')??[]),s=a.indexOf(e.currentTarget);if(s<0||a.length<2)return;e.preventDefault();let n="Home"===e.key?0:"End"===e.key?a.length-1:(s+("ArrowRight"===e.key?1:-1)+a.length)%a.length;a[n].focus(),a[n].click()}let eU=W.WORK_ZOOMS;function eG({artifacts:e,files:a,sources:s=[],activeId:n,onSelect:l,turns:r,generating:o,onClose:d,threadId:h,onSendMessage:x,onSeedComposer:b,onRefreshed:v,onAttachSource:j,workPanel:y,app:w}){let{t:k}=(0,c.useTranslation)("paletteOs"),N=(0,W.useWorkPanelState)(y?null:h),{state:C,update:S,select:_}=y??N,T=(0,i.useId)(),[E,A]=(0,i.useState)(null),[D,M]=(0,i.useState)({}),I=r.filter(t=>!t.artifactId||!e.some(e=>e.artifact_id===t.artifactId)),O=I.length>0,P=w&&("app"===n||n?.startsWith("app:"))?w.id:e.some(e=>e.artifact_id===n)||a?.some(e=>eO(e)===n)||n===ei.ARTIFACT_DATA_TAB&&O?n:e.at(-1)?.artifact_id??(a?.length?eO(a.at(-1)):O?ei.ARTIFACT_DATA_TAB:w?.id??null),L=!!w&&P===w.id,F=e.find(e=>e.artifact_id===P)??(P?null:e.at(-1)),$=r.find(e=>e.artifactId&&e.artifactId===F?.artifact_id&&e.artifactRevision===(F.revision??1)),B=$??I.find(e=>e.messageId===E)??I[0]??null,H=B?.panels??[],z=1===H.length&&"dashboard"===H[0].type?H[0]:{type:"dashboard",panels:H},U=z.title??H.find(e=>"hero"===e.type)?.caption??H.find(e=>"title"in e&&e.title)?.title,[G,K]=(0,i.useState)(!1),[V,Y]=(0,i.useState)({}),q=(0,i.useRef)(null),[J,X]=(0,i.useState)(null),Z=(0,i.useRef)(()=>{});async function Q(e){if(h&&!G){K(!0);try{let t=!1;try{t=(await (0,m.apiFetch)(`/api/v1/general-chat/threads/${h}/artifacts/${e.artifact_id}/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({base_revision:e.revision??1})})).ok}catch(e){if(e?.status===428||e?.status===409&&e?.detail?.code==="artifact_revision_conflict"){u.toast.error(k("common:artifactEditor.refreshConflict")),v?.();return}}if(t){u.toast.success(k("session.preview.refreshedToast","Data refreshed from source")),v?.();return}x?.(`Refresh the ${e.artifact_kind} artifact "${e.artifact_id}" with the latest data: re-run the queries/tools behind its numbers, then update it with create_artifact using the SAME artifact_id, fresh data bindings + data_provenance, and an updated "Data as of" stamp. Keep the layout unchanged.`),u.toast.info(k("session.preview.refreshAskToast","Asking the agent to refresh the dataâ¦"))}finally{K(!1)}}}let ee=(0,i.useRef)(null),[et,ea]=(0,i.useState)(null),es=P?.startsWith(eI)?(a??[]).find(e=>eO(e)===P)??null:null,[el,er]=(0,i.useState)({}),eo=L||P===ei.ARTIFACT_DATA_TAB||es?null:e.find(e=>e.artifact_id===P)??e[e.length-1]??null,ed=eo?el[`${h}:${eo.artifact_id}`]:null,ec=ed&&(ed.revision??1)>=(eo?.revision??1)?ed:eo,eu=!!$&&!!ec&&(ec.revision??1)===$.artifactRevision,em=ec?D[ec.artifact_id]??"report":"report",eh=P===ei.ARTIFACT_DATA_TAB||!L&&!ec&&
24!es&&O,ep=eh||eu&&"dashboard"===em,eg=ec&&(0,f.isHtmlArtifactKind)(ec.artifact_kind)?(0,en.panelArtifactFallback)(ec.content):null,ef=(0,i.useMemo)(()=>ec&&(0,f.isHtmlArtifactKind)(ec.artifact_kind)?(0,eM.countArtifactSlides)(ec.content??""):0,[ec]),ex=ef>=2,eb=(0,i.useMemo)(()=>ex&&ec?function(e){if(!e)return[];try{let t=new DOMParser().parseFromString(e,"text/html");return Array.from(t.querySelectorAll(eH)).filter(e=>!e.parentElement?.closest(eH)).map(e=>(e.querySelector("h1, h2, h3")?.textContent??e.textContent??"").trim().replace(/\s+/g," ").slice(0,60))}catch{return[]}}(ec.content??""):[],[ex,ec]),ev=ec?`${ec.artifact_id}#${ec.revision??1}`:null,ey=(0,i.useMemo)(()=>ec&&(0,f.isHtmlArtifactKind)(ec.artifact_kind)?(0,eM.countArtifactTables)(ec.content??""):0,[ec]),ew=(0,i.useMemo)(()=>{let t=new Set;for(let a of e)(0,f.isHtmlArtifactKind)(a.artifact_kind)&&(0,eM.countArtifactSlides)(a.content??"")>=2&&t.add(a.artifact_id);return t},[e]),eN=!ep&&!es&&!!ec&&(0,f.isHtmlArtifactKind)(ec.artifact_kind)&&!eg,eS=!!(h&&ec&&(0,f.canOpenArtifactStudio)(ec.artifact_kind,ec.structured)),e_=ex?"slides":"preview",eP=eN||!ep&&!es&&ec&&["image","svg"].includes(ec.artifact_kind),eF=ec?V[ec.artifact_id]??e_:"preview",eW=eP&&("doc"!==eF||eS)?eF:"preview",eK=e=>{ec&&("doc"!==e||eS)&&Y(t=>({...t,[ec.artifact_id]:e}))};Z.current=()=>{eS&&eK("doc")};let eV=`${h}:${ec?.artifact_id}`,[eY,eq]=(0,i.useState)(null),eJ=(0,i.useCallback)(e=>{eq(e?{key:eV,controls:e}:null)},[eV]),eX=(0,i.useMemo)(()=>new Set(C.closedTabs),[C.closedTabs]),eZ=C.hist;(0,i.useEffect)(()=>{P&&_(P)},[P,_]);let eQ=e=>{let t=tj(e);t<0||(S(e=>({...e,hist:{...eZ,cur:t}})),l(eZ.ids[t]))},[e0,e1]=(0,i.useState)(0),e2=C.notesOpen,e3=`po-work-notes:${h??""}`,[e4,e5]=(0,i.useState)("");(0,i.useEffect)(()=>{try{let e=window.localStorage.getItem(e3);if(null===e){let t=Object.keys(window.localStorage).filter(e=>e.startsWith(`${e3}:`)).map(e=>window.localStorage.getItem(e)).filter(e=>!!e);(e=[...new Set(t)].join("\n\n"))&&window.localStorage.setItem(e3,e)}e5(e)}catch{e5("")}},[e3]);let e6=C.zoom,e7=e=>S(t=>({...t,zoom:e})),[e8,e9]=(0,i.useState)(!1),[te,tt]=(0,i.useState)(null),ta=(0,i.useRef)(null),ts=(0,i.useRef)(null),tn=(0,i.useRef)(null),tl=(0,i.useRef)(null),[ti,tr]=(0,i.useState)(null),[to,td]=(0,i.useState)(null),tc=()=>{let e="lib"===te?tn.current:ts.current;e?.focus(),tt(null)};(0,i.useEffect)(()=>{tt(null),tr(null),td(null)},[h]);let[tu,tm]=(0,i.useState)(!1),th=(0,i.useRef)(!1),tp=async()=>{if(!th.current&&(ec||es)){th.current=!0,tm(!0);try{var e;if(es||ec?.artifact_kind==="image"||ec?.artifact_kind==="video"){let e=es?.url??ec?.url;if(!e)throw Error("missing_download_url");let t=document.createElement("a");t.href=e,t.download=es?.filename??`${ec.title.replace(/[^a-z0-9.-]+/gi,"_")}.${e$(ec.artifact_kind)}`,t.target="_blank",t.rel="noopener";try{document.body.appendChild(t),t.click()}finally{t.remove()}return}if(!ec)return;let t=(0,f.isHtmlArtifactKind)(ec.artifact_kind)?await (0,eM.withInlineChartRuntime)(ec.content??""):ec.content??"";(0,eT.downloadBlob)(new Blob([t],{type:(e=ec.artifact_kind,(0,f.isHtmlArtifactKind)(e)?"text/html":"svg"===e?"image/svg+xml":"video"===e?"video/mp4":"text/markdown")}),`${ec.title.replace(/[^a-z0-9.-]+/gi,"_")}.${e$(ec.artifact_kind)}`)}catch{u.toast.error(k("session.preview.downloadFailed"))}finally{th.current=!1,tm(!1)}}},tg=eY?.key===eV?eY.controls:null,tf="doc"===eW&&eS,tx=tu||tf&&(!tg||tg.disabled||!!tg.exporting||!tg.formats.includes("png")),tb=async()=>{if(!th.current&&!tx&&ec&&h){th.current=!0,tm(!0);try{if(tf)await tg.exportAs("png");else{let e=await (0,m.apiFetch)(`/api/v1/general-chat/threads/${encodeURIComponent(h)}/artifacts/${encodeURIComponent(ec.artifact_id)}/revisions/${ec.revision??1}/slides.zip`);if(!e.ok)throw Error("slides_export_failed");(0,eT.downloadBlob)(await e.blob(),`${ec.title.replace(/[^a-z0-9.-]+/gi,"_")}-r${ec.revision??1}-slides.zip`)}}catch{u.toast.error(k("session.preview.downloadFailed"))}finally{th.current=!1,tm(!1)}}},tv=[...w?[{id:w.id,name:w.name,letter:"A",sub:w.sub}]:[],...e.map(e=>({id:e.artifact_id,name:e.title,letter:ew.has(e.artifact_id)?"P":"image"===e.artifact_kind||"video"===e.artifact_kind||"svg"===e.artifact_kind?"I":"dashboard"===e.artifact_kind?"S":"D",sub:eB(k,e)})),...(a??[]).map(e=>({id:eO(e),name:e.filename,letter:"F",sub:k("session.preview.kindFile","File")})),...O?[{id:ei.ARTIFACT_DATA_TAB,name:!$&&U||k("session.preview.dataTab","Data"),letter:"S",sub:k("session.preview.kindData","Data")}]:[]];function tj(e){for(let t=eZ.cur+e;t>=0&&t<eZ.ids.length;t+=e)if(tv.some(e=>e.id===eZ.ids[t]))return t;return -1}let ty=L?w.id:eh?ei.ARTIFACT_DATA_TAB:es?eO(es):ec?.artifact_id??null,tw=tv.filter(e=>!eX.has(e.id)||e.id===ty),tk=e=>{let t=tw.findIndex(t=>t.id===e),a=tw.filter(t=>t.id!==e);if(S(t=>({...t,closedTabs:[...new Set([...t.closedTabs,e])]})),e!==ty){tl.current=ty;return}if(a.length){let e=a[Math.min(Math.max(t,0),a.length-1)].id;tl.current=e,l(e)}else d?.()},tN=tv.find(e=>e.id===ty)??null,tC=Math.max(0,tv.findIndex(e=>e.id===ty)),tS=e=>`${T}-output-${e}`,t_=`${T}-panel`,tT=eu?`${T}-research-${em}`:eN?`${T}-view-${eW}`:null,tE=!!(ec||ep||es),tA=eN&&ex&&"slides"===eW,tR=(0,i.useRef)(C.page);tR.current=C.activeId===P?C.page:0,(0,i.useEffect)(()=>
24{if(X(null),!tA)return;let e=!0,t=Math.min(tR.current,ef-1),a=a=>{let s=q.current?.contentWindow;if(!s||a.source!==s)return;let n=a.data?.__plttSlides;if(n){if(!0===n.edit)return void Z.current();if("number"==typeof n.current&&Number.isInteger(n.current)&&!(n.current<0)&&!(n.current>=ef)&&n.count===ef){if(e&&(e=!1,n.current!==t))return void s.postMessage({__plttSlidesNav:t},"*");X({current:n.current,count:ef}),S(e=>e.page===n.current?e:{...e,page:n.current})}}};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[ev,ef,tA,e0,h,S]);let tD=tE&&!ep&&"doc"!==eW,tM=es?es.filename.split(".").pop()?.toUpperCase()??"":ec?e$(ec.artifact_kind).toUpperCase():"";(0,i.useLayoutEffect)(()=>{if(!tl.current)return;let e=Array.from(ta.current?.querySelectorAll("[data-output-id]")??[]).find(e=>e.dataset.outputId===tl.current);e&&(e.focus(),tl.current=null)},[ty,eX]),(0,i.useEffect)(()=>{let e=()=>e9(document.fullscreenElement===ta.current),t=e=>{"Escape"!==e.key||e.defaultPrevented||document.fullscreenElement||e9(!1)};return document.addEventListener("fullscreenchange",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("fullscreenchange",e),document.removeEventListener("keydown",t)}},[]);let tI=()=>{e9(!e8),document.fullscreenElement===ta.current&&document.exitFullscreen().catch(()=>e9(!0))},tO=k("session.preview.menuFit","Fit to screen"),tP=e8?k("session.preview.restore","Restore work panel size"):k("session.preview.expand","Expand work panel"),tL=(e,a,s,n={})=>(0,t.jsx)("button",{type:"button","aria-label":e,title:e,onClick:s,...n,className:`spvIcon${n.className?` ${n.className}`:""}`,children:(0,t.jsx)(eL,{name:a})}),tF=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",onClick:()=>{tc(),tI()},children:[(0,t.jsx)(eL,{name:"panelRight"}),k("session.preview.menuExpand","Expand / restore panel")]})}),(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",onClick:()=>{tc(),document.fullscreenElement===ta.current?tI():(e9(!0),ta.current?.requestFullscreen?.().catch(()=>{}))},children:[(0,t.jsx)(eL,{name:"fullscreen"}),k("session.preview.menuFullscreen","Fullscreen")]})}),ty?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",onClick:()=>{tc(),tk(ty)},children:[(0,t.jsx)(eL,{name:"close"}),k("session.preview.menuCloseTab","Close current file tab")]})}):null,d?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",onClick:()=>{tc(),d()},children:[(0,t.jsx)(eL,{name:"panelRight"}),k("session.preview.menuClosePanel","Close panel")]})}):null]}),t$=(a,n)=>(0,t.jsx)(ej.DropdownMenu.Portal,{container:("u">typeof document?document.fullscreenElement:null)??ta.current?.closest(".po-root")??void 0,children:(0,t.jsx)(ej.DropdownMenu.Content,{className:"menu"===a?"spvMenu":"spvLib",align:"lib"===a?"start":"end",sideOffset:6,collisionPadding:8,collisionBoundary:ta.current,loop:!0,"aria-labelledby":void 0,"aria-label":"menu"===a?k("session.preview.more","More actions"):k("session.preview.library","Outputs and sources"),onCloseAutoFocus:e=>{document.activeElement?.closest('[role="dialog"], [data-output-id]')&&e.preventDefault()},children:"menu"===a&&L?(0,t.jsxs)(t.Fragment,{children:[n,n?(0,t.jsx)("span",{className:"spvMenuSep",role:"separator"}):null,tF]}):"menu"===a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",onClick:()=>{tc(),tN&&tr({name:tN.name,detail:ex&&ec?.artifact_id===tN.id?k("session.preview.infoPages",{defaultValue:"{{n}} pages · {{kind}}",n:ef,kind:tN.sub}):tN.sub})},children:[(0,t.jsx)(eL,{name:"file"}),k("session.preview.menuInfo","Result info")]})}),!ep&&(ec||es)?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",onClick:()=>{tc(),(()=>{if(es)return window.open(es.url,"_blank","noopener");
24if(ec){if("image"===ec.artifact_kind||"video"===ec.artifact_kind){ec.url&&window.open(ec.url,"_blank","noopener");return}h&&window.open(`/artifact/preview?thread=${encodeURIComponent(h)}&slug=${encodeURIComponent(ec.artifact_id)}&revision=${ec.revision??1}`,"_blank","noopener")}})()},children:[(0,t.jsx)(eL,{name:"external"}),k("session.preview.newTabTitle","Open in a new tab")]})}):null,h?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem spvFootShare",onClick:()=>{tc(),ea(es?{file:es}:ep?H.length>0?{panels:H}:null:ec?{artifactSlug:ec.artifact_id,revision:ec.revision??1}:null)},children:[(0,t.jsx)(eL,{name:"share"}),k("session.preview.menuShare","Share")]})}):null,!ep&&ec&&("dashboard"===ec.artifact_kind||"report"===ec.artifact_kind)&&x?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,disabled:G,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",disabled:G,onClick:()=>{tc(),Q(ec)},children:[(0,t.jsx)(eL,{name:"dataRefresh"}),k("session.preview.menuRefreshData","Refresh data")]})}):null,!ep&&ec?.artifact_kind==="carousel"&&h?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,disabled:tx,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",disabled:tx,"aria-busy":tu,onClick:()=>{tc(),tb()},children:[(0,t.jsx)(eL,{name:"image"}),k("session.preview.menuSlidesZip","Export slides as PNG")]})}):null,(0,t.jsx)("span",{className:"spvMenuSep",role:"separator"}),(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,disabled:!tD,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",disabled:!tD,onClick:()=>{tc(),e7("fit")},children:[(0,t.jsx)(eL,{name:"expand"}),tO]})}),tF]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"spvLibHead",children:(0,t.jsxs)("span",{children:[k("session.preview.libOutputs","Outputs")," ",(0,t.jsx)("small",{children:tv.length})]})}),tv.length?tv.map(a=>(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvLibRow",onClick:()=>{tc(),l(a.id)},children:[(0,t.jsx)("span",{className:"spvLibThumb","data-kind":a.letter,"aria-hidden":"true",children:a.letter}),(0,t.jsxs)("span",{className:"spvLibCopy",children:[(0,t.jsx)("strong",{children:a.name}),(0,t.jsx)("small",{children:ew.has(a.id)?k("session.preview.libPages",{defaultValue:"{{n}} pages · Presentation",n:e.find(e=>e.artifact_id===a.id)?(0,eM.countArtifactSlides)(e.find(e=>e.artifact_id===a.id).content??""):0}):a.sub})]}),a.id===ty?(0,t.jsx)(eL,{name:"check"}):null]})},a.id)):(0,t.jsx)("p",{className:"spvLibEmpty",children:k("session.preview.libNoOutputs","No outputs yet.")}),(0,t.jsxs)("div",{className:"spvLibHead",children:[(0,t.jsxs)("span",{children:[k("session.preview.libSources","Sources")," ",(0,t.jsx)("small",{children:s.length})]}),j?(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:tL(k("session.preview.libAttach","Add source file"),"plus",()=>{tc(),j()})}):null]}),s.length?s.map(e=>(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",className:"spvLibRow",onClick:()=>{tc(),td(e)},children:[(0,t.jsx)(eL,{name:"file"}),(0,t.jsxs)("span",{className:"spvLibCopy",children:[(0,t.jsx)("strong",{children:e.name}),(0,t.jsx)("small",{children:k(e.pending?"session.preview.sourcePending":"session.preview.sourceUsed")})]})]})},e.key)):(0,t.jsx)("p",{className:"spvLibEmpty",children:k("session.preview.libNoSources","Attach reference files with +.")})]})})});return(0,t.jsxs)("aside",{ref:ta,className:`sessPreview workPanel${e8?" spvExpanded":""}`,children:[(0,t.jsxs)("div",{className:"spvHead",children:[d?tL(k("session.preview.close","Close work panel"),"panelRight",d,{className:"spvToggle","aria-expanded":!0}):null,(0,t.jsxs)("div",{className:"spvOutputTabs",children:[(0,t.jsx)("div",{className:"sr-only",role:"tablist","aria-label":k("session.preview.outputTabs","Outputs"),"aria-owns":tw.map(e=>tS(tv.indexOf(e))).join(" ")}),tw.map(e=>{let a=tv.indexOf(e),s=e.id===ty;return(0,t.jsxs)("div",{className:`spvTabShell${s?" on":""}`,children:[(0,t.jsxs)("button",{id:tS(a),"data-output-id":e.id,role:"tab","aria-selected":s,"aria-controls":t_,"aria-keyshortcuts":"Delete",tabIndex:s?0:-1,onKeyDown:t=>{"Delete"===t.key?(t.preventDefault(),t.stopPropagation(),tk(e.id)):ez(t)},onClick:()=>l(e.id),className:`spvTab${s?" on":""}`,title:e.name,children:[(0,t.jsx)("span",{className:"spvTabKind","aria-hidden":"true",children:e.letter}),(0,t.jsx)("span",{className:"spvTabName",children:e.name})]}),(0,t.jsx)("button",{type:"button",className:"spvTabX",tabIndex:s?0:-1,"aria-label":k("session.preview.closeTab",{defaultValue:"Close {{name}} tab",name:e.name}),title:k("session.preview.closeTab",{defaultValue:"Close {{name}} tab",name:e.name}),onClick:()=>tk(e.id),children:(0,t.jsx)(eL,{name:"close"})})]},e.id)})]}),o?(0,t.jsxs)("span",{className:"spvRev spvGen",role:"status",children:[(0,t.jsx)("span",{className:"spvSpin","aria-hidden":!0}),k("session.preview.generating","Generatingâ¦")]}):null,(0,t.jsxs)(ej.DropdownMenu.Root,{open:"lib"===te,onOpenChange:e=>tt(e?"lib":null),modal:!1,children:[(0,t.jsx)(ej.DropdownMenu.Trigger,{asChild:!0,children:(0,t.jsx)("button",{ref:tn,type:"button",className:"spvIcon spvAdd","aria-label":k("session.preview.addFile","Open file"),title:k("session.preview.addFile","Open file"),children:(0,t.jsx)(eL,{name:"plus"})})}),t$("lib")]}),(0,t.jsx)("span",{className:"spvHeadEnd",children:tL(tP,e8?"panelRight":"exp
24and",tI,{className:"spvExpand","aria-pressed":e8})})]}),L?w.render({nav:e=>(0,t.jsxs)("div",{className:"spvNav",role:"group","aria-label":k("session.preview.fileNav","File navigation"),children:[tL(k("session.preview.back","Previous file"),"chevronLeft",()=>eQ(-1),{disabled:0>tj(-1)}),tL(k("session.preview.forward","Next file"),"chevronRight",()=>eQ(1),{disabled:0>tj(1)}),e]}),more:e=>(0,t.jsxs)(ej.DropdownMenu.Root,{open:"menu"===te,onOpenChange:e=>tt(e?"menu":null),modal:!1,children:[(0,t.jsx)(ej.DropdownMenu.Trigger,{asChild:!0,children:(0,t.jsx)("button",{ref:ts,type:"button",className:"spvIcon spvMore","aria-label":k("session.preview.more","More actions"),title:k("session.preview.more","More actions"),children:(0,t.jsx)(eL,{name:"more"})})}),t$("menu",e)]}),panel:{id:t_,role:"tabpanel","aria-labelledby":tS(tC)}}):(0,t.jsxs)(t.Fragment,{children:[tE?(0,t.jsxs)("div",{className:"spvTools",children:[(0,t.jsxs)("div",{className:"spvNav",role:"group","aria-label":k("session.preview.fileNav","File navigation"),children:[tL(k("session.preview.back","Previous file"),"chevronLeft",()=>eQ(-1),{disabled:0>tj(-1)}),tL(k("session.preview.forward","Next file"),"chevronRight",()=>eQ(1),{disabled:0>tj(1)}),tL(k("session.preview.refreshPreview","Refresh preview"),"refresh",()=>e1(e=>e+1))]}),(0,t.jsxs)("div",{className:"spvToolMid",children:[(0,t.jsx)("span",{className:"spvFile",title:tN?.name,children:tN?.name}),eu&&ec?(0,t.jsxs)("div",{className:"spvViewSeg",children:[(0,t.jsx)("div",{className:"spvViewTabs",role:"tablist","aria-label":k("session.preview.viewSeg","Output view"),children:["report","dashboard"].map(e=>(0,t.jsx)("button",{role:"tab",id:`${T}-research-${e}`,"aria-controls":t_,"aria-selected":em===e,tabIndex:em===e?0:-1,onKeyDown:ez,className:`spvViewBtn${em===e?" on":""}`,onClick:()=>M(t=>({...t,[ec.artifact_id]:e})),children:k(`session.preview.researchView.${e}`,"report"===e?"REPORT":"DASHBOARD")},e))}),(0,t.jsx)(eE,{artifact:ec,threadId:h,studioActive:!1,controls:null},`${eV}:${ec.revision??1}:research`)]}):eP?(0,t.jsxs)("div",{className:"spvViewSeg",children:[(0,t.jsx)("div",{className:"spvViewTabs",role:"tablist","aria-label":k("session.preview.viewSeg","Output view"),children:[...ex?[["slides",k("session.preview.viewSlides","SLIDES")]]:[],["preview",k("session.preview.viewPreview","PREVIEW")],...eS?[["doc",k("session.preview.viewDoc","STUDIO")]]:[],...ey>0?[["sheet",k("session.preview.viewSheet","SHEET")]]:[]].map(([e,a])=>(0,t.jsx)("button",{id:`${T}-view-${e}`,role:"tab","aria-selected":eW===e,"aria-controls":t_,tabIndex:eW===e?0:-1,onKeyDown:ez,className:`spvViewBtn${eW===e?" on":""}`,onClick:()=>eK(e),children:a},e))}),ec&&(0,t.jsx)(eE,{artifact:ec,threadId:h,studioActive:"doc"===eW&&eS,controls:eY?.key===eV?eY.controls:null},`${eV}:${ec.revision??1}:${eW}`)]}):null]}),(0,t.jsxs)("div",{className:"spvToolActs",children:[tL(k("session.preview.notes","Work notes"),"messageSquare",()=>{let e;return e=!e2,S(t=>({...t,notesOpen:e}))},{className:"spvNotesBtn","aria-pressed":e2,"aria-expanded":e2,"aria-controls":`${T}-note-area`}),!ep&&(ec||es)?tL(tu?k("session.preview.downloadPreparing"):k("session.preview.download",{defaultValue:"Download · {{ext}}",ext:tM}),"download",()=>{tp()},{disabled:tu,"aria-busy":tu}):null,(0,t.jsxs)(ej.DropdownMenu.Root,{open:"menu"===te,onOpenChange:e=>tt(e?"menu":null),modal:!1,children:[(0,t.jsx)(ej.DropdownMenu.Trigger,{asChild:!0,children:(0,t.jsx)("button",{ref:ts,type:"button",className:"spvIcon spvMore","aria-label":k("session.preview.more","More actions"),title:k("session.preview.more","More actions"),children:(0,t.jsx)(eL,{name:"more"})})}),t$("menu")]})]})]}):null,(0,t.jsx)(eR.PanelActionContext.Provider,{value:x??null,children:(0,t.jsxs)("div",{ref:ee,id:t_,role:"tabpanel","aria-labelledby":tN?`${tS(tC)}${tT?` ${tT}`:""}`:void 0,"aria-label":tN?void 0:k("session.preview.outputTabs","Outputs"),className:`spvBody${tA?" isDeck":""}`,style:{"--spv-zoom":"fit"===e6?1:e6/100},children:[o&&!es&&!ep&&!ec&&(0,t.jsx)("div",{className:"spvSkel","aria-hidden":!0,children:Array.from({length:7},(e,a)=>(0,t.jsx)("span",{className:"rlSkel",style:{width:`${0===a?46:92-17*a%38}%`}},a))}),es?"application/pdf"===es.mime_type?(0,t.jsx)("iframe",{title:es.filename,src:es.url,className:"spvFrame"},e0):es.mime_type.startsWith("image/")?(0,t.jsx)("div",{className:"spvImgWrap",children:(0,t.jsx)("img",{src:es.url,alt:es.filename,className:"spvImg"})}):(0,t.jsx)("div",{className:"spvFileWrap",children:(0,t.jsx)(p.AttachmentTile,{name:es.filename,mime:es.mime_type,size:es.size_bytes,url:es.url,href:es.url})}):ep?(0,t.jsx)("div",{className:"dashView",children:(0,t.jsxs)("div",{className:"spvData pvPanelView",children:[eh&&I.length>1&&B&&(0,t.jsxs)("div",{className:"spvTurnBar",children:[(0,t.jsxs)("span",{className:"spvTurnAge",children:[B===I[0]?k("session.preview.turnLatest","LATEST OUTPUT"):k("session.preview.turnEarlier","EARLIER OUTPUT"),B.timestamp?` \xb7 ${new Date(B.timestamp).toLocaleStr
24ing()}`:""]}),(0,t.jsx)("select",{className:"spvTurnPick",value:B.messageId,onChange:e=>A(e.target.value),"aria-label":k("session.preview.turnPickerLabel","Choose which output to view"),children:I.map((e,a)=>(0,t.jsxs)("option",{value:e.messageId,children:[0===a?k("session.preview.turnLatest","LATEST OUTPUT"):k("session.preview.turnNth",{defaultValue:"OUTPUT â{{n}}",n:a}),e.timestamp?` \xb7 ${new Date(e.timestamp).toLocaleTimeString()}`:""]},e.messageId))})]}),H.length>0&&(0,t.jsxs)(eA.SessionDashboard,{canvas:"light",theme:z.theme,children:[H.some(e=>"dashboard"===e.type)&&(0,t.jsx)("div",{className:"spvDraftNotice",role:"status",children:k("session.preview.unsavedDashboard","Unverified dashboard draft. This view has not been saved or validated. Check its figures against the sources.")}),(0,t.jsxs)("header",{className:"spvDashHead",children:[(0,t.jsx)("span",{className:"spvDashEyebrow",children:z.subtitle??`${k("session.preview.dataTab","Data")}${B?.timestamp?` \xb7 ${new Date(B.timestamp).toLocaleDateString()}`:""}`}),U?(0,t.jsx)("h3",{className:"spvDashTitle",children:U}):null]}),(0,t.jsx)(eR.PanelContentView,{panel:z})]})]})}):ec?"doc"===eW&&eS&&h?(0,t.jsx)(eC.ArtifactStudio,{threadId:h,artifactSlug:ec.artifact_id,revision:ec.revision,title:ec.title,assets:e.filter(e=>"image"===e.artifact_kind&&e.url).map(e=>({url:e.url,title:e.title})),onExportChange:eJ,onAskAgent:b,onSaved:e=>{er(t=>({...t,[eV]:{...ec,...e}})),v?.()},onClose:()=>eK("preview")}):"image"===ec.artifact_kind?(0,t.jsx)("div",{className:"spvImgWrap",children:(0,t.jsx)("img",{src:ec.url,alt:ec.title,className:"spvImg"})}):"video"===ec.artifact_kind?(0,t.jsx)("div",{className:"spvImgWrap",children:(0,t.jsx)("video",{src:ec.url,controls:!0,preload:"metadata",className:"spvImg"})}):"markdown"===ec.artifact_kind?(0,t.jsx)("div",{className:"spvMd",children:(0,t.jsx)(g.ChatMarkdown,{children:ec.content??""})}):eg?(0,t.jsx)("div",{className:"dashView",children:(0,t.jsx)("div",{className:"spvData pvPanelView",children:(0,t.jsx)(eA.SessionDashboard,{children:(0,t.jsx)(eR.PanelContentCard,{panel:{type:"dashboard",panels:eg}})})})}):(0,t.jsxs)(t.Fragment,{children:[tA?(0,t.jsx)("div",{className:"spvThumbs","aria-label":k("session.preview.pages","Pages"),children:Array.from({length:ef},(e,a)=>(0,t.jsxs)("button",{type:"button",className:`spvThumb${(J?.current??0)===a?" on":""}`,"aria-label":k("session.preview.pageN",{defaultValue:"Page {{n}}",n:a+1}),"aria-pressed":(J?.current??0)===a,onClick:()=>q.current?.contentWindow?.postMessage({__plttSlidesNav:a},"*"),children:[(0,t.jsx)("span",{className:"spvThumbNo",children:a+1}),(0,t.jsx)("span",{className:"spvThumbCard",children:(0,t.jsx)("small",{children:eb[a]})})]},a))}):null,(0,t.jsx)("div",{className:tA?"spvBoardScroll":"spvDoc",tabIndex:tA?0:void 0,children:(0,t.jsx)("div",{className:tA?"spvBoardCanvas":void 0,children:(0,t.jsx)("iframe",{ref:q,title:ec.title,srcDoc:"slides"===eW?(0,eM.withSlideRuntime)((0,eM.prepareArtifactHtml)(ec.content??"",!0,!0)):"sheet"===eW?(0,eM.buildSheetPreview)(ec.content??"",ec.title):(0,eM.prepareArtifactHtml)(ec.content??"",!0,!0),sandbox:"allow-scripts allow-popups allow-popups-to-escape-sandbox",className:`spvFrame${tA?" spvBoard":""}`},`${ec.artifact_id}-${ec.revision??1}-${eW}-${e0}`)})})]}):o?null:(0,t.jsxs)("div",{className:"spvEmpty",children:[(0,t.jsx)("span",{className:"spvEmptyIcon","aria-hidden":"true",children:(0,t.jsx)(eL,{name:"panelRight"})}),(0,t.jsx)("p",{children:k("session.preview.emptyTitle","Nothing open yet.")}),(0,t.jsx)("small",{children:k("session.preview.emptySub","Results you create in the conversation show up here.")})]})]})}),tD?(0,t.jsxs)("div",{className:"spvFoot",children:[(0,t.jsx)("div",{className:"spvPager",children:tA&&J?(0,t.jsxs)(t.Fragment,{children:[tL(k("session.preview.slidePrev","Previous slide"),"chevronLeft",()=>q.current?.contentWindow?.postMessage({__plttSlidesNav:"prev"},"*"),{disabled:J.current<=0}),(0,t.jsxs)("span",{className:"spvPageCount","aria-live":"polite",children:[J.current+1," / ",J.count]}),tL(k("session.preview.slideNext","Next slide"),"chevronRight",()=>q.current?.contentWindow?.postMessage({__plttSlidesNav:"next"},"*"),{disabled:J.current>=J.count-1})]}):null}),(0,t.jsxs)("div",{className:"spvZoomTools",children:[tL(tO,"expand",()=>e7("fit"),{className:"spvFit","aria-pressed":"fit"===e6}),(0,t.jsxs)("select",{className:"spvZoom",value:String(e6),onChange:e=>e7("fit"===e.target.value?"fit":Number(e.target.value)),"aria-label":k("session.preview.zoomLabel","Zoom"),children:[(0,t.jsx)("option",{value:"fit",children:k("session.preview.zoomFit","Fit")}),eU.map(e=>(0,t.jsxs)("option",{value:e,children:[e,"%"]},e))]})]})]}):null,e2?(0,t.jsxs)("section",{id:`${T}-note-area`,className:"spvNotes",children:[(0,t.jsxs)("label",{htmlFor:`${T}-notes`,children:[k("session.preview.notes","Work notes"),(0,t.jsx)("small",{children:k("session.preview.notesHint","This conversation · saved in this browser")})]}),(0,t.jsx)("textarea",{id:`${T}-notes`,className:"spvNotesArea",value:e4,placeholder:k("session.preview.notesPlaceholder","Jot down changes or ideas"),onChange:e=>{e5(e.target.value);try{window.localStorage.setItem(e3,e.target.value)}catch{}}})]}):null]}),ti&&(0,t.jsxs)(R.ConversationDialog,{title:k("session.preview.menuInfo","Result info"),onClose:()=>tr(null),fallbackFocus:ts,children:[(0,t.jsx)("p",{className:"ssDlgP",children:(0,t.jsx)("strong",{children:ti.name})}),(0,t.jsx)("p",{className:"ssDlgP",children:ti.detail})]}),to&&(0,t.jsx)(ek,{source:to,onClose:()=>td(null),fallbackFocus:tn},to.key),h?(0,t.jsx)(eD.ShareArtifactDialog,{paletteOs:!0,fallbackFocus:ts,open:null!==et,onOpenChange:e=>{e||ea(null)},threadId:h,target:et}):null]})}var eW=e.i(587583),eK=e.i(103590),eV=e.i(954243),eY=e.i(454170),eq=e.i(66447),eJ=e.i(687495),eX=e.i(341870),eZ=e.i(683934),eQ=e.i(815330),e0=e.i(268817),e1=e.i(901753),e2=e.i(452450);function e3({appId:e}){let{t:a}=(0,c.useTranslation)("messages"),[s,n]=i.default.useState(null),[l,r]=i.default.useState("loading"),[o,d]=i.default.useState(new Set(["backend","frontend","backend
24/api","frontend/src"])),[u,h]=i.default.useState(null),[p,g]=i.default.useState(""),[f,x]=i.default.useState("idle"),[b,v]=i.default.useState(!1),[j,y]=i.default.useState(!1),w=i.default.useRef(null),k=i.default.useCallback(async()=>{r("loading");try{let t=await (0,m.apiFetch)(`/api/v1/agent-apps/builds/${e}/source`);n(await t.json()),r("ready")}catch{r("failed")}},[e]);i.default.useEffect(()=>{k()},[k]);let N=i.default.useCallback(async t=>{w.current=t,h(t),x("loading");try{let a=await (0,m.apiFetch)(`/api/v1/agent-apps/builds/${e}/source/file?path=${encodeURIComponent(t)}`),s=await a.text();if(w.current!==t)return;g(s),x("idle")}catch{if(w.current!==t)return;g(""),x("failed")}},[e]),C=async()=>{if(s&&!b){v(!0),y(!1);try{let t=await (0,m.apiFetch)(`/api/v1/agent-apps/builds/${e}/source/download`),a=await t.blob(),n=URL.createObjectURL(a),l=document.createElement("a");l.href=n,l.download=`${s.plugin_id}-${s.version}.zip`,document.body.appendChild(l),l.click(),l.remove(),URL.revokeObjectURL(n)}catch{y(!0)}finally{v(!1)}}};if("loading"===l)return(0,t.jsx)("div",{className:"p-4 text-xs text-muted-foreground",children:a("appSource.loading","Loading sourceâ¦")});if("failed"===l||!s)return(0,t.jsxs)("div",{className:"flex flex-col items-start gap-2 p-4",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:a("appSource.loadFailed","Couldn't load the source")}),(0,t.jsx)("button",{type:"button",onClick:()=>void k(),className:"rounded border border-border px-2 py-1 text-xs hover:bg-muted",children:a("appSource.retry","Retry")})]});let S=new Set(s.changed_files.filter(e=>!e.startsWith("-"))),_=s.validation_report?.blockers??[],T="failed"!==s.status&&0===_.length,E=function(e){let t=[];for(let a of e){let e=a.path.split("/"),s=t,n="";for(let t=0;t<e.length;t++){n=n?`${n}/${e[t]}`:e[t];let l=t===e.length-1,i=s.find(a=>a.name===e[t]&&!!a.children!==l);i||(i=l?{name:e[t],path:n,size:a.size}:{name:e[t],path:n,children:[]},s.push(i)),l||(s=i.children)}}let a=e=>{for(let t of(e.sort((e,t)=>!!t.children-!!e.children||e.name.localeCompare(t.name)),e))t.children&&a(t.children)};return a(t),t}(s.files),A=(e,s)=>{if(e.children){let a=o.has(e.path);return(0,t.jsxs)(i.default.Fragment,{children:[(0,t.jsxs)("button",{type:"button",onClick:()=>d(t=>{let a=new Set(t);return a.has(e.path)?a.delete(e.path):a.add(e.path),a}),className:"flex w-full items-center gap-1 rounded px-1.5 py-0.5 text-left text-xs text-foreground hover:bg-muted",style:{paddingLeft:`${12*s+6}px`},children:[a?(0,t.jsx)(eQ.CaretDown,{size:10}):(0,t.jsx)(e0.CaretRight,{size:10}),(0,t.jsx)("span",{className:"font-medium",children:e.name})]}),a?e.children.map(e=>A(e,s+1)):null]},e.path)}return(0,t.jsxs)("button",{type:"button",onClick:()=>void N(e.path),className:`flex w-full items-center gap-1 rounded px-1.5 py-0.5 text-left text-xs hover:bg-muted ${u===e.path?"bg-muted text-foreground":"text-muted-foreground"}`,style:{paddingLeft:`${12*s+6}px`},children:[(0,t.jsx)(e2.FileText,{size:10,className:"shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:e.name}),S.has(e.path)?(0,t.jsx)("span",{className:"ml-auto shrink-0 rounded-full border border-amber-500/40 px-1.5 text-[9px] font-semibold uppercase text-amber-600 dark:text-amber-400",children:a("appSource.changedBadge","changed")}):null]},e.path)};return(0,t.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 border-b border-border px-3 py-2 text-xs",children:[(0,t.jsxs)("span",{className:"rounded-full border border-border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground tabular-nums",children:[a("appSource.revision","Rev {{n}}",{n:s.revision})," · v",s.version]}),(0,t.jsx)("span",{title:_.join(" · ")||void 0,className:`rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${T?"border-emerald-500/40 text-emerald-600 dark:text-emerald-400":"border-red-500/40 text-red-600 dark:text-red-400"}`,children:T?a("appSource.validationPassed","Validation passed"):a("appSource.validationFailed","Validation failed")}),S.size>0?(0,t.jsx)("span",{className:"rounded-full border border-border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:a("appSource.changed","{{count}} changed",{count:S.size})}):null,(0,t.jsxs)("button",{type:"button",onClick:()=>void C(),disabled:b,className:"ml-auto inline-flex items-center gap-1 rounded border border-border px-2 py-0.5 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",children:[(0,t.jsx)(e1.DownloadSimple,{size:12}),a("appSource.downloadZip","Download ZIP")]}),j?(0,t.jsx)("span",{className:"w-full text-[11px] text-muted-foreground",role:"alert",children:a("appSource.downloadFailed","Couldn't download the source. Try again.")}):null]}),(0,t.jsxs)("div",{className:"flex min-h-0 flex-1",children:[(0,t.jsx)("div",{className:"w-56 shrink-0 overflow-auto border-r border-border py-1.5",children:E.map(e=>A(e,0))}),(0,t.jsx)("div",{className:"min-w-0 flex-1 overflow-auto",children:null==u?(0,t.jsx)("p",{className:"p-4 text-xs text-muted-foreground",children:a("appSource.selectFile","Select a file to view it")}):"loading"===f?(0,t.jsx)("p",{className:"p-4 text-xs text-muted-foreground",children:a("appSource.loading","Loading sourceâ¦")}):"failed"===f?(0,t.jsx)("p",{className:"p-4 text-xs text-muted-foreground",children:a("appSource.loadFailed","Couldn't load the source")}):(0,t.jsx)("pre",{className:"whitespace-pre p-3 font-mono text-xs leading-5 text-foreground",children:p})})]})]})}var e4=e.i(957801),e5=e.i(424180),e6=e.i(976991);
24let e7=/data-block\s*=\s*["']([^"']+)["']/g;function e8(e,t){return{key:e,version:t,doc:t?(0,eX.withCsp)((0,eX.withCrashHook)((0,e6.withLiveHook)(t.html))):(0,eX.withCsp)((0,e6.liveAssemblyDocument)())}}function e9({live:e,title:a,screen:s,onScreen:n,onReport:l,onActiveVersion:r}){let{t:o}=(0,c.useTranslation)("messages"),d=i.default.useMemo(()=>({planned:o("artifactPreview.livePlanned","Planned"),writing:o("artifactPreview.liveWriting","Writingâ¦"),notInteractive:o("artifactPreview.liveNotInteractive","Not interactive yet â this part works once the app's script is connected."),updated:o("artifactPreview.liveUpdated","Updated"),needsFix:o("artifactPreview.liveNeedsFix","Needs a fix")}),[o]),u=o("artifactPreview.liveSampleText","Sample response â the app's assistant answers for real once the build finishes."),[m,h]=i.default.useState(()=>[e8(1,e.version)]),[p,g]=i.default.useState(1),[f,x]=i.default.useState(null),b=i.default.useRef(2),v=i.default.useRef(new Map),j=i.default.useRef(new Set),y=i.default.useRef(null),w=i.default.useRef({at:0,editing:!1}),k=i.default.useRef(null),N=i.default.useRef(null);!y.current&&e.sample&&(y.current=(0,eJ.createSampleStore)(e.sample));let C=i.default.useRef({slots:m,active:p,pending:f,live:e,screen:s,labels:d,onScreen:n,onReport:l,onActiveVersion:r});C.current={slots:m,active:p,pending:f,live:e,screen:s,labels:d,onScreen:n,onReport:l,onActiveVersion:r};let S=i.default.useCallback((e,t)=>{v.current.get(e)?.contentWindow?.postMessage(t,"*")},[]),_=i.default.useRef(""),T=i.default.useCallback((e,t=!1)=>{let{live:a,screen:s,labels:n}=C.current,l=!t&&a.draft.startsWith(_.current)?{append:a.draft.slice(_.current.length)}:{draft:a.draft};_.current=a.draft,S(e,{__palLive:{outline:a.outline,...l,screen:s??"",labels:n}})},[S]),E=i.default.useCallback((e,t)=>{let{live:a,labels:s}=C.current;S(e,{__palMark:{changed:t,issues:a.issues,labels:s}})},[S]),A=i.default.useCallback(e=>{let{slots:t,active:a}=C.current,s=t.find(t=>t.key===e),n=t.find(e=>e.key===a);if(!s||e===a)return;g(e),x(null);let l=n?.version&&s.version?s.version.changed:[];N.current=s.version?.n??null,E(e,l),window.setTimeout(()=>{h(t=>t.filter(t=>t.key===e||t.key>e))},220)},[E]),R=e.version?.n??null;i.default.useEffect(()=>{let e=C.current.live.version;e&&h(t=>{if(t.some(t=>t.version?.n===e.n))return t;let a=t.find(e=>e.key===C.current.active);return[...a?[a]:[],e8(b.current++,e)]})},[R]);let D=()=>w.current.editing||Date.now()-w.current.at<5e3,M=i.default.useCallback(e=>{j.current.add(e);let{slots:t,active:a,screen:s}=C.current,n=t.find(t=>t.key===e);if(!n)return;if(!n.version)return void T(e,!0);if(s&&(k.current=s,S(e,{__palShowScreen:s})),e===a){N.current=n.version.n,E(e,[]);return}if(e!==Math.max(...t.map(e=>e.key)))return;let l=t.find(e=>e.key===a);l?.version&&D()?x(e):window.setTimeout(()=>A(e),140)},[S,T,E,A]);i.default.useEffect(()=>{let e=e=>{let t=null;for(let[a,s]of v.current)if(s.contentWindow===e.source){t=a;break}if(null==t)return;let a=e.data;if(!a||"object"!=typeof a)return;let s=C.current.active;if(a.__palReady)M(t);else if("string"==typeof a.__palScreen&&t===s){let e=a.__palScreen.slice(0,120);k.current=e,C.current.onScreen(e)}else if(a.__palActivity&&t===s)w.current.at=Date.now();else if("boolean"==typeof a.__palEditing&&t===s)w.current.editing=a.__palEditing,w.current.at=Date.now();else if(a.__palRendered&&"object"==typeof a.__palRendered){let e=a.__palRendered,t=Array.isArray(e.blocks)?e.blocks.filter(e=>"string"==typeof e).slice(0,200):[];C.current.onReport?.({blocks:t,writing:"string"==typeof e.writing?e.writing:null})}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[M]);let I=m.find(e=>e.key===p)?.version??null;i.default.useEffect(()=>{C.current.onActiveVersion?.(I)},[I]),i.default.useEffect(()=>{if(null==f)return;let e=window.setInterval(()=>{D()||A(f)},1e3);return()=>window.clearInterval(e)},[f,A]);let O=m.find(e=>e.key===p&&!e.version);i.default.useEffect(()=>{O&&j.current.has(O.key)&&T(O.key)},[O,e.outline,e.draft,d,T]),i.default.useEffect(()=>{if(!s)return;let e=C.current.slots.find(e=>e.key===p);
24e&&j.current.has(e.key)&&(e.version?k.current!==s&&(k.current=s,S(e.key,{__palShowScreen:s})):T(e.key))},[s,p,S,T]),i.default.useEffect(()=>{let e=C.current.slots.find(e=>e.key===p);e?.version&&j.current.has(e.key)&&N.current===e.version.n&&E(e.key,[])},[e.issues,p,E]);let P=i.default.useRef(u);P.current=u;let L=i.default.useRef(new Map);return i.default.useEffect(()=>{let e=new Set(m.map(e=>e.key));for(let t of[...L.current.keys()])e.has(t)||(L.current.delete(t),j.current.delete(t))},[m]),(0,t.jsxs)("div",{className:"alpStage",children:[m.map(e=>{var s,n;let l,i=e.key===p;return(0,t.jsx)("iframe",{ref:(s=e.key,n=null!=e.version,(l=L.current.get(s))||(l=e=>{if(!e)return;v.current.set(s,e);let t=n?(0,eJ.attachSampleBridge)({iframe:e,store:y.current??=(0,eJ.createSampleStore)(null),sampleText:P.current}):null;return()=>{t?.dispose(),v.current.get(s)===e&&v.current.delete(s)}},L.current.set(s,l)),l),title:a,srcDoc:e.doc,sandbox:"allow-scripts allow-forms",referrerPolicy:"no-referrer",className:"alpFrame","data-active":i?"":void 0,"data-kind":e.version?"version":"assembly","aria-hidden":!i||void 0,inert:!i,tabIndex:i?void 0:-1},e.key)}),null!=f?(0,t.jsxs)("div",{className:"alpUpdate",role:"status",children:[(0,t.jsx)("span",{children:o("artifactPreview.liveUpdateReady","An updated version is ready")}),(0,t.jsx)("button",{type:"button",onClick:()=>A(f),children:o("artifactPreview.liveApplyUpdate","Show it now")})]}):null]})}var te=e.i(928264);let tt={desktop:void 0,tablet:768,mobile:390};function ta(e){let s,n=(0,a.c)(2),{name:l}=e,i=`h_${l}`;return n[0]!==i?(s=(0,t.jsx)($.Glyph,{name:i,className:"spvGlyph",strokeWidth:1.6}),n[0]=i,n[1]=s):s=n[1],s}function ts({chrome:e,plan:a,building:s,stopped:n,app:l,isOwner:r,readiness:o,qualityAction:d,onQualityAction:h,onPublish:p,onOpenWindow:g,onCancelBuild:f,onRenamed:x,onRetired:b,onInspect:v}){let{t:j}=(0,c.useTranslation)("messages"),y=(0,e5.useAppBuildCounter)(s?.phases??[],null!=s),w=null!=s&&(0,e5.waitingStep)(s.phases,!0)>=0&&s.queue?.state!=="running",[k,N]=(0,i.useState)(0),[C,S]=(0,i.useState)(null),[_,T]=(0,i.useState)(null),[E,A]=(0,i.useState)("desktop"),[R,D]=(0,i.useState)("app"),[M,I]=(0,i.useState)(!1),[O,P]=(0,i.useState)(null),[L,F]=(0,i.useState)(""),[$,B]=(0,i.useState)(null),[H,z]=(0,i.useState)(!1),[U,G]=(0,i.useState)(null),W=(0,i.useRef)(new Set),[K,V]=(0,i.useState)(new Set),Y=(0,i.useContext)(eo.AppLiveBuildContext),q=Y?.appId??null,J=Y?.unavailable??!1,X=l?null:s?.appId??n?.appId??null,Z=null!=q&&(X===q||l?.appId===q)?Y?.live??null:null,[Q,ee]=(0,i.useState)(!1),et=null!=X&&null==Z&&!J;(0,i.useEffect)(()=>{if(ee(!1),!et)return;let e=window.setTimeout(()=>ee(!0),3e3);return()=>window.clearTimeout(e)},[et,X]);let[ea,es]=(0,i.useState)(null),[en,el]=(0,i.useState)({blocks:[],writing:null}),[ei,er]=(0,i.useState)(null),[ed,ec]=(0,i.useState)(!1),eu=(0,i.useRef)(q);(0,i.useEffect)(()=>{eu.current!==q&&(eu.current=q,es(null),el({blocks:[],writing:null}),er(null),ec(!1))},[q]);let em=null!=l&&null!=Z&&l.appId===q&&!ed;(0,i.useEffect)(()=>{if(!em)return;let e=window.setTimeout(()=>ec(!0),8e3);return()=>window.clearTimeout(e)},[em]);let eh=(0,i.useCallback)(()=>window.setTimeout(()=>ec(!0),120),[]),ep=l?.agentId??null;(0,i.useEffect)(()=>{S(null),I(!1),P(null),D("app")},[ep]),(0,i.useEffect)(()=>{if(B(null),null==ep)return;let e=!0,t=t=>{t.detail?.agentId===ep&&(0,e4.fetchAppSetup)(ep).then(t=>{e&&t&&B(t)})};return window.addEventListener(eJ.AGENT_APP_OPEN_SETUP_EVENT,t),()=>{e=!1,window.removeEventListener(eJ.AGENT_APP_OPEN_SETUP_EVENT,t)}},[ep]);let eg=(0,i.useCallback)(e=>S(e.revision),[]),ef=(0,i.useCallback)(e=>{I(!1),v?.(e)},[v]),ex=async(e,t)=>{if(t&&!U){G(e);try{await t()}finally{G(null)}}},eb=async()=>{if(!l||!p||W.current.has(l.agentId))return;let e=l.agentId;W.current.add(e),V(new Set(W.current));try{await p()}catch{u.toast.error(j("artifactPreview.publishFailed","Couldn't publish the app. Try again."))}finally{W.current.delete(e),V(new Set(W.current))}},ev=async()=>{if(l&&!H){z(!0);try{await (0,m.apiFetch)(`/api/v1/agent-apps/${l.agentId}/preview/reset`,{method:"POST"}),u.toast.success(j("artifactPreview.resetTestDataDone","Test data reset.")),N(e=>e+1)}catch(t){let e=t instanceof Error?t.message:"";u.toast.error("preview_shares_live"===e?j("artifactPreview.resetTestDataShared","This preview still shares live data; rebuild the app first."):j("artifactPreview.resetTestDataFailed","Couldn't reset the test data. Try again."))}finally{z(!1)}}},ey=()=>{l&&(0,e4.renameAgentApp)(l.agentId,L).then(e=>{P(null),e&&x?.(e)})},ew=(e,a,s,n=!1)=>(0,t.jsx)(ej.DropdownMenu.Item,{asChild:!0,disabled:n,children:(0,t.jsxs)("button",{type:"button",role:"menuitem",className:"spvMenuItem",disabled:n,onClick:s,children:[(0,t.jsx)(ta,{name:e}),a]})}),ek=(a,s,n,l)=>(0,t.jsxs)("div",{className:"spvTools",children:[e.nav(l),(0,t.jsx)("div",{className:"spvToolMid",children:a}),(0,t.jsxs)("div",{className:"spvToolActs",children:[s,e.more(n)]})]}),eN=(e,a)=>(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"spvFile",title:e,children:e}),a]});if(l){let a="full_stack"===l.runtimeMode,n=l.publishPending??"published"!==l.status,i=!!(l.publishing||K.has(l.agentId)),c=!!(a&&r&&null!=l.appId),u=c&&"files"===R,m=tt[E],x=(0,t.jsx)("span",{className:"spvChip","data-tone":"published"!==l.status||n&&r?void 0:"live",children:"published"===l.status&&n&&r?j("artifactPreview.unpublishedChanges","Unpublished changes"):"published"===l.status?j("artifactPreview.appPublished","Published"):j("artifactPreview.appPreview","Preview")});return(0,t.jsxs)(t.Fragment,{children:[ek((0,t.jsxs)(t.Fragment,{children:[eN(l.name,x),null!=C?(0,t.jsxs)("span",{className:"spvChip tabular-nums",title:j("artifactPreview.versionChip","Revision {{n}} is live in this preview",{n:C}),children:["v",C]}):null,n&&r&&o?(0,t.jsx)("span",{className:"spvChip","data-tone":"ready"===o.overall?"ok":"ready_with_warnings"===o.overall?"warn":"attn",title:o.failing.length?o.failing.join(" · "):void 0,children:"ready"===o.overall?j("artifactPreview.readyChip","Ready to publish"):"ready_with_warnings"===o.overall?j("artifactPreview.readyWarnChip","Minor warnings"):j("artifactPreview.readyAttnChip","Needs attention")}):null,c?(0,t.jsx)("div",{className:"spvViewSeg",children:(0,t.jsx)("div",{className:"spvViewTabs",role:"group","aria-label":j("artifactPreview.appViewLabel","App view"),children:["app","files"].map(e=>(0,t.jsx)("button",{type:"button","aria-pressed":R===e,className:`spvViewBtn${R===e?" on":""}`,onClick:()=>D(e),children:"app"===e?j("artifactPreview.viewApp","App"):j("artifactPreview.filesTab","Files")},e))})}):null]}),(0,t.jsxs)(t.Fragment,{children:[!v||a||u?null:(0,t.jsx)("button",{type:"button",className:"spvIcon",onClick:()=>I(e=>!e),"aria-pressed":M,title:j("artifactPreview.inspectToggle","Select an element to change â click it in the preview"),"aria-label":j("artifactPreview.inspectToggle","Select an element to change â click it in the preview"),children:(0,t.jsx)(eK.CursorClick,{size:17})}),n&&p&&r?(0,t.jsxs)("button",{type:"button",className:"spvPrimaryBtn",onClick:()=>void eb(),disabled:i||!!s,"aria-busy":i,children:[i?(0,t.jsx)(eW.CircleNotch,{size:13,className:"animate-spin motion-reduce:animate-none","aria-hidden":"true"}):null,i?j("artifactPreview.publishing","Publishingâ¦"):"published"===l.status?j("artifactPreview.publishUpdate","Publish update"):j("artifactPreview.publishApp","Publish")]}):null]}),(0,t.jsxs)(t.Fragment,{children:[g&&"published"===l.status?ew("external",j("artifactPreview.openWindow","Open in a window"),g):null,r?(0,t.jsxs)(t.Fragment,{children:[a&&_?.previewSharesLive?null:ew("refresh",H?j("artifactPreview.resettingTestData","Resettingâ¦"):j("artifactPreview.resetTestData","Reset test data"),()=>void ev(),H||!!s),ew("pencil",j("agentApp.rename","Rename"),()=>{F(l.name),P("rename")}
24),ew("clock",j("agentApp.versionHistory","Version history"),()=>P(e=>"versions"===e?null:"versions")),ew("shield",j("agentApp.health.open","App health"),()=>P(e=>"health"===e?null:"health")),ew("archive",j("agentApp.retire","Retire app"),()=>{(0,e4.retireAgentApp)(l.agentId,j("agentApp.retireConfirm","Retire this app? It leaves your library and its schedule stops.")).then(e=>{e&&b?.()})})]}):null]}),(0,t.jsx)("button",{type:"button",className:"spvIcon",onClick:()=>N(e=>e+1),title:j("artifactPreview.refresh","Refresh preview"),"aria-label":j("artifactPreview.refresh","Refresh preview"),children:(0,t.jsx)(ta,{name:"refresh"})})),s?(0,t.jsxs)("div",{className:"spvAppNote","data-tone":"live",role:"status",children:[(0,t.jsx)("span",{className:"spvLiveDot","aria-hidden":"true"}),(0,t.jsxs)("span",{className:"spvAppNoteText",children:[j("artifactPreview.rebuilding","Updating {{name}}â¦",{name:s.name}),y?(0,t.jsxs)("span",{className:"spvAppNoteMeta",children:[" · ",y]}):null]}),f?(0,t.jsx)("button",{type:"button",className:"spvTextBtn",onClick:()=>void ex("cancel",f),disabled:null!=U,children:j("artifactPreview.stopBuild","Stop")}):null]}):null,r?(0,t.jsxs)("p",{className:"spvAppNote",children:[a&&_?(0,t.jsx)("span",{className:"spvChip",children:"personal"===_.dataScope?j("artifactPreview.dataScopePersonal","Personal data"):j("artifactPreview.dataScopeOrg","Shared org data")}):null,(0,t.jsxs)("span",{className:"spvAppNoteText",children:[n?("published"===l.status?j("artifactPreview.unpublishedChangesHint","You're testing unpublished changes. People you've shared the app with keep using the published version until you publish this update."):j("artifactPreview.privatePreviewHint","Only you can open this preview. Publish to add the app to your library; sharing is your choice."))+" ":null,a&&_?.previewSharesLive?j("artifactPreview.previewDataSharedHint","This app was published before test data was separated, so this preview still uses the live data. The next rebuild gives the preview its own test data."):j("artifactPreview.previewDataHint","This preview uses separate test data. Nothing you add, edit or delete here reaches the published app.")]})]}):null,$?(0,t.jsx)(e4.AppSetupStrip,{agentId:l.agentId,setup:$,onChange:B,onClose:()=>B(null)}):null,r&&d&&h&&!s?(0,t.jsxs)("div",{className:"spvAppNote","data-tone":"warn",role:"status",children:[(0,t.jsx)("span",{className:"spvAppNoteText",children:"recheck"===d?j("artifactPreview.qualityUnverified","The automatic quality review couldn't run for this version. You can publish as is, or re-check it first."):j("artifactPreview.qualityNeedsPass","This version is below the automatic quality bar. Publish as is, improve it, or ask for a specific change in chat.")}),(0,t.jsxs)("button",{type:"button",className:"spvPrimaryBtn",onClick:()=>void ex("quality",h),disabled:null!=U,"aria-busy":"quality"===U,children:["quality"===U?(0,t.jsx)(eW.CircleNotch,{size:13,className:"animate-spin motion-reduce:animate-none","aria-hidden":"true"}):null,"recheck"===d?j("artifactPreview.recheckQuality","Re-check quality"):j("artifactPreview.improveApp","Improve it")]})]}):null,"rename"===O?(0,t.jsxs)("div",{className:"spvAppNote",children:[(0,t.jsx)("input",{autoFocus:!0,value:L,onChange:e=>F(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),ey()):"Escape"===e.key&&(e.preventDefault(),P(null))},"aria-label":j("agentApp.renameLabel","App name"),className:"spvAppInput"}),(0,t.jsx)("button",{type:"button",className:"spvPrimaryBtn",onClick:ey,children:j("agentApp.rename","Rename")}),(0,t.jsx)("button",{type:"button",className:"spvTextBtn",onClick:()=>P(null),children:j("agentApp.close","Close")})]}):null,"health"===O?(0,t.jsx)(e4.AppHealthStrip,{agentId:l.agentId,onClose:()=>P(null)}):null,"versions"===O?(0,t.jsx)(e4.AppVersionStrip,{agentId:l.agentId,onClose:()=>P(null),onRestored:()=>N(e=>e+1)}):null,(0,t.jsx)("div",{className:"spvBody spvAppPage spvAppBody",...e.panel,children:u&&null!=l.appId?(0,t.jsx)("div",{className:"spvAppStage overflow-auto",children:(0,t.jsx)(e3,{appId:l.appId})}):(0,t.jsxs)("div",{className:"spvAppStage",style:m?{width:m,maxWidth:"100%"}:void 0,children:[a?(0,t.jsx)(eZ.AgentAppPluginHost,{agentId:l.agentId,audience:r?"preview":"published",refreshToken:k,onRuntimeLoaded:e=>{T({dataScope:e.dataScope,previewSharesLive:e.previewSharesLive}),eh()},title:l.name},"app"):(0,t.jsx)(eX.AgentAppFrame,{agentId:l.agentId,title:l.name,pollRevision:!0,draft:r,refreshToken:k,onLoaded:eg,inspect:M,onInspect:v?ef:void 0,openChat:()=>{},initialScreen:ea,onScreen:es,onFrameReady:eh},"app"),em&&Z?(0,t.jsx)("div",{className:"spvLiveLayer","data-handoff":"","aria-hidden":"true",children:(0,t.jsx)(e9,{live:Z,title:l.name,screen:ea,onScreen:es})},"live"):null]})},"stage"),u?null:(0,t.jsxs)("div",{className:"spvFoot",children:[(0,t.jsx)("div",{className:"spvPager"}),(0,t.jsx)("div",{className:"spvZoomTools",role:"group","aria-label":j("artifactPreview.viewportLabel","Preview size"),children:["desktop","tablet","mobile"].map(e=>{let a="desktop"===e?eq.Monitor:"tablet"===e?eY.DeviceTablet:eV.DeviceMobile,s=j(`artifactPreview.viewport_${e}`,e.charAt(0).toUpperCase()+e.slice(1));return(0,t.jsx)("button",{type:"button",className:"spvIcon",onClick:()=>A(e),"aria-pressed":E===e,title:s,"aria-label":s,children:(0,t.jsx)(a,{size:17})},e)})})]})]})}let eC=(0,e5.planFacts)(a);if(Z&&(s||n||Z.version)){let l=s?.name??n?.name??a?.app_name??"",i=!s&&(null!=n||"failed"===Z.state),r=!!(n?.cancelled||!s&&"cancelled"===Z.error),o=tt[E],d=(0,t.jsxs)("span",{className:"spvChip","data-tone":i?r?void 0:"attn":"accent",children:[i?null:(0,t.jsx)("span",{className:"spvLiveDot","aria-hidden":"true"}),i?r?j("artifactPreview.appChipStopped","Stopped"):j("artifactPreview.appChipFailed","Build failed"):w?j("artifactPreview.appChipQueued","Queued"):j("artifactPreview.appChipBuilding","Building")]});return(0,t.jsxs)(t.Fragment,{children:[ek(eN(l,d),s&&f?(0,t.jsxs)("button",{type:"button",className:"spvTextBtn",onClick:()=>void ex("cancel",f),disabled:null!=U,"aria-busy":"cancel"===U,children:[(0,t.jsx)(ta,{name:"stop"}),j("artifactPreview.stopBuild","Stop")]}):null),(0,t.jsx)(ti,{live:Z,screen:ea,onScreen:es,rendered:en,shownVersion:ei},"live-bar"),(0,t.jsx)(to,{live:Z,failed:i,cancelled:r,error:n?.error??Z.error,ph
24ases:s?.phases??n?.phases??[]},"live-notes"),(0,t.jsx)("div",{className:"spvBody spvAppPage spvAppBody",...e.panel,children:(0,t.jsx)("div",{className:"spvAppStage",style:o?{width:o,maxWidth:"100%"}:void 0,children:(0,t.jsx)("div",{className:"spvLiveLayer",children:(0,t.jsx)(e9,{live:Z,title:l,screen:ea,onScreen:es,onReport:el,onActiveVersion:er})},"live")})},"stage"),(0,t.jsx)(tu,{live:Z,building:s,stopped:n,queued:w,rendered:en,viewport:E,onViewport:A},"live-foot")]})}if((s||n)&&et&&!Q)return(0,t.jsxs)(t.Fragment,{children:[ek(eN(s?.name??n?.name??a?.app_name??"",null),null),(0,t.jsx)("div",{className:"spvBody spvAppPage spvAppBody",...e.panel,children:(0,t.jsx)("div",{className:"spvAppStage","aria-busy":"true",children:(0,t.jsx)("p",{className:"spvLiveConnecting",children:j("artifactPreview.liveConnecting","Connecting to the live previewâ¦")})})},"stage")]});if(s||n){let l=s?.name??n?.name??a?.app_name??"",i=!s&&null!=n;return(0,t.jsxs)(t.Fragment,{children:[ek(eN(l,(0,t.jsxs)("span",{className:"spvChip","data-tone":i?n.cancelled?void 0:"attn":"accent",children:[i?null:(0,t.jsx)("span",{className:"spvLiveDot","aria-hidden":"true"}),i?n.cancelled?j("artifactPreview.appChipStopped","Stopped"):j("artifactPreview.appChipFailed","Build failed"):w?j("artifactPreview.appChipQueued","Queued"):j("artifactPreview.appChipBuilding","Building")]})),s&&f?(0,t.jsxs)("button",{type:"button",className:"spvTextBtn",onClick:()=>void ex("cancel",f),disabled:null!=U,"aria-busy":"cancel"===U,children:[(0,t.jsx)(ta,{name:"stop"}),j("artifactPreview.stopBuild","Stop")]}):null),(0,t.jsx)("div",{className:"spvBody spvAppPage",...e.panel,children:(0,t.jsxs)("div",{className:"spvAppSheet",role:s?"status":void 0,children:[(0,t.jsxs)("header",{className:"spvAppHead",children:[(0,t.jsx)("p",{className:"spvAppEyebrow","data-tone":i?"muted":void 0,children:i?n.cancelled?j("artifactPreview.stoppedEyebrow","Build stopped"):j("artifactPreview.failedEyebrow","Build failed"):w?j("artifactPreview.queuedEyebrow","Waiting for a builder"):j("artifactPreview.buildingEyebrow","Building your app")}),(0,t.jsx)("h2",{className:"spvAppTitle",children:l}),a?.summary?(0,t.jsx)("p",{className:"spvAppLede",children:a.summary}):null]}),(0,t.jsx)(e5.AppBuildProgress,{variant:"pane",phases:s?.phases??n?.phases??[],detail:s?.detail??null,trail:s?.trail??n?.trail,plan:eC,error:i&&!n.cancelled?n.error:null,queue:s?.queue,active:null!=s}),s&&eC?.screens.length?(0,t.jsxs)("section",{className:"spvAppSection",children:[(0,t.jsx)("h3",{className:"spvAppLabel",children:j("artifactPreview.buildingScreens","Screens being built")}),(0,t.jsx)("ol",{className:"spvAppScreens",children:eC.screens.map((e,a)=>(0,t.jsxs)("li",{children:[(0,t.jsx)("span",{className:"spvAppNo","aria-hidden":"true",children:a+1}),e]},`${e}-${a}`))})]}):null,(0,t.jsx)("p",{className:"spvAppFootnote",children:s?j("artifactPreview.buildingNote","Your app opens here the moment it's ready. Keep chatting â the build carries on even if you leave."):j("artifactPreview.stoppedNote","Retry from the build card in the chat. Your plan and saved progress are kept.")})]})})]})}if(!a)return null;let eS=a.screens??[],e_=a.features??[],eT=a.data_model??[];return(0,t.jsxs)(t.Fragment,{children:[ek(eN(a.app_name,(0,t.jsx)("span",{className:"spvChip",children:j("artifactPreview.blueprintTitle","Blueprint")})),null),(0,t.jsx)("div",{className:"spvBody spvAppPage",...e.panel,children:(0,t.jsxs)("article",{className:"spvAppSheet",children:[(0,t.jsxs)("header",{className:"spvAppHead",children:[(0,t.jsxs)("p",{className:"spvAppEyebrow",children:[j("artifactPreview.blueprintTitle","Blueprint"),a.runtime_mode?(0,t.jsxs)("span",{className:"spvAppEyebrowMeta",children:[" · ","full_stack"===a.runtime_mode?j("common:componentsUi.chatActionCards.appPlanRuntimeFullStack","Full-stack app"):j("common:componentsUi.chatActionCards.appPlanRuntimeLightweight","Lightweight app")]}):null]}),(0,t.jsx)("h2",{className:"spvAppTitle",children:a.app_name}),a.summary?(0,t.jsx)("p",{className:"spvAppLede",children:a.summary}):null]}),eS.length>0?(0,t.jsxs)("section",{className:"spvAppSection",children:[(0,t.jsxs)("h3",{className:"spvAppLabel",children:[j("artifactPreview.blueprintScreens","Screens"),(0,t.jsx)("span",{className:"spvAppCount",children:eS.length})]}),(0,t.jsx)("ol",{className:"spvAppList",children:eS.map((e,a)=>(0,t.jsxs)("li",{className:"spvAppRow",children:[(0,t.jsx)("span",{className:"spvAppNo","aria-hidden":"true",children:a+1}),(0,t.jsxs)("span",{className:"spvAppRowCopy",children:[(0,t.jsx)("strong",{children:e.title}),e.description?(0,t.jsx)("small",{children:e.description}):null]})]},`${e.title}-${a}`))})]}):null,e_.length>0?(0,t.jsxs)("section",{className:"spvAppSection",children:[(0,t.jsxs)("h3",{className:"spvAppLabel",children:[j("artifactPreview.blueprintFeatures","It will"),(0,t.jsx)("span",{className:"spvAppCount",children:e_.length})]}),(0,t.jsx)("ul",{className:"spvAppList",children:e_.map((e,a)=>(0,t.jsxs)("li",{className:"spvAppRow",children:[(0,t.jsx)("span",{className:"spvAppTick","aria-hidden":"true",children:(0,t.jsx)(ta,{name:"check"})}),(0,t.jsxs)("span",{className:"spvAppRowCopy",children:[(0,t.jsx)("strong",{children:e.title}),e.description?(0,t.jsx)("small",{children:e.description}):null]})]},`${e.title}-${a}`))})]}):null,eT.length>0?(0,t.jsxs)("section",{className:"spvAppSection",children:[(0,t.jsxs)("h3",{className:"spvAppLabel",children:[j("artifactPreview.blueprintData","Data"),(0,t.jsx)("span",{className:"spvAppCount",children:eT.length})]}),(0,t.jsx)("ul",{className:"spvAppList",children:eT.map((e,a)=>(0,t.jsxs)("li",{className:"spvAppRow",children:[(0,t.jsx)("span",{className:"spvAppTick","aria-hidden":"true",children:(0,t.jsx)(ta,{name:"layers"})}),(0,t.jsxs)("span",{className:"spvAppRowCopy",children:[(0,t.jsx)("strong",{className:"spvAppMono",children:e.entity}),e.fields.length?(0,t.jsx)("small",{className:"spvAppMono",children:e.fields.join(" · ")}):null]})]},`${e.entity}-${a}
24`))})]}):null,a.schedule?(0,t.jsxs)("p",{className:"spvAppMeta",children:[(0,t.jsx)(ta,{name:"clock"}),j("artifactPreview.blueprintSchedule","Runs automatically: {{schedule}}",{schedule:a.schedule})]}):null,(0,t.jsx)("p",{className:"spvAppFootnote",children:j("artifactPreview.blueprintHint","Confirm the plan in chat â the live app takes this pane over the moment it's built.")})]})})]})}let tn=e=>String(e??"").trim().toLowerCase(),tl=/data-screen\s*=\s*["']([^"']+)["']/g;function ti(e){let s,n,l,i,r,o,d,u,m,h,p,g,f,x,b=(0,a.c)(60),{live:v,screen:j,onScreen:y,rendered:w,shownVersion:k}=e,{t:N}=(0,c.useTranslation)("messages");b[0]!==w.blocks||b[1]!==k?(s=k?function(e){let t=new Set;for(let a of e.matchAll(e7))t.add(a[1]);return[...t]}(k.html):w.blocks,b[0]=w.blocks,b[1]=k,b[2]=s):s=b[2],b[3]!==s?(n=new Set(s),b[3]=s,b[4]=n):n=b[4];let C=n;if(b[5]!==C||b[6]!==v.draft||b[7]!==v.outline||b[8]!==y||b[9]!==w.writing||b[10]!==j||b[11]!==k||b[12]!==N){p=Symbol.for("react.early_return_sentinel");e:{let e,a,s,n,c,g,f,x,S,_=(0,eo.screenProgress)(v.outline,C),T=k?function(e){let t=[];for(let a of e.matchAll(tl))t.some(e=>tn(e)===tn(a[1]))||t.push(a[1]);return t}(k.html):[],E=T.length?T.map(tr):_;b[22]!==v.outline||b[23]!==w.writing?(e=(0,eo.blockTitle)(v.outline,w.writing)?.screen??null,b[22]=v.outline,b[23]=w.writing,b[24]=e):e=b[24];let A=e,R=tn(j??E[0]?.name);if(l=k?"sample":v.draft?"rendering":"outline",b[25]!==N?(a=N("artifactPreview.liveModeOutline","Outline"),b[25]=N,b[26]=a):a=b[26],b[27]!==N?(s=N("artifactPreview.liveModeRendering","Rendering"),b[27]=N,b[28]=s):s=b[28],b[29]!==N?(n=N("artifactPreview.liveModeSample","Sample data"),b[29]=N,b[30]=n):n=b[30],b[31]!==a||b[32]!==s||b[33]!==n?(c={outline:a,rendering:s,sample:n},b[31]=a,b[32]=s,b[33]=n,b[34]=c):c=b[34],i=c[l],b[35]!==N?(g=N("artifactPreview.liveModeOutlineTip","The layout from your plan. Each section is replaced by the real one as it is built."),b[35]=N,b[36]=g):g=b[36],b[37]!==N?(f=N("artifactPreview.liveModeRenderingTip","Finished sections appear as they are written. Nothing is interactive yet."),b[37]=N,b[38]=f):f=b[38],b[39]!==N?(x=N("artifactPreview.liveModeSampleTip","Working on sample data â nothing you do here is saved. Your preview data connects when the checks pass."),b[39]=N,b[40]=x):x=b[40],b[41]!==g||b[42]!==f||b[43]!==x?(S={outline:g,rendering:f,sample:x},b[41]=g,b[42]=f,b[43]=x,b[44]=S):S=b[44],r=S[l],!E.length){p=null;break e}h="spvLiveBar",o="spvLiveScreens",d="group",b[45]!==N?(u=N("artifactPreview.liveScreens","Screens"),b[45]=N,b[46]=u):u=b[46],m=E.map(e=>{let a=0===e.total?!!k:e.done>=e.total,s=tn(e.name)===R;return(0,t.jsxs)("button",{type:"button",className:"spvLiveScreen","aria-pressed":s,onClick:()=>y(e.name),title:a?N("artifactPreview.liveScreenDone",{name:e.name,defaultValue:"{{name}} â built"}):N("artifactPreview.liveScreenProgress",{name:e.name,done:e.done,total:e.total,defaultValue:"{{name}} â {{done}} of {{total}} sections"}),children:[(0,t.jsx)("span",{className:"spvLiveScreenName",children:e.name}),A===e.name?(0,t.jsx)("span",{className:"spvLiveDot","aria-hidden":"true"}):null,a?(0,t.jsx)("span",{className:"spvLiveScreenDone","aria-hidden":"true",children:(0,t.jsx)(ta,{name:"check"})}):e.total>0?(0,t.jsxs)("span",{className:"spvLiveScreenCount",children:[e.done,"/",e.total]}):null]},e.name)})}b[5]=C,b[6]=v.draft,b[7]=v.outline,b[8]=y,b[9]=w.writing,b[10]=j,b[11]=k,b[12]=N,b[13]=l,b[14]=i,b[15]=r,b[16]=o,b[17]=d,b[18]=u,b[19]=m,b[20]=h,b[21]=p}else l=b[13],i=b[14],r=b[15],o=b[16],d=b[17],u=b[18],m=b[19],h=b[20],p=b[21];if(p!==Symbol.for("react.early_return_sentinel"))return p;b[47]!==o||b[48]!==d||b[49]!==u||b[50]!==m?(g=(0,t.jsx)("div",{className:o,role:d,"aria-label":u,children:m}),b[47]=o,b[48]=d,b[49]=u,b[50]=m,b[51]=g):g=b[51];let S="sample"===l?"warn":"rendering"===l?"accent":void 0;return b[52]!==i||b[53]!==r||b[54]!==S?(f=(0,t.jsx)("span",{className:"spvChip spvLiveMode","data-tone":S,title:r,children:i}),b[52]=i,b[53]=r,b[54]=S,b[55]=f):f=b[55],b[56]!==f||b[57]!==h||b[58]!==g?(x=(0,t.jsxs)("div",{className:h,children:[g,f]}),b[56]=f,b[57]=h,b[58]=g,b[59]=x):x=b[59],x}function tr(e){return{name:e,total:0,done:0}}function to(e){let s,n,l,i,r,o,d=(0,a.c)(22),{live:u,failed:m,cancelled:h,error:p,phases:g}=e,{t:f}=(0,c.useTranslation)("messages"),x=(0,e5.useAppBuildPhaseLabel)();if(d[0]!==h||d[1]!==p||d[2]!==m||d[3]!==x||d[4]!==u.change||d[5]!==u.issues.length||d[6]!==g||d[7]!==f){let e=g.find(td);s=u.change,n=u.issues.length,l=m?(0,t.jsx)("div",{className:"spvAppNote","data-tone":"warn",role:"alert",children:(0,t.jsx)("span",{className:"spvAppNoteText",children:h||"cancelled"===p||!e?f("artifactPreview.liveStoppedNote","The build stopped. The last working version stays here â retry from the build card in the chat."):f("artifactPreview.liveFailedNote",{step:x(e.id),defaultValue:"The build stopped at {{step}}. The last working version stays here â retry from the build card in the chat."})})}):null,d[0]=h,d[1]=p,d[2]=m,d[3]=x,d[4]=u.change,d[5]=u.issues.length,d[6]=g,d[7]=f,d[8]=s,d[9]=n,d[10]=l}else s=d[8],n=d[9],l=d[10];return d[11]!==m||d[12]!==n||d[13]!==f?(i=!m&&n>0?(0,t.jsx)("div",{className:"spvAppNote","data-tone":"warn",role:"status",children:(0,t.jsx)("span",{className:"spvAppNoteText",children:f("artifactPreview.liveIssuesNote",{count:n,defaultValue_one:"A check flagged {{count}} area â it's marked in the preview while the build fixes it.",defaultValue_other:"Checks flagged {{count}} areas â they're marked in the preview while the build fixes them."})})}):null,d[11]=m,d[12]=n,d[13]=f,d[14]=i):i=d[14],d[15]!==s||d[16]!==f?(r=s?(0,t.jsxs)("div",{className:"spvAppNote","data-tone":"failed"===s.state?"warn":"live",role:"status",children:["queued"===s.state||"applying"===s.state?(0,t.jsx)("span",{className:"spvLiveDot","aria-hidden":"true"}):null,(0,t.jsx)("span",{className:"spvAppNoteText",children:"queued"===s.state?f("artifactPreview.liveChangeQueued",{text:s.text.replace(/^- /gm,""),defaultValue:"Your change is queued: â{{text}}â â it's applied as soon as the screens are drafted."}):"applying"===s.state?f("artifactPreview.liveChangeApplying",{text:s.text.replace(/^- /gm,""),defaultValue:"Applying your change: â{{text}}â"}):"applied"===s.state?f("artifactPreview.liveChangeApplied","Your change is applied â the areas it updated are marked."):f("artifactPreview.liveChangeFailed","Your change couldn't be applied during the build. Ask again once it finishes.")})]}):null,d[15]=s,d[16]=f,d[17]=r):r=d[17],d[18]!==l||d[19]!==i||d[20]!==r?(o=(0,t.jsxs)(t.Fragment,{children:[l,i,r]}),d[18]=l,d[19]=i,d[20]=r,d[21]=o):o=d[21],o}function td(e){return"failed"===e.status}let tc=new Set(["outline","version","connected","failed","change"]);function tu(e){let s,n,l,i,r,o,d,u,m=(0,a.c)(57),{live:h,building:p,stopped:g,queued:f,rendered:x,viewport:b,onViewport:v}=e,{t:j}=(0,c.useTranslation)("messages"),y=(0,e5.useAppBuildPhaseLabel)(),w=(0,e5.useBuildDetailText)(),k=(0,e5.useQueueLine)(),N=(0,te.useLiveEventText)();m[0]!==p?.phases||m[1]!==g?.phases?(s=p?.phases??g?.phases??[],m[0]=p?.phases,m[1]=g?.phases,m[2]=s):s=m[2];let C=s,S=(0,e5.useAppBuildCounter)(C,null!=p);if(m[3]!==p||m[4]!==y||m[5]!==h.change?.state||m[6]!==h.outline||m[7]!==h.version||m[8]!==w||m[9]!==C||m[10]!==k||m[11]!==f||m[12]!==x.writing||m[13]!==g||m[14]!==j){let e=(0,eo.blockTitle)(h.outline,x.writing),t=C.find(th);n=g?g.cancelled?j("artifactPreview.stoppedEyebrow","Build stopped"):t?j("artifactPreview.liveStoppedAt",{step:y(t.id),defaultValue:"Stopped at {{step}}"}):j("artifactPreview.failedEyebrow","Build failed"):f?k(p?.queue):h.change?.state==="applying"?j("artifactPreview.liveApplyingChange","Applying your change"):"nav"!==x.writing||h.version?e&&!h.version?j("artifactPreview.liveWritingNow",{title:e.title,defaultValue:"Writing {{title}}"}):p?.detail?w(p.detail):t?y(t.id):j("artifactPreview.buildingEyebrow","Building your app"):j("artifactPreview.liveWritingNav","Writing the navigation"),m[3]=p,m[4]=y,m[5]=h.change?.state,m[6]=h.outline,m[7]=h.version,m[8]=w,m[9]=C,m[10]=k,m[11]=f,m[12]=x.writing,m[13]=g,m[14]=j,m[15]=n}else n=m[15];let _=n;if(m[16]!==p||m[17]!==S||m[18]!==N||m[19]!==h.events||m[20]!==v||m[21]!==_||m[22]!==j||m[23]!==b){let e,a,s,n,d,c,u,g=[...h.events].reverse().find(tm);m[28]!==p?(e=p?(0,t.jsx)("span",{className:"spvLiveDot","aria-hidden":"true"}):null,m[28]=p,m[29]=e):e=m[29],m[30]!==_?(a=(0,t.jsx)("span",{className:"spvLiveStatusText",children:_}),m[30]=_,m[31]=a):a=m[31],m[32]!==S?(s=S?(0,t.jsx)("span",{className:"spvLiveStatusMeta",children:S}):null,m[32]=S,m[33]=s):s=m[33],m[34]!==e||m[35]!==a||m[36]!==s?(n=(0,t.jsxs)("p",{className:"spvLiveStatus",children:[e,a,s]}),m[34]=e,m[35]=a,m[36]=s,m[37]=n):n=m[37],m[38]!==j?(d=j("artifactPreview.viewportLabel","Preview size"),m[38]=j,m[39]=d):d=m[39],m[40]!==v||m[41]!==j||m[42]!==b?(c=["desktop","tablet","mobile"].map(e=>{let a="desktop"===e?eq.Monitor:"tablet"===e?eY.DeviceTablet:eV.DeviceMobile,s=j(`artifactPreview.viewport_${e}`,e.charAt(0).toUpperCase()+e.slice(1));return(0,t.jsx)("button",{type:"button",className:"spvIcon",onClick:()=>v(e),"aria-pressed":b===e,title:s,"aria-label":s,children:(0,t.jsx)(a,{size:17})},e)}),m[40]=v,m[41]=j,m[42]=b,m[43]=c):c=m[43],m[44]!==d||m[45]!==c?(u=(0,t.jsx)("div",{className:"spvZoomTools",role:"group","aria-label":d,children:c}),m[44]=d,m[45]=c,m[46]=u):u=m[46],m[47]!==n||m[48]!==u?(o=(0,t.jsxs)("div",{className:"spvFoot spvLiveFoot",children:[n,u]}),m[47]=n,m[48]=u,m[49]=o):o=m[49],l="sr-only",i="polite",r=g?N(g):"",m[16]=p,m[17]=S,m[18]=N,m[19]=h.events,m[20]=v,m[21]=_,m[22]=j,m[23]=b,m[24]=l,m[25]=i,m[26]=r,m[27]=o}else l=m[24],i=m[25],r=m[26],o=m[27];return m[50]!==l||m[51]!==i||m[52]!==r?(d=(0,t.jsx)("p",{className:l,"aria-live":i,children:r}),m[50]=l,m[51]=i,m[52]=r,m[53]=d):d=m[53],m[54]!==o||m[55]!==d?(u=(0,t.jsxs)(t.Fragment,{children:[o,d]}),m[54]=o,m[55]=d,m[56]=u):u=m[56],u}function tm(e){return tc.has(e.kind)&&("outline"!==e.kind||"plan"!==e.source)}function th(e){return"running"===e.status||"failed"===e.status}var tp=e.i(640393);let tg=new Set(["artifact","file"]),tf=new Set(["approval","questions","plan_review","app_plan","confirm","prompt"]),tx={approval:"APPROVAL REQUEST",plan_review:"PLAN REVIEW",questions:"QUESTION",prompt:"QUESTION",confirm:"CONFIRM",followups:"NEXT STEPS",sources:"SOURCES",file:"FILE",task_launched:"TASK",routine_created:"ROUTINE",agent_created:"AGENT",app_plan:"APP PLAN",app_build:"APP BUILD",loop_plan:"LOOP",connect_service:"CONNECT",install_app:"APP",os_action:"OPEN"};function tb(e){let s,n,l,i,r,o,d,u=(0,a.c)(21),{entry:m,onOpen:h}=e,{t:p}=(0,c.useTranslation)("paletteOs"),g=m.action,x="artifact"===g.kind?(0,f.isHtmlArtifactKind)(g.artifact_kind)&&(0,eM.countArtifactSlides)(g.content??"")>=2?"slides":"image"===g.artifact_kind||"svg"===g.artifact_kind||"video"===g.artifact_kind?"image":"dashboard"===g.artifact_kind?"spreadsheet":"document":"file";u[0]!==g||u[1]!==p?(s="artifact"===g.kind?eB(p,g):p("session.preview.kindFile","File"),u[0]=g,u[1]=p,u[2]=s):s=u[2];let b=s;u[3]!==m||u[4]!==h?(n=()=>h(m),u[3]=m,u[4]=h,u[5]=n):n=u[5];let v=m.title||m.head;u[6]!==x?(l=(0,t.jsx)("span",{className:"mpIcon","aria-hidden":"true",children:(0,t.jsx)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:"slides"===x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"3",y:"4",width:"18",height:"12",rx:"2"}),(0,t.jsx)("path",{d:"M8 20h8M12 16v4M7 9h6M7 12.5h10"})]}):"image"===x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,t.jsx)("circle",{cx:"8",cy:"8",r:"2"}
24),(0,t.jsx)("path",{d:"m21 15-5-5L4 21"})]}):"spreadsheet"===x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,t.jsx)("path",{d:"M3 9h18M3 15h18M9 3v18M15 3v18"})]}):(0,t.jsx)("path",{d:"M14 2H4v20h16V8l-6-6ZM14 2v6h6M8 13h8M8 17h5"})})}),u[6]=x,u[7]=l):l=u[7];let j=m.title||m.head;return u[8]!==j?(i=(0,t.jsx)("span",{className:"mpTitle",children:j}),u[8]=j,u[9]=i):i=u[9],u[10]!==b?(r=(0,t.jsx)("span",{className:"mpSub",children:b}),u[10]=b,u[11]=r):r=u[11],u[12]!==i||u[13]!==r?(o=(0,t.jsxs)("span",{className:"mpCopy",children:[i,r]}),u[12]=i,u[13]=r,u[14]=o):o=u[14],u[15]!==x||u[16]!==n||u[17]!==v||u[18]!==l||u[19]!==o?(d=(0,t.jsxs)("button",{type:"button",className:"msgPreviewBtn mpCard","data-file-kind":x,onClick:n,title:v,children:[l,o]}),u[15]=x,u[16]=n,u[17]=v,u[18]=l,u[19]=o,u[20]=d):d=u[20],d}function tv(e){let s,n,l,i=(0,a.c)(7);return i[0]!==e?({entry:n,...s}=e,i[0]=e,i[1]=s,i[2]=n):(s=i[1],n=i[2]),i[3]!==s||i[4]!==n.action||i[5]!==n.interactive?(l=(0,t.jsx)("div",{className:"spvCardSec",children:(0,t.jsx)(tp.ChatActionCard,{...s,surface:"session",action:n.action,interactive:n.interactive})}),i[3]=s,i[4]=n.action,i[5]=n.interactive,i[6]=l):l=i[6],l}var tj=e.i(643531),ty=e.i(664659),tw=e.i(160434),tw=tw,tk=e.i(717521),tk=tk,tN=e.i(89128);function tC(e){let s,n,l,r,o=(0,a.c)(40),{turn:u,rows:m,status:h}=e,{t:p}=(0,c.useTranslation)("paletteOs"),[g,f]=(0,i.useState)(u.isTyping),x=(0,i.useId)();o[0]!==u.responseSegments?(s=u.responseSegments??[],o[0]=u.responseSegments,o[1]=s):s=o[1];let b=s;o[2]!==p||o[3]!==u.outcome?(n="error"===u.outcome?p("session.activity.error","Work interrupted"):"stopped"===u.outcome?p("session.activity.stopped","Stopped"):p("session.activity.completed","Work completed"),o[2]=p,o[3]=u.outcome,o[4]=n):n=o[4];let v=n;o[5]!==h||o[6]!==p||o[7]!==v||o[8]!==u.isTyping?(l=u.isTyping?h||p("session.activity.starting","Getting started"):v,o[5]=h,o[6]=p,o[7]=v,o[8]=u.isTyping,o[9]=l):l=o[9];let j=l;if(o[10]!==x||o[11]!==g||o[12]!==j||o[13]!==m||o[14]!==p||o[15]!==u.agentActivities||o[16]!==u.isTyping||o[17]!==u.outcome||o[18]!==b){let e,a,s,n,l,i,c,h=m.slice(-24);o[20]!==p?(e=p("session.activity.label","Response activity"),o[20]=p,o[21]=e):e=o[21],o[22]===Symbol.for("react.memo_cache_sentinel")?(a=()=>f(tE),o[22]=a):a=o[22],o[23]!==g||o[24]!==p?(s=g?p("session.activity.hide","Hide activity"):p("session.activity.view","View activity"),o[23]=g,o[24]=p,o[25]=s):s=o[25];let v=`${s}: ${j}`;o[26]!==u.isTyping||o[27]!==u.outcome?(n=(0,t.jsx)("span",{className:"ssActivityMark","aria-hidden":"true",children:u.isTyping?(0,t.jsx)(tk.default,{size:14}):"error"===u.outcome?(0,t.jsx)(tN.TriangleAlert,{size:14}):"stopped"===u.outcome?(0,t.jsx)(d.Square,{size:12}):(0,t.jsx)(tj.Check,{size:14})}),o[26]=u.isTyping,o[27]=u.outcome,o[28]=n):n=o[28],o[29]!==j?(l=(0,t.jsx)("span",{className:"ssActivityStatus",role:"status","aria-live":"polite","aria-atomic":"true",children:j}),o[29]=j,o[30]=l):l=o[30];let y=g?"isOpen":"";o[31]!==y?(i=(0,t.jsx)(ty.ChevronDown,{size:15,className:y,"aria-hidden":"true"}),o[31]=y,o[32]=i):i=o[32],o[33]!==x||o[34]!==g||o[35]!==l||o[36]!==i||o[37]!==v||o[38]!==n?(c=(0,t.jsxs)("button",{type:"button",className:"ssActivityToggle",onClick:a,"aria-expanded":g,"aria-controls":x,"aria-label":v,children:[n,l,i]}),o[33]=x,o[34]=g,o[35]=l,o[36]=i,o[37]=v,o[38]=n,o[39]=c):c=o[39],r=(0,t.jsxs)("section",{className:`ssActivity${u.isTyping?" isLive":" isComplete"}`,"aria-label":e,children:[c,g&&(0,t.jsxs)("div",{id:x,className:"ssActivityDetails",children:[b.length>0&&(0,t.jsx)("div",{className:"ssActivityUpdates",children:b.map(tT)}),(0,t.jsxs)("ol",{className:"ssActivitySteps",children:[m.length>24&&(0,t.jsx)("li",{className:"ssActivityEarlier",children:p("session.activity.earlier","{{count}} earlier steps",{count:m.length-24})}),h.map(e=>(0,t.jsxs)("li",{className:`ssActivityStep ${e.state}`,children:[(0,t.jsx)("span",{"aria-hidden":"true",children:"done"===e.state?(0,t.jsx)(tj.Check,{size:15}):"failed"===e.state?(0,t.jsx)(tN.TriangleAlert,{size:15}):"running"===e.state&&u.isTyping?(0,t.jsx)(tk.default,{size:15}):(0,t.jsx)(tw.default,{size:12})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{children:e.label}),e.sub&&(0,t.jsx)("small",{children:e.sub})]}),(0,t.jsx)("span",{className:"ssActivityStepState",children:"done"===e.state?p("session.activity.done","Done"):"failed"===e.state?p("session.activity.failed","Failed"):"running"===e.state&&u.isTyping?p("session.activity.working","In progress"):p("session.activity.pending","Not completed")})]},e.key))]}),Object.values(u.agentActivities).filter(t_).map(tS)]})]}),o[10]=x,o[11]=g,o[12]=j,o[13]=m,o[14]=p,o[15]=u.agentActivities,o[16]=u.isTyping,o[17]=u.outcome,o[18]=b,o[19]=r}else r=o[19];return r}function tS(e){return(0,t.jsxs)("div",{className:"ssActivityAgent",children:[(0,t.jsx)("p",{children:e.agentName}),(0,t.jsx)(g.ChatMarkdown,{compact:!0,children:(0,en.stripPanelBlocks)(e.streamingContent)})]},e.agentId)}function t_(e){return e.streamingContent}function tT(e){return(0,t.jsx)("div",{children:(0,t.jsx)(g.ChatMarkdown,{compact:!0,children:(0,en.stripPanelBlocks)(e.text)})},e.id)}function tE(e){return!e}function tA({turn:e,renderActivity:a,renderPlan:s}){let n,l,r;return(l=[...n=e.planBoundaries??[],null].map((t,a)=>({...e,isTyping:!t&&e.isTyping,outcome:t?void 0:e.outcome,executionSteps:[],responseSegments:(e.responseSegments??[]).filter(e=>n.findIndex(t=>t.segmentIds.includes(e.id))===(t?a:-1)),turnTodos:t?.todos??e.turnTodos,agentActivities:t?.agents??e.agentActivities,collaborationPhase:t?"idle":e.collaborationPhase})),r=new Map,e.executionSteps.forEach((e,t)=>{let a=e.callId??e.toolName,s=n.findIndex(e=>t<e.stepIndex);s<0&&(s=n.length),"tool_call"===e.type?r.set(a,[...r.get(a)??[],s]):s=r.get(a)?.shift()??s,l[s].executionSteps.push(e)}),l.forEach((e,t)=>{t&&(e.turnTodos===n[t-1].todos&&(e.turnTodos=[]),e.agentActivities===n[t-1].agents&&(e.agentActivities={}))}),l).map((n,l)=>(0,t.jsxs)(i.Fragment,{children:[n.executionSteps.length>0||n.responseSegments?.length||n.turnTodos.length>0||Object.keys(n.agentActivities).length>0||n.isTyping&&!e.planBoundaries?.length||"error"===n.outcome||"stopped"===n.outcome?a(n):null,e.planBoundaries?.[l]&&s(e.planBoundaries[l].interactionId)]},e.planBoundaries?.[l]?.interactionId??"current"))}let tR=new Set(["create_artifact","edit_artifact","imagen","generate_video"]),tD="palette_session_contexts_v1",tM={queued:"Waiting for a worker",preparing_files:"Reading files",routing:"Thinking",context:"Gathering relevant information",planning:"Preparing the next step",recovering:"Recovering",reconnecting:"Reconnecting"},tI={web_search:"Searching the web",web_fetch:"Reading a web page",deep_research:"Researching across sources",search_knowledge_base:"Searching Drive",query_structured_data:"Querying the database",read_attachment:"Reading a file",search_attachments:"Searching your files",query_attachments:"Querying your data",consult_team_member:"Asking a teammate",memory_search:"Searching Memory",generate_video:"Generating a video",generate_presentation:"Building a presentation",create_docx:"Writing a document",create_pdf:"Writing a PDF",create_pptx:"Building slides",create_xlsx:"Building a spreadsheet",imagen:"Generating an image",create_artifact:"Creating an artifact",edit_artifact:"Editing the artifact",run_python:"Running code",task:"Delegating to a sub-agent"};function tO(e){let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}function tP(e,t){return tI[e]?t(`session.toolsLive.${e}`,tI[e]):tO(e)}function tL(e,t){let a,s,{turnTodos:n,agentActivities:l,executionSteps:i,collaborationPhase:r}=e,o=[];for(let e of(n.forEach((e,t)=>{o.push({key:`td-${t}`,label:e.content,state:"completed"===e.status?"done":"in_progress"===e.status?"running":"idle"})}),Object.values(l)))o.push({key:`ag-${e.agentId}`,label:e.agentName,sub:"tool_call"===e.status&&e.toolCalls.length?tP(e.toolCalls[e.toolCalls.length-1],t)+(e.toolDetail?` â ${e.toolDetail}`:""):e.agentField,state:"done"===e.status?"done":"running"});
24return o.push(...(a=[],s=new Map,i.forEach((e,n)=>{if("tool_call"===e.type){let l=e.detail?"web_fetch"===e.toolName?function(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}(e.detail):e.detail:void 0;a.push({key:`tl-${n}`,tool:e.toolName,label:tP(e.toolName,t),sub:l,progressChars:e.progressChars,state:"running"});let i=e.callId??e.toolName,r=s.get(i)??[];r.push(a.length-1),s.set(i,r)}else{let t=s.get(e.callId??e.toolName)?.shift();void 0!==t&&(a[t].state=!1===e.ok?"failed":"done")}}),a.map(({progressChars:e,...a})=>({...a,sub:a.sub??("running"===a.state&&e?t("session.activity.preparing","Preparing content"):void 0)})))),"synthesizing"===r&&o.push({key:"synth",label:t("session.plan.synthesizing","Synthesizing answer"),state:"running"}),o}let tF=/^\/(?:session|general-chat)(?:\/([^/?#]+))?\/?$/;function t$(){let e=window.location.pathname.match(tF);if(!e?.[1])return null;try{return decodeURIComponent(e[1])}catch{return e[1]}}function tB(e,t){if(!tF.test(window.location.pathname))return;let a=e?`/general-chat/${encodeURIComponent(e)}`:"/general-chat";if(window.location.pathname+window.location.search!==a)try{t?window.history.pushState(null,"",a):window.history.replaceState(null,"",a)}catch{}}function tH(e,t){return 0===e.length?null:1===e.length?{title:e[0].name,meta:t("session.selection.fileMeta",{defaultValue:"LOCAL FILE · {{size}}",size:(0,em.fmtSize)(e[0].size)})}:{title:t("session.selection.filesTitle",{defaultValue:"{{n}} selected files",n:e.length}),meta:t("session.selection.filesMeta","LOCAL FILES")}}function tz(e){let s,n,l,i,r,o,d,u,m=(0,a.c)(26),{eyebrow:h,title:p,meta:g,suggestions:f,onPick:x,onClear:b,disabled:v}=e,{t:j}=(0,c.useTranslation)("paletteOs");if(m[0]!==h?(s=(0,t.jsx)("span",{children:h}),m[0]=h,m[1]=s):s=m[1],m[2]!==b||m[3]!==j?(n=b&&(0,t.jsx)("button",{type:"button",onClick:b,"aria-label":j("session.selection.clear","Clear selection"),children:"Ã"}),m[2]=b,m[3]=j,m[4]=n):n=m[4],m[5]!==s||m[6]!==n?(l=(0,t.jsxs)("div",{className:"ctxEyebrow",children:[s,n]}),m[5]=s,m[6]=n,m[7]=l):l=m[7],m[8]!==p?(i=(0,t.jsx)("div",{className:"ctxTitle",children:p}),m[8]=p,m[9]=i):i=m[9],m[10]!==g?(r=(0,t.jsx)("div",{className:"ctxMeta",children:g}),m[10]=g,m[11]=r):r=m[11],m[12]!==v||m[13]!==x||m[14]!==f){let e;m[16]!==v||m[17]!==x?(e=e=>(0,t.jsx)("button",{type:"button",disabled:v,onClick:()=>x(e),children:e},e),m[16]=v,m[17]=x,m[18]=e):e=m[18],o=f.map(e),m[12]=v,m[13]=x,m[14]=f,m[15]=o}else o=m[15];return m[19]!==o?(d=(0,t.jsx)("div",{className:"ctxSuggestions",children:o}),m[19]=o,m[20]=d):d=m[20],m[21]!==l||m[22]!==i||m[23]!==r||m[24]!==d?(u=(0,t.jsxs)("div",{className:"sessionContextCard",children:[l,i,r,d]}),m[21]=l,m[22]=i,m[23]=r,m[24]=d,m[25]=u):u=m[25],u}let tU="palette_session_model_v2",tG="palette_guest_draft_v1",tW="palette_session_archived_v1",tK="palette_session_effort_v1",tV="palette_session_mode_v1",tY="palette_session_plan_v1",tq="palette_session_filter_v1",tJ=()=>"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,tX={run:"Running task",gate:"Waiting for your input",done:"Done",idle:"Chat"},tZ="session.hero.exploreLine",tQ="Hello. What shall we do today?",t0=[{id:"research",d:"M6.5 2.5 a4 4 0 1 0 0 8 a4 4 0 1 0 0 -8 M9.6 9.6 L13.5 13.5",cat:{key:"session.work.customerAppCat",fallback:"Customer tracker"},desc:{key:"session.work.customerAppDesc",fallback:"Keep customers, follow-ups, and your sales pipeline together"},prompt:{key:"session.work.customerAppPrompt",fallback:"Build a customer tracker for my team with contacts, follow-ups, and a sales pipeline"}},{id:"document",d:"M3.5 1.5 H9.5 L12.5 4.5 V14.5 H3.5 Z M9.5 1.5 V4.5 H12.5 M6 8.5 H10 M6 11 H10",cat:{key:"session.work.approvalAppCat",fallback:"Requests & approvals"},desc:{key:"session.work.approvalAppDesc",fallback:"Collect requests and guide them through review"},prompt:{key:"session.work.approvalAppPrompt",fallback:"Build an expense request app where my team submits receipts and managers review them"}},{id:"develop",d:"M5.5 4.5 L2.5 8 L5.5 11.5 M10.5 4.5 L13.5 8 L10.5 11.5",cat:{key:"session.work.inventoryAppCat",fallback:"Inventory manager"}
24,desc:{key:"session.work.inventoryAppDesc",fallback:"Track stock, suppliers, and items that need reordering"},prompt:{key:"session.work.inventoryAppPrompt",fallback:"Build an inventory app with products, stock movements, suppliers, and low-stock alerts"}},{id:"execute",d:"M2.5 2.5 H13.5 V13.5 H2.5 Z M5.5 8.2 L7.3 10 L10.8 5.8",cat:{key:"session.work.projectAppCat",fallback:"Project workspace"},desc:{key:"session.work.projectAppDesc",fallback:"Plan tasks, assign owners, and see what needs attention"},prompt:{key:"session.work.projectAppPrompt",fallback:"Build a project app with task boards, owners, deadlines, and a progress overview"}},{id:"automate",d:"M13 8 a5 5 0 1 1 -1.7 -3.8 M13 2.5 V4.6 H10.9",cat:{key:"session.work.customAppCat",fallback:"Your own idea"},desc:{key:"session.work.customAppDesc",fallback:"Describe a daily problem and shape an app around it"},prompt:{key:"session.work.customAppPrompt",fallback:"Help me design an app for a daily task. Ask me about my workflow first"}}];function t1(e){return e.hasOutput?"WORK":"CHAT"}e.s(["SessionView",0,function({initialChatId:e=null,threadRouter:a,syncUrl:Y=!1}={}){let q,J,X,Z,{conversations:Q,convLoading:ee,convCreating:et,loadMoreConversations:eh,convHasMore:ep,convLoadingMore:eg,createConversation:ef,duplicateConversation:ex,renameConversation:eb,deleteConversation:ej,getMessages:ew,loadMessages:eN,sendMessage:eC,queueCardReply:eS,uploadFiles:e_,markAsRead:eT,setFeedbackRating:eE,turnsByConv:eA,activityByMessage:eR,planExecutions:eD={},msgLoadingByConv:eM,reconnectIfActive:eO,pendingOsAction:eP,consumeOsAction:eL,stopStreaming:e$}=(0,h.useGeneralChat)(),{openRoute:eB}=(0,j.useOsActions)(),{activeView:eH,openConfirm:ez,sessionIntent:eU,clearSessionIntent:eW,urlSync:eK,setView:eV,setSettingsOpen:eY,setProjectDialog:eq}=(0,eu.useViewContext)(),eJ=!a&&(eK||Y),{preferences:eX}=(0,U.useSessionPreferences)(),{projects:eZ,assignConversation:eQ}=(0,z.useSessionProjects)(),e0=(0,v.useIsViewer)(),{user:e1,requireAuth:e2}=(0,N.useAuth)(),e3=!e1,{data:e4,reload:e5}=(0,k.useSubscription)(),e6=!!e4?.usage&&!e4.usage.execution_allowed,[e7,e8]=(0,i.useState)(!1),{t:e9}=(0,c.useTranslation)("paletteOs"),[te,tt]=(0,i.useState)(null),[ta,tn]=(0,i.useState)(()=>{try{let e=sessionStorage.getItem(tG);if(null===e)return{};return sessionStorage.removeItem(tG),e?{"":e}:{}}catch{return{}}}),tl=te??"",ti=ta[tl]??"",tr=ta[""]??"";(0,i.useEffect)(()=>{if(e3)try{tr?sessionStorage.setItem(tG,tr):sessionStorage.removeItem(tG)}catch{}},[e3,tr]);let to=(0,i.useCallback)((e,t)=>{tn(a=>a[e]===t?a:{...a,[e]:t})},[]),td=(0,i.useCallback)(e=>to(tl,e),[tl,to]),tc=(0,i.useCallback)((...e)=>{tn(t=>{let a={...t};for(let t of e)delete a[t];return a})},[]),[tu,tm]=(0,i.useState)(null),[th,tp]=(0,i.useState)(null),[tj,ty]=(0,i.useState)(""),[tw,tk]=(0,i.useState)([]),[tN,tS]=(0,i.useState)(null),[t_,tT]=(0,i.useState)(new Set);(0,i.useEffect)(()=>{tS(null),tT(new Set)},[te]);let[tE,tI]=(0,i.useState)([]),[tP,tF]=(0,i.useState)(!1),[t2,t3]=(0,i.useState)(new Map),t4=(0,i.useRef)([]),t5=(0,i.useRef)(Promise.resolve()),t6=(0,i.useRef)(new WeakMap),[t7,t8]=(0,i.useState)(!1),t9=(0,i.useRef)(0),[ae,at]=(0,i.useState)(null),[aa,as]=(0,i.useState)({}),{secure:an}=(0,w.useSecureMode)(),[al,ai]=(0,i.useState)(T.AUTO_MODEL.id),[ar,ao]=(0,i.useState)([]),[ad,ac]=(0,i.useState)("high"),{open:au,setOpen:am,closeOnMobile:ah}=(0,V.usePaletteSidebar)("session"),[ap,ag]=(0,i.useState)("chat"),[af,ax]=(0,i.useState)(!1),[ab,av]=(0,i.useState)("ALL"),[aj,ay]=(0,i.useState)(null),[aw,ak]=(0,i.useState)(""),[aN,aC]=(0,i.useState)(!1),aS=(0,i.useRef)(null),a_=(0,i.useRef)(null),aT=(0,i.useRef)(null),aE=(0,i.useRef)(null),[aA,aR]=(0,i.useState)(!1),aD=(0,W.useWorkPanelState)(te),{update:aM,select:aI}=aD,aO=aD.state.activeId,aP=!aD.state.open,[aL,aF]=(0,i.useState)(!1),a$=(0,i.useRef)(""),aB=(0,i.useRef)(null),aH=(0,i.useRef)(null),az=(0,i.useRef)(null),aU=(0,i.useRef)(null),[aG,aW]=(0,i.useState)(null);(0,i.useEffect)(()=>aW(null),[te]);let aK=(0,i.useRef)(!1),[aV,aY]=(0,i.useState)(0);(0,i.useEffect)(()=>{aK.current=!1},[aV]);let aq=(0,i.useRef)(null),aJ=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=aJ.current;if(!e||!ep)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&eh()},{root:e.parentElement,rootMargin:"200px"});return t.observe(e),()=>t.disconnect()},[ep,eh,Q.length]),(0,i.useEffect)(()=>{as(function(){try{let e=localStorage.getItem(tD);return e?JSON.parse(e):{}}catch{return{}}}());try{let e=localStorage.getItem(tU)??localStorage.getItem("palette_general_model_v1");null!==e&&(T.ALL_MODELS.some(t=>t.id===e)||e.startsWith("byo:"))&&ai(e);let t=localStorage.getItem(tK);t&&es.some(e=>e.id===t)&&ac(t),ax("true"===localStorage.getItem(tY));let a=localStorage.getItem(tV);("chat"===a||"work"===a)&&ag(a);let s=localStorage.getItem(tq);("ALL"===s||"CHAT"===s||"WORK"===s||"ARCHIVED"===s)&&av(s)}catch{}},[]),(0,i.useEffect)(()=>
24{if(ao([]),!e1?.id)return;let e=!0,t=0,a=()=>{let a=++t;(0,E.fetchByoProviders)(!0,e1.id).then(s=>{e&&a===t&&ao(s)})};return a(),window.addEventListener(E.BYO_CHANGE_EVENT,a),()=>{e=!1,window.removeEventListener(E.BYO_CHANGE_EVENT,a)}},[e1?.id]);let aX=(0,i.useMemo)(()=>an?[]:(0,E.byoModelGroups)(ar),[ar,an]),aZ=e=>{ag(e);try{localStorage.setItem(tV,e)}catch{}},aQ=e=>{ax(e);try{localStorage.setItem(tY,String(e))}catch{}};(0,i.useEffect)(()=>{if(eU?.newThread)return;let t=a?.current??e;if(t){tt(t),eJ&&tB(t,!1);return}let s=eJ?t$():null;s&&tt(s)},[]),(0,i.useEffect)(()=>{let e=a?.current;e&&tt(t=>t===e?t:e)},[a?.current]);let a0=(0,i.useCallback)((e,t)=>{tt(e),ah(),tm(null),a?a.select(e,t?.push??!0):eJ&&tB(e,t?.push??!0)},[eJ,a,ah]);(0,i.useEffect)(()=>{let e=e=>{"session"===e.detail&&(a0(null,{push:!1}),am(!0))};return window.addEventListener("palette:view-reclick",e),()=>window.removeEventListener("palette:view-reclick",e)},[a0,am]);let a1=(0,i.useCallback)(()=>{t4.current=[],t6.current=new WeakMap,tk([]),t3(new Map)},[]),a2=(0,i.useCallback)(e=>{let t=t4.current.filter(t=>t!==e);t4.current=t,t6.current.delete(e),tk(t),t3(t=>{let a=new Map(t);return a.delete(e),a})},[]),a3=(0,i.useCallback)((e,t=te)=>{if(0!==(e=e.filter(e=>!t6.current.has(e))).length&&t)return t3(t=>{let a=new Map(t);for(let t of e)a.set(t,{status:"queued",progress:0});return a}),t5.current=t5.current.then(async()=>{let a=e.filter(e=>t4.current.includes(e)&&!t6.current.has(e));if(0!==a.length){t3(e=>{let t=new Map(e);for(let e of a)t.set(e,{status:"uploading",progress:0});return t});try{let e=await e_(t,a,(e,t)=>{t4.current.includes(e)&&t3(a=>{let s=new Map(a);return s.set(e,{status:"uploading",progress:t}),s})});for(let t of e.uploaded)t4.current.includes(t.file)&&t6.current.set(t.file,t.attachment);t3(t=>{let a=new Map(t);for(let t of e.uploaded)t4.current.includes(t.file)&&a.set(t.file,{status:"complete",progress:100});for(let t of e.failed)t4.current.includes(t.file)&&a.set(t.file,{status:"error",progress:0});return a}),e.failed.length>0&&u.toast.error(e9("session.uploadRetry",{defaultValue:"{{count}} file(s) could not upload. Retry or remove them; your message is still here.",count:e.failed.length}))}catch(e){console.error("Attachment upload failed:",e),t3(e=>{let t=new Map(e);for(let e of a)t4.current.includes(e)&&t.set(e,{status:"error",progress:0});return t}),u.toast.error(e9("session.uploadRetry",{defaultValue:"Files could not upload. Retry or remove them; your message is still here.",count:a.length}))}}}),t5.current},[te,e9,e_]),a4=(0,i.useCallback)(e=>{let t=e.filter(e=>e.size<=0xc800000||(u.toast.error(e9("session.fileTooLarge",{defaultValue:"{{name}} is larger than the 200 MB chat limit.",name:e.name})),!1)),a=Math.max(0,20-tE.length-t4.current.length);t.length>a&&u.toast.error(e9("session.tooManyFiles","You can attach up to 20 files to one message."));let s=t.slice(0,a);if(0===s.length)return;let n=[...t4.current,...s];t4.current=n,tk(n),a3(s)},[tE.length,a3,e9]),a5=(0,i.useCallback)((e,t)=>{as(a=>{let s={...a,[e]:t};try{localStorage.setItem(tD,JSON.stringify(s))}catch{}return s})},[]),a6=(0,i.useCallback)(e=>{as(t=>{if(!t[e])return t;let a={...t};delete a[e];try{localStorage.setItem(tD,JSON.stringify(a))}catch{}return a})},[]),a7=e=>Array.from(e.dataTransfer.types).includes("Files"),a8=(0,i.useCallback)(()=>{!e2()||e0||et||tP||(tc(""),a1(),tI([]),a6(""),at(null),a0(null),aU.current?.focus())},[e2,e0,et,tP,tc,a1,a6,a0]),a9=(0,i.useCallback)(e=>{a5(te??"",e),a1(),te&&0===ew(te).length&&e.targetName&&eb(te,e9("session.dataRoomTitle",{defaultValue:"{{name}} · Drive",name:e.targetName}))},[te,a1,ew,eb,a5,e9]);(0,i.useEffect)(()=>{if(!eJ)return;let e=()=>{let e=window.location.pathname;(e.startsWith("/session")||e.startsWith("/general-chat"))&&a0(t$(),{push:!1})};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[a0,eJ]),(0,i.useEffect)(()=>{if(!eU||aq.current===eU)return;aq.current=eU;let e=null;eU.newThread?(a8(),eU.dataRoomContext&&a5("",eU.dataRoomContext),at(eU.projectId??null)):eU.threadId&&(a0(eU.threadId),e=eU.threadId),eU.prompt&&to(e??"",eU.prompt),eW()},[eU,eW,a8,a5,a0,to]),(0,i.useEffect)(()=>
24{if(!te)return;let e=!0;return eN(te).then(t=>{if(e){if("missing"===t)return void a0(null,{push:!1});"loaded"===t&&(eT(te),eO(te))}}),()=>{e=!1}},[te,eN,eT,eO,a0]);let se=(0,i.useMemo)(()=>te?ew(te):[],[te,ew]),st=(te?eA[te]:void 0)??h.EMPTY_TURN,{isTyping:sa,streamingContent:ss,executionSteps:sn,agentActivities:sl,liveActions:si,statusStage:sr,activity:so}=st,sd=(0,i.useRef)(!1);(0,i.useEffect)(()=>{sd.current&&!sa&&e5(!0),sd.current=sa},[sa,e5]);let sc=aa[te??""]??null,su=(0,i.useMemo)(()=>tH(tw,e9),[tw,e9]),sm=(0,i.useMemo)(()=>{let e;return(e=tH(tw,e9))?1===tw.length?[e9("session.selection.suggestSummarizeOne",{defaultValue:"Summarize {{title}}",title:e.title}),e9("session.selection.suggestExtract",{defaultValue:"Extract key dates, numbers, and entities from {{title}}",title:e.title}),e9("session.selection.suggestRisks",{defaultValue:"List risks, decisions, and action items from {{title}}",title:e.title})]:[e9("session.selection.suggestSummarizeMany",{defaultValue:"Summarize these {{n}} files",n:tw.length}),e9("session.selection.suggestCompare","Compare the selected files and highlight differences"),e9("session.selection.suggestRisksMany","List risks, decisions, and action items across these files")]:[]},[tw,e9]),sh=tw.every(e=>t2.get(e)?.status==="complete"),sp=tw.filter(e=>t2.get(e)?.status==="complete").length,sg=tw.filter(e=>t2.get(e)?.status==="error").length,sf=te?tw.length-sp-sg:0,sx=!!te&&tw.length>0&&!sh,sb=!su&&!sc&&0===se.length&&!sa&&!eM[te??""];(0,i.useEffect)(()=>{let e=aU.current;if(!e)return;let t=()=>{e.style.height="0px",e.style.height=`${Math.min(e.scrollHeight,200)}px`};t();let a=e.clientWidth,s=new ResizeObserver(()=>{e.clientWidth!==a&&(a=e.clientWidth,t())});return s.observe(e),()=>s.disconnect()},[ti,sb]);let sv=(0,i.useMemo)(()=>{let e=new Map,t=t=>{let a=`${t.artifact_id}#${t.revision??1}`;e.delete(a),e.set(a,t)};for(let e of se)for(let a of e.actions??[])"artifact"===a.kind&&t(a);if(sa)for(let e of si)"artifact"===e.kind&&t(e);return Array.from(e.values())},[se,si,sa]),sj=(0,i.useMemo)(()=>{let e=new Map;for(let t of sv){let a=e.get(t.artifact_id);(!a||(t.revision??1)>=(a.revision??1))&&(e.delete(t.artifact_id),e.set(t.artifact_id,t))}return Array.from(e.values())},[sv]),sy=(0,i.useMemo)(()=>{let e=new Map,t=t=>{e.delete(t.url),e.set(t.url,{filename:t.filename,url:t.url,mime_type:t.mime_type,size_bytes:t.size_bytes})};for(let e of se)for(let a of e.actions??[])"file"===a.kind&&t(a);if(sa)for(let e of si)"file"===e.kind&&t(e);return Array.from(e.values())},[se,si,sa]),sw=(0,i.useMemo)(()=>(function(e,t,a){let s=[],n=null;for(let t of e)"agent"===t.role&&t.actions?.length&&(n=t.id);for(let t of e)for(let e of t.actions??[])s.push({action:e,stamp:function(e){if(!e)return"";let t=e instanceof Date?e:new Date(e);return Number.isNaN(t.getTime())?"":`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(t.timestamp),live:!1,last:t.id===n});if(a)for(let e of t)s.push({action:e,stamp:"",live:!0,last:!0});let l=new Map;for(let e of s)"artifact"===e.action.kind&&l.set(e.action.artifact_id,e.action);let i=new Set,r=new Set((0,f.collapseLatestActions)(s.map(e=>e.action)).flatMap(e=>"artifact"!==e.kind?[e]:i.has(e.artifact_id)?[]:(i.add(e.artifact_id),[l.get(e.artifact_id)]))),o={CARD:0,OUTPUT:0},d=[];for(let[e,t]of s.entries()){if("workflow_progress"===t.action.kind||!r.has(t.action))continue;let s=tg.has(t.action.kind)?"OUTPUT":"CARD",n=o[s]+=1,l=tx[t.action.kind]??("artifact"===t.action.kind?t.action.artifact_kind.toUpperCase():t.action.kind.toUpperCase());d.push({key:"plan_review"===t.action.kind?`plan-${t.action.interaction_id}`:`${s}-${n}-${e}`,action:t.action,register:s,no:n,label:`${s} ${String(n).padStart(2,"0")}`,head:t.stamp?`${l} \xb7 ${t.stamp}`:l,title:function(e){switch(e.kind){case"connect_service":return e.display_name;case"install_app":case"agent_created":return e.name;case"task_launched":case"routine_created":case"loop_plan":case"confirm":case"artifact":return e.title;case"app_plan":case"app_build":return e.app_name;case"os_action":return e.label??e.route;case"prompt":return e.question;case"approval":return e.summary??e.tool;case"questions":return e.questions[0]?.question??"";case"plan_review":return e.goal;case"file":return e.filename;case"sources":return e.items[0]?.title??"";default:return""}}(t.action),gate:function(e){if(!tf.has(e.kind))return!1;let t="status"in e?e.status:void 0;return null==t||"pending"===t}(t.action),interactive:t.live||t.last&&!a})}return d})(se,si,sa),[se,si,sa]),sk=(0,i.useMemo)(()=>(0,el.panelTurns)(se),[se]),sN=(0,i.useMemo)(()=>sk.flatMap(e=>e.panels),[sk]),sC=(0,i.useMemo)(()=>{for(let e=se.length-1;e>=0;e--){let t=se[e];
24if("agent"!==t.role)continue;let a=eF(t.actions,t.panelData);if(a)return a}return null},[se]),sS=(0,i.useMemo)(()=>{if(!sa)return!1;let e=0;for(let t of sn)tR.has(t.toolName)&&(e+="tool_call"===t.type?1:-1);return e>0},[sa,sn]);(0,i.useEffect)(()=>{a$.current=""},[te]),(0,i.useEffect)(()=>{let e=sj[sj.length-1],t=(sa?eF(si,null):null)??sC??(sS?aO:null);if(!t&&!sS)return;let a=`${te??"new"}:${t??"generating"}#${e?.revision??1}:${sN.length}`;a!==a$.current&&(a$.current=a,t&&(!aO||sa||sS)&&aI(t),aM(e=>({...e,open:!0})))},[aO,te,sj,sS,si,sC,sN.length,sa,aI,aM]);let[s_,sT]=(0,i.useState)(null),[sE,sA]=(0,i.useState)(0),[sR,sD]=(0,i.useState)(null),sM=sR?.agentId??null,[sI,sO]=(0,i.useState)(null),[sP,sL]=(0,i.useState)(null);(0,i.useEffect)(()=>{sT(null),sO(null),sL(null),sD(null)},[te]);let sF=(0,i.useMemo)(()=>{if(s_)return s_;let e=[...se.flatMap(e=>e.actions??[]),...sa?si:[]],t=(0,f.collapseLatestActions)(e).filter(e=>"app_build"===e.kind).filter(e=>null!=e.agent_id&&"succeeded"===e.status),a=t[t.length-1];return a&&null!=a.agent_id?{appId:a.app_id,agentId:a.agent_id,name:a.app_name,status:"published"===a.app_status?"published":"preview",runtimeMode:a.runtime_mode??(a.phases.some(e=>"source"===e.id)?"full_stack":"lightweight"),isOwner:!0,publishPending:"published"!==a.app_status}:null},[s_,se,si,sa]),s$=sI?.appId??sP?.appId??null,sB=null!=s$&&sF?.appId!==s$?s$:null,[sH,sz]=(0,i.useState)(null);(0,i.useEffect)(()=>{null!=sB&&sz(sB)},[sB]),(0,i.useEffect)(()=>{sz(null)},[te]);let sU=(0,i.useMemo)(()=>{let e=[...se.flatMap(e=>e.actions??[]),...sa?si:[]],t=(0,f.collapseLatestActions)(e).filter(e=>"app_plan"===e.kind);return t[t.length-1]??null},[se,si,sa]),sG=sF||sU?`${te}:${sF?.agentId??sU?.app_id}`:null;(0,i.useEffect)(()=>{sG&&eX.autoPanel&&!(0,G.isPalettePhoneViewport)()&&aM(e=>({...e,open:!0}))},[sG,eX.autoPanel,aM]);let sW=(0,i.useCallback)((e,t,a,s)=>{s?.appId!=null&&(sT(n=>({...n?.agentId===e?n:{},appId:s.appId,agentId:e,name:t,status:a,runtimeMode:s.runtimeMode,isOwner:!0,publishPending:n?.agentId===e?n.publishPending:"published"!==a})),sA(e=>e+1),aI("app"),(!s.automatic||eX.autoPanel)&&aM(e=>({...e,open:!0})))},[eX.autoPanel,aI,aM]),sK=(0,i.useRef)(null),sV=(0,i.useCallback)(e=>{let{appId:t,name:a,status:s,phases:n,detail:l,trail:i,queue:r}=e;if(sO(e=>{var o;return o={appId:t,name:a,phases:n,detail:l,trail:i,queue:r},"running"===s?o:e?.appId===o.appId?null:e}),sL(a=>"failed"===s?e:a?.appId===t?null:a),"running"!==s){sK.current===t&&(sK.current=null);return}sK.current!==t&&(sK.current=t,eX.autoPanel&&!(0,G.isPalettePhoneViewport)()&&aM(e=>({...e,open:!0})))},[eX.autoPanel,aM]);(0,i.useEffect)(()=>{if(!te)return;let e=!0;return(0,m.apiFetch)(`/api/v1/agent-apps/threads/${te}`).then(async t=>{if(!e||!t.ok)return;let a=await t.json();if(null!=a.agent_id&&"retired"!==a.status){if(a.build_progress?.job?.kind==="publish"&&"running"===a.build_state&&sD({agentId:a.agent_id,appId:a.id}),("building"===a.status||"failed"===a.status)&&null==a.current_ui_revision&&null==a.current_source_revision)return void sT(null);sT({appId:a.id,agentId:a.agent_id,name:a.plan_json?.name||"App",status:"published"===a.status?"published":"preview",runtimeMode:a.runtime_mode,isOwner:!!a.is_mine,publishPending:"published"!==a.status||a.current_ui_revision!==a.published_ui_revision||a.current_source_revision!==a.published_source_revision||!!a.has_pending_behavior,revision:"full_stack"===a.runtime_mode?a.current_source_revision:a.current_ui_revision,behaviorRev:"number"==typeof a.pending_behavior_rev?a.pending_behavior_rev:null})}}).catch(()=>{}),()=>{e=!1}},[te,null==sI,sE]);let[sY,sq]=(0,i.useState)(null),sJ=null!=sF&&(sF.publishPending??"published"!==sF.status);(0,i.useEffect)(()=>{if(sq(null),!sF||!sJ)return;let e=!0;return(0,m.apiFetch)(`/api/v1/agent-apps/${sF.agentId}/readiness`).then(async t=>{e&&t.ok&&sq(await t.json())}).catch(()=>{}),()=>{e=!1}},[sF?.agentId,sJ,null==sI]);let sX=(0,i.useCallback)(async()=>{if(sF&&sJ&&sM!==sF.agentId){if(sY?.overall==="requires_attention"){let e=sY.checks.filter(e=>"fail"===e.status).map(e=>e.id.replace(/_/g," ")).join(" · ");u.toast.error(e9("session.preview.publishBlocked",{defaultValue:"Fix these checks before publishing: {{failing}}",failing:e}));return}try{let e=new URLSearchParams;null!=sF.revision&&e.set("revision",String(sF.revision)),"behaviorRev"in sF&&null!=sF.behaviorRev&&e.set("behavior_rev",String(sF.behaviorRev));let t=e.toString()?`?${e}`:"",a=await (0,m.apiFetch)(`/api/v1/agent-apps/${sF.agentId}/publish${t}`,{method:"POST"});if(202===a.status){sD({agentId:sF.agentId,appId:sF.appId}),u.toast.info(e9("session.preview.appPublishQueued","Publication queued. Your app will appear when the release is ready."));return}sT(e=>e?.agentId===sF.agentId?{...e,status:"published",publishPending:!1}:e),u.toast.success(e9("session.preview.appPublishedToast","App published to your library."))}catch(t){let e=t instanceof Error?t.message:"";"stale_revision"===e&&(sT(null),sA(e=>e+1)),u.toast.error("requires_attention"===e?e9("session.preview.publishBlockedShort","Fix the readiness checks before publishing."):"readiness_unavailable"===e?e9("session.preview.publishUnavailable","Readiness could not be verified. Try again shortly."):"stale_revision"===e?e9("session.preview.publishStale","The app changed since you reviewed it. Check the new preview, then publish."):e.startsWith("live_provisioning_failed")?e9("session.preview.publishLiveFailed","Publishing couldn't prepare the app's live data. The previous version stays live."):e9("session.preview.publishFailed","Couldn't publish the app. Try again."))}}},[sF,sJ,sY,sM,e9]),sZ=(0,i.useCallback)(e=>{null!=e.build_state&&"running"!==e.build_state&&(sD(null),sA(e=>e+1),"succeeded"===e.build_state&&"published"===e.status?u.toast.success(e9("session.preview.appPublishedToast","App published to your library.")):u.toast.error(e9("session.preview.publishLiveFailed","Publishing couldn't prepare the app's live data. The previous version stays live.")))},[e9]);
24(0,er.useAppBuildStream)(sR?.appId??null,null!=sR,sZ);let sQ=(0,i.useMemo)(()=>{let e=sY?.checks.find(e=>"revision_quality"===e.id);return e&&"ok"!==e.status&&sF?e.params?.judges_unavailable?"recheck":"improve":null},[sY,sF]),s0=(0,i.useCallback)(async()=>{if(sF&&sQ){try{await (0,m.apiFetch)(`/api/v1/agent-apps/${sF.agentId}/${"recheck"===sQ?"recheck":"improve"}`,{method:"POST"})}catch{u.toast.error(e9("session.preview.qualityActionFailed","Couldn't start that. Try again."));return}u.toast.success("recheck"===sQ?e9("session.preview.recheckStarted","Re-checking this version's qualityâ¦"):e9("session.preview.improveStarted","Improving the app â the preview updates when it's ready.")),sA(e=>e+1)}},[sF,sQ,e9]),s1=(0,i.useCallback)(async()=>{let e=sI?.appId??sF?.appId;if(null!=e){try{await (0,m.apiFetch)(`/api/v1/agent-apps/builds/${e}/cancel`,{method:"POST"}),u.toast.success(e9("session.preview.buildCancelled","Stopped."))}catch(e){if(409!==e.status)return void u.toast.error(e9("session.preview.cancelFailed","Couldn't stop the build. Try again."))}sO(null),sA(e=>e+1)}},[sI?.appId,sF?.appId,e9]),s2=(0,i.useCallback)(()=>{if(!sF)return;let e=(0,ed.agentLaunchTarget)({agent_id:sF.agentId,ui_type:"app"});eB(e.route,e.subRoute)},[sF,eB]),s3=!aP&&!sb&&!!te,s4=Q.find(e=>e.id===te)?.title??e9("session.untitled","Untitled"),s5=!au,s6=(0,i.useCallback)(e=>{e?aI(e):aO||aI(sC),aM(e=>({...e,open:!0}))},[aO,sC,aI,aM]),s7=(0,i.useCallback)(()=>{aM(e=>({...e,open:!1})),requestAnimationFrame(()=>aU.current?.focus())},[aM]),s8=(0,i.useCallback)(e=>{var t;s6(("artifact"===(t=e.action).kind?t.artifact_id:"file"===t.kind?eI+t.url:null)??void 0)},[s6]);(0,i.useEffect)(()=>{if(!eP||eP.convId!==te)return;let{action:e}=eP;eL(eP.id),eB(e.route,e.sub_route)},[eP,te,eL,eB]);let s9=(e,t)=>{!e0&&te&&eS(te,e,al||void 0,{reasoningEffort:ad,sessionMode:ap,planOnly:af,approvedPlanInteractionId:af?void 0:t?.approvedPlanInteractionId})},ne=e=>"OUTPUT"===e.register?(0,t.jsx)(tb,{entry:e,onOpen:s8},e.key):(0,t.jsx)(tv,{entry:e,planExecution:te&&"plan_review"===e.action.kind?eD[te]?.[e.action.interaction_id]:void 0,compact:!0,onReply:"followups"===e.action.kind?e0||sa||tP||sx||te&&eM[te]?void 0:e=>{ns(e)}:s9,onEdit:e=>{e&&td(e),aU.current?.focus()},onOpenArtifact:s6,onPreviewApp:sW,onBuildProgress:sV},e.key),nt=(e,a)=>(0,t.jsx)(tA,{turn:e,renderActivity:e=>(0,t.jsx)(tC,{turn:e,rows:tL(e,e9),status:e.isTyping?a:void 0}),renderPlan:e=>{let a=sw.find(t=>"plan_review"===t.action.kind&&t.action.interaction_id===e);return a?(0,t.jsx)("div",{className:"msg bot",children:(0,t.jsx)("div",{className:"bub",children:ne(a)})}):null}}),na=(e,t)=>"plan_review"===e.kind&&t?.planBoundaries?.some(t=>t.interactionId===e.interaction_id),ns=async(e,t,a)=>{if(!e2())return;if(e6)return void e8(!0);if(e0||aK.current)return;let s=(e??ti).trim(),n=tw.length>0||tE.length>0||!!t?.length;if(sa||tP||te&&eM[te])return;if(null==e&&!t&&!a){if("/plan"===s){aQ(!af),td("");return}if("/help"===s)return void window.dispatchEvent(new CustomEvent("po:shortcuts"));if("/new"===s){td(""),a8();return}}if(!s&&!n||sx)return;aK.current=!0;let l=te,i=!1;try{if(!l){if(l=await ef(),null==e&&to(l,ti),sc&&a5(l,sc),ae)try{eQ(l,ae)}catch{u.toast.error(e9("projects.saveFailed","Could not save projects in this browser. Your conversations are unchanged."))}at(null),a6(""),a0(l)}let n=t;if(!t&&(tw.length||tE.length)){if(tF(!0),await a3(tw,l),tw.some(e=>!t6.current.has(e)))throw Error("Attachments have not finished uploading");n=[...tw.flatMap(e=>{let t=t6.current.get(e);return t?[t]:[]}),...tE],tF(!1)}let r=eC(l,s,n,(an?"":al)||void 0,{reasoningEffort:ad,sessionMode:ap,planOnly:af,...a?{turnId:a,approvedPlanInteractionId:Object.values(eD[l]??{}).find(e=>e.turn_id===a)?.interaction_id}:{},onAccepted:()=>{null!=e||t||(tc(tl,l??""),a1(),tI([]))},...sc?{dataRoomContext:{room_id:sc.roomId,kind:sc.kind,target_id:"room"===sc.kind?null:sc.targetId??null,target_name:sc.targetName}}:{}});i=!0,aY(e=>e+1),await r}catch(e){console.error("Send failed:",e),u.toast.error(e9("session.sendFailed","Couldn't send that message. Your text and files are still here."))}finally{i||(aK.current=!1,tF(!1))}},nn=()=>{te&&!sa&&eC(te,"(regenerate)",void 0,(an?"":al)||void 0,{regenerate:!0,reasoningEffort:ad,sessionMode:ap,planOnly:af})},nl=e=>{let t=tj.trim();t&&eb(e,t),tp(null)},ni=(e,t)=>{tm(null),ez({title:e9("session.rename.title","Rename conversation"),desc:"",confirmLabel:e9("session.rename.save","Save"),input:{label:e9("session.rename.field","Name / value"),value:t??""},onConfirm:t=>{if(t)return eb(e,t)}})},nr=(e,t)=>
24{tm(null),ez({title:e9("session.confirmDelete.title","Delete session?"),desc:e9("session.confirmDelete.desc",{defaultValue:'"{{title}}" and its messages will be removed. This cannot be undone.',title:t??e9("session.untitled","Untitled")}),danger:!0,confirmLabel:e9("session.confirmDelete.confirm","Delete"),onConfirm:async()=>{if(await ej(e)===!1)return!1;a6(e),e===te&&a0(null)}})},[no,nd]=(0,i.useState)(!1),[nc,nu]=(0,i.useState)(!1),[nm,nh]=(0,i.useState)(!1),[np,ng]=(0,i.useState)(null),{speakingId:nf,read:nx,stop:nb}=(0,K.useResponseSpeech)(`${eH}:${te??""}`),[nv,nj]=(0,i.useState)(null),[ny,nw]=(0,i.useState)(null),[nk,nN]=(0,i.useState)(null),[nC,nS]=(0,i.useState)(null),n_=se.find(e=>e.id===nk?.id),[nT,nE]=(0,i.useState)(!1),nA=(0,i.useRef)(!1),nR=(e,t)=>{nb(),aW(null);let a=Q.find(e=>e.id===t);eb(e,`${a?.title??e9("session.untitled","Untitled")}${e9("sideChat.branchSuffix"," · Branch")}`);let s=eZ.find(e=>e.conversations.includes(t));if(s)try{eQ(e,s.id)}catch{u.toast.error(e9("projects.saveFailed","Could not save projects in this browser. Your conversations are unchanged."))}let n=aa[t];return n&&a5(e,n),a0(e),requestAnimationFrame(()=>aU.current?.focus()),n},nD=(e,t,a,s)=>{to(e,a);let n=nR(e,t);eC(e,a,s,(an?"":al)||void 0,{reasoningEffort:ad,sessionMode:ap,planOnly:af,...n?{dataRoomContext:{room_id:n.roomId,kind:n.kind,target_id:n.targetId??null,target_name:n.targetName}}:{},onAccepted:()=>tn(t=>t[e]===a?{...t,[e]:""}:t)}).catch(()=>u.toast.error(e9("sideChat.sendFailed","Could not send. Your draft is kept in the new branch.")))},nM=async e=>{if(te&&!e0&&!sa&&!nA.current){nA.current=!0,nE(!0);try{let t=await ex(te,e);nR(t,te)}catch{u.toast.error(e9("session.msg.branchFailed","Could not create the branch. Please try again."))}finally{nA.current=!1,nE(!1)}}},nI=(e,t,a)=>{let s=document.createElement("a");s.href=URL.createObjectURL(new Blob([t],{type:a})),s.download=e,s.click(),setTimeout(()=>URL.revokeObjectURL(s.href),2e3)},nO=e=>{let t=s4.replace(/[\\/:*?"<>|]+/g,"-").slice(0,60)||"conversation";"json"===e?nI(`${t}.json`,JSON.stringify({title:s4,exportedAt:new Date().toISOString(),messages:se.map(e=>({role:e.role,content:e.content}))},null,2),"application/json"):nI(`${t}.md`,`# ${s4} 25 26`+se.map(e=>`**${"user"===e.role?e9("session.share.me","Me"):"Palette"}** 27 28${e.content}`).join("\n\n---\n\n"),"text/markdown"),nd(!1)},nP=(0,i.useMemo)(()=>tL(st,e9),[st,e9]),nL=(0,i.useMemo)(()=>[...nP].reverse().find(e=>"running"===e.state&&!e.key.startsWith("td-")),[nP]),nF=(0,i.useMemo)(()=>[...nP].reverse().find(e=>"running"===e.state&&e.key.startsWith("td-")),[nP]),n$=sr?e9(`session.status.${sr}`,tM[sr]??tO(sr)):null,nB=sa?("reconnecting"===sr||"recovering"===sr||"queued"===sr?n$:null)??so??(nL?"web_search"===nL.tool&&nL.sub?e9("session.live.searchDetail","Searching the web for '{{detail}}'",{detail:nL.sub}):"web_fetch"===nL.tool&&nL.sub?e9("session.live.readDetail","Reading {{detail}}",{detail:nL.sub}):nL.sub?`${nL.label} â ${nL.sub}`:nL.label:null)??(ss?e9("session.live.writing","Writingâ¦"):null)??nF?.label??n$??e9("session.live.thinking","Thinkingâ¦"):e9("session.status.ready","READY"),nH=e3?e9("session.hero.guestLine","A new AI is here."):e9(tZ,tQ),nz=e=>eA[e.id]?.isTyping?"run":e.awaiting?"gate":e.hasOutput?"done":"idle",[nU,nG]=(0,i.useState)([]);(0,i.useEffect)(()=>{try{let e=JSON.parse(localStorage.getItem(tW)??"[]");Array.isArray(e)&&nG(e.filter(e=>"string"==typeof e))}catch{}},[]);let nW=(0,i.useCallback)(e=>{nG(t=>{let a=t.includes(e)?t.filter(t=>t!==e):[e,...t];try{localStorage.setItem(tW,JSON.stringify(a))}catch{}return a})},[]),nK=(0,i.useMemo)(()=>Q.filter(e=>!nU.includes(e.id)),[Q,nU]),nV=(0,i.useMemo)(()=>"ARCHIVED"===ab?Q.filter(e=>nU.includes(e.id)):"ALL"===ab?nK:nK.filter(e=>t1(e)===ab),[Q,nK,nU,ab]),nY=(0,i.useMemo)(()=>{let e=aw.trim().toLowerCase();return e?nK.filter(t=>(t.title??"").toLowerCase().includes(e)||(t.lastMessage??"").toLowerCase().includes(e)):nK},[nK,aw]),{pinned:nq,togglePin:nJ,listRef:nX,statusRef:nZ,onClickCapture:nQ}=(0,H.usePinnedConversations)(nV.map(e=>e.id),au);(0,B.useConversationTitleOverflow)(nX);let n0=(0,i.useMemo)(()=>nq.map(e=>nV.find(t=>
28t.id===e)).filter(e=>!!e),[nq,nV]),n1=(0,i.useMemo)(()=>new Set(eZ.flatMap(e=>e.conversations)),[eZ]),n2=(0,i.useMemo)(()=>nV.filter(e=>!nq.includes(e.id)&&!n1.has(e.id)),[nq,nV,n1]),n3=e=>{let t=nq.includes(e.id),a=nU.includes(e.id);return[{k:"rename",glyph:"h_pencil",hint:"Alt Ctrl R",label:e9("session.menu.rename","Rename"),run:()=>ni(e.id,e.title)},{k:"pin",glyph:"h_pin",hint:"Alt Ctrl P",label:t?e9("session.menu.unpin","Unpin"):e9("session.menu.pin","Pin"),run:()=>{nJ(e.id),tm(null),nh(!1)}},{k:"project",glyph:"h_folder",label:e9("projects.move","Move to project"),run:()=>{tm(null),nh(!1),eq({conversationId:e.id})}},{k:"archive",glyph:"h_archive",hint:"Ctrl Shift A",label:a?e9("session.menu.unarchive","Unarchive"):e9("session.menu.archive","Archive"),run:()=>{nW(e.id),tm(null),nh(!1)}},{k:"delete",glyph:"h_trash",sep:!0,danger:!0,label:e9("session.menu.delete","Delete"),run:()=>{nh(!1),nr(e.id,e.title)}}]},n4=e=>e.map((e,a)=>(0,t.jsxs)(i.Fragment,{children:[e.sep&&(0,t.jsx)("div",{className:"clMenuSep",role:"separator"}),(0,t.jsxs)("button",{type:"button",role:"menuitem",autoFocus:0===a,className:e.danger?"danger":void 0,onClick:t=>{t.currentTarget.closest(".clItem, .ssTopbarMenuWrap")?.querySelector(".clKebab, .ssTopbarMore")?.focus(),e.run()},children:[(0,t.jsx)($.Glyph,{name:e.glyph,className:"clMi"}),(0,t.jsx)("span",{className:"clMl",children:e.label}),e.hint&&(0,t.jsx)("span",{className:"clMk","aria-hidden":!0,children:e.hint})]})]},e.k)),n5=e=>(0,t.jsxs)("div",{"data-thread-id":e.id,"data-reorder-pinned":nq.includes(e.id)?"":void 0,className:`clItem${e.id===te?" active":""}${tu===e.id?" menuOpen":""}`,"aria-current":e.id===te?"page":void 0,onClick:()=>a0(e.id),children:[th!==e.id&&(0,t.jsx)("span",{className:`clState ${nz(e)}`,title:e9(`session.list.state.${nz(e)}`,tX[nz(e)]),children:"gate"===nz(e)?"?":""}),th===e.id?(0,t.jsx)("input",{className:"clRename",autoFocus:!0,value:tj,onClick:e=>e.stopPropagation(),onChange:e=>ty(e.target.value),onKeyDown:t=>{"Enter"===t.key&&nl(e.id),"Escape"===t.key&&tp(null)},onBlur:()=>nl(e.id)}):(0,t.jsx)("button",{type:"button",className:"t clT",children:(0,t.jsx)("span",{className:"clTitleViewport",children:(0,t.jsx)("span",{className:"clTx",children:e.title??e9("session.untitled","Untitled")})})}),th!==e.id&&(0,t.jsx)("span",{className:`clBadge ${t1(e).toLowerCase()}`,children:t1(e)}),(0,t.jsx)("span",{className:"time",children:(0,em.relTime)(e.updatedAt)}),(0,t.jsx)("button",{type:"button",className:"clKebab","aria-label":e9("session.list.options","Session options"),onClick:t=>{t.stopPropagation(),tm(t=>t===e.id?null:e.id)},children:(0,t.jsx)($.Glyph,{name:"h_more"})}),tu===e.id&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"clMenuBd",onClick:e=>{e.stopPropagation(),tm(null)}}),(0,t.jsx)("div",{className:"clMenu",role:"menu",onClick:e=>e.stopPropagation(),onKeyDown:e=>{"Escape"===e.key&&tm(null)},children:n4(n3(e))})]})]},e.id);(0,i.useEffect)(()=>{let e=e=>{if(e.defaultPrevented||e.isComposing||!(e.ctrlKey||e.metaKey)||e.target instanceof Element&&e.target.closest('[role="dialog"], [role="menu"]'))return;let t=e.key.toLowerCase();if("k"===t&&!e.altKey&&!e.shiftKey){e.preventDefault(),e2()&&aC(e=>!e);return}if("b"===t&&!e.altKey&&!e.shiftKey){e.preventDefault(),am(e=>!e);return}if("o"===t&&e.shiftKey&&!e.altKey){e.preventDefault(),a8();return}if("l"===t&&!e.altKey&&!e.shiftKey){e.preventDefault(),aU.current?.focus();return}if(te){if(e.altKey&&"s"===t&&!e.shiftKey&&!e0){e.preventDefault(),ng(te);return}if(e.altKey&&"r"===t){e.preventDefault();let t=Q.find(e=>e.id===te);ni(te,t?.title??null)}else e.altKey&&"p"===t?(e.preventDefault(),nJ(te)):e.shiftKey&&"a"===t&&(e.preventDefault(),nW(te))}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[te,Q,nJ,nW,am,e0,a8,e2]);let n6=!!sc&&0===se.length&&!sa&&!eM[te??""],n7=!!su&&0===se.length&&!sa&&!eM[te??""],n8=(0,i.useRef)(!0),n9=(0,i.useRef)(0),[le,lt]=(0,i.useState)(!1),la=(0,i.useCallback)(()=>{let e=aB.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<96,a=e.scrollTop<n9.current;n9.current=e.scrollTop,t?n8.current=!0:a&&(n8.current=!1),lt(!n8.current)},[]),ls=(0,i.useRef)(0),ln=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=aB.current;if(!e||sb||!n8.current)return;let t=ln.current!==(te??null),a=se.length!==ls.current;ln.current=te??null,ls.current=se.length,e.scrollTo({top:e.scrollHeight,behavior:!a||t||tJ()?"auto":"smooth"})},[sb,se.length,ss,sn.length,sl,te,sa,so,st.responseSegments]),(0,i.useEffect)(()=>{sa||aF(!1)},[sa]);let ll=(0,i.useCallback)(()=>{let e=aB.current;n8.current=!0,lt(!1),e?.scrollTo({top:e.scrollHeight,behavior:tJ()?"auto":"smooth"})},[]),li=(0,i.useRef)(sb);(0,i.useEffect)(()=>{li.current!==sb&&(li.current=sb,aU.current?.focus())},[sb]);let lr=(0,y.useSmartSuggestions)({surface:"file-selected",enabled:!!sc,threadId:te,dataRoomContext:sc?{roomId:sc.roomId,kind:sc.kind,targetId:"room"===sc.kind?null:sc.targetId??null,targetName:sc.targetName}:null}),lo=(0,y.useSmartSuggestions)({surface:"file-selected",enabled:!!su,threadId:te,localFiles:tw.map(e=>e.name)}
28),ld=(0,i.useCallback)(e=>{td(e);let t=aU.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length))},[td]);return(0,t.jsx)(eo.AppLiveBuildScope,{appId:sH,enabled:null!=sH&&sB===sH,children:(0,t.jsxs)(ec.TipHost,{children:[ny&&(0,t.jsx)(D.PluginConnectionsDialog,{returnFocus:ny.trigger,onClose:()=>nw(null),onManage:()=>eV("plugin")}),nC&&(0,t.jsx)(P.ResponseHistoryDialog,{threadId:nC.threadId,returnFocus:nC.trigger,onClose:()=>nS(null)},nC.threadId),nk&&n_&&(0,t.jsx)(O.MessageDialog,{message:n_,request:"user"===n_.role?n_:se.slice(0,se.indexOf(n_)).reverse().find(e=>"user"===e.role),mode:nk.mode,returnFocus:nk.trigger,onClose:()=>nN(null),onDownload:e=>nI("Palette_message.md",e,"text/markdown;charset=utf-8")},`${nk.id}:${nk.mode}`),np&&(0,t.jsx)(M.SideChatDialog,{threadId:np,blocked:e0||!!eA[np]?.isTyping,onClose:()=>ng(null),onBranch:(e,t)=>nD(e,np,t)},np),(0,t.jsxs)("div",{className:"viewPane sessionView","data-list-density":eX.density,children:[(0,t.jsxs)("div",{className:"ssHeadRow",inert:s5,children:[!e0&&(0,t.jsxs)("button",{type:"button",className:`ssNewBtn${"work"===ap?" work":""}`,onClick:a8,disabled:et||tP,children:[(0,t.jsx)("span",{className:"ssNewMark",children:(0,t.jsx)($.Glyph,{name:"h_edit"})}),e9("session.list.newSession","New Chat")]}),(0,t.jsx)("button",{type:"button",className:"ssSearchBtn",ref:aS,onClick:()=>{e2()&&aC(!0)},title:e9("session.search.title","Search conversations"),"aria-label":e9("session.search.title","Search conversations"),children:(0,t.jsx)($.Glyph,{name:"h_search"})}),aN&&(0,t.jsxs)(R.ConversationDialog,{title:e9("session.search.title","Search conversations"),onClose:()=>aC(!1),fallbackFocus:aS,initialFocus:a_,children:[(0,t.jsxs)("div",{className:"ssSearchField poSearch",children:[(0,t.jsx)($.Glyph,{name:"h_search"}),(0,t.jsx)("input",{type:"search",ref:a_,value:aw,onChange:e=>ak(e.target.value),placeholder:e9("session.search.placeholder","Search titles and messages"),"aria-label":e9("session.search.title","Search conversations")})]}),(0,t.jsxs)("div",{className:"ssSearchResults",children:[0===nY.length&&(0,t.jsx)("div",{className:"ssSearchEmpty",children:e9("session.search.empty","No results.")}),nY.map(e=>(0,t.jsxs)("button",{type:"button",className:"ssSearchHit",onClick:()=>{a0(e.id),aC(!1)},children:[(0,t.jsx)($.Glyph,{name:"h_chat"}),(0,t.jsx)("span",{children:e.title??e9("session.untitled","Untitled")})]},e.id))]})]}),(0,t.jsxs)("div",{className:"ssFilterWrap",children:[(0,t.jsxs)("button",{type:"button",className:`ssFilterBtn${"ALL"!==ab?" on":""}`,ref:aT,onClick:e=>{if(!e2())return;let t=e.currentTarget.getBoundingClientRect();ay(e=>e?null:{x:t.right-226,y:t.bottom+10})},"aria-expanded":!!aj,"aria-haspopup":"menu",children:[(0,t.jsx)($.Glyph,{name:"h_sliders"}),(0,t.jsx)("span",{className:"sr",children:"ALL"===ab?e9("session.filter.all","All"):ab}),(0,t.jsx)("span",{className:"ssFilterCaret",children:"â¾"})]}),aj&&!s5&&(0,t.jsx)(I.PoContextMenu,{className:"poSidebarMenu",onClose:()=>ay(null),ctx:{...aj,sections:[[{label:e9("session.search.title","Search conversations"),icon:"h_search",on:()=>aC(!0)},{label:e9("projects.manage","Manage projects"),icon:"h_folder",on:()=>eq({})},{label:e9("session.list.archivedTitle","Archived conversations"),icon:"h_archive",on:()=>nu(!0)}],[{label:e9("session.list.sortRecent","Sort by recent activity"),icon:"h_clock",on:()=>(()=>{av("ALL"),ay(null);try{localStorage.setItem(tq,"ALL")}catch{}})()},{label:e9("session.list.densitySettings","List density / settings"),icon:"h_settings",on:()=>eY(!0)}]]}}),nc&&(0,t.jsxs)(R.ConversationDialog,{title:e9("session.list.archivedTitle","Archived conversations"),onClose:()=>nu(!1),fallbackFocus:aT,children:[0===nU.length&&(0,t.jsx)("div",{className:"ssSearchEmpty",children:e9("session.list.archivedEmpty","No archived conversations.")}),Q.filter(e=>nU.includes(e.id)).map(e=>(0,t.jsxs)("div",{className:"ssDlgRow",children:[(0,t.jsx)("button",{type:"button",className:"ssDlgRowMain",onClick:()=>{a0(e.id),nu(!1)},children:e.title??e9("session.untitled","Untitled")}),(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>nW(e.id),children:e9("session.list.restore","Restore")}),(0,t.jsx)("button",{type:"button",className:"ssDlgIcon",title:e9("session.list.deleteForever","Delete permanently"),"aria-label":e9("session.list.deleteForever","Delete permanently"),onClick:()=>{nu(!1),setTimeout(()=>nr(e.id,e.title),60)},children:(0,t.jsx)($.Glyph,{name:"h_trash",strokeWidth:1.6})})]},e.id))]})]}),(0,t.jsx)("div",{className:"ssSeg",children:(0,t.jsxs)("button",{type:"button",className:`ssSegBtn${s5?" on":""}`,"aria-pressed":s5,"aria-controls":"poSessionList","aria-expanded":!s5,title:s5?e9("session.seg.showList","Show conversations"):e9("session.seg.hideList","Hide conversations"),onClick:()=>am(e=>!e),children:[(0,t.jsx)($.Glyph,{name:"h_panelLeft"}),(0,t.jsx)("span",{className:"sr",children:s5?e9("session.seg.showList","Show conversations"):e9("session.seg.hideList","Hide conversations")})]})})]}),(0,t.jsxs)("div",{id:"poSessionList",inert:s5,className:`chatList${s5?" stood-down":""}`,children:[(0,t.jsx)("span",{className:"clRelief","aria-hidden":"true"}),(0,t.jsx)(n.SidebarResizer,{open:au}),(0,t.jsxs)("div",{className:"clItems",ref:nX,onClickCapture:nQ,children:[et&&(0,t.jsx)("div",{className:"clItem skeleton",children:(0,t.jsx)("span",{className:"t",children:e9("session.untitled","Untitled")})}),ee&&0===Q.length&&[0,1,2].map(e=>(0,t.jsx)("div",{className:"clItem skeleton",children:(0,t.jsx)("span",{className:"t",children:e9("session.loading","Loadingâ¦")})},e)),!e3&&[{id:"pinned",name:e9("session.list.pinned","Pinned"),rows:n0},{id:"recent",name:e9("session.list.recent","Recent"),rows:n2},...eZ.map(e=>({id:`project:${e.id}`,name:e.name,rows:nV.filter(t=>e.conversations.includes(t.id)&&!nq.includes(t.id))}
28))].map(e=>(0,t.jsxs)("details",{className:"clGroup",open:!0,children:[(0,t.jsxs)("summary",{className:"clSection",children:[(0,t.jsx)($.Glyph,{name:"h_chevronRight"}),(0,t.jsx)("span",{children:e.name})]}),e.rows.map(n5)]},e.id)),ep&&(0,t.jsx)("div",{ref:aJ,className:"clMore",role:"status","aria-live":"polite",children:eg?e9("session.loading","Loadingâ¦"):(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>void eh(),children:e9("history.loadMore","Load more")})}),!e3&&!ee&&0===Q.length&&(0,t.jsx)("div",{className:"clEmpty",children:e9("session.list.empty","No sessions yet")})]}),(0,t.jsx)("div",{ref:nZ,className:"poPinnedStatus",role:"status","aria-live":"polite"}),(0,t.jsxs)("div",{className:"ssFoot",children:[(0,t.jsx)("span",{className:"ssFootSpacer"}),(0,t.jsx)("button",{type:"button",className:"ssFootBtn",title:e9("session.list.archivedTitle","Archived conversations"),"aria-label":e9("session.list.archivedTitle","Archived conversations"),onClick:()=>{e2()&&nu(!0)},children:(0,t.jsx)($.Glyph,{name:"h_archive",strokeWidth:1.6})}),(0,t.jsx)("button",{type:"button",className:"ssFootBtn",title:e9("session.list.settings","Settings"),"aria-label":e9("session.list.settings","Settings"),onClick:()=>{e2()&&eY(!0)},children:(0,t.jsx)($.Glyph,{name:"h_settings",strokeWidth:1.6})})]})]}),(0,t.jsxs)("div",{ref:aH,className:"sessionWorkspace",style:{"--po-chat-col":s3?"calc(100% - var(--work-panel-size))":"100%"},children:[(0,t.jsxs)("div",{className:"chatMain",onDragEnter:e=>{a7(e)&&(e.preventDefault(),t9.current+=1,t8(!0))},onDragOver:e=>{a7(e)&&e.preventDefault()},onDragLeave:()=>{t9.current=Math.max(0,t9.current-1),0===t9.current&&t8(!1)},onDrop:e=>{if(!a7(e))return;e.preventDefault(),t9.current=0,t8(!1);let t=Array.from(e.dataTransfer.files??[]);t.length&&a4(t)},children:[t7&&(0,t.jsxs)("div",{className:"chatDropOverlay",role:"status","aria-live":"polite",children:[(0,t.jsx)($.Glyph,{name:"h_upload"}),(0,t.jsx)("span",{children:e9("session.drop.title","Drop files here")})]}),!sb&&te&&(0,t.jsxs)("div",{className:"ssTopbar",children:[(0,t.jsx)("span",{className:"ssTopbarTitle",title:s4,children:s4}),(0,t.jsxs)("span",{className:"ssTopbarMenuWrap",children:[(0,t.jsx)("button",{type:"button",className:"ssTopbarBtn ssTopbarMore","aria-haspopup":"menu","aria-expanded":nm,title:e9("session.topbar.threadMenu","Conversation menu"),"aria-label":e9("session.topbar.threadMenu","Conversation menu"),onClick:()=>nh(e=>!e),children:(0,t.jsx)($.Glyph,{name:"h_more",strokeWidth:1.6})}),nm&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"clMenuBd",onClick:()=>nh(!1)}),(0,t.jsx)("div",{className:"clMenu ssTopbarMenu",role:"menu",onKeyDown:e=>{"Escape"===e.key&&nh(!1)},children:n4(n3({id:te,title:Q.find(e=>e.id===te)?.title??null}))})]})]}),(0,t.jsxs)("span",{className:"ssTopbarEnd",children:[(0,t.jsx)("button",{type:"button",className:"ssTopbarBtn",ref:aE,title:e9("session.share.title","Share / export"),"aria-label":e9("session.share.title","Share / export"),onClick:()=>nd(!0),children:(0,t.jsx)($.Glyph,{name:"h_share",strokeWidth:1.6})}),!s3&&(0,t.jsx)("button",{type:"button",className:"ssTopbarBtn","aria-expanded":!1,title:e9("session.preview.open","Open work panel"),"aria-label":e9("session.preview.open","Open work panel"),onClick:()=>s6(),children:(0,t.jsx)($.Glyph,{name:"h_panelRight",strokeWidth:1.6})})]})]}),no&&(0,t.jsxs)(R.ConversationDialog,{title:e9("session.share.title","Share / export"),onClose:()=>nd(!1),fallbackFocus:aE,children:[(0,t.jsx)("p",{className:"ssDlgP",children:e9("session.share.desc","Download a copy of this conversation as a local file.")}),(0,t.jsxs)("div",{className:"ssDlgNote",children:[s4," · ",e9("session.share.count",{defaultValue:"{{count}} messages",count:se.length}),(0,t.jsx)("br",{}),e9("session.share.noAttachments","Attached source files are not included in the export.")]}),(0,t.jsxs)("div",{className:"ssDlgActions",children:[(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>nO("md"),children:e9("session.share.markdown","Download Markdown")}),(0,t.jsx)("button",{type:"button",className:"cfBtn cfPrimary",onClick:()=>nO("json"),children:e9("session.share.json","Download JSON")})]})]}),(0,t.jsxs)("div",{className:`chatStack${sb?" isHero":""}`,children:[(0,t.jsxs)("div",{ref:aB,onScroll:la,className:`chatLog${sb?" isHero":n6||n7?" isContextReady":""}`,children:[sb?(0,t.jsx)("div",{className:"chatHero",children:(0,t.jsx)("div",{className:"heroH",role:"heading","aria-level":1,"aria-label":nH,children:nH.split(" ").map((e,a)=>(0,t.jsx)("span",{className:"hwm","aria-hidden":"true",style:{"--i":a},children:(0,t.jsx)("span",{className:"hwi",children:e})},`${e}-${a}`))})}):(0,t.jsxs)(t.Fragment,{children:[te&&eM[te]&&0===se.length&&(0,t.jsx)("div",{className:"msg bot","aria-busy":"true","aria-label":e9("session.loading","Loadingâ¦"),children:(0,t.jsxs)("div",{className:"bub ssSkelBub",children:[(0,t.jsx)("span",{className:"rlSkel",style:{width:"62%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{width:"88%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{width:"40%"}})]})}),se.map((e,a)=>{let s=a===se.length-1,n=!!e.attachments?.length&&(0,t.jsx)("div",{className:"msgFiles",children:e.attachments.map((a,s)=>{if(a.mime_type?.startsWith("audio/"))return(0,t.jsx)(p.AttachmentTile,{name:a.filename,mime:a.mime_type,size:a.file_size,url:a.file_url,href:a.file_url},s);let n=`${e.id}:${s}:${a.file_url}`,l=a.mime_type?.startsWith("image/")&&!a.mime_type.includes("photoshop")&&!t_.has(n);return(0,t.jsx)("button",{type:"button",className:"ssSentFile","aria-label":e9("common:attachment.openFile","Open {{name}}",{name:a.filename}),onClick:()=>tS({key:n,name:a.filename,mime:a.mime_type??"",size:a.file_size,url:a.file_url,pending:!1}),children:l?(0,t.jsx)("img",{src:a.file_url,alt:"",onError:()=>tT(e=>new Set(e).add(n))}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)($.Glyph,{name:"h_file"}),(0,t.jsx)("span",{children:a.filename})]})},n)})});if("user"===e.role)return(0,t.jsxs)("div",{className:"ssUserLane",children:[aG===e.id&&te?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(L.InlineMessageEditor,{threadId:te,messageId:e.id,initialText:e.content,blocked:e0||sa,onCancel:()=>{aW(null),requestAnimationFrame(()=>aB.current?.querySelector(`[data-edit-message="${e.id}"]`)?.focus())},onBranch:(t,a)=>nD(t,te,a,e.attachments??void 0)},`${te}:${e.id}`),n]}):(0,t.jsx)("div",{className:"msg me",children:(0,t.jsxs)("div",{className:"bub",children:[(0,t.jsx)("span",{className:"tx",children:e.content}),n]})}),!sa&&aG!==e.id&&(0,t.jsxs)("div",{className:"ssRowActs",children:[(0,t.jsx)(b.CopyButton,{text:e.content,className:"ssEdit",copyLabel:e9("session.msg.copyMessage","Copy message"),icons:{copy:(0,t.jsx)($.Glyph,{name:"h_responseCopy"}),copied:(0,t.jsx)($.Glyph,{name:"h_responseCopy"})},onCopied:()=>u.toast.success(e9("session.msg.copied","Copied"))}),(0,t.jsx)(ec.Tip,{label:e9("session.msg.edit","Edit request"),hint:e9("session.msg.editHint","Continue with an edited request in a new branch"),children:(0,t.jsx)("button",{type:"button",className:"ssEdit","data-edit-message":e.id,disabled:e0,"aria-label":e9("session.msg.edit","Edit request"),onClick:()=>aW(e.id),children:(0,t.jsx)($.Glyph,{name:"h_pencil"})})}),(0,t.jsx)("button",{type:"button",className:"ssEdit",title:e9("session.share.message","Share"),"aria-label":e9("session.share.message","Share"),onClick:t=>nN({id:e.id,mode:"share",trigger:t.currentTarget}),children:(0,t.jsx)($.Glyph,{name:"h_responseShare",strokeWidth:1.6})})]})]},e.id);let r=(0,en.stripPanelBlocks)(e.content),d=(e.actions??[]).find(e=>"sources"===e.kind),c=d&&"sources"===d.kind?d.items:null;return(0,t.jsxs)(i.Fragment,{children:[eR[e.id]&&nt(eR[e.id]),(0,t.jsx)("div",{className:"msg bot",children:(0,t.jsxs)("div",{className:"bub",children:[(0,t.jsx)(g.ChatMarkdown,{compact:!0,citations:c,children:r}),n,sw.filter(t=>(e.actions??[]).includes(t.action)&&!na(t.action,eR[e.id])).sort((e,t)=>
28Number("followups"===e.action.kind)-Number("followups"===t.action.kind)).map(ne),eF(e.actions,e.panelData)===ei.ARTIFACT_DATA_TAB&&(0,t.jsxs)("button",{type:"button",className:"msgPreviewBtn",onClick:()=>s6(ei.ARTIFACT_DATA_TAB),children:[(0,t.jsx)(o.PanelRightOpen,{size:13}),(0,t.jsx)("span",{children:e9("session.preview.output","Preview output")})]}),e.resumeJobId&&s&&!sa&&(0,t.jsx)(l.ResumeJobButton,{jobId:e.resumeJobId,onResumed:()=>te?eO(te):void 0}),e.retryContent&&s&&!sa&&(0,t.jsx)("button",{type:"button",className:"cfBtn",onClick:()=>ns(e.retryContent,e.retryAttachments??void 0,e.retryTurnId??void 0),children:e9("session.msg.tryAgain","Try again")}),!e.retryContent&&(0,t.jsxs)("div",{className:"ssJudge",children:[(0,t.jsx)(b.CopyButton,{text:r,copyLabel:e9("session.msg.copyResponse","Copy response"),icons:{copy:(0,t.jsx)($.Glyph,{name:"h_responseCopy"}),copied:(0,t.jsx)($.Glyph,{name:"h_responseCopy"})},onCopied:()=>u.toast.success(e9("session.msg.copied","Copied"))}),(0,t.jsx)(x.MessageFeedback,{messageId:e.id,surface:"session",image:e.actions?.some(e=>"artifact"===e.kind&&"image"===e.artifact_kind),rating:e.feedbackRating??null,onChange:t=>{te&&eE(te,e.id,t)}}),(0,t.jsx)("button",{type:"button",className:"ssRegen",title:e9("session.share.message","Share"),"aria-label":e9("session.share.message","Share"),onClick:t=>nN({id:e.id,mode:"share",trigger:t.currentTarget}),children:(0,t.jsx)($.Glyph,{name:"h_responseShare",strokeWidth:1.6})}),(0,t.jsxs)("span",{className:"ssMoreWrap",children:[(0,t.jsx)("button",{type:"button",className:"ssRegen ssMoreBtn","aria-haspopup":"menu","aria-expanded":nv?.id===e.id,title:e9("session.msg.more","More actions"),"aria-label":e9("session.msg.more","More actions"),onClick:t=>{let a=t.currentTarget,s=a.getBoundingClientRect();nj(t=>t?.id===e.id?null:{id:e.id,x:s.left,y:s.bottom+6,trigger:a})},children:(0,t.jsx)($.Glyph,{name:"h_responseMore",strokeWidth:1.6})}),nv?.id===e.id&&(0,t.jsx)(I.PoContextMenu,{className:"poResponseMenu",onClose:()=>nj(null),ctx:{x:nv.x,y:nv.y,head:e.timestamp?new Date(e.timestamp).toLocaleString(void 0,{month:"long",day:"numeric",hour:"numeric",minute:"2-digit"}):void 0,sections:[[{label:e9("messageDialog.sources","View sources"),icon:"h_responseBook",on:()=>nN({id:e.id,mode:"sources",trigger:nv.trigger})},{label:e9("session.msg.branch","Branch in new chat"),icon:"h_responseBranch",disabled:e0||sa||nT,on:()=>{nM(e.id)}},{label:nf===e.id?e9("session.msg.stopReading","Stop reading"):e9("session.msg.readAloud","Read aloud"),icon:nf===e.id?"h_stop":"h_responseSpeaker",on:()=>nx(e.id,r)}],[{label:e9("session.msg.regenerateLast","Regenerate last request"),icon:"h_refresh",disabled:e0||sa,on:nn},{label:e9("responseHistory.title","Previous generated answers"),icon:"h_clock",disabled:!te,on:()=>{te&&nS({threadId:te,trigger:nv.trigger})}}]]}})]})]})]})})]},e.id)}),sa&&(0,t.jsx)(i.Fragment,{children:nt(st,nB)},`${te}-${st.startedAt}`),sa&&(0,en.stripPanelBlocks)(ss).trim()&&(0,t.jsx)("div",{className:"msg bot isStreaming","aria-busy":"true",children:(0,t.jsx)("div",{className:"bub",children:(0,t.jsx)(g.ChatMarkdown,{compact:!0,children:(0,en.stripPanelBlocks)(ss)})})}),sa&&si.length>0&&(0,t.jsx)("div",{className:"msg bot",children:(0,t.jsx)("div",{className:"bub",children:sw.filter(e=>si.includes(e.action)&&!na(e.action,st)).sort((e,t)=>Number("followups"===e.action.kind)-Number("followups"===t.action.kind)).map(ne)})}),sc&&!sa&&(0,t.jsx)(tz,{eyebrow:e9("session.selection.dataRoomLoaded","DRIVE CONTEXT LOADED"),title:sc.targetName,meta:`${sc.kind.toUpperCase()} \xb7 ${sc.roomName}`,suggestions:lr.suggestions.length?lr.suggestions.map(e=>e.message):sc.suggestions,onPick:e=>ns(e),onClear:te?()=>a6(te):void 0}),su&&!sa&&(0,t.jsx)(tz,{eyebrow:e9("session.selection.localSelected","LOCAL CONTENT SELECTED"),title:su.title,meta:su.meta,suggestions:lo.suggestions.length?lo.suggestions.map(e=>e.message):sm,onPick:e=>ns(e),disabled:sx,onClear:a1})]}),!sb&&le&&(0,t.jsx)("button",{type:"button",className:`ssJump${sa?" isLive":""}`,onClick:ll,children:sa?e9("session.jumpAnswering","ANSWERING â"):e9("session.jumpLatest","LATEST â")})]}),(q=(0,t.jsx)(C.AuthGate,{children:(0,t.jsx)(F.ComposerDock,{menu:!0,onDeviceFiles:()=>az.current?.click(),onDataRoom:()=>aR(!0),onAddLink:()=>{ez({title:e9("session.webLink.title","Add web link"),desc:e9("session.webLink.desc","Add a web link or page to refer to."),confirmLabel:e9("session.webLink.add","Add"),input:{label:e9("session.webLink.field","Web address"),value:"",placeholder:"https://"},onConfirm:e=>{try{let t=new URL((e??"").trim());if(!["http:","https:"].includes(t.protocol))throw Error("scheme");td((ti?`${ti} 29`:"")+t.href),aU.current?.focus()}catch{return u.toast.error(e9("session.webLink.invalid","Enter an http or https web address.")),!1}}})},onConnectPlugins:e=>nw({trigger:e}),voiceInput:sa||e0?void 0:(0,t.jsx)(s.VoiceInput,{onText:e=>{let t=te??"";tn(a=>
29({...a,[t]:[a[t]?.trimEnd(),e].filter(Boolean).join(" ")})),requestAnimationFrame(()=>aU.current?.focus())}})},te??"new")}),J=!e0&&!tP&&!sx&&!e6&&(ti.trim().length>0||tw.length>0||tE.length>0),X=sa?(0,t.jsx)(ec.Tip,{label:e9("session.composer.stop","â STOP"),hint:e9("session.composer.stopHint","Partial answer is kept"),side:"top",children:(0,t.jsx)("button",{type:"button",className:"cdSend isStop",onClick:()=>{te&&(aF(!0),e$(te))},"aria-busy":aL,"aria-label":aL?e9("session.composer.stopping","STOPPING"):e9("session.composer.stopTitle","Stop generating (partial answer is kept)"),children:(0,t.jsx)(d.Square,{size:11,strokeWidth:0,fill:"currentColor"})})}):(0,t.jsx)(ec.Tip,{label:e9("session.composer.send","SEND"),hint:e9("session.composer.sendHint","Enter sends · Shift+Enter for a new line"),side:"top",children:(0,t.jsx)("button",{type:"button",className:"cdSend",onClick:()=>void ns(),disabled:!J,"aria-label":e9("session.composer.send","SEND"),children:(0,t.jsx)(r.ArrowUp,{size:16,strokeWidth:2.5})})}),Z=(0,t.jsx)("textarea",{ref:aU,rows:1,value:ti,onChange:e=>td(e.target.value),onKeyDown:e=>{(0,U.shouldSendComposerKey)(e.nativeEvent,eX.enterSend)&&(e.preventDefault(),ns())},onPaste:e=>{let t=Array.from(e.clipboardData?.files??[]);t.length>0&&(e.preventDefault(),a4(t))},placeholder:e3?"work"===ap?e9("session.composer.guestPlaceholderWork","Do everything"):e9("session.composer.guestPlaceholderChat","Ask anything"):e0?e9("session.viewOnly"):e6?e9(e4?.subscription.status==="pending"?"workspaceSettings:subscription.completePayment":"usage.blockedPlaceholder","You can use the agent again after your usage renews."):"work"===ap?e9("session.composer.placeholderApp","Describe the app you need"):e9("session.composer.placeholderChat","Ask anything"),"aria-label":e9("session.composer.messageAria","Message"),"aria-describedby":sx?"session-upload-status":void 0,disabled:e0||tP||e6}),(0,t.jsxs)(t.Fragment,{children:[(tw.length>0||tE.length>0)&&(0,t.jsxs)("div",{className:"cdFiles","aria-busy":sf>0||void 0,children:[tw.map((e,a)=>{let s=t2.get(e)??{status:"queued",progress:0};return(0,t.jsx)(p.AttachmentTile,{chip:!0,name:e.name,mime:e.type,size:e.size,file:e,uploadStatus:te?s.status:void 0,uploadProgress:s.progress,onRetry:"error"===s.status?()=>a3([e]):void 0,onRemove:()=>a2(e)},`${e.name}:${e.lastModified}:${e.size}:${a}`)}),tE.map((e,a)=>(0,t.jsx)(p.AttachmentTile,{chip:!0,name:e.filename,mime:e.mime_type,size:e.file_size,url:e.file_url,room:!0,onRemove:()=>tI(e=>e.filter((e,t)=>t!==a))},`room:${e.file_url}:${a}`))]}),tw.length>0&&(0,t.jsx)("span",{id:"session-upload-status",className:"sr-only",role:sg>0?"alert":"status","aria-live":"polite",children:sg>0?e9("session.uploadFailedFiles",{defaultValue:"{{count}} upload(s) need retry or removal",count:sg}):sf>0?e9("session.uploadProgress",{defaultValue:"UPLOADING · {{done}}/{{total}} READY",done:sp,total:tw.length}):e9("session.uploadReady",{defaultValue:"{{count}} FILE(S) READY",count:te?sp:tw.length})}),aA&&(0,t.jsx)(ev,{onClose:()=>aR(!1),onAttach:e=>tI(t=>[...t,...e].slice(0,25)),onUseContext:a9}),(0,t.jsx)(S.UsageBanner,{data:e4,onViewPlan:()=>e8(!0)}),(0,t.jsx)(_.PlanUsageDialog,{open:e7,onOpenChange:e8,data:e4}),(0,t.jsxs)("div",{className:`chatComposer cdGrow${e6?" usageBlocked":""}`,children:[(0,t.jsx)("input",{ref:az,type:"file",multiple:!0,hidden:!0,onChange:e=>{a4(Array.from(e.target.files??[])),e.target.value=""}}),(0,t.jsxs)("div",{className:"cdMain",children:[Z,X]}),(0,t.jsxs)("div",{className:"cdMeta",children:[(0,t.jsxs)("span",{className:"cdModeChips",role:"group","aria-label":e9("session.mode.label","Turn mode"),children:[(0,t.jsxs)("button",{type:"button",className:`cdChip${"chat"===ap?" on":""}`,"aria-pressed":"chat"===ap,onClick:()=>aZ("chat"),title:e9("session.mode.chat","CHAT"),children:[(0,t.jsx)($.Glyph,{name:"h_chat"}),(0,t.jsx)("span",{className:"sr",children:e9("session.mode.chat","CHAT")})]}),(0,t.jsxs)("button",{type:"button",className:`cdChip work${"work"===ap?" on":""}`,"aria-pressed":"work"===ap,onClick:()=>aZ("work"),title:e9("session.mode.work","WORK"),children:[(0,t.jsx)($.Glyph,{name:"h_cube"}),(0,t.jsx)("span",{className:"sr",children:e9("session.mode.work","WORK")})]})]}),(0,t.jsx)("span",{className:"cdMetaSep"}),q,(0,t.jsx)("span",{className:"cdMetaL"}),(0,t.jsxs)("span",{className:"cdMetaR",children:[af&&(0,t.jsxs)("button",{type:"button",className:"cdPlan","aria-pressed":"true",onClick:()=>aQ(!1),children:[(0,t.jsx)($.Glyph,{name:"h_list"}),e9("session.planMode","Plan mode")]}),(0,t.jsx)(C.AuthGate,{children:(0,t.jsx)(ea,{className:"cdMetaItem cdModel",layout:"tabbed",value:al,onPick:e=>{ai(e);try{localStorage.setItem(tU,e)}catch{}},secure:an,byo:aX,recentKey:`${tU}_recent`,effort:ad,onPickEffort:e=>{ac(e);try{localStorage.setItem(tK,e)}catch{}}})})]})]})]})]})),sb&&(0,t.jsx)("div",{className:`ssHeroExBox${"work"===ap?" on":""}`,"aria-hidden":"work"!==ap,children:(0,t.jsx)("div",{className:"ssHeroEx",children:t0.map(e=>{let a=e9(e.cat.key,e.cat.fallback);return(0,t.jsxs)("button",{type:"button",className:"ssHeroExRow",tabIndex:"work"===ap?void 0:-1,onClick:()=>ld(e9(e.prompt.key,e.prompt.fallback)),children:[(0,t.jsx)("svg",{className:"ehIco",viewBox:"0 0 16 16","aria-hidden":"true",children:(0,t.jsx)("path",{d:e.d})}),(0,t.jsx)("span",{className:"ehCmd",children:a}),(0,t.jsx)("span",{className:"ehTx",children:e9(e.desc.key,e.desc.fallback)}),(0,t.jsx)("span",{className:"ehGo","aria-hidden":"true",children:"â"})]},e.id)})})})]})]}),s3&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(A.WorkPanelDivider,{workspace:aH}),(0,t.jsx)(eG,{workPanel:aD,artifacts:sj,files:sy,sources:ey(se,tE,tw),onAttachSource:()=>az.current?.click(),activeId:aO??(sN.length>0&&0===sj.length?ei.ARTIFACT_DATA_TAB:null),onSelect:aI,turns:sk,generating:sS,onClose:s7,threadId:te,onSendMessage:e=>ns(e),onSeedComposer:ld,onRefreshed:()=>{te&&eN(te,{force:!0})},app:sU||sF||sI||sP?{id:"app",name:sF?.name??sI?.name??sU?.app_name??sP?.name??"",sub:sF?e9("session.preview.kindApp","App"):sI?e9("session.preview.kindBuilding","Building"):e9("session.preview.kindBlueprint","Blueprint"),render:e=>(0,t.jsx)(ts,{chrome:e,plan:sU,building:sI,stopped:sP,app:sF?{...sF,publishing:sM===sF.agentId}:null,isOwner:sF?.isOwner??!0,readiness:sY?{overall:sY.overall,failing:sY.checks.filter(e=>"ok"!==e.status).map(e=>e.id.replace(/_/g," "))}:null,onPublish:sJ&&!sQ?sX:void 0,onOpenWindow:sF?s2:void 0,onCancelBuild:sI||sF?s1:void 0,qualityAction:sQ,onQualityAction:s0,onRenamed:e=>sT(t=>t?{...t,name:e}:t),onRetired:()=>{sT(null),aI(null)},onInspect:e=>td(`Change the ${e}: `)})}:null})]})]}),tN&&(0,t.jsx)(ek,{source:tN,onClose:()=>tS(null),fallbackFocus:aU},tN.key)]})]})})}],576666)},621680,292792,e=>{"use strict";var t=e.i(843476),a=e.i(500932),s=e.i(702107),n=e.i(964053),l=e.i(295692),i=e.i(127923),r=e.i(271645),o=e.i(981140),d=e.i(30030),c=e.i(842727),u=e.i(248425),m="horizontal",h=["horizontal","vertical"],p=r.forwardRef((e,a)=>{var s;let{decorative:n,orientation:l=m,...i}=e,r=(s=l,h.includes(s))?l:m;return(0,t.jsx)(u.Primitive.div,{"data-orientation":r,...n?{role:"none"}
29:{"aria-orientation":"vertical"===r?r:void 0,role:"separator"},...i,ref:a})});p.displayName="Separator";var g=e.i(369340),f="Toggle",x=r.forwardRef((e,a)=>{let{pressed:s,defaultPressed:n,onPressedChange:l,...i}=e,[r,d]=(0,g.useControllableState)({prop:s,onChange:l,defaultProp:n??!1,caller:f});return(0,t.jsx)(u.Primitive.button,{type:"button","aria-pressed":r,"data-state":r?"on":"off","data-disabled":e.disabled?"":void 0,...i,ref:a,onClick:(0,o.composeEventHandlers)(e.onClick,()=>{e.disabled||d(!r)})})});x.displayName=f;var b=e.i(586318),v="ToggleGroup",[j,y]=(0,d.createContextScope)(v,[c.createRovingFocusGroupScope]),w=(0,c.createRovingFocusGroupScope)(),k=r.default.forwardRef((e,a)=>{let{type:s,...n}=e;if("single"===s)return(0,t.jsx)(S,{...n,ref:a});if("multiple"===s)return(0,t.jsx)(_,{...n,ref:a});throw Error(`Missing prop \`type\` expected on \`${v}\``)});k.displayName=v;var[N,C]=j(v),S=r.default.forwardRef((e,a)=>{let{value:s,defaultValue:n,onValueChange:l=()=>{},...i}=e,[o,d]=(0,g.useControllableState)({prop:s,defaultProp:n??"",onChange:l,caller:v});return(0,t.jsx)(N,{scope:e.__scopeToggleGroup,type:"single",value:r.default.useMemo(()=>o?[o]:[],[o]),onItemActivate:d,onItemDeactivate:r.default.useCallback(()=>d(""),[d]),children:(0,t.jsx)(A,{...i,ref:a})})}),_=r.default.forwardRef((e,a)=>{let{value:s,defaultValue:n,onValueChange:l=()=>{},...i}=e,[o,d]=(0,g.useControllableState)({prop:s,defaultProp:n??[],onChange:l,caller:v}),c=r.default.useCallback(e=>d((t=[])=>[...t,e]),[d]),u=r.default.useCallback(e=>d((t=[])=>t.filter(t=>t!==e)),[d]);return(0,t.jsx)(N,{scope:e.__scopeToggleGroup,type:"multiple",value:o,onItemActivate:c,onItemDeactivate:u,children:(0,t.jsx)(A,{...i,ref:a})})});k.displayName=v;var[T,E]=j(v),A=r.default.forwardRef((e,a)=>{let{__scopeToggleGroup:s,disabled:n=!1,rovingFocus:l=!0,orientation:i,dir:r,loop:o=!0,...d}=e,m=w(s),h=(0,b.useDirection)(r),p={role:"group",dir:h,...d};return(0,t.jsx)(T,{scope:s,rovingFocus:l,disabled:n,children:l?(0,t.jsx)(c.Root,{asChild:!0,...m,orientation:i,dir:h,loop:o,children:(0,t.jsx)(u.Primitive.div,{...p,ref:a})}):(0,t.jsx)(u.Primitive.div,{...p,ref:a})})}),R="ToggleGroupItem",D=r.default.forwardRef((e,a)=>{let s=C(R,e.__scopeToggleGroup),n=E(R,e.__scopeToggleGroup),l=w(e.__scopeToggleGroup),i=s.value.includes(e.value),o=n.disabled||e.disabled,d={...e,pressed:i,disabled:o},u=r.default.useRef(null);return n.rovingFocus?(0,t.jsx)(c.Item,{asChild:!0,...l,focusable:!o,active:i,ref:u,children:(0,t.jsx)(M,{...d,ref:a})}):(0,t.jsx)(M,{...d,ref:a})});D.displayName=R;var M=r.default.forwardRef((e,a)=>{let{__scopeToggleGroup:s,value:n,...l}=e,i=C(R,s),r={role:"radio","aria-checked":e.pressed,"aria-pressed":void 0},o="single"===i.type?r:void 0;
29return(0,t.jsx)(x,{...o,...l,ref:a,onPressedChange:e=>{e?i.onItemActivate(n):i.onItemDeactivate(n)}})}),I="Toolbar",[O,P]=(0,d.createContextScope)(I,[c.createRovingFocusGroupScope,y]),L=(0,c.createRovingFocusGroupScope)(),F=y(),[$,B]=O(I),H=r.forwardRef((e,a)=>{let{__scopeToolbar:s,orientation:n="horizontal",dir:l,loop:i=!0,...r}=e,o=L(s),d=(0,b.useDirection)(l);return(0,t.jsx)($,{scope:s,orientation:n,dir:d,children:(0,t.jsx)(c.Root,{asChild:!0,...o,orientation:n,dir:d,loop:i,children:(0,t.jsx)(u.Primitive.div,{role:"toolbar","aria-orientation":n,dir:d,...r,ref:a})})})});H.displayName=I;var z="ToolbarSeparator",U=r.forwardRef((e,a)=>{let{__scopeToolbar:s,...n}=e,l=B(z,s);return(0,t.jsx)(p,{orientation:"horizontal"===l.orientation?"vertical":"horizontal",...n,ref:a})});U.displayName=z;var G=r.forwardRef((e,a)=>{let{__scopeToolbar:s,...n}=e,l=L(s);return(0,t.jsx)(c.Item,{asChild:!0,...l,focusable:!e.disabled,children:(0,t.jsx)(u.Primitive.button,{type:"button",...n,ref:a})})});G.displayName="ToolbarButton";var W=r.forwardRef((e,a)=>{let{__scopeToolbar:s,...n}=e,l=L(s);return(0,t.jsx)(c.Item,{asChild:!0,...l,focusable:!0,children:(0,t.jsx)(u.Primitive.a,{...n,ref:a,onKeyDown:(0,o.composeEventHandlers)(e.onKeyDown,e=>{" "===e.key&&e.currentTarget.click()})})})});W.displayName="ToolbarLink";var K="ToolbarToggleGroup",V=r.forwardRef((e,a)=>{let{__scopeToolbar:s,...n}=e,l=B(K,s),i=F(s);return(0,t.jsx)(k,{"data-orientation":l.orientation,dir:l.dir,...i,...n,ref:a,rovingFocus:!1})});V.displayName=K;var Y=r.forwardRef((e,a)=>{let{__scopeToolbar:s,...n}=e,l=F(s),i={__scopeToolbar:e.__scopeToolbar};return(0,t.jsx)(G,{asChild:!0,...i,children:(0,t.jsx)(D,{...l,...n,ref:a})})});Y.displayName="ToolbarToggleItem",e.s(["Button",0,G,"Link",0,W,"Root",0,H,"Separator",0,U,"ToggleGroup",0,V,"ToggleItem",0,Y,"Toolbar",0,H,"ToolbarButton",0,G,"ToolbarLink",0,W,"ToolbarSeparator",0,U,"ToolbarToggleGroup",0,V,"ToolbarToggleItem",0,Y,"createToolbarScope",0,P],696279);var q=e.i(696279),q=q,J=e.i(455435),X=e.i(39891);e.i(785269);var Z=e.i(322831),Q=e.i(549127),ee=e.i(846696),et=e.i(244002),ea=e.i(729995);function es(e){let s,n,l,i,o,d,c,u=(0,a.c)(25),{name:m,mime:h,size:p,file:g,url:f,onRemove:x}=e,{t:b}=(0,Z.useTranslation)("paletteOs"),[v,j]=(0,r.useState)(!1),y=(0,r.useRef)(null),w=!!x,k=f??m,N=p??g?.size;u[0]!==g||u[1]!==h||u[2]!==m||u[3]!==w||u[4]!==k||u[5]!==N||u[6]!==f?(s={key:k,name:m,mime:h,size:N,file:g,url:f,pending:w},u[0]=g,u[1]=h,u[2]=m,u[3]=w,u[4]=k,u[5]=N,u[6]=f,u[7]=s):s=u[7];let C=s,S=h.startsWith("image/")?"h_image":"h_file";return u[8]!==S?(n=(0,t.jsx)(et.Glyph,{name:S}),u[8]=S,u[9]=n):n=u[9],u[10]===Symbol.for("react.memo_cache_sentinel")?(l=()=>j(!0),u[10]=l):l=u[10],u[11]!==m?(i=(0,t.jsx)("button",{ref:y,type:"button",className:"tlFileName",title:m,"aria-haspopup":"dialog",onClick:l,children:m}),u[11]=m,u[12]=i):i=u[12],u[13]!==m||u[14]!==x||u[15]!==b?(o=x&&(0,t.jsx)("button",{type:"button",className:"tlFileRemove","aria-label":b("talk.removeAttachment",{name:m}),onClick:x,children:(0,t.jsx)(et.Glyph,{name:"h_close"})}),u[13]=m,u[14]=x,u[15]=b,u[16]=o):o=u[16],u[17]!==v||u[18]!==C?(d=v&&(0,t.jsx)(ea.WorkSourceDialog,{source:C,fallbackFocus:y,onClose:()=>j(!1)}),u[17]=v,u[18]=C,u[19]=d):d=u[19],u[20]!==n||u[21]!==i||u[22]!==o||u[23]!==d?(c=(0,t.jsxs)("span",{className:"tlFileChip",children:[n,i,o,d]}),u[20]=n,u[21]=i,u[22]=o,u[23]=d,u[24]=c):c=u[24],c}var en=e.i(640393),el=e.i(416317),ei=e.i(47297),er=e.i(670378),eo=e.i(13080),ed=e.i(96213),ec=e.i(219760),eu=e.i(713967);let em=[{id:"kr-office",name:{en:"Korean office",ko:"íêµ ì¤í¼ì¤",ja:"éå½ãªãã£ã¹"},items:[{id:"hwaiting",label:"íì´í
!"},{id:"sugohasyeotseumnida",label:"ìê³ íì
¨ìµëë¤"},{id:"gamsahamnida",label:"ê°ì¬í©ëë¤"},{id:"joesonghamnida",label:"ì£ì¡í©ëë¤"},{id:"hwaginhaesseumnida",label:"íì¸íìµëë¤"},{id:"nep",label:"ëµ!"},{id:"injeong",label:"ã
ã
"},{id:"daebak",label:"ëë°"},{id:"good",label:"굿"},{id:"jinjja",label:"ì§ì§?"},{id:"yuyu",label:"ã
ã
"},{id:"kkk",label:"ã
ã
ã
"},{id:"heol",label:"í"},{id:"chukhahae",label:"ì¶íí´!"},{id:"saranghae",label:"ì¬ëí´"},{id:"toegeun",label:"í´ê·¼!"},{id:"yageun",label:"ì¼ê·¼..."},{id:"keopi",label:"ì»¤í¼ í ì"},{id:"chimaek",label:"ì¹ë§¥"},{id:"hoeuijung",label:"íìì¤"},{id:"baepo-wanryo",label:"ë°°í¬ ìë£"},{id:"geupham",label:"ê¸í¨!"},{id:"cheoncheonhi",label:"ì²ì²í"},{id:"jal-butak",label:"ì ë¶íëë ¤ì"},{id:"gosaenghasyeosseoyo",label:"ê³ ìíì
¨ì´ì"},{id:"okay",label:"ì¤ì¼ì´"},{id:"gutbam",label:"굿밤"},{id:"jeomsim",label:"ì ì¬ ë 먹ì§"},{id:"paitinghaeyo",label:"íì´í
í´ì"},{id:"choego",label:"ìµê³ "}]},{id:"universal",name:{en:"Universal",ko:"ì ëë²ì¤",ja:"ã¦ããã¼ãµã«"},items:[{id:"yes",label:"YES"},{id:"no",label:"NO"},{id:"lgtm",label:"LGTM"},{id:"shipped",label:"SHIPPED"},{id:"gg",label:"GG"},{id:"thinking",label:"THINKING"},{id:"plus-one",label:"+1"},{id:"wip",label:"WIP"},{id:"blocked",label:"BLOCKED"},{id:"merged",label:"MERGED"},{id:"rollback",label:"ROLLBACK"},{id:"ping",label:"PING"},{id:"eod",label:"EOD"},{id:"afk",label:"AFK"},{id:"typo",label:"TYPO"},{id:"nice",label:"NICE"},{id:"oops",label:"OOPS"},{id:"done",label:"DONE"}]}],eh=(e,t)=>`/themes/palette-os/stickers/${e}/${t}.svg`;em.flatMap(e=>e.items.map(t=>
29[`${e.id}/${t.id}`,t]));let ep={ping:[[880,0,.09,.09]],mention:[[988,0,.09,.12],[1319,.1,.18,.12]],ring:[[659,0,.13,.11],[880,.15,.13,.11],[1319,.3,.34,.13]],join:[[660,0,.07,.06],[990,.07,.11,.06]],leave:[[660,0,.07,.06],[440,.07,.13,.06]]},eg=null;function ef(){let e=ex();e&&"suspended"===e.state&&e.resume().catch(()=>{})}function ex(){if(eg)return eg;let e=window.AudioContext??window.webkitAudioContext;if(!e)return null;try{eg=new e}catch{return null}return eg}function eb(e){let t=ex();if(!t)return;"suspended"===t.state&&t.resume().catch(()=>{});let a=t.currentTime;for(let[s,n,l,i]of ep[e]){let e=t.createOscillator(),r=t.createGain();e.type="sine",e.frequency.value=s,r.gain.setValueAtTime(1e-4,a+n),r.gain.exponentialRampToValueAtTime(i,a+n+.012),r.gain.exponentialRampToValueAtTime(1e-4,a+n+l),e.connect(r).connect(t.destination),e.start(a+n),e.stop(a+n+l+.02)}}var ev=e.i(174080),ej=e.i(702748);function ey(e){let t,s,n,l,i,o,d=(0,a.c)(10),[c,u]=(0,r.useState)(ew);if(d[0]!==e?(t=()=>{if(!e)return;let t=window.setInterval(()=>u(Date.now()),1e3);return()=>window.clearInterval(t)},s=[e],d[0]=e,d[1]=t,d[2]=s):(t=d[1],s=d[2]),(0,r.useEffect)(t,s),!e||(d[3]!==e?(l=Number.isNaN(n=new Date(e).getTime()),d[3]=e,d[4]=n,d[5]=l):(n=d[4],l=d[5]),l))return"";let m=Math.max(0,Math.floor((c-n)/1e3)),h=String(Math.floor(m/60));d[6]!==h?(i=h.padStart(2,"0"),d[6]=h,d[7]=i):i=d[7];let p=String(m%60);return d[8]!==p?(o=p.padStart(2,"0"),d[8]=p,d[9]=o):o=d[9],`${i}:${o}`}function ew(){return Date.now()}function ek(e){let s,n,l,i,r,o=(0,a.c)(15),{people:d,speaking:c,max:u}=e,m=void 0===u?6:u;if(o[0]!==m||o[1]!==d||o[2]!==c){let e;s=d.slice(0,m),n="tlHudRoster",o[6]!==c?(e=e=>(0,t.jsx)("span",{className:`tlHudFace${c.includes(String(e.id))?" talking":""}`,title:e.name,children:e.name.split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?"},e.id),o[6]=c,o[7]=e):e=o[7],l=s.map(e),o[0]=m,o[1]=d,o[2]=c,o[3]=s,o[4]=n,o[5]=l}else s=o[3],n=o[4],l=o[5];return o[8]!==d.length||o[9]!==s.length?(i=d.length>s.length&&(0,t.jsxs)("span",{className:"tlHudFace tlHudFace--more",children:["+",d.length-s.length]}),o[8]=d.length,o[9]=s.length,o[10]=i):i=o[10],o[11]!==n||o[12]!==l||o[13]!==i?(r=(0,t.jsxs)("div",{className:n,children:[l,i]}),o[11]=n,o[12]=l,o[13]=i,o[14]=r):r=o[14],r}function eN(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f=(0,a.c)(48),{huddle:x,speaking:b,inHuddle:v,voiceOn:j,muted:y,onJoin:w,onLeave:k,onToggleMute:N}=e,{t:C}=(0,Z.useTranslation)("paletteOs"),S=ey(x.started_at);if(f[0]!==S||f[1]!==x.participants||f[2]!==v||f[3]!==b||f[4]!==C){let e,a=x.participants.map(eC).filter(Boolean);l=`tlHudBar${v?" in":""}`,i="region",f[14]!==C?(r=C("talk.huddleRegion","Huddle"),f[14]=C,f[15]=r):r=f[15],f[16]===Symbol.for("react.memo_cache_sentinel")?(o=(0,t.jsx)("span",{className:"tlHudLive","aria-hidden":!0}),f[16]=o):o=f[16],f[17]!==C?(e=C("talk.huddleWord","HUDDLE"),f[17]=C,f[18]=e):e=f[18],f[19]!==e?(d=(0,t.jsx)("span",{className:"tlHudReg",children:e}),f[19]=e,f[20]=d):d=f[20],f[21]!==S?(c=(0,t.jsx)("span",{className:"tlHudTime",children:S}),f[21]=S,f[22]=c):c=f[22],f[23]!==x.participants||f[24]!==b?(u=(0,t.jsx)(ek,{people:x.participants,speaking:b}),f[23]=x.participants,f[24]=b,f[25]=u):u=f[25],s="tlHudWho",n=1===a.length?C("talk.huddleOneWaiting","{{name}} is waiting",{name:a[0]}):C("talk.huddleCount","{{count}} on the call",{count:a.length}),f[0]=S,f[1]=x.participants,f[2]=v,f[3]=b,f[4]=C,f[5]=s,f[6]=n,f[7]=l,f[8]=i,f[9]=r,f[10]=o,f[11]=d,f[12]=c,f[13]=u}else s=f[5],n=f[6],l=f[7],i=f[8],r=f[9],o=f[10],d=f[11],c=f[12],u=f[13];return f[26]!==s||f[27]!==n?(m=(0,t.jsx)("span",{className:s,children:n}),f[26]=s,f[27]=n,f[28]=m):m=f[28],f[29]===Symbol.for("react.memo_cache_sentinel")?(h=(0,t.jsx)("span",{className:"tlHudGap"}),f[29]=h):h=f[29],f[30]!==v||f[31]!==y||f[32]!==w||f[33]!==k||f[34]!==N||f[35]!==C||f[36]!==j?(p=v?(0,t.jsxs)(t.Fragment,{children:[j?(0,t.jsxs)("button",{className:`tlHudBtn${y?" on":""}`,onClick:N,"aria-pressed":y,title:y?C("talk.unmute","Unmute"):C("talk.mute","Mute"),children:[(0,t.jsx)(ej.TlIcon,{n:y?"micOff":"mic",size:14}),y?C("talk.mutedChip","MUTED"):C("talk.liveChip","LIVE")]}):(0,t.jsxs)("span",{className:"tlHudBtn tlHudBtn--note",title:C("talk.huddleListenWhy","No microphone â you are in the room but not on the audio"),children:[(0,t.jsx)(ej.TlIcon,{n:"micOff",size:14}),C("talk.huddleListen","NO MIC")]}),(0,t.jsxs)("button",{className:"tlHudBtn tlHudBtn--end",onClick:k,children:[(0,t.jsx)(ej.TlIcon,{n:"hang",size:14}),C("talk.huddleLeave","LEAVE")]})]}):(0,t.jsxs)("button",{className:"tlHudBtn tlHudBtn--go",onClick:w,children:[(0,t.jsx)(ej.TlIcon,{n:"call",size:14}),C("talk.huddleJoin","JOIN")]}),f[30]=v,f[31]=y,f[32]=w,f[33]=k,f[34]=N,f[35]=C,f[36]=j,f[37]=p):p=f[37],f[38]!==m||f[39]!==p||f[40]!==l||f[41]!==i||f[42]!==r||f[43]!==o||f[44]!==d||f[45]!==c||f[46]!==u?(g=(0,t.jsxs)("div",{className:l,role:i,"aria-label":r,children:[o,d,c,u,m,h,p
29]}),f[38]=m,f[39]=p,f[40]=l,f[41]=i,f[42]=r,f[43]=o,f[44]=d,f[45]=c,f[46]=u,f[47]=g):g=f[47],g}function eC(e){return e.name}function eS({invite:e,inviteLabel:a,inviteRoster:s,onAnswer:n,onDismiss:l,mine:i,mineLabel:o,speaking:d,muted:c,voiceOn:u,onOpenRoom:m,onToggleMute:h,onLeave:p}){let{t:g}=(0,Z.useTranslation)("paletteOs"),f=ey(i?.started_at);if((0,r.useEffect)(()=>{if(!e)return;let t=window.setTimeout(l,45e3);return()=>window.clearTimeout(t)},[e,l]),(0,r.useEffect)(()=>{if(!e)return;let t=0,a=window.setInterval(()=>{++t>3?window.clearInterval(a):eb("ring")},3e3);return()=>window.clearInterval(a)},[e?.huddleId]),(0,r.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&l()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e,l]),"u"<typeof document||!e&&!i)return null;let x=document.documentElement.getAttribute("data-canvas")??void 0;return(0,ev.createPortal)((0,t.jsx)("div",{"data-theme":"palette-os","data-canvas":x,style:{display:"contents"},children:(0,t.jsxs)("div",{className:"tlHudDock",children:[i&&(0,t.jsxs)("section",{className:"tlHudCard tlHudCard--mine","aria-label":g("talk.huddleRegion","Huddle"),children:[(0,t.jsxs)("header",{className:"tlHudCardHead",children:[(0,t.jsx)("span",{className:"tlHudLive","aria-hidden":!0}),(0,t.jsx)("span",{className:"tlHudReg",children:g("talk.huddleOnCall","ON A CALL")}),(0,t.jsx)("span",{className:"tlHudTime",children:f})]}),(0,t.jsx)("button",{className:"tlHudRoom",onClick:()=>m(i.channel_id),title:g("talk.huddleBack","Back to the room"),children:o}),(0,t.jsx)(ek,{people:i.participants,speaking:d,max:5}),(0,t.jsxs)("div",{className:"tlHudCardFoot",children:[u&&(0,t.jsxs)("button",{className:`tlHudBtn${c?" on":""}`,onClick:h,"aria-pressed":c,children:[(0,t.jsx)(ej.TlIcon,{n:c?"micOff":"mic",size:14}),c?g("talk.mutedChip","MUTED"):g("talk.liveChip","LIVE")]}),(0,t.jsxs)("button",{className:"tlHudBtn tlHudBtn--end",onClick:p,children:[(0,t.jsx)(ej.TlIcon,{n:"hang",size:14}),g("talk.huddleLeave","LEAVE")]})]})]}),e&&(0,t.jsxs)("section",{className:"tlHudCard tlHudCard--ring",role:"alertdialog","aria-label":g("talk.huddleInviteTitle","Huddle starting"),children:[(0,t.jsxs)("span",{className:"tlHudPulse","aria-hidden":!0,children:[(0,t.jsx)("i",{}),(0,t.jsx)("i",{}),(0,t.jsx)("i",{})]}),(0,t.jsxs)("header",{className:"tlHudCardHead",children:[(0,t.jsx)("span",{className:"tlHudReg",children:g("talk.huddleInviteTitle","Huddle starting")}),(0,t.jsx)("button",{className:"tlHudDismiss",onClick:l,"aria-label":g("talk.huddleIgnore","Ignore"),children:(0,t.jsx)(ej.TlIcon,{n:"x",size:14})})]}),(0,t.jsx)("p",{className:"tlHudLead",children:e.actor?g("talk.huddleStartedBy","{{name}} started a huddle in",{name:e.actor}):g("talk.huddleStartedIn","A huddle started in")}),(0,t.jsx)("button",{className:"tlHudRoom",onClick:()=>m(e.channelId),children:a}),s.length>0&&(0,t.jsx)(ek,{people:s,speaking:d,max:5}),(0,t.jsxs)("div",{className:"tlHudCardFoot",children:[(0,t.jsxs)("button",{className:"tlHudBtn tlHudBtn--go",autoFocus:!0,onClick:n,children:[(0,t.jsx)(ej.TlIcon,{n:"call",size:14}),g("talk.huddleJoin","JOIN")]}),(0,t.jsx)("button",{className:"tlHudBtn",onClick:l,children:g("talk.huddleIgnore","Ignore")})]})]})]})}),document.body)}var e_=e.i(33289),eT=e.i(205366),eE=e.i(718720),eA=e.i(376185),eR=e.i(46280),eD=e.i(429036),eM=e.i(385328),eI=e.i(325574),eO=e.i(835548),eP=e.i(525209),eL=e.i(825857),eF=e.i(148103),e$=e.i(66447),eB=e.i(451203),eH=e.i(640616),ez=e.i(416014),eU=e.i(302903),eG=e.i(940274),eW=e.i(303984),eK=e.i(914057),eV=e.i(689962),eY=e.i(455489),eq=e.i(829045),eJ=e.i(631256),eX=e.i(599613),eZ=e.i(874795),eQ=e.i(710596);let e0={Globe:eA.Globe,Megaphone:eT.Megaphone,PencilLine:eR.PencilLine,Envelope:eE.Envelope,Target:eD.Target,Lightbulb:eM.Lightbulb,Palette:e_.Palette,ChartBar:eO.ChartBar,MagnifyingGlass:eP.MagnifyingGlass,Users:eL.Users,Binoculars:eF.Binoculars,Monitor:e$.Monitor,FilmStr
29ip:eB.FilmStrip,Stack:eH.Stack,PhoneCall:ez.PhoneCall,PresentationChart:eU.PresentationChart,Smiley:eG.Smiley,Handshake:eI.Handshake,TShirt:eW.TShirt,IdentificationCard:eK.IdentificationCard,Note:eV.Note,Article:eY.Article,SquaresFour:eq.SquaresFour,Tag:eJ.Tag,Image:eX.Image,Newspaper:eZ.Newspaper,Sparkle:eQ.Sparkle};function e1(e){let s,n,l,i=(0,a.c)(30),{actor:o,size:d,className:c}=e,u=void 0===d?24:d,m=c?`tlFace ${c}`:"tlFace";i[0]!==u?(s={width:u,height:u},i[0]=u,i[1]=s):s=i[1];let h=s,[p,g]=(0,r.useState)(null);if(!o.is_agent){let e,a,s,n,l;i[2]!==u?(e=Math.round(.38*u),i[2]=u,i[3]=e):e=i[3];let r=Math.max(8,e);i[4]!==r?(a={fontSize:r},i[4]=r,i[5]=a):a=i[5];let d=o.name??"";return i[6]!==d?(s=d.split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?",i[6]=d,i[7]=s):s=i[7],i[8]!==a||i[9]!==s?(n=(0,t.jsx)("span",{className:"tlFaceTxt",style:a,children:s}),i[8]=a,i[9]=s,i[10]=n):n=i[10],i[11]!==m||i[12]!==h||i[13]!==n?(l=(0,t.jsx)("span",{className:m,style:h,"aria-hidden":!0,children:n}),i[11]=m,i[12]=h,i[13]=n,i[14]=l):l=i[14],l}if(o.avatar&&o.avatar!==p){let e,a,s,n=`${m} tlFace--img tlFace--agent`;return i[15]!==o.avatar?(e=()=>g(o.avatar??null),i[15]=o.avatar,i[16]=e):e=i[16],i[17]!==o.avatar||i[18]!==e?(a=(0,t.jsx)("img",{src:o.avatar,alt:"",loading:"lazy",onError:e}),i[17]=o.avatar,i[18]=e,i[19]=a):a=i[19],i[20]!==h||i[21]!==n||i[22]!==a?(s=(0,t.jsx)("span",{className:n,style:h,"aria-hidden":!0,children:a}),i[20]=h,i[21]=n,i[22]=a,i[23]=s):s=i[23],s}let f=o.icon_name?e0[o.icon_name]:void 0,x=`${m} tlFace--agent`;return i[24]!==f?(n=f?(0,t.jsx)(f,{}):(0,t.jsx)(et.Glyph,{name:"h_bot"}),i[24]=f,i[25]=n):n=i[25],i[26]!==h||i[27]!==x||i[28]!==n?(l=(0,t.jsx)("span",{className:x,style:h,"aria-hidden":!0,children:n}),i[26]=h,i[27]=x,i[28]=n,i[29]=l):l=i[29],l}function e2({directory:e,meId:a,browse:s,onMessage:n,onOpenChannel:l,onJoinChannel:i,onPersonMenu:o}){let{t:d}=(0,Z.useTranslation)("paletteOs"),[c,u]=(0,r.useState)("people"),[m,h]=(0,r.useState)(""),[p,g]=(0,r.useState)(null),[f,x]=(0,r.useState)(null),b=(0,r.useCallback)(()=>{g(null),s("all").then(g).catch(()=>g([]))},[s]);(0,r.useEffect)(()=>{"channels"===c&&b()},[c,b]);let v=m.trim().toLowerCase(),j=(0,r.useMemo)(()=>[...e.people,...e.agents].filter(e=>!v||e.name.toLowerCase().includes(v)||(e.email??"").toLowerCase().includes(v)),[e,v]),y=(0,r.useMemo)(()=>(p??[]).filter(e=>!v||e.name.toLowerCase().includes(v)||e.description.toLowerCase().includes(v)),[p,v]),w={people:e.people.length,agents:e.agents.length};return(0,t.jsxs)("div",{className:"tlDirPane",children:[(0,t.jsx)("header",{className:"tlDirHead",children:(0,t.jsx)("h1",{className:"tlDirTitle",children:d("talk.directories","Directories")})}),(0,t.jsxs)("div",{className:"spvTabs tlDirTabs",role:"tablist",children:[(0,t.jsx)("button",{role:"tab","aria-selected":"people"===c,className:`spvTab${"people"===c?" on":""}`,onClick:()=>u("people"),children:d("talk.dirPeople","PEOPLE")}),(0,t.jsx)("button",{role:"tab","aria-selected":"channels"===c,className:`spvTab${"channels"===c?" on":""}`,onClick:()=>u("channels"),children:d("talk.dirChannels","CHANNELS")})]}),(0,t.jsxs)("div",{className:"tlDirFind poSearch",children:[(0,t.jsx)(ej.TlIcon,{n:"find",size:16}),(0,t.jsx)("input",{value:m,placeholder:"people"===c?d("talk.dirFindPeople","Search for people and agents"):d("talk.dirFindChannels","Search for channels"),"aria-label":"people"===c?d("talk.dirFindPeople","Search for people and agents"):d("talk.dirFindChannels","Search for channels"),onChange:e=>h(e.target.value)}),(0,t.jsx)("span",{className:"tlDirCount",children:"people"===c?d("talk.dirPeopleCount","{{people}} members · {{agents}} agents",w):null===p?"":d("talk.dirChannelCount","{{count}} channels",{count:y.length})})]}),"people"===c?(0,t.jsxs)("div",{className:"tlDirGrid",children:[j.map(e=>{let s=!e.is_agent&&String(e.id)===a;return(0,t.jsxs)("div",{className:"tlDirCard",onContextMenu:t=>{s||(t.preventDefault(),o(e,{x:t.clientX,y:t.clientY}))},children:[(0,t.jsx)(e1,{actor:e,size:44,className:"tlDirFace"}),(0,t.jsxs)("div",{className:"tlDirCardBody",children:[(0,t.jsxs)("span",{className:"tlDirName",children:[e.name,s&&(0,t.jsx)("em",{children:d("talk.dirYou","you")}),e.presence&&(0,t.jsx)("span",{className:"tlOn",title:d("talk.online","Online")})]}),(0,t.jsx)("span",{className:"tlDirSub",children:e.is_agent?d("talk.dirAgent","Agent"):e.email??d("talk.cardPerson","Member")})]}),!s&&(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:()=>n(e),children:d("talk.dirMessage","MESSAGE")})]},`${e.kind}:${e.id}`)}),0===j.length&&(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:d("talk.nobodyFound","Nobody by that name")}
29)})]}):null===p?(0,t.jsx)("div",{className:"tlDirGrid",children:Array.from({length:6},(e,a)=>(0,t.jsxs)("div",{className:"tlDirCard","aria-hidden":!0,children:[(0,t.jsx)("span",{className:"rlSkel tlDirFace"}),(0,t.jsxs)("div",{className:"tlDirCardBody",children:[(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:"60%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${40+11*a%40}%`}})]})]},a))}):(0,t.jsxs)("div",{className:"tlDirGrid",children:[y.map(e=>(0,t.jsxs)("div",{className:"tlDirCard",children:[(0,t.jsx)("div",{className:"tlDirFace tlDirFace--room",children:(0,t.jsx)(ej.TlIcon,{n:"private"===e.visibility?"lock":"hash",size:22})}),(0,t.jsxs)("div",{className:"tlDirCardBody",children:[(0,t.jsx)("span",{className:"tlDirName",children:e.name}),(0,t.jsxs)("span",{className:"tlDirSub",children:[d("talk.dirMembers","{{count}} members",{count:e.member_count}),e.description?` \xb7 ${e.description}`:""]})]}),e.joined?(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:()=>l(e.id),children:d("talk.dirOpen","OPEN")}):(0,t.jsx)("button",{className:"po-btn po-btn--sm",disabled:f===e.id,onClick:async()=>{x(e.id);try{await i(e.id),b()}finally{x(null)}},children:d("talk.dirJoin","JOIN")})]},e.id)),0===y.length&&(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:v?d("talk.noChannelsFound","No channel by that name"):d("talk.noChannels","No channels yet")})})]})]})}let e3=e=>`${e.kind}:${e.id}`;function e4(e){let s,n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D,M,I,O,P,L,F,$,B,H,z,U,G,W,K,V,Y=(0,a.c)(136),{people:q,channels:J,meId:X,liveIn:Q,onClose:ee,onStart:et}=e,{t:ea}=(0,Z.useTranslation)("paletteOs"),[es,en]=(0,r.useState)("people"),[el,ei]=(0,r.useState)("");Y[0]===Symbol.for("react.memo_cache_sentinel")?(s=[],Y[0]=s):s=Y[0];let[er,eo]=(0,r.useState)(s),[ed,ec]=(0,r.useState)(0);Y[1]!==er?(n=new Set(er.map(e3)),Y[1]=er,Y[2]=n):n=Y[2];let eu=n;Y[3]!==el?(l=el.trim().toLowerCase(),Y[3]=el,Y[4]=l):l=Y[4];let em=l;if(Y[5]!==eu||Y[6]!==X||Y[7]!==q||Y[8]!==em){let e,t;Y[10]!==X?(e=e=>String(e.id)!==X,Y[10]=X,Y[11]=e):e=Y[11],Y[12]!==eu||Y[13]!==em?(t=e=>!eu.has(e3(e))&&(!em||e.name.toLowerCase().includes(em)),Y[12]=eu,Y[13]=em,Y[14]=t):t=Y[14],i=q.filter(e).filter(t),Y[5]=eu,Y[6]=X,Y[7]=q,Y[8]=em,Y[9]=i}else i=Y[9];let eh=i;if(Y[15]!==J||Y[16]!==em){let e;Y[18]!==em?(e=e=>!em||e.name.toLowerCase().includes(em),Y[18]=em,Y[19]=e):e=Y[19],o=J.filter(e6).filter(e),Y[15]=J,Y[16]=em,Y[17]=o}else o=Y[17];let ep=o;Y[20]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{ec(0)},Y[20]=d):d=Y[20],Y[21]!==er.length||Y[22]!==em||Y[23]!==es?(c=[em,es,er.length],Y[21]=er.length,Y[22]=em,Y[23]=es,Y[24]=c):c=Y[24],(0,r.useEffect)(d,c),Y[25]===Symbol.for("react.memo_cache_sentinel")?(u=e=>{eo(t=>t.some(t=>e3(t)===e3(e))?t:[...t,e]),ei("")},Y[25]=u):u=Y[25];let eg=u;Y[26]!==et?(m=e=>et({channelId:e}),Y[26]=et,Y[27]=m):m=Y[27];let ef=m,ex="people"===es?eh:ep,eb=er.length>0;if(Y[28]!==ea?(h=ea("talk.hbNewHead","Start a huddle"),Y[28]=ea,Y[29]=h):h=Y[29],Y[30]!==ea?(p=ea("talk.hbNewHead","Start a huddle"),Y[30]=ea,Y[31]=p):p=Y[31],Y[32]!==p?(g=(0,t.jsx)("span",{className:"tlNewMsgTitle",children:p}),Y[32]=p,Y[33]=g):g=Y[33],Y[34]!==ea?(f=ea("talk.close","Close"),Y[34]=ea,Y[35]=f):f=Y[35],Y[36]===Symbol.for("react.memo_cache_sentinel")?(x=(0,t.jsx)(ej.TlIcon,{n:"x",size:18}),Y[36]=x):x=Y[36],Y[37]!==ee||Y[38]!==f?(b=(0,t.jsx)("button",{className:"tlIconBtn","aria-label":f,onClick:ee,children:x}),Y[37]=ee,Y[38]=f,Y[39]=b):b=Y[39],Y[40]!==g||Y[41]!==b?(v=(0,t.jsxs)("header",{className:"tlNewMsgHead",children:[g,b]}),Y[40]=g,Y[41]=b,Y[42]=v):v=Y[42],Y[43]!==ea?(j=ea("talk.hbNewLead","Find a person or channel to huddle with"),Y[43]=ea,Y[44]=j):j=Y[44],Y[45]!==j?(y=(0,t.jsx)("p",{className:"tlStartHudLead",children:j}),Y[45]=j,Y[46]=y):y=Y[46],Y[47]!==er||Y[48]!==ea){let e;Y[50]!==ea?(e=e=>(0,t.jsxs)("span",{className:"tlNewMsgChip",children:[(0,t.jsx)(e1,{actor:e,size:17,className:"tlNewMsgChipAv"}),(0,t.jsx)("span",{children:e.name}),(0,t.jsx)("button",{"aria-label":ea("talk.remove","Remove"),onClick:()=>eo(t=>t.filter(t=>e3(t)!==e3(e))),children:(0,t.jsx)(ej.TlIcon,{n:"x",size:14})})]}
29,e3(e)),Y[50]=ea,Y[51]=e):e=Y[51],w=er.map(e),Y[47]=er,Y[48]=ea,Y[49]=w}else w=Y[49];Y[52]!==ea?(k=ea("talk.hbSearchName","Search by name"),Y[52]=ea,Y[53]=k):k=Y[53],Y[54]!==ea?(N=ea("talk.hbSearchName","Search by name"),Y[54]=ea,Y[55]=N):N=Y[55],Y[56]===Symbol.for("react.memo_cache_sentinel")?(C=e=>ei(e.target.value),Y[56]=C):C=Y[56],Y[57]!==ed||Y[58]!==el||Y[59]!==ee||Y[60]!==er.length||Y[61]!==ex||Y[62]!==es||Y[63]!==ef?(S=e=>{"ArrowDown"===e.key&&ex.length?(e.preventDefault(),ec(e=>(e+1)%ex.length)):"ArrowUp"===e.key&&ex.length?(e.preventDefault(),ec(e=>(e-1+ex.length)%ex.length)):"Enter"===e.key&&ex[ed]?(e.preventDefault(),"people"===es?eg(ex[ed]):ef(ex[ed].id)):"Backspace"===e.key&&!el&&er.length?eo(e5):"Escape"===e.key&&ee()},Y[57]=ed,Y[58]=el,Y[59]=ee,Y[60]=er.length,Y[61]=ex,Y[62]=es,Y[63]=ef,Y[64]=S):S=Y[64],Y[65]!==el||Y[66]!==k||Y[67]!==N||Y[68]!==S?(_=(0,t.jsx)("input",{autoFocus:!0,value:el,placeholder:k,"aria-label":N,onChange:C,onKeyDown:S}),Y[65]=el,Y[66]=k,Y[67]=N,Y[68]=S,Y[69]=_):_=Y[69],Y[70]!==w||Y[71]!==_?(T=(0,t.jsxs)("div",{className:"tlNewMsgTo",children:[w,_]}),Y[70]=w,Y[71]=_,Y[72]=T):T=Y[72];let ev="people"===es,ey=`spvTab${"people"===es?" on":""}`;Y[73]===Symbol.for("react.memo_cache_sentinel")?(E=()=>en("people"),Y[73]=E):E=Y[73],Y[74]!==ea?(A=ea("talk.dirPeople","PEOPLE"),Y[74]=ea,Y[75]=A):A=Y[75],Y[76]!==ev||Y[77]!==ey||Y[78]!==A?(R=(0,t.jsx)("button",{role:"tab","aria-selected":ev,className:ey,onClick:E,children:A}),Y[76]=ev,Y[77]=ey,Y[78]=A,Y[79]=R):R=Y[79];let ew="channels"===es,ek=`spvTab${"channels"===es?" on":""}`;Y[80]===Symbol.for("react.memo_cache_sentinel")?(D=()=>en("channels"),Y[80]=D):D=Y[80],Y[81]!==ea?(M=ea("talk.dirChannels","CHANNELS"),Y[81]=ea,Y[82]=M):M=Y[82],Y[83]!==ew||Y[84]!==ek||Y[85]!==M?(I=(0,t.jsx)("button",{role:"tab","aria-selected":ew,className:ek,onClick:D,children:M}),Y[83]=ew,Y[84]=ek,Y[85]=M,Y[86]=I):I=Y[86],Y[87]!==R||Y[88]!==I?(O=(0,t.jsxs)("div",{className:"spvTabs",role:"tablist",children:[R,I]}),Y[87]=R,Y[88]=I,Y[89]=O):O=Y[89],Y[90]!==ed||Y[91]!==eh||Y[92]!==Q||Y[93]!==ep||Y[94]!==ea||Y[95]!==es||Y[96]!==ef?(P="people"===es?eh.map((e,a)=>(0,t.jsxs)("button",{role:"option","aria-selected":a===ed,className:`tlRoom${a===ed?" on":""}`,onMouseEnter:()=>ec(a),onClick:()=>eg(e),children:[(0,t.jsx)(e1,{actor:e,size:24}),(0,t.jsx)("span",{className:"tlRoomN",children:e.name}),e.is_agent&&(0,t.jsx)("span",{className:"tlBotMark",children:ea("talk.bot","BOT")}),e.presence&&(0,t.jsx)("span",{className:"tlOn",title:ea("talk.online","Online")})]},e3(e))):ep.map((e,a)=>{let s=!!Q[e.id];return(0,t.jsxs)("button",{role:"option","aria-selected":a===ed,className:`tlRoom${a===ed?" on":""}`,onMouseEnter:()=>ec(a),onClick:()=>ef(e.id),children:[(0,t.jsx)(ej.TlIcon,{n:"private"===e.visibility?"lock":"hash",size:16}),(0,t.jsx)("span",{className:"tlRoomN",children:e.name}),s&&(0,t.jsx)("span",{className:"tlHudLive",title:ea("talk.huddleHere","A huddle is live here")})]},e.id)}),Y[90]=ed,Y[91]=eh,Y[92]=Q,Y[93]=ep,Y[94]=ea,Y[95]=es,Y[96]=ef,Y[97]=P):P=Y[97],Y[98]!==em||Y[99]!==ex.length||Y[100]!==ea?(L=0===ex.length&&(0,t.jsx)("div",{className:"tlRoomEmpty",children:em?ea("talk.nobodyFound","Nobody by that name"):ea("talk.nobodyYet","You're the only one here â invite teammates or build an agent")}),Y[98]=em,Y[99]=ex.length,Y[100]=ea,Y[101]=L):L=Y[101],Y[102]!==P||Y[103]!==L?(F=(0,t.jsxs)("div",{className:"tlNewMsgList",role:"listbox",children:[P,L]}),Y[102]=P,Y[103]=L,Y[104]=F):F=Y[104],Y[105]!==er.length||Y[106]!==ea?($=er.length>1?ea("talk.hbWillCall","Calls {{count}} people in a new conversation",{count:er.length}):"",Y[105]=er.length,Y[106]=ea,Y[107]=$):$=Y[107],Y[108]!==$?(B=(0,t.jsx)("span",{className:"tlNewMsgNote",children:$}),Y[108]=$,Y[109]=B):B=Y[109],Y[110]!==ea?(H=ea("talk.cancel","CANCEL"),Y[110]=ea,Y[111]=H):H=Y[111],Y[112]!==ee||Y[113]!==H?(z=(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:ee,children:H}),Y[112]=ee,Y[113]=H,Y[114]=z):z=Y[114];let eN=!eb;return Y[115]!==et||Y[116]!==er?(U=()=>et({actors:er}),Y[115]=et,Y[116]=er,Y[117]=U):U=Y[117],Y[118]!==ea?(G=ea("talk.hbNewHead","Start a huddle"),Y[118]=ea,Y[119]=G):G=Y[119],Y[120]!==eN||Y[121]!==U||Y[122]!==G?(W=(0,t.jsx)("button",{className:"po-btn po-btn--sm",disabled:eN,onClick:U,children:G}),Y[120]=eN,Y[121]=U,Y[122]=G,Y[123]=W):W=Y[123],Y[124]!==B||Y[125]!==z||Y[126]!==W?(K=(0,t.jsxs)("footer",{className:"tlNewMsgFoot",children:[B,z,W]}),Y[124]=B,Y[125]=z,Y[126]=W,Y[127]=K):K=Y[127],Y[128]!==h||Y[129]!==v||Y[130]!==y||Y[131]!==T||Y[132]!==O||Y[133]!==F||Y[134]!==K?(V=(0,t.jsxs)("div",{className:"tlNewMsg tlStartHud",role:"dialog","aria-label":h,children:[v,y,T,O,F,K]}),Y[128]=h,Y[129]=v,Y[130]=y,Y[131]=T,Y[132]=O,Y[133]=F,Y[134]=K,Y[135]=V):V=Y[135],V}function e5(e){return e.slice(0,-1)}function e6(e){return"stream"===e.channel_type||"forum"===e.channel_type}function e7(e){let n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D,M,I,O,P,L,F=(0,a.c)(103),{load:$,channels:B,people:H,meId:z,speaking:U,liveIn:G,onOpenChannel:W,onStartIn:K,onStartWith:V}=e,{t:Y,i18n:q}=(0,Z.useTranslation)("paletteOs"),J=q.language,[X,Q]=(0,r.useState)(null),[ee,et]=(0,r.useState)("all"),[ea,es]=(0,r.useState)(null),[en,el]=(0,r.useState)(null),[ei,er]=(0,r.useState)(null),[eo,ed]=(0,r.useState)(!1);F[0]!==en||F[1]!==$||F[2]!==ee||F[3]!==ea?(n=()=>{let e=!0;return Q(null),$({scope:ee,withUserId:ea,channelId:en}).then(t=>{e&&Q(t)}).catch(()=>{e&&Q([])}),()=>{e=!1}},l=[$,ee,ea,en],F[0]=en,F[1]=$,F[2]=ee,F[3]=ea,F[4]=n,F[5]=l):(n=F[4],l=F[5]),(0,r.useEffect)(n,l),F[6]===Symbol.for("react.memo_cache_sentinel")?(i=(e,t,a)=>{let s=e.currentTarget.getBoundingClientRect();er({x:s.left,y:s.bottom+4,head:t,sections:[a]})},F[6]=i):i=F[6];let ec=i;F[7]!==ee||F[8]!==Y?(o="missed"===ee?Y("talk.hbScopeMissed","Missed"):"mine"===ee?Y("talk.hbScopeMine","My huddles"):Y("talk.hbAll","All huddles"),F[7]=ee,F[8]=Y,F[9]=o):o=F[9];let em=o;F[10]!==H||F[11]!==Y||F[12]!==ea?(d=H.find(e=>String(e.id)===ea)?.name??Y("talk.hbWith","With"),F[10]=H,F[11]=Y,F[12]=ea,F[13]=d):d=F[13];let eh=d;F[14]!==B||F[15]!==en||F[16]!==Y?(c=B.find(e=>e.id===en)?.name?`#${B.find(e=>e.id===en).name}`:Y("talk.hbIn","In"),F[14]=B,F[15]=en,F[16]=Y,F[17]=c):c=F[17];let ep=c;F[18]!==G||F[19]!==W||F[20]!==K||F[21]!==Y?(u=(e,t)=>{t.preventDefault();let a=t.currentTarget.getBoundingClientRect();er({x:Math.max(8,a.right-240),y:a.bottom+4,head:(e.channel_name||Y
29("talk.directMessage","Direct message")).toUpperCase(),sections:[[{label:Y("talk.hbOpenRoom","Open the conversation"),on:()=>W(e.channel_id)},{label:e.live?Y("talk.hbJoinLive","Join this huddle"):Y("talk.startHuddle","Start a huddle"),disabled:!e.live&&!!G[e.channel_id],on:()=>K(e.channel_id)}],[{label:Y("talk.hbFilterRoom","Only this conversation"),on:()=>el(e.channel_id)}]]})},F[18]=G,F[19]=W,F[20]=K,F[21]=Y,F[22]=u):u=F[22];let eg=u;F[23]!==X?(m=X??[],F[23]=X,F[24]=m):m=F[24];let ef=m;F[25]!==Y?(h=Y("talk.huddles","Huddles"),F[25]=Y,F[26]=h):h=F[26],F[27]!==h?(p=(0,t.jsx)("h1",{className:"tlHbTitle",children:h}),F[27]=h,F[28]=p):p=F[28],F[29]===Symbol.for("react.memo_cache_sentinel")?(g=(0,t.jsx)("span",{className:"tlHbGap"}),F[29]=g):g=F[29],F[30]===Symbol.for("react.memo_cache_sentinel")?(f=()=>ed(!0),x=(0,t.jsx)(ej.TlIcon,{n:"plus",size:14}),F[30]=f,F[31]=x):(f=F[30],x=F[31]),F[32]!==Y?(b=Y("talk.hbNew","New huddle"),F[32]=Y,F[33]=b):b=F[33],F[34]!==b?(v=(0,t.jsxs)("button",{className:"po-btn po-btn--sm","aria-haspopup":"dialog",onClick:f,children:[x,b]}),F[34]=b,F[35]=v):v=F[35],F[36]!==p||F[37]!==v?(j=(0,t.jsxs)("header",{className:"tlHbHead",children:[p,g,v]}),F[36]=p,F[37]=v,F[38]=j):j=F[38],F[39]!==Y?(y=Y("talk.hbRecent","Recent huddles"),F[39]=Y,F[40]=y):y=F[40],F[41]!==y?(w=(0,t.jsx)("div",{className:"tlHbSub",children:y}),F[41]=y,F[42]=w):w=F[42],F[43]!==ee||F[44]!==Y?(k=e=>ec(e,Y("talk.hbAll","All huddles").toUpperCase(),[{label:Y("talk.hbAll","All huddles"),checked:"all"===ee,on:()=>et("all")},{label:Y("talk.hbScopeMine","My huddles"),checked:"mine"===ee,on:()=>et("mine")},{label:Y("talk.hbScopeMissed","Missed"),checked:"missed"===ee,on:()=>et("missed")}]),F[43]=ee,F[44]=Y,F[45]=k):k=F[45],F[46]===Symbol.for("react.memo_cache_sentinel")?(N=(0,t.jsx)(ej.TlIcon,{n:"chev",size:14,cls:"tlFold"}),F[46]=N):N=F[46],F[47]!==em||F[48]!==k?(C=(0,t.jsxs)("button",{className:"tlHbChip","aria-haspopup":"menu",onClick:k,children:[em,N]}),F[47]=em,F[48]=k,F[49]=C):C=F[49];let ex=`tlHbChip${ea?" on":""}`;F[50]!==H||F[51]!==Y||F[52]!==ea?(S=e=>ec(e,Y("talk.hbWith","With").toUpperCase(),[{label:Y("talk.hbAnyone","Anyone"),checked:!ea,on:()=>es(null)},...H.map(e=>({id:`w:${e.id}`,label:e.name,checked:ea===String(e.id),on:()=>es(String(e.id))}))]),F[50]=H,F[51]=Y,F[52]=ea,F[53]=S):S=F[53],F[54]===Symbol.for("react.memo_cache_sentinel")?(_=(0,t.jsx)(ej.TlIcon,{n:"chev",size:14,cls:"tlFold"}),F[54]=_):_=F[54],F[55]!==ex||F[56]!==S||F[57]!==eh?(T=(0,t.jsxs)("button",{className:ex,"aria-haspopup":"menu",onClick:S,children:[eh,_]}),F[55]=ex,F[56]=S,F[57]=eh,F[58]=T):T=F[58];let eb=`tlHbChip${en?" on":""}`;return F[59]!==B||F[60]!==en||F[61]!==Y?(E=e=>ec(e,Y("talk.hbIn","In").toUpperCase(),[{label:Y("talk.hbAnywhere","Anywhere"),checked:!en,on:()=>el(null)},...B.map(e=>({id:`i:${e.id}`,label:e.name?`#${e.name}`:Y("talk.directMessage","Direct message"),checked:en===e.id,on:()=>el(e.id)}))]),F[59]=B,F[60]=en,F[61]=Y,F[62]=E):E=F[62],F[63]===Symbol.for("react.memo_cache_sentinel")?(A=(0,t.jsx)(ej.TlIcon,{n:"chev",size:14,cls:"tlFold"}),F[63]=A):A=F[63],F[64]!==ep||F[65]!==eb||F[66]!==E?(R=(0,t.jsxs)("button",{className:eb,"aria-haspopup":"menu",onClick:E,children:[ep,A]}),F[64]=ep,F[65]=eb,F[66]=E,F[67]=R):R=F[67],F[68]!==C||F[69]!==T||F[70]!==R?(D=(0,t.jsxs)("div",{className:"tlHbFilters",children:[C,T,R]}),F[68]=C,F[69]=T,F[70]=R,F[71]=D):D=F[71],F[72]!==en||F[73]!==J||F[74]!==ef||F[75]!==W||F[76]!==eg||F[77]!==X||F[78]!==ee||F[79]!==U||F[80]!==Y||F[81]!==ea?(M=null===X?Array.from({length:5},e8):0===ef.length?(0,t.jsxs)("div",{className:"tlAsideEmpty",children:[(0,t.jsx)("span",{className:"rlEmptyLead",children:"all"!==ee||ea||en?Y("talk.hbEmptyFiltered","No huddles match those filters."):Y("talk.hbEmpty","No huddles yet. Start one and it shows up here.")}),(0,t.jsx)("button",{className:"po-btn po-btn--sm",onClick:()=>ed(!0),children:Y("talk.hbNew","New huddle")})]}):(0,t.jsx)("div",{className:"tlHbCard",children:ef.map(e=>(0,t.jsx)(te,{row:e,lang:J,speaking:e.live?U:e9,onOpen:()=>W(e.channel_id),onMenu:t=>eg(e,t)},e.id))}),F[72]=en,F[73]=J,F[74]=ef,F[75]=W,F[76]=eg,F[77]=X,F[78]=ee,F[79]=U,F[80]=Y,F[81]=ea,F[82]=M):M=F[82],F[83]!==M?(I=(0,t.jsx)("div",{className:"tlHbList",children:M}),F[83]=M,F[84]=I):I=F[84],F[85]!==B||F[86]!==G||F[87]!==z||F[88]!==K||F[89]!==V||F[90]!==H||F[91]!==eo||F[92]!==Y?(O=eo&&(0,t.jsxs)(s.OverlayPortal,{children:[(0,t.jsx)("button",{className:"tlBrowseScrim","aria-label":Y("talk.close","Close"),onClick:()=>ed(!1)}),(0,t.jsx)(e4,{people:H,channels:B,meId:z,liveIn:G,onClose:()=>ed(!1),onStart:e=>{ed(!1),"channelId"in e?K(e.channelId):V(e.actors)}})]}),F[85]=B,F[86]=G,F[87]=z,F[88]=K,F[89]=V,F[90]=H,F[91]=eo,F[92]=Y,F[93]=O):O=F[93],F[94]!==ei?(P=ei&&(0,t.jsx)(eu.PoContextMenu,{ctx:ei,onClose:()=>er(null)}),F[94]=ei,F[95]=P):P=F[95],F[96]!==j||F[97]!==w||F[98]!==D||F[99]!==I||F[100]!==O||F[101]!==P?(L=(0,t.jsxs)("div",{className:"tlHbPane",children:[j,w,D,I,O,P]}),F[96]=j,F[97]=w,F[98]=D,F[99]=I,F[100]=O,F[101]=P,F[102]=L):L=F[102],L}function e8(e,a){return(0,t.jsxs)("div",{className:"tlHbRowSkel","aria-hidden":!0,
29children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:"34%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${46+13*a%30}%`}})]})]},a)}let e9=[];function te(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b=(0,a.c)(46),{row:v,lang:j,speaking:y,onOpen:w,onMenu:k}=e,{t:N}=(0,Z.useTranslation)("paletteOs"),C="dm"===v.channel_type||"group_dm"===v.channel_type;b[0]!==C||b[1]!==v.channel_name||b[2]!==v.started_by?.name||b[3]!==N?(s=C?v.channel_name||v.started_by?.name||N("talk.directMessage","Direct message"):`#${v.channel_name}`,b[0]=C,b[1]=v.channel_name,b[2]=v.started_by?.name,b[3]=N,b[4]=s):s=b[4];let S=s;b[5]!==j||b[6]!==v.duration_seconds?(n=(0,Q.durationLabel)(v.duration_seconds,j),b[5]=j,b[6]=v.duration_seconds,b[7]=n):n=b[7];let _=n,T=`tlHbRow${v.live?" live":""}`;b[8]===Symbol.for("react.memo_cache_sentinel")?(l=(0,t.jsx)(ej.TlIcon,{n:"headphones",size:18}),b[8]=l):l=b[8],b[9]!==w?(i=(0,t.jsx)("button",{className:"tlHbTile",onClick:w,tabIndex:-1,"aria-hidden":!0,children:l}),b[9]=w,b[10]=i):i=b[10],b[11]!==S?(r=(0,t.jsx)("span",{className:"tlHbName",children:S}),b[11]=S,b[12]=r):r=b[12];let E=`tlHbMeta${v.missed?" missed":""}`;return b[13]!==j||b[14]!==v.started_at?(o=(0,Q.agoLabel)(v.started_at,j),b[13]=j,b[14]=v.started_at,b[15]=o):o=b[15],b[16]===Symbol.for("react.memo_cache_sentinel")?(d=(0,t.jsx)("i",{"aria-hidden":!0,children:"·"}),b[16]=d):d=b[16],b[17]!==v.live||b[18]!==v.missed||b[19]!==_||b[20]!==N?(c=v.missed?N("talk.hbMissed","Missed huddle invitation"):v.live?N("talk.hbLive","Happening now"):_??N("talk.hbUnderMinute","Less than a minute"),b[17]=v.live,b[18]=v.missed,b[19]=_,b[20]=N,b[21]=c):c=b[21],b[22]!==c||b[23]!==E||b[24]!==o?(u=(0,t.jsxs)("span",{className:E,children:[o,d,c]}),b[22]=c,b[23]=E,b[24]=o,b[25]=u):u=b[25],b[26]!==w||b[27]!==u||b[28]!==r?(m=(0,t.jsxs)("button",{className:"tlHbBody",onClick:w,children:[r,u]}),b[26]=w,b[27]=u,b[28]=r,b[29]=m):m=b[29],b[30]!==v.participants||b[31]!==y?(h=v.participants.length>0&&(0,t.jsx)(ek,{people:v.participants,speaking:y,max:5}),b[30]=v.participants,b[31]=y,b[32]=h):h=b[32],b[33]!==N?(p=N("talk.hbRowMenu","Huddle options"),b[33]=N,b[34]=p):p=b[34],b[35]===Symbol.for("react.memo_cache_sentinel")?(g=(0,t.jsx)(ej.TlIcon,{n:"more",size:16}),b[35]=g):g=b[35],b[36]!==k||b[37]!==p?(f=(0,t.jsx)("button",{className:"tlHbMore","aria-haspopup":"menu","aria-label":p,onClick:k,children:g}),b[36]=k,b[37]=p,b[38]=f):f=b[38],b[39]!==k||b[40]!==m||b[41]!==h||b[42]!==f||b[43]!==T||b[44]!==i?(x=(0,t.jsxs)("div",{className:T,onContextMenu:k,children:[i,m,h,f]}),b[39]=k,b[40]=m,b[41]=h,b[42]=f,b[43]=T,b[44]=i,b[45]=x):x=b[45],x}let tt=e=>`${e.kind??"agent"}:${e.id}`;function ta({channel:e,label:a,tab:s,setTab:n,participants:l,directory:i,meId:o,draft:d,setDraft:c,emojiSection:u,onClose:m,onSave:h,onAdd:p,onRemove:g,onRole:f,onMode:x,onDm:b,onMenu:v,onExport:j,onArchive:y}){let{t:w}=(0,Z.useTranslation)("paletteOs"),[k,N]=(0,r.useState)(""),[C,S]=(0,r.useState)("everyone"),[_,T]=(0,r.useState)(!1),[E,A]=(0,r.useState)(null),[R,D]=(0,r.useState)(!1),[M,I]=(0,r.useState)(null),O=k.trim().toLowerCase(),P=(0,r.useMemo)(()=>new Set(l.map(e=>tt(e))),[l]),L=(0,r.useMemo)(()=>l.filter(e=>"everyone"===C||"agents"===C===e.is_agent).filter(e=>!O||e.name.toLowerCase().includes(O)),[l,C,O]),F=(0,r.useMemo)(()=>[...i.people,...i.agents].filter(e=>!P.has(tt(e))).filter(e=>!O||e.name.toLowerCase().includes(O)),[i,P,O]),$="stream"===e.channel_type||"forum"===e.channel_type,B=l.find(e=>!e.is_agent&&String(e.id)===o)?.role,H="owner"===B||"admin"===B;return(0,t.jsxs)("div",{className:"tlNewMsg tlChanDet",role:"dialog","aria-label":a,children:[(0,t.jsxs)("header",{className:"tlNewMsgHead",children:[(0,t.jsxs)("span",{className:"tlNewMsgTitle tlChanDetTitle",children:[$&&(0,t.jsx)(ej.TlIcon,{n:"private"===e.visibility?"lock":"hash",size:16}),(0,t.jsx)("span",{children:a})]}),(0,t.jsx)("button",{className:"tlIconBtn","aria-label":w("talk.close","Close"),onClick:m,children:(0,t.jsx)(ej.TlIcon,{n:"x",size:18})})]}),(0,t.jsxs)("div",{className:"spvTabs",role:"tablist",children:[(0,t.jsx)("button",{role:"tab","aria-selected":"about"===s,className:`spvTab${"about"===s?" on":""}`,onClick:()=>n("about"),children:w("talk.cdAbout","ABOUT")}),(0,t.jsxs)("button",{role:"tab","aria-selected":"members"===s,className:`spvTab${"members"===s?" on":""}`,onClick:()=>n("members"),children:[w("talk.members","MEMBERS"),(0,t.jsx)("em",{className:"tlChanDetTally",children:l.length})]})]}),"members"===s?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"tlChanDetFind",children:[(0,t.jsxs)("div",{className:"tlDirFind poSearch",children:[(0,t.jsx)(ej.TlIcon,{n:"find",size:16}),(0,t.jsx)("input",{value:k,placeholder:w("talk.cdFindMembers","Find members"),"aria-label":w("talk.cdFindMembers","Find members"),onChange:e=>N(e.target.value)})]}),(0,t.jsxs)("select",{className:"rlSelect",value:C,"aria-label":w("talk.cdFilter","Filter members"),onChange:e=>S(e.target.value),children:[(0,t.jsx)("option",{value:"everyone",children:w("talk.cdEvery
29one","Everyone")}),(0,t.jsx)("option",{value:"people",children:w("talk.cdPeopleOnly","People")}),(0,t.jsx)("option",{value:"agents",children:w("talk.cdAgentsOnly","Agents")})]})]}),(0,t.jsxs)("div",{className:"tlNewMsgList tlChanDetList",children:[H&&(0,t.jsxs)("button",{className:"tlChanDetAdd","aria-expanded":_,onClick:()=>T(e=>!e),children:[(0,t.jsx)("span",{className:"tlChanDetAddMark",children:(0,t.jsx)(ej.TlIcon,{n:"plus",size:16})}),(0,t.jsx)("span",{className:"tlRoomN",children:w("talk.cdAddPeople","Add people or agents")}),(0,t.jsx)(ej.TlIcon,{n:"chev",size:14,cls:"tlFold"})]}),H&&_&&(F.length>0?F.map(e=>(0,t.jsxs)("button",{className:"tlAddRow",onClick:()=>p(e),onContextMenu:t=>{t.preventDefault(),v(e,{x:t.clientX,y:t.clientY})},children:[(0,t.jsx)(e1,{actor:e,size:24}),(0,t.jsx)("span",{className:"tlRoomN",children:e.name}),e.is_agent&&(0,t.jsx)("span",{className:"tlBotMark",children:w("talk.bot","BOT")}),(0,t.jsx)(ej.TlIcon,{n:"plus",size:14})]},tt(e))):(0,t.jsx)("div",{className:"tlRoomEmpty",children:w("talk.cdEveryoneIn","Everyone in the workspace is already here")})),L.map(e=>{let a=String(e.id)===o&&!e.is_agent;return(0,t.jsxs)("div",{className:"tlMember",onContextMenu:t=>{t.preventDefault(),v(e,{x:t.clientX,y:t.clientY})},children:[(0,t.jsx)(e1,{actor:e,size:32}),(0,t.jsxs)("div",{className:"tlMemberBody",children:[(0,t.jsxs)("div",{className:"tlMemberTop",children:[a?(0,t.jsx)("span",{className:"tlMemberN",children:e.name}):(0,t.jsx)("button",{className:"tlMemberN tlMemberN--link",title:w("talk.messageDirectly","Message directly"),onClick:()=>b(e),children:e.name}),a&&(0,t.jsx)("em",{className:"tlChanDetYou",children:w("talk.dirYou","you")}),e.is_agent?(0,t.jsx)("span",{className:"tlBotMark",children:w("talk.bot","BOT")}):e.presence&&(0,t.jsx)("span",{className:"tlOn",title:w("talk.online","Online")}),(0,t.jsx)("span",{className:"tlChanDetGap"}),!e.is_agent&&(H&&!a?(0,t.jsxs)("select",{className:"rlSelect tlChanDetRole",value:e.role,"aria-label":w("talk.cdRole","Channel role"),onChange:t=>f(e.participant_id,t.target.value,e.name),children:[(0,t.jsx)("option",{value:"owner",children:w("talk.cdRoleOwner","Owner")}),(0,t.jsx)("option",{value:"admin",children:w("talk.cdRoleAdmin","Admin")}),(0,t.jsx)("option",{value:"member",children:w("talk.cdRoleMember","Member")}),(0,t.jsx)("option",{value:"guest",children:w("talk.cdRoleGuest","Guest")})]}):"member"!==e.role&&(0,t.jsx)("span",{className:"tlMemberRole",children:e.role.toUpperCase()})),e.is_agent&&H&&(0,t.jsx)("button",{className:"tlIconBtn tlChanDetCog","aria-expanded":M===e.participant_id,title:w("talk.cdConfigure","Agent settings"),"aria-label":w("talk.cdConfigure","Agent settings"),onClick:()=>I(t=>t===e.participant_id?null:e.participant_id),children:(0,t.jsx)(ej.TlIcon,{n:"chev",size:14,cls:"tlFold"})}),H&&!a&&(0,t.jsx)("button",{className:"tlIconBtn tlChanDetKick",title:w("talk.cdRemove","Remove from channel"),"aria-label":w("talk.cdRemove","Remove from channel"),onClick:()=>g(e.participant_id,e.name),children:(0,t.jsx)(ej.TlIcon,{n:"x",size:14})})]}),e.is_agent&&M===e.participant_id&&(0,t.jsxs)("div",{className:"tlAgentCfg",children:[(0,t.jsxs)("select",{className:"rlSelect",value:e.respond_to??"anyone","aria-label":w("talk.respondsTo","Responds to"),onChange:t=>x(e.participant_id,{respond_to:t.target.value}),children:[(0,t.jsx)("option",{value:"anyone",children:w("talk.respondAnyone","Anyone may instruct")}),(0,t.jsx)("option",{value:"owner_only",children:w("talk.respondOwner","Channel owner only")}),(0,t.jsx)("option",{value:"allowlist",children:w("talk.respondList","Allowlist only")})]}),(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{className:"rlCheck",type:"checkbox",checked:e.always_on,onChange:t=>x(e.participant_id,{always_on:t.target.checked})}),w("talk.alwaysOn","Reads every message")]}),(0,t.jsx)("textarea",{className:"tlBrief",rows:2,defaultValue:e.instructions??"",placeholder:w("talk.briefPlaceholder","What should it do in this channel?"),onBlur:t=>{let a=t.target.value.trim();a!==(e.instructions??"")&&x(e.participant_id,{instructions:a})}})]})]})]},e.participant_id)}),0===L.length&&(O||l.length>0?(0,t.jsx)("div",{className:"tlRoomEmpty",children:w("talk.nobodyFound","Nobody by that name")}
29):Array.from({length:4},(e,a)=>(0,t.jsxs)("div",{className:"tlMember tlMemberSkel","aria-hidden":!0,children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsx)("div",{className:"tlMemberBody",children:(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${44+13*a%26}%`}})})]},a))),!H&&(0,t.jsx)("p",{className:"tlChanDetNote",children:w("talk.cdReadOnly","Only a channel owner or admin can add or remove members.")})]})]}):(0,t.jsxs)("div",{className:"tlNewMsgBody",children:[(0,t.jsxs)("label",{className:"tlField",children:[(0,t.jsx)("span",{children:w("talk.topic","TOPIC")}),(0,t.jsx)("input",{value:d.topic,placeholder:w("talk.topicHint","What is this channel about right now?"),onChange:e=>c({...d,topic:e.target.value})})]}),(0,t.jsxs)("label",{className:"tlField",children:[(0,t.jsx)("span",{children:w("talk.description","DESCRIPTION")}),(0,t.jsx)("input",{value:d.description,placeholder:w("talk.descHint","What it is for, in one line"),onChange:e=>c({...d,description:e.target.value})})]}),(0,t.jsxs)("div",{className:"tlSheetRow",children:[(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:()=>j("md"),children:w("talk.exportMd","EXPORT .MD")}),(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:()=>j("json"),children:w("talk.exportJson","EXPORT .JSON")}),(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:y,children:e.archived?w("talk.unarchive","UNARCHIVE"):w("talk.archive","ARCHIVE")})]}),u]}),(0,t.jsxs)("footer",{className:"tlNewMsgFoot",children:[(0,t.jsx)("span",{className:"tlNewMsgNote"}),(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:m,children:"about"===s?w("talk.cancel","CANCEL"):w("talk.cdDone","DONE")}),"about"===s&&(0,t.jsx)("button",{className:"po-btn po-btn--sm","aria-busy":R,disabled:R,onClick:async()=>{D(!0);try{await h()}finally{D(!1)}},children:w("talk.save","SAVE")})]})]})}let ts=["thread","runs","rules","search"],tn=ts.filter(e=>"thread"!==e),tl=["huddles","directory","drafts","threads","activity"],ti=["all","joined","archived"],tr=/^\/talk(?:\/([^/?#]+))?\/?$/,to={channelId:null,thread:null,pane:null,query:"",scopeHere:!1,board:null,details:null,detailsTab:"about",browse:null},td=(e,t)=>t&&e.includes(t)?t:null;function tc(e){let t=e.indexOf("?"),a=-1===t?e:e.slice(0,t),s=-1===t?"":e.slice(t+1),n=a.match(tr);if(!n)return null;let l=new URLSearchParams(s),i=l.get("thread")||null,r=l.get("details")||null;return{channelId:n[1]?(e=>{try{return decodeURIComponent(e)}catch{return e}})(n[1]):null,thread:i,pane:i?null:td(tn,l.get("pane")),query:l.get("q")??"",scopeHere:"here"===l.get("scope"),board:td(tl,l.get("board")),details:r,detailsTab:r&&"members"===l.get("tab")?"members":"about",browse:td(ti,l.get("browse"))}}let tu=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");function tm(e){return tu(e).replace(/`([^`]+)`/g,"<code>$1</code>").replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>").replace(/~~([^~]+)~~/g,"<s>$1</s>").replace(/(^|[\s(])_([^_]+)_/g,"$1<em>$2</em>").replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,'<a href="$2">$1</a>')}function th(e,t){let a=/^(\s*)([\s\S]*?)(\s*)$/.exec(e);return a&&a[2]?`${a[1]}${t}${a[2]}${t}${a[3]}`:e}function tp(e){if(e.nodeType===Node.TEXT_NODE)return e.nodeValue??"";if(e.nodeType!==Node.ELEMENT_NODE)return"";let t=[...e.childNodes].map(tp).join("");switch(e.tagName){case"BR":return"\n";case"B":case"STRONG":return th(t,"**");case"I":case"EM":return th(t,"_");case"S":case"STRIKE":case"DEL":return th(t,"~~");case"CODE":return th(t,"`");case"A":{let a=e.getAttribute("href")??"";return a&&a!==t?`[${t}](${a})`:t}default:return t}}let tg=(0,r.forwardRef)(function(e,s){let n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j=(0,a.c)(38),{value:y,onChange:w,onMention:k,placeholder:N,ariaLabel:C,onSubmit:S,onFiles:_,onKeyDown:T}=e,E=(0,r.useRef)(null),A=(0,r.useRef)(""),R=(0,r.useRef)(!1),D=(0,r.useRef)(null);j[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>{let e=()=>{let e=window.getSelection(),t=E.current;e&&e.rangeCount&&t&&t.contains(e.anchorNode)&&(D.current=e.getRangeAt(0).cloneRange())};return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},l=[],j[0]=n,j[1]=l):(n=j[0],l=j[1]),(0,r.useEffect)(n,l),j[2]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{let e,t=E.current;if(!t)return;let a=window.getSelection();if(a?.anchorNode&&t.contains(a.anchorNode))return void t.focus();t.focus();let s=D.current??((e=document.createRange()).selectNodeContents(t),e.collapse(!1),e);a?.removeAllRanges(),a?.addRange(s)},j[2]=i):i=j[2];let M=i;j[3]!==y?(o=()=>{let e=E.current;e&&y!==A.current&&(A.current=y,e.innerHTML=function(e){if(!e)return"";let t=[],a=null,s=null,n=()=>{a&&(t.push(`</${a}>`),a=null)};for(let l of e.split("\n")){if(s){"```"===l.trim()?(t.push(`<pre>${tu(s.join("\n"))}</pre>`),s=null):s.push(l);continue}if("```"===l.trim()){n(),s=[];continue}let e=/^(\d+)\.\s(.*)$/.exec(l),i=/^[-*]\s(.*)$/.exec(l),r=/^>\s?(.*)$/.exec(l);e?("ol"!==a&&(n(),t.push("<ol>"),a="ol"),t.push(`<li>${tm(e[2])}</li>`)):i?("ul"!==a&&(n(),t.push("<ul>
29"),a="ul"),t.push(`<li>${tm(i[1])}</li>`)):r?(n(),t.push(`<blockquote>${tm(r[1])||"<br>"}</blockquote>`)):(n(),t.push(`<div>${tm(l)||"<br>"}</div>`))}return s&&t.push(`<pre>${tu(s.join("\n"))}</pre>`),n(),t.join("")}(y))},d=[y],j[3]=y,j[4]=o,j[5]=d):(o=j[4],d=j[5]),(0,r.useEffect)(o,d),j[6]!==w||j[7]!==k?(c=()=>{let e=E.current;if(!e)return;R.current||e.textContent?.trim()||(e.innerHTML="");let t=function(e){let t=[],a=e=>{switch(e.tagName){case"UL":for(let a of e.children)t.push(`- ${tp(a)}`);return;case"OL":{let a=1;for(let s of e.children)t.push(`${a++}. ${tp(s)}`);return}case"BLOCKQUOTE":for(let a of tp(e).split("\n"))t.push(`> ${a}`);return;case"PRE":t.push("```",...(e.textContent??"").split("\n"),"```");return;default:t.push(tp(e))}};for(let s of e.childNodes)if(s.nodeType===Node.TEXT_NODE){let e=s.nodeValue??"";e&&t.push(e)}else s.nodeType===Node.ELEMENT_NODE&&a(s);return t.join("\n").replace(/\n+$/,"")}(e);A.current=t,w(t);let a=function(e){let t=window.getSelection();if(!t||!t.isCollapsed||!t.anchorNode||!e.contains(t.anchorNode))return null;let a=t.anchorNode;return a.nodeType!==Node.TEXT_NODE?"":(a.nodeValue??"").slice(0,t.anchorOffset)}(e),s=null===a?null:/(?:^|\s)@([^\s@]{0,40})$/.exec(a);k(s?s[1]:null)},j[6]=w,j[7]=k,j[8]=c):c=j[8];let I=c;j[9]!==I?(u=(e,t)=>{M(),document.execCommand(e,!1,t),I()},j[9]=I,j[10]=u):u=j[10];let O=u;j[11]!==O||j[12]!==I?(m=e=>{switch(e){case"bold":return O("bold");case"italic":return O("italic");case"strike":return O("strikeThrough");case"listOl":return O("insertOrderedList");case"listUl":return O("insertUnorderedList");case"quote":return O("formatBlock","blockquote");case"codeBlock":return O("formatBlock","pre");case"code":{M();let e=window.getSelection();if(!e||0===e.rangeCount)return;let t=e.getRangeAt(0);if(t.collapsed)return;let a=document.createElement("code");a.appendChild(t.extractContents()),t.insertNode(a),e.removeAllRanges();let s=document.createRange();return s.selectNodeContents(a),e.addRange(s),I()}case"link":{M();let e=window.getSelection(),t=e?.toString()??"",a=window.prompt("https://","https://");if(!a)return;t?O("createLink",a):O("insertHTML",`<a href="${tu(a)}">${tu(a)}</a>`);return}}},j[11]=O,j[12]=I,j[13]=m):m=j[13];let P=m;return j[14]!==O||j[15]!==P||j[16]!==k||j[17]!==I?(p=()=>({insert:e=>O("insertText",e),focus:()=>E.current?.focus(),format:P,replaceMention:e=>{if(!E.current)return;let t=window.getSelection(),a=t?.anchorNode;if(!t||!a||a.nodeType!==Node.TEXT_NODE)return;let s=(a.nodeValue??"").slice(0,t.anchorOffset).lastIndexOf("@");if(s<0)return;let n=document.createRange();n.setStart(a,s),n.setEnd(a,t.anchorOffset),t.removeAllRanges(),t.addRange(n),document.execCommand("insertText",!1,`@${e} `),k(null),I()}}),h=[O,P,k,I],j[14]=O,j[15]=P,j[16]=k,j[17]=I,j[18]=h,j[19]=p):(h=j[18],p=j[19]),(0,r.useImperativeHandle)(s,p,h),j[20]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{R.current=!0},j[20]=g):g=j[20],j[21]!==I?(f=()=>{R.current=!1,I()},j[21]=I,j[22]=f):f=j[22],j[23]!==_||j[24]!==I?(x=e=>{if(e.clipboardData?.files?.length){e.preventDefault(),_(e.clipboardData.files);return}e.preventDefault(),document.execCommand("insertText",!1,e.clipboardData.getData("text/plain")),I()},j[23]=_,j[24]=I,j[25]=x):x=j[25],j[26]!==P||j[27]!==T||j[28]!==k||j[29]!==S?(b=e=>{if(T?.(e))return;let t=e.metaKey||e.ctrlKey;if(t&&!e.altKey){let t=e.key.toLowerCase(),a=e.shiftKey?{x:"strike",c:"code",7:"listOl",8:"listUl",9:"quote"}:{b:"bold",i:"italic",k:"link"};if(a[t]){e.preventDefault(),P(a[t]);return}}if(t&&e.altKey&&e.shiftKey&&"c"===e.key.toLowerCase()){e.preventDefault(),P("codeBlock");return}if("Escape"===e.key)return void k(null);if("Enter"===e.key&&!e.shiftKey&&!R.current){if(function(e){let t=window.getSelection()?.anchorNode;if(!e||!t||!e.contains(t))return!1;let a=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement,s=a?.closest("li, pre, blockquote");return!!s&&!!e.contains(s)&&!!s.textContent?.trim()}(E.current))return;e.preventDefault(),S()}},j[26]=P,j[27]=T,j[28]=k,j[29]=S,j[30]=b):b=j[30],j[31]!==C||j[32]!==N||j[33]!==I||j[34]!==f||j[35]!==x||j[36]!==b?(v=(0,t.jsx)("div",{ref:E,className:"tlEditor",contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox","aria-multiline":"true","aria-label":C,"data-placeholder":N,onInput:I,onCompositionStart:g,onCompositionEnd:f,onPaste:x,onKeyDown:b}
29),j[31]=C,j[32]=N,j[33]=I,j[34]=f,j[35]=x,j[36]=b,j[37]=v):v=j[37],v});var tf=e.i(452726);let tx="palette_talk_recent_emoji_v1",tb="palette_talk_skin_tone_v1";function tv(){try{let e=JSON.parse(localStorage.getItem(tx)||"[]");return Array.isArray(e)?e.filter(e=>"string"==typeof e).slice(0,24):[]}catch{return[]}}function tj(e){try{let t=[e,...tv().filter(t=>t!==e)].slice(0,24);localStorage.setItem(tx,JSON.stringify(t))}catch{}}let ty=["","ð»","ð¼","ð½","ð¾","ð¿"],tw=["#ffd93d","#f7dbc0","#e8c39e","#c68863","#8d5524","#4a312c"],tk=[{value:"ã
ã
ã
",hint:"laughing"},{value:"ã
ã
",hint:"hehe"},{value:"ã
ã
",hint:"crying"},{value:"ã
ã
",hint:"crying"},{value:"ã·ã·",hint:"shivering / wow"},{value:"ã
ã
",hint:"agreed"},{value:"ã±ã
",hint:"thanks"},{value:"ã
ã±",hint:"good work"},{value:"ã
ã
",hint:"hi"},{value:"ã
ã
",hint:"bye"},{value:"ã
ã
",hint:"sorry"},{value:"ã±ã±",hint:"let's go"},{value:"ã
ã
",hint:"okay"},{value:"ã´ã´",hint:"no no"},{value:"ã
ã
",hint:"congrats"},{value:"ã
ã
",hint:"unreal"},{value:"^^",hint:"smile"},{value:"ã
¡ã
¡",hint:"unimpressed"},{value:"ã
ã
ã
",hint:"blank stare"},{value:"(à¸'Ì-'Ì)à¸",hint:"fight!"},{value:"(à¹â¢Ìã
â¢Ì)Ùâ§",hint:"determined"},{value:"¯\\_(ã)_/¯",hint:"shrug"},{value:"(ã¥ï½¡ââ¿â¿â。)ã¥",hint:"hug"},{value:"(ã
_ã
)",hint:"staring"}],tN=[0,1,3,4,5,6,7,8,9],tC={0:["emojiGroup.smileys","Smileys"],1:["emojiGroup.people","People"],3:["emojiGroup.nature","Nature"],4:["emojiGroup.food","Food"],5:["emojiGroup.travel","Travel"],6:["emojiGroup.activities","Activity"],7:["emojiGroup.objects","Objects"],8:["emojiGroup.symbols","Symbols"],9:["emojiGroup.flags","Flags"]};function tS({anchor:a,onPick:s,onClose:n,customEmoji:l,allowSend:i=!0}){let o,{t:d,i18n:c}=(0,Z.useTranslation)("paletteOs"),u=(0,r.useRef)(null),[m]=(0,r.useState)(()=>document.activeElement),[h,p]=(0,r.useState)(null),[g,f]=(0,r.useState)(!1),[x,b]=(0,r.useState)("recent"),[v,j]=(0,r.useState)(""),[y,w]=(0,r.useState)(0),[k,N]=(0,r.useState)([]),[C,S]=(0,r.useState)({left:-9999,top:-9999});(0,r.useLayoutEffect)(()=>{let e=u.current;return()=>{m?.isConnected&&(document.activeElement===document.body||e?.contains(document.activeElement))&&m.focus()}},[m]),(0,r.useEffect)(()=>{let e;N(tv()),w(Number.isInteger(e=Number("u"<typeof localStorage?0:localStorage.getItem(tb)))&&e>=0&&e<ty.length?e:0)},[]),(0,r.useEffect)(()=>{let t=!0,a=(c.language||"en").toLowerCase().slice(0,2);return("ko"===a?e.A(300324):"ja"===a?e.A(986048):e.A(439791)).then(e=>{t&&p(e.default??e)}).catch(()=>{t&&f(!0)}),()=>{t=!1}},[c.language]),(0,r.useLayoutEffect)(()=>{let{rect:e,place:t}=a,s="above"===t?Math.max(8,e.top-372-8):Math.min(e.bottom+8,window.innerHeight-372-8);S({left:Math.max(8,Math.min(e.left,window.innerWidth-340-8)),top:Math.max(8,s)})},[a]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),n())},t=e=>{u.current?.contains(e.target)||n()};return document.addEventListener("keydown",e,!0),document.addEventListener("mousedown",t),()=>{document.removeEventListener("keydown",e,!0),document.removeEventListener("mousedown",t)}},[n]);let _=(0,r.useCallback)(e=>{let t=ty[y];if(!t||!e.skins?.length)return e.unicode;let a=e.skins.find(e=>e.unicode.includes(t));return a?.unicode??e.unicode},[y]),T=(0,r.useMemo)(()=>{let e=new Map;for(let t of h??[]){if("number"!=typeof t.group||2===t.group)continue;let a=e.get(t.group);a?a.push(t):e.set(t.group,[t])}for(let t of e.values())t.sort((e,t)=>(e.order??0)-(t.order??0));return e},[h]),E=v.trim().toLowerCase(),A=(0,r.useMemo)(()=>{if(!E||!h)return[];let e=[];for(let t of h)if("number"==typeof t.group&&2!==t.group&&(t.unicode===E||t.label.toLowerCase().includes(E)||t.tags?.some(e=>e.toLowerCase().includes(E)))&&(e.push(t),e.length>=240))break;return e},[E,h]),R=(0,r.useMemo)(()=>em.map(e=>({...e,items:E?e.items.filter(e=>e.label.toLowerCase().includes(E)||e.id.includes(E)):e.items})).filter(e=>e.items.length>0),[E]),D=(0,r.useMemo)(()=>E?l.filter(e=>e.code.includes(E)||e.label.toLowerCase().includes(E)):l,[E,l]),M=e=>{"emoji"===e.type&&(tj(e.value),N(tv())),s(e)},I=e=>{let a=_(e);return(0,t.jsx)("button",{className:"tlEmojiCell",title:e.label,"aria-label":e.label,onClick:()=>M({type:"emoji",value:a}),children:a},e.hexcode)},O=(0,t.jsxs)("div",{className:"tlEmojiStickers",children:[R.map(e=>(0,t.jsxs)("section",{children:[(0,t.jsx)("h4",{className:"tlEmojiRule",children:e.name[(0,tf.normalizeLanguage)(c.language)]}),(0,t.jsx)("div",{className:"tlEmojiStickerGrid",children:e.items.map(a=>(0,t.jsx)("button",{className:"tlStickerCell",title:a.label,onClick:()=>M({type:"sticker",pack:e.id,id:a.id,label:a.label}),children:(0,t.jsx)("img",{src:eh(e.id,a.id),alt:a.label})},a.id))})]},e.id)),D.filter(e=>"sticker"===e.kind).length>0&&(0,t.jsxs)("section",{children:[(0,t.jsx)("h4",{className:"tlEmojiRule",children:d("talk.emojiCustom","Your workspace")}),(0,t.jsx)("div",{className:"tlEmojiStickerGrid",children:D.filter(e=>"sticker"===e.kind).map(e=>(0,t.jsx)("button",{className:"tlStickerCell",title:e.label,onClick:()=>M({type:"sticker",pack:"custom",id:e.code,label:e.label}
29),children:(0,t.jsx)("img",{src:e.file_url,alt:e.label})},e.id))})]})]}),P=[{id:"recent",label:d("talk.emojiRecent","RECENT")},...i?[{id:"kr",label:"íê¸"}]:[],...tN.map(e=>({id:`g${e}`,label:d(`talk.${tC[e][0]}`,tC[e][1])})),...i?[{id:"stickers",label:d("talk.emojiStickers","STICKERS")}]:[],{id:"custom",label:d("talk.emojiOrg","ORG")}];if(g)o=(0,t.jsx)("p",{className:"tlEmojiNote",children:d("talk.emojiFailed","Emoji could not be loaded.")});else if(E)o=0===A.length&&0===R.length&&0===D.length?(0,t.jsx)("p",{className:"tlEmojiNote",children:d("talk.emojiNone","Nothing matches that.")}):(0,t.jsxs)(t.Fragment,{children:[A.length>0&&(0,t.jsx)("div",{className:"tlEmojiGrid",children:A.map(I)}),i&&R.length>0&&O,D.filter(e=>"emoji"===e.kind).length>0&&(0,t.jsx)("div",{className:"tlEmojiGrid",children:D.filter(e=>"emoji"===e.kind).map(e=>(0,t.jsx)("button",{className:"tlEmojiCell",title:`:${e.code}:`,onClick:()=>M({type:"custom",code:e.code,label:e.label}),children:(0,t.jsx)("img",{src:e.file_url,alt:e.label})},e.id))})]});else if("recent"===x)o=0===k.length?(0,t.jsx)("p",{className:"tlEmojiNote",children:d("talk.emojiNoRecent","Emoji you use will collect here.")}):(0,t.jsx)("div",{className:"tlEmojiGrid",children:k.map(e=>(0,t.jsx)("button",{className:"tlEmojiCell",onClick:()=>M({type:"emoji",value:e}),children:e},e))});else if("kr"===x)o=(0,t.jsx)("div",{className:"tlEmojiKr",children:tk.map(e=>(0,t.jsx)("button",{className:"tlKrCell",title:e.hint,onClick:()=>M({type:"text",value:e.value}),children:e.value},e.value))});else if("stickers"===x)o=O;else if("custom"===x){let e=l.filter(e=>"emoji"===e.kind);o=0===l.length?(0,t.jsx)("p",{className:"tlEmojiNote",children:d("talk.emojiNoCustom","No custom emoji yet. An admin can add them in channel settings.")}):(0,t.jsxs)(t.Fragment,{children:[e.length>0&&(0,t.jsx)("div",{className:"tlEmojiGrid",children:e.map(e=>(0,t.jsx)("button",{className:"tlEmojiCell",title:`:${e.code}:`,onClick:()=>M({type:"custom",code:e.code,label:e.label}),children:(0,t.jsx)("img",{src:e.file_url,alt:e.label})},e.id))}),i&&l.some(e=>"sticker"===e.kind)&&O]})}else{let e=Number(x.slice(1)),a=T.get(e);o=h?(0,t.jsx)("div",{className:"tlEmojiGrid",children:(a??[]).map(I)}):(0,t.jsx)("p",{className:"tlEmojiNote",children:d("talk.emojiLoading","Loadingâ¦")})}let L=document.documentElement.getAttribute("data-canvas")??void 0;return(0,ev.createPortal)((0,t.jsx)("div",{"data-theme":"palette-os","data-canvas":L,style:{display:"contents"},children:(0,t.jsxs)("div",{ref:u,className:"tlEmojiPanel",style:{left:C.left,top:C.top},role:"dialog","aria-label":d("talk.emojiPicker","Emoji and stickers"),children:[(0,t.jsxs)("div",{className:"tlEmojiHead",children:[(0,t.jsxs)("label",{className:"tlEmojiSearch poSearch",children:[(0,t.jsx)(ej.TlIcon,{n:"find",size:16}),(0,t.jsx)("input",{autoFocus:!0,value:v,placeholder:d("talk.emojiSearch","Search emoji"),"aria-label":d("talk.emojiSearch","Search emoji"),onChange:e=>j(e.target.value)})]}),(0,t.jsx)("button",{className:"tlEmojiClose","aria-label":d("talk.close","Close"),onClick:n,children:(0,t.jsx)(ej.TlIcon,{n:"x",size:16})}),(0,t.jsx)("div",{className:"tlEmojiTones",role:"group","aria-label":d("talk.emojiTone","Skin tone"),children:tw.map((e,a)=>(0,t.jsx)("button",{className:`tlEmojiTone${y===a?" on":""}`,style:{background:e},"aria-pressed":y===a,"aria-label":`${d("talk.emojiTone","Skin tone")} ${a}`,onClick:()=>{w(a);try{localStorage.setItem(tb,String(a))}catch{}}},e))})]}),(0,t.jsx)("div",{className:"tlEmojiTabs",role:"tablist",children:P.map(e=>(0,t.jsx)("button",{role:"tab","aria-selected":!E&&x===e.id,className:`tlEmojiTab${!E&&x===e.id?" on":""}`,onClick:()=>{j(""),b(e.id)},children:e.label},e.id))}),(0,t.jsx)("div",{className:"tlEmojiBody",children:o})]})}),document.body)}var t_=e.i(168948),tT=e.i(602725),tE=e.i(402389),tA=e.i(209165),tR=e.i(843756);let tD="/api/v1/talk",tM=`${tA.BASE}${tD}`;function tI(e,t){let{starred:a,muted:s,section:n,unread:l}=e,i=void 0!==t.last_message?t.last_message:e.last_message;return{...e,...t,starred:a,muted:s,section:n,unread:l,last_message:i}}function tO(e,t){let a=new Map(e.map(e=>[e.id,e]));for(let e of t)a.set(e.id,e);return[...a.values()].sort((e,t)=>
29e.created_at.localeCompare(t.created_at))}function tP(e,t){return e.map(e=>e.id===t?{...e,content:"",deleted_at:e.deleted_at??new Date().toISOString(),reactions:[],attachments:[],panel_data:null}:e)}async function tL(e,t){return(await (0,tA.apiFetch)(`${tD}${e}`,t)).json()}let tF="image/png,image/jpeg,image/gif,image/webp,image/avif,image/bmp,application/pdf,text/plain,text/csv,text/markdown,application/json,application/zip,application/msword,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.oasis.opendocument.text,application/vnd.oasis.opendocument.spreadsheet,video/mp4,video/webm,video/quicktime,audio/mpeg,audio/wav,audio/ogg,audio/webm";function t$(e){let s,n,l,i=(0,a.c)(7),{n:r,size:o}=e,d=void 0===o?18:o;i[0]!==d?(s={width:d,height:d},i[0]=d,i[1]=s):s=i[1];let c=`h_${r}`;return i[2]!==c?(n=(0,t.jsx)(et.Glyph,{name:c,strokeWidth:1.6}),i[2]=c,i[3]=n):n=i[3],i[4]!==s||i[5]!==n?(l=(0,t.jsx)("span",{className:"tlHIcon",style:s,"aria-hidden":!0,children:n}),i[4]=s,i[5]=n,i[6]=l):l=i[6],l}function tB({mode:e,kind:a,anchor:s,directory:n,directoryLoading:l,directoryError:i,onRetryDirectory:o,meId:d,existing:c,returnFocus:u,onClose:m,onConfirm:h}){let{t:p}=(0,Z.useTranslation)("paletteOs"),g=(0,r.useRef)(null),[f,x]=(0,r.useState)(""),[b,v]=(0,r.useState)(a),[j,y]=(0,r.useState)([]),[w,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(!1),[S,_]=(0,r.useState)(null),[T,E]=(0,r.useState)(()=>new Set),A=(0,r.useRef)(!1),R=(0,r.useRef)(!0);(0,r.useEffect)(()=>(R.current=!0,()=>{R.current=!1}),[]);let D=new Set([...n.people,...n.agents].map(t7)),M=j.filter(e=>D.has(t7(e))&&!c.has(t7(e))&&!T.has(t7(e))),I=async()=>{if(!A.current&&!l&&!i&&M.length){A.current=!0,C(!0),_(null);try{if("new"===e)await h(M,w);else{let e=await Promise.allSettled(M.map(e=>h([e],w)));if(!R.current)return;let t=M.filter((t,a)=>"rejected"===e[a].status);if(E(t=>new Set([...t,...M.filter((t,a)=>"fulfilled"===e[a].status).map(t7)])),t.length){y(t),_(p("talk.addParticipantsFailed","Could not add {{names}}. Retry the remaining selection.",{names:t.map(e=>e.name).join(", ")}));return}}R.current&&m()}catch(e){R.current&&_(e instanceof Error?e.message:p("talk.dmFailed","Could not open the conversation"))}finally{A.current=!1,R.current&&C(!1)}}},O="add"===e,P=(0,r.useMemo)(()=>new Set(j.map(t7)),[j]),L=e=>e.is_agent?p("talk.agent","Agent"):e.email??p("talk.cardPerson","Member"),F=f.trim().toLocaleLowerCase(),$=e=>!F||`${e.name} ${L(e)}`.toLocaleLowerCase().includes(F),B="agent"===b?[]:n.people.filter(e=>String(e.id)!==d).filter($),H="person"===b?[]:n.agents.filter($),z=e=>y(t=>t.some(t=>t7(t)===t7(e))?t.filter(t=>t7(t)!==t7(e)):[...t,e]),U=M.filter(e=>!e.is_agent).length,G="agent"===a?p("talk.addAgents","Add agents"):p("talk.addPeople","Add people"),W=(e,a)=>a.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"tlPickGroup",children:e}),a.map(e=>{let a=c.has(t7(e))||T.has(t7(e)),s=a||P.has(t7(e));return(0,t.jsxs)("button",{className:"tlPickRow","aria-pressed":s,disabled:a||N,onClick:()=>z(e),children:[(0,t.jsx)(e1,{actor:e,size:33}),(0,t.jsxs)("span",{className:"tlPickBody",children:[(0,t.jsxs)("strong",{children:[e.name,e.is_agent&&(0,t.jsx)("i",{className:"tlBotMark",children:p("talk.agent","Agent")})]}),(0,t.jsxs)("small",{children:[L(e),a?` \xb7 ${p("talk.inRoomAlready","already in")}`:""]})]}),(0,t.jsx)("span",{className:`tlCheck${s?" on":""}`,"aria-hidden":!0,children:s&&(0,t.jsx)(t$,{n:"check",size:13})})]},t7(e))})]},e),K=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("label",{className:"tlPickSearch poSearch",children:[(0,t.jsx)(t$,{n:"search",size:16}),(0,t.jsx)("input",{ref:g,type:"search",value:f,placeholder:p("talk.pickSearch","Search by name or role"),"aria-label":p("talk.pickSearch","Search by name or role"),onChange:e=>x(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),m())}})]}),(0,t.jsx)("div",{className:"tlPicked",children:j.map(e=>(0,t.jsxs)("button",{className:"tlPickedChip",disabled:N,onClick:()=>z(e),children:[e.name,(0,t.jsx)(t$,{n:"close",size:12})]},t7(e)))}),!O&&(0,t.jsx)("div",{className:"tlPickTabs",role:"group","aria-label":p("talk.pickKind","Participant type"),children:[["all",p("talk.pickAll","All")],["person",p("talk.pickPeople","People")],["agent",p("talk.pickAgents","Agents")]].map(([e,a])=>(0,t.jsx)("button",{className:"tlPickTab","aria-pressed":b===e,onClick:()=>v(e),children:a},e))}),l&&(0,t.jsx)("p",{className:"tlPickStatus",role:"status",children:p("talk.directoryLoading","Loading people and agentsâ¦")}),i&&(0,t.jsxs)("div",{className:"tlPickError",role:"alert",children:[(0,t.jsx)("p",{children:p("talk.directoryFailed","Could not load people and agents.")}),(0,t.jsx)("button",{className:"tlBtn",onClick:o,children:p("talk.retryDirectory","Retry")})]}),(0,t.jsxs)("div",{className:"tlPickRows","aria-busy":l,children:[W(p("talk.pickPeople","People"),B),W(p("talk.pickAgents","Agents"),H),!l&&!i&&B.length+H.length===0&&(0,t.jsx)("p",{className:"tlPickEmpty",children:p("talk.noPickMatch","No results.")})]}),"new"===e&&(0,t.jsxs)("label",{className:"tlRoomNameField",children:[p("talk.roomNameLabel","Conversation name")," ",(0,t.jsx)("span",{children:p("talk.optional","optional")}),(0,t.jsx)("input",{value:w,disabled:N,maxLength:80,placeholder:p("talk.roomNameHint","e.g. Brand design team"),onChange:e=>k(e.target.value)})]}),S&&(0,t.jsx)("p",{className:"tlPickError",role:"alert",children:S}),(0,t.jsxs)("div",{className:"tlPickFoot",children:[(0,t.jsx)("span",{role:"status",children:O?p("talk.pickCountOne","{{count}} selected",{count:M.length}):p("talk.pickCount","{{people}} people · {{agents}} agents selected",{people:U,agents:M.length-U})}),(0,t.jsxs)("div",{className:"tlModalActs",children:[(0,t.jsx)("button",{className:"tlBtn",onClick:m,children:p("talk.cancel","Cancel")}),(0,t.jsx)("button",{className:"tlBtn tlBtn--primary","aria-busy":N,disabled:N||l||!!i||0===M.length,onClick:()=>void I(),children:N?p("talk.pickerSaving","Savingâ¦"):O?G:p("talk.startChat","Start chat")})]})]})]});return(0,t.jsxs)(tH,{title:O?G:p("talk.newTalk","New chat"),onClose:m,initialFocus:g,returnFocus:u,popover:O,anchor:s,children:[!O&&(0,t.jsx)("p",{className:"tlModalIntro",children:p("talk.newChatIntro","Pick people and agents together.")}),K]})}function tH(e){let l,i,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w=(0,a.c)(44),{title:k,onClose:N,children:C,initialFocus:S,returnFocus:_,popover:T,anchor:E}=e,A=void 0!==T&&T,{t:R}=(0,Z.useTranslation)("paletteOs"),[D]=(0,r.useState)(tz),M=(0,r.useRef)(null);w[0]!==N||w[1]!==A?(l=()=>{if(!A)return;let e=()=>N();return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},i=[A,N],w[0]=N,w[1]=A,w[2]=l,w[3]=i):(l=w[2],i=w[3]),(0,r.useEffect)(l,i);let I=Math.min((E?.bottom??60)+10,window.innerHeight-44);w[4]!==E||w[5]!==A||w[6]!==I?(o=A?{left:Math.max(12,Math.min((E?E.left+E.width/2+16:window.innerWidth)-340,window.innerWidth-352)),top:I,maxHeight:Math.max(32,window.innerHeight-I-12)}:void 0,w[4]=E,w[5]=A,w[6]=I,w[7]=o):o=w[7];let O=o;w[8]!==N?(d=e=>{e||N()},w[8]=N,w[9]=d):d=w[9];let P=A?"tlPopBd":"tlModalBd";w[10]!==P?(c=(0,t.jsx)(n.Dialog.Overlay,{className:P}),w[10]=P,w[11]=c):c=w[11];let L=A?"tlPickPop":"tlModal";w[12]!==S?(u=e=>{S?.current&&(e.preventDefault(),S.current.focus())},w[12]=S,w[13]=u):u=w[13],w[14]!==D||w[15]!==_?.current?(m=e=>{e.preventDefault();let t=document.activeElement;if(t instanceof HTMLElement&&t.closest('[role="dialog"]')&&!M.current?.contains(t))return;let a=D?.isConnected&&D!==document.body?D:_?.current;a?.focus()},w[14]=D,w[15]=_?.current,w[16]=m):m=w[16];let F=A?"tlPickPopHead":"tlModalHead";return w[17]!==k?(h=(0,t.jsx)(n.Dialog.Title,{asChild:!0,children:(0,t.jsx)("h2",{children:k})}),w[17]=k,w[18]=h):h=w[18],w[19]!==R?(p=R("talk.close","Close"),w[19]=R,w[20]=p):p=w[20],w[21]===Symbol.for("react.memo_cache_sentinel")?(g=(0,t.jsx)(t$,{n:"close",size:20}),w[21]=g):g=w[21],w[22]!==p?(f=(0,t.jsx)(n.Dialog.Close,{asChild:!0,children:(0,t.jsx)("button",{className:"tlIconBtn","aria-label":p,children:g})}),w[22]=p,w[23]=f):f=w[23],w[24]!==F||w[25]!==h||w[26]!==f?(x=(0,t.jsxs)("div",{className:F,children:[h,f]}),w[24]=F,w[25]=h,w[26]=f,w[27]=x):x=w[27],w[28]!==C||w[29]!==A?(b=A?C:(0,t.jsx)("div",{className:"tlModalBody",children:C}),w[28]=C,w[29]=A,w[30]=b):b=w[30],w[31]!==O||w[32]!==m||w[33]!==x||w[34]!==b||w[35]!==L||w[36]!==u?(v=(0,t.jsxs)(n.Dialog.Content,{ref:M,className:L,style:O,"aria-describedby":void 0,onOpenAutoFocus:u,onCloseAutoFocus:m,children:[x,b]}),w[31]=O,w[32]=m,w[33]=x,w[34]=b,w[35]=L,w[36]=u,w[37]=v):v=w[37],w[38]!==v||w[39]!==c?(j=(0,t.jsxs)(s.OverlayPortal,{children:[c,v]}),w[38]=v,w[39]=c,w[40]=j):j=w[40],w[41]!==j||w[42]!==d?(y=(0,t.jsx)(n.Dialog.Root,{open:!0,onOpenChange:d,children:j}),w[41]=j,w[42]=d,w[43]=y):y=w[43],y}function tz(){return document.activeElement instanceof HTMLElement?document.activeElement:null}function tU({name:e,returnTo:a,onClose:s,onSave:n}){let{t:l}=(0,Z.useTranslation)("paletteOs"),[i,o]=(0,r.useState)(e),[d,c]=(0,r.useState)(!1),[u,m]=(0,r.useState)(null),h=(0,r.useId)(),p=(0,r.useRef)(null),g=(0,r.useRef)(!1),f=(0,r.useRef)(!0);(0,r.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]);let x=async()=>
29{if(!g.current&&i.trim()){g.current=!0,c(!0),m(null);try{await n(i.trim()),f.current&&s()}catch(e){f.current&&m(e instanceof Error?e.message:l("talk.renameFailed","Could not rename the conversation."))}finally{g.current=!1,f.current&&c(!1)}}};return(0,t.jsx)(tH,{title:l("talk.renameConversation","Rename conversation"),onClose:s,initialFocus:p,returnFocus:{current:a},children:(0,t.jsxs)("form",{className:"tlRenameForm",onSubmit:e=>{e.preventDefault(),x()},onKeyDown:e=>{"Enter"===e.key&&(e.nativeEvent.isComposing||229===e.nativeEvent.keyCode)&&e.preventDefault()},children:[(0,t.jsx)("label",{htmlFor:h,children:l("session.rename.field","Name / value")}),(0,t.jsx)("input",{id:h,ref:p,required:!0,maxLength:80,value:i,disabled:d,onFocus:e=>e.currentTarget.select(),onChange:e=>o(e.target.value)}),u&&(0,t.jsx)("p",{className:"tlPickError",role:"alert",children:u}),(0,t.jsxs)("div",{className:"tlModalActs",children:[(0,t.jsx)("button",{type:"button",className:"tlBtn",onClick:s,children:l("talk.cancel","Cancel")}),(0,t.jsx)("button",{type:"submit",className:"tlBtn tlBtn--primary",disabled:d||!i.trim(),"aria-busy":d,children:d?l("talk.pickerSaving","Savingâ¦"):l("session.rename.save","Save")})]})]})})}function tG(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x=(0,a.c)(43),{label:b,meta:v,participants:j,meId:y,onClose:w,onAddPeople:k,onAddAgents:N,onMenu:C}=e,{t:S}=(0,Z.useTranslation)("paletteOs");if(x[0]!==S?(s=S("talk.participantsTitle","Participants"),x[0]=S,x[1]=s):s=x[1],x[2]!==b||x[3]!==v?(n=(0,t.jsxs)("p",{className:"tlModalIntro",children:[b," · ",v]}),x[2]=b,x[3]=v,x[4]=n):n=x[4],x[5]!==y||x[6]!==C||x[7]!==j||x[8]!==S){let e;x[10]!==y||x[11]!==C||x[12]!==S?(e=e=>{let a=!e.is_agent&&String(e.id)===y;return(0,t.jsxs)("div",{className:"tlRosterRow",onContextMenu:t=>{t.preventDefault(),C(e,{x:t.clientX,y:t.clientY})},children:[(0,t.jsx)(e1,{actor:e,size:33}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("strong",{children:[e.name,a?` \xb7 ${S("talk.me","Me")}`:""]}),(0,t.jsx)("small",{children:e.is_agent?S("talk.agent","Agent"):e.email??e.role})]}),e.is_agent&&(0,t.jsx)("span",{className:"tlBotMark",children:S("talk.agent","Agent")})]},e.participant_id)},x[10]=y,x[11]=C,x[12]=S,x[13]=e):e=x[13],l=j.map(e),x[5]=y,x[6]=C,x[7]=j,x[8]=S,x[9]=l}else l=x[9];return x[14]!==l?(i=(0,t.jsx)("div",{className:"tlRoster",children:l}),x[14]=l,x[15]=i):i=x[15],x[16]!==S?(r=S("talk.close","Close"),x[16]=S,x[17]=r):r=x[17],x[18]!==w||x[19]!==r?(o=(0,t.jsx)("button",{className:"tlBtn",onClick:w,children:r}),x[18]=w,x[19]=r,x[20]=o):o=x[20],x[21]===Symbol.for("react.memo_cache_sentinel")?(d=(0,t.jsx)(t$,{n:"personPlus",size:17}),x[21]=d):d=x[21],x[22]!==S?(c=S("talk.addPeople","Add people"),x[22]=S,x[23]=c):c=x[23],x[24]!==k||x[25]!==c?(u=(0,t.jsxs)("button",{className:"tlBtn",onClick:k,children:[d,c]}),x[24]=k,x[25]=c,x[26]=u):u=x[26],x[27]===Symbol.for("react.memo_cache_sentinel")?(m=(0,t.jsx)(t$,{n:"botPlus",size:17}),x[27]=m):m=x[27],x[28]!==S?(h=S("talk.addAgents","Add agents"),x[28]=S,x[29]=h):h=x[29],x[30]!==N||x[31]!==h?(p=(0,t.jsxs)("button",{className:"tlBtn tlBtn--primary",onClick:N,children:[m,h]}),x[30]=N,x[31]=h,x[32]=p):p=x[32],x[33]!==p||x[34]!==o||x[35]!==u?(g=(0,t.jsxs)("div",{className:"tlModalActs",children:[o,u,p]}),x[33]=p,x[34]=o,x[35]=u,x[36]=g):g=x[36],x[37]!==w||x[38]!==s||x[39]!==g||x[40]!==n||x[41]!==i?(f=(0,t.jsxs)(tH,{title:s,onClose:w,children:[n,i,g]}),x[37]=w,x[38]=s,x[39]=g,x[40]=n,x[41]=i,x[42]=f):f=x[42],f}function tW(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_=(0,a.c)(96),{draft:T,setDraft:E,error:A,busy:R,onClose:D,onCreate:M}=e,{t:I}=(0,Z.useTranslation)("paletteOs");if(_[0]!==T||_[1]!==A||_[2]!==D||_[3]!==M||_[4]!==E||_[5]!==I){let e,a,u,m,h,p,g,f,x,b,v;s=T.name.trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9_-]/g,""),r="tlNewMsg tlNewMsg--room",o="dialog",_[14]!==I?(d=I("talk.newChannelRow","New channel"),_[14]=I,_[15]=d):d=_[15],_[16]!==I?(e=I("talk.newChannelRow","New channel"),_[16]=I,_[17]=e):e=_[17],_[18]!==e?(a=(0,t.jsx)("span",{className:"tlNewMsgTitle",children:e}),_[18]=e,_[19]=a):a=_[19],_[20]!==I?(u=I("talk.close","Close"),_[20]=I,_[21]=u):u=_[21],_[22]===Symbol.for("react.memo_cache_sentinel")?(m=(0,t.jsx)(ej.TlIcon,{n:"x",size:18}),_[22]=m):m=_[22],_[23]!==D||_[24]!==u?(h=(0,t.jsx)("button",{className:"tlIconBtn","aria-label":u,onClick:D,children:m}
29),_[23]=D,_[24]=u,_[25]=h):h=_[25],_[26]!==h||_[27]!==a?(c=(0,t.jsxs)("header",{className:"tlNewMsgHead",children:[a,h]}),_[26]=h,_[27]=a,_[28]=c):c=_[28],n="tlNewMsgBody",_[29]!==I?(p=I("talk.channelName","NAME"),_[29]=I,_[30]=p):p=_[30],_[31]!==p?(g=(0,t.jsx)("span",{children:p}),_[31]=p,_[32]=g):g=_[32];let j=T.private?"lock":"hash";_[33]!==j?(f=(0,t.jsx)(ej.TlIcon,{n:j,size:16}),_[33]=j,_[34]=f):f=_[34];let y=T.name;_[35]!==I?(x=I("talk.newChannelName","channel-name"),_[35]=I,_[36]=x):x=_[36],_[37]!==T||_[38]!==E?(b=e=>E({...T,name:e.target.value}),_[37]=T,_[38]=E,_[39]=b):b=_[39];let w=(0,t.jsx)("input",{autoFocus:!0,value:y,placeholder:x,onChange:b,onKeyDown:e=>{"Enter"===e.key&&s&&M(),"Escape"===e.key&&D()}});_[40]!==f||_[41]!==w?(v=(0,t.jsxs)("div",{className:"tlNewMsgName",children:[f,w]}),_[40]=f,_[41]=w,_[42]=v):v=_[42],_[43]!==g||_[44]!==v?(l=(0,t.jsxs)("label",{className:"tlField",children:[g,v]}),_[43]=g,_[44]=v,_[45]=l):l=_[45],i=A?(0,t.jsx)("p",{className:"tlNewMsgHint tlNewMsgErr",role:"alert",children:A}):s&&s!==T.name.trim()&&(0,t.jsx)("p",{className:"tlNewMsgHint",children:I("talk.willBeCalled","It will be called #{{slug}}",{slug:s})}),_[0]=T,_[1]=A,_[2]=D,_[3]=M,_[4]=E,_[5]=I,_[6]=s,_[7]=n,_[8]=l,_[9]=i,_[10]=r,_[11]=o,_[12]=d,_[13]=c}else s=_[6],n=_[7],l=_[8],i=_[9],r=_[10],o=_[11],d=_[12],c=_[13];let O=T.private;_[46]!==T||_[47]!==E?(u=()=>E({...T,private:!T.private}),_[46]=T,_[47]=E,_[48]=u):u=_[48];let P=`rlCheck${T.private?" on":""}`;_[49]!==P?(m=(0,t.jsx)("span",{className:P,"aria-hidden":!0}),_[49]=P,_[50]=m):m=_[50],_[51]!==I?(h=I("talk.makePrivate","Make private"),_[51]=I,_[52]=h):h=_[52],_[53]!==h?(p=(0,t.jsx)("strong",{children:h}),_[53]=h,_[54]=p):p=_[54],_[55]!==T.private||_[56]!==I?(g=T.private?I("talk.privateNote","Only invited people can find and open it"):I("talk.openNote","Anyone in the workspace can find and join it"),_[55]=T.private,_[56]=I,_[57]=g):g=_[57],_[58]!==g?(f=(0,t.jsx)("em",{children:g}),_[58]=g,_[59]=f):f=_[59],_[60]!==p||_[61]!==f?(x=(0,t.jsxs)("span",{children:[p,f]}),_[60]=p,_[61]=f,_[62]=x):x=_[62],_[63]!==T.private||_[64]!==m||_[65]!==x||_[66]!==u?(b=(0,t.jsxs)("button",{className:"tlNewMsgVis",role:"switch","aria-checked":O,onClick:u,children:[m,x]}),_[63]=T.private,_[64]=m,_[65]=x,_[66]=u,_[67]=b):b=_[67],_[68]!==n||_[69]!==b||_[70]!==l||_[71]!==i?(v=(0,t.jsxs)("div",{className:n,children:[l,i,b]}),_[68]=n,_[69]=b,_[70]=l,_[71]=i,_[72]=v):v=_[72],_[73]===Symbol.for("react.memo_cache_sentinel")?(j=(0,t.jsx)("span",{className:"tlNewMsgNote"}),_[73]=j):j=_[73],_[74]!==I?(y=I("talk.cancel","CANCEL"),_[74]=I,_[75]=y):y=_[75],_[76]!==D||_[77]!==y?(w=(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:D,children:y}),_[76]=D,_[77]=y,_[78]=w):w=_[78];let L=!s||R;return _[79]!==I?(k=I("talk.create","CREATE"),_[79]=I,_[80]=k):k=_[80],_[81]!==R||_[82]!==M||_[83]!==L||_[84]!==k?(N=(0,t.jsx)("button",{className:"po-btn po-btn--sm",disabled:L,"aria-busy":R,onClick:M,children:k}),_[81]=R,_[82]=M,_[83]=L,_[84]=k,_[85]=N):N=_[85],_[86]!==w||_[87]!==N?(C=(0,t.jsxs)("footer",{className:"tlNewMsgFoot",children:[j,w,N]}),_[86]=w,_[87]=N,_[88]=C):C=_[88],_[89]!==v||_[90]!==C||_[91]!==r||_[92]!==o||_[93]!==d||_[94]!==c?(S=(0,t.jsxs)("div",{className:r,role:o,"aria-label":d,children:[c,v,C]}),_[89]=v,_[90]=C,_[91]=r,_[92]=o,_[93]=d,_[94]=c,_[95]=S):S=_[95],S}let tK="palette_talk_unread_v1",tV="palette_talk_last_room_v1",tY="palette_talk_drafts_v1";function tq(e,t,a){if(!a.trim()){if(!(t in e))return e;let a={...e};return delete a[t],a}if(e[t]===a)return e;let s={...e,[t]:a.slice(0,1e4)},n=Object.keys(s);return n.length<=50?s:Object.fromEntries(n.slice(-50).map(e=>[e,s[e]]))}let tJ={"+1":"ð","-1":"ð",eyes:"ð",tada:"ð",heart:"â¤ï¸",rocket:"ð",ok:"â
",fire:"ð¥",clap:"ð",thinking:"ð¤"},tX=e=>tJ[e]??e,tZ=/^:([a-z0-9][a-z0-9_-]*):$/,tQ=(e,t)=>({bold:e("talk.fmtBold","Bold"),italic:e("talk.fmtItalic","Italic"),strike:e("talk.fmtStrike","Strikethrough"),link:e("talk.fmtLink","
29Link"),listOl:e("talk.fmtOl","Numbered list"),listUl:e("talk.fmtUl","Bulleted list"),quote:e("talk.fmtQuote","Quote"),code:e("talk.fmtCode","Code"),codeBlock:e("talk.fmtCodeBlock","Code block")})[t],t0=[{id:"bold",icon:"bold",keys:"B"},{id:"italic",icon:"italic",keys:"I"},{id:"strike",icon:"strike",keys:"â§X"},{id:"link",icon:"link",keys:"K",sep:!0},{id:"listOl",icon:"listOl",keys:"â§7",sep:!0},{id:"listUl",icon:"listUl",keys:"â§8"},{id:"quote",icon:"quote",keys:"â§9"},{id:"code",icon:"code",keys:"â§C",sep:!0},{id:"codeBlock",icon:"codeBlock",keys:"â¥â§C"}],t1="u">typeof navigator&&/Mac|iPhone|iPad/.test(navigator.platform)?"â":"Ctrl+",t2="palette_talk_aux_w",t3=(e,t)=>Math.max(300,Math.min(e,Math.min(760,Math.max(320,t-420))));function t4(e){let t=e?.closest(".viewPane, .talkView")??document;return(t.querySelector(".tlMain")?.getBoundingClientRect().width??0)+(t.querySelector(".tlAux")?.getBoundingClientRect().width??0)||900}let t5=e=>{if(!e)return"";let t=new Date(e);return Number.isNaN(t.getTime())?"":`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`};function t6(e){let s,n,l,i,r=(0,a.c)(15),{channel:o,members:d,meId:c,size:u}=e;r[0]!==c||r[1]!==d?(s=d?.find(e=>e&&("user"!==e.kind||String(e.id)!==c)),r[0]=c,r[1]=d,r[2]=s):s=r[2];let m=s;if("dm"===o.channel_type){let e,a;return r[3]!==o.id||r[4]!==o.name||r[5]!==m?(e=m??{id:o.id,name:o.name,is_agent:!1},r[3]=o.id,r[4]=o.name,r[5]=m,r[6]=e):e=r[6],r[7]!==u||r[8]!==e?(a=(0,t.jsx)(e1,{size:u,actor:e}),r[7]=u,r[8]=e,r[9]=a):a=r[9],a}return r[10]!==u?(n={width:u,height:u},r[10]=u,r[11]=n):n=r[11],r[12]===Symbol.for("react.memo_cache_sentinel")?(l=(0,t.jsx)(t$,{n:"users",size:18}),r[12]=l):l=r[12],r[13]!==n?(i=(0,t.jsx)("span",{className:"tlRoomTile",style:n,"aria-hidden":!0,children:l}),r[13]=n,r[14]=i):i=r[14],i}let t7=e=>e?`${e.kind}:${e.id}`:"?",t8=e=>e.split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";function t9(e,t,a,s){if("dm"!==e.channel_type&&"group_dm"!==e.channel_type||e.name.trim())return e.name;let n=(t??[]).filter(Boolean),l=n.filter(e=>"user"!==e.kind||String(e.id)!==s),i=(l.length?l:n).map(e=>e.name);return i.length?i.join(", "):a}function ae({items:e,onCreate:a,onDelete:s}){let{t:n}=(0,Z.useTranslation)("paletteOs"),l=(0,r.useRef)(null),[i,o]=(0,r.useState)(""),[d,c]=(0,r.useState)("emoji"),[u,m]=(0,r.useState)(!1),h=i.trim().toLowerCase().replace(/[^a-z0-9_-]/g,"-").replace(/^-+/,""),p=async e=>{if(!h)return void ee.toast.error(n("talk.emojiNeedsCode","Give it a short code first"));m(!0);try{await a(e,{kind:d,code:h}),o(""),(0,ee.toast)(n("talk.emojiAdded",":{{code}}: is ready",{code:h}))}catch(e){ee.toast.error(e instanceof Error?e.message:n("talk.emojiAddFailed","Could not add it"))}finally{m(!1)}};return(0,t.jsxs)("div",{className:"tlEmojiAdmin",children:[(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:n("talk.emojiOrgTitle","WORKSPACE EMOJI")})}),(0,t.jsxs)("div",{className:"tlSheetRow",children:[(0,t.jsx)("input",{className:"tlEmojiCode",value:i,placeholder:n("talk.emojiCode","short-code"),"aria-label":n("talk.emojiCode","short-code"),onChange:e=>o(e.target.value)}),(0,t.jsx)("button",{className:`po-btn po-btn--sm po-btn--rect${"emoji"===d?" on":""}`,"aria-pressed":"emoji"===d,onClick:()=>c("emoji"),children:n("talk.emojiKindEmoji","EMOJI")}),(0,t.jsx)("button",{className:`po-btn po-btn--sm po-btn--rect${"sticker"===d?" on":""}`,"aria-pressed":"sticker"===d,onClick:()=>c("sticker"),children:n("talk.emojiKindSticker","STICKER")}),(0,t.jsx)("button",{className:"po-btn po-btn--sm",disabled:u,onClick:()=>l.current?.click(),children:n("talk.emojiUpload","UPLOAD")}),(0,t.jsx)("input",{ref:l,type:"file",hidden:!0,accept:"image/png,image/gif,image/webp,image/jpeg",onChange:e=>{let t=e.target.files?.[0];e.target.value="",t&&p(t)}})]}),(0,t.jsx)("p",{className:"tlEmojiHint",children:n("talk.emojiHint","PNG, GIF, WebP or JPEG · up to 512KB · use it as :code:")}),e.length>0&&(0,t.jsx)("div",{className:"tlEmojiAdminGrid",children:e.map(e=>(0,t.jsxs)("span",{className:"tlEmojiAdminRow",children:[(0,t.jsx)("img",{src:e.f
29ile_url,alt:e.label}),(0,t.jsxs)("code",{children:[":",e.code,":"]}),(0,t.jsx)("button",{"aria-label":n("talk.delete","Delete"),onClick:()=>void s(e.id),children:(0,t.jsx)(ej.TlIcon,{n:"trash",size:14})})]},e.id))})]})}function at(e){let s,n,l=(0,a.c)(5),{caption:i,announce:r}=e,o=void 0!==r&&r?"status":void 0;return l[0]!==i?(s=(0,t.jsx)("span",{children:i}),l[0]=i,l[1]=s):s=l[1],l[2]!==o||l[3]!==s?(n=(0,t.jsx)("div",{className:"tlIntro",role:o,children:s}),l[2]=o,l[3]=s,l[4]=n):n=l[4],n}let aa=["ð","â¤ï¸","â
"],as=["ð","ð","â¤ï¸","â
","ð","ð"];function an(e){let s,n,l,o,d,c,u,m,h,p,g,f=(0,a.c)(34),{rect:x,label:b,choices:v,moreLabel:j,onPick:y,onMore:w,onClose:k}=e,[N]=(0,r.useState)(al),C=(0,r.useRef)(null);f[0]!==k?(s=e=>{e||k()},f[0]=k,f[1]=s):s=f[1],f[2]!==x?(n=(0,t.jsx)(i.Popover.Anchor,{virtualRef:{current:{getBoundingClientRect:()=>x}}}),f[2]=x,f[3]=n):n=f[3];let S=x.top>window.innerHeight/2?"top":"bottom";if(f[4]!==k?(l=e=>{e.preventDefault(),k()},f[4]=k,f[5]=l):l=f[5],f[6]!==N?(o=e=>{e.preventDefault(),N?.isConnected&&(document.activeElement===document.body||C.current?.contains(document.activeElement))&&N.focus()},f[6]=N,f[7]=o):o=f[7],f[8]!==v||f[9]!==y){let e;f[11]!==y?(e=e=>(0,t.jsx)(q.Button,{"aria-label":e,onClick:()=>y(e),children:e},e),f[11]=y,f[12]=e):e=f[12],d=v.map(e),f[8]=v,f[9]=y,f[10]=d}else d=f[10];return f[13]!==w||f[14]!==N?(c=()=>{N?.focus(),w()},f[13]=w,f[14]=N,f[15]=c):c=f[15],f[16]===Symbol.for("react.memo_cache_sentinel")?(u=(0,t.jsx)(t$,{n:"more",size:16}),f[16]=u):u=f[16],f[17]!==j||f[18]!==c?(m=(0,t.jsx)(q.Button,{className:"tlQuickMore","aria-label":j,onClick:c,children:u}),f[17]=j,f[18]=c,f[19]=m):m=f[19],f[20]!==b||f[21]!==d||f[22]!==m?(h=(0,t.jsxs)(q.Root,{className:"tlQuickChoices","aria-label":b,loop:!0,children:[d,m]}),f[20]=b,f[21]=d,f[22]=m,f[23]=h):h=f[23],f[24]!==b||f[25]!==h||f[26]!==S||f[27]!==l||f[28]!==o?(p=(0,t.jsx)(i.Popover.Content,{ref:C,className:"tlQuickPill","aria-label":b,side:S,align:"start",sideOffset:6,collisionPadding:8,onEscapeKeyDown:l,onCloseAutoFocus:o,children:h}),f[24]=b,f[25]=h,f[26]=S,f[27]=l,f[28]=o,f[29]=p):p=f[29],f[30]!==s||f[31]!==p||f[32]!==n?(g=(0,t.jsxs)(i.Popover.Root,{open:!0,onOpenChange:s,children:[n,p]}),f[30]=s,f[31]=p,f[32]=n,f[33]=g):g=f[33],g}function al(){return document.activeElement}let ai=["WORK","PRODUCT","OPS","SOCIAL"];function ar(e){let s,n,l=(0,a.c)(4),{attachments:i}=e;return l[0]!==i?(s=i.map(ao),l[0]=i,l[1]=s):s=l[1],l[2]!==s?(n=(0,t.jsx)("div",{className:"tlFiles",children:s}),l[2]=s,l[3]=n):n=l[3],n}function ao(e){return e.mime_type?.startsWith("audio/")?(0,t.jsx)("audio",{className:"tlClip",controls:!0,preload:"metadata",src:e.file_url,title:e.filename},e.file_url):e.mime_type?.startsWith("video/")?(0,t.jsx)("video",{className:"tlClip tlClip--video",controls:!0,preload:"metadata",src:e.file_url,title:e.filename},e.file_url):(0,t.jsx)(es,{name:e.filename,mime:e.mime_type??"",size:e.file_size,url:e.file_url},e.file_url)}function ad(e){let s,n,l,i,r,o=(0,a.c)(12),{content:d,children:c}=e;o[0]!==d?(s=(0,er.parseAllPanels)(d),o[0]=d,o[1]=s):s=o[1];let u=s;o[2]!==d?(n=(0,er.stripPanelBlocks)(d),o[2]=d,o[3]=n):n=o[3];let m=n;return o[4]!==c||o[5]!==m?(l=(m.trim()||c)&&(0,t.jsxs)("div",{className:"tlBodyText",children:[m.trim()&&(0,t.jsx)(el.ChatMarkdown,{children:m}),c]}),o[4]=c,o[5]=m,o[6]=l):l=o[6],o[7]!==u?(i=u.map(ac),o[7]=u,o[8]=i):i=o[8],o[9]!==l||o[10]!==i?(r=(0,t.jsxs)(t.Fragment,{children:[l,i]}),o[9]=l,o[10]=i,o[11]=r):r=o[11],r}function ac(e,a){return(0,t.jsx)("div",{className:"tlPanel",children:(0,t.jsx)(ei.PanelContentCard,{panel:e})},a)}function au(e){let s,n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D,M,I=(0,a.c)(72),{text:O,customEmoji:P,onChange:L,onCancel:F,onSave:$}=e,{t:B}=(0,Z.useTranslation)("paletteOs"),H=(0,r.useRef)(null),z=(0,r.useRef)(null),[U,G]=(0,r.useState)(null);I[0]===Symbol.for("react.memo_cache_sentinel")?(s=()=>{z.current?.scrollIntoView({block:"nearest"}),H.current?.focus()},n=[],I[0]=s,I[1]=n):(s=I[0],n=I[1]),(0,r.useEffect)(s,n),I[2]!==B?(l=B("talk.formatting","Formatting"),I[2]=B,I[3]=l):l=I[3],I[4]!==B?(i=t0.map(e=>(0,t.jsx)("button",{className:`tlFmtBtn${e.sep?" tlFmtBtn--group":""}`,title:`${tQ(B,e.id)} ${t1}${e.keys}`,"aria-label":tQ(B,e.id),onMouseDown:ap,onClick:()=>H.current?.format(e.id),children:(0,t.jsx)(ej.TlIcon,{n:e.icon,size:15})},e.id)),I[4]=B,I[5]=i):i=I[5],I[6]!==l||I[7]!==i?(o=(0,t.jsx)("div",{className:"tlFmtBar",role:"toolbar","aria-label":l,children:i}),I[6]=l,I[7]=i,I[8]=o):o=I[8],I[9]!==B?(d=B("talk.edit","Edit"),I[9]=B,I[10]=d):d=I[10],I[11]!==B?(c=B("talk.edit","Edit"),I[11]=B,I[12]=c):c=I[12],I[13]!==F?(u=e=>"Escape"===e.key&&(F(),!0),I[13]=F,I[14]=u):u=I[14],I[15]!==L||I[16]!==$||I[17]!==d||I[18]!==c||I[19]!==u||I[20]!==O?(m=(0,t.jsx)("div",{className:"cdM
29ain",children:(0,t.jsx)(tg,{ref:H,value:O,onChange:L,onMention:ah,ariaLabel:d,placeholder:c,onSubmit:$,onFiles:am,onKeyDown:u})}),I[15]=L,I[16]=$,I[17]=d,I[18]=c,I[19]=u,I[20]=O,I[21]=m):m=I[21],I[22]!==B?(h=B("talk.emojiPicker","Emoji and stickers"),I[22]=B,I[23]=h):h=I[23],I[24]!==B?(p=B("talk.emojiPicker","Emoji and stickers"),I[24]=B,I[25]=p):p=I[25],I[26]===Symbol.for("react.memo_cache_sentinel")?(g=e=>G({rect:e.currentTarget.getBoundingClientRect(),place:"above"}),f=(0,t.jsx)(ej.TlIcon,{n:"smile",size:16}),I[26]=g,I[27]=f):(g=I[26],f=I[27]),I[28]!==h||I[29]!==p?(x=(0,t.jsx)("button",{className:"cdIcon",title:h,"aria-label":p,onClick:g,children:f}),I[28]=h,I[29]=p,I[30]=x):x=I[30],I[31]!==B?(b=B("talk.mention","Mention someone"),I[31]=B,I[32]=b):b=I[32],I[33]!==B?(v=B("talk.mention","Mention someone"),I[33]=B,I[34]=v):v=I[34],I[35]===Symbol.for("react.memo_cache_sentinel")?(j=()=>H.current?.insert("@"),y=(0,t.jsx)(ej.TlIcon,{n:"at",size:16}),I[35]=j,I[36]=y):(j=I[35],y=I[36]),I[37]!==b||I[38]!==v?(w=(0,t.jsx)("button",{className:"cdIcon",title:b,"aria-label":v,onClick:j,children:y}),I[37]=b,I[38]=v,I[39]=w):w=I[39],I[40]!==B?(k=B("talk.editHint","ENTER SAVES · ESC CANCELS"),I[40]=B,I[41]=k):k=I[41],I[42]!==k?(N=(0,t.jsx)("span",{className:"tlEditHint",children:k}),I[42]=k,I[43]=N):N=I[43],I[44]===Symbol.for("react.memo_cache_sentinel")?(C=(0,t.jsx)("span",{className:"tlFmtGap"}),I[44]=C):C=I[44],I[45]!==B?(S=B("talk.cancel","CANCEL"),I[45]=B,I[46]=S):S=I[46],I[47]!==F||I[48]!==S?(_=(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:F,children:S}),I[47]=F,I[48]=S,I[49]=_):_=I[49],I[50]!==O?(T=O.trim(),I[50]=O,I[51]=T):T=I[51];let W=!T;return I[52]!==B?(E=B("talk.save","SAVE"),I[52]=B,I[53]=E):E=I[53],I[54]!==$||I[55]!==W||I[56]!==E?(A=(0,t.jsx)("button",{className:"cdSend",onClick:$,disabled:W,children:E}),I[54]=$,I[55]=W,I[56]=E,I[57]=A):A=I[57],I[58]!==x||I[59]!==w||I[60]!==N||I[61]!==_||I[62]!==A?(R=(0,t.jsxs)("div",{className:"tlComposerTools",children:[x,w,N,C,_,A]}),I[58]=x,I[59]=w,I[60]=N,I[61]=_,I[62]=A,I[63]=R):R=I[63],I[64]!==P||I[65]!==U?(D=U&&(0,t.jsx)(tS,{anchor:U,customEmoji:P,onPick:e=>{G(null),"sticker"!==e.type&&H.current?.insert("custom"===e.type?`:${e.code}:`:e.value)},onClose:()=>G(null)}),I[64]=P,I[65]=U,I[66]=D):D=I[66],I[67]!==R||I[68]!==D||I[69]!==o||I[70]!==m?(M=(0,t.jsxs)("div",{ref:z,className:"tlEditRow chatComposer tlCompose tlCompose--edit",children:[o,m,R,D]}),I[67]=R,I[68]=D,I[69]=o,I[70]=m,I[71]=M):M=I[71],M}function am(){}function ah(){}function ap(e){return e.preventDefault()}function ag({messages:e,unreadAnchor:a,meId:s,editing:n,setEditing:l,customEmoji:i,onMenu:o,onReply:d,onThread:c,onCopy:u,onReact:m,onSaveEdit:h,onOpenPicker:p,onCardReply:g}){let{t:f}=(0,Z.useTranslation)("paletteOs"),x=(0,r.useMemo)(()=>new Map(i.map(e=>[e.code,e])),[i]),b="",v="";return(0,t.jsx)(t.Fragment,{children:e.filter(e=>!e.root_message_id).map(e=>{let r=(e.created_at||"").slice(0,10),j=r!==b;b=r;let y=e.id===a,w="system"===e.message_type,k=w?"system":t7(e.sender),N=w&&!j&&!y&&k===v;v=k;let C=e.sender?.is_agent??!1,S=e.id.startsWith("pending:"),_=!w&&e.sender?.kind==="user"&&String(e.sender.id)===s,T=e.deleted_at?null:e.panel_data,E=T&&"kind"in T&&"sticker"===T.kind?T:null,A=w&&null!==T&&"kind"in T&&"huddle"===T.kind,R=T&&"actions"in T?T.actions:null,D=!e.deleted_at&&e.attachments.length>0?(0,t.jsx)(ar,{attachments:e.attachments}):null,M=e.deleted_at?(0,t.jsx)("div",{className:"tlBodyText tlGone",children:f("talk.deleted","Message deleted")}):E?.kind==="sticker"?(0,t.jsx)("div",{className:"tlSticker",children:(0,t.jsx)("img",{src:E.url??eh(E.pack,E.id),alt:e.content||E.id})}):n?.id===e.id?(0,t.jsx)(au,{text:n.text,customEmoji:i,onChange:t=>l({id:e.id,text:t}),onCancel:()=>l(null),onSave:()=>{n.text.trim()&&h(e,n.text.trim())}}):_?e.content.trim()||D?(0,t.jsx)("div",{className:"msg me",children:(0,t.jsxs)("div",{className:"bub",children:[e.content.trim()&&(0,t.jsx)("span",{className:"tx",children:(0,t.jsx)(el.ChatMarkdown,{compact:!0,children:e.content})}),D]})}):null:(0,t.jsx)(ad,{content:e.content,children:D}),I=!!e.deleted_at,O=!I&&(e.reactions.length>0||e.reply_count>0)&&(0,t.jsxs)("div",{className:"tlMarks",children:[e.reactions.map(a=>{let n,l=(n=a.actors,n.some(e=>e?.kind==="user"&&String(e.id)===s)),i=a.emoji.match(tZ)?.[1],r=i?x.get(i):void 0;return(0,t.jsxs)("button",{className:`tlMark${l?" tlMark--mine":""}`,"aria-pressed":l,title:r?.label??a.emoji,onClick:()=>m(e,a.emoji),children:[(0,t.jsx)("em",{children:r?(0,t.jsx)("img",{src:r.file_url,alt:r.label}):tX(a.emoji)}),a.count]},a.emoji)}),e.reply_count>0&&(0,t.jsx)("button",{className:"tlMark tlMark--thread",onClick:()=>c(e),children:f("talk.replies","{{count}} REPLIES",{count:e.reply_count})})]}),P=!S&&!I&&(0,t.jsx)(aE,{message:e,onOpenPicker:p,onReply:d,onCopy:u});return(0,t.jsxs)("div",{children:[j&&(0,t.jsx)("div",{className:"tlDay",children:(0,t.jsx)("span",{children:(0,Q.dayLabel)(e.created_at,f)})}),y&&(0,t.jsx)("div",{className:"tlDay tlDay--new",children:(0,t.jsx)("span",{children:f("talk.new","NEW")})}),_?(0,t.jsxs)("div",{className:`ssUserLane tlMine${S?" tlRow--pending":""}`,onContextMenu:S||I?void 0:t=>{t.preventDefault(),o(e,{x:t.clientX,y:t.clientY})},children:[(0,t.jsxs)("header",{className:"tlRowHead tlMineHead",children:[(0,t.jsx)("span",{className:"tlWho",children:e.sender?.name??f("talk.you","You")}),(0,t.jsxs)("span",{className:"tlWhen",children:[t5(e.created_at),e.edited_at&&!e.deleted_at?` \xb7 ${f("talk.edited","EDITED")}`:""]})]}),M,(E||n?.id===e.id)&&D,(0,t.jsxs)("div",{className:"tlUnder",children:[O,P]})]}):(0,t.jsxs)("article",{className:`tlRow${N?" tlRow--tight":""}${S?" tlRow--pending":""}${w?" tlRow--sys":""}`,onContextMenu:w||S||I?void 0:t=>{t.preventDefault(),o(e,{x:t.clientX,y:t.clientY})},children:[N?(0,t.jsx)("div",{className:"tlAv tlAv--ghost",children:t5(e.created_at)}):w?(0,t.jsx)("div",{className:"tlAv tlAv--sys",children:(0,t.jsx)(ej.TlIcon,{n:A?"mic":"bolt",size:13})}):(0,t.jsx)(e1,{actor:e.sender??{id:"?",name:"",is_agent:!1},size:29}),(0,t.jsxs)("div",{className:"tlRowBody",children:[!N&&(0,t.jsxs)("header",{className:"tlRowHead",children:[w?(0,t.jsx)("span",{className:"tlWho",children:A?f("talk.huddleWord","HUDDLE"):f("talk.automation","Automation")}):(0,t.jsxs)("span",{className:"tlWho tlWhoCard",tabIndex:0,children:[e.sender?.name??f("talk.you","You"),(0,t.jsxs)("span",{className:"tlCard",role:"tooltip",children:[(0,t.jsx)("span",{className:"tlCardName",children:e.sender?.name}),(0,t.jsx)("span",{className:"tlCardKind",children:e.sender?.is_agent?f("talk.cardAgent","Agent · a member of this channel"):e.sender?.email??f("talk.cardPerson","Member")})]})]}),w&&!A&&(0,t.jsx)("span",{className:"tlBotMark",children:f("talk.rule","RULE")}),!w&&C&&(0,t.jsx)("span",{className:"tlBotMark",children:f("talk.agent","Agent")}),(0,t.jsx)("span",{className:"tlWhen",children:t5(e.created_at)}),e.edited_at&&(0,t.jsx)("span",{className:"tlWhen",children:f("talk.edited","EDITED")})]}),M,R&&R.length>0&&(0,t.jsx)(en.ChatActionCards,{actions:R,compact:!0,onReply:g}),(E||n?.id===e.id)&&D,(0,t.jsxs)("div",{className:"tlUnder",children:[O,P]})]})]})]},e.id)})})}let af=e=>e.replace(/^(\s*)(?:[-*]\s|\d+\.\s|>\s?|```)/gm,"$1").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/[*_~`]/g,"").replace(/\s+/g," ").trim();function ax(e){let s,n,l,i,r,o,d=(0,a.c)(17),{rows:c,onOpen:u,onDiscard:m}=e,{t:h}=(0,Z.useTranslation)("paletteOs");return d[0]!==h?(s=h("talk.drafts","Drafts"),d[0]=h,d[1]=s):s=d[1],d[2]!==s?(n=(0,t.jsx)("header",{className:"tlHbHead",children:(0,t.jsx)("h1",{className:"tlHbTitle",children:s})}),d[2]=s,d[3]=n):n=d[3],d[4]!==h?(l=h("talk.draftsSub","Unsent messages"),d[4]=h,d[5]=l):l=d[5],d[6]!==l?(i=(0,t.jsx)("div",{className:"tlHbSub",children:l}),d[6]=l,d[7]=i):i=d[7],d[8]!==m||d[9]!==u||d[10]!==c||d[11]!==h?(r=(0,t.jsx)("div",{className:"tlHbList",children:0===c.length?(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:h("talk.draftsEmpty","Nothing half-written. Start typing anywhere and it waits for you here.")})}):(0,t.jsx)("div",{className:"tlHbCard",children:c.map(e=>(0,t.jsxs)("div",{className:"tlHbRow",children:[(0,t.jsx)("span",{className:"tlHbTile","aria-hidden":!0,
29children:(0,t.jsx)(ej.TlIcon,{n:"edit",size:16})}),(0,t.jsxs)("button",{className:"tlHbBody",onClick:()=>u(e.id),children:[(0,t.jsx)("span",{className:"tlHbName",children:e.label}),(0,t.jsx)("span",{className:"tlHbMeta",children:af(e.text).slice(0,120)})]}),(0,t.jsx)("button",{className:"tlHbMore",title:h("talk.draftDiscard","Discard"),"aria-label":h("talk.draftDiscard","Discard"),onClick:()=>m(e.id),children:(0,t.jsx)(ej.TlIcon,{n:"trash",size:15})})]},e.id))})}),d[8]=m,d[9]=u,d[10]=c,d[11]=h,d[12]=r):r=d[12],d[13]!==n||d[14]!==i||d[15]!==r?(o=(0,t.jsxs)("div",{className:"tlHbPane",children:[n,i,r]}),d[13]=n,d[14]=i,d[15]=r,d[16]=o):o=d[16],o}function ab(e){let s,n,l,i,r,o,d=(0,a.c)(16),{rows:c,onOpen:u}=e,{t:m}=(0,Z.useTranslation)("paletteOs");return d[0]!==m?(s=m("talk.threads","Threads"),d[0]=m,d[1]=s):s=d[1],d[2]!==s?(n=(0,t.jsx)("header",{className:"tlHbHead",children:(0,t.jsx)("h1",{className:"tlHbTitle",children:s})}),d[2]=s,d[3]=n):n=d[3],d[4]!==m?(l=m("talk.threadsSub","Tagged you, and threads you are in"),d[4]=m,d[5]=l):l=d[5],d[6]!==l?(i=(0,t.jsx)("div",{className:"tlHbSub",children:l}),d[6]=l,d[7]=i):i=d[7],d[8]!==u||d[9]!==c||d[10]!==m?(r=(0,t.jsx)("div",{className:"tlHbList",children:null===c?(0,t.jsx)("div",{className:"tlHbCard",children:Array.from({length:3},aj)}):0===c.length?(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:m("talk.noThreads","Nothing with your name on it yet. A reply of yours, or an @ from a teammate, shows up here.")})}):(0,t.jsx)("div",{className:"tlHbCard",children:c.map(e=>(0,t.jsxs)("button",{className:"tlInboxRow",onClick:()=>u(e),children:[(0,t.jsx)("div",{className:`tlAv tlAv--sm${e.root.sender?.is_agent?" tlAv--bot":""}`,children:e.root.sender?.is_agent?(0,t.jsx)(ej.TlIcon,{n:"bot",size:11}):t8(e.root.sender?.name??"")}),(0,t.jsxs)("div",{className:"tlRowBody",children:[(0,t.jsxs)("header",{className:"tlRowHead",children:[(0,t.jsx)("span",{className:"tlWho",children:e.root.sender?.name??""}),(0,t.jsxs)("span",{className:"tlWhen",children:["#",e.channel_name]}),(0,t.jsx)("span",{className:"tlWhen",children:t5(e.last_reply_at)}),e.unread>0&&(0,t.jsx)("span",{className:"tlRoomC",children:e.unread})]}),(0,t.jsx)("span",{className:"tlInboxText",children:e.root.content.slice(0,120)}),(0,t.jsxs)("span",{className:"tlThreadMeta",children:[m("talk.replies","{{count}} REPLIES",{count:e.reply_count}),e.participants.length>0&&` \xb7 ${e.participants.map(av).filter(Boolean).join(", ")}`]})]})]},e.root.id))})}),d[8]=u,d[9]=c,d[10]=m,d[11]=r):r=d[11],d[12]!==n||d[13]!==i||d[14]!==r?(o=(0,t.jsxs)("div",{className:"tlHbPane",children:[n,i,r]}),d[12]=n,d[13]=i,d[14]=r,d[15]=o):o=d[15],o}function av(e){return e.name}function aj(e,a){return(0,t.jsxs)("div",{className:"tlInboxRow tlInboxRow--skel","aria-hidden":!0,children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:"34%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${52+13*a%26}%`}}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:"26%"}})]})]},a)}function ay(e){let s,n,l=(0,a.c)(13),{messages:i,onOpen:r}=e,{t:o}=(0,Z.useTranslation)("paletteOs");if(0===i.length){let e,a;return l[0]!==o?(e=o("talk.noPosts","No posts yet. The first message starts one."),l[0]=o,l[1]=e):e=l[1],l[2]!==e?(a=(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:e})}),l[2]=e,l[3]=a):a=l[3],a}if(l[4]!==i||l[5]!==r||l[6]!==o){let e;l[8]!==r||l[9]!==o?(e=e=>(0,t.jsxs)("button",{className:"tlPost",onClick:()=>r(e),children:[(0,t.jsx)("div",{className:`tlAv${e.sender?.is_agent?" tlAv--bot":""}`,children:e.sender?.is_agent?(0,t.jsx)(ej.TlIcon,{n:"bot",size:13}):t8(e.sender?.name??"")}),(0,t.jsxs)("div",{className:"tlPostBody",children:[(0,t.jsxs)("header",{className:"tlRowHead",children:[(0,t.jsx)("span",{className:"tlWho",children:e.sender?.name??o("talk.you","You")}),(0,t.jsx)("span",{className:"tlWhen",children:t5(e.created_at)})]}),(0,t.jsx)("span",{className:"tlPostText",children:e.content.slice(0,220)}),(0,t.jsxs)("span",{className:"tlPostMeta",children:[o("talk.replies","{{count}} REPLIES",{count:e.reply_count}),e.reactions.length>0&&` \xb7 ${e.reactions.length}`]})]})]},e.id),l[8]=r,l[9]=o,l[10]=e):e=l[10],s=i.map(e),l[4]=i,l[5]=r,l[6]=o,l[7]=s}else s=l[7];return l[11]!==s?(n=(0,t.jsx)("div",{className:"tlForum",children:s}),l[11]=s,l[12]=n):n=l[12],n}function aw({rules:e,agents:a,onCreate:s,onToggle:n,onDelete:l}){let{t:i}=(0,Z.useTranslation)("paletteOs"),[o,d]=(0,r.useState)("message_contains"),[c,u]=(0,r.useState)("post_message"),[m,h]=(0,r.useState)(""),[p,g]=(0,r.useState)(""),[f,x]=(0,r.useState)(""),[b,v]=(0,r.useState)(!1),j="message_contains"===o?{text:m}:"reaction_added"===o?{emoji:m||"+1"}:{every_minutes:Number(m)||60},y="post_message"===c?{text:p}:"set_topic"===c?{topic:p}:"add_reaction"===c?{emoji:p||"+1"}:{agent_id:Number(f),prompt:p},w="run_agent"===c?!!(f&&p.trim()):!!p.trim(),k=async()=>{v(!0);try{await s({name:(m||i("talk.rules","RULES")).slice(0,60),trigger_kind:o,trigger_config:j,action_kind:c,action_config:y}),h(""),g("")}finally{v(!1)}};return(0,t.jsxs)("div",{className:"tlAuxScroll",children:[(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:i("talk.channelRules","CHANNEL RULES")})}),0===e.length&&(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:i("talk.noRules","No automation here yet.")})}),e.map(e=>(0,t.jsxs)("div",{className:`tlRuleRow${e.enabled?"":" off"}`,children:[(0,t.jsxs)("div",{className:"tlRuleBody",children:[(0,t.jsx)("span",{className:"tlRuleWhen",children:"message_contains"===e.trigger_kind?i("talk.ruleOnText",'When a message says "{{v}}"',{v:String(e.trigger_config.text??"")}):"reaction_added"===e.trigger_kind?i("talk.ruleOnReaction","When someone reacts :{{v}}:",{v:String(e.trigger_config.emoji??"")}):i("talk.ruleOnSchedule","Every {{v}} minutes",{v:String(e.trigger_config.every_minutes??60)})}),(0,t.jsxs)("span",{className:"tlRuleThen",children:["run_agent"===e.action_kind?i("talk.ruleRunAgent","run an agent"):"post_message"===e.action_kind?i("talk.rulePost","post a message"):"set_topic"===e.action_kind?i("talk.ruleTopic","set the topic"):i("talk.ruleReact","add a reaction")," · ",i("talk.ruleFires","{{count}} fires",{count:e.fire_count})]}),e.last_error&&(0,t.jsx)("span",{className:"tlRuleErr",children:e.last_error})]}),(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect tlRuleBtn","aria-pressed":e.enabled,onClick:()=>void n(e.id,!e.enabled),children:e.enabled?i("talk.ruleOn","ON"):i("talk.ruleOff","OFF")}),(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect tlRuleBtn","aria-label":i("talk.delete","Delete"),title:i("talk.delete","Delete"),onClick:()=>void l(e.id),children:(0,t.jsx)(ej.TlIcon,{n:"trash",size:15})})]},e.id)),(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:i("talk.newRule","NEW RULE")})}),(0,t.jsxs)("div",{className:"tlRuleForm",children:[(0,t.jsxs)("label",{className:"tlField",children:[(0,t.jsx)("span",{children:i("talk.ruleWhen","WHEN")}),(0,t.jsxs)("select",{className:"rlSelect",value:o,onChange:e=>d(e.target.value),children:[(0,t.jsx)("option",{value:"message_contains",children:i("talk.trigText","A message containsâ¦")}),(0,t.jsx)("option",{value:"reaction_added",children:i("talk.trigReaction","Someone reacts withâ¦")}),(0,t.jsx)("option",{value:"schedule",children:i("talk.trigSchedule","Every N minutes")})]}),(0,t.jsx)("input",{value:m,onChange:e=>h(e.target.value),placeholder:"schedule"===o?"60":"reaction_added"===o?"+1":"deploy"})]}),(0,t.jsxs)("label",{className:"tlField",children:[(0,t.jsx)("span",{children:i("talk.ruleThen","THEN")}),(0,t.jsxs)("select",{className:"rlSelect",value:c,onChange:e=>u(e.target.value),children:[(0,t.jsx)("option",{value:"post_message",children:i("talk.actPost","Post a message")}),(0,t.jsx)("option",{value:"run_agent",children:i("talk.actAgent","Ask an agent")}),(0,t.jsx)("option",{value:"add_reaction",children:i("talk.actReact","Add a reaction")}),(0,t.jsx)("option",{value:"set_topic",children:i("talk.actTopic","Set the topic")})]}),"run_agent"===c&&(0,t.jsxs)("select",{className:"rlSelect",value:f,onChange:e=>x(e.target.value),children:[(0,t.jsx)("option",{value:"",children:i("talk.pickAgent","Pick an agentâ¦")}),a.map(e=>(0,t.jsx)("option",{value:String(e.id),children:e.name},e.participant_id))]}),(0,t.jsx)("input",{value:p,onChange:e=>g(e.target.value),placeholder:"run_agent"===c?i("talk.actAgentHint","What should it do?"):"add_reaction"===c?"+1":"set_topic"===c?i("talk.actTopicHint","New topic"):i("talk.actPostHint","What to post")})]}),(0,t.jsx)("div",{className:"tlSheetFoot",children:(0,t.jsx)("button",{className:"po-btn po-btn--sm",disabled:!w||b,onClick:()=>void k(),children:i("talk.addRule","ADD RULE")})})]})]})}function ak({turns:e,loadTranscript:a,onResumed:s}){let{t:n}=(0,Z.useTranslation)("paletteOs"),[l,i]=(0,r.useState)(null),[o,d]=(0,r.useState)([]),[c,u]=(0,r.useState)(null),m=(0,r.useCallback)(async e=>{if(l===e)return void i(null);i(e),d([]),u(null);try{let t=await a(e);d(t.transcript??[]),u(t.error)}catch{u(n("talk.transcriptFailed","Could not load the transcript"))}},[l,a,n]);return(0,t.jsxs)("div",{className:"tlAuxScroll",children:[(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:n("talk.agentRuns","AGENT RUNS")})}),0===e.length&&(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:n("talk.noRuns","No agent has run here yet.")})}),e.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsxs)("button",{className:"tlRun",onClick:()=>void m(e.id),children:[(0,t.jsx)("span",{className:`tlRunDot tlRunDot--${e.status}`}),(0,t.jsx)("span",{className:"tlRunName",children:e.agent_name}),(0,t.jsx)("span",{className:"tlRunMeta",children:e.trigger_kind.toUpperCase()}),e.hop>0&&(0,t.jsx)("span",{className:"tlRunMeta",children:n("talk.hop","HOP {{n}}",{n:e.hop})}),(0,t.jsx)("span",{className:"tlRunMeta",children:"silent"===e.status?n("talk.silent","SILENT"):e.status.toUpperCase()}),(0,t.jsx)("span",{className:"tlRunMs",children:null!=e.latency_ms?`${Math.round(e.latency_ms/100)/10}s`:""})]}),e.resume_job_id&&(0,t.jsx)(X.ResumeJobButton,{jobId:e.resume_job_id,onResumed:s}),l===e.id&&(0,t.jsxs)("div",{className:"tlRunDetail",children:["silent"===e.status&&(0,t.jsx)("p",{className:"tlRunNote",children:n("talk.silentNote","This run finished without posting anything.")}),c&&(0,t.jsx)("p",{className:"tlRunNote tlRunNote--bad",children:c}),0===o.length&&!c&&(0,t.jsx)("p",{className:"tlRunNote",children:n("talk.noSteps","No tool calls were recorded.")}),o.map((e,a)=>(0,t.jsxs)("div",{className:"tlRunStep",children:[(0,t.jsx)("span",{className:"tlRunStepKind",children:e.event.toUpperCase()}),(0,t.jsx)("code",{children:String(e.data??"").slice(0,300)})]},a))]})]},e.id))]})}function aN(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N=(0,a.c)(72),{query:C,setQuery:S,hits:_,here:T,setHere:E,room:A,onOpen:R,status:D,onRetry:M,openingHit:I}=e,{t:O}=(0,Z.useTranslation)("paletteOs");N[0]!==O?(s=O("talk.search","SEARCH"),N[0]=O,N[1]=s):s=N[1],N[2]!==s?(n=(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:s})}),N[2]=s,N[3]=n):n=N[3],N[4]!==O?(l=O("talk.searchScope","Search scope"),N[4]=O,N[5]=l):l=N[5];let P=`spvTab${T?" on":""}`;N[6]!==E?(i=()=>E(!0),N[6]=E,N[7]=i):i=N[7],N[8]!==O?(r=O("talk.scopeHere","THIS CHANNEL"),N[8]=O,N[9]=r):r=N[9],N[10]!==T||N[11]!==P||N[12]!==i||N[13]!==r?(o=(0,t.jsx)("button",{type:"button","aria-pressed":T,className:P,onClick:i,children:r}),N[10]=T,N[11]=P,N[12]=i,N[13]=r,N[14]=o):o=N[14];let L=!T,F=`spvTab${!T?" on":""}`;if(N[15]!==E?(d=()=>E(!1),N[15]=E,N[16]=d):d=N[16],N[17]!==O?(c=O("talk.scopeEverywhere","EVERYWHERE"),N[17]=O,N[18]=c):c=N[18],N[19]!==d||N[20]!==c||N[21]!==L||N[22]!==F?(u=(0,t.jsx)("button",{type:"button","aria-pressed":L,className:F,onClick:d,children:c}),N[19]=d,N[20]=c,N[21]=L,N[22]=F,N[23]=u):u=N[23],N[24]!==u||N[25]!==l||N[26]!==o?(m=(0,t.jsxs)("div",{className:"spvTabs",role:"group","aria-label":l,children:[o,u]}),N[24]=u,N[25]=l,N[26]=o,N[27]=m):m=N[27],N[28]===Symbol.for("react.memo_cache_sentinel")?(h=(0,t.jsx)(t$,{n:"search",size:16}),N[28]=h):h=N[28],N[29]!==O?(p=O("talk.messageSearch","Search messages"),N[29]=O,N[30]=p):p=N[30],N[31]!==S?(g=e=>S(e.target.value),N[31]=S,N[32]=g):g=N[32],N[33]!==T||N[34]!==A||N[35]!==O?(f=T?O("talk.searchHerePlaceholder","Search {{room}}",{room:A}):O("talk.searchPlaceholder","Search every channel you can see"),N[33]=T,N[34]=A,N[35]=O,N[36]=f):f=N[36],N[37]!==C||N[38]!==p||N[39]!==g||N[40]!==f?(x=(0,t.jsx)("div",{className:"tlSearchRow",children:(0,t.jsxs)("label",{className:"poSearch",children:[h,(0,t.jsx)("input",{autoFocus:!0,t
29ype:"search",maxLength:200,"aria-label":p,value:C,onChange:g,placeholder:f})]})}),N[37]=C,N[38]=p,N[39]=g,N[40]=f,N[41]=x):x=N[41],N[42]!==D||N[43]!==O?(b="loading"===D&&(0,t.jsx)("p",{className:"tlAsideEmpty",role:"status",children:O("talk.searching","Searchingâ¦")}),N[42]=D,N[43]=O,N[44]=b):b=N[44],N[45]!==M||N[46]!==D||N[47]!==O?(v="error"===D&&(0,t.jsxs)("div",{className:"tlAsideEmpty",children:[(0,t.jsx)("p",{role:"alert",children:O("talk.searchFailed","Could not search messages.")}),(0,t.jsx)("button",{type:"button",className:"btn",onClick:M,children:O("talk.retryDirectory","Retry")})]}),N[45]=M,N[46]=D,N[47]=O,N[48]=v):v=N[48],N[49]!==D||N[50]!==O?(j="idle"===D&&(0,t.jsx)("p",{className:"tlAsideEmpty",children:O("talk.searchMinLength","Enter at least two characters to search.")}),N[49]=D,N[50]=O,N[51]=j):j=N[51],N[52]!==_.length||N[53]!==D||N[54]!==O?(y="ready"===D&&0===_.length&&(0,t.jsx)("div",{className:"tlAsideEmpty",role:"status",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:O("talk.noHits","Nothing matched.")})}),N[52]=_.length,N[53]=D,N[54]=O,N[55]=y):y=N[55],N[56]!==_||N[57]!==R||N[58]!==I){let e;N[60]!==R||N[61]!==I?(e=e=>(0,t.jsxs)("button",{className:"tlInboxRow",disabled:null!==I,"aria-busy":I===e.id,onClick:()=>R(e),children:[(0,t.jsx)("div",{className:`tlAv tlAv--sm${e.sender?.is_agent?" tlAv--bot":""}`,children:e.sender?.is_agent?(0,t.jsx)(ej.TlIcon,{n:"bot",size:11}):t8(e.sender?.name??"")}),(0,t.jsxs)("div",{className:"tlRowBody",children:[(0,t.jsxs)("header",{className:"tlRowHead",children:[(0,t.jsx)("span",{className:"tlWho",children:e.sender?.name??""}),(0,t.jsx)("span",{className:"tlWhen",children:e.channel_name??""}),(0,t.jsx)("span",{className:"tlWhen",children:t5(e.created_at)})]}),(0,t.jsx)("span",{className:"tlInboxText",children:e.content.slice(0,120)})]})]},e.id),N[60]=R,N[61]=I,N[62]=e):e=N[62],w=_.map(e),N[56]=_,N[57]=R,N[58]=I,N[59]=w}else w=N[59];return N[63]!==m||N[64]!==x||N[65]!==b||N[66]!==n||N[67]!==v||N[68]!==j||N[69]!==y||N[70]!==w?(k=(0,t.jsxs)("div",{className:"tlAuxScroll",children:[n,m,x,b,v,j,y,w]}),N[63]=m,N[64]=x,N[65]=b,N[66]=n,N[67]=v,N[68]=j,N[69]=y,N[70]=w,N[71]=k):k=N[71],k}function aC(e){let n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j=(0,a.c)(64),{scope:y,rows:w,onScope:k,onClose:N,onOpen:C,onJoin:S,onLeave:_}=e,{t:T}=(0,Z.useTranslation)("paletteOs"),[E,A]=(0,r.useState)("");if(j[0]!==E||j[1]!==N||j[2]!==S||j[3]!==_||j[4]!==C||j[5]!==k||j[6]!==w||j[7]!==y||j[8]!==T){let e,a,r,f,x,b,v,R;j[20]!==E?(e=e=>e.name.toLowerCase().includes(E.trim().toLowerCase()),j[20]=E,j[21]=e):e=j[21];let D=w.filter(e);n=s.OverlayPortal,g="tlBrowseScrim",i=N,c="tlBrowse",u=aS,j[22]!==T?(a=T("talk.addChannel","ADD A CHANNEL"),j[22]=T,j[23]=a):a=j[23],j[24]!==a?(m=(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:a})}),j[24]=a,j[25]=m):m=j[25],j[26]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)(t$,{n:"search",size:16}),j[26]=r):r=j[26],j[27]===Symbol.for("react.memo_cache_sentinel")?(f=e=>A(e.target.value),j[27]=f):f=j[27],j[28]!==T?(x=T("talk.filterChannels","Filter channels"),j[28]=T,j[29]=x):x=j[29],j[30]!==T?(b=T("talk.filterChannels","Filter channels"),j[30]=T,j[31]=b):b=j[31],j[32]!==E||j[33]!==x||j[34]!==b?(h=(0,t.jsx)("div",{className:"tlSearchRow",children:(0,t.jsxs)("label",{className:"poSearch",children:[r,(0,t.jsx)("input",{autoFocus:!0,t
29ype:"search",value:E,onChange:f,placeholder:x,"aria-label":b})]})}),j[32]=E,j[33]=x,j[34]=b,j[35]=h):h=j[35],j[36]===Symbol.for("react.memo_cache_sentinel")?(v=["all","joined","archived"],j[36]=v):v=j[36],j[37]!==k||j[38]!==y||j[39]!==T?(p=(0,t.jsx)("div",{className:"tlBrowseScope",role:"tablist",children:v.map(e=>(0,t.jsx)("button",{role:"tab","aria-selected":y===e,className:`spvTab${y===e?" on":""}`,onClick:()=>k(e),children:"all"===e?T("talk.scopeAll","ALL"):"joined"===e?T("talk.scopeJoined","JOINED"):T("talk.scopeArchived","ARCHIVED")},e))}),j[37]=k,j[38]=y,j[39]=T,j[40]=p):p=j[40],l="tlBrowseList",o=0===D.length&&(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:T("talk.noChannelsHere","Nothing here.")})}),j[41]!==S||j[42]!==_||j[43]!==C||j[44]!==T?(R=e=>(0,t.jsxs)("div",{className:"tlBrowseRow",children:[(0,t.jsx)(ej.TlIcon,{n:"private"===e.visibility?"lock":"hash",size:12}),(0,t.jsxs)("div",{className:"tlBrowseBody",children:[(0,t.jsx)("button",{className:"tlBrowseName",onClick:()=>C(e.id),children:e.name}),(0,t.jsxs)("span",{className:"tlBrowseMeta",children:[T("talk.memberCount","{{count}} members",{count:e.member_count}),e.description?` \xb7 ${e.description}`:""]})]}),e.joined?(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect",onClick:()=>void _(e.id),children:T("talk.leaveShort","LEAVE")}):(0,t.jsx)("button",{className:"po-btn po-btn--sm",onClick:()=>void S(e.id),children:T("talk.join","JOIN")})]},e.id),j[41]=S,j[42]=_,j[43]=C,j[44]=T,j[45]=R):R=j[45],d=D.map(R),j[0]=E,j[1]=N,j[2]=S,j[3]=_,j[4]=C,j[5]=k,j[6]=w,j[7]=y,j[8]=T,j[9]=n,j[10]=l,j[11]=i,j[12]=o,j[13]=d,j[14]=c,j[15]=u,j[16]=m,j[17]=h,j[18]=p,j[19]=g}else n=j[9],l=j[10],i=j[11],o=j[12],d=j[13],c=j[14],u=j[15],m=j[16],h=j[17],p=j[18],g=j[19];return j[46]!==l||j[47]!==o||j[48]!==d?(f=(0,t.jsxs)("div",{className:l,children:[o,d]}),j[46]=l,j[47]=o,j[48]=d,j[49]=f):f=j[49],j[50]!==f||j[51]!==c||j[52]!==u||j[53]!==m||j[54]!==h||j[55]!==p?(x=(0,t.jsxs)("div",{className:c,onClick:u,children:[m,h,p,f]}),j[50]=f,j[51]=c,j[52]=u,j[53]=m,j[54]=h,j[55]=p,j[56]=x):x=j[56],j[57]!==i||j[58]!==x||j[59]!==g?(b=(0,t.jsx)("div",{className:g,onClick:i,children:x}),j[57]=i,j[58]=x,j[59]=g,j[60]=b):b=j[60],j[61]!==n||j[62]!==b?(v=(0,t.jsx)(n,{children:b}),j[61]=n,j[62]=b,j[63]=v):v=j[63],v}function aS(e){return e.stopPropagation()}function a_(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j=(0,a.c)(50),{inbox:y,digest:w,onOpen:k}=e,{t:N}=(0,Z.useTranslation)("paletteOs");if(j[0]!==N?(s=N("talk.activity","Activity"),j[0]=N,j[1]=s):s=j[1],j[2]!==s?(n=(0,t.jsx)("header",{className:"tlHbHead",children:(0,t.jsx)("h1",{className:"tlHbTitle",children:s})}),j[2]=s,j[3]=n):n=j[3],j[4]!==N?(l=N("talk.heroInbox","See what has your name on it"),j[4]=N,j[5]=l):l=j[5],j[6]!==l?(i=(0,t.jsx)("div",{className:"tlHbSub",children:l}),j[6]=l,j[7]=i):i=j[7],j[8]!==w.unread_total||j[9]!==N?(r=N("talk.digestUnread","{{count}} unread",{count:w.unread_total}),j[8]=w.unread_total,j[9]=N,j[10]=r):r=j[10],j[11]!==r?(o=(0,t.jsx)("span",{children:r}),j[11]=r,j[12]=o):o=j[12],j[13]!==w.busiest||j[14]!==k){let e;j[16]!==k?(e=e=>(0,t.jsxs)("button",{onClick:()=>k(e.channel_id),children:["#",e.name||"dm"," · ",e.messages]},e.channel_id),j[16]=k,j[17]=e):e=j[17],d=w.busiest.slice(0,3).map(e),j[13]=w.busiest,j[14]=k,j[15]=d}else d=j[15];return j[18]!==w.agent_runs?(c=w.agent_runs.map(aT),j[18]=w.agent_runs,j[19]=c):c=j[19],j[20]!==o||j[21]!==d||j[22]!==c?(u=(0,t.jsxs)("div",{className:"tlDigest",children:[o,d,c]}),j[20]=o,j[21]=d,j[22]=c,j[23]=u):u=j[23],j[24]!==N?(m=N("talk.mentionsOfYou","MENTIONS OF YOU"),j[24]=N,j[25]=m):m=j[25],j[26]!==m?(h=(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:m})}),j[26]=m,j[27]=h):h=j[27],j[28]!==y.mentions||j[29]!==k||j[30]!==N?(p=0===y.mentions.length?(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:N("talk.noMentions","Nothing has your name on it.")})}):(0,t.jsx)("div",{className:"tlHbCard",children:y.mentions.map(e=>(0,t.jsxs)("button",{className:"tlInboxRow",onClick:()=>k(e.channel_id),children:[(0,t.jsx)("div",{className:`tlAv tlAv--sm${e.sender?.is_agent?" tlAv--bot":""}`,children:e.sender?.is_agent?(0,t.jsx)(ej.TlIcon,{n:"bot",size:11}):t8(e.sender?.name??"")}),(0,t.jsxs)("div",{className:"tlRowBody",children:[(0,t.jsxs)("header",{className:"tlRowHead",children:[(0,t.jsx)("span",{className:"tlWho",children:e.sender?.name??""}),(0,t.jsx)("span",{className:"tlWhen",children:t5(e.created_at)})]}),(0,t.jsx)("span",{className:"tlInboxText",children:e.content.slice(0,110)})]})]},e.id))}),j[28]=y.mentions,j[29]=k,j[30]=N,j[31]=p):p=j[31],j[32]!==N?(g=N("talk.unreadRooms","UNREAD"),j[32]=N,j[33]=g):g=j[33],j[34]!==g?(f=(0,t.jsx)("div",{className:"tlAuxReg",children:(0,t.jsx)("span",{children:g})}),j[34]=g,j[35]=f):f=j[35],j[36]!==y.unread||j[37]!==k||j[38]!==N?(x=0===y.unread.length?(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:N("talk.allRead","Everything is read.")})}):(0,t.jsx)("div",{className:"tlHbCard",children:y.unread.map(e=>(0,t.jsxs)("button",{className:"tlAddRow",onClick:()=>k(e.channel_id),children:[(0,t.jsx)(ej.TlIcon,{n:"hash",size:14}),(0,t.jsx)("span",{className:"tlRoomN",children:e.name||N("talk.directMessage","Direct message")}),(0,t.jsx)("span",{className:"tlRoomC",children:e.count})]},e.channel_id))}),j[36]=y.unread,j[37]=k,j[38]=N,j[39]=x):x=j[39],j[40]!==h||j[41]!==p||j[42]!==f||j[43]!==x?(b=(0,t.jsxs)("div",{className:"tlHbList",children:[h,p,f,x]}),j[40]=h,j[41]=p,j[42]=f,j[43]=x,j[44]=b):b=j[44],j[45]!==b||j[46]!==n||j[47]!==i||j[48]!==u?(v=(0,t.jsxs)("div",{className:"tlHbPane",children:[n,i,u,b]}),j[45]=b,j[46]=n,j[47]=i,j[48]=u,j[49]=v):v=j[49],v}function aT(e){return(0,t.jsxs)("span",{className:"tlDigestRun",children:[e.status.toUpperCase()," ",e.count]},e.status)}function aE(e){let s,n,l,i,r,o,d,c,u,m,h,p,g=(0,a.c)(32),{message:f,onReply:x,onCopy:b,onOpenPicker:v}=e,{t:j}=(0,Z.useTranslation)("paletteOs");return g[0]!==f||g[1]!==x||g[2]!==j?(s=x&&(0,t.jsx)("button",{onClick:()=>x(f),title:j("talk.reply","Reply"),"aria-label":j("talk.reply","Reply"),children:(0,t.jsx)(t$,{n:"reply",size:14})}),g[0]=f,g[1]=x,g[2]=j,g[3]=s):s=g[3],g[4]!==f||g[5]!==b?(n=()=>b(f),g[4]=f,g[5]=b,g[6]=n):n=g[6],g[7]!==j?(l=j("talk.copyMessage","Copy message"),g[7]=j,g[8]=l):l=g[8],g[9]!==j?(i=j("talk.copyMessage","Copy message"),g[9]=j,g[10]=i):i=g[10],g[11]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)(t$,{n:"copy",size:14}),g[11]=r):r=g[11],g[12]!==n||g[13]!==l||g[14]!==i?(o=(0,t.jsx)("button",{onClick:n,title:l,"aria-label":i,children:r}),g[12]=n,g[13]=l,g[14]=i,g[15]=o):o=g[15],g[16]!==j?(d=j("talk.addReaction","Add reaction"),g[16
29]=j,g[17]=d):d=g[17],g[18]!==j?(c=j("talk.addReaction","Add reaction"),g[18]=j,g[19]=c):c=g[19],g[20]!==f||g[21]!==v?(u=e=>{e.currentTarget.focus(),v(f,e.currentTarget.getBoundingClientRect())},g[20]=f,g[21]=v,g[22]=u):u=g[22],g[23]===Symbol.for("react.memo_cache_sentinel")?(m=(0,t.jsx)(t$,{n:"smile",size:14}),g[23]=m):m=g[23],g[24]!==d||g[25]!==c||g[26]!==u?(h=(0,t.jsx)("button",{title:d,"aria-label":c,onClick:u,children:m}),g[24]=d,g[25]=c,g[26]=u,g[27]=h):h=g[27],g[28]!==s||g[29]!==h||g[30]!==o?(p=(0,t.jsxs)("div",{className:"tlActions",children:[s,o,h]}),g[28]=s,g[29]=h,g[30]=o,g[31]=p):p=g[31],p}function aA(e){let s,n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D,M,I,O,P,L,F,$,B,H,z,U,G,W,K,V,Y,q,J,X,Q,ee,et,ea,en,el,ei=(0,a.c)(178),{root:er,messages:eo,draft:ed,setDraft:ec,customEmoji:eu,onBack:em,loadThread:eh,focusMessageId:ep,onSend:eg,onVoice:ef,onReact:ex,onOpenPicker:eb,onCopy:ev,onMenu:ey}=e,{t:ew}=(0,Z.useTranslation)("paletteOs"),ek=(0,r.useRef)(null),eN=(0,r.useRef)(null);ei[0]===Symbol.for("react.memo_cache_sentinel")?(s=[],ei[0]=s):s=ei[0];let[eC,eS]=(0,r.useState)(s);ei[1]===Symbol.for("react.memo_cache_sentinel")?(n=[],ei[1]=n):n=ei[1];let[e_,eT]=(0,r.useState)(n),[eE,eA]=(0,r.useState)(null),[eR,eD]=(0,r.useState)(!1),[eM,eI]=(0,r.useState)("loading"),eO=(0,r.useRef)(null),eP=(0,r.useRef)(null);ei[2]!==ep?(l=()=>{if(!ep||eP.current===ep)return;let e=Array.from(eO.current?.querySelectorAll("[data-thread-message]")??[]).find(e=>e.dataset.threadMessage===ep);e&&(eP.current=ep,e.focus({preventScroll:!0}),e.scrollIntoView({block:"center",behavior:"auto"}))},ei[2]=ep,ei[3]=l):l=ei[3],ei[4]!==ep||ei[5]!==eo?(i=[ep,eo],ei[4]=ep,ei[5]=eo,ei[6]=i):i=ei[6],(0,r.useEffect)(l,i);let[eL,eF]=(0,r.useState)(0),e$=er?.id;ei[7]!==eh||ei[8]!==e$?(o=()=>{if(!e$)return;let e=!0;return eI("loading"),eh(e$).then(()=>{e&&eI("ready")},()=>{e&&eI("error")}),()=>{e=!1}},ei[7]=eh,ei[8]=e$,ei[9]=o):o=ei[9],ei[10]!==eL||ei[11]!==eh||ei[12]!==e$?(d=[e$,eh,eL],ei[10]=eL,ei[11]=eh,ei[12]=e$,ei[13]=d):d=ei[13],(0,r.useEffect)(o,d),ei[14]===Symbol.for("react.memo_cache_sentinel")?(c=e=>{e&&eS(t=>[...t,...Array.from(e)].slice(0,10))},ei[14]=c):c=ei[14];let eB=c;ei[15]!==eC||ei[16]!==eg||ei[17]!==e_?(u=()=>{eg(eC,e_),eS([]),eT([])},ei[15]=eC,ei[16]=eg,ei[17]=e_,ei[18]=u):u=ei[18];let eH=u;if(!er){let e,a,s,n,l,i,r,o;return ei[19]!==ew?(e=ew("talk.thread","Thread"),ei[19]=ew,ei[20]=e):e=ei[20],ei[21]!==em||ei[22]!==ew?(a=em&&(0,t.jsxs)("button",{className:"tlAuxBack",onClick:em,children:[(0,t.jsx)(ej.TlIcon,{n:"chev",size:13,cls:"tlBackChev"}),(0,t.jsx)("span",{children:ew("talk.threadsReg","ALL THREADS")})]}),ei[21]=em,ei[22]=ew,ei[23]=a):a=ei[23],ei[24]!==ew?(s=ew("talk.thread","THREAD"),ei[24]=ew,ei[25]=s):s=ei[25],ei[26]!==s?(n=(0,t.jsx)("span",{children:s}),ei[26]=s,ei[27]=n):n=ei[27],ei[28]!==a||ei[29]!==n?(l=(0,t.jsxs)("div",{className:"tlAuxReg",children:[a,n]}),ei[28]=a,ei[29]=n,ei[30]=l):l=ei[30],ei[31]!==ew?(i=ew("talk.noThread","Reply to a message to open its thread."),ei[31]=ew,ei[32]=i):i=ei[32],ei[33]!==i?(r=(0,t.jsx)("div",{className:"tlAsideEmpty",children:(0,t.jsx)("span",{className:"rlEmptyLead",children:i})}),ei[33]=i,ei[34]=r):r=ei[34],ei[35]!==l||ei[36]!==r||ei[37]!==e?(o=(0,t.jsxs)("div",{className:"tlAuxScroll",ref:eO,tabIndex:-1,role:"region","aria-label":e,children:[l,r]}),ei[35]=l,ei[36]=r,ei[37]=e,ei[38]=o):o=ei[38],o}if(ei[39]!==ew?(m=ew("talk.thread","Thread"),ei[39]=ew,ei[40]=m):m=ei[40],ei[41]!==em||ei[42]!==ew?(h=em&&(0,t.jsxs)("button",{className:"tlAuxBack",onClick:em,children:[(0,t.jsx)(ej.TlIcon,{n:"chev",size:13,cls:"tlBackChev"}),(0,t.jsx)("span",{children:ew("talk.threadsReg","ALL THREADS")})]}),ei[41]=em,ei[42]=ew,ei[43]=h):h=ei[43],ei[44]!==ew?(p=ew("talk.thread","THREAD"),ei[44]=ew,ei[45]=p):p=ei[45],ei[46]!==p?(g=(0,t.jsx)("span",{children:p}),ei[46]=p,ei[47]=g):g=ei[47],ei[48]!==h||ei[49]!==g?(f=(0,t.jsxs)("div",{className:"tlAuxReg",children:[h,g]}),ei[48]=h,ei[49]=g,ei[50]=f):f=ei[50],ei[51]!==eM||ei[52]!==ew?(x="loading"===eM&&(0,t.jsx)("p",{className:"tlPickStatus",role:"status",children:ew("talk.loadingReplies")}
29),ei[51]=eM,ei[52]=ew,ei[53]=x):x=ei[53],ei[54]!==eM||ei[55]!==ew?(b="error"===eM&&(0,t.jsxs)("div",{className:"tlPickError",role:"alert",children:[(0,t.jsx)("p",{children:ew("talk.loadRepliesFailed")}),(0,t.jsx)("button",{className:"tlBtn",onClick:()=>{eO.current?.focus({preventScroll:!0}),eI("loading"),eF(aO)},children:ew("talk.retryDirectory","Retry")})]}),ei[54]=eM,ei[55]=ew,ei[56]=b):b=ei[56],ei[57]!==eM||ei[58]!==eo.length||ei[59]!==er?(v="loading"===eM&&eo.length<=1&&Array.from({length:Math.max(1,Math.min(er.reply_count??0,3))},aI),ei[57]=eM,ei[58]=eo.length,ei[59]=er,ei[60]=v):v=ei[60],ei[61]!==eo||ei[62]!==ev||ei[63]!==ey||ei[64]!==eb||ei[65]!==ex||ei[66]!==ew){let e;ei[68]!==ev||ei[69]!==ey||ei[70]!==eb||ei[71]!==ex||ei[72]!==ew?(e=e=>(0,t.jsxs)("article",{className:"tlRow tlRow--thread","data-thread-message":e.id,tabIndex:-1,onContextMenu:e.deleted_at?void 0:t=>{t.preventDefault(),ey(e,{x:t.clientX,y:t.clientY})},children:[(0,t.jsx)(e1,{actor:e.sender??{id:"?",name:"",is_agent:!1},size:29}),(0,t.jsxs)("div",{className:"tlRowBody",children:[(0,t.jsxs)("header",{className:"tlRowHead",children:[(0,t.jsx)("span",{className:"tlWho",children:e.sender?.name??ew("talk.you","You")}),(0,t.jsx)("span",{className:"tlWhen",children:t5(e.created_at)})]}),e.deleted_at?(0,t.jsx)("div",{className:"tlBodyText tlGone",children:ew("talk.deleted","Message deleted")}):(0,t.jsx)(ad,{content:e.content,children:e.attachments.length>0&&(0,t.jsx)(ar,{attachments:e.attachments})}),!e.deleted_at&&e.reactions.length>0&&(0,t.jsx)("div",{className:"tlMarks",children:e.reactions.map(a=>(0,t.jsxs)("button",{className:"tlMark",title:a.emoji,onClick:()=>ex(e,a.emoji),children:[(0,t.jsx)("em",{children:a.emoji}),a.count]},a.emoji))})]}),!e.deleted_at&&(0,t.jsx)(aE,{message:e,onOpenPicker:eb,onCopy:ev})]},e.id),ei[68]=ev,ei[69]=ey,ei[70]=eb,ei[71]=ex,ei[72]=ew,ei[73]=e):e=ei[73],j=eo.map(e),ei[61]=eo,ei[62]=ev,ei[63]=ey,ei[64]=eb,ei[65]=ex,ei[66]=ew,ei[67]=j}else j=ei[67];ei[74]!==f||ei[75]!==x||ei[76]!==b||ei[77]!==v||ei[78]!==j||ei[79]!==m?(y=(0,t.jsxs)("div",{className:"tlAuxScroll",ref:eO,tabIndex:-1,role:"region","aria-label":m,children:[f,x,b,v,j]}),ei[74]=f,ei[75]=x,ei[76]=b,ei[77]=v,ei[78]=j,ei[79]=m,ei[80]=y):y=ei[80];let ez=(eC.length>0||e_.length>0)&&(0,t.jsxs)("div",{className:"tlPending tlPending--slim",children:[eC.map((e,a)=>(0,t.jsx)(es,{name:e.name,mime:e.type,size:e.size,file:e,onRemove:()=>{eS(e=>e.filter((e,t)=>t!==a)),ek.current?.focus()}},`${e.name}:${a}`)),e_.map((e,a)=>(0,t.jsx)(es,{name:e.filename,mime:e.mime_type,size:e.file_size,url:e.file_url,onRemove:()=>{eT(e=>e.filter((e,t)=>t!==a)),ek.current?.focus()}},`room:${e.file_url}:${a}`))]});ei[81]!==eR||ei[82]!==eD?(w=eR&&(0,t.jsx)(t_.RoomPicker,{onClose:()=>eD(!1),onAttach:e=>eT(t=>[...t,...e].slice(0,t_.ROOM_PICK_MAX))}),ei[81]=eR,ei[82]=eD,ei[83]=w):w=ei[83];let eU=eE&&(0,t.jsx)(tS,{anchor:eE,customEmoji:eu,onPick:e=>{eA(null),"sticker"!==e.type&&ek.current?.insert("custom"===e.type?`:${e.code}:`:e.value)},onClose:()=>eA(null)});ei[84]!==ew?(k=ew("talk.formatting","Formatting"),ei[84]=ew,ei[85]=k):k=ei[85];let eG=t0.map(e=>(0,t.jsx)("button",{className:`tlFmtBtn${e.sep?" tlFmtBtn--group":""}`,title:`${tQ(ew,e.id)} ${t1}${e.keys}`,"aria-label":tQ(ew,e.id),onMouseDown:aM,onClick:()=>ek.current?.format(e.id),children:(0,t.jsx)(ej.TlIcon,{n:e.icon,size:15})},e.id));ei[86]!==k||ei[87]!==eG?(N=(0,t.jsx)("div",{className:"tlFmtBar",role:"toolbar","aria-label":k,children:eG}),ei[86]=k,ei[87]=eG,ei[88]=N):N=ei[88],ei[89]!==ew?(C=ew("talk.replyPlaceholder","Reply in thread"),ei[89]=ew,ei[90]=C):C=ei[90],ei[91]!==ew?(S=ew("talk.replyPlaceholder","Reply in thread"),ei[91]=ew,ei[92]=S):S=ei[92],ei[93]!==eB||ei[94]!==ed||ei[95]!==ek||ei[96]!==eH||ei[97]!==ec||ei[98]!==C||ei[99]!==S?(_=(0,t.jsx)("div",{className:"cdMain",children:(0,t.jsx)(tg,{ref:ek,value:ed,onChange:ec,onMention:aD,ariaLabel:C,placeholder:S,onSubmit:eH,onFiles:eB})}),ei[93]=eB,ei[94]=ed,ei[95]=ek,ei[96]=eH,ei[97]=ec,ei[98]=C,ei[99]=S,ei[100]=_):_=ei[100],ei[101]!==ew?(T=ew("talk.attach","Attach a file"),ei[101]=ew,ei[102]=T):T=ei[102],ei[103]!==ew?(E=ew("talk.attach","Attach a file"),ei[103]=ew,ei[104]=E):E=ei[104],ei[105]===Symbol.for("react.memo_cache_sentinel")?(A=()=>eN.current?.click(),R=(0,t.jsx)(ej.TlIcon,{n:"plus",size:16}),ei[105]=A,ei[106]=R):(A=ei[105],R=ei[106]),ei[107]!==T||ei[108]!==E?(D=(0,t.jsx)("button",{className:"cdIcon",title:T,"aria-label":E,onClick:A,children:R}),ei[107]=T,ei[108]=E,ei[109]=D):D=ei[109],ei[110]!==eB?(M=(0,t.jsx)("input",{ref:eN,type:"file",multiple:!0,hidden:!0,accept:tF,onChange:e=>{eB(e.target.files),e.target.value=""}}),ei[110]=eB,ei[111]=M):M=ei[111],ei[112]!==ew?(I=ew("talk.emojiPicker","Emoji and stickers"),ei[112]=ew,ei[113]=I):I=ei[113],ei[114]!==ew?(O=ew("talk.emojiPicker","Emoji and stickers"),ei[114]=ew,ei[115]=O):O=ei[115],ei[116]!==eA?(P=e=>eA({rect:e.currentTarget.getBoundingClientRect(),place:"above"}),ei[116]=eA,ei[117]=P):P=ei[117],ei[118]===Symbol.for("react.memo_cache_sentinel")?(L=(0,t.jsx)(ej.TlIcon,{n:"smile",size:16}),ei[118]=L):L=ei[118],ei[119]!==I||ei[120]!==O||ei[121]!==P?(F=(0,t.jsx)("button",{className:"cdIcon",title:I,"aria-label":O,onClick:P,children:L}),ei[119]=I,ei[120]=O,ei[121]=P,ei[122]=F):F=ei[122],ei[123]!==ew?($=ew("talk.mention","Mention someone"),ei[123]=ew,ei[124]=$):$=ei[124],ei[125]!==ew?(B=ew("talk.mention","Mention someone"),ei[125]=ew,ei[126]=B):B=ei[126],ei[127]!==ek?(H=()=>ek.current?.insert("@"),ei[127]=ek,ei[128]=H):H=ei[128],ei[129]===Symbol.for("react.memo_cache_sentinel")?(z=(0,t.jsx)(ej.TlIcon,{n:"at",size:16}),ei[129]=z):z=ei[129],ei[130]!==$||ei[131]!==B||ei[132]!==H?(U=(0,t.jsx)("button",{className:"cdIcon",title:$,"aria-label":B,onClick:H,children:z}),ei[130]=$,ei[131]=B,ei[132]=H,ei[133]=U):U=ei[133],ei[134]!==ew?(G=ew("talk.attachFromRoom","Attach from Drive"),ei[134]=ew,ei[135]=G):G=ei[135],ei[136]!==ew?(W=ew("talk.attachFromRoom","Attach from Drive"),ei[136]=ew,ei[137]=W):W=ei[137],ei[138]!==eD?(K=()=>eD(aR),ei[138]=eD,ei[139]=K):K=ei[139],ei[140]===Symbol.for("react.memo_cache_sentinel")?(V=(0,t.jsx)(ej.TlIcon,{n:"folder",size:16}),ei[140]=V):V=ei[140],ei[141]!==G||ei[142]!==W||ei[143]!==K?(Y=(0,t.jsx)("button",{className:"cdIcon",title:G,"aria-label":W,onClick:K,children:V}),ei[141]=G,ei[142]=W,ei[143]=K,ei[144]=Y):Y=ei[144];let eW=er?.id;
29return ei[145]!==ef||ei[146]!==eW?(q=(0,t.jsx)(tT.MicButton,{onNote:ef},eW),ei[145]=ef,ei[146]=eW,ei[147]=q):q=ei[147],ei[148]===Symbol.for("react.memo_cache_sentinel")?(J=(0,t.jsx)("span",{className:"tlFmtGap"}),ei[148]=J):J=ei[148],ei[149]!==ed||ei[150]!==eC.length||ei[151]!==e_?(X=!ed.trim()&&0===eC.length&&0===e_.length,ei[149]=ed,ei[150]=eC.length,ei[151]=e_,ei[152]=X):X=ei[152],ei[153]!==ew?(Q=ew("talk.send","SEND"),ei[153]=ew,ei[154]=Q):Q=ei[154],ei[155]===Symbol.for("react.memo_cache_sentinel")?(ee=(0,t.jsx)(ej.TlIcon,{n:"send",size:15}),ei[155]=ee):ee=ei[155],ei[156]!==eH||ei[157]!==X||ei[158]!==Q?(et=(0,t.jsxs)("button",{className:"cdSend",onClick:eH,disabled:X,children:[Q,ee]}),ei[156]=eH,ei[157]=X,ei[158]=Q,ei[159]=et):et=ei[159],ei[160]!==D||ei[161]!==M||ei[162]!==F||ei[163]!==U||ei[164]!==Y||ei[165]!==q||ei[166]!==et?(ea=(0,t.jsxs)("div",{className:"tlComposerTools",children:[D,M,F,U,Y,q,J,et]}),ei[160]=D,ei[161]=M,ei[162]=F,ei[163]=U,ei[164]=Y,ei[165]=q,ei[166]=et,ei[167]=ea):ea=ei[167],ei[168]!==N||ei[169]!==_||ei[170]!==ea?(en=(0,t.jsxs)("div",{className:"chatComposer tlCompose tlCompose--slim",children:[N,_,ea]}),ei[168]=N,ei[169]=_,ei[170]=ea,ei[171]=en):en=ei[171],ei[172]!==y||ei[173]!==ez||ei[174]!==w||ei[175]!==eU||ei[176]!==en?(el=(0,t.jsxs)(t.Fragment,{children:[y,ez,w,eU,en]}),ei[172]=y,ei[173]=ez,ei[174]=w,ei[175]=eU,ei[176]=en,ei[177]=el):el=ei[177],el}function aR(e){return!e}function aD(){}function aM(e){return e.preventDefault()}function aI(e,a){return(0,t.jsxs)("div",{className:"tlRowSkel tlRow--thread","aria-hidden":!0,children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:"38%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${52+17*a%30}%`}})]})]},`skel:${a}`)}function aO(e){return e+1}e.s(["TalkView",0,function({initialChannelId:e=null,router:a,syncUrl:n=!1}={}){let{t:i}=(0,Z.useTranslation)("paletteOs"),{talkSeed:o,setTalkSeed:d,urlSync:c}=(0,ed.useViewContext)(),u=function(){let[e,t]=(0,r.useState)([]),[a,s]=(0,r.useState)({}),[n,l]=(0,r.useState)(null),[i,o]=(0,r.useState)([]),[d,c]=(0,r.useState)([]),[u,m]=(0,r.useState)({people:[],agents:[]}),[h,p]=(0,r.useState)(!0),[g,f]=(0,r.useState)(null),x=(0,r.useRef)(null),[b,v]=(0,r.useState)([]),[j,y]=(0,r.useState)([]),[w,k]=(0,r.useState)([]),[N,C]=(0,r.useState)({mentions:[],unread:[]}),[S,_]=(0,r.useState)(null),[T,E]=(0,r.useState)([]),[A,R]=(0,r.useState)([]),[D,M]=(0,r.useState)({}),[I,O]=(0,r.useState)(null),[P,L]=(0,r.useState)(null),[F,$]=(0,r.useState)({unread_total:0,busiest:[],agent_runs:[]}),[B,H]=(0,r.useState)([]),[z,U]=(0,r.useState)(!0),[G,W]=(0,r.useState)(!1),[K,V]=(0,r.useState)(null),[Y,q]=(0,r.useState)(null),[J,X]=(0,r.useState)(!1),[Z,Q]=(0,r.useState)(!1),ee=(0,r.useRef)(null),et=(0,r.useRef)(!1),[ea,es]=(0,r.useState)(!1),en=(0,r.useRef)(null),el=(0,r.useRef)(0);en.current=n;let ei=(0,r.useRef)([]);ei.current=e;let{user:er}=(0,eo.useAuth)(),ed=(0,r.useRef)(void 0);ed.current=er?.id;let ec=(0,r.useRef)(null);ec.current=er?{kind:"user",id:String(er.id),name:er.name||er.email,is_agent:!1}:null;let eu=(0,r.useCallback)(async()=>{U(!0),q(null);try{let e=await tL("/channels",{timeoutMs:15e3});return t(e.channels),s(e.participants??{}),e.huddles&&M(e.huddles),q(null),e.channels}catch(e){return q(e instanceof Error&&"TimeoutError"===e.name?tE.default.t("paletteOs:talk.noResponse","Talk did not respond"):e instanceof Error?e.message:tE.default.t("paletteOs:talk.loadChannelsFailed","Could not load channels")),[]}finally{U(!1)}},[]);(0,r.useEffect)(()=>{eu()},[eu]);let em=(0,r.useCallback)((e,t)=>{M(a=>{if(!t){if(!(e in a))return a;let t={...a};return delete t[e],t}return{...a,[e]:t}}),t||O(t=>t?.channelId===e?null:t)},[]);(0,r.useEffect)(()=>(0,tR.liveSource)(`${tM}/events`,{open:()=>es(!1),error:()=>es(!0),message:e=>{let a;try{a=JSON.parse(e.data)}catch{return}if("connected"===a.type)return void(0,tA.noteWorkspace)(a.organization_id);if("channel_created"===a.type&&a.channel)return void t(e=>e.some(e=>e.id===a.channel.id)?e:[a.channel,...e]);if("channel_updated"===a.type&&a.channel)return void t(e=>e.map(e=>
29e.id===a.channel.id?tI(e,a.channel):e));if("participants_changed"===a.type){let e=a.channel_id;eu().then(t=>{t.length&&e&&e===en.current&&!t.some(t=>t.id===e)&&l(null)});return}if("huddle"===a.type&&a.channel_id){let e=a.channel_id,t=a.huddle??null;em(e,t);let s=String(ed.current??""),n=t?.participants.some(e=>String(e.id)===s)??!1;a.started&&t&&!n&&(O({channelId:e,huddleId:t.id,actor:a.actor||""}),eb("ring"));return}if("channel_activity"===a.type&&a.channel_id){let e=a.channel_id,s=String(ed.current??""),n=a.sender?.kind==="user"&&String(a.sender.id)===s;if(e!==en.current&&!n&&a.sender){let t=ei.current.find(t=>t.id===e);t?.muted||eb(a.mentions?.some(e=>String(e)===s)||t?.channel_type==="dm"||t?.channel_type==="group_dm"?"mention":"ping")}let l=a.sender?{text:a.preview??"",sender:a.sender.name??"",sender_id:String(a.sender.id??""),is_agent:!!a.sender.is_agent,kind:"text"}:null;t(t=>t.map(t=>t.id!==e?t:{...t,unread:t.id===en.current?t.unread:t.unread+1,last_message:l??t.last_message,last_message_at:new Date().toISOString()}))}}}),[em,eu]);let eh=(0,r.useCallback)(e=>{e&&tL(`/channels/${e}/turns`).then(e=>{E(e.turns);let t=e.turns.filter(e=>"running"===e.status||"queued"===e.status);v(a=>{let s=t.map(e=>{let t=a.find(t=>t.turnId===e.id),s=e.partial??"";return t&&t.text.length>=s.length?t:{turnId:e.id,agentId:e.agent_id,text:s}}),n=a.filter(e=>e.outcome&&!t.some(t=>t.id===e.turnId)),l=e.turns[0],i=!l||"failed"!==l.status&&"silent"!==l.status||l.reply_message_id||n.some(e=>e.turnId===l.id)||s.some(e=>e.turnId===l.id)?[]:[{turnId:l.id,agentId:l.agent_id,text:"",outcome:l.status,error:l.error??void 0}];return[...n,...i,...s]})}).catch(()=>{})},[]),ep=(0,r.useCallback)(async e=>{let a=++el.current;if(ee.current=null,l(e),en.current=e,o([]),v([]),y([]),k([]),_(null),E([]),R([]),c([]),X(!1),W(!!e),e){t(t=>t.map(t=>t.id===e?{...t,unread:0}:t));try{let[s,n]=await Promise.all([tL(`/channels/${e}/messages`),tL(`/channels/${e}/participants`)]);if(en.current!==e||el.current!==a)return;ee.current=s.messages[0]?.created_at??null,o(e=>tO(e,s.messages)),X(s.has_more),c(n.participants);let l=ei.current.find(t=>t.id===e)?.unread??0;_(l>0&&s.messages.length>=l?s.messages[s.messages.length-l].id:null),W(!1),tL(`/channels/${e}/pins`).then(e=>k(e.messages)).catch(()=>k([])),eh(e),tL(`/channels/${e}/huddle`).then(t=>em(e,t.huddle)).catch(()=>{});let i=s.messages[s.messages.length-1];await tL(`/channels/${e}/read`,{method:"POST",body:JSON.stringify({last_read_message_id:i?.id??null})}).catch(()=>{}),t(t=>t.map(t=>t.id===e?{...t,unread:0}:t))}catch(s){if(en.current!==e||el.current!==a)return;W(!1);let t=s.status;if(404===t||403===t){en.current=null,l(null),V({id:e});return}q(s instanceof Error?s.message:tE.default.t("paletteOs:talk.openChannelFailed","Could not open the channel"))}}},[em]);(0,r.useEffect)(()=>{if(!n)return;let e=!1;return(0,tR.liveSource)(`${tM}/channels/${n}/events`,{message:e=>{let a;try{a=JSON.parse(e.data)}catch{return}switch(a.type){case"message":{let e=a.message,s=e.sender?.kind==="user"&&String(e.sender.id)===String(ed.current??"");o(t=>{let a=s?t.findIndex(t=>t.id.startsWith("pending:")&&t.content===e.content):-1;if(a>=0){let s=[...t];return s[a]=e,s}return t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e]}),e.sender?.is_agent&&v(t=>t.filter(t=>t.agentId!==e.sender.id)),t(e=>e.map(e=>e.id===n?{...e,unread:0}:e)),tL(`/channels/${n}/read`,{method:"POST",body:JSON.stringify({last_read_message_id:e.id})}).catch(()=>{});break}case"message_updated":o(e=>e.map(e=>e.id===a.message.id?a.message:e));break;case"message_deleted":{let e=a.message_id;o(t=>tP(t,e)),k(t=>t.filter(t=>t.id!==e));break}case"reactions":o(e=>e.map(e=>e.id===a.message_id?{...e,reactions:a.reactions}:e));break;case"agent_turn":{"running"!==a.status&&eh(n);let e=a.turn_id;if("running"===a.status){v(t=>[...t.filter(t=>t.turnId!==e),{turnId:e,agentId:a.agent_id,text:""}]);break}let t="failed"===a.status?"failed":"silent"===a.status?"silent":null;v(s=>null===t?s.filter(t=>t.turnId!==e):s.map(s=>s.turnId===e?{...s,outcome:t,error:a.error||void 0}:s));break}case"agent_token":v(e=>e.map(e=>e.turnId===a.turn_id?{...e,text:e.text+a.content}:e));break;
29case"typing":{if(String(a.user_id)===String(ed.current))break;let e=a.name||"";y(t=>t.includes(e)?t:[...t,e]),window.setTimeout(()=>y(t=>t.filter(t=>t!==e)),5e3);break}case"huddle":{let e=a.huddle??null;em(n,e),eD.current.onRoster(e);break}case"huddle_signal":eD.current.onSignal(a);break;case"rules_changed":tL(`/channels/${n}/rules`).then(e=>R(e.rules)).catch(()=>{});break;case"pins_changed":tL(`/channels/${n}/pins`).then(e=>k(e.messages)).catch(()=>{});break;case"participants_changed":tL(`/channels/${n}/participants`).then(e=>c(e.participants)).catch(()=>{})}},error:()=>es(!0),open:()=>{if(es(!1),!e){e=!0;return}eh(n),tL(`/channels/${n}/messages`).then(e=>o(t=>t.length?tO(t,e.messages):e.messages)).catch(()=>{})}})},[n,eh,em]),(0,r.useEffect)(()=>{if(P&&P!==n)return(0,tR.liveSource)(`${tM}/channels/${P}/events`,{message:e=>{let t;try{t=JSON.parse(e.data)}catch{return}if("huddle"===t.type){let e=t.huddle??null;em(P,e),eD.current.onRoster(e)}else"huddle_signal"===t.type&&eD.current.onSignal(t)}})},[P,n,em]);let eg=(0,r.useCallback)(async(e,t)=>{let a=en.current;if(!a||!e.trim()&&!t?.attachments?.length&&!t?.panelData)return;let s={id:`pending:${Date.now()}`,channel_id:a,content:e,message_type:"text",sender:ec.current,parent_message_id:t?.parentId??null,root_message_id:t?.parentId??null,reply_count:0,attachments:t?.attachments??[],mention_refs:t?.mentionRefs??[],panel_data:t?.panelData??null,reactions:[],edited_at:null,deleted_at:null,created_at:new Date().toISOString()};o(e=>[...e,s]);try{let n=await tL(`/channels/${a}/messages`,{method:"POST",body:JSON.stringify({content:e,parent_message_id:t?.parentId??null,mention_refs:t?.mentionRefs??[],attachments:t?.attachments??[],panel_data:t?.panelData??null})});o(e=>{let t=e.filter(e=>e.id!==n.id),a=t.findIndex(e=>e.id===s.id);if(a<0)return[...t,n];let l=[...t];return l[a]=n,l})}catch(e){o(e=>e.filter(e=>
29e.id!==s.id)),q(e instanceof Error?e.message:tE.default.t("paletteOs:talk.sendFailed","Could not send"))}},[]),ef=(0,r.useCallback)(async()=>{let e=en.current,t=el.current,a=ee.current;if(e&&a&&J&&!et.current){et.current=!0,Q(!0);try{let s=await tL(`/channels/${e}/messages?before=${encodeURIComponent(a)}`);if(en.current!==e||el.current!==t)return;ee.current=s.messages[0]?.created_at??a,o(e=>tO(e,s.messages)),X(s.has_more)}finally{et.current=!1,Q(!1)}}},[J]),ex=(0,r.useCallback)(async(e,t)=>{await tL(`/messages/${e}/reactions`,{method:"POST",body:JSON.stringify({emoji:t})})},[]),ev=(0,r.useCallback)(async e=>{let t=en.current;if(!t)throw Error(tE.default.t("paletteOs:talk.noChannelOpen","No channel open"));let a=new FormData;a.append("file",e);let s=await (0,tA.apiFetch)(`${tD}/channels/${t}/upload`,{method:"POST",body:a});if(!s.ok){let e=await s.json().then(e=>e?.detail).catch(()=>null);throw Error("string"==typeof e?e:`Upload failed (${s.status})`)}return await s.json()},[]),ej=(0,r.useCallback)(async()=>{try{let e=await tL("/custom-emoji");H(e.items??[])}catch{H([])}},[]);(0,r.useEffect)(()=>{ej()},[ej]);let ey=(0,r.useCallback)(async(e,t)=>{let a=new FormData;a.append("file",e),a.append("code",t.code),a.append("kind",t.kind),t.label&&a.append("label",t.label);let s=await (0,tA.apiFetch)(`${tD}/custom-emoji`,{method:"POST",body:a});if(!s.ok){let e=await s.json().catch(()=>null);throw Error("string"==typeof e?.detail?e.detail:tE.default.t("paletteOs:talk.uploadError","Upload failed"))}await ej()},[ej]),ew=(0,r.useCallback)(async e=>{await (0,tA.apiFetch)(`${tD}/custom-emoji/${e}`,{method:"DELETE"}),await ej()},[ej]),ek=(0,r.useCallback)(async(e,t)=>{await tL(`/messages/${e}`,{method:"PATCH",body:JSON.stringify({content:t})})},[]),eN=(0,r.useCallback)(async e=>{await tL(`/messages/${e}`,{method:"DELETE"}),o(t=>tP(t,e)),k(t=>t.filter(t=>t.id!==e))},[]),eC=(0,r.useCallback)(async e=>{await tL(`/messages/${e}/pin`,{method:"POST"})},[]),eS=(0,r.useCallback)(async(e="all")=>(await tL(`/browse?scope=${e}`)).channels,[]),e_=(0,r.useCallback)(async e=>{await tL(`/channels/${e}/join`,{method:"POST"}),await eu()},[eu]),eT=(0,r.useCallback)(async e=>{await tL(`/channels/${e}/leave`,{method:"POST"}),en.current===e&&await ep(null),await eu()},[eu,ep]),eE=(0,r.useCallback)(async(e,a)=>{t(t=>t.map(t=>t.id===e?{...t,...a}:t));try{return await tL(`/channels/${e}/prefs`,{method:"PATCH",body:JSON.stringify(a)}),!0}catch{return await eu(),!1}},[eu]),eA=(0,r.useCallback)(async(e,a)=>{let s=await tL(`/channels/${e}`,{method:"PATCH",body:JSON.stringify(a)});t(t=>t.map(t=>t.id===e?tI(t,s):t)),await eu()},[eu]),eR=(0,r.useCallback)(async(e,t)=>{if(e.trim().length<2)return[];let a=t?`&channel_id=${t}`:"";return(await tL(`/search?q=${encodeURIComponent(e)}${a}`)).results},[]),eD=(0,r.useRef)({stream:null,peers:new Map,audios:new Map,meters:new Map,audioCtx:null,channelId:null,onRoster:()=>{},onSignal:()=>{}}),[eM,eI]=(0,r.useState)(!1),[eO,eP]=(0,r.useState)(!1),[eL,eF]=(0,r.useState)([]),e$=(0,r.useCallback)((e,t,a)=>
29{let s=eD.current.channelId;s&&tL(`/channels/${s}/huddle/signal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({to_user_id:e,kind:t,payload:a})}).catch(()=>{})},[]),eB=(0,r.useCallback)((e,t)=>{let a=eD.current;try{let s=window.AudioContext??window.webkitAudioContext;if(!s)return;a.audioCtx??=new s;let n=a.audioCtx.createAnalyser();n.fftSize=512,a.audioCtx.createMediaStreamSource(t).connect(n),a.meters.set(e,{analyser:n,buffer:new Uint8Array(n.frequencyBinCount)})}catch{}},[]),eH=(0,r.useCallback)(e=>{let t=eD.current;t.peers.get(e)?.close(),t.peers.delete(e);let a=t.audios.get(e);a&&(a.srcObject=null,t.audios.delete(e)),t.meters.delete(e)},[]),ez=(0,r.useCallback)(()=>{let e=eD.current;for(let t of[...e.peers.keys()])eH(t);e.stream?.getTracks().forEach(e=>e.stop()),e.stream=null,e.meters.clear(),e.audioCtx?.close().catch(()=>{}),e.audioCtx=null,eI(!1),eP(!1),eF([])},[eH]),eU=(0,r.useCallback)(e=>{let t=eD.current,a=t.peers.get(e);return a||(a=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]}),t.stream?.getTracks().forEach(e=>a.addTrack(e,t.stream)),a.onicecandidate=t=>{t.candidate&&e$(e,"ice",t.candidate.toJSON())},a.ontrack=a=>{let s=t.audios.get(e);s||((s=new Audio).autoplay=!0,t.audios.set(e,s)),s.srcObject=a.streams[0],s.play().catch(()=>{}),eB(e,a.streams[0])},a.onconnectionstatechange=()=>{"failed"===a.connectionState&&eH(e)},t.peers.set(e,a)),a},[e$,eH,eB]),eG=(0,r.useCallback)(async e=>{let t=eU(e),a=await t.createOffer();await t.setLocalDescription(a),e$(e,"offer",{sdp:a.sdp,type:a.type})},[eU,e$]),eW=(0,r.useCallback)(e=>{let t=eD.current;if(!t.stream)return;let a=String(ed.current??""),s=new Set((e?.participants??[]).map(e=>String(e.id)).filter(e=>e!==a));for(let e of[...t.peers.keys()])s.has(e)||eH(e);for(let e of s)!t.peers.has(e)&&a<e&&eG(e)},[eH,eG]),eK=(0,r.useCallback)(async e=>{let t=String(ed.current??"");if(String(e.to_user_id)!==t)return;let a=eD.current;if(!a.stream)return;let s=String(e.from_user_id),n=e.payload;try{if("offer"===e.kind){let e=eU(s);await e.setRemoteDescription(n);let t=await e.createAnswer();await e.setLocalDescription(t),e$(s,"answer",{sdp:t.sdp,type:t.type})}else"answer"===e.kind?await a.peers.get(s)?.setRemoteDescription(n):"ice"===e.kind&&await a.peers.get(s)?.addIceCandidate(n)}catch{}},[eU,e$]),eV=(0,r.useCallback)(async e=>{ez(),eD.current.channelId=null,L(null);let t=await tL(`/channels/${e}/huddle`,{method:"DELETE"}).catch(()=>({huddle:null}));em(e,t.huddle)},[ez,em]),eY=(0,r.useCallback)(async e=>{let t=e??en.current;if(!t)return;eD.current.channelId&&eD.current.channelId!==t&&await eV(eD.current.channelId);let a=await tL(`/channels/${t}/huddle`,{method:"POST"});em(t,a.huddle),O(e=>e?.channelId===t?null:e),eD.current.channelId=t,L(t);let s=(a.huddle?.participants.length??1)-1;if(s>=0&&s<6&&"u">typeof RTCPeerConnection)try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});eD.current.stream=e,eI(!0),eB(String(ed.current??""),e),eW(a.huddle)}catch{}},[eW,em,eB,eV]),eq=(0,r.useCallback)(async()=>{let e=eD.current.channelId??en.current;e&&await eV(e)},[eV]),eJ=(0,r.useCallback)(()=>{let e=eD.current.stream;e&&eP(t=>(e.getAudioTracks().forEach(e=>{e.enabled=t}),!t))},[]);(0,r.useEffect)(()=>()=>{let e=eD.current.channelId;ez(),e&&(0,tA.apiFetch)(`${tD}/channels/${e}/huddle`,{method:"DELETE"}).catch(()=>{})},[ez]),(0,r.useEffect)(()=>{if(!eM)return;let e=0,t="",a=()=>{let s=[];for(let[e,{analyser:t,buffer:a}]of eD.current.meters){t.getByteTimeDomainData(a);let n=0;for(let e of a)n=Math.max(n,Math.abs(e-128));n>6&&s.push(e)}let n=s.sort().join(",");n!==t&&(t=n,eF(s)),e=window.requestAnimationFrame(a)};return e=window.requestAnimationFrame(a),()=>window.cancelAnimationFrame(e)},[eM]),eD.current.onRoster=eW,eD.current.onSignal=eK;let eX=(0,r.useRef)(""),eZ=P?D[P]??null:null;(0,r.useEffect)(()=>{let e=(eZ?.participants??[]).map(e=>String(e.id)).sort().join(","),t=eX.current;eX.current=e,t&&e&&t!==e&&eb(e.split(",").length>t.split(",").length?"join":"leave")},[eZ]);let eQ=(0,r.useCallback)(()=>O(null),[]),e0=(0,r.useCallback)((e,t)=>{let a=t??en.current;a&&window.open(`${tM}/channels/${a}/export?format=${e}`,"_blank")},[]),e1=(0,r.useCallback)(async(e={})=>{let t=new URLSearchParams;return e.scope&&t.set("scope",e.scope),e.withUserId&&t.set("with_user_id",e.withUserId),e.channelId&&t.set("channel_id",e.channelId),t.set("limit",String(e.limit??50)),(await tL(`/huddles?${t}`)).huddles},[]),e2=(0,r.useCallback)(async(e,t)=>{if(en.current!==e)return null;let a=el.current;try{let s=await tL(`/channels/${encodeURIComponent(e)}/messages/${encodeURIComponent(t)}`,{timeoutMs:15e3});if(en.current!==e||el.current!==a)return null;return o(e=>tO(e,[s.root,s.message])),s}catch(t){if(en.current!==e||el.current!==a)return null;throw t}},[]),e3=(0,r.useCallback)(async e=>{let t=en.current,a=el.current;if(!t)return;let s=await tL(`/channels/${t}/messages?root=${e}&limit=200`,{timeoutMs:15e3});en.current===t&&el.current===a&&o(e=>tO(e,s.messages))},[]),e4=(0,r.useCallback)(async()=>(await tL("/threads")).threads,[]),e5=(0,r.useCallback)(async(e,a)=>{t(t=>t.map(t=>
29t.id===e?{...t,unread:Math.max(1,t.unread)}:t)),en.current===e&&l(null),await tL(`/channels/${e}/read`,{method:"POST",body:JSON.stringify({last_read_message_id:a??null,unread:!0})}).catch(()=>{}),await eu()},[eu]),e6=(0,r.useCallback)(async(e,t)=>tL(`/channels/${e}/summarise`,{method:"POST",body:JSON.stringify({range:t})}),[]),e7=(0,r.useCallback)(async()=>{let e=await tL("/digest");return $(e),e},[]),e8=(0,r.useCallback)(async()=>{let e=en.current;if(!e)return[];let t=await tL(`/channels/${e}/rules`);return R(t.rules),t.rules},[]),e9=(0,r.useCallback)(async e=>{let t=en.current;t&&(await tL(`/channels/${t}/rules`,{method:"POST",body:JSON.stringify(e)}),await e8())},[e8]),te=(0,r.useCallback)(async(e,t)=>{await tL(`/rules/${e}`,{method:"PATCH",body:JSON.stringify({enabled:t})}),await e8()},[e8]),tt=(0,r.useCallback)(async e=>{await tL(`/rules/${e}`,{method:"DELETE"}),await e8()},[e8]),ta=(0,r.useCallback)(async(e,t)=>{let a=new Date(Date.now()+6e4*t).toISOString();await tL("/reminders",{method:"POST",body:JSON.stringify({message_id:e,remind_at:a})})},[]),ts=(0,r.useCallback)(async()=>{let e=en.current;if(!e)return[];let t=await tL(`/channels/${e}/turns`);return E(t.turns),t.turns},[]),tn=(0,r.useCallback)(async e=>tL(`/turns/${e}`),[]),tl=(0,r.useCallback)(async()=>{let e=await tL("/inbox");return C(e),e},[]),ti=(0,r.useCallback)(()=>{if(x.current)return x.current;p(!0),f(null);let e=(async()=>{try{let e=await tL("/directory",{signal:AbortSignal.timeout(15e3)});return m(e),e}catch(e){return f(e instanceof Error?e.message:tE.default.t("paletteOs:talk.directoryFailed","Could not load people and agents.")),null}finally{x.current=null,p(!1)}})();return x.current=e,e},[]),tr=(0,r.useCallback)(async(e,t)=>{let a=await tL("/channels",{method:"POST",body:JSON.stringify({name:e,visibility:t})});return await eu(),ep(a.id),a},[eu,ep]),to=(0,r.useCallback)(async e=>{let t=await tL("/dms",{method:"POST",body:JSON.stringify(e.is_agent?{agent_ids:[e.id]}:{user_ids:[e.id]})});return await eu(),ep(t.id),t},[eu,ep]),td=(0,r.useCallback)(async(e,t)=>{if(!e.length)return null;let a=await tL("/dms",{method:"POST",body:JSON.stringify({user_ids:e.filter(e=>!e.is_agent).map(e=>e.id),agent_ids:e.filter(e=>e.is_agent).map(e=>e.id),name:t?.trim()||null})});return await eu(),ep(a.id),a},[eu,ep]),tc=(0,r.useCallback)(async(e,t="anyone",a=!1)=>{let s=en.current;s&&await tL(`/channels/${s}/participants`,{method:"POST",body:JSON.stringify(e.is_agent?{agent_ids:[e.id],respond_to:t,always_on:a}:{user_ids:[e.id]})})},[]),tu=(0,r.useCallback)(async e=>{let t=en.current;t&&await tL(`/channels/${t}/participants/${e}`,{method:"DELETE"})},[]),tm=(0,r.useCallback)(async(e,t)=>{let a=en.current;a&&await tL(`/channels/${a}/participants/${e}`,{method:"PATCH",body:JSON.stringify(t)})},[]),th=(0,r.useRef)({id:"",at:0}),tp=(0,r.useCallback)(()=>{let e=en.current;if(!e)return;let t=Date.now();(function(e,t,a,s=3e3){return e.id!==t||a-e.at>=s})(th.current,e,t)&&(th.current={id:e,at:t},tL(`/channels/${e}/typing`,{method:"POST"}).catch(()=>{}))},[]);(0,r.useEffect)(()=>{let e=()=>void tL("/presence",{method:"POST"}).catch(()=>{});e();let t=window.setInterval(e,6e4);return()=>window.clearInterval(t)},[]);let tg=(0,r.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]),tf=(0,r.useMemo)(()=>n?D[n]??null:null,[D,n]);return(0,r.useMemo)(()=>({channels:e,dmMembers:a,active:tg,activeId:n,messages:i,participants:d,directory:u,directoryLoading:h,directoryError:g,turns:b,typing:j,pins:w,inbox:N,unreadAnchor:S,turnLog:T,rules:A,digest:F,huddle:tf,loading:z,opening:G,unreachable:K,error:Y,hasMore:J,loadingOlder:Z,streamDown:ea,openChannel:ep,send:eg,loadOlder:ef,react:ex,loadDirectory:ti,createChannel:tr,openDm:to,openGroupDm:td,addToChannel:tc,removeFromChannel:tu,setAgentMode:tm,notifyTyping:tp,refresh:eu,editMessage:ek,deleteMessage:eN,togglePin:eC,loadInbox:tl,browse:eS,joinChannel:e_,leaveChannel:eT,setPrefs:eE,updateChannel:eA,search:eR,loadTurns:ts,loadTranscript:tn,loadRules:e8,createRule:e9,toggleRule:te,deleteRule:tt,remindMe:ta,exportChannel:e0,loadDigest:e7,joinHuddle:eY,leaveHuddle:eq,huddles:D,invite:I,dismissInvite:eQ,huddleChannelId:P,myHuddle:eZ,speaking:eL,loadHuddleLog:e1,loadThread:e3,loadMessageTarget:e2,loadThreads:e4,markUnread:e5,summarise:e6,voiceOn:eM,muted:eO,toggleMute:eJ,customEmoji:B,uploadAttachment:ev,createCustomEmoji:ey,deleteCustomEmoji:ew}),[e,a,tg,n,i,d,u,h,g,b,j,w,N,S,T,A,F,tf,z,G,K,Y,J,Z,ea,ep,eg,ef,ex,ti,tr,to,td,tc,tu,tm,tp,eu,ek,eN,eC,tl,eS,e_,eT,eE,eA,eR,ts,tn,e8,e9,te,tt,ta,e0,e7,eY,eq,D,I,eQ,P,eZ,eL,e1,e3,e2,e4,e5,e6,eM,eO,eJ,B,ev,ey,ew])}(),m=u.search,{user:h}=(0,eo.useAuth)(),p=h?.id,g=String(p??""),[f,x]=(0,r.useState)(""),[b,v]=(0,r.useState)(null),[j,y]=(0,r.useState)(null),[w,k]=(0,r.useState)(""),[N,C]=(0,r.useState)(null),[S,_]=(0,r.useState)([]),[T,E]=(0,r.useState)(null),[A,R]=(0,r.useState)(null),[D,M]=(0,r.useState)(!1),[I,O]=(0,r.useState)(null),[P,L]=(0,r.useState)(!0),[F,$]=(0,r.useState)(null),[B,H]=(0,r.useState)(null),[z,U]=(0,r.useState)(""),[G,W]=(0,r.useState)([]),[K,V]=(0,r.useState)(null),Y=(0,r.useRef)(!1),q=(0,r.useRef)(0),[X,Q]=(0,r.useState)(null),[et,ea]=(0,r.useState)("idle"),[en,el]=(0,r.useState)(0),[ei,er]=(0,r.useState)(!1),[em,eh]=(0,r.useState)(null),[ep,eg]=(0,r.useState)(null),[ex,ev]=(0,r.useState)(null),[ey,ew]=(0,r.useState)([]),[ek,eC]=(0,r.useState)([]),[e_,eT]=(0,r.useState)(!1),[eE,eA]=(0,r.useState)(!1),eR=(0,r.useRef)(0),[eD,eM]=(0,r.useState)(!1),[eI,eO]=(0,r.useState)(!1),[eP,eL]=(0,r.useState)(380),[eF,e$]=(0,r.useState)(!1),[eB,eH]=(0,r.useState)(null),[ez,eU]=(0,r.useState)(!1),[eG,eW]=(0,r.useState)(!1),[eK,eV]=(0,r.useState)(""),{open:eY,setOpen:eq,closeOnMobile:eJ}=(0,ec.usePaletteSidebar)("talk"),eX=!eY,[eZ,eQ]=(0,r.useState)(!1),[e0,e3]=(0,r.useState)(""),[e4,e5]=(0,r.useState)(null),[e6,e8]=(0,r.useState)(!1),[e9,te]=(0,r.useState)(null),tt=(0,r.useRef)(null),tn=(0,r.useRef)(null),[tl,ti]=(0,r.useState)({}),[td,tu]=(0,r.useState)(null),[tm,th]=(0,r.useState)(null),tp=!a&&(c||n),[tf,tx]=(0,r.useState)(null),tb=(0,r.useRef)(null),tv=(0,r.useRef)(null),ty=(0,r.useRef)(null),tw=(0,r.useRef)(null),tk=(0,r.useRef)(null),tN=(0,r.useRef)(null),tC=(0,r.useRef)(null),tH=(0,r.useRef)(null),tz=(0,r.useCallback)(()=>{eQ(!1),e3(""),tN.current?.focus()},[]),{channels:tJ,dmMembers:tQ,active:t0,activeId:t1,messages:t5,participants:t8,directory:al,turns:ar,typing:ao}=u,ac=i("talk.directMessage","Direct message"),au=(0,r.useMemo)(()=>tJ.filter(e=>"stream"===e.channel_type||"forum"===e.channel_type),[tJ]),am=(0,r.useMemo)(()=>{let e=eK.trim().toLowerCase();return tJ.filter(e=>!eG||e.unread>0).filter(t=>!e||t9(t,tQ[t.id],ac,g).toLowerCase().includes(e)||(t.last_message?.text??"").toLowerCase().includes(e))},[tJ,eG,eK,tQ,ac,g]),ah=(0,r.useCallback)(e=>
29(tQ[e.id]??[]).some(e=>e?.is_agent)||!!e.last_message?.is_agent,[tQ]),ap=(0,r.useMemo)(()=>{let e=e0.trim().toLowerCase();return e?t5.filter(t=>t.content.toLowerCase().includes(e)||(t.sender?.name??"").toLowerCase().includes(e)||t.attachments.some(t=>t.filename.toLowerCase().includes(e))):t5},[t5,e0]),av=(0,r.useCallback)(e=>{let t=e.last_message;if(!t)return i("talk.newConversation","New conversation");let a=t.text||("system"===t.kind?i("talk.systemLine","Room activity"):i("talk.attachmentLine","Attachment"));return!t.is_agent&&t.sender_id&&t.sender_id===g?i("talk.previewMine","You: {{body}}",{body:a}):"dm"===e.channel_type?a:i("talk.previewOther","{{who}}: {{body}}",{who:t.sender,body:a})},[g,i]);(0,r.useEffect)(()=>{o&&(u.openChannel(o),d(null))},[o,d,u]);let aj=(0,r.useRef)(!1),aS=`${tV}:${h?.organization_id??""}`;(0,r.useEffect)(()=>{u.unreachable&&(ee.toast.error(i("talk.notInWorkspace","That conversation isn't available in this workspace.")),ty.current=null,aj.current=!1)},[u.unreachable,i]),(0,r.useEffect)(()=>{if(t1||o){aj.current=!0;return}if(aj.current||!au.length||!tJ.length)return;aj.current=!0;let e=null;try{e=localStorage.getItem(aS)??localStorage.getItem(tV)}catch{}let t=e&&tJ.some(t=>t.id===e)?e:null;u.openChannel(t??au[0].id)},[t1,o,au,tJ,u,aS]),(0,r.useEffect)(()=>{tv.current=t1},[t1]),(0,r.useEffect)(()=>{if(t1&&tJ.some(e=>e.id===t1))try{localStorage.setItem(aS,t1)}catch{}},[t1,tJ,aS]),(0,r.useEffect)(()=>{u.loadDirectory()},[u.loadDirectory]);let aT=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=tk.current;if(!e||!P)return;let t=aT.current!==t1;aT.current=t1??null,e.scrollTo({top:e.scrollHeight,behavior:t?"auto":"smooth"})},[t5.length,ar,t1,P]);let aE=(0,r.useRef)(0);(0,r.useEffect)(()=>{P&&(aE.current=t5.length)},[P,t5.length]);let aR=(0,r.useCallback)(()=>{let e=tk.current;e&&L(e.scrollHeight-e.scrollTop-e.clientHeight<60)},[]),aD=(0,r.useCallback)(()=>{let e=tk.current;e?.scrollTo({top:e.scrollHeight,behavior:"smooth"}),L(!0)},[]),aM=(0,r.useMemo)(()=>{if(P)return 0;let e=t5.length-aE.current;if(!u.unreadAnchor)return Math.max(0,e);let t=t5.findIndex(e=>e.id===u.unreadAnchor);return Math.max(t<0?0:t5.length-t,e,0)},[P,t5,u.unreadAnchor]),aI=(0,r.useMemo)(()=>({"--ss-body":"12.5px","--ss-lh":"1.6","--ss-gap":"20px","--po-col":"720px"}),[]);(0,r.useEffect)(()=>{u.error&&tJ.length&&ee.toast.error(u.error)},[u.error,tJ.length]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&!e.defaultPrevented&&(eB?eH(null):ez?eU(!1):T?E(null):eF?e$(!1):F?$(null):B?H(null):eZ?tz():e4?e5(null):eI&&eO(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[T,eF,F,B,eI,eB,ez,eZ,e4,tz]),(0,r.useEffect)(()=>{e5(null),eQ(!1),e3(""),te(null),ev(null),e8(!1),eH(null),eU(!1)},[t1]);let aO=(0,r.useMemo)(()=>new Set(t8.map(e=>t7(e))),[t8]),aP=(0,r.useMemo)(()=>{if(null==N)return[];let e=N.toLowerCase(),t=[...al.agents,...al.people].map(e=>({...e,in_channel:aO.has(t7(e))})),a=new Set;return t.filter(t=>{if(!t.name.toLowerCase().includes(e))return!1;let s=t7(t);return!a.has(s)&&(a.add(s),!0)}).sort((e,t)=>Number(t.in_channel)-Number(e.in_channel)||Number(t.is_agent)-Number(e.is_agent)||e.name.localeCompare(t.name)).slice(0,50)},[al,N,aO]),[aL,aF]=(0,r.useState)(0);(0,r.useEffect)(()=>{aF(0)},[N]);let a$=(0,r.useRef)(null);(0,r.useEffect)(()=>{a$.current?.querySelector('[aria-selected="true"]')?.scrollIntoView({block:"nearest"})},[aL]);let aB=(0,r.useCallback)(e=>{x(e),t1&&ti(t=>tq(t,t1,e))},[t1]);(0,r.useEffect)(()=>{if(p)try{let e=localStorage.getItem(`${tY}:${p}`);e&&ti(JSON.parse(e))}catch{}},[p]);let aH=(0,r.useRef)({});aH.current=tl,(0,r.useEffect)(()=>{x(t1?aH.current[t1]??"":"")},[t1]),(0,r.useEffect)(()=>{let e=Number(localStorage.getItem(t2));e&&eL(e)},[]);let az=(0,r.useCallback)(e=>{e.preventDefault();let t=e.currentTarget,a=e.clientX,s=t.parentElement?.querySelector(".tlAux")?.getBoundingClientRect().width??380,n=t4(t);t.setPointerCapture(e.pointerId);let l=e=>{eL(t3(s-(e.clientX-a),n))},i=()=>{t.releasePointerCapture(e.pointerId),t.removeEventListener("pointermove",l),t.removeEventListener("pointerup",i),eL(e=>(localStorage.setItem(t2,String(e)),e))};t.addEventListener("pointermove",l),t.addEventListener("pointerup",i)},[]);(0,r.useEffect)(()=>
29{if(!p)return;let e=window.setTimeout(()=>{try{localStorage.setItem(`${tY}:${p}`,JSON.stringify(tl))}catch{}},500);return()=>window.clearTimeout(e)},[tl,p]);let aU=(0,r.useCallback)(e=>{aB(e),u.notifyTyping()},[u,aB]),aG=(0,r.useCallback)(e=>{tN.current?.replaceMention(e.name),C(null),_(t=>t.some(t=>t.kind===e.kind&&t.id===String(e.id))?t:[...t,{kind:e.kind,id:String(e.id),label:e.name}]),e.is_agent&&!e.in_channel&&u.addToChannel(e).then(()=>(0,ee.toast)(i("talk.agentAdded","{{name}} joined the channel",{name:e.name}))).catch(()=>ee.toast.error(i("talk.agentAddFailed","Could not add {{name}}",{name:e.name})))},[u,i]),aW=(0,r.useCallback)(async()=>{let e=f.trim();if(!e&&0===ey.length&&0===ek.length)return;let t=e4?`> **${e4.sender?.name??""}**: ${af(e4.content).slice(0,100)} 30 31${e}`:e;e5(null),aB(""),C(null);let a=S.filter(e=>t.toLowerCase().includes(`@${e.label??""}`.toLowerCase()));_([]),ew([]),eC([]);let s=[];if(ey.length){eA(!0);try{s=await Promise.all(ey.map(e=>u.uploadAttachment(e)))}catch(t){aB(e),e5(e4),ew(ey),eC(ek),ee.toast.error(t instanceof Error?t.message:i("talk.uploadFailed","Could not upload"));return}finally{eA(!1)}}await u.send(t,{mentionRefs:a,attachments:[...s,...ek]})},[f,ey,ek,S,e4,u,i,aB]),aK=(0,r.useCallback)((e,t,a)=>{u.setPrefs(e,t).then(e=>{e?(0,ee.toast)(a):ee.toast.error(i("talk.prefFailed","Could not save that"))})},[u,i]),aV=(0,r.useCallback)(e=>{tN.current?.insert(e)},[]),aY=(0,r.useCallback)(e=>{let t=ex?.on;if(ev(null),t){if("react"===t.kind)return void("emoji"===e.type?u.react(t.message.id,e.value):"custom"===e.type&&u.react(t.message.id,`:${e.code}:`));if("sticker"===e.type)return void u.send(e.label,{panelData:{kind:"sticker",pack:e.pack,id:e.id}});aV("custom"===e.type?`:${e.code}:`:e.value)}},[ex,u,aV]),aq=(0,r.useCallback)(e=>{if(!e?.length)return;let t=Array.from(e);ew(e=>[...e,...t].slice(0,10))},[]),aJ=(0,r.useCallback)(async(e,t)=>{eA(!0);try{let a=await u.uploadAttachment(e);await u.send("",{attachments:[a],parentId:t})}catch(e){ee.toast.error(e instanceof Error?e.message:i("talk.uploadFailed","Could not upload"))}finally{eA(!1)}},[u,i]),aX=e=>Array.from(e.dataTransfer.types).includes("Files"),aZ=(0,r.useCallback)(async(e=[],t=[])=>{let a=w.trim();if((a||e.length||t.length)&&j){k("");try{let s=e.length?await Promise.all(e.map(e=>u.uploadAttachment(e))):[];await u.send(a,{parentId:j.id,attachments:[...s,...t]})}catch(e){k(a),ee.toast.error(e instanceof Error?e.message:i("talk.uploadFailed","Could not upload"))}}},[w,j,u,i]),aQ=(0,r.useCallback)(async e=>{try{$({scope:e,rows:await u.browse(e)})}catch(e){ee.toast.error(e instanceof Error?e.message:i("talk.browseFailed","Could not load channels"))}},[u,i]),a0=ei?t1:null;(0,r.useEffect)(()=>{if("search"!==b)return;let e=z.trim();if(W([]),e.length<2||ei&&!a0)return void ea("idle");let t=!0;ea("loading");let a=window.setTimeout(()=>{m(e,a0).then(e=>{t&&(W(e),ea("ready"))}).catch(()=>{t&&ea("error")})},260);return()=>{t=!1,window.clearTimeout(a)}},[b,z,ei,a0,m,en]);let a1=(0,r.useCallback)(async()=>{let e=(T?.name??"").trim();if(!e)return void E(null);R(null),M(!0);try{tu(null),await u.createChannel(e,T?.private?"private":"open"),E(null)}catch(e){R(e instanceof Error?e.message:i("talk.createFailed","Could not create the channel"))}finally{M(!1)}},[T,u,i]);(0,r.useEffect)(()=>(q.current+=1,Y.current=!1,V(null),()=>{q.current+=1}),[b,eI,z,ei]);let a2=async e=>{if(Y.current)return;let t=++q.current;Y.current=!0,V(e.id);try{t1!==e.channel_id&&await u.openChannel(e.channel_id);let a=await u.loadMessageTarget(e.channel_id,e.id);if(!a||q.current!==t)return;y(a.root),Q(a.message.id),tu(null),sd("thread")}catch{if(q.current!==t)return;ee.toast.error(i("talk.openMessageFailed","Could not open this message. Try again from the search results."))}finally{q.current===t&&(Y.current=!1,V(null))}},a3=(0,r.useMemo)(()=>j?t5.filter(e=>e.id===j.id||e.root_message_id===j.id):[],[t5,j]);(0,r.useEffect)(()=>{j&&j.channel_id!==t1&&(y(null),k(""))},[t1,j]);let a4=(0,r.useMemo)(()=>{let e=new Map;for(let t of t8)t.is_agent&&e.set(Number(t.id),t.name);return e},[t8]),a5=t0?t9(t0,tQ[t0.id],ac,g):"",a6=(0,r.useMemo)(()=>
31{if(!t0)return"";let e=t8.filter(e=>e.is_agent).length,t=[i("talk.metaPeople","{{people}} people · {{agents}} agents",{people:t8.length-e,agents:e})];return t0.topic&&t.push(t0.topic),t.join(" · ")},[t0,t8,i]),a7=!!u.huddle?.participants.some(e=>e.id===g),a8=(0,r.useCallback)(e=>{let t=tJ.find(t=>t.id===e);return t?t9(t,tQ[e],ac,g):i("talk.someChannel","a channel")},[tJ,tQ,ac,g,i]),a9=(0,r.useMemo)(()=>B?tJ.find(e=>e.id===B.id)??null:null,[B,tJ]),se=(0,r.useCallback)((e,t)=>{let a=tJ.find(t=>t.id===e);return!!a&&(H({id:a.id,topic:a.topic??"",description:a.description,tab:t}),!0)},[tJ]),st=(0,r.useCallback)((e,t)=>{navigator.clipboard?.writeText(e).then(()=>(0,ee.toast)(t)).catch(()=>ee.toast.error(i("talk.copyFailed","Could not copy")))},[i]),sa=(0,r.useCallback)((e,t)=>{let a=a8(e.id),s=ee.toast.loading(i("talk.summarising","Reading {{room}}â¦",{room:a}));u.summarise(e.id,t).then(e=>{(ee.toast.dismiss(s),e.summary)?(0,ee.toast)(a,{description:e.summary,duration:6e4,closeButton:!0}):(0,ee.toast)(e.messages?i("talk.summaryUnavailable","Could not read that window just now"):i("talk.summaryEmpty","Nothing was said in that window"))}).catch(()=>{ee.toast.dismiss(s),ee.toast.error(i("talk.summaryFailed","Could not summarise"))})},[u,a8,i]),ss=(0,r.useCallback)((e,t)=>{let a=t8.find(t=>t.is_agent&&String(t.id)===String(e.id));eh({x:t.x,y:t.y,head:e.name.toUpperCase(),sections:[[{label:i("talk.messagePerson","Message {{name}}",{name:e.name}),on:()=>void u.openDm(e)},{label:i("talk.startHuddleWith","Start a huddle"),on:()=>{ef(),u.openDm(e).then(e=>u.joinHuddle(e.id))}}],a?[{label:i("talk.respondsTo","Responds to"),submenu:[{label:i("talk.respondAnyone","Anyone may instruct"),checked:(a.respond_to??"anyone")==="anyone",on:()=>void u.setAgentMode(a.participant_id,{respond_to:"anyone"})},{label:i("talk.respondOwner","Channel owner only"),checked:"owner_only"===a.respond_to,on:()=>void u.setAgentMode(a.participant_id,{respond_to:"owner_only"})},{label:i("talk.respondList","Allowlist only"),checked:"allowlist"===a.respond_to,on:()=>void u.setAgentMode(a.participant_id,{respond_to:"allowlist"})}]},{label:i("talk.alwaysOn","Reads every message"),checked:a.always_on,on:()=>void u.setAgentMode(a.participant_id,{always_on:!a.always_on})}]:[],[{label:i("talk.copyName","Copy name"),on:()=>st(e.name,i("talk.copiedName","Name copied"))},...e.email?[{label:i("talk.copyEmail","Copy email"),on:()=>st(e.email,i("talk.copiedEmail","Email copied"))}]:[]]]})},[u,i,t8,st]),sn=u.huddleChannelId&&u.huddleChannelId!==t1?u.myHuddle:null,sl=u.invite?u.huddles[u.invite.channelId]?.participants??[]:[],si=(0,r.useCallback)(()=>{let e=u.invite?.channelId;e&&(ef(),u.openChannel(e),u.joinHuddle(e).catch(e=>ee.toast.error(e instanceof Error?e.message:i("talk.huddleJoinFailed","Could not join the huddle"))))},[u,i]),sr=(0,r.useCallback)(()=>{ef(),(a7?u.leaveHuddle():u.joinHuddle()).catch(e=>ee.toast.error(e instanceof Error?e.message:i("talk.huddleJoinFailed","Could not join the huddle")))},[a7,u,i]),so={thread:i("talk.thread","THREAD"),runs:i("talk.runs","RUNS"),rules:i("talk.rules","RULES"),search:i("talk.search","SEARCH")},sd=(0,r.useCallback)(e=>{v(e),eO(!0),"runs"===e&&u.loadTurns(),"rules"===e&&u.loadRules()},[u]),sc=(0,r.useCallback)(e=>{tu(e),"threads"===e&&(th(null),u.loadThreads().then(th).catch(()=>th([]))),"directory"===e&&u.loadDirectory(),"activity"===e&&(u.loadInbox(),u.loadDigest())},[u]),su=(0,r.useCallback)(e=>{tb.current=null,Q(null),e.channelId&&(ty.current=e.channelId),e.channelId&&e.channelId!==tv.current&&u.openChannel(e.channelId),sc(e.board),U(e.query),er(e.scopeHere),e.browse?aQ(e.browse):$(null),e.pane?sd(e.pane):e.thread||(v(null),eO(!1)),e.thread||y(null),e.details||H(null);let t={thread:e.thread,details:e.details&&!se(e.details,e.detailsTab)?e.details:null,detailsTab:e.detailsTab};tx(t.thread||t.details?t:null)},[u,sd,sc,aQ,se]);(0,r.useEffect)(()=>{let t=a?tc(`/talk${a.current}`):tp?tc(window.location.pathname+window.location.search):null,s=e??t?.channelId??null;su({...t??to,channelId:o?null:s}),ty.current=o??s},[]),(0,r.useEffect)(()=>
31{if(!a?.current)return;let e=`/talk${a.current}`;if(e===tw.current)return;let t=tc(e);t&&su(t)},[a?.current]),(0,r.useEffect)(()=>{if(!tp)return;let e=()=>{let e=tc(window.location.pathname+window.location.search);e&&su(e)};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[tp,su]),(0,r.useEffect)(()=>{var e;let t,s,n;if(!t1)return;let l=(e={channelId:t1,thread:j?.id??tf?.thread??null,pane:"thread"===b?null:b,query:z,scopeHere:ei,board:td,details:B?.id??tf?.details??null,detailsTab:B?.tab??tf?.detailsTab??"about",browse:F?.scope??null},t=new URLSearchParams,e.thread?t.set("thread",e.thread):e.pane&&t.set("pane",e.pane),e.query&&t.set("q",e.query),e.scopeHere&&t.set("scope","here"),e.board&&t.set("board",e.board),e.details&&(t.set("details",e.details),"members"===e.detailsTab&&t.set("tab","members")),e.browse&&t.set("browse",e.browse),s=e.channelId?`/talk/${encodeURIComponent(e.channelId)}`:"/talk",(n=t.toString())?`${s}?${n}`:s),i=null!==ty.current&&ty.current!==t1;ty.current=t1,l!==tw.current&&(tw.current=l,a?a.select(l,i):tp&&function(e,t){if(tr.test(window.location.pathname)&&e!==window.location.pathname+window.location.search)try{t?window.history.pushState(null,"",e):window.history.replaceState(null,"",e)}catch{}}(l,i))},[t1,j?.id,b,z,ei,td,B?.id,B?.tab,F?.scope,tf,a,tp]),(0,r.useEffect)(()=>{if(!tf)return;let e=tf;if(e.details&&(se(e.details,e.detailsTab)||tJ.length)&&(e={...e,details:null}),e.thread){let t=t5.find(t=>t.id===e.thread);if(t)y(t),"threads"!==td&&sd("thread"),e={...e,thread:null};else if(t1&&tb.current!==e.thread){let t=e.thread;tb.current=t,u.loadMessageTarget(t1,t).catch(()=>{tb.current===t&&(tx(e=>e?.thread===t?{...e,thread:null}:e),ee.toast.error(i("talk.openMessageFailed","Could not open this message. Try again from the search results.")))})}}e.thread||e.details?e!==tf&&tx(e):tx(null)},[tf,tJ,t5,t1,se,sd,u,td,i]);let sm=(0,r.useCallback)((e,t)=>{let a=e.sender?.kind==="user"&&String(e.sender.id)===g;eh({x:t.x,y:t.y,head:i("talk.message","MESSAGE"),sections:[aa.map(t=>({id:`r:${t}`,label:t,on:()=>{tj(tX(t)),u.react(e.id,t)}})),[{label:i("talk.replyInThread","Reply in thread"),on:()=>{y(e),sd("thread")}},{label:i("talk.pin","Pin"),on:()=>void u.togglePin(e.id)},{label:i("talk.remindMe","Remind me in an hour"),on:()=>void u.remindMe(e.id,60).then(()=>(0,ee.toast)(i("talk.reminderSet","Reminder set for an hour from now"))).catch(()=>ee.toast.error(i("talk.reminderFailed","Could not set the reminder")))},{label:i("talk.copyText","Copy text"),on:()=>st(e.content,i("talk.copied","Copied"))}],a?[...Date.now()-new Date(e.created_at).getTime()<36e5?[{label:i("talk.edit","Edit"),on:()=>O({id:e.id,text:e.content})}]:[],{label:i("talk.delete","Delete"),danger:!0,on:()=>void u.deleteMessage(e.id)}]:[]]})},[g,i,u,st,sd]),sh=u.loading&&!tJ.length,sp=!!u.error&&!tJ.length&&!u.loading;(0,r.useEffect)(()=>{try{eW("1"===localStorage.getItem(tK))}catch{}},[]);let sg=(0,r.useCallback)(()=>{eW(e=>{try{localStorage.setItem(tK,e?"0":"1")}catch{}return!e})},[]),sf=(0,r.useMemo)(()=>tJ.reduce((e,t)=>e+t.unread,0),[tJ]),sx=(0,r.useMemo)(()=>Object.keys(tl).filter(e=>tJ.some(t=>t.id===e)),[tl,tJ]),sb=Object.keys(u.huddles).length,sv=(0,r.useMemo)(()=>[{board:"threads",label:i("talk.threads","Threads")},{board:"huddles",label:sb?`${i("talk.huddles","Huddles")} \xb7 ${sb}`:i("talk.huddles","Huddles")},{board:"drafts",label:sx.length?`${i("talk.drafts","Drafts")} \xb7 ${sx.length}`:i("talk.drafts","Drafts"),disabled:0===sx.length},{board:"directory",label:i("talk.directories","Directories")},{board:"activity",label:sf?`${i("talk.activity","Activity")} \xb7 ${sf}`:i("talk.activity","Activity")}],[i,sb,sx,sf]),sj=(0,r.useCallback)((e,t)=>{let a="dm"===e.channel_type||"group_dm"===e.channel_type,s=a?(tQ[e.id]??[]).find(e=>"user"!==e.kind||String(e.id)!==g):void 0,n=document.activeElement instanceof HTMLElement?document.activeElement:null,l={x:t.x,y:t.y,head:a8(e.id),sections:[[{label:e.starred?i("talk.unpinRoom","Unpin"):i("talk.pinRoom","Pin"),on:()=>aK(e.id,{starred:!e.starred},e.starred?i("talk.starOff","Star removed"):i("talk.starOn","Starred"))},{label:i("talk.markUnread","Mark as unread"),disabled:e.unread>0,on:()=>void u.markUnread(e.id)},{label:i("talk.unreadOnlyMenu","Unread only"),checked:eG,on:sg}],[{label:i("talk.viewMembers","View participants"),on:()=>{e.id===tv.current?eU(!0):se(e.id,"members")}},{label:i("talk.details","Conversation details"),on:()=>se(e.id,"about")}],sv.map(e=>({label:e.label,checked:e.board===td,disabled:e.disabled,on:()=>sc(td===e.board?null:e.board)})),[{label:i("talk.newChannelRow","New channel"),on:()=>{R(null),E({name:"",private:!1})}},{label:i("talk.browseRow","Browse channels"),on:()=>void aQ("all")},{label:i("talk.searchEverywhere","Search everywhere"),on:()=>{er(!1),sd("search")}}],[{label:i("talk.copy","Copy"),submenu:[{label:i("talk.copyName","Copy name"),on:()=>st(a8(e.id),i("talk.copiedName","Name copied"))},{label:i("talk.copyLink","Copy link"),on:()=>st(`${window.location.origin}/talk/${e.id}`,i("talk.copiedLink","Link copied"))}]},{label:i("talk.summarise","Summarise conversation"),submenu:[{label:i("talk.sumYesterday","Since yesterday"),on:()=>sa(e,"since_yesterday")},{label:i("talk.sumWeek","Last 7 days"),on:()=>sa(e,"last_7_days")},{label:i("talk.sumUnread","Everything unread"),on:()=>sa(e,"unread")}]},{label:i("talk.exportConv","Export conversation"),submenu:[{label:i("talk.exportMdRow","Markdown"),on:()=>
31u.exportChannel("md",e.id)},{label:i("talk.exportJsonRow","JSON"),on:()=>u.exportChannel("json",e.id)}]}],[{label:i("talk.mute","Mute"),checked:e.muted,on:()=>aK(e.id,{muted:!e.muted},e.muted?i("talk.muteOff","Unmuted"):i("talk.muteOn","Muted"))},{label:i("talk.moveToSection","Move to section"),submenu:[{label:i("talk.sectionNone","No section"),checked:!e.section,on:()=>aK(e.id,{section:null},i("talk.sectionCleared","Removed from the section"))},...ai.map(t=>({label:t,checked:e.section===t,on:()=>aK(e.id,{section:t},i("talk.sectionSet","Moved to {{name}}",{name:t}))}))]}],[{label:i("talk.startHuddle","Start a huddle"),disabled:!!u.huddles[e.id],on:()=>{ef(),u.joinHuddle(e.id)}}],[{label:i("talk.appRuns","App runs"),on:()=>sd("runs")},{label:i("talk.automations","Automations"),on:()=>sd("rules")}],a?[{label:i("talk.closeConversation","Close conversation"),danger:!0,on:()=>void u.leaveChannel(e.id)}]:[{label:e.archived?i("talk.unarchiveRow","Unarchive channel"):i("talk.archiveRow","Archive channel"),danger:!e.archived,on:()=>void u.updateChannel(e.id,{archived:!e.archived})},{label:i("talk.leave","Leave channel"),danger:!0,on:()=>void u.leaveChannel(e.id)}],s?[{label:i("talk.messagePerson","Message {{name}}",{name:s.name}),on:()=>void u.openDm(s)}]:[]]},r={x:t.x,y:t.y,sections:[[{icon:"h_pin",label:e.starred?i("talk.unpinRoom","Unpin"):i("talk.pinRoom","Pin"),on:()=>aK(e.id,{starred:!e.starred},e.starred?i("talk.starOff","Star removed"):i("talk.starOn","Starred"))},{icon:"h_pencil",label:i("talk.renameConversation","Rename conversation"),on:()=>eg({id:e.id,name:a8(e.id),opener:n})},{icon:"h_messageSquare",label:i("talk.markUnread","Mark as unread"),disabled:e.unread>0,on:()=>void u.markUnread(e.id)}],[{icon:"h_download",label:i("talk.downloadConversation","Download conversation"),on:()=>u.exportChannel("md",e.id)}],[{icon:"h_more",label:i("talk.moreActions","More actions"),on:()=>eh(l)}]]};l.sections.unshift([{icon:"h_chevronLeft",label:i("talk.backToMenu","Back"),on:()=>eh(r)}]),eh(r)},[u,i,a8,tQ,g,st,sa,se,aK,eG,sg,td,sc,sd,aQ]),sy=(0,r.useCallback)((e,t)=>{t.preventDefault();let a=t.currentTarget.getBoundingClientRect();sj(e,t.clientX||t.clientY?{x:t.clientX,y:t.clientY}:{x:a.right-226,y:a.bottom+4})},[sj]),sw=e=>(0,t.jsx)(aA,{loadThread:u.loadThread,focusMessageId:X,onBack:e,root:j?.channel_id===t1?a3.find(e=>e.id===j.id)??j:null,messages:j?.channel_id===t1?a3:[],draft:w,setDraft:k,customEmoji:u.customEmoji,onReact:(e,t)=>{tZ.test(t)||tj(tX(t)),u.react(e.id,t)},onOpenPicker:(e,t)=>te({message:e,rect:t}),onCopy:e=>st(e.content,i("talk.copied","Copied")),onMenu:sm,onSend:(e,t)=>void aZ(e,t),onVoice:e=>{j&&aJ(e,j.id)}},`${t1}:${j?.id}`);return(0,t.jsxs)("div",{className:"viewPane talkView",style:aI,onDragEnter:e=>{aX(e)&&(e.preventDefault(),eR.current+=1,eM(!0))},onDragOver:e=>{aX(e)&&e.preventDefault()},onDragLeave:()=>{eR.current=Math.max(0,eR.current-1),0===eR.current&&eM(!1)},onDrop:e=>{aX(e)&&(e.preventDefault(),eR.current=0,eM(!1),aq(e.dataTransfer.files))},children:[eD&&(0,t.jsx)("div",{className:"tlDropVeil","aria-hidden":!0,children:(0,t.jsx)("span",{children:i("talk.dropToAttach","Drop to attach")})}),(0,t.jsxs)("div",{className:"tlBody",children:[(0,t.jsxs)("aside",{inert:eX,className:`tlAside${eX?" stood-down":""}`,children:[(0,t.jsxs)("div",{className:"tlListHead",children:[(0,t.jsxs)("button",{className:"tlNewTalk","aria-expanded":eF,"aria-haspopup":"dialog",onClick:()=>e$(e=>!e),children:[(0,t.jsx)(t$,{n:"edit",size:17}),i("talk.newTalk","New chat")]}),(0,t.jsx)("button",{className:"tlCollapse","aria-label":i("talk.collapseList","Collapse list"),title:i("talk.collapseList","Collapse list"),"aria-expanded":!eX,onClick:()=>eq(!1),children:(0,t.jsx)(t$,{n:"panelLeft",size:18})})]}),(0,t.jsxs)("label",{className:"tlListSearch poSearch",children:[(0,t.jsx)(t$,{n:"search",size:16}),(0,t.jsx)("input",{type:"search",value:eK,placeholder:i("talk.listSearch","Search conversations"),"aria-label":i("talk.listSearch","Search conversations"),onChange:e=>eV(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),eV(""))}})]}),sh&&(0,t.jsx)("div",{className:"tlAsideScroll","aria-hidden":!0,
31children:Array.from({length:7},(e,a)=>(0,t.jsxs)("div",{className:"tlRoomSkel",children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${52+17*a%40}%`}})]},a))}),sp&&(0,t.jsx)("div",{className:"tlAsideScroll",children:(0,t.jsxs)("div",{className:"tlAsideEmpty",role:"alert",children:[(0,t.jsx)("span",{className:"rlEmptyLead",children:i("talk.channelsFailed","Could not reach Talk.")}),(0,t.jsx)("button",{className:"po-btn po-btn--sm",onClick:()=>void u.refresh(),children:i("talk.retry","RETRY")})]})}),!sh&&!sp&&(0,t.jsxs)("div",{className:"tlAsideScroll tlChats",children:[[[i("talk.groupPinned","Pinned"),am.filter(e=>e.starred)],[i("talk.groupRecent","Recent"),am.filter(e=>!e.starred)]].map(([e,a])=>a.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"tlGroupLabel",children:e}),a.map(e=>(0,t.jsxs)("div",{className:`tlChatRow${e.id===t1&&!td?" on":""}`,onContextMenu:t=>sy(e,t),children:[(0,t.jsxs)("button",{className:`tlChat${e.id===t1&&!td?" on":""}${e.unread?" unread":""}`,"aria-current":e.id!==t1||td?void 0:"page",onClick:()=>{tu(null),eJ(),u.openChannel(e.id)},children:[(0,t.jsx)(t6,{channel:e,members:tQ[e.id],meId:g,size:33}),(0,t.jsxs)("span",{className:"tlChatMain",children:[(0,t.jsxs)("span",{className:"tlChatTop",children:[(0,t.jsx)("span",{className:"tlChatN",children:a8(e.id)}
31),ah(e)&&(0,t.jsx)("span",{className:"tlAiMark",title:i("talk.agent","Agent"),children:i("talk.aiMark","AI")}),e.muted&&(0,t.jsx)(ej.TlIcon,{n:"bellOff",size:12,cls:"tlChatMute"}),u.huddles[e.id]&&(0,t.jsx)("span",{className:"tlHudLive",title:i("talk.huddleHere","A huddle is live here")})]}),(0,t.jsx)("span",{className:"tlChatPrev",children:av(e)})]}),e.unread>0&&(0,t.jsx)("span",{className:"tlRoomC","aria-label":i("talk.unreadRooms","Unread")})]}),(0,t.jsx)("button",{className:"tlIconBtn tlChatMenu","aria-haspopup":"menu","aria-label":`${i("talk.roomMenu","Conversation menu")} \xb7 ${a8(e.id)}`,onClick:t=>{let a=t.currentTarget.getBoundingClientRect();sj(e,{x:a.right-226,y:a.bottom+4})},children:(0,t.jsx)(t$,{n:"more",size:20})})]},e.id))]},e)),!am.length&&(0,t.jsxs)("div",{className:"tlAsideEmpty",children:[(0,t.jsx)("span",{className:"rlEmptyLead",children:eK.trim()?i("talk.noListMatch","No matching conversations."):eG?i("talk.allRead","Nothing unread"):i("talk.noConversationsYet","No conversations yet")}),!eK.trim()&&(0,t.jsx)("button",{className:"po-btn po-btn--sm",onClick:()=>eG?sg():e$(!0),children:eG?i("talk.showAll","SHOW ALL"):i("talk.newTalk","NEW TALK")})]})]}),(0,t.jsx)(J.SidebarResizer,{open:eY})]}),(0,t.jsxs)("section",{className:"tlMain",children:[t0&&(0,t.jsxs)("header",{className:"tlHead",children:[(0,t.jsx)(t6,{channel:t0,members:tQ[t0.id],meId:g,size:36}),(0,t.jsxs)("button",{className:"tlHeadName",onClick:()=>eU(!0),children:[(0,t.jsx)("span",{className:"tlHeadTitle",children:a5}),(0,t.jsx)("span",{className:"tlHeadMeta",children:a6})]}),(0,t.jsxs)("span",{className:"tlHeadR",children:[(0,t.jsx)("button",{"data-tip":i("talk.viewMembers","View participants"),className:"tlIconBtn tlHeadMembersButton","aria-label":i("talk.viewMembers","View participants"),onClick:()=>eU(!0),children:(0,t.jsx)(t$,{n:"users"})}),(0,t.jsx)("button",{"data-tip":i("talk.addPeople","Add people"),ref:tt,className:"tlIconBtn","aria-haspopup":"dialog","aria-expanded":eB?.kind==="person","aria-label":i("talk.addPeople","Add people"),onClick:e=>eH({kind:"person",anchor:e.currentTarget.getBoundingClientRect()}),children:(0,t.jsx)(t$,{n:"personPlus"})}),(0,t.jsx)("button",{"data-tip":i("talk.addAgents","Add agents"),ref:tn,className:"tlIconBtn","aria-haspopup":"dialog","aria-expanded":eB?.kind==="agent","aria-label":i("talk.addAgents","Add agents"),onClick:e=>eH({kind:"agent",anchor:e.currentTarget.getBoundingClientRect()}),children:(0,t.jsx)(t$,{n:"botPlus"})}),(0,t.jsx)("button",{"data-tip":i("talk.searchInRoom","Search this conversation"),className:"tlIconBtn","aria-pressed":eZ,"aria-label":i("talk.searchInRoom","Search this conversation"),onClick:()=>{eQ(!0),tC.current?.focus()},children:(0,t.jsx)(t$,{n:"search"})}),(0,t.jsx)("button",{"data-tip":i("talk.roomMenu","Conversation menu"),className:"tlIconBtn","aria-haspopup":"menu","aria-label":i("talk.roomMenu","Conversation menu"),onClick:e=>{let t=e.currentTarget.getBoundingClientRect();sj(t0,{x:t.right-226,y:t.bottom+4})},children:(0,t.jsx)(t$,{n:"more"})})]})]}),t0&&eZ&&(0,t.jsxs)("div",{className:"tlSearchBar poSearch",children:[(0,t.jsx)(t$,{n:"search",size:16}
31),(0,t.jsx)("input",{ref:tC,autoFocus:!0,type:"search",value:e0,placeholder:i("talk.searchInRoom","Search this conversation"),"aria-label":i("talk.messageSearch","Search messages"),onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),tz())},onChange:e=>e3(e.target.value)}),(0,t.jsx)("button",{type:"button","aria-label":i("talk.closeSearch","Close message search"),onClick:tz,children:(0,t.jsx)(t$,{n:"close",size:14})})]}),"threads"===td?j?(0,t.jsx)("div",{className:"tlThreadMain",children:sw(()=>y(null))}):(0,t.jsx)(ab,{rows:tm,onOpen:e=>{u.openChannel(e.channel_id),y(e.root)}}):"directory"===td?(0,t.jsx)(e2,{directory:al,meId:g,browse:u.browse,onMessage:e=>{tu(null),u.openDm(e)},onOpenChannel:e=>{tu(null),u.openChannel(e)},onJoinChannel:async e=>{await u.joinChannel(e)},onPersonMenu:ss}):"activity"===td?(0,t.jsx)(a_,{inbox:u.inbox,digest:u.digest,onOpen:e=>{tu(null),u.openChannel(e)}}):"drafts"===td?(0,t.jsx)(ax,{rows:sx.map(e=>({id:e,label:a8(e),text:tl[e]})),onOpen:e=>{tu(null),u.openChannel(e)},onDiscard:e=>ti(t=>tq(t,e,""))}):"huddles"===td?(0,t.jsx)(e7,{load:u.loadHuddleLog,channels:tJ,people:[...al.people,...al.agents],meId:g,speaking:u.speaking,liveIn:u.huddles,onOpenChannel:e=>{tu(null),u.openChannel(e)},onStartIn:e=>{ef(),tu(null),u.openChannel(e),u.joinHuddle(e).catch(e=>ee.toast.error(e instanceof Error?e.message:i("talk.huddleJoinFailed","Could not join the huddle")))},onStartWith:e=>{e.length&&(ef(),tu(null),(1===e.length?u.openDm(e[0]):u.openGroupDm(e)).then(e=>e&&u.joinHuddle(e.id)).catch(e=>ee.toast.error(e instanceof Error?e.message:i("talk.huddleJoinFailed","Could not join the huddle"))))}}):t0?(0,t.jsxs)(t.Fragment,{children:[u.huddle&&(0,t.jsx)(eN,{huddle:u.huddle,speaking:u.speaking,inHuddle:a7,voiceOn:u.voiceOn,muted:u.muted,onJoin:sr,onLeave:()=>void u.leaveHuddle(),onToggleMute:u.toggleMute}),u.pins.length>0&&(0,t.jsxs)("div",{className:"tlPinStrip",children:[(0,t.jsx)("span",{className:"tlPinReg",children:i("talk.pinned","PINNED")}),u.pins.map(e=>(0,t.jsx)("button",{className:"tlPinChip",onClick:()=>void u.togglePin(e.id),title:i("talk.unpin","Unpin"),children:(e.sender?.name??"")+": "+e.content.slice(0,48)},e.id))]}),u.streamDown&&(0,t.jsx)("div",{className:"tlOffline",role:"status",children:i("talk.reconnecting","Reconnecting â live updates are paused")}),(0,t.jsxs)("div",{className:"tlStream",ref:tk,onScroll:aR,children:[u.hasMore&&!e0&&(0,t.jsx)("button",{className:"po-btn po-btn--sm po-btn--rect tlOlder",disabled:u.loadingOlder,onClick:()=>void u.loadOlder().catch(()=>ee.toast.error(i("talk.loadOlderFailed","Could not load earlier messages"))),children:u.loadingOlder?i("talk.loadingOlder","LOADINGâ¦"):i("talk.loadOlder","LOAD EARLIER")}),(u.opening||u.loading)&&!t5.length?Array.from({length:5},(e,a)=>(0,t.jsxs)("div",{className:"tlRowSkel","aria-hidden":!0,children:[(0,t.jsx)("span",{className:"rlSkel"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:"22%"}}),(0,t.jsx)("span",{className:"rlSkel",style:{maxWidth:`${58+19*a%38}%`}})]})]},a)):(0,t.jsx)(at,{announce:eZ,caption:e0.trim()?i("talk.searchResults","{{count}} results",{count:ap.length}):t0.description||i("talk.introBlank","This is the beginning of the channel. Mention an agent with @ and it will answer here.")}),"forum"===t0.channel_type?(0,t.jsx)(ay,{messages:ap,onOpen:e=>{y(e),sd("thread")}}):(0,t.jsx)(ag,{messages:ap,unreadAnchor:u.unreadAnchor,meId:g,editing:I,setEditing:O,customEmoji:u.customEmoji,onOpenPicker:(e,t)=>te({message:e,rect:t}),onReply:e=>{e5(e),tN.current?.focus()},onThread:e=>{y(e),sd("thread")},onCopy:e=>st(e.content,i("talk.copied","Copied")),onReact:(e,t)=>{tZ.test(t)||tj(tX(t)),u.react(e.id,t)},onSaveEdit:(e,t)=>
31void u.editMessage(e.id,t).then(()=>O(null)),onMenu:sm,onCardReply:e=>void u.send(e)}),ar.map(e=>(0,t.jsxs)("article",{className:`tlRow tlRow--live${e.text?" isStreaming":""}`,children:[(0,t.jsx)("div",{className:"tlAv tlAv--bot",children:(0,t.jsx)(ej.TlIcon,{n:"bot",size:13})}),(0,t.jsxs)("div",{className:"tlRowBody",children:[(0,t.jsxs)("header",{className:"tlRowHead",children:[(0,t.jsx)("span",{className:"tlWho",children:a4.get(e.agentId)??i("talk.agent","Agent")}),(0,t.jsx)("span",{className:"tlBotMark",children:i("talk.agent","Agent")}),(0,t.jsx)("span",{className:"tlWhen",children:e.outcome?i("talk.turnEnded","ENDED"):i("talk.working","WORKING")})]}),e.text?(0,t.jsx)(ad,{content:e.text}):!e.outcome&&(0,t.jsx)("div",{className:"tlPulse","aria-hidden":!0}),"failed"===e.outcome&&(0,t.jsxs)("div",{className:"tlBodyText tlGone",children:[i("talk.turnFailed","This agent could not finish."),e.error?` ${e.error}`:""]}),"silent"===e.outcome&&(0,t.jsx)("div",{className:"tlBodyText tlGone",children:i("talk.turnSilent","This agent had nothing to add.")})]})]},e.turnId))]}),(0,t.jsxs)("div",{className:"tlDock",children:[!P&&(0,t.jsx)("button",{className:`tlJump${aM>0?" tlJump--new":""}`,onClick:aD,children:aM>0?i("talk.newMessages","{{count}} NEW MESSAGES",{count:aM}):i("talk.jumpLatest","JUMP TO LATEST")}),null!==N&&aP.length>0&&(0,t.jsx)("div",{className:"tlMentions",role:"listbox",ref:a$,"aria-label":i("talk.mentionList","Mention someone"),children:aP.map((e,a)=>(0,t.jsxs)("button",{role:"option","aria-selected":a===aL,className:a===aL?"on":"",onMouseEnter:()=>aF(a),onMouseDown:t=>{t.preventDefault(),aG(e)},children:[(0,t.jsx)(e1,{actor:e,size:22}),(0,t.jsx)("span",{className:"tlMentionN",children:e.name}),e.is_agent&&(0,t.jsx)("span",{className:"tlBotMark",children:i("talk.agent","Agent")}),!e.in_channel&&(0,t.jsx)("span",{className:"tlMentionAdd",children:i("talk.willJoin","WILL JOIN")})]},t7(e)))}),e4&&(0,t.jsxs)("div",{className:"tlReplyDraft",children:[(0,t.jsx)(t$,{n:"reply",size:17}),(0,t.jsxs)("div",{children:[(0,t.jsx)("strong",{children:i("talk.replyTo","Reply to {{name}}",{name:e4.sender?.name??""})}),(0,t.jsx)("span",{children:af(e4.content).slice(0,100)||i("talk.attachmentLine","Attachment")})]}),(0,t.jsx)("button",{className:"tlIconBtn","aria-label":i("talk.cancelReply","Cancel reply"),onClick:()=>e5(null),children:(0,t.jsx)(t$,{n:"close",size:16})})]}),(ey.length>0||ek.length>0)&&(0,t.jsxs)("div",{className:"tlPending",children:[ey.map((e,a)=>(0,t.jsx)(es,{name:e.name,mime:e.type,size:e.size,file:e,onRemove:()=>{ew(e=>e.filter((e,t)=>t!==a)),tN.current?.focus()}},`${e.name}:${a}`)),ek.map((e,a)=>(0,t.jsx)(es,{name:e.filename,mime:e.mime_type,size:e.file_size,url:e.file_url,onRemove:()=>{eC(e=>e.filter((e,t)=>t!==a)),tN.current?.focus()}},`room:${e.file_url}:${a}`))]}),e_&&(0,t.jsx)(t_.RoomPicker,{onClose:()=>eT(!1),onAttach:e=>eC(t=>[...t,...e].slice(0,t_.ROOM_PICK_MAX))}),(0,t.jsxs)("div",{className:"chatComposer tlCompose",children:[(0,t.jsxs)(l.DropdownMenu.Root,{open:e6,onOpenChange:e8,modal:!1,children:[(0,t.jsx)(l.DropdownMenu.Trigger,{asChild:!0,children:(0,t.jsx)("button",{className:"cdIcon tlPlus",title:i("talk.addMenu","Attach and tools"),"aria-label":i("talk.addMenu","Attach and tools"),children:(0,t.jsx)(t$,{n:"plus",size:20})})}),(0,t.jsxs)(l.DropdownMenu.Content,{className:"tlPlusMenu",side:"top",align:"start",sideOffset:10,collisionPadding:8,onCloseAutoFocus:e=>{document.activeElement?.closest(".tlEditor, .roomPick")&&e.preventDefault()},children:[(0,t.jsx)(l.DropdownMenu.Item,{asChild:!0,onSelect:()=>tH.current?.click(),children:(0,t.jsxs)("button",{children:[(0,t.jsx)(t$,{n:"file",size:18}),i("talk.attach","Attach a file")]})}),(0,t.jsx)(l.DropdownMenu.Item,{asChild:!0,onSelect:()=>eT(e=>!e),children:(0,t.jsxs)("button",{children:[(0,t.jsx)(t$,{n:"folder",size:18}),i("talk.attachFromRoom","Attach from Drive")]})}),(0,t.jsx)(l.DropdownMenu.Item,{asChild:!0,onSelect:()=>aV("@"),children:(0,t.jsxs)("button",{children:[(0,t.jsx)(ej.TlIcon,{n:"at",size:18}),i("talk.mention","Mention someone")]})})]})]}),(0,t.jsx)("input",{ref:tH,type:"file",multiple:!0,hidden:!0,accept:tF,onChange:e=>{aq(e.target.files),e.target.value=""}}
31),(0,t.jsx)("div",{className:"cdMain",children:(0,t.jsx)(tg,{ref:tN,value:f,onChange:aU,onMention:C,ariaLabel:i("talk.messageInput"),placeholder:i("talk.messagePlaceholder","Type a message"),onSubmit:()=>void aW(),onFiles:aq,onKeyDown:e=>{if(null===N||0===aP.length)return!1;if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let t="ArrowDown"===e.key?1:-1;return aF(e=>(e+t+aP.length)%aP.length),!0}return"Home"===e.key||"End"===e.key?(e.preventDefault(),aF("Home"===e.key?0:aP.length-1),!0):("Enter"===e.key||"Tab"===e.key)&&!e.shiftKey&&(e.preventDefault(),aG(aP[aL]??aP[0]),!0)}})}),(0,t.jsx)(tT.MicButton,{onNote:e=>void aJ(e)},t1),(0,t.jsx)("button",{className:"cdIcon tlEmojiBtn",title:i("talk.emoji","Emoji"),"aria-label":i("talk.emojiPicker","Emoji and stickers"),"aria-haspopup":"dialog","aria-expanded":!!(e9&&!e9.message),onClick:e=>{e.currentTarget.focus(),te({rect:e.currentTarget.getBoundingClientRect()})},children:(0,t.jsx)(t$,{n:"smile",size:20})}),(0,t.jsx)("button",{className:"cdSend","aria-busy":eE,"aria-label":i("talk.send","Send"),title:i("talk.send","Send"),onClick:()=>void aW(),disabled:eE||!f.trim()&&0===ey.length&&0===ek.length,children:(0,t.jsx)(t$,{n:"arrowUp",size:18})})]}),ao.length>0&&(0,t.jsx)("p",{className:"tlComposeNote",role:"status",children:i("talk.typing","{{who}} is typing",{who:ao.join(", ")})})]})]}):(0,t.jsx)("div",{className:"tlEmpty",children:(0,t.jsxs)("div",{className:"tlNoConv",children:[(0,t.jsx)(t$,{n:"chat",size:30}),(0,t.jsx)("span",{className:"tlNoConvLead",children:i("talk.noConvLead","Pick a conversation on the left, or start a new one.")}),(0,t.jsx)("button",{className:"tlBtn tlBtn--primary",onClick:()=>e$(!0),children:i("talk.newTalk","New chat")})]})})]}),t0&&b&&"threads"!==td&&(0,t.jsx)("div",{className:"tlGrip",role:"separator","aria-orientation":"vertical","aria-label":i("talk.resizePane","Resize the pane"),"aria-valuenow":Math.round(eP),tabIndex:0,onPointerDown:az,onDoubleClick:()=>{eL(380),localStorage.setItem(t2,String(380))},onKeyDown:e=>{let t="ArrowLeft"===e.key?24:"ArrowRight"===e.key?-24:0;if(!t)return;e.preventDefault();let a=t4(e.currentTarget);eL(e=>{let s=t3(e+t,a);return localStorage.setItem(t2,String(s)),s})}}),t0&&b&&"threads"!==td&&(0,t.jsxs)("aside",{className:`tlAux${eI?" tlAux--open":""}`,style:{"--tl-aux-w":`${eP}px`},children:[(0,t.jsxs)("div",{className:"spvTabs",role:"tablist",children:[ts.map(e=>(0,t.jsx)("button",{role:"tab","aria-selected":b===e,className:`spvTab${b===e?" on":""}`,onClick:()=>sd(e),children:so[e]},e)),(0,t.jsx)("button",{className:"spvTab tlAuxClose",onClick:()=>{v(null),eO(!1)},children:i("talk.close","CLOSE")})]}),"rules"===b?(0,t.jsx)(aw,{rules:u.rules,agents:u.participants.filter(e=>e.is_agent),onCreate:u.createRule,onToggle:u.toggleRule,onDelete:u.deleteRule}):"runs"===b?(0,t.jsx)(ak,{turns:u.turnLog,loadTranscript:u.loadTranscript,onResumed:async()=>{await u.loadTurns()}}):"search"===b?(0,t.jsx)(aN,{query:z,setQuery:U,hits:G,status:et,onRetry:()=>el(e=>
31e+1),openingHit:K,here:ei,setHere:er,room:a5,onOpen:e=>{a2(e)}}):sw()]})]}),F&&(0,t.jsx)(aC,{scope:F.scope,rows:F.rows,onScope:e=>void aQ(e),onClose:()=>$(null),onOpen:e=>{$(null),u.openChannel(e)},onJoin:async e=>{await u.joinChannel(e),await aQ(F.scope)},onLeave:async e=>{await u.leaveChannel(e),await aQ(F.scope)}}),B&&a9&&(0,t.jsxs)(s.OverlayPortal,{children:[(0,t.jsx)("button",{className:"tlBrowseScrim","aria-label":i("talk.close","Close"),onClick:()=>H(null)}),(0,t.jsx)(ta,{channel:a9,label:a8(B.id),tab:B.tab,setTab:e=>H({...B,tab:e}),participants:t8,directory:al,meId:g,draft:B,setDraft:e=>H({...B,...e}),emojiSection:(0,t.jsx)(ae,{items:u.customEmoji,onCreate:u.createCustomEmoji,onDelete:u.deleteCustomEmoji}),onClose:()=>H(null),onSave:async()=>{await u.updateChannel(B.id,{topic:B.topic,description:B.description}),H(null)},onAdd:async e=>{try{await u.addToChannel(e),(0,ee.toast)(i("talk.agentAdded","{{name}} joined the channel",{name:e.name}))}catch(t){ee.toast.error(t instanceof Error?t.message:i("talk.agentAddFailed","Could not add {{name}}",{name:e.name}))}},onRemove:(e,t)=>void u.removeFromChannel(e).then(()=>(0,ee.toast)(i("talk.cdRemoved","{{name}} left the channel",{name:t}))).catch(e=>ee.toast.error(e instanceof Error?e.message:i("talk.cdRemoveFailed","Could not remove them"))),onRole:(e,t,a)=>void u.setAgentMode(e,{role:t}).then(()=>(0,ee.toast)(i("talk.cdRoleSet","{{name}} is now {{role}}",{name:a,role:t}))).catch(e=>ee.toast.error(e instanceof Error?e.message:i("talk.cdRoleFailed","Could not change their role"))),onMode:(e,t)=>void u.setAgentMode(e,t),onDm:e=>{H(null),u.openDm(e)},onMenu:ss,onExport:e=>u.exportChannel(e,B.id),onArchive:()=>void u.updateChannel(B.id,{archived:!a9.archived})})]}),ex&&(0,t.jsx)(tS,{anchor:ex.anchor,customEmoji:u.customEmoji,allowSend:"compose"===ex.on.kind,onPick:aY,onClose:()=>ev(null)}),eF&&(0,t.jsx)(tB,{mode:"new",kind:"all",directory:al,meId:g,existing:new Set,directoryLoading:u.directoryLoading,directoryError:u.directoryError,onRetryDirectory:()=>void u.loadDirectory(),onClose:()=>e$(!1),onConfirm:async(e,t)=>{await (1===e.length?u.openDm(e[0]):u.openGroupDm(e,t)),tu(null),eJ()}}),eB&&t0&&(0,t.jsx)(tB,{mode:"add",kind:eB.kind,anchor:eB.anchor,directory:al,meId:g,existing:aO,directoryLoading:u.directoryLoading,directoryError:u.directoryError,onRetryDirectory:()=>void u.loadDirectory(),returnFocus:"agent"===eB.kind?tn:tt,onClose:()=>eH(null),onConfirm:async([e])=>{await u.addToChannel(e),(0,ee.toast)(i("talk.agentAdded","{{name}} joined the channel",{name:e.name}))}},`${t0.id}:${eB.kind}`),ez&&t0&&(0,t.jsx)(tG,{label:a5,meta:a6,participants:t8,meId:g,onClose:()=>eU(!1),onAddPeople:()=>{eU(!1),eH({kind:"person",anchor:tt.current?.getBoundingClientRect()??null})},onAddAgents:()=>{eU(!1),eH({kind:"agent",anchor:tn.current?.getBoundingClientRect()??null})},onMenu:(e,t)=>{eU(!1),ss(e,t)}}),e9&&(0,t.jsx)(an,{rect:e9.rect,label:i(e9.message?"talk.addReaction":"talk.emoji",e9.message?"Add reaction":"Emoji"),choices:e9.message?aa:as,moreLabel:i(e9.message?"talk.moreReactions":"talk.emojiPicker",e9.message?"More reactions":"Emoji and stickers"),onClose:()=>te(null),onPick:e=>{tj(e),e9.message?u.react(e9.message.id,e):aV(e),te(null)},onMore:()=>{ev({on:e9.message?{kind:"react",message:e9.message}:{kind:"compose"},anchor:{rect:e9.rect,place:e9.rect.top>window.innerHeight/2?"above":"below"}}),te(null)}}),null!==T&&(0,t.jsxs)(s.OverlayPortal,{children:[(0,t.jsx)("button",{className:"tlBrowseScrim","aria-label":i("talk.close","Close"),onClick:()=>E(null)}),(0,t.jsx)(tW,{draft:T,setDraft:e=>{R(null),E(e)},error:A,busy:D,onClose:()=>E(null),onCreate:()=>void a1()})]}),ep&&(0,t.jsx)(tU,{name:ep.name,returnTo:ep.opener,onClose:()=>eg(null),onSave:e=>u.updateChannel(ep.id,{name:e})},ep.id),em&&(0,t.jsx)(eu.PoContextMenu,{ctx:em,onClose:()=>eh(null)}),(0,t.jsx)(eS,{invite:u.invite,inviteLabel:u.invite?a8(u.invite.channelId):"",inviteRoster:sl,onAnswer:si,onDismiss:u.dismissInvite,mine:sn,mineLabel:u.huddleChannelId?a8(u.huddleChannelId):"",speaking:u.speaking,muted:u.muted,voiceOn:u.voiceOn,onOpenRoom:e=>void u.openChannel(e),onToggleMute:u.toggleMute,onLeave:()=>void u.leaveHuddle()})]})}],621680);var aP=e.i(540956),aL=e.i(278126);function aF(e,t,a){return e.filter(e=>e.id!==a&&e.gx<t.gx+t.gw&&t.gx<e.gx+e.gw&&e.gy<t.gy+t.gh&&t.gy<e.gy+e.gh)}
31function a$(e){let t=Math.max(1,Math.min(aL.PO_GRID_COLS,Math.round(e.gw))),a=Math.max(1,Math.round(e.gh));return{gx:Math.max(0,Math.min(aL.PO_GRID_COLS-t,Math.round(e.gx))),gy:Math.max(0,Math.round(e.gy)),gw:t,gh:a}}function aB(e,t,a){let s=e.reduce((e,t)=>Math.max(e,t.gy+t.gh),0);for(let n=0;n<=s;n++)for(let s=0;s<=aL.PO_GRID_COLS-t;s++)if(0===aF(e,{gx:s,gy:n,gw:t,gh:a}).length)return{gx:s,gy:n};return{gx:0,gy:s}}function aH(e,t,a,s){let n=e.find(e=>e.id===t);if(!n)return e;let l=a$({...n,gx:a,gy:s}),i=e.map(e=>e.id===t?{...e,gx:l.gx,gy:l.gy}:{...e});for(let e=0;e<500;e++){let e=!1;for(let a of[...i].sort((e,t)=>e.gy-t.gy||e.gx-t.gx)){let s=aF(i,a,a.id).find(e=>e.id===t||e.gy<=a.gy);s&&a.id!==t&&(a.gy=s.gy+s.gh,e=!0)}if(!e)break}return i}function az(e){let t=[...e].sort((e,t)=>e.gy-t.gy||e.gx-t.gx),a=[];for(let e of t){let t={...e};for(;t.gy>0;){let e={...t,gy:t.gy-1};if(aF(a,e).length>0)break;t.gy=e.gy}a.push(t)}return a}let aU="orgOps",aG=["orgOps","agentCommand","executive","finance","sales","hr","ecommerce","marketing","operations"];function aW(e,t,a,s,n,l={}){return{id:(0,aL.newWidgetId)(e),type:e,gx:t,gy:a,gw:s,gh:n,config:l}}function aK(e,t,a,s,n){let{label:l,visual:i,binding:r,...o}=n;return{id:(0,aL.newWidgetId)("data"),type:"data",gx:e,gy:t,gw:a,gh:s,label:l,config:{binding:r,visual:i,...o}}}let aV={kind:"tasks.stats"},aY={kind:"llm.usage",params:{range:"30d",bucket:"total"}},aq={kind:"llm.usage",params:{range:"30d",bucket:"day"}},aJ={kind:"llm.usage",params:{range:"30d",bucket:"total",group_by:"model"}},aX={orgOps:()=>[aW("hero",0,0,12,7),aW("kpi-strip",0,7,12,4,{range:"7d"}),aW("run-volume",0,11,6,9,{days:14}),aW("active-org",6,11,3,9),aW("teams",9,11,3,9),aW("members",0,20,6,9),aW("task-stats",6,20,3,9,{range:"7d"}),aW("org-apps",9,20,3,9)],agentCommand:()=>[aK(0,0,3,4,{label:"AGENTS ACTIVE",visual:"stat",binding:{kind:"agents.workload"},valueKey:"active_count"}),aK(3,0,3,4,{label:"OPEN TASKS",visual:"stat",binding:aV,valueKey:"open"}),aK(6,0,3,4,{label:"AI SPEND 30D",visual:"stat",binding:aY,valueKey:"cost_usd",prefix:"$"}),aK(9,0,3,4,{label:"PENDING DECISIONS",visual:"stat",binding:{kind:"loops.summary"},valueKey:"pending_decisions"}),aK(0,4,6,9,{label:"TASKS 30D",visual:"sparkline",binding:{kind:"tasks.timeseries",params:{range:"30d"}},labelKey:"date",valueKey:"created"}),aK(6,4,6,9,{label:"AI COST 30D",visual:"vbars",binding:aq,labelKey:"date",valueKey:"cost_usd"}),aK(0,13,6,9,{label:"RECENT AGENT RUNS",visual:"table",binding:{kind:"agents.runs",params:{limit:8}}}),aK(6,13,3,9,{label:"TASKS BY AGENT",visual:"bars",binding:{kind:"tasks.by_agent"},labelKey:"agent",valueKey:"count"}),aK(9,13,3,9,{label:"LOOPS",visual:"list",binding:{kind:"loops.summary"},labelKey:"title",valueKey:"status"})],executive:()=>[aW("kpi-strip",0,0,12,4,{range:"30d"}),aK(0,4,3,4,{label:"AI SPEND 30D",visual:"stat",binding:aY,valueKey:"cost_usd",prefix:"$"}),aK(3,4,3,4,{label:"TASKS DONE 30D",visual:"stat",binding:aV,valueKey:"completed_month"}),aK(6,4,3,4,{label:"COMPLETION RATE",visual:"stat",binding:aV,valueKey:"conversion",suffix:"%"}),aK(9,4,3,4,{label:"OVERDUE",visual:"stat",binding:aV,valueKey:"overdue"}),aW("run-volume",0,8,6,9,{days:30}),aK(6,8,3,9,{label:"TASKS BY STATUS",visual:"donut",binding:{kind:"tasks.by_status"},labelKey:"status",valueKey:"count"}),aK(9,8,3,9,{label:"AGENT WORKLOAD",visual:"bars",binding:{kind:"agents.workload"},labelKey:"agent",valueKey:"open"}),aK(0,17,6,9,{label:"REVENUE â CONNECT YOUR SOURCE",visual:"sparkline",binding:null}),aW("members",6,17,6,9)],finance:()=>[aK(0,0,3,4,{label:"AI SPEND 30D",visual:"stat",binding:aY,valueKey:"cost_usd",prefix:"$"}),aK(3,0,3,4,{label:"LLM CALLS 30D",visual:"stat",binding:aY,valueKey:"calls"}),aK(6,0,3,4,{label:"TOKENS IN 30D",visual:"stat",binding:aY,valueKey:"input_tokens"}),aK(9,0,3,4,{label:"ROUTINE RUNS 7D",visual:"stat",binding:{kind:"routines.executions",params:{range:"7d"}},valueKey:"total"}),aK(0,4,6,9,{label:"AI SPEND TREND 30D",visual:"sparkline",binding:aq,labelKey:"date",valueKey:"cost_usd"}),aK(6,4,3,9,{label:"COST BY MODEL",visual:"donut",binding:aJ,labelKey:"model",valueKey:"cost_usd"}),aK(9,4,3,9,{label:"AR AGING â CONNECT YOUR SOURCE",visual:"bars",binding:null}),aK(0,13,6,9,{label:"USAGE LEDGER",visual:"table",binding:aq}),aK(6,13,6,9,{label:"REVENUE VS EXPENSES â CONNECT YOUR SOURCE",visual:"vbars",binding:null})],sales:()=>[aK(0,0,3,4,{label:"OPEN PIPELINE",visual:"stat",binding:aV,valueKey:"open"}),aK(3,0,3,4,{label:"CONVERSION",visual:"stat",binding:aV,valueKey:"conversion",suffix:"%"}),aK(6,0,3,4,{label:"CLOSED 30D",visual:"stat",binding:aV,valueKey:"completed_month"}),aK(9,0,3,4,{label:"IN PROGRESS",visual:"stat",binding:aV,valueKey:"in_progress"}),aK(0,4,4,9,{label:"PIPELINE BY STAGE",visual:"bars",binding:{kind:"tasks.by_status"},labelKey:"status",valueKey:"count"}),aK(4,4,5,9,{label:"ACTIVITY 30D",visual:"sparkline",binding:{kind:"tasks.timeseries",params:{range:"30d"}},labelKey:"date",valueKey:"created"}),aK(9,4,3,9,{label:"BY OWNER",visual:"bars",binding:{kind:"tasks.by_agent"},labelKey:"agent",valueKey:"count"}),aK(0,13,7,9,{label:"TOP DEALS â CONNECT YOUR CRM",visual:"table",binding:null}),aK(7,13,5,9,{label:"BOOKINGS â CONNECT YOUR SOURCE",visual:"vbars",binding:null})],hr:()=>[aW("kpi-strip",0,0,12,4,{range:"30d"}),aW("teams",0,4,4,9),aW("members",4,4,8,9),aK(0,13,4,9,{label:"HIRING PIPELINE â CONNECT YOUR ATS",visual:"bars",binding:null}),aK(4,13,4,9,{label:"TASKS BY STATUS",visual:"donut",binding:{kind:"tasks.by_status"},labelKey:"status",valueKey:"count"}),aK(8,13,4,9,{label:"ANNIVERSARIES â CONNECT YOUR SOURCE",visual:"list",binding:null})],ecommerce:()=>[aK(0,0,3,4,{label:"REVENUE TODAY â CONNECT",visual:"stat",binding:null}),aK(3,0,3,4,{label:"ORDERS â CONNECT",visual:"stat",binding:null}),aK(6,0,3,4,{label:"OPEN TASKS",visual:"stat",binding:aV,valueKey:"open"}),aK(9,0,3,4,{label:"AUTOMATION RUNS 7D",visual:"stat",binding:{kind:"routines.executions",params:{range:"7d"}},valueKey:"total"}),aK(0,4,6,9,{label:"REVENUE 30D â CONNECT YOUR STORE",visual:"sparkline",binding:null}),aK(6,4,3,9,{label:"TRAFFIC â CONNECT ANALYTICS",visual:"donut",binding:null}),aK(9,4,3,9,{label:"TASKS BY STATUS",visual:"donut",binding:{kind:"tasks.by_status"},labelKey:"status",valueKey:"count"}),aK(0,13,7,9,{label:"TOP PRODUCTS â CONNECT YOUR STORE",visual:"table",binding:null}),aW("task-stats",7,13,5,9,{range:"7d"})],marketing:()=>[aK(0,0,3,4,{label:"SESSIONS â CONNECT",visual:"stat",binding:null}),aK(3,0,3,4,{label:"LEADS â CONNECT",visual:"stat",binding:null}),aK(6,0,3,4,{label:"OPEN TASKS",visual:"stat",binding:aV,valueKey:"open"}),aK(9,0,3,4,{label:"AI SPEND 30D",visual:"stat",binding:aY,valueKey:"cost_usd",prefix:"$"}),aK(0,4,6,9,{label:"LEADS BY CHANNEL â CONNECT ANALYTICS",visual:"vbars",binding:null}),aK(6,4,3,9,{label:"FUNNEL â CONNECT ANALYTICS",visual:"bars",binding:null}),aK(9,4,3,9,{label:"KNOWLEDGE BASE",visual:"donut",binding:{kind:"okg.stats",params:{view:"by_type"}},labelKey:"type",valueKey:"count"}),aK(0,13,7,9,{label:"CAMPAIGNS â CONNECT YOUR SOURCE",visual:"table",binding:null}),aK(7,13,5,9,{label:"CONTENT ACTIVITY 30D",visual:"sparkline",binding:{kind:"tasks.timeseries",params:{range:"30d"}},labelKey:"date",valueKey:"created"})],operations:()=>[aK(0,0,3,4,{label:"OPEN TASKS",visual:"stat",binding:aV,valueKey:"open"}),aK(3,0,3,4,{label:"OVERDUE",visual:"stat",binding:aV,valueKey:"overdue"}),aK(6,0,3,4,{label:"DONE 7D",visual:"stat",binding:aV,valueKey:"completed_week"}),aK(9,0,3,4,{label:"ROUTINE RUNS 7D",visual:"stat",binding:{kind:"routines.executions",params:{range:"7d"}},valueKey:"total"}),aK(0,4,4,9,{label:"TASKS BY STATUS",visual:"donut",binding:{kind:"tasks.by_status"},labelKey:"status",valueKey:"count"}),aK(4,4,5,9,{label:"TASK FLOW 30D",visual:"sparkline",binding:{kind:"tasks.timeseries",params:{range:"30d"}},labelKey:"date",valueKey:"created"}),aW("task-stats",9,4,3,9,{range:"7d"}),aK(0,13,6,9,{label:"TASKS BY AGENT",visual:"bars",binding:{kind:"tasks.by_agent"},labelKey:"agent",valueKey:"count"}),aK(6,13,6,9,{label:"INSTALLED APPS",visual:"table",binding:{kind:"apps.installed"}})]};function aZ(e){return(0,aX[e in aX?e:aU])()}function aQ(e){return{...e,tabs:e.tabs.map(e=>({...e,widgets:az(e.widgets)}))}}var a0=e.i(741979),a1=e.i(543679),a2=e.i(762603),a3=e.i(569552),a4=e.i(521135),a5=e.i(274883);let a6={today:1,"7d":7,"30d":30};function a7(e,t){let s,n,l,i,r,o,d,c=(0,a.c)(20),u=Date.now(),m=(a6[t]??7)*864e5;if(c[0]!==m||c[1]!==e){let t,a;c[8]!==m?(t=e=>!e.created_at||u-Date.parse(e.created_at)<=m,c[8]=m,c[9]=t):t=c[9];let d=e.filter(t),h=e=>d.filter(t=>t.status===e).length;if(c[10]!==e){let t;c[12]===Symbol.for("react.memo_cache_sentinel")?(t=e=>e.due_date&&Date.parse(e.due_date)>
31u||e.routine_id,c[12]=t):t=c[12],a=e.filter(t),c[10]=e,c[11]=a}else a=c[11];s=a.length,n=d.length,l=h("in_progress"),i=h("pending"),r=h("completed"),o=h("failed"),c[0]=m,c[1]=e,c[2]=s,c[3]=n,c[4]=l,c[5]=i,c[6]=r,c[7]=o}else s=c[2],n=c[3],l=c[4],i=c[5],r=c[6],o=c[7];return c[13]!==s||c[14]!==n||c[15]!==l||c[16]!==i||c[17]!==r||c[18]!==o?(d={runs:n,running:l,pending:i,done:r,failed:o,nextRuns:s},c[13]=s,c[14]=n,c[15]=l,c[16]=i,c[17]=r,c[18]=o,c[19]=d):d=c[19],d}function a8(e){return(e??"member").replace(/_/g," ").toUpperCase()}function a9(e){return e.is_active}function se(e){return(0,t.jsxs)("div",{className:"dbKpi",children:[(0,t.jsx)("span",{className:"kl",children:e.label}),(0,t.jsx)("span",{className:`kv${e.live?" live":""}`,children:e.value})]},e.label)}function st(e){return e.is_active}function sa(e){return(0,t.jsxs)("div",{className:"dbAgentRow",title:e.meta,children:[(0,t.jsx)("i",{style:{background:e.color}}),(0,t.jsx)("span",{children:e.name}),(0,t.jsx)("em",{children:(0,t.jsx)("strong",{style:{width:e.pct,background:e.color}})}),(0,t.jsx)("b",{children:e.n})]},e.name)}function ss(e){return e.member_count}function sn(e){return e.name}function sl(e){return(0,t.jsxs)("div",{children:[(0,t.jsx)("small",{children:e.status.toUpperCase()}),(0,t.jsx)("span",{children:e.title})]},`run-${e.id}`)}function si(e){return"in_progress"===e.status}function sr(e,t){return Date.parse(t.updated_at||t.created_at)-Date.parse(e.updated_at||e.created_at)}function so(e){return"restricted"===e.app_access_mode}let sd=new Map,sc=new Map,su=new Set(["mcp.tool","broker.service"]);function sm(e,t){let a=(0,r.useMemo)(()=>e?JSON.stringify(e):"",[e]),[s,n]=(0,r.useState)(()=>a?sd.get(a)?.data??null:null),[l,i]=(0,r.useState)(!!a&&!sd.has(a)),[o,d]=(0,r.useState)(null),[c,u]=(0,r.useState)(()=>a?sd.get(a)?.ts??null:null),m=(0,r.useRef)(e);m.current=e;let h=(0,r.useCallback)(async(e=!1)=>{let a=m.current;if(!a)return;let s=JSON.stringify(a);if("static"===a.kind){n(a.params?.data??null),i(!1);return}let l=1e3*Math.max(15,t??60),r=sd.get(s);if(!e&&r&&Date.now()-r.ts<l){n(r.data),u(r.ts),i(!1);return}try{let e=sc.get(s);e||(e=(async()=>{let e=await (0,tA.apiFetch)("/api/v1/insights-dashboards/data/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!e.ok){let t=`request failed (${e.status})`;try{let a=await e.json();"string"==typeof a?.detail?t=a.detail:"string"==typeof a?.error&&(t=a.error)}catch{}throw Error(t)}return e.json()})().finally(()=>sc.delete(s)),sc.set(s,e));let t=await e;if(sd.size>=300)for(let e of[...sd.keys()].slice(0,75))sd.delete(e);sd.set(s,{ts:Date.now(),data:t}),n(t),u(sd.get(s)?.ts??Date.now()),d(null)}catch(e){d(e instanceof Error?e.message:"failed to load")}finally{i(!1)}},[t]);return(0,r.useEffect)(()=>{if(!a){n(null),i(!1);return}i(!sd.has(a)),h();let e=m.current?.kind??"",s=Math.max(15,t??60);su.has(e)&&(s=Math.max(30,s));let l=window.setInterval(()=>{document.hidden||h(!0)},1e3*s),r=()=>{document.hidden||h()};return document.addEventListener("visibilitychange",r),()=>{window.clearInterval(l),document.removeEventListener("visibilitychange",r)}},[a,h,t]),{data:s,loading:l,error:o,updatedAt:c,refetch:()=>h(!0)}}var sh=e.i(770062);let sp={today:"1d","7d":"7d","30d":"30d"};function sg(e,t){let a=Number(e.config.limit);return Number.isFinite(a)?Math.min(50,Math.max(1,Math.round(a))):t}function sf(e){let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:0}function sx(e){if("string"!=typeof e)return"â";let t=Date.now()-Date.parse(e);if(!Number.isFinite(t))return"â";let a=Math.max(0,Math.round(t/6e4));return a<60?`${a}m`:a<1440?`${Math.round(a/60)}h`:`${Math.round(a/1440)}d`}function sb(e){let t=sf(e);return t<1024?`${t}B`:t<1048576?`${Math.round(t/1024)}KB`:`${(t/1048576).toFixed(1)}MB`}function sv(e,t){return e.columns.indexOf(t)}function sj(e,s){let n,l,i=(0,a.c)(24),{t:r}=(0,Z.useTranslation)("paletteOs"),{data:o,loading:d,error:c,refetch:u}=sm(e,void 0===s?60:s);i[0]!==o?(n=(0,sh.normalizeColumnar)(o),i[0]=o,i[1]=n):n=i[1];let m=n,h=c??m.error,p=null;if(d&&null==o){let e,a,s,n,l;i[2]!==r?(e=r("dashboard.loading","LOADING"),i[2]=r,i[3]=e):e=i[3],i[4]===Symbol.for("react.memo_cache_sentinel")?(a=(0,t.jsx)("span",{}),s=(0,t.jsx)("span",{}),n=(0,t.jsx)("span",{}),i[4]=a,i[5]=s,i[6]=n):(a=i[4],s=i[5],n=i[6]),i[7]!==e?(l=(0,t.jsxs)("div",{className:"pvSkel","aria-label":e,role:"status",children:[a,s,n]}),i[7]=e,i[8]=l):l=i[8],p=l}else if(h){let e,a,s,n,l;i[9]!==h?(e=(0,t.jsx)("span",{className:"dbEmpty",children:h}),i[9]=h,i[10]=e):e=i[10],i[11]!==u?(a=()=>u(),i[11]=u,i[12]=a):a=i[12],i[13]!==r?(s=r("widgetConfig.retry","RETRY"),i[13]=r,
31i[14]=s):s=i[14],i[15]!==a||i[16]!==s?(n=(0,t.jsx)("button",{className:"pvRetry",onClick:a,children:s}),i[15]=a,i[16]=s,i[17]=n):n=i[17],i[18]!==e||i[19]!==n?(l=(0,t.jsxs)("div",{className:"pvError",children:[e,n]}),i[18]=e,i[19]=n,i[20]=l):l=i[20],p=l}return i[21]!==p||i[22]!==m?(l={data:m,fallback:p},i[21]=p,i[22]=m,i[23]=l):l=i[23],l}let sy={completed:"var(--dnk-pos)",running:"var(--dnk-info)",failed:"var(--dnk-neg)"};var sw=e.i(534959),sk=e.i(477592),sN=e.i(512611);function sC({label:e,binding:a,rationale:s}){let{t:n}=(0,Z.useTranslation)("paletteOs"),[l,i]=(0,r.useState)(null),[o,d]=(0,r.useState)(null);return(0,r.useEffect)(()=>{let t=!1;return(0,tA.apiFetch)("/api/v1/insights-dashboards/po/explain",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:e,binding:a})}).then(e=>e.json()).then(e=>{t||(e?.error?d(String(e.error)):i(String(e?.text??"")))}).catch(()=>{t||d(n("widgetConfig.explainFailed","Explain failed â try again"))}),()=>{t=!0}},[]),(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[(0,t.jsx)("div",{className:"gcTitle",children:e}),s?(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:n("widgetConfig.rationaleTitle","WHY THIS WIDGET")}),(0,t.jsx)("div",{className:"wcExplain",children:s})]}):null,(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:n("widgetConfig.explainTitle","AI READ")}),null===l&&!o&&(0,t.jsx)("span",{className:"dbEmpty",children:n("widgetConfig.explaining","READING THE DATAâ¦")}),o&&(0,t.jsx)("span",{className:"dbEmpty",children:o}),l&&(0,t.jsx)("div",{className:"wcExplain",children:l})]})]})}let sS=new Set(["area","sparkline","line"]),s_=new Set(["area","line","sparkline","step-line","vbars","stacked-bar"]),sT={year:"quarter",quarter:"month",month:"day",week:"day",day:"hour"};function sE(e){let s,n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j=(0,a.c)(44),{x:y,existing:w,onSave:k,onRemove:N}=e,{t:C}=(0,Z.useTranslation)("paletteOs"),[S,_]=(0,r.useState)("");j[0]!==C?(s=C("widgetConfig.annotateTitle","ANNOTATE"),j[0]=C,j[1]=s):s=j[1],j[2]!==y?(n=y.slice(0,19),j[2]=y,j[3]=n):n=j[3],j[4]!==s||j[5]!==n?(l=(0,t.jsxs)("div",{className:"gcTitle",children:[s," â ",n]}),j[4]=s,j[5]=n,j[6]=l):l=j[6],j[7]!==C?(i=C("widgetConfig.annotateNote","NOTE"),j[7]=C,j[8]=i):i=j[8],j[9]!==i?(o=(0,t.jsx)("label",{htmlFor:"annotate-note",children:i}),j[9]=i,j[10]=o):o=j[10],j[11]===Symbol.for("react.memo_cache_sentinel")?(d=e=>_(e.target.value),j[11]=d):d=j[11],j[12]!==k||j[13]!==S?(c=e=>{"Enter"===e.key&&S.trim()&&k(S.trim())},j[12]=k,j[13]=S,j[14]=c):c=j[14],j[15]!==C?(u=C("widgetConfig.annotatePlaceholder","WHAT HAPPENED HERE?"),j[15]=C,j[16]=u):u=j[16],j[17]!==c||j[18]!==u||j[19]!==S?(m=(0,t.jsx)("input",{id:"annotate-note",autoFocus:!0,value:S,onChange:d,onKeyDown:c,placeholder:u}),j[17]=c,j[18]=u,j[19]=S,j[20]=m):m=j[20],j[21]!==S?(h=S.trim(),j[21]=S,j[22]=h):h=j[22];let T=!h;return j[23]!==k||j[24]!==S?(p=()=>k(S.trim()),j[23]=k,j[24]=S,j[25]=p):p=j[25],j[26]!==C?(g=C("widgetConfig.annotateSave","PIN NOTE"),j[26]=C,j[27]=g):g=j[27],j[28]!==T||j[29]!==p||j[30]!==g?(f=(0,t.jsx)("div",{className:"wcChips",children:(0,t.jsx)("button",{className:"wcChip",disabled:T,onClick:p,children:g})}),j[28]=T,j[29]=p,j[30]=g,j[31]=f):f=j[31],j[32]!==f||j[33]!==o||j[34]!==m?(x=(0,t.jsxs)("div",{className:"gcField",children:[o,m,f]}),j[32]=f,j[33]=o,j[34]=m,j[35]=x):x=j[35],j[36]!==w||j[37]!==N||j[38]!==C?(b=w.length>0&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:C("widgetConfig.annotateExisting","PINNED NOTES")}),w.map((e,a)=>(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("span",{className:"wcInlineLbl",children:e.x.slice(0,10)}),(0,t.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:e.text}),(0,t.jsx)("button",{className:"wcChip",onClick:()=>N(a),"aria-label":C("widgetConfig.annotateRemove","Remove note"),children:"â"})]},a))]}),j[36]=w,j[37]=N,j[38]=C,j[39]=b):b=j[39],j[40]!==x||j[41]!==b||j[42]!==l?(v=(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[l,x,b]}),j[40]=x,j[41]=b,j[42]=l,j[43]=v):v=j[43],v}var sA=e.i(917344);function sR(e){let s,n,l=(0,a.c)(6),{verdict:i}=e,{t:r}=(0,Z.useTranslation)("paletteOs");l[0]!==r||l[1]!==i.detail||l[2]!==i.reason?(s="scheme"===i.reason?r("contentWidgets.httpsOnly","ONLY HTTPS IS ALLOWED â GOT {{scheme}}",{scheme:i.detail||"?"}):"origin"===i.reason?r("contentWidgets.originBlocked","ORIGIN NOT ALLOWED BY YOUR WORKSPACE â {{host}}",{host:i.detail}):r("contentWidgets.badUrl","NOT A VALID URL"),l[0]=r,l[1]=i.detail,l[2]=i.reason,l[3]=s):s=l[3];let o=s;return l[4]!==o?(n=(0,t.jsx)("div",{className:"dbEmpty",children:o}),l[4]=o,l[5]=n):n=l[5],n}function sD(e){let s,n=(0,a.c)(3),{label:l,onConfigure:i}=e;return n[0]!==l||n[1]!==i?(s=(0,t.jsx)("button",{className:"pvEmptyCta",onClick:i,children:l}),n[0]=l,n[1]=i,n[2]=s):s=n[2],s}function sM(e){let s,n,l=(0,a.c)(7),{src:i,alt:r}
31=e,o="string"==typeof i?i:void 0;l[0]!==o?(s=(0,sA.checkUrl)(o),l[0]=o,l[1]=s):s=l[1];let d=s;if(!d.ok){let e,a=r||"image blocked";return l[2]!==a?(e=(0,t.jsx)("span",{className:"cwBlockedImg",children:a}),l[2]=a,l[3]=e):e=l[3],e}let c=r??"";return l[4]!==c||l[5]!==d.url?(n=(0,t.jsx)("img",{src:d.url,alt:c,referrerPolicy:"no-referrer",loading:"lazy",decoding:"async"}),l[4]=c,l[5]=d.url,l[6]=n):n=l[6],n}let sI={hero:{labelKey:"hero",label:"HERO / GRID BUTTONS",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x=(0,a.c)(52),{range:b}=e,{t:v,i18n:j}=(0,Z.useTranslation)("paletteOs"),{user:y,orgs:w}=(0,eo.useAuth)(),{org:k,loading:N}=(0,a1.useOrganisation)(),{members:C}=(0,a2.useOrgMembers)(),{teams:S}=(0,a3.useOrgTeams)(),{apps:_}=(0,a4.usePoInstalledApps)();y?.organization_id,x[0]!==w||x[1]!==y?.organization_id?(s=w?.find(e=>e.id===y?.organization_id)??w?.[0]??null,x[0]=w,x[1]=y?.organization_id,x[2]=s):s=x[2];let T=s;if(x[3]!==T?.name||x[4]!==T?.slug||x[5]!==_.length||x[6]!==j.language||x[7]!==C||x[8]!==k?.name||x[9]!==k?.slug||x[10]!==N||x[11]!==b||x[12]!==v||x[13]!==S.length||x[14]!==y){let e,a,s,u=k?.name??T?.name??y?.company_name??v("dashboard.orgFallback","Workspace"),m=k?.slug??T?.slug??(y?.organization_id?`org-${y.organization_id}`:"active");x[22]!==C?(e=C.filter(a9),x[22]=C,x[23]=e):e=x[23];let h=e.length,p=new Date().toLocaleDateString(j.language,{weekday:"short",month:"short",day:"2-digit"}).toUpperCase();c="dbHeroBand",d="dbHero",i="dbHeroCard";let g=N?"â":h;x[24]!==v?(a=v("dashboard.people","PEOPLE"),x[24]=v,x[25]=a):a=x[25],x[26]!==a?(s=(0,t.jsx)("small",{children:a}),x[26]=a,x[27]=s):s=x[27],x[28]!==g||x[29]!==s?(r=(0,t.jsxs)("span",{className:"dbHeroNum",children:[g," ",s]}),x[28]=g,x[29]=s,x[30]=r):r=x[30];let f=v("dashboard.heroSub","{{org}} · {{role}} · {{teams}} teams · {{apps}} apps",{org:u,role:a8(y?.org_role),teams:S.length,apps:_.length});x[31]!==f?(o=(0,t.jsx)("span",{className:"dbHeroSub",children:f}),x[31]=f,x[32]=o):o=x[32],n="dbHeroDate",l=v("dashboard.heroWindow","{{slug}} · {{range}} RUN WINDOW · {{date}}",{slug:m.toUpperCase(),range:b.toUpperCase(),date:p}),x[3]=T?.name,x[4]=T?.slug,x[5]=_.length,x[6]=j.language,x[7]=C,x[8]=k?.name,x[9]=k?.slug,x[10]=N,x[11]=b,x[12]=v,x[13]=S.length,x[14]=y,x[15]=n,x[16]=l,x[17]=i,x[18]=r,x[19]=o,x[20]=d,x[21]=c}else n=x[15],l=x[16],i=x[17],r=x[18],o=x[19],d=x[20],c=x[21];return x[33]!==n||x[34]!==l?(u=(0,t.jsx)("span",{className:n,children:l}),x[33]=n,x[34]=l,x[35]=u):u=x[35],x[36]!==i||x[37]!==r||x[38]!==o||x[39]!==u?(m=(0,t.jsxs)("div",{className:i,children:[r,o,u]}),x[36]=i,x[37]=r,x[38]=o,x[39]=u,x[40]=m):m=x[40],x[41]!==m||x[42]!==d?(h=(0,t.jsx)("div",{className:d,children:m}),x[41]=m,x[42]=d,x[43]=h):h=x[43],x[44]!==v?(p=v("dashboard.hint","ACTIVE WORKSPACE · PEOPLE · TEAMS · APPS · RUNS"),x[44]=v,x[45]=p):p=x[45],x[46]!==p?(g=(0,t.jsx)("span",{className:"dbHint",children:p}),x[46]=p,x[47]=g):g=x[47],x[48]!==h||x[49]!==g||x[50]!==c?(f=(0,t.jsxs)("section",{className:c,children:[h,g]}),x[48]=h,x[49]=g,x[50]=c,x[51]=f):f=x[51],f},defaultSize:{gw:12,gh:7},minSize:{gw:6,gh:6},singleton:!0,bare:!0},"kpi-strip":{labelKey:"kpiStrip",label:"ORG KPI STRIP",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j=(0,a.c)(50),{range:y,tasks:w,tasksLoading:k}=e,{t:N}=(0,Z.useTranslation)("paletteOs"),{loading:C}=(0,a1.useOrganisation)(),{members:S,loading:_}=(0,a2.useOrgMembers)(),{teams:T,loading:E}=(0,a3.useOrgTeams)(),{apps:A,loading:R}=(0,a4.usePoInstalledApps)(),D=a7(w,y);j[0]!==k?(s=e=>k?"â":String(e),j[0]=k,j[1]=s):s=j[1];let M=s;j[2]!==R||j[3]!==_||j[4]!==C||j[5]!==E?(n=e=>C||_||E||R?"â":String(e),j[2]=R,j[3]=_,j[4]=C,j[5]=E,j[6]=n):n=j[6];let I=n;j[7]!==N?(l=N("dashboard.people","PEOPLE"),j[7]=N,j[8]=l):l=j[8];let O=I(S.length);j[9]!==l||j[10]!==O?(i={label:l,value:O},j[9]=l,j[10]=O,j[11]=i):i=j[11],j[12]!==N?(r=N("dashboard.active","ACTIVE"),j[12]=N,j[13]=r):r=j[13],j[14]!==S||j[15]!==I?(o=I(S.filter(st).length),j[14]=S,j[15]=I,j[16]=o):o=j[16],j[17]!==r||j[18]!==o?(d={label:r,value:o},j[17]=r,j[18]=o,j[19]=d):d=j[19],j[20]!==N?(c=N("dashboard.teams","TEAMS"),j[20]=N,j[21]=c):c=j[21];let P=I(T.length);j[22]!==P||j[23]!==c?(u={label:c,value:P},j[22]=P,j[23]=c,j[24]=u):u=j[24],j[25]!==N?(m=N("dashboard.apps","APPS"),j[25]=N,j[26]=m):m=j[26];let L=I(A.length);j[27]!==m||j[28]!==L?(h={label:m,value:L},j[27]=m,j[28]=L,j[29]=h):h=j[29],j[30]!==N?(p=N("dashboard.runs","RUNS"),j[30]=N,j[31]=p):p=j[31];let F=M(D.runs);j[32]!==p||j[33]!==F?(g={label:p,value:F},j[32]=p,j[33]=F,j[34]=g):g=j[34],j[35]!==N?(f=N("dashboard.running","RUNNING"),j[35]=N,j[36]=f):f=j[36];let $=M(D.running),B=!k&&D.running>0;j[37]!==f||j[38]!==$||j[39]!==B?(x={label:f,value:$,live:B},j[37]=f,j[38]=$,j[39]=B,j[40]=x):x=j[40],j[41]!==u||j[42]!==h||j[43]!==g||j[44]!==x||j[45]!==i||j[46]!==d?(b=[i,d,u,h,g,x],j[41]=u,j[42]=h,j[43]=g,j[44]=x,j[45]=i,j[46]=d,j[47]=b):b=j[47];let H=b;return j[48]!==H?(v=(0,t.jsx)("div",{className:"dbKpis",children:H.map(se)}),j[48]=H,j[49]=v):v=j[49],v},defaultSize:{gw:12,gh:4},minSize:{gw:6,gh:3},singleton:!0},"run-volume":{labelKey:"runVolume",label:"RUN VOLUME",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x=(0,a.c)(38),{widget:b,tasks:v}=e,{t:j}=(0,Z.useTranslation)("paletteOs"),{setView:y}=(0,ed.useViewContext)(),w=Number(b.config.days);x[0]!==w?(s=Number.isFinite(w)?Math.min(30,Math.max(7,Math.round(w))):14,x[0]=w,x[1]=s):s=x[1];let k=s;if(x[2]!==k||x[3]!==j||x[4]!==v){let e,t,a=function(e,t,a){let s=Array(t).fill(0);for(let n of e){let e=n.created_at?Date.parse(n.created_at):NaN;if(Number.isNaN(e))continue;let l=t-1-Math.floor((a-e)/864e5);l>=0&&l<t&&s[l]++}return s}(v,k,Date.now()),s=Date.now()-(k-1)*864e5;x[7]!==j?(e=j("dashboard.runs","RUNS"),x[7]=j,x[8]=e):e=x[8],x[9]!==e?(n=["day",e],x[9]=e,x[10]=n):n=x[10],x[11]!==s?(t=(e,t)=>
31[new Date(s+864e5*t).toISOString().slice(0,10),e],x[11]=s,x[12]=t):t=x[12],l=a.map(t),x[2]=k,x[3]=j,x[4]=v,x[5]=n,x[6]=l}else n=x[5],l=x[6];x[13]===Symbol.for("react.memo_cache_sentinel")?(i={},x[13]=i):i=x[13],x[14]!==n||x[15]!==l?(r={columns:n,rows:l,scalars:i},x[14]=n,x[15]=l,x[16]=r):r=x[16];let N=r;return x[17]!==k||x[18]!==j?(o=j("dashboard.runVolume","RUN VOLUME · 14D").replace("14D",`${k}D`),x[17]=k,x[18]=j,x[19]=o):o=x[19],x[20]!==o?(d=(0,t.jsx)("span",{children:o}),x[20]=o,x[21]=d):d=x[21],x[22]!==y?(c=()=>y("agents"),x[22]=y,x[23]=c):c=x[23],x[24]!==j?(u=j("dashboard.agentsLink","AGENTS âº"),x[24]=j,x[25]=u):u=x[25],x[26]!==c||x[27]!==u?(m=(0,t.jsx)("button",{onClick:c,children:u}),x[26]=c,x[27]=u,x[28]=m):m=x[28],x[29]!==m||x[30]!==d?(h=(0,t.jsxs)("div",{className:"dbPanelHead",children:[d,m]}),x[29]=m,x[30]=d,x[31]=h):h=x[31],x[32]===Symbol.for("react.memo_cache_sentinel")?(p={},x[32]=p):p=x[32],x[33]!==N?(g=(0,t.jsx)(a5.PoChart,{data:N,opts:p,build:a5.areaOption}),x[33]=N,x[34]=g):g=x[34],x[35]!==h||x[36]!==g?(f=(0,t.jsxs)(t.Fragment,{children:[h,g]}),x[35]=h,x[36]=g,x[37]=f):f=x[37],f},defaultSize:{gw:6,gh:9},minSize:{gw:3,gh:5}},"active-org":{labelKey:"activeOrg",label:"ACTIVE WORKSPACE",Renderer:function(){let e,s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D=(0,a.c)(80),{t:M}=(0,Z.useTranslation)("paletteOs"),{setView:I}=(0,ed.useViewContext)(),{user:O}=(0,eo.useAuth)(),{org:P,loading:L}=(0,a1.useOrganisation)(),{members:F,loading:$}=(0,a2.useOrgMembers)(),{apps:B,loading:H,appStoreEnabled:z}=(0,a4.usePoInstalledApps)();D[0]!==H||D[1]!==$||D[2]!==L?(e=e=>L||$||H?"â":String(e),D[0]=H,D[1]=$,D[2]=L,D[3]=e):e=D[3];let U=e;if(D[4]!==P?.company_type||D[5]!==P?.description||D[6]!==P?.name||D[7]!==P?.slug||D[8]!==M||D[9]!==O?.company_name||D[10]!==O?.company_type){let e,t=P?.name??O?.company_name??M("dashboard.orgFallback","Workspace");D[14]!==P?.company_type||D[15]!==M||D[16]!==O?.company_type?(e=P?.company_type??O?.company_type??M("dashboard.orgTypeFallback","Virtual workspace"),D[14]=P?.company_type,D[15]=M,D[16]=O?.company_type,D[17]=e):e=D[17],n=e,s=P?.slug??"active",l=P?.description?.trim()||M("dashboard.orgDescriptionFallback","{{org}} workspace activity across people, teams, apps, and agent runs.",{org:t}),D[4]=P?.company_type,D[5]=P?.description,D[6]=P?.name,D[7]=P?.slug,D[8]=M,D[9]=O?.company_name,D[10]=O?.company_type,D[11]=s,D[12]=n,D[13]=l}else s=D[11],n=D[12],l=D[13];let G=l;D[18]!==M?(i=M("dashboard.activeOrg","ACTIVE WORKSPACE"),D[18]=M,D[19]=i):i=D[19],D[20]!==i?(r=(0,t.jsx)("span",{children:i}),D[20]=i,D[21]=r):r=D[21],D[22]!==I?(o=()=>I("setting"),D[22]=I,D[23]=o):o=D[23],D[24]!==M?(d=M("dashboard.settingsLink","SETTINGS âº"),D[24]=M,D[25]=d):d=D[25],D[26]!==o||D[27]!==d?(c=(0,t.jsx)("button",{onClick:o,children:d}),D[26]=o,D[27]=d,D[28]=c):c=D[28],D[29]!==r||D[30]!==c?(u=(0,t.jsxs)("div",{className:"dbPanelHead",children:[r,c]}),D[29]=r,D[30]=c,D[31]=u):u=D[31];let W=U(F.length);D[32]!==W?(m=(0,t.jsx)("span",{children:W}),D[32]=W,D[33]=m):m=D[33],D[34]!==M?(h=M("dashboard.members","members"),D[34]=M,D[35]=h):h=D[35],D[36]!==h?(p=(0,t.jsx)("small",{children:h}),D[36]=h,D[37]=p):p=D[37],D[38]!==p||D[39]!==m?(g=(0,t.jsxs)("div",{className:"dbNextBig",children:[m,p]}),D[38]=p,D[39]=m,D[40]=g):g=D[40],D[41]===Symbol.for("react.memo_cache_sentinel")?(f=(0,t.jsx)("i",{}),D[41]=f):f=D[41],D[42]!==n?(x=(0,t.jsx)("span",{children:n}),D[42]=n,D[43]=x):x=D[43];let K=O?.org_role;return D[44]!==K?(b=a8(K),D[44]=K,D[45]=b):b=D[45],D[46]!==b?(v=(0,t.jsx)("b",{children:b}),D[46]=b,D[47]=v):v=D[47],D[48]!==x||D[49]!==v?(j=(0,t.jsxs)("div",{className:"dbListRow",children:[f,x,v]}),D[48]=x,D[49]=v,D[50]=j):j=D[50],D[51]===Symbol.for("react.memo_cache_sentinel")?(y=(0,t.jsx)("i",{}),D[51]=y):y=D[51],D[52]!==G?(w=(0,t.jsx)("span",{children:G}),D[52]=G,D[53]=w):w=D[53],D[54]!==s?(k=(0,t.jsx)("b",{children:s}),D[54]=s,D[55]=k):k=D[55],D[56]!==w||D[57]!==k?(N=(0,t.jsxs)("div",{className:"dbListRow",children:[y,w,k]}),D[56]=w,D[57]=k,D[58]=N):N=D[58],D[59]===Symbol.for("react.memo_cache_sentinel")?(C=(0,t.jsx)("i",{}),D[59]=C):C=D[59],D[60]!==z||D[61]!==M?(S=z?M("dashboard.appStoreEnabled","App Store enabled"):M("dashboard.appStoreDisabled","App Store disabled"),D[60]=z,D[61]=M,D[62]=S):S=D[62],D[63]!==S?(_=(0,t.jsx)("span",{children:S}),D[63]=S,D[64]=_):_=D[64],D[65]!==B.length||D[66]!==U||D[67]!==M?(T=M("dashboard.appsCount","{{value}} apps",{value:U(B.length)}),D[65]=B.length,D[66]=U,D[67]=M,D[68]=T):T=D[68],D[69]!==T?(E=(0,t.jsx)("b",{children:T}),D[69]=T,D[70]=E):E=D[70],D[71]!==_||D[72]!==E?(A=(0,t.jsxs)("div",{className:"dbListRow",children:[C,_,E]}),D[71]=_,D[72]=E,D[73]=A):A=D[73],D[74]!==g||D[75]!==j||D[76]!==N||D[77]!==A||D[78]!==u?(R=(0,t.jsxs)(t.Fragment,{children:[u,g,j,N,A]}),D[74]=g,D[75]=j,D[76]=N,D[77]=A,D[78]=u,D[79]=R):R=D[79],R},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:6},singleton:!0},teams:{labelKey:"teams",label:"TEAMS",Renderer:function(){let e,s,n,l,i,r,o,d,c=(0,a.c)(25),{t:u}=(0,Z.useTranslation)("paletteOs"),{setView:m}=(0,ed.useViewContext)(),{teams:h,loading:p}=(0,a3.useOrgTeams)();c[0]!==h?(e=Math.max(1,...h.map(ss)),c[0]=h,c[1]=e):e=c[1];let g=e;if(c[2]!==g||c[3]!==u||c[4]!==h){let e;c[6]!==g||c[7]!==u?(e=(e,t)=>({name:e.name,n:e.member_count,color:e.color??a5.DASH_CAT[t%a5.DASH_CAT.length],pct:`${Math.max(8,Math.round(e.member_count/g*100))}%`,meta:"all"===e.app_access_mode?u("dashboard.allApps","ALL APPS"):u("dashboard.appCount","{{count}} APPS",{count:e.app_ids.length})}),c[6]=g,c[7]=u,c[8]=e):e=c[8],s=h.slice(0,4).map(e),c[2]=g,c[3]=u,c[4]=h,c[5]=s}else s=c[5];let f=s;return c[9]!==u?(n=u("dashboard.teams","TEAMS"),c[9]=u,c[10]=n):n=c[10],c[11]!==n?(l=(0,t.jsx)("span",{children:n}),c[11]=n,c[12]=l):l=c[12],c[13]!==m?(i=(0,t.jsx)("button",{onClick:()=>m("setting"),children:"âº"}),c[13]=m,c[14]=i):i=c[14],c[15]!==l||c[16]!==i?(r=(0,t.jsxs)("div",{className:"dbPanelHead",children:[l,i]}),c[15]=l,c[16]=i,c[17]=r):r=c[17],c[18]!==u||c[19]!==f||c[20]!==p?(o=f.length?f.map(sa):(0,t.jsx)("div",{className:"dbEmpty",children:p?u("dashboard.loadingTeams","LOADING TEAMS"):u("dashboard.noTeams","NO TEAMS")}),c[18]=u,c[19]=f,c[20]=p,c[21]=o):o=c[21],c[22]!==r||c[23]!==o?(d=(0,t.jsxs)(t.Fragment,{children:[r,o]}),c[22]=r,c[23]=o,c[24]=d):d=c[24],d},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:5},singleton:!0},members:{labelKey:"members",label:"WORKSPACE MEMBERS",Renderer:function(){let e,s,n,l,i,r,o,d,c,u=(0,a.c)(24),{t:m}=(0,Z.useTranslation)("paletteOs"),{setView:h}=(0,ed.useViewContext)(),{members:p,loading:g}=(0,a2.useOrgMembers)();u[0]!==p?(e=p.slice(0,5),u[0]=p,u[1]=e):e=u[1];let f=e;return u[2]!==m?(s=m("dashboard.orgMembers","WORKSPACE MEMBERS"),u[2]=m,u[3]=s):s=u[3],u[4]!==s?(n=(0,t.jsx)("span",{children:s}),u[4]=s,u[5]=n):n=u[5],u[6]!==h?(l=()=>h("setting"),u[6]=h,u[7]=l):l=u[7],u[8]!==m?(i=m("dashboard.membersLink","MEMBERS âº"),u[8]=m,u[9]=i):i=u[9],u[10]!==l||u[11]!==i?(r=(0,t.jsx)("button",{onClick:l,children:i}
31),u[10]=l,u[11]=i,u[12]=r):r=u[12],u[13]!==n||u[14]!==r?(o=(0,t.jsxs)("div",{className:"dbPanelHead",children:[n,r]}),u[13]=n,u[14]=r,u[15]=o):o=u[15],u[16]!==f||u[17]!==g||u[18]!==h||u[19]!==m?(d=f.length?f.map(e=>(0,t.jsxs)("button",{className:"dbOutputRow",onClick:()=>h("setting"),children:[(0,t.jsx)("span",{className:"dbOutputAv",children:(e.name||e.email).split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"OR"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:e.name||e.email}),(0,t.jsxs)("small",{children:[e.email," · ",e.teams.length?e.teams.map(sn).join(" / "):m("dashboard.noTeam","No team")]})]}),(0,t.jsx)("em",{children:e.role.toUpperCase()})]},`member-${e.id}`)):(0,t.jsx)("div",{className:"dbEmpty",children:g?m("dashboard.loadingMembers","LOADING MEMBERS"):m("dashboard.noMembers","NO MEMBERS")}),u[16]=f,u[17]=g,u[18]=h,u[19]=m,u[20]=d):d=u[20],u[21]!==o||u[22]!==d?(c=(0,t.jsxs)(t.Fragment,{children:[o,d]}),u[21]=o,u[22]=d,u[23]=c):c=u[23],c},defaultSize:{gw:6,gh:9},minSize:{gw:3,gh:5},singleton:!0},"task-stats":{labelKey:"taskStats",label:"TASKS",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C=(0,a.c)(52),{range:S,tasks:_,tasksLoading:T}=e,{t:E}=(0,Z.useTranslation)("paletteOs");(0,ed.useViewContext)();let A=a7(_,S);C[0]!==T?(s=e=>T?"â":String(e),C[0]=T,C[1]=s):s=C[1];let R=s;C[2]!==_?(n=[..._].sort(sr).slice(0,5),C[2]=_,C[3]=n):n=C[3];let D=n;C[4]!==_?(l=_.filter(si).slice(0,2),C[4]=_,C[5]=l):l=C[5];let M=l;C[6]!==E?(i=E("dashboard.tasks","TASKS"),C[6]=E,C[7]=i):i=C[7],C[8]!==i?(r=(0,t.jsx)("div",{className:"dbPanelHead",children:(0,t.jsx)("span",{children:i})}),C[8]=i,C[9]=r):r=C[9],C[10]!==E?(o=E("dashboard.todo","TODO"),C[10]=E,C[11]=o):o=C[11],C[12]!==o?(d=(0,t.jsx)("small",{children:o}),C[12]=o,C[13]=d):d=C[13];let I=R(A.pending);C[14]!==I?(c=(0,t.jsx)("b",{children:I}),C[14]=I,C[15]=c):c=C[15],C[16]!==d||C[17]!==c?(u=(0,t.jsxs)("span",{children:[d,c]}),C[16]=d,C[17]=c,C[18]=u):u=C[18],C[19]!==E?(m=E("dashboard.running","RUNNING"),C[19]=E,C[20]=m):m=C[20],C[21]!==m?(h=(0,t.jsx)("small",{children:m}),C[21]=m,C[22]=h):h=C[22];let O=R(A.running);C[23]!==O?(p=(0,t.jsx)("b",{children:O}),C[23]=O,C[24]=p):p=C[24],C[25]!==h||C[26]!==p?(g=(0,t.jsxs)("span",{children:[h,p]}),C[25]=h,C[26]=p,C[27]=g):g=C[27],C[28]!==E?(f=E("dashboard.done","DONE"),C[28]=E,C[29]=f):f=C[29],C[30]!==f?(x=(0,t.jsx)("small",{children:f}),C[30]=f,C[31]=x):x=C[31];let P=R(A.done);return C[32]!==P?(b=(0,t.jsx)("b",{children:P}),C[32]=P,C[33]=b):b=C[33],C[34]!==x||C[35]!==b?(v=(0,t.jsxs)("span",{children:[x,b]}),C[34]=x,C[35]=b,C[36]=v):v=C[36],C[37]!==u||C[38]!==g||C[39]!==v?(j=(0,t.jsxs)("div",{className:"dbTaskStats",children:[u,g,v]}),C[37]=u,C[38]=g,C[39]=v,C[40]=j):j=C[40],C[41]!==D||C[42]!==M?(y=M.length?M:D.slice(0,2),C[41]=D,C[42]=M,C[43]=y):y=C[43],C[44]!==y?(w=y.map(sl),C[44]=y,C[45]=w):w=C[45],C[46]!==w?(k=(0,t.jsx)("div",{className:"dbRunningList",children:w}),C[46]=w,C[47]=k):k=C[47],C[48]!==j||C[49]!==k||C[50]!==r?(N=(0,t.jsxs)(t.Fragment,{children:[r,j,k]}),C[48]=j,C[49]=k,C[50]=r,C[51]=N):N=C[51],N},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:5}},"org-apps":{labelKey:"orgApps",label:"ORG APPS",Renderer:function(){let e,s,n,l,i,r,o,d,c,u,m,h,p=(0,a.c)(72),{t:g}=(0,Z.useTranslation)("paletteOs"),{setView:f}=(0,ed.useViewContext)(),{teams:x,loading:b}=(0,a3.useOrgTeams)(),{apps:v,loading:j}=(0,a4.usePoInstalledApps)();if(p[0]!==v||p[1]!==j||p[2]!==f||p[3]!==g||p[4]!==x||p[5]!==b){let a,d,c,u,m,h,y,w,k,N,C,S,_,T,E=x.filter(so).length;p[13]!==j||p[14]!==b?(a=e=>b||j?"â":String(e),p[13]=j,p[14]=b,p[15]=a):a=p[15];let A=a;p[16]!==v?(d=v.slice(0,5),p[16]=v,p[17]=d):d=p[17],e=d,p[18]!==g?(c=g("dashboard.orgApps","ORG APPS"),p[18]=g,p[19]=c):c=p[19],p[20]!==c?(u=(0,t.jsx)("span",{children:c}),p[20]=c,p[21]=u):u=p[21],p[22]!==f?(m=()=>f("agents"),p[22]=f,p[23]=m):m=p[23],p[24]!==g?(h=g("dashboard.appsLink","APPS âº"),p[24]=g,p[25]=h):h=p[25],p[26]!==m||p[27]!==h?(y=(0,t.jsx)("button",{onClick:m,children:h}),p[26]=m,p[27]=h,p[28]=y):y=p[28],p[29]!==y||p[30]!==u?(o=(0,t.jsxs)("div",{className:"dbPanelHead",children:[u,y]}),p[29]=y,p[30]=u,p[31]=o):o=p[31],l="dbTaskStats",p[32]!==g?(w=g("dashboard.installed","INSTALLED"),p[32]=g,p[33]=w):w=p[33],p[34]!==w?(k=(0,t.jsx)("small",{children:w}),p[34]=w,p[35]=k):k=p[35];let R=A(v.length);p[36]!==R?(N=(0,t.jsx)("b",{children:R}),p[36]=R,p[37]=N):N=p[37],p[38]!==k||p[39]!==N?(i=(0,t.jsxs)("span",{children:[k,N]}),p[38]=k,p[39]=N,p[40]=i):i=p[40],p[41]!==g?(C=g("dashboard.teams","TEAMS"),p[41]=g,p[42]=C):C=p[42],p[43]!==C?(S=(0,t.jsx)("small",{children:C}),p[43]=C,p[44]=S):S=p[44];let D=A(x.length);p[45]!==D?(_=(0,t.jsx)("b",{children:D}),p[45]=D,p[46]=_):_=p[46],p[47]!==S||p[48]!==_?(r=(0,t.jsxs)("span",{children:[S,_]}),p[47]=S,p[48]=_,p[49]=r):r=p[49],p[50]!==g?(T=g("dashboard.restrict","RESTRICT"),p[50]=g,p[51]=T):T=p[51],p[52]!==T?(n=(0,t.jsx)("small",{children:T}),p[52]=T,p[53]=n):n=p[53],s=A(E),p[0]=v,p[1]=j,p[2]=f,p[3]=g,p[4]=x,p[5]=b,p[6]=e,p[7]=s,p[8]=n,p[9]=l,p[10]=i,p[11]=r,p[12]=o}else e=p[6],s=p[7],n=p[8],l=p[9],i=p[10],r=p[11],o=p[12];return p[54]!==s?(d=(0,t.jsx)("b",{children:s}),p[54]=s,p[55]=d):d=p[55],p[56]!==n||p[57]!==d?(c=(0,t.jsxs)("span",{children:[n,d]}),p[56]=n,p[57]=d,p[58]=c):c=p[58],p[59]!==l||p[60]!==i||p[61]!==r||p[62]!==c?(u=(0,t.jsxs)("div",{className:l,children:[i,r,c]}),p[59]=l,p[60]=i,p[61]=r,p[62]=c,p[63]=u):u=p[63],p[64]!==e||p[65]!==j||p[66]!==g?(m=e.length?e.map(e=>(0,t.jsxs)("div",{className:"dbFileRow",children:[(0,t.jsx)("b",{children:g("dashboard.appTag","APP")}),(0,t.jsx)("span",{children:e.name}),(0,t.jsx)("small",{children:e.category})]},`app-${e.id}`)):(0,t.jsx)("div",{className:"dbEmpty",children:j?g("dashboard.loadingApps","LOADING APPS"):g("dashboard.noOrgApps","NO ORG APPS")}),p[64]=e,p[65]=j,p[66]=g,p[67]=m):m=p[67],p[68]!==o||p[69]!==u||p[70]!==m?(h=(0,t.jsxs)(t.Fragment,{children:[o,u,m]}
31),p[68]=o,p[69]=u,p[70]=m,p[71]=h):h=p[71],h},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:5},singleton:!0},"next-runs":{labelKey:"nextRuns",label:"NEXT RUNS",Renderer:function({widget:e}){let{t:a}=(0,Z.useTranslation)("paletteOs"),{setView:s}=(0,ed.useViewContext)(),{data:n,fallback:l}=sj((0,r.useMemo)(()=>({kind:"loops.summary",params:{limit:sg(e,20)}}),[e.config.limit])),i=(0,t.jsxs)("div",{className:"dbPanelHead",children:[(0,t.jsx)("span",{children:a("dashboard.cards.nextRuns","NEXT RUNS")}),(0,t.jsx)("button",{onClick:()=>s("loops"),children:a("dashboard.cards.loopsLink","LOOPS âº")})]});if(l)return(0,t.jsxs)(t.Fragment,{children:[i,l]});let o=sv(n,"title"),d=sv(n,"schedule_cron"),c=sv(n,"latest_run_status"),u=sv(n,"last_run_at"),m=sv(n,"pending_decisions"),h=n.rows.reduce((e,t)=>e+sf(t[m]),0);return(0,t.jsxs)(t.Fragment,{children:[i,(0,t.jsxs)("div",{className:"dbNextBig",children:[(0,t.jsx)("span",{children:n.rows.length}),(0,t.jsx)("small",{children:h?a("dashboard.cards.awaitingDecision","{{n}} awaiting decision",{n:h}):a("dashboard.cards.scheduledLoops","scheduled · all clear")})]}),n.rows.length?n.rows.slice(0,6).map((e,a)=>(0,t.jsxs)("div",{className:"dbListRow",title:String(e[c]??""),children:[(0,t.jsx)("i",{}),(0,t.jsx)("span",{children:String(e[o]??"â")}),(0,t.jsx)("b",{children:String(e[d]??"")||sx(e[u])})]},`${String(e[o])}-${a}`)):(0,t.jsx)("div",{className:"dbEmpty",children:a("dashboard.cards.noLoops","NO SCHEDULED LOOPS")})]})},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:5}},"by-agent":{labelKey:"byAgent",label:"BY AGENT",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m=(0,a.c)(29),{widget:h}=e,{t:p}=(0,Z.useTranslation)("paletteOs"),{setView:g}=(0,ed.useViewContext)();m[0]===Symbol.for("react.memo_cache_sentinel")?(s={kind:"tasks.by_agent",params:{}},m[0]=s):s=m[0];let{data:f,fallback:x}=sj(s);m[1]!==p?(n=p("dashboard.cards.byAgent","BY AGENT"),m[1]=p,m[2]=n):n=m[2],m[3]!==n?(l=(0,t.jsx)("span",{children:n}),m[3]=n,m[4]=l):l=m[4],m[5]!==g?(i=(0,t.jsx)("button",{onClick:()=>g("agents"),children:"âº"}),m[5]=g,m[6]=i):i=m[6],m[7]!==l||m[8]!==i?(r=(0,t.jsxs)("div",{className:"dbPanelHead",children:[l,i]}),m[7]=l,m[8]=i,m[9]=r):r=m[9];let b=r;if(x){let e;return m[10]!==x||m[11]!==b?(e=(0,t.jsxs)(t.Fragment,{children:[b,x]}),m[10]=x,m[11]=b,m[12]=e):e=m[12],e}m[13]!==f?(o=sv(f,"agent"),m[13]=f,m[14]=o):o=m[14];let v=o;m[15]!==f?(d=sv(f,"count"),m[15]=f,m[16]=d):d=m[16];let j=d;m[17]!==f?(c=sv(f,"open"),m[17]=f,m[18]=c):c=m[18];let y=c;if(m[19]!==f.rows||m[20]!==b||m[21]!==j||m[22]!==v||m[23]!==y||m[24]!==p||m[25]!==h){let e,a=f.rows.slice(0,sg(h,5));m[27]!==j?(e=e=>sf(e[j]),m[27]=j,m[28]=e):e=m[28];let s=Math.max(1,...a.map(e));u=(0,t.jsxs)(t.Fragment,{children:[b,a.length?a.map((e,a)=>{let n=a5.DASH_CAT[a%a5.DASH_CAT.length];return(0,t.jsxs)("div",{className:"dbAgentRow",title:p("dashboard.cards.openTasks","{{n}} open",{n:sf(e[y])}),children:[(0,t.jsx)("i",{style:{background:n}}),(0,t.jsx)("span",{children:String(e[v]??"â")}),(0,t.jsx)("em",{children:(0,t.jsx)("strong",{style:{width:`${Math.max(8,Math.round(sf(e[j])/s*100))}%`,background:n}})}),(0,t.jsx)("b",{children:sf(e[j])})]},`${String(e[v])}-${a}`)}):(0,t.jsx)("div",{className:"dbEmpty",children:p("dashboard.cards.noAgentWork","NO AGENT WORK YET")})]}),m[19]=f.rows,m[20]=b,m[21]=j,m[22]=v,m[23]=y,m[24]=p,m[25]=h,m[26]=u}else u=m[26];return u},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:5}},outputs:{labelKey:"outputs",label:"OUTPUTS",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p=(0,a.c)(32),{widget:g}=e,{t:f}=(0,Z.useTranslation)("paletteOs");p[0]!==g?(s=sg(g,20),p[0]=g,p[1]=s):s=p[1];let x=s;p[2]!==x?(n={kind:"artifacts.recent",params:{limit:x}},p[2]=x,p[3]=n):n=p[3];let{data:b,fallback:v}=sj(n);p[4]!==f?(l=f("dashboard.cards.outputs","OUTPUTS"),p[4]=f,p[5]=l):l=p[5],p[6]!==l?(i=(0,t.jsx)("div",{className:"dbPanelHead",children:(0,t.jsx)("span",{children:l})}),p[6]=l,p[7]=i):i=p[7];let j=i;if(v){let e;return p[8]!==v||p[9]!==j?(e=(0,t.jsxs)(t.Fragment,{children:[j,v]}),p[8]=v,p[9]=j,p[10]=e):e=p[10],e}p[11]!==b?(r=sv(b,"title"),p[11]=b,p[12]=r):r=p[12];let y=r;p[13]!==b?(o=sv(b,"kind"),p[13]=b,p[14]=o):o=p[14];let w=o;p[15]!==b?(d=sv(b,"revision"),p[15]=b,p[16]=d):d=p[16];let k=d;p[17]!==b?(c=sv(b,"size_bytes"),p[17]=b,p[18]=c):c=p[18];let N=c;p[19]!==b?(u=sv(b,"created_at"),p[19]=b,p[20]=u):u=p[20];let C=u;return p[21]!==b.rows||p[22]!==C||p[23]!==w||p[24]!==k||p[25]!==N||p[26]!==y||p[27]!==f?(m=b.rows.length?b.rows.slice(0,8).map((e,a)=>{let s=String(e[w]??"â");return(0,t.jsxs)("div",{className:"dbOutputRow",role:"listitem",children:[(0,t.jsx)("span",{className:"dbOutputAv","aria-hidden":!0,
31children:s.slice(0,2).toUpperCase()}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{children:String(e[y]??"â")}),(0,t.jsx)("small",{children:f("dashboard.cards.outputMeta","r{{rev}} · {{size}} · {{ago}}",{rev:sf(e[k]),size:sb(e[N]),ago:sx(e[C])})})]}),(0,t.jsx)("em",{children:s.toUpperCase()})]},`${String(e[y])}-${a}`)}):(0,t.jsx)("div",{className:"dbEmpty",children:f("dashboard.cards.noOutputs","NO OUTPUTS YET")}),p[21]=b.rows,p[22]=C,p[23]=w,p[24]=k,p[25]=N,p[26]=y,p[27]=f,p[28]=m):m=p[28],p[29]!==j||p[30]!==m?(h=(0,t.jsxs)(t.Fragment,{children:[j,m]}),p[29]=j,p[30]=m,p[31]=h):h=p[31],h},defaultSize:{gw:6,gh:9},minSize:{gw:3,gh:5}},"new-in-drive":{labelKey:"newInDrive",label:"NEW IN DRIVE",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x=(0,a.c)(39),{widget:b}=e,{t:v}=(0,Z.useTranslation)("paletteOs"),{setView:j}=(0,ed.useViewContext)();x[0]!==b?(s=sg(b,20),x[0]=b,x[1]=s):s=x[1];let y=s;x[2]!==y?(n={kind:"drive.recent",params:{limit:y}},x[2]=y,x[3]=n):n=x[3];let{data:w,fallback:k}=sj(n);x[4]!==v?(l=v("dashboard.cards.newInDrive","NEW IN DRIVE"),x[4]=v,x[5]=l):l=x[5],x[6]!==l?(i=(0,t.jsx)("span",{children:l}),x[6]=l,x[7]=i):i=x[7],x[8]!==j?(r=()=>j("memory"),x[8]=j,x[9]=r):r=x[9],x[10]!==v?(o=v("dashboard.cards.driveLink","DRIVE âº"),x[10]=v,x[11]=o):o=x[11],x[12]!==r||x[13]!==o?(d=(0,t.jsx)("button",{onClick:r,children:o}),x[12]=r,x[13]=o,x[14]=d):d=x[14],x[15]!==i||x[16]!==d?(c=(0,t.jsxs)("div",{className:"dbPanelHead",children:[i,d]}),x[15]=i,x[16]=d,x[17]=c):c=x[17];let N=c;if(k){let e;return x[18]!==k||x[19]!==N?(e=(0,t.jsxs)(t.Fragment,{children:[N,k]}),x[18]=k,x[19]=N,x[20]=e):e=x[20],e}x[21]!==w?(u=sv(w,"name"),x[21]=w,x[22]=u):u=x[22];let C=u;x[23]!==w?(m=sv(w,"ext"),x[23]=w,x[24]=m):m=x[24];let S=m;x[25]!==w?(h=sv(w,"size_bytes"),x[25]=w,x[26]=h):h=x[26];let _=h;x[27]!==w?(p=sv(w,"created_at"),x[27]=w,x[28]=p):p=x[28];let T=p;return x[29]!==w.rows||x[30]!==T||x[31]!==S||x[32]!==C||x[33]!==_||x[34]!==v?(g=w.rows.length?w.rows.slice(0,6).map((e,a)=>(0,t.jsxs)("div",{className:"dbFileRow",title:sb(e[_]),children:[(0,t.jsx)("b",{children:String(e[S]??"FILE")}),(0,t.jsx)("span",{children:String(e[C]??"â")}),(0,t.jsx)("small",{children:sx(e[T])})]},`${String(e[C])}-${a}`)):(0,t.jsx)("div",{className:"dbEmpty",children:v("dashboard.cards.noFiles","NO FILES YET")}),x[29]=w.rows,x[30]=T,x[31]=S,x[32]=C,x[33]=_,x[34]=v,x[35]=g):g=x[35],x[36]!==N||x[37]!==g?(f=(0,t.jsxs)(t.Fragment,{children:[N,g]}),x[36]=N,x[37]=g,x[38]=f):f=x[38],f},defaultSize:{gw:3,gh:9},minSize:{gw:3,gh:5}},cost:{labelKey:"cost",label:"COST",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p=(0,a.c)(66),{widget:g,range:f,onConfigure:x}=e,{t:b}=(0,Z.useTranslation)("paletteOs"),v=sp[f]??"7d",j="org"===g.config.scope?"org":"user";p[0]!==v||p[1]!==j?(s={kind:"llm.usage",params:{bucket:"day",range:v,scope:j}},p[0]=v,p[1]=j,p[2]=s):s=p[2];let y=s;p[3]!==v||p[4]!==j?(n={kind:"llm.usage",params:{bucket:"total",group_by:"model",range:v,scope:j}},p[3]=v,p[4]=j,p[5]=n):n=p[5];let w=n,k=sj(y),N=sj(w);p[6]!==g.config.budgetLimitUsd?(l=sf(g.config.budgetLimitUsd)||50,p[6]=g.config.budgetLimitUsd,p[7]=l):l=p[7];let C=Math.max(.01,l);p[8]!==b?(i=b("dashboard.cards.cost","COST"),p[8]=b,p[9]=i):i=p[9],p[10]!==i?(r=(0,t.jsx)("span",{children:i}),p[10]=i,p[11]=r):r=p[11],p[12]!==b?(o=b("dashboard.cards.budgetLink","BUDGET âº"),p[12]=b,p[13]=o):o=p[13],p[14]!==x||p[15]!==o?(d=(0,t.jsx)("button",{onClick:x,children:o}),p[14]=x,p[15]=o,p[16]=d):d=p[16],p[17]!==r||p[18]!==d?(c=(0,t.jsxs)("div",{className:"dbPanelHead",children:[r,d]}),p[17]=r,p[18]=d,p[19]=c):c=p[19];let S=c;if(k.fallback){let e;return p[20]!==k.fallback||p[21]!==S?(e=(0,t.jsxs)(t.Fragment,{children:[S,k.fallback]}),p[20]=k.fallback,p[21]=S,p[22]=e):e=p[22],e}p[23]!==k.data?(u=sv(k.data,"date"),p[23]=k.data,p[24]=u):u=p[24];let _=u;p[25]!==k.data?(m=sv(k.data,"cost_usd"),p[25]=k.data,p[26]=m):m=p[26];let T=m,E=k.data.rows;if(p[27]!==E||p[28]!==S||p[29]!==T||p[30]!==_||p[31]!==C||p[32]!==N.data||p[33]!==b){let e,a,s,n,l,i,r,o,d,c,u,m,g;p[35]!==T?(e=(e,t)=>e+sf(t[T]),p[35]=T,p[36]=e):e=p[36];let f=E.reduce(e,0),x=Math.min(100,Math.round(f/C*100)),v=E.slice(-7);p[37]!==T?(a=e=>sf(e[T]),p[37]=T,p[38]=a):a=p[38];let j=Math.max(1e-6,...v.map(a));p[39]!==N.data?(s=sv(N.data,"model"),p[39]=N.data,p[40]=s):s=p[40];let y=s;p[41]!==N.data?(n=sv(N.data,"cost_usd"),p[41]=N.data,p[42]=n):n=p[42];let w=n;p[43]!==N.data?(l=sv(N.data,"calls"),p[43]=N.data,p[44]=l):l=p[44];let k=l,A=N.data.rows.slice(0,4);p[45]!==w?(i=e=>sf(e[w]),p[45]=w,p[46]=i):i=p[46];let R=Math.max(1e-6,...A.map(i)),D=f.toFixed(2);p[47]!==D?(r=(0,t.jsxs)("span",{children:["$",D]}),p[47]=D,p[48]=r):r=p[48],p[49]!==C||p[50]!==x||p[51]!==b?(o=b("dashboard.cards.costMeta","/ ${{limit}} · {{pct}}% used",{limit:C.toFixed(0),pct:x}),p[49]=C,p[50]=x,p[51]=b,p[52]=o):o=p[52],p[53]!==o?(d=(0,t.jsx)("small",{children:o}),p[53]=o,p[54]=d):d=p[54],p[55]!==r||p[56]!==d?(c=(0,t.jsxs)("div",{className:"dbNextBig",children:[r,d]}
31),p[55]=r,p[56]=d,p[57]=c):c=p[57];let M=x>=100?"over":x>=80?"near":void 0,I=`${Math.min(x,100)}%`;p[58]!==I?(u={width:I},p[58]=I,p[59]=u):u=p[59],p[60]!==M||p[61]!==u?(m=(0,t.jsx)("span",{className:M,style:u}),p[60]=M,p[61]=u,p[62]=m):m=p[62],p[63]!==x||p[64]!==m?(g=(0,t.jsx)("div",{className:"dbCostBar",role:"meter","aria-valuenow":x,"aria-valuemin":0,"aria-valuemax":100,children:m}),p[63]=x,p[64]=m,p[65]=g):g=p[65],h=(0,t.jsxs)(t.Fragment,{children:[S,c,g,v.length?(0,t.jsx)("div",{className:"dbCostDays",children:v.map((e,a)=>(0,t.jsxs)("div",{title:`$${sf(e[T]).toFixed(4)}`,children:[(0,t.jsx)("em",{children:(0,t.jsx)("strong",{style:{height:`${Math.max(3,Math.round(sf(e[T])/j*100))}%`}})}),(0,t.jsx)("small",{children:String(e[_]??"").slice(5)})]},`${String(e[_])}-${a}`))}):null,A.length?A.map((e,a)=>(0,t.jsxs)("div",{className:"dbAgentRow",title:b("dashboard.cards.calls","{{n}} calls",{n:sf(e[k])}),children:[(0,t.jsx)("i",{style:{background:a5.DASH_CAT[a%a5.DASH_CAT.length]}}),(0,t.jsx)("span",{children:String(e[y]??"â")}),(0,t.jsx)("em",{children:(0,t.jsx)("strong",{style:{width:`${Math.max(8,Math.round(sf(e[w])/R*100))}%`,background:a5.DASH_CAT[a%a5.DASH_CAT.length]}})}),(0,t.jsxs)("b",{children:["$",sf(e[w]).toFixed(2)]})]},`${String(e[y])}-${a}`)):(0,t.jsx)("div",{className:"dbEmpty",children:b("dashboard.cards.noSpend","NO SPEND IN THIS RANGE")})]}),p[27]=E,p[28]=S,p[29]=T,p[30]=_,p[31]=C,p[32]=N.data,p[33]=b,p[34]=h}else h=p[34];return h},defaultSize:{gw:8,gh:12},minSize:{gw:4,gh:8}},"agent-perf":{labelKey:"agentPerf",label:"AGENT PERFORMANCE",Renderer:function(e){let s,n,l,i,r,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D=(0,a.c)(78),{widget:M,range:I}=e,{t:O}=(0,Z.useTranslation)("paletteOs"),{setView:P}=(0,ed.useViewContext)(),L=sp[I]??"7d";D[0]!==M?(s=sg(M,20),D[0]=M,D[1]=s):s=D[1];let F=s;D[2]!==F||D[3]!==L?(n={kind:"agents.performance",params:{range:L,limit:F}},D[2]=F,D[3]=L,D[4]=n):n=D[4];let{data:$,fallback:B}=sj(n);D[5]!==O?(l=O("dashboard.cards.agentPerf","AGENT PERFORMANCE"),D[5]=O,D[6]=l):l=D[6],D[7]!==l?(i=(0,t.jsx)("span",{children:l}),D[7]=l,D[8]=i):i=D[8],D[9]!==P?(r=()=>P("agents"),D[9]=P,D[10]=r):r=D[10],D[11]!==O?(o=O("dashboard.cards.desktopLink","DESKTOP âº"),D[11]=O,D[12]=o):o=D[12],D[13]!==r||D[14]!==o?(d=(0,t.jsx)("button",{onClick:r,children:o}),D[13]=r,D[14]=o,D[15]=d):d=D[15],D[16]!==i||D[17]!==d?(c=(0,t.jsxs)("div",{className:"dbPanelHead",children:[i,d]}),D[16]=i,D[17]=d,D[18]=c):c=D[18];let H=c;if(B){let e;return D[19]!==B||D[20]!==H?(e=(0,t.jsxs)(t.Fragment,{children:[H,B]}),D[19]=B,D[20]=H,D[21]=e):e=D[21],e}D[22]!==$?(u=sv($,"agent"),D[22]=$,D[23]=u):u=D[23];let z=u;D[24]!==$?(m=sv($,"runs"),D[24]=$,D[25]=m):m=D[25];let U=m;D[26]!==$?(h=sv($,"success_pct"),D[26]=$,D[27]=h):h=D[27];let G=h;D[28]!==$?(p=sv($,"cost_usd"),D[28]=$,D[29]=p):p=D[29];let W=p;D[30]!==$?(g=sv($,"avg_secs"),D[30]=$,D[31]=g):g=D[31];let K=g;D[32]!==$?(f=sv($,"state"),D[32]=$,D[33]=f):f=D[33];let V=f;return D[34]!==O?(x=O("dashboard.cards.colAgent","AGENT"),D[34]=O,D[35]=x):x=D[35],D[36]!==x?(b=(0,t.jsx)("span",{children:x}),D[36]=x,D[37]=b):b=D[37],D[38]!==O?(v=O("dashboard.cards.colRuns","RUNS"),D[38]=O,D[39]=v):v=D[39],D[40]!==v?(j=(0,t.jsx)("span",{children:v}),D[40]=v,D[41]=j):j=D[41],D[42]!==O?(y=O("dashboard.cards.colSuccess","SUCCESS"),D[42]=O,D[43]=y):y=D[43],D[44]!==y?(w=(0,t.jsx)("span",{children:y}),D[44]=y,D[45]=w):w=D[45],D[46]!==O?(k=O("dashboard.cards.colCost","COST"),D[46]=O,D[47]=k):k=D[47],D[48]!==k?(N=(0,t.jsx)("span",{children:k}),D[48]=k,D[49]=N):N=D[49],D[50]!==O?(C=O("dashboard.cards.colAvg","AVG"),D[50]=O,D[51]=C):C=D[51],D[52]!==C?(S=(0,t.jsx)("span",{children:C}),D[52]=C,D[53]=S):S=D[53],D[54]!==O?(_=O("dashboard.cards.colState","STATE"),D[54]=O,D[55]=_):_=D[55],D[56]!==_?(T=(0,t.jsx)("span",{children:_}),D[56]=_,D[57]=T):T=D[57],D[58]!==b||D[59]!==j||D[60]!==w||D[61]!==N||D[62]!==S||D[63]!==T?(E=(0,t.jsxs)("div",{className:"dbPerfHead","aria-hidden":!0,children:[b,j,w,N,S,T]}),D[58]=b,D[59]=j,D[60]=w,D[61]=N,D[62]=S,D[63]=T,D[64]=E):E=D[64],D[65]!==$.rows||D[66]!==K||D[67]!==W||D[68]!==z||D[69]!==G||D[70]!==U||D[71]!==V||D[72]!==O?(A=$.rows.length?$.rows.map((e,a)=>{let s=sf(e[G]),n=sf(e[W]);return(0,t.jsxs)("div",{className:"dbPerfRow",children:[(0,t.jsx)("span",{className:"dbPerfName",children:String(e[z]??"â")}),(0,t.jsx)("span",{className:"dbPerfNum",children:sf(e[U])}),(0,t.jsxs)("span",{className:"dbPerfBar",children:[(0,t.jsx)("em",{children:(0,t.jsx)("strong",{style:{width:`${Math.min(100,Math.max(2,
31s))}%`}})}),(0,t.jsxs)("b",{children:[s.toFixed(0),"%"]})]}),(0,t.jsx)("span",{className:"dbPerfNum",children:n?`$${n.toFixed(2)}`:"â"}),(0,t.jsx)("span",{className:"dbPerfNum dim",children:sf(e[K])?`${Math.round(sf(e[K]))}s`:"â"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("em",{className:"dbPerfState",style:{background:sy[String(e[V])]??"var(--dnk-neutral)"}}),String(e[V]??"â").replace(/_/g," ")]})]},`${String(e[z])}-${a}`)}):(0,t.jsx)("div",{className:"dbEmpty",children:O("dashboard.cards.noRuns","NO AGENT RUNS IN THIS RANGE")}),D[65]=$.rows,D[66]=K,D[67]=W,D[68]=z,D[69]=G,D[70]=U,D[71]=V,D[72]=O,D[73]=A):A=D[73],D[74]!==H||D[75]!==E||D[76]!==A?(R=(0,t.jsxs)(t.Fragment,{children:[H,E,A]}),D[74]=H,D[75]=E,D[76]=A,D[77]=R):R=D[77],R},defaultSize:{gw:12,gh:12},minSize:{gw:6,gh:6}},data:{labelKey:"data",label:"DATA WIDGET",Renderer:function({widget:e,editMode:a,range:s,onConfigure:n,onPatchConfig:l,crossFilter:i,onCrossFilter:o,boardFilter:d,datasetColumns:c}){let u,m,h,{t:p}=(0,Z.useTranslation)("paletteOs"),{openDrawer:g,closeDrawer:f}=(0,ed.useViewContext)(),[x,b]=(0,r.useState)(!1),v=(0,a0.useOsDark)(),j=e.config.binding??null,y=e.config.visual??"stat",w="number"==typeof e.config.refreshSec?e.config.refreshSec:void 0,[k,N]=(0,r.useState)(!1),C=e.config.dateField,[S,_]=(0,r.useState)([]),T=j?.kind==="dataset"?j.dimensions?.[0]:void 0,E=T&&"object"==typeof T&&T.grain?T:null,A=!!E&&s_.has(y);(0,r.useEffect)(()=>{_([])},[e.id,y]);let R=S.length&&j&&E?{...j,dimensions:[{column:E.column,grain:S[S.length-1].grain},...(j.dimensions??[]).slice(1)],filters:[...j.filters??[],...S.flatMap(e=>e.filters)]}:j,D=i&&R&&"dataset"===R.kind&&R.dataset_id===i.datasetId&&i.widgetId!==e.id&&i&&R?{...R,filters:[...R.filters??[],{column:i.column,op:"=",value:i.value}]}:R,M=d&&D&&"dataset"===D.kind&&D.dataset_id&&(c?.[D.dataset_id]??[]).includes(d.column)&&d&&D?{...D,filters:[...D.filters??[],{column:d.column,op:"=",value:d.value}]}:D,I=(0,aL.withDashboardRange)(M,C,s),{data:O,loading:P,error:L,updatedAt:F,refetch:$}=sm(I,w),{data:B,loading:H}=sm(k&&I?.kind==="dataset"?{...I,raw:!0,dimensions:[],measures:[],sort:[],limit:200}:null,w),z=("stat"===y||sS.has(y))&&!S.length?(0,aL.priorPeriodBinding)(M,C,s):null,{data:U}=sm(z,w),G=e.config.alert,W=(0,sN.useVisualRenderer)(y),K=e.config.pick,V=(0,r.useMemo)(()=>(0,sh.normalizeColumnar)(O,K),[O,K]),Y=!a&&!!o&&j?.kind==="dataset"&&!!j.dataset_id,q=Array.isArray(e.config.annotations)?e.config.annotations.filter(e=>e&&"string"==typeof e.text):[],J=async()=>{var t,a,s;let n,l,i,r;if(!j)return;let o=(0,sh.normalizeColumnar)(O,e.config.pick);if("dataset"===j.kind)try{let t=await (0,tA.apiFetch)("/api/v1/insights-dashboards/data/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...I??j,limit:5e4})}),a=(0,sh.normalizeColumnar)(await t.json(),e.config.pick);!a.error&&a.columns.length&&(o=a)}catch{}o.columns.length&&(t=e.label||"widget",a=o.columns,s=o.rows,n=e=>{let t=null==e?"":String(e);return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t},l="\uFEFF"+[a,...s].map(e=>e.map(n).join(",")).join("\n"),i=URL.createObjectURL(new Blob([l],{type:"text/csv;charset=utf-8"})),(r=document.createElement("a")).href=i,r.download=`${t.toLowerCase().replace(/[^\w-]+/g,"-")||"widget"}.csv`,r.click(),URL.revokeObjectURL(i))},X=!!j&&"dataset"!==j.kind&&!!j.params&&"range"in j.params,Q=(0,t.jsxs)("div",{className:"dbPanelHead",title:e.config.rationale,children:[(0,t.jsx)("span",{children:e.label||p("widgetConfig.dataWidget","DATA WIDGET")}),X?(0,t.jsx)("span",{className:"dbRangeTag",title:p("widgetConfig.rangeTag","Following the board range"),children:"today"===s?"1D":s.toUpperCase()}):null,S.map((e,a)=>(0,t.jsxs)("button",{className:"dbRangeTag",title:p("widgetConfig.drillUp","Back up one level"),onClick:()=>_(e=>e.slice(0,a)),children:[e.label," â"]},a)),G?.enabled?(0,t.jsx)("button",{className:`dbAlertChip${G.lastState?" breached":""}`,onClick:n,title:p("widgetConfig.alertArmed","Alert armed â click to edit"),children:G.lastState?p("widgetConfig.alertBreached","ALERT!"):p("widgetConfig.alertOn","ALERT")}):null,e.config.sample?(0,t.jsx)("button",{className:"dbSampleBadge",onClick:n,title:p("widgetConfig.sampleTooltip","Template sample data â click to connect a real source"),children:p("widgetConfig.sampleBadge","SAMPLE â CONNECT SOURCE")}):null,j&&!a?(0,t.jsxs)("div",{className:"dbHeadTools",children:[sS.has(y)&&"dataset"===j.kind?(0,t.jsx)("button",{className:"dbExplainBtn",onClick:()=>b(e=>!e),"aria-pressed":x,"aria-label":p("widgetConfig.annotate","Pin a note on a point"),title:x?p("widgetConfig.annotateArmed","Click a point to pin a note â click again to cancel"):p("widgetConfig.annotate","Pin a note on a point"),children:"â"}):null,(0,t.jsx)("button",{className:"dbExplainBtn",onClick:()=>
31$(),"aria-label":p("widgetConfig.refreshNow","Refresh now"),title:F?p("widgetConfig.refreshedAt","Refresh now â updated {{time}}",{time:new Date(F).toLocaleTimeString()}):p("widgetConfig.refreshNow","Refresh now"),children:"â³"}),(0,t.jsx)("button",{className:"dbExplainBtn",onClick:()=>N(e=>!e),"aria-pressed":k,"aria-label":p("widgetConfig.viewData","View underlying data"),title:p("widgetConfig.viewData","View underlying data"),children:"â¤"}),(0,t.jsx)("button",{className:"dbExplainBtn",onClick:()=>void J(),"aria-label":p("widgetConfig.exportCsv","Download CSV"),title:p("widgetConfig.exportCsv","Download CSV"),children:"â¤"}),(0,t.jsx)("button",{className:"dbExplainBtn",onClick:()=>{j&&g({inverted:v,tag:p("widgetConfig.explainTag","EXPLAIN"),content:(0,t.jsx)(sC,{label:e.label||p("widgetConfig.dataWidget","DATA WIDGET"),binding:j,rationale:e.config.rationale})})},"aria-label":p("widgetConfig.explainTitle","AI READ"),title:p("widgetConfig.explainTitle","AI READ"),children:"â¦"})]}):null]});if(!j)return(0,t.jsxs)(t.Fragment,{children:[Q,(0,t.jsx)("button",{className:"pvEmptyCta",onClick:n,children:p("widgetConfig.chooseSource","CHOOSE A DATA SOURCE âº")})]});if(P&&null==O)return(0,t.jsxs)(t.Fragment,{children:[Q,(0,t.jsxs)("div",{className:"pvSkel","aria-label":p("dashboard.loading","LOADING"),role:"status",children:[(0,t.jsx)("span",{}),(0,t.jsx)("span",{}),(0,t.jsx)("span",{})]})]});let ee=L??V.error;if(ee)return(0,t.jsxs)(t.Fragment,{children:[Q,(0,t.jsxs)("div",{className:"pvError",children:[(0,t.jsx)("span",{className:"dbEmpty",children:ee}),(0,t.jsx)("button",{className:"pvRetry",onClick:()=>$(),children:p("widgetConfig.retry","RETRY")})]})]});let et=0===V.rows.length||V.rows.every(e=>e.every(e=>null==e));if(C&&"dataset"===j.kind&&et&&!k){let e="today"===s?"7D":"7d"===s?"30D":null;return(0,t.jsxs)(t.Fragment,{children:[Q,(0,t.jsx)("div",{className:"pvError",children:(0,t.jsx)("span",{className:"dbEmpty",children:e?p("widgetConfig.emptyInRange","NO ROWS IN THIS RANGE â TRY {{range}}",{range:e}):p("widgetConfig.emptyInAnyRange","NO ROWS IN THE SELECTED RANGE")})})]})}let ea=e.config.alert;if(z&&null!=U){let t=(0,sh.normalizeColumnar)(U,K);if("stat"===y){let a=(0,sw.aggregateValue)(t,{valueKey:e.config.valueKey}),s=(0,sw.aggregateValue)(V,{valueKey:e.config.valueKey});"number"==typeof a&&0!==a&&"number"==typeof s&&(u=(s-a)/Math.abs(a))}else if(!t.error&&t.rows.length){let{series:a}=(0,sw.chartSeries)(t,{valueKey:e.config.valueKey,labelKey:e.config.labelKey});m=a[0]?.values}}if(!0===e.config.forecast&&sS.has(y)&&E&&!S.length){let{labels:t,series:a}=(0,sw.chartSeries)(V,{valueKey:e.config.valueKey,labelKey:e.config.labelKey});if(1===a.length){let e=Math.min(6,Math.max(2,Math.ceil(a[0].values.length/3))),s=(0,sw.linearForecast)(a[0].values,e);s&&(h={labels:function(e,t,a){let s=new Date(String(e??"").replace(" ","T"));if(Number.isNaN(+s))return Array.from({length:a},(e,t)=>`+${t+1}`);let n=[],l=new Date(s);for(let e=0;e<a;e++)"year"===t?l.setFullYear(l.getFullYear()+1):"quarter"===t?l.setMonth(l.getMonth()+3):"month"===t?l.setMonth(l.getMonth()+1):"week"===t?l.setDate(l.getDate()+7):"hour"===t?l.setHours(l.getHours()+1):l.setDate(l.getDate()+1),n.push([l.getFullYear(),l.getMonth()+1,l.getDate()].map((e,t)=>String(e).padStart(t?2:4,"0")).join("-"));return n}(t[t.length-1],E.grain,e),values:s})}}let es={labelKey:e.config.labelKey,valueKey:e.config.valueKey,template:e.config.template,prefix:e.config.prefix,suffix:e.config.suffix,latKey:e.config.latKey,lngKey:e.config.lngKey,target:e.config.target,rowCap:e.config.rowCap,format:e.config.format,delta:u,prior:m,forecast:h,annotations:q.length?q:void 0,threshold:ea?.enabled&&"number"==typeof ea.value?ea.value:void 0,thresholdOp:ea?.enabled?ea.op:void 0,onSelect:x||Y||A&&!a?(s,n)=>{if(x){b(!1);let e=String(n??s);g({inverted:v,tag:p("widgetConfig.annotateTag","ANNOTATE"),content:(0,t.jsx)(sE,{x:e,existing:q,onSave:t=>{l({annotations:[...q,{x:e,text:t}]}),f()},onRemove:e=>{l({annotations:q.filter((t,a)=>a!==e)}),f()}})});return}if(A&&E&&!a){let e=S.length?S[S.length-1].grain:E.grain,t=function(e,t,a){let s=sT[t];if(!s)return null;let n=new Date(String(a??"").replace(" ","T"));if(Number.isNaN(+n))return null;let l=new Date(n);return"year"===t?l.setFullYear(l.getFullYear()+1):"quarter"===t?l.setMonth(l.getMonth()+3):"month"===t?l.setMonth(l.getMonth()+1):"week"===t?l.setDate(l.getDate()+7):l.setDate(l.getDate()+1),{grain:s,label:String(a??"").slice(0,10),filters:[{column:e,op:">=",value:String(a??"")},{column:e,op:"<",value:[l.getFullYear(),l.getMonth()+1,l.getDate()].map((e,t)=>String(e).padStart(t?2:4,"0")).join("-")}]}}(E.column,e,n);if(t)return void _(e=>[...e,t])}if(!Y||!j?.dataset_id||!o)return;let r=e.config.labelKey||(0,aL.dimensionColumn)(j.dimensions?.[0]);r&&o(i?.widgetId===e.id&&i.value===n?null:{widgetId:e.id,datasetId:j.dataset_id,column:r,value:n})}:void 0,selected:i?.widgetId===e.id?String(i.value):void 0};return(0,t.jsxs)(t.Fragment,{children:[Q,(0,t.jsx)("div",{className:"pvBody",children:k?null==B&&H?(0,t.jsxs)("div",{className:"pvSkel",role:"status","aria-label":p("dashboard.loading","LOADING"),children:[(0,t.jsx)("span",{}),(0,t.jsx)("span",{}),(0,t.jsx)("span",{})]}):(0,t.jsx)(sk.PoTable,{data:null!=B?(0,sh.normalizeColumnar)(B):V,opts:{labelKey:es.labelKey}}):(0,t.jsx)(W,{data:V,opts:es})})]})},defaultSize:{gw:6,gh:9},minSize:{gw:2,gh:3}},section:{labelKey:"section",label:"SECTION DIVIDER",Renderer:function(e){let s,n,l,i=(0,a.c)(5),{widget:r}=e,o=r.label||"SECTION";return i[0]!==o?(s=(0,t.jsx)("span",{children:o}),i[0]=o,i[1]=s):s=i[1],i[2]===Symbol.for("react.memo_cache_sentinel")?(n=(0,t.jsx)("i",{}),i[2]=n):n=i[2],i[3]!==s?(l=(0,t.jsxs)("div",{className:"dbSectionBand",role:"heading","aria-level":2,children:[s,n]}),i[3]=s,i[4]=l):l=i[4],l},defaultSize:{gw:12,gh:2},minSize:{gw:3,gh:2},bare:!0,group:"layout"},note:{labelKey:"note",label:"NOTE",Renderer:function(e){let s,n,l,i,r=(0,a.c)(12),{widget:o,onConfigure:d}=e,{t:c}=(0,Z.useTranslation)("paletteOs"),u=String(o.config.content??"");return r[0]!==c||r[1]!==o.label?(s=o.label||c("contentWidgets.note","NOTE"),r[0]=c,r[1]=o.label,r[2]=s):s=r[2],r[3]!==s?(n=(0,t.jsx)("div",{className:"dbPanelHead",children:(0,t.jsx)("span",{children:s})}),r[3]=s,r[4]=n):n=r[4],r[5]!==u||r[6]!==d||r[7]!==c?(l=(0,t.jsx)("div",{className:"pvPanelView cwNote",children:u?(0,t.jsx)(el.ChatMarkdown,{compact:!0,components:{img:sM},children:u}):(0,t.jsx)(sD,{label:c("contentWidgets.addNote","WRITE A NOTE âº"),onConfigure:d})}),r[5]=u,r[6]=d,r[7]=c,r[8]=l):l=r[8],r[9]!==n||r[10]!==l?(i=(0,t.jsxs)(t.Fragment,{children:[n,l]}),r[9]=n,r[10]=l,r[11]=i):i=r[11],i},defaultSize:{gw:4,gh:6},minSize:{gw:2,gh:3},group:"content"},image:{labelKey:"image",label:"IMAGE",Renderer:function(e){let s,n,l,i,r,o=(0,a.c)(20),{widget:d,onConfigure:c}=e,{t:u}=(0,Z.useTranslation)("paletteOs"),m=String(d.config.src??""),h=String(d.config.caption??""),p="contain"===d.config.fit?"contain":"cover";if(!m){let e,a;return o[0]!==u?(e=u("contentWidgets.addImage","ADD AN IMAGE URL âº"),o[0]=u,o[1]=e):e=o[1],o[2]!==c||o[3]!==e?(a=(0,t.jsx)(sD,{label:e,onConfigure:c}),o[2]=c,o[3]=e,o[4]=a):a=o[4],a}o[5]!==m?(s=(0,sA.checkUrl)(m),o[5]=m,o[6]=s):s=o[6];let g=s;if(!g.ok){let e;return o[7]!==g?(e=(0,t.jsx)(sR,{verdict:g}),o[7]=g,o[8]=e):e=o[8],e}let f=h||"";return o[9]!==p?(n={objectFit:p},o[9]=p,o[10]=n):n=o[10],o[11]!==f||o[12]!==n||o[13]!==g.url?(l=(0,t.jsx)("img",{src:g.url,alt:f,style:n,referrerPolicy:"no-referrer",loading:"lazy",decoding:"async"}
31),o[11]=f,o[12]=n,o[13]=g.url,o[14]=l):l=o[14],o[15]!==h?(i=h&&(0,t.jsx)("figcaption",{children:h}),o[15]=h,o[16]=i):i=o[16],o[17]!==l||o[18]!==i?(r=(0,t.jsxs)("figure",{className:"cwImage",children:[l,i]}),o[17]=l,o[18]=i,o[19]=r):r=o[19],r},defaultSize:{gw:4,gh:6},minSize:{gw:2,gh:2},bare:!0,group:"content"},embed:{labelKey:"embed",label:"EMBED",Renderer:function(e){let s,n,l,i,r,o,d=(0,a.c)(20),{widget:c,onConfigure:u}=e,{t:m}=(0,Z.useTranslation)("paletteOs"),h=function(){let{org:e}=(0,a1.useOrganisation)();return e?.embed_allowlist??null}(),p=String(c.config.src??"");if(!p){let e,a;return d[0]!==m?(e=m("contentWidgets.addEmbed","ADD AN EMBED URL âº"),d[0]=m,d[1]=e):e=d[1],d[2]!==u||d[3]!==e?(a=(0,t.jsx)(sD,{label:e,onConfigure:u}),d[2]=u,d[3]=e,d[4]=a):a=d[4],a}if(d[5]!==h||d[6]!==p||d[7]!==c.config.embedCredentialed){n=Symbol.for("react.early_return_sentinel");e:{if(!(l=(0,sA.checkUrl)(p,h)).ok){n=(0,t.jsx)(sR,{verdict:l});break e}s=!0===c.config.embedCredentialed&&!(0,sA.isSameHost)(l.url)}d[5]=h,d[6]=p,d[7]=c.config.embedCredentialed,d[8]=s,d[9]=n,d[10]=l}else s=d[8],n=d[9],l=d[10];if(n!==Symbol.for("react.early_return_sentinel"))return n;let g=s;d[11]!==g?(i=["allow-scripts","allow-popups","allow-popups-to-escape-sandbox","allow-forms",...g?["allow-same-origin"]:[]],d[11]=g,d[12]=i):i=d[12];let f=i.join(" ");return d[13]!==m||d[14]!==c.label?(r=c.label||m("contentWidgets.embed","EMBED"),d[13]=m,d[14]=c.label,d[15]=r):r=d[15],d[16]!==f||d[17]!==r||d[18]!==l.url?(o=(0,t.jsx)("iframe",{className:"cwEmbed",src:l.url,title:r,sandbox:f,referrerPolicy:"no-referrer",allow:"",loading:"lazy"}),d[16]=f,d[17]=r,d[18]=l.url,d[19]=o):o=d[19],o},defaultSize:{gw:6,gh:10},minSize:{gw:3,gh:4},bare:!0,group:"content"},button:{labelKey:"button",label:"BUTTON",Renderer:function(e){let s,n,l,i=(0,a.c)(16),{widget:r,onConfigure:o}=e,{t:d}=(0,Z.useTranslation)("paletteOs");i[0]!==d||i[1]!==r.config.text||i[2]!==r.label?(s=String(r.config.text??"")||r.label||d("contentWidgets.button","OPEN"),i[0]=d,i[1]=r.config.text,i[2]=r.label,i[3]=s):s=i[3];let c=s,u=String(r.config.href??"");if(!u){let e,a;return i[4]!==d?(e=d("contentWidgets.addLink","ADD A LINK âº"),i[4]=d,i[5]=e):e=i[5],i[6]!==o||i[7]!==e?(a=(0,t.jsx)(sD,{label:e,onConfigure:o}),i[6]=o,i[7]=e,i[8]=a):a=i[8],a}i[9]!==u?(n=(0,sA.checkUrl)(u),i[9]=u,i[10]=n):n=i[10];let m=n;if(!m.ok){let e;return i[11]!==m?(e=(0,t.jsx)(sR,{verdict:m}),i[11]=m,i[12]=e):e=i[12],e}return i[13]!==c||i[14]!==m.url?(l=(0,t.jsx)("a",{className:"cwButton",href:m.url,target:"_blank",rel:"noreferrer noopener",children:c}),i[13]=c,i[14]=m.url,i[15]=l):l=i[15],l},defaultSize:{gw:3,gh:2},minSize:{gw:2,gh:2},bare:!0,group:"content"},clock:{labelKey:"clock",label:"CLOCK",Renderer:function({widget:e}){let{t:s}=(0,Z.useTranslation)("paletteOs"),n=String(e.config.tz??"")||void 0,l="countdown"===e.config.mode,i=!1!==e.config.showSeconds,o=function(e){let t,s,n=(0,a.c)(3),[l,i]=(0,r.useState)(null);return n[0]!==e?(t=()=>{let t,a=e?1e3:3e4,s=()=>{i(new Date),t=setTimeout(s,a-Date.now()%a)};return s(),()=>clearTimeout(t)},s=[e],n[0]=e,n[1]=t,n[2]=s):(t=n[1],s=n[2]),(0,r.useEffect)(t,s),l}(i||l),d=(0,r.useMemo)(()=>{let t=e.config.countdownTo,a="string"==typeof t?Date.parse(t):NaN;return Number.isNaN(a)?null:a},[e.config.countdownTo]),c=(()=>{if(!o)return"â";if(l){let e,t,a;if(null===d)return"â";let n=d-o.getTime();return n<=0?s("contentWidgets.elapsed","ELAPSED"):(t=Math.floor((e=Math.max(0,Math.floor(n/1e3)))/86400),a=[Math.floor(e%86400/3600),Math.floor(e%3600/60),e%60].map(e=>String(e).padStart(2,"0")),t>0?`${t}d ${a.join(":")}`:a.join(":"))}try{return new Intl.DateTimeFormat(void 0,{timeZone:n,hour:"2-digit",minute:"2-digit",...i?{second:"2-digit"}:{},hour12:!0===e.config.hour12}
31).format(o)}catch{return s("contentWidgets.badZone","UNKNOWN TIMEZONE")}})(),u=l?null!==d?new Date(d).toLocaleDateString():"":n??Intl.DateTimeFormat().resolvedOptions().timeZone;return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"dbPanelHead",children:(0,t.jsx)("span",{children:e.label||u})}),(0,t.jsxs)("div",{className:"cwClock",children:[(0,t.jsx)("b",{suppressHydrationWarning:!0,children:c}),(0,t.jsx)("small",{children:u})]})]})},defaultSize:{gw:3,gh:4},minSize:{gw:2,gh:3},group:"content"},spacer:{labelKey:"spacer",label:"SPACER",Renderer:function(){return null},defaultSize:{gw:12,gh:2},minSize:{gw:1,gh:1},bare:!0,group:"layout"}},sO=new Set(["note","image","embed","button","clock","spacer"]),sP=new Set(["image","embed","button"]);function sL({type:e,verdict:a,note:s,url:n,image:l,embed:i,button:o,clock:d}){let{t:c}=(0,Z.useTranslation)("paletteOs"),u=(0,r.useMemo)(()=>{try{let e=Intl.supportedValuesOf?.("timeZone");return e?.length?e:s$}catch{return s$}},[]),m=a&&!a.ok?"scheme"===a.reason?c("contentWidgets.httpsOnly","ONLY HTTPS IS ALLOWED â GOT {{scheme}}",{scheme:a.detail||"?"}):"origin"===a.reason?c("contentWidgets.originBlocked","ORIGIN NOT ALLOWED BY YOUR WORKSPACE â {{host}}",{host:a.detail}):c("contentWidgets.badUrl","NOT A VALID URL"):null;return(0,t.jsxs)(t.Fragment,{children:["note"===e&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.body","BODY (MARKDOWN)")}),(0,t.jsx)("textarea",{"aria-label":c("widgetConfig.noteBody","NOTE"),className:"wcJson",rows:10,value:s.noteBody,onChange:e=>s.setNoteBody(e.target.value)})]}),sP.has(e)&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.url","URL (HTTPS)")}),(0,t.jsx)("input",{"aria-label":c("widgetConfig.url","URL"),value:"button"===e?n.href:n.srcUrl,onChange:t=>("button"===e?n.setHref:n.setSrcUrl)(t.target.value),placeholder:"https://",spellCheck:!1}),m&&(0,t.jsx)("span",{className:"wcErrorRow",children:m})]}),"image"===e&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.caption","CAPTION")}),(0,t.jsx)("input",{"aria-label":c("widgetConfig.caption","CAPTION"),value:l.caption,onChange:e=>l.setCaption(e.target.value)}),(0,t.jsxs)("div",{className:"gcSeg",style:{marginTop:8},children:[(0,t.jsx)("button",{className:"cover"===l.fit?"on":"",onClick:()=>l.setFit("cover"),children:c("contentWidgets.cover","COVER")}),(0,t.jsx)("button",{className:"contain"===l.fit?"on":"",onClick:()=>l.setFit("contain"),children:c("contentWidgets.contain","CONTAIN")})]})]}),"embed"===e&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.embedAuth","SIGN-IN")}),(0,t.jsx)("div",{className:"wcChips",children:(0,t.jsx)("button",{className:`wcChip${i.credentialed&&!i.sameHost?" on":""}`,disabled:i.sameHost,"aria-pressed":i.credentialed&&!i.sameHost,onClick:()=>i.setCredentialed(!i.credentialed),children:c("contentWidgets.needsSignIn","THIS EMBED NEEDS TO BE SIGNED IN")})}),(0,t.jsx)("span",{className:"wcHint",children:i.sameHost?c("contentWidgets.sameHostRefused","NOT AVAILABLE FOR THIS APP'S OWN DOMAIN"):c("contentWidgets.signInHint","OFF KEEPS THE FRAME ISOLATED. TURN ON ONLY IF THE TOOL SHOWS A LOGIN SCREEN.")})]}),"button"===e&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.buttonText","BUTTON TEXT")}),(0,t.jsx)("input",{"aria-label":c("widgetConfig.buttonText","BUTTON TEXT"),value:o.btnText,onChange:e=>o.setBtnText(e.target.value)})]}),"clock"===e&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.timezone","TIMEZONE")}),(0,t.jsxs)("select",{"aria-label":c("widgetConfig.timezone","TIMEZONE"),value:d.tz,onChange:e=>d.setTz(e.target.value),children:[(0,t.jsx)("option",{value:"",children:c("contentWidgets.localZone","THIS DEVICE")}),u.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c("contentWidgets.mode","MODE")}),(0,t.jsxs)("div",{className:"gcSeg",children:[(0,t.jsx)("button",{className:"clock"===d.clockMode?"on":"",onClick:()=>
31d.setClockMode("clock"),children:c("contentWidgets.modeClock","CLOCK")}),(0,t.jsx)("button",{className:"countdown"===d.clockMode?"on":"",onClick:()=>d.setClockMode("countdown"),children:c("contentWidgets.modeCountdown","COUNTDOWN")})]}),"countdown"===d.clockMode&&(0,t.jsx)("input",{type:"datetime-local","aria-label":c("widgetConfig.countdownTo","COUNTDOWN TO"),style:{marginTop:8},value:d.countdownTo,onChange:e=>d.setCountdownTo(e.target.value)}),(0,t.jsx)("div",{className:"wcChips",style:{marginTop:8},children:(0,t.jsx)("button",{className:`wcChip${d.showSeconds?" on":""}`,"aria-pressed":d.showSeconds,onClick:()=>d.setShowSeconds(!d.showSeconds),children:c("contentWidgets.seconds","SHOW SECONDS")})})]})]})]})}function sF(e,t){return(0,sN.visualDef)(e).controls?.includes(t)??!1}let s$=["UTC","America/Los_Angeles","America/New_York","Europe/London","Europe/Berlin","Asia/Dubai","Asia/Kolkata","Asia/Singapore","Asia/Seoul","Asia/Tokyo","Australia/Sydney"],sB=/\.(csv|tsv|xlsx|xls|parquet|json|ndjson)$/i,sH=null,sz=null;function sU(){}function sG(e){return e.json()}function sW(){}function sK(e){return e.json()}let sV=new Set(["next-runs","by-agent","outputs","new-in-drive","agent-perf"]);function sY(e){let s,n,l,i,r,o,d,c,u=(0,a.c)(29),{label:m,value:h,min:p,max:g,onChange:f}=e;u[0]!==m?(s=(0,t.jsx)("span",{className:"gcStepLbl",children:m}),u[0]=m,u[1]=s):s=u[1];let x=`${m} â`;u[2]!==p||u[3]!==f||u[4]!==h?(n=()=>f(Math.max(p,h-1)),u[2]=p,u[3]=f,u[4]=h,u[5]=n):n=u[5],u[6]!==x||u[7]!==n?(l=(0,t.jsx)("button",{"aria-label":x,onClick:n,children:"â"}),u[6]=x,u[7]=n,u[8]=l):l=u[8],u[9]!==h?(i=(0,t.jsx)("span",{className:"gcStepVal","aria-hidden":!0,children:h}),u[9]=h,u[10]=i):i=u[10];let b=`${m} ï¼`;return u[11]!==g||u[12]!==f||u[13]!==h?(r=()=>f(Math.min(g,h+1)),u[11]=g,u[12]=f,u[13]=h,u[14]=r):r=u[14],u[15]!==b||u[16]!==r?(o=(0,t.jsx)("button",{"aria-label":b,onClick:r,children:"ï¼"}),u[15]=b,u[16]=r,u[17]=o):o=u[17],u[18]!==m||u[19]!==g||u[20]!==p||u[21]!==l||u[22]!==i||u[23]!==o||u[24]!==h?(d=(0,t.jsxs)("div",{className:"gcStepCtl",role:"spinbutton","aria-label":m,"aria-valuenow":h,"aria-valuemin":p,"aria-valuemax":g,children:[l,i,o]}),u[18]=m,u[19]=g,u[20]=p,u[21]=l,u[22]=i,u[23]=o,u[24]=h,u[25]=d):d=u[25],u[26]!==s||u[27]!==d?(c=(0,t.jsxs)("div",{className:"gcStep",children:[s,d]}),u[26]=s,u[27]=d,u[28]=c):c=u[28],c}function sq({onPicked:e}){let{t:a}=(0,Z.useTranslation)("paletteOs"),[s,n]=(0,r.useState)([]),[l,i]=(0,r.useState)(null),[o,d]=(0,r.useState)([]),[c,u]=(0,r.useState)(null),[m,h]=(0,r.useState)(null);(0,r.useEffect)(()=>{(0,tA.apiFetch)("/api/v1/data-rooms").then(e=>e.json()).then(e=>n(e)).catch(()=>void 0)},[]);let p=async e=>{i(e),d([]);try{let t=await (0,tA.apiFetch)(`/api/v1/data-rooms/${e}`),a=await t.json();d((a?.files??[]).filter(e=>sB.test(e.original_filename)))}catch{d([])}},g=async t=>{u(t.original_filename),h(null);try{let a=await (0,tA.apiFetch)("/api/v1/datasets/from-data-room",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data_room_file_id:t.id})});if(!a.ok)throw Error((await a.json())?.detail??"import failed");e(await a.json())}catch(e){h(e instanceof Error?e.message:"import failed")}finally{u(null)}};return(0,t.jsxs)("div",{className:"wcRoomPick",children:[(0,t.jsxs)("div",{className:"gcActions wcGrid",children:[s.map(e=>(0,t.jsx)("button",{className:`gcAction${l===e.id?" on":""}`,onClick:()=>p(e.id),children:e.name.toUpperCase()},e.id)),!s.length&&(0,t.jsx)("span",{className:"dbEmpty",children:a("widgetConfig.noRooms","NO DRIVES")})]}),null!==l&&(0,t.jsxs)("div",{className:"gcActions wcGrid",children:[o.map(e=>(0,t.jsx)("button",{className:"gcAction",disabled:!!c,onClick:()=>g(e),children:c===e.original_filename?a("widgetConfig.importing","IMPORTINGâ¦"):e.original_filename},e.id)),!o.length&&(0,t.jsx)("span",{className:"dbEmpty",children:a("widgetConfig.noTabularFiles","NO SPREADSHEET/CSV FILES AT ROOT")})]}),m&&(0,t.jsx)("span",{className:"dbEmpty",children:m})]})}function sJ({widget:e,onSave:s,onRemove:n}){let{t:l}=(0,Z.useTranslation)("paletteOs"),i=sI[e.type],o="data"===e.type,d=function(){let e,t,s=(0,a.c)(2),[n,l]=(0,r.useState)(sH);return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=()=>{if(sH)return;let e=!1;return(0,tA.apiFetch)("/api/v1/insights-dashboards/data/live-sources").then(sG).then(t=>{sH={...t,connections:t.connections??[]},e||l(sH)}).catch(sU),()=>{e=!0}},t=[],s[0]=e,s[1]=t):(e=s[0],t=s[1]),(0,r.useEffect)(e,t),n}(),[c,u]=function(){let e,t,s,n,l,i=(0,a.c)(6);i[0]===Symbol.for("react.memo_cache_sentinel")?(e=sz??[],i[0]=e):e=i[0];let[o,d]=(0,r.useState)(e);i[1]===Symbol.for("react.memo_cache_sentinel")?(t=()=>{if(sz)return;let e=!1;return(0,tA.apiFetch)("/api/v1/datasets").then(sK).then(t=>{sz=t,e||d(t)}).catch(sW),()=>{e=!0}},s=[],i[1]=t,i[2]=s):(t=i[1],s=i[2]),(0,r.useEffect)(t,s),i[3]===Symbol.for("react.memo_cache_sentinel")?(n=e=>{d(sz=[e,...sz??[]])},i[3]=n):n=i[3];let c=n;return i[4]!==o?(l=[o,c],i[4]=o,i[5]=l):l=i[5],l}(),m=e.config.binding??null,[h,p]=(0,r.useState)(e.label??""),[g,f]=(0,r.useState)(e.gw),[x,b]=(0,r.useState)(e.gh),[v,j]=(0,r.useState)(Number(e.config.days)||14),y=sV.has(e.type),[w,k]=(0,r.useState)(Number(e.config.limit)||20),[N,C]=(0,r.useState)(String(Number(e.config.budgetLimitUsd)||50)),[S,_]=(0,r.useState)("org"===e.config.scope?"org":"user"),[T,E]=(0,r.useState)(m),[A,R]=(0,r.useState)(e.config.visual??"stat"),[D,M]=(0,r.useState)(""),[I,O]=(0,r.useState)(e.config.latKey??""),[P,L]=(0,r.useState)(e.config.lngKey??""),[F,$]=(0,r.useState)(e.config.content??""),[B,H]=(0,r.useState)(e.config.src??""),[z,U]=(0,r.useState)(e.config.caption??""),[G,W]=(0,r.useState)("contain"===e.config.fit?"contain":"cover"),[K,V]=(0,r.useState)(!0===e.config.embedCredentialed),[Y,q]=(0,r.useState)(e.config.text??""),[J,X]=(0,r.useState)(e.config.href??""),[Q,ee]=(0,r.useState)(e.config.tz??""),[et,ea]=(0,r.useState)("countdown"===e.config.mode?"countdown":"clock"),[es,en]=(0,r.useState)(e.config.countdownTo??""),[el,ei]=(0,r.useState)(!1!==e.config.showSeconds),er="image"===e.type||"embed"===e.type?B:J,eo=sP.has(e.type)&&er?(0,sA.checkUrl)(er):null,[ed,ec]=(0,r.useState)(e.config.labelKey??""),[eu,em]=(0,r.useState)(e.config.valueKey??""),[eh,ep]=(0,r.useState)(e.config.template??""),[eg,ef]=(0,r.useState)(e.config.prefix??""),[ex,eb]=(0,r.useState)(e.config.suffix??""),[ev,ej]=(0,r.useState)(e.config.format??""),[ey,ew]=(0,r.useState)(Number(e.config.refreshSec)||60),[ek,eN]=(0,r.useState)(e.config.dateField??""),[eC,eS]=(0,r.useState)(!0===e.config.forecast),[e_,eT]=(0,r.useState)(!1),eE=e.config.alert??{},[eA,eR]=(0,r.useState)(!!eE.enabled),[eD,eM]=(0,r.useState)(eE.op??">"),[eI,eO]=(0,r.useState)(null!=eE.value?String(eE.value):""),[eP,eL]=(0,r.useState)(()=>m?"mcp.tool"===m.kind||"broker.service"===m.kind?JSON.stringify(m.params?.payload??{}):"connection.tool"===m.kind?JSON.stringify(m.params?.args??{}):"static"===m.kind?"{}":JSON.stringify(m.params??{}):"{}"),[eF,e$]=(0,r.useState)(()=>m?.kind==="static"?JSON.stringify(m.params?.data??{},null,2):""),[eB,eH]=(0,r.useState)([]),[ez,eU]=(0,r.useState)([]),[eG,eW]=(0,r.useState)(()=>m?.kind==="dataset"?(m.dimensions??[]).map(e=>"string"==typeof e?e:e.column):[]),[eK,eV]=(0,r.useState)(()=>m?.kind==="dataset"?(m.measures??[]).map(e=>"string"==typeof e?e:e.column):[]),[eY,eq]=(0,r.useState)(()=>m?.kind!=="dataset"?{}:Object.fromEntries((m.measures??[]).flatMap(e=>"string"==typeof e?[]:[[e.column,e.agg??"sum"]]))),[eJ,eX]=(0,r.useState)(()=>m?.kind!=="dataset"?{}:Object.fromEntries((m.dimensions??[]).flatMap(e=>"string"!=typeof e&&e.grain?[[e.column,e.grain]]:[]))),[eZ,eQ]=(0,r.useState)(()=>m?.kind==="dataset"?(m.filters??[]).map(e=>({column:String(e.column??""),op:String(e.op??"="),value:null===e.value||void 0===e.value?"":String(e.value)})):[]),e0=m?.kind==="dataset"?m.sort?.[0]:void 0,[e1,e2]=(0,r.useState)(String(e0?.by??"")),[e3,e4]=(0,r.useState)(String(e0?.dir??"desc")),[e5,e6]=(0,r.useState)(()=>m?.kind==="dataset"&&m.limit?String(m.limit):"200"),[e7,e8]=(0,r.useState)(null!=e.config.target?Str
31ing(e.config.target):""),[e9,te]=(0,r.useState)(null!=e.config.rowCap?String(e.config.rowCap):""),[tt,ta]=(0,r.useState)(""),ts=m?.kind==="dataset"?m.join:void 0,[tn,tl]=(0,r.useState)(ts?.dataset_id??""),[ti,tr]=(0,r.useState)(ts?.left_on??""),[to,td]=(0,r.useState)(ts?.right_on??""),[tc,tu]=(0,r.useState)([]),tm=(0,r.useMemo)(()=>{if(!tn||!ti||!to)return[];let e=new Set(eB.map(e=>e.name));return tc.filter(t=>!e.has(t.name)&&t.name!==to)},[tn,ti,to,tc,eB]),th=(0,r.useMemo)(()=>[...eB,...tm],[eB,tm]),tp=(e={})=>{let t=e.dims??eG,a=e.meas??eK,s=e.aggs??eY,n=e.grains??eJ,l=e.filters??eZ,i=e.sortBy??e1,r=e.sortDir??e3,o=Math.max(1,Math.min(5e4,Number(e.limit??e5)||200)),d=void 0!==e.join?e.join:tn&&ti&&to?{dataset_id:tn,left_on:ti,right_on:to}:null;E(e=>{if(e?.kind!=="dataset")return e;let c={...e,dimensions:t.map(e=>n[e]?{column:e,grain:n[e]}:e),measures:a.map(e=>{let t=s[e];return t&&"sum"!==t&&!ez.includes(e)?{column:e,agg:t}:e}),filters:l.filter(e=>e.column&&("is_null"===e.op||"not_null"===e.op||""!==e.value)).map(e=>({column:e.column,op:e.op,..."is_null"===e.op||"not_null"===e.op?{}:{value:e.value}})),sort:i?[{by:i,dir:r}]:[],limit:o};return d?c.join=d:delete c.join,c})},tg=async e=>{try{let t=await (await (0,tA.apiFetch)(`/api/v1/datasets/${e}`)).json();tu((t.schema_json?.columns??[]).map(e=>({name:e.name,role:e.role})))}catch{tu([])}};(0,r.useEffect)(()=>{ts?.dataset_id&&tg(ts.dataset_id)},[]);let tf=async e=>{try{let[t,a]=await Promise.all([(0,tA.apiFetch)(`/api/v1/datasets/${e}`),(0,tA.apiFetch)(`/api/v1/datasets/${e}/measures`)]),s=await t.json(),n=await a.json(),l=(s.schema_json?.columns??[]).map(e=>({name:e.name,role:e.role}));eH(l),eN(e=>e||l.find(e=>"time"===e.role)?.name||""),eU(n.map(e=>e.name))}catch{eH([]),eU([])}};(0,r.useEffect)(()=>{m?.kind==="dataset"&&m.dataset_id&&tf(m.dataset_id)},[]);let{data:tx}=sm(o?T:null,300),tb=(0,r.useMemo)(()=>(0,sh.normalizeColumnar)(tx,e.config.pick),[tx,e.config.pick]),tv=(e,t)=>{eL("{}"),E({kind:e,params:{target:t.target,payload:{}}})},tj=e=>{eW([]),eV([]),eq({}),eX({}),eQ([]),e2(""),e4("desc"),e6("200"),eN(""),E({kind:"dataset",dataset_id:e,dimensions:[],measures:[],limit:200}),tf(e)},ty=(0,r.useRef)(null),[tw,tk]=(0,r.useState)(!1);(0,r.useEffect)(()=>()=>{ty.current&&window.clearTimeout(ty.current)},[]);let tN=(0,r.useRef)(null);(0,r.useEffect)(()=>()=>{tN.current&&window.clearTimeout(tN.current)},[]);let tC=e=>{eQ(e),tp({filters:e})},tS=(0,sN.rendererFor)(A),t_={labelKey:ed||void 0,valueKey:eu||void 0,template:eh,prefix:eg,suffix:ex,format:ev||void 0,target:Number(e7)>0?Number(e7):void 0,latKey:I||void 0,lngKey:P||void 0,rowCap:Number(e9)>0?Number(e9):void 0},tT=T?.kind,tE=[...new Set([...ez,...th.filter(e=>"measure"===e.role).map(e=>e.name)])],tR=new Set(eB.filter(e=>"time"===e.role).map(e=>e.name)),tD=e=>!tt||e.toLowerCase().includes(tt.toLowerCase());return(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[(0,t.jsx)("div",{className:"gcTitle",children:h||i.label}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.label","LABEL")}),(0,t.jsx)("input",{"aria-label":l("widgetConfig.label","LABEL"),value:h,onChange:e=>p(e.target.value.toUpperCase()),placeholder:i.label})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.size","SIZE")}),(0,t.jsxs)("div",{className:"gcSteps",children:[(0,t.jsx)(sY,{label:l("widgetConfig.width","W"),value:g,min:i.minSize.gw,max:aL.PO_GRI
31D_COLS,onChange:f}),(0,t.jsx)(sY,{label:l("widgetConfig.height","H"),value:x,min:i.minSize.gh,max:30,onChange:b})]})]}),"run-volume"===e.type&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.days","DAYS")}),(0,t.jsx)("div",{className:"gcSteps",children:(0,t.jsx)(sY,{label:l("widgetConfig.days","DAYS"),value:v,min:7,max:30,onChange:j})})]}),y&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.rows","ROWS")}),(0,t.jsx)("div",{className:"gcSteps",children:(0,t.jsx)(sY,{label:l("widgetConfig.rows","ROWS"),value:w,min:1,max:50,onChange:k})})]}),"cost"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{htmlFor:`budget-${e.id}`,children:l("widgetConfig.budgetLimit","BUDGET LIMIT (USD)")}),(0,t.jsx)("input",{id:`budget-${e.id}`,type:"number",min:"1",step:"1",value:N,onChange:e=>C(e.target.value)})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.costScope","SCOPE")}),(0,t.jsxs)("div",{className:"gcSeg",children:[(0,t.jsx)("button",{className:"user"===S?"on":"",onClick:()=>_("user"),children:l("widgetConfig.scopeMine","MINE")}),(0,t.jsx)("button",{className:"org"===S?"on":"",onClick:()=>_("org"),children:l("widgetConfig.scopeOrg","WORKSPACE")})]})]})]}),sO.has(e.type)&&(0,t.jsx)(sL,{type:e.type,verdict:eo,note:{noteBody:F,setNoteBody:$},url:{srcUrl:B,setSrcUrl:H,href:J,setHref:X},image:{caption:z,setCaption:U,fit:G,setFit:W},embed:{credentialed:K,setCredentialed:V,sameHost:(0,sA.isSameHost)(B)},button:{btnText:Y,setBtnText:q},clock:{tz:Q,setTz:ee,clockMode:et,setClockMode:ea,countdownTo:es,setCountdownTo:en,showSeconds:el,setShowSeconds:ei}}),o&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{htmlFor:`source-search-${e.id}`,children:l("widgetConfig.searchSources","SEARCH SOURCES")}),(0,t.jsx)("input",{id:`source-search-${e.id}`,value:tt,onChange:e=>ta(e.target.value),placeholder:l("widgetConfig.searchPlaceholder","FILTER SOURCES & DATASETSâ¦")})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.source","SOURCE â ORG DATA")}),(0,t.jsxs)("div",{className:"gcActions wcGrid",children:[(d?.builtin??[]).filter(e=>tD(e.label)||tD(e.kind)).map(e=>(0,t.jsx)("button",{className:`gcAction${tT===e.kind?" on":""}`,onClick:()=>(e=>{let t={};for(let a of e.params)null!=a.default&&(t[a.name]=a.default);E({kind:e.kind,params:t}),eL(JSON.stringify(t))})(e),children:e.label.toUpperCase()},e.kind)),(0,t.jsx)("button",{className:`gcAction${"static"===tT?" on":""}`,onClick:()=>{e$(e=>e||'{\n "columns": ["label", "value"],\n "rows": [["A", 1]]\n}'),E({kind:"static",params:{data:{}}})},children:l("widgetConfig.staticSource","STATIC JSON")})]})]}),(d?.connections?.length??0)>0&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.connections","CONNECTED SOURCES")}),(0,t.jsx)("div",{className:"gcActions wcGrid",children:d.connections.filter(e=>tD(`${e.provider} ${e.tool} ${e.label}`)).map(e=>(0,t.jsxs)("button",{className:`gcAction${"connection.tool"===tT&&T?.params?.tool===e.tool?" on":""}`,title:e.label,onClick:()=>{eL("{}"),E({kind:"connection.tool",params:{provider:e.provider,tool:e.tool,args:{}}})},children:[e.provider.toUpperCase()," · ",e.tool.toUpperCase()]},`${e.provider}:${e.tool}`))})]}),((d?.plugin?.length??0)>0||(d?.mcp?.length??0)>0||(d?.broker?.length??0)>0)&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.appsMcp","APPS & MCP")}),(0,t.jsxs)("div",{className:"gcActions wcGrid",children:[(d?.plugin??[]).filter(e=>tD(`${e.name??""} ${e.key} ${e.plugin_id}`)).map(e=>(0,t.jsxs)("button",{className:`gcAction${"plugin"===tT&&T?.source_key===e.key?" on":""}`,onClick:()=>E({kind:"plugin",plugin_id:e.plugin_id,source_key:e.key,params:{}}),children:[(e.name||e.key).toUpperCase()," · ",e.plugin_id.toUpperCase()]},`${e.plugin_id}:${e.key}`)),(d?.mcp??[]).filter(e=>tD(e.label)).map(e=>(0,t.jsxs)("button",{className:`gcAction${"mcp.tool"===tT&&T?.params?.target===e.target?" on":""}`,onClick:()=>tv("mcp.tool",e),children:["MCP · ",e.label.toUpperCase()]},e.target)),(d?.broker??[]).filter(e=>tD(e.label)).map(e=>(0,t.jsxs)("button",{className:`gcAction${"broker.service"===tT&&T?.params?.target===e.target?" on":""}`,onClick:()=>tv("broker.service",e),children:["APP · ",e.label.toUpperCase()]},e.target))]})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.datasets","DATASETS · SPREADSHEETS")}),(0,t.jsxs)("div",{className:"gcActions wcGrid",children:[c.filter(e=>tD(e.name)).map(e=>(0,t.jsx)("button",{className:`gcAction${"dataset"===tT&&T?.dataset_id===e.id?" on":""}`,onClick:()=>tj(e.id),children:e.name.toUpperCase()},e.id)),(0,t.jsx)("button",{className:`gcAction${e_?" on":""}`,onClick:()=>eT(e=>!e),children:l("widgetConfig.fromDataRoom","ï¼ FROM DRIVE")})]}),e_&&(0,t.jsx)(sq,{onPicked:e=>{u(e),eT(!1),tj(e.id)}})]}),"dataset"===tT&&eB.length>0&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.dimensions","GROUP BY (COLUMNS)")}),(0,t.jsx)("div",{className:"wcChips",children:th.map(e=>(0,t.jsx)("button",{className:`wcChip${eG.includes(e.name)?" on":""}`,onClick:()=>{var t;let a;return t=e.name,void(eW(a=eG.includes(t)?eG.filter(e=>e!==t):[...eG,t]),tp({dims:a}))},children:e.name},e.name))}),eG.filter(e=>tR.has(e)).map(e=>(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("span",{className:"wcInlineLbl",children:e}),(0,t.jsxs)("select",{value:eJ[e]??"",onChange:t=>{var a;let s;return a=t.target.value,s={...eJ},void(a?s[e]=a:delete s[e],eX(s),tp({grains:s}))},"aria-label":l("widgetConfig.grain","TIME GRAIN"),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.grainExact","EXACT VALUES")}),["hour","day","week","month","quarter","year"].map(e=>(0,t.jsx)("option",{value:e,children:l(`widgetConfig.grains.${e}`,e.toUpperCase())},e))]})]},`grain-${e}`)),(0,t.jsx)("label",{children:l("widgetConfig.measures","MEASURES")}),(0,t.jsxs)("div",{className:"wcChips",children:[tE.map(e=>(0,t.jsx)("button",{className:`wcChip${eK.includes(e)?" on":""}`,onClick:()=>{let t;eV(t=eK.includes(e)?eK.filter(t=>t!==e):[...eK,e]),tp({meas:t})},children:e},e)),!tE.length&&(0,t.jsx)("span",{className:"dbEmpty",children:l("widgetConfig.noMeasures","NO NUMERIC COLUMNS")})]}),eK.filter(e=>!ez.includes(e)).map(e=>(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("span",{className:"wcInlineLbl",children:e}),(0,t.jsx)("select",{value:eY[e]??"sum",onChange:t=>{var a;let s;return a=t.target.value,void(eq(s={...eY,[e]:a}),tp({aggs:s}))},"aria-label":l("widgetConfig.aggregation","AGGREGATION"),children:["sum","avg","min","max","count","count_distinct"].map(e=>(0,t.jsx)("option",{value:e,children:l(`widgetConfig.aggs.${e}`,e.replace("_"," ").toUpperCase())},e))})]},`agg-${e}`)),(0,t.jsx)("label",{children:l("widgetConfig.join","JOIN ANOTHER DATASET (OPTIONAL)")}),(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsxs)("select",{"aria-label":l("widgetConfig.joinDataset","JOIN DATASET"),value:tn,onChange:e=>{let t=e.target.value;tl(t),td(""),tu([]),t?tg(t):tp({join:null})},children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.noJoin","NO JOIN")}),c.filter(e=>T?.kind==="dataset"&&e.id!==T.dataset_id).map(e=>(0,t.jsx)("option",{value:e.id,children:e.name},e.id))]}),tn&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("select",{"aria-label":l("widgetConfig.joinLeft","THIS DATASET'S KEY"),value:ti,onChange:e=>{tr(e.target.value),tp(e.target.value&&to?{join:{dataset_id:tn,left_on:e.target.value,right_on:to}}:{join:null})},children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.joinLeft","THIS KEY")}),eB.map(e=>(0,t.jsx)("option",{value:e.name,children:e.name},e.name))]}),(0,t.jsxs)("select",{"aria-label":l("widgetConfig.joinRight","JOINED DATASET'S KEY"),value:to,onChange:e=>{td(e.target.value),tp(ti&&e.target.value?{join:{dataset_id:tn,left_on:ti,right_on:e.target.value}}:{join:null})},children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.joinRight","THEIR KEY")}),tc.map(e=>(0,t.jsx)("option",{value:e.name,children:e.name},e.name))]})]})]}),(0,t.jsx)("label",{children:l("widgetConfig.filters","FILTERS")}),eZ.map((e,a)=>(0,t.jsxs)("div",{className:"wcMapRow wcFilterRow",children:[(0,t.jsxs)("select",{value:e.column,onChange:e=>tC(eZ.map((t,s)=>s===a?{...t,column:e.target.value}:t)),"aria-label":l("widgetConfig.filterColumn","FILTER COLUMN"),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.filterColumn","COLUMN")}),th.map(e=>(0,t.jsx)("option",{value:e.name,children:e.name},e.name))]}),(0,t.jsx)("select",{value:e.op,onChange:e=>tC(eZ.map((t,s)=>s===a?{...t,op:e.target.value}:t)),"aria-label":l("widgetConfig.filterOp","OPERATOR"),children:["=","!=",">",">=","<","<=","contains","starts_with","not_null","is_null"].map(e=>(0,t.jsx)("option",{value:e,children:e},e))}),"not_null"!==e.op&&"is_null"!==e.op&&(0,t.jsx)("input",{value:e.value,onChange:e=>tC(eZ.map((t,s)=>s===a?{...t,value:e.target.value}:t)),placeholder:l("widgetConfig.filterValue","VALUE"),"aria-label":l("widgetConfig.filterValue","VALUE")}),(0,t.jsx)("button",{className:"wcChip",onClick:()=>tC(eZ.filter((e,t)=>
31t!==a)),"aria-label":l("widgetConfig.removeFilter","Remove filter"),children:"â"})]},a)),(0,t.jsx)("div",{className:"wcChips",children:(0,t.jsx)("button",{className:"wcChip",onClick:()=>tC([...eZ,{column:eB[0]?.name??"",op:"=",value:""}]),children:l("widgetConfig.addFilter","ï¼ FILTER")})}),(0,t.jsx)("label",{children:l("widgetConfig.sortLimit","SORT · LIMIT")}),(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsxs)("select",{value:e1,onChange:e=>{e2(e.target.value),tp({sortBy:e.target.value})},"aria-label":l("widgetConfig.sortBy","SORT BY"),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.noSort","NO SORT")}),[...new Set([...eG,...eK])].map(e=>(0,t.jsx)("option",{value:e,children:e},e)),eG.length>0&&!eK.length&&(0,t.jsx)("option",{value:"__count__",children:"__count__"})]}),(0,t.jsxs)("select",{value:e3,onChange:e=>{e4(e.target.value),tp({sortDir:e.target.value})},"aria-label":l("widgetConfig.sortDir","DIRECTION"),disabled:!e1,children:[(0,t.jsx)("option",{value:"desc",children:l("widgetConfig.desc","DESC")}),(0,t.jsx)("option",{value:"asc",children:l("widgetConfig.asc","ASC")})]}),(0,t.jsx)("input",{value:e5,onChange:e=>{var t;e6(t=e.target.value),tN.current&&window.clearTimeout(tN.current),tN.current=window.setTimeout(()=>tp({limit:t}),500)},inputMode:"numeric","aria-label":l("widgetConfig.limit","ROW LIMIT"),placeholder:l("widgetConfig.limit","LIMIT")})]}),(0,t.jsx)("label",{htmlFor:`date-field-${e.id}`,children:l("widgetConfig.dateField","DASHBOARD DATE FILTER")}),(0,t.jsxs)("select",{id:`date-field-${e.id}`,value:ek,onChange:e=>eN(e.target.value),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.noDateField","DO NOT APPLY BOARD RANGE")}),eB.filter(e=>"time"===e.role).map(e=>(0,t.jsx)("option",{value:e.name,children:e.name},e.name))]}),["area","line","sparkline"].includes(A)&&(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("label",{className:"wcInlineLbl",htmlFor:`forecast-${e.id}`,children:l("widgetConfig.forecast","FORECAST (LINEAR TREND)")}),(0,t.jsx)("input",{id:`forecast-${e.id}`,type:"checkbox",checked:eC,onChange:e=>eS(e.target.checked)})]})]}),tT&&!["static","dataset","plugin"].includes(tT)&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.params","PARAMS (JSON)")}),(0,t.jsx)("textarea",{className:"wcJson",rows:3,value:eP,onChange:e=>{var t;eL(t=e.target.value),ty.current&&window.clearTimeout(ty.current),ty.current=window.setTimeout(()=>{try{let e=JSON.parse(t);tk(!1),E(t=>t?"mcp.tool"===t.kind||"broker.service"===t.kind?{...t,params:{target:t.params?.target,payload:e}}:"connection.tool"===t.kind?{...t,params:{provider:t.params?.provider,tool:t.params?.tool,args:e}}:{...t,params:e}:t)}catch{tk(!0)}},500)},spellCheck:!1,"aria-invalid":tw}),tw&&(0,t.jsx)("span",{className:"wcJsonErr",role:"alert",children:l("widgetConfig.invalidJson","INVALID JSON â CHANGES NOT APPLIED")})]}),"static"===tT&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.staticData","DATA (JSON)")}),(0,t.jsx)("textarea",{"aria-label":l("widgetConfig.staticData","STATIC DATA (JSON)"),className:"wcJson",rows:6,value:eF,onChange:e=>(e=>{e$(e);try{E({kind:"static",params:{data:JSON.parse(e)}})}catch{}})(e.target.value),spellCheck:!1})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.visual","VISUAL")}),(0,t.jsx)("input",{className:"wcVisualSearch",value:D,onChange:e=>M(e.target.value),placeholder:l("widgetConfig.visualSearch","FILTER VISUALSâ¦"),"aria-label":l("widgetConfig.visualSearch","FILTER VISUALSâ¦")}),(0,sN.visualGroups)(D).map(a=>(0,t.jsxs)("div",{className:"wcVisualGroup",children:[(0,t.jsx)("span",{className:"wcVisualGroupLabel",children:l(`widgetConfig.visualGroups.${a.group}`,a.group.toUpperCase())}),(0,t.jsx)("div",{className:"gcActions wcGrid wcGrid3",children:a.visuals.map(a=>(0,t.jsx)("button",{className:`gcAction${A===a?" on":""}`,onClick:()=>(t=>{let a=(0,sN.visualDef)(A).size,s=sI[e.type].defaultSize,n=g===a.gw&&x===a.gh||g===s.gw&&x===s.gh;if(R(t),n){let e=(0,sN.visualDef)(t).size;f(e.gw),b(e.gh)}})(a),children:l(`widgetConfig.visuals.${a}`,a.toUpperCase())},a))})]},a.group))]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.mapping","MAPPING")}),(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsxs)("select",{"aria-label":l("widgetConfig.labelKey","LABEL KEY"),value:ed,onChange:e=>ec(e.target.value),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.labelKey","LABEL COLUMN")}),tb.columns.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]}),(0,t.jsxs)("select",{"aria-label":l("widgetConfig.valueKey","VALUE KEY"),value:eu,onChange:e=>em(e.target.value),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.valueKey","VALUE COLUMN")}),[...new Set([...tb.columns,...Object.keys(tb.scalars)])].map(e=>(0,t.jsx)("option",{value:e,children:e},e))]})]}
31),"pin-map"===A&&(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsxs)("select",{value:I,onChange:e=>O(e.target.value),"aria-label":l("widgetConfig.latLbl","LATITUDE"),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.latLbl","LATITUDE")}),tb.columns.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]}),(0,t.jsxs)("select",{value:P,onChange:e=>L(e.target.value),"aria-label":l("widgetConfig.lngLbl","LONGITUDE"),children:[(0,t.jsx)("option",{value:"",children:l("widgetConfig.lngLbl","LONGITUDE")}),tb.columns.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]})]}),(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("input",{"aria-label":l("widgetConfig.prefix","PREFIX"),value:eg,onChange:e=>ef(e.target.value),placeholder:l("widgetConfig.prefix","PREFIX ($)")}),(0,t.jsx)("input",{"aria-label":l("widgetConfig.suffix","SUFFIX"),value:ex,onChange:e=>eb(e.target.value),placeholder:l("widgetConfig.suffix","SUFFIX (%)")})]}),(0,t.jsx)("div",{className:"wcChips",children:[["",l("widgetConfig.formatAuto","AUTO")],["number",l("widgetConfig.formatNumber","NUMBER")],["compact",l("widgetConfig.formatCompact","COMPACT")],["currency",l("widgetConfig.formatCurrency","CURRENCY")],["percent",l("widgetConfig.formatPercent","PERCENT")]].map(([e,a])=>(0,t.jsx)("button",{className:`wcChip${ev===e?" on":""}`,onClick:()=>ej(e),"aria-pressed":ev===e,children:a},e))}),sF(A,"target")&&(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("span",{className:"wcInlineLbl",children:l("widgetConfig.maxLbl","TARGET / MAX")}),(0,t.jsx)("input",{value:e7,onChange:e=>e8(e.target.value),inputMode:"numeric",placeholder:l("widgetConfig.maxHint","DENOMINATOR (DEFAULT 100)"),"aria-label":l("widgetConfig.maxLbl","TARGET / MAX")})]}),sF(A,"rowCap")&&(0,t.jsxs)("div",{className:"wcMapRow",children:[(0,t.jsx)("span",{className:"wcInlineLbl",children:l("widgetConfig.rowCapLbl","ROW CAP")}),(0,t.jsx)("input",{value:e9,onChange:e=>te(e.target.value),inputMode:"numeric",placeholder:l("widgetConfig.rowCapHint","TOP N ROWS (DEFAULT PER VISUAL)"),"aria-label":l("widgetConfig.rowCapLbl","ROW CAP")})]}),"text"===A&&(0,t.jsx)("textarea",{"aria-label":l("widgetConfig.template","TEMPLATE"),className:"wcJson",rows:2,value:eh,onChange:e=>ep(e.target.value),placeholder:l("widgetConfig.templateHint","{{field}} interpolation"),spellCheck:!1})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.refresh","REFRESH (SEC)")}),(0,t.jsx)("div",{className:"gcSteps",children:(0,t.jsx)(sY,{label:l("widgetConfig.refresh","SEC"),value:ey,min:30,max:3600,onChange:ew})})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.alert","ALERT â NOTIFY WHEN VALUE")}),(0,t.jsxs)("div",{className:"wcAlertRow",children:[(0,t.jsx)("button",{className:`wcChip${eA?" on":""}`,onClick:()=>eR(e=>!e),children:eA?l("widgetConfig.alertEnabled","ARMED"):l("widgetConfig.alertDisabled","OFF")}),(0,t.jsx)("div",{className:"gcSeg",children:[">",">=","<","<="].map(e=>(0,t.jsx)("button",{className:eD===e?"on":"",onClick:()=>eM(e),children:e},e))}),(0,t.jsx)("input",{inputMode:"decimal","aria-label":l("widgetConfig.alertThreshold","THRESHOLD"),value:eI,onChange:e=>eO(e.target.value),placeholder:l("widgetConfig.alertThreshold","THRESHOLD")})]}),(0,t.jsx)("span",{className:"wcHint",children:l("widgetConfig.alertHint","Checked every 5 min server-side; you get a notification when it crosses.")})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:l("widgetConfig.preview","PREVIEW")}),(0,t.jsx)("div",{className:"wcPreview",children:tb.error?(0,t.jsx)("span",{className:"dbEmpty",children:tb.error}):(0,t.jsx)(tS,{data:tb,opts:t_})})]})]}),(0,t.jsxs)("div",{className:"gcFoot",children:[(0,t.jsx)("button",{className:"gcDelete",onClick:n,children:l("widgetConfig.remove","REMOVE")}),(0,t.jsx)("button",{className:"gcDone",onClick:()=>{let t={};if("run-volume"===e.type&&(t.days=v),y&&(t.limit=w),"cost"===e.type){let e=Number(N);t.budgetLimitUsd=Number.isFinite(e)&&e>0?e:50,t.scope=S}if(o){let e=Number(eI);Object.assign(t,{binding:T,visual:A,labelKey:ed||void 0,valueKey:eu||void 0,template:eh||void 0,prefix:eg||void 0,suffix:ex||void 0,format:ev||void 0,target:sF(A,"target")&&Number(e7)>0?Number(e7):void 0,latKey:"pin-map"===A&&I||void 0,lngKey:"pin-map"===A&&P||void 0,rowCap:sF(A,"rowCap")&&Number(e9)>0?Number(e9):void 0,dateField:T?.kind==="dataset"&&ek||void 0,forecast:!!(eC&&["area","line","sparkline"].includes(A))||void 0,refreshSec:ey,sample:void 0,alert:eA&&Number.isFinite(e)?{enabled:!0,op:eD,value:e,field:eu||void 0,lastState:eE.lastState??!1}:void 0})}"note"===e.type&&Object.assign(t,{content:F}),"image"===e.type&&Object.assign(t,{src:B,caption:z,fit:G}),"embed"===e.type&&Object.assign(t,{src:B,embedCredentialed:K}),"button"===e.type&&Object.assign(t,{text:Y,href:J}),"clock"===e.type&&Object.assign(t,{tz:Q||void 0,mode:et,showSeconds:el,countdownTo:"countdown"===et&&es||void 0}),s({label:h||void 0,gw:g,gh:x},t)},children:l("widgetConfig.done","DONE")})]})]})}function sX({widgets:e,onAdd:a,onAddBuilt:s}){let{t:n}=(0,Z.useTranslation)("paletteOs"),[l,i]=(0,r.useState)(""),[o,d]=(0,r.useState)(!1),[c,u]=(0,r.useState)(null),m=new Set(e.map(e=>e.type)),h=Object.entries(sI),p=async()=>{let e=l.trim();if(e&&!o){d(!0),u(null);try{let t=await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/ai-widget",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e})}),a=await t.json();
31a?.error||!a?.binding?u(a?.error??n("widgetPicker.aiFailed","Could not build that widget")):s(a)}catch{u(n("widgetPicker.aiFailed","Could not build that widget"))}finally{d(!1)}}};return(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[(0,t.jsx)("div",{className:"gcTitle",children:n("widgetPicker.title","ADD WIDGET")}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:n("widgetPicker.ai","DESCRIBE IT â AI BUILDS IT")}),(0,t.jsxs)("div",{className:"wcAiRow",children:[(0,t.jsx)("input",{value:l,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&p()},placeholder:n("widgetPicker.aiPlaceholder","e.g. AI spend by model this month as a donut"),disabled:o}),(0,t.jsx)("button",{className:"gcDone",onClick:()=>void p(),disabled:o||!l.trim(),children:o?n("widgetPicker.aiBuilding","BUILDINGâ¦"):n("widgetPicker.aiBuild","BUILD")})]}),c&&(0,t.jsx)("span",{className:"dbEmpty",children:c})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:n("widgetPicker.data","DATA")}),(0,t.jsx)("div",{className:"gcActions",children:(0,t.jsxs)("button",{className:"gcAction wpData",onClick:()=>a("data"),children:[n("widgetPicker.types.data","DATA WIDGET")," â ",n("widgetPicker.dataHint","ANY SOURCE · ANY VISUAL")]})})]}),[["org",n("widgetPicker.builtins","ORG WIDGETS")],["content",n("widgetPicker.content","CONTENT")],["layout",n("widgetPicker.layout","LAYOUT")]].map(([e,s])=>{let l=h.filter(([t,a])=>"data"!==t&&(a.group??"org")===e);return l.length?(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:s}),(0,t.jsx)("div",{className:"gcActions wcGrid",children:l.map(([e,s])=>{let l=!!s.singleton&&m.has(e);return(0,t.jsxs)("button",{className:"gcAction",disabled:l,style:l?{opacity:.35,pointerEvents:"none"}:void 0,onClick:()=>a(e),children:[n(`widgetPicker.types.${s.labelKey}`,s.label),l?` \xb7 ${n("widgetPicker.placed","ON BOARD")}`:""]},e)})})]},e):null})]})}function sZ(e){let s,n,l,i=(0,a.c)(9),{widgets:r}=e;i[0]!==r?(s=Math.max(1,...r.map(sQ)),i[0]=r,i[1]=s):s=i[1];let o=s;if(i[2]!==o||i[3]!==r){let e;i[5]!==o?(e=e=>(0,t.jsx)("span",{className:`tpBlock${"data"===e.type?" tpData":""}`,style:{left:`${e.gx/aL.PO_GRID_COLS*100}%`,top:`${e.gy/o*100}%`,width:`${e.gw/aL.PO_GRID_COLS*100}%`,height:`${e.gh/o*100}%`}},e.id),i[5]=o,i[6]=e):e=i[6],n=r.map(e),i[2]=o,i[3]=r,i[4]=n}else n=i[4];return i[7]!==n?(l=(0,t.jsx)("div",{className:"tpPreview","aria-hidden":!0,children:n}),i[7]=n,i[8]=l):l=i[8],l}function sQ(e){return e.gy+e.gh}function s0(e){let s,n,l,i,o,d,c,u,m,h,p,g,f,x,b,v,j,y,w,k,N,C,S,_,T,E,A,R,D,M,I,O,P,L=(0,a.c)(78),{currentWidgets:F,onApply:$,onReset:B}=e,{t:H}=(0,Z.useTranslation)("paletteOs"),{user:z}=(0,eo.useAuth)();L[0]===Symbol.for("react.memo_cache_sentinel")?(s=[],L[0]=s):s=L[0];let[U,G]=(0,r.useState)(s),[W,K]=(0,r.useState)(""),[V,Y]=(0,r.useState)(!1);L[1]!==z?(n=e=>!z?.id||e.user_id===z.id,L[1]=z,L[2]=n):n=L[2];let q=U.filter(n);L[3]!==z?(l=e=>!!z?.id&&e.user_id!==z.id,L[3]=z,L[4]=l):l=L[4];let J=U.filter(l);L[5]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{(0,tA.apiFetch)("/api/v1/dashboard/templates").then(s4).then(e=>G(e.filter(s3))).catch(s2)},L[5]=i):i=L[5];let X=i;L[6]===Symbol.for("react.memo_cache_sentinel")?(o=[],L[6]=o):o=L[6],(0,r.useEffect)(X,o),L[7]===Symbol.for("react.memo_cache_sentinel")?(d=async e=>{try{await (0,tA.apiFetch)(`/api/v1/dashboard/templates/${e.id}/share`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({shared:!e.shared})}),G(t=>t.map(t=>t.id===e.id?{...t,shared:!e.shared}:t))}catch{}},L[7]=d):d=L[7];let Q=d;L[8]!==F||L[9]!==W?(c=async()=>{let e=W.trim();if(e)try{await (0,tA.apiFetch)("/api/v1/dashboard/templates",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,config:{widgets:[],po:{version:1,widgets:F}}})}),K(""),Y(!0),window.setTimeout(()=>Y(!1),1600),X()}catch{}},L[8]=F,L[9]=W,L[10]=c):c=L[10];let ee=c;L[11]===Symbol.for("react.memo_cache_sentinel")?(u=async e=>{try{await (0,tA.apiFetch)(`/api/v1/dashboard/templates/${e}`,{method:"DELETE"}),G(t=>t.filter(t=>t.id!==e))}catch{}},L[11]=u):u=L[11];let et=u;L[12]!==H?(m=H("dashTemplates.title","TEMPLATES"),L[12]=H,L[13]=m):m=L[13],L[14]!==m?(h=(0,t.jsx)("div",{className:"gcTitle",children:m}),L[14]=m,L[15]=h):h=L[15],L[16]!==H?(p=H("dashTemplates.builtins","BUILT-IN"),L[16]=H,L[17]=p):p=L[17],L[18]!==p?(g=(0,t.jsx)("label",{children:p}),L[18]=p,L[19]=g):g=L[19],L[20]!==$||L[21]!==H?(f=aG.map(e=>{let a=aZ(e),s=a.filter(s1).length;return(0,t.jsxs)("button",{className:"tpRow",onClick:()=>$(aZ(e),H(`dashTemplates.names.${e}`,e.toUpperCase())),children:[(0,t.jsx)(sZ,{widgets:a}),(0,t.jsxs)("span",{className:"tpMeta",children:[(0,t.jsx)("b",{children:H(`dashTemplates.names.${e}`,e.toUpperCase())}),(0,t.jsxs)("small",{children:[H(`dashTemplates.descs.${e}`,""),s?` \xb7 ${H("dashTemplates.connectTag","{{count}} CONNECT SLOTS",{count:s})}`:""]})]})]},e)}),L[20]=$,L[21]=H,L[22]=f):f=L[22],L[23]!==f?(x=(0,t.jsx)("div",{className:"tpList",children:f}),L[23]=f,L[24]=x):x=L[24],L[25]!==g||L[26]!==x?(b=(0,t.jsxs)("div",{className:"gcField",children:[g,x]}),L[25]=g,L[26]=x,L[27]=b):b=L[27],L[28]!==H?(v=H("dashTemplates.mine","MY TEMPLATES"),L[28]=H,L[29]=v):v=L[29],L[30]!==v?(j=(0,t.jsx)("label",{children:v}),L[30]=v,L[31]=j):j=L[31];let ea=0===q.length&&(0,t.jsx)("div",{className:"dbEmpty",children:H("dashTemplates.mineEmpty","NONE SAVED YET")});L[32]!==$||L[33]!==H?(y=e=>(0,t.jsxs)("div",{className:"tpRow tpMine",children:[(0,t.jsxs)("button",{className:"tpApply",onClick:()=>$(e.config.po.widgets,e.name),children:[(0,t.jsx)(sZ,{widgets:e.config.po.widgets}),(0,t.jsxs)("span",{className:"tpMeta",children:[(0,t.jsxs)("b",{children:[e.name,e.shared?` \xb7 ${H("dashTemplates.sharedTag","SHARED")}`:""]}),e.description?(0,t.jsx)("small",{children:e.description}):null]})]}),(0,t.jsx)("button",{className:"tpDelete",onClick:()=>Q(e),"aria-label":e.shared?H("dashTemplates.unshare","UNSHARE FROM ORG"):H("dashTemplates.share","SHARE TO ORG"),title:e.shared?H("dashTemplates.unshare","UNSHARE FROM ORG"):H("dashTemplates.share","SHARE TO ORG"),children:e.shared?"â":"â
"}),(0,t.jsx)("button",{className:"tpDelete",onClick:()=>et(e.id),"aria-label":H("dashTemplates.delete","DELETE"),children:"â"})]},e.id),L[32]=$,L[33]=H,L[34]=y):y=L[34];let es=q.map(y);
31L[35]!==es?(w=(0,t.jsx)("div",{className:"tpList",children:es}),L[35]=es,L[36]=w):w=L[36],L[37]!==j||L[38]!==ea||L[39]!==w?(k=(0,t.jsxs)("div",{className:"gcField",children:[j,ea,w]}),L[37]=j,L[38]=ea,L[39]=w,L[40]=k):k=L[40];let en=J.length>0&&(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:H("dashTemplates.org","SHARED IN YOUR WORKSPACE")}),(0,t.jsx)("div",{className:"tpList",children:J.map(e=>(0,t.jsx)("div",{className:"tpRow tpMine",children:(0,t.jsxs)("button",{className:"tpApply",onClick:()=>$(e.config.po.widgets,e.name),children:[(0,t.jsx)(sZ,{widgets:e.config.po.widgets}),(0,t.jsxs)("span",{className:"tpMeta",children:[(0,t.jsx)("b",{children:e.name}),e.description?(0,t.jsx)("small",{children:e.description}):null]})]})},e.id))})]});L[41]!==H?(N=H("dashTemplates.saveAs","SAVE CURRENT AS TEMPLATE"),L[41]=H,L[42]=N):N=L[42],L[43]!==N?(C=(0,t.jsx)("label",{children:N}),L[43]=N,L[44]=C):C=L[44],L[45]===Symbol.for("react.memo_cache_sentinel")?(S=e=>K(e.target.value),L[45]=S):S=L[45],L[46]!==H?(_=H("dashTemplates.namePlaceholder","TEMPLATE NAME"),L[46]=H,L[47]=_):_=L[47],L[48]!==W||L[49]!==_?(T=(0,t.jsx)("input",{value:W,onChange:S,placeholder:_}),L[48]=W,L[49]=_,L[50]=T):T=L[50],L[51]!==W?(E=W.trim(),L[51]=W,L[52]=E):E=L[52];let el=!E;return L[53]!==V||L[54]!==H?(A=V?H("dashTemplates.saved","SAVED"):H("dashTemplates.save","SAVE"),L[53]=V,L[54]=H,L[55]=A):A=L[55],L[56]!==ee||L[57]!==el||L[58]!==A?(R=(0,t.jsx)("button",{className:"gcDone",onClick:ee,disabled:el,children:A}),L[56]=ee,L[57]=el,L[58]=A,L[59]=R):R=L[59],L[60]!==T||L[61]!==R?(D=(0,t.jsxs)("div",{className:"wcMapRow",children:[T,R]}),L[60]=T,L[61]=R,L[62]=D):D=L[62],L[63]!==C||L[64]!==D?(M=(0,t.jsxs)("div",{className:"gcField",children:[C,D]}),L[63]=C,L[64]=D,L[65]=M):M=L[65],L[66]!==H?(I=H("dashTemplates.reset","RESET TO DEFAULT"),L[66]=H,L[67]=I):I=L[67],L[68]!==B||L[69]!==I?(O=(0,t.jsx)("div",{className:"gcFoot",children:(0,t.jsx)("button",{className:"gcDelete",onClick:B,children:I})}),L[68]=B,L[69]=I,L[70]=O):O=L[70],L[71]!==h||L[72]!==b||L[73]!==k||L[74]!==en||L[75]!==M||L[76]!==O?(P=(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[h,b,k,en,M,O]}),L[71]=h,L[72]=b,L[73]=k,L[74]=en,L[75]=M,L[76]=O,L[77]=P):P=L[77],P}function s1(e){return"data"===e.type&&!e.config.binding}function s2(){}function s3(e){return e.config?.po?.widgets?.length}function s4(e){return e.json()}let s5=new Map;function s6({tabId:e,tabName:a,getWidgets:s,onApply:n}){let{t:l}=(0,Z.useTranslation)("paletteOs"),[i,o]=(0,r.useState)(()=>s5.get(e)??[]),[d,c]=(0,r.useState)(""),[u,m]=(0,r.useState)(!1),h=(0,r.useRef)(null),p=t=>{s5.set(e,t),o(t)};(0,r.useEffect)(()=>{h.current?.scrollIntoView({block:"end"})},[i,u]);let g=async()=>{let e=d.trim();if(!e||u)return;let t=[...i,{role:"user",content:e}];p(t),c(""),m(!0);let r="",o=0,h=e=>p([...t,{role:"assistant",content:r,streaming:e,...o?{applied:o}:{}}]);try{let e=await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/agent/stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:t.slice(-12).map(({role:e,content:t})=>({role:e,content:t})),widgets:s(),tab_name:a})});if(!e.ok||!e.body)throw Error(String(e.status));let i=e.body.getReader(),d=new TextDecoder,c="";for(;;){let{value:e,done:t}=await i.read();if(t)break;let a=(c+=d.decode(e,{stream:!0})).split("\n\n");for(let e of(c=a.pop()??"",a)){let t=e.split("\n").find(e=>e.startsWith("data: "));if(!t)continue;let a=JSON.parse(t.slice(6));if("delta"===a.type&&a.text)r+=a.text,h(!0);else if("done"===a.type){let e=Array.isArray(a.actions)?a.actions:[];o=e.length?n(e):0}else"error"===a.type&&(r=a.message??l("dashboard.agent.failed","The agent could not process that â try again."),h(!0))}}r.trim()||(r=l("dashboard.agent.failed","The agent could not process that â try again.")),h(!1)}catch{r=r.trim()||l("dashboard.agent.failed","The agent could not process that â try again."),h(!1)}finally{m(!1)}};return(0,t.jsxs)("div",{className:"gcWrap wcScroll agWrap",children:[(0,t.jsx)("div",{className:"gcTitle",children:l("dashboard.agent.title","BOARD AGENT")}),(0,t.jsx)("div",{className:"agBoardName",children:a}),(0,t.jsxs)("div",{className:"agMsgs",children:[0===i.length&&(0,t.jsxs)("div",{className:"agHint",children:[l("dashboard.agent.hint","Ask for changes to this dashboard â add, update, resize, or remove widgets."),
31(0,t.jsx)("span",{children:l("dashboard.agent.example1","âSet this up as an HR dashboardâ")}),(0,t.jsx)("span",{children:l("dashboard.agent.example2","âAdd a donut of AI spend by modelâ")}),(0,t.jsx)("span",{children:l("dashboard.agent.example3","âMake the task widget wider and call it WORKLOADâ")})]}),i.map((e,a)=>(0,t.jsxs)("div",{className:`agMsg ${"user"===e.role?"agUser":"agAi"}${e.streaming?" agStreaming":""}`,children:[e.content,"assistant"===e.role&&!e.streaming&&!!e.applied&&(0,t.jsx)("span",{className:"agApplied",children:l("dashboard.agent.applied","{{count}} CHANGES APPLIED",{count:e.applied})})]},a)),u&&i.at(-1)?.role==="user"&&(0,t.jsx)("div",{className:"agMsg agAi",children:l("dashboard.agent.thinking","THINKINGâ¦")}),(0,t.jsx)("div",{ref:h})]}),(0,t.jsx)("div",{className:"gcFoot agFoot",children:(0,t.jsxs)("div",{className:"wcAiRow",children:[(0,t.jsx)("input",{value:d,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key&&g()},placeholder:l("dashboard.agent.placeholder","e.g. add a gauge of open tasks"),disabled:u,autoFocus:!0}),(0,t.jsx)("button",{className:"gcDone",onClick:()=>void g(),disabled:u||!d.trim(),children:l("dashboard.agent.send","SEND")})]})})]})}var s7=e.i(122764),s8=e.i(625227);function s9({open:e,onClose:a,onEmpty:s,onTemplate:n,onBuild:l}){let{t:i}=(0,Z.useTranslation)("paletteOs"),[o,d]=(0,r.useState)("start"),[c,u]=(0,r.useState)(""),[m,h]=(0,r.useState)(null),[p,g]=(0,r.useState)(null),[f,x]=(0,r.useState)(null),[b,v]=(0,r.useState)({skip:!0}),[j,y]=(0,r.useState)(!0),[w,k]=(0,r.useState)("executive"),[N,C]=(0,r.useState)("mixed"),[S,_]=(0,r.useState)(""),[T,E]=(0,r.useState)(!1),[A,R]=(0,r.useState)(null),[D,M]=(0,r.useState)([]),I=(0,r.useRef)(null),O=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!e)return;let t=document.activeElement;return d("start"),g(null),h(null),x(null),u(""),O.current?.focus(),()=>t?.focus?.()},[e]),(0,r.useEffect)(()=>{"template"!==o||D.length||(0,tA.apiFetch)("/api/v1/dashboard/templates").then(e=>e.json()).then(e=>M(e.filter(e=>e.config?.po?.widgets?.length))).catch(()=>void 0)},[o]);let P=async e=>{let t=await e.json().catch(()=>({}));if(!e.ok||t?.error)throw Error(t?.detail??t?.error??"request failed");return t},L=async e=>{h(i("dashboard.newBoard.reviewing","PROFILING DATAâ¦"));let t=await P(await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/auto-board/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_id:e})}));x(t.dataset),v(t.preparation??{skip:!0}),y(!0),d("review"),h(null)},F=async(e,t)=>{h(i("dashboard.newBoard.uploading","UPLOADINGâ¦")),g(null);try{let a=new FormData;a.append("file",e),t?.sheet&&a.append("sheet",t.sheet),t?.headerRow&&a.append("header_row",String(t.headerRow));let s=await P(await (0,tA.apiFetch)("/api/v1/datasets/upload",{method:"POST",body:a}));await L(s.id)}catch(e){g(e instanceof Error?e.message:"upload failed"),h(null)}},$=async()=>{if(c.trim()){h(i("dashboard.newBoard.importing","IMPORTING LINKâ¦")),g(null);try{let e=await P(await (0,tA.apiFetch)("/api/v1/datasets/from-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:c.trim()})}));await L(e.id)}catch(e){g(e instanceof Error?e.message:"import failed"),h(null)}}},B=(0,r.useRef)(null),[H,z]=(0,r.useState)(!1),U={profiling:i("dashboard.newBoard.phaseProfiling","PROFILING DATAâ¦"),preparing:i("dashboard.newBoard.phasePreparing","CLEANING DATAâ¦"),designing:i("dashboard.newBoard.phaseDesigning","DESIGNING WIDGETSâ¦"),building:i("dashboard.newBoard.phaseBuilding","BUILDING THE BOARDâ¦")},G=async()=>{if(!f)return;let e=new AbortController;B.current=e,z(!0),h(i("dashboard.newBoard.building","ANALYSING DATA â BUILDING BOARDâ¦")),g(null);let t=await l(f.id,{intent:w,audience:N,goal:S.trim(),preparation:j?b:{skip:!0}},{signal:e.signal,onPhase:e=>h(U[e]??e.toUpperCase())});B.current=null,z(!1),t?(g(t),h(null)):e.signal.aborted&&h(null)};if(!e)return null;let W=Array.isArray(b.changes)?b.changes.map(String):[],K=aG.length+D.length,V=[{key:"empty",glyph:"â¡",name:i("dashboard.newBoard.empty","EMPTY BOARD"),desc:i("dashboard.newBoard.emptyDesc","A blank grid â add widgets yourself."),tag:i("dashboard.newBoard.tagInstant","INSTANT")},{key:"template",glyph:"â¤",name:i("dashboard.newBoard.template","FROM A TEMPLATE"),desc:i("dashboard.newBoard.templateDesc","Start from a ready-made layout."),tag:i("dashboard.newBoard.tagCount","{{count}} READY",{count:K})},{key:"upload",glyph:"â",name:i("dashboard.newBoard.upload","UPLOAD A FILE"),desc:i("dashboard.newBoard.uploadDesc","CSV · XLSX · JSON · Parquet â AI builds the board."),tag:i("dashboard.newBoard.tagAi","AI BUILT")},{key:"dataRoom",glyph:"â£",name:i("dashboard.newBoard.dataRoom","FROM DRIVE"),desc:i("dashboard.newBoard.dataRoomDesc","Pick a file already stored in your drives."),tag:i("dashboard.newBoard.tagAi","AI BUILT")},{key:"link",glyph:"â¯",name:i("dashboard.newBoard.link","FROM A LINK"),desc:i("dashboard.newBoard.linkDesc","A shared CSV, XLSX or Google Sheet."),tag:i("dashboard.newBoard.tagAi","AI BUILT")}],Y={start:i("dashboard.newBoard.subStart","{{count}} WAYS TO START",{count:V.length}),template:i("dashboard.newBoard.subTemplate","PICK A LAYOUT"),link:i("dashboard.newBoard.subLink","PASTE A SHARED LINK"),review:i("dashboard.newBoard.subReview","STEP 2 / 3 â REVIEW THE DATA"),intent:i("dashboard.newBoard.subIntent","STEP 3 / 3 â WHAT IS IT FOR")};return(0,ev.createPortal)((0,t.jsxs)("div",{"data-theme":"palette-os","data-canvas":document.documentElement.getAttribute("data-canvas")??void 0,className:"dbNb",role:"presentation",children:[(0,t.jsx)("div",{className:"dbNbScrim",onClick:m?void 0:a}),(0,t.jsxs)("div",{ref:O,className:"dbNbCard",role:"dialog","aria-modal":"true","aria-labelledby":"db-nb-title",tabIndex:-1,onKeyDown:e=>{"Escape"!==e.key||m||(e.stopPropagation(),"start"===o?a():d("start"))},children:[(0,t.jsxs)("div",{className:"dbNbHead",children:["start"!==o&&(0,t.jsx)("button",{className:"dbNbBack",onClick:()=>d("intent"===o?"review":"start"),"aria-label":i("common.back","BACK"),children:"â¹"}),(0,t.jsx)("span",{id:"db-nb-title",children:i("dashboard.newBoard.title","NEW DASHBOARD")}),(0,t.jsx)("span",{className:"dbNbSub",children:Y[o]}),(0,t.jsx)("button",{className:"dbNbClose",onClick:a,"aria-label":i("dashboard.newBoard.close","CLOSE"),children:"â"})]}),(0,t.jsxs)("div",{className:"dbNbBody",children:["start"===o&&V.map(e=>(0,t.jsxs)("button",{className:"dbNbRow",disabled:!!m,onClick:()=>{var t;return t=e.key,void((g(null),"empty"===t)?s():"upload"===t?I.current?.click():"dataRoom"===t?E(!0):d(t))},children:[(0,t.jsx)("span",{className:"dbNbGlyph","aria-hidden":!0,
31children:e.glyph}),(0,t.jsxs)("span",{className:"dbNbText",children:[(0,t.jsx)("b",{children:e.name}),(0,t.jsx)("small",{children:e.desc})]}),(0,t.jsx)("span",{className:"dbNbTag",children:e.tag})]},e.key)),"template"===o&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"dbNbSection",children:i("dashTemplates.builtins","BUILT-IN")}),(0,t.jsx)("div",{className:"dbNbTpl",children:aG.map(e=>{let a=aZ(e),s=a.filter(e=>"data"===e.type&&!e.config.binding).length,l=i(`dashTemplates.names.${e}`,e.toUpperCase());return(0,t.jsxs)("button",{className:"tpRow",onClick:()=>n(aZ(e),l),children:[(0,t.jsx)(sZ,{widgets:a}),(0,t.jsxs)("span",{className:"tpMeta",children:[(0,t.jsx)("b",{children:l}),(0,t.jsxs)("small",{children:[i(`dashTemplates.descs.${e}`,""),s?` \xb7 ${i("dashTemplates.connectTag","{{count}} CONNECT SLOTS",{count:s})}`:""]})]})]},e)})}),(0,t.jsx)("div",{className:"dbNbSection",children:i("dashTemplates.mine","MY TEMPLATES")}),D.length?(0,t.jsx)("div",{className:"dbNbTpl",children:D.map(e=>(0,t.jsxs)("button",{className:"tpRow",onClick:()=>n(e.config.po.widgets,e.name),children:[(0,t.jsx)(sZ,{widgets:e.config.po.widgets}),(0,t.jsxs)("span",{className:"tpMeta",children:[(0,t.jsx)("b",{children:e.name}),e.description?(0,t.jsx)("small",{children:e.description}):null]})]},e.id))}):(0,t.jsx)("div",{className:"dbEmpty",children:i("dashTemplates.mineEmpty","NONE SAVED YET")})]}),"link"===o&&(0,t.jsxs)("div",{className:"dbNbPane",children:[(0,t.jsx)("label",{htmlFor:"db-nb-url",children:i("dashboard.newBoard.linkLabel","SHARED LINK â CSV / XLSX / GOOGLE SHEETS")}),(0,t.jsx)("input",{id:"db-nb-url",autoFocus:!0,value:c,onChange:e=>u(e.target.value),placeholder:"https://docs.google.com/spreadsheets/d/â¦",onKeyDown:e=>{"Enter"===e.key&&$()}}),(0,t.jsx)("span",{className:"dbNbHint",children:i("dashboard.newBoard.linkHint","The link must be readable without signing in.")}),(0,t.jsx)("button",{className:"dbNbPrimary",disabled:!!m||!c.trim(),onClick:()=>void $(),children:i("dashboard.newBoard.import","IMPORT LINK")})]}),"review"===o&&f&&(0,t.jsxs)("div",{className:"dbNbPane",children:[(0,t.jsx)("label",{children:i("dashboard.newBoard.detected","DETECTED DATA")}),(0,t.jsx)("strong",{children:f.name}),(0,t.jsxs)("span",{className:"dbEmpty",children:[f.row_count.toLocaleString()," ROWS · ",f.columns.length," COLUMNS · ",f.source_type.toUpperCase()]}),(0,t.jsx)("div",{className:"wcChips",children:f.columns.slice(0,12).map(e=>(0,t.jsxs)("span",{className:"wcChip on",children:[e.display_name||e.name," · ",e.semantic_type||e.role]},e.name))}),!!f.sample_rows?.rows?.length&&(0,t.jsx)("div",{className:"wcDataPreview",tabIndex:0,"aria-label":i("dashboard.newBoard.sample","Data sample"),children:(0,t.jsxs)("table",{children:[(0,t.jsx)("thead",{children:(0,t.jsx)("tr",{children:f.sample_rows.columns.slice(0,6).map(e=>(0,t.jsx)("th",{scope:"col",children:e},e))})}),(0,t.jsx)("tbody",{children:f.sample_rows.rows.slice(0,4).map((e,a)=>(0,t.jsx)("tr",{children:e.slice(0,6).map((e,a)=>(0,t.jsx)("td",{children:String(e??"â")},a))},a))})]})}),(0,t.jsx)("label",{children:i("dashboard.newBoard.preparation","PROPOSED PREPARATION")}),W.length?(0,t.jsx)("ul",{className:"wcPrepList",children:W.map(e=>(0,t.jsx)("li",{children:e},e))}):(0,t.jsx)("span",{className:"dbEmpty",children:i("dashboard.newBoard.noPrep","NO DATA CHANGES NEEDED")}),!!W.length&&(0,t.jsxs)("label",{className:"wcCheck",children:[(0,t.jsx)("input",{type:"checkbox",checked:j,onChange:e=>y(e.target.checked)}),i("dashboard.newBoard.approvePrep","Apply these changes before building")]}),(0,t.jsx)("button",{className:"dbNbPrimary",onClick:()=>d("intent"),children:i("dashboard.newBoard.continue","CONTINUE")})]}),"intent"===o&&f&&(0,t.jsxs)("div",{className:"dbNbPane",children:[(0,t.jsx)("label",{children:i("dashboard.newBoard.intent","BOARD INTENT")}),(0,t.jsx)("div",{className:"dbNbSeg",children:["executive","operational","exploratory"].map(e=>(0,t.jsx)("button",{className:w===e?"on":"",onClick:()=>k(e),children:i(`dashboard.newBoard.intents.${e}`,e.toUpperCase())},e))}),(0,t.jsx)("label",{children:i("dashboard.newBoard.audience","AUDIENCE")}),(0,t.jsx)("div",{className:"dbNbSeg",children:["business","mixed","analyst"].map(e=>(0,t.jsx)("button",{className:N===e?"on":"",onClick:()=>C(e),children:i(`dashboard.newBoard.audiences.${e}`,e.toUpperCase())},e))}),(0,t.jsx)("label",{htmlFor:"db-nb-goal",children:i("dashboard.newBoard.goal","OPTIONAL DECISION OR GOAL")}),(0,t.jsx)("textarea",{id:"db-nb-goal",rows:3,maxLength:500,value:S,onChange:e=>_(e.target.value),placeholder:i("dashboard.newBoard.goalPlaceholder","Example: Show where revenue is growing and which regions need attention.")}),(0,t.jsx)("button",{className:"dbNbPrimary",disabled:!!m,onClick:()=>void G(),children:i("dashboard.newBoard.build","BUILD DASHBOARD")})]})]}),(m||p)&&(0,t.jsxs)("div",{className:"dbNbFoot",children:[m&&(0,t.jsx)("span",{className:"dbNbBusy",role:"status","aria-live":"polite",children:m}),p&&(0,t.jsx)("span",{className:"dbNbError",role:"alert",children:p}),H&&(0,t.jsx)("button",{className:"dbNbCancel",onClick:()=>{B.current?.abort(),h(null),z(!1)},children:i("dashboard.newBoard.cancel","CANCEL")})]})]}),(0,t.jsx)("input",{ref:I,type:"file",accept:".csv,.tsv,.txt,.xlsx,.xls,.json,.ndjson,.parquet",hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value="",t&&(/\.xlsx?$/i.test(t.name)?R(t):F(t))}}),(0,t.jsx)(s8.ExcelUploadDialog,{open:null!==A,file:A,onClose:()=>R(null),onConfirm:e=>{R(null),A&&F(A,e)}}),(0,t.jsx)(s7.DataRoomFilePickerDialog,{open:T,onClose:()=>E(!1),onPick:async(e,t)=>{E(!1),h(i("dashboard.newBoard.importing","IMPORTING FILEâ¦")),g(null);try{let a=await P(await (0,tA.apiFetch)("/api/v1/datasets/from-data-room",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data_room_file_id:e,name:t})}));await L(a.id)}catch(e){g(e instanceof Error?e.message:"import failed"),h(null)}}})]}),document.body)}let ne=[{id:"today",label:"TODAY"},{id:"7d",label:"7D"},{id:"30d",label:"30D"}],nt=["â§","â¤","â¦","â£","â¨","$","â"];function na(){var e;return("today"===(e=new URLSearchParams(window.location.search).get("range"))||"7d"===e||"30d"===e?e:null)??"7d"}function ns(e,t){let a=new URL(window.location.href);a.searchParams.set("range",e),t&&a.searchParams.set("tab",t),a.searchParams.delete("theme"),window.history.replaceState(window.history.state,"",`${a.pathname}?${a.searchParams.toString()}${a.hash}`)}function nn({tabName:e,widgets:a}){let{t:s}=(0,Z.useTranslation)("paletteOs"),[n,l]=(0,r.useState)(""),[i,o]=(0,r.useState)(!0),[d,c]=(0,r.useState)(null);return(0,r.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/explain-board/stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tab_name:e,widgets:a})});if(!n.ok||!n.body)throw Error(String(n.status));
31let i=n.body.getReader(),r=new TextDecoder,o="";for(;;){let{value:e,done:a}=await i.read();if(a||t)break;let n=(o+=r.decode(e,{stream:!0})).split("\n\n");for(let e of(o=n.pop()??"",n)){let t=e.split("\n").find(e=>e.startsWith("data: "));if(!t)continue;let a=JSON.parse(t.slice(6));"delta"===a.type&&a.text?l(e=>e+a.text):"error"===a.type&&c(a.message??s("dashboard.summary.failed","Summary failed â try again"))}}}catch{t||c(e=>e??s("dashboard.summary.failed","Summary failed â try again"))}finally{t||o(!1)}})(),()=>{t=!0}},[]),(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[(0,t.jsx)("div",{className:"gcTitle",children:e}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:s("dashboard.summary.title","BOARD SUMMARY")}),i&&!n&&!d&&(0,t.jsx)("span",{className:"dbEmpty",children:s("dashboard.summary.loading","READING THE BOARDâ¦")}),d&&(0,t.jsx)("span",{className:"dbEmpty",children:d}),n&&(0,t.jsx)("div",{className:`wcExplain${i?" agStreaming":""}`,children:n})]})]})}function nl({onAdd:e}){let{t:a}=(0,Z.useTranslation)("paletteOs"),[s,n]=(0,r.useState)(""),[l,i]=(0,r.useState)(!1),[o,d]=(0,r.useState)(null),[c,u]=(0,r.useState)(null),m=async()=>{if(s.trim()&&!l){i(!0),d(null),u(null);try{let e=await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/ask",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:s.trim()})}),t=await e.json();!e.ok||t.error?d(String(t.error??t.detail??a("dashboard.ask.failed","Could not answer that â try rephrasing"))):u(t)}catch{d(a("dashboard.ask.failed","Could not answer that â try rephrasing"))}finally{i(!1)}}},h=c?(0,sh.normalizeColumnar)(c.data):null,p=c?(0,sN.rendererFor)(c.widget.visual):null;return(0,t.jsxs)("div",{className:"gcWrap wcScroll",children:[(0,t.jsx)("div",{className:"gcTitle",children:a("dashboard.ask.title","ASK YOUR DATA")}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{htmlFor:"ask-data-q",children:a("dashboard.ask.label","QUESTION")}),(0,t.jsx)("textarea",{id:"ask-data-q",rows:2,maxLength:500,value:s,onChange:e=>n(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),m())},placeholder:a("dashboard.ask.placeholder","Example: What were the top 5 regions by revenue last month?")}),(0,t.jsx)("button",{className:"gcAction on",disabled:l||!s.trim(),onClick:()=>void m(),children:l?a("dashboard.ask.working","ANALYSINGâ¦"):a("dashboard.ask.button","ASK")})]}),o&&(0,t.jsx)("span",{className:"wcErrorRow",role:"alert",children:o}),c&&h&&p&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:a("dashboard.ask.answer","ANSWER")}),(0,t.jsx)("div",{className:"wcExplain",children:c.answer})]}),(0,t.jsxs)("div",{className:"gcField",children:[(0,t.jsx)("label",{children:c.widget.label}),(0,t.jsx)("div",{className:"wcPreview",children:(0,t.jsx)(p,{data:h,opts:{labelKey:c.widget.labelKey,valueKey:c.widget.valueKey,prefix:c.widget.prefix,suffix:c.widget.suffix,format:c.widget.format}})}),(0,t.jsx)("button",{className:"gcAction on",onClick:()=>e(c.widget),children:a("dashboard.ask.addToBoard","ADD TO BOARD")})]})]})]})}e.s(["DashboardView",0,function(){let{t:a}=(0,Z.useTranslation)("paletteOs"),{urlSync:s,openConfirm:n,openDrawer:l,closeDrawer:i,drawer:o}=(0,ed.useViewContext)(),{tasks:d,loading:c}=function(){let[e,t]=(0,r.useState)([]),[a,s]=(0,r.useState)(!0),[n,l]=(0,r.useState)(null),[i,o]=(0,r.useState)("all"),[d,c]=(0,r.useState)("all"),u=(0,r.useCallback)(async()=>{let e=new URLSearchParams;"all"!==i&&e.set("team_id",String(i)),"all"!==d&&e.set("user_id",d);let a=e.toString();try{t(await (0,aP.readJson)(`/api/v1/tasks/board${a?`?${a}`:""}`)),l(null)}catch(e){l(e instanceof Error?e.message:"Failed to load tasks")}},[i,d]);(0,r.useEffect)(()=>{u().finally(()=>s(!1))},[u]);let m=(0,r.useRef)(u);m.current=u,(0,r.useEffect)(()=>{let e=null,t=(0,aP.subscribeTaskStream)(()=>{e&&clearTimeout(e),e=setTimeout(()=>{m.current()},300)});return()=>{e&&clearTimeout(e),t()}},[]);let h=(0,r.useCallback)(async(e,a)=>{t(t=>t.map(t=>
31t.id===e?{...t,status:a}:t));try{await (0,tA.apiFetch)(`/api/v1/tasks/${e}`,{method:"PATCH",body:JSON.stringify({status:a})})}catch(e){console.error(e),await u()}},[u]),p=(0,r.useCallback)(async e=>{let t=await (0,tA.apiFetch)("/api/v1/tasks",{method:"POST",body:JSON.stringify({title:e,description:"",task_type:"manual"})});if(!t.ok)throw Error((await t.json().catch(()=>({}))).detail??`Failed to create task (${t.status})`);let a=await t.json();return await u(),a},[u]);return{tasks:e,loading:a,error:n,refreshBoard:u,changeStatus:h,createTask:p,teamFilter:i,setTeamFilter:o,memberFilter:d,setMemberFilter:c}}(),{widgets:u,setWidgets:m,loading:h,saving:p,applyTemplate:g,resetToDefault:f,tabs:x,activeTabId:b,defaultTabId:v,setActiveTab:j,addTab:y,renameTab:w,removeTab:k,reorderTabs:N,setDefaultTab:C,setTabDigest:S,flush:_,reload:T,saveError:E,retrySave:A,undo:R,redo:D,canUndo:M,canRedo:I}=function(){let[e,t]=(0,r.useState)(null),[a,s]=(0,r.useState)(""),[n,l]=(0,r.useState)(!0),[i,o]=(0,r.useState)(!1),[d,c]=(0,r.useState)(null),[u,m]=(0,r.useState)(0),h=(0,r.useRef)({}),p=(0,r.useRef)(null),g=(0,r.useRef)("");g.current=a;let f=(0,r.useRef)(null),x=(0,r.useRef)(!1),b=(0,r.useRef)([]),v=(0,r.useRef)([]);(0,r.useEffect)(()=>{let e=!1;return(async()=>{try{let a=await (0,tA.apiFetch)("/api/v1/dashboard"),n=await a.json(),l=n?.config??{};if(e)return;h.current=l;let i=(0,aL.normalizePoConfig)(l.po);if(i){let e=aQ(i);p.current=e,t(e),s(e.defaultTabId??e.tabs[0].id)}else{let e=aZ(aU),a={version:2,tabs:[{id:(0,aL.newWidgetId)("tab"),name:"DASHBOARD 1",widgets:e}]};p.current=a,t(a),s(a.tabs[0].id),j()}}catch{}finally{e||l(!1)}})(),()=>{e=!0}},[]);let j=(0,r.useCallback)(async()=>{if(!p.current)return!0;o(!0),c(null);try{let e=p.current,t={...h.current,po:e},a=await (0,tA.apiFetch)("/api/v1/dashboard",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:t})});if(!a.ok)throw Error((await a.json().catch(()=>({})))?.detail??`save failed (${a.status})`);return h.current=t,x.current=p.current!==e,!0}catch(e){return x.current=!0,c(e instanceof Error?e.message:"save failed"),!1}finally{o(!1)}},[]),y=(0,r.useCallback)(()=>{x.current=!0,f.current&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{j()},800)},[j]);(0,r.useEffect)(()=>()=>{f.current&&window.clearTimeout(f.current),x.current&&j()},[j]);let w=(0,r.useCallback)((e,a=!1)=>{if(!p.current)return;let s=p.current,n=e(s);n!==s&&(b.current=[...b.current.slice(-29),s],v.current=[],m(e=>e+1),p.current=n,t(n),a?j():y())},[j,y]),k=(0,r.useCallback)(e=>{if(!p.current)return;let a="undo"===e?b:v,s="undo"===e?v:b,n=a.current.at(-1);n&&(a.current=a.current.slice(0,-1),s.current=[...s.current.slice(-29),p.current],p.current=n,t(n),m(e=>e+1),y())},[y]),N=(0,r.useCallback)((e,t=!1)=>{w(t=>{let a=t.tabs.some(e=>e.id===g.current)?g.current:t.tabs[0]?.id;return{...t,tabs:t.tabs.map(t=>t.id===a?{...t,widgets:e(t.widgets)}:t)}},t)},[w]),C=(0,r.useCallback)(e=>{N(e)},[N]),S=(0,r.useCallback)(e=>{N(()=>e,!0)},[N]),_=(0,r.useCallback)(()=>{S(aZ(aU))},[S]),T=(0,r.useCallback)(async()=>{if(f.current&&window.clearTimeout(f.current),x.current&&!await j())throw Error(tE.default.t("paletteOs:dashboard.saveBeforeBuild","Save the current board before building a new one"))},[j]),E=(0,r.useCallback)(async e=>{f.current&&window.clearTimeout(f.current),x.current=!1;let a=await (0,tA.apiFetch)("/api/v1/dashboard"),n=await a.json(),l=n?.config??{};h.current=l;let i=(0,aL.normalizePoConfig)(l.po);if(i){let a=aQ(i);p.current=a,t(a),b.current=[],v.current=[],m(e=>e+1),e&&i.tabs.some(t=>t.id===e)&&s(e)}},[]),A=(0,r.useCallback)((e,t=[])=>{let a=(0,aL.newWidgetId)("tab");w(s=>({...s,tabs:[...s.tabs,{id:a,name:e.trim()||`DASHBOARD ${s.tabs.length+1}`,widgets:t}]})),s(a)},[w]),R=(0,r.useCallback)((e,t)=>{let a=t.trim();a&&w(t=>({...t,tabs:t.tabs.map(t=>t.id===e?{...t,name:a}:t)}))},[w]),D=(0,r.useCallback)(e=>{w(t=>{if(t.tabs.length<=1)return t;let a=t.tabs.findIndex(t=>t.id===e);if(a<0)return t;let n=t.tabs.filter(t=>t.id!==e);g.current===e&&s(n[Math.min(a,n.length-1)].id);let l={...t,tabs:n};return l.defaultTabId===e&&delete l.defaultTabId,l})},[w]),M=(0,r.useCallback)((e,t)=>{w(a=>{let s=[...a.tabs],[n]=s.splice(e,1);return n?(s.splice(t,0,n),{...a,tabs:s}):a})},[w]),I=(0,r.useCallback)(e=>{w(t=>({...t,defaultTabId:e}))},[w]),O=(0,r.useCallback)((e,t)=>{w(a=>({...a,tabs:a.tabs.map(a=>a.id===e?{...a,digest:t||void 0}:a)}),!0)},[w]),P=e?.tabs??[],L=P.find(e=>e.id===a)??P[0];return{widgets:L?.widgets??[],setWidgets:C,loading:n,saving:i,saveError:d,retrySave:j,undo:()=>k("undo"),redo:()=>k("redo"),canUndo:u>=0&&b.current.length>0,canRedo:u>=0&&v.current.length>0,applyTemplate:S,resetToDefault:_,tabs:P,activeTabId:L?.id??"",defaultTabId:e?.defaultTabId??P[0]?.id??"",setActiveTab:s,addTab:A,renameTab:R,removeTab:D,reorderTabs:M,setDefaultTab:I,setTabDigest:O,flush:T,reload:E}}(),O=(0,a0.useOsDark)(),[P,L]=(0,r.useState)(na),[F,$]=(0,r.useState)(!1),[B,H]=(0,r.useState)(aL.PO_GRI
31D_COLS),[z,U]=(0,r.useState)(null),[G,W]=(0,r.useState)(null),[K,V]=(0,r.useState)(null),[Y,q]=(0,r.useState)(null),[J,X]=(0,r.useState)(null),[Q,ee]=(0,r.useState)(!1),et=(0,r.useRef)(null),ea=(0,r.useRef)(null),es=(0,r.useRef)(null),en=(0,r.useRef)(u);en.current=u;let el=(0,r.useRef)(new URLSearchParams(window.location.search).get("tab")),[ei,er]=(0,r.useState)(!1);(0,r.useEffect)(()=>{if(h)return;let e=el.current;el.current=null,e&&(x.some(t=>t.id===e)?j(e):(er(!0),window.setTimeout(()=>er(!1),8e3)))},[h,x,j]),(0,r.useEffect)(()=>{s&&!h&&b&&ns(P,b)},[b,s,h]),(0,r.useEffect)(()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey)||"z"!==e.key.toLowerCase())return;let t=e.target;t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName||t.isContentEditable)||(e.preventDefault(),e.shiftKey?D():R())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[R,D]),(0,r.useEffect)(()=>{let e=ea.current;if(!e)return;let t=e=>H(e>=1e3?aL.PO_GRID_COLS:e>=620?6:1);t(e.clientWidth);let a=new ResizeObserver(a=>t(a[0]?.contentRect.width??e.clientWidth));return a.observe(e),()=>a.disconnect()},[h]),(0,r.useEffect)(()=>{q(null)},[b]);let eo=(0,r.useMemo)(()=>B===aL.PO_GRID_COLS?u:function(e,t){if(t>=aL.PO_GRID_COLS)return e;let a=[...e].sort((e,t)=>e.gy-t.gy||e.gx-t.gx),s=[];for(let e of a){let a=Math.min(e.gw,t),n={gx:0,gy:0},l=!1,i=s.reduce((e,t)=>Math.max(e,t.gy+t.gh),0);for(let r=0;r<=i&&!l;r++)for(let i=0;i<=t-a&&!l;i++)0===aF(s,{gx:i,gy:r,gw:a,gh:e.gh}).length&&(n={gx:i,gy:r},l=!0);l||(n={gx:0,gy:i}),s.push({...e,gx:n.gx,gy:n.gy,gw:a})}return s}(u,B),[u,B]),ec=(0,r.useCallback)(()=>{let e=ea.current;return e?(e.clientWidth-40*(aL.PO_GRID_COLS-1))/aL.PO_GRID_COLS+40:80},[]),em=(0,r.useCallback)((e,t,a)=>{m(s=>az(s.map(s=>s.id===e?{...s,...t,config:a?{...s.config,...a}:s.config}:s)))},[m]),eh=(0,r.useCallback)((e,t)=>{m(a=>a.map(a=>a.id===e?{...a,config:{...a.config,...t}}:a))},[m]),ep=(0,r.useCallback)((e,t)=>{m(a=>{let s=[...a].sort((e,t)=>e.gy-t.gy||e.gx-t.gx),n=s.findIndex(t=>t.id===e),l=n+t;if(n<0||l<0||l>=s.length)return a;[s[n],s[l]]=[s[l],s[n]];let i=[];for(let e of s){let t=aB(i,e.gw,e.gh);i=[...i,{...e,gx:t.gx,gy:t.gy}]}return i})},[m]),[eg,ef]=(0,r.useState)(null),[ex,eb]=(0,r.useState)(""),[ev,ej]=(0,r.useState)([]),[ey,ew]=(0,r.useState)({});(0,r.useEffect)(()=>{ef(null),eb(""),ej([])},[b]);let ek=(0,r.useMemo)(()=>{let e=new Set;for(let t of u){let a=t.config.binding;a?.kind==="dataset"&&a.dataset_id&&e.add(a.dataset_id)}return[...e]},[u]);(0,r.useEffect)(()=>{for(let e of ek)ey[e]||(0,tA.apiFetch)(`/api/v1/datasets/${e}`).then(e=>e.json()).then(t=>{let a=(t?.schema_json?.columns??[]).filter(e=>"dimension"===e.role).map(e=>e.name);ew(t=>({...t,[e]:a}))}).catch(()=>ew(t=>({...t,[e]:[]})))},[ek]);let eN=(0,r.useMemo)(()=>[...new Set(ek.flatMap(e=>ey[e]??[]))].sort(),[ek,ey]),eC=(0,r.useCallback)(async e=>{if(eb(e),ef(null),ej([]),!e)return;let t=ek.find(t=>(ey[t]??[]).includes(e));if(t)try{let a=await (0,tA.apiFetch)("/api/v1/insights-dashboards/data/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:"dataset",dataset_id:t,dimensions:[e],limit:50})}),s=await a.json(),n=Array.isArray(s?.rows)?s.rows:[];ej(n.map(e=>String(e[0]??"")).filter(Boolean).slice(0,50))}catch{}},[ek,ey]),eS=(0,r.useCallback)(e=>{let t=en.current.find(t=>t.id===e);n({title:a("dashboard.removeWidget","REMOVE WIDGET"),desc:a("dashboard.removeWidgetDesc",'"{{name}}" is removed from the board. Templates can restore defaults.',{name:t?.label||sI[t?.type??"data"].label}),onConfirm:()=>m(t=>az(t.filter(t=>t.id!==e)))})},[n,m,a]),e_=(0,r.useCallback)(e=>{let t=x.find(t=>t.id===e);n({title:a("dashboard.tabs.delete","DELETE DASHBOARD"),desc:a("dashboard.tabs.deleteDesc",'"{{name}}" and its widgets are removed.',{name:t?.name??""}),onConfirm:()=>k(e)})},[n,k,a,x]),eT=(0,r.useCallback)(async(e,t)=>{try{await _();let a=await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tab_id:e,enable:t})}),s=await a.json().catch(()=>({}));t&&s?.token&&await navigator.clipboard.writeText(`${window.location.origin}/board/${s.token}`).catch(()=>void 0),await T(e)}catch{}},[_,T]),eE=(0,r.useCallback)((e,t,s)=>{e.preventDefault(),e.stopPropagation();let n=x.find(e=>e.id===t);X({x:e.clientX,y:e.clientY,head:(n?.name??"").toUpperCase(),sections:[[{label:a("dashboard.rail.view","View this dashboard"),disabled:t===b,on:()=>j(t)},{label:a("dashboard.rail.rename","Rename"),on:()=>V(t)}],[{label:a("dashboard.rail.moveLeft","Move left"),disabled:0===s,on:()=>N(s,s-1)},{label:a("dashboard.rail.moveRight","Move right"),disabled:s===x.length-1,on:()=>N(s,s+1)}],[{label:a("dashboard.rail.setDefault","Set as default"),disabled:t===v,on:()=>C(t)},{label:n?.digest?a("dashboard.rail.digestOff","Weekly digest â â turn off"):a("dashboard.rail.digestOn","Weekly digest"),on:()=>S(t,!n?.digest)},...n?.shareToken?[{label:a("dashboard.rail.copyLink","Copy public link"),on:()=>{navigator.clipboard.writeText(`${window.location.origin}/board/${n.shareToken}`).catch(()=>void 0)}},{label:a("dashboard.rail.revokeLink","Revoke public link"),danger:!0,on:()=>void eT(t,!1)}]:[{label:a("dashboard.rail.publicLink","Public link (copies URL)"),on:()=>void eT(t,!0)}],{label:a("dashboard.rail.delete","Delete dashboard"),danger:!0,disabled:x.length<=1,on:()=>e_(t)}]]})},[x,b,v,j,N,C,S,eT,e_,a]),eA=(0,r.useCallback)(e=>{l({inverted:O,tag:a("widgetConfig.tag","WIDGET"),content:(0,t.jsx)(sJ,{widget:e,onSave:(t,a)=>{em(e.id,t,a),i()},onRemove:()=>{i(),eS(e.id)}})})},[l,i,O,em,eS,a]),eR=(0,r.useCallback)(e=>{let t=sI[e],a={id:(0,aL.newWidgetId)(e),type:e,gx:0,gy:0,gw:t.defaultSize.gw,gh:t.defaultSize.gh,config:{}},s=!1;m(n=>{if(t.singleton&&n.some(t=>t.type===e))return n;let l=aB(n,t.defaultSize.gw,t.defaultSize.gh);return a.gx=l.gx,a.gy=l.gy,s=!0,[...n,a]}),i(),$(!0),s&&"data"===e&&eA(a)},[m,i,B,eA]),eD=(0,r.useCallback)(e=>{let t=(0,sN.visualDef)(e.visual).size,a={id:(0,aL.newWidgetId)("data"),type:"data",gx:0,gy:0,gw:e.gw||t.gw,gh:e.gh||t.gh,label:e.label,config:{binding:e.binding,visual:e.visual,labelKey:e.labelKey,valueKey:e.valueKey,prefix:e.prefix,suffix:e.suffix,format:e.format,refreshSec:60}};m(e=>{let t=aB(e,a.gw,a.gh);return a.gx=t.gx,a.gy=t.gy,[...e,a]}),i(),eA(a)},[m,i,eA]),eM=(0,r.useCallback)(()=>{l({inverted:O,tag:a("widgetPicker.tag","WIDGETS"),content:(0,t.jsx)(sX,{widgets:en.current,onAdd:eR,onAddBuilt:eD})})},[l,O,eR,eD,a]),eI=(0,r.useCallback)(e=>{let t=0;for(let a of e)"rename_board"===a.op&&a.name?(w(b,a.name),t++):"set_range"===a.op&&("today"===a.range||"7d"===a.range||"3
310d"===a.range)&&(L(a.range),s&&ns(a.range,b),t++);let l=(e,t)=>{let a=(0,sN.visualDef)(String(e.visual||"stat")).size,s=e.gw||a.gw,n=e.gh||a.gh,l=aB(t,s,n);return{id:(0,aL.newWidgetId)("data"),type:"data",gx:l.gx,gy:l.gy,gw:s,gh:n,label:e.label,config:{binding:e.binding,visual:e.visual,labelKey:e.labelKey,valueKey:e.valueKey,prefix:e.prefix,suffix:e.suffix,format:e.format,refreshSec:60}}},i=(e,t)=>{let a=e,s=0;for(let e of t)"add"===e.op&&e.widget?.binding?(a=[...a,l(e.widget,a)],s++):"update"===e.op&&e.id&&a.some(t=>t.id===e.id)?(a=a.map(t=>t.id===e.id?{...t,...e.patch,config:{...t.config,...e.config}}:t),s++):"remove"===e.op&&e.id&&a.some(t=>t.id===e.id)&&(a=a.filter(t=>t.id!==e.id),s++);return[a,s]},r=e.find(e=>"apply_template"===e.op&&aG.includes(e.key??"")),o=e.find(e=>"add_tab"===e.op&&e.name);if(r)return n({title:a("dashTemplates.applyTitle","APPLY TEMPLATE"),desc:a("dashboard.agent.applyTemplateDesc",'The agent wants to replace this board with the "{{name}}" template.',{name:r.key}),onConfirm:()=>m(()=>az(i(az(aZ(r.key)),e)[0]))}),t;if(o){let[a,s]=i(en.current,e.filter(e=>"add"!==e.op));s&&m(()=>az(a)),t+=s;let n=[];for(let t of e)"add"===t.op&&t.widget?.binding&&n.push(l(t.widget,n));return y(o.name??"",az(n)),t+=n.length+1}let[d,c]=i(en.current,e);return c&&m(()=>az(d)),t+c},[m,w,y,b,n,s,a]),eO=(0,r.useCallback)(()=>{let e=x.find(e=>e.id===b);l({inverted:O,inline:!0,tag:a("dashboard.agent.tag","AGENT"),content:(0,t.jsx)(s6,{tabId:b,tabName:e?.name??a("dashboard.title","DASHBOARD"),getWidgets:()=>en.current,onApply:eI})})},[l,O,x,b,eI,a]),eP=(0,r.useCallback)(async(e,t,a)=>{try{await _();let s=await (0,tA.apiFetch)("/api/v1/insights-dashboards/po/auto-board/stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataset_id:e,...t}),signal:a?.signal});if(!s.ok||!s.body){let e=await s.json().catch(()=>({}));return String(e.error??e.detail??"could not build the board")}let n=s.body.getReader(),l=new TextDecoder,i="";for(;;){let{value:e,done:t}=await n.read();if(t)break;let s=(i+=l.decode(e,{stream:!0})).split("\n\n");for(let e of(i=s.pop()??"",s)){let t=e.split("\n").find(e=>e.startsWith("data: "));if(!t)continue;let s=JSON.parse(t.slice(6));if("phase"===s.type&&s.phase)a?.onPhase?.(s.phase);else if("error"===s.type)return s.message??"could not build the board";else if("done"===s.type&&s.tab_id)return n.cancel().catch(()=>void 0),await T(s.tab_id),ee(!1),null}}return"could not build the board"}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return null;return e instanceof Error?e.message:"could not build the board"}},[_,T]),eL=(0,r.useCallback)(()=>{y(a("dashboard.tabs.defaultName","DASHBOARD {{n}}",{n:x.length+1})),ee(!1)},[y,x.length,a]),eF=(0,r.useCallback)((e,t)=>{y(t,az(e)),ee(!1)},[y]),e$=(0,r.useCallback)(()=>{l({inverted:O,tag:a("dashboard.ask.tag","ASK"),content:(0,t.jsx)(nl,{onAdd:eD})})},[l,O,eD,a]),eB=(0,r.useCallback)(()=>{let e=x.find(e=>e.id===b);l({inverted:O,tag:a("dashboard.summary.tag","SUMMARY"),content:(0,t.jsx)(nn,{tabName:e?.name??a("dashboard.title","DASHBOARD"),widgets:en.current})})},[l,O,x,b,a]),eH=(0,r.useCallback)(async()=>{let t=ea.current;if(!t)return;let a="#ffffff";for(let e=t;e;e=e.parentElement){let t=getComputedStyle(e).backgroundColor;if(t&&"transparent"!==t&&"rgba(0, 0, 0, 0)"!==t){a=t;break}}let{default:s}=await e.A(270830),n=await s(t,{backgroundColor:a,scale:2}),l=x.find(e=>e.id===b)?.name??"dashboard",i=document.createElement("a");i.href=n.toDataURL("image/png"),i.download=`${l.toLowerCase().replace(/[^\w-]+/g,"-")||"dashboard"}.png`,i.click()},[x,b]),ez=(0,r.useCallback)(async()=>{let t=ea.current;if(!t)return;let a=x.find(e=>e.id===b)?.name??"DASHBOARD",{exportSessionPreview:s}=await e.A(295753);await s("pdf",{title:a,artifact:null,panels:[],element:t})},[x,b]),eU=(0,r.useCallback)(async()=>{let t=x.find(e=>e.id===b)?.name??"DASHBOARD",{utils:a,writeFile:s}=await e.A(342078),{normalizeColumnar:n}=await e.A(677601),{withDashboardRange:l}=await e.A(140874),i=a.book_new(),r=[["Widget","Rows"]],o=new Set;for(let e of en.current){let t=e.config?.binding;if("data"===e.type&&t)try{let s=l(t,e.config.dateField,P),d=await (0,tA.apiFetch)("/api/v1/insights-dashboards/data/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...s,limit:5e4})}),c=n(await d.json(),e.config.pick);if(c.error||!c.columns.length)continue;let u=(e.label||"WIDGET").replace(/[[\]:*?/\\]+/g," ").trim().slice(0,28)||"WIDGET",m=2;for(;o.has(u);)u=`${u.slice(0,25)} ${m++}`;o.add(u),a.book_append_sheet(i,a.aoa_to_sheet([c.columns,...c.rows]),u),r.push([e.label||u,c.rows.length])}catch{}}if(1===r.length)return;let d=a.aoa_to_sheet(r);i.SheetNames.unshift("Report"),i.Sheets.Report=d,s(i,`${t.toLowerCase().replace(/[^\w-]+/g,"-")||"dashboard"}.xlsx`)},[x,b,P]),eG=(0,r.useCallback)(()=>{l({inverted:O,wide:!0,tag:a("dashTemplates.tag","TEMPLATES"),content:(0,t.jsx)(s0,{currentWidgets:en.current,onApply:(e,t)=>{n({title:a("dashTemplates.applyTitle","APPLY TEMPLATE"),desc:a("dashTemplates.applyDesc",'"{{name}}" replaces the current board layout.',{name:t}),onConfirm:()=>{g(e),i()}})},onReset:()=>{n({title:a("dashTemplates.resetTitle","RESET BOARD"),desc:a("dashTemplates.resetDesc","The board returns to the default workspace layout."),onConfirm:()=>{f(),i()}})}})})},[l,i,O,g,f,n,a]),eW=(e,t,a)=>
31{if(!F||B!==aL.PO_GRID_COLS)return;let s=en.current.find(e=>e.id===t);s&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture?.(e.pointerId),es.current={id:t,kind:a,pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,orig:{gx:s.gx,gy:s.gy,gw:s.gw,gh:s.gh},minSize:sI[s.type].minSize,moved:!1},W(t))},eK=e=>{let t=es.current;t&&e.pointerId===t.pointerId&&(es.current=null,W(null),U(e=>(t.moved&&e&&("move"===t.kind?m(a=>az(aH(a,t.id,e.gx,e.gy))):m(a=>az(aH(a.map(a=>a.id===t.id?{...a,gw:e.gw,gh:e.gh}:a),t.id,e.gx,e.gy)))),null)))},eV=(e,t,a)=>{if(!a.startsWith("Arrow"))return;let s="ArrowLeft"===a?-1:+("ArrowRight"===a),n="ArrowUp"===a?-1:+("ArrowDown"===a);m(a=>{if("move"===t)return az(aH(a,e.id,e.gx+s,e.gy+n));let l=sI[e.type].minSize;return a.map(t=>t.id===e.id?{...t,...a$({...t,gw:Math.max(l.gw,t.gw+s),gh:Math.max(l.gh,t.gh+n)})}:t)})};return(0,t.jsxs)("div",{className:`viewPane dashView${O?" dataDark":""}${o?.inline?" dbAgentSide":""}`,children:[(0,t.jsxs)("div",{className:"dbBand",children:[(0,t.jsx)("span",{className:"dbBandTitle",children:a("dashboard.title","DASHBOARD")}),(0,t.jsx)("span",{className:"dbBandClock",role:"status","aria-live":"polite",children:p?a("dashboard.saving","SAVINGâ¦"):E?a("dashboard.saveFailed","SAVE FAILED"):""}),(0,t.jsx)("span",{className:"dbSeg",children:ne.map(e=>(0,t.jsx)("button",{className:e.id===P?"on":"",onClick:()=>{var t;L(t=e.id),s&&ns(t,b)},children:a(`dashboard.range.${e.id}`,e.label)},e.id))})]}),x.length>0&&(0,t.jsxs)("div",{className:"dbRail",role:"tablist","aria-label":a("dashboard.rail.label","DASHBOARDS"),onKeyDown:e=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(e.key))return;e.preventDefault();let t=x.findIndex(e=>e.id===b),a="Home"===e.key?0:"End"===e.key?x.length-1:"ArrowLeft"===e.key?Math.max(0,t-1):Math.min(x.length-1,t+1),s=x[a];s&&s.id!==b&&(j(s.id),e.currentTarget.querySelectorAll("[role='tab']")[a]?.focus())},children:[x.map((e,s)=>K===e.id?(0,t.jsx)("input",{autoFocus:!0,defaultValue:e.name,"aria-label":a("dashboard.tabs.rename","RENAME DASHBOARD"),onKeyDown:e=>{"Enter"===e.key&&e.currentTarget.blur(),"Escape"===e.key&&V(null)},onBlur:t=>{w(e.id,t.currentTarget.value),V(null)}},e.id):(0,t.jsxs)("button",{className:`dbRailPill${e.id===b?" on":""}`,role:"tab","aria-selected":e.id===b,"aria-controls":"dbBoardPanel",tabIndex:e.id===b?0:-1,draggable:!0,title:a("dashboard.rail.hint","Double-click to rename · right-click for options"),onDragStart:()=>{et.current=s},onDragOver:e=>{e.preventDefault(),null!==et.current&&et.current!==s&&(N(et.current,s),et.current=s)},onDragEnd:()=>{et.current=null},onClick:()=>j(e.id),onDoubleClick:()=>V(e.id),onContextMenu:t=>eE(t,e.id,s),children:[(0,t.jsx)("span",{className:"dbRailGlyph","aria-hidden":!0,children:e.id===v?"â":nt[s%nt.length]}),(0,t.jsx)("span",{className:"dbRailName",children:e.name})]},e.id)),(0,t.jsx)("button",{className:"dbRailAdd","aria-label":a("dashboard.tabs.new","NEW DASHBOARD"),title:a("dashboard.tabs.new","NEW DASHBOARD"),onClick:()=>ee(!0),children:"ï¼"})]}),(0,t.jsxs)("div",{className:"dbActRow",children:[(0,t.jsx)("span",{className:`dbActBadge${E?" live":""}`,title:a("dashboard.act.count","{{n}} widgets on this board",{n:u.length}),children:u.length}),(0,t.jsx)("span",{className:"dbActLabel",children:E?a("dashboard.saveFailed","SAVE FAILED"):F?a("dashboard.act.editing","EDITING"):a("dashboard.act.widgets","WIDGETS")}),E&&(0,t.jsx)("button",{className:"dbWidget urgent",onClick:()=>void A(),title:E,children:a("dashboard.retrySave","RETRY SAVE")}),ei&&(0,t.jsx)("span",{className:"dbActLabel",role:"status",children:a("dashboard.staleTab","SAVED TAB NOT FOUND â SHOWING DEFAULT")}),(0,t.jsxs)("button",{className:"dbWidget",disabled:!M,onClick:R,children:[(0,t.jsx)("span",{className:"dbActGlyph","aria-hidden":!0,children:"â¶"}),a("dashboard.undo","UNDO")]}),(0,t.jsxs)("button",{className:"dbWidget",disabled:!I,onClick:D,children:[(0,t.jsx)("span",{className:"dbActGlyph","aria-hidden":!0,children:"â·"}),a("dashboard.redo","REDO")]}),(0,t.jsx)("span",{className:"dbSpacer"}
31),Y&&(0,t.jsx)("button",{className:"dbWidget dbEditOn",onClick:()=>q(null),title:a("dashboard.filterClear","Clear cross-filter"),children:a("dashboard.filterChip","FILTER: {{value}} â",{value:String(Y.value)})}),(0,t.jsxs)("button",{className:"dbWidget",onClick:e$,children:[(0,t.jsx)("span",{className:"dbActGlyph","aria-hidden":!0,children:"â¦"}),a("dashboard.ask.button","ASK")]}),(0,t.jsxs)("button",{className:"dbWidget",onClick:eB,children:[(0,t.jsx)("span",{className:"dbActGlyph","aria-hidden":!0,children:"â¦"}),a("dashboard.summary.button","SUMMARY")]}),(0,t.jsx)("button",{className:"dbWidget",onClick:()=>void eH(),children:a("dashboard.exportPng","PNG")}),(0,t.jsx)("button",{className:"dbWidget",onClick:()=>void ez(),children:a("dashboard.exportPdf","PDF")}),(0,t.jsx)("button",{className:"dbWidget",onClick:()=>void eU(),children:a("dashboard.exportXlsx","XLS")}),(0,t.jsx)("button",{className:"dbWidget",onClick:eG,children:a("dashTemplates.button","TEMPLATES")}),(0,t.jsxs)("button",{className:`dbWidget${F?" dbEditOn":""}`,onClick:()=>$(e=>!e),children:[(0,t.jsx)("span",{className:"dbActGlyph","aria-hidden":!0,children:"â«"}),F?a("dashboard.doneEditing","DONE"):a("dashboard.edit","EDIT")]}),(0,t.jsxs)("button",{className:"dbWidget",onClick:eM,children:[(0,t.jsx)("span",{className:"dbActGlyph","aria-hidden":!0,children:"+"}),a("dashboard.addWidgetShort","WIDGET")]})]}),eN.length>0&&(0,t.jsx)("div",{className:"dbFilterRow",children:(0,t.jsxs)("span",{className:"dbFilterBar",children:[(0,t.jsx)("label",{htmlFor:"board-filter-col",children:a("dashboard.filterBar.label","FILTER")}),(0,t.jsxs)("select",{id:"board-filter-col",value:ex,onChange:e=>void eC(e.target.value),children:[(0,t.jsx)("option",{value:"",children:a("dashboard.filterBar.column","COLUMNâ¦")}),eN.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]}),ex&&(0,t.jsxs)("select",{value:eg?.value??"",onChange:e=>ef(e.target.value?{column:ex,value:e.target.value}:null),"aria-label":a("dashboard.filterBar.value","VALUE"),children:[(0,t.jsx)("option",{value:"",children:a("dashboard.filterBar.anyValue","ALL VALUES")}),ev.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]}),eg&&(0,t.jsx)("button",{onClick:()=>{ef(null),eb(""),ej([])},"aria-label":a("dashboard.filterBar.clear","Clear board filter"),children:"â"})]})}),(0,t.jsx)("div",{className:"dbScroll",id:"dbBoardPanel",role:"tabpanel","aria-label":a("dashboard.title","DASHBOARD"),children:h?(0,t.jsx)("div",{className:"dbEmpty",style:{padding:40},children:a("dashboard.loading","LOADING")}):(0,t.jsxs)("div",{ref:ea,className:`dbGrid${F?" editing":""}`,style:{"--db-cols":B},onPointerMove:e=>{let t=es.current;if(!t||e.pointerId!==t.pointerId||!t.moved&&5>Math.hypot(e.clientX-t.startX,e.clientY-t.startY))return;t.moved=!0;let a=ec();if("move"===t.kind){let s=Math.round((e.clientX-t.startX)/a),n=Math.round((e.clientY-t.startY)/aL.PO_ROW_PX);U(a$({...t.orig,gx:t.orig.gx+s,gy:t.orig.gy+n}))}else{let s=Math.round((e.clientX-t.startX)/a),n=Math.round((e.clientY-t.startY)/aL.PO_ROW_PX);U(a$({...t.orig,gw:Math.max(t.minSize.gw,t.orig.gw+s),gh:Math.max(t.minSize.gh,t.orig.gh+n)}))}},onPointerUp:eK,onPointerCancel:eK,children:[eo.map(e=>{let s=sI[e.type],n=s.Renderer;return(0,t.jsxs)("div",{className:`dbWidgetShell${s.bare?" bare":""}${G===e.id?" dbDragging":""}`,style:{gridColumn:`${e.gx+1} / span ${Math.min(e.gw,B)}`,gridRow:`${e.gy+1} / span ${e.gh}`},children:[(0,t.jsx)("div",{className:s.bare?"dbBareBody":"dbPanel dbPanelFill",children:(0,t.jsx)(n,{widget:e,editMode:F,range:P,tasks:d,tasksLoading:c,onPatchConfig:t=>eh(e.id,t),onConfigure:()=>eA(e),crossFilter:Y,onCrossFilter:q,boardFilter:eg,datasetColumns:ey})}),F&&(0,t.jsxs)(t.Fragment,{children:[B===aL.PO_GRID_COLS&&(0,t.jsx)("button",{className:"dbDragBar",onPointerDown:t=>eW(t,e.id,"move"),onKeyDown:t=>{eV(e,"move",t.key),t.key.startsWith("Arrow")&&t.preventDefault()},"aria-label":a("dashboard.dragHint","Move widget; use arrow keys"),title:a("dashboard.dragHint","Drag to move")}),B!==aL.PO_GRID_COLS&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{className:"dbWidgetKebab",style:{right:84},onClick:()=>ep(e.id,-1),"aria-label":a("dashboard.moveUp","Move widget up"),children:"â"}),(0,t.jsx)("button",{className:"dbWidgetKebab",style:{right:56},onClick:()=>ep(e.id,1),"aria-label":a("dashboard.moveDown","Move widget down"),children:"â"})]}),(0,t.jsx)("button",{className:"dbWidgetKebab",onClick:()=>eA(e),"aria-label":a("dashboard.configureWidget","Configure widget"),children:"â¯"}),(0,t.jsx)("button",{className:"dbWidgetRemove",onClick:()=>eS(e.id),"aria-label":a("dashboard.removeWidget","REMOVE WIDGET"),children:"â"}
31),B===aL.PO_GRID_COLS&&(0,t.jsx)("button",{className:"dbResizeHandle",onPointerDown:t=>eW(t,e.id,"resize"),onKeyDown:t=>{eV(e,"resize",t.key),t.key.startsWith("Arrow")&&t.preventDefault()},"aria-label":a("dashboard.resizeHint","Resize")})]})]},e.id)}),z&&(0,t.jsx)("div",{className:"dbDropGhost",style:{gridColumn:`${z.gx+1} / span ${z.gw}`,gridRow:`${z.gy+1} / span ${z.gh}`}}),!eo.length&&(0,t.jsxs)("div",{className:"dbBoardEmpty",children:[(0,t.jsx)("span",{children:a("dashboard.emptyBoard","NO WIDGETS ON THIS BOARD")}),(0,t.jsxs)("div",{className:"dbBoardEmptyActions",children:[(0,t.jsx)("button",{className:"po-btn",onClick:eG,children:a("dashTemplates.button","TEMPLATES")}),(0,t.jsx)("button",{className:"po-btn po-btn--ghost",onClick:eM,children:a("dashboard.addWidget","ï¼ WIDGET")}),(0,t.jsx)("button",{className:"po-btn po-btn--ghost",onClick:()=>ee(!0),children:a("dashboard.newBoard.fromData","BUILD FROM DATA")})]})]})]})}),J&&(0,t.jsx)(eu.PoContextMenu,{ctx:J,onClose:()=>X(null)}),(0,t.jsx)(s9,{open:Q,onClose:()=>ee(!1),onEmpty:eL,onTemplate:eF,onBuild:eP}),(0,t.jsx)("button",{className:"dbChatFab",onClick:eO,"aria-label":a("dashboard.agent.open","OPEN BOARD AGENT"),title:a("dashboard.agent.open","OPEN BOARD AGENT"),children:(0,t.jsxs)("svg",{viewBox:"0 0 16 16",width:"17",height:"17","aria-hidden":!0,children:[(0,t.jsx)("path",{d:"M2 3h12v8H6l-3 3v-3H2z",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M5 6.5h6M5 8.5h4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})})]})}],292792)}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.