@chenpu17/cc-gw 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/web/dist/assets/{About-DWr_0zUb.js → About-Cgfq_d7I.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-45nn2Z53.js → ApiKeys-C4QbVKdv.js} +1 -1
- package/src/web/dist/assets/{Dashboard-ixJ72-sA.js → Dashboard-28JGQst7.js} +1 -1
- package/src/web/dist/assets/{Help-Badmmw97.js → Help-BojpuZMh.js} +1 -1
- package/src/web/dist/assets/{Logs-BufGG-m_.js → Logs-B1rVvkYR.js} +1 -1
- package/src/web/dist/assets/{ModelManagement-Br1rWj5I.js → ModelManagement-DIMCLs1b.js} +1 -1
- package/src/web/dist/assets/{Settings-CQatmqRt.js → Settings-CB4YZNh9.js} +1 -1
- package/src/web/dist/assets/{index-xwXTrmLG.js → index-B0rGDFRO.js} +1 -1
- package/src/web/dist/assets/{index-Jqz_kqzz.js → index-wA9rsqII.js} +2 -2
- package/src/web/dist/assets/{useApiQuery-BigNbUj6.js → useApiQuery-De0jYBDD.js} +1 -1
- package/src/web/dist/index.html +1 -1
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as x,a as p,r as o,j as e}from"./index-
|
|
1
|
+
import{u as x,a as p,r as o,j as e}from"./index-wA9rsqII.js";import{u as m}from"./useApiQuery-De0jYBDD.js";const h="0.3.6",v={version:h},g={};function N(){const{t:s}=x(),{pushToast:l}=p(),t=m(["status","gateway"],{url:"/api/status",method:"GET"},{staleTime:6e4});o.useEffect(()=>{t.isError&&t.error&&l({title:s("about.toast.statusError.title"),description:t.error.message,variant:"error"})},[t.isError,t.error,l,s]);const d=v.version,r=o.useMemo(()=>{const a=g,u=a.VITE_BUILD_TIME??"-",b=a.VITE_NODE_VERSION??"-";return{buildTime:u,nodeVersion:b}},[]),i=()=>{l({title:s("about.toast.updatesPlanned"),variant:"info"})},n=[{label:s("about.app.labels.name"),value:"cc-local-gw"},{label:s("about.app.labels.version"),value:d},{label:s("about.app.labels.buildTime"),value:r.buildTime},{label:s("about.app.labels.node"),value:r.nodeVersion}],c=t.data?[{label:s("about.status.labels.host"),value:t.data.host??"127.0.0.1"},{label:s("about.status.labels.port"),value:t.data.port},{label:s("about.status.labels.providers"),value:t.data.providers},{label:s("about.status.labels.active"),value:t.data.activeRequests??0}]:[];return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:s("about.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:s("about.description")})]}),e.jsxs("section",{className:"grid gap-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("about.app.title")}),e.jsx("dl",{className:"grid grid-cols-[160px_1fr] gap-2 text-sm text-slate-600 dark:text-slate-300",children:n.map(a=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-medium",children:a.label}),e.jsx("dd",{children:a.value})]},a.label))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("about.status.title")}),t.isLoading?e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:s("about.status.loading")}):t.data?e.jsx("dl",{className:"grid grid-cols-[160px_1fr] gap-2 text-sm text-slate-600 dark:text-slate-300",children:c.map(a=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-medium",children:a.label}),e.jsx("dd",{children:a.value})]},a.label))}):e.jsx("p",{className:"text-sm text-red-500",children:s("about.status.empty")})]})]}),e.jsxs("section",{className:"rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("about.support.title")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("about.support.subtitle")})]}),e.jsx("button",{type:"button",onClick:i,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("about.support.actions.checkUpdates")})]}),e.jsx("p",{className:"mt-4 text-sm leading-6 text-slate-600 dark:text-slate-300",children:s("about.support.description")})]})]})}export{N as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as g,u as R,a as U,r as d,j as e,L as k,K as W}from"./index-
|
|
1
|
+
import{c as g,u as R,a as U,r as d,j as e,L as k,K as W}from"./index-wA9rsqII.js";import{E as L}from"./index-B0rGDFRO.js";import{u as N,a as v}from"./useApiQuery-De0jYBDD.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{u as A,a as R,r as h,j as t,L as D}from"./index-Jqz_kqzz.js";import{E as O}from"./index-xwXTrmLG.js";import{u as v}from"./useApiQuery-BigNbUj6.js";function N(e,a,s){return e==null?"-":`${e.toLocaleString(void 0,s)} ${a}`}function B(e){if(e==null)return"-";if(e<1024)return`${e} B`;const a=["KB","MB","GB","TB"];let s=e/1024,d=0;for(;s>=1024&&d<a.length-1;)s/=1024,d+=1;return`${s.toFixed(s>=100?0:s>=10?1:2)} ${a[d]}`}function _(){var S;const{t:e}=A(),{pushToast:a}=R(),[s,d]=h.useState("all"),l=s==="all"?void 0:s,b=v(["stats","overview",s],{url:"/api/stats/overview",method:"GET",params:l?{endpoint:l}:void 0}),p=v(["stats","daily",14,s],{url:"/api/stats/daily",method:"GET",params:{days:14,...l?{endpoint:l}:{}}}),u=v(["stats","model",7,6,s],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...l?{endpoint:l}:{}}}),g=v(["status"],{url:"/api/status",method:"GET"}),f=v(["db","info"],{url:"/api/db/info",method:"GET"}),y=v(["logs","recent",s],{url:"/api/logs",method:"GET",params:{limit:5,...l?{endpoint:l}:{}}},{refetchInterval:3e4});h.useEffect(()=>{b.isError&&b.error&&a({title:e("dashboard.toast.overviewError"),description:b.error.message,variant:"error"})},[b.isError,b.error,a,e]),h.useEffect(()=>{p.isError&&p.error&&a({title:e("dashboard.toast.dailyError"),description:p.error.message,variant:"error"})},[p.isError,p.error,a,e]),h.useEffect(()=>{u.isError&&u.error&&a({title:e("dashboard.toast.modelError"),description:u.error.message,variant:"error"})},[u.isError,u.error,a,e]),h.useEffect(()=>{g.isError&&g.error&&a({title:e("dashboard.toast.statusError"),description:g.error.message,variant:"error"})},[g.isError,g.error,a,e]),h.useEffect(()=>{f.isError&&f.error&&a({title:e("dashboard.toast.dbError"),description:f.error.message,variant:"error"})},[f.isError,f.error,a,e]),h.useEffect(()=>{y.isError&&y.error&&a({title:e("dashboard.toast.recentError"),description:y.error.message,variant:"error"})},[y.isError,y.error,a,e]);const c=b.data,j=p.data??[],n=u.data??[],k=g.data,M=f.data,$=((S=y.data)==null?void 0:S.items)??[],q=h.useMemo(()=>{const i=j.map(o=>o.date),x=e("dashboard.charts.barRequests"),r=e("dashboard.charts.lineInput"),m=e("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[x,r,m]},grid:{left:40,right:20,top:40,bottom:40},xAxis:{type:"category",data:i},yAxis:{type:"value"},series:[{name:x,type:"bar",data:j.map(o=>o.requestCount),itemStyle:{color:"#2563eb"}},{name:r,type:"line",yAxisIndex:0,data:j.map(o=>o.inputTokens),smooth:!0,itemStyle:{color:"#22c55e"}},{name:m,type:"line",yAxisIndex:0,data:j.map(o=>o.outputTokens),smooth:!0,itemStyle:{color:"#f97316"}}]}},[j,e]),w=h.useMemo(()=>{const i=n.map(o=>`${o.provider}/${o.model}`),x=e("dashboard.charts.barRequests"),r=e("dashboard.charts.lineInput"),m=e("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[x,r,m]},grid:{left:50,right:40,top:40,bottom:70},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:[{type:"value",name:x},{type:"value",name:e("dashboard.charts.axisTokens"),position:"right"}],series:[{name:x,type:"bar",data:n.map(o=>o.requests),itemStyle:{color:"#6366f1"},yAxisIndex:0},{name:r,type:"line",yAxisIndex:1,smooth:!0,data:n.map(o=>o.inputTokens??0),itemStyle:{color:"#22c55e"}},{name:m,type:"line",yAxisIndex:1,smooth:!0,data:n.map(o=>o.outputTokens??0),itemStyle:{color:"#f97316"}}]}},[n,e]),I=h.useMemo(()=>{const i=n.map(r=>`${r.provider}/${r.model}`),x=e("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis",formatter(r){var T;if(!Array.isArray(r)||r.length===0)return"";const m=((T=r[0])==null?void 0:T.dataIndex)??0,o=n[m];return o?`<strong>${i[m]}</strong><br/>${x}: ${N(o.avgTtftMs,e("common.units.ms"))}`:""}},grid:{left:50,right:30,top:40,bottom:70},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:{type:"value",name:e("dashboard.charts.ttftAxis")},series:[{name:x,type:"bar",data:n.map(r=>r.avgTtftMs??0),itemStyle:{color:"#2563eb"}}]}},[n,e]),P=h.useMemo(()=>{const i=n.map(r=>`${r.provider}/${r.model}`),x=e("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis",formatter(r){var T;if(!Array.isArray(r)||r.length===0)return"";const m=((T=r[0])==null?void 0:T.dataIndex)??0,o=n[m];return o?`<strong>${i[m]}</strong><br/>${x}: ${N(o.avgTpotMs,e("common.units.msPerToken"),{maximumFractionDigits:2})}`:""}},grid:{left:50,right:30,top:40,bottom:70},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:{type:"value",name:e("dashboard.charts.tpotAxis")},series:[{name:x,type:"bar",data:n.map(r=>r.avgTpotMs??0),itemStyle:{color:"#f97316"}}]}},[n,e]);return b.isPending||g.isPending||f.isPending?t.jsx(D,{}):t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h1",{className:"text-2xl font-semibold",children:e("nav.dashboard")}),t.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:e("dashboard.description")}),k?t.jsxs("div",{className:"flex flex-wrap gap-3 rounded-lg border border-slate-200 bg-white p-4 text-sm shadow-sm dark:border-slate-800 dark:bg-slate-900","aria-live":"polite",children:[t.jsx("span",{className:"font-medium",children:e("dashboard.status.listening",{host:k.host??"0.0.0.0",port:k.port})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.providers",{value:k.providers})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.todayRequests",{value:((c==null?void 0:c.today.requests)??0).toLocaleString()})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.active",{value:(k.activeRequests??0).toLocaleString()})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.dbSize",{value:M?B(M.sizeBytes):"-"})})]}):null,t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[t.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:e("dashboard.filters.endpoint")}),t.jsxs("select",{value:s,onChange:i=>d(i.target.value),className:"h-9 rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:[t.jsx("option",{value:"all",children:e("dashboard.filters.endpointAll")}),t.jsx("option",{value:"anthropic",children:e("dashboard.filters.endpointAnthropic")}),t.jsx("option",{value:"openai",children:e("dashboard.filters.endpointOpenAI")})]})]})]}),t.jsxs("section",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[t.jsx(E,{title:e("dashboard.cards.todayRequests"),value:(c==null?void 0:c.today.requests)??0,suffix:e("common.units.request")}),t.jsx(E,{title:e("dashboard.cards.todayInput"),value:(c==null?void 0:c.today.inputTokens)??0,suffix:e("common.units.token")}),t.jsx(E,{title:e("dashboard.cards.todayOutput"),value:(c==null?void 0:c.today.outputTokens)??0,suffix:e("common.units.token")}),t.jsx(E,{title:e("dashboard.cards.avgLatency"),value:(c==null?void 0:c.today.avgLatencyMs)??0,suffix:e("common.units.ms")})]}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[t.jsx(L,{title:e("dashboard.charts.requestsTitle"),description:e("dashboard.charts.requestsDesc"),loading:p.isPending,option:q,empty:!j.length,emptyText:e("dashboard.charts.empty")}),t.jsx(L,{title:e("dashboard.charts.modelTitle"),description:e("dashboard.charts.modelDesc"),loading:u.isPending,option:w,empty:!n.length,emptyText:e("dashboard.charts.empty")})]}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[t.jsx(L,{title:e("dashboard.charts.ttftTitle"),description:e("dashboard.charts.ttftDesc"),loading:u.isPending,option:I,empty:!n.some(i=>i.avgTtftMs!=null&&i.avgTtftMs>0),emptyText:e("dashboard.charts.ttftEmpty")}),t.jsx(L,{title:e("dashboard.charts.tpotTitle"),description:e("dashboard.charts.tpotDesc"),loading:u.isPending,option:P,empty:!n.some(i=>i.avgTpotMs!=null&&i.avgTpotMs>0),emptyText:e("dashboard.charts.tpotEmpty")})]}),t.jsx(G,{models:n,loading:u.isPending}),t.jsx(Q,{loading:y.isPending,records:$})]})}function E({title:e,value:a,suffix:s}){return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:e}),t.jsxs("p",{className:"mt-2 text-2xl font-semibold",children:[a.toLocaleString(),s?t.jsx("span",{className:"ml-1 text-base font-normal text-slate-500 dark:text-slate-400",children:s}):null]})]})}function L({title:e,description:a,option:s,loading:d,empty:l,emptyText:b}){const{t:p}=A();return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-sm font-semibold",children:e}),t.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:a})]}),d?t.jsx("div",{className:"flex h-60 items-center justify-center text-sm text-slate-400",children:p("common.loadingShort")}):l?t.jsx("div",{className:"flex h-60 items-center justify-center text-sm text-slate-400",children:b??p("dashboard.charts.empty")}):t.jsx(O,{option:s,style:{height:260},notMerge:!0,lazyUpdate:!0,theme:void 0})]})}function G({models:e,loading:a}){const{t:s}=A(),d=e.length>0;return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsx("div",{className:"flex items-center justify-between border-b border-slate-200 px-4 py-3 dark:border-slate-800",children:t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold",children:s("dashboard.modelTable.title")}),t.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.description")})]})}),a?t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("common.loadingShort")}):d?t.jsx("div",{className:"max-h-80 overflow-x-auto",children:t.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[t.jsx("caption",{className:"sr-only",children:s("dashboard.modelTable.title")}),t.jsx("thead",{className:"bg-slate-100 dark:bg-slate-800/50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.model")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.requests")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.latency")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.ttft")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.tpot")})]})}),t.jsx("tbody",{className:"divide-y divide-slate-200 dark:divide-slate-800",children:e.map(l=>t.jsxs("tr",{className:"hover:bg-slate-50 dark:hover:bg-slate-800/60",children:[t.jsx("td",{className:"px-4 py-2",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-100",children:l.provider}),t.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:l.model})]})}),t.jsx("td",{className:"px-4 py-2 text-right",children:l.requests.toLocaleString()}),t.jsx("td",{className:"px-4 py-2 text-right",children:N(l.avgLatencyMs,s("common.units.ms"))}),t.jsx("td",{className:"px-4 py-2 text-right",children:N(l.avgTtftMs,s("common.units.ms"))}),t.jsx("td",{className:"px-4 py-2 text-right",children:N(l.avgTpotMs,s("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${l.provider}/${l.model}`))})]})}):t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("dashboard.modelTable.empty")})]})}function Q({records:e,loading:a}){const{t:s}=A();return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200 px-4 py-3 dark:border-slate-800",children:[t.jsx("p",{className:"text-sm font-semibold",children:s("dashboard.recent.title")}),t.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("dashboard.recent.subtitle",{count:5})})]}),a?t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("dashboard.recent.loading")}):e.length===0?t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("dashboard.recent.empty")}):t.jsx("div",{className:"max-h-80 overflow-auto",children:t.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[t.jsx("caption",{className:"sr-only",children:s("dashboard.recent.title")}),t.jsx("thead",{className:"bg-slate-100 dark:bg-slate-800/50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.time")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.endpoint")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.provider")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.route")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.latency")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.status")})]})}),t.jsx("tbody",{className:"divide-y divide-slate-200 dark:divide-slate-800",children:e.map(d=>t.jsxs("tr",{className:"hover:bg-slate-50 dark:hover:bg-slate-800/60",children:[t.jsx("td",{className:"px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:new Date(d.timestamp).toLocaleString()}),t.jsx("td",{className:"px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:d.endpoint==="anthropic"?s("logs.table.endpointAnthropic"):d.endpoint==="openai"?s("logs.table.endpointOpenAI"):d.endpoint}),t.jsx("td",{className:"px-4 py-2",children:d.provider}),t.jsxs("td",{className:"px-4 py-2",children:[t.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:d.client_model??s("dashboard.recent.routePlaceholder")}),t.jsx("span",{className:"mx-1 text-slate-400",children:"→"}),t.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-100",children:d.model})]}),t.jsx("td",{className:"px-4 py-2",children:N(d.latency_ms,s("common.units.ms"))}),t.jsx("td",{className:"px-4 py-2",children:t.jsxs("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${d.error?"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-200":"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200"}`,children:[(d.status_code??200).toString(),t.jsx("span",{className:"ml-1",children:d.error?s("common.status.error"):s("common.status.success")})]})})]},d.id))})]})})]})}export{_ as default};
|
|
1
|
+
import{u as A,a as R,r as h,j as t,L as D}from"./index-wA9rsqII.js";import{E as O}from"./index-B0rGDFRO.js";import{u as v}from"./useApiQuery-De0jYBDD.js";function N(e,a,s){return e==null?"-":`${e.toLocaleString(void 0,s)} ${a}`}function B(e){if(e==null)return"-";if(e<1024)return`${e} B`;const a=["KB","MB","GB","TB"];let s=e/1024,d=0;for(;s>=1024&&d<a.length-1;)s/=1024,d+=1;return`${s.toFixed(s>=100?0:s>=10?1:2)} ${a[d]}`}function _(){var S;const{t:e}=A(),{pushToast:a}=R(),[s,d]=h.useState("all"),l=s==="all"?void 0:s,b=v(["stats","overview",s],{url:"/api/stats/overview",method:"GET",params:l?{endpoint:l}:void 0}),p=v(["stats","daily",14,s],{url:"/api/stats/daily",method:"GET",params:{days:14,...l?{endpoint:l}:{}}}),u=v(["stats","model",7,6,s],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...l?{endpoint:l}:{}}}),g=v(["status"],{url:"/api/status",method:"GET"}),f=v(["db","info"],{url:"/api/db/info",method:"GET"}),y=v(["logs","recent",s],{url:"/api/logs",method:"GET",params:{limit:5,...l?{endpoint:l}:{}}},{refetchInterval:3e4});h.useEffect(()=>{b.isError&&b.error&&a({title:e("dashboard.toast.overviewError"),description:b.error.message,variant:"error"})},[b.isError,b.error,a,e]),h.useEffect(()=>{p.isError&&p.error&&a({title:e("dashboard.toast.dailyError"),description:p.error.message,variant:"error"})},[p.isError,p.error,a,e]),h.useEffect(()=>{u.isError&&u.error&&a({title:e("dashboard.toast.modelError"),description:u.error.message,variant:"error"})},[u.isError,u.error,a,e]),h.useEffect(()=>{g.isError&&g.error&&a({title:e("dashboard.toast.statusError"),description:g.error.message,variant:"error"})},[g.isError,g.error,a,e]),h.useEffect(()=>{f.isError&&f.error&&a({title:e("dashboard.toast.dbError"),description:f.error.message,variant:"error"})},[f.isError,f.error,a,e]),h.useEffect(()=>{y.isError&&y.error&&a({title:e("dashboard.toast.recentError"),description:y.error.message,variant:"error"})},[y.isError,y.error,a,e]);const c=b.data,j=p.data??[],n=u.data??[],k=g.data,M=f.data,$=((S=y.data)==null?void 0:S.items)??[],q=h.useMemo(()=>{const i=j.map(o=>o.date),x=e("dashboard.charts.barRequests"),r=e("dashboard.charts.lineInput"),m=e("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[x,r,m]},grid:{left:40,right:20,top:40,bottom:40},xAxis:{type:"category",data:i},yAxis:{type:"value"},series:[{name:x,type:"bar",data:j.map(o=>o.requestCount),itemStyle:{color:"#2563eb"}},{name:r,type:"line",yAxisIndex:0,data:j.map(o=>o.inputTokens),smooth:!0,itemStyle:{color:"#22c55e"}},{name:m,type:"line",yAxisIndex:0,data:j.map(o=>o.outputTokens),smooth:!0,itemStyle:{color:"#f97316"}}]}},[j,e]),w=h.useMemo(()=>{const i=n.map(o=>`${o.provider}/${o.model}`),x=e("dashboard.charts.barRequests"),r=e("dashboard.charts.lineInput"),m=e("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[x,r,m]},grid:{left:50,right:40,top:40,bottom:70},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:[{type:"value",name:x},{type:"value",name:e("dashboard.charts.axisTokens"),position:"right"}],series:[{name:x,type:"bar",data:n.map(o=>o.requests),itemStyle:{color:"#6366f1"},yAxisIndex:0},{name:r,type:"line",yAxisIndex:1,smooth:!0,data:n.map(o=>o.inputTokens??0),itemStyle:{color:"#22c55e"}},{name:m,type:"line",yAxisIndex:1,smooth:!0,data:n.map(o=>o.outputTokens??0),itemStyle:{color:"#f97316"}}]}},[n,e]),I=h.useMemo(()=>{const i=n.map(r=>`${r.provider}/${r.model}`),x=e("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis",formatter(r){var T;if(!Array.isArray(r)||r.length===0)return"";const m=((T=r[0])==null?void 0:T.dataIndex)??0,o=n[m];return o?`<strong>${i[m]}</strong><br/>${x}: ${N(o.avgTtftMs,e("common.units.ms"))}`:""}},grid:{left:50,right:30,top:40,bottom:70},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:{type:"value",name:e("dashboard.charts.ttftAxis")},series:[{name:x,type:"bar",data:n.map(r=>r.avgTtftMs??0),itemStyle:{color:"#2563eb"}}]}},[n,e]),P=h.useMemo(()=>{const i=n.map(r=>`${r.provider}/${r.model}`),x=e("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis",formatter(r){var T;if(!Array.isArray(r)||r.length===0)return"";const m=((T=r[0])==null?void 0:T.dataIndex)??0,o=n[m];return o?`<strong>${i[m]}</strong><br/>${x}: ${N(o.avgTpotMs,e("common.units.msPerToken"),{maximumFractionDigits:2})}`:""}},grid:{left:50,right:30,top:40,bottom:70},xAxis:{type:"category",data:i,axisLabel:{rotate:30}},yAxis:{type:"value",name:e("dashboard.charts.tpotAxis")},series:[{name:x,type:"bar",data:n.map(r=>r.avgTpotMs??0),itemStyle:{color:"#f97316"}}]}},[n,e]);return b.isPending||g.isPending||f.isPending?t.jsx(D,{}):t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h1",{className:"text-2xl font-semibold",children:e("nav.dashboard")}),t.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:e("dashboard.description")}),k?t.jsxs("div",{className:"flex flex-wrap gap-3 rounded-lg border border-slate-200 bg-white p-4 text-sm shadow-sm dark:border-slate-800 dark:bg-slate-900","aria-live":"polite",children:[t.jsx("span",{className:"font-medium",children:e("dashboard.status.listening",{host:k.host??"0.0.0.0",port:k.port})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.providers",{value:k.providers})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.todayRequests",{value:((c==null?void 0:c.today.requests)??0).toLocaleString()})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.active",{value:(k.activeRequests??0).toLocaleString()})}),t.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:e("dashboard.status.dbSize",{value:M?B(M.sizeBytes):"-"})})]}):null,t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[t.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:e("dashboard.filters.endpoint")}),t.jsxs("select",{value:s,onChange:i=>d(i.target.value),className:"h-9 rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:[t.jsx("option",{value:"all",children:e("dashboard.filters.endpointAll")}),t.jsx("option",{value:"anthropic",children:e("dashboard.filters.endpointAnthropic")}),t.jsx("option",{value:"openai",children:e("dashboard.filters.endpointOpenAI")})]})]})]}),t.jsxs("section",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[t.jsx(E,{title:e("dashboard.cards.todayRequests"),value:(c==null?void 0:c.today.requests)??0,suffix:e("common.units.request")}),t.jsx(E,{title:e("dashboard.cards.todayInput"),value:(c==null?void 0:c.today.inputTokens)??0,suffix:e("common.units.token")}),t.jsx(E,{title:e("dashboard.cards.todayOutput"),value:(c==null?void 0:c.today.outputTokens)??0,suffix:e("common.units.token")}),t.jsx(E,{title:e("dashboard.cards.avgLatency"),value:(c==null?void 0:c.today.avgLatencyMs)??0,suffix:e("common.units.ms")})]}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[t.jsx(L,{title:e("dashboard.charts.requestsTitle"),description:e("dashboard.charts.requestsDesc"),loading:p.isPending,option:q,empty:!j.length,emptyText:e("dashboard.charts.empty")}),t.jsx(L,{title:e("dashboard.charts.modelTitle"),description:e("dashboard.charts.modelDesc"),loading:u.isPending,option:w,empty:!n.length,emptyText:e("dashboard.charts.empty")})]}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[t.jsx(L,{title:e("dashboard.charts.ttftTitle"),description:e("dashboard.charts.ttftDesc"),loading:u.isPending,option:I,empty:!n.some(i=>i.avgTtftMs!=null&&i.avgTtftMs>0),emptyText:e("dashboard.charts.ttftEmpty")}),t.jsx(L,{title:e("dashboard.charts.tpotTitle"),description:e("dashboard.charts.tpotDesc"),loading:u.isPending,option:P,empty:!n.some(i=>i.avgTpotMs!=null&&i.avgTpotMs>0),emptyText:e("dashboard.charts.tpotEmpty")})]}),t.jsx(G,{models:n,loading:u.isPending}),t.jsx(Q,{loading:y.isPending,records:$})]})}function E({title:e,value:a,suffix:s}){return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:e}),t.jsxs("p",{className:"mt-2 text-2xl font-semibold",children:[a.toLocaleString(),s?t.jsx("span",{className:"ml-1 text-base font-normal text-slate-500 dark:text-slate-400",children:s}):null]})]})}function L({title:e,description:a,option:s,loading:d,empty:l,emptyText:b}){const{t:p}=A();return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-sm font-semibold",children:e}),t.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:a})]}),d?t.jsx("div",{className:"flex h-60 items-center justify-center text-sm text-slate-400",children:p("common.loadingShort")}):l?t.jsx("div",{className:"flex h-60 items-center justify-center text-sm text-slate-400",children:b??p("dashboard.charts.empty")}):t.jsx(O,{option:s,style:{height:260},notMerge:!0,lazyUpdate:!0,theme:void 0})]})}function G({models:e,loading:a}){const{t:s}=A(),d=e.length>0;return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsx("div",{className:"flex items-center justify-between border-b border-slate-200 px-4 py-3 dark:border-slate-800",children:t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold",children:s("dashboard.modelTable.title")}),t.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.description")})]})}),a?t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("common.loadingShort")}):d?t.jsx("div",{className:"max-h-80 overflow-x-auto",children:t.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[t.jsx("caption",{className:"sr-only",children:s("dashboard.modelTable.title")}),t.jsx("thead",{className:"bg-slate-100 dark:bg-slate-800/50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.model")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.requests")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.latency")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.ttft")}),t.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.modelTable.columns.tpot")})]})}),t.jsx("tbody",{className:"divide-y divide-slate-200 dark:divide-slate-800",children:e.map(l=>t.jsxs("tr",{className:"hover:bg-slate-50 dark:hover:bg-slate-800/60",children:[t.jsx("td",{className:"px-4 py-2",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-100",children:l.provider}),t.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:l.model})]})}),t.jsx("td",{className:"px-4 py-2 text-right",children:l.requests.toLocaleString()}),t.jsx("td",{className:"px-4 py-2 text-right",children:N(l.avgLatencyMs,s("common.units.ms"))}),t.jsx("td",{className:"px-4 py-2 text-right",children:N(l.avgTtftMs,s("common.units.ms"))}),t.jsx("td",{className:"px-4 py-2 text-right",children:N(l.avgTpotMs,s("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${l.provider}/${l.model}`))})]})}):t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("dashboard.modelTable.empty")})]})}function Q({records:e,loading:a}){const{t:s}=A();return t.jsxs("div",{className:"rounded-lg border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200 px-4 py-3 dark:border-slate-800",children:[t.jsx("p",{className:"text-sm font-semibold",children:s("dashboard.recent.title")}),t.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("dashboard.recent.subtitle",{count:5})})]}),a?t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("dashboard.recent.loading")}):e.length===0?t.jsx("div",{className:"flex h-40 items-center justify-center text-sm text-slate-400",children:s("dashboard.recent.empty")}):t.jsx("div",{className:"max-h-80 overflow-auto",children:t.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[t.jsx("caption",{className:"sr-only",children:s("dashboard.recent.title")}),t.jsx("thead",{className:"bg-slate-100 dark:bg-slate-800/50",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.time")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.endpoint")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.provider")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.route")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.latency")}),t.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:s("dashboard.recent.columns.status")})]})}),t.jsx("tbody",{className:"divide-y divide-slate-200 dark:divide-slate-800",children:e.map(d=>t.jsxs("tr",{className:"hover:bg-slate-50 dark:hover:bg-slate-800/60",children:[t.jsx("td",{className:"px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:new Date(d.timestamp).toLocaleString()}),t.jsx("td",{className:"px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:d.endpoint==="anthropic"?s("logs.table.endpointAnthropic"):d.endpoint==="openai"?s("logs.table.endpointOpenAI"):d.endpoint}),t.jsx("td",{className:"px-4 py-2",children:d.provider}),t.jsxs("td",{className:"px-4 py-2",children:[t.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:d.client_model??s("dashboard.recent.routePlaceholder")}),t.jsx("span",{className:"mx-1 text-slate-400",children:"→"}),t.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-100",children:d.model})]}),t.jsx("td",{className:"px-4 py-2",children:N(d.latency_ms,s("common.units.ms"))}),t.jsx("td",{className:"px-4 py-2",children:t.jsxs("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ${d.error?"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-200":"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200"}`,children:[(d.status_code??200).toString(),t.jsx("span",{className:"ml-1",children:d.error?s("common.status.error"):s("common.status.success")})]})})]},d.id))})]})})]})}export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as c,r as d,j as e}from"./index-
|
|
1
|
+
import{u as c,r as d,j as e}from"./index-wA9rsqII.js";function o(){const{t:s}=c(),a=d.useMemo(()=>{const t=s("help.sections.configuration.items",{returnObjects:!0}),l=s("help.sections.usage.items",{returnObjects:!0}),i=s("help.sections.tips.items",{returnObjects:!0});return[{title:s("help.sections.configuration.title"),items:t},{title:s("help.sections.usage.title"),items:l},{title:s("help.sections.tips.title"),items:i}]},[s]),r=s("help.faq.items",{returnObjects:!0});return e.jsxs("div",{className:"mx-auto flex max-w-4xl flex-col gap-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:s("help.title")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-300",children:s("help.intro")}),e.jsx("div",{className:"rounded-md border border-blue-100 bg-blue-50 px-4 py-3 text-xs text-blue-700 dark:border-blue-900/40 dark:bg-blue-950/60 dark:text-blue-200",children:s("help.note")})]}),a.map(t=>e.jsxs("section",{className:"space-y-3 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsx("h2",{className:"text-lg font-semibold",children:t.title}),e.jsx("ol",{className:"list-decimal space-y-2 pl-6 text-sm text-slate-700 dark:text-slate-300",children:t.items.map(l=>e.jsx("li",{children:l},l))})]},t.title)),e.jsxs("section",{className:"space-y-3 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("help.faq.title")}),e.jsx("dl",{className:"space-y-4 text-sm text-slate-700 dark:text-slate-300",children:r.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("dt",{className:"font-medium text-slate-900 dark:text-slate-100",children:t.q}),e.jsx("dd",{children:t.a})]},t.q))})]})]})}export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as L,a as J,r as d,j as e,b as ae,L as le}from"./index-Jqz_kqzz.js";import{u as C}from"./useApiQuery-BigNbUj6.js";const W=[20,50,100];function z(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,h=Date.parse(n);return Number.isFinite(h)?h:void 0}function Y(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 w(t){return t==null?"-":t.toLocaleString()}function N(t,r){const n=w(t);return n==="-"?"-":`${n} ${r}`}function P(t){return t?"true":"false"}function H(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 ce(){var B,G;const{t}=L(),{pushToast:r}=J(),[n,h]=d.useState("all"),[i,s]=d.useState("all"),[m,y]=d.useState(""),[p,c]=d.useState("all"),[b,a]=d.useState(""),[x,o]=d.useState(""),[f,v]=d.useState(1),[u,_]=d.useState(W[0]),[D,E]=d.useState(null),[V,R]=d.useState(!1),[T,A]=d.useState([]);d.useEffect(()=>{v(1)},[n,i,m,p,b,x,u,T]);const M=d.useMemo(()=>{const l={limit:u,offset:(f-1)*u};n!=="all"&&(l.provider=n),i!=="all"&&(l.endpoint=i),m.trim().length>0&&(l.model=m.trim()),p!=="all"&&(l.status=p);const j=z(b),Q=z(x,!0);return j!==void 0&&(l.from=j),Q!==void 0&&(l.to=Q),T.length>0&&(l.apiKeys=T.join(",")),l},[n,i,m,p,b,x,f,u,T]),g=C(["logs",M],{url:"/api/logs",method:"GET",params:M}),S=C(["providers","all"],{url:"/api/providers",method:"GET"}),q=C(["api-keys"],{url:"/api/keys",method:"GET"});d.useEffect(()=>{g.isError&&g.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:g.error.message}),variant:"error"})},[g.isError,g.error,r,t]),d.useEffect(()=>{S.isError&&S.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:S.error.message}),variant:"error"})},[S.isError,S.error,r,t]);const $=((B=g.data)==null?void 0:B.total)??0,k=$>0?Math.ceil($/u):0,O=((G=g.data)==null?void 0:G.items)??[];d.useEffect(()=>{k>0&&f>k&&v(k)},[k,f]);const F=S.data??[],U=d.useMemo(()=>{const l=new Map;for(const j of F)j.id&&l.set(j.id,j.label??j.id);return l},[F]),K=q.data??[],I=d.useMemo(()=>{const l=new Map;for(const j of K)l.set(j.id,j);return l},[K]),X=d.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),ee=()=>{h("all"),y(""),s("all"),c("all"),a(""),o(""),A([])},te=d.useCallback(l=>{E(l),R(!0)},[]),se=d.useCallback(()=>{R(!1),E(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:t("logs.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400","aria-live":"polite",children:[e.jsx("span",{children:t("logs.summary.total",{value:$.toLocaleString()})}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:()=>g.refetch(),disabled:g.isFetching,children:g.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.provider")}),e.jsxs("select",{value:n,onChange:l=>h(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:[e.jsx("option",{value:"all",children:t("logs.filters.providerAll")}),F.map(l=>e.jsx("option",{value:l.id,children:l.label??l.id},l.id))]})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.endpoint")}),e.jsxs("select",{value:i,onChange:l=>s(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:[e.jsx("option",{value:"all",children:t("logs.filters.endpointAll")}),e.jsx("option",{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx("option",{value:"openai",children:t("logs.filters.endpointOpenAI")})]})]}),e.jsx(oe,{apiKeys:K,selected:T,disabled:q.isLoading,onChange:A}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.modelId")}),e.jsx("input",{value:m,onChange:l=>y(l.target.value),placeholder:t("logs.filters.modelPlaceholder"),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40"})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.status")}),e.jsx("select",{value:p,onChange:l=>c(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:X.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.startDate")}),e.jsx("input",{type:"date",value:b,onChange:l=>a(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40"})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.endDate")}),e.jsx("input",{type:"date",value:x,onChange:l=>o(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40"})]}),e.jsx("div",{className:"ml-auto flex items-center gap-2 text-sm",children:e.jsx("button",{type:"button",onClick:ee,className:"rounded-md border border-slate-200 px-3 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:t("common.actions.reset")})})]})]}),e.jsxs("section",{className:"rounded-lg border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-slate-100 dark:bg-slate-800/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.cachedTokens")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.stream")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200 dark:divide-slate-800",children:g.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-4 py-10 text-center text-sm text-slate-400",children:t("logs.table.loading")})}):O.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-4 py-10 text-center text-sm text-slate-400",children:t("logs.table.empty")})}):O.map(l=>e.jsx(re,{record:l,providerLabelMap:U,apiKeyMap:I,onSelect:te},l.id))})]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-slate-200 px-4 py-3 text-sm dark:border-slate-800",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:u,onChange:l=>_(Number(l.target.value)),className:"rounded-md border border-slate-200 bg-white px-2 py-1 text-sm dark:border-slate-700 dark:bg-slate-800",children:W.map(l=>e.jsx("option",{value:l,children:l},l))}),e.jsx("span",{children:t("logs.table.pagination.unit")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>v(l=>Math.max(l-1,1)),disabled:f<=1,className:"rounded-md border border-slate-200 px-3 py-1 transition enabled:hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:enabled:hover:bg-slate-800",children:t("logs.table.pagination.previous")}),e.jsx("span",{children:t("logs.table.pagination.pageLabel",{page:k===0?0:f,total:k})}),e.jsx("button",{type:"button",onClick:()=>v(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||f>=k,className:"rounded-md border border-slate-200 px-3 py-1 transition enabled:hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:enabled:hover:bg-slate-800",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(de,{open:V,logId:D,onClose:se,providerLabelMap:U,apiKeyMap:I})]})}function re({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:h}){const{t:i}=L(),s=r.get(t.provider)??t.provider,m=t.endpoint||"-",y=!!t.error,p=t.client_model??i("logs.table.requestedModelFallback"),c=t.api_key_id!=null?n.get(t.api_key_id):void 0,b=t.api_key_id==null?i("logs.table.apiKeyUnknown"):c!=null&&c.isWildcard?i("apiKeys.wildcard"):c!=null&&c.name?c.name:t.api_key_name?t.api_key_name:i("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:"hover:bg-slate-50 dark:hover:bg-slate-800/60",children:[e.jsx("td",{className:"px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:Y(t.timestamp)}),e.jsx("td",{className:"px-4 py-2",children:m}),e.jsx("td",{className:"px-4 py-2",children:s}),e.jsx("td",{className:"px-4 py-2",children:p}),e.jsx("td",{className:"px-4 py-2",children:t.model}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("span",{className:"block truncate",title:b,children:b})}),e.jsx("td",{className:"px-4 py-2 text-right",children:w(t.input_tokens)}),e.jsx("td",{className:"px-4 py-2 text-right",children:w(t.cached_tokens)}),e.jsx("td",{className:"px-4 py-2 text-right",children:w(t.output_tokens)}),e.jsx("td",{className:"px-4 py-2 text-right",children:P(t.stream)}),e.jsx("td",{className:"px-4 py-2 text-right",children:N(t.latency_ms,i("common.units.ms"))}),e.jsx("td",{className:"px-4 py-2 text-right",children:N(t.ttft_ms,i("common.units.ms"))}),e.jsx("td",{className:"px-4 py-2 text-right",children:N(t.tpot_ms,i("common.units.msPerToken"))}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(Z,{success:!y,statusCode:t.status_code})}),e.jsx("td",{className:"max-w-xs px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:e.jsx("span",{className:"block truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("button",{type:"button",onClick:()=>h(t.id),"aria-haspopup":"dialog",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:i("logs.actions.detail")})})]})}function Z({success:t,statusCode:r}){const{t:n}=L(),h="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",i=t?"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200":"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-200";return e.jsxs("span",{className:`${h} ${i}`,children:[n(t?"common.status.success":"common.status.error"),r?` · ${r}`:""]})}function de({open:t,logId:r,onClose:n,providerLabelMap:h,apiKeyMap:i}){var f,v;const{t:s}=L(),{pushToast:m}=J(),y=d.useRef(null),p=d.useRef(null),c=C(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});d.useEffect(()=>{c.isError&&c.error&&m({title:s("logs.detail.loadError"),description:c.error.message,variant:"error"})},[c.isError,c.error,m,s]),d.useEffect(()=>{if(!t)return;const u=_=>{_.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[t,n]),d.useEffect(()=>{t&&p.current&&p.current.focus()},[t,r]);const b=d.useCallback(async(u,_,D)=>{if(!_){m({title:s("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await navigator.clipboard.writeText(_),m({title:s(D),variant:"success"})}catch(E){m({title:s("logs.detail.copy.failure"),description:E instanceof Error?E.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[m,s]);if(!t)return null;const a=c.data,x=a?h.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?i.get(a.api_key_id):void 0;return typeof document>"u"?null:ae.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:y,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-transform dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:p,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:c.isPending?e.jsx(le,{}):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:N(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:N(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:N(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:P(a.stream)})}),e.jsx(Z,{success:!a.error,statusCode:a.status_code})]}),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:Y(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:x})]}),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:P(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:w(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cachedTokens")}),e.jsx("dd",{className:"font-medium",children:w(a.cached_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:w(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:N(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:N(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:"flex items-center justify-between rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.raw")}),e.jsx("p",{className:"mt-1 text-xs",children:a.api_key_value?a.api_key_value:s("logs.detail.apiKey.rawUnavailable")})]}),e.jsx("button",{type:"button",disabled:!a.api_key_value,onClick:()=>b(s("logs.detail.apiKey.raw"),a.api_key_value,"logs.detail.copy.keySuccess"),className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 disabled:opacity-50 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var u;return b(s("logs.detail.payload.request"),(u=a.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:H((f=a.payload)==null?void 0:f.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var u;return b(s("logs.detail.payload.response"),(u=a.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:H((v=a.payload)==null?void 0:v.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 oe({apiKeys:t,selected:r,onChange:n,disabled:h}){const{t:i}=L(),[s,m]=d.useState(!1),y=d.useRef(null);d.useEffect(()=>{if(!s)return;const a=x=>{var o;(o=y.current)!=null&&o.contains(x.target)||m(!1)};return window.addEventListener("mousedown",a),()=>window.removeEventListener("mousedown",a)},[s]);const p=d.useMemo(()=>{if(r.length===0)return[];const a=new Map;for(const x of t)a.set(x.id,x);return r.map(x=>{const o=a.get(x);return o?o.isWildcard?i("apiKeys.wildcard"):o.name:null}).filter(x=>!!x)},[t,r,i]),c=r.length===0?i("logs.filters.apiKeyAll"):i("logs.filters.apiKeySelected",{count:r.length}),b=a=>{r.includes(a)?n(r.filter(x=>x!==a)):n([...r,a])};return e.jsxs("div",{className:"relative flex flex-col text-sm",ref:y,children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:i("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>m(a=>!a),disabled:h||t.length===0,title:i("logs.filters.apiKeyHint"),className:`flex w-48 items-center justify-between rounded-md border px-3 py-2 text-left text-sm transition focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:opacity-50 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:ring-blue-400/40 ${r.length>0?"border-blue-500 dark:border-blue-500":"border-slate-200"}`,"aria-haspopup":"listbox","aria-expanded":s,children:[e.jsxs("span",{className:"truncate",children:[c,p.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:p.join(", ")})]}),e.jsx("svg",{className:`h-4 w-4 text-slate-500 transition-transform dark:text-slate-300 ${s?"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"})})]}),s&&e.jsxs("div",{className:"absolute left-0 top-full z-20 mt-2 w-56 rounded-lg border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200 px-3 py-2 text-xs text-slate-500 dark:border-slate-700 dark:text-slate-300",children:[e.jsx("span",{children:c}),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:i("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-2 py-2",children:[t.map(a=>{const x=a.isWildcard?i("apiKeys.wildcard"):a.name,o=r.includes(a.id);return e.jsxs("label",{className:`flex items-center gap-2 rounded px-2 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800 ${o?"bg-slate-100 dark:bg-slate-800/70":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4",checked:o,onChange:()=>b(a.id)}),e.jsx("span",{className:"truncate",children:x})]},a.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:i("logs.filters.apiKeyAll")})]})]})]})}export{ce as default};
|
|
1
|
+
import{u as L,a as J,r as d,j as e,b as ae,L as le}from"./index-wA9rsqII.js";import{u as C}from"./useApiQuery-De0jYBDD.js";const W=[20,50,100];function z(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,h=Date.parse(n);return Number.isFinite(h)?h:void 0}function Y(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 w(t){return t==null?"-":t.toLocaleString()}function N(t,r){const n=w(t);return n==="-"?"-":`${n} ${r}`}function P(t){return t?"true":"false"}function H(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 ce(){var B,G;const{t}=L(),{pushToast:r}=J(),[n,h]=d.useState("all"),[i,s]=d.useState("all"),[m,y]=d.useState(""),[p,c]=d.useState("all"),[b,a]=d.useState(""),[x,o]=d.useState(""),[f,v]=d.useState(1),[u,_]=d.useState(W[0]),[D,E]=d.useState(null),[V,R]=d.useState(!1),[T,A]=d.useState([]);d.useEffect(()=>{v(1)},[n,i,m,p,b,x,u,T]);const M=d.useMemo(()=>{const l={limit:u,offset:(f-1)*u};n!=="all"&&(l.provider=n),i!=="all"&&(l.endpoint=i),m.trim().length>0&&(l.model=m.trim()),p!=="all"&&(l.status=p);const j=z(b),Q=z(x,!0);return j!==void 0&&(l.from=j),Q!==void 0&&(l.to=Q),T.length>0&&(l.apiKeys=T.join(",")),l},[n,i,m,p,b,x,f,u,T]),g=C(["logs",M],{url:"/api/logs",method:"GET",params:M}),S=C(["providers","all"],{url:"/api/providers",method:"GET"}),q=C(["api-keys"],{url:"/api/keys",method:"GET"});d.useEffect(()=>{g.isError&&g.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:g.error.message}),variant:"error"})},[g.isError,g.error,r,t]),d.useEffect(()=>{S.isError&&S.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:S.error.message}),variant:"error"})},[S.isError,S.error,r,t]);const $=((B=g.data)==null?void 0:B.total)??0,k=$>0?Math.ceil($/u):0,O=((G=g.data)==null?void 0:G.items)??[];d.useEffect(()=>{k>0&&f>k&&v(k)},[k,f]);const F=S.data??[],U=d.useMemo(()=>{const l=new Map;for(const j of F)j.id&&l.set(j.id,j.label??j.id);return l},[F]),K=q.data??[],I=d.useMemo(()=>{const l=new Map;for(const j of K)l.set(j.id,j);return l},[K]),X=d.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),ee=()=>{h("all"),y(""),s("all"),c("all"),a(""),o(""),A([])},te=d.useCallback(l=>{E(l),R(!0)},[]),se=d.useCallback(()=>{R(!1),E(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:t("logs.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400","aria-live":"polite",children:[e.jsx("span",{children:t("logs.summary.total",{value:$.toLocaleString()})}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:()=>g.refetch(),disabled:g.isFetching,children:g.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3 rounded-lg border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.provider")}),e.jsxs("select",{value:n,onChange:l=>h(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:[e.jsx("option",{value:"all",children:t("logs.filters.providerAll")}),F.map(l=>e.jsx("option",{value:l.id,children:l.label??l.id},l.id))]})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.endpoint")}),e.jsxs("select",{value:i,onChange:l=>s(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:[e.jsx("option",{value:"all",children:t("logs.filters.endpointAll")}),e.jsx("option",{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx("option",{value:"openai",children:t("logs.filters.endpointOpenAI")})]})]}),e.jsx(oe,{apiKeys:K,selected:T,disabled:q.isLoading,onChange:A}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.modelId")}),e.jsx("input",{value:m,onChange:l=>y(l.target.value),placeholder:t("logs.filters.modelPlaceholder"),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40"})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.status")}),e.jsx("select",{value:p,onChange:l=>c(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",children:X.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.startDate")}),e.jsx("input",{type:"date",value:b,onChange:l=>a(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40"})]}),e.jsxs("div",{className:"flex flex-col text-sm",children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:t("logs.filters.endDate")}),e.jsx("input",{type:"date",value:x,onChange:l=>o(l.target.value),className:"h-10 w-full rounded-md border border-slate-200 bg-white px-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:border-blue-400 dark:focus:ring-blue-400/40"})]}),e.jsx("div",{className:"ml-auto flex items-center gap-2 text-sm",children:e.jsx("button",{type:"button",onClick:ee,className:"rounded-md border border-slate-200 px-3 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:t("common.actions.reset")})})]})]}),e.jsxs("section",{className:"rounded-lg border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-slate-100 dark:bg-slate-800/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.cachedTokens")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.stream")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-slate-500 dark:text-slate-400",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200 dark:divide-slate-800",children:g.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-4 py-10 text-center text-sm text-slate-400",children:t("logs.table.loading")})}):O.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-4 py-10 text-center text-sm text-slate-400",children:t("logs.table.empty")})}):O.map(l=>e.jsx(re,{record:l,providerLabelMap:U,apiKeyMap:I,onSelect:te},l.id))})]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-slate-200 px-4 py-3 text-sm dark:border-slate-800",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:u,onChange:l=>_(Number(l.target.value)),className:"rounded-md border border-slate-200 bg-white px-2 py-1 text-sm dark:border-slate-700 dark:bg-slate-800",children:W.map(l=>e.jsx("option",{value:l,children:l},l))}),e.jsx("span",{children:t("logs.table.pagination.unit")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>v(l=>Math.max(l-1,1)),disabled:f<=1,className:"rounded-md border border-slate-200 px-3 py-1 transition enabled:hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:enabled:hover:bg-slate-800",children:t("logs.table.pagination.previous")}),e.jsx("span",{children:t("logs.table.pagination.pageLabel",{page:k===0?0:f,total:k})}),e.jsx("button",{type:"button",onClick:()=>v(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||f>=k,className:"rounded-md border border-slate-200 px-3 py-1 transition enabled:hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700 dark:enabled:hover:bg-slate-800",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(de,{open:V,logId:D,onClose:se,providerLabelMap:U,apiKeyMap:I})]})}function re({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:h}){const{t:i}=L(),s=r.get(t.provider)??t.provider,m=t.endpoint||"-",y=!!t.error,p=t.client_model??i("logs.table.requestedModelFallback"),c=t.api_key_id!=null?n.get(t.api_key_id):void 0,b=t.api_key_id==null?i("logs.table.apiKeyUnknown"):c!=null&&c.isWildcard?i("apiKeys.wildcard"):c!=null&&c.name?c.name:t.api_key_name?t.api_key_name:i("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:"hover:bg-slate-50 dark:hover:bg-slate-800/60",children:[e.jsx("td",{className:"px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:Y(t.timestamp)}),e.jsx("td",{className:"px-4 py-2",children:m}),e.jsx("td",{className:"px-4 py-2",children:s}),e.jsx("td",{className:"px-4 py-2",children:p}),e.jsx("td",{className:"px-4 py-2",children:t.model}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("span",{className:"block truncate",title:b,children:b})}),e.jsx("td",{className:"px-4 py-2 text-right",children:w(t.input_tokens)}),e.jsx("td",{className:"px-4 py-2 text-right",children:w(t.cached_tokens)}),e.jsx("td",{className:"px-4 py-2 text-right",children:w(t.output_tokens)}),e.jsx("td",{className:"px-4 py-2 text-right",children:P(t.stream)}),e.jsx("td",{className:"px-4 py-2 text-right",children:N(t.latency_ms,i("common.units.ms"))}),e.jsx("td",{className:"px-4 py-2 text-right",children:N(t.ttft_ms,i("common.units.ms"))}),e.jsx("td",{className:"px-4 py-2 text-right",children:N(t.tpot_ms,i("common.units.msPerToken"))}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(Z,{success:!y,statusCode:t.status_code})}),e.jsx("td",{className:"max-w-xs px-4 py-2 text-xs text-slate-500 dark:text-slate-400",children:e.jsx("span",{className:"block truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("button",{type:"button",onClick:()=>h(t.id),"aria-haspopup":"dialog",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:i("logs.actions.detail")})})]})}function Z({success:t,statusCode:r}){const{t:n}=L(),h="inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",i=t?"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200":"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-200";return e.jsxs("span",{className:`${h} ${i}`,children:[n(t?"common.status.success":"common.status.error"),r?` · ${r}`:""]})}function de({open:t,logId:r,onClose:n,providerLabelMap:h,apiKeyMap:i}){var f,v;const{t:s}=L(),{pushToast:m}=J(),y=d.useRef(null),p=d.useRef(null),c=C(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});d.useEffect(()=>{c.isError&&c.error&&m({title:s("logs.detail.loadError"),description:c.error.message,variant:"error"})},[c.isError,c.error,m,s]),d.useEffect(()=>{if(!t)return;const u=_=>{_.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[t,n]),d.useEffect(()=>{t&&p.current&&p.current.focus()},[t,r]);const b=d.useCallback(async(u,_,D)=>{if(!_){m({title:s("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await navigator.clipboard.writeText(_),m({title:s(D),variant:"success"})}catch(E){m({title:s("logs.detail.copy.failure"),description:E instanceof Error?E.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[m,s]);if(!t)return null;const a=c.data,x=a?h.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?i.get(a.api_key_id):void 0;return typeof document>"u"?null:ae.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:y,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-transform dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:p,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:c.isPending?e.jsx(le,{}):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:N(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:N(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:N(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:P(a.stream)})}),e.jsx(Z,{success:!a.error,statusCode:a.status_code})]}),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:Y(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:x})]}),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:P(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:w(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cachedTokens")}),e.jsx("dd",{className:"font-medium",children:w(a.cached_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:w(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:N(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:N(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:"flex items-center justify-between rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.raw")}),e.jsx("p",{className:"mt-1 text-xs",children:a.api_key_value?a.api_key_value:s("logs.detail.apiKey.rawUnavailable")})]}),e.jsx("button",{type:"button",disabled:!a.api_key_value,onClick:()=>b(s("logs.detail.apiKey.raw"),a.api_key_value,"logs.detail.copy.keySuccess"),className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 disabled:opacity-50 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var u;return b(s("logs.detail.payload.request"),(u=a.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:H((f=a.payload)==null?void 0:f.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var u;return b(s("logs.detail.payload.response"),(u=a.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:H((v=a.payload)==null?void 0:v.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 oe({apiKeys:t,selected:r,onChange:n,disabled:h}){const{t:i}=L(),[s,m]=d.useState(!1),y=d.useRef(null);d.useEffect(()=>{if(!s)return;const a=x=>{var o;(o=y.current)!=null&&o.contains(x.target)||m(!1)};return window.addEventListener("mousedown",a),()=>window.removeEventListener("mousedown",a)},[s]);const p=d.useMemo(()=>{if(r.length===0)return[];const a=new Map;for(const x of t)a.set(x.id,x);return r.map(x=>{const o=a.get(x);return o?o.isWildcard?i("apiKeys.wildcard"):o.name:null}).filter(x=>!!x)},[t,r,i]),c=r.length===0?i("logs.filters.apiKeyAll"):i("logs.filters.apiKeySelected",{count:r.length}),b=a=>{r.includes(a)?n(r.filter(x=>x!==a)):n([...r,a])};return e.jsxs("div",{className:"relative flex flex-col text-sm",ref:y,children:[e.jsx("label",{className:"mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:i("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>m(a=>!a),disabled:h||t.length===0,title:i("logs.filters.apiKeyHint"),className:`flex w-48 items-center justify-between rounded-md border px-3 py-2 text-left text-sm transition focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:opacity-50 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200 dark:focus:ring-blue-400/40 ${r.length>0?"border-blue-500 dark:border-blue-500":"border-slate-200"}`,"aria-haspopup":"listbox","aria-expanded":s,children:[e.jsxs("span",{className:"truncate",children:[c,p.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:p.join(", ")})]}),e.jsx("svg",{className:`h-4 w-4 text-slate-500 transition-transform dark:text-slate-300 ${s?"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"})})]}),s&&e.jsxs("div",{className:"absolute left-0 top-full z-20 mt-2 w-56 rounded-lg border border-slate-200 bg-white shadow-lg dark:border-slate-700 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200 px-3 py-2 text-xs text-slate-500 dark:border-slate-700 dark:text-slate-300",children:[e.jsx("span",{children:c}),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:i("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-2 py-2",children:[t.map(a=>{const x=a.isWildcard?i("apiKeys.wildcard"):a.name,o=r.includes(a.id);return e.jsxs("label",{className:`flex items-center gap-2 rounded px-2 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800 ${o?"bg-slate-100 dark:bg-slate-800/70":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4",checked:o,onChange:()=>b(a.id)}),e.jsx("span",{className:"truncate",children:x})]},a.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:i("logs.filters.apiKeyAll")})]})]})]})}export{ce as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as xe,r as x,j as e,a as Be}from"./index-Jqz_kqzz.js";import{u as Qe,a as L}from"./useApiQuery-BigNbUj6.js";function be(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:be(),id:"",label:""}}const ue={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5 (2025-09-29)"},{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4 (2025-05-14)"},{id:"claude-opus-4-1-20250805",label:"Claude Opus 4.1 (2025-08-05)"},{id:"claude-3-5-haiku-20241022",label:"Claude 3.5 Haiku (2024-10-22)"}]},custom:{}};function ge(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(u=>({...u,_key:be()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[ke()],authMode:"apiKey"}}function ze(s){return{_key:be(),id:s.id,label:s.label}}function Ge({open:s,mode:u,provider:m,existingProviderIds:R,onClose:C,onSubmit:q}){const{t:a}=xe(),[o,M]=x.useState(()=>ge(m)),[A,$]=x.useState({}),[H,P]=x.useState(!1),[B,Q]=x.useState(null),Z=x.useRef(null),K=x.useRef(null),j=x.useRef(null),[_,E]=x.useState(u==="edit");x.useEffect(()=>{s&&(M(ge(m)),$({}),Q(null),P(!1),E(u==="edit"))},[s,m,u]),x.useEffect(()=>{if(!s)return;const l=i=>{i.key==="Escape"&&C()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s,C]),x.useEffect(()=>{if(s){if(u==="create"&&j.current){j.current.focus();return}K.current&&K.current.focus()}},[s,u]);const ie=x.useMemo(()=>o.models.filter(l=>l.id.trim().length>0),[o.models]),z=l=>i=>{M(p=>({...p,[l]:i}))},J=l=>{M(i=>{const b=!_||i.label.trim().length===0||i.label===i.id?l:i.label;return{...i,id:l,label:b}})},W=l=>{M(i=>{var X;const b=ue[l??"custom"]??ue.custom,g=Object.values(ue).map(v=>v.baseUrl).filter(v=>!!v),S=!i.baseUrl||g.includes(i.baseUrl),N=u==="create"&&(i.models.length===0||i.models.every(v=>v.id.trim().length===0)),T={...i,type:l,authMode:l==="anthropic"?i.authMode??"apiKey":"apiKey"};return b!=null&&b.baseUrl&&S&&(T.baseUrl=b.baseUrl),b!=null&&b.models&&N&&(T.models=b.models.map(ze),T.defaultModel=b.defaultModel??((X=b.models[0])==null?void 0:X.id)??""),T})},ee=(l,i)=>{M(p=>{const b=[...p.models];return b[l]={...b[l],...i},{...p,models:b}})},te=(l,i)=>{M(p=>{const b=[...p.models],g=b[l];if(!g)return p;const S=!_||!g.label||g.label===g.id,N={...g,id:i,label:S?i:g.label};b[l]=N;const T=p.defaultModel===g.id?i:p.defaultModel;return{...p,models:b,defaultModel:T}})},se=l=>{M(i=>{var g;if(i.models.length<=1)return i;const p=i.models.filter((S,N)=>N!==l);let b=i.defaultModel;return p.some(S=>S.id===b)||(b=((g=p[0])==null?void 0:g.id)??""),{...i,models:p,defaultModel:b}})},G=()=>{M(l=>({...l,models:[...l.models,ke()]}))},V=l=>{M(i=>({...i,authMode:l}))},ae=()=>{const l={},i=o.id.trim(),p=o.baseUrl.trim();if(u==="create"&&(i.length===0?l.id=a("providers.drawer.errors.idRequired"):R.includes(i)&&(l.id=a("providers.drawer.errors.idDuplicate"))),u==="edit"&&i.length===0&&(l.id=a("providers.drawer.errors.idRequired")),p.length===0)l.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(p)}catch{l.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}const b=new Set;return o.models.some(S=>{const N=S.id.trim();return N.length===0||b.has(N)?!0:(b.add(N),!1)})&&(l.models=a("providers.drawer.errors.modelInvalid")),o.models.length===0&&(l.models=a("providers.drawer.errors.modelsRequired")),o.defaultModel&&!o.models.some(S=>S.id===o.defaultModel)&&(l.models=a("providers.drawer.errors.defaultInvalid")),$(l),Object.keys(l).length===0},ce=()=>{const l=o.models.map(b=>{var g;return{id:b.id.trim(),label:(g=b.label)!=null&&g.trim()?b.label.trim():void 0}}),i=m!=null&&m.extraHeaders&&Object.keys(m.extraHeaders).length>0?m.extraHeaders:void 0,p=o.type==="anthropic"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:l,extraHeaders:i,authMode:p}},re=async()=>{if(Q(null),!!ae()){P(!0);try{const l=ce();await q(l)}catch(l){Q(a("providers.drawer.toast.saveFailure",{message:l instanceof Error?l.message:"unknown"})),P(!1);return}P(!1),C()}},le=u==="create";return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:C,"aria-hidden":"true"}),e.jsxs("aside",{ref:Z,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-3xl flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold",children:a(le?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:K,onClick:C,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a("common.actions.close")})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-fields",children:[e.jsx("div",{id:"provider-basic-fields",className:"sr-only",children:a("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>E(l=>!l),className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a(_?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:j,onChange:l=>J(l.target.value),disabled:!le,placeholder:a("providers.drawer.fields.idPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!A.id}),A.id?e.jsx("span",{className:"text-xs text-red-500",children:A.id}):null]}),_?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:l=>z("label")(l.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:l=>z("baseUrl")(l.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!A.baseUrl}),A.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:A.baseUrl}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.type")}),e.jsxs("select",{value:o.type??"custom",onChange:l=>W(l.target.value),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"deepseek",children:"DeepSeek"}),e.jsx("option",{value:"huawei",children:"华为云"}),e.jsx("option",{value:"kimi",children:"Kimi"}),e.jsx("option",{value:"anthropic",children:"Anthropic (Claude)"}),e.jsx("option",{value:"custom",children:"Custom"})]})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:l=>z("apiKey")(l.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),o.type==="anthropic"?e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-slate-200 p-3 text-xs dark:border-slate-700",children:[e.jsx("legend",{className:"px-1 text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"apiKey",checked:o.authMode==="apiKey",onChange:()=>V("apiKey")}),e.jsx("span",{children:a("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"authToken",checked:o.authMode==="authToken",onChange:()=>V("authToken")}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]})]}):null]}),e.jsxs("section",{className:"mt-6 space-y-3","aria-labelledby":"provider-model-fields",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"provider-model-fields",className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:G,className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a("providers.drawer.fields.addModel")})]}),A.models?e.jsx("p",{className:"text-xs text-red-500",children:A.models}):null,e.jsx("div",{className:"space-y-4",children:o.models.map((l,i)=>e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:l.id,onChange:p=>te(i,p.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),_?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:l.label??"",onChange:p=>ee(i,{label:p.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:l.id,checked:o.defaultModel===l.id,onChange:()=>M(p=>({...p,defaultModel:l.id})),disabled:l.id.trim().length===0}),a("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>se(i),disabled:o.models.length<=1,children:a("providers.drawer.fields.removeModel")})]})]},l._key))}),ie.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:B?e.jsx("span",{children:B}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:C,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:H,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:re,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:H,children:a(H?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const Ve=["claude-sonnet-4-5-20250929","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-3-5-haiku-20241022"],Ye=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function me(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function F(s){return s?Object.entries(s).map(([u,m])=>({id:me(),source:u,target:m})):[]}function ne(s){var m,R;if(!s)return{anthropic:[],openai:[]};const u=s.endpointRouting??{};return{anthropic:F(((m=u.anthropic)==null?void 0:m.modelRoutes)??s.modelRoutes??{}),openai:F(((R=u.openai)==null?void 0:R.modelRoutes)??{})}}function et(){const{t:s}=xe(),{pushToast:u}=Be(),m=Qe(["config","full"],{url:"/api/config",method:"GET"}),R=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc")},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc")},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc")}],[C,q]=x.useState("providers"),[a,o]=x.useState(null),[M,A]=x.useState(!1),[$,H]=x.useState("create"),[P,B]=x.useState(void 0),[Q,Z]=x.useState(null),[K,j]=x.useState({anthropic:[],openai:[]}),[_,E]=x.useState({anthropic:null,openai:null}),[ie,z]=x.useState(null),[J,W]=x.useState([]),[ee,te]=x.useState(""),[se,G]=x.useState(null),[V,ae]=x.useState(!1),[ce,re]=x.useState(null),[le,l]=x.useState(null),[i,p]=x.useState(!1),[b,g]=x.useState(""),[S,N]=x.useState(null),[T,X]=x.useState(!1),v=(a==null?void 0:a.providers)??[],ye=v.length;x.useEffect(()=>{var t;if(m.data){const r=m.data;o(r),j(ne(r)),E({anthropic:null,openai:null}),W(((t=r.routingPresets)==null?void 0:t.anthropic)??[])}},[m.data]),x.useEffect(()=>{m.isError&&m.error&&u({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,u,s]);const je=x.useMemo(()=>{const t=new Map;for(const r of v){if(!r.defaultModel||!r.models)continue;const d=r.models.find(n=>n.id===r.defaultModel);d&&t.set(r.id,ve(d))}return t},[v]),pe=x.useMemo(()=>{const t=[],r=new Set;for(const n of v){const c=n.label||n.id,f=n.models??[];if(f.length>0)for(const k of f){const U=`${n.id}:${k.id}`;r.has(U)||(r.add(U),t.push({value:U,label:`${c} · ${k.label??k.id}`}))}else if(n.defaultModel){const k=`${n.id}:${n.defaultModel}`;r.has(k)||(r.add(k),t.push({value:k,label:`${c} · ${n.defaultModel}`}))}}const d=[...K.anthropic,...K.openai];for(const n of d){const c=n.target.trim();c&&!r.has(c)&&(r.add(c),t.push({value:c,label:c}))}return t},[v,K]),he=t=>{W(t),o(r=>r&&{...r,routingPresets:{...r.routingPresets,anthropic:t}})},O=()=>a?!0:(u({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),we=t=>{if(!a)return t;let r=t,d=1;for(;a.providers.some(n=>n.id===r);)r=`${t}-${d}`,d+=1;return r},Ne=t=>{te(t),t.trim()&&G(null)},Me=async()=>{if(!O())return;const t=ee.trim();if(!t){G(s("modelManagement.validation.presetName"));return}if(J.some(r=>r.name.toLowerCase()===t.toLowerCase())){G(s("modelManagement.validation.presetDuplicate",{name:t}));return}ae(!0);try{const d=(await L.post("/api/routing-presets/anthropic",{name:t})).data.presets??[];he(d),te(""),G(null),u({title:s("modelManagement.toast.presetSaved",{name:t}),variant:"success"})}catch(r){u({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{ae(!1),m.refetch()}},Ce=async t=>{var r;if(O()){re(t.name);try{const n=(await L.post("/api/routing-presets/anthropic/apply",{name:t.name})).data.config;n?(o(n),j(ne(n)),W(((r=n.routingPresets)==null?void 0:r.anthropic)??[])):j(c=>({...c,anthropic:F(t.modelRoutes)})),u({title:s("modelManagement.toast.presetApplySuccess",{name:t.name}),variant:"success"})}catch(d){u({title:s("modelManagement.toast.presetApplyFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{re(null),m.refetch()}}},Se=async t=>{if(!(!O()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:t.name})))){l(t.name);try{const n=(await L.delete(`/api/routing-presets/anthropic/${encodeURIComponent(t.name)}`)).data.presets??[];he(n),u({title:s("modelManagement.toast.presetDeleteSuccess",{name:t.name}),variant:"success"})}catch(d){u({title:s("modelManagement.toast.presetDeleteFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{l(null),m.refetch()}}},Re=()=>{O()&&(H("create"),B(void 0),A(!0))},Ae=()=>{O()&&(g(""),N(null),p(!0))},Ee=t=>{O()&&(H("edit"),B(t),A(!0))},Pe=async()=>{if(!a){u({title:s("settings.toast.missingConfig"),variant:"error"});return}const t=b.trim();if(!t){N(s("providers.quickAddHuawei.validation.apiKey"));return}const n={id:we("huawei-cloud"),label:s("providers.quickAddHuawei.providerLabel"),baseUrl:"https://api.modelarts-maas.com/v1",apiKey:t,type:"huawei",defaultModel:"deepseek-v3.1",models:[{id:"deepseek-v3.1",label:"DeepSeek V3.1"},{id:"KIMI-K2",label:"KIMI-K2"},{id:"qwen3-235b-a22b",label:"Qwen3 235B A22B"}]},c={...a,providers:[...a.providers,n]};try{X(!0),await L.put("/api/config",c),o(c),j(ne(c)),p(!1),u({title:s("providers.quickAddHuawei.toast.success"),description:s("providers.quickAddHuawei.toast.added",{name:n.label||n.id}),variant:"success"}),m.refetch()}catch(f){N(f instanceof Error?f.message:s("providers.quickAddHuawei.toast.failure"))}finally{X(!1)}},Ue=async t=>{if(!a)throw new Error(s("settings.toast.missingConfig"));const r=$==="create"?[...v,t]:v.map(c=>P&&c.id===P.id?{...t,id:P.id}:c),d={...a,providers:r};await L.put("/api/config",d),o(d),j(ne(d)),m.refetch();const n=$==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});u({title:n,variant:"success"})},Ie=async t=>{Z(t.id);try{const r=await L.post(`/api/providers/${t.id}/test`);r.data.ok?u({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:r.data.status,duration:r.data.durationMs?`${r.data.durationMs} ms`:"—"}),variant:"success"}):u({title:s("providers.toast.testFailure",{message:`${r.data.status} ${r.data.statusText}`}),variant:"error"})}catch(r){u({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{Z(null)}},De=async t=>{var h,w,D,I;if(!O()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const d=v.filter(y=>y.id!==t.id),n=y=>{const Y={};if(!y)return Y;for(const[Fe,oe]of Object.entries(y)){if(!oe)continue;const[fe]=oe.split(":");fe&&fe===t.id||oe===t.id||(Y[Fe]=oe)}return Y},c=(a==null?void 0:a.endpointRouting)??{},f=n(((h=c.anthropic)==null?void 0:h.modelRoutes)??(a==null?void 0:a.modelRoutes)??{}),k=n(((w=c.openai)==null?void 0:w.modelRoutes)??{}),U={...a,providers:d,modelRoutes:f,endpointRouting:{anthropic:{defaults:((D=c.anthropic)==null?void 0:D.defaults)??a.defaults,modelRoutes:f},openai:{defaults:((I=c.openai)==null?void 0:I.defaults)??a.defaults,modelRoutes:k}}};try{await L.put("/api/config",U),o(U),j({anthropic:F(f),openai:F(k)}),u({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(y){u({title:s("providers.toast.deleteFailure",{message:y instanceof Error?y.message:"unknown"}),variant:"error"})}},Ke=t=>{j(r=>({...r,[t]:[...r[t],{id:me(),source:"",target:""}]})),E(r=>({...r,[t]:null}))},Te=(t,r)=>{j(d=>d[t].some(n=>n.source.trim()===r.trim())?d:{...d,[t]:[...d[t],{id:me(),source:r,target:""}]}),E(d=>({...d,[t]:null}))},de=(t,r,d,n)=>{j(c=>({...c,[t]:c[t].map(f=>f.id===r?{...f,[d]:n}:f)})),E(c=>({...c,[t]:null}))},$e=(t,r)=>{j(d=>({...d,[t]:d[t].filter(n=>n.id!==r)})),E(d=>({...d,[t]:null}))},Oe=t=>{var c;if(!a)return;const r=a.endpointRouting??{},d=t==="anthropic"?a.modelRoutes??{}:{},n=((c=r[t])==null?void 0:c.modelRoutes)??d;j(f=>({...f,[t]:F(n)})),E(f=>({...f,[t]:null}))},Le=async t=>{var n,c,f,k,U;if(!O())return;const r=K[t],d={};for(const h of r){const w=h.source.trim(),D=h.target.trim();if(!(!w&&!D)){if(!w||!D){E(I=>({...I,[t]:s("settings.validation.routePair")}));return}if(d[w]){E(I=>({...I,[t]:s("settings.validation.routeDuplicate",{model:w})}));return}d[w]=D}}E(h=>({...h,[t]:null})),z(t);try{const h=a.endpointRouting??{anthropic:{defaults:a.defaults,modelRoutes:a.modelRoutes??{}},openai:{defaults:((c=(n=a.endpointRouting)==null?void 0:n.openai)==null?void 0:c.defaults)??a.defaults,modelRoutes:((k=(f=a.endpointRouting)==null?void 0:f.openai)==null?void 0:k.modelRoutes)??{}}},w={...h,[t]:{defaults:((U=h[t])==null?void 0:U.defaults)??a.defaults,modelRoutes:d}},D={...a,endpointRouting:w,modelRoutes:t==="anthropic"?d:a.modelRoutes??{}};await L.put("/api/config",D),o(D),j(I=>({...I,[t]:F(d)})),u({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}catch(h){u({title:s("modelManagement.toast.routesSaveFailure",{message:h instanceof Error?h.message:"unknown"}),variant:"error"})}finally{z(null)}},qe=()=>e.jsxs("section",{className:"space-y-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("providers.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:s("providers.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:s("providers.count",{count:ye})}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:Ae,children:s("providers.quickAddHuawei.button")}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:Re,children:s("providers.actions.add")})]})]}),m.isPending||!a&&m.isFetching?e.jsx("section",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-slate-200 bg-white text-sm text-slate-500 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-400",children:s("common.loading")}):v.length===0?e.jsx("section",{className:"rounded-lg border border-dashed border-slate-300 bg-white p-8 text-sm text-slate-500 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-400",children:s("providers.emptyState")}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:v.map(t=>e.jsxs("article",{className:"flex h-full flex-col gap-4 rounded-lg border border-slate-200 bg-white p-5 shadow-sm transition hover:shadow-md dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-semibold",children:t.label||t.id}),t.type?e.jsx(We,{type:t.type}):null]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["ID:",t.id]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["Base URL:",e.jsx("span",{className:"break-all text-slate-600 dark:text-slate-300",children:t.baseUrl})]})]}),e.jsx("div",{className:"flex flex-col gap-2 text-xs text-slate-500 dark:text-slate-400",children:t.defaultModel?e.jsx("span",{className:"inline-flex items-center rounded-full bg-emerald-100 px-2 py-0.5 font-medium text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200",children:s("providers.card.defaultModel",{model:je.get(t.id)??t.defaultModel})}):e.jsx("span",{className:"inline-flex items-center rounded-full bg-slate-100 px-2 py-0.5 font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300",children:s("providers.card.noDefault")})})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("ul",{className:"flex flex-wrap gap-2",children:t.models.map(r=>e.jsx("li",{className:"flex items-center gap-2 rounded-md border border-slate-200 bg-slate-50 px-3 py-1 text-xs dark:border-slate-700 dark:bg-slate-800/60",children:e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:ve(r)})},r.id))}):e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("providers.card.noModels")})]}),e.jsxs("footer",{className:"mt-auto flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",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",onClick:()=>Ee(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>Ie(t),disabled:Q===t.id,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition enabled:hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-slate-700 dark:enabled:hover:bg-slate-800",children:Q===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:"rounded-md border border-red-200 px-3 py-1 text-sm text-red-600 transition hover:bg-red-50 dark:border-red-800 dark:text-red-300 dark:hover:bg-red-900/40",onClick:()=>De(t),children:s("providers.actions.delete")})]})]},t.id))})]}),He=()=>e.jsxs("div",{className:"space-y-3 rounded-md border border-dashed border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:s("modelManagement.presets.title")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("modelManagement.presets.description")})]}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center",children:[e.jsx("input",{type:"text",value:ee,onChange:t=>Ne(t.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:"w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100 md:w-56",disabled:V}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-md bg-blue-600 px-3 py-2 text-sm font-medium text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:V,children:s(V?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),se?e.jsx("p",{className:"text-xs text-red-500",children:se}):null,J.length===0?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("modelManagement.presets.empty")}):e.jsx("div",{className:"flex flex-wrap gap-2",children:J.map(t=>{const r=ce===t.name,d=le===t.name;return e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-slate-200 bg-white px-3 py-2 text-sm shadow-sm dark:border-slate-700 dark:bg-slate-900",children:[e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:t.name}),e.jsx("button",{type:"button",onClick:()=>Ce(t),className:"rounded-md bg-blue-500 px-2 py-1 text-xs font-medium text-white transition hover:bg-blue-600 disabled:opacity-60",disabled:r||d,children:s(r?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>Se(t),className:"rounded-md border border-slate-200 px-2 py-1 text-xs text-slate-600 transition hover:bg-slate-100 disabled:opacity-60 dark:border-slate-600 dark:text-slate-300 dark:hover:bg-slate-800",disabled:d||r,children:s(d?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]},t.name)})})]}),_e=t=>{const r=K[t],d=_[t],n=t==="anthropic"?Ve:Ye,c=ie===t,f=s(`modelManagement.tabs.${t}`),k=`route-source-${t}`,U=`route-target-${t}`;return e.jsxs("section",{className:"space-y-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("settings.routing.titleByEndpoint",{endpoint:f})}),e.jsx("p",{className:"max-w-3xl text-xs text-slate-500 dark:text-slate-400",children:s(`settings.routing.descriptionByEndpoint.${t}`)})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>Ke(t),className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>Oe(t),className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:c,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Le(t),className:"rounded-md bg-blue-600 px-3 py-1 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:c,children:s(c?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),t==="anthropic"?He():null,d?e.jsx("p",{className:"text-xs text-red-500",children:d}):null,r.length===0?e.jsx("p",{className:"rounded-md border border-dashed border-slate-200 bg-slate-50 px-3 py-6 text-center text-sm text-slate-500 dark:border-slate-700 dark:bg-slate-800/60 dark:text-slate-300",children:s("settings.routing.empty")}):e.jsx("div",{className:"grid gap-3",children:r.map(h=>e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-xs",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:s("settings.routing.source")}),e.jsx("input",{type:"text",value:h.source,onChange:w=>de(t,h.id,"source",w.target.value),className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100",placeholder:"claude-3.5-sonnet",list:k,disabled:c})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-xs",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:s("settings.routing.target")}),(()=>{const w=h.target.trim(),I=pe.some(y=>y.value===w)?w:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:I,onChange:y=>{const Y=y.target.value;Y==="__custom"?de(t,h.id,"target",w):de(t,h.id,"target",Y)},className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100",disabled:c,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),pe.map(y=>e.jsx("option",{value:y.value,children:y.label},`${U}-${y.value}`))]}),I==="__custom"&&e.jsx("input",{type:"text",value:h.target,onChange:y=>de(t,h.id,"target",y.target.value),className:"mt-2 rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100",placeholder:"providerId:modelId",disabled:c})]})})()]}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-2 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:()=>$e(t,h.id),disabled:c,children:s("settings.routing.remove")})})]},h.id))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:s("settings.routing.suggested")}),n.map(h=>e.jsx("button",{type:"button",onClick:()=>Te(t,h),className:"rounded-md border border-slate-200 px-2 py-1 text-xs text-slate-600 transition hover:bg-slate-100 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800",disabled:c,children:h},`${t}-${h}`))]}),e.jsx("datalist",{id:k,children:n.map(h=>e.jsx("option",{value:h},`${k}-${h}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:s("modelManagement.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:s("modelManagement.description")})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:R.map(t=>{const r=C===t.key;return e.jsxs("button",{type:"button",onClick:()=>q(t.key),className:`flex min-w-[200px] flex-col gap-1 rounded-lg border px-4 py-3 text-left transition ${r?"border-blue-500 bg-blue-50 text-blue-700 dark:border-blue-400 dark:bg-blue-900/30 dark:text-blue-100":"border-slate-200 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800"}`,children:[e.jsx("span",{className:"text-sm font-semibold",children:t.label}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:t.description})]},t.key)})}),C==="providers"?qe():_e(C),e.jsx(Ge,{open:M,mode:$,provider:$==="edit"?P:void 0,existingProviderIds:v.map(t=>t.id).filter(t=>$==="edit"&&P?t!==P.id:!0),onClose:()=>{A(!1),B(void 0),H("create")},onSubmit:Ue}),e.jsx(Je,{open:i,apiKey:b,onApiKeyChange:t=>{g(t),S&&N(null)},loading:T,error:S,onClose:()=>{T||(p(!1),N(null))},onSubmit:Pe})]})}function Je({open:s,apiKey:u,onApiKeyChange:m,loading:R,error:C,onClose:q,onSubmit:a}){const{t:o}=xe();return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:q,"aria-hidden":"true"}),e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"quick-add-huawei",className:"flex h-full w-full max-w-md flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"quick-add-huawei",className:"text-lg font-semibold",children:o("providers.quickAddHuawei.title")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.quickAddHuawei.description")})]}),e.jsx("button",{type:"button",onClick:q,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",disabled:R,children:o("common.actions.close")})]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-4 px-6 py-5 text-sm",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.quickAddHuawei.apiKeyLabel")}),e.jsx("input",{type:"password",value:u,onChange:M=>m(M.target.value),placeholder:o("providers.quickAddHuawei.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",disabled:R})]}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.quickAddHuawei.note")}),C?e.jsx("p",{className:"text-xs text-red-500",children:C}):null]}),e.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("button",{type:"button",onClick:q,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:R,children:o("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:R,children:o(R?"common.actions.saving":"providers.quickAddHuawei.submit")})]})]})]}):null}function ve(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function We({type:s}){const u={openai:"OpenAI",deepseek:"DeepSeek",huawei:"华为云",kimi:"Kimi",anthropic:"Anthropic",custom:"Custom"};return e.jsx("span",{className:"rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300",children:u[s]??s})}export{et as default};
|
|
1
|
+
import{u as xe,r as x,j as e,a as Be}from"./index-wA9rsqII.js";import{u as Qe,a as L}from"./useApiQuery-De0jYBDD.js";function be(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:be(),id:"",label:""}}const ue={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1",defaultModel:"claude-sonnet-4-5-20250929",models:[{id:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5 (2025-09-29)"},{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4 (2025-05-14)"},{id:"claude-opus-4-1-20250805",label:"Claude Opus 4.1 (2025-08-05)"},{id:"claude-3-5-haiku-20241022",label:"Claude 3.5 Haiku (2024-10-22)"}]},custom:{}};function ge(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(u=>({...u,_key:be()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[ke()],authMode:"apiKey"}}function ze(s){return{_key:be(),id:s.id,label:s.label}}function Ge({open:s,mode:u,provider:m,existingProviderIds:R,onClose:C,onSubmit:q}){const{t:a}=xe(),[o,M]=x.useState(()=>ge(m)),[A,$]=x.useState({}),[H,P]=x.useState(!1),[B,Q]=x.useState(null),Z=x.useRef(null),K=x.useRef(null),j=x.useRef(null),[_,E]=x.useState(u==="edit");x.useEffect(()=>{s&&(M(ge(m)),$({}),Q(null),P(!1),E(u==="edit"))},[s,m,u]),x.useEffect(()=>{if(!s)return;const l=i=>{i.key==="Escape"&&C()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[s,C]),x.useEffect(()=>{if(s){if(u==="create"&&j.current){j.current.focus();return}K.current&&K.current.focus()}},[s,u]);const ie=x.useMemo(()=>o.models.filter(l=>l.id.trim().length>0),[o.models]),z=l=>i=>{M(p=>({...p,[l]:i}))},J=l=>{M(i=>{const b=!_||i.label.trim().length===0||i.label===i.id?l:i.label;return{...i,id:l,label:b}})},W=l=>{M(i=>{var X;const b=ue[l??"custom"]??ue.custom,g=Object.values(ue).map(v=>v.baseUrl).filter(v=>!!v),S=!i.baseUrl||g.includes(i.baseUrl),N=u==="create"&&(i.models.length===0||i.models.every(v=>v.id.trim().length===0)),T={...i,type:l,authMode:l==="anthropic"?i.authMode??"apiKey":"apiKey"};return b!=null&&b.baseUrl&&S&&(T.baseUrl=b.baseUrl),b!=null&&b.models&&N&&(T.models=b.models.map(ze),T.defaultModel=b.defaultModel??((X=b.models[0])==null?void 0:X.id)??""),T})},ee=(l,i)=>{M(p=>{const b=[...p.models];return b[l]={...b[l],...i},{...p,models:b}})},te=(l,i)=>{M(p=>{const b=[...p.models],g=b[l];if(!g)return p;const S=!_||!g.label||g.label===g.id,N={...g,id:i,label:S?i:g.label};b[l]=N;const T=p.defaultModel===g.id?i:p.defaultModel;return{...p,models:b,defaultModel:T}})},se=l=>{M(i=>{var g;if(i.models.length<=1)return i;const p=i.models.filter((S,N)=>N!==l);let b=i.defaultModel;return p.some(S=>S.id===b)||(b=((g=p[0])==null?void 0:g.id)??""),{...i,models:p,defaultModel:b}})},G=()=>{M(l=>({...l,models:[...l.models,ke()]}))},V=l=>{M(i=>({...i,authMode:l}))},ae=()=>{const l={},i=o.id.trim(),p=o.baseUrl.trim();if(u==="create"&&(i.length===0?l.id=a("providers.drawer.errors.idRequired"):R.includes(i)&&(l.id=a("providers.drawer.errors.idDuplicate"))),u==="edit"&&i.length===0&&(l.id=a("providers.drawer.errors.idRequired")),p.length===0)l.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(p)}catch{l.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}const b=new Set;return o.models.some(S=>{const N=S.id.trim();return N.length===0||b.has(N)?!0:(b.add(N),!1)})&&(l.models=a("providers.drawer.errors.modelInvalid")),o.models.length===0&&(l.models=a("providers.drawer.errors.modelsRequired")),o.defaultModel&&!o.models.some(S=>S.id===o.defaultModel)&&(l.models=a("providers.drawer.errors.defaultInvalid")),$(l),Object.keys(l).length===0},ce=()=>{const l=o.models.map(b=>{var g;return{id:b.id.trim(),label:(g=b.label)!=null&&g.trim()?b.label.trim():void 0}}),i=m!=null&&m.extraHeaders&&Object.keys(m.extraHeaders).length>0?m.extraHeaders:void 0,p=o.type==="anthropic"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:l,extraHeaders:i,authMode:p}},re=async()=>{if(Q(null),!!ae()){P(!0);try{const l=ce();await q(l)}catch(l){Q(a("providers.drawer.toast.saveFailure",{message:l instanceof Error?l.message:"unknown"})),P(!1);return}P(!1),C()}},le=u==="create";return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:C,"aria-hidden":"true"}),e.jsxs("aside",{ref:Z,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-3xl flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold",children:a(le?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:K,onClick:C,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a("common.actions.close")})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-fields",children:[e.jsx("div",{id:"provider-basic-fields",className:"sr-only",children:a("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>E(l=>!l),className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a(_?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:j,onChange:l=>J(l.target.value),disabled:!le,placeholder:a("providers.drawer.fields.idPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!A.id}),A.id?e.jsx("span",{className:"text-xs text-red-500",children:A.id}):null]}),_?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:l=>z("label")(l.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:l=>z("baseUrl")(l.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!A.baseUrl}),A.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:A.baseUrl}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.type")}),e.jsxs("select",{value:o.type??"custom",onChange:l=>W(l.target.value),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"deepseek",children:"DeepSeek"}),e.jsx("option",{value:"huawei",children:"华为云"}),e.jsx("option",{value:"kimi",children:"Kimi"}),e.jsx("option",{value:"anthropic",children:"Anthropic (Claude)"}),e.jsx("option",{value:"custom",children:"Custom"})]})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:l=>z("apiKey")(l.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),o.type==="anthropic"?e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-slate-200 p-3 text-xs dark:border-slate-700",children:[e.jsx("legend",{className:"px-1 text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"apiKey",checked:o.authMode==="apiKey",onChange:()=>V("apiKey")}),e.jsx("span",{children:a("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"authToken",checked:o.authMode==="authToken",onChange:()=>V("authToken")}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]})]}):null]}),e.jsxs("section",{className:"mt-6 space-y-3","aria-labelledby":"provider-model-fields",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"provider-model-fields",className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:G,className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:a("providers.drawer.fields.addModel")})]}),A.models?e.jsx("p",{className:"text-xs text-red-500",children:A.models}):null,e.jsx("div",{className:"space-y-4",children:o.models.map((l,i)=>e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:l.id,onChange:p=>te(i,p.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),_?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:l.label??"",onChange:p=>ee(i,{label:p.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:l.id,checked:o.defaultModel===l.id,onChange:()=>M(p=>({...p,defaultModel:l.id})),disabled:l.id.trim().length===0}),a("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>se(i),disabled:o.models.length<=1,children:a("providers.drawer.fields.removeModel")})]})]},l._key))}),ie.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:B?e.jsx("span",{children:B}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:C,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:H,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:re,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:H,children:a(H?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const Ve=["claude-sonnet-4-5-20250929","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-3-5-haiku-20241022"],Ye=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function me(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function F(s){return s?Object.entries(s).map(([u,m])=>({id:me(),source:u,target:m})):[]}function ne(s){var m,R;if(!s)return{anthropic:[],openai:[]};const u=s.endpointRouting??{};return{anthropic:F(((m=u.anthropic)==null?void 0:m.modelRoutes)??s.modelRoutes??{}),openai:F(((R=u.openai)==null?void 0:R.modelRoutes)??{})}}function et(){const{t:s}=xe(),{pushToast:u}=Be(),m=Qe(["config","full"],{url:"/api/config",method:"GET"}),R=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc")},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc")},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc")}],[C,q]=x.useState("providers"),[a,o]=x.useState(null),[M,A]=x.useState(!1),[$,H]=x.useState("create"),[P,B]=x.useState(void 0),[Q,Z]=x.useState(null),[K,j]=x.useState({anthropic:[],openai:[]}),[_,E]=x.useState({anthropic:null,openai:null}),[ie,z]=x.useState(null),[J,W]=x.useState([]),[ee,te]=x.useState(""),[se,G]=x.useState(null),[V,ae]=x.useState(!1),[ce,re]=x.useState(null),[le,l]=x.useState(null),[i,p]=x.useState(!1),[b,g]=x.useState(""),[S,N]=x.useState(null),[T,X]=x.useState(!1),v=(a==null?void 0:a.providers)??[],ye=v.length;x.useEffect(()=>{var t;if(m.data){const r=m.data;o(r),j(ne(r)),E({anthropic:null,openai:null}),W(((t=r.routingPresets)==null?void 0:t.anthropic)??[])}},[m.data]),x.useEffect(()=>{m.isError&&m.error&&u({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,u,s]);const je=x.useMemo(()=>{const t=new Map;for(const r of v){if(!r.defaultModel||!r.models)continue;const d=r.models.find(n=>n.id===r.defaultModel);d&&t.set(r.id,ve(d))}return t},[v]),pe=x.useMemo(()=>{const t=[],r=new Set;for(const n of v){const c=n.label||n.id,f=n.models??[];if(f.length>0)for(const k of f){const U=`${n.id}:${k.id}`;r.has(U)||(r.add(U),t.push({value:U,label:`${c} · ${k.label??k.id}`}))}else if(n.defaultModel){const k=`${n.id}:${n.defaultModel}`;r.has(k)||(r.add(k),t.push({value:k,label:`${c} · ${n.defaultModel}`}))}}const d=[...K.anthropic,...K.openai];for(const n of d){const c=n.target.trim();c&&!r.has(c)&&(r.add(c),t.push({value:c,label:c}))}return t},[v,K]),he=t=>{W(t),o(r=>r&&{...r,routingPresets:{...r.routingPresets,anthropic:t}})},O=()=>a?!0:(u({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),we=t=>{if(!a)return t;let r=t,d=1;for(;a.providers.some(n=>n.id===r);)r=`${t}-${d}`,d+=1;return r},Ne=t=>{te(t),t.trim()&&G(null)},Me=async()=>{if(!O())return;const t=ee.trim();if(!t){G(s("modelManagement.validation.presetName"));return}if(J.some(r=>r.name.toLowerCase()===t.toLowerCase())){G(s("modelManagement.validation.presetDuplicate",{name:t}));return}ae(!0);try{const d=(await L.post("/api/routing-presets/anthropic",{name:t})).data.presets??[];he(d),te(""),G(null),u({title:s("modelManagement.toast.presetSaved",{name:t}),variant:"success"})}catch(r){u({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{ae(!1),m.refetch()}},Ce=async t=>{var r;if(O()){re(t.name);try{const n=(await L.post("/api/routing-presets/anthropic/apply",{name:t.name})).data.config;n?(o(n),j(ne(n)),W(((r=n.routingPresets)==null?void 0:r.anthropic)??[])):j(c=>({...c,anthropic:F(t.modelRoutes)})),u({title:s("modelManagement.toast.presetApplySuccess",{name:t.name}),variant:"success"})}catch(d){u({title:s("modelManagement.toast.presetApplyFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{re(null),m.refetch()}}},Se=async t=>{if(!(!O()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:t.name})))){l(t.name);try{const n=(await L.delete(`/api/routing-presets/anthropic/${encodeURIComponent(t.name)}`)).data.presets??[];he(n),u({title:s("modelManagement.toast.presetDeleteSuccess",{name:t.name}),variant:"success"})}catch(d){u({title:s("modelManagement.toast.presetDeleteFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{l(null),m.refetch()}}},Re=()=>{O()&&(H("create"),B(void 0),A(!0))},Ae=()=>{O()&&(g(""),N(null),p(!0))},Ee=t=>{O()&&(H("edit"),B(t),A(!0))},Pe=async()=>{if(!a){u({title:s("settings.toast.missingConfig"),variant:"error"});return}const t=b.trim();if(!t){N(s("providers.quickAddHuawei.validation.apiKey"));return}const n={id:we("huawei-cloud"),label:s("providers.quickAddHuawei.providerLabel"),baseUrl:"https://api.modelarts-maas.com/v1",apiKey:t,type:"huawei",defaultModel:"deepseek-v3.1",models:[{id:"deepseek-v3.1",label:"DeepSeek V3.1"},{id:"KIMI-K2",label:"KIMI-K2"},{id:"qwen3-235b-a22b",label:"Qwen3 235B A22B"}]},c={...a,providers:[...a.providers,n]};try{X(!0),await L.put("/api/config",c),o(c),j(ne(c)),p(!1),u({title:s("providers.quickAddHuawei.toast.success"),description:s("providers.quickAddHuawei.toast.added",{name:n.label||n.id}),variant:"success"}),m.refetch()}catch(f){N(f instanceof Error?f.message:s("providers.quickAddHuawei.toast.failure"))}finally{X(!1)}},Ue=async t=>{if(!a)throw new Error(s("settings.toast.missingConfig"));const r=$==="create"?[...v,t]:v.map(c=>P&&c.id===P.id?{...t,id:P.id}:c),d={...a,providers:r};await L.put("/api/config",d),o(d),j(ne(d)),m.refetch();const n=$==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});u({title:n,variant:"success"})},Ie=async t=>{Z(t.id);try{const r=await L.post(`/api/providers/${t.id}/test`);r.data.ok?u({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:r.data.status,duration:r.data.durationMs?`${r.data.durationMs} ms`:"—"}),variant:"success"}):u({title:s("providers.toast.testFailure",{message:`${r.data.status} ${r.data.statusText}`}),variant:"error"})}catch(r){u({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{Z(null)}},De=async t=>{var h,w,D,I;if(!O()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const d=v.filter(y=>y.id!==t.id),n=y=>{const Y={};if(!y)return Y;for(const[Fe,oe]of Object.entries(y)){if(!oe)continue;const[fe]=oe.split(":");fe&&fe===t.id||oe===t.id||(Y[Fe]=oe)}return Y},c=(a==null?void 0:a.endpointRouting)??{},f=n(((h=c.anthropic)==null?void 0:h.modelRoutes)??(a==null?void 0:a.modelRoutes)??{}),k=n(((w=c.openai)==null?void 0:w.modelRoutes)??{}),U={...a,providers:d,modelRoutes:f,endpointRouting:{anthropic:{defaults:((D=c.anthropic)==null?void 0:D.defaults)??a.defaults,modelRoutes:f},openai:{defaults:((I=c.openai)==null?void 0:I.defaults)??a.defaults,modelRoutes:k}}};try{await L.put("/api/config",U),o(U),j({anthropic:F(f),openai:F(k)}),u({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(y){u({title:s("providers.toast.deleteFailure",{message:y instanceof Error?y.message:"unknown"}),variant:"error"})}},Ke=t=>{j(r=>({...r,[t]:[...r[t],{id:me(),source:"",target:""}]})),E(r=>({...r,[t]:null}))},Te=(t,r)=>{j(d=>d[t].some(n=>n.source.trim()===r.trim())?d:{...d,[t]:[...d[t],{id:me(),source:r,target:""}]}),E(d=>({...d,[t]:null}))},de=(t,r,d,n)=>{j(c=>({...c,[t]:c[t].map(f=>f.id===r?{...f,[d]:n}:f)})),E(c=>({...c,[t]:null}))},$e=(t,r)=>{j(d=>({...d,[t]:d[t].filter(n=>n.id!==r)})),E(d=>({...d,[t]:null}))},Oe=t=>{var c;if(!a)return;const r=a.endpointRouting??{},d=t==="anthropic"?a.modelRoutes??{}:{},n=((c=r[t])==null?void 0:c.modelRoutes)??d;j(f=>({...f,[t]:F(n)})),E(f=>({...f,[t]:null}))},Le=async t=>{var n,c,f,k,U;if(!O())return;const r=K[t],d={};for(const h of r){const w=h.source.trim(),D=h.target.trim();if(!(!w&&!D)){if(!w||!D){E(I=>({...I,[t]:s("settings.validation.routePair")}));return}if(d[w]){E(I=>({...I,[t]:s("settings.validation.routeDuplicate",{model:w})}));return}d[w]=D}}E(h=>({...h,[t]:null})),z(t);try{const h=a.endpointRouting??{anthropic:{defaults:a.defaults,modelRoutes:a.modelRoutes??{}},openai:{defaults:((c=(n=a.endpointRouting)==null?void 0:n.openai)==null?void 0:c.defaults)??a.defaults,modelRoutes:((k=(f=a.endpointRouting)==null?void 0:f.openai)==null?void 0:k.modelRoutes)??{}}},w={...h,[t]:{defaults:((U=h[t])==null?void 0:U.defaults)??a.defaults,modelRoutes:d}},D={...a,endpointRouting:w,modelRoutes:t==="anthropic"?d:a.modelRoutes??{}};await L.put("/api/config",D),o(D),j(I=>({...I,[t]:F(d)})),u({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}catch(h){u({title:s("modelManagement.toast.routesSaveFailure",{message:h instanceof Error?h.message:"unknown"}),variant:"error"})}finally{z(null)}},qe=()=>e.jsxs("section",{className:"space-y-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("providers.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:s("providers.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:s("providers.count",{count:ye})}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:Ae,children:s("providers.quickAddHuawei.button")}),e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:Re,children:s("providers.actions.add")})]})]}),m.isPending||!a&&m.isFetching?e.jsx("section",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-slate-200 bg-white text-sm text-slate-500 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-400",children:s("common.loading")}):v.length===0?e.jsx("section",{className:"rounded-lg border border-dashed border-slate-300 bg-white p-8 text-sm text-slate-500 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-400",children:s("providers.emptyState")}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:v.map(t=>e.jsxs("article",{className:"flex h-full flex-col gap-4 rounded-lg border border-slate-200 bg-white p-5 shadow-sm transition hover:shadow-md dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-semibold",children:t.label||t.id}),t.type?e.jsx(We,{type:t.type}):null]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["ID:",t.id]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["Base URL:",e.jsx("span",{className:"break-all text-slate-600 dark:text-slate-300",children:t.baseUrl})]})]}),e.jsx("div",{className:"flex flex-col gap-2 text-xs text-slate-500 dark:text-slate-400",children:t.defaultModel?e.jsx("span",{className:"inline-flex items-center rounded-full bg-emerald-100 px-2 py-0.5 font-medium text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200",children:s("providers.card.defaultModel",{model:je.get(t.id)??t.defaultModel})}):e.jsx("span",{className:"inline-flex items-center rounded-full bg-slate-100 px-2 py-0.5 font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300",children:s("providers.card.noDefault")})})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("ul",{className:"flex flex-wrap gap-2",children:t.models.map(r=>e.jsx("li",{className:"flex items-center gap-2 rounded-md border border-slate-200 bg-slate-50 px-3 py-1 text-xs dark:border-slate-700 dark:bg-slate-800/60",children:e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:ve(r)})},r.id))}):e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("providers.card.noModels")})]}),e.jsxs("footer",{className:"mt-auto flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",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",onClick:()=>Ee(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>Ie(t),disabled:Q===t.id,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition enabled:hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-60 dark:border-slate-700 dark:enabled:hover:bg-slate-800",children:Q===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:"rounded-md border border-red-200 px-3 py-1 text-sm text-red-600 transition hover:bg-red-50 dark:border-red-800 dark:text-red-300 dark:hover:bg-red-900/40",onClick:()=>De(t),children:s("providers.actions.delete")})]})]},t.id))})]}),He=()=>e.jsxs("div",{className:"space-y-3 rounded-md border border-dashed border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:s("modelManagement.presets.title")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("modelManagement.presets.description")})]}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center",children:[e.jsx("input",{type:"text",value:ee,onChange:t=>Ne(t.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:"w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100 md:w-56",disabled:V}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-md bg-blue-600 px-3 py-2 text-sm font-medium text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:V,children:s(V?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),se?e.jsx("p",{className:"text-xs text-red-500",children:se}):null,J.length===0?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("modelManagement.presets.empty")}):e.jsx("div",{className:"flex flex-wrap gap-2",children:J.map(t=>{const r=ce===t.name,d=le===t.name;return e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-slate-200 bg-white px-3 py-2 text-sm shadow-sm dark:border-slate-700 dark:bg-slate-900",children:[e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:t.name}),e.jsx("button",{type:"button",onClick:()=>Ce(t),className:"rounded-md bg-blue-500 px-2 py-1 text-xs font-medium text-white transition hover:bg-blue-600 disabled:opacity-60",disabled:r||d,children:s(r?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>Se(t),className:"rounded-md border border-slate-200 px-2 py-1 text-xs text-slate-600 transition hover:bg-slate-100 disabled:opacity-60 dark:border-slate-600 dark:text-slate-300 dark:hover:bg-slate-800",disabled:d||r,children:s(d?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]},t.name)})})]}),_e=t=>{const r=K[t],d=_[t],n=t==="anthropic"?Ve:Ye,c=ie===t,f=s(`modelManagement.tabs.${t}`),k=`route-source-${t}`,U=`route-target-${t}`;return e.jsxs("section",{className:"space-y-4 rounded-lg border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("settings.routing.titleByEndpoint",{endpoint:f})}),e.jsx("p",{className:"max-w-3xl text-xs text-slate-500 dark:text-slate-400",children:s(`settings.routing.descriptionByEndpoint.${t}`)})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsx("button",{type:"button",onClick:()=>Ke(t),className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>Oe(t),className:"rounded-md border border-slate-200 px-3 py-1 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:c,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Le(t),className:"rounded-md bg-blue-600 px-3 py-1 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:c,children:s(c?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),t==="anthropic"?He():null,d?e.jsx("p",{className:"text-xs text-red-500",children:d}):null,r.length===0?e.jsx("p",{className:"rounded-md border border-dashed border-slate-200 bg-slate-50 px-3 py-6 text-center text-sm text-slate-500 dark:border-slate-700 dark:bg-slate-800/60 dark:text-slate-300",children:s("settings.routing.empty")}):e.jsx("div",{className:"grid gap-3",children:r.map(h=>e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-xs",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:s("settings.routing.source")}),e.jsx("input",{type:"text",value:h.source,onChange:w=>de(t,h.id,"source",w.target.value),className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100",placeholder:"claude-3.5-sonnet",list:k,disabled:c})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-xs",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:s("settings.routing.target")}),(()=>{const w=h.target.trim(),I=pe.some(y=>y.value===w)?w:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:I,onChange:y=>{const Y=y.target.value;Y==="__custom"?de(t,h.id,"target",w):de(t,h.id,"target",Y)},className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100",disabled:c,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),pe.map(y=>e.jsx("option",{value:y.value,children:y.label},`${U}-${y.value}`))]}),I==="__custom"&&e.jsx("input",{type:"text",value:h.target,onChange:y=>de(t,h.id,"target",y.target.value),className:"mt-2 rounded-md border border-slate-200 bg-slate-50 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 dark:border-slate-700 dark:bg-slate-900/80 dark:text-slate-100",placeholder:"providerId:modelId",disabled:c})]})})()]}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:"rounded-md border border-slate-200 px-3 py-2 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",onClick:()=>$e(t,h.id),disabled:c,children:s("settings.routing.remove")})})]},h.id))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:s("settings.routing.suggested")}),n.map(h=>e.jsx("button",{type:"button",onClick:()=>Te(t,h),className:"rounded-md border border-slate-200 px-2 py-1 text-xs text-slate-600 transition hover:bg-slate-100 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800",disabled:c,children:h},`${t}-${h}`))]}),e.jsx("datalist",{id:k,children:n.map(h=>e.jsx("option",{value:h},`${k}-${h}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("header",{className:"flex flex-col gap-2",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:s("modelManagement.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:s("modelManagement.description")})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:R.map(t=>{const r=C===t.key;return e.jsxs("button",{type:"button",onClick:()=>q(t.key),className:`flex min-w-[200px] flex-col gap-1 rounded-lg border px-4 py-3 text-left transition ${r?"border-blue-500 bg-blue-50 text-blue-700 dark:border-blue-400 dark:bg-blue-900/30 dark:text-blue-100":"border-slate-200 hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800"}`,children:[e.jsx("span",{className:"text-sm font-semibold",children:t.label}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:t.description})]},t.key)})}),C==="providers"?qe():_e(C),e.jsx(Ge,{open:M,mode:$,provider:$==="edit"?P:void 0,existingProviderIds:v.map(t=>t.id).filter(t=>$==="edit"&&P?t!==P.id:!0),onClose:()=>{A(!1),B(void 0),H("create")},onSubmit:Ue}),e.jsx(Je,{open:i,apiKey:b,onApiKeyChange:t=>{g(t),S&&N(null)},loading:T,error:S,onClose:()=>{T||(p(!1),N(null))},onSubmit:Pe})]})}function Je({open:s,apiKey:u,onApiKeyChange:m,loading:R,error:C,onClose:q,onSubmit:a}){const{t:o}=xe();return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:q,"aria-hidden":"true"}),e.jsxs("aside",{role:"dialog","aria-modal":"true","aria-labelledby":"quick-add-huawei",className:"flex h-full w-full max-w-md flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"quick-add-huawei",className:"text-lg font-semibold",children:o("providers.quickAddHuawei.title")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.quickAddHuawei.description")})]}),e.jsx("button",{type:"button",onClick:q,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",disabled:R,children:o("common.actions.close")})]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-4 px-6 py-5 text-sm",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.quickAddHuawei.apiKeyLabel")}),e.jsx("input",{type:"password",value:u,onChange:M=>m(M.target.value),placeholder:o("providers.quickAddHuawei.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40",disabled:R})]}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.quickAddHuawei.note")}),C?e.jsx("p",{className:"text-xs text-red-500",children:C}):null]}),e.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("button",{type:"button",onClick:q,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:R,children:o("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:R,children:o(R?"common.actions.saving":"providers.quickAddHuawei.submit")})]})]})]}):null}function ve(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function We({type:s}){const u={openai:"OpenAI",deepseek:"DeepSeek",huawei:"华为云",kimi:"Kimi",anthropic:"Anthropic",custom:"Custom"};return e.jsx("span",{className:"rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300",children:u[s]??s})}export{et as default};
|