UNPKG

decocms

Version:

Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools

5 lines • 70.1 kB
import{r as $,cd as nt,c as U,b as ie,j as i,gl as ke,o as lt,gm as rt,a6 as be,an as we,q as _e,aH as We,aI as Ue,e as je,I as fe,aJ as Be,aK as xe,K as pe,t as le,B as oe,y as Ve,E as ne,D as ot,v as at,w as ct,x as dt,h as Oe,m as ge,e3 as J,d as ht,R as ut,a7 as mt}from"./index-DoEtSiIe.js";import{C as ft}from"./checkbox-CkODjqKt.js";import{S as pt,b as xt,a as gt,d as vt,c as bt}from"./select-OlcoUSVg.js";import{i as He}from"./ArrowLeft-DuGHc_Gh.js";import{i as yt}from"./ChevronSelectorVertical-Cvgyclsz.js";import{i as jt}from"./Key01-DfLmV_su.js";import{i as qe,t as St,f as Nt,e as kt,d as wt,a as _t,s as It}from"./Tool01-D90Wr5xR.js";import{i as Ye}from"./SearchMd-BGRe_18c.js";import{e as Ie,u as Ct,a as Mt,c as Et}from"./use-ai-providers-BwkzkRi2.js";import{d as Ot}from"./chat-context-vJ6R-Clt.js";import{g as Ce}from"./ai-providers-logos-DD3qZ33J.js";import{g as ve}from"./openai-compatible-presets-BKGfVqEx.js";import{i as zt}from"./Monitor01-DUhT2Mcw.js";import{i as Pt}from"./AlertCircle-GoAGGV0G.js";import{u as At}from"./use-entitlements-4v7LU4jM.js";import{s as Qe}from"./Eye-DwRCQHLk.js";import{t as ze}from"./ChevronDown-Dm2xO7jf.js";import{a as Ft}from"./Image01-BRABRo3v.js";function me(n,e,t){let s=t.initialDeps??[],l,r=!0;function a(){var c,h,d;let o;t.key&&((c=t.debug)!=null&&c.call(t))&&(o=Date.now());const m=n();if(!(m.length!==s.length||m.some((f,g)=>s[g]!==f)))return l;s=m;let u;if(t.key&&((h=t.debug)!=null&&h.call(t))&&(u=Date.now()),l=e(...m),t.key&&((d=t.debug)!=null&&d.call(t))){const f=Math.round((Date.now()-o)*100)/100,g=Math.round((Date.now()-u)*100)/100,I=g/16,S=(y,w)=>{for(y=String(y);y.length<w;)y=" "+y;return y};console.info(`%c⏱ ${S(g,5)} /${S(f,5)} ms`,`
            font-size: .6rem;
            font-weight: bold;
            color: hsl(${Math.max(0,Math.min(120-120*I,120))}deg 100% 31%);`,t?.key)}return t?.onChange&&!(r&&t.skipInitialOnChange)&&t.onChange(l),r=!1,l}return a.updateDeps=c=>{s=c},a}function Pe(n,e){if(n===void 0)throw new Error("Unexpected undefined");return n}const Tt=(n,e)=>Math.abs(n-e)<1.01,Rt=(n,e,t)=>{let s;return function(...l){n.clearTimeout(s),s=n.setTimeout(()=>e.apply(this,l),t)}},Ae=n=>{const{offsetWidth:e,offsetHeight:t}=n;return{width:e,height:t}},Kt=n=>n,Lt=n=>{const e=Math.max(n.startIndex-n.overscan,0),t=Math.min(n.endIndex+n.overscan,n.count-1),s=[];for(let l=e;l<=t;l++)s.push(l);return s},Dt=(n,e)=>{const t=n.scrollElement;if(!t)return;const s=n.targetWindow;if(!s)return;const l=a=>{const{width:c,height:h}=a;e({width:Math.round(c),height:Math.round(h)})};if(l(Ae(t)),!s.ResizeObserver)return()=>{};const r=new s.ResizeObserver(a=>{const c=()=>{const h=a[0];if(h?.borderBoxSize){const d=h.borderBoxSize[0];if(d){l({width:d.inlineSize,height:d.blockSize});return}}l(Ae(t))};n.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return r.observe(t,{box:"border-box"}),()=>{r.unobserve(t)}},Fe={passive:!0},Te=typeof window>"u"?!0:"onscrollend"in window,$t=(n,e)=>{const t=n.scrollElement;if(!t)return;const s=n.targetWindow;if(!s)return;let l=0;const r=n.options.useScrollendEvent&&Te?()=>{}:Rt(s,()=>{e(l,!1)},n.options.isScrollingResetDelay),a=o=>()=>{const{horizontal:m,isRtl:p}=n.options;l=m?t.scrollLeft*(p&&-1||1):t.scrollTop,r(),e(l,o)},c=a(!0),h=a(!1);t.addEventListener("scroll",c,Fe);const d=n.options.useScrollendEvent&&Te;return d&&t.addEventListener("scrollend",h,Fe),()=>{t.removeEventListener("scroll",c),d&&t.removeEventListener("scrollend",h)}},Wt=(n,e,t)=>{if(e?.borderBoxSize){const s=e.borderBoxSize[0];if(s)return Math.round(s[t.options.horizontal?"inlineSize":"blockSize"])}return n[t.options.horizontal?"offsetWidth":"offsetHeight"]},Ut=(n,{adjustments:e=0,behavior:t},s)=>{var l,r;const a=n+e;(r=(l=s.scrollElement)==null?void 0:l.scrollTo)==null||r.call(l,{[s.options.horizontal?"left":"top"]:a,behavior:t})};class Bt{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var t,s,l;return((l=(s=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:s.now)==null?void 0:l.call(s))??Date.now()},this.observer=(()=>{let t=null;const s=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(l=>{l.forEach(r=>{const a=()=>{const c=r.target,h=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);return}this.shouldMeasureDuringScroll(h)&&this.resizeItem(h,this.options.measureElement(c,r,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var l;(l=s())==null||l.disconnect(),t=null},observe:l=>{var r;return(r=s())==null?void 0:r.observe(l,{box:"border-box"})},unobserve:l=>{var r;return(r=s())==null?void 0:r.unobserve(l)}}})(),this.range=null,this.setOptions=t=>{Object.entries(t).forEach(([s,l])=>{typeof l>"u"&&delete t[s]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Kt,rangeExtractor:Lt,onChange:()=>{},measureElement:Wt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...t}},this.notify=t=>{var s,l;(l=(s=this.options).onChange)==null||l.call(s,this,t)},this.maybeNotify=me(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const s=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==s){if(this.cleanup(),!s){this.maybeNotify();return}this.scrollElement=s,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(l=>{this.observer.observe(l)}),this.unsubs.push(this.options.observeElementRect(this,l=>{this.scrollRect=l,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(l,r)=>{this.scrollAdjustments=0,this.scrollDirection=r?this.getScrollOffset()<l?"forward":"backward":null,this.scrollOffset=l,this.isScrolling=r,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(t,s)=>{const l=new Map,r=new Map;for(let a=s-1;a>=0;a--){const c=t[a];if(l.has(c.lane))continue;const h=r.get(c.lane);if(h==null||c.end>h.end?r.set(c.lane,c):c.end<h.end&&l.set(c.lane,!0),l.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((a,c)=>a.end===c.end?a.index-c.index:a.end-c.end)[0]:void 0},this.getMeasurementOptions=me(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(t,s,l,r,a,c,h)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMeasuredCacheIndexes=[],{count:t,paddingStart:s,scrollMargin:l,getItemKey:r,enabled:a,lanes:c,laneAssignmentMode:h}),{key:!1}),this.getMeasurements=me(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:t,paddingStart:s,scrollMargin:l,getItemKey:r,enabled:a,lanes:c,laneAssignmentMode:h},d)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const u of this.laneAssignments.keys())u>=t&&this.laneAssignments.delete(u);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(u=>{this.itemSizeCache.set(u.key,u.size)}));const o=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1);const m=this.measurementsCache.slice(0,o),p=new Array(c).fill(void 0);for(let u=0;u<o;u++){const f=m[u];f&&(p[f.lane]=u)}for(let u=o;u<t;u++){const f=r(u),g=this.laneAssignments.get(u);let I,S;const y=h==="estimate"||d.has(f);if(g!==void 0&&this.options.lanes>1){I=g;const N=p[I],x=N!==void 0?m[N]:void 0;S=x?x.end+this.options.gap:s+l}else{const N=this.options.lanes===1?m[u-1]:this.getFurthestMeasurement(m,u);S=N?N.end+this.options.gap:s+l,I=N?N.lane:u%this.options.lanes,this.options.lanes>1&&y&&this.laneAssignments.set(u,I)}const w=d.get(f),_=typeof w=="number"?w:this.options.estimateSize(u),C=S+_;m[u]={index:u,start:S,size:_,end:C,key:f,lane:I},p[I]=u}return this.measurementsCache=m,m},{key:!1,debug:()=>this.options.debug}),this.calculateRange=me(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,s,l,r)=>this.range=t.length>0&&s>0?Vt({measurements:t,outerSize:s,scrollOffset:l,lanes:r}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=me(()=>{let t=null,s=null;const l=this.calculateRange();return l&&(t=l.startIndex,s=l.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,s]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,s]},(t,s,l,r,a)=>r===null||a===null?[]:t({startIndex:r,endIndex:a,overscan:s,count:l}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const s=this.options.indexAttribute,l=t.getAttribute(s);return l?parseInt(l,10):(console.warn(`Missing attribute name '${s}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var s;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const l=this.scrollState.index??((s=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:s.index);if(l!==void 0&&this.range){const r=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),a=Math.max(0,l-r),c=Math.min(this.options.count-1,l+r);return t>=a&&t<=c}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((a,c)=>{a.isConnected||(this.observer.unobserve(a),this.elementsCache.delete(c))});return}const s=this.indexFromElement(t),l=this.options.getItemKey(s),r=this.elementsCache.get(l);r!==t&&(r&&this.observer.unobserve(r),this.observer.observe(t),this.elementsCache.set(l,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,s)=>{var l;const r=this.measurementsCache[t];if(!r)return;const a=this.itemSizeCache.get(r.key)??r.size,c=s-a;c!==0&&(((l=this.scrollState)==null?void 0:l.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(r,c,this):r.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=c,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(r.index),this.itemSizeCache=new Map(this.itemSizeCache.set(r.key,s)),this.notify(!1))},this.getVirtualItems=me(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,s)=>{const l=[];for(let r=0,a=t.length;r<a;r++){const c=t[r],h=s[c];l.push(h)}return l},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const s=this.getMeasurements();if(s.length!==0)return Pe(s[Xe(0,s.length-1,l=>Pe(s[l]).start,t)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(t,s,l=0)=>{if(!this.scrollElement)return 0;const r=this.getSize(),a=this.getScrollOffset();s==="auto"&&(s=t>=a+r?"end":"start"),s==="center"?t+=(l-r)/2:s==="end"&&(t-=r);const c=this.getMaxScrollOffset();return Math.max(Math.min(c,t),0)},this.getOffsetForIndex=(t,s="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const l=this.getSize(),r=this.getScrollOffset(),a=this.measurementsCache[t];if(!a)return;if(s==="auto")if(a.end>=r+l-this.options.scrollPaddingEnd)s="end";else if(a.start<=r+this.options.scrollPaddingStart)s="start";else return[r,s];if(s==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),s];const c=s==="end"?a.end+this.options.scrollPaddingEnd:a.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,s,a.size),s]},this.scrollToOffset=(t,{align:s="start",behavior:l="auto"}={})=>{const r=this.getOffsetForAlignment(t,s),a=this.now();this.scrollState={index:null,align:s,behavior:l,startedAt:a,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:l}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:s="auto",behavior:l="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const r=this.getOffsetForIndex(t,s);if(!r)return;const[a,c]=r,h=this.now();this.scrollState={index:t,align:c,behavior:l,startedAt:h,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:l}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:s="auto"}={})=>{const l=this.getScrollOffset()+t,r=this.now();this.scrollState={index:null,align:"start",behavior:s,startedAt:r,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:s}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var t;const s=this.getMeasurements();let l;if(s.length===0)l=this.options.paddingStart;else if(this.options.lanes===1)l=((t=s[s.length-1])==null?void 0:t.end)??0;else{const r=Array(this.options.lanes).fill(null);let a=s.length-1;for(;a>=0&&r.some(c=>c===null);){const c=s[a];r[c.lane]===null&&(r[c.lane]=c.end),a--}l=Math.max(...r.filter(c=>c!==null))}return Math.max(l-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(t,{adjustments:s,behavior:l})=>{this.options.scrollToFn(t,{behavior:l,adjustments:s},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const s=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,l=s?s[0]:this.scrollState.lastTargetOffset,r=1,a=l!==this.scrollState.lastTargetOffset;if(!a&&Tt(l,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=r){this.scrollState=null;return}}else this.scrollState.stableFrames=0,a&&(this.scrollState.lastTargetOffset=l,this.scrollState.behavior="auto",this._scrollToOffset(l,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const Xe=(n,e,t,s)=>{for(;n<=e;){const l=(n+e)/2|0,r=t(l);if(r<s)n=l+1;else if(r>s)e=l-1;else return l}return n>0?n-1:0};function Vt({measurements:n,outerSize:e,scrollOffset:t,lanes:s}){const l=n.length-1,r=h=>n[h].start;if(n.length<=s)return{startIndex:0,endIndex:l};let a=Xe(0,l,r,t),c=a;if(s===1)for(;c<l&&n[c].end<t+e;)c++;else if(s>1){const h=Array(s).fill(0);for(;c<l&&h.some(o=>o<t+e);){const o=n[c];h[o.lane]=o.end,c++}const d=Array(s).fill(t+e);for(;a>=0&&d.some(o=>o>=t);){const o=n[a];d[o.lane]=o.start,a--}a=Math.max(0,a-a%s),c=Math.min(l,c+(s-1-c%s))}return{startIndex:a,endIndex:c}}const Re=typeof document<"u"?$.useLayoutEffect:$.useEffect;function Ht({useFlushSync:n=!0,...e}){const t=$.useReducer(()=>({}),{})[1],s={...e,onChange:(r,a)=>{var c;n&&a?nt.flushSync(t):t(),(c=e.onChange)==null||c.call(e,r,a)}},[l]=$.useState(()=>new Bt(s));return l.setOptions(s),Re(()=>l._didMount(),[]),Re(()=>l._willUpdate()),l}function qt(n){return Ht({observeElementRect:Dt,observeElementOffset:$t,scrollToFn:Ut,...n})}const Yt=["anthropic","openrouter"],Qt=["google"];function Ne(n){const e=U.c(8),{logo:t,name:s,description:l,onClick:r}=n;let a;e[0]!==t||e[1]!==s?(a=t?i.jsx("img",{src:t,alt:s,className:"size-5 object-contain"}):i.jsx(lt,{fallback:s.charAt(0),className:"size-8 bg-primary/10 text-primary"}),e[0]=t,e[1]=s,e[2]=a):a=e[2];let c;return e[3]!==l||e[4]!==s||e[5]!==r||e[6]!==a?(c=i.jsx(rt,{onClick:r,icon:a,title:s,description:l}),e[3]=l,e[4]=s,e[5]=r,e[6]=a,e[7]=c):c=e[7],c}function Ke(n){const e=U.c(7),{label:t,children:s}=n;let l;e[0]!==t?(l=i.jsx("span",{className:"px-1 text-meta",children:t}),e[0]=t,e[1]=l):l=e[1];let r;e[2]!==s?(r=i.jsx(ke,{children:s}),e[2]=s,e[3]=r):r=e[3];let a;return e[4]!==l||e[5]!==r?(a=i.jsxs("div",{className:"flex flex-col gap-2",children:[l,r]}),e[4]=l,e[5]=r,e[6]=a):a=e[6],a}function Ge(n){const e=U.c(45),{providers:t,onSelect:s}=n,l=ie(),r=At();let a;e[0]!==t?(a=S=>t.find(y=>y.id===S),e[0]=t,e[1]=a):a=e[1];const c=a;let h,d,o,m,p;if(e[2]!==c||e[3]!==s||e[4]!==r){const S=r?void 0:c("deco");let y;e[10]!==c?(y=c("openai-compatible"),e[10]=c,e[11]=y):y=e[11],o=y;let w;e[12]===Symbol.for("react.memo_cache_sentinel")?(w=ve("openai"),e[12]=w):w=e[12];const _=w;let C;e[13]!==s?(C=v=>i.jsx(Ne,{logo:v.logo,name:v.name,description:v.description,onClick:()=>s({kind:"provider",provider:v})},v.id),e[13]=s,e[14]=C):C=e[14];const N=C;if(e[15]!==c||e[16]!==s||e[17]!==o||e[18]!==N){let v;if(e[20]!==c||e[21]!==N?(v=j=>{const M=c(j);return M?[N(M)]:[]},e[20]=c,e[21]=N,e[22]=v):v=e[22],h=Yt.flatMap(v),o&&_){let j;e[23]!==s||e[24]!==o?(j=i.jsx(Ne,{logo:_.logo,name:_.name,description:_.description,onClick:()=>s({kind:"openai-compatible",provider:o,preset:_})},_.id),e[23]=s,e[24]=o,e[25]=j):j=e[25],h.push(j)}e[15]=c,e[16]=s,e[17]=o,e[18]=N,e[19]=h}else h=e[19];let x;e[26]!==c||e[27]!==N?(x=Qt.flatMap(v=>{const j=c(v);return j?[N(j)]:[]}),e[26]=c,e[27]=N,e[28]=x):x=e[28],d=x,m="flex flex-col gap-5",p=S&&i.jsx(ke,{children:N(S)}),e[2]=c,e[3]=s,e[4]=r,e[5]=h,e[6]=d,e[7]=o,e[8]=m,e[9]=p}else h=e[5],d=e[6],o=e[7],m=e[8],p=e[9];let u;e[29]!==h||e[30]!==l?(u=h.length>0&&i.jsx(Ke,{label:l("settings.aiProviders.groupChat"),children:h}),e[29]=h,e[30]=l,e[31]=u):u=e[31];let f;e[32]!==d||e[33]!==l?(f=d.length>0&&i.jsx(Ke,{label:l("settings.aiProviders.groupMedia"),children:d}),e[32]=d,e[33]=l,e[34]=f):f=e[34];let g;e[35]!==s||e[36]!==o||e[37]!==l?(g=o&&i.jsx(ke,{children:i.jsx(Ne,{logo:o.logo,name:l("settings.aiProviders.customOpenAiCompatible"),description:l("settings.aiProviders.customOpenAiDescription"),onClick:()=>s({kind:"openai-compatible",provider:o,preset:null})})}),e[35]=s,e[36]=o,e[37]=l,e[38]=g):g=e[38];let I;return e[39]!==m||e[40]!==p||e[41]!==u||e[42]!==f||e[43]!==g?(I=i.jsxs("div",{className:m,children:[p,u,f,g]}),e[39]=m,e[40]=p,e[41]=u,e[42]=f,e[43]=g,e[44]=I):I=e[44],I}function Xt(n){return Be({label:xe().optional(),apiKey:xe().min(1,n)})}function Gt(n){const e=U.c(91),{providerId:t,onCancel:s,onSuccess:l}=n,{org:r}=be(),a=we(),c=_e(),[h,d]=$.useState(!1),o=ie();let m;e[0]!==o?(m=We(Xt(o("settings.connectForms.apiKeyRequired"))),e[0]=o,e[1]=m):m=e[1];let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p={label:"",apiKey:""},e[2]=p):p=e[2];let u;e[3]!==m?(u={resolver:m,defaultValues:p},e[3]=m,e[4]=u):u=e[4];const{register:f,handleSubmit:g,formState:I}=Ue(u),{errors:S}=I;let y;e[5]!==t||e[6]!==a||e[7]!==o?(y=async se=>{await a.call("AI_PROVIDER_KEY_CREATE",{providerId:t,label:se.label||o("settings.connectForms.defaultKeyLabel"),apiKey:se.apiKey})},e[5]=t,e[6]=a,e[7]=o,e[8]=y):y=e[8];let w;e[9]!==l||e[10]!==r||e[11]!==c||e[12]!==o?(w=()=>{c.invalidateQueries({queryKey:pe.aiProviderKeys(r.id)}),c.invalidateQueries({queryKey:pe.aiProviders(r.id)}),le.success(o("settings.connectForms.keySavedSuccess")),l()},e[9]=l,e[10]=r,e[11]=c,e[12]=o,e[13]=w):w=e[13];let _;e[14]!==o?(_=se=>{le.error(o("settings.connectForms.failedSaveKey",{error:se.message}))},e[14]=o,e[15]=_):_=e[15];let C;e[16]!==y||e[17]!==w||e[18]!==_?(C={mutationFn:y,onSuccess:w,onError:_},e[16]=y,e[17]=w,e[18]=_,e[19]=C):C=e[19];const{mutate:N,isPending:x,error:v}=je(C);let j;e[20]!==N?(j=se=>N(se),e[20]=N,e[21]=j):j=e[21];let M;e[22]!==g||e[23]!==j?(M=g(j),e[22]=g,e[23]=j,e[24]=M):M=e[24];let E;e[25]!==o?(E=o("settings.connectForms.labelField"),e[25]=o,e[26]=E):E=e[26];let R;e[27]!==E?(R=i.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:E}),e[27]=E,e[28]=R):R=e[28];let A;e[29]!==o?(A=o("settings.connectForms.labelPlaceholder"),e[29]=o,e[30]=A):A=e[30];let b;e[31]!==f?(b=f("label"),e[31]=f,e[32]=b):b=e[32];let k;e[33]!==A||e[34]!==b?(k=i.jsx(fe,{placeholder:A,...b,size:"sm"}),e[33]=A,e[34]=b,e[35]=k):k=e[35];let z;e[36]!==R||e[37]!==k?(z=i.jsxs("div",{className:"space-y-1",children:[R,k]}),e[36]=R,e[37]=k,e[38]=z):z=e[38];let T;e[39]!==o?(T=o("settings.connectForms.apiKeyField"),e[39]=o,e[40]=T):T=e[40];let L;e[41]!==T?(L=i.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:T}),e[41]=T,e[42]=L):L=e[42];const W=h?"text":"password";let P;e[43]!==f?(P=f("apiKey"),e[43]=f,e[44]=P):P=e[44];let V;e[45]!==W||e[46]!==P?(V=i.jsx(fe,{type:W,placeholder:"sk-...",...P,size:"sm",className:"ph-no-capture pr-8"}),e[45]=W,e[46]=P,e[47]=V):V=e[47];let G;e[48]!==h?(G=()=>d(!h),e[48]=h,e[49]=G):G=e[49];let H;e[50]!==h||e[51]!==o?(H=o(h?"settings.connectForms.hideApiKey":"settings.connectForms.showApiKey"),e[50]=h,e[51]=o,e[52]=H):H=e[52];let q;e[53]!==h?(q=h?i.jsx(qe,{size:14}):i.jsx(Qe,{size:14}),e[53]=h,e[54]=q):q=e[54];let Y;e[55]!==G||e[56]!==H||e[57]!==q?(Y=i.jsx("button",{type:"button",onClick:G,"aria-label":H,className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:q}),e[55]=G,e[56]=H,e[57]=q,e[58]=Y):Y=e[58];let ee;e[59]!==V||e[60]!==Y?(ee=i.jsxs("div",{className:"relative",children:[V,Y]}),e[59]=V,e[60]=Y,e[61]=ee):ee=e[61];let Q;e[62]!==S.apiKey?(Q=S.apiKey&&i.jsx("p",{className:"text-xs text-destructive",children:S.apiKey.message}),e[62]=S.apiKey,e[63]=Q):Q=e[63];let X;e[64]!==L||e[65]!==ee||e[66]!==Q?(X=i.jsxs("div",{className:"space-y-1",children:[L,ee,Q]}),e[64]=L,e[65]=ee,e[66]=Q,e[67]=X):X=e[67];let Z;e[68]!==v?(Z=v&&i.jsx("p",{className:"text-xs text-destructive",children:v.message}),e[68]=v,e[69]=Z):Z=e[69];let O;e[70]!==o?(O=o("settings.connectForms.cancel"),e[70]=o,e[71]=O):O=e[71];let F;e[72]!==x||e[73]!==s||e[74]!==O?(F=i.jsx(oe,{type:"button",variant:"ghost",size:"sm",onClick:s,disabled:x,children:O}),e[72]=x,e[73]=s,e[74]=O,e[75]=F):F=e[75];let K;e[76]!==x||e[77]!==o?(K=o(x?"settings.connectForms.saving":"settings.connectForms.saveKey"),e[76]=x,e[77]=o,e[78]=K):K=e[78];let D;e[79]!==x||e[80]!==K?(D=i.jsx(oe,{type:"submit",size:"sm",disabled:x,children:K}),e[79]=x,e[80]=K,e[81]=D):D=e[81];let B;e[82]!==F||e[83]!==D?(B=i.jsxs(Ve,{children:[F,D]}),e[82]=F,e[83]=D,e[84]=B):B=e[84];let te;return e[85]!==M||e[86]!==z||e[87]!==X||e[88]!==Z||e[89]!==B?(te=i.jsxs("form",{onSubmit:M,className:"space-y-3",children:[z,X,Z,B]}),e[85]=M,e[86]=z,e[87]=X,e[88]=Z,e[89]=B,e[90]=te):te=e[90],te}function Jt(n){return Be({label:xe().optional(),baseUrl:xe().min(1,n),apiKey:xe().optional()})}function Zt(n){const e=U.c(109),{preset:t,onCancel:s,onSuccess:l}=n,{org:r}=be(),a=we(),c=_e(),[h,d]=$.useState(!1),o=ie();let m;e[0]!==o?(m=We(Jt(o("settings.connectForms.baseUrlRequired"))),e[0]=o,e[1]=m):m=e[1];const p=t?.defaultBaseUrl??"";let u;e[2]!==p?(u={label:"",baseUrl:p,apiKey:""},e[2]=p,e[3]=u):u=e[3];let f;e[4]!==m||e[5]!==u?(f={resolver:m,defaultValues:u},e[4]=m,e[5]=u,e[6]=f):f=e[6];const{register:g,handleSubmit:I,formState:S}=Ue(f),{errors:y}=S;let w;e[7]!==t||e[8]!==a?(w=async re=>{const it=JSON.stringify({baseUrl:re.baseUrl,apiKey:re.apiKey||""});await a.call("AI_PROVIDER_KEY_CREATE",{providerId:"openai-compatible",label:re.label||t?.name||re.baseUrl,apiKey:it,...t?{presetId:t.id}:{}})},e[7]=t,e[8]=a,e[9]=w):w=e[9];let _;e[10]!==l||e[11]!==r||e[12]!==c||e[13]!==o?(_=()=>{c.invalidateQueries({queryKey:pe.aiProviderKeys(r.id)}),c.invalidateQueries({queryKey:pe.aiProviders(r.id)}),le.success(o("settings.connectForms.connectionSavedSuccess")),l()},e[10]=l,e[11]=r,e[12]=c,e[13]=o,e[14]=_):_=e[14];let C;e[15]!==o?(C=re=>{le.error(o("settings.connectForms.failedSaveConnection",{error:re.message}))},e[15]=o,e[16]=C):C=e[16];let N;e[17]!==w||e[18]!==_||e[19]!==C?(N={mutationFn:w,onSuccess:_,onError:C},e[17]=w,e[18]=_,e[19]=C,e[20]=N):N=e[20];const{mutate:x,isPending:v,error:j}=je(N);let M;e[21]!==t||e[22]!==o?(M=t?o("settings.connectForms.labelPlaceholderPreset",{name:t.name}):o("settings.connectForms.labelPlaceholderOpenAiCompatible"),e[21]=t,e[22]=o,e[23]=M):M=e[23];const E=M;let R;e[24]!==t?.baseUrlPlaceholder||e[25]!==o?(R=t?.baseUrlPlaceholder??o("settings.connectForms.baseUrlPlaceholder"),e[24]=t?.baseUrlPlaceholder,e[25]=o,e[26]=R):R=e[26];const A=R;let b;e[27]!==x?(b=re=>x(re),e[27]=x,e[28]=b):b=e[28];let k;e[29]!==I||e[30]!==b?(k=I(b),e[29]=I,e[30]=b,e[31]=k):k=e[31];let z;e[32]!==o?(z=o("settings.connectForms.labelField"),e[32]=o,e[33]=z):z=e[33];let T;e[34]!==z?(T=i.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:z}),e[34]=z,e[35]=T):T=e[35];let L;e[36]!==g?(L=g("label"),e[36]=g,e[37]=L):L=e[37];let W;e[38]!==E||e[39]!==L?(W=i.jsx(fe,{placeholder:E,...L,size:"sm"}),e[38]=E,e[39]=L,e[40]=W):W=e[40];let P;e[41]!==T||e[42]!==W?(P=i.jsxs("div",{className:"space-y-1",children:[T,W]}),e[41]=T,e[42]=W,e[43]=P):P=e[43];let V;e[44]!==A||e[45]!==y||e[46]!==t?.defaultBaseUrl||e[47]!==g||e[48]!==o?(V=t?.defaultBaseUrl?i.jsx("input",{type:"hidden",...g("baseUrl")}):i.jsxs("div",{className:"space-y-1",children:[i.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:o("settings.connectForms.baseUrlField")}),i.jsx(fe,{type:"url",placeholder:A,...g("baseUrl"),size:"sm"}),y.baseUrl&&i.jsx("p",{className:"text-xs text-destructive",children:y.baseUrl.message})]}),e[44]=A,e[45]=y,e[46]=t?.defaultBaseUrl,e[47]=g,e[48]=o,e[49]=V):V=e[49];let G;e[50]!==o?(G=o("settings.connectForms.apiKeyField"),e[50]=o,e[51]=G):G=e[51];let H;e[52]!==t?.apiKeyRecommended||e[53]!==o?(H=t?.apiKeyRecommended?o("settings.connectForms.recommended"):o("settings.connectForms.optional"),e[52]=t?.apiKeyRecommended,e[53]=o,e[54]=H):H=e[54];let q;e[55]!==H?(q=i.jsxs("span",{className:"text-muted-foreground/60",children:["(",H,")"]}),e[55]=H,e[56]=q):q=e[56];let Y;e[57]!==G||e[58]!==q?(Y=i.jsxs("label",{className:"text-xs font-medium text-muted-foreground",children:[G," ",q]}),e[57]=G,e[58]=q,e[59]=Y):Y=e[59];const ee=h?"text":"password";let Q;e[60]!==g?(Q=g("apiKey"),e[60]=g,e[61]=Q):Q=e[61];let X;e[62]!==ee||e[63]!==Q?(X=i.jsx(fe,{type:ee,placeholder:"sk-...",...Q,size:"sm",className:"ph-no-capture pr-8"}),e[62]=ee,e[63]=Q,e[64]=X):X=e[64];let Z;e[65]!==h?(Z=()=>d(!h),e[65]=h,e[66]=Z):Z=e[66];let O;e[67]!==h||e[68]!==o?(O=o(h?"settings.connectForms.hideApiKey":"settings.connectForms.showApiKey"),e[67]=h,e[68]=o,e[69]=O):O=e[69];let F;e[70]!==h?(F=h?i.jsx(qe,{size:14}):i.jsx(Qe,{size:14}),e[70]=h,e[71]=F):F=e[71];let K;e[72]!==Z||e[73]!==O||e[74]!==F?(K=i.jsx("button",{type:"button",onClick:Z,"aria-label":O,className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:F}),e[72]=Z,e[73]=O,e[74]=F,e[75]=K):K=e[75];let D;e[76]!==X||e[77]!==K?(D=i.jsxs("div",{className:"relative",children:[X,K]}),e[76]=X,e[77]=K,e[78]=D):D=e[78];let B;e[79]!==Y||e[80]!==D?(B=i.jsxs("div",{className:"space-y-1",children:[Y,D]}),e[79]=Y,e[80]=D,e[81]=B):B=e[81];let te;e[82]!==t?(te=t?.helpText&&i.jsx("p",{className:"text-xs text-muted-foreground",children:t.helpText}),e[82]=t,e[83]=te):te=e[83];let se;e[84]!==j?(se=j&&i.jsx("p",{className:"text-xs text-destructive",children:j.message}),e[84]=j,e[85]=se):se=e[85];let ae;e[86]!==o?(ae=o("settings.connectForms.cancel"),e[86]=o,e[87]=ae):ae=e[87];let ce;e[88]!==v||e[89]!==s||e[90]!==ae?(ce=i.jsx(oe,{type:"button",variant:"ghost",size:"sm",onClick:s,disabled:v,children:ae}),e[88]=v,e[89]=s,e[90]=ae,e[91]=ce):ce=e[91];let de;e[92]!==v||e[93]!==o?(de=o(v?"settings.connectForms.saving":"settings.connectForms.saveConnection"),e[92]=v,e[93]=o,e[94]=de):de=e[94];let he;e[95]!==v||e[96]!==de?(he=i.jsx(oe,{type:"submit",size:"sm",disabled:v,children:de}),e[95]=v,e[96]=de,e[97]=he):he=e[97];let ue;e[98]!==ce||e[99]!==he?(ue=i.jsxs(Ve,{children:[ce,he]}),e[98]=ce,e[99]=he,e[100]=ue):ue=e[100];let ye;return e[101]!==k||e[102]!==P||e[103]!==V||e[104]!==B||e[105]!==te||e[106]!==se||e[107]!==ue?(ye=i.jsxs("form",{onSubmit:k,className:"space-y-3",children:[P,V,B,te,se,ue]}),e[101]=k,e[102]=P,e[103]=V,e[104]=B,e[105]=te,e[106]=se,e[107]=ue,e[108]=ye):ye=e[108],ye}const es={kind:"closed"};function ts(n,e){switch(e.type){case"open":return n.kind==="closed"?{kind:"grid"}:n;case"close":return{kind:"closed"};case"back":switch(n.kind){case"form":case"oauth-pending":case"provision-pending":case"provision-error":return{kind:"grid"};default:return n}case"select-form":return n.kind!=="grid"?n:{kind:"form",providerId:e.providerId,presetId:e.presetId};case"select-oauth":return n.kind!=="grid"?n:{kind:"oauth-pending",providerId:e.providerId,stateToken:e.stateToken};case"oauth-failed":return n.kind==="oauth-pending"?{kind:"grid"}:n;case"select-provision":return n.kind!=="grid"?n:{kind:"provision-pending",providerId:e.providerId};case"provision-error":return n.kind!=="provision-pending"?n:{kind:"provision-error",providerId:n.providerId,error:e.error};case"retry-provision":return n.kind!=="provision-error"?n:{kind:"provision-pending",providerId:n.providerId}}}function ss(n){switch(n.kind){case"form":case"oauth-pending":case"provision-pending":case"provision-error":return n.providerId;default:return null}}function is({open:n,onOpenChange:e,initialProvider:t}){const s=ie(),r=Ie()?.providers??[],{org:a}=be(),c=we(),h=_e(),[d,o]=$.useReducer(ts,es),m=$.useRef(!1);$.useEffect(()=>{n&&d.kind==="closed"?o({type:"open"}):!n&&d.kind!=="closed"&&o({type:"close"})},[n,d.kind]);const p=()=>{m.current=!1,o({type:"close"}),e(!1)},u=()=>{h.invalidateQueries({queryKey:pe.aiProviderKeys(a.id)}),h.invalidateQueries({queryKey:pe.aiProviders(a.id)})},{mutate:f}=je({mutationFn:async({providerId:b,code:k,stateToken:z,label:T})=>(await c.call("AI_PROVIDER_OAUTH_EXCHANGE",{providerId:b,code:k,stateToken:z,label:T}),b),onSuccess:b=>{ne("ai_provider_oauth_succeeded",{provider_id:b}),u();const k=r.find(z=>z.id===b);le.success(s("settings.connectProviderDialog.oauthSuccessMessage",{provider:k?.name??s("settings.connectProviderDialog.defaultProviderName")})),p()},onError:(b,k)=>{ne("ai_provider_oauth_failed",{provider_id:k.providerId,error:b.message}),le.error(s("settings.connectProviderDialog.oauthFailedMessage",{error:b.message})),o({type:"oauth-failed"})}}),{mutate:g}=je({mutationFn:async b=>(await c.call("AI_PROVIDER_PROVISION_KEY",{providerId:b}),b),onSuccess:b=>{ne("ai_provider_provision_succeeded",{provider_id:b}),u();const k=r.find(z=>z.id===b);le.success(s("settings.connectProviderDialog.provisionSuccessMessage",{provider:k?.name??s("settings.connectProviderDialog.defaultProviderName")})),p()},onError:(b,k)=>{ne("ai_provider_provision_failed",{provider_id:k,error:b.message}),o({type:"provision-error",error:b.message})}}),I=async b=>{const{provider:k}=b,z=b.kind==="openai-compatible"?b.preset?.id??null:null,T=k.supportedMethods.includes("oauth-pkce"),L=k.supportedMethods.includes("api-key");if(k.supportsProvision===!0){ne("ai_provider_connect_clicked",{provider_id:k.id,method:"provision"}),o({type:"select-provision",providerId:k.id}),g(k.id);return}if(T){ne("ai_provider_connect_clicked",{provider_id:k.id,method:"oauth-pkce"});try{const P=await c.call("AI_PROVIDER_OAUTH_URL",{providerId:k.id,callbackUrl:`${window.location.origin}/oauth/callback/ai-provider`});if(!P?.url)throw new Error("Invalid response from AI_PROVIDER_OAUTH_URL");o({type:"select-oauth",providerId:k.id,stateToken:P.stateToken}),window.open(P.url,"AiProviderOAuth","width=600,height=700")}catch(P){le.error(s("settings.connectProviderDialog.startOAuthFailedMessage",{error:P instanceof Error?P.message:String(P)}))}return}L&&(ne("ai_provider_connect_clicked",{provider_id:k.id,...z!==null?{preset_id:z}:{},method:"api-key"}),o({type:"select-form",providerId:k.id,presetId:z}))},S=$.useRef(I);S.current=I;const y=$.useRef(t);y.current=t,$.useEffect(()=>{!y.current||d.kind!=="grid"||m.current||(m.current=!0,S.current(y.current))},[d.kind]);const w=d.kind==="oauth-pending"?d.stateToken:null,_=d.kind==="oauth-pending"?d.providerId:null;$.useEffect(()=>{if(d.kind!=="oauth-pending")return;let b=!1;const k=d.stateToken,z=d.providerId,T=W=>{if(W.origin!==window.location.origin||W.data?.type!=="AI_PROVIDER_OAUTH_CALLBACK")return;const{code:P,stateToken:V}=W.data;if(V!==k){le.error(s("settings.connectProviderDialog.securityCheckFailedMessage")),o({type:"oauth-failed"});return}b=!0;const G=r.find(H=>H.id===z);f({providerId:z,code:P,stateToken:k,label:G?.name??z})};window.addEventListener("message",T);const L=setTimeout(()=>{b||(ne("ai_provider_oauth_timeout",{provider_id:z}),o({type:"oauth-failed"}),le.error(s("settings.connectProviderDialog.connectionTimedOutMessage")))},12e4);return()=>{window.removeEventListener("message",T),clearTimeout(L)}},[d.kind,w,_,f]);const[C,N]=$.useState(d);d.kind!=="closed"&&d!==C&&N(d);const x=d.kind==="closed"?C:d,v=ss(x),j=v?r.find(b=>b.id===v):null,E=(x.kind==="form"&&x.presetId?ve(x.presetId):null)?.name??j?.name??s("settings.connectProviderDialog.defaultTitle"),R=x.kind!=="grid"&&x.kind!=="closed",A=()=>{t?p():o({type:"back"})};return i.jsx(ot,{open:d.kind!=="closed",onOpenChange:b=>!b&&p(),children:i.jsxs(at,{className:"sm:max-w-md max-h-[90vh] overflow-y-auto",children:[i.jsx(ct,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[R&&i.jsx(oe,{variant:"ghost",size:"icon-sm","aria-label":s("settings.connectProviderDialog.backButtonLabel"),onClick:A,children:i.jsx(He,{size:16})}),i.jsx(dt,{children:E})]})}),x.kind==="grid"&&!t&&i.jsx(Ge,{providers:r,onSelect:I}),x.kind==="form"&&(x.providerId==="openai-compatible"?i.jsx(Zt,{preset:x.presetId?ve(x.presetId):void 0,onCancel:()=>o({type:"back"}),onSuccess:()=>{u(),p()}}):i.jsx(Gt,{providerId:x.providerId,onCancel:()=>o({type:"back"}),onSuccess:()=>{u(),p()}})),x.kind==="oauth-pending"&&i.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[i.jsx(Oe,{size:"lg"}),i.jsx("p",{className:"text-sm text-muted-foreground text-center",children:s("settings.connectProviderDialog.oauthPendingMessage")})]}),x.kind==="provision-pending"&&i.jsxs("div",{className:"flex flex-col items-center gap-4 py-8",children:[i.jsx(Oe,{size:"lg"}),i.jsx("p",{className:"text-sm text-muted-foreground",children:s("settings.connectProviderDialog.provisionPendingMessage")})]}),x.kind==="provision-error"&&i.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[i.jsx(Pt,{size:28,className:"text-destructive"}),i.jsx("p",{className:"text-sm text-foreground text-center",children:x.error}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(oe,{variant:"outline",size:"sm",onClick:()=>o({type:"back"}),children:s("settings.connectProviderDialog.backButton")}),i.jsx(oe,{size:"sm",onClick:()=>{o({type:"retry-provision"}),g(x.providerId)},children:s("settings.connectProviderDialog.retryButton")})]})]})]})})}function ns(n){const e=U.c(35);let t;e[0]!==n?(t=n===void 0?{}:n,e[0]=n,e[1]=t):t=e[1];const{title:s,description:l,providerFilter:r}=t,a=ie(),{org:c}=be(),[h,d]=$.useState(null),o=Ie();let m;e[2]!==o?.providers?(m=o?.providers??[],e[2]=o?.providers,e[3]=m):m=e[3];let p;if(e[4]!==r||e[5]!==m){let b;e[7]!==r?(b=k=>!r||r(k.id),e[7]=r,e[8]=b):b=e[8],p=m.filter(b),e[4]=r,e[5]=m,e[6]=p}else p=e[6];const u=p,f=c.name;let g;e[9]!==f||e[10]!==a||e[11]!==s?(g=s??(f?a("chat.noAiProviderEmptyState.headingWithOrg",{org:f}):a("chat.noAiProviderEmptyState.headingDefault")),e[9]=f,e[10]=a,e[11]=s,e[12]=g):g=e[12];const I=g;let S;e[13]!==l||e[14]!==a?(S=l??a("chat.noAiProviderEmptyState.subtitleDefault"),e[13]=l,e[14]=a,e[15]=S):S=e[15];const y=S;let w;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=i.jsx("div",{className:"flex items-center justify-center size-14 rounded-2xl bg-muted border border-border",children:i.jsx(zt,{size:24,className:"text-muted-foreground"})}),e[16]=w):w=e[16];let _;e[17]!==I?(_=i.jsx("p",{className:"text-xl font-semibold text-foreground tracking-tight",children:I}),e[17]=I,e[18]=_):_=e[18];let C;e[19]!==y?(C=i.jsx("p",{className:"text-sm text-muted-foreground max-w-md",children:y}),e[19]=y,e[20]=C):C=e[20];let N;e[21]!==_||e[22]!==C?(N=i.jsxs("div",{className:"flex flex-col items-center gap-4 text-center",children:[w,i.jsxs("div",{className:"space-y-2",children:[_,C]})]}),e[21]=_,e[22]=C,e[23]=N):N=e[23];let x;e[24]===Symbol.for("react.memo_cache_sentinel")?(x=b=>d(b),e[24]=x):x=e[24];let v;e[25]!==u?(v=i.jsx("div",{className:"w-full",children:i.jsx(Ge,{providers:u,onSelect:x})}),e[25]=u,e[26]=v):v=e[26];const j=h!==null;let M;e[27]===Symbol.for("react.memo_cache_sentinel")?(M=b=>{b||d(null)},e[27]=M):M=e[27];const E=h??void 0;let R;e[28]!==j||e[29]!==E?(R=i.jsx(is,{open:j,onOpenChange:M,initialProvider:E}),e[28]=j,e[29]=E,e[30]=R):R=e[30];let A;return e[31]!==v||e[32]!==R||e[33]!==N?(A=i.jsxs("div",{className:"flex flex-col items-center gap-8 w-full max-w-3xl px-4",children:[N,v,R]}),e[31]=v,e[32]=R,e[33]=N,e[34]=A):A=e[34],A}function Me(n){const e=n.title.includes(": ");return{provider:e?n.title.split(": ")[0]??"":n.modelId.split("/")[0]??"",displayName:e?n.title.split(": ").slice(1).join(": "):n.title}}function ls(n){return n<32e3?{level:1,labelKey:"chat.shared.contextLevelSmall",descriptionKey:"chat.shared.contextLevelSmallDesc"}:n<2e5?{level:2,labelKey:"chat.shared.contextLevelMedium",descriptionKey:"chat.shared.contextLevelMediumDesc"}:n<5e5?{level:3,labelKey:"chat.shared.contextLevelLarge",descriptionKey:"chat.shared.contextLevelLargeDesc"}:{level:4,labelKey:"chat.shared.contextLevelVeryLarge",descriptionKey:"chat.shared.contextLevelVeryLargeDesc"}}const rs=["bg-destructive","bg-warning","bg-success","bg-success"],os=["text-success","text-warning","text-warning","text-destructive"];function as(n,e){const t=Math.round(n*.75/1e3),s=t>=1?`${t}K`:`${Math.round(n*.75)}`;return e("chat.shared.approxWords",{wordCount:s})}function cs(n){return n<1?{level:1,labelKey:"chat.shared.costLevelCheap"}:n<5?{level:2,labelKey:"chat.shared.costLevelModerate"}:n<15?{level:3,labelKey:"chat.shared.costLevelHigh"}:{level:4,labelKey:"chat.shared.costLevelExpensive"}}const ds={text:{icon:i.jsx(wt,{className:"size-3.5"}),labelKey:"chat.shared.capabilityText"},vision:{icon:i.jsx(Ft,{className:"size-3.5"}),labelKey:"chat.shared.capabilityVision"},image:{icon:i.jsx(kt,{className:"size-3.5"}),labelKey:"chat.shared.capabilityImage"},tools:{icon:i.jsx(Nt,{className:"size-3.5"}),labelKey:"chat.shared.capabilityTools"},reasoning:{icon:i.jsx(St,{className:"size-3.5"}),labelKey:"chat.shared.capabilityReasoning"},"web-search":{icon:i.jsx(Ye,{className:"size-3.5"}),labelKey:"chat.shared.capabilityWebSearch"}};function hs(n){const e=U.c(10),{capability:t}=n,s=ie(),l=ds[t];if(l){const h=l.icon;let d;e[0]!==l.labelKey||e[1]!==s?(d=s(l.labelKey),e[0]=l.labelKey,e[1]=s,e[2]=d):d=e[2];let o;return e[3]!==l.icon||e[4]!==d?(o=i.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground border border-border rounded px-2 py-0.5",children:[h,d]}),e[3]=l.icon,e[4]=d,e[5]=o):o=e[5],o}let r;e[6]!==t?(r=t.charAt(0).toUpperCase(),e[6]=t,e[7]=r):r=e[7];const a=r+t.slice(1);let c;return e[8]!==a?(c=i.jsx("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground border border-border rounded px-2 py-0.5",children:a}),e[8]=a,e[9]=c):c=e[9],c}function us(n){const e=U.c(59),{model:t,compact:s}=n,l=s===void 0?!1:s,r=ie();if(!t){let x;e[0]!==r?(x=r("chat.shared.hoverToPreview"),e[0]=r,e[1]=x):x=e[1];let v;return e[2]!==x?(v=i.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:x}),e[2]=x,e[3]=v):v=e[3],v}const a=t.costs?.input!=null?t.costs.input*1e6:null,c=t.costs?.output!=null?t.costs.output*1e6:null;let h;e[4]!==t?(h=Me(t),e[4]=t,e[5]=h):h=e[5];const{provider:d,displayName:o}=h;if(l){let x;e[6]!==t.limits||e[7]!==r?(x=t.limits?.contextWindow&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-muted-foreground",children:r("chat.shared.context")}),i.jsxs("span",{className:"text-foreground font-medium",children:[t.limits.contextWindow.toLocaleString()," ",r("chat.shared.tokens")]})]}),e[6]=t.limits,e[7]=r,e[8]=x):x=e[8];let v;e[9]!==a||e[10]!==r?(v=a!=null&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-muted-foreground",children:r("chat.shared.input")}),i.jsxs("span",{className:"text-foreground font-medium",children:["$",a.toFixed(2)," / 1M"]})]}),e[9]=a,e[10]=r,e[11]=v):v=e[11];let j;e[12]!==c||e[13]!==r?(j=c!=null&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-muted-foreground",children:r("chat.shared.output")}),i.jsxs("span",{className:"text-foreground font-medium",children:["$",c.toFixed(2)," / 1M"]})]}),e[12]=c,e[13]=r,e[14]=j):j=e[14];let M;e[15]!==t.limits||e[16]!==r?(M=t.limits?.maxOutputTokens&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-muted-foreground",children:r("chat.shared.outputLimit")}),i.jsxs("span",{className:"text-foreground font-medium",children:[t.limits.maxOutputTokens.toLocaleString()," ",r("chat.shared.tokens")]})]}),e[15]=t.limits,e[16]=r,e[17]=M):M=e[17];let E;return e[18]!==x||e[19]!==v||e[20]!==j||e[21]!==M?(E=i.jsxs("div",{className:"flex flex-col gap-2 pt-3 pb-3 px-3 text-xs",children:[x,v,j,M]}),e[18]=x,e[19]=v,e[20]=j,e[21]=M,e[22]=E):E=e[22],E}let m;e[23]!==d?(m=i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:d}),e[23]=d,e[24]=m):m=e[24];let p;e[25]!==t.logo||e[26]!==t.title?(p=t.logo&&i.jsx("img",{src:t.logo,className:"size-6 shrink-0 rounded-md dark:bg-white dark:rounded-sm dark:p-px",alt:t.title}),e[25]=t.logo,e[26]=t.title,e[27]=p):p=e[27];let u;e[28]!==o?(u=i.jsx("p",{className:"text-lg font-semibold leading-snug tracking-tight",children:o}),e[28]=o,e[29]=u):u=e[29];let f;e[30]!==p||e[31]!==u?(f=i.jsxs("div",{className:"flex items-center gap-2.5",children:[p,u]}),e[30]=p,e[31]=u,e[32]=f):f=e[32];let g;e[33]!==t.modelId?(g=i.jsx("p",{className:"text-xs text-muted-foreground/50 font-mono",children:t.modelId}),e[33]=t.modelId,e[34]=g):g=e[34];let I;e[35]!==m||e[36]!==f||e[37]!==g?(I=i.jsxs("div",{className:"flex flex-col gap-1 pt-1 pr-6",children:[m,f,g]}),e[35]=m,e[36]=f,e[37]=g,e[38]=I):I=e[38];let S;e[39]!==t.capabilities?(S=t.capabilities&&t.capabilities.length>0&&i.jsx("div",{className:"flex flex-wrap items-center gap-1.5 pb-4 border-b border-border",children:[...new Set(t.capabilities)].map(ms)}),e[39]=t.capabilities,e[40]=S):S=e[40];let y;e[41]!==t.limits||e[42]!==r?(y=t.limits?.contextWindow&&(()=>{const{level:x,labelKey:v,descriptionKey:j}=ls(t.limits.contextWindow);return i.jsxs("div",{className:"flex flex-col gap-1.5",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:r("chat.shared.contextWindow")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"flex items-center gap-0.5",children:[1,2,3,4].map(M=>i.jsx("div",{className:ge("w-2 h-2 rounded-full",M<=x?rs[x-1]:"bg-muted")},M))}),i.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:r(v)}),i.jsxs("span",{className:"text-xs text-muted-foreground",children:["— ",r(j)]})]}),i.jsxs("span",{className:"text-sm text-muted-foreground",children:[t.limits.contextWindow.toLocaleString()," ",r("chat.shared.tokens")]})]})})(),e[41]=t.limits,e[42]=r,e[43]=y):y=e[43];let w;e[44]!==t.limits||e[45]!==r?(w=t.limits?.maxOutputTokens&&i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:r("chat.shared.outputLimit")}),i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsxs("span",{className:"text-sm text-foreground",children:[t.limits.maxOutputTokens.toLocaleString()," ",r("chat.shared.tokens")]}),i.jsx("span",{className:"text-sm text-muted-foreground",children:as(t.limits.maxOutputTokens,r)})]})]}),e[44]=t.limits,e[45]=r,e[46]=w):w=e[46];let _;e[47]!==a||e[48]!==c||e[49]!==r?(_=(a!=null||c!=null)&&(()=>{const{level:x,labelKey:v}=a!=null?cs(a):{level:0,labelKey:null};return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:r("chat.shared.pricing")}),a!=null&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"flex items-center",children:[1,2,3,4].map(j=>i.jsx("span",{className:ge("text-sm font-semibold leading-none",j<=x?os[x-1]:"text-muted-foreground/20"),children:"$"},j))}),i.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:v?r(v):""})]}),i.jsxs("div",{className:"flex flex-col gap-1",children:[a!=null&&i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:r("chat.shared.input")}),i.jsxs("span",{className:"text-xs text-foreground",children:["$",a.toFixed(2)," / 1M"," ",r("chat.shared.tokens")]})]}),c!=null&&i.jsxs("div",{className:"flex justify-between items-center",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:r("chat.shared.output")}),i.jsxs("span",{className:"text-xs text-foreground",children:["$",c.toFixed(2)," / 1M"," ",r("chat.shared.tokens")]})]})]})]})})(),e[47]=a,e[48]=c,e[49]=r,e[50]=_):_=e[50];let C;e[51]!==y||e[52]!==w||e[53]!==_?(C=i.jsxs("div",{className:"flex flex-col gap-6",children:[y,w,_]}),e[51]=y,e[52]=w,e[53]=_,e[54]=C):C=e[54];let N;return e[55]!==C||e[56]!==I||e[57]!==S?(N=i.jsxs("div",{className:"flex flex-col gap-5 py-1 px-1.5",children:[I,S,C]}),e[55]=C,e[56]=I,e[57]=S,e[58]=N):N=e[58],N}function ms(n){return i.jsx(hs,{capability:n},n)}function ni(n){const e=U.c(22),{model:t,placeholder:s,isLoading:l}=n,r=l===void 0?!1:l,a=ie();let c;e[0]!==s||e[1]!==a?(c=s??a("chat.shared.selectModel"),e[0]=s,e[1]=a,e[2]=c):c=e[2];const h=c;if(r){let S;return e[3]===Symbol.for("react.memo_cache_sentinel")?(S=i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(J,{className:"w-5 h-5 rounded-sm shrink-0"}),i.jsx(J,{className:"w-16 h-3 hidden md:block"})]}),e[3]=S):S=e[3],S}if(!t){let S;e[4]!==h?(S=i.jsx("span",{className:"text-sm text-muted-foreground",children:h}),e[4]=h,e[5]=S):S=e[5];let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=i.jsx(ze,{size:14,className:"text-muted-foreground opacity-50 shrink-0"}),e[6]=y):y=e[6];let w;return e[7]!==S?(w=i.jsxs("div",{className:"flex items-center gap-1.5",children:[S,y]}),e[7]=S,e[8]=w):w=e[8],w}let d;e[9]!==t?(d=Me(t),e[9]=t,e[10]=d):d=e[10];const{displayName:o}=d;let m;e[11]!==t?(m=Ce(t),e[11]=t,e[12]=m):m=e[12];const p=m;let u;e[13]!==t.title||e[14]!==p?(u=i.jsx("img",{src:p,className:"w-3.5 h-3.5 shrink-0 rounded-sm dark:bg-white dark:rounded-sm dark:p-px",alt:t.title}),e[13]=t.title,e[14]=p,e[15]=u):u=e[15];let f;e[16]!==o?(f=i.jsx("span",{className:"text-sm truncate whitespace-nowrap text-muted-foreground max-w-[100px] sm:max-w-none",children:o}),e[16]=o,e[17]=f):f=e[17];let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=i.jsx(ze,{size:14,className:"text-muted-foreground opacity-50 shrink-0"}),e[18]=g):g=e[18];let I;return e[19]!==u||e[20]!==f?(I=i.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 overflow-hidden",children:[u,f,g]}),e[19]=u,e[20]=f,e[21]=I):I=e[21],I}const fs=["vision","image","file","audio","video"],Je=["image/png","image/jpeg","image/gif","image/webp"],Ze=["application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];function Ee(n){const e=n?.capabilities;return e?fs.some(t=>e.includes(t)):!1}function li(n,e){if(!n)return!1;if(n.startsWith("text/"))return!0;const t=e?.capabilities??[],s=t.includes("vision")||t.includes("image"),l=t.includes("file"),r=t.includes("audio"),a=t.includes("video");return!!(s&&Je.includes(n)||l&&n==="application/pdf"||r&&n.startsWith("audio/")||a&&n.startsWith("video/")||Ee(e)&&Ze.includes(n))}function ri(n){const e=n?.capabilities??[],t=["text/*"];return(e.includes("vision")||e.includes("image"))&&t.push(...Je),e.includes("file")&&t.push("application/pdf"),e.includes("audio")&&t.push("audio/*"),e.includes("video")&&t.push("video/*"),Ee(n)&&t.push(...Ze),t.join(",")}function oi(n){const e=n?.capabilities??[],t=[];return(e.includes("vision")||e.includes("image"))&&t.push("chat.shared.fileTypeImages"),e.includes("file")&&t.push("chat.shared.fileTypePdfs"),e.includes("audio")&&t.push("chat.shared.fileTypeAudio"),e.includes("video")&&t.push("chat.shared.fileTypeVideo"),Ee(n)&&t.push("chat.shared.fileTypeOffice"),{parts:t,count:t.length}}const et=["smarter","faster","cheaper"],ps={smarter:"chat.decopilot.tierSmarter",faster:"chat.decopilot.tierFaster",cheaper:"chat.decopilot.tierCheaper"},xs=[{tier:"smarter",prefixes:["anthropic/claude-opus-4.8","anthropic/claude-sonnet-4.6","anthropic/claude-4.6-sonnet","openai/gpt-5.3-codex","google/gemini-3-pro","google/gemini-2.5-pro","cohere/command-r-plus","cohere/command-a"]},{tier:"faster",prefixes:["anthropic/claude-haiku-4.5","anthropic/claude-4.5-haiku","google/gemini-3-flash","openai/gpt-5.1-codex-mini","x-ai/grok-code-fast","x-ai/grok-3","mistralai/mistral-large","mistralai/codestral","mistralai/mistral-medium","minimax/minimax-m1"]},{tier:"cheaper",prefixes:["google/gemini-2.5-flash-lite","google/gemini-2.5-flash","google/gemini-2.0-flash","deepseek/deepseek-v3","openai/gpt-oss-120b","mistralai/mistral-small","mistralai/pixtral","cohere/command-r"]}],gs=xs.flatMap(({tier:n,prefixes:e})=>e.map(t=>({tier:n,prefix:t}))).sort((n,e)=>e.prefix.length-n.prefix.length),vs="google/gemini-2.5-pro",Le=new Map;function bs(n){const e=Le.get(n);if(e!==void 0)return e;let t=null;if(n.endsWith(":free"))t="cheaper";else for(const{tier:s,prefix:l}of gs)if(n.startsWith(l)){if(l===vs&&n.length>l.length&&n[l.length]==="-"){const a=n[l.length+1];if(!a||!/\d/.test(a))continue}t=s;break}return Le.set(n,t),t}function ys(n,e,t){if(t)return n;const s=n.filter(l=>e.has(l.modelId));return s.length>0?s:n}function De(n){const e={smarter:[],faster:[],cheaper:[],other:[]};for(const t of n){const s=bs(t.modelId);e[s??"other"].push(t)}for(const t of Object.keys(e))e[t].sort((s,l)=>s.title.localeCompare(l.title));return e}const tt="studio:model-shortlist:",js=new Set(["anthropic/claude-opus-4.8","anthropic/claude-sonnet-4.6","anthropic/claude-4.6-sonnet","anthropic/claude-sonnet-4.6:extended","openai/gpt-5.3-codex","google/gemini-3-pro-preview","google/gemini-2.5-pro","anthropic/claude-haiku-4.5","anthropic/claude-haiku-4.5-20251001","anthropic/claude-4.5-haiku","google/gemini-3-flash-preview","openai/gpt-5.1-codex-mini","x-ai/grok-code-fast-1","google/gemini-2.5-flash","deepseek/deepseek-v3.2","google/gemini-2.5-flash-lite","openai/gpt-oss-120b:free"]);function Ss(n){try{const e=localStorage.getItem(tt+n);return e?new Set(JSON.parse(e)):null}catch{return null}}function Ns(n,e){localStorage.setItem(tt+n,JSON.stringify([...e]))}function ks(n){const e=U.c(21),{model:t,onHover:s}=n;let l;e[0]!==t?(l=Me(t),e[0]=t,e[1]=l):l=e[1];const{displayName:r,provider:a}=l;let c;e[2]!==t?(c=Ce(t),e[2]=t,e[3]=c):c=e[3];const h=c;let d;e[4]!==t||e[5]!==s?(d=()=>s(t),e[4]=t,e[5]=s,e[6]=d):d=e[6];let o;e[7]!==t.title||e[8]!==h?(o=i.jsx("img",{src:h,className:"w-4 h-4 shrink-0 rounded-sm dark:bg-white dark:rounded-sm dark:p-px",alt:t.title}),e[7]=t.title,e[8]=h,e[9]=o):o=e[9];let m;e[10]!==r?(m=i.jsx("span",{className:"text-sm text-foreground leading-tight truncate",children:r}),e[10]=r,e[11]=m):m=e[11];let p;e[12]!==a?(p=i.jsx("span",{className:"text-xs text-muted-foreground/60 leading-tight",children:a}),e[12]=a,e[13]=p):p=e[13];let u;e[14]!==m||e[15]!==p?(u=i.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[m,p]}),e[14]=m,e[15]=p,e[16]=u):u=e[16];let f;return e[17]!==d||e[18]!==o||e[19]!==u?(f=i.jsxs("div",{className:"flex items-center gap-2.5 py-2 px-3 hover:bg-accent cursor-pointer rounded-lg",onMouseEnter:d,children:[o,u]}),e[17]=d,e[18]=o,e[19]=u,e[20]=f):f=e[20],f}function ws(n){const e=U.c(16),{error:t,onRetry:s}=n,l=ie();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=i.jsx("div",{className:"bg-destructive/10 p-2 rounded-full",children:i.jsx(mt,{className:"size-5 text-destructive"})}),e[0]=r):r=e[0];const a=l("chat.decopilot.failedToLoadModels");let c;e[1]!==a?(c=i.jsx("p",{className:"text-sm font-medium text-foreground",children:a}),e[1]=a,e[2]=c):c=e[2];const h=t?.message||l("chat.decopilot.couldNotFetchModels"),d=" "+l("chat.decopilot.tryAnotherProviderOrRetry");let o;e[3]!==h||e[4]!==d?(o=i.jsxs("p",{className:"text-xs text-muted-foreground max-w-[260px]",children:[h,d]}),e[3]=h,e[4]=d,e[5]=o):o=e[5];let m;e[6]!==c||e[7]!==o?(m=i.jsxs("div",{className:"flex flex-col gap-1",children:[c,o]}),e[6]=c,e[7]=o,e[8]=m):m=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=i.jsx(It,{className:"size-3.5"}),e[9]=p):p=e[9];const u=l("chat.decopilot.retry");let f;e[10]!==s||e[11]!==u?(f=i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs(oe,{variant:"outline",size:"sm",onClick:s,className:"gap-1.5",children:[p,u]})}),e[10]=s,e[11]=u,e[12]=f):f=e[12];let g;return e[13]!==f||e[14]!==m?(g=i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 px-4 py-8 text-center",children:[r,m,f]}),e[13]=f,e[14]=m,e[15]=g):g=e[15],g}function _s(){const n=U.c(1);let e;return n[0]===Symbol.for("react.memo_cache_sentinel")?(e=i.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:Array.from({length:6}).map(Is)}),n[0]=e):e=n[0],e}function Is(n,e){return i.jsxs("div",{className:"flex items-center gap-2 min-h-8 py-3 px-3 rounded-lg",children:[i.jsx(J,{className:"size-5 shrink-0 rounded-sm"}),i.jsx(J,{className:"flex-1 h-4"}),i.jsx(J,{className:"w-16 h-5 shrink-0 rounded-md"})]},e)}function $e(n){const e=U.c(12),{label:t,models:s,onSelect:l,onHover:r}=n;if(s.length===0)return null;let a;e[0]!==t?(a=i.jsx("div",{className:"text-xs font-medium text-muted-foreground px-3 pt-3 pb-1",children:t}),e[0]=t,e[1]=a):a=e[1];let c;if(e[2]!==s||e[3]!==r||e[4]!==l){let d;e[6]!==r||e[7]!==l?(d=o=>i.jsx("button",{type:"button",onClick:()=>l(o),onFocus:()=>r(o),className:"w-full text-left cursor-pointer",children:i.jsx(ks,{model:o,onHover:r})},o.modelId),e[6]=r,e[7]=l,e[8]=d):d=e[8],c=s.map(d),e[2]=s,e[3]=r,e[4]=l,e[5]=c}else c=e[5];let h;return e[9]!==a||e[10]!==c?(h=i.jsxs("div",{children:[a,c]}),e[9]=a,e[10]=c,e[11]=h):h=e[11],h}function Se(n,e){return e(n==="other"?"chat.decopilot.tierOther":ps[n])}function Cs(n){const e=U.c(21),{model:t,isChecked:s,onToggle:l,onHover:r}=n,[a,c]=$.useState(s);a!==s&&c(s);let h;e[0]!==t?(h=Ce(t),e[0]=t,e[1]=h):h=e[1];const d=h;let o;e[2]!==t||e[3]!==r?(o=()=>r(t),e[2]=t,e[3]=r,e[4]=o):o=e[4];let m;e[5]!==t.modelId||e[6]!==l?(m=()=>{c(Ms),l(t.modelId)},e[5]=t.modelId,e[6]=l,e[7]=m):m=e[7];let p;e[8]!==a||e[9]!==m?(p=i.jsx(ft,{checked:a,onCheckedChange:m}),e[8]=a,e[9]=m,e[10]=p):p=e[10];let u;e[11]!==d||e[12]!==t.title?(u=i.jsx("img",{src:d,className:"w-5 h-5 shrink-0 rounded-sm dark:bg-white dark:rounded-sm dark:p-px",alt:t.title}),e[11]=d,e[12]=t.title,e[13]=u):u=e[13];let f;e[14]!==t.title?(f=i.jsx("span",{className:"text-sm text-foreground flex-1 min-w-0 line-clamp-1",children:t.title}),e[14]=t.title,e[15]=f):f=e[15];let g;return e[16]!==o||e[17]!==p||e[18]!==u||e[19]!==f?(g=i.jsxs("label",{className:"flex items-center gap-3 min-h-8 py-2.5 px-3 hover:bg-accent cursor-pointer rounded-lg",onMouseEnter:o,children:[p,u,f]}),e[16]=o,e[17]=p,e[18]=u,e[19]=f,e[20]=g):g=e[20],g}function Ms(n){return!n}function Es(n,e){const t=[];for(const s of et)if(n[s].length>0){t.push({type:"header",label:Se(s,e)});for(const l of n[s])t.push({type:"model",model:l})}if(n.other.length>0){t.push({type:"header",label:Se("other",e)});for(const s of n.other)t.push({type:"model",model:s})}return t}function Os({items:n,shortlistSet:e,onToggle:t,onHover:s}){const l=$.useRef(null),r=qt({count:n.length,getScrollElement:()=>l.current,estimateSize:a=>n[a]?.type==="header"?36:44,overscan:6});return i.jsx("div",{ref:l,className:"flex-1 overflow-y-auto",children:i.jsx("div",{className:"relative",style:{height:r.getTotalSize()},children:r.getVirtualItems().map(a=>{const c=n[a.index];return c?i.jsx("div",{"data-index":a.index,ref:r.measureElement,className:"absolute left-0 right-0 top-0 px-0.5",style:{transform:`translateY(${a.start}px)`},children:c.type==="header"?i.jsx("div",{className:"text-xs font-medium text-muted-foreground px-3 pt-3 pb-1",children:c.label}):i.jsx(Cs,{model:c.model,isChecked:e.has(c.model.modelId),onToggle:t,onHover:s})},a.key):null})})})}function zs(n){const e=U.c(28),{keyId:t,searchTerm:s,onHover:l,onModelSelect:r,managing:a,onToggleManage:c,filterModels:h}=n,d=ie(),{models:o}=Mt(t),m=h?o.filter(h):o.filter(Et);let p;e[0]!==t?(p=()=>(t?Ss(t):null)??js,e[0]=t,e[1]=p):p=e[1];const[u,f]=$.useState(p),[,g]=$.useTransition();let I;e[2]!==t||e[3]!==g?(I=j=>{t&&g(()=>{f(M=>{const E=new Set(M);return E.has(j)?E.delete(j):E.add(j),Ns(t,E),E})})},e[2]=t,e[3]=g,e[4]=I):I=e[4];const S=I,y=s.toLowerCase().trim(),w=j=>y?j.filter(M=>M.title.toLowerCase().includes(y)||M.modelId.toLowerCase().includes(y)):j;if(a){const j=De(w(m)),M=Es(j,d);let E;e[5]!==u?(E=z=>u.has(z.modelId),e[5]=u,e[6]=E):E=e[6];const R=m.filter(E).length;let A;e[7]===Symbol.for("react.memo_cache_sentinel")?(A=i.jsx(He,{size:14}),e[7]=A):A=e[7];let b;e[8]!==d?(b=d("chat.decopilot.back"),e[8]=d,e[9]=b):b=e[9];let k;return e[10]!==c||e[11]!==b?(k=i.jsxs("button",{type:"button",onClick:c,className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground cursor-pointer",children:[A,b]}),e[10]=c,e[11]=b,e[12]=k):k=e[12],i.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border",children:[k,i.jsx("span",{className:"text-xs text-muted-foreground",children:d("chat.decopilot.selectedCount",{count:R})})]}),i.jsx(Os,{items:M,shortlistSet:u,onToggle:S,onHover:l})]})}const _=De(w(ys(m,u,y)));let C;e[13]!==_||e[14]!==l||e[15]!==r||e[16]!==d?(C=et.map(j=>i.jsx($e,{label:Se(j,d),models:_[j],onSelect:r,onHover:l},j)),e[13]=_,e[14]=l,e[15]=r,e[16]=d,e[17]=C):C=e[17];let N;e[18]!==d?(N=Se("other",d),e[18]=d,e[19]=N):N=e[19];let x;e[20]!==_.other||e[21]!==l||e[22]!==r||e[23]!==N?(x=i.jsx($e,{label:N,models:_.other,onSelect:r,onHover:l}),e[20]=_.other,e[21]=l,e[22]=r,e[23]=N,e[24]=x):x=e[24];let v;return e[25]!==C||e[26]!==x?(v=i.jsxs("div",{className:"flex-1 overflow-y-auto px-0.5 pt-1 [touch-action:pan-y]",children:[C,x]}),e[25]=C,e[26]=x,e[27]=v):v=e[27],v}function ai(){const n=U.c(6);let e;n[0]===Symbol.for("react.memo_cache_sentinel")?(e=i.jsx("div",{className:"border-b border-border h-12 bg-background/95 backdrop-blur sticky top-0 z-10",children:i.jsxs("div",{className:"flex items-center gap-2.5 h-12 px-4",children:[i.jsx(J,{className:"size-4 shrink-0"}),i.jsx(J,{className:"flex-1 h-6"}),i.jsx(J,{className:"w-[140px] h-8 shrink-0"})]})}),n[0]=e):e=n[0];let t;n[1]===Symbol.for("react.memo_cache_sentinel")?(t=i.jsxs("div",{className:"flex-1 flex flex-col md:border-r md:w-[420px] md:min-w-[420px] min-h-0 overflow-hidden",children:[e,i.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:Array.from({length:8}).map(Ps)})]}),n[1]=t):t=n[1];let s;n[2]===Symbol.for("react.memo_cache_sentinel")?(s=i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx(J,{className:"size-6 shrink-0"}),i.jsx(J,{className:"h-6 w-32"})]}),n[2]=s):s=n[2];let l;n[3]===Symbol.for("react.memo_cache_sentinel")?(l=i.jsxs("div",{className:"flex flex-col gap-3 py-2 px-0",children:[s,i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(J,{className:"h-6 w-20 rounded-md"}),i.jsx(J,{className:"h-6 w-24 rounded-md"})]})]}),n[3]=l):l=n[3];let r;n[4]===Symbol.for("react.memo_cache_sentinel")?(r=i.jsxs("div",{className:"flex flex-col gap-1.5",children:[i.jsx(J,{className:"h-4 w-24"}),i.jsx(J,{className:"h-4 w-32"})]}),n[4]=r):r=n[4];let a;return n[5]===Symbol.for("react.memo_cache_sentinel")?(a=i.jsxs("div",{className:"flex flex-col md:flex-row h-full sm:h-[460px] min-h-0",children:[t,i.jsx("div",{className:"hidden md:block md:w-[320px] md:shrink-0 p-3",children:i.jsxs("div",{className:"flex flex-col gap-3 py-1 px-1.5",children:[l,i.jsxs("div",{className:"flex flex-col gap-4",children:[r,i.jsxs("div",{className:"flex flex-col gap-1.5",children:[i.jsx(J,{className:"h-4 w-16"}),i.jsx(J,{className:"h-4 w-40"})]})]})]})})]}),n[5]=a):a=n[5],a}function Ps(n,e){return i.jsxs("div",{className:"flex items-center gap-2 min-h-8 py-3 px-3 rounded-lg",children:[i.jsx(J,{className:"size-5 shrink-0 rounded-sm"}),i.jsx(J,{className:"flex-1 h-4"}),i.jsx(J,{className:"w-16 h-5 shrink-0 rounded-md"})]},e)}function st(n){const e=U.c(66),{onClose:t,credentialId:s,onCredentialChange:l,selectedModel:r,onModelChange:a,filterModels:c,compact:h}=n,d=ie(),[o,m]=$.useState(null),[p,u]=$.useState(""),[f,g]=$.useState(!1),I=Ie(),S=Ct();let y;e[0]!==I?.providers?(y=Object.fromEntries((I?.providers??[]).map(Ts)),e[0]=I?.providers,e[1]=y):y=e[1];const w=y,_=ht(),{org:C}=be();let N;e[2]!==l?(N=O=>{l(O),m(null)},e[2]=l,e[3]=N):N=e[3];const x=N;let v;e[4]!==s||e[5]!==t||e[6]!==a?(v=O=>{s&&(a(O),u(""),t())},e[4]=s,e[5]=t,e[6]=a,e[7]=v):v=e[7];const j=v;if(S.length===0){const O=!h&&"sm:w-[740px]";let F;e[8]!==O?(F=ge("flex items-center justify-center p-8 w-full",O),e[8]=O,e[9]=F):F=e[9];let K;e[10]===Symbol.for("react.memo_cache_sentinel")?(K=i.jsx(ns,{}),e[10]=K):K=e[10];let D;return e[11]!==F?(D=i.jsx("div",{className:F,children:K}),e[11]=F,e[12]=D):D=e[12],D}const M=h?"sm:h-[420px]":"sm:h-[460px]";let E;e[13]!==M?(E=ge("flex flex-col md:flex-row h-full min-h-0",M),e[13]=M,e[14]=E):E=e[14];const R=h?"w-full":"md:border-r md:w-[420px] md:min-w-[420px]";let A;e[15]!==R?(A=ge("flex-1 flex flex-col min-h-0 overflow-hidden",R),e[15]=R,e[16]=A):A=e[16];let b;e[17]===Symbol.for("react.memo_cache_sentinel")?(b=i.jsx(Ye,{size:16,className:"text-muted-foreground shrink-0"}),e[17]=b):b=e[17];let k;e[18]!==f||e[19]!==d?(k=d(f?"chat.decopilot.searchAllModels":"chat.decopilot.searchForModel"),e[18]=f,e[19]=d,e[20]=k):k=e[20];let z;e[21]===Symbol.for("react.memo_cache_sentinel")?(z=O=>u(O.target.value),e[21]=z):z=e[21];let T;e[22]!==p||e[23]!==k?(T=i.jsx(fe,{autoFocus:!0,type:"text",placeholder:k,value:p,onChange:z,className:"flex-1 min-w-0 border-0 !shadow-none px-0 h-full text-sm placeholder:text-muted-foreground/50 bg-transparent"}),e[22]=p,e[23]=k,e[24]=T):T=e[24];let L;e[25]!==s||e[26]!==x||e[27]!==S||e[28]!==w||e[29]!==d?(L=S.length>0&&i.jsxs(pt,{value:s??"",onValueChange:x,children:[i.jsxs(xt,{size:"sm",className:"w-auto max-w-[140px] h-8 shrink-0 gap-1.5 px-2 [&>svg:last-child]:hidden",onClick:Fs,children:[i.jsx(gt,{placeholder:d("chat.decopilot.key"),children:(()=>{const O=S.find(te=>te.id===s),F=O?w[O.providerId]:void 0,K=ve(O?.presetId),D=K?.logo??F?.logo,B=K?.name??F?.name??O?.providerId??"Key";return i.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[D?i.jsx("img",{src:D,alt:B,className:"w-4 h-4 rounded shrink-0 dark:bg-white dark:rounded-sm dark:p-px"}):i.jsx("div",{className:"w-4 h-4 rounded bg-primary/10 flex items-center justify-center text-xs font-semibold text-primary shrink-0",children:B.slice(0,1).toUpperCase()}),i.jsx("span",{className:"text-xs truncate",children:B})]})})()}),i.jsx(yt,{className:"size-4 opacity-50 shrink-0 pointer-events-none"})]}),i.jsx(vt,{children:S.map(O=>{const F=w[O.providerId],K=ve(O.presetId),D=K?.logo??F?.logo,B=K?.name??F?.name??O.providerId;return i.jsx(bt,{value:O.id,children:i.jsxs("div",{className:"flex items-center gap-2",children:[D?i.jsx("img",{src:D,alt:B,className:"w-4 h-4 rounded dark:bg-white dark:rounded-sm dark:p-px"}):i.jsx("div",{className:"w-4 h-4 rounded bg-primary/10 flex items-center justify-center text-xs font-semibold text-primary",children:B.slice(0,1).toUpperCase()}),i.jsxs("span",{children:[B," — ",O.label]})]})},O.id)})})]}),e[25]=s,e[26]=x,e[27]=S,e[28]=w,e[29]=d,e[30]=L):L=e[30];let W;e[31]!==T||e[32]!==L?(W=i.jsx("div",{className:"border-b border-border h-12 bg-background/95 backdrop-blur sticky top-0 z-10",children:i.jsxs("label",{className:"flex items-center gap-2.5 h-12 px-4 pr-12 md:pr-4 cursor-text",children:[b,T,L]})}),e[31]=T,e[32]=L,e[33]=W):W=e[33];let P;e[34]!==s?(P=O=>{const{error:F,resetError:K}=O;return i.jsx(ws,{error:F,onRetry:K,credentialId:s??void 0})},e[34]=s,e[35]=P):P=e[35];let V;e[36]===Symbol.for("react.memo_cache_sentinel")?(V=i.jsx(_s,{}),e[36]=V):V=e[36];const G=s??void 0;let H;e[37]===Symbol.for("react.memo_cache_sentinel")?(H=()=>g(As),e[37]=H):H=e[37];let q;e[38]!==c||e[39]!==j||e[40]!==f||e[41]!==p||e[42]!==G?(q=i.jsx($.Suspense,{fallback:V,children:i.jsx(zs,{keyId:G,searchTerm:p,onHover:m,onModelSelect:j,managing:f,onToggleManage:H,filterModels:c})}),e[38]=c,e[39]=j,e[40]=f,e[41]=p,e[42]=G,e[43]=q):q=e[43];let Y;e[44]!==s||e[45]!==P||e[46]!==q?(Y=i.jsx(ut,{fallback:P,children:q},s),e[44]=s,e[45]=P,e[46]=q,e[47]=Y):Y=e[47];let ee;e[48]!==f||e[49]!==_||e[50]!==C||e[51]!==d?(ee=!f&&i.jsxs("div",{className:"border-t border-border flex",children:[i.jsxs("button",{type:"button",onClick:()=>$.startTransition(()=>g(!0)),className:"flex items-center gap-2 flex-1 px-4 py-2.5 text-xs text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer",children:[i.jsx(_t,{className:"size-3.5 shrink-0"}),d("chat.decopilot.manageModels")]}),i.jsx("div",{className:"w-px bg-border shrink-0"}),i.jsxs("button",{type:"button",onClick:()=>_({to:"/$org/settings/ai-providers",params:{org:C.slug}}),className:"flex items-center gap-2 flex-1 px-4 py-2.5 text-xs text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer",children:[i.jsx(jt,{className:"size-3.5 shrink-0"}),d("chat.decopilot.manageApiKeys")]})]}),e[48]=f,e[49]=_,e[50]=C,e[51]=d,e[52]=ee):ee=e[52];let Q;e[53]!==W||e[54]!==Y||e[55]!==ee||e[56]!==A?(Q=i.jsxs("div",{className:A,children:[W,Y,ee]}),e[53]=W,e[54]=Y,e[55]=ee,e[56]=A,e[57]=Q):Q=e[57];let X;e[58]!==h||e[59]!==o||e[60]!==r?(X=!h&&i.jsx("div",{className:"hidden md:flex md:flex-col md:w-[320px] md:shrink-0 p-3",children:i.jsx(us,{model:o??r??null})}),e[58]=h,e[59]=o,e[60]=r,e[61]=X):X=e[61];let Z;return e[62]!==Q||e[63]!==X||e[64]!==E?(Z=i.jsxs("div",{className:E,children:[Q,X]}),e[62]=Q,e[63]=X,e[64]=E,e[65]=Z):Z=e[65],Z}function As(n){return!n}function Fs(n){return n.stopPropagation()}function Ts(n){return[n.id,n]}function Rs(n){const e=U.c(12),{onClose:t}=n,{credentialId:s,setCredentialId:l,selectedModel:r,setModel:a}=Ot();let c;e[0]!==l?(c=o=>{ne("chat_credential_changed",{credential_id:o}),l(o)},e[0]=l,e[1]=c):c=e[1];let h;e[2]!==s||e[3]!==r?.modelId||e[4]!==a?(h=o=>{s&&(ne("chat_model_changed",{from_model_id:r?.modelId??null,to_model_id:o.modelId,to_model_provider:o.providerId??null,credential_id:s}),a({...o,keyId:s}))},e[2]=s,e[3]=r?.modelId,e[4]=a,e[5]=h):h=e[5];let d;return e[6]!==s||e[7]!==t||e[8]!==r||e[9]!==c||e[10]!==h?(d=i.jsx(st,{onClose:t,credentialId:s,onCredentialChange:c,selectedModel:r,onModelChange:h}),e[6]=s,e[7]=t,e[8]=r,e[9]=c,e[10]=h,e[11]=d):d=e[11],d}function Ks(n){const e=U.c(2),{onClose:t}=n;let s;return e[0]!==t?(s=i.jsx(Rs,{onClose:t}),e[0]=t,e[1]=s):s=e[1],s}function Ls(n){const e=U.c(2);let t;return e[0]!==n?(t=i.jsx(st,{...n}),e[0]=n,e[1]=t):t=e[1],t}function ci(n){const e=U.c(2),{onClose:t}=n;let s;return e[0]!==t?(s=i.jsx(Ks,{onClose:t}),e[0]=t,e[1]=s):s=e[1],s}function di(n){const e=U.c(4);let t;e[0]!==n?({...t}=n,e[0]=n,e[1]=t):t=e[1];let s;return e[2]!==t?(s=i.jsx(Ls,{...t}),e[2]=t,e[3]=s):s=e[3],s}export{is as C,di as M,ns as N,Ge as P,ni as S,ai as a,oi as b,ci as c,ri as g,li as i,Ee as m};