@chenpu17/cc-gw 0.7.2 → 0.7.3
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/LICENSE +21 -0
- package/package.json +19 -6
- package/{server → src/server/dist}/index.js +51 -1
- package/{web/assets/About-BY3JDEBL.js → src/web/dist/assets/About-B-TlL_1U.js} +2 -2
- package/src/web/dist/assets/ApiKeys-vV04L6nB.js +26 -0
- package/{web/assets/Button-6f5FYqHp.js → src/web/dist/assets/Button-CK3N5RnJ.js} +1 -1
- package/{web/assets/Dashboard-xs4UfKRq.js → src/web/dist/assets/Dashboard-Ct0nz59m.js} +1 -1
- package/{web/assets/Events-D_RJKNNo.js → src/web/dist/assets/Events-D1dFnWUQ.js} +1 -1
- package/{web/assets/FormField-DKWx0tXD.js → src/web/dist/assets/FormField-D6CVd30C.js} +1 -1
- package/{web/assets/Help-CXLtGK8v.js → src/web/dist/assets/Help-BAX6PZdo.js} +1 -1
- package/{web/assets/Input-Iev5RCKK.js → src/web/dist/assets/Input-DwLjINOT.js} +1 -1
- package/{web/assets/Login-qc-n0iUi.js → src/web/dist/assets/Login-DmMmSsuJ.js} +1 -1
- package/{web/assets/Logs-DSGqxauM.js → src/web/dist/assets/Logs-BgPHhO9L.js} +1 -1
- package/{web/assets/ModelManagement-D11jx2bC.js → src/web/dist/assets/ModelManagement-ptCXiwmH.js} +1 -1
- package/{web/assets/PageSection-BJJ735Qk.js → src/web/dist/assets/PageSection-Ce8cXojT.js} +1 -1
- package/{web/assets/Settings-BT-6W3GT.js → src/web/dist/assets/Settings-N7huQDJE.js} +1 -1
- package/{web/assets/StatusBadge-9lxhNpvi.js → src/web/dist/assets/StatusBadge-DnIFGtUc.js} +1 -1
- package/{web/assets/copy-DMW-t8h3.js → src/web/dist/assets/copy-MV8oAPES.js} +1 -1
- package/{web/assets/index-CJMKkw2H.css → src/web/dist/assets/index-BhKQmj-I.css} +1 -1
- package/{web/assets/index-BM-Zc1f-.js → src/web/dist/assets/index-DUQNG-qd.js} +1 -1
- package/{web/assets/index-dFe_7qSp.js → src/web/dist/assets/index-Dz1s8uzG.js} +4 -4
- package/{web/assets/info-ByJJXVcp.js → src/web/dist/assets/info-B4aq_I9e.js} +1 -1
- package/{web/assets/refresh-cw-BF1LiBLP.js → src/web/dist/assets/refresh-cw-DDXCOeFJ.js} +1 -1
- package/{web/assets/useApiQuery-i7GI_aGQ.js → src/web/dist/assets/useApiQuery-BA98Vr2f.js} +1 -1
- package/{web → src/web/dist}/index.html +2 -2
- package/web/assets/ApiKeys-qhC2jZqJ.js +0 -16
- /package/{cli → src/cli/dist}/index.d.ts +0 -0
- /package/{cli → src/cli/dist}/index.js +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 chenpu17
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chenpu17/cc-gw",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"dev": "pnpm --filter server dev",
|
|
8
|
+
"build": "pnpm run build:server && pnpm run build:web",
|
|
9
|
+
"build:server": "pnpm --filter @cc-gw/server build",
|
|
10
|
+
"build:cli": "pnpm --filter @cc-gw/cli build",
|
|
11
|
+
"build:web": "pnpm --filter @cc-gw/web build",
|
|
12
|
+
"build:all": "pnpm run build:server && pnpm run build:cli && pnpm run build:web",
|
|
13
|
+
"release:bundle": "pnpm run build:all && node scripts/build-release.mjs",
|
|
14
|
+
"prepack": "pnpm run build:all",
|
|
15
|
+
"lint": "pnpm exec eslint .",
|
|
16
|
+
"format": "pnpm exec prettier --check .",
|
|
17
|
+
"format:write": "pnpm exec prettier --write .",
|
|
18
|
+
"typecheck": "pnpm -r exec tsc --noEmit",
|
|
19
|
+
"test": "pnpm exec vitest run",
|
|
20
|
+
"test:playwright": "playwright test"
|
|
8
21
|
},
|
|
9
22
|
"bin": {
|
|
10
|
-
"cc-gw": "cli/index.js"
|
|
23
|
+
"cc-gw": "src/cli/dist/index.js"
|
|
11
24
|
},
|
|
12
25
|
"files": [
|
|
13
|
-
"cli",
|
|
14
|
-
"server",
|
|
15
|
-
"web",
|
|
26
|
+
"src/cli/dist",
|
|
27
|
+
"src/server/dist",
|
|
28
|
+
"src/web/dist",
|
|
16
29
|
"README.md",
|
|
17
30
|
"LICENSE"
|
|
18
31
|
],
|
|
@@ -12959,6 +12959,20 @@ async function recordApiKeyUsage(id, delta) {
|
|
|
12959
12959
|
async function decryptApiKeyValue(value) {
|
|
12960
12960
|
return decryptSecret(value);
|
|
12961
12961
|
}
|
|
12962
|
+
async function revealApiKey(id) {
|
|
12963
|
+
const row = await getOne("SELECT id, key_ciphertext, is_wildcard FROM api_keys WHERE id = ?", [id]);
|
|
12964
|
+
if (!row) {
|
|
12965
|
+
return null;
|
|
12966
|
+
}
|
|
12967
|
+
if (row.is_wildcard) {
|
|
12968
|
+
return null;
|
|
12969
|
+
}
|
|
12970
|
+
const decrypted = await decryptSecret(row.key_ciphertext);
|
|
12971
|
+
if (!decrypted) {
|
|
12972
|
+
return null;
|
|
12973
|
+
}
|
|
12974
|
+
return { key: decrypted };
|
|
12975
|
+
}
|
|
12962
12976
|
async function ensureWildcardMetadata() {
|
|
12963
12977
|
const wildcard = await fetchWildcard();
|
|
12964
12978
|
if (!wildcard) {
|
|
@@ -13015,7 +13029,7 @@ async function listEvents(options = {}) {
|
|
|
13015
13029
|
|
|
13016
13030
|
// routes/anthropic-validator.ts
|
|
13017
13031
|
var ALLOWED_ROLES = /* @__PURE__ */ new Set(["user", "assistant"]);
|
|
13018
|
-
var KNOWN_BLOCK_TYPES = /* @__PURE__ */ new Set(["text", "tool_use", "tool_result", "thinking", "output_text", "input_text", "image"]);
|
|
13032
|
+
var KNOWN_BLOCK_TYPES = /* @__PURE__ */ new Set(["text", "tool_use", "tool_result", "thinking", "output_text", "input_text", "image", "document"]);
|
|
13019
13033
|
var ALLOWED_TYPE_PREFIXES = ["input_", "output_", "data_", "media_"];
|
|
13020
13034
|
function isPlainObject(value) {
|
|
13021
13035
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -13136,6 +13150,24 @@ function validateContentBlock(block, opts) {
|
|
|
13136
13150
|
}
|
|
13137
13151
|
break;
|
|
13138
13152
|
}
|
|
13153
|
+
case "document": {
|
|
13154
|
+
if (!block.source || !isPlainObject(block.source)) {
|
|
13155
|
+
return fail("document \u5757\u5FC5\u987B\u5305\u542B source \u5BF9\u8C61", appendPath(opts.path, "source"), "invalid_content_block");
|
|
13156
|
+
}
|
|
13157
|
+
if (typeof block.source.type !== "string") {
|
|
13158
|
+
return fail("document \u5757 source.type \u5FC5\u987B\u662F\u5B57\u7B26\u4E32", appendPath(opts.path, "source.type"), "invalid_content_block");
|
|
13159
|
+
}
|
|
13160
|
+
if (block.source.media_type !== void 0 && typeof block.source.media_type !== "string") {
|
|
13161
|
+
return fail("document \u5757 source.media_type \u5FC5\u987B\u662F\u5B57\u7B26\u4E32", appendPath(opts.path, "source.media_type"), "invalid_content_block");
|
|
13162
|
+
}
|
|
13163
|
+
if (block.title !== void 0 && typeof block.title !== "string") {
|
|
13164
|
+
return fail("document \u5757 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32", appendPath(opts.path, "title"), "invalid_content_block");
|
|
13165
|
+
}
|
|
13166
|
+
if (block.context !== void 0 && typeof block.context !== "string") {
|
|
13167
|
+
return fail("document \u5757 context \u5FC5\u987B\u662F\u5B57\u7B26\u4E32", appendPath(opts.path, "context"), "invalid_content_block");
|
|
13168
|
+
}
|
|
13169
|
+
break;
|
|
13170
|
+
}
|
|
13139
13171
|
case "tool_use": {
|
|
13140
13172
|
if (typeof block.id !== "string" || block.id.trim().length === 0) {
|
|
13141
13173
|
return fail("tool_use \u5757\u9700\u8981\u5B57\u7B26\u4E32\u7C7B\u578B\u7684 id", appendPath(opts.path, "id"), "invalid_tool_use");
|
|
@@ -17590,6 +17622,24 @@ async function registerAdminRoutes(app) {
|
|
|
17590
17622
|
return { error: error instanceof Error ? error.message : "Failed to delete API key" };
|
|
17591
17623
|
}
|
|
17592
17624
|
});
|
|
17625
|
+
app.get("/api/keys/:id/reveal", async (request, reply) => {
|
|
17626
|
+
const id = Number(request.params.id);
|
|
17627
|
+
if (!Number.isFinite(id)) {
|
|
17628
|
+
reply.code(400);
|
|
17629
|
+
return { error: "Invalid id" };
|
|
17630
|
+
}
|
|
17631
|
+
try {
|
|
17632
|
+
const result = await revealApiKey(id);
|
|
17633
|
+
if (!result) {
|
|
17634
|
+
reply.code(404);
|
|
17635
|
+
return { error: "API key not found or cannot be revealed" };
|
|
17636
|
+
}
|
|
17637
|
+
return result;
|
|
17638
|
+
} catch (error) {
|
|
17639
|
+
reply.code(500);
|
|
17640
|
+
return { error: error instanceof Error ? error.message : "Failed to reveal API key" };
|
|
17641
|
+
}
|
|
17642
|
+
});
|
|
17593
17643
|
const normalizePath = (path5) => {
|
|
17594
17644
|
const trimmed = path5.trim();
|
|
17595
17645
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{c as f,u as v,a as j,r,j as e,d as o,W as k,m as i}from"./index-
|
|
1
|
+
import{c as f,u as v,a as j,r,j as e,d as o,W as k,m as i}from"./index-Dz1s8uzG.js";import{u as N}from"./useApiQuery-BA98Vr2f.js";import{P as w,a as d}from"./PageSection-Ce8cXojT.js";import"./Input-DwLjINOT.js";import{B as b}from"./Button-CK3N5RnJ.js";import{I as T}from"./info-B4aq_I9e.js";import{R as y}from"./refresh-cw-DDXCOeFJ.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const E=f("Sparkles",[["path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z",key:"17u4zn"}],["path",{d:"M5 3v4",key:"bklmnn"}],["path",{d:"M19 17v4",key:"iiml17"}],["path",{d:"M3 5h4",key:"nem4j1"}],["path",{d:"M17 19h4",key:"lbex7p"}]]),I="0.7.
|
|
6
|
+
*/const E=f("Sparkles",[["path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z",key:"17u4zn"}],["path",{d:"M5 3v4",key:"bklmnn"}],["path",{d:"M19 17v4",key:"iiml17"}],["path",{d:"M3 5h4",key:"nem4j1"}],["path",{d:"M17 19h4",key:"lbex7p"}]]),I="0.7.3",_={version:I},L={VITE_BUILD_TIME:"2025-12-05T04:26:10.372Z",VITE_NODE_VERSION:"v22.16.0"};function m({items:t}){return t.length===0?null:e.jsx("dl",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-2",children:t.map(s=>e.jsxs("div",{className:"rounded-2xl border border-slate-200/50 bg-white p-4 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-200/70 hover:shadow-md hover:shadow-slate-200/40 dark:border-slate-700/50 dark:bg-slate-900/80 dark:shadow-lg dark:shadow-slate-900/30 dark:hover:border-slate-600/70",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-slate-500 dark:text-slate-400",children:s.label}),e.jsx("dd",{className:"mt-2 text-base font-semibold text-slate-900 dark:text-slate-100",children:s.value}),s.hint?e.jsx("p",{className:o(i,"mt-2 text-xs leading-relaxed"),children:s.hint}):null]},s.label))})}function D(){const{t}=v(),{pushToast:s}=j(),a=N(["status","gateway"],{url:"/api/status",method:"GET"},{staleTime:6e4});r.useEffect(()=>{a.isError&&a.error&&s({title:t("about.toast.statusError.title"),description:a.error.message,variant:"error"})},[a.isError,a.error,s,t]);const n=_.version,l=r.useMemo(()=>{const u=L,h=u.VITE_BUILD_TIME,g=u.VITE_NODE_VERSION;return{buildTime:h,nodeVersion:g}},[]),p=r.useMemo(()=>[{label:t("about.app.labels.name"),value:e.jsx("span",{className:"font-mono text-sm font-semibold text-slate-900 dark:text-slate-100",children:"cc-gw"})},{label:t("about.app.labels.version"),value:e.jsxs("span",{className:"font-mono text-sm font-semibold text-blue-700 dark:text-blue-200",children:["v",n]})},{label:t("about.app.labels.buildTime"),value:l.buildTime,hint:t("about.app.hint.buildTime")},{label:t("about.app.labels.node"),value:e.jsx("span",{className:"font-mono text-sm text-slate-800 dark:text-slate-200",children:l.nodeVersion})}],[n,l.buildTime,l.nodeVersion,t]),c=r.useMemo(()=>a.data?[{label:t("about.status.labels.host"),value:a.data.host??"127.0.0.1"},{label:t("about.status.labels.port"),value:a.data.port.toLocaleString()},{label:t("about.status.labels.providers"),value:a.data.providers.toLocaleString()},{label:t("about.status.labels.active"),value:(a.data.activeRequests??0).toLocaleString(),hint:t("about.status.hint.active")}]:[],[a.data,t]),x=()=>{s({title:t("about.toast.updatesPlanned"),variant:"info"})};return e.jsxs("div",{className:"space-y-8",children:[e.jsx(w,{icon:e.jsx(T,{className:"h-6 w-6","aria-hidden":"true"}),title:t("about.title"),description:t("about.description"),badge:`v${n}`,actions:e.jsx(b,{variant:"primary",icon:e.jsx(E,{className:"h-4 w-4","aria-hidden":"true"}),onClick:x,children:t("about.support.actions.checkUpdates")})}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(d,{title:t("about.app.title"),description:t("about.app.subtitle"),className:"h-full",contentClassName:"gap-4",children:e.jsx(m,{items:p})}),e.jsx(d,{title:t("about.status.title"),description:t("about.status.subtitle"),className:"h-full",contentClassName:"gap-4",actions:e.jsx(b,{variant:"subtle",size:"sm",icon:e.jsx(y,{className:"h-4 w-4","aria-hidden":"true"}),onClick:()=>a.refetch(),loading:a.isFetching,children:a.isFetching?t("common.actions.refreshing"):t("common.actions.refresh")}),children:a.isLoading?e.jsxs("div",{className:"flex h-36 flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-[3px] border-blue-500/30 border-t-blue-600 dark:border-blue-400/20 dark:border-t-blue-300"}),e.jsx("p",{className:o(i,"text-sm"),children:t("about.status.loading")})]}):c.length>0?e.jsx(m,{items:c}):e.jsxs("div",{className:"flex h-36 flex-col items-center justify-center gap-2 rounded-2xl border border-dashed border-slate-200/60 bg-white p-6 text-center shadow-inner dark:border-slate-700/60 dark:bg-slate-900/60",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:t("about.status.empty")}),e.jsx("p",{className:o(i,"text-xs"),children:t("common.actions.refresh")})]})})]}),e.jsx(d,{title:t("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-semibold text-blue-600 dark:text-blue-300",children:t("about.support.subtitle")}),e.jsx("span",{children:t("about.support.description")})]}),className:"relative overflow-hidden",contentClassName:"gap-6",children:e.jsxs("div",{className:"flex flex-col gap-4 rounded-3xl border border-slate-200/50 bg-white p-6 shadow-lg shadow-slate-200/30 backdrop-blur-md dark:border-slate-700/50 dark:bg-slate-900/80 dark:shadow-slate-900/40",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsx("div",{className:"grid h-12 w-12 place-items-center rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 text-blue-600 shadow-inner dark:text-blue-200",children:e.jsx(k,{className:"h-6 w-6","aria-hidden":"true"})}),e.jsx("p",{className:o(i,"text-sm leading-6"),children:t("about.support.tip")})]}),e.jsx("code",{className:"inline-flex items-center gap-2 self-start rounded-full border border-blue-200/50 bg-blue-50/80 px-4 py-2 text-xs font-semibold tracking-wide text-blue-700 shadow-sm dark:border-blue-500/30 dark:bg-blue-900/30 dark:text-blue-200",children:"~/.cc-gw/config.json"})]})})]})}export{D as default};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{c as v,u as B,a as te,r as d,j as e,L as le,P as ie,d as l,b as K,m as c,J as x,H as re,k as ne,l as ce,f as de,h as oe}from"./index-Dz1s8uzG.js";import{E as pe}from"./index-DUQNG-qd.js";import{u as S}from"./useApiQuery-BA98Vr2f.js";import{P as me,a as I}from"./PageSection-Ce8cXojT.js";import{F as W}from"./FormField-D6CVd30C.js";import{I as xe}from"./Input-DwLjINOT.js";import{B as T}from"./Button-CK3N5RnJ.js";import{S as ue}from"./StatusBadge-DnIFGtUc.js";import{C as z}from"./copy-MV8oAPES.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 ye=v("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 he=v("EyeOff",[["path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24",key:"1jxqfv"}],["path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68",key:"9wicm4"}],["path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61",key:"1jreej"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);/**
|
|
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 ge=v("Eye",[["path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z",key:"rwhkz3"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
|
|
17
|
+
* @license lucide-react v0.344.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const fe=v("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
|
|
22
|
+
* @license lucide-react v0.344.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const be=v("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"}]]),ve=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function Me(){const{t:a}=B(),{pushToast:r}=te(),[N,u]=d.useState(!1),[y,h]=d.useState(""),[M,w]=d.useState(""),[g,E]=d.useState(null),[V,L]=d.useState(null),[p,G]=d.useState(7),[A,P]=d.useState(new Map),[Q,R]=d.useState(null),f=S(["api-keys"],{url:"/api/keys",method:"GET"}),j=S(["api-keys","overview",p],{url:"/api/stats/api-keys/overview",method:"GET",params:{days:p}}),b=S(["api-keys","usage",p],{url:"/api/stats/api-keys/usage",method:"GET",params:{days:p,limit:10}}),C=f.data??[],m=j.data,o=b.data??[],U=C.some(s=>s.isWildcard),$=m?m.totalKeys.toLocaleString():"–",J=m?m.enabledKeys.toLocaleString():"–",Z=m?m.activeKeys.toLocaleString():"–",q=async()=>{var s,t;if(!y.trim()){r({title:a("apiKeys.errors.nameRequired"),variant:"error"});return}try{const i=await K.post("/api/keys",{name:y.trim(),description:M.trim()||void 0});E(i.data),u(!1),h(""),w(""),f.refetch(),j.refetch(),b.refetch(),r({title:a("apiKeys.toast.keyCreated"),variant:"success"})}catch(i){r({title:a("apiKeys.toast.createFailure",{message:((t=(s=i.response)==null?void 0:s.data)==null?void 0:t.error)||i.message}),variant:"error"})}},_=async(s,t)=>{var i,n;try{await K.patch(`/api/keys/${s}`,{enabled:!t}),f.refetch(),j.refetch(),r({title:a("apiKeys.toast.keyUpdated"),variant:"success"})}catch(k){r({title:a("apiKeys.toast.updateFailure",{message:((n=(i=k.response)==null?void 0:i.data)==null?void 0:n.error)||k.message}),variant:"error"})}},X=async s=>{var t,i;if(confirm(a("apiKeys.confirmDelete"))){L(s);try{await K.delete(`/api/keys/${s}`),f.refetch(),j.refetch(),b.refetch(),r({title:a("apiKeys.toast.keyDeleted"),variant:"success"})}catch(n){r({title:a("apiKeys.toast.deleteFailure",{message:((i=(t=n.response)==null?void 0:t.data)==null?void 0:i.error)||n.message}),variant:"error"})}finally{L(null)}}},Y=async s=>{var t,i;if(!A.has(s)){R(s);try{const n=await K.get(`/api/keys/${s}/reveal`);P(k=>new Map(k).set(s,n.data.key))}catch(n){r({title:a("apiKeys.toast.revealFailure"),description:((i=(t=n.response)==null?void 0:t.data)==null?void 0:i.error)||n.message,variant:"error"})}finally{R(null)}}},ee=s=>{P(t=>{const i=new Map(t);return i.delete(s),i})},F=async s=>{try{await navigator.clipboard.writeText(s),r({title:a("apiKeys.toast.keyCopied"),variant:"success"})}catch(t){r({title:a("apiKeys.toast.copyFailure"),description:t instanceof Error?t.message:a("common.unknownError"),variant:"error"})}},O=s=>s?new Date(s).toLocaleString():a("common.noData"),ae=d.useMemo(()=>{const s=o.map(t=>t.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.requestsSeries"),type:"bar",data:o.map(t=>t.requests),itemStyle:{color:"#2563eb"}}]}},[o,a]),se=d.useMemo(()=>{const s=o.map(t=>t.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[a("apiKeys.analytics.tokens.input"),a("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:o.map(t=>t.inputTokens)},{name:a("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:o.map(t=>t.outputTokens)}]}},[o,a]);return f.isLoading?e.jsx(le,{}):e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(me,{icon:e.jsx(ie,{className:"h-6 w-6","aria-hidden":"true"}),title:a("apiKeys.title"),description:a("apiKeys.description"),actions:e.jsx(T,{onClick:()=>u(!0),variant:"primary",size:"lg",icon:e.jsx(fe,{className:"h-4 w-4","aria-hidden":"true"}),className:"rounded-full",children:a("apiKeys.createNew")})}),e.jsxs(I,{title:a("apiKeys.analytics.title"),description:a("apiKeys.analytics.description",{days:p}),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:ve.map(s=>{const t=p===s.value;return e.jsx("button",{type:"button",onClick:()=>G(s.value),className:l("inline-flex h-8 items-center rounded-full px-3 text-xs font-semibold transition",t?"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(D,{label:a("apiKeys.analytics.cards.total"),value:$}),e.jsx(D,{label:a("apiKeys.analytics.cards.enabled"),value:J}),e.jsx(D,{label:a("apiKeys.analytics.cards.active",{days:p}),value:Z})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(H,{title:a("apiKeys.analytics.charts.requests"),loading:b.isLoading,empty:o.length===0,emptyText:a("apiKeys.analytics.empty"),option:ae}),e.jsx(H,{title:a("apiKeys.analytics.charts.tokens"),loading:b.isLoading,empty:o.length===0,emptyText:a("apiKeys.analytics.empty"),option:se})]})]}),e.jsx(I,{title:a("apiKeys.list.title"),description:U?a("apiKeys.wildcardHint"):void 0,contentClassName:"gap-4",children:C.length===0?e.jsx("div",{className:l(x,"p-6 text-center"),children:e.jsx("p",{className:l(c,"text-sm"),children:a("apiKeys.list.empty")})}):e.jsx("div",{className:"grid gap-4",children:C.map(s=>{const t=(s.totalInputTokens+s.totalOutputTokens).toLocaleString(),i=A.get(s.id),n=Q===s.id;return e.jsx("div",{className:l(x,"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(ue,{variant:s.enabled?"success":"info",children:s.enabled?a("apiKeys.status.enabled"):a("apiKeys.status.disabled")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"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"):i??s.maskedKey??"********"}),!s.isWildcard&&e.jsx("div",{className:"flex items-center gap-1",children:i?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void F(i),className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-slate-600 transition hover:bg-slate-200/80 dark:text-slate-300 dark:hover:bg-slate-700/80","aria-label":a("common.actions.copy"),title:a("common.actions.copy"),children:e.jsx(z,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>ee(s.id),className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-slate-600 transition hover:bg-slate-200/80 dark:text-slate-300 dark:hover:bg-slate-700/80","aria-label":a("apiKeys.actions.hide"),title:a("apiKeys.actions.hide"),children:e.jsx(he,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx("button",{type:"button",onClick:()=>void Y(s.id),disabled:n,className:l("inline-flex h-8 w-8 items-center justify-center rounded-full text-slate-600 transition hover:bg-slate-200/80 dark:text-slate-300 dark:hover:bg-slate-700/80",n&&"cursor-wait opacity-50"),"aria-label":a("apiKeys.actions.reveal"),title:a("apiKeys.actions.reveal"),children:e.jsx(ge,{className:"h-4 w-4","aria-hidden":"true"})})})]}),s.isWildcard?e.jsx("p",{className:l(c,"text-sm text-purple-600 dark:text-purple-200"),children:a("apiKeys.wildcardHint")}):s.description?e.jsx("p",{className:l(c,"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:l(c,"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:O(s.createdAt)})]}),e.jsxs("div",{className:l(c,"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:O(s.lastUsedAt)})]}),e.jsxs("div",{className:l(c,"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:l(c,"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:t})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>_(s.id,s.enabled),className:l("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:()=>X(s.id),disabled:V===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(be,{className:"h-4 w-4","aria-hidden":"true"})})]})]})},s.id)})})}),N&&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:l(x,"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:l(c,"text-sm"),children:a("apiKeys.createDescription")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(W,{label:a("apiKeys.keyNamePlaceholder"),required:!0,children:e.jsx(xe,{value:y,onChange:s=>h(s.target.value),placeholder:a("apiKeys.keyNamePlaceholder"),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),q())}})}),e.jsx(W,{label:a("apiKeys.descriptionLabel"),children:e.jsx("textarea",{value:M,onChange:s=>w(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(T,{onClick:()=>{u(!1),h(""),w("")},variant:"subtle",className:"rounded-full",children:a("common.actions.cancel")}),e.jsx(T,{onClick:()=>void q(),variant:"primary",className:"rounded-full",children:a("apiKeys.createAction")})]})]})}),g&&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:l(x,"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(ye,{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:g.key}),g.description?e.jsx("p",{className:l(c,"whitespace-pre-wrap text-sm"),children:g.description}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>void F(g.key),className:l(re,"h-10 rounded-full px-4"),children:[e.jsx(z,{className:"h-4 w-4","aria-hidden":"true"}),a("common.actions.copy")]}),e.jsx("button",{type:"button",onClick:()=>E(null),className:l(ne,"h-10 rounded-full px-4"),children:a("common.actions.close")})]})]})})]})}function D({label:a,value:r}){return e.jsxs("div",{className:l(x,"p-6"),children:[e.jsx("p",{className:l(c,"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:r})]})}function H({title:a,option:r,loading:N,empty:u,emptyText:y}){const{t:h}=B();return e.jsxs("div",{className:l(x,"space-y-4 p-6"),children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-50",children:a}),N?e.jsx("div",{className:ce,children:e.jsx("span",{className:l(c,"text-sm"),children:h("common.loadingShort")})}):u?e.jsx("div",{className:de,children:e.jsx("span",{className:l(c,"text-sm"),children:y})}):e.jsx(pe,{option:r,style:{height:280},notMerge:!0,lazyUpdate:!0,className:oe})]})}export{Me as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,d as c,M as i,H as p,k as b}from"./index-
|
|
1
|
+
import{j as s,d as c,M as i,H as p,k as b}from"./index-Dz1s8uzG.js";function h({variant:n="subtle",size:o="md",children:a,loading:t,icon:e,className:l,disabled:r,...u}){const m={subtle:b,primary:p,danger:i}[n],x={sm:"h-8 px-3 text-xs",md:"h-10 px-4 text-sm",lg:"h-12 px-6 text-base"}[o];return s.jsx("button",{className:c(m,x,t&&"cursor-wait opacity-70",r&&"cursor-not-allowed opacity-50",l),disabled:r||t,...u,children:t?s.jsx("div",{className:"inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-current"}):e?s.jsxs(s.Fragment,{children:[e,a]}):a})}export{h as B};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as O,u as q,a as te,r as h,b as se,t as ae,j as e,L as re,B,d as o,m as g,g as z,e as $,f as G,h as oe,l as _,s as le,i as M,k as ie,n as P}from"./index-
|
|
1
|
+
import{c as O,u as q,a as te,r as h,b as se,t as ae,j as e,L as re,B,d as o,m as g,g as z,e as $,f as G,h as oe,l as _,s as le,i as M,k as ie,n as P}from"./index-Dz1s8uzG.js";import{E as ne}from"./index-DUQNG-qd.js";import{P as de,a as H}from"./PageSection-Ce8cXojT.js";import{S as ce}from"./Input-DwLjINOT.js";import{S as me}from"./StatusBadge-DnIFGtUc.js";import{u as C}from"./useApiQuery-BA98Vr2f.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as p,u as E,a as S,r as n,j as e,k as h,d as b,v as R,w as L,t as $,i as k}from"./index-
|
|
1
|
+
import{c as p,u as E,a as S,r as n,j as e,k as h,d as b,v as R,w as L,t as $,i as k}from"./index-Dz1s8uzG.js";import{R as z}from"./refresh-cw-DDXCOeFJ.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,d,T as m,U as x}from"./index-
|
|
1
|
+
import{j as s,d,T as m,U as x}from"./index-Dz1s8uzG.js";function i({label:a,children:l,className:t,required:r,error:e}){return s.jsxs("div",{className:d(x,t),children:[s.jsxs("label",{className:m,children:[a,r&&s.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),l,e&&s.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:e})]})}export{i as F};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as u,u as p,r as b,j as e,d as x,m}from"./index-
|
|
1
|
+
import{c as u,u as p,r as b,j as e,d as x,m}from"./index-Dz1s8uzG.js";import{P as g,a as o}from"./PageSection-Ce8cXojT.js";import{I as j}from"./info-B4aq_I9e.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as d,j as e,d as n,O as c,N as i}from"./index-
|
|
1
|
+
import{r as d,j as e,d as n,O as c,N as i}from"./index-Dz1s8uzG.js";const f=d.forwardRef(({options:t,placeholder:s,className:r,...l},u)=>e.jsxs("select",{ref:u,className:n(c,r),...l,children:[s&&e.jsx("option",{value:"",disabled:!0,children:s}),t.map(a=>e.jsx("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})),j=d.forwardRef(({variant:t="default",className:s,...r},l)=>e.jsx("input",{ref:l,className:n(i,s),...r}));export{j as I,f as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as y,aa as E,ab as C,ac as S,r as l,j as e,d,L as _,m as j,N as v,H as L}from"./index-
|
|
1
|
+
import{u as y,aa as E,ab as C,ac as S,r as l,j as e,d,L as _,m as j,N as v,H as L}from"./index-Dz1s8uzG.js";function P(){const{t:a}=y(),o=E(),m=C(),{authEnabled:n,isAuthenticated:x,loading:i,login:k,error:b}=S(),[r,h]=l.useState({username:"",password:""}),[f,u]=l.useState(null),[p,g]=l.useState(!1),c=l.useMemo(()=>{var t;const s=m.state;return((t=s==null?void 0:s.from)==null?void 0:t.pathname)??"/"},[m.state]);l.useEffect(()=>{if(!n&&!i){o(c,{replace:!0});return}n&&x&&!i&&o(c,{replace:!0})},[n,x,i,o,c]);const N=async s=>{if(s.preventDefault(),u(null),!r.username.trim()||!r.password){u(a("login.validation.required"));return}g(!0);try{await k(r.username.trim(),r.password),o(c,{replace:!0})}catch(t){u(t instanceof Error?t.message:a("login.validation.failed"))}finally{g(!1)}},w=s=>e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-slate-100 via-white to-slate-200 px-4 dark:from-slate-950/95 dark:via-slate-950 dark:to-slate-900",children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0",children:[e.jsx("div",{className:"absolute left-10 top-20 h-48 w-48 rounded-full bg-slate-200/40 blur-3xl dark:bg-slate-700/30"}),e.jsx("div",{className:"absolute right-16 bottom-32 h-56 w-56 rounded-full bg-slate-300/35 blur-3xl dark:bg-slate-800/30"}),e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_top,_rgba(15,23,42,0.08),_transparent_55%)]"})]}),e.jsx("div",{className:"relative z-10 w-full max-w-lg",children:s})]});return i?w(e.jsx("div",{className:"flex min-h-[320px] items-center justify-center rounded-3xl border border-blue-200/60 bg-white/90 shadow-2xl shadow-blue-200/50 backdrop-blur-xl dark:border-slate-800/50 dark:bg-slate-900/80 dark:shadow-slate-900/60",children:e.jsx(_,{})})):n?w(e.jsxs("main",{className:"rounded-3xl border border-slate-200/70 bg-white/95 px-8 pb-10 pt-9 shadow-2xl shadow-slate-200/40 backdrop-blur-xl dark:border-slate-800/60 dark:bg-slate-900/85 dark:shadow-slate-900/60",children:[e.jsxs("header",{className:"mb-8 flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-slate-900 via-slate-800 to-slate-700 text-xl font-bold text-white shadow-lg shadow-slate-400/30 dark:from-blue-500 dark:via-blue-600 dark:to-indigo-600 dark:shadow-blue-900/40",children:"GW"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-2xl font-semibold text-slate-900 dark:text-slate-50",children:a("login.title")}),e.jsx("p",{className:d(j,"text-sm leading-relaxed max-w-[360px]"),children:a("login.description")})]})]}),e.jsxs("form",{className:"space-y-5",onSubmit:N,children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.username")}),e.jsx("input",{value:r.username,autoComplete:"username",autoFocus:!0,onChange:s=>h(t=>({...t,username:s.target.value})),placeholder:a("login.fields.usernamePlaceholder"),className:d(v,"h-11 font-medium")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.password")}),e.jsx("input",{type:"password",value:r.password,autoComplete:"current-password",onChange:s=>h(t=>({...t,password:s.target.value})),placeholder:a("login.fields.passwordPlaceholder"),className:d(v,"h-11")})]}),f||b?e.jsx("div",{className:"rounded-2xl border border-red-200/70 bg-red-50/80 px-4 py-3 text-sm font-medium text-red-600 shadow-sm shadow-red-200/40 dark:border-red-500/40 dark:bg-red-500/15 dark:text-red-100",children:f||b}):null,e.jsx("button",{type:"submit",className:d(L,"w-full justify-center rounded-full py-3 text-sm font-semibold"),disabled:p,children:a(p?"common.actions.loading":"login.actions.submit")})]}),e.jsx("footer",{className:"mt-7 text-center text-xs",children:e.jsx("p",{className:d(j,"leading-relaxed"),children:a("login.hint")})})]})):null}export{P as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-dFe_7qSp.js";import{u as K}from"./useApiQuery-i7GI_aGQ.js";import{P as _e,a as se}from"./PageSection-BJJ735Qk.js";import{F as T}from"./FormField-DKWx0tXD.js";import{S as I,I as W}from"./Input-Iev5RCKK.js";import{B as $}from"./Button-6f5FYqHp.js";import{S as de}from"./StatusBadge-9lxhNpvi.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function v(t){return t==null?"-":t.toLocaleString()}function w(t,r){const n=v(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,_]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{_(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&_(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1380px",minWidth:"1380px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>_(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>_(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:s("logs.actions.detail")})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,_;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:w(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:w(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:w(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:w(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:w(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((_=a.payload)==null?void 0:_.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};
|
|
1
|
+
import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-Dz1s8uzG.js";import{u as K}from"./useApiQuery-BA98Vr2f.js";import{P as _e,a as se}from"./PageSection-Ce8cXojT.js";import{F as T}from"./FormField-D6CVd30C.js";import{S as I,I as W}from"./Input-DwLjINOT.js";import{B as $}from"./Button-CK3N5RnJ.js";import{S as de}from"./StatusBadge-DnIFGtUc.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function v(t){return t==null?"-":t.toLocaleString()}function w(t,r){const n=v(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,_]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{_(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&_(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1380px",minWidth:"1380px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>_(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>_(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:s("logs.actions.detail")})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,_;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:w(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:w(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:w(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:w(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:w(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((_=a.payload)==null?void 0:_.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};
|