fluxy-bot 0.1.24 → 0.1.26

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.
@@ -49,7 +49,9 @@ export default function App() {
49
49
  if (s.agent_name) setBotName(s.agent_name);
50
50
  if (s.whisper_enabled === 'true') setWhisperEnabled(true);
51
51
  })
52
- .catch(() => setShowOnboard(true));
52
+ .catch(() => {
53
+ // Network error — bot is unreachable, don't assume not onboarded
54
+ });
53
55
  }, []);
54
56
 
55
57
  // Refresh bot name + whisper after onboarding completes
@@ -97,4 +97,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
97
97
  ${C}px !important;
98
98
  ${_}px !important;
99
99
  }
100
- `),()=>{F.contains(L)&&F.removeChild(L)}},[t]),S.jsx(E9,{isPresent:t,childRef:d,sizeRef:f,pop:l,children:l===!1?e:A.cloneElement(e,{ref:g})})}const v9=({children:e,initial:t,isPresent:n,onExitComplete:r,custom:o,presenceAffectsLayout:l,mode:u,anchorX:d,anchorY:f,root:p})=>{const m=Rv(x9),g=A.useId();let y=!0,E=A.useMemo(()=>(y=!1,{id:g,initial:t,isPresent:n,custom:o,onExitComplete:v=>{m.set(v,!0);for(const T of m.values())if(!T)return;r&&r()},register:v=>(m.set(v,!1),()=>m.delete(v))}),[n,m,r]);return l&&y&&(E={...E}),A.useMemo(()=>{m.forEach((v,T)=>m.set(T,!1))},[n]),A.useEffect(()=>{!n&&!m.size&&r&&r()},[n]),e=S.jsx(S9,{pop:u==="popLayout",isPresent:n,anchorX:d,anchorY:f,root:p,children:e}),S.jsx(kd.Provider,{value:E,children:e})};function x9(){return new Map}function b1(e=!0){const t=A.useContext(kd);if(t===null)return[!0,null];const{isPresent:n,onExitComplete:r,register:o}=t,l=A.useId();A.useEffect(()=>{if(e)return o(l)},[e]);const u=A.useCallback(()=>e&&r&&r(l),[l,r,e]);return!n&&r?[!1,u]:[!0]}const pc=e=>e.key||"";function zN(e){const t=[];return A.Children.forEach(e,n=>{A.isValidElement(n)&&t.push(n)}),t}const qc=({children:e,custom:t,initial:n=!0,onExitComplete:r,presenceAffectsLayout:o=!0,mode:l="sync",propagate:u=!1,anchorX:d="left",anchorY:f="top",root:p})=>{const[m,g]=b1(u),y=A.useMemo(()=>zN(e),[e]),E=u&&!m?[]:y.map(pc),v=A.useRef(!0),T=A.useRef(y),k=Rv(()=>new Map),w=A.useRef(new Set),[C,_]=A.useState(y),[L,F]=A.useState(y);VO(()=>{v.current=!1,T.current=y;for(let B=0;B<L.length;B++){const W=pc(L[B]);E.includes(W)?(k.delete(W),w.current.delete(W)):k.get(W)!==!0&&k.set(W,!1)}},[L,E.length,E.join("-")]);const D=[];if(y!==C){let B=[...y];for(let W=0;W<L.length;W++){const U=L[W],X=pc(U);E.includes(X)||(B.splice(W,0,U),D.push(U))}return l==="wait"&&D.length&&(B=D),F(zN(B)),_(y),null}const{forceRender:z}=A.useContext(kv);return S.jsx(S.Fragment,{children:L.map(B=>{const W=pc(B),U=u&&!m?!1:y===L||E.includes(W),X=()=>{if(w.current.has(W))return;if(w.current.add(W),k.has(W))k.set(W,!0);else return;let Q=!0;k.forEach(te=>{te||(Q=!1)}),Q&&(z?.(),F(T.current),u&&g?.(),r&&r())};return S.jsx(v9,{isPresent:U,initial:!v.current||n?void 0:!1,custom:t,presenceAffectsLayout:o,mode:l,root:p,onExitComplete:U?void 0:X,anchorX:d,anchorY:f,children:B},W)})})},y1=A.createContext({strict:!1}),GN={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 $N=!1;function w9(){if($N)return;const e={};for(const t in GN)e[t]={isEnabled:n=>GN[t].some(r=>!!n[r])};YI(e),$N=!0}function E1(){return w9(),u8()}function T9(e){const t=E1();for(const n in e)t[n]={...t[n],...e[n]};YI(t)}const A9=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 Yc(e){return e.startsWith("while")||e.startsWith("drag")&&e!=="draggable"||e.startsWith("layout")||e.startsWith("onTap")||e.startsWith("onPan")||e.startsWith("onLayout")||A9.has(e)}let S1=e=>!Yc(e);function k9(e){typeof e=="function"&&(S1=t=>t.startsWith("on")?!Yc(t):e(t))}try{k9(require("@emotion/is-prop-valid").default)}catch{}function R9(e,t,n){const r={};for(const o in e)o==="values"&&typeof e.values=="object"||(S1(o)||n===!0&&Yc(o)||!t&&!Yc(o)||e.draggable&&o.startsWith("onDrag"))&&(r[o]=e[o]);return r}const _d=A.createContext({});function N9(e,t){if(Nd(e)){const{initial:n,animate:r}=e;return{initial:n===!1||fl(n)?n:void 0,animate:fl(r)?r:void 0}}return e.inherit!==!1?t:{}}function _9(e){const{initial:t,animate:n}=N9(e,A.useContext(_d));return A.useMemo(()=>({initial:t,animate:n}),[HN(t),HN(n)])}function HN(e){return Array.isArray(e)?e.join(" "):e}const tx=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function v1(e,t,n){for(const r in t)!Wt(t[r])&&!e1(r,n)&&(e[r]=t[r])}function C9({transformTemplate:e},t){return A.useMemo(()=>{const n=tx();return Qv(n,t,e),Object.assign({},n.vars,n.style)},[t])}function O9(e,t){const n=e.style||{},r={};return v1(r,n,e),Object.assign(r,C9(e,t)),r}function I9(e,t){const n={},r=O9(e,t);return e.drag&&e.dragListener!==!1&&(n.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout="none",r.touchAction=e.drag===!0?"none":`pan-${e.drag==="x"?"y":"x"}`),e.tabIndex===void 0&&(e.onTap||e.onTapStart||e.whileTap)&&(n.tabIndex=0),n.style=r,n}const x1=()=>({...tx(),attrs:{}});function D9(e,t,n,r){const o=A.useMemo(()=>{const l=x1();return t1(l,t,a1(r),e.transformTemplate,e.style),{...l.attrs,style:{...l.style}}},[t]);if(e.style){const l={};v1(l,e.style,e),o.style={...l,...o.style}}return o}const L9=["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 nx(e){return typeof e!="string"||e.includes("-")?!1:!!(L9.indexOf(e)>-1||/[A-Z]/u.test(e))}function M9(e,t,n,{latestValues:r},o,l=!1,u){const f=(u??nx(e)?D9:I9)(t,r,o,e),p=R9(t,typeof e=="string",l),m=e!==A.Fragment?{...p,...f,ref:n}:{},{children:g}=t,y=A.useMemo(()=>Wt(g)?g.get():g,[g]);return A.createElement(e,{...m,children:y})}function F9({scrapeMotionValuesFromProps:e,createRenderState:t},n,r,o){return{latestValues:U9(n,r,o,e),renderState:t()}}function U9(e,t,n,r){const o={},l=r(e,{});for(const y in l)o[y]=Ac(l[y]);let{initial:u,animate:d}=e;const f=Nd(e),p=VI(e);t&&p&&!f&&e.inherit!==!1&&(u===void 0&&(u=t.initial),d===void 0&&(d=t.animate));let m=n?n.initial===!1:!1;m=m||u===!1;const g=m?d:u;if(g&&typeof g!="boolean"&&!Rd(g)){const y=Array.isArray(g)?g:[g];for(let E=0;E<y.length;E++){const v=Hv(e,y[E]);if(v){const{transitionEnd:T,transition:k,...w}=v;for(const C in w){let _=w[C];if(Array.isArray(_)){const L=m?_.length-1:0;_=_[L]}_!==null&&(o[C]=_)}for(const C in T)o[C]=T[C]}}}return o}const w1=e=>(t,n)=>{const r=A.useContext(_d),o=A.useContext(kd),l=()=>F9(e,t,r,o);return n?l():Rv(l)},B9=w1({scrapeMotionValuesFromProps:Jv,createRenderState:tx}),P9=w1({scrapeMotionValuesFromProps:r1,createRenderState:x1}),j9=Symbol.for("motionComponentSymbol");function z9(e,t,n){const r=A.useRef(n);A.useInsertionEffect(()=>{r.current=n});const o=A.useRef(null);return A.useCallback(l=>{l&&e.onMount?.(l),t&&(l?t.mount(l):t.unmount());const u=r.current;if(typeof u=="function")if(l){const d=u(l);typeof d=="function"&&(o.current=d)}else o.current?(o.current(),o.current=null):u(l);else u&&(u.current=l)},[t])}const T1=A.createContext({});function go(e){return e&&typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function G9(e,t,n,r,o,l){const{visualElement:u}=A.useContext(_d),d=A.useContext(y1),f=A.useContext(kd),p=A.useContext(ex),m=p.reducedMotion,g=p.skipAnimations,y=A.useRef(null),E=A.useRef(!1);r=r||d.renderer,!y.current&&r&&(y.current=r(e,{visualState:t,parent:u,props:n,presenceContext:f,blockInitialAnimation:f?f.initial===!1:!1,reducedMotionConfig:m,skipAnimations:g,isSVG:l}),E.current&&y.current&&(y.current.manuallyAnimateOnMount=!0));const v=y.current,T=A.useContext(T1);v&&!v.projection&&o&&(v.type==="html"||v.type==="svg")&&$9(y.current,n,o,T);const k=A.useRef(!1);A.useInsertionEffect(()=>{v&&k.current&&v.update(n,f)});const w=n[II],C=A.useRef(!!w&&!window.MotionHandoffIsComplete?.(w)&&window.MotionHasOptimisedAnimation?.(w));return VO(()=>{E.current=!0,v&&(k.current=!0,window.MotionIsMounted=!0,v.updateFeatures(),v.scheduleRenderMicrotask(),C.current&&v.animationState&&v.animationState.animateChanges())}),A.useEffect(()=>{v&&(!C.current&&v.animationState&&v.animationState.animateChanges(),C.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(w)}),C.current=!1),v.enteringChildren=void 0)}),v}function $9(e,t,n,r){const{layoutId:o,layout:l,drag:u,dragConstraints:d,layoutScroll:f,layoutRoot:p,layoutCrossfade:m}=t;e.projection=new n(e.latestValues,t["data-framer-portal-id"]?void 0:A1(e.parent)),e.projection.setOptions({layoutId:o,layout:l,alwaysMeasureLayout:!!u||d&&go(d),visualElement:e,animationType:typeof l=="string"?l:"both",initialPromotionConfig:r,crossfade:m,layoutScroll:f,layoutRoot:p})}function A1(e){if(e)return e.options.allowProjection!==!1?e.projection:A1(e.parent)}function Lm(e,{forwardMotionProps:t=!1,type:n}={},r,o){r&&T9(r);const l=n?n==="svg":nx(e),u=l?P9:B9;function d(p,m){let g;const y={...A.useContext(ex),...p,layoutId:H9(p)},{isStatic:E}=y,v=_9(p),T=u(p,E);if(!E&&HO){V9();const k=q9(y);g=k.MeasureLayout,v.visualElement=G9(e,T,y,o,k.ProjectionNode,l)}return S.jsxs(_d.Provider,{value:v,children:[g&&v.visualElement?S.jsx(g,{visualElement:v.visualElement,...y}):null,M9(e,p,z9(T,v.visualElement,m),T,E,t,l)]})}d.displayName=`motion.${typeof e=="string"?e:`create(${e.displayName??e.name??""})`}`;const f=A.forwardRef(d);return f[j9]=e,f}function H9({layoutId:e}){const t=A.useContext(kv).id;return t&&e!==void 0?t+"-"+e:e}function V9(e,t){A.useContext(y1).strict}function q9(e){const t=E1(),{drag:n,layout:r}=t;if(!n&&!r)return{};const o={...n,...r};return{MeasureLayout:n?.isEnabled(e)||r?.isEnabled(e)?o.MeasureLayout:void 0,ProjectionNode:o.ProjectionNode}}function Y9(e,t){if(typeof Proxy>"u")return Lm;const n=new Map,r=(l,u)=>Lm(l,u,e,t),o=(l,u)=>r(l,u);return new Proxy(o,{get:(l,u)=>u==="create"?r:(n.has(u)||n.set(u,Lm(u,void 0,e,t)),n.get(u))})}const W9=(e,t)=>t.isSVG??nx(e)?new k8(t):new S8(t,{allowProjection:e!==A.Fragment});class K9 extends Dr{constructor(t){super(t),t.animationState||(t.animationState=O8(t))}updateAnimationControlsSubscription(){const{animate:t}=this.node.getProps();Rd(t)&&(this.unmountControls=t.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:t}=this.node.getProps(),{animate:n}=this.node.prevProps||{};t!==n&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let X9=0;class Z9 extends Dr{constructor(){super(...arguments),this.id=X9++}update(){if(!this.node.presenceContext)return;const{isPresent:t,onExitComplete:n}=this.node.presenceContext,{isPresent:r}=this.node.prevPresenceContext||{};if(!this.node.animationState||t===r)return;const o=this.node.animationState.setActive("exit",!t);n&&!t&&o.then(()=>{n(this.id)})}mount(){const{register:t,onExitComplete:n}=this.node.presenceContext||{};n&&n(this.id),t&&(this.unmount=t(this.id))}unmount(){}}const Q9={animation:{Feature:K9},exit:{Feature:Z9}};function Dl(e){return{point:{x:e.pageX,y:e.pageY}}}const J9=e=>t=>Wv(t)&&e(t,Dl(t));function el(e,t,n,r){return ml(e,t,J9(n),r)}const k1=({current:e})=>e?e.ownerDocument.defaultView:null,VN=(e,t)=>Math.abs(e-t);function eY(e,t){const n=VN(e.x,t.x),r=VN(e.y,t.y);return Math.sqrt(n**2+r**2)}const qN=new Set(["auto","scroll"]);class R1{constructor(t,n,{transformPagePoint:r,contextWindow:o=window,dragSnapToOrigin:l=!1,distanceThreshold:u=3,element:d}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.removeScrollListeners=null,this.onElementScroll=E=>{this.handleScroll(E.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const E=Fm(this.lastMoveEventInfo,this.history),v=this.startEvent!==null,T=eY(E.offset,{x:0,y:0})>=this.distanceThreshold;if(!v&&!T)return;const{point:k}=E,{timestamp:w}=jt;this.history.push({...k,timestamp:w});const{onStart:C,onMove:_}=this.handlers;v||(C&&C(this.lastMoveEvent,E),this.startEvent=this.lastMoveEvent),_&&_(this.lastMoveEvent,E)},this.handlePointerMove=(E,v)=>{this.lastMoveEvent=E,this.lastMoveEventInfo=Mm(v,this.transformPagePoint),it.update(this.updatePoint,!0)},this.handlePointerUp=(E,v)=>{this.end();const{onEnd:T,onSessionEnd:k,resumeAnimation:w}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&w&&w(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const C=Fm(E.type==="pointercancel"?this.lastMoveEventInfo:Mm(v,this.transformPagePoint),this.history);this.startEvent&&T&&T(E,C),k&&k(E,C)},!Wv(t))return;this.dragSnapToOrigin=l,this.handlers=n,this.transformPagePoint=r,this.distanceThreshold=u,this.contextWindow=o||window;const f=Dl(t),p=Mm(f,this.transformPagePoint),{point:m}=p,{timestamp:g}=jt;this.history=[{...m,timestamp:g}];const{onSessionStart:y}=n;y&&y(t,Fm(p,this.history)),this.removeListeners=Cl(el(this.contextWindow,"pointermove",this.handlePointerMove),el(this.contextWindow,"pointerup",this.handlePointerUp),el(this.contextWindow,"pointercancel",this.handlePointerUp)),d&&this.startScrollTracking(d)}startScrollTracking(t){let n=t.parentElement;for(;n;){const r=getComputedStyle(n);(qN.has(r.overflowX)||qN.has(r.overflowY))&&this.scrollPositions.set(n,{x:n.scrollLeft,y:n.scrollTop}),n=n.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(t){const n=this.scrollPositions.get(t);if(!n)return;const r=t===window,o=r?{x:window.scrollX,y:window.scrollY}:{x:t.scrollLeft,y:t.scrollTop},l={x:o.x-n.x,y:o.y-n.y};l.x===0&&l.y===0||(r?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=l.x,this.lastMoveEventInfo.point.y+=l.y):this.history.length>0&&(this.history[0].x-=l.x,this.history[0].y-=l.y),this.scrollPositions.set(t,o),it.update(this.updatePoint,!0))}updateHandlers(t){this.handlers=t}end(){this.removeListeners&&this.removeListeners(),this.removeScrollListeners&&this.removeScrollListeners(),this.scrollPositions.clear(),_r(this.updatePoint)}}function Mm(e,t){return t?{point:t(e.point)}:e}function YN(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Fm({point:e},t){return{point:e,delta:YN(e,N1(t)),offset:YN(e,tY(t)),velocity:nY(t,.1)}}function tY(e){return e[0]}function N1(e){return e[e.length-1]}function nY(e,t){if(e.length<2)return{x:0,y:0};let n=e.length-1,r=null;const o=N1(e);for(;n>=0&&(r=e[n],!(o.timestamp-r.timestamp>Xn(t)));)n--;if(!r)return{x:0,y:0};r===e[0]&&e.length>2&&o.timestamp-r.timestamp>Xn(t)*2&&(r=e[1]);const l=Pn(o.timestamp-r.timestamp);if(l===0)return{x:0,y:0};const u={x:(o.x-r.x)/l,y:(o.y-r.y)/l};return u.x===1/0&&(u.x=0),u.y===1/0&&(u.y=0),u}function aY(e,{min:t,max:n},r){return t!==void 0&&e<t?e=r?ut(t,e,r.min):Math.max(e,t):n!==void 0&&e>n&&(e=r?ut(n,e,r.max):Math.min(e,n)),e}function WN(e,t,n){return{min:t!==void 0?e.min+t:void 0,max:n!==void 0?e.max+n-(e.max-e.min):void 0}}function rY(e,{top:t,left:n,bottom:r,right:o}){return{x:WN(e.x,n,o),y:WN(e.y,t,r)}}function KN(e,t){let n=t.min-e.min,r=t.max-e.max;return t.max-t.min<e.max-e.min&&([n,r]=[r,n]),{min:n,max:r}}function iY(e,t){return{x:KN(e.x,t.x),y:KN(e.y,t.y)}}function oY(e,t){let n=.5;const r=nn(e),o=nn(t);return o>r?n=cl(t.min,t.max-r,e.min):r>o&&(n=cl(e.min,e.max-o,t.min)),ha(0,1,n)}function sY(e,t){const n={};return t.min!==void 0&&(n.min=t.min-e.min),t.max!==void 0&&(n.max=t.max-e.min),n}const Dg=.35;function lY(e=Dg){return e===!1?e=0:e===!0&&(e=Dg),{x:XN(e,"left","right"),y:XN(e,"top","bottom")}}function XN(e,t,n){return{min:ZN(e,t),max:ZN(e,n)}}function ZN(e,t){return typeof e=="number"?e:e[t]||0}const uY=new WeakMap;class cY{constructor(t){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=Rt(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=t}start(t,{snapToCursor:n=!1,distanceThreshold:r}={}){const{presenceContext:o}=this.visualElement;if(o&&o.isPresent===!1)return;const l=g=>{n&&this.snapToCursor(Dl(g).point),this.stopAnimation()},u=(g,y)=>{const{drag:E,dragPropagation:v,onDragStart:T}=this.getProps();if(E&&!v&&(this.openDragLock&&this.openDragLock(),this.openDragLock=Pq(E),!this.openDragLock))return;this.latestPointerEvent=g,this.latestPanInfo=y,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints(),this.visualElement.projection&&(this.visualElement.projection.isAnimationBlocked=!0,this.visualElement.projection.target=void 0),ua(w=>{let C=this.getAxisMotionValue(w).get()||0;if(fa.test(C)){const{projection:_}=this.visualElement;if(_&&_.layout){const L=_.layout.layoutBox[w];L&&(C=nn(L)*(parseFloat(C)/100))}}this.originPoint[w]=C}),T&&it.update(()=>T(g,y),!1,!0),Tg(this.visualElement,"transform");const{animationState:k}=this.visualElement;k&&k.setActive("whileDrag",!0)},d=(g,y)=>{this.latestPointerEvent=g,this.latestPanInfo=y;const{dragPropagation:E,dragDirectionLock:v,onDirectionLock:T,onDrag:k}=this.getProps();if(!E&&!this.openDragLock)return;const{offset:w}=y;if(v&&this.currentDirection===null){this.currentDirection=pY(w),this.currentDirection!==null&&T&&T(this.currentDirection);return}this.updateAxis("x",y.point,w),this.updateAxis("y",y.point,w),this.visualElement.render(),k&&it.update(()=>k(g,y),!1,!0)},f=(g,y)=>{this.latestPointerEvent=g,this.latestPanInfo=y,this.stop(g,y),this.latestPointerEvent=null,this.latestPanInfo=null},p=()=>{const{dragSnapToOrigin:g}=this.getProps();(g||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:m}=this.getProps();this.panSession=new R1(t,{onSessionStart:l,onStart:u,onMove:d,onSessionEnd:f,resumeAnimation:p},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:m,distanceThreshold:r,contextWindow:k1(this.visualElement),element:this.visualElement.current})}stop(t,n){const r=t||this.latestPointerEvent,o=n||this.latestPanInfo,l=this.isDragging;if(this.cancel(),!l||!o||!r)return;const{velocity:u}=o;this.startAnimation(u);const{onDragEnd:d}=this.getProps();d&&it.postRender(()=>d(r,o))}cancel(){this.isDragging=!1;const{projection:t,animationState:n}=this.visualElement;t&&(t.isAnimationBlocked=!1),this.endPanSession();const{dragPropagation:r}=this.getProps();!r&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),n&&n.setActive("whileDrag",!1)}endPanSession(){this.panSession&&this.panSession.end(),this.panSession=void 0}updateAxis(t,n,r){const{drag:o}=this.getProps();if(!r||!fc(t,o,this.currentDirection))return;const l=this.getAxisMotionValue(t);let u=this.originPoint[t]+r[t];this.constraints&&this.constraints[t]&&(u=aY(u,this.constraints[t],this.elastic[t])),l.set(u)}resolveConstraints(){const{dragConstraints:t,dragElastic:n}=this.getProps(),r=this.visualElement.projection&&!this.visualElement.projection.layout?this.visualElement.projection.measure(!1):this.visualElement.projection?.layout,o=this.constraints;t&&go(t)?this.constraints||(this.constraints=this.resolveRefConstraints()):t&&r?this.constraints=rY(r.layoutBox,t):this.constraints=!1,this.elastic=lY(n),o!==this.constraints&&!go(t)&&r&&this.constraints&&!this.hasMutatedConstraints&&ua(l=>{this.constraints!==!1&&this.getAxisMotionValue(l)&&(this.constraints[l]=sY(r.layoutBox[l],this.constraints[l]))})}resolveRefConstraints(){const{dragConstraints:t,onMeasureDragConstraints:n}=this.getProps();if(!t||!go(t))return!1;const r=t.current,{projection:o}=this.visualElement;if(!o||!o.layout)return!1;const l=m8(r,o.root,this.visualElement.getTransformPagePoint());let u=iY(o.layout.layoutBox,l);if(n){const d=n(d8(u));this.hasMutatedConstraints=!!d,d&&(u=KI(d))}return u}startAnimation(t){const{drag:n,dragMomentum:r,dragElastic:o,dragTransition:l,dragSnapToOrigin:u,onDragTransitionEnd:d}=this.getProps(),f=this.constraints||{},p=ua(m=>{if(!fc(m,n,this.currentDirection))return;let g=f&&f[m]||{};u&&(g={min:0,max:0});const y=o?200:1e6,E=o?40:1e7,v={type:"inertia",velocity:r?t[m]:0,bounceStiffness:y,bounceDamping:E,timeConstant:750,restDelta:1,restSpeed:10,...l,...g};return this.startAxisValueAnimation(m,v)});return Promise.all(p).then(d)}startAxisValueAnimation(t,n){const r=this.getAxisMotionValue(t);return Tg(this.visualElement,t),r.start($v(t,r,0,n,this.visualElement,!1))}stopAnimation(){ua(t=>this.getAxisMotionValue(t).stop())}getAxisMotionValue(t){const n=`_drag${t.toUpperCase()}`,r=this.visualElement.getProps(),o=r[n];return o||this.visualElement.getValue(t,(r.initial?r.initial[t]:void 0)||0)}snapToCursor(t){ua(n=>{const{drag:r}=this.getProps();if(!fc(n,r,this.currentDirection))return;const{projection:o}=this.visualElement,l=this.getAxisMotionValue(n);if(o&&o.layout){const{min:u,max:d}=o.layout.layoutBox[n],f=l.get()||0;l.set(t[n]-ut(u,d,.5)+f)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:t,dragConstraints:n}=this.getProps(),{projection:r}=this.visualElement;if(!go(n)||!r||!this.constraints)return;this.stopAnimation();const o={x:0,y:0};ua(u=>{const d=this.getAxisMotionValue(u);if(d&&this.constraints!==!1){const f=d.get();o[u]=oY({min:f,max:f},this.constraints[u])}});const{transformTemplate:l}=this.visualElement.getProps();this.visualElement.current.style.transform=l?l({},""):"none",r.root&&r.root.updateScroll(),r.updateLayout(),this.constraints=!1,this.resolveConstraints(),ua(u=>{if(!fc(u,t,null))return;const d=this.getAxisMotionValue(u),{min:f,max:p}=this.constraints[u];d.set(ut(f,p,o[u]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;uY.set(this.visualElement,this);const t=this.visualElement.current,n=el(t,"pointerdown",p=>{const{drag:m,dragListener:g=!0}=this.getProps(),y=p.target,E=y!==t&&Vq(y);m&&g&&!E&&this.start(p)});let r;const o=()=>{const{dragConstraints:p}=this.getProps();go(p)&&p.current&&(this.constraints=this.resolveRefConstraints(),r||(r=dY(t,p.current,()=>this.scalePositionWithinConstraints())))},{projection:l}=this.visualElement,u=l.addEventListener("measure",o);l&&!l.layout&&(l.root&&l.root.updateScroll(),l.updateLayout()),it.read(o);const d=ml(window,"resize",()=>this.scalePositionWithinConstraints()),f=l.addEventListener("didUpdate",(({delta:p,hasLayoutChanged:m})=>{this.isDragging&&m&&(ua(g=>{const y=this.getAxisMotionValue(g);y&&(this.originPoint[g]+=p[g].translate,y.set(y.get()+p[g].translate))}),this.visualElement.render())}));return()=>{d(),n(),u(),f&&f(),r&&r()}}getProps(){const t=this.visualElement.getProps(),{drag:n=!1,dragDirectionLock:r=!1,dragPropagation:o=!1,dragConstraints:l=!1,dragElastic:u=Dg,dragMomentum:d=!0}=t;return{...t,drag:n,dragDirectionLock:r,dragPropagation:o,dragConstraints:l,dragElastic:u,dragMomentum:d}}}function QN(e){let t=!0;return()=>{if(t){t=!1;return}e()}}function dY(e,t,n){const r=iN(e,QN(n)),o=iN(t,QN(n));return()=>{r(),o()}}function fc(e,t,n){return(t===!0||t===e)&&(n===null||n===e)}function pY(e,t=10){let n=null;return Math.abs(e.y)>t?n="y":Math.abs(e.x)>t&&(n="x"),n}class fY extends Dr{constructor(t){super(t),this.removeGroupControls=zn,this.removeListeners=zn,this.controls=new cY(t)}mount(){const{dragControls:t}=this.node.getProps();t&&(this.removeGroupControls=t.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||zn}update(){const{dragControls:t}=this.node.getProps(),{dragControls:n}=this.node.prevProps||{};t!==n&&(this.removeGroupControls(),t&&(this.removeGroupControls=t.subscribe(this.controls)))}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}}const Um=e=>(t,n)=>{e&&it.update(()=>e(t,n),!1,!0)};class mY extends Dr{constructor(){super(...arguments),this.removePointerDownListener=zn}onPointerDown(t){this.session=new R1(t,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:k1(this.node)})}createPanHandlers(){const{onPanSessionStart:t,onPanStart:n,onPan:r,onPanEnd:o}=this.node.getProps();return{onSessionStart:Um(t),onStart:Um(n),onMove:Um(r),onEnd:(l,u)=>{delete this.session,o&&it.postRender(()=>o(l,u))}}}mount(){this.removePointerDownListener=el(this.node.current,"pointerdown",t=>this.onPointerDown(t))}update(){this.session&&this.session.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session&&this.session.end()}}let Bm=!1;class gY extends A.Component{componentDidMount(){const{visualElement:t,layoutGroup:n,switchLayoutGroup:r,layoutId:o}=this.props,{projection:l}=t;l&&(n.group&&n.group.add(l),r&&r.register&&o&&r.register(l),Bm&&l.root.didUpdate(),l.addEventListener("animationComplete",()=>{this.safeToRemove()}),l.setOptions({...l.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),kc.hasEverUpdated=!0}getSnapshotBeforeUpdate(t){const{layoutDependency:n,visualElement:r,drag:o,isPresent:l}=this.props,{projection:u}=r;return u&&(u.isPresent=l,t.layoutDependency!==n&&u.setOptions({...u.options,layoutDependency:n}),Bm=!0,o||t.layoutDependency!==n||n===void 0||t.isPresent!==l?u.willUpdate():this.safeToRemove(),t.isPresent!==l&&(l?u.promote():u.relegate()||it.postRender(()=>{const d=u.getStack();(!d||!d.members.length)&&this.safeToRemove()}))),null}componentDidUpdate(){const{projection:t}=this.props.visualElement;t&&(t.root.didUpdate(),Yv.postRender(()=>{!t.currentAnimation&&t.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:t,layoutGroup:n,switchLayoutGroup:r}=this.props,{projection:o}=t;Bm=!0,o&&(o.scheduleCheckAfterUnmount(),n&&n.group&&n.group.remove(o),r&&r.deregister&&r.deregister(o))}safeToRemove(){const{safeToRemove:t}=this.props;t&&t()}render(){return null}}function _1(e){const[t,n]=b1(),r=A.useContext(kv);return S.jsx(gY,{...e,layoutGroup:r,switchLayoutGroup:A.useContext(T1),isPresent:t,safeToRemove:n})}const hY={pan:{Feature:mY},drag:{Feature:fY,ProjectionNode:h1,MeasureLayout:_1}};function JN(e,t,n){const{props:r}=e;e.animationState&&r.whileHover&&e.animationState.setActive("whileHover",n==="Start");const o="onHover"+n,l=r[o];l&&it.postRender(()=>l(t,Dl(t)))}class bY extends Dr{mount(){const{current:t}=this.node;t&&(this.unmount=zq(t,(n,r)=>(JN(this.node,r,"Start"),o=>JN(this.node,o,"End"))))}unmount(){}}class yY extends Dr{constructor(){super(...arguments),this.isActive=!1}onFocus(){let t=!1;try{t=this.node.current.matches(":focus-visible")}catch{t=!0}!t||!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=Cl(ml(this.node.current,"focus",()=>this.onFocus()),ml(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function e_(e,t,n){const{props:r}=e;if(e.current instanceof HTMLButtonElement&&e.current.disabled)return;e.animationState&&r.whileTap&&e.animationState.setActive("whileTap",n==="Start");const o="onTap"+(n==="End"?"":n),l=r[o];l&&it.postRender(()=>l(t,Dl(t)))}class EY extends Dr{mount(){const{current:t}=this.node;if(!t)return;const{globalTapTarget:n,propagate:r}=this.node.props;this.unmount=Yq(t,(o,l)=>(e_(this.node,l,"Start"),(u,{success:d})=>e_(this.node,u,d?"End":"Cancel")),{useGlobalTarget:n,stopPropagation:r?.tap===!1})}unmount(){}}const Lg=new WeakMap,Pm=new WeakMap,SY=e=>{const t=Lg.get(e.target);t&&t(e)},vY=e=>{e.forEach(SY)};function xY({root:e,...t}){const n=e||document;Pm.has(n)||Pm.set(n,{});const r=Pm.get(n),o=JSON.stringify(t);return r[o]||(r[o]=new IntersectionObserver(vY,{root:e,...t})),r[o]}function wY(e,t,n){const r=xY(t);return Lg.set(e,n),r.observe(e),()=>{Lg.delete(e),r.unobserve(e)}}const TY={some:0,all:1};class AY extends Dr{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:t={}}=this.node.getProps(),{root:n,margin:r,amount:o="some",once:l}=t,u={root:n?n.current:void 0,rootMargin:r,threshold:typeof o=="number"?o:TY[o]},d=f=>{const{isIntersecting:p}=f;if(this.isInView===p||(this.isInView=p,l&&!p&&this.hasEnteredView))return;p&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",p);const{onViewportEnter:m,onViewportLeave:g}=this.node.getProps(),y=p?m:g;y&&y(f)};return wY(this.node.current,u,d)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:t,prevProps:n}=this.node;["amount","margin","root"].some(kY(t,n))&&this.startObserver()}unmount(){}}function kY({viewport:e={}},{viewport:t={}}={}){return n=>e[n]!==t[n]}const RY={inView:{Feature:AY},tap:{Feature:EY},focus:{Feature:yY},hover:{Feature:bY}},NY={layout:{ProjectionNode:h1,MeasureLayout:_1}},_Y={...Q9,...RY,...hY,...NY},ui=Y9(_Y,W9);function CY({images:e,index:t,onClose:n,onNavigate:r}){const o=A.useCallback(()=>{t>0&&r(t-1)},[t,r]),l=A.useCallback(()=>{t<e.length-1&&r(t+1)},[t,e.length,r]);return A.useEffect(()=>{const u=d=>{d.key==="Escape"&&n(),d.key==="ArrowLeft"&&o(),d.key==="ArrowRight"&&l()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n,o,l]),S.jsx(qc,{children:S.jsxs(ui.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/90",onClick:n,children:[S.jsx("button",{onClick:n,className:"absolute top-4 right-4 z-10 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-white",children:S.jsx(Kc,{className:"h-5 w-5"})}),e.length>1&&S.jsxs("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 text-white/70 text-sm tabular-nums",children:[t+1," / ",e.length]}),t>0&&S.jsx("button",{onClick:u=>{u.stopPropagation(),o()},className:"absolute left-3 top-1/2 -translate-y-1/2 z-10 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-white",children:S.jsx(gM,{className:"h-6 w-6"})}),t<e.length-1&&S.jsx("button",{onClick:u=>{u.stopPropagation(),l()},className:"absolute right-3 top-1/2 -translate-y-1/2 z-10 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-white",children:S.jsx(bM,{className:"h-6 w-6"})}),S.jsx("img",{src:e[t],alt:"",className:"max-h-[85vh] max-w-[90vw] object-contain rounded-lg",onClick:u=>u.stopPropagation()})]})})}function OY({messages:e,streaming:t,streamBuffer:n,tools:r}){const o=A.useRef(null),[l,u]=A.useState(null),d=A.useCallback((m,g)=>{u({images:m,index:g})},[]);A.useEffect(()=>{o.current?.scrollIntoView({behavior:"smooth"})},[e,n,r,t]);const f=r.length>0?r[r.length-1]:null,p=f?.status==="running"?f.name:void 0;return S.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-4 flex flex-col min-h-0",children:[S.jsx("div",{className:"flex-1"}),e.length===0&&!t&&S.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-sm",children:"Start a conversation"}),S.jsxs("div",{className:"space-y-3",children:[e.map(m=>S.jsx(L5,{role:m.role,content:m.content,timestamp:m.timestamp,hasAttachments:m.hasAttachments,audioData:m.audioData,attachments:m.attachments,onImageClick:d},m.id)),t&&S.jsx(F5,{text:n,toolName:p})]}),S.jsx("div",{ref:o}),l&&S.jsx(CY,{images:l.images,index:l.index,onClose:()=>u(null),onNavigate:m=>u(g=>g?{...g,index:m}:null)})]})}function IY(e){const t=Math.floor(e/60),n=e%60;return`${t}:${n.toString().padStart(2,"0")}`}function DY(e,t=4*1024*1024){return new Promise(n=>{const r=new Image;r.onload=()=>{let{width:l,height:u}=r;if(l>1600||u>1600){const p=Math.min(1600/l,1600/u);l=Math.round(l*p),u=Math.round(u*p)}const d=document.createElement("canvas");d.width=l,d.height=u,d.getContext("2d").drawImage(r,0,0,l,u);for(const p of[.8,.6,.4,.3]){const m=d.toDataURL("image/jpeg",p);if(Math.round((m.length-23)*.75)<=t){n(m);return}}n(d.toDataURL("image/jpeg",.2))},r.onerror=()=>n(e),r.src=e})}function LY({onSend:e,onStop:t,streaming:n,whisperEnabled:r}){const[o,l]=A.useState(""),[u,d]=A.useState([]),[f,p]=A.useState(!1),[m,g]=A.useState(0),E=o.trim().length>0||u.length>0,v=A.useRef(null),T=A.useRef(null),k=A.useRef(null),w=A.useRef(null),C=A.useRef(null),_=A.useRef(0),L=A.useRef(0),F=A.useRef(null),D=A.useRef(!1),z=A.useRef(null),B=A.useRef(null),W=A.useRef([]),U=A.useRef(null);A.useEffect(()=>{const R=v.current;R&&(R.style.height="0px",R.style.height=`${Math.min(R.scrollHeight,88)}px`)},[o]),A.useEffect(()=>{if(f)return z.current=setInterval(()=>g(R=>R+1),1e3),()=>{z.current&&clearInterval(z.current)}},[f]);const X=A.useCallback(R=>{z.current&&clearInterval(z.current),F.current&&(clearTimeout(F.current),F.current=null),D.current=!1;const M=B.current,H=U.current;R||!M||M.state==="inactive"?(H?.getTracks().forEach(I=>I.stop()),B.current=null,U.current=null,W.current=[]):(M.onstop=async()=>{H?.getTracks().forEach(ue=>ue.stop());const I=new Blob(W.current,{type:"audio/webm"});if(W.current=[],B.current=null,U.current=null,I.size<1e3)return;const ce=new FileReader;ce.onloadend=async()=>{const ue=ce.result,de=ue.split(",")[1];if(de)try{const ke=await(await fetch("/api/whisper/transcribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio:de})})).json();ke.transcript?.trim()&&e(ke.transcript.trim(),void 0,ue)}catch{}},ce.readAsDataURL(I)},M.stop()),C.current&&(C.current.style.transform=""),p(!1),g(0),L.current=0},[e]),Q=A.useCallback(R=>{const M=R.type.startsWith("image/"),H=R.type==="application/pdf";if(!M&&!H)return;const I=new FileReader;I.onload=async ce=>{let ue=ce.target?.result;M&&(ue=await DY(ue)),d(de=>[...de,{id:Math.random().toString(36).slice(2),type:M?"image":"file",name:R.name,preview:ue}])},I.readAsDataURL(R)},[]),te=A.useCallback(R=>{const M=R.target.files;if(M){for(let H=0;H<M.length;H++)Q(M[H]);R.target.value=""}},[Q]),ie=A.useCallback(R=>{d(M=>M.filter(H=>H.id!==R))},[]);A.useEffect(()=>{const R=M=>{if(M.clipboardData?.items){for(const H of M.clipboardData.items)if(H.type.startsWith("image/")){M.preventDefault();const I=H.getAsFile();I&&Q(I)}}};return document.addEventListener("paste",R),()=>document.removeEventListener("paste",R)},[Q]);const ee=()=>{E&&(e(o,u.length>0?u:void 0),l(""),d([]),requestAnimationFrame(()=>v.current?.focus()))},j=A.useCallback(R=>{R.preventDefault(),_.current=R.clientX,L.current=0,R.currentTarget.setPointerCapture(R.pointerId),F.current=setTimeout(async()=>{if(r)try{const M=await navigator.mediaDevices.getUserMedia({audio:!0});U.current=M;const H=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":"audio/webm",I=new MediaRecorder(M,{mimeType:H});W.current=[],I.ondataavailable=ce=>{ce.data.size>0&&W.current.push(ce.data)},B.current=I,I.start(),D.current=!0,p(!0),g(0)}catch{}},200)},[]),V=A.useCallback(R=>{if(!D.current)return;const M=Math.min(0,R.clientX-_.current);if(L.current=M,C.current&&(C.current.style.transform=`translateX(${M}px)`),w.current){const H=w.current.getBoundingClientRect(),I=H.left+H.width/2;Math.abs(R.clientX-I)<36&&X(!0)}},[X]),Z=A.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null),D.current&&X(!1)},[X]),ne=A.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null),D.current&&X(!0)},[X]);return S.jsxs("div",{className:"shrink-0 p-3 relative",children:[S.jsxs("div",{className:`flex flex-col transition-opacity duration-100 ${f?"opacity-0 pointer-events-none":"opacity-100"}`,children:[S.jsx(qc,{children:u.length>0&&S.jsx(ui.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:S.jsx("div",{className:"flex gap-2 px-3 pt-2.5 pb-2 flex-wrap bg-white/[0.04] border border-white/[0.08] rounded-2xl mb-2",children:u.map(R=>S.jsxs("div",{className:"relative group flex-shrink-0",children:[R.type==="image"?S.jsx("img",{src:R.preview,alt:R.name,className:"w-14 h-14 rounded-lg object-cover border border-white/10"}):S.jsxs("div",{className:"w-14 h-14 rounded-lg bg-white/5 border border-white/10 flex flex-col items-center justify-center gap-0.5 px-1",children:[S.jsx("svg",{className:"w-5 h-5 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:S.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),S.jsx("span",{className:"text-[8px] text-muted-foreground truncate w-full text-center",children:R.name.split(".").pop()})]}),S.jsx("button",{onClick:()=>ie(R.id),className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-black/80 border border-white/20 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:S.jsx(Kc,{className:"w-2.5 h-2.5 text-white"})})]},R.id))})})}),S.jsxs("div",{className:"flex items-end gap-2",children:[S.jsxs("div",{className:"flex-1 flex items-end bg-white rounded-2xl px-4",children:[S.jsx("textarea",{ref:v,value:o,onChange:R=>l(R.target.value),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 overflow-y-auto",style:{maxHeight:88}}),S.jsx("input",{ref:T,type:"file",className:"hidden",accept:"image/*,.pdf",multiple:!0,onChange:te}),S.jsx("input",{ref:k,type:"file",className:"hidden",accept:"image/*",capture:"environment",onChange:te}),S.jsx("button",{type:"button",onClick:()=>T.current?.click(),className:"shrink-0 p-1.5 mb-2 text-gray-400 hover:text-gray-600 transition-colors",children:S.jsx(zm,{className:"h-4 w-4"})}),S.jsx("button",{type:"button",onClick:()=>k.current?.click(),className:"shrink-0 p-1.5 mb-2 text-gray-400 hover:text-gray-600 transition-colors",children:S.jsx(dM,{className:"h-4 w-4"})})]}),n?S.jsx("button",{onClick:t,className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-destructive text-destructive-foreground transition-colors",children:S.jsx(XM,{className:"h-4 w-4"})}):E?S.jsx("button",{onClick:ee,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:S.jsx(VM,{className:"h-4 w-4"})}):S.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:j,onPointerMove:V,onPointerUp:Z,onPointerCancel:ne,children:S.jsx(jm,{className:"h-4 w-4"})})]})]}),S.jsx(qc,{children:f&&S.jsx(ui.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:S.jsxs("div",{className:"flex items-center w-full gap-2",children:[S.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[S.jsxs("span",{className:"relative flex h-2 w-2 shrink-0",children:[S.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-destructive opacity-75"}),S.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-destructive"})]}),S.jsx("span",{className:"text-sm font-medium tabular-nums",children:IY(m)})]}),S.jsxs("div",{className:"flex-1 flex items-center bg-muted rounded-full h-12 pl-1 pr-0.5",children:[S.jsx("div",{ref:w,className:"flex items-center justify-center h-9 w-9 shrink-0 rounded-full bg-destructive/10 text-destructive",children:S.jsx(u_,{className:"h-4 w-4"})}),S.jsx("div",{className:"flex-1 flex justify-center min-w-0",children:S.jsx(ui.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"})}),S.jsx("div",{ref:C,className:"shrink-0 touch-none select-none will-change-transform",style:{transition:"none"},onPointerDown:j,onPointerMove:V,onPointerUp:Z,onPointerCancel:ne,children:S.jsx("div",{className:"flex items-center justify-center h-11 w-11 rounded-full bg-destructive text-destructive-foreground",children:S.jsx(jm,{className:"h-5 w-5"})})})]})]})})})]})}function MY({ws:e,clearContextRef:t,whisperEnabled:n}){const{messages:r,streaming:o,streamBuffer:l,tools:u,sendMessage:d,stopStreaming:f,clearContext:p}=dz(e);return t&&(t.current=p),S.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[S.jsx(OY,{messages:r,streaming:o,streamBuffer:l,tools:u}),S.jsx(LY,{onSend:d,onStop:f,streaming:o,whisperEnabled:n})]})}function FY({onClick:e}){return S.jsx(ui.div,{className:"fixed bottom-6 right-6 z-50 cursor-pointer",whileHover:{scale:1.1},whileTap:{scale:.95},onClick:e,role:"button","aria-label":"Open Fluxy chat",children:S.jsx("video",{src:"/fluxy_tilts.webm",poster:"/fluxy_frame1.png",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-11 w-auto drop-shadow-lg pointer-events-none",draggable:!1})})}const UY=[{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}],BY={anthropic:[{id:"claude-opus-4-6",label:"Opus 4.6"},{id:"claude-sonnet-4-6",label:"Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",label:"Haiku 4.5"}],openai:[{id:"gpt-5.2-codex:medium",label:"GPT-5.2 Codex Medium"},{id:"gpt-5.2-codex:high",label:"GPT-5.2 Codex High"},{id:"gpt-5.2-codex:xhigh",label:"GPT-5.2 Codex Extra High"},{id:"gpt-5.3-codex:medium",label:"GPT-5.3 Codex Medium (Pro)"},{id:"gpt-5.3-codex:high",label:"GPT-5.3 Codex High (Pro)"},{id:"gpt-5.3-codex:xhigh",label:"GPT-5.3 Codex Extra High (Pro)"}],ollama:[{id:"llama3.2",label:"Llama 3.2"},{id:"mistral",label:"Mistral"},{id:"codellama",label:"Code Llama"},{id:"phi3",label:"Phi-3"}]},t_=6,n_=[{tier:"premium",label:e=>`${e}.fluxy.bot`,badge:"$5",badgeCls:"bg-[#AF27E3]/15 text-[#AF27E3] border-[#AF27E3]/20",highlight:!0},{tier:"at",label:e=>`${e}.at.fluxy.bot`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1}];function PY({models:e,value:t,onChange:n}){const[r,o]=A.useState(!1),l=A.useRef(null);A.useEffect(()=>{if(!r)return;const d=f=>{l.current&&!l.current.contains(f.target)&&o(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[r]);const u=e.find(d=>d.id===t);return S.jsxs("div",{className:"relative",ref:l,children:[S.jsxs("button",{type:"button",onClick:()=>o(d=>!d),className:"w-full flex items-center justify-between bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none hover:border-white/15 focus:border-[#AF27E3]/30 transition-colors",children:[S.jsx("span",{className:u?"text-white":"text-white/20",children:u?u.label:"Choose a model..."}),S.jsx(hl,{className:`h-4 w-4 text-white/30 transition-transform ${r?"rotate-180":""}`})]}),r&&S.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:e.map(d=>S.jsx("button",{onClick:()=>{n(d.id),o(!1)},className:`w-full text-left px-4 py-2 text-[13px] transition-colors ${t===d.id?"text-[#AF27E3] bg-[#AF27E3]/10":"text-white/70 hover:bg-white/[0.04] hover:text-white"}`,children:d.label},d.id))})]})}function jY({onComplete:e}){const[t,n]=A.useState(0),[r,o]=A.useState(""),[l,u]=A.useState("anthropic"),[d,f]=A.useState(""),[p,m]=A.useState(!1),[g,y]=A.useState({anthropic:"idle",openai:"idle",ollama:"connected"}),[E,v]=A.useState(!1),[T,k]=A.useState(""),[w,C]=A.useState(!1),[_,L]=A.useState(),[F,D]=A.useState(!1),[z,B]=A.useState(!1),[W,U]=A.useState(),[X,Q]=A.useState(""),[te,ie]=A.useState(""),[ee,j]=A.useState(null),[V,Z]=A.useState(""),[ne,R]=A.useState({}),[M,H]=A.useState("at"),[I,ce]=A.useState(!1),[ue,de]=A.useState(!1),[me,ke]=A.useState(""),Se=A.useRef(null),[We,mt]=A.useState(null),[gt,It]=A.useState(!1),[Dt,Sa]=A.useState(!1),[mn,Lr]=A.useState(""),[kn,Ya]=A.useState(""),[na,Mr]=A.useState(""),[Go,yi]=A.useState(!1),[ct,$o]=A.useState(!1),[oe,fe]=A.useState(""),[we,Ne]=A.useState(""),[ze,Ht]=A.useState(!1),[Rn,Nt]=A.useState(!1),[Ze,Lt]=A.useState(!1),[Le,Gn]=A.useState(""),Qt=A.useRef(!1),va=g[l]==="connected";A.useEffect(()=>{fetch("/api/onboard/status").then(re=>re.json()).then(re=>{re.userName&&o(re.userName),re.handle&&(ie(re.handle.username),H(re.handle.tier||"at"),mt({username:re.handle.username,tier:re.handle.tier,url:re.handle.url}),de(!0),ke(re.handle.url)),re.portalUser&&Lr(re.portalUser),re.portalConfigured&&$o(!0),re.provider&&u(re.provider),re.model&&f(re.model),re.whisperEnabled&&(Lt(!0),Gn(re.whisperKey||"")),Qt.current=!0}).catch(()=>{Qt.current=!0})},[]),A.useEffect(()=>{l!=="anthropic"||g.anthropic==="connected"||fetch("/api/auth/claude/status").then(re=>re.json()).then(re=>{re.authenticated&&y(Ae=>({...Ae,anthropic:"connected"}))}).catch(()=>{})},[l]),A.useEffect(()=>{l!=="openai"||g.openai==="connected"||fetch("/api/auth/codex/status").then(re=>re.json()).then(re=>{re.authenticated&&y(Ae=>({...Ae,openai:"connected"}))}).catch(()=>{})},[l]),A.useEffect(()=>{if(!z)return;const re=setInterval(async()=>{try{(await(await fetch("/api/auth/codex/status")).json()).authenticated&&(B(!1),y(Xa=>({...Xa,openai:"connected"})))}catch{}},2e3);return()=>clearInterval(re)},[z]),A.useEffect(()=>{if(Se.current&&clearTimeout(Se.current),!Qt.current||We&&ue&&te===We.username)return;j(null),Z(""),R({}),de(!1),ke("");const re=te.trim();if(re){if(re.length<3){j("invalid"),Z("At least 3 characters");return}return j("checking"),Se.current=setTimeout(async()=>{try{const Mt=await(await fetch(`/api/handle/check/${encodeURIComponent(re)}`)).json();if(!Mt.valid)j("invalid"),Z(Mt.error);else{const Xa={};for(const Ur of Mt.handles)Xa[Ur.tier]=Ur.available;R(Xa),j("ready");const Bl=n_.find(Ur=>Xa[Ur.tier]);Bl&&!Xa[M]&&H(Bl.tier)}}catch{j(null)}},400),()=>{Se.current&&clearTimeout(Se.current)}}},[te]);const Ei=re=>{ie(re.toLowerCase().replace(/[^a-z0-9-]/g,""))},Si=async()=>{if(!(!te||ee!=="ready"||!ne[M])){ce(!0);try{const Ae=await(await fetch("/api/handle/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:te,tier:M})})).json();Ae.ok?(de(!0),ke(Ae.url)):(Z(Ae.error||"Registration failed"),j("invalid"))}catch{Z("Could not reach server"),j("invalid")}finally{ce(!1)}}},vi=async()=>{if(!(!te||ee!=="ready"||!ne[M])){Sa(!0);try{const Ae=await(await fetch("/api/handle/change",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:te,tier:M})})).json();Ae.ok?(de(!0),ke(Ae.url),mt({username:te,tier:M,url:Ae.url}),It(!1)):(Z(Ae.error||"Handle change failed"),j("invalid"))}catch{Z("Could not reach server"),j("invalid")}finally{Sa(!1)}}},xa=re=>{l==="openai"&&re!=="openai"&&z&&(fetch("/api/auth/codex/cancel",{method:"POST"}),B(!1)),u(re),f(""),v(!1),k(""),L(void 0),B(!1),U(void 0)},xi=async()=>{L(void 0);try{const Ae=await(await fetch("/api/auth/claude/start",{method:"POST"})).json();Ae.success&&Ae.authUrl?(window.open(Ae.authUrl,"_blank"),v(!0)):L(Ae.error||"Failed to start authentication")}catch(re){L(re.message)}},Wa=async()=>{if(T.trim()){C(!0),L(void 0);try{const Ae=await(await fetch("/api/auth/claude/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:T.trim()})})).json();Ae.success?y(Mt=>({...Mt,anthropic:"connected"})):L(Ae.error||"Code exchange failed")}catch(re){L(re.message)}finally{C(!1)}}},Cd=async()=>{try{const re=await navigator.clipboard.readText();re&&k(re.trim())}catch{}},Ll=async()=>{D(!0),L(void 0);try{(await(await fetch("/api/auth/claude/status")).json()).authenticated?y(Mt=>({...Mt,anthropic:"connected"})):L("No active session found. Please authenticate first.")}catch{}finally{D(!1)}},Ho=async()=>{B(!0),U(void 0);try{const Ae=await(await fetch("/api/auth/codex/start",{method:"POST"})).json();Ae.success&&Ae.authUrl?window.open(Ae.authUrl,"_blank"):(B(!1),U(Ae.error||"Failed to start authentication"))}catch(re){B(!1),U(re.message)}},Fr=()=>{B(!1),fetch("/api/auth/codex/cancel",{method:"POST"})},Ml=kn===na,Vo=mn.trim().length>=3&&kn.length>=6&&Ml,Fl=ct?mn.trim().length>=3&&(kn.length===0||ze&&Vo):Vo,Ka=(()=>{switch(t){case 0:return!0;case 1:return r.trim().length>0;case 2:return ue;case 3:return Fl;case 4:return!!(l&&d&&va);case 5:return!0;default:return!1}})(),$n=()=>{Ka&&t<t_-1&&n(re=>re+1)},qo=()=>{t>0&&n(re=>re-1)},wi=re=>{re.key==="Enter"&&Ka&&$n()},Ul=async()=>{m(!0);try{await fetch("/api/onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userName:r.trim(),agentName:te.trim()||"Fluxy",provider:l,model:d,apiKey:"",baseUrl:l==="ollama"&&X||void 0,whisperEnabled:Ze,whisperKey:Ze?Le:"",portalUser:mn.trim(),portalPass:kn})}),e()}catch(re){console.error("Onboard failed:",re),m(!1)}},Vt="w-full bg-white/[0.05] border border-white/[0.08] text-white rounded-xl px-4 py-3 text-base outline-none input-glow placeholder:text-white/20 transition-all",yt="w-full bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none input-glow placeholder:text-white/20 transition-all";return S.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4",children:[S.jsx("div",{className:"absolute inset-0 bg-black/85 backdrop-blur-md"}),S.jsxs(ui.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:[S.jsx("div",{className:"flex justify-center gap-2 pt-6",children:Array.from({length:t_},(re,Ae)=>S.jsx("div",{className:`h-1.5 rounded-full transition-all duration-300 ${Ae===t?"w-7 bg-gradient-brand":Ae<t?"w-1.5 bg-gradient-brand opacity-60":"w-1.5 bg-white/10"}`},Ae))}),S.jsx(qc,{mode:"wait",children:S.jsxs(ui.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:[t===0&&S.jsxs("div",{className:"flex flex-col items-center text-center",children:[S.jsx("video",{src:"/fluxy_say_hi.webm",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-[180px] mb-4"}),S.jsx("h1",{className:"text-2xl font-bold text-white tracking-tight",children:"Welcome to Fluxy"}),S.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."}),S.jsxs("button",{onClick:$n,className:"mt-6 px-7 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center gap-2",children:["Get Started",S.jsx(sa,{className:"h-4 w-4"})]})]}),t===1&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"What's your name?"}),S.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"This is how your agent will address you."}),S.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[S.jsx("input",{type:"text",value:r,onChange:re=>o(re.target.value),onKeyDown:wi,placeholder:"Enter your name",autoFocus:!0,className:Vt+" flex-1"}),S.jsx("button",{onClick:$n,disabled:!Ka,className:"shrink-0 h-12 w-12 flex items-center justify-center rounded-full bg-gradient-brand hover:opacity-90 text-white transition-colors disabled:opacity-30",children:S.jsx(sa,{className:"h-5 w-5"})})]})]}),t===2&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Name your bot"}),S.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."}),We&&ue&&!gt&&S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"}),S.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Current handle"})]}),S.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:me})]}),S.jsxs("div",{className:"flex gap-2 mt-4",children:[S.jsxs("button",{onClick:$n,className:"flex-1 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]}),S.jsx("button",{onClick:()=>{It(!0),de(!1),ie(""),j(null),R({})},className:"px-5 py-3 bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 text-[13px] font-medium rounded-full transition-colors",children:"Change"})]})]}),gt&&!ue&&S.jsxs("div",{className:"mt-4 bg-amber-500/8 border border-amber-500/20 rounded-xl px-4 py-3",children:[S.jsx("p",{className:"text-amber-400/90 text-[13px] font-medium",children:"Changing your handle"}),S.jsxs("p",{className:"text-amber-400/60 text-[12px] mt-1",children:["Your current handle ",S.jsx("span",{className:"font-mono",children:We?.url})," will be released and become available for others."]})]}),(!We||gt||!ue)&&!(We&&ue&&!gt)&&S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"relative mt-5",children:[S.jsx("input",{type:"text",value:te,onChange:re=>Ei(re.target.value),maxLength:30,placeholder:"your-bot-name",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",autoFocus:!0,disabled:ue,className:Vt+" pr-10 font-mono"+(ue?" opacity-50":"")}),ee&&te.length>0&&!ue&&S.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:[ee==="checking"&&S.jsx("div",{className:"w-5 h-5 border-2 border-white/10 border-t-[#04D1FE] rounded-full animate-spin"}),ee==="invalid"&&S.jsx("div",{className:"w-6 h-6 rounded-full bg-amber-500/15 flex items-center justify-center",children:S.jsx("svg",{className:"w-3.5 h-3.5 text-amber-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:S.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3m0 4h.01"})})})]})]}),ee==="invalid"&&V&&S.jsx("p",{className:"text-amber-400 text-[12px] mt-2",children:V}),ee==="ready"&&te.length>0&&!ue&&S.jsx("div",{className:"space-y-2 mt-4",children:n_.map(re=>{const Mt=ne[re.tier]===!1;return S.jsxs("button",{onClick:()=>!Mt&&H(re.tier),disabled:Mt,className:`w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all duration-200 text-left ${Mt?"border-white/[0.04] bg-transparent opacity-50 cursor-not-allowed":M===re.tier?re.highlight?"border-[#AF27E3]/40 bg-[#AF27E3]/[0.06]":"border-[#AF27E3]/30 bg-white/[0.04]":"border-white/[0.06] bg-transparent hover:border-white/10 hover:bg-white/[0.02]"}`,children:[S.jsx("span",{className:"font-mono text-[13px] text-white/70",children:re.label(te)}),Mt?S.jsx("span",{className:"text-[11px] font-medium px-2.5 py-0.5 rounded-full border bg-red-500/10 text-red-400 border-red-500/20",children:"Taken"}):S.jsx("span",{className:`text-[11px] font-medium px-2.5 py-0.5 rounded-full border ${re.badgeCls}`,children:re.badge})]},re.tier)})}),ue&&S.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"}),S.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Handle claimed!"})]}),S.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:me})]}),ee==="ready"&&ne[M]&&te.length>0&&!ue&&S.jsx("button",{onClick:gt?vi:Si,disabled:I||Dt,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:I||Dt?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-4 w-4 animate-spin"}),gt?"Changing...":"Claiming..."]}):S.jsxs(S.Fragment,{children:[gt?"Change Handle":"Claim & Continue",S.jsx(sa,{className:"h-4 w-4"})]})}),ue&&S.jsxs("button",{onClick:$n,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]}),gt&&!ue&&S.jsx("button",{onClick:()=>{It(!1),ie(We.username),de(!0),ke(We.url),H(We.tier),j(null)},className:"w-full mt-2 py-2 text-white/25 hover:text-white/40 text-[12px] transition-colors",children:"Cancel — keep current handle"})]})]}),t===3&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Secure your portal"}),S.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"Create credentials to protect your dashboard. Anyone with your URL will need these to log in."}),ue&&me&&S.jsxs("div",{className:"mt-4 flex items-center gap-2 bg-white/[0.03] border border-white/[0.06] rounded-xl px-4 py-3",children:[S.jsx("span",{className:"font-mono text-[13px] text-white/60 truncate flex-1",children:me}),S.jsx("button",{onClick:()=>{navigator.clipboard.writeText(me),yi(!0),setTimeout(()=>yi(!1),2e3)},className:"shrink-0 text-white/30 hover:text-white/60 transition-colors",children:Go?S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"}):S.jsxs("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[S.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),S.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),ct&&S.jsx("div",{className:"mt-4 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-2.5",children:S.jsx("p",{className:"text-white/40 text-[12px]",children:"Credentials already set. Leave password fields empty to keep your current password, or enter your current password to change it."})}),S.jsxs("div",{className:"mt-5",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Username"}),S.jsx("input",{type:"text",value:mn,onChange:re=>Lr(re.target.value.replace(/\s/g,"").toLowerCase()),placeholder:"admin",autoFocus:!0,autoComplete:"username",className:Vt+" font-mono"}),mn.length>0&&mn.trim().length<3&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 3 characters"})]}),ct&&S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Current password"}),S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx("input",{type:"password",value:oe,onChange:re=>{fe(re.target.value),Ne(""),Ht(!1)},placeholder:"Enter current password to change it",autoComplete:"current-password",className:Vt+" flex-1"}),oe.length>0&&!ze&&S.jsx("button",{onClick:async()=>{Nt(!0),Ne("");try{(await(await fetch("/api/portal/verify-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:oe})})).json()).valid?Ht(!0):Ne("Incorrect password")}catch{Ne("Could not verify")}finally{Nt(!1)}},disabled:Rn,className:"shrink-0 px-4 py-3 bg-white/[0.06] hover:bg-white/[0.1] text-white/60 text-[13px] font-medium rounded-xl transition-colors disabled:opacity-40",children:Rn?S.jsx(so,{className:"h-4 w-4 animate-spin"}):"Verify"}),ze&&S.jsx("div",{className:"shrink-0 w-10 h-10 flex items-center justify-center",children:S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"})})]}),we&&S.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:we})]}),(!ct||ze)&&S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:ct?"New password":"Password"}),S.jsx("input",{type:"password",value:kn,onChange:re=>Ya(re.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:wi,className:Vt}),kn.length>0&&kn.length<6&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 6 characters"})]}),S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:ct?"Confirm new password":"Confirm password"}),S.jsx("input",{type:"password",value:na,onChange:re=>Mr(re.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:wi,className:Vt}),na.length>0&&!Ml&&S.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:"Passwords don't match"})]})]}),S.jsxs("button",{onClick:$n,disabled:!Ka,className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]})]}),t===4&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Choose your AI provider"}),S.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."}),S.jsx("div",{className:"flex gap-2.5 mt-4",children:UY.map(re=>S.jsxs("button",{onClick:()=>xa(re.id),className:`flex-1 relative rounded-xl border transition-all duration-200 p-3 text-left ${l===re.id?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:[S.jsxs("div",{className:"flex flex-col items-center gap-1.5 py-0.5",children:[re.icon?S.jsx("img",{src:re.icon,alt:re.name,className:"w-8 h-8 rounded-lg"}):S.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"}),S.jsxs("div",{className:"text-center",children:[S.jsx("div",{className:"text-[13px] font-medium text-white",children:re.name}),S.jsx("div",{className:"text-[10px] text-white/30",children:re.subtitle})]})]}),g[re.id]==="connected"?S.jsx("div",{className:"absolute top-2 right-2 w-4 h-4 rounded-full bg-emerald-500/15 flex items-center justify-center",children:S.jsx(Bs,{className:"h-2.5 w-2.5 text-emerald-400"})}):l===re.id?S.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-gradient-brand"}):null]},re.id))}),S.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),l==="anthropic"&&S.jsxs("div",{className:"space-y-2.5",children:[va&&S.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — Anthropic subscription is active."})}),!va&&S.jsxs(S.Fragment,{children:[_&&S.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-red-400/90 text-[12px]",children:_})}),S.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((re,Ae)=>S.jsxs("div",{className:"flex items-start gap-2",children:[S.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:Ae+1}),S.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:re})]},Ae))}),S.jsx("button",{onClick:xi,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2",children:E?S.jsxs(S.Fragment,{children:[S.jsx(AM,{className:"h-3.5 w-3.5 opacity-60"}),"Open authentication page again"]}):S.jsxs(S.Fragment,{children:["Authenticate with Anthropic",S.jsx(sa,{className:"h-3.5 w-3.5 opacity-60"})]})}),S.jsxs("div",{className:"relative",children:[S.jsx("input",{type:"text",value:T,onChange:re=>k(re.target.value),onKeyDown:re=>re.key==="Enter"&&Wa(),placeholder:"Paste your code here...",className:yt+" pr-10 font-mono"}),S.jsx("button",{onClick:Cd,className:"absolute right-3 top-1/2 -translate-y-1/2 text-white/20 hover:text-white/50 transition-colors",children:S.jsx(EM,{className:"h-3.5 w-3.5"})})]}),S.jsx("button",{onClick:Wa,disabled:!T.trim()||w,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:w?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-3.5 w-3.5 animate-spin"}),"Verifying..."]}):"Connect"}),S.jsxs("button",{onClick:Ll,disabled:F,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:[F?S.jsx(so,{className:"h-3 w-3 animate-spin"}):S.jsx(zM,{className:"h-3 w-3"}),F?"Checking...":"I'm already authenticated"]})]})]}),l==="openai"&&S.jsxs("div",{className:"space-y-2.5",children:[va&&S.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — ChatGPT subscription is active."})}),!va&&S.jsxs(S.Fragment,{children:[W&&S.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-red-400/90 text-[12px]",children:W})}),S.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((re,Ae)=>S.jsxs("div",{className:"flex items-start gap-2",children:[S.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:Ae+1}),S.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:re})]},Ae))}),S.jsx("button",{onClick:Ho,disabled:z,className:"w-full py-2.5 px-4 bg-white/[0.06] hover:bg-white/[0.09] text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-60",children:z?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-3.5 w-3.5 animate-spin opacity-60"}),"Waiting for sign-in..."]}):S.jsxs(S.Fragment,{children:["Authenticate with ChatGPT",S.jsx(sa,{className:"h-3.5 w-3.5 opacity-60"})]})}),z&&S.jsx("button",{onClick:Fr,className:"w-full py-1.5 text-white/25 text-[11px] hover:text-white/40 transition-colors",children:"Cancel"})]})]}),l==="ollama"&&S.jsxs("div",{className:"space-y-2.5",children:[S.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"No authentication needed — Ollama runs locally."})}),S.jsxs("div",{children:[S.jsxs("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:["Base URL ",S.jsx("span",{className:"text-white/20",children:"(optional)"})]}),S.jsx("input",{type:"text",value:X,onChange:re=>Q(re.target.value),placeholder:"http://localhost:11434",className:yt})]})]}),va&&S.jsxs(S.Fragment,{children:[S.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Select a model"}),S.jsx(PY,{models:BY[l]||[],value:d,onChange:f})]}),va&&S.jsxs("button",{onClick:$n,disabled:!Ka,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]})]}),t===5&&S.jsxs("div",{children:[S.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Voice Messages"}),S.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"})]}),S.jsx("p",{className:"text-white/40 text-[13px] mt-1 leading-relaxed",children:"Allow users to send audio messages that are automatically transcribed."}),S.jsx("button",{onClick:()=>Lt(re=>!re),className:`w-full mt-5 rounded-xl border transition-all duration-200 p-4 text-left ${Ze?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:S.jsxs("div",{className:"flex items-center gap-3.5",children:[S.jsx("img",{src:"/icons/openai.svg",alt:"OpenAI",className:"w-10 h-10 rounded-xl bg-white/[0.04] p-1.5"}),S.jsxs("div",{className:"flex-1",children:[S.jsx("div",{className:"text-[14px] font-medium text-white",children:"OpenAI Whisper"}),S.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."})]}),S.jsx("div",{className:`w-10 h-[22px] rounded-full transition-colors duration-200 flex items-center px-0.5 shrink-0 ${Ze?"bg-gradient-brand":"bg-white/[0.08]"}`,children:S.jsx("div",{className:`w-[18px] h-[18px] rounded-full bg-white shadow-sm transition-transform duration-200 ${Ze?"translate-x-[18px]":"translate-x-0"}`})})]})}),Ze&&S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"OpenAI API Key"}),S.jsx("input",{type:"password",value:Le,onChange:re=>Gn(re.target.value.trim()),placeholder:"sk-...",autoComplete:"off",className:Vt+" font-mono text-[13px]"}),Le.length>0&&!Le.startsWith("sk-")&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key should start with sk-"}),Le.length>0&&Le.startsWith("sk-")&&Le.length<20&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key looks too short"}),S.jsxs("div",{className:"flex items-start gap-2.5 mt-3 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-3",children:[S.jsx(jm,{className:"h-4 w-4 text-[#AF27E3]/60 mt-0.5 shrink-0"}),S.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."})]})]}),S.jsx("button",{onClick:Ul,disabled:p||Ze&&(!Le.startsWith("sk-")||Le.length<20),className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:p?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-4 w-4 animate-spin"}),"Setting up..."]}):S.jsxs(S.Fragment,{children:["Complete Setup",S.jsx(sa,{className:"h-4 w-4"})]})}),!Ze&&S.jsx("p",{className:"text-center text-white/20 text-[11px] mt-2.5",children:"You can enable this later in Settings."})]})]},t)}),t>0&&S.jsx("div",{className:"px-8 pb-5 -mt-3",children:S.jsx("button",{onClick:qo,className:"text-white/25 hover:text-white/50 text-[12px] transition-colors",children:"← Back"})})]})]})}function zY({...e}){return S.jsx(Uj,{"data-slot":"dropdown-menu",...e})}function GY({...e}){return S.jsx(Bj,{"data-slot":"dropdown-menu-trigger",...e})}function $Y({className:e,sideOffset:t=4,...n}){return S.jsx(Pj,{children:S.jsx(jj,{"data-slot":"dropdown-menu-content",sideOffset:t,className:pn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",e),...n})})}function HY({className:e,inset:t,variant:n="default",...r}){return S.jsx(zj,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:pn("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r})}function VY(){return S.jsx("div",{className:"flex items-center justify-center h-dvh p-6 text-center",children:S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Something went wrong"}),S.jsx("p",{className:"text-sm text-muted-foreground",children:"The dashboard encountered an error. Use the Fluxy button to continue chatting."})]})})}function qY(){const[e,t]=A.useState(!1),[n,r]=A.useState(!1),[o,l]=A.useState("Fluxy"),[u,d]=A.useState(!1),{ws:f,connected:p}=XL(),m=A.useRef(null);A.useEffect(()=>{fetch("/api/settings").then(y=>y.json()).then(y=>{y.onboard_complete!=="true"&&r(!0),y.agent_name&&l(y.agent_name),y.whisper_enabled==="true"&&d(!0)}).catch(()=>r(!0))},[]);const g=()=>{r(!1),fetch("/api/settings").then(y=>y.json()).then(y=>{y.agent_name&&l(y.agent_name),d(y.whisper_enabled==="true")}).catch(()=>{})};return S.jsxs(S.Fragment,{children:[S.jsx(t2,{fallback:S.jsx(VY,{}),children:S.jsx(iz,{onOpenOnboard:()=>r(!0),children:S.jsx(cz,{})})}),S.jsx(wC,{open:e,onOpenChange:t,children:S.jsxs(TC,{side:"right",className:"w-full sm:max-w-md !gap-0 !p-0 !border-l-0 !h-dvh overflow-hidden",onOpenAutoFocus:y=>y.preventDefault(),children:[S.jsxs("div",{className:"flex items-center gap-3 px-4 pr-12 py-3 border-b border-border shrink-0",children:[S.jsx("img",{src:"/fluxy.png",alt:o,className:"h-5 w-auto"}),S.jsx(AC,{className:"text-sm font-semibold",children:o}),S.jsx("div",{className:`h-2 w-2 rounded-full ${p?"bg-green-500":"bg-red-500"}`}),S.jsx("div",{className:"flex-1"}),S.jsxs(zY,{children:[S.jsx(GY,{asChild:!0,children:S.jsx("button",{className:"flex items-center justify-center h-7 w-7 rounded-full text-muted-foreground hover:text-foreground hover:bg-white/[0.06] transition-colors",children:S.jsx(vM,{className:"h-4 w-4"})})}),S.jsx($Y,{align:"end",sideOffset:8,children:S.jsxs(HY,{onClick:()=>m.current?.(),children:[S.jsx(u_,{className:"h-3.5 w-3.5"}),"Clear Context"]})})]}),S.jsxs(nz,{className:"sr-only",children:["Chat with your ",o," AI assistant"]})]}),S.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:S.jsx(MY,{ws:f,clearContextRef:m,whisperEnabled:u})})]})}),S.jsx(FY,{onClick:()=>t(y=>!y)}),n&&S.jsx(jY,{onComplete:g})]})}KL.createRoot(document.getElementById("root")).render(S.jsx(zt.StrictMode,{children:S.jsx(qY,{})}));
100
+ `),()=>{F.contains(L)&&F.removeChild(L)}},[t]),S.jsx(E9,{isPresent:t,childRef:d,sizeRef:f,pop:l,children:l===!1?e:A.cloneElement(e,{ref:g})})}const v9=({children:e,initial:t,isPresent:n,onExitComplete:r,custom:o,presenceAffectsLayout:l,mode:u,anchorX:d,anchorY:f,root:p})=>{const m=Rv(x9),g=A.useId();let y=!0,E=A.useMemo(()=>(y=!1,{id:g,initial:t,isPresent:n,custom:o,onExitComplete:v=>{m.set(v,!0);for(const T of m.values())if(!T)return;r&&r()},register:v=>(m.set(v,!1),()=>m.delete(v))}),[n,m,r]);return l&&y&&(E={...E}),A.useMemo(()=>{m.forEach((v,T)=>m.set(T,!1))},[n]),A.useEffect(()=>{!n&&!m.size&&r&&r()},[n]),e=S.jsx(S9,{pop:u==="popLayout",isPresent:n,anchorX:d,anchorY:f,root:p,children:e}),S.jsx(kd.Provider,{value:E,children:e})};function x9(){return new Map}function b1(e=!0){const t=A.useContext(kd);if(t===null)return[!0,null];const{isPresent:n,onExitComplete:r,register:o}=t,l=A.useId();A.useEffect(()=>{if(e)return o(l)},[e]);const u=A.useCallback(()=>e&&r&&r(l),[l,r,e]);return!n&&r?[!1,u]:[!0]}const pc=e=>e.key||"";function zN(e){const t=[];return A.Children.forEach(e,n=>{A.isValidElement(n)&&t.push(n)}),t}const qc=({children:e,custom:t,initial:n=!0,onExitComplete:r,presenceAffectsLayout:o=!0,mode:l="sync",propagate:u=!1,anchorX:d="left",anchorY:f="top",root:p})=>{const[m,g]=b1(u),y=A.useMemo(()=>zN(e),[e]),E=u&&!m?[]:y.map(pc),v=A.useRef(!0),T=A.useRef(y),k=Rv(()=>new Map),w=A.useRef(new Set),[C,_]=A.useState(y),[L,F]=A.useState(y);VO(()=>{v.current=!1,T.current=y;for(let B=0;B<L.length;B++){const W=pc(L[B]);E.includes(W)?(k.delete(W),w.current.delete(W)):k.get(W)!==!0&&k.set(W,!1)}},[L,E.length,E.join("-")]);const D=[];if(y!==C){let B=[...y];for(let W=0;W<L.length;W++){const U=L[W],X=pc(U);E.includes(X)||(B.splice(W,0,U),D.push(U))}return l==="wait"&&D.length&&(B=D),F(zN(B)),_(y),null}const{forceRender:z}=A.useContext(kv);return S.jsx(S.Fragment,{children:L.map(B=>{const W=pc(B),U=u&&!m?!1:y===L||E.includes(W),X=()=>{if(w.current.has(W))return;if(w.current.add(W),k.has(W))k.set(W,!0);else return;let Q=!0;k.forEach(te=>{te||(Q=!1)}),Q&&(z?.(),F(T.current),u&&g?.(),r&&r())};return S.jsx(v9,{isPresent:U,initial:!v.current||n?void 0:!1,custom:t,presenceAffectsLayout:o,mode:l,root:p,onExitComplete:U?void 0:X,anchorX:d,anchorY:f,children:B},W)})})},y1=A.createContext({strict:!1}),GN={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 $N=!1;function w9(){if($N)return;const e={};for(const t in GN)e[t]={isEnabled:n=>GN[t].some(r=>!!n[r])};YI(e),$N=!0}function E1(){return w9(),u8()}function T9(e){const t=E1();for(const n in e)t[n]={...t[n],...e[n]};YI(t)}const A9=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 Yc(e){return e.startsWith("while")||e.startsWith("drag")&&e!=="draggable"||e.startsWith("layout")||e.startsWith("onTap")||e.startsWith("onPan")||e.startsWith("onLayout")||A9.has(e)}let S1=e=>!Yc(e);function k9(e){typeof e=="function"&&(S1=t=>t.startsWith("on")?!Yc(t):e(t))}try{k9(require("@emotion/is-prop-valid").default)}catch{}function R9(e,t,n){const r={};for(const o in e)o==="values"&&typeof e.values=="object"||(S1(o)||n===!0&&Yc(o)||!t&&!Yc(o)||e.draggable&&o.startsWith("onDrag"))&&(r[o]=e[o]);return r}const _d=A.createContext({});function N9(e,t){if(Nd(e)){const{initial:n,animate:r}=e;return{initial:n===!1||fl(n)?n:void 0,animate:fl(r)?r:void 0}}return e.inherit!==!1?t:{}}function _9(e){const{initial:t,animate:n}=N9(e,A.useContext(_d));return A.useMemo(()=>({initial:t,animate:n}),[HN(t),HN(n)])}function HN(e){return Array.isArray(e)?e.join(" "):e}const tx=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function v1(e,t,n){for(const r in t)!Wt(t[r])&&!e1(r,n)&&(e[r]=t[r])}function C9({transformTemplate:e},t){return A.useMemo(()=>{const n=tx();return Qv(n,t,e),Object.assign({},n.vars,n.style)},[t])}function O9(e,t){const n=e.style||{},r={};return v1(r,n,e),Object.assign(r,C9(e,t)),r}function I9(e,t){const n={},r=O9(e,t);return e.drag&&e.dragListener!==!1&&(n.draggable=!1,r.userSelect=r.WebkitUserSelect=r.WebkitTouchCallout="none",r.touchAction=e.drag===!0?"none":`pan-${e.drag==="x"?"y":"x"}`),e.tabIndex===void 0&&(e.onTap||e.onTapStart||e.whileTap)&&(n.tabIndex=0),n.style=r,n}const x1=()=>({...tx(),attrs:{}});function D9(e,t,n,r){const o=A.useMemo(()=>{const l=x1();return t1(l,t,a1(r),e.transformTemplate,e.style),{...l.attrs,style:{...l.style}}},[t]);if(e.style){const l={};v1(l,e.style,e),o.style={...l,...o.style}}return o}const L9=["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 nx(e){return typeof e!="string"||e.includes("-")?!1:!!(L9.indexOf(e)>-1||/[A-Z]/u.test(e))}function M9(e,t,n,{latestValues:r},o,l=!1,u){const f=(u??nx(e)?D9:I9)(t,r,o,e),p=R9(t,typeof e=="string",l),m=e!==A.Fragment?{...p,...f,ref:n}:{},{children:g}=t,y=A.useMemo(()=>Wt(g)?g.get():g,[g]);return A.createElement(e,{...m,children:y})}function F9({scrapeMotionValuesFromProps:e,createRenderState:t},n,r,o){return{latestValues:U9(n,r,o,e),renderState:t()}}function U9(e,t,n,r){const o={},l=r(e,{});for(const y in l)o[y]=Ac(l[y]);let{initial:u,animate:d}=e;const f=Nd(e),p=VI(e);t&&p&&!f&&e.inherit!==!1&&(u===void 0&&(u=t.initial),d===void 0&&(d=t.animate));let m=n?n.initial===!1:!1;m=m||u===!1;const g=m?d:u;if(g&&typeof g!="boolean"&&!Rd(g)){const y=Array.isArray(g)?g:[g];for(let E=0;E<y.length;E++){const v=Hv(e,y[E]);if(v){const{transitionEnd:T,transition:k,...w}=v;for(const C in w){let _=w[C];if(Array.isArray(_)){const L=m?_.length-1:0;_=_[L]}_!==null&&(o[C]=_)}for(const C in T)o[C]=T[C]}}}return o}const w1=e=>(t,n)=>{const r=A.useContext(_d),o=A.useContext(kd),l=()=>F9(e,t,r,o);return n?l():Rv(l)},B9=w1({scrapeMotionValuesFromProps:Jv,createRenderState:tx}),P9=w1({scrapeMotionValuesFromProps:r1,createRenderState:x1}),j9=Symbol.for("motionComponentSymbol");function z9(e,t,n){const r=A.useRef(n);A.useInsertionEffect(()=>{r.current=n});const o=A.useRef(null);return A.useCallback(l=>{l&&e.onMount?.(l),t&&(l?t.mount(l):t.unmount());const u=r.current;if(typeof u=="function")if(l){const d=u(l);typeof d=="function"&&(o.current=d)}else o.current?(o.current(),o.current=null):u(l);else u&&(u.current=l)},[t])}const T1=A.createContext({});function go(e){return e&&typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function G9(e,t,n,r,o,l){const{visualElement:u}=A.useContext(_d),d=A.useContext(y1),f=A.useContext(kd),p=A.useContext(ex),m=p.reducedMotion,g=p.skipAnimations,y=A.useRef(null),E=A.useRef(!1);r=r||d.renderer,!y.current&&r&&(y.current=r(e,{visualState:t,parent:u,props:n,presenceContext:f,blockInitialAnimation:f?f.initial===!1:!1,reducedMotionConfig:m,skipAnimations:g,isSVG:l}),E.current&&y.current&&(y.current.manuallyAnimateOnMount=!0));const v=y.current,T=A.useContext(T1);v&&!v.projection&&o&&(v.type==="html"||v.type==="svg")&&$9(y.current,n,o,T);const k=A.useRef(!1);A.useInsertionEffect(()=>{v&&k.current&&v.update(n,f)});const w=n[II],C=A.useRef(!!w&&!window.MotionHandoffIsComplete?.(w)&&window.MotionHasOptimisedAnimation?.(w));return VO(()=>{E.current=!0,v&&(k.current=!0,window.MotionIsMounted=!0,v.updateFeatures(),v.scheduleRenderMicrotask(),C.current&&v.animationState&&v.animationState.animateChanges())}),A.useEffect(()=>{v&&(!C.current&&v.animationState&&v.animationState.animateChanges(),C.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(w)}),C.current=!1),v.enteringChildren=void 0)}),v}function $9(e,t,n,r){const{layoutId:o,layout:l,drag:u,dragConstraints:d,layoutScroll:f,layoutRoot:p,layoutCrossfade:m}=t;e.projection=new n(e.latestValues,t["data-framer-portal-id"]?void 0:A1(e.parent)),e.projection.setOptions({layoutId:o,layout:l,alwaysMeasureLayout:!!u||d&&go(d),visualElement:e,animationType:typeof l=="string"?l:"both",initialPromotionConfig:r,crossfade:m,layoutScroll:f,layoutRoot:p})}function A1(e){if(e)return e.options.allowProjection!==!1?e.projection:A1(e.parent)}function Lm(e,{forwardMotionProps:t=!1,type:n}={},r,o){r&&T9(r);const l=n?n==="svg":nx(e),u=l?P9:B9;function d(p,m){let g;const y={...A.useContext(ex),...p,layoutId:H9(p)},{isStatic:E}=y,v=_9(p),T=u(p,E);if(!E&&HO){V9();const k=q9(y);g=k.MeasureLayout,v.visualElement=G9(e,T,y,o,k.ProjectionNode,l)}return S.jsxs(_d.Provider,{value:v,children:[g&&v.visualElement?S.jsx(g,{visualElement:v.visualElement,...y}):null,M9(e,p,z9(T,v.visualElement,m),T,E,t,l)]})}d.displayName=`motion.${typeof e=="string"?e:`create(${e.displayName??e.name??""})`}`;const f=A.forwardRef(d);return f[j9]=e,f}function H9({layoutId:e}){const t=A.useContext(kv).id;return t&&e!==void 0?t+"-"+e:e}function V9(e,t){A.useContext(y1).strict}function q9(e){const t=E1(),{drag:n,layout:r}=t;if(!n&&!r)return{};const o={...n,...r};return{MeasureLayout:n?.isEnabled(e)||r?.isEnabled(e)?o.MeasureLayout:void 0,ProjectionNode:o.ProjectionNode}}function Y9(e,t){if(typeof Proxy>"u")return Lm;const n=new Map,r=(l,u)=>Lm(l,u,e,t),o=(l,u)=>r(l,u);return new Proxy(o,{get:(l,u)=>u==="create"?r:(n.has(u)||n.set(u,Lm(u,void 0,e,t)),n.get(u))})}const W9=(e,t)=>t.isSVG??nx(e)?new k8(t):new S8(t,{allowProjection:e!==A.Fragment});class K9 extends Dr{constructor(t){super(t),t.animationState||(t.animationState=O8(t))}updateAnimationControlsSubscription(){const{animate:t}=this.node.getProps();Rd(t)&&(this.unmountControls=t.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:t}=this.node.getProps(),{animate:n}=this.node.prevProps||{};t!==n&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let X9=0;class Z9 extends Dr{constructor(){super(...arguments),this.id=X9++}update(){if(!this.node.presenceContext)return;const{isPresent:t,onExitComplete:n}=this.node.presenceContext,{isPresent:r}=this.node.prevPresenceContext||{};if(!this.node.animationState||t===r)return;const o=this.node.animationState.setActive("exit",!t);n&&!t&&o.then(()=>{n(this.id)})}mount(){const{register:t,onExitComplete:n}=this.node.presenceContext||{};n&&n(this.id),t&&(this.unmount=t(this.id))}unmount(){}}const Q9={animation:{Feature:K9},exit:{Feature:Z9}};function Dl(e){return{point:{x:e.pageX,y:e.pageY}}}const J9=e=>t=>Wv(t)&&e(t,Dl(t));function el(e,t,n,r){return ml(e,t,J9(n),r)}const k1=({current:e})=>e?e.ownerDocument.defaultView:null,VN=(e,t)=>Math.abs(e-t);function eY(e,t){const n=VN(e.x,t.x),r=VN(e.y,t.y);return Math.sqrt(n**2+r**2)}const qN=new Set(["auto","scroll"]);class R1{constructor(t,n,{transformPagePoint:r,contextWindow:o=window,dragSnapToOrigin:l=!1,distanceThreshold:u=3,element:d}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.removeScrollListeners=null,this.onElementScroll=E=>{this.handleScroll(E.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const E=Fm(this.lastMoveEventInfo,this.history),v=this.startEvent!==null,T=eY(E.offset,{x:0,y:0})>=this.distanceThreshold;if(!v&&!T)return;const{point:k}=E,{timestamp:w}=jt;this.history.push({...k,timestamp:w});const{onStart:C,onMove:_}=this.handlers;v||(C&&C(this.lastMoveEvent,E),this.startEvent=this.lastMoveEvent),_&&_(this.lastMoveEvent,E)},this.handlePointerMove=(E,v)=>{this.lastMoveEvent=E,this.lastMoveEventInfo=Mm(v,this.transformPagePoint),it.update(this.updatePoint,!0)},this.handlePointerUp=(E,v)=>{this.end();const{onEnd:T,onSessionEnd:k,resumeAnimation:w}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&w&&w(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const C=Fm(E.type==="pointercancel"?this.lastMoveEventInfo:Mm(v,this.transformPagePoint),this.history);this.startEvent&&T&&T(E,C),k&&k(E,C)},!Wv(t))return;this.dragSnapToOrigin=l,this.handlers=n,this.transformPagePoint=r,this.distanceThreshold=u,this.contextWindow=o||window;const f=Dl(t),p=Mm(f,this.transformPagePoint),{point:m}=p,{timestamp:g}=jt;this.history=[{...m,timestamp:g}];const{onSessionStart:y}=n;y&&y(t,Fm(p,this.history)),this.removeListeners=Cl(el(this.contextWindow,"pointermove",this.handlePointerMove),el(this.contextWindow,"pointerup",this.handlePointerUp),el(this.contextWindow,"pointercancel",this.handlePointerUp)),d&&this.startScrollTracking(d)}startScrollTracking(t){let n=t.parentElement;for(;n;){const r=getComputedStyle(n);(qN.has(r.overflowX)||qN.has(r.overflowY))&&this.scrollPositions.set(n,{x:n.scrollLeft,y:n.scrollTop}),n=n.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(t){const n=this.scrollPositions.get(t);if(!n)return;const r=t===window,o=r?{x:window.scrollX,y:window.scrollY}:{x:t.scrollLeft,y:t.scrollTop},l={x:o.x-n.x,y:o.y-n.y};l.x===0&&l.y===0||(r?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=l.x,this.lastMoveEventInfo.point.y+=l.y):this.history.length>0&&(this.history[0].x-=l.x,this.history[0].y-=l.y),this.scrollPositions.set(t,o),it.update(this.updatePoint,!0))}updateHandlers(t){this.handlers=t}end(){this.removeListeners&&this.removeListeners(),this.removeScrollListeners&&this.removeScrollListeners(),this.scrollPositions.clear(),_r(this.updatePoint)}}function Mm(e,t){return t?{point:t(e.point)}:e}function YN(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Fm({point:e},t){return{point:e,delta:YN(e,N1(t)),offset:YN(e,tY(t)),velocity:nY(t,.1)}}function tY(e){return e[0]}function N1(e){return e[e.length-1]}function nY(e,t){if(e.length<2)return{x:0,y:0};let n=e.length-1,r=null;const o=N1(e);for(;n>=0&&(r=e[n],!(o.timestamp-r.timestamp>Xn(t)));)n--;if(!r)return{x:0,y:0};r===e[0]&&e.length>2&&o.timestamp-r.timestamp>Xn(t)*2&&(r=e[1]);const l=Pn(o.timestamp-r.timestamp);if(l===0)return{x:0,y:0};const u={x:(o.x-r.x)/l,y:(o.y-r.y)/l};return u.x===1/0&&(u.x=0),u.y===1/0&&(u.y=0),u}function aY(e,{min:t,max:n},r){return t!==void 0&&e<t?e=r?ut(t,e,r.min):Math.max(e,t):n!==void 0&&e>n&&(e=r?ut(n,e,r.max):Math.min(e,n)),e}function WN(e,t,n){return{min:t!==void 0?e.min+t:void 0,max:n!==void 0?e.max+n-(e.max-e.min):void 0}}function rY(e,{top:t,left:n,bottom:r,right:o}){return{x:WN(e.x,n,o),y:WN(e.y,t,r)}}function KN(e,t){let n=t.min-e.min,r=t.max-e.max;return t.max-t.min<e.max-e.min&&([n,r]=[r,n]),{min:n,max:r}}function iY(e,t){return{x:KN(e.x,t.x),y:KN(e.y,t.y)}}function oY(e,t){let n=.5;const r=nn(e),o=nn(t);return o>r?n=cl(t.min,t.max-r,e.min):r>o&&(n=cl(e.min,e.max-o,t.min)),ha(0,1,n)}function sY(e,t){const n={};return t.min!==void 0&&(n.min=t.min-e.min),t.max!==void 0&&(n.max=t.max-e.min),n}const Dg=.35;function lY(e=Dg){return e===!1?e=0:e===!0&&(e=Dg),{x:XN(e,"left","right"),y:XN(e,"top","bottom")}}function XN(e,t,n){return{min:ZN(e,t),max:ZN(e,n)}}function ZN(e,t){return typeof e=="number"?e:e[t]||0}const uY=new WeakMap;class cY{constructor(t){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=Rt(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=t}start(t,{snapToCursor:n=!1,distanceThreshold:r}={}){const{presenceContext:o}=this.visualElement;if(o&&o.isPresent===!1)return;const l=g=>{n&&this.snapToCursor(Dl(g).point),this.stopAnimation()},u=(g,y)=>{const{drag:E,dragPropagation:v,onDragStart:T}=this.getProps();if(E&&!v&&(this.openDragLock&&this.openDragLock(),this.openDragLock=Pq(E),!this.openDragLock))return;this.latestPointerEvent=g,this.latestPanInfo=y,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints(),this.visualElement.projection&&(this.visualElement.projection.isAnimationBlocked=!0,this.visualElement.projection.target=void 0),ua(w=>{let C=this.getAxisMotionValue(w).get()||0;if(fa.test(C)){const{projection:_}=this.visualElement;if(_&&_.layout){const L=_.layout.layoutBox[w];L&&(C=nn(L)*(parseFloat(C)/100))}}this.originPoint[w]=C}),T&&it.update(()=>T(g,y),!1,!0),Tg(this.visualElement,"transform");const{animationState:k}=this.visualElement;k&&k.setActive("whileDrag",!0)},d=(g,y)=>{this.latestPointerEvent=g,this.latestPanInfo=y;const{dragPropagation:E,dragDirectionLock:v,onDirectionLock:T,onDrag:k}=this.getProps();if(!E&&!this.openDragLock)return;const{offset:w}=y;if(v&&this.currentDirection===null){this.currentDirection=pY(w),this.currentDirection!==null&&T&&T(this.currentDirection);return}this.updateAxis("x",y.point,w),this.updateAxis("y",y.point,w),this.visualElement.render(),k&&it.update(()=>k(g,y),!1,!0)},f=(g,y)=>{this.latestPointerEvent=g,this.latestPanInfo=y,this.stop(g,y),this.latestPointerEvent=null,this.latestPanInfo=null},p=()=>{const{dragSnapToOrigin:g}=this.getProps();(g||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:m}=this.getProps();this.panSession=new R1(t,{onSessionStart:l,onStart:u,onMove:d,onSessionEnd:f,resumeAnimation:p},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:m,distanceThreshold:r,contextWindow:k1(this.visualElement),element:this.visualElement.current})}stop(t,n){const r=t||this.latestPointerEvent,o=n||this.latestPanInfo,l=this.isDragging;if(this.cancel(),!l||!o||!r)return;const{velocity:u}=o;this.startAnimation(u);const{onDragEnd:d}=this.getProps();d&&it.postRender(()=>d(r,o))}cancel(){this.isDragging=!1;const{projection:t,animationState:n}=this.visualElement;t&&(t.isAnimationBlocked=!1),this.endPanSession();const{dragPropagation:r}=this.getProps();!r&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),n&&n.setActive("whileDrag",!1)}endPanSession(){this.panSession&&this.panSession.end(),this.panSession=void 0}updateAxis(t,n,r){const{drag:o}=this.getProps();if(!r||!fc(t,o,this.currentDirection))return;const l=this.getAxisMotionValue(t);let u=this.originPoint[t]+r[t];this.constraints&&this.constraints[t]&&(u=aY(u,this.constraints[t],this.elastic[t])),l.set(u)}resolveConstraints(){const{dragConstraints:t,dragElastic:n}=this.getProps(),r=this.visualElement.projection&&!this.visualElement.projection.layout?this.visualElement.projection.measure(!1):this.visualElement.projection?.layout,o=this.constraints;t&&go(t)?this.constraints||(this.constraints=this.resolveRefConstraints()):t&&r?this.constraints=rY(r.layoutBox,t):this.constraints=!1,this.elastic=lY(n),o!==this.constraints&&!go(t)&&r&&this.constraints&&!this.hasMutatedConstraints&&ua(l=>{this.constraints!==!1&&this.getAxisMotionValue(l)&&(this.constraints[l]=sY(r.layoutBox[l],this.constraints[l]))})}resolveRefConstraints(){const{dragConstraints:t,onMeasureDragConstraints:n}=this.getProps();if(!t||!go(t))return!1;const r=t.current,{projection:o}=this.visualElement;if(!o||!o.layout)return!1;const l=m8(r,o.root,this.visualElement.getTransformPagePoint());let u=iY(o.layout.layoutBox,l);if(n){const d=n(d8(u));this.hasMutatedConstraints=!!d,d&&(u=KI(d))}return u}startAnimation(t){const{drag:n,dragMomentum:r,dragElastic:o,dragTransition:l,dragSnapToOrigin:u,onDragTransitionEnd:d}=this.getProps(),f=this.constraints||{},p=ua(m=>{if(!fc(m,n,this.currentDirection))return;let g=f&&f[m]||{};u&&(g={min:0,max:0});const y=o?200:1e6,E=o?40:1e7,v={type:"inertia",velocity:r?t[m]:0,bounceStiffness:y,bounceDamping:E,timeConstant:750,restDelta:1,restSpeed:10,...l,...g};return this.startAxisValueAnimation(m,v)});return Promise.all(p).then(d)}startAxisValueAnimation(t,n){const r=this.getAxisMotionValue(t);return Tg(this.visualElement,t),r.start($v(t,r,0,n,this.visualElement,!1))}stopAnimation(){ua(t=>this.getAxisMotionValue(t).stop())}getAxisMotionValue(t){const n=`_drag${t.toUpperCase()}`,r=this.visualElement.getProps(),o=r[n];return o||this.visualElement.getValue(t,(r.initial?r.initial[t]:void 0)||0)}snapToCursor(t){ua(n=>{const{drag:r}=this.getProps();if(!fc(n,r,this.currentDirection))return;const{projection:o}=this.visualElement,l=this.getAxisMotionValue(n);if(o&&o.layout){const{min:u,max:d}=o.layout.layoutBox[n],f=l.get()||0;l.set(t[n]-ut(u,d,.5)+f)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:t,dragConstraints:n}=this.getProps(),{projection:r}=this.visualElement;if(!go(n)||!r||!this.constraints)return;this.stopAnimation();const o={x:0,y:0};ua(u=>{const d=this.getAxisMotionValue(u);if(d&&this.constraints!==!1){const f=d.get();o[u]=oY({min:f,max:f},this.constraints[u])}});const{transformTemplate:l}=this.visualElement.getProps();this.visualElement.current.style.transform=l?l({},""):"none",r.root&&r.root.updateScroll(),r.updateLayout(),this.constraints=!1,this.resolveConstraints(),ua(u=>{if(!fc(u,t,null))return;const d=this.getAxisMotionValue(u),{min:f,max:p}=this.constraints[u];d.set(ut(f,p,o[u]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;uY.set(this.visualElement,this);const t=this.visualElement.current,n=el(t,"pointerdown",p=>{const{drag:m,dragListener:g=!0}=this.getProps(),y=p.target,E=y!==t&&Vq(y);m&&g&&!E&&this.start(p)});let r;const o=()=>{const{dragConstraints:p}=this.getProps();go(p)&&p.current&&(this.constraints=this.resolveRefConstraints(),r||(r=dY(t,p.current,()=>this.scalePositionWithinConstraints())))},{projection:l}=this.visualElement,u=l.addEventListener("measure",o);l&&!l.layout&&(l.root&&l.root.updateScroll(),l.updateLayout()),it.read(o);const d=ml(window,"resize",()=>this.scalePositionWithinConstraints()),f=l.addEventListener("didUpdate",(({delta:p,hasLayoutChanged:m})=>{this.isDragging&&m&&(ua(g=>{const y=this.getAxisMotionValue(g);y&&(this.originPoint[g]+=p[g].translate,y.set(y.get()+p[g].translate))}),this.visualElement.render())}));return()=>{d(),n(),u(),f&&f(),r&&r()}}getProps(){const t=this.visualElement.getProps(),{drag:n=!1,dragDirectionLock:r=!1,dragPropagation:o=!1,dragConstraints:l=!1,dragElastic:u=Dg,dragMomentum:d=!0}=t;return{...t,drag:n,dragDirectionLock:r,dragPropagation:o,dragConstraints:l,dragElastic:u,dragMomentum:d}}}function QN(e){let t=!0;return()=>{if(t){t=!1;return}e()}}function dY(e,t,n){const r=iN(e,QN(n)),o=iN(t,QN(n));return()=>{r(),o()}}function fc(e,t,n){return(t===!0||t===e)&&(n===null||n===e)}function pY(e,t=10){let n=null;return Math.abs(e.y)>t?n="y":Math.abs(e.x)>t&&(n="x"),n}class fY extends Dr{constructor(t){super(t),this.removeGroupControls=zn,this.removeListeners=zn,this.controls=new cY(t)}mount(){const{dragControls:t}=this.node.getProps();t&&(this.removeGroupControls=t.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||zn}update(){const{dragControls:t}=this.node.getProps(),{dragControls:n}=this.node.prevProps||{};t!==n&&(this.removeGroupControls(),t&&(this.removeGroupControls=t.subscribe(this.controls)))}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}}const Um=e=>(t,n)=>{e&&it.update(()=>e(t,n),!1,!0)};class mY extends Dr{constructor(){super(...arguments),this.removePointerDownListener=zn}onPointerDown(t){this.session=new R1(t,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:k1(this.node)})}createPanHandlers(){const{onPanSessionStart:t,onPanStart:n,onPan:r,onPanEnd:o}=this.node.getProps();return{onSessionStart:Um(t),onStart:Um(n),onMove:Um(r),onEnd:(l,u)=>{delete this.session,o&&it.postRender(()=>o(l,u))}}}mount(){this.removePointerDownListener=el(this.node.current,"pointerdown",t=>this.onPointerDown(t))}update(){this.session&&this.session.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session&&this.session.end()}}let Bm=!1;class gY extends A.Component{componentDidMount(){const{visualElement:t,layoutGroup:n,switchLayoutGroup:r,layoutId:o}=this.props,{projection:l}=t;l&&(n.group&&n.group.add(l),r&&r.register&&o&&r.register(l),Bm&&l.root.didUpdate(),l.addEventListener("animationComplete",()=>{this.safeToRemove()}),l.setOptions({...l.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),kc.hasEverUpdated=!0}getSnapshotBeforeUpdate(t){const{layoutDependency:n,visualElement:r,drag:o,isPresent:l}=this.props,{projection:u}=r;return u&&(u.isPresent=l,t.layoutDependency!==n&&u.setOptions({...u.options,layoutDependency:n}),Bm=!0,o||t.layoutDependency!==n||n===void 0||t.isPresent!==l?u.willUpdate():this.safeToRemove(),t.isPresent!==l&&(l?u.promote():u.relegate()||it.postRender(()=>{const d=u.getStack();(!d||!d.members.length)&&this.safeToRemove()}))),null}componentDidUpdate(){const{projection:t}=this.props.visualElement;t&&(t.root.didUpdate(),Yv.postRender(()=>{!t.currentAnimation&&t.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:t,layoutGroup:n,switchLayoutGroup:r}=this.props,{projection:o}=t;Bm=!0,o&&(o.scheduleCheckAfterUnmount(),n&&n.group&&n.group.remove(o),r&&r.deregister&&r.deregister(o))}safeToRemove(){const{safeToRemove:t}=this.props;t&&t()}render(){return null}}function _1(e){const[t,n]=b1(),r=A.useContext(kv);return S.jsx(gY,{...e,layoutGroup:r,switchLayoutGroup:A.useContext(T1),isPresent:t,safeToRemove:n})}const hY={pan:{Feature:mY},drag:{Feature:fY,ProjectionNode:h1,MeasureLayout:_1}};function JN(e,t,n){const{props:r}=e;e.animationState&&r.whileHover&&e.animationState.setActive("whileHover",n==="Start");const o="onHover"+n,l=r[o];l&&it.postRender(()=>l(t,Dl(t)))}class bY extends Dr{mount(){const{current:t}=this.node;t&&(this.unmount=zq(t,(n,r)=>(JN(this.node,r,"Start"),o=>JN(this.node,o,"End"))))}unmount(){}}class yY extends Dr{constructor(){super(...arguments),this.isActive=!1}onFocus(){let t=!1;try{t=this.node.current.matches(":focus-visible")}catch{t=!0}!t||!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=Cl(ml(this.node.current,"focus",()=>this.onFocus()),ml(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function e_(e,t,n){const{props:r}=e;if(e.current instanceof HTMLButtonElement&&e.current.disabled)return;e.animationState&&r.whileTap&&e.animationState.setActive("whileTap",n==="Start");const o="onTap"+(n==="End"?"":n),l=r[o];l&&it.postRender(()=>l(t,Dl(t)))}class EY extends Dr{mount(){const{current:t}=this.node;if(!t)return;const{globalTapTarget:n,propagate:r}=this.node.props;this.unmount=Yq(t,(o,l)=>(e_(this.node,l,"Start"),(u,{success:d})=>e_(this.node,u,d?"End":"Cancel")),{useGlobalTarget:n,stopPropagation:r?.tap===!1})}unmount(){}}const Lg=new WeakMap,Pm=new WeakMap,SY=e=>{const t=Lg.get(e.target);t&&t(e)},vY=e=>{e.forEach(SY)};function xY({root:e,...t}){const n=e||document;Pm.has(n)||Pm.set(n,{});const r=Pm.get(n),o=JSON.stringify(t);return r[o]||(r[o]=new IntersectionObserver(vY,{root:e,...t})),r[o]}function wY(e,t,n){const r=xY(t);return Lg.set(e,n),r.observe(e),()=>{Lg.delete(e),r.unobserve(e)}}const TY={some:0,all:1};class AY extends Dr{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:t={}}=this.node.getProps(),{root:n,margin:r,amount:o="some",once:l}=t,u={root:n?n.current:void 0,rootMargin:r,threshold:typeof o=="number"?o:TY[o]},d=f=>{const{isIntersecting:p}=f;if(this.isInView===p||(this.isInView=p,l&&!p&&this.hasEnteredView))return;p&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",p);const{onViewportEnter:m,onViewportLeave:g}=this.node.getProps(),y=p?m:g;y&&y(f)};return wY(this.node.current,u,d)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:t,prevProps:n}=this.node;["amount","margin","root"].some(kY(t,n))&&this.startObserver()}unmount(){}}function kY({viewport:e={}},{viewport:t={}}={}){return n=>e[n]!==t[n]}const RY={inView:{Feature:AY},tap:{Feature:EY},focus:{Feature:yY},hover:{Feature:bY}},NY={layout:{ProjectionNode:h1,MeasureLayout:_1}},_Y={...Q9,...RY,...hY,...NY},ui=Y9(_Y,W9);function CY({images:e,index:t,onClose:n,onNavigate:r}){const o=A.useCallback(()=>{t>0&&r(t-1)},[t,r]),l=A.useCallback(()=>{t<e.length-1&&r(t+1)},[t,e.length,r]);return A.useEffect(()=>{const u=d=>{d.key==="Escape"&&n(),d.key==="ArrowLeft"&&o(),d.key==="ArrowRight"&&l()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n,o,l]),S.jsx(qc,{children:S.jsxs(ui.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/90",onClick:n,children:[S.jsx("button",{onClick:n,className:"absolute top-4 right-4 z-10 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-white",children:S.jsx(Kc,{className:"h-5 w-5"})}),e.length>1&&S.jsxs("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 text-white/70 text-sm tabular-nums",children:[t+1," / ",e.length]}),t>0&&S.jsx("button",{onClick:u=>{u.stopPropagation(),o()},className:"absolute left-3 top-1/2 -translate-y-1/2 z-10 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-white",children:S.jsx(gM,{className:"h-6 w-6"})}),t<e.length-1&&S.jsx("button",{onClick:u=>{u.stopPropagation(),l()},className:"absolute right-3 top-1/2 -translate-y-1/2 z-10 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors text-white",children:S.jsx(bM,{className:"h-6 w-6"})}),S.jsx("img",{src:e[t],alt:"",className:"max-h-[85vh] max-w-[90vw] object-contain rounded-lg",onClick:u=>u.stopPropagation()})]})})}function OY({messages:e,streaming:t,streamBuffer:n,tools:r}){const o=A.useRef(null),[l,u]=A.useState(null),d=A.useCallback((m,g)=>{u({images:m,index:g})},[]);A.useEffect(()=>{o.current?.scrollIntoView({behavior:"smooth"})},[e,n,r,t]);const f=r.length>0?r[r.length-1]:null,p=f?.status==="running"?f.name:void 0;return S.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-4 flex flex-col min-h-0",children:[S.jsx("div",{className:"flex-1"}),e.length===0&&!t&&S.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-sm",children:"Start a conversation"}),S.jsxs("div",{className:"space-y-3",children:[e.map(m=>S.jsx(L5,{role:m.role,content:m.content,timestamp:m.timestamp,hasAttachments:m.hasAttachments,audioData:m.audioData,attachments:m.attachments,onImageClick:d},m.id)),t&&S.jsx(F5,{text:n,toolName:p})]}),S.jsx("div",{ref:o}),l&&S.jsx(CY,{images:l.images,index:l.index,onClose:()=>u(null),onNavigate:m=>u(g=>g?{...g,index:m}:null)})]})}function IY(e){const t=Math.floor(e/60),n=e%60;return`${t}:${n.toString().padStart(2,"0")}`}function DY(e,t=4*1024*1024){return new Promise(n=>{const r=new Image;r.onload=()=>{let{width:l,height:u}=r;if(l>1600||u>1600){const p=Math.min(1600/l,1600/u);l=Math.round(l*p),u=Math.round(u*p)}const d=document.createElement("canvas");d.width=l,d.height=u,d.getContext("2d").drawImage(r,0,0,l,u);for(const p of[.8,.6,.4,.3]){const m=d.toDataURL("image/jpeg",p);if(Math.round((m.length-23)*.75)<=t){n(m);return}}n(d.toDataURL("image/jpeg",.2))},r.onerror=()=>n(e),r.src=e})}function LY({onSend:e,onStop:t,streaming:n,whisperEnabled:r}){const[o,l]=A.useState(""),[u,d]=A.useState([]),[f,p]=A.useState(!1),[m,g]=A.useState(0),E=o.trim().length>0||u.length>0,v=A.useRef(null),T=A.useRef(null),k=A.useRef(null),w=A.useRef(null),C=A.useRef(null),_=A.useRef(0),L=A.useRef(0),F=A.useRef(null),D=A.useRef(!1),z=A.useRef(null),B=A.useRef(null),W=A.useRef([]),U=A.useRef(null);A.useEffect(()=>{const R=v.current;R&&(R.style.height="0px",R.style.height=`${Math.min(R.scrollHeight,88)}px`)},[o]),A.useEffect(()=>{if(f)return z.current=setInterval(()=>g(R=>R+1),1e3),()=>{z.current&&clearInterval(z.current)}},[f]);const X=A.useCallback(R=>{z.current&&clearInterval(z.current),F.current&&(clearTimeout(F.current),F.current=null),D.current=!1;const M=B.current,H=U.current;R||!M||M.state==="inactive"?(H?.getTracks().forEach(I=>I.stop()),B.current=null,U.current=null,W.current=[]):(M.onstop=async()=>{H?.getTracks().forEach(ue=>ue.stop());const I=new Blob(W.current,{type:"audio/webm"});if(W.current=[],B.current=null,U.current=null,I.size<1e3)return;const ce=new FileReader;ce.onloadend=async()=>{const ue=ce.result,de=ue.split(",")[1];if(de)try{const ke=await(await fetch("/api/whisper/transcribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({audio:de})})).json();ke.transcript?.trim()&&e(ke.transcript.trim(),void 0,ue)}catch{}},ce.readAsDataURL(I)},M.stop()),C.current&&(C.current.style.transform=""),p(!1),g(0),L.current=0},[e]),Q=A.useCallback(R=>{const M=R.type.startsWith("image/"),H=R.type==="application/pdf";if(!M&&!H)return;const I=new FileReader;I.onload=async ce=>{let ue=ce.target?.result;M&&(ue=await DY(ue)),d(de=>[...de,{id:Math.random().toString(36).slice(2),type:M?"image":"file",name:R.name,preview:ue}])},I.readAsDataURL(R)},[]),te=A.useCallback(R=>{const M=R.target.files;if(M){for(let H=0;H<M.length;H++)Q(M[H]);R.target.value=""}},[Q]),ie=A.useCallback(R=>{d(M=>M.filter(H=>H.id!==R))},[]);A.useEffect(()=>{const R=M=>{if(M.clipboardData?.items){for(const H of M.clipboardData.items)if(H.type.startsWith("image/")){M.preventDefault();const I=H.getAsFile();I&&Q(I)}}};return document.addEventListener("paste",R),()=>document.removeEventListener("paste",R)},[Q]);const ee=()=>{E&&(e(o,u.length>0?u:void 0),l(""),d([]),requestAnimationFrame(()=>v.current?.focus()))},j=A.useCallback(R=>{R.preventDefault(),_.current=R.clientX,L.current=0,R.currentTarget.setPointerCapture(R.pointerId),F.current=setTimeout(async()=>{if(r)try{const M=await navigator.mediaDevices.getUserMedia({audio:!0});U.current=M;const H=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":"audio/webm",I=new MediaRecorder(M,{mimeType:H});W.current=[],I.ondataavailable=ce=>{ce.data.size>0&&W.current.push(ce.data)},B.current=I,I.start(),D.current=!0,p(!0),g(0)}catch{}},200)},[]),V=A.useCallback(R=>{if(!D.current)return;const M=Math.min(0,R.clientX-_.current);if(L.current=M,C.current&&(C.current.style.transform=`translateX(${M}px)`),w.current){const H=w.current.getBoundingClientRect(),I=H.left+H.width/2;Math.abs(R.clientX-I)<36&&X(!0)}},[X]),Z=A.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null),D.current&&X(!1)},[X]),ne=A.useCallback(()=>{F.current&&(clearTimeout(F.current),F.current=null),D.current&&X(!0)},[X]);return S.jsxs("div",{className:"shrink-0 p-3 relative",children:[S.jsxs("div",{className:`flex flex-col transition-opacity duration-100 ${f?"opacity-0 pointer-events-none":"opacity-100"}`,children:[S.jsx(qc,{children:u.length>0&&S.jsx(ui.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:S.jsx("div",{className:"flex gap-2 px-3 pt-2.5 pb-2 flex-wrap bg-white/[0.04] border border-white/[0.08] rounded-2xl mb-2",children:u.map(R=>S.jsxs("div",{className:"relative group flex-shrink-0",children:[R.type==="image"?S.jsx("img",{src:R.preview,alt:R.name,className:"w-14 h-14 rounded-lg object-cover border border-white/10"}):S.jsxs("div",{className:"w-14 h-14 rounded-lg bg-white/5 border border-white/10 flex flex-col items-center justify-center gap-0.5 px-1",children:[S.jsx("svg",{className:"w-5 h-5 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:S.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),S.jsx("span",{className:"text-[8px] text-muted-foreground truncate w-full text-center",children:R.name.split(".").pop()})]}),S.jsx("button",{onClick:()=>ie(R.id),className:"absolute -top-1.5 -right-1.5 w-4 h-4 bg-black/80 border border-white/20 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:S.jsx(Kc,{className:"w-2.5 h-2.5 text-white"})})]},R.id))})})}),S.jsxs("div",{className:"flex items-end gap-2",children:[S.jsxs("div",{className:"flex-1 flex items-end bg-white rounded-2xl px-4",children:[S.jsx("textarea",{ref:v,value:o,onChange:R=>l(R.target.value),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 overflow-y-auto",style:{maxHeight:88}}),S.jsx("input",{ref:T,type:"file",className:"hidden",accept:"image/*,.pdf",multiple:!0,onChange:te}),S.jsx("input",{ref:k,type:"file",className:"hidden",accept:"image/*",capture:"environment",onChange:te}),S.jsx("button",{type:"button",onClick:()=>T.current?.click(),className:"shrink-0 p-1.5 mb-2 text-gray-400 hover:text-gray-600 transition-colors",children:S.jsx(zm,{className:"h-4 w-4"})}),S.jsx("button",{type:"button",onClick:()=>k.current?.click(),className:"shrink-0 p-1.5 mb-2 text-gray-400 hover:text-gray-600 transition-colors",children:S.jsx(dM,{className:"h-4 w-4"})})]}),n?S.jsx("button",{onClick:t,className:"flex items-center justify-center h-12 w-12 shrink-0 rounded-full bg-destructive text-destructive-foreground transition-colors",children:S.jsx(XM,{className:"h-4 w-4"})}):E?S.jsx("button",{onClick:ee,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:S.jsx(VM,{className:"h-4 w-4"})}):S.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:j,onPointerMove:V,onPointerUp:Z,onPointerCancel:ne,children:S.jsx(jm,{className:"h-4 w-4"})})]})]}),S.jsx(qc,{children:f&&S.jsx(ui.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:S.jsxs("div",{className:"flex items-center w-full gap-2",children:[S.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[S.jsxs("span",{className:"relative flex h-2 w-2 shrink-0",children:[S.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-destructive opacity-75"}),S.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-destructive"})]}),S.jsx("span",{className:"text-sm font-medium tabular-nums",children:IY(m)})]}),S.jsxs("div",{className:"flex-1 flex items-center bg-muted rounded-full h-12 pl-1 pr-0.5",children:[S.jsx("div",{ref:w,className:"flex items-center justify-center h-9 w-9 shrink-0 rounded-full bg-destructive/10 text-destructive",children:S.jsx(u_,{className:"h-4 w-4"})}),S.jsx("div",{className:"flex-1 flex justify-center min-w-0",children:S.jsx(ui.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"})}),S.jsx("div",{ref:C,className:"shrink-0 touch-none select-none will-change-transform",style:{transition:"none"},onPointerDown:j,onPointerMove:V,onPointerUp:Z,onPointerCancel:ne,children:S.jsx("div",{className:"flex items-center justify-center h-11 w-11 rounded-full bg-destructive text-destructive-foreground",children:S.jsx(jm,{className:"h-5 w-5"})})})]})]})})})]})}function MY({ws:e,clearContextRef:t,whisperEnabled:n}){const{messages:r,streaming:o,streamBuffer:l,tools:u,sendMessage:d,stopStreaming:f,clearContext:p}=dz(e);return t&&(t.current=p),S.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[S.jsx(OY,{messages:r,streaming:o,streamBuffer:l,tools:u}),S.jsx(LY,{onSend:d,onStop:f,streaming:o,whisperEnabled:n})]})}function FY({onClick:e}){return S.jsx(ui.div,{className:"fixed bottom-6 right-6 z-50 cursor-pointer",whileHover:{scale:1.1},whileTap:{scale:.95},onClick:e,role:"button","aria-label":"Open Fluxy chat",children:S.jsx("video",{src:"/fluxy_tilts.webm",poster:"/fluxy_frame1.png",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-11 w-auto drop-shadow-lg pointer-events-none",draggable:!1})})}const UY=[{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}],BY={anthropic:[{id:"claude-opus-4-6",label:"Opus 4.6"},{id:"claude-sonnet-4-6",label:"Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",label:"Haiku 4.5"}],openai:[{id:"gpt-5.2-codex:medium",label:"GPT-5.2 Codex Medium"},{id:"gpt-5.2-codex:high",label:"GPT-5.2 Codex High"},{id:"gpt-5.2-codex:xhigh",label:"GPT-5.2 Codex Extra High"},{id:"gpt-5.3-codex:medium",label:"GPT-5.3 Codex Medium (Pro)"},{id:"gpt-5.3-codex:high",label:"GPT-5.3 Codex High (Pro)"},{id:"gpt-5.3-codex:xhigh",label:"GPT-5.3 Codex Extra High (Pro)"}],ollama:[{id:"llama3.2",label:"Llama 3.2"},{id:"mistral",label:"Mistral"},{id:"codellama",label:"Code Llama"},{id:"phi3",label:"Phi-3"}]},t_=6,n_=[{tier:"premium",label:e=>`${e}.fluxy.bot`,badge:"$5",badgeCls:"bg-[#AF27E3]/15 text-[#AF27E3] border-[#AF27E3]/20",highlight:!0},{tier:"at",label:e=>`${e}.at.fluxy.bot`,badge:"Free",badgeCls:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",highlight:!1}];function PY({models:e,value:t,onChange:n}){const[r,o]=A.useState(!1),l=A.useRef(null);A.useEffect(()=>{if(!r)return;const d=f=>{l.current&&!l.current.contains(f.target)&&o(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[r]);const u=e.find(d=>d.id===t);return S.jsxs("div",{className:"relative",ref:l,children:[S.jsxs("button",{type:"button",onClick:()=>o(d=>!d),className:"w-full flex items-center justify-between bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none hover:border-white/15 focus:border-[#AF27E3]/30 transition-colors",children:[S.jsx("span",{className:u?"text-white":"text-white/20",children:u?u.label:"Choose a model..."}),S.jsx(hl,{className:`h-4 w-4 text-white/30 transition-transform ${r?"rotate-180":""}`})]}),r&&S.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:e.map(d=>S.jsx("button",{onClick:()=>{n(d.id),o(!1)},className:`w-full text-left px-4 py-2 text-[13px] transition-colors ${t===d.id?"text-[#AF27E3] bg-[#AF27E3]/10":"text-white/70 hover:bg-white/[0.04] hover:text-white"}`,children:d.label},d.id))})]})}function jY({onComplete:e}){const[t,n]=A.useState(0),[r,o]=A.useState(""),[l,u]=A.useState("anthropic"),[d,f]=A.useState(""),[p,m]=A.useState(!1),[g,y]=A.useState({anthropic:"idle",openai:"idle",ollama:"connected"}),[E,v]=A.useState(!1),[T,k]=A.useState(""),[w,C]=A.useState(!1),[_,L]=A.useState(),[F,D]=A.useState(!1),[z,B]=A.useState(!1),[W,U]=A.useState(),[X,Q]=A.useState(""),[te,ie]=A.useState(""),[ee,j]=A.useState(null),[V,Z]=A.useState(""),[ne,R]=A.useState({}),[M,H]=A.useState("at"),[I,ce]=A.useState(!1),[ue,de]=A.useState(!1),[me,ke]=A.useState(""),Se=A.useRef(null),[We,mt]=A.useState(null),[gt,It]=A.useState(!1),[Dt,Sa]=A.useState(!1),[mn,Lr]=A.useState(""),[kn,Ya]=A.useState(""),[na,Mr]=A.useState(""),[Go,yi]=A.useState(!1),[ct,$o]=A.useState(!1),[oe,fe]=A.useState(""),[we,Ne]=A.useState(""),[ze,Ht]=A.useState(!1),[Rn,Nt]=A.useState(!1),[Ze,Lt]=A.useState(!1),[Le,Gn]=A.useState(""),Qt=A.useRef(!1),va=g[l]==="connected";A.useEffect(()=>{fetch("/api/onboard/status").then(re=>re.json()).then(re=>{re.userName&&o(re.userName),re.handle&&(ie(re.handle.username),H(re.handle.tier||"at"),mt({username:re.handle.username,tier:re.handle.tier,url:re.handle.url}),de(!0),ke(re.handle.url)),re.portalUser&&Lr(re.portalUser),re.portalConfigured&&$o(!0),re.provider&&u(re.provider),re.model&&f(re.model),re.whisperEnabled&&(Lt(!0),Gn(re.whisperKey||"")),Qt.current=!0}).catch(()=>{Qt.current=!0})},[]),A.useEffect(()=>{l!=="anthropic"||g.anthropic==="connected"||fetch("/api/auth/claude/status").then(re=>re.json()).then(re=>{re.authenticated&&y(Ae=>({...Ae,anthropic:"connected"}))}).catch(()=>{})},[l]),A.useEffect(()=>{l!=="openai"||g.openai==="connected"||fetch("/api/auth/codex/status").then(re=>re.json()).then(re=>{re.authenticated&&y(Ae=>({...Ae,openai:"connected"}))}).catch(()=>{})},[l]),A.useEffect(()=>{if(!z)return;const re=setInterval(async()=>{try{(await(await fetch("/api/auth/codex/status")).json()).authenticated&&(B(!1),y(Xa=>({...Xa,openai:"connected"})))}catch{}},2e3);return()=>clearInterval(re)},[z]),A.useEffect(()=>{if(Se.current&&clearTimeout(Se.current),!Qt.current||We&&ue&&te===We.username)return;j(null),Z(""),R({}),de(!1),ke("");const re=te.trim();if(re){if(re.length<3){j("invalid"),Z("At least 3 characters");return}return j("checking"),Se.current=setTimeout(async()=>{try{const Mt=await(await fetch(`/api/handle/check/${encodeURIComponent(re)}`)).json();if(!Mt.valid)j("invalid"),Z(Mt.error);else{const Xa={};for(const Ur of Mt.handles)Xa[Ur.tier]=Ur.available;R(Xa),j("ready");const Bl=n_.find(Ur=>Xa[Ur.tier]);Bl&&!Xa[M]&&H(Bl.tier)}}catch{j(null)}},400),()=>{Se.current&&clearTimeout(Se.current)}}},[te]);const Ei=re=>{ie(re.toLowerCase().replace(/[^a-z0-9-]/g,""))},Si=async()=>{if(!(!te||ee!=="ready"||!ne[M])){ce(!0);try{const Ae=await(await fetch("/api/handle/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:te,tier:M})})).json();Ae.ok?(de(!0),ke(Ae.url)):(Z(Ae.error||"Registration failed"),j("invalid"))}catch{Z("Could not reach server"),j("invalid")}finally{ce(!1)}}},vi=async()=>{if(!(!te||ee!=="ready"||!ne[M])){Sa(!0);try{const Ae=await(await fetch("/api/handle/change",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:te,tier:M})})).json();Ae.ok?(de(!0),ke(Ae.url),mt({username:te,tier:M,url:Ae.url}),It(!1)):(Z(Ae.error||"Handle change failed"),j("invalid"))}catch{Z("Could not reach server"),j("invalid")}finally{Sa(!1)}}},xa=re=>{l==="openai"&&re!=="openai"&&z&&(fetch("/api/auth/codex/cancel",{method:"POST"}),B(!1)),u(re),f(""),v(!1),k(""),L(void 0),B(!1),U(void 0)},xi=async()=>{L(void 0);try{const Ae=await(await fetch("/api/auth/claude/start",{method:"POST"})).json();Ae.success&&Ae.authUrl?(window.open(Ae.authUrl,"_blank"),v(!0)):L(Ae.error||"Failed to start authentication")}catch(re){L(re.message)}},Wa=async()=>{if(T.trim()){C(!0),L(void 0);try{const Ae=await(await fetch("/api/auth/claude/exchange",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:T.trim()})})).json();Ae.success?y(Mt=>({...Mt,anthropic:"connected"})):L(Ae.error||"Code exchange failed")}catch(re){L(re.message)}finally{C(!1)}}},Cd=async()=>{try{const re=await navigator.clipboard.readText();re&&k(re.trim())}catch{}},Ll=async()=>{D(!0),L(void 0);try{(await(await fetch("/api/auth/claude/status")).json()).authenticated?y(Mt=>({...Mt,anthropic:"connected"})):L("No active session found. Please authenticate first.")}catch{}finally{D(!1)}},Ho=async()=>{B(!0),U(void 0);try{const Ae=await(await fetch("/api/auth/codex/start",{method:"POST"})).json();Ae.success&&Ae.authUrl?window.open(Ae.authUrl,"_blank"):(B(!1),U(Ae.error||"Failed to start authentication"))}catch(re){B(!1),U(re.message)}},Fr=()=>{B(!1),fetch("/api/auth/codex/cancel",{method:"POST"})},Ml=kn===na,Vo=mn.trim().length>=3&&kn.length>=6&&Ml,Fl=ct?mn.trim().length>=3&&(kn.length===0||ze&&Vo):Vo,Ka=(()=>{switch(t){case 0:return!0;case 1:return r.trim().length>0;case 2:return ue;case 3:return Fl;case 4:return!!(l&&d&&va);case 5:return!0;default:return!1}})(),$n=()=>{Ka&&t<t_-1&&n(re=>re+1)},qo=()=>{t>0&&n(re=>re-1)},wi=re=>{re.key==="Enter"&&Ka&&$n()},Ul=async()=>{m(!0);try{await fetch("/api/onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userName:r.trim(),agentName:te.trim()||"Fluxy",provider:l,model:d,apiKey:"",baseUrl:l==="ollama"&&X||void 0,whisperEnabled:Ze,whisperKey:Ze?Le:"",portalUser:mn.trim(),portalPass:kn})}),e()}catch(re){console.error("Onboard failed:",re),m(!1)}},Vt="w-full bg-white/[0.05] border border-white/[0.08] text-white rounded-xl px-4 py-3 text-base outline-none input-glow placeholder:text-white/20 transition-all",yt="w-full bg-white/[0.03] border border-white/[0.08] text-white rounded-xl px-4 py-2.5 text-[13px] outline-none input-glow placeholder:text-white/20 transition-all";return S.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4",children:[S.jsx("div",{className:"absolute inset-0 bg-black/85 backdrop-blur-md"}),S.jsxs(ui.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:[S.jsx("div",{className:"flex justify-center gap-2 pt-6",children:Array.from({length:t_},(re,Ae)=>S.jsx("div",{className:`h-1.5 rounded-full transition-all duration-300 ${Ae===t?"w-7 bg-gradient-brand":Ae<t?"w-1.5 bg-gradient-brand opacity-60":"w-1.5 bg-white/10"}`},Ae))}),S.jsx(qc,{mode:"wait",children:S.jsxs(ui.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:[t===0&&S.jsxs("div",{className:"flex flex-col items-center text-center",children:[S.jsx("video",{src:"/fluxy_say_hi.webm",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"h-[180px] mb-4"}),S.jsx("h1",{className:"text-2xl font-bold text-white tracking-tight",children:"Welcome to Fluxy"}),S.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."}),S.jsxs("button",{onClick:$n,className:"mt-6 px-7 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center gap-2",children:["Get Started",S.jsx(sa,{className:"h-4 w-4"})]})]}),t===1&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"What's your name?"}),S.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"This is how your agent will address you."}),S.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[S.jsx("input",{type:"text",value:r,onChange:re=>o(re.target.value),onKeyDown:wi,placeholder:"Enter your name",autoFocus:!0,className:Vt+" flex-1"}),S.jsx("button",{onClick:$n,disabled:!Ka,className:"shrink-0 h-12 w-12 flex items-center justify-center rounded-full bg-gradient-brand hover:opacity-90 text-white transition-colors disabled:opacity-30",children:S.jsx(sa,{className:"h-5 w-5"})})]})]}),t===2&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Name your bot"}),S.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."}),We&&ue&&!gt&&S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"}),S.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Current handle"})]}),S.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:me})]}),S.jsxs("div",{className:"flex gap-2 mt-4",children:[S.jsxs("button",{onClick:$n,className:"flex-1 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]}),S.jsx("button",{onClick:()=>{It(!0),de(!1),ie(""),j(null),R({})},className:"px-5 py-3 bg-white/[0.04] hover:bg-white/[0.08] border border-white/[0.08] text-white/60 text-[13px] font-medium rounded-full transition-colors",children:"Change"})]})]}),gt&&!ue&&S.jsxs("div",{className:"mt-4 bg-amber-500/8 border border-amber-500/20 rounded-xl px-4 py-3",children:[S.jsx("p",{className:"text-amber-400/90 text-[13px] font-medium",children:"Changing your handle"}),S.jsxs("p",{className:"text-amber-400/60 text-[12px] mt-1",children:["Your current handle ",S.jsx("span",{className:"font-mono",children:We?.url})," will be released and become available for others."]})]}),(!We||gt||!ue)&&!(We&&ue&&!gt)&&S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"relative mt-5",children:[S.jsx("input",{type:"text",value:te,onChange:re=>Ei(re.target.value),maxLength:30,placeholder:"your-bot-name",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",autoFocus:!0,disabled:ue,className:Vt+" pr-10 font-mono"+(ue?" opacity-50":"")}),ee&&te.length>0&&!ue&&S.jsxs("div",{className:"absolute right-4 top-1/2 -translate-y-1/2",children:[ee==="checking"&&S.jsx("div",{className:"w-5 h-5 border-2 border-white/10 border-t-[#04D1FE] rounded-full animate-spin"}),ee==="invalid"&&S.jsx("div",{className:"w-6 h-6 rounded-full bg-amber-500/15 flex items-center justify-center",children:S.jsx("svg",{className:"w-3.5 h-3.5 text-amber-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:S.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3m0 4h.01"})})})]})]}),ee==="invalid"&&V&&S.jsx("p",{className:"text-amber-400 text-[12px] mt-2",children:V}),ee==="ready"&&te.length>0&&!ue&&S.jsx("div",{className:"space-y-2 mt-4",children:n_.map(re=>{const Mt=ne[re.tier]===!1;return S.jsxs("button",{onClick:()=>!Mt&&H(re.tier),disabled:Mt,className:`w-full flex items-center justify-between px-4 py-3 rounded-xl border transition-all duration-200 text-left ${Mt?"border-white/[0.04] bg-transparent opacity-50 cursor-not-allowed":M===re.tier?re.highlight?"border-[#AF27E3]/40 bg-[#AF27E3]/[0.06]":"border-[#AF27E3]/30 bg-white/[0.04]":"border-white/[0.06] bg-transparent hover:border-white/10 hover:bg-white/[0.02]"}`,children:[S.jsx("span",{className:"font-mono text-[13px] text-white/70",children:re.label(te)}),Mt?S.jsx("span",{className:"text-[11px] font-medium px-2.5 py-0.5 rounded-full border bg-red-500/10 text-red-400 border-red-500/20",children:"Taken"}):S.jsx("span",{className:`text-[11px] font-medium px-2.5 py-0.5 rounded-full border ${re.badgeCls}`,children:re.badge})]},re.tier)})}),ue&&S.jsxs("div",{className:"mt-4 bg-emerald-500/8 border border-emerald-500/15 rounded-xl px-4 py-3",children:[S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"}),S.jsx("p",{className:"text-emerald-400/90 text-[13px] font-medium",children:"Handle claimed!"})]}),S.jsx("p",{className:"text-emerald-400/60 text-[12px] mt-1 font-mono",children:me})]}),ee==="ready"&&ne[M]&&te.length>0&&!ue&&S.jsx("button",{onClick:gt?vi:Si,disabled:I||Dt,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:I||Dt?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-4 w-4 animate-spin"}),gt?"Changing...":"Claiming..."]}):S.jsxs(S.Fragment,{children:[gt?"Change Handle":"Claim & Continue",S.jsx(sa,{className:"h-4 w-4"})]})}),ue&&S.jsxs("button",{onClick:$n,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]}),gt&&!ue&&S.jsx("button",{onClick:()=>{It(!1),ie(We.username),de(!0),ke(We.url),H(We.tier),j(null)},className:"w-full mt-2 py-2 text-white/25 hover:text-white/40 text-[12px] transition-colors",children:"Cancel — keep current handle"})]})]}),t===3&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Secure your portal"}),S.jsx("p",{className:"text-white/40 text-[13px] mt-1.5 leading-relaxed",children:"Create credentials to protect your dashboard. Anyone with your URL will need these to log in."}),ue&&me&&S.jsxs("div",{className:"mt-4 flex items-center gap-2 bg-white/[0.03] border border-white/[0.06] rounded-xl px-4 py-3",children:[S.jsx("span",{className:"font-mono text-[13px] text-white/60 truncate flex-1",children:me}),S.jsx("button",{onClick:()=>{navigator.clipboard.writeText(me),yi(!0),setTimeout(()=>yi(!1),2e3)},className:"shrink-0 text-white/30 hover:text-white/60 transition-colors",children:Go?S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"}):S.jsxs("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[S.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),S.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),ct&&S.jsx("div",{className:"mt-4 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-2.5",children:S.jsx("p",{className:"text-white/40 text-[12px]",children:"Credentials already set. Leave password fields empty to keep your current password, or enter your current password to change it."})}),S.jsxs("div",{className:"mt-5",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Username"}),S.jsx("input",{type:"text",value:mn,onChange:re=>Lr(re.target.value.replace(/\s/g,"").toLowerCase()),placeholder:"admin",autoFocus:!0,autoComplete:"username",className:Vt+" font-mono"}),mn.length>0&&mn.trim().length<3&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 3 characters"})]}),ct&&S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Current password"}),S.jsxs("div",{className:"flex items-center gap-2",children:[S.jsx("input",{type:"password",value:oe,onChange:re=>{fe(re.target.value),Ne(""),Ht(!1)},placeholder:"Enter current password to change it",autoComplete:"current-password",className:Vt+" flex-1"}),oe.length>0&&!ze&&S.jsx("button",{onClick:async()=>{Nt(!0),Ne("");try{(await(await fetch("/api/portal/verify-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:oe})})).json()).valid?Ht(!0):Ne("Incorrect password")}catch{Ne("Could not verify")}finally{Nt(!1)}},disabled:Rn,className:"shrink-0 px-4 py-3 bg-white/[0.06] hover:bg-white/[0.1] text-white/60 text-[13px] font-medium rounded-xl transition-colors disabled:opacity-40",children:Rn?S.jsx(so,{className:"h-4 w-4 animate-spin"}):"Verify"}),ze&&S.jsx("div",{className:"shrink-0 w-10 h-10 flex items-center justify-center",children:S.jsx(Bs,{className:"h-4 w-4 text-emerald-400"})})]}),we&&S.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:we})]}),(!ct||ze)&&S.jsxs(S.Fragment,{children:[S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:ct?"New password":"Password"}),S.jsx("input",{type:"password",value:kn,onChange:re=>Ya(re.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:wi,className:Vt}),kn.length>0&&kn.length<6&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"At least 6 characters"})]}),S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:ct?"Confirm new password":"Confirm password"}),S.jsx("input",{type:"password",value:na,onChange:re=>Mr(re.target.value),placeholder:"••••••••",autoComplete:"new-password",onKeyDown:wi,className:Vt}),na.length>0&&!Ml&&S.jsx("p",{className:"text-red-400/70 text-[11px] mt-1",children:"Passwords don't match"})]})]}),S.jsxs("button",{onClick:$n,disabled:!Ka,className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]})]}),t===4&&S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Choose your AI provider"}),S.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."}),S.jsx("div",{className:"flex gap-2.5 mt-4",children:UY.map(re=>S.jsxs("button",{onClick:()=>xa(re.id),className:`flex-1 relative rounded-xl border transition-all duration-200 p-3 text-left ${l===re.id?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:[S.jsxs("div",{className:"flex flex-col items-center gap-1.5 py-0.5",children:[re.icon?S.jsx("img",{src:re.icon,alt:re.name,className:"w-8 h-8 rounded-lg"}):S.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"}),S.jsxs("div",{className:"text-center",children:[S.jsx("div",{className:"text-[13px] font-medium text-white",children:re.name}),S.jsx("div",{className:"text-[10px] text-white/30",children:re.subtitle})]})]}),g[re.id]==="connected"?S.jsx("div",{className:"absolute top-2 right-2 w-4 h-4 rounded-full bg-emerald-500/15 flex items-center justify-center",children:S.jsx(Bs,{className:"h-2.5 w-2.5 text-emerald-400"})}):l===re.id?S.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 rounded-full bg-gradient-brand"}):null]},re.id))}),S.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),l==="anthropic"&&S.jsxs("div",{className:"space-y-2.5",children:[va&&S.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — Anthropic subscription is active."})}),!va&&S.jsxs(S.Fragment,{children:[_&&S.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-red-400/90 text-[12px]",children:_})}),S.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((re,Ae)=>S.jsxs("div",{className:"flex items-start gap-2",children:[S.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:Ae+1}),S.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:re})]},Ae))}),S.jsx("button",{onClick:xi,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2",children:E?S.jsxs(S.Fragment,{children:[S.jsx(AM,{className:"h-3.5 w-3.5 opacity-60"}),"Open authentication page again"]}):S.jsxs(S.Fragment,{children:["Authenticate with Anthropic",S.jsx(sa,{className:"h-3.5 w-3.5 opacity-60"})]})}),S.jsxs("div",{className:"relative",children:[S.jsx("input",{type:"text",value:T,onChange:re=>k(re.target.value),onKeyDown:re=>re.key==="Enter"&&Wa(),placeholder:"Paste your code here...",className:yt+" pr-10 font-mono"}),S.jsx("button",{onClick:Cd,className:"absolute right-3 top-1/2 -translate-y-1/2 text-white/20 hover:text-white/50 transition-colors",children:S.jsx(EM,{className:"h-3.5 w-3.5"})})]}),S.jsx("button",{onClick:Wa,disabled:!T.trim()||w,className:"w-full py-2.5 px-4 bg-gradient-brand hover:opacity-90 text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:w?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-3.5 w-3.5 animate-spin"}),"Verifying..."]}):"Connect"}),S.jsxs("button",{onClick:Ll,disabled:F,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:[F?S.jsx(so,{className:"h-3 w-3 animate-spin"}):S.jsx(zM,{className:"h-3 w-3"}),F?"Checking...":"I'm already authenticated"]})]})]}),l==="openai"&&S.jsxs("div",{className:"space-y-2.5",children:[va&&S.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"Connected — ChatGPT subscription is active."})}),!va&&S.jsxs(S.Fragment,{children:[W&&S.jsx("div",{className:"bg-red-500/8 border border-red-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-red-400/90 text-[12px]",children:W})}),S.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((re,Ae)=>S.jsxs("div",{className:"flex items-start gap-2",children:[S.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:Ae+1}),S.jsx("p",{className:"text-white/40 text-[12px] leading-relaxed",children:re})]},Ae))}),S.jsx("button",{onClick:Ho,disabled:z,className:"w-full py-2.5 px-4 bg-white/[0.06] hover:bg-white/[0.09] text-white text-[13px] font-medium rounded-xl transition-colors flex items-center justify-center gap-2 disabled:opacity-60",children:z?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-3.5 w-3.5 animate-spin opacity-60"}),"Waiting for sign-in..."]}):S.jsxs(S.Fragment,{children:["Authenticate with ChatGPT",S.jsx(sa,{className:"h-3.5 w-3.5 opacity-60"})]})}),z&&S.jsx("button",{onClick:Fr,className:"w-full py-1.5 text-white/25 text-[11px] hover:text-white/40 transition-colors",children:"Cancel"})]})]}),l==="ollama"&&S.jsxs("div",{className:"space-y-2.5",children:[S.jsx("div",{className:"bg-emerald-500/8 border border-emerald-500/15 rounded-lg px-3.5 py-2.5",children:S.jsx("p",{className:"text-emerald-400/90 text-[12px]",children:"No authentication needed — Ollama runs locally."})}),S.jsxs("div",{children:[S.jsxs("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:["Base URL ",S.jsx("span",{className:"text-white/20",children:"(optional)"})]}),S.jsx("input",{type:"text",value:X,onChange:re=>Q(re.target.value),placeholder:"http://localhost:11434",className:yt})]})]}),va&&S.jsxs(S.Fragment,{children:[S.jsx("div",{className:"border-t border-white/[0.06] mt-4 mb-3"}),S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"Select a model"}),S.jsx(PY,{models:BY[l]||[],value:d,onChange:f})]}),va&&S.jsxs("button",{onClick:$n,disabled:!Ka,className:"w-full mt-4 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:["Continue",S.jsx(sa,{className:"h-4 w-4"})]})]}),t===5&&S.jsxs("div",{children:[S.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[S.jsx("h1",{className:"text-xl font-bold text-white tracking-tight",children:"Voice Messages"}),S.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"})]}),S.jsx("p",{className:"text-white/40 text-[13px] mt-1 leading-relaxed",children:"Allow users to send audio messages that are automatically transcribed."}),S.jsx("button",{onClick:()=>Lt(re=>!re),className:`w-full mt-5 rounded-xl border transition-all duration-200 p-4 text-left ${Ze?"bg-white/[0.04] border-[#AF27E3]/40":"bg-transparent border-white/[0.06] hover:border-white/10 hover:bg-white/[0.02]"}`,children:S.jsxs("div",{className:"flex items-center gap-3.5",children:[S.jsx("img",{src:"/icons/openai.svg",alt:"OpenAI",className:"w-10 h-10 rounded-xl bg-white/[0.04] p-1.5"}),S.jsxs("div",{className:"flex-1",children:[S.jsx("div",{className:"text-[14px] font-medium text-white",children:"OpenAI Whisper"}),S.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."})]}),S.jsx("div",{className:`w-10 h-[22px] rounded-full transition-colors duration-200 flex items-center px-0.5 shrink-0 ${Ze?"bg-gradient-brand":"bg-white/[0.08]"}`,children:S.jsx("div",{className:`w-[18px] h-[18px] rounded-full bg-white shadow-sm transition-transform duration-200 ${Ze?"translate-x-[18px]":"translate-x-0"}`})})]})}),Ze&&S.jsxs("div",{className:"mt-3",children:[S.jsx("label",{className:"text-[12px] text-white/40 font-medium mb-1.5 block",children:"OpenAI API Key"}),S.jsx("input",{type:"password",value:Le,onChange:re=>Gn(re.target.value.trim()),placeholder:"sk-...",autoComplete:"off",className:Vt+" font-mono text-[13px]"}),Le.length>0&&!Le.startsWith("sk-")&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key should start with sk-"}),Le.length>0&&Le.startsWith("sk-")&&Le.length<20&&S.jsx("p",{className:"text-amber-400/70 text-[11px] mt-1",children:"Key looks too short"}),S.jsxs("div",{className:"flex items-start gap-2.5 mt-3 bg-white/[0.02] border border-white/[0.06] rounded-xl px-4 py-3",children:[S.jsx(jm,{className:"h-4 w-4 text-[#AF27E3]/60 mt-0.5 shrink-0"}),S.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."})]})]}),S.jsx("button",{onClick:Ul,disabled:p||Ze&&(!Le.startsWith("sk-")||Le.length<20),className:"w-full mt-5 py-3 bg-gradient-brand hover:opacity-90 text-white text-[14px] font-semibold rounded-full transition-colors flex items-center justify-center gap-2 disabled:opacity-40",children:p?S.jsxs(S.Fragment,{children:[S.jsx(so,{className:"h-4 w-4 animate-spin"}),"Setting up..."]}):S.jsxs(S.Fragment,{children:["Complete Setup",S.jsx(sa,{className:"h-4 w-4"})]})}),!Ze&&S.jsx("p",{className:"text-center text-white/20 text-[11px] mt-2.5",children:"You can enable this later in Settings."})]})]},t)}),t>0&&S.jsx("div",{className:"px-8 pb-5 -mt-3",children:S.jsx("button",{onClick:qo,className:"text-white/25 hover:text-white/50 text-[12px] transition-colors",children:"← Back"})})]})]})}function zY({...e}){return S.jsx(Uj,{"data-slot":"dropdown-menu",...e})}function GY({...e}){return S.jsx(Bj,{"data-slot":"dropdown-menu-trigger",...e})}function $Y({className:e,sideOffset:t=4,...n}){return S.jsx(Pj,{children:S.jsx(jj,{"data-slot":"dropdown-menu-content",sideOffset:t,className:pn("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",e),...n})})}function HY({className:e,inset:t,variant:n="default",...r}){return S.jsx(zj,{"data-slot":"dropdown-menu-item","data-inset":t,"data-variant":n,className:pn("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r})}function VY(){return S.jsx("div",{className:"flex items-center justify-center h-dvh p-6 text-center",children:S.jsxs("div",{children:[S.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Something went wrong"}),S.jsx("p",{className:"text-sm text-muted-foreground",children:"The dashboard encountered an error. Use the Fluxy button to continue chatting."})]})})}function qY(){const[e,t]=A.useState(!1),[n,r]=A.useState(!1),[o,l]=A.useState("Fluxy"),[u,d]=A.useState(!1),{ws:f,connected:p}=XL(),m=A.useRef(null);A.useEffect(()=>{fetch("/api/settings").then(y=>y.json()).then(y=>{y.onboard_complete!=="true"&&r(!0),y.agent_name&&l(y.agent_name),y.whisper_enabled==="true"&&d(!0)}).catch(()=>{})},[]);const g=()=>{r(!1),fetch("/api/settings").then(y=>y.json()).then(y=>{y.agent_name&&l(y.agent_name),d(y.whisper_enabled==="true")}).catch(()=>{})};return S.jsxs(S.Fragment,{children:[S.jsx(t2,{fallback:S.jsx(VY,{}),children:S.jsx(iz,{onOpenOnboard:()=>r(!0),children:S.jsx(cz,{})})}),S.jsx(wC,{open:e,onOpenChange:t,children:S.jsxs(TC,{side:"right",className:"w-full sm:max-w-md !gap-0 !p-0 !border-l-0 !h-dvh overflow-hidden",onOpenAutoFocus:y=>y.preventDefault(),children:[S.jsxs("div",{className:"flex items-center gap-3 px-4 pr-12 py-3 border-b border-border shrink-0",children:[S.jsx("img",{src:"/fluxy.png",alt:o,className:"h-5 w-auto"}),S.jsx(AC,{className:"text-sm font-semibold",children:o}),S.jsx("div",{className:`h-2 w-2 rounded-full ${p?"bg-green-500":"bg-red-500"}`}),S.jsx("div",{className:"flex-1"}),S.jsxs(zY,{children:[S.jsx(GY,{asChild:!0,children:S.jsx("button",{className:"flex items-center justify-center h-7 w-7 rounded-full text-muted-foreground hover:text-foreground hover:bg-white/[0.06] transition-colors",children:S.jsx(vM,{className:"h-4 w-4"})})}),S.jsx($Y,{align:"end",sideOffset:8,children:S.jsxs(HY,{onClick:()=>m.current?.(),children:[S.jsx(u_,{className:"h-3.5 w-3.5"}),"Clear Context"]})})]}),S.jsxs(nz,{className:"sr-only",children:["Chat with your ",o," AI assistant"]})]}),S.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:S.jsx(MY,{ws:f,clearContextRef:m,whisperEnabled:u})})]})}),S.jsx(FY,{onClick:()=>t(y=>!y)}),n&&S.jsx(jY,{onComplete:g})]})}KL.createRoot(document.getElementById("root")).render(S.jsx(zt.StrictMode,{children:S.jsx(qY,{})}));
package/dist/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, interactive-widget=resizes-content" />
6
6
  <meta name="theme-color" content="#212121" />
7
7
  <title>Fluxy</title>
8
- <script type="module" crossorigin src="/assets/index-CW6a7xtX.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-D8wa5QyC.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-Dpj8titN.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,i={};const s=(s,t)=>(s=new URL(s+".js",t).href,i[s]||new Promise(i=>{if("document"in self){const e=document.createElement("script");e.src=s,e.onload=i,document.head.appendChild(e)}else e=s,importScripts(s),i()}).then(()=>{let e=i[s];if(!e)throw new Error(`Module ${s} didn’t register its module`);return e}));self.define=(t,n)=>{const r=e||("document"in self?document.currentScript.src:"")||location.href;if(i[r])return;let o={};const l=e=>s(e,r),d={module:{uri:r},exports:o,require:l};i[r]=Promise.all(t.map(e=>d[e]||l(e))).then(e=>(n(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"34e37a8e7d80036d1f96c18d12f3d5c3"},{url:"assets/index-Dpj8titN.css",revision:null},{url:"assets/index-CW6a7xtX.js",revision:null},{url:"manifest.webmanifest",revision:"f73683d89ca6b3b7b63451130e165f71"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});
1
+ if(!self.define){let e,i={};const s=(s,n)=>(s=new URL(s+".js",n).href,i[s]||new Promise(i=>{if("document"in self){const e=document.createElement("script");e.src=s,e.onload=i,document.head.appendChild(e)}else e=s,importScripts(s),i()}).then(()=>{let e=i[s];if(!e)throw new Error(`Module ${s} didn’t register its module`);return e}));self.define=(n,t)=>{const r=e||("document"in self?document.currentScript.src:"")||location.href;if(i[r])return;let o={};const l=e=>s(e,r),c={module:{uri:r},exports:o,require:l};i[r]=Promise.all(n.map(e=>c[e]||l(e))).then(e=>(t(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"2c070fe5b292d5cff3896de969c36d81"},{url:"assets/index-Dpj8titN.css",revision:null},{url:"assets/index-D8wa5QyC.js",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.24",
3
+ "version": "0.1.26",
4
4
  "description": "Self-hosted AI bot — run your own AI assistant from anywhere",
5
5
  "type": "module",
6
6
  "license": "MIT",