@chenpu17/cc-gw 0.7.0 → 0.7.2
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/server/index.js +23 -55
- package/web/assets/{About-CuhVJpOY.js → About-BY3JDEBL.js} +2 -2
- package/web/assets/{ApiKeys-Cj7BE4i-.js → ApiKeys-qhC2jZqJ.js} +1 -1
- package/web/assets/{Button-C32hr6jT.js → Button-6f5FYqHp.js} +1 -1
- package/web/assets/{Dashboard-Bfw6yiF4.js → Dashboard-xs4UfKRq.js} +1 -1
- package/web/assets/{Events-DjBfGGvr.js → Events-D_RJKNNo.js} +1 -1
- package/web/assets/{FormField-8w92_1Tx.js → FormField-DKWx0tXD.js} +1 -1
- package/web/assets/{Help-CboPPlN8.js → Help-CXLtGK8v.js} +1 -1
- package/web/assets/{Input-BBMxqTTH.js → Input-Iev5RCKK.js} +1 -1
- package/web/assets/{Login-DdvwaiG0.js → Login-qc-n0iUi.js} +1 -1
- package/web/assets/{Logs-CCyXKpHp.js → Logs-DSGqxauM.js} +1 -1
- package/web/assets/{ModelManagement-EGKGD6z0.js → ModelManagement-D11jx2bC.js} +1 -1
- package/web/assets/{PageSection-CJ0vDlWb.js → PageSection-BJJ735Qk.js} +1 -1
- package/web/assets/{Settings-DtX-SQH8.js → Settings-BT-6W3GT.js} +1 -1
- package/web/assets/{StatusBadge-DphP4K9e.js → StatusBadge-9lxhNpvi.js} +1 -1
- package/web/assets/{copy-DKUCqVEJ.js → copy-DMW-t8h3.js} +1 -1
- package/web/assets/{index-CCRGLvYb.js → index-BM-Zc1f-.js} +1 -1
- package/web/assets/{index-B1C47gGx.js → index-dFe_7qSp.js} +2 -2
- package/web/assets/{info-BDaov2xM.js → info-ByJJXVcp.js} +1 -1
- package/web/assets/{refresh-cw-CI3kg9Ko.js → refresh-cw-BF1LiBLP.js} +1 -1
- package/web/assets/{useApiQuery-CvZfYN_4.js → useApiQuery-i7GI_aGQ.js} +1 -1
- package/web/index.html +1 -1
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -14725,20 +14725,20 @@ function normalizeOpenAIChatPayload(payload) {
|
|
|
14725
14725
|
}
|
|
14726
14726
|
|
|
14727
14727
|
// routes/shared/models-handler.ts
|
|
14728
|
-
function buildModelsResponse(configSnapshot) {
|
|
14728
|
+
function buildModelsResponse(configSnapshot, endpointId) {
|
|
14729
14729
|
const now = Math.floor(Date.now() / 1e3);
|
|
14730
14730
|
const models = /* @__PURE__ */ new Map();
|
|
14731
|
-
const addModel = (modelId,
|
|
14731
|
+
const addModel = (modelId, targetProvider, targetModel) => {
|
|
14732
14732
|
const trimmed = modelId.trim();
|
|
14733
14733
|
if (!trimmed)
|
|
14734
14734
|
return;
|
|
14735
14735
|
const existing = models.get(trimmed);
|
|
14736
14736
|
if (existing) {
|
|
14737
14737
|
const routeExists = existing.routedTo.some(
|
|
14738
|
-
(r) => r.
|
|
14738
|
+
(r) => r.targetProvider === targetProvider && r.targetModel === targetModel
|
|
14739
14739
|
);
|
|
14740
14740
|
if (!routeExists) {
|
|
14741
|
-
existing.routedTo.push({
|
|
14741
|
+
existing.routedTo.push({ targetProvider, targetModel });
|
|
14742
14742
|
}
|
|
14743
14743
|
return;
|
|
14744
14744
|
}
|
|
@@ -14750,58 +14750,27 @@ function buildModelsResponse(configSnapshot) {
|
|
|
14750
14750
|
owned_by: "gateway",
|
|
14751
14751
|
permission: []
|
|
14752
14752
|
},
|
|
14753
|
-
routedTo: [{
|
|
14753
|
+
routedTo: [{ targetProvider, targetModel }]
|
|
14754
14754
|
});
|
|
14755
14755
|
};
|
|
14756
|
-
|
|
14757
|
-
|
|
14758
|
-
|
|
14759
|
-
|
|
14760
|
-
|
|
14761
|
-
|
|
14762
|
-
|
|
14763
|
-
|
|
14764
|
-
|
|
14765
|
-
}
|
|
14766
|
-
if (routing.defaults?.completion) {
|
|
14767
|
-
addModel(routing.defaults.completion, endpointName, "default", routing.defaults.completion);
|
|
14768
|
-
}
|
|
14769
|
-
if (routing.defaults?.reasoning) {
|
|
14770
|
-
addModel(routing.defaults.reasoning, endpointName, "default", routing.defaults.reasoning);
|
|
14771
|
-
}
|
|
14772
|
-
if (routing.defaults?.background) {
|
|
14773
|
-
addModel(routing.defaults.background, endpointName, "default", routing.defaults.background);
|
|
14774
|
-
}
|
|
14775
|
-
}
|
|
14776
|
-
const customEndpoints = configSnapshot.customEndpoints ?? [];
|
|
14777
|
-
for (const customEndpoint of customEndpoints) {
|
|
14778
|
-
if (!customEndpoint.routing?.modelRoutes)
|
|
14779
|
-
continue;
|
|
14780
|
-
for (const [sourceModel, target] of Object.entries(customEndpoint.routing.modelRoutes)) {
|
|
14781
|
-
const [providerId, targetModel] = target.split(":");
|
|
14782
|
-
if (providerId && targetModel) {
|
|
14783
|
-
addModel(sourceModel, `custom:${customEndpoint.id}`, providerId, targetModel);
|
|
14756
|
+
if (endpointId.startsWith("custom:")) {
|
|
14757
|
+
const customId = endpointId.slice(7);
|
|
14758
|
+
const customEndpoint = configSnapshot.customEndpoints?.find((e) => e.id === customId);
|
|
14759
|
+
if (customEndpoint?.routing?.modelRoutes) {
|
|
14760
|
+
for (const [sourceModel, target] of Object.entries(customEndpoint.routing.modelRoutes)) {
|
|
14761
|
+
const [providerId, targetModel] = target.split(":");
|
|
14762
|
+
if (providerId && targetModel) {
|
|
14763
|
+
addModel(sourceModel, providerId, targetModel);
|
|
14764
|
+
}
|
|
14784
14765
|
}
|
|
14785
14766
|
}
|
|
14786
|
-
|
|
14787
|
-
|
|
14788
|
-
|
|
14789
|
-
|
|
14790
|
-
|
|
14791
|
-
|
|
14792
|
-
|
|
14793
|
-
if (defaults?.background) {
|
|
14794
|
-
addModel(defaults.background, `custom:${customEndpoint.id}`, "default", defaults.background);
|
|
14795
|
-
}
|
|
14796
|
-
}
|
|
14797
|
-
if (models.size === 0) {
|
|
14798
|
-
for (const provider of configSnapshot.providers) {
|
|
14799
|
-
if (provider.defaultModel) {
|
|
14800
|
-
addModel(provider.defaultModel, "fallback", provider.id, provider.defaultModel);
|
|
14801
|
-
}
|
|
14802
|
-
if (Array.isArray(provider.models)) {
|
|
14803
|
-
for (const model of provider.models) {
|
|
14804
|
-
addModel(model.id, "fallback", provider.id, model.id);
|
|
14767
|
+
} else {
|
|
14768
|
+
const routing = configSnapshot.endpointRouting?.[endpointId];
|
|
14769
|
+
if (routing?.modelRoutes) {
|
|
14770
|
+
for (const [sourceModel, target] of Object.entries(routing.modelRoutes)) {
|
|
14771
|
+
const [providerId, targetModel] = target.split(":");
|
|
14772
|
+
if (providerId && targetModel) {
|
|
14773
|
+
addModel(sourceModel, providerId, targetModel);
|
|
14805
14774
|
}
|
|
14806
14775
|
}
|
|
14807
14776
|
}
|
|
@@ -14809,7 +14778,6 @@ function buildModelsResponse(configSnapshot) {
|
|
|
14809
14778
|
const data = Array.from(models.values()).map(({ entry, routedTo }) => {
|
|
14810
14779
|
const metadata = {
|
|
14811
14780
|
routes: routedTo.map((r) => ({
|
|
14812
|
-
endpoint: r.endpoint,
|
|
14813
14781
|
target: `${r.targetProvider}:${r.targetModel}`
|
|
14814
14782
|
}))
|
|
14815
14783
|
};
|
|
@@ -16263,7 +16231,7 @@ async function registerOpenAiRoutes(app) {
|
|
|
16263
16231
|
throw error;
|
|
16264
16232
|
}
|
|
16265
16233
|
const configSnapshot = getConfig();
|
|
16266
|
-
const data = buildModelsResponse(configSnapshot);
|
|
16234
|
+
const data = buildModelsResponse(configSnapshot, "openai");
|
|
16267
16235
|
reply.header("content-type", "application/json");
|
|
16268
16236
|
return {
|
|
16269
16237
|
object: "list",
|
|
@@ -18159,7 +18127,7 @@ async function registerModelsHandler(app, path5, endpointId) {
|
|
|
18159
18127
|
throw error;
|
|
18160
18128
|
}
|
|
18161
18129
|
const configSnapshot = getConfig();
|
|
18162
|
-
const data = buildModelsResponse(configSnapshot);
|
|
18130
|
+
const data = buildModelsResponse(configSnapshot, `custom:${endpointId}`);
|
|
18163
18131
|
reply.header("content-type", "application/json");
|
|
18164
18132
|
return {
|
|
18165
18133
|
object: "list",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{c as f,u as v,a as j,r,j as e,d as o,W as k,m as i}from"./index-
|
|
1
|
+
import{c as f,u as v,a as j,r,j as e,d as o,W as k,m as i}from"./index-dFe_7qSp.js";import{u as N}from"./useApiQuery-i7GI_aGQ.js";import{P as w,a as d}from"./PageSection-BJJ735Qk.js";import"./Input-Iev5RCKK.js";import{B as b}from"./Button-6f5FYqHp.js";import{I as T}from"./info-ByJJXVcp.js";import{R as y}from"./refresh-cw-BF1LiBLP.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const E=f("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"}]]),I="0.7.
|
|
6
|
+
*/const E=f("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"}]]),I="0.7.2",_={version:I},L={VITE_BUILD_TIME:"2025-11-24T01:58:58.267Z",VITE_NODE_VERSION:"v22.16.0"};function m({items:t}){return t.length===0?null:e.jsx("dl",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-2",children:t.map(s=>e.jsxs("div",{className:"rounded-2xl border border-slate-200/50 bg-white p-4 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-200/70 hover:shadow-md hover:shadow-slate-200/40 dark:border-slate-700/50 dark:bg-slate-900/80 dark:shadow-lg dark:shadow-slate-900/30 dark:hover:border-slate-600/70",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-slate-500 dark:text-slate-400",children:s.label}),e.jsx("dd",{className:"mt-2 text-base font-semibold text-slate-900 dark:text-slate-100",children:s.value}),s.hint?e.jsx("p",{className:o(i,"mt-2 text-xs leading-relaxed"),children:s.hint}):null]},s.label))})}function D(){const{t}=v(),{pushToast:s}=j(),a=N(["status","gateway"],{url:"/api/status",method:"GET"},{staleTime:6e4});r.useEffect(()=>{a.isError&&a.error&&s({title:t("about.toast.statusError.title"),description:a.error.message,variant:"error"})},[a.isError,a.error,s,t]);const n=_.version,l=r.useMemo(()=>{const u=L,h=u.VITE_BUILD_TIME,g=u.VITE_NODE_VERSION;return{buildTime:h,nodeVersion:g}},[]),p=r.useMemo(()=>[{label:t("about.app.labels.name"),value:e.jsx("span",{className:"font-mono text-sm font-semibold text-slate-900 dark:text-slate-100",children:"cc-gw"})},{label:t("about.app.labels.version"),value:e.jsxs("span",{className:"font-mono text-sm font-semibold text-blue-700 dark:text-blue-200",children:["v",n]})},{label:t("about.app.labels.buildTime"),value:l.buildTime,hint:t("about.app.hint.buildTime")},{label:t("about.app.labels.node"),value:e.jsx("span",{className:"font-mono text-sm text-slate-800 dark:text-slate-200",children:l.nodeVersion})}],[n,l.buildTime,l.nodeVersion,t]),c=r.useMemo(()=>a.data?[{label:t("about.status.labels.host"),value:a.data.host??"127.0.0.1"},{label:t("about.status.labels.port"),value:a.data.port.toLocaleString()},{label:t("about.status.labels.providers"),value:a.data.providers.toLocaleString()},{label:t("about.status.labels.active"),value:(a.data.activeRequests??0).toLocaleString(),hint:t("about.status.hint.active")}]:[],[a.data,t]),x=()=>{s({title:t("about.toast.updatesPlanned"),variant:"info"})};return e.jsxs("div",{className:"space-y-8",children:[e.jsx(w,{icon:e.jsx(T,{className:"h-6 w-6","aria-hidden":"true"}),title:t("about.title"),description:t("about.description"),badge:`v${n}`,actions:e.jsx(b,{variant:"primary",icon:e.jsx(E,{className:"h-4 w-4","aria-hidden":"true"}),onClick:x,children:t("about.support.actions.checkUpdates")})}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(d,{title:t("about.app.title"),description:t("about.app.subtitle"),className:"h-full",contentClassName:"gap-4",children:e.jsx(m,{items:p})}),e.jsx(d,{title:t("about.status.title"),description:t("about.status.subtitle"),className:"h-full",contentClassName:"gap-4",actions:e.jsx(b,{variant:"subtle",size:"sm",icon:e.jsx(y,{className:"h-4 w-4","aria-hidden":"true"}),onClick:()=>a.refetch(),loading:a.isFetching,children:a.isFetching?t("common.actions.refreshing"):t("common.actions.refresh")}),children:a.isLoading?e.jsxs("div",{className:"flex h-36 flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-[3px] border-blue-500/30 border-t-blue-600 dark:border-blue-400/20 dark:border-t-blue-300"}),e.jsx("p",{className:o(i,"text-sm"),children:t("about.status.loading")})]}):c.length>0?e.jsx(m,{items:c}):e.jsxs("div",{className:"flex h-36 flex-col items-center justify-center gap-2 rounded-2xl border border-dashed border-slate-200/60 bg-white p-6 text-center shadow-inner dark:border-slate-700/60 dark:bg-slate-900/60",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:t("about.status.empty")}),e.jsx("p",{className:o(i,"text-xs"),children:t("common.actions.refresh")})]})})]}),e.jsx(d,{title:t("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-semibold text-blue-600 dark:text-blue-300",children:t("about.support.subtitle")}),e.jsx("span",{children:t("about.support.description")})]}),className:"relative overflow-hidden",contentClassName:"gap-6",children:e.jsxs("div",{className:"flex flex-col gap-4 rounded-3xl border border-slate-200/50 bg-white p-6 shadow-lg shadow-slate-200/30 backdrop-blur-md dark:border-slate-700/50 dark:bg-slate-900/80 dark:shadow-slate-900/40",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsx("div",{className:"grid h-12 w-12 place-items-center rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 text-blue-600 shadow-inner dark:text-blue-200",children:e.jsx(k,{className:"h-6 w-6","aria-hidden":"true"})}),e.jsx("p",{className:o(i,"text-sm leading-6"),children:t("about.support.tip")})]}),e.jsx("code",{className:"inline-flex items-center gap-2 self-start rounded-full border border-blue-200/50 bg-blue-50/80 px-4 py-2 text-xs font-semibold tracking-wide text-blue-700 shadow-sm dark:border-blue-500/30 dark:bg-blue-900/30 dark:text-blue-200",children:"~/.cc-gw/config.json"})]})})]})}export{D as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as T,u as W,a as _,r as d,j as e,L as X,P as Y,d as t,b as K,m as r,J as m,H as Z,k as ee,l as ae,f as se,h as te}from"./index-
|
|
1
|
+
import{c as T,u as W,a as _,r as d,j as e,L as X,P as Y,d as t,b as K,m as r,J as m,H as Z,k as ee,l as ae,f as se,h as te}from"./index-dFe_7qSp.js";import{E as le}from"./index-BM-Zc1f-.js";import{u as w}from"./useApiQuery-i7GI_aGQ.js";import{P as ie,a as q}from"./PageSection-BJJ735Qk.js";import{F as I}from"./FormField-DKWx0tXD.js";import{I as re}from"./Input-Iev5RCKK.js";import{B as C}from"./Button-6f5FYqHp.js";import{S as ne}from"./StatusBadge-9lxhNpvi.js";import{C as ce}from"./copy-DMW-t8h3.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,d as c,M as i,H as p,k as b}from"./index-
|
|
1
|
+
import{j as s,d as c,M as i,H as p,k as b}from"./index-dFe_7qSp.js";function h({variant:n="subtle",size:o="md",children:a,loading:t,icon:e,className:l,disabled:r,...u}){const m={subtle:b,primary:p,danger:i}[n],x={sm:"h-8 px-3 text-xs",md:"h-10 px-4 text-sm",lg:"h-12 px-6 text-base"}[o];return s.jsx("button",{className:c(m,x,t&&"cursor-wait opacity-70",r&&"cursor-not-allowed opacity-50",l),disabled:r||t,...u,children:t?s.jsx("div",{className:"inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-current"}):e?s.jsxs(s.Fragment,{children:[e,a]}):a})}export{h as B};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as O,u as q,a as te,r as h,b as se,t as ae,j as e,L as re,B,d as o,m as g,g as z,e as $,f as G,h as oe,l as _,s as le,i as M,k as ie,n as P}from"./index-
|
|
1
|
+
import{c as O,u as q,a as te,r as h,b as se,t as ae,j as e,L as re,B,d as o,m as g,g as z,e as $,f as G,h as oe,l as _,s as le,i as M,k as ie,n as P}from"./index-dFe_7qSp.js";import{E as ne}from"./index-BM-Zc1f-.js";import{P as de,a as H}from"./PageSection-BJJ735Qk.js";import{S as ce}from"./Input-Iev5RCKK.js";import{S as me}from"./StatusBadge-9lxhNpvi.js";import{u as C}from"./useApiQuery-i7GI_aGQ.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as p,u as E,a as S,r as n,j as e,k as h,d as b,v as R,w as L,t as $,i as k}from"./index-
|
|
1
|
+
import{c as p,u as E,a as S,r as n,j as e,k as h,d as b,v as R,w as L,t as $,i as k}from"./index-dFe_7qSp.js";import{R as z}from"./refresh-cw-BF1LiBLP.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,d,T as m,U as x}from"./index-
|
|
1
|
+
import{j as s,d,T as m,U as x}from"./index-dFe_7qSp.js";function i({label:a,children:l,className:t,required:r,error:e}){return s.jsxs("div",{className:d(x,t),children:[s.jsxs("label",{className:m,children:[a,r&&s.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),l,e&&s.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:e})]})}export{i as F};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as u,u as p,r as b,j as e,d as x,m}from"./index-
|
|
1
|
+
import{c as u,u as p,r as b,j as e,d as x,m}from"./index-dFe_7qSp.js";import{P as g,a as o}from"./PageSection-BJJ735Qk.js";import{I as j}from"./info-ByJJXVcp.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as d,j as e,d as n,O as c,N as i}from"./index-
|
|
1
|
+
import{r as d,j as e,d as n,O as c,N as i}from"./index-dFe_7qSp.js";const f=d.forwardRef(({options:t,placeholder:s,className:r,...l},u)=>e.jsxs("select",{ref:u,className:n(c,r),...l,children:[s&&e.jsx("option",{value:"",disabled:!0,children:s}),t.map(a=>e.jsx("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})),j=d.forwardRef(({variant:t="default",className:s,...r},l)=>e.jsx("input",{ref:l,className:n(i,s),...r}));export{j as I,f as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as y,aa as E,ab as C,ac as S,r as l,j as e,d,L as _,m as j,N as v,H as L}from"./index-
|
|
1
|
+
import{u as y,aa as E,ab as C,ac as S,r as l,j as e,d,L as _,m as j,N as v,H as L}from"./index-dFe_7qSp.js";function P(){const{t:a}=y(),o=E(),m=C(),{authEnabled:n,isAuthenticated:x,loading:i,login:k,error:b}=S(),[r,h]=l.useState({username:"",password:""}),[f,u]=l.useState(null),[p,g]=l.useState(!1),c=l.useMemo(()=>{var t;const s=m.state;return((t=s==null?void 0:s.from)==null?void 0:t.pathname)??"/"},[m.state]);l.useEffect(()=>{if(!n&&!i){o(c,{replace:!0});return}n&&x&&!i&&o(c,{replace:!0})},[n,x,i,o,c]);const N=async s=>{if(s.preventDefault(),u(null),!r.username.trim()||!r.password){u(a("login.validation.required"));return}g(!0);try{await k(r.username.trim(),r.password),o(c,{replace:!0})}catch(t){u(t instanceof Error?t.message:a("login.validation.failed"))}finally{g(!1)}},w=s=>e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-slate-100 via-white to-slate-200 px-4 dark:from-slate-950/95 dark:via-slate-950 dark:to-slate-900",children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0",children:[e.jsx("div",{className:"absolute left-10 top-20 h-48 w-48 rounded-full bg-slate-200/40 blur-3xl dark:bg-slate-700/30"}),e.jsx("div",{className:"absolute right-16 bottom-32 h-56 w-56 rounded-full bg-slate-300/35 blur-3xl dark:bg-slate-800/30"}),e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_top,_rgba(15,23,42,0.08),_transparent_55%)]"})]}),e.jsx("div",{className:"relative z-10 w-full max-w-lg",children:s})]});return i?w(e.jsx("div",{className:"flex min-h-[320px] items-center justify-center rounded-3xl border border-blue-200/60 bg-white/90 shadow-2xl shadow-blue-200/50 backdrop-blur-xl dark:border-slate-800/50 dark:bg-slate-900/80 dark:shadow-slate-900/60",children:e.jsx(_,{})})):n?w(e.jsxs("main",{className:"rounded-3xl border border-slate-200/70 bg-white/95 px-8 pb-10 pt-9 shadow-2xl shadow-slate-200/40 backdrop-blur-xl dark:border-slate-800/60 dark:bg-slate-900/85 dark:shadow-slate-900/60",children:[e.jsxs("header",{className:"mb-8 flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-slate-900 via-slate-800 to-slate-700 text-xl font-bold text-white shadow-lg shadow-slate-400/30 dark:from-blue-500 dark:via-blue-600 dark:to-indigo-600 dark:shadow-blue-900/40",children:"GW"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-2xl font-semibold text-slate-900 dark:text-slate-50",children:a("login.title")}),e.jsx("p",{className:d(j,"text-sm leading-relaxed max-w-[360px]"),children:a("login.description")})]})]}),e.jsxs("form",{className:"space-y-5",onSubmit:N,children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.username")}),e.jsx("input",{value:r.username,autoComplete:"username",autoFocus:!0,onChange:s=>h(t=>({...t,username:s.target.value})),placeholder:a("login.fields.usernamePlaceholder"),className:d(v,"h-11 font-medium")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.password")}),e.jsx("input",{type:"password",value:r.password,autoComplete:"current-password",onChange:s=>h(t=>({...t,password:s.target.value})),placeholder:a("login.fields.passwordPlaceholder"),className:d(v,"h-11")})]}),f||b?e.jsx("div",{className:"rounded-2xl border border-red-200/70 bg-red-50/80 px-4 py-3 text-sm font-medium text-red-600 shadow-sm shadow-red-200/40 dark:border-red-500/40 dark:bg-red-500/15 dark:text-red-100",children:f||b}):null,e.jsx("button",{type:"submit",className:d(L,"w-full justify-center rounded-full py-3 text-sm font-semibold"),disabled:p,children:a(p?"common.actions.loading":"login.actions.submit")})]}),e.jsx("footer",{className:"mt-7 text-center text-xs",children:e.jsx("p",{className:d(j,"leading-relaxed"),children:a("login.hint")})})]})):null}export{P as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-B1C47gGx.js";import{u as K}from"./useApiQuery-CvZfYN_4.js";import{P as _e,a as se}from"./PageSection-CJ0vDlWb.js";import{F as T}from"./FormField-8w92_1Tx.js";import{S as I,I as W}from"./Input-BBMxqTTH.js";import{B as $}from"./Button-C32hr6jT.js";import{S as de}from"./StatusBadge-DphP4K9e.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);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 v(t){return t==null?"-":t.toLocaleString()}function w(t,r){const n=v(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,_]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{_(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&_(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1380px",minWidth:"1380px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>_(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>_(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:s("logs.actions.detail")})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,_;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all 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:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,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:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:w(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:w(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:w(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),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-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:w(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:w(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("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-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((_=a.payload)==null?void 0:_.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",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"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};
|
|
1
|
+
import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-dFe_7qSp.js";import{u as K}from"./useApiQuery-i7GI_aGQ.js";import{P as _e,a as se}from"./PageSection-BJJ735Qk.js";import{F as T}from"./FormField-DKWx0tXD.js";import{S as I,I as W}from"./Input-Iev5RCKK.js";import{B as $}from"./Button-6f5FYqHp.js";import{S as de}from"./StatusBadge-9lxhNpvi.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);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 v(t){return t==null?"-":t.toLocaleString()}function w(t,r){const n=v(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,_]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{_(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&_(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1380px",minWidth:"1380px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>_(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>_(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:s("logs.actions.detail")})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,_;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all 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:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,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:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:w(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:w(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:w(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),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-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:w(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:w(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("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-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((_=a.payload)==null?void 0:_.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",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"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ze=s=>{throw TypeError(s)};var Te=(s,a,c)=>a.has(s)||Ze("Cannot "+c);var C=(s,a,c)=>(Te(s,a,"read from private field"),c?c.call(s):a.get(s)),de=(s,a,c)=>a.has(s)?Ze("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,c),ne=(s,a,c,m)=>(Te(s,a,"write to private field"),m?m.call(s,c):a.set(s,c),c),ie=(s,a,c)=>(Te(s,a,"access private method"),c);import{S as Ut,x as Lt,y as et,z as Tt,A as dt,C as nt,r as g,D as $t,E as At,u as Pe,j as e,a as it,G as It,H as oe,b as W,I as ge,t as Re,J as tt,i as Kt,k as q,K as st,M as $e,N as ce,O as ct}from"./index-B1C47gGx.js";import{u as Bt,a as Vt}from"./useApiQuery-CvZfYN_4.js";var Y,se,A,X,Z,Se,Ke,ot,Ft=(ot=class extends Ut{constructor(a,c){super();de(this,Z);de(this,Y);de(this,se);de(this,A);de(this,X);ne(this,Y,a),this.setOptions(c),this.bindMethods(),ie(this,Z,Se).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(a){var m;const c=this.options;this.options=C(this,Y).defaultMutationOptions(a),Lt(this.options,c)||C(this,Y).getMutationCache().notify({type:"observerOptionsUpdated",mutation:C(this,A),observer:this}),c!=null&&c.mutationKey&&this.options.mutationKey&&et(c.mutationKey)!==et(this.options.mutationKey)?this.reset():((m=C(this,A))==null?void 0:m.state.status)==="pending"&&C(this,A).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=C(this,A))==null||a.removeObserver(this)}onMutationUpdate(a){ie(this,Z,Se).call(this),ie(this,Z,Ke).call(this,a)}getCurrentResult(){return C(this,se)}reset(){var a;(a=C(this,A))==null||a.removeObserver(this),ne(this,A,void 0),ie(this,Z,Se).call(this),ie(this,Z,Ke).call(this)}mutate(a,c){var m;return ne(this,X,c),(m=C(this,A))==null||m.removeObserver(this),ne(this,A,C(this,Y).getMutationCache().build(C(this,Y),this.options)),C(this,A).addObserver(this),C(this,A).execute(a)}},Y=new WeakMap,se=new WeakMap,A=new WeakMap,X=new WeakMap,Z=new WeakSet,Se=function(){var c;const a=((c=C(this,A))==null?void 0:c.state)??Tt();ne(this,se,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ke=function(a){dt.batch(()=>{var c,m,p,j,d,x,N,b;if(C(this,X)&&this.hasListeners()){const P=C(this,se).variables,I=C(this,se).context,O={client:C(this,Y),meta:this.options.meta,mutationKey:this.options.mutationKey};(a==null?void 0:a.type)==="success"?((m=(c=C(this,X)).onSuccess)==null||m.call(c,a.data,P,I,O),(j=(p=C(this,X)).onSettled)==null||j.call(p,a.data,null,P,I,O)):(a==null?void 0:a.type)==="error"&&((x=(d=C(this,X)).onError)==null||x.call(d,a.error,P,I,O),(b=(N=C(this,X)).onSettled)==null||b.call(N,void 0,a.error,P,I,O))}this.listeners.forEach(P=>{P(C(this,se))})})},ot);function at(s,a){const c=nt(),[m]=g.useState(()=>new Ft(c,s));g.useEffect(()=>{m.setOptions(s)},[m,s]);const p=g.useSyncExternalStore(g.useCallback(d=>m.subscribe(dt.batchCalls(d)),[m]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),j=g.useCallback((d,x)=>{m.mutate(d,x).catch($t)},[m]);if(p.error&&At(m.options.throwOnError,[p.error]))throw p.error;return{...p,mutate:j,mutateAsync:p.mutate}}function Ve(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Ht(){return{_key:Ve(),id:"",label:""}}const Ae={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"},custom:{}};function rt(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(a=>({...a,_key:Ve()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function _t(s){return{_key:Ve(),id:s.id,label:s.label}}function qt({open:s,mode:a,provider:c,existingProviderIds:m,onClose:p,onSubmit:j}){const{t:d}=Pe(),[x,N]=g.useState(()=>rt(c)),[b,P]=g.useState({}),[I,O]=g.useState(!1),[B,V]=g.useState(null),y=g.useRef(null),E=g.useRef(null),D=g.useRef(null),[L,fe]=g.useState(a==="edit");g.useEffect(()=>{s&&(N(rt(c)),P({}),V(null),O(!1),fe(a==="edit"))},[s,c,a]),g.useEffect(()=>{if(!s)return;const u=f=>{f.key==="Escape"&&p()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,p]),g.useEffect(()=>{if(s){if(a==="create"&&D.current){D.current.focus();return}E.current&&E.current.focus()}},[s,a]);const ve=g.useMemo(()=>x.models.filter(u=>u.id.trim().length>0),[x.models]),ue=u=>f=>{N(w=>({...w,[u]:f}))},ke=u=>{N(f=>{const k=!L||f.label.trim().length===0||f.label===f.id?u:f.label;return{...f,id:u,label:k}})},ae=u=>{N(f=>{var Ne;const k=Ae[u??"custom"]??Ae.custom,S=Object.values(Ae).map(ee=>ee.baseUrl).filter(ee=>!!ee),z=!f.baseUrl||S.includes(f.baseUrl),$=a==="create"&&(f.models.length===0||f.models.every(ee=>ee.id.trim().length===0)),Q={...f,type:u,authMode:u==="anthropic"?f.authMode??"apiKey":"apiKey"};return k!=null&&k.baseUrl&&z&&(Q.baseUrl=k.baseUrl),k!=null&&k.models&&$&&(Q.models=k.models.map(_t),Q.defaultModel=k.defaultModel??((Ne=k.models[0])==null?void 0:Ne.id)??""),Q})},T=(u,f)=>{N(w=>{const k=[...w.models];return k[u]={...k[u],...f},{...w,models:k}})},De=(u,f)=>{N(w=>{const k=[...w.models],S=k[u];if(!S)return w;const z=!L||!S.label||S.label===S.id,$={...S,id:f,label:z?f:S.label};k[u]=$;const Q=w.defaultModel===S.id?f:w.defaultModel;return{...w,models:k,defaultModel:Q}})},F=u=>{N(f=>{if(u<0||u>=f.models.length)return f;const w=f.models.filter((S,z)=>z!==u);let k=f.defaultModel;return w.some(S=>S.id===k)||(k=""),{...f,models:w,defaultModel:k}})},Oe=()=>{N(u=>({...u,models:[...u.models,Ht()]}))},me=u=>{N(f=>({...f,authMode:u}))},je=()=>{const u={},f=x.id.trim(),w=x.baseUrl.trim();if(a==="create"&&(f.length===0?u.id=d("providers.drawer.errors.idRequired"):m.includes(f)&&(u.id=d("providers.drawer.errors.idDuplicate"))),a==="edit"&&f.length===0&&(u.id=d("providers.drawer.errors.idRequired")),w.length===0)u.baseUrl=d("providers.drawer.errors.baseUrlInvalid");else try{new URL(w)}catch{u.baseUrl=d("providers.drawer.errors.baseUrlInvalid")}if(x.models.length>0){const k=new Set;x.models.some(z=>{const $=z.id.trim();return $.length===0||k.has($)?!0:(k.add($),!1)})&&(u.models=d("providers.drawer.errors.modelInvalid"))}return x.defaultModel&&!x.models.some(k=>k.id===x.defaultModel)&&(u.models=d("providers.drawer.errors.defaultInvalid")),P(u),Object.keys(u).length===0},xe=()=>{const u=x.models.map(k=>{var S;return{id:k.id.trim(),label:(S=k.label)!=null&&S.trim()?k.label.trim():void 0}}).filter(k=>k.id.length>0),f=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,w=x.type==="anthropic"?x.authMode:void 0;return{id:x.id.trim(),label:x.label.trim()||x.id.trim(),baseUrl:x.baseUrl.trim(),apiKey:x.apiKey.trim()||void 0,type:x.type??"custom",defaultModel:x.defaultModel||void 0,models:u.length>0?u:void 0,extraHeaders:f,authMode:w}},ye=async()=>{if(V(null),!!je()){O(!0);try{const u=xe();await j(u)}catch(u){V(d("providers.drawer.toast.saveFailure",{message:u instanceof Error?u.message:"unknown"})),O(!1);return}O(!1),p()}},he=a==="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:p,"aria-hidden":"true"}),e.jsxs("aside",{ref:y,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:d(he?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:E,onClick:p,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:d("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:d("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>fe(u=>!u),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:d(L?"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:d("providers.drawer.fields.id")}),e.jsx("input",{value:x.id,ref:D,onChange:u=>ke(u.target.value),disabled:!he,placeholder:d("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":!!b.id}),b.id?e.jsx("span",{className:"text-xs text-red-500",children:b.id}):null]}),L?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:d("providers.drawer.fields.label")}),e.jsx("input",{value:x.label,onChange:u=>ue("label")(u.target.value),placeholder:d("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:d("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:x.baseUrl,onChange:u=>ue("baseUrl")(u.target.value),placeholder:d("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":!!b.baseUrl}),b.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:b.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:d("providers.drawer.fields.type")}),e.jsxs("select",{value:x.type??"custom",onChange:u=>ae(u.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:d("providers.drawer.fields.apiKey")}),e.jsx("input",{value:x.apiKey,onChange:u=>ue("apiKey")(u.target.value),placeholder:d("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"})]}),x.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:d("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:d("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:x.authMode==="apiKey",onChange:()=>me("apiKey")}),e.jsx("span",{children:d("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:x.authMode==="authToken",onChange:()=>me("authToken")}),e.jsx("span",{children:d("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:d("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Oe,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:d("providers.drawer.fields.addModel")})]}),b.models?e.jsx("p",{className:"text-xs text-red-500",children:b.models}):null,e.jsxs("div",{className:"space-y-4",children:[x.models.map((u,f)=>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:d("providers.drawer.fields.modelId")}),e.jsx("input",{value:u.id,onChange:w=>De(f,w.target.value),placeholder:d("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"})]}),L?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:d("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:u.label??"",onChange:w=>T(f,{label:w.target.value}),placeholder:d("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:u.id,checked:x.defaultModel===u.id,onChange:()=>N(w=>({...w,defaultModel:u.id})),disabled:u.id.trim().length===0}),d("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:()=>F(f),disabled:x.models.length===0,children:d("providers.drawer.fields.removeModel")})]})]},u._key)),x.models.length===0?e.jsx("div",{className:"rounded-xl border-2 border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-md dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-900/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 text-2xl",children:"💡"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:d("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:d("providers.drawer.noModelsHint",{providerId:x.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md bg-amber-100/80 p-2.5 dark:bg-amber-800/40",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-amber-900 dark:text-amber-200",children:d("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded bg-white px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-sm dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(x.id||"provider-id").trim()||"provider-id",':*"']})]})]})]})}):null]}),ve.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.defaultHint",{model:x.defaultModel||d("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:B?e.jsx("span",{children:B}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,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:I,children:d("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ye,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:I,children:d(I?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const zt=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Qt=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function Be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function J(s){return s?Object.entries(s).map(([a,c])=>({id:Be(),source:a,target:c})):[]}function Ie(s,a){var p,j,d;if(!s)return{};const c={},m=s.endpointRouting??{};c.anthropic=J(((p=m.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),c.openai=J(((j=m.openai)==null?void 0:j.modelRoutes)??{});for(const x of a)(d=x.routing)!=null&&d.modelRoutes?c[x.id]=J(x.routing.modelRoutes):c[x.id]=[];return c}function Gt(s,a){if(s==="anthropic")return!0;const c=a.find(m=>m.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(m=>m.protocol==="anthropic"):c.protocol==="anthropic":!1}function Wt(s,a,c){var p,j,d;if(!a)return;if(s==="anthropic"||s==="openai")return(j=(p=a.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const m=c.find(x=>x.id===s);return(d=m==null?void 0:m.routing)==null?void 0:d.validation}function as(){const{t:s}=Pe(),{pushToast:a}=it(),c=nt(),m=Bt(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=Vt({queryKey:["custom-endpoints"],queryFn:ge.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],d=g.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],o=j.map(r=>{let l,n=[];if(r.paths&&r.paths.length>0){const i=r.paths.map(h=>`${h.path} (${h.protocol})`).join(", ");l=`${s("modelManagement.tabs.customEndpoint")}: ${i}`,n=[...new Set(r.paths.map(h=>h.protocol))]}else if(r.path){const i=r.protocol||"anthropic";l=`${s("modelManagement.tabs.customEndpoint")}: ${r.path} (${i})`,n=[i]}else l=s("modelManagement.tabs.customEndpoint");return{key:r.id,label:r.label,description:l,isSystem:!1,canDelete:!0,protocols:n}});return[...t,...o]},[s,j]),[x,N]=g.useState("providers"),[b,P]=g.useState(null),[I,O]=g.useState(!1),[B,V]=g.useState("create"),[y,E]=g.useState(void 0),[D,L]=g.useState(null),[fe,ve]=g.useState(!1),[ue,ke]=g.useState(void 0),[ae,T]=g.useState({}),[De,F]=g.useState({}),[Oe,me]=g.useState(null),[je,xe]=g.useState({}),[ye,he]=g.useState({}),[u,f]=g.useState({}),[w,k]=g.useState(null),[S,z]=g.useState(null),[$,Q]=g.useState(null),[Ne,ee]=g.useState(!1),[Ue,Fe]=g.useState(null),[we,Le]=g.useState(!0),[He,_e]=g.useState({}),[qe,ze]=g.useState(!1),H=(b==null?void 0:b.providers)??[],ut=H.length,be=g.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")}],[s]);g.useEffect(()=>{var t,o;if(m.data){const r=m.data;P(r),T(Ie(r,j)),F({});const l={anthropic:((t=r.routingPresets)==null?void 0:t.anthropic)??[],openai:((o=r.routingPresets)==null?void 0:o.openai)??[]};for(const n of j)l[n.id]=n.routingPresets??[];xe(l)}},[m.data,j]),g.useEffect(()=>{m.isError&&m.error&&a({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,a,s]);const mt=g.useMemo(()=>{const t=new Map;for(const o of H){if(!o.defaultModel||!o.models)continue;const r=o.models.find(l=>l.id===o.defaultModel);r&&t.set(o.id,lt(r))}return t},[H]),Qe=g.useMemo(()=>{const t=[],o=new Set;for(const l of H){const n=l.label||l.id,i=l.models??[];if(i.length>0)for(const v of i){const R=`${l.id}:${v.id}`;o.has(R)||(o.add(R),t.push({value:R,label:`${n} · ${v.label??v.id}`}))}else if(l.defaultModel){const v=`${l.id}:${l.defaultModel}`;o.has(v)||(o.add(v),t.push({value:v,label:`${n} · ${l.defaultModel}`}))}const h=`${l.id}:*`;o.has(h)||(o.add(h),t.push({value:h,label:s("settings.routing.providerPassthroughOption",{provider:n})}))}const r=[...ae.anthropic||[],...ae.openai||[]];for(const l of r){const n=l.target.trim();n&&!o.has(n)&&(o.add(n),t.push({value:n,label:n}))}return t},[H,ae,s]),Ge=(t,o)=>{xe(r=>({...r,[t]:o})),P(r=>{if(!r)return r;if(t==="anthropic"||t==="openai")return{...r,routingPresets:{...r.routingPresets,[t]:o}};const l=r.customEndpoints??[],n=l.findIndex(h=>h.id===t);if(n===-1)return r;const i=[...l];return i[n]={...i[n],routingPresets:o},{...r,customEndpoints:i}})},te=()=>b?!0:(a({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),xt=(t,o)=>{he(r=>({...r,[t]:o})),o.trim()&&f(r=>({...r,[t]:null}))},ht=async t=>{if(!te())return;const o=ye[t].trim();if(!o){f(r=>({...r,[t]:s("modelManagement.validation.presetName")}));return}if(je[t].some(r=>r.name.toLowerCase()===o.toLowerCase())){f(r=>({...r,[t]:s("modelManagement.validation.presetDuplicate",{name:o})}));return}k(t);try{const l=(await W.post(`/api/routing-presets/${t}`,{name:o})).data.presets??[];Ge(t,l),he(n=>({...n,[t]:""})),f(n=>({...n,[t]:null})),a({title:s("modelManagement.toast.presetSaved",{name:o}),variant:"success"})}catch(r){a({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{k(null),m.refetch()}},bt=async(t,o)=>{var r,l,n;if(te()){z({endpoint:t,name:o.name});try{const h=(await W.post(`/api/routing-presets/${t}/apply`,{name:o.name})).data.config;if(h){P(h),T(Ie(h,j));const v={anthropic:((r=h.routingPresets)==null?void 0:r.anthropic)??[],openai:((l=h.routingPresets)==null?void 0:l.openai)??[]};for(const R of j){const U=(n=h.customEndpoints)==null?void 0:n.find(K=>K.id===R.id);v[R.id]=(U==null?void 0:U.routingPresets)??[]}xe(v)}else T(v=>({...v,[t]:J(o.modelRoutes)}));a({title:s("modelManagement.toast.presetApplySuccess",{name:o.name}),variant:"success"})}catch(i){a({title:s("modelManagement.toast.presetApplyFailure",{message:i instanceof Error?i.message:"unknown"}),variant:"error"})}finally{z(null),m.refetch()}}},pt=async(t,o)=>{if(!(!te()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:o.name})))){Q({endpoint:t,name:o.name});try{const n=(await W.delete(`/api/routing-presets/${t}/${encodeURIComponent(o.name)}`)).data.presets??[];Ge(t,n),a({title:s("modelManagement.toast.presetDeleteSuccess",{name:o.name}),variant:"success"})}catch(l){a({title:s("modelManagement.toast.presetDeleteFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}finally{Q(null),m.refetch()}}},gt=()=>{te()&&(V("create"),E(void 0),O(!0))},ft=t=>{te()&&(V("edit"),E(t),O(!0))},vt=async t=>{if(!b)throw new Error(s("settings.toast.missingConfig"));const o=B==="create"?[...H,t]:H.map(n=>y&&n.id===y.id?{...t,id:y.id}:n),r={...b,providers:o};await W.put("/api/config",r),P(r),T(Ie(r,j)),m.refetch();const l=B==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});a({title:l,variant:"success"})},kt=async t=>{const o=j.find(r=>r.id===t);if(o&&confirm(s("modelManagement.deleteEndpointConfirm",{label:o.label})))try{await ge.delete(t),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),x===t&&N("providers")}catch(r){const l=Re(r);a({title:s("modelManagement.deleteEndpointError",{error:l.message}),variant:"error"})}},We=async(t,o)=>{L(t.id);try{const r=o&&(o.headers||o.query)?{headers:o.headers&&Object.keys(o.headers).length>0?o.headers:void 0,query:o.query&&o.query.trim().length>0?o.query.trim():void 0}:void 0,l=await W.post(`/api/providers/${t.id}/test`,r);l.data.ok?a({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:l.data.status,duration:l.data.durationMs?`${l.data.durationMs} ms`:"—"}),variant:"success"}):a({title:s("providers.toast.testFailure",{message:`${l.data.status} ${l.data.statusText}`}),variant:"error"})}catch(r){a({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{L(null)}},jt=t=>{if(t.type==="anthropic"){const o=t.extraHeaders??{},r=new Map(be.map(i=>[i.key.toLowerCase(),i])),l={};let n=!0;for(const i of be){const h=Object.entries(o).find(([v])=>v.toLowerCase()===i.key.toLowerCase());if(h){const[v,R]=h;String(R??"")===i.value||(n=!1,l[v]=String(R??""))}}for(const[i,h]of Object.entries(o))r.has(i.toLowerCase())||(l[i]=String(h??""));_e(l),Le(n),Fe(t),ee(!0);return}We(t)},Je=()=>{ee(!1),Fe(null),Le(!0),_e({})},yt=async()=>{if(!Ue)return;const t={};if(we)for(const l of be)t[l.key]=l.value;const o=new Map(be.map(l=>[l.key.toLowerCase(),l]));for(const[l,n]of Object.entries(He)){const i=l.toLowerCase();o.get(i)&&we||(t[l]=n)}const r=Ue;Je(),await We(r,{headers:Object.keys(t).length>0?t:void 0,query:we?"beta=true":void 0})},Nt=async t=>{var R,U,K,re;if(!te()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const r=H.filter(_=>_.id!==t.id),l=_=>{const le={};if(!_)return le;for(const[Ee,M]of Object.entries(_)){if(!M)continue;const[Ce]=M.split(":");Ce&&Ce===t.id||M===t.id||(le[Ee]=M)}return le},n=(b==null?void 0:b.endpointRouting)??{},i=l(((R=n.anthropic)==null?void 0:R.modelRoutes)??(b==null?void 0:b.modelRoutes)??{}),h=l(((U=n.openai)==null?void 0:U.modelRoutes)??{}),v={...b,providers:r,modelRoutes:i,endpointRouting:{anthropic:{defaults:((K=n.anthropic)==null?void 0:K.defaults)??b.defaults,modelRoutes:i},openai:{defaults:((re=n.openai)==null?void 0:re.defaults)??b.defaults,modelRoutes:h}}};try{await W.put("/api/config",v),P(v),T({anthropic:J(i),openai:J(h)}),a({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(_){a({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},wt=t=>{T(o=>({...o,[t]:[...o[t]||[],{id:Be(),source:"",target:""}]})),F(o=>({...o,[t]:null}))},Mt=async(t,o)=>{if(te()){ze(!0);try{if(t==="anthropic"||t==="openai"){const r=b.endpointRouting?{...b.endpointRouting}:{},l=r[t]??{defaults:b.defaults,modelRoutes:(t==="anthropic"?b.modelRoutes:{})??{}},n={defaults:l.defaults??b.defaults,modelRoutes:l.modelRoutes??{}};let i=l.validation;o?(i={...i??{},mode:"claude-code"},i.allowExperimentalBlocks===void 0&&(i.allowExperimentalBlocks=!0)):i=void 0;const h=i?{...n,validation:i}:{...n},v={...r,[t]:h},R={...b,endpointRouting:v};await W.put("/api/config",R),P(R)}else{const r=b.customEndpoints??[],l=r.findIndex(re=>re.id===t);if(l===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const n=r[l],i=n.routing??{defaults:b.defaults,modelRoutes:{}};let h=i.validation;o?(h={...h??{},mode:"claude-code"},h.allowExperimentalBlocks===void 0&&(h.allowExperimentalBlocks=!0)):h=void 0;const v=h?{...i,validation:h}:{...i},R={...n,routing:v},U=[...r];U[l]=R;const K={...b,customEndpoints:U};await W.put("/api/config",K),P(K)}a({title:s(o?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),m.refetch()}catch(r){const l=Re(r);a({title:s("modelManagement.toast.claudeValidationFailure",{message:l.message}),variant:"error"})}finally{ze(!1)}}},Et=(t,o)=>{T(r=>{const l=r[t]||[];return l.some(n=>n.source.trim()===o.trim())?r:{...r,[t]:[...l,{id:Be(),source:o,target:""}]}}),F(r=>({...r,[t]:null}))},Me=(t,o,r,l)=>{T(n=>({...n,[t]:(n[t]||[]).map(i=>i.id===o?{...i,[r]:l}:i)})),F(n=>({...n,[t]:null}))},Ct=(t,o)=>{T(r=>({...r,[t]:(r[t]||[]).filter(l=>l.id!==o)})),F(r=>({...r,[t]:null}))},St=t=>{var r,l;if(!b)return;const o=j.find(n=>n.id===t);if(o){const n=((r=o.routing)==null?void 0:r.modelRoutes)??{};T(i=>({...i,[t]:J(n)}))}else{const n=b.endpointRouting??{},i=t,h=i==="anthropic"?b.modelRoutes??{}:{},v=((l=n[i])==null?void 0:l.modelRoutes)??h;T(R=>({...R,[t]:J(v)}))}F(n=>({...n,[t]:null}))},Rt=async t=>{var l;if(!te())return;const o=ae[t]||[],r={};for(const n of o){const i=n.source.trim(),h=n.target.trim();if(!(!i&&!h)){if(!i||!h){F(v=>({...v,[t]:s("settings.validation.routePair")}));return}if(r[i]){F(v=>({...v,[t]:s("settings.validation.routeDuplicate",{model:i})}));return}r[i]=h}}F(n=>({...n,[t]:null})),me(t);try{const n=j.find(i=>i.id===t);if(n){const i={...n.routing||{},modelRoutes:r,defaults:((l=n.routing)==null?void 0:l.defaults)||b.defaults};await ge.update(t,{routing:i}),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const i=b.endpointRouting?{...b.endpointRouting}:{},h=t,v=i[h]??{defaults:b.defaults,modelRoutes:h==="anthropic"?b.modelRoutes??{}:{}},R={...v,defaults:v.defaults??b.defaults,modelRoutes:r},U={...i,[h]:R},K={...b,endpointRouting:U,modelRoutes:h==="anthropic"?r:b.modelRoutes??{}};await W.put("/api/config",K),P(K),a({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}T(i=>({...i,[t]:J(r)}))}catch(n){a({title:s("modelManagement.toast.routesSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{me(null)}},Pt=()=>e.jsxs("section",{className:tt,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:Kt.default,children:s("providers.count",{count:ut})}),e.jsx("button",{type:"button",className:q,onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:oe,onClick:gt,children:s("providers.actions.add")})]})]}),m.isPending||!b&&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")}):H.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:H.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(Yt,{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:st.success,children:s("providers.card.defaultModel",{model:mt.get(t.id)??t.defaultModel})}):e.jsx("div",{className:st.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(o=>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:lt(o)})]},o.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:q,onClick:()=>ft(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>jt(t),disabled:D===t.id,className:D===t.id?`${q} opacity-60 cursor-not-allowed`:q,children:D===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:$e,onClick:()=>Nt(t),children:s("providers.actions.delete")})]})]},t.id))})]}),Dt=t=>{const o=je[t],r=ye[t],l=u[t],n=w===t;return 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:r,onChange:i=>xt(t,i.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:ce,disabled:n}),e.jsx("button",{type:"button",onClick:()=>ht(t),className:oe,disabled:n,children:s(n?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),l?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:l}):null,o.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:o.map(i=>{const h=(S==null?void 0:S.endpoint)===t&&(S==null?void 0:S.name)===i.name,v=($==null?void 0:$.endpoint)===t&&($==null?void 0:$.name)===i.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:i.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>bt(t,i),className:h||v?`${q} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${oe} text-xs px-2 py-1`,disabled:h||v,children:s(h?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>pt(t,i),className:v||h?`${q} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${$e} text-xs px-2 py-1`,disabled:v||h,children:s(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},i.name)})})]})},Ot=t=>{var Ee;const o=ae[t]||[],r=De[t],l=d.find(M=>M.key===t),i=((Ee=l==null?void 0:l.protocols)==null?void 0:Ee.includes("anthropic"))??t==="anthropic"?zt:Qt,h=Oe===t,v=(l==null?void 0:l.label)??s(`modelManagement.tabs.${t}`),R=(l==null?void 0:l.isSystem)===!1?l.description:s(`settings.routing.descriptionByEndpoint.${t}`),U=`route-source-${t}`,K=`route-target-${t}`,re=Gt(t,j),_=Wt(t,b,j),le=re&&(_==null?void 0:_.mode)==="claude-code";return e.jsxs("section",{className:tt,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:v})}),e.jsx("p",{className:"max-w-3xl text-sm text-slate-600 dark:text-slate-400",children:R}),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:()=>wt(t),className:q,disabled:h,children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>St(t),className:q,disabled:h,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Rt(t),className:oe,disabled:h,children:s(h?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),re&&e.jsx("div",{className:"mt-6 rounded-xl border border-blue-200/60 bg-blue-50/60 p-4 dark:border-blue-500/40 dark:bg-blue-900/30 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-sm font-semibold text-blue-700 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-600/80 dark:text-blue-200/80",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-blue-300 text-blue-600 focus:ring-blue-500",checked:!!le,onChange:M=>Mt(t,M.target.checked),disabled:qe}),e.jsx("span",{className:"text-xs font-medium text-blue-700 dark:text-blue-200",children:s(qe?"common.actions.saving":"modelManagement.claudeValidation.toggleLabel")})]})]}),e.jsx("span",{className:`text-xs font-semibold ${le?"text-emerald-600 dark:text-emerald-300":"text-slate-500 dark:text-slate-400"}`,children:s(le?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})}),Dt(t),r?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:r}):null,o.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:o.map((M,Ce)=>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:Ce+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:M.source,onChange:pe=>Me(t,M.id,"source",pe.target.value),className:ce,placeholder:"claude-3.5-sonnet",list:U,disabled:h})]})}),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 pe=M.target.trim(),Ye=Qe.some(G=>G.value===pe)?pe:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:Ye,onChange:G=>{const Xe=G.target.value;Xe==="__custom"?Me(t,M.id,"target",pe):Me(t,M.id,"target",Xe)},className:ct,disabled:h,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),Qe.map(G=>e.jsx("option",{value:G.value,children:G.label},`${K}-${G.value}`))]}),Ye==="__custom"&&e.jsx("input",{type:"text",value:M.target,onChange:G=>Me(t,M.id,"target",G.target.value),className:ce,placeholder:"providerId:modelId",disabled:h})]})})()]})}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:$e,onClick:()=>Ct(t,M.id),disabled:h,children:s("settings.routing.remove")})})]})]},M.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:i.map(M=>e.jsx("button",{type:"button",onClick:()=>Et(t,M),className:q,disabled:h,children:M},`${t}-${M}`))})]})}),e.jsx("datalist",{id:U,children:i.map(M=>e.jsx("option",{value:M},`${U}-${M}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx("div",{className:It,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",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.jsxs("button",{onClick:()=>{ke(void 0),ve(!0)},className:oe,children:["+ ",s("modelManagement.addEndpoint")]})]})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:d.map(t=>{const o=x===t.key;return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(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 ${o?"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.canDelete&&e.jsx("button",{onClick:r=>{r.stopPropagation(),kt(t.key)},className:"absolute -top-2 -right-2 h-6 w-6 rounded-full bg-red-500 text-white hover:bg-red-600 flex items-center justify-center text-xs shadow-md",title:s("common.delete"),children:"×"})]},t.key)})}),x==="providers"?Pt():Ot(x),e.jsx(qt,{open:I,mode:B,provider:B==="edit"?y:void 0,existingProviderIds:H.map(t=>t.id).filter(t=>B==="edit"&&y?t!==y.id:!0),onClose:()=>{O(!1),E(void 0),V("create")},onSubmit:vt}),e.jsx(Xt,{open:fe,endpoint:ue,onClose:()=>{ve(!1),ke(void 0)},onSuccess:()=>{c.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Jt,{open:Ne,provider:Ue,options:be,preservedExtras:He,usePreset:we,onPresetChange:Le,onConfirm:yt,onClose:Je})]})}function Jt({open:s,provider:a,options:c,usePreset:m,preservedExtras:p,onPresetChange:j,onConfirm:d,onClose:x}){const{t:N}=Pe();return!s||!a?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:x,"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:N("providers.testDialog.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:N("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsx("p",{className:"mb-5 text-sm leading-relaxed text-slate-600 dark:text-slate-300",children:N("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:m,onChange:b=>j(b.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:N("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs leading-relaxed text-slate-500 dark:text-slate-400",children:N("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:N("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 grid gap-1",children:c.map(b=>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:[b.key,": ",b.value]},b.key))})]})]})]})}),Object.keys(p).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:N("providers.testDialog.preservedInfo")}),e.jsx("div",{className:"grid gap-2",children:Object.entries(p).map(([b,P])=>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:[b,": ",P]},b))})]}):null,e.jsxs("footer",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:x,className:q,children:N("providers.testDialog.cancel")}),e.jsx("button",{type:"button",onClick:()=>{d()},className:oe,children:N("providers.testDialog.primary")})]})]})]})}function lt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Yt({type:s}){const a={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:c,color:m}=a[s]||a.custom;return e.jsx("span",{className:`rounded-full ${m} px-2.5 py-1 text-xs font-semibold shadow-sm`,children:c})}function Xt({open:s,endpoint:a,onClose:c,onSuccess:m}){const{t:p}=Pe(),{pushToast:j}=it(),[d,x]=g.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});g.useEffect(()=>{if(a){let y;a.paths&&a.paths.length>0?y=a.paths:a.path&&a.protocol?y=[{path:a.path,protocol:a.protocol}]:y=[{path:"",protocol:"openai-auto"}],x({id:a.id,label:a.label,paths:y,enabled:a.enabled!==!1})}else x({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[a,s]);const N=at({mutationFn:ge.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),m(),c()},onError:y=>{const E=Re(y);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),b=at({mutationFn:y=>ge.update(y.id,y.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),m(),c()},onError:y=>{const E=Re(y);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),P=()=>{x({...d,paths:[...d.paths,{path:"",protocol:"anthropic"}]})},I=y=>{if(d.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=d.paths.filter((D,L)=>L!==y);x({...d,paths:E})},O=(y,E,D)=>{const L=[...d.paths];L[y]={...L[y],[E]:D},x({...d,paths:L})},B=y=>{if(y.preventDefault(),!d.id.trim()||!d.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const D of d.paths)if(!D.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=d.paths.map(D=>({path:D.path.trim(),protocol:D.protocol}));a?b.mutate({id:a.id,updates:{label:d.label.trim(),paths:E,enabled:d.enabled}}):N.mutate({id:d.id.trim(),label:d.label.trim(),paths:E,enabled:d.enabled})},V=N.isPending||b.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 dark:bg-black/70 z-40 transition-opacity",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 w-full max-w-md bg-white dark:bg-gray-900 shadow-xl z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:p(a?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("button",{onClick:c,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:B,className:"flex-1 p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.id,onChange:y=>x({...d,id:y.target.value}),className:ce,placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!a,required:!0}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.label,onChange:y=>x({...d,label:y.target.value}),className:ce,placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("button",{type:"button",onClick:P,className:"text-sm text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",children:["+ ",p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:d.paths.map((y,E)=>e.jsxs("div",{className:"p-3 border border-gray-200 dark:border-gray-700 rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{type:"text",value:y.path,onChange:D=>O(E,"path",D.target.value),className:ce,placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs("select",{value:y.protocol,onChange:D=>O(E,"protocol",D.target.value),className:ct,required:!0,children:[e.jsx("option",{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx("option",{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]}),d.paths.length>1&&e.jsx("button",{type:"button",onClick:()=>I(E),className:"text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 mt-1",title:p("modelManagement.removePath"),children:e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}),E===0&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",id:"enabled",checked:d.enabled,onChange:y=>x({...d,enabled:y.target.checked}),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-700 dark:bg-gray-800"}),e.jsx("label",{htmlFor:"enabled",className:"text-sm text-gray-700 dark:text-gray-300",children:p("modelManagement.endpointEnabled")})]}),!a&&e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-900/20 p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-300",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 p-6 border-t border-gray-200 dark:border-gray-800",children:[e.jsx("button",{type:"button",onClick:c,className:`${q} flex-1`,disabled:V,children:p("common.cancel")}),e.jsx("button",{type:"submit",onClick:B,className:`${oe} flex-1`,disabled:V,children:p(V?"common.saving":a?"common.save":"common.create")})]})]})})]}):null}export{as as default};
|
|
1
|
+
var Ze=s=>{throw TypeError(s)};var Te=(s,a,c)=>a.has(s)||Ze("Cannot "+c);var C=(s,a,c)=>(Te(s,a,"read from private field"),c?c.call(s):a.get(s)),de=(s,a,c)=>a.has(s)?Ze("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,c),ne=(s,a,c,m)=>(Te(s,a,"write to private field"),m?m.call(s,c):a.set(s,c),c),ie=(s,a,c)=>(Te(s,a,"access private method"),c);import{S as Ut,x as Lt,y as et,z as Tt,A as dt,C as nt,r as g,D as $t,E as At,u as Pe,j as e,a as it,G as It,H as oe,b as W,I as ge,t as Re,J as tt,i as Kt,k as q,K as st,M as $e,N as ce,O as ct}from"./index-dFe_7qSp.js";import{u as Bt,a as Vt}from"./useApiQuery-i7GI_aGQ.js";var Y,se,A,X,Z,Se,Ke,ot,Ft=(ot=class extends Ut{constructor(a,c){super();de(this,Z);de(this,Y);de(this,se);de(this,A);de(this,X);ne(this,Y,a),this.setOptions(c),this.bindMethods(),ie(this,Z,Se).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(a){var m;const c=this.options;this.options=C(this,Y).defaultMutationOptions(a),Lt(this.options,c)||C(this,Y).getMutationCache().notify({type:"observerOptionsUpdated",mutation:C(this,A),observer:this}),c!=null&&c.mutationKey&&this.options.mutationKey&&et(c.mutationKey)!==et(this.options.mutationKey)?this.reset():((m=C(this,A))==null?void 0:m.state.status)==="pending"&&C(this,A).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=C(this,A))==null||a.removeObserver(this)}onMutationUpdate(a){ie(this,Z,Se).call(this),ie(this,Z,Ke).call(this,a)}getCurrentResult(){return C(this,se)}reset(){var a;(a=C(this,A))==null||a.removeObserver(this),ne(this,A,void 0),ie(this,Z,Se).call(this),ie(this,Z,Ke).call(this)}mutate(a,c){var m;return ne(this,X,c),(m=C(this,A))==null||m.removeObserver(this),ne(this,A,C(this,Y).getMutationCache().build(C(this,Y),this.options)),C(this,A).addObserver(this),C(this,A).execute(a)}},Y=new WeakMap,se=new WeakMap,A=new WeakMap,X=new WeakMap,Z=new WeakSet,Se=function(){var c;const a=((c=C(this,A))==null?void 0:c.state)??Tt();ne(this,se,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ke=function(a){dt.batch(()=>{var c,m,p,j,d,x,N,b;if(C(this,X)&&this.hasListeners()){const P=C(this,se).variables,I=C(this,se).context,O={client:C(this,Y),meta:this.options.meta,mutationKey:this.options.mutationKey};(a==null?void 0:a.type)==="success"?((m=(c=C(this,X)).onSuccess)==null||m.call(c,a.data,P,I,O),(j=(p=C(this,X)).onSettled)==null||j.call(p,a.data,null,P,I,O)):(a==null?void 0:a.type)==="error"&&((x=(d=C(this,X)).onError)==null||x.call(d,a.error,P,I,O),(b=(N=C(this,X)).onSettled)==null||b.call(N,void 0,a.error,P,I,O))}this.listeners.forEach(P=>{P(C(this,se))})})},ot);function at(s,a){const c=nt(),[m]=g.useState(()=>new Ft(c,s));g.useEffect(()=>{m.setOptions(s)},[m,s]);const p=g.useSyncExternalStore(g.useCallback(d=>m.subscribe(dt.batchCalls(d)),[m]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),j=g.useCallback((d,x)=>{m.mutate(d,x).catch($t)},[m]);if(p.error&&At(m.options.throwOnError,[p.error]))throw p.error;return{...p,mutate:j,mutateAsync:p.mutate}}function Ve(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Ht(){return{_key:Ve(),id:"",label:""}}const Ae={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"},custom:{}};function rt(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(a=>({...a,_key:Ve()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function _t(s){return{_key:Ve(),id:s.id,label:s.label}}function qt({open:s,mode:a,provider:c,existingProviderIds:m,onClose:p,onSubmit:j}){const{t:d}=Pe(),[x,N]=g.useState(()=>rt(c)),[b,P]=g.useState({}),[I,O]=g.useState(!1),[B,V]=g.useState(null),y=g.useRef(null),E=g.useRef(null),D=g.useRef(null),[L,fe]=g.useState(a==="edit");g.useEffect(()=>{s&&(N(rt(c)),P({}),V(null),O(!1),fe(a==="edit"))},[s,c,a]),g.useEffect(()=>{if(!s)return;const u=f=>{f.key==="Escape"&&p()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,p]),g.useEffect(()=>{if(s){if(a==="create"&&D.current){D.current.focus();return}E.current&&E.current.focus()}},[s,a]);const ve=g.useMemo(()=>x.models.filter(u=>u.id.trim().length>0),[x.models]),ue=u=>f=>{N(w=>({...w,[u]:f}))},ke=u=>{N(f=>{const k=!L||f.label.trim().length===0||f.label===f.id?u:f.label;return{...f,id:u,label:k}})},ae=u=>{N(f=>{var Ne;const k=Ae[u??"custom"]??Ae.custom,S=Object.values(Ae).map(ee=>ee.baseUrl).filter(ee=>!!ee),z=!f.baseUrl||S.includes(f.baseUrl),$=a==="create"&&(f.models.length===0||f.models.every(ee=>ee.id.trim().length===0)),Q={...f,type:u,authMode:u==="anthropic"?f.authMode??"apiKey":"apiKey"};return k!=null&&k.baseUrl&&z&&(Q.baseUrl=k.baseUrl),k!=null&&k.models&&$&&(Q.models=k.models.map(_t),Q.defaultModel=k.defaultModel??((Ne=k.models[0])==null?void 0:Ne.id)??""),Q})},T=(u,f)=>{N(w=>{const k=[...w.models];return k[u]={...k[u],...f},{...w,models:k}})},De=(u,f)=>{N(w=>{const k=[...w.models],S=k[u];if(!S)return w;const z=!L||!S.label||S.label===S.id,$={...S,id:f,label:z?f:S.label};k[u]=$;const Q=w.defaultModel===S.id?f:w.defaultModel;return{...w,models:k,defaultModel:Q}})},F=u=>{N(f=>{if(u<0||u>=f.models.length)return f;const w=f.models.filter((S,z)=>z!==u);let k=f.defaultModel;return w.some(S=>S.id===k)||(k=""),{...f,models:w,defaultModel:k}})},Oe=()=>{N(u=>({...u,models:[...u.models,Ht()]}))},me=u=>{N(f=>({...f,authMode:u}))},je=()=>{const u={},f=x.id.trim(),w=x.baseUrl.trim();if(a==="create"&&(f.length===0?u.id=d("providers.drawer.errors.idRequired"):m.includes(f)&&(u.id=d("providers.drawer.errors.idDuplicate"))),a==="edit"&&f.length===0&&(u.id=d("providers.drawer.errors.idRequired")),w.length===0)u.baseUrl=d("providers.drawer.errors.baseUrlInvalid");else try{new URL(w)}catch{u.baseUrl=d("providers.drawer.errors.baseUrlInvalid")}if(x.models.length>0){const k=new Set;x.models.some(z=>{const $=z.id.trim();return $.length===0||k.has($)?!0:(k.add($),!1)})&&(u.models=d("providers.drawer.errors.modelInvalid"))}return x.defaultModel&&!x.models.some(k=>k.id===x.defaultModel)&&(u.models=d("providers.drawer.errors.defaultInvalid")),P(u),Object.keys(u).length===0},xe=()=>{const u=x.models.map(k=>{var S;return{id:k.id.trim(),label:(S=k.label)!=null&&S.trim()?k.label.trim():void 0}}).filter(k=>k.id.length>0),f=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,w=x.type==="anthropic"?x.authMode:void 0;return{id:x.id.trim(),label:x.label.trim()||x.id.trim(),baseUrl:x.baseUrl.trim(),apiKey:x.apiKey.trim()||void 0,type:x.type??"custom",defaultModel:x.defaultModel||void 0,models:u.length>0?u:void 0,extraHeaders:f,authMode:w}},ye=async()=>{if(V(null),!!je()){O(!0);try{const u=xe();await j(u)}catch(u){V(d("providers.drawer.toast.saveFailure",{message:u instanceof Error?u.message:"unknown"})),O(!1);return}O(!1),p()}},he=a==="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:p,"aria-hidden":"true"}),e.jsxs("aside",{ref:y,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:d(he?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:E,onClick:p,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:d("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:d("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>fe(u=>!u),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:d(L?"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:d("providers.drawer.fields.id")}),e.jsx("input",{value:x.id,ref:D,onChange:u=>ke(u.target.value),disabled:!he,placeholder:d("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":!!b.id}),b.id?e.jsx("span",{className:"text-xs text-red-500",children:b.id}):null]}),L?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:d("providers.drawer.fields.label")}),e.jsx("input",{value:x.label,onChange:u=>ue("label")(u.target.value),placeholder:d("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:d("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:x.baseUrl,onChange:u=>ue("baseUrl")(u.target.value),placeholder:d("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":!!b.baseUrl}),b.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:b.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:d("providers.drawer.fields.type")}),e.jsxs("select",{value:x.type??"custom",onChange:u=>ae(u.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:d("providers.drawer.fields.apiKey")}),e.jsx("input",{value:x.apiKey,onChange:u=>ue("apiKey")(u.target.value),placeholder:d("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"})]}),x.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:d("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:d("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:x.authMode==="apiKey",onChange:()=>me("apiKey")}),e.jsx("span",{children:d("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:x.authMode==="authToken",onChange:()=>me("authToken")}),e.jsx("span",{children:d("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:d("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Oe,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:d("providers.drawer.fields.addModel")})]}),b.models?e.jsx("p",{className:"text-xs text-red-500",children:b.models}):null,e.jsxs("div",{className:"space-y-4",children:[x.models.map((u,f)=>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:d("providers.drawer.fields.modelId")}),e.jsx("input",{value:u.id,onChange:w=>De(f,w.target.value),placeholder:d("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"})]}),L?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:d("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:u.label??"",onChange:w=>T(f,{label:w.target.value}),placeholder:d("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:u.id,checked:x.defaultModel===u.id,onChange:()=>N(w=>({...w,defaultModel:u.id})),disabled:u.id.trim().length===0}),d("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:()=>F(f),disabled:x.models.length===0,children:d("providers.drawer.fields.removeModel")})]})]},u._key)),x.models.length===0?e.jsx("div",{className:"rounded-xl border-2 border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-md dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-900/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 text-2xl",children:"💡"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:d("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:d("providers.drawer.noModelsHint",{providerId:x.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md bg-amber-100/80 p-2.5 dark:bg-amber-800/40",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-amber-900 dark:text-amber-200",children:d("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded bg-white px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-sm dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(x.id||"provider-id").trim()||"provider-id",':*"']})]})]})]})}):null]}),ve.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.defaultHint",{model:x.defaultModel||d("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:B?e.jsx("span",{children:B}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,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:I,children:d("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ye,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:I,children:d(I?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const zt=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Qt=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function Be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function J(s){return s?Object.entries(s).map(([a,c])=>({id:Be(),source:a,target:c})):[]}function Ie(s,a){var p,j,d;if(!s)return{};const c={},m=s.endpointRouting??{};c.anthropic=J(((p=m.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),c.openai=J(((j=m.openai)==null?void 0:j.modelRoutes)??{});for(const x of a)(d=x.routing)!=null&&d.modelRoutes?c[x.id]=J(x.routing.modelRoutes):c[x.id]=[];return c}function Gt(s,a){if(s==="anthropic")return!0;const c=a.find(m=>m.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(m=>m.protocol==="anthropic"):c.protocol==="anthropic":!1}function Wt(s,a,c){var p,j,d;if(!a)return;if(s==="anthropic"||s==="openai")return(j=(p=a.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const m=c.find(x=>x.id===s);return(d=m==null?void 0:m.routing)==null?void 0:d.validation}function as(){const{t:s}=Pe(),{pushToast:a}=it(),c=nt(),m=Bt(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=Vt({queryKey:["custom-endpoints"],queryFn:ge.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],d=g.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],o=j.map(r=>{let l,n=[];if(r.paths&&r.paths.length>0){const i=r.paths.map(h=>`${h.path} (${h.protocol})`).join(", ");l=`${s("modelManagement.tabs.customEndpoint")}: ${i}`,n=[...new Set(r.paths.map(h=>h.protocol))]}else if(r.path){const i=r.protocol||"anthropic";l=`${s("modelManagement.tabs.customEndpoint")}: ${r.path} (${i})`,n=[i]}else l=s("modelManagement.tabs.customEndpoint");return{key:r.id,label:r.label,description:l,isSystem:!1,canDelete:!0,protocols:n}});return[...t,...o]},[s,j]),[x,N]=g.useState("providers"),[b,P]=g.useState(null),[I,O]=g.useState(!1),[B,V]=g.useState("create"),[y,E]=g.useState(void 0),[D,L]=g.useState(null),[fe,ve]=g.useState(!1),[ue,ke]=g.useState(void 0),[ae,T]=g.useState({}),[De,F]=g.useState({}),[Oe,me]=g.useState(null),[je,xe]=g.useState({}),[ye,he]=g.useState({}),[u,f]=g.useState({}),[w,k]=g.useState(null),[S,z]=g.useState(null),[$,Q]=g.useState(null),[Ne,ee]=g.useState(!1),[Ue,Fe]=g.useState(null),[we,Le]=g.useState(!0),[He,_e]=g.useState({}),[qe,ze]=g.useState(!1),H=(b==null?void 0:b.providers)??[],ut=H.length,be=g.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")}],[s]);g.useEffect(()=>{var t,o;if(m.data){const r=m.data;P(r),T(Ie(r,j)),F({});const l={anthropic:((t=r.routingPresets)==null?void 0:t.anthropic)??[],openai:((o=r.routingPresets)==null?void 0:o.openai)??[]};for(const n of j)l[n.id]=n.routingPresets??[];xe(l)}},[m.data,j]),g.useEffect(()=>{m.isError&&m.error&&a({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,a,s]);const mt=g.useMemo(()=>{const t=new Map;for(const o of H){if(!o.defaultModel||!o.models)continue;const r=o.models.find(l=>l.id===o.defaultModel);r&&t.set(o.id,lt(r))}return t},[H]),Qe=g.useMemo(()=>{const t=[],o=new Set;for(const l of H){const n=l.label||l.id,i=l.models??[];if(i.length>0)for(const v of i){const R=`${l.id}:${v.id}`;o.has(R)||(o.add(R),t.push({value:R,label:`${n} · ${v.label??v.id}`}))}else if(l.defaultModel){const v=`${l.id}:${l.defaultModel}`;o.has(v)||(o.add(v),t.push({value:v,label:`${n} · ${l.defaultModel}`}))}const h=`${l.id}:*`;o.has(h)||(o.add(h),t.push({value:h,label:s("settings.routing.providerPassthroughOption",{provider:n})}))}const r=[...ae.anthropic||[],...ae.openai||[]];for(const l of r){const n=l.target.trim();n&&!o.has(n)&&(o.add(n),t.push({value:n,label:n}))}return t},[H,ae,s]),Ge=(t,o)=>{xe(r=>({...r,[t]:o})),P(r=>{if(!r)return r;if(t==="anthropic"||t==="openai")return{...r,routingPresets:{...r.routingPresets,[t]:o}};const l=r.customEndpoints??[],n=l.findIndex(h=>h.id===t);if(n===-1)return r;const i=[...l];return i[n]={...i[n],routingPresets:o},{...r,customEndpoints:i}})},te=()=>b?!0:(a({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),xt=(t,o)=>{he(r=>({...r,[t]:o})),o.trim()&&f(r=>({...r,[t]:null}))},ht=async t=>{if(!te())return;const o=ye[t].trim();if(!o){f(r=>({...r,[t]:s("modelManagement.validation.presetName")}));return}if(je[t].some(r=>r.name.toLowerCase()===o.toLowerCase())){f(r=>({...r,[t]:s("modelManagement.validation.presetDuplicate",{name:o})}));return}k(t);try{const l=(await W.post(`/api/routing-presets/${t}`,{name:o})).data.presets??[];Ge(t,l),he(n=>({...n,[t]:""})),f(n=>({...n,[t]:null})),a({title:s("modelManagement.toast.presetSaved",{name:o}),variant:"success"})}catch(r){a({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{k(null),m.refetch()}},bt=async(t,o)=>{var r,l,n;if(te()){z({endpoint:t,name:o.name});try{const h=(await W.post(`/api/routing-presets/${t}/apply`,{name:o.name})).data.config;if(h){P(h),T(Ie(h,j));const v={anthropic:((r=h.routingPresets)==null?void 0:r.anthropic)??[],openai:((l=h.routingPresets)==null?void 0:l.openai)??[]};for(const R of j){const U=(n=h.customEndpoints)==null?void 0:n.find(K=>K.id===R.id);v[R.id]=(U==null?void 0:U.routingPresets)??[]}xe(v)}else T(v=>({...v,[t]:J(o.modelRoutes)}));a({title:s("modelManagement.toast.presetApplySuccess",{name:o.name}),variant:"success"})}catch(i){a({title:s("modelManagement.toast.presetApplyFailure",{message:i instanceof Error?i.message:"unknown"}),variant:"error"})}finally{z(null),m.refetch()}}},pt=async(t,o)=>{if(!(!te()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:o.name})))){Q({endpoint:t,name:o.name});try{const n=(await W.delete(`/api/routing-presets/${t}/${encodeURIComponent(o.name)}`)).data.presets??[];Ge(t,n),a({title:s("modelManagement.toast.presetDeleteSuccess",{name:o.name}),variant:"success"})}catch(l){a({title:s("modelManagement.toast.presetDeleteFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}finally{Q(null),m.refetch()}}},gt=()=>{te()&&(V("create"),E(void 0),O(!0))},ft=t=>{te()&&(V("edit"),E(t),O(!0))},vt=async t=>{if(!b)throw new Error(s("settings.toast.missingConfig"));const o=B==="create"?[...H,t]:H.map(n=>y&&n.id===y.id?{...t,id:y.id}:n),r={...b,providers:o};await W.put("/api/config",r),P(r),T(Ie(r,j)),m.refetch();const l=B==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});a({title:l,variant:"success"})},kt=async t=>{const o=j.find(r=>r.id===t);if(o&&confirm(s("modelManagement.deleteEndpointConfirm",{label:o.label})))try{await ge.delete(t),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),x===t&&N("providers")}catch(r){const l=Re(r);a({title:s("modelManagement.deleteEndpointError",{error:l.message}),variant:"error"})}},We=async(t,o)=>{L(t.id);try{const r=o&&(o.headers||o.query)?{headers:o.headers&&Object.keys(o.headers).length>0?o.headers:void 0,query:o.query&&o.query.trim().length>0?o.query.trim():void 0}:void 0,l=await W.post(`/api/providers/${t.id}/test`,r);l.data.ok?a({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:l.data.status,duration:l.data.durationMs?`${l.data.durationMs} ms`:"—"}),variant:"success"}):a({title:s("providers.toast.testFailure",{message:`${l.data.status} ${l.data.statusText}`}),variant:"error"})}catch(r){a({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{L(null)}},jt=t=>{if(t.type==="anthropic"){const o=t.extraHeaders??{},r=new Map(be.map(i=>[i.key.toLowerCase(),i])),l={};let n=!0;for(const i of be){const h=Object.entries(o).find(([v])=>v.toLowerCase()===i.key.toLowerCase());if(h){const[v,R]=h;String(R??"")===i.value||(n=!1,l[v]=String(R??""))}}for(const[i,h]of Object.entries(o))r.has(i.toLowerCase())||(l[i]=String(h??""));_e(l),Le(n),Fe(t),ee(!0);return}We(t)},Je=()=>{ee(!1),Fe(null),Le(!0),_e({})},yt=async()=>{if(!Ue)return;const t={};if(we)for(const l of be)t[l.key]=l.value;const o=new Map(be.map(l=>[l.key.toLowerCase(),l]));for(const[l,n]of Object.entries(He)){const i=l.toLowerCase();o.get(i)&&we||(t[l]=n)}const r=Ue;Je(),await We(r,{headers:Object.keys(t).length>0?t:void 0,query:we?"beta=true":void 0})},Nt=async t=>{var R,U,K,re;if(!te()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const r=H.filter(_=>_.id!==t.id),l=_=>{const le={};if(!_)return le;for(const[Ee,M]of Object.entries(_)){if(!M)continue;const[Ce]=M.split(":");Ce&&Ce===t.id||M===t.id||(le[Ee]=M)}return le},n=(b==null?void 0:b.endpointRouting)??{},i=l(((R=n.anthropic)==null?void 0:R.modelRoutes)??(b==null?void 0:b.modelRoutes)??{}),h=l(((U=n.openai)==null?void 0:U.modelRoutes)??{}),v={...b,providers:r,modelRoutes:i,endpointRouting:{anthropic:{defaults:((K=n.anthropic)==null?void 0:K.defaults)??b.defaults,modelRoutes:i},openai:{defaults:((re=n.openai)==null?void 0:re.defaults)??b.defaults,modelRoutes:h}}};try{await W.put("/api/config",v),P(v),T({anthropic:J(i),openai:J(h)}),a({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(_){a({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},wt=t=>{T(o=>({...o,[t]:[...o[t]||[],{id:Be(),source:"",target:""}]})),F(o=>({...o,[t]:null}))},Mt=async(t,o)=>{if(te()){ze(!0);try{if(t==="anthropic"||t==="openai"){const r=b.endpointRouting?{...b.endpointRouting}:{},l=r[t]??{defaults:b.defaults,modelRoutes:(t==="anthropic"?b.modelRoutes:{})??{}},n={defaults:l.defaults??b.defaults,modelRoutes:l.modelRoutes??{}};let i=l.validation;o?(i={...i??{},mode:"claude-code"},i.allowExperimentalBlocks===void 0&&(i.allowExperimentalBlocks=!0)):i=void 0;const h=i?{...n,validation:i}:{...n},v={...r,[t]:h},R={...b,endpointRouting:v};await W.put("/api/config",R),P(R)}else{const r=b.customEndpoints??[],l=r.findIndex(re=>re.id===t);if(l===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const n=r[l],i=n.routing??{defaults:b.defaults,modelRoutes:{}};let h=i.validation;o?(h={...h??{},mode:"claude-code"},h.allowExperimentalBlocks===void 0&&(h.allowExperimentalBlocks=!0)):h=void 0;const v=h?{...i,validation:h}:{...i},R={...n,routing:v},U=[...r];U[l]=R;const K={...b,customEndpoints:U};await W.put("/api/config",K),P(K)}a({title:s(o?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),m.refetch()}catch(r){const l=Re(r);a({title:s("modelManagement.toast.claudeValidationFailure",{message:l.message}),variant:"error"})}finally{ze(!1)}}},Et=(t,o)=>{T(r=>{const l=r[t]||[];return l.some(n=>n.source.trim()===o.trim())?r:{...r,[t]:[...l,{id:Be(),source:o,target:""}]}}),F(r=>({...r,[t]:null}))},Me=(t,o,r,l)=>{T(n=>({...n,[t]:(n[t]||[]).map(i=>i.id===o?{...i,[r]:l}:i)})),F(n=>({...n,[t]:null}))},Ct=(t,o)=>{T(r=>({...r,[t]:(r[t]||[]).filter(l=>l.id!==o)})),F(r=>({...r,[t]:null}))},St=t=>{var r,l;if(!b)return;const o=j.find(n=>n.id===t);if(o){const n=((r=o.routing)==null?void 0:r.modelRoutes)??{};T(i=>({...i,[t]:J(n)}))}else{const n=b.endpointRouting??{},i=t,h=i==="anthropic"?b.modelRoutes??{}:{},v=((l=n[i])==null?void 0:l.modelRoutes)??h;T(R=>({...R,[t]:J(v)}))}F(n=>({...n,[t]:null}))},Rt=async t=>{var l;if(!te())return;const o=ae[t]||[],r={};for(const n of o){const i=n.source.trim(),h=n.target.trim();if(!(!i&&!h)){if(!i||!h){F(v=>({...v,[t]:s("settings.validation.routePair")}));return}if(r[i]){F(v=>({...v,[t]:s("settings.validation.routeDuplicate",{model:i})}));return}r[i]=h}}F(n=>({...n,[t]:null})),me(t);try{const n=j.find(i=>i.id===t);if(n){const i={...n.routing||{},modelRoutes:r,defaults:((l=n.routing)==null?void 0:l.defaults)||b.defaults};await ge.update(t,{routing:i}),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const i=b.endpointRouting?{...b.endpointRouting}:{},h=t,v=i[h]??{defaults:b.defaults,modelRoutes:h==="anthropic"?b.modelRoutes??{}:{}},R={...v,defaults:v.defaults??b.defaults,modelRoutes:r},U={...i,[h]:R},K={...b,endpointRouting:U,modelRoutes:h==="anthropic"?r:b.modelRoutes??{}};await W.put("/api/config",K),P(K),a({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}T(i=>({...i,[t]:J(r)}))}catch(n){a({title:s("modelManagement.toast.routesSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{me(null)}},Pt=()=>e.jsxs("section",{className:tt,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:Kt.default,children:s("providers.count",{count:ut})}),e.jsx("button",{type:"button",className:q,onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:oe,onClick:gt,children:s("providers.actions.add")})]})]}),m.isPending||!b&&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")}):H.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:H.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(Yt,{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:st.success,children:s("providers.card.defaultModel",{model:mt.get(t.id)??t.defaultModel})}):e.jsx("div",{className:st.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(o=>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:lt(o)})]},o.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:q,onClick:()=>ft(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>jt(t),disabled:D===t.id,className:D===t.id?`${q} opacity-60 cursor-not-allowed`:q,children:D===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:$e,onClick:()=>Nt(t),children:s("providers.actions.delete")})]})]},t.id))})]}),Dt=t=>{const o=je[t],r=ye[t],l=u[t],n=w===t;return 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:r,onChange:i=>xt(t,i.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:ce,disabled:n}),e.jsx("button",{type:"button",onClick:()=>ht(t),className:oe,disabled:n,children:s(n?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),l?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:l}):null,o.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:o.map(i=>{const h=(S==null?void 0:S.endpoint)===t&&(S==null?void 0:S.name)===i.name,v=($==null?void 0:$.endpoint)===t&&($==null?void 0:$.name)===i.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:i.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>bt(t,i),className:h||v?`${q} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${oe} text-xs px-2 py-1`,disabled:h||v,children:s(h?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>pt(t,i),className:v||h?`${q} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${$e} text-xs px-2 py-1`,disabled:v||h,children:s(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},i.name)})})]})},Ot=t=>{var Ee;const o=ae[t]||[],r=De[t],l=d.find(M=>M.key===t),i=((Ee=l==null?void 0:l.protocols)==null?void 0:Ee.includes("anthropic"))??t==="anthropic"?zt:Qt,h=Oe===t,v=(l==null?void 0:l.label)??s(`modelManagement.tabs.${t}`),R=(l==null?void 0:l.isSystem)===!1?l.description:s(`settings.routing.descriptionByEndpoint.${t}`),U=`route-source-${t}`,K=`route-target-${t}`,re=Gt(t,j),_=Wt(t,b,j),le=re&&(_==null?void 0:_.mode)==="claude-code";return e.jsxs("section",{className:tt,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:v})}),e.jsx("p",{className:"max-w-3xl text-sm text-slate-600 dark:text-slate-400",children:R}),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:()=>wt(t),className:q,disabled:h,children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>St(t),className:q,disabled:h,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Rt(t),className:oe,disabled:h,children:s(h?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),re&&e.jsx("div",{className:"mt-6 rounded-xl border border-blue-200/60 bg-blue-50/60 p-4 dark:border-blue-500/40 dark:bg-blue-900/30 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-sm font-semibold text-blue-700 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-600/80 dark:text-blue-200/80",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-blue-300 text-blue-600 focus:ring-blue-500",checked:!!le,onChange:M=>Mt(t,M.target.checked),disabled:qe}),e.jsx("span",{className:"text-xs font-medium text-blue-700 dark:text-blue-200",children:s(qe?"common.actions.saving":"modelManagement.claudeValidation.toggleLabel")})]})]}),e.jsx("span",{className:`text-xs font-semibold ${le?"text-emerald-600 dark:text-emerald-300":"text-slate-500 dark:text-slate-400"}`,children:s(le?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})}),Dt(t),r?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:r}):null,o.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:o.map((M,Ce)=>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:Ce+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:M.source,onChange:pe=>Me(t,M.id,"source",pe.target.value),className:ce,placeholder:"claude-3.5-sonnet",list:U,disabled:h})]})}),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 pe=M.target.trim(),Ye=Qe.some(G=>G.value===pe)?pe:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:Ye,onChange:G=>{const Xe=G.target.value;Xe==="__custom"?Me(t,M.id,"target",pe):Me(t,M.id,"target",Xe)},className:ct,disabled:h,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),Qe.map(G=>e.jsx("option",{value:G.value,children:G.label},`${K}-${G.value}`))]}),Ye==="__custom"&&e.jsx("input",{type:"text",value:M.target,onChange:G=>Me(t,M.id,"target",G.target.value),className:ce,placeholder:"providerId:modelId",disabled:h})]})})()]})}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:$e,onClick:()=>Ct(t,M.id),disabled:h,children:s("settings.routing.remove")})})]})]},M.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:i.map(M=>e.jsx("button",{type:"button",onClick:()=>Et(t,M),className:q,disabled:h,children:M},`${t}-${M}`))})]})}),e.jsx("datalist",{id:U,children:i.map(M=>e.jsx("option",{value:M},`${U}-${M}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx("div",{className:It,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",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.jsxs("button",{onClick:()=>{ke(void 0),ve(!0)},className:oe,children:["+ ",s("modelManagement.addEndpoint")]})]})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:d.map(t=>{const o=x===t.key;return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(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 ${o?"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.canDelete&&e.jsx("button",{onClick:r=>{r.stopPropagation(),kt(t.key)},className:"absolute -top-2 -right-2 h-6 w-6 rounded-full bg-red-500 text-white hover:bg-red-600 flex items-center justify-center text-xs shadow-md",title:s("common.delete"),children:"×"})]},t.key)})}),x==="providers"?Pt():Ot(x),e.jsx(qt,{open:I,mode:B,provider:B==="edit"?y:void 0,existingProviderIds:H.map(t=>t.id).filter(t=>B==="edit"&&y?t!==y.id:!0),onClose:()=>{O(!1),E(void 0),V("create")},onSubmit:vt}),e.jsx(Xt,{open:fe,endpoint:ue,onClose:()=>{ve(!1),ke(void 0)},onSuccess:()=>{c.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Jt,{open:Ne,provider:Ue,options:be,preservedExtras:He,usePreset:we,onPresetChange:Le,onConfirm:yt,onClose:Je})]})}function Jt({open:s,provider:a,options:c,usePreset:m,preservedExtras:p,onPresetChange:j,onConfirm:d,onClose:x}){const{t:N}=Pe();return!s||!a?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:x,"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:N("providers.testDialog.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:N("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsx("p",{className:"mb-5 text-sm leading-relaxed text-slate-600 dark:text-slate-300",children:N("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:m,onChange:b=>j(b.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:N("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs leading-relaxed text-slate-500 dark:text-slate-400",children:N("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:N("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 grid gap-1",children:c.map(b=>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:[b.key,": ",b.value]},b.key))})]})]})]})}),Object.keys(p).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:N("providers.testDialog.preservedInfo")}),e.jsx("div",{className:"grid gap-2",children:Object.entries(p).map(([b,P])=>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:[b,": ",P]},b))})]}):null,e.jsxs("footer",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:x,className:q,children:N("providers.testDialog.cancel")}),e.jsx("button",{type:"button",onClick:()=>{d()},className:oe,children:N("providers.testDialog.primary")})]})]})]})}function lt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Yt({type:s}){const a={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:c,color:m}=a[s]||a.custom;return e.jsx("span",{className:`rounded-full ${m} px-2.5 py-1 text-xs font-semibold shadow-sm`,children:c})}function Xt({open:s,endpoint:a,onClose:c,onSuccess:m}){const{t:p}=Pe(),{pushToast:j}=it(),[d,x]=g.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});g.useEffect(()=>{if(a){let y;a.paths&&a.paths.length>0?y=a.paths:a.path&&a.protocol?y=[{path:a.path,protocol:a.protocol}]:y=[{path:"",protocol:"openai-auto"}],x({id:a.id,label:a.label,paths:y,enabled:a.enabled!==!1})}else x({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[a,s]);const N=at({mutationFn:ge.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),m(),c()},onError:y=>{const E=Re(y);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),b=at({mutationFn:y=>ge.update(y.id,y.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),m(),c()},onError:y=>{const E=Re(y);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),P=()=>{x({...d,paths:[...d.paths,{path:"",protocol:"anthropic"}]})},I=y=>{if(d.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=d.paths.filter((D,L)=>L!==y);x({...d,paths:E})},O=(y,E,D)=>{const L=[...d.paths];L[y]={...L[y],[E]:D},x({...d,paths:L})},B=y=>{if(y.preventDefault(),!d.id.trim()||!d.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const D of d.paths)if(!D.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=d.paths.map(D=>({path:D.path.trim(),protocol:D.protocol}));a?b.mutate({id:a.id,updates:{label:d.label.trim(),paths:E,enabled:d.enabled}}):N.mutate({id:d.id.trim(),label:d.label.trim(),paths:E,enabled:d.enabled})},V=N.isPending||b.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 dark:bg-black/70 z-40 transition-opacity",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 w-full max-w-md bg-white dark:bg-gray-900 shadow-xl z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:p(a?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("button",{onClick:c,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:B,className:"flex-1 p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.id,onChange:y=>x({...d,id:y.target.value}),className:ce,placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!a,required:!0}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.label,onChange:y=>x({...d,label:y.target.value}),className:ce,placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("button",{type:"button",onClick:P,className:"text-sm text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",children:["+ ",p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:d.paths.map((y,E)=>e.jsxs("div",{className:"p-3 border border-gray-200 dark:border-gray-700 rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{type:"text",value:y.path,onChange:D=>O(E,"path",D.target.value),className:ce,placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs("select",{value:y.protocol,onChange:D=>O(E,"protocol",D.target.value),className:ct,required:!0,children:[e.jsx("option",{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx("option",{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]}),d.paths.length>1&&e.jsx("button",{type:"button",onClick:()=>I(E),className:"text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 mt-1",title:p("modelManagement.removePath"),children:e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}),E===0&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",id:"enabled",checked:d.enabled,onChange:y=>x({...d,enabled:y.target.checked}),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-700 dark:bg-gray-800"}),e.jsx("label",{htmlFor:"enabled",className:"text-sm text-gray-700 dark:text-gray-300",children:p("modelManagement.endpointEnabled")})]}),!a&&e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-900/20 p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-300",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 p-6 border-t border-gray-200 dark:border-gray-800",children:[e.jsx("button",{type:"button",onClick:c,className:`${q} flex-1`,disabled:V,children:p("common.cancel")}),e.jsx("button",{type:"submit",onClick:B,className:`${oe} flex-1`,disabled:V,children:p(V?"common.saving":a?"common.save":"common.create")})]})]})})]}):null}export{as as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,d as s,a6 as u,m,a7 as h,G as f,a8 as g,a9 as o,J as p}from"./index-
|
|
1
|
+
import{j as e,d as s,a6 as u,m,a7 as h,G as f,a8 as g,a9 as o,J as p}from"./index-dFe_7qSp.js";function j({icon:a,title:r,description:l,badge:d,actions:n,className:i,disableAnimation:t,variant:x="default"}){const c=x==="plain"?h:f;return e.jsxs("div",{className:s(c,!t&&"animate-slide-up",i),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-6",children:[a?e.jsx("div",{className:"grid h-14 w-14 place-items-center rounded-2xl bg-gradient-to-br from-blue-600/15 to-indigo-600/10 text-blue-600 shadow-lg shadow-blue-200/30 ring-1 ring-blue-500/20 backdrop-blur-sm dark:from-blue-500/25 dark:to-indigo-500/15 dark:text-blue-200 dark:shadow-xl dark:shadow-blue-500/20 dark:ring-blue-400/20",children:a}):null,e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight text-slate-900 dark:text-slate-50 gradient-text",children:r}),d?e.jsx("span",{className:s(u,"shadow-md"),children:d}):null]}),l?e.jsx("div",{className:s(m,"max-w-3xl text-base leading-relaxed"),children:l}):null]})]}),n?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-4",children:n}):null]})}function N({title:a,description:r,actions:l,className:d,contentClassName:n,children:i,disableAnimation:t,variant:x="default"}){const c=x==="plain"?o:p;return e.jsxs("section",{className:s(c,!t&&"animate-slide-up",d),children:[(a||r||l)&&e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-6",children:[e.jsxs("div",{className:"space-y-3",children:[typeof a=="string"?e.jsx("h2",{className:s(g,"text-base font-bold"),children:a}):a,r?e.jsx("div",{className:s(m,"max-w-3xl text-sm leading-relaxed"),children:r}):null]}),l?e.jsx("div",{className:"flex shrink-0 items-center gap-3",children:l}):null]}),e.jsx("div",{className:s("flex flex-col gap-6",n),children:i})]})}export{j as P,N as a};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as se,u as be,a as fe,r as m,j as e,d as n,V as ke,L as Y,b as T,k as B,H as Z,N as b,m as y,M as ee}from"./index-
|
|
1
|
+
import{c as se,u as be,a as fe,r as m,j as e,d as n,V as ke,L as Y,b as T,k as B,H as Z,N as b,m as y,M as ee}from"./index-dFe_7qSp.js";import{u as te}from"./useApiQuery-i7GI_aGQ.js";import{P as ye,a as P}from"./PageSection-BJJ735Qk.js";import{C as Ne}from"./copy-DMW-t8h3.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,d as n,K as u}from"./index-
|
|
1
|
+
import{j as s,d as n,K as u}from"./index-dFe_7qSp.js";function c({variant:a,children:e,icon:r,className:t}){return s.jsxs("span",{className:n(u[a],t),children:[r||s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current","aria-hidden":"true"}),e]})}export{c as S};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Q as VL,R as zL,r as GL}from"./index-
|
|
1
|
+
import{Q as VL,R as zL,r as GL}from"./index-dFe_7qSp.js";/*! *****************************************************************************
|
|
2
2
|
Copyright (c) Microsoft Corporation.
|
|
3
3
|
|
|
4
4
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -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-xs4UfKRq.js","assets/index-BM-Zc1f-.js","assets/PageSection-BJJ735Qk.js","assets/Input-Iev5RCKK.js","assets/StatusBadge-9lxhNpvi.js","assets/useApiQuery-i7GI_aGQ.js","assets/Logs-DSGqxauM.js","assets/FormField-DKWx0tXD.js","assets/Button-6f5FYqHp.js","assets/Events-D_RJKNNo.js","assets/refresh-cw-BF1LiBLP.js","assets/ModelManagement-D11jx2bC.js","assets/ApiKeys-qhC2jZqJ.js","assets/copy-DMW-t8h3.js","assets/Settings-BT-6W3GT.js","assets/About-BY3JDEBL.js","assets/info-ByJJXVcp.js","assets/Help-CXLtGK8v.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),D=(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){D(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 jd={exports:{}},eo={},Md={exports:{}},M={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react.production.min.js
|
|
@@ -209,4 +209,4 @@ env_key = "cc_gw_key"
|
|
|
209
209
|
"protocol": "anthropic"
|
|
210
210
|
}
|
|
211
211
|
\`\`\`
|
|
212
|
-
After configuration, clients access via \`http://127.0.0.1:4100/claude/v1/messages\` (path auto-expansion).`,'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.","Use **routing presets** to save common routing configurations and quickly switch between different provider setups.","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:"How do I use custom endpoints?",a:'Create a custom endpoint in the "Model Management" page by configuring a base path (e.g., `/my-endpoint`) and protocol type. The system automatically registers full API paths based on the protocol. For example, after configuring `/claude` + `anthropic` protocol, clients access via `http://127.0.0.1:4100/claude/v1/messages`.\n\nIf you encounter 404 errors, check:\n1) Is the endpoint enabled?\n2) Are clients using the complete path (including protocol subpath)?\n3) Check server logs to confirm route registration'},{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."},{q:"How can I use different models for different clients?",a:'Create separate API keys for each client and configure different routing rules in "Model Management → Routing". You can also create dedicated custom endpoints for different clients.'}]}},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."}},endpoints:{title:"Custom Endpoints",description:"Manage custom API endpoints with multiple protocol support.",createButton:"Add Endpoint",createTitle:"Create Endpoint",editTitle:"Edit Endpoint",emptyTitle:"No custom endpoints",emptyDescription:'Click "Add Endpoint" to create your first custom endpoint.',loadError:"Failed to load endpoints",id:"ID",path:"Path",disabled:"Disabled",hasRouting:"Routing configured",protocols:{anthropic:"Anthropic Protocol","openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses"},protocolHints:{anthropic:"Anthropic Messages API protocol (/v1/messages)","openai-chat":"OpenAI Chat Completions API protocol (/v1/chat/completions)","openai-responses":"OpenAI Responses API protocol (/v1/responses)"},form:{id:"Endpoint ID",idPlaceholder:"e.g. custom-api",idHint:"ID cannot be changed after creation, used for internal identification.",label:"Display Name",labelPlaceholder:"e.g. My Custom API",path:"Access Path",pathPlaceholder:"e.g. /custom/api",pathHint:"Path must start with /. Changes take effect immediately.",protocol:"Protocol Type",enabled:"Enable this endpoint"},routing:{title:"Routing Configuration (Optional)",modelRoutes:"Model Routing Rules",addRoute:"Add Rule",noRoutes:"No routing rules",sourceModelPlaceholder:"Source model (e.g. claude-3-5-sonnet-20241022)",targetPlaceholder:"Target (e.g. anthropic:claude-3-5-sonnet-20241022)",modelRoutesHint:"Format: source model → provider:model, wildcards supported (e.g. gpt-* → openai:*)",defaults:"Default Model Configuration",defaultCompletion:"Default for completion tasks",defaultReasoning:"Default for reasoning tasks",defaultBackground:"Default for background tasks",longContextThreshold:"Long context threshold (tokens)",defaultPlaceholder:"e.g. anthropic:claude-3-5-sonnet-20241022"},createSuccess:"Endpoint created successfully",createError:"Failed to create: {{error}}",updateSuccess:"Endpoint updated successfully",updateError:"Failed to update: {{error}}",deleteSuccess:"Endpoint deleted successfully",deleteError:"Failed to delete: {{error}}",deleteConfirm:'Are you sure you want to delete endpoint "{{label}}"? This action cannot be undone.',validationError:"Please fill in all required fields"}}}};de.isInitialized||de.use(ev).init({resources:Yw,lng:"zh",fallbackLng:"en",interpolation:{escapeValue:!1}});const Zh=S.createContext(void 0);function Xw(){return`toast_${Math.random().toString(36).slice(2)}`}function Zw({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??Xw();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 ok(){const e=S.useContext(Zh);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function ex({children:e}){const[t]=S.useState(()=>new bw);return E.jsx(Tw,{client:t,children:E.jsx(sv,{i18n:de,children:E.jsx(wv,{children:E.jsx(Zw,{children:E.jsx(X1,{children:e})})})})})}function em(){const{t:e}=Ar();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")})]})})}function ak(){const{t:e}=Ar();return E.jsxs("div",{className:"flex items-center gap-3 text-sm text-slate-500 dark:text-slate-400",children:[E.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-slate-300 border-t-transparent dark:border-slate-600"}),E.jsx("span",{children:e("common.loading")})]})}const tx=S.lazy(()=>_t(()=>import("./Dashboard-Bfw6yiF4.js"),__vite__mapDeps([0,1,2,3,4,5]))),nx=S.lazy(()=>_t(()=>import("./Logs-CCyXKpHp.js"),__vite__mapDeps([6,5,2,7,3,8,4]))),rx=S.lazy(()=>_t(()=>import("./Events-DjBfGGvr.js"),__vite__mapDeps([9,10]))),Td=S.lazy(()=>_t(()=>import("./ModelManagement-EGKGD6z0.js"),__vite__mapDeps([11,5]))),sx=S.lazy(()=>_t(()=>import("./ApiKeys-Cj7BE4i-.js"),__vite__mapDeps([12,1,5,2,7,3,8,4,13]))),ix=S.lazy(()=>_t(()=>import("./Settings-DtX-SQH8.js"),__vite__mapDeps([14,5,2,13]))),ox=S.lazy(()=>_t(()=>import("./About-CuhVJpOY.js"),__vite__mapDeps([15,5,2,3,8,16,10]))),ax=S.lazy(()=>_t(()=>import("./Help-CboPPlN8.js"),__vite__mapDeps([17,2,16]))),lx=S.lazy(()=>_t(()=>import("./Login-DdvwaiG0.js"),[]));function ux({children:e}){const{authEnabled:t,isAuthenticated:n,loading:r}=Bh(),s=gn();return r?E.jsx(em,{}):!t||n?e:E.jsx(lh,{to:"/login",replace:!0,state:{from:s}})}function cx(){return E.jsx(ex,{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(je,{path:"/",element:E.jsx(ux,{children:E.jsx(ew,{})}),children:[E.jsx(je,{index:!0,element:E.jsx(tx,{})}),E.jsx(je,{path:"logs",element:E.jsx(nx,{})}),E.jsx(je,{path:"events",element:E.jsx(rx,{})}),E.jsx(je,{path:"models",element:E.jsx(Td,{})}),E.jsx(je,{path:"providers",element:E.jsx(Td,{})}),E.jsx(je,{path:"api-keys",element:E.jsx(sx,{})}),E.jsx(je,{path:"settings",element:E.jsx(ix,{})}),E.jsx(je,{path:"about",element:E.jsx(ox,{})}),E.jsx(je,{path:"help",element:E.jsx(ax,{})})]}),E.jsx(je,{path:"/login",element:E.jsx(lx,{})}),E.jsx(je,{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(cx,{})}));export{iw as $,Pe as A,lv as B,ik as C,tt as D,sk as E,cv as F,fx as G,vx as H,ek as I,hx as J,Lx as K,em as L,wx as M,Cx as N,Px as O,dv as P,im as Q,Wd as R,Eo as S,bx as T,Tx as U,yv as V,hv as W,hw as X,aw as Y,pl as Z,bo as _,ok as a,ow as a0,fl as a1,Vh as a2,xw as a3,cw as a4,rk as a5,xx as a6,px as a7,gx as a8,mx as a9,sh as aa,gn as ab,Bh as ac,ot as b,De as c,Lt as d,Dx as e,Ax as f,kx as g,Ix as h,Ex as i,E as j,yh as k,Nx as l,yx as m,Fx as n,Ox as o,Rx as p,A0 as q,S as r,Sx as s,ia as t,Ar as u,ak as v,tk as w,nk as x,Ps as y,Cw as z};
|
|
212
|
+
After configuration, clients access via \`http://127.0.0.1:4100/claude/v1/messages\` (path auto-expansion).`,'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.","Use **routing presets** to save common routing configurations and quickly switch between different provider setups.","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:"How do I use custom endpoints?",a:'Create a custom endpoint in the "Model Management" page by configuring a base path (e.g., `/my-endpoint`) and protocol type. The system automatically registers full API paths based on the protocol. For example, after configuring `/claude` + `anthropic` protocol, clients access via `http://127.0.0.1:4100/claude/v1/messages`.\n\nIf you encounter 404 errors, check:\n1) Is the endpoint enabled?\n2) Are clients using the complete path (including protocol subpath)?\n3) Check server logs to confirm route registration'},{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."},{q:"How can I use different models for different clients?",a:'Create separate API keys for each client and configure different routing rules in "Model Management → Routing". You can also create dedicated custom endpoints for different clients.'}]}},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."}},endpoints:{title:"Custom Endpoints",description:"Manage custom API endpoints with multiple protocol support.",createButton:"Add Endpoint",createTitle:"Create Endpoint",editTitle:"Edit Endpoint",emptyTitle:"No custom endpoints",emptyDescription:'Click "Add Endpoint" to create your first custom endpoint.',loadError:"Failed to load endpoints",id:"ID",path:"Path",disabled:"Disabled",hasRouting:"Routing configured",protocols:{anthropic:"Anthropic Protocol","openai-chat":"OpenAI Chat","openai-responses":"OpenAI Responses"},protocolHints:{anthropic:"Anthropic Messages API protocol (/v1/messages)","openai-chat":"OpenAI Chat Completions API protocol (/v1/chat/completions)","openai-responses":"OpenAI Responses API protocol (/v1/responses)"},form:{id:"Endpoint ID",idPlaceholder:"e.g. custom-api",idHint:"ID cannot be changed after creation, used for internal identification.",label:"Display Name",labelPlaceholder:"e.g. My Custom API",path:"Access Path",pathPlaceholder:"e.g. /custom/api",pathHint:"Path must start with /. Changes take effect immediately.",protocol:"Protocol Type",enabled:"Enable this endpoint"},routing:{title:"Routing Configuration (Optional)",modelRoutes:"Model Routing Rules",addRoute:"Add Rule",noRoutes:"No routing rules",sourceModelPlaceholder:"Source model (e.g. claude-3-5-sonnet-20241022)",targetPlaceholder:"Target (e.g. anthropic:claude-3-5-sonnet-20241022)",modelRoutesHint:"Format: source model → provider:model, wildcards supported (e.g. gpt-* → openai:*)",defaults:"Default Model Configuration",defaultCompletion:"Default for completion tasks",defaultReasoning:"Default for reasoning tasks",defaultBackground:"Default for background tasks",longContextThreshold:"Long context threshold (tokens)",defaultPlaceholder:"e.g. anthropic:claude-3-5-sonnet-20241022"},createSuccess:"Endpoint created successfully",createError:"Failed to create: {{error}}",updateSuccess:"Endpoint updated successfully",updateError:"Failed to update: {{error}}",deleteSuccess:"Endpoint deleted successfully",deleteError:"Failed to delete: {{error}}",deleteConfirm:'Are you sure you want to delete endpoint "{{label}}"? This action cannot be undone.',validationError:"Please fill in all required fields"}}}};de.isInitialized||de.use(ev).init({resources:Yw,lng:"zh",fallbackLng:"en",interpolation:{escapeValue:!1}});const Zh=S.createContext(void 0);function Xw(){return`toast_${Math.random().toString(36).slice(2)}`}function Zw({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??Xw();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 ok(){const e=S.useContext(Zh);if(!e)throw new Error("useToast must be used within ToastProvider");return e}function ex({children:e}){const[t]=S.useState(()=>new bw);return E.jsx(Tw,{client:t,children:E.jsx(sv,{i18n:de,children:E.jsx(wv,{children:E.jsx(Zw,{children:E.jsx(X1,{children:e})})})})})}function em(){const{t:e}=Ar();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")})]})})}function ak(){const{t:e}=Ar();return E.jsxs("div",{className:"flex items-center gap-3 text-sm text-slate-500 dark:text-slate-400",children:[E.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-slate-300 border-t-transparent dark:border-slate-600"}),E.jsx("span",{children:e("common.loading")})]})}const tx=S.lazy(()=>_t(()=>import("./Dashboard-xs4UfKRq.js"),__vite__mapDeps([0,1,2,3,4,5]))),nx=S.lazy(()=>_t(()=>import("./Logs-DSGqxauM.js"),__vite__mapDeps([6,5,2,7,3,8,4]))),rx=S.lazy(()=>_t(()=>import("./Events-D_RJKNNo.js"),__vite__mapDeps([9,10]))),Td=S.lazy(()=>_t(()=>import("./ModelManagement-D11jx2bC.js"),__vite__mapDeps([11,5]))),sx=S.lazy(()=>_t(()=>import("./ApiKeys-qhC2jZqJ.js"),__vite__mapDeps([12,1,5,2,7,3,8,4,13]))),ix=S.lazy(()=>_t(()=>import("./Settings-BT-6W3GT.js"),__vite__mapDeps([14,5,2,13]))),ox=S.lazy(()=>_t(()=>import("./About-BY3JDEBL.js"),__vite__mapDeps([15,5,2,3,8,16,10]))),ax=S.lazy(()=>_t(()=>import("./Help-CXLtGK8v.js"),__vite__mapDeps([17,2,16]))),lx=S.lazy(()=>_t(()=>import("./Login-qc-n0iUi.js"),[]));function ux({children:e}){const{authEnabled:t,isAuthenticated:n,loading:r}=Bh(),s=gn();return r?E.jsx(em,{}):!t||n?e:E.jsx(lh,{to:"/login",replace:!0,state:{from:s}})}function cx(){return E.jsx(ex,{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(je,{path:"/",element:E.jsx(ux,{children:E.jsx(ew,{})}),children:[E.jsx(je,{index:!0,element:E.jsx(tx,{})}),E.jsx(je,{path:"logs",element:E.jsx(nx,{})}),E.jsx(je,{path:"events",element:E.jsx(rx,{})}),E.jsx(je,{path:"models",element:E.jsx(Td,{})}),E.jsx(je,{path:"providers",element:E.jsx(Td,{})}),E.jsx(je,{path:"api-keys",element:E.jsx(sx,{})}),E.jsx(je,{path:"settings",element:E.jsx(ix,{})}),E.jsx(je,{path:"about",element:E.jsx(ox,{})}),E.jsx(je,{path:"help",element:E.jsx(ax,{})})]}),E.jsx(je,{path:"/login",element:E.jsx(lx,{})}),E.jsx(je,{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(cx,{})}));export{iw as $,Pe as A,lv as B,ik as C,tt as D,sk as E,cv as F,fx as G,vx as H,ek as I,hx as J,Lx as K,em as L,wx as M,Cx as N,Px as O,dv as P,im as Q,Wd as R,Eo as S,bx as T,Tx as U,yv as V,hv as W,hw as X,aw as Y,pl as Z,bo as _,ok as a,ow as a0,fl as a1,Vh as a2,xw as a3,cw as a4,rk as a5,xx as a6,px as a7,gx as a8,mx as a9,sh as aa,gn as ab,Bh as ac,ot as b,De as c,Lt as d,Dx as e,Ax as f,kx as g,Ix as h,Ex as i,E as j,yh as k,Nx as l,yx as m,Fx as n,Ox as o,Rx as p,A0 as q,S as r,Sx as s,ia as t,Ar as u,ak as v,tk as w,nk as x,Ps as y,Cw as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var ft=e=>{throw TypeError(e)};var $=(e,t,s)=>t.has(e)||ft("Cannot "+s);var i=(e,t,s)=>($(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)=>($(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),d=(e,t,s)=>($(e,t,"access private method"),s);import{S as It,X as pt,Y as S,x as G,Z as H,D as J,_ as tt,$ as bt,a0 as Ot,a1 as q,a2 as Tt,a3 as wt,a4 as yt,A as St,r as I,E as Qt,C as xt,a5 as Mt,b as _t,t as Ut}from"./index-B1C47gGx.js";var g,a,j,y,Q,U,E,O,z,D,F,x,M,T,P,n,B,et,st,it,rt,at,nt,ht,Ct,vt,Dt=(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,D);b(this,F);b(this,x);b(this,M);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&&!G(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,F))==null?void 0:dt.state.data,i(this,F)):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,D);else try{u(this,z,s.select),f=s.select(f),f=yt(o==null?void 0:o.data,f,s),u(this,D,f),u(this,O,null)}catch(R){u(this,O,R)}i(this,O)&&(A=i(this,O),f=i(this,D),k=Date.now(),m="error");const X=l.fetchStatus==="fetching",Y=m==="pending",Z=m==="error",ut=Y&&X,lt=f!==void 0,C={status:m,fetchStatus:l.fetchStatus,isPending:Y,isSuccess:m==="success",isError:Z,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:X,isRefetching:X&&!Y,isLoadingError:Z&&!lt,isPaused:l.fetchStatus==="paused",isPlaceholderData:N,isRefetchError:Z&<,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,F,i(this,a)),G(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,D=new WeakMap,F=new WeakMap,x=new WeakMap,M=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(J)),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,x,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,M,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,x)&&(q.clearTimeout(i(this,x)),u(this,x,void 0))},nt=function(){i(this,M)&&(q.clearInterval(i(this,M)),u(this,M,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 Ft(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 Ft(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!G(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=xt(),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)):J;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(J).finally(()=>{p.updateResult()})}return c.notifyOnChangeProps?v:p.trackResult(v)}function qt(e,t){return Kt(e,Dt)}function $t(e,t,s){return qt({queryKey:e,placeholderData:Mt,...s,queryFn:async()=>{try{return(await _t.request(t)).data}catch(r){throw Ut(r)}}})}export{qt as a,$t as u};
|
|
1
|
+
var ft=e=>{throw TypeError(e)};var $=(e,t,s)=>t.has(e)||ft("Cannot "+s);var i=(e,t,s)=>($(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)=>($(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),d=(e,t,s)=>($(e,t,"access private method"),s);import{S as It,X as pt,Y as S,x as G,Z as H,D as J,_ as tt,$ as bt,a0 as Ot,a1 as q,a2 as Tt,a3 as wt,a4 as yt,A as St,r as I,E as Qt,C as xt,a5 as Mt,b as _t,t as Ut}from"./index-dFe_7qSp.js";var g,a,j,y,Q,U,E,O,z,D,F,x,M,T,P,n,B,et,st,it,rt,at,nt,ht,Ct,vt,Dt=(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,D);b(this,F);b(this,x);b(this,M);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&&!G(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,F))==null?void 0:dt.state.data,i(this,F)):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,D);else try{u(this,z,s.select),f=s.select(f),f=yt(o==null?void 0:o.data,f,s),u(this,D,f),u(this,O,null)}catch(R){u(this,O,R)}i(this,O)&&(A=i(this,O),f=i(this,D),k=Date.now(),m="error");const X=l.fetchStatus==="fetching",Y=m==="pending",Z=m==="error",ut=Y&&X,lt=f!==void 0,C={status:m,fetchStatus:l.fetchStatus,isPending:Y,isSuccess:m==="success",isError:Z,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:X,isRefetching:X&&!Y,isLoadingError:Z&&!lt,isPaused:l.fetchStatus==="paused",isPlaceholderData:N,isRefetchError:Z&<,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,F,i(this,a)),G(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,D=new WeakMap,F=new WeakMap,x=new WeakMap,M=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(J)),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,x,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,M,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,x)&&(q.clearTimeout(i(this,x)),u(this,x,void 0))},nt=function(){i(this,M)&&(q.clearInterval(i(this,M)),u(this,M,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 Ft(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 Ft(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!G(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=xt(),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)):J;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(J).finally(()=>{p.updateResult()})}return c.notifyOnChangeProps?v:p.trackResult(v)}function qt(e,t){return Kt(e,Dt)}function $t(e,t,s){return qt({queryKey:e,placeholderData:Mt,...s,queryFn:async()=>{try{return(await _t.request(t)).data}catch(r){throw Ut(r)}}})}export{qt as a,$t as u};
|
package/web/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-dFe_7qSp.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-CJMKkw2H.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body class="bg-slate-50 text-slate-900 dark:bg-slate-900 dark:text-slate-50">
|