@chenpu17/cc-gw 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/package.json +1 -1
- package/src/cli/dist/index.js +2 -1
- package/src/server/dist/index.js +26 -15
- package/src/web/dist/assets/About-Bxxb0hlP.js +11 -0
- package/src/web/dist/assets/ApiKeys-B57jV3AH.js +16 -0
- package/src/web/dist/assets/Button-DIJdkdyt.js +1 -0
- package/src/web/dist/assets/Dashboard-Cxu97ZgH.js +16 -0
- package/src/web/dist/assets/FormField-JMg-tjrG.js +1 -0
- package/src/web/dist/assets/Help-Bcnhv1mL.js +6 -0
- package/src/web/dist/assets/Input-BOaaGybK.js +1 -0
- package/src/web/dist/assets/Logs-DhIgaGtG.js +1 -0
- package/src/web/dist/assets/ModelManagement-BR4fCLUq.js +1 -0
- package/src/web/dist/assets/PageSection-Dndgc9r9.js +1 -0
- package/src/web/dist/assets/Settings-B83xPKID.js +1 -0
- package/src/web/dist/assets/StatusBadge-DOVCfoYm.js +1 -0
- package/src/web/dist/assets/copy-CG_L9fTW.js +6 -0
- package/src/web/dist/assets/index-CD8snFBp.css +1 -0
- package/src/web/dist/assets/index-COB9rriK.js +143 -0
- package/src/web/dist/assets/{index-xwXTrmLG.js → index-mV9BV7rj.js} +16 -16
- package/src/web/dist/assets/info-DNl8lKHj.js +6 -0
- package/src/web/dist/assets/{useApiQuery-BigNbUj6.js → useApiQuery-mnvEnqVq.js} +6 -6
- package/src/web/dist/index.html +2 -2
- package/src/web/dist/assets/About-DWr_0zUb.js +0 -1
- package/src/web/dist/assets/ApiKeys-45nn2Z53.js +0 -21
- package/src/web/dist/assets/Dashboard-ixJ72-sA.js +0 -1
- package/src/web/dist/assets/Help-Badmmw97.js +0 -1
- package/src/web/dist/assets/Logs-BufGG-m_.js +0 -1
- package/src/web/dist/assets/ModelManagement-Br1rWj5I.js +0 -1
- package/src/web/dist/assets/Settings-CQatmqRt.js +0 -1
- package/src/web/dist/assets/index-Gx2WWHJn.css +0 -1
- package/src/web/dist/assets/index-Jqz_kqzz.js +0 -133
package/README.md
CHANGED
|
@@ -127,7 +127,8 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
|
|
|
127
127
|
"claude-opus-4-1-20250805": "anthropic:claude-3-5-sonnet-latest"
|
|
128
128
|
},
|
|
129
129
|
"logRetentionDays": 30,
|
|
130
|
-
"
|
|
130
|
+
"storeRequestPayloads": true,
|
|
131
|
+
"storeResponsePayloads": true,
|
|
131
132
|
"logLevel": "info",
|
|
132
133
|
"requestLogging": true,
|
|
133
134
|
"responseLogging": true
|
|
@@ -140,7 +141,7 @@ UI 支持中英文、深色/浅色主题以及移动端响应式布局,提供
|
|
|
140
141
|
- 模型标识使用 `providerId:modelId` 形式供路由引用。
|
|
141
142
|
- `modelRoutes`:将 Claude 发起的模型名映射到上游模型;未命中时使用 `defaults`。
|
|
142
143
|
- `routingPresets`:可选字段,保存多个 `anthropic`(或其他端点)路由模板,供 Web UI “一键切换”;每个模板仅包含 `name` 与 `modelRoutes`。
|
|
143
|
-
- `
|
|
144
|
+
- `storeRequestPayloads` / `storeResponsePayloads`:是否分别在 SQLite 中压缩保存请求原文与响应内容;关闭可减少敏感数据落盘。
|
|
144
145
|
- `logLevel`:控制 Fastify/Pino 控制台日志级别(`fatal`/`error`/`warn`/`info`/`debug`/`trace`)。
|
|
145
146
|
- `providers[].authMode`:仅在 `type: "anthropic"` 时生效,可选 `apiKey`(默认,发送 `x-api-key`)或 `authToken`(发送 `Authorization: Bearer`)。配置 Claude Code 使用 `ANTHROPIC_AUTH_TOKEN` 时,请选择 `authToken` 并在 `apiKey` 输入框填入该值。
|
|
146
147
|
- `requestLogging`:是否输出每个 HTTP 请求的进入日志。
|
|
@@ -199,7 +200,7 @@ cc-gw is a local gateway tailored for Claude Code and similar Anthropic-compatib
|
|
|
199
200
|
| ------- | ------- |
|
|
200
201
|
| Protocol adaptation | Converts Claude-style payloads into OpenAI-, Anthropic-, Kimi-, and DeepSeek-compatible requests while preserving tool calls and reasoning blocks. |
|
|
201
202
|
| Model routing | Maps incoming model IDs to configured upstream providers with fallbacks for long-context/background tasks, plus Anthropic routing presets for one-click provider swaps. |
|
|
202
|
-
| Observability | Persists request logs, token usage (including cache hits), TTFT, TPOT, and daily aggregates via better-sqlite3 with Brotli-compressed payloads. |
|
|
203
|
+
| Observability | Persists request logs, token usage (including cache hits), TTFT, TPOT, and daily aggregates via better-sqlite3 with Brotli-compressed payloads; request/response bodies can be stored independently. |
|
|
203
204
|
| Web console | React + Vite UI with dashboards, filters, provider CRUD, bilingual copy, and responsive layout. |
|
|
204
205
|
| CLI daemon | `cc-gw` command wraps start/stop/restart/status, manages PID/log files, and scaffolds a default config on first launch. |
|
|
205
206
|
|
|
@@ -246,7 +247,7 @@ If the client expects a full path, call `POST /openai/v1/responses`. The gateway
|
|
|
246
247
|
- Providers include `type`, `baseUrl`, `apiKey`, and `models` descriptions.
|
|
247
248
|
- When `type` is `anthropic`, cc-gw forwards the original Claude payload and all headers to `<baseUrl>/v1/messages`, so tool calls/metadata remain intact.
|
|
248
249
|
- Model routes use `providerId:modelId` syntax to remap Claude requests.
|
|
249
|
-
- `
|
|
250
|
+
- `storeRequestPayloads` / `storeResponsePayloads` control whether prompts and completions are persisted; disable either switch to avoid storing sensitive data.
|
|
250
251
|
- `logLevel` adjusts Fastify/Pino verbosity (`fatal` → `trace`).
|
|
251
252
|
- `requestLogging` controls whether per-request access logs are emitted to the console.
|
|
252
253
|
- `responseLogging` toggles completion logs separately so you can keep the console quieter while preserving metrics.
|
package/package.json
CHANGED
package/src/cli/dist/index.js
CHANGED
|
@@ -79,6 +79,8 @@ async function ensureConfigTemplate(port) {
|
|
|
79
79
|
port: selectedPort,
|
|
80
80
|
providers: [],
|
|
81
81
|
defaults: { ...baseDefaults },
|
|
82
|
+
storeRequestPayloads: true,
|
|
83
|
+
storeResponsePayloads: true,
|
|
82
84
|
endpointRouting: {
|
|
83
85
|
anthropic: {
|
|
84
86
|
defaults: { ...baseDefaults },
|
|
@@ -91,7 +93,6 @@ async function ensureConfigTemplate(port) {
|
|
|
91
93
|
},
|
|
92
94
|
logRetentionDays: 30,
|
|
93
95
|
modelRoutes: {},
|
|
94
|
-
storePayloads: true,
|
|
95
96
|
logLevel: "info",
|
|
96
97
|
requestLogging: true,
|
|
97
98
|
responseLogging: true
|
package/src/server/dist/index.js
CHANGED
|
@@ -105,8 +105,15 @@ function parseConfig(raw) {
|
|
|
105
105
|
if (typeof data.logRetentionDays !== "number") {
|
|
106
106
|
data.logRetentionDays = 30;
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const legacyStorePayloads = typeof data.storePayloads === "boolean" ? data.storePayloads : void 0;
|
|
109
|
+
const hasRequestFlag = typeof data.storeRequestPayloads === "boolean";
|
|
110
|
+
const hasResponseFlag = typeof data.storeResponsePayloads === "boolean";
|
|
111
|
+
const resolvedStoreRequest = hasRequestFlag ? data.storeRequestPayloads : legacyStorePayloads ?? true;
|
|
112
|
+
const resolvedStoreResponse = hasResponseFlag ? data.storeResponsePayloads : legacyStorePayloads ?? true;
|
|
113
|
+
data.storeRequestPayloads = resolvedStoreRequest;
|
|
114
|
+
data.storeResponsePayloads = resolvedStoreResponse;
|
|
115
|
+
if ("storePayloads" in data) {
|
|
116
|
+
delete data.storePayloads;
|
|
110
117
|
}
|
|
111
118
|
const legacyRoutes = sanitizeModelRoutes(data.modelRoutes);
|
|
112
119
|
if (typeof data.logLevel !== "string" || !LOG_LEVELS.has(data.logLevel)) {
|
|
@@ -1997,7 +2004,9 @@ async function registerMessagesRoute(app) {
|
|
|
1997
2004
|
}
|
|
1998
2005
|
const connector = getConnector(target.providerId);
|
|
1999
2006
|
const requestStart = Date.now();
|
|
2000
|
-
const
|
|
2007
|
+
const configSnapshot = getConfig();
|
|
2008
|
+
const storeRequestPayloads = configSnapshot.storeRequestPayloads !== false;
|
|
2009
|
+
const storeResponsePayloads = configSnapshot.storeResponsePayloads !== false;
|
|
2001
2010
|
const logId = await recordLog({
|
|
2002
2011
|
timestamp: requestStart,
|
|
2003
2012
|
endpoint: "anthropic",
|
|
@@ -2011,7 +2020,7 @@ async function registerMessagesRoute(app) {
|
|
|
2011
2020
|
apiKeyValue: encryptedApiKeyValue
|
|
2012
2021
|
});
|
|
2013
2022
|
incrementActiveRequests();
|
|
2014
|
-
if (
|
|
2023
|
+
if (storeRequestPayloads) {
|
|
2015
2024
|
await upsertLogPayload(logId, {
|
|
2016
2025
|
prompt: (() => {
|
|
2017
2026
|
try {
|
|
@@ -2068,7 +2077,7 @@ async function registerMessagesRoute(app) {
|
|
|
2068
2077
|
console.warn(
|
|
2069
2078
|
`[cc-gw][provider:${target.providerId}] upstream error status=${upstream.status} body=${bodyText || "<empty>"}`
|
|
2070
2079
|
);
|
|
2071
|
-
if (
|
|
2080
|
+
if (storeResponsePayloads) {
|
|
2072
2081
|
await upsertLogPayload(logId, { response: bodyText || null });
|
|
2073
2082
|
}
|
|
2074
2083
|
await commitUsage(0, 0);
|
|
@@ -2108,7 +2117,7 @@ async function registerMessagesRoute(app) {
|
|
|
2108
2117
|
outputTokens: outputTokens2,
|
|
2109
2118
|
latencyMs: latencyMs2
|
|
2110
2119
|
});
|
|
2111
|
-
if (
|
|
2120
|
+
if (storeResponsePayloads) {
|
|
2112
2121
|
await upsertLogPayload(logId, {
|
|
2113
2122
|
response: (() => {
|
|
2114
2123
|
try {
|
|
@@ -2154,7 +2163,7 @@ async function registerMessagesRoute(app) {
|
|
|
2154
2163
|
outputTokens,
|
|
2155
2164
|
latencyMs
|
|
2156
2165
|
});
|
|
2157
|
-
if (
|
|
2166
|
+
if (storeResponsePayloads) {
|
|
2158
2167
|
await upsertLogPayload(logId, {
|
|
2159
2168
|
response: (() => {
|
|
2160
2169
|
try {
|
|
@@ -2275,7 +2284,7 @@ async function registerMessagesRoute(app) {
|
|
|
2275
2284
|
outputTokens: usageCompletion2,
|
|
2276
2285
|
latencyMs: totalLatencyMs
|
|
2277
2286
|
});
|
|
2278
|
-
if (
|
|
2287
|
+
if (storeResponsePayloads) {
|
|
2279
2288
|
await upsertLogPayload(logId, {
|
|
2280
2289
|
response: (() => {
|
|
2281
2290
|
try {
|
|
@@ -2400,7 +2409,7 @@ data: ${JSON.stringify(data)}
|
|
|
2400
2409
|
outputTokens: finalCompletionTokens,
|
|
2401
2410
|
latencyMs: totalLatencyMs
|
|
2402
2411
|
});
|
|
2403
|
-
if (
|
|
2412
|
+
if (storeResponsePayloads) {
|
|
2404
2413
|
await upsertLogPayload(logId, {
|
|
2405
2414
|
response: (() => {
|
|
2406
2415
|
try {
|
|
@@ -2558,7 +2567,7 @@ data: ${JSON.stringify(data)}
|
|
|
2558
2567
|
outputTokens: fallbackCompletion,
|
|
2559
2568
|
latencyMs: totalLatencyMs
|
|
2560
2569
|
});
|
|
2561
|
-
if (
|
|
2570
|
+
if (storeResponsePayloads) {
|
|
2562
2571
|
await upsertLogPayload(logId, {
|
|
2563
2572
|
response: (() => {
|
|
2564
2573
|
try {
|
|
@@ -2868,7 +2877,9 @@ async function registerOpenAiRoutes(app) {
|
|
|
2868
2877
|
connector = getConnector(target.providerId);
|
|
2869
2878
|
}
|
|
2870
2879
|
const requestStart = Date.now();
|
|
2871
|
-
const
|
|
2880
|
+
const configSnapshot = getConfig();
|
|
2881
|
+
const storeRequestPayloads = configSnapshot.storeRequestPayloads !== false;
|
|
2882
|
+
const storeResponsePayloads = configSnapshot.storeResponsePayloads !== false;
|
|
2872
2883
|
const logId = await recordLog({
|
|
2873
2884
|
timestamp: requestStart,
|
|
2874
2885
|
endpoint: "openai",
|
|
@@ -2881,7 +2892,7 @@ async function registerOpenAiRoutes(app) {
|
|
|
2881
2892
|
apiKeyName: apiKeyContext.name,
|
|
2882
2893
|
apiKeyValue: encryptedApiKeyValue
|
|
2883
2894
|
});
|
|
2884
|
-
if (
|
|
2895
|
+
if (storeRequestPayloads) {
|
|
2885
2896
|
await upsertLogPayload(logId, {
|
|
2886
2897
|
prompt: (() => {
|
|
2887
2898
|
try {
|
|
@@ -2938,7 +2949,7 @@ async function registerOpenAiRoutes(app) {
|
|
|
2938
2949
|
const bodyText = upstream.body ? await new Response(upstream.body).text() : "";
|
|
2939
2950
|
const errorText = bodyText || "Upstream provider error";
|
|
2940
2951
|
debugLog("upstream error", upstream.status, errorText.slice(0, 200));
|
|
2941
|
-
if (
|
|
2952
|
+
if (storeResponsePayloads) {
|
|
2942
2953
|
await upsertLogPayload(logId, { response: bodyText || null });
|
|
2943
2954
|
}
|
|
2944
2955
|
await commitUsage(0, 0);
|
|
@@ -2947,7 +2958,7 @@ async function registerOpenAiRoutes(app) {
|
|
|
2947
2958
|
}
|
|
2948
2959
|
if (!normalized.stream) {
|
|
2949
2960
|
const rawBody = upstream.body ? await new Response(upstream.body).text() : "";
|
|
2950
|
-
if (
|
|
2961
|
+
if (storeResponsePayloads) {
|
|
2951
2962
|
await upsertLogPayload(logId, { response: rawBody });
|
|
2952
2963
|
}
|
|
2953
2964
|
let parsed = null;
|
|
@@ -3019,7 +3030,7 @@ async function registerOpenAiRoutes(app) {
|
|
|
3019
3030
|
let usageCached = null;
|
|
3020
3031
|
let firstTokenAt = null;
|
|
3021
3032
|
let chunkCount = 0;
|
|
3022
|
-
const capturedResponseChunks =
|
|
3033
|
+
const capturedResponseChunks = storeResponsePayloads ? [] : null;
|
|
3023
3034
|
const replyClosed = () => {
|
|
3024
3035
|
debugLog("client connection closed before completion");
|
|
3025
3036
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{c as p,u as v,a as k,r,j as e,b as o,D as j,m as i}from"./index-COB9rriK.js";import{u as N}from"./useApiQuery-mnvEnqVq.js";import{P as w,a as d}from"./PageSection-Dndgc9r9.js";import"./Input-BOaaGybK.js";import{B as b}from"./Button-DIJdkdyt.js";import{I as y}from"./info-DNl8lKHj.js";/**
|
|
2
|
+
* @license lucide-react v0.344.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const T=p("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
|
7
|
+
* @license lucide-react v0.344.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const L=p("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"}]]),E="0.3.7",I={version:E},M={};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 B(){const{t}=v(),{pushToast:s}=k(),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=I.version,l=r.useMemo(()=>{const u=M,f=u.VITE_BUILD_TIME??"-",g=u.VITE_NODE_VERSION??"-";return{buildTime:f,nodeVersion:g}},[]),h=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-local-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(y,{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(L,{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:h})}),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(T,{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(j,{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{B as default};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{c as T,u as W,a as J,r as d,j as e,L as X,K as Y,b as t,m as r,q as m,t as Z,i as ee,l as ae,e as se,f as te}from"./index-COB9rriK.js";import{E as le}from"./index-mV9BV7rj.js";import{u as K,a as w}from"./useApiQuery-mnvEnqVq.js";import{P as ie,a as q}from"./PageSection-Dndgc9r9.js";import{F as I}from"./FormField-JMg-tjrG.js";import{I as re}from"./Input-BOaaGybK.js";import{B as C}from"./Button-DIJdkdyt.js";import{S as ne}from"./StatusBadge-DOVCfoYm.js";import{C as ce}from"./copy-CG_L9fTW.js";/**
|
|
2
|
+
* @license lucide-react v0.344.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const de=T("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
|
|
7
|
+
* @license lucide-react v0.344.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const oe=T("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
|
|
12
|
+
* @license lucide-react v0.344.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const pe=T("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]),me=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function ke(){const{t:a}=W(),{pushToast:i}=J(),[v,x]=d.useState(!1),[u,y]=d.useState(""),[D,k]=d.useState(""),[h,L]=d.useState(null),[F,A]=d.useState(null),[o,z]=d.useState(7),g=K(["api-keys"],{url:"/api/keys",method:"GET"}),j=K(["api-keys","overview",o],{url:"/api/stats/api-keys/overview",method:"GET",params:{days:o}}),f=K(["api-keys","usage",o],{url:"/api/stats/api-keys/usage",method:"GET",params:{days:o,limit:10}}),N=g.data??[],p=j.data,c=f.data??[],B=N.some(s=>s.isWildcard),R=p?p.totalKeys.toLocaleString():"–",V=p?p.enabledKeys.toLocaleString():"–",G=p?p.activeKeys.toLocaleString():"–",E=async()=>{var s,l;if(!u.trim()){i({title:a("apiKeys.errors.nameRequired"),variant:"error"});return}try{const n=await w.post("/api/keys",{name:u.trim(),description:D.trim()||void 0});L(n.data),x(!1),y(""),k(""),g.refetch(),j.refetch(),f.refetch(),i({title:a("apiKeys.toast.keyCreated"),variant:"success"})}catch(n){i({title:a("apiKeys.toast.createFailure",{message:((l=(s=n.response)==null?void 0:s.data)==null?void 0:l.error)||n.message}),variant:"error"})}},H=async(s,l)=>{var n,b;try{await w.patch(`/api/keys/${s}`,{enabled:!l}),g.refetch(),j.refetch(),i({title:a("apiKeys.toast.keyUpdated"),variant:"success"})}catch(P){i({title:a("apiKeys.toast.updateFailure",{message:((b=(n=P.response)==null?void 0:n.data)==null?void 0:b.error)||P.message}),variant:"error"})}},Q=async s=>{var l,n;if(confirm(a("apiKeys.confirmDelete"))){A(s);try{await w.delete(`/api/keys/${s}`),g.refetch(),j.refetch(),f.refetch(),i({title:a("apiKeys.toast.keyDeleted"),variant:"success"})}catch(b){i({title:a("apiKeys.toast.deleteFailure",{message:((n=(l=b.response)==null?void 0:l.data)==null?void 0:n.error)||b.message}),variant:"error"})}finally{A(null)}}},U=s=>{navigator.clipboard.writeText(s),i({title:a("apiKeys.toast.keyCopied"),variant:"success"})},M=s=>s?new Date(s).toLocaleString():a("common.noData"),$=d.useMemo(()=>{const s=c.map(l=>l.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.requestsSeries"),type:"bar",data:c.map(l=>l.requests),itemStyle:{color:"#2563eb"}}]}},[c,a]),_=d.useMemo(()=>{const s=c.map(l=>l.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[a("apiKeys.analytics.tokens.input"),a("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:c.map(l=>l.inputTokens)},{name:a("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:c.map(l=>l.outputTokens)}]}},[c,a]);return g.isLoading?e.jsx(X,{}):e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ie,{icon:e.jsx(Y,{className:"h-6 w-6","aria-hidden":"true"}),title:a("apiKeys.title"),description:a("apiKeys.description"),actions:e.jsx(C,{onClick:()=>x(!0),variant:"primary",size:"lg",icon:e.jsx(oe,{className:"h-4 w-4","aria-hidden":"true"}),className:"rounded-full",children:a("apiKeys.createNew")})}),e.jsxs(q,{title:a("apiKeys.analytics.title"),description:a("apiKeys.analytics.description",{days:o}),actions:e.jsx("div",{className:"flex items-center gap-2 rounded-full bg-white/70 px-2 py-1 shadow-sm shadow-slate-200/60 ring-1 ring-slate-200/60 backdrop-blur dark:bg-slate-900/70 dark:ring-slate-700/60",children:me.map(s=>{const l=o===s.value;return e.jsx("button",{type:"button",onClick:()=>z(s.value),className:t("inline-flex h-8 items-center rounded-full px-3 text-xs font-semibold transition",l?"bg-blue-600 text-white shadow-sm shadow-blue-500/20":"text-slate-600 hover:bg-white/80 dark:text-slate-300 dark:hover:bg-slate-800/60"),children:a(s.labelKey)},s.value)})}),contentClassName:"gap-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(S,{label:a("apiKeys.analytics.cards.total"),value:R}),e.jsx(S,{label:a("apiKeys.analytics.cards.enabled"),value:V}),e.jsx(S,{label:a("apiKeys.analytics.cards.active",{days:o}),value:G})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(O,{title:a("apiKeys.analytics.charts.requests"),loading:f.isLoading,empty:c.length===0,emptyText:a("apiKeys.analytics.empty"),option:$}),e.jsx(O,{title:a("apiKeys.analytics.charts.tokens"),loading:f.isLoading,empty:c.length===0,emptyText:a("apiKeys.analytics.empty"),option:_})]})]}),e.jsx(q,{title:a("apiKeys.list.title"),description:B?a("apiKeys.wildcardHint"):void 0,contentClassName:"gap-4",children:N.length===0?e.jsx("div",{className:t(m,"p-6 text-center"),children:e.jsx("p",{className:t(r,"text-sm"),children:a("apiKeys.list.empty")})}):e.jsx("div",{className:"grid gap-4",children:N.map(s=>{const l=(s.totalInputTokens+s.totalOutputTokens).toLocaleString();return e.jsx("div",{className:t(m,"space-y-4"),children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-50",children:s.name}),s.isWildcard?e.jsx("span",{className:"inline-flex items-center rounded-full bg-purple-500/10 px-3 py-1 text-xs font-semibold text-purple-600 dark:bg-purple-500/20 dark:text-purple-200",children:a("apiKeys.wildcard")}):null,e.jsx(ne,{variant:s.enabled?"success":"info",children:s.enabled?a("apiKeys.status.enabled"):a("apiKeys.status.disabled")})]}),e.jsx("code",{className:"inline-flex items-center rounded-2xl bg-slate-900/90 px-4 py-2 font-mono text-sm text-slate-50 shadow-inner shadow-slate-900/30 dark:bg-slate-800/80",children:s.isWildcard?a("apiKeys.wildcard"):s.maskedKey??"********"}),s.isWildcard?e.jsx("p",{className:t(r,"text-sm text-purple-600 dark:text-purple-200"),children:a("apiKeys.wildcardHint")}):s.description?e.jsx("p",{className:t(r,"whitespace-pre-wrap text-sm"),children:s.description}):null,e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.created")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:M(s.createdAt)})]}),e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.lastUsed")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:M(s.lastUsedAt)})]}),e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.requestCount")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:s.requestCount.toLocaleString()})]}),e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.totalTokens")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:l})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>H(s.id,s.enabled),className:t("inline-flex h-9 items-center rounded-full px-4 text-sm font-semibold transition",s.enabled?"bg-slate-200/80 text-slate-700 hover:bg-slate-300 dark:bg-slate-800/80 dark:text-slate-200 dark:hover:bg-slate-700/70":"bg-emerald-500 text-white shadow-sm shadow-emerald-500/30 hover:bg-emerald-500/90"),children:s.enabled?a("apiKeys.actions.disable"):a("apiKeys.actions.enable")}),s.isWildcard?null:e.jsx("button",{type:"button",onClick:()=>Q(s.id),disabled:F===s.id,className:"inline-flex h-9 w-9 items-center justify-center rounded-full text-red-500 transition hover:bg-red-500/10 disabled:opacity-50","aria-label":a("apiKeys.actions.delete"),children:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"})})]})]})},s.id)})})}),v&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-slate-950/60 p-4 backdrop-blur-sm",children:e.jsxs("div",{className:t(m,"w-full max-w-md space-y-5 p-6 shadow-xl shadow-slate-900/30 dark:shadow-black/40"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:a("apiKeys.createNew")}),e.jsx("p",{className:t(r,"text-sm"),children:a("apiKeys.createDescription")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(I,{label:a("apiKeys.keyNamePlaceholder"),required:!0,children:e.jsx(re,{value:u,onChange:s=>y(s.target.value),placeholder:a("apiKeys.keyNamePlaceholder"),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),E())}})}),e.jsx(I,{label:a("apiKeys.descriptionLabel"),children:e.jsx("textarea",{value:D,onChange:s=>k(s.target.value),placeholder:a("apiKeys.keyDescriptionPlaceholder"),className:"w-full rounded-2xl border border-slate-200/50 bg-white/90 px-4 py-3 text-sm text-slate-800 shadow-sm shadow-slate-200/30 transition-all duration-200 focus:border-blue-400/70 focus:bg-white focus:outline-none focus:ring-2 focus:ring-blue-400/20 focus:shadow-md focus:shadow-blue-200/40 dark:border-slate-700/50 dark:bg-slate-900/90 dark:text-slate-200 dark:shadow-lg dark:shadow-slate-900/30 dark:focus:border-blue-400/70 dark:focus:ring-blue-400/20 min-h-[96px] resize-none"})})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{onClick:()=>{x(!1),y(""),k("")},variant:"subtle",className:"rounded-full",children:a("common.actions.cancel")}),e.jsx(C,{onClick:()=>void E(),variant:"primary",className:"rounded-full",children:a("apiKeys.createAction")})]})]})}),h&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-slate-950/60 p-4 backdrop-blur-sm",children:e.jsxs("div",{className:t(m,"w-full max-w-md space-y-5 p-6 shadow-xl shadow-slate-900/30 dark:shadow-black/40"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"grid h-10 w-10 place-items-center rounded-full bg-emerald-500/20 text-emerald-600 dark:bg-emerald-500/30 dark:text-emerald-200",children:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("h2",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:a("apiKeys.keyCreated")})]}),e.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:a("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-2xl bg-slate-900/95 px-4 py-3 font-mono text-sm text-slate-50 shadow-inner shadow-slate-900/40 dark:bg-slate-800/90",children:h.key}),h.description?e.jsx("p",{className:t(r,"whitespace-pre-wrap text-sm"),children:h.description}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>U(h.key),className:t(Z,"h-10 rounded-full px-4"),children:[e.jsx(ce,{className:"h-4 w-4","aria-hidden":"true"}),a("common.actions.copy")]}),e.jsx("button",{type:"button",onClick:()=>L(null),className:t(ee,"h-10 rounded-full px-4"),children:a("common.actions.close")})]})]})})]})}function S({label:a,value:i}){return e.jsxs("div",{className:t(m,"p-6"),children:[e.jsx("p",{className:t(r,"text-xs font-semibold uppercase tracking-[0.18em]"),children:a}),e.jsx("p",{className:"mt-3 text-3xl font-semibold text-slate-900 dark:text-slate-50",children:i})]})}function O({title:a,option:i,loading:v,empty:x,emptyText:u}){const{t:y}=W();return e.jsxs("div",{className:t(m,"space-y-4 p-6"),children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-50",children:a}),v?e.jsx("div",{className:ae,children:e.jsx("span",{className:t(r,"text-sm"),children:y("common.loadingShort")})}):x?e.jsx("div",{className:se,children:e.jsx("span",{className:t(r,"text-sm"),children:u})}):e.jsx(le,{option:i,style:{height:280},notMerge:!0,lazyUpdate:!0,className:te})]})}export{ke as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as s,b as x,w as c,t as b,i as p}from"./index-COB9rriK.js";function h({variant:n="subtle",size:o="md",children:a,loading:t,icon:e,className:l,disabled:r,...u}){const i={subtle:p,primary:b,danger:c}[n],m={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:x(i,m,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};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{c as q,u as C,a as U,r as u,j as e,L as _,B as M,b as d,m as y,g as $,l as I,d as H,e as P,f as K,s as V,h as E}from"./index-COB9rriK.js";import{E as J}from"./index-mV9BV7rj.js";import{P as W,a as B}from"./PageSection-Dndgc9r9.js";import{S as X}from"./Input-BOaaGybK.js";import{S as Y}from"./StatusBadge-DOVCfoYm.js";import{u as k}from"./useApiQuery-mnvEnqVq.js";/**
|
|
2
|
+
* @license lucide-react v0.344.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Z=q("Activity",[["path",{d:"M22 12h-4l-3 9L9 3l-3 9H2",key:"d5dnw9"}]]);/**
|
|
7
|
+
* @license lucide-react v0.344.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const ee=q("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
|
|
12
|
+
* @license lucide-react v0.344.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const te=q("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);function S(t,r,s){return t==null?"-":`${t.toLocaleString(void 0,s)} ${r}`}function se(t){if(t==null)return"-";if(t<1024)return`${t} B`;const r=["KB","MB","GB","TB"];let s=t/1024,a=0;for(;s>=1024&&a<r.length-1;)s/=1024,a+=1;return`${s.toFixed(s>=100?0:s>=10?1:2)} ${r[a]}`}function me(){var D;const{t}=C(),{pushToast:r}=U(),[s,a]=u.useState("all"),l=s==="all"?void 0:s,p=k(["stats","overview",s],{url:"/api/stats/overview",method:"GET",params:l?{endpoint:l}:void 0}),b=k(["stats","daily",14,s],{url:"/api/stats/daily",method:"GET",params:{days:14,...l?{endpoint:l}:{}}}),g=k(["stats","model",7,6,s],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...l?{endpoint:l}:{}}}),f=k(["status"],{url:"/api/status",method:"GET"}),j=k(["db","info"],{url:"/api/db/info",method:"GET"}),v=k(["logs","recent",s],{url:"/api/logs",method:"GET",params:{limit:5,...l?{endpoint:l}:{}}},{refetchInterval:3e4});u.useEffect(()=>{p.isError&&p.error&&r({title:t("dashboard.toast.overviewError"),description:p.error.message,variant:"error"})},[p.isError,p.error,r,t]),u.useEffect(()=>{b.isError&&b.error&&r({title:t("dashboard.toast.dailyError"),description:b.error.message,variant:"error"})},[b.isError,b.error,r,t]),u.useEffect(()=>{g.isError&&g.error&&r({title:t("dashboard.toast.modelError"),description:g.error.message,variant:"error"})},[g.isError,g.error,r,t]),u.useEffect(()=>{f.isError&&f.error&&r({title:t("dashboard.toast.statusError"),description:f.error.message,variant:"error"})},[f.isError,f.error,r,t]),u.useEffect(()=>{j.isError&&j.error&&r({title:t("dashboard.toast.dbError"),description:j.error.message,variant:"error"})},[j.isError,j.error,r,t]),u.useEffect(()=>{v.isError&&v.error&&r({title:t("dashboard.toast.recentError"),description:v.error.message,variant:"error"})},[v.isError,v.error,r,t]);const m=p.data,N=b.data??[],n=g.data??[],T=f.data,R=j.data,O=((D=v.data)==null?void 0:D.items)??[],G=u.useMemo(()=>{const c=N.map(i=>i.date),x=t("dashboard.charts.barRequests"),o=t("dashboard.charts.lineInput"),h=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"}},legend:{data:[x,o,h],textStyle:{color:"#64748b"}},grid:{left:60,right:40,top:60,bottom:60},xAxis:{type:"category",data:c,axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:N.map(i=>i.requestCount),itemStyle:{color:"#3b82f6",borderRadius:[4,4,0,0]},emphasis:{itemStyle:{color:"#2563eb"}}},{name:o,type:"line",yAxisIndex:0,data:N.map(i=>i.inputTokens),smooth:!0,itemStyle:{color:"#10b981"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:h,type:"line",yAxisIndex:0,data:N.map(i=>i.outputTokens),smooth:!0,itemStyle:{color:"#f59e0b"},lineStyle:{width:3},symbol:"circle",symbolSize:6}]}},[N,t]),Q=u.useMemo(()=>{const c=n.map(i=>`${i.provider}/${i.model}`),x=t("dashboard.charts.barRequests"),o=t("dashboard.charts.lineInput"),h=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"}},legend:{data:[x,o,h],textStyle:{color:"#64748b"}},grid:{left:80,right:60,top:60,bottom:100},xAxis:{type:"category",data:c,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:[{type:"value",name:x,axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},{type:"value",name:t("dashboard.charts.axisTokens"),position:"right",axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}}],series:[{name:x,type:"bar",data:n.map(i=>i.requests),itemStyle:{color:"#6366f1",borderRadius:[4,4,0,0]},yAxisIndex:0},{name:o,type:"line",yAxisIndex:1,smooth:!0,data:n.map(i=>i.inputTokens??0),itemStyle:{color:"#10b981"},lineStyle:{width:3}},{name:h,type:"line",yAxisIndex:1,smooth:!0,data:n.map(i=>i.outputTokens??0),itemStyle:{color:"#f59e0b"},lineStyle:{width:3}}]}},[n,t]),F=u.useMemo(()=>{const c=n.map(o=>`${o.provider}/${o.model}`),x=t("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"},formatter(o){var L;if(!Array.isArray(o)||o.length===0)return"";const h=((L=o[0])==null?void 0:L.dataIndex)??0,i=n[h];return i?`<strong>${c[h]}</strong><br/>${x}: ${S(i.avgTtftMs,t("common.units.ms"))}`:""}},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:c,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",name:t("dashboard.charts.ttftAxis"),axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:n.map(o=>o.avgTtftMs??0),itemStyle:{color:"#3b82f6",borderRadius:[4,4,0,0]}}]}},[n,t]),z=u.useMemo(()=>{const c=n.map(o=>`${o.provider}/${o.model}`),x=t("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"},formatter(o){var L;if(!Array.isArray(o)||o.length===0)return"";const h=((L=o[0])==null?void 0:L.dataIndex)??0,i=n[h];return i?`<strong>${c[h]}</strong><br/>${x}: ${S(i.avgTpotMs,t("common.units.msPerToken"),{maximumFractionDigits:2})}`:""}},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:c,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",name:t("dashboard.charts.tpotAxis"),axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:n.map(o=>o.avgTpotMs??0),itemStyle:{color:"#f59e0b",borderRadius:[4,4,0,0]}}]}},[n,t]);return p.isPending||f.isPending||j.isPending?e.jsx(_,{}):e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(W,{icon:e.jsx(M,{className:"h-7 w-7","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description"),actions:e.jsxs("div",{className:"flex items-center gap-4 rounded-2xl bg-white/90 px-4 py-3 shadow-lg shadow-slate-200/30 ring-1 ring-slate-200/40 backdrop-blur-lg dark:bg-slate-900/90 dark:shadow-xl dark:shadow-slate-900/30 dark:ring-slate-700/40",children:[e.jsx("label",{htmlFor:"dashboard-endpoint-filter",className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:t("dashboard.filters.endpoint")}),e.jsx("div",{className:"relative",children:e.jsx(X,{id:"dashboard-endpoint-filter",value:s,onChange:c=>a(c.target.value),options:[{value:"all",label:t("dashboard.filters.endpointAll")},{value:"anthropic",label:t("dashboard.filters.endpointAnthropic")},{value:"openai",label:t("dashboard.filters.endpointOpenAI")}]})})]})}),T?e.jsxs("section",{className:d($,"flex flex-wrap items-center gap-4 text-sm leading-relaxed animate-slide-up"),"aria-live":"polite",children:[e.jsxs("span",{className:d(V.success,"inline-flex items-center gap-2 rounded-full px-4 py-2 font-semibold"),children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-current shadow-lg","aria-hidden":"true"}),t("dashboard.status.listening",{host:T.host??"0.0.0.0",port:T.port})]}),e.jsx("span",{className:d(E.default,"font-semibold"),children:t("dashboard.status.providers",{value:T.providers.toLocaleString()})}),e.jsx("span",{className:d(E.primary,"font-semibold"),children:t("dashboard.status.todayRequests",{value:((m==null?void 0:m.today.requests)??0).toLocaleString()})}),e.jsx("span",{className:d(E.default,"font-semibold"),children:t("dashboard.status.active",{value:(T.activeRequests??0).toLocaleString()})}),e.jsx("span",{className:d(E.default,"font-semibold"),children:t("dashboard.status.dbSize",{value:R?se(R.sizeBytes):"-"})})]}):null,e.jsxs("section",{className:"grid gap-6 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(w,{icon:e.jsx(Z,{className:"h-5 w-5"}),title:t("dashboard.cards.todayRequests"),value:(m==null?void 0:m.today.requests)??0,suffix:t("common.units.request"),trend:"+12%",trendDirection:"up"}),e.jsx(w,{icon:e.jsx(te,{className:"h-5 w-5"}),title:t("dashboard.cards.todayInput"),value:(m==null?void 0:m.today.inputTokens)??0,suffix:t("common.units.token"),trend:"+8%",trendDirection:"up"}),e.jsx(w,{icon:e.jsx(M,{className:"h-5 w-5"}),title:t("dashboard.cards.todayOutput"),value:(m==null?void 0:m.today.outputTokens)??0,suffix:t("common.units.token"),trend:"+15%",trendDirection:"up"}),e.jsx(w,{icon:e.jsx(ee,{className:"h-5 w-5"}),title:t("dashboard.cards.avgLatency"),value:(m==null?void 0:m.today.avgLatencyMs)??0,suffix:t("common.units.ms"),trend:"-5%",trendDirection:"down"})]}),e.jsxs("div",{className:"grid gap-8 xl:grid-cols-2",children:[e.jsx(A,{title:t("dashboard.charts.requestsTitle"),description:t("dashboard.charts.requestsDesc"),loading:b.isPending,option:G,empty:!N.length,emptyText:t("dashboard.charts.empty")}),e.jsx(A,{title:t("dashboard.charts.modelTitle"),description:t("dashboard.charts.modelDesc"),loading:g.isPending,option:Q,empty:!n.length,emptyText:t("dashboard.charts.empty")})]}),e.jsxs("div",{className:"grid gap-8 xl:grid-cols-2",children:[e.jsx(A,{title:t("dashboard.charts.ttftTitle"),description:t("dashboard.charts.ttftDesc"),loading:g.isPending,option:F,empty:!n.some(c=>c.avgTtftMs!=null&&c.avgTtftMs>0),emptyText:t("dashboard.charts.ttftEmpty")}),e.jsx(A,{title:t("dashboard.charts.tpotTitle"),description:t("dashboard.charts.tpotDesc"),loading:g.isPending,option:z,empty:!n.some(c=>c.avgTpotMs!=null&&c.avgTpotMs>0),emptyText:t("dashboard.charts.tpotEmpty")})]}),e.jsx(ae,{models:n,loading:g.isPending}),e.jsx(re,{loading:v.isPending,records:O})]})}function w({icon:t,title:r,value:s,suffix:a,trend:l,trendDirection:p}){return e.jsxs("div",{className:d($,"group hover-lift animate-slide-up"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("div",{className:d(y,"text-xs font-bold uppercase tracking-[0.15em]"),children:r}),t&&e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-xl bg-gradient-to-br from-blue-600/15 to-indigo-600/10 text-blue-600 ring-1 ring-blue-500/20 dark:from-blue-500/25 dark:to-indigo-500/15 dark:text-blue-200 dark:ring-blue-400/20",children:t})]}),e.jsx("div",{className:"flex items-end justify-between",children:e.jsxs("div",{children:[e.jsxs("p",{className:"text-3xl font-bold text-slate-900 dark:text-slate-50",children:[s.toLocaleString(),a?e.jsx("span",{className:d(y,"ml-2 text-lg font-medium"),children:a}):null]}),l&&e.jsxs("div",{className:d("mt-2 flex items-center gap-1 text-xs font-semibold",p==="up"?"text-emerald-600 dark:text-emerald-400":"text-red-600 dark:text-red-400"),children:[e.jsx("span",{children:l}),e.jsx("span",{className:"text-slate-500",children:"vs last period"})]})]})})]})}function A({title:t,description:r,option:s,loading:a,empty:l,emptyText:p}){const{t:b}=C();return e.jsxs("div",{className:d($,"space-y-6 hover-lift animate-slide-up"),children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xl font-bold text-slate-900 dark:text-slate-50",children:t}),e.jsx("p",{className:d(y,"mt-2 text-sm leading-relaxed"),children:r})]}),a?e.jsx("div",{className:I,children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:H}),e.jsx("span",{className:d(y,"text-sm mt-4 block"),children:b("common.loadingShort")})]})}):l?e.jsx("div",{className:P,children:e.jsxs("div",{className:"text-center",children:[e.jsx(M,{className:"mx-auto h-12 w-12 text-slate-300 dark:text-slate-600 mb-4"}),e.jsx("span",{className:d(y,"text-sm"),children:p??b("dashboard.charts.empty")})]})}):e.jsx(J,{option:s,style:{height:320},notMerge:!0,lazyUpdate:!0,theme:void 0,className:K})]})}function ae({models:t,loading:r}){const{t:s}=C(),a=t.length>0;return e.jsx(B,{title:e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-50",children:s("dashboard.modelTable.title")}),description:s("dashboard.modelTable.description"),contentClassName:"gap-0 overflow-hidden p-0",children:r?e.jsx("div",{className:I,children:e.jsx("span",{className:d(y,"text-sm"),children:s("common.loadingShort")})}):a?e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:s("dashboard.modelTable.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.modelTable.columns.model")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.requests")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.ttft")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.tpot")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 text-sm dark:divide-slate-800/60",children:t.map(l=>e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-semibold text-slate-800 dark:text-slate-50",children:l.provider}),e.jsx("span",{className:d(y,"text-xs"),children:l.model})]})}),e.jsx("td",{className:"px-5 py-3 text-right font-medium text-slate-800 dark:text-slate-50",children:l.requests.toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right",children:S(l.avgLatencyMs,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right",children:S(l.avgTtftMs,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right",children:S(l.avgTpotMs,s("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${l.provider}/${l.model}`))})]})}):e.jsx("div",{className:P,children:e.jsx("span",{className:d(y,"text-sm"),children:s("dashboard.modelTable.empty")})})})}function re({records:t,loading:r}){const{t:s}=C();return e.jsx(B,{title:e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-50",children:s("dashboard.recent.title")}),description:s("dashboard.recent.subtitle",{count:5}),contentClassName:"gap-0 overflow-hidden p-0",children:r?e.jsx("div",{className:I,children:e.jsx("span",{className:d(y,"text-sm"),children:s("dashboard.recent.loading")})}):t.length===0?e.jsx("div",{className:P,children:e.jsx("span",{className:d(y,"text-sm"),children:s("dashboard.recent.empty")})}):e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:s("dashboard.recent.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.time")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.endpoint")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.provider")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.route")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.recent.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold",children:s("dashboard.recent.columns.status")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 dark:divide-slate-800/60",children:t.map(a=>e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:"px-5 py-3 text-xs font-medium text-slate-600 dark:text-slate-300",children:new Date(a.timestamp).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-xs text-slate-500 dark:text-slate-400",children:a.endpoint==="anthropic"?s("logs.table.endpointAnthropic"):a.endpoint==="openai"?s("logs.table.endpointOpenAI"):a.endpoint}),e.jsx("td",{className:"px-5 py-3 text-sm font-medium text-slate-800 dark:text-slate-50",children:a.provider}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:a.client_model??s("dashboard.recent.routePlaceholder")}),e.jsx("span",{"aria-hidden":"true",className:"text-slate-400",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-700 dark:text-slate-100",children:a.model})]})}),e.jsx("td",{className:"px-5 py-3 text-right text-sm font-medium text-slate-800 dark:text-slate-100",children:S(a.latency_ms,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs(Y,{variant:a.error?"error":"success",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-current","aria-hidden":"true"}),(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})})]},a.id))})]})})})}export{me as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as s,b as m,A as x,C as d}from"./index-COB9rriK.js";function i({label:a,children:l,className:t,required:r,error:e}){return s.jsxs("div",{className:m(d,t),children:[s.jsxs("label",{className:x,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};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c,u as h,r as u,j as e,b as l,m as o}from"./index-COB9rriK.js";import{P as m,a as d}from"./PageSection-Dndgc9r9.js";import{I as p}from"./info-DNl8lKHj.js";/**
|
|
2
|
+
* @license lucide-react v0.344.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const b=c("BookOpen",[["path",{d:"M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z",key:"vv98re"}],["path",{d:"M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z",key:"1cyq3y"}]]);function k(){const{t:s}=h(),t=u.useMemo(()=>{const a=s("help.sections.configuration.items",{returnObjects:!0}),i=s("help.sections.usage.items",{returnObjects:!0}),n=s("help.sections.tips.items",{returnObjects:!0});return[{title:s("help.sections.configuration.title"),items:a},{title:s("help.sections.usage.title"),items:i},{title:s("help.sections.tips.title"),items:n}]},[s]),r=s("help.faq.items",{returnObjects:!0});return e.jsxs("div",{className:"space-y-8",children:[e.jsx(m,{icon:e.jsx(b,{className:"h-6 w-6","aria-hidden":"true"}),title:s("help.title"),description:s("help.intro")}),e.jsx("div",{className:"rounded-3xl border border-blue-200/40 bg-gradient-to-br from-blue-50/90 via-white/90 to-purple-50/80 p-6 shadow-lg shadow-blue-100/40 backdrop-blur-sm dark:border-blue-900/30 dark:from-blue-900/40 dark:via-slate-900/70 dark:to-indigo-900/30 dark:shadow-indigo-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-blue-500/10 text-blue-600 dark:bg-blue-500/20 dark:text-blue-200",children:e.jsx(p,{className:"h-6 w-6","aria-hidden":"true"})}),e.jsx("p",{className:l(o,"text-sm leading-6"),children:s("help.note")})]})}),e.jsx("div",{className:"grid gap-6 lg:grid-cols-2",children:t.map(a=>e.jsx(d,{title:a.title,className:"h-full",contentClassName:"gap-4",children:e.jsx(x,{items:a.items})},a.title))}),e.jsx(d,{title:s("help.faq.title"),contentClassName:"gap-4",children:e.jsx(g,{items:r})})]})}function x({items:s}){return e.jsx("ol",{className:"flex flex-col gap-4",children:s.map((t,r)=>e.jsxs("li",{className:"group flex gap-4 rounded-3xl border border-slate-200/60 bg-white p-4 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-blue-200/60 hover:shadow-md hover:shadow-blue-200/40 dark:border-slate-700/60 dark:bg-slate-900/80 dark:shadow-slate-900/40 dark:hover:border-blue-500/40",children:[e.jsx("span",{className:"flex h-9 w-9 items-center justify-center rounded-2xl bg-gradient-to-br from-blue-500 to-indigo-500 text-sm font-semibold text-white shadow-lg shadow-blue-500/30 dark:from-blue-400 dark:to-indigo-400",children:r+1}),e.jsx("p",{className:l(o,"text-sm leading-6"),children:t})]},`${r}-${t}`))})}function g({items:s}){return s.length===0?null:e.jsx("dl",{className:"flex flex-col gap-4",children:s.map(t=>e.jsxs("div",{className:"rounded-3xl border border-slate-200/60 bg-white p-5 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-blue-200/60 hover:shadow-md hover:shadow-blue-200/40 dark:border-slate-700/60 dark:bg-slate-900/80 dark:shadow-slate-900/40 dark:hover:border-blue-500/40",children:[e.jsx("dt",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:t.q}),e.jsx("dd",{className:l(o,"mt-2 text-sm leading-6"),children:t.a})]},t.q))})}export{k as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as n,j as e,b as u,y as d,x as i}from"./index-COB9rriK.js";const f=n.forwardRef(({options:t,placeholder:s,className:r,...l},c)=>e.jsxs("select",{ref:c,className:u(d,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=n.forwardRef(({variant:t="default",className:s,...r},l)=>e.jsx("input",{ref:l,className:u(i,s),...r}));export{j as I,f as S};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as P,a as ae,r as d,j as e,b as N,i as V,F as xe,p as me,m as D,k as pe,n as ue,L as he}from"./index-COB9rriK.js";import{u as F}from"./useApiQuery-mnvEnqVq.js";import{P as ge,a as X}from"./PageSection-Dndgc9r9.js";import{F as T}from"./FormField-JMg-tjrG.js";import{S as M,I as q}from"./Input-BOaaGybK.js";import{B as O}from"./Button-DIJdkdyt.js";import{S as le}from"./StatusBadge-DOVCfoYm.js";const ee=[20,50,100];function te(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 re(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 _(t){return t==null?"-":t.toLocaleString()}function v(t,r){const n=_(t);return n==="-"?"-":`${n} ${r}`}function B(t){return t?"true":"false"}function se(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 Ee(){var J,Y;const{t}=P(),{pushToast:r}=ae(),[n,b]=d.useState("all"),[x,s]=d.useState("all"),[c,j]=d.useState(""),[g,h]=d.useState("all"),[p,a]=d.useState(""),[o,i]=d.useState(""),[m,w]=d.useState(1),[u,S]=d.useState(ee[0]),[K,C]=d.useState(null),[ie,I]=d.useState(!1),[L,U]=d.useState([]);d.useEffect(()=>{w(1)},[n,x,c,g,p,o,u,L]);const z=d.useMemo(()=>{const l={limit:u,offset:(m-1)*u};n!=="all"&&(l.provider=n),x!=="all"&&(l.endpoint=x),c.trim().length>0&&(l.model=c.trim()),g!=="all"&&(l.status=g);const y=te(p),Z=te(o,!0);return y!==void 0&&(l.from=y),Z!==void 0&&(l.to=Z),L.length>0&&(l.apiKeys=L.join(",")),l},[n,x,c,g,p,o,m,u,L]),f=F(["logs",z],{url:"/api/logs",method:"GET",params:z}),E=F(["providers","all"],{url:"/api/providers",method:"GET"}),G=F(["api-keys"],{url:"/api/keys",method:"GET"});d.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]),d.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 R=((J=f.data)==null?void 0:J.total)??0,k=R>0?Math.ceil(R/u):0,Q=((Y=f.data)==null?void 0:Y.items)??[];d.useEffect(()=>{k>0&&m>k&&w(k)},[k,m]);const $=E.data??[],W=d.useMemo(()=>{const l=new Map;for(const y of $)y.id&&l.set(y.id,y.label??y.id);return l},[$]),A=G.data??[],H=d.useMemo(()=>{const l=new Map;for(const y of A)l.set(y.id,y);return l},[A]),de=d.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),oe=()=>{b("all"),j(""),s("all"),h("all"),a(""),i(""),U([])},ne=d.useCallback(l=>{C(l),I(!0)},[]),ce=d.useCallback(()=>{I(!1),C(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ge,{icon:e.jsx(xe,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),actions:e.jsxs("div",{className:"flex items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx("span",{className:N(D,"font-medium"),children:t("logs.summary.total",{value:R.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:N(V,"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(X,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:oe,className:N(V,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),contentClassName:"grid w-full gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(M,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...$.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(M,{value:x,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(je,{className:"md:col-span-2",apiKeys:A,selected:L,disabled:G.isLoading,onChange:U}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(q,{value:c,onChange:l=>j(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(M,{value:g,onChange:l=>h(l.target.value),options:de})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(q,{type:"date",value:p,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(q,{type:"date",value:o,onChange:l=>i(l.target.value)})})]}),e.jsxs(X,{className:"p-0",contentClassName:"gap-0",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cachedTokens")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.stream")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 dark:divide-slate-800/60",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-5 py-12 text-center text-sm text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):Q.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-5 py-12 text-center text-sm text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):Q.map(l=>e.jsx(fe,{record:l,providerLabelMap:W,apiKeyMap:H,onSelect:ne},l.id))})]})}),e.jsxs("div",{className:me,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:D,children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:u,onChange:l=>S(Number(l.target.value)),className:pe,children:ee.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(O,{onClick:()=>w(l=>Math.max(l-1,1)),disabled:m<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:N(D,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:m,total:k})}),e.jsx(O,{onClick:()=>w(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||m>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(be,{open:ie,logId:K,onClose:ce,providerLabelMap:W,apiKeyMap:H})]})}function fe({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b}){const{t:x}=P(),s=r.get(t.provider)??t.provider,c=t.endpoint||"-",j=!!t.error,g=t.status_code,h=t.client_model??x("logs.table.requestedModelFallback"),p=t.api_key_id!=null?n.get(t.api_key_id):void 0,a=t.api_key_id==null?x("logs.table.apiKeyUnknown"):p!=null&&p.isWildcard?x("apiKeys.wildcard"):p!=null&&p.name?p.name:t.api_key_name?t.api_key_name:x("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:N(D,"px-5 py-3 text-xs font-medium"),children:re(t.timestamp)}),e.jsx("td",{className:"px-5 py-3 text-sm text-slate-700 dark:text-slate-100",children:c}),e.jsx("td",{className:"px-5 py-3 text-sm text-slate-700 dark:text-slate-100",children:s}),e.jsx("td",{className:"px-5 py-3 text-sm text-slate-600 dark:text-slate-200",children:h}),e.jsx("td",{className:"px-5 py-3 text-sm text-slate-700 dark:text-slate-100",children:t.model}),e.jsx("td",{className:"px-5 py-3",children:e.jsx("span",{className:N(D,"block truncate text-sm"),title:a,children:a})}),e.jsx("td",{className:"px-5 py-3 text-right text-sm font-medium text-slate-700 dark:text-slate-100",children:_(t.input_tokens)}),e.jsx("td",{className:"px-5 py-3 text-right text-sm font-medium text-slate-700 dark:text-slate-100",children:_(t.cached_tokens)}),e.jsx("td",{className:"px-5 py-3 text-right text-sm font-medium text-slate-700 dark:text-slate-100",children:_(t.output_tokens)}),e.jsx("td",{className:"px-5 py-3 text-right text-sm text-slate-600 dark:text-slate-200",children:B(t.stream)}),e.jsx("td",{className:"px-5 py-3 text-right text-sm text-slate-700 dark:text-slate-100",children:v(t.latency_ms,x("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right text-sm text-slate-700 dark:text-slate-100",children:v(t.ttft_ms,x("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right text-sm text-slate-700 dark:text-slate-100",children:v(t.tpot_ms,x("common.units.msPerToken"))}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs(le,{variant:j?"error":"success",children:[g??(j?500:200),e.jsx("span",{children:x(j?"common.status.error":"common.status.success")})]})}),e.jsx("td",{className:"max-w-xs px-5 py-3 text-xs text-slate-500 dark:text-slate-400",children:e.jsx("span",{className:"block truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-5 py-3",children:e.jsx(O,{onClick:()=>b(t.id),size:"sm",className:"rounded-full",children:x("logs.actions.detail")})})]})}function be({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:x}){var m,w;const{t:s}=P(),{pushToast:c}=ae(),j=d.useRef(null),g=d.useRef(null),h=F(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});d.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),d.useEffect(()=>{if(!t)return;const u=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[t,n]),d.useEffect(()=>{t&&g.current&&g.current.focus()},[t,r]);const p=d.useCallback(async(u,S,K)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(K),variant:"success"})}catch(C){c({title:s("logs.detail.copy.failure"),description:C instanceof Error?C.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,o=a?b.get(a.provider)??a.provider:"",i=a&&a.api_key_id!=null?x.get(a.api_key_id):void 0;return typeof document>"u"?null:ue.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:j,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-transform 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:g,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(he,{}):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:v(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:v(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:v(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:B(a.stream)})}),e.jsxs(le,{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:re(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:o})]}),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:B(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:_(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.cachedTokens")}),e.jsx("dd",{className:"font-medium",children:_(a.cached_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:_(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:v(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:v(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"):i!=null&&i.isWildcard?s("apiKeys.wildcard"):(i==null?void 0:i.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:i!=null&&i.isWildcard?s("apiKeys.wildcard"):(i==null?void 0:i.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:i!=null&&i.lastUsedAt?new Date(i.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.raw")}),e.jsx("p",{className:"mt-1 text-xs",children:a.api_key_value?a.api_key_value:s("logs.detail.apiKey.rawUnavailable")})]}),e.jsx("button",{type:"button",disabled:!a.api_key_value,onClick:()=>p(s("logs.detail.apiKey.raw"),a.api_key_value,"logs.detail.copy.keySuccess"),className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 disabled:opacity-50 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]})]}),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 u;return p(s("logs.detail.payload.request"),(u=a.payload)==null?void 0:u.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:se((m=a.payload)==null?void 0:m.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 u;return p(s("logs.detail.payload.response"),(u=a.payload)==null?void 0:u.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:se((w=a.payload)==null?void 0:w.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 je({apiKeys:t,selected:r,onChange:n,disabled:b,className:x}){const{t:s}=P(),[c,j]=d.useState(!1),g=d.useRef(null);d.useEffect(()=>{if(!c)return;const o=i=>{var m;(m=g.current)!=null&&m.contains(i.target)||j(!1)};return window.addEventListener("mousedown",o),()=>window.removeEventListener("mousedown",o)},[c]);const h=d.useMemo(()=>{if(r.length===0)return[];const o=new Map;for(const i of t)o.set(i.id,i);return r.map(i=>{const m=o.get(i);return m?m.isWildcard?s("apiKeys.wildcard"):m.name:null}).filter(i=>!!i)},[t,r,s]),p=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=o=>{r.includes(o)?n(r.filter(i=>i!==o)):n([...r,o])};return e.jsxs("div",{className:N("relative flex flex-col gap-2",x),ref:g,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:()=>j(o=>!o),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:N("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:[p,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:N("h-4 w-4 text-slate-400 transition-transform 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/95 p-2 shadow-lg shadow-slate-200/70 backdrop-blur dark:border-slate-700/60 dark:bg-slate-900/90",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:p}),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(o=>{const i=o.isWildcard?s("apiKeys.wildcard"):o.name,m=r.includes(o.id);return e.jsxs("label",{className:N("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",m?"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:m,onChange:()=>a(o.id)}),e.jsx("span",{className:"truncate",children:i})]},o.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{Ee as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as ge,r as x,j as e,a as Ye,o as Je,q as we,h as Xe,i as U,t as ee,v as Ne,w as pe,x as me,y as Ze}from"./index-COB9rriK.js";import{u as et,a as q}from"./useApiQuery-mnvEnqVq.js";function ke(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Se(){return{_key:ke(),id:"",label:""}}const he={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5 (2025-09-29)"},{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4 (2025-05-14)"},{id:"claude-opus-4-1-20250805",label:"Claude Opus 4.1 (2025-08-05)"},{id:"claude-3-5-haiku-20241022",label:"Claude 3.5 Haiku (2024-10-22)"}]},custom:{}};function Me(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(c=>({...c,_key:ke()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[Se()],authMode:"apiKey"}}function tt(s){return{_key:ke(),id:s.id,label:s.label}}function st({open:s,mode:c,provider:m,existingProviderIds:N,onClose:C,onSubmit:B}){const{t:a}=ge(),[o,M]=x.useState(()=>Me(m)),[A,H]=x.useState({}),[_,I]=x.useState(!1),[V,F]=x.useState(null),te=x.useRef(null),K=x.useRef(null),j=x.useRef(null),[z,E]=x.useState(c==="edit");x.useEffect(()=>{s&&(M(Me(m)),H({}),F(null),I(!1),E(c==="edit"))},[s,m,c]),x.useEffect(()=>{if(!s)return;const l=u=>{u.key==="Escape"&&C()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s,C]),x.useEffect(()=>{if(s){if(c==="create"&&j.current){j.current.focus();return}K.current&&K.current.focus()}},[s,c]);const xe=x.useMemo(()=>o.models.filter(l=>l.id.trim().length>0),[o.models]),G=l=>u=>{M(p=>({...p,[l]:u}))},J=l=>{M(u=>{const b=!z||u.label.trim().length===0||u.label===u.id?l:u.label;return{...u,id:l,label:b}})},X=l=>{M(u=>{var Z;const b=he[l??"custom"]??he.custom,g=Object.values(he).map(k=>k.baseUrl).filter(k=>!!k),S=!u.baseUrl||g.includes(u.baseUrl),y=c==="create"&&(u.models.length===0||u.models.every(k=>k.id.trim().length===0)),$={...u,type:l,authMode:l==="anthropic"?u.authMode??"apiKey":"apiKey"};return b!=null&&b.baseUrl&&S&&($.baseUrl=b.baseUrl),b!=null&&b.models&&y&&($.models=b.models.map(tt),$.defaultModel=b.defaultModel??((Z=b.models[0])==null?void 0:Z.id)??""),$})},se=(l,u)=>{M(p=>{const b=[...p.models];return b[l]={...b[l],...u},{...p,models:b}})},ae=(l,u)=>{M(p=>{const b=[...p.models],g=b[l];if(!g)return p;const S=!z||!g.label||g.label===g.id,y={...g,id:u,label:S?u:g.label};b[l]=y;const $=p.defaultModel===g.id?u:p.defaultModel;return{...p,models:b,defaultModel:$}})},re=l=>{M(u=>{var g;if(u.models.length<=1)return u;const p=u.models.filter((S,y)=>y!==l);let b=u.defaultModel;return p.some(S=>S.id===b)||(b=((g=p[0])==null?void 0:g.id)??""),{...u,models:p,defaultModel:b}})},W=()=>{M(l=>({...l,models:[...l.models,Se()]}))},Y=l=>{M(u=>({...u,authMode:l}))},le=()=>{const l={},u=o.id.trim(),p=o.baseUrl.trim();if(c==="create"&&(u.length===0?l.id=a("providers.drawer.errors.idRequired"):N.includes(u)&&(l.id=a("providers.drawer.errors.idDuplicate"))),c==="edit"&&u.length===0&&(l.id=a("providers.drawer.errors.idRequired")),p.length===0)l.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(p)}catch{l.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}const b=new Set;return o.models.some(S=>{const y=S.id.trim();return y.length===0||b.has(y)?!0:(b.add(y),!1)})&&(l.models=a("providers.drawer.errors.modelInvalid")),o.models.length===0&&(l.models=a("providers.drawer.errors.modelsRequired")),o.defaultModel&&!o.models.some(S=>S.id===o.defaultModel)&&(l.models=a("providers.drawer.errors.defaultInvalid")),H(l),Object.keys(l).length===0},be=()=>{const l=o.models.map(b=>{var g;return{id:b.id.trim(),label:(g=b.label)!=null&&g.trim()?b.label.trim():void 0}}),u=m!=null&&m.extraHeaders&&Object.keys(m.extraHeaders).length>0?m.extraHeaders:void 0,p=o.type==="anthropic"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:l,extraHeaders:u,authMode:p}},de=async()=>{if(F(null),!!le()){I(!0);try{const l=be();await B(l)}catch(l){F(a("providers.drawer.toast.saveFailure",{message:l instanceof Error?l.message:"unknown"})),I(!1);return}I(!1),C()}},oe=c==="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:C,"aria-hidden":"true"}),e.jsxs("aside",{ref:te,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:a(oe?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:K,onClick:C,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:a("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:a("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>E(l=>!l),className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a(z?"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:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:j,onChange:l=>J(l.target.value),disabled:!oe,placeholder:a("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":!!A.id}),A.id?e.jsx("span",{className:"text-xs text-red-500",children:A.id}):null]}),z?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:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:l=>G("label")(l.target.value),placeholder:a("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:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:l=>G("baseUrl")(l.target.value),placeholder:a("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":!!A.baseUrl}),A.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:A.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:a("providers.drawer.fields.type")}),e.jsxs("select",{value:o.type??"custom",onChange:l=>X(l.target.value),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"deepseek",children:"DeepSeek"}),e.jsx("option",{value:"huawei",children:"华为云"}),e.jsx("option",{value:"kimi",children:"Kimi"}),e.jsx("option",{value:"anthropic",children:"Anthropic (Claude)"}),e.jsx("option",{value:"custom",children:"Custom"})]})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:l=>G("apiKey")(l.target.value),placeholder:a("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"})]}),o.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:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:a("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:o.authMode==="apiKey",onChange:()=>Y("apiKey")}),e.jsx("span",{children:a("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:o.authMode==="authToken",onChange:()=>Y("authToken")}),e.jsx("span",{children:a("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:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:W,className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a("providers.drawer.fields.addModel")})]}),A.models?e.jsx("p",{className:"text-xs text-red-500",children:A.models}):null,e.jsx("div",{className:"space-y-4",children:o.models.map((l,u)=>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:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:l.id,onChange:p=>ae(u,p.target.value),placeholder:a("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"})]}),z?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:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:l.label??"",onChange:p=>se(u,{label:p.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:l.id,checked:o.defaultModel===l.id,onChange:()=>M(p=>({...p,defaultModel:l.id})),disabled:l.id.trim().length===0}),a("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:()=>re(u),disabled:o.models.length<=1,children:a("providers.drawer.fields.removeModel")})]})]},l._key))}),xe.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("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:V?e.jsx("span",{children:V}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:C,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:_,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:de,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:_,children:a(_?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const at=["claude-sonnet-4-5-20250929","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-3-5-haiku-20241022"],rt=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function fe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Q(s){return s?Object.entries(s).map(([c,m])=>({id:fe(),source:c,target:m})):[]}function ue(s){var m,N;if(!s)return{anthropic:[],openai:[]};const c=s.endpointRouting??{};return{anthropic:Q(((m=c.anthropic)==null?void 0:m.modelRoutes)??s.modelRoutes??{}),openai:Q(((N=c.openai)==null?void 0:N.modelRoutes)??{})}}function nt(){const{t:s}=ge(),{pushToast:c}=Ye(),m=et(["config","full"],{url:"/api/config",method:"GET"}),N=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc")},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc")},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc")}],[C,B]=x.useState("providers"),[a,o]=x.useState(null),[M,A]=x.useState(!1),[H,_]=x.useState("create"),[I,V]=x.useState(void 0),[F,te]=x.useState(null),[K,j]=x.useState({anthropic:[],openai:[]}),[z,E]=x.useState({anthropic:null,openai:null}),[xe,G]=x.useState(null),[J,X]=x.useState([]),[se,ae]=x.useState(""),[re,W]=x.useState(null),[Y,le]=x.useState(!1),[be,de]=x.useState(null),[oe,l]=x.useState(null),[u,p]=x.useState(!1),[b,g]=x.useState(""),[S,y]=x.useState(null),[$,Z]=x.useState(!1),k=(a==null?void 0:a.providers)??[],Re=k.length;x.useEffect(()=>{var t;if(m.data){const r=m.data;o(r),j(ue(r)),E({anthropic:null,openai:null}),X(((t=r.routingPresets)==null?void 0:t.anthropic)??[])}},[m.data]),x.useEffect(()=>{m.isError&&m.error&&c({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,c,s]);const Ae=x.useMemo(()=>{const t=new Map;for(const r of k){if(!r.defaultModel||!r.models)continue;const d=r.models.find(i=>i.id===r.defaultModel);d&&t.set(r.id,Ce(d))}return t},[k]),ve=x.useMemo(()=>{const t=[],r=new Set;for(const i of k){const n=i.label||i.id,f=i.models??[];if(f.length>0)for(const v of f){const L=`${i.id}:${v.id}`;r.has(L)||(r.add(L),t.push({value:L,label:`${n} · ${v.label??v.id}`}))}else if(i.defaultModel){const v=`${i.id}:${i.defaultModel}`;r.has(v)||(r.add(v),t.push({value:v,label:`${n} · ${i.defaultModel}`}))}}const d=[...K.anthropic,...K.openai];for(const i of d){const n=i.target.trim();n&&!r.has(n)&&(r.add(n),t.push({value:n,label:n}))}return t},[k,K]),je=t=>{X(t),o(r=>r&&{...r,routingPresets:{...r.routingPresets,anthropic:t}})},O=()=>a?!0:(c({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),Ee=t=>{if(!a)return t;let r=t,d=1;for(;a.providers.some(i=>i.id===r);)r=`${t}-${d}`,d+=1;return r},Pe=t=>{ae(t),t.trim()&&W(null)},Ue=async()=>{if(!O())return;const t=se.trim();if(!t){W(s("modelManagement.validation.presetName"));return}if(J.some(r=>r.name.toLowerCase()===t.toLowerCase())){W(s("modelManagement.validation.presetDuplicate",{name:t}));return}le(!0);try{const d=(await q.post("/api/routing-presets/anthropic",{name:t})).data.presets??[];je(d),ae(""),W(null),c({title:s("modelManagement.toast.presetSaved",{name:t}),variant:"success"})}catch(r){c({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{le(!1),m.refetch()}},Ie=async t=>{var r;if(O()){de(t.name);try{const i=(await q.post("/api/routing-presets/anthropic/apply",{name:t.name})).data.config;i?(o(i),j(ue(i)),X(((r=i.routingPresets)==null?void 0:r.anthropic)??[])):j(n=>({...n,anthropic:Q(t.modelRoutes)})),c({title:s("modelManagement.toast.presetApplySuccess",{name:t.name}),variant:"success"})}catch(d){c({title:s("modelManagement.toast.presetApplyFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{de(null),m.refetch()}}},Le=async t=>{if(!(!O()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:t.name})))){l(t.name);try{const i=(await q.delete(`/api/routing-presets/anthropic/${encodeURIComponent(t.name)}`)).data.presets??[];je(i),c({title:s("modelManagement.toast.presetDeleteSuccess",{name:t.name}),variant:"success"})}catch(d){c({title:s("modelManagement.toast.presetDeleteFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{l(null),m.refetch()}}},De=()=>{O()&&(_("create"),V(void 0),A(!0))},Ke=()=>{O()&&(g(""),y(null),p(!0))},$e=t=>{O()&&(_("edit"),V(t),A(!0))},Te=async()=>{if(!a){c({title:s("settings.toast.missingConfig"),variant:"error"});return}const t=b.trim();if(!t){y(s("providers.quickAddHuawei.validation.apiKey"));return}const i={id:Ee("huawei-cloud"),label:s("providers.quickAddHuawei.providerLabel"),baseUrl:"https://api.modelarts-maas.com/v1",apiKey:t,type:"huawei",defaultModel:"deepseek-v3.1",models:[{id:"deepseek-v3.1",label:"DeepSeek V3.1"},{id:"KIMI-K2",label:"KIMI-K2"},{id:"qwen3-235b-a22b",label:"Qwen3 235B A22B"}]},n={...a,providers:[...a.providers,i]};try{Z(!0),await q.put("/api/config",n),o(n),j(ue(n)),p(!1),c({title:s("providers.quickAddHuawei.toast.success"),description:s("providers.quickAddHuawei.toast.added",{name:i.label||i.id}),variant:"success"}),m.refetch()}catch(f){y(f instanceof Error?f.message:s("providers.quickAddHuawei.toast.failure"))}finally{Z(!1)}},He=async t=>{if(!a)throw new Error(s("settings.toast.missingConfig"));const r=H==="create"?[...k,t]:k.map(n=>I&&n.id===I.id?{...t,id:I.id}:n),d={...a,providers:r};await q.put("/api/config",d),o(d),j(ue(d)),m.refetch();const i=H==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});c({title:i,variant:"success"})},Oe=async t=>{te(t.id);try{const r=await q.post(`/api/providers/${t.id}/test`);r.data.ok?c({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:r.data.status,duration:r.data.durationMs?`${r.data.durationMs} ms`:"—"}),variant:"success"}):c({title:s("providers.toast.testFailure",{message:`${r.data.status} ${r.data.statusText}`}),variant:"error"})}catch(r){c({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{te(null)}},qe=async t=>{var h,P,w,T;if(!O()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const d=k.filter(D=>D.id!==t.id),i=D=>{const R={};if(!D)return R;for(const[ne,ce]of Object.entries(D)){if(!ce)continue;const[ye]=ce.split(":");ye&&ye===t.id||ce===t.id||(R[ne]=ce)}return R},n=(a==null?void 0:a.endpointRouting)??{},f=i(((h=n.anthropic)==null?void 0:h.modelRoutes)??(a==null?void 0:a.modelRoutes)??{}),v=i(((P=n.openai)==null?void 0:P.modelRoutes)??{}),L={...a,providers:d,modelRoutes:f,endpointRouting:{anthropic:{defaults:((w=n.anthropic)==null?void 0:w.defaults)??a.defaults,modelRoutes:f},openai:{defaults:((T=n.openai)==null?void 0:T.defaults)??a.defaults,modelRoutes:v}}};try{await q.put("/api/config",L),o(L),j({anthropic:Q(f),openai:Q(v)}),c({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(D){c({title:s("providers.toast.deleteFailure",{message:D instanceof Error?D.message:"unknown"}),variant:"error"})}},Be=t=>{j(r=>({...r,[t]:[...r[t],{id:fe(),source:"",target:""}]})),E(r=>({...r,[t]:null}))},_e=(t,r)=>{j(d=>d[t].some(i=>i.source.trim()===r.trim())?d:{...d,[t]:[...d[t],{id:fe(),source:r,target:""}]}),E(d=>({...d,[t]:null}))},ie=(t,r,d,i)=>{j(n=>({...n,[t]:n[t].map(f=>f.id===r?{...f,[d]:i}:f)})),E(n=>({...n,[t]:null}))},Fe=(t,r)=>{j(d=>({...d,[t]:d[t].filter(i=>i.id!==r)})),E(d=>({...d,[t]:null}))},ze=t=>{var n;if(!a)return;const r=a.endpointRouting??{},d=t==="anthropic"?a.modelRoutes??{}:{},i=((n=r[t])==null?void 0:n.modelRoutes)??d;j(f=>({...f,[t]:Q(i)})),E(f=>({...f,[t]:null}))},Qe=async t=>{var i,n,f,v,L;if(!O())return;const r=K[t],d={};for(const h of r){const P=h.source.trim(),w=h.target.trim();if(!(!P&&!w)){if(!P||!w){E(T=>({...T,[t]:s("settings.validation.routePair")}));return}if(d[P]){E(T=>({...T,[t]:s("settings.validation.routeDuplicate",{model:P})}));return}d[P]=w}}E(h=>({...h,[t]:null})),G(t);try{const h=a.endpointRouting??{anthropic:{defaults:a.defaults,modelRoutes:a.modelRoutes??{}},openai:{defaults:((n=(i=a.endpointRouting)==null?void 0:i.openai)==null?void 0:n.defaults)??a.defaults,modelRoutes:((v=(f=a.endpointRouting)==null?void 0:f.openai)==null?void 0:v.modelRoutes)??{}}},P={...h,[t]:{defaults:((L=h[t])==null?void 0:L.defaults)??a.defaults,modelRoutes:d}},w={...a,endpointRouting:P,modelRoutes:t==="anthropic"?d:a.modelRoutes??{}};await q.put("/api/config",w),o(w),j(T=>({...T,[t]:Q(d)})),c({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}catch(h){c({title:s("modelManagement.toast.routesSaveFailure",{message:h instanceof Error?h.message:"unknown"}),variant:"error"})}finally{G(null)}},Ve=()=>e.jsxs("section",{className:we,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:Xe.default,children:s("providers.count",{count:Re})}),e.jsx("button",{type:"button",className:U,onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:U,onClick:Ke,children:s("providers.quickAddHuawei.button")}),e.jsx("button",{type:"button",className:ee,onClick:De,children:s("providers.actions.add")})]})]}),m.isPending||!a&&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")}):k.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:k.map(t=>e.jsxs("article",{className:"group flex h-full flex-col gap-5 rounded-3xl border border-slate-200/50 bg-gradient-to-br from-white/85 via-white/80 to-white/75 p-6 shadow-lg shadow-slate-200/30 backdrop-blur-md transition-all duration-300 hover:border-slate-200/70 hover:shadow-xl hover:shadow-slate-200/50 hover:-translate-y-1 dark:border-slate-700/50 dark:from-slate-900/85 dark:via-slate-900/80 dark:to-slate-900/75 dark:shadow-2xl dark:shadow-slate-900/40 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/90",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-blue-500 via-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-500/30",children:e.jsx("span",{className:"text-lg font-bold",children:(t.label||t.id).charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-800 dark:text-slate-100",children:t.label||t.id}),t.type?e.jsx(dt,{type:t.type}):null]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["ID: ",t.id]})]})]}),e.jsxs("div",{className:"mt-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400 font-medium",children:"Base URL:"}),e.jsx("p",{className:"text-xs font-mono text-slate-700 dark:text-slate-300 bg-slate-100/50 dark:bg-slate-800/50 rounded-lg px-2 py-1 break-all",children:t.baseUrl})]})]}),e.jsx("div",{className:"flex flex-col gap-2",children:t.defaultModel?e.jsx("div",{className:Ne.success,children:s("providers.card.defaultModel",{model:Ae.get(t.id)??t.defaultModel})}):e.jsx("div",{className:Ne.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(r=>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:Ce(r)})]},r.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:U,onClick:()=>$e(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>Oe(t),disabled:F===t.id,className:F===t.id?`${U} opacity-60 cursor-not-allowed`:U,children:F===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:pe,onClick:()=>qe(t),children:s("providers.actions.delete")})]})]},t.id))})]}),Ge=()=>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:se,onChange:t=>Pe(t.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:me,disabled:Y}),e.jsx("button",{type:"button",onClick:Ue,className:ee,disabled:Y,children:s(Y?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),re?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:re}):null,J.length===0?e.jsx("div",{className:"rounded-xl border border-slate-200/40 bg-slate-50/60 p-6 text-center text-sm text-slate-600 dark:border-slate-700/40 dark:bg-slate-800/40 dark:text-slate-400 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"rounded-xl bg-slate-200/50 p-3 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-6 w-6 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("modelManagement.presets.empty")})]})}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:J.map(t=>{const r=be===t.name,d=oe===t.name;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-slate-200/50 bg-gradient-to-r from-white/90 to-white/80 px-4 py-3 text-sm shadow-sm backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-white/95 hover:shadow-md dark:border-slate-700/50 dark:from-slate-900/90 dark:to-slate-900/80 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/95",children:[e.jsx("span",{className:"truncate font-medium text-slate-700 dark:text-slate-200",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Ie(t),className:r||d?`${U} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${ee} text-xs px-2 py-1`,disabled:r||d,children:s(r?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>Le(t),className:d||r?`${U} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${pe} text-xs px-2 py-1`,disabled:d||r,children:s(d?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},t.name)})})]}),We=t=>{const r=K[t],d=z[t],i=t==="anthropic"?at:rt,n=xe===t,f=s(`modelManagement.tabs.${t}`),v=`route-source-${t}`,L=`route-target-${t}`;return e.jsxs("section",{className:we,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:f})}),e.jsx("p",{className:"max-w-3xl text-sm text-slate-600 dark:text-slate-400",children:s(`settings.routing.descriptionByEndpoint.${t}`)})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>Be(t),className:U,disabled:n,children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>ze(t),className:U,disabled:n,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Qe(t),className:ee,disabled:n,children:s(n?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),t==="anthropic"?Ge():null,d?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:d}):null,r.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:r.map((h,P)=>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:P+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:h.source,onChange:w=>ie(t,h.id,"source",w.target.value),className:me,placeholder:"claude-3.5-sonnet",list:v,disabled:n})]})}),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 w=h.target.trim(),D=ve.some(R=>R.value===w)?w:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:D,onChange:R=>{const ne=R.target.value;ne==="__custom"?ie(t,h.id,"target",w):ie(t,h.id,"target",ne)},className:Ze,disabled:n,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),ve.map(R=>e.jsx("option",{value:R.value,children:R.label},`${L}-${R.value}`))]}),D==="__custom"&&e.jsx("input",{type:"text",value:h.target,onChange:R=>ie(t,h.id,"target",R.target.value),className:me,placeholder:"providerId:modelId",disabled:n})]})})()]})}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:pe,onClick:()=>Fe(t,h.id),disabled:n,children:s("settings.routing.remove")})})]})]},h.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(h=>e.jsx("button",{type:"button",onClick:()=>_e(t,h),className:U,disabled:n,children:h},`${t}-${h}`))})]})}),e.jsx("datalist",{id:v,children:i.map(h=>e.jsx("option",{value:h},`${v}-${h}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx("div",{className:Je,children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-900 to-slate-700 bg-clip-text text-transparent dark:from-slate-100 dark:to-slate-300",children:s("modelManagement.title")}),e.jsx("p",{className:"text-base text-slate-600 dark:text-slate-400",children:s("modelManagement.description")})]})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:N.map(t=>{const r=C===t.key;return e.jsxs("button",{type:"button",onClick:()=>B(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 ${r?"border-blue-500/30 bg-gradient-to-r from-blue-50 to-indigo-50 text-blue-700 shadow-lg shadow-blue-200/40 ring-1 ring-blue-500/20 dark:border-blue-400/30 dark:from-blue-900/40 dark:to-indigo-900/30 dark:text-blue-100 dark:shadow-xl dark:shadow-blue-500/20 dark:ring-blue-400/20":"border-slate-200/50 bg-white/80 hover:bg-white/90 hover:shadow-md hover:shadow-slate-200/30 dark:border-slate-700/50 dark:bg-slate-900/80 dark:hover:bg-slate-900/90 dark:hover:shadow-lg dark:hover:shadow-slate-900/30"}`,children:[e.jsx("span",{className:"text-base font-bold",children:t.label}),e.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:t.description})]},t.key)})}),C==="providers"?Ve():We(C),e.jsx(st,{open:M,mode:H,provider:H==="edit"?I:void 0,existingProviderIds:k.map(t=>t.id).filter(t=>H==="edit"&&I?t!==I.id:!0),onClose:()=>{A(!1),V(void 0),_("create")},onSubmit:He}),e.jsx(lt,{open:u,apiKey:b,onApiKeyChange:t=>{g(t),S&&y(null)},loading:$,error:S,onClose:()=>{$||(p(!1),y(null))},onSubmit:Te})]})}function lt({open:s,apiKey:c,onApiKeyChange:m,loading:N,error:C,onClose:B,onSubmit:a}){const{t:o}=ge();return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex animate-fade-in",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60 backdrop-blur-sm",onClick:B,"aria-hidden":"true"}),e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"quick-add-huawei",className:"flex h-full w-full max-w-md flex-col border-l border-slate-200/50 bg-gradient-to-b from-white/95 to-white/90 shadow-2xl backdrop-blur-xl animate-slide-up dark:border-slate-800/50 dark:from-slate-950/95 dark:to-slate-950/90",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200/50 px-6 py-5 dark:border-slate-800/50",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h2",{id:"quick-add-huawei",className:"text-xl font-bold text-slate-800 dark:text-slate-100",children:o("providers.quickAddHuawei.title")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:o("providers.quickAddHuawei.description")})]}),e.jsx("button",{type:"button",onClick:B,className:U,disabled:N,children:o("common.actions.close")})]}),e.jsx("div",{className:"flex flex-1 flex-col gap-6 px-6 py-6",children:e.jsxs("div",{className:"space-y-3",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:o("providers.quickAddHuawei.apiKeyLabel")}),e.jsx("input",{type:"password",value:c,onChange:M=>m(M.target.value),placeholder:o("providers.quickAddHuawei.apiKeyPlaceholder"),className:me,disabled:N})]}),e.jsx("div",{className:"rounded-xl border border-blue-200/50 bg-blue-50/80 p-4 text-sm text-blue-700 dark:border-blue-800/50 dark:bg-blue-900/40 dark:text-blue-300 backdrop-blur-sm",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("svg",{className:"h-5 w-5 text-blue-500 flex-shrink-0 mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm",children:o("providers.quickAddHuawei.note")})]})}),C?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:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("svg",{className:"h-5 w-5 text-red-500 flex-shrink-0 mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm",children:C})]})}):null]})}),e.jsxs("footer",{className:"flex items-center justify-end gap-3 border-t border-slate-200/50 px-6 py-5 dark:border-slate-800/50",children:[e.jsx("button",{type:"button",onClick:B,className:U,disabled:N,children:o("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:a,className:ee,disabled:N,children:o(N?"common.actions.saving":"providers.quickAddHuawei.submit")})]})]})]}):null}function Ce(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function dt({type:s}){const c={openai:{label:"OpenAI",color:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300"},deepseek:{label:"DeepSeek",color:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300"},huawei:{label:"华为云",color:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300"},kimi:{label:"Kimi",color:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300"},anthropic:{label:"Anthropic",color:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300"},custom:{label:"Custom",color:"bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"}},{label:m,color:N}=c[s]||c.custom;return e.jsx("span",{className:`rounded-full ${N} px-2.5 py-1 text-xs font-semibold shadow-sm`,children:m})}export{nt as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,b as a,_ as x,m as n,o as c,$ as m,q as h}from"./index-COB9rriK.js";function g({icon:s,title:r,description:l,badge:d,actions:i,className:t}){return e.jsxs("div",{className:a(c,"animate-slide-up",t),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-6",children:[s?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:s}):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:a(x,"shadow-md"),children:d}):null]}),l?e.jsx("div",{className:a(n,"max-w-3xl text-base leading-relaxed"),children:l}):null]})]}),i?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-4",children:i}):null]})}function o({title:s,description:r,actions:l,className:d,contentClassName:i,children:t}){return e.jsxs("section",{className:a(h,"animate-slide-up",d),children:[(s||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 s=="string"?e.jsx("h2",{className:a(m,"text-base font-bold"),children:s}):s,r?e.jsx("div",{className:a(n,"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:a("flex flex-col gap-6",i),children:t})]})}export{g as P,o as a};
|