@chenpu17/cc-gw 0.3.11 → 0.3.12
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/README.md +26 -1
- package/package.json +1 -1
- package/src/server/dist/index.js +2429 -201
- package/src/web/dist/assets/{About-DmfYXdTi.js → About-DnWkOgAf.js} +2 -2
- package/src/web/dist/assets/{ApiKeys-Bq84uD5O.js → ApiKeys-CBe66hEA.js} +1 -1
- package/src/web/dist/assets/{Button-B4UYWk6z.js → Button-C-i-DISc.js} +1 -1
- package/src/web/dist/assets/{Dashboard-CJmps0fW.js → Dashboard-D8pCuP6p.js} +1 -1
- package/src/web/dist/assets/{FormField-DKIC96zy.js → FormField-1cnBcVyy.js} +1 -1
- package/src/web/dist/assets/{Help-C7fFCpNH.js → Help-BxOmZMMV.js} +1 -1
- package/src/web/dist/assets/{Input-Cr1GbVY7.js → Input-BZ6K0tyW.js} +1 -1
- package/src/web/dist/assets/{Login-f_-O93Uo.js → Login-Dv9uSd3D.js} +1 -1
- package/src/web/dist/assets/{Logs-CyN3g8z0.js → Logs-CPHSNLlA.js} +1 -1
- package/src/web/dist/assets/ModelManagement-Cf-NV2X0.js +1 -0
- package/src/web/dist/assets/{PageSection-eOpSKdGw.js → PageSection-BdauTwx0.js} +1 -1
- package/src/web/dist/assets/{Settings-BUNwIquC.js → Settings-BG-7LB6a.js} +1 -1
- package/src/web/dist/assets/{StatusBadge-CFXAJ2QF.js → StatusBadge-BCWow-Yk.js} +1 -1
- package/src/web/dist/assets/{copy-Br9n1n5X.js → copy-BhWxP215.js} +1 -1
- package/src/web/dist/assets/{index-DtOsr5xX.js → index-DCeJcrH5.js} +1 -1
- package/src/web/dist/assets/{index-ChT0XT-w.js → index-Jd5giEeS.js} +2 -2
- package/src/web/dist/assets/{info-Cnwm2-vh.js → info-BLq7flU9.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-mBT5M_Q6.js → useApiQuery-DByVsawz.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/assets/ModelManagement-B11a4hW3.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Dashboard-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Dashboard-D8pCuP6p.js","assets/index-DCeJcrH5.js","assets/PageSection-BdauTwx0.js","assets/Input-BZ6K0tyW.js","assets/StatusBadge-BCWow-Yk.js","assets/useApiQuery-DByVsawz.js","assets/Logs-CPHSNLlA.js","assets/FormField-1cnBcVyy.js","assets/Button-C-i-DISc.js","assets/ModelManagement-Cf-NV2X0.js","assets/ApiKeys-CBe66hEA.js","assets/copy-BhWxP215.js","assets/Settings-BG-7LB6a.js","assets/About-DnWkOgAf.js","assets/info-BLq7flU9.js","assets/Help-BxOmZMMV.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var nm=Object.defineProperty;var wu=e=>{throw TypeError(e)};var rm=(e,t,n)=>t in e?nm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var xu=(e,t,n)=>rm(e,typeof t!="symbol"?t+"":t,n),Ro=(e,t,n)=>t.has(e)||wu("Cannot "+n);var P=(e,t,n)=>(Ro(e,t,"read from private field"),n?n.call(e):t.get(e)),z=(e,t,n)=>t.has(e)?wu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),_=(e,t,n,r)=>(Ro(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),ge=(e,t,n)=>(Ro(e,t,"access private method"),n);var zs=(e,t,n,r)=>({set _(s){_(e,t,s,n)},get _(){return P(e,t,r)}});function sm(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in e)){const i=Object.getOwnPropertyDescriptor(r,s);i&&Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(s){if(s.ep)return;s.ep=!0;const i=n(s);fetch(s.href,i)}})();function im(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Dd={exports:{}},eo={},Md={exports:{}},M={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react.production.min.js
|
|
@@ -170,4 +170,4 @@ name = "cc_gw"
|
|
|
170
170
|
base_url = "http://127.0.0.1:4100/openai/v1"
|
|
171
171
|
wire_api = "responses"
|
|
172
172
|
env_key = "cc_gw_key"
|
|
173
|
-
\`\`\``,"Set environment variable:\n```bash\nexport cc_gw_key=sk-ant.....\n```\nAdd to ~/.bashrc or ~/.zshrc and run `source` to apply.",'Verify configuration:\n```bash\ncodex status # Check connection status\ncodex ask "Hello, please introduce yourself" # Test conversation\ncodex chat # Enter interactive mode\n```\nSuccessful responses indicate proper setup.']},usage:{title:"4. Daily Usage",items:["Use the dashboard to keep an eye on request volume, token usage, cache hits, and TTFT/TPOT trends.","“Request Logs” provides rich filters plus full payload replay for debugging client/provider compatibility issues.","“Model Management” lets you switch defaults or update mappings without redeploying IDE extensions or automation scripts.","“Settings” controls log retention, payload storage, and log verbosity to suit your operations."]},tips:{title:"5. Practical Tips",items:["Enable “Store request/response bodies” to copy raw payloads from the log drawer when troubleshooting.","Turn off request or response logs individually to keep the console quiet while preserving metrics and database records.","If you edit ~/.cc-gw/config.json manually, refresh the Settings page or restart cc-gw so the UI reflects the latest configuration."]}},faq:{title:"Frequently asked questions",items:[{q:"How can I change the default model for each endpoint?",a:"Go to “Model Management → Routing” and choose defaults for /anthropic and /openai. Saving applies the change right away."},{q:"Why are cached token numbers missing?",a:"Upstream providers must return cached_tokens or input_tokens_details.cached_tokens. Enable cache metrics on the provider if supported."}]}},apiKeys:{title:"API Keys Management",description:"Create and manage API keys for gateway access",createNew:"Create New Key",createAction:"Create",createDescription:"Create a new API key for authentication and optionally add a description.",descriptionLabel:"Key description (optional)",keyDescriptionPlaceholder:"e.g. Internal staging access only",keyNamePlaceholder:"Enter key name",keyCreated:"API Key Created",saveKeyWarning:"This is the only time you'll see the full key. Save it securely!",wildcard:"Any Key",wildcardHint:"When enabled, any custom key — including an empty key — is accepted. Disable this key to enforce strict authentication.",status:{enabled:"Enabled",disabled:"Disabled"},actions:{enable:"Enable",disable:"Disable",delete:"Delete"},created:"Created",lastUsed:"Last Used",requestCount:"Requests",totalTokens:"Total Tokens",confirmDelete:"Are you sure you want to delete this API key? This action cannot be undone.",errors:{nameRequired:"Key name is required"},analytics:{title:"Key Usage Analytics",description:"Highlights for the past {{days}} days of API key activity",range:{today:"Today",week:"Last 7 days",month:"Last 30 days"},cards:{total:"Total keys",enabled:"Enabled keys",active:"Active keys ({{days}} days)"},charts:{requests:"Top 10 keys by request count",tokens:"Top 10 keys by token usage"},tokens:{input:"Input tokens",output:"Output tokens"},requestsSeries:"Requests",empty:"No activity for the selected range.",unknownKey:"Unknown key"},list:{title:"Key Inventory",empty:"No API keys found. Use the button above to create one."},toast:{keyCreated:"API key created successfully",keyUpdated:"API key updated successfully",keyDeleted:"API key deleted successfully",keyCopied:"Key copied to clipboard",createFailure:"Failed to create: {{message}}",updateFailure:"Failed to update: {{message}}",deleteFailure:"Failed to delete: {{message}}"}},about:{title:"About",description:"Review cc-gw version details, build metadata, and current runtime status.",app:{title:"Application",subtitle:"Gateway build metadata at a glance.",labels:{name:"Name",version:"Version",buildTime:"Build time",node:"Node version"},hint:{buildTime:"Timestamps are recorded in UTC so you can trace deployments easily."}},status:{title:"Runtime status",subtitle:"Live metrics reported by the running gateway.",loading:"Fetching status...",empty:"Unable to retrieve status information.",labels:{host:"Listen host",port:"Listen port",providers:"Providers configured",active:"Active requests"},hint:{active:"Active request totals refresh roughly every minute."}},support:{title:"Operational notes",subtitle:"Maintenance guidance",description:"Manage providers, routing, and logs in the Web UI; advanced settings live in ~/.cc-gw/config.json.",tip:"Consider keeping ~/.cc-gw/config.json under version control or managing it via automation scripts.",actions:{checkUpdates:"Check for updates"}},toast:{statusError:{title:"Failed to load status"},updatesPlanned:"Update checks will arrive in a future release."}}}}};de.isInitialized||de.use(ev).init({resources:Gw,lng:"zh",fallbackLng:"en",interpolation:{escapeValue:!1}});const Zh=S.createContext(void 0);function Yw(){return`toast_${Math.random().toString(36).slice(2)}`}function Xw({children:e}){const[t,n]=S.useState([]),r=S.useCallback(o=>{n(a=>a.filter(l=>l.id!==o))},[]),s=S.useCallback(o=>{const a=o.id??Yw();n(u=>[...u,{...o,id:a}]);const l=o.durationMs??3e3;l>0&&setTimeout(()=>r(a),l)},[r]),i=S.useMemo(()=>({toasts:t,pushToast:s,dismissToast:r}),[t,r,s]);return E.jsxs(Zh.Provider,{value:i,children:[e,E.jsx("div",{className:"fixed right-6 top-6 z-50 flex w-80 flex-col gap-3",children:t.map(o=>E.jsx("div",{className:`rounded-md border border-slate-200 bg-white p-4 shadow-lg dark:border-slate-700 dark:bg-slate-800 ${o.variant==="error"?"border-red-200 bg-red-50 text-red-900 dark:border-red-700 dark:bg-red-900/40 dark:text-red-200":o.variant==="success"?"border-emerald-200 bg-emerald-50 text-emerald-900 dark:border-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200":""}`,children:E.jsxs("div",{className:"flex items-start justify-between gap-4",children:[E.jsxs("div",{children:[E.jsx("p",{className:"text-sm font-semibold",children:o.title}),o.description?E.jsx("p",{className:"mt-1 text-sm opacity-75",children:o.description}):null]}),E.jsx("button",{type:"button",className:"text-sm text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-100",onClick:()=>r(o.id),children:"×"})]})},o.id))})]})}function nk(){const e=S.useContext(Zh);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Zw({children:e}){const[t]=S.useState(()=>new Ew);return E.jsx(bw,{client:t,children:E.jsx(sv,{i18n:de,children:E.jsx(vv,{children:E.jsx(Xw,{children:E.jsx(Y1,{children:e})})})})})}function em(){const{t:e}=Fs();return E.jsx("div",{className:"flex h-full items-center justify-center p-12",role:"status","aria-live":"polite",children:E.jsxs("div",{className:"flex flex-col items-center gap-4",children:[E.jsx("div",{className:"h-12 w-12 animate-spin rounded-full border-4 border-primary border-t-transparent"}),E.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:e("common.loading")})]})})}const ex=S.lazy(()=>hn(()=>import("./Dashboard-
|
|
173
|
+
\`\`\``,"Set environment variable:\n```bash\nexport cc_gw_key=sk-ant.....\n```\nAdd to ~/.bashrc or ~/.zshrc and run `source` to apply.",'Verify configuration:\n```bash\ncodex status # Check connection status\ncodex ask "Hello, please introduce yourself" # Test conversation\ncodex chat # Enter interactive mode\n```\nSuccessful responses indicate proper setup.']},usage:{title:"4. Daily Usage",items:["Use the dashboard to keep an eye on request volume, token usage, cache hits, and TTFT/TPOT trends.","“Request Logs” provides rich filters plus full payload replay for debugging client/provider compatibility issues.","“Model Management” lets you switch defaults or update mappings without redeploying IDE extensions or automation scripts.","“Settings” controls log retention, payload storage, and log verbosity to suit your operations."]},tips:{title:"5. Practical Tips",items:["Enable “Store request/response bodies” to copy raw payloads from the log drawer when troubleshooting.","Turn off request or response logs individually to keep the console quiet while preserving metrics and database records.","If you edit ~/.cc-gw/config.json manually, refresh the Settings page or restart cc-gw so the UI reflects the latest configuration."]}},faq:{title:"Frequently asked questions",items:[{q:"How can I change the default model for each endpoint?",a:"Go to “Model Management → Routing” and choose defaults for /anthropic and /openai. Saving applies the change right away."},{q:"Why are cached token numbers missing?",a:"Upstream providers must return cached_tokens or input_tokens_details.cached_tokens. Enable cache metrics on the provider if supported."}]}},apiKeys:{title:"API Keys Management",description:"Create and manage API keys for gateway access",createNew:"Create New Key",createAction:"Create",createDescription:"Create a new API key for authentication and optionally add a description.",descriptionLabel:"Key description (optional)",keyDescriptionPlaceholder:"e.g. Internal staging access only",keyNamePlaceholder:"Enter key name",keyCreated:"API Key Created",saveKeyWarning:"This is the only time you'll see the full key. Save it securely!",wildcard:"Any Key",wildcardHint:"When enabled, any custom key — including an empty key — is accepted. Disable this key to enforce strict authentication.",status:{enabled:"Enabled",disabled:"Disabled"},actions:{enable:"Enable",disable:"Disable",delete:"Delete"},created:"Created",lastUsed:"Last Used",requestCount:"Requests",totalTokens:"Total Tokens",confirmDelete:"Are you sure you want to delete this API key? This action cannot be undone.",errors:{nameRequired:"Key name is required"},analytics:{title:"Key Usage Analytics",description:"Highlights for the past {{days}} days of API key activity",range:{today:"Today",week:"Last 7 days",month:"Last 30 days"},cards:{total:"Total keys",enabled:"Enabled keys",active:"Active keys ({{days}} days)"},charts:{requests:"Top 10 keys by request count",tokens:"Top 10 keys by token usage"},tokens:{input:"Input tokens",output:"Output tokens"},requestsSeries:"Requests",empty:"No activity for the selected range.",unknownKey:"Unknown key"},list:{title:"Key Inventory",empty:"No API keys found. Use the button above to create one."},toast:{keyCreated:"API key created successfully",keyUpdated:"API key updated successfully",keyDeleted:"API key deleted successfully",keyCopied:"Key copied to clipboard",createFailure:"Failed to create: {{message}}",updateFailure:"Failed to update: {{message}}",deleteFailure:"Failed to delete: {{message}}"}},about:{title:"About",description:"Review cc-gw version details, build metadata, and current runtime status.",app:{title:"Application",subtitle:"Gateway build metadata at a glance.",labels:{name:"Name",version:"Version",buildTime:"Build time",node:"Node version"},hint:{buildTime:"Timestamps are recorded in UTC so you can trace deployments easily."}},status:{title:"Runtime status",subtitle:"Live metrics reported by the running gateway.",loading:"Fetching status...",empty:"Unable to retrieve status information.",labels:{host:"Listen host",port:"Listen port",providers:"Providers configured",active:"Active requests"},hint:{active:"Active request totals refresh roughly every minute."}},support:{title:"Operational notes",subtitle:"Maintenance guidance",description:"Manage providers, routing, and logs in the Web UI; advanced settings live in ~/.cc-gw/config.json.",tip:"Consider keeping ~/.cc-gw/config.json under version control or managing it via automation scripts.",actions:{checkUpdates:"Check for updates"}},toast:{statusError:{title:"Failed to load status"},updatesPlanned:"Update checks will arrive in a future release."}}}}};de.isInitialized||de.use(ev).init({resources:Gw,lng:"zh",fallbackLng:"en",interpolation:{escapeValue:!1}});const Zh=S.createContext(void 0);function Yw(){return`toast_${Math.random().toString(36).slice(2)}`}function Xw({children:e}){const[t,n]=S.useState([]),r=S.useCallback(o=>{n(a=>a.filter(l=>l.id!==o))},[]),s=S.useCallback(o=>{const a=o.id??Yw();n(u=>[...u,{...o,id:a}]);const l=o.durationMs??3e3;l>0&&setTimeout(()=>r(a),l)},[r]),i=S.useMemo(()=>({toasts:t,pushToast:s,dismissToast:r}),[t,r,s]);return E.jsxs(Zh.Provider,{value:i,children:[e,E.jsx("div",{className:"fixed right-6 top-6 z-50 flex w-80 flex-col gap-3",children:t.map(o=>E.jsx("div",{className:`rounded-md border border-slate-200 bg-white p-4 shadow-lg dark:border-slate-700 dark:bg-slate-800 ${o.variant==="error"?"border-red-200 bg-red-50 text-red-900 dark:border-red-700 dark:bg-red-900/40 dark:text-red-200":o.variant==="success"?"border-emerald-200 bg-emerald-50 text-emerald-900 dark:border-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200":""}`,children:E.jsxs("div",{className:"flex items-start justify-between gap-4",children:[E.jsxs("div",{children:[E.jsx("p",{className:"text-sm font-semibold",children:o.title}),o.description?E.jsx("p",{className:"mt-1 text-sm opacity-75",children:o.description}):null]}),E.jsx("button",{type:"button",className:"text-sm text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-100",onClick:()=>r(o.id),children:"×"})]})},o.id))})]})}function nk(){const e=S.useContext(Zh);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function Zw({children:e}){const[t]=S.useState(()=>new Ew);return E.jsx(bw,{client:t,children:E.jsx(sv,{i18n:de,children:E.jsx(vv,{children:E.jsx(Xw,{children:E.jsx(Y1,{children:e})})})})})}function em(){const{t:e}=Fs();return E.jsx("div",{className:"flex h-full items-center justify-center p-12",role:"status","aria-live":"polite",children:E.jsxs("div",{className:"flex flex-col items-center gap-4",children:[E.jsx("div",{className:"h-12 w-12 animate-spin rounded-full border-4 border-primary border-t-transparent"}),E.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:e("common.loading")})]})})}const ex=S.lazy(()=>hn(()=>import("./Dashboard-D8pCuP6p.js"),__vite__mapDeps([0,1,2,3,4,5]))),tx=S.lazy(()=>hn(()=>import("./Logs-CPHSNLlA.js"),__vite__mapDeps([6,5,2,7,3,8,4]))),Td=S.lazy(()=>hn(()=>import("./ModelManagement-Cf-NV2X0.js"),__vite__mapDeps([9,5]))),nx=S.lazy(()=>hn(()=>import("./ApiKeys-CBe66hEA.js"),__vite__mapDeps([10,1,5,2,7,3,8,4,11]))),rx=S.lazy(()=>hn(()=>import("./Settings-BG-7LB6a.js"),__vite__mapDeps([12,5,2,11]))),sx=S.lazy(()=>hn(()=>import("./About-DnWkOgAf.js"),__vite__mapDeps([13,5,2,3,8,14]))),ix=S.lazy(()=>hn(()=>import("./Help-BxOmZMMV.js"),__vite__mapDeps([15,2,14]))),ox=S.lazy(()=>hn(()=>import("./Login-Dv9uSd3D.js"),[]));function ax({children:e}){const{authEnabled:t,isAuthenticated:n,loading:r}=Hh(),s=mn();return r?E.jsx(em,{}):!t||n?e:E.jsx(lh,{to:"/login",replace:!0,state:{from:s}})}function lx(){return E.jsx(Zw,{children:E.jsx(Fy,{basename:typeof window<"u"&&window.location.pathname.startsWith("/ui")?"/ui":"/",children:E.jsx(S.Suspense,{fallback:E.jsx(em,{}),children:E.jsxs(by,{children:[E.jsxs(Ke,{path:"/",element:E.jsx(ax,{children:E.jsx(Z1,{})}),children:[E.jsx(Ke,{index:!0,element:E.jsx(ex,{})}),E.jsx(Ke,{path:"logs",element:E.jsx(tx,{})}),E.jsx(Ke,{path:"models",element:E.jsx(Td,{})}),E.jsx(Ke,{path:"providers",element:E.jsx(Td,{})}),E.jsx(Ke,{path:"api-keys",element:E.jsx(nx,{})}),E.jsx(Ke,{path:"settings",element:E.jsx(rx,{})}),E.jsx(Ke,{path:"about",element:E.jsx(sx,{})}),E.jsx(Ke,{path:"help",element:E.jsx(ix,{})})]}),E.jsx(Ke,{path:"/login",element:E.jsx(ox,{})}),E.jsx(Ke,{path:"*",element:E.jsx(lh,{to:"/",replace:!0})})]})})})})}const tm=document.getElementById("root");if(!tm)throw new Error("Root element #root not found");la.createRoot(tm).render(E.jsx(Wd.StrictMode,{children:E.jsx(lx,{})}));export{tk as $,kx as A,av as B,Sx as C,im as D,Px as E,uv as F,Ex as G,pv as H,Eo as I,pw as J,cv as K,em as L,ow as M,Xx as N,pl as O,tt as P,bo as Q,Wd as R,gv as S,sw as T,iw as U,fl as V,Vh as W,ww as X,uw as Y,Pe as Z,ek as _,nk as a,Zx as a0,vx as a1,dx as a2,hx as a3,px as a4,sh as a5,mn as a6,Hh as a7,qn as b,Be as c,Lt as d,Ix as e,Ox as f,wx as g,Nx as h,Cx as i,E as j,yh as k,Lx as l,mx as m,Ax as n,Tx as o,bx as p,A0 as q,S as r,xx as s,ia as t,Fs as u,cx as v,fx as w,gx as x,Rx as y,yx as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var ft=e=>{throw TypeError(e)};var Z=(e,t,s)=>t.has(e)||ft("Cannot "+s);var i=(e,t,s)=>(Z(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)=>(Z(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),d=(e,t,s)=>(Z(e,t,"access private method"),s);import{I as It,J as pt,M as S,N as $,O as H,P as G,Q as tt,T as bt,U as Ot,V as q,W as Tt,X as Qt,Y as yt,Z as St,r as I,_ as wt,$ as Mt,a0 as _t,b as xt,t as Ut}from"./index-ChT0XT-w.js";var g,a,j,y,w,U,E,O,V,F,P,M,_,T,D,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,w);b(this,U);b(this,E);b(this,O);b(this,V);b(this,F);b(this,P);b(this,M);b(this,_);b(this,T);b(this,D,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&&!$(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 Dt(this,r)&&(u(this,y,r),u(this,U,this.options),u(this,w,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,D).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,w),Q=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(),z=!R&>(t,s),x=R&&mt(t,r,s,h);(z||x)&&(l={...l,...Qt(L.data,t.options)}),s._optimisticResults==="isRestoring"&&(l.fetchStatus="idle")}let{error:A,errorUpdatedAt:k,status:m}=l;f=l.data;let W=!1;if(s.placeholderData!==void 0&&f===void 0&&m==="pending"){let R;o!=null&&o.isPlaceholderData&&s.placeholderData===(Q==null?void 0:Q.placeholderData)?(R=o.data,W=!0):R=typeof s.placeholderData=="function"?s.placeholderData((dt=i(this,P))==null?void 0:dt.state.data,i(this,P)):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&&!W)if(o&&f===(c==null?void 0:c.data)&&s.select===i(this,V))f=i(this,F);else try{u(this,V,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 J=l.fetchStatus==="fetching",X=m==="pending",Y=m==="error",ut=X&&J,lt=f!==void 0,C={status:m,fetchStatus:l.fetchStatus,isPending:X,isSuccess:m==="success",isError:Y,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:J,isRefetching:J&&!X,isLoadingError:Y&&!lt,isPaused:l.fetchStatus==="paused",isPlaceholderData:N,isRefetchError:Y&<,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)},z=()=>{const K=u(this,E,C.promise=pt());R(K)},x=i(this,E);switch(x.status){case"pending":t.queryHash===r.queryHash&&R(x);break;case"fulfilled":(C.status==="error"||C.data!==x.value)&&z();break;case"rejected":(C.status!=="error"||C.error!==x.reason)&&z();break}}return C}updateResult(){const t=i(this,y),s=this.createResult(i(this,a),this.options);if(u(this,w,i(this,a).state),u(this,U,this.options),i(this,w).data!==void 0&&u(this,P,i(this,a)),$(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,D).size)return!0;const c=new Set(o??i(this,D));return this.options.throwOnError&&c.add("error"),Object.keys(i(this,y)).some(Q=>{const p=Q;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,w=new WeakMap,U=new WeakMap,E=new WeakMap,O=new WeakMap,V=new WeakMap,F=new WeakMap,P=new WeakMap,M=new WeakMap,_=new WeakMap,T=new WeakMap,D=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(G)),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,_,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,_)&&(q.clearInterval(i(this,_)),u(this,_,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 Pt(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 Pt(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 Dt(e,t){return!$(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||wt(s,[e.error,r])),Vt=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))}},Wt=(e,t)=>e.isLoading&&e.isFetching&&!t,zt=(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",Vt(c),Bt(c,h),Ht(h);const Q=!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 W=L?p.subscribe(St.batchCalls(m)):G;return p.updateResult(),W},[p,L]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),I.useEffect(()=>{p.setOptions(c)},[c,p]),zt(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&&Wt(v,r)){const m=Q?Rt(c,p,h):(k=o.getQueryCache().get(c.queryHash))==null?void 0:k.promise;m==null||m.catch(G).finally(()=>{p.updateResult()})}return c.notifyOnChangeProps?v:p.trackResult(v)}function qt(e,t){return Kt(e,Ft)}function Zt(e,t,s){return qt({queryKey:e,placeholderData:_t,...s,queryFn:async()=>{try{return(await xt.request(t)).data}catch(r){throw Ut(r)}}})}export{Zt as u};
|
|
1
|
+
var ft=e=>{throw TypeError(e)};var Z=(e,t,s)=>t.has(e)||ft("Cannot "+s);var i=(e,t,s)=>(Z(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)=>(Z(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),d=(e,t,s)=>(Z(e,t,"access private method"),s);import{I as It,J as pt,M as S,N as $,O as H,P as G,Q as tt,T as bt,U as Ot,V as q,W as Tt,X as Qt,Y as yt,Z as St,r as I,_ as wt,$ as Mt,a0 as _t,b as xt,t as Ut}from"./index-Jd5giEeS.js";var g,a,j,y,w,U,E,O,V,F,P,M,_,T,D,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,w);b(this,U);b(this,E);b(this,O);b(this,V);b(this,F);b(this,P);b(this,M);b(this,_);b(this,T);b(this,D,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&&!$(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 Dt(this,r)&&(u(this,y,r),u(this,U,this.options),u(this,w,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,D).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,w),Q=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(),z=!R&>(t,s),x=R&&mt(t,r,s,h);(z||x)&&(l={...l,...Qt(L.data,t.options)}),s._optimisticResults==="isRestoring"&&(l.fetchStatus="idle")}let{error:A,errorUpdatedAt:k,status:m}=l;f=l.data;let W=!1;if(s.placeholderData!==void 0&&f===void 0&&m==="pending"){let R;o!=null&&o.isPlaceholderData&&s.placeholderData===(Q==null?void 0:Q.placeholderData)?(R=o.data,W=!0):R=typeof s.placeholderData=="function"?s.placeholderData((dt=i(this,P))==null?void 0:dt.state.data,i(this,P)):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&&!W)if(o&&f===(c==null?void 0:c.data)&&s.select===i(this,V))f=i(this,F);else try{u(this,V,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 J=l.fetchStatus==="fetching",X=m==="pending",Y=m==="error",ut=X&&J,lt=f!==void 0,C={status:m,fetchStatus:l.fetchStatus,isPending:X,isSuccess:m==="success",isError:Y,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:J,isRefetching:J&&!X,isLoadingError:Y&&!lt,isPaused:l.fetchStatus==="paused",isPlaceholderData:N,isRefetchError:Y&<,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)},z=()=>{const K=u(this,E,C.promise=pt());R(K)},x=i(this,E);switch(x.status){case"pending":t.queryHash===r.queryHash&&R(x);break;case"fulfilled":(C.status==="error"||C.data!==x.value)&&z();break;case"rejected":(C.status!=="error"||C.error!==x.reason)&&z();break}}return C}updateResult(){const t=i(this,y),s=this.createResult(i(this,a),this.options);if(u(this,w,i(this,a).state),u(this,U,this.options),i(this,w).data!==void 0&&u(this,P,i(this,a)),$(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,D).size)return!0;const c=new Set(o??i(this,D));return this.options.throwOnError&&c.add("error"),Object.keys(i(this,y)).some(Q=>{const p=Q;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,w=new WeakMap,U=new WeakMap,E=new WeakMap,O=new WeakMap,V=new WeakMap,F=new WeakMap,P=new WeakMap,M=new WeakMap,_=new WeakMap,T=new WeakMap,D=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(G)),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,_,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,_)&&(q.clearInterval(i(this,_)),u(this,_,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 Pt(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 Pt(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 Dt(e,t){return!$(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||wt(s,[e.error,r])),Vt=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))}},Wt=(e,t)=>e.isLoading&&e.isFetching&&!t,zt=(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",Vt(c),Bt(c,h),Ht(h);const Q=!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 W=L?p.subscribe(St.batchCalls(m)):G;return p.updateResult(),W},[p,L]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),I.useEffect(()=>{p.setOptions(c)},[c,p]),zt(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&&Wt(v,r)){const m=Q?Rt(c,p,h):(k=o.getQueryCache().get(c.queryHash))==null?void 0:k.promise;m==null||m.catch(G).finally(()=>{p.updateResult()})}return c.notifyOnChangeProps?v:p.trackResult(v)}function qt(e,t){return Kt(e,Ft)}function Zt(e,t,s){return qt({queryKey:e,placeholderData:_t,...s,queryFn:async()=>{try{return(await xt.request(t)).data}catch(r){throw Ut(r)}}})}export{Zt 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-Jd5giEeS.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-BOv43c_r.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body class="bg-slate-50 text-slate-900 dark:bg-slate-900 dark:text-slate-50">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as ve,r as p,j as e,a as Je,v as Xe,b as V,w as Ce,i as Ze,k as O,x as te,y as De,z as pe,A as be,C as et}from"./index-ChT0XT-w.js";import{u as tt}from"./useApiQuery-mBT5M_Q6.js";function ke(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Pe(){return{_key:ke(),id:"",label:""}}const he={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5 (2025-09-29)"},{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4 (2025-05-14)"},{id:"claude-opus-4-1-20250805",label:"Claude Opus 4.1 (2025-08-05)"},{id:"claude-3-5-haiku-20241022",label:"Claude 3.5 Haiku (2024-10-22)"}]},custom:{}};function Se(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(n=>({...n,_key:ke()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[Pe()],authMode:"apiKey"}}function st(s){return{_key:ke(),id:s.id,label:s.label}}function at({open:s,mode:n,provider:m,existingProviderIds:L,onClose:D,onSubmit:Y}){const{t:r}=ve(),[u,f]=p.useState(()=>Se(m)),[v,A]=p.useState({}),[_,U]=p.useState(!1),[q,B]=p.useState(null),se=p.useRef(null),I=p.useRef(null),w=p.useRef(null),[F,E]=p.useState(n==="edit");p.useEffect(()=>{s&&(f(Se(m)),A({}),B(null),U(!1),E(n==="edit"))},[s,m,n]),p.useEffect(()=>{if(!s)return;const l=c=>{c.key==="Escape"&&D()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s,D]),p.useEffect(()=>{if(s){if(n==="create"&&w.current){w.current.focus();return}I.current&&I.current.focus()}},[s,n]);const me=p.useMemo(()=>u.models.filter(l=>l.id.trim().length>0),[u.models]),G=l=>c=>{f(h=>({...h,[l]:c}))},J=l=>{f(c=>{const b=!F||c.label.trim().length===0||c.label===c.id?l:c.label;return{...c,id:l,label:b}})},X=l=>{f(c=>{var Z;const b=he[l??"custom"]??he.custom,k=Object.values(he).map(N=>N.baseUrl).filter(N=>!!N),M=!c.baseUrl||k.includes(c.baseUrl),S=n==="create"&&(c.models.length===0||c.models.every(N=>N.id.trim().length===0)),$={...c,type:l,authMode:l==="anthropic"?c.authMode??"apiKey":"apiKey"};return b!=null&&b.baseUrl&&M&&($.baseUrl=b.baseUrl),b!=null&&b.models&&S&&($.models=b.models.map(st),$.defaultModel=b.defaultModel??((Z=b.models[0])==null?void 0:Z.id)??""),$})},ae=(l,c)=>{f(h=>{const b=[...h.models];return b[l]={...b[l],...c},{...h,models:b}})},re=(l,c)=>{f(h=>{const b=[...h.models],k=b[l];if(!k)return h;const M=!F||!k.label||k.label===k.id,S={...k,id:c,label:M?c:k.label};b[l]=S;const $=h.defaultModel===k.id?c:h.defaultModel;return{...h,models:b,defaultModel:$}})},le=l=>{f(c=>{var k;if(c.models.length<=1)return c;const h=c.models.filter((M,S)=>S!==l);let b=c.defaultModel;return h.some(M=>M.id===b)||(b=((k=h[0])==null?void 0:k.id)??""),{...c,models:h,defaultModel:b}})},W=()=>{f(l=>({...l,models:[...l.models,Pe()]}))},Q=l=>{f(c=>({...c,authMode:l}))},oe=()=>{const l={},c=u.id.trim(),h=u.baseUrl.trim();if(n==="create"&&(c.length===0?l.id=r("providers.drawer.errors.idRequired"):L.includes(c)&&(l.id=r("providers.drawer.errors.idDuplicate"))),n==="edit"&&c.length===0&&(l.id=r("providers.drawer.errors.idRequired")),h.length===0)l.baseUrl=r("providers.drawer.errors.baseUrlInvalid");else try{new URL(h)}catch{l.baseUrl=r("providers.drawer.errors.baseUrlInvalid")}const b=new Set;return u.models.some(M=>{const S=M.id.trim();return S.length===0||b.has(S)?!0:(b.add(S),!1)})&&(l.models=r("providers.drawer.errors.modelInvalid")),u.models.length===0&&(l.models=r("providers.drawer.errors.modelsRequired")),u.defaultModel&&!u.models.some(M=>M.id===u.defaultModel)&&(l.models=r("providers.drawer.errors.defaultInvalid")),A(l),Object.keys(l).length===0},xe=()=>{const l=u.models.map(b=>{var k;return{id:b.id.trim(),label:(k=b.label)!=null&&k.trim()?b.label.trim():void 0}}),c=m!=null&&m.extraHeaders&&Object.keys(m.extraHeaders).length>0?m.extraHeaders:void 0,h=u.type==="anthropic"?u.authMode:void 0;return{id:u.id.trim(),label:u.label.trim()||u.id.trim(),baseUrl:u.baseUrl.trim(),apiKey:u.apiKey.trim()||void 0,type:u.type??"custom",defaultModel:u.defaultModel||void 0,models:l,extraHeaders:c,authMode:h}},de=async()=>{if(B(null),!!oe()){U(!0);try{const l=xe();await Y(l)}catch(l){B(r("providers.drawer.toast.saveFailure",{message:l instanceof Error?l.message:"unknown"})),U(!1);return}U(!1),D()}},ie=n==="create";return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:D,"aria-hidden":"true"}),e.jsxs("aside",{ref:se,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-3xl flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold",children:r(ie?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:I,onClick:D,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:r("common.actions.close")})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-fields",children:[e.jsx("div",{id:"provider-basic-fields",className:"sr-only",children:r("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>E(l=>!l),className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:r(F?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.id")}),e.jsx("input",{value:u.id,ref:w,onChange:l=>J(l.target.value),disabled:!ie,placeholder:r("providers.drawer.fields.idPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!v.id}),v.id?e.jsx("span",{className:"text-xs text-red-500",children:v.id}):null]}),F?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.label")}),e.jsx("input",{value:u.label,onChange:l=>G("label")(l.target.value),placeholder:r("providers.drawer.fields.labelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:u.baseUrl,onChange:l=>G("baseUrl")(l.target.value),placeholder:r("providers.drawer.fields.baseUrlPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!v.baseUrl}),v.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:v.baseUrl}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.type")}),e.jsxs("select",{value:u.type??"custom",onChange:l=>X(l.target.value),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"deepseek",children:"DeepSeek"}),e.jsx("option",{value:"huawei",children:"华为云"}),e.jsx("option",{value:"kimi",children:"Kimi"}),e.jsx("option",{value:"anthropic",children:"Anthropic (Claude)"}),e.jsx("option",{value:"custom",children:"Custom"})]})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.apiKey")}),e.jsx("input",{value:u.apiKey,onChange:l=>G("apiKey")(l.target.value),placeholder:r("providers.drawer.fields.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),u.type==="anthropic"?e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-slate-200 p-3 text-xs dark:border-slate-700",children:[e.jsx("legend",{className:"px-1 text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"apiKey",checked:u.authMode==="apiKey",onChange:()=>Q("apiKey")}),e.jsx("span",{children:r("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"authToken",checked:u.authMode==="authToken",onChange:()=>Q("authToken")}),e.jsx("span",{children:r("providers.drawer.fields.authModeAuthToken")})]})]}):null]}),e.jsxs("section",{className:"mt-6 space-y-3","aria-labelledby":"provider-model-fields",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"provider-model-fields",className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:W,className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:r("providers.drawer.fields.addModel")})]}),v.models?e.jsx("p",{className:"text-xs text-red-500",children:v.models}):null,e.jsx("div",{className:"space-y-4",children:u.models.map((l,c)=>e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.modelId")}),e.jsx("input",{value:l.id,onChange:h=>re(c,h.target.value),placeholder:r("providers.drawer.fields.modelIdPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),F?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:l.label??"",onChange:h=>ae(c,{label:h.target.value}),placeholder:r("providers.drawer.fields.modelLabelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:l.id,checked:u.defaultModel===l.id,onChange:()=>f(h=>({...h,defaultModel:l.id})),disabled:l.id.trim().length===0}),r("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>le(c),disabled:u.models.length<=1,children:r("providers.drawer.fields.removeModel")})]})]},l._key))}),me.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:r("providers.drawer.defaultHint",{model:u.defaultModel||r("providers.card.noDefault")})}):null]})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:q?e.jsx("span",{children:q}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:D,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:_,children:r("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:de,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:_,children:r(_?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const rt=["claude-sonnet-4-5-20250929","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-3-5-haiku-20241022"],lt=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function fe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function z(s){return s?Object.entries(s).map(([n,m])=>({id:fe(),source:n,target:m})):[]}function ge(s){var m,L;if(!s)return{anthropic:[],openai:[]};const n=s.endpointRouting??{};return{anthropic:z(((m=n.anthropic)==null?void 0:m.modelRoutes)??s.modelRoutes??{}),openai:z(((L=n.openai)==null?void 0:L.modelRoutes)??{})}}function ct(){const{t:s}=ve(),{pushToast:n}=Je(),m=tt(["config","full"],{url:"/api/config",method:"GET"}),L=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc")},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc")},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc")}],[D,Y]=p.useState("providers"),[r,u]=p.useState(null),[f,v]=p.useState(!1),[A,_]=p.useState("create"),[U,q]=p.useState(void 0),[B,se]=p.useState(null),[I,w]=p.useState({anthropic:[],openai:[]}),[F,E]=p.useState({anthropic:null,openai:null}),[me,G]=p.useState(null),[J,X]=p.useState([]),[ae,re]=p.useState(""),[le,W]=p.useState(null),[Q,oe]=p.useState(!1),[xe,de]=p.useState(null),[ie,l]=p.useState(null),[c,h]=p.useState(!1),[b,k]=p.useState(null),[M,S]=p.useState(!0),[$,Z]=p.useState({}),N=(r==null?void 0:r.providers)??[],Ee=N.length,ee=p.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")},{key:"anthropic-dangerous-direct-browser-access",value:"true",label:s("providers.testDialog.options.browser.label"),description:s("providers.testDialog.options.browser.description")},{key:"x-app",value:"cli",label:s("providers.testDialog.options.xApp.label"),description:s("providers.testDialog.options.xApp.description")},{key:"user-agent",value:"claude-cli/2.0.14 (external, cli)",label:s("providers.testDialog.options.userAgent.label"),description:s("providers.testDialog.options.userAgent.description")},{key:"accept",value:"application/json",label:s("providers.testDialog.options.accept.label"),description:s("providers.testDialog.options.accept.description")},{key:"accept-language",value:"*",label:s("providers.testDialog.options.acceptLanguage.label"),description:s("providers.testDialog.options.acceptLanguage.description")},{key:"sec-fetch-mode",value:"cors",label:s("providers.testDialog.options.secFetchMode.label"),description:s("providers.testDialog.options.secFetchMode.description")},{key:"accept-encoding",value:"gzip, deflate",label:s("providers.testDialog.options.acceptEncoding.label"),description:s("providers.testDialog.options.acceptEncoding.description")},{key:"x-stainless-helper-method",value:"stream",label:s("providers.testDialog.options.stainlessHelper.label"),description:s("providers.testDialog.options.stainlessHelper.description")},{key:"x-stainless-retry-count",value:"0",label:s("providers.testDialog.options.stainlessRetry.label"),description:s("providers.testDialog.options.stainlessRetry.description")},{key:"x-stainless-timeout",value:"600",label:s("providers.testDialog.options.stainlessTimeout.label"),description:s("providers.testDialog.options.stainlessTimeout.description")},{key:"x-stainless-lang",value:"js",label:s("providers.testDialog.options.stainlessLang.label"),description:s("providers.testDialog.options.stainlessLang.description")},{key:"x-stainless-package-version",value:"0.60.0",label:s("providers.testDialog.options.stainlessPackage.label"),description:s("providers.testDialog.options.stainlessPackage.description")},{key:"x-stainless-os",value:"MacOS",label:s("providers.testDialog.options.stainlessOs.label"),description:s("providers.testDialog.options.stainlessOs.description")},{key:"x-stainless-arch",value:"arm64",label:s("providers.testDialog.options.stainlessArch.label"),description:s("providers.testDialog.options.stainlessArch.description")},{key:"x-stainless-runtime",value:"node",label:s("providers.testDialog.options.stainlessRuntime.label"),description:s("providers.testDialog.options.stainlessRuntime.description")},{key:"x-stainless-runtime-version",value:"v22.14.0",label:s("providers.testDialog.options.stainlessRuntimeVersion.label"),description:s("providers.testDialog.options.stainlessRuntimeVersion.description")}],[s]);p.useEffect(()=>{var t;if(m.data){const a=m.data;u(a),w(ge(a)),E({anthropic:null,openai:null}),X(((t=a.routingPresets)==null?void 0:t.anthropic)??[])}},[m.data]),p.useEffect(()=>{m.isError&&m.error&&n({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,n,s]);const Ue=p.useMemo(()=>{const t=new Map;for(const a of N){if(!a.defaultModel||!a.models)continue;const o=a.models.find(d=>d.id===a.defaultModel);o&&t.set(a.id,Re(o))}return t},[N]),je=p.useMemo(()=>{const t=[],a=new Set;for(const d of N){const i=d.label||d.id,g=d.models??[];if(g.length>0)for(const y of g){const x=`${d.id}:${y.id}`;a.has(x)||(a.add(x),t.push({value:x,label:`${i} · ${y.label??y.id}`}))}else if(d.defaultModel){const y=`${d.id}:${d.defaultModel}`;a.has(y)||(a.add(y),t.push({value:y,label:`${i} · ${d.defaultModel}`}))}const j=`${d.id}:*`;a.has(j)||(a.add(j),t.push({value:j,label:s("settings.routing.providerPassthroughOption",{provider:i})}))}const o=[...I.anthropic,...I.openai];for(const d of o){const i=d.target.trim();i&&!a.has(i)&&(a.add(i),t.push({value:i,label:i}))}return t},[N,I,s]),ye=t=>{X(t),u(a=>a&&{...a,routingPresets:{...a.routingPresets,anthropic:t}})},H=()=>r?!0:(n({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),Le=t=>{re(t),t.trim()&&W(null)},Ae=async()=>{if(!H())return;const t=ae.trim();if(!t){W(s("modelManagement.validation.presetName"));return}if(J.some(a=>a.name.toLowerCase()===t.toLowerCase())){W(s("modelManagement.validation.presetDuplicate",{name:t}));return}oe(!0);try{const o=(await V.post("/api/routing-presets/anthropic",{name:t})).data.presets??[];ye(o),re(""),W(null),n({title:s("modelManagement.toast.presetSaved",{name:t}),variant:"success"})}catch(a){n({title:s("modelManagement.toast.presetSaveFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{oe(!1),m.refetch()}},Te=async t=>{var a;if(H()){de(t.name);try{const d=(await V.post("/api/routing-presets/anthropic/apply",{name:t.name})).data.config;d?(u(d),w(ge(d)),X(((a=d.routingPresets)==null?void 0:a.anthropic)??[])):w(i=>({...i,anthropic:z(t.modelRoutes)})),n({title:s("modelManagement.toast.presetApplySuccess",{name:t.name}),variant:"success"})}catch(o){n({title:s("modelManagement.toast.presetApplyFailure",{message:o instanceof Error?o.message:"unknown"}),variant:"error"})}finally{de(null),m.refetch()}}},Oe=async t=>{if(!(!H()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:t.name})))){l(t.name);try{const d=(await V.delete(`/api/routing-presets/anthropic/${encodeURIComponent(t.name)}`)).data.presets??[];ye(d),n({title:s("modelManagement.toast.presetDeleteSuccess",{name:t.name}),variant:"success"})}catch(o){n({title:s("modelManagement.toast.presetDeleteFailure",{message:o instanceof Error?o.message:"unknown"}),variant:"error"})}finally{l(null),m.refetch()}}},Ie=()=>{H()&&(_("create"),q(void 0),v(!0))},$e=t=>{H()&&(_("edit"),q(t),v(!0))},Ke=async t=>{if(!r)throw new Error(s("settings.toast.missingConfig"));const a=A==="create"?[...N,t]:N.map(i=>U&&i.id===U.id?{...t,id:U.id}:i),o={...r,providers:a};await V.put("/api/config",o),u(o),w(ge(o)),m.refetch();const d=A==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});n({title:d,variant:"success"})},Ne=async(t,a)=>{se(t.id);try{const o=a&&(a.headers||a.query)?{headers:a.headers&&Object.keys(a.headers).length>0?a.headers:void 0,query:a.query&&a.query.trim().length>0?a.query.trim():void 0}:void 0,d=await V.post(`/api/providers/${t.id}/test`,o);d.data.ok?n({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:d.data.status,duration:d.data.durationMs?`${d.data.durationMs} ms`:"—"}),variant:"success"}):n({title:s("providers.toast.testFailure",{message:`${d.data.status} ${d.data.statusText}`}),variant:"error"})}catch(o){n({title:s("providers.toast.testFailure",{message:o instanceof Error?o.message:"unknown"}),variant:"error"})}finally{se(null)}},_e=t=>{if(t.type==="anthropic"){const a=t.extraHeaders??{},o=new Map(ee.map(g=>[g.key.toLowerCase(),g])),d={};let i=!0;for(const g of ee){const j=Object.entries(a).find(([y])=>y.toLowerCase()===g.key.toLowerCase());if(j){const[y,x]=j;String(x??"")===g.value||(i=!1,d[y]=String(x??""))}}for(const[g,j]of Object.entries(a))o.has(g.toLowerCase())||(d[g]=String(j??""));Z(d),S(i),k(t),h(!0);return}Ne(t)},we=()=>{h(!1),k(null),S(!0),Z({})},Be=async()=>{if(!b)return;const t={};if(M)for(const d of ee)t[d.key]=d.value;const a=new Map(ee.map(d=>[d.key.toLowerCase(),d]));for(const[d,i]of Object.entries($)){const g=d.toLowerCase();a.get(g)&&M||(t[d]=i)}const o=b;we(),await Ne(o,{headers:Object.keys(t).length>0?t:void 0,query:M?"beta=true":void 0})},Fe=async t=>{var x,R,C,K;if(!H()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const o=N.filter(T=>T.id!==t.id),d=T=>{const P={};if(!T)return P;for(const[ce,ue]of Object.entries(T)){if(!ue)continue;const[Me]=ue.split(":");Me&&Me===t.id||ue===t.id||(P[ce]=ue)}return P},i=(r==null?void 0:r.endpointRouting)??{},g=d(((x=i.anthropic)==null?void 0:x.modelRoutes)??(r==null?void 0:r.modelRoutes)??{}),j=d(((R=i.openai)==null?void 0:R.modelRoutes)??{}),y={...r,providers:o,modelRoutes:g,endpointRouting:{anthropic:{defaults:((C=i.anthropic)==null?void 0:C.defaults)??r.defaults,modelRoutes:g},openai:{defaults:((K=i.openai)==null?void 0:K.defaults)??r.defaults,modelRoutes:j}}};try{await V.put("/api/config",y),u(y),w({anthropic:z(g),openai:z(j)}),n({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(T){n({title:s("providers.toast.deleteFailure",{message:T instanceof Error?T.message:"unknown"}),variant:"error"})}},He=t=>{w(a=>({...a,[t]:[...a[t],{id:fe(),source:"",target:""}]})),E(a=>({...a,[t]:null}))},Ve=(t,a)=>{w(o=>o[t].some(d=>d.source.trim()===a.trim())?o:{...o,[t]:[...o[t],{id:fe(),source:a,target:""}]}),E(o=>({...o,[t]:null}))},ne=(t,a,o,d)=>{w(i=>({...i,[t]:i[t].map(g=>g.id===a?{...g,[o]:d}:g)})),E(i=>({...i,[t]:null}))},ze=(t,a)=>{w(o=>({...o,[t]:o[t].filter(d=>d.id!==a)})),E(o=>({...o,[t]:null}))},qe=t=>{var i;if(!r)return;const a=r.endpointRouting??{},o=t==="anthropic"?r.modelRoutes??{}:{},d=((i=a[t])==null?void 0:i.modelRoutes)??o;w(g=>({...g,[t]:z(d)})),E(g=>({...g,[t]:null}))},Ge=async t=>{var d,i,g,j,y;if(!H())return;const a=I[t],o={};for(const x of a){const R=x.source.trim(),C=x.target.trim();if(!(!R&&!C)){if(!R||!C){E(K=>({...K,[t]:s("settings.validation.routePair")}));return}if(o[R]){E(K=>({...K,[t]:s("settings.validation.routeDuplicate",{model:R})}));return}o[R]=C}}E(x=>({...x,[t]:null})),G(t);try{const x=r.endpointRouting??{anthropic:{defaults:r.defaults,modelRoutes:r.modelRoutes??{}},openai:{defaults:((i=(d=r.endpointRouting)==null?void 0:d.openai)==null?void 0:i.defaults)??r.defaults,modelRoutes:((j=(g=r.endpointRouting)==null?void 0:g.openai)==null?void 0:j.modelRoutes)??{}}},R={...x,[t]:{defaults:((y=x[t])==null?void 0:y.defaults)??r.defaults,modelRoutes:o}},C={...r,endpointRouting:R,modelRoutes:t==="anthropic"?o:r.modelRoutes??{}};await V.put("/api/config",C),u(C),w(K=>({...K,[t]:z(o)})),n({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}catch(x){n({title:s("modelManagement.toast.routesSaveFailure",{message:x instanceof Error?x.message:"unknown"}),variant:"error"})}finally{G(null)}},We=()=>e.jsxs("section",{className:Ce,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800 dark:text-slate-100",children:s("providers.title")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:s("providers.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:Ze.default,children:s("providers.count",{count:Ee})}),e.jsx("button",{type:"button",className:O,onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:te,onClick:Ie,children:s("providers.actions.add")})]})]}),m.isPending||!r&&m.isFetching?e.jsx("section",{className:"flex min-h-[200px] items-center justify-center rounded-3xl border border-slate-200/50 bg-gradient-to-br from-white/80 to-white/70 text-sm text-slate-600 dark:border-slate-700/50 dark:from-slate-900/80 dark:to-slate-900/70 dark:text-slate-400 backdrop-blur-lg",children:s("common.loading")}):N.length===0?e.jsx("section",{className:"rounded-3xl border border-dashed border-slate-300/60 bg-gradient-to-br from-slate-50/80 to-white/70 p-12 text-center text-sm text-slate-600 dark:border-slate-600/60 dark:from-slate-900/80 dark:to-slate-800/70 dark:text-slate-400 backdrop-blur-lg",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"rounded-2xl bg-slate-200/50 p-4 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-8 w-8 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]})]})}):e.jsx("div",{className:"grid gap-6 md:grid-cols-2 xl:grid-cols-3",children:N.map(t=>e.jsxs("article",{className:"group flex h-full flex-col gap-5 rounded-3xl border border-slate-200/50 bg-gradient-to-br from-white/85 via-white/80 to-white/75 p-6 shadow-lg shadow-slate-200/30 backdrop-blur-md transition-all duration-300 hover:border-slate-200/70 hover:shadow-xl hover:shadow-slate-200/50 hover:-translate-y-1 dark:border-slate-700/50 dark:from-slate-900/85 dark:via-slate-900/80 dark:to-slate-900/75 dark:shadow-2xl dark:shadow-slate-900/40 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/90",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-blue-500 via-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-500/30",children:e.jsx("span",{className:"text-lg font-bold",children:(t.label||t.id).charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-800 dark:text-slate-100",children:t.label||t.id}),t.type?e.jsx(dt,{type:t.type}):null]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["ID: ",t.id]})]})]}),e.jsxs("div",{className:"mt-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400 font-medium",children:"Base URL:"}),e.jsx("p",{className:"text-xs font-mono text-slate-700 dark:text-slate-300 bg-slate-100/50 dark:bg-slate-800/50 rounded-lg px-2 py-1 break-all",children:t.baseUrl})]})]}),e.jsx("div",{className:"flex flex-col gap-2",children:t.defaultModel?e.jsx("div",{className:De.success,children:s("providers.card.defaultModel",{model:Ue.get(t.id)??t.defaultModel})}):e.jsx("div",{className:De.info,children:s("providers.card.noDefault")})})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h4",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:t.models.map(a=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-slate-200/60 bg-gradient-to-r from-slate-50/80 to-slate-100/70 px-3 py-1.5 text-xs dark:border-slate-700/60 dark:from-slate-800/60 dark:to-slate-700/50 backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-slate-100/80 dark:hover:border-slate-600/70 dark:hover:bg-slate-700/60",children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-blue-500"}),e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:Re(a)})]},a.id))}):e.jsx("div",{className:"rounded-xl border border-dashed border-slate-300/50 bg-slate-50/50 px-4 py-3 text-xs text-slate-500 dark:border-slate-600/50 dark:bg-slate-800/30 dark:text-slate-400",children:s("providers.card.noModels")})]}),e.jsxs("footer",{className:"mt-auto flex flex-wrap gap-3 pt-2 border-t border-slate-200/30 dark:border-slate-700/30",children:[e.jsx("button",{type:"button",className:O,onClick:()=>$e(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>_e(t),disabled:B===t.id,className:B===t.id?`${O} opacity-60 cursor-not-allowed`:O,children:B===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:pe,onClick:()=>Fe(t),children:s("providers.actions.delete")})]})]},t.id))})]}),Qe=()=>e.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-300/60 bg-gradient-to-br from-slate-50/80 to-white/70 p-6 dark:border-slate-600/60 dark:from-slate-800/60 dark:to-slate-900/70 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h3",{className:"text-base font-bold text-slate-800 dark:text-slate-100",children:s("modelManagement.presets.title")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:s("modelManagement.presets.description")})]}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx("input",{type:"text",value:ae,onChange:t=>Le(t.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:be,disabled:Q}),e.jsx("button",{type:"button",onClick:Ae,className:te,disabled:Q,children:s(Q?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),le?e.jsx("div",{className:"rounded-xl bg-red-50/80 border border-red-200/50 p-3 text-xs text-red-700 dark:bg-red-900/40 dark:border-red-800/50 dark:text-red-300 backdrop-blur-sm",children:le}):null,J.length===0?e.jsx("div",{className:"rounded-xl border border-slate-200/40 bg-slate-50/60 p-6 text-center text-sm text-slate-600 dark:border-slate-700/40 dark:bg-slate-800/40 dark:text-slate-400 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"rounded-xl bg-slate-200/50 p-3 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-6 w-6 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("modelManagement.presets.empty")})]})}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:J.map(t=>{const a=xe===t.name,o=ie===t.name;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-slate-200/50 bg-gradient-to-r from-white/90 to-white/80 px-4 py-3 text-sm shadow-sm backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-white/95 hover:shadow-md dark:border-slate-700/50 dark:from-slate-900/90 dark:to-slate-900/80 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/95",children:[e.jsx("span",{className:"truncate font-medium text-slate-700 dark:text-slate-200",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Te(t),className:a||o?`${O} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${te} text-xs px-2 py-1`,disabled:a||o,children:s(a?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>Oe(t),className:o||a?`${O} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${pe} text-xs px-2 py-1`,disabled:o||a,children:s(o?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},t.name)})})]}),Ye=t=>{const a=I[t],o=F[t],d=t==="anthropic"?rt:lt,i=me===t,g=s(`modelManagement.tabs.${t}`),j=`route-source-${t}`,y=`route-target-${t}`;return e.jsxs("section",{className:Ce,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800 dark:text-slate-100",children:s("settings.routing.titleByEndpoint",{endpoint:g})}),e.jsx("p",{className:"max-w-3xl text-sm text-slate-600 dark:text-slate-400",children:s(`settings.routing.descriptionByEndpoint.${t}`)}),e.jsx("p",{className:"max-w-3xl text-xs text-slate-500 dark:text-slate-400",children:s("settings.routing.wildcardHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>He(t),className:O,disabled:i,children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>qe(t),className:O,disabled:i,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Ge(t),className:te,disabled:i,children:s(i?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),t==="anthropic"?Qe():null,o?e.jsx("div",{className:"rounded-xl bg-red-50/80 border border-red-200/50 p-4 text-sm text-red-700 dark:bg-red-900/40 dark:border-red-800/50 dark:text-red-300 backdrop-blur-sm",children:o}):null,a.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-slate-300/60 bg-gradient-to-br from-slate-50/80 to-white/70 p-12 text-center text-sm text-slate-600 dark:border-slate-600/60 dark:from-slate-800/60 dark:to-slate-900/70 dark:text-slate-400 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"rounded-2xl bg-slate-200/50 p-4 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-8 w-8 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("settings.routing.emptySub",{default:"点击上方按钮添加路由规则"})})]})]})}):e.jsx("div",{className:"space-y-4",children:a.map((x,R)=>e.jsxs("div",{className:"rounded-xl border border-slate-200/50 bg-gradient-to-r from-white/90 to-white/85 p-4 shadow-sm backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-white/95 hover:shadow-md dark:border-slate-700/50 dark:from-slate-900/90 dark:to-slate-900/85 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/95",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300",children:e.jsx("span",{className:"text-sm font-bold",children:R+1})}),e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-300",children:"路由规则"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("settings.routing.source")}),e.jsx("input",{type:"text",value:x.source,onChange:C=>ne(t,x.id,"source",C.target.value),className:be,placeholder:"claude-3.5-sonnet",list:j,disabled:i})]})}),e.jsx("div",{className:"space-y-2",children:e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("settings.routing.target")}),(()=>{const C=x.target.trim(),T=je.some(P=>P.value===C)?C:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:T,onChange:P=>{const ce=P.target.value;ce==="__custom"?ne(t,x.id,"target",C):ne(t,x.id,"target",ce)},className:et,disabled:i,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),je.map(P=>e.jsx("option",{value:P.value,children:P.label},`${y}-${P.value}`))]}),T==="__custom"&&e.jsx("input",{type:"text",value:x.target,onChange:P=>ne(t,x.id,"target",P.target.value),className:be,placeholder:"providerId:modelId",disabled:i})]})})()]})}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:pe,onClick:()=>ze(t,x.id),disabled:i,children:s("settings.routing.remove")})})]})]},x.id))}),e.jsx("div",{className:"rounded-xl border border-slate-200/40 bg-gradient-to-r from-slate-50/80 to-white/70 p-4 dark:border-slate-700/40 dark:from-slate-800/60 dark:to-slate-900/70 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("settings.routing.suggested")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(x=>e.jsx("button",{type:"button",onClick:()=>Ve(t,x),className:O,disabled:i,children:x},`${t}-${x}`))})]})}),e.jsx("datalist",{id:j,children:d.map(x=>e.jsx("option",{value:x},`${j}-${x}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx("div",{className:Xe,children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-900 to-slate-700 bg-clip-text text-transparent dark:from-slate-100 dark:to-slate-300",children:s("modelManagement.title")}),e.jsx("p",{className:"text-base text-slate-600 dark:text-slate-400",children:s("modelManagement.description")})]})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:L.map(t=>{const a=D===t.key;return e.jsxs("button",{type:"button",onClick:()=>Y(t.key),className:`flex min-w-[240px] flex-col gap-2 rounded-2xl border px-6 py-4 text-left transition-all duration-300 hover-lift ${a?"border-blue-500/30 bg-gradient-to-r from-blue-50 to-indigo-50 text-blue-700 shadow-lg shadow-blue-200/40 ring-1 ring-blue-500/20 dark:border-blue-400/30 dark:from-blue-900/40 dark:to-indigo-900/30 dark:text-blue-100 dark:shadow-xl dark:shadow-blue-500/20 dark:ring-blue-400/20":"border-slate-200/50 bg-white/80 hover:bg-white/90 hover:shadow-md hover:shadow-slate-200/30 dark:border-slate-700/50 dark:bg-slate-900/80 dark:hover:bg-slate-900/90 dark:hover:shadow-lg dark:hover:shadow-slate-900/30"}`,children:[e.jsx("span",{className:"text-base font-bold",children:t.label}),e.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:t.description})]},t.key)})}),D==="providers"?We():Ye(D),e.jsx(at,{open:f,mode:A,provider:A==="edit"?U:void 0,existingProviderIds:N.map(t=>t.id).filter(t=>A==="edit"&&U?t!==U.id:!0),onClose:()=>{v(!1),q(void 0),_("create")},onSubmit:Ke}),e.jsx(ot,{open:c,provider:b,options:ee,preservedExtras:$,usePreset:M,onPresetChange:S,onConfirm:Be,onClose:we})]})}function ot({open:s,provider:n,options:m,usePreset:L,preservedExtras:D,onPresetChange:Y,onConfirm:r,onClose:u}){const{t:f}=ve();return!s||!n?null:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:u,"aria-hidden":"true"}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"connection-test-dialog-title",className:"relative z-10 w-full max-w-lg rounded-2xl border border-slate-200/70 bg-white/95 p-6 shadow-2xl backdrop-blur-xl animate-fade-in dark:border-slate-800/60 dark:bg-slate-900/95",children:[e.jsxs("header",{className:"mb-4 space-y-1",children:[e.jsx("h2",{id:"connection-test-dialog-title",className:"text-lg font-semibold text-slate-900 dark:text-slate-100",children:f("providers.testDialog.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:f("providers.testDialog.subtitle",{name:n.label||n.id})})]}),e.jsx("p",{className:"mb-5 text-sm leading-relaxed text-slate-600 dark:text-slate-300",children:f("providers.testDialog.description")}),e.jsx("div",{className:"space-y-3",children:e.jsxs("label",{className:"flex items-start gap-3 rounded-xl border border-slate-200 bg-white/90 p-4 shadow-sm transition hover:border-blue-200 hover:bg-blue-50/70 dark:border-slate-700 dark:bg-slate-800/70 dark:hover:border-blue-500/60 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-500",checked:L,onChange:v=>Y(v.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-800 dark:text-slate-100",children:f("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs leading-relaxed text-slate-500 dark:text-slate-400",children:f("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-lg bg-slate-50/60 px-3 py-2 text-xs text-slate-600 transition dark:bg-slate-800/50 dark:text-slate-300",children:[e.jsx("summary",{className:"cursor-pointer text-blue-600 hover:underline dark:text-blue-300",children:f("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 grid gap-1",children:m.map(v=>e.jsxs("code",{className:"rounded bg-white/80 px-2 py-1 text-[11px] text-slate-700 shadow-sm dark:bg-slate-900/60 dark:text-slate-200",children:[v.key,": ",v.value]},v.key))})]})]})]})}),Object.keys(D).length>0?e.jsxs("div",{className:"mt-6 rounded-xl border border-slate-200 bg-slate-50/80 p-4 text-xs text-slate-600 dark:border-slate-700 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"mb-2 font-semibold text-slate-700 dark:text-slate-200",children:f("providers.testDialog.preservedInfo")}),e.jsx("div",{className:"grid gap-2",children:Object.entries(D).map(([v,A])=>e.jsxs("code",{className:"rounded bg-white/70 px-2 py-1 text-[11px] text-slate-700 shadow-sm dark:bg-slate-900/70 dark:text-slate-200",children:[v,": ",A]},v))})]}):null,e.jsxs("footer",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:u,className:O,children:f("providers.testDialog.cancel")}),e.jsx("button",{type:"button",onClick:()=>{r()},className:te,children:f("providers.testDialog.primary")})]})]})]})}function Re(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function dt({type:s}){const n={openai:{label:"OpenAI",color:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300"},deepseek:{label:"DeepSeek",color:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300"},huawei:{label:"华为云",color:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300"},kimi:{label:"Kimi",color:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300"},anthropic:{label:"Anthropic",color:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300"},custom:{label:"Custom",color:"bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"}},{label:m,color:L}=n[s]||n.custom;return e.jsx("span",{className:`rounded-full ${L} px-2.5 py-1 text-xs font-semibold shadow-sm`,children:m})}export{ct as default};
|