@chenpu17/cc-gw 0.12.0 → 0.13.0

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.
Files changed (23) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-B4KoKSAM.js → About-BJbSQIDc.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-CwiStTlS.js → ApiKeys-C8I9ti-a.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-cZsL-k-v.js → ConfirmDialog-BOe5HI56.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-khRk8U0-.js → Dashboard-C7n9KzBy.js} +1 -1
  6. package/src/web/dist/assets/{Events-BGQklKqB.js → Events-BGfmA69d.js} +1 -1
  7. package/src/web/dist/assets/{Help-B2MDKuj8.js → Help-DUrs56_n.js} +1 -1
  8. package/src/web/dist/assets/{Login-CrvH8tn2.js → Login-Dxeq-BfV.js} +1 -1
  9. package/src/web/dist/assets/{Logs-DoAgVjw3.js → Logs-VRdCNMkl.js} +1 -1
  10. package/src/web/dist/assets/{ProvidersWorkbench-CI7TbMf1.js → ProvidersWorkbench-DOGrU9Xl.js} +1 -1
  11. package/src/web/dist/assets/{Settings-BnqMqPol.js → Settings-CGxWfI_h.js} +1 -1
  12. package/src/web/dist/assets/{Setup-deGPdPcE.js → Setup-yKUdrXJQ.js} +1 -1
  13. package/src/web/dist/assets/{apiKeys-Ol_q3sZL.js → apiKeys-B-WRyKci.js} +1 -1
  14. package/src/web/dist/assets/{app-BBAnVEPg.js → app-BnQl39hq.js} +2 -2
  15. package/src/web/dist/assets/{gateway-B_xLF-Rk.js → gateway-DxCj_uok.js} +1 -1
  16. package/src/web/dist/assets/{landing-MsSWlQKc.js → landing-BuuM1jg8.js} +1 -1
  17. package/src/web/dist/assets/package-CKkVmaOi.js +1 -0
  18. package/src/web/dist/assets/{shared-BIsbTzWd.js → shared-DHBfRHZV.js} +1 -1
  19. package/src/web/dist/assets/{useAppMutation-Ds2SX3kE.js → useAppMutation-Cix9n50u.js} +1 -1
  20. package/src/web/dist/assets/{useProviderForm-CtZEenP9.js → useProviderForm-CsPV2Cqr.js} +1 -1
  21. package/src/web/dist/index.html +1 -1
  22. package/src/web/dist/landing.html +2 -2
  23. package/src/web/dist/assets/package-DHb277_G.js +0 -1
@@ -1 +1 @@
1
- import{r as R,j as r,$ as Se}from"./vendor-D2wC0h2o.js";import{u as Me}from"./query-DVc6ZTRQ.js";import{a as ke,c as Ce,q as te,e as Ue,i as W,d as V,B as F}from"./app-BBAnVEPg.js";import{g as Re}from"./gateway-B_xLF-Rk.js";import{u as q}from"./i18n-Dp-o1LhZ.js";import{c as K}from"./global-CJOj9WGx.js";import{D as ne}from"./disclosure-CJdf1-ap.js";import{L as C,I as U}from"./label-Da-JMxO2.js";import{S as Ie,a as Te,b as Ee,c as Ae,d as Y}from"./select-BTwqvh0l.js";import{S as Z}from"./switch-CeKtgMDT.js";import{B as _e}from"./badge-RZTsODn-.js";const br=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],vr=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function He(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function P(e,s){var a;return(a=e==null?void 0:e.customEndpoints)!=null&&a.length?e.customEndpoints:s}function ee(e){return e?Object.entries(e).map(([s,a])=>({id:He(),source:s,target:a})):[]}function yr(e,s){var i,d,c;if(!e)return{};const a={},m=e.endpointRouting??{};a.anthropic=ee(((i=m.anthropic)==null?void 0:i.modelRoutes)??e.modelRoutes??{}),a.openai=ee(((d=m.openai)==null?void 0:d.modelRoutes)??{});for(const h of P(e,s))(c=h.routing)!=null&&c.modelRoutes?a[h.id]=ee(h.routing.modelRoutes):a[h.id]=[];return a}function De(e,s,a){var d,c,h;const m=P(e,s).find(S=>S.id===a);if(m)return((d=m.routing)==null?void 0:d.modelRoutes)??{};const i=e.endpointRouting??{};return a==="anthropic"?((c=i.anthropic)==null?void 0:c.modelRoutes)??e.modelRoutes??{}:a==="openai"?((h=i.openai)==null?void 0:h.modelRoutes)??{}:{}}function re(e,s,a){var i,d,c;if(a==="anthropic"||a==="openai")return((d=(i=e.endpointRouting)==null?void 0:i[a])==null?void 0:d.defaults)??e.defaults;const m=P(e,s).find(h=>h.id===a);return((c=m==null?void 0:m.routing)==null?void 0:c.defaults)??{completion:null,reasoning:null,background:null,longContextThreshold:e.defaults.longContextThreshold}}function jr(e,s){if(!e)return{};const a={anthropic:re(e,s,"anthropic"),openai:re(e,s,"openai")};for(const m of P(e,s))a[m.id]=re(e,s,m.id);return a}function Le(e){const s={};for(const a of e){const m=a.source.trim(),i=a.target.trim();m&&i&&(s[m]=i)}return s}function Nr(e,s){return JSON.stringify(Le(e))!==JSON.stringify(s)}function wr(e,s,a){var i,d,c;if(!s)return;if(e==="anthropic"||e==="openai")return(d=(i=s.endpointRouting)==null?void 0:i[e])==null?void 0:d.compatibility;const m=P(s,a).find(h=>h.id===e);return(c=m==null?void 0:m.routing)==null?void 0:c.compatibility}function Sr(e,s){var m,i;const a={anthropic:((m=e.routingPresets)==null?void 0:m.anthropic)??[],openai:((i=e.routingPresets)==null?void 0:i.openai)??[]};for(const d of P(e,s))a[d.id]=d.routingPresets??[];return a}function Pe(e,s){const a=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],m=s.map(i=>{let d=e("modelManagement.tabs.customEndpoint"),c=[];if(i.paths&&i.paths.length>0)d=`${e("modelManagement.tabs.customEndpoint")}: ${i.paths.map(h=>`${h.path} (${h.protocol})`).join(", ")}`,c=[...new Set(i.paths.map(h=>h.protocol))];else if(i.path){const h=i.protocol||"anthropic";d=`${e("modelManagement.tabs.customEndpoint")}: ${i.path} (${h})`,c=[h]}return{key:i.id,label:i.label||i.id,description:d,isSystem:!1,canDelete:i.deletable!==!1,protocols:c}});return[...a,...m]}function Mr(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function Oe(e,s){if(!e)return!1;const[a]=e.split(":");return a===s||e===s}function We(e,s,a){if(!e)return[];const m=["anthropic","openai",...P(e,s).map(d=>d.id)],i=[];for(const d of m){const c=De(e,s,d);for(const[h,S]of Object.entries(c))Oe(S,a)&&i.push({endpoint:d,source:h,target:S})}return i}function kr(e,s,a){return We(e,s,a).length}function Cr(){var N;const{t:e}=q(),{pushToast:s}=ke(),a=Ce(te.config.full(),Re.configRequest()),m=Me({queryKey:te.customEndpoints.all(),queryFn:Ue.list,refetchInterval:1e4}),i=R.useMemo(()=>{var y;return((y=m.data)==null?void 0:y.endpoints)??[]},[(N=m.data)==null?void 0:N.endpoints]),d=R.useMemo(()=>Pe(e,i),[i,e]),[c,h]=R.useState(null);return R.useEffect(()=>{a.data&&h(a.data)},[a.data]),R.useEffect(()=>{!a.isError||!a.error||s({title:e("providers.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,e]),{t:e,pushToast:s,config:c,setConfig:h,configQuery:a,customEndpoints:i,customEndpointsQuery:m,tabs:d,ensureConfig:()=>c?!0:(s({title:e("settings.toast.missingConfig"),variant:"error"}),a.refetch(),!1)}}const Ur={savePreset(e,s){return W(V.post(`/api/routing-presets/${e}`,{name:s}))},applyPreset(e,s){return W(V.post(`/api/routing-presets/${e}/apply`,{name:s}))},deletePreset(e,s){return W(V.delete(`/api/routing-presets/${e}/${encodeURIComponent(s)}`))},testProvider(e,s){return W(V.post(`/api/providers/${e}/test`,s??{}))},probeModels(e,s){return W(V.post(`/api/providers/${e}/models/probe`,s?{provider:s}:{}))},backendsHealth(){return W(V.get("/api/providers/backends/health"))}},Ve={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Fe={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function Rr({steps:e,current:s,onSelect:a,className:m}){return r.jsx("nav",{"aria-label":"steps",className:K("flex items-start",m),children:e.map((i,d)=>{const c=a&&(i.status==="complete"||i.status==="current"),h=d===e.length-1,S=i.status==="complete"?"bg-primary/40":"bg-border",N=r.jsx("span",{className:K("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",Ve[i.status]),"aria-current":i.id===s?"step":void 0,children:i.status==="complete"?r.jsx(Se,{className:"h-3.5 w-3.5","aria-hidden":!0}):d+1}),y=`stepnav-${i.id}-label`;return r.jsxs("div",{className:"flex flex-1 items-start",children:[r.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[c?r.jsx("button",{type:"button",onClick:()=>a==null?void 0:a(i.id),"aria-labelledby":y,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,r.jsx("span",{id:y,className:K("text-center text-[11px] leading-tight",Fe[i.status]),children:i.label})]}),h?null:r.jsx("span",{"aria-hidden":!0,className:K("mx-1.5 mt-3.5 h-px flex-1",S)})]},i.id)})})}function Ke({result:e,className:s}){const{t:a}=q();return r.jsxs("div",{className:K("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",s),children:[r.jsx(_e,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?a("workbench.testResult.success"):a("workbench.testResult.failure")}),e.status?r.jsx("span",{className:"shrink-0",children:a("workbench.testResult.status",{status:e.status})}):null,e.durationMs?r.jsx("span",{className:"shrink-0",children:a("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?r.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function L(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ae(){return{_key:L(),id:"",label:"",members:[],failover:de()}}function $e(){return{_key:L(),target:""}}function de(){return{consecutiveFailures:"",cooldownSeconds:"",failureWindowSeconds:"",triggerStatusCodes:""}}function Be(e){var s;return{consecutiveFailures:(e==null?void 0:e.consecutiveFailures)!=null?String(e.consecutiveFailures):"",cooldownSeconds:(e==null?void 0:e.cooldownSeconds)!=null?String(e.cooldownSeconds):"",failureWindowSeconds:(e==null?void 0:e.failureWindowSeconds)!=null?String(e.failureWindowSeconds):"",triggerStatusCodes:((s=e==null?void 0:e.triggerStatusCodes)==null?void 0:s.join(", "))??""}}function ze(){return{_key:L(),name:"",value:""}}const G={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:{},aggregate:{}},le=[{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"},{value:"aggregate",label:"Aggregate"}];function qe(e,s){var a;return e==="aggregate"?s("providers.aggregate.typeLabel"):((a=le.find(m=>m.value===e))==null?void 0:a.label)??"Custom"}const Ir=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function Q(e){return e==="anthropic"?"authToken":"apiKey"}function Xe(e,s,a){return a(s==="authToken"?"providers.drawer.fields.authModeAuthToken":s==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function ie(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl??"",apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(s=>({...s,_key:L(),members:(s.members??[]).map(a=>({...a,_key:L()})),failover:Be(s.failover)})),authMode:e.authMode??Q(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,streamUsage:e.streamUsage===!0,rpmLimit:e.rpmLimit!=null?String(e.rpmLimit):"",rpmMaxWaitSeconds:e.rpmMaxWaitSeconds!=null?String(e.rpmMaxWaitSeconds):"",extraHeaders:Object.entries(e.extraHeaders??{}).map(([s,a])=>({name:s,value:a,_key:L()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:Q("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,streamUsage:!1,rpmLimit:"",rpmMaxWaitSeconds:"",extraHeaders:[]}}function Ge(e){return{_key:L(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream,members:[],failover:de()}}function Tr({form:e,errors:s,isCreate:a,advancedOpen:m,onAdvancedOpenChange:i,idInputRef:d,onProviderIdChange:c,onFieldChange:h,onTypeChange:S,onAuthModeChange:N,onNonStreamViaStreamChange:y,onUseAbsoluteUrlChange:T,onStreamUsageChange:g,onAddHeader:$,onRemoveHeader:w,onHeaderChange:I}){const{t:l}=q(),X=e.type==="aggregate";return r.jsxs("div",{className:"space-y-8",children:[r.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:l("providers.drawer.sections.type")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:l("providers.drawer.hints.type")})]}),r.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:le.map(b=>{var E;const A=b.value===e.type;return r.jsxs("button",{type:"button",onClick:()=>S(b.value),className:K("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",A?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[r.jsx("div",{className:"text-sm font-semibold",children:qe(b.value,l)}),r.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:b.value==="aggregate"?l("providers.aggregate.drawer.typeHint"):((E=G[b.value??"custom"])==null?void 0:E.baseUrl)??l("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),r.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:l("providers.drawer.sections.basic")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:l("providers.drawer.hints.basic")})]}),r.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.id")}),r.jsx(U,{value:e.id,ref:d,onChange:b=>c(b.target.value),disabled:!a,placeholder:l("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!s.id}),s.id?r.jsx("span",{className:"text-xs text-destructive",children:s.id}):null]}),r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.label")}),r.jsx(U,{value:e.label,onChange:b=>h("label")(b.target.value),placeholder:l("providers.drawer.fields.labelPlaceholder")})]})]}),X?r.jsxs("div",{className:"space-y-2 border border-border bg-card p-4",children:[r.jsx("p",{className:"text-sm font-semibold",children:l("providers.aggregate.drawer.explainerTitle")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.aggregate.drawer.explainerBody")})]}):r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.baseUrl")}),r.jsx(U,{value:e.baseUrl,onChange:b=>h("baseUrl")(b.target.value),placeholder:l("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!s.baseUrl}),s.baseUrl?r.jsx("span",{className:"text-xs text-destructive",children:s.baseUrl}):null]})]}),X?null:r.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:l("providers.drawer.sections.auth")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:l("providers.drawer.hints.auth")})]}),r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.apiKey")}),r.jsx(U,{value:e.apiKey,onChange:b=>h("apiKey")(b.target.value),placeholder:l("providers.drawer.fields.apiKeyPlaceholder")})]}),r.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[r.jsx("legend",{className:"px-1 text-muted-foreground",children:l("providers.drawer.fields.authMode")}),r.jsx("p",{className:"text-[11px] text-muted-foreground",children:l("providers.drawer.fields.authModeHint")}),r.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[r.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),r.jsx("span",{children:Xe(e.type,"apiKey",l)})]}),r.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[r.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),r.jsx("span",{children:l("providers.drawer.fields.authModeAuthToken")})]}),r.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[r.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),r.jsx("span",{children:l("providers.drawer.fields.authModeXAuthToken")})]})]}),r.jsxs(ne,{open:m,onOpenChange:i,summary:l("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.nonStreamViaStream")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.nonStreamViaStreamHint")})]}),r.jsx(Z,{checked:e.nonStreamViaStream,onCheckedChange:y,"aria-label":l("providers.drawer.fields.nonStreamViaStream")})]}),r.jsx("div",{className:"mt-4 border-t border-border pt-4",children:r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.useAbsoluteUrl")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.useAbsoluteUrlHint")})]}),r.jsx(Z,{checked:e.useAbsoluteUrl,onCheckedChange:T,"aria-label":l("providers.drawer.fields.useAbsoluteUrl")})]})}),r.jsx("div",{className:"mt-4 border-t border-border pt-4",children:r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.streamUsage")}),r.jsx("p",{className:"text-xs leading-relaxed text-warning",children:l("providers.drawer.fields.streamUsageHint")})]}),r.jsx(Z,{checked:e.streamUsage,onCheckedChange:g,"aria-label":l("providers.drawer.fields.streamUsage")})]})}),r.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.rpmLimitSection")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.rpmLimitHint")})]}),r.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.rpmLimit")}),r.jsx(U,{type:"number",min:1,value:e.rpmLimit,onChange:b=>h("rpmLimit")(b.target.value),placeholder:l("providers.drawer.fields.rpmLimitPlaceholder"),"aria-invalid":!!s.rpmLimit})]}),r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.rpmMaxWaitSeconds")}),r.jsx(U,{type:"number",min:1,max:3600,value:e.rpmMaxWaitSeconds,onChange:b=>h("rpmMaxWaitSeconds")(b.target.value),placeholder:l("providers.drawer.fields.rpmMaxWaitPlaceholder"),"aria-invalid":!!s.rpmMaxWaitSeconds})]})]}),s.rpmLimit?r.jsx("p",{className:"mt-2 text-xs text-destructive",children:s.rpmLimit}):null,s.rpmMaxWaitSeconds?r.jsx("p",{className:"mt-2 text-xs text-destructive",children:s.rpmMaxWaitSeconds}):null]}),r.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.extraHeaders")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.extraHeadersHint")})]}),r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:$,className:"bg-card text-xs",children:l("providers.drawer.fields.addHeader")})]}),s.extraHeaders?r.jsx("p",{className:"mt-2 text-xs text-destructive",children:s.extraHeaders}):null,e.extraHeaders.length>0?r.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,A)=>r.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[r.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.headerName")}),r.jsx(U,{value:b.name,onChange:E=>I(A,{name:E.target.value}),placeholder:l("providers.drawer.fields.headerNamePlaceholder")})]}),r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.headerValue")}),r.jsx(U,{value:b.value,onChange:E=>I(A,{value:E.target.value}),placeholder:l("providers.drawer.fields.headerValuePlaceholder")})]})]}),r.jsx("div",{className:"mt-2 flex justify-end",children:r.jsx(F,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>w(A),children:l("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function Er({form:e,errors:s,advancedOpen:a,onAdvancedOpenChange:m,onModelIdChange:i,onModelChange:d,onAddModel:c,onRemoveModel:h,onModelNonStreamViaStreamChange:S,onSetDefaultModel:N,testVerification:y,probeModels:T}){const{t:g}=q(),$=e.models.filter(w=>w.id.trim().length>0);return r.jsxs("div",{className:"space-y-8",children:[r.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:g("providers.drawer.fields.models")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:g("providers.drawer.modelsDescription")})]}),r.jsxs("div",{className:"flex shrink-0 gap-2",children:[T?r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:T.onProbe,disabled:!T.available,title:T.available?void 0:g("providers.drawer.probe.needsBaseUrl"),className:"bg-card text-xs",children:g("providers.drawer.probe.button")}):null,r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:c,className:"bg-card text-xs",children:g("providers.drawer.fields.addModel")})]})]}),s.models?r.jsx("p",{className:"text-xs text-destructive",children:s.models}):null,r.jsxs("div",{className:"space-y-4",children:[e.models.map((w,I)=>r.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[r.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:g("providers.drawer.fields.modelId")}),r.jsx(U,{value:w.id,onChange:l=>i(I,l.target.value),placeholder:g("providers.drawer.fields.modelIdPlaceholder")})]})}),r.jsxs(ne,{open:a,onOpenChange:m,summary:g("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:g("providers.drawer.fields.modelLabel")}),r.jsx(U,{value:w.label??"",onChange:l=>d(I,{label:l.target.value}),placeholder:g("providers.drawer.fields.modelLabelPlaceholder")})]}),r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:g("providers.drawer.fields.modelNonStreamViaStream")}),r.jsxs(Ie,{value:w.nonStreamViaStream===void 0?"inherit":w.nonStreamViaStream?"enabled":"disabled",onValueChange:l=>S(I,l),children:[r.jsx(Te,{children:r.jsx(Ee,{})}),r.jsxs(Ae,{children:[r.jsx(Y,{value:"inherit",children:g("providers.drawer.fields.modelNonStreamViaStreamInherit")}),r.jsx(Y,{value:"enabled",children:g("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),r.jsx(Y,{value:"disabled",children:g("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),r.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[r.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[r.jsx("input",{type:"radio",name:"defaultModel",value:w.id,"aria-label":g("providers.drawer.fields.setDefault"),checked:e.defaultModel===w.id,onChange:()=>N(w.id),disabled:w.id.trim().length===0,className:"h-4 w-4 accent-primary"}),g("providers.drawer.fields.setDefault")]}),r.jsx(F,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>h(I),disabled:e.models.length===0,children:g("providers.drawer.fields.removeModel")})]})]},w._key)),e.models.length===0?r.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-sm font-semibold text-warning",children:g("providers.drawer.noModelsTitle")}),r.jsx("p",{className:"text-xs leading-relaxed text-warning",children:g("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),r.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[r.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:g("providers.drawer.routeExample")}),r.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),$.length>1?r.jsx("div",{className:"text-xs text-muted-foreground",children:g("providers.drawer.defaultHint",{model:e.defaultModel||g("providers.card.noDefault")})}):null]}),y?r.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:g("workbench.drawer.verifyTitle")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:g("workbench.drawer.verifyHint")})]}),y.available?r.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:y.onTest,disabled:y.testing,children:y.testing?g("common.actions.testingConnection"):g("workbench.drawer.verifyRun")}),y.result?r.jsx(Ke,{result:y.result}):null]}):r.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:g("workbench.drawer.verifySaveFirst")})]}):null]})}const Qe=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,Je=1e6,Ye=3600,Ze=100,er=86400,rr=86400,sr=/^[^:\s]+:[^:\s]+$/;function tr(e){if(/^[1-5]xx$/.test(e))return!0;if(/^\d{3}$/.test(e)){const s=Number(e);return s>=100&&s<=599}return!1}function ar(e){const s={},a=Number(e.consecutiveFailures.trim());e.consecutiveFailures.trim()&&Number.isInteger(a)&&(s.consecutiveFailures=a);const m=Number(e.cooldownSeconds.trim());e.cooldownSeconds.trim()&&Number.isInteger(m)&&(s.cooldownSeconds=m);const i=Number(e.failureWindowSeconds.trim());e.failureWindowSeconds.trim()&&Number.isInteger(i)&&(s.failureWindowSeconds=i);const d=e.triggerStatusCodes.split(",").map(c=>c.trim()).filter(Boolean);return d.length>0&&(s.triggerStatusCodes=d),Object.keys(s).length>0?s:void 0}function Ar({mode:e,provider:s,existingProviderIds:a,providers:m}){const{t:i}=q(),[d,c]=R.useState(()=>ie(s)),[h,S]=R.useState({}),[N,y]=R.useState(e==="edit"),T=R.useRef(null),g=R.useCallback(()=>{c(ie(s)),S({}),y(e==="edit")},[s,e]),$=t=>n=>{c(u=>({...u,[t]:n}))},w=t=>{c(n=>{const o=!N||n.label.trim().length===0||n.label===n.id?t:n.label;return{...n,id:t,label:o}})},I=t=>{c(n=>{var _;const o=G[t??"custom"]??G.custom,f=Q(n.type),p=Q(t),v=Object.values(G).map(H=>H.baseUrl).filter(H=>!!H),j=!n.baseUrl||v.includes(n.baseUrl),x=e==="create"&&(n.models.length===0||n.models.every(H=>H.id.trim().length===0)),M={...n,type:t,authMode:n.authMode===f?p:n.authMode};return o!=null&&o.baseUrl&&j&&(M.baseUrl=o.baseUrl),o!=null&&o.models&&x&&(M.models=o.models.map(Ge),M.defaultModel=o.defaultModel??((_=o.models[0])==null?void 0:_.id)??""),M})},l=(t,n)=>{c(u=>{const o=[...u.models];return o[t]={...o[t],...n},{...u,models:o}})},X=(t,n)=>{c(u=>{const o=[...u.models],f=o[t];if(!f)return u;const p=!N||!f.label||f.label===f.id,v={...f,id:n,label:p?n:f.label};o[t]=v;const j=u.defaultModel===f.id?n:u.defaultModel;return{...u,models:o,defaultModel:j}})},b=t=>{c(n=>{if(t<0||t>=n.models.length)return n;const u=n.models.filter((f,p)=>p!==t);let o=n.defaultModel;return u.some(f=>f.id===o)||(o=""),{...n,models:u,defaultModel:o}})},A=()=>{c(t=>({...t,models:[...t.models,ae()]}))},E=t=>{c(n=>{const u=new Set(n.models.map(f=>f.id.trim())),o=t.filter(f=>f.id.trim().length>0&&!u.has(f.id.trim())).map(f=>{var p;return{...ae(),id:f.id.trim(),label:((p=f.label)==null?void 0:p.trim())??""}});return o.length===0?n:{...n,models:[...n.models,...o]}})},oe=(t,n)=>{c(u=>{const o=[...u.extraHeaders];return o[t]={...o[t],...n},{...u,extraHeaders:o}})},ce=()=>{c(t=>({...t,extraHeaders:[...t.extraHeaders,ze()]}))},me=t=>{c(n=>{if(t<0||t>=n.extraHeaders.length)return n;const u=n.extraHeaders.filter((o,f)=>f!==t);return{...n,extraHeaders:u}})},ue=t=>{c(n=>({...n,authMode:t}))},pe=t=>{c(n=>({...n,nonStreamViaStream:t}))},xe=t=>{c(n=>({...n,useAbsoluteUrl:t}))},he=t=>{c(n=>({...n,streamUsage:t}))},fe=(t,n)=>{l(t,{nonStreamViaStream:n==="inherit"?void 0:n==="enabled"})},ge=t=>{c(n=>({...n,defaultModel:t}))},B=(t,n)=>{c(u=>({...u,models:u.models.map(o=>o._key===t?n(o):o)}))},be=t=>{B(t,n=>({...n,members:[...n.members,$e()]}))},ve=(t,n)=>{B(t,u=>({...u,members:u.members.filter(o=>o._key!==n)}))},ye=(t,n,u)=>{B(t,o=>({...o,members:o.members.map(f=>f._key===n?{...f,target:u}:f)}))},je=(t,n,u)=>{n!==u&&B(t,o=>{const f=o.members.findIndex(x=>x._key===n),p=o.members.findIndex(x=>x._key===u);if(f<0||p<0)return o;const v=[...o.members],[j]=v.splice(f,1);return v.splice(p,0,j),{...o,members:v}})},Ne=(t,n)=>{B(t,u=>({...u,failover:{...u.failover,...n}}))},se=()=>{const t={},n=d.id.trim(),u=d.baseUrl.trim();if(e==="create"&&(n.length===0?t.id=i("providers.drawer.errors.idRequired"):a.includes(n)&&(t.id=i("providers.drawer.errors.idDuplicate"))),e==="edit"&&n.length===0&&(t.id=i("providers.drawer.errors.idRequired")),d.type!=="aggregate")if(u.length===0)t.baseUrl=i("providers.drawer.errors.baseUrlInvalid");else try{new URL(u)}catch{t.baseUrl=i("providers.drawer.errors.baseUrlInvalid")}if(d.type==="aggregate"){d.models.length===0&&(t.models=i("providers.drawer.errors.modelsRequired"));const p={},v={},j=new Map((m??[]).map(x=>[x.id,x]));for(const x of d.models){const M=x.members.map(k=>k.target.trim()).filter(k=>k.length>0);if(M.length===0)p[x._key]=i("providers.aggregate.errors.memberRequired");else{const k=new Set;for(const D of M){if(!sr.test(D)){p[x._key]=i("providers.aggregate.errors.memberInvalid");break}const[O]=D.split(":");if(m){const z=j.get(O);if(!z){p[x._key]=i("providers.aggregate.errors.memberDangling",{provider:O});break}if(z.type==="aggregate"||O===d.id.trim()){p[x._key]=i("providers.aggregate.errors.memberNested",{provider:O});break}}if(k.has(D)){p[x._key]=i("providers.aggregate.errors.memberDuplicate",{target:D});break}k.add(D)}}const H=[[x.failover.consecutiveFailures,1,Ze],[x.failover.cooldownSeconds,1,er],[x.failover.failureWindowSeconds,1,rr]].some(([k,D,O])=>{const z=k.trim();if(!z)return!1;const J=Number(z);return!Number.isInteger(J)||J<D||J>O}),we=x.failover.triggerStatusCodes.split(",").map(k=>k.trim()).filter(Boolean);H?v[x._key]=i("providers.aggregate.errors.failoverInvalid"):we.some(k=>!tr(k))&&(v[x._key]=i("providers.aggregate.errors.triggerCodesInvalid"))}Object.keys(p).length>0&&(t.members=p),Object.keys(v).length>0&&(t.failover=v)}if(d.models.length>0){const p=new Set;d.models.some(j=>{const x=j.id.trim();return x.length===0||p.has(x)?!0:(p.add(x),!1)})&&(t.models=i("providers.drawer.errors.modelInvalid"))}d.defaultModel&&!d.models.some(p=>p.id===d.defaultModel)&&(t.models=i("providers.drawer.errors.defaultInvalid"));const o=d.rpmLimit.trim();if(o.length>0){const p=Number(o);(!Number.isInteger(p)||p<1||p>Je)&&(t.rpmLimit=i("providers.drawer.errors.rpmLimitInvalid"))}const f=d.rpmMaxWaitSeconds.trim();if(f.length>0){const p=Number(f);(!Number.isInteger(p)||p<1||p>Ye)&&(t.rpmMaxWaitSeconds=i("providers.drawer.errors.rpmMaxWaitInvalid"))}if(d.extraHeaders.length>0){const p=new Set;for(const v of d.extraHeaders){const j=v.name.trim();if(j.length===0)continue;if(!Qe.test(j)){t.extraHeaders=i("providers.drawer.errors.headerNameInvalid");break}const x=j.toLowerCase();if(p.has(x)){t.extraHeaders=i("providers.drawer.errors.headerNameDuplicate");break}p.add(x)}}return S(t),t};return{form:d,errors:h,advancedOpen:N,setAdvancedOpen:y,providerIdRef:T,isCreate:e==="create",resetForm:g,validate:()=>Object.keys(se()).length===0,validateErrors:se,serialize:()=>{const t=d.type==="aggregate",n=d.models.map(x=>{var M;return{id:x.id.trim(),label:(M=x.label)!=null&&M.trim()?x.label.trim():void 0,nonStreamViaStream:x.nonStreamViaStream,...t?{members:x.members.map(_=>({target:_.target.trim()})).filter(_=>_.target.length>0),failover:ar(x.failover)}:null}}).filter(x=>x.id.length>0),u={};for(const x of d.extraHeaders){const M=x.name.trim();M.length>0&&(u[M]=x.value)}const o=Object.keys(u).length>0,f=d.authMode==="apiKey"&&d.type!=="anthropic"?void 0:d.authMode,p={id:d.id.trim(),label:d.label.trim()||d.id.trim(),baseUrl:t?void 0:d.baseUrl.trim(),apiKey:t?void 0:d.apiKey.trim()||void 0,type:d.type??"custom",defaultModel:t?void 0:d.defaultModel||void 0,models:n.length>0?n:void 0,extraHeaders:t?void 0:o?u:void 0,authMode:t?void 0:f};d.nonStreamViaStream&&(p.nonStreamViaStream=!0),d.useAbsoluteUrl&&(p.useAbsoluteUrl=!0),d.streamUsage&&(p.streamUsage=!0);const v=Number(d.rpmLimit.trim());d.rpmLimit.trim().length>0&&Number.isInteger(v)&&v>=1&&(p.rpmLimit=v);const j=Number(d.rpmMaxWaitSeconds.trim());return d.rpmMaxWaitSeconds.trim().length>0&&Number.isInteger(j)&&j>=1&&(p.rpmMaxWaitSeconds=j),p},handleFieldChange:$,handleProviderIdChange:w,handleTypeChange:I,handleModelChange:l,handleModelIdChange:X,handleRemoveModel:b,handleAddModel:A,handleImportModels:E,handleHeaderChange:oe,handleAddHeader:ce,handleRemoveHeader:me,handleAuthModeChange:ue,handleProviderNonStreamViaStreamChange:pe,handleUseAbsoluteUrlChange:xe,handleStreamUsageChange:he,handleModelNonStreamViaStreamChange:fe,handleSetDefaultModel:ge,handleAddMember:be,handleRemoveMember:ve,handleMemberTargetChange:ye,handleReorderMembers:je,handleModelFailoverChange:Ne}}export{Tr as B,br as C,Er as M,vr as O,Ir as P,Rr as S,Ke as T,Nr as a,jr as b,re as c,yr as d,Sr as e,He as f,De as g,Mr as h,Xe as i,le as j,We as k,wr as l,Ur as m,Cr as n,kr as o,qe as p,Oe as r,Ar as u};
1
+ import{r as R,j as r,$ as Se}from"./vendor-D2wC0h2o.js";import{u as Me}from"./query-DVc6ZTRQ.js";import{a as ke,c as Ce,q as te,e as Ue,i as W,d as V,B as F}from"./app-BnQl39hq.js";import{g as Re}from"./gateway-DxCj_uok.js";import{u as q}from"./i18n-Dp-o1LhZ.js";import{c as K}from"./global-CJOj9WGx.js";import{D as ne}from"./disclosure-CJdf1-ap.js";import{L as C,I as U}from"./label-Da-JMxO2.js";import{S as Ie,a as Te,b as Ee,c as Ae,d as Y}from"./select-BTwqvh0l.js";import{S as Z}from"./switch-CeKtgMDT.js";import{B as _e}from"./badge-RZTsODn-.js";const br=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],vr=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function He(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function P(e,s){var a;return(a=e==null?void 0:e.customEndpoints)!=null&&a.length?e.customEndpoints:s}function ee(e){return e?Object.entries(e).map(([s,a])=>({id:He(),source:s,target:a})):[]}function yr(e,s){var i,d,c;if(!e)return{};const a={},m=e.endpointRouting??{};a.anthropic=ee(((i=m.anthropic)==null?void 0:i.modelRoutes)??e.modelRoutes??{}),a.openai=ee(((d=m.openai)==null?void 0:d.modelRoutes)??{});for(const h of P(e,s))(c=h.routing)!=null&&c.modelRoutes?a[h.id]=ee(h.routing.modelRoutes):a[h.id]=[];return a}function De(e,s,a){var d,c,h;const m=P(e,s).find(S=>S.id===a);if(m)return((d=m.routing)==null?void 0:d.modelRoutes)??{};const i=e.endpointRouting??{};return a==="anthropic"?((c=i.anthropic)==null?void 0:c.modelRoutes)??e.modelRoutes??{}:a==="openai"?((h=i.openai)==null?void 0:h.modelRoutes)??{}:{}}function re(e,s,a){var i,d,c;if(a==="anthropic"||a==="openai")return((d=(i=e.endpointRouting)==null?void 0:i[a])==null?void 0:d.defaults)??e.defaults;const m=P(e,s).find(h=>h.id===a);return((c=m==null?void 0:m.routing)==null?void 0:c.defaults)??{completion:null,reasoning:null,background:null,longContextThreshold:e.defaults.longContextThreshold}}function jr(e,s){if(!e)return{};const a={anthropic:re(e,s,"anthropic"),openai:re(e,s,"openai")};for(const m of P(e,s))a[m.id]=re(e,s,m.id);return a}function Le(e){const s={};for(const a of e){const m=a.source.trim(),i=a.target.trim();m&&i&&(s[m]=i)}return s}function Nr(e,s){return JSON.stringify(Le(e))!==JSON.stringify(s)}function wr(e,s,a){var i,d,c;if(!s)return;if(e==="anthropic"||e==="openai")return(d=(i=s.endpointRouting)==null?void 0:i[e])==null?void 0:d.compatibility;const m=P(s,a).find(h=>h.id===e);return(c=m==null?void 0:m.routing)==null?void 0:c.compatibility}function Sr(e,s){var m,i;const a={anthropic:((m=e.routingPresets)==null?void 0:m.anthropic)??[],openai:((i=e.routingPresets)==null?void 0:i.openai)??[]};for(const d of P(e,s))a[d.id]=d.routingPresets??[];return a}function Pe(e,s){const a=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],m=s.map(i=>{let d=e("modelManagement.tabs.customEndpoint"),c=[];if(i.paths&&i.paths.length>0)d=`${e("modelManagement.tabs.customEndpoint")}: ${i.paths.map(h=>`${h.path} (${h.protocol})`).join(", ")}`,c=[...new Set(i.paths.map(h=>h.protocol))];else if(i.path){const h=i.protocol||"anthropic";d=`${e("modelManagement.tabs.customEndpoint")}: ${i.path} (${h})`,c=[h]}return{key:i.id,label:i.label||i.id,description:d,isSystem:!1,canDelete:i.deletable!==!1,protocols:c}});return[...a,...m]}function Mr(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function Oe(e,s){if(!e)return!1;const[a]=e.split(":");return a===s||e===s}function We(e,s,a){if(!e)return[];const m=["anthropic","openai",...P(e,s).map(d=>d.id)],i=[];for(const d of m){const c=De(e,s,d);for(const[h,S]of Object.entries(c))Oe(S,a)&&i.push({endpoint:d,source:h,target:S})}return i}function kr(e,s,a){return We(e,s,a).length}function Cr(){var N;const{t:e}=q(),{pushToast:s}=ke(),a=Ce(te.config.full(),Re.configRequest()),m=Me({queryKey:te.customEndpoints.all(),queryFn:Ue.list,refetchInterval:1e4}),i=R.useMemo(()=>{var y;return((y=m.data)==null?void 0:y.endpoints)??[]},[(N=m.data)==null?void 0:N.endpoints]),d=R.useMemo(()=>Pe(e,i),[i,e]),[c,h]=R.useState(null);return R.useEffect(()=>{a.data&&h(a.data)},[a.data]),R.useEffect(()=>{!a.isError||!a.error||s({title:e("providers.toast.loadFailure",{message:a.error.message}),variant:"error"})},[a.error,a.isError,s,e]),{t:e,pushToast:s,config:c,setConfig:h,configQuery:a,customEndpoints:i,customEndpointsQuery:m,tabs:d,ensureConfig:()=>c?!0:(s({title:e("settings.toast.missingConfig"),variant:"error"}),a.refetch(),!1)}}const Ur={savePreset(e,s){return W(V.post(`/api/routing-presets/${e}`,{name:s}))},applyPreset(e,s){return W(V.post(`/api/routing-presets/${e}/apply`,{name:s}))},deletePreset(e,s){return W(V.delete(`/api/routing-presets/${e}/${encodeURIComponent(s)}`))},testProvider(e,s){return W(V.post(`/api/providers/${e}/test`,s??{}))},probeModels(e,s){return W(V.post(`/api/providers/${e}/models/probe`,s?{provider:s}:{}))},backendsHealth(){return W(V.get("/api/providers/backends/health"))}},Ve={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Fe={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function Rr({steps:e,current:s,onSelect:a,className:m}){return r.jsx("nav",{"aria-label":"steps",className:K("flex items-start",m),children:e.map((i,d)=>{const c=a&&(i.status==="complete"||i.status==="current"),h=d===e.length-1,S=i.status==="complete"?"bg-primary/40":"bg-border",N=r.jsx("span",{className:K("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",Ve[i.status]),"aria-current":i.id===s?"step":void 0,children:i.status==="complete"?r.jsx(Se,{className:"h-3.5 w-3.5","aria-hidden":!0}):d+1}),y=`stepnav-${i.id}-label`;return r.jsxs("div",{className:"flex flex-1 items-start",children:[r.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[c?r.jsx("button",{type:"button",onClick:()=>a==null?void 0:a(i.id),"aria-labelledby":y,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,r.jsx("span",{id:y,className:K("text-center text-[11px] leading-tight",Fe[i.status]),children:i.label})]}),h?null:r.jsx("span",{"aria-hidden":!0,className:K("mx-1.5 mt-3.5 h-px flex-1",S)})]},i.id)})})}function Ke({result:e,className:s}){const{t:a}=q();return r.jsxs("div",{className:K("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",s),children:[r.jsx(_e,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?a("workbench.testResult.success"):a("workbench.testResult.failure")}),e.status?r.jsx("span",{className:"shrink-0",children:a("workbench.testResult.status",{status:e.status})}):null,e.durationMs?r.jsx("span",{className:"shrink-0",children:a("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?r.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function L(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ae(){return{_key:L(),id:"",label:"",members:[],failover:de()}}function $e(){return{_key:L(),target:""}}function de(){return{consecutiveFailures:"",cooldownSeconds:"",failureWindowSeconds:"",triggerStatusCodes:""}}function Be(e){var s;return{consecutiveFailures:(e==null?void 0:e.consecutiveFailures)!=null?String(e.consecutiveFailures):"",cooldownSeconds:(e==null?void 0:e.cooldownSeconds)!=null?String(e.cooldownSeconds):"",failureWindowSeconds:(e==null?void 0:e.failureWindowSeconds)!=null?String(e.failureWindowSeconds):"",triggerStatusCodes:((s=e==null?void 0:e.triggerStatusCodes)==null?void 0:s.join(", "))??""}}function ze(){return{_key:L(),name:"",value:""}}const G={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:{},aggregate:{}},le=[{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"},{value:"aggregate",label:"Aggregate"}];function qe(e,s){var a;return e==="aggregate"?s("providers.aggregate.typeLabel"):((a=le.find(m=>m.value===e))==null?void 0:a.label)??"Custom"}const Ir=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function Q(e){return e==="anthropic"?"authToken":"apiKey"}function Xe(e,s,a){return a(s==="authToken"?"providers.drawer.fields.authModeAuthToken":s==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function ie(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl??"",apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(s=>({...s,_key:L(),members:(s.members??[]).map(a=>({...a,_key:L()})),failover:Be(s.failover)})),authMode:e.authMode??Q(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,streamUsage:e.streamUsage===!0,rpmLimit:e.rpmLimit!=null?String(e.rpmLimit):"",rpmMaxWaitSeconds:e.rpmMaxWaitSeconds!=null?String(e.rpmMaxWaitSeconds):"",extraHeaders:Object.entries(e.extraHeaders??{}).map(([s,a])=>({name:s,value:a,_key:L()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:Q("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,streamUsage:!1,rpmLimit:"",rpmMaxWaitSeconds:"",extraHeaders:[]}}function Ge(e){return{_key:L(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream,members:[],failover:de()}}function Tr({form:e,errors:s,isCreate:a,advancedOpen:m,onAdvancedOpenChange:i,idInputRef:d,onProviderIdChange:c,onFieldChange:h,onTypeChange:S,onAuthModeChange:N,onNonStreamViaStreamChange:y,onUseAbsoluteUrlChange:T,onStreamUsageChange:g,onAddHeader:$,onRemoveHeader:w,onHeaderChange:I}){const{t:l}=q(),X=e.type==="aggregate";return r.jsxs("div",{className:"space-y-8",children:[r.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:l("providers.drawer.sections.type")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:l("providers.drawer.hints.type")})]}),r.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:le.map(b=>{var E;const A=b.value===e.type;return r.jsxs("button",{type:"button",onClick:()=>S(b.value),className:K("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",A?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[r.jsx("div",{className:"text-sm font-semibold",children:qe(b.value,l)}),r.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:b.value==="aggregate"?l("providers.aggregate.drawer.typeHint"):((E=G[b.value??"custom"])==null?void 0:E.baseUrl)??l("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),r.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:l("providers.drawer.sections.basic")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:l("providers.drawer.hints.basic")})]}),r.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.id")}),r.jsx(U,{value:e.id,ref:d,onChange:b=>c(b.target.value),disabled:!a,placeholder:l("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!s.id}),s.id?r.jsx("span",{className:"text-xs text-destructive",children:s.id}):null]}),r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.label")}),r.jsx(U,{value:e.label,onChange:b=>h("label")(b.target.value),placeholder:l("providers.drawer.fields.labelPlaceholder")})]})]}),X?r.jsxs("div",{className:"space-y-2 border border-border bg-card p-4",children:[r.jsx("p",{className:"text-sm font-semibold",children:l("providers.aggregate.drawer.explainerTitle")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.aggregate.drawer.explainerBody")})]}):r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.baseUrl")}),r.jsx(U,{value:e.baseUrl,onChange:b=>h("baseUrl")(b.target.value),placeholder:l("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!s.baseUrl}),s.baseUrl?r.jsx("span",{className:"text-xs text-destructive",children:s.baseUrl}):null]})]}),X?null:r.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:l("providers.drawer.sections.auth")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:l("providers.drawer.hints.auth")})]}),r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.apiKey")}),r.jsx(U,{value:e.apiKey,onChange:b=>h("apiKey")(b.target.value),placeholder:l("providers.drawer.fields.apiKeyPlaceholder")})]}),r.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[r.jsx("legend",{className:"px-1 text-muted-foreground",children:l("providers.drawer.fields.authMode")}),r.jsx("p",{className:"text-[11px] text-muted-foreground",children:l("providers.drawer.fields.authModeHint")}),r.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[r.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),r.jsx("span",{children:Xe(e.type,"apiKey",l)})]}),r.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[r.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),r.jsx("span",{children:l("providers.drawer.fields.authModeAuthToken")})]}),r.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[r.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),r.jsx("span",{children:l("providers.drawer.fields.authModeXAuthToken")})]})]}),r.jsxs(ne,{open:m,onOpenChange:i,summary:l("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.nonStreamViaStream")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.nonStreamViaStreamHint")})]}),r.jsx(Z,{checked:e.nonStreamViaStream,onCheckedChange:y,"aria-label":l("providers.drawer.fields.nonStreamViaStream")})]}),r.jsx("div",{className:"mt-4 border-t border-border pt-4",children:r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.useAbsoluteUrl")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.useAbsoluteUrlHint")})]}),r.jsx(Z,{checked:e.useAbsoluteUrl,onCheckedChange:T,"aria-label":l("providers.drawer.fields.useAbsoluteUrl")})]})}),r.jsx("div",{className:"mt-4 border-t border-border pt-4",children:r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.streamUsage")}),r.jsx("p",{className:"text-xs leading-relaxed text-warning",children:l("providers.drawer.fields.streamUsageHint")})]}),r.jsx(Z,{checked:e.streamUsage,onCheckedChange:g,"aria-label":l("providers.drawer.fields.streamUsage")})]})}),r.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.rpmLimitSection")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.rpmLimitHint")})]}),r.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2",children:[r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.rpmLimit")}),r.jsx(U,{type:"number",min:1,value:e.rpmLimit,onChange:b=>h("rpmLimit")(b.target.value),placeholder:l("providers.drawer.fields.rpmLimitPlaceholder"),"aria-invalid":!!s.rpmLimit})]}),r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.rpmMaxWaitSeconds")}),r.jsx(U,{type:"number",min:1,max:3600,value:e.rpmMaxWaitSeconds,onChange:b=>h("rpmMaxWaitSeconds")(b.target.value),placeholder:l("providers.drawer.fields.rpmMaxWaitPlaceholder"),"aria-invalid":!!s.rpmMaxWaitSeconds})]})]}),s.rpmLimit?r.jsx("p",{className:"mt-2 text-xs text-destructive",children:s.rpmLimit}):null,s.rpmMaxWaitSeconds?r.jsx("p",{className:"mt-2 text-xs text-destructive",children:s.rpmMaxWaitSeconds}):null]}),r.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:l("providers.drawer.fields.extraHeaders")}),r.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:l("providers.drawer.fields.extraHeadersHint")})]}),r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:$,className:"bg-card text-xs",children:l("providers.drawer.fields.addHeader")})]}),s.extraHeaders?r.jsx("p",{className:"mt-2 text-xs text-destructive",children:s.extraHeaders}):null,e.extraHeaders.length>0?r.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,A)=>r.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[r.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.headerName")}),r.jsx(U,{value:b.name,onChange:E=>I(A,{name:E.target.value}),placeholder:l("providers.drawer.fields.headerNamePlaceholder")})]}),r.jsxs(C,{className:"flex flex-col gap-1.5 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:l("providers.drawer.fields.headerValue")}),r.jsx(U,{value:b.value,onChange:E=>I(A,{value:E.target.value}),placeholder:l("providers.drawer.fields.headerValuePlaceholder")})]})]}),r.jsx("div",{className:"mt-2 flex justify-end",children:r.jsx(F,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>w(A),children:l("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function Er({form:e,errors:s,advancedOpen:a,onAdvancedOpenChange:m,onModelIdChange:i,onModelChange:d,onAddModel:c,onRemoveModel:h,onModelNonStreamViaStreamChange:S,onSetDefaultModel:N,testVerification:y,probeModels:T}){const{t:g}=q(),$=e.models.filter(w=>w.id.trim().length>0);return r.jsxs("div",{className:"space-y-8",children:[r.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:g("providers.drawer.fields.models")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:g("providers.drawer.modelsDescription")})]}),r.jsxs("div",{className:"flex shrink-0 gap-2",children:[T?r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:T.onProbe,disabled:!T.available,title:T.available?void 0:g("providers.drawer.probe.needsBaseUrl"),className:"bg-card text-xs",children:g("providers.drawer.probe.button")}):null,r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:c,className:"bg-card text-xs",children:g("providers.drawer.fields.addModel")})]})]}),s.models?r.jsx("p",{className:"text-xs text-destructive",children:s.models}):null,r.jsxs("div",{className:"space-y-4",children:[e.models.map((w,I)=>r.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[r.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:g("providers.drawer.fields.modelId")}),r.jsx(U,{value:w.id,onChange:l=>i(I,l.target.value),placeholder:g("providers.drawer.fields.modelIdPlaceholder")})]})}),r.jsxs(ne,{open:a,onOpenChange:m,summary:g("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:g("providers.drawer.fields.modelLabel")}),r.jsx(U,{value:w.label??"",onChange:l=>d(I,{label:l.target.value}),placeholder:g("providers.drawer.fields.modelLabelPlaceholder")})]}),r.jsxs(C,{className:"flex flex-col gap-2 text-sm",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:g("providers.drawer.fields.modelNonStreamViaStream")}),r.jsxs(Ie,{value:w.nonStreamViaStream===void 0?"inherit":w.nonStreamViaStream?"enabled":"disabled",onValueChange:l=>S(I,l),children:[r.jsx(Te,{children:r.jsx(Ee,{})}),r.jsxs(Ae,{children:[r.jsx(Y,{value:"inherit",children:g("providers.drawer.fields.modelNonStreamViaStreamInherit")}),r.jsx(Y,{value:"enabled",children:g("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),r.jsx(Y,{value:"disabled",children:g("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),r.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[r.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[r.jsx("input",{type:"radio",name:"defaultModel",value:w.id,"aria-label":g("providers.drawer.fields.setDefault"),checked:e.defaultModel===w.id,onChange:()=>N(w.id),disabled:w.id.trim().length===0,className:"h-4 w-4 accent-primary"}),g("providers.drawer.fields.setDefault")]}),r.jsx(F,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>h(I),disabled:e.models.length===0,children:g("providers.drawer.fields.removeModel")})]})]},w._key)),e.models.length===0?r.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-sm font-semibold text-warning",children:g("providers.drawer.noModelsTitle")}),r.jsx("p",{className:"text-xs leading-relaxed text-warning",children:g("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),r.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[r.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:g("providers.drawer.routeExample")}),r.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),$.length>1?r.jsx("div",{className:"text-xs text-muted-foreground",children:g("providers.drawer.defaultHint",{model:e.defaultModel||g("providers.card.noDefault")})}):null]}),y?r.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[r.jsxs("div",{className:"space-y-1",children:[r.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:g("workbench.drawer.verifyTitle")}),r.jsx("p",{className:"text-xs text-muted-foreground",children:g("workbench.drawer.verifyHint")})]}),y.available?r.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[r.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:y.onTest,disabled:y.testing,children:y.testing?g("common.actions.testingConnection"):g("workbench.drawer.verifyRun")}),y.result?r.jsx(Ke,{result:y.result}):null]}):r.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:g("workbench.drawer.verifySaveFirst")})]}):null]})}const Qe=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,Je=1e6,Ye=3600,Ze=100,er=86400,rr=86400,sr=/^[^:\s]+:[^:\s]+$/;function tr(e){if(/^[1-5]xx$/.test(e))return!0;if(/^\d{3}$/.test(e)){const s=Number(e);return s>=100&&s<=599}return!1}function ar(e){const s={},a=Number(e.consecutiveFailures.trim());e.consecutiveFailures.trim()&&Number.isInteger(a)&&(s.consecutiveFailures=a);const m=Number(e.cooldownSeconds.trim());e.cooldownSeconds.trim()&&Number.isInteger(m)&&(s.cooldownSeconds=m);const i=Number(e.failureWindowSeconds.trim());e.failureWindowSeconds.trim()&&Number.isInteger(i)&&(s.failureWindowSeconds=i);const d=e.triggerStatusCodes.split(",").map(c=>c.trim()).filter(Boolean);return d.length>0&&(s.triggerStatusCodes=d),Object.keys(s).length>0?s:void 0}function Ar({mode:e,provider:s,existingProviderIds:a,providers:m}){const{t:i}=q(),[d,c]=R.useState(()=>ie(s)),[h,S]=R.useState({}),[N,y]=R.useState(e==="edit"),T=R.useRef(null),g=R.useCallback(()=>{c(ie(s)),S({}),y(e==="edit")},[s,e]),$=t=>n=>{c(u=>({...u,[t]:n}))},w=t=>{c(n=>{const o=!N||n.label.trim().length===0||n.label===n.id?t:n.label;return{...n,id:t,label:o}})},I=t=>{c(n=>{var _;const o=G[t??"custom"]??G.custom,f=Q(n.type),p=Q(t),v=Object.values(G).map(H=>H.baseUrl).filter(H=>!!H),j=!n.baseUrl||v.includes(n.baseUrl),x=e==="create"&&(n.models.length===0||n.models.every(H=>H.id.trim().length===0)),M={...n,type:t,authMode:n.authMode===f?p:n.authMode};return o!=null&&o.baseUrl&&j&&(M.baseUrl=o.baseUrl),o!=null&&o.models&&x&&(M.models=o.models.map(Ge),M.defaultModel=o.defaultModel??((_=o.models[0])==null?void 0:_.id)??""),M})},l=(t,n)=>{c(u=>{const o=[...u.models];return o[t]={...o[t],...n},{...u,models:o}})},X=(t,n)=>{c(u=>{const o=[...u.models],f=o[t];if(!f)return u;const p=!N||!f.label||f.label===f.id,v={...f,id:n,label:p?n:f.label};o[t]=v;const j=u.defaultModel===f.id?n:u.defaultModel;return{...u,models:o,defaultModel:j}})},b=t=>{c(n=>{if(t<0||t>=n.models.length)return n;const u=n.models.filter((f,p)=>p!==t);let o=n.defaultModel;return u.some(f=>f.id===o)||(o=""),{...n,models:u,defaultModel:o}})},A=()=>{c(t=>({...t,models:[...t.models,ae()]}))},E=t=>{c(n=>{const u=new Set(n.models.map(f=>f.id.trim())),o=t.filter(f=>f.id.trim().length>0&&!u.has(f.id.trim())).map(f=>{var p;return{...ae(),id:f.id.trim(),label:((p=f.label)==null?void 0:p.trim())??""}});return o.length===0?n:{...n,models:[...n.models,...o]}})},oe=(t,n)=>{c(u=>{const o=[...u.extraHeaders];return o[t]={...o[t],...n},{...u,extraHeaders:o}})},ce=()=>{c(t=>({...t,extraHeaders:[...t.extraHeaders,ze()]}))},me=t=>{c(n=>{if(t<0||t>=n.extraHeaders.length)return n;const u=n.extraHeaders.filter((o,f)=>f!==t);return{...n,extraHeaders:u}})},ue=t=>{c(n=>({...n,authMode:t}))},pe=t=>{c(n=>({...n,nonStreamViaStream:t}))},xe=t=>{c(n=>({...n,useAbsoluteUrl:t}))},he=t=>{c(n=>({...n,streamUsage:t}))},fe=(t,n)=>{l(t,{nonStreamViaStream:n==="inherit"?void 0:n==="enabled"})},ge=t=>{c(n=>({...n,defaultModel:t}))},B=(t,n)=>{c(u=>({...u,models:u.models.map(o=>o._key===t?n(o):o)}))},be=t=>{B(t,n=>({...n,members:[...n.members,$e()]}))},ve=(t,n)=>{B(t,u=>({...u,members:u.members.filter(o=>o._key!==n)}))},ye=(t,n,u)=>{B(t,o=>({...o,members:o.members.map(f=>f._key===n?{...f,target:u}:f)}))},je=(t,n,u)=>{n!==u&&B(t,o=>{const f=o.members.findIndex(x=>x._key===n),p=o.members.findIndex(x=>x._key===u);if(f<0||p<0)return o;const v=[...o.members],[j]=v.splice(f,1);return v.splice(p,0,j),{...o,members:v}})},Ne=(t,n)=>{B(t,u=>({...u,failover:{...u.failover,...n}}))},se=()=>{const t={},n=d.id.trim(),u=d.baseUrl.trim();if(e==="create"&&(n.length===0?t.id=i("providers.drawer.errors.idRequired"):a.includes(n)&&(t.id=i("providers.drawer.errors.idDuplicate"))),e==="edit"&&n.length===0&&(t.id=i("providers.drawer.errors.idRequired")),d.type!=="aggregate")if(u.length===0)t.baseUrl=i("providers.drawer.errors.baseUrlInvalid");else try{new URL(u)}catch{t.baseUrl=i("providers.drawer.errors.baseUrlInvalid")}if(d.type==="aggregate"){d.models.length===0&&(t.models=i("providers.drawer.errors.modelsRequired"));const p={},v={},j=new Map((m??[]).map(x=>[x.id,x]));for(const x of d.models){const M=x.members.map(k=>k.target.trim()).filter(k=>k.length>0);if(M.length===0)p[x._key]=i("providers.aggregate.errors.memberRequired");else{const k=new Set;for(const D of M){if(!sr.test(D)){p[x._key]=i("providers.aggregate.errors.memberInvalid");break}const[O]=D.split(":");if(m){const z=j.get(O);if(!z){p[x._key]=i("providers.aggregate.errors.memberDangling",{provider:O});break}if(z.type==="aggregate"||O===d.id.trim()){p[x._key]=i("providers.aggregate.errors.memberNested",{provider:O});break}}if(k.has(D)){p[x._key]=i("providers.aggregate.errors.memberDuplicate",{target:D});break}k.add(D)}}const H=[[x.failover.consecutiveFailures,1,Ze],[x.failover.cooldownSeconds,1,er],[x.failover.failureWindowSeconds,1,rr]].some(([k,D,O])=>{const z=k.trim();if(!z)return!1;const J=Number(z);return!Number.isInteger(J)||J<D||J>O}),we=x.failover.triggerStatusCodes.split(",").map(k=>k.trim()).filter(Boolean);H?v[x._key]=i("providers.aggregate.errors.failoverInvalid"):we.some(k=>!tr(k))&&(v[x._key]=i("providers.aggregate.errors.triggerCodesInvalid"))}Object.keys(p).length>0&&(t.members=p),Object.keys(v).length>0&&(t.failover=v)}if(d.models.length>0){const p=new Set;d.models.some(j=>{const x=j.id.trim();return x.length===0||p.has(x)?!0:(p.add(x),!1)})&&(t.models=i("providers.drawer.errors.modelInvalid"))}d.defaultModel&&!d.models.some(p=>p.id===d.defaultModel)&&(t.models=i("providers.drawer.errors.defaultInvalid"));const o=d.rpmLimit.trim();if(o.length>0){const p=Number(o);(!Number.isInteger(p)||p<1||p>Je)&&(t.rpmLimit=i("providers.drawer.errors.rpmLimitInvalid"))}const f=d.rpmMaxWaitSeconds.trim();if(f.length>0){const p=Number(f);(!Number.isInteger(p)||p<1||p>Ye)&&(t.rpmMaxWaitSeconds=i("providers.drawer.errors.rpmMaxWaitInvalid"))}if(d.extraHeaders.length>0){const p=new Set;for(const v of d.extraHeaders){const j=v.name.trim();if(j.length===0)continue;if(!Qe.test(j)){t.extraHeaders=i("providers.drawer.errors.headerNameInvalid");break}const x=j.toLowerCase();if(p.has(x)){t.extraHeaders=i("providers.drawer.errors.headerNameDuplicate");break}p.add(x)}}return S(t),t};return{form:d,errors:h,advancedOpen:N,setAdvancedOpen:y,providerIdRef:T,isCreate:e==="create",resetForm:g,validate:()=>Object.keys(se()).length===0,validateErrors:se,serialize:()=>{const t=d.type==="aggregate",n=d.models.map(x=>{var M;return{id:x.id.trim(),label:(M=x.label)!=null&&M.trim()?x.label.trim():void 0,nonStreamViaStream:x.nonStreamViaStream,...t?{members:x.members.map(_=>({target:_.target.trim()})).filter(_=>_.target.length>0),failover:ar(x.failover)}:null}}).filter(x=>x.id.length>0),u={};for(const x of d.extraHeaders){const M=x.name.trim();M.length>0&&(u[M]=x.value)}const o=Object.keys(u).length>0,f=d.authMode==="apiKey"&&d.type!=="anthropic"?void 0:d.authMode,p={id:d.id.trim(),label:d.label.trim()||d.id.trim(),baseUrl:t?void 0:d.baseUrl.trim(),apiKey:t?void 0:d.apiKey.trim()||void 0,type:d.type??"custom",defaultModel:t?void 0:d.defaultModel||void 0,models:n.length>0?n:void 0,extraHeaders:t?void 0:o?u:void 0,authMode:t?void 0:f};d.nonStreamViaStream&&(p.nonStreamViaStream=!0),d.useAbsoluteUrl&&(p.useAbsoluteUrl=!0),d.streamUsage&&(p.streamUsage=!0);const v=Number(d.rpmLimit.trim());d.rpmLimit.trim().length>0&&Number.isInteger(v)&&v>=1&&(p.rpmLimit=v);const j=Number(d.rpmMaxWaitSeconds.trim());return d.rpmMaxWaitSeconds.trim().length>0&&Number.isInteger(j)&&j>=1&&(p.rpmMaxWaitSeconds=j),p},handleFieldChange:$,handleProviderIdChange:w,handleTypeChange:I,handleModelChange:l,handleModelIdChange:X,handleRemoveModel:b,handleAddModel:A,handleImportModels:E,handleHeaderChange:oe,handleAddHeader:ce,handleRemoveHeader:me,handleAuthModeChange:ue,handleProviderNonStreamViaStreamChange:pe,handleUseAbsoluteUrlChange:xe,handleStreamUsageChange:he,handleModelNonStreamViaStreamChange:fe,handleSetDefaultModel:ge,handleAddMember:be,handleRemoveMember:ve,handleMemberTargetChange:ye,handleReorderMembers:je,handleModelFailoverChange:Ne}}export{Tr as B,br as C,Er as M,vr as O,Ir as P,Rr as S,Ke as T,Nr as a,jr as b,re as c,yr as d,Sr as e,He as f,De as g,Mr as h,Xe as i,le as j,We as k,wr as l,Ur as m,Cr as n,kr as o,qe as p,Oe as r,Ar as u};
@@ -14,7 +14,7 @@
14
14
  rel="stylesheet"
15
15
  />
16
16
  <title>cc-gw 控制台</title>
17
- <script type="module" crossorigin src="/assets/app-BBAnVEPg.js"></script>
17
+ <script type="module" crossorigin src="/assets/app-BnQl39hq.js"></script>
18
18
  <link rel="modulepreload" crossorigin href="/assets/vendor-D2wC0h2o.js">
19
19
  <link rel="modulepreload" crossorigin href="/assets/global-CJOj9WGx.js">
20
20
  <link rel="modulepreload" crossorigin href="/assets/query-DVc6ZTRQ.js">
@@ -42,11 +42,11 @@
42
42
  }
43
43
  </script>
44
44
  <title>cc-gw | 你的 API Key 不该躺在 30 个 .env 里 · local-first AI gateway</title>
45
- <script type="module" crossorigin src="/assets/landing-MsSWlQKc.js"></script>
45
+ <script type="module" crossorigin src="/assets/landing-BuuM1jg8.js"></script>
46
46
  <link rel="modulepreload" crossorigin href="/assets/vendor-D2wC0h2o.js">
47
47
  <link rel="modulepreload" crossorigin href="/assets/global-CJOj9WGx.js">
48
48
  <link rel="modulepreload" crossorigin href="/assets/clipboard-BnAnBk_-.js">
49
- <link rel="modulepreload" crossorigin href="/assets/package-DHb277_G.js">
49
+ <link rel="modulepreload" crossorigin href="/assets/package-CKkVmaOi.js">
50
50
  <link rel="stylesheet" crossorigin href="/assets/global-CWlBZlIY.css">
51
51
  </head>
52
52
  <body class="bg-slate-50 text-slate-900">
@@ -1 +0,0 @@
1
- const o="0.12.0",s={version:o};export{s as p};