omniroute 2.8.7 → 2.8.8
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/app/.next/BUILD_ID +1 -1
- package/app/.next/build-manifest.json +2 -2
- package/app/.next/prerender-manifest.json +3 -3
- package/app/.next/server/app/(dashboard)/dashboard/a2a/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/agents/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/analytics/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/api-manager/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/audit-log/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/auto-combo/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/costs/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/health/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/limits/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/logs/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/mcp/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/media/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/onboarding/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/playground/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/search-tools/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/settings/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/400/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/401/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/403/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/408/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/429/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/500/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/502/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/503/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/_global-error.html +2 -2
- package/app/.next/server/app/_global-error.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/api/providers/test-batch/route.js +4 -4
- package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/docs/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/forbidden/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/forgot-password/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/maintenance/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/offline/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/privacy/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/status/page_client-reference-manifest.js +1 -1
- package/app/.next/server/app/terms/page_client-reference-manifest.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__09c944b3._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__7d9b23e7._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__80e3bfc3._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__84e445b2._.js +2 -2
- package/app/.next/server/chunks/[root-of-the-server]__92cb0def._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__d4563e10._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__db2f9fe0._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__e27a89bd._.js +1 -1
- package/app/.next/server/chunks/[root-of-the-server]__f31b4656._.js +1 -1
- package/app/.next/server/chunks/_05c48915._.js +1 -1
- package/app/.next/server/chunks/_2115d8de._.js +1 -1
- package/app/.next/server/chunks/_3ac953eb._.js +1 -1
- package/app/.next/server/chunks/_4b8fd853._.js +1 -1
- package/app/.next/server/chunks/_68683848._.js +1 -1
- package/app/.next/server/chunks/_ee9b677b._.js +1 -1
- package/app/.next/server/chunks/ssr/[root-of-the-server]__9affb65e._.js +1 -1
- package/app/.next/server/chunks/ssr/[root-of-the-server]__a6942102._.js +1 -1
- package/app/.next/server/chunks/ssr/src_d3225e36._.js +1 -1
- package/app/.next/server/pages/500.html +2 -2
- package/app/.next/server/server-reference-manifest.js +1 -1
- package/app/.next/server/server-reference-manifest.json +1 -1
- package/app/.next/static/chunks/{53e0c73d409ce003.js → 0c5e4a7f0f799d8c.js} +1 -1
- package/app/.next/static/chunks/6fecf6be49542089.js +1 -0
- package/app/CHANGELOG.md +14 -0
- package/app/docs/openapi.yaml +1 -1
- package/app/package-lock.json +2 -2
- package/app/package.json +1 -1
- package/app/src/app/(dashboard)/dashboard/providers/[id]/page.tsx +156 -0
- package/app/src/app/api/providers/test-batch/route.ts +48 -8
- package/package.json +1 -1
- package/app/.next/static/chunks/91761ba00c702cff.js +0 -1
- /package/app/.next/static/{zi0Yj1AW2_CKS-WmB5ZUc → yygubF7HqPRxaseKRZqYC}/_buildManifest.js +0 -0
- /package/app/.next/static/{zi0Yj1AW2_CKS-WmB5ZUc → yygubF7HqPRxaseKRZqYC}/_clientMiddlewareManifest.json +0 -0
- /package/app/.next/static/{zi0Yj1AW2_CKS-WmB5ZUc → yygubF7HqPRxaseKRZqYC}/_ssgManifest.js +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[779276,a=>{"use strict";var b=a.i(743442);a.s(["OAuthModal",()=>b.default])},202373,a=>{"use strict";var b=a.i(394093);a.s(["KiroOAuthWrapper",()=>b.default])},182527,a=>{"use strict";var b=a.i(296193);a.s(["CursorAuthModal",()=>b.default])},755235,a=>a.a(async(b,c)=>{try{var d=a.i(187924),e=a.i(572131),f=a.i(240246),g=a.i(341212),h=a.i(50944),i=a.i(238246),j=a.i(571987),k=a.i(415925),l=a.i(442308),m=a.i(292216),n=a.i(294023),o=a.i(818465),p=a.i(489108),q=a.i(563203),r=a.i(831097),s=a.i(779276),t=a.i(202373),u=a.i(182527),v=a.i(709918),w=a.i(525290),x=a.i(248172),y=a.i(662073),z=a.i(867933),A=a.i(911655),B=a.i(386592),C=b([l,y,z]);function D(a){let b=a&&"object"==typeof a&&!Array.isArray(a)?a:{};return{use5h:"boolean"!=typeof b.use5h||b.use5h,useWeekly:"boolean"!=typeof b.useWeekly||b.useWeekly}}function E({t:a,normalizeToolCallId:b,preserveDeveloperRole:c,showDeveloperToggle:f=!0,onNormalizeChange:g,onPreserveChange:h,disabled:i}){let[j,k]=(0,e.useState)(!1),l=(0,e.useRef)(null);return(0,e.useEffect)(()=>{if(!j)return;let a=a=>{l.current&&!l.current.contains(a.target)&&k(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[j]),(0,d.jsxs)("div",{className:"relative inline-block",ref:l,children:[(0,d.jsxs)("button",{type:"button",onClick:()=>k(a=>!a),disabled:i,className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md border border-border bg-sidebar/50 hover:bg-sidebar text-text-muted hover:text-text-main disabled:opacity-50",title:a("compatAdjustmentsTitle"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"tune"}),a("compatButtonLabel")]}),j&&(0,d.jsxs)("div",{className:"absolute left-0 top-full mt-1 z-50 min-w-[200px] p-3 rounded-lg border border-border bg-white dark:bg-zinc-900 shadow-xl ring-1 ring-black/5 dark:ring-white/10",children:[(0,d.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-text-muted mb-2",children:a("compatAdjustmentsTitle")}),(0,d.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,d.jsx)(v.Toggle,{size:"sm",label:a("compatToolIdShort"),title:a("normalizeToolCallIdLabel"),checked:b,onChange:g,disabled:i}),f&&(0,d.jsx)(v.Toggle,{size:"sm",label:a("compatDoNotPreserveDeveloper"),title:a("preserveDeveloperRoleLabel"),checked:!1===c,onChange:a=>h(!a),disabled:i})]})]})]})}function F(){let a=(0,h.useParams)(),b=(0,h.useRouter)(),c=a.id,[g,l]=(0,e.useState)([]),[o,p]=(0,e.useState)(!0),[v,w]=(0,e.useState)(null),[z,C]=(0,e.useState)(!1),[E,F]=(0,e.useState)(!1),[I,L]=(0,e.useState)(!1),[O,R]=(0,e.useState)(!1),[S,T]=(0,e.useState)(null),[U,V]=(0,e.useState)(null),[W,X]=(0,e.useState)({}),[Y,Z]=(0,e.useState)(!1),{copied:$,copy:_}=(0,B.useCopyToClipboard)(),aa=(0,k.useTranslations)("providers"),ab=(0,f.useNotificationStore)(),ac=(0,e.useRef)(!1),ad=(0,e.useRef)(!1),[ae,af]=(0,e.useState)(null),[ag,ah]=(0,e.useState)(null),[ai,aj]=(0,e.useState)(!1),[ak,al]=(0,e.useState)(!1),[am,an]=(0,e.useState)({current:0,total:0,phase:"idle",status:"",logs:[],error:"",importedCount:0}),[ao,ap]=(0,e.useState)({customModels:[],modelCompatOverrides:[]}),[aq,ar]=(0,e.useState)(null),as=v?{id:v.id,name:v.name||("anthropic-compatible"===v.type?aa("anthropicCompatibleName"):aa("openaiCompatibleName")),color:"anthropic-compatible"===v.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===v.type?"AC":"OC",apiType:v.apiType,baseUrl:v.baseUrl,type:v.type}:y.FREE_PROVIDERS[c]||y.OAUTH_PROVIDERS[c]||y.APIKEY_PROVIDERS[c],at=!!y.FREE_PROVIDERS[c]||!!y.OAUTH_PROVIDERS[c],au=(0,A.getModelsByProviderId)(c),av=(0,y.getProviderAlias)(c),aw=(0,y.isOpenAICompatibleProvider)(c),ax=(0,y.isAnthropicCompatibleProvider)(c),ay=aw||ax,az=c.endsWith("-search"),aA=ay?c:av,aB=ay?v?.prefix||c:av,aC=(0,e.useCallback)(async()=>{try{let a=await fetch("/api/models/alias"),b=await a.json();a.ok&&X(b.aliases||{})}catch(a){console.log("Error fetching aliases:",a)}},[]),aD=(0,e.useCallback)(async()=>{if(!az)try{let a=await fetch(`/api/provider-models?provider=${encodeURIComponent(c)}`,{cache:"no-store"});if(!a.ok)return;let b=await a.json();ap({customModels:b.models||[],modelCompatOverrides:b.modelCompatOverrides||[]})}catch(a){console.error("fetchProviderModelMeta",a)}},[c,az]),aE=(0,e.useCallback)(async()=>{try{let[a,b]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/provider-nodes",{cache:"no-store"})]),d=await a.json(),e=await b.json();if(a.ok){let a=(d.connections||[]).filter(a=>a.provider===c);l(a)}if(b.ok){let a=(e.nodes||[]).find(a=>a.id===c)||null;if(!a&&ay)for(let b=0;b<3;b+=1){await new Promise(a=>setTimeout(a,150));let b=await fetch("/api/provider-nodes",{cache:"no-store"});if(b.ok&&(a=((await b.json()).nodes||[]).find(a=>a.id===c)||null))break}w(a)}}catch(a){console.log("Error fetching connections:",a)}finally{p(!1)}},[c,ay]),aF=async a=>{try{let b=await fetch(`/api/provider-nodes/${c}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),d=await b.json();b.ok&&(w(d.node),await aE(),R(!1))}catch(a){console.log("Error updating provider node:",a)}};(0,e.useEffect)(()=>{aE(),aC(),fetch("/api/settings/proxy").then(a=>a.ok?a.json():null).then(a=>ah(a)).catch(()=>{})},[aE,aC]),(0,e.useEffect)(()=>{o||az||aD()},[o,az,aD]),(0,e.useEffect)(()=>{o||0!==g.length||!as||ay||ac.current||ad.current||(ac.current=!0,at?C(!0):F(!0))},[o]);let aG=async(a,b,c=av)=>{let d=`${c}/${a}`;try{let a=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:d,alias:b})});if(a.ok)await aC();else{let b=await a.json();alert(b.error||aa("failedSetAlias"))}}catch(a){console.log("Error setting alias:",a)}},aH=async a=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(a)}`,{method:"DELETE"})).ok&&await aC()}catch(a){console.log("Error deleting alias:",a)}},aI=async a=>{if(confirm(aa("deleteConnectionConfirm")))try{(await fetch(`/api/providers/${a}`,{method:"DELETE"})).ok&&l(g.filter(b=>b.id!==a))}catch(a){console.log("Error deleting connection:",a)}},aJ=(0,e.useCallback)(()=>{aE(),C(!1)},[aE]),aK=async a=>{try{let b=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,...a})});if(b.ok)return await aE(),F(!1),null;let d=await b.json().catch(()=>({}));return d.error?.message||d.error||aa("failedSaveConnection")}catch(a){return console.log("Error saving connection:",a),aa("failedSaveConnectionRetry")}},aL=async a=>{try{let b=await fetch(`/api/providers/${S.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(b.ok)return await aE(),L(!1),null;let c=await b.json().catch(()=>({}));return c.error?.message||c.error||aa("failedSaveConnection")}catch(a){return console.log("Error updating connection:",a),aa("failedSaveConnectionRetry")}},aM=async(a,b)=>{try{(await fetch(`/api/providers/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:b})})).ok&&l(c=>c.map(c=>c.id===a?{...c,isActive:b}:c))}catch(a){console.log("Error updating connection status:",a)}},aN=async(a,b)=>{try{(await fetch("/api/rate-limits",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connectionId:a,enabled:b})})).ok&&l(c=>c.map(c=>c.id===a?{...c,rateLimitProtection:b}:c))}catch(a){console.error("Error toggling rate limit:",a)}},aO=async(a,b,c)=>{try{let d=g.find(b=>b.id===a);if(!d)return;let e=d.providerSpecificData&&"object"==typeof d.providerSpecificData?d.providerSpecificData:{},f=e.codexLimitPolicy&&"object"==typeof e.codexLimitPolicy?e.codexLimitPolicy:{},h={...D(f),[b]:c},i=await fetch(`/api/providers/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerSpecificData:{...e,codexLimitPolicy:h}})});if(!i.ok){let a=await i.json().catch(()=>({}));ab.error(a.error||"Failed to update Codex limit policy");return}l(b=>b.map(b=>b.id===a?{...b,providerSpecificData:{...b.providerSpecificData||{},codexLimitPolicy:h}}:b)),ab.success("Codex limit policy updated")}catch(a){console.error("Error toggling Codex quota policy:",a),ab.error("Failed to update Codex limit policy")}},aP=async a=>{if(a&&!U){V(a);try{let b=await fetch(`/api/providers/${a}/test`,{method:"POST"});if(!b.ok){let a=await b.json().catch(()=>({}));alert(a.error||aa("failedRetestConnection"));return}await aE()}catch(a){console.error("Error retesting connection:",a)}finally{V(null)}}},[aQ,aR]=(0,e.useState)(null),aS=async a=>{if(!aQ){aR(a);try{let b=await fetch(`/api/providers/${a}/refresh`,{method:"POST"}),c=await b.json().catch(()=>({}));b.ok&&c.success?(ab.success(aa("tokenRefreshed")),await aE()):ab.error(c.error||aa("tokenRefreshFailed"))}catch(a){console.error("Error refreshing token:",a),ab.error(aa("tokenRefreshFailed"))}finally{aR(null)}}},aT=async(a,b)=>{if(a&&b)try{let c=b.priority,d=a.priority;c===d&&(c=g.indexOf(a)>g.indexOf(b)?b.priority-.5:b.priority+.5),await Promise.all([fetch(`/api/providers/${a.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:c})}),fetch(`/api/providers/${b.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:d})})]),await aE()}catch(a){console.log("Error swapping priority:",a)}},aU=async()=>{if(ai)return;let a=g.find(a=>!1!==a.isActive);if(a){aj(!0),al(!0),an({current:0,total:0,phase:"fetching",status:aa("fetchingModels"),logs:[],error:"",importedCount:0});try{let b=await fetch(`/api/providers/${a.id}/models`),d=await b.json();if(!b.ok)return void an(a=>({...a,phase:"error",status:aa("failedFetchModels"),error:d.error||aa("failedImportModels")}));let e=d.models||[];if(0===e.length)return void an(a=>({...a,phase:"done",status:aa("noModelsFound"),logs:[aa("noModelsReturnedFromEndpoint")]}));an(a=>({...a,phase:"importing",total:e.length,status:aa("importingModelsProgress",{current:0,total:e.length}),logs:[aa("foundModelsStartingImport",{count:e.length})]}));let f=0;for(let a=0;a<e.length;a++){let b=e[a],d=b.id||b.name||b.model;if(!d)continue;let g=d.split("/"),h=g[g.length-1];an(b=>({...b,current:a+1,status:aa("importingModelsProgress",{current:a+1,total:e.length}),logs:[...b.logs,aa("importingModelById",{modelId:d})]})),await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,modelId:d,modelName:b.name||d,source:"imported"})}),W[h]||await aG(d,h,aA),f+=1}await aC(),an(a=>({...a,phase:"done",current:e.length,status:f>0?aa("importSuccessCount",{count:f}):aa("noNewModelsAddedExisting"),logs:[...a.logs,f>0?aa("importDoneCount",{count:f}):aa("noNewModelsAdded")],importedCount:f})),f>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(a){console.log("Error importing models:",a),an(b=>({...b,phase:"error",status:aa("importFailed"),error:a instanceof Error?a.message:aa("unexpectedErrorOccurred")}))}finally{aj(!1)}}},aV=async(a,b)=>{al(!0),an({current:0,total:0,phase:"fetching",status:aa("fetchingModels"),logs:[],error:"",importedCount:0});try{let c=(await a()).models||[];if(0===c.length)return void an(a=>({...a,phase:"done",status:aa("noModelsFound"),logs:[aa("noModelsReturnedFromEndpoint")]}));an(a=>({...a,phase:"importing",total:c.length,status:aa("importingModelsProgress",{current:0,total:c.length}),logs:[aa("foundModelsStartingImport",{count:c.length})]}));let d=0;for(let a=0;a<c.length;a++){let e=c[a],f=e.id||e.name||e.model;f&&(an(b=>({...b,current:a+1,status:aa("importingModelsProgress",{current:a+1,total:c.length}),logs:[...b.logs,aa("importingModelById",{modelId:f})]})),await b(e)&&(d+=1))}an(a=>({...a,phase:"done",current:c.length,status:d>0?aa("importSuccessCount",{count:d}):aa("noNewModelsAdded"),logs:[...a.logs,d>0?aa("importDoneCount",{count:d}):aa("noNewModelsAdded")],importedCount:d})),d>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(a){console.log("Error importing models:",a),an(b=>({...b,phase:"error",status:aa("importFailed"),error:a instanceof Error?a.message:aa("unexpectedErrorOccurred")}))}},aW=g.some(a=>!1!==a.isActive),aX=a=>{let b=ao.customModels.find(b=>b.id===a);if(b)return!!b.normalizeToolCallId;let c=ao.modelCompatOverrides.find(b=>b.id===a);return!!c?.normalizeToolCallId},aY=a=>{let b=ao.customModels.find(b=>b.id===a);if(b&&Object.prototype.hasOwnProperty.call(b,"preserveOpenAIDeveloperRole"))return!!b.preserveOpenAIDeveloperRole;let c=ao.modelCompatOverrides.find(b=>b.id===a);return!(c&&Object.prototype.hasOwnProperty.call(c,"preserveOpenAIDeveloperRole"))||!!c.preserveOpenAIDeveloperRole},aZ=async(a,b)=>{ar(a);try{let d,e=ao.customModels.find(b=>b.id===a);d=e?{provider:c,modelId:a,modelName:e.name||a,source:e.source||"manual",apiFormat:e.apiFormat||"chat-completions",supportedEndpoints:Array.isArray(e.supportedEndpoints)&&e.supportedEndpoints.length?e.supportedEndpoints:["chat"],normalizeToolCallId:void 0!==b.normalizeToolCallId?b.normalizeToolCallId:!!e.normalizeToolCallId,preserveOpenAIDeveloperRole:void 0!==b.preserveOpenAIDeveloperRole?b.preserveOpenAIDeveloperRole:!Object.prototype.hasOwnProperty.call(e,"preserveOpenAIDeveloperRole")||!!e.preserveOpenAIDeveloperRole}:{provider:c,modelId:a,...b},(await fetch("/api/provider-models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})).ok?await aD():ab.error(aa("failedSaveCustomModel"))}catch{ab.error(aa("failedSaveCustomModel"))}finally{ar(null)}};return o?(0,d.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,d.jsx)(r.CardSkeleton,{}),(0,d.jsx)(r.CardSkeleton,{})]}):as?(0,d.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,d.jsxs)("div",{children:[(0,d.jsxs)(i.default,{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),aa("backToProviders")]}),(0,d.jsxs)("div",{className:"flex items-center gap-4",children:[(0,d.jsx)("div",{className:"rounded-lg flex items-center justify-center",style:{backgroundColor:`${as.color}15`},children:Y?(0,d.jsx)("span",{className:"text-sm font-bold",style:{color:as.color},children:as.textIcon||as.id.slice(0,2).toUpperCase()}):(0,d.jsx)(j.default,{src:aw&&as.apiType?"responses"===as.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":ax?"/providers/anthropic-m.png":`/providers/${as.id}.png`,alt:as.name,width:48,height:48,className:"object-contain rounded-lg max-w-[48px] max-h-[48px]",sizes:"48px",onError:()=>Z(!0)})}),(0,d.jsxs)("div",{children:[as.website?(0,d.jsxs)("a",{href:as.website,target:"_blank",rel:"noopener noreferrer",className:"text-3xl font-semibold tracking-tight hover:underline inline-flex items-center gap-2",style:{color:as.color},children:[as.name,(0,d.jsx)("span",{className:"material-symbols-outlined text-lg opacity-60",children:"open_in_new"})]}):(0,d.jsx)("h1",{className:"text-3xl font-semibold tracking-tight",children:as.name}),(0,d.jsx)("p",{className:"text-text-muted",children:aa("connectionCountLabel",{count:g.length})})]})]})]}),ay&&v&&(0,d.jsxs)(m.Card,{children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:ax?aa("anthropicCompatibleDetails"):aa("openaiCompatibleDetails")}),(0,d.jsxs)("p",{className:"text-sm text-text-muted",children:[ax?aa("messagesApi"):"responses"===v.apiType?aa("responsesApi"):aa("chatCompletions")," ","· ",(v.baseUrl||"").replace(/\/$/,""),"/",ax?aa("messagesPath"):"responses"===v.apiType?aa("responsesPath"):aa("chatCompletionsPath")]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:()=>F(!0),disabled:g.length>0,children:aa("add")}),(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>R(!0),children:aa("edit")}),(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(aa("deleteCompatibleNodeConfirm",{type:ax?aa("anthropic"):aa("openai")})))try{(await fetch(`/api/provider-nodes/${c}`,{method:"DELETE"})).ok&&b.push("/dashboard/providers")}catch(a){console.log("Error deleting provider node:",a)}},children:aa("delete")})]})]}),g.length>0&&(0,d.jsx)("p",{className:"text-sm text-text-muted",children:aa("singleConnectionPerCompatible")})]}),(0,d.jsxs)(m.Card,{children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-3",children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:aa("connections")}),(0,d.jsxs)("button",{onClick:()=>af({level:"provider",id:c,label:as?.name||c}),className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs font-medium transition-all ${ag?.providers?.[c]?"bg-amber-500/15 text-amber-500 hover:bg-amber-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:ag?.providers?.[c]?aa("providerProxyTitleConfigured",{host:ag.providers[c].host||aa("configured")}):aa("providerProxyConfigureHint"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"vpn_lock"}),ag?.providers?.[c]&&ag.providers[c].host||aa("providerProxy")]})]}),ay?0===g.length&&(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:()=>F(!0),children:aa("add")}):(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:()=>at?C(!0):F(!0),children:aa("add")})]}),0===g.length?(0,d.jsxs)("div",{className:"text-center py-12",children:[(0,d.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[32px]",children:at?"lock":"key"})}),(0,d.jsx)("p",{className:"text-text-main font-medium mb-1",children:aa("noConnectionsYet")}),(0,d.jsx)("p",{className:"text-sm text-text-muted mb-4",children:aa("addFirstConnectionHint")}),!ay&&(0,d.jsx)(n.Button,{icon:"add",onClick:()=>at?C(!0):F(!0),children:aa("addConnection")})]}):(0,d.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:g.sort((a,b)=>(a.priority||0)-(b.priority||0)).map((a,b)=>(0,d.jsx)(M,{connection:a,isOAuth:at,isFirst:0===b,isLast:b===g.length-1,onMoveUp:()=>aT(a,g[b-1]),onMoveDown:()=>aT(a,g[b+1]),onToggleActive:b=>aM(a.id,b),onToggleRateLimit:b=>aN(a.id,b),isCodex:"codex"===c,onToggleCodex5h:b=>aO(a.id,"use5h",b),onToggleCodexWeekly:b=>aO(a.id,"useWeekly",b),onRetest:()=>aP(a.id),isRetesting:U===a.id,onEdit:()=>{T(a),L(!0)},onDelete:()=>aI(a.id),onReauth:at?()=>C(!0):void 0,onRefreshToken:at?()=>aS(a.id):void 0,isRefreshing:aQ===a.id,onProxy:()=>af({level:"key",id:a.id,label:a.name||a.email||a.id}),hasProxy:!!(ag?.keys?.[a.id]||ag?.providers?.[c]||ag?.global),proxySource:ag?.keys?.[a.id]?"key":ag?.providers?.[c]?"provider":ag?.global?"global":null,proxyHost:(ag?.keys?.[a.id]||ag?.providers?.[c]||ag?.global)?.host||null},a.id))})]}),!az&&(0,d.jsxs)(m.Card,{children:[(0,d.jsx)("h2",{className:"text-lg font-semibold mb-4",children:aa("availableModels")}),(()=>{if(ay)return(0,d.jsx)(K,{providerStorageAlias:aA,providerDisplayAlias:aB,modelAliases:W,copied:$,onCopy:_,onSetAlias:aG,onDeleteAlias:aH,connections:g,isAnthropic:ax,onImportWithProgress:aV,t:aa,effectiveModelNormalize:aX,effectiveModelPreserveDeveloper:aY,saveModelCompatFlags:aZ,compatSavingModelId:aq,onModelsChanged:aD});if(as.passthroughModels)return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"download",onClick:aU,disabled:!aW||ai,children:ai?aa("importingModels"):aa("importFromModels")}),!aW&&(0,d.jsx)("span",{className:"text-xs text-text-muted",children:aa("addConnectionToImport")})]}),(0,d.jsx)(H,{providerAlias:av,modelAliases:W,copied:$,onCopy:_,onSetAlias:aG,onDeleteAlias:aH,t:aa,effectiveModelNormalize:aX,effectiveModelPreserveDeveloper:aY,saveModelCompatFlags:aZ,compatSavingModelId:aq})]});let a=(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"download",onClick:aU,disabled:!aW||ai,children:ai?aa("importingModels"):aa("importFromModels")}),!aW&&(0,d.jsx)("span",{className:"text-xs text-text-muted",children:aa("addConnectionToImport")})]});return 0===au.length?(0,d.jsxs)("div",{children:[a,(0,d.jsx)("p",{className:"text-sm text-text-muted",children:aa("noModelsConfigured")})]}):(0,d.jsxs)("div",{children:[a,(0,d.jsx)("div",{className:"flex flex-wrap gap-3",children:au.map(a=>{let b=`${aA}/${a.id}`,e=`${c}/${a.id}`,f=Object.entries(W).find(([,a])=>a===b||a===e)?.[0];return(0,d.jsx)(G,{model:a,fullModel:`${aB}/${a.id}`,alias:f,copied:$,onCopy:_,t:aa,showDeveloperToggle:!0,normalizeToolCallId:aX(a.id),preserveDeveloperRole:aY(a.id),onNormalizeChange:b=>aZ(a.id,{normalizeToolCallId:b}),onPreserveChange:b=>aZ(a.id,{preserveOpenAIDeveloperRole:b}),compatDisabled:aq===a.id},a.id)})})]})})(),!ay&&(0,d.jsx)(J,{providerId:c,providerAlias:aB,copied:$,onCopy:_,onModelsChanged:aD})]}),az&&(0,d.jsxs)(m.Card,{children:[(0,d.jsx)("h2",{className:"text-lg font-semibold mb-4",children:aa("searchProvider")||"Search Provider"}),(0,d.jsx)("p",{className:"text-sm text-text-muted",children:aa("searchProviderDesc")||"This provider is used for web search via POST /v1/search. No model configuration needed — search providers are ready to use once an API key is connected."}),"perplexity-search"===c&&(0,d.jsxs)("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded-lg bg-blue-500/10 border border-blue-500/20",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-sm text-blue-400",children:"link"}),(0,d.jsxs)("p",{className:"text-xs text-blue-300",children:["Uses the same API key as ",(0,d.jsx)("strong",{children:"Perplexity"})," (chat provider). If you already have Perplexity configured, no additional setup is needed."]})]})]}),"kiro"===c?(0,d.jsx)(t.KiroOAuthWrapper,{isOpen:z,providerInfo:as,onSuccess:aJ,onClose:()=>{ad.current=!0,C(!1)}}):"cursor"===c?(0,d.jsx)(u.CursorAuthModal,{isOpen:z,onSuccess:aJ,onClose:()=>{ad.current=!0,C(!1)}}):(0,d.jsx)(s.OAuthModal,{isOpen:z,provider:c,providerInfo:as,onSuccess:aJ,onClose:()=>{ad.current=!0,C(!1)}}),(0,d.jsx)(N,{isOpen:E,provider:c,providerName:as.name,isCompatible:ay,isAnthropic:ax,onSave:aK,onClose:()=>F(!1)}),(0,d.jsx)(P,{isOpen:I,connection:S,onSave:aL,onClose:()=>L(!1)}),ay&&(0,d.jsx)(Q,{isOpen:O,node:v,onSave:aF,onClose:()=>R(!1),isAnthropic:ax}),ae&&(0,d.jsx)(x.ProxyConfigModal,{isOpen:!!ae,onClose:()=>af(null),level:ae.level,levelId:ae.id,levelLabel:ae.label}),(0,d.jsx)(q.Modal,{isOpen:ak,onClose:()=>{("done"===am.phase||"error"===am.phase)&&al(!1)},title:aa("importingModelsTitle"),size:"md",closeOnOverlay:!1,showCloseButton:"done"===am.phase||"error"===am.phase,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-3",children:["fetching"===am.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"importing"===am.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"done"===am.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-green-500",children:"check_circle"}),"error"===am.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-red-500",children:"error"}),(0,d.jsx)("span",{className:"text-sm font-medium text-text-main",children:am.status})]}),("importing"===am.phase||"done"===am.phase)&&am.total>0&&(0,d.jsxs)("div",{className:"w-full",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,d.jsxs)("span",{className:"text-xs text-text-muted",children:[am.current," / ",am.total]}),(0,d.jsxs)("span",{className:"text-xs text-text-muted",children:[Math.round(am.current/am.total*100),"%"]})]}),(0,d.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,d.jsx)("div",{className:"h-full rounded-full transition-all duration-300 ease-out",style:{width:`${am.current/am.total*100}%`,background:"done"===am.phase?"linear-gradient(90deg, #22c55e, #16a34a)":"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})})]}),"fetching"===am.phase&&(0,d.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,d.jsx)("div",{className:"h-full rounded-full animate-pulse",style:{width:"60%",background:"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})}),"error"===am.phase&&am.error&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-red-500/10 border border-red-500/20",children:(0,d.jsx)("p",{className:"text-sm text-red-400",children:am.error})}),am.logs.length>0&&(0,d.jsx)("div",{className:"max-h-48 overflow-y-auto rounded-lg bg-black/5 dark:bg-white/5 p-3 border border-black/5 dark:border-white/5",children:(0,d.jsx)("div",{className:"flex flex-col gap-1",children:am.logs.map((a,b)=>(0,d.jsx)("p",{className:`text-xs font-mono ${a.startsWith("✓")?"text-green-500 font-semibold":"text-text-muted"}`,children:a},b))})}),"done"===am.phase&&am.importedCount>0&&(0,d.jsx)("p",{className:"text-xs text-text-muted text-center animate-pulse",children:aa("pageAutoRefresh")})]})})]}):(0,d.jsxs)("div",{className:"text-center py-20",children:[(0,d.jsx)("p",{className:"text-text-muted",children:aa("providerNotFound")}),(0,d.jsx)(i.default,{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:aa("backToProviders")})]})}function G({model:a,fullModel:b,alias:c,copied:e,onCopy:f,t:g,showDeveloperToggle:h=!0,normalizeToolCallId:i,preserveDeveloperRole:j,onNormalizeChange:k,onPreserveChange:l,compatDisabled:m}){return(0,d.jsxs)("div",{className:"flex flex-col px-3 py-2 rounded-lg border border-border hover:bg-sidebar/50 min-w-[220px] max-w-md",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted shrink-0",children:"smart_toy"}),(0,d.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:b}),(0,d.jsx)("button",{onClick:()=>f(b,`model-${a.id}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:g("copyModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:e===`model-${a.id}`?"check":"content_copy"})})]}),(0,d.jsx)(E,{t:g,normalizeToolCallId:!!i,preserveDeveloperRole:j,showDeveloperToggle:h,onNormalizeChange:k,onPreserveChange:l,disabled:m})]})}function H({providerAlias:a,modelAliases:b,copied:c,onCopy:f,onSetAlias:g,onDeleteAlias:h,t:i,effectiveModelNormalize:j,effectiveModelPreserveDeveloper:k,saveModelCompatFlags:l,compatSavingModelId:m}){let[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(!1),s=Object.entries(b).filter(([,b])=>b.startsWith(`${a}/`)).map(([b,c])=>({modelId:c.replace(`${a}/`,""),fullModel:c,alias:b})),t=async()=>{let a;if(!o.trim()||q)return;let c=o.trim(),d=(a=c.split("/"))[a.length-1];if(b[d])return void alert(i("aliasExistsAlert",{alias:d}));r(!0);try{await g(c,d),p("")}catch(a){console.log("Error adding model:",a)}finally{r(!1)}};return(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)("p",{className:"text-sm text-text-muted",children:i("openRouterAnyModelHint")}),(0,d.jsxs)("div",{className:"flex items-end gap-2",children:[(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("label",{htmlFor:"new-model-input",className:"text-xs text-text-muted mb-1 block",children:i("modelIdFromOpenRouter")}),(0,d.jsx)("input",{id:"new-model-input",type:"text",value:o,onChange:a=>p(a.target.value),onKeyDown:a=>"Enter"===a.key&&t(),placeholder:i("openRouterModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:t,disabled:!o.trim()||q,children:q?i("adding"):i("add")})]}),s.length>0&&(0,d.jsx)("div",{className:"flex flex-col gap-3",children:s.map(({modelId:a,fullModel:b,alias:e})=>(0,d.jsx)(I,{modelId:a,fullModel:b,copied:c,onCopy:f,onDeleteAlias:()=>h(e),t:i,showDeveloperToggle:!0,normalizeToolCallId:j(a),preserveDeveloperRole:k(a),onNormalizeChange:b=>l(a,{normalizeToolCallId:b}),onPreserveChange:b=>l(a,{preserveOpenAIDeveloperRole:b}),compatDisabled:m===a},b))})]})}function I({modelId:a,fullModel:b,copied:c,onCopy:e,onDeleteAlias:f,t:g,showDeveloperToggle:h=!0,normalizeToolCallId:i,preserveDeveloperRole:j,onNormalizeChange:k,onPreserveChange:l,compatDisabled:m}){return(0,d.jsxs)("div",{className:"flex flex-col gap-0 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,d.jsxs)("div",{className:"flex items-start gap-3",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted shrink-0",children:"smart_toy"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium truncate",children:a}),(0,d.jsxs)("div",{className:"flex items-center gap-1 mt-1 flex-wrap",children:[(0,d.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:b}),(0,d.jsx)("button",{onClick:()=>e(b,`model-${a}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:g("copyModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:c===`model-${a}`?"check":"content_copy"})})]})]}),(0,d.jsx)("button",{onClick:f,className:"p-1 hover:bg-red-50 rounded text-red-500 shrink-0",title:g("removeModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]}),(0,d.jsx)("div",{className:"pl-9",children:(0,d.jsx)(E,{t:g,normalizeToolCallId:!!i,preserveDeveloperRole:j,showDeveloperToggle:h,onNormalizeChange:k,onPreserveChange:l,disabled:m})})]})}function J({providerId:a,providerAlias:b,copied:c,onCopy:g,onModelsChanged:h}){let i=(0,k.useTranslations)("providers"),j=(0,f.useNotificationStore)(),[l,m]=(0,e.useState)([]),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)("chat-completions"),[u,v]=(0,e.useState)(["chat"]),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!0),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)("chat-completions"),[F,G]=(0,e.useState)(["chat"]),[H,I]=(0,e.useState)(!1),[J,K]=(0,e.useState)(!1),[L,M]=(0,e.useState)(null),N=(0,e.useCallback)(async()=>{try{let b=await fetch(`/api/provider-models?provider=${encodeURIComponent(a)}`);if(b.ok){let a=await b.json();m(a.models||[])}}catch(a){console.error("Failed to fetch custom models:",a)}finally{z(!1)}},[a]);(0,e.useEffect)(()=>{N()},[N]);let O=async()=>{if(o.trim()&&!w){x(!0);try{(await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:o.trim(),modelName:q.trim()||void 0,apiFormat:s,supportedEndpoints:u})})).ok&&(p(""),r(""),t("chat-completions"),v(["chat"]),await N(),h?.())}catch(a){console.error("Failed to add custom model:",a)}finally{x(!1)}}},P=async b=>{try{await fetch(`/api/provider-models?provider=${encodeURIComponent(a)}&model=${encodeURIComponent(b)}`,{method:"DELETE"}),await N(),h?.()}catch(a){console.error("Failed to remove custom model:",a)}},Q=()=>{B(null),D("chat-completions"),G(["chat"]),I(!1),K(!0),M(null)},R=async b=>{if(A&&A===b){if(!F.length)return void j.error("Select at least one supported endpoint");M(b);try{let c=l.find(a=>a.id===b);if(!(await fetch("/api/provider-models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:b,modelName:c?.name||b,source:c?.source||"manual",apiFormat:C,supportedEndpoints:F,normalizeToolCallId:H,preserveOpenAIDeveloperRole:J})})).ok)throw Error("Failed to save model endpoint settings");await N(),h?.(),j.success("Saved model endpoint settings"),Q()}catch(a){console.error("Failed to save custom model:",a),j.error("Failed to save model endpoint settings")}finally{M(null)}}};return(0,d.jsxs)("div",{className:"mt-6 pt-6 border-t border-border",children:[(0,d.jsxs)("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),i("customModels")]}),(0,d.jsx)("p",{className:"text-xs text-text-muted mb-3",children:i("customModelsHint")}),(0,d.jsxs)("div",{className:"flex flex-col gap-3 mb-3",children:[(0,d.jsxs)("div",{className:"flex items-end gap-2",children:[(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("label",{htmlFor:"custom-model-id",className:"text-xs text-text-muted mb-1 block",children:i("modelId")}),(0,d.jsx)("input",{id:"custom-model-id",type:"text",value:o,onChange:a=>p(a.target.value),onKeyDown:a=>"Enter"===a.key&&O(),placeholder:i("customModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsxs)("div",{className:"w-40",children:[(0,d.jsx)("label",{htmlFor:"custom-model-name",className:"text-xs text-text-muted mb-1 block",children:i("displayName")}),(0,d.jsx)("input",{id:"custom-model-name",type:"text",value:q,onChange:a=>r(a.target.value),onKeyDown:a=>"Enter"===a.key&&O(),placeholder:i("optional"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:O,disabled:!o.trim()||w,children:w?i("adding"):i("add")})]}),(0,d.jsxs)("div",{className:"flex items-end gap-4 flex-wrap",children:[(0,d.jsxs)("div",{className:"w-48",children:[(0,d.jsx)("label",{htmlFor:"custom-api-format",className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,d.jsxs)("select",{id:"custom-api-format",value:s,onChange:a=>t(a.target.value),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,d.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,d.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,d.jsx)("div",{className:"flex items-center gap-3",children:["chat","embeddings","images","audio"].map(a=>(0,d.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,d.jsx)("input",{type:"checkbox",checked:u.includes(a),onChange:b=>{b.target.checked?v(b=>[...b,a]):v(b=>b.filter(b=>b!==a))},className:"rounded border-border"}),"chat"===a?"💬 Chat":"embeddings"===a?"📐 Embeddings":"images"===a?"🖼️ Images":"🔊 Audio"]},a))})]})]})]}),y?(0,d.jsx)("p",{className:"text-xs text-text-muted",children:i("loading")}):l.length>0?(0,d.jsx)("div",{className:"flex flex-col gap-2",children:l.map(a=>{let e=`${b}/${a.id}`,f=`custom-${a.id}`;return(0,d.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium truncate",children:a.name||a.id}),(0,d.jsxs)("div",{className:"flex items-center gap-1 mt-1 flex-wrap",children:[(0,d.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:e}),(0,d.jsx)("button",{onClick:()=>g(e,f),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:i("copyModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:c===f?"check":"content_copy"})}),"responses"===a.apiFormat&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-blue-500/15 text-blue-400 font-medium",children:"Responses"}),a.supportedEndpoints?.includes("embeddings")&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-purple-500/15 text-purple-400 font-medium",children:"📐 Embed"}),a.supportedEndpoints?.includes("images")&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/15 text-amber-400 font-medium",children:"🖼️ Images"}),a.supportedEndpoints?.includes("audio")&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400 font-medium",children:"🔊 Audio"}),a.normalizeToolCallId&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-slate-500/15 text-slate-400 font-medium",title:i("normalizeToolCallIdLabel"),children:"ID×9"}),!1===a.preserveOpenAIDeveloperRole&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-cyan-500/15 text-cyan-400 font-medium",title:i("compatDoNotPreserveDeveloper"),children:i("compatBadgeNoPreserve")})]}),A===a.id&&(0,d.jsxs)("div",{className:"mt-3 p-3 rounded-lg border border-border bg-sidebar/40",children:[(0,d.jsxs)("div",{className:"flex items-end gap-3 flex-wrap",children:[(0,d.jsxs)("div",{className:"w-44",children:[(0,d.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,d.jsxs)("select",{value:C,onChange:a=>D(a.target.value),className:"w-full px-2.5 py-2 text-xs border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,d.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,d.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,d.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,d.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,d.jsx)("div",{className:"flex items-center gap-3 flex-wrap",children:["chat","embeddings","images","audio"].map(a=>(0,d.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,d.jsx)("input",{type:"checkbox",checked:F.includes(a),onChange:b=>{b.target.checked?G(b=>b.includes(a)?b:[...b,a]):G(b=>b.filter(b=>b!==a))},className:"rounded border-border"}),"chat"===a?"💬 Chat":"embeddings"===a?"📐 Embeddings":"images"===a?"🖼️ Images":"🔊 Audio"]},a))})]})]}),(0,d.jsx)("div",{className:"mt-3 pt-3 border-t border-border/80 w-full",children:(0,d.jsx)(E,{t:i,normalizeToolCallId:H,preserveDeveloperRole:J,showDeveloperToggle:!0,onNormalizeChange:I,onPreserveChange:K,disabled:L===a.id})}),(0,d.jsxs)("div",{className:"mt-3 flex items-center gap-2",children:[(0,d.jsx)(n.Button,{size:"sm",onClick:()=>R(a.id),disabled:L===a.id,children:L===a.id?i("saving"):i("save")}),(0,d.jsx)(n.Button,{size:"sm",variant:"ghost",onClick:Q,children:i("cancel")})]})]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("button",{onClick:()=>{B(a.id),D(a.apiFormat||"chat-completions"),G(Array.isArray(a.supportedEndpoints)&&a.supportedEndpoints.length?a.supportedEndpoints:["chat"]),I(!!a.normalizeToolCallId),K(!Object.prototype.hasOwnProperty.call(a,"preserveOpenAIDeveloperRole")||!!a.preserveOpenAIDeveloperRole)},className:"p-1 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:i("edit"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"edit"})}),(0,d.jsx)("button",{onClick:()=>P(a.id),className:"p-1 hover:bg-red-50 rounded text-red-500",title:i("removeCustomModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})]},a.id)})}):(0,d.jsx)("p",{className:"text-xs text-text-muted",children:i("noCustomModels")})]})}function K({providerStorageAlias:a,providerDisplayAlias:b,modelAliases:c,copied:g,onCopy:h,onSetAlias:i,onDeleteAlias:j,connections:k,isAnthropic:l,onImportWithProgress:m,t:o,effectiveModelNormalize:p,effectiveModelPreserveDeveloper:q,saveModelCompatFlags:r,compatSavingModelId:s,onModelsChanged:t}){let[u,v]=(0,e.useState)(""),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),A=(0,f.useNotificationStore)(),B=Object.entries(c).filter(([,b])=>b.startsWith(`${a}/`)).map(([b,c])=>({modelId:c.replace(`${a}/`,""),fullModel:c,alias:b})),C=a=>{let d,e=(d=a.split("/"))[d.length-1];if(!c[e])return e;let f=`${b}-${e}`;return c[f]?null:f},D=async()=>{if(!u.trim()||w)return;let b=u.trim(),c=C(b);if(!c)return void A.error(o("allSuggestedAliasesExist"));x(!0);try{let d=await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:b,modelName:b,source:"manual"})});if(!d.ok){let a={};try{a=await d.json()}catch(a){console.error("Failed to parse error response from custom model API:",a)}throw Error(a.error?.message||o("failedSaveCustomModel"))}await i(b,c,a),v(""),A.success(o("modelAddedSuccess",{modelId:b})),t?.()}catch(a){console.error("Error adding model:",a),A.error(a instanceof Error?a.message:o("failedAddModelTryAgain"))}finally{x(!1)}},E=async()=>{if(y)return;let b=k.find(a=>!1!==a.isActive);if(b){z(!0);try{await m(async()=>{let a=await fetch(`/api/providers/${b.id}/models`),c=await a.json();if(!a.ok)throw Error(c.error||o("failedImportModels"));return c},async b=>{let c=b.id||b.name||b.model;if(!c)return!1;let d=C(c);return!!d&&((await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:c,modelName:b.name||c,source:"imported"})})).ok?(await i(c,d,a),!0):(A.error(o("failedSaveImportedModel")),!1))})}catch(a){console.error("Error importing models:",a),A.error(o("failedImportModelsTryAgain"))}finally{z(!1)}}},F=k.some(a=>!1!==a.isActive),G=async(b,c)=>{try{if(!(await fetch(`/api/provider-models?provider=${encodeURIComponent(a)}&model=${encodeURIComponent(b)}`,{method:"DELETE"})).ok)throw Error(o("failedRemoveModelFromDatabase"));await j(c),A.success(o("modelRemovedSuccess")),t?.()}catch(a){console.error("Error deleting model:",a),A.error(a instanceof Error?a.message:o("failedDeleteModelTryAgain"))}};return(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)("p",{className:"text-sm text-text-muted",children:o("compatibleModelsDescription",{type:l?o("anthropic"):o("openai")})}),(0,d.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,d.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:o("modelId")}),(0,d.jsx)("input",{id:"new-compatible-model-input",type:"text",value:u,onChange:a=>v(a.target.value),onKeyDown:a=>"Enter"===a.key&&D(),placeholder:l?o("anthropicCompatibleModelPlaceholder"):o("openaiCompatibleModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:D,disabled:!u.trim()||w,children:w?o("adding"):o("add")}),(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"download",onClick:E,disabled:!F||y,children:y?o("importingModels"):o("importFromModels")})]}),!F&&(0,d.jsx)("p",{className:"text-xs text-text-muted",children:o("addConnectionToImport")}),B.length>0&&(0,d.jsx)("div",{className:"flex flex-col gap-3",children:B.map(({modelId:a,fullModel:c,alias:e})=>(0,d.jsx)(I,{modelId:a,fullModel:`${b}/${a}`,copied:g,onCopy:h,onDeleteAlias:()=>G(a,e),t:o,showDeveloperToggle:!l,normalizeToolCallId:p(a),preserveDeveloperRole:q(a),onNormalizeChange:b=>r(a,{normalizeToolCallId:b}),onPreserveChange:b=>r(a,{preserveOpenAIDeveloperRole:b}),compatDisabled:s===a},c))})]})}function L({until:a}){let[b,c]=(0,e.useState)("");return((0,e.useEffect)(()=>{let b=()=>{let b=new Date(a).getTime()-Date.now();if(b<=0)return void c("");let d=Math.floor(b/1e3);if(d<60)c(`${d}s`);else if(d<3600)c(`${Math.floor(d/60)}m ${d%60}s`);else{let a=Math.floor(d/3600),b=Math.floor(d%3600/60);c(`${a}h ${b}m`)}};b();let d=setInterval(b,1e3);return()=>clearInterval(d)},[a]),b)?(0,d.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",b]}):null}[l,y,z]=C.then?(await C)():C,G.propTypes={model:g.default.shape({id:g.default.string.isRequired}).isRequired,fullModel:g.default.string.isRequired,alias:g.default.string,copied:g.default.string,onCopy:g.default.func.isRequired,t:g.default.func,showDeveloperToggle:g.default.bool,normalizeToolCallId:g.default.bool,preserveDeveloperRole:g.default.bool,onNormalizeChange:g.default.func,onPreserveChange:g.default.func,compatDisabled:g.default.bool},H.propTypes={providerAlias:g.default.string.isRequired,modelAliases:g.default.object.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onSetAlias:g.default.func.isRequired,onDeleteAlias:g.default.func.isRequired,t:g.default.func.isRequired,effectiveModelNormalize:g.default.func.isRequired,effectiveModelPreserveDeveloper:g.default.func.isRequired,saveModelCompatFlags:g.default.func.isRequired,compatSavingModelId:g.default.string},I.propTypes={modelId:g.default.string.isRequired,fullModel:g.default.string.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onDeleteAlias:g.default.func.isRequired,t:g.default.func,showDeveloperToggle:g.default.bool,normalizeToolCallId:g.default.bool,preserveDeveloperRole:g.default.bool,onNormalizeChange:g.default.func,onPreserveChange:g.default.func,compatDisabled:g.default.bool},J.propTypes={providerId:g.default.string.isRequired,providerAlias:g.default.string.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onModelsChanged:g.default.func},K.propTypes={providerStorageAlias:g.default.string.isRequired,providerDisplayAlias:g.default.string.isRequired,modelAliases:g.default.object.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onSetAlias:g.default.func.isRequired,onDeleteAlias:g.default.func.isRequired,connections:g.default.arrayOf(g.default.shape({id:g.default.string,isActive:g.default.bool})).isRequired,isAnthropic:g.default.bool,onImportWithProgress:g.default.func.isRequired,t:g.default.func.isRequired,effectiveModelNormalize:g.default.func.isRequired,effectiveModelPreserveDeveloper:g.default.func.isRequired,saveModelCompatFlags:g.default.func.isRequired,compatSavingModelId:g.default.string,onModelsChanged:g.default.func},L.propTypes={until:g.default.string.isRequired};let R={runtime_error:{labelKey:"errorTypeRuntime",variant:"warning"},upstream_auth_error:{labelKey:"errorTypeUpstreamAuth",variant:"error"},auth_missing:{labelKey:"errorTypeMissingCredential",variant:"warning"},token_refresh_failed:{labelKey:"errorTypeRefreshFailed",variant:"warning"},token_expired:{labelKey:"errorTypeTokenExpired",variant:"warning"},upstream_rate_limited:{labelKey:"errorTypeRateLimited",variant:"warning"},upstream_unavailable:{labelKey:"errorTypeUpstreamUnavailable",variant:"error"},network_error:{labelKey:"errorTypeNetworkError",variant:"warning"},unsupported:{labelKey:"errorTypeTestUnsupported",variant:"default"},upstream_error:{labelKey:"errorTypeUpstreamError",variant:"error"}};function M({connection:a,isOAuth:b,isCodex:c,isFirst:f,isLast:g,onMoveUp:h,onMoveDown:i,onToggleActive:j,onToggleRateLimit:l,onToggleCodex5h:m,onToggleCodexWeekly:p,onRetest:q,isRetesting:r,onEdit:s,onDelete:t,onReauth:u,onProxy:w,hasProxy:x,proxySource:y,proxyHost:z,onRefreshToken:A,isRefreshing:B}){let C,E=(0,k.useTranslations)("providers"),F=b?a.name||a.email||a.displayName||E("oauthAccount"):a.name,[G,H]=(0,e.useState)(!1),[I,J]=(0,e.useState)(()=>{if(!b||!a.expiresAt)return null;let c=new Date(a.expiresAt).getTime();return Math.floor((c-Date.now())/6e4)});(0,e.useEffect)(()=>{if(!b||!a.expiresAt)return;let c=setInterval(()=>{let b=new Date(a.expiresAt).getTime();J(Math.floor((b-Date.now())/6e4))},3e4);return()=>clearInterval(c)},[b,a.expiresAt]),(0,e.useEffect)(()=>{let b=()=>{let b=a.rateLimitedUntil&&new Date(a.rateLimitedUntil).getTime()>Date.now();H(b)};b();let c=a.rateLimitedUntil?setInterval(b,1e3):null;return()=>{c&&clearInterval(c)}},[a.rateLimitedUntil]);let K="unavailable"!==a.testStatus||G?a.testStatus:"active",M=function(a,b,c,d){if(!1===a.isActive)return{statusVariant:"default",statusLabel:d("statusDisabled"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};if("active"===b||"success"===b)return{statusVariant:"success",statusLabel:d("statusConnected"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};let e=function(a,b){if(b)return"upstream_rate_limited";if(a.lastErrorType)return a.lastErrorType;let c=Number(a.errorCode);if(401===c||403===c)return"upstream_auth_error";if(429===c)return"upstream_rate_limited";if(c>=500)return"upstream_unavailable";let d=(a.lastError||"").toLowerCase();return d?d.includes("runtime")||d.includes("not runnable")||d.includes("not installed")||d.includes("healthcheck")?"runtime_error":d.includes("refresh failed")?"token_refresh_failed":d.includes("token expired")||d.includes("expired")?"token_expired":d.includes("invalid api key")||d.includes("token invalid")||d.includes("revoked")||d.includes("access denied")||d.includes("unauthorized")?"upstream_auth_error":d.includes("rate limit")||d.includes("quota")||d.includes("too many requests")||d.includes("429")?"upstream_rate_limited":d.includes("fetch failed")||d.includes("network")||d.includes("timeout")||d.includes("econn")||d.includes("enotfound")?"network_error":d.includes("not supported")?"unsupported":"upstream_error":null}(a,c),f=e&&R[e]||null;if("runtime_error"===e)return{statusVariant:"warning",statusLabel:d("statusRuntimeIssue"),errorType:e,errorBadge:f,errorTextClass:"text-yellow-600 dark:text-yellow-400"};if("upstream_auth_error"===e||"auth_missing"===e||"token_refresh_failed"===e||"token_expired"===e)return{statusVariant:"error",statusLabel:d("statusAuthFailed"),errorType:e,errorBadge:f,errorTextClass:"text-red-500"};if("upstream_rate_limited"===e)return{statusVariant:"warning",statusLabel:d("statusRateLimited"),errorType:e,errorBadge:f,errorTextClass:"text-yellow-600 dark:text-yellow-400"};if("network_error"===e)return{statusVariant:"warning",statusLabel:d("statusNetworkIssue"),errorType:e,errorBadge:f,errorTextClass:"text-yellow-600 dark:text-yellow-400"};if("unsupported"===e)return{statusVariant:"default",statusLabel:d("statusTestUnsupported"),errorType:e,errorBadge:f,errorTextClass:"text-text-muted"};let g={unavailable:d("statusUnavailable"),failed:d("statusFailed"),error:d("statusError")};return{statusVariant:"error",statusLabel:g[b]||b||d("statusError"),errorType:e,errorBadge:f,errorTextClass:"text-red-500"}}(a,K,G,E),N=!!a.rateLimitProtection,O=a.providerSpecificData&&"object"==typeof a.providerSpecificData&&a.providerSpecificData.codexLimitPolicy&&"object"==typeof a.providerSpecificData.codexLimitPolicy?a.providerSpecificData.codexLimitPolicy:{},P=D(O),Q=P.use5h,S=P.useWeekly;return(0,d.jsxs)("div",{className:`group flex items-center justify-between p-3 rounded-lg hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${!1===a.isActive?"opacity-60":""}`,children:[(0,d.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex flex-col",children:[(0,d.jsx)("button",{onClick:h,disabled:f,className:`p-0.5 rounded ${f?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,d.jsx)("button",{onClick:i,disabled:g,className:`p-0.5 rounded ${g?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:b?"lock":"key"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium truncate",children:F}),(0,d.jsxs)("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[(0,d.jsx)(o.Badge,{variant:M.statusVariant,size:"sm",dot:!0,children:M.statusLabel}),null!==I&&(I<0?(0,d.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-red-500/15 text-red-500",title:`Token expired: ${a.expiresAt}`,children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"error"}),"expired"]}):I<30?(0,d.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/15 text-amber-500",title:`Token expires in ${I}m`,children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"warning"}),`~${I}m`]}):null),G&&!1!==a.isActive&&(0,d.jsx)(L,{until:a.rateLimitedUntil}),M.errorBadge&&!1!==a.isActive&&(0,d.jsx)(o.Badge,{variant:M.errorBadge.variant,size:"sm",children:E(M.errorBadge.labelKey)}),a.lastError&&!1!==a.isActive&&(0,d.jsx)("span",{className:`text-xs truncate max-w-[300px] ${M.errorTextClass}`,title:a.lastError,children:a.lastError}),(0,d.jsxs)("span",{className:"text-xs text-text-muted",children:["#",a.priority]}),a.globalPriority&&(0,d.jsx)("span",{className:"text-xs text-text-muted",children:E("autoPriority",{priority:a.globalPriority})}),(0,d.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,d.jsxs)("button",{onClick:()=>l(!N),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${N?"bg-emerald-500/15 text-emerald-500 hover:bg-emerald-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:E(N?"disableRateLimitProtection":"enableRateLimitProtection"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"shield"}),E(N?"rateLimitProtected":"rateLimitUnprotected")]}),c&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,d.jsxs)("button",{onClick:()=>m?.(!Q),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${Q?"bg-blue-500/15 text-blue-500 hover:bg-blue-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex 5h limit policy",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"timer"}),"5h ",Q?"ON":"OFF"]}),(0,d.jsxs)("button",{onClick:()=>p?.(!S),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${S?"bg-violet-500/15 text-violet-500 hover:bg-violet-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex weekly limit policy",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"date_range"}),"Weekly ",S?"ON":"OFF"]})]}),x&&(C=E("global"===y?"proxySourceGlobal":"provider"===y?"proxySourceProvider":"proxySourceKey"),(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,d.jsxs)("span",{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium ${"global"===y?"bg-emerald-500/15 text-emerald-500":"provider"===y?"bg-amber-500/15 text-amber-500":"bg-blue-500/15 text-blue-500"}`,title:E("proxyConfiguredBySource",{source:C,host:z||E("configured")}),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"vpn_lock"}),z||E("proxy")]})]}))]})]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(n.Button,{size:"sm",variant:"ghost",icon:"refresh",loading:r,disabled:!1===a.isActive,onClick:q,className:"!h-7 !px-2 text-xs",title:E("retestAuthentication"),children:E("retest")}),A&&(0,d.jsx)(n.Button,{size:"sm",variant:"ghost",icon:"token",loading:B,disabled:!1===a.isActive||B,onClick:A,className:"!h-7 !px-2 text-xs text-amber-500 hover:text-amber-400",title:"Refresh OAuth token manually",children:"Token"}),(0,d.jsx)(v.Toggle,{size:"sm",checked:a.isActive??!0,onChange:j,title:E(a.isActive??!0?"disableConnection":"enableConnection")}),(0,d.jsxs)("div",{className:"flex gap-1 ml-1 transition-opacity",children:[u&&(0,d.jsx)("button",{onClick:u,className:"p-2 hover:bg-amber-500/10 rounded text-amber-600 hover:text-amber-500",title:E("reauthenticateConnection"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"passkey"})}),(0,d.jsx)("button",{onClick:s,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:E("edit"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),(0,d.jsx)("button",{onClick:w,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:E("proxyConfig"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"vpn_lock"})}),(0,d.jsx)("button",{onClick:t,className:"p-2 hover:bg-red-500/10 rounded text-red-500",title:E("delete"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]})]})}function N({isOpen:a,provider:b,providerName:c,isCompatible:f,isAnthropic:g,onSave:h,onClose:i}){let j=(0,k.useTranslations)("providers"),l="bailian-coding-plan"===b,m="https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1",[r,s]=(0,e.useState)({name:"",apiKey:"",priority:1,baseUrl:l?m:""}),[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(null),[x,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(null),B=async()=>{u(!0),A(null);try{let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b,apiKey:r.apiKey})}),c=await a.json();w(c.valid?"success":"failed")}catch{w("failed")}finally{u(!1)}},C=async()=>{if(b&&r.apiKey){y(!0),A(null);try{let a=null;if(l){let b=O(r.baseUrl,m);if(b.error)return void A(b.error);a=b.value}let c=!1;try{u(!0),w(null);let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b,apiKey:r.apiKey})});c=!!(await a.json()).valid,w(c?"success":"failed")}catch{w("failed")}finally{u(!1)}if(!c)return void A(j("apiKeyValidationFailed"));let d={name:r.name,apiKey:r.apiKey,priority:r.priority,testStatus:"active",providerSpecificData:void 0};l&&(d.providerSpecificData={baseUrl:a});let e=await h(d);e&&A("string"==typeof e?e:j("failedSaveConnection"))}finally{y(!1)}}};return b?(0,d.jsx)(q.Modal,{isOpen:a,title:j("addProviderApiKeyTitle",{provider:c||b}),onClose:i,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)(p.Input,{label:j("nameLabel"),value:r.name,onChange:a=>s({...r,name:a.target.value}),placeholder:j("productionKey")}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(p.Input,{label:j("apiKeyLabel"),type:"password",value:r.apiKey,onChange:a=>s({...r,apiKey:a.target.value}),className:"flex-1"}),(0,d.jsx)("div",{className:"pt-6",children:(0,d.jsx)(n.Button,{onClick:B,disabled:!r.apiKey||t||x,variant:"secondary",children:t?j("checking"):j("check")})})]}),v&&(0,d.jsx)(o.Badge,{variant:"success"===v?"success":"error",children:"success"===v?j("valid"):j("invalid")}),z&&(0,d.jsx)("div",{className:"text-sm text-red-500 bg-red-500/10 border border-red-500/20 rounded-lg px-3 py-2",children:z}),f&&(0,d.jsx)("p",{className:"text-xs text-text-muted",children:g?j("validationChecksAnthropicCompatible",{provider:c||j("anthropicCompatibleName")}):j("validationChecksOpenAiCompatible",{provider:c||j("openaiCompatibleName")})}),(0,d.jsx)(p.Input,{label:j("priorityLabel"),type:"number",value:r.priority,onChange:a=>s({...r,priority:Number.parseInt(a.target.value)||1})}),l&&(0,d.jsx)(p.Input,{label:"Base URL",value:r.baseUrl,onChange:a=>s({...r,baseUrl:a.target.value}),placeholder:m,hint:"Optional: Custom base URL for bailian-coding-plan provider"}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(n.Button,{onClick:C,fullWidth:!0,disabled:!r.name||!r.apiKey||x,children:x?j("saving"):j("save")}),(0,d.jsx)(n.Button,{onClick:i,variant:"ghost",fullWidth:!0,children:j("cancel")})]})]})}):null}function O(a,b){let c=("string"==typeof a?a.trim():"")||b;try{let a=new URL(c);if("http:"!==a.protocol&&"https:"!==a.protocol)return{value:null,error:"Base URL must use http or https"};return{value:c,error:null}}catch{return{value:null,error:"Base URL must be a valid URL"}}}function P({isOpen:a,connection:b,onSave:c,onClose:f}){let g=(0,k.useTranslations)("providers"),[h,i]=(0,e.useState)({name:"",priority:1,apiKey:"",healthCheckInterval:60,baseUrl:""}),[j,l]=(0,e.useState)(!1),[m,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(!1),[z,A]=(0,e.useState)(null),[B,C]=(0,e.useState)([]),[D,E]=(0,e.useState)(""),F=b?.provider==="bailian-coding-plan",G="https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1";(0,e.useEffect)(()=>{if(b){let a=b.providerSpecificData?.baseUrl;i({name:b.name||"",priority:b.priority||1,apiKey:"",healthCheckInterval:b.healthCheckInterval??60,baseUrl:a||(F?G:"")});let c=b.providerSpecificData?.extraApiKeys;C(Array.isArray(c)?c:[]),E(""),r(null),v(null),A(null)}},[b,F]);let H=async()=>{if(b?.provider){l(!0),r(null);try{let a=await fetch(`/api/providers/${b.id}/test`,{method:"POST"}),c=await a.json();r({valid:!!c.valid,diagnosis:c.diagnosis||null,message:c.error||null})}catch{r({valid:!1,diagnosis:{type:"network_error"},message:g("failedTestConnection")})}finally{l(!1)}}},I=async()=>{if(b?.provider&&h.apiKey){t(!0),v(null);try{let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b.provider,apiKey:h.apiKey})}),c=await a.json();v(c.valid?"success":"failed")}catch{v("failed")}finally{t(!1)}}},J=async()=>{x(!0),A(null);try{let a={name:h.name,priority:h.priority,healthCheckInterval:h.healthCheckInterval},d=null;if(F){let a=O(h.baseUrl,G);if(a.error)return void A(a.error);d=a.value}if(!K&&h.apiKey){a.apiKey=h.apiKey;let c="success"===u;if(!c)try{t(!0),v(null);let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b.provider,apiKey:h.apiKey})});c=!!(await a.json()).valid,v(c?"success":"failed")}catch{v("failed")}finally{t(!1)}c&&(a.testStatus="active",a.lastError=null,a.lastErrorAt=null,a.lastErrorType=null,a.lastErrorSource=null,a.errorCode=null,a.rateLimitedUntil=null)}!K&&(a.providerSpecificData={...b.providerSpecificData||{},extraApiKeys:B.filter(a=>a.trim().length>0)},F&&(a.providerSpecificData.baseUrl=d));let e=await c(a);e&&A("string"==typeof e?e:g("failedSaveConnection"))}finally{x(!1)}};if(!b)return null;let K="oauth"===b.authType,L=(0,y.isOpenAICompatibleProvider)(b.provider)||(0,y.isAnthropicCompatibleProvider)(b.provider),M=!m?.valid&&m?.diagnosis?.type&&R[m.diagnosis.type]||null;return(0,d.jsx)(q.Modal,{isOpen:a,title:g("editConnection"),onClose:f,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)(p.Input,{label:g("nameLabel"),value:h.name,onChange:a=>i({...h,name:a.target.value}),placeholder:K?g("accountName"):g("productionKey")}),K&&b.email&&(0,d.jsxs)("div",{className:"bg-sidebar/50 p-3 rounded-lg",children:[(0,d.jsx)("p",{className:"text-sm text-text-muted mb-1",children:g("email")}),(0,d.jsx)("p",{className:"font-medium",children:b.email})]}),K&&(0,d.jsx)(p.Input,{label:g("healthCheckMinutes"),type:"number",value:h.healthCheckInterval,onChange:a=>i({...h,healthCheckInterval:Math.max(0,Number.parseInt(a.target.value)||0)}),hint:g("healthCheckHint")}),(0,d.jsx)(p.Input,{label:g("priorityLabel"),type:"number",value:h.priority,onChange:a=>i({...h,priority:Number.parseInt(a.target.value)||1})}),!K&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(p.Input,{label:g("apiKeyLabel"),type:"password",value:h.apiKey,onChange:a=>i({...h,apiKey:a.target.value}),placeholder:g("enterNewApiKey"),hint:g("leaveBlankKeepCurrentApiKey"),className:"flex-1"}),(0,d.jsx)("div",{className:"pt-6",children:(0,d.jsx)(n.Button,{onClick:I,disabled:!h.apiKey||s||w,variant:"secondary",children:s?g("checking"):g("check")})})]}),u&&(0,d.jsx)(o.Badge,{variant:"success"===u?"success":"error",children:"success"===u?g("valid"):g("invalid")}),z&&(0,d.jsx)("div",{className:"text-sm text-red-500 bg-red-500/10 border border-red-500/20 rounded-lg px-3 py-2",children:z})]}),F&&(0,d.jsx)(p.Input,{label:"Base URL",value:h.baseUrl,onChange:a=>i({...h,baseUrl:a.target.value}),placeholder:G,hint:"Custom base URL for bailian-coding-plan provider"}),!K&&(0,d.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,d.jsxs)("label",{className:"text-sm font-medium text-text-main",children:["Extra API Keys",(0,d.jsx)("span",{className:"ml-2 text-[11px] font-normal text-text-muted",children:"(round-robin rotation — optional)"})]}),B.length>0&&(0,d.jsx)("div",{className:"flex flex-col gap-1.5",children:B.map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"flex-1 font-mono text-xs bg-sidebar/50 px-3 py-2 rounded border border-border text-text-muted truncate",children:`Key #${b+2}: ${a.slice(0,6)}...${a.slice(-4)}`}),(0,d.jsx)("button",{onClick:()=>C(B.filter((a,c)=>c!==b)),className:"p-1.5 rounded hover:bg-red-500/10 text-red-400 hover:text-red-500",title:"Remove this key",children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},b))}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)("input",{type:"password",value:D,onChange:a=>E(a.target.value),placeholder:"Add another API key...",className:"flex-1 text-sm bg-sidebar/50 border border-border rounded px-3 py-2 text-text-main placeholder:text-text-muted focus:ring-1 focus:ring-primary outline-none",onKeyDown:a=>{"Enter"===a.key&&D.trim()&&(C([...B,D.trim()]),E(""))}}),(0,d.jsx)("button",{onClick:()=>{D.trim()&&(C([...B,D.trim()]),E(""))},disabled:!D.trim(),className:"px-3 py-2 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40 text-sm font-medium",children:"Add"})]}),B.length>0&&(0,d.jsxs)("p",{className:"text-[11px] text-text-muted",children:[B.length+1," keys total — rotating round-robin on each request."]})]}),!L&&(0,d.jsxs)("div",{className:"flex items-center gap-3",children:[(0,d.jsx)(n.Button,{onClick:H,variant:"secondary",disabled:j,children:j?g("testing"):g("testConnection")}),m&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.Badge,{variant:m.valid?"success":"error",children:m.valid?g("valid"):g("failed")}),M&&(0,d.jsx)(o.Badge,{variant:M.variant,children:g(M.labelKey)})]})]}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(n.Button,{onClick:J,fullWidth:!0,disabled:w,children:w?g("saving"):g("save")}),(0,d.jsx)(n.Button,{onClick:f,variant:"ghost",fullWidth:!0,children:g("cancel")})]})]})})}function Q({isOpen:a,node:b,onSave:c,onClose:f,isAnthropic:g}){let h=(0,k.useTranslations)("providers"),[i,j]=(0,e.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1",chatPath:"",modelsPath:""}),[l,m]=(0,e.useState)(!1),[r,s]=(0,e.useState)(""),[t,u]=(0,e.useState)(!1),[v,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(!1);(0,e.useEffect)(()=>{b&&(j({name:b.name||"",prefix:b.prefix||"",apiType:b.apiType||"chat",baseUrl:b.baseUrl||(g?"https://api.anthropic.com/v1":"https://api.openai.com/v1"),chatPath:b.chatPath||"",modelsPath:b.modelsPath||""}),z(!!(b.chatPath||b.modelsPath)))},[b,g]);let A=[{value:"chat",label:h("chatCompletions")},{value:"responses",label:h("responsesApi")}],B=async()=>{if(i.name.trim()&&i.prefix.trim()&&i.baseUrl.trim()){m(!0);try{let a={name:i.name,prefix:i.prefix,baseUrl:i.baseUrl,chatPath:i.chatPath||"",modelsPath:i.modelsPath||""};g||(a.apiType=i.apiType),await c(a)}finally{m(!1)}}},C=async()=>{u(!0);try{let a=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:i.baseUrl,apiKey:r,type:g?"anthropic-compatible":"openai-compatible",modelsPath:i.modelsPath||""})}),b=await a.json();x(b.valid?"success":"failed")}catch{x("failed")}finally{u(!1)}};return b?(0,d.jsx)(q.Modal,{isOpen:a,title:h("editCompatibleTitle",{type:h(g?"anthropic":"openai")}),onClose:f,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)(p.Input,{label:h("nameLabel"),value:i.name,onChange:a=>j({...i,name:a.target.value}),placeholder:h("compatibleProdPlaceholder",{type:h(g?"anthropic":"openai")}),hint:h("nameHint")}),(0,d.jsx)(p.Input,{label:h("prefixLabel"),value:i.prefix,onChange:a=>j({...i,prefix:a.target.value}),placeholder:h(g?"anthropicPrefixPlaceholder":"openaiPrefixPlaceholder"),hint:h("prefixHint")}),!g&&(0,d.jsx)(w.Select,{label:h("apiTypeLabel"),options:A,value:i.apiType,onChange:a=>j({...i,apiType:a.target.value})}),(0,d.jsx)(p.Input,{label:h("baseUrlLabel"),value:i.baseUrl,onChange:a=>j({...i,baseUrl:a.target.value}),placeholder:h(g?"anthropicBaseUrlPlaceholder":"openaiBaseUrlPlaceholder"),hint:h("compatibleBaseUrlHint",{type:h(g?"anthropic":"openai")})}),(0,d.jsxs)("button",{type:"button",className:"text-sm text-text-muted hover:text-text-primary flex items-center gap-1",onClick:()=>z(!y),"aria-expanded":y,"aria-controls":"advanced-settings",children:[(0,d.jsx)("span",{className:`transition-transform ${y?"rotate-90":""}`,"aria-hidden":"true",children:"▶"}),h("advancedSettings")]}),y&&(0,d.jsxs)("div",{id:"advanced-settings",className:"flex flex-col gap-3 pl-2 border-l-2 border-border",children:[(0,d.jsx)(p.Input,{label:h("chatPathLabel"),value:i.chatPath,onChange:a=>j({...i,chatPath:a.target.value}),placeholder:g?"/messages":h("chatPathPlaceholder"),hint:h("chatPathHint")}),(0,d.jsx)(p.Input,{label:h("modelsPathLabel"),value:i.modelsPath,onChange:a=>j({...i,modelsPath:a.target.value}),placeholder:h("modelsPathPlaceholder"),hint:h("modelsPathHint")})]}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(p.Input,{label:h("apiKeyForCheck"),type:"password",value:r,onChange:a=>s(a.target.value),className:"flex-1"}),(0,d.jsx)("div",{className:"pt-6",children:(0,d.jsx)(n.Button,{onClick:C,disabled:!r||t||!i.baseUrl.trim(),variant:"secondary",children:h(t?"checking":"check")})})]}),v&&(0,d.jsx)(o.Badge,{variant:"success"===v?"success":"error",children:h("success"===v?"valid":"invalid")}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(n.Button,{onClick:B,fullWidth:!0,disabled:!i.name.trim()||!i.prefix.trim()||!i.baseUrl.trim()||l,children:h(l?"saving":"save")}),(0,d.jsx)(n.Button,{onClick:f,variant:"ghost",fullWidth:!0,children:h("cancel")})]})]})}):null}M.propTypes={connection:g.default.shape({id:g.default.string,name:g.default.string,email:g.default.string,displayName:g.default.string,rateLimitedUntil:g.default.string,rateLimitProtection:g.default.bool,testStatus:g.default.string,isActive:g.default.bool,priority:g.default.number,lastError:g.default.string,lastErrorType:g.default.string,lastErrorSource:g.default.string,errorCode:g.default.oneOfType([g.default.string,g.default.number]),globalPriority:g.default.number,providerSpecificData:g.default.object}).isRequired,isOAuth:g.default.bool.isRequired,isCodex:g.default.bool,isFirst:g.default.bool.isRequired,isLast:g.default.bool.isRequired,onMoveUp:g.default.func.isRequired,onMoveDown:g.default.func.isRequired,onToggleActive:g.default.func.isRequired,onToggleRateLimit:g.default.func.isRequired,onToggleCodex5h:g.default.func,onToggleCodexWeekly:g.default.func,onRetest:g.default.func.isRequired,isRetesting:g.default.bool,onEdit:g.default.func.isRequired,onDelete:g.default.func.isRequired,onReauth:g.default.func},N.propTypes={isOpen:g.default.bool.isRequired,provider:g.default.string,providerName:g.default.string,isCompatible:g.default.bool,isAnthropic:g.default.bool,onSave:g.default.func.isRequired,onClose:g.default.func.isRequired},P.propTypes={isOpen:g.default.bool.isRequired,connection:g.default.shape({id:g.default.string,name:g.default.string,email:g.default.string,priority:g.default.number,authType:g.default.string,provider:g.default.string}),onSave:g.default.func.isRequired,onClose:g.default.func.isRequired},Q.propTypes={isOpen:g.default.bool.isRequired,node:g.default.shape({id:g.default.string,name:g.default.string,prefix:g.default.string,apiType:g.default.string,baseUrl:g.default.string,chatPath:g.default.string,modelsPath:g.default.string}),onSave:g.default.func.isRequired,onClose:g.default.func.isRequired,isAnthropic:g.default.bool},a.s(["default",()=>F]),c()}catch(a){c(a)}},!1)];
|
|
1
|
+
module.exports=[779276,a=>{"use strict";var b=a.i(743442);a.s(["OAuthModal",()=>b.default])},202373,a=>{"use strict";var b=a.i(394093);a.s(["KiroOAuthWrapper",()=>b.default])},182527,a=>{"use strict";var b=a.i(296193);a.s(["CursorAuthModal",()=>b.default])},755235,a=>a.a(async(b,c)=>{try{var d=a.i(187924),e=a.i(572131),f=a.i(240246),g=a.i(341212),h=a.i(50944),i=a.i(238246),j=a.i(571987),k=a.i(415925),l=a.i(442308),m=a.i(292216),n=a.i(294023),o=a.i(818465),p=a.i(489108),q=a.i(563203),r=a.i(831097),s=a.i(779276),t=a.i(202373),u=a.i(182527),v=a.i(709918),w=a.i(525290),x=a.i(248172),y=a.i(662073),z=a.i(867933),A=a.i(911655),B=a.i(386592),C=b([l,y,z]);function D(a){let b=a&&"object"==typeof a&&!Array.isArray(a)?a:{};return{use5h:"boolean"!=typeof b.use5h||b.use5h,useWeekly:"boolean"!=typeof b.useWeekly||b.useWeekly}}function E({t:a,normalizeToolCallId:b,preserveDeveloperRole:c,showDeveloperToggle:f=!0,onNormalizeChange:g,onPreserveChange:h,disabled:i}){let[j,k]=(0,e.useState)(!1),l=(0,e.useRef)(null);return(0,e.useEffect)(()=>{if(!j)return;let a=a=>{l.current&&!l.current.contains(a.target)&&k(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[j]),(0,d.jsxs)("div",{className:"relative inline-block",ref:l,children:[(0,d.jsxs)("button",{type:"button",onClick:()=>k(a=>!a),disabled:i,className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md border border-border bg-sidebar/50 hover:bg-sidebar text-text-muted hover:text-text-main disabled:opacity-50",title:a("compatAdjustmentsTitle"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"tune"}),a("compatButtonLabel")]}),j&&(0,d.jsxs)("div",{className:"absolute left-0 top-full mt-1 z-50 min-w-[200px] p-3 rounded-lg border border-border bg-white dark:bg-zinc-900 shadow-xl ring-1 ring-black/5 dark:ring-white/10",children:[(0,d.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-text-muted mb-2",children:a("compatAdjustmentsTitle")}),(0,d.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,d.jsx)(v.Toggle,{size:"sm",label:a("compatToolIdShort"),title:a("normalizeToolCallIdLabel"),checked:b,onChange:g,disabled:i}),f&&(0,d.jsx)(v.Toggle,{size:"sm",label:a("compatDoNotPreserveDeveloper"),title:a("preserveDeveloperRoleLabel"),checked:!1===c,onChange:a=>h(!a),disabled:i})]})]})]})}function F(){let a=(0,h.useParams)(),b=(0,h.useRouter)(),c=a.id,[g,l]=(0,e.useState)([]),[o,p]=(0,e.useState)(!0),[v,w]=(0,e.useState)(null),[z,C]=(0,e.useState)(!1),[E,F]=(0,e.useState)(!1),[I,L]=(0,e.useState)(!1),[O,R]=(0,e.useState)(!1),[S,T]=(0,e.useState)(null),[U,V]=(0,e.useState)(null),[W,X]=(0,e.useState)(!1),[Y,Z]=(0,e.useState)(null),[$,_]=(0,e.useState)({}),[aa,ab]=(0,e.useState)(!1),{copied:ac,copy:ad}=(0,B.useCopyToClipboard)(),ae=(0,k.useTranslations)("providers"),af=(0,f.useNotificationStore)(),ag=(0,e.useRef)(!1),ah=(0,e.useRef)(!1),[ai,aj]=(0,e.useState)(null),[ak,al]=(0,e.useState)(null),[am,an]=(0,e.useState)(!1),[ao,ap]=(0,e.useState)(!1),[aq,ar]=(0,e.useState)({current:0,total:0,phase:"idle",status:"",logs:[],error:"",importedCount:0}),[as,at]=(0,e.useState)({customModels:[],modelCompatOverrides:[]}),[au,av]=(0,e.useState)(null),aw=v?{id:v.id,name:v.name||("anthropic-compatible"===v.type?ae("anthropicCompatibleName"):ae("openaiCompatibleName")),color:"anthropic-compatible"===v.type?"#D97757":"#10A37F",textIcon:"anthropic-compatible"===v.type?"AC":"OC",apiType:v.apiType,baseUrl:v.baseUrl,type:v.type}:y.FREE_PROVIDERS[c]||y.OAUTH_PROVIDERS[c]||y.APIKEY_PROVIDERS[c],ax=!!y.FREE_PROVIDERS[c]||!!y.OAUTH_PROVIDERS[c],ay=(0,A.getModelsByProviderId)(c),az=(0,y.getProviderAlias)(c),aA=(0,y.isOpenAICompatibleProvider)(c),aB=(0,y.isAnthropicCompatibleProvider)(c),aC=aA||aB,aD=c.endsWith("-search"),aE=aC?c:az,aF=aC?v?.prefix||c:az,aG=(0,e.useCallback)(async()=>{try{let a=await fetch("/api/models/alias"),b=await a.json();a.ok&&_(b.aliases||{})}catch(a){console.log("Error fetching aliases:",a)}},[]),aH=(0,e.useCallback)(async()=>{if(!aD)try{let a=await fetch(`/api/provider-models?provider=${encodeURIComponent(c)}`,{cache:"no-store"});if(!a.ok)return;let b=await a.json();at({customModels:b.models||[],modelCompatOverrides:b.modelCompatOverrides||[]})}catch(a){console.error("fetchProviderModelMeta",a)}},[c,aD]),aI=(0,e.useCallback)(async()=>{try{let[a,b]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/provider-nodes",{cache:"no-store"})]),d=await a.json(),e=await b.json();if(a.ok){let a=(d.connections||[]).filter(a=>a.provider===c);l(a)}if(b.ok){let a=(e.nodes||[]).find(a=>a.id===c)||null;if(!a&&aC)for(let b=0;b<3;b+=1){await new Promise(a=>setTimeout(a,150));let b=await fetch("/api/provider-nodes",{cache:"no-store"});if(b.ok&&(a=((await b.json()).nodes||[]).find(a=>a.id===c)||null))break}w(a)}}catch(a){console.log("Error fetching connections:",a)}finally{p(!1)}},[c,aC]),aJ=async a=>{try{let b=await fetch(`/api/provider-nodes/${c}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),d=await b.json();b.ok&&(w(d.node),await aI(),R(!1))}catch(a){console.log("Error updating provider node:",a)}};(0,e.useEffect)(()=>{aI(),aG(),fetch("/api/settings/proxy").then(a=>a.ok?a.json():null).then(a=>al(a)).catch(()=>{})},[aI,aG]),(0,e.useEffect)(()=>{o||aD||aH()},[o,aD,aH]),(0,e.useEffect)(()=>{o||0!==g.length||!aw||aC||ag.current||ah.current||(ag.current=!0,ax?C(!0):F(!0))},[o]);let aK=async(a,b,c=az)=>{let d=`${c}/${a}`;try{let a=await fetch("/api/models/alias",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:d,alias:b})});if(a.ok)await aG();else{let b=await a.json();alert(b.error||ae("failedSetAlias"))}}catch(a){console.log("Error setting alias:",a)}},aL=async a=>{try{(await fetch(`/api/models/alias?alias=${encodeURIComponent(a)}`,{method:"DELETE"})).ok&&await aG()}catch(a){console.log("Error deleting alias:",a)}},aM=async a=>{if(confirm(ae("deleteConnectionConfirm")))try{(await fetch(`/api/providers/${a}`,{method:"DELETE"})).ok&&l(g.filter(b=>b.id!==a))}catch(a){console.log("Error deleting connection:",a)}},aN=(0,e.useCallback)(()=>{aI(),C(!1)},[aI]),aO=async a=>{try{let b=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,...a})});if(b.ok)return await aI(),F(!1),null;let d=await b.json().catch(()=>({}));return d.error?.message||d.error||ae("failedSaveConnection")}catch(a){return console.log("Error saving connection:",a),ae("failedSaveConnectionRetry")}},aP=async a=>{try{let b=await fetch(`/api/providers/${S.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(b.ok)return await aI(),L(!1),null;let c=await b.json().catch(()=>({}));return c.error?.message||c.error||ae("failedSaveConnection")}catch(a){return console.log("Error updating connection:",a),ae("failedSaveConnectionRetry")}},aQ=async(a,b)=>{try{(await fetch(`/api/providers/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:b})})).ok&&l(c=>c.map(c=>c.id===a?{...c,isActive:b}:c))}catch(a){console.log("Error updating connection status:",a)}},aR=async(a,b)=>{try{(await fetch("/api/rate-limits",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({connectionId:a,enabled:b})})).ok&&l(c=>c.map(c=>c.id===a?{...c,rateLimitProtection:b}:c))}catch(a){console.error("Error toggling rate limit:",a)}},aS=async(a,b,c)=>{try{let d=g.find(b=>b.id===a);if(!d)return;let e=d.providerSpecificData&&"object"==typeof d.providerSpecificData?d.providerSpecificData:{},f=e.codexLimitPolicy&&"object"==typeof e.codexLimitPolicy?e.codexLimitPolicy:{},h={...D(f),[b]:c},i=await fetch(`/api/providers/${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerSpecificData:{...e,codexLimitPolicy:h}})});if(!i.ok){let a=await i.json().catch(()=>({}));af.error(a.error||"Failed to update Codex limit policy");return}l(b=>b.map(b=>b.id===a?{...b,providerSpecificData:{...b.providerSpecificData||{},codexLimitPolicy:h}}:b)),af.success("Codex limit policy updated")}catch(a){console.error("Error toggling Codex quota policy:",a),af.error("Failed to update Codex limit policy")}},aT=async a=>{if(a&&!U){V(a);try{let b=await fetch(`/api/providers/${a}/test`,{method:"POST"});if(!b.ok){let a=await b.json().catch(()=>({}));alert(a.error||ae("failedRetestConnection"));return}await aI()}catch(a){console.error("Error retesting connection:",a)}finally{V(null)}}},aU=async()=>{if(W||0===g.length)return;X(!0),Z(null);let a=new AbortController,b=setTimeout(()=>a.abort(),12e4);try{let b,d=await fetch("/api/providers/test-batch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"provider",providerId:c}),signal:a.signal});try{b=await d.json()}catch{b={error:ae("providerTestFailed"),results:[],summary:null}}if(Z({...b,error:b.error?"object"==typeof b.error?b.error.message||b.error.error||JSON.stringify(b.error):String(b.error):null}),b?.summary){let{passed:a,failed:c,total:d}=b.summary;0===c?af.success(ae("allTestsPassed",{total:d})):af.warning(ae("testSummary",{passed:a,failed:c,total:d}))}await aI()}catch(b){let a=b?.name==="AbortError"?ae("providerTestTimeout"):ae("providerTestFailed");Z({error:a,results:[],summary:null}),af.error(a)}finally{clearTimeout(b),X(!1)}},[aV,aW]=(0,e.useState)(null),aX=async a=>{if(!aV){aW(a);try{let b=await fetch(`/api/providers/${a}/refresh`,{method:"POST"}),c=await b.json().catch(()=>({}));b.ok&&c.success?(af.success(ae("tokenRefreshed")),await aI()):af.error(c.error||ae("tokenRefreshFailed"))}catch(a){console.error("Error refreshing token:",a),af.error(ae("tokenRefreshFailed"))}finally{aW(null)}}},aY=async(a,b)=>{if(a&&b)try{let c=b.priority,d=a.priority;c===d&&(c=g.indexOf(a)>g.indexOf(b)?b.priority-.5:b.priority+.5),await Promise.all([fetch(`/api/providers/${a.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:c})}),fetch(`/api/providers/${b.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:d})})]),await aI()}catch(a){console.log("Error swapping priority:",a)}},aZ=async()=>{if(am)return;let a=g.find(a=>!1!==a.isActive);if(a){an(!0),ap(!0),ar({current:0,total:0,phase:"fetching",status:ae("fetchingModels"),logs:[],error:"",importedCount:0});try{let b=await fetch(`/api/providers/${a.id}/models`),d=await b.json();if(!b.ok)return void ar(a=>({...a,phase:"error",status:ae("failedFetchModels"),error:d.error||ae("failedImportModels")}));let e=d.models||[];if(0===e.length)return void ar(a=>({...a,phase:"done",status:ae("noModelsFound"),logs:[ae("noModelsReturnedFromEndpoint")]}));ar(a=>({...a,phase:"importing",total:e.length,status:ae("importingModelsProgress",{current:0,total:e.length}),logs:[ae("foundModelsStartingImport",{count:e.length})]}));let f=0;for(let a=0;a<e.length;a++){let b=e[a],d=b.id||b.name||b.model;if(!d)continue;let g=d.split("/"),h=g[g.length-1];ar(b=>({...b,current:a+1,status:ae("importingModelsProgress",{current:a+1,total:e.length}),logs:[...b.logs,ae("importingModelById",{modelId:d})]})),await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,modelId:d,modelName:b.name||d,source:"imported"})}),$[h]||await aK(d,h,aE),f+=1}await aG(),ar(a=>({...a,phase:"done",current:e.length,status:f>0?ae("importSuccessCount",{count:f}):ae("noNewModelsAddedExisting"),logs:[...a.logs,f>0?ae("importDoneCount",{count:f}):ae("noNewModelsAdded")],importedCount:f})),f>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(a){console.log("Error importing models:",a),ar(b=>({...b,phase:"error",status:ae("importFailed"),error:a instanceof Error?a.message:ae("unexpectedErrorOccurred")}))}finally{an(!1)}}},a$=async(a,b)=>{ap(!0),ar({current:0,total:0,phase:"fetching",status:ae("fetchingModels"),logs:[],error:"",importedCount:0});try{let c=(await a()).models||[];if(0===c.length)return void ar(a=>({...a,phase:"done",status:ae("noModelsFound"),logs:[ae("noModelsReturnedFromEndpoint")]}));ar(a=>({...a,phase:"importing",total:c.length,status:ae("importingModelsProgress",{current:0,total:c.length}),logs:[ae("foundModelsStartingImport",{count:c.length})]}));let d=0;for(let a=0;a<c.length;a++){let e=c[a],f=e.id||e.name||e.model;f&&(ar(b=>({...b,current:a+1,status:ae("importingModelsProgress",{current:a+1,total:c.length}),logs:[...b.logs,ae("importingModelById",{modelId:f})]})),await b(e)&&(d+=1))}ar(a=>({...a,phase:"done",current:c.length,status:d>0?ae("importSuccessCount",{count:d}):ae("noNewModelsAdded"),logs:[...a.logs,d>0?ae("importDoneCount",{count:d}):ae("noNewModelsAdded")],importedCount:d})),d>0&&setTimeout(()=>{window.location.reload()},2e3)}catch(a){console.log("Error importing models:",a),ar(b=>({...b,phase:"error",status:ae("importFailed"),error:a instanceof Error?a.message:ae("unexpectedErrorOccurred")}))}},a_=g.some(a=>!1!==a.isActive),a0=a=>{let b=as.customModels.find(b=>b.id===a);if(b)return!!b.normalizeToolCallId;let c=as.modelCompatOverrides.find(b=>b.id===a);return!!c?.normalizeToolCallId},a1=a=>{let b=as.customModels.find(b=>b.id===a);if(b&&Object.prototype.hasOwnProperty.call(b,"preserveOpenAIDeveloperRole"))return!!b.preserveOpenAIDeveloperRole;let c=as.modelCompatOverrides.find(b=>b.id===a);return!(c&&Object.prototype.hasOwnProperty.call(c,"preserveOpenAIDeveloperRole"))||!!c.preserveOpenAIDeveloperRole},a2=async(a,b)=>{av(a);try{let d,e=as.customModels.find(b=>b.id===a);d=e?{provider:c,modelId:a,modelName:e.name||a,source:e.source||"manual",apiFormat:e.apiFormat||"chat-completions",supportedEndpoints:Array.isArray(e.supportedEndpoints)&&e.supportedEndpoints.length?e.supportedEndpoints:["chat"],normalizeToolCallId:void 0!==b.normalizeToolCallId?b.normalizeToolCallId:!!e.normalizeToolCallId,preserveOpenAIDeveloperRole:void 0!==b.preserveOpenAIDeveloperRole?b.preserveOpenAIDeveloperRole:!Object.prototype.hasOwnProperty.call(e,"preserveOpenAIDeveloperRole")||!!e.preserveOpenAIDeveloperRole}:{provider:c,modelId:a,...b},(await fetch("/api/provider-models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})).ok?await aH():af.error(ae("failedSaveCustomModel"))}catch{af.error(ae("failedSaveCustomModel"))}finally{av(null)}};return o?(0,d.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,d.jsx)(r.CardSkeleton,{}),(0,d.jsx)(r.CardSkeleton,{})]}):aw?(0,d.jsxs)("div",{className:"flex flex-col gap-8",children:[(0,d.jsxs)("div",{children:[(0,d.jsxs)(i.default,{href:"/dashboard/providers",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary transition-colors mb-4",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-lg",children:"arrow_back"}),ae("backToProviders")]}),(0,d.jsxs)("div",{className:"flex items-center gap-4",children:[(0,d.jsx)("div",{className:"rounded-lg flex items-center justify-center",style:{backgroundColor:`${aw.color}15`},children:aa?(0,d.jsx)("span",{className:"text-sm font-bold",style:{color:aw.color},children:aw.textIcon||aw.id.slice(0,2).toUpperCase()}):(0,d.jsx)(j.default,{src:aA&&aw.apiType?"responses"===aw.apiType?"/providers/oai-r.png":"/providers/oai-cc.png":aB?"/providers/anthropic-m.png":`/providers/${aw.id}.png`,alt:aw.name,width:48,height:48,className:"object-contain rounded-lg max-w-[48px] max-h-[48px]",sizes:"48px",onError:()=>ab(!0)})}),(0,d.jsxs)("div",{children:[aw.website?(0,d.jsxs)("a",{href:aw.website,target:"_blank",rel:"noopener noreferrer",className:"text-3xl font-semibold tracking-tight hover:underline inline-flex items-center gap-2",style:{color:aw.color},children:[aw.name,(0,d.jsx)("span",{className:"material-symbols-outlined text-lg opacity-60",children:"open_in_new"})]}):(0,d.jsx)("h1",{className:"text-3xl font-semibold tracking-tight",children:aw.name}),(0,d.jsx)("p",{className:"text-text-muted",children:ae("connectionCountLabel",{count:g.length})})]})]})]}),aC&&v&&(0,d.jsxs)(m.Card,{children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:aB?ae("anthropicCompatibleDetails"):ae("openaiCompatibleDetails")}),(0,d.jsxs)("p",{className:"text-sm text-text-muted",children:[aB?ae("messagesApi"):"responses"===v.apiType?ae("responsesApi"):ae("chatCompletions")," ","· ",(v.baseUrl||"").replace(/\/$/,""),"/",aB?ae("messagesPath"):"responses"===v.apiType?ae("responsesPath"):ae("chatCompletionsPath")]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:()=>F(!0),disabled:g.length>0,children:ae("add")}),(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"edit",onClick:()=>R(!0),children:ae("edit")}),(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"delete",onClick:async()=>{if(confirm(ae("deleteCompatibleNodeConfirm",{type:aB?ae("anthropic"):ae("openai")})))try{(await fetch(`/api/provider-nodes/${c}`,{method:"DELETE"})).ok&&b.push("/dashboard/providers")}catch(a){console.log("Error deleting provider node:",a)}},children:ae("delete")})]})]}),g.length>0&&(0,d.jsx)("p",{className:"text-sm text-text-muted",children:ae("singleConnectionPerCompatible")})]}),(0,d.jsxs)(m.Card,{children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-3",children:[(0,d.jsx)("h2",{className:"text-lg font-semibold",children:ae("connections")}),(0,d.jsxs)("button",{onClick:()=>aj({level:"provider",id:c,label:aw?.name||c}),className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs font-medium transition-all ${ak?.providers?.[c]?"bg-amber-500/15 text-amber-500 hover:bg-amber-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:ak?.providers?.[c]?ae("providerProxyTitleConfigured",{host:ak.providers[c].host||ae("configured")}):ae("providerProxyConfigureHint"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:"vpn_lock"}),ak?.providers?.[c]&&ak.providers[c].host||ae("providerProxy")]})]}),g.length>1&&(0,d.jsxs)("button",{onClick:aU,disabled:W||!!U,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ${W?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg-subtle border-border text-text-muted hover:text-text-primary hover:border-primary/40"}`,title:ae("testAll"),"aria-label":ae("testAll"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:W?"sync":"play_arrow"}),W?ae("testing"):ae("testAll")]}),aC?0===g.length&&(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:()=>F(!0),children:ae("add")}):(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:()=>ax?C(!0):F(!0),children:ae("add")})]}),0===g.length?(0,d.jsxs)("div",{className:"text-center py-12",children:[(0,d.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[32px]",children:ax?"lock":"key"})}),(0,d.jsx)("p",{className:"text-text-main font-medium mb-1",children:ae("noConnectionsYet")}),(0,d.jsx)("p",{className:"text-sm text-text-muted mb-4",children:ae("addFirstConnectionHint")}),!aC&&(0,d.jsx)(n.Button,{icon:"add",onClick:()=>ax?C(!0):F(!0),children:ae("addConnection")})]}):(0,d.jsx)("div",{className:"flex flex-col divide-y divide-black/[0.03] dark:divide-white/[0.03]",children:g.sort((a,b)=>(a.priority||0)-(b.priority||0)).map((a,b)=>(0,d.jsx)(M,{connection:a,isOAuth:ax,isFirst:0===b,isLast:b===g.length-1,onMoveUp:()=>aY(a,g[b-1]),onMoveDown:()=>aY(a,g[b+1]),onToggleActive:b=>aQ(a.id,b),onToggleRateLimit:b=>aR(a.id,b),isCodex:"codex"===c,onToggleCodex5h:b=>aS(a.id,"use5h",b),onToggleCodexWeekly:b=>aS(a.id,"useWeekly",b),onRetest:()=>aT(a.id),isRetesting:U===a.id,onEdit:()=>{T(a),L(!0)},onDelete:()=>aM(a.id),onReauth:ax?()=>C(!0):void 0,onRefreshToken:ax?()=>aX(a.id):void 0,isRefreshing:aV===a.id,onProxy:()=>aj({level:"key",id:a.id,label:a.name||a.email||a.id}),hasProxy:!!(ak?.keys?.[a.id]||ak?.providers?.[c]||ak?.global),proxySource:ak?.keys?.[a.id]?"key":ak?.providers?.[c]?"provider":ak?.global?"global":null,proxyHost:(ak?.keys?.[a.id]||ak?.providers?.[c]||ak?.global)?.host||null},a.id))})]}),!aD&&(0,d.jsxs)(m.Card,{children:[(0,d.jsx)("h2",{className:"text-lg font-semibold mb-4",children:ae("availableModels")}),(()=>{if(aC)return(0,d.jsx)(K,{providerStorageAlias:aE,providerDisplayAlias:aF,modelAliases:$,copied:ac,onCopy:ad,onSetAlias:aK,onDeleteAlias:aL,connections:g,isAnthropic:aB,onImportWithProgress:a$,t:ae,effectiveModelNormalize:a0,effectiveModelPreserveDeveloper:a1,saveModelCompatFlags:a2,compatSavingModelId:au,onModelsChanged:aH});if(aw.passthroughModels)return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"download",onClick:aZ,disabled:!a_||am,children:am?ae("importingModels"):ae("importFromModels")}),!a_&&(0,d.jsx)("span",{className:"text-xs text-text-muted",children:ae("addConnectionToImport")})]}),(0,d.jsx)(H,{providerAlias:az,modelAliases:$,copied:ac,onCopy:ad,onSetAlias:aK,onDeleteAlias:aL,t:ae,effectiveModelNormalize:a0,effectiveModelPreserveDeveloper:a1,saveModelCompatFlags:a2,compatSavingModelId:au})]});let a=(0,d.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"download",onClick:aZ,disabled:!a_||am,children:am?ae("importingModels"):ae("importFromModels")}),!a_&&(0,d.jsx)("span",{className:"text-xs text-text-muted",children:ae("addConnectionToImport")})]});return 0===ay.length?(0,d.jsxs)("div",{children:[a,(0,d.jsx)("p",{className:"text-sm text-text-muted",children:ae("noModelsConfigured")})]}):(0,d.jsxs)("div",{children:[a,(0,d.jsx)("div",{className:"flex flex-wrap gap-3",children:ay.map(a=>{let b=`${aE}/${a.id}`,e=`${c}/${a.id}`,f=Object.entries($).find(([,a])=>a===b||a===e)?.[0];return(0,d.jsx)(G,{model:a,fullModel:`${aF}/${a.id}`,alias:f,copied:ac,onCopy:ad,t:ae,showDeveloperToggle:!0,normalizeToolCallId:a0(a.id),preserveDeveloperRole:a1(a.id),onNormalizeChange:b=>a2(a.id,{normalizeToolCallId:b}),onPreserveChange:b=>a2(a.id,{preserveOpenAIDeveloperRole:b}),compatDisabled:au===a.id},a.id)})})]})})(),!aC&&(0,d.jsx)(J,{providerId:c,providerAlias:aF,copied:ac,onCopy:ad,onModelsChanged:aH})]}),aD&&(0,d.jsxs)(m.Card,{children:[(0,d.jsx)("h2",{className:"text-lg font-semibold mb-4",children:ae("searchProvider")||"Search Provider"}),(0,d.jsx)("p",{className:"text-sm text-text-muted",children:ae("searchProviderDesc")||"This provider is used for web search via POST /v1/search. No model configuration needed — search providers are ready to use once an API key is connected."}),"perplexity-search"===c&&(0,d.jsxs)("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded-lg bg-blue-500/10 border border-blue-500/20",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-sm text-blue-400",children:"link"}),(0,d.jsxs)("p",{className:"text-xs text-blue-300",children:["Uses the same API key as ",(0,d.jsx)("strong",{children:"Perplexity"})," (chat provider). If you already have Perplexity configured, no additional setup is needed."]})]})]}),"kiro"===c?(0,d.jsx)(t.KiroOAuthWrapper,{isOpen:z,providerInfo:aw,onSuccess:aN,onClose:()=>{ah.current=!0,C(!1)}}):"cursor"===c?(0,d.jsx)(u.CursorAuthModal,{isOpen:z,onSuccess:aN,onClose:()=>{ah.current=!0,C(!1)}}):(0,d.jsx)(s.OAuthModal,{isOpen:z,provider:c,providerInfo:aw,onSuccess:aN,onClose:()=>{ah.current=!0,C(!1)}}),(0,d.jsx)(N,{isOpen:E,provider:c,providerName:aw.name,isCompatible:aC,isAnthropic:aB,onSave:aO,onClose:()=>F(!1)}),(0,d.jsx)(P,{isOpen:I,connection:S,onSave:aP,onClose:()=>L(!1)}),aC&&(0,d.jsx)(Q,{isOpen:O,node:v,onSave:aJ,onClose:()=>R(!1),isAnthropic:aB}),Y&&(0,d.jsxs)("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[10vh]",onClick:()=>Z(null),children:[(0,d.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),(0,d.jsxs)("div",{className:"relative bg-bg-primary border border-border rounded-xl w-full max-w-[600px] max-h-[80vh] overflow-y-auto shadow-2xl",onClick:a=>a.stopPropagation(),children:[(0,d.jsxs)("div",{className:"sticky top-0 z-10 flex items-center justify-between px-5 py-3 border-b border-border bg-bg-primary/95 backdrop-blur-sm rounded-t-xl",children:[(0,d.jsx)("h3",{className:"font-semibold",children:ae("testResults")}),(0,d.jsx)("button",{onClick:()=>Z(null),className:"p-1 rounded-lg hover:bg-bg-subtle text-text-muted hover:text-text-primary transition-colors","aria-label":"Close",children:(0,d.jsx)("span",{className:"material-symbols-outlined text-lg",children:"close"})})]}),(0,d.jsx)("div",{className:"p-5",children:Y.error&&(!Y.results||0===Y.results.length)?(0,d.jsxs)("div",{className:"text-center py-6",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-red-500 text-[32px] mb-2 block",children:"error"}),(0,d.jsx)("p",{className:"text-sm text-red-400",children:String(Y.error)})]}):(0,d.jsxs)("div",{className:"flex flex-col gap-3",children:[Y.summary&&(0,d.jsxs)("div",{className:"flex items-center gap-3 text-xs mb-1",children:[(0,d.jsx)("span",{className:"text-text-muted",children:aw?.name||c}),(0,d.jsx)("span",{className:"px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-400 font-medium",children:ae("passedCount",{count:Y.summary.passed})}),Y.summary.failed>0&&(0,d.jsx)("span",{className:"px-2 py-0.5 rounded bg-red-500/15 text-red-400 font-medium",children:ae("failedCount",{count:Y.summary.failed})}),(0,d.jsx)("span",{className:"text-text-muted ml-auto",children:ae("testedCount",{count:Y.summary.total})})]}),(Y.results||[]).map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2 text-xs px-3 py-2 rounded-lg bg-black/[0.03] dark:bg-white/[0.03]",children:[(0,d.jsx)("span",{className:`material-symbols-outlined text-[16px] ${a.valid?"text-emerald-500":"text-red-500"}`,children:a.valid?"check_circle":"error"}),(0,d.jsx)("div",{className:"flex-1 min-w-0",children:(0,d.jsx)("span",{className:"font-medium",children:a.connectionName})}),void 0!==a.latencyMs&&(0,d.jsx)("span",{className:"text-text-muted font-mono tabular-nums",children:ae("millisecondsAbbr",{value:a.latencyMs})}),(0,d.jsx)("span",{className:`text-[10px] uppercase font-bold px-1.5 py-0.5 rounded ${a.valid?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:a.valid?ae("okShort"):a.diagnosis?.type||ae("errorShort")})]},a.connectionId||b)),(!Y.results||0===Y.results.length)&&(0,d.jsx)("div",{className:"text-center py-4 text-text-muted text-sm",children:ae("noActiveConnectionsInGroup")})]})})]})]}),ai&&(0,d.jsx)(x.ProxyConfigModal,{isOpen:!!ai,onClose:()=>aj(null),level:ai.level,levelId:ai.id,levelLabel:ai.label}),(0,d.jsx)(q.Modal,{isOpen:ao,onClose:()=>{("done"===aq.phase||"error"===aq.phase)&&ap(!1)},title:ae("importingModelsTitle"),size:"md",closeOnOverlay:!1,showCloseButton:"done"===aq.phase||"error"===aq.phase,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsxs)("div",{className:"flex items-center gap-3",children:["fetching"===aq.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"importing"===aq.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-primary animate-spin",children:"progress_activity"}),"done"===aq.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-green-500",children:"check_circle"}),"error"===aq.phase&&(0,d.jsx)("span",{className:"material-symbols-outlined text-red-500",children:"error"}),(0,d.jsx)("span",{className:"text-sm font-medium text-text-main",children:aq.status})]}),("importing"===aq.phase||"done"===aq.phase)&&aq.total>0&&(0,d.jsxs)("div",{className:"w-full",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,d.jsxs)("span",{className:"text-xs text-text-muted",children:[aq.current," / ",aq.total]}),(0,d.jsxs)("span",{className:"text-xs text-text-muted",children:[Math.round(aq.current/aq.total*100),"%"]})]}),(0,d.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,d.jsx)("div",{className:"h-full rounded-full transition-all duration-300 ease-out",style:{width:`${aq.current/aq.total*100}%`,background:"done"===aq.phase?"linear-gradient(90deg, #22c55e, #16a34a)":"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})})]}),"fetching"===aq.phase&&(0,d.jsx)("div",{className:"w-full h-2.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:(0,d.jsx)("div",{className:"h-full rounded-full animate-pulse",style:{width:"60%",background:"linear-gradient(90deg, var(--color-primary), var(--color-primary-hover, var(--color-primary)))"}})}),"error"===aq.phase&&aq.error&&(0,d.jsx)("div",{className:"p-3 rounded-lg bg-red-500/10 border border-red-500/20",children:(0,d.jsx)("p",{className:"text-sm text-red-400",children:aq.error})}),aq.logs.length>0&&(0,d.jsx)("div",{className:"max-h-48 overflow-y-auto rounded-lg bg-black/5 dark:bg-white/5 p-3 border border-black/5 dark:border-white/5",children:(0,d.jsx)("div",{className:"flex flex-col gap-1",children:aq.logs.map((a,b)=>(0,d.jsx)("p",{className:`text-xs font-mono ${a.startsWith("✓")?"text-green-500 font-semibold":"text-text-muted"}`,children:a},b))})}),"done"===aq.phase&&aq.importedCount>0&&(0,d.jsx)("p",{className:"text-xs text-text-muted text-center animate-pulse",children:ae("pageAutoRefresh")})]})})]}):(0,d.jsxs)("div",{className:"text-center py-20",children:[(0,d.jsx)("p",{className:"text-text-muted",children:ae("providerNotFound")}),(0,d.jsx)(i.default,{href:"/dashboard/providers",className:"text-primary mt-4 inline-block",children:ae("backToProviders")})]})}function G({model:a,fullModel:b,alias:c,copied:e,onCopy:f,t:g,showDeveloperToggle:h=!0,normalizeToolCallId:i,preserveDeveloperRole:j,onNormalizeChange:k,onPreserveChange:l,compatDisabled:m}){return(0,d.jsxs)("div",{className:"flex flex-col px-3 py-2 rounded-lg border border-border hover:bg-sidebar/50 min-w-[220px] max-w-md",children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted shrink-0",children:"smart_toy"}),(0,d.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:b}),(0,d.jsx)("button",{onClick:()=>f(b,`model-${a.id}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:g("copyModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:e===`model-${a.id}`?"check":"content_copy"})})]}),(0,d.jsx)(E,{t:g,normalizeToolCallId:!!i,preserveDeveloperRole:j,showDeveloperToggle:h,onNormalizeChange:k,onPreserveChange:l,disabled:m})]})}function H({providerAlias:a,modelAliases:b,copied:c,onCopy:f,onSetAlias:g,onDeleteAlias:h,t:i,effectiveModelNormalize:j,effectiveModelPreserveDeveloper:k,saveModelCompatFlags:l,compatSavingModelId:m}){let[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(!1),s=Object.entries(b).filter(([,b])=>b.startsWith(`${a}/`)).map(([b,c])=>({modelId:c.replace(`${a}/`,""),fullModel:c,alias:b})),t=async()=>{let a;if(!o.trim()||q)return;let c=o.trim(),d=(a=c.split("/"))[a.length-1];if(b[d])return void alert(i("aliasExistsAlert",{alias:d}));r(!0);try{await g(c,d),p("")}catch(a){console.log("Error adding model:",a)}finally{r(!1)}};return(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)("p",{className:"text-sm text-text-muted",children:i("openRouterAnyModelHint")}),(0,d.jsxs)("div",{className:"flex items-end gap-2",children:[(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("label",{htmlFor:"new-model-input",className:"text-xs text-text-muted mb-1 block",children:i("modelIdFromOpenRouter")}),(0,d.jsx)("input",{id:"new-model-input",type:"text",value:o,onChange:a=>p(a.target.value),onKeyDown:a=>"Enter"===a.key&&t(),placeholder:i("openRouterModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:t,disabled:!o.trim()||q,children:q?i("adding"):i("add")})]}),s.length>0&&(0,d.jsx)("div",{className:"flex flex-col gap-3",children:s.map(({modelId:a,fullModel:b,alias:e})=>(0,d.jsx)(I,{modelId:a,fullModel:b,copied:c,onCopy:f,onDeleteAlias:()=>h(e),t:i,showDeveloperToggle:!0,normalizeToolCallId:j(a),preserveDeveloperRole:k(a),onNormalizeChange:b=>l(a,{normalizeToolCallId:b}),onPreserveChange:b=>l(a,{preserveOpenAIDeveloperRole:b}),compatDisabled:m===a},b))})]})}function I({modelId:a,fullModel:b,copied:c,onCopy:e,onDeleteAlias:f,t:g,showDeveloperToggle:h=!0,normalizeToolCallId:i,preserveDeveloperRole:j,onNormalizeChange:k,onPreserveChange:l,compatDisabled:m}){return(0,d.jsxs)("div",{className:"flex flex-col gap-0 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,d.jsxs)("div",{className:"flex items-start gap-3",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted shrink-0",children:"smart_toy"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium truncate",children:a}),(0,d.jsxs)("div",{className:"flex items-center gap-1 mt-1 flex-wrap",children:[(0,d.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:b}),(0,d.jsx)("button",{onClick:()=>e(b,`model-${a}`),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:g("copyModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:c===`model-${a}`?"check":"content_copy"})})]})]}),(0,d.jsx)("button",{onClick:f,className:"p-1 hover:bg-red-50 rounded text-red-500 shrink-0",title:g("removeModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]}),(0,d.jsx)("div",{className:"pl-9",children:(0,d.jsx)(E,{t:g,normalizeToolCallId:!!i,preserveDeveloperRole:j,showDeveloperToggle:h,onNormalizeChange:k,onPreserveChange:l,disabled:m})})]})}function J({providerId:a,providerAlias:b,copied:c,onCopy:g,onModelsChanged:h}){let i=(0,k.useTranslations)("providers"),j=(0,f.useNotificationStore)(),[l,m]=(0,e.useState)([]),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)("chat-completions"),[u,v]=(0,e.useState)(["chat"]),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!0),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)("chat-completions"),[F,G]=(0,e.useState)(["chat"]),[H,I]=(0,e.useState)(!1),[J,K]=(0,e.useState)(!1),[L,M]=(0,e.useState)(null),N=(0,e.useCallback)(async()=>{try{let b=await fetch(`/api/provider-models?provider=${encodeURIComponent(a)}`);if(b.ok){let a=await b.json();m(a.models||[])}}catch(a){console.error("Failed to fetch custom models:",a)}finally{z(!1)}},[a]);(0,e.useEffect)(()=>{N()},[N]);let O=async()=>{if(o.trim()&&!w){x(!0);try{(await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:o.trim(),modelName:q.trim()||void 0,apiFormat:s,supportedEndpoints:u})})).ok&&(p(""),r(""),t("chat-completions"),v(["chat"]),await N(),h?.())}catch(a){console.error("Failed to add custom model:",a)}finally{x(!1)}}},P=async b=>{try{await fetch(`/api/provider-models?provider=${encodeURIComponent(a)}&model=${encodeURIComponent(b)}`,{method:"DELETE"}),await N(),h?.()}catch(a){console.error("Failed to remove custom model:",a)}},Q=()=>{B(null),D("chat-completions"),G(["chat"]),I(!1),K(!0),M(null)},R=async b=>{if(A&&A===b){if(!F.length)return void j.error("Select at least one supported endpoint");M(b);try{let c=l.find(a=>a.id===b);if(!(await fetch("/api/provider-models",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:b,modelName:c?.name||b,source:c?.source||"manual",apiFormat:C,supportedEndpoints:F,normalizeToolCallId:H,preserveOpenAIDeveloperRole:J})})).ok)throw Error("Failed to save model endpoint settings");await N(),h?.(),j.success("Saved model endpoint settings"),Q()}catch(a){console.error("Failed to save custom model:",a),j.error("Failed to save model endpoint settings")}finally{M(null)}}};return(0,d.jsxs)("div",{className:"mt-6 pt-6 border-t border-border",children:[(0,d.jsxs)("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),i("customModels")]}),(0,d.jsx)("p",{className:"text-xs text-text-muted mb-3",children:i("customModelsHint")}),(0,d.jsxs)("div",{className:"flex flex-col gap-3 mb-3",children:[(0,d.jsxs)("div",{className:"flex items-end gap-2",children:[(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("label",{htmlFor:"custom-model-id",className:"text-xs text-text-muted mb-1 block",children:i("modelId")}),(0,d.jsx)("input",{id:"custom-model-id",type:"text",value:o,onChange:a=>p(a.target.value),onKeyDown:a=>"Enter"===a.key&&O(),placeholder:i("customModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsxs)("div",{className:"w-40",children:[(0,d.jsx)("label",{htmlFor:"custom-model-name",className:"text-xs text-text-muted mb-1 block",children:i("displayName")}),(0,d.jsx)("input",{id:"custom-model-name",type:"text",value:q,onChange:a=>r(a.target.value),onKeyDown:a=>"Enter"===a.key&&O(),placeholder:i("optional"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:O,disabled:!o.trim()||w,children:w?i("adding"):i("add")})]}),(0,d.jsxs)("div",{className:"flex items-end gap-4 flex-wrap",children:[(0,d.jsxs)("div",{className:"w-48",children:[(0,d.jsx)("label",{htmlFor:"custom-api-format",className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,d.jsxs)("select",{id:"custom-api-format",value:s,onChange:a=>t(a.target.value),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,d.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,d.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,d.jsxs)("div",{className:"flex-1",children:[(0,d.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,d.jsx)("div",{className:"flex items-center gap-3",children:["chat","embeddings","images","audio"].map(a=>(0,d.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,d.jsx)("input",{type:"checkbox",checked:u.includes(a),onChange:b=>{b.target.checked?v(b=>[...b,a]):v(b=>b.filter(b=>b!==a))},className:"rounded border-border"}),"chat"===a?"💬 Chat":"embeddings"===a?"📐 Embeddings":"images"===a?"🖼️ Images":"🔊 Audio"]},a))})]})]})]}),y?(0,d.jsx)("p",{className:"text-xs text-text-muted",children:i("loading")}):l.length>0?(0,d.jsx)("div",{className:"flex flex-col gap-2",children:l.map(a=>{let e=`${b}/${a.id}`,f=`custom-${a.id}`;return(0,d.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border hover:bg-sidebar/50",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-primary",children:"tune"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium truncate",children:a.name||a.id}),(0,d.jsxs)("div",{className:"flex items-center gap-1 mt-1 flex-wrap",children:[(0,d.jsx)("code",{className:"text-xs text-text-muted font-mono bg-sidebar px-1.5 py-0.5 rounded",children:e}),(0,d.jsx)("button",{onClick:()=>g(e,f),className:"p-0.5 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:i("copyModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:c===f?"check":"content_copy"})}),"responses"===a.apiFormat&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-blue-500/15 text-blue-400 font-medium",children:"Responses"}),a.supportedEndpoints?.includes("embeddings")&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-purple-500/15 text-purple-400 font-medium",children:"📐 Embed"}),a.supportedEndpoints?.includes("images")&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/15 text-amber-400 font-medium",children:"🖼️ Images"}),a.supportedEndpoints?.includes("audio")&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/15 text-green-400 font-medium",children:"🔊 Audio"}),a.normalizeToolCallId&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-slate-500/15 text-slate-400 font-medium",title:i("normalizeToolCallIdLabel"),children:"ID×9"}),!1===a.preserveOpenAIDeveloperRole&&(0,d.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-cyan-500/15 text-cyan-400 font-medium",title:i("compatDoNotPreserveDeveloper"),children:i("compatBadgeNoPreserve")})]}),A===a.id&&(0,d.jsxs)("div",{className:"mt-3 p-3 rounded-lg border border-border bg-sidebar/40",children:[(0,d.jsxs)("div",{className:"flex items-end gap-3 flex-wrap",children:[(0,d.jsxs)("div",{className:"w-44",children:[(0,d.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"API Format"}),(0,d.jsxs)("select",{value:C,onChange:a=>D(a.target.value),className:"w-full px-2.5 py-2 text-xs border border-border rounded-lg bg-background focus:outline-none focus:border-primary",children:[(0,d.jsx)("option",{value:"chat-completions",children:"Chat Completions"}),(0,d.jsx)("option",{value:"responses",children:"Responses API"})]})]}),(0,d.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,d.jsx)("span",{className:"text-xs text-text-muted mb-1 block",children:"Supported Endpoints"}),(0,d.jsx)("div",{className:"flex items-center gap-3 flex-wrap",children:["chat","embeddings","images","audio"].map(a=>(0,d.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-text-main cursor-pointer",children:[(0,d.jsx)("input",{type:"checkbox",checked:F.includes(a),onChange:b=>{b.target.checked?G(b=>b.includes(a)?b:[...b,a]):G(b=>b.filter(b=>b!==a))},className:"rounded border-border"}),"chat"===a?"💬 Chat":"embeddings"===a?"📐 Embeddings":"images"===a?"🖼️ Images":"🔊 Audio"]},a))})]})]}),(0,d.jsx)("div",{className:"mt-3 pt-3 border-t border-border/80 w-full",children:(0,d.jsx)(E,{t:i,normalizeToolCallId:H,preserveDeveloperRole:J,showDeveloperToggle:!0,onNormalizeChange:I,onPreserveChange:K,disabled:L===a.id})}),(0,d.jsxs)("div",{className:"mt-3 flex items-center gap-2",children:[(0,d.jsx)(n.Button,{size:"sm",onClick:()=>R(a.id),disabled:L===a.id,children:L===a.id?i("saving"):i("save")}),(0,d.jsx)(n.Button,{size:"sm",variant:"ghost",onClick:Q,children:i("cancel")})]})]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-1",children:[(0,d.jsx)("button",{onClick:()=>{B(a.id),D(a.apiFormat||"chat-completions"),G(Array.isArray(a.supportedEndpoints)&&a.supportedEndpoints.length?a.supportedEndpoints:["chat"]),I(!!a.normalizeToolCallId),K(!Object.prototype.hasOwnProperty.call(a,"preserveOpenAIDeveloperRole")||!!a.preserveOpenAIDeveloperRole)},className:"p-1 hover:bg-sidebar rounded text-text-muted hover:text-primary",title:i("edit"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"edit"})}),(0,d.jsx)("button",{onClick:()=>P(a.id),className:"p-1 hover:bg-red-50 rounded text-red-500",title:i("removeCustomModel"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"delete"})})]})]},a.id)})}):(0,d.jsx)("p",{className:"text-xs text-text-muted",children:i("noCustomModels")})]})}function K({providerStorageAlias:a,providerDisplayAlias:b,modelAliases:c,copied:g,onCopy:h,onSetAlias:i,onDeleteAlias:j,connections:k,isAnthropic:l,onImportWithProgress:m,t:o,effectiveModelNormalize:p,effectiveModelPreserveDeveloper:q,saveModelCompatFlags:r,compatSavingModelId:s,onModelsChanged:t}){let[u,v]=(0,e.useState)(""),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),A=(0,f.useNotificationStore)(),B=Object.entries(c).filter(([,b])=>b.startsWith(`${a}/`)).map(([b,c])=>({modelId:c.replace(`${a}/`,""),fullModel:c,alias:b})),C=a=>{let d,e=(d=a.split("/"))[d.length-1];if(!c[e])return e;let f=`${b}-${e}`;return c[f]?null:f},D=async()=>{if(!u.trim()||w)return;let b=u.trim(),c=C(b);if(!c)return void A.error(o("allSuggestedAliasesExist"));x(!0);try{let d=await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:b,modelName:b,source:"manual"})});if(!d.ok){let a={};try{a=await d.json()}catch(a){console.error("Failed to parse error response from custom model API:",a)}throw Error(a.error?.message||o("failedSaveCustomModel"))}await i(b,c,a),v(""),A.success(o("modelAddedSuccess",{modelId:b})),t?.()}catch(a){console.error("Error adding model:",a),A.error(a instanceof Error?a.message:o("failedAddModelTryAgain"))}finally{x(!1)}},E=async()=>{if(y)return;let b=k.find(a=>!1!==a.isActive);if(b){z(!0);try{await m(async()=>{let a=await fetch(`/api/providers/${b.id}/models`),c=await a.json();if(!a.ok)throw Error(c.error||o("failedImportModels"));return c},async b=>{let c=b.id||b.name||b.model;if(!c)return!1;let d=C(c);return!!d&&((await fetch("/api/provider-models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:a,modelId:c,modelName:b.name||c,source:"imported"})})).ok?(await i(c,d,a),!0):(A.error(o("failedSaveImportedModel")),!1))})}catch(a){console.error("Error importing models:",a),A.error(o("failedImportModelsTryAgain"))}finally{z(!1)}}},F=k.some(a=>!1!==a.isActive),G=async(b,c)=>{try{if(!(await fetch(`/api/provider-models?provider=${encodeURIComponent(a)}&model=${encodeURIComponent(b)}`,{method:"DELETE"})).ok)throw Error(o("failedRemoveModelFromDatabase"));await j(c),A.success(o("modelRemovedSuccess")),t?.()}catch(a){console.error("Error deleting model:",a),A.error(a instanceof Error?a.message:o("failedDeleteModelTryAgain"))}};return(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)("p",{className:"text-sm text-text-muted",children:o("compatibleModelsDescription",{type:l?o("anthropic"):o("openai")})}),(0,d.jsxs)("div",{className:"flex items-end gap-2 flex-wrap",children:[(0,d.jsxs)("div",{className:"flex-1 min-w-[240px]",children:[(0,d.jsx)("label",{htmlFor:"new-compatible-model-input",className:"text-xs text-text-muted mb-1 block",children:o("modelId")}),(0,d.jsx)("input",{id:"new-compatible-model-input",type:"text",value:u,onChange:a=>v(a.target.value),onKeyDown:a=>"Enter"===a.key&&D(),placeholder:l?o("anthropicCompatibleModelPlaceholder"):o("openaiCompatibleModelPlaceholder"),className:"w-full px-3 py-2 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"})]}),(0,d.jsx)(n.Button,{size:"sm",icon:"add",onClick:D,disabled:!u.trim()||w,children:w?o("adding"):o("add")}),(0,d.jsx)(n.Button,{size:"sm",variant:"secondary",icon:"download",onClick:E,disabled:!F||y,children:y?o("importingModels"):o("importFromModels")})]}),!F&&(0,d.jsx)("p",{className:"text-xs text-text-muted",children:o("addConnectionToImport")}),B.length>0&&(0,d.jsx)("div",{className:"flex flex-col gap-3",children:B.map(({modelId:a,fullModel:c,alias:e})=>(0,d.jsx)(I,{modelId:a,fullModel:`${b}/${a}`,copied:g,onCopy:h,onDeleteAlias:()=>G(a,e),t:o,showDeveloperToggle:!l,normalizeToolCallId:p(a),preserveDeveloperRole:q(a),onNormalizeChange:b=>r(a,{normalizeToolCallId:b}),onPreserveChange:b=>r(a,{preserveOpenAIDeveloperRole:b}),compatDisabled:s===a},c))})]})}function L({until:a}){let[b,c]=(0,e.useState)("");return((0,e.useEffect)(()=>{let b=()=>{let b=new Date(a).getTime()-Date.now();if(b<=0)return void c("");let d=Math.floor(b/1e3);if(d<60)c(`${d}s`);else if(d<3600)c(`${Math.floor(d/60)}m ${d%60}s`);else{let a=Math.floor(d/3600),b=Math.floor(d%3600/60);c(`${a}h ${b}m`)}};b();let d=setInterval(b,1e3);return()=>clearInterval(d)},[a]),b)?(0,d.jsxs)("span",{className:"text-xs text-orange-500 font-mono",children:["⏱ ",b]}):null}[l,y,z]=C.then?(await C)():C,G.propTypes={model:g.default.shape({id:g.default.string.isRequired}).isRequired,fullModel:g.default.string.isRequired,alias:g.default.string,copied:g.default.string,onCopy:g.default.func.isRequired,t:g.default.func,showDeveloperToggle:g.default.bool,normalizeToolCallId:g.default.bool,preserveDeveloperRole:g.default.bool,onNormalizeChange:g.default.func,onPreserveChange:g.default.func,compatDisabled:g.default.bool},H.propTypes={providerAlias:g.default.string.isRequired,modelAliases:g.default.object.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onSetAlias:g.default.func.isRequired,onDeleteAlias:g.default.func.isRequired,t:g.default.func.isRequired,effectiveModelNormalize:g.default.func.isRequired,effectiveModelPreserveDeveloper:g.default.func.isRequired,saveModelCompatFlags:g.default.func.isRequired,compatSavingModelId:g.default.string},I.propTypes={modelId:g.default.string.isRequired,fullModel:g.default.string.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onDeleteAlias:g.default.func.isRequired,t:g.default.func,showDeveloperToggle:g.default.bool,normalizeToolCallId:g.default.bool,preserveDeveloperRole:g.default.bool,onNormalizeChange:g.default.func,onPreserveChange:g.default.func,compatDisabled:g.default.bool},J.propTypes={providerId:g.default.string.isRequired,providerAlias:g.default.string.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onModelsChanged:g.default.func},K.propTypes={providerStorageAlias:g.default.string.isRequired,providerDisplayAlias:g.default.string.isRequired,modelAliases:g.default.object.isRequired,copied:g.default.string,onCopy:g.default.func.isRequired,onSetAlias:g.default.func.isRequired,onDeleteAlias:g.default.func.isRequired,connections:g.default.arrayOf(g.default.shape({id:g.default.string,isActive:g.default.bool})).isRequired,isAnthropic:g.default.bool,onImportWithProgress:g.default.func.isRequired,t:g.default.func.isRequired,effectiveModelNormalize:g.default.func.isRequired,effectiveModelPreserveDeveloper:g.default.func.isRequired,saveModelCompatFlags:g.default.func.isRequired,compatSavingModelId:g.default.string,onModelsChanged:g.default.func},L.propTypes={until:g.default.string.isRequired};let R={runtime_error:{labelKey:"errorTypeRuntime",variant:"warning"},upstream_auth_error:{labelKey:"errorTypeUpstreamAuth",variant:"error"},auth_missing:{labelKey:"errorTypeMissingCredential",variant:"warning"},token_refresh_failed:{labelKey:"errorTypeRefreshFailed",variant:"warning"},token_expired:{labelKey:"errorTypeTokenExpired",variant:"warning"},upstream_rate_limited:{labelKey:"errorTypeRateLimited",variant:"warning"},upstream_unavailable:{labelKey:"errorTypeUpstreamUnavailable",variant:"error"},network_error:{labelKey:"errorTypeNetworkError",variant:"warning"},unsupported:{labelKey:"errorTypeTestUnsupported",variant:"default"},upstream_error:{labelKey:"errorTypeUpstreamError",variant:"error"}};function M({connection:a,isOAuth:b,isCodex:c,isFirst:f,isLast:g,onMoveUp:h,onMoveDown:i,onToggleActive:j,onToggleRateLimit:l,onToggleCodex5h:m,onToggleCodexWeekly:p,onRetest:q,isRetesting:r,onEdit:s,onDelete:t,onReauth:u,onProxy:w,hasProxy:x,proxySource:y,proxyHost:z,onRefreshToken:A,isRefreshing:B}){let C,E=(0,k.useTranslations)("providers"),F=b?a.name||a.email||a.displayName||E("oauthAccount"):a.name,[G,H]=(0,e.useState)(!1),[I,J]=(0,e.useState)(()=>{if(!b||!a.expiresAt)return null;let c=new Date(a.expiresAt).getTime();return Math.floor((c-Date.now())/6e4)});(0,e.useEffect)(()=>{if(!b||!a.expiresAt)return;let c=setInterval(()=>{let b=new Date(a.expiresAt).getTime();J(Math.floor((b-Date.now())/6e4))},3e4);return()=>clearInterval(c)},[b,a.expiresAt]),(0,e.useEffect)(()=>{let b=()=>{let b=a.rateLimitedUntil&&new Date(a.rateLimitedUntil).getTime()>Date.now();H(b)};b();let c=a.rateLimitedUntil?setInterval(b,1e3):null;return()=>{c&&clearInterval(c)}},[a.rateLimitedUntil]);let K="unavailable"!==a.testStatus||G?a.testStatus:"active",M=function(a,b,c,d){if(!1===a.isActive)return{statusVariant:"default",statusLabel:d("statusDisabled"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};if("active"===b||"success"===b)return{statusVariant:"success",statusLabel:d("statusConnected"),errorType:null,errorBadge:null,errorTextClass:"text-text-muted"};let e=function(a,b){if(b)return"upstream_rate_limited";if(a.lastErrorType)return a.lastErrorType;let c=Number(a.errorCode);if(401===c||403===c)return"upstream_auth_error";if(429===c)return"upstream_rate_limited";if(c>=500)return"upstream_unavailable";let d=(a.lastError||"").toLowerCase();return d?d.includes("runtime")||d.includes("not runnable")||d.includes("not installed")||d.includes("healthcheck")?"runtime_error":d.includes("refresh failed")?"token_refresh_failed":d.includes("token expired")||d.includes("expired")?"token_expired":d.includes("invalid api key")||d.includes("token invalid")||d.includes("revoked")||d.includes("access denied")||d.includes("unauthorized")?"upstream_auth_error":d.includes("rate limit")||d.includes("quota")||d.includes("too many requests")||d.includes("429")?"upstream_rate_limited":d.includes("fetch failed")||d.includes("network")||d.includes("timeout")||d.includes("econn")||d.includes("enotfound")?"network_error":d.includes("not supported")?"unsupported":"upstream_error":null}(a,c),f=e&&R[e]||null;if("runtime_error"===e)return{statusVariant:"warning",statusLabel:d("statusRuntimeIssue"),errorType:e,errorBadge:f,errorTextClass:"text-yellow-600 dark:text-yellow-400"};if("upstream_auth_error"===e||"auth_missing"===e||"token_refresh_failed"===e||"token_expired"===e)return{statusVariant:"error",statusLabel:d("statusAuthFailed"),errorType:e,errorBadge:f,errorTextClass:"text-red-500"};if("upstream_rate_limited"===e)return{statusVariant:"warning",statusLabel:d("statusRateLimited"),errorType:e,errorBadge:f,errorTextClass:"text-yellow-600 dark:text-yellow-400"};if("network_error"===e)return{statusVariant:"warning",statusLabel:d("statusNetworkIssue"),errorType:e,errorBadge:f,errorTextClass:"text-yellow-600 dark:text-yellow-400"};if("unsupported"===e)return{statusVariant:"default",statusLabel:d("statusTestUnsupported"),errorType:e,errorBadge:f,errorTextClass:"text-text-muted"};let g={unavailable:d("statusUnavailable"),failed:d("statusFailed"),error:d("statusError")};return{statusVariant:"error",statusLabel:g[b]||b||d("statusError"),errorType:e,errorBadge:f,errorTextClass:"text-red-500"}}(a,K,G,E),N=!!a.rateLimitProtection,O=a.providerSpecificData&&"object"==typeof a.providerSpecificData&&a.providerSpecificData.codexLimitPolicy&&"object"==typeof a.providerSpecificData.codexLimitPolicy?a.providerSpecificData.codexLimitPolicy:{},P=D(O),Q=P.use5h,S=P.useWeekly;return(0,d.jsxs)("div",{className:`group flex items-center justify-between p-3 rounded-lg hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${!1===a.isActive?"opacity-60":""}`,children:[(0,d.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"flex flex-col",children:[(0,d.jsx)("button",{onClick:h,disabled:f,className:`p-0.5 rounded ${f?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_up"})}),(0,d.jsx)("button",{onClick:i,disabled:g,className:`p-0.5 rounded ${g?"text-text-muted/30 cursor-not-allowed":"hover:bg-sidebar text-text-muted hover:text-primary"}`,children:(0,d.jsx)("span",{className:"material-symbols-outlined text-sm",children:"keyboard_arrow_down"})})]}),(0,d.jsx)("span",{className:"material-symbols-outlined text-base text-text-muted",children:b?"lock":"key"}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("p",{className:"text-sm font-medium truncate",children:F}),(0,d.jsxs)("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[(0,d.jsx)(o.Badge,{variant:M.statusVariant,size:"sm",dot:!0,children:M.statusLabel}),null!==I&&(I<0?(0,d.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-red-500/15 text-red-500",title:`Token expired: ${a.expiresAt}`,children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"error"}),"expired"]}):I<30?(0,d.jsxs)("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/15 text-amber-500",title:`Token expires in ${I}m`,children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"warning"}),`~${I}m`]}):null),G&&!1!==a.isActive&&(0,d.jsx)(L,{until:a.rateLimitedUntil}),M.errorBadge&&!1!==a.isActive&&(0,d.jsx)(o.Badge,{variant:M.errorBadge.variant,size:"sm",children:E(M.errorBadge.labelKey)}),a.lastError&&!1!==a.isActive&&(0,d.jsx)("span",{className:`text-xs truncate max-w-[300px] ${M.errorTextClass}`,title:a.lastError,children:a.lastError}),(0,d.jsxs)("span",{className:"text-xs text-text-muted",children:["#",a.priority]}),a.globalPriority&&(0,d.jsx)("span",{className:"text-xs text-text-muted",children:E("autoPriority",{priority:a.globalPriority})}),(0,d.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,d.jsxs)("button",{onClick:()=>l(!N),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${N?"bg-emerald-500/15 text-emerald-500 hover:bg-emerald-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:E(N?"disableRateLimitProtection":"enableRateLimitProtection"),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"shield"}),E(N?"rateLimitProtected":"rateLimitUnprotected")]}),c&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,d.jsxs)("button",{onClick:()=>m?.(!Q),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${Q?"bg-blue-500/15 text-blue-500 hover:bg-blue-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex 5h limit policy",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"timer"}),"5h ",Q?"ON":"OFF"]}),(0,d.jsxs)("button",{onClick:()=>p?.(!S),className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium transition-all cursor-pointer ${S?"bg-violet-500/15 text-violet-500 hover:bg-violet-500/25":"bg-black/[0.03] dark:bg-white/[0.03] text-text-muted/50 hover:text-text-muted hover:bg-black/[0.06] dark:hover:bg-white/[0.06]"}`,title:"Toggle Codex weekly limit policy",children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"date_range"}),"Weekly ",S?"ON":"OFF"]})]}),x&&(C=E("global"===y?"proxySourceGlobal":"provider"===y?"proxySourceProvider":"proxySourceKey"),(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("span",{className:"text-text-muted/30 select-none",children:"|"}),(0,d.jsxs)("span",{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium ${"global"===y?"bg-emerald-500/15 text-emerald-500":"provider"===y?"bg-amber-500/15 text-amber-500":"bg-blue-500/15 text-blue-500"}`,title:E("proxyConfiguredBySource",{source:C,host:z||E("configured")}),children:[(0,d.jsx)("span",{className:"material-symbols-outlined text-[13px]",children:"vpn_lock"}),z||E("proxy")]})]}))]})]})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)(n.Button,{size:"sm",variant:"ghost",icon:"refresh",loading:r,disabled:!1===a.isActive,onClick:q,className:"!h-7 !px-2 text-xs",title:E("retestAuthentication"),children:E("retest")}),A&&(0,d.jsx)(n.Button,{size:"sm",variant:"ghost",icon:"token",loading:B,disabled:!1===a.isActive||B,onClick:A,className:"!h-7 !px-2 text-xs text-amber-500 hover:text-amber-400",title:"Refresh OAuth token manually",children:"Token"}),(0,d.jsx)(v.Toggle,{size:"sm",checked:a.isActive??!0,onChange:j,title:E(a.isActive??!0?"disableConnection":"enableConnection")}),(0,d.jsxs)("div",{className:"flex gap-1 ml-1 transition-opacity",children:[u&&(0,d.jsx)("button",{onClick:u,className:"p-2 hover:bg-amber-500/10 rounded text-amber-600 hover:text-amber-500",title:E("reauthenticateConnection"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"passkey"})}),(0,d.jsx)("button",{onClick:s,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:E("edit"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),(0,d.jsx)("button",{onClick:w,className:"p-2 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary",title:E("proxyConfig"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"vpn_lock"})}),(0,d.jsx)("button",{onClick:t,className:"p-2 hover:bg-red-500/10 rounded text-red-500",title:E("delete"),children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]})]})}function N({isOpen:a,provider:b,providerName:c,isCompatible:f,isAnthropic:g,onSave:h,onClose:i}){let j=(0,k.useTranslations)("providers"),l="bailian-coding-plan"===b,m="https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1",[r,s]=(0,e.useState)({name:"",apiKey:"",priority:1,baseUrl:l?m:""}),[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(null),[x,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(null),B=async()=>{u(!0),A(null);try{let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b,apiKey:r.apiKey})}),c=await a.json();w(c.valid?"success":"failed")}catch{w("failed")}finally{u(!1)}},C=async()=>{if(b&&r.apiKey){y(!0),A(null);try{let a=null;if(l){let b=O(r.baseUrl,m);if(b.error)return void A(b.error);a=b.value}let c=!1;try{u(!0),w(null);let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b,apiKey:r.apiKey})});c=!!(await a.json()).valid,w(c?"success":"failed")}catch{w("failed")}finally{u(!1)}if(!c)return void A(j("apiKeyValidationFailed"));let d={name:r.name,apiKey:r.apiKey,priority:r.priority,testStatus:"active",providerSpecificData:void 0};l&&(d.providerSpecificData={baseUrl:a});let e=await h(d);e&&A("string"==typeof e?e:j("failedSaveConnection"))}finally{y(!1)}}};return b?(0,d.jsx)(q.Modal,{isOpen:a,title:j("addProviderApiKeyTitle",{provider:c||b}),onClose:i,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)(p.Input,{label:j("nameLabel"),value:r.name,onChange:a=>s({...r,name:a.target.value}),placeholder:j("productionKey")}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(p.Input,{label:j("apiKeyLabel"),type:"password",value:r.apiKey,onChange:a=>s({...r,apiKey:a.target.value}),className:"flex-1"}),(0,d.jsx)("div",{className:"pt-6",children:(0,d.jsx)(n.Button,{onClick:B,disabled:!r.apiKey||t||x,variant:"secondary",children:t?j("checking"):j("check")})})]}),v&&(0,d.jsx)(o.Badge,{variant:"success"===v?"success":"error",children:"success"===v?j("valid"):j("invalid")}),z&&(0,d.jsx)("div",{className:"text-sm text-red-500 bg-red-500/10 border border-red-500/20 rounded-lg px-3 py-2",children:z}),f&&(0,d.jsx)("p",{className:"text-xs text-text-muted",children:g?j("validationChecksAnthropicCompatible",{provider:c||j("anthropicCompatibleName")}):j("validationChecksOpenAiCompatible",{provider:c||j("openaiCompatibleName")})}),(0,d.jsx)(p.Input,{label:j("priorityLabel"),type:"number",value:r.priority,onChange:a=>s({...r,priority:Number.parseInt(a.target.value)||1})}),l&&(0,d.jsx)(p.Input,{label:"Base URL",value:r.baseUrl,onChange:a=>s({...r,baseUrl:a.target.value}),placeholder:m,hint:"Optional: Custom base URL for bailian-coding-plan provider"}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(n.Button,{onClick:C,fullWidth:!0,disabled:!r.name||!r.apiKey||x,children:x?j("saving"):j("save")}),(0,d.jsx)(n.Button,{onClick:i,variant:"ghost",fullWidth:!0,children:j("cancel")})]})]})}):null}function O(a,b){let c=("string"==typeof a?a.trim():"")||b;try{let a=new URL(c);if("http:"!==a.protocol&&"https:"!==a.protocol)return{value:null,error:"Base URL must use http or https"};return{value:c,error:null}}catch{return{value:null,error:"Base URL must be a valid URL"}}}function P({isOpen:a,connection:b,onSave:c,onClose:f}){let g=(0,k.useTranslations)("providers"),[h,i]=(0,e.useState)({name:"",priority:1,apiKey:"",healthCheckInterval:60,baseUrl:""}),[j,l]=(0,e.useState)(!1),[m,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(!1),[z,A]=(0,e.useState)(null),[B,C]=(0,e.useState)([]),[D,E]=(0,e.useState)(""),F=b?.provider==="bailian-coding-plan",G="https://coding-intl.dashscope.aliyuncs.com/apps/anthropic/v1";(0,e.useEffect)(()=>{if(b){let a=b.providerSpecificData?.baseUrl;i({name:b.name||"",priority:b.priority||1,apiKey:"",healthCheckInterval:b.healthCheckInterval??60,baseUrl:a||(F?G:"")});let c=b.providerSpecificData?.extraApiKeys;C(Array.isArray(c)?c:[]),E(""),r(null),v(null),A(null)}},[b,F]);let H=async()=>{if(b?.provider){l(!0),r(null);try{let a=await fetch(`/api/providers/${b.id}/test`,{method:"POST"}),c=await a.json();r({valid:!!c.valid,diagnosis:c.diagnosis||null,message:c.error||null})}catch{r({valid:!1,diagnosis:{type:"network_error"},message:g("failedTestConnection")})}finally{l(!1)}}},I=async()=>{if(b?.provider&&h.apiKey){t(!0),v(null);try{let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b.provider,apiKey:h.apiKey})}),c=await a.json();v(c.valid?"success":"failed")}catch{v("failed")}finally{t(!1)}}},J=async()=>{x(!0),A(null);try{let a={name:h.name,priority:h.priority,healthCheckInterval:h.healthCheckInterval},d=null;if(F){let a=O(h.baseUrl,G);if(a.error)return void A(a.error);d=a.value}if(!K&&h.apiKey){a.apiKey=h.apiKey;let c="success"===u;if(!c)try{t(!0),v(null);let a=await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:b.provider,apiKey:h.apiKey})});c=!!(await a.json()).valid,v(c?"success":"failed")}catch{v("failed")}finally{t(!1)}c&&(a.testStatus="active",a.lastError=null,a.lastErrorAt=null,a.lastErrorType=null,a.lastErrorSource=null,a.errorCode=null,a.rateLimitedUntil=null)}!K&&(a.providerSpecificData={...b.providerSpecificData||{},extraApiKeys:B.filter(a=>a.trim().length>0)},F&&(a.providerSpecificData.baseUrl=d));let e=await c(a);e&&A("string"==typeof e?e:g("failedSaveConnection"))}finally{x(!1)}};if(!b)return null;let K="oauth"===b.authType,L=(0,y.isOpenAICompatibleProvider)(b.provider)||(0,y.isAnthropicCompatibleProvider)(b.provider),M=!m?.valid&&m?.diagnosis?.type&&R[m.diagnosis.type]||null;return(0,d.jsx)(q.Modal,{isOpen:a,title:g("editConnection"),onClose:f,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)(p.Input,{label:g("nameLabel"),value:h.name,onChange:a=>i({...h,name:a.target.value}),placeholder:K?g("accountName"):g("productionKey")}),K&&b.email&&(0,d.jsxs)("div",{className:"bg-sidebar/50 p-3 rounded-lg",children:[(0,d.jsx)("p",{className:"text-sm text-text-muted mb-1",children:g("email")}),(0,d.jsx)("p",{className:"font-medium",children:b.email})]}),K&&(0,d.jsx)(p.Input,{label:g("healthCheckMinutes"),type:"number",value:h.healthCheckInterval,onChange:a=>i({...h,healthCheckInterval:Math.max(0,Number.parseInt(a.target.value)||0)}),hint:g("healthCheckHint")}),(0,d.jsx)(p.Input,{label:g("priorityLabel"),type:"number",value:h.priority,onChange:a=>i({...h,priority:Number.parseInt(a.target.value)||1})}),!K&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(p.Input,{label:g("apiKeyLabel"),type:"password",value:h.apiKey,onChange:a=>i({...h,apiKey:a.target.value}),placeholder:g("enterNewApiKey"),hint:g("leaveBlankKeepCurrentApiKey"),className:"flex-1"}),(0,d.jsx)("div",{className:"pt-6",children:(0,d.jsx)(n.Button,{onClick:I,disabled:!h.apiKey||s||w,variant:"secondary",children:s?g("checking"):g("check")})})]}),u&&(0,d.jsx)(o.Badge,{variant:"success"===u?"success":"error",children:"success"===u?g("valid"):g("invalid")}),z&&(0,d.jsx)("div",{className:"text-sm text-red-500 bg-red-500/10 border border-red-500/20 rounded-lg px-3 py-2",children:z})]}),F&&(0,d.jsx)(p.Input,{label:"Base URL",value:h.baseUrl,onChange:a=>i({...h,baseUrl:a.target.value}),placeholder:G,hint:"Custom base URL for bailian-coding-plan provider"}),!K&&(0,d.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,d.jsxs)("label",{className:"text-sm font-medium text-text-main",children:["Extra API Keys",(0,d.jsx)("span",{className:"ml-2 text-[11px] font-normal text-text-muted",children:"(round-robin rotation — optional)"})]}),B.length>0&&(0,d.jsx)("div",{className:"flex flex-col gap-1.5",children:B.map((a,b)=>(0,d.jsxs)("div",{className:"flex items-center gap-2",children:[(0,d.jsx)("span",{className:"flex-1 font-mono text-xs bg-sidebar/50 px-3 py-2 rounded border border-border text-text-muted truncate",children:`Key #${b+2}: ${a.slice(0,6)}...${a.slice(-4)}`}),(0,d.jsx)("button",{onClick:()=>C(B.filter((a,c)=>c!==b)),className:"p-1.5 rounded hover:bg-red-500/10 text-red-400 hover:text-red-500",title:"Remove this key",children:(0,d.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},b))}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)("input",{type:"password",value:D,onChange:a=>E(a.target.value),placeholder:"Add another API key...",className:"flex-1 text-sm bg-sidebar/50 border border-border rounded px-3 py-2 text-text-main placeholder:text-text-muted focus:ring-1 focus:ring-primary outline-none",onKeyDown:a=>{"Enter"===a.key&&D.trim()&&(C([...B,D.trim()]),E(""))}}),(0,d.jsx)("button",{onClick:()=>{D.trim()&&(C([...B,D.trim()]),E(""))},disabled:!D.trim(),className:"px-3 py-2 rounded bg-primary/10 text-primary hover:bg-primary/20 disabled:opacity-40 text-sm font-medium",children:"Add"})]}),B.length>0&&(0,d.jsxs)("p",{className:"text-[11px] text-text-muted",children:[B.length+1," keys total — rotating round-robin on each request."]})]}),!L&&(0,d.jsxs)("div",{className:"flex items-center gap-3",children:[(0,d.jsx)(n.Button,{onClick:H,variant:"secondary",disabled:j,children:j?g("testing"):g("testConnection")}),m&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.Badge,{variant:m.valid?"success":"error",children:m.valid?g("valid"):g("failed")}),M&&(0,d.jsx)(o.Badge,{variant:M.variant,children:g(M.labelKey)})]})]}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(n.Button,{onClick:J,fullWidth:!0,disabled:w,children:w?g("saving"):g("save")}),(0,d.jsx)(n.Button,{onClick:f,variant:"ghost",fullWidth:!0,children:g("cancel")})]})]})})}function Q({isOpen:a,node:b,onSave:c,onClose:f,isAnthropic:g}){let h=(0,k.useTranslations)("providers"),[i,j]=(0,e.useState)({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1",chatPath:"",modelsPath:""}),[l,m]=(0,e.useState)(!1),[r,s]=(0,e.useState)(""),[t,u]=(0,e.useState)(!1),[v,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(!1);(0,e.useEffect)(()=>{b&&(j({name:b.name||"",prefix:b.prefix||"",apiType:b.apiType||"chat",baseUrl:b.baseUrl||(g?"https://api.anthropic.com/v1":"https://api.openai.com/v1"),chatPath:b.chatPath||"",modelsPath:b.modelsPath||""}),z(!!(b.chatPath||b.modelsPath)))},[b,g]);let A=[{value:"chat",label:h("chatCompletions")},{value:"responses",label:h("responsesApi")}],B=async()=>{if(i.name.trim()&&i.prefix.trim()&&i.baseUrl.trim()){m(!0);try{let a={name:i.name,prefix:i.prefix,baseUrl:i.baseUrl,chatPath:i.chatPath||"",modelsPath:i.modelsPath||""};g||(a.apiType=i.apiType),await c(a)}finally{m(!1)}}},C=async()=>{u(!0);try{let a=await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:i.baseUrl,apiKey:r,type:g?"anthropic-compatible":"openai-compatible",modelsPath:i.modelsPath||""})}),b=await a.json();x(b.valid?"success":"failed")}catch{x("failed")}finally{u(!1)}};return b?(0,d.jsx)(q.Modal,{isOpen:a,title:h("editCompatibleTitle",{type:h(g?"anthropic":"openai")}),onClose:f,children:(0,d.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,d.jsx)(p.Input,{label:h("nameLabel"),value:i.name,onChange:a=>j({...i,name:a.target.value}),placeholder:h("compatibleProdPlaceholder",{type:h(g?"anthropic":"openai")}),hint:h("nameHint")}),(0,d.jsx)(p.Input,{label:h("prefixLabel"),value:i.prefix,onChange:a=>j({...i,prefix:a.target.value}),placeholder:h(g?"anthropicPrefixPlaceholder":"openaiPrefixPlaceholder"),hint:h("prefixHint")}),!g&&(0,d.jsx)(w.Select,{label:h("apiTypeLabel"),options:A,value:i.apiType,onChange:a=>j({...i,apiType:a.target.value})}),(0,d.jsx)(p.Input,{label:h("baseUrlLabel"),value:i.baseUrl,onChange:a=>j({...i,baseUrl:a.target.value}),placeholder:h(g?"anthropicBaseUrlPlaceholder":"openaiBaseUrlPlaceholder"),hint:h("compatibleBaseUrlHint",{type:h(g?"anthropic":"openai")})}),(0,d.jsxs)("button",{type:"button",className:"text-sm text-text-muted hover:text-text-primary flex items-center gap-1",onClick:()=>z(!y),"aria-expanded":y,"aria-controls":"advanced-settings",children:[(0,d.jsx)("span",{className:`transition-transform ${y?"rotate-90":""}`,"aria-hidden":"true",children:"▶"}),h("advancedSettings")]}),y&&(0,d.jsxs)("div",{id:"advanced-settings",className:"flex flex-col gap-3 pl-2 border-l-2 border-border",children:[(0,d.jsx)(p.Input,{label:h("chatPathLabel"),value:i.chatPath,onChange:a=>j({...i,chatPath:a.target.value}),placeholder:g?"/messages":h("chatPathPlaceholder"),hint:h("chatPathHint")}),(0,d.jsx)(p.Input,{label:h("modelsPathLabel"),value:i.modelsPath,onChange:a=>j({...i,modelsPath:a.target.value}),placeholder:h("modelsPathPlaceholder"),hint:h("modelsPathHint")})]}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(p.Input,{label:h("apiKeyForCheck"),type:"password",value:r,onChange:a=>s(a.target.value),className:"flex-1"}),(0,d.jsx)("div",{className:"pt-6",children:(0,d.jsx)(n.Button,{onClick:C,disabled:!r||t||!i.baseUrl.trim(),variant:"secondary",children:h(t?"checking":"check")})})]}),v&&(0,d.jsx)(o.Badge,{variant:"success"===v?"success":"error",children:h("success"===v?"valid":"invalid")}),(0,d.jsxs)("div",{className:"flex gap-2",children:[(0,d.jsx)(n.Button,{onClick:B,fullWidth:!0,disabled:!i.name.trim()||!i.prefix.trim()||!i.baseUrl.trim()||l,children:h(l?"saving":"save")}),(0,d.jsx)(n.Button,{onClick:f,variant:"ghost",fullWidth:!0,children:h("cancel")})]})]})}):null}M.propTypes={connection:g.default.shape({id:g.default.string,name:g.default.string,email:g.default.string,displayName:g.default.string,rateLimitedUntil:g.default.string,rateLimitProtection:g.default.bool,testStatus:g.default.string,isActive:g.default.bool,priority:g.default.number,lastError:g.default.string,lastErrorType:g.default.string,lastErrorSource:g.default.string,errorCode:g.default.oneOfType([g.default.string,g.default.number]),globalPriority:g.default.number,providerSpecificData:g.default.object}).isRequired,isOAuth:g.default.bool.isRequired,isCodex:g.default.bool,isFirst:g.default.bool.isRequired,isLast:g.default.bool.isRequired,onMoveUp:g.default.func.isRequired,onMoveDown:g.default.func.isRequired,onToggleActive:g.default.func.isRequired,onToggleRateLimit:g.default.func.isRequired,onToggleCodex5h:g.default.func,onToggleCodexWeekly:g.default.func,onRetest:g.default.func.isRequired,isRetesting:g.default.bool,onEdit:g.default.func.isRequired,onDelete:g.default.func.isRequired,onReauth:g.default.func},N.propTypes={isOpen:g.default.bool.isRequired,provider:g.default.string,providerName:g.default.string,isCompatible:g.default.bool,isAnthropic:g.default.bool,onSave:g.default.func.isRequired,onClose:g.default.func.isRequired},P.propTypes={isOpen:g.default.bool.isRequired,connection:g.default.shape({id:g.default.string,name:g.default.string,email:g.default.string,priority:g.default.number,authType:g.default.string,provider:g.default.string}),onSave:g.default.func.isRequired,onClose:g.default.func.isRequired},Q.propTypes={isOpen:g.default.bool.isRequired,node:g.default.shape({id:g.default.string,name:g.default.string,prefix:g.default.string,apiType:g.default.string,baseUrl:g.default.string,chatPath:g.default.string,modelsPath:g.default.string}),onSave:g.default.func.isRequired,onClose:g.default.func.isRequired,isAnthropic:g.default.bool},a.s(["default",()=>F]),c()}catch(a){c(a)}},!1)];
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=src_d3225e36._.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<!DOCTYPE html><!--
|
|
2
|
-
@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding-right:23px;font-size:24px;font-weight:500;vertical-align:top">500</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:28px">Internal Server Error.</h2></div></div></div><!--$--><!--/$--><script src="/_next/static/chunks/e22b90cf374c3818.js" id="_R_" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\n2:I[339756,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"default\"]\n3:I[837457,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"default\"]\n4:I[897367,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"OutletBoundary\"]\n5:\"$Sreact.suspense\"\n7:I[897367,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"ViewportBoundary\"]\n9:I[897367,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"MetadataBoundary\"]\nb:I[168027,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"0:{\"P\":null,\"b\":\"
|
|
1
|
+
<!DOCTYPE html><!--yygubF7HqPRxaseKRZqYC--><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/_next/static/chunks/e22b90cf374c3818.js"/><script src="/_next/static/chunks/3dd6d23a48e5d078.js" async=""></script><script src="/_next/static/chunks/726579f2940c2a2f.js" async=""></script><script src="/_next/static/chunks/b133d1854532ff8c.js" async=""></script><script src="/_next/static/chunks/c88fcc5f8b21ff92.js" async=""></script><script src="/_next/static/chunks/turbopack-858efc89e955ca00.js" async=""></script><script src="/_next/static/chunks/d96012bcfc98706a.js" async=""></script><script src="/_next/static/chunks/16ea27c3b926bc31.js" async=""></script><meta name="next-size-adjust" content=""/><title>500: Internal Server Error.</title><script src="/_next/static/chunks/a6dad97d9634a72d.js" noModule=""></script></head><body><div hidden=""><!--$--><!--/$--></div><div style="font-family:system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div style="line-height:48px"><style>body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}
|
|
2
|
+
@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding-right:23px;font-size:24px;font-weight:500;vertical-align:top">500</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:28px">Internal Server Error.</h2></div></div></div><!--$--><!--/$--><script src="/_next/static/chunks/e22b90cf374c3818.js" id="_R_" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\n2:I[339756,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"default\"]\n3:I[837457,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"default\"]\n4:I[897367,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"OutletBoundary\"]\n5:\"$Sreact.suspense\"\n7:I[897367,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"ViewportBoundary\"]\n9:I[897367,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"MetadataBoundary\"]\nb:I[168027,[\"/_next/static/chunks/d96012bcfc98706a.js\",\"/_next/static/chunks/16ea27c3b926bc31.js\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"0:{\"P\":null,\"b\":\"yygubF7HqPRxaseKRZqYC\",\"c\":[\"\",\"_global-error\"],\"q\":\"\",\"i\":false,\"f\":[[[\"\",{\"children\":[\"__PAGE__\",{}]}],[[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$L2\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L3\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}],{\"children\":[[\"$\",\"$1\",\"c\",{\"children\":[[\"$\",\"html\",null,{\"id\":\"__next_error__\",\"children\":[[\"$\",\"head\",null,{\"children\":[\"$\",\"title\",null,{\"children\":\"500: Internal Server Error.\"}]}],[\"$\",\"body\",null,{\"children\":[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"style\":{\"lineHeight\":\"48px\"},\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}\\n@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"paddingRight\":23,\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\"},\"children\":\"500\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"28px\"},\"children\":\"Internal Server Error.\"}]}]]}]}]}]]}],[[\"$\",\"script\",\"script-0\",{\"src\":\"/_next/static/chunks/d96012bcfc98706a.js\",\"async\":true,\"nonce\":\"$undefined\"}],[\"$\",\"script\",\"script-1\",{\"src\":\"/_next/static/chunks/16ea27c3b926bc31.js\",\"async\":true,\"nonce\":\"$undefined\"}]],[\"$\",\"$L4\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.MetadataOutlet\",\"children\":\"$@6\"}]}]]}],{},null,false,false]},null,false,false],[\"$\",\"$1\",\"h\",{\"children\":[null,[\"$\",\"$L7\",null,{\"children\":\"$L8\"}],[\"$\",\"div\",null,{\"hidden\":true,\"children\":[\"$\",\"$L9\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.Metadata\",\"children\":\"$La\"}]}]}],[\"$\",\"meta\",null,{\"name\":\"next-size-adjust\",\"content\":\"\"}]]}],false]],\"m\":\"$undefined\",\"G\":[\"$b\",\"$undefined\"],\"S\":true}\n"])</script><script>self.__next_f.push([1,"8:[[\"$\",\"meta\",\"0\",{\"charSet\":\"utf-8\"}],[\"$\",\"meta\",\"1\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}]]\n"])</script><script>self.__next_f.push([1,"6:null\na:[]\n"])</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
self.__RSC_SERVER_MANIFEST="{\n \"node\": {},\n \"edge\": {},\n \"encryptionKey\": \"
|
|
1
|
+
self.__RSC_SERVER_MANIFEST="{\n \"node\": {},\n \"edge\": {},\n \"encryptionKey\": \"DKO58nUyPsjx3O1mtnxCqECke7C6jEhmntavi3BSer0=\"\n}"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,804730,t=>{t.v({name:"omniroute",version:"2.8.
|
|
1
|
+
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,804730,t=>{t.v({name:"omniroute",version:"2.8.8",description:"Smart AI Router with auto fallback — route to FREE & cheap models, zero downtime. Works with Cursor, Cline, Claude Desktop, Codex, and any OpenAI-compatible tool.",type:"module",bin:{omniroute:"bin/omniroute.mjs","omniroute-reset-password":"bin/reset-password.mjs"},files:["bin/","app/","open-sse/mcp-server/","src/shared/contracts/","scripts/postinstall.mjs","scripts/native-binary-compat.mjs","README.md","LICENSE"],workspaces:["open-sse"],engines:{node:">=18.0.0 <24.0.0"},keywords:["ai","router","proxy","openai","claude","anthropic","gemini","fallback","cursor","cline","codex","llm","auto-fallback"],license:"MIT",author:"diegosouzapw",repository:{type:"git",url:"https://github.com/diegosouzapw/OmniRoute"},homepage:"https://omniroute.online",scripts:{dev:"node scripts/run-next.mjs dev",build:"next build","build:cli":"node scripts/prepublish.mjs",start:"node scripts/run-next.mjs start",lint:"eslint .","electron:dev":'concurrently "npm run dev" "wait-on http://localhost:20128 && cd electron && npm run dev"',"electron:build":"npm run build && cd electron && npm run build","electron:build:win":"npm run build && cd electron && npm run build:win","electron:build:mac":"npm run build && cd electron && npm run build:mac","electron:build:linux":"npm run build && cd electron && npm run build:linux",test:"node --import tsx/esm --test tests/unit/*.test.mjs","test:unit":"node --import tsx/esm --test tests/unit/*.test.mjs","test:plan3":"node --import tsx/esm --test tests/unit/plan3-p0.test.mjs","test:fixes":"node --import tsx/esm --test tests/unit/fixes-p1.test.mjs","test:security":"node --import tsx/esm --test tests/unit/security-fase01.test.mjs","check:cycles":"node scripts/check-cycles.mjs","check:route-validation:t06":"node scripts/check-route-validation.mjs","check:any-budget:t11":"node scripts/check-t11-any-budget.mjs","check:docs-sync":"node scripts/check-docs-sync.mjs","typecheck:core":"tsc --pretty false -p tsconfig.typecheck-core.json","typecheck:noimplicit:core":"tsc --pretty false -p tsconfig.typecheck-noimplicit-core.json","test:integration":"node --import tsx/esm --test tests/integration/*.test.mjs","test:e2e":"node scripts/run-playwright-tests.mjs test tests/e2e/*.spec.ts","test:protocols:e2e":"node scripts/run-protocol-clients-tests.mjs","test:vitest":"vitest run open-sse/mcp-server/__tests__/*.test.ts open-sse/services/autoCombo/__tests__/*.test.ts","test:ecosystem":"node scripts/run-ecosystem-tests.mjs","test:coverage":"npx c8 --exclude=open-sse --check-coverage --lines 50 --functions 50 --branches 50 node --import tsx/esm --test tests/unit/*.test.mjs","test:all":"npm run test:unit && npm run test:vitest && npm run test:ecosystem && npm run test:e2e",check:"npm run lint && npm run test",prepublishOnly:"npm run build:cli",postinstall:"node scripts/postinstall.mjs",prepare:"husky","system-info":"node scripts/system-info.mjs"},dependencies:{"@modelcontextprotocol/sdk":"^1.27.1","@monaco-editor/react":"^4.7.0",bcryptjs:"^3.0.3","better-sqlite3":"^12.6.2",bottleneck:"^2.19.5",dompurify:"^3.3.2",express:"^5.2.1","fetch-socks":"^1.3.2","http-proxy-middleware":"^3.0.5","https-proxy-agent":"^8.0.0",jose:"^6.1.3",lowdb:"^7.0.1","monaco-editor":"^0.55.1",next:"^16.1.6","next-intl":"^4.8.3","node-machine-id":"^1.1.12",open:"^11.0.0",ora:"^9.1.0",pino:"^10.3.1","pino-pretty":"^13.1.3",react:"19.2.4","react-dom":"19.2.4",recharts:"^3.7.0",selfsigned:"^5.5.0",tsx:"^4.21.0",undici:"^7.19.2",uuid:"^13.0.0","wreq-js":"^2.0.1",zod:"^4.3.6",zustand:"^5.0.10","@swc/helpers":"0.5.19"},devDependencies:{"@playwright/test":"^1.58.2","@tailwindcss/postcss":"^4.1.18","@types/bcryptjs":"^3.0.0","@types/better-sqlite3":"^7.6.13","@types/node":"^25.2.3","@types/react":"^19.2.14","@types/react-dom":"^19.2.3",concurrently:"^9.2.1","cross-env":"^10.1.0",eslint:"^9.39.2","eslint-config-next":"16.1.6",husky:"^9.1.7","lint-staged":"^16.2.7",prettier:"^3.8.1",tailwindcss:"^4",typescript:"^5.9.3","typescript-eslint":"^8.56.0",vitest:"^4.0.18","wait-on":"^9.0.4"},"lint-staged":{"*.{js,jsx,ts,tsx,mjs}":["prettier --write","eslint --fix --no-error-on-unmatched-pattern"],"*.{json,md,yml,yaml,css}":["prettier --write"]},pnpm:{onlyBuiltDependencies:["@parcel/watcher","@swc/core","better-sqlite3","esbuild","omniroute","sharp"]}})},175696,t=>{"use strict";var e=t.i(861745),s=t.i(843476);function n({locale:t,...n}){if(!t)throw Error(void 0);return(0,s.jsx)(e.IntlProvider,{locale:t,...n})}t.s(["default",()=>n])}]);
|