fluxy-bot 0.2.8 → 0.2.10

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.
@@ -33,21 +33,30 @@ export default function App() {
33
33
 
34
34
  // Listen for rebuild events from Fluxy iframe via postMessage
35
35
  useEffect(() => {
36
+ let safetyTimer: ReturnType<typeof setTimeout>;
36
37
  const handler = (e: MessageEvent) => {
37
38
  if (e.data?.type === 'fluxy:rebuilding') {
38
39
  setRebuildState('rebuilding');
39
40
  setBuildError('');
41
+ // Safety: auto-reload after 60s in case app:rebuilt message is lost
42
+ clearTimeout(safetyTimer);
43
+ safetyTimer = setTimeout(() => location.reload(), 60_000);
40
44
  } else if (e.data?.type === 'fluxy:rebuilt') {
45
+ clearTimeout(safetyTimer);
41
46
  setRebuildState('idle');
42
47
  location.reload();
43
48
  } else if (e.data?.type === 'fluxy:build-error') {
49
+ clearTimeout(safetyTimer);
44
50
  setRebuildState('error');
45
51
  setBuildError(e.data.error || 'Build failed');
46
52
  setTimeout(() => setRebuildState('idle'), 5000);
47
53
  }
48
54
  };
49
55
  window.addEventListener('message', handler);
50
- return () => window.removeEventListener('message', handler);
56
+ return () => {
57
+ window.removeEventListener('message', handler);
58
+ clearTimeout(safetyTimer);
59
+ };
51
60
  }, []);
52
61
 
53
62
  const handleOnboardComplete = () => {
@@ -61,4 +61,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${i.do
61
61
  ${q}px !important;
62
62
  ${U}px !important;
63
63
  }
64
- `),()=>{P.contains(G)&&P.removeChild(G)}},[i]),y.jsx(dN,{isPresent:i,childRef:h,sizeRef:g,pop:f,children:f===!1?n:T.cloneElement(n,{ref:b})})}const mN=({children:n,initial:i,isPresent:l,onExitComplete:r,custom:c,presenceAffectsLayout:f,mode:d,anchorX:h,anchorY:g,root:p})=>{const v=bd(pN),b=T.useId();let S=!0,A=T.useMemo(()=>(S=!1,{id:b,initial:i,isPresent:l,custom:c,onExitComplete:D=>{v.set(D,!0);for(const M of v.values())if(!M)return;r&&r()},register:D=>(v.set(D,!1),()=>v.delete(D))}),[l,v,r]);return f&&S&&(A={...A}),T.useMemo(()=>{v.forEach((D,M)=>v.set(M,!1))},[l]),T.useEffect(()=>{!l&&!v.size&&r&&r()},[l]),n=y.jsx(hN,{pop:d==="popLayout",isPresent:l,anchorX:h,anchorY:g,root:p,children:n}),y.jsx(Bo.Provider,{value:A,children:n})};function pN(){return new Map}function _x(n=!0){const i=T.useContext(Bo);if(i===null)return[!0,null];const{isPresent:l,onExitComplete:r,register:c}=i,f=T.useId();T.useEffect(()=>{if(n)return c(f)},[n]);const d=T.useCallback(()=>n&&r&&r(f),[f,r,n]);return!l&&r?[!1,d]:[!0]}const co=n=>n.key||"";function Tv(n){const i=[];return T.Children.forEach(n,l=>{T.isValidElement(l)&&i.push(l)}),i}const gN=({children:n,custom:i,initial:l=!0,onExitComplete:r,presenceAffectsLayout:c=!0,mode:f="sync",propagate:d=!1,anchorX:h="left",anchorY:g="top",root:p})=>{const[v,b]=_x(d),S=T.useMemo(()=>Tv(n),[n]),A=d&&!v?[]:S.map(co),D=T.useRef(!0),M=T.useRef(S),N=bd(()=>new Map),V=T.useRef(new Set),[q,U]=T.useState(S),[G,P]=T.useState(S);ob(()=>{D.current=!1,M.current=S;for(let L=0;L<G.length;L++){const tt=co(G[L]);A.includes(tt)?(N.delete(tt),V.current.delete(tt)):N.get(tt)!==!0&&N.set(tt,!1)}},[G,A.length,A.join("-")]);const W=[];if(S!==q){let L=[...S];for(let tt=0;tt<G.length;tt++){const mt=G[tt],St=co(mt);A.includes(St)||(L.splice(tt,0,mt),W.push(mt))}return f==="wait"&&W.length&&(L=W),P(Tv(L)),U(S),null}const{forceRender:Z}=T.useContext(vd);return y.jsx(y.Fragment,{children:G.map(L=>{const tt=co(L),mt=d&&!v?!1:S===G||A.includes(tt),St=()=>{if(V.current.has(tt))return;if(V.current.add(tt),N.has(tt))N.set(tt,!0);else return;let At=!0;N.forEach(jt=>{jt||(At=!1)}),At&&(Z?.(),P(M.current),d&&b?.(),r&&r())};return y.jsx(mN,{isPresent:mt,initial:!D.current||l?void 0:!1,custom:i,presenceAffectsLayout:c,mode:f,root:p,onExitComplete:mt?void 0:St,anchorX:h,anchorY:g,children:L},tt)})})},Vx=T.createContext({strict:!1}),Ev={animation:["animate","variants","whileHover","whileTap","exit","whileInView","whileFocus","whileDrag"],exit:["exit"],drag:["drag","dragControls"],focus:["whileFocus"],hover:["whileHover","onHoverStart","onHoverEnd"],tap:["whileTap","onTap","onTapStart","onTapCancel"],pan:["onPan","onPanStart","onPanSessionStart","onPanEnd"],inView:["whileInView","onViewportEnter","onViewportLeave"],layout:["layout","layoutId"]};let wv=!1;function yN(){if(wv)return;const n={};for(const i in Ev)n[i]={isEnabled:l=>Ev[i].some(r=>!!l[r])};cx(n),wv=!0}function Lx(){return yN(),nM()}function vN(n){const i=Lx();for(const l in n)i[l]={...i[l],...n[l]};cx(i)}const bN=new Set(["animate","exit","variants","initial","style","values","variants","transition","transformTemplate","custom","inherit","onBeforeLayoutMeasure","onAnimationStart","onAnimationComplete","onUpdate","onDragStart","onDrag","onDragEnd","onMeasureDragConstraints","onDirectionLock","onDragTransitionEnd","_dragX","_dragY","onHoverStart","onHoverEnd","onViewportEnter","onViewportLeave","globalTapTarget","propagate","ignoreStrict","viewport"]);function Oo(n){return n.startsWith("while")||n.startsWith("drag")&&n!=="draggable"||n.startsWith("layout")||n.startsWith("onTap")||n.startsWith("onPan")||n.startsWith("onLayout")||bN.has(n)}let Ux=n=>!Oo(n);function xN(n){typeof n=="function"&&(Ux=i=>i.startsWith("on")?!Oo(i):n(i))}try{xN(require("@emotion/is-prop-valid").default)}catch{}function SN(n,i,l){const r={};for(const c in n)c==="values"&&typeof n.values=="object"||(Ux(c)||l===!0&&Oo(c)||!i&&!Oo(c)||n.draggable&&c.startsWith("onDrag"))&&(r[c]=n[c]);return r}const qo=T.createContext({});function TN(n,i){if(Go(n)){const{initial:l,animate:r}=n;return{initial:l===!1||Tl(l)?l:void 0,animate:Tl(r)?r:void 0}}return n.inherit!==!1?i:{}}function EN(n){const{initial:i,animate:l}=TN(n,T.useContext(qo));return T.useMemo(()=>({initial:i,animate:l}),[Av(i),Av(l)])}function Av(n){return Array.isArray(n)?n.join(" "):n}const Zd=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function kx(n,i,l){for(const r in i)!Te(i[r])&&!yx(r,l)&&(n[r]=i[r])}function wN({transformTemplate:n},i){return T.useMemo(()=>{const l=Zd();return Xd(l,i,n),Object.assign({},l.vars,l.style)},[i])}function AN(n,i){const l=n.style||{},r={};return kx(r,l,n),Object.assign(r,wN(n,i)),r}function CN(n,i){const l={},r=AN(n,i);return n.drag&&n.dragListener!==!1&&(l.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout="none",r.touchAction=n.drag===!0?"none":`pan-${n.drag==="x"?"y":"x"}`),n.tabIndex===void 0&&(n.onTap||n.onTapStart||n.whileTap)&&(l.tabIndex=0),l.style=r,l}const Bx=()=>({...Zd(),attrs:{}});function MN(n,i,l,r){const c=T.useMemo(()=>{const f=Bx();return vx(f,i,xx(r),n.transformTemplate,n.style),{...f.attrs,style:{...f.style}}},[i]);if(n.style){const f={};kx(f,n.style,n),c.style={...f,...c.style}}return c}const NN=["animate","circle","defs","desc","ellipse","g","image","line","filter","marker","mask","metadata","path","pattern","polygon","polyline","rect","stop","switch","symbol","svg","text","tspan","use","view"];function Fd(n){return typeof n!="string"||n.includes("-")?!1:!!(NN.indexOf(n)>-1||/[A-Z]/u.test(n))}function jN(n,i,l,{latestValues:r},c,f=!1,d){const g=(d??Fd(n)?MN:CN)(i,r,c,n),p=SN(i,typeof n=="string",f),v=n!==T.Fragment?{...p,...g,ref:l}:{},{children:b}=i,S=T.useMemo(()=>Te(b)?b.get():b,[b]);return T.createElement(n,{...v,children:S})}function DN({scrapeMotionValuesFromProps:n,createRenderState:i},l,r,c){return{latestValues:RN(l,r,c,n),renderState:i()}}function RN(n,i,l,r){const c={},f=r(n,{});for(const S in f)c[S]=xo(f[S]);let{initial:d,animate:h}=n;const g=Go(n),p=ox(n);i&&p&&!g&&n.inherit!==!1&&(d===void 0&&(d=i.initial),h===void 0&&(h=i.animate));let v=l?l.initial===!1:!1;v=v||d===!1;const b=v?h:d;if(b&&typeof b!="boolean"&&!Ho(b)){const S=Array.isArray(b)?b:[b];for(let A=0;A<S.length;A++){const D=Ld(n,S[A]);if(D){const{transitionEnd:M,transition:N,...V}=D;for(const q in V){let U=V[q];if(Array.isArray(U)){const G=v?U.length-1:0;U=U[G]}U!==null&&(c[q]=U)}for(const q in M)c[q]=M[q]}}}return c}const Hx=n=>(i,l)=>{const r=T.useContext(qo),c=T.useContext(Bo),f=()=>DN(n,i,r,c);return l?f():bd(f)},ON=Hx({scrapeMotionValuesFromProps:Kd,createRenderState:Zd}),zN=Hx({scrapeMotionValuesFromProps:Sx,createRenderState:Bx}),_N=Symbol.for("motionComponentSymbol");function VN(n,i,l){const r=T.useRef(l);T.useInsertionEffect(()=>{r.current=l});const c=T.useRef(null);return T.useCallback(f=>{f&&n.onMount?.(f),i&&(f?i.mount(f):i.unmount());const d=r.current;if(typeof d=="function")if(f){const h=d(f);typeof h=="function"&&(c.current=h)}else c.current?(c.current(),c.current=null):d(f);else d&&(d.current=f)},[i])}const Gx=T.createContext({});function es(n){return n&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"current")}function LN(n,i,l,r,c,f){const{visualElement:d}=T.useContext(qo),h=T.useContext(Vx),g=T.useContext(Bo),p=T.useContext(Pd),v=p.reducedMotion,b=p.skipAnimations,S=T.useRef(null),A=T.useRef(!1);r=r||h.renderer,!S.current&&r&&(S.current=r(n,{visualState:i,parent:d,props:l,presenceContext:g,blockInitialAnimation:g?g.initial===!1:!1,reducedMotionConfig:v,skipAnimations:b,isSVG:f}),A.current&&S.current&&(S.current.manuallyAnimateOnMount=!0));const D=S.current,M=T.useContext(Gx);D&&!D.projection&&c&&(D.type==="html"||D.type==="svg")&&UN(S.current,l,c,M);const N=T.useRef(!1);T.useInsertionEffect(()=>{D&&N.current&&D.update(l,g)});const V=l[Qb],q=T.useRef(!!V&&!window.MotionHandoffIsComplete?.(V)&&window.MotionHasOptimisedAnimation?.(V));return ob(()=>{A.current=!0,D&&(N.current=!0,window.MotionIsMounted=!0,D.updateFeatures(),D.scheduleRenderMicrotask(),q.current&&D.animationState&&D.animationState.animateChanges())}),T.useEffect(()=>{D&&(!q.current&&D.animationState&&D.animationState.animateChanges(),q.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(V)}),q.current=!1),D.enteringChildren=void 0)}),D}function UN(n,i,l,r){const{layoutId:c,layout:f,drag:d,dragConstraints:h,layoutScroll:g,layoutRoot:p,layoutCrossfade:v}=i;n.projection=new l(n.latestValues,i["data-framer-portal-id"]?void 0:qx(n.parent)),n.projection.setOptions({layoutId:c,layout:f,alwaysMeasureLayout:!!d||h&&es(h),visualElement:n,animationType:typeof f=="string"?f:"both",initialPromotionConfig:r,crossfade:v,layoutScroll:g,layoutRoot:p})}function qx(n){if(n)return n.options.allowProjection!==!1?n.projection:qx(n.parent)}function jf(n,{forwardMotionProps:i=!1,type:l}={},r,c){r&&vN(r);const f=l?l==="svg":Fd(n),d=f?zN:ON;function h(p,v){let b;const S={...T.useContext(Pd),...p,layoutId:kN(p)},{isStatic:A}=S,D=EN(p),M=d(p,A);if(!A&&rb){BN();const N=HN(S);b=N.MeasureLayout,D.visualElement=LN(n,M,S,c,N.ProjectionNode,f)}return y.jsxs(qo.Provider,{value:D,children:[b&&D.visualElement?y.jsx(b,{visualElement:D.visualElement,...S}):null,jN(n,p,VN(M,D.visualElement,v),M,A,i,f)]})}h.displayName=`motion.${typeof n=="string"?n:`create(${n.displayName??n.name??""})`}`;const g=T.forwardRef(h);return g[_N]=n,g}function kN({layoutId:n}){const i=T.useContext(vd).id;return i&&n!==void 0?i+"-"+n:n}function BN(n,i){T.useContext(Vx).strict}function HN(n){const i=Lx(),{drag:l,layout:r}=i;if(!l&&!r)return{};const c={...l,...r};return{MeasureLayout:l?.isEnabled(n)||r?.isEnabled(n)?c.MeasureLayout:void 0,ProjectionNode:c.ProjectionNode}}function GN(n,i){if(typeof Proxy>"u")return jf;const l=new Map,r=(f,d)=>jf(f,d,n,i),c=(f,d)=>r(f,d);return new Proxy(c,{get:(f,d)=>d==="create"?r:(l.has(d)||l.set(d,jf(d,void 0,n,i)),l.get(d))})}const qN=(n,i)=>i.isSVG??Fd(n)?new bM(i):new hM(i,{allowProjection:n!==T.Fragment});class YN extends Na{constructor(i){super(i),i.animationState||(i.animationState=wM(i))}updateAnimationControlsSubscription(){const{animate:i}=this.node.getProps();Ho(i)&&(this.unmountControls=i.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:i}=this.node.getProps(),{animate:l}=this.node.prevProps||{};i!==l&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let XN=0;class KN extends Na{constructor(){super(...arguments),this.id=XN++}update(){if(!this.node.presenceContext)return;const{isPresent:i,onExitComplete:l}=this.node.presenceContext,{isPresent:r}=this.node.prevPresenceContext||{};if(!this.node.animationState||i===r)return;const c=this.node.animationState.setActive("exit",!i);l&&!i&&c.then(()=>{l(this.id)})}mount(){const{register:i,onExitComplete:l}=this.node.presenceContext||{};l&&l(this.id),i&&(this.unmount=i(this.id))}unmount(){}}const PN={animation:{Feature:YN},exit:{Feature:KN}};function Rl(n){return{point:{x:n.pageX,y:n.pageY}}}const ZN=n=>i=>Hd(i)&&n(i,Rl(i));function vl(n,i,l,r){return El(n,i,ZN(l),r)}const Yx=({current:n})=>n?n.ownerDocument.defaultView:null,Cv=(n,i)=>Math.abs(n-i);function FN(n,i){const l=Cv(n.x,i.x),r=Cv(n.y,i.y);return Math.sqrt(l**2+r**2)}const Mv=new Set(["auto","scroll"]);class Xx{constructor(i,l,{transformPagePoint:r,contextWindow:c=window,dragSnapToOrigin:f=!1,distanceThreshold:d=3,element:h}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.removeScrollListeners=null,this.onElementScroll=A=>{this.handleScroll(A.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const A=Rf(this.lastMoveEventInfo,this.history),D=this.startEvent!==null,M=FN(A.offset,{x:0,y:0})>=this.distanceThreshold;if(!D&&!M)return;const{point:N}=A,{timestamp:V}=ve;this.history.push({...N,timestamp:V});const{onStart:q,onMove:U}=this.handlers;D||(q&&q(this.lastMoveEvent,A),this.startEvent=this.lastMoveEvent),U&&U(this.lastMoveEvent,A)},this.handlePointerMove=(A,D)=>{this.lastMoveEvent=A,this.lastMoveEventInfo=Df(D,this.transformPagePoint),Ut.update(this.updatePoint,!0)},this.handlePointerUp=(A,D)=>{this.end();const{onEnd:M,onSessionEnd:N,resumeAnimation:V}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&V&&V(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const q=Rf(A.type==="pointercancel"?this.lastMoveEventInfo:Df(D,this.transformPagePoint),this.history);this.startEvent&&M&&M(A,q),N&&N(A,q)},!Hd(i))return;this.dragSnapToOrigin=f,this.handlers=l,this.transformPagePoint=r,this.distanceThreshold=d,this.contextWindow=c||window;const g=Rl(i),p=Df(g,this.transformPagePoint),{point:v}=p,{timestamp:b}=ve;this.history=[{...v,timestamp:b}];const{onSessionStart:S}=l;S&&S(i,Rf(p,this.history)),this.removeListeners=Nl(vl(this.contextWindow,"pointermove",this.handlePointerMove),vl(this.contextWindow,"pointerup",this.handlePointerUp),vl(this.contextWindow,"pointercancel",this.handlePointerUp)),h&&this.startScrollTracking(h)}startScrollTracking(i){let l=i.parentElement;for(;l;){const r=getComputedStyle(l);(Mv.has(r.overflowX)||Mv.has(r.overflowY))&&this.scrollPositions.set(l,{x:l.scrollLeft,y:l.scrollTop}),l=l.parentElement}this.scrollPositions.set(window,{x:window.scrollX,y:window.scrollY}),window.addEventListener("scroll",this.onElementScroll,{capture:!0}),window.addEventListener("scroll",this.onWindowScroll),this.removeScrollListeners=()=>{window.removeEventListener("scroll",this.onElementScroll,{capture:!0}),window.removeEventListener("scroll",this.onWindowScroll)}}handleScroll(i){const l=this.scrollPositions.get(i);if(!l)return;const r=i===window,c=r?{x:window.scrollX,y:window.scrollY}:{x:i.scrollLeft,y:i.scrollTop},f={x:c.x-l.x,y:c.y-l.y};f.x===0&&f.y===0||(r?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=f.x,this.lastMoveEventInfo.point.y+=f.y):this.history.length>0&&(this.history[0].x-=f.x,this.history[0].y-=f.y),this.scrollPositions.set(i,c),Ut.update(this.updatePoint,!0))}updateHandlers(i){this.handlers=i}end(){this.removeListeners&&this.removeListeners(),this.removeScrollListeners&&this.removeScrollListeners(),this.scrollPositions.clear(),Ca(this.updatePoint)}}function Df(n,i){return i?{point:i(n.point)}:n}function Nv(n,i){return{x:n.x-i.x,y:n.y-i.y}}function Rf({point:n},i){return{point:n,delta:Nv(n,Kx(i)),offset:Nv(n,QN(i)),velocity:JN(i,.1)}}function QN(n){return n[0]}function Kx(n){return n[n.length-1]}function JN(n,i){if(n.length<2)return{x:0,y:0};let l=n.length-1,r=null;const c=Kx(n);for(;l>=0&&(r=n[l],!(c.timestamp-r.timestamp>rn(i)));)l--;if(!r)return{x:0,y:0};r===n[0]&&n.length>2&&c.timestamp-r.timestamp>rn(i)*2&&(r=n[1]);const f=We(c.timestamp-r.timestamp);if(f===0)return{x:0,y:0};const d={x:(c.x-r.x)/f,y:(c.y-r.y)/f};return d.x===1/0&&(d.x=0),d.y===1/0&&(d.y=0),d}function WN(n,{min:i,max:l},r){return i!==void 0&&n<i?n=r?Yt(i,n,r.min):Math.max(n,i):l!==void 0&&n>l&&(n=r?Yt(l,n,r.max):Math.min(n,l)),n}function jv(n,i,l){return{min:i!==void 0?n.min+i:void 0,max:l!==void 0?n.max+l-(n.max-n.min):void 0}}function IN(n,{top:i,left:l,bottom:r,right:c}){return{x:jv(n.x,l,c),y:jv(n.y,i,r)}}function Dv(n,i){let l=i.min-n.min,r=i.max-n.max;return i.max-i.min<n.max-n.min&&([l,r]=[r,l]),{min:l,max:r}}function $N(n,i){return{x:Dv(n.x,i.x),y:Dv(n.y,i.y)}}function t4(n,i){let l=.5;const r=Ce(n),c=Ce(i);return c>r?l=bl(i.min,i.max-r,n.min):r>c&&(l=bl(n.min,n.max-c,i.min)),En(0,1,l)}function e4(n,i){const l={};return i.min!==void 0&&(l.min=i.min-n.min),i.max!==void 0&&(l.max=i.max-n.min),l}const rd=.35;function n4(n=rd){return n===!1?n=0:n===!0&&(n=rd),{x:Rv(n,"left","right"),y:Rv(n,"top","bottom")}}function Rv(n,i,l){return{min:Ov(n,i),max:Ov(n,l)}}function Ov(n,i){return typeof n=="number"?n:n[i]||0}const a4=new WeakMap;class i4{constructor(i){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=re(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=i}start(i,{snapToCursor:l=!1,distanceThreshold:r}={}){const{presenceContext:c}=this.visualElement;if(c&&c.isPresent===!1)return;const f=b=>{l&&this.snapToCursor(Rl(b).point),this.stopAnimation()},d=(b,S)=>{const{drag:A,dragPropagation:D,onDragStart:M}=this.getProps();if(A&&!D&&(this.openDragLock&&this.openDragLock(),this.openDragLock=O3(A),!this.openDragLock))return;this.latestPointerEvent=b,this.latestPanInfo=S,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints(),this.visualElement.projection&&(this.visualElement.projection.isAnimationBlocked=!0,this.visualElement.projection.target=void 0),bn(V=>{let q=this.getAxisMotionValue(V).get()||0;if(Sn.test(q)){const{projection:U}=this.visualElement;if(U&&U.layout){const G=U.layout.layoutBox[V];G&&(q=Ce(G)*(parseFloat(q)/100))}}this.originPoint[V]=q}),M&&Ut.update(()=>M(b,S),!1,!0),If(this.visualElement,"transform");const{animationState:N}=this.visualElement;N&&N.setActive("whileDrag",!0)},h=(b,S)=>{this.latestPointerEvent=b,this.latestPanInfo=S;const{dragPropagation:A,dragDirectionLock:D,onDirectionLock:M,onDrag:N}=this.getProps();if(!A&&!this.openDragLock)return;const{offset:V}=S;if(D&&this.currentDirection===null){this.currentDirection=l4(V),this.currentDirection!==null&&M&&M(this.currentDirection);return}this.updateAxis("x",S.point,V),this.updateAxis("y",S.point,V),this.visualElement.render(),N&&Ut.update(()=>N(b,S),!1,!0)},g=(b,S)=>{this.latestPointerEvent=b,this.latestPanInfo=S,this.stop(b,S),this.latestPointerEvent=null,this.latestPanInfo=null},p=()=>{const{dragSnapToOrigin:b}=this.getProps();(b||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:v}=this.getProps();this.panSession=new Xx(i,{onSessionStart:f,onStart:d,onMove:h,onSessionEnd:g,resumeAnimation:p},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:v,distanceThreshold:r,contextWindow:Yx(this.visualElement),element:this.visualElement.current})}stop(i,l){const r=i||this.latestPointerEvent,c=l||this.latestPanInfo,f=this.isDragging;if(this.cancel(),!f||!c||!r)return;const{velocity:d}=c;this.startAnimation(d);const{onDragEnd:h}=this.getProps();h&&Ut.postRender(()=>h(r,c))}cancel(){this.isDragging=!1;const{projection:i,animationState:l}=this.visualElement;i&&(i.isAnimationBlocked=!1),this.endPanSession();const{dragPropagation:r}=this.getProps();!r&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),l&&l.setActive("whileDrag",!1)}endPanSession(){this.panSession&&this.panSession.end(),this.panSession=void 0}updateAxis(i,l,r){const{drag:c}=this.getProps();if(!r||!fo(i,c,this.currentDirection))return;const f=this.getAxisMotionValue(i);let d=this.originPoint[i]+r[i];this.constraints&&this.constraints[i]&&(d=WN(d,this.constraints[i],this.elastic[i])),f.set(d)}resolveConstraints(){const{dragConstraints:i,dragElastic:l}=this.getProps(),r=this.visualElement.projection&&!this.visualElement.projection.layout?this.visualElement.projection.measure(!1):this.visualElement.projection?.layout,c=this.constraints;i&&es(i)?this.constraints||(this.constraints=this.resolveRefConstraints()):i&&r?this.constraints=IN(r.layoutBox,i):this.constraints=!1,this.elastic=n4(l),c!==this.constraints&&!es(i)&&r&&this.constraints&&!this.hasMutatedConstraints&&bn(f=>{this.constraints!==!1&&this.getAxisMotionValue(f)&&(this.constraints[f]=e4(r.layoutBox[f],this.constraints[f]))})}resolveRefConstraints(){const{dragConstraints:i,onMeasureDragConstraints:l}=this.getProps();if(!i||!es(i))return!1;const r=i.current,{projection:c}=this.visualElement;if(!c||!c.layout)return!1;const f=rM(r,c.root,this.visualElement.getTransformPagePoint());let d=$N(c.layout.layoutBox,f);if(l){const h=l(iM(d));this.hasMutatedConstraints=!!h,h&&(d=dx(h))}return d}startAnimation(i){const{drag:l,dragMomentum:r,dragElastic:c,dragTransition:f,dragSnapToOrigin:d,onDragTransitionEnd:h}=this.getProps(),g=this.constraints||{},p=bn(v=>{if(!fo(v,l,this.currentDirection))return;let b=g&&g[v]||{};d&&(b={min:0,max:0});const S=c?200:1e6,A=c?40:1e7,D={type:"inertia",velocity:r?i[v]:0,bounceStiffness:S,bounceDamping:A,timeConstant:750,restDelta:1,restSpeed:10,...f,...b};return this.startAxisValueAnimation(v,D)});return Promise.all(p).then(h)}startAxisValueAnimation(i,l){const r=this.getAxisMotionValue(i);return If(this.visualElement,i),r.start(Vd(i,r,0,l,this.visualElement,!1))}stopAnimation(){bn(i=>this.getAxisMotionValue(i).stop())}getAxisMotionValue(i){const l=`_drag${i.toUpperCase()}`,r=this.visualElement.getProps(),c=r[l];return c||this.visualElement.getValue(i,(r.initial?r.initial[i]:void 0)||0)}snapToCursor(i){bn(l=>{const{drag:r}=this.getProps();if(!fo(l,r,this.currentDirection))return;const{projection:c}=this.visualElement,f=this.getAxisMotionValue(l);if(c&&c.layout){const{min:d,max:h}=c.layout.layoutBox[l],g=f.get()||0;f.set(i[l]-Yt(d,h,.5)+g)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:i,dragConstraints:l}=this.getProps(),{projection:r}=this.visualElement;if(!es(l)||!r||!this.constraints)return;this.stopAnimation();const c={x:0,y:0};bn(d=>{const h=this.getAxisMotionValue(d);if(h&&this.constraints!==!1){const g=h.get();c[d]=t4({min:g,max:g},this.constraints[d])}});const{transformTemplate:f}=this.visualElement.getProps();this.visualElement.current.style.transform=f?f({},""):"none",r.root&&r.root.updateScroll(),r.updateLayout(),this.constraints=!1,this.resolveConstraints(),bn(d=>{if(!fo(d,i,null))return;const h=this.getAxisMotionValue(d),{min:g,max:p}=this.constraints[d];h.set(Yt(g,p,c[d]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;a4.set(this.visualElement,this);const i=this.visualElement.current,l=vl(i,"pointerdown",p=>{const{drag:v,dragListener:b=!0}=this.getProps(),S=p.target,A=S!==i&&k3(S);v&&b&&!A&&this.start(p)});let r;const c=()=>{const{dragConstraints:p}=this.getProps();es(p)&&p.current&&(this.constraints=this.resolveRefConstraints(),r||(r=s4(i,p.current,()=>this.scalePositionWithinConstraints())))},{projection:f}=this.visualElement,d=f.addEventListener("measure",c);f&&!f.layout&&(f.root&&f.root.updateScroll(),f.updateLayout()),Ut.read(c);const h=El(window,"resize",()=>this.scalePositionWithinConstraints()),g=f.addEventListener("didUpdate",(({delta:p,hasLayoutChanged:v})=>{this.isDragging&&v&&(bn(b=>{const S=this.getAxisMotionValue(b);S&&(this.originPoint[b]+=p[b].translate,S.set(S.get()+p[b].translate))}),this.visualElement.render())}));return()=>{h(),l(),d(),g&&g(),r&&r()}}getProps(){const i=this.visualElement.getProps(),{drag:l=!1,dragDirectionLock:r=!1,dragPropagation:c=!1,dragConstraints:f=!1,dragElastic:d=rd,dragMomentum:h=!0}=i;return{...i,drag:l,dragDirectionLock:r,dragPropagation:c,dragConstraints:f,dragElastic:d,dragMomentum:h}}}function zv(n){let i=!0;return()=>{if(i){i=!1;return}n()}}function s4(n,i,l){const r=Hy(n,zv(l)),c=Hy(i,zv(l));return()=>{r(),c()}}function fo(n,i,l){return(i===!0||i===n)&&(l===null||l===n)}function l4(n,i=10){let l=null;return Math.abs(n.y)>i?l="y":Math.abs(n.x)>i&&(l="x"),l}class r4 extends Na{constructor(i){super(i),this.removeGroupControls=Ie,this.removeListeners=Ie,this.controls=new i4(i)}mount(){const{dragControls:i}=this.node.getProps();i&&(this.removeGroupControls=i.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Ie}update(){const{dragControls:i}=this.node.getProps(),{dragControls:l}=this.node.prevProps||{};i!==l&&(this.removeGroupControls(),i&&(this.removeGroupControls=i.subscribe(this.controls)))}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}}const Of=n=>(i,l)=>{n&&Ut.update(()=>n(i,l),!1,!0)};class o4 extends Na{constructor(){super(...arguments),this.removePointerDownListener=Ie}onPointerDown(i){this.session=new Xx(i,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:Yx(this.node)})}createPanHandlers(){const{onPanSessionStart:i,onPanStart:l,onPan:r,onPanEnd:c}=this.node.getProps();return{onSessionStart:Of(i),onStart:Of(l),onMove:Of(r),onEnd:(f,d)=>{delete this.session,c&&Ut.postRender(()=>c(f,d))}}}mount(){this.removePointerDownListener=vl(this.node.current,"pointerdown",i=>this.onPointerDown(i))}update(){this.session&&this.session.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session&&this.session.end()}}let zf=!1;class u4 extends T.Component{componentDidMount(){const{visualElement:i,layoutGroup:l,switchLayoutGroup:r,layoutId:c}=this.props,{projection:f}=i;f&&(l.group&&l.group.add(f),r&&r.register&&c&&r.register(f),zf&&f.root.didUpdate(),f.addEventListener("animationComplete",()=>{this.safeToRemove()}),f.setOptions({...f.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),So.hasEverUpdated=!0}getSnapshotBeforeUpdate(i){const{layoutDependency:l,visualElement:r,drag:c,isPresent:f}=this.props,{projection:d}=r;return d&&(d.isPresent=f,i.layoutDependency!==l&&d.setOptions({...d.options,layoutDependency:l}),zf=!0,c||i.layoutDependency!==l||l===void 0||i.isPresent!==f?d.willUpdate():this.safeToRemove(),i.isPresent!==f&&(f?d.promote():d.relegate()||Ut.postRender(()=>{const h=d.getStack();(!h||!h.members.length)&&this.safeToRemove()}))),null}componentDidUpdate(){const{projection:i}=this.props.visualElement;i&&(i.root.didUpdate(),Bd.postRender(()=>{!i.currentAnimation&&i.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:i,layoutGroup:l,switchLayoutGroup:r}=this.props,{projection:c}=i;zf=!0,c&&(c.scheduleCheckAfterUnmount(),l&&l.group&&l.group.remove(c),r&&r.deregister&&r.deregister(c))}safeToRemove(){const{safeToRemove:i}=this.props;i&&i()}render(){return null}}function Px(n){const[i,l]=_x(),r=T.useContext(vd);return y.jsx(u4,{...n,layoutGroup:r,switchLayoutGroup:T.useContext(Gx),isPresent:i,safeToRemove:l})}const c4={pan:{Feature:o4},drag:{Feature:r4,ProjectionNode:zx,MeasureLayout:Px}};function _v(n,i,l){const{props:r}=n;n.animationState&&r.whileHover&&n.animationState.setActive("whileHover",l==="Start");const c="onHover"+l,f=r[c];f&&Ut.postRender(()=>f(i,Rl(i)))}class f4 extends Na{mount(){const{current:i}=this.node;i&&(this.unmount=_3(i,(l,r)=>(_v(this.node,r,"Start"),c=>_v(this.node,c,"End"))))}unmount(){}}class d4 extends Na{constructor(){super(...arguments),this.isActive=!1}onFocus(){let i=!1;try{i=this.node.current.matches(":focus-visible")}catch{i=!0}!i||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!0),this.isActive=!0)}onBlur(){!this.isActive||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!1),this.isActive=!1)}mount(){this.unmount=Nl(El(this.node.current,"focus",()=>this.onFocus()),El(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function Vv(n,i,l){const{props:r}=n;if(n.current instanceof HTMLButtonElement&&n.current.disabled)return;n.animationState&&r.whileTap&&n.animationState.setActive("whileTap",l==="Start");const c="onTap"+(l==="End"?"":l),f=r[c];f&&Ut.postRender(()=>f(i,Rl(i)))}class h4 extends Na{mount(){const{current:i}=this.node;if(!i)return;const{globalTapTarget:l,propagate:r}=this.node.props;this.unmount=H3(i,(c,f)=>(Vv(this.node,f,"Start"),(d,{success:h})=>Vv(this.node,d,h?"End":"Cancel")),{useGlobalTarget:l,stopPropagation:r?.tap===!1})}unmount(){}}const od=new WeakMap,_f=new WeakMap,m4=n=>{const i=od.get(n.target);i&&i(n)},p4=n=>{n.forEach(m4)};function g4({root:n,...i}){const l=n||document;_f.has(l)||_f.set(l,{});const r=_f.get(l),c=JSON.stringify(i);return r[c]||(r[c]=new IntersectionObserver(p4,{root:n,...i})),r[c]}function y4(n,i,l){const r=g4(i);return od.set(n,l),r.observe(n),()=>{od.delete(n),r.unobserve(n)}}const v4={some:0,all:1};class b4 extends Na{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:i={}}=this.node.getProps(),{root:l,margin:r,amount:c="some",once:f}=i,d={root:l?l.current:void 0,rootMargin:r,threshold:typeof c=="number"?c:v4[c]},h=g=>{const{isIntersecting:p}=g;if(this.isInView===p||(this.isInView=p,f&&!p&&this.hasEnteredView))return;p&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",p);const{onViewportEnter:v,onViewportLeave:b}=this.node.getProps(),S=p?v:b;S&&S(g)};return y4(this.node.current,d,h)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:i,prevProps:l}=this.node;["amount","margin","root"].some(x4(i,l))&&this.startObserver()}unmount(){}}function x4({viewport:n={}},{viewport:i={}}={}){return l=>n[l]!==i[l]}const S4={inView:{Feature:b4},tap:{Feature:h4},focus:{Feature:d4},hover:{Feature:f4}},T4={layout:{ProjectionNode:zx,MeasureLayout:Px}},E4={...PN,...S4,...c4,...T4},Lv=GN(E4,qN),w4=[{id:"anthropic",name:"Claude",subtitle:"by Anthropic",icon:"/icons/claude.png"},{id:"openai",name:"OpenAI Codex",subtitle:"ChatGPT Plus / Pro",icon:"/icons/codex.png"},{id:"ollama",name:"Ollama",subtitle:"Run locally",icon:null}],A4={anthropic:[{id:"claude-opus-4-6",label:"Opus 4.6"},{id:"claude-sonnet-4-6",label:"Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",label:"Haiku 4.5"}],openai:[{id:"gpt-5.2-codex:medium",label:"GPT-5.2 Codex Medium"},{id:"gpt-5.2-codex:high",label:"GPT-5.2 Codex High"},{id:"gpt-5.2-codex:xhigh",label:"GPT-5.2 Codex Extra High"},{id:"gpt-5.3-codex:medium",label:"GPT-5.3 Codex Medium (Pro)"},{id:"gpt-5.3-codex:high",label:"GPT-5.3 Codex High (Pro)"},{id:"gpt-5.3-codex:xhigh",label:"GPT-5.3 Codex Extra High (Pro)"}],ollama:[{id:"llama3.2",label:"Llama 3.2"},{id:"mistral",label:"Mistral"},{id:"codellama",label:"Code Llama"},{id:"phi3",label:"Phi-3"}]},Uv=6,kv=[{tier:"premium",label:n=>`${n}.fluxy.bot`,badge:"$5",badgeCls:"bg-[#AF27E3]/15 text-[#AF27E3] border-[#AF27E3]/20",highlight:!0},{tier:"at",label:n=>`${n}.at.fluxy.bot`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1}];function C4({models:n,value:i,onChange:l}){const[r,c]=T.useState(!1),f=T.useRef(null);T.useEffect(()=>{if(!r)return;const h=g=>{f.current&&!f.current.contains(g.target)&&c(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[r]);const d=n.find(h=>h.id===i);return y.jsxs("div",{className:"relative",ref:f,children:[y.jsxs("button",{type:"button",onClick:()=>c(h=>!h),className:"w-full flex items-center justify-between bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none hover:border-white/15 focus:border-[#AF27E3]/30 transition-colors",children:[y.jsx("span",{className:d?"text-white":"text-white/20",children:d?d.label:"Choose a model..."}),y.jsx(wl,{className:`h-4 w-4 text-white/30 transition-transform ${r?"rotate-180":""}`})]}),r&&y.jsx("div",{className:"absolute left-0 right-0 top-full mt-1 bg-[#222] border border-white/[0.08] rounded-xl shadow-xl py-1 z-10 max-h-48 overflow-y-auto",children:n.map(h=>y.jsx("button",{onClick:()=>{l(h.id),c(!1)},className:`w-full text-left px-4 py-2 text-[13px] transition-colors ${i===h.id?"text-[#AF27E3] bg-[#AF27E3]/10":"text-white/70 hover:bg-white/[0.04] hover:text-white"}`,children:h.label},h.id))})]})}function M4({onComplete:n}){const[i,l]=T.useState(0),[r,c]=T.useState(""),[f,d]=T.useState("anthropic"),[h,g]=T.useState(""),[p,v]=T.useState(!1),[b,S]=T.useState({anthropic:"idle",openai:"idle",ollama:"connected"}),[A,D]=T.useState(!1),[M,N]=T.useState(""),[V,q]=T.useState(!1),[U,G]=T.useState(),[P,W]=T.useState(!1),[Z,L]=T.useState(!1),[tt,mt]=T.useState(),[St,At]=T.useState(""),[jt,Xt]=T.useState(""),[Ct,z]=T.useState(null),[F,$]=T.useState(""),[dt,Q]=T.useState({}),[w,Y]=T.useState("at"),[J,et]=T.useState(!1),[I,rt]=T.useState(!1),[gt,Ht]=T.useState(""),ft=T.useRef(null),[oe,He]=T.useState(null),[de,fn]=T.useState(!1),[Ee,li]=T.useState(!1),[dn,Ol]=T.useState(""),[hn,hs]=T.useState(""),[ja,ms]=T.useState(""),[Yo,zl]=T.useState(!1),[It,Xo]=T.useState(!1),[ri,_l]=T.useState(""),[Da,oi]=T.useState(""),[Ra,Vl]=T.useState(!1),[Ll,Zn]=T.useState(!1),[Kt,$e]=T.useState(!1),[qt,Ul]=T.useState(""),ps=T.useRef(!1),wn=b[f]==="connected";T.useEffect(()=>{fetch("/api/onboard/status").then(H=>H.json()).then(H=>{H.userName&&c(H.userName),H.handle&&(Xt(H.handle.username),Y(H.handle.tier||"at"),He({username:H.handle.username,tier:H.handle.tier,url:H.handle.url}),rt(!0),Ht(H.handle.url)),H.portalUser&&Ol(H.portalUser),H.portalConfigured&&Xo(!0),H.provider&&d(H.provider),H.model&&g(H.model),H.whisperEnabled&&($e(!0),Ul(H.whisperKey||"")),ps.current=!0}).catch(()=>{ps.current=!0})},[]),T.useEffect(()=>{f!=="anthropic"||b.anthropic==="connected"||fetch("/api/auth/claude/status").then(H=>H.json()).then(H=>{H.authenticated&&S(ct=>({...ct,anthropic:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{f!=="openai"||b.openai==="connected"||fetch("/api/auth/codex/status").then(H=>H.json()).then(H=>{H.authenticated&&S(ct=>({...ct,openai:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{if(!Z)return;const H=setInterval(async()=>{try{(await(await fetch("/api/auth/codex/status")).json()).authenticated&&(L(!1),S(Jn=>({...Jn,openai:"connected"})))}catch{}},2e3);return()=>clearInterval(H)},[Z]),T.useEffect(()=>{if(ft.current&&clearTimeout(ft.current),!ps.current||oe&&I&&jt===oe.username)return;z(null),$(""),Q({}),rt(!1),Ht("");const H=jt.trim();if(H){if(H.length<3){z("invalid"),$("At least 3 characters");return}return z("checking"),ft.current=setTimeout(async()=>{try{const he=await(await fetch(`/api/handle/check/${encodeURIComponent(H)}`)).json();if(!he.valid)z("invalid"),$(he.error);else{const Jn={};for(const za of he.handles)Jn[za.tier]=za.available;Q(Jn),z("ready");const ql=kv.find(za=>Jn[za.tier]);ql&&!Jn[w]&&Y(ql.tier)}}catch{z(null)}},400),()=>{ft.current&&clearTimeout(ft.current)}}},[jt]);const ui=H=>{Xt(H.toLowerCase().replace(/[^a-z0-9-]/g,""))},ci=async()=>{if(!(!jt||Ct!=="ready"||!dt[w])){et(!0);try{const ct=await(await fetch("/api/handle/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:jt,tier:w})})).json();ct.ok?(rt(!0),Ht(ct.url)):($(ct.error||"Registration failed"),z("invalid"))}catch{$("Could not reach server"),z("invalid")}finally{et(!1)}}},fi=async()=>{if(!(!jt||Ct!=="ready"||!dt[w])){li(!0);try{const ct=await(await fetch("/api/handle/change",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:jt,tier:w})})).json();ct.ok?(rt(!0),Ht(ct.url),He({username:jt,tier:w,url:ct.url}),fn(!1)):($(ct.error||"Handle change failed"),z("invalid"))}catch{$("Could not reach server"),z("invalid")}finally{li(!1)}}},An=H=>{f==="openai"&&H!=="openai"&&Z&&(fetch("/api/auth/codex/cancel",{method:"POST"}),L(!1)),d(H),g(""),D(!1),N(""),G(void 0),L(!1),mt(void 0)},di=async()=>{G(void 0);try{const ct=await(await fetch("/api/auth/claude/start",{method:"POST"})).json();ct.success&&ct.authUrl?(window.open(ct.authUrl,"_blank"),D(!0)):G(ct.error||"Failed to start authentication")}catch(H){G(H.message)}},Fn=async()=>{if(M.trim()){q(!0),G(void 0);try{const ct=await(await fetch("/api/auth/claude/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:M.trim()})})).json();ct.success?S(he=>({...he,anthropic:"connected"})):G(ct.error||"Code exchange failed")}catch(H){G(H.message)}finally{q(!1)}}},Ko=async()=>{try{const H=await navigator.clipboard.readText();H&&N(H.trim())}catch{}},kl=async()=>{W(!0),G(void 0);try{(await(await fetch("/api/auth/claude/status")).json()).authenticated?S(he=>({...he,anthropic:"connected"})):G("No active session found. Please authenticate first.")}catch{}finally{W(!1)}},gs=async()=>{L(!0),mt(void 0);try{const ct=await(await fetch("/api/auth/codex/start",{method:"POST"})).json();ct.success&&ct.authUrl?window.open(ct.authUrl,"_blank"):(L(!1),mt(ct.error||"Failed to start authentication"))}catch(H){L(!1),mt(H.message)}},Oa=()=>{L(!1),fetch("/api/auth/codex/cancel",{method:"POST"})},Bl=hn===ja,ys=dn.trim().length>=3&&hn.length>=6&&Bl,Hl=It?dn.trim().length>=3&&(hn.length===0||Ra&&ys):ys,Qn=(()=>{switch(i){case 0:return!0;case 1:return r.trim().length>0;case 2:return I;case 3:return Hl;case 4:return!!(f&&h&&wn);case 5:return!0;default:return!1}})(),tn=()=>{Qn&&i<Uv-1&&l(H=>H+1)},vs=()=>{i>0&&l(H=>H-1)},hi=H=>{H.key==="Enter"&&Qn&&tn()},Gl=async()=>{v(!0);try{await fetch("/api/onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userName:r.trim(),agentName:jt.trim()||"Fluxy",provider:f,model:h,apiKey:"",baseUrl:f==="ollama"&&St||void 0,whisperEnabled:Kt,whisperKey:Kt?qt:"",portalUser:dn.trim(),portalPass:hn})}),n()}catch(H){console.error("Onboard failed:",H),v(!1)}},xe="w-full bg-white/[0.05] border border-white/[0.08] text-white rounded-xl px-4 py-3 text-base outline-none input-glow placeholder:text-white/20 transition-all",$t="w-full bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none input-glow placeholder:text-white/20 transition-all";return y.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4",children:[y.jsx("div",{className:"absolute inset-0 bg-black/85 backdrop-blur-md"}),y.jsxs(Lv.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.3},className:"relative w-full max-w-[480px] bg-[#181818] border border-white/[0.06] rounded-[24px] shadow-2xl overflow-hidden",children:[y.jsx("div",{className:"flex justify-center gap-2 pt-6",children:Array.from({length:Uv},(H,ct)=>y.jsx("div",{className:`h-1.5 rounded-full transition-all duration-300 ${ct===i?"w-7 bg-gradient-brand":ct<i?"w-1.5 bg-gradient-brand opacity-60":"w-1.5 bg-white/10"}`},ct))}),y.jsx(gN,{mode:"wait",children:y.jsxs(Lv.div,{initial:{opacity:0,x:30},animate:{opacity:1,x:0},exit:{opacity:0,x:-30},transition:{duration:.2,ease:"easeOut"},className:"px-8 pt-6 pb-8",children:[i===0&&y.jsxs("div",{className:"flex flex-col items-center text-center",children:[y.jsx("video",{src:"/fluxy_say_hi.webm",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-[180px] mb-4"}),y.jsx("h1",{className:"text-2xl font-bold text-white tracking-tight",children:"Welcome to Fluxy"}),y.jsx("p",{className:"text-white/40 text-[14px] mt-2 leading-relaxed max-w-[320px]",children:"Let's set up your AI assistant in just a few steps."}),y.jsxs("button",{onClick:tn,className:"mt-6 px-7 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center gap-2",children:["Get Started",y.jsx(vn,{className:"h-4 w-4"})]})]}),i===1&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"What's your name?"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"This is how your agent will address you."}),y.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[y.jsx("input",{type:"text",value:r,onChange:H=>c(H.target.value),onKeyDown:hi,placeholder:"Enter your name",autoFocus:!0,className:xe+" flex-1"}),y.jsx("button",{onClick:tn,disabled:!Qn,className:"shrink-0 h-12 w-12 flex items-center justify-center rounded-full bg-gradient-brand hover:opacity-90 text-white transition-colors disabled:opacity-30",children:y.jsx(vn,{className:"h-5 w-5"})})]})]}),i===2&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Name your bot"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"This is your bot's name and permanent handle — access it from anywhere."}),oe&&I&&!de&&y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(cl,{className:"h-4 w-4 text-emerald-400"}),y.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Current handle"})]}),y.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:gt})]}),y.jsxs("div",{className:"flex gap-2 mt-4",children:[y.jsxs("button",{onClick:tn,className:"flex-1 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]}),y.jsx("button",{onClick:()=>{fn(!0),rt(!1),Xt(""),z(null),Q({})},className:"px-5 py-3 bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 text-[13px] font-medium rounded-full transition-colors",children:"Change"})]})]}),de&&!I&&y.jsxs("div",{className:"mt-4 bg-amber-500/8 border border-amber-500/20 rounded-xl px-4 py-3",children:[y.jsx("p",{className:"text-amber-400/90 text-[13px] font-medium",children:"Changing your handle"}),y.jsxs("p",{className:"text-amber-400/60 text-[12px] mt-1",children:["Your current handle ",y.jsx("span",{className:"font-mono",children:oe?.url})," will be released and become available for others."]})]}),(!oe||de||!I)&&!(oe&&I&&!de)&&y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"relative mt-5",children:[y.jsx("input",{type:"text",value:jt,onChange:H=>ui(H.target.value),maxLength:30,placeholder:"your-bot-name",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",autoFocus:!0,disabled:I,className:xe+" pr-10 font-mono"+(I?" opacity-50":"")}),Ct&&jt.length>0&&!I&&y.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:[Ct==="checking"&&y.jsx("div",{className:"w-5 h-5 border-2 border-white/10 border-t-[#04D1FE] rounded-full animate-spin"}),Ct==="invalid"&&y.jsx("div",{className:"w-6 h-6 rounded-full bg-amber-500/15 flex items-center justify-center",children:y.jsx("svg",{className:"w-3.5 h-3.5 text-amber-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:y.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3m0 4h.01"})})})]})]}),Ct==="invalid"&&F&&y.jsx("p",{className:"text-amber-400 text-[12px] mt-2",children:F}),Ct==="ready"&&jt.length>0&&!I&&y.jsx("div",{className:"space-y-2 mt-4",children:kv.map(H=>{const he=dt[H.tier]===!1;return y.jsxs("button",{onClick:()=>!he&&Y(H.tier),disabled:he,className:`w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all duration-200 text-left ${he?"border-white/[0.04] bg-transparent opacity-50 cursor-not-allowed":w===H.tier?H.highlight?"border-[#AF27E3]/40 bg-[#AF27E3]/[0.06]":"border-[#AF27E3]/30 bg-white/[0.04]":"border-white/[0.06] bg-transparent hover:border-white/10 hover:bg-white/[0.02]"}`,children:[y.jsx("span",{className:"font-mono text-[13px] text-white/70",children:H.label(jt)}),he?y.jsx("span",{className:"text-[11px] font-medium px-2.5 py-0.5 rounded-full border bg-red-500/10 text-red-400 border-red-500/20",children:"Taken"}):y.jsx("span",{className:`text-[11px] font-medium px-2.5 py-0.5 rounded-full border ${H.badgeCls}`,children:H.badge})]},H.tier)})}),I&&y.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(cl,{className:"h-4 w-4 text-emerald-400"}),y.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Handle claimed!"})]}),y.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:gt})]}),Ct==="ready"&&dt[w]&&jt.length>0&&!I&&y.jsx("button",{onClick:de?fi:ci,disabled:J||Ee,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:J||Ee?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-4 w-4 animate-spin"}),de?"Changing...":"Claiming..."]}):y.jsxs(y.Fragment,{children:[de?"Change Handle":"Claim & Continue",y.jsx(vn,{className:"h-4 w-4"})]})}),I&&y.jsxs("button",{onClick:tn,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]}),de&&!I&&y.jsx("button",{onClick:()=>{fn(!1),Xt(oe.username),rt(!0),Ht(oe.url),Y(oe.tier),z(null)},className:"w-full mt-2 py-2 text-white/25 hover:text-white/40 text-[12px] transition-colors",children:"Cancel — keep current handle"})]})]}),i===3&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Secure your portal"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"Create credentials to protect your dashboard. Anyone with your URL will need these to log in."}),I&&gt&&y.jsxs("div",{className:"mt-4 flex items-center gap-2 bg-white/[0.03] border border-white/[0.06] rounded-xl px-4 py-3",children:[y.jsx("span",{className:"font-mono text-[13px] text-white/60 truncate flex-1",children:gt}),y.jsx("button",{onClick:()=>{navigator.clipboard.writeText(gt),zl(!0),setTimeout(()=>zl(!1),2e3)},className:"shrink-0 text-white/30 hover:text-white/60 transition-colors",children:Yo?y.jsx(cl,{className:"h-4 w-4 text-emerald-400"}):y.jsxs("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[y.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),y.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),It&&y.jsx("div",{className:"mt-4 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-2.5",children:y.jsx("p",{className:"text-white/40 text-[12px]",children:"Credentials already set. Leave password fields empty to keep your current password, or enter your current password to change it."})}),y.jsxs("div",{className:"mt-5",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Username"}),y.jsx("input",{type:"text",value:dn,onChange:H=>Ol(H.target.value.replace(/\s/g,"").toLowerCase()),placeholder:"admin",autoFocus:!0,autoComplete:"username",className:xe+" font-mono"}),dn.length>0&&dn.trim().length<3&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 3 characters"})]}),It&&y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Current password"}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("input",{type:"password",value:ri,onChange:H=>{_l(H.target.value),oi(""),Vl(!1)},placeholder:"Enter current password to change it",autoComplete:"current-password",className:xe+" flex-1"}),ri.length>0&&!Ra&&y.jsx("button",{onClick:async()=>{Zn(!0),oi("");try{(await(await fetch("/api/portal/verify-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ri})})).json()).valid?Vl(!0):oi("Incorrect password")}catch{oi("Could not verify")}finally{Zn(!1)}},disabled:Ll,className:"shrink-0 px-4 py-3 bg-white/[0.06] hover:bg-white/[0.1] text-white/60 text-[13px] font-medium rounded-xl transition-colors disabled:opacity-40",children:Ll?y.jsx(Wi,{className:"h-4 w-4 animate-spin"}):"Verify"}),Ra&&y.jsx("div",{className:"shrink-0 w-10 h-10 flex items-center justify-center",children:y.jsx(cl,{className:"h-4 w-4 text-emerald-400"})})]}),Da&&y.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:Da})]}),(!It||Ra)&&y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:It?"New password":"Password"}),y.jsx("input",{type:"password",value:hn,onChange:H=>hs(H.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:hi,className:xe}),hn.length>0&&hn.length<6&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 6 characters"})]}),y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:It?"Confirm new password":"Confirm password"}),y.jsx("input",{type:"password",value:ja,onChange:H=>ms(H.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:hi,className:xe}),ja.length>0&&!Bl&&y.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:"Passwords don't match"})]})]}),y.jsxs("button",{onClick:tn,disabled:!Qn,className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]})]}),i===4&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Choose your AI provider"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"Pick one provider to power your bot, authenticate, and select a model."}),y.jsx("div",{className:"flex gap-2.5 mt-4",children:w4.map(H=>y.jsxs("button",{onClick:()=>An(H.id),className:`flex-1 relative rounded-xl border transition-all duration-200 p-3 text-left ${f===H.id?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:[y.jsxs("div",{className:"flex flex-col items-center gap-1.5 py-0.5",children:[H.icon?y.jsx("img",{src:H.icon,alt:H.name,className:"w-8 h-8 rounded-lg"}):y.jsx("div",{className:"w-8 h-8 rounded-lg bg-white/[0.06] flex items-center justify-center text-white/50 text-sm font-bold",children:"O"}),y.jsxs("div",{className:"text-center",children:[y.jsx("div",{className:"text-[13px] font-medium text-white",children:H.name}),y.jsx("div",{className:"text-[10px] text-white/30",children:H.subtitle})]})]}),b[H.id]==="connected"?y.jsx("div",{className:"absolute top-2 right-2 w-4 h-4 rounded-full bg-emerald-500/15 flex items-center justify-center",children:y.jsx(cl,{className:"h-2.5 w-2.5 text-emerald-400"})}):f===H.id?y.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-gradient-brand"}):null]},H.id))}),y.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),f==="anthropic"&&y.jsxs("div",{className:"space-y-2.5",children:[wn&&y.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — Anthropic subscription is active."})}),!wn&&y.jsxs(y.Fragment,{children:[U&&y.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-red-400/90 text-[12px]",children:U})}),y.jsx("div",{className:"space-y-1.5",children:["Click the button below to open Anthropic's login page","Sign in with your Anthropic account — a code will be generated","Copy the code and paste it in the field below"].map((H,ct)=>y.jsxs("div",{className:"flex items-start gap-2",children:[y.jsx("span",{className:"flex-shrink-0 w-[18px] h-[18px] rounded-full bg-white/[0.06] text-white/30 text-[10px] font-medium flex items-center justify-center mt-px",children:ct+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:H})]},ct))}),y.jsx("button",{onClick:di,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2",children:A?y.jsxs(y.Fragment,{children:[y.jsx(_2,{className:"h-3.5 w-3.5 opacity-60"}),"Open authentication page again"]}):y.jsxs(y.Fragment,{children:["Authenticate with Anthropic",y.jsx(vn,{className:"h-3.5 w-3.5 opacity-60"})]})}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:M,onChange:H=>N(H.target.value),onKeyDown:H=>H.key==="Enter"&&Fn(),placeholder:"Paste your code here...",className:$t+" pr-10 font-mono"}),y.jsx("button",{onClick:Ko,className:"absolute right-3 top-1/2 -translate-y-1/2 text-white/20 hover:text-white/50 transition-colors",children:y.jsx(D2,{className:"h-3.5 w-3.5"})})]}),y.jsx("button",{onClick:Fn,disabled:!M.trim()||V,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:V?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-3.5 w-3.5 animate-spin"}),"Verifying..."]}):"Connect"}),y.jsxs("button",{onClick:kl,disabled:P,className:"w-full py-1.5 text-white/25 text-[11px] hover:text-white/40 transition-colors flex items-center justify-center gap-1.5 disabled:opacity-50",children:[P?y.jsx(Wi,{className:"h-3 w-3 animate-spin"}):y.jsx(P2,{className:"h-3 w-3"}),P?"Checking...":"I'm already authenticated"]})]})]}),f==="openai"&&y.jsxs("div",{className:"space-y-2.5",children:[wn&&y.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — ChatGPT subscription is active."})}),!wn&&y.jsxs(y.Fragment,{children:[tt&&y.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-red-400/90 text-[12px]",children:tt})}),y.jsx("div",{className:"space-y-1.5",children:["Click the button below — your browser will open for ChatGPT sign-in","Sign in with your ChatGPT Plus or Pro account","Authentication completes automatically — no code to copy"].map((H,ct)=>y.jsxs("div",{className:"flex items-start gap-2",children:[y.jsx("span",{className:"flex-shrink-0 w-[18px] h-[18px] rounded-full bg-white/[0.06] text-white/30 text-[10px] font-medium flex items-center justify-center mt-px",children:ct+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:H})]},ct))}),y.jsx("button",{onClick:gs,disabled:Z,className:"w-full py-2.5 px-4 bg-white/[0.06] hover:bg-white/[0.09] text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-60",children:Z?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-3.5 w-3.5 animate-spin opacity-60"}),"Waiting for sign-in..."]}):y.jsxs(y.Fragment,{children:["Authenticate with ChatGPT",y.jsx(vn,{className:"h-3.5 w-3.5 opacity-60"})]})}),Z&&y.jsx("button",{onClick:Oa,className:"w-full py-1.5 text-white/25 text-[11px] hover:text-white/40 transition-colors",children:"Cancel"})]})]}),f==="ollama"&&y.jsxs("div",{className:"space-y-2.5",children:[y.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"No authentication needed — Ollama runs locally."})}),y.jsxs("div",{children:[y.jsxs("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:["Base URL ",y.jsx("span",{className:"text-white/20",children:"(optional)"})]}),y.jsx("input",{type:"text",value:St,onChange:H=>At(H.target.value),placeholder:"http://localhost:11434",className:$t})]})]}),wn&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Select a model"}),y.jsx(C4,{models:A4[f]||[],value:h,onChange:g})]}),wn&&y.jsxs("button",{onClick:tn,disabled:!Qn,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]})]}),i===5&&y.jsxs("div",{children:[y.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Voice Messages"}),y.jsx("span",{className:"text-[11px] text-white/25 font-medium bg-white/[0.04] border border-white/[0.06] rounded-full px-2.5 py-0.5",children:"Optional"})]}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1 leading-relaxed",children:"Allow users to send audio messages that are automatically transcribed."}),y.jsx("button",{onClick:()=>$e(H=>!H),className:`w-full mt-5 rounded-xl border transition-all duration-200 p-4 text-left ${Kt?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:y.jsxs("div",{className:"flex items-center gap-3.5",children:[y.jsx("img",{src:"/icons/openai.svg",alt:"OpenAI",className:"w-10 h-10 rounded-xl bg-white/[0.04] p-1.5"}),y.jsxs("div",{className:"flex-1",children:[y.jsx("div",{className:"text-[14px] font-medium text-white",children:"OpenAI Whisper"}),y.jsx("div",{className:"text-[12px] text-white/35 mt-0.5 leading-relaxed",children:"Speech-to-text powered by OpenAI. Requires an OpenAI API key."})]}),y.jsx("div",{className:`w-10 h-[22px] rounded-full transition-colors duration-200 flex items-center px-0.5 shrink-0 ${Kt?"bg-gradient-brand":"bg-white/[0.08]"}`,children:y.jsx("div",{className:`w-[18px] h-[18px] rounded-full bg-white shadow-sm transition-transform duration-200 ${Kt?"translate-x-[18px]":"translate-x-0"}`})})]})}),Kt&&y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"OpenAI API Key"}),y.jsx("input",{type:"password",value:qt,onChange:H=>Ul(H.target.value.trim()),placeholder:"sk-...",autoComplete:"off",className:xe+" font-mono text-[13px]"}),qt.length>0&&!qt.startsWith("sk-")&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key should start with sk-"}),qt.length>0&&qt.startsWith("sk-")&&qt.length<20&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key looks too short"}),y.jsxs("div",{className:"flex items-start gap-2.5 mt-3 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-3",children:[y.jsx(X2,{className:"h-4 w-4 text-[#AF27E3]/60 mt-0.5 shrink-0"}),y.jsx("p",{className:"text-white/35 text-[12px] leading-relaxed",children:"Users will see a microphone button in the chat. Audio is sent to OpenAI's Whisper API for transcription, then processed as a regular text message."})]})]}),y.jsx("button",{onClick:Gl,disabled:p||Kt&&(!qt.startsWith("sk-")||qt.length<20),className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:p?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-4 w-4 animate-spin"}),"Setting up..."]}):y.jsxs(y.Fragment,{children:["Complete Setup",y.jsx(vn,{className:"h-4 w-4"})]})}),!Kt&&y.jsx("p",{className:"text-center text-white/20 text-[11px] mt-2.5",children:"You can enable this later in Settings."})]})]},i)}),i>0&&y.jsx("div",{className:"px-8 pb-5 -mt-3",children:y.jsx("button",{onClick:vs,className:"text-white/25 hover:text-white/50 text-[12px] transition-colors",children:"← Back"})})]})]})}function N4(){return y.jsx("div",{className:"flex items-center justify-center h-dvh p-6 text-center",children:y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Something went wrong"}),y.jsx("p",{className:"text-sm text-muted-foreground",children:"The dashboard encountered an error. Use the Fluxy button to continue chatting."})]})})}function j4(){const[n,i]=T.useState(!1),[l,r]=T.useState("idle"),[c,f]=T.useState("");T.useEffect(()=>{fetch("/api/settings").then(h=>h.json()).then(h=>{h.onboard_complete!=="true"&&i(!0)}).catch(()=>{})},[]),T.useEffect(()=>{const h=g=>{g.data?.type==="fluxy:rebuilding"?(r("rebuilding"),f("")):g.data?.type==="fluxy:rebuilt"?(r("idle"),location.reload()):g.data?.type==="fluxy:build-error"&&(r("error"),f(g.data.error||"Build failed"),setTimeout(()=>r("idle"),5e3))};return window.addEventListener("message",h),()=>window.removeEventListener("message",h)},[]);const d=()=>{i(!1)};return y.jsxs(y.Fragment,{children:[y.jsx(h2,{fallback:y.jsx(N4,{}),children:y.jsx(wA,{onOpenOnboard:()=>i(!0),children:y.jsx(jA,{})})}),n&&y.jsx(M4,{onComplete:d}),l!=="idle"&&y.jsxs("div",{className:"fixed inset-0 z-[49] flex flex-col items-center justify-center bg-background/90",children:[y.jsx("video",{src:"/fluxy_tilts.webm",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-24 w-24 rounded-full object-cover"}),y.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:l==="rebuilding"?"Rebuilding app...":c})]})]})}d2.createRoot(document.getElementById("root")).render(y.jsx(Kn.StrictMode,{children:y.jsx(j4,{})}));
64
+ `),()=>{P.contains(G)&&P.removeChild(G)}},[i]),y.jsx(dN,{isPresent:i,childRef:h,sizeRef:g,pop:f,children:f===!1?n:T.cloneElement(n,{ref:b})})}const mN=({children:n,initial:i,isPresent:l,onExitComplete:r,custom:c,presenceAffectsLayout:f,mode:d,anchorX:h,anchorY:g,root:p})=>{const v=bd(pN),b=T.useId();let S=!0,A=T.useMemo(()=>(S=!1,{id:b,initial:i,isPresent:l,custom:c,onExitComplete:D=>{v.set(D,!0);for(const M of v.values())if(!M)return;r&&r()},register:D=>(v.set(D,!1),()=>v.delete(D))}),[l,v,r]);return f&&S&&(A={...A}),T.useMemo(()=>{v.forEach((D,M)=>v.set(M,!1))},[l]),T.useEffect(()=>{!l&&!v.size&&r&&r()},[l]),n=y.jsx(hN,{pop:d==="popLayout",isPresent:l,anchorX:h,anchorY:g,root:p,children:n}),y.jsx(Bo.Provider,{value:A,children:n})};function pN(){return new Map}function _x(n=!0){const i=T.useContext(Bo);if(i===null)return[!0,null];const{isPresent:l,onExitComplete:r,register:c}=i,f=T.useId();T.useEffect(()=>{if(n)return c(f)},[n]);const d=T.useCallback(()=>n&&r&&r(f),[f,r,n]);return!l&&r?[!1,d]:[!0]}const co=n=>n.key||"";function Tv(n){const i=[];return T.Children.forEach(n,l=>{T.isValidElement(l)&&i.push(l)}),i}const gN=({children:n,custom:i,initial:l=!0,onExitComplete:r,presenceAffectsLayout:c=!0,mode:f="sync",propagate:d=!1,anchorX:h="left",anchorY:g="top",root:p})=>{const[v,b]=_x(d),S=T.useMemo(()=>Tv(n),[n]),A=d&&!v?[]:S.map(co),D=T.useRef(!0),M=T.useRef(S),N=bd(()=>new Map),V=T.useRef(new Set),[q,U]=T.useState(S),[G,P]=T.useState(S);ob(()=>{D.current=!1,M.current=S;for(let L=0;L<G.length;L++){const tt=co(G[L]);A.includes(tt)?(N.delete(tt),V.current.delete(tt)):N.get(tt)!==!0&&N.set(tt,!1)}},[G,A.length,A.join("-")]);const W=[];if(S!==q){let L=[...S];for(let tt=0;tt<G.length;tt++){const mt=G[tt],St=co(mt);A.includes(St)||(L.splice(tt,0,mt),W.push(mt))}return f==="wait"&&W.length&&(L=W),P(Tv(L)),U(S),null}const{forceRender:Z}=T.useContext(vd);return y.jsx(y.Fragment,{children:G.map(L=>{const tt=co(L),mt=d&&!v?!1:S===G||A.includes(tt),St=()=>{if(V.current.has(tt))return;if(V.current.add(tt),N.has(tt))N.set(tt,!0);else return;let At=!0;N.forEach(jt=>{jt||(At=!1)}),At&&(Z?.(),P(M.current),d&&b?.(),r&&r())};return y.jsx(mN,{isPresent:mt,initial:!D.current||l?void 0:!1,custom:i,presenceAffectsLayout:c,mode:f,root:p,onExitComplete:mt?void 0:St,anchorX:h,anchorY:g,children:L},tt)})})},Vx=T.createContext({strict:!1}),Ev={animation:["animate","variants","whileHover","whileTap","exit","whileInView","whileFocus","whileDrag"],exit:["exit"],drag:["drag","dragControls"],focus:["whileFocus"],hover:["whileHover","onHoverStart","onHoverEnd"],tap:["whileTap","onTap","onTapStart","onTapCancel"],pan:["onPan","onPanStart","onPanSessionStart","onPanEnd"],inView:["whileInView","onViewportEnter","onViewportLeave"],layout:["layout","layoutId"]};let wv=!1;function yN(){if(wv)return;const n={};for(const i in Ev)n[i]={isEnabled:l=>Ev[i].some(r=>!!l[r])};cx(n),wv=!0}function Lx(){return yN(),nM()}function vN(n){const i=Lx();for(const l in n)i[l]={...i[l],...n[l]};cx(i)}const bN=new Set(["animate","exit","variants","initial","style","values","variants","transition","transformTemplate","custom","inherit","onBeforeLayoutMeasure","onAnimationStart","onAnimationComplete","onUpdate","onDragStart","onDrag","onDragEnd","onMeasureDragConstraints","onDirectionLock","onDragTransitionEnd","_dragX","_dragY","onHoverStart","onHoverEnd","onViewportEnter","onViewportLeave","globalTapTarget","propagate","ignoreStrict","viewport"]);function Oo(n){return n.startsWith("while")||n.startsWith("drag")&&n!=="draggable"||n.startsWith("layout")||n.startsWith("onTap")||n.startsWith("onPan")||n.startsWith("onLayout")||bN.has(n)}let Ux=n=>!Oo(n);function xN(n){typeof n=="function"&&(Ux=i=>i.startsWith("on")?!Oo(i):n(i))}try{xN(require("@emotion/is-prop-valid").default)}catch{}function SN(n,i,l){const r={};for(const c in n)c==="values"&&typeof n.values=="object"||(Ux(c)||l===!0&&Oo(c)||!i&&!Oo(c)||n.draggable&&c.startsWith("onDrag"))&&(r[c]=n[c]);return r}const qo=T.createContext({});function TN(n,i){if(Go(n)){const{initial:l,animate:r}=n;return{initial:l===!1||Tl(l)?l:void 0,animate:Tl(r)?r:void 0}}return n.inherit!==!1?i:{}}function EN(n){const{initial:i,animate:l}=TN(n,T.useContext(qo));return T.useMemo(()=>({initial:i,animate:l}),[Av(i),Av(l)])}function Av(n){return Array.isArray(n)?n.join(" "):n}const Zd=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function kx(n,i,l){for(const r in i)!Te(i[r])&&!yx(r,l)&&(n[r]=i[r])}function wN({transformTemplate:n},i){return T.useMemo(()=>{const l=Zd();return Xd(l,i,n),Object.assign({},l.vars,l.style)},[i])}function AN(n,i){const l=n.style||{},r={};return kx(r,l,n),Object.assign(r,wN(n,i)),r}function CN(n,i){const l={},r=AN(n,i);return n.drag&&n.dragListener!==!1&&(l.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout="none",r.touchAction=n.drag===!0?"none":`pan-${n.drag==="x"?"y":"x"}`),n.tabIndex===void 0&&(n.onTap||n.onTapStart||n.whileTap)&&(l.tabIndex=0),l.style=r,l}const Bx=()=>({...Zd(),attrs:{}});function MN(n,i,l,r){const c=T.useMemo(()=>{const f=Bx();return vx(f,i,xx(r),n.transformTemplate,n.style),{...f.attrs,style:{...f.style}}},[i]);if(n.style){const f={};kx(f,n.style,n),c.style={...f,...c.style}}return c}const NN=["animate","circle","defs","desc","ellipse","g","image","line","filter","marker","mask","metadata","path","pattern","polygon","polyline","rect","stop","switch","symbol","svg","text","tspan","use","view"];function Fd(n){return typeof n!="string"||n.includes("-")?!1:!!(NN.indexOf(n)>-1||/[A-Z]/u.test(n))}function jN(n,i,l,{latestValues:r},c,f=!1,d){const g=(d??Fd(n)?MN:CN)(i,r,c,n),p=SN(i,typeof n=="string",f),v=n!==T.Fragment?{...p,...g,ref:l}:{},{children:b}=i,S=T.useMemo(()=>Te(b)?b.get():b,[b]);return T.createElement(n,{...v,children:S})}function DN({scrapeMotionValuesFromProps:n,createRenderState:i},l,r,c){return{latestValues:RN(l,r,c,n),renderState:i()}}function RN(n,i,l,r){const c={},f=r(n,{});for(const S in f)c[S]=xo(f[S]);let{initial:d,animate:h}=n;const g=Go(n),p=ox(n);i&&p&&!g&&n.inherit!==!1&&(d===void 0&&(d=i.initial),h===void 0&&(h=i.animate));let v=l?l.initial===!1:!1;v=v||d===!1;const b=v?h:d;if(b&&typeof b!="boolean"&&!Ho(b)){const S=Array.isArray(b)?b:[b];for(let A=0;A<S.length;A++){const D=Ld(n,S[A]);if(D){const{transitionEnd:M,transition:N,...V}=D;for(const q in V){let U=V[q];if(Array.isArray(U)){const G=v?U.length-1:0;U=U[G]}U!==null&&(c[q]=U)}for(const q in M)c[q]=M[q]}}}return c}const Hx=n=>(i,l)=>{const r=T.useContext(qo),c=T.useContext(Bo),f=()=>DN(n,i,r,c);return l?f():bd(f)},ON=Hx({scrapeMotionValuesFromProps:Kd,createRenderState:Zd}),zN=Hx({scrapeMotionValuesFromProps:Sx,createRenderState:Bx}),_N=Symbol.for("motionComponentSymbol");function VN(n,i,l){const r=T.useRef(l);T.useInsertionEffect(()=>{r.current=l});const c=T.useRef(null);return T.useCallback(f=>{f&&n.onMount?.(f),i&&(f?i.mount(f):i.unmount());const d=r.current;if(typeof d=="function")if(f){const h=d(f);typeof h=="function"&&(c.current=h)}else c.current?(c.current(),c.current=null):d(f);else d&&(d.current=f)},[i])}const Gx=T.createContext({});function es(n){return n&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"current")}function LN(n,i,l,r,c,f){const{visualElement:d}=T.useContext(qo),h=T.useContext(Vx),g=T.useContext(Bo),p=T.useContext(Pd),v=p.reducedMotion,b=p.skipAnimations,S=T.useRef(null),A=T.useRef(!1);r=r||h.renderer,!S.current&&r&&(S.current=r(n,{visualState:i,parent:d,props:l,presenceContext:g,blockInitialAnimation:g?g.initial===!1:!1,reducedMotionConfig:v,skipAnimations:b,isSVG:f}),A.current&&S.current&&(S.current.manuallyAnimateOnMount=!0));const D=S.current,M=T.useContext(Gx);D&&!D.projection&&c&&(D.type==="html"||D.type==="svg")&&UN(S.current,l,c,M);const N=T.useRef(!1);T.useInsertionEffect(()=>{D&&N.current&&D.update(l,g)});const V=l[Qb],q=T.useRef(!!V&&!window.MotionHandoffIsComplete?.(V)&&window.MotionHasOptimisedAnimation?.(V));return ob(()=>{A.current=!0,D&&(N.current=!0,window.MotionIsMounted=!0,D.updateFeatures(),D.scheduleRenderMicrotask(),q.current&&D.animationState&&D.animationState.animateChanges())}),T.useEffect(()=>{D&&(!q.current&&D.animationState&&D.animationState.animateChanges(),q.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(V)}),q.current=!1),D.enteringChildren=void 0)}),D}function UN(n,i,l,r){const{layoutId:c,layout:f,drag:d,dragConstraints:h,layoutScroll:g,layoutRoot:p,layoutCrossfade:v}=i;n.projection=new l(n.latestValues,i["data-framer-portal-id"]?void 0:qx(n.parent)),n.projection.setOptions({layoutId:c,layout:f,alwaysMeasureLayout:!!d||h&&es(h),visualElement:n,animationType:typeof f=="string"?f:"both",initialPromotionConfig:r,crossfade:v,layoutScroll:g,layoutRoot:p})}function qx(n){if(n)return n.options.allowProjection!==!1?n.projection:qx(n.parent)}function jf(n,{forwardMotionProps:i=!1,type:l}={},r,c){r&&vN(r);const f=l?l==="svg":Fd(n),d=f?zN:ON;function h(p,v){let b;const S={...T.useContext(Pd),...p,layoutId:kN(p)},{isStatic:A}=S,D=EN(p),M=d(p,A);if(!A&&rb){BN();const N=HN(S);b=N.MeasureLayout,D.visualElement=LN(n,M,S,c,N.ProjectionNode,f)}return y.jsxs(qo.Provider,{value:D,children:[b&&D.visualElement?y.jsx(b,{visualElement:D.visualElement,...S}):null,jN(n,p,VN(M,D.visualElement,v),M,A,i,f)]})}h.displayName=`motion.${typeof n=="string"?n:`create(${n.displayName??n.name??""})`}`;const g=T.forwardRef(h);return g[_N]=n,g}function kN({layoutId:n}){const i=T.useContext(vd).id;return i&&n!==void 0?i+"-"+n:n}function BN(n,i){T.useContext(Vx).strict}function HN(n){const i=Lx(),{drag:l,layout:r}=i;if(!l&&!r)return{};const c={...l,...r};return{MeasureLayout:l?.isEnabled(n)||r?.isEnabled(n)?c.MeasureLayout:void 0,ProjectionNode:c.ProjectionNode}}function GN(n,i){if(typeof Proxy>"u")return jf;const l=new Map,r=(f,d)=>jf(f,d,n,i),c=(f,d)=>r(f,d);return new Proxy(c,{get:(f,d)=>d==="create"?r:(l.has(d)||l.set(d,jf(d,void 0,n,i)),l.get(d))})}const qN=(n,i)=>i.isSVG??Fd(n)?new bM(i):new hM(i,{allowProjection:n!==T.Fragment});class YN extends Na{constructor(i){super(i),i.animationState||(i.animationState=wM(i))}updateAnimationControlsSubscription(){const{animate:i}=this.node.getProps();Ho(i)&&(this.unmountControls=i.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:i}=this.node.getProps(),{animate:l}=this.node.prevProps||{};i!==l&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let XN=0;class KN extends Na{constructor(){super(...arguments),this.id=XN++}update(){if(!this.node.presenceContext)return;const{isPresent:i,onExitComplete:l}=this.node.presenceContext,{isPresent:r}=this.node.prevPresenceContext||{};if(!this.node.animationState||i===r)return;const c=this.node.animationState.setActive("exit",!i);l&&!i&&c.then(()=>{l(this.id)})}mount(){const{register:i,onExitComplete:l}=this.node.presenceContext||{};l&&l(this.id),i&&(this.unmount=i(this.id))}unmount(){}}const PN={animation:{Feature:YN},exit:{Feature:KN}};function Rl(n){return{point:{x:n.pageX,y:n.pageY}}}const ZN=n=>i=>Hd(i)&&n(i,Rl(i));function vl(n,i,l,r){return El(n,i,ZN(l),r)}const Yx=({current:n})=>n?n.ownerDocument.defaultView:null,Cv=(n,i)=>Math.abs(n-i);function FN(n,i){const l=Cv(n.x,i.x),r=Cv(n.y,i.y);return Math.sqrt(l**2+r**2)}const Mv=new Set(["auto","scroll"]);class Xx{constructor(i,l,{transformPagePoint:r,contextWindow:c=window,dragSnapToOrigin:f=!1,distanceThreshold:d=3,element:h}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.removeScrollListeners=null,this.onElementScroll=A=>{this.handleScroll(A.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const A=Rf(this.lastMoveEventInfo,this.history),D=this.startEvent!==null,M=FN(A.offset,{x:0,y:0})>=this.distanceThreshold;if(!D&&!M)return;const{point:N}=A,{timestamp:V}=ve;this.history.push({...N,timestamp:V});const{onStart:q,onMove:U}=this.handlers;D||(q&&q(this.lastMoveEvent,A),this.startEvent=this.lastMoveEvent),U&&U(this.lastMoveEvent,A)},this.handlePointerMove=(A,D)=>{this.lastMoveEvent=A,this.lastMoveEventInfo=Df(D,this.transformPagePoint),Ut.update(this.updatePoint,!0)},this.handlePointerUp=(A,D)=>{this.end();const{onEnd:M,onSessionEnd:N,resumeAnimation:V}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&V&&V(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const q=Rf(A.type==="pointercancel"?this.lastMoveEventInfo:Df(D,this.transformPagePoint),this.history);this.startEvent&&M&&M(A,q),N&&N(A,q)},!Hd(i))return;this.dragSnapToOrigin=f,this.handlers=l,this.transformPagePoint=r,this.distanceThreshold=d,this.contextWindow=c||window;const g=Rl(i),p=Df(g,this.transformPagePoint),{point:v}=p,{timestamp:b}=ve;this.history=[{...v,timestamp:b}];const{onSessionStart:S}=l;S&&S(i,Rf(p,this.history)),this.removeListeners=Nl(vl(this.contextWindow,"pointermove",this.handlePointerMove),vl(this.contextWindow,"pointerup",this.handlePointerUp),vl(this.contextWindow,"pointercancel",this.handlePointerUp)),h&&this.startScrollTracking(h)}startScrollTracking(i){let l=i.parentElement;for(;l;){const r=getComputedStyle(l);(Mv.has(r.overflowX)||Mv.has(r.overflowY))&&this.scrollPositions.set(l,{x:l.scrollLeft,y:l.scrollTop}),l=l.parentElement}this.scrollPositions.set(window,{x:window.scrollX,y:window.scrollY}),window.addEventListener("scroll",this.onElementScroll,{capture:!0}),window.addEventListener("scroll",this.onWindowScroll),this.removeScrollListeners=()=>{window.removeEventListener("scroll",this.onElementScroll,{capture:!0}),window.removeEventListener("scroll",this.onWindowScroll)}}handleScroll(i){const l=this.scrollPositions.get(i);if(!l)return;const r=i===window,c=r?{x:window.scrollX,y:window.scrollY}:{x:i.scrollLeft,y:i.scrollTop},f={x:c.x-l.x,y:c.y-l.y};f.x===0&&f.y===0||(r?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=f.x,this.lastMoveEventInfo.point.y+=f.y):this.history.length>0&&(this.history[0].x-=f.x,this.history[0].y-=f.y),this.scrollPositions.set(i,c),Ut.update(this.updatePoint,!0))}updateHandlers(i){this.handlers=i}end(){this.removeListeners&&this.removeListeners(),this.removeScrollListeners&&this.removeScrollListeners(),this.scrollPositions.clear(),Ca(this.updatePoint)}}function Df(n,i){return i?{point:i(n.point)}:n}function Nv(n,i){return{x:n.x-i.x,y:n.y-i.y}}function Rf({point:n},i){return{point:n,delta:Nv(n,Kx(i)),offset:Nv(n,QN(i)),velocity:JN(i,.1)}}function QN(n){return n[0]}function Kx(n){return n[n.length-1]}function JN(n,i){if(n.length<2)return{x:0,y:0};let l=n.length-1,r=null;const c=Kx(n);for(;l>=0&&(r=n[l],!(c.timestamp-r.timestamp>rn(i)));)l--;if(!r)return{x:0,y:0};r===n[0]&&n.length>2&&c.timestamp-r.timestamp>rn(i)*2&&(r=n[1]);const f=We(c.timestamp-r.timestamp);if(f===0)return{x:0,y:0};const d={x:(c.x-r.x)/f,y:(c.y-r.y)/f};return d.x===1/0&&(d.x=0),d.y===1/0&&(d.y=0),d}function WN(n,{min:i,max:l},r){return i!==void 0&&n<i?n=r?Yt(i,n,r.min):Math.max(n,i):l!==void 0&&n>l&&(n=r?Yt(l,n,r.max):Math.min(n,l)),n}function jv(n,i,l){return{min:i!==void 0?n.min+i:void 0,max:l!==void 0?n.max+l-(n.max-n.min):void 0}}function IN(n,{top:i,left:l,bottom:r,right:c}){return{x:jv(n.x,l,c),y:jv(n.y,i,r)}}function Dv(n,i){let l=i.min-n.min,r=i.max-n.max;return i.max-i.min<n.max-n.min&&([l,r]=[r,l]),{min:l,max:r}}function $N(n,i){return{x:Dv(n.x,i.x),y:Dv(n.y,i.y)}}function t4(n,i){let l=.5;const r=Ce(n),c=Ce(i);return c>r?l=bl(i.min,i.max-r,n.min):r>c&&(l=bl(n.min,n.max-c,i.min)),En(0,1,l)}function e4(n,i){const l={};return i.min!==void 0&&(l.min=i.min-n.min),i.max!==void 0&&(l.max=i.max-n.min),l}const rd=.35;function n4(n=rd){return n===!1?n=0:n===!0&&(n=rd),{x:Rv(n,"left","right"),y:Rv(n,"top","bottom")}}function Rv(n,i,l){return{min:Ov(n,i),max:Ov(n,l)}}function Ov(n,i){return typeof n=="number"?n:n[i]||0}const a4=new WeakMap;class i4{constructor(i){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=re(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=i}start(i,{snapToCursor:l=!1,distanceThreshold:r}={}){const{presenceContext:c}=this.visualElement;if(c&&c.isPresent===!1)return;const f=b=>{l&&this.snapToCursor(Rl(b).point),this.stopAnimation()},d=(b,S)=>{const{drag:A,dragPropagation:D,onDragStart:M}=this.getProps();if(A&&!D&&(this.openDragLock&&this.openDragLock(),this.openDragLock=O3(A),!this.openDragLock))return;this.latestPointerEvent=b,this.latestPanInfo=S,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints(),this.visualElement.projection&&(this.visualElement.projection.isAnimationBlocked=!0,this.visualElement.projection.target=void 0),bn(V=>{let q=this.getAxisMotionValue(V).get()||0;if(Sn.test(q)){const{projection:U}=this.visualElement;if(U&&U.layout){const G=U.layout.layoutBox[V];G&&(q=Ce(G)*(parseFloat(q)/100))}}this.originPoint[V]=q}),M&&Ut.update(()=>M(b,S),!1,!0),If(this.visualElement,"transform");const{animationState:N}=this.visualElement;N&&N.setActive("whileDrag",!0)},h=(b,S)=>{this.latestPointerEvent=b,this.latestPanInfo=S;const{dragPropagation:A,dragDirectionLock:D,onDirectionLock:M,onDrag:N}=this.getProps();if(!A&&!this.openDragLock)return;const{offset:V}=S;if(D&&this.currentDirection===null){this.currentDirection=l4(V),this.currentDirection!==null&&M&&M(this.currentDirection);return}this.updateAxis("x",S.point,V),this.updateAxis("y",S.point,V),this.visualElement.render(),N&&Ut.update(()=>N(b,S),!1,!0)},g=(b,S)=>{this.latestPointerEvent=b,this.latestPanInfo=S,this.stop(b,S),this.latestPointerEvent=null,this.latestPanInfo=null},p=()=>{const{dragSnapToOrigin:b}=this.getProps();(b||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:v}=this.getProps();this.panSession=new Xx(i,{onSessionStart:f,onStart:d,onMove:h,onSessionEnd:g,resumeAnimation:p},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:v,distanceThreshold:r,contextWindow:Yx(this.visualElement),element:this.visualElement.current})}stop(i,l){const r=i||this.latestPointerEvent,c=l||this.latestPanInfo,f=this.isDragging;if(this.cancel(),!f||!c||!r)return;const{velocity:d}=c;this.startAnimation(d);const{onDragEnd:h}=this.getProps();h&&Ut.postRender(()=>h(r,c))}cancel(){this.isDragging=!1;const{projection:i,animationState:l}=this.visualElement;i&&(i.isAnimationBlocked=!1),this.endPanSession();const{dragPropagation:r}=this.getProps();!r&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),l&&l.setActive("whileDrag",!1)}endPanSession(){this.panSession&&this.panSession.end(),this.panSession=void 0}updateAxis(i,l,r){const{drag:c}=this.getProps();if(!r||!fo(i,c,this.currentDirection))return;const f=this.getAxisMotionValue(i);let d=this.originPoint[i]+r[i];this.constraints&&this.constraints[i]&&(d=WN(d,this.constraints[i],this.elastic[i])),f.set(d)}resolveConstraints(){const{dragConstraints:i,dragElastic:l}=this.getProps(),r=this.visualElement.projection&&!this.visualElement.projection.layout?this.visualElement.projection.measure(!1):this.visualElement.projection?.layout,c=this.constraints;i&&es(i)?this.constraints||(this.constraints=this.resolveRefConstraints()):i&&r?this.constraints=IN(r.layoutBox,i):this.constraints=!1,this.elastic=n4(l),c!==this.constraints&&!es(i)&&r&&this.constraints&&!this.hasMutatedConstraints&&bn(f=>{this.constraints!==!1&&this.getAxisMotionValue(f)&&(this.constraints[f]=e4(r.layoutBox[f],this.constraints[f]))})}resolveRefConstraints(){const{dragConstraints:i,onMeasureDragConstraints:l}=this.getProps();if(!i||!es(i))return!1;const r=i.current,{projection:c}=this.visualElement;if(!c||!c.layout)return!1;const f=rM(r,c.root,this.visualElement.getTransformPagePoint());let d=$N(c.layout.layoutBox,f);if(l){const h=l(iM(d));this.hasMutatedConstraints=!!h,h&&(d=dx(h))}return d}startAnimation(i){const{drag:l,dragMomentum:r,dragElastic:c,dragTransition:f,dragSnapToOrigin:d,onDragTransitionEnd:h}=this.getProps(),g=this.constraints||{},p=bn(v=>{if(!fo(v,l,this.currentDirection))return;let b=g&&g[v]||{};d&&(b={min:0,max:0});const S=c?200:1e6,A=c?40:1e7,D={type:"inertia",velocity:r?i[v]:0,bounceStiffness:S,bounceDamping:A,timeConstant:750,restDelta:1,restSpeed:10,...f,...b};return this.startAxisValueAnimation(v,D)});return Promise.all(p).then(h)}startAxisValueAnimation(i,l){const r=this.getAxisMotionValue(i);return If(this.visualElement,i),r.start(Vd(i,r,0,l,this.visualElement,!1))}stopAnimation(){bn(i=>this.getAxisMotionValue(i).stop())}getAxisMotionValue(i){const l=`_drag${i.toUpperCase()}`,r=this.visualElement.getProps(),c=r[l];return c||this.visualElement.getValue(i,(r.initial?r.initial[i]:void 0)||0)}snapToCursor(i){bn(l=>{const{drag:r}=this.getProps();if(!fo(l,r,this.currentDirection))return;const{projection:c}=this.visualElement,f=this.getAxisMotionValue(l);if(c&&c.layout){const{min:d,max:h}=c.layout.layoutBox[l],g=f.get()||0;f.set(i[l]-Yt(d,h,.5)+g)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:i,dragConstraints:l}=this.getProps(),{projection:r}=this.visualElement;if(!es(l)||!r||!this.constraints)return;this.stopAnimation();const c={x:0,y:0};bn(d=>{const h=this.getAxisMotionValue(d);if(h&&this.constraints!==!1){const g=h.get();c[d]=t4({min:g,max:g},this.constraints[d])}});const{transformTemplate:f}=this.visualElement.getProps();this.visualElement.current.style.transform=f?f({},""):"none",r.root&&r.root.updateScroll(),r.updateLayout(),this.constraints=!1,this.resolveConstraints(),bn(d=>{if(!fo(d,i,null))return;const h=this.getAxisMotionValue(d),{min:g,max:p}=this.constraints[d];h.set(Yt(g,p,c[d]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;a4.set(this.visualElement,this);const i=this.visualElement.current,l=vl(i,"pointerdown",p=>{const{drag:v,dragListener:b=!0}=this.getProps(),S=p.target,A=S!==i&&k3(S);v&&b&&!A&&this.start(p)});let r;const c=()=>{const{dragConstraints:p}=this.getProps();es(p)&&p.current&&(this.constraints=this.resolveRefConstraints(),r||(r=s4(i,p.current,()=>this.scalePositionWithinConstraints())))},{projection:f}=this.visualElement,d=f.addEventListener("measure",c);f&&!f.layout&&(f.root&&f.root.updateScroll(),f.updateLayout()),Ut.read(c);const h=El(window,"resize",()=>this.scalePositionWithinConstraints()),g=f.addEventListener("didUpdate",(({delta:p,hasLayoutChanged:v})=>{this.isDragging&&v&&(bn(b=>{const S=this.getAxisMotionValue(b);S&&(this.originPoint[b]+=p[b].translate,S.set(S.get()+p[b].translate))}),this.visualElement.render())}));return()=>{h(),l(),d(),g&&g(),r&&r()}}getProps(){const i=this.visualElement.getProps(),{drag:l=!1,dragDirectionLock:r=!1,dragPropagation:c=!1,dragConstraints:f=!1,dragElastic:d=rd,dragMomentum:h=!0}=i;return{...i,drag:l,dragDirectionLock:r,dragPropagation:c,dragConstraints:f,dragElastic:d,dragMomentum:h}}}function zv(n){let i=!0;return()=>{if(i){i=!1;return}n()}}function s4(n,i,l){const r=Hy(n,zv(l)),c=Hy(i,zv(l));return()=>{r(),c()}}function fo(n,i,l){return(i===!0||i===n)&&(l===null||l===n)}function l4(n,i=10){let l=null;return Math.abs(n.y)>i?l="y":Math.abs(n.x)>i&&(l="x"),l}class r4 extends Na{constructor(i){super(i),this.removeGroupControls=Ie,this.removeListeners=Ie,this.controls=new i4(i)}mount(){const{dragControls:i}=this.node.getProps();i&&(this.removeGroupControls=i.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Ie}update(){const{dragControls:i}=this.node.getProps(),{dragControls:l}=this.node.prevProps||{};i!==l&&(this.removeGroupControls(),i&&(this.removeGroupControls=i.subscribe(this.controls)))}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}}const Of=n=>(i,l)=>{n&&Ut.update(()=>n(i,l),!1,!0)};class o4 extends Na{constructor(){super(...arguments),this.removePointerDownListener=Ie}onPointerDown(i){this.session=new Xx(i,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:Yx(this.node)})}createPanHandlers(){const{onPanSessionStart:i,onPanStart:l,onPan:r,onPanEnd:c}=this.node.getProps();return{onSessionStart:Of(i),onStart:Of(l),onMove:Of(r),onEnd:(f,d)=>{delete this.session,c&&Ut.postRender(()=>c(f,d))}}}mount(){this.removePointerDownListener=vl(this.node.current,"pointerdown",i=>this.onPointerDown(i))}update(){this.session&&this.session.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session&&this.session.end()}}let zf=!1;class u4 extends T.Component{componentDidMount(){const{visualElement:i,layoutGroup:l,switchLayoutGroup:r,layoutId:c}=this.props,{projection:f}=i;f&&(l.group&&l.group.add(f),r&&r.register&&c&&r.register(f),zf&&f.root.didUpdate(),f.addEventListener("animationComplete",()=>{this.safeToRemove()}),f.setOptions({...f.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),So.hasEverUpdated=!0}getSnapshotBeforeUpdate(i){const{layoutDependency:l,visualElement:r,drag:c,isPresent:f}=this.props,{projection:d}=r;return d&&(d.isPresent=f,i.layoutDependency!==l&&d.setOptions({...d.options,layoutDependency:l}),zf=!0,c||i.layoutDependency!==l||l===void 0||i.isPresent!==f?d.willUpdate():this.safeToRemove(),i.isPresent!==f&&(f?d.promote():d.relegate()||Ut.postRender(()=>{const h=d.getStack();(!h||!h.members.length)&&this.safeToRemove()}))),null}componentDidUpdate(){const{projection:i}=this.props.visualElement;i&&(i.root.didUpdate(),Bd.postRender(()=>{!i.currentAnimation&&i.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:i,layoutGroup:l,switchLayoutGroup:r}=this.props,{projection:c}=i;zf=!0,c&&(c.scheduleCheckAfterUnmount(),l&&l.group&&l.group.remove(c),r&&r.deregister&&r.deregister(c))}safeToRemove(){const{safeToRemove:i}=this.props;i&&i()}render(){return null}}function Px(n){const[i,l]=_x(),r=T.useContext(vd);return y.jsx(u4,{...n,layoutGroup:r,switchLayoutGroup:T.useContext(Gx),isPresent:i,safeToRemove:l})}const c4={pan:{Feature:o4},drag:{Feature:r4,ProjectionNode:zx,MeasureLayout:Px}};function _v(n,i,l){const{props:r}=n;n.animationState&&r.whileHover&&n.animationState.setActive("whileHover",l==="Start");const c="onHover"+l,f=r[c];f&&Ut.postRender(()=>f(i,Rl(i)))}class f4 extends Na{mount(){const{current:i}=this.node;i&&(this.unmount=_3(i,(l,r)=>(_v(this.node,r,"Start"),c=>_v(this.node,c,"End"))))}unmount(){}}class d4 extends Na{constructor(){super(...arguments),this.isActive=!1}onFocus(){let i=!1;try{i=this.node.current.matches(":focus-visible")}catch{i=!0}!i||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!0),this.isActive=!0)}onBlur(){!this.isActive||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!1),this.isActive=!1)}mount(){this.unmount=Nl(El(this.node.current,"focus",()=>this.onFocus()),El(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function Vv(n,i,l){const{props:r}=n;if(n.current instanceof HTMLButtonElement&&n.current.disabled)return;n.animationState&&r.whileTap&&n.animationState.setActive("whileTap",l==="Start");const c="onTap"+(l==="End"?"":l),f=r[c];f&&Ut.postRender(()=>f(i,Rl(i)))}class h4 extends Na{mount(){const{current:i}=this.node;if(!i)return;const{globalTapTarget:l,propagate:r}=this.node.props;this.unmount=H3(i,(c,f)=>(Vv(this.node,f,"Start"),(d,{success:h})=>Vv(this.node,d,h?"End":"Cancel")),{useGlobalTarget:l,stopPropagation:r?.tap===!1})}unmount(){}}const od=new WeakMap,_f=new WeakMap,m4=n=>{const i=od.get(n.target);i&&i(n)},p4=n=>{n.forEach(m4)};function g4({root:n,...i}){const l=n||document;_f.has(l)||_f.set(l,{});const r=_f.get(l),c=JSON.stringify(i);return r[c]||(r[c]=new IntersectionObserver(p4,{root:n,...i})),r[c]}function y4(n,i,l){const r=g4(i);return od.set(n,l),r.observe(n),()=>{od.delete(n),r.unobserve(n)}}const v4={some:0,all:1};class b4 extends Na{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:i={}}=this.node.getProps(),{root:l,margin:r,amount:c="some",once:f}=i,d={root:l?l.current:void 0,rootMargin:r,threshold:typeof c=="number"?c:v4[c]},h=g=>{const{isIntersecting:p}=g;if(this.isInView===p||(this.isInView=p,f&&!p&&this.hasEnteredView))return;p&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",p);const{onViewportEnter:v,onViewportLeave:b}=this.node.getProps(),S=p?v:b;S&&S(g)};return y4(this.node.current,d,h)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:i,prevProps:l}=this.node;["amount","margin","root"].some(x4(i,l))&&this.startObserver()}unmount(){}}function x4({viewport:n={}},{viewport:i={}}={}){return l=>n[l]!==i[l]}const S4={inView:{Feature:b4},tap:{Feature:h4},focus:{Feature:d4},hover:{Feature:f4}},T4={layout:{ProjectionNode:zx,MeasureLayout:Px}},E4={...PN,...S4,...c4,...T4},Lv=GN(E4,qN),w4=[{id:"anthropic",name:"Claude",subtitle:"by Anthropic",icon:"/icons/claude.png"},{id:"openai",name:"OpenAI Codex",subtitle:"ChatGPT Plus / Pro",icon:"/icons/codex.png"},{id:"ollama",name:"Ollama",subtitle:"Run locally",icon:null}],A4={anthropic:[{id:"claude-opus-4-6",label:"Opus 4.6"},{id:"claude-sonnet-4-6",label:"Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",label:"Haiku 4.5"}],openai:[{id:"gpt-5.2-codex:medium",label:"GPT-5.2 Codex Medium"},{id:"gpt-5.2-codex:high",label:"GPT-5.2 Codex High"},{id:"gpt-5.2-codex:xhigh",label:"GPT-5.2 Codex Extra High"},{id:"gpt-5.3-codex:medium",label:"GPT-5.3 Codex Medium (Pro)"},{id:"gpt-5.3-codex:high",label:"GPT-5.3 Codex High (Pro)"},{id:"gpt-5.3-codex:xhigh",label:"GPT-5.3 Codex Extra High (Pro)"}],ollama:[{id:"llama3.2",label:"Llama 3.2"},{id:"mistral",label:"Mistral"},{id:"codellama",label:"Code Llama"},{id:"phi3",label:"Phi-3"}]},Uv=6,kv=[{tier:"premium",label:n=>`${n}.fluxy.bot`,badge:"$5",badgeCls:"bg-[#AF27E3]/15 text-[#AF27E3] border-[#AF27E3]/20",highlight:!0},{tier:"at",label:n=>`${n}.at.fluxy.bot`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1}];function C4({models:n,value:i,onChange:l}){const[r,c]=T.useState(!1),f=T.useRef(null);T.useEffect(()=>{if(!r)return;const h=g=>{f.current&&!f.current.contains(g.target)&&c(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[r]);const d=n.find(h=>h.id===i);return y.jsxs("div",{className:"relative",ref:f,children:[y.jsxs("button",{type:"button",onClick:()=>c(h=>!h),className:"w-full flex items-center justify-between bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none hover:border-white/15 focus:border-[#AF27E3]/30 transition-colors",children:[y.jsx("span",{className:d?"text-white":"text-white/20",children:d?d.label:"Choose a model..."}),y.jsx(wl,{className:`h-4 w-4 text-white/30 transition-transform ${r?"rotate-180":""}`})]}),r&&y.jsx("div",{className:"absolute left-0 right-0 top-full mt-1 bg-[#222] border border-white/[0.08] rounded-xl shadow-xl py-1 z-10 max-h-48 overflow-y-auto",children:n.map(h=>y.jsx("button",{onClick:()=>{l(h.id),c(!1)},className:`w-full text-left px-4 py-2 text-[13px] transition-colors ${i===h.id?"text-[#AF27E3] bg-[#AF27E3]/10":"text-white/70 hover:bg-white/[0.04] hover:text-white"}`,children:h.label},h.id))})]})}function M4({onComplete:n}){const[i,l]=T.useState(0),[r,c]=T.useState(""),[f,d]=T.useState("anthropic"),[h,g]=T.useState(""),[p,v]=T.useState(!1),[b,S]=T.useState({anthropic:"idle",openai:"idle",ollama:"connected"}),[A,D]=T.useState(!1),[M,N]=T.useState(""),[V,q]=T.useState(!1),[U,G]=T.useState(),[P,W]=T.useState(!1),[Z,L]=T.useState(!1),[tt,mt]=T.useState(),[St,At]=T.useState(""),[jt,Xt]=T.useState(""),[Ct,z]=T.useState(null),[F,$]=T.useState(""),[dt,Q]=T.useState({}),[w,Y]=T.useState("at"),[J,et]=T.useState(!1),[I,rt]=T.useState(!1),[gt,Ht]=T.useState(""),ft=T.useRef(null),[oe,He]=T.useState(null),[de,fn]=T.useState(!1),[Ee,li]=T.useState(!1),[dn,Ol]=T.useState(""),[hn,hs]=T.useState(""),[ja,ms]=T.useState(""),[Yo,zl]=T.useState(!1),[It,Xo]=T.useState(!1),[ri,_l]=T.useState(""),[Da,oi]=T.useState(""),[Ra,Vl]=T.useState(!1),[Ll,Zn]=T.useState(!1),[Kt,$e]=T.useState(!1),[qt,Ul]=T.useState(""),ps=T.useRef(!1),wn=b[f]==="connected";T.useEffect(()=>{fetch("/api/onboard/status").then(H=>H.json()).then(H=>{H.userName&&c(H.userName),H.handle&&(Xt(H.handle.username),Y(H.handle.tier||"at"),He({username:H.handle.username,tier:H.handle.tier,url:H.handle.url}),rt(!0),Ht(H.handle.url)),H.portalUser&&Ol(H.portalUser),H.portalConfigured&&Xo(!0),H.provider&&d(H.provider),H.model&&g(H.model),H.whisperEnabled&&($e(!0),Ul(H.whisperKey||"")),ps.current=!0}).catch(()=>{ps.current=!0})},[]),T.useEffect(()=>{f!=="anthropic"||b.anthropic==="connected"||fetch("/api/auth/claude/status").then(H=>H.json()).then(H=>{H.authenticated&&S(ct=>({...ct,anthropic:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{f!=="openai"||b.openai==="connected"||fetch("/api/auth/codex/status").then(H=>H.json()).then(H=>{H.authenticated&&S(ct=>({...ct,openai:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{if(!Z)return;const H=setInterval(async()=>{try{(await(await fetch("/api/auth/codex/status")).json()).authenticated&&(L(!1),S(Jn=>({...Jn,openai:"connected"})))}catch{}},2e3);return()=>clearInterval(H)},[Z]),T.useEffect(()=>{if(ft.current&&clearTimeout(ft.current),!ps.current||oe&&I&&jt===oe.username)return;z(null),$(""),Q({}),rt(!1),Ht("");const H=jt.trim();if(H){if(H.length<3){z("invalid"),$("At least 3 characters");return}return z("checking"),ft.current=setTimeout(async()=>{try{const he=await(await fetch(`/api/handle/check/${encodeURIComponent(H)}`)).json();if(!he.valid)z("invalid"),$(he.error);else{const Jn={};for(const za of he.handles)Jn[za.tier]=za.available;Q(Jn),z("ready");const ql=kv.find(za=>Jn[za.tier]);ql&&!Jn[w]&&Y(ql.tier)}}catch{z(null)}},400),()=>{ft.current&&clearTimeout(ft.current)}}},[jt]);const ui=H=>{Xt(H.toLowerCase().replace(/[^a-z0-9-]/g,""))},ci=async()=>{if(!(!jt||Ct!=="ready"||!dt[w])){et(!0);try{const ct=await(await fetch("/api/handle/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:jt,tier:w})})).json();ct.ok?(rt(!0),Ht(ct.url)):($(ct.error||"Registration failed"),z("invalid"))}catch{$("Could not reach server"),z("invalid")}finally{et(!1)}}},fi=async()=>{if(!(!jt||Ct!=="ready"||!dt[w])){li(!0);try{const ct=await(await fetch("/api/handle/change",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:jt,tier:w})})).json();ct.ok?(rt(!0),Ht(ct.url),He({username:jt,tier:w,url:ct.url}),fn(!1)):($(ct.error||"Handle change failed"),z("invalid"))}catch{$("Could not reach server"),z("invalid")}finally{li(!1)}}},An=H=>{f==="openai"&&H!=="openai"&&Z&&(fetch("/api/auth/codex/cancel",{method:"POST"}),L(!1)),d(H),g(""),D(!1),N(""),G(void 0),L(!1),mt(void 0)},di=async()=>{G(void 0);try{const ct=await(await fetch("/api/auth/claude/start",{method:"POST"})).json();ct.success&&ct.authUrl?(window.open(ct.authUrl,"_blank"),D(!0)):G(ct.error||"Failed to start authentication")}catch(H){G(H.message)}},Fn=async()=>{if(M.trim()){q(!0),G(void 0);try{const ct=await(await fetch("/api/auth/claude/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:M.trim()})})).json();ct.success?S(he=>({...he,anthropic:"connected"})):G(ct.error||"Code exchange failed")}catch(H){G(H.message)}finally{q(!1)}}},Ko=async()=>{try{const H=await navigator.clipboard.readText();H&&N(H.trim())}catch{}},kl=async()=>{W(!0),G(void 0);try{(await(await fetch("/api/auth/claude/status")).json()).authenticated?S(he=>({...he,anthropic:"connected"})):G("No active session found. Please authenticate first.")}catch{}finally{W(!1)}},gs=async()=>{L(!0),mt(void 0);try{const ct=await(await fetch("/api/auth/codex/start",{method:"POST"})).json();ct.success&&ct.authUrl?window.open(ct.authUrl,"_blank"):(L(!1),mt(ct.error||"Failed to start authentication"))}catch(H){L(!1),mt(H.message)}},Oa=()=>{L(!1),fetch("/api/auth/codex/cancel",{method:"POST"})},Bl=hn===ja,ys=dn.trim().length>=3&&hn.length>=6&&Bl,Hl=It?dn.trim().length>=3&&(hn.length===0||Ra&&ys):ys,Qn=(()=>{switch(i){case 0:return!0;case 1:return r.trim().length>0;case 2:return I;case 3:return Hl;case 4:return!!(f&&h&&wn);case 5:return!0;default:return!1}})(),tn=()=>{Qn&&i<Uv-1&&l(H=>H+1)},vs=()=>{i>0&&l(H=>H-1)},hi=H=>{H.key==="Enter"&&Qn&&tn()},Gl=async()=>{v(!0);try{await fetch("/api/onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userName:r.trim(),agentName:jt.trim()||"Fluxy",provider:f,model:h,apiKey:"",baseUrl:f==="ollama"&&St||void 0,whisperEnabled:Kt,whisperKey:Kt?qt:"",portalUser:dn.trim(),portalPass:hn})}),n()}catch(H){console.error("Onboard failed:",H),v(!1)}},xe="w-full bg-white/[0.05] border border-white/[0.08] text-white rounded-xl px-4 py-3 text-base outline-none input-glow placeholder:text-white/20 transition-all",$t="w-full bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none input-glow placeholder:text-white/20 transition-all";return y.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4",children:[y.jsx("div",{className:"absolute inset-0 bg-black/85 backdrop-blur-md"}),y.jsxs(Lv.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.3},className:"relative w-full max-w-[480px] bg-[#181818] border border-white/[0.06] rounded-[24px] shadow-2xl overflow-hidden",children:[y.jsx("div",{className:"flex justify-center gap-2 pt-6",children:Array.from({length:Uv},(H,ct)=>y.jsx("div",{className:`h-1.5 rounded-full transition-all duration-300 ${ct===i?"w-7 bg-gradient-brand":ct<i?"w-1.5 bg-gradient-brand opacity-60":"w-1.5 bg-white/10"}`},ct))}),y.jsx(gN,{mode:"wait",children:y.jsxs(Lv.div,{initial:{opacity:0,x:30},animate:{opacity:1,x:0},exit:{opacity:0,x:-30},transition:{duration:.2,ease:"easeOut"},className:"px-8 pt-6 pb-8",children:[i===0&&y.jsxs("div",{className:"flex flex-col items-center text-center",children:[y.jsx("video",{src:"/fluxy_say_hi.webm",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-[180px] mb-4"}),y.jsx("h1",{className:"text-2xl font-bold text-white tracking-tight",children:"Welcome to Fluxy"}),y.jsx("p",{className:"text-white/40 text-[14px] mt-2 leading-relaxed max-w-[320px]",children:"Let's set up your AI assistant in just a few steps."}),y.jsxs("button",{onClick:tn,className:"mt-6 px-7 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center gap-2",children:["Get Started",y.jsx(vn,{className:"h-4 w-4"})]})]}),i===1&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"What's your name?"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"This is how your agent will address you."}),y.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[y.jsx("input",{type:"text",value:r,onChange:H=>c(H.target.value),onKeyDown:hi,placeholder:"Enter your name",autoFocus:!0,className:xe+" flex-1"}),y.jsx("button",{onClick:tn,disabled:!Qn,className:"shrink-0 h-12 w-12 flex items-center justify-center rounded-full bg-gradient-brand hover:opacity-90 text-white transition-colors disabled:opacity-30",children:y.jsx(vn,{className:"h-5 w-5"})})]})]}),i===2&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Name your bot"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"This is your bot's name and permanent handle — access it from anywhere."}),oe&&I&&!de&&y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(cl,{className:"h-4 w-4 text-emerald-400"}),y.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Current handle"})]}),y.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:gt})]}),y.jsxs("div",{className:"flex gap-2 mt-4",children:[y.jsxs("button",{onClick:tn,className:"flex-1 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]}),y.jsx("button",{onClick:()=>{fn(!0),rt(!1),Xt(""),z(null),Q({})},className:"px-5 py-3 bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 text-[13px] font-medium rounded-full transition-colors",children:"Change"})]})]}),de&&!I&&y.jsxs("div",{className:"mt-4 bg-amber-500/8 border border-amber-500/20 rounded-xl px-4 py-3",children:[y.jsx("p",{className:"text-amber-400/90 text-[13px] font-medium",children:"Changing your handle"}),y.jsxs("p",{className:"text-amber-400/60 text-[12px] mt-1",children:["Your current handle ",y.jsx("span",{className:"font-mono",children:oe?.url})," will be released and become available for others."]})]}),(!oe||de||!I)&&!(oe&&I&&!de)&&y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"relative mt-5",children:[y.jsx("input",{type:"text",value:jt,onChange:H=>ui(H.target.value),maxLength:30,placeholder:"your-bot-name",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",autoFocus:!0,disabled:I,className:xe+" pr-10 font-mono"+(I?" opacity-50":"")}),Ct&&jt.length>0&&!I&&y.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:[Ct==="checking"&&y.jsx("div",{className:"w-5 h-5 border-2 border-white/10 border-t-[#04D1FE] rounded-full animate-spin"}),Ct==="invalid"&&y.jsx("div",{className:"w-6 h-6 rounded-full bg-amber-500/15 flex items-center justify-center",children:y.jsx("svg",{className:"w-3.5 h-3.5 text-amber-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:y.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3m0 4h.01"})})})]})]}),Ct==="invalid"&&F&&y.jsx("p",{className:"text-amber-400 text-[12px] mt-2",children:F}),Ct==="ready"&&jt.length>0&&!I&&y.jsx("div",{className:"space-y-2 mt-4",children:kv.map(H=>{const he=dt[H.tier]===!1;return y.jsxs("button",{onClick:()=>!he&&Y(H.tier),disabled:he,className:`w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all duration-200 text-left ${he?"border-white/[0.04] bg-transparent opacity-50 cursor-not-allowed":w===H.tier?H.highlight?"border-[#AF27E3]/40 bg-[#AF27E3]/[0.06]":"border-[#AF27E3]/30 bg-white/[0.04]":"border-white/[0.06] bg-transparent hover:border-white/10 hover:bg-white/[0.02]"}`,children:[y.jsx("span",{className:"font-mono text-[13px] text-white/70",children:H.label(jt)}),he?y.jsx("span",{className:"text-[11px] font-medium px-2.5 py-0.5 rounded-full border bg-red-500/10 text-red-400 border-red-500/20",children:"Taken"}):y.jsx("span",{className:`text-[11px] font-medium px-2.5 py-0.5 rounded-full border ${H.badgeCls}`,children:H.badge})]},H.tier)})}),I&&y.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx(cl,{className:"h-4 w-4 text-emerald-400"}),y.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Handle claimed!"})]}),y.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:gt})]}),Ct==="ready"&&dt[w]&&jt.length>0&&!I&&y.jsx("button",{onClick:de?fi:ci,disabled:J||Ee,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:J||Ee?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-4 w-4 animate-spin"}),de?"Changing...":"Claiming..."]}):y.jsxs(y.Fragment,{children:[de?"Change Handle":"Claim & Continue",y.jsx(vn,{className:"h-4 w-4"})]})}),I&&y.jsxs("button",{onClick:tn,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]}),de&&!I&&y.jsx("button",{onClick:()=>{fn(!1),Xt(oe.username),rt(!0),Ht(oe.url),Y(oe.tier),z(null)},className:"w-full mt-2 py-2 text-white/25 hover:text-white/40 text-[12px] transition-colors",children:"Cancel — keep current handle"})]})]}),i===3&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Secure your portal"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"Create credentials to protect your dashboard. Anyone with your URL will need these to log in."}),I&&gt&&y.jsxs("div",{className:"mt-4 flex items-center gap-2 bg-white/[0.03] border border-white/[0.06] rounded-xl px-4 py-3",children:[y.jsx("span",{className:"font-mono text-[13px] text-white/60 truncate flex-1",children:gt}),y.jsx("button",{onClick:()=>{navigator.clipboard.writeText(gt),zl(!0),setTimeout(()=>zl(!1),2e3)},className:"shrink-0 text-white/30 hover:text-white/60 transition-colors",children:Yo?y.jsx(cl,{className:"h-4 w-4 text-emerald-400"}):y.jsxs("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[y.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),y.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),It&&y.jsx("div",{className:"mt-4 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-2.5",children:y.jsx("p",{className:"text-white/40 text-[12px]",children:"Credentials already set. Leave password fields empty to keep your current password, or enter your current password to change it."})}),y.jsxs("div",{className:"mt-5",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Username"}),y.jsx("input",{type:"text",value:dn,onChange:H=>Ol(H.target.value.replace(/\s/g,"").toLowerCase()),placeholder:"admin",autoFocus:!0,autoComplete:"username",className:xe+" font-mono"}),dn.length>0&&dn.trim().length<3&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 3 characters"})]}),It&&y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Current password"}),y.jsxs("div",{className:"flex items-center gap-2",children:[y.jsx("input",{type:"password",value:ri,onChange:H=>{_l(H.target.value),oi(""),Vl(!1)},placeholder:"Enter current password to change it",autoComplete:"current-password",className:xe+" flex-1"}),ri.length>0&&!Ra&&y.jsx("button",{onClick:async()=>{Zn(!0),oi("");try{(await(await fetch("/api/portal/verify-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:ri})})).json()).valid?Vl(!0):oi("Incorrect password")}catch{oi("Could not verify")}finally{Zn(!1)}},disabled:Ll,className:"shrink-0 px-4 py-3 bg-white/[0.06] hover:bg-white/[0.1] text-white/60 text-[13px] font-medium rounded-xl transition-colors disabled:opacity-40",children:Ll?y.jsx(Wi,{className:"h-4 w-4 animate-spin"}):"Verify"}),Ra&&y.jsx("div",{className:"shrink-0 w-10 h-10 flex items-center justify-center",children:y.jsx(cl,{className:"h-4 w-4 text-emerald-400"})})]}),Da&&y.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:Da})]}),(!It||Ra)&&y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:It?"New password":"Password"}),y.jsx("input",{type:"password",value:hn,onChange:H=>hs(H.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:hi,className:xe}),hn.length>0&&hn.length<6&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 6 characters"})]}),y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:It?"Confirm new password":"Confirm password"}),y.jsx("input",{type:"password",value:ja,onChange:H=>ms(H.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:hi,className:xe}),ja.length>0&&!Bl&&y.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:"Passwords don't match"})]})]}),y.jsxs("button",{onClick:tn,disabled:!Qn,className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]})]}),i===4&&y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Choose your AI provider"}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"Pick one provider to power your bot, authenticate, and select a model."}),y.jsx("div",{className:"flex gap-2.5 mt-4",children:w4.map(H=>y.jsxs("button",{onClick:()=>An(H.id),className:`flex-1 relative rounded-xl border transition-all duration-200 p-3 text-left ${f===H.id?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:[y.jsxs("div",{className:"flex flex-col items-center gap-1.5 py-0.5",children:[H.icon?y.jsx("img",{src:H.icon,alt:H.name,className:"w-8 h-8 rounded-lg"}):y.jsx("div",{className:"w-8 h-8 rounded-lg bg-white/[0.06] flex items-center justify-center text-white/50 text-sm font-bold",children:"O"}),y.jsxs("div",{className:"text-center",children:[y.jsx("div",{className:"text-[13px] font-medium text-white",children:H.name}),y.jsx("div",{className:"text-[10px] text-white/30",children:H.subtitle})]})]}),b[H.id]==="connected"?y.jsx("div",{className:"absolute top-2 right-2 w-4 h-4 rounded-full bg-emerald-500/15 flex items-center justify-center",children:y.jsx(cl,{className:"h-2.5 w-2.5 text-emerald-400"})}):f===H.id?y.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-gradient-brand"}):null]},H.id))}),y.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),f==="anthropic"&&y.jsxs("div",{className:"space-y-2.5",children:[wn&&y.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — Anthropic subscription is active."})}),!wn&&y.jsxs(y.Fragment,{children:[U&&y.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-red-400/90 text-[12px]",children:U})}),y.jsx("div",{className:"space-y-1.5",children:["Click the button below to open Anthropic's login page","Sign in with your Anthropic account — a code will be generated","Copy the code and paste it in the field below"].map((H,ct)=>y.jsxs("div",{className:"flex items-start gap-2",children:[y.jsx("span",{className:"flex-shrink-0 w-[18px] h-[18px] rounded-full bg-white/[0.06] text-white/30 text-[10px] font-medium flex items-center justify-center mt-px",children:ct+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:H})]},ct))}),y.jsx("button",{onClick:di,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2",children:A?y.jsxs(y.Fragment,{children:[y.jsx(_2,{className:"h-3.5 w-3.5 opacity-60"}),"Open authentication page again"]}):y.jsxs(y.Fragment,{children:["Authenticate with Anthropic",y.jsx(vn,{className:"h-3.5 w-3.5 opacity-60"})]})}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:M,onChange:H=>N(H.target.value),onKeyDown:H=>H.key==="Enter"&&Fn(),placeholder:"Paste your code here...",className:$t+" pr-10 font-mono"}),y.jsx("button",{onClick:Ko,className:"absolute right-3 top-1/2 -translate-y-1/2 text-white/20 hover:text-white/50 transition-colors",children:y.jsx(D2,{className:"h-3.5 w-3.5"})})]}),y.jsx("button",{onClick:Fn,disabled:!M.trim()||V,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:V?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-3.5 w-3.5 animate-spin"}),"Verifying..."]}):"Connect"}),y.jsxs("button",{onClick:kl,disabled:P,className:"w-full py-1.5 text-white/25 text-[11px] hover:text-white/40 transition-colors flex items-center justify-center gap-1.5 disabled:opacity-50",children:[P?y.jsx(Wi,{className:"h-3 w-3 animate-spin"}):y.jsx(P2,{className:"h-3 w-3"}),P?"Checking...":"I'm already authenticated"]})]})]}),f==="openai"&&y.jsxs("div",{className:"space-y-2.5",children:[wn&&y.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — ChatGPT subscription is active."})}),!wn&&y.jsxs(y.Fragment,{children:[tt&&y.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-red-400/90 text-[12px]",children:tt})}),y.jsx("div",{className:"space-y-1.5",children:["Click the button below — your browser will open for ChatGPT sign-in","Sign in with your ChatGPT Plus or Pro account","Authentication completes automatically — no code to copy"].map((H,ct)=>y.jsxs("div",{className:"flex items-start gap-2",children:[y.jsx("span",{className:"flex-shrink-0 w-[18px] h-[18px] rounded-full bg-white/[0.06] text-white/30 text-[10px] font-medium flex items-center justify-center mt-px",children:ct+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:H})]},ct))}),y.jsx("button",{onClick:gs,disabled:Z,className:"w-full py-2.5 px-4 bg-white/[0.06] hover:bg-white/[0.09] text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-60",children:Z?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-3.5 w-3.5 animate-spin opacity-60"}),"Waiting for sign-in..."]}):y.jsxs(y.Fragment,{children:["Authenticate with ChatGPT",y.jsx(vn,{className:"h-3.5 w-3.5 opacity-60"})]})}),Z&&y.jsx("button",{onClick:Oa,className:"w-full py-1.5 text-white/25 text-[11px] hover:text-white/40 transition-colors",children:"Cancel"})]})]}),f==="ollama"&&y.jsxs("div",{className:"space-y-2.5",children:[y.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:y.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"No authentication needed — Ollama runs locally."})}),y.jsxs("div",{children:[y.jsxs("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:["Base URL ",y.jsx("span",{className:"text-white/20",children:"(optional)"})]}),y.jsx("input",{type:"text",value:St,onChange:H=>At(H.target.value),placeholder:"http://localhost:11434",className:$t})]})]}),wn&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Select a model"}),y.jsx(C4,{models:A4[f]||[],value:h,onChange:g})]}),wn&&y.jsxs("button",{onClick:tn,disabled:!Qn,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",y.jsx(vn,{className:"h-4 w-4"})]})]}),i===5&&y.jsxs("div",{children:[y.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[y.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Voice Messages"}),y.jsx("span",{className:"text-[11px] text-white/25 font-medium bg-white/[0.04] border border-white/[0.06] rounded-full px-2.5 py-0.5",children:"Optional"})]}),y.jsx("p",{className:"text-white/40 text-[13px] mt-1 leading-relaxed",children:"Allow users to send audio messages that are automatically transcribed."}),y.jsx("button",{onClick:()=>$e(H=>!H),className:`w-full mt-5 rounded-xl border transition-all duration-200 p-4 text-left ${Kt?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:y.jsxs("div",{className:"flex items-center gap-3.5",children:[y.jsx("img",{src:"/icons/openai.svg",alt:"OpenAI",className:"w-10 h-10 rounded-xl bg-white/[0.04] p-1.5"}),y.jsxs("div",{className:"flex-1",children:[y.jsx("div",{className:"text-[14px] font-medium text-white",children:"OpenAI Whisper"}),y.jsx("div",{className:"text-[12px] text-white/35 mt-0.5 leading-relaxed",children:"Speech-to-text powered by OpenAI. Requires an OpenAI API key."})]}),y.jsx("div",{className:`w-10 h-[22px] rounded-full transition-colors duration-200 flex items-center px-0.5 shrink-0 ${Kt?"bg-gradient-brand":"bg-white/[0.08]"}`,children:y.jsx("div",{className:`w-[18px] h-[18px] rounded-full bg-white shadow-sm transition-transform duration-200 ${Kt?"translate-x-[18px]":"translate-x-0"}`})})]})}),Kt&&y.jsxs("div",{className:"mt-3",children:[y.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"OpenAI API Key"}),y.jsx("input",{type:"password",value:qt,onChange:H=>Ul(H.target.value.trim()),placeholder:"sk-...",autoComplete:"off",className:xe+" font-mono text-[13px]"}),qt.length>0&&!qt.startsWith("sk-")&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key should start with sk-"}),qt.length>0&&qt.startsWith("sk-")&&qt.length<20&&y.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key looks too short"}),y.jsxs("div",{className:"flex items-start gap-2.5 mt-3 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-3",children:[y.jsx(X2,{className:"h-4 w-4 text-[#AF27E3]/60 mt-0.5 shrink-0"}),y.jsx("p",{className:"text-white/35 text-[12px] leading-relaxed",children:"Users will see a microphone button in the chat. Audio is sent to OpenAI's Whisper API for transcription, then processed as a regular text message."})]})]}),y.jsx("button",{onClick:Gl,disabled:p||Kt&&(!qt.startsWith("sk-")||qt.length<20),className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:p?y.jsxs(y.Fragment,{children:[y.jsx(Wi,{className:"h-4 w-4 animate-spin"}),"Setting up..."]}):y.jsxs(y.Fragment,{children:["Complete Setup",y.jsx(vn,{className:"h-4 w-4"})]})}),!Kt&&y.jsx("p",{className:"text-center text-white/20 text-[11px] mt-2.5",children:"You can enable this later in Settings."})]})]},i)}),i>0&&y.jsx("div",{className:"px-8 pb-5 -mt-3",children:y.jsx("button",{onClick:vs,className:"text-white/25 hover:text-white/50 text-[12px] transition-colors",children:"← Back"})})]})]})}function N4(){return y.jsx("div",{className:"flex items-center justify-center h-dvh p-6 text-center",children:y.jsxs("div",{children:[y.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Something went wrong"}),y.jsx("p",{className:"text-sm text-muted-foreground",children:"The dashboard encountered an error. Use the Fluxy button to continue chatting."})]})})}function j4(){const[n,i]=T.useState(!1),[l,r]=T.useState("idle"),[c,f]=T.useState("");T.useEffect(()=>{fetch("/api/settings").then(h=>h.json()).then(h=>{h.onboard_complete!=="true"&&i(!0)}).catch(()=>{})},[]),T.useEffect(()=>{let h;const g=p=>{p.data?.type==="fluxy:rebuilding"?(r("rebuilding"),f(""),clearTimeout(h),h=setTimeout(()=>location.reload(),6e4)):p.data?.type==="fluxy:rebuilt"?(clearTimeout(h),r("idle"),location.reload()):p.data?.type==="fluxy:build-error"&&(clearTimeout(h),r("error"),f(p.data.error||"Build failed"),setTimeout(()=>r("idle"),5e3))};return window.addEventListener("message",g),()=>{window.removeEventListener("message",g),clearTimeout(h)}},[]);const d=()=>{i(!1)};return y.jsxs(y.Fragment,{children:[y.jsx(h2,{fallback:y.jsx(N4,{}),children:y.jsx(wA,{onOpenOnboard:()=>i(!0),children:y.jsx(jA,{})})}),n&&y.jsx(M4,{onComplete:d}),l!=="idle"&&y.jsxs("div",{className:"fixed inset-0 z-[49] flex flex-col items-center justify-center bg-background/90",children:[y.jsx("video",{src:"/fluxy_tilts.webm",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-24 w-24 rounded-full object-cover"}),y.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:l==="rebuilding"?"Rebuilding app...":c})]})]})}d2.createRoot(document.getElementById("root")).render(y.jsx(Kn.StrictMode,{children:y.jsx(j4,{})}));
package/dist/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, interactive-widget=resizes-content" />
6
6
  <meta name="theme-color" content="#212121" />
7
7
  <title>Fluxy</title>
8
- <script type="module" crossorigin src="/assets/index-Dhxcodfu.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-BrX_TIDh.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-CTBZksup.css">
10
10
  </head>
11
11
  <body class="bg-background text-foreground">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluxy-bot",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Self-hosted AI bot — run your own AI assistant from anywhere",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,9 +63,11 @@ function readOAuthToken(): string | null {
63
63
  try {
64
64
  if (fs.existsSync(CREDENTIALS_FILE)) {
65
65
  const creds = JSON.parse(fs.readFileSync(CREDENTIALS_FILE, 'utf-8'));
66
- if (creds.accessToken) {
67
- if (creds.expiresAt && Date.now() >= creds.expiresAt) return null;
68
- return creds.accessToken;
66
+ // Support both flat format ({ accessToken }) and nested ({ claudeAiOauth: { accessToken } })
67
+ const oauth = creds.claudeAiOauth || creds;
68
+ if (oauth.accessToken) {
69
+ if (oauth.expiresAt && Date.now() >= oauth.expiresAt) return null;
70
+ return oauth.accessToken;
69
71
  }
70
72
  }
71
73
  } catch {}
@@ -201,7 +203,7 @@ export async function startFluxyAgentQuery(
201
203
  }
202
204
  } finally {
203
205
  activeQueries.delete(conversationId);
204
- const FILE_TOOLS = ['Write', 'Edit', 'Bash'];
206
+ const FILE_TOOLS = ['Write', 'Edit'];
205
207
  const usedFileTools = FILE_TOOLS.some((t) => usedTools.has(t));
206
208
  onMessage('bot:done', { conversationId, usedFileTools });
207
209
  }
@@ -131,7 +131,7 @@ export async function startSupervisor() {
131
131
  ? createProvider(freshConfig.ai.provider, freshConfig.ai.apiKey, freshConfig.ai.baseUrl)
132
132
  : null;
133
133
 
134
- log.info(`[fluxy] provider=${freshConfig.ai.provider}, model=${freshConfig.ai.model}, hasApiKey=${!!freshConfig.ai.apiKey}`);
134
+ log.info(`[fluxy] provider=${freshConfig.ai.provider}, model=${freshConfig.ai.model}`);
135
135
 
136
136
  // Route Anthropic through Agent SDK (uses OAuth token, not API key)
137
137
  if (freshConfig.ai.provider === 'anthropic') {
@@ -142,7 +142,10 @@ export async function startSupervisor() {
142
142
  // COMMIT HERE
143
143
  ws.send(JSON.stringify({ type: 'app:rebuilding', data: {} }));
144
144
  log.info('File tools used — rebuilding app...');
145
- exec('npm run build', { cwd: PKG_DIR }, (err, stdout, stderr) => {
145
+ const localBin = path.join(PKG_DIR, 'node_modules', '.bin');
146
+ const sep = process.platform === 'win32' ? ';' : ':';
147
+ const execEnv = { ...process.env, PATH: `${localBin}${sep}${process.env.PATH}` };
148
+ exec('npm run build', { cwd: PKG_DIR, env: execEnv }, (err, stdout, stderr) => {
146
149
  if (err) {
147
150
  const errorMsg = stderr || err.message;
148
151
  log.error(`Build failed: ${errorMsg}`);