fluxy-bot 0.1.7 → 0.1.9

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.
package/bin/cli.js CHANGED
@@ -140,24 +140,22 @@ function createConfig() {
140
140
  }
141
141
  }
142
142
 
143
+ const MIN_CF_SIZE = 10 * 1024 * 1024; // 10 MB — valid cloudflared is ~30-50 MB
144
+
143
145
  function hasCloudflared() {
144
146
  // Check system-wide install
145
- try {
146
- execSync('cloudflared --version', { stdio: 'ignore' });
147
- return true;
148
- } catch {}
147
+ const which = process.platform === 'win32' ? 'where cloudflared' : 'which cloudflared';
148
+ try { execSync(which, { stdio: 'ignore' }); return true; } catch {}
149
149
 
150
- // Check local install
150
+ // Check local install (validate by file size, never execute — avoids Windows popup)
151
151
  const cfExe = process.platform === 'win32' ? CF_PATH + '.exe' : CF_PATH;
152
152
  if (!fs.existsSync(cfExe)) return false;
153
- try {
154
- execSync(`"${cfExe}" --version`, { stdio: 'ignore' });
155
- return true;
156
- } catch {
157
- // Binary exists but is corrupt — delete it
153
+ const size = fs.statSync(cfExe).size;
154
+ if (size < MIN_CF_SIZE) {
158
155
  fs.unlinkSync(cfExe);
159
156
  return false;
160
157
  }
158
+ return true;
161
159
  }
162
160
 
163
161
  async function installCloudflared() {
@@ -166,11 +164,14 @@ async function installCloudflared() {
166
164
  fs.mkdirSync(BIN_DIR, { recursive: true });
167
165
 
168
166
  const platform = os.platform();
169
- const arch = os.arch();
167
+ // os.arch() returns Node's arch, not the OS. Use PROCESSOR_ARCHITECTURE on Windows for real OS arch.
168
+ const arch = platform === 'win32'
169
+ ? (process.env.PROCESSOR_ARCHITECTURE || os.arch()).toLowerCase()
170
+ : os.arch();
170
171
  let url;
171
172
 
172
173
  if (platform === 'win32') {
173
- url = arch === 'arm64'
174
+ url = arch.includes('arm')
174
175
  ? 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-arm64.exe'
175
176
  : 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe';
176
177
  } else if (platform === 'darwin') {
@@ -36,9 +36,7 @@ const TOTAL_STEPS = 5; // 0..4
36
36
 
37
37
  const HANDLES = [
38
38
  { tier: 'premium', label: (n: string) => `${n}.fluxy.bot`, badge: '$5', badgeCls: 'bg-primary/15 text-primary border-primary/20', highlight: true },
39
- { tier: 'my', label: (n: string) => `my.fluxy.bot/${n}`, badge: 'Free', badgeCls: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20', highlight: false },
40
- { tier: 'at', label: (n: string) => `at.fluxy.bot/${n}`, badge: 'Free', badgeCls: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20', highlight: false },
41
- { tier: 'on', label: (n: string) => `on.fluxy.bot/${n}`, badge: 'Free', badgeCls: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20', highlight: false },
39
+ { tier: 'at', label: (n: string) => `${n}.at.fluxy.bot`, badge: 'Free', badgeCls: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20', highlight: false },
42
40
  ] as const;
43
41
 
44
42
  /* ── Dropdown ── */
@@ -129,7 +127,7 @@ export default function OnboardWizard({ onComplete }: Props) {
129
127
  const [botName, setBotName] = useState('');
130
128
  const [handleStatus, setHandleStatus] = useState<null | 'checking' | 'available' | 'taken' | 'invalid'>(null);
131
129
  const [handleError, setHandleError] = useState('');
132
- const [selectedTier, setSelectedTier] = useState('my');
130
+ const [selectedTier, setSelectedTier] = useState('at');
133
131
  const [registering, setRegistering] = useState(false);
134
132
  const [registered, setRegistered] = useState(false);
135
133
  const [registeredUrl, setRegisteredUrl] = useState('');
@@ -61,4 +61,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${i.do
61
61
  ${G}px !important;
62
62
  ${L}px !important;
63
63
  }
64
- `),()=>{K.contains(B)&&K.removeChild(B)}},[i]),y.jsx(DN,{isPresent:i,childRef:h,sizeRef:g,pop:f,children:f===!1?n:T.cloneElement(n,{ref:b})})}const ON=({children:n,initial:i,isPresent:l,onExitComplete:r,custom:c,presenceAffectsLayout:f,mode:d,anchorX:h,anchorY:g,root:p})=>{const v=sd(zN),b=T.useId();let S=!0,w=T.useMemo(()=>(S=!1,{id:b,initial:i,isPresent:l,custom:c,onExitComplete:j=>{v.set(j,!0);for(const A of v.values())if(!A)return;r&&r()},register:j=>(v.set(j,!1),()=>v.delete(j))}),[l,v,r]);return f&&S&&(w={...w}),T.useMemo(()=>{v.forEach((j,A)=>v.set(A,!1))},[l]),T.useEffect(()=>{!l&&!v.size&&r&&r()},[l]),n=y.jsx(RN,{pop:d==="popLayout",isPresent:l,anchorX:h,anchorY:g,root:p,children:n}),y.jsx(bo.Provider,{value:w,children:n})};function zN(){return new Map}function jx(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 Xr=n=>n.key||"";function pv(n){const i=[];return T.Children.forEach(n,l=>{T.isValidElement(l)&&i.push(l)}),i}const Dx=({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]=jx(d),S=T.useMemo(()=>pv(n),[n]),w=d&&!v?[]:S.map(Xr),j=T.useRef(!0),A=T.useRef(S),N=sd(()=>new Map),R=T.useRef(new Set),[G,L]=T.useState(S),[B,K]=T.useState(S);ab(()=>{j.current=!1,A.current=S;for(let k=0;k<B.length;k++){const I=Xr(B[k]);w.includes(I)?(N.delete(I),R.current.delete(I)):N.get(I)!==!0&&N.set(I,!1)}},[B,w.length,w.join("-")]);const W=[];if(S!==G){let k=[...S];for(let I=0;I<B.length;I++){const ft=B[I],ut=Xr(ft);w.includes(ut)||(k.splice(I,0,ft),W.push(ft))}return f==="wait"&&W.length&&(k=W),K(pv(k)),L(S),null}const{forceRender:P}=T.useContext(id);return y.jsx(y.Fragment,{children:B.map(k=>{const I=Xr(k),ft=d&&!v?!1:S===B||w.includes(I),ut=()=>{if(R.current.has(I))return;if(R.current.add(I),N.has(I))N.set(I,!0);else return;let wt=!0;N.forEach(Mt=>{Mt||(wt=!1)}),wt&&(P?.(),K(A.current),d&&b?.(),r&&r())};return y.jsx(ON,{isPresent:ft,initial:!j.current||l?void 0:!1,custom:i,presenceAffectsLayout:c,mode:f,root:p,onExitComplete:ft?void 0:ut,anchorX:h,anchorY:g,children:k},I)})})},Rx=T.createContext({strict:!1}),gv={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 yv=!1;function _N(){if(yv)return;const n={};for(const i in gv)n[i]={isEnabled:l=>gv[i].some(r=>!!l[r])};sx(n),yv=!0}function Ox(){return _N(),x3()}function VN(n){const i=Ox();for(const l in n)i[l]={...i[l],...n[l]};sx(i)}const LN=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 fo(n){return n.startsWith("while")||n.startsWith("drag")&&n!=="draggable"||n.startsWith("layout")||n.startsWith("onTap")||n.startsWith("onPan")||n.startsWith("onLayout")||LN.has(n)}let zx=n=>!fo(n);function kN(n){typeof n=="function"&&(zx=i=>i.startsWith("on")?!fo(i):n(i))}try{kN(require("@emotion/is-prop-valid").default)}catch{}function UN(n,i,l){const r={};for(const c in n)c==="values"&&typeof n.values=="object"||(zx(c)||l===!0&&fo(c)||!i&&!fo(c)||n.draggable&&c.startsWith("onDrag"))&&(r[c]=n[c]);return r}const To=T.createContext({});function BN(n,i){if(So(n)){const{initial:l,animate:r}=n;return{initial:l===!1||sl(l)?l:void 0,animate:sl(r)?r:void 0}}return n.inherit!==!1?i:{}}function HN(n){const{initial:i,animate:l}=BN(n,T.useContext(To));return T.useMemo(()=>({initial:i,animate:l}),[vv(i),vv(l)])}function vv(n){return Array.isArray(n)?n.join(" "):n}const zd=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function _x(n,i,l){for(const r in i)!ge(i[r])&&!dx(r,l)&&(n[r]=i[r])}function GN({transformTemplate:n},i){return T.useMemo(()=>{const l=zd();return Dd(l,i,n),Object.assign({},l.vars,l.style)},[i])}function qN(n,i){const l=n.style||{},r={};return _x(r,l,n),Object.assign(r,GN(n,i)),r}function YN(n,i){const l={},r=qN(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 Vx=()=>({...zd(),attrs:{}});function XN(n,i,l,r){const c=T.useMemo(()=>{const f=Vx();return hx(f,i,px(r),n.transformTemplate,n.style),{...f.attrs,style:{...f.style}}},[i]);if(n.style){const f={};_x(f,n.style,n),c.style={...f,...c.style}}return c}const KN=["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 _d(n){return typeof n!="string"||n.includes("-")?!1:!!(KN.indexOf(n)>-1||/[A-Z]/u.test(n))}function PN(n,i,l,{latestValues:r},c,f=!1,d){const g=(d??_d(n)?XN:YN)(i,r,c,n),p=UN(i,typeof n=="string",f),v=n!==T.Fragment?{...p,...g,ref:l}:{},{children:b}=i,S=T.useMemo(()=>ge(b)?b.get():b,[b]);return T.createElement(n,{...v,children:S})}function ZN({scrapeMotionValuesFromProps:n,createRenderState:i},l,r,c){return{latestValues:QN(l,r,c,n),renderState:i()}}function QN(n,i,l,r){const c={},f=r(n,{});for(const S in f)c[S]=$r(f[S]);let{initial:d,animate:h}=n;const g=So(n),p=ax(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"&&!xo(b)){const S=Array.isArray(b)?b:[b];for(let w=0;w<S.length;w++){const j=Td(n,S[w]);if(j){const{transitionEnd:A,transition:N,...R}=j;for(const G in R){let L=R[G];if(Array.isArray(L)){const B=v?L.length-1:0;L=L[B]}L!==null&&(c[G]=L)}for(const G in A)c[G]=A[G]}}}return c}const Lx=n=>(i,l)=>{const r=T.useContext(To),c=T.useContext(bo),f=()=>ZN(n,i,r,c);return l?f():sd(f)},FN=Lx({scrapeMotionValuesFromProps:Rd,createRenderState:zd}),JN=Lx({scrapeMotionValuesFromProps:gx,createRenderState:Vx}),WN=Symbol.for("motionComponentSymbol");function IN(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 kx=T.createContext({});function Ui(n){return n&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"current")}function $N(n,i,l,r,c,f){const{visualElement:d}=T.useContext(To),h=T.useContext(Rx),g=T.useContext(bo),p=T.useContext(Od),v=p.reducedMotion,b=p.skipAnimations,S=T.useRef(null),w=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}),w.current&&S.current&&(S.current.manuallyAnimateOnMount=!0));const j=S.current,A=T.useContext(kx);j&&!j.projection&&c&&(j.type==="html"||j.type==="svg")&&t4(S.current,l,c,A);const N=T.useRef(!1);T.useInsertionEffect(()=>{j&&N.current&&j.update(l,g)});const R=l[Xb],G=T.useRef(!!R&&!window.MotionHandoffIsComplete?.(R)&&window.MotionHasOptimisedAnimation?.(R));return ab(()=>{w.current=!0,j&&(N.current=!0,window.MotionIsMounted=!0,j.updateFeatures(),j.scheduleRenderMicrotask(),G.current&&j.animationState&&j.animationState.animateChanges())}),T.useEffect(()=>{j&&(!G.current&&j.animationState&&j.animationState.animateChanges(),G.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(R)}),G.current=!1),j.enteringChildren=void 0)}),j}function t4(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:Ux(n.parent)),n.projection.setOptions({layoutId:c,layout:f,alwaysMeasureLayout:!!d||h&&Ui(h),visualElement:n,animationType:typeof f=="string"?f:"both",initialPromotionConfig:r,crossfade:v,layoutScroll:g,layoutRoot:p})}function Ux(n){if(n)return n.options.allowProjection!==!1?n.projection:Ux(n.parent)}function mf(n,{forwardMotionProps:i=!1,type:l}={},r,c){r&&VN(r);const f=l?l==="svg":_d(n),d=f?JN:FN;function h(p,v){let b;const S={...T.useContext(Od),...p,layoutId:e4(p)},{isStatic:w}=S,j=HN(p),A=d(p,w);if(!w&&nb){n4();const N=a4(S);b=N.MeasureLayout,j.visualElement=$N(n,A,S,c,N.ProjectionNode,f)}return y.jsxs(To.Provider,{value:j,children:[b&&j.visualElement?y.jsx(b,{visualElement:j.visualElement,...S}):null,PN(n,p,IN(A,j.visualElement,v),A,w,i,f)]})}h.displayName=`motion.${typeof n=="string"?n:`create(${n.displayName??n.name??""})`}`;const g=T.forwardRef(h);return g[WN]=n,g}function e4({layoutId:n}){const i=T.useContext(id).id;return i&&n!==void 0?i+"-"+n:n}function n4(n,i){T.useContext(Rx).strict}function a4(n){const i=Ox(),{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 i4(n,i){if(typeof Proxy>"u")return mf;const l=new Map,r=(f,d)=>mf(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,mf(d,void 0,n,i)),l.get(d))})}const s4=(n,i)=>i.isSVG??_d(n)?new k3(i):new R3(i,{allowProjection:n!==T.Fragment});class l4 extends Ta{constructor(i){super(i),i.animationState||(i.animationState=q3(i))}updateAnimationControlsSubscription(){const{animate:i}=this.node.getProps();xo(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 r4=0;class o4 extends Ta{constructor(){super(...arguments),this.id=r4++}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 u4={animation:{Feature:l4},exit:{Feature:o4}};function pl(n){return{point:{x:n.pageX,y:n.pageY}}}const c4=n=>i=>Cd(i)&&n(i,pl(i));function el(n,i,l,r){return ll(n,i,c4(l),r)}const Bx=({current:n})=>n?n.ownerDocument.defaultView:null,bv=(n,i)=>Math.abs(n-i);function f4(n,i){const l=bv(n.x,i.x),r=bv(n.y,i.y);return Math.sqrt(l**2+r**2)}const xv=new Set(["auto","scroll"]);class Hx{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=w=>{this.handleScroll(w.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const w=gf(this.lastMoveEventInfo,this.history),j=this.startEvent!==null,A=f4(w.offset,{x:0,y:0})>=this.distanceThreshold;if(!j&&!A)return;const{point:N}=w,{timestamp:R}=de;this.history.push({...N,timestamp:R});const{onStart:G,onMove:L}=this.handlers;j||(G&&G(this.lastMoveEvent,w),this.startEvent=this.lastMoveEvent),L&&L(this.lastMoveEvent,w)},this.handlePointerMove=(w,j)=>{this.lastMoveEvent=w,this.lastMoveEventInfo=pf(j,this.transformPagePoint),Ut.update(this.updatePoint,!0)},this.handlePointerUp=(w,j)=>{this.end();const{onEnd:A,onSessionEnd:N,resumeAnimation:R}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&R&&R(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const G=gf(w.type==="pointercancel"?this.lastMoveEventInfo:pf(j,this.transformPagePoint),this.history);this.startEvent&&A&&A(w,G),N&&N(w,G)},!Cd(i))return;this.dragSnapToOrigin=f,this.handlers=l,this.transformPagePoint=r,this.distanceThreshold=d,this.contextWindow=c||window;const g=pl(i),p=pf(g,this.transformPagePoint),{point:v}=p,{timestamp:b}=de;this.history=[{...v,timestamp:b}];const{onSessionStart:S}=l;S&&S(i,gf(p,this.history)),this.removeListeners=dl(el(this.contextWindow,"pointermove",this.handlePointerMove),el(this.contextWindow,"pointerup",this.handlePointerUp),el(this.contextWindow,"pointercancel",this.handlePointerUp)),h&&this.startScrollTracking(h)}startScrollTracking(i){let l=i.parentElement;for(;l;){const r=getComputedStyle(l);(xv.has(r.overflowX)||xv.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(),xa(this.updatePoint)}}function pf(n,i){return i?{point:i(n.point)}:n}function Sv(n,i){return{x:n.x-i.x,y:n.y-i.y}}function gf({point:n},i){return{point:n,delta:Sv(n,Gx(i)),offset:Sv(n,d4(i)),velocity:h4(i,.1)}}function d4(n){return n[0]}function Gx(n){return n[n.length-1]}function h4(n,i){if(n.length<2)return{x:0,y:0};let l=n.length-1,r=null;const c=Gx(n);for(;l>=0&&(r=n[l],!(c.timestamp-r.timestamp>an(i)));)l--;if(!r)return{x:0,y:0};r===n[0]&&n.length>2&&c.timestamp-r.timestamp>an(i)*2&&(r=n[1]);const f=Qe(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 m4(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 Tv(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 p4(n,{top:i,left:l,bottom:r,right:c}){return{x:Tv(n.x,l,c),y:Tv(n.y,i,r)}}function Ev(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 g4(n,i){return{x:Ev(n.x,i.x),y:Ev(n.y,i.y)}}function y4(n,i){let l=.5;const r=xe(n),c=xe(i);return c>r?l=nl(i.min,i.max-r,n.min):r>c&&(l=nl(n.min,n.max-c,i.min)),vn(0,1,l)}function v4(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 Zf=.35;function b4(n=Zf){return n===!1?n=0:n===!0&&(n=Zf),{x:wv(n,"left","right"),y:wv(n,"top","bottom")}}function wv(n,i,l){return{min:Av(n,i),max:Av(n,l)}}function Av(n,i){return typeof n=="number"?n:n[i]||0}const x4=new WeakMap;class S4{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=ae(),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(pl(b).point),this.stopAnimation()},d=(b,S)=>{const{drag:w,dragPropagation:j,onDragStart:A}=this.getProps();if(w&&!j&&(this.openDragLock&&this.openDragLock(),this.openDragLock=JM(w),!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),mn(R=>{let G=this.getAxisMotionValue(R).get()||0;if(gn.test(G)){const{projection:L}=this.visualElement;if(L&&L.layout){const B=L.layout.layoutBox[R];B&&(G=xe(B)*(parseFloat(G)/100))}}this.originPoint[R]=G}),A&&Ut.update(()=>A(b,S),!1,!0),Uf(this.visualElement,"transform");const{animationState:N}=this.visualElement;N&&N.setActive("whileDrag",!0)},h=(b,S)=>{this.latestPointerEvent=b,this.latestPanInfo=S;const{dragPropagation:w,dragDirectionLock:j,onDirectionLock:A,onDrag:N}=this.getProps();if(!w&&!this.openDragLock)return;const{offset:R}=S;if(j&&this.currentDirection===null){this.currentDirection=E4(R),this.currentDirection!==null&&A&&A(this.currentDirection);return}this.updateAxis("x",S.point,R),this.updateAxis("y",S.point,R),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 Hx(i,{onSessionStart:f,onStart:d,onMove:h,onSessionEnd:g,resumeAnimation:p},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:v,distanceThreshold:r,contextWindow:Bx(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||!Kr(i,c,this.currentDirection))return;const f=this.getAxisMotionValue(i);let d=this.originPoint[i]+r[i];this.constraints&&this.constraints[i]&&(d=m4(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&&Ui(i)?this.constraints||(this.constraints=this.resolveRefConstraints()):i&&r?this.constraints=p4(r.layoutBox,i):this.constraints=!1,this.elastic=b4(l),c!==this.constraints&&!Ui(i)&&r&&this.constraints&&!this.hasMutatedConstraints&&mn(f=>{this.constraints!==!1&&this.getAxisMotionValue(f)&&(this.constraints[f]=v4(r.layoutBox[f],this.constraints[f]))})}resolveRefConstraints(){const{dragConstraints:i,onMeasureDragConstraints:l}=this.getProps();if(!i||!Ui(i))return!1;const r=i.current,{projection:c}=this.visualElement;if(!c||!c.layout)return!1;const f=A3(r,c.root,this.visualElement.getTransformPagePoint());let d=g4(c.layout.layoutBox,f);if(l){const h=l(T3(d));this.hasMutatedConstraints=!!h,h&&(d=rx(h))}return d}startAnimation(i){const{drag:l,dragMomentum:r,dragElastic:c,dragTransition:f,dragSnapToOrigin:d,onDragTransitionEnd:h}=this.getProps(),g=this.constraints||{},p=mn(v=>{if(!Kr(v,l,this.currentDirection))return;let b=g&&g[v]||{};d&&(b={min:0,max:0});const S=c?200:1e6,w=c?40:1e7,j={type:"inertia",velocity:r?i[v]:0,bounceStiffness:S,bounceDamping:w,timeConstant:750,restDelta:1,restSpeed:10,...f,...b};return this.startAxisValueAnimation(v,j)});return Promise.all(p).then(h)}startAxisValueAnimation(i,l){const r=this.getAxisMotionValue(i);return Uf(this.visualElement,i),r.start(Sd(i,r,0,l,this.visualElement,!1))}stopAnimation(){mn(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){mn(l=>{const{drag:r}=this.getProps();if(!Kr(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(!Ui(l)||!r||!this.constraints)return;this.stopAnimation();const c={x:0,y:0};mn(d=>{const h=this.getAxisMotionValue(d);if(h&&this.constraints!==!1){const g=h.get();c[d]=y4({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(),mn(d=>{if(!Kr(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;x4.set(this.visualElement,this);const i=this.visualElement.current,l=el(i,"pointerdown",p=>{const{drag:v,dragListener:b=!0}=this.getProps(),S=p.target,w=S!==i&&n3(S);v&&b&&!w&&this.start(p)});let r;const c=()=>{const{dragConstraints:p}=this.getProps();Ui(p)&&p.current&&(this.constraints=this.resolveRefConstraints(),r||(r=T4(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=ll(window,"resize",()=>this.scalePositionWithinConstraints()),g=f.addEventListener("didUpdate",(({delta:p,hasLayoutChanged:v})=>{this.isDragging&&v&&(mn(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=Zf,dragMomentum:h=!0}=i;return{...i,drag:l,dragDirectionLock:r,dragPropagation:c,dragConstraints:f,dragElastic:d,dragMomentum:h}}}function Cv(n){let i=!0;return()=>{if(i){i=!1;return}n()}}function T4(n,i,l){const r=zy(n,Cv(l)),c=zy(i,Cv(l));return()=>{r(),c()}}function Kr(n,i,l){return(i===!0||i===n)&&(l===null||l===n)}function E4(n,i=10){let l=null;return Math.abs(n.y)>i?l="y":Math.abs(n.x)>i&&(l="x"),l}class w4 extends Ta{constructor(i){super(i),this.removeGroupControls=Fe,this.removeListeners=Fe,this.controls=new S4(i)}mount(){const{dragControls:i}=this.node.getProps();i&&(this.removeGroupControls=i.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Fe}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 yf=n=>(i,l)=>{n&&Ut.update(()=>n(i,l),!1,!0)};class A4 extends Ta{constructor(){super(...arguments),this.removePointerDownListener=Fe}onPointerDown(i){this.session=new Hx(i,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:Bx(this.node)})}createPanHandlers(){const{onPanSessionStart:i,onPanStart:l,onPan:r,onPanEnd:c}=this.node.getProps();return{onSessionStart:yf(i),onStart:yf(l),onMove:yf(r),onEnd:(f,d)=>{delete this.session,c&&Ut.postRender(()=>c(f,d))}}}mount(){this.removePointerDownListener=el(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 vf=!1;class C4 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),vf&&f.root.didUpdate(),f.addEventListener("animationComplete",()=>{this.safeToRemove()}),f.setOptions({...f.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),to.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}),vf=!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(),Ad.postRender(()=>{!i.currentAnimation&&i.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:i,layoutGroup:l,switchLayoutGroup:r}=this.props,{projection:c}=i;vf=!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 qx(n){const[i,l]=jx(),r=T.useContext(id);return y.jsx(C4,{...n,layoutGroup:r,switchLayoutGroup:T.useContext(kx),isPresent:i,safeToRemove:l})}const M4={pan:{Feature:A4},drag:{Feature:w4,ProjectionNode:Nx,MeasureLayout:qx}};function Mv(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,pl(i)))}class N4 extends Ta{mount(){const{current:i}=this.node;i&&(this.unmount=IM(i,(l,r)=>(Mv(this.node,r,"Start"),c=>Mv(this.node,c,"End"))))}unmount(){}}class j4 extends Ta{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=dl(ll(this.node.current,"focus",()=>this.onFocus()),ll(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function Nv(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,pl(i)))}class D4 extends Ta{mount(){const{current:i}=this.node;if(!i)return;const{globalTapTarget:l,propagate:r}=this.node.props;this.unmount=i3(i,(c,f)=>(Nv(this.node,f,"Start"),(d,{success:h})=>Nv(this.node,d,h?"End":"Cancel")),{useGlobalTarget:l,stopPropagation:r?.tap===!1})}unmount(){}}const Qf=new WeakMap,bf=new WeakMap,R4=n=>{const i=Qf.get(n.target);i&&i(n)},O4=n=>{n.forEach(R4)};function z4({root:n,...i}){const l=n||document;bf.has(l)||bf.set(l,{});const r=bf.get(l),c=JSON.stringify(i);return r[c]||(r[c]=new IntersectionObserver(O4,{root:n,...i})),r[c]}function _4(n,i,l){const r=z4(i);return Qf.set(n,l),r.observe(n),()=>{Qf.delete(n),r.unobserve(n)}}const V4={some:0,all:1};class L4 extends Ta{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 _4(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(k4(i,l))&&this.startObserver()}unmount(){}}function k4({viewport:n={}},{viewport:i={}}={}){return l=>n[l]!==i[l]}const U4={inView:{Feature:L4},tap:{Feature:D4},focus:{Feature:j4},hover:{Feature:N4}},B4={layout:{ProjectionNode:Nx,MeasureLayout:qx}},H4={...u4,...U4,...M4,...B4},rl=i4(H4,s4);function G4(n){const i=Math.floor(n/60),l=n%60;return`${i}:${l.toString().padStart(2,"0")}`}function q4({onSend:n,onStop:i,streaming:l}){const[r,c]=T.useState(""),[f,d]=T.useState(!1),[h,g]=T.useState(0),p=r.trim().length>0,v=T.useRef(null),b=T.useRef(null),S=T.useRef(null),w=T.useRef(null),j=T.useRef(null),A=T.useRef(0),N=T.useRef(0),R=T.useRef(null),G=T.useRef(!1),L=T.useRef(null);T.useEffect(()=>{if(f)return L.current=setInterval(()=>g(ut=>ut+1),1e3),()=>{L.current&&clearInterval(L.current)}},[f]);const B=T.useCallback(ut=>{L.current&&clearInterval(L.current),R.current&&(clearTimeout(R.current),R.current=null),G.current=!1,j.current&&(j.current.style.transform=""),d(!1),g(0),N.current=0},[]),K=()=>{p&&(n(r),c(""),requestAnimationFrame(()=>v.current?.focus()))},W=ut=>{ut.key==="Enter"&&!ut.shiftKey&&(ut.preventDefault(),K())},P=T.useCallback(ut=>{ut.preventDefault(),A.current=ut.clientX,N.current=0,ut.currentTarget.setPointerCapture(ut.pointerId),R.current=setTimeout(()=>{G.current=!0,d(!0),g(0)},200)},[]),k=T.useCallback(ut=>{if(!G.current)return;const wt=Math.min(0,ut.clientX-A.current);if(N.current=wt,j.current&&(j.current.style.transform=`translateX(${wt}px)`),w.current){const Mt=w.current.getBoundingClientRect(),Zt=Mt.left+Mt.width/2;Math.abs(ut.clientX-Zt)<36&&B(!0)}},[B]),I=T.useCallback(()=>{R.current&&(clearTimeout(R.current),R.current=null),G.current&&B(!1)},[B]),ft=T.useCallback(()=>{R.current&&(clearTimeout(R.current),R.current=null),G.current&&B(!0)},[B]);return y.jsxs("div",{className:"shrink-0 p-3 relative",children:[y.jsxs("div",{className:`flex items-center gap-2 transition-opacity duration-100 ${f?"opacity-0 pointer-events-none":"opacity-100"}`,children:[y.jsxs("div",{className:"flex-1 flex items-center bg-white rounded-full px-4",children:[y.jsx("textarea",{ref:v,value:r,onChange:ut=>c(ut.target.value),onKeyDown:W,placeholder:"Type a message...",rows:1,className:"flex-1 resize-none bg-transparent text-gray-900 py-3 text-sm outline-none placeholder:text-gray-400"}),y.jsx("input",{ref:b,type:"file",className:"hidden",accept:"*/*"}),y.jsx("input",{ref:S,type:"file",className:"hidden",accept:"image/*",capture:"environment"}),y.jsx("button",{type:"button",onClick:()=>b.current?.click(),className:"shrink-0 p-1.5 text-gray-400 hover:text-gray-600 transition-colors",children:y.jsx(tT,{className:"h-4 w-4"})}),y.jsx("button",{type:"button",onClick:()=>S.current?.click(),className:"shrink-0 p-1.5 text-gray-400 hover:text-gray-600 transition-colors",children:y.jsx(V2,{className:"h-4 w-4"})})]}),l?y.jsx("button",{onClick:i,className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-destructive text-destructive-foreground transition-colors",children:y.jsx(fT,{className:"h-4 w-4"})}):p?y.jsx("button",{onClick:K,className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-white text-gray-900 transition-colors hover:bg-gray-100",children:y.jsx(lT,{className:"h-4 w-4"})}):y.jsx("div",{className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-white text-gray-900 transition-colors hover:bg-gray-100 cursor-pointer touch-none select-none",onPointerDown:P,onPointerMove:k,onPointerUp:I,onPointerCancel:ft,children:y.jsx(xf,{className:"h-4 w-4"})})]}),y.jsx(Dx,{children:f&&y.jsx(rl.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"absolute inset-0 p-3 flex items-center touch-none",children:y.jsxs("div",{className:"flex items-center w-full gap-2",children:[y.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[y.jsxs("span",{className:"relative flex h-2 w-2 shrink-0",children:[y.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-destructive opacity-75"}),y.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-destructive"})]}),y.jsx("span",{className:"text-sm font-medium tabular-nums",children:G4(h)})]}),y.jsxs("div",{className:"flex-1 flex items-center bg-muted rounded-full h-12 pl-1 pr-0.5",children:[y.jsx("div",{ref:w,className:"flex items-center justify-center h-9 w-9 shrink-0 rounded-full bg-destructive/10 text-destructive",children:y.jsx(hT,{className:"h-4 w-4"})}),y.jsx("div",{className:"flex-1 flex justify-center min-w-0",children:y.jsx(rl.span,{className:"text-[13px] whitespace-nowrap select-none font-medium",style:{backgroundImage:"linear-gradient(90deg, #999 0%, #999 35%, #fff 50%, #999 65%, #999 100%)",backgroundSize:"200% 100%",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",backgroundClip:"text"},animate:{backgroundPosition:["200% center","-200% center"]},transition:{duration:2.5,repeat:1/0,ease:"linear"},children:"◄◄ slide to cancel"})}),y.jsx("div",{ref:j,className:"shrink-0 touch-none select-none will-change-transform",style:{transition:"none"},onPointerDown:P,onPointerMove:k,onPointerUp:I,onPointerCancel:ft,children:y.jsx("div",{className:"flex items-center justify-center h-11 w-11 rounded-full bg-destructive text-destructive-foreground",children:y.jsx(xf,{className:"h-5 w-5"})})})]})]})})})]})}function Y4({ws:n}){const{messages:i,streaming:l,streamBuffer:r,sendMessage:c,stopStreaming:f}=XA(n);return y.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[y.jsx(ZA,{messages:i,streaming:l,streamBuffer:r}),y.jsx(q4,{onSend:c,onStop:f,streaming:l})]})}function X4({onClick:n}){return y.jsx(rl.div,{className:"fixed bottom-6 right-6 z-50 cursor-pointer",whileHover:{scale:1.1},whileTap:{scale:.95},onClick:n,role:"button","aria-label":"Open Fluxy chat",children:y.jsx("img",{src:"/fluxy.png",alt:"Fluxy",className:"h-11 w-auto drop-shadow-lg",draggable:!1})})}const K4=[{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}],P4={anthropic:[{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4"},{id:"claude-opus-4-20250514",label:"Claude Opus 4"},{id:"claude-haiku-4-5-20251001",label:"Claude 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"}]},jv=5,Z4=[{tier:"premium",label:n=>`${n}.fluxy.bot`,badge:"$5",badgeCls:"bg-primary/15 text-primary border-primary/20",highlight:!0},{tier:"my",label:n=>`my.fluxy.bot/${n}`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1},{tier:"at",label:n=>`at.fluxy.bot/${n}`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1},{tier:"on",label:n=>`on.fluxy.bot/${n}`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1}];function Q4({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-primary/30 transition-colors",children:[y.jsx("span",{className:d?"text-white":"text-white/20",children:d?d.label:"Choose a model..."}),y.jsx(ol,{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-primary bg-primary/10":"text-white/70 hover:bg-white/[0.04] hover:text-white"}`,children:h.label},h.id))})]})}function F4({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"}),[w,j]=T.useState(!1),[A,N]=T.useState(""),[R,G]=T.useState(!1),[L,B]=T.useState(),[K,W]=T.useState(!1),[P,k]=T.useState(!1),[I,ft]=T.useState(),[ut,wt]=T.useState(""),[Mt,Zt]=T.useState(""),[At,_]=T.useState(null),[Z,$]=T.useState(""),[ht,Q]=T.useState("my"),[C,Y]=T.useState(!1),[F,tt]=T.useState(!1),[lt,rt]=T.useState(""),gt=T.useRef(null),[Bt,mt]=T.useState(!1),me=b[f]==="connected";T.useEffect(()=>{f!=="anthropic"||b.anthropic==="connected"||fetch("/api/auth/claude/status").then(J=>J.json()).then(J=>{J.authenticated&&S(bt=>({...bt,anthropic:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{f!=="openai"||b.openai==="connected"||fetch("/api/auth/codex/status").then(J=>J.json()).then(J=>{J.authenticated&&S(bt=>({...bt,openai:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{if(!P)return;const J=setInterval(async()=>{try{(await(await fetch("/api/auth/codex/status")).json()).authenticated&&(k(!1),S(vl=>({...vl,openai:"connected"})))}catch{}},2e3);return()=>clearInterval(J)},[P]),T.useEffect(()=>{gt.current&&clearTimeout(gt.current),_(null),$(""),tt(!1),rt("");const J=Mt.trim();if(J){if(J.length<3){_("invalid"),$("At least 3 characters");return}return _("checking"),gt.current=setTimeout(async()=>{try{const un=await(await fetch(`/api/handle/check/${encodeURIComponent(J)}`)).json();un.valid?un.available?_("available"):_("taken"):(_("invalid"),$(un.error))}catch{_(null)}},400),()=>{gt.current&&clearTimeout(gt.current)}}},[Mt]);const We=J=>{Zt(J.toLowerCase().replace(/[^a-z0-9-]/g,""))},rn=async()=>{if(!(!Mt||At!=="available")){Y(!0);try{const bt=await(await fetch("/api/handle/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:Mt,tier:ht})})).json();bt.ok?(tt(!0),rt(bt.url)):($(bt.error||"Registration failed"),_("invalid"))}catch{$("Could not reach server"),_("invalid")}finally{Y(!1)}}},Gn=J=>{f==="openai"&&J!=="openai"&&P&&(fetch("/api/auth/codex/cancel",{method:"POST"}),k(!1)),d(J),g(""),j(!1),N(""),B(void 0),k(!1),ft(void 0)},Se=async()=>{B(void 0);try{const bt=await(await fetch("/api/auth/claude/start",{method:"POST"})).json();bt.success&&bt.authUrl?(window.open(bt.authUrl,"_blank"),j(!0)):B(bt.error||"Failed to start authentication")}catch(J){B(J.message)}},Ja=async()=>{if(A.trim()){G(!0),B(void 0);try{const bt=await(await fetch("/api/auth/claude/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:A.trim()})})).json();bt.success?S(un=>({...un,anthropic:"connected"})):B(bt.error||"Code exchange failed")}catch(J){B(J.message)}finally{G(!1)}}},Ji=async()=>{try{const J=await navigator.clipboard.readText();J&&N(J.trim())}catch{}},Eo=async()=>{W(!0),B(void 0);try{(await(await fetch("/api/auth/claude/status")).json()).authenticated?S(un=>({...un,anthropic:"connected"})):B("No active session found. Please authenticate first.")}catch{}finally{W(!1)}},gl=async()=>{k(!0),ft(void 0);try{const bt=await(await fetch("/api/auth/codex/start",{method:"POST"})).json();bt.success&&bt.authUrl?window.open(bt.authUrl,"_blank"):(k(!1),ft(bt.error||"Failed to start authentication"))}catch(J){k(!1),ft(J.message)}},Wi=()=>{k(!1),fetch("/api/auth/codex/cancel",{method:"POST"})},qn=(()=>{switch(i){case 0:return!0;case 1:return r.trim().length>0;case 2:return Mt.trim().length>=3;case 3:return!!(f&&h&&me);case 4:return!0;default:return!1}})(),on=()=>{qn&&i<jv-1&&l(J=>J+1)},wo=()=>{i>0&&l(J=>J-1)},Ao=J=>{J.key==="Enter"&&qn&&on()},ye=async()=>{v(!0);try{await fetch("/api/onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userName:r.trim(),agentName:Mt.trim()||"Fluxy",provider:f,model:h,apiKey:"",baseUrl:f==="ollama"&&ut||void 0,whisperEnabled:Bt})}),n()}catch(J){console.error("Onboard failed:",J),v(!1)}},yl="w-full bg-white/[0.05] border border-white/[0.08] text-white rounded-xl px-4 py-3 text-base outline-none focus:border-primary/40 placeholder:text-white/20 transition-colors",Ii="w-full bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none focus:border-primary/30 placeholder:text-white/20 transition-colors";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(rl.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:jv},(J,bt)=>y.jsx("div",{className:`h-1.5 rounded-full transition-all duration-300 ${bt===i?"w-7 bg-primary":bt<i?"w-1.5 bg-primary/60":"w-1.5 bg-white/10"}`},bt))}),y.jsx(Dx,{mode:"wait",children:y.jsxs(rl.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("img",{src:"/fluxy.png",alt:"Fluxy",className:"h-16 w-auto 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:on,className:"mt-6 px-7 py-3 bg-primary hover:bg-primary/90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center gap-2",children:["Get Started",y.jsx(kn,{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:J=>c(J.target.value),onKeyDown:Ao,placeholder:"Enter your name",autoFocus:!0,className:yl+" flex-1"}),y.jsx("button",{onClick:on,disabled:!qn,className:"shrink-0 h-12 w-12 flex items-center justify-center rounded-full bg-primary hover:bg-primary/90 text-white transition-colors disabled:opacity-30",children:y.jsx(kn,{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."}),y.jsxs("div",{className:"relative mt-5",children:[y.jsx("input",{type:"text",value:Mt,onChange:J=>We(J.target.value),maxLength:30,placeholder:"your-bot-name",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",autoFocus:!0,disabled:F,className:yl+" pr-10 font-mono"+(F?" opacity-50":"")}),At&&Mt.length>0&&!F&&y.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:[At==="checking"&&y.jsx("div",{className:"w-5 h-5 border-2 border-white/10 border-t-primary rounded-full animate-spin"}),At==="available"&&y.jsx("div",{className:"w-6 h-6 rounded-full bg-emerald-500/15 flex items-center justify-center",children:y.jsx(Xc,{className:"h-3.5 w-3.5 text-emerald-400"})}),At==="taken"&&y.jsx("div",{className:"w-6 h-6 rounded-full bg-red-500/15 flex items-center justify-center",children:y.jsx("svg",{className:"w-3.5 h-3.5 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:y.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}),At==="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"})})})]})]}),At==="invalid"&&Z&&y.jsx("p",{className:"text-amber-400 text-[12px] mt-2",children:Z}),At==="taken"&&y.jsx("p",{className:"text-red-400 text-[12px] mt-2",children:"This name is already taken"}),At==="available"&&Mt.length>0&&!F&&y.jsx("div",{className:"space-y-2 mt-4",children:Z4.map(J=>y.jsxs("button",{onClick:()=>Q(J.tier),className:`w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all duration-200 text-left ${ht===J.tier?J.highlight?"border-primary/40 bg-primary/[0.06]":"border-primary/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:J.label(Mt)}),y.jsx("span",{className:`text-[11px] font-medium px-2.5 py-0.5 rounded-full border ${J.badgeCls}`,children:J.badge})]},J.tier))}),F&&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(Xc,{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:lt})]}),At==="available"&&Mt.length>0&&!F&&y.jsx("button",{onClick:rn,disabled:C,className:"w-full mt-4 py-3 bg-primary hover:bg-primary/90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:C?y.jsxs(y.Fragment,{children:[y.jsx(Zs,{className:"h-4 w-4 animate-spin"}),"Claiming..."]}):y.jsxs(y.Fragment,{children:["Claim & Continue",y.jsx(kn,{className:"h-4 w-4"})]})}),F&&y.jsxs("button",{onClick:on,className:"w-full mt-4 py-3 bg-primary hover:bg-primary/90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",y.jsx(kn,{className:"h-4 w-4"})]}),!F&&(At!=="available"||Mt.length===0)&&Mt.length>=3&&y.jsxs("button",{onClick:on,className:"w-full mt-4 py-2.5 text-white/30 hover:text-white/50 text-[13px] transition-colors flex items-center justify-center gap-2",children:["Skip handle for now",y.jsx(kn,{className:"h-3.5 w-3.5"})]})]}),i===3&&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:K4.map(J=>y.jsxs("button",{onClick:()=>Gn(J.id),className:`flex-1 relative rounded-xl border transition-all duration-200 p-3 text-left ${f===J.id?"bg-white/[0.04] border-primary/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:[J.icon?y.jsx("img",{src:J.icon,alt:J.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:J.name}),y.jsx("div",{className:"text-[10px] text-white/30",children:J.subtitle})]})]}),b[J.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(Xc,{className:"h-2.5 w-2.5 text-emerald-400"})}):f===J.id?y.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-primary"}):null]},J.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:[me&&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."})}),!me&&y.jsxs(y.Fragment,{children:[L&&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:L})}),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((J,bt)=>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:bt+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:J})]},bt))}),y.jsx("button",{onClick:Se,className:"w-full py-2.5 px-4 bg-primary hover:bg-primary/90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2",children:w?y.jsxs(y.Fragment,{children:[y.jsx(Y2,{className:"h-3.5 w-3.5 opacity-60"}),"Open authentication page again"]}):y.jsxs(y.Fragment,{children:["Authenticate with Anthropic",y.jsx(kn,{className:"h-3.5 w-3.5 opacity-60"})]})}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:A,onChange:J=>N(J.target.value),onKeyDown:J=>J.key==="Enter"&&Ja(),placeholder:"Paste your code here...",className:Ii+" pr-10 font-mono"}),y.jsx("button",{onClick:Ji,className:"absolute right-3 top-1/2 -translate-y-1/2 text-white/20 hover:text-white/50 transition-colors",children:y.jsx(B2,{className:"h-3.5 w-3.5"})})]}),y.jsx("button",{onClick:Ja,disabled:!A.trim()||R,className:"w-full py-2.5 px-4 bg-primary hover:bg-primary/90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:R?y.jsxs(y.Fragment,{children:[y.jsx(Zs,{className:"h-3.5 w-3.5 animate-spin"}),"Verifying..."]}):"Connect"}),y.jsxs("button",{onClick:Eo,disabled:K,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:[K?y.jsx(Zs,{className:"h-3 w-3 animate-spin"}):y.jsx(nT,{className:"h-3 w-3"}),K?"Checking...":"I'm already authenticated"]})]})]}),f==="openai"&&y.jsxs("div",{className:"space-y-2.5",children:[me&&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."})}),!me&&y.jsxs(y.Fragment,{children:[I&&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:I})}),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((J,bt)=>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:bt+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:J})]},bt))}),y.jsx("button",{onClick:gl,disabled:P,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:P?y.jsxs(y.Fragment,{children:[y.jsx(Zs,{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(kn,{className:"h-3.5 w-3.5 opacity-60"})]})}),P&&y.jsx("button",{onClick:Wi,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:ut,onChange:J=>wt(J.target.value),placeholder:"http://localhost:11434",className:Ii})]})]}),me&&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(Q4,{models:P4[f]||[],value:h,onChange:g})]}),me&&y.jsxs("button",{onClick:on,disabled:!qn,className:"w-full mt-4 py-3 bg-primary hover:bg-primary/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(kn,{className:"h-4 w-4"})]})]}),i===4&&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:()=>mt(J=>!J),className:`w-full mt-5 rounded-xl border transition-all duration-200 p-4 text-left ${Bt?"bg-white/[0.04] border-primary/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 ${Bt?"bg-primary":"bg-white/[0.08]"}`,children:y.jsx("div",{className:`w-[18px] h-[18px] rounded-full bg-white shadow-sm transition-transform duration-200 ${Bt?"translate-x-[18px]":"translate-x-0"}`})})]})}),Bt&&y.jsx("div",{className:"mt-3 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-3",children:y.jsxs("div",{className:"flex items-start gap-2.5",children:[y.jsx(xf,{className:"h-4 w-4 text-primary/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:ye,disabled:p,className:"w-full mt-5 py-3 bg-primary hover:bg-primary/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(Zs,{className:"h-4 w-4 animate-spin"}),"Setting up..."]}):y.jsxs(y.Fragment,{children:["Complete Setup",y.jsx(kn,{className:"h-4 w-4"})]})}),!Bt&&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:wo,className:"text-white/25 hover:text-white/50 text-[12px] transition-colors",children:"← Back"})})]})]})}function J4(){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 W4(){const[n,i]=T.useState(!1),[l,r]=T.useState(!1),{ws:c,connected:f}=b2();return T.useEffect(()=>{fetch("/api/settings").then(d=>d.json()).then(d=>{d.onboard_complete!=="true"&&r(!0)}).catch(()=>r(!0))},[]),y.jsxs(y.Fragment,{children:[y.jsx(x2,{fallback:y.jsx(J4,{}),children:y.jsx(UA,{onOpenOnboard:()=>r(!0),children:y.jsx(YA,{})})}),y.jsx($0,{open:n,onOpenChange:i,children:y.jsxs(tb,{side:"right",className:"w-full sm:max-w-md !gap-0 !p-0 !border-l-0",onOpenAutoFocus:d=>d.preventDefault(),children:[y.jsxs("div",{className:"flex items-center gap-3 px-4 pr-12 py-3 border-b border-border shrink-0",children:[y.jsx("img",{src:"/fluxy.png",alt:"Fluxy",className:"h-5 w-auto"}),y.jsx(eb,{className:"text-sm font-semibold",children:"Fluxy"}),y.jsx("div",{className:`h-2 w-2 rounded-full ${f?"bg-green-500":"bg-red-500"}`}),y.jsx(VA,{className:"sr-only",children:"Chat with your Fluxy AI assistant"})]}),y.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:y.jsx(Y4,{ws:c})})]})}),y.jsx(X4,{onClick:()=>i(d=>!d)}),l&&y.jsx(F4,{onComplete:()=>r(!1)})]})}y2.createRoot(document.getElementById("root")).render(y.jsx(Bn.StrictMode,{children:y.jsx(W4,{})}));
64
+ `),()=>{K.contains(B)&&K.removeChild(B)}},[i]),y.jsx(DN,{isPresent:i,childRef:h,sizeRef:g,pop:f,children:f===!1?n:T.cloneElement(n,{ref:b})})}const ON=({children:n,initial:i,isPresent:l,onExitComplete:r,custom:c,presenceAffectsLayout:f,mode:d,anchorX:h,anchorY:g,root:p})=>{const v=sd(zN),b=T.useId();let S=!0,w=T.useMemo(()=>(S=!1,{id:b,initial:i,isPresent:l,custom:c,onExitComplete:j=>{v.set(j,!0);for(const A of v.values())if(!A)return;r&&r()},register:j=>(v.set(j,!1),()=>v.delete(j))}),[l,v,r]);return f&&S&&(w={...w}),T.useMemo(()=>{v.forEach((j,A)=>v.set(A,!1))},[l]),T.useEffect(()=>{!l&&!v.size&&r&&r()},[l]),n=y.jsx(RN,{pop:d==="popLayout",isPresent:l,anchorX:h,anchorY:g,root:p,children:n}),y.jsx(bo.Provider,{value:w,children:n})};function zN(){return new Map}function jx(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 Xr=n=>n.key||"";function pv(n){const i=[];return T.Children.forEach(n,l=>{T.isValidElement(l)&&i.push(l)}),i}const Dx=({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]=jx(d),S=T.useMemo(()=>pv(n),[n]),w=d&&!v?[]:S.map(Xr),j=T.useRef(!0),A=T.useRef(S),N=sd(()=>new Map),R=T.useRef(new Set),[G,L]=T.useState(S),[B,K]=T.useState(S);ab(()=>{j.current=!1,A.current=S;for(let k=0;k<B.length;k++){const I=Xr(B[k]);w.includes(I)?(N.delete(I),R.current.delete(I)):N.get(I)!==!0&&N.set(I,!1)}},[B,w.length,w.join("-")]);const W=[];if(S!==G){let k=[...S];for(let I=0;I<B.length;I++){const ft=B[I],ut=Xr(ft);w.includes(ut)||(k.splice(I,0,ft),W.push(ft))}return f==="wait"&&W.length&&(k=W),K(pv(k)),L(S),null}const{forceRender:P}=T.useContext(id);return y.jsx(y.Fragment,{children:B.map(k=>{const I=Xr(k),ft=d&&!v?!1:S===B||w.includes(I),ut=()=>{if(R.current.has(I))return;if(R.current.add(I),N.has(I))N.set(I,!0);else return;let wt=!0;N.forEach(Mt=>{Mt||(wt=!1)}),wt&&(P?.(),K(A.current),d&&b?.(),r&&r())};return y.jsx(ON,{isPresent:ft,initial:!j.current||l?void 0:!1,custom:i,presenceAffectsLayout:c,mode:f,root:p,onExitComplete:ft?void 0:ut,anchorX:h,anchorY:g,children:k},I)})})},Rx=T.createContext({strict:!1}),gv={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 yv=!1;function _N(){if(yv)return;const n={};for(const i in gv)n[i]={isEnabled:l=>gv[i].some(r=>!!l[r])};sx(n),yv=!0}function Ox(){return _N(),x3()}function VN(n){const i=Ox();for(const l in n)i[l]={...i[l],...n[l]};sx(i)}const LN=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 fo(n){return n.startsWith("while")||n.startsWith("drag")&&n!=="draggable"||n.startsWith("layout")||n.startsWith("onTap")||n.startsWith("onPan")||n.startsWith("onLayout")||LN.has(n)}let zx=n=>!fo(n);function kN(n){typeof n=="function"&&(zx=i=>i.startsWith("on")?!fo(i):n(i))}try{kN(require("@emotion/is-prop-valid").default)}catch{}function UN(n,i,l){const r={};for(const c in n)c==="values"&&typeof n.values=="object"||(zx(c)||l===!0&&fo(c)||!i&&!fo(c)||n.draggable&&c.startsWith("onDrag"))&&(r[c]=n[c]);return r}const To=T.createContext({});function BN(n,i){if(So(n)){const{initial:l,animate:r}=n;return{initial:l===!1||sl(l)?l:void 0,animate:sl(r)?r:void 0}}return n.inherit!==!1?i:{}}function HN(n){const{initial:i,animate:l}=BN(n,T.useContext(To));return T.useMemo(()=>({initial:i,animate:l}),[vv(i),vv(l)])}function vv(n){return Array.isArray(n)?n.join(" "):n}const zd=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function _x(n,i,l){for(const r in i)!ge(i[r])&&!dx(r,l)&&(n[r]=i[r])}function GN({transformTemplate:n},i){return T.useMemo(()=>{const l=zd();return Dd(l,i,n),Object.assign({},l.vars,l.style)},[i])}function qN(n,i){const l=n.style||{},r={};return _x(r,l,n),Object.assign(r,GN(n,i)),r}function YN(n,i){const l={},r=qN(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 Vx=()=>({...zd(),attrs:{}});function XN(n,i,l,r){const c=T.useMemo(()=>{const f=Vx();return hx(f,i,px(r),n.transformTemplate,n.style),{...f.attrs,style:{...f.style}}},[i]);if(n.style){const f={};_x(f,n.style,n),c.style={...f,...c.style}}return c}const KN=["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 _d(n){return typeof n!="string"||n.includes("-")?!1:!!(KN.indexOf(n)>-1||/[A-Z]/u.test(n))}function PN(n,i,l,{latestValues:r},c,f=!1,d){const g=(d??_d(n)?XN:YN)(i,r,c,n),p=UN(i,typeof n=="string",f),v=n!==T.Fragment?{...p,...g,ref:l}:{},{children:b}=i,S=T.useMemo(()=>ge(b)?b.get():b,[b]);return T.createElement(n,{...v,children:S})}function ZN({scrapeMotionValuesFromProps:n,createRenderState:i},l,r,c){return{latestValues:QN(l,r,c,n),renderState:i()}}function QN(n,i,l,r){const c={},f=r(n,{});for(const S in f)c[S]=$r(f[S]);let{initial:d,animate:h}=n;const g=So(n),p=ax(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"&&!xo(b)){const S=Array.isArray(b)?b:[b];for(let w=0;w<S.length;w++){const j=Td(n,S[w]);if(j){const{transitionEnd:A,transition:N,...R}=j;for(const G in R){let L=R[G];if(Array.isArray(L)){const B=v?L.length-1:0;L=L[B]}L!==null&&(c[G]=L)}for(const G in A)c[G]=A[G]}}}return c}const Lx=n=>(i,l)=>{const r=T.useContext(To),c=T.useContext(bo),f=()=>ZN(n,i,r,c);return l?f():sd(f)},FN=Lx({scrapeMotionValuesFromProps:Rd,createRenderState:zd}),JN=Lx({scrapeMotionValuesFromProps:gx,createRenderState:Vx}),WN=Symbol.for("motionComponentSymbol");function IN(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 kx=T.createContext({});function Ui(n){return n&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"current")}function $N(n,i,l,r,c,f){const{visualElement:d}=T.useContext(To),h=T.useContext(Rx),g=T.useContext(bo),p=T.useContext(Od),v=p.reducedMotion,b=p.skipAnimations,S=T.useRef(null),w=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}),w.current&&S.current&&(S.current.manuallyAnimateOnMount=!0));const j=S.current,A=T.useContext(kx);j&&!j.projection&&c&&(j.type==="html"||j.type==="svg")&&t4(S.current,l,c,A);const N=T.useRef(!1);T.useInsertionEffect(()=>{j&&N.current&&j.update(l,g)});const R=l[Xb],G=T.useRef(!!R&&!window.MotionHandoffIsComplete?.(R)&&window.MotionHasOptimisedAnimation?.(R));return ab(()=>{w.current=!0,j&&(N.current=!0,window.MotionIsMounted=!0,j.updateFeatures(),j.scheduleRenderMicrotask(),G.current&&j.animationState&&j.animationState.animateChanges())}),T.useEffect(()=>{j&&(!G.current&&j.animationState&&j.animationState.animateChanges(),G.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(R)}),G.current=!1),j.enteringChildren=void 0)}),j}function t4(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:Ux(n.parent)),n.projection.setOptions({layoutId:c,layout:f,alwaysMeasureLayout:!!d||h&&Ui(h),visualElement:n,animationType:typeof f=="string"?f:"both",initialPromotionConfig:r,crossfade:v,layoutScroll:g,layoutRoot:p})}function Ux(n){if(n)return n.options.allowProjection!==!1?n.projection:Ux(n.parent)}function mf(n,{forwardMotionProps:i=!1,type:l}={},r,c){r&&VN(r);const f=l?l==="svg":_d(n),d=f?JN:FN;function h(p,v){let b;const S={...T.useContext(Od),...p,layoutId:e4(p)},{isStatic:w}=S,j=HN(p),A=d(p,w);if(!w&&nb){n4();const N=a4(S);b=N.MeasureLayout,j.visualElement=$N(n,A,S,c,N.ProjectionNode,f)}return y.jsxs(To.Provider,{value:j,children:[b&&j.visualElement?y.jsx(b,{visualElement:j.visualElement,...S}):null,PN(n,p,IN(A,j.visualElement,v),A,w,i,f)]})}h.displayName=`motion.${typeof n=="string"?n:`create(${n.displayName??n.name??""})`}`;const g=T.forwardRef(h);return g[WN]=n,g}function e4({layoutId:n}){const i=T.useContext(id).id;return i&&n!==void 0?i+"-"+n:n}function n4(n,i){T.useContext(Rx).strict}function a4(n){const i=Ox(),{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 i4(n,i){if(typeof Proxy>"u")return mf;const l=new Map,r=(f,d)=>mf(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,mf(d,void 0,n,i)),l.get(d))})}const s4=(n,i)=>i.isSVG??_d(n)?new k3(i):new R3(i,{allowProjection:n!==T.Fragment});class l4 extends Ta{constructor(i){super(i),i.animationState||(i.animationState=q3(i))}updateAnimationControlsSubscription(){const{animate:i}=this.node.getProps();xo(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 r4=0;class o4 extends Ta{constructor(){super(...arguments),this.id=r4++}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 u4={animation:{Feature:l4},exit:{Feature:o4}};function pl(n){return{point:{x:n.pageX,y:n.pageY}}}const c4=n=>i=>Cd(i)&&n(i,pl(i));function el(n,i,l,r){return ll(n,i,c4(l),r)}const Bx=({current:n})=>n?n.ownerDocument.defaultView:null,bv=(n,i)=>Math.abs(n-i);function f4(n,i){const l=bv(n.x,i.x),r=bv(n.y,i.y);return Math.sqrt(l**2+r**2)}const xv=new Set(["auto","scroll"]);class Hx{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=w=>{this.handleScroll(w.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const w=gf(this.lastMoveEventInfo,this.history),j=this.startEvent!==null,A=f4(w.offset,{x:0,y:0})>=this.distanceThreshold;if(!j&&!A)return;const{point:N}=w,{timestamp:R}=de;this.history.push({...N,timestamp:R});const{onStart:G,onMove:L}=this.handlers;j||(G&&G(this.lastMoveEvent,w),this.startEvent=this.lastMoveEvent),L&&L(this.lastMoveEvent,w)},this.handlePointerMove=(w,j)=>{this.lastMoveEvent=w,this.lastMoveEventInfo=pf(j,this.transformPagePoint),Ut.update(this.updatePoint,!0)},this.handlePointerUp=(w,j)=>{this.end();const{onEnd:A,onSessionEnd:N,resumeAnimation:R}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&R&&R(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const G=gf(w.type==="pointercancel"?this.lastMoveEventInfo:pf(j,this.transformPagePoint),this.history);this.startEvent&&A&&A(w,G),N&&N(w,G)},!Cd(i))return;this.dragSnapToOrigin=f,this.handlers=l,this.transformPagePoint=r,this.distanceThreshold=d,this.contextWindow=c||window;const g=pl(i),p=pf(g,this.transformPagePoint),{point:v}=p,{timestamp:b}=de;this.history=[{...v,timestamp:b}];const{onSessionStart:S}=l;S&&S(i,gf(p,this.history)),this.removeListeners=dl(el(this.contextWindow,"pointermove",this.handlePointerMove),el(this.contextWindow,"pointerup",this.handlePointerUp),el(this.contextWindow,"pointercancel",this.handlePointerUp)),h&&this.startScrollTracking(h)}startScrollTracking(i){let l=i.parentElement;for(;l;){const r=getComputedStyle(l);(xv.has(r.overflowX)||xv.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(),xa(this.updatePoint)}}function pf(n,i){return i?{point:i(n.point)}:n}function Sv(n,i){return{x:n.x-i.x,y:n.y-i.y}}function gf({point:n},i){return{point:n,delta:Sv(n,Gx(i)),offset:Sv(n,d4(i)),velocity:h4(i,.1)}}function d4(n){return n[0]}function Gx(n){return n[n.length-1]}function h4(n,i){if(n.length<2)return{x:0,y:0};let l=n.length-1,r=null;const c=Gx(n);for(;l>=0&&(r=n[l],!(c.timestamp-r.timestamp>an(i)));)l--;if(!r)return{x:0,y:0};r===n[0]&&n.length>2&&c.timestamp-r.timestamp>an(i)*2&&(r=n[1]);const f=Qe(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 m4(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 Tv(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 p4(n,{top:i,left:l,bottom:r,right:c}){return{x:Tv(n.x,l,c),y:Tv(n.y,i,r)}}function Ev(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 g4(n,i){return{x:Ev(n.x,i.x),y:Ev(n.y,i.y)}}function y4(n,i){let l=.5;const r=xe(n),c=xe(i);return c>r?l=nl(i.min,i.max-r,n.min):r>c&&(l=nl(n.min,n.max-c,i.min)),vn(0,1,l)}function v4(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 Zf=.35;function b4(n=Zf){return n===!1?n=0:n===!0&&(n=Zf),{x:wv(n,"left","right"),y:wv(n,"top","bottom")}}function wv(n,i,l){return{min:Av(n,i),max:Av(n,l)}}function Av(n,i){return typeof n=="number"?n:n[i]||0}const x4=new WeakMap;class S4{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=ae(),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(pl(b).point),this.stopAnimation()},d=(b,S)=>{const{drag:w,dragPropagation:j,onDragStart:A}=this.getProps();if(w&&!j&&(this.openDragLock&&this.openDragLock(),this.openDragLock=JM(w),!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),mn(R=>{let G=this.getAxisMotionValue(R).get()||0;if(gn.test(G)){const{projection:L}=this.visualElement;if(L&&L.layout){const B=L.layout.layoutBox[R];B&&(G=xe(B)*(parseFloat(G)/100))}}this.originPoint[R]=G}),A&&Ut.update(()=>A(b,S),!1,!0),Uf(this.visualElement,"transform");const{animationState:N}=this.visualElement;N&&N.setActive("whileDrag",!0)},h=(b,S)=>{this.latestPointerEvent=b,this.latestPanInfo=S;const{dragPropagation:w,dragDirectionLock:j,onDirectionLock:A,onDrag:N}=this.getProps();if(!w&&!this.openDragLock)return;const{offset:R}=S;if(j&&this.currentDirection===null){this.currentDirection=E4(R),this.currentDirection!==null&&A&&A(this.currentDirection);return}this.updateAxis("x",S.point,R),this.updateAxis("y",S.point,R),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 Hx(i,{onSessionStart:f,onStart:d,onMove:h,onSessionEnd:g,resumeAnimation:p},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:v,distanceThreshold:r,contextWindow:Bx(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||!Kr(i,c,this.currentDirection))return;const f=this.getAxisMotionValue(i);let d=this.originPoint[i]+r[i];this.constraints&&this.constraints[i]&&(d=m4(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&&Ui(i)?this.constraints||(this.constraints=this.resolveRefConstraints()):i&&r?this.constraints=p4(r.layoutBox,i):this.constraints=!1,this.elastic=b4(l),c!==this.constraints&&!Ui(i)&&r&&this.constraints&&!this.hasMutatedConstraints&&mn(f=>{this.constraints!==!1&&this.getAxisMotionValue(f)&&(this.constraints[f]=v4(r.layoutBox[f],this.constraints[f]))})}resolveRefConstraints(){const{dragConstraints:i,onMeasureDragConstraints:l}=this.getProps();if(!i||!Ui(i))return!1;const r=i.current,{projection:c}=this.visualElement;if(!c||!c.layout)return!1;const f=A3(r,c.root,this.visualElement.getTransformPagePoint());let d=g4(c.layout.layoutBox,f);if(l){const h=l(T3(d));this.hasMutatedConstraints=!!h,h&&(d=rx(h))}return d}startAnimation(i){const{drag:l,dragMomentum:r,dragElastic:c,dragTransition:f,dragSnapToOrigin:d,onDragTransitionEnd:h}=this.getProps(),g=this.constraints||{},p=mn(v=>{if(!Kr(v,l,this.currentDirection))return;let b=g&&g[v]||{};d&&(b={min:0,max:0});const S=c?200:1e6,w=c?40:1e7,j={type:"inertia",velocity:r?i[v]:0,bounceStiffness:S,bounceDamping:w,timeConstant:750,restDelta:1,restSpeed:10,...f,...b};return this.startAxisValueAnimation(v,j)});return Promise.all(p).then(h)}startAxisValueAnimation(i,l){const r=this.getAxisMotionValue(i);return Uf(this.visualElement,i),r.start(Sd(i,r,0,l,this.visualElement,!1))}stopAnimation(){mn(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){mn(l=>{const{drag:r}=this.getProps();if(!Kr(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(!Ui(l)||!r||!this.constraints)return;this.stopAnimation();const c={x:0,y:0};mn(d=>{const h=this.getAxisMotionValue(d);if(h&&this.constraints!==!1){const g=h.get();c[d]=y4({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(),mn(d=>{if(!Kr(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;x4.set(this.visualElement,this);const i=this.visualElement.current,l=el(i,"pointerdown",p=>{const{drag:v,dragListener:b=!0}=this.getProps(),S=p.target,w=S!==i&&n3(S);v&&b&&!w&&this.start(p)});let r;const c=()=>{const{dragConstraints:p}=this.getProps();Ui(p)&&p.current&&(this.constraints=this.resolveRefConstraints(),r||(r=T4(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=ll(window,"resize",()=>this.scalePositionWithinConstraints()),g=f.addEventListener("didUpdate",(({delta:p,hasLayoutChanged:v})=>{this.isDragging&&v&&(mn(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=Zf,dragMomentum:h=!0}=i;return{...i,drag:l,dragDirectionLock:r,dragPropagation:c,dragConstraints:f,dragElastic:d,dragMomentum:h}}}function Cv(n){let i=!0;return()=>{if(i){i=!1;return}n()}}function T4(n,i,l){const r=zy(n,Cv(l)),c=zy(i,Cv(l));return()=>{r(),c()}}function Kr(n,i,l){return(i===!0||i===n)&&(l===null||l===n)}function E4(n,i=10){let l=null;return Math.abs(n.y)>i?l="y":Math.abs(n.x)>i&&(l="x"),l}class w4 extends Ta{constructor(i){super(i),this.removeGroupControls=Fe,this.removeListeners=Fe,this.controls=new S4(i)}mount(){const{dragControls:i}=this.node.getProps();i&&(this.removeGroupControls=i.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||Fe}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 yf=n=>(i,l)=>{n&&Ut.update(()=>n(i,l),!1,!0)};class A4 extends Ta{constructor(){super(...arguments),this.removePointerDownListener=Fe}onPointerDown(i){this.session=new Hx(i,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:Bx(this.node)})}createPanHandlers(){const{onPanSessionStart:i,onPanStart:l,onPan:r,onPanEnd:c}=this.node.getProps();return{onSessionStart:yf(i),onStart:yf(l),onMove:yf(r),onEnd:(f,d)=>{delete this.session,c&&Ut.postRender(()=>c(f,d))}}}mount(){this.removePointerDownListener=el(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 vf=!1;class C4 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),vf&&f.root.didUpdate(),f.addEventListener("animationComplete",()=>{this.safeToRemove()}),f.setOptions({...f.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),to.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}),vf=!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(),Ad.postRender(()=>{!i.currentAnimation&&i.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:i,layoutGroup:l,switchLayoutGroup:r}=this.props,{projection:c}=i;vf=!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 qx(n){const[i,l]=jx(),r=T.useContext(id);return y.jsx(C4,{...n,layoutGroup:r,switchLayoutGroup:T.useContext(kx),isPresent:i,safeToRemove:l})}const M4={pan:{Feature:A4},drag:{Feature:w4,ProjectionNode:Nx,MeasureLayout:qx}};function Mv(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,pl(i)))}class N4 extends Ta{mount(){const{current:i}=this.node;i&&(this.unmount=IM(i,(l,r)=>(Mv(this.node,r,"Start"),c=>Mv(this.node,c,"End"))))}unmount(){}}class j4 extends Ta{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=dl(ll(this.node.current,"focus",()=>this.onFocus()),ll(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function Nv(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,pl(i)))}class D4 extends Ta{mount(){const{current:i}=this.node;if(!i)return;const{globalTapTarget:l,propagate:r}=this.node.props;this.unmount=i3(i,(c,f)=>(Nv(this.node,f,"Start"),(d,{success:h})=>Nv(this.node,d,h?"End":"Cancel")),{useGlobalTarget:l,stopPropagation:r?.tap===!1})}unmount(){}}const Qf=new WeakMap,bf=new WeakMap,R4=n=>{const i=Qf.get(n.target);i&&i(n)},O4=n=>{n.forEach(R4)};function z4({root:n,...i}){const l=n||document;bf.has(l)||bf.set(l,{});const r=bf.get(l),c=JSON.stringify(i);return r[c]||(r[c]=new IntersectionObserver(O4,{root:n,...i})),r[c]}function _4(n,i,l){const r=z4(i);return Qf.set(n,l),r.observe(n),()=>{Qf.delete(n),r.unobserve(n)}}const V4={some:0,all:1};class L4 extends Ta{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 _4(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(k4(i,l))&&this.startObserver()}unmount(){}}function k4({viewport:n={}},{viewport:i={}}={}){return l=>n[l]!==i[l]}const U4={inView:{Feature:L4},tap:{Feature:D4},focus:{Feature:j4},hover:{Feature:N4}},B4={layout:{ProjectionNode:Nx,MeasureLayout:qx}},H4={...u4,...U4,...M4,...B4},rl=i4(H4,s4);function G4(n){const i=Math.floor(n/60),l=n%60;return`${i}:${l.toString().padStart(2,"0")}`}function q4({onSend:n,onStop:i,streaming:l}){const[r,c]=T.useState(""),[f,d]=T.useState(!1),[h,g]=T.useState(0),p=r.trim().length>0,v=T.useRef(null),b=T.useRef(null),S=T.useRef(null),w=T.useRef(null),j=T.useRef(null),A=T.useRef(0),N=T.useRef(0),R=T.useRef(null),G=T.useRef(!1),L=T.useRef(null);T.useEffect(()=>{if(f)return L.current=setInterval(()=>g(ut=>ut+1),1e3),()=>{L.current&&clearInterval(L.current)}},[f]);const B=T.useCallback(ut=>{L.current&&clearInterval(L.current),R.current&&(clearTimeout(R.current),R.current=null),G.current=!1,j.current&&(j.current.style.transform=""),d(!1),g(0),N.current=0},[]),K=()=>{p&&(n(r),c(""),requestAnimationFrame(()=>v.current?.focus()))},W=ut=>{ut.key==="Enter"&&!ut.shiftKey&&(ut.preventDefault(),K())},P=T.useCallback(ut=>{ut.preventDefault(),A.current=ut.clientX,N.current=0,ut.currentTarget.setPointerCapture(ut.pointerId),R.current=setTimeout(()=>{G.current=!0,d(!0),g(0)},200)},[]),k=T.useCallback(ut=>{if(!G.current)return;const wt=Math.min(0,ut.clientX-A.current);if(N.current=wt,j.current&&(j.current.style.transform=`translateX(${wt}px)`),w.current){const Mt=w.current.getBoundingClientRect(),Zt=Mt.left+Mt.width/2;Math.abs(ut.clientX-Zt)<36&&B(!0)}},[B]),I=T.useCallback(()=>{R.current&&(clearTimeout(R.current),R.current=null),G.current&&B(!1)},[B]),ft=T.useCallback(()=>{R.current&&(clearTimeout(R.current),R.current=null),G.current&&B(!0)},[B]);return y.jsxs("div",{className:"shrink-0 p-3 relative",children:[y.jsxs("div",{className:`flex items-center gap-2 transition-opacity duration-100 ${f?"opacity-0 pointer-events-none":"opacity-100"}`,children:[y.jsxs("div",{className:"flex-1 flex items-center bg-white rounded-full px-4",children:[y.jsx("textarea",{ref:v,value:r,onChange:ut=>c(ut.target.value),onKeyDown:W,placeholder:"Type a message...",rows:1,className:"flex-1 resize-none bg-transparent text-gray-900 py-3 text-sm outline-none placeholder:text-gray-400"}),y.jsx("input",{ref:b,type:"file",className:"hidden",accept:"*/*"}),y.jsx("input",{ref:S,type:"file",className:"hidden",accept:"image/*",capture:"environment"}),y.jsx("button",{type:"button",onClick:()=>b.current?.click(),className:"shrink-0 p-1.5 text-gray-400 hover:text-gray-600 transition-colors",children:y.jsx(tT,{className:"h-4 w-4"})}),y.jsx("button",{type:"button",onClick:()=>S.current?.click(),className:"shrink-0 p-1.5 text-gray-400 hover:text-gray-600 transition-colors",children:y.jsx(V2,{className:"h-4 w-4"})})]}),l?y.jsx("button",{onClick:i,className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-destructive text-destructive-foreground transition-colors",children:y.jsx(fT,{className:"h-4 w-4"})}):p?y.jsx("button",{onClick:K,className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-white text-gray-900 transition-colors hover:bg-gray-100",children:y.jsx(lT,{className:"h-4 w-4"})}):y.jsx("div",{className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-white text-gray-900 transition-colors hover:bg-gray-100 cursor-pointer touch-none select-none",onPointerDown:P,onPointerMove:k,onPointerUp:I,onPointerCancel:ft,children:y.jsx(xf,{className:"h-4 w-4"})})]}),y.jsx(Dx,{children:f&&y.jsx(rl.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"absolute inset-0 p-3 flex items-center touch-none",children:y.jsxs("div",{className:"flex items-center w-full gap-2",children:[y.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[y.jsxs("span",{className:"relative flex h-2 w-2 shrink-0",children:[y.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-destructive opacity-75"}),y.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-destructive"})]}),y.jsx("span",{className:"text-sm font-medium tabular-nums",children:G4(h)})]}),y.jsxs("div",{className:"flex-1 flex items-center bg-muted rounded-full h-12 pl-1 pr-0.5",children:[y.jsx("div",{ref:w,className:"flex items-center justify-center h-9 w-9 shrink-0 rounded-full bg-destructive/10 text-destructive",children:y.jsx(hT,{className:"h-4 w-4"})}),y.jsx("div",{className:"flex-1 flex justify-center min-w-0",children:y.jsx(rl.span,{className:"text-[13px] whitespace-nowrap select-none font-medium",style:{backgroundImage:"linear-gradient(90deg, #999 0%, #999 35%, #fff 50%, #999 65%, #999 100%)",backgroundSize:"200% 100%",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",backgroundClip:"text"},animate:{backgroundPosition:["200% center","-200% center"]},transition:{duration:2.5,repeat:1/0,ease:"linear"},children:"◄◄ slide to cancel"})}),y.jsx("div",{ref:j,className:"shrink-0 touch-none select-none will-change-transform",style:{transition:"none"},onPointerDown:P,onPointerMove:k,onPointerUp:I,onPointerCancel:ft,children:y.jsx("div",{className:"flex items-center justify-center h-11 w-11 rounded-full bg-destructive text-destructive-foreground",children:y.jsx(xf,{className:"h-5 w-5"})})})]})]})})})]})}function Y4({ws:n}){const{messages:i,streaming:l,streamBuffer:r,sendMessage:c,stopStreaming:f}=XA(n);return y.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[y.jsx(ZA,{messages:i,streaming:l,streamBuffer:r}),y.jsx(q4,{onSend:c,onStop:f,streaming:l})]})}function X4({onClick:n}){return y.jsx(rl.div,{className:"fixed bottom-6 right-6 z-50 cursor-pointer",whileHover:{scale:1.1},whileTap:{scale:.95},onClick:n,role:"button","aria-label":"Open Fluxy chat",children:y.jsx("img",{src:"/fluxy.png",alt:"Fluxy",className:"h-11 w-auto drop-shadow-lg",draggable:!1})})}const K4=[{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}],P4={anthropic:[{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4"},{id:"claude-opus-4-20250514",label:"Claude Opus 4"},{id:"claude-haiku-4-5-20251001",label:"Claude 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"}]},jv=5,Z4=[{tier:"premium",label:n=>`${n}.fluxy.bot`,badge:"$5",badgeCls:"bg-primary/15 text-primary border-primary/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 Q4({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-primary/30 transition-colors",children:[y.jsx("span",{className:d?"text-white":"text-white/20",children:d?d.label:"Choose a model..."}),y.jsx(ol,{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-primary bg-primary/10":"text-white/70 hover:bg-white/[0.04] hover:text-white"}`,children:h.label},h.id))})]})}function F4({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"}),[w,j]=T.useState(!1),[A,N]=T.useState(""),[R,G]=T.useState(!1),[L,B]=T.useState(),[K,W]=T.useState(!1),[P,k]=T.useState(!1),[I,ft]=T.useState(),[ut,wt]=T.useState(""),[Mt,Zt]=T.useState(""),[At,_]=T.useState(null),[Z,$]=T.useState(""),[ht,Q]=T.useState("at"),[C,Y]=T.useState(!1),[F,tt]=T.useState(!1),[lt,rt]=T.useState(""),gt=T.useRef(null),[Bt,mt]=T.useState(!1),me=b[f]==="connected";T.useEffect(()=>{f!=="anthropic"||b.anthropic==="connected"||fetch("/api/auth/claude/status").then(J=>J.json()).then(J=>{J.authenticated&&S(bt=>({...bt,anthropic:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{f!=="openai"||b.openai==="connected"||fetch("/api/auth/codex/status").then(J=>J.json()).then(J=>{J.authenticated&&S(bt=>({...bt,openai:"connected"}))}).catch(()=>{})},[f]),T.useEffect(()=>{if(!P)return;const J=setInterval(async()=>{try{(await(await fetch("/api/auth/codex/status")).json()).authenticated&&(k(!1),S(vl=>({...vl,openai:"connected"})))}catch{}},2e3);return()=>clearInterval(J)},[P]),T.useEffect(()=>{gt.current&&clearTimeout(gt.current),_(null),$(""),tt(!1),rt("");const J=Mt.trim();if(J){if(J.length<3){_("invalid"),$("At least 3 characters");return}return _("checking"),gt.current=setTimeout(async()=>{try{const un=await(await fetch(`/api/handle/check/${encodeURIComponent(J)}`)).json();un.valid?un.available?_("available"):_("taken"):(_("invalid"),$(un.error))}catch{_(null)}},400),()=>{gt.current&&clearTimeout(gt.current)}}},[Mt]);const We=J=>{Zt(J.toLowerCase().replace(/[^a-z0-9-]/g,""))},rn=async()=>{if(!(!Mt||At!=="available")){Y(!0);try{const bt=await(await fetch("/api/handle/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:Mt,tier:ht})})).json();bt.ok?(tt(!0),rt(bt.url)):($(bt.error||"Registration failed"),_("invalid"))}catch{$("Could not reach server"),_("invalid")}finally{Y(!1)}}},Gn=J=>{f==="openai"&&J!=="openai"&&P&&(fetch("/api/auth/codex/cancel",{method:"POST"}),k(!1)),d(J),g(""),j(!1),N(""),B(void 0),k(!1),ft(void 0)},Se=async()=>{B(void 0);try{const bt=await(await fetch("/api/auth/claude/start",{method:"POST"})).json();bt.success&&bt.authUrl?(window.open(bt.authUrl,"_blank"),j(!0)):B(bt.error||"Failed to start authentication")}catch(J){B(J.message)}},Ja=async()=>{if(A.trim()){G(!0),B(void 0);try{const bt=await(await fetch("/api/auth/claude/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:A.trim()})})).json();bt.success?S(un=>({...un,anthropic:"connected"})):B(bt.error||"Code exchange failed")}catch(J){B(J.message)}finally{G(!1)}}},Ji=async()=>{try{const J=await navigator.clipboard.readText();J&&N(J.trim())}catch{}},Eo=async()=>{W(!0),B(void 0);try{(await(await fetch("/api/auth/claude/status")).json()).authenticated?S(un=>({...un,anthropic:"connected"})):B("No active session found. Please authenticate first.")}catch{}finally{W(!1)}},gl=async()=>{k(!0),ft(void 0);try{const bt=await(await fetch("/api/auth/codex/start",{method:"POST"})).json();bt.success&&bt.authUrl?window.open(bt.authUrl,"_blank"):(k(!1),ft(bt.error||"Failed to start authentication"))}catch(J){k(!1),ft(J.message)}},Wi=()=>{k(!1),fetch("/api/auth/codex/cancel",{method:"POST"})},qn=(()=>{switch(i){case 0:return!0;case 1:return r.trim().length>0;case 2:return Mt.trim().length>=3;case 3:return!!(f&&h&&me);case 4:return!0;default:return!1}})(),on=()=>{qn&&i<jv-1&&l(J=>J+1)},wo=()=>{i>0&&l(J=>J-1)},Ao=J=>{J.key==="Enter"&&qn&&on()},ye=async()=>{v(!0);try{await fetch("/api/onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userName:r.trim(),agentName:Mt.trim()||"Fluxy",provider:f,model:h,apiKey:"",baseUrl:f==="ollama"&&ut||void 0,whisperEnabled:Bt})}),n()}catch(J){console.error("Onboard failed:",J),v(!1)}},yl="w-full bg-white/[0.05] border border-white/[0.08] text-white rounded-xl px-4 py-3 text-base outline-none focus:border-primary/40 placeholder:text-white/20 transition-colors",Ii="w-full bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none focus:border-primary/30 placeholder:text-white/20 transition-colors";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(rl.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:jv},(J,bt)=>y.jsx("div",{className:`h-1.5 rounded-full transition-all duration-300 ${bt===i?"w-7 bg-primary":bt<i?"w-1.5 bg-primary/60":"w-1.5 bg-white/10"}`},bt))}),y.jsx(Dx,{mode:"wait",children:y.jsxs(rl.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("img",{src:"/fluxy.png",alt:"Fluxy",className:"h-16 w-auto 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:on,className:"mt-6 px-7 py-3 bg-primary hover:bg-primary/90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center gap-2",children:["Get Started",y.jsx(kn,{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:J=>c(J.target.value),onKeyDown:Ao,placeholder:"Enter your name",autoFocus:!0,className:yl+" flex-1"}),y.jsx("button",{onClick:on,disabled:!qn,className:"shrink-0 h-12 w-12 flex items-center justify-center rounded-full bg-primary hover:bg-primary/90 text-white transition-colors disabled:opacity-30",children:y.jsx(kn,{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."}),y.jsxs("div",{className:"relative mt-5",children:[y.jsx("input",{type:"text",value:Mt,onChange:J=>We(J.target.value),maxLength:30,placeholder:"your-bot-name",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",autoFocus:!0,disabled:F,className:yl+" pr-10 font-mono"+(F?" opacity-50":"")}),At&&Mt.length>0&&!F&&y.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:[At==="checking"&&y.jsx("div",{className:"w-5 h-5 border-2 border-white/10 border-t-primary rounded-full animate-spin"}),At==="available"&&y.jsx("div",{className:"w-6 h-6 rounded-full bg-emerald-500/15 flex items-center justify-center",children:y.jsx(Xc,{className:"h-3.5 w-3.5 text-emerald-400"})}),At==="taken"&&y.jsx("div",{className:"w-6 h-6 rounded-full bg-red-500/15 flex items-center justify-center",children:y.jsx("svg",{className:"w-3.5 h-3.5 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:y.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}),At==="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"})})})]})]}),At==="invalid"&&Z&&y.jsx("p",{className:"text-amber-400 text-[12px] mt-2",children:Z}),At==="taken"&&y.jsx("p",{className:"text-red-400 text-[12px] mt-2",children:"This name is already taken"}),At==="available"&&Mt.length>0&&!F&&y.jsx("div",{className:"space-y-2 mt-4",children:Z4.map(J=>y.jsxs("button",{onClick:()=>Q(J.tier),className:`w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all duration-200 text-left ${ht===J.tier?J.highlight?"border-primary/40 bg-primary/[0.06]":"border-primary/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:J.label(Mt)}),y.jsx("span",{className:`text-[11px] font-medium px-2.5 py-0.5 rounded-full border ${J.badgeCls}`,children:J.badge})]},J.tier))}),F&&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(Xc,{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:lt})]}),At==="available"&&Mt.length>0&&!F&&y.jsx("button",{onClick:rn,disabled:C,className:"w-full mt-4 py-3 bg-primary hover:bg-primary/90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:C?y.jsxs(y.Fragment,{children:[y.jsx(Zs,{className:"h-4 w-4 animate-spin"}),"Claiming..."]}):y.jsxs(y.Fragment,{children:["Claim & Continue",y.jsx(kn,{className:"h-4 w-4"})]})}),F&&y.jsxs("button",{onClick:on,className:"w-full mt-4 py-3 bg-primary hover:bg-primary/90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",y.jsx(kn,{className:"h-4 w-4"})]}),!F&&(At!=="available"||Mt.length===0)&&Mt.length>=3&&y.jsxs("button",{onClick:on,className:"w-full mt-4 py-2.5 text-white/30 hover:text-white/50 text-[13px] transition-colors flex items-center justify-center gap-2",children:["Skip handle for now",y.jsx(kn,{className:"h-3.5 w-3.5"})]})]}),i===3&&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:K4.map(J=>y.jsxs("button",{onClick:()=>Gn(J.id),className:`flex-1 relative rounded-xl border transition-all duration-200 p-3 text-left ${f===J.id?"bg-white/[0.04] border-primary/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:[J.icon?y.jsx("img",{src:J.icon,alt:J.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:J.name}),y.jsx("div",{className:"text-[10px] text-white/30",children:J.subtitle})]})]}),b[J.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(Xc,{className:"h-2.5 w-2.5 text-emerald-400"})}):f===J.id?y.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-primary"}):null]},J.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:[me&&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."})}),!me&&y.jsxs(y.Fragment,{children:[L&&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:L})}),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((J,bt)=>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:bt+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:J})]},bt))}),y.jsx("button",{onClick:Se,className:"w-full py-2.5 px-4 bg-primary hover:bg-primary/90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2",children:w?y.jsxs(y.Fragment,{children:[y.jsx(Y2,{className:"h-3.5 w-3.5 opacity-60"}),"Open authentication page again"]}):y.jsxs(y.Fragment,{children:["Authenticate with Anthropic",y.jsx(kn,{className:"h-3.5 w-3.5 opacity-60"})]})}),y.jsxs("div",{className:"relative",children:[y.jsx("input",{type:"text",value:A,onChange:J=>N(J.target.value),onKeyDown:J=>J.key==="Enter"&&Ja(),placeholder:"Paste your code here...",className:Ii+" pr-10 font-mono"}),y.jsx("button",{onClick:Ji,className:"absolute right-3 top-1/2 -translate-y-1/2 text-white/20 hover:text-white/50 transition-colors",children:y.jsx(B2,{className:"h-3.5 w-3.5"})})]}),y.jsx("button",{onClick:Ja,disabled:!A.trim()||R,className:"w-full py-2.5 px-4 bg-primary hover:bg-primary/90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:R?y.jsxs(y.Fragment,{children:[y.jsx(Zs,{className:"h-3.5 w-3.5 animate-spin"}),"Verifying..."]}):"Connect"}),y.jsxs("button",{onClick:Eo,disabled:K,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:[K?y.jsx(Zs,{className:"h-3 w-3 animate-spin"}):y.jsx(nT,{className:"h-3 w-3"}),K?"Checking...":"I'm already authenticated"]})]})]}),f==="openai"&&y.jsxs("div",{className:"space-y-2.5",children:[me&&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."})}),!me&&y.jsxs(y.Fragment,{children:[I&&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:I})}),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((J,bt)=>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:bt+1}),y.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:J})]},bt))}),y.jsx("button",{onClick:gl,disabled:P,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:P?y.jsxs(y.Fragment,{children:[y.jsx(Zs,{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(kn,{className:"h-3.5 w-3.5 opacity-60"})]})}),P&&y.jsx("button",{onClick:Wi,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:ut,onChange:J=>wt(J.target.value),placeholder:"http://localhost:11434",className:Ii})]})]}),me&&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(Q4,{models:P4[f]||[],value:h,onChange:g})]}),me&&y.jsxs("button",{onClick:on,disabled:!qn,className:"w-full mt-4 py-3 bg-primary hover:bg-primary/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(kn,{className:"h-4 w-4"})]})]}),i===4&&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:()=>mt(J=>!J),className:`w-full mt-5 rounded-xl border transition-all duration-200 p-4 text-left ${Bt?"bg-white/[0.04] border-primary/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 ${Bt?"bg-primary":"bg-white/[0.08]"}`,children:y.jsx("div",{className:`w-[18px] h-[18px] rounded-full bg-white shadow-sm transition-transform duration-200 ${Bt?"translate-x-[18px]":"translate-x-0"}`})})]})}),Bt&&y.jsx("div",{className:"mt-3 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-3",children:y.jsxs("div",{className:"flex items-start gap-2.5",children:[y.jsx(xf,{className:"h-4 w-4 text-primary/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:ye,disabled:p,className:"w-full mt-5 py-3 bg-primary hover:bg-primary/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(Zs,{className:"h-4 w-4 animate-spin"}),"Setting up..."]}):y.jsxs(y.Fragment,{children:["Complete Setup",y.jsx(kn,{className:"h-4 w-4"})]})}),!Bt&&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:wo,className:"text-white/25 hover:text-white/50 text-[12px] transition-colors",children:"← Back"})})]})]})}function J4(){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 W4(){const[n,i]=T.useState(!1),[l,r]=T.useState(!1),{ws:c,connected:f}=b2();return T.useEffect(()=>{fetch("/api/settings").then(d=>d.json()).then(d=>{d.onboard_complete!=="true"&&r(!0)}).catch(()=>r(!0))},[]),y.jsxs(y.Fragment,{children:[y.jsx(x2,{fallback:y.jsx(J4,{}),children:y.jsx(UA,{onOpenOnboard:()=>r(!0),children:y.jsx(YA,{})})}),y.jsx($0,{open:n,onOpenChange:i,children:y.jsxs(tb,{side:"right",className:"w-full sm:max-w-md !gap-0 !p-0 !border-l-0",onOpenAutoFocus:d=>d.preventDefault(),children:[y.jsxs("div",{className:"flex items-center gap-3 px-4 pr-12 py-3 border-b border-border shrink-0",children:[y.jsx("img",{src:"/fluxy.png",alt:"Fluxy",className:"h-5 w-auto"}),y.jsx(eb,{className:"text-sm font-semibold",children:"Fluxy"}),y.jsx("div",{className:`h-2 w-2 rounded-full ${f?"bg-green-500":"bg-red-500"}`}),y.jsx(VA,{className:"sr-only",children:"Chat with your Fluxy AI assistant"})]}),y.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:y.jsx(Y4,{ws:c})})]})}),y.jsx(X4,{onClick:()=>i(d=>!d)}),l&&y.jsx(F4,{onComplete:()=>r(!1)})]})}y2.createRoot(document.getElementById("root")).render(y.jsx(Bn.StrictMode,{children:y.jsx(W4,{})}));
package/dist/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <meta name="theme-color" content="#212121" />
7
7
  <title>Fluxy</title>
8
- <script type="module" crossorigin src="/assets/index-qj4hIsKu.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-DVzlk0FS.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-CX_6AQUX.css">
10
10
  <link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
11
11
  <body class="bg-background text-foreground">
package/dist/sw.js CHANGED
@@ -1 +1 @@
1
- if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const d=e=>i(e,t),l={module:{uri:t},exports:o,require:d};s[t]=Promise.all(n.map(e=>l[e]||d(e))).then(e=>(r(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"22a4841b0baedddcea1d808314dff43c"},{url:"assets/index-qj4hIsKu.js",revision:null},{url:"assets/index-CX_6AQUX.css",revision:null},{url:"manifest.webmanifest",revision:"f73683d89ca6b3b7b63451130e165f71"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});
1
+ if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const l=e=>i(e,t),d={module:{uri:t},exports:o,require:l};s[t]=Promise.all(n.map(e=>d[e]||l(e))).then(e=>(r(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"77701374670d87799892d5e2bd2d0ced"},{url:"assets/index-DVzlk0FS.js",revision:null},{url:"assets/index-CX_6AQUX.css",revision:null},{url:"manifest.webmanifest",revision:"f73683d89ca6b3b7b63451130e165f71"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluxy-bot",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Self-hosted AI bot — run your own AI assistant from anywhere",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -7,20 +7,21 @@ import { log } from '../shared/logger.js';
7
7
 
8
8
  let proc: ChildProcess | null = null;
9
9
 
10
+ const MIN_CF_SIZE = 10 * 1024 * 1024; // 10 MB — valid cloudflared is ~30-50 MB
11
+
10
12
  function findBinary(): string | null {
11
13
  // Check system-wide install
12
- try { execSync('cloudflared --version', { stdio: 'ignore' }); return 'cloudflared'; } catch {}
14
+ const which = process.platform === 'win32' ? 'where cloudflared' : 'which cloudflared';
15
+ try { execSync(which, { stdio: 'ignore' }); return 'cloudflared'; } catch {}
13
16
 
14
- // Check local install
17
+ // Check local install (validate by file size, never execute — avoids Windows popup)
15
18
  if (!fs.existsSync(paths.cloudflared)) return null;
16
- try {
17
- execSync(`"${paths.cloudflared}" --version`, { stdio: 'ignore' });
18
- return paths.cloudflared;
19
- } catch {
20
- // Binary exists but is corrupt — delete and re-download
19
+ const size = fs.statSync(paths.cloudflared).size;
20
+ if (size < MIN_CF_SIZE) {
21
21
  fs.unlinkSync(paths.cloudflared);
22
22
  return null;
23
23
  }
24
+ return paths.cloudflared;
24
25
  }
25
26
 
26
27
  export async function installCloudflared(): Promise<string> {
@@ -30,11 +31,14 @@ export async function installCloudflared(): Promise<string> {
30
31
  const dir = path.dirname(paths.cloudflared);
31
32
  fs.mkdirSync(dir, { recursive: true });
32
33
 
33
- const p = os.platform(), a = os.arch();
34
+ const p = os.platform();
35
+ const a = p === 'win32'
36
+ ? (process.env.PROCESSOR_ARCHITECTURE || os.arch()).toLowerCase()
37
+ : os.arch();
34
38
  const base = 'https://github.com/cloudflare/cloudflared/releases/latest/download';
35
39
 
36
40
  let url: string;
37
- if (p === 'win32') url = `${base}/cloudflared-windows-${a === 'arm64' ? 'arm64' : 'amd64'}.exe`;
41
+ if (p === 'win32') url = `${base}/cloudflared-windows-${a.includes('arm') ? 'arm64' : 'amd64'}.exe`;
38
42
  else if (p === 'darwin') url = `${base}/cloudflared-darwin-${a === 'arm64' ? 'arm64' : 'amd64'}.tgz`;
39
43
  else if (a === 'arm64' || a === 'aarch64') url = `${base}/cloudflared-linux-arm64`;
40
44
  else if (a.startsWith('arm')) url = `${base}/cloudflared-linux-arm`;