@vellumai/web 0.10.12-dev.202607272227.bd2aa0b → 0.10.12-dev.202607280044.d57f000

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./jsx-runtime-D3ZM-ToX.js";import{n as r,r as i}from"./avatar-svg-compositor-FtVPqzlC.js";import{t as a}from"./use-reduced-motion-Se97jRQ-.js";var o=e(t(),1),s=n();function c(e,t){return e+Math.random()*(t-e)}function l(e){let t=[],n=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi,r;for(;(r=n.exec(e))!==null;)t.push(parseFloat(r[0]));return t}function u(e){let t=0,n=0,r=0;for(let i=0;i<e.length-1;i+=2)t+=e[i],n+=e[i+1],r++;return r>0?{x:t/r,y:n/r}:{x:0,y:0}}function d(e,t,n,r,i){let a=r*1.1,o=0;return e.replace(/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi,()=>{let e=o;o++;let r=t[e],s=e%2==0,c=s?n.x:n.y,l=s?e+1:e-1,u=l>=0&&l<t.length?t[l]:c,d=s?r:u,f=Math.atan2((s?u:r)-n.y,d-n.x),p=1+(Math.sin(f*2+a)*.7+Math.sin(f*3-a*.5)*.3)*i;return(c+(r-c)*p).toFixed(3)})}function f(e,t,n){let r=l(e),i=u(r),a=[e];for(let o=1;o<t;o++)a.push(d(e,r,i,o,n));return a}function p({components:e,traits:t,size:n,isAssistantBusy:l=!1,breathe:u=!0}){let d=a(),{bodyShape:p,eyeStyle:m,color:h}=i(e,t.bodyShape,t.eyeStyle,t.color),{bodyTransform:g,eyeTransform:_}=r(p,m,e,n),v=m.sourceViewBox,y=p.viewBox,b=Math.min(n/y.width,n/y.height),x=(n-y.width*b)/2,S=(n-y.height*b)/2,C=Math.min(y.width/v.width,y.height/v.height),w=e.faceCenterOverrides.find(e=>e.bodyShape===p.id&&e.eyeStyle===m.id),T=w?w.faceCenter:p.faceCenter,E=T.x-m.eyeCenter.x*C,D=T.y-m.eyeCenter.y*C,O=b*(E+m.eyeCenter.x*C)+x,k=b*(D+m.eyeCenter.y*C)+S,A=(0,o.useMemo)(()=>l?f(p.svgPath,16,.06):[p.svgPath],[p.svgPath,l]),[j,M]=(0,o.useState)(!1),[N,P]=(0,o.useState)(0),F=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(d||l){M(!1);return}let e=!1;function t(){return setTimeout(()=>{e||(M(!0),setTimeout(()=>{e||(M(!1),Math.random()<.2?setTimeout(()=>{e||(M(!0),setTimeout(()=>{e||(M(!1),t())},150))},200):t())},150))},c(3e3,7e3))}let n=t();return()=>{e=!0,clearTimeout(n)}},[d,l]),(0,o.useEffect)(()=>{if(d||l){P(0);return}let e=!1;function t(){return setTimeout(()=>{e||(P((Math.random()<.5?-1:1)*c(1,2)),setTimeout(()=>{e||(P(0),t())},200))},c(8e3,15e3))}let n=t();return()=>{e=!0,clearTimeout(n)}},[d,l]),(0,o.useEffect)(()=>{let e=F.current;if(!e)return;let t=A[0]??p.svgPath;if(!l||d||A.length<=1){e.setAttribute(`d`,t);return}let n=0,r=setInterval(()=>{n=(n+1)%A.length;let t=A[n];t&&e.setAttribute(`d`,t)},150);return()=>{clearInterval(r),e.setAttribute(`d`,t)}},[l,d,A,p.svgPath]);let I=n/2,L=n/2,R=d?`none`:l?`avatar-morph-scale 2.4s ease-in-out infinite, avatar-morph-rotate 3s ease-in-out infinite`:u?`avatar-breathe-kf 4s ease-in-out infinite`:`none`,z=l?0:N,B=j&&!l,V=A[0]??p.svgPath;return(0,s.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:n,height:n,viewBox:`0 0 ${n} ${n}`,style:{animation:R,transformOrigin:`center`},children:[(0,s.jsx)(`g`,{style:{transform:`rotate(${z}deg)`,transformOrigin:`${I}px ${L}px`,transition:z===0?`transform 0.3s ease-out`:`transform 0.2s ease-in-out`},children:(0,s.jsx)(`path`,{ref:F,d:V,fill:h.hex,transform:g,style:{transition:l?`d 0.3s ease-in-out`:`none`}})}),(0,s.jsx)(`g`,{style:{transform:B?`scaleY(0.1)`:`scaleY(1)`,transformOrigin:`${O}px ${k}px`,transition:`transform 0.15s ease-in-out`},children:m.paths.map((e,t)=>(0,s.jsx)(`path`,{d:e.svgPath,fill:e.color,transform:_},t))})]})}export{p as t};
@@ -1,3 +1,3 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/native-file-DQ9qLg0-.js","assets/chunk-jRWAZmH_.js","assets/preload-helper-Cv2QeVDK.js","assets/is-electron-m5eeGBnd.js","assets/dist-BwAT3VYQ.js"])))=>i.map(i=>d[i]);
2
- import{o as e,t}from"./chunk-jRWAZmH_.js";import{t as n}from"./capture-error-Bj8_eutd.js";import{t as r}from"./react-BFJW0bSv.js";import{t as i}from"./button-Dy5001j6.js";import{t as a}from"./preload-helper-Cv2QeVDK.js";import{m as o,t as s,u as c}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as l}from"./QueryClientProvider-CMu7CkQU.js";import{t as u}from"./useQuery-Bz-fbQ-m.js";import{t as d}from"./useMutation-CXGTrp4W.js";import{t as f}from"./jsx-runtime-D3ZM-ToX.js";import{t as p}from"./typography-DEI9Ra9z.js";import{t as m}from"./card-DRIctGVs.js";import{t as h}from"./createLucideIcon-CAM1RhH8.js";import{t as g}from"./arrow-left-C2ylPLHq.js";import{t as _}from"./check-sC49_hjU.js";import{t as v}from"./chevron-down-B5A-0g8A.js";import{t as y}from"./chevron-up-2Qqarz0p.js";import{t as b}from"./circle-check-CjGnAahM.js";import{t as x}from"./coins-Hrmb9tmj.js";import{A as S,C,D as w,E as T,I as E,L as D,M as O,O as k,P as A,S as j,T as M,_ as N,b as ee,c as P,d as te,f as ne,g as re,h as F,i as I,j as L,l as R,m as ie,n as ae,p as oe,s as se,t as ce,u as le,v as z,w as ue,x as B,y as de}from"./use-checkout-dismiss-refresh-BKKz6nyN.js";import{n as V,o as fe}from"./list-row-B1wPb2Au.js";import{t as pe}from"./credit-card-C1RL73Rt.js";import{t as me}from"./download-CywcQLB2.js";import{t as he}from"./external-link-CS0aVYGt.js";import{t as ge}from"./info-vgPTIsGI.js";import{t as H}from"./loader-circle-XREx3i4W.js";import{t as _e}from"./sparkles-Ccrj7hxd.js";import{t as ve}from"./triangle-alert-CQfiAg_t.js";import{t as ye}from"./users-iLvfYFOP.js";import{t as be}from"./x-JBAsSOmg.js";import{t as U}from"./notice-BMK7xqUw.js";import{M as xe,r as Se}from"./src-te3YTBG-.js";import{t as Ce}from"./tag-NXcyiTkK.js";import{t as we}from"./input-hw3el2GJ.js";import{t as Te}from"./toggle-lfnhEAcN.js";import{t as W}from"./modal-BR4CUFBd.js";import{n as G}from"./toast-LgLp4obE.js";import{t as Ee}from"./confirm-dialog-UYFm4osC.js";import{t as De}from"./dropdown-BCfnSdIZ.js";import{Or as Oe}from"./sdk.gen-BVAVE6A_.js";import{It as ke,Lt as Ae,Rt as je,c as Me,d as Ne,ht as Pe,zt as Fe}from"./react-query.gen-r3I6j8-1.js";import{t as Ie}from"./api-errors-CFiCT7Ap.js";import{o as Le}from"./auth-store-FtoML9k1.js";import{lt as Re,ut as ze}from"./sdk.gen-BIu1DgTs.js";import{u as Be}from"./routes-vE-2hncW.js";import{i as Ve,r as He,t as Ue}from"./use-platform-gate-CiX10TX6.js";import{t as We}from"./use-is-org-ready-1-Hv4dF3.js";import{n as Ge,r as Ke}from"./browser-DLWdxyJA.js";import{n as qe,t as Je}from"./conversation-navigation-KFwqoqT9.js";import{n as Ye}from"./use-is-mobile-Bz2l7wPL.js";import{t as Xe}from"./effective-timezone-qiooajmO.js";import{$ as Ze,B as Qe,G as $e,H as et,J as tt,K as nt,L as rt,Mt as it,Q as at,R as ot,U as st,V as ct,W as lt,X as ut,Y as dt,Z as ft,ct as pt,dt as mt,et as ht,ft as gt,gt as _t,ht as vt,it as yt,lt as bt,nt as xt,pt as St,q as Ct,st as wt,tt as Tt,ut as Et,wt as Dt,z as Ot}from"./react-query.gen-Mwd5l-vZ.js";import{t as kt}from"./use-effective-timezone-LqzBqHBy.js";import{t as At}from"./misc-DckBb5zz.js";import{t as jt}from"./platform-login-notice-BvVdKM0X.js";import{t as Mt}from"./use-active-assistant-id-CXhDyK7y.js";import{t as Nt}from"./format-date-C5pKGCAG.js";import{t as Pt}from"./add-credits-modal-CtdZCpuZ.js";import{t as Ft}from"./link-click-kJxAxKHH.js";import{t as It}from"./schedules-CKGVEPqD.js";import{i as Lt,n as Rt,r as zt,t as Bt}from"./profile-metadata-DgZjbPj8.js";var Vt=h(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),Ht=h(`target`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Ut=h(`tree-palm`,[[`path`,{d:`M13 8c0-2.76-2.46-5-5.5-5S2 5.24 2 8h2l1-1 1 1h4`,key:`foxbe7`}],[`path`,{d:`M13 7.14A5.82 5.82 0 0 1 16.5 6c3.04 0 5.5 2.24 5.5 5h-3l-1-1-1 1h-3`,key:`18arnh`}],[`path`,{d:`M5.89 9.71c-2.15 2.15-2.3 5.47-.35 7.43l4.24-4.25.7-.7.71-.71 2.12-2.12c-1.95-1.96-5.27-1.8-7.42.35`,key:`ywahnh`}],[`path`,{d:`M11 15.5c.5 2.5-.17 4.5-1 6.5h4c2-5.5-.5-12-1-14`,key:`ft0feo`}]]),K=e(r(),1);function Wt(e){return e.get(`tab`)===`billing`||e.has(`adjust_plan`)||e.has(`pro_onboarding`)||e.has(`billing_status`)||e.has(`session_id`)}function Gt(e,t){return e===`full`?!0:e===`disabled`?Wt(t):!1}function Kt(e){if(!e)return{};let t={};for(let n of e.callSites)!n.id||!n.displayName||(t[n.id]={id:n.id,displayName:n.displayName,description:n.description,domain:n.domain});return t}function q(e){return Number.isFinite(e)?Math.round(e).toLocaleString():`0`}function qt(e){return!Number.isFinite(e)||e===0?`$0.00`:`$${e.toFixed(2)}`}var Jt=`model`,Yt={model:`Model`,task:`Action`,profile:`Profile`},Xt=[{value:`model`,label:Yt.model},{value:`task`,label:Yt.task},{value:`profile`,label:Yt.profile}];function Zt(e){return e===`model`||e===`task`||e===`profile`}function Qt(e){switch(e){case`model`:return`model`;case`task`:return`call_site`;case`profile`:return`inference_profile`}}function $t(e){switch(e){case`model`:return`model`;case`task`:return`llm_call_site`;case`profile`:return`inference_profile`}}function en(e,t,n){if(e===`task`){let e=t.groupKey;return e?n.callSites?.[e]?.displayName??t.group:t.group}if(e===`profile`){let e=t.groupKey;return e?n.profiles?.[e]?.displayName??t.group:t.group||`Default / Unset`}return t.group}function tn(e,t,n){return!e||e.length===0?[]:e.map(e=>{let r=en(t,e,n);return r===e.group?e:{...e,group:r}})}var nn=6,rn=`value:`,an=`null:`;function on(e,t=`schedule`){return e===null?`${an}${Zt(t)?Qt(t):t}`:`${rn}${e}`}function sn(e){return[...e].sort((e,t)=>{if(e.date!==t.date)return e.date<t.date?-1:1;let n=fn(e.bucketId),r=fn(t.bucketId);return n===r?e.bucketId===t.bucketId?0:e.bucketId<t.bucketId?-1:1:n-r})}function cn(e){return e.map(e=>({bucketId:e.bucketId,date:e.date,displayLabel:e.displayLabel,totalInputTokens:e.totalInputTokens,totalOutputTokens:e.totalOutputTokens,totalEstimatedCostUsd:e.totalEstimatedCostUsd,eventCount:e.eventCount,groups:{}}))}function ln(e,t,n){return t!==`task`&&t!==`profile`?[...e]:e.map(e=>{let r=!1,i={};for(let[a,o]of Object.entries(e.groups)){let e=en(t,dn(o),n);e===o.group?i[a]=o:(r=!0,i[a]={...o,group:e})}return r?{...e,groups:i}:e})}function un(e){let t=new Map;for(let n of e)for(let[e,r]of Object.entries(n.groups)){let n=t.get(e);t.set(e,{label:n?.label??r.group,totalEstimatedCostUsd:(n?.totalEstimatedCostUsd??0)+r.totalEstimatedCostUsd})}let n=Array.from(t.entries()).sort(([e,t],[n,r])=>t.totalEstimatedCostUsd===r.totalEstimatedCostUsd?t.label===r.label?e===n?0:e<n?-1:1:t.label<r.label?-1:1:r.totalEstimatedCostUsd-t.totalEstimatedCostUsd).map(([e,t],n)=>({seriesKey:e,label:t.label,totalEstimatedCostUsd:t.totalEstimatedCostUsd,colorIndex:n}));return{items:n,visibleItems:n.slice(0,nn)}}function dn(e){return{group:e.group,groupId:e.groupKey,groupKey:e.groupKey,totalInputTokens:e.totalInputTokens,totalOutputTokens:e.totalOutputTokens,totalCacheCreationTokens:0,totalCacheReadTokens:0,totalEstimatedCostUsd:e.totalEstimatedCostUsd,eventCount:e.eventCount,turnCount:null}}function fn(e){let t=e.lastIndexOf(`|`);if(t<0)return 0;let n=Number(e.slice(t+1));return Number.isFinite(n)?n:0}var J=f(),pn=140,mn=40,hn=28,gn=2,_n=2,vn=1e-6,yn=12,bn=220,xn=56,Sn=[40,80,60,100,50,70,30],Cn=[18,24,28,35,42,50,64,78,92,106,118,96,84,74,68,80,88,72,56,48,40,34,26,20],wn=[`var(--usage-trend-stack-positive, var(--system-positive-strong, #10b981))`,`var(--usage-trend-stack-info, var(--system-info-strong, #3b82f6))`,`var(--usage-trend-stack-mid, var(--system-mid-strong, #f59e0b))`,`var(--usage-trend-stack-secondary, var(--content-secondary, #6b7280))`,`var(--usage-trend-stack-negative, var(--system-negative-strong, #f87171))`,`var(--usage-trend-stack-tertiary, var(--content-tertiary, #9ca3af))`];function Tn(e){return wn[e%wn.length]}function En(e){return e.displayLabel?e.displayLabel:e.date}function Dn(e,t){let n=e+yn,r=t+yn;return n+bn>window.innerWidth&&(n=e-bn-yn),r+xn>window.innerHeight&&(r=t-xn-yn),{x:n,y:r}}function On({buckets:e,isHourly:t,legendItems:n}){let[r,i]=(0,K.useState)(null),a=(0,K.useMemo)(()=>sn(e),[e]),o=(0,K.useMemo)(()=>un(e),[e]),s=n??o.items,c=n??o.visibleItems,l=(0,K.useMemo)(()=>a.reduce((e,t)=>Math.max(e,t.totalEstimatedCostUsd),0),[a]),u=(0,K.useCallback)((e,t)=>{let n=Dn(e.clientX,e.clientY);i({...t,x:n.x,y:n.y})},[]),d=(0,K.useCallback)(()=>i(null),[]);if(a.length===0){let e=(0,J.jsx)(Nn,{title:t?`No hourly data`:`No daily data`,subtitle:`No usage recorded in this time range`});return c.length===0?e:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e,(0,J.jsx)(Mn,{items:c})]})}let f=t?hn:mn;return(0,J.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(`div`,{className:`flex items-end gap-2`,style:{height:`${pn}px`},"aria-hidden":`true`,children:a.map(e=>{let t=l>0?e.totalEstimatedCostUsd/l:0,r=Math.max(gn,pn*t);return(0,J.jsx)(`div`,{className:`flex items-end`,style:{width:`${f}px`,minWidth:`${f}px`,height:`${r}px`,opacity:e.totalEstimatedCostUsd>0?1:.3},title:`${En(e)}: ${qt(e.totalEstimatedCostUsd)}`,"data-usage-series-bar":e.bucketId,children:(0,J.jsx)(An,{bucket:e,height:r,legendItems:s,hasLegendOverride:n!=null,onSegmentHover:u,onSegmentLeave:d})},e.bucketId)})}),(0,J.jsx)(`div`,{className:`flex items-start gap-2`,children:a.map(e=>(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,style:{width:`${f}px`,minWidth:`${f}px`},children:[(0,J.jsx)(`span`,{className:`truncate text-[10px]`,style:{color:`var(--content-secondary)`},children:qt(e.totalEstimatedCostUsd)}),(0,J.jsx)(`span`,{className:`truncate text-[10px]`,style:{color:`var(--content-tertiary)`},children:En(e)})]},e.bucketId))}),c.length>0?(0,J.jsx)(Mn,{items:c}):null]}),r?(0,J.jsx)(jn,{tooltip:r}):null]})}function kn({isHourly:e}){let t=e?Cn:Sn,n=e?hn:mn;return(0,J.jsx)(`div`,{className:`flex items-end gap-2`,style:{height:`${pn}px`},"aria-hidden":`true`,children:t.map((e,t)=>(0,J.jsx)(`div`,{className:`rounded-sm`,style:{width:`${n}px`,height:`${e}px`,background:`color-mix(in srgb, var(--border-base) 40%, transparent)`}},t))})}function An({bucket:e,height:t,legendItems:n,hasLegendOverride:r,onSegmentHover:i,onSegmentLeave:a}){let o=Object.keys(e.groups).length>0,s=n.filter(e=>(e.state??`active`)===`active`).flatMap(t=>{let n=e.groups[t.seriesKey];return!n||n.totalEstimatedCostUsd<=0?[]:[{item:t,value:n}]});if(s.length===0&&!o&&!r){let n={label:`Total`,bucketLabel:En(e),cost:qt(e.totalEstimatedCostUsd)};return(0,J.jsx)(`div`,{className:`w-full rounded-sm`,title:`${n.label}: ${n.cost}`,onMouseEnter:e=>i(e,n),onMouseMove:e=>i(e,n),onMouseLeave:a,style:{height:`${t}px`,background:Tn(0)},"data-usage-series-segment-label":n.label,"data-usage-fallback-segment":`true`})}return s.length===0?null:(0,J.jsx)(`div`,{className:`flex w-full flex-col-reverse overflow-hidden rounded-sm`,style:{height:`${t}px`},"data-usage-series-stack":e.bucketId,children:s.map(({item:n,value:r})=>{let o={label:n.label,bucketLabel:En(e),cost:qt(r.totalEstimatedCostUsd)};return(0,J.jsx)(`div`,{title:`${o.label}: ${o.cost}`,onMouseEnter:e=>i(e,o),onMouseMove:e=>i(e,o),onMouseLeave:a,style:{height:`${Math.max(_n,t*r.totalEstimatedCostUsd/Math.max(e.totalEstimatedCostUsd,vn))}px`,background:Tn(n.colorIndex)},"data-usage-series-segment":n.seriesKey,"data-usage-series-segment-label":n.label,"data-usage-series-color-index":n.colorIndex},n.seriesKey)})})}function jn({tooltip:e}){return(0,J.jsxs)(`div`,{className:`pointer-events-none fixed z-50 max-w-[220px] rounded-md border px-2 py-1 shadow-xl`,style:{left:`${e.x}px`,top:`${e.y}px`,background:`var(--surface-overlay, var(--surface-lift))`,borderColor:`var(--border-base)`},"aria-hidden":`true`,children:[(0,J.jsx)(`div`,{className:`truncate text-body-small-default`,style:{color:`var(--content-default)`},children:e.label}),(0,J.jsxs)(`div`,{className:`truncate text-body-small-default`,style:{color:`var(--content-tertiary)`},children:[e.bucketLabel,` · `,e.cost]})]})}function Mn({items:e}){return(0,J.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 pt-1`,children:e.map(e=>{let t=e.state??`active`,n=t===`inactive`;return(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,"data-usage-legend-state":t,children:[(0,J.jsx)(`span`,{className:`h-[7px] w-[7px] shrink-0 rounded-full`,style:{background:n?`var(--content-tertiary)`:Tn(e.colorIndex),opacity:n?.45:1},"aria-hidden":`true`,"data-usage-series-color-index":e.colorIndex}),(0,J.jsx)(`span`,{className:n?`truncate text-[10px] line-through`:`truncate text-[10px]`,style:{color:`var(--content-tertiary)`,opacity:n?.65:1},children:e.label})]},e.seriesKey)})})}function Nn({title:e,subtitle:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-md py-12 text-center`,style:{color:`var(--content-tertiary)`},children:[(0,J.jsx)(`p`,{className:`text-body-medium-default`,style:{color:`var(--content-secondary)`},children:e}),(0,J.jsx)(`p`,{className:`mt-1 text-body-small-default`,children:t})]})}function Pn(e){return Zt(e)?Qt(e):e}function Fn(e){return zn({from:e.from,to:e.to},e.scheduleId)}function In(e){return zn({from:e.from,to:e.to,...e.granularity?{granularity:e.granularity}:{},...e.tz?{tz:e.tz}:{}},e.scheduleId)}function Ln(e){return zn({from:e.from,to:e.to,groupBy:Pn(e.groupBy)},e.scheduleId)}function Rn(e){return zn({from:e.from,to:e.to,granularity:e.granularity,groupBy:Pn(e.groupBy),...e.tz?{tz:e.tz}:{}},e.scheduleId)}function zn(e,t){return t?{...e,scheduleId:t}:e}function Bn(e){return[`${q(e.totalInputTokens)} direct`,`${q(e.totalCacheCreationTokens)} cache created`,`${q(e.totalCacheReadTokens)} cache read`,`${q(e.totalOutputTokens)} out`].join(` / `)}function Vn(e){return!Number.isFinite(e)||e===0?`0`:e>=1e6||e>=999950&&e<1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toLocaleString()}function Hn(e){return`${Vn(e.totalInputTokens+e.totalCacheCreationTokens+e.totalCacheReadTokens)} in / ${Vn(e.totalOutputTokens)} out`}var Un=`task`,Wn=`model`,Gn=new Set([400,404,422]),Kn=3,qn=new Set([`today`,`yesterday`,`7d`,`30d`,`90d`,`all`]),Jn=new Set([`actor`,`provider`,`model`,`conversation`,`task`,`profile`,`schedule`]),Yn={task:Yt.task,profile:Yt.profile,model:Yt.model,provider:`Provider`,actor:`Actor`,conversation:`Conversation`,schedule:`Schedule`},Xn=[{value:`task`,label:Yn.task},{value:`profile`,label:Yn.profile},{value:`model`,label:Yn.model},{value:`provider`,label:Yn.provider},{value:`schedule`,label:Yn.schedule},{value:`conversation`,label:Yn.conversation}];function Zn(e){let t=e.get(`range`),n=e.get(`groupBy`),r=tr(n)?n:Un;return{range:er(t)?t:`7d`,groupBy:r,scheduleId:r===`schedule`?Qn(e):void 0}}function Qn(e){let t=e.get(`scheduleId`);if(!(!t||t.trim().length===0))return t}function $n(e,t){let n=new URLSearchParams(e);return t.range!==void 0&&n.set(`range`,t.range),t.groupBy!==void 0&&n.set(`groupBy`,t.groupBy),t.scheduleId!==void 0&&(t.scheduleId===null||t.scheduleId.trim().length===0?n.delete(`scheduleId`):n.set(`scheduleId`,t.scheduleId)),n.get(`groupBy`)!==`schedule`&&n.delete(`scheduleId`),n}function er(e){return e!=null&&qn.has(e)}function tr(e){return e!=null&&Jn.has(e)}function nr(e){return e!==`conversation`}function rr(e,t){return e!==`task`&&e!==`profile`?!1:ar(t)}function ir(e,t){return!ar(t)&&e<Kn}function ar(e){return e instanceof Ie&&Gn.has(e.status)}function or(e,t){let n=e===`hourly`?`Hourly Trend`:`Daily Trend`;return!t||t===`conversation`?n:`${n} by ${Yn[t]}`}function sr({requestedGranularity:e,isLoading:t,buckets:n}){return e===`hourly`&&(t||!n||n.length===0||n.some(cr))?`hourly`:`daily`}function cr(e){return e.bucketId.includes(`|`)||lr(e.date)}function lr(e){return/^\d{4}-\d{2}-\d{2} ([01]\d|2[0-3]):00$/.test(e)}function ur(e,t,n=Date.now()){return zt(e,t,n)}function dr(e){return e===`today`||e===`yesterday`?`hourly`:`daily`}function fr({prompt:e,children:t,variant:n=`outlined`,size:r=`regular`,className:a}){let o=c(),s=(0,K.useCallback)(()=>{qe(o,{prompt:e})},[o,e]);return(0,J.jsx)(i,{variant:n,size:r,leftIcon:(0,J.jsx)(_e,{}),onClick:s,className:a,children:t})}var pr=[{value:`today`,label:`Today`},{value:`yesterday`,label:`Yesterday`},{value:`7d`,label:`Last 7 days`},{value:`30d`,label:`Last 30 days`},{value:`90d`,label:`Last 90 days`},{value:`all`,label:`All time`}],mr=300*1e3,hr=[`Please load the llm-cost-optimizer skill.`,`Analyze my recent LLM usage and explain the biggest cost contributors by call site, model, and profile.`,`Check my current llm.default, llm.callSites, and llm.profiles.`,`Give me a concise summary of what is driving cost and what you would optimize first.`,`Do not change config yet.`].join(` `),gr=[`Please load the llm-cost-optimizer skill.`,`Analyze my recent LLM usage and current LLM config, then recommend the safest cost-optimization changes.`,`If changes are clearly safe, show me the exact config commands you would run and ask for confirmation before applying them.`].join(` `);function _r({assistantId:e}){let[t,n]=o(),{range:r,groupBy:i,scheduleId:a}=(0,K.useMemo)(()=>Zn(t),[t]),s=kt(),c=(0,K.useCallback)(e=>{n(t=>$n(t,e),{replace:!0})},[n]),l=(0,K.useMemo)(()=>ur(r,s),[r,s]),d=(0,K.useMemo)(()=>dr(r),[r]),f=u({queryKey:Pe({path:{assistant_id:e}}),queryFn:()=>It(e),staleTime:1e4}),p=(0,K.useCallback)(e=>{c({range:e})},[c]),m=u({...Fe({path:{assistant_id:e},query:Fn({from:l.from,to:l.to,scheduleId:a})})}),h=u({queryKey:ke({path:{assistant_id:e},query:Ln({from:l.from,to:l.to,groupBy:i,scheduleId:a})}),queryFn:async({signal:t})=>{try{let{data:n}=await Oe({path:{assistant_id:e},query:Ln({from:l.from,to:l.to,groupBy:i,scheduleId:a}),signal:t,throwOnError:!0});return{groupBy:i,response:n}}catch(n){if(!rr(i,n))throw n;let{data:r}=await Oe({path:{assistant_id:e},query:Ln({from:l.from,to:l.to,groupBy:Wn,scheduleId:a}),signal:t,throwOnError:!0});return{groupBy:Wn,response:r}}},retry:ir}),g=h.data?.groupBy??i,_=nr(g)?g:void 0,v=u({...je({path:{assistant_id:e},query:Rn({from:l.from,to:l.to,granularity:d,groupBy:_??`actor`,tz:s,scheduleId:a})}),enabled:!!_,retry:ir}),y=u({...Ae({path:{assistant_id:e},query:In({from:l.from,to:l.to,granularity:d,tz:s,scheduleId:a})}),enabled:!_||v.isError}),b=u({...Ne({path:{assistant_id:e}}),enabled:g===`task`,staleTime:1/0}),x=u({...Me({path:{assistant_id:e}}),select:Bt,enabled:g===`profile`,staleTime:mr}),S=(0,K.useMemo)(()=>({callSites:Kt(b.data),profiles:x.data??{}}),[b.data,x.data]),C=(0,K.useMemo)(()=>{let e=h.data;if(e)return tn(e.response.breakdown,e.groupBy,S)},[h.data,S]),w=(0,K.useMemo)(()=>{if(!(!_||!v.data))return ln(v.data.buckets,_,S)},[v.data,_,S]),T=(0,K.useMemo)(()=>{if(y.data)return cn(y.data.buckets)},[y.data]),E=(0,K.useMemo)(()=>_?v.error?T?{isLoading:!1,error:null,data:T,refetch:y.refetch}:{isLoading:y.isLoading||!T&&!y.error,error:y.error??v.error,data:void 0,refetch:y.error?y.refetch:v.refetch}:{isLoading:v.isLoading,error:v.error,data:w,refetch:v.refetch}:{isLoading:y.isLoading,error:y.error,data:T,refetch:y.refetch},[T,y.error,y.isLoading,y.refetch,w,_,v.error,v.isLoading,v.refetch]),D=sr({requestedGranularity:d,isLoading:E.isLoading,buckets:E.data}),O=D===`hourly`,k=_&&v.error?void 0:g,A=(0,K.useMemo)(()=>{if(!(g!==`schedule`||!a))return vr(f.data,a)},[g,a,f.data]);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`h3`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:`Usage`}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:(0,J.jsx)(xr,{range:r,onChange:p})})]}),(0,J.jsx)(`section`,{"aria-label":`Totals`,children:(0,J.jsx)(Cr,{query:m,skeleton:(0,J.jsx)(Er,{}),render:e=>(0,J.jsx)(wr,{totals:e})})}),(0,J.jsx)(Sr,{title:`Inference Usage`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`h4`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:or(D,k)}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:(0,J.jsx)(Dr,{value:g,onChange:e=>{e===i&&g!==i&&(h.refetch(),v.refetch()),c({groupBy:e,scheduleId:e===`schedule`?void 0:null})}})})]}),(0,J.jsx)(Cr,{query:E,skeleton:(0,J.jsx)(kn,{isHourly:O}),render:e=>(0,J.jsx)(On,{buckets:e,isHourly:O,legendItems:A})})]})}),(0,J.jsx)(Or,{query:h,groups:C}),(0,J.jsx)(br,{})]})}function vr(e,t){let n=e??[];return[...n.some(e=>e.id===t)?[]:[{id:t,label:yr(t)}],...n.map(e=>({id:e.id,label:e.name||e.id}))].map((e,n)=>({seriesKey:on(e.id,`schedule`),label:e.label,colorIndex:n,state:e.id===t?`active`:`inactive`}))}function yr(e){return`Unknown schedule (${e})`}function br(){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsx)(`div`,{className:`h-px w-full`,style:{background:`linear-gradient(to right, transparent, var(--border-base), transparent)`}}),(0,J.jsx)(Sr,{title:`Cost assistant`,subtitle:`Review recent spend and tune model profile choices.`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md px-3 py-3 sm:flex-row sm:items-center`,children:[(0,J.jsx)(fr,{prompt:hr,children:`Analyze costs with assistant`}),(0,J.jsx)(fr,{prompt:gr,variant:`ghost`,children:`Optimize settings`})]})})]})}function xr({range:e,onChange:t}){return(0,J.jsx)(`div`,{className:`flex items-center`,children:(0,J.jsx)(De,{value:e,onChange:t,options:pr.map(e=>({value:e.value,label:e.label}))})})}function Sr({title:e,subtitle:t,children:n}){return(0,J.jsxs)(`section`,{className:`flex flex-col gap-3 rounded-md border px-4 py-4`,style:{background:`var(--surface-lift)`,borderColor:`var(--border-base)`},children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`h3`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:e}),t?(0,J.jsx)(`p`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:t}):null]}),n]})}function Cr({query:e,skeleton:t,render:n}){return e.isLoading?(0,J.jsx)(J.Fragment,{children:t}):e.error?(0,J.jsx)(Nr,{message:e.error instanceof Error?e.error.message:`Failed to load usage.`,onRetry:()=>e.refetch()}):e.data?(0,J.jsx)(J.Fragment,{children:n(e.data)}):(0,J.jsx)(J.Fragment,{children:t})}function wr({totals:e}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{style:{fontSize:`30px`,fontWeight:600,lineHeight:1,color:`var(--content-default)`},children:qt(e.totalEstimatedCostUsd)}),(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-secondary)`},children:`Cost`})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:q(e.eventCount)}),(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-secondary)`},children:`LLM Calls`})]})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,J.jsx)(Tr,{label:`Direct Input Tokens`,value:q(e.totalInputTokens)}),(0,J.jsx)(Tr,{label:`Output Tokens`,value:q(e.totalOutputTokens)}),(0,J.jsx)(Tr,{label:`Cache Created`,value:q(e.totalCacheCreationTokens)}),(0,J.jsx)(Tr,{label:`Cache Read`,value:q(e.totalCacheReadTokens)})]})]})}function Tr({label:e,value:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md px-3 py-2`,style:{background:`color-mix(in srgb, var(--border-base) 15%, transparent)`},children:[(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-default)`},children:t}),(0,J.jsx)(`span`,{className:`text-label-medium-default`,style:{color:`var(--content-tertiary)`},children:e})]})}function Er(){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,"aria-hidden":`true`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(Y,{width:140,height:30}),(0,J.jsx)(Y,{width:90,height:12})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(Y,{width:60,height:16}),(0,J.jsx)(Y,{width:60,height:12})]})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:Array.from({length:4}).map((e,t)=>(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md px-3 py-2`,style:{background:`color-mix(in srgb, var(--border-base) 15%, transparent)`},children:[(0,J.jsx)(Y,{width:`50%`,height:12}),(0,J.jsx)(Y,{width:`70%`,height:11})]},t))})]})}function Dr({value:e,onChange:t}){return(0,J.jsx)(`div`,{className:`flex items-center`,children:(0,J.jsx)(De,{value:e,onChange:t,menuAlign:`end`,menuMinWidth:196,options:Xn.map(e=>({value:e.value,label:e.label}))})})}function Or({query:e,groups:t}){let[n,r]=(0,K.useState)(new Set),i=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,J.jsx)(Sr,{title:`Breakdown`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(kr,{label:`% of total`,active:n.has(`pct`),onClick:()=>i(`pct`)}),(0,J.jsx)(kr,{label:`Tokens`,active:n.has(`tokens`),onClick:()=>i(`tokens`)}),(0,J.jsx)(kr,{label:`Turns`,active:n.has(`turns`),onClick:()=>i(`turns`)})]}),(0,J.jsx)(Cr,{query:e,skeleton:(0,J.jsx)(jr,{}),render:e=>(0,J.jsx)(Ar,{groups:t??e.response.breakdown,groupBy:e.groupBy,showPct:n.has(`pct`),showTokens:n.has(`tokens`),showTurns:n.has(`turns`)})})]})})}function kr({label:e,active:t,onClick:n}){return(0,J.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-full border px-2.5 py-1 text-label-medium-default`,style:{borderColor:t?`var(--content-secondary)`:`var(--border-base)`,background:t?`color-mix(in srgb, var(--content-secondary) 15%, transparent)`:`transparent`,color:t?`var(--content-default)`:`var(--content-tertiary)`},children:e})}function Ar({groups:e,groupBy:t,showPct:n,showTokens:r,showTurns:i}){let a=c();if(e.length===0)return(0,J.jsx)(Mr,{title:`No breakdown data`,subtitle:`No usage recorded for this grouping`});let o=e.reduce((e,t)=>e+t.totalEstimatedCostUsd,0);return(0,J.jsx)(`div`,{className:`overflow-hidden rounded-md`,children:(0,J.jsxs)(`table`,{className:`w-full table-fixed`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{style:{borderBottom:`1px solid var(--border-base)`},children:[(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-left text-label-medium-default`,style:{color:`var(--content-tertiary)`},children:`Group`}),r?(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-left text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`35%`},children:`Tokens`}):null,i?(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-right text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`72px`},children:`Turns`}):null,n?(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-right text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`64px`},children:`%`}):null,(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-right text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`100px`},children:`Cost`})]})}),(0,J.jsx)(`tbody`,{children:e.map((e,c)=>{let l=Bn(e),u=Hn(e),d=t===`conversation`?e.groupId:null,f=o>0?Math.round(e.totalEstimatedCostUsd/o*100):0;return(0,J.jsxs)(`tr`,{className:d?`cursor-pointer hover:bg-[var(--surface-hover)]`:void 0,onClick:d?e=>{e.target.closest(`a`)||Je(a,d)}:void 0,style:{borderTop:c===0?`none`:`1px solid var(--border-base)`},children:[(0,J.jsx)(`td`,{className:`min-w-0 px-3 py-2`,style:{color:`var(--content-default)`},children:d?(0,J.jsx)(s,{to:Be.conversation(d),className:`block truncate text-body-medium-lighter`,title:e.group,onClick:e=>{Ft(e)||(e.preventDefault(),Je(a,d))},children:e.group}):(0,J.jsx)(`span`,{className:`block truncate text-body-medium-lighter`,title:e.group,children:e.group})}),r?(0,J.jsx)(`td`,{className:`min-w-0 px-3 py-2`,style:{color:`var(--content-secondary)`},children:(0,J.jsx)(`span`,{className:`block truncate text-body-small-default`,title:l,children:u})}):null,i?(0,J.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2 text-right`,children:(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:e.turnCount==null?`—`:e.turnCount.toLocaleString()})}):null,n?(0,J.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2 text-right`,children:(0,J.jsxs)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:[f,`%`]})}):null,(0,J.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2 text-right`,children:(0,J.jsx)(`span`,{className:`text-body-medium-lighter`,style:{color:`var(--content-default)`},children:qt(e.totalEstimatedCostUsd)})})]},e.groupKey??e.groupId??`${e.group}-${c}`)})})]})})}function jr(){return(0,J.jsx)(`div`,{className:`flex flex-col gap-2`,"aria-hidden":`true`,children:Array.from({length:4}).map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(Y,{width:100,height:14}),(0,J.jsx)(Y,{width:`60%`,height:12}),(0,J.jsx)(Y,{width:50,height:14})]},t))})}function Y({width:e,height:t}){return(0,J.jsx)(`div`,{className:`rounded-sm`,style:{width:typeof e==`number`?`${e}px`:e,height:`${t}px`,background:`color-mix(in srgb, var(--border-base) 40%, transparent)`}})}function Mr({title:e,subtitle:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-1 py-8 text-center`,children:[(0,J.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:e}),(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:t})]})}function Nr({message:e,onRetry:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,J.jsx)(ve,{className:`h-4 w-4 shrink-0`,style:{color:`var(--system-negative-strong, #f87171)`}}),(0,J.jsx)(`span`,{className:`text-body-medium-lighter`,style:{color:`var(--content-default)`},children:e})]}),t?(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`self-start rounded-md border px-3 py-1 text-body-small-default`,style:{background:`var(--surface-lift)`,borderColor:`var(--border-base)`,color:`var(--content-default)`},children:`Retry`}):null]})}function Pr({open:e,onCancel:t,onConfirm:n,confirming:r,lostFeatures:a}){return(0,J.jsx)(W.Root,{open:e,onOpenChange:e=>{!e&&!r&&t()},children:(0,J.jsxs)(W.Content,{size:`md`,hideCloseButton:!0,children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{icon:ve,children:`Downgrade to Base?`})}),(0,J.jsxs)(W.Body,{children:[(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`text-(--content-secondary)`,children:`Downgrading removes the following Pro features:`}),(0,J.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5`,children:a.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,children:e})},e))})]}),(0,J.jsxs)(W.Footer,{children:[(0,J.jsx)(i,{variant:`outlined`,onClick:t,disabled:r,children:`Keep Pro`}),(0,J.jsx)(i,{variant:`danger`,onClick:n,disabled:r,"data-testid":`confirm-downgrade-button`,children:`Confirm Downgrade`})]})]})})}var Fr=`__none__`;function Ir(e){return`${e.label} — ${B(e.price_cents)}`}function Lr({creditTiers:e,selectedCreditTier:t,onCreditTierChange:n,disabled:r=!1}){let i=(0,K.useMemo)(()=>[{value:Fr,label:`No credit bundle — ${B(0)}`},...e.map(e=>({value:e.tier,label:Ir(e)}))],[e]);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(p,{as:`p`,variant:`label-small-default`,className:`text-[var(--content-secondary)]`,children:`Credit bundle`}),(0,J.jsx)(`span`,{title:`A monthly allotment of credits added to your Pro Plan subscription`,children:(0,J.jsx)(ge,{className:`h-3 w-3 text-[var(--content-tertiary)]`})})]}),(0,J.jsx)(De,{"aria-label":`Credit bundle`,placeholder:`Select a credit bundle`,disabled:r,value:t??Fr,onChange:e=>n(e===Fr?null:e),options:i})]})}function Rr({features:e,variant:t,header:n,maxInline:r=3}){return t===`inline`?(0,J.jsx)(J.Fragment,{children:e.slice(0,r).join(`, `)}):(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n&&(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-secondary)]`,children:n}),(0,J.jsx)(`ul`,{className:`flex flex-col gap-2`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,J.jsx)(b,{className:`mt-0.5 h-4 w-4 shrink-0 text-[var(--content-tertiary)]`,"aria-hidden":!0}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,children:e})]},e))})]})}function zr({plan:e,isCurrent:t,onPro:n,cancelAtPeriodEnd:r,isCanceled:a,cancelDate:o,formatGraceDate:s,proTierChangeMode:c,creditTiersEnabled:l,creditTiers:u,displayCreditTier:d,onCreditTierChange:f,selectedMachineTier:h,selectedStorageTier:g,onMachineTierChange:_,onStorageTierChange:v,machineTiersForPicker:y,storageTiersForPicker:b,currentMachinePrice:x,currentStoragePrice:S,currentCreditPriceUnknown:C,proCurrentTotalCents:w,proLiveTotalCents:T,proTotalDelta:E,onboardingLoading:D,tierChangePending:O,machineChanged:k,storageChanged:A,creditChanged:j,tierChangeError:M,upgradePending:N,portalPending:P,onUpgrade:te,onApplyTierChange:ne,onDowngradeClick:re,onKeepPlan:I}){let L=e.id===`pro`,R=e.id===`base`,ie=L&&n&&r&&!a,ae=L&&(!t||t&&c),oe=L&&t&&c;return(0,J.jsx)(m.Root,{className:`flex flex-col bg-[var(--surface-base)]`,children:(0,J.jsxs)(m.Body,{padding:`lg`,className:`max-sm:p-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(`span`,{"aria-hidden":!0,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-[var(--border-base)] bg-[var(--surface-lift)]`,children:L?(0,J.jsx)(Vt,{className:`h-5 w-5 text-[var(--content-default)]`}):(0,J.jsx)(Ut,{className:`h-5 w-5 text-[var(--content-default)]`})}),(0,J.jsxs)(`div`,{className:`flex min-h-6 items-center gap-2`,children:[(0,J.jsx)(p,{as:`h3`,variant:`title-small`,children:e.name}),t&&(0,J.jsx)(Ce,{tone:`positive`,children:`Current`})]}),(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`-mt-2 text-[var(--content-tertiary)]`,children:R?`All you need for a capable assistant`:`More features, more compute, more storage`}),ie&&o&&(0,J.jsxs)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--system-mid-strong)]`,"data-testid":`modal-cancels-on`,children:[`Your plan ends on `,s(o)]}),(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1`,children:R?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(p,{as:`p`,variant:`title-medium`,children:`Free`}),(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Forever`})]}):t&&!(ae&&T!=null)&&(w==null||C)?D?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-lighter`,children:`Loading your plan...`})]}):(0,J.jsx)(p,{as:`p`,variant:`body-medium-lighter`,className:`text-[var(--content-tertiary)]`,"data-testid":`modal-pro-price-unavailable`,children:`Current plan pricing unavailable`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(p,{as:`p`,variant:`title-medium`,"data-testid":`modal-pro-price`,children:ae&&T!=null?(0,J.jsxs)(J.Fragment,{children:[B(T),E!=null&&E!==0&&(0,J.jsxs)(`span`,{className:`ml-1 text-[var(--content-tertiary)]`,children:[`(`,de(E),`)`]})]}):w==null?e.id===`pro`?`From ${B(e.base_price_cents+F(e.machine_tiers)+F(e.storage_tiers))}`:null:`Currently ${B(w)}`}),ae&&E!=null&&E!==0&&(0,J.jsx)(`span`,{title:`Your Pro Plan subscription will change from ${B(w)} to ${B(T)}.`,children:(0,J.jsx)(ge,{className:`h-3 w-3 text-[var(--content-tertiary)]`})})]}),e.id===`pro`&&(0,J.jsxs)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,"data-testid":`modal-pro-base-fee`,children:[ee(e.base_price_cents),` base fee`]})]})}),(0,J.jsx)(Rr,{features:e.included_features,variant:`checklist`}),L&&!l&&(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,"data-testid":`modal-credits-not-included`,children:`*Credits not included`})]}),(0,J.jsxs)(`div`,{className:`mt-4 flex flex-1 flex-col justify-end gap-4`,children:[!t&&L&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),l&&(0,J.jsx)(Lr,{creditTiers:u,selectedCreditTier:d,onCreditTierChange:f,disabled:N}),(0,J.jsx)(z,{machineTiers:y,storageTiers:b,selectedMachineTier:h,selectedStorageTier:g,onMachineTierChange:_,onStorageTierChange:v}),(0,J.jsx)(i,{variant:`primary`,className:`w-full`,onClick:te,disabled:N||!h||!g,"data-testid":`modal-upgrade-to-pro-button`,children:`Upgrade to Pro`})]}),oe&&(D?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-lighter`,children:`Loading your plan...`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),l&&(0,J.jsx)(Lr,{creditTiers:u,selectedCreditTier:d,onCreditTierChange:f,disabled:O}),(0,J.jsx)(z,{machineTiers:y,storageTiers:b,selectedMachineTier:h,selectedStorageTier:g,onMachineTierChange:_,onStorageTierChange:v,currentMachinePriceCents:x,currentStoragePriceCents:S}),M&&(0,J.jsx)(U,{tone:`error`,children:M}),(0,J.jsx)(i,{variant:`primary`,className:`w-full`,onClick:ne,disabled:O||!k&&!A&&!j,"data-testid":`modal-change-tier-button`,children:`Update Plan`})]})),!t&&R&&n&&!r&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),(0,J.jsx)(i,{variant:`outlined`,className:`w-full`,onClick:re,disabled:P,"data-testid":`modal-downgrade-to-base-button`,children:`Downgrade to Base`})]}),ie&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),(0,J.jsx)(i,{variant:`outlined`,className:`w-full`,onClick:I,disabled:P,"data-testid":`modal-keep-plan-button`,children:`Keep your Plan`})]})]})]})})}function Br({open:e,onClose:t,onTierUpgraded:n}){let r=l(),a=u(Ze()),o=u(bt()),s=d(mt()),c=d(xt()),f=d(yt()),m=d(Tt()),h=k(C(o.data)),[_,v]=(0,K.useState)(`plans`),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(null),[w,E]=(0,K.useState)(null),[O,A]=(0,K.useState)(void 0);(0,K.useEffect)(()=>Ke(()=>{r.invalidateQueries({queryKey:Et()}),r.invalidateQueries({queryKey:ht()}),r.invalidateQueries({queryKey:pt()}),t()}),[r,t]);let ee=o.data?.plan_id,P=ee===`pro`,te=u({...wt(),enabled:P}),F=te.data?.max_machine_tier??null,I=te.data?.selected_storage_tier??null,L=te.data?.selected_storage_gib??null,R=o.data?.cancel_at_period_end===!0||!!o.data?.cancel_at,ie=o.data?.status===`canceled`,ae=T(o.data),se=o.data?.status,ce=se!=null&&ne.has(se),le=P&&ce&&!R&&!ie,z=a.data?.plans.find(e=>e.id===`pro`),ue=z?.credit_tiers??[],B=ue.length>0,de=o.data?.selected_credit_tier??null,V=e=>ue.find(t=>t.tier===e)?.price_cents??0,fe=V(de),pe=de!=null&&!ue.some(e=>e.tier===de),me=O===void 0?de:O,he=V(me),ge=z?.machine_tiers??[],_e=le&&L!=null?(z?.storage_tiers??[]).map(e=>e.storage_gib<L?{...e,disabled:!0}:e):z?.storage_tiers??[];(0,K.useEffect)(()=>{if(!e){S(null),E(null),A(void 0);return}if(z){if(le){if(F==null||I==null)return;S(e=>N(ge,e??F)),E(e=>N(_e,e??I)),A(e=>re(ue,e,de));return}S(e=>N(z.machine_tiers,e)),E(e=>N(z.storage_tiers,e)),A(e=>re(ue,e,null))}},[e,z,le,F,I,de]);let ye=a.data?.plans.find(e=>e.id===`base`),be=new Set(ye?.included_features??[]),xe=(z?.included_features??[]).filter(e=>!be.has(e)),Se=()=>{if(!s.isPending){if(!x||!w){G.error(`Pick a machine and storage tier to continue.`,{id:`pro-upgrade-error`});return}s.mutate({body:{target_plan_id:`pro`,confirm:!0,machine_tier:x,storage_tier:w,credit_tier:me,return_target:j()}},{onSuccess:e=>{if(e.checkout_url){D({kind:`custom`,machineTier:x,storageTier:w,creditTier:me}),Ge(e.checkout_url);return}if(e.status===`no_op`){G.info(`You're already on Pro.`,{id:`pro-upgrade`}),t();return}G.error(e.message??`Failed to start upgrade. Please try again.`,{id:`pro-upgrade-error`})},onError:e=>{G.error(oe(e,`Failed to start upgrade. Please try again.`),{id:`pro-upgrade-error`})}})}},Ce=()=>{h.isPending||(v(`plans`),h.mutate({}))},we=()=>{r.invalidateQueries({queryKey:Et()}),r.invalidateQueries({queryKey:pt()}),r.invalidateQueries({queryKey:ht()})},Te=c.isPending||f.isPending||m.isPending,Ee=x!=null&&x!==F,De=w!=null&&w!==I,Oe=B&&O!==void 0&&O!==de,ke=e=>ge.find(t=>t.tier===e)?.price_cents??null,Ae=e=>_e.find(t=>t.tier===e)?.price_cents??null,je=ke(x),Me=Ae(w),Ne=ke(F),Pe=Ae(I),Fe=Ee&&je!=null&&Ne!=null&&je<Ne,Ie=()=>{if(Te)return;let e=[];Ee&&x&&e.push(new Promise(e=>{c.mutate({body:{machine_tier:x}},{onSuccess:()=>e({dimension:`machine`,ok:!0}),onError:t=>e({dimension:`machine`,ok:!1,error:t})})})),De&&w&&e.push(new Promise(e=>{f.mutate({body:{storage_tier:w}},{onSuccess:()=>e({dimension:`storage`,ok:!0}),onError:t=>e({dimension:`storage`,ok:!1,error:t})})})),Oe&&e.push(new Promise(e=>{m.mutate({body:{credit_tier:me}},{onSuccess:()=>e({dimension:`credit`,ok:!0}),onError:t=>e({dimension:`credit`,ok:!1,error:t})})})),Promise.all(e).then(e=>{we();let r=e.some(e=>e.ok&&e.dimension===`storage`),i=e.some(e=>e.ok&&e.dimension===`machine`)&&!Fe,a=(r||i)&&!!n,o=e.filter(e=>!e.ok);if(o.length>0){let e=o.map(e=>oe(e.error,`Failed to update ${e.dimension} tier.`)).join(` `);G.error(e,{id:`pro-tier-change-error`}),a&&(t(),n());return}a?(t(),n()):G.success(Oe&&!Ee&&!De?`Credit bundle updated.`:`Plan updated.`,{id:`pro-tier-change`})})},Le=()=>{if(!Te){if(Fe){b(!0);return}Ie()}},Re=()=>{b(!1),Ie()},ze=e=>je!=null&&Me!=null?e.base_price_cents+je+Me+he:null,Be=e=>Ne!=null&&Pe!=null?e.base_price_cents+Ne+Pe+fe:null,Ve=c.isError||f.isError||m.isError?oe(c.error??f.error??m.error,`Failed to update plan. Please try again.`):null,He=a.isLoading||o.isLoading,Ue=a.isError||o.isError||!a.data||!o.data;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(W.Root,{open:e,onOpenChange:e=>{e||(v(`plans`),t())},children:(0,J.jsx)(W.Content,{size:_===`plans`?`lg`:`md`,children:_===`downgrade-confirm`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{icon:ve,children:`Downgrade to Base?`})}),(0,J.jsxs)(W.Body,{children:[(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`text-(--content-secondary)`,children:`Downgrading removes the following Pro features:`}),(0,J.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5`,children:xe.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,children:e})},e))})]}),(0,J.jsxs)(W.Footer,{children:[(0,J.jsx)(i,{variant:`ghost`,onClick:()=>v(`plans`),disabled:h.isPending,leftIcon:(0,J.jsx)(g,{className:`h-4 w-4`}),children:`Back`}),(0,J.jsx)(i,{variant:`danger`,onClick:Ce,disabled:h.isPending,"data-testid":`confirm-downgrade-button`,children:`Confirm Downgrade`})]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{className:`sr-only`,children:`Upgrade Plan`})}),(0,J.jsx)(W.Body,{children:He?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-lighter`,children:`Loading plans...`})]}):Ue?(0,J.jsx)(U,{tone:`error`,children:`Failed to load plans. Please try again later.`}):(0,J.jsxs)(`div`,{className:`space-y-4 sm:space-y-6`,children:[(0,J.jsxs)(`div`,{className:`space-y-2 pb-2 pt-4 text-center`,children:[(0,J.jsx)(p,{as:`p`,variant:`title-medium`,children:`Your Assistant, Your Way`}),(0,J.jsx)(p,{as:`p`,variant:`body-medium-lighter`,className:`text-[var(--content-secondary)]`,children:`Choose the plan that works best for you and your assistant.`})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:a.data.plans.map(e=>{let t=e.id===ee,n=e.id===`pro`&&z?ze(z):null,r=e.id===`pro`&&z?Be(z):null;return(0,J.jsx)(zr,{plan:e,isCurrent:t,onPro:P,cancelAtPeriodEnd:R,isCanceled:ie,cancelDate:ae,formatGraceDate:M,proTierChangeMode:le,creditTiersEnabled:B,creditTiers:ue,displayCreditTier:me,onCreditTierChange:A,selectedMachineTier:x,selectedStorageTier:w,onMachineTierChange:S,onStorageTierChange:E,machineTiersForPicker:ge,storageTiersForPicker:_e,currentMachinePrice:Ne,currentStoragePrice:Pe,currentCreditPriceUnknown:pe,proCurrentTotalCents:r,proLiveTotalCents:n,proTotalDelta:n!=null&&r!=null?n-r:null,onboardingLoading:te.isLoading,tierChangePending:Te,machineChanged:Ee,storageChanged:De,creditChanged:Oe,tierChangeError:Ve,upgradePending:s.isPending,portalPending:h.isPending,onUpgrade:Se,onApplyTierChange:Le,onDowngradeClick:()=>v(`downgrade-confirm`),onKeepPlan:()=>h.mutate({})},e.id)})})]})}),(0,J.jsxs)(W.Footer,{className:`relative items-center`,children:[(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`pointer-events-none absolute inset-x-0 text-center text-[var(--content-tertiary)]`,children:(0,J.jsx)(`span`,{className:`pointer-events-auto`,children:`You can change or cancel your plan at any time from billing settings.`})}),(0,J.jsx)(`div`,{className:`ml-auto`,children:(0,J.jsx)(i,{variant:`outlined`,onClick:t,"data-testid":`modal-cancel-button`,children:`Cancel`})})]})]})})}),(0,J.jsx)(Pr,{open:y,onCancel:()=>b(!1),onConfirm:Re,confirming:Te,lostFeatures:[`Reduced CPU and memory for your assistant — it will resize to the smaller compute profile.`]})]})}function Vr({open:e,confirming:t,onCancel:n,onConfirm:r}){return(0,J.jsx)(Ee,{open:e,title:`Disable automatic top-ups?`,message:`Auto top-ups will stop. Any saved payment method stays on file.`,confirmLabel:t?`Disabling…`:`Disable`,cancelLabel:`Keep enabled`,destructive:!0,onConfirm:r,onCancel:n})}var Hr={threshold_usd:`100`,amount_usd:`10`,monthly_cap_usd:``};function Ur(e){if(e===``||e===`-`)return e;let t=parseFloat(e);return Number.isFinite(t)?String(Math.trunc(t)):``}function Wr(e){let t={},n=parseFloat(e.threshold_usd),r=parseFloat(e.amount_usd);if((!Number.isFinite(r)||r<10||r>500)&&(t.amount_usd=`Must be between $10 and $500`),(!Number.isFinite(n)||n<1||n>100)&&(t.threshold_usd=`Must be between $1 and $100`),e.monthly_cap_usd!==``){let n=parseFloat(e.monthly_cap_usd);!Number.isFinite(n)||n<25||n>1e4?t.monthly_cap_usd=`Must be between $25 and $10,000`:Number.isFinite(r)&&n<r&&(t.monthly_cap_usd=`Must be at least the top-up amount`)}return t}function Gr(e,t,n,r){if(n[e])return n[e];if(r)return t[e]}function Kr({initialValues:e=Hr,submitting:t,serverErrors:n,onSave:r,onCancel:a}){let[o,s]=(0,K.useState)(e),[c,l]=(0,K.useState)({threshold_usd:!1,amount_usd:!1,monthly_cap_usd:!1}),u=Wr(o),d=e=>t=>{s(n=>({...n,[e]:t.target.value}))},f=e=>()=>{l(t=>({...t,[e]:!0})),s(t=>({...t,[e]:Ur(t[e])}))},p=e=>Gr(e,u,n,c[e]);return(0,J.jsx)(`div`,{className:`mt-4`,children:(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,J.jsx)(`div`,{className:`min-w-[10rem] flex-1`,children:(0,J.jsx)(we,{type:`number`,step:`1`,label:`Auto-reload when balance below`,value:o.threshold_usd,onChange:d(`threshold_usd`),onBlur:f(`threshold_usd`),errorText:p(`threshold_usd`),"data-testid":`auto-top-up-threshold-input`,fullWidth:!0})}),(0,J.jsx)(`div`,{className:`min-w-[10rem] flex-1`,children:(0,J.jsx)(we,{type:`number`,step:`1`,label:`Auto-reload amount`,value:o.amount_usd,onChange:d(`amount_usd`),onBlur:f(`amount_usd`),errorText:p(`amount_usd`),"data-testid":`auto-top-up-amount-input`,fullWidth:!0})}),(0,J.jsx)(`div`,{className:`min-w-[10rem] flex-1`,children:(0,J.jsx)(we,{type:`number`,step:`1`,label:`Monthly spending cap`,helperText:`Pauses auto top-ups for the rest of the month once spending reaches this amount. Manual purchases also count toward the total. Leave empty for no limit.`,value:o.monthly_cap_usd,onChange:d(`monthly_cap_usd`),onBlur:f(`monthly_cap_usd`),errorText:p(`monthly_cap_usd`),"data-testid":`auto-top-up-cap-input`,fullWidth:!0})}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pt-[18px]`,children:[(0,J.jsx)(i,{variant:`outlined`,onClick:a,disabled:t,children:`Cancel`}),(0,J.jsx)(i,{variant:`primary`,onClick:()=>{l({threshold_usd:!0,amount_usd:!0,monthly_cap_usd:!0});let e={threshold_usd:Ur(o.threshold_usd),amount_usd:Ur(o.amount_usd),monthly_cap_usd:Ur(o.monthly_cap_usd)};s(e);let t=Wr(e);if(Object.keys(t).length!==0)return;let n=e=>e===``?``:`${parseInt(e,10)}.00`;r({threshold_usd:n(e.threshold_usd),amount_usd:n(e.amount_usd),monthly_cap_usd:e.monthly_cap_usd===``?``:n(e.monthly_cap_usd)})},disabled:t,"data-testid":`auto-top-up-save-button`,children:`Save`})]})]})})}var qr=t(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),Jr=t(((e,t)=>{var n=qr();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),X=e(t(((e,t)=>{t.exports=Jr()()}))(),1);function Yr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Xr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Yr(Object(n),!0).forEach(function(t){Qr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Yr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Zr(e){"@babel/helpers - typeof";return Zr=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Zr(e)}function Qr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $r(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,a;for(a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}function ei(e,t){if(e==null)return{};var n=$r(e,t),r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)r=a[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function ti(e,t){return ni(e)||ri(e,t)||ii(e,t)||oi()}function ni(e){if(Array.isArray(e))return e}function ri(e,t){var n=e&&(typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`]);if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function ii(e,t){if(e){if(typeof e==`string`)return ai(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ai(e,t)}}function ai(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function oi(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
2
+ import{o as e,t}from"./chunk-jRWAZmH_.js";import{t as n}from"./capture-error-Bj8_eutd.js";import{t as r}from"./react-BFJW0bSv.js";import{t as i}from"./button-Dy5001j6.js";import{t as a}from"./preload-helper-Cv2QeVDK.js";import{m as o,t as s,u as c}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as l}from"./QueryClientProvider-CMu7CkQU.js";import{t as u}from"./useQuery-Bz-fbQ-m.js";import{t as d}from"./useMutation-CXGTrp4W.js";import{t as f}from"./jsx-runtime-D3ZM-ToX.js";import{t as p}from"./typography-DEI9Ra9z.js";import{t as m}from"./card-DRIctGVs.js";import{t as h}from"./createLucideIcon-CAM1RhH8.js";import{t as g}from"./arrow-left-C2ylPLHq.js";import{t as _}from"./check-sC49_hjU.js";import{t as v}from"./chevron-down-B5A-0g8A.js";import{t as y}from"./chevron-up-2Qqarz0p.js";import{t as b}from"./circle-check-CjGnAahM.js";import{t as x}from"./coins-Hrmb9tmj.js";import{A as S,C,D as w,E as T,I as E,L as D,M as O,O as k,P as A,S as j,T as M,_ as N,b as ee,c as P,d as te,f as ne,g as re,h as F,i as I,j as L,l as R,m as ie,n as ae,p as oe,s as se,t as ce,u as le,v as z,w as ue,x as B,y as de}from"./use-checkout-dismiss-refresh-5bSduG7s.js";import{n as V,o as fe}from"./list-row-B1wPb2Au.js";import{t as pe}from"./credit-card-C1RL73Rt.js";import{t as me}from"./download-CywcQLB2.js";import{t as he}from"./external-link-CS0aVYGt.js";import{t as ge}from"./info-vgPTIsGI.js";import{t as H}from"./loader-circle-XREx3i4W.js";import{t as _e}from"./sparkles-Ccrj7hxd.js";import{t as ve}from"./triangle-alert-CQfiAg_t.js";import{t as ye}from"./users-iLvfYFOP.js";import{t as be}from"./x-JBAsSOmg.js";import{t as U}from"./notice-BMK7xqUw.js";import{M as xe,r as Se}from"./src-te3YTBG-.js";import{t as Ce}from"./tag-NXcyiTkK.js";import{t as we}from"./input-hw3el2GJ.js";import{t as Te}from"./toggle-lfnhEAcN.js";import{t as W}from"./modal-BR4CUFBd.js";import{n as G}from"./toast-LgLp4obE.js";import{t as Ee}from"./confirm-dialog-UYFm4osC.js";import{t as De}from"./dropdown-BCfnSdIZ.js";import{Or as Oe}from"./sdk.gen-BVAVE6A_.js";import{It as ke,Lt as Ae,Rt as je,c as Me,d as Ne,ht as Pe,zt as Fe}from"./react-query.gen-r3I6j8-1.js";import{t as Ie}from"./api-errors-CFiCT7Ap.js";import{o as Le}from"./auth-store-FtoML9k1.js";import{lt as Re,ut as ze}from"./sdk.gen-BIu1DgTs.js";import{u as Be}from"./routes-vE-2hncW.js";import{i as Ve,r as He,t as Ue}from"./use-platform-gate-CiX10TX6.js";import{t as We}from"./use-is-org-ready-1-Hv4dF3.js";import{n as Ge,r as Ke}from"./browser-DLWdxyJA.js";import{n as qe,t as Je}from"./conversation-navigation-KFwqoqT9.js";import{n as Ye}from"./use-is-mobile-Bz2l7wPL.js";import{t as Xe}from"./effective-timezone-qiooajmO.js";import{$ as Ze,B as Qe,G as $e,H as et,J as tt,K as nt,L as rt,Mt as it,Q as at,R as ot,U as st,V as ct,W as lt,X as ut,Y as dt,Z as ft,ct as pt,dt as mt,et as ht,ft as gt,gt as _t,ht as vt,it as yt,lt as bt,nt as xt,pt as St,q as Ct,st as wt,tt as Tt,ut as Et,wt as Dt,z as Ot}from"./react-query.gen-Mwd5l-vZ.js";import{t as kt}from"./use-effective-timezone-LqzBqHBy.js";import{t as At}from"./misc-DckBb5zz.js";import{t as jt}from"./platform-login-notice-BvVdKM0X.js";import{t as Mt}from"./use-active-assistant-id-CXhDyK7y.js";import{t as Nt}from"./format-date-C5pKGCAG.js";import{t as Pt}from"./add-credits-modal-CtdZCpuZ.js";import{t as Ft}from"./link-click-kJxAxKHH.js";import{t as It}from"./schedules-CKGVEPqD.js";import{i as Lt,n as Rt,r as zt,t as Bt}from"./profile-metadata-DgZjbPj8.js";var Vt=h(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),Ht=h(`target`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Ut=h(`tree-palm`,[[`path`,{d:`M13 8c0-2.76-2.46-5-5.5-5S2 5.24 2 8h2l1-1 1 1h4`,key:`foxbe7`}],[`path`,{d:`M13 7.14A5.82 5.82 0 0 1 16.5 6c3.04 0 5.5 2.24 5.5 5h-3l-1-1-1 1h-3`,key:`18arnh`}],[`path`,{d:`M5.89 9.71c-2.15 2.15-2.3 5.47-.35 7.43l4.24-4.25.7-.7.71-.71 2.12-2.12c-1.95-1.96-5.27-1.8-7.42.35`,key:`ywahnh`}],[`path`,{d:`M11 15.5c.5 2.5-.17 4.5-1 6.5h4c2-5.5-.5-12-1-14`,key:`ft0feo`}]]),K=e(r(),1);function Wt(e){return e.get(`tab`)===`billing`||e.has(`adjust_plan`)||e.has(`pro_onboarding`)||e.has(`billing_status`)||e.has(`session_id`)}function Gt(e,t){return e===`full`?!0:e===`disabled`?Wt(t):!1}function Kt(e){if(!e)return{};let t={};for(let n of e.callSites)!n.id||!n.displayName||(t[n.id]={id:n.id,displayName:n.displayName,description:n.description,domain:n.domain});return t}function q(e){return Number.isFinite(e)?Math.round(e).toLocaleString():`0`}function qt(e){return!Number.isFinite(e)||e===0?`$0.00`:`$${e.toFixed(2)}`}var Jt=`model`,Yt={model:`Model`,task:`Action`,profile:`Profile`},Xt=[{value:`model`,label:Yt.model},{value:`task`,label:Yt.task},{value:`profile`,label:Yt.profile}];function Zt(e){return e===`model`||e===`task`||e===`profile`}function Qt(e){switch(e){case`model`:return`model`;case`task`:return`call_site`;case`profile`:return`inference_profile`}}function $t(e){switch(e){case`model`:return`model`;case`task`:return`llm_call_site`;case`profile`:return`inference_profile`}}function en(e,t,n){if(e===`task`){let e=t.groupKey;return e?n.callSites?.[e]?.displayName??t.group:t.group}if(e===`profile`){let e=t.groupKey;return e?n.profiles?.[e]?.displayName??t.group:t.group||`Default / Unset`}return t.group}function tn(e,t,n){return!e||e.length===0?[]:e.map(e=>{let r=en(t,e,n);return r===e.group?e:{...e,group:r}})}var nn=6,rn=`value:`,an=`null:`;function on(e,t=`schedule`){return e===null?`${an}${Zt(t)?Qt(t):t}`:`${rn}${e}`}function sn(e){return[...e].sort((e,t)=>{if(e.date!==t.date)return e.date<t.date?-1:1;let n=fn(e.bucketId),r=fn(t.bucketId);return n===r?e.bucketId===t.bucketId?0:e.bucketId<t.bucketId?-1:1:n-r})}function cn(e){return e.map(e=>({bucketId:e.bucketId,date:e.date,displayLabel:e.displayLabel,totalInputTokens:e.totalInputTokens,totalOutputTokens:e.totalOutputTokens,totalEstimatedCostUsd:e.totalEstimatedCostUsd,eventCount:e.eventCount,groups:{}}))}function ln(e,t,n){return t!==`task`&&t!==`profile`?[...e]:e.map(e=>{let r=!1,i={};for(let[a,o]of Object.entries(e.groups)){let e=en(t,dn(o),n);e===o.group?i[a]=o:(r=!0,i[a]={...o,group:e})}return r?{...e,groups:i}:e})}function un(e){let t=new Map;for(let n of e)for(let[e,r]of Object.entries(n.groups)){let n=t.get(e);t.set(e,{label:n?.label??r.group,totalEstimatedCostUsd:(n?.totalEstimatedCostUsd??0)+r.totalEstimatedCostUsd})}let n=Array.from(t.entries()).sort(([e,t],[n,r])=>t.totalEstimatedCostUsd===r.totalEstimatedCostUsd?t.label===r.label?e===n?0:e<n?-1:1:t.label<r.label?-1:1:r.totalEstimatedCostUsd-t.totalEstimatedCostUsd).map(([e,t],n)=>({seriesKey:e,label:t.label,totalEstimatedCostUsd:t.totalEstimatedCostUsd,colorIndex:n}));return{items:n,visibleItems:n.slice(0,nn)}}function dn(e){return{group:e.group,groupId:e.groupKey,groupKey:e.groupKey,totalInputTokens:e.totalInputTokens,totalOutputTokens:e.totalOutputTokens,totalCacheCreationTokens:0,totalCacheReadTokens:0,totalEstimatedCostUsd:e.totalEstimatedCostUsd,eventCount:e.eventCount,turnCount:null}}function fn(e){let t=e.lastIndexOf(`|`);if(t<0)return 0;let n=Number(e.slice(t+1));return Number.isFinite(n)?n:0}var J=f(),pn=140,mn=40,hn=28,gn=2,_n=2,vn=1e-6,yn=12,bn=220,xn=56,Sn=[40,80,60,100,50,70,30],Cn=[18,24,28,35,42,50,64,78,92,106,118,96,84,74,68,80,88,72,56,48,40,34,26,20],wn=[`var(--usage-trend-stack-positive, var(--system-positive-strong, #10b981))`,`var(--usage-trend-stack-info, var(--system-info-strong, #3b82f6))`,`var(--usage-trend-stack-mid, var(--system-mid-strong, #f59e0b))`,`var(--usage-trend-stack-secondary, var(--content-secondary, #6b7280))`,`var(--usage-trend-stack-negative, var(--system-negative-strong, #f87171))`,`var(--usage-trend-stack-tertiary, var(--content-tertiary, #9ca3af))`];function Tn(e){return wn[e%wn.length]}function En(e){return e.displayLabel?e.displayLabel:e.date}function Dn(e,t){let n=e+yn,r=t+yn;return n+bn>window.innerWidth&&(n=e-bn-yn),r+xn>window.innerHeight&&(r=t-xn-yn),{x:n,y:r}}function On({buckets:e,isHourly:t,legendItems:n}){let[r,i]=(0,K.useState)(null),a=(0,K.useMemo)(()=>sn(e),[e]),o=(0,K.useMemo)(()=>un(e),[e]),s=n??o.items,c=n??o.visibleItems,l=(0,K.useMemo)(()=>a.reduce((e,t)=>Math.max(e,t.totalEstimatedCostUsd),0),[a]),u=(0,K.useCallback)((e,t)=>{let n=Dn(e.clientX,e.clientY);i({...t,x:n.x,y:n.y})},[]),d=(0,K.useCallback)(()=>i(null),[]);if(a.length===0){let e=(0,J.jsx)(Nn,{title:t?`No hourly data`:`No daily data`,subtitle:`No usage recorded in this time range`});return c.length===0?e:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e,(0,J.jsx)(Mn,{items:c})]})}let f=t?hn:mn;return(0,J.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsx)(`div`,{className:`flex items-end gap-2`,style:{height:`${pn}px`},"aria-hidden":`true`,children:a.map(e=>{let t=l>0?e.totalEstimatedCostUsd/l:0,r=Math.max(gn,pn*t);return(0,J.jsx)(`div`,{className:`flex items-end`,style:{width:`${f}px`,minWidth:`${f}px`,height:`${r}px`,opacity:e.totalEstimatedCostUsd>0?1:.3},title:`${En(e)}: ${qt(e.totalEstimatedCostUsd)}`,"data-usage-series-bar":e.bucketId,children:(0,J.jsx)(An,{bucket:e,height:r,legendItems:s,hasLegendOverride:n!=null,onSegmentHover:u,onSegmentLeave:d})},e.bucketId)})}),(0,J.jsx)(`div`,{className:`flex items-start gap-2`,children:a.map(e=>(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5`,style:{width:`${f}px`,minWidth:`${f}px`},children:[(0,J.jsx)(`span`,{className:`truncate text-[10px]`,style:{color:`var(--content-secondary)`},children:qt(e.totalEstimatedCostUsd)}),(0,J.jsx)(`span`,{className:`truncate text-[10px]`,style:{color:`var(--content-tertiary)`},children:En(e)})]},e.bucketId))}),c.length>0?(0,J.jsx)(Mn,{items:c}):null]}),r?(0,J.jsx)(jn,{tooltip:r}):null]})}function kn({isHourly:e}){let t=e?Cn:Sn,n=e?hn:mn;return(0,J.jsx)(`div`,{className:`flex items-end gap-2`,style:{height:`${pn}px`},"aria-hidden":`true`,children:t.map((e,t)=>(0,J.jsx)(`div`,{className:`rounded-sm`,style:{width:`${n}px`,height:`${e}px`,background:`color-mix(in srgb, var(--border-base) 40%, transparent)`}},t))})}function An({bucket:e,height:t,legendItems:n,hasLegendOverride:r,onSegmentHover:i,onSegmentLeave:a}){let o=Object.keys(e.groups).length>0,s=n.filter(e=>(e.state??`active`)===`active`).flatMap(t=>{let n=e.groups[t.seriesKey];return!n||n.totalEstimatedCostUsd<=0?[]:[{item:t,value:n}]});if(s.length===0&&!o&&!r){let n={label:`Total`,bucketLabel:En(e),cost:qt(e.totalEstimatedCostUsd)};return(0,J.jsx)(`div`,{className:`w-full rounded-sm`,title:`${n.label}: ${n.cost}`,onMouseEnter:e=>i(e,n),onMouseMove:e=>i(e,n),onMouseLeave:a,style:{height:`${t}px`,background:Tn(0)},"data-usage-series-segment-label":n.label,"data-usage-fallback-segment":`true`})}return s.length===0?null:(0,J.jsx)(`div`,{className:`flex w-full flex-col-reverse overflow-hidden rounded-sm`,style:{height:`${t}px`},"data-usage-series-stack":e.bucketId,children:s.map(({item:n,value:r})=>{let o={label:n.label,bucketLabel:En(e),cost:qt(r.totalEstimatedCostUsd)};return(0,J.jsx)(`div`,{title:`${o.label}: ${o.cost}`,onMouseEnter:e=>i(e,o),onMouseMove:e=>i(e,o),onMouseLeave:a,style:{height:`${Math.max(_n,t*r.totalEstimatedCostUsd/Math.max(e.totalEstimatedCostUsd,vn))}px`,background:Tn(n.colorIndex)},"data-usage-series-segment":n.seriesKey,"data-usage-series-segment-label":n.label,"data-usage-series-color-index":n.colorIndex},n.seriesKey)})})}function jn({tooltip:e}){return(0,J.jsxs)(`div`,{className:`pointer-events-none fixed z-50 max-w-[220px] rounded-md border px-2 py-1 shadow-xl`,style:{left:`${e.x}px`,top:`${e.y}px`,background:`var(--surface-overlay, var(--surface-lift))`,borderColor:`var(--border-base)`},"aria-hidden":`true`,children:[(0,J.jsx)(`div`,{className:`truncate text-body-small-default`,style:{color:`var(--content-default)`},children:e.label}),(0,J.jsxs)(`div`,{className:`truncate text-body-small-default`,style:{color:`var(--content-tertiary)`},children:[e.bucketLabel,` · `,e.cost]})]})}function Mn({items:e}){return(0,J.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 pt-1`,children:e.map(e=>{let t=e.state??`active`,n=t===`inactive`;return(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,"data-usage-legend-state":t,children:[(0,J.jsx)(`span`,{className:`h-[7px] w-[7px] shrink-0 rounded-full`,style:{background:n?`var(--content-tertiary)`:Tn(e.colorIndex),opacity:n?.45:1},"aria-hidden":`true`,"data-usage-series-color-index":e.colorIndex}),(0,J.jsx)(`span`,{className:n?`truncate text-[10px] line-through`:`truncate text-[10px]`,style:{color:`var(--content-tertiary)`,opacity:n?.65:1},children:e.label})]},e.seriesKey)})})}function Nn({title:e,subtitle:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-md py-12 text-center`,style:{color:`var(--content-tertiary)`},children:[(0,J.jsx)(`p`,{className:`text-body-medium-default`,style:{color:`var(--content-secondary)`},children:e}),(0,J.jsx)(`p`,{className:`mt-1 text-body-small-default`,children:t})]})}function Pn(e){return Zt(e)?Qt(e):e}function Fn(e){return zn({from:e.from,to:e.to},e.scheduleId)}function In(e){return zn({from:e.from,to:e.to,...e.granularity?{granularity:e.granularity}:{},...e.tz?{tz:e.tz}:{}},e.scheduleId)}function Ln(e){return zn({from:e.from,to:e.to,groupBy:Pn(e.groupBy)},e.scheduleId)}function Rn(e){return zn({from:e.from,to:e.to,granularity:e.granularity,groupBy:Pn(e.groupBy),...e.tz?{tz:e.tz}:{}},e.scheduleId)}function zn(e,t){return t?{...e,scheduleId:t}:e}function Bn(e){return[`${q(e.totalInputTokens)} direct`,`${q(e.totalCacheCreationTokens)} cache created`,`${q(e.totalCacheReadTokens)} cache read`,`${q(e.totalOutputTokens)} out`].join(` / `)}function Vn(e){return!Number.isFinite(e)||e===0?`0`:e>=1e6||e>=999950&&e<1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toLocaleString()}function Hn(e){return`${Vn(e.totalInputTokens+e.totalCacheCreationTokens+e.totalCacheReadTokens)} in / ${Vn(e.totalOutputTokens)} out`}var Un=`task`,Wn=`model`,Gn=new Set([400,404,422]),Kn=3,qn=new Set([`today`,`yesterday`,`7d`,`30d`,`90d`,`all`]),Jn=new Set([`actor`,`provider`,`model`,`conversation`,`task`,`profile`,`schedule`]),Yn={task:Yt.task,profile:Yt.profile,model:Yt.model,provider:`Provider`,actor:`Actor`,conversation:`Conversation`,schedule:`Schedule`},Xn=[{value:`task`,label:Yn.task},{value:`profile`,label:Yn.profile},{value:`model`,label:Yn.model},{value:`provider`,label:Yn.provider},{value:`schedule`,label:Yn.schedule},{value:`conversation`,label:Yn.conversation}];function Zn(e){let t=e.get(`range`),n=e.get(`groupBy`),r=tr(n)?n:Un;return{range:er(t)?t:`7d`,groupBy:r,scheduleId:r===`schedule`?Qn(e):void 0}}function Qn(e){let t=e.get(`scheduleId`);if(!(!t||t.trim().length===0))return t}function $n(e,t){let n=new URLSearchParams(e);return t.range!==void 0&&n.set(`range`,t.range),t.groupBy!==void 0&&n.set(`groupBy`,t.groupBy),t.scheduleId!==void 0&&(t.scheduleId===null||t.scheduleId.trim().length===0?n.delete(`scheduleId`):n.set(`scheduleId`,t.scheduleId)),n.get(`groupBy`)!==`schedule`&&n.delete(`scheduleId`),n}function er(e){return e!=null&&qn.has(e)}function tr(e){return e!=null&&Jn.has(e)}function nr(e){return e!==`conversation`}function rr(e,t){return e!==`task`&&e!==`profile`?!1:ar(t)}function ir(e,t){return!ar(t)&&e<Kn}function ar(e){return e instanceof Ie&&Gn.has(e.status)}function or(e,t){let n=e===`hourly`?`Hourly Trend`:`Daily Trend`;return!t||t===`conversation`?n:`${n} by ${Yn[t]}`}function sr({requestedGranularity:e,isLoading:t,buckets:n}){return e===`hourly`&&(t||!n||n.length===0||n.some(cr))?`hourly`:`daily`}function cr(e){return e.bucketId.includes(`|`)||lr(e.date)}function lr(e){return/^\d{4}-\d{2}-\d{2} ([01]\d|2[0-3]):00$/.test(e)}function ur(e,t,n=Date.now()){return zt(e,t,n)}function dr(e){return e===`today`||e===`yesterday`?`hourly`:`daily`}function fr({prompt:e,children:t,variant:n=`outlined`,size:r=`regular`,className:a}){let o=c(),s=(0,K.useCallback)(()=>{qe(o,{prompt:e})},[o,e]);return(0,J.jsx)(i,{variant:n,size:r,leftIcon:(0,J.jsx)(_e,{}),onClick:s,className:a,children:t})}var pr=[{value:`today`,label:`Today`},{value:`yesterday`,label:`Yesterday`},{value:`7d`,label:`Last 7 days`},{value:`30d`,label:`Last 30 days`},{value:`90d`,label:`Last 90 days`},{value:`all`,label:`All time`}],mr=300*1e3,hr=[`Please load the llm-cost-optimizer skill.`,`Analyze my recent LLM usage and explain the biggest cost contributors by call site, model, and profile.`,`Check my current llm.default, llm.callSites, and llm.profiles.`,`Give me a concise summary of what is driving cost and what you would optimize first.`,`Do not change config yet.`].join(` `),gr=[`Please load the llm-cost-optimizer skill.`,`Analyze my recent LLM usage and current LLM config, then recommend the safest cost-optimization changes.`,`If changes are clearly safe, show me the exact config commands you would run and ask for confirmation before applying them.`].join(` `);function _r({assistantId:e}){let[t,n]=o(),{range:r,groupBy:i,scheduleId:a}=(0,K.useMemo)(()=>Zn(t),[t]),s=kt(),c=(0,K.useCallback)(e=>{n(t=>$n(t,e),{replace:!0})},[n]),l=(0,K.useMemo)(()=>ur(r,s),[r,s]),d=(0,K.useMemo)(()=>dr(r),[r]),f=u({queryKey:Pe({path:{assistant_id:e}}),queryFn:()=>It(e),staleTime:1e4}),p=(0,K.useCallback)(e=>{c({range:e})},[c]),m=u({...Fe({path:{assistant_id:e},query:Fn({from:l.from,to:l.to,scheduleId:a})})}),h=u({queryKey:ke({path:{assistant_id:e},query:Ln({from:l.from,to:l.to,groupBy:i,scheduleId:a})}),queryFn:async({signal:t})=>{try{let{data:n}=await Oe({path:{assistant_id:e},query:Ln({from:l.from,to:l.to,groupBy:i,scheduleId:a}),signal:t,throwOnError:!0});return{groupBy:i,response:n}}catch(n){if(!rr(i,n))throw n;let{data:r}=await Oe({path:{assistant_id:e},query:Ln({from:l.from,to:l.to,groupBy:Wn,scheduleId:a}),signal:t,throwOnError:!0});return{groupBy:Wn,response:r}}},retry:ir}),g=h.data?.groupBy??i,_=nr(g)?g:void 0,v=u({...je({path:{assistant_id:e},query:Rn({from:l.from,to:l.to,granularity:d,groupBy:_??`actor`,tz:s,scheduleId:a})}),enabled:!!_,retry:ir}),y=u({...Ae({path:{assistant_id:e},query:In({from:l.from,to:l.to,granularity:d,tz:s,scheduleId:a})}),enabled:!_||v.isError}),b=u({...Ne({path:{assistant_id:e}}),enabled:g===`task`,staleTime:1/0}),x=u({...Me({path:{assistant_id:e}}),select:Bt,enabled:g===`profile`,staleTime:mr}),S=(0,K.useMemo)(()=>({callSites:Kt(b.data),profiles:x.data??{}}),[b.data,x.data]),C=(0,K.useMemo)(()=>{let e=h.data;if(e)return tn(e.response.breakdown,e.groupBy,S)},[h.data,S]),w=(0,K.useMemo)(()=>{if(!(!_||!v.data))return ln(v.data.buckets,_,S)},[v.data,_,S]),T=(0,K.useMemo)(()=>{if(y.data)return cn(y.data.buckets)},[y.data]),E=(0,K.useMemo)(()=>_?v.error?T?{isLoading:!1,error:null,data:T,refetch:y.refetch}:{isLoading:y.isLoading||!T&&!y.error,error:y.error??v.error,data:void 0,refetch:y.error?y.refetch:v.refetch}:{isLoading:v.isLoading,error:v.error,data:w,refetch:v.refetch}:{isLoading:y.isLoading,error:y.error,data:T,refetch:y.refetch},[T,y.error,y.isLoading,y.refetch,w,_,v.error,v.isLoading,v.refetch]),D=sr({requestedGranularity:d,isLoading:E.isLoading,buckets:E.data}),O=D===`hourly`,k=_&&v.error?void 0:g,A=(0,K.useMemo)(()=>{if(!(g!==`schedule`||!a))return vr(f.data,a)},[g,a,f.data]);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`h3`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:`Usage`}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:(0,J.jsx)(xr,{range:r,onChange:p})})]}),(0,J.jsx)(`section`,{"aria-label":`Totals`,children:(0,J.jsx)(Cr,{query:m,skeleton:(0,J.jsx)(Er,{}),render:e=>(0,J.jsx)(wr,{totals:e})})}),(0,J.jsx)(Sr,{title:`Inference Usage`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`h4`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:or(D,k)}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:(0,J.jsx)(Dr,{value:g,onChange:e=>{e===i&&g!==i&&(h.refetch(),v.refetch()),c({groupBy:e,scheduleId:e===`schedule`?void 0:null})}})})]}),(0,J.jsx)(Cr,{query:E,skeleton:(0,J.jsx)(kn,{isHourly:O}),render:e=>(0,J.jsx)(On,{buckets:e,isHourly:O,legendItems:A})})]})}),(0,J.jsx)(Or,{query:h,groups:C}),(0,J.jsx)(br,{})]})}function vr(e,t){let n=e??[];return[...n.some(e=>e.id===t)?[]:[{id:t,label:yr(t)}],...n.map(e=>({id:e.id,label:e.name||e.id}))].map((e,n)=>({seriesKey:on(e.id,`schedule`),label:e.label,colorIndex:n,state:e.id===t?`active`:`inactive`}))}function yr(e){return`Unknown schedule (${e})`}function br(){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsx)(`div`,{className:`h-px w-full`,style:{background:`linear-gradient(to right, transparent, var(--border-base), transparent)`}}),(0,J.jsx)(Sr,{title:`Cost assistant`,subtitle:`Review recent spend and tune model profile choices.`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md px-3 py-3 sm:flex-row sm:items-center`,children:[(0,J.jsx)(fr,{prompt:hr,children:`Analyze costs with assistant`}),(0,J.jsx)(fr,{prompt:gr,variant:`ghost`,children:`Optimize settings`})]})})]})}function xr({range:e,onChange:t}){return(0,J.jsx)(`div`,{className:`flex items-center`,children:(0,J.jsx)(De,{value:e,onChange:t,options:pr.map(e=>({value:e.value,label:e.label}))})})}function Sr({title:e,subtitle:t,children:n}){return(0,J.jsxs)(`section`,{className:`flex flex-col gap-3 rounded-md border px-4 py-4`,style:{background:`var(--surface-lift)`,borderColor:`var(--border-base)`},children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`h3`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:e}),t?(0,J.jsx)(`p`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:t}):null]}),n]})}function Cr({query:e,skeleton:t,render:n}){return e.isLoading?(0,J.jsx)(J.Fragment,{children:t}):e.error?(0,J.jsx)(Nr,{message:e.error instanceof Error?e.error.message:`Failed to load usage.`,onRetry:()=>e.refetch()}):e.data?(0,J.jsx)(J.Fragment,{children:n(e.data)}):(0,J.jsx)(J.Fragment,{children:t})}function wr({totals:e}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{style:{fontSize:`30px`,fontWeight:600,lineHeight:1,color:`var(--content-default)`},children:qt(e.totalEstimatedCostUsd)}),(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-secondary)`},children:`Cost`})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:q(e.eventCount)}),(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-secondary)`},children:`LLM Calls`})]})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,J.jsx)(Tr,{label:`Direct Input Tokens`,value:q(e.totalInputTokens)}),(0,J.jsx)(Tr,{label:`Output Tokens`,value:q(e.totalOutputTokens)}),(0,J.jsx)(Tr,{label:`Cache Created`,value:q(e.totalCacheCreationTokens)}),(0,J.jsx)(Tr,{label:`Cache Read`,value:q(e.totalCacheReadTokens)})]})]})}function Tr({label:e,value:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md px-3 py-2`,style:{background:`color-mix(in srgb, var(--border-base) 15%, transparent)`},children:[(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-default)`},children:t}),(0,J.jsx)(`span`,{className:`text-label-medium-default`,style:{color:`var(--content-tertiary)`},children:e})]})}function Er(){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,"aria-hidden":`true`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(Y,{width:140,height:30}),(0,J.jsx)(Y,{width:90,height:12})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(Y,{width:60,height:16}),(0,J.jsx)(Y,{width:60,height:12})]})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:Array.from({length:4}).map((e,t)=>(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md px-3 py-2`,style:{background:`color-mix(in srgb, var(--border-base) 15%, transparent)`},children:[(0,J.jsx)(Y,{width:`50%`,height:12}),(0,J.jsx)(Y,{width:`70%`,height:11})]},t))})]})}function Dr({value:e,onChange:t}){return(0,J.jsx)(`div`,{className:`flex items-center`,children:(0,J.jsx)(De,{value:e,onChange:t,menuAlign:`end`,menuMinWidth:196,options:Xn.map(e=>({value:e.value,label:e.label}))})})}function Or({query:e,groups:t}){let[n,r]=(0,K.useState)(new Set),i=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,J.jsx)(Sr,{title:`Breakdown`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(kr,{label:`% of total`,active:n.has(`pct`),onClick:()=>i(`pct`)}),(0,J.jsx)(kr,{label:`Tokens`,active:n.has(`tokens`),onClick:()=>i(`tokens`)}),(0,J.jsx)(kr,{label:`Turns`,active:n.has(`turns`),onClick:()=>i(`turns`)})]}),(0,J.jsx)(Cr,{query:e,skeleton:(0,J.jsx)(jr,{}),render:e=>(0,J.jsx)(Ar,{groups:t??e.response.breakdown,groupBy:e.groupBy,showPct:n.has(`pct`),showTokens:n.has(`tokens`),showTurns:n.has(`turns`)})})]})})}function kr({label:e,active:t,onClick:n}){return(0,J.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-full border px-2.5 py-1 text-label-medium-default`,style:{borderColor:t?`var(--content-secondary)`:`var(--border-base)`,background:t?`color-mix(in srgb, var(--content-secondary) 15%, transparent)`:`transparent`,color:t?`var(--content-default)`:`var(--content-tertiary)`},children:e})}function Ar({groups:e,groupBy:t,showPct:n,showTokens:r,showTurns:i}){let a=c();if(e.length===0)return(0,J.jsx)(Mr,{title:`No breakdown data`,subtitle:`No usage recorded for this grouping`});let o=e.reduce((e,t)=>e+t.totalEstimatedCostUsd,0);return(0,J.jsx)(`div`,{className:`overflow-hidden rounded-md`,children:(0,J.jsxs)(`table`,{className:`w-full table-fixed`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{style:{borderBottom:`1px solid var(--border-base)`},children:[(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-left text-label-medium-default`,style:{color:`var(--content-tertiary)`},children:`Group`}),r?(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-left text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`35%`},children:`Tokens`}):null,i?(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-right text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`72px`},children:`Turns`}):null,n?(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-right text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`64px`},children:`%`}):null,(0,J.jsx)(`th`,{className:`px-3 py-2.5 text-right text-label-medium-default`,style:{color:`var(--content-tertiary)`,width:`100px`},children:`Cost`})]})}),(0,J.jsx)(`tbody`,{children:e.map((e,c)=>{let l=Bn(e),u=Hn(e),d=t===`conversation`?e.groupId:null,f=o>0?Math.round(e.totalEstimatedCostUsd/o*100):0;return(0,J.jsxs)(`tr`,{className:d?`cursor-pointer hover:bg-[var(--surface-hover)]`:void 0,onClick:d?e=>{e.target.closest(`a`)||Je(a,d)}:void 0,style:{borderTop:c===0?`none`:`1px solid var(--border-base)`},children:[(0,J.jsx)(`td`,{className:`min-w-0 px-3 py-2`,style:{color:`var(--content-default)`},children:d?(0,J.jsx)(s,{to:Be.conversation(d),className:`block truncate text-body-medium-lighter`,title:e.group,onClick:e=>{Ft(e)||(e.preventDefault(),Je(a,d))},children:e.group}):(0,J.jsx)(`span`,{className:`block truncate text-body-medium-lighter`,title:e.group,children:e.group})}),r?(0,J.jsx)(`td`,{className:`min-w-0 px-3 py-2`,style:{color:`var(--content-secondary)`},children:(0,J.jsx)(`span`,{className:`block truncate text-body-small-default`,title:l,children:u})}):null,i?(0,J.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2 text-right`,children:(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:e.turnCount==null?`—`:e.turnCount.toLocaleString()})}):null,n?(0,J.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2 text-right`,children:(0,J.jsxs)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:[f,`%`]})}):null,(0,J.jsx)(`td`,{className:`whitespace-nowrap px-3 py-2 text-right`,children:(0,J.jsx)(`span`,{className:`text-body-medium-lighter`,style:{color:`var(--content-default)`},children:qt(e.totalEstimatedCostUsd)})})]},e.groupKey??e.groupId??`${e.group}-${c}`)})})]})})}function jr(){return(0,J.jsx)(`div`,{className:`flex flex-col gap-2`,"aria-hidden":`true`,children:Array.from({length:4}).map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(Y,{width:100,height:14}),(0,J.jsx)(Y,{width:`60%`,height:12}),(0,J.jsx)(Y,{width:50,height:14})]},t))})}function Y({width:e,height:t}){return(0,J.jsx)(`div`,{className:`rounded-sm`,style:{width:typeof e==`number`?`${e}px`:e,height:`${t}px`,background:`color-mix(in srgb, var(--border-base) 40%, transparent)`}})}function Mr({title:e,subtitle:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-1 py-8 text-center`,children:[(0,J.jsx)(`span`,{className:`text-body-medium-default`,style:{color:`var(--content-default)`},children:e}),(0,J.jsx)(`span`,{className:`text-body-small-default`,style:{color:`var(--content-tertiary)`},children:t})]})}function Nr({message:e,onRetry:t}){return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,J.jsx)(ve,{className:`h-4 w-4 shrink-0`,style:{color:`var(--system-negative-strong, #f87171)`}}),(0,J.jsx)(`span`,{className:`text-body-medium-lighter`,style:{color:`var(--content-default)`},children:e})]}),t?(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`self-start rounded-md border px-3 py-1 text-body-small-default`,style:{background:`var(--surface-lift)`,borderColor:`var(--border-base)`,color:`var(--content-default)`},children:`Retry`}):null]})}function Pr({open:e,onCancel:t,onConfirm:n,confirming:r,lostFeatures:a}){return(0,J.jsx)(W.Root,{open:e,onOpenChange:e=>{!e&&!r&&t()},children:(0,J.jsxs)(W.Content,{size:`md`,hideCloseButton:!0,children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{icon:ve,children:`Downgrade to Base?`})}),(0,J.jsxs)(W.Body,{children:[(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`text-(--content-secondary)`,children:`Downgrading removes the following Pro features:`}),(0,J.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5`,children:a.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,children:e})},e))})]}),(0,J.jsxs)(W.Footer,{children:[(0,J.jsx)(i,{variant:`outlined`,onClick:t,disabled:r,children:`Keep Pro`}),(0,J.jsx)(i,{variant:`danger`,onClick:n,disabled:r,"data-testid":`confirm-downgrade-button`,children:`Confirm Downgrade`})]})]})})}var Fr=`__none__`;function Ir(e){return`${e.label} — ${B(e.price_cents)}`}function Lr({creditTiers:e,selectedCreditTier:t,onCreditTierChange:n,disabled:r=!1}){let i=(0,K.useMemo)(()=>[{value:Fr,label:`No credit bundle — ${B(0)}`},...e.map(e=>({value:e.tier,label:Ir(e)}))],[e]);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(p,{as:`p`,variant:`label-small-default`,className:`text-[var(--content-secondary)]`,children:`Credit bundle`}),(0,J.jsx)(`span`,{title:`A monthly allotment of credits added to your Pro Plan subscription`,children:(0,J.jsx)(ge,{className:`h-3 w-3 text-[var(--content-tertiary)]`})})]}),(0,J.jsx)(De,{"aria-label":`Credit bundle`,placeholder:`Select a credit bundle`,disabled:r,value:t??Fr,onChange:e=>n(e===Fr?null:e),options:i})]})}function Rr({features:e,variant:t,header:n,maxInline:r=3}){return t===`inline`?(0,J.jsx)(J.Fragment,{children:e.slice(0,r).join(`, `)}):(0,J.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n&&(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-secondary)]`,children:n}),(0,J.jsx)(`ul`,{className:`flex flex-col gap-2`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,J.jsx)(b,{className:`mt-0.5 h-4 w-4 shrink-0 text-[var(--content-tertiary)]`,"aria-hidden":!0}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,children:e})]},e))})]})}function zr({plan:e,isCurrent:t,onPro:n,cancelAtPeriodEnd:r,isCanceled:a,cancelDate:o,formatGraceDate:s,proTierChangeMode:c,creditTiersEnabled:l,creditTiers:u,displayCreditTier:d,onCreditTierChange:f,selectedMachineTier:h,selectedStorageTier:g,onMachineTierChange:_,onStorageTierChange:v,machineTiersForPicker:y,storageTiersForPicker:b,currentMachinePrice:x,currentStoragePrice:S,currentCreditPriceUnknown:C,proCurrentTotalCents:w,proLiveTotalCents:T,proTotalDelta:E,onboardingLoading:D,tierChangePending:O,machineChanged:k,storageChanged:A,creditChanged:j,tierChangeError:M,upgradePending:N,portalPending:P,onUpgrade:te,onApplyTierChange:ne,onDowngradeClick:re,onKeepPlan:I}){let L=e.id===`pro`,R=e.id===`base`,ie=L&&n&&r&&!a,ae=L&&(!t||t&&c),oe=L&&t&&c;return(0,J.jsx)(m.Root,{className:`flex flex-col bg-[var(--surface-base)]`,children:(0,J.jsxs)(m.Body,{padding:`lg`,className:`max-sm:p-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(`span`,{"aria-hidden":!0,className:`flex h-9 w-9 items-center justify-center rounded-lg border border-[var(--border-base)] bg-[var(--surface-lift)]`,children:L?(0,J.jsx)(Vt,{className:`h-5 w-5 text-[var(--content-default)]`}):(0,J.jsx)(Ut,{className:`h-5 w-5 text-[var(--content-default)]`})}),(0,J.jsxs)(`div`,{className:`flex min-h-6 items-center gap-2`,children:[(0,J.jsx)(p,{as:`h3`,variant:`title-small`,children:e.name}),t&&(0,J.jsx)(Ce,{tone:`positive`,children:`Current`})]}),(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`-mt-2 text-[var(--content-tertiary)]`,children:R?`All you need for a capable assistant`:`More features, more compute, more storage`}),ie&&o&&(0,J.jsxs)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--system-mid-strong)]`,"data-testid":`modal-cancels-on`,children:[`Your plan ends on `,s(o)]}),(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1`,children:R?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(p,{as:`p`,variant:`title-medium`,children:`Free`}),(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Forever`})]}):t&&!(ae&&T!=null)&&(w==null||C)?D?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-lighter`,children:`Loading your plan...`})]}):(0,J.jsx)(p,{as:`p`,variant:`body-medium-lighter`,className:`text-[var(--content-tertiary)]`,"data-testid":`modal-pro-price-unavailable`,children:`Current plan pricing unavailable`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(p,{as:`p`,variant:`title-medium`,"data-testid":`modal-pro-price`,children:ae&&T!=null?(0,J.jsxs)(J.Fragment,{children:[B(T),E!=null&&E!==0&&(0,J.jsxs)(`span`,{className:`ml-1 text-[var(--content-tertiary)]`,children:[`(`,de(E),`)`]})]}):w==null?e.id===`pro`?`From ${B(e.base_price_cents+F(e.machine_tiers)+F(e.storage_tiers))}`:null:`Currently ${B(w)}`}),ae&&E!=null&&E!==0&&(0,J.jsx)(`span`,{title:`Your Pro Plan subscription will change from ${B(w)} to ${B(T)}.`,children:(0,J.jsx)(ge,{className:`h-3 w-3 text-[var(--content-tertiary)]`})})]}),e.id===`pro`&&(0,J.jsxs)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,"data-testid":`modal-pro-base-fee`,children:[ee(e.base_price_cents),` base fee`]})]})}),(0,J.jsx)(Rr,{features:e.included_features,variant:`checklist`}),L&&!l&&(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,"data-testid":`modal-credits-not-included`,children:`*Credits not included`})]}),(0,J.jsxs)(`div`,{className:`mt-4 flex flex-1 flex-col justify-end gap-4`,children:[!t&&L&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),l&&(0,J.jsx)(Lr,{creditTiers:u,selectedCreditTier:d,onCreditTierChange:f,disabled:N}),(0,J.jsx)(z,{machineTiers:y,storageTiers:b,selectedMachineTier:h,selectedStorageTier:g,onMachineTierChange:_,onStorageTierChange:v}),(0,J.jsx)(i,{variant:`primary`,className:`w-full`,onClick:te,disabled:N||!h||!g,"data-testid":`modal-upgrade-to-pro-button`,children:`Upgrade to Pro`})]}),oe&&(D?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-lighter`,children:`Loading your plan...`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),l&&(0,J.jsx)(Lr,{creditTiers:u,selectedCreditTier:d,onCreditTierChange:f,disabled:O}),(0,J.jsx)(z,{machineTiers:y,storageTiers:b,selectedMachineTier:h,selectedStorageTier:g,onMachineTierChange:_,onStorageTierChange:v,currentMachinePriceCents:x,currentStoragePriceCents:S}),M&&(0,J.jsx)(U,{tone:`error`,children:M}),(0,J.jsx)(i,{variant:`primary`,className:`w-full`,onClick:ne,disabled:O||!k&&!A&&!j,"data-testid":`modal-change-tier-button`,children:`Update Plan`})]})),!t&&R&&n&&!r&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),(0,J.jsx)(i,{variant:`outlined`,className:`w-full`,onClick:re,disabled:P,"data-testid":`modal-downgrade-to-base-button`,children:`Downgrade to Base`})]}),ie&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`hr`,{className:`border-t border-[var(--border-base)]`}),(0,J.jsx)(i,{variant:`outlined`,className:`w-full`,onClick:I,disabled:P,"data-testid":`modal-keep-plan-button`,children:`Keep your Plan`})]})]})]})})}function Br({open:e,onClose:t,onTierUpgraded:n}){let r=l(),a=u(Ze()),o=u(bt()),s=d(mt()),c=d(xt()),f=d(yt()),m=d(Tt()),h=k(C(o.data)),[_,v]=(0,K.useState)(`plans`),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(null),[w,E]=(0,K.useState)(null),[O,A]=(0,K.useState)(void 0);(0,K.useEffect)(()=>Ke(()=>{r.invalidateQueries({queryKey:Et()}),r.invalidateQueries({queryKey:ht()}),r.invalidateQueries({queryKey:pt()}),t()}),[r,t]);let ee=o.data?.plan_id,P=ee===`pro`,te=u({...wt(),enabled:P}),F=te.data?.max_machine_tier??null,I=te.data?.selected_storage_tier??null,L=te.data?.selected_storage_gib??null,R=o.data?.cancel_at_period_end===!0||!!o.data?.cancel_at,ie=o.data?.status===`canceled`,ae=T(o.data),se=o.data?.status,ce=se!=null&&ne.has(se),le=P&&ce&&!R&&!ie,z=a.data?.plans.find(e=>e.id===`pro`),ue=z?.credit_tiers??[],B=ue.length>0,de=o.data?.selected_credit_tier??null,V=e=>ue.find(t=>t.tier===e)?.price_cents??0,fe=V(de),pe=de!=null&&!ue.some(e=>e.tier===de),me=O===void 0?de:O,he=V(me),ge=z?.machine_tiers??[],_e=le&&L!=null?(z?.storage_tiers??[]).map(e=>e.storage_gib<L?{...e,disabled:!0}:e):z?.storage_tiers??[];(0,K.useEffect)(()=>{if(!e){S(null),E(null),A(void 0);return}if(z){if(le){if(F==null||I==null)return;S(e=>N(ge,e??F)),E(e=>N(_e,e??I)),A(e=>re(ue,e,de));return}S(e=>N(z.machine_tiers,e)),E(e=>N(z.storage_tiers,e)),A(e=>re(ue,e,null))}},[e,z,le,F,I,de]);let ye=a.data?.plans.find(e=>e.id===`base`),be=new Set(ye?.included_features??[]),xe=(z?.included_features??[]).filter(e=>!be.has(e)),Se=()=>{if(!s.isPending){if(!x||!w){G.error(`Pick a machine and storage tier to continue.`,{id:`pro-upgrade-error`});return}s.mutate({body:{target_plan_id:`pro`,confirm:!0,machine_tier:x,storage_tier:w,credit_tier:me,return_target:j()}},{onSuccess:e=>{if(e.checkout_url){D({kind:`custom`,machineTier:x,storageTier:w,creditTier:me}),Ge(e.checkout_url);return}if(e.status===`no_op`){G.info(`You're already on Pro.`,{id:`pro-upgrade`}),t();return}G.error(e.message??`Failed to start upgrade. Please try again.`,{id:`pro-upgrade-error`})},onError:e=>{G.error(oe(e,`Failed to start upgrade. Please try again.`),{id:`pro-upgrade-error`})}})}},Ce=()=>{h.isPending||(v(`plans`),h.mutate({}))},we=()=>{r.invalidateQueries({queryKey:Et()}),r.invalidateQueries({queryKey:pt()}),r.invalidateQueries({queryKey:ht()})},Te=c.isPending||f.isPending||m.isPending,Ee=x!=null&&x!==F,De=w!=null&&w!==I,Oe=B&&O!==void 0&&O!==de,ke=e=>ge.find(t=>t.tier===e)?.price_cents??null,Ae=e=>_e.find(t=>t.tier===e)?.price_cents??null,je=ke(x),Me=Ae(w),Ne=ke(F),Pe=Ae(I),Fe=Ee&&je!=null&&Ne!=null&&je<Ne,Ie=()=>{if(Te)return;let e=[];Ee&&x&&e.push(new Promise(e=>{c.mutate({body:{machine_tier:x}},{onSuccess:()=>e({dimension:`machine`,ok:!0}),onError:t=>e({dimension:`machine`,ok:!1,error:t})})})),De&&w&&e.push(new Promise(e=>{f.mutate({body:{storage_tier:w}},{onSuccess:()=>e({dimension:`storage`,ok:!0}),onError:t=>e({dimension:`storage`,ok:!1,error:t})})})),Oe&&e.push(new Promise(e=>{m.mutate({body:{credit_tier:me}},{onSuccess:()=>e({dimension:`credit`,ok:!0}),onError:t=>e({dimension:`credit`,ok:!1,error:t})})})),Promise.all(e).then(e=>{we();let r=e.some(e=>e.ok&&e.dimension===`storage`),i=e.some(e=>e.ok&&e.dimension===`machine`)&&!Fe,a=(r||i)&&!!n,o=e.filter(e=>!e.ok);if(o.length>0){let e=o.map(e=>oe(e.error,`Failed to update ${e.dimension} tier.`)).join(` `);G.error(e,{id:`pro-tier-change-error`}),a&&(t(),n());return}a?(t(),n()):G.success(Oe&&!Ee&&!De?`Credit bundle updated.`:`Plan updated.`,{id:`pro-tier-change`})})},Le=()=>{if(!Te){if(Fe){b(!0);return}Ie()}},Re=()=>{b(!1),Ie()},ze=e=>je!=null&&Me!=null?e.base_price_cents+je+Me+he:null,Be=e=>Ne!=null&&Pe!=null?e.base_price_cents+Ne+Pe+fe:null,Ve=c.isError||f.isError||m.isError?oe(c.error??f.error??m.error,`Failed to update plan. Please try again.`):null,He=a.isLoading||o.isLoading,Ue=a.isError||o.isError||!a.data||!o.data;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(W.Root,{open:e,onOpenChange:e=>{e||(v(`plans`),t())},children:(0,J.jsx)(W.Content,{size:_===`plans`?`lg`:`md`,children:_===`downgrade-confirm`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{icon:ve,children:`Downgrade to Base?`})}),(0,J.jsxs)(W.Body,{children:[(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`text-(--content-secondary)`,children:`Downgrading removes the following Pro features:`}),(0,J.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5`,children:xe.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,children:e})},e))})]}),(0,J.jsxs)(W.Footer,{children:[(0,J.jsx)(i,{variant:`ghost`,onClick:()=>v(`plans`),disabled:h.isPending,leftIcon:(0,J.jsx)(g,{className:`h-4 w-4`}),children:`Back`}),(0,J.jsx)(i,{variant:`danger`,onClick:Ce,disabled:h.isPending,"data-testid":`confirm-downgrade-button`,children:`Confirm Downgrade`})]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{className:`sr-only`,children:`Upgrade Plan`})}),(0,J.jsx)(W.Body,{children:He?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-lighter`,children:`Loading plans...`})]}):Ue?(0,J.jsx)(U,{tone:`error`,children:`Failed to load plans. Please try again later.`}):(0,J.jsxs)(`div`,{className:`space-y-4 sm:space-y-6`,children:[(0,J.jsxs)(`div`,{className:`space-y-2 pb-2 pt-4 text-center`,children:[(0,J.jsx)(p,{as:`p`,variant:`title-medium`,children:`Your Assistant, Your Way`}),(0,J.jsx)(p,{as:`p`,variant:`body-medium-lighter`,className:`text-[var(--content-secondary)]`,children:`Choose the plan that works best for you and your assistant.`})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:a.data.plans.map(e=>{let t=e.id===ee,n=e.id===`pro`&&z?ze(z):null,r=e.id===`pro`&&z?Be(z):null;return(0,J.jsx)(zr,{plan:e,isCurrent:t,onPro:P,cancelAtPeriodEnd:R,isCanceled:ie,cancelDate:ae,formatGraceDate:M,proTierChangeMode:le,creditTiersEnabled:B,creditTiers:ue,displayCreditTier:me,onCreditTierChange:A,selectedMachineTier:x,selectedStorageTier:w,onMachineTierChange:S,onStorageTierChange:E,machineTiersForPicker:ge,storageTiersForPicker:_e,currentMachinePrice:Ne,currentStoragePrice:Pe,currentCreditPriceUnknown:pe,proCurrentTotalCents:r,proLiveTotalCents:n,proTotalDelta:n!=null&&r!=null?n-r:null,onboardingLoading:te.isLoading,tierChangePending:Te,machineChanged:Ee,storageChanged:De,creditChanged:Oe,tierChangeError:Ve,upgradePending:s.isPending,portalPending:h.isPending,onUpgrade:Se,onApplyTierChange:Le,onDowngradeClick:()=>v(`downgrade-confirm`),onKeepPlan:()=>h.mutate({})},e.id)})})]})}),(0,J.jsxs)(W.Footer,{className:`relative items-center`,children:[(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`pointer-events-none absolute inset-x-0 text-center text-[var(--content-tertiary)]`,children:(0,J.jsx)(`span`,{className:`pointer-events-auto`,children:`You can change or cancel your plan at any time from billing settings.`})}),(0,J.jsx)(`div`,{className:`ml-auto`,children:(0,J.jsx)(i,{variant:`outlined`,onClick:t,"data-testid":`modal-cancel-button`,children:`Cancel`})})]})]})})}),(0,J.jsx)(Pr,{open:y,onCancel:()=>b(!1),onConfirm:Re,confirming:Te,lostFeatures:[`Reduced CPU and memory for your assistant — it will resize to the smaller compute profile.`]})]})}function Vr({open:e,confirming:t,onCancel:n,onConfirm:r}){return(0,J.jsx)(Ee,{open:e,title:`Disable automatic top-ups?`,message:`Auto top-ups will stop. Any saved payment method stays on file.`,confirmLabel:t?`Disabling…`:`Disable`,cancelLabel:`Keep enabled`,destructive:!0,onConfirm:r,onCancel:n})}var Hr={threshold_usd:`100`,amount_usd:`10`,monthly_cap_usd:``};function Ur(e){if(e===``||e===`-`)return e;let t=parseFloat(e);return Number.isFinite(t)?String(Math.trunc(t)):``}function Wr(e){let t={},n=parseFloat(e.threshold_usd),r=parseFloat(e.amount_usd);if((!Number.isFinite(r)||r<10||r>500)&&(t.amount_usd=`Must be between $10 and $500`),(!Number.isFinite(n)||n<1||n>100)&&(t.threshold_usd=`Must be between $1 and $100`),e.monthly_cap_usd!==``){let n=parseFloat(e.monthly_cap_usd);!Number.isFinite(n)||n<25||n>1e4?t.monthly_cap_usd=`Must be between $25 and $10,000`:Number.isFinite(r)&&n<r&&(t.monthly_cap_usd=`Must be at least the top-up amount`)}return t}function Gr(e,t,n,r){if(n[e])return n[e];if(r)return t[e]}function Kr({initialValues:e=Hr,submitting:t,serverErrors:n,onSave:r,onCancel:a}){let[o,s]=(0,K.useState)(e),[c,l]=(0,K.useState)({threshold_usd:!1,amount_usd:!1,monthly_cap_usd:!1}),u=Wr(o),d=e=>t=>{s(n=>({...n,[e]:t.target.value}))},f=e=>()=>{l(t=>({...t,[e]:!0})),s(t=>({...t,[e]:Ur(t[e])}))},p=e=>Gr(e,u,n,c[e]);return(0,J.jsx)(`div`,{className:`mt-4`,children:(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,J.jsx)(`div`,{className:`min-w-[10rem] flex-1`,children:(0,J.jsx)(we,{type:`number`,step:`1`,label:`Auto-reload when balance below`,value:o.threshold_usd,onChange:d(`threshold_usd`),onBlur:f(`threshold_usd`),errorText:p(`threshold_usd`),"data-testid":`auto-top-up-threshold-input`,fullWidth:!0})}),(0,J.jsx)(`div`,{className:`min-w-[10rem] flex-1`,children:(0,J.jsx)(we,{type:`number`,step:`1`,label:`Auto-reload amount`,value:o.amount_usd,onChange:d(`amount_usd`),onBlur:f(`amount_usd`),errorText:p(`amount_usd`),"data-testid":`auto-top-up-amount-input`,fullWidth:!0})}),(0,J.jsx)(`div`,{className:`min-w-[10rem] flex-1`,children:(0,J.jsx)(we,{type:`number`,step:`1`,label:`Monthly spending cap`,helperText:`Pauses auto top-ups for the rest of the month once spending reaches this amount. Manual purchases also count toward the total. Leave empty for no limit.`,value:o.monthly_cap_usd,onChange:d(`monthly_cap_usd`),onBlur:f(`monthly_cap_usd`),errorText:p(`monthly_cap_usd`),"data-testid":`auto-top-up-cap-input`,fullWidth:!0})}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pt-[18px]`,children:[(0,J.jsx)(i,{variant:`outlined`,onClick:a,disabled:t,children:`Cancel`}),(0,J.jsx)(i,{variant:`primary`,onClick:()=>{l({threshold_usd:!0,amount_usd:!0,monthly_cap_usd:!0});let e={threshold_usd:Ur(o.threshold_usd),amount_usd:Ur(o.amount_usd),monthly_cap_usd:Ur(o.monthly_cap_usd)};s(e);let t=Wr(e);if(Object.keys(t).length!==0)return;let n=e=>e===``?``:`${parseInt(e,10)}.00`;r({threshold_usd:n(e.threshold_usd),amount_usd:n(e.amount_usd),monthly_cap_usd:e.monthly_cap_usd===``?``:n(e.monthly_cap_usd)})},disabled:t,"data-testid":`auto-top-up-save-button`,children:`Save`})]})]})})}var qr=t(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),Jr=t(((e,t)=>{var n=qr();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),X=e(t(((e,t)=>{t.exports=Jr()()}))(),1);function Yr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Xr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Yr(Object(n),!0).forEach(function(t){Qr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Yr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Zr(e){"@babel/helpers - typeof";return Zr=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Zr(e)}function Qr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function $r(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,a;for(a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}function ei(e,t){if(e==null)return{};var n=$r(e,t),r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)r=a[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function ti(e,t){return ni(e)||ri(e,t)||ii(e,t)||oi()}function ni(e){if(Array.isArray(e))return e}function ri(e,t){var n=e&&(typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`]);if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function ii(e,t){if(e){if(typeof e==`string`)return ai(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ai(e,t)}}function ai(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function oi(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
3
3
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var Z=function(e,t,n){var r=!!n,i=K.useRef(n);K.useEffect(function(){i.current=n},[n]),K.useEffect(function(){if(!r||!e)return function(){};var n=function(){i.current&&i.current.apply(i,arguments)};return e.on(t,n),function(){e.off(t,n)}},[r,t,e,i])},si=function(e){var t=K.useRef(e);return K.useEffect(function(){t.current=e},[e]),t.current},ci=function(e){return e!==null&&Zr(e)===`object`},li=function(e){return ci(e)&&typeof e.then==`function`},ui=function(e){return ci(e)&&typeof e.elements==`function`&&typeof e.createToken==`function`&&typeof e.createPaymentMethod==`function`&&typeof e.confirmCardPayment==`function`},di=`[object Object]`,fi=function e(t,n){if(!ci(t)||!ci(n))return t===n;var r=Array.isArray(t);if(r!==Array.isArray(n))return!1;var i=Object.prototype.toString.call(t)===di;if(i!==(Object.prototype.toString.call(n)===di))return!1;if(!i&&!r)return t===n;var a=Object.keys(t),o=Object.keys(n);if(a.length!==o.length)return!1;for(var s={},c=0;c<a.length;c+=1)s[a[c]]=!0;for(var l=0;l<o.length;l+=1)s[o[l]]=!0;var u=Object.keys(s);if(u.length!==a.length)return!1;var d=t,f=n;return u.every(function(t){return e(d[t],f[t])})},pi=function(e,t,n){return ci(e)?Object.keys(e).reduce(function(r,i){var a=!ci(t)||!fi(e[i],t[i]);return n.includes(i)?(a&&console.warn(`Unsupported prop change: options.${i} is not a mutable property.`),r):a?Xr(Xr({},r||{}),{},Qr({},i,e[i])):r},null):null},mi="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",hi=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:mi;if(e===null||ui(e))return e;throw Error(t)},gi=function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:mi;if(li(e))return{tag:`async`,stripePromise:Promise.resolve(e).then(function(e){return hi(e,t)})};var n=hi(e,t);return n===null?{tag:`empty`}:{tag:`sync`,stripe:n}},_i=function(e){!e||!e._registerWrapper||!e.registerAppInfo||(e._registerWrapper({name:`react-stripe-js`,version:`6.4.0`}),e.registerAppInfo({name:`react-stripe-js`,version:`6.4.0`,url:`https://stripe.com/docs/stripe-js/react`}))},vi=K.createContext(null);vi.displayName=`ElementsContext`;var yi=function(e,t){if(!e)throw Error(`Could not find Elements context; You need to wrap the part of your app that ${t} in an <Elements> provider.`);return e},bi=function(e){var t=e.stripe,n=e.options,r=e.children,i=K.useMemo(function(){return gi(t)},[t]),a=ti(K.useState(function(){return{stripe:i.tag===`sync`?i.stripe:null,elements:i.tag===`sync`?i.stripe.elements(n):null}}),2),o=a[0],s=a[1];K.useEffect(function(){var e=!0,t=function(e){s(function(t){return t.stripe?t:{stripe:e,elements:e.elements(n)}})};return i.tag===`async`&&!o.stripe?i.stripePromise.then(function(n){n&&e&&t(n)}):i.tag===`sync`&&!o.stripe&&t(i.stripe),function(){e=!1}},[i,o,n]);var c=si(t);K.useEffect(function(){c!==null&&c!==t&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[c,t]);var l=si(n);return K.useEffect(function(){if(o.elements){var e=pi(n,l,[`clientSecret`,`fonts`]);e&&o.elements.update(e)}},[n,l,o.elements]),K.useEffect(function(){_i(o.stripe)},[o.stripe]),K.createElement(vi.Provider,{value:o},r)};bi.propTypes={stripe:X.default.any,options:X.default.object};var xi=function(e){return yi(K.useContext(vi),e)},Si=function(e){var t=e.children;return t(xi(`mounts <ElementsConsumer>`))};Si.propTypes={children:X.default.func.isRequired};var Ci=K.createContext(null);Ci.displayName=`CheckoutContext`;var wi=function(e){var t=K.useContext(Ci),n=K.useContext(vi);if(t){if(n)throw Error(`You cannot wrap the part of your app that ${e} in both a checkout provider and <Elements> provider.`);return t}else return yi(n,e)},Ti=[`mode`],Ei=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},Q=function(e,t,n){var r=`${Ei(e)}Element`,i=t?function(e){wi(`mounts <${r}>`);var t=e.id,n=e.className;return K.createElement(`div`,{id:t,className:n})}:function(t){var n=t.id,i=t.className,a=t.options,o=a===void 0?{}:a,s=t.onBlur,c=t.onFocus,l=t.onReady,u=t.onChange,d=t.onEscape,f=t.onClick,p=t.onLoadError,m=t.onLoaderStart,h=t.onNetworksChange,g=t.onConfirm,_=t.onCancel,v=t.onShippingAddressChange,y=t.onShippingRateChange,b=t.onSavedPaymentMethodRemove,x=t.onSavedPaymentMethodUpdate,S=t.onAvailablePaymentMethodsChange,C=wi(`mounts <${r}>`),w=`elements`in C?C.elements:null,T=`checkoutState`in C?C.checkoutState:null,E=T?.type===`success`||T?.type===`loading`?T.sdk:null,D=ti(K.useState(null),2),O=D[0],k=D[1],A=K.useRef(null),j=K.useRef(null);Z(O,`blur`,s),Z(O,`focus`,c),Z(O,`escape`,d),Z(O,`click`,f),Z(O,`loaderror`,p),Z(O,`loaderstart`,m),Z(O,`networkschange`,h),Z(O,`confirm`,g),Z(O,`cancel`,_),Z(O,`shippingaddresschange`,v),Z(O,`shippingratechange`,y),Z(O,`savedpaymentmethodremove`,b),Z(O,`savedpaymentmethodupdate`,x),Z(O,`availablepaymentmethodschange`,S),Z(O,`change`,u);var M;l&&(M=e===`expressCheckout`?l:function(){l(O)}),Z(O,`ready`,M),K.useLayoutEffect(function(){if(A.current===null&&j.current!==null&&(w||E)){var t=null;if(E){var n=E,i=E;switch(e){case`paymentForm`:t=i.createForm(o);break;case`payment`:t=n.createPaymentElement(o);break;case`address`:if(`mode`in o){var a=o.mode,s=ei(o,Ti);if(a===`shipping`)t=n.createShippingAddressElement(s);else if(a===`billing`)t=n.createBillingAddressElement(s);else throw Error(`Invalid options.mode. mode must be 'billing' or 'shipping'.`)}else throw Error(`You must supply options.mode. mode must be 'billing' or 'shipping'.`);break;case`expressCheckout`:t=n.createExpressCheckoutElement(o);break;case`currencySelector`:t=E.createCurrencySelectorElement();break;case`taxId`:t=n.createTaxIdElement(o);break;case`contactDetails`:t=n.createContactDetailsElement();break;default:throw Error(`<${r}> is not supported inside a checkout provider. Use an <Elements> provider instead.`)}}else w&&(t=w.create(e,o));A.current=t,k(t),t&&t.mount(j.current)}},[w,E,o]);var N=si(o);return K.useEffect(function(){if(A.current){var e=pi(o,N,[`paymentRequest`]);e&&`update`in A.current&&A.current.update(e)}},[o,N]),K.useLayoutEffect(function(){return function(){if(A.current&&typeof A.current.destroy==`function`)try{A.current.destroy(),A.current=null}catch{}}},[]),K.createElement(`div`,{id:n,className:i,ref:j})};return i.propTypes={id:X.default.string,className:X.default.string,onChange:X.default.func,onBlur:X.default.func,onFocus:X.default.func,onReady:X.default.func,onEscape:X.default.func,onClick:X.default.func,onLoadError:X.default.func,onLoaderStart:X.default.func,onNetworksChange:X.default.func,onConfirm:X.default.func,onCancel:X.default.func,onShippingAddressChange:X.default.func,onShippingRateChange:X.default.func,onSavedPaymentMethodRemove:X.default.func,onSavedPaymentMethodUpdate:X.default.func,onAvailablePaymentMethodsChange:X.default.func,options:X.default.object},i.displayName=r,i.__elementType=e,i},$=typeof window>`u`,Di=K.createContext(null);Di.displayName=`EmbeddedCheckoutProviderContext`,Q(`auBankAccount`,$),Q(`card`,$),Q(`cardNumber`,$),Q(`cardExpiry`,$),Q(`cardCvc`,$),Q(`iban`,$),Q(`payment`,$),Q(`expressCheckout`,$),Q(`paymentRequestButton`,$),Q(`linkAuthentication`,$),Q(`contactDetails`,$),Q(`address`,$),Q(`shippingAddress`,$),Q(`paymentMethodMessaging`,$),Q(`taxId`,$),Q(`issuingCardNumberDisplay`,$),Q(`issuingCardCvcDisplay`,$),Q(`issuingCardExpiryDisplay`,$),Q(`issuingCardPinDisplay`,$),Q(`issuingCardCopyButton`,$);var Oi=`dahlia`,ki=`https://js.stripe.com`,Ai=`${ki}/${Oi}/stripe.js`,ji=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,Mi=/^https:\/\/js\.stripe\.com\/(v3|[a-z]+)\/stripe\.js(\?.*)?$/,Ni=`loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used`,Pi=function(e){return ji.test(e)||Mi.test(e)},Fi=function(){for(var e=document.querySelectorAll(`script[src^="${ki}"]`),t=0;t<e.length;t++){var n=e[t];if(Pi(n.src))return n}return null},Ii=function(e){var t=e&&!e.advancedFraudSignals?`?advancedFraudSignals=false`:``,n=document.createElement(`script`);n.src=`${Ai}${t}`;var r=document.head||document.body;if(!r)throw Error(`Expected document.body not to be null. Stripe.js requires a <body> element.`);return r.appendChild(n),n},Li=null,Ri=null,zi=null,Bi=function(e){return function(t){e(Error(`Failed to load Stripe.js`,{cause:t}))}},Vi=function(e,t){return function(){window.Stripe?e(window.Stripe):t(Error(`Stripe.js not available`))}},Hi=function(e){return Li===null?(Li=new Promise(function(t,n){if(typeof window>`u`||typeof document>`u`){t(null);return}if(window.Stripe&&e&&console.warn(Ni),window.Stripe){t(window.Stripe);return}try{var r=Fi();if(r&&e)console.warn(Ni);else if(!r)r=Ii(e);else if(r&&zi!==null&&Ri!==null){var i;r.removeEventListener(`load`,zi),r.removeEventListener(`error`,Ri),(i=r.parentNode)==null||i.removeChild(r),r=Ii(e)}zi=Vi(t,n),Ri=Bi(n),r.addEventListener(`load`,zi),r.addEventListener(`error`,Ri)}catch(e){n(e);return}}),Li.catch(function(e){return Li=null,Promise.reject(e)})):Li},Ui,Wi=!1,Gi=function(){return Ui||(Ui=Hi(null).catch(function(e){return Ui=null,Promise.reject(e)}),Ui)};Promise.resolve().then(function(){return Gi()}).catch(function(e){Wi||console.warn(e)});function Ki(){return typeof document<`u`&&document.documentElement.classList.contains(`dark`)?{theme:`night`}:{theme:`stripe`}}function qi({open:e,onClose:t,onSavedOptimistic:n}){let r=d(et()),{mutate:i,reset:a}=r;return(0,K.useEffect)(()=>{e||a()},[e,i,a]),(0,K.useMemo)(()=>Ki(),[r.data?.client_secret??null]),(0,J.jsx)(W.Root,{open:e,onOpenChange:e=>{e||t()},children:(0,J.jsxs)(W.Content,{size:`sm`,children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{children:`Save Payment Method`})}),(0,J.jsx)(W.Body,{className:`min-h-[260px]`,children:(0,J.jsx)(Ji,{})})]})})}function Ji(){return(0,K.useEffect)(()=>{console.warn(`[AutoTopUpPaymentMethodModal] VITE_STRIPE_PUBLISHABLE_KEY is not set; the payment-method modal cannot mount Stripe Elements.`)},[]),(0,J.jsx)(U,{tone:`error`,children:`Payment method setup is currently unavailable. Please try again later.`})}var Yi={visa:`Visa`,mastercard:`Mastercard`,amex:`Amex`,discover:`Discover`,diners:`Diners Club`,jcb:`JCB`,unionpay:`UnionPay`};function Xi(e){return Yi[e.toLowerCase()]??e}function Zi({brand:e,last4:t,onUpdateCard:n,onRemove:r,removing:a=!1}){return(0,J.jsxs)(`div`,{"data-testid":`payment-method-row`,className:`flex items-center justify-between gap-2 rounded-lg bg-[var(--surface-base)] pl-3 pr-2 py-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(pe,{"aria-hidden":!0,className:`h-4 w-4 shrink-0 text-[var(--content-default)]`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`truncate text-[var(--content-default)]`,children:e?Xi(e):`Saved card`}),t!=null&&(0,J.jsxs)(p,{as:`p`,variant:`body-small-default`,className:`truncate text-[var(--content-tertiary)]`,children:[`Ending in `,t]})]})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,J.jsx)(i,{variant:`outlined`,onClick:n,"data-testid":`payment-method-update`,children:`Update Card`}),(0,J.jsx)(i,{variant:`dangerOutline`,onClick:r,disabled:a,"data-testid":`payment-method-remove`,children:a?`Removing…`:`Remove`})]})]})}function Qi(e){if(!e)return``;let t=parseFloat(e);return Number.isFinite(t)?String(Math.trunc(t)):``}function $i(e){if(!e)return`$0`;let t=parseFloat(e);if(!Number.isFinite(t))return`$0`;let n=Math.abs(t).toLocaleString(`en-US`,{minimumFractionDigits:2,maximumFractionDigits:2}),r=n.endsWith(`.00`)?n.slice(0,-3):n;return t<0?`-$${r}`:`$${r}`}var ea={enabled:!1,threshold_usd:null,amount_usd:null,monthly_cap_usd:null,has_payment_method:!1,payment_method_brand:null,payment_method_last4:null,stripe_payment_method_updated_at:null,last_charge_at:null,last_failure_at:null,last_failure_reason:null,disabled_due_to_repeated_failures:!1,paused_until:null,current_month_credits_purchased_usd:`0.00`,current_month_charged_usd:`0.00`,next_trigger_amount_usd:null,stubbed:!1};function ta(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e))Array.isArray(r)&&typeof r[0]==`string`&&(t[n]=r[0]);return t}function na({testId:e,children:t}){return(0,J.jsx)(`div`,{"data-testid":e,className:`flex h-8 min-w-0 flex-1 items-center gap-1.5 rounded-lg bg-[var(--surface-base)] px-2`,children:t})}function ra(){let e=l(),t=u(Ot()),n=d(st()),r=d(rt()),a=d(ot()),[s,c]=o(),f=(0,K.useRef)(null),[m,h]=(0,K.useState)(`view`),[g,_]=(0,K.useState)(!1),[v,y]=(0,K.useState)(!1),[b,S]=(0,K.useState)(!1),[C,w]=(0,K.useState)(!1),[T,E]=(0,K.useState)(!1),[D,O]=(0,K.useState)(!1);(0,K.useEffect)(()=>{C&&t.data?.has_payment_method&&w(!1)},[C,t.data?.has_payment_method]);let k=()=>{n.reset(),r.reset(),h(`form`)},A=e=>{if(_(!0),!e.has_payment_method||e.disabled_due_to_repeated_failures===!0){w(!0),E(!1);return}w(!1),k()},j=s.get(`configure_top_up`)===`1`;if((0,K.useEffect)(()=>{if(!j||t.data==null)return;let e=new URLSearchParams(s);e.delete(`configure_top_up`),c(e,{replace:!0});let n=t.data;if(n.enabled===!0)return;A(n);let r=typeof window<`u`&&window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches===!0;f.current?.scrollIntoView({behavior:r?`auto`:`smooth`,block:`center`})},[j,t.data]),t.isLoading)return(0,J.jsx)(`div`,{"data-testid":`auto-top-up-card`,children:(0,J.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Loading…`})});if(t.isError||!t.data)return(0,J.jsx)(`div`,{"data-testid":`auto-top-up-card`,children:(0,J.jsx)(U,{tone:`error`,children:`Failed to load auto top-up configuration.`})});let M=t.data,N=M.enabled===!0,ee=M.disabled_due_to_repeated_failures===!0&&!N,P=()=>{h(`view`),_(!1)},te=()=>{r.reset(),y(!1)},ne=t=>{n.mutate({body:{enabled:!0,threshold_usd:t.threshold_usd,amount_usd:t.amount_usd,monthly_cap_usd:t.monthly_cap_usd===``?null:t.monthly_cap_usd}},{onSuccess:t=>{ct(e,void 0,e=>({...t,payment_method_brand:e?.payment_method_brand??null,payment_method_last4:e?.payment_method_last4??null})),e.invalidateQueries({queryKey:Qe()}),P()}})},re=()=>{r.mutate({},{onSuccess:()=>{ct(e,void 0,e=>({...ea,has_payment_method:e?.has_payment_method??!1,payment_method_brand:e?.payment_method_brand??null,payment_method_last4:e?.payment_method_last4??null,stripe_payment_method_updated_at:e?.stripe_payment_method_updated_at??null})),y(!1),h(`view`),_(!1)}})},F=()=>{a.mutate({},{onSuccess:()=>{ct(e,void 0,{...M,enabled:!1,has_payment_method:!1,payment_method_brand:null,payment_method_last4:null}),e.invalidateQueries({queryKey:Qe()}),S(!1),P()},onError:()=>{S(!1)}})},I=e=>{if(e&&!N){A(M);return}if(!e&&!N&&g){w(!1),P();return}!e&&N&&y(!0)},L=async()=>{let t=Date.now(),n=M.stripe_payment_method_updated_at??null;try{await e.invalidateQueries({queryKey:Qe()})}catch{}for(;Date.now()-t<2e4;){try{let t=await e.fetchQuery(Ot());if(t.has_payment_method&&t.stripe_payment_method_updated_at!==n)break}catch{}await new Promise(e=>setTimeout(e,1500))}w(!1),g&&k()},R=m===`form`,ie=ta(n.error),ae=n.isError&&Object.keys(ie).length===0;return(0,J.jsxs)(`div`,{ref:f,"data-testid":`auto-top-up-card`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,J.jsx)(Te,{checked:N||g,onChange:I,label:`Enable Extra Usage`})}),M.has_payment_method&&(0,J.jsx)(`div`,{className:`mt-3`,children:(0,J.jsx)(Zi,{brand:M.payment_method_brand,last4:M.payment_method_last4,onUpdateCard:()=>O(!0),onRemove:()=>S(!0),removing:a.isPending})}),N&&!R&&(0,J.jsxs)(`div`,{className:`mt-3 flex w-full items-center gap-2`,children:[(0,J.jsxs)(na,{testId:`auto-top-up-summary`,children:[(0,J.jsx)(x,{className:`h-3.5 w-3.5 shrink-0 text-[var(--content-default)]`,"aria-hidden":`true`}),(0,J.jsxs)(p,{variant:`body-medium-default`,className:`truncate text-[var(--content-default)]`,children:[`Add `,$i(M.amount_usd),` when balance falls under`,` `,$i(M.threshold_usd)]})]}),M.monthly_cap_usd!=null&&(0,J.jsx)(na,{testId:`auto-top-up-cap-progress`,children:(0,J.jsxs)(p,{variant:`body-medium-default`,className:`truncate text-[var(--content-default)]`,children:[(0,J.jsxs)(`span`,{children:[$i(M.current_month_credits_purchased_usd),` `]}),(0,J.jsxs)(`span`,{className:`text-[var(--content-tertiary)]`,children:[`/ `,$i(M.monthly_cap_usd),` this month`]})]})}),(0,J.jsx)(i,{variant:`outlined`,onClick:k,"data-testid":`auto-top-up-edit-button`,className:`shrink-0`,children:`Adjust`})]}),ee&&(0,J.jsx)(U,{tone:`warning`,className:`mt-3`,"data-testid":`auto-top-up-declined-cutoff`,actions:(0,J.jsx)(i,{variant:`outlined`,onClick:()=>O(!0),"data-testid":`auto-top-up-add-pm-button`,children:`Add payment method`}),children:`We paused automatic reloads after several declined payments. Add a new payment method to turn auto-reload back on.`}),(0,J.jsx)(`div`,{className:`grid transition-[grid-template-rows] duration-200 ease-in-out`,style:{gridTemplateRows:C&&!ee?`1fr`:`0fr`},children:(0,J.jsx)(`div`,{className:`overflow-hidden`,children:(0,J.jsxs)(`div`,{className:`mt-3 flex flex-col gap-3`,children:[!T&&(0,J.jsxs)(`div`,{className:`flex h-8 items-center justify-between gap-3 rounded-lg bg-[var(--system-mid-weak)] px-2`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(ge,{className:`h-4 w-4 shrink-0 text-[var(--system-mid-strong)]`,"aria-hidden":`true`}),(0,J.jsx)(p,{variant:`body-medium-default`,className:`truncate text-[var(--system-mid-strong)]`,children:`Extra usage requires you to connect a credit card.`})]}),(0,J.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,onClick:()=>E(!0),className:`flex shrink-0 cursor-pointer items-center justify-center rounded p-0.5 text-[var(--system-mid-strong)] opacity-70 transition-opacity hover:opacity-100`,children:(0,J.jsx)(be,{className:`h-2.5 w-2.5`,strokeWidth:2,"aria-hidden":`true`})})]}),(0,J.jsx)(i,{variant:`primary`,onClick:()=>O(!0),"data-testid":`auto-top-up-add-pm-button`,className:`self-start`,children:`Add a Credit Card`})]})})}),ae&&(0,J.jsx)(U,{tone:`error`,className:`mt-4`,"data-testid":`auto-top-up-update-error`,children:`Failed to save automatic top-ups. Please try again.`}),r.isError&&(0,J.jsx)(U,{tone:`error`,className:`mt-4`,"data-testid":`auto-top-up-disable-error`,children:`Failed to disable automatic top-ups. Please try again.`}),a.isError&&(0,J.jsx)(U,{tone:`error`,className:`mt-4`,"data-testid":`auto-top-up-remove-error`,children:`Failed to remove the payment method. Please try again.`}),R&&(0,J.jsx)(Kr,{initialValues:N?{threshold_usd:Qi(M.threshold_usd),amount_usd:Qi(M.amount_usd),monthly_cap_usd:Qi(M.monthly_cap_usd)}:void 0,submitting:n.isPending,serverErrors:ie,onCancel:P,onSave:ne}),(N||R)&&(0,J.jsx)(U,{tone:`info`,className:`mt-4`,children:`If you're too close to your monthly limit, the auto-reload will only top up to that limit.`}),(0,J.jsx)(Vr,{open:v,confirming:r.isPending,onCancel:te,onConfirm:re}),(0,J.jsx)(Ee,{open:b,title:`Remove payment method?`,message:`Removing your card will turn off Extra Usage.`,confirmLabel:a.isPending?`Removing…`:`Remove`,isPending:a.isPending,cancelLabel:`Keep card`,destructive:!0,onConfirm:F,onCancel:()=>S(!1)}),(0,J.jsx)(qi,{open:D,onClose:()=>O(!1),onSavedOptimistic:L})]})}function ia(e){let t=parseFloat(e);return Number.isFinite(t)?`$${t.toFixed(2)}`:`$${e}`}function aa(e){let t=e.trim();if(t===``)return`Enter a daily limit`;let n=parseFloat(t);if(!Number.isFinite(n)||n<1)return`Must be at least $1`;if(!/^\d+(\.\d{1,2})?$/.test(t))return`Use at most two decimal places`}function oa(){let e=l(),t=u(lt()),n=u(gt()),r=d(Ct()),[a,o]=(0,K.useState)(null),[s,c]=(0,K.useState)(!1),[f,p]=(0,K.useState)(!1);if(t.isLoading)return(0,J.jsx)(`div`,{"data-testid":`daily-credit-limit-card`,children:(0,J.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Loading…`})});if(t.isError||!t.data)return(0,J.jsx)(`div`,{"data-testid":`daily-credit-limit-card`,children:(0,J.jsx)(U,{tone:`error`,children:`Failed to load daily credit limit settings.`})});let m=t.data,h=m.daily_credit_limit_usd!=null,g=h||f,_=a??m.daily_credit_limit_usd??``,v=aa(_),y=n.data,b=y?.daily_spend_usd??m.current_day_spent_usd,x=y?.daily_limit_reached===!0,S=e=>{o(e.target.value)},C=t=>{r.mutate({body:{daily_credit_limit_usd:t}},{onSuccess:n=>{nt(e,void 0,n),e.invalidateQueries({queryKey:$e()}),e.invalidateQueries({queryKey:St()}),o(null),c(!1),t===null&&p(!1)}})},w=e=>{if(e){p(!0);return}p(!1),o(null),c(!1),h&&C(null)},T=()=>{c(!0),!v&&C(parseFloat(_.trim()).toFixed(2))},E=r.isError,D=s?v:void 0;return(0,J.jsxs)(`div`,{"data-testid":`daily-credit-limit-card`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(Te,{checked:g,onChange:w,disabled:r.isPending,label:`Set a daily credit limit`}),g&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,J.jsx)(`div`,{className:`w-60 max-w-full`,children:(0,J.jsx)(we,{type:`number`,step:`0.01`,min:`1`,label:`Stop spending Vellum credits after`,helperText:`Per UTC day. Resets at midnight UTC.`,placeholder:`0.00`,value:_,onChange:S,onBlur:()=>c(!0),errorText:D,"data-testid":`daily-credit-limit-input`,fullWidth:!0})}),(0,J.jsx)(`div`,{className:`flex shrink-0 items-center gap-2 pt-[18px]`,children:(0,J.jsx)(i,{variant:`primary`,onClick:T,disabled:r.isPending,"data-testid":`daily-credit-limit-save-button`,children:`Save`})})]}),h&&m.daily_credit_limit_usd!=null&&(0,J.jsxs)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,"data-testid":`daily-credit-limit-progress`,children:[ia(b),` of `,ia(m.daily_credit_limit_usd),` `,`spent today`]}),x&&(0,J.jsx)(U,{tone:`warning`,"data-testid":`daily-credit-limit-reached`,children:`Today's Vellum credit spend has reached this limit. Generation resumes after midnight UTC or when you raise the limit.`})]})]}),(0,J.jsx)(`p`,{className:`mt-3 text-body-small-default text-[var(--content-tertiary)]`,children:`Applies to Vellum credit spend only. Usage billed to your own provider API keys isn't limited. Resets at midnight UTC.`}),E&&(0,J.jsx)(U,{tone:`error`,className:`mt-4`,"data-testid":`daily-credit-limit-update-error`,children:`Failed to save daily credit limit. Please try again.`})]})}function sa(e){let t=parseFloat(e);return Number.isFinite(t)?`$${t.toFixed(2)}`:`$${e}`}function ca(e){if(e.trim()===``)return;let t=parseFloat(e);if(!Number.isFinite(t)||t<1||t>1e3)return`Must be between $1 and $1,000`;if(!/^\d+(\.\d{1,2})?$/.test(e.trim()))return`Use at most two decimal places`}function la(){let e=l(),t=u(dt()),n=d(at()),[r,a]=(0,K.useState)(null),[o,s]=(0,K.useState)(!1);if(t.isLoading)return(0,J.jsx)(`div`,{"data-testid":`low-balance-alert-card`,children:(0,J.jsx)(`p`,{className:`text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Loading…`})});if(t.isError||!t.data)return(0,J.jsx)(`div`,{"data-testid":`low-balance-alert-card`,children:(0,J.jsx)(U,{tone:`error`,children:`Failed to load low-balance alert settings.`})});let c=t.data,f=r??c.threshold_usd??``,p=ca(f),m=e=>{a(e.target.value)},h=t=>{n.mutate({body:{threshold_usd:t}},{onSuccess:t=>{ft(e,void 0,t),e.invalidateQueries({queryKey:ut()}),a(null),s(!1)}})},g=()=>{if(s(!0),p)return;let e=f.trim();h(e===``?null:parseFloat(e).toFixed(2))},_=()=>{a(``),s(!1),h(null)},v=n.isError,y=o?p:void 0;return(0,J.jsxs)(`div`,{"data-testid":`low-balance-alert-card`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,J.jsx)(`div`,{className:`w-60 max-w-full`,children:(0,J.jsx)(we,{type:`number`,step:`0.01`,label:`Alert me when my balance drops below`,helperText:`Default is ${sa(c.default_threshold_usd)} when unset`,placeholder:c.effective_threshold_usd,value:f,onChange:m,onBlur:()=>s(!0),errorText:y,"data-testid":`low-balance-alert-input`,fullWidth:!0})}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pt-[18px]`,children:[c.threshold_usd!=null&&(0,J.jsx)(i,{variant:`outlined`,onClick:_,disabled:n.isPending,"data-testid":`low-balance-alert-reset-button`,children:`Reset to default`}),(0,J.jsx)(i,{variant:`primary`,onClick:g,disabled:n.isPending,"data-testid":`low-balance-alert-save-button`,children:`Save`})]})]}),v&&(0,J.jsx)(U,{tone:`error`,className:`mt-4`,"data-testid":`low-balance-alert-update-error`,children:`Failed to save low-balance alert. Please try again.`})]})}function ua(e){return e.replace(/\.00$/,``)}function da({icon:e,value:t,label:n}){return(0,J.jsxs)(`div`,{className:`flex h-8 min-w-0 flex-1 items-center gap-1.5 rounded-lg bg-[var(--surface-base)] px-2 py-1.5`,children:[(0,J.jsx)(`span`,{"aria-hidden":`true`,className:`flex h-3.5 w-3.5 shrink-0 items-center justify-center text-[var(--content-default)]`,children:e}),(0,J.jsx)(p,{variant:`body-medium-default`,as:`span`,className:`text-[var(--content-default)]`,children:t}),(0,J.jsx)(p,{variant:`body-small-default`,as:`span`,className:`min-w-0 truncate text-[var(--content-tertiary)]`,children:n})]})}function fa(){let{data:e,isLoading:t,isError:n}=u(Dt()),[r,a]=(0,K.useState)(!1),o=(0,K.useCallback)(e=>{navigator.clipboard.writeText(e).then(()=>{a(!0),G.success(`Copied to clipboard!`),setTimeout(()=>a(!1),2e3)})},[]),s=e?.is_eligible_for_credits===!1;return(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`text-[var(--content-tertiary)]`,children:s?`Invite friends to Vellum. You'll start earning referral credits once you've purchased credits or upgraded to Pro.`:e?`Share Vellum with friends - you'll each earn ${ua(e.referrer_credit_amount)} credits when they sign up, up to ${ua(e.earning_cap)} total.`:`Share Vellum with friends and earn credits for every signup.`}),s&&(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`text-[var(--content-tertiary)]`,children:`You're not currently earning referral credits. Buy credits or upgrade to Pro to start earning — your invite link still works in the meantime.`}),t?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),`Loading...`]}):n||!e?(0,J.jsx)(U,{tone:`error`,children:`Failed to load referral information.`}):(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2`,children:[(0,J.jsx)(da,{icon:(0,J.jsx)(x,{className:`h-3.5 w-3.5`}),value:ua(e.total_earned),label:`Credits Earned`}),(0,J.jsx)(da,{icon:(0,J.jsx)(ye,{className:`h-3.5 w-3.5`}),value:e.referred_count,label:`Friends Referred`}),(0,J.jsx)(i,{variant:`outlined`,className:`shrink-0`,onClick:()=>o(e.referral_url),leftIcon:r?(0,J.jsx)(_,{className:`h-3.5 w-3.5`}):(0,J.jsx)(fe,{className:`h-3.5 w-3.5`}),"data-testid":`referral-copy-button`,children:r?`Copied!`:`Share Link`})]})]})}function pa({open:e,onOpenChange:t}){return(0,J.jsx)(W.Root,{open:e,onOpenChange:t,children:(0,J.jsxs)(W.Content,{"data-testid":`referral-modal`,children:[(0,J.jsx)(W.Header,{children:(0,J.jsx)(W.Title,{children:`Earn Free Credits`})}),(0,J.jsx)(W.Body,{children:(0,J.jsx)(fa,{})})]})})}var ma=2e3;function ha(e){let t=parseFloat(e);if(Number.isNaN(t))return`0`;let n=Math.abs(t).toLocaleString(`en-US`,{minimumFractionDigits:2,maximumFractionDigits:2}),r=n.endsWith(`.00`)?n.slice(0,-3):n;return t<0?`-${r}`:r}function ga(){let e=l(),{data:t,isLoading:n,isError:r}=u(gt()),a=t??null,[o,s]=(0,K.useState)(!1),[c,d]=(0,K.useState)(!1),[f,h]=(0,K.useState)(!1),g=(0,K.useRef)(0),_=(0,K.useRef)(null),v=it({onSuccess:()=>{e.invalidateQueries({queryKey:St()})},onError:()=>{g.current<3&&(_.current=setTimeout(()=>{v.reset()},ma))}});(0,K.useEffect)(()=>()=>{_.current&&clearTimeout(_.current)},[]);let y=v.mutate;(0,K.useEffect)(()=>{a&&a.settled_balance===`0.00`&&a.pending_compute===`0.00`&&a.effective_balance===`0.00`&&g.current<3&&!v.isPending&&!v.isError&&!v.isSuccess&&(g.current+=1,y({}))},[a,v.isPending,v.isError,v.isSuccess,y]);let b=(0,J.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between sm:gap-4`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(p,{as:`h2`,variant:`title-medium`,className:`text-[var(--content-emphasised)]`,children:`Credit Balance`}),(0,J.jsx)(p,{as:`p`,variant:`body-medium-default`,className:`mt-2 text-[var(--content-tertiary)]`,children:`Quick overview of your balances and other things`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(i,{variant:`outlined`,leftIcon:(0,J.jsx)(x,{className:`h-4 w-4`,"aria-hidden":!0}),onClick:()=>d(!0),"data-testid":`earn-credits-button`,children:`Earn Free Credits`}),(0,J.jsx)(i,{variant:`primary`,onClick:()=>s(!0),disabled:n||!a,"data-testid":`add-credits-button`,children:`Add Credits`})]})]});return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(m,{padding:`md`,children:[b,n?(0,J.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 text-body-medium-lighter text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),`Loading billing summary...`]}):r?(0,J.jsx)(`div`,{className:`mt-4`,children:(0,J.jsx)(U,{tone:`error`,children:`Failed to load billing summary. Please try again later.`})}):a?(0,J.jsxs)(J.Fragment,{children:[(()=>{if(!a)return null;let e=parseFloat(a.effective_balance)<0;return(0,J.jsx)(`div`,{className:`mt-4`,children:(0,J.jsx)(Se,{icon:(0,J.jsx)(x,{className:`h-4 w-4`,"aria-hidden":!0}),value:(0,J.jsx)(`span`,{"data-testid":`effective-balance`,children:ha(a.effective_balance)}),label:`Balance`,tone:e?`negative`:`default`})})})(),a.is_degraded&&(0,J.jsx)(`div`,{className:`mt-4`,children:(0,J.jsx)(U,{tone:`warning`,children:`Pending charges could not be calculated. The balance shown may be incomplete.`})})]}):(0,J.jsx)(`p`,{className:`mt-4 text-body-medium-lighter text-[var(--content-tertiary)]`,children:`No billing information available.`}),(0,J.jsx)(`div`,{className:`mt-6`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsx)(Te,{checked:f,onChange:h,label:`Custom low balance alert`}),f&&(0,J.jsx)(la,{})]})}),(0,J.jsx)(`div`,{className:`mt-6 border-t border-[var(--border-base)] pt-6`,children:(0,J.jsx)(ra,{})}),(0,J.jsx)(`div`,{className:`mt-6 border-t border-[var(--border-base)] pt-6`,children:(0,J.jsx)(oa,{})})]}),(0,J.jsx)(Pt,{open:o,onOpenChange:s}),(0,J.jsx)(pa,{open:c,onOpenChange:d})]})}var _a=1e3,va=15e3,ya=3e3,ba=45e3,xa=`billing-portal-return`;function Sa(e,t){if(!e)return{kind:`info`,message:`Subscription updated.`};let n=e.cancel_at_period_end||!!e.cancel_at,r=t.cancel_at_period_end||!!t.cancel_at;return!n&&r?{kind:`info`,message:`Pro plan canceled. You'll have access until ${t.cancel_at?M(t.cancel_at):`the end of your billing period`}.`}:n&&!r?{kind:`success`,message:`Pro plan reactivated.`}:{kind:`info`,message:`Subscription updated.`}}function Ca(){let[e]=o(),t=c(),n=l(),r=(0,K.useRef)(null);return(0,K.useEffect)(()=>()=>{r.current!==null&&(clearInterval(r.current),r.current=null)},[]),(0,K.useEffect)(()=>{if(e.get(`portal_return`)!==`true`)return;let i={current:!1},a=w(),o=bt(),s=Et(),c=Date.now();async function l(){await n.invalidateQueries({queryKey:s});let e=await n.fetchQuery(o);return{cancel_at_period_end:e.cancel_at_period_end,cancel_at:e.cancel_at}}async function u(){let e=await l();for(;!i.current&&a&&e.cancel_at_period_end===a.cancel_at_period_end&&e.cancel_at===a.cancel_at&&Date.now()-c<va&&(await new Promise(e=>setTimeout(e,_a)),!i.current);)e=await l();return e}return(async()=>{try{let e=await u();if(i.current)return;let{kind:t,message:n}=Sa(a,e);t===`success`?G.success(n,{id:xa}):G.info(n,{id:xa})}catch{if(i.current)return;G.info(`Subscription updated.`,{id:xa})}finally{if(!i.current){ue(),t(Be.settings.usageBilling,{replace:!0});let e=Date.now();r.current!==null&&clearInterval(r.current),r.current=setInterval(()=>{if(Date.now()-e>=ba){r.current!==null&&(clearInterval(r.current),r.current=null);return}l().catch(e=>{console.error(`billing poll error:`,e)})},ya)}}})(),()=>{i.current=!0}},[e,t,n]),null}var wa=[7,30,90].map(e=>({value:`${e}`,label:`Last ${e} days`}));function Ta(e,t=Xe()){let{fromDate:n,toDate:r}=Rt(e,t);return{from:n,to:r}}function Ea(e,t){let n=new Date(e),r=new Date(t);return Math.round((r.getTime()-n.getTime())/864e5)+1}function Da({from:e,to:t}){let n=Ea(e,t);return n===7?7:n===90?90:30}function Oa({value:e,onChange:t}){let n=kt(),r=(0,K.useMemo)(()=>`${Da(e)}`,[e]);return(0,J.jsx)(De,{options:wa,value:r,onChange:e=>{let r=Number(e);t(Ta(r,n),r)},"aria-label":`Date range`})}var ka={strokeDasharray:`3 3`,stroke:`var(--border-subtle)`,strokeOpacity:.4},Aa={fontSize:12,fill:`var(--content-tertiary)`},ja={stroke:`var(--border-subtle)`,strokeOpacity:.4},Ma=[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#06b6d4`,`#ec4899`,`#84cc16`];function Na({item:e}){return(0,J.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-[13px] text-[var(--content-default)]`,children:[(0,J.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:e.color}}),(0,J.jsx)(`span`,{children:e.label}),(0,J.jsx)(`span`,{className:`ml-auto tabular-nums`,children:e.value})]})}function Pa({active:e,payload:t,hoveredKey:n,label:r,labelMap:i,colorMap:a,formatValue:o,showTotal:s,formatLabel:c}){if(!e||!t?.length)return null;let l=t.filter(e=>e.value!=null&&e.dataKey!=null).map(e=>({key:String(e.dataKey),label:i[String(e.dataKey)]??String(e.dataKey),value:o(Number(e.value)),color:a[String(e.dataKey)]??`#6b7280`,numericValue:Number(e.value)})).sort((e,t)=>e.numericValue===t.numericValue?e.label.localeCompare(t.label):t.numericValue-e.numericValue),u=n?l.find(e=>e.key===n):null,d=u?l.filter(e=>e.key!==n):l,f=l.reduce((e,t)=>e+t.numericValue,0);return(0,J.jsxs)(`div`,{className:`rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-overlay)] px-3.5 py-2.5 shadow-[var(--shadow-popover)]`,children:[(0,J.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-[var(--content-secondary)]`,children:(c??Lt)(String(r))}),u&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Na,{item:u}),d.length>0&&(0,J.jsx)(`div`,{className:`my-1.5 border-t border-[var(--border-subtle)]`})]}),d.map(e=>(0,J.jsx)(Na,{item:e},e.key)),s&&(0,J.jsx)(`div`,{className:`mt-1 flex items-center gap-2 border-t border-[var(--border-subtle)] pt-1.5 text-[13px] font-semibold text-[var(--content-default)]`,children:(0,J.jsxs)(`span`,{children:[`Total: `,o(f)]})})]})}function Fa(e,t){let[n,r]=e,[i,a]=t,o=r-n||1;return e=>i+(e-n)/o*(a-i)}function Ia(e){if(e<=0)return 1;let t=10**Math.floor(Math.log10(e)),n=e/t,r;return r=n<=1?1:n<=2?2:n<=2.5?2.5:n<=5?5:10,r*t}function La(e){if(e>=1)return+!Number.isInteger(e);let t=e/10**Math.floor(Math.log10(e)),n=Math.abs(t-2.5)<.01;return Math.ceil(-Math.log10(e))+ +!!n}function Ra(e,t){let n=Math.max(0,...e),r=t?.tickCount??5;return n===0?t?.integerOnly?r:1:t?.integerOnly?Math.max(1,Math.ceil(n/r))*r:Ia(n/r)*r}function za(e,t){if(e===0)return[0];let n=e/t,r=10**(n>=1?0:Math.ceil(-Math.log10(n))+2),i=[];for(let e=0;e<=t;e++)i.push(Math.round(n*e*r)/r);return i}function Ba(e,t,n,r,i){let a=Math.min(i,n/2,r/2);return[`M${e},${t+a}`,`A${a},${a} 0 0 1 ${e+a},${t}`,`H${e+n-a}`,`A${a},${a} 0 0 1 ${e+n},${t+a}`,`V${t+r}`,`H${e}`,`Z`].join(``)}function Va(e,t){if(e<=0)return[];if(t)return e<=3?Array.from({length:e},(e,t)=>t):[0,Math.floor(e/2),e-1];let n=Math.max(1,Math.ceil(e/Math.min(e,12))),r=[];for(let t=0;t<e;t+=n)r.push(t);return r[r.length-1]!==e-1&&r.push(e-1),r}var Ha=40,Ua={fontSize:11,fill:`var(--content-tertiary)`},Wa={runtime_proxy_api:`#3b82f6`,oauth_proxy:`#f59e0b`};function Ga(e,t){return Wa[e]??Ma[t%Ma.length]??`#6b7280`}function Ka(e,t){let n=new Set,r={};for(let t of e)for(let e of t.groups)n.add(e.group_key),r[e.group_key]=e.group_label;return{data:e.map(e=>{let n={date:e.date};for(let r of e.groups)n[r.group_key]=t===`spend`?parseFloat(r.total_usd):r.event_count;return n}),stackKeys:Array.from(n),labelMap:r}}function qa({stackKeys:e,labelMap:t}){return(0,J.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-x-5 gap-y-1 pt-3 text-body-small-default`,children:e.map((e,n)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-sm`,style:{backgroundColor:Ga(e,n)}}),(0,J.jsx)(`span`,{className:`text-[var(--content-quiet)]`,children:t[e]??e})]},e))})}var Ja=350,Ya={top:8,right:4,bottom:32,left:0},Xa=.2,Za=5,Qa=12,$a=200;function eo({buckets:e,metric:t,onBarClick:n}){let r=Ye(),i=(0,K.useRef)(null),[a,o]=(0,K.useState)(0);(0,K.useEffect)(()=>{let e=i.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&o(e.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let{data:s,stackKeys:c,labelMap:l}=(0,K.useMemo)(()=>Ka(e,t),[e,t]),u=(0,K.useMemo)(()=>{let e={};for(let t=0;t<c.length;t++)e[c[t]]=Ga(c[t],t);return e},[c]),d=(0,K.useCallback)(e=>t===`spend`?`$${e.toLocaleString(`en-US`,{minimumFractionDigits:2,maximumFractionDigits:2})}`:e.toLocaleString(`en-US`),[t]),[f,p]=(0,K.useState)(null),m=r?Ha:56,h=r?Ua:Aa,g=Ya.left+m,_=Math.max(0,a-g-Ya.right),v=Ya.top,y=Ja-Ya.top-Ya.bottom,b=(0,K.useMemo)(()=>s.map(e=>c.reduce((t,n)=>t+(Number(e[n])||0),0)),[s,c]),x=t===`events`,S=(0,K.useMemo)(()=>Ra(b,{integerOnly:x,tickCount:Za}),[b,x]),C=(0,K.useMemo)(()=>za(S,Za),[S]),w=(0,K.useCallback)(e=>{if(t===`spend`){if(e===0)return`$0`;let t=S/Za,n=Math.max(t<1?2:0,La(t));return`$${e.toLocaleString(`en-US`,{minimumFractionDigits:n,maximumFractionDigits:n})}`}return e.toLocaleString(`en-US`)},[t,S]),T=(0,K.useMemo)(()=>Fa([0,S],[v+y,v]),[S,v,y]),E=s.length,D=E>0?_/E:0,O=D*(1-Xa),k=(D-O)/2,A=(0,K.useMemo)(()=>Va(E,r),[E,r]),j=c.length===0,M=j?[]:s.map((e,t)=>{let n=g+t*D+k,r=0;return{di:t,x:n,segments:c.map((t,i)=>{let a=Number(e[t])||0,o=r;r+=a;let s=T(r),l=T(o)-s,u=i===c.length-1;return{key:t,val:a,x:n,y:s,h:l,color:Ga(t,i),isLast:u}})}}),N=(e,t,n)=>{let r=i.current?.getBoundingClientRect();r&&p({x:e.clientX-r.left,y:e.clientY-r.top,datumIndex:t,hoveredKey:n})},ee=()=>p(null),P=e=>{n&&n(e)},te=f?c.filter(e=>(Number(s[f.datumIndex]?.[e])||0)>0).map(e=>({dataKey:e,value:Number(s[f.datumIndex]?.[e])||0})):[],ne={left:f?Math.max(0,Math.min(f.x+Qa,a-$a)):0,top:f?f.y-Qa:0,visibility:f?`visible`:`hidden`};return(0,J.jsxs)(`div`,{onMouseDown:e=>e.preventDefault(),children:[(0,J.jsx)(`div`,{ref:i,className:`relative w-full`,style:{height:Ja},children:j?(0,J.jsx)(`div`,{className:`flex h-full items-center justify-center text-body-medium-lighter text-[var(--content-faint)]`,children:`No usage data for this period`}):a>0?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`svg`,{width:a,height:Ja,className:`block`,children:[C.map(e=>(0,J.jsx)(`line`,{x1:g,x2:g+_,y1:T(e),y2:T(e),stroke:ka.stroke,strokeOpacity:ka.strokeOpacity,strokeDasharray:ka.strokeDasharray},e)),(0,J.jsx)(`line`,{x1:g,x2:g+_,y1:v+y,y2:v+y,stroke:ja.stroke,strokeOpacity:ja.strokeOpacity}),C.map(e=>(0,J.jsx)(`text`,{x:g-8,y:T(e),textAnchor:`end`,dominantBaseline:`middle`,fontSize:h.fontSize,fill:h.fill,children:w(e)},e)),A.map(e=>{let t=s[e];return t?(0,J.jsx)(`text`,{x:g+e*D+D/2,y:v+y+20,textAnchor:`middle`,fontSize:h.fontSize,fill:h.fill,children:Lt(String(t.date))},e):null}),M.map(({di:e,segments:t})=>t.map(t=>{if(t.h<=0)return null;let r=f?.hoveredKey&&f.hoveredKey!==t.key?.4:1,i={key:`${e}-${t.key}`,fill:t.color,opacity:r,cursor:n?`pointer`:void 0,onMouseMove:n=>N(n,e,t.key),onMouseLeave:ee,onClick:()=>P(t.key)};return t.isLast?(0,J.jsx)(`path`,{...i,d:Ba(t.x,t.y,O,t.h,3)}):(0,J.jsx)(`rect`,{...i,x:t.x,y:t.y,width:O,height:t.h})}))]}),(0,J.jsx)(`div`,{className:`pointer-events-none absolute z-[1] max-w-[calc(100vw-32px)] -translate-y-full`,style:ne,children:(0,J.jsx)(Pa,{active:!!f,payload:te,hoveredKey:f?.hoveredKey??void 0,label:f?String(s[f.datumIndex]?.date):``,labelMap:l,colorMap:u,formatValue:d})})]}):null}),!j&&(0,J.jsx)(qa,{stackKeys:c,labelMap:l})]})}function to(e=Xe()){return Ta(30,e)}function no(e){if(e)return e.usageSource===`oauth_proxy`?`oauth_provider`:$t(e.llmDimension??`model`)}function ro(e,t=Xe()){return{from:e.dateRange.from,to:e.dateRange.to,tz:t,...e.drilldown?{usage_source:e.drilldown.usageSource,group_by:no(e.drilldown)}:{}}}function io(e,t=Xe()){return{from:e.dateRange.from,to:e.dateRange.to,tz:t,...e.drilldown?{usage_source:e.drilldown.usageSource}:{}}}function ao(e,t,n){return e===`full`&&t!==`gated`&&n}function oo(e){let t=kt(),n=ao(Ve({platformHostedOnly:!0}),Ve(),Ue()),r=u({...vt({query:ro(e,t)}),enabled:n}),i=u({..._t({query:io(e,t)}),enabled:n});return{series:r.data,totals:i.data,isLoading:r.isLoading||i.isLoading,isError:r.isError||i.isError}}var so=[{value:`spend`,label:`Spend ($)`},{value:`events`,label:`Events`}];function co(e){if(e===void 0)return`—`;let t=parseFloat(e);return Number.isNaN(t)?`$0.00`:`$${t.toLocaleString(`en-US`,{minimumFractionDigits:2,maximumFractionDigits:2})}`}function lo(e){return e===void 0?`—`:e.toLocaleString(`en-US`)}function uo(){let e=kt(),[t,n]=(0,K.useState)(30),[r,i]=(0,K.useState)(()=>to(e)),a=(0,K.useMemo)(()=>t===null?r:Ta(t,e),[t,r,e]),o=(e,t)=>{n(t),i(e)},[s,c]=(0,K.useState)(null),[l,u]=(0,K.useState)(`spend`),{series:d,totals:f,isLoading:h,isError:_}=oo({dateRange:a,setDateRange:e=>{n(null),i(e)},drilldown:s,setDrilldown:c}),v=s?void 0:e=>{let t={runtime_proxy_api:`runtime_proxy`,oauth_proxy:`oauth_proxy`}[e];t&&c({usageSource:t,...t===`runtime_proxy`?{llmDimension:Jt}:{}})};return(0,J.jsx)(m,{padding:`md`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(p,{as:`h2`,variant:`title-medium`,className:`text-[var(--content-default)]`,children:`Credit Usage`}),(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`mt-2 text-[var(--content-tertiary)]`,children:`Overview of your spending habits.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2 [&_[role=combobox]]:h-8 [&_[role=radio]]:h-7`,children:[(0,J.jsx)(Oa,{value:a,onChange:o}),(0,J.jsx)(`div`,{className:`w-44`,children:(0,J.jsx)(xe,{items:so,value:l,onChange:u,ariaLabel:`Chart metric`})})]})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,J.jsx)(Se,{icon:(0,J.jsx)(x,{className:`h-4 w-4`,"aria-hidden":!0}),value:h?(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}):co(f?.total_usd),label:`Spend`}),(0,J.jsx)(Se,{icon:(0,J.jsx)(Ht,{className:`h-4 w-4`,"aria-hidden":!0}),value:h?(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":!0}):lo(f?.event_count),label:`Events`})]}),s&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`div`,{children:(0,J.jsxs)(`button`,{className:`flex items-center gap-1.5 text-body-medium-lighter text-[var(--content-tertiary)] transition-colors hover:text-[var(--content-secondary)]`,onClick:()=>c(null),children:[(0,J.jsx)(g,{className:`h-3.5 w-3.5`}),(0,J.jsx)(`span`,{children:`Back to all usage`}),(0,J.jsx)(`span`,{className:`text-[var(--content-tertiary)]`,children:`/`}),(0,J.jsx)(`span`,{className:`text-body-medium-default text-[var(--content-default)]`,children:s.usageSource===`runtime_proxy`?`LLM Spend`:`OAuth Spend`})]})}),s.usageSource===`runtime_proxy`&&(0,J.jsx)(`div`,{className:`w-56`,children:(0,J.jsx)(xe,{items:Xt,value:s.llmDimension??`model`,onChange:e=>c({usageSource:`runtime_proxy`,llmDimension:e}),ariaLabel:`LLM spend dimension`})})]}),h?(0,J.jsx)(`div`,{className:`flex h-[345px] items-center justify-center rounded-xl bg-[var(--surface-base)]`,children:(0,J.jsx)(H,{className:`h-6 w-6 animate-spin text-[var(--content-tertiary)]`})}):_?(0,J.jsx)(`div`,{className:`flex h-[345px] items-center justify-center rounded-xl bg-[var(--surface-base)] text-body-medium-lighter text-[var(--content-tertiary)]`,children:`Failed to load usage data.`}):d?(0,J.jsx)(`div`,{className:`rounded-xl bg-[var(--surface-base)] p-3`,children:(0,J.jsx)(eo,{buckets:d.buckets,metric:l,onBarClick:v})}):null]})})}function fo(){let{data:e}=u(bt()),t=k((0,K.useMemo)(()=>C(e),[e]));if(!e||e.plan_id!==`pro`||e.status===`canceled`||!e.cancel_at_period_end&&!e.cancel_at)return null;let n=T(e);return n?(0,J.jsx)(U,{tone:`info`,title:`Your Pro plan will end on ${M(n)}.`,actions:(0,J.jsx)(i,{variant:`outlined`,size:`compact`,onClick:()=>t.mutate({}),disabled:t.isPending,leftIcon:t.isPending?(0,J.jsx)(H,{className:`animate-spin`}):void 0,"data-testid":`grace-period-reactivate-button`,children:`Reactivate`}),"data-testid":`grace-period-banner`,children:`You'll keep Pro features until then.`}):null}var po={invoices:[]},mo=4;function ho(e){switch(e){case`paid`:return`positive`;case`open`:return`warning`;case`uncollectible`:return`negative`;default:return`neutral`}}function go(e,t){let n=t.toUpperCase();try{let t=new Intl.NumberFormat(void 0,{style:`currency`,currency:n}),r=t.resolvedOptions().maximumFractionDigits??2;return t.format(e/10**r)}catch{return`${(e/100).toFixed(2)} ${n}`}}function _o(e){return Nt(new Date(e*1e3),{alwaysShowYear:!0})}function vo(e){let t=document.createElement(`a`);t.href=e,t.target=`_blank`,t.rel=`noopener noreferrer`,document.body.appendChild(t),t.click(),t.remove()}function yo(){let[e,t]=(0,K.useState)(!1),[r,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(!1),l=u({enabled:e,queryKey:tt(),queryFn:async({signal:e})=>{let{data:t,response:n}=await ze({throwOnError:!1,signal:e});if(n?.status===404)return po;if(!n?.ok||!t)throw Error(`Failed to load invoices (${n?.status??`network error`})`);return t}}),d=l.data?.invoices??[],f=r?d:d.slice(0,mo),h=d.length>mo;async function g(){c(!0);try{let{data:e,response:t}=await Re({throwOnError:!1,parseAs:`blob`});if(!t?.ok||!(e instanceof Blob))throw Error(`Failed to download invoices (${t?.status??`network error`})`);let{saveFile:n}=await a(async()=>{let{saveFile:e}=await import(`./native-file-DQ9qLg0-.js`).then(e=>e.t);return{saveFile:e}},__vite__mapDeps([0,1,2,3,4]));await n(e,`invoices.zip`)}catch(e){n(e,{context:`download_all_invoices`}),G.error(`Failed to download invoices.`)}finally{c(!1)}}return(0,J.jsx)(m,{padding:`md`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(p,{as:`h2`,variant:`title-medium`,className:`text-[var(--content-default)]`,children:`Invoices`}),(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`mt-2 text-[var(--content-tertiary)]`,children:`Your billing history.`})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[e&&d.length>0&&(0,J.jsx)(i,{variant:`outlined`,leftIcon:s?(0,J.jsx)(H,{className:`animate-spin`}):(0,J.jsx)(me,{className:`h-4 w-4`}),onClick:g,disabled:s,"data-testid":`invoices-download-all`,children:`Download all`}),(0,J.jsx)(i,{variant:`outlined`,leftIcon:e?(0,J.jsx)(y,{className:`h-4 w-4`}):(0,J.jsx)(v,{className:`h-4 w-4`}),onClick:()=>t(e=>!e),"data-testid":`invoices-toggle`,children:e?`Hide invoices`:`Show invoices`})]})]}),e?l.isLoading?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-small-default`,children:`Loading invoices...`})]}):l.isError?(0,J.jsx)(U,{tone:`error`,children:`Failed to load invoices.`}):d.length===0?(0,J.jsx)(p,{as:`p`,variant:`body-small-default`,className:`py-6 text-center text-[var(--content-tertiary)]`,"data-testid":`invoices-empty`,children:`No Invoices Found`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`overflow-x-auto`,children:(0,J.jsxs)(`table`,{className:`w-full`,"data-testid":`invoices-table`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{className:`border-b border-[var(--border-base)] text-left`,children:[(0,J.jsx)(`th`,{className:`pb-2 pr-4 text-body-small-default text-[var(--content-tertiary)]`,children:`Date`}),(0,J.jsx)(`th`,{className:`pb-2 pr-4 text-body-small-default text-[var(--content-tertiary)]`,children:`Amount`}),(0,J.jsx)(`th`,{className:`pb-2 pr-4 text-body-small-default text-[var(--content-tertiary)]`,children:`Status`}),(0,J.jsx)(`th`,{className:`pb-2 text-body-small-default text-[var(--content-tertiary)]`,children:`Action`})]})}),(0,J.jsx)(`tbody`,{children:f.map(e=>(0,J.jsxs)(`tr`,{className:`border-b border-[var(--border-base)] last:border-0`,"data-testid":`invoice-row`,children:[(0,J.jsx)(`td`,{className:`py-3 pr-4`,children:(0,J.jsx)(p,{as:`span`,variant:`body-small-default`,className:`text-[var(--content-secondary)]`,children:_o(e.created)})}),(0,J.jsx)(`td`,{className:`py-3 pr-4`,children:(0,J.jsx)(p,{as:`span`,variant:`body-small-default`,className:`text-[var(--content-secondary)]`,children:go(e.amount_due,e.currency)})}),(0,J.jsx)(`td`,{className:`py-3 pr-4`,children:e.status&&(0,J.jsx)(Ce,{tone:ho(e.status),children:e.status})}),(0,J.jsx)(`td`,{className:`py-3`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.hosted_invoice_url&&(0,J.jsx)(i,{asChild:!0,variant:`ghost`,size:`compact`,leftIcon:(0,J.jsx)(he,{className:`h-3.5 w-3.5`}),children:(0,J.jsx)(`a`,{href:e.hosted_invoice_url,target:`_blank`,rel:`noopener noreferrer`,children:`View`})}),e.invoice_pdf&&(0,J.jsx)(i,{variant:`ghost`,size:`compact`,iconOnly:(0,J.jsx)(me,{className:`h-3.5 w-3.5`}),"aria-label":`Download invoice PDF`,onClick:()=>vo(e.invoice_pdf)})]})})]},e.id))})]})}),h&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`self-start text-body-small-default text-[var(--content-tertiary)] transition-colors hover:text-[var(--content-secondary)]`,"data-testid":`invoices-show-more`,children:r?`Show less`:`Show more (${d.length-mo} more)`})]}):null]})})}function bo({title:e,blurb:t,ctaLabel:n,ctaTestId:r,pending:a=!1,disabled:o=!1,onCtaClick:s,className:c}){return(0,J.jsxs)(`div`,{"data-theme":`dark`,className:At(`flex min-w-0 flex-1 flex-col items-center justify-center gap-5 rounded-xl bg-[var(--surface-base)] py-5 pl-3 pr-4`,c),children:[(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-center`,children:[(0,J.jsx)(p,{as:`span`,variant:`body-large-default`,className:`text-[var(--content-default)]`,children:e}),t?(0,J.jsx)(p,{as:`span`,variant:`body-small-default`,className:`text-[var(--content-secondary)]`,children:t}):null]}),(0,J.jsx)(i,{variant:`primary`,className:`h-8 shrink-0`,onClick:s,disabled:o||a,leftIcon:a?(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}):void 0,"data-testid":r,children:n})]})}function xo({icon:e,label:t,multiline:n=!1}){return(0,J.jsxs)(`div`,{className:At(`flex items-center gap-1.5 rounded-lg bg-[var(--surface-overlay)] px-2 py-1.5`,n?`min-h-8 min-w-0`:`h-8`),children:[(0,J.jsx)(e,{className:`h-3.5 w-3.5 shrink-0 text-[var(--content-default)]`,"aria-hidden":!0}),(0,J.jsx)(p,{as:`span`,variant:`body-medium-default`,className:At(`text-[var(--content-default)]`,n?`whitespace-normal`:`whitespace-nowrap`),children:t})]})}function So({tierKey:e,name:t,nameTestId:n,tag:r,specs:i,className:a}){let o=i!=null&&i.length>0;return(0,J.jsxs)(`div`,{"data-theme":`light`,className:At(`flex min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-xl bg-[var(--surface-base)] py-3 pl-3 pr-4`,a),children:[o?(0,J.jsx)(`div`,{className:`h-px w-full bg-[var(--border-base)]`}):null,(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(P,{tier:e,size:48}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,J.jsx)(p,{as:`span`,variant:`body-large-default`,className:`text-[var(--content-default)]`,"data-testid":n,children:t}),r]})]}),o?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`h-px w-full bg-[var(--border-base)]`}),(0,J.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:i.map(e=>(0,J.jsx)(xo,{icon:e.icon,label:e.label,multiline:e.multiline},e.label))})]}):null]})}var Co={pro:{actionLabel:`Manage`,actionVariant:`outlined`,actionTestId:`plan-card-manage-button`,showsRenewal:!0},base:{actionLabel:`View All Plans`,actionVariant:`primary`,actionTestId:`plan-card-upgrade-button`,showsRenewal:!0}},wo=Co.pro;function To(){return(0,J.jsx)(p,{as:`h2`,variant:`title-medium`,className:`text-[var(--content-emphasised)]`,children:`Plan`})}function Eo({packages:e,proPlan:t,currentKey:n,isProUser:r,canChangePackage:i,relation:a,onManage:o,onTierUpgraded:s}){let c=l(),u=d(mt()),{changePackage:f,isPending:p}=te(),{changeTiers:m,isPending:h,current:g,currentReady:_}=le({enabled:r}),[v,y]=(0,K.useState)(!1),[b,x]=(0,K.useState)(!1),[S,C]=(0,K.useState)(!1);ce();let w=(0,K.useMemo)(()=>!r||g.storageTier==null?null:{machineTier:g.machineTier,storageTier:g.storageTier,creditTier:g.creditTier},[r,g.machineTier,g.storageTier,g.creditTier]),T=L(e,n),E=e.length>0,O=T!=null&&a!==`switch`,k=r&&E&&(a===`switch`||T==null&&n!=null&&e.some(e=>e.key===n)),A=v||u.isPending||p,M=async()=>{if(!T)return;let e=await f(T.key);e&&(x(!1),e.status===`ok`?s?.():G.success(`You're already on this plan.`))},N=async()=>{if(T){if(r&&!i){o();return}if(r){x(!0);return}y(!0);try{let e=await u.mutateAsync({body:{target_plan_id:`pro`,package:T.key,confirm:!0,return_target:j()}});e.status===`redirect`&&e.checkout_url?(D({kind:`package`,packageKey:T.key}),Ge(e.checkout_url)):(await c.invalidateQueries({queryKey:Et()}),await c.invalidateQueries({queryKey:ht()}))}catch(e){G.error(oe(e,`Failed to start the upgrade checkout. Please try again.`))}finally{y(!1)}}},ee=async e=>{let t=await m(e);t&&(C(!1),t.needsResize?s?.():G.success(t.creditChanged?`Credit bundle updated.`:`Plan updated.`))},P=()=>{if(!i){o();return}if(!(h||!_)){if(w==null){o();return}C(!0)}},ne=i&&(h||!_);return O?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(bo,{className:`lg:flex-[2]`,title:`Upgrade to ${T.name}`,blurb:I(T.key)?.upgradeBlurb,ctaLabel:`Upgrade`,ctaTestId:`recommended-upgrade-button`,pending:A,onCtaClick:()=>void N()}),(0,J.jsx)(ae,{open:b,relation:a,packageName:T.name,targetPackage:T,pending:A,onConfirm:()=>void M(),onCancel:()=>x(!1)})]}):k&&t?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(bo,{className:`lg:flex-[2]`,title:`Create a custom plan`,ctaLabel:`Customize`,ctaTestId:`recommended-customize-button`,pending:h,disabled:ne,onCtaClick:P}),(0,J.jsx)(R,{open:S,proPlan:t,pending:h,currentStorageGib:g.storageGib,initialSelection:w,onClose:()=>C(!1),onContinue:e=>void ee(e)})]}):null}function Do({onManage:e,onTierUpgraded:t}){let n=c(),r=u(bt()),a=u(Ze());if(r.isLoading||a.isLoading)return(0,J.jsxs)(m,{padding:`md`,children:[(0,J.jsx)(To,{}),(0,J.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 text-[var(--content-tertiary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),(0,J.jsx)(p,{as:`span`,variant:`body-small-default`,children:`Loading plan...`})]})]});let o=r.data,s=a.data?.plans,l=s?.find(e=>e.id===o?.plan_id);if(r.isError||a.isError||!o||!s||!l)return(0,J.jsx)(U,{tone:`error`,children:`Failed to load plan.`});let d=Co[l.id]??wo,f=l.id===`pro`?O(o.package):l.name??l.id,h=d.showsRenewal&&(o.cancel_at_period_end===!0||!!o.cancel_at),g=o.status===`canceled`,_=T(o),v=d.showsRenewal&&!h&&!g&&o.current_period_end,y=d.showsRenewal&&h&&!g&&_,b=s.find(e=>e.id===`pro`),x=b?.packages??[],C=o.package?.key??null,w=C??`free`,E=x.length>0&&(l.id===`base`||S(o.package)||ie(o)),D=ie(o),k=l.id===`base`||S(o.package)?`upgrade`:`switch`,A=l.id!==`base`&&S(o.package)?x.find(e=>e.key===C)??null:null,j=A?se(A):null;return(0,J.jsx)(m,{padding:`md`,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,J.jsx)(To,{}),v&&(0,J.jsxs)(p,{variant:`body-small-default`,as:`div`,className:`leading-snug text-[var(--content-tertiary)]`,"data-testid":`plan-card-renews`,children:[`Monthly Payment • Your subscription will auto renew on`,` `,M(o.current_period_end),`.`]}),y&&(0,J.jsxs)(p,{variant:`body-small-default`,as:`div`,className:`leading-snug text-[var(--system-mid-strong)]`,"data-testid":`plan-card-cancels`,children:[`Your plan ends on `,M(_),`.`]})]}),(0,J.jsx)(i,{variant:d.actionVariant,onClick:E?()=>n(Be.plans):e,"data-testid":d.actionTestId,className:`shrink-0`,children:d.actionLabel})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 lg:flex-row lg:items-stretch`,children:[(0,J.jsx)(So,{tierKey:w,name:f,nameTestId:`plan-card-name`,className:`lg:flex-[3]`,tag:(0,J.jsx)(Ce,{className:`bg-[var(--feed-digest-weak)] text-[var(--content-default)]`,children:`Current Plan`}),specs:j}),(0,J.jsx)(Eo,{packages:x,proPlan:b,currentKey:C,isProUser:l.id!==`base`,canChangePackage:D,relation:k,onManage:e,onTierUpgraded:t})]})]})})}function Oo(){let[e]=o(),t=c(),n=l();return(0,K.useEffect)(()=>{let r=e.get(`billing_status`);r&&(r===`success`?(G.success(`Payment received! Your credit balance will update shortly.`,{id:`billing-status`}),n.invalidateQueries({queryKey:gt().queryKey})):r===`cancel`&&G.info(`Checkout was cancelled. No credits were added.`,{id:`billing-status`}),t(Be.settings.usageBilling,{replace:!0}))},[e,t,n]),null}function ko({onFinishSetup:e}){let t=We(),{data:n}=u({...bt(),enabled:t}),r=n?.plan_id===`pro`,{data:a}=u({...wt(),enabled:r&&t}),o=r&&a?.domain_setup_available===!0,{domains:s}=E(o,a?.primary_assistant_id),c=s!==void 0&&s.results.length===0;return!o||!c?null:(0,J.jsx)(U,{tone:`info`,title:`Finish setting up your ${O(n?.package)} plan`,actions:(0,J.jsx)(i,{variant:`outlined`,size:`compact`,onClick:e,"data-testid":`finish-pro-setup-button`,children:`Finish setup`}),"data-testid":`finish-pro-setup-notice`,children:`Your assistant's email address hasn't been set up yet.`})}function Ao(){let e=Ve({platformHostedOnly:!0}),t=Ve(),n=Ue(),r=He(),[i,a]=o(),[s,c]=(0,K.useState)(!1),l=(0,K.useCallback)(()=>c(!0),[]),u=(0,K.useCallback)(()=>c(!1),[]),[d,f]=(0,K.useState)(!1),p=(0,K.useCallback)(()=>f(!0),[]),[m,h]=(0,K.useState)(!1);(0,K.useEffect)(()=>{if(t!==`full`)return;let e=i.has(`adjust_plan`),n=i.has(`pro_onboarding`);!e&&!n||(e&&c(!0),n&&h(!0),a(e=>{let t=new URLSearchParams(e);return t.delete(`adjust_plan`),t.delete(`pro_onboarding`),t},{replace:!0}))},[t,i,a]);let g=i.has(`session_id`),_=(0,K.useCallback)(()=>{h(!1),a(e=>{let t=new URLSearchParams(e);return t.delete(`session_id`),t},{replace:!0})},[a]),v=(0,K.useCallback)(()=>{a(e=>{let t=new URLSearchParams(e);return t.set(`pro_onboarding`,``),t},{replace:!0})},[a]);if(t===`disabled`)return(0,J.jsx)(`div`,{className:`space-y-4`,children:(0,J.jsx)(jt,{children:`Log in to the Vellum platform to manage billing and usage.`})});if(r)return(0,J.jsx)(`div`,{className:`space-y-4`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-2 py-6 text-body-medium-lighter text-[var(--content-secondary)]`,children:[(0,J.jsx)(H,{className:`h-4 w-4 animate-spin`}),`Loading billing…`]})});let y=n;return!n&&e!==`gated`?(0,J.jsx)(`div`,{className:`space-y-4`,children:(0,J.jsx)(U,{tone:`warning`,children:`Billing isn't available for the current assistant state.`})}):(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(K.Suspense,{fallback:null,children:[(0,J.jsx)(Oo,{}),(0,J.jsx)(Ca,{})]}),y&&(0,J.jsx)(fo,{}),y&&(0,J.jsx)(ko,{onFinishSetup:v}),y&&(0,J.jsx)(Do,{onManage:l,onTierUpgraded:p}),y&&(0,J.jsx)(Br,{open:s,onClose:u,onTierUpgraded:p}),(0,J.jsx)(K.Suspense,{fallback:null,children:(0,J.jsx)(ga,{})}),(0,J.jsx)(K.Suspense,{fallback:null,children:(0,J.jsx)(yo,{})}),y&&(0,J.jsx)(A,{open:g||m,onClose:_}),y&&(0,J.jsx)(A,{mode:`resize`,open:d,onClose:()=>f(!1)})]})}function jo(){let e=Mt(),t=Ve({platformHostedOnly:!0}),n=Ve();return(0,J.jsxs)(`div`,{className:`space-y-4`,children:[t===`full`&&n!==`gated`&&(0,J.jsx)(uo,{}),(0,J.jsx)(_r,{assistantId:e})]})}function Mo(){let e=Ve(),[t,n]=o(),r=Gt(e,t),i=r&&t.get(`tab`)!==`usage`?`billing`:`usage`,a=Le();return(0,K.useEffect)(()=>{if(a&&t.get(`tab`)!==i){let e=new URLSearchParams(t);e.set(`tab`,i),n(e,{replace:!0})}},[a,t,i,n]),(0,J.jsx)(`div`,{className:`space-y-6`,children:(0,J.jsxs)(V.Root,{value:i,onValueChange:e=>{let r=new URLSearchParams(t);r.set(`tab`,e),n(r,{replace:!0})},children:[(0,J.jsxs)(V.List,{children:[r&&(0,J.jsx)(V.Trigger,{value:`billing`,children:`Billing`}),(0,J.jsx)(V.Trigger,{value:`usage`,children:`Usage`})]}),r&&(0,J.jsx)(V.Panel,{value:`billing`,className:`pt-4`,children:(0,J.jsx)(Ao,{})}),(0,J.jsx)(V.Panel,{value:`usage`,className:`pt-4`,children:(0,J.jsx)(jo,{})})]})})}export{Mo as BillingPage};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./jsx-runtime-D3ZM-ToX.js";import{t as r}from"./sound-manager-xEbUgFv-.js";import{t as i}from"./proxy-RtD8704m.js";import{t as a}from"./use-reduced-motion-Se97jRQ-.js";import{t as o}from"./animated-avatar-DzfEDnTh.js";var s=e(t(),1),c=n();function l({components:e,traits:t,customImageUrl:n,size:l=28,className:u,interactive:d=!1,isAssistantBusy:f=!1,originAnchor:p=!1}){let m=a(),[h,g]=(0,s.useState)(!1),_=p?{"data-voice-origin":``}:{},v=(0,s.useCallback)(()=>{r().play(`character_poke`),!m&&(g(!0),window.setTimeout(()=>g(!1),360))},[m]),y=d?v:void 0,b=(0,s.useMemo)(()=>{if(t)return t;if(!e)return null;let n=e.bodyShapes[0],r=e.eyeStyles[0],i=e.colors[0];return!n||!r||!i?null:{bodyShape:n.id,eyeStyle:r.id,color:i.id}},[t,e]),x=!!e&&!!b&&(!!t||!n),S={width:l,height:l,flexShrink:0,cursor:d?`pointer`:void 0,transformOrigin:`center`,position:`relative`},C=m?{duration:0}:{type:`spring`,visualDuration:.3,bounce:.5},w=m?{scale:1,opacity:1}:{scale:.6,opacity:0},T={scale:h?1.15:1,opacity:1};return x?(0,c.jsx)(i.div,{..._,className:u,style:S,onClick:y,initial:w,animate:T,transition:C,children:(0,c.jsx)(o,{components:e,traits:b,size:l,isAssistantBusy:f})}):n?(0,c.jsx)(i.div,{..._,onClick:y,initial:w,animate:T,transition:C,style:{cursor:d?`pointer`:void 0,transformOrigin:`center`,position:`relative`,width:l,height:l,flexShrink:0},children:(0,c.jsx)(`img`,{src:n,alt:`Assistant avatar`,width:l,height:l,className:`rounded-full object-cover ${u??``}`,style:{width:l,height:l,flexShrink:0}})}):(0,c.jsx)(i.div,{..._,className:`flex items-center justify-center rounded-full bg-[var(--primary-base)] text-[var(--content-inset)] ${u??``}`,style:{...S,fontSize:l*.45},onClick:y,initial:w,animate:T,transition:C,children:`V`})}var u=(0,s.memo)(l);export{u as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./jsx-runtime-D3ZM-ToX.js";import{t as r}from"./sound-manager-xEbUgFv-.js";import{t as i}from"./proxy-RtD8704m.js";import{t as a}from"./use-reduced-motion-Se97jRQ-.js";import{t as o}from"./animated-avatar-BQyRNU0U.js";var s=e(t(),1),c=n();function l({components:e,traits:t,customImageUrl:n,size:l=28,className:u,interactive:d=!1,isAssistantBusy:f=!1,originAnchor:p=!1}){let m=a(),[h,g]=(0,s.useState)(!1),_=p?{"data-voice-origin":``}:{},v=(0,s.useCallback)(()=>{r().play(`character_poke`),!m&&(g(!0),window.setTimeout(()=>g(!1),360))},[m]),y=d?v:void 0,b=(0,s.useMemo)(()=>{if(t)return t;if(!e)return null;let n=e.bodyShapes[0],r=e.eyeStyles[0],i=e.colors[0];return!n||!r||!i?null:{bodyShape:n.id,eyeStyle:r.id,color:i.id}},[t,e]),x=!!e&&!!b&&(!!t||!n),S={width:l,height:l,flexShrink:0,cursor:d?`pointer`:void 0,transformOrigin:`center`,position:`relative`},C=m?{duration:0}:{type:`spring`,visualDuration:.3,bounce:.5},w=m?{scale:1,opacity:1}:{scale:.6,opacity:0},T={scale:h?1.15:1,opacity:1};return x?(0,c.jsx)(i.div,{..._,className:u,style:S,onClick:y,initial:w,animate:T,transition:C,children:(0,c.jsx)(o,{components:e,traits:b,size:l,isAssistantBusy:f})}):n?(0,c.jsx)(i.div,{..._,onClick:y,initial:w,animate:T,transition:C,style:{cursor:d?`pointer`:void 0,transformOrigin:`center`,position:`relative`,width:l,height:l,flexShrink:0},children:(0,c.jsx)(`img`,{src:n,alt:`Assistant avatar`,width:l,height:l,className:`rounded-full object-cover ${u??``}`,style:{width:l,height:l,flexShrink:0}})}):(0,c.jsx)(i.div,{..._,className:`flex items-center justify-center rounded-full bg-[var(--primary-base)] text-[var(--content-inset)] ${u??``}`,style:{...S,fontSize:l*.45},onClick:y,initial:w,animate:T,transition:C,children:`V`})}var u=(0,s.memo)(l);export{u as t};
@@ -1,4 +1,4 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-Dy5001j6.js";import{t as r}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as i}from"./QueryClientProvider-CMu7CkQU.js";import{t as a}from"./useQuery-Bz-fbQ-m.js";import{t as o}from"./jsx-runtime-D3ZM-ToX.js";import{t as s}from"./card-DRIctGVs.js";import{t as c}from"./createLucideIcon-CAM1RhH8.js";import{t as l}from"./brain-BIzJCPA6.js";import{n as u,t as d}from"./upload-Bdbyo_ok.js";import{t as f}from"./chevron-left-CytMddTB.js";import{t as p}from"./chevron-right-HU6H84S0.js";import{t as m}from"./dices-DcuIF52A.js";import{t as h}from"./folder-open-Nlg0OphT.js";import{t as g}from"./layout-grid-DA_CfD6d.js";import{t as _}from"./pencil-D38YNe2r.js";import{t as v}from"./sparkles-Ccrj7hxd.js";import{t as y}from"./users-iLvfYFOP.js";import{n as b,t as x}from"./installed-plugins-query-C29LGAEV.js";import"./src-te3YTBG-.js";import{t as S}from"./modal-BR4CUFBd.js";import{n as C}from"./toast-LgLp4obE.js";import{E as w,St as T,b as E,ht as D,ln as O,o as k,t as A}from"./react-query.gen-r3I6j8-1.js";import{t as j}from"./assistant-identity-store-DIyVo8LV.js";import{n as M,u as N}from"./routes-vE-2hncW.js";import{n as P,t as F}from"./eye-bbox-DXmmg9ML.js";import{a as ee,n as te,o as I,r as ne}from"./use-assistant-avatar-DSu2_Mzi.js";import{t as L}from"./plugins-surface-D4i2vqBz.js";import{t as R}from"./proxy-RtD8704m.js";import{t as z}from"./use-reduced-motion-Se97jRQ-.js";import{r as B}from"./avatar-tone-CMoWR2JX.js";import{t as V}from"./chat-avatar-BnRnoKo8.js";import{t as re}from"./avatar-renderer-DK54o2kQ.js";import{t as H}from"./use-active-assistant-id-CXhDyK7y.js";import{t as ie}from"./page-shell-BEWoPpRT.js";import{a as ae,i as oe,n as U,o as W}from"./latest-assistant-text-C4DnCZXH.js";import{a as G,n as se,r as K,s as ce,t as le}from"./use-assistant-identity-details-7N1jAxdm.js";import{t as ue}from"./schedules-CKGVEPqD.js";import{t as de}from"./get-memory-stats-D5-UCwt0.js";var fe=c(`radio`,[[`path`,{d:`M16.247 7.761a6 6 0 0 1 0 8.478`,key:`1fwjs5`}],[`path`,{d:`M19.075 4.933a10 10 0 0 1 0 14.134`,key:`ehdyv1`}],[`path`,{d:`M4.925 19.067a10 10 0 0 1 0-14.134`,key:`1q22gi`}],[`path`,{d:`M7.753 16.239a6 6 0 0 1 0-8.478`,key:`r2q7qm`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),q=e(t(),1),J=o();function Y(e,t,n){return n===`forward`?(e+1)%t:(e-1+t)%t}function pe({open:e,onClose:t,assistantId:r,components:i,traits:a,customImageUrl:o,onSaveCharacter:s,onUploadImage:c,assistantName:l,onRenameSubmit:u,isRenaming:f=!1}){let p=(0,q.useRef)(null),[h,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(!1),y=i??h,[b,x]=(0,q.useState)(0),[C,w]=(0,q.useState)(0),[T,E]=(0,q.useState)(0),[D,O]=(0,q.useState)(`character`),[k,A]=(0,q.useState)(null),[j,M]=(0,q.useState)(!1),[N,P]=(0,q.useState)(!1),[F,te]=(0,q.useState)(l??``),L=k??o,R=!!L;(0,q.useEffect)(()=>{e&&te(l??``)},[e,l]);let z=(0,q.useRef)(!1);(0,q.useEffect)(()=>{e&&!z.current&&O(o?`custom`:`character`),z.current=e},[e,o]),(0,q.useEffect)(()=>{if(e)if(y&&a){let e=y.bodyShapes.findIndex(e=>e.id===a.bodyShape),t=y.eyeStyles.findIndex(e=>e.id===a.eyeStyle),n=y.colors.findIndex(e=>e.id===a.color);x(e>=0?e:0),w(t>=0?t:0),E(n>=0?n:0)}else x(0),w(0),E(0)},[e,y,a]),(0,q.useEffect)(()=>{if(!e||y||_)return;let t=!1;return v(!0),ne(r).then(e=>{t||(g(e),v(!1))}),()=>{t=!0}},[e,y,_,r]),(0,q.useEffect)(()=>{if(k)return()=>{URL.revokeObjectURL(k)}},[k]),(0,q.useEffect)(()=>{e||A(null)},[e]);let B=F.trim(),V=!!u&&B.length>0&&B!==(l??``),H=(0,q.useCallback)(()=>{y&&(O(`character`),x(Math.floor(Math.random()*y.bodyShapes.length)),w(Math.floor(Math.random()*y.eyeStyles.length)),E(Math.floor(Math.random()*y.colors.length)))},[y]),ie=(0,q.useCallback)(()=>{p.current?.click()},[]),ae=(0,q.useCallback)(async e=>{let t=e.target.files?.[0];if(!t)return;P(!0);let n=await I(r,t);P(!1),n&&(c(),A(URL.createObjectURL(t)),O(`custom`)),p.current&&(p.current.value=``)},[r,c]),oe=(0,q.useCallback)(async e=>{if(e.preventDefault(),!(j||f)){if(V&&u&&u(B),y&&D===`character`){let e={bodyShape:y.bodyShapes[b].id,eyeStyle:y.eyeStyles[C].id,color:y.colors[T].id};M(!0);try{await ee(r,e),A(null),s(e)}finally{M(!1)}}t()}},[j,f,V,u,B,y,D,b,C,T,r,s,t]),U=y?.bodyShapes[b],W=y?.eyeStyles[C],G=y?.colors[T],se=D===`custom`&&R,K=l!==void 0&&u?(0,J.jsx)(me,{value:F,onChange:te,disabled:f}):null;return(0,J.jsx)(S.Root,{open:e,onOpenChange:e=>!e&&t(),children:(0,J.jsxs)(S.Content,{size:`sm`,children:[(0,J.jsx)(S.Header,{children:(0,J.jsx)(S.Title,{children:`Update Avatar`})}),(0,J.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:oe,children:[(0,J.jsx)(S.Body,{className:`space-y-4`,children:se?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`flex justify-center`,children:(0,J.jsx)(`div`,{className:`rounded-2xl bg-[var(--surface-sunken)] p-6`,children:(0,J.jsx)(`img`,{src:L,alt:`Uploaded avatar`,className:`h-40 w-40 rounded-xl object-cover`})})}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[K,(0,J.jsx)(he,{label:`Use a character instead`,description:`Pick from our built-in avatars`,onClick:()=>O(`character`),thumbnail:y&&U&&W&&G?(0,J.jsx)(re,{components:y,bodyShapeId:U.id,eyeStyleId:W.id,colorId:G.id,size:32}):(0,J.jsx)(m,{className:`h-4 w-4`,style:{color:`var(--content-secondary)`}})})]})]}):y?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`flex justify-center`,children:(0,J.jsx)(`div`,{className:`rounded-2xl bg-[var(--surface-sunken)] p-6`,children:(0,J.jsx)(re,{components:y,bodyShapeId:U.id,eyeStyleId:W.id,colorId:G.id,size:160})})}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[K,(0,J.jsx)(ge,{label:`Body`,value:U.id,onPrev:()=>x(Y(b,y.bodyShapes.length,`backward`)),onNext:()=>x(Y(b,y.bodyShapes.length,`forward`))}),(0,J.jsx)(ge,{label:`Eyes`,value:W.id,onPrev:()=>w(Y(C,y.eyeStyles.length,`backward`)),onNext:()=>w(Y(C,y.eyeStyles.length,`forward`))}),(0,J.jsx)(ge,{label:`Color`,value:G.id,colorHex:G.hex,onPrev:()=>E(Y(T,y.colors.length,`backward`)),onNext:()=>E(Y(T,y.colors.length,`forward`))})]}),R&&(0,J.jsx)(he,{label:`Keep your uploaded image`,description:`Saving the character replaces it`,onClick:()=>O(`custom`),thumbnail:(0,J.jsx)(`img`,{src:L,alt:``,className:`h-8 w-8 rounded-md object-cover`})})]}):(0,J.jsxs)(J.Fragment,{children:[K,_?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,J.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-[var(--border-element)] border-t-[var(--content-tertiary)]`})}):(0,J.jsx)(`div`,{className:`py-8 text-center text-body-medium-lighter text-[var(--content-quiet)]`,children:`Unable to load avatar components. Make sure your assistant is running.`})]})}),(0,J.jsxs)(S.Footer,{className:`justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(n,{type:`button`,variant:`outlined`,iconOnly:(0,J.jsx)(m,{}),"aria-label":`Randomize`,tooltip:`Randomize`,onClick:H,disabled:!y}),(0,J.jsx)(n,{type:`button`,variant:`outlined`,iconOnly:(0,J.jsx)(d,{}),"aria-label":`Upload image`,tooltip:`Upload image`,onClick:ie,disabled:N})]}),(0,J.jsx)(n,{type:`submit`,variant:`primary`,disabled:j||f||N,children:j||f?`Saving…`:`Save`})]})]}),(0,J.jsx)(`input`,{ref:p,type:`file`,accept:`image/png,image/jpeg,image/webp,image/gif`,className:`hidden`,onChange:ae})]})})}function me({value:e,onChange:t,disabled:n}){return(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-3 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-lift)] px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-body-small-default uppercase tracking-wider text-[var(--content-quiet)]`,children:`Name`}),(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`flex min-w-[80px] items-center justify-center`,children:(0,J.jsx)(`input`,{value:e,onChange:e=>t(e.target.value),disabled:n,maxLength:40,size:8,placeholder:`Name`,"aria-label":`Name`,className:`h-7 min-w-0 field-sizing-content bg-transparent text-center text-body-medium-default text-[var(--content-strong)] outline-none placeholder:text-[var(--content-tertiary)] disabled:cursor-not-allowed disabled:opacity-60`})}),(0,J.jsx)(`span`,{"aria-hidden":!0,className:`h-7 w-7 shrink-0`})]})]})}function he({label:e,description:t,thumbnail:n,onClick:r}){return(0,J.jsxs)(`button`,{type:`button`,onClick:r,className:`flex w-full cursor-pointer items-center gap-3 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-lift)] px-3 py-2 text-left transition-colors hover:bg-[var(--surface-hover)]`,children:[(0,J.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-md bg-[var(--surface-sunken)]`,children:n}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-body-medium-default text-[var(--content-strong)]`,children:e}),(0,J.jsx)(`span`,{className:`block truncate text-body-small-default text-[var(--content-quiet)]`,children:t})]}),(0,J.jsx)(p,{className:`h-4 w-4 shrink-0 text-[var(--content-quiet)]`})]})}function ge({label:e,value:t,colorHex:n,onPrev:r,onNext:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-lift)] px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-body-small-default uppercase tracking-wider text-[var(--content-quiet)]`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:r,"aria-label":`Previous ${e.toLowerCase()}`,className:`flex h-7 w-7 cursor-pointer items-center justify-center rounded-md text-[var(--content-quiet)] transition-colors hover:bg-[var(--surface-active)]`,children:(0,J.jsx)(f,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`flex min-w-[80px] items-center justify-center gap-2`,children:[n&&(0,J.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-[var(--border-element)]`,style:{backgroundColor:n}}),(0,J.jsx)(`span`,{className:`text-body-medium-default capitalize text-[var(--content-strong)]`,children:t})]}),(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":`Next ${e.toLowerCase()}`,className:`flex h-7 w-7 cursor-pointer items-center justify-center rounded-md text-[var(--content-quiet)] transition-colors hover:bg-[var(--surface-active)]`,children:(0,J.jsx)(p,{className:`h-4 w-4`})})]})]})}function _e(e){let t=e.trim();return`<system-message>
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-Dy5001j6.js";import{t as r}from"./chunk-5KNZJZUH-Bsoom5--.js";import{n as i}from"./QueryClientProvider-CMu7CkQU.js";import{t as a}from"./useQuery-Bz-fbQ-m.js";import{t as o}from"./jsx-runtime-D3ZM-ToX.js";import{t as s}from"./card-DRIctGVs.js";import{t as c}from"./createLucideIcon-CAM1RhH8.js";import{t as l}from"./brain-BIzJCPA6.js";import{n as u,t as d}from"./upload-Bdbyo_ok.js";import{t as f}from"./chevron-left-CytMddTB.js";import{t as p}from"./chevron-right-HU6H84S0.js";import{t as m}from"./dices-DcuIF52A.js";import{t as h}from"./folder-open-Nlg0OphT.js";import{t as g}from"./layout-grid-DA_CfD6d.js";import{t as _}from"./pencil-D38YNe2r.js";import{t as v}from"./sparkles-Ccrj7hxd.js";import{t as y}from"./users-iLvfYFOP.js";import{n as b,t as x}from"./installed-plugins-query-C29LGAEV.js";import"./src-te3YTBG-.js";import{t as S}from"./modal-BR4CUFBd.js";import{n as C}from"./toast-LgLp4obE.js";import{E as w,St as T,b as E,ht as D,ln as O,o as k,t as A}from"./react-query.gen-r3I6j8-1.js";import{t as j}from"./assistant-identity-store-DIyVo8LV.js";import{n as M,u as N}from"./routes-vE-2hncW.js";import{n as P,t as F}from"./eye-bbox-DXmmg9ML.js";import{a as ee,n as te,o as I,r as ne}from"./use-assistant-avatar-DSu2_Mzi.js";import{t as L}from"./plugins-surface-D4i2vqBz.js";import{t as R}from"./proxy-RtD8704m.js";import{t as z}from"./use-reduced-motion-Se97jRQ-.js";import{r as B}from"./avatar-tone-CMoWR2JX.js";import{t as V}from"./chat-avatar-DT-jt-zV.js";import{t as re}from"./avatar-renderer-DK54o2kQ.js";import{t as H}from"./use-active-assistant-id-CXhDyK7y.js";import{t as ie}from"./page-shell-BEWoPpRT.js";import{a as ae,i as oe,n as U,o as W}from"./latest-assistant-text-C4DnCZXH.js";import{a as G,n as se,r as K,s as ce,t as le}from"./use-assistant-identity-details-7N1jAxdm.js";import{t as ue}from"./schedules-CKGVEPqD.js";import{t as de}from"./get-memory-stats-D5-UCwt0.js";var fe=c(`radio`,[[`path`,{d:`M16.247 7.761a6 6 0 0 1 0 8.478`,key:`1fwjs5`}],[`path`,{d:`M19.075 4.933a10 10 0 0 1 0 14.134`,key:`ehdyv1`}],[`path`,{d:`M4.925 19.067a10 10 0 0 1 0-14.134`,key:`1q22gi`}],[`path`,{d:`M7.753 16.239a6 6 0 0 1 0-8.478`,key:`r2q7qm`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),q=e(t(),1),J=o();function Y(e,t,n){return n===`forward`?(e+1)%t:(e-1+t)%t}function pe({open:e,onClose:t,assistantId:r,components:i,traits:a,customImageUrl:o,onSaveCharacter:s,onUploadImage:c,assistantName:l,onRenameSubmit:u,isRenaming:f=!1}){let p=(0,q.useRef)(null),[h,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(!1),y=i??h,[b,x]=(0,q.useState)(0),[C,w]=(0,q.useState)(0),[T,E]=(0,q.useState)(0),[D,O]=(0,q.useState)(`character`),[k,A]=(0,q.useState)(null),[j,M]=(0,q.useState)(!1),[N,P]=(0,q.useState)(!1),[F,te]=(0,q.useState)(l??``),L=k??o,R=!!L;(0,q.useEffect)(()=>{e&&te(l??``)},[e,l]);let z=(0,q.useRef)(!1);(0,q.useEffect)(()=>{e&&!z.current&&O(o?`custom`:`character`),z.current=e},[e,o]),(0,q.useEffect)(()=>{if(e)if(y&&a){let e=y.bodyShapes.findIndex(e=>e.id===a.bodyShape),t=y.eyeStyles.findIndex(e=>e.id===a.eyeStyle),n=y.colors.findIndex(e=>e.id===a.color);x(e>=0?e:0),w(t>=0?t:0),E(n>=0?n:0)}else x(0),w(0),E(0)},[e,y,a]),(0,q.useEffect)(()=>{if(!e||y||_)return;let t=!1;return v(!0),ne(r).then(e=>{t||(g(e),v(!1))}),()=>{t=!0}},[e,y,_,r]),(0,q.useEffect)(()=>{if(k)return()=>{URL.revokeObjectURL(k)}},[k]),(0,q.useEffect)(()=>{e||A(null)},[e]);let B=F.trim(),V=!!u&&B.length>0&&B!==(l??``),H=(0,q.useCallback)(()=>{y&&(O(`character`),x(Math.floor(Math.random()*y.bodyShapes.length)),w(Math.floor(Math.random()*y.eyeStyles.length)),E(Math.floor(Math.random()*y.colors.length)))},[y]),ie=(0,q.useCallback)(()=>{p.current?.click()},[]),ae=(0,q.useCallback)(async e=>{let t=e.target.files?.[0];if(!t)return;P(!0);let n=await I(r,t);P(!1),n&&(c(),A(URL.createObjectURL(t)),O(`custom`)),p.current&&(p.current.value=``)},[r,c]),oe=(0,q.useCallback)(async e=>{if(e.preventDefault(),!(j||f)){if(V&&u&&u(B),y&&D===`character`){let e={bodyShape:y.bodyShapes[b].id,eyeStyle:y.eyeStyles[C].id,color:y.colors[T].id};M(!0);try{await ee(r,e),A(null),s(e)}finally{M(!1)}}t()}},[j,f,V,u,B,y,D,b,C,T,r,s,t]),U=y?.bodyShapes[b],W=y?.eyeStyles[C],G=y?.colors[T],se=D===`custom`&&R,K=l!==void 0&&u?(0,J.jsx)(me,{value:F,onChange:te,disabled:f}):null;return(0,J.jsx)(S.Root,{open:e,onOpenChange:e=>!e&&t(),children:(0,J.jsxs)(S.Content,{size:`sm`,children:[(0,J.jsx)(S.Header,{children:(0,J.jsx)(S.Title,{children:`Update Avatar`})}),(0,J.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:oe,children:[(0,J.jsx)(S.Body,{className:`space-y-4`,children:se?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`flex justify-center`,children:(0,J.jsx)(`div`,{className:`rounded-2xl bg-[var(--surface-sunken)] p-6`,children:(0,J.jsx)(`img`,{src:L,alt:`Uploaded avatar`,className:`h-40 w-40 rounded-xl object-cover`})})}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[K,(0,J.jsx)(he,{label:`Use a character instead`,description:`Pick from our built-in avatars`,onClick:()=>O(`character`),thumbnail:y&&U&&W&&G?(0,J.jsx)(re,{components:y,bodyShapeId:U.id,eyeStyleId:W.id,colorId:G.id,size:32}):(0,J.jsx)(m,{className:`h-4 w-4`,style:{color:`var(--content-secondary)`}})})]})]}):y?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`flex justify-center`,children:(0,J.jsx)(`div`,{className:`rounded-2xl bg-[var(--surface-sunken)] p-6`,children:(0,J.jsx)(re,{components:y,bodyShapeId:U.id,eyeStyleId:W.id,colorId:G.id,size:160})})}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[K,(0,J.jsx)(ge,{label:`Body`,value:U.id,onPrev:()=>x(Y(b,y.bodyShapes.length,`backward`)),onNext:()=>x(Y(b,y.bodyShapes.length,`forward`))}),(0,J.jsx)(ge,{label:`Eyes`,value:W.id,onPrev:()=>w(Y(C,y.eyeStyles.length,`backward`)),onNext:()=>w(Y(C,y.eyeStyles.length,`forward`))}),(0,J.jsx)(ge,{label:`Color`,value:G.id,colorHex:G.hex,onPrev:()=>E(Y(T,y.colors.length,`backward`)),onNext:()=>E(Y(T,y.colors.length,`forward`))})]}),R&&(0,J.jsx)(he,{label:`Keep your uploaded image`,description:`Saving the character replaces it`,onClick:()=>O(`custom`),thumbnail:(0,J.jsx)(`img`,{src:L,alt:``,className:`h-8 w-8 rounded-md object-cover`})})]}):(0,J.jsxs)(J.Fragment,{children:[K,_?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,J.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-[var(--border-element)] border-t-[var(--content-tertiary)]`})}):(0,J.jsx)(`div`,{className:`py-8 text-center text-body-medium-lighter text-[var(--content-quiet)]`,children:`Unable to load avatar components. Make sure your assistant is running.`})]})}),(0,J.jsxs)(S.Footer,{className:`justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(n,{type:`button`,variant:`outlined`,iconOnly:(0,J.jsx)(m,{}),"aria-label":`Randomize`,tooltip:`Randomize`,onClick:H,disabled:!y}),(0,J.jsx)(n,{type:`button`,variant:`outlined`,iconOnly:(0,J.jsx)(d,{}),"aria-label":`Upload image`,tooltip:`Upload image`,onClick:ie,disabled:N})]}),(0,J.jsx)(n,{type:`submit`,variant:`primary`,disabled:j||f||N,children:j||f?`Saving…`:`Save`})]})]}),(0,J.jsx)(`input`,{ref:p,type:`file`,accept:`image/png,image/jpeg,image/webp,image/gif`,className:`hidden`,onChange:ae})]})})}function me({value:e,onChange:t,disabled:n}){return(0,J.jsxs)(`label`,{className:`flex items-center justify-between gap-3 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-lift)] px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-body-small-default uppercase tracking-wider text-[var(--content-quiet)]`,children:`Name`}),(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`flex min-w-[80px] items-center justify-center`,children:(0,J.jsx)(`input`,{value:e,onChange:e=>t(e.target.value),disabled:n,maxLength:40,size:8,placeholder:`Name`,"aria-label":`Name`,className:`h-7 min-w-0 field-sizing-content bg-transparent text-center text-body-medium-default text-[var(--content-strong)] outline-none placeholder:text-[var(--content-tertiary)] disabled:cursor-not-allowed disabled:opacity-60`})}),(0,J.jsx)(`span`,{"aria-hidden":!0,className:`h-7 w-7 shrink-0`})]})]})}function he({label:e,description:t,thumbnail:n,onClick:r}){return(0,J.jsxs)(`button`,{type:`button`,onClick:r,className:`flex w-full cursor-pointer items-center gap-3 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-lift)] px-3 py-2 text-left transition-colors hover:bg-[var(--surface-hover)]`,children:[(0,J.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-md bg-[var(--surface-sunken)]`,children:n}),(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate text-body-medium-default text-[var(--content-strong)]`,children:e}),(0,J.jsx)(`span`,{className:`block truncate text-body-small-default text-[var(--content-quiet)]`,children:t})]}),(0,J.jsx)(p,{className:`h-4 w-4 shrink-0 text-[var(--content-quiet)]`})]})}function ge({label:e,value:t,colorHex:n,onPrev:r,onNext:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-lift)] px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-body-small-default uppercase tracking-wider text-[var(--content-quiet)]`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:r,"aria-label":`Previous ${e.toLowerCase()}`,className:`flex h-7 w-7 cursor-pointer items-center justify-center rounded-md text-[var(--content-quiet)] transition-colors hover:bg-[var(--surface-active)]`,children:(0,J.jsx)(f,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`flex min-w-[80px] items-center justify-center gap-2`,children:[n&&(0,J.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-[var(--border-element)]`,style:{backgroundColor:n}}),(0,J.jsx)(`span`,{className:`text-body-medium-default capitalize text-[var(--content-strong)]`,children:t})]}),(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":`Next ${e.toLowerCase()}`,className:`flex h-7 w-7 cursor-pointer items-center justify-center rounded-md text-[var(--content-quiet)] transition-colors hover:bg-[var(--surface-active)]`,children:(0,J.jsx)(p,{className:`h-4 w-4`})})]})]})}function _e(e){let t=e.trim();return`<system-message>
2
2
  The user renamed you: your name is now ${t}.
3
3
 
4
4
  Update IDENTITY.md so its name line reads exactly \`- **Name:** ${t}\`. This is a rename only — keep everything else in IDENTITY.md and SOUL.md exactly as it is, and do not touch users/ (that is your user's profile, not your identity). If your name appears elsewhere in those files, update those mentions to ${t} too.