%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/
Upload File :
Create Path :
Current File : /home2/rezakur1/ai.rezakurnia.com/assets/AdminModelsPage-D-vSusIH.js

import{r as a,c as S,j as e}from"./index-_MR6QBUm.js";import{B as j}from"./Button-BRUb7BtQ.js";import{C as B,d as F,e as R,a as A,n as f}from"./format-DuRu6B7q.js";import{B as x}from"./Badge-MEsxA8Zk.js";import{M as D}from"./Modal-DfWk_p7K.js";import{I as N}from"./Input-DmEL3T9J.js";import"./index-B2yPAbM9.js";function L(){const[o,r]=a.useState([]),[m,p]=a.useState(!0),[c,u]=a.useState(null),n=a.useCallback(async()=>{try{const s=await S("/admin/models");r(s.models),u(null)}catch(s){u(s instanceof Error?s.message:"Gagal memuat model")}finally{p(!1)}},[]);a.useEffect(()=>{n()},[n]);const i=a.useCallback(async(s,l)=>{const g=await S(`/admin/models/${encodeURIComponent(s)}`,{method:"PATCH",body:l});return await n(),g.model},[n]);return{models:o,loading:m,error:c,patch:i,refresh:n}}function y(o){const r=Number(o);return!Number.isFinite(r)||r===0?"0":`${r.toLocaleString("id-ID")}`}function T(){const{models:o,loading:r,error:m,patch:p}=L(),[c,u]=a.useState(""),[n,i]=a.useState(null),[s,l]=a.useState({inp:"",out:"",cache:""}),[g,_]=a.useState(!1),[w,h]=a.useState(null),[M,v]=a.useState(null),C=o.filter(t=>!c.trim()||t.model.toLowerCase().includes(c.trim().toLowerCase())),E=t=>{i(t),l({inp:f(t.input_price_per_1m),out:f(t.output_price_per_1m),cache:f(t.cache_price_per_1m)}),h(null)},I=async()=>{const t=Number(s.inp),d=Number(s.out),b=Number(s.cache);if(!Number.isFinite(t)||t<0||!Number.isFinite(d)||d<0||!Number.isFinite(b)||b<0){h("Harga harus angka ≥ 0.");return}if(n){_(!0),h(null);try{await p(n.model,{input_price_per_1m:String(t),output_price_per_1m:String(d),cache_price_per_1m:String(b)}),i(null)}catch(k){h(k instanceof Error?k.message:"Gagal menyimpan harga")}finally{_(!1)}}},H=async t=>{v(t.model);try{await p(t.model,{is_hidden:Number(t.is_hidden)!==1})}catch{}finally{v(null)}};return e.jsxs(e.Fragment,{children:[e.jsxs(B,{children:[e.jsx(F,{title:"Katalog Model",subtitle:"Kelola harga & visibilitas model (status otomatis dari health check)",action:e.jsx("input",{type:"search",placeholder:"Cari model…",value:c,onChange:t=>u(t.target.value),className:"input-solid w-56"})}),e.jsxs(R,{className:"p-0",children:[m&&e.jsxs("div",{className:"p-5 text-sm text-red-300",children:["Gagal memuat: ",m]}),r?e.jsx("div",{className:"space-y-3 p-5",children:[...Array(5)].map((t,d)=>e.jsx("div",{className:"h-12 animate-pulse rounded-xl bg-white/[0.02]"},d))}):C.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-slate-500",children:"Tidak ada model yang cocok."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[980px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:"Model"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Input /1M"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Output /1M"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Cache /1M"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Konteks"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Uptime"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Hidden"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Aksi"})]})}),e.jsx("tbody",{children:C.map(t=>e.jsxs("tr",{className:`border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02] ${Number(t.is_hidden)===1?"opacity-60":""}`,children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"font-mono text-sm font-medium text-slate-100",children:t.model}),!t.in_upstream&&e.jsx(x,{tone:"warning",className:"!text-[10px]",children:"tidak di upstream"})]})}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-300",children:y(t.input_price_per_1m)}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-300",children:y(t.output_price_per_1m)}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:y(t.cache_price_per_1m)}),e.jsx("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:t.context_window?A(t.context_window):"—"}),e.jsxs("td",{className:"px-4 py-3.5 text-right tabular-nums text-slate-400",children:[Number(t.uptime).toLocaleString("id-ID"),"%"]}),e.jsx("td",{className:"px-4 py-3.5",children:t.status==="maintenance"?e.jsx(x,{tone:"danger",children:"Maintenance"}):t.status==="active"?e.jsx(x,{tone:"success",children:"Aktif"}):e.jsx(x,{tone:"default",children:t.status})}),e.jsx("td",{className:"px-4 py-3.5",children:e.jsx("button",{type:"button",role:"switch","aria-checked":Number(t.is_hidden)===1,disabled:M===t.model,onClick:()=>H(t),className:`relative h-6 w-11 rounded-full transition-colors disabled:opacity-40 ${Number(t.is_hidden)===1?"bg-red-500/70":"bg-white/[0.08]"}`,children:e.jsx("span",{className:`absolute top-0.5 h-5 w-5 rounded-full bg-white transition-all ${Number(t.is_hidden)===1?"left-[22px]":"left-0.5"}`})})}),e.jsx("td",{className:"px-5 py-3.5 text-right",children:e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>E(t),children:"Edit Harga"})})]},t.model))})]})})]})]}),e.jsx(D,{open:!!n,onClose:()=>i(null),title:"Edit Harga Model",subtitle:n?n.model:"",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(N,{label:"Input (IDR / 1M token)",type:"number",min:0,step:100,value:s.inp,onChange:t=>l({...s,inp:t.target.value})}),e.jsx(N,{label:"Output (IDR / 1M token)",type:"number",min:0,step:100,value:s.out,onChange:t=>l({...s,out:t.target.value})}),e.jsx(N,{label:"Cache (IDR / 1M token)",type:"number",min:0,step:100,value:s.cache,onChange:t=>l({...s,cache:t.target.value})}),w&&e.jsx("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-sm text-red-300",children:w}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx(j,{variant:"ghost",onClick:()=>i(null),children:"Batal"}),e.jsx(j,{isLoading:g,onClick:I,children:"Simpan Harga"})]})]})})]})}export{T as default};

Zerion Mini Shell 1.0