%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/KeysPage-BMOvfwGP.js

import{r as s,c as w,j as e}from"./index-CnB9nKbp.js";import{B as i}from"./Button-RaC0qoA7.js";import{C as $,d as Y,e as F,c as O,g as X}from"./format-B8Won_Te.js";import{B as T}from"./Badge-CXRzVGa3.js";import{I as q}from"./Input-B7FggKMg.js";import{M as C}from"./Modal-BQ95Cl32.js";import"./index-BjE9Ehy3.js";const R=10;function ee(){const[m,j]=s.useState([]),[c,u]=s.useState(0),[o,p]=s.useState(1),[x,y]=s.useState(!0),[S,K]=s.useState(null),[B,h]=s.useState(0),r=s.useCallback(()=>h(l=>l+1),[]);s.useEffect(()=>{let l=!1;return y(!0),w(`/me/keys?page=${o}&limit=${R}`).then(n=>{l||(j(n.keys),u(n.total))}).catch(n=>{l||K(n.message)}).finally(()=>{l||y(!1)}),()=>{l=!0}},[B,o]);const k=s.useCallback(async l=>{const n=await w("/me/keys",{method:"POST",body:{name:l}});return r(),n},[r]),E=s.useCallback(async l=>{await w(`/me/keys/${l}`,{method:"DELETE"}),r()},[r]),f=s.useCallback(async l=>{await w(`/me/keys/${l}/permanent`,{method:"DELETE"}),r()},[r]),g=Math.max(1,Math.ceil(c/R));return{keys:m,total:c,page:o,totalPages:g,setPage:p,loading:x,error:S,refresh:r,createKey:k,revokeKey:E,removePermanent:f}}function de(){const{keys:m,total:j,page:c,totalPages:u,setPage:o,loading:p,error:x,createKey:y,revokeKey:S,removePermanent:K}=ee(),[B,h]=s.useState(!1),[r,k]=s.useState(""),[E,f]=s.useState(!1),[g,l]=s.useState(null),[n,A]=s.useState(null),[U,P]=s.useState(!1),[_,b]=s.useState(null),[W,H]=s.useState(!1),[t,N]=s.useState(null),[D,I]=s.useState(""),[L,M]=s.useState(!1),[G,v]=s.useState(null),Z=a=>{N(a),I(""),v(null)},J=async()=>{if(t){M(!0),v(null);try{await K(t.id),N(null),I(""),m.length===1&&c>1&&o(c-1)}catch(a){v(a instanceof Error?a.message:"Gagal menghapus key"),M(!1)}}},z=async()=>{const a=r.trim();if(!a){l("Nama key wajib diisi.");return}f(!0),l(null);try{const d=await y(a);h(!1),k(""),A(d),P(!1)}catch(d){l(d instanceof Error?d.message:"Gagal membuat key")}finally{f(!1)}},Q=async()=>{if(n!=null&&n.key)try{await navigator.clipboard.writeText(n.key),P(!0),setTimeout(()=>P(!1),2e3)}catch{}},V=async()=>{if(_!=null){H(!0);try{await S(_),b(null)}catch(a){alert(a instanceof Error?a.message:"Gagal revoke key")}finally{H(!1)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight text-white sm:text-2xl",children:"API Keys"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Buat dan kelola kunci API untuk mengakses gateway."})]}),e.jsxs(i,{onClick:()=>h(!0),children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4.5v15m7.5-7.5h-15"})}),"Buat Key Baru"]})]}),e.jsxs($,{children:[e.jsx(Y,{title:"Contoh Pemakaian",subtitle:"Format header Authorization yang benar untuk memanggil gateway"}),e.jsx(F,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs leading-relaxed text-slate-500",children:["API key berbeda dari sesi login. Gunakan header"," ",e.jsx("code",{className:"rounded bg-white/[0.06] px-1.5 py-0.5 font-mono text-[11px] text-brand-200",children:"Authorization: Bearer kd_live_..."})," ","di setiap request. Key lengkap hanya tampil sekali saat dibuat."]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-ink-950/80 px-4 py-3 font-mono text-[11px] leading-relaxed text-slate-300",children:[e.jsx("p",{className:"text-slate-500",children:"# Ganti BASE_URL jika bukan http://localhost:5173"}),e.jsx("p",{children:"curl http://localhost:5173/v1/chat/completions \\"}),e.jsxs("p",{children:["  ",'-H "Content-Type: application/json" \\']}),e.jsxs("p",{children:["  ",'-H "Authorization: Bearer kd_live_<KEY_LENGKAP>" \\']}),e.jsx("p",{children:`  -d '{"model":"mercury-3","messages":[{"role":"user","content":"Halo"}]}'`})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-1 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["• ",e.jsx("span",{className:"text-red-300",children:"401"})," → key salah / nonaktif / format salah"]}),e.jsxs("span",{children:["• ",e.jsx("span",{className:"text-amber-300",children:"402"})," → saldo 0 & tanpa paket aktif"]}),e.jsxs("span",{children:["• ",e.jsx("span",{className:"text-emerald-300",children:"200"})," → sukses"]})]})]})})]}),e.jsxs($,{children:[e.jsx(Y,{title:"Daftar API Key",subtitle:"Key lengkap hanya terlihat satu kali saat dibuat"}),e.jsxs(F,{className:"p-0",children:[x&&e.jsxs("div",{className:"p-5 text-sm text-red-300",children:["Gagal memuat key: ",x]}),p&&!x&&e.jsx("div",{className:"space-y-3 p-5",children:[...Array(3)].map((a,d)=>e.jsx("div",{className:"h-16 animate-pulse rounded-xl bg-white/[0.02]"},d))}),!p&&!x&&m.length===0&&e.jsxs("div",{className:"px-5 py-12 text-center",children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Belum ada API key."}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Buat key pertama Anda untuk mulai memanggil model AI."})]}),!p&&!x&&m.length>0&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[680px] 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:"Nama"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Key Prefix"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Saldo Kredit"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Dibuat"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Aksi"})]})}),e.jsx("tbody",{children:m.map(a=>{const d=a.is_active===1;return e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-5 py-3.5",children:e.jsx("p",{className:"font-medium text-white",children:a.name})}),e.jsx("td",{className:"px-4 py-3.5",children:e.jsx("span",{className:"font-mono text-xs text-slate-500",children:a.key_prefix})}),e.jsx("td",{className:"px-4 py-3.5",children:d?e.jsxs(T,{tone:"success",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-400"}),"Aktif"]}):e.jsxs(T,{tone:"danger",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-red-400"}),"Nonaktif"]})}),e.jsx("td",{className:"px-4 py-3.5 text-right font-medium tabular-nums text-slate-300",children:O(a.credit_balance)}),e.jsx("td",{className:"px-4 py-3.5 text-xs tabular-nums text-slate-500",children:X(a.created_at)}),e.jsx("td",{className:"px-5 py-3.5 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[d?e.jsx(i,{variant:"danger",size:"sm",onClick:()=>b(a.id),children:"Revoke"}):e.jsx("span",{className:"text-xs text-slate-600",children:"—"}),e.jsx(i,{variant:"subtle",size:"sm",title:"Hapus key permanen dari akun",onClick:()=>Z(a),className:"text-red-400 hover:bg-red-500/10 hover:text-red-300",children:"Hapus"})]})})]},a.id)})})]})})]})]}),j>R&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs text-slate-500",children:["Total ",j," key · Halaman ",c," dari ",u]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(i,{variant:"ghost",size:"sm",disabled:c<=1,onClick:()=>o(a=>Math.max(1,a-1)),children:"← Sebelumnya"}),e.jsx(i,{variant:"ghost",size:"sm",disabled:c>=u,onClick:()=>o(a=>Math.min(u,a+1)),children:"Berikutnya →"})]})]}),e.jsx(C,{open:B,onClose:()=>h(!1),title:"Buat API Key Baru",subtitle:"Beri nama yang jelas, mis. 'App Mobile' atau 'Server Prod'",children:e.jsxs("div",{className:"space-y-4",children:[g&&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:g}),e.jsx(q,{label:"Nama Key",placeholder:"cth: App Mobile",maxLength:100,value:r,onChange:a=>k(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),z())},autoFocus:!0}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(i,{variant:"ghost",onClick:()=>h(!1),children:"Batal"}),e.jsx(i,{isLoading:E,onClick:z,children:"Buat Key"})]})]})}),e.jsx(C,{open:!!n,onClose:()=>A(null),title:"API Key Berhasil Dibuat 🎉",subtitle:"Salin sekarang — key tidak akan tampil lagi setelah ditutup.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl border border-amber-400/25 bg-amber-500/10 px-4 py-3 text-xs text-amber-200",children:"⚠️ Key lengkap hanya ditampilkan sekali. Simpan di tempat aman sebelum menutup jendela ini."}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"rounded-xl border border-white/[0.08] bg-ink-950/80 px-4 py-3 pr-24 font-mono text-xs text-brand-200 break-all",children:n==null?void 0:n.key}),e.jsx("button",{onClick:Q,className:"absolute right-2 top-1/2 -translate-y-1/2 rounded-lg border border-white/[0.08] bg-white/[0.04] px-3 py-1.5 text-xs font-medium text-white transition hover:bg-white/[0.08]",children:U?"✓ Tersalin":"Salin"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[e.jsx("span",{className:"font-mono",children:n==null?void 0:n.key_prefix}),e.jsxs("span",{children:["Saldo:"," ",e.jsx("span",{className:"tabular-nums",children:n?O(n.credit_balance):"0.00"})]})]}),e.jsx(i,{className:"w-full",onClick:()=>A(null),children:"Saya sudah menyimpannya"})]})}),e.jsx(C,{open:!!t,onClose:()=>{L||N(null)},title:"Hapus API Key Permanen",subtitle:"Tindakan ini tidak dapat dibatalkan",width:"max-w-sm",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-xs leading-relaxed text-red-300",children:["Anda akan ",e.jsx("strong",{children:"menghapus permanen"})," key"," ",e.jsx("strong",{children:t==null?void 0:t.name})," (",e.jsxs("span",{className:"font-mono",children:[t==null?void 0:t.key_prefix,"…"]}),"). Key ini berhenti berfungsi dan riwayat pemakaiannya ikut terhapus."]}),e.jsx(q,{label:`Ketik nama key untuk konfirmasi: ${(t==null?void 0:t.name)??""}`,value:D,onChange:a=>{I(a.target.value),v(null)},placeholder:(t==null?void 0:t.name)??"",autoFocus:!0}),G&&e.jsx("p",{className:"text-xs font-medium text-red-400",children:G}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(i,{variant:"ghost",onClick:()=>N(null),disabled:L,children:"Batal"}),e.jsx(i,{variant:"danger",isLoading:L,disabled:D.trim()!==(t==null?void 0:t.name),onClick:J,children:"Ya, Hapus"})]}),D.trim()!==(t==null?void 0:t.name)&&e.jsx("p",{className:"text-right text-[11px] text-slate-500",children:"Ketik nama key lengkap untuk mengaktifkan tombol."})]})}),e.jsx(C,{open:_!=null,onClose:()=>b(null),title:"Revoke API Key?",subtitle:"Key akan langsung nonaktif dan tidak bisa dipakai lagi.",width:"max-w-sm",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-slate-400",children:"Tindakan ini tidak bisa dibatalkan. Key yang di-revoke tetap tampil di daftar dengan status Nonaktif."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(i,{variant:"ghost",onClick:()=>b(null),children:"Batal"}),e.jsx(i,{variant:"danger",isLoading:W,onClick:V,children:"Ya, Revoke"})]})]})})]})}export{de as default};

Zerion Mini Shell 1.0