@chenpu17/cc-gw 0.7.5 → 0.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/dist/index.js +160 -60
- package/src/web/dist/assets/About-DCvCA-EN.js +6 -0
- package/src/web/dist/assets/ApiKeys-chBAE4F4.js +16 -0
- package/src/web/dist/assets/Dashboard-B4kvSkr7.js +16 -0
- package/src/web/dist/assets/{Events-DjHvrNLA.js → Events-D9F6cmSK.js} +1 -1
- package/src/web/dist/assets/{Help-B4aI51F7.js → Help-WBFjl1uQ.js} +6 -6
- package/src/web/dist/assets/{Login-D2mlt6E4.js → Login-C2ITDdIa.js} +1 -1
- package/src/web/dist/assets/Logs-Cb_N4UAX.js +6 -0
- package/src/web/dist/assets/{ModelManagement-BBL4JPx_.js → ModelManagement-IWXiEI0s.js} +1 -1
- package/src/web/dist/assets/{PageHeader-CArgoeOl.js → PageHeader-xFKpGYn6.js} +1 -1
- package/src/web/dist/assets/{PageSection-B9KNzbSh.js → PageSection-Vn4S3q9j.js} +1 -1
- package/src/web/dist/assets/Settings-DJ0_2N3_.js +11 -0
- package/src/web/dist/assets/{card-Hot3HWFO.js → card-C20_HqC6.js} +1 -1
- package/src/web/dist/assets/clipboard-CALi6bTW.js +1 -0
- package/src/web/dist/assets/{copy-DXxd_I6B.js → copy-CUEQDKMx.js} +1 -1
- package/src/web/dist/assets/{dialog-DOFVjgLV.js → dialog-Cx1HX_hR.js} +1 -1
- package/src/web/dist/assets/{index-DgZMz9ou.js → index-DgjUxG8I.js} +1 -1
- package/src/web/dist/assets/{index-DSWEYKFg.js → index-UV1Qa96f.js} +2 -2
- package/src/web/dist/assets/{info-C3Uvuy3w.js → info-CewFzdVp.js} +1 -1
- package/src/web/dist/assets/{input-CSRYqyMm.js → input-CBGvcnZr.js} +1 -1
- package/src/web/dist/assets/{label-sxZdAo5j.js → label-BqSverDm.js} +1 -1
- package/src/web/dist/assets/{refresh-cw-Cm_OQO9a.js → refresh-cw-ISOSG1Po.js} +1 -1
- package/src/web/dist/assets/{select-qZIYkE-k.js → select-C8rWWJbl.js} +1 -1
- package/src/web/dist/assets/{switch-DDvmmBlT.js → switch-ODrypdNp.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-CDChhTqt.js → useApiQuery-C2OD7H7U.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/assets/About-BH1K5IKD.js +0 -6
- package/src/web/dist/assets/ApiKeys-B5xWItFi.js +0 -16
- package/src/web/dist/assets/Dashboard-3H13REtP.js +0 -16
- package/src/web/dist/assets/Logs-mTxHOg7D.js +0 -6
- package/src/web/dist/assets/Settings-CzKp7gwN.js +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
var ft=e=>{throw TypeError(e)};var Y=(e,t,s)=>t.has(e)||ft("Cannot "+s);var i=(e,t,s)=>(Y(e,t,"read from private field"),s?s.call(e):t.get(e)),b=(e,t,s)=>t.has(e)?ft("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),u=(e,t,s,r)=>(Y(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),d=(e,t,s)=>(Y(e,t,"access private method"),s);import{S as It,a6 as pt,a7 as S,s as Z,a8 as H,m as $,a9 as tt,aa as bt,ab as Ot,ac as q,ad as Tt,ae as wt,af as yt,n as St,r as I,o as Qt,l as Mt,ag as xt,d as _t,t as Ut}from"./index-DSWEYKFg.js";var g,a,j,y,Q,U,E,O,z,F,D,M,x,T,P,n,B,et,st,it,rt,at,nt,ht,Ct,vt,Ft=(vt=class extends It{constructor(t,s){super();b(this,n);b(this,g);b(this,a);b(this,j);b(this,y);b(this,Q);b(this,U);b(this,E);b(this,O);b(this,z);b(this,F);b(this,D);b(this,M);b(this,x);b(this,T);b(this,P,new Set);this.options=s,u(this,g,t),u(this,O,null),u(this,E,pt()),this.bindMethods(),this.setOptions(s)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(i(this,a).addObserver(this),gt(i(this,a),this.options)?d(this,n,B).call(this):this.updateResult(),d(this,n,rt).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return ot(i(this,a),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return ot(i(this,a),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,d(this,n,at).call(this),d(this,n,nt).call(this),i(this,a).removeObserver(this)}setOptions(t){const s=this.options,r=i(this,a);if(this.options=i(this,g).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof S(this.options.enabled,i(this,a))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");d(this,n,ht).call(this),i(this,a).setOptions(this.options),s._defaulted&&!Z(this.options,s)&&i(this,g).getQueryCache().notify({type:"observerOptionsUpdated",query:i(this,a),observer:this});const h=this.hasListeners();h&&mt(i(this,a),r,this.options,s)&&d(this,n,B).call(this),this.updateResult(),h&&(i(this,a)!==r||S(this.options.enabled,i(this,a))!==S(s.enabled,i(this,a))||H(this.options.staleTime,i(this,a))!==H(s.staleTime,i(this,a)))&&d(this,n,et).call(this);const o=d(this,n,st).call(this);h&&(i(this,a)!==r||S(this.options.enabled,i(this,a))!==S(s.enabled,i(this,a))||o!==i(this,T))&&d(this,n,it).call(this,o)}getOptimisticResult(t){const s=i(this,g).getQueryCache().build(i(this,g),t),r=this.createResult(s,t);return Pt(this,r)&&(u(this,y,r),u(this,U,this.options),u(this,Q,i(this,a).state)),r}getCurrentResult(){return i(this,y)}trackResult(t,s){return new Proxy(t,{get:(r,h)=>(this.trackProp(h),s==null||s(h),h==="promise"&&!this.options.experimental_prefetchInRender&&i(this,E).status==="pending"&&i(this,E).reject(new Error("experimental_prefetchInRender feature flag is not enabled")),Reflect.get(r,h))})}trackProp(t){i(this,P).add(t)}getCurrentQuery(){return i(this,a)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const s=i(this,g).defaultQueryOptions(t),r=i(this,g).getQueryCache().build(i(this,g),s);return r.fetch().then(()=>this.createResult(r,s))}fetch(t){return d(this,n,B).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),i(this,y)))}createResult(t,s){var dt;const r=i(this,a),h=this.options,o=i(this,y),c=i(this,Q),w=i(this,U),v=t!==r?t.state:i(this,j),{state:L}=t;let l={...L},N=!1,f;if(s._optimisticResults){const R=this.hasListeners(),W=!R&>(t,s),_=R&&mt(t,r,s,h);(W||_)&&(l={...l,...wt(L.data,t.options)}),s._optimisticResults==="isRestoring"&&(l.fetchStatus="idle")}let{error:A,errorUpdatedAt:k,status:m}=l;f=l.data;let V=!1;if(s.placeholderData!==void 0&&f===void 0&&m==="pending"){let R;o!=null&&o.isPlaceholderData&&s.placeholderData===(w==null?void 0:w.placeholderData)?(R=o.data,V=!0):R=typeof s.placeholderData=="function"?s.placeholderData((dt=i(this,D))==null?void 0:dt.state.data,i(this,D)):s.placeholderData,R!==void 0&&(m="success",f=yt(o==null?void 0:o.data,R,s),N=!0)}if(s.select&&f!==void 0&&!V)if(o&&f===(c==null?void 0:c.data)&&s.select===i(this,z))f=i(this,F);else try{u(this,z,s.select),f=s.select(f),f=yt(o==null?void 0:o.data,f,s),u(this,F,f),u(this,O,null)}catch(R){u(this,O,R)}i(this,O)&&(A=i(this,O),f=i(this,F),k=Date.now(),m="error");const G=l.fetchStatus==="fetching",J=m==="pending",X=m==="error",ut=J&&G,lt=f!==void 0,C={status:m,fetchStatus:l.fetchStatus,isPending:J,isSuccess:m==="success",isError:X,isInitialLoading:ut,isLoading:ut,data:f,dataUpdatedAt:l.dataUpdatedAt,error:A,errorUpdatedAt:k,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:l.dataUpdateCount>0||l.errorUpdateCount>0,isFetchedAfterMount:l.dataUpdateCount>v.dataUpdateCount||l.errorUpdateCount>v.errorUpdateCount,isFetching:G,isRefetching:G&&!J,isLoadingError:X&&!lt,isPaused:l.fetchStatus==="paused",isPlaceholderData:N,isRefetchError:X&<,isStale:ct(t,s),refetch:this.refetch,promise:i(this,E),isEnabled:S(s.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const R=K=>{C.status==="error"?K.reject(C.error):C.data!==void 0&&K.resolve(C.data)},W=()=>{const K=u(this,E,C.promise=pt());R(K)},_=i(this,E);switch(_.status){case"pending":t.queryHash===r.queryHash&&R(_);break;case"fulfilled":(C.status==="error"||C.data!==_.value)&&W();break;case"rejected":(C.status!=="error"||C.error!==_.reason)&&W();break}}return C}updateResult(){const t=i(this,y),s=this.createResult(i(this,a),this.options);if(u(this,Q,i(this,a).state),u(this,U,this.options),i(this,Q).data!==void 0&&u(this,D,i(this,a)),Z(s,t))return;u(this,y,s);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:h}=this.options,o=typeof h=="function"?h():h;if(o==="all"||!o&&!i(this,P).size)return!0;const c=new Set(o??i(this,P));return this.options.throwOnError&&c.add("error"),Object.keys(i(this,y)).some(w=>{const p=w;return i(this,y)[p]!==t[p]&&c.has(p)})};d(this,n,Ct).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&d(this,n,rt).call(this)}},g=new WeakMap,a=new WeakMap,j=new WeakMap,y=new WeakMap,Q=new WeakMap,U=new WeakMap,E=new WeakMap,O=new WeakMap,z=new WeakMap,F=new WeakMap,D=new WeakMap,M=new WeakMap,x=new WeakMap,T=new WeakMap,P=new WeakMap,n=new WeakSet,B=function(t){d(this,n,ht).call(this);let s=i(this,a).fetch(this.options,t);return t!=null&&t.throwOnError||(s=s.catch($)),s},et=function(){d(this,n,at).call(this);const t=H(this.options.staleTime,i(this,a));if(tt||i(this,y).isStale||!bt(t))return;const r=Ot(i(this,y).dataUpdatedAt,t)+1;u(this,M,q.setTimeout(()=>{i(this,y).isStale||this.updateResult()},r))},st=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(i(this,a)):this.options.refetchInterval)??!1},it=function(t){d(this,n,nt).call(this),u(this,T,t),!(tt||S(this.options.enabled,i(this,a))===!1||!bt(i(this,T))||i(this,T)===0)&&u(this,x,q.setInterval(()=>{(this.options.refetchIntervalInBackground||Tt.isFocused())&&d(this,n,B).call(this)},i(this,T)))},rt=function(){d(this,n,et).call(this),d(this,n,it).call(this,d(this,n,st).call(this))},at=function(){i(this,M)&&(q.clearTimeout(i(this,M)),u(this,M,void 0))},nt=function(){i(this,x)&&(q.clearInterval(i(this,x)),u(this,x,void 0))},ht=function(){const t=i(this,g).getQueryCache().build(i(this,g),this.options);if(t===i(this,a))return;const s=i(this,a);u(this,a,t),u(this,j,t.state),this.hasListeners()&&(s==null||s.removeObserver(this),t.addObserver(this))},Ct=function(t){St.batch(()=>{t.listeners&&this.listeners.forEach(s=>{s(i(this,y))}),i(this,g).getQueryCache().notify({query:i(this,a),type:"observerResultsUpdated"})})},vt);function Dt(e,t){return S(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function gt(e,t){return Dt(e,t)||e.state.data!==void 0&&ot(e,t,t.refetchOnMount)}function ot(e,t,s){if(S(t.enabled,e)!==!1&&H(t.staleTime,e)!=="static"){const r=typeof s=="function"?s(e):s;return r==="always"||r!==!1&&ct(e,t)}return!1}function mt(e,t,s,r){return(e!==t||S(r.enabled,e)===!1)&&(!s.suspense||e.state.status!=="error")&&ct(e,s)}function ct(e,t){return S(t.enabled,e)!==!1&&e.isStaleByTime(H(t.staleTime,e))}function Pt(e,t){return!Z(e.getCurrentResult(),t)}var Et=I.createContext(!1),Lt=()=>I.useContext(Et);Et.Provider;function Nt(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var At=I.createContext(Nt()),kt=()=>I.useContext(At),Bt=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},Ht=e=>{I.useEffect(()=>{e.clearReset()},[e])},jt=({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:h})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(h&&e.data===void 0||Qt(s,[e.error,r])),zt=e=>{if(e.suspense){const s=h=>h==="static"?h:Math.max(h??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...h)=>s(r(...h)):s(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},Vt=(e,t)=>e.isLoading&&e.isFetching&&!t,Wt=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,Rt=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function Kt(e,t,s){var l,N,f,A,k;const r=Lt(),h=kt(),o=Mt(),c=o.defaultQueryOptions(e);(N=(l=o.getDefaultOptions().queries)==null?void 0:l._experimental_beforeQuery)==null||N.call(l,c),c._optimisticResults=r?"isRestoring":"optimistic",zt(c),Bt(c,h),Ht(h);const w=!o.getQueryCache().get(c.queryHash),[p]=I.useState(()=>new t(o,c)),v=p.getOptimisticResult(c),L=!r&&e.subscribed!==!1;if(I.useSyncExternalStore(I.useCallback(m=>{const V=L?p.subscribe(St.batchCalls(m)):$;return p.updateResult(),V},[p,L]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),I.useEffect(()=>{p.setOptions(c)},[c,p]),Wt(c,v))throw Rt(c,p,h);if(jt({result:v,errorResetBoundary:h,throwOnError:c.throwOnError,query:o.getQueryCache().get(c.queryHash),suspense:c.suspense}))throw v.error;if((A=(f=o.getDefaultOptions().queries)==null?void 0:f._experimental_afterQuery)==null||A.call(f,c,v),c.experimental_prefetchInRender&&!tt&&Vt(v,r)){const m=w?Rt(c,p,h):(k=o.getQueryCache().get(c.queryHash))==null?void 0:k.promise;m==null||m.catch($).finally(()=>{p.updateResult()})}return c.notifyOnChangeProps?v:p.trackResult(v)}function qt(e,t){return Kt(e,Ft)}function Yt(e,t,s){return qt({queryKey:e,placeholderData:xt,...s,queryFn:async()=>{try{return(await _t.request(t)).data}catch(r){throw Ut(r)}}})}export{qt as a,Yt as u};
|
|
1
|
+
var ft=e=>{throw TypeError(e)};var Y=(e,t,s)=>t.has(e)||ft("Cannot "+s);var i=(e,t,s)=>(Y(e,t,"read from private field"),s?s.call(e):t.get(e)),b=(e,t,s)=>t.has(e)?ft("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),u=(e,t,s,r)=>(Y(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),d=(e,t,s)=>(Y(e,t,"access private method"),s);import{S as It,a6 as pt,a7 as S,s as Z,a8 as H,m as $,a9 as tt,aa as bt,ab as Ot,ac as q,ad as Tt,ae as wt,af as yt,n as St,r as I,o as Qt,l as Mt,ag as xt,d as _t,t as Ut}from"./index-UV1Qa96f.js";var g,a,j,y,Q,U,E,O,z,F,D,M,x,T,P,n,B,et,st,it,rt,at,nt,ht,Ct,vt,Ft=(vt=class extends It{constructor(t,s){super();b(this,n);b(this,g);b(this,a);b(this,j);b(this,y);b(this,Q);b(this,U);b(this,E);b(this,O);b(this,z);b(this,F);b(this,D);b(this,M);b(this,x);b(this,T);b(this,P,new Set);this.options=s,u(this,g,t),u(this,O,null),u(this,E,pt()),this.bindMethods(),this.setOptions(s)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(i(this,a).addObserver(this),gt(i(this,a),this.options)?d(this,n,B).call(this):this.updateResult(),d(this,n,rt).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return ot(i(this,a),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return ot(i(this,a),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,d(this,n,at).call(this),d(this,n,nt).call(this),i(this,a).removeObserver(this)}setOptions(t){const s=this.options,r=i(this,a);if(this.options=i(this,g).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof S(this.options.enabled,i(this,a))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");d(this,n,ht).call(this),i(this,a).setOptions(this.options),s._defaulted&&!Z(this.options,s)&&i(this,g).getQueryCache().notify({type:"observerOptionsUpdated",query:i(this,a),observer:this});const h=this.hasListeners();h&&mt(i(this,a),r,this.options,s)&&d(this,n,B).call(this),this.updateResult(),h&&(i(this,a)!==r||S(this.options.enabled,i(this,a))!==S(s.enabled,i(this,a))||H(this.options.staleTime,i(this,a))!==H(s.staleTime,i(this,a)))&&d(this,n,et).call(this);const o=d(this,n,st).call(this);h&&(i(this,a)!==r||S(this.options.enabled,i(this,a))!==S(s.enabled,i(this,a))||o!==i(this,T))&&d(this,n,it).call(this,o)}getOptimisticResult(t){const s=i(this,g).getQueryCache().build(i(this,g),t),r=this.createResult(s,t);return Pt(this,r)&&(u(this,y,r),u(this,U,this.options),u(this,Q,i(this,a).state)),r}getCurrentResult(){return i(this,y)}trackResult(t,s){return new Proxy(t,{get:(r,h)=>(this.trackProp(h),s==null||s(h),h==="promise"&&!this.options.experimental_prefetchInRender&&i(this,E).status==="pending"&&i(this,E).reject(new Error("experimental_prefetchInRender feature flag is not enabled")),Reflect.get(r,h))})}trackProp(t){i(this,P).add(t)}getCurrentQuery(){return i(this,a)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const s=i(this,g).defaultQueryOptions(t),r=i(this,g).getQueryCache().build(i(this,g),s);return r.fetch().then(()=>this.createResult(r,s))}fetch(t){return d(this,n,B).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),i(this,y)))}createResult(t,s){var dt;const r=i(this,a),h=this.options,o=i(this,y),c=i(this,Q),w=i(this,U),v=t!==r?t.state:i(this,j),{state:L}=t;let l={...L},N=!1,f;if(s._optimisticResults){const R=this.hasListeners(),W=!R&>(t,s),_=R&&mt(t,r,s,h);(W||_)&&(l={...l,...wt(L.data,t.options)}),s._optimisticResults==="isRestoring"&&(l.fetchStatus="idle")}let{error:A,errorUpdatedAt:k,status:m}=l;f=l.data;let V=!1;if(s.placeholderData!==void 0&&f===void 0&&m==="pending"){let R;o!=null&&o.isPlaceholderData&&s.placeholderData===(w==null?void 0:w.placeholderData)?(R=o.data,V=!0):R=typeof s.placeholderData=="function"?s.placeholderData((dt=i(this,D))==null?void 0:dt.state.data,i(this,D)):s.placeholderData,R!==void 0&&(m="success",f=yt(o==null?void 0:o.data,R,s),N=!0)}if(s.select&&f!==void 0&&!V)if(o&&f===(c==null?void 0:c.data)&&s.select===i(this,z))f=i(this,F);else try{u(this,z,s.select),f=s.select(f),f=yt(o==null?void 0:o.data,f,s),u(this,F,f),u(this,O,null)}catch(R){u(this,O,R)}i(this,O)&&(A=i(this,O),f=i(this,F),k=Date.now(),m="error");const G=l.fetchStatus==="fetching",J=m==="pending",X=m==="error",ut=J&&G,lt=f!==void 0,C={status:m,fetchStatus:l.fetchStatus,isPending:J,isSuccess:m==="success",isError:X,isInitialLoading:ut,isLoading:ut,data:f,dataUpdatedAt:l.dataUpdatedAt,error:A,errorUpdatedAt:k,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:l.dataUpdateCount>0||l.errorUpdateCount>0,isFetchedAfterMount:l.dataUpdateCount>v.dataUpdateCount||l.errorUpdateCount>v.errorUpdateCount,isFetching:G,isRefetching:G&&!J,isLoadingError:X&&!lt,isPaused:l.fetchStatus==="paused",isPlaceholderData:N,isRefetchError:X&<,isStale:ct(t,s),refetch:this.refetch,promise:i(this,E),isEnabled:S(s.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const R=K=>{C.status==="error"?K.reject(C.error):C.data!==void 0&&K.resolve(C.data)},W=()=>{const K=u(this,E,C.promise=pt());R(K)},_=i(this,E);switch(_.status){case"pending":t.queryHash===r.queryHash&&R(_);break;case"fulfilled":(C.status==="error"||C.data!==_.value)&&W();break;case"rejected":(C.status!=="error"||C.error!==_.reason)&&W();break}}return C}updateResult(){const t=i(this,y),s=this.createResult(i(this,a),this.options);if(u(this,Q,i(this,a).state),u(this,U,this.options),i(this,Q).data!==void 0&&u(this,D,i(this,a)),Z(s,t))return;u(this,y,s);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:h}=this.options,o=typeof h=="function"?h():h;if(o==="all"||!o&&!i(this,P).size)return!0;const c=new Set(o??i(this,P));return this.options.throwOnError&&c.add("error"),Object.keys(i(this,y)).some(w=>{const p=w;return i(this,y)[p]!==t[p]&&c.has(p)})};d(this,n,Ct).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&d(this,n,rt).call(this)}},g=new WeakMap,a=new WeakMap,j=new WeakMap,y=new WeakMap,Q=new WeakMap,U=new WeakMap,E=new WeakMap,O=new WeakMap,z=new WeakMap,F=new WeakMap,D=new WeakMap,M=new WeakMap,x=new WeakMap,T=new WeakMap,P=new WeakMap,n=new WeakSet,B=function(t){d(this,n,ht).call(this);let s=i(this,a).fetch(this.options,t);return t!=null&&t.throwOnError||(s=s.catch($)),s},et=function(){d(this,n,at).call(this);const t=H(this.options.staleTime,i(this,a));if(tt||i(this,y).isStale||!bt(t))return;const r=Ot(i(this,y).dataUpdatedAt,t)+1;u(this,M,q.setTimeout(()=>{i(this,y).isStale||this.updateResult()},r))},st=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(i(this,a)):this.options.refetchInterval)??!1},it=function(t){d(this,n,nt).call(this),u(this,T,t),!(tt||S(this.options.enabled,i(this,a))===!1||!bt(i(this,T))||i(this,T)===0)&&u(this,x,q.setInterval(()=>{(this.options.refetchIntervalInBackground||Tt.isFocused())&&d(this,n,B).call(this)},i(this,T)))},rt=function(){d(this,n,et).call(this),d(this,n,it).call(this,d(this,n,st).call(this))},at=function(){i(this,M)&&(q.clearTimeout(i(this,M)),u(this,M,void 0))},nt=function(){i(this,x)&&(q.clearInterval(i(this,x)),u(this,x,void 0))},ht=function(){const t=i(this,g).getQueryCache().build(i(this,g),this.options);if(t===i(this,a))return;const s=i(this,a);u(this,a,t),u(this,j,t.state),this.hasListeners()&&(s==null||s.removeObserver(this),t.addObserver(this))},Ct=function(t){St.batch(()=>{t.listeners&&this.listeners.forEach(s=>{s(i(this,y))}),i(this,g).getQueryCache().notify({query:i(this,a),type:"observerResultsUpdated"})})},vt);function Dt(e,t){return S(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function gt(e,t){return Dt(e,t)||e.state.data!==void 0&&ot(e,t,t.refetchOnMount)}function ot(e,t,s){if(S(t.enabled,e)!==!1&&H(t.staleTime,e)!=="static"){const r=typeof s=="function"?s(e):s;return r==="always"||r!==!1&&ct(e,t)}return!1}function mt(e,t,s,r){return(e!==t||S(r.enabled,e)===!1)&&(!s.suspense||e.state.status!=="error")&&ct(e,s)}function ct(e,t){return S(t.enabled,e)!==!1&&e.isStaleByTime(H(t.staleTime,e))}function Pt(e,t){return!Z(e.getCurrentResult(),t)}var Et=I.createContext(!1),Lt=()=>I.useContext(Et);Et.Provider;function Nt(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var At=I.createContext(Nt()),kt=()=>I.useContext(At),Bt=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},Ht=e=>{I.useEffect(()=>{e.clearReset()},[e])},jt=({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:h})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(h&&e.data===void 0||Qt(s,[e.error,r])),zt=e=>{if(e.suspense){const s=h=>h==="static"?h:Math.max(h??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...h)=>s(r(...h)):s(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},Vt=(e,t)=>e.isLoading&&e.isFetching&&!t,Wt=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,Rt=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function Kt(e,t,s){var l,N,f,A,k;const r=Lt(),h=kt(),o=Mt(),c=o.defaultQueryOptions(e);(N=(l=o.getDefaultOptions().queries)==null?void 0:l._experimental_beforeQuery)==null||N.call(l,c),c._optimisticResults=r?"isRestoring":"optimistic",zt(c),Bt(c,h),Ht(h);const w=!o.getQueryCache().get(c.queryHash),[p]=I.useState(()=>new t(o,c)),v=p.getOptimisticResult(c),L=!r&&e.subscribed!==!1;if(I.useSyncExternalStore(I.useCallback(m=>{const V=L?p.subscribe(St.batchCalls(m)):$;return p.updateResult(),V},[p,L]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),I.useEffect(()=>{p.setOptions(c)},[c,p]),Wt(c,v))throw Rt(c,p,h);if(jt({result:v,errorResetBoundary:h,throwOnError:c.throwOnError,query:o.getQueryCache().get(c.queryHash),suspense:c.suspense}))throw v.error;if((A=(f=o.getDefaultOptions().queries)==null?void 0:f._experimental_afterQuery)==null||A.call(f,c,v),c.experimental_prefetchInRender&&!tt&&Vt(v,r)){const m=w?Rt(c,p,h):(k=o.getQueryCache().get(c.queryHash))==null?void 0:k.promise;m==null||m.catch($).finally(()=>{p.updateResult()})}return c.notifyOnChangeProps?v:p.trackResult(v)}function qt(e,t){return Kt(e,Ft)}function Yt(e,t,s){return qt({queryKey:e,placeholderData:xt,...s,queryFn:async()=>{try{return(await _t.request(t)).data}catch(r){throw Ut(r)}}})}export{qt as a,Yt as u};
|
package/src/web/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no" />
|
|
6
6
|
<meta name="format-detection" content="telephone=no" />
|
|
7
7
|
<title>cc-gw 控制台</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-UV1Qa96f.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-CsJ3GRy4.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body class="bg-slate-50 text-slate-900 dark:bg-slate-900 dark:text-slate-50">
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{c as j,u as g,b as v,r as i,j as e,e as d,a5 as N}from"./index-DSWEYKFg.js";import{u as y}from"./useApiQuery-CDChhTqt.js";import{P as E}from"./PageHeader-CArgoeOl.js";import{P as n}from"./PageSection-B9KNzbSh.js";import{C as m,a as p}from"./card-Hot3HWFO.js";import{I}from"./info-C3Uvuy3w.js";import{R as T}from"./refresh-cw-Cm_OQO9a.js";/**
|
|
2
|
-
* @license lucide-react v0.344.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const k=j("Sparkles",[["path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z",key:"17u4zn"}],["path",{d:"M5 3v4",key:"bklmnn"}],["path",{d:"M19 17v4",key:"iiml17"}],["path",{d:"M3 5h4",key:"nem4j1"}],["path",{d:"M17 19h4",key:"lbex7p"}]]),_="0.7.5",w={version:_},L={VITE_BUILD_TIME:"2025-12-06T01:46:57.956Z",VITE_NODE_VERSION:"v22.16.0"};function u({items:t}){return t.length===0?null:e.jsx("dl",{className:"grid gap-4 sm:grid-cols-2",children:t.map(a=>e.jsx(m,{children:e.jsxs(p,{className:"pt-4",children:[e.jsx("dt",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a.label}),e.jsx("dd",{className:"mt-1 text-sm font-semibold",children:a.value}),a.hint&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a.hint})]})},a.label))})}function D(){const{t}=g(),{pushToast:a}=v(),s=y(["status","gateway"],{url:"/api/status",method:"GET"},{staleTime:6e4});i.useEffect(()=>{s.isError&&s.error&&a({title:t("about.toast.statusError.title"),description:s.error.message,variant:"error"})},[s.isError,s.error,a,t]);const o=w.version,r=i.useMemo(()=>{const c=L,b=c.VITE_BUILD_TIME,f=c.VITE_NODE_VERSION;return{buildTime:b,nodeVersion:f}},[]),x=i.useMemo(()=>[{label:t("about.app.labels.name"),value:e.jsx("span",{className:"font-mono",children:"cc-gw"})},{label:t("about.app.labels.version"),value:e.jsxs("span",{className:"font-mono text-primary",children:["v",o]})},{label:t("about.app.labels.buildTime"),value:r.buildTime,hint:t("about.app.hint.buildTime")},{label:t("about.app.labels.node"),value:e.jsx("span",{className:"font-mono",children:r.nodeVersion})}],[o,r.buildTime,r.nodeVersion,t]),l=i.useMemo(()=>s.data?[{label:t("about.status.labels.host"),value:s.data.host??"127.0.0.1"},{label:t("about.status.labels.port"),value:s.data.port.toLocaleString()},{label:t("about.status.labels.providers"),value:s.data.providers.toLocaleString()},{label:t("about.status.labels.active"),value:(s.data.activeRequests??0).toLocaleString(),hint:t("about.status.hint.active")}]:[],[s.data,t]),h=()=>{a({title:t("about.toast.updatesPlanned"),variant:"info"})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(E,{icon:e.jsx(I,{className:"h-5 w-5","aria-hidden":"true"}),title:t("about.title"),description:t("about.description"),badge:`v${o}`,actions:e.jsxs(d,{onClick:h,children:[e.jsx(k,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),t("about.support.actions.checkUpdates")]})}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(n,{title:t("about.app.title"),description:t("about.app.subtitle"),children:e.jsx(u,{items:x})}),e.jsx(n,{title:t("about.status.title"),description:t("about.status.subtitle"),actions:e.jsxs(d,{variant:"outline",size:"sm",onClick:()=>s.refetch(),disabled:s.isFetching,children:[e.jsx(T,{className:`mr-2 h-4 w-4 ${s.isFetching?"animate-spin":""}`,"aria-hidden":"true"}),s.isFetching?t("common.actions.refreshing"):t("common.actions.refresh")]}),children:s.isLoading?e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center gap-2 text-center",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-primary border-t-transparent"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("about.status.loading")})]}):l.length>0?e.jsx(u,{items:l}):e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center gap-1 rounded-lg border border-dashed p-6 text-center",children:[e.jsx("p",{className:"text-sm font-medium",children:t("about.status.empty")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("common.actions.refresh")})]})})]}),e.jsx(n,{title:t("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-medium text-primary",children:t("about.support.subtitle")}),e.jsx("span",{children:t("about.support.description")})]}),children:e.jsx(m,{children:e.jsxs(p,{className:"flex flex-col gap-4 pt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10 text-primary",children:e.jsx(N,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"flex-1 text-sm text-muted-foreground",children:t("about.support.tip")})]}),e.jsx("code",{className:"inline-flex self-start rounded-md bg-muted px-3 py-1.5 text-xs font-medium",children:"~/.cc-gw/config.json"})]})})})]})}export{D as default};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{c as D,r as c,j as e,a as $,u as Z,b as de,L as pe,e as o,K as me,v as ue,d as K}from"./index-DSWEYKFg.js";import{E as ye}from"./index-DgZMz9ou.js";import{u as k}from"./useApiQuery-CDChhTqt.js";import{P as xe,B as q}from"./PageHeader-CArgoeOl.js";import{P as z}from"./PageSection-B9KNzbSh.js";import{I as he}from"./input-CSRYqyMm.js";import{L as I}from"./label-sxZdAo5j.js";import{C as T,a as S}from"./card-Hot3HWFO.js";import{P as ge,D as W,a as H,b as V,c as G,d as fe,e as Q}from"./dialog-DOFVjgLV.js";import{C as U}from"./copy-DXxd_I6B.js";/**
|
|
2
|
-
* @license lucide-react v0.344.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const je=D("EyeOff",[["path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24",key:"1jxqfv"}],["path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68",key:"9wicm4"}],["path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61",key:"1jreej"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);/**
|
|
7
|
-
* @license lucide-react v0.344.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const ve=D("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"}]]);/**
|
|
12
|
-
* @license lucide-react v0.344.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Ke=D("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]),_=c.forwardRef(({className:a,...r},y)=>e.jsx("textarea",{className:$("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",a),ref:y,...r}));_.displayName="Textarea";const Ne=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function Ae(){const{t:a}=Z(),{pushToast:r}=de(),[y,m]=c.useState(!1),[x,h]=c.useState(""),[L,N]=c.useState(""),[l,b]=c.useState(null),[J,E]=c.useState(null),[p,X]=c.useState(7),[M,A]=c.useState(new Map),[Y,O]=c.useState(null),g=k(["api-keys"],{url:"/api/keys",method:"GET"}),j=k(["api-keys","overview",p],{url:"/api/stats/api-keys/overview",method:"GET",params:{days:p}}),f=k(["api-keys","usage",p],{url:"/api/stats/api-keys/usage",method:"GET",params:{days:p,limit:10}}),w=g.data??[],u=j.data,d=f.data??[],ee=w.some(s=>s.isWildcard),ae=u?u.totalKeys.toLocaleString():"-",se=u?u.enabledKeys.toLocaleString():"-",te=u?u.activeKeys.toLocaleString():"-",P=async()=>{var s,t;if(!x.trim()){r({title:a("apiKeys.errors.nameRequired"),variant:"error"});return}try{const i=await K.post("/api/keys",{name:x.trim(),description:L.trim()||void 0});b(i.data),m(!1),h(""),N(""),g.refetch(),j.refetch(),f.refetch(),r({title:a("apiKeys.toast.keyCreated"),variant:"success"})}catch(i){r({title:a("apiKeys.toast.createFailure",{message:((t=(s=i.response)==null?void 0:s.data)==null?void 0:t.error)||i.message}),variant:"error"})}},ie=async(s,t)=>{var i,n;try{await K.patch(`/api/keys/${s}`,{enabled:!t}),g.refetch(),j.refetch(),r({title:a("apiKeys.toast.keyUpdated"),variant:"success"})}catch(v){r({title:a("apiKeys.toast.updateFailure",{message:((n=(i=v.response)==null?void 0:i.data)==null?void 0:n.error)||v.message}),variant:"error"})}},re=async s=>{var t,i;if(confirm(a("apiKeys.confirmDelete"))){E(s);try{await K.delete(`/api/keys/${s}`),g.refetch(),j.refetch(),f.refetch(),r({title:a("apiKeys.toast.keyDeleted"),variant:"success"})}catch(n){r({title:a("apiKeys.toast.deleteFailure",{message:((i=(t=n.response)==null?void 0:t.data)==null?void 0:i.error)||n.message}),variant:"error"})}finally{E(null)}}},ne=async s=>{var t,i;if(!M.has(s)){O(s);try{const n=await K.get(`/api/keys/${s}/reveal`);A(v=>new Map(v).set(s,n.data.key))}catch(n){r({title:a("apiKeys.toast.revealFailure"),description:((i=(t=n.response)==null?void 0:t.data)==null?void 0:i.error)||n.message,variant:"error"})}finally{O(null)}}},le=s=>{A(t=>{const i=new Map(t);return i.delete(s),i})},R=async s=>{try{await navigator.clipboard.writeText(s),r({title:a("apiKeys.toast.keyCopied"),variant:"success"})}catch(t){r({title:a("apiKeys.toast.copyFailure"),description:t instanceof Error?t.message:a("common.unknownError"),variant:"error"})}},F=s=>s?new Date(s).toLocaleString():a("common.noData"),ce=c.useMemo(()=>{const s=d.map(t=>t.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.requestsSeries"),type:"bar",data:d.map(t=>t.requests),itemStyle:{color:"hsl(var(--primary))"}}]}},[d,a]),oe=c.useMemo(()=>{const s=d.map(t=>t.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[a("apiKeys.analytics.tokens.input"),a("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:d.map(t=>t.inputTokens)},{name:a("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:d.map(t=>t.outputTokens)}]}},[d,a]);return g.isLoading?e.jsx(pe,{}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(xe,{icon:e.jsx(me,{className:"h-5 w-5","aria-hidden":"true"}),title:a("apiKeys.title"),description:a("apiKeys.description"),actions:e.jsxs(o,{onClick:()=>m(!0),children:[e.jsx(ge,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("apiKeys.createNew")]})}),e.jsx(z,{title:a("apiKeys.analytics.title"),description:a("apiKeys.analytics.description",{days:p}),actions:e.jsx("div",{className:"flex items-center gap-1 rounded-lg border p-1",children:Ne.map(s=>{const t=p===s.value;return e.jsx("button",{type:"button",onClick:()=>X(s.value),className:$("inline-flex h-7 items-center rounded-md px-3 text-xs font-medium transition-colors",t?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"),children:a(s.labelKey)},s.value)})}),children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(C,{label:a("apiKeys.analytics.cards.total"),value:ae}),e.jsx(C,{label:a("apiKeys.analytics.cards.enabled"),value:se}),e.jsx(C,{label:a("apiKeys.analytics.cards.active",{days:p}),value:te})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(B,{title:a("apiKeys.analytics.charts.requests"),loading:f.isLoading,empty:d.length===0,emptyText:a("apiKeys.analytics.empty"),option:ce}),e.jsx(B,{title:a("apiKeys.analytics.charts.tokens"),loading:f.isLoading,empty:d.length===0,emptyText:a("apiKeys.analytics.empty"),option:oe})]})]})}),e.jsx(z,{title:a("apiKeys.list.title"),description:ee?a("apiKeys.wildcardHint"):void 0,children:w.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-lg border border-dashed",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:a("apiKeys.list.empty")})}):e.jsx("div",{className:"grid gap-4",children:w.map(s=>{const t=(s.totalInputTokens+s.totalOutputTokens).toLocaleString(),i=M.get(s.id),n=Y===s.id;return e.jsx(T,{children:e.jsx(S,{className:"space-y-4 pt-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold",children:s.name}),s.isWildcard&&e.jsx(q,{variant:"secondary",children:a("apiKeys.wildcard")}),e.jsx(q,{variant:s.enabled?"default":"outline",children:s.enabled?a("apiKeys.status.enabled"):a("apiKeys.status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"rounded-md bg-muted px-3 py-1.5 font-mono text-sm",children:s.isWildcard?a("apiKeys.wildcard"):i??s.maskedKey??"********"}),!s.isWildcard&&e.jsx("div",{className:"flex items-center gap-1",children:i?e.jsxs(e.Fragment,{children:[e.jsx(o,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>void R(i),"aria-label":a("common.actions.copy"),title:a("common.actions.copy"),children:e.jsx(U,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(o,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>le(s.id),"aria-label":a("apiKeys.actions.hide"),title:a("apiKeys.actions.hide"),children:e.jsx(je,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx(o,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>void ne(s.id),disabled:n,"aria-label":a("apiKeys.actions.reveal"),title:a("apiKeys.actions.reveal"),children:e.jsx(ve,{className:"h-4 w-4","aria-hidden":"true"})})})]}),s.isWildcard?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("apiKeys.wildcardHint")}):s.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:s.description}):null,e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a("apiKeys.created")}),e.jsx("p",{className:"font-medium",children:F(s.createdAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a("apiKeys.lastUsed")}),e.jsx("p",{className:"font-medium",children:F(s.lastUsedAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a("apiKeys.requestCount")}),e.jsx("p",{className:"font-medium",children:s.requestCount.toLocaleString()})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a("apiKeys.totalTokens")}),e.jsx("p",{className:"font-medium",children:t})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{variant:s.enabled?"outline":"default",size:"sm",onClick:()=>ie(s.id,s.enabled),children:s.enabled?a("apiKeys.actions.disable"):a("apiKeys.actions.enable")}),!s.isWildcard&&e.jsx(o,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>re(s.id),disabled:J===s.id,"aria-label":a("apiKeys.actions.delete"),children:e.jsx(Ke,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})},s.id)})})}),e.jsx(W,{open:y,onOpenChange:m,children:e.jsxs(H,{children:[e.jsxs(V,{children:[e.jsx(G,{children:a("apiKeys.createNew")}),e.jsx(fe,{children:a("apiKeys.createDescription")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(I,{htmlFor:"keyName",children:[a("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(he,{id:"keyName",value:x,onChange:s=>h(s.target.value),placeholder:a("apiKeys.keyNamePlaceholder"),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),P())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"keyDescription",children:a("apiKeys.descriptionLabel")}),e.jsx(_,{id:"keyDescription",value:L,onChange:s=>N(s.target.value),placeholder:a("apiKeys.keyDescriptionPlaceholder"),rows:3})]})]}),e.jsxs(Q,{children:[e.jsx(o,{variant:"outline",onClick:()=>{m(!1),h(""),N("")},children:a("common.actions.cancel")}),e.jsx(o,{onClick:()=>void P(),children:a("apiKeys.createAction")})]})]})}),e.jsx(W,{open:!!l,onOpenChange:()=>b(null),children:e.jsxs(H,{children:[e.jsx(V,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600",children:e.jsx(ue,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx(G,{children:a("apiKeys.keyCreated")})]})}),e.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:a("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-md bg-muted px-4 py-3 font-mono text-sm",children:l==null?void 0:l.key}),(l==null?void 0:l.description)&&e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:l.description}),e.jsxs(Q,{children:[e.jsxs(o,{onClick:()=>void R((l==null?void 0:l.key)??""),children:[e.jsx(U,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("common.actions.copy")]}),e.jsx(o,{variant:"outline",onClick:()=>b(null),children:a("common.actions.close")})]})]})})]})}function C({label:a,value:r}){return e.jsx(T,{children:e.jsxs(S,{className:"pt-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a}),e.jsx("p",{className:"mt-2 text-2xl font-semibold",children:r})]})})}function B({title:a,option:r,loading:y,empty:m,emptyText:x}){const{t:h}=Z();return e.jsx(T,{children:e.jsxs(S,{className:"space-y-4 pt-4",children:[e.jsx("h3",{className:"text-base font-semibold",children:a}),y?e.jsx("div",{className:"flex h-[280px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:h("common.loadingShort")})}):m?e.jsx("div",{className:"flex h-[280px] items-center justify-center rounded-lg border border-dashed",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:x})}):e.jsx(ye,{option:r,style:{height:280},notMerge:!0,lazyUpdate:!0})]})})}export{Ae as default};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{c as O,r as d,j as e,a as f,u as P,b as re,d as oe,t as de,L as ne,B as D,e as ie}from"./index-DSWEYKFg.js";import{E as le}from"./index-DgZMz9ou.js";import{P as ce,B as S}from"./PageHeader-CArgoeOl.js";import{P as J}from"./PageSection-B9KNzbSh.js";import{u as k}from"./useApiQuery-CDChhTqt.js";import{C as G,a as Q}from"./card-Hot3HWFO.js";import{S as me,a as he,b as ue,c as xe,d as I}from"./select-qZIYkE-k.js";/**
|
|
2
|
-
* @license lucide-react v0.344.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const $=O("Activity",[["path",{d:"M22 12h-4l-3 9L9 3l-3 9H2",key:"d5dnw9"}]]);/**
|
|
7
|
-
* @license lucide-react v0.344.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const pe=O("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
|
|
12
|
-
* @license lucide-react v0.344.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const be=O("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]),F=d.forwardRef(({className:t,...s},a)=>e.jsx("div",{className:"relative w-full overflow-auto rounded-lg",children:e.jsx("table",{ref:a,className:f("w-full caption-bottom text-sm border-collapse",t),...s})}));F.displayName="Table";const H=d.forwardRef(({className:t,...s},a)=>e.jsx("thead",{ref:a,className:f("bg-muted/40 [&_tr]:border-b [&_tr]:border-border/60",t),...s}));H.displayName="TableHeader";const _=d.forwardRef(({className:t,...s},a)=>e.jsx("tbody",{ref:a,className:f("[&_tr:last-child]:border-0",t),...s}));_.displayName="TableBody";const ge=d.forwardRef(({className:t,...s},a)=>e.jsx("tfoot",{ref:a,className:f("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...s}));ge.displayName="TableFooter";const A=d.forwardRef(({className:t,...s},a)=>e.jsx("tr",{ref:a,className:f("border-b border-border/50 transition-all duration-150","hover:bg-primary/5 data-[state=selected]:bg-primary/10","group",t),...s}));A.displayName="TableRow";const h=d.forwardRef(({className:t,...s},a)=>e.jsx("th",{ref:a,className:f("h-11 px-4 text-left align-middle text-xs font-semibold uppercase tracking-wider text-muted-foreground/80","[&:has([role=checkbox])]:pr-0",t),...s}));h.displayName="TableHead";const u=d.forwardRef(({className:t,...s},a)=>e.jsx("td",{ref:a,className:f("px-4 py-3 align-middle text-sm","[&:has([role=checkbox])]:pr-0","group-hover:text-foreground transition-colors",t),...s}));u.displayName="TableCell";const fe=d.forwardRef(({className:t,...s},a)=>e.jsx("caption",{ref:a,className:f("mt-4 text-sm text-muted-foreground",t),...s}));fe.displayName="TableCaption";function M(t,s,a){return t==null?"-":`${t.toLocaleString(void 0,a)} ${s}`}function K(t){if(t==null)return"-";if(t<1024)return`${t} B`;const s=["KB","MB","GB","TB"];let a=t/1024,r=0;for(;a>=1024&&r<s.length-1;)a/=1024,r+=1;return`${a.toFixed(a>=100?0:a>=10?1:2)} ${s[r]}`}function Le(){var U;const{t}=P(),{pushToast:s}=re(),[a,r]=d.useState("all"),[n,y]=d.useState(!1),x=a==="all"?void 0:a,N=k(["stats","overview",a],{url:"/api/stats/overview",method:"GET",params:x?{endpoint:x}:void 0}),T=k(["stats","daily",14,a],{url:"/api/stats/daily",method:"GET",params:{days:14,...x?{endpoint:x}:{}}}),g=k(["stats","model",7,6,a],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...x?{endpoint:x}:{}}}),E=k(["status"],{url:"/api/status",method:"GET"}),j=k(["db","info"],{url:"/api/db/info",method:"GET"}),z=j.refetch??(async()=>{}),C=k(["logs","recent",a],{url:"/api/logs",method:"GET",params:{limit:5,...x?{endpoint:x}:{}}},{refetchInterval:3e4});d.useEffect(()=>{N.isError&&N.error&&s({title:t("dashboard.toast.overviewError"),description:N.error.message,variant:"error"})},[N.isError,N.error,s,t]),d.useEffect(()=>{T.isError&&T.error&&s({title:t("dashboard.toast.dailyError"),description:T.error.message,variant:"error"})},[T.isError,T.error,s,t]),d.useEffect(()=>{g.isError&&g.error&&s({title:t("dashboard.toast.modelError"),description:g.error.message,variant:"error"})},[g.isError,g.error,s,t]),d.useEffect(()=>{E.isError&&E.error&&s({title:t("dashboard.toast.statusError"),description:E.error.message,variant:"error"})},[E.isError,E.error,s,t]),d.useEffect(()=>{j.isError&&j.error&&s({title:t("dashboard.toast.dbError"),description:j.error.message,variant:"error"})},[j.isError,j.error,s,t]);const W=d.useCallback(async()=>{if(!n){y(!0);try{await oe.post("/api/db/compact"),await z(),s({title:t("dashboard.toast.compactSuccess.title"),description:t("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(i){const m=de(i);s({title:t("dashboard.toast.compactError.title"),description:m.message,variant:"error"})}finally{y(!1)}}},[n,s,z,t]);d.useEffect(()=>{C.isError&&C.error&&s({title:t("dashboard.toast.recentError"),description:C.error.message,variant:"error"})},[C.isError,C.error,s,t]);const o=N.data,v=T.data??[],l=g.data??[],L=E.data,R=j.data,X=((U=C.data)==null?void 0:U.items)??[],Y=R?K(R.totalBytes??R.sizeBytes):"-",Z=R?K(R.memoryRssBytes??0):"-",ee=d.useMemo(()=>{const i=v.map(b=>b.date),m=t("dashboard.charts.barRequests"),c=t("dashboard.charts.lineInput"),B=t("dashboard.charts.lineOutput"),p=t("dashboard.charts.lineCacheRead"),V=t("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis"},legend:{data:[m,c,B,p,V]},grid:{left:60,right:40,top:60,bottom:60},xAxis:{type:"category",data:i},yAxis:{type:"value"},series:[{name:m,type:"bar",data:v.map(b=>b.requestCount),itemStyle:{color:"hsl(var(--primary))",borderRadius:[4,4,0,0]}},{name:c,type:"line",data:v.map(b=>b.inputTokens),smooth:!0,itemStyle:{color:"#10b981"},lineStyle:{width:2}},{name:B,type:"line",data:v.map(b=>b.outputTokens),smooth:!0,itemStyle:{color:"#f59e0b"},lineStyle:{width:2}},{name:p,type:"line",data:v.map(b=>b.cacheReadTokens),smooth:!0,itemStyle:{color:"#8b5cf6"},lineStyle:{width:2}},{name:V,type:"line",data:v.map(b=>b.cacheCreationTokens),smooth:!0,itemStyle:{color:"#ec4899"},lineStyle:{width:2}}]}},[v,t]),te=d.useMemo(()=>{const i=l.map(p=>`${p.provider}/${p.model}`),m=t("dashboard.charts.barRequests"),c=t("dashboard.charts.lineInput"),B=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[m,c,B]},grid:{left:80,right:60,top:60,bottom:100},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:[{type:"value",name:m},{type:"value",name:t("dashboard.charts.axisTokens"),position:"right"}],series:[{name:m,type:"bar",data:l.map(p=>p.requests),itemStyle:{color:"#6366f1",borderRadius:[4,4,0,0]}},{name:c,type:"line",yAxisIndex:1,smooth:!0,data:l.map(p=>p.inputTokens??0),itemStyle:{color:"#10b981"}},{name:B,type:"line",yAxisIndex:1,smooth:!0,data:l.map(p=>p.outputTokens??0),itemStyle:{color:"#f59e0b"}}]}},[l,t]),ae=d.useMemo(()=>{const i=l.map(c=>`${c.provider}/${c.model}`),m=t("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis"},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:{type:"value",name:t("dashboard.charts.ttftAxis")},series:[{name:m,type:"bar",data:l.map(c=>c.avgTtftMs??0),itemStyle:{color:"hsl(var(--primary))",borderRadius:[4,4,0,0]}}]}},[l,t]),se=d.useMemo(()=>{const i=l.map(c=>`${c.provider}/${c.model}`),m=t("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis"},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:{type:"value",name:t("dashboard.charts.tpotAxis")},series:[{name:m,type:"bar",data:l.map(c=>c.avgTpotMs??0),itemStyle:{color:"#f59e0b",borderRadius:[4,4,0,0]}}]}},[l,t]);return N.isPending||E.isPending||j.isPending?e.jsx(ne,{}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ce,{icon:e.jsx(D,{className:"h-5 w-5","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description"),actions:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:t("dashboard.filters.endpoint")}),e.jsxs(me,{value:a,onValueChange:i=>r(i),children:[e.jsx(he,{className:"w-[140px]",children:e.jsx(ue,{})}),e.jsxs(xe,{children:[e.jsx(I,{value:"all",children:t("dashboard.filters.endpointAll")}),e.jsx(I,{value:"anthropic",children:t("dashboard.filters.endpointAnthropic")}),e.jsx(I,{value:"openai",children:t("dashboard.filters.endpointOpenAI")})]})]})]})}),L&&e.jsx(G,{children:e.jsxs(Q,{className:"flex flex-wrap items-center gap-3 pt-4",children:[e.jsx(S,{variant:"default",className:"bg-emerald-500",children:t("dashboard.status.listening",{host:L.host??"0.0.0.0",port:L.port})}),e.jsx(S,{variant:"secondary",children:t("dashboard.status.providers",{value:L.providers.toLocaleString()})}),e.jsx(S,{variant:"secondary",children:t("dashboard.status.todayRequests",{value:((o==null?void 0:o.today.requests)??0).toLocaleString()})}),e.jsx(S,{variant:"outline",children:t("dashboard.status.active",{value:(L.activeRequests??0).toLocaleString()})}),e.jsx(S,{variant:"outline",children:t("dashboard.status.dbSize",{value:Y})}),e.jsx(S,{variant:"outline",children:t("dashboard.status.memory",{value:Z})}),e.jsx(ie,{variant:"outline",size:"sm",onClick:W,disabled:n,children:t(n?"dashboard.actions.compacting":"dashboard.actions.compact")})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(w,{icon:e.jsx($,{className:"h-5 w-5"}),title:t("dashboard.cards.todayRequests"),value:(o==null?void 0:o.today.requests)??0,suffix:t("common.units.request"),color:"blue"}),e.jsx(w,{icon:e.jsx(be,{className:"h-5 w-5"}),title:t("dashboard.cards.todayInput"),value:(o==null?void 0:o.today.inputTokens)??0,suffix:t("common.units.token"),color:"emerald"}),e.jsx(w,{icon:e.jsx($,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheRead"),value:(o==null?void 0:o.today.cacheReadTokens)??0,suffix:t("common.units.token"),color:"violet"}),e.jsx(w,{icon:e.jsx($,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheCreation"),value:(o==null?void 0:o.today.cacheCreationTokens)??0,suffix:t("common.units.token"),color:"rose"}),e.jsx(w,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayOutput"),value:(o==null?void 0:o.today.outputTokens)??0,suffix:t("common.units.token"),color:"amber"}),e.jsx(w,{icon:e.jsx(pe,{className:"h-5 w-5"}),title:t("dashboard.cards.avgLatency"),value:(o==null?void 0:o.today.avgLatencyMs)??0,suffix:t("common.units.ms"),color:"cyan"})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(q,{title:t("dashboard.charts.requestsTitle"),description:t("dashboard.charts.requestsDesc"),loading:T.isPending,option:ee,empty:!v.length,emptyText:t("dashboard.charts.empty")}),e.jsx(q,{title:t("dashboard.charts.modelTitle"),description:t("dashboard.charts.modelDesc"),loading:g.isPending,option:te,empty:!l.length,emptyText:t("dashboard.charts.empty")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(q,{title:t("dashboard.charts.ttftTitle"),description:t("dashboard.charts.ttftDesc"),loading:g.isPending,option:ae,empty:!l.some(i=>i.avgTtftMs!=null&&i.avgTtftMs>0),emptyText:t("dashboard.charts.ttftEmpty")}),e.jsx(q,{title:t("dashboard.charts.tpotTitle"),description:t("dashboard.charts.tpotDesc"),loading:g.isPending,option:se,empty:!l.some(i=>i.avgTpotMs!=null&&i.avgTpotMs>0),emptyText:t("dashboard.charts.tpotEmpty")})]}),e.jsx(je,{models:l,loading:g.isPending}),e.jsx(ve,{loading:C.isPending,records:X})]})}const ye={blue:{gradient:"bg-gradient-to-br from-blue-500/10 via-blue-500/5 to-transparent",iconBg:"bg-blue-500/15",iconColor:"text-blue-600 dark:text-blue-400"},emerald:{gradient:"bg-gradient-to-br from-emerald-500/10 via-emerald-500/5 to-transparent",iconBg:"bg-emerald-500/15",iconColor:"text-emerald-600 dark:text-emerald-400"},amber:{gradient:"bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent",iconBg:"bg-amber-500/15",iconColor:"text-amber-600 dark:text-amber-400"},violet:{gradient:"bg-gradient-to-br from-violet-500/10 via-violet-500/5 to-transparent",iconBg:"bg-violet-500/15",iconColor:"text-violet-600 dark:text-violet-400"},rose:{gradient:"bg-gradient-to-br from-rose-500/10 via-rose-500/5 to-transparent",iconBg:"bg-rose-500/15",iconColor:"text-rose-600 dark:text-rose-400"},cyan:{gradient:"bg-gradient-to-br from-cyan-500/10 via-cyan-500/5 to-transparent",iconBg:"bg-cyan-500/15",iconColor:"text-cyan-600 dark:text-cyan-400"}};function w({icon:t,title:s,value:a,suffix:r,color:n="blue"}){const y=ye[n];return e.jsx(G,{variant:"interactive",className:f("overflow-hidden",y.gradient),children:e.jsxs(Q,{className:"pt-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:s}),t&&e.jsx("div",{className:f("flex h-10 w-10 items-center justify-center rounded-xl",y.iconBg,y.iconColor),children:t})]}),e.jsxs("p",{className:"text-3xl font-bold tracking-tight",children:[a.toLocaleString(),r&&e.jsx("span",{className:"ml-1.5 text-sm font-medium text-muted-foreground",children:r})]})]})})}function q({title:t,description:s,option:a,loading:r,empty:n,emptyText:y}){const{t:x}=P();return e.jsx(G,{children:e.jsxs(Q,{className:"space-y-4 pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold",children:t}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]}),r?e.jsx("div",{className:"flex h-[320px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:x("common.loadingShort")})}):n?e.jsxs("div",{className:"flex h-[320px] flex-col items-center justify-center rounded-lg border border-dashed",children:[e.jsx(D,{className:"mb-2 h-10 w-10 text-muted-foreground/50"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:y??x("dashboard.charts.empty")})]}):e.jsx(le,{option:a,style:{height:320},notMerge:!0,lazyUpdate:!0})]})})}function je({models:t,loading:s}){const{t:a}=P(),r=t.length>0;return e.jsx(J,{title:a("dashboard.modelTable.title"),description:a("dashboard.modelTable.description"),children:s?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:a("common.loadingShort")})}):r?e.jsx("div",{className:"max-h-80 overflow-auto rounded-md border",children:e.jsxs(F,{children:[e.jsx(H,{children:e.jsxs(A,{children:[e.jsx(h,{children:a("dashboard.modelTable.columns.model")}),e.jsx(h,{className:"text-right",children:a("dashboard.modelTable.columns.requests")}),e.jsx(h,{className:"text-right",children:a("dashboard.modelTable.columns.latency")}),e.jsx(h,{className:"text-right",children:a("dashboard.modelTable.columns.ttft")}),e.jsx(h,{className:"text-right",children:a("dashboard.modelTable.columns.tpot")})]})}),e.jsx(_,{children:t.map(n=>e.jsxs(A,{children:[e.jsx(u,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:n.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n.model})]})}),e.jsx(u,{className:"text-right font-medium",children:n.requests.toLocaleString()}),e.jsx(u,{className:"text-right",children:M(n.avgLatencyMs,a("common.units.ms"))}),e.jsx(u,{className:"text-right",children:M(n.avgTtftMs,a("common.units.ms"))}),e.jsx(u,{className:"text-right",children:M(n.avgTpotMs,a("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${n.provider}/${n.model}`))})]})}):e.jsx("div",{className:"flex h-32 items-center justify-center rounded-lg border border-dashed",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:a("dashboard.modelTable.empty")})})})}function ve({records:t,loading:s}){const{t:a}=P();return e.jsx(J,{title:a("dashboard.recent.title"),description:a("dashboard.recent.subtitle",{count:5}),children:s?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:a("dashboard.recent.loading")})}):t.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-lg border border-dashed",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:a("dashboard.recent.empty")})}):e.jsx("div",{className:"max-h-80 overflow-auto rounded-md border",children:e.jsxs(F,{children:[e.jsx(H,{children:e.jsxs(A,{children:[e.jsx(h,{children:a("dashboard.recent.columns.time")}),e.jsx(h,{children:a("dashboard.recent.columns.endpoint")}),e.jsx(h,{children:a("dashboard.recent.columns.provider")}),e.jsx(h,{children:a("dashboard.recent.columns.route")}),e.jsx(h,{className:"text-right",children:a("dashboard.recent.columns.latency")}),e.jsx(h,{children:a("dashboard.recent.columns.status")})]})}),e.jsx(_,{children:t.map(r=>e.jsxs(A,{children:[e.jsx(u,{className:"text-xs",children:new Date(r.timestamp).toLocaleString()}),e.jsx(u,{className:"text-xs text-muted-foreground",children:r.endpoint==="anthropic"?a("logs.table.endpointAnthropic"):r.endpoint==="openai"?a("logs.table.endpointOpenAI"):r.endpoint}),e.jsx(u,{className:"font-medium",children:r.provider}),e.jsx(u,{children:e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx("span",{children:r.client_model??a("dashboard.recent.routePlaceholder")}),e.jsx("span",{children:"→"}),e.jsx("span",{className:"font-medium text-foreground",children:r.model})]})}),e.jsx(u,{className:"text-right font-medium",children:M(r.latency_ms,a("common.units.ms"))}),e.jsx(u,{children:e.jsx(S,{variant:r.error?"destructive":"default",children:(r.status_code??(r.error?500:200)).toString()})})]},r.id))})]})})})}export{Le as default};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{c as ye,u as U,b as de,r as n,d as Ne,t as ve,j as e,e as k,a as L,F as be,f as we,X as ke,L as _e}from"./index-DSWEYKFg.js";import{u as q}from"./useApiQuery-CDChhTqt.js";import{P as Se,B as ce}from"./PageHeader-CArgoeOl.js";import{I as H}from"./input-CSRYqyMm.js";import{L as S}from"./label-sxZdAo5j.js";import{C as ae,a as ie}from"./card-Hot3HWFO.js";import{S as A,a as M,b as z,c as O,d as w}from"./select-qZIYkE-k.js";import{R as Ee}from"./refresh-cw-Cm_OQO9a.js";/**
|
|
2
|
-
* @license lucide-react v0.344.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const Te=ye("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]),re=[20,50,100];function ne(s,r=!1){if(!s)return;const o=r?`${s}T23:59:59.999`:`${s}T00:00:00.000`,f=Date.parse(o);return Number.isFinite(f)?f:void 0}function me(s){const r=new Date(s);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function _(s){return s==null?"-":s.toLocaleString()}function E(s,r){const o=_(s);return o==="-"?"-":`${o} ${r}`}function Ce(s){return s?"true":"false"}function oe(s,r){if(!s||s.trim().length===0)return r;try{const o=JSON.parse(s);return JSON.stringify(o,null,2)}catch{return s}}function qe(){var se,te;const{t:s}=U(),{pushToast:r}=de(),[o,f]=n.useState("all"),[j,t]=n.useState("all"),[d,y]=n.useState(""),[m,v]=n.useState("all"),[l,h]=n.useState(""),[i,x]=n.useState(""),[c,p]=n.useState(1),[N,I]=n.useState(re[0]),[F,Q]=n.useState(null),[xe,V]=n.useState(!1),[D,W]=n.useState([]),[K,J]=n.useState(!1);n.useEffect(()=>{p(1)},[o,j,d,m,l,i,N,D]);const P=n.useMemo(()=>{const a={limit:N,offset:(c-1)*N};o!=="all"&&(a.provider=o),j!=="all"&&(a.endpoint=j),d.trim().length>0&&(a.model=d.trim()),m!=="all"&&(a.status=m);const u=ne(l),$=ne(i,!0);return u!==void 0&&(a.from=u),$!==void 0&&(a.to=$),D.length>0&&(a.apiKeys=D.join(",")),a},[o,j,d,m,l,i,c,N,D]),g=q(["logs",P],{url:"/api/logs",method:"GET",params:P}),T=q(["providers","all"],{url:"/api/providers",method:"GET"}),X=q(["api-keys"],{url:"/api/keys",method:"GET"});n.useEffect(()=>{g.isError&&g.error&&r({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:g.error.message}),variant:"error"})},[g.isError,g.error,r,s]),n.useEffect(()=>{T.isError&&T.error&&r({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:T.error.message}),variant:"error"})},[T.isError,T.error,r,s]);const C=((se=g.data)==null?void 0:se.total)??0,b=C>0?Math.ceil(C/N):0,Y=((te=g.data)==null?void 0:te.items)??[];n.useEffect(()=>{b>0&&c>b&&p(b)},[b,c]);const B=T.data??[],Z=n.useMemo(()=>{const a=new Map;for(const u of B)u.id&&a.set(u.id,u.label??u.id);return a},[B]),G=X.data??[],ee=n.useMemo(()=>{const a=new Map;for(const u of G)a.set(u.id,u);return a},[G]),ue=()=>{f("all"),y(""),t("all"),v("all"),h(""),x(""),W([])},pe=n.useCallback(async()=>{if(!K){J(!0);try{const a=C>0?Math.min(C,5e3):1e3,u={...P,limit:a,offset:0},$=await Ne.post("/api/logs/export",u,{responseType:"blob"}),fe=new Blob([$.data],{type:"application/zip"}),je=new Date().toISOString().replace(/[:.]/g,"-"),le=URL.createObjectURL(fe),R=document.createElement("a");R.href=le,R.download=`cc-gw-logs-${je}.zip`,document.body.appendChild(R),R.click(),R.remove(),URL.revokeObjectURL(le),r({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(a){const u=ve(a);r({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:u.message}),variant:"error"})}finally{J(!1)}}},[K,r,P,s,C]),he=n.useCallback(a=>{Q(a),V(!0)},[]),ge=n.useCallback(()=>{V(!1),Q(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Se,{icon:e.jsx(be,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(k,{onClick:pe,disabled:K,children:[e.jsx(Te,{className:"mr-2 h-4 w-4"}),s(K?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:C.toLocaleString()})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>g.refetch(),disabled:g.isFetching,children:[e.jsx(Ee,{className:L("mr-2 h-4 w-4",g.isFetching&&"animate-spin")}),g.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(ae,{children:e.jsxs(ie,{className:"pt-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:s("logs.filtersTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:ue,children:s("common.actions.reset")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.provider")}),e.jsxs(A,{value:o,onValueChange:f,children:[e.jsx(M,{children:e.jsx(z,{})}),e.jsxs(O,{children:[e.jsx(w,{value:"all",children:s("logs.filters.providerAll")}),B.map(a=>e.jsx(w,{value:a.id,children:a.label??a.id},a.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.endpoint")}),e.jsxs(A,{value:j,onValueChange:a=>t(a),children:[e.jsx(M,{children:e.jsx(z,{})}),e.jsxs(O,{children:[e.jsx(w,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(w,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(w,{value:"openai",children:s("logs.filters.endpointOpenAI")})]})]})]}),e.jsx(Re,{className:"md:col-span-2",apiKeys:G,selected:D,disabled:X.isLoading,onChange:W}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.modelId")}),e.jsx(H,{value:d,onChange:a=>y(a.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.status")}),e.jsxs(A,{value:m,onValueChange:a=>v(a),children:[e.jsx(M,{children:e.jsx(z,{})}),e.jsxs(O,{children:[e.jsx(w,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(w,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(w,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.startDate")}),e.jsx(H,{type:"date",value:l,onChange:a=>h(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.endDate")}),e.jsx(H,{type:"date",value:i,onChange:a=>x(a.target.value)})]})]})]})}),e.jsx(ae,{children:e.jsxs(ie,{className:"p-0",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1200px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:g.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:s("logs.table.loading")})}):Y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:s("logs.table.empty")})}):Y.map((a,u)=>e.jsx(Le,{record:a,providerLabelMap:Z,apiKeyMap:ee,onSelect:he,isEven:u%2===0},a.id))})]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.perPage")}),e.jsxs(A,{value:N.toString(),onValueChange:a=>I(Number(a)),children:[e.jsx(M,{className:"w-[80px]",children:e.jsx(z,{})}),e.jsx(O,{children:re.map(a=>e.jsx(w,{value:a.toString(),children:a},a))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>p(a=>Math.max(a-1,1)),disabled:c<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:b===0?0:c,total:b})}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>p(a=>b===0?a:Math.min(a+1,b)),disabled:b===0||c>=b,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(De,{open:xe,logId:F,onClose:ge,providerLabelMap:Z,apiKeyMap:ee})]})}function Le({record:s,providerLabelMap:r,apiKeyMap:o,onSelect:f,isEven:j}){const{t}=U(),d=r.get(s.provider)??s.provider,y=s.endpoint||"-",m=!!s.error,v=s.status_code,l=s.client_model??t("logs.table.requestedModelFallback"),h=s.api_key_id!=null?o.get(s.api_key_id):void 0,i=s.api_key_id==null?t("logs.table.apiKeyUnknown"):h!=null&&h.isWildcard?t("apiKeys.wildcard"):h!=null&&h.name?h.name:s.api_key_name?s.api_key_name:t("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:L("transition-colors",j?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:"px-3 py-2 text-xs",children:me(s.timestamp)}),e.jsx("td",{className:"px-3 py-2 text-xs",children:y}),e.jsx("td",{className:"px-3 py-2 text-xs",children:e.jsx("div",{className:"max-w-[100px] truncate",title:d,children:d})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground",children:e.jsx("div",{className:"max-w-[120px] truncate",title:l,children:l})}),e.jsx("td",{className:"px-3 py-2 text-xs",children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground",children:e.jsx("div",{className:"max-w-[90px] truncate",title:i,children:i})}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.input_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.output_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:E(s.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:E(s.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:E(s.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx(ce,{variant:m?"destructive":"default",className:"text-xs",children:v??(m?500:200)})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground",children:e.jsx("div",{className:"max-w-[100px] truncate",title:s.error??"",children:s.error?s.error:"-"})}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx(k,{variant:"outline",size:"sm",onClick:()=>f(s.id),children:t("logs.actions.detail")})})]})}function De({open:s,logId:r,onClose:o,providerLabelMap:f,apiKeyMap:j}){var x,c;const{t}=U(),{pushToast:d}=de(),y=n.useRef(null),m=q(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:s&&r!==null,staleTime:3e4});n.useEffect(()=>{m.isError&&m.error&&d({title:t("logs.detail.loadError"),description:m.error.message,variant:"error"})},[m.isError,m.error,d,t]),n.useEffect(()=>{if(!s)return;const p=N=>{N.key==="Escape"&&o()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,o]),n.useEffect(()=>{s&&y.current&&y.current.focus()},[s,r]);const v=n.useCallback(async(p,N,I)=>{if(!N){d({title:t("logs.detail.copy.empty",{label:p}),variant:"info"});return}try{await navigator.clipboard.writeText(N),d({title:t(I),variant:"success"})}catch(F){d({title:t("logs.detail.copy.failure"),description:F instanceof Error?F.message:t("logs.detail.copy.failureFallback"),variant:"error"})}},[d,t]);if(!s)return null;const l=m.data,h=l?f.get(l.provider)??l.provider:"",i=l&&l.api_key_id!=null?j.get(l.api_key_id):void 0;return typeof document>"u"?null:we.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:o}),e.jsxs("aside",{role:"dialog","aria-modal":"true",className:"flex h-full w-full max-w-xl flex-col border-l bg-card shadow-xl",children:[e.jsxs("header",{className:"flex items-center justify-between border-b px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:t("logs.detail.title")}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.id",{id:l.id})})]}),e.jsxs(k,{ref:y,variant:"outline",size:"sm",onClick:o,children:[e.jsx(ke,{className:"mr-2 h-4 w-4"}),t("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:m.isPending?e.jsx(_e,{}):l?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md bg-muted p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:t("logs.detail.summary.route",{from:l.client_model??t("logs.detail.info.noRequestedModel"),to:l.model})}),e.jsx("span",{className:"text-muted-foreground",children:t("logs.detail.summary.latency",{value:E(l.latency_ms,t("common.units.ms"))})}),l.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",E(l.ttft_ms,t("common.units.ms"))]}),e.jsx(ce,{variant:l.error?"destructive":"default",children:(l.status_code??(l.error?500:200)).toString()})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:me(l.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:l.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:l.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:h})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:l.client_model??t("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:l.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:Ce(l.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:E(l.ttft_ms,t("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:E(l.tpot_ms,t("common.units.msPerToken"))})]})]}),l.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:l.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id==null&&!l.api_key_name?t("logs.detail.apiKey.missing"):i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.name)??l.api_key_name??t("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id??t("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.maskedKey)??l.api_key_name??t("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:i!=null&&i.lastUsedAt?new Date(i.lastUsedAt).toLocaleString():t("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border bg-muted p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:t("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:l.api_key_value_available?l.api_key_value_masked??t("logs.detail.apiKey.rawUnavailable"):t("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:t("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.payload.request")}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>{var p;return v(t("logs.detail.payload.request"),(p=l.payload)==null?void 0:p.prompt,"logs.detail.copy.requestSuccess")},children:t("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border bg-muted p-3 text-xs",children:oe((x=l.payload)==null?void 0:x.prompt,t("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.payload.response")}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>{var p;return v(t("logs.detail.payload.response"),(p=l.payload)==null?void 0:p.response,"logs.detail.copy.responseSuccess")},children:t("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border bg-muted p-3 text-xs",children:oe((c=l.payload)==null?void 0:c.response,t("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:t("logs.detail.loadError")})})]})]}),document.body)}function Re({apiKeys:s,selected:r,onChange:o,disabled:f,className:j}){const{t}=U(),[d,y]=n.useState(!1),m=n.useRef(null);n.useEffect(()=>{if(!d)return;const i=x=>{var c;(c=m.current)!=null&&c.contains(x.target)||y(!1)};return window.addEventListener("mousedown",i),()=>window.removeEventListener("mousedown",i)},[d]);const v=n.useMemo(()=>{if(r.length===0)return[];const i=new Map;for(const x of s)i.set(x.id,x);return r.map(x=>{const c=i.get(x);return c?c.isWildcard?t("apiKeys.wildcard"):c.name:null}).filter(x=>!!x)},[s,r,t]),l=r.length===0?t("logs.filters.apiKeyAll"):t("logs.filters.apiKeySelected",{count:r.length}),h=i=>{r.includes(i)?o(r.filter(x=>x!==i)):o([...r,i])};return e.jsxs("div",{className:L("relative space-y-2",j),ref:m,children:[e.jsx(S,{children:t("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>y(i=>!i),disabled:f||s.length===0,title:t("logs.filters.apiKeyHint"),className:L("flex h-10 w-full items-center justify-between rounded-md border bg-background px-3 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",r.length>0&&"border-primary",d&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[l,v.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:v.join(", ")})]}),e.jsx("svg",{className:L("h-4 w-4 opacity-50 transition-transform",d&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),d&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-1 w-64 rounded-md border bg-popover p-2 shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-muted px-3 py-2 text-xs",children:[e.jsx("span",{children:l}),e.jsx("button",{type:"button",onClick:()=>o([]),disabled:r.length===0,className:"text-primary hover:underline disabled:opacity-40",children:t("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(i=>{const x=i.isWildcard?t("apiKeys.wildcard"):i.name,c=r.includes(i.id);return e.jsxs("label",{className:L("flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm transition hover:bg-muted",c&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border",checked:c,onChange:()=>h(i.id)}),e.jsx("span",{className:"truncate",children:x})]},i.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:t("logs.filters.apiKeyAll")})]})]})]})}export{qe as default};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{c as te,u as xe,b as be,r as u,j as e,e as S,U as fe,L as Z,d as K}from"./index-DSWEYKFg.js";import{u as ee}from"./useApiQuery-CDChhTqt.js";import{P as je}from"./PageHeader-CArgoeOl.js";import{I as f}from"./input-CSRYqyMm.js";import{L as l}from"./label-sxZdAo5j.js";import{C as F,a as H}from"./card-Hot3HWFO.js";import{S as L}from"./switch-DDvmmBlT.js";import{S as ve,a as ye,b as Ne,c as Pe,d as ke}from"./select-qZIYkE-k.js";import{C as we}from"./copy-DXxd_I6B.js";/**
|
|
2
|
-
* @license lucide-react v0.344.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const I=te("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"}]]);/**
|
|
7
|
-
* @license lucide-react v0.344.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Ce=te("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]),Le=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}];function Ke(){const{t}=xe(),{pushToast:p}=be(),b=ee(["config","info"],{url:"/api/config/info",method:"GET"}),j=ee(["auth","web"],{url:"/api/auth/web",method:"GET"}),[n,_]=u.useState(null),[V,se]=u.useState(""),[r,m]=u.useState({port:"",host:"",logRetentionDays:"",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",requestLogging:!0,responseLogging:!0,bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[g,G]=u.useState({}),[O,Q]=u.useState(!1),[z,W]=u.useState(!1),[U,$]=u.useState(!1),[d,J]=u.useState(null),[i,R]=u.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[q,T]=u.useState({}),[B,X]=u.useState(!1),ae=u.useMemo(()=>{if(!n)return null;const s=n.defaults;if(!s)return null;const a=[];return s.completion&&a.push(t("settings.defaults.completion",{model:s.completion})),s.reasoning&&a.push(t("settings.defaults.reasoning",{model:s.reasoning})),s.background&&a.push(t("settings.defaults.background",{model:s.background})),a.length>0?a.join(" | "):t("settings.defaults.none")},[n,t]),Y=u.useMemo(()=>i.enabled?d!=null&&d.hasPassword?i.username.trim()!==((d==null?void 0:d.username)??""):!0:!1,[i.enabled,i.username,d]);u.useEffect(()=>{var s,a,c,h,x,N,P,k,w,v,A;if(b.data){_(b.data.config),se(b.data.path);const M=b.data.config.storePayloads,E=y=>typeof y=="boolean"?y:typeof M=="boolean"?M:!0,o=b.data.config;m({port:String(o.port??((s=o.http)==null?void 0:s.port)??""),host:o.host??((a=o.http)==null?void 0:a.host)??"127.0.0.1",logRetentionDays:String(o.logRetentionDays??30),storeRequestPayloads:E(o.storeRequestPayloads),storeResponsePayloads:E(o.storeResponsePayloads),logLevel:o.logLevel??"info",requestLogging:o.requestLogging!==!1,responseLogging:o.responseLogging??o.requestLogging!==!1,bodyLimitMb:(()=>{const y=o.bodyLimit;return typeof y=="number"&&Number.isFinite(y)&&y>0?String(Math.max(1,Math.round(y/(1024*1024)))):"10"})(),enableRoutingFallback:o.enableRoutingFallback===!0,httpEnabled:((c=o.http)==null?void 0:c.enabled)!==!1,httpPort:String(((h=o.http)==null?void 0:h.port)??o.port??4100),httpHost:((x=o.http)==null?void 0:x.host)??o.host??"127.0.0.1",httpsEnabled:((N=o.https)==null?void 0:N.enabled)===!0,httpsPort:String(((P=o.https)==null?void 0:P.port)??4443),httpsHost:((k=o.https)==null?void 0:k.host)??o.host??"127.0.0.1",httpsKeyPath:((w=o.https)==null?void 0:w.keyPath)??"",httpsCertPath:((v=o.https)==null?void 0:v.certPath)??"",httpsCaPath:((A=o.https)==null?void 0:A.caPath)??""})}},[b.data]),u.useEffect(()=>{j.data&&(J(j.data),R({enabled:j.data.enabled,username:j.data.username??"",password:"",confirmPassword:""}),T({}))},[j.data]),u.useEffect(()=>{b.isError&&b.error&&p({title:t("settings.toast.loadFailure",{message:b.error.message}),variant:"error"})},[b.isError,b.error,p,t]),u.useEffect(()=>{j.isError&&j.error&&p({title:t("settings.toast.authLoadFailure",{message:j.error.message}),variant:"error"})},[j.isError,j.error,p,t]);const D=s=>a=>{m(c=>({...c,[s]:a}))},re=()=>{const s={};if(!r.httpEnabled&&!r.httpsEnabled&&(s.protocol="至少需要启用 HTTP 或 HTTPS 协议"),r.httpEnabled){const x=Number(r.httpPort);(!Number.isFinite(x)||x<1||x>65535)&&(s.httpPort="HTTP 端口必须在 1-65535 之间")}if(r.httpsEnabled){const x=Number(r.httpsPort);(!Number.isFinite(x)||x<1||x>65535)&&(s.httpsPort="HTTPS 端口必须在 1-65535 之间"),(!r.httpsKeyPath||!r.httpsCertPath)&&(s.protocol="HTTPS 已启用但缺少证书路径,请手动配置受信任的证书")}const a=Number(r.port);(!Number.isFinite(a)||a<1||a>65535)&&(s.port=t("settings.validation.port"));const c=Number(r.logRetentionDays);(!Number.isFinite(c)||c<1||c>365)&&(s.logRetentionDays=t("settings.validation.retention"));const h=Number(r.bodyLimitMb);return(!Number.isFinite(h)||h<1||h>2048)&&(s.bodyLimitMb=t("settings.validation.bodyLimit")),G(s),Object.keys(s).length===0},ne=()=>{const s={},a=i.username.trim(),c=d?a!==(d.username??""):!0,h=i.enabled&&(!(d!=null&&d.hasPassword)||c);return i.enabled&&!a&&(s.username=t("settings.auth.validation.username")),i.password&&i.password.length<6&&(s.password=t("settings.auth.validation.minLength")),h&&!i.password&&(s.password=t("settings.auth.validation.passwordRequired")),(i.password||i.confirmPassword)&&i.password!==i.confirmPassword&&(s.confirmPassword=t("settings.auth.validation.confirmMismatch")),T(s),Object.keys(s).length===0},oe=async()=>{var s,a,c,h,x,N,P,k,w,v,A,M;if(!n){p({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(re()){Q(!0);try{const E=Number(r.port),o=Number(r.logRetentionDays),y=Number(r.bodyLimitMb),C={...n,http:{enabled:r.httpEnabled,port:Number(r.httpPort),host:r.httpHost.trim()||"127.0.0.1"},https:{enabled:r.httpsEnabled,port:Number(r.httpsPort),host:r.httpsHost.trim()||"127.0.0.1",keyPath:r.httpsKeyPath.trim(),certPath:r.httpsCertPath.trim(),caPath:r.httpsCaPath.trim()||void 0},port:E,host:r.host.trim()||void 0,logRetentionDays:o,storeRequestPayloads:r.storeRequestPayloads,storeResponsePayloads:r.storeResponsePayloads,logLevel:r.logLevel,requestLogging:r.requestLogging,responseLogging:r.responseLogging,bodyLimit:Math.max(1,Math.floor(y*1024*1024)),enableRoutingFallback:r.enableRoutingFallback},{webAuth:Re,...ge}=C;await K.put("/api/config",ge),_({...C,webAuth:n.webAuth});const ue=((s=n.http)==null?void 0:s.enabled)!==((a=C.http)==null?void 0:a.enabled)||((c=n.http)==null?void 0:c.port)!==((h=C.http)==null?void 0:h.port)||((x=n.https)==null?void 0:x.enabled)!==((N=C.https)==null?void 0:N.enabled)||((P=n.https)==null?void 0:P.port)!==((k=C.https)==null?void 0:k.port)||((w=n.https)==null?void 0:w.keyPath)!==((v=C.https)==null?void 0:v.keyPath)||((A=n.https)==null?void 0:A.certPath)!==((M=C.https)==null?void 0:M.certPath);p(ue?{title:"配置已保存!请执行 cc-gw restart --daemon 重启服务使协议配置生效",variant:"success"}:{title:t("settings.toast.saveSuccess"),variant:"success"}),b.refetch()}catch(E){p({title:t("settings.toast.saveFailure",{message:E instanceof Error?E.message:"unknown"}),variant:"error"})}finally{Q(!1)}}},ie=()=>{var s,a,c,h,x,N,P,k,w;n&&(m({port:String(n.port??""),host:n.host??"",logRetentionDays:String(n.logRetentionDays??30),storeRequestPayloads:typeof n.storeRequestPayloads=="boolean"?n.storeRequestPayloads:typeof n.storePayloads=="boolean"?n.storePayloads:!0,storeResponsePayloads:typeof n.storeResponsePayloads=="boolean"?n.storeResponsePayloads:typeof n.storePayloads=="boolean"?n.storePayloads:!0,logLevel:n.logLevel??"info",requestLogging:n.requestLogging!==!1,responseLogging:n.responseLogging??n.requestLogging!==!1,bodyLimitMb:(()=>{const v=n.bodyLimit;return typeof v=="number"&&Number.isFinite(v)&&v>0?String(Math.max(1,Math.round(v/(1024*1024)))):"10"})(),enableRoutingFallback:n.enableRoutingFallback===!0,httpEnabled:((s=n.http)==null?void 0:s.enabled)!==!1,httpPort:String(((a=n.http)==null?void 0:a.port)??n.port??4100),httpHost:((c=n.http)==null?void 0:c.host)??n.host??"127.0.0.1",httpsEnabled:((h=n.https)==null?void 0:h.enabled)===!0,httpsPort:String(((x=n.https)==null?void 0:x.port)??4443),httpsHost:((N=n.https)==null?void 0:N.host)??n.host??"127.0.0.1",httpsKeyPath:((P=n.https)==null?void 0:P.keyPath)??"",httpsCertPath:((k=n.https)==null?void 0:k.certPath)??"",httpsCaPath:((w=n.https)==null?void 0:w.caPath)??""}),G({}))},le=async()=>{var s;if(ne()){X(!0);try{const a={enabled:i.enabled,username:i.username.trim()||void 0};i.password&&(a.password=i.password);const h=(s=(await K.post("/api/auth/web",a)).data)==null?void 0:s.auth;h&&(J(h),R({enabled:h.enabled,username:h.username??"",password:"",confirmPassword:""}),T({})),p({title:t("settings.auth.toast.success"),variant:"success"}),j.refetch()}catch(a){const c=a instanceof Error?a.message:"unknown";p({title:t("settings.auth.toast.failure",{message:c}),variant:"error"})}finally{X(!1)}}},de=()=>{d&&(R({enabled:d.enabled,username:d.username??"",password:"",confirmPassword:""}),T({}))},ce=async()=>{if(!V){p({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await navigator.clipboard.writeText(V),p({title:t("settings.toast.copySuccess"),variant:"success"})}catch(s){p({title:t("settings.toast.copyFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}},he=async()=>{W(!0);try{const a=(await K.post("/api/logs/cleanup")).data.deleted??0;p({title:a>0?t("settings.toast.cleanupSuccess",{count:a}):t("settings.toast.cleanupNone"),variant:"success"})}catch(s){p({title:t("settings.toast.cleanupFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{W(!1)}},me=async()=>{$(!0);try{const s=await K.post("/api/logs/clear"),{deleted:a,metricsCleared:c}=s.data;p({title:t("settings.toast.clearAllSuccess",{logs:a,metrics:c}),variant:"success"})}catch(s){p({title:t("settings.toast.clearAllFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{$(!1)}},pe=b.isPending||!n&&b.isFetching;return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(je,{icon:e.jsx(fe,{className:"h-5 w-5","aria-hidden":"true"}),title:t("settings.title"),description:t("settings.description"),actions:n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",onClick:ie,disabled:O,children:t("common.actions.reset")}),e.jsx(S,{onClick:()=>void oe(),disabled:O,children:t(O?"common.actions.saving":"common.actions.save")})]}):null}),pe?e.jsx(F,{children:e.jsx(H,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Z,{})})}):n?e.jsxs(e.Fragment,{children:[e.jsx(F,{children:e.jsxs(H,{className:"pt-6",children:[e.jsx("h3",{className:"mb-4 text-sm font-semibold",children:t("settings.sections.basics")}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.port")}),e.jsx(f,{type:"number",min:1,max:65535,value:r.port,onChange:s=>D("port")(s.target.value),"aria-invalid":!!g.port}),g.port&&e.jsx("p",{className:"text-xs text-destructive",children:g.port})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.host")}),e.jsx(f,{value:r.host,onChange:s=>D("host")(s.target.value),placeholder:t("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.retention")}),e.jsx(f,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:s=>D("logRetentionDays")(s.target.value),"aria-invalid":!!g.logRetentionDays}),g.logRetentionDays&&e.jsx("p",{className:"text-xs text-destructive",children:g.logRetentionDays})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.bodyLimit")}),e.jsx(f,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:s=>D("bodyLimitMb")(s.target.value),"aria-invalid":!!g.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.bodyLimitHint")}),g.bodyLimitMb&&e.jsx("p",{className:"text-xs text-destructive",children:g.bodyLimitMb})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.logLevel")}),e.jsxs(ve,{value:r.logLevel,onValueChange:s=>m(a=>({...a,logLevel:s})),children:[e.jsx(ye,{children:e.jsx(Ne,{})}),e.jsx(Pe,{children:Le.map(s=>e.jsx(ke,{value:s.value,children:t(`settings.fields.logLevelOption.${s.labelKey}`)},s.value))})]})]}),e.jsxs("div",{className:"md:col-span-2 grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{className:"text-sm font-medium",children:t("settings.fields.storeRequestPayloads")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.storeRequestPayloadsHint")})]}),e.jsx(L,{checked:r.storeRequestPayloads,onCheckedChange:s=>m(a=>({...a,storeRequestPayloads:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{className:"text-sm font-medium",children:t("settings.fields.storeResponsePayloads")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.storeResponsePayloadsHint")})]}),e.jsx(L,{checked:r.storeResponsePayloads,onCheckedChange:s=>m(a=>({...a,storeResponsePayloads:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{className:"text-sm font-medium",children:t("settings.fields.requestLogging")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.requestLoggingHint")})]}),e.jsx(L,{checked:r.requestLogging,onCheckedChange:s=>m(a=>({...a,requestLogging:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{className:"text-sm font-medium",children:t("settings.fields.responseLogging")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.responseLoggingHint")})]}),e.jsx(L,{checked:r.responseLogging,onCheckedChange:s=>m(a=>({...a,responseLogging:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-950",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{className:"text-sm font-medium text-amber-700 dark:text-amber-300",children:t("settings.fields.enableRoutingFallback")}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:t("settings.fields.enableRoutingFallbackHint")})]}),e.jsx(L,{checked:r.enableRoutingFallback,onCheckedChange:s=>m(a=>({...a,enableRoutingFallback:s}))})]})]}),e.jsxs("div",{className:"md:col-span-2 rounded-lg border bg-muted/50 p-4",children:[e.jsx(l,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:t("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:ae??t("settings.defaults.none")})]})]})]})}),e.jsx(F,{children:e.jsxs(H,{className:"pt-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:t("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:t("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-md bg-amber-100 px-3 py-2 text-xs font-mono text-amber-900 dark:bg-amber-900 dark:text-amber-100",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:t("settings.protocol.restartTip")})]})]})}),g.protocol&&e.jsxs("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(I,{className:"inline h-4 w-4 mr-2"}),g.protocol]}),e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50/50 p-5 dark:border-blue-800 dark:bg-blue-950/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:t("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400",children:t("settings.protocol.http.hint")})]}),e.jsx(L,{checked:r.httpEnabled,onCheckedChange:s=>m(a=>({...a,httpEnabled:s}))})]}),r.httpEnabled&&e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 mt-4 pt-4 border-t border-blue-200 dark:border-blue-800",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.http.port")}),e.jsx(f,{type:"number",min:1,max:65535,value:r.httpPort,onChange:s=>m(a=>({...a,httpPort:s.target.value})),"aria-invalid":!!g.httpPort}),g.httpPort&&e.jsx("p",{className:"text-xs text-destructive",children:g.httpPort})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.http.host")}),e.jsx(f,{value:r.httpHost,onChange:s=>m(a=>({...a,httpHost:s.target.value})),placeholder:"127.0.0.1"})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-green-200 bg-green-50/50 p-5 dark:border-green-800 dark:bg-green-950/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(l,{className:"text-sm font-medium text-green-800 dark:text-green-200",children:t("settings.protocol.https.enable")}),e.jsx(Ce,{className:"h-4 w-4 text-green-600 dark:text-green-400"})]}),e.jsx("p",{className:"text-xs text-green-600 dark:text-green-400",children:t("settings.protocol.https.hint")})]}),e.jsx(L,{checked:r.httpsEnabled,onCheckedChange:s=>m(a=>({...a,httpsEnabled:s}))})]}),r.httpsEnabled&&e.jsxs("div",{className:"space-y-4 mt-4 pt-4 border-t border-green-200 dark:border-green-800",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.port")}),e.jsx(f,{type:"number",min:1,max:65535,value:r.httpsPort,onChange:s=>m(a=>({...a,httpsPort:s.target.value})),"aria-invalid":!!g.httpsPort}),g.httpsPort&&e.jsx("p",{className:"text-xs text-destructive",children:g.httpsPort})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.host")}),e.jsx(f,{value:r.httpsHost,onChange:s=>m(a=>({...a,httpsHost:s.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.keyPath")}),e.jsx(f,{value:r.httpsKeyPath,onChange:s=>m(a=>({...a,httpsKeyPath:s.target.value})),placeholder:"~/.cc-gw/certs/key.pem",className:"font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.certPath")}),e.jsx(f,{value:r.httpsCertPath,onChange:s=>m(a=>({...a,httpsCertPath:s.target.value})),placeholder:"~/.cc-gw/certs/cert.pem",className:"font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.caPath")}),e.jsx(f,{value:r.httpsCaPath,onChange:s=>m(a=>({...a,httpsCaPath:s.target.value})),placeholder:"留空则不使用",className:"font-mono text-xs"})]}),e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:t("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300 leading-relaxed",children:[e.jsx("strong",{children:t("settings.protocol.https.invalidCert")}),t("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300 leading-relaxed",children:[e.jsx("strong",{children:t("settings.protocol.https.recommended")}),t("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 leading-relaxed",children:t("settings.protocol.https.tip")})]})]})})]})]})]})}),e.jsx(F,{children:e.jsxs(H,{className:"pt-6 space-y-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.auth.description")})]}),j.isPending&&!d?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Z,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{className:"text-sm font-medium",children:t("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full bg-muted px-3 py-1",children:"/ui"}),e.jsx("span",{className:"rounded-full bg-muted px-3 py-1",children:"/api/*"}),e.jsx("span",{className:"rounded-full bg-muted px-3 py-1",children:"Cookie Session"})]})]}),e.jsx(L,{checked:i.enabled,onCheckedChange:s=>R(a=>({...a,enabled:s}))})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(l,{children:t("settings.auth.username")}),e.jsx(f,{value:i.username,onChange:s=>R(a=>({...a,username:s.target.value})),placeholder:t("settings.auth.usernamePlaceholder")}),q.username&&e.jsx("p",{className:"text-xs text-destructive",children:q.username})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.auth.password")}),e.jsx(f,{type:"password",value:i.password,disabled:!i.enabled,onChange:s=>R(a=>({...a,password:s.target.value})),placeholder:t("settings.auth.passwordPlaceholder")}),q.password?e.jsx("p",{className:"text-xs text-destructive",children:q.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:t(Y?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.auth.confirmPassword")}),e.jsx(f,{type:"password",value:i.confirmPassword,disabled:!i.enabled,onChange:s=>R(a=>({...a,confirmPassword:s.target.value})),placeholder:t("settings.auth.confirmPasswordPlaceholder")}),q.confirmPassword&&e.jsx("p",{className:"text-xs text-destructive",children:q.confirmPassword})]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:t("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:d!=null&&d.enabled?t("settings.auth.statusEnabled"):t("settings.auth.statusDisabled")}),(d==null?void 0:d.username)&&e.jsxs("div",{className:"mt-3 rounded-md bg-primary/10 px-3 py-2 text-xs font-medium text-primary",children:[t("settings.auth.username"),": ",d.username]})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 text-xs text-muted-foreground",children:t(Y?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(S,{onClick:()=>void le(),disabled:B,children:t(B?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(S,{variant:"outline",onClick:de,disabled:B,children:t("common.actions.reset")})]})]})]})}),e.jsx(F,{children:e.jsxs(H,{className:"pt-6 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.file.description")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>void ce(),children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),t("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg border bg-muted px-4 py-3 text-xs",children:V||t("settings.file.unknown")})]})}),e.jsx(F,{children:e.jsxs(H,{className:"pt-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.cleanup.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(S,{variant:"outline",onClick:()=>void he(),disabled:z,className:"border-destructive/50 text-destructive hover:bg-destructive/10",children:t(z?"common.actions.cleaning":"common.actions.cleanup")}),e.jsx(S,{variant:"destructive",onClick:()=>void me(),disabled:U,children:t(U?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]}),e.jsx("p",{className:"text-xs text-destructive",children:t("settings.cleanup.clearAllWarning")})]})})]}):e.jsx(F,{children:e.jsx(H,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})})]})}export{Ke as default};
|