openrouter-model-picker
Version:
Third-party React component for OpenRouter model selection
31 lines (28 loc) • 45 kB
JavaScript
;var Sr=Object.defineProperty;var Rr=(o,t,i)=>t in o?Sr(o,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[t]=i;var q=(o,t,i)=>Rr(o,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react");var he={exports:{}},H={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var $e;function Er(){if($e)return H;$e=1;var o=C,t=Symbol.for("react.element"),i=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,d=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,h={key:!0,ref:!0,__self:!0,__source:!0};function T(v,a,g){var b,u={},l=null,p=null;g!==void 0&&(l=""+g),a.key!==void 0&&(l=""+a.key),a.ref!==void 0&&(p=a.ref);for(b in a)c.call(a,b)&&!h.hasOwnProperty(b)&&(u[b]=a[b]);if(v&&v.defaultProps)for(b in a=v.defaultProps,a)u[b]===void 0&&(u[b]=a[b]);return{$$typeof:t,type:v,key:l,ref:p,props:u,_owner:d.current}}return H.Fragment=i,H.jsx=T,H.jsxs=T,H}var K={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Ne;function _r(){return Ne||(Ne=1,process.env.NODE_ENV!=="production"&&function(){var o=C,t=Symbol.for("react.element"),i=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),h=Symbol.for("react.profiler"),T=Symbol.for("react.provider"),v=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),g=Symbol.for("react.suspense"),b=Symbol.for("react.suspense_list"),u=Symbol.for("react.memo"),l=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),R=Symbol.iterator,M="@@iterator";function P(e){if(e===null||typeof e!="object")return null;var n=R&&e[R]||e[M];return typeof n=="function"?n:null}var S=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(e){{for(var n=arguments.length,s=new Array(n>1?n-1:0),f=1;f<n;f++)s[f-1]=arguments[f];$("error",e,s)}}function $(e,n,s){{var f=S.ReactDebugCurrentFrame,j=f.getStackAddendum();j!==""&&(n+="%s",s=s.concat([j]));var k=s.map(function(y){return String(y)});k.unshift("Warning: "+n),Function.prototype.apply.call(console[e],console,k)}}var z=!1,te=!1,ne=!1,B=!1,ie=!1,G;G=Symbol.for("react.module.reference");function V(e){return!!(typeof e=="string"||typeof e=="function"||e===c||e===h||ie||e===d||e===g||e===b||B||e===p||z||te||ne||typeof e=="object"&&e!==null&&(e.$$typeof===l||e.$$typeof===u||e.$$typeof===T||e.$$typeof===v||e.$$typeof===a||e.$$typeof===G||e.getModuleId!==void 0))}function oe(e,n,s){var f=e.displayName;if(f)return f;var j=n.displayName||n.name||"";return j!==""?s+"("+j+")":s}function J(e){return e.displayName||"Context"}function x(e){if(e==null)return null;if(typeof e.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case c:return"Fragment";case i:return"Portal";case h:return"Profiler";case d:return"StrictMode";case g:return"Suspense";case b:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case v:var n=e;return J(n)+".Consumer";case T:var s=e;return J(s._context)+".Provider";case a:return oe(e,e.render,"ForwardRef");case u:var f=e.displayName||null;return f!==null?f:x(e.type)||"Memo";case l:{var j=e,k=j._payload,y=j._init;try{return x(y(k))}catch{return null}}}return null}var F=Object.assign,L=0,ge,ye,ve,xe,be,je,Ce;function we(){}we.__reactDisabledLog=!0;function Qe(){{if(L===0){ge=console.log,ye=console.info,ve=console.warn,xe=console.error,be=console.group,je=console.groupCollapsed,Ce=console.groupEnd;var e={configurable:!0,enumerable:!0,value:we,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}L++}}function er(){{if(L--,L===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:ge}),info:F({},e,{value:ye}),warn:F({},e,{value:ve}),error:F({},e,{value:xe}),group:F({},e,{value:be}),groupCollapsed:F({},e,{value:je}),groupEnd:F({},e,{value:Ce})})}L<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var se=S.ReactCurrentDispatcher,ae;function X(e,n,s){{if(ae===void 0)try{throw Error()}catch(j){var f=j.stack.trim().match(/\n( *(at )?)/);ae=f&&f[1]||""}return`
`+ae+e}}var le=!1,Z;{var rr=typeof WeakMap=="function"?WeakMap:Map;Z=new rr}function ke(e,n){if(!e||le)return"";{var s=Z.get(e);if(s!==void 0)return s}var f;le=!0;var j=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var k;k=se.current,se.current=null,Qe();try{if(n){var y=function(){throw Error()};if(Object.defineProperty(y.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(y,[])}catch(A){f=A}Reflect.construct(e,[],y)}else{try{y.call()}catch(A){f=A}e.call(y.prototype)}}else{try{throw Error()}catch(A){f=A}e()}}catch(A){if(A&&f&&typeof A.stack=="string"){for(var m=A.stack.split(`
`),I=f.stack.split(`
`),E=m.length-1,_=I.length-1;E>=1&&_>=0&&m[E]!==I[_];)_--;for(;E>=1&&_>=0;E--,_--)if(m[E]!==I[_]){if(E!==1||_!==1)do if(E--,_--,_<0||m[E]!==I[_]){var D=`
`+m[E].replace(" at new "," at ");return e.displayName&&D.includes("<anonymous>")&&(D=D.replace("<anonymous>",e.displayName)),typeof e=="function"&&Z.set(e,D),D}while(E>=1&&_>=0);break}}}finally{le=!1,se.current=k,er(),Error.prepareStackTrace=j}var U=e?e.displayName||e.name:"",N=U?X(U):"";return typeof e=="function"&&Z.set(e,N),N}function tr(e,n,s){return ke(e,!1)}function nr(e){var n=e.prototype;return!!(n&&n.isReactComponent)}function Q(e,n,s){if(e==null)return"";if(typeof e=="function")return ke(e,nr(e));if(typeof e=="string")return X(e);switch(e){case g:return X("Suspense");case b:return X("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case a:return tr(e.render);case u:return Q(e.type,n,s);case l:{var f=e,j=f._payload,k=f._init;try{return Q(k(j),n,s)}catch{}}}return""}var Y=Object.prototype.hasOwnProperty,Te={},Se=S.ReactDebugCurrentFrame;function ee(e){if(e){var n=e._owner,s=Q(e.type,e._source,n?n.type:null);Se.setExtraStackFrame(s)}else Se.setExtraStackFrame(null)}function ir(e,n,s,f,j){{var k=Function.call.bind(Y);for(var y in e)if(k(e,y)){var m=void 0;try{if(typeof e[y]!="function"){var I=Error((f||"React class")+": "+s+" type `"+y+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[y]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw I.name="Invariant Violation",I}m=e[y](n,y,f,s,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){m=E}m&&!(m instanceof Error)&&(ee(j),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",f||"React class",s,y,typeof m),ee(null)),m instanceof Error&&!(m.message in Te)&&(Te[m.message]=!0,ee(j),w("Failed %s type: %s",s,m.message),ee(null))}}}var or=Array.isArray;function ce(e){return or(e)}function sr(e){{var n=typeof Symbol=="function"&&Symbol.toStringTag,s=n&&e[Symbol.toStringTag]||e.constructor.name||"Object";return s}}function ar(e){try{return Re(e),!1}catch{return!0}}function Re(e){return""+e}function Ee(e){if(ar(e))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",sr(e)),Re(e)}var _e=S.ReactCurrentOwner,lr={key:!0,ref:!0,__self:!0,__source:!0},Pe,Fe;function cr(e){if(Y.call(e,"ref")){var n=Object.getOwnPropertyDescriptor(e,"ref").get;if(n&&n.isReactWarning)return!1}return e.ref!==void 0}function dr(e){if(Y.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function ur(e,n){typeof e.ref=="string"&&_e.current}function fr(e,n){{var s=function(){Pe||(Pe=!0,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};s.isReactWarning=!0,Object.defineProperty(e,"key",{get:s,configurable:!0})}}function pr(e,n){{var s=function(){Fe||(Fe=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};s.isReactWarning=!0,Object.defineProperty(e,"ref",{get:s,configurable:!0})}}var hr=function(e,n,s,f,j,k,y){var m={$$typeof:t,type:e,key:n,ref:s,props:y,_owner:k};return m._store={},Object.defineProperty(m._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(m,"_self",{configurable:!1,enumerable:!1,writable:!1,value:f}),Object.defineProperty(m,"_source",{configurable:!1,enumerable:!1,writable:!1,value:j}),Object.freeze&&(Object.freeze(m.props),Object.freeze(m)),m};function mr(e,n,s,f,j){{var k,y={},m=null,I=null;s!==void 0&&(Ee(s),m=""+s),dr(n)&&(Ee(n.key),m=""+n.key),cr(n)&&(I=n.ref,ur(n,j));for(k in n)Y.call(n,k)&&!lr.hasOwnProperty(k)&&(y[k]=n[k]);if(e&&e.defaultProps){var E=e.defaultProps;for(k in E)y[k]===void 0&&(y[k]=E[k])}if(m||I){var _=typeof e=="function"?e.displayName||e.name||"Unknown":e;m&&fr(y,_),I&&pr(y,_)}return hr(e,m,I,j,f,_e.current,y)}}var de=S.ReactCurrentOwner,Me=S.ReactDebugCurrentFrame;function W(e){if(e){var n=e._owner,s=Q(e.type,e._source,n?n.type:null);Me.setExtraStackFrame(s)}else Me.setExtraStackFrame(null)}var ue;ue=!1;function fe(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Oe(){{if(de.current){var e=x(de.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function gr(e){return""}var Ie={};function yr(e){{var n=Oe();if(!n){var s=typeof e=="string"?e:e.displayName||e.name;s&&(n=`
Check the top-level render call using <`+s+">.")}return n}}function Ae(e,n){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var s=yr(n);if(Ie[s])return;Ie[s]=!0;var f="";e&&e._owner&&e._owner!==de.current&&(f=" It was passed a child from "+x(e._owner.type)+"."),W(e),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',s,f),W(null)}}function De(e,n){{if(typeof e!="object")return;if(ce(e))for(var s=0;s<e.length;s++){var f=e[s];fe(f)&&Ae(f,n)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var j=P(e);if(typeof j=="function"&&j!==e.entries)for(var k=j.call(e),y;!(y=k.next()).done;)fe(y.value)&&Ae(y.value,n)}}}function vr(e){{var n=e.type;if(n==null||typeof n=="string")return;var s;if(typeof n=="function")s=n.propTypes;else if(typeof n=="object"&&(n.$$typeof===a||n.$$typeof===u))s=n.propTypes;else return;if(s){var f=x(n);ir(s,e.props,"prop",f,e)}else if(n.PropTypes!==void 0&&!ue){ue=!0;var j=x(n);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",j||"Unknown")}typeof n.getDefaultProps=="function"&&!n.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function xr(e){{for(var n=Object.keys(e.props),s=0;s<n.length;s++){var f=n[s];if(f!=="children"&&f!=="key"){W(e),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",f),W(null);break}}e.ref!==null&&(W(e),w("Invalid attribute `ref` supplied to `React.Fragment`."),W(null))}}var Le={};function ze(e,n,s,f,j,k){{var y=V(e);if(!y){var m="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(m+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var I=gr();I?m+=I:m+=Oe();var E;e===null?E="null":ce(e)?E="array":e!==void 0&&e.$$typeof===t?(E="<"+(x(e.type)||"Unknown")+" />",m=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,m)}var _=mr(e,n,s,j,k);if(_==null)return _;if(y){var D=n.children;if(D!==void 0)if(f)if(ce(D)){for(var U=0;U<D.length;U++)De(D[U],e);Object.freeze&&Object.freeze(D)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else De(D,e)}if(Y.call(n,"key")){var N=x(e),A=Object.keys(n).filter(function(Tr){return Tr!=="key"}),pe=A.length>0?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}";if(!Le[N+pe]){var kr=A.length>0?"{"+A.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,pe,N,kr,N),Le[N+pe]=!0}}return e===c?xr(_):vr(_),_}}function br(e,n,s){return ze(e,n,s,!0)}function jr(e,n,s){return ze(e,n,s,!1)}var Cr=jr,wr=br;K.Fragment=c,K.jsx=Cr,K.jsxs=wr}()),K}process.env.NODE_ENV==="production"?he.exports=Er():he.exports=_r();var r=he.exports,Pr={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const Fr=o=>o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Mr=(o,t)=>{const i=C.forwardRef(({color:c="currentColor",size:d=24,strokeWidth:h=2,absoluteStrokeWidth:T,children:v,...a},g)=>C.createElement("svg",{ref:g,...Pr,width:d,height:d,stroke:c,strokeWidth:T?Number(h)*24/Number(d):h,className:`lucide lucide-${Fr(o)}`,...a},[...t.map(([b,u])=>C.createElement(b,u)),...(Array.isArray(v)?v:[v])||[]]));return i.displayName=`${o}`,i};var O=Mr;const Or=O("AlertCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),Ir=O("Brain",[["path",{d:"M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24 2.5 2.5 0 0 1 1.98-3A2.5 2.5 0 0 1 9.5 2Z",key:"1mhkh5"}],["path",{d:"M14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 14.5 2Z",key:"1d6s00"}]]),Ar=O("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),We=O("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]),Dr=O("Eye",[["path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z",key:"rwhkz3"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),Lr=O("FileText",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["line",{x1:"16",x2:"8",y1:"13",y2:"13",key:"14keom"}],["line",{x1:"16",x2:"8",y1:"17",y2:"17",key:"17nazh"}],["line",{x1:"10",x2:"8",y1:"9",y2:"9",key:"1a5vjj"}]]),zr=O("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]),Ue=O("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),$r=O("Loader2",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]),Nr=O("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),Wr=O("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),Ur=O("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]),Br=O("Shield",[["path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z",key:"3xmgem"}]]),Vr=O("StopCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{width:"6",height:"6",x:"9",y:"9",key:"1wrtvo"}]]),Yr=O("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),qr=O("Zap",[["polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2",key:"45s27k"}]]),Hr="https://openrouter.ai/api/v1/models",Kr="https://openrouter.ai/api/v1/chat/completions";class Ve{constructor(t){q(this,"endpoint");q(this,"cache",null);q(this,"cacheTimestamp",0);q(this,"CACHE_DURATION",5*60*1e3);this.endpoint=t||Hr}async fetchModels(t=!1){if(!t&&this.cache&&Date.now()-this.cacheTimestamp<this.CACHE_DURATION)return this.cache;try{const i={"Content-Type":"application/json"},c=await fetch(this.endpoint,{headers:i});if(!c.ok)throw new Error(`HTTP error! status: ${c.status}`);const d=await c.json(),h=this.filterAvailableModels(d.data).map(T=>this.transformModel(T));return this.cache=h,this.cacheTimestamp=Date.now(),h}catch(i){return console.error("Failed to fetch models from OpenRouter:",i),this.cache?this.cache:this.getFallbackModels()}}async testModel(t,i,c="Hello! Please respond with a brief greeting."){var d,h,T,v;if(!i)return{success:!1,error:"API key is required for testing models"};try{const a=await fetch(Kr,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify({model:t,messages:[{role:"user",content:c}],max_tokens:100,temperature:.7})});if(!a.ok){const b=await a.json().catch(()=>({}));return{success:!1,error:`HTTP ${a.status}: ${((d=b.error)==null?void 0:d.message)||a.statusText}`}}const g=await a.json();return{success:!0,response:((v=(T=(h=g.choices)==null?void 0:h[0])==null?void 0:T.message)==null?void 0:v.content)||"No response content",usage:g.usage}}catch(a){return{success:!1,error:a instanceof Error?a.message:"Unknown error occurred"}}}filterAvailableModels(t){return t.filter(i=>{if(!i.context_length||i.context_length<=0)return console.debug(`Filtered out model ${i.id}: invalid context length (${i.context_length})`),!1;if(this.isModelDeprecated(i))return console.debug(`Filtered out model ${i.id}: deprecated`),!1;if(i.per_request_limits){const d=parseInt(i.per_request_limits.prompt_tokens||"0"),h=parseInt(i.per_request_limits.completion_tokens||"0");if(d<=0&&h<=0)return console.debug(`Filtered out model ${i.id}: zero capacity limits`),!1}return!i.pricing||!i.pricing.prompt&&!i.pricing.completion?(console.debug(`Filtered out model ${i.id}: invalid pricing`),!1):!i.id||i.id.trim()===""?(console.debug("Filtered out model: empty or invalid ID"),!1):this.isKnownProblematicModel(i.id)?(console.debug(`Filtered out model ${i.id}: known problematic model`),!1):!0})}isModelDeprecated(t){var c,d,h,T;if((d=(c=t.architecture)==null?void 0:c.instruct_type)!=null&&d.toLowerCase().includes("deprecated"))return!0;if(t.description){const v=t.description.toLowerCase();if(["deprecated","has been deprecated","please switch to","no longer supported","discontinued","replaced by"].some(g=>v.includes(g)))return!0}if([/.*-exp-\d{2}-\d{2}$/,/.*experimental.*$/i].some(v=>v.test(t.id))){const v=parseFloat(((h=t.pricing)==null?void 0:h.prompt)||"0"),a=parseFloat(((T=t.pricing)==null?void 0:T.completion)||"0");if(v===0&&a===0)return!0}return!1}isKnownProblematicModel(t){return["google/gemini-2.5-pro-exp-03-25"].includes(t)}categorizeModels(t){const i=[],c=[];return t.forEach(d=>{d.costTier==="free"?i.push(d):c.push(d)}),{freeModels:i,paidModels:c}}transformModel(t){const i=this.extractProvider(t.id),c=this.calculateCostTier(t.pricing),d=this.extractFeatures(t);return{id:t.id,name:t.name,provider:i,costTier:c,description:t.description||"No description available",features:d,pricing:{input:parseFloat(t.pricing.prompt)||0,output:parseFloat(t.pricing.completion)||0,currency:"USD"},context:t.context_length,multimodal:this.isMultimodal(t),reasoning:this.isReasoningModel(t),streamCancel:this.supportsStreamCancellation(t)}}extractProvider(t){const i=t.split("/");if(i.length>1){const c=i[0];return c.charAt(0).toUpperCase()+c.slice(1)}return"Unknown"}calculateCostTier(t){const i=parseFloat(t.prompt)||0,c=parseFloat(t.completion)||0;if(i===0&&c===0)return"free";const d=(i+c)/2;return d<1e-6?"low":d<1e-5?"medium":"high"}extractFeatures(t){var h;const i=[];((h=t.architecture.input_modalities)!=null&&h.includes("image")||t.architecture.modality==="multimodal")&&i.push("Vision"),this.isReasoningModel(t)&&i.push("Reasoning"),this.supportsStreamCancellation(t)&&i.push("Stream Cancel"),t.top_provider.is_moderated&&i.push("Moderated"),t.context_length>1e5&&i.push("Long Context"),t.architecture.instruct_type&&i.push("Instruct");const c=parseFloat(t.pricing.prompt)||0,d=parseFloat(t.pricing.completion)||0;return c===0&&d===0&&i.push("Free"),i}isMultimodal(t){var i;return((i=t.architecture.input_modalities)==null?void 0:i.includes("image"))||t.architecture.modality==="multimodal"||!1}isReasoningModel(t){var d;const i=((d=t.id)==null?void 0:d.toLowerCase())||"";return[/\bo1(-preview|-mini)?\b/i,/\bdeepseek.*r1\b/i,/\bgemini.*thinking\b/i,/\bclaude.*thinking/i,/anthropic.*thinking/i,/\bgrok.*reasoning\b/i,/\bminimax.*m1\b/i,/\bqwen.*r1\b/i,/reasoning.*model/i,/thinking.*model/i].some(h=>h.test(i))}supportsStreamCancellation(t){const i=this.extractProvider(t.id).toLowerCase();return new Set(["openai","azure","anthropic","fireworks","mancer","recursal","anyscale","lepton","octoai","novita","deepinfra","together","cohere","hyperbolic","infermatic","avian","xai","cloudflare","sfcompute","nineteen","liquid","friendli","chutes","deepseek"]).has(i)}getFallbackModels(){return[{id:"openai/gpt-4o-mini",name:"GPT-4o Mini",provider:"OpenAI",costTier:"low",description:"Fast and affordable multimodal model",features:["Vision","Fast"],pricing:{input:15e-5,output:6e-4,currency:"USD"},context:128e3,multimodal:!0,reasoning:!1,streamCancel:!0},{id:"openai/o1-preview",name:"o1-preview",provider:"OpenAI",costTier:"high",description:"Advanced reasoning model with enhanced thinking capabilities",features:["Reasoning","Advanced"],pricing:{input:.015,output:.06,currency:"USD"},context:128e3,multimodal:!1,reasoning:!0,streamCancel:!0},{id:"openai/gpt-4o",name:"GPT-4o",provider:"OpenAI",costTier:"high",description:"Most capable multimodal model",features:["Vision","Advanced"],pricing:{input:.005,output:.015,currency:"USD"},context:128e3,multimodal:!0,reasoning:!1,streamCancel:!0},{id:"deepseek/deepseek-r1",name:"DeepSeek R1",provider:"DeepSeek",costTier:"medium",description:"Advanced reasoning model with step-by-step thinking",features:["Reasoning","Long Context"],pricing:{input:.002,output:.008,currency:"USD"},context:2e5,multimodal:!1,reasoning:!0,streamCancel:!0},{id:"anthropic/claude-3-sonnet",name:"Claude 3 Sonnet",provider:"Anthropic",costTier:"medium",description:"Balanced performance and cost",features:["Long Context"],pricing:{input:.003,output:.015,currency:"USD"},context:2e5,multimodal:!1,reasoning:!1,streamCancel:!0},{id:"meta-llama/llama-3.2-3b-instruct:free",name:"Llama 3.2 3B Instruct (Free)",provider:"Meta",costTier:"free",description:"Free tier access to Llama 3.2 3B",features:["Free","Instruct"],pricing:{input:0,output:0,currency:"USD"},context:131072,multimodal:!1,reasoning:!1,streamCancel:!1}]}clearCache(){this.cache=null,this.cacheTimestamp=0}}function Ye(o,t){const[i,c]=C.useState([]),[d,h]=C.useState([]),[T,v]=C.useState([]),[a,g]=C.useState(!0),[b,u]=C.useState(null),[l]=C.useState(()=>new Ve(o)),p=C.useCallback(async(P=!1)=>{try{g(!0),u(null);let S;try{S=await l.fetchModels(P)}catch(z){if(t&&t.length>0)S=t;else throw z}c(S);const{freeModels:w,paidModels:$}=l.categorizeModels(S);h(w),v($)}catch(S){const w=S instanceof Error?S.message:"Failed to fetch models";if(u(w),t&&t.length>0){c(t);const{freeModels:$,paidModels:z}=l.categorizeModels(t);h($),v(z)}}finally{g(!1)}},[l,t]),R=C.useCallback(async()=>{await p(!0)},[p]),M=C.useCallback(async(P,S,w)=>await l.testModel(P,S,w),[l]);return C.useEffect(()=>{p()},[p]),{models:i,freeModels:d,paidModels:T,loading:a,error:b,refresh:R,testModel:M}}const Be={searchTerm:"",selectedProviders:[],selectedCostTiers:[],showMultimodal:!1,hideExperimental:!1,showReasoning:!1,showStreamCancel:!1};function qe(o){const[t,i]=C.useState(Be),[c,d]=C.useState({key:null,direction:"asc"}),h=C.useMemo(()=>[...new Set(o.map(p=>p.provider))].sort(),[o]),T=C.useCallback((l,p)=>{i(R=>({...R,[l]:p}))},[]),v=C.useCallback(()=>{i(Be)},[]),a=C.useCallback((l,p="asc")=>{d(R=>R.key===l?{key:l,direction:R.direction==="asc"?"desc":"asc"}:{key:l,direction:p})},[]),g=C.useCallback(l=>[/.*-exp-\d{2}-\d{2}$/i,/.*experimental.*$/i,/.*-preview.*$/i,/.*-beta.*$/i,/.*-alpha.*$/i,/.*-test.*$/i].some(R=>R.test(l.id))||l.name.toLowerCase().includes("experimental")||l.name.toLowerCase().includes("preview")||l.name.toLowerCase().includes("beta")||l.description.toLowerCase().includes("experimental"),[]),b=C.useMemo(()=>{let l=[...o];if(t.searchTerm){const p=t.searchTerm.toLowerCase();l=l.filter(R=>{var M;return R.name.toLowerCase().includes(p)||R.provider.toLowerCase().includes(p)||R.description.toLowerCase().includes(p)||R.id.toLowerCase().includes(p)||((M=R.features)==null?void 0:M.some(P=>P.toLowerCase().includes(p)))})}return t.selectedProviders.length>0&&(l=l.filter(p=>t.selectedProviders.includes(p.provider))),t.selectedCostTiers.length>0&&(l=l.filter(p=>t.selectedCostTiers.includes(p.costTier))),t.showMultimodal&&(l=l.filter(p=>p.multimodal)),t.showReasoning&&(l=l.filter(p=>p.reasoning)),t.showStreamCancel&&(l=l.filter(p=>p.streamCancel)),t.hideExperimental&&(l=l.filter(p=>!g(p))),c.key&&l.sort((p,R)=>{const M=p[c.key],P=R[c.key];if(M===void 0&&P===void 0)return 0;if(M===void 0)return 1;if(P===void 0)return-1;let S=0;return typeof M=="string"&&typeof P=="string"?S=M.localeCompare(P):typeof M=="number"&&typeof P=="number"?S=M-P:S=String(M).localeCompare(String(P)),c.direction==="desc"?-S:S}),l},[o,t,c,g]),u=C.useMemo(()=>({total:o.length,filtered:b.length}),[o.length,b.length]);return{filteredModels:b,filterState:t,sortConfig:c,updateFilter:T,clearFilters:v,setSort:a,availableProviders:h,filterStats:u}}function me(o){if(o===0)return"Free";const t=o*1e3;return t<.01?`$${t.toFixed(4)}/1K`:`$${t.toFixed(2)}/1K`}function He(o){return o?o>=1e6?`${(o/1e6).toFixed(1)}M`:o>=1e3?`${(o/1e3).toFixed(0)}K`:o.toString():"Unknown"}function Gr(o){switch(o){case"free":return"#10b981";case"low":return"#3b82f6";case"medium":return"#f59e0b";case"high":return"#ef4444";default:return"#6b7280"}}function Ke(o){switch(o){case"free":return"Free";case"low":return"Low Cost";case"medium":return"Medium Cost";case"high":return"High Cost";default:return"Unknown"}}function Ge(o,t){return o.length<=t?o:o.slice(0,t-3)+"..."}function Jr(o,t){let i;return(...c)=>{clearTimeout(i),i=setTimeout(()=>o(...c),t)}}const Xr=["free","low","medium","high"];function Je({filterState:o,onFilterChange:t,onClearFilters:i,availableProviders:c,filterStats:d}){const h=C.useRef(),T=C.useCallback(u=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{t("searchTerm",u)},300)},[t]),v=u=>{T(u.target.value)},a=u=>{const l=o.selectedProviders.includes(u)?o.selectedProviders.filter(p=>p!==u):[...o.selectedProviders,u];t("selectedProviders",l)},g=u=>{const l=o.selectedCostTiers.includes(u)?o.selectedCostTiers.filter(p=>p!==u):[...o.selectedCostTiers,u];t("selectedCostTiers",l)},b=o.searchTerm||o.selectedProviders.length>0||o.selectedCostTiers.length>0||o.showMultimodal||o.showReasoning||o.showStreamCancel||o.hideExperimental;return r.jsxs("div",{className:"filter-bar",children:[r.jsxs("div",{style:{position:"relative",marginBottom:"0.75rem"},children:[r.jsx(Ur,{style:{position:"absolute",left:"0.75rem",top:"50%",transform:"translateY(-50%)",color:"var(--or-text-secondary)",width:"1rem",height:"1rem"}}),r.jsx("input",{type:"text",placeholder:"Search models, providers, or features...",className:"search-input",style:{paddingLeft:"2.5rem"},onChange:v,defaultValue:o.searchTerm})]}),r.jsxs("div",{className:"filter-row",style:{flexDirection:"column",gap:"0.5rem",alignItems:"flex-start"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",justifyContent:"space-between",width:"100%"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[r.jsx(zr,{style:{width:"1rem",height:"1rem",color:"var(--or-text-secondary)"}}),r.jsx("span",{style:{fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:"Filters:"})]}),b&&r.jsxs("button",{onClick:i,className:"clear-filters-button",style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[r.jsx(Wr,{style:{width:"0.75rem",height:"0.75rem"}}),"Clear all"]})]}),r.jsxs("div",{style:{width:"100%"},children:[r.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.5rem",alignItems:"center",marginBottom:"0.25rem"},children:r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--or-text-secondary)",textTransform:"uppercase",fontWeight:"500",minWidth:"fit-content"},children:"Provider:"})}),r.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.375rem",maxHeight:"50px",overflowY:"auto",padding:"0.375rem",border:"1px solid var(--or-border)",borderRadius:"0.25rem",backgroundColor:"rgba(0, 0, 0, 0.01)"},children:c.map(u=>r.jsx("button",{onClick:()=>a(u),className:`filter-button ${o.selectedProviders.includes(u)?"active":""}`,style:{fontSize:"0.7rem",padding:"0.25rem 0.5rem"},children:u},u))})]}),r.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.375rem",alignItems:"center"},children:[r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--or-text-secondary)",textTransform:"uppercase",fontWeight:"500"},children:"Cost:"}),Xr.map(u=>r.jsx("button",{onClick:()=>g(u),className:`filter-button ${o.selectedCostTiers.includes(u)?"active":""}`,style:{fontSize:"0.7rem",padding:"0.25rem 0.5rem"},children:Ke(u)},u))]}),r.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.75rem",alignItems:"center"},children:[r.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.375rem",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:o.showMultimodal,onChange:u=>t("showMultimodal",u.target.checked),style:{width:"0.875rem",height:"0.875rem"}}),r.jsx("span",{style:{fontSize:"0.8rem",color:"var(--or-text)"},children:"Multimodal only"})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[r.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.375rem",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:o.showReasoning,onChange:u=>t("showReasoning",u.target.checked),style:{width:"0.875rem",height:"0.875rem"}}),r.jsx("span",{style:{fontSize:"0.8rem",color:"var(--or-text)"},children:"Reasoning only"})]}),r.jsx("div",{style:{position:"relative",display:"flex",alignItems:"center",cursor:"help"},title:"⚠️ Reasoning detection uses pattern matching for known models (o1, DeepSeek R1, Gemini Thinking, etc.). New reasoning models may not be detected. OpenRouter doesn't provide an official reasoning capability field.",children:r.jsx(Ue,{style:{width:"0.75rem",height:"0.75rem",color:"var(--or-text-secondary)",opacity:.7}})})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[r.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.375rem",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:o.showStreamCancel,onChange:u=>t("showStreamCancel",u.target.checked),style:{width:"0.875rem",height:"0.875rem"}}),r.jsx("span",{style:{fontSize:"0.8rem",color:"var(--or-text)"},children:"Stream cancel only"})]}),r.jsx("div",{style:{position:"relative",display:"flex",alignItems:"center",cursor:"help"},title:"⚠️ Stream cancellation stops model processing and billing immediately when you abort a request. Provider-dependent: OpenAI, Anthropic, DeepSeek support it; Google, Groq, HuggingFace don't. Critical for cost control in streaming scenarios.",children:r.jsx(Ue,{style:{width:"0.75rem",height:"0.75rem",color:"var(--or-text-secondary)",opacity:.7}})})]}),r.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.375rem",cursor:"pointer"},children:[r.jsx("input",{type:"checkbox",checked:o.hideExperimental,onChange:u=>t("hideExperimental",u.target.checked),style:{width:"0.875rem",height:"0.875rem"}}),r.jsx("span",{style:{fontSize:"0.8rem",color:"var(--or-text)"},children:"Hide experimental"})]})]})]}),r.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:"0.8rem",color:"var(--or-text-secondary)",marginTop:"0.5rem",paddingTop:"0.5rem",borderTop:"1px solid var(--or-border)"},children:[r.jsxs("span",{className:"results-count",children:["Showing ",d.filtered," of ",d.total," models"]}),d.filtered<d.total&&r.jsxs("span",{style:{color:"var(--or-primary-color)",marginLeft:"1rem"},children:[d.total-d.filtered," hidden by filters"]})]})]})}function re({models:o,selectedModel:t,onModelSelect:i,sortConfig:c,onSort:d}){const h=a=>c.key!==a?r.jsx(We,{style:{width:"1rem",height:"1rem",color:"var(--or-text-secondary)"}}):c.direction==="asc"?r.jsx(We,{style:{width:"1rem",height:"1rem",color:"var(--or-primary-color)"}}):r.jsx(Ar,{style:{width:"1rem",height:"1rem",color:"var(--or-primary-color)"}}),T=a=>{const g={width:"0.75rem",height:"0.75rem"};switch(a.toLowerCase()){case"vision":return r.jsx(Dr,{style:g});case"reasoning":return r.jsx(Ir,{style:g});case"stream cancel":return r.jsx(Vr,{style:g});case"fast":return r.jsx(qr,{style:g});case"moderated":return r.jsx(Br,{style:g});case"long context":return r.jsx(Lr,{style:g});default:return null}},v=a=>{if(!a||a.length===0)return null;const g=a.slice(0,3),b=a.length-3;return r.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.25rem"},children:[g.map((u,l)=>r.jsxs("span",{className:"feature-tag",children:[T(u),u]},l)),b>0&&r.jsxs("span",{style:{padding:"0.25rem 0.5rem",fontSize:"0.75rem",color:"var(--or-text-secondary)",borderRadius:"0.375rem"},children:["+",b," more"]})]})};return r.jsxs("div",{className:"table-container",children:[r.jsxs("table",{className:"model-table",children:[r.jsx("thead",{children:r.jsxs("tr",{children:[r.jsx("th",{children:r.jsxs("button",{onClick:()=>d("name"),style:{display:"flex",alignItems:"center",gap:"0.5rem",background:"none",border:"none",cursor:"pointer",fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:["Model",h("name")]})}),r.jsx("th",{children:r.jsxs("button",{onClick:()=>d("provider"),style:{display:"flex",alignItems:"center",gap:"0.5rem",background:"none",border:"none",cursor:"pointer",fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:["Provider",h("provider")]})}),r.jsx("th",{children:r.jsxs("button",{onClick:()=>d("costTier"),style:{display:"flex",alignItems:"center",gap:"0.5rem",background:"none",border:"none",cursor:"pointer",fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:["Cost",h("costTier")]})}),r.jsx("th",{children:r.jsxs("button",{onClick:()=>d("context"),style:{display:"flex",alignItems:"center",gap:"0.5rem",background:"none",border:"none",cursor:"pointer",fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:["Context",h("context")]})}),r.jsx("th",{children:r.jsx("span",{style:{fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:"Features"})}),r.jsx("th",{children:r.jsx("span",{style:{fontSize:"0.875rem",fontWeight:"500",color:"var(--or-text)"},children:"Description"})})]})}),r.jsx("tbody",{children:o.map(a=>r.jsxs("tr",{onClick:()=>i(a.id),className:t===a.id?"selected":"",children:[r.jsx("td",{children:r.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[r.jsx("span",{style:{fontWeight:"500",color:"var(--or-text)"},children:a.name}),r.jsx("span",{style:{fontSize:"0.75rem",color:"var(--or-text-secondary)"},children:a.id})]})}),r.jsx("td",{children:r.jsx("span",{style:{fontSize:"0.875rem",color:"var(--or-text)"},children:a.provider})}),r.jsx("td",{children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.25rem"},children:[r.jsx("span",{className:`cost-tier-${a.costTier}`,style:{display:"inline-flex",alignItems:"center",padding:"0.25rem 0.5rem",fontSize:"0.75rem",fontWeight:"500",borderRadius:"0.375rem",color:"white",width:"fit-content"},children:a.costTier.charAt(0).toUpperCase()+a.costTier.slice(1)}),a.pricing&&r.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--or-text-secondary)"},children:["In: ",me(a.pricing.input)," | Out: ",me(a.pricing.output)]})]})}),r.jsx("td",{children:r.jsx("span",{style:{fontSize:"0.875rem",color:"var(--or-text)"},children:He(a.context)})}),r.jsx("td",{children:v(a.features)}),r.jsx("td",{children:r.jsx("p",{style:{fontSize:"0.875rem",color:"var(--or-text-secondary)",maxWidth:"20rem",margin:0},children:Ge(a.description,100)})})]},a.id))})]}),o.length===0&&r.jsxs("div",{className:"empty-container",children:[r.jsx("div",{style:{fontSize:"1.125rem",fontWeight:"500",marginBottom:"0.5rem",color:"var(--or-text)"},children:"No models found"}),r.jsx("p",{style:{fontSize:"0.875rem",textAlign:"center",maxWidth:"24rem",margin:0},children:"Try adjusting your search terms or clearing some filters to see more results."})]})]})}function Xe({message:o="Loading models..."}){return r.jsxs("div",{className:"loading-container",children:[r.jsx($r,{className:"loading-spinner spinner",style:{width:"2rem",height:"2rem"}}),r.jsx("p",{style:{color:"var(--or-text-secondary)",textAlign:"center"},children:o})]})}function Ze({error:o,onRetry:t}){return r.jsxs("div",{className:"error-container",children:[r.jsx(Or,{style:{width:"2rem",height:"2rem",color:"#ef4444",marginBottom:"1rem"}}),r.jsx("h3",{style:{fontSize:"1.125rem",fontWeight:"500",color:"var(--or-text)",marginBottom:"0.5rem"},children:"Failed to load models"}),r.jsx("p",{className:"error-message",style:{textAlign:"center",maxWidth:"24rem"},children:o}),t&&r.jsxs("button",{onClick:t,className:"retry-button",style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[r.jsx(Nr,{style:{width:"1rem",height:"1rem"}}),"Try Again"]})]})}function Zr({onClearFilters:o}){return r.jsxs("div",{className:"empty-container",children:[r.jsx("div",{style:{fontSize:"3.75rem",marginBottom:"1rem"},children:"🔍"}),r.jsx("h3",{style:{fontSize:"1.125rem",fontWeight:"500",color:"var(--or-text)",marginBottom:"0.5rem"},children:"No models match your criteria"}),r.jsx("p",{style:{color:"var(--or-text-secondary)",textAlign:"center",maxWidth:"24rem",marginBottom:"1rem"},children:"Try adjusting your search terms or clearing some filters to see more results."}),o&&r.jsx("button",{onClick:o,style:{padding:"0.5rem 1rem",backgroundColor:"rgba(0, 0, 0, 0.05)",color:"var(--or-text)",border:"none",borderRadius:"0.5rem",cursor:"pointer",fontSize:"0.875rem"},children:"Clear all filters"})]})}function Qr({isOpen:o,onClose:t,selectedModel:i,onModelChange:c,onModelSelect:d,apiEndpoint:h,fallbackModels:T,theme:v="light",maxHeight:a="80vh",maxWidth:g,className:b,categorizeByType:u=!1}){const{models:l,freeModels:p,paidModels:R,loading:M,error:P,refresh:S}=Ye(h,T),{filteredModels:w,filterState:$,sortConfig:z,updateFilter:te,clearFilters:ne,setSort:B,availableProviders:ie,filterStats:G}=qe(l);C.useEffect(()=>{const x=F=>{F.key==="Escape"&&t()};return o&&(document.addEventListener("keydown",x),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",x),document.body.style.overflow=""}},[o,t]);const V=C.useCallback(x=>{if(c(x),d){const F=l.find(L=>L.id===x);F&&d(F)}},[c,d,l]),oe=C.useCallback(()=>{i&&t()},[i,t]);if(!o)return null;const J=()=>{if(!u)return r.jsx(re,{models:w,selectedModel:i,onModelSelect:V,sortConfig:z,onSort:B});const x=w.filter(L=>L.costTier==="free"),F=w.filter(L=>L.costTier!=="free");return r.jsxs("div",{className:"categorized-models",children:[x.length>0&&r.jsxs("div",{className:"model-category",children:[r.jsxs("h3",{style:{fontSize:"1rem",fontWeight:"600",margin:"0.75rem 0 0.5rem",color:"#10b981",display:"flex",alignItems:"center",gap:"0.5rem"},children:["Free Models (",x.length,")"]}),r.jsx(re,{models:x,selectedModel:i,onModelSelect:V,sortConfig:z,onSort:B})]}),F.length>0&&r.jsxs("div",{className:"model-category",children:[r.jsxs("h3",{style:{fontSize:"1rem",fontWeight:"600",margin:"1rem 0 0.5rem",color:"var(--or-text)",display:"flex",alignItems:"center",gap:"0.5rem"},children:["Paid Models (",F.length,")"]}),r.jsx(re,{models:F,selectedModel:i,onModelSelect:V,sortConfig:z,onSort:B})]})]})};return r.jsx("div",{className:`openrouter-modal ${v==="dark"?"dark":""} ${b||""}`,children:r.jsx("div",{className:"modal-overlay",onClick:t,children:r.jsxs("div",{className:"modal-content",onClick:x=>x.stopPropagation(),style:{maxHeight:a,...g&&{maxWidth:g,width:g}},children:[r.jsxs("div",{className:"modal-header",children:[r.jsxs("h2",{className:"modal-title",children:["Choose OpenRouter LLM Model",!M&&!P&&l.length>0&&r.jsxs("span",{style:{fontWeight:"400",fontSize:"0.875rem",color:"var(--or-text-secondary)",marginLeft:"0.5rem"},children:["(",l.length," models",p.length>0&&`: ${p.length} free, ${R.length} paid`,")"]})]}),r.jsx("button",{onClick:t,className:"modal-close-button",children:r.jsx(Yr,{style:{width:"1.25rem",height:"1.25rem"}})})]}),r.jsx("div",{className:"modal-body",children:M?r.jsx(Xe,{message:"Loading available models..."}):P?r.jsx(Ze,{error:P,onRetry:S}):r.jsxs(r.Fragment,{children:[r.jsx(Je,{filterState:$,onFilterChange:te,onClearFilters:ne,availableProviders:ie,filterStats:G}),J()]})}),w.some(x=>x.reasoning)&&r.jsx("div",{style:{padding:"0.75rem 1.5rem",borderTop:"1px solid var(--or-border)",backgroundColor:"#fef3c7",borderLeft:"4px solid #f59e0b",fontSize:"0.75rem",color:"#92400e",lineHeight:"1.4"},children:r.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"0.5rem"},children:[r.jsx("span",{style:{fontSize:"0.875rem"},children:"⚠️"}),r.jsxs("div",{children:[r.jsx("strong",{children:"Reasoning Detection Notice:"})," Reasoning capabilities are detected using pattern matching for known models (o1, DeepSeek R1, Gemini Thinking, etc.). This may not detect all reasoning models or may change as new models are released. OpenRouter doesn't provide an official reasoning capability field."]})]})}),r.jsxs("div",{style:{padding:"1rem 1.5rem",borderTop:w.some(x=>x.reasoning)?"none":"1px solid var(--or-border)",backgroundColor:"rgba(0, 0, 0, 0.02)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[r.jsx("div",{children:i&&(()=>{const x=l.find(F=>F.id===i);return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.25rem"},children:[r.jsxs("div",{style:{fontSize:"0.875rem",color:"var(--or-text-secondary)"},children:["Selected: ",r.jsx("span",{style:{fontWeight:"500",color:"var(--or-text)",fontFamily:"monospace",fontSize:"0.8rem"},children:i})]}),x&&r.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[r.jsxs("span",{style:{fontSize:"0.75rem",color:"var(--or-text-secondary)"},children:[x.name," • ",x.provider]}),x.reasoning&&r.jsx("span",{style:{padding:"0.125rem 0.375rem",fontSize:"0.7rem",backgroundColor:"#8b5cf6",color:"white",borderRadius:"0.25rem",fontWeight:"500"},children:"🧠 Reasoning"}),x.multimodal&&r.jsx("span",{style:{padding:"0.125rem 0.375rem",fontSize:"0.7rem",backgroundColor:"#10b981",color:"white",borderRadius:"0.25rem",fontWeight:"500"},children:"👁 Vision"}),x.streamCancel&&r.jsx("span",{style:{padding:"0.125rem 0.375rem",fontSize:"0.7rem",backgroundColor:"#f59e0b",color:"white",borderRadius:"0.25rem",fontWeight:"500"},children:"⏹️ Stream Cancel"})]})]})})()}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[r.jsx("button",{onClick:t,style:{padding:"0.5rem 1rem",color:"var(--or-text)",backgroundColor:"var(--or-background)",border:"1px solid var(--or-border)",borderRadius:"0.5rem",cursor:"pointer",fontSize:"0.875rem"},children:"Cancel"}),r.jsx("button",{onClick:oe,disabled:!i,style:{padding:"0.5rem 1.5rem",borderRadius:"0.5rem",fontWeight:"500",fontSize:"0.875rem",border:"none",cursor:i?"pointer":"not-allowed",backgroundColor:i?"var(--or-primary-color)":"#d1d5db",color:i?"white":"#6b7280"},children:"Select Model"})]})]})]})})})}exports.ApiClient=Ve;exports.EmptyState=Zr;exports.ErrorState=Ze;exports.FilterBar=Je;exports.LoadingState=Xe;exports.ModelChooserModal=Qr;exports.ModelTable=re;exports.debounce=Jr;exports.formatContextLength=He;exports.formatPrice=me;exports.getCostTierColor=Gr;exports.getCostTierLabel=Ke;exports.truncateText=Ge;exports.useFiltering=qe;exports.useModelData=Ye;