1import{r as c,j as e}from"./react-dIJTUJVE.js";import{u as W,a9 as X,U as Y,aQ as H,aR as P,aa as K,aS as Z,aT as ee,aU as D}from"./index-CO0FZyR6.js";import{L as T,B as N,P as V,E as te,X as se,e as ne}from"./App-gXf3oHlu.js";import{S as ae,a as re,b as le,c as oe,d as ie}from"./select-Br0wQ4WL.js";import{S as ce}from"./save-CuOlixF5.js";import{S as de}from"./star-B_Xbyhq1.js";import{V as xe}from"./volume-2-B3UySZgt.js";import"./firebase-C7EYTMAQ.js";import"./chevron-up-dmA6KFEN.js";import"./isElementDisabled-CwHw_lZC.js";import"./resolveAriaLabelledBy-CZd1bu7B.js";import"./clamp-DyuOe9kr.js";const L="https://app.trooper.so",ue="https://models.dev/api.json",j=["anthropic","openai","google","deepseek","mistral","xai","perplexity"],me=["text","image","audio","video","search"],pe={anthropic:"bg-orange-50 text-orange-600 border-orange-200",openai:"bg-emerald-50 text-emerald-600 border-emerald-200",google:"bg-blue-50 text-blue-600 border-blue-200",deepseek:"bg-sky-50 text-sky-600 border-sky-200",mistral:"bg-amber-50 text-amber-600 border-amber-200",xai:"bg-stone-50 text-neutral-600 border-neutral-200",perplexity:"bg-teal-50 text-teal-600 border-teal-200"},he={text:D,image:ee,audio:xe,search:P,video:Z};function fe(){return{id:"",name:"",provider:"anthropic",category:["text"],intelligence:7,speed:7,recommended:!1}}function ge(d,x){const u=Array.isArray(d)?d:d?[d]:[];return u.includes(x)?u.filter(a=>a!==x):[...u,x]}function U(d){return Array.isArray(d)?d:d?[d]:[]}function be(d,x){var f;const u=x.modalities||{},a=u.input||[],y=u.output||[],h=new Set;(y.includes("text")||a.includes("text"))&&h.add("text"),(y.includes("image")||a.includes("image"))&&h.add("image"),(y.includes("audio")||a.includes("audio"))&&h.add("audio"),(y.includes("video")||a.includes("video"))&&h.add("video"),h.size===0&&h.add("text");const S=x.cost||{};return{id:`${d}/${x.id}`,name:x.name||x.id,provider:d,category:[...h],contextWindow:((f=x.limit)==null?void 0:f.context)||null,intelligence:null,speed:null,capabilities:[...x.tool_call?["tools"]:[],...x.reasoning?["reasoning"]:[],...a.includes("image")?["vision"]:[]],pricing:{input:S.input||0,output:S.output||0},recommended:!1,tags:[]}}function je({existingIds:d,onImport:x,onClose:u}){const[a,y]=c.useState(null),[h,S]=c.useState(!0),[f,C]=c.useState("anthropic"),[m,A]=c.useState(""),[w,$]=c.useState(new Set);c.useEffect(()=>{(async()=>{try{const r=await(await fetch(ue)).json();y(r);const o=j.find(p=>{var b;return((b=r[p])==null?void 0:b.models)&&Object.keys(r[p].models).length>0});o&&C(o)}catch(s){console.error("Failed to fetch models.dev:",s)}finally{S(!1)}})()},[]);const g=a==null?void 0:a[f],I=(g!=null&&g.models?Object.values(g.models):[]).filter(s=>{if(!m)return!0;const r=m.toLowerCase();return(s.name||"").toLowerCase().includes(r)||(s.id||"").toLowerCase().includes(r)});function z(s){$(r=>{const o=new Set(r);return o.has(s)?o.delete(s):o.add(s),o})}function O(){const s=I.filter(r=>w.has(r.id)).map(r=>be(f,r));x(s)}const R=a?Object.keys(a).filter(s=>{var r;return((r=a[s])==null?void 0:r.models)&&Object.keys(a[s].models).length>0}).sort((s,r)=>{var p,b;const o=j.indexOf(s)-j.indexOf(r);return j.includes(s)&&!j.includes(r)?-1:!j.includes(s)&&j.includes(r)?1:j.includes(s)&&j.includes(r)?o:(((p=a[s])==null?void 0:p.name)||s).localeCompare(((b=a[r])==null?void 0:b.name)||r)}):j;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/40 p-0 sm:p-4 overscroll-contain",children:e.jsxs("div",{className:"flex max-h-[85dvh] sm:max-h-[90vh] w-full sm:max-w-4xl flex-col overflow-hidden rounded-t-2xl sm:rounded-2xl bg-white shadow-2xl",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-neutral-100 px-4 py-4 sm:px-5 min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 sm:gap-3",children:[e.jsx("h2",{className:"text-lg font-bold text-neutral-900",children:"Import from models.dev"}),e.jsx("a",{href:"https://models.dev",target:"_blank",rel:"noopener noreferrer",className:"text-neutral-400 hover:text-neutral-600",children:e.jsx(te,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex flex-shrink-0 flex-wrap items-center gap-2",children:[w.size>0&&e.jsxs(N,{onClick:O,size:"sm",children:[e.jsx(V,{className:"w-3.5 h-3.5"})," Import ",w.size," model",w.size>1?"s":""]}),e.jsx(N,{variant:"ghost",size:"icon",onClick:u,className:"text-neutral-400 hover:text-neutral-600",children:e.jsx(se,{className:"w-4 h-4"})})]})]}),h?e.jsx("div",{className:"flex-1 flex items-center justify-center py-16",children:e.jsx(T,{className:"w-5 h-5 text-neutral-400 animate-spin"})}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col md:flex-row",children:[e.jsx("div",{className:"flex max-h-32 w-full flex-shrink-0 flex-row gap-0 overflow-x-auto overflow-y-hidden border-b border-neutral-100 py-2 md:max-h-none md:w-44 md:flex-col md:overflow-y-auto md:overflow-x-hidden md:border-b-0 md:border-r",children:R.map(s=>{var o,p;const r=(o=a==null?void 0:a[s])!=null&&o.models?Object.keys(a[s].models).length:0;return e.jsxs("button",{onClick:()=>{C(s),$(new Set),A("")},className:`shrink-0 min-w-[9rem] text-left px-4 py-2 text-sm flex items-center justify-between transition-colors md:w-full md:min-w-0 ${f===s?"bg-stone-100 font-medium text-neutral-900":"text-neutral-500 hover:bg-stone-50"}`,children:[e.jsx("span",{className:"capitalize",children:((p=a==null?void 0:a[s])==null?void 0:p.name)||s}),e.jsx("span",{className:"text-[10px] text-neutral-400",children:r})]},s)})}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx("div",{className:"px-4 py-3 border-b border-neutral-100",children:e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-neutral-400"}),e.jsx("input",{value:m,onChange:s=>A(s.target.value),placeholder:`Search ${(g==null?void 0:g.name)||f} models...`,className:"w-full pl-9 pr-4 py-2 text-sm bg-stone-50 border border-neutral-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[I.map(s=>{var _;const r=`${f}/${s.id}`,o=d.has(r),p=w.has(s.id),b=s.cost||{};return e.jsxs("div",{onClick:()=>!o&&z(s.id),className:`flex items-center gap-3 px-4 py-2.5 border-b border-neutral-50 cursor-pointer transition-colors ${o?"opacity-40 cursor-default":p?"bg-blue-50/50":"hover:bg-stone-50/50"}`,children:[e.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center flex-shrink-0 ${o?"bg-stone-200 border-neutral-300":p?"bg-blue-500 border-blue-500":"border-neutral-300"}`,children:(p||o)&&e.jsx(ne,{className:"w-3 h-3 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-neutral-900 truncate",children:s.name||s.id}),o&&e.jsx("span",{className:"text-[9px] text-neutral-400 bg-stone-100 px-1.5 py-0.5 rounded",children:"already added"})]}),e.jsx("span",{className:"text-[11px] font-mono text-neutral-400",children:s.id})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0 text-[11px] text-neutral-500",children:[((_=s.limit)==null?void 0:_.context)&&e.jsxs("span",{children:[(s.limit.context/1e3).toFixed(0),"k ctx"]}),b.input!=null&&e.jsxs("span",{children:["$",b.input,"/",b.output]}
1),s.reasoning&&e.jsx("span",{className:"px-1.5 py-0.5 bg-violet-50 text-violet-600 rounded text-[9px] font-medium",children:"reasoning"}),s.tool_call&&e.jsx("span",{className:"px-1.5 py-0.5 bg-emerald-50 text-emerald-600 rounded text-[9px] font-medium",children:"tools"})]})]},s.id)}),I.length===0&&e.jsx("div",{className:"px-4 py-12 text-center text-sm text-neutral-400",children:"No models found"})]})]})]})]})})}function ze(){const{getIdToken:d,isPlatformAdmin:x}=W(),[u,a]=c.useState([]),[y,h]=c.useState(!0),[S,f]=c.useState(!1),[C,m]=c.useState(null),[A,w]=c.useState(null),[$,g]=c.useState(!1),[M,I]=c.useState(""),[z,O]=c.useState(null),[R,s]=c.useState(!1),r=c.useRef(null),o=c.useCallback(async()=>({Authorization:`Bearer ${await d()}`,"Content-Type":"application/json"}),[d]);c.useEffect(()=>{(async()=>{h(!0);try{const t=await o(),n=await fetch(`${L}/api/platform/model-catalog`,{headers:t});if(n.ok){const i=await n.json();a(i.models||[])}}catch(t){console.error("Failed to load catalog:",t)}finally{h(!1)}})()},[]);const p=new Set(u.map(t=>t.id));async function b(){f(!0),m(null);try{const t=await o(),n=await fetch(`${L}/api/platform/model-catalog`,{method:"PUT",headers:t,body:JSON.stringify({version:1,models:u})}),i=await n.json();m(n.ok?{ok:!0,text:`Saved ${i.count} models`}:{ok:!1,text:i.error})}catch(t){m({ok:!1,text:t.message})}finally{f(!1),setTimeout(()=>m(null),4e3)}}function _(){const t=new Blob([JSON.stringify({version:1,models:u},null,2)],{type:"application/json"}),n=URL.createObjectURL(t),i=document.createElement("a");i.href=n,i.download="model-catalog.json",i.click(),URL.revokeObjectURL(n)}function B(t){var E;const n=(E=t.target.files)==null?void 0:E[0];if(!n)return;const i=new FileReader;i.onload=l=>{try{const v=JSON.parse(l.target.result),J=v.models||v;if(!Array.isArray(J))throw new Error("Expected { models: [...] } or an array");a(J),m({ok:!0,text:`Imported ${J.length} models (not saved yet)`}),setTimeout(()=>m(null),4e3)}catch(v){m({ok:!1,text:`Import failed: ${v.message}`}),setTimeout(()=>m(null),4e3)}},i.readAsText(n),t.target.value=""}function F(){I(JSON.stringify(u,null,2)),O(null),g(!0)}function G(){try{const t=JSON.parse(M),n=Array.isArray(t)?t:t.models;if(!Array.isArray(n))throw new Error("Expected array or { models: [...] }");a(n),g(!1),m({ok:!0,text:`Applied ${n.length} models (not saved yet)`}),setTimeout(()=>m(null),4e3)}catch(t){O(t.message)}}function Q(t){const n=t.filter(i=>!p.has(i.id));n.length>0&&(a(i=>[...i,...n]),m({ok:!0,text:`Added ${n.length} model${n.length>1?"s":""} (not saved yet)`}),setTimeout(()=>m(null),4e3)),s(!1)}function k(t,n,i){a(E=>E.map((l,v)=>v===t?{...l,[n]:i}:l))}const q=t=>he[t]||D;return x?y?e.jsx("div",{className:"h-dvh flex items-center justify-center bg-[#f5f4ef]",children:e.jsx(T,{className:"w-6 h-6 text-neutral-400 animate-spin"})}):$?e.jsxs("div",{className:"h-dvh bg-[#f5f4ef] flex flex-col",children:[e.jsx("div",{className:"fixed inset-0 z-0",style:{backgroundImage:"linear-gradient(rgba(0,0,0,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(0,0,0,0.05) 1px, transparent 1px)",backgroundSize:"48px 48px"}}),e.jsxs("div",{className:"relative z-10 max-w-5xl mx-auto w-full flex-1 flex flex-col px-4 py-6 sm:px-6 sm:py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-bold text-neutral-900",children:"Edit JSON"}),e.jsxs("div",{className:"flex items-center gap-2",children:[z&&e.jsx("span",{className:"text-xs text-green-500",children:z}),e.jsx(N,{variant:"ghost",onClick:()=>g(!1),children:"Cancel"}),e.jsx(N,{onClick:G,children:"Apply"})]})]}),e.jsx("textarea",{value:M,onChange:t=>{I(t.target.value),O(null)},spellCheck:!1,className:"flex-1 w-full p-4 text-sm font-mono bg-white border border-neutral-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500/20 resize-none"})]})]}):e.jsxs("div",{className:"min-h-dvh bg-[#f5f4ef]",children:[e.jsx("div",{className:"fixed inset-0 z-0",style:{backgroundImage:"linear-gradient(rgba(0,0,0,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(0,0,0,0.05) 1px, transparent 1px)",backgroundSize:"48px 48px"}}),e.jsx("input",{type:"file",ref:r,accept:".json",onChange:B,className:"hidden"}),e.jsxs("div",{className:"relative z-10 max-w-5xl mx-auto px-6 py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-neutral-900",children:"Model Catalog"}),e.jsxs("p",{className:"text-xs text-neutral-400 mt-0.5",children:[u.length," models"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[C&&e.jsx("span",{className:`text-xs font-medium mr-2 ${C.ok?"text-emerald-600":"text-green-500"}`,children:C.text}),e.jsx(N,{variant:"ghost",size:"icon",onClick:_,title:"Download JSON",className:"text-neutral-400 hover:text-neutral-600 hover:bg-white",children:e.jsx(X,{className:"w-4 h-4"})}),e.jsx(N,{variant:"ghost",size:"icon",onClick:()=>{var t;return(t=r.current)==null?void 0:t.click()},title:"Upload JSON",className:"text-neutral-400 hover:text-neutral-600 hover:bg-white",children:e.jsx(Y,{className:"w-4 h-4"})}),e.jsx(N,{variant:"ghost",size:"icon",onClick:F,title:"Edit as JSON",className:"text-neutral-400 hover:text-neutral-600 hover:bg-white",children:e.jsx(H,{className:"w-4 h-4"})}),e.jsx("div",{className:"w-px h-5 bg-stone-200 mx-1"}),e.jsxs(N,{variant:"outline",onClick:()=>s(!0),children:[e.jsx(P,{className:"w-3.5 h-3.5"})," models.dev"]}),e.jsxs(N,{variant:"outline",onClick:()=>{a(t=>[fe(),...t]),w(0)},children:[e.jsx(V,{className:"w-3.5 h-3.5"})," Add"]}),e.jsxs(N,{onClick:b,disabled:S,children:[S?e.jsx(T,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ce,{className:"w-3.5 h-3.5"}),"Save"]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-neutral-200 overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_2fr_
1100px_80px_60px_60px_36px] gap-2 px-4 py-2.5 text-[10px] font-semibold text-neutral-400 uppercase tracking-wider border-b border-neutral-100 bg-stone-50/50",children:[e.jsx("span",{children:"Model ID"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Provider"}),e.jsx("span",{children:"Type"}),e.jsx("span",{className:"text-center",children:"IQ"}),e.jsx("span",{className:"text-center",children:"Speed"}),e.jsx("span",{className:"text-center",children:"â
"})]}),u.length===0&&e.jsx("div",{className:"px-4 py-12 text-center text-sm text-neutral-400",children:"No models. Add one, upload JSON, or import from models.dev."}),u.map((t,n)=>{const i=A===n,E=pe[t.provider]||"bg-stone-50 text-neutral-500 border-neutral-200";return e.jsxs("div",{className:`border-b border-neutral-50 last:border-0 ${i?"bg-blue-50/30":"hover:bg-stone-50/50"}`,children:[e.jsxs("div",{className:"grid grid-cols-[1fr_2fr_100px_80px_60px_60px_36px] gap-2 px-4 py-2.5 items-center cursor-pointer",onClick:()=>w(i?null:n),children:[e.jsx("span",{className:"text-xs font-mono text-neutral-600 truncate",children:t.id||"â"}),e.jsx("span",{className:"text-sm font-medium text-neutral-900 truncate",children:t.name||"â"}),e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full border w-fit ${E}`,children:t.provider}),e.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:U(t.category).map(l=>{const v=q(l);return e.jsx(v,{className:"w-3 h-3 text-neutral-400",title:l},l)})}),e.jsx("span",{className:"text-xs text-neutral-600 text-center",children:t.intelligence??"â"}),e.jsx("span",{className:"text-xs text-neutral-600 text-center",children:t.speed??"â"}),e.jsx("span",{className:"text-center",children:t.recommended?e.jsx(de,{className:"w-3 h-3 text-amber-400 fill-amber-400 inline"}):""})]}),i&&e.jsxs("div",{className:"grid grid-cols-1 gap-2 px-4 pb-3 pt-1 sm:grid-cols-4",children:[e.jsx("input",{value:t.id,onChange:l=>k(n,"id",l.target.value),placeholder:"anthropic/claude-sonnet-4-6",className:"col-span-1 px-2.5 py-1.5 font-mono text-xs border border-neutral-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500/20 sm:col-span-2"}),e.jsx("input",{value:t.name,onChange:l=>k(n,"name",l.target.value),placeholder:"Claude Sonnet 4.6",className:"col-span-1 px-2.5 py-1.5 text-xs border border-neutral-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500/20 sm:col-span-2"}),e.jsxs(ae,{value:t.provider,onValueChange:l=>k(n,"provider",l),children:[e.jsx(re,{className:"px-2 py-1.5 text-xs border border-neutral-200 rounded-lg bg-white focus:outline-none focus:ring-2 focus:ring-blue-500/20 h-auto",children:e.jsx(le,{})}),e.jsx(oe,{children:j.map(l=>e.jsx(ie,{value:l,children:l},l))})]}),e.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:me.map(l=>{const v=U(t.category).includes(l);return e.jsx("button",{onClick:()=>k(n,"category",ge(t.category,l)),className:`px-2 py-1 text-[10px] font-medium rounded-md border transition-colors ${v?"bg-blue-50 text-blue-600 border-blue-200":"bg-white text-neutral-400 border-neutral-200 hover:border-neutral-300"}`,children:l},l)})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-neutral-400 w-6",children:"IQ"}),e.jsx("input",{type:"number",min:1,max:10,value:t.intelligence||"",onChange:l=>k(n,"intelligence",parseInt(l.target.value)||null),className:"w-full px-2 py-1.5 text-xs font-mono border border-neutral-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] text-neutral-400 w-10",children:"Speed"}),e.jsx("input",{type:"number",min:1,max:10,value:t.speed||"",onChange:l=>k(n,"speed",parseInt(l.target.value)||null),className:"w-full px-2 py-1.5 text-xs font-mono border border-neutral-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),e.jsxs("label",{className:"col-span-1 mt-1 flex items-center gap-2 sm:col-span-4",children:[e.jsx("input",{type:"checkbox",checked:!!t.recommended,onChange:l=>k(n,"recommended",l.target.checked),className:"w-3.5 h-3.5 rounded border-neutral-300 text-blue-600"}),e.jsx("span",{className:"text-xs text-neutral-500",children:"Recommended"})]})]})]},n)})]})]}),R&&e.jsx(je,{existingIds:p,onImport:Q,onClose:()=>s(!1)})]}):e.jsx("div",{className:"h-dvh flex items-center justify-center bg-[#f5f4ef]",children:e.jsx("p",{className:"text-sm text-neutral-400",children:"Not authorized"})})}
1export{ze as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.