PageSourceSearch

https://routerai.ai/static/js/async/3900.91d6d05bef.js

js routerai.ai collected 2026-10-05 14:53:21 UTC 50,521 bytes, 2 lines download raw bytes

1/*! LICENSE: 3900.91d6d05bef.js.LICENSE.txt */
2"use strict";(self.rspackChunknewapi_web=self.rspackChunknewapi_web||[]).push([[3900],{98622(e,t,a){var s=a(72361),l=a(6702),n=a(56275),r=a(42817);function i(e){var t;let{t:a}=(0,l.Bd)(),{group:i,label:o,ratio:d,copyable:c=!1,showDot:u,className:m,...x}=e,p=i?.trim(),h="auto"===p,g=!p,j=h||g,f=(t={labelOverride:o,groupName:p,isAutoGroup:h,isEmptyGroup:g,t:a}).labelOverride?t.labelOverride:t.isEmptyGroup?t.t("User Group"):t.isAutoGroup?t.t("Auto"):t.groupName??"",y=(0,s.jsx)(r.Wh,{...x,copyable:c,label:f,showDot:u??(!j&&void 0),variant:j?"neutral":void 0,autoColor:j?void 0:p,className:(0,n.cn)("min-w-0 shrink overflow-hidden",m)});return null==d?y:(0,s.jsxs)("span",{className:"inline-flex max-w-full min-w-0 items-center gap-2 text-xs",children:[(0,s.jsx)("span",{className:"max-w-full min-w-0 overflow-hidden",children:y}),(0,s.jsx)("span",{className:(0,n.cn)("inline-flex h-5 shrink-0 items-center rounded-full px-1.5 font-mono text-xs leading-none font-medium tabular-nums",d>1?"bg-warning/10 text-warning":d<1?"bg-info/10 text-info":"bg-muted text-muted-foreground"),children:(0,s.jsxs)("span",{children:[d,"x"]})})]})}a.d(t,{d:()=>i})},18353(e,t,a){var s=a(72361),l=a(25104),n=a(74401),r=a(68413),i=a(6702),o=a(20598),d=a(49641),c=a(11768),u=a(56275);let m=/[,,\n]/;function x(e){let{t}=(0,i.Bd)(),a=e.placeholder??t("Select items..."),x=(0,d.I0)(),[p,h]=r.useState(""),[g,j]=r.useState(!1),[f,y]=r.useState(!1),b=r.useMemo(()=>new Set(e.selected),[e.selected]),v=r.useMemo(()=>{let t=new Map;for(let a of e.options)t.set(a.value,a.label);return t},[e.options]),w=p.trim(),k=w.length>0&&(b.has(w)||e.options.some(e=>e.value===w||e.label===w)),N=!0===e.allowCreate&&w.length>0&&!k,C=r.useMemo(()=>{let t=new Set(e.options.map(e=>e.value));for(let a of e.selected)t.add(a);return N&&t.add(w),Array.from(t)},[e.options,e.selected,N,w]),_=r.useCallback(t=>{let a=[],s=new Set(e.selected);for(let e of t){let t=e.trim();t&&(s.has(t)||(s.add(t),a.push(t)))}0!==a.length&&e.onChange([...e.selected,...a])},[e]),A=r.useCallback(async(e,a,s)=>{e.preventDefault(),e.stopPropagation(),await (0,c.l)(a)?o.oR.success(t("Copied: {{model}}",{model:s})):o.oR.error(t("Failed to copy"))},[t]);return(0,s.jsxs)(d.G3,{multiple:!0,items:C,value:e.selected,onValueChange:t=>{e.onChange(t),t.length>e.selected.length&&h("")},inputValue:p,onInputValueChange:t=>{if(!e.allowCreate)return void h(t);let a=function(e){if(!m.test(e))return{completed:[],draft:e};let t=e.replaceAll(",",",").replaceAll("\n",",").split(","),a=t.at(-1)??"";return{completed:t.slice(0,-1).map(e=>e.trim()).filter(Boolean),draft:a}}(t);if(a.completed.length>0){_(a.completed),h(a.draft);return}h(t)},open:g,onOpenChange:j,disabled:e.disabled,children:[(0,s.jsxs)(d.HL,{ref:x,className:(0,u.cn)("w-full",e.className),children:[(0,s.jsx)(d.pn,{children:a=>{if(e.renderSelectedSummary)return(0,s.jsx)("span",{className:"bg-muted text-muted-foreground flex h-[calc(--spacing(5.25))] w-fit items-center justify-center rounded-sm px-1.5 font-mono text-xs font-medium whitespace-nowrap",children:e.renderSelectedSummary(a)});let l="number"!=typeof e.maxVisibleChips||f?a:a.slice(0,e.maxVisibleChips),n=a.length-l.length;return(0,s.jsxs)(s.Fragment,{children:[l.map(a=>{let l=v.get(a)??a;return(0,s.jsx)(d.em,{children:e.copyChipOnClick?(0,s.jsx)("button",{type:"button",onClick:e=>A(e,a,l),onPointerDown:e=>e.stopPropagation(),title:t("Click to copy"),className:"max-w-[16rem] cursor-pointer truncate rounded-sm hover:underline",children:l}):(0,s.jsx)("span",{className:"max-w-[16rem] truncate",children:l})},a)}),n>0&&(0,s.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),y(!0)},onPointerDown:e=>e.stopPropagation(),title:t("Show All"),className:"bg-muted text-muted-foreground hover:bg-muted/80 hover:text-foreground flex h-[calc(--spacing(5.25))] w-fit cursor-pointer items-center justify-center rounded-sm px-1.5 text-xs font-medium whitespace-nowrap transition-colors",children:t("+{{count}} more",{count:n})}),f&&"number"==typeof e.maxVisibleChips&&a.length>e.maxVisibleChips&&(0,s.jsx)("button",{type:"button",onClick:e=>{e.preventDefault(),e.stopPropagation(),y(!1)},onPointerDown:e=>e.stopPropagation(),title:t("Collapse"),className:"bg-muted text-muted-foreground hover:bg-muted/80 hover:text-foreground flex h-[calc(--spacing(5.25))] w-fit cursor-pointer items-center justify-center rounded-sm px-1.5 text-xs font-medium whitespace-nowrap transition-colors",children:t("Collapse")})]})}}),(0,s.jsx)(d.pJ,{id:e.id,placeholder:0!==e.selected.length||e.render
2SelectedSummary?void 0:a,onKeyDown:t=>{if("Enter"===t.key&&e.allowCreate&&N){let e=document.querySelector('[data-slot="combobox-content"][data-open]');e?.querySelector("[data-highlighted]")==null&&(t.preventDefault(),_([w]),h(""))}},"aria-label":a})]}),(0,s.jsxs)(d.h5,{anchor:x,children:[(0,s.jsx)(d.ex,{children:(0,s.jsx)(d.uL,{children:a=>{let r=N&&a===w,i=v.get(a)??a;return(0,s.jsx)(d.x4,{value:a,className:r?"text-foreground":void 0,children:r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.n,{icon:l.A,strokeWidth:2,className:"text-muted-foreground","aria-hidden":"true"}),(0,s.jsx)("span",{className:"truncate",children:e.createLabel?t(e.createLabel,{value:a}):t('Add "{{value}}"',{value:a})})]}):(0,s.jsx)("span",{className:"truncate",children:i})},a)}})}),(0,s.jsx)(d.$U,{children:e.emptyText??t("No matching items")})]})]})}a.d(t,{K:()=>x})},8803(e,t,a){var s=a(68413);let l="page-size";function n(e){let{search:t,navigate:a,pagination:n,globalFilter:r,columnFilters:i=[]}=e,o=n?.pageKey??"page",d=n?.pageSizeKey??"pageSize",c=n?.defaultPage??1,u=n?.defaultPageSize??20,m=r?.key??"filter",x=r?.enabled??!0,p=r?.trim??!0,h=(0,s.useMemo)(()=>{let e=[];for(let a of i){let s=t[a.searchKey],l=a.deserialize??(e=>e);if("string"===a.type){let t=l(s)??"";"string"==typeof t&&""!==t.trim()&&e.push({id:a.columnId,value:t})}else{let t=l(s)??[];Array.isArray(t)&&t.length>0&&e.push({id:a.columnId,value:t})}}return e},[i,t]),[g,j]=(0,s.useState)(h);(0,s.useEffect)(()=>{j(h)},[t]);let f=(0,s.useMemo)(()=>{let e=t[o],a=t[d];return{pageIndex:Math.max(0,("number"==typeof e?e:c)-1),pageSize:"number"==typeof a?a:function(){try{let e=parseInt(localStorage.getItem(l)??"",10);return e>0?e:void 0}catch{return}}()??u}},[t,o,d,c,u]),[y,b]=(0,s.useState)(()=>{if(!x)return;let e=t[m];return"string"==typeof e?e:""}),v=x?e=>{let t="function"==typeof e?e(y??""):e,s=p?t.trim():t;b(s),a({search:e=>({...e,[o]:void 0,[m]:s||void 0})})}:void 0;return{globalFilter:x?y??"":void 0,onGlobalFilterChange:v,columnFilters:g,onColumnFiltersChange:e=>{let t="function"==typeof e?e(g):e;j(t);let s={};for(let e of i){let a=t.find(t=>t.id===e.columnId),l=e.serialize??(e=>e);if("string"===e.type){let t="string"==typeof a?.value?a.value:"";s[e.searchKey]=""!==t.trim()?l(t):void 0}else{let t=Array.isArray(a?.value)?a.value:[];s[e.searchKey]=t.length>0?l(t):void 0}}a({search:e=>({...e,[o]:void 0,...s})})},pagination:f,onPaginationChange:e=>{let t="function"==typeof e?e(f):e,s=t.pageIndex+1,n=t.pageSize;n!==f.pageSize&&function(e){try{localStorage.setItem(l,String(e))}catch{}}(n),a({search:e=>({...e,[o]:s<=c?void 0:s,[d]:n})})},ensurePageInRange:function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{resetTo:"first"},l=t[o],n="number"==typeof l?l:c;e>0&&n>e&&a({replace:!0,search:t=>({...t,[o]:"last"===s.resetTo?e:void 0})})}}}a.d(t,{c:()=>n})},71463(e,t,a){let s="newapi_channel_conn";function l(e,t){return JSON.stringify({_type:s,key:e,url:t})}function n(e){if(!e||"string"!=typeof e)return null;try{let t=JSON.parse(e.trim());if("object"==typeof t&&null!==t&&t._type===s&&"string"==typeof t.key&&"string"==typeof t.url)return{key:t.key,url:t.url}}catch{}return null}a.d(t,{G1:()=>l,hd:()=>n})},8695(e,t,a){a.r(t),a.d(t,{component:()=>eY});var s=a(72361),l=a(6702),n=a(47745),r=a(68413),i=a(20598),o=a(92379),d=a(96713),c=a(64564),u=a(20687);let m=r.createContext(null);function x(e){let{children:t}=e,{t:a}=(0,l.Bd)(),[n,o]=(0,u.Ay)(null),[x,p]=(0,r.useState)(null),[h,g]=(0,r.useState)(0),[j,f]=(0,r.useState)(""),[y,b]=(0,r.useState)({}),[v,w]=(0,r.useState)({}),k=(0,r.useRef)({}),[N,C]=(0,r.useState)(null),_=(0,r.useRef)(void 0);(0,r.useEffect)(()=>()=>clearTimeout(_.current),[]);let A=(0,r.useCallback)(e=>{C(e),clearTimeout(_.current),_.current=setTimeout(()=>C(null),2e3)},[]),S=(0,r.useCallback)(()=>{g(e=>e+1)},[]),I=(0,r.useCallback)(async e=>{if(y[e])return y[e];if(e in k.current)return k.current[e];let t=(async()=>{w(t=>({...t,[e]:!0}));try{let t=await (0,d.$8)(e);if(t.success&&t.data?.key){let a=`sk-${t.data.key}`;return b(t=>({...t,[e]:a})),a}return i.oR.error(t.message||a(c.UU.UNEXPECTED)),null}catch{return i.oR.error(a(c.UU.UNEXPECTED)),null}finally{delete k.current[e],w(t=>{let a={...t};return delete a[e],a})}})();return k.current[e]=t,t},[y,a]),P=(0,r.useCallback)(async e=>{let t=e.filter(e=>!y[e]);if(0===t.length){let t={};for(let a of e)t[a]=y[a];return t}for(let e of t)w(t=>({...t,[e]:!0}));try{let s=await (0,d.wD)(t);if(s.success&&s.data?.keys){let t={};for(let[e,a]of Object.entries(s.data.keys))t[Number(e)]=`sk-${a}`;b(e=>({...e,...t}));let a={...t};for(let t of e)y[t]&&(a[t]=y[t]);return a}return i.oR.error(s.message||a(c.UU.UNEXPECTED)),{}}catch{return i.oR.error(a(c.UU.UNEXPECTED)),{}}finally{for(let e of t)w(t=>{let a={...t};return delete a[e],a})}},[y,a]);return(0,s.jsx)(m,{value:{open:n,setOpen:o,currentRow:x,setCurrentRow:p,refreshTrigger:h,triggerRefresh:S,resolvedKey:j,setResolvedKey:f,resolveRealKey:I,resolveRealKeysBatch:P,resolvedKeys:y,loadingKeys:v,copiedKeyId:N,markKeyCopied:A},children:t})}let p=()=>{let e=r.useContext(m);if(!e)throw Error("useApiKeys has to be used within <ApiKeysContext>");return e};function h(){let{t:e}=(0,l.Bd)(),{open:t,setOpen:a,currentRow:n,triggerRefresh:u}=p(),[m,x]=(0,r.useState)(!1),h=async()=>
2{if(n){x(!0);try{let t=await (0,d.Lh)(n.id);t.success?(i.oR.success(e(c.PL.API_KEY_DELETED)),a(null),u()):i.oR.error(t.message||e(c.UU.DELETE_FAILED))}catch{i.oR.error(e(c.UU.UNEXPECTED))}finally{x(!1)}}};return(0,s.jsx)(o.Lt,{open:"delete"===t,onOpenChange:e=>!e&&a(null),children:(0,s.jsxs)(o.EO,{children:[(0,s.jsxs)(o.wd,{children:[(0,s.jsx)(o.r7,{children:e("Are you sure?")}),(0,s.jsxs)(o.$v,{children:[e("This will permanently delete API key")," ",(0,s.jsx)("span",{className:"font-semibold",children:n?.name}),e(". This action cannot be undone.")]})]}),(0,s.jsxs)(o.ck,{children:[(0,s.jsx)(o.Zr,{disabled:m,children:e("Cancel")}),(0,s.jsx)(o.Rx,{onClick:h,disabled:m,variant:"destructive",children:m?e("Deleting..."):e("Delete")})]})]})})}var g=a(48367),j=a(53540),f=a(47296),y=a(567),b=a(76336),v=a(37116),w=a(86832),k=a(8802),N=a(47029),C=a(18353),_=a(72868),A=a(6242),S=a(36710),I=a(1738),P=a(74559),E=a(87212),z=a(70954),R=a(13289),K=a(22990),D=a(43459),M=a(56275),q=a(25732),U=a(33271);let F={name:"",remain_quota_dollars:10,expired_time:void 0,unlimited_quota:!0,model_limits:[],allow_ips:"",group:"",cross_group_retry:!0,tokenCount:1};function L(e){return{...F,group:e?"auto":"",cross_group_retry:e}}var T=a(4421),$=a(67834),B=a(90879),O=a(97653),V=a(74501);function J(e){var t;let{ratio:a}=e,{t:n}=(0,l.Bd)(),r=(t=n("Ratio"),null==a||""===a?null:`${a}x ${t}`);return r?(0,s.jsx)(B.E,{variant:"outline",className:(0,M.cn)("max-w-24 shrink-0 truncate text-[10px] sm:max-w-none sm:text-xs","number"!=typeof a?"border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/40 dark:text-emerald-300":a>5?"border-rose-200 bg-rose-50 text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/40 dark:text-rose-300":a>3?"border-orange-200 bg-orange-50 text-orange-700 dark:border-orange-900/60 dark:bg-orange-950/40 dark:text-orange-300":a>1?"border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900/60 dark:bg-blue-950/40 dark:text-blue-300":"border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/40 dark:text-emerald-300"),children:r}):null}function W(e){let{options:t,value:a,onValueChange:n,placeholder:i,disabled:o}=e,{t:d}=(0,l.Bd)(),[c,u]=(0,r.useState)(!1),[m,x]=(0,r.useState)(""),p=t.find(e=>e.value===a),h=(0,r.useMemo)(()=>{let e=m.trim().toLowerCase();return e?t.filter(t=>{let a=String(t.ratio??"").toLowerCase();return t.value.toLowerCase().includes(e)||t.label.toLowerCase().includes(e)||t.desc?.toLowerCase().includes(e)||a.includes(e)}):t},[t,m]);return(0,s.jsxs)(V.AM,{open:c,onOpenChange:u,children:[(0,s.jsxs)(V.Wv,{render:(0,s.jsx)(_.$,{type:"button",variant:"outline",role:"combobox","aria-expanded":c,disabled:o,className:"border-input bg-muted/40 hover:bg-muted/55 hover:text-foreground active:bg-background data-popup-open:border-ring data-popup-open:bg-background data-popup-open:ring-ring/20 h-auto min-h-14 w-full justify-between gap-2 rounded-lg px-3 py-2 text-start shadow-none transition-[background-color,border-color,box-shadow] duration-150 data-popup-open:ring-[3px] sm:min-h-20 sm:gap-3 sm:px-4 sm:py-3"}),children:[(0,s.jsxs)("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-2 sm:gap-3",children:[(0,s.jsxs)("span",{className:"min-w-0",children:[(0,s.jsx)("span",{className:"block truncate font-medium",children:p?.label||i||d("Select a group")}),p?.desc&&(0,s.jsx)("span",{className:"text-muted-foreground block truncate text-[11px] sm:text-xs",children:p.desc})]}),(0,s.jsx)("span",{className:"hidden sm:block",children:(0,s.jsx)(J,{ratio:p?.ratio})})]}),(0,s.jsx)(T.A,{className:"h-4 w-4 shrink-0 opacity-50"})]}),(0,s.jsx)(V.hl,{className:"data-closed:zoom-out-100 data-open:zoom-in-100 data-[side=bottom]:slide-in-from-top-0 data-[side=left]:slide-in-from-right-0 data-[side=right]:slide-in-from-left-0 data-[side=top]:slide-in-from-bottom-0 w-[var(--anchor-width)] overflow-hidden rounded-xl p-0 shadow-lg data-closed:duration-75 data-open:duration-100",onWheel:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:(0,s.jsxs)(O.uB,{shouldFilter:!1,children:[(0,s.jsx)(O.G7,{placeholder:d("Search..."),value:m,onValueChange:x}),(0,s.jsxs)(O.oI,{className:"max-h-[360px]",children:[(0,s.jsx)(O.xL,{children:d("No group found.")}),(0,s.jsx)(O.L$,{children:h.map(e=>(0,s.jsxs)(O.h_,{value:e.value,onSelect:()=>{n(e.value),u(!1),x("")},className:"data-[selected=true]:bg-muted items-start gap-3 rounded-lg px-3 py-3 transition-colors",children:[(0,s.jsx)($.A,{className:(0,M.cn)("mt-0.5 h-4 w-4",a===e.value?"opacity-100":"opacity-0")}),(0,s.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"block truncate font-medium",children:e.label}),e.desc&&(0,s.jsx)("span",{className:"text-muted-foreground block truncate text-xs",children:e.desc})]}),(0,s.jsx)(J,{ratio:e.ratio})]},e.value))})]})]})})]})}function H(e){let{open:t,onOpenChange:a,currentRow:n}=e,{t:o}=(0,l.Bd)(),u=!!n,{triggerRefresh:m}=p(),{status:x}=(0,R.s)(),[h,F]=(0,r.useState)(!1),[T,$]=(0,r.useState)(!1),B=x?.default_use_auto_group===!0,{data:O}=(0,j.I)({queryKey:["user-models"],queryFn:K.QK,enabled:t,staleTime:0}),{data:V}=(0,j.I)({queryKey:["user-groups"],queryFn:K.K4,enabled:t,staleTime:0}),J=O?.data||[],H=Object.entries(V?.data||{}).map(e=>
2{let[t,a]=e;return{value:t,label:t,desc:a.desc||t,ratio:a.ratio}}),Y=H.some(e=>"auto"===e.value),G=q.Ik({name:q.Yj().min(1,o("Please enter a name")),remain_quota_dollars:q.ai().optional(),expired_time:q.p6().optional(),unlimited_quota:q.zM(),model_limits:q.YO(q.Yj()),allow_ips:q.Yj().optional(),group:q.Yj().optional(),cross_group_retry:q.zM().optional(),tokenCount:q.ai().min(1).optional()}).superRefine((e,t)=>{!e.unlimited_quota&&(void 0===e.remain_quota_dollars||e.remain_quota_dollars<0)&&t.addIssue({code:"custom",path:["remain_quota_dollars"],message:o("Quota must be zero or greater")})}),X=(0,w.mN)({resolver:(0,g.u)(G),defaultValues:L(B)});(0,r.useEffect)(()=>{t&&u&&n?(0,d.CG)(n.id).then(e=>{var t;e.success&&e.data&&X.reset({name:(t=e.data).name,remain_quota_dollars:t.unlimited_quota?0:(0,U.Sh)(t.remain_quota),expired_time:t.expired_time>0?new Date(1e3*t.expired_time):void 0,unlimited_quota:t.unlimited_quota,model_limits:t.model_limits?t.model_limits.split(",").filter(Boolean):[],allow_ips:t.allow_ips||"",group:t.group||"",cross_group_retry:!!t.cross_group_retry,tokenCount:1})}):t&&!u&&X.reset(L(B&&Y))},[t,u,n,X,B,Y]),(0,r.useEffect)(()=>{if(0===H.length)return;let e=X.getValues("group");if(e&&!H.some(t=>t.value===e)){let t=H.find(e=>"default"===e.value)?.value??H[0]?.value??"";X.setValue("group",t),"auto"===e&&X.setValue("cross_group_retry",!1)}},[H,X]);let Z=async e=>{F(!0);try{let t={name:e.name,remain_quota:e.unlimited_quota?0:(0,U.dD)(e.remain_quota_dollars||0),expired_time:e.expired_time?Math.floor(e.expired_time.getTime()/1e3):-1,unlimited_quota:e.unlimited_quota,model_limits_enabled:e.model_limits.length>0,model_limits:e.model_limits.join(","),allow_ips:e.allow_ips||"",group:e.group||"",cross_group_retry:"auto"===e.group&&!!e.cross_group_retry};if(u&&n){let e=await (0,d.XW)({...t,id:n.id});e.success?(i.oR.success(o(c.PL.API_KEY_UPDATED)),a(!1),m()):i.oR.error(e.message||o(c.UU.UPDATE_FAILED))}else{let s=e.tokenCount||1,l=0;for(let a=0;a<s;a++){let s=await (0,d.Iq)({...t,name:0===a&&e.name?e.name:`${e.name||"default"}-${Math.random().toString(36).slice(2,8)}`});if(s.success)l++;else{i.oR.error(s.message||o(c.UU.CREATE_FAILED));break}}l>0&&(i.oR.success(o("Successfully created {{count}} API Key(s)",{count:l})),a(!1),m())}}catch{i.oR.error(o(c.UU.UNEXPECTED))}finally{F(!1)}},Q=()=>{i.oR.error(o("Please fix the highlighted fields before saving"))},ee=(e,t,a)=>{if(0===e&&0===t&&0===a)return void X.setValue("expired_time",void 0);let s=new Date;s.setMonth(s.getMonth()+e),s.setDate(s.getDate()+t),s.setHours(s.getHours()+a),X.setValue("expired_time",s)},{meta:et}=(0,D.cw)(),ea=(0,D.yz)(),es="tokens"===et.kind,el=o("Quota ({{currency}})",{currency:ea}),en=es?o("Enter quota in tokens"):o("Enter quota in {{currency}}",{currency:ea}),er=X.watch("group"),ei=X.watch("unlimited_quota");return(0,s.jsx)(P.cj,{open:t,onOpenChange:e=>{a(e),e||X.reset()},children:(0,s.jsxs)(P.h,{className:(0,N.jW)("max-w-none sm:!max-w-[620px]"),children:[(0,s.jsxs)(P.Fm,{className:(0,N.Dt)(),children:[(0,s.jsx)(P.qp,{children:u?o("Update API Key"):o("Create API Key")}),(0,s.jsx)(P.Qs,{children:u?o("Update the API key by providing necessary info."):o("Add a new API key by providing necessary info.")})]}),(0,s.jsx)(S.lV,{...X,children:(0,s.jsxs)("form",{id:"api-key-form",onSubmit:X.handleSubmit(Z,Q),className:(0,N.e)("gap-5"),children:[(0,s.jsxs)(N.y5,{children:[(0,s.jsx)(N.JP,{title:o("Basic Information"),description:o("Set API key basic information"),icon:(0,s.jsx)(f.A,{className:"size-4"}),iconTone:"info"}),(0,s.jsx)(S.zB,{control:X.control,name:"name",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:o("Name")}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(I.p,{...t,placeholder:o("Enter a name")})}),(0,s.jsx)(S.C5,{})]})}}),(0,s.jsx)(S.zB,{control:X.control,name:"group",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:o("Group")}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(W,{options:H,value:t.value,onValueChange:t.onChange,placeholder:o("Select a group")})}),(0,s.jsx)(S.C5,{})]})}}),"auto"===er&&(0,s.jsx)(S.zB,{control:X.control,name:"cross_group_retry",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{className:(0,N.fE)(),children:[(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)(S.lR,{className:"text-sm",children:o("Cross-group retry")}),(0,s.jsx)(S.Rr,{className:"line-clamp-2 text-xs sm:line-clamp-none",children:o("When enabled, if channels in the current group fail, it will try channels in the next group in order.")})]}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(E.d,{checked:!!t.value,onCheckedChange:t.onChange})})]})}}),(0,s.jsx)(S.zB,{control:X.control,name:"expired_time",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:o("Expiration Time")}),(0,s.jsxs)("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center",children:[(0,s.jsx)(S.MJ,{children:(0,s.jsx)(k.K,{value:t.value,onChange:t.onChange,placeholder:o("Never expires"),className:"min-w-0 [&_input[type=time]]:w-24 sm:[&_input[type=time]]:w-32"})}),(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-2 sm:flex",children:[(0,s.jsx)(_.$,{type:"button",variant:"outline",size:"sm",className:"px-2 text-xs sm:px-3 sm:text-sm",onClick:()=>ee(0,0,0),children:o("Never")}),(0,s.jsx)(_.$,{type:"button",variant:"outline",size:"sm",className:"px-2 text-xs sm:px-3 sm:text-sm",onClick:()=>ee(1,0,0),children:o("1 Month")}),(0,s.jsx)(_.$,{type:"button",variant:"outline",size:"sm",className:"px-2 text-xs sm:px-3 sm:text-sm",onClick:()=>ee(0,1,0),children:o("1 Day")}),(0,s.jsx)(_.$,{type:"button",variant:"outline",size:"sm",className:"px-2 text-xs sm:px-3 sm:text-sm",onClick:()=>ee(0,0,1),children:o("1 Hour")})]})]}),(0,s.jsx)(S.C5,{})]})}}),!u&&(0,s.jsx)(S.zB,{control:X.control,name:"tokenCount",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:o("Quantity")}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(I.p,{...t,type:"number",min:"1",placeholder:o("Number of keys to create"),onChange:e=>t.onChange(Number.parseInt(e.target.value,10)||1)})}),(0,s.jsx)(S.Rr,{children:o("Create multiple API keys at once (random suffix will be added to names)")}),(0,s.jsx)(S.C5,{})]})}})]}),(0,s.jsxs)(N.y5,{children:[(0,s.jsx)(N.JP,{title:o("Quota Settings"),description:o("Set quota amount and limits"),icon:(0,s.jsx)(y.A,{className:"size-4"}),iconTone:"success"}),!ei&&(0,s.jsx)(S.zB,{control:X.control,name:"remain_quota_dollars",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:el}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(I.p,{...t,type:"number",step:es?1:.01,placeholder:en,onChange:e=>t.onChange(Number.parseFloat(e.target.value)||0)})}),(0,s.jsx)(S.Rr,{children:es?o("Enter the quota amount in tokens"):o("Enter the quota amount in {{currency}}",{currency:ea})}),(0,s.jsx)(S.C5,{})]})}}),(0,s.jsx)(S.zB,{control:X.control,name:"unlimited_quota",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{className:(0,N.fE)(),children:[(0,s.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,s.jsx)(S.lR,{className:"text-sm",children:o("Unlimited Quota")}),(0,s.jsx)(S.Rr,{className:"text-xs",children:o("Enable unlimited quota for this API key")})]}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(E.d,{checked:t.value,onCheckedChange:t.onChange})})]})}})]}),(0,s.jsx)(A.Nt,{open:T,onOpenChange:$,children:(0,s.jsxs)(N.y5,{children:[(0,s.jsxs)(A.R6,{render:(0,s.jsx)("button",{type:"button",className:"hover:bg-muted/40 flex w-full items-center gap-3 rounded-md py-1.5 text-left transition-colors"}),children:[(0,s.jsx)(N.JP,{className:"flex-1",title:o("Advanced Settings"),description:o("Set API key access restrictions"),icon:(0,s.jsx)(b.A,{className:"size-4"})}),(0,s.jsx)(v.A,{className:(0,M.cn)("text-muted-foreground size-4 shrink-0 transition-transform",T&&"rotate-180")}
2)]}),(0,s.jsx)(A.Ke,{children:(0,s.jsxs)("div",{className:"flex flex-col gap-4 pt-2",children:[(0,s.jsx)(S.zB,{control:X.control,name:"model_limits",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:o("Model Limits")}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(C.K,{options:J.map(e=>({label:e,value:e})),selected:t.value,onChange:t.onChange,placeholder:o("Select models (empty for allow all)")})}),(0,s.jsx)(S.Rr,{children:o("Limit which models can be used with this key")}),(0,s.jsx)(S.C5,{})]})}}),(0,s.jsx)(S.zB,{control:X.control,name:"allow_ips",render:e=>{let{field:t}=e;return(0,s.jsxs)(S.eI,{children:[(0,s.jsx)(S.lR,{children:o("IP Whitelist (supports CIDR)")}),(0,s.jsx)(S.MJ,{children:(0,s.jsx)(z.T,{...t,className:"min-h-20 resize-none",placeholder:o("One IP per line (empty for no restriction)"),rows:3})}),(0,s.jsx)(S.Rr,{children:o("Do not over-trust this feature. IP may be spoofed. Please use with nginx, CDN and other gateways.")}),(0,s.jsx)(S.C5,{})]})}})]})})]})})]})}),(0,s.jsxs)(P.XW,{className:(0,N.Jx)(),children:[(0,s.jsx)(P.kN,{render:(0,s.jsx)(_.$,{variant:"outline",className:"w-full sm:w-auto"}),children:o("Close")}),(0,s.jsx)(_.$,{type:"button",onClick:X.handleSubmit(Z,Q),disabled:h,className:"w-full sm:w-auto",children:h?o("Saving..."):o("Save changes")})]})]})})}var Y=a(60641),G=a(8150),X=a(11728),Z=a(67085);let Q={claude:{label:"Claude",defaultName:"My Claude",modelFields:[{key:"model",labelKey:"Primary Model",required:!0},{key:"haikuModel",labelKey:"Haiku Model",required:!1},{key:"sonnetModel",labelKey:"Sonnet Model",required:!1},{key:"opusModel",labelKey:"Opus Model",required:!1}]},codex:{label:"Codex",defaultName:"My Codex",modelFields:[{key:"model",labelKey:"Primary Model",required:!0}]},gemini:{label:"Gemini",defaultName:"My Gemini",modelFields:[{key:"model",labelKey:"Primary Model",required:!0}]}};function ee(e){let{t}=(0,l.Bd)(),[a,n]=(0,r.useState)("claude"),[o,d]=(0,r.useState)(Q.claude.defaultName),[c,u]=(0,r.useState)({}),{data:m}=(0,j.I)({queryKey:["user-models-ccswitch"],queryFn:K.QK,enabled:e.open,staleTime:3e5}),x=(0,r.useMemo)(()=>(m?.data??[]).map(e=>({value:e,label:e})),[m?.data]);(0,r.useEffect)(()=>{e.open&&(u({}),n("claude"),d(Q.claude.defaultName))},[e.open]);let p=Q[a];return(0,s.jsx)(Y.l,{open:e.open,onOpenChange:e.onOpenChange,title:t("Import to CC Switch"),contentClassName:"sm:max-w-md",contentHeight:"auto",bodyClassName:1===p.modelFields.length?"space-y-4 pb-52":"space-y-4",footer:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(_.$,{variant:"outline",onClick:()=>e.onOpenChange(!1),children:t("Cancel")}),(0,s.jsx)(_.$,{onClick:()=>{if(!c.model)return void i.oR.warning(t("Please select a primary model"));let s=function(e,t,a,s){let l=function(){try{let e=localStorage.getItem("status");if(e){let t=JSON.parse(e);if(t.server_address)return t.server_address}}catch{}return window.location.origin}(),n="codex"===e?l+"/v1":l,r=new URLSearchParams;for(let[l,i]of(r.set("resource","provider"),r.set("app",e),r.set("name",t),r.set("endpoint",n),r.set("apiKey",s),Object.entries(a)))i&&r.set(l,i);return r.set("homepage",l),r.set("enabled","true"),`ccswitch://v1/import?${r.toString()}`}(a,o,c,e.tokenKey.startsWith("sk-")?e.tokenKey:`sk-${e.tokenKey}`);window.open(s,"_blank"),e.onOpenChange(!1)},children:t("Open CC Switch")})]}),children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(X.J,{children:t("Application")}),(0,s.jsx)(Z.z,{value:a,onValueChange:e=>{n(e),d(Q[e].defaultName),u({})},className:"flex gap-4",children:Object.entries(Q).map(e=>{let[t,a]=e;return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(Z.C,{value:t,id:`app-${t}`}),(0,s.jsx)(X.J,{htmlFor:`app-${t}`,className:"cursor-pointer",children:a.label})]},t)})})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(X.J,{children:t("Name")}
2),(0,s.jsx)(G.o,{options:[],value:o,onValueChange:d,placeholder:p.defaultName,emptyText:"",allowCustomValue:!0})]}),p.modelFields.map(e=>(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)(X.J,{children:[t(e.labelKey),e.required&&(0,s.jsx)("span",{className:"text-destructive ml-0.5",children:"*"})]}),(0,s.jsx)(G.o,{options:x,value:c[e.key]||"",onValueChange:t=>u(a=>({...a,[e.key]:t})),placeholder:t("Select or enter model name"),emptyText:t("No models found")})]},e.key))]})})}function et(){let{open:e,setOpen:t,currentRow:a,resolvedKey:l}=p();return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(H,{open:"create"===e||"update"===e,onOpenChange:e=>!e&&t(null),currentRow:"update"===e&&a||void 0}),(0,s.jsx)(h,{}),(0,s.jsx)(ee,{open:"cc-switch"===e,onOpenChange:e=>!e&&t(null),tokenKey:l})]})}var ea=a(66002);function es(){let{t:e}=(0,l.Bd)(),{setOpen:t}=p();return(0,s.jsx)("div",{className:"flex gap-2",children:(0,s.jsxs)(_.$,{size:"sm",onClick:()=>t("create"),children:[(0,s.jsx)(ea.A,{className:"h-4 w-4"}),e("Create API Key")]})})}var el=a(2718),en=a(11397),er=a(55045),ei=a(42817),eo=a(12393),ed=a(97785),ec=a(8803),eu=a(99893),em=a(55724),ex=a(47303),ep=a(11768);function eh(e){let{apiKey:t}=e,{t:a}=(0,l.Bd)(),{resolveRealKey:n,resolvedKeys:i,loadingKeys:o,copiedKeyId:d,markKeyCopied:c}=p(),[u,m]=(0,r.useState)(!1),x=!!o[t.id],h=i[t.id],g=d===t.id,j=`sk-${t.key}`,f=(0,r.useCallback)(e=>{m(e),e&&!h&&n(t.id)},[h,n,t.id]),y=(0,r.useCallback)(async()=>{let e=h||await n(t.id);!e||await (0,ep.l)(e)&&c(t.id)},[h,n,t.id,c]),b=(0,s.jsx)(eu.A,{className:"size-3.5"}),v=a("Copy API key");return x?(b=(0,s.jsx)(em.A,{className:"size-3.5 animate-spin"}),v=a("Loading...")):g&&(b=(0,s.jsx)($.A,{className:"size-3.5 text-green-600"}),v=a("Copied!")),(0,s.jsxs)("div",{className:"flex max-w-full min-w-0 items-center",children:[(0,s.jsxs)(V.AM,{open:u,onOpenChange:f,children:[(0,s.jsx)(V.Wv,{render:(0,s.jsx)(_.$,{variant:"ghost",size:"sm",className:"text-muted-foreground h-7 max-w-full min-w-0 justify-start truncate px-0 font-mono text-xs hover:bg-transparent aria-expanded:bg-transparent"}),children:(0,s.jsx)("span",{className:"truncate",children:j})}),(0,s.jsx)(V.hl,{className:"w-auto max-w-[min(90vw,28rem)]",align:"start",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("p",{className:"text-muted-foreground text-xs",children:a("Full API Key")}),x?(0,s.jsxs)("div",{className:"flex items-center gap-2 py-2",children:[(0,s.jsx)(em.A,{className:"size-3.5 animate-spin"}),(0,s.jsx)("span",{className:"text-muted-foreground text-xs",children:a("Loading...")})]}):(0,s.jsx)("input",{readOnly:!0,value:h||j,autoFocus:!0,onFocus:e=>e.target.select(),className:"bg-muted/50 w-full min-w-[280px] rounded-md border px-3 py-2 font-mono text-xs outline-none"})]})})]}),(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)(_.$,{variant:"ghost",size:"icon",className:"size-7 shrink-0",onClick:y,disabled:x}),children:b}),(0,s.jsx)(ex.ZI,{children:v})]})]})}function eg(e){let{t}=(0,l.Bd)(),a=(0,U.eN)(e.used);return(0,s.jsxs)(V.AM,{children:[(0,s.jsx)(V.Wv,{render:(0,s.jsx)("button",{type:"button",className:"focus-visible:ring-ring/50 -ml-1.5 cursor-help rounded-4xl focus-visible:ring-[3px] focus-visible:outline-none","aria-label":`${t("Unlimited")}; ${t("Used:")} ${a}`}),children:(0,s.jsx)(ei.Wh,{label:t("Unlimited"),variant:"neutral",copyable:!1})}),(0,s.jsx)(V.hl,{className:"w-auto p-2",side:"top",children:(0,s.jsxs)("span",{className:"text-xs",children:[t("Used:")," ",a]})})]})}function ej(e){let{apiKey:t}=e,{t:a}=(0,l.Bd)();if(!t.model_limits_enabled||!t.model_limits)return(0,s.jsx)(ei.Wh,{label:a("Unlimited"),variant:"neutral",copyable:!1,className:"-ml-1.5"});let n=t.model_limits.split(",").filter(Boolean);return(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)(er.ak,{}),children:(0,s.jsx)(ei.Wh,{label:a("{{count}} model(s)",{count:n.length}),variant:"neutral",copyable:!1})}),(0,s.jsx)(ex.ZI,{side:"top",className:"max-w-xs",children:(0,s.jsx)("div",{className:"max-h-[200px] space-y-0.5 overflow-y-auto text-xs",children:n.map(e=>(0,s.jsx)("div",{className:"font-mono",children:e},e))})})]})}function ef(e){let{apiKey:t}=e,{t:a}=(0,l.Bd)(),n=t.allow_ips?.trim();if(!n)return(0,s.jsx)(ei.Wh,{label:a("No restriction"),variant:"neutral",copyable:!1,className:"-ml-1.5"});let r=n.split("\n").map(e=>
2e.trim()).filter(Boolean);return(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)(er.ak,{}),children:(0,s.jsx)(ei.Wh,{label:a("{{count}} IP(s)",{count:r.length}),variant:"neutral",copyable:!1})}),(0,s.jsx)(ex.ZI,{side:"top",className:"max-w-xs",children:(0,s.jsx)("div",{className:"max-h-[200px] space-y-0.5 overflow-y-auto text-xs",children:r.map(e=>(0,s.jsx)("div",{className:"font-mono",children:e},e))})})]})}var ey=a(98622),eb=a(82655),ev=a(47497),ew=a(52048),ek=a(84935);function eN(e){if(!e.timestamp||-1===e.timestamp)return(0,s.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let t=1e3*e.timestamp,a=t<=e.now&&e.now-t<6e4?e.justNowLabel:(0,U.K3)(e.timestamp,"seconds",e.locale),l=(0,U.fk)(e.timestamp);return(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)("time",{dateTime:new Date(t).toISOString(),tabIndex:0,className:(0,M.cn)("block truncate font-mono text-xs tabular-nums",e.className)}),children:a}),(0,s.jsx)(ex.ZI,{children:(0,s.jsx)("span",{className:"font-mono tabular-nums",children:l})})]})}var eC=a(36001),e_=a(6201),eA=a(5825),eS=a(9781);let eI=(0,eS.A)("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),eP=(0,eS.A)("arrow-right-left",[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]]);var eE=a(66552),ez=a(14653),eR=a(43494),eK=a(84368),eD=a(84619),eM=a(83013),eq=a(71463);let eU=q.Ik({id:q.ai(),name:q.Yj(),key:q.Yj(),status:q.ai(),remain_quota:q.ai(),used_quota:q.ai(),unlimited_quota:q.zM(),expired_time:q.ai(),created_time:q.ai(),accessed_time:q.ai(),group:q.Yj().nullish().default(""),cross_group_retry:q.vk(e=>1===e||0!==e&&e,q.zM()).optional().default(!1),model_limits_enabled:q.zM(),model_limits:q.Yj().nullish().default(""),allow_ips:q.Yj().nullish().default("")});function eF(e){let{row:t}=e,{t:a}=(0,l.Bd)(),n=eU.parse(t.original),{setOpen:o,setCurrentRow:u,triggerRefresh:m,setResolvedKey:x,resolveRealKey:h,resolvedKeys:g,loadingKeys:j}=p(),f=n.status===c.m7.ENABLED,{chatPresets:y,serverAddress:b}=(0,eD.w)(),[v,w]=(0,r.useState)(!1),k=g[n.id],N=!!j[n.id],C=y.length>0,A=f?a("Disable"):a("Enable"),S=(0,r.useCallback)(e=>{!e||k||N||h(n.id)},[n.id,N,k,h]),I=(0,r.useCallback)(()=>k||(h(n.id),i.oR.info(a("API key is loading, please try again in a moment")),null),[n.id,k,h,a]),P=(0,r.useCallback)(async e=>{let t=await h(n.id);if(!t)return;if("fluent"===e.type)return void(!function(e,t){if("u"<typeof window)return!1;let a=document.getElementById("fluent-new-api-container");if(!a)return!1;let s={id:"new-api",baseUrl:t||window.location.origin,apiKey:`sk-${e}`};return a.dispatchEvent(new CustomEvent("fluent:prefill",{detail:s})),!0}(t,b)?i.oR.info(a("FluentRead extension not detected. Please ensure it is installed and active.")):i.oR.success(a("Sent the API key to FluentRead.")));let s=(0,eM.Kf)({template:e.url,apiKey:t,serverAddress:b});if(!s)return void i.oR.error(a("Invalid chat link. Please contact your administrator."));if("u">typeof window)try{window.open(s,"_blank","noopener")}catch{window.location.href=s}},[h,n.id,b,a]),E=async e=>{e?.stopPropagation();let t=f?c.m7.DISABLED:c.m7.ENABLED;w(!0);try{let e=await (0,d.JM)(n.id,t);if(e.success){let e=f?a(c.PL.API_KEY_DISABLED):a(c.PL.API_KEY_ENABLED);i.oR.success(e),m()}else i.oR.error(e.message||a(c.UU.STATUS_UPDATE_FAILED))}catch{i.oR.error(a(c.UU.UNEXPECTED))}finally{w(!1)}},z=(0,s.jsx)(eC.A,{className:"size-4"});return v?z=(0,s.jsx)(em.A,{className:"size-4 animate-spin"}):f&&(z=(0,s.jsx)(e_.A,{className:"size-4"})),(0,s.jsxs)("div",{className:"-ml-1.5 flex items-center gap-1",children:[(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)(_.$,{variant:"ghost",size:"icon-sm",onClick:E,disabled:v,"aria-label":A,className:f?"text-destructive hover:text-destructive":"text-emerald-600 hover:text-emerald-600 dark:text-emerald-400 dark:hover:text-emerald-400"}),children:z}),(0,s.jsx)(ex.ZI,{children:A})]}),(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)(_.$,{variant:"ghost",size:"icon-sm",onClick:()=>{u(n),o("update")},"aria-label":a("Edit")}),children:(0,s.jsx)(eA.A,{})}),(0,s.jsx)(ex.ZI,{children:a("Edit")})]}),(0,s.jsxs)(eR.C,{ariaLabel:a("Open menu"),contentClassName:"w-[200px]",modal:!1,onOpenChange:S,children:[(0,s.jsxs)(eK._2,{onClick:async()=>{let e=I();!e||await (0,ep.l)(e)&&i.oR.success(a("Copied"))},children:[a("Copy Key"),(0,s.jsx)(eK.V0,{children:(0,s.jsx)(eu.A,{size:16})})]}),(0,s.jsxs)(eK._2,{onClick:async()=>{let e=I();if(!e)return;let t=(0,eq.G1)(e,function(){try{let e=localStorage.getItem("status");if(e){let t=JSON.parse(e);if(t.server_address)return t.server_address}}catch{}return window.location.origin}());await (0,ep.l)(t)&&i.oR.success(a("Copied"))},children:[a("Copy Connection Info"),(0,s.jsx)(eK.V0,{children:(0,s.jsx)(eI,{size:16})})]}),(0,s.jsx)(eK.mB,{}),(0,s.jsxs)(eK._2,{onClick:async()=>{let e=await h(n.id);e&&(x(e),u(n),o("cc-switch"))},children:[a("CC Switch"),(0,s.jsx)(eK.V0,{children:(0,s.jsx)(eP,{size:16})})]}),C&&(0,s.jsxs)(eK.lv,{children:[(0,s.jsx)(eK.nV,{children:a("Chat")}),(0,s.jsx)(eK.M5,{children:y.map(e=>(0,s.jsxs)(eK._2,{onClick:()=>P(e),children:[e.name,"web"!==e.type&&(0,s.jsx)(eK.V0,{children:(0,s.jsx)(eE.A,{size:16})})]},e.id))})]}),(0,s.jsx)(eK.mB,{}),(0,s.jsxs)(eK._2,{onClick:()=>{u(n),o("delete")},className:"text-destructive focus:text-destructive",children:[a("Delete"),(0,s.jsx)(eK.V0,{children:(0,s.jsx)(ez.A,{size:16})})]})]})]})}var eL=a(73280);function eT(e){let{open:t,onOpenChange:a,table:n}=e,{t:o}=(0,l.Bd)(),{triggerRefresh:u}=p(),[m,x]=(0,r.useState)(!1),h=n.getFilteredSelectedRowModel().rows,g=async()=>{x(!0);try{let e=h.map(e=>e.original.id),t=await (0,d.S0)(e);if(t.success){let s=t.data||e.length;i.oR.success(o("Successfully deleted {{count}} API key(s)",{count:s})),n.resetRowSelection(),u(),a(!1)}
2else i.oR.error(t.message||o(c.UU.BATCH_DELETE_FAILED))}catch(e){i.oR.error(o(c.UU.UNEXPECTED))}finally{x(!1)}};return(0,s.jsx)(eL.T,{destructive:!0,open:t,onOpenChange:a,handleConfirm:g,isLoading:m,className:"max-w-md",title:o("Delete {{count}} API key(s)?",{count:h.length}),desc:(0,s.jsxs)(s.Fragment,{children:[o("You are about to delete {{count}} API key(s).",{count:h.length})," ",(0,s.jsx)("br",{}),o("This action cannot be undone.")]}),confirmText:o("Delete")})}function e$(e){let{table:t}=e,{t:a}=(0,l.Bd)(),{resolveRealKeysBatch:n}=p(),[o,d]=(0,r.useState)(!1),[c,u]=(0,r.useState)(!1),m=t.getFilteredSelectedRowModel().rows,x=(0,r.useCallback)(async()=>{if(0!==m.length){u(!0);try{let e=m.map(e=>e.original.id),t=await n(e),s=[];for(let e of m){let a=e.original,l=t[a.id];l&&s.push(`${a.name}	${l}`)}s.length>0&&(await (0,ep.l)(s.join("\n"))?i.oR.success(a("Copied {{count}} key(s)",{count:s.length})):i.oR.error(a("Failed to copy keys")))}catch{i.oR.error(a("Failed to copy keys"))}finally{u(!1)}}},[m,n,a]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(er.Of,{table:t,entityName:"API key",children:[(0,s.jsxs)(ex.m_,{children:[(0,s.jsx)(ex.k$,{render:(0,s.jsx)(_.$,{variant:"outline",size:"icon",className:"size-8",onClick:x,disabled:c,"aria-label":a("Copy selected keys")}),children:c?(0,s.jsx)(em.A,{className:"size-4 animate-spin"}):(0,s.jsx)(eu.A,{className:"size-4"})}),(0,s.jsx)(ex.ZI,{children:(0,s.jsx)("p",{children:a("Copy selected keys")})})]}),(0,s.jsxs)(ex.m_,{children:[(0,s.jsxs)(ex.k$,{render:(0,s.jsx)(_.$,{variant:"destructive",size:"icon",onClick:()=>d(!0),className:"size-8","aria-label":a("Delete selected API keys")}),children:[(0,s.jsx)(ez.A,{}),(0,s.jsx)("span",{className:"sr-only",children:a("Delete selected API keys")})]}),(0,s.jsx)(ex.ZI,{children:(0,s.jsx)("p",{children:a("Delete selected API keys")})})]})]}),(0,s.jsx)(eT,{open:o,onOpenChange:d,table:t})]})}let eB=(0,el.GY)("/_authenticated/keys/"),eO=Array.from({length:5},(e,t)=>`api-key-mobile-skeleton-${t+1}`);function eV(e){return e.status!==c.m7.ENABLED}function eJ(){return(0,s.jsx)("div",{className:"divide-border overflow-hidden rounded-lg border",children:eO.map(e=>(0,s.jsxs)("div",{className:"space-y-2 border-b px-3 py-2.5 last:border-b-0",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)(ed.E,{className:"h-4 w-32"}),(0,s.jsx)(ed.E,{className:"h-5 w-16 rounded-md"})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,s.jsx)(ed.E,{className:"h-7 w-44"}),(0,s.jsx)(ed.E,{className:"h-8 w-16"})]}),(0,s.jsx)(ed.E,{className:"h-3 w-28"})]},e))})}function eW(e){let{table:t,isLoading:a}=e,{t:n}=(0,l.Bd)(),r=t.getRowModel().rows;return a?(0,s.jsx)(eJ,{}):r.length?(0,s.jsx)("div",{className:"divide-border overflow-hidden rounded-lg border",children:r.map(e=>{let t=e.original,a=c.EG[t.status],l=t.used_quota+t.remain_quota;return(0,s.jsxs)("div",{className:(0,M.cn)("bg-card space-y-2.5 border-b px-3 py-2.5 last:border-b-0",eV(t)&&er.Z0),children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("div",{className:"truncate text-sm font-semibold",children:t.name}),(0,s.jsx)("div",{className:"text-muted-foreground text-[11px]",children:n("API Key")})]}),a&&(0,s.jsx)(ei.Wh,{label:n(a.label),variant:a.variant,copyable:!1})]}),(0,s.jsxs)("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[(0,s.jsx)("div",{className:"min-w-0 flex-1 [&_button:first-child]:max-w-full [&_button:first-child]:truncate [&_button:first-child]:px-0",children:(0,s.jsx)(eh,{apiKey:t})}),(0,s.jsx)(eF,{row:e})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 text-xs",children:[(0,s.jsx)("span",{className:"text-muted-foreground",children:n("Quota")}),t.unlimited_quota?(0,s.jsx)(eg,{used:t.used_quota}):(0,s.jsxs)("span",{className:"font-medium tabular-nums",children:[(0,U.eN)(t.remain_quota),(0,s.jsxs)("span",{className:"text-muted-foreground font-normal",children:[" / ",(0,U.eN)(l)]})]})]})]},e.id)})}):(0,s.jsx)("div",{className:"rounded-lg border p-8",children:(0,s.jsx)(eo.Sv,{className:"border-none p-0",children:(0,s.jsxs)(eo.FT,{children:[(0,s.jsx)(eo.Kr,{variant:"icon",children:(0,s.jsx)(en.A,{className:"size-6"})}),(0,s.jsx)(eo.cz,{children:n("No API Keys Found")}),(0,s.jsx)(eo.Ou,{children:n("No API keys available. Create your first API key to get started.")})]})})})}function eH(){let{t:e}=(0,l.Bd)(),{refreshTrigger:t}=p(),[a,n]=(0,r.useState)(()=>Date.now()),o=function(e){let{t,i18n:a}=(0,l.Bd)(),n=function(){let{data:e}=(0,j.I)({queryKey:["user-groups"],queryFn:K.K4,staleTime:0,select:e=>{if(!e.success||!e.data)return{};let t={};for(let[a,s]of Object.entries(e.data))"number"==typeof s.ratio&&(t[a]=s.ratio);return t}});return e??{}}(),r=(0,ew.Tl)(a.resolvedLanguage||a.language),i=t("Just now"),o=(0,ek.A)(e).subtract(3,"month").valueOf();return[{id:"select",header:e=>{let{table:t}=e;return(0,s.jsx)(eb.S,{checked:t.getIsAllPageRowsSelected(),indeterminate:t.getIsSomePageRowsSelected(),onCheckedChange:e=>t.toggleAllPageRowsSelected(!!e),"aria-label":"Select all",className:"translate-y-[2px]"})},cell:e=>{let{row:t}=e;return(0,s.jsx)(eb.S,{checked:t.getIsSelected(),onCheckedChange:e=>t.toggleSelected(!!e),"aria-label":"Select row",className:"translate-y-[2px]"})},enableSorting:!1,enableHiding:!1,size:40},{accessorKey:"name",header:t("Name"),cell:e=>{let{row:t}=e;return(0,s.jsx)("span",{className:"font-medium",children:t.getValue("name")}
2)},size:180,meta:{mobileTitle:!0}},{accessorKey:"status",header:t("Status"),cell:e=>{let{row:a}=e,l=c.EG[a.getValue("status")];return l?(0,s.jsx)(ei.Wh,{label:t(l.label),variant:l.variant,copyable:!1,className:"-ml-1.5"}):null},filterFn:(e,t,a)=>a.includes(String(e.getValue(t))),size:120,meta:{mobileBadge:!0}},{id:"key",accessorKey:"key",header:t("API Key"),cell:e=>{let{row:t}=e;return(0,s.jsx)(eh,{apiKey:t.original})},enableSorting:!1,size:260},{id:"quota",accessorKey:"remain_quota",header:t("Quota"),cell:e=>{let{row:a}=e,l=a.original;if(l.unlimited_quota)return(0,s.jsx)(eg,{used:l.used_quota});let n=l.used_quota,r=l.remain_quota,i=n+r,o=i>0?r/i*100:0;return(0,s.jsxs)(ex.m_,{children:[(0,s.jsxs)(ex.k$,{render:(0,s.jsx)("div",{className:"w-[150px] space-y-1"}),children:[(0,s.jsxs)("div",{className:"flex justify-between text-xs",children:[(0,s.jsx)("span",{className:"font-medium tabular-nums",children:(0,U.eN)(r)}),(0,s.jsx)("span",{className:"text-muted-foreground tabular-nums",children:(0,U.eN)(i)})]}),(0,s.jsx)(ev.ke,{value:o,className:(0,M.cn)("h-1.5",o<=10?"[&_[data-slot=progress-indicator]]:bg-rose-500":o<=30?"[&_[data-slot=progress-indicator]]:bg-amber-500":"[&_[data-slot=progress-indicator]]:bg-emerald-500")})]}),(0,s.jsx)(ex.ZI,{children:(0,s.jsxs)("div",{className:"space-y-1 text-xs",children:[(0,s.jsxs)("div",{children:[t("Used:")," ",(0,U.eN)(n)]}),(0,s.jsxs)("div",{children:[t("Remaining:")," ",(0,U.eN)(r)," (",o.toFixed(1),"%)"]}),(0,s.jsxs)("div",{children:[t("Total:")," ",(0,U.eN)(i)]})]})})]})},size:170},{accessorKey:"group",header:t("Group"),cell:e=>{let{row:a}=e,l=a.original,r=a.getValue("group"),i=r&&"auto"!==r?n[r]:void 0;return"auto"===r?(0,s.jsxs)(ex.m_,{children:[(0,s.jsxs)(ex.k$,{render:(0,s.jsx)(er.ak,{className:"gap-1.5 text-xs"}),children:[(0,s.jsx)(ey.d,{group:"auto"}),l.cross_group_retry&&(0,s.jsx)(ei.Wh,{label:t("Cross-group"),variant:"info",copyable:!1})]}),(0,s.jsx)(ex.ZI,{children:(0,s.jsx)("span",{className:"text-xs",children:t("Automatically selects the best available group with circuit breaker mechanism")})})]}):(0,s.jsx)(er.TX,{className:"-ml-1.5",tooltipContent:r||"-",tooltipClassName:"break-all",children:(0,s.jsx)(ey.d,{group:r,ratio:i})})},size:160,meta:{mobileHidden:!0}},{id:"model_limits",accessorKey:"model_limits",header:t("Models"),cell:e=>{let{row:t}=e;return(0,s.jsx)(ej,{apiKey:t.original})},enableSorting:!1,size:160,meta:{mobileHidden:!0}},{id:"allow_ips",accessorKey:"allow_ips",header:t("IP Restriction"),cell:e=>{let{row:t}=e;return(0,s.jsx)(ef,{apiKey:t.original})},enableSorting:!1,size:160,meta:{mobileHidden:!0}},{accessorKey:"created_time",header:t("Created"),cell:t=>{let{row:a}=t;return(0,s.jsx)(eN,{timestamp:a.getValue("created_time"),now:e,locale:r,justNowLabel:i,className:"text-muted-foreground"})},size:180,meta:{mobileHidden:!0}},{accessorKey:"accessed_time",header:t("Last Used"),cell:t=>{let{row:a}=t,l=a.getValue("accessed_time"),n=l>0&&1e3*l<o;return(0,s.jsx)(eN,{timestamp:l,now:e,locale:r,justNowLabel:i,className:n?"text-warning":"text-muted-foreground"})},size:180,meta:{mobileHidden:!0}},{accessorKey:"expired_time",header:t("Expires"),cell:a=>{let{row:l}=a,n=l.getValue("expired_time");if(-1===n)return(0,s.jsx)(ei.Wh,{label:t("Never"),variant:"neutral",copyable:!1,className:"-ml-1.5"});let o=1e3*n<e;return(0,s.jsx)(eN,{timestamp:n,now:e,locale:r,justNowLabel:i,className:(0,M.cn)(o?"text-destructive":"text-muted-foreground")})},size:180,meta:{mobileHidden:!0}},{id:"actions",header:()=>t("Actions"),cell:e=>{let{row:t}=e;return(0,s.jsx)(eF,{row:t})},meta:{pinned:"right"}}]}(a);(0,r.useEffect)(()=>{let e=window.setInterval(()=>{n(Date.now())},3e4);return()=>window.clearInterval(e)},[]);let{globalFilter:u,onGlobalFilterChange:m,columnFilters:x,onColumnFiltersChange:h,pagination:g,onPaginationChange:f,ensurePageInRange:y}=(0,ec.c)({search:eB.useSearch(),navigate:eB.useNavigate(),pagination:{defaultPage:1,defaultPageSize:20},globalFilter:{enabled:!0,key:"filter"}
2,columnFilters:[{columnId:"status",searchKey:"status",type:"array"},{columnId:"_tokenSearch",searchKey:"token",type:"string"}]}),{value:b,inputValue:v,setInputValue:w}=(0,er.bz)({columnFilters:x,columnId:"_tokenSearch",onColumnFiltersChange:h}),k=!!(u?.trim()||b.trim()),{data:N,isLoading:C,isFetching:_}=(0,j.I)({queryKey:["keys",g.pageIndex+1,g.pageSize,u,b,t],queryFn:async()=>{let t=k?await (0,d.Dw)({keyword:u,token:b,p:g.pageIndex+1,size:g.pageSize}):await (0,d.PX)({p:g.pageIndex+1,size:g.pageSize});return t.success?{items:t.data?.items||[],total:t.data?.total||0}:(i.oR.error(t.message||e(k?c.UU.SEARCH_FAILED:c.UU.LOAD_FAILED)),{items:[],total:0})},placeholderData:e=>e}),A=N?.items||[],{table:S}=(0,er.uI)({data:A,columns:o,enableRowSelection:!0,columnFilters:x,columnVisibilityStorageKey:"api-keys:column-visibility",globalFilter:u,pagination:g,globalFilterFn:()=>!0,onPaginationChange:f,onGlobalFilterChange:m,onColumnFiltersChange:h,manualPagination:!0,totalCount:N?.total||0,ensurePageInRange:y});return(0,s.jsx)(er.cx,{table:S,columns:o,isLoading:C,isFetching:_,emptyTitle:e("No API Keys Found"),emptyDescription:e("No API keys available. Create your first API key to get started."),skeletonKeyPrefix:"api-keys-skeleton",applyHeaderSize:!0,toolbarProps:{searchPlaceholder:e("Filter by name..."),additionalSearch:(0,s.jsx)(I.p,{placeholder:e("Filter by API key..."),"aria-label":e("Filter by API key..."),value:v,onChange:e=>w(e.target.value),className:"w-full sm:w-50 lg:w-60"}),filters:[{columnId:"status",title:e("Status"),options:c.F7,singleSelect:!0}]},mobile:(0,s.jsx)(eW,{table:S,isLoading:C}),getRowClassName:e=>eV(e.original)?er.JM:void 0,bulkActions:(0,s.jsx)(e$,{table:S})})}let eY=function(){let{t:e}=(0,l.Bd)();return(0,s.jsxs)(x,{children:[(0,s.jsxs)(n.Ni,{fixedContent:!0,children:[(0,s.jsx)(n.Ni.Title,{children:e("API Keys")}),(0,s.jsx)(n.Ni.Actions,{children:(0,s.jsx)(es,{})}),(0,s.jsx)(n.Ni.Content,{children:(0,s.jsx)(eH,{})})]}),(0,s.jsx)(et,{})]})}},25104(e,t,a){a.d(t,{},{A:[["path",{d:"M12.001 5.00003V19.002",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",key:"0"}],["path",{d:"M19.002 12.002L4.99998 12.002",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",key:"1"}]]})},47296(e,t,a){let s=(0,a(9781).A)("key-round",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);a.d(t,{},{A:s})},6201(e,t,a){let s=(0,a(9781).A)("power-off",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);a.d(t,{},{A:s})},36001(e,t,a){let s=(0,a(9781).A)("power",[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]]);a.d(t,{},{A:s})},76336(e,t,a){let s=(0,a(9781).A)("settings-2",[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);a.d(t,{},{A:s})},567(e,t,a){let s=(0,a(9781).A)("wallet-cards",[["path",{d:"M3 11h3.75a2 2 0 0 1 1.6.8l.45.6a4 4 0 0 0 6.4 0l.45-.6a2 2 0 0 1 1.6-.8H21",key:"1vwh6y"}],["path",{d:"M3 7h18",key:"1uiuf2"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]);a.d(t,{},{A:s})}}]);

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.