@chenpu17/cc-gw 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +5 -5
- package/src/web/dist/assets/{About-CTbbI3Xf.js → About-DUvmHkXW.js} +1 -1
- package/src/web/dist/assets/ApiKeys--jCty6ZH.js +1 -0
- package/src/web/dist/assets/{ConfirmDialog-DW7jBfm1.js → ConfirmDialog-Dwx6RgvT.js} +1 -1
- package/src/web/dist/assets/Dashboard-JKAR2hcD.js +1 -0
- package/src/web/dist/assets/{DialogShell-BqzUE3vU.js → DialogShell-DpB7I936.js} +1 -1
- package/src/web/dist/assets/EChart-B2VLuu4H.js +1 -0
- package/src/web/dist/assets/{Events-19qjsHJf.js → Events-COTOWRsF.js} +1 -1
- package/src/web/dist/assets/{Help-FrXAXPhx.js → Help-mc9elk2p.js} +2 -2
- package/src/web/dist/assets/{Login-BYpsX-S8.js → Login-CHt4FZ25.js} +1 -1
- package/src/web/dist/assets/Logs-ZWbE_Oab.js +1 -0
- package/src/web/dist/assets/ModelManagement-DLeiN23D.js +1 -0
- package/src/web/dist/assets/{PageHeader-DDxjKW4B.js → PageHeader-DipLZp28.js} +1 -1
- package/src/web/dist/assets/{PageSection-DRyQEnmK.js → PageSection-q7kP54e8.js} +1 -1
- package/src/web/dist/assets/{PageState-DA98vXl7.js → PageState-CiCo8uzV.js} +1 -1
- package/src/web/dist/assets/{Profiler-D5P7FF0I.js → Profiler-tMLEINUS.js} +1 -1
- package/src/web/dist/assets/RoutingManagement-BGVGRnZ_.js +1 -0
- package/src/web/dist/assets/{Settings-D8Xgk7cH.js → Settings-CLz6BWYx.js} +1 -1
- package/src/web/dist/assets/{Skeleton-D_opZxQ7.js → Skeleton-9uhP36eN.js} +1 -1
- package/src/web/dist/assets/{badge-B-TfGxGB.js → badge-CUJnXP--.js} +1 -1
- package/src/web/dist/assets/{card-I07afQF2.js → card-Vz-Wm3NU.js} +1 -1
- package/src/web/dist/assets/{charts-core-C-3-Lo7l.js → charts-core-D_rRW-0W.js} +1 -1
- package/src/web/dist/assets/{charts-engine-BI1CmRJo.js → charts-engine-BXnGh0aE.js} +1 -1
- package/src/web/dist/assets/{charts-react-DJ_0LNAP.js → charts-react-t97X9Vfc.js} +1 -1
- package/src/web/dist/assets/{gateway-CkqHb_VE.js → gateway-D8Ly9AH3.js} +1 -1
- package/src/web/dist/assets/{i18n-C7VVFIdN.js → i18n-dgCQR_PB.js} +1 -1
- package/src/web/dist/assets/index-BYn7J5K_.js +61 -0
- package/src/web/dist/assets/index-UZDzrtNM.css +1 -0
- package/src/web/dist/assets/{input-DZMeIHxj.js → input-BpqO0M53.js} +1 -1
- package/src/web/dist/assets/{label-DZr7itdg.js → label-G00TC871.js} +1 -1
- package/src/web/dist/assets/{popover-_LyL4tgU.js → popover-Dhl3J4mH.js} +1 -1
- package/src/web/dist/assets/{query-DxhDvnDC.js → query-Db16w3tH.js} +1 -1
- package/src/web/dist/assets/{radix-CmyU-WBH.js → radix-D08JKSgz.js} +1 -1
- package/src/web/dist/assets/{router-D8u_RlVh.js → router-BURlSZbt.js} +2 -2
- package/src/web/dist/assets/{select-BUvJR07s.js → select-D49a8SjJ.js} +1 -1
- package/src/web/dist/assets/{switch-BpfcwR9i.js → switch-tXufYzT3.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-BzbOtl4s.js → useApiQuery-Dqxujlur.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-D8Mjcv9t.js → useAppMutation-D-iOmckM.js} +1 -1
- package/src/web/dist/assets/useModelManagementState-B58fytAY.js +1 -0
- package/src/web/dist/assets/utils-BHook6QN.js +1 -0
- package/src/web/dist/assets/{vendor-5iCEqDpV.js → vendor-DfnQOGOQ.js} +78 -63
- package/src/web/dist/index.html +7 -7
- package/src/web/dist/assets/ApiKeys-Dca6MyO2.js +0 -1
- package/src/web/dist/assets/Dashboard-DMo-YHgS.js +0 -1
- package/src/web/dist/assets/EChart-VRAvk6sX.js +0 -1
- package/src/web/dist/assets/Logs-ynLMNHgv.js +0 -1
- package/src/web/dist/assets/ModelManagement-DrE_4kky.js +0 -1
- package/src/web/dist/assets/index-8bCfrPhk.css +0 -1
- package/src/web/dist/assets/index-CYeQpt9d.js +0 -61
- package/src/web/dist/assets/utils-DQfq7gRo.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,r as h,av as me,U as ue}from"./vendor-DfnQOGOQ.js";import{L as pe}from"./router-BURlSZbt.js";import{C as xe}from"./ConfirmDialog-Dwx6RgvT.js";import{P as he}from"./PageHeader-DipLZp28.js";import{B as v,c as $}from"./index-BYn7J5K_.js";import{B as E}from"./badge-CUJnXP--.js";import{C as G,a as W}from"./card-Vz-Wm3NU.js";import{I as be}from"./input-BpqO0M53.js";import{L as K}from"./label-G00TC871.js";import{S as fe,a as ge,b as ve,c as ye,d as N}from"./select-D49a8SjJ.js";import{r as je,u as Ne}from"./useModelManagementState-B58fytAY.js";import{u as R}from"./i18n-dgCQR_PB.js";import{D as we,A as ke,a as Me,b as Ce,c as De,d as Te,e as Pe}from"./DialogShell-DpB7I936.js";import{S as Ae}from"./switch-tXufYzT3.js";import"./query-Db16w3tH.js";import"./radix-D08JKSgz.js";import"./gateway-D8Ly9AH3.js";import"./queryKeys-BMvyDTQS.js";import"./useAppMutation-D-iOmckM.js";import"./useApiQuery-Dqxujlur.js";function Se({providersLength:l,filteredProviders:a,defaultLabels:m,providerSearch:f,providerTypeFilter:b,configPending:C,testingProviderId:s,onOpenEdit:d,onTestConnection:u,onRequestDelete:p,onProviderSearchChange:w,onProviderTypeChange:D,onResetFilters:k}){const{t:c}=R(),T=o=>{const g=o.authMode??(o.type==="anthropic"?"authToken":"apiKey");return g==="authToken"?"Bearer":g==="xAuthToken"?"X-Auth-Token":o.type==="anthropic"?"X-API-Key":c("providers.card.providerDefault")};return e.jsx(G,{children:e.jsxs(W,{className:"space-y-6 pt-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2 xl:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(K,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:c("providers.filters.searchPlaceholder")}),e.jsx(be,{value:f,onChange:o=>w(o.target.value),placeholder:c("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(K,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:c("providers.filters.typeAll")}),e.jsxs(fe,{value:b,onValueChange:D,children:[e.jsx(ge,{children:e.jsx(ve,{})}),e.jsxs(ye,{children:[e.jsx(N,{value:"all",children:c("providers.filters.typeAll")}),e.jsx(N,{value:"openai",children:"OpenAI"}),e.jsx(N,{value:"anthropic",children:"Anthropic"}),e.jsx(N,{value:"deepseek",children:"DeepSeek"}),e.jsx(N,{value:"huawei",children:"Huawei"}),e.jsx(N,{value:"kimi",children:"Kimi"}),e.jsx(N,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end sm:col-span-2 xl:col-span-1",children:e.jsx(v,{variant:"ghost",size:"sm",onClick:k,disabled:!f.trim()&&b==="all",className:"w-full xl:w-auto",children:c("common.actions.reset")})})]}),C?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-border bg-secondary text-sm text-muted-foreground",children:c("common.loading")}):l===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:c("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:c("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):a.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:c("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:a.map(o=>{var g;return e.jsx(G,{className:"flex flex-col overflow-hidden","data-testid":"provider-card",children:e.jsxs(W,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:o.label||o.id}),o.type?e.jsx(Ue,{type:o.type}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",o.id]}),e.jsx("code",{className:"block max-w-full break-all rounded-lg border border-border bg-secondary px-2.5 py-1.5 text-[11px] text-muted-foreground",children:o.baseUrl})]}),o.defaultModel?e.jsx(E,{variant:"default",className:"text-xs",children:m.get(o.id)??o.defaultModel}):e.jsx(E,{variant:"secondary",className:"text-xs",children:c("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(S,{label:c("providers.card.authMode"),value:T(o)}),e.jsx(S,{label:c("providers.card.modelsTitle"),value:(g=o.models)!=null&&g.length?c("providers.card.modelCount",{count:o.models.length}):c("providers.card.passthrough")}),e.jsx(S,{label:c("providers.card.defaultModelLabel"),value:o.defaultModel?m.get(o.id)??o.defaultModel:c("providers.card.noDefault"),truncate:!0})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsx(S,{label:"Routing readiness",value:o.defaultModel?"Ready":"Needs default"}),e.jsx(S,{label:"Endpoint type",value:o.type?o.type:"custom"})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-3",children:[e.jsx(K,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:c("providers.card.modelsTitle")}),o.models&&o.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:o.models.map(M=>e.jsx(E,{variant:"outline",className:"text-xs",children:je(M)},M.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:c("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto grid gap-2 border-t border-border pt-4 sm:grid-cols-3",children:[e.jsx(v,{variant:"default",size:"sm",onClick:()=>d(o),className:"w-full",children:c("providers.actions.edit")}),e.jsx(v,{variant:"outline",size:"sm",onClick:()=>u(o),disabled:s===o.id,className:"w-full",children:s===o.id?c("common.actions.testingConnection"):c("providers.actions.test")}),e.jsx(v,{variant:"destructive",size:"sm",onClick:()=>p(o),className:"w-full",children:c("providers.actions.delete")})]})]})},o.id)})})]})})}function S({label:l,value:a,truncate:m}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:l}),e.jsx("p",{className:$("mt-1 text-sm font-medium",m&&"truncate"),children:a})]})}function Ue({type:l}){const a={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:m,variant:f}=a[l]||a.custom;return e.jsx(E,{variant:f,className:"text-xs",children:m})}function Ie({open:l,provider:a,options:m,usePreset:f,preservedExtras:b,onPresetChange:C,onConfirm:s,onClose:d}){const{t:u}=R();return a?e.jsx(we,{open:l,onOpenChange:p=>!p&&d(),children:e.jsxs(ke,{className:"max-w-2xl",children:[e.jsxs(Me,{children:[e.jsx(Ce,{children:u("providers.testDialog.title")}),e.jsx(De,{children:u("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsxs(Te,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-primary",children:u("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(K,{htmlFor:"provider-test-preset",children:u("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ae,{id:"provider-test-preset",checked:f,onCheckedChange:C})})]}),f?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-lg border border-border bg-secondary p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:u("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:m.map(p=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1 text-xs",children:[p.key,": ",p.value]},p.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:u("providers.testDialog.presetDescription")})]}),Object.keys(b).length>0&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:u("providers.testDialog.preservedInfo")}),Object.entries(b).map(([p,w])=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1",children:[p,": ",w]},p))]})]}),e.jsxs(Pe,{children:[e.jsx(v,{variant:"outline",onClick:d,children:u("providers.testDialog.cancel")}),e.jsx(v,{onClick:()=>void s(),children:u("providers.testDialog.primary")})]})]})}):null}function z(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Ee(){return{_key:z(),id:"",label:""}}const I={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},J=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}];function L(l){return l==="anthropic"?"authToken":"apiKey"}function Z(l){return l?{id:l.id,label:l.label??l.id,baseUrl:l.baseUrl,apiKey:l.apiKey??"",type:l.type??"custom",defaultModel:l.defaultModel??"",models:(l.models??[]).map(a=>({...a,_key:z()})),authMode:l.authMode??L(l.type??"custom")}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:L("custom")}}function Ke(l){return{_key:z(),id:l.id,label:l.label}}function Le({open:l,mode:a,provider:m,existingProviderIds:f,onClose:b,onSubmit:C}){const{t:s}=R(),[d,u]=h.useState(()=>Z(m)),[p,w]=h.useState({}),[D,k]=h.useState(!1),[c,T]=h.useState(null),o=h.useRef(null),g=h.useRef(null),M=h.useRef(null),[P,q]=h.useState(a==="edit");h.useEffect(()=>{l&&(u(Z(m)),w({}),T(null),k(!1),q(a==="edit"))},[l,m,a]),h.useEffect(()=>{if(!l)return;const r=t=>{t.key==="Escape"&&b()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[l,b]),h.useEffect(()=>{if(l){if(a==="create"&&M.current){M.current.focus();return}g.current&&g.current.focus()}},[l,a]);const O=a==="create",_=h.useMemo(()=>d.models.filter(r=>r.id.trim().length>0),[d.models]),V=h.useMemo(()=>{var r;return((r=J.find(t=>t.value===d.type))==null?void 0:r.label)??"Custom"},[d.type]),X=(r,t)=>s(t==="authToken"?"providers.drawer.fields.authModeAuthToken":t==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":r==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault"),ee=d.label.trim()||d.id.trim()||s("providers.drawer.summary.untitled"),Q=h.useMemo(()=>[{label:s("providers.drawer.summary.type"),value:V},{label:s("providers.drawer.summary.auth"),value:X(d.type,d.authMode)},{label:s("providers.drawer.summary.models"),value:_.length.toLocaleString()}],[_.length,d.authMode,d.type,V,s]),B=r=>t=>{u(n=>({...n,[r]:t}))},re=r=>{u(t=>{const i=!P||t.label.trim().length===0||t.label===t.id?r:t.label;return{...t,id:r,label:i}})},se=r=>{u(t=>{var Y;const i=I[r??"custom"]??I.custom,x=L(t.type),y=L(r),j=Object.values(I).map(A=>A.baseUrl).filter(A=>!!A),F=!t.baseUrl||j.includes(t.baseUrl),ce=a==="create"&&(t.models.length===0||t.models.every(A=>A.id.trim().length===0)),U={...t,type:r,authMode:t.authMode===x?y:t.authMode};return i!=null&&i.baseUrl&&F&&(U.baseUrl=i.baseUrl),i!=null&&i.models&&ce&&(U.models=i.models.map(Ke),U.defaultModel=i.defaultModel??((Y=i.models[0])==null?void 0:Y.id)??""),U})},ae=(r,t)=>{u(n=>{const i=[...n.models];return i[r]={...i[r],...t},{...n,models:i}})},de=(r,t)=>{u(n=>{const i=[...n.models],x=i[r];if(!x)return n;const y=!P||!x.label||x.label===x.id,j={...x,id:t,label:y?t:x.label};i[r]=j;const F=n.defaultModel===x.id?t:n.defaultModel;return{...n,models:i,defaultModel:F}})},te=r=>{u(t=>{if(r<0||r>=t.models.length)return t;const n=t.models.filter((x,y)=>y!==r);let i=t.defaultModel;return n.some(x=>x.id===i)||(i=""),{...t,models:n,defaultModel:i}})},le=()=>{u(r=>({...r,models:[...r.models,Ee()]}))},H=r=>{u(t=>({...t,authMode:r}))},oe=()=>{const r={},t=d.id.trim(),n=d.baseUrl.trim();if(a==="create"&&(t.length===0?r.id=s("providers.drawer.errors.idRequired"):f.includes(t)&&(r.id=s("providers.drawer.errors.idDuplicate"))),a==="edit"&&t.length===0&&(r.id=s("providers.drawer.errors.idRequired")),n.length===0)r.baseUrl=s("providers.drawer.errors.baseUrlInvalid");else try{new URL(n)}catch{r.baseUrl=s("providers.drawer.errors.baseUrlInvalid")}if(d.models.length>0){const i=new Set;d.models.some(y=>{const j=y.id.trim();return j.length===0||i.has(j)?!0:(i.add(j),!1)})&&(r.models=s("providers.drawer.errors.modelInvalid"))}return d.defaultModel&&!d.models.some(i=>i.id===d.defaultModel)&&(r.models=s("providers.drawer.errors.defaultInvalid")),w(r),Object.keys(r).length===0},ie=()=>{const r=d.models.map(i=>{var x;return{id:i.id.trim(),label:(x=i.label)!=null&&x.trim()?i.label.trim():void 0}}).filter(i=>i.id.length>0),t=m!=null&&m.extraHeaders&&Object.keys(m.extraHeaders).length>0?m.extraHeaders:void 0,n=d.authMode==="apiKey"&&d.type!=="anthropic"?void 0:d.authMode;return{id:d.id.trim(),label:d.label.trim()||d.id.trim(),baseUrl:d.baseUrl.trim(),apiKey:d.apiKey.trim()||void 0,type:d.type??"custom",defaultModel:d.defaultModel||void 0,models:r.length>0?r:void 0,extraHeaders:t,authMode:n}},ne=async()=>{if(T(null),!!oe()){k(!0);try{const r=ie();await C(r)}catch(r){T(s("providers.drawer.toast.saveFailure",{message:r instanceof Error?r.message:"unknown"})),k(!1);return}k(!1),b()}};return l?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:b,"aria-hidden":"true"}),e.jsxs("aside",{ref:o,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full min-h-0 w-full max-w-5xl flex-col border-l border-border bg-background shadow-lg",children:[e.jsxs("header",{className:"border-b border-border bg-secondary px-6 py-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:s(O?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:s(O?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:s("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:g,onClick:b,className:"rounded-full border border-border bg-card px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-accent/50",children:s("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:Q.map(r=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"min-h-0 overflow-y-auto px-6 py-5 pb-10",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:s("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:J.map(r=>{var n;const t=r.value===d.type;return e.jsxs("button",{type:"button",onClick:()=>se(r.value),className:$("rounded-2xl border px-4 py-3 text-left transition",t?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:r.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((n=I[r.value??"custom"])==null?void 0:n.baseUrl)??s("providers.drawer.hints.customProvider")})]},r.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:s("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>q(r=>!r),className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:s(P?"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-muted-foreground",children:s("providers.drawer.fields.id")}),e.jsx("input",{value:d.id,ref:M,onChange:r=>re(r.target.value),disabled:!O,placeholder:s("providers.drawer.fields.idPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!p.id}),p.id?e.jsx("span",{className:"text-xs text-red-500",children:p.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s("providers.drawer.fields.label")}),e.jsx("input",{value:d.label,onChange:r=>B("label")(r.target.value),placeholder:s("providers.drawer.fields.labelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:d.baseUrl,onChange:r=>B("baseUrl")(r.target.value),placeholder:s("providers.drawer.fields.baseUrlPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!p.baseUrl}),p.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:p.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:s("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s("providers.drawer.fields.apiKey")}),e.jsx("input",{value:d.apiKey,onChange:r=>B("apiKey")(r.target.value),placeholder:s("providers.drawer.fields.apiKeyPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-border bg-card p-4 text-xs",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:s("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:d.authMode==="apiKey",onChange:()=>H("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:X(d.type,"apiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:d.authMode==="authToken",onChange:()=>H("authToken"),className:"mt-0.5"}),e.jsx("span",{children:s("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:d.authMode==="xAuthToken",onChange:()=>H("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:s("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:s("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:le,className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:s("providers.drawer.fields.addModel")})]}),p.models?e.jsx("p",{className:"text-xs text-red-500",children:p.models}):null,e.jsxs("div",{className:"space-y-4",children:[d.models.map((r,t)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",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-muted-foreground",children:s("providers.drawer.fields.modelId")}),e.jsx("input",{value:r.id,onChange:n=>de(t,n.target.value),placeholder:s("providers.drawer.fields.modelIdPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),P?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:r.label??"",onChange:n=>ae(t,{label:n.target.value}),placeholder:s("providers.drawer.fields.modelLabelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}):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-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:r.id,checked:d.defaultModel===r.id,onChange:()=>u(n=>({...n,defaultModel:r.id})),disabled:r.id.trim().length===0}),s("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:()=>te(t),disabled:d.models.length===0,children:s("providers.drawer.fields.removeModel")})]})]},r._key)),d.models.length===0?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50/60 p-5 dark:border-amber-700/50 dark:bg-amber-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:s("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:s("providers.drawer.noModelsHint",{providerId:d.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md border border-border bg-secondary p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:s("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground",children:['"claude-*": "',(d.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),_.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:s("providers.drawer.defaultHint",{model:d.defaultModel||s("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden min-h-0 overflow-y-auto border-l border-border bg-secondary px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ee}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:Q.map(r=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:r.label}),e.jsx("span",{className:"text-right font-medium",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:s("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:s("providers.drawer.hints.checkModels")})]})]}),P&&e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:s("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border bg-secondary px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:c?e.jsx("span",{children:c}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:b,className:"rounded-full border border-border bg-card px-4 py-2 transition hover:border-primary/20 hover:bg-accent/50",disabled:D,children:s("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ne,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:D,children:s(D?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}function ar(){const{t:l}=R(),a=Ne();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(he,{icon:e.jsx(ue,{className:"h-5 w-5","aria-hidden":"true"}),title:l("providers.title"),description:l("providers.description"),eyebrow:l("modelManagement.providersEyebrow"),breadcrumb:"Gateway / Providers",badge:l("providers.count",{count:a.providerCount}),actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx(v,{asChild:!0,variant:"outline",className:"w-full sm:w-auto",children:e.jsxs(pe,{to:"/routing",children:[l("nav.routing"),e.jsx(me,{className:"h-4 w-4","aria-hidden":"true"})]})}),e.jsx(v,{onClick:a.handleOpenCreate,className:"w-full sm:w-auto",children:l("providers.actions.add")})]})}),e.jsx(Se,{configPending:a.configQuery.isPending||!a.config&&a.configQuery.isFetching,defaultLabels:a.defaultLabels,filteredProviders:a.filteredProviders,onOpenEdit:a.handleOpenEdit,onRequestDelete:m=>a.setConfirmAction({kind:"provider",provider:m}),onResetFilters:()=>{a.setProviderSearch(""),a.setProviderTypeFilter("all")},onProviderSearchChange:a.setProviderSearch,onProviderTypeChange:a.setProviderTypeFilter,onTestConnection:a.initiateTestConnection,providerSearch:a.providerSearch,providerTypeFilter:a.providerTypeFilter,providersLength:a.providers.length,testingProviderId:a.testingProviderId}),e.jsx(Le,{open:a.drawerOpen,mode:a.drawerMode,provider:a.drawerMode==="edit"?a.editingProvider:void 0,existingProviderIds:a.providers.map(m=>m.id).filter(m=>a.drawerMode==="edit"&&a.editingProvider?m!==a.editingProvider.id:!0),onClose:()=>{a.setDrawerOpen(!1),a.setEditingProvider(void 0),a.setDrawerMode("create")},onSubmit:a.handleProviderSubmit}),e.jsx(Ie,{open:a.testDialogOpen,provider:a.testDialogProvider,options:a.anthropicTestHeaderOptions,preservedExtras:a.testDialogPreservedExtras,usePreset:a.testDialogUsePreset,onPresetChange:a.setTestDialogUsePreset,onConfirm:a.confirmTestDialog,onClose:a.closeTestDialog}),e.jsx(xe,{open:!!a.confirmAction,onOpenChange:m=>{!m&&!a.confirmingAction&&a.setConfirmAction(null)},title:a.confirmDialogTitle,description:a.confirmDialogDescription,confirmLabel:a.confirmingAction?l("common.actions.loading"):l("common.delete"),cancelLabel:l("common.actions.cancel"),loading:a.confirmingAction,onConfirm:a.handleConfirmDialog,children:a.confirmDialogName?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:a.confirmDialogName}):null})]})}export{ar as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./vendor-
|
|
1
|
+
import{j as e}from"./vendor-DfnQOGOQ.js";import{c as i}from"./index-BYn7J5K_.js";import{B as c}from"./badge-CUJnXP--.js";function u({icon:l,title:x,description:t,badge:a,eyebrow:s,breadcrumb:r,helper:d,actions:n,className:m}){return e.jsxs("div",{className:i("flex flex-col gap-5 rounded-lg border border-border bg-card p-5 sm:flex-row sm:items-start sm:justify-between",m),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[l&&e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:l}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[(s||r)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[s?e.jsx("span",{children:s}):null,s&&r?e.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,r?e.jsx("span",{className:"text-muted-foreground/90",children:r}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:x}),a&&e.jsx(c,{variant:"secondary",children:a})]}),t&&e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:t}),d&&e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:d})]})]}),n&&e.jsx("div",{className:"w-full shrink-0 self-start sm:w-auto",children:n})]})}export{u as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./vendor-
|
|
1
|
+
import{j as s}from"./vendor-DfnQOGOQ.js";import{c as m}from"./index-BYn7J5K_.js";import{C as c,b as x,c as i,d as f,a as j}from"./card-Vz-Wm3NU.js";function b({title:a,description:e,eyebrow:d,actions:r,className:l,contentClassName:n,children:o}){const t=a||e||r;return s.jsxs(c,{className:m("overflow-hidden",l),children:[t&&s.jsxs(x,{className:"flex flex-col gap-4 border-b border-border bg-secondary sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[d?s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?s.jsx(i,{className:"text-base font-semibold",children:a}):a,e&&(typeof e=="string"?s.jsx(f,{children:e}):s.jsx("div",{className:"text-sm text-muted-foreground",children:e}))]}),r&&s.jsx("div",{className:"w-full shrink-0 sm:w-auto",children:r})]}),s.jsx(j,{className:m(!t&&"pt-6",t&&"pt-5",n),children:o})]})}export{b as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,P as c}from"./vendor-
|
|
1
|
+
import{j as e,P as c}from"./vendor-DfnQOGOQ.js";import{c as i}from"./index-BYn7J5K_.js";const m={default:"border-border bg-secondary",primary:"border-primary/15 bg-accent",danger:"border-destructive/20 bg-destructive/10"},x={default:"bg-secondary text-primary",primary:"bg-primary/10 text-primary",danger:"bg-destructive/10 text-destructive"};function o({icon:r,title:s,description:t,action:a,className:d,compact:l=!1,tone:n="default"}){return e.jsxs("div",{className:i("flex flex-col items-center justify-center rounded-lg border border-dashed px-6 text-center",l?"min-h-[180px] py-8":"min-h-[260px] py-12",m[n],d),children:[r?e.jsx("div",{className:i("mb-4 flex h-12 w-12 items-center justify-center rounded-2xl",x[n]),children:r}):null,e.jsxs("div",{className:"max-w-xl space-y-1.5",children:[e.jsx("div",{className:"text-base font-semibold tracking-[-0.01em]",children:s}),t?e.jsx("div",{className:"text-sm text-muted-foreground",children:t}):null]}),a?e.jsx("div",{className:"mt-5 flex flex-wrap items-center justify-center gap-2",children:a}):null]})}function p({label:r,className:s,compact:t=!1}){return e.jsx(o,{className:s,compact:t,tone:"primary",icon:e.jsx(c,{className:"h-5 w-5 animate-spin","aria-hidden":"true"}),title:r})}export{p as P,o as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as f,j as e,X as Y,am as ie,ay as Z,aH as oe,aI as de,S as ce,ar as xe,a1 as me,al as ue}from"./vendor-5iCEqDpV.js";import{u as pe,a as A,b as S}from"./query-DxhDvnDC.js";import{P as ee,a as M}from"./PageState-DA98vXl7.js";import{B as se}from"./badge-B-TfGxGB.js";import{h as F,b as q,r as O,c as m,B as $}from"./index-CYeQpt9d.js";import{d as he}from"./utils-DQfq7gRo.js";import{q as b}from"./queryKeys-BMvyDTQS.js";import"./i18n-C7VVFIdN.js";import"./router-D8u_RlVh.js";import"./radix-CmyU-WBH.js";const v={getStatus:()=>O({url:"/api/profiler/status",method:"GET"}),start:()=>F(q.post("/api/profiler/start")),stop:()=>F(q.post("/api/profiler/stop")),listSessions:s=>O({url:"/api/profiler/sessions",method:"GET",params:s}),getSession:s=>O({url:`/api/profiler/sessions/${s}`,method:"GET"}),deleteSession:s=>F(q.delete(`/api/profiler/sessions/${s}`)),clearAll:()=>F(q.post("/api/profiler/sessions/clear"))};function g(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(2)}s`:`${Math.round(s)}ms`}function I(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(1)}s`:`${Math.round(s)}ms`}function k(s){return s==null?"-":s.toLocaleString()}function K(s){return s==null?"-":s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function L(s){return s.endedAt==null||s.turnCount===0?s.totalLatencyMs??0:s.endedAt-s.startedAt}function fe(s){const t=s.sessionId;return t.length>18?`${t.slice(0,8)}…${t.slice(-6)}`:t}function be(s){const t=Math.max(0,Date.now()-s),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n} min ago`;const l=Math.floor(n/60);if(l<24)return`${l} hr ago`;const r=Math.floor(l/24);return`${r} day${r===1?"":"s"} ago`}function ge(s){if(!s)return null;try{return JSON.parse(s)}catch{return null}}function _(s,t){if(Array.isArray(s)){for(const n of s)_(n,t);return}if(s&&typeof s=="object"){const n=s,l=n.tool_calls;Array.isArray(l)&&t.push(...l);const r=n.content;if(Array.isArray(r)){for(const i of r)if(i&&typeof i=="object"){const a=i;a.type==="tool_use"&&t.push(a)}}for(const i of Object.values(n))_(i,t)}}function R(s){const t=[];return _(ge(s.clientResponse),t),t}function le(s,t){const n=s.timestamp-t,l=n+(s.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(l/1e3).toFixed(3)}s`}function Q(s,t){return he(s??null,t)}function je(s,t){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),l=URL.createObjectURL(n),r=document.createElement("a");r.href=l,r.download=s,r.click(),URL.revokeObjectURL(l)}function B({tone:s="default",children:t}){return e.jsx("span",{className:m("inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium",s==="accent"?"bg-indigo-100 text-indigo-700":"bg-slate-100 text-slate-600"),children:t})}function Ne({session:s,selected:t,index:n,onClick:l}){const r=["bg-indigo-500","bg-emerald-500","bg-amber-500"],i=t?"bg-indigo-500":r[n%r.length],a=(s.totalInputTokens??0)+(s.totalOutputTokens??0);return e.jsxs("button",{type:"button",onClick:l,className:m("w-full border-b border-border px-4 py-3 text-left transition-colors",t?"bg-indigo-50/70":"hover:bg-slate-50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("h-2 w-2 flex-shrink-0 rounded-full",i)}),e.jsx("span",{className:m("truncate text-sm font-semibold",t?"text-indigo-700":"text-slate-800"),children:fe(s)})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(s.startedAt)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[e.jsxs(B,{tone:t?"accent":"default",children:[s.turnCount," turns"]}),e.jsx(B,{children:I(L(s))}),e.jsxs(B,{children:[K(a)," tok"]})]})]})}function te({active:s,icon:t,label:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-slate-50 text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx(t,{className:"h-3.5 w-3.5"}),n]})}function D({active:s,label:t,count:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-transparent text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx("span",{children:t}),typeof n=="number"&&e.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-800",children:n})]})}function ve({detail:s,selectedTurn:t,onSelectTurn:n}){const l=s.records;if(l.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const r=L(s),i=Math.max(1,...l.map(a=>Math.max(a.latencyMs??0,a.ttftMs??0,1)));return Math.max(1,...l.map(a=>R(a).length)),e.jsxs("div",{className:"border-b border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-5 py-3",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Compressed overview · idle gaps folded · wraps as turns grow"}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"text-slate-500",children:"Mode:"}),e.jsx("span",{className:"rounded border border-slate-200 bg-slate-100 px-2 py-0.5 font-medium text-slate-700",children:"Compressed"}),e.jsxs("span",{className:"rounded border border-slate-200 bg-white px-2 py-0.5 font-medium text-slate-700",children:["Session ",I(r)]})]})]}),e.jsxs("div",{className:"px-5 pb-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between text-[10px] text-slate-400",children:[e.jsx("span",{children:"start"}),e.jsxs("span",{children:[(r/1e3).toFixed(1),"s"]})]}),e.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:l.map((a,u)=>{const p=u===t,y=Math.max(a.latencyMs??0,1),o=`${Math.max(28,Math.min(100,y/i*100))}%`,x=a.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(a.ttftMs,i)/i*100))}%`:null,C=Math.max(0,a.timestamp-s.startedAt),w=R(a);return e.jsxs("button",{type:"button",onClick:()=>n(u),className:m("border border-transparent px-1.5 py-1 text-left transition-colors",p?"rounded-md border-rose-300":"hover:bg-slate-50/40"),title:`Turn ${a.turnIndex+1}`,children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",p?"border-indigo-300 bg-indigo-100 text-indigo-700":"border-slate-200 bg-white text-slate-700"),children:a.turnIndex+1}),e.jsx("span",{className:"truncate text-[15px] font-semibold text-slate-800",children:I(a.latencyMs)})]})}),e.jsxs("p",{className:"mt-1 text-[10px] text-slate-500",children:["start ",(C/1e3).toFixed(1),"s"]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between text-[10px] text-slate-500",children:e.jsxs("span",{children:[g(a.ttftMs)," TTFT"]})}),e.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-slate-100",children:[e.jsx("div",{className:"h-4 rounded-sm bg-blue-200",style:{width:o}}),x!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 shadow-[0_0_0_1px_rgba(255,255,255,0.9)]",style:{left:x}}),e.jsx("span",{className:"absolute top-[-6px] h-2.5 w-2.5 -translate-x-1/2 rounded-full border border-white bg-violet-500",style:{left:x}})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[10px] text-slate-500",children:[e.jsx("span",{children:"Tools"}),e.jsx("span",{children:w.length})]}),e.jsx("div",{className:"flex h-5 items-center gap-1",children:e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[10px] font-semibold",w.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-slate-300 bg-white text-slate-500"),children:w.length})})]})]},a.id)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),"Total latency"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 shadow-[0_0_0_1px_rgba(139,92,246,0.35)]"}),"First token (TTFT)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),"Tool executing"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),"Selected turn"]})]})]})]})}function ye({detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:l,onSelectTurn:r}){const i=s.records[t];if(!i)return null;const a=R(i),u=(i.inputTokens??0)+(i.outputTokens??0),p=n==="request"?Q(i.clientRequest,"(empty request)"):n==="response"?Q(i.clientResponse,"(empty response)"):a.length>0?JSON.stringify(a,null,2):"(no tool calls)";return e.jsxs("div",{"data-testid":"profiler-turn-detail",className:"shrink-0 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-slate-200 bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[e.jsxs("span",{className:"rounded-full px-2 py-1 font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["Turn ",i.turnIndex+1]}),e.jsx("span",{className:"text-slate-500",children:le(i,s.startedAt)}),e.jsxs("span",{className:"rounded-full bg-violet-100 px-2 py-1 font-semibold text-violet-700",children:["TTFT ",g(i.ttftMs)]}),e.jsxs("span",{className:"rounded-full bg-blue-100 px-2 py-1 font-semibold text-blue-700",children:[K(u)," tokens"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("button",{type:"button",onClick:()=>r(Math.max(0,t-1)),disabled:t===0,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Previous turn",children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-10 text-center font-medium text-slate-600",children:[t+1," / ",s.records.length]}),e.jsx("button",{type:"button",onClick:()=>r(Math.min(s.records.length-1,t+1)),disabled:t===s.records.length-1,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Next turn",children:e.jsx(me,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"border-b border-slate-200 bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(D,{active:n==="request",label:"Request",onClick:()=>l("request")}),e.jsx(D,{active:n==="response",label:"Response",onClick:()=>l("response")}),e.jsx(D,{active:n==="tools",label:"Tool Calls",count:a.length,onClick:()=>l("tools")})]})}),e.jsxs("div",{className:"p-5",children:[e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:p}),i.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:i.error})]})]})}function we({detail:s,selectedTurn:t,detailTab:n,onSelectTurn:l,onDetailTabChange:r}){return e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsx(ve,{detail:s,selectedTurn:t,onSelectTurn:l}),e.jsx(ye,{detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:r,onSelectTurn:l})]})}function ne({title:s,payload:t,accentClass:n}){return e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:m("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",n),children:s}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:Q(t,"(empty)")})]})}function T({label:s,value:t,sub:n,accentClass:l}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-white p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:s}),e.jsx("p",{className:m("mt-2 text-2xl font-semibold text-slate-900",l),children:t}),n&&e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:n})]})}function Te({record:s,sessionStart:t,expanded:n,onToggle:l}){const r=R(s);return e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border bg-white",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-4 px-4 py-3 text-left hover:bg-slate-50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"rounded-full px-2 py-0.5 text-[11px] font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["T",s.turnIndex+1]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900",children:le(s,t)}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["Total ",g(s.latencyMs)]}),e.jsxs("span",{children:["TTFT ",g(s.ttftMs)]}),e.jsxs("span",{children:["TPOT ",s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"]}),e.jsxs("span",{children:["↑ ",k(s.inputTokens)]}),e.jsxs("span",{children:["↓ ",k(s.outputTokens)]}),e.jsxs("span",{children:[r.length," tool calls"]}),s.error&&e.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600",children:"Error"})]})]})]}),e.jsx(ue,{className:m("h-4 w-4 flex-shrink-0 text-slate-400 transition-transform",n&&"rotate-180")})]}),n&&e.jsxs("div",{className:"border-t border-border bg-slate-50/70 p-4",children:[e.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[e.jsx(ne,{title:"Request",payload:s.clientRequest,accentClass:"text-blue-600"}),e.jsx(ne,{title:"Response",payload:s.clientResponse,accentClass:"text-violet-600"})]}),e.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-amber-600",children:"Tool Calls"}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:r.length>0?JSON.stringify(r,null,2):"(no tool calls)"})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:"Turn Metrics"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Duration"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.latencyMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TTFT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.ttftMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TPOT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Status"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.statusCode??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Input"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.inputTokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Output"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.outputTokens)})]})]}),s.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:s.error})]})]})]})]})}function Me({detail:s,expandedTurn:t,onToggleTurn:n}){if(s.records.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const l=L(s),r=s.records.reduce((o,x)=>{const C=x.latencyMs??0,w=x.ttftMs??0;return o+Math.max(C-w,0)},0),i=l>0?(r/l*100).toFixed(1):"-",a=s.records.map(o=>o.ttftMs).filter(o=>o!=null),u=s.records.map(o=>o.tpotMs).filter(o=>o!=null),p=a.length>0?a.reduce((o,x)=>o+x,0)/a.length:null,y=u.length>0?u.reduce((o,x)=>o+x,0)/u.length:null;return e.jsxs("div",{className:"space-y-5 p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(T,{label:"Total Duration",value:g(l),sub:`${s.records.length} turns`}),e.jsx(T,{label:"LLM Time",value:g(r),sub:`${i}% of session`,accentClass:"text-violet-700"}),e.jsx(T,{label:"Avg TTFT",value:g(p)}),e.jsx(T,{label:"Avg TPOT",value:y!=null?`${y.toFixed(1)} ms/tok`:"-"}),e.jsx(T,{label:"Input Tokens",value:k(s.totalInputTokens)}),e.jsx(T,{label:"Output Tokens",value:k(s.totalOutputTokens)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Per-Turn Breakdown"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Expand a turn to inspect request, response, tool calls, and errors."})]})}),s.records.map(o=>e.jsx(Te,{record:o,sessionStart:s.startedAt,expanded:t===o.turnIndex,onToggle:()=>n(o.turnIndex)},o.id))]})]})}function Ee(){var H,X;const s=pe(),[t,n]=f.useState(null),[l,r]=f.useState("timeline"),[i,a]=f.useState("request"),[u,p]=f.useState(0),[y,o]=f.useState(0),[x,C]=f.useState(""),h=((H=A({queryKey:b.profiler.status(),queryFn:()=>v.getStatus(),refetchInterval:3e3}).data)==null?void 0:H.active)??!1,J=A({queryKey:b.profiler.sessions({}),queryFn:()=>v.listSessions({limit:100}),refetchInterval:h?2e3:!1}),j=((X=J.data)==null?void 0:X.items)??[],P=A({queryKey:b.profiler.session(t),queryFn:()=>v.getSession(t),enabled:t!=null,refetchInterval:h&&t!=null?2e3:!1}),z=S({mutationFn:()=>v.start(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),U=S({mutationFn:()=>v.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),G=S({mutationFn:d=>v.deleteSession(d),onSuccess:(d,N)=>{t===N&&n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),ae=S({mutationFn:()=>v.clearAll(),onSuccess:()=>{n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),V=f.useMemo(()=>{const d=x.trim().toLowerCase();return d?j.filter(N=>N.sessionId.toLowerCase().includes(d)):j},[x,j]),c=P.data,E=j.find(d=>d.id===t)??null,W=(c==null?void 0:c.records[u])??null;f.useEffect(()=>{t&&!j.some(d=>d.id===t)&&n(null)},[t,j]),f.useEffect(()=>{p(0),o(0),a("request")},[t]),f.useEffect(()=>{if(!c){p(0),o(0);return}p(d=>Math.min(d,Math.max(c.records.length-1,0))),o(d=>d==null?0:Math.min(d,Math.max(c.records.length-1,0)))},[c]);const re=()=>{c&&je(`profiler-${c.sessionId}.json`,c)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",style:{height:"calc(100vh - 64px)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-indigo-500"}),e.jsx("span",{className:"text-base font-semibold text-slate-900",children:"Profiler"}),e.jsxs(se,{variant:"outline",className:m("rounded-full border px-2.5 py-1 text-xs font-semibold",h?"border-red-200 bg-red-50 text-red-600":"border-slate-200 bg-slate-50 text-slate-500"),children:[e.jsx("span",{className:m("mr-2 inline-block h-1.5 w-1.5 rounded-full",h?"bg-red-500":"bg-slate-400")}),h?"Recording":"Not Recording"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{size:"sm",variant:h?"destructive":"default",onClick:()=>h?U.mutate():z.mutate(),disabled:z.isPending||U.isPending,children:h?"Stop Recording":"Start Recording"}),e.jsxs($,{size:"sm",variant:"outline",onClick:re,disabled:!c,children:[e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Export"]}),e.jsxs($,{size:"sm",variant:"outline",onClick:()=>ae.mutate(),disabled:j.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800",children:[e.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Clear"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden bg-[#F1F3F4]",children:[e.jsxs("div",{className:"flex w-80 flex-shrink-0 flex-col border-r border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-900",children:"Sessions"}),e.jsx(se,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:j.length})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-slate-400"}),e.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-slate-400",placeholder:"Search sessions...",value:x,onChange:d=>C(d.target.value)})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:J.isPending?e.jsx(ee,{compact:!0,className:"min-h-[160px]",label:"Loading..."}):V.length===0?e.jsx(M,{compact:!0,className:"m-4 min-h-[160px]",title:h?"Waiting for requests…":"No sessions",description:h?"Requests with session_id will appear here.":"Start recording to capture LLM sessions."}):V.map((d,N)=>e.jsx(Ne,{session:d,selected:t===d.id,index:N,onClick:()=>n(d.id)},d.id))})]}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col bg-white",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),e.jsx("span",{className:"truncate text-sm font-semibold text-slate-900",children:(c==null?void 0:c.sessionId)??(E==null?void 0:E.sessionId)??t}),e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx("span",{className:"truncate text-sm text-slate-500",children:c?`${c.turnCount} turns · ${I(L(c))} · ${K((c.totalInputTokens??0)+(c.totalOutputTokens??0))} tokens`:"Loading session…"})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>t&&G.mutate(t),disabled:!t||G.isPending,className:"text-slate-500 hover:text-red-700",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"border-b border-border bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{active:l==="timeline",icon:de,label:"Timeline",onClick:()=>r("timeline")}),e.jsx(te,{active:l==="breakdown",icon:ce,label:"Breakdown",onClick:()=>r("breakdown")})]})}),e.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-slate-50",children:P.isPending?e.jsx(ee,{compact:!0,className:"min-h-[240px]",label:"Loading session..."}):P.isError?e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:"Failed to load session"}):c?l==="timeline"?e.jsx(we,{detail:c,selectedTurn:u,detailTab:i,onSelectTurn:p,onDetailTabChange:a}):e.jsx(Me,{detail:c,expandedTurn:y,onToggleTurn:d=>o(N=>N===d?null:d)}):e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",title:"Session not found"})}),W&&e.jsxs("span",{className:"sr-only",children:["Selected turn ",W.turnIndex+1]})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(M,{title:"Select a session",description:"Choose a session from the left to inspect its timeline, message payloads, and stats.",icon:e.jsx(Y,{className:"h-5 w-5"})})})})]})]})}export{Ee as default};
|
|
1
|
+
import{r as f,j as e,Y as X,ap as ie,aB as Z,aK as oe,aL as de,S as ce,au as xe,a2 as me,ao as ue}from"./vendor-DfnQOGOQ.js";import{u as pe,a as A,b as S}from"./query-Db16w3tH.js";import{P as ee,a as M}from"./PageState-CiCo8uzV.js";import{B as se}from"./badge-CUJnXP--.js";import{h as F,b as q,r as O,c as m,B as $}from"./index-BYn7J5K_.js";import{d as he}from"./utils-BHook6QN.js";import{q as b}from"./queryKeys-BMvyDTQS.js";import"./i18n-dgCQR_PB.js";import"./router-BURlSZbt.js";import"./radix-D08JKSgz.js";const v={getStatus:()=>O({url:"/api/profiler/status",method:"GET"}),start:()=>F(q.post("/api/profiler/start")),stop:()=>F(q.post("/api/profiler/stop")),listSessions:s=>O({url:"/api/profiler/sessions",method:"GET",params:s}),getSession:s=>O({url:`/api/profiler/sessions/${s}`,method:"GET"}),deleteSession:s=>F(q.delete(`/api/profiler/sessions/${s}`)),clearAll:()=>F(q.post("/api/profiler/sessions/clear"))};function g(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(2)}s`:`${Math.round(s)}ms`}function R(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(1)}s`:`${Math.round(s)}ms`}function k(s){return s==null?"-":s.toLocaleString()}function Q(s){return s==null?"-":s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function L(s){return s.endedAt==null||s.turnCount===0?s.totalLatencyMs??0:s.endedAt-s.startedAt}function fe(s){const t=s.sessionId;return t.length>18?`${t.slice(0,8)}…${t.slice(-6)}`:t}function be(s){const t=Math.max(0,Date.now()-s),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n} min ago`;const l=Math.floor(n/60);if(l<24)return`${l} hr ago`;const r=Math.floor(l/24);return`${r} day${r===1?"":"s"} ago`}function ge(s){if(!s)return null;try{return JSON.parse(s)}catch{return null}}function _(s,t){if(Array.isArray(s)){for(const n of s)_(n,t);return}if(s&&typeof s=="object"){const n=s,l=n.tool_calls;Array.isArray(l)&&t.push(...l);const r=n.content;if(Array.isArray(r)){for(const i of r)if(i&&typeof i=="object"){const a=i;a.type==="tool_use"&&t.push(a)}}for(const i of Object.values(n))_(i,t)}}function I(s){const t=[];return _(ge(s.clientResponse),t),t}function le(s,t){const n=s.timestamp-t,l=n+(s.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(l/1e3).toFixed(3)}s`}function K(s,t){return he(s??null,t)}function je(s,t){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),l=URL.createObjectURL(n),r=document.createElement("a");r.href=l,r.download=s,r.click(),URL.revokeObjectURL(l)}function B({tone:s="default",children:t}){return e.jsx("span",{className:m("inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium",s==="accent"?"bg-indigo-100 text-indigo-700":"bg-slate-100 text-slate-600"),children:t})}function Ne({session:s,selected:t,index:n,onClick:l}){const r=["bg-indigo-500","bg-emerald-500","bg-amber-500"],i=t?"bg-indigo-500":r[n%r.length],a=(s.totalInputTokens??0)+(s.totalOutputTokens??0);return e.jsxs("button",{type:"button",onClick:l,className:m("w-full border-b border-border px-4 py-3 text-left transition-colors",t?"bg-indigo-50/70":"hover:bg-slate-50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("h-2 w-2 flex-shrink-0 rounded-full",i)}),e.jsx("span",{className:m("truncate text-sm font-semibold",t?"text-indigo-700":"text-slate-800"),children:fe(s)})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(s.startedAt)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[e.jsxs(B,{tone:t?"accent":"default",children:[s.turnCount," turns"]}),e.jsx(B,{children:R(L(s))}),e.jsxs(B,{children:[Q(a)," tok"]})]})]})}function te({active:s,icon:t,label:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-slate-50 text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx(t,{className:"h-3.5 w-3.5"}),n]})}function D({active:s,label:t,count:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-transparent text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx("span",{children:t}),typeof n=="number"&&e.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-800",children:n})]})}function ve({detail:s,selectedTurn:t,onSelectTurn:n}){const l=s.records;if(l.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const r=L(s),i=Math.max(1,...l.map(a=>Math.max(a.latencyMs??0,a.ttftMs??0,1)));return Math.max(1,...l.map(a=>I(a).length)),e.jsxs("div",{className:"border-b border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-5 py-3",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Compressed overview · idle gaps folded · wraps as turns grow"}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"text-slate-500",children:"Mode:"}),e.jsx("span",{className:"rounded border border-slate-200 bg-slate-100 px-2 py-0.5 font-medium text-slate-700",children:"Compressed"}),e.jsxs("span",{className:"rounded border border-slate-200 bg-white px-2 py-0.5 font-medium text-slate-700",children:["Session ",R(r)]})]})]}),e.jsxs("div",{className:"px-5 pb-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between text-[10px] text-slate-400",children:[e.jsx("span",{children:"start"}),e.jsxs("span",{children:[(r/1e3).toFixed(1),"s"]})]}),e.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:l.map((a,u)=>{const p=u===t,y=Math.max(a.latencyMs??0,1),o=`${Math.max(28,Math.min(100,y/i*100))}%`,x=a.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(a.ttftMs,i)/i*100))}%`:null,C=Math.max(0,a.timestamp-s.startedAt),w=I(a);return e.jsxs("button",{type:"button",onClick:()=>n(u),className:m("border border-transparent px-1.5 py-1 text-left transition-colors",p?"rounded-md border-rose-300":"hover:bg-slate-50/40"),title:`Turn ${a.turnIndex+1}`,children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",p?"border-indigo-300 bg-indigo-100 text-indigo-700":"border-slate-200 bg-white text-slate-700"),children:a.turnIndex+1}),e.jsx("span",{className:"truncate text-[15px] font-semibold text-slate-800",children:R(a.latencyMs)})]})}),e.jsxs("p",{className:"mt-1 text-[10px] text-slate-500",children:["start ",(C/1e3).toFixed(1),"s"]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between text-[10px] text-slate-500",children:e.jsxs("span",{children:[g(a.ttftMs)," TTFT"]})}),e.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-slate-100",children:[e.jsx("div",{className:"h-4 rounded-sm bg-blue-200",style:{width:o}}),x!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 shadow-[0_0_0_1px_rgba(255,255,255,0.9)]",style:{left:x}}),e.jsx("span",{className:"absolute top-[-6px] h-2.5 w-2.5 -translate-x-1/2 rounded-full border border-white bg-violet-500",style:{left:x}})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[10px] text-slate-500",children:[e.jsx("span",{children:"Tools"}),e.jsx("span",{children:w.length})]}),e.jsx("div",{className:"flex h-5 items-center gap-1",children:e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[10px] font-semibold",w.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-slate-300 bg-white text-slate-500"),children:w.length})})]})]},a.id)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),"Total latency"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 shadow-[0_0_0_1px_rgba(139,92,246,0.35)]"}),"First token (TTFT)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),"Tool executing"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),"Selected turn"]})]})]})]})}function ye({detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:l,onSelectTurn:r}){const i=s.records[t];if(!i)return null;const a=I(i),u=(i.inputTokens??0)+(i.outputTokens??0),p=n==="request"?K(i.clientRequest,"(empty request)"):n==="response"?K(i.clientResponse,"(empty response)"):a.length>0?JSON.stringify(a,null,2):"(no tool calls)";return e.jsxs("div",{"data-testid":"profiler-turn-detail",className:"shrink-0 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-slate-200 bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[e.jsxs("span",{className:"rounded-full px-2 py-1 font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["Turn ",i.turnIndex+1]}),e.jsx("span",{className:"text-slate-500",children:le(i,s.startedAt)}),e.jsxs("span",{className:"rounded-full bg-violet-100 px-2 py-1 font-semibold text-violet-700",children:["TTFT ",g(i.ttftMs)]}),e.jsxs("span",{className:"rounded-full bg-blue-100 px-2 py-1 font-semibold text-blue-700",children:[Q(u)," tokens"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("button",{type:"button",onClick:()=>r(Math.max(0,t-1)),disabled:t===0,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Previous turn",children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-10 text-center font-medium text-slate-600",children:[t+1," / ",s.records.length]}),e.jsx("button",{type:"button",onClick:()=>r(Math.min(s.records.length-1,t+1)),disabled:t===s.records.length-1,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Next turn",children:e.jsx(me,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"border-b border-slate-200 bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(D,{active:n==="request",label:"Request",onClick:()=>l("request")}),e.jsx(D,{active:n==="response",label:"Response",onClick:()=>l("response")}),e.jsx(D,{active:n==="tools",label:"Tool Calls",count:a.length,onClick:()=>l("tools")})]})}),e.jsxs("div",{className:"p-5",children:[e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:p}),i.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:i.error})]})]})}function we({detail:s,selectedTurn:t,detailTab:n,onSelectTurn:l,onDetailTabChange:r}){return e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsx(ve,{detail:s,selectedTurn:t,onSelectTurn:l}),e.jsx(ye,{detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:r,onSelectTurn:l})]})}function ne({title:s,payload:t,accentClass:n}){return e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:m("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",n),children:s}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:K(t,"(empty)")})]})}function T({label:s,value:t,sub:n,accentClass:l}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-white p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:s}),e.jsx("p",{className:m("mt-2 text-2xl font-semibold text-slate-900",l),children:t}),n&&e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:n})]})}function Te({record:s,sessionStart:t,expanded:n,onToggle:l}){const r=I(s);return e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border bg-white",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-4 px-4 py-3 text-left hover:bg-slate-50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"rounded-full px-2 py-0.5 text-[11px] font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["T",s.turnIndex+1]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900",children:le(s,t)}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["Total ",g(s.latencyMs)]}),e.jsxs("span",{children:["TTFT ",g(s.ttftMs)]}),e.jsxs("span",{children:["TPOT ",s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"]}),e.jsxs("span",{children:["↑ ",k(s.inputTokens)]}),e.jsxs("span",{children:["↓ ",k(s.outputTokens)]}),e.jsxs("span",{children:[r.length," tool calls"]}),s.error&&e.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600",children:"Error"})]})]})]}),e.jsx(ue,{className:m("h-4 w-4 flex-shrink-0 text-slate-400 transition-transform",n&&"rotate-180")})]}),n&&e.jsxs("div",{className:"border-t border-border bg-slate-50/70 p-4",children:[e.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[e.jsx(ne,{title:"Request",payload:s.clientRequest,accentClass:"text-blue-600"}),e.jsx(ne,{title:"Response",payload:s.clientResponse,accentClass:"text-violet-600"})]}),e.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-amber-600",children:"Tool Calls"}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:r.length>0?JSON.stringify(r,null,2):"(no tool calls)"})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:"Turn Metrics"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Duration"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.latencyMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TTFT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.ttftMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TPOT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Status"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.statusCode??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Input"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.inputTokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Output"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.outputTokens)})]})]}),s.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:s.error})]})]})]})]})}function Me({detail:s,expandedTurn:t,onToggleTurn:n}){if(s.records.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const l=L(s),r=s.records.reduce((o,x)=>{const C=x.latencyMs??0,w=x.ttftMs??0;return o+Math.max(C-w,0)},0),i=l>0?(r/l*100).toFixed(1):"-",a=s.records.map(o=>o.ttftMs).filter(o=>o!=null),u=s.records.map(o=>o.tpotMs).filter(o=>o!=null),p=a.length>0?a.reduce((o,x)=>o+x,0)/a.length:null,y=u.length>0?u.reduce((o,x)=>o+x,0)/u.length:null;return e.jsxs("div",{className:"space-y-5 p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(T,{label:"Total Duration",value:g(l),sub:`${s.records.length} turns`}),e.jsx(T,{label:"LLM Time",value:g(r),sub:`${i}% of session`,accentClass:"text-violet-700"}),e.jsx(T,{label:"Avg TTFT",value:g(p)}),e.jsx(T,{label:"Avg TPOT",value:y!=null?`${y.toFixed(1)} ms/tok`:"-"}),e.jsx(T,{label:"Input Tokens",value:k(s.totalInputTokens)}),e.jsx(T,{label:"Output Tokens",value:k(s.totalOutputTokens)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Per-Turn Breakdown"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Expand a turn to inspect request, response, tool calls, and errors."})]})}),s.records.map(o=>e.jsx(Te,{record:o,sessionStart:s.startedAt,expanded:t===o.turnIndex,onToggle:()=>n(o.turnIndex)},o.id))]})]})}function Ee(){var Y,H;const s=pe(),[t,n]=f.useState(null),[l,r]=f.useState("timeline"),[i,a]=f.useState("request"),[u,p]=f.useState(0),[y,o]=f.useState(0),[x,C]=f.useState(""),h=((Y=A({queryKey:b.profiler.status(),queryFn:()=>v.getStatus(),refetchInterval:3e3}).data)==null?void 0:Y.active)??!1,J=A({queryKey:b.profiler.sessions({}),queryFn:()=>v.listSessions({limit:100}),refetchInterval:h?2e3:!1}),j=((H=J.data)==null?void 0:H.items)??[],P=A({queryKey:b.profiler.session(t),queryFn:()=>v.getSession(t),enabled:t!=null,refetchInterval:h&&t!=null?2e3:!1}),z=S({mutationFn:()=>v.start(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),U=S({mutationFn:()=>v.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),G=S({mutationFn:d=>v.deleteSession(d),onSuccess:(d,N)=>{t===N&&n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),ae=S({mutationFn:()=>v.clearAll(),onSuccess:()=>{n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),V=f.useMemo(()=>{const d=x.trim().toLowerCase();return d?j.filter(N=>N.sessionId.toLowerCase().includes(d)):j},[x,j]),c=P.data,E=j.find(d=>d.id===t)??null,W=(c==null?void 0:c.records[u])??null;f.useEffect(()=>{t&&!j.some(d=>d.id===t)&&n(null)},[t,j]),f.useEffect(()=>{p(0),o(0),a("request")},[t]),f.useEffect(()=>{if(!c){p(0),o(0);return}p(d=>Math.min(d,Math.max(c.records.length-1,0))),o(d=>d==null?0:Math.min(d,Math.max(c.records.length-1,0)))},[c]);const re=()=>{c&&je(`profiler-${c.sessionId}.json`,c)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",style:{height:"calc(100vh - 64px)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(X,{className:"h-5 w-5 text-indigo-500"}),e.jsx("span",{className:"text-base font-semibold text-slate-900",children:"Profiler"}),e.jsxs(se,{variant:"outline",className:m("rounded-full border px-2.5 py-1 text-xs font-semibold",h?"border-red-200 bg-red-50 text-red-600":"border-slate-200 bg-slate-50 text-slate-500"),children:[e.jsx("span",{className:m("mr-2 inline-block h-1.5 w-1.5 rounded-full",h?"bg-red-500":"bg-slate-400")}),h?"Recording":"Not Recording"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{size:"sm",variant:h?"destructive":"default",onClick:()=>h?U.mutate():z.mutate(),disabled:z.isPending||U.isPending,children:h?"Stop Recording":"Start Recording"}),e.jsxs($,{size:"sm",variant:"outline",onClick:re,disabled:!c,children:[e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Export"]}),e.jsxs($,{size:"sm",variant:"outline",onClick:()=>ae.mutate(),disabled:j.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800",children:[e.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Clear"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden bg-[#F1F3F4]",children:[e.jsxs("div",{className:"flex w-80 flex-shrink-0 flex-col border-r border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-900",children:"Sessions"}),e.jsx(se,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:j.length})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-slate-400"}),e.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-slate-400",placeholder:"Search sessions...",value:x,onChange:d=>C(d.target.value)})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:J.isPending?e.jsx(ee,{compact:!0,className:"min-h-[160px]",label:"Loading..."}):V.length===0?e.jsx(M,{compact:!0,className:"m-4 min-h-[160px]",title:h?"Waiting for requests…":"No sessions",description:h?"Requests with session_id will appear here.":"Start recording to capture LLM sessions."}):V.map((d,N)=>e.jsx(Ne,{session:d,selected:t===d.id,index:N,onClick:()=>n(d.id)},d.id))})]}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col bg-white",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),e.jsx("span",{className:"truncate text-sm font-semibold text-slate-900",children:(c==null?void 0:c.sessionId)??(E==null?void 0:E.sessionId)??t}),e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx("span",{className:"truncate text-sm text-slate-500",children:c?`${c.turnCount} turns · ${R(L(c))} · ${Q((c.totalInputTokens??0)+(c.totalOutputTokens??0))} tokens`:"Loading session…"})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>t&&G.mutate(t),disabled:!t||G.isPending,className:"text-slate-500 hover:text-red-700",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"border-b border-border bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{active:l==="timeline",icon:de,label:"Timeline",onClick:()=>r("timeline")}),e.jsx(te,{active:l==="breakdown",icon:ce,label:"Breakdown",onClick:()=>r("breakdown")})]})}),e.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-slate-50",children:P.isPending?e.jsx(ee,{compact:!0,className:"min-h-[240px]",label:"Loading session..."}):P.isError?e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:"Failed to load session"}):c?l==="timeline"?e.jsx(we,{detail:c,selectedTurn:u,detailTab:i,onSelectTurn:p,onDetailTabChange:a}):e.jsx(Me,{detail:c,expandedTurn:y,onToggleTurn:d=>o(N=>N===d?null:d)}):e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",title:"Session not found"})}),W&&e.jsxs("span",{className:"sr-only",children:["Selected turn ",W.turnIndex+1]})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(M,{title:"Select a session",description:"Choose a session from the left to inspect its timeline, message payloads, and stats.",icon:e.jsx(X,{className:"h-5 w-5"})})})})]})]})}export{Ee as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as S,j as e,a9 as O,aw as re,av as A,ao as le,a2 as oe,U as de,V as ie}from"./vendor-DfnQOGOQ.js";import{L as ce}from"./router-BURlSZbt.js";import{C as me}from"./ConfirmDialog-Dwx6RgvT.js";import{P as xe}from"./PageHeader-DipLZp28.js";import{B as j,d as G,c as E,T as pe,e as ue,f as he,g as ge}from"./index-BYn7J5K_.js";import{u as I}from"./useAppMutation-D-iOmckM.js";import{I as T}from"./input-BpqO0M53.js";import{L as k}from"./label-G00TC871.js";import{S as fe,a as be,b as je,c as ve,d as Ne}from"./select-D49a8SjJ.js";import{S as U}from"./switch-tXufYzT3.js";import{q as K}from"./queryKeys-BMvyDTQS.js";import{u as P}from"./i18n-dgCQR_PB.js";import{B as w}from"./badge-CUJnXP--.js";import{C as Q,a as W}from"./card-Vz-Wm3NU.js";import{D as ye,A as we,a as Me,b as ke,c as Ce,d as Ee,e as Pe}from"./DialogShell-DpB7I936.js";import{P as De,a as Ae,b as Se}from"./popover-Dhl3J4mH.js";import{i as Te,g as Oe,C as Re,O as Le,u as $e}from"./useModelManagementState-B58fytAY.js";import"./query-Db16w3tH.js";import"./radix-D08JKSgz.js";import"./gateway-D8Ly9AH3.js";import"./useApiQuery-Dqxujlur.js";const Be=["anthropic","openai-auto","openai-chat","openai-responses"];function Ve({open:d,endpoint:s,onClose:f,onSuccess:o}){const{t:a}=P(),[x,m]=S.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});S.useEffect(()=>{if(s){const n=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];m({id:s.id,label:s.label,paths:n,enabled:s.enabled!==!1});return}m({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,d]);const r=I({mutationFn:G.create,invalidateKeys:[K.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:n=>({title:a("modelManagement.createEndpointError",{error:n.message})}),onSuccess:async()=>{o(),f()}}),i=I({mutationFn:n=>G.update(n.id,n.updates),invalidateKeys:[K.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:n=>({title:a("modelManagement.updateEndpointError",{error:n.message})}),onSuccess:async()=>{o(),f()}}),c=()=>{m(n=>({...n,paths:[...n.paths,{path:"",protocol:"anthropic"}]}))},v=n=>{x.paths.length!==1&&m(p=>({...p,paths:p.paths.filter((h,M)=>M!==n)}))},N=(n,p,h)=>{m(M=>{const C=[...M.paths];return C[n]={...C[n],[p]:h},{...M,paths:C}})},t=n=>{if(n==null||n.preventDefault(),!x.id.trim()||!x.label.trim())return;for(const h of x.paths)if(!h.path.trim())return;const p=x.paths.map(h=>({path:h.path.trim(),protocol:h.protocol}));if(s){i.mutate({id:s.id,updates:{label:x.label.trim(),paths:p,enabled:x.enabled}});return}r.mutate({id:x.id.trim(),label:x.label.trim(),paths:p,enabled:x.enabled})},u=r.isPending||i.isPending,l=x.paths.length===0?a("modelManagement.atLeastOnePath"):!x.id.trim()||!x.label.trim()?a("modelManagement.endpointValidationError"):x.paths.some(n=>!n.path.trim())?a("modelManagement.pathValidationError"):null;return d?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:f}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-secondary p-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(j,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(O,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:t,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:x.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:x.id,onChange:n=>m(p=>({...p,id:n.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:x.label,onChange:n=>m(p=>({...p,label:n.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(k,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(j,{type:"button",variant:"ghost",size:"sm",onClick:c,children:[e.jsx(re,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:x.paths.map((n,p)=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(T,{value:n.path,onChange:h=>N(p,"path",h.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(fe,{value:n.protocol,onValueChange:h=>N(p,"protocol",h),children:[e.jsx(be,{children:e.jsx(je,{})}),e.jsx(ve,{children:Be.map(h=>e.jsx(Ne,{value:h,children:a(h==="anthropic"?"modelManagement.protocolAnthropic":h==="openai-auto"?"modelManagement.protocolOpenAI":h==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},h))})]})]}),x.paths.length>1?e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(p),className:"text-destructive",children:e.jsx(O,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[p===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${n.protocol}`)})]})]},`${n.protocol}-${p}`))}),l?e.jsx("p",{className:"text-xs text-destructive",children:l}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(U,{id:"enabled",checked:x.enabled,onCheckedChange:n=>m(p=>({...p,enabled:n}))}),e.jsx(k,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?null:e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border bg-secondary p-6",children:[e.jsx(j,{variant:"outline",className:"flex-1",onClick:f,disabled:u,children:a("common.cancel")}),e.jsx(j,{className:"flex-1",onClick:()=>t(),disabled:u,children:a(u?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function z(d,s){return s(d==="anthropic"?"modelManagement.protocolAnthropic":d==="openai-chat"?"modelManagement.protocolOpenAIChat":d==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function ze({activeTab:d,customEndpoints:s,customTabs:f,isDirtyByEndpoint:o,onDeleteEndpoint:a,onEditEndpoint:x,onSelectTab:m,systemTabs:r}){const{t:i}=P();return e.jsx(Q,{className:"overflow-hidden",children:e.jsxs(W,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:i("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:r.map(c=>{const v=d===c.key,N=c.key!=="providers"&&o[c.key];return e.jsxs("button",{type:"button",onClick:()=>m(c.key),className:E("group flex min-h-[96px] flex-col justify-between rounded-lg border px-4 py-4 text-left transition-all",v?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:E("text-base font-semibold",v?"text-primary":"text-foreground"),children:c.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c.key==="providers"?i("modelManagement.overview.providerPoolTag"):i("modelManagement.overview.systemEndpointTag")})]}),N?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:c.description})]},c.key)})})]}),f.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:i("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full snap-x gap-3",children:f.map(c=>{var u;const v=d===c.key,N=o[c.key],t=s.find(l=>l.id===c.key);return e.jsxs("div",{className:E("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-lg border px-4 py-4 text-left transition-all",v?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:()=>m(c.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:E("truncate text-base font-semibold",v?"text-primary":"text-foreground"),children:c.label}),N?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:c.description})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:items-start",children:[e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-full px-2 text-xs sm:w-auto",disabled:!t,onClick:()=>{t&&x(t)},children:i("common.edit")}),c.canDelete?e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),t&&a({kind:"endpoint",endpoint:t})},className:"flex h-7 w-full items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive sm:w-7",title:i("common.delete"),children:e.jsx(O,{className:"h-3.5 w-3.5"})}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(c.protocols??[]).map(l=>e.jsx(w,{variant:"outline",className:"max-w-full truncate text-[11px]",children:z(l,i)},`${c.key}-${l}`)),e.jsx(w,{variant:(t==null?void 0:t.enabled)===!1?"secondary":"success",className:"text-[11px]",children:(t==null?void 0:t.enabled)===!1?i("modelManagement.overview.endpointDisabled"):i("modelManagement.overview.endpointEnabled")})]}),t!=null&&t.paths&&t.paths.length>0?e.jsxs("div",{className:"space-y-1 rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[t.paths.slice(0,2).map(l=>e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:l.path})," · ",z(l.protocol,i)]},`${t.id}-${l.path}-${l.protocol}`)),t.paths.length>2?e.jsx("div",{children:i("modelManagement.overview.endpointMorePaths",{count:t.paths.length-2})}):null]}):t!=null&&t.path?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:t.path})," · ",z(t.protocol??"anthropic",i)]}):null,e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:(u=c.protocols)!=null&&u.length?i("modelManagement.overview.endpointProtocols",{count:c.protocols.length}):i("modelManagement.overview.endpointNoProtocol")}),c.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground",children:i("modelManagement.overview.endpointManagedExternally")})]},c.key)})})})]}):null]})})}function He({dialog:d,currentRoutes:s,onConfirm:f,onClose:o}){const{t:a}=P();if(!d)return null;const{endpoint:x,preset:m}=d,r=m.modelRoutes??{},i={};for(const l of s){const n=l.source.trim(),p=l.target.trim();n&&p&&(i[n]=p)}const c=new Set([...Object.keys(i),...Object.keys(r)]),v=[],N=[],t=[];for(const l of c){const n=l in i,p=l in r;p&&!n?v.push([l,r[l]]):n&&!p?N.push([l,i[l]]):n&&p&&i[l]!==r[l]&&t.push([l,i[l],r[l]])}const u=v.length>0||N.length>0||t.length>0;return e.jsx(ye,{open:!0,onOpenChange:l=>!l&&o(),children:e.jsxs(we,{className:"max-w-2xl",children:[e.jsxs(Me,{children:[e.jsx(ke,{children:a("modelManagement.presets.diffTitle")}),e.jsx(Ce,{children:a("modelManagement.presets.diffDescription",{name:m.name})})]}),e.jsx(Ee,{children:u?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-lg border border-border bg-secondary p-3 text-sm",children:[v.map(([l,n])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(w,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n})]},`add-${l}`)),N.map(([l,n])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(w,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n})]},`rm-${l}`)),t.map(([l,n,p])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-amber-50 px-2 py-1.5 text-amber-800 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx(w,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:n}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:p})]},`chg-${l}`))]}):e.jsx("p",{className:"rounded-lg border border-border bg-secondary py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(Pe,{children:[e.jsx(j,{variant:"outline",onClick:o,children:a("common.cancel")}),e.jsx(j,{onClick:()=>f(x,m),disabled:!u,children:a("modelManagement.presets.diffConfirm")})]})]})})}function _e({value:d,onChange:s,options:f,disabled:o,placeholder:a}){const{t:x}=P(),[m,r]=S.useState(!1),[i,c]=S.useState(""),v=S.useMemo(()=>{if(!i.trim())return f;const t=i.toLowerCase();return f.filter(u=>u.label.toLowerCase().includes(t)||u.value.toLowerCase().includes(t))},[f,i]),N=t=>{s(t),c(""),r(!1)};return e.jsxs(De,{open:m,onOpenChange:t=>{r(t),t&&c("")},children:[e.jsx(Ae,{asChild:!0,children:e.jsx(T,{value:d,onChange:t=>{s(t.target.value),c(t.target.value),m||r(!0)},onFocus:()=>{c(""),r(!0)},onClick:()=>{m||r(!0)},placeholder:a,disabled:o,autoComplete:"off"})}),e.jsx(Se,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto p-1",align:"start",onOpenAutoFocus:t=>t.preventDefault(),children:v.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:x("common.noMatches")}):v.map(t=>e.jsx("button",{type:"button",className:E("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",t.value===d.trim()&&"bg-accent"),onMouseDown:u=>{u.preventDefault(),N(t.value)},children:e.jsx("span",{className:"truncate",children:t.label})},t.value))})]})}function Fe({endpoint:d,tabs:s,customEndpoints:f,config:o,routes:a,routeError:x,savingRoute:m,isDirty:r,presets:i,presetName:c,presetError:v,savingPreset:N,applyingPreset:t,deletingPreset:u,presetsExpanded:l,savingClaudeValidation:n,providerModelOptions:p,onTogglePresetsExpanded:h,onPresetNameChange:M,onSavePreset:C,onRequestPresetDiff:X,onRequestDeletePreset:J,onToggleClaudeValidation:Y,onRouteChange:H,onRemoveRoute:_,onAddSuggestion:Z,onAddRoute:ee,onResetRoutes:se,onSaveRoutes:te}){var q;const{t:g}=P(),y=s.find(b=>b.key===d),R=((q=y==null?void 0:y.protocols)==null?void 0:q.includes("anthropic"))??d==="anthropic"?Re:Le,ae=(y==null?void 0:y.label)??d;(y==null?void 0:y.isSystem)===!1?y.description:g(`settings.routing.descriptionByEndpoint.${d}`);const L=`route-source-${d}`,F=Te(d,f),$=Oe(d,o,f),B=F&&($==null?void 0:$.mode)==="claude-code",ne=new Set(a.map(b=>b.source.trim()).filter(Boolean));return e.jsx(Q,{children:e.jsxs(W,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:g("settings.routing.wildcardHint")}),F?e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary",children:g("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-primary/80",children:g("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start sm:self-auto",children:[e.jsx(U,{checked:B,onCheckedChange:Y,disabled:n}),e.jsx("span",{className:E("text-xs font-medium",B?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:g(B?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}):null,x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null,e.jsx(qe,{presets:i,presetName:c,presetError:v,savingPreset:N,applyingPreset:t,deletingPreset:u,expanded:l,onToggleExpanded:h,onPresetNameChange:M,onSavePreset:C,onRequestPresetDiff:X,onRequestDeletePreset:J}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{className:"text-sm font-semibold text-foreground",children:g("modelManagement.routesEditorTitle")}),e.jsxs(w,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:g("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-lg border border-border bg-card px-3 py-2 text-[11px] text-muted-foreground",children:[ae," workspace"]})]}),a.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:g("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:g("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:g("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:g("settings.routing.target")}),e.jsx("span",{})]}),a.map((b,D)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(w,{variant:"outline",className:"text-[11px]",children:["#",D+1]}),e.jsx(j,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>_(b.id),disabled:m,children:e.jsx(O,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:g("settings.routing.source")}),e.jsx(T,{value:b.source,onChange:V=>H(b.id,"source",V.target.value),placeholder:g("settings.routing.sourcePlaceholder"),list:L,disabled:m,"aria-label":`route-source-${D+1}`})]}),e.jsx(A,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:g("settings.routing.target")}),e.jsx(_e,{value:b.target,onChange:V=>H(b.id,"target",V),options:p,disabled:m,placeholder:g("settings.routing.targetPlaceholder")})]}),e.jsx(j,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>_(b.id),disabled:m,children:e.jsx(O,{className:"h-4 w-4"})})]})]},b.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:g("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g(r?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(j,{variant:"outline",size:"sm",onClick:ee,disabled:m,className:"w-full",children:g("settings.routing.add")}),e.jsx(j,{variant:"outline",size:"sm",onClick:se,disabled:m||!r,className:"w-full",children:g("common.actions.reset")}),e.jsxs(j,{size:"sm",onClick:te,disabled:m,className:"relative w-full",children:[g(m?"common.actions.saving":"modelManagement.actions.saveRoutes"),r?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/70 bg-secondary/55 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{className:"text-sm font-medium text-foreground",children:g("settings.routing.suggested")}),e.jsx(w,{variant:"outline",className:"text-[11px]",children:R.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:g("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:R.map(b=>{const D=ne.has(b);return e.jsx(j,{variant:D?"ghost":"outline",size:"sm",onClick:()=>Z(b),disabled:m||D,className:E("h-7 rounded-md px-2.5 text-[11px] font-normal",D?"opacity-45":"bg-background/70"),children:b},`${d}-${b}`)})})]}),e.jsx("datalist",{id:L,children:R.map(b=>e.jsx("option",{value:b},`${L}-${b}`))})]})})}function qe({presets:d,presetName:s,presetError:f,savingPreset:o,applyingPreset:a,deletingPreset:x,expanded:m,onToggleExpanded:r,onPresetNameChange:i,onSavePreset:c,onRequestPresetDiff:v,onRequestDeletePreset:N}){const{t}=P();return e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-card",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:r,children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(le,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:t("modelManagement.presets.title")}),e.jsx(w,{variant:"secondary",className:"text-xs",children:d.length})]})}),m?e.jsxs("div",{className:"space-y-4 border-t px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(T,{value:s,onChange:u=>i(u.target.value),placeholder:t("modelManagement.presets.namePlaceholder"),disabled:o,className:"w-full md:w-48"}),e.jsx(j,{onClick:c,disabled:o,className:"w-full md:w-auto",children:t(o?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),f?e.jsx("p",{className:"text-sm text-destructive",children:f}):null,d.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:t("modelManagement.presets.empty")}):e.jsx(pe,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:d.map(u=>{const l=a===u.name,n=x===u.name,p=Object.entries(u.modelRoutes??{}),h=p.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-secondary px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ue,{children:[e.jsx(he,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:u.name}),e.jsx(w,{variant:"outline",className:"mt-1 text-xs",children:h>0?t("modelManagement.presets.rulesCount",{count:h}):t("modelManagement.presets.noRules")})]})}),h>0?e.jsx(ge,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[p.slice(0,5).map(([M,C])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:M}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:C})]},M)),h>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",h-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(j,{size:"sm",onClick:()=>v(u),disabled:l||n,className:"w-full sm:w-auto",children:t(l?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(j,{variant:"destructive",size:"sm",onClick:()=>N(u),disabled:n||l,className:"w-full sm:w-auto",children:t(n?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]}):null]})}function xs(){var x,m;const{t:d}=P(),s=$e(),f=s.systemTabs.filter(r=>r.key!=="providers"),o=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(r=>r.key===o)??null;return S.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(xe,{icon:e.jsx(ie,{className:"h-5 w-5","aria-hidden":"true"}),title:d("routingManagement.title"),description:d("routingManagement.description"),eyebrow:d("routingManagement.eyebrow"),breadcrumb:"Gateway / Routing",badge:(a==null?void 0:a.label)??o,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsx(j,{asChild:!0,variant:"outline",className:"w-full sm:w-auto",children:e.jsxs(ce,{to:"/models",children:[e.jsx(de,{className:"h-4 w-4","aria-hidden":"true"}),d("nav.models")]})}),e.jsx(j,{onClick:s.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:d("modelManagement.addEndpoint")})]})}),e.jsx(ze,{activeTab:o,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:f}),e.jsx(Fe,{endpoint:o,applyingPreset:((x=s.applyingPreset)==null?void 0:x.endpoint)===o?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((m=s.deletingPreset)==null?void 0:m.endpoint)===o?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[o]??!1,onAddRoute:()=>s.handleAddRoute(o),onAddSuggestion:r=>s.handleAddSuggestion(o,r),onPresetNameChange:r=>s.handlePresetNameChange(o,r),onRequestDeletePreset:r=>s.setConfirmAction({kind:"preset",endpoint:o,preset:r}),onRequestPresetDiff:r=>s.setPresetDiffDialog({endpoint:o,preset:r}),onRemoveRoute:r=>s.handleRemoveRoute(o,r),onResetRoutes:()=>s.handleResetRoutes(o),onRouteChange:(r,i,c)=>s.handleRouteChange(o,r,i,c),onSavePreset:()=>void s.handleSavePreset(o),onSaveRoutes:()=>void s.handleSaveRoutes(o),onToggleClaudeValidation:r=>void s.handleToggleClaudeValidation(o,r),onTogglePresetsExpanded:()=>s.setPresetsExpanded(r=>({...r,[o]:!r[o]})),presetError:s.presetErrorByEndpoint[o],presetName:s.presetNameByEndpoint[o]??"",presets:s.presetsByEndpoint[o]??[],presetsExpanded:s.presetsExpanded[o]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[o],routes:s.routesByEndpoint[o]||[],savingClaudeValidation:s.savingClaudeValidation,savingPreset:s.savingPresetFor===o,savingRoute:s.savingRouteFor===o,tabs:s.tabs.filter(r=>r.key!=="providers")}),e.jsx(Ve,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(He,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(r,i)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(r,i)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(me,{open:!!s.confirmAction,onOpenChange:r=>{!r&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?d("common.actions.loading"):d("common.delete"),cancelLabel:d("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:s.confirmDialogName}):null})]})}export{xs as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,az as J,av as gt,au as xt,r as m,Y as bt}from"./vendor-5iCEqDpV.js";import{C as Le}from"./ConfirmDialog-DW7jBfm1.js";import{c as M,L as Fe,B as k,r as Te,h as ft,b as vt,u as jt}from"./index-CYeQpt9d.js";import{P as yt}from"./PageHeader-DDxjKW4B.js";import{C as A,a as L}from"./card-I07afQF2.js";import{B as E}from"./badge-B-TfGxGB.js";import{I as w}from"./input-DZMeIHxj.js";import{L as v}from"./label-DZr7itdg.js";import{S as B}from"./switch-BpfcwR9i.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-BUvJR07s.js";import{u as R}from"./i18n-C7VVFIdN.js";import{u as Me}from"./useApiQuery-BzbOtl4s.js";import{u as Q}from"./useAppMutation-D8Mjcv9t.js";import{g as Oe}from"./gateway-CkqHb_VE.js";import{c as St}from"./clipboard-CALi6bTW.js";import{q as _}from"./queryKeys-BMvyDTQS.js";import"./DialogShell-BqzUE3vU.js";import"./radix-CmyU-WBH.js";import"./query-DxhDvnDC.js";import"./router-D8u_RlVh.js";const Rt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],te=[{id:"section-basics",labelKey:"settings.sections.basics"},{id:"section-protocol",labelKey:"settings.sections.protocol"},{id:"section-security",labelKey:"settings.sections.security"},{id:"section-config-file",labelKey:"settings.sections.configFile"},{id:"section-cleanup",labelKey:"settings.sections.cleanup"}];function z(s){var o,l,c,a,i,h,p,T,x,d,N;const t=s.storePayloads,n=C=>typeof C=="boolean"?C:typeof t=="boolean"?t:!0;return{port:String(s.port??((o=s.http)==null?void 0:o.port)??""),host:s.host??((l=s.http)==null?void 0:l.host)??"127.0.0.1",logRetentionDays:String(s.logRetentionDays??30),logExportTimeoutSeconds:String(s.logExportTimeoutSeconds??60),storeRequestPayloads:n(s.storeRequestPayloads),storeResponsePayloads:n(s.storeResponsePayloads),logLevel:s.logLevel??"info",bodyLimitMb:(()=>{const C=s.bodyLimit;return typeof C=="number"&&Number.isFinite(C)&&C>0?String(Math.max(1,Math.round(C/(1024*1024)))):"10"})(),enableRoutingFallback:s.enableRoutingFallback===!0,httpEnabled:((c=s.http)==null?void 0:c.enabled)!==!1,httpPort:String(((a=s.http)==null?void 0:a.port)??s.port??4100),httpHost:((i=s.http)==null?void 0:i.host)??s.host??"127.0.0.1",httpsEnabled:((h=s.https)==null?void 0:h.enabled)===!0,httpsPort:String(((p=s.https)==null?void 0:p.port)??4443),httpsHost:((T=s.https)==null?void 0:T.host)??s.host??"127.0.0.1",httpsKeyPath:((x=s.https)==null?void 0:x.keyPath)??"",httpsCertPath:((d=s.https)==null?void 0:d.certPath)??"",httpsCaPath:((N=s.https)==null?void 0:N.caPath)??""}}function Y(s){return{enabled:s.enabled,username:s.username??"",password:"",confirmPassword:""}}function Et({activeSection:s,onSelectSection:t}){const{t:n}=R();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs("div",{className:"sticky top-20 rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"mb-3 text-xs font-medium uppercase tracking-wider text-muted-foreground",children:n("settings.sections.jump")}),e.jsx("div",{className:"space-y-1",children:te.map((o,l)=>e.jsxs("button",{type:"button",onClick:()=>t(o.id),className:M("flex w-full items-center gap-3 rounded-full px-3.5 py-2.5 text-left text-sm transition-all",s===o.id?"bg-accent font-medium text-primary":"text-muted-foreground hover:bg-secondary hover:text-foreground"),children:[e.jsx("span",{className:M("flex h-7 w-7 items-center justify-center rounded-full border text-[11px] font-semibold",s===o.id?"border-primary/20 bg-primary text-primary-foreground":"border-border bg-secondary text-muted-foreground"),children:l+1}),e.jsx("span",{children:n(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"-mx-1 overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:te.map(o=>e.jsx("button",{type:"button",onClick:()=>t(o.id),className:M("rounded-full border px-3.5 py-2 text-xs font-medium transition-all",s===o.id?"border-primary bg-accent text-primary":"border-border bg-card text-muted-foreground hover:border-primary/20 hover:bg-accent hover:text-primary"),children:n(o.labelKey)},o.id))})})})]})}function At({configPath:s,defaultsSummary:t,form:n,protocolSummaryLabel:o,protocolChangesPending:l,isAuthDirty:c,isConfigDirty:a,authEnabled:i,authUsername:h}){const{t:p}=R();return e.jsx(A,{children:e.jsxs(L,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:p("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("settings.overview.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:a||c?"warning":"success",children:p(a||c?"modelManagement.actions.unsaved":"common.status.success")}),l?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.protocol.restartWarning")}):null]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(U,{label:p("settings.overview.cards.protocols"),value:o,helper:`${n.httpHost||"127.0.0.1"}:${n.httpPort}${n.httpsEnabled?` / ${n.httpsHost||"127.0.0.1"}:${n.httpsPort}`:""}`}),e.jsx(U,{label:p("settings.overview.cards.security"),value:p(i?"settings.overview.values.authEnabled":"settings.overview.values.authDisabled"),helper:h?`${p("settings.auth.username")}: ${h}`:p("settings.auth.enableHint")}),e.jsx(U,{label:p("settings.overview.cards.configFile"),value:s||p("settings.file.unknown"),helper:t??p("settings.defaults.none"),mono:!0})]})]})})}function Lt({defaultsSummary:s,errors:t,form:n,onInputChange:o,onSetForm:l,sectionRef:c}){const{t:a}=R();return e.jsx(A,{id:"section-basics",ref:c,children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(X,{label:a("settings.fields.retention"),value:n.logRetentionDays}),e.jsx(X,{label:a("settings.fields.logExportTimeout"),value:`${n.logExportTimeoutSeconds}s`}),e.jsx(X,{label:a("settings.fields.bodyLimit"),value:`${n.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:n.port,onChange:i=>o("port")(i.target.value),"aria-invalid":!!t.port}),t.port?e.jsx("p",{className:"text-xs text-destructive",children:t.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.host")}),e.jsx(w,{value:n.host,onChange:i=>o("host")(i.target.value),placeholder:a("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.retention")}),e.jsx(w,{type:"number",min:1,max:365,value:n.logRetentionDays,onChange:i=>o("logRetentionDays")(i.target.value),"aria-invalid":!!t.logRetentionDays}),t.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:t.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.logExportTimeout")}),e.jsx(w,{type:"number",min:5,max:600,value:n.logExportTimeoutSeconds,onChange:i=>o("logExportTimeoutSeconds")(i.target.value),"aria-invalid":!!t.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.fields.logExportTimeoutHint")}),t.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:t.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.bodyLimit")}),e.jsx(w,{type:"number",min:1,max:2048,value:n.bodyLimitMb,onChange:i=>o("bodyLimitMb")(i.target.value),"aria-invalid":!!t.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.fields.bodyLimitHint")}),t.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:t.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.logLevel")}),e.jsxs(Nt,{value:n.logLevel,onValueChange:i=>l(h=>({...h,logLevel:i})),children:[e.jsx(wt,{children:e.jsx(Ct,{})}),e.jsx(Pt,{children:Rt.map(i=>e.jsx(kt,{value:i.value,children:a(`settings.fields.logLevelOption.${i.labelKey}`)},i.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(Z,{label:a("settings.fields.storeRequestPayloads"),hint:a("settings.fields.storeRequestPayloadsHint"),checked:n.storeRequestPayloads,onCheckedChange:i=>l(h=>({...h,storeRequestPayloads:i}))}),e.jsx(Z,{label:a("settings.fields.storeResponsePayloads"),hint:a("settings.fields.storeResponsePayloadsHint"),checked:n.storeResponsePayloads,onCheckedChange:i=>l(h=>({...h,storeResponsePayloads:i}))}),e.jsx(Z,{label:a("settings.fields.enableRoutingFallback"),hint:a("settings.fields.enableRoutingFallbackHint"),checked:n.enableRoutingFallback,onCheckedChange:i=>l(h=>({...h,enableRoutingFallback:i}))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-4 md:col-span-2",children:[e.jsx(v,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:a("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:s??a("settings.defaults.none")})]})]})]})})}function Tt({errors:s,form:t,onSetForm:n,sectionRef:o}){const{t:l}=R();return e.jsx(A,{id:"section-protocol",ref:o,children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:l("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-[hsl(var(--warning)/1)]"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartTip")})]})]})}),s.protocol?e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(J,{className:"mr-2 inline h-4 w-4"}),s.protocol]}):null,e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.http.hint")})]}),e.jsx(B,{checked:t.httpEnabled,onCheckedChange:c=>n(a=>({...a,httpEnabled:c}))})]}),t.httpEnabled?e.jsxs("div",{className:"mt-4 grid gap-4 border-t border-border pt-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.http.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpPort,onChange:c=>n(a=>({...a,httpPort:c.target.value})),"aria-invalid":!!s.httpPort}),s.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.http.host")}),e.jsx(w,{value:t.httpHost,onChange:c=>n(a=>({...a,httpHost:c.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.https.enable")}),e.jsx(gt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.https.hint")})]}),e.jsx(B,{checked:t.httpsEnabled,onCheckedChange:c=>n(a=>({...a,httpsEnabled:c}))})]}),t.httpsEnabled?e.jsxs("div",{className:"mt-4 space-y-4 border-t border-border pt-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.https.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpsPort,onChange:c=>n(a=>({...a,httpsPort:c.target.value})),"aria-invalid":!!s.httpsPort}),s.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.https.host")}),e.jsx(w,{value:t.httpsHost,onChange:c=>n(a=>({...a,httpsHost:c.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(ee,{label:l("settings.protocol.https.keyPath"),value:t.httpsKeyPath,onChange:c=>n(a=>({...a,httpsKeyPath:c})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(ee,{label:l("settings.protocol.https.certPath"),value:t.httpsCertPath,onChange:c=>n(a=>({...a,httpsCertPath:c})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(ee,{label:l("settings.protocol.https.caPath"),value:t.httpsCaPath,onChange:c=>n(a=>({...a,httpsCaPath:c})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-[hsl(var(--warning)/1)]"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:l("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:l("settings.protocol.https.invalidCert")}),l("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:l("settings.protocol.https.recommended")}),l("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-600 dark:text-amber-400",children:l("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Mt({authErrors:s,authForm:t,authLoading:n,authSettings:o,needsPassword:l,onAuthReset:c,onAuthSave:a,onSetAuthForm:i,savingAuth:h,isAuthDirty:p,sectionRef:T}){const{t:x}=R();return e.jsx(A,{id:"section-security",ref:T,children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:x("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:x("settings.auth.description")})]}),n&&!o?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Fe,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 rounded-lg border border-border bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-medium",children:x("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"/ui"}),e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"/api/*"}),e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(E,{variant:t.enabled?"success":"secondary",children:t.enabled?x("settings.auth.statusEnabled"):x("settings.auth.statusDisabled")}),e.jsx(B,{checked:t.enabled,onCheckedChange:d=>i(N=>({...N,enabled:d}))})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(v,{children:x("settings.auth.username")}),e.jsx(w,{value:t.username,onChange:d=>i(N=>({...N,username:d.target.value})),placeholder:x("settings.auth.usernamePlaceholder")}),s.username?e.jsx("p",{className:"text-xs text-destructive",children:s.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:x("settings.auth.password")}),e.jsx(w,{type:"password",value:t.password,disabled:!t.enabled,onChange:d=>i(N=>({...N,password:d.target.value})),placeholder:x("settings.auth.passwordPlaceholder")}),s.password?e.jsx("p",{className:"text-xs text-destructive",children:s.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:x(l?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:x("settings.auth.confirmPassword")}),e.jsx(w,{type:"password",value:t.confirmPassword,disabled:!t.enabled,onChange:d=>i(N=>({...N,confirmPassword:d.target.value})),placeholder:x("settings.auth.confirmPasswordPlaceholder")}),s.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:s.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:x("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?x("settings.auth.statusEnabled"):x("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[x("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary p-4 text-xs text-muted-foreground",children:x(l?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsx(k,{onClick:a,disabled:h||!p,className:"w-full lg:w-auto",children:x(h?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(k,{variant:"outline",onClick:c,disabled:h||!p,className:"w-full lg:w-auto",children:x("common.actions.reset")})]})]})]})})}function Ot({configPath:s,onCopyPath:t,sectionRef:n}){const{t:o}=R();return e.jsx(A,{id:"section-config-file",ref:n,children:e.jsxs(L,{className:"space-y-3 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,className:"w-full sm:w-auto",children:[e.jsx(xt,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg border border-border bg-secondary px-4 py-3 text-xs",children:s||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ft({cleaning:s,clearingAll:t,onOpenCleanup:n,onOpenClearAll:o,sectionRef:l}){const{t:c}=R();return e.jsx(A,{id:"section-cleanup",ref:l,children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:c("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:c("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"warning",children:c("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:c("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.cleanup.softDescription")}),e.jsx(k,{variant:"outline",onClick:n,disabled:s,className:"w-full sm:w-auto",children:c(s?"common.actions.cleaning":"common.actions.cleanup")})]})}),e.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:c("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:c("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.cleanup.clearAllWarning")}),e.jsx(k,{variant:"destructive",onClick:o,disabled:t,className:"w-full sm:w-auto",children:c(t?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ht({isAuthDirty:s,isConfigDirty:t,protocolChangesPending:n,onAuthReset:o,onAuthSave:l,onReset:c,onSave:a,saving:i,savingAuth:h}){const{t:p}=R();return!s&&!t?null:e.jsxs("div",{className:"sticky bottom-4 z-20 flex flex-col gap-3 rounded-lg border border-primary/20 bg-card p-4 shadow-lg backdrop-blur-sm md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{variant:"secondary",children:p("modelManagement.actions.unsaved")}),t?e.jsx(E,{variant:"outline",children:p("settings.sections.basics")}):null,s?e.jsx(E,{variant:"outline",children:p("settings.sections.security")}):null,n?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.sections.protocol")}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p(n?"settings.toast.protocolRestartRequired":"modelManagement.actions.footerDirtyHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:items-center",children:[s?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:o,disabled:h,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:l,disabled:h,className:"w-full lg:w-auto",children:p(h?"common.actions.saving":"settings.auth.actions.save")})]}):null,t?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:c,disabled:i,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:a,disabled:i,className:"w-full lg:w-auto",children:p(i?"common.actions.saving":"common.actions.save")})]}):null]})]})}function U({label:s,value:t,helper:n,mono:o=!1}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:M("mt-2 text-sm font-semibold text-foreground",o&&"break-all font-mono text-xs"),children:t}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:n})]})}function X({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}function Z({checked:s,className:t,hint:n,hintClassName:o,label:l,labelClassName:c,onCheckedChange:a}){return e.jsxs("div",{className:M("flex flex-col gap-4 rounded-lg border border-border bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",t),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:M("text-sm font-medium",c),children:l}),e.jsx("p",{className:M("text-xs text-muted-foreground",o),children:n})]}),e.jsx(B,{checked:s,onCheckedChange:a,className:"self-start sm:self-auto"})]})}function ee({label:s,onChange:t,placeholder:n,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:s}),e.jsx(w,{value:o,onChange:l=>t(l.target.value),placeholder:n,className:"font-mono text-xs"})]})}const V={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async s=>ft(vt.post("/api/auth/web",s)),cleanupLogs:async()=>Te({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Te({url:"/api/logs/clear",method:"POST"})};function Dt(){const{t:s}=R(),{pushToast:t}=jt(),[n,o]=m.useState(te[0].id),l=m.useRef(new Map),c=m.useCallback(r=>{const g=l.current.get(r);g&&g.scrollIntoView({behavior:"smooth",block:"start"})},[]),a=m.useCallback(r=>g=>{g?l.current.set(r,g):l.current.delete(r)},[]),i=Me(_.config.info(),Oe.configInfoRequest()),h=Me(_.auth.web(),V.authStatusRequest()),p=Q({mutationFn:V.saveWebAuth,successToast:()=>({title:s("settings.auth.toast.success")}),errorToast:r=>({title:s("settings.auth.toast.failure",{message:r.message})}),invalidateKeys:[_.auth.web()]}),T=Q({mutationFn:V.cleanupLogs,successToast:r=>({title:r.deleted>0?s("settings.toast.cleanupSuccess",{count:r.deleted}):s("settings.toast.cleanupNone")}),errorToast:r=>({title:s("settings.toast.cleanupFailure",{message:r.message})})}),x=Q({mutationFn:V.clearLogs,successToast:r=>({title:s("settings.toast.clearAllSuccess",{logs:r.deleted,metrics:r.metricsCleared})}),errorToast:r=>({title:s("settings.toast.clearAllFailure",{message:r.message})})}),[d,N]=m.useState(null),[C,He]=m.useState(""),[u,H]=m.useState({port:"",host:"",logRetentionDays:"",logExportTimeoutSeconds:"60",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[De,I]=m.useState({}),[Ke,se]=m.useState(!1),[qe,ae]=m.useState(!1),[Ve,ne]=m.useState(!1),[Be,Ie]=m.useState(!1),[$e,We]=m.useState(!1),[j,re]=m.useState(null),[b,D]=m.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ge,K]=m.useState({}),[Je,le]=m.useState(!1),Qe=m.useMemo(()=>{if(!(d!=null&&d.defaults))return null;const r=[];return d.defaults.completion&&r.push(s("settings.defaults.completion",{model:d.defaults.completion})),d.defaults.reasoning&&r.push(s("settings.defaults.reasoning",{model:d.defaults.reasoning})),d.defaults.background&&r.push(s("settings.defaults.background",{model:d.defaults.background})),r.length>0?r.join(" | "):s("settings.defaults.none")},[d,s]),_e=m.useMemo(()=>u.httpEnabled&&u.httpsEnabled?s("settings.overview.values.httpAndHttps"):u.httpsEnabled?s("settings.overview.values.httpsOnly"):s("settings.overview.values.httpOnly"),[u.httpEnabled,u.httpsEnabled,s]),ze=m.useMemo(()=>b.enabled?j!=null&&j.hasPassword?b.username.trim()!==(j.username??""):!0:!1,[b.enabled,b.username,j]),O=m.useMemo(()=>d?z(d):null,[d]),Ye=m.useMemo(()=>O?JSON.stringify(u)!==JSON.stringify(O):!1,[u,O]),$=m.useMemo(()=>j?Y(j):null,[j]),Ue=m.useMemo(()=>$?JSON.stringify(b)!==JSON.stringify($):!1,[b,$]),Xe=m.useMemo(()=>O?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(g=>u[g]!==O[g]):!1,[u,O]);m.useEffect(()=>{i.data&&(N(i.data.config),He(i.data.path),H(z(i.data.config)))},[i.data]),m.useEffect(()=>{h.data&&(re(h.data),D(Y(h.data)),K({}))},[h.data]),m.useEffect(()=>{!i.isError||!i.error||t({title:s("settings.toast.loadFailure",{message:i.error.message}),variant:"error"})},[i.error,i.isError,t,s]),m.useEffect(()=>{!h.isError||!h.error||t({title:s("settings.toast.authLoadFailure",{message:h.error.message}),variant:"error"})},[h.error,h.isError,t,s]);const Ze=m.useCallback(r=>g=>{H(y=>({...y,[r]:g}))},[]),oe=m.useCallback(()=>{const r={};if(!u.httpEnabled&&!u.httpsEnabled&&(r.protocol=s("settings.validation.protocolRequired")),u.httpEnabled){const S=Number(u.httpPort);(!Number.isFinite(S)||S<1||S>65535)&&(r.httpPort=s("settings.validation.httpPort"))}if(u.httpsEnabled){const S=Number(u.httpsPort);(!Number.isFinite(S)||S<1||S>65535)&&(r.httpsPort=s("settings.validation.httpsPort")),(!u.httpsKeyPath||!u.httpsCertPath)&&(r.protocol=s("settings.validation.httpsCertificate"))}const g=Number(u.port);(!Number.isFinite(g)||g<1||g>65535)&&(r.port=s("settings.validation.port"));const y=Number(u.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(r.logRetentionDays=s("settings.validation.retention"));const P=Number(u.logExportTimeoutSeconds);(!Number.isFinite(P)||P<5||P>600)&&(r.logExportTimeoutSeconds=s("settings.validation.logExportTimeout"));const F=Number(u.bodyLimitMb);return(!Number.isFinite(F)||F<1||F>2048)&&(r.bodyLimitMb=s("settings.validation.bodyLimit")),I(r),Object.keys(r).length===0},[u,s]),ie=m.useCallback(()=>{const r={},g=b.username.trim(),y=j?g!==(j.username??""):!0,P=b.enabled&&(!(j!=null&&j.hasPassword)||y);return b.enabled&&!g&&(r.username=s("settings.auth.validation.username")),b.password&&b.password.length<6&&(r.password=s("settings.auth.validation.minLength")),P&&!b.password&&(r.password=s("settings.auth.validation.passwordRequired")),(b.password||b.confirmPassword)&&b.password!==b.confirmPassword&&(r.confirmPassword=s("settings.auth.validation.confirmMismatch")),K(r),Object.keys(r).length===0},[b,j,s]),et=m.useCallback(async()=>{var r,g,y,P,F,S,ce,de,ue,me,pe,he,ge,xe,be,fe,ve,je,ye,Ne,we,Ce,Pe,ke,Se,Re;if(!d){t({title:s("settings.toast.loadFailure",{message:s("settings.toast.missingConfig")}),variant:"error"});return}if(oe()){se(!0);try{const q=Number(u.port),ot=Number(u.logRetentionDays),it=Number(u.logExportTimeoutSeconds),ct=Number(u.bodyLimitMb),f={...d,http:{enabled:u.httpEnabled,port:Number(u.httpPort),host:u.httpHost.trim()||"127.0.0.1"},https:{enabled:u.httpsEnabled,port:Number(u.httpsPort),host:u.httpsHost.trim()||"127.0.0.1",keyPath:u.httpsKeyPath.trim(),certPath:u.httpsCertPath.trim(),caPath:u.httpsCaPath.trim()||void 0},port:q,host:u.host.trim()||void 0,logRetentionDays:ot,logExportTimeoutSeconds:Math.min(Math.max(Math.round(it),5),600),storeRequestPayloads:u.storeRequestPayloads,storeResponsePayloads:u.storeResponsePayloads,logLevel:u.logLevel,bodyLimit:Math.max(1,Math.floor(ct*1024*1024)),enableRoutingFallback:u.enableRoutingFallback};delete f.requestLogging,delete f.responseLogging;const Ee={...f};delete Ee.webAuth,await Oe.saveConfig(Ee),N({...f,webAuth:d.webAuth});const Ae=G=>(G==null?void 0:G.trim())||void 0,dt=d.port??((r=d.http)==null?void 0:r.port)??4100,ut=f.port??((g=f.http)==null?void 0:g.port)??4100,mt=((y=d.host)==null?void 0:y.trim())||((F=(P=d.http)==null?void 0:P.host)==null?void 0:F.trim())||"127.0.0.1",pt=((S=f.host)==null?void 0:S.trim())||((de=(ce=f.http)==null?void 0:ce.host)==null?void 0:de.trim())||"127.0.0.1",ht=dt!==ut||mt!==pt||((ue=d.http)==null?void 0:ue.enabled)!==((me=f.http)==null?void 0:me.enabled)||((pe=d.http)==null?void 0:pe.port)!==((he=f.http)==null?void 0:he.port)||(((ge=d.http)==null?void 0:ge.host)??d.host??"127.0.0.1")!==(((xe=f.http)==null?void 0:xe.host)??f.host??"127.0.0.1")||((be=d.https)==null?void 0:be.enabled)!==((fe=f.https)==null?void 0:fe.enabled)||((ve=d.https)==null?void 0:ve.port)!==((je=f.https)==null?void 0:je.port)||(((ye=d.https)==null?void 0:ye.host)??d.host??"127.0.0.1")!==(((Ne=f.https)==null?void 0:Ne.host)??f.host??"127.0.0.1")||((we=d.https)==null?void 0:we.keyPath)!==((Ce=f.https)==null?void 0:Ce.keyPath)||((Pe=d.https)==null?void 0:Pe.certPath)!==((ke=f.https)==null?void 0:ke.certPath)||Ae((Se=d.https)==null?void 0:Se.caPath)!==Ae((Re=f.https)==null?void 0:Re.caPath);t({title:s(ht?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),i.refetch()}catch(q){t({title:s("settings.toast.saveFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}finally{se(!1)}}},[d,i,u,t,s,oe]),tt=m.useCallback(()=>{d&&(H(z(d)),I({}))},[d]),st=m.useCallback(async()=>{if(ie()){le(!0);try{const r={enabled:b.enabled,username:b.username.trim()||void 0};b.password&&(r.password=b.password);const g=await p.mutateAsync(r);g.auth&&(re(g.auth),D({enabled:g.auth.enabled,username:g.auth.username??"",password:"",confirmPassword:""}),K({})),h.refetch()}catch{}finally{le(!1)}}},[b,h,p,ie]),at=m.useCallback(()=>{j&&(D(Y(j)),K({}))},[j]),nt=m.useCallback(async()=>{if(!C){t({title:s("settings.toast.copyFailure",{message:s("settings.file.unknown")}),variant:"error"});return}try{await St(C),t({title:s("settings.toast.copySuccess"),variant:"success"})}catch(r){t({title:s("settings.toast.copyFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}},[C,t,s]),rt=m.useCallback(async()=>{ae(!0);try{await T.mutateAsync()}catch{}finally{ae(!1)}},[T]),lt=m.useCallback(async()=>{ne(!0);try{await x.mutateAsync()}catch{}finally{ne(!1)}},[x]),W=i.isPending||!d&&i.isFetching;return m.useEffect(()=>{if(W)return;const r=Array.from(l.current.values());if(r.length===0)return;const g=new IntersectionObserver(y=>{for(const P of y)if(P.isIntersecting){o(P.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of r)g.observe(y);return()=>g.disconnect()},[W]),{activeSection:n,authErrors:Ge,authForm:b,authQuery:h,authSettings:j,clearingAll:Ve,cleaning:qe,config:d,configPath:C,configQuery:i,confirmCleanupOpen:Be,confirmClearAllOpen:$e,defaultsSummary:Qe,errors:De,form:u,handleAuthReset:at,handleAuthSave:st,handleCleanupLogs:rt,handleClearAllLogs:lt,handleCopyPath:nt,handleInputChange:Ze,handleReset:tt,handleSave:et,handleSectionClick:c,isAuthDirty:Ue,isConfigDirty:Ye,isLoading:W,needsPassword:ze,protocolSummaryLabel:_e,protocolChangesPending:Xe,saving:Ke,savingAuth:Je,sectionRefs:l,setAuthForm:D,setConfirmCleanupOpen:Ie,setConfirmClearAllOpen:We,setErrors:I,setForm:H,setSectionRef:a,t:s}}function ns(){var l,c;const{t:s}=R(),t=Dt(),n=Number(t.isConfigDirty)+Number(t.isAuthDirty),o=t.protocolChangesPending?s("settings.protocol.restartHint"):s("settings.overview.description");return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(yt,{icon:e.jsx(bt,{className:"h-5 w-5","aria-hidden":"true"}),title:s("settings.title"),description:s("settings.description"),eyebrow:"Gateway Controls",breadcrumb:"Gateway / Settings",helper:o,badge:n>0?s("settings.overview.unsavedCount",{count:n}):void 0,actions:t.config?e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:t.protocolChangesPending?s("settings.protocol.restartWarning"):s("common.status.success")}),e.jsx(k,{variant:"outline",onClick:t.handleReset,disabled:t.saving||!t.isConfigDirty,className:"w-full sm:w-auto",children:s("common.actions.reset")}),e.jsx(k,{onClick:()=>void t.handleSave(),disabled:t.saving||!t.isConfigDirty,className:"w-full sm:w-auto",children:t.saving?s("common.actions.saving"):s("common.actions.save")})]}):null}),t.isLoading?e.jsx(A,{children:e.jsx(L,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Fe,{})})}):t.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Et,{activeSection:t.activeSection,onSelectSection:t.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(At,{configPath:t.configPath,defaultsSummary:t.defaultsSummary,form:t.form,protocolSummaryLabel:t.protocolSummaryLabel,protocolChangesPending:t.protocolChangesPending,isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,authEnabled:((l=t.authSettings)==null?void 0:l.enabled)??!1,authUsername:(c=t.authSettings)==null?void 0:c.username}),e.jsx(Lt,{defaultsSummary:t.defaultsSummary,errors:t.errors,form:t.form,onInputChange:t.handleInputChange,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-basics")}),e.jsx(Tt,{errors:t.errors,form:t.form,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-protocol")}),e.jsx(Mt,{authErrors:t.authErrors,authForm:t.authForm,authLoading:t.authQuery.isPending||!t.authSettings&&t.authQuery.isFetching,authSettings:t.authSettings,needsPassword:t.needsPassword,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onSetAuthForm:t.setAuthForm,savingAuth:t.savingAuth,isAuthDirty:t.isAuthDirty,sectionRef:t.setSectionRef("section-security")}),e.jsx(Ot,{configPath:t.configPath,onCopyPath:()=>void t.handleCopyPath(),sectionRef:t.setSectionRef("section-config-file")}),e.jsx(Ft,{cleaning:t.cleaning,clearingAll:t.clearingAll,onOpenCleanup:()=>t.setConfirmCleanupOpen(!0),onOpenClearAll:()=>t.setConfirmClearAllOpen(!0),sectionRef:t.setSectionRef("section-cleanup")})]})]}),e.jsx(Ht,{isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,protocolChangesPending:t.protocolChangesPending,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onReset:t.handleReset,onSave:()=>void t.handleSave(),saving:t.saving,savingAuth:t.savingAuth})]}):e.jsx(A,{children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:s("settings.toast.missingConfig")})})}),e.jsx(Le,{open:t.confirmCleanupOpen,onOpenChange:a=>{!a&&!t.cleaning&&t.setConfirmCleanupOpen(!1)},title:s("settings.cleanup.confirmTitle"),description:s("settings.cleanup.confirmDescription"),confirmLabel:t.cleaning?s("common.actions.cleaning"):s("common.actions.cleanup"),cancelLabel:s("common.actions.cancel"),loading:t.cleaning,onConfirm:async()=>{await t.handleCleanupLogs(),t.setConfirmCleanupOpen(!1)}}),e.jsx(Le,{open:t.confirmClearAllOpen,onOpenChange:a=>{!a&&!t.clearingAll&&t.setConfirmClearAllOpen(!1)},title:s("settings.cleanup.clearAllTitle"),description:s("settings.cleanup.clearAllWarning"),confirmLabel:t.clearingAll?s("settings.cleanup.clearingAll"):s("settings.cleanup.clearAll"),cancelLabel:s("common.actions.cancel"),loading:t.clearingAll,onConfirm:async()=>{await t.handleClearAllLogs(),t.setConfirmClearAllOpen(!1)}})]})}export{ns as default};
|
|
1
|
+
import{j as e,aC as J,ay as gt,ax as xt,r as m,Z as bt}from"./vendor-DfnQOGOQ.js";import{C as Le}from"./ConfirmDialog-Dwx6RgvT.js";import{c as M,L as Fe,B as k,r as Te,h as ft,b as vt,u as jt}from"./index-BYn7J5K_.js";import{P as yt}from"./PageHeader-DipLZp28.js";import{C as A,a as L}from"./card-Vz-Wm3NU.js";import{B as E}from"./badge-CUJnXP--.js";import{I as w}from"./input-BpqO0M53.js";import{L as v}from"./label-G00TC871.js";import{S as B}from"./switch-tXufYzT3.js";import{S as Nt,a as wt,b as Ct,c as Pt,d as kt}from"./select-D49a8SjJ.js";import{u as R}from"./i18n-dgCQR_PB.js";import{u as Me}from"./useApiQuery-Dqxujlur.js";import{u as Q}from"./useAppMutation-D-iOmckM.js";import{g as Oe}from"./gateway-D8Ly9AH3.js";import{c as St}from"./clipboard-CALi6bTW.js";import{q as _}from"./queryKeys-BMvyDTQS.js";import"./DialogShell-DpB7I936.js";import"./radix-D08JKSgz.js";import"./query-Db16w3tH.js";import"./router-BURlSZbt.js";const Rt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],te=[{id:"section-basics",labelKey:"settings.sections.basics"},{id:"section-protocol",labelKey:"settings.sections.protocol"},{id:"section-security",labelKey:"settings.sections.security"},{id:"section-config-file",labelKey:"settings.sections.configFile"},{id:"section-cleanup",labelKey:"settings.sections.cleanup"}];function z(s){var o,l,c,a,i,h,p,T,x,d,N;const t=s.storePayloads,n=C=>typeof C=="boolean"?C:typeof t=="boolean"?t:!0;return{port:String(s.port??((o=s.http)==null?void 0:o.port)??""),host:s.host??((l=s.http)==null?void 0:l.host)??"127.0.0.1",logRetentionDays:String(s.logRetentionDays??30),logExportTimeoutSeconds:String(s.logExportTimeoutSeconds??60),storeRequestPayloads:n(s.storeRequestPayloads),storeResponsePayloads:n(s.storeResponsePayloads),logLevel:s.logLevel??"info",bodyLimitMb:(()=>{const C=s.bodyLimit;return typeof C=="number"&&Number.isFinite(C)&&C>0?String(Math.max(1,Math.round(C/(1024*1024)))):"10"})(),enableRoutingFallback:s.enableRoutingFallback===!0,httpEnabled:((c=s.http)==null?void 0:c.enabled)!==!1,httpPort:String(((a=s.http)==null?void 0:a.port)??s.port??4100),httpHost:((i=s.http)==null?void 0:i.host)??s.host??"127.0.0.1",httpsEnabled:((h=s.https)==null?void 0:h.enabled)===!0,httpsPort:String(((p=s.https)==null?void 0:p.port)??4443),httpsHost:((T=s.https)==null?void 0:T.host)??s.host??"127.0.0.1",httpsKeyPath:((x=s.https)==null?void 0:x.keyPath)??"",httpsCertPath:((d=s.https)==null?void 0:d.certPath)??"",httpsCaPath:((N=s.https)==null?void 0:N.caPath)??""}}function Z(s){return{enabled:s.enabled,username:s.username??"",password:"",confirmPassword:""}}function Et({activeSection:s,onSelectSection:t}){const{t:n}=R();return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs("div",{className:"sticky top-20 rounded-lg border border-border bg-card p-4",children:[e.jsx("p",{className:"mb-3 text-xs font-medium uppercase tracking-wider text-muted-foreground",children:n("settings.sections.jump")}),e.jsx("div",{className:"space-y-1",children:te.map((o,l)=>e.jsxs("button",{type:"button",onClick:()=>t(o.id),className:M("flex w-full items-center gap-3 rounded-full px-3.5 py-2.5 text-left text-sm transition-all",s===o.id?"bg-accent font-medium text-primary":"text-muted-foreground hover:bg-secondary hover:text-foreground"),children:[e.jsx("span",{className:M("flex h-7 w-7 items-center justify-center rounded-full border text-[11px] font-semibold",s===o.id?"border-primary/20 bg-primary text-primary-foreground":"border-border bg-secondary text-muted-foreground"),children:l+1}),e.jsx("span",{children:n(o.labelKey)})]},o.id))})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"-mx-1 overflow-x-auto pb-1",children:e.jsx("div",{className:"flex w-max gap-2 px-1",children:te.map(o=>e.jsx("button",{type:"button",onClick:()=>t(o.id),className:M("rounded-full border px-3.5 py-2 text-xs font-medium transition-all",s===o.id?"border-primary bg-accent text-primary":"border-border bg-card text-muted-foreground hover:border-primary/20 hover:bg-accent hover:text-primary"),children:n(o.labelKey)},o.id))})})})]})}function At({configPath:s,defaultsSummary:t,form:n,protocolSummaryLabel:o,protocolChangesPending:l,isAuthDirty:c,isConfigDirty:a,authEnabled:i,authUsername:h}){const{t:p}=R();return e.jsx(A,{children:e.jsxs(L,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:p("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p("settings.overview.description")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:a||c?"warning":"success",children:p(a||c?"modelManagement.actions.unsaved":"common.status.success")}),l?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.protocol.restartWarning")}):null]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(U,{label:p("settings.overview.cards.protocols"),value:o,helper:`${n.httpHost||"127.0.0.1"}:${n.httpPort}${n.httpsEnabled?` / ${n.httpsHost||"127.0.0.1"}:${n.httpsPort}`:""}`}),e.jsx(U,{label:p("settings.overview.cards.security"),value:p(i?"settings.overview.values.authEnabled":"settings.overview.values.authDisabled"),helper:h?`${p("settings.auth.username")}: ${h}`:p("settings.auth.enableHint")}),e.jsx(U,{label:p("settings.overview.cards.configFile"),value:s||p("settings.file.unknown"),helper:t??p("settings.defaults.none"),mono:!0})]})]})})}function Lt({defaultsSummary:s,errors:t,form:n,onInputChange:o,onSetForm:l,sectionRef:c}){const{t:a}=R();return e.jsx(A,{id:"section-basics",ref:c,children:e.jsxs(L,{className:"pt-6",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("settings.sections.basics")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("settings.description")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(X,{label:a("settings.fields.retention"),value:n.logRetentionDays}),e.jsx(X,{label:a("settings.fields.logExportTimeout"),value:`${n.logExportTimeoutSeconds}s`}),e.jsx(X,{label:a("settings.fields.bodyLimit"),value:`${n.bodyLimitMb} MB`})]})]}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:n.port,onChange:i=>o("port")(i.target.value),"aria-invalid":!!t.port}),t.port?e.jsx("p",{className:"text-xs text-destructive",children:t.port}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.host")}),e.jsx(w,{value:n.host,onChange:i=>o("host")(i.target.value),placeholder:a("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.retention")}),e.jsx(w,{type:"number",min:1,max:365,value:n.logRetentionDays,onChange:i=>o("logRetentionDays")(i.target.value),"aria-invalid":!!t.logRetentionDays}),t.logRetentionDays?e.jsx("p",{className:"text-xs text-destructive",children:t.logRetentionDays}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.logExportTimeout")}),e.jsx(w,{type:"number",min:5,max:600,value:n.logExportTimeoutSeconds,onChange:i=>o("logExportTimeoutSeconds")(i.target.value),"aria-invalid":!!t.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.fields.logExportTimeoutHint")}),t.logExportTimeoutSeconds?e.jsx("p",{className:"text-xs text-destructive",children:t.logExportTimeoutSeconds}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.bodyLimit")}),e.jsx(w,{type:"number",min:1,max:2048,value:n.bodyLimitMb,onChange:i=>o("bodyLimitMb")(i.target.value),"aria-invalid":!!t.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.fields.bodyLimitHint")}),t.bodyLimitMb?e.jsx("p",{className:"text-xs text-destructive",children:t.bodyLimitMb}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:a("settings.fields.logLevel")}),e.jsxs(Nt,{value:n.logLevel,onValueChange:i=>l(h=>({...h,logLevel:i})),children:[e.jsx(wt,{children:e.jsx(Ct,{})}),e.jsx(Pt,{children:Rt.map(i=>e.jsx(kt,{value:i.value,children:a(`settings.fields.logLevelOption.${i.labelKey}`)},i.value))})]})]}),e.jsxs("div",{className:"grid gap-4 md:col-span-2 sm:grid-cols-2",children:[e.jsx(Y,{label:a("settings.fields.storeRequestPayloads"),hint:a("settings.fields.storeRequestPayloadsHint"),checked:n.storeRequestPayloads,onCheckedChange:i=>l(h=>({...h,storeRequestPayloads:i}))}),e.jsx(Y,{label:a("settings.fields.storeResponsePayloads"),hint:a("settings.fields.storeResponsePayloadsHint"),checked:n.storeResponsePayloads,onCheckedChange:i=>l(h=>({...h,storeResponsePayloads:i}))}),e.jsx(Y,{label:a("settings.fields.enableRoutingFallback"),hint:a("settings.fields.enableRoutingFallbackHint"),checked:n.enableRoutingFallback,onCheckedChange:i=>l(h=>({...h,enableRoutingFallback:i}))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-4 md:col-span-2",children:[e.jsx(v,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:a("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:s??a("settings.defaults.none")})]})]})]})})}function Tt({errors:s,form:t,onSetForm:n,sectionRef:o}){const{t:l}=R();return e.jsx(A,{id:"section-protocol",ref:o,children:e.jsxs(L,{className:"space-y-6 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:l("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-[hsl(var(--warning)/1)]"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:l("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-lg border border-border bg-secondary px-3 py-2 text-xs font-mono text-foreground",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.restartTip")})]})]})}),s.protocol?e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(J,{className:"mr-2 inline h-4 w-4"}),s.protocol]}):null,e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.http.hint")})]}),e.jsx(B,{checked:t.httpEnabled,onCheckedChange:c=>n(a=>({...a,httpEnabled:c}))})]}),t.httpEnabled?e.jsxs("div",{className:"mt-4 grid gap-4 border-t border-border pt-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.http.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpPort,onChange:c=>n(a=>({...a,httpPort:c.target.value})),"aria-invalid":!!s.httpPort}),s.httpPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.http.host")}),e.jsx(w,{value:t.httpHost,onChange:c=>n(a=>({...a,httpHost:c.target.value})),placeholder:"127.0.0.1"})]})]}):null]}),e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"text-sm font-medium text-foreground",children:l("settings.protocol.https.enable")}),e.jsx(gt,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.protocol.https.hint")})]}),e.jsx(B,{checked:t.httpsEnabled,onCheckedChange:c=>n(a=>({...a,httpsEnabled:c}))})]}),t.httpsEnabled?e.jsxs("div",{className:"mt-4 space-y-4 border-t border-border pt-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.https.port")}),e.jsx(w,{type:"number",min:1,max:65535,value:t.httpsPort,onChange:c=>n(a=>({...a,httpsPort:c.target.value})),"aria-invalid":!!s.httpsPort}),s.httpsPort?e.jsx("p",{className:"text-xs text-destructive",children:s.httpsPort}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:l("settings.protocol.https.host")}),e.jsx(w,{value:t.httpsHost,onChange:c=>n(a=>({...a,httpsHost:c.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsx(ee,{label:l("settings.protocol.https.keyPath"),value:t.httpsKeyPath,onChange:c=>n(a=>({...a,httpsKeyPath:c})),placeholder:"~/.cc-gw/certs/key.pem"}),e.jsx(ee,{label:l("settings.protocol.https.certPath"),value:t.httpsCertPath,onChange:c=>n(a=>({...a,httpsCertPath:c})),placeholder:"~/.cc-gw/certs/cert.pem"}),e.jsx(ee,{label:l("settings.protocol.https.caPath"),value:t.httpsCaPath,onChange:c=>n(a=>({...a,httpsCaPath:c})),placeholder:"留空则不使用"}),e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(J,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-[hsl(var(--warning)/1)]"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:l("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:l("settings.protocol.https.invalidCert")}),l("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs leading-relaxed text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:l("settings.protocol.https.recommended")}),l("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-600 dark:text-amber-400",children:l("settings.protocol.https.tip")})]})]})})]}):null]})]})})}function Mt({authErrors:s,authForm:t,authLoading:n,authSettings:o,needsPassword:l,onAuthReset:c,onAuthSave:a,onSetAuthForm:i,savingAuth:h,isAuthDirty:p,sectionRef:T}){const{t:x}=R();return e.jsx(A,{id:"section-security",ref:T,children:e.jsxs(L,{className:"space-y-5 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:x("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:x("settings.auth.description")})]}),n&&!o?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Fe,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 rounded-lg border border-border bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{className:"text-sm font-medium",children:x("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"/ui"}),e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"/api/*"}),e.jsx("span",{className:"rounded-full border border-border bg-card px-3 py-1",children:"Cookie Session"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 self-start sm:self-auto",children:[e.jsx(E,{variant:t.enabled?"success":"secondary",children:t.enabled?x("settings.auth.statusEnabled"):x("settings.auth.statusDisabled")}),e.jsx(B,{checked:t.enabled,onCheckedChange:d=>i(N=>({...N,enabled:d}))})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(v,{children:x("settings.auth.username")}),e.jsx(w,{value:t.username,onChange:d=>i(N=>({...N,username:d.target.value})),placeholder:x("settings.auth.usernamePlaceholder")}),s.username?e.jsx("p",{className:"text-xs text-destructive",children:s.username}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:x("settings.auth.password")}),e.jsx(w,{type:"password",value:t.password,disabled:!t.enabled,onChange:d=>i(N=>({...N,password:d.target.value})),placeholder:x("settings.auth.passwordPlaceholder")}),s.password?e.jsx("p",{className:"text-xs text-destructive",children:s.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:x(l?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:x("settings.auth.confirmPassword")}),e.jsx(w,{type:"password",value:t.confirmPassword,disabled:!t.enabled,onChange:d=>i(N=>({...N,confirmPassword:d.target.value})),placeholder:x("settings.auth.confirmPasswordPlaceholder")}),s.confirmPassword?e.jsx("p",{className:"text-xs text-destructive",children:s.confirmPassword}):null]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:x("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?x("settings.auth.statusEnabled"):x("settings.auth.statusDisabled")}),o!=null&&o.username?e.jsxs("div",{className:"mt-3 rounded-lg bg-accent px-3 py-2 text-xs font-medium text-primary",children:[x("settings.auth.username"),": ",o.username]}):null]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary p-4 text-xs text-muted-foreground",children:x(l?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:flex lg:flex-wrap lg:justify-end",children:[e.jsx(k,{onClick:a,disabled:h||!p,className:"w-full lg:w-auto",children:x(h?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(k,{variant:"outline",onClick:c,disabled:h||!p,className:"w-full lg:w-auto",children:x("common.actions.reset")})]})]})]})})}function Ot({configPath:s,onCopyPath:t,sectionRef:n}){const{t:o}=R();return e.jsx(A,{id:"section-config-file",ref:n,children:e.jsxs(L,{className:"space-y-3 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:o("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("settings.file.description")})]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,className:"w-full sm:w-auto",children:[e.jsx(xt,{className:"mr-2 h-4 w-4"}),o("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg border border-border bg-secondary px-4 py-3 text-xs",children:s||o("settings.file.unknown")}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:o("help.note")})]})})}function Ft({cleaning:s,clearingAll:t,onOpenCleanup:n,onOpenClearAll:o,sectionRef:l}){const{t:c}=R();return e.jsx(A,{id:"section-cleanup",ref:l,children:e.jsxs(L,{className:"space-y-4 pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:c("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c("settings.cleanup.description")})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:c("settings.cleanup.confirmCleanup")}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-lg border border-[hsl(var(--warning)/0.3)] bg-[hsl(var(--warning-bg))] p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"warning",children:c("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:c("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.cleanup.softDescription")}),e.jsx(k,{variant:"outline",onClick:n,disabled:s,className:"w-full sm:w-auto",children:c(s?"common.actions.cleaning":"common.actions.cleanup")})]})}),e.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:c("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:c("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.cleanup.clearAllWarning")}),e.jsx(k,{variant:"destructive",onClick:o,disabled:t,className:"w-full sm:w-auto",children:c(t?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})}function Ht({isAuthDirty:s,isConfigDirty:t,protocolChangesPending:n,onAuthReset:o,onAuthSave:l,onReset:c,onSave:a,saving:i,savingAuth:h}){const{t:p}=R();return!s&&!t?null:e.jsxs("div",{className:"sticky bottom-4 z-20 flex flex-col gap-3 rounded-lg border border-primary/20 bg-card p-4 shadow-lg backdrop-blur-sm md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(E,{variant:"secondary",children:p("modelManagement.actions.unsaved")}),t?e.jsx(E,{variant:"outline",children:p("settings.sections.basics")}):null,s?e.jsx(E,{variant:"outline",children:p("settings.sections.security")}):null,n?e.jsx(E,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:p("settings.sections.protocol")}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p(n?"settings.toast.protocolRestartRequired":"modelManagement.actions.footerDirtyHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2 lg:flex lg:flex-wrap lg:items-center",children:[s?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:o,disabled:h,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:l,disabled:h,className:"w-full lg:w-auto",children:p(h?"common.actions.saving":"settings.auth.actions.save")})]}):null,t?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",onClick:c,disabled:i,className:"w-full lg:w-auto",children:p("common.actions.reset")}),e.jsx(k,{onClick:a,disabled:i,className:"w-full lg:w-auto",children:p(i?"common.actions.saving":"common.actions.save")})]}):null]})]})}function U({label:s,value:t,helper:n,mono:o=!1}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("p",{className:M("mt-2 text-sm font-semibold text-foreground",o&&"break-all font-mono text-xs"),children:t}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:n})]})}function X({label:s,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:t})]})}function Y({checked:s,className:t,hint:n,hintClassName:o,label:l,labelClassName:c,onCheckedChange:a}){return e.jsxs("div",{className:M("flex flex-col gap-4 rounded-lg border border-border bg-secondary p-4 sm:flex-row sm:items-center sm:justify-between",t),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{className:M("text-sm font-medium",c),children:l}),e.jsx("p",{className:M("text-xs text-muted-foreground",o),children:n})]}),e.jsx(B,{checked:s,onCheckedChange:a,className:"self-start sm:self-auto"})]})}function ee({label:s,onChange:t,placeholder:n,value:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:s}),e.jsx(w,{value:o,onChange:l=>t(l.target.value),placeholder:n,className:"font-mono text-xs"})]})}const V={authStatusRequest(){return{url:"/api/auth/web",method:"GET"}},saveWebAuth:async s=>ft(vt.post("/api/auth/web",s)),cleanupLogs:async()=>Te({url:"/api/logs/cleanup",method:"POST"}),clearLogs:async()=>Te({url:"/api/logs/clear",method:"POST"})};function Dt(){const{t:s}=R(),{pushToast:t}=jt(),[n,o]=m.useState(te[0].id),l=m.useRef(new Map),c=m.useCallback(r=>{const g=l.current.get(r);g&&g.scrollIntoView({behavior:"smooth",block:"start"})},[]),a=m.useCallback(r=>g=>{g?l.current.set(r,g):l.current.delete(r)},[]),i=Me(_.config.info(),Oe.configInfoRequest()),h=Me(_.auth.web(),V.authStatusRequest()),p=Q({mutationFn:V.saveWebAuth,successToast:()=>({title:s("settings.auth.toast.success")}),errorToast:r=>({title:s("settings.auth.toast.failure",{message:r.message})}),invalidateKeys:[_.auth.web()]}),T=Q({mutationFn:V.cleanupLogs,successToast:r=>({title:r.deleted>0?s("settings.toast.cleanupSuccess",{count:r.deleted}):s("settings.toast.cleanupNone")}),errorToast:r=>({title:s("settings.toast.cleanupFailure",{message:r.message})})}),x=Q({mutationFn:V.clearLogs,successToast:r=>({title:s("settings.toast.clearAllSuccess",{logs:r.deleted,metrics:r.metricsCleared})}),errorToast:r=>({title:s("settings.toast.clearAllFailure",{message:r.message})})}),[d,N]=m.useState(null),[C,He]=m.useState(""),[u,H]=m.useState({port:"",host:"",logRetentionDays:"",logExportTimeoutSeconds:"60",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[De,I]=m.useState({}),[Ke,se]=m.useState(!1),[qe,ae]=m.useState(!1),[Ve,ne]=m.useState(!1),[Be,Ie]=m.useState(!1),[$e,We]=m.useState(!1),[j,re]=m.useState(null),[b,D]=m.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[Ge,K]=m.useState({}),[Je,le]=m.useState(!1),Qe=m.useMemo(()=>{if(!(d!=null&&d.defaults))return null;const r=[];return d.defaults.completion&&r.push(s("settings.defaults.completion",{model:d.defaults.completion})),d.defaults.reasoning&&r.push(s("settings.defaults.reasoning",{model:d.defaults.reasoning})),d.defaults.background&&r.push(s("settings.defaults.background",{model:d.defaults.background})),r.length>0?r.join(" | "):s("settings.defaults.none")},[d,s]),_e=m.useMemo(()=>u.httpEnabled&&u.httpsEnabled?s("settings.overview.values.httpAndHttps"):u.httpsEnabled?s("settings.overview.values.httpsOnly"):s("settings.overview.values.httpOnly"),[u.httpEnabled,u.httpsEnabled,s]),ze=m.useMemo(()=>b.enabled?j!=null&&j.hasPassword?b.username.trim()!==(j.username??""):!0:!1,[b.enabled,b.username,j]),O=m.useMemo(()=>d?z(d):null,[d]),Ze=m.useMemo(()=>O?JSON.stringify(u)!==JSON.stringify(O):!1,[u,O]),$=m.useMemo(()=>j?Z(j):null,[j]),Ue=m.useMemo(()=>$?JSON.stringify(b)!==JSON.stringify($):!1,[b,$]),Xe=m.useMemo(()=>O?["httpEnabled","httpPort","httpHost","httpsEnabled","httpsPort","httpsHost","httpsKeyPath","httpsCertPath","httpsCaPath","port","host"].some(g=>u[g]!==O[g]):!1,[u,O]);m.useEffect(()=>{i.data&&(N(i.data.config),He(i.data.path),H(z(i.data.config)))},[i.data]),m.useEffect(()=>{h.data&&(re(h.data),D(Z(h.data)),K({}))},[h.data]),m.useEffect(()=>{!i.isError||!i.error||t({title:s("settings.toast.loadFailure",{message:i.error.message}),variant:"error"})},[i.error,i.isError,t,s]),m.useEffect(()=>{!h.isError||!h.error||t({title:s("settings.toast.authLoadFailure",{message:h.error.message}),variant:"error"})},[h.error,h.isError,t,s]);const Ye=m.useCallback(r=>g=>{H(y=>({...y,[r]:g}))},[]),oe=m.useCallback(()=>{const r={};if(!u.httpEnabled&&!u.httpsEnabled&&(r.protocol=s("settings.validation.protocolRequired")),u.httpEnabled){const S=Number(u.httpPort);(!Number.isFinite(S)||S<1||S>65535)&&(r.httpPort=s("settings.validation.httpPort"))}if(u.httpsEnabled){const S=Number(u.httpsPort);(!Number.isFinite(S)||S<1||S>65535)&&(r.httpsPort=s("settings.validation.httpsPort")),(!u.httpsKeyPath||!u.httpsCertPath)&&(r.protocol=s("settings.validation.httpsCertificate"))}const g=Number(u.port);(!Number.isFinite(g)||g<1||g>65535)&&(r.port=s("settings.validation.port"));const y=Number(u.logRetentionDays);(!Number.isFinite(y)||y<1||y>365)&&(r.logRetentionDays=s("settings.validation.retention"));const P=Number(u.logExportTimeoutSeconds);(!Number.isFinite(P)||P<5||P>600)&&(r.logExportTimeoutSeconds=s("settings.validation.logExportTimeout"));const F=Number(u.bodyLimitMb);return(!Number.isFinite(F)||F<1||F>2048)&&(r.bodyLimitMb=s("settings.validation.bodyLimit")),I(r),Object.keys(r).length===0},[u,s]),ie=m.useCallback(()=>{const r={},g=b.username.trim(),y=j?g!==(j.username??""):!0,P=b.enabled&&(!(j!=null&&j.hasPassword)||y);return b.enabled&&!g&&(r.username=s("settings.auth.validation.username")),b.password&&b.password.length<6&&(r.password=s("settings.auth.validation.minLength")),P&&!b.password&&(r.password=s("settings.auth.validation.passwordRequired")),(b.password||b.confirmPassword)&&b.password!==b.confirmPassword&&(r.confirmPassword=s("settings.auth.validation.confirmMismatch")),K(r),Object.keys(r).length===0},[b,j,s]),et=m.useCallback(async()=>{var r,g,y,P,F,S,ce,de,ue,me,pe,he,ge,xe,be,fe,ve,je,ye,Ne,we,Ce,Pe,ke,Se,Re;if(!d){t({title:s("settings.toast.loadFailure",{message:s("settings.toast.missingConfig")}),variant:"error"});return}if(oe()){se(!0);try{const q=Number(u.port),ot=Number(u.logRetentionDays),it=Number(u.logExportTimeoutSeconds),ct=Number(u.bodyLimitMb),f={...d,http:{enabled:u.httpEnabled,port:Number(u.httpPort),host:u.httpHost.trim()||"127.0.0.1"},https:{enabled:u.httpsEnabled,port:Number(u.httpsPort),host:u.httpsHost.trim()||"127.0.0.1",keyPath:u.httpsKeyPath.trim(),certPath:u.httpsCertPath.trim(),caPath:u.httpsCaPath.trim()||void 0},port:q,host:u.host.trim()||void 0,logRetentionDays:ot,logExportTimeoutSeconds:Math.min(Math.max(Math.round(it),5),600),storeRequestPayloads:u.storeRequestPayloads,storeResponsePayloads:u.storeResponsePayloads,logLevel:u.logLevel,bodyLimit:Math.max(1,Math.floor(ct*1024*1024)),enableRoutingFallback:u.enableRoutingFallback};delete f.requestLogging,delete f.responseLogging;const Ee={...f};delete Ee.webAuth,await Oe.saveConfig(Ee),N({...f,webAuth:d.webAuth});const Ae=G=>(G==null?void 0:G.trim())||void 0,dt=d.port??((r=d.http)==null?void 0:r.port)??4100,ut=f.port??((g=f.http)==null?void 0:g.port)??4100,mt=((y=d.host)==null?void 0:y.trim())||((F=(P=d.http)==null?void 0:P.host)==null?void 0:F.trim())||"127.0.0.1",pt=((S=f.host)==null?void 0:S.trim())||((de=(ce=f.http)==null?void 0:ce.host)==null?void 0:de.trim())||"127.0.0.1",ht=dt!==ut||mt!==pt||((ue=d.http)==null?void 0:ue.enabled)!==((me=f.http)==null?void 0:me.enabled)||((pe=d.http)==null?void 0:pe.port)!==((he=f.http)==null?void 0:he.port)||(((ge=d.http)==null?void 0:ge.host)??d.host??"127.0.0.1")!==(((xe=f.http)==null?void 0:xe.host)??f.host??"127.0.0.1")||((be=d.https)==null?void 0:be.enabled)!==((fe=f.https)==null?void 0:fe.enabled)||((ve=d.https)==null?void 0:ve.port)!==((je=f.https)==null?void 0:je.port)||(((ye=d.https)==null?void 0:ye.host)??d.host??"127.0.0.1")!==(((Ne=f.https)==null?void 0:Ne.host)??f.host??"127.0.0.1")||((we=d.https)==null?void 0:we.keyPath)!==((Ce=f.https)==null?void 0:Ce.keyPath)||((Pe=d.https)==null?void 0:Pe.certPath)!==((ke=f.https)==null?void 0:ke.certPath)||Ae((Se=d.https)==null?void 0:Se.caPath)!==Ae((Re=f.https)==null?void 0:Re.caPath);t({title:s(ht?"settings.toast.protocolRestartRequired":"settings.toast.saveSuccess"),variant:"success"}),i.refetch()}catch(q){t({title:s("settings.toast.saveFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}finally{se(!1)}}},[d,i,u,t,s,oe]),tt=m.useCallback(()=>{d&&(H(z(d)),I({}))},[d]),st=m.useCallback(async()=>{if(ie()){le(!0);try{const r={enabled:b.enabled,username:b.username.trim()||void 0};b.password&&(r.password=b.password);const g=await p.mutateAsync(r);g.auth&&(re(g.auth),D({enabled:g.auth.enabled,username:g.auth.username??"",password:"",confirmPassword:""}),K({})),h.refetch()}catch{}finally{le(!1)}}},[b,h,p,ie]),at=m.useCallback(()=>{j&&(D(Z(j)),K({}))},[j]),nt=m.useCallback(async()=>{if(!C){t({title:s("settings.toast.copyFailure",{message:s("settings.file.unknown")}),variant:"error"});return}try{await St(C),t({title:s("settings.toast.copySuccess"),variant:"success"})}catch(r){t({title:s("settings.toast.copyFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}},[C,t,s]),rt=m.useCallback(async()=>{ae(!0);try{await T.mutateAsync()}catch{}finally{ae(!1)}},[T]),lt=m.useCallback(async()=>{ne(!0);try{await x.mutateAsync()}catch{}finally{ne(!1)}},[x]),W=i.isPending||!d&&i.isFetching;return m.useEffect(()=>{if(W)return;const r=Array.from(l.current.values());if(r.length===0)return;const g=new IntersectionObserver(y=>{for(const P of y)if(P.isIntersecting){o(P.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const y of r)g.observe(y);return()=>g.disconnect()},[W]),{activeSection:n,authErrors:Ge,authForm:b,authQuery:h,authSettings:j,clearingAll:Ve,cleaning:qe,config:d,configPath:C,configQuery:i,confirmCleanupOpen:Be,confirmClearAllOpen:$e,defaultsSummary:Qe,errors:De,form:u,handleAuthReset:at,handleAuthSave:st,handleCleanupLogs:rt,handleClearAllLogs:lt,handleCopyPath:nt,handleInputChange:Ye,handleReset:tt,handleSave:et,handleSectionClick:c,isAuthDirty:Ue,isConfigDirty:Ze,isLoading:W,needsPassword:ze,protocolSummaryLabel:_e,protocolChangesPending:Xe,saving:Ke,savingAuth:Je,sectionRefs:l,setAuthForm:D,setConfirmCleanupOpen:Ie,setConfirmClearAllOpen:We,setErrors:I,setForm:H,setSectionRef:a,t:s}}function ns(){var l,c;const{t:s}=R(),t=Dt(),n=Number(t.isConfigDirty)+Number(t.isAuthDirty),o=t.protocolChangesPending?s("settings.protocol.restartHint"):s("settings.overview.description");return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(yt,{icon:e.jsx(bt,{className:"h-5 w-5","aria-hidden":"true"}),title:s("settings.title"),description:s("settings.description"),eyebrow:"Gateway Controls",breadcrumb:"Gateway / Settings",helper:o,badge:n>0?s("settings.overview.unsavedCount",{count:n}):void 0,actions:t.config?e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:t.protocolChangesPending?s("settings.protocol.restartWarning"):s("common.status.success")}),e.jsx(k,{variant:"outline",onClick:t.handleReset,disabled:t.saving||!t.isConfigDirty,className:"w-full sm:w-auto",children:s("common.actions.reset")}),e.jsx(k,{onClick:()=>void t.handleSave(),disabled:t.saving||!t.isConfigDirty,className:"w-full sm:w-auto",children:t.saving?s("common.actions.saving"):s("common.actions.save")})]}):null}),t.isLoading?e.jsx(A,{children:e.jsx(L,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Fe,{})})}):t.config?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[200px_1fr]",children:[e.jsx(Et,{activeSection:t.activeSection,onSelectSection:t.handleSectionClick}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(At,{configPath:t.configPath,defaultsSummary:t.defaultsSummary,form:t.form,protocolSummaryLabel:t.protocolSummaryLabel,protocolChangesPending:t.protocolChangesPending,isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,authEnabled:((l=t.authSettings)==null?void 0:l.enabled)??!1,authUsername:(c=t.authSettings)==null?void 0:c.username}),e.jsx(Lt,{defaultsSummary:t.defaultsSummary,errors:t.errors,form:t.form,onInputChange:t.handleInputChange,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-basics")}),e.jsx(Tt,{errors:t.errors,form:t.form,onSetForm:t.setForm,sectionRef:t.setSectionRef("section-protocol")}),e.jsx(Mt,{authErrors:t.authErrors,authForm:t.authForm,authLoading:t.authQuery.isPending||!t.authSettings&&t.authQuery.isFetching,authSettings:t.authSettings,needsPassword:t.needsPassword,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onSetAuthForm:t.setAuthForm,savingAuth:t.savingAuth,isAuthDirty:t.isAuthDirty,sectionRef:t.setSectionRef("section-security")}),e.jsx(Ot,{configPath:t.configPath,onCopyPath:()=>void t.handleCopyPath(),sectionRef:t.setSectionRef("section-config-file")}),e.jsx(Ft,{cleaning:t.cleaning,clearingAll:t.clearingAll,onOpenCleanup:()=>t.setConfirmCleanupOpen(!0),onOpenClearAll:()=>t.setConfirmClearAllOpen(!0),sectionRef:t.setSectionRef("section-cleanup")})]})]}),e.jsx(Ht,{isAuthDirty:t.isAuthDirty,isConfigDirty:t.isConfigDirty,protocolChangesPending:t.protocolChangesPending,onAuthReset:t.handleAuthReset,onAuthSave:()=>void t.handleAuthSave(),onReset:t.handleReset,onSave:()=>void t.handleSave(),saving:t.saving,savingAuth:t.savingAuth})]}):e.jsx(A,{children:e.jsx(L,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:s("settings.toast.missingConfig")})})}),e.jsx(Le,{open:t.confirmCleanupOpen,onOpenChange:a=>{!a&&!t.cleaning&&t.setConfirmCleanupOpen(!1)},title:s("settings.cleanup.confirmTitle"),description:s("settings.cleanup.confirmDescription"),confirmLabel:t.cleaning?s("common.actions.cleaning"):s("common.actions.cleanup"),cancelLabel:s("common.actions.cancel"),loading:t.cleaning,onConfirm:async()=>{await t.handleCleanupLogs(),t.setConfirmCleanupOpen(!1)}}),e.jsx(Le,{open:t.confirmClearAllOpen,onOpenChange:a=>{!a&&!t.clearingAll&&t.setConfirmClearAllOpen(!1)},title:s("settings.cleanup.clearAllTitle"),description:s("settings.cleanup.clearAllWarning"),confirmLabel:t.clearingAll?s("settings.cleanup.clearingAll"):s("settings.cleanup.clearAll"),cancelLabel:s("common.actions.cancel"),loading:t.clearingAll,onConfirm:async()=>{await t.handleClearAllLogs(),t.setConfirmClearAllOpen(!1)}})]})}export{ns as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./vendor-
|
|
1
|
+
import{j as e}from"./vendor-DfnQOGOQ.js";import{c as n}from"./index-BYn7J5K_.js";function s({className:a}){return e.jsx("div",{role:"status","aria-label":"Loading",className:n("animate-pulse rounded-xl bg-muted/70",a)})}function o(){return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s,{className:"h-3 w-24"}),e.jsx(s,{className:"h-10 w-10 rounded-xl"})]}),e.jsx(s,{className:"h-8 w-32"})]})}function m(){return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s,{className:"h-4 w-32"}),e.jsx(s,{className:"h-3 w-48"})]}),e.jsx(s,{className:"h-[320px] w-full rounded-lg"})]})}function i({columns:a=6}){const r=["w-24","w-16","w-20","w-28","w-14","w-12","w-20","w-16","w-14","w-12"];return e.jsx("tr",{className:"border-b",children:Array.from({length:a}).map((d,l)=>e.jsx("td",{className:"px-3 py-3",children:e.jsx(s,{className:n("h-4",r[l%r.length])})},l))})}export{m as C,o as S,i as T};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as d,
|
|
1
|
+
import{j as d,a1 as t}from"./vendor-DfnQOGOQ.js";import{c as o}from"./index-BYn7J5K_.js";const n=t("inline-flex items-center rounded-full border px-2.5 py-1 text-[11px] font-semibold tracking-[0.02em] transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-primary/15 bg-primary/10 text-primary hover:bg-primary/15 dark:border-primary/25 dark:bg-primary/15 dark:text-primary-foreground",secondary:"border-border/70 bg-secondary/90 text-secondary-foreground hover:bg-secondary dark:border-border dark:bg-secondary/70 dark:text-secondary-foreground",destructive:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 dark:border-red-900 dark:bg-red-950/60 dark:text-red-300",outline:"border-border bg-transparent text-muted-foreground hover:bg-accent dark:border-border dark:text-muted-foreground dark:hover:bg-accent",success:"border-emerald-200 bg-emerald-50 text-emerald-700 hover:bg-emerald-100 dark:border-emerald-900 dark:bg-emerald-950/60 dark:text-emerald-300",warning:"border-amber-200 bg-amber-50 text-amber-700 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-300",info:"border-cyan-200 bg-cyan-50 text-cyan-700 hover:bg-cyan-100 dark:border-cyan-900 dark:bg-cyan-950/60 dark:text-cyan-300",purple:"border-violet-200 bg-violet-50 text-violet-700 hover:bg-violet-100 dark:border-violet-900 dark:bg-violet-950/60 dark:text-violet-300",pink:"border-pink-200 bg-pink-50 text-pink-700 hover:bg-pink-100 dark:border-pink-900 dark:bg-pink-950/60 dark:text-pink-300"}},defaultVariants:{variant:"default"}});function g({className:r,variant:e,...a}){return d.jsx("div",{className:o(n({variant:e}),r),...a})}export{g as B};
|