omniroute 2.7.5 → 2.7.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.
Files changed (100) hide show
  1. package/app/.next/BUILD_ID +1 -1
  2. package/app/.next/build-manifest.json +2 -2
  3. package/app/.next/prerender-manifest.json +3 -3
  4. package/app/.next/server/app/(dashboard)/dashboard/a2a/page_client-reference-manifest.js +1 -1
  5. package/app/.next/server/app/(dashboard)/dashboard/agents/page_client-reference-manifest.js +1 -1
  6. package/app/.next/server/app/(dashboard)/dashboard/analytics/page_client-reference-manifest.js +1 -1
  7. package/app/.next/server/app/(dashboard)/dashboard/api-manager/page_client-reference-manifest.js +1 -1
  8. package/app/.next/server/app/(dashboard)/dashboard/audit-log/page_client-reference-manifest.js +1 -1
  9. package/app/.next/server/app/(dashboard)/dashboard/auto-combo/page_client-reference-manifest.js +1 -1
  10. package/app/.next/server/app/(dashboard)/dashboard/cli-tools/page_client-reference-manifest.js +1 -1
  11. package/app/.next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
  12. package/app/.next/server/app/(dashboard)/dashboard/costs/page_client-reference-manifest.js +1 -1
  13. package/app/.next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
  14. package/app/.next/server/app/(dashboard)/dashboard/health/page_client-reference-manifest.js +1 -1
  15. package/app/.next/server/app/(dashboard)/dashboard/limits/page_client-reference-manifest.js +1 -1
  16. package/app/.next/server/app/(dashboard)/dashboard/logs/page_client-reference-manifest.js +1 -1
  17. package/app/.next/server/app/(dashboard)/dashboard/mcp/page_client-reference-manifest.js +1 -1
  18. package/app/.next/server/app/(dashboard)/dashboard/media/page_client-reference-manifest.js +1 -1
  19. package/app/.next/server/app/(dashboard)/dashboard/onboarding/page_client-reference-manifest.js +1 -1
  20. package/app/.next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
  21. package/app/.next/server/app/(dashboard)/dashboard/playground/page_client-reference-manifest.js +1 -1
  22. package/app/.next/server/app/(dashboard)/dashboard/profile/page_client-reference-manifest.js +1 -1
  23. package/app/.next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
  24. package/app/.next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
  25. package/app/.next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
  26. package/app/.next/server/app/(dashboard)/dashboard/search-tools/page_client-reference-manifest.js +1 -1
  27. package/app/.next/server/app/(dashboard)/dashboard/settings/page_client-reference-manifest.js +1 -1
  28. package/app/.next/server/app/(dashboard)/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
  29. package/app/.next/server/app/(dashboard)/dashboard/translator/page_client-reference-manifest.js +1 -1
  30. package/app/.next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
  31. package/app/.next/server/app/400/page_client-reference-manifest.js +1 -1
  32. package/app/.next/server/app/401/page_client-reference-manifest.js +1 -1
  33. package/app/.next/server/app/403/page_client-reference-manifest.js +1 -1
  34. package/app/.next/server/app/408/page_client-reference-manifest.js +1 -1
  35. package/app/.next/server/app/429/page_client-reference-manifest.js +1 -1
  36. package/app/.next/server/app/500/page_client-reference-manifest.js +1 -1
  37. package/app/.next/server/app/502/page_client-reference-manifest.js +1 -1
  38. package/app/.next/server/app/503/page_client-reference-manifest.js +1 -1
  39. package/app/.next/server/app/_global-error.html +2 -2
  40. package/app/.next/server/app/_global-error.rsc +1 -1
  41. package/app/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  42. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  43. package/app/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  44. package/app/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  45. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  46. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  47. package/app/.next/server/app/api/v1/chat/completions/route.js +2 -2
  48. package/app/.next/server/app/api/v1/completions/route.js +2 -2
  49. package/app/.next/server/app/callback/page_client-reference-manifest.js +1 -1
  50. package/app/.next/server/app/docs/page_client-reference-manifest.js +1 -1
  51. package/app/.next/server/app/forbidden/page_client-reference-manifest.js +1 -1
  52. package/app/.next/server/app/forgot-password/page_client-reference-manifest.js +1 -1
  53. package/app/.next/server/app/landing/page_client-reference-manifest.js +1 -1
  54. package/app/.next/server/app/login/page_client-reference-manifest.js +1 -1
  55. package/app/.next/server/app/maintenance/page_client-reference-manifest.js +1 -1
  56. package/app/.next/server/app/offline/page_client-reference-manifest.js +1 -1
  57. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  58. package/app/.next/server/app/privacy/page_client-reference-manifest.js +1 -1
  59. package/app/.next/server/app/status/page_client-reference-manifest.js +1 -1
  60. package/app/.next/server/app/terms/page_client-reference-manifest.js +1 -1
  61. package/app/.next/server/chunks/[root-of-the-server]__09c944b3._.js +1 -1
  62. package/app/.next/server/chunks/[root-of-the-server]__12e1b68b._.js +1 -1
  63. package/app/.next/server/chunks/[root-of-the-server]__167585da._.js +1 -1
  64. package/app/.next/server/chunks/[root-of-the-server]__7d9b23e7._.js +1 -1
  65. package/app/.next/server/chunks/[root-of-the-server]__80e3bfc3._.js +2 -2
  66. package/app/.next/server/chunks/[root-of-the-server]__84e445b2._.js +1 -1
  67. package/app/.next/server/chunks/[root-of-the-server]__92cb0def._.js +1 -1
  68. package/app/.next/server/chunks/[root-of-the-server]__db2f9fe0._.js +1 -1
  69. package/app/.next/server/chunks/[root-of-the-server]__dc47ee64._.js +1 -1
  70. package/app/.next/server/chunks/_05c48915._.js +1 -1
  71. package/app/.next/server/chunks/_2115d8de._.js +1 -1
  72. package/app/.next/server/chunks/_3ac953eb._.js +1 -1
  73. package/app/.next/server/chunks/_4b8fd853._.js +1 -1
  74. package/app/.next/server/chunks/_68683848._.js +1 -1
  75. package/app/.next/server/chunks/_ee9b677b._.js +1 -1
  76. package/app/.next/server/chunks/open-sse_services_826884e1._.js +2 -2
  77. package/app/.next/server/chunks/ssr/[root-of-the-server]__9affb65e._.js +1 -1
  78. package/app/.next/server/chunks/ssr/[root-of-the-server]__a6942102._.js +1 -1
  79. package/app/.next/server/chunks/ssr/src_55fa8e28._.js +1 -1
  80. package/app/.next/server/chunks/ssr/src_app_(dashboard)_dashboard_cc92bcad._.js +1 -1
  81. package/app/.next/server/pages/500.html +2 -2
  82. package/app/.next/server/server-reference-manifest.js +1 -1
  83. package/app/.next/server/server-reference-manifest.json +1 -1
  84. package/app/.next/static/chunks/{78578600bdb6c280.js → 31d265d1cd5222f3.js} +1 -1
  85. package/app/.next/static/chunks/{cd0b93c0ed63a487.js → 3423ff268c85cc05.js} +1 -1
  86. package/app/.next/static/chunks/8c9234a3ed7f8c07.js +1 -0
  87. package/app/CHANGELOG.md +30 -0
  88. package/app/Dockerfile +4 -0
  89. package/app/docs/openapi.yaml +1 -1
  90. package/app/open-sse/services/comboAgentMiddleware.ts +19 -0
  91. package/app/package-lock.json +2 -2
  92. package/app/package.json +1 -1
  93. package/app/src/app/(dashboard)/dashboard/combos/page.tsx +80 -0
  94. package/app/src/app/(dashboard)/dashboard/usage/components/BudgetTab.tsx +7 -2
  95. package/app/src/app/api/v1/responses/route.ts +9 -12
  96. package/package.json +1 -1
  97. package/app/.next/static/chunks/c089b7e37ffa02b7.js +0 -1
  98. /package/app/.next/static/{sr8mILxXxauNpSSzV2kMh → V_vOqF97lGIlKgf2kSlun}/_buildManifest.js +0 -0
  99. /package/app/.next/static/{sr8mILxXxauNpSSzV2kMh → V_vOqF97lGIlKgf2kSlun}/_clientMiddlewareManifest.json +0 -0
  100. /package/app/.next/static/{sr8mILxXxauNpSSzV2kMh → V_vOqF97lGIlKgf2kSlun}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,915202,e=>{"use strict";var t=e.i(843476),a=e.i(271645);e.i(565650);var s=e.i(11477),r=e.i(474078),i=e.i(87855),l=e.i(339971),o=e.i(148943),n=e.i(454149),d=e.i(95368),c=e.i(105370),m=e.i(11131);function x({children:e,content:s,position:r="top",className:i="",delayMs:l=200}){let o,[n,d]=(0,a.useState)(!1),c=(0,a.useId)(),m=(0,a.useRef)(null),x=(0,a.useCallback)(()=>{clearTimeout(m.current),m.current=setTimeout(()=>d(!0),l)},[l]),p=(0,a.useCallback)(()=>{clearTimeout(m.current),d(!1)},[]);(0,a.useEffect)(()=>()=>{clearTimeout(m.current)},[]);let u={top:"bottom-full left-1/2 -translate-x-1/2 mb-2",bottom:"top-full left-1/2 -translate-x-1/2 mt-2",left:"right-full top-1/2 -translate-y-1/2 mr-2",right:"left-full top-1/2 -translate-y-1/2 ml-2"},h=s?c:void 0,b=(0,a.isValidElement)(e)?(o=[e.props["aria-describedby"],h].filter(Boolean).join(" "),(0,a.cloneElement)(e,{"aria-describedby":o||void 0})):(0,t.jsx)("span",{tabIndex:0,"aria-describedby":h,children:e});return(0,t.jsxs)("span",{className:`relative inline-flex ${i}`,onMouseEnter:x,onMouseLeave:p,onFocus:x,onBlur:p,onKeyDown:e=>{"Escape"===e.key&&p()},children:[b,n&&s&&(0,t.jsx)("span",{id:c,role:"tooltip",className:`absolute z-50 px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900/95 rounded-md shadow-lg whitespace-nowrap pointer-events-none animate-in fade-in duration-150 motion-reduce:transition-none motion-reduce:animate-none border border-white/10 ${u[r]||u.top}`,children:s})]})}var p=e.i(556938),u=e.i(627949),h=e.i(948148);let b=/^[a-zA-Z0-9_/.-]+$/,g=[{value:"priority",labelKey:"priority",descKey:"priorityDesc",icon:"sort"},{value:"weighted",labelKey:"weighted",descKey:"weightedDesc",icon:"percent"},{value:"round-robin",labelKey:"roundRobin",descKey:"roundRobinDesc",icon:"autorenew"},{value:"random",labelKey:"random",descKey:"randomDesc",icon:"shuffle"},{value:"least-used",labelKey:"leastUsed",descKey:"leastUsedDesc",icon:"low_priority"},{value:"cost-optimized",labelKey:"costOpt",descKey:"costOptimizedDesc",icon:"savings"},{value:"fill-first",labelKey:"fillFirst",descKey:"fillFirstDesc",icon:"stacked_bar_chart"},{value:"p2c",labelKey:"p2c",descKey:"p2cDesc",icon:"compare_arrows"},{value:"strict-random",labelKey:"strictRandom",descKey:"strictRandomDesc",icon:"casino"}],f={priority:{when:"Use when you have one preferred model and only want fallback on failure.",avoid:"Avoid when you need balanced load between models.",example:"Example: Primary coding model with cheaper backup for outages."},weighted:{when:"Use when you need controlled traffic split across models.",avoid:"Avoid when weights are not maintained or you need strict fairness.",example:"Example: 80% stable model and 20% canary model for safe rollout."},"round-robin":{when:"Use when you need predictable, even request distribution.",avoid:"Avoid when model latency/cost differs significantly.",example:"Example: Same model across multiple accounts to spread throughput."},random:{when:"Use when you want a simple spread with low configuration effort.",avoid:"Avoid when requests must be distributed with strict guarantees.",example:"Example: Prototyping with equivalent models and no traffic policy."},"least-used":{when:"Use when you want adaptive balancing based on recent demand.",avoid:"Avoid when your traffic is too low to benefit from usage balancing.",example:"Example: Mixed workloads where one model tends to get overloaded."},"cost-optimized":{when:"Use when minimizing cost is the top priority.",avoid:"Avoid when pricing data is missing or outdated.",example:"Example: Batch or background jobs where lower cost matters most."},"fill-first":{when:"Use when you want to drain one provider's quota fully before moving to the next.",avoid:"Avoid when you need request-level load balancing across providers.",example:"Example: Use all $200 Deepgram credits before falling to Groq."},p2c:{when:"Use when you want low-latency selection using Power-of-Two-Choices algorithm.",avoid:"Avoid for small combos with 2 or fewer models — no benefit over round-robin.",example:"Example: High-throughput inference across 4+ equivalent model endpoints."},"strict-random":{when:"Use when you want perfectly even spread — each model used once before repeating.",avoid:"Avoid when models have different quality or latency and order matters.",example:"Example: Multiple accounts of the same model to distribute usage evenly."}},y={priority:{title:"Fail-safe baseline",description:"Use one primary model and keep fallback chain short and reliable.",tips:["Put your most reliable model first.","Keep 1-2 backup models with similar quality.","Use safe retries to absorb transient provider failures."]},weighted:{title:"Controlled traffic split",description:"Great for canary rollouts and gradual migration between models.",tips:["Start with conservative split like 90/10.","Keep the total at 100% and auto-balance after changes.","Monitor success and latency before increasing canary weight."]},"round-robin":{title:"Predictable load sharing",description:"Best when models are equivalent and you need smooth distribution.",tips:["Use at least 2 models.","Set concurrency limits to avoid burst overload.","Use queue timeout to fail fast under saturation."]},random:{title:"Quick spread with low setup",description:"Use when you need simple distribution without strict guarantees.",tips:["Use models with similar latency profiles.","Keep retries enabled to absorb random misses.","Prefer this for experimentation, not strict SLAs."]},"least-used":{title:"Adaptive balancing",description:"Routes to less-used models to reduce hotspots over time.",tips:["Works better under continuous traffic.","Combine with health checks for safer balancing.","Track per-model usage to validate distribution gains."]},"cost-optimized":{title:"Budget-first routing",description:"Routes to lower-cost models when pricing metadata is available.",tips:["Ensure pricing coverage for all selected models.","Keep a quality fallback for hard prompts.","Use for batch/background jobs where cost is the main KPI."]},"fill-first":{title:"Quota drain strategy",description:"Exhausts one provider's quota before moving to the next in chain.",tips:["Order models by free quota size — biggest first.","Enable health checks to skip drained providers.","Ideal for free-tier stacking (Deepgram → Groq → NIM)."]},p2c:{title:"Power-of-Two-Choices",description:"Picks the less-loaded of two random candidates per request — low latency at scale.",tips:["Use with 4+ models for best effect.","Requires latency telemetry enabled in Settings.","Great replacement for round-robin in high-throughput combos."]},"strict-random":{title:"Shuffle deck distribution",description:"Each model is used exactly once per cycle before reshuffling.",tips:["Use at least 2 models for meaningful distribution.","Ideal for same-model accounts to evenly spread quota.","Guarantees no model is skipped or repeated within a cycle."]}},v="omniroute:combos:hide-usage-guide",j=[{id:"free-stack",icon:"volunteer_activism",titleKey:"templateFreeStack",descKey:"templateFreeStackDesc",fallbackTitle:"Free Stack ($0)",fallbackDesc:"Round-robin across all free providers: Kiro, iFlow, Qwen, Gemini CLI. Zero cost, never stops.",strategy:"round-robin",suggestedName:"free-stack",isFeatured:!0,config:{maxRetries:3,retryDelayMs:500,healthCheckEnabled:!0}},{id:"high-availability",icon:"shield",titleKey:"templateHighAvailability",descKey:"templateHighAvailabilityDesc",fallbackTitle:"High availability",fallbackDesc:"Priority routing with health checks and safe retries.",strategy:"priority",suggestedName:"high-availability",config:{maxRetries:2,retryDelayMs:1500,healthCheckEnabled:!0}},{id:"cost-saver",icon:"savings",titleKey:"templateCostSaver",descKey:"templateCostSaverDesc",fallbackTitle:"Cost saver",fallbackDesc:"Cost-optimized routing for budget-first workloads.",strategy:"cost-optimized",suggestedName:"cost-saver",config:{maxRetries:1,retryDelayMs:500,healthCheckEnabled:!0}},{id:"balanced",icon:"balance",titleKey:"templateBalanced",descKey:"templateBalancedDesc",fallbackTitle:"Balanced load",fallbackDesc:"Least-used routing to spread demand over time.",strategy:"least-used",suggestedName:"balanced-load",config:{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0}}];function w(e){return g.find(t=>t.value===e)||g[0]}function k(e,t){return e(w(t).labelKey)}function N(e,t){return e(w(t).descKey)}function C(e,t,a){return"function"==typeof e.has&&e.has(t)?e(t):a}function S(e,t,a){let s=f[t]||f.priority;return C(e,`strategyGuide.${t}.${a}`,s[a])}function T(e,t,a){let s=y[t]||y.priority;return"tips"===a?s.tips.map((a,s)=>C(e,`strategyRecommendations.${t}.tip${s+1}`,a)):C(e,`strategyRecommendations.${t}.${a}`,s[a])}function $(e){return"string"==typeof e?{model:e,weight:0}:{model:e.model,weight:e.weight||0}}function M(){let e=(0,h.useTranslations)("combos"),l=(0,h.useTranslations)("common"),[o,d]=(0,a.useState)([]),[x,b]=(0,a.useState)(!0),[g,f]=(0,a.useState)(!1),[y,j]=(0,a.useState)(null),[w,k]=(0,a.useState)([]),[N,S]=(0,a.useState)({}),[T,$]=(0,a.useState)(null),[M,E]=(0,a.useState)(null),{copied:P,copy:R}=(0,p.useCopyToClipboard)(),q=(0,u.useNotificationStore)(),[U,B]=(0,a.useState)(null),[O,_]=(0,a.useState)(null),[H,F]=(0,a.useState)([]),[G,I]=(0,a.useState)(!0),[W,L]=(0,a.useState)("");(0,a.useEffect)(()=>{J(),fetch("/api/settings/proxy").then(e=>e.ok?e.json():null).then(e=>_(e)).catch(()=>{})},[]),(0,a.useEffect)(()=>{try{globalThis.localStorage?.getItem(v)==="1"&&I(!1)}catch{}},[]);let J=async()=>{try{let[e,t,a,s]=await Promise.all([fetch("/api/combos"),fetch("/api/providers"),fetch("/api/combos/metrics"),fetch("/api/provider-nodes")]),r=await e.json(),i=await t.json(),l=await a.json(),o=s.ok?await s.json():{nodes:[]};if(e.ok&&d(r.combos||[]),t.ok){let e=(i.connections||[]).filter(e=>"active"===e.testStatus||"success"===e.testStatus);k(e)}a.ok&&S(l.metrics||{}),F(o.nodes||[])}catch(e){console.log("Error fetching data:",e)}finally{b(!1)}},Q=async t=>{try{let a=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(a.ok)await J(),f(!1),L(t.name?.trim()||""),q.success(e("comboCreated"));else{let t=await a.json();q.error(t.error?.message||t.error||e("failedCreate"))}}catch(t){q.error(e("errorCreating"))}},Y=async(t,a)=>{try{let s=await fetch(`/api/combos/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(s.ok)await J(),j(null),q.success(e("comboUpdated"));else{let t=await s.json();q.error(t.error?.message||t.error||e("failedUpdate"))}}catch(t){q.error(e("errorUpdating"))}},V=async t=>{if(confirm(e("deleteConfirm")))try{(await fetch(`/api/combos/${t}`,{method:"DELETE"})).ok&&(d(o.filter(e=>e.id!==t)),q.success(e("comboDeleted")))}catch(t){q.error(e("errorDeleting"))}},Z=async e=>{let t=e.name.replace(/-copy(-\d+)?$/,""),a=o.map(e=>e.name),s=`${t}-copy`,r=1;for(;a.includes(s);)r++,s=`${t}-copy-${r}`;let i={name:s,models:e.models,strategy:e.strategy||"priority",config:e.config||{}};await Q(i)},X=async t=>{E(t.name),$(null);try{let e=await fetch("/api/combos/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboName:t.name})}),a=await e.json();$(a)}catch(t){$({error:e("testFailed")}),q.error(e("testFailed"))}},ee=async t=>{let a=!1===t.isActive;d(e=>e.map(e=>e.id===t.id?{...e,isActive:a}:e));try{await fetch(`/api/combos/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:a})})}catch(s){d(e=>e.map(e=>e.id===t.id?{...e,isActive:!a}:e)),q.error(e("failedToggle"))}};return x?(0,t.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,t.jsx)(n.CardSkeleton,{}),(0,t.jsx)(n.CardSkeleton,{})]}):(0,t.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-semibold",children:e("title")}),(0,t.jsx)("p",{className:"text-sm text-text-muted mt-1",children:e("description")})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[!G&&(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:()=>{I(!0);try{globalThis.localStorage?.removeItem(v)}catch{}},children:C(e,"usageGuideShow","Show guide")}),(0,t.jsx)(r.Button,{icon:"add",onClick:()=>f(!0),children:e("createCombo")})]})]}),G&&(0,t.jsx)(D,{onHide:()=>I(!1),onHideForever:()=>{I(!1);try{globalThis.localStorage?.setItem(v,"1")}catch{}}}),W&&(0,t.jsx)(s.Card,{padding:"sm",className:"border border-emerald-500/20 bg-emerald-500/[0.04] dark:bg-emerald-500/[0.08]",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-emerald-700 dark:text-emerald-300",children:C(e,"quickTestTitle",`Combo "${W}" ready to validate`)}),(0,t.jsx)("code",{className:"inline-block text-[11px] mt-0.5 px-1.5 py-0.5 rounded bg-emerald-500/15 text-emerald-700 dark:text-emerald-300",children:W}),(0,t.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:C(e,"quickTestDescription","Run a test now to confirm fallback and latency behavior.")})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(r.Button,{size:"sm",variant:"secondary",icon:"play_arrow",onClick:()=>{X({name:W}),L("")},children:C(e,"testNow","Test now")}),(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:()=>L(""),children:l("close")})]})]})}),0===o.length?(0,t.jsx)(m.EmptyState,{icon:"🧩",title:e("noCombosYet"),description:e("description"),actionLabel:e("createCombo"),onAction:()=>f(!0)}):(0,t.jsx)("div",{className:"flex flex-col gap-4",children:o.map(e=>(0,t.jsx)(K,{combo:e,metrics:N[e.name],providerNodes:H,copied:P,onCopy:R,onEdit:()=>j(e),onDelete:()=>V(e.id),onDuplicate:()=>Z(e),onTest:()=>X(e),testing:M===e.name,onProxy:()=>B(e),hasProxy:!!O?.combos?.[e.id],onToggle:()=>ee(e)},e.id))}),T&&(0,t.jsx)(i.Modal,{isOpen:!!T,onClose:()=>{$(null),E(null)},title:e("testResults",{name:M}),children:(0,t.jsx)(A,{results:T})}),(0,t.jsx)(z,{isOpen:g,onClose:()=>f(!1),onSave:Q,activeProviders:w,combo:null},"create"),(0,t.jsx)(z,{isOpen:!!y,combo:y,onClose:()=>j(null),onSave:e=>Y(y.id,e),activeProviders:w},y?.id||"new"),U&&(0,t.jsx)(c.ProxyConfigModal,{isOpen:!!U,onClose:()=>B(null),level:"combo",levelId:U.id,levelLabel:U.name})]})}function D({onHide:e,onHideForever:a}){let i=(0,h.useTranslations)("combos");return(0,t.jsxs)(s.Card,{padding:"sm",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("div",{className:"size-7 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:(0,t.jsx)("span",{className:"material-symbols-outlined text-primary text-[16px]",children:"tips_and_updates"})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold",children:i("routingStrategy")}),(0,t.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:i("description")})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:e,className:"!h-6 px-2 text-[10px]",children:C(i,"usageGuideHide","Hide")}),(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:a,className:"!h-6 px-2 text-[10px]",children:C(i,"usageGuideDontShowAgain","Don't show again")})]})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2 mt-3",children:["priority","cost-optimized","least-used"].map(e=>{let a=w(e);return(0,t.jsxs)("div",{className:"rounded-lg border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.02] p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] text-primary",children:a.icon}),(0,t.jsx)("span",{className:"text-xs font-medium",children:k(i,e)})]}),(0,t.jsx)("p",{className:"text-[11px] leading-4 text-text-muted mt-1.5",children:N(i,e)})]},e)})})]})}function E({strategy:e}){let a=(0,h.useTranslations)("combos");return(0,t.jsxs)("div",{className:"rounded-lg border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.02] p-2.5",children:[(0,t.jsx)("div",{className:"text-[11px] text-text-muted",children:C(a,"strategyGuideTitle","How to use this strategy")}),(0,t.jsxs)("div",{className:"mt-1.5 flex flex-col gap-1.5 text-[11px]",children:[(0,t.jsxs)("p",{className:"text-text-main",children:[(0,t.jsxs)("span",{className:"font-semibold",children:[C(a,"strategyGuideWhen","When to use"),":"]})," ",S(a,e,"when")]}),(0,t.jsxs)("p",{className:"text-text-main",children:[(0,t.jsxs)("span",{className:"font-semibold",children:[C(a,"strategyGuideAvoid","Avoid when"),":"]})," ",S(a,e,"avoid")]}),(0,t.jsxs)("p",{className:"text-text-main",children:[(0,t.jsxs)("span",{className:"font-semibold",children:[C(a,"strategyGuideExample","Example"),":"]})," ",S(a,e,"example")]})]})]})}function P({strategy:e,onApply:a,showNudge:s}){let i=(0,h.useTranslations)("combos"),l=k(i,e),o=T(i,e,"title"),n=T(i,e,"description"),d=T(i,e,"tips");return(0,t.jsxs)("div",{className:"rounded-lg border border-black/10 dark:border-white/10 bg-white/70 dark:bg-white/[0.02] p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-[11px] text-text-muted",children:C(i,"recommendationsLabel","Recommended setup")}),(0,t.jsxs)("p",{className:"text-xs font-semibold text-text-main mt-0.5",children:[o," · ",(0,t.jsx)("span",{className:"text-primary",children:l})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:n})]}),(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:a,className:"!h-6 px-2 text-[10px]",children:C(i,"applyRecommendations","Apply recommendations")})]}),(0,t.jsx)("div",{className:"mt-2 grid grid-cols-1 gap-1",children:d.map((a,s)=>(0,t.jsxs)("div",{className:"flex items-start gap-1 rounded-md bg-black/[0.02] dark:bg-white/[0.03] px-1.5 py-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px] text-primary mt-0.5",children:"check"}),(0,t.jsx)("p",{className:"text-[10px] text-text-main",children:a})]},`${e}-tip-${s+1}`))}),s&&(0,t.jsx)("div",{"data-testid":"strategy-change-nudge",className:"mt-2 rounded-md border border-primary/20 bg-primary/10 px-2 py-1 text-[10px] text-primary",children:C(i,"recommendationsUpdated","Recommendations updated for {strategy}.").replace("{strategy}",l)})]})}function R({label:e,help:a}){return(0,t.jsxs)("div",{className:"flex items-center gap-1 mb-0.5",children:[(0,t.jsx)("label",{className:"text-[10px] text-text-muted",children:e}),(0,t.jsx)(x,{content:a,children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px] text-text-muted cursor-help",children:"help"})})]})}function q({checks:e,blockers:a}){let s=(0,h.useTranslations)("combos"),r=a.length>0;return(0,t.jsxs)("div",{"data-testid":"combo-readiness-panel",className:`rounded-lg border px-2.5 py-2 ${r?"border-amber-500/30 bg-amber-500/5":"border-emerald-500/20 bg-emerald-500/[0.04]"}`,children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[14px] ${r?"text-amber-600 dark:text-amber-400":"text-emerald-600 dark:text-emerald-400"}`,children:r?"rule":"check_circle"}),(0,t.jsx)("p",{className:"text-[11px] font-medium text-text-main",children:C(s,"readinessTitle","Ready to save?")})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:C(s,"readinessDescription","Review the checklist before creating or updating this combo.")}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-1 mt-2",children:e.map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-1 rounded-md px-1.5 py-1 bg-black/[0.02] dark:bg-white/[0.02]",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[12px] ${e.ok?"text-emerald-500":"text-amber-500"}`,children:e.ok?"task_alt":"pending"}),(0,t.jsx)("span",{className:"text-[10px] text-text-main",children:e.label})]},e.id))}),r&&(0,t.jsxs)("div",{"data-testid":"combo-save-blockers",className:"mt-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1.5",children:[(0,t.jsx)("p",{className:"text-[10px] font-medium text-amber-700 dark:text-amber-300",children:C(s,"saveBlockedTitle","Save is blocked until the following items are fixed:")}),(0,t.jsx)("div",{className:"mt-1 flex flex-col gap-0.5",children:a.map((e,a)=>(0,t.jsxs)("p",{className:"text-[10px] text-amber-700 dark:text-amber-300",children:["• ",e]},`${e}-${a}`))})]})]})}function K({combo:e,metrics:a,copied:r,onCopy:i,onEdit:l,onDelete:n,onDuplicate:d,onTest:c,testing:m,onProxy:p,hasProxy:u,onToggle:b,providerNodes:g}){let f=e.strategy||"priority",y=e.models||[],v=!1===e.isActive,j=(0,h.useTranslations)("combos"),w=(0,h.useTranslations)("common"),C=N(j,f);return(0,t.jsx)(s.Card,{padding:"sm",className:`group ${v?"opacity-50":""}`,children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,t.jsx)("div",{className:"size-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:(0,t.jsx)("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"text-sm font-medium font-mono truncate",children:e.name}),(0,t.jsx)(x,{content:C,children:(0,t.jsx)("span",{className:`text-[9px] uppercase font-semibold px-1.5 py-0.5 rounded-full ${"weighted"===f?"bg-amber-500/15 text-amber-600 dark:text-amber-400":"round-robin"===f?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"random"===f?"bg-purple-500/15 text-purple-600 dark:text-purple-400":"least-used"===f?"bg-cyan-500/15 text-cyan-600 dark:text-cyan-400":"cost-optimized"===f?"bg-teal-500/15 text-teal-600 dark:text-teal-400":"fill-first"===f?"bg-orange-500/15 text-orange-600 dark:text-orange-400":"p2c"===f?"bg-indigo-500/15 text-indigo-600 dark:text-indigo-400":"bg-blue-500/15 text-blue-600 dark:text-blue-400"}`,children:k(j,f)})}),u&&(0,t.jsxs)("span",{className:"text-[9px] uppercase font-semibold px-1.5 py-0.5 rounded-full bg-primary/15 text-primary flex items-center gap-0.5",title:j("proxyConfigured"),children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"vpn_lock"}),"proxy"]}),(0,t.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.name,`combo-${e.id}`)},className:"p-0.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors opacity-100 md:opacity-0 md:group-hover:opacity-100",title:j("copyComboName"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:r===`combo-${e.id}`?"check":"content_copy"})})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[0===y.length?(0,t.jsx)("span",{className:"text-xs text-text-muted italic",children:j("noModels")}):y.slice(0,3).map((e,a)=>{let{model:s,weight:r}=$(e);return(0,t.jsxs)("code",{className:"text-[10px] font-mono bg-black/5 dark:bg-white/5 px-1.5 py-0.5 rounded text-text-muted",children:[(e=>{let t=e.split("/");if(2!==t.length)return e;let[a,s]=t,r=(g||[]).find(e=>e.id===a||e.prefix===a);return r?`${r.name}/${s}`:e})(s),"weighted"===f&&r>0?` (${r}%)`:""]},a)}),y.length>3&&(0,t.jsx)("span",{className:"text-[10px] text-text-muted",children:j("more",{count:y.length-3})})]}),a&&(0,t.jsxs)("div",{className:"flex items-center gap-3 mt-1",children:[(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:[(0,t.jsx)("span",{className:"text-emerald-500",children:a.totalSuccesses}),"/",a.totalRequests," ",j("reqs")]}),(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:[a.successRate,"% ",j("success")]}),(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:["~",a.avgLatencyMs,"ms"]}),a.fallbackRate>0&&(0,t.jsxs)("span",{className:"text-[10px] text-amber-500",children:[a.fallbackRate,"% fallback"]})]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[(0,t.jsx)(o.Toggle,{size:"sm",checked:!v,onChange:b,title:j(v?"enableCombo":"disableCombo")}),(0,t.jsxs)("div",{className:"flex items-center gap-1 transition-opacity",children:[(0,t.jsx)("button",{onClick:c,disabled:m,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-emerald-500 transition-colors",title:j("testCombo"),children:(0,t.jsx)("span",{className:`material-symbols-outlined text-[16px] ${m?"animate-spin":""}`,children:m?"progress_activity":"play_arrow"})}),(0,t.jsx)("button",{onClick:d,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors",title:j("duplicate"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"content_copy"})}),(0,t.jsx)("button",{onClick:p,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors",title:j("proxyConfig"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"vpn_lock"})}),(0,t.jsx)("button",{onClick:l,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors",title:w("edit"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"edit"})}),(0,t.jsx)("button",{onClick:n,className:"p-1.5 hover:bg-red-500/10 rounded text-red-500 transition-colors",title:w("delete"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]})]})})}function A({results:e}){return e.error?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-red-500 text-sm",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"error"}),"string"==typeof e.error?e.error:JSON.stringify(e.error)]}):(0,t.jsxs)("div",{className:"flex flex-col gap-2",children:[e.resolvedBy&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-emerald-500 text-[18px]",children:"check_circle"}),(0,t.jsxs)("span",{children:["Resolved by:"," ",(0,t.jsx)("code",{className:"text-xs bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 px-1.5 py-0.5 rounded",children:e.resolvedBy})]})]}),e.results?.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs px-2 py-1.5 rounded bg-black/[0.02] dark:bg-white/[0.02]",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[14px] ${"ok"===e.status?"text-emerald-500":"skipped"===e.status?"text-text-muted":"text-red-500"}`,children:"ok"===e.status?"check_circle":"skipped"===e.status?"skip_next":"error"}),(0,t.jsx)("code",{className:"font-mono flex-1",children:e.model}),void 0!==e.latencyMs&&(0,t.jsxs)("span",{className:"text-text-muted",children:[e.latencyMs,"ms"]}),(0,t.jsx)("span",{className:`text-[10px] uppercase font-medium ${"ok"===e.status?"text-emerald-500":"skipped"===e.status?"text-text-muted":"text-red-500"}`,children:e.status})]},a))]})}function z({isOpen:e,combo:s,onClose:o,onSave:n,activeProviders:c}){let m=(0,h.useTranslations)("combos"),p=(0,h.useTranslations)("common"),f=(0,u.useNotificationStore)(),[y,v]=(0,a.useState)(s?.name||""),[w,S]=(0,a.useState)(()=>(s?.models||[]).map(e=>$(e))),[T,M]=(0,a.useState)(s?.strategy||"priority"),[D,K]=(0,a.useState)(!1),[A,z]=(0,a.useState)(!1),[B,O]=(0,a.useState)(""),[_,H]=(0,a.useState)({}),[F,G]=(0,a.useState)({}),[I,W]=(0,a.useState)([]),[L,J]=(0,a.useState)(!1),[Q,Y]=(0,a.useState)(s?.config||{}),[V,Z]=(0,a.useState)(!1),X=(0,a.useRef)(!1),ee=(0,a.useCallback)(e=>{let t=e.split("/");if(2!==t.length)return!1;let[a,s]=t,r=I.find(e=>e.id===a||e.prefix===a),i=[a];return r?.apiType&&i.push(r.apiType),r?.name&&i.push(String(r.name).toLowerCase()),i.some(e=>!!_?.[e]?.[s])},[_,I]),[et,ea]=(0,a.useState)(null),[es,er]=(0,a.useState)(null),ei=w.reduce((e,t)=>e+(t.weight||0),0),el=w.reduce((e,t)=>e+ +!!ee(t.model),0),eo=w.length>0?Math.round(el/w.length*100):0,en=0===w.length,ed="round-robin"===T&&1===w.length,ec="cost-optimized"===T&&w.length>0&&0===el,em="cost-optimized"===T&&w.length>0&&el>0&&el<w.length,ex="weighted"===T&&w.length>0&&100!==ei,ep=!y.trim()||!!B||A||en||ex||ec,eu=[{id:"name",ok:!!y.trim()&&!B,label:C(m,"readinessCheckName","Combo name is valid")},{id:"models",ok:!en,label:C(m,"readinessCheckModels","At least one model is selected")},{id:"weights",ok:"weighted"!==T||!ex,label:"weighted"===T?C(m,"readinessCheckWeights","Weighted total is 100%"):C(m,"readinessCheckWeightsOptional","Weight rule not required")},{id:"pricing",ok:"cost-optimized"!==T||!ec,label:"cost-optimized"===T?C(m,"readinessCheckPricing","Pricing data is available"):C(m,"readinessCheckPricingOptional","Pricing rule not required")}],eh=[];y.trim()?B&&eh.push(B):eh.push(C(m,"saveBlockName","Define a combo name.")),en&&eh.push(C(m,"saveBlockModels","Add at least one model.")),ex&&eh.push("function"==typeof m.has&&m.has("saveBlockWeighted")?m("saveBlockWeighted",{total:ei}):`Set weights to 100% (current: ${ei}%).`),ec&&eh.push(C(m,"saveBlockPricing","Add pricing for at least one model or choose a different strategy."));let eb=async()=>{try{let[e,t,a]=await Promise.all([fetch("/api/models/alias"),fetch("/api/provider-nodes"),fetch("/api/pricing")]);if(!e.ok||!t.ok)throw Error(`Failed to fetch data: aliases=${e.status}, nodes=${t.status}`);let s=a.ok?await a.json():{},[r,i]=await Promise.all([e.json(),t.json()]);H(s&&"object"==typeof s&&!Array.isArray(s)?s:{}),G(r.aliases||{}),W(i.nodes||[])}catch(e){console.error("Error fetching modal data:",e)}};(0,a.useEffect)(()=>{e&&eb()},[e]),(0,a.useEffect)(()=>{if(!X.current){X.current=!0;return}Z(!0);let e=setTimeout(()=>Z(!1),2600);return()=>clearTimeout(e)},[T]);let eg=e=>e.trim()?b.test(e)?(O(""),!0):(O(m("nameInvalid")),!1):(O(m("nameRequired")),!1),ef=()=>{let e=w.length;if(0===e)return;let t=Math.floor(100/e),a=100-t*e;S(w.map((e,s)=>({...e,weight:t+(0===s?a:0)})))},ey=[{model:"gc/gemini-3-flash-preview",weight:0},{model:"kr/claude-sonnet-4.5",weight:0},{model:"if/kimi-k2-thinking",weight:0},{model:"if/qwen3-coder-plus",weight:0},{model:"qw/qwen3-coder-plus",weight:0},{model:"nvidia/llama-3.3-70b-instruct",weight:0},{model:"groq/llama-3.3-70b-versatile",weight:0}],ev=(0,a.useCallback)(e=>{let t=e.split("/");if(2!==t.length)return e;let[a,s]=t,r=I.find(e=>e.id===a||e.prefix===a);return r?`${r.name}/${s}`:e},[I]),ej=e=>{e.target&&(e.currentTarget.style.opacity="1"),ea(null),er(null)},ew=async()=>{if(!eg(y)||en||ex||ec)return;z(!0);let e={name:y.trim(),models:"weighted"===T?w:w.map(e=>e.model),strategy:T},t={...Q};"round-robin"===T&&(void 0!==Q.concurrencyPerModel&&(t.concurrencyPerModel=Q.concurrencyPerModel),void 0!==Q.queueTimeoutMs&&(t.queueTimeoutMs=Q.queueTimeoutMs)),Object.keys(t).length>0&&(e.config=t),await n(e),z(!1)},ek=!!s;return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(i.Modal,{isOpen:e,onClose:o,title:ek?m("editCombo"):m("createCombo"),size:"full",children:(0,t.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(l.Input,{label:m("comboName"),value:y,onChange:e=>{let t=e.target.value;v(t),t?eg(t):O("")},placeholder:m("comboNamePlaceholder"),error:B}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:m("nameHint")})]}),!ek&&(0,t.jsxs)("div",{className:"rounded-lg border border-black/8 dark:border-white/8 bg-black/[0.02] dark:bg-white/[0.02] p-3",children:[(0,t.jsxs)("div",{className:"mb-2",children:[(0,t.jsx)("p",{className:"text-xs font-medium",children:C(m,"templatesTitle","Quick templates")}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:C(m,"templatesDescription","Apply a starting profile, then adjust models and config.")})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-1",children:j.map(e=>(0,t.jsxs)("button",{type:"button",onClick:()=>{M(e.strategy),Y(t=>({...t,...e.config})),y.trim()||v(e.suggestedName),"free-stack"===e.id&&S(ey)},className:`text-left rounded-md border px-3 py-2 transition-all ${e.isFeatured?"border-emerald-500/50 bg-emerald-500/5 hover:border-emerald-500/80 hover:bg-emerald-500/10 ring-1 ring-emerald-500/20":"border-black/10 dark:border-white/10 bg-white/70 dark:bg-white/[0.03] hover:border-primary/40 hover:bg-primary/5"}`,children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[16px] ${e.isFeatured?"text-emerald-500":"text-primary"}`,children:e.icon}),(0,t.jsx)("span",{className:"text-[12px] font-semibold text-text-main",children:C(m,e.titleKey,e.fallbackTitle)}),e.isFeatured&&(0,t.jsx)("span",{className:"ml-auto text-[9px] font-bold uppercase tracking-wide bg-emerald-500/20 text-emerald-600 dark:text-emerald-400 px-1.5 py-0.5 rounded",children:"FREE"})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-1.5 leading-[1.5]",children:C(m,e.descKey,e.fallbackDesc)}),(0,t.jsxs)("p",{className:`text-[10px] mt-1.5 font-medium ${e.isFeatured?"text-emerald-500":"text-primary"}`,children:[C(m,"templateApply","Apply template")," →"]})]},e.id))})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,t.jsx)("label",{className:"text-sm font-medium",children:m("routingStrategy")}),(0,t.jsx)(x,{content:N(m,T),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[13px] text-text-muted cursor-help",children:"help"})})]}),(0,t.jsx)("div",{className:"grid grid-cols-3 gap-1 p-0.5 bg-black/5 dark:bg-white/5 rounded-lg",children:g.map(e=>(0,t.jsxs)("button",{onClick:()=>M(e.value),"data-testid":`strategy-option-${e.value}`,title:m(e.descKey),"aria-label":`${k(m,e.value)}. ${m(e.descKey)}`,className:`py-1.5 px-2 rounded-md text-xs font-medium transition-all ${T===e.value?"bg-white dark:bg-bg-main shadow-sm text-primary":"text-text-muted hover:text-text-main"}`,children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] align-middle mr-0.5",children:e.icon}),k(m,e.value)]},e.value))}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:N(m,T)}),(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(E,{strategy:T})}),(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(P,{strategy:T,onApply:()=>{let e={priority:{maxRetries:2,retryDelayMs:1500,healthCheckEnabled:!0},weighted:{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0},"round-robin":{maxRetries:1,retryDelayMs:750,healthCheckEnabled:!0,concurrencyPerModel:3,queueTimeoutMs:3e4},random:{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0},"least-used":{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0},"cost-optimized":{maxRetries:1,retryDelayMs:500,healthCheckEnabled:!0}},t=e[T]||e.priority;Y(e=>{let a={...e};for(let[e,s]of Object.entries(t))(void 0===a[e]||null===a[e]||""===a[e])&&(a[e]=s);return a}),"weighted"===T&&w.length>1&&ef(),"round-robin"===T&&J(!0),f.success(C(m,"recommendationsApplied","Recommendations applied to this combo."))},showNudge:V})})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,t.jsx)("label",{className:"text-sm font-medium",children:m("models")}),"weighted"===T&&w.length>1&&(0,t.jsx)("button",{onClick:ef,className:"text-[10px] text-primary hover:text-primary/80 transition-colors",children:m("autoBalance")})]}),0===w.length?(0,t.jsxs)("div",{className:"text-center py-4 border border-dashed border-black/10 dark:border-white/10 rounded-lg bg-black/[0.01] dark:bg-white/[0.01]",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-text-muted text-xl mb-1",children:"layers"}),(0,t.jsx)("p",{className:"text-xs text-text-muted",children:m("noModelsYet")})]}):(0,t.jsx)("div",{className:"flex flex-col gap-1 max-h-[240px] overflow-y-auto",children:w.map((e,a)=>(0,t.jsxs)("div",{draggable:!0,onDragStart:e=>{ea(a),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",a.toString()),e.target&&setTimeout(()=>e.currentTarget.style.opacity="0.5",0)},onDragEnd:ej,onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move",er(a)},onDrop:e=>((e,t)=>{if(e.preventDefault(),null===et||et===t)return;let a=[...w],[s]=a.splice(et,1);a.splice(t,0,s),S(a),ea(null),er(null)})(e,a),className:`group/item flex items-center gap-1.5 px-2 py-1.5 rounded-md transition-all cursor-grab active:cursor-grabbing ${es===a&&et!==a?"bg-primary/10 border border-primary/30":"bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.04] dark:hover:bg-white/[0.04] border border-transparent"} ${et===a?"opacity-50":""}`,children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] text-text-muted/40 cursor-grab shrink-0",children:"drag_indicator"}),(0,t.jsx)("span",{className:"text-[10px] font-medium text-text-muted w-3 text-center shrink-0",children:a+1}),(0,t.jsx)("div",{className:"flex-1 min-w-0 px-1 text-xs text-text-main truncate",children:ev(e.model)}),"cost-optimized"===T&&(0,t.jsx)("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase font-semibold ${ee(e.model)?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"bg-amber-500/15 text-amber-600 dark:text-amber-400"}`,title:ee(e.model)?C(m,"pricingAvailable","Pricing available"):C(m,"pricingMissing","No pricing"),children:ee(e.model)?C(m,"pricingAvailableShort","priced"):C(m,"pricingMissingShort","no-price")}),"weighted"===T&&(0,t.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,t.jsx)("input",{type:"number",min:"0",max:"100",value:e.weight,onChange:e=>{var t;let s;return t=e.target.value,void((s=[...w])[a]={...s[a],weight:Math.max(0,Math.min(100,Number(t)||0))},S(s))},className:"w-10 text-[11px] text-center py-0.5 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"}),(0,t.jsx)("span",{className:"text-[10px] text-text-muted",children:"%"})]}),"priority"===T&&(0,t.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,t.jsx)("button",{onClick:()=>(e=>{if(0===e)return;let t=[...w];[t[e-1],t[e]]=[t[e],t[e-1]],S(t)})(a),disabled:0===a,className:`p-0.5 rounded ${0===a?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:m("moveUp"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_upward"})}),(0,t.jsx)("button",{onClick:()=>(e=>{if(e===w.length-1)return;let t=[...w];[t[e],t[e+1]]=[t[e+1],t[e]],S(t)})(a),disabled:a===w.length-1,className:`p-0.5 rounded ${a===w.length-1?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:m("moveDown"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_downward"})})]}),(0,t.jsx)("button",{onClick:()=>{S(w.filter((e,t)=>t!==a))},className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all",title:m("removeModel"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},`${e.model}-${a}`))}),"weighted"===T&&w.length>0&&(0,t.jsx)(U,{models:w}),"cost-optimized"===T&&w.length>0&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.02] px-2 py-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between text-[10px]",children:[(0,t.jsx)("span",{className:"text-text-muted",children:C(m,"pricingCoverage","Pricing coverage")}),(0,t.jsxs)("span",{className:"font-medium text-text-main",children:[el,"/",w.length," (",eo,"%)"]})]}),(0,t.jsx)("div",{className:"h-1.5 mt-1 rounded-full bg-black/10 dark:bg-white/10 overflow-hidden",children:(0,t.jsx)("div",{className:`h-full transition-all duration-300 ${100===eo?"bg-emerald-500":eo>0?"bg-amber-500":"bg-red-500"}`,style:{width:`${eo}%`}})}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-1",children:C(m,"pricingCoverageHint","Cost-optimized works best when all combo models have pricing.")})]}),en&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsx)("span",{children:m("noModelsYet")})]}),ex&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsxs)("span",{children:[m("weighted")," ",ei,"% ","≠"," 100%. ",m("autoBalance")]})]}),ed&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-blue-500/20 bg-blue-500/10 px-2 py-1.5 text-[10px] text-blue-700 dark:text-blue-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"info"}),(0,t.jsx)("span",{children:C(m,"warningRoundRobinSingleModel","Round-robin is most useful with at least 2 models.")})]}),em&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsx)("span",{children:"function"==typeof m.has&&m.has("warningCostOptimizedPartialPricing")?m("warningCostOptimizedPartialPricing",{priced:el,total:w.length}):`Only ${el} of ${w.length} models have pricing. Routing may be partially cost-aware.`})]}),ec&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsx)("span",{children:C(m,"warningCostOptimizedNoPricing","No pricing data found for this combo. Cost-optimized may route unexpectedly.")})]}),(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(q,{checks:eu,blockers:eh})}),(0,t.jsxs)("button",{onClick:()=>K(!0),className:"w-full mt-2 py-2 border border-dashed border-black/10 dark:border-white/10 rounded-lg text-xs text-text-muted hover:text-primary hover:border-primary/30 transition-colors flex items-center justify-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),m("addModel")]})]}),(0,t.jsxs)("button",{onClick:()=>J(!L),className:"flex items-center gap-1 text-xs text-text-muted hover:text-text-main transition-colors self-start",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:L?"expand_less":"expand_more"}),m("advancedSettings")]}),L&&(0,t.jsxs)("div",{className:"flex flex-col gap-2 p-3 bg-black/[0.02] dark:bg-white/[0.02] rounded-lg border border-black/5 dark:border-white/5",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(R,{label:m("maxRetries"),help:C(m,"advancedHelp.maxRetries","How many retries are attempted before failing the request.")}),(0,t.jsx)("input",{type:"number",min:"0",max:"10",value:Q.maxRetries??"",placeholder:"1",onChange:e=>Y({...Q,maxRetries:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(R,{label:m("retryDelay"),help:C(m,"advancedHelp.retryDelay","Initial delay between retries. Higher values reduce burst pressure.")}),(0,t.jsx)("input",{type:"number",min:"0",max:"60000",step:"500",value:Q.retryDelayMs??"",placeholder:"2000",onChange:e=>Y({...Q,retryDelayMs:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(R,{label:m("timeout"),help:C(m,"advancedHelp.timeout","Maximum request time before aborting. Set higher for long generations.")}),(0,t.jsx)("input",{type:"number",min:"1000",max:"600000",step:"1000",value:Q.timeoutMs??"",placeholder:"120000",onChange:e=>Y({...Q,timeoutMs:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)(R,{label:m("healthcheck"),help:C(m,"advancedHelp.healthcheck","Skips unhealthy models/providers from routing decisions when enabled.")}),(0,t.jsx)("input",{type:"checkbox",checked:!1!==Q.healthCheckEnabled,onChange:e=>Y({...Q,healthCheckEnabled:e.target.checked}),className:"accent-primary"})]})]}),"round-robin"===T&&(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2 pt-2 border-t border-black/5 dark:border-white/5",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(R,{label:m("concurrencyPerModel"),help:C(m,"advancedHelp.concurrencyPerModel","Max simultaneous requests sent to each model in round-robin.")}),(0,t.jsx)("input",{type:"number",min:"1",max:"20",value:Q.concurrencyPerModel??"",placeholder:"3",onChange:e=>Y({...Q,concurrencyPerModel:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(R,{label:m("queueTimeout"),help:C(m,"advancedHelp.queueTimeout","How long a request can wait in queue before timeout in round-robin.")}),(0,t.jsx)("input",{type:"number",min:"1000",max:"120000",step:"1000",value:Q.queueTimeoutMs??"",placeholder:"30000",onChange:e=>Y({...Q,queueTimeoutMs:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted",children:m("advancedHint")})]}),(0,t.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,t.jsx)(r.Button,{onClick:o,variant:"ghost",fullWidth:!0,size:"sm",children:p("cancel")}),(0,t.jsx)(r.Button,{onClick:ew,fullWidth:!0,size:"sm",disabled:ep,children:A?m("saving"):ek?p("save"):m("createCombo")})]})]})}),(0,t.jsx)(d.ModelSelectModal,{isOpen:D,onClose:()=>K(!1),onSelect:e=>{w.find(t=>t.model===e.value)||S([...w,{model:e.value,weight:0}])},activeProviders:c,modelAliases:F,title:m("addModelToCombo"),selectedModel:null,addedModelValues:w.map(e=>e.model)})]})}function U({models:e}){let a=e.reduce((e,t)=>e+(t.weight||0),0),s=100===a,r=["bg-blue-500","bg-emerald-500","bg-amber-500","bg-purple-500","bg-rose-500","bg-cyan-500","bg-orange-500","bg-indigo-500"];return(0,t.jsxs)("div",{className:"mt-1.5",children:[(0,t.jsx)("div",{className:"h-1.5 rounded-full bg-black/5 dark:bg-white/5 overflow-hidden flex",children:e.map((e,a)=>e.weight?(0,t.jsx)("div",{className:`${r[a%r.length]} transition-all duration-300`,style:{width:`${Math.min(e.weight,100)}%`}},a):null)}),(0,t.jsxs)("div",{className:"flex items-center justify-between mt-0.5",children:[(0,t.jsx)("div",{className:"flex gap-1",children:e.map((e,a)=>e.weight>0&&(0,t.jsxs)("span",{className:"flex items-center gap-0.5 text-[9px] text-text-muted",children:[(0,t.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${r[a%r.length]}`}),e.weight,"%"]},a))}),(0,t.jsxs)("span",{className:`text-[10px] font-medium ${s?"text-emerald-500":a>100?"text-red-500":"text-amber-500"}`,children:[a,"%",!s&&a>0&&" ≠ 100%"]})]})]})}e.s(["default",()=>M],915202)}]);
1
+ (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,915202,e=>{"use strict";var t=e.i(843476),a=e.i(271645);e.i(565650);var s=e.i(11477),r=e.i(474078),i=e.i(87855),l=e.i(339971),o=e.i(148943),n=e.i(454149),d=e.i(95368),c=e.i(105370),m=e.i(11131);function x({children:e,content:s,position:r="top",className:i="",delayMs:l=200}){let o,[n,d]=(0,a.useState)(!1),c=(0,a.useId)(),m=(0,a.useRef)(null),x=(0,a.useCallback)(()=>{clearTimeout(m.current),m.current=setTimeout(()=>d(!0),l)},[l]),p=(0,a.useCallback)(()=>{clearTimeout(m.current),d(!1)},[]);(0,a.useEffect)(()=>()=>{clearTimeout(m.current)},[]);let u={top:"bottom-full left-1/2 -translate-x-1/2 mb-2",bottom:"top-full left-1/2 -translate-x-1/2 mt-2",left:"right-full top-1/2 -translate-y-1/2 mr-2",right:"left-full top-1/2 -translate-y-1/2 ml-2"},h=s?c:void 0,b=(0,a.isValidElement)(e)?(o=[e.props["aria-describedby"],h].filter(Boolean).join(" "),(0,a.cloneElement)(e,{"aria-describedby":o||void 0})):(0,t.jsx)("span",{tabIndex:0,"aria-describedby":h,children:e});return(0,t.jsxs)("span",{className:`relative inline-flex ${i}`,onMouseEnter:x,onMouseLeave:p,onFocus:x,onBlur:p,onKeyDown:e=>{"Escape"===e.key&&p()},children:[b,n&&s&&(0,t.jsx)("span",{id:c,role:"tooltip",className:`absolute z-50 px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900/95 rounded-md shadow-lg whitespace-nowrap pointer-events-none animate-in fade-in duration-150 motion-reduce:transition-none motion-reduce:animate-none border border-white/10 ${u[r]||u.top}`,children:s})]})}var p=e.i(556938),u=e.i(627949),h=e.i(948148);let b=/^[a-zA-Z0-9_/.-]+$/,g=[{value:"priority",labelKey:"priority",descKey:"priorityDesc",icon:"sort"},{value:"weighted",labelKey:"weighted",descKey:"weightedDesc",icon:"percent"},{value:"round-robin",labelKey:"roundRobin",descKey:"roundRobinDesc",icon:"autorenew"},{value:"random",labelKey:"random",descKey:"randomDesc",icon:"shuffle"},{value:"least-used",labelKey:"leastUsed",descKey:"leastUsedDesc",icon:"low_priority"},{value:"cost-optimized",labelKey:"costOpt",descKey:"costOptimizedDesc",icon:"savings"},{value:"fill-first",labelKey:"fillFirst",descKey:"fillFirstDesc",icon:"stacked_bar_chart"},{value:"p2c",labelKey:"p2c",descKey:"p2cDesc",icon:"compare_arrows"},{value:"strict-random",labelKey:"strictRandom",descKey:"strictRandomDesc",icon:"casino"}],f={priority:{when:"Use when you have one preferred model and only want fallback on failure.",avoid:"Avoid when you need balanced load between models.",example:"Example: Primary coding model with cheaper backup for outages."},weighted:{when:"Use when you need controlled traffic split across models.",avoid:"Avoid when weights are not maintained or you need strict fairness.",example:"Example: 80% stable model and 20% canary model for safe rollout."},"round-robin":{when:"Use when you need predictable, even request distribution.",avoid:"Avoid when model latency/cost differs significantly.",example:"Example: Same model across multiple accounts to spread throughput."},random:{when:"Use when you want a simple spread with low configuration effort.",avoid:"Avoid when requests must be distributed with strict guarantees.",example:"Example: Prototyping with equivalent models and no traffic policy."},"least-used":{when:"Use when you want adaptive balancing based on recent demand.",avoid:"Avoid when your traffic is too low to benefit from usage balancing.",example:"Example: Mixed workloads where one model tends to get overloaded."},"cost-optimized":{when:"Use when minimizing cost is the top priority.",avoid:"Avoid when pricing data is missing or outdated.",example:"Example: Batch or background jobs where lower cost matters most."},"fill-first":{when:"Use when you want to drain one provider's quota fully before moving to the next.",avoid:"Avoid when you need request-level load balancing across providers.",example:"Example: Use all $200 Deepgram credits before falling to Groq."},p2c:{when:"Use when you want low-latency selection using Power-of-Two-Choices algorithm.",avoid:"Avoid for small combos with 2 or fewer models — no benefit over round-robin.",example:"Example: High-throughput inference across 4+ equivalent model endpoints."},"strict-random":{when:"Use when you want perfectly even spread — each model used once before repeating.",avoid:"Avoid when models have different quality or latency and order matters.",example:"Example: Multiple accounts of the same model to distribute usage evenly."}},y={priority:{title:"Fail-safe baseline",description:"Use one primary model and keep fallback chain short and reliable.",tips:["Put your most reliable model first.","Keep 1-2 backup models with similar quality.","Use safe retries to absorb transient provider failures."]},weighted:{title:"Controlled traffic split",description:"Great for canary rollouts and gradual migration between models.",tips:["Start with conservative split like 90/10.","Keep the total at 100% and auto-balance after changes.","Monitor success and latency before increasing canary weight."]},"round-robin":{title:"Predictable load sharing",description:"Best when models are equivalent and you need smooth distribution.",tips:["Use at least 2 models.","Set concurrency limits to avoid burst overload.","Use queue timeout to fail fast under saturation."]},random:{title:"Quick spread with low setup",description:"Use when you need simple distribution without strict guarantees.",tips:["Use models with similar latency profiles.","Keep retries enabled to absorb random misses.","Prefer this for experimentation, not strict SLAs."]},"least-used":{title:"Adaptive balancing",description:"Routes to less-used models to reduce hotspots over time.",tips:["Works better under continuous traffic.","Combine with health checks for safer balancing.","Track per-model usage to validate distribution gains."]},"cost-optimized":{title:"Budget-first routing",description:"Routes to lower-cost models when pricing metadata is available.",tips:["Ensure pricing coverage for all selected models.","Keep a quality fallback for hard prompts.","Use for batch/background jobs where cost is the main KPI."]},"fill-first":{title:"Quota drain strategy",description:"Exhausts one provider's quota before moving to the next in chain.",tips:["Order models by free quota size — biggest first.","Enable health checks to skip drained providers.","Ideal for free-tier stacking (Deepgram → Groq → NIM)."]},p2c:{title:"Power-of-Two-Choices",description:"Picks the less-loaded of two random candidates per request — low latency at scale.",tips:["Use with 4+ models for best effect.","Requires latency telemetry enabled in Settings.","Great replacement for round-robin in high-throughput combos."]},"strict-random":{title:"Shuffle deck distribution",description:"Each model is used exactly once per cycle before reshuffling.",tips:["Use at least 2 models for meaningful distribution.","Ideal for same-model accounts to evenly spread quota.","Guarantees no model is skipped or repeated within a cycle."]}},v="omniroute:combos:hide-usage-guide",j=[{id:"free-stack",icon:"volunteer_activism",titleKey:"templateFreeStack",descKey:"templateFreeStackDesc",fallbackTitle:"Free Stack ($0)",fallbackDesc:"Round-robin across all free providers: Kiro, iFlow, Qwen, Gemini CLI. Zero cost, never stops.",strategy:"round-robin",suggestedName:"free-stack",isFeatured:!0,config:{maxRetries:3,retryDelayMs:500,healthCheckEnabled:!0}},{id:"high-availability",icon:"shield",titleKey:"templateHighAvailability",descKey:"templateHighAvailabilityDesc",fallbackTitle:"High availability",fallbackDesc:"Priority routing with health checks and safe retries.",strategy:"priority",suggestedName:"high-availability",config:{maxRetries:2,retryDelayMs:1500,healthCheckEnabled:!0}},{id:"cost-saver",icon:"savings",titleKey:"templateCostSaver",descKey:"templateCostSaverDesc",fallbackTitle:"Cost saver",fallbackDesc:"Cost-optimized routing for budget-first workloads.",strategy:"cost-optimized",suggestedName:"cost-saver",config:{maxRetries:1,retryDelayMs:500,healthCheckEnabled:!0}},{id:"balanced",icon:"balance",titleKey:"templateBalanced",descKey:"templateBalancedDesc",fallbackTitle:"Balanced load",fallbackDesc:"Least-used routing to spread demand over time.",strategy:"least-used",suggestedName:"balanced-load",config:{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0}}];function w(e){return g.find(t=>t.value===e)||g[0]}function k(e,t){return e(w(t).labelKey)}function N(e,t){return e(w(t).descKey)}function C(e,t,a){return"function"==typeof e.has&&e.has(t)?e(t):a}function S(e,t,a){let s=f[t]||f.priority;return C(e,`strategyGuide.${t}.${a}`,s[a])}function T(e,t,a){let s=y[t]||y.priority;return"tips"===a?s.tips.map((a,s)=>C(e,`strategyRecommendations.${t}.tip${s+1}`,a)):C(e,`strategyRecommendations.${t}.${a}`,s[a])}function $(e){return"string"==typeof e?{model:e,weight:0}:{model:e.model,weight:e.weight||0}}function M(){let e=(0,h.useTranslations)("combos"),l=(0,h.useTranslations)("common"),[o,d]=(0,a.useState)([]),[x,b]=(0,a.useState)(!0),[g,f]=(0,a.useState)(!1),[y,j]=(0,a.useState)(null),[w,k]=(0,a.useState)([]),[N,S]=(0,a.useState)({}),[T,$]=(0,a.useState)(null),[M,P]=(0,a.useState)(null),{copied:R,copy:E}=(0,p.useCopyToClipboard)(),q=(0,u.useNotificationStore)(),[z,O]=(0,a.useState)(null),[U,B]=(0,a.useState)(null),[F,H]=(0,a.useState)([]),[I,G]=(0,a.useState)(!0),[L,W]=(0,a.useState)("");(0,a.useEffect)(()=>{J(),fetch("/api/settings/proxy").then(e=>e.ok?e.json():null).then(e=>B(e)).catch(()=>{})},[]),(0,a.useEffect)(()=>{try{globalThis.localStorage?.getItem(v)==="1"&&G(!1)}catch{}},[]);let J=async()=>{try{let[e,t,a,s]=await Promise.all([fetch("/api/combos"),fetch("/api/providers"),fetch("/api/combos/metrics"),fetch("/api/provider-nodes")]),r=await e.json(),i=await t.json(),l=await a.json(),o=s.ok?await s.json():{nodes:[]};if(e.ok&&d(r.combos||[]),t.ok){let e=(i.connections||[]).filter(e=>"active"===e.testStatus||"success"===e.testStatus);k(e)}a.ok&&S(l.metrics||{}),H(o.nodes||[])}catch(e){console.log("Error fetching data:",e)}finally{b(!1)}},Q=async t=>{try{let a=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(a.ok)await J(),f(!1),W(t.name?.trim()||""),q.success(e("comboCreated"));else{let t=await a.json();q.error(t.error?.message||t.error||e("failedCreate"))}}catch(t){q.error(e("errorCreating"))}},Y=async(t,a)=>{try{let s=await fetch(`/api/combos/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(s.ok)await J(),j(null),q.success(e("comboUpdated"));else{let t=await s.json();q.error(t.error?.message||t.error||e("failedUpdate"))}}catch(t){q.error(e("errorUpdating"))}},V=async t=>{if(confirm(e("deleteConfirm")))try{(await fetch(`/api/combos/${t}`,{method:"DELETE"})).ok&&(d(o.filter(e=>e.id!==t)),q.success(e("comboDeleted")))}catch(t){q.error(e("errorDeleting"))}},Z=async e=>{let t=e.name.replace(/-copy(-\d+)?$/,""),a=o.map(e=>e.name),s=`${t}-copy`,r=1;for(;a.includes(s);)r++,s=`${t}-copy-${r}`;let i={name:s,models:e.models,strategy:e.strategy||"priority",config:e.config||{}};await Q(i)},X=async t=>{P(t.name),$(null);try{let e=await fetch("/api/combos/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboName:t.name})}),a=await e.json();$(a)}catch(t){$({error:e("testFailed")}),q.error(e("testFailed"))}},ee=async t=>{let a=!1===t.isActive;d(e=>e.map(e=>e.id===t.id?{...e,isActive:a}:e));try{await fetch(`/api/combos/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:a})})}catch(s){d(e=>e.map(e=>e.id===t.id?{...e,isActive:!a}:e)),q.error(e("failedToggle"))}};return x?(0,t.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,t.jsx)(n.CardSkeleton,{}),(0,t.jsx)(n.CardSkeleton,{})]}):(0,t.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-2xl font-semibold",children:e("title")}),(0,t.jsx)("p",{className:"text-sm text-text-muted mt-1",children:e("description")})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[!I&&(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:()=>{G(!0);try{globalThis.localStorage?.removeItem(v)}catch{}},children:C(e,"usageGuideShow","Show guide")}),(0,t.jsx)(r.Button,{icon:"add",onClick:()=>f(!0),children:e("createCombo")})]})]}),I&&(0,t.jsx)(D,{onHide:()=>G(!1),onHideForever:()=>{G(!1);try{globalThis.localStorage?.setItem(v,"1")}catch{}}}),L&&(0,t.jsx)(s.Card,{padding:"sm",className:"border border-emerald-500/20 bg-emerald-500/[0.04] dark:bg-emerald-500/[0.08]",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-emerald-700 dark:text-emerald-300",children:C(e,"quickTestTitle",`Combo "${L}" ready to validate`)}),(0,t.jsx)("code",{className:"inline-block text-[11px] mt-0.5 px-1.5 py-0.5 rounded bg-emerald-500/15 text-emerald-700 dark:text-emerald-300",children:L}),(0,t.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:C(e,"quickTestDescription","Run a test now to confirm fallback and latency behavior.")})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(r.Button,{size:"sm",variant:"secondary",icon:"play_arrow",onClick:()=>{X({name:L}),W("")},children:C(e,"testNow","Test now")}),(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:()=>W(""),children:l("close")})]})]})}),0===o.length?(0,t.jsx)(m.EmptyState,{icon:"🧩",title:e("noCombosYet"),description:e("description"),actionLabel:e("createCombo"),onAction:()=>f(!0)}):(0,t.jsx)("div",{className:"flex flex-col gap-4",children:o.map(e=>(0,t.jsx)(A,{combo:e,metrics:N[e.name],providerNodes:F,copied:R,onCopy:E,onEdit:()=>j(e),onDelete:()=>V(e.id),onDuplicate:()=>Z(e),onTest:()=>X(e),testing:M===e.name,onProxy:()=>O(e),hasProxy:!!U?.combos?.[e.id],onToggle:()=>ee(e)},e.id))}),T&&(0,t.jsx)(i.Modal,{isOpen:!!T,onClose:()=>{$(null),P(null)},title:e("testResults",{name:M}),children:(0,t.jsx)(K,{results:T})}),(0,t.jsx)(_,{isOpen:g,onClose:()=>f(!1),onSave:Q,activeProviders:w,combo:null},"create"),(0,t.jsx)(_,{isOpen:!!y,combo:y,onClose:()=>j(null),onSave:e=>Y(y.id,e),activeProviders:w},y?.id||"new"),z&&(0,t.jsx)(c.ProxyConfigModal,{isOpen:!!z,onClose:()=>O(null),level:"combo",levelId:z.id,levelLabel:z.name})]})}function D({onHide:e,onHideForever:a}){let i=(0,h.useTranslations)("combos");return(0,t.jsxs)(s.Card,{padding:"sm",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("div",{className:"size-7 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:(0,t.jsx)("span",{className:"material-symbols-outlined text-primary text-[16px]",children:"tips_and_updates"})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold",children:i("routingStrategy")}),(0,t.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:i("description")})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:e,className:"!h-6 px-2 text-[10px]",children:C(i,"usageGuideHide","Hide")}),(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:a,className:"!h-6 px-2 text-[10px]",children:C(i,"usageGuideDontShowAgain","Don't show again")})]})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2 mt-3",children:["priority","cost-optimized","least-used"].map(e=>{let a=w(e);return(0,t.jsxs)("div",{className:"rounded-lg border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.02] p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] text-primary",children:a.icon}),(0,t.jsx)("span",{className:"text-xs font-medium",children:k(i,e)})]}),(0,t.jsx)("p",{className:"text-[11px] leading-4 text-text-muted mt-1.5",children:N(i,e)})]},e)})})]})}function P({strategy:e}){let a=(0,h.useTranslations)("combos");return(0,t.jsxs)("div",{className:"rounded-lg border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.02] p-2.5",children:[(0,t.jsx)("div",{className:"text-[11px] text-text-muted",children:C(a,"strategyGuideTitle","How to use this strategy")}),(0,t.jsxs)("div",{className:"mt-1.5 flex flex-col gap-1.5 text-[11px]",children:[(0,t.jsxs)("p",{className:"text-text-main",children:[(0,t.jsxs)("span",{className:"font-semibold",children:[C(a,"strategyGuideWhen","When to use"),":"]})," ",S(a,e,"when")]}),(0,t.jsxs)("p",{className:"text-text-main",children:[(0,t.jsxs)("span",{className:"font-semibold",children:[C(a,"strategyGuideAvoid","Avoid when"),":"]})," ",S(a,e,"avoid")]}),(0,t.jsxs)("p",{className:"text-text-main",children:[(0,t.jsxs)("span",{className:"font-semibold",children:[C(a,"strategyGuideExample","Example"),":"]})," ",S(a,e,"example")]})]})]})}function R({strategy:e,onApply:a,showNudge:s}){let i=(0,h.useTranslations)("combos"),l=k(i,e),o=T(i,e,"title"),n=T(i,e,"description"),d=T(i,e,"tips");return(0,t.jsxs)("div",{className:"rounded-lg border border-black/10 dark:border-white/10 bg-white/70 dark:bg-white/[0.02] p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-[11px] text-text-muted",children:C(i,"recommendationsLabel","Recommended setup")}),(0,t.jsxs)("p",{className:"text-xs font-semibold text-text-main mt-0.5",children:[o," · ",(0,t.jsx)("span",{className:"text-primary",children:l})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:n})]}),(0,t.jsx)(r.Button,{size:"sm",variant:"ghost",onClick:a,className:"!h-6 px-2 text-[10px]",children:C(i,"applyRecommendations","Apply recommendations")})]}),(0,t.jsx)("div",{className:"mt-2 grid grid-cols-1 gap-1",children:d.map((a,s)=>(0,t.jsxs)("div",{className:"flex items-start gap-1 rounded-md bg-black/[0.02] dark:bg-white/[0.03] px-1.5 py-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px] text-primary mt-0.5",children:"check"}),(0,t.jsx)("p",{className:"text-[10px] text-text-main",children:a})]},`${e}-tip-${s+1}`))}),s&&(0,t.jsx)("div",{"data-testid":"strategy-change-nudge",className:"mt-2 rounded-md border border-primary/20 bg-primary/10 px-2 py-1 text-[10px] text-primary",children:C(i,"recommendationsUpdated","Recommendations updated for {strategy}.").replace("{strategy}",l)})]})}function E({label:e,help:a}){return(0,t.jsxs)("div",{className:"flex items-center gap-1 mb-0.5",children:[(0,t.jsx)("label",{className:"text-[10px] text-text-muted",children:e}),(0,t.jsx)(x,{content:a,children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px] text-text-muted cursor-help",children:"help"})})]})}function q({checks:e,blockers:a}){let s=(0,h.useTranslations)("combos"),r=a.length>0;return(0,t.jsxs)("div",{"data-testid":"combo-readiness-panel",className:`rounded-lg border px-2.5 py-2 ${r?"border-amber-500/30 bg-amber-500/5":"border-emerald-500/20 bg-emerald-500/[0.04]"}`,children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[14px] ${r?"text-amber-600 dark:text-amber-400":"text-emerald-600 dark:text-emerald-400"}`,children:r?"rule":"check_circle"}),(0,t.jsx)("p",{className:"text-[11px] font-medium text-text-main",children:C(s,"readinessTitle","Ready to save?")})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:C(s,"readinessDescription","Review the checklist before creating or updating this combo.")}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-1 mt-2",children:e.map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-1 rounded-md px-1.5 py-1 bg-black/[0.02] dark:bg-white/[0.02]",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[12px] ${e.ok?"text-emerald-500":"text-amber-500"}`,children:e.ok?"task_alt":"pending"}),(0,t.jsx)("span",{className:"text-[10px] text-text-main",children:e.label})]},e.id))}),r&&(0,t.jsxs)("div",{"data-testid":"combo-save-blockers",className:"mt-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1.5",children:[(0,t.jsx)("p",{className:"text-[10px] font-medium text-amber-700 dark:text-amber-300",children:C(s,"saveBlockedTitle","Save is blocked until the following items are fixed:")}),(0,t.jsx)("div",{className:"mt-1 flex flex-col gap-0.5",children:a.map((e,a)=>(0,t.jsxs)("p",{className:"text-[10px] text-amber-700 dark:text-amber-300",children:["• ",e]},`${e}-${a}`))})]})]})}function A({combo:e,metrics:a,copied:r,onCopy:i,onEdit:l,onDelete:n,onDuplicate:d,onTest:c,testing:m,onProxy:p,hasProxy:u,onToggle:b,providerNodes:g}){let f=e.strategy||"priority",y=e.models||[],v=!1===e.isActive,j=(0,h.useTranslations)("combos"),w=(0,h.useTranslations)("common"),C=N(j,f);return(0,t.jsx)(s.Card,{padding:"sm",className:`group ${v?"opacity-50":""}`,children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,t.jsx)("div",{className:"size-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:(0,t.jsx)("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"text-sm font-medium font-mono truncate",children:e.name}),(0,t.jsx)(x,{content:C,children:(0,t.jsx)("span",{className:`text-[9px] uppercase font-semibold px-1.5 py-0.5 rounded-full ${"weighted"===f?"bg-amber-500/15 text-amber-600 dark:text-amber-400":"round-robin"===f?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"random"===f?"bg-purple-500/15 text-purple-600 dark:text-purple-400":"least-used"===f?"bg-cyan-500/15 text-cyan-600 dark:text-cyan-400":"cost-optimized"===f?"bg-teal-500/15 text-teal-600 dark:text-teal-400":"fill-first"===f?"bg-orange-500/15 text-orange-600 dark:text-orange-400":"p2c"===f?"bg-indigo-500/15 text-indigo-600 dark:text-indigo-400":"bg-blue-500/15 text-blue-600 dark:text-blue-400"}`,children:k(j,f)})}),u&&(0,t.jsxs)("span",{className:"text-[9px] uppercase font-semibold px-1.5 py-0.5 rounded-full bg-primary/15 text-primary flex items-center gap-0.5",title:j("proxyConfigured"),children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[11px]",children:"vpn_lock"}),"proxy"]}),(0,t.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.name,`combo-${e.id}`)},className:"p-0.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors opacity-100 md:opacity-0 md:group-hover:opacity-100",title:j("copyComboName"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:r===`combo-${e.id}`?"check":"content_copy"})})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[0===y.length?(0,t.jsx)("span",{className:"text-xs text-text-muted italic",children:j("noModels")}):y.slice(0,3).map((e,a)=>{let{model:s,weight:r}=$(e);return(0,t.jsxs)("code",{className:"text-[10px] font-mono bg-black/5 dark:bg-white/5 px-1.5 py-0.5 rounded text-text-muted",children:[(e=>{let t=e.split("/");if(2!==t.length)return e;let[a,s]=t,r=(g||[]).find(e=>e.id===a||e.prefix===a);return r?`${r.name}/${s}`:e})(s),"weighted"===f&&r>0?` (${r}%)`:""]},a)}),y.length>3&&(0,t.jsx)("span",{className:"text-[10px] text-text-muted",children:j("more",{count:y.length-3})})]}),a&&(0,t.jsxs)("div",{className:"flex items-center gap-3 mt-1",children:[(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:[(0,t.jsx)("span",{className:"text-emerald-500",children:a.totalSuccesses}),"/",a.totalRequests," ",j("reqs")]}),(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:[a.successRate,"% ",j("success")]}),(0,t.jsxs)("span",{className:"text-[10px] text-text-muted",children:["~",a.avgLatencyMs,"ms"]}),a.fallbackRate>0&&(0,t.jsxs)("span",{className:"text-[10px] text-amber-500",children:[a.fallbackRate,"% fallback"]})]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 ml-2",children:[(0,t.jsx)(o.Toggle,{size:"sm",checked:!v,onChange:b,title:j(v?"enableCombo":"disableCombo")}),(0,t.jsxs)("div",{className:"flex items-center gap-1 transition-opacity",children:[(0,t.jsx)("button",{onClick:c,disabled:m,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-emerald-500 transition-colors",title:j("testCombo"),children:(0,t.jsx)("span",{className:`material-symbols-outlined text-[16px] ${m?"animate-spin":""}`,children:m?"progress_activity":"play_arrow"})}),(0,t.jsx)("button",{onClick:d,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors",title:j("duplicate"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"content_copy"})}),(0,t.jsx)("button",{onClick:p,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors",title:j("proxyConfig"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"vpn_lock"})}),(0,t.jsx)("button",{onClick:l,className:"p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded text-text-muted hover:text-primary transition-colors",title:w("edit"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"edit"})}),(0,t.jsx)("button",{onClick:n,className:"p-1.5 hover:bg-red-500/10 rounded text-red-500 transition-colors",title:w("delete"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]})]})})}function K({results:e}){return e.error?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-red-500 text-sm",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[18px]",children:"error"}),"string"==typeof e.error?e.error:JSON.stringify(e.error)]}):(0,t.jsxs)("div",{className:"flex flex-col gap-2",children:[e.resolvedBy&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-emerald-500 text-[18px]",children:"check_circle"}),(0,t.jsxs)("span",{children:["Resolved by:"," ",(0,t.jsx)("code",{className:"text-xs bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 px-1.5 py-0.5 rounded",children:e.resolvedBy})]})]}),e.results?.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs px-2 py-1.5 rounded bg-black/[0.02] dark:bg-white/[0.02]",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[14px] ${"ok"===e.status?"text-emerald-500":"skipped"===e.status?"text-text-muted":"text-red-500"}`,children:"ok"===e.status?"check_circle":"skipped"===e.status?"skip_next":"error"}),(0,t.jsx)("code",{className:"font-mono flex-1",children:e.model}),void 0!==e.latencyMs&&(0,t.jsxs)("span",{className:"text-text-muted",children:[e.latencyMs,"ms"]}),(0,t.jsx)("span",{className:`text-[10px] uppercase font-medium ${"ok"===e.status?"text-emerald-500":"skipped"===e.status?"text-text-muted":"text-red-500"}`,children:e.status})]},a))]})}function _({isOpen:e,combo:s,onClose:o,onSave:n,activeProviders:c}){let m=(0,h.useTranslations)("combos"),p=(0,h.useTranslations)("common"),f=(0,u.useNotificationStore)(),[y,v]=(0,a.useState)(s?.name||""),[w,S]=(0,a.useState)(()=>(s?.models||[]).map(e=>$(e))),[T,M]=(0,a.useState)(s?.strategy||"priority"),[D,A]=(0,a.useState)(!1),[K,_]=(0,a.useState)(!1),[O,U]=(0,a.useState)(""),[B,F]=(0,a.useState)({}),[H,I]=(0,a.useState)({}),[G,L]=(0,a.useState)([]),[W,J]=(0,a.useState)(!1),[Q,Y]=(0,a.useState)(s?.config||{}),[V,Z]=(0,a.useState)(!1),X=(0,a.useRef)(!1),[ee,et]=(0,a.useState)(s?.system_message||""),[ea,es]=(0,a.useState)(s?.tool_filter_regex||""),[er,ei]=(0,a.useState)(!!s?.context_cache_protection),el=(0,a.useCallback)(e=>{let t=e.split("/");if(2!==t.length)return!1;let[a,s]=t,r=G.find(e=>e.id===a||e.prefix===a),i=[a];return r?.apiType&&i.push(r.apiType),r?.name&&i.push(String(r.name).toLowerCase()),i.some(e=>!!B?.[e]?.[s])},[B,G]),[eo,en]=(0,a.useState)(null),[ed,ec]=(0,a.useState)(null),em=w.reduce((e,t)=>e+(t.weight||0),0),ex=w.reduce((e,t)=>e+ +!!el(t.model),0),ep=w.length>0?Math.round(ex/w.length*100):0,eu=0===w.length,eh="round-robin"===T&&1===w.length,eb="cost-optimized"===T&&w.length>0&&0===ex,eg="cost-optimized"===T&&w.length>0&&ex>0&&ex<w.length,ef="weighted"===T&&w.length>0&&100!==em,ey=!y.trim()||!!O||K||eu||ef||eb,ev=[{id:"name",ok:!!y.trim()&&!O,label:C(m,"readinessCheckName","Combo name is valid")},{id:"models",ok:!eu,label:C(m,"readinessCheckModels","At least one model is selected")},{id:"weights",ok:"weighted"!==T||!ef,label:"weighted"===T?C(m,"readinessCheckWeights","Weighted total is 100%"):C(m,"readinessCheckWeightsOptional","Weight rule not required")},{id:"pricing",ok:"cost-optimized"!==T||!eb,label:"cost-optimized"===T?C(m,"readinessCheckPricing","Pricing data is available"):C(m,"readinessCheckPricingOptional","Pricing rule not required")}],ej=[];y.trim()?O&&ej.push(O):ej.push(C(m,"saveBlockName","Define a combo name.")),eu&&ej.push(C(m,"saveBlockModels","Add at least one model.")),ef&&ej.push("function"==typeof m.has&&m.has("saveBlockWeighted")?m("saveBlockWeighted",{total:em}):`Set weights to 100% (current: ${em}%).`),eb&&ej.push(C(m,"saveBlockPricing","Add pricing for at least one model or choose a different strategy."));let ew=async()=>{try{let[e,t,a]=await Promise.all([fetch("/api/models/alias"),fetch("/api/provider-nodes"),fetch("/api/pricing")]);if(!e.ok||!t.ok)throw Error(`Failed to fetch data: aliases=${e.status}, nodes=${t.status}`);let s=a.ok?await a.json():{},[r,i]=await Promise.all([e.json(),t.json()]);F(s&&"object"==typeof s&&!Array.isArray(s)?s:{}),I(r.aliases||{}),L(i.nodes||[])}catch(e){console.error("Error fetching modal data:",e)}};(0,a.useEffect)(()=>{e&&ew()},[e]),(0,a.useEffect)(()=>{if(!X.current){X.current=!0;return}Z(!0);let e=setTimeout(()=>Z(!1),2600);return()=>clearTimeout(e)},[T]);let ek=e=>e.trim()?b.test(e)?(U(""),!0):(U(m("nameInvalid")),!1):(U(m("nameRequired")),!1),eN=()=>{let e=w.length;if(0===e)return;let t=Math.floor(100/e),a=100-t*e;S(w.map((e,s)=>({...e,weight:t+(0===s?a:0)})))},eC=[{model:"gc/gemini-3-flash-preview",weight:0},{model:"kr/claude-sonnet-4.5",weight:0},{model:"if/kimi-k2-thinking",weight:0},{model:"if/qwen3-coder-plus",weight:0},{model:"qw/qwen3-coder-plus",weight:0},{model:"nvidia/llama-3.3-70b-instruct",weight:0},{model:"groq/llama-3.3-70b-versatile",weight:0}],eS=(0,a.useCallback)(e=>{let t=e.split("/");if(2!==t.length)return e;let[a,s]=t,r=G.find(e=>e.id===a||e.prefix===a);return r?`${r.name}/${s}`:e},[G]),eT=e=>{e.target&&(e.currentTarget.style.opacity="1"),en(null),ec(null)},e$=async()=>{if(!ek(y)||eu||ef||eb)return;_(!0);let e={name:y.trim(),models:"weighted"===T?w:w.map(e=>e.model),strategy:T},t={...Q};"round-robin"===T&&(void 0!==Q.concurrencyPerModel&&(t.concurrencyPerModel=Q.concurrencyPerModel),void 0!==Q.queueTimeoutMs&&(t.queueTimeoutMs=Q.queueTimeoutMs)),Object.keys(t).length>0&&(e.config=t),ee.trim()?e.system_message=ee.trim():delete e.system_message,ea.trim()?e.tool_filter_regex=ea.trim():delete e.tool_filter_regex,er?e.context_cache_protection=!0:delete e.context_cache_protection,await n(e),_(!1)},eM=!!s;return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(i.Modal,{isOpen:e,onClose:o,title:eM?m("editCombo"):m("createCombo"),size:"full",children:(0,t.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(l.Input,{label:m("comboName"),value:y,onChange:e=>{let t=e.target.value;v(t),t?ek(t):U("")},placeholder:m("comboNamePlaceholder"),error:O}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:m("nameHint")})]}),!eM&&(0,t.jsxs)("div",{className:"rounded-lg border border-black/8 dark:border-white/8 bg-black/[0.02] dark:bg-white/[0.02] p-3",children:[(0,t.jsxs)("div",{className:"mb-2",children:[(0,t.jsx)("p",{className:"text-xs font-medium",children:C(m,"templatesTitle","Quick templates")}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:C(m,"templatesDescription","Apply a starting profile, then adjust models and config.")})]}),(0,t.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-1",children:j.map(e=>(0,t.jsxs)("button",{type:"button",onClick:()=>{M(e.strategy),Y(t=>({...t,...e.config})),y.trim()||v(e.suggestedName),"free-stack"===e.id&&S(eC)},className:`text-left rounded-md border px-3 py-2 transition-all ${e.isFeatured?"border-emerald-500/50 bg-emerald-500/5 hover:border-emerald-500/80 hover:bg-emerald-500/10 ring-1 ring-emerald-500/20":"border-black/10 dark:border-white/10 bg-white/70 dark:bg-white/[0.03] hover:border-primary/40 hover:bg-primary/5"}`,children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-[16px] ${e.isFeatured?"text-emerald-500":"text-primary"}`,children:e.icon}),(0,t.jsx)("span",{className:"text-[12px] font-semibold text-text-main",children:C(m,e.titleKey,e.fallbackTitle)}),e.isFeatured&&(0,t.jsx)("span",{className:"ml-auto text-[9px] font-bold uppercase tracking-wide bg-emerald-500/20 text-emerald-600 dark:text-emerald-400 px-1.5 py-0.5 rounded",children:"FREE"})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-1.5 leading-[1.5]",children:C(m,e.descKey,e.fallbackDesc)}),(0,t.jsxs)("p",{className:`text-[10px] mt-1.5 font-medium ${e.isFeatured?"text-emerald-500":"text-primary"}`,children:[C(m,"templateApply","Apply template")," →"]})]},e.id))})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,t.jsx)("label",{className:"text-sm font-medium",children:m("routingStrategy")}),(0,t.jsx)(x,{content:N(m,T),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[13px] text-text-muted cursor-help",children:"help"})})]}),(0,t.jsx)("div",{className:"grid grid-cols-3 gap-1 p-0.5 bg-black/5 dark:bg-white/5 rounded-lg",children:g.map(e=>(0,t.jsxs)("button",{onClick:()=>M(e.value),"data-testid":`strategy-option-${e.value}`,title:m(e.descKey),"aria-label":`${k(m,e.value)}. ${m(e.descKey)}`,className:`py-1.5 px-2 rounded-md text-xs font-medium transition-all ${T===e.value?"bg-white dark:bg-bg-main shadow-sm text-primary":"text-text-muted hover:text-text-main"}`,children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] align-middle mr-0.5",children:e.icon}),k(m,e.value)]},e.value))}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:N(m,T)}),(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(P,{strategy:T})}),(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(R,{strategy:T,onApply:()=>{let e={priority:{maxRetries:2,retryDelayMs:1500,healthCheckEnabled:!0},weighted:{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0},"round-robin":{maxRetries:1,retryDelayMs:750,healthCheckEnabled:!0,concurrencyPerModel:3,queueTimeoutMs:3e4},random:{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0},"least-used":{maxRetries:1,retryDelayMs:1e3,healthCheckEnabled:!0},"cost-optimized":{maxRetries:1,retryDelayMs:500,healthCheckEnabled:!0}},t=e[T]||e.priority;Y(e=>{let a={...e};for(let[e,s]of Object.entries(t))(void 0===a[e]||null===a[e]||""===a[e])&&(a[e]=s);return a}),"weighted"===T&&w.length>1&&eN(),"round-robin"===T&&J(!0),f.success(C(m,"recommendationsApplied","Recommendations applied to this combo."))},showNudge:V})})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,t.jsx)("label",{className:"text-sm font-medium",children:m("models")}),"weighted"===T&&w.length>1&&(0,t.jsx)("button",{onClick:eN,className:"text-[10px] text-primary hover:text-primary/80 transition-colors",children:m("autoBalance")})]}),0===w.length?(0,t.jsxs)("div",{className:"text-center py-4 border border-dashed border-black/10 dark:border-white/10 rounded-lg bg-black/[0.01] dark:bg-white/[0.01]",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-text-muted text-xl mb-1",children:"layers"}),(0,t.jsx)("p",{className:"text-xs text-text-muted",children:m("noModelsYet")})]}):(0,t.jsx)("div",{className:"flex flex-col gap-1 max-h-[240px] overflow-y-auto",children:w.map((e,a)=>(0,t.jsxs)("div",{draggable:!0,onDragStart:e=>{en(a),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",a.toString()),e.target&&setTimeout(()=>e.currentTarget.style.opacity="0.5",0)},onDragEnd:eT,onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ec(a)},onDrop:e=>((e,t)=>{if(e.preventDefault(),null===eo||eo===t)return;let a=[...w],[s]=a.splice(eo,1);a.splice(t,0,s),S(a),en(null),ec(null)})(e,a),className:`group/item flex items-center gap-1.5 px-2 py-1.5 rounded-md transition-all cursor-grab active:cursor-grabbing ${ed===a&&eo!==a?"bg-primary/10 border border-primary/30":"bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.04] dark:hover:bg-white/[0.04] border border-transparent"} ${eo===a?"opacity-50":""}`,children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] text-text-muted/40 cursor-grab shrink-0",children:"drag_indicator"}),(0,t.jsx)("span",{className:"text-[10px] font-medium text-text-muted w-3 text-center shrink-0",children:a+1}),(0,t.jsx)("div",{className:"flex-1 min-w-0 px-1 text-xs text-text-main truncate",children:eS(e.model)}),"cost-optimized"===T&&(0,t.jsx)("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase font-semibold ${el(e.model)?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"bg-amber-500/15 text-amber-600 dark:text-amber-400"}`,title:el(e.model)?C(m,"pricingAvailable","Pricing available"):C(m,"pricingMissing","No pricing"),children:el(e.model)?C(m,"pricingAvailableShort","priced"):C(m,"pricingMissingShort","no-price")}),"weighted"===T&&(0,t.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[(0,t.jsx)("input",{type:"number",min:"0",max:"100",value:e.weight,onChange:e=>{var t;let s;return t=e.target.value,void((s=[...w])[a]={...s[a],weight:Math.max(0,Math.min(100,Number(t)||0))},S(s))},className:"w-10 text-[11px] text-center py-0.5 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"}),(0,t.jsx)("span",{className:"text-[10px] text-text-muted",children:"%"})]}),"priority"===T&&(0,t.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,t.jsx)("button",{onClick:()=>(e=>{if(0===e)return;let t=[...w];[t[e-1],t[e]]=[t[e],t[e-1]],S(t)})(a),disabled:0===a,className:`p-0.5 rounded ${0===a?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:m("moveUp"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_upward"})}),(0,t.jsx)("button",{onClick:()=>(e=>{if(e===w.length-1)return;let t=[...w];[t[e],t[e+1]]=[t[e+1],t[e]],S(t)})(a),disabled:a===w.length-1,className:`p-0.5 rounded ${a===w.length-1?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:m("moveDown"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_downward"})})]}),(0,t.jsx)("button",{onClick:()=>{S(w.filter((e,t)=>t!==a))},className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all",title:m("removeModel"),children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},`${e.model}-${a}`))}),"weighted"===T&&w.length>0&&(0,t.jsx)(z,{models:w}),"cost-optimized"===T&&w.length>0&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.02] px-2 py-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between text-[10px]",children:[(0,t.jsx)("span",{className:"text-text-muted",children:C(m,"pricingCoverage","Pricing coverage")}),(0,t.jsxs)("span",{className:"font-medium text-text-main",children:[ex,"/",w.length," (",ep,"%)"]})]}),(0,t.jsx)("div",{className:"h-1.5 mt-1 rounded-full bg-black/10 dark:bg-white/10 overflow-hidden",children:(0,t.jsx)("div",{className:`h-full transition-all duration-300 ${100===ep?"bg-emerald-500":ep>0?"bg-amber-500":"bg-red-500"}`,style:{width:`${ep}%`}})}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-1",children:C(m,"pricingCoverageHint","Cost-optimized works best when all combo models have pricing.")})]}),eu&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsx)("span",{children:m("noModelsYet")})]}),ef&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsxs)("span",{children:[m("weighted")," ",em,"% ","≠"," 100%. ",m("autoBalance")]})]}),eh&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-blue-500/20 bg-blue-500/10 px-2 py-1.5 text-[10px] text-blue-700 dark:text-blue-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"info"}),(0,t.jsx)("span",{children:C(m,"warningRoundRobinSingleModel","Round-robin is most useful with at least 2 models.")})]}),eg&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsx)("span",{children:"function"==typeof m.has&&m.has("warningCostOptimizedPartialPricing")?m("warningCostOptimizedPartialPricing",{priced:ex,total:w.length}):`Only ${ex} of ${w.length} models have pricing. Routing may be partially cost-aware.`})]}),eb&&(0,t.jsxs)("div",{className:"mt-2 rounded-md border border-amber-500/20 bg-amber-500/10 px-2 py-1.5 text-[10px] text-amber-700 dark:text-amber-300 flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[12px]",children:"warning"}),(0,t.jsx)("span",{children:C(m,"warningCostOptimizedNoPricing","No pricing data found for this combo. Cost-optimized may route unexpectedly.")})]}),(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(q,{checks:ev,blockers:ej})}),(0,t.jsxs)("button",{onClick:()=>A(!0),className:"w-full mt-2 py-2 border border-dashed border-black/10 dark:border-white/10 rounded-lg text-xs text-text-muted hover:text-primary hover:border-primary/30 transition-colors flex items-center justify-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),m("addModel")]})]}),(0,t.jsxs)("button",{onClick:()=>J(!W),className:"flex items-center gap-1 text-xs text-text-muted hover:text-text-main transition-colors self-start",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px]",children:W?"expand_less":"expand_more"}),m("advancedSettings")]}),W&&(0,t.jsxs)("div",{className:"flex flex-col gap-2 p-3 bg-black/[0.02] dark:bg-white/[0.02] rounded-lg border border-black/5 dark:border-white/5",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(E,{label:m("maxRetries"),help:C(m,"advancedHelp.maxRetries","How many retries are attempted before failing the request.")}),(0,t.jsx)("input",{type:"number",min:"0",max:"10",value:Q.maxRetries??"",placeholder:"1",onChange:e=>Y({...Q,maxRetries:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(E,{label:m("retryDelay"),help:C(m,"advancedHelp.retryDelay","Initial delay between retries. Higher values reduce burst pressure.")}),(0,t.jsx)("input",{type:"number",min:"0",max:"60000",step:"500",value:Q.retryDelayMs??"",placeholder:"2000",onChange:e=>Y({...Q,retryDelayMs:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(E,{label:m("timeout"),help:C(m,"advancedHelp.timeout","Maximum request time before aborting. Set higher for long generations.")}),(0,t.jsx)("input",{type:"number",min:"1000",max:"600000",step:"1000",value:Q.timeoutMs??"",placeholder:"120000",onChange:e=>Y({...Q,timeoutMs:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)(E,{label:m("healthcheck"),help:C(m,"advancedHelp.healthcheck","Skips unhealthy models/providers from routing decisions when enabled.")}),(0,t.jsx)("input",{type:"checkbox",checked:!1!==Q.healthCheckEnabled,onChange:e=>Y({...Q,healthCheckEnabled:e.target.checked}),className:"accent-primary"})]})]}),"round-robin"===T&&(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2 pt-2 border-t border-black/5 dark:border-white/5",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(E,{label:m("concurrencyPerModel"),help:C(m,"advancedHelp.concurrencyPerModel","Max simultaneous requests sent to each model in round-robin.")}),(0,t.jsx)("input",{type:"number",min:"1",max:"20",value:Q.concurrencyPerModel??"",placeholder:"3",onChange:e=>Y({...Q,concurrencyPerModel:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(E,{label:m("queueTimeout"),help:C(m,"advancedHelp.queueTimeout","How long a request can wait in queue before timeout in round-robin.")}),(0,t.jsx)("input",{type:"number",min:"1000",max:"120000",step:"1000",value:Q.queueTimeoutMs??"",placeholder:"30000",onChange:e=>Y({...Q,queueTimeoutMs:e.target.value?Number(e.target.value):void 0}),className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none"})]})]}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted",children:m("advancedHint")})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-2 p-3 bg-black/[0.02] dark:bg-white/[0.02] rounded-lg border border-black/5 dark:border-white/5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[14px] text-primary",children:"smart_toy"}),(0,t.jsx)("p",{className:"text-xs font-medium",children:"Agent Features"}),(0,t.jsx)("span",{className:"text-[10px] text-text-muted",children:"— optional, for agent/tool workflows"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-[11px] font-medium text-text-muted block mb-0.5",children:"System Message Override"}),(0,t.jsx)("textarea",{rows:2,value:ee,onChange:e=>et(e.target.value),placeholder:"Override the system prompt for all requests routed through this combo…",className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none resize-none"}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:"Replaces any system message sent by the client. Leave empty to pass through client system messages."})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-[11px] font-medium text-text-muted block mb-0.5",children:"Tool Filter Regex"}),(0,t.jsx)("input",{type:"text",value:ea,onChange:e=>es(e.target.value),placeholder:"e.g. ^(bash|computer)$",className:"w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none font-mono"}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted mt-0.5",children:"Only tools whose name matches this regex are forwarded to the provider. Leave empty to forward all tools."})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-[11px] font-medium text-text-muted block",children:"Context Cache Protection"}),(0,t.jsx)("p",{className:"text-[10px] text-text-muted",children:"Pins the provider/model across turns to preserve cache sessions. Internal tags are stripped before forwarding to the provider."})]}),(0,t.jsx)("input",{type:"checkbox",checked:er,onChange:e=>ei(e.target.checked),className:"accent-primary shrink-0"})]})]}),(0,t.jsxs)("div",{className:"flex gap-2 pt-1",children:[(0,t.jsx)(r.Button,{onClick:o,variant:"ghost",fullWidth:!0,size:"sm",children:p("cancel")}),(0,t.jsx)(r.Button,{onClick:e$,fullWidth:!0,size:"sm",disabled:ey,children:K?m("saving"):eM?p("save"):m("createCombo")})]})]})}),(0,t.jsx)(d.ModelSelectModal,{isOpen:D,onClose:()=>A(!1),onSelect:e=>{w.find(t=>t.model===e.value)||S([...w,{model:e.value,weight:0}])},activeProviders:c,modelAliases:H,title:m("addModelToCombo"),selectedModel:null,addedModelValues:w.map(e=>e.model)})]})}function z({models:e}){let a=e.reduce((e,t)=>e+(t.weight||0),0),s=100===a,r=["bg-blue-500","bg-emerald-500","bg-amber-500","bg-purple-500","bg-rose-500","bg-cyan-500","bg-orange-500","bg-indigo-500"];return(0,t.jsxs)("div",{className:"mt-1.5",children:[(0,t.jsx)("div",{className:"h-1.5 rounded-full bg-black/5 dark:bg-white/5 overflow-hidden flex",children:e.map((e,a)=>e.weight?(0,t.jsx)("div",{className:`${r[a%r.length]} transition-all duration-300`,style:{width:`${Math.min(e.weight,100)}%`}},a):null)}),(0,t.jsxs)("div",{className:"flex items-center justify-between mt-0.5",children:[(0,t.jsx)("div",{className:"flex gap-1",children:e.map((e,a)=>e.weight>0&&(0,t.jsxs)("span",{className:"flex items-center gap-0.5 text-[9px] text-text-muted",children:[(0,t.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${r[a%r.length]}`}),e.weight,"%"]},a))}),(0,t.jsxs)("span",{className:`text-[10px] font-medium ${s?"text-emerald-500":a>100?"text-red-500":"text-amber-500"}`,children:[a,"%",!s&&a>0&&" ≠ 100%"]})]})]})}e.s(["default",()=>M],915202)}]);
@@ -0,0 +1 @@
1
+ (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,474078,e=>{"use strict";var t=e.i(342923);e.s(["Button",()=>t.default])},565650,e=>{"use strict";e.i(342923),e.i(80173),e.i(907714),e.i(393718),e.i(703166),e.i(454149),e.i(822124),e.i(969353),e.i(635055),e.i(897844),e.i(450222),e.i(647829),e.i(6998),e.i(982131),e.i(116016),e.i(279743),e.i(193464),e.i(548036),e.i(566770),e.i(953789),e.i(8839),e.i(227404),e.i(621745),e.i(567955),e.i(17517),e.i(419947),e.i(323060),e.i(642440),e.i(629342),e.i(816062),e.i(690777),e.i(563201),e.i(115243),e.i(165149),e.i(359505),e.s([],565650)},11477,e=>{"use strict";var t=e.i(393718);e.s(["Card",()=>t.default])},339971,e=>{"use strict";var t=e.i(80173);e.s(["Input",()=>t.default])},643953,e=>{"use strict";var t=e.i(323060);e.s(["SegmentedControl",()=>t.default])},11131,e=>{"use strict";var t=e.i(629342);e.s(["EmptyState",()=>t.default])},979765,e=>{"use strict";var t=e.i(843476),s=e.i(271645);e.i(565650);var a=e.i(643953),i=e.i(861745),l=e.i(948148),r=e.i(11477),n=e.i(474078),d=e.i(339971),o=e.i(11131),c=e.i(627949);function m({value:e,max:s,warningAt:a=.8,formatCurrency:i}){let l=s>0?Math.min(e/s*100,100):0,r=s>0?e/s:0;return(0,t.jsxs)("div",{className:"w-full",children:[(0,t.jsxs)("div",{className:"flex justify-between text-xs mb-1",children:[(0,t.jsx)("span",{className:"text-text-muted",children:i(e)}),(0,t.jsx)("span",{className:"text-text-muted",children:i(s)})]}),(0,t.jsx)("div",{className:"w-full h-2 rounded-full bg-surface/50 overflow-hidden",children:(0,t.jsx)("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${l}%`,backgroundColor:r>=1?"#ef4444":r>=a?"#f59e0b":"#22c55e"}})})]})}function u(){let e=(0,l.useTranslations)("usage"),a=(0,i.useLocale)(),[u,x]=(0,s.useState)([]),[p,h]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),[y,f]=(0,s.useState)(!0),[j,v]=(0,s.useState)(!1),[N,w]=(0,s.useState)({dailyLimitUsd:"",monthlyLimitUsd:"",warningThreshold:"80"}),C=(0,c.useNotificationStore)(),S=e=>new Intl.NumberFormat(a,{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(Number(e||0));(0,s.useEffect)(()=>{fetch("/api/keys").then(e=>e.json()).then(e=>{let t=Array.isArray(e)?e:e.keys||[];x(t),t.length>0&&h(t[0].id),f(!1)}).catch(()=>f(!1))},[]);let L=(0,s.useCallback)(async()=>{if(p)try{let e=await fetch(`/api/usage/budget?apiKeyId=${p}`);if(e.ok){let t=await e.json();b(t),t.dailyLimitUsd&&w(e=>({...e,dailyLimitUsd:String(t.dailyLimitUsd)})),t.monthlyLimitUsd&&w(e=>({...e,monthlyLimitUsd:String(t.monthlyLimitUsd)})),t.warningThreshold&&w(e=>({...e,warningThreshold:String(Math.round(100*t.warningThreshold))}))}}catch{}},[p]);(0,s.useEffect)(()=>{L()},[L]);let k=async()=>{v(!0);try{(await fetch("/api/usage/budget",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKeyId:p,dailyLimitUsd:N.dailyLimitUsd?parseFloat(N.dailyLimitUsd):null,monthlyLimitUsd:N.monthlyLimitUsd?parseFloat(N.monthlyLimitUsd):null,warningThreshold:(parseInt(N.warningThreshold)||80)/100})})).ok?(C.success(e("budgetSaved")),await L()):C.error(e("budgetSaveFailed"))}catch{C.error(e("budgetSaveFailed"))}finally{v(!1)}};if(y)return(0,t.jsxs)("div",{className:"flex items-center gap-2 text-text-muted p-8 animate-pulse",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[20px]","aria-hidden":"true",children:"account_balance_wallet"}),e("loadingBudgetData")]});if(0===u.length)return(0,t.jsx)(o.EmptyState,{icon:"vpn_key",title:e("noApiKeysTitle"),description:e("noApiKeysDescription")});let T=g?.dailyLimitUsd||parseFloat(N.dailyLimitUsd)||0,U=g?.monthlyLimitUsd||parseFloat(N.monthlyLimitUsd)||0,P=g?.totalCostToday||0,$=g?.totalCostMonth||0,D=(parseInt(N.warningThreshold)||80)/100;return(0,t.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,t.jsxs)(r.Card,{className:"p-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,t.jsx)("div",{className:"p-2 rounded-lg bg-emerald-500/10 text-emerald-500",children:(0,t.jsx)("span",{className:"material-symbols-outlined text-[20px]","aria-hidden":"true",children:"account_balance_wallet"})}),(0,t.jsx)("h3",{className:"text-lg font-semibold",children:e("budgetManagement")})]}),(0,t.jsxs)("div",{className:"mb-4",children:[(0,t.jsx)("label",{className:"text-sm text-text-muted mb-1 block",children:e("apiKey")}),(0,t.jsx)("select",{value:p||"",onChange:e=>h(e.target.value),className:"w-full md:w-auto px-3 py-2 rounded-lg border border-border/50 bg-surface/30 text-text-main text-sm focus:outline-none focus:ring-1 focus:ring-primary",children:u.map(e=>(0,t.jsxs)("option",{value:e.id,children:[e.name||e.id," ",e.provider?`(${e.provider})`:""]},e.id))})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-6",children:[(0,t.jsxs)("div",{className:"p-4 rounded-lg border border-border/30 bg-surface/20",children:[(0,t.jsx)("p",{className:"text-sm text-text-muted mb-2",children:e("todaysSpend")}),(0,t.jsx)("p",{className:"text-2xl font-bold text-text-main",children:S(P)}),T>0&&(0,t.jsx)(m,{value:P,max:T,warningAt:D,formatCurrency:S})]}),(0,t.jsxs)("div",{className:"p-4 rounded-lg border border-border/30 bg-surface/20",children:[(0,t.jsx)("p",{className:"text-sm text-text-muted mb-2",children:e("thisMonth")}),(0,t.jsx)("p",{className:"text-2xl font-bold text-text-main",children:S($)}),U>0&&(0,t.jsx)(m,{value:$,max:U,warningAt:D,formatCurrency:S})]})]}),(0,t.jsxs)("div",{className:"border-t border-border/30 pt-4",children:[(0,t.jsx)("p",{className:"text-sm font-medium mb-3",children:e("setLimits")}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-4",children:[(0,t.jsx)(d.Input,{label:e("dailyLimitUsd"),type:"number",step:"0.01",min:"0",placeholder:e("dailyLimitPlaceholder"),value:N.dailyLimitUsd,onChange:e=>w({...N,dailyLimitUsd:e.target.value})}),(0,t.jsx)(d.Input,{label:e("monthlyLimitUsd"),type:"number",step:"0.01",min:"0",placeholder:e("monthlyLimitPlaceholder"),value:N.monthlyLimitUsd,onChange:e=>w({...N,monthlyLimitUsd:e.target.value})}),(0,t.jsx)(d.Input,{label:e("warningThresholdPercent"),type:"number",min:"1",max:"100",placeholder:e("warningThresholdPlaceholder"),value:N.warningThreshold,onChange:e=>w({...N,warningThreshold:e.target.value})})]}),(0,t.jsx)(n.Button,{variant:"primary",onClick:k,loading:j,children:e("saveLimits")})]})]}),g?.budgetCheck&&(0,t.jsx)(r.Card,{className:"p-4",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-[20px]","aria-hidden":"true",style:{color:g.budgetCheck.allowed?"#22c55e":"#ef4444"},children:g.budgetCheck.allowed?"check_circle":"block"}),(0,t.jsx)("span",{className:"text-sm",children:g.budgetCheck.allowed?e("budgetOk",{remaining:S(g.budgetCheck.remaining||0)}):e("budgetExceeded")})]})})]})}let x=["input","output","cached","reasoning","cache_creation"],p={input:"input",output:"output",cached:"cached",reasoning:"reasoning",cache_creation:"cacheCreation"};function h(){let[e,a]=(0,s.useState)({}),[i,n]=(0,s.useState)({}),[d,o]=(0,s.useState)(!0),[c,m]=(0,s.useState)(!1),[u,x]=(0,s.useState)(""),[p,h]=(0,s.useState)(null),[b,y]=(0,s.useState)(new Set),[f,j]=(0,s.useState)(""),[v,N]=(0,s.useState)(new Set),w=(0,l.useTranslations)("settings");(0,s.useEffect)(()=>{C()},[]);let C=async()=>{o(!0);try{let[e,t]=await Promise.all([fetch("/api/pricing/models"),fetch("/api/pricing")]);e.ok&&a(await e.json()),t.ok&&n(await t.json())}catch(e){console.error("Failed to load pricing data:",e)}finally{o(!1)}},S=(0,s.useMemo)(()=>Object.entries(e).map(([e,t])=>({alias:e,...t,pricedModels:i[e]?Object.keys(i[e]).length:0})).sort((e,t)=>t.modelCount-e.modelCount),[e,i]),L=(0,s.useMemo)(()=>{if(!f.trim())return S;let e=f.toLowerCase();return S.filter(t=>t.alias.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||t.models.some(t=>t.id.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)))},[S,f]),k=(0,s.useMemo)(()=>{let e=S.reduce((e,t)=>e+t.modelCount,0),t=Object.values(i).reduce((e,t)=>e+Object.keys(t).length,0);return{providers:S.length,totalModels:e,pricedCount:t}},[S,i]),T=(0,s.useCallback)(e=>{y(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),U=(0,s.useCallback)((e,t,s,a)=>{let i=parseFloat(a);isNaN(i)||i<0||(n(a=>{let l={...a};return l[e]||(l[e]={}),l[e][t]||(l[e][t]={input:0,output:0,cached:0,reasoning:0,cache_creation:0}),l[e][t]={...l[e][t],[s]:i},l}),N(t=>new Set(t).add(e)))},[]),P=(0,s.useCallback)(async e=>{m(!0),x("");try{let t=i[e]||{},s=await fetch("/api/pricing",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({[e]:t})});if(s.ok)x(`✅ ${e.toUpperCase()} ${w("saved")}`),N(t=>{let s=new Set(t);return s.delete(e),s}),setTimeout(()=>x(""),3e3);else{let e=await s.json();x(`❌ ${w("errorOccurred")}: ${e.error}`)}}catch(e){x(`❌ ${w("saveFailed")}: ${e.message}`)}finally{m(!1)}},[i,w]),$=(0,s.useCallback)(async e=>{if(confirm(w("resetPricingConfirm",{provider:e.toUpperCase()})))try{let t=await fetch(`/api/pricing?provider=${e}`,{method:"DELETE"});if(t.ok){let s=await t.json();n(s),x(`🔄 ${e.toUpperCase()} ${w("resetDefaults")}`),N(t=>{let s=new Set(t);return s.delete(e),s}),setTimeout(()=>x(""),3e3)}}catch(e){x(`❌ ${w("resetFailed")}: ${e.message}`)}},[w]),D=(0,s.useCallback)(e=>{h(t=>t===e?null:e)},[]),F=(0,s.useMemo)(()=>p?L.filter(e=>e.alias===p):L,[L,p]);return d?(0,t.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,t.jsx)("div",{className:"text-text-muted animate-pulse",children:w("loadingPricing")})}):(0,t.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between flex-wrap gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-xl font-bold",children:w("modelPricing")}),(0,t.jsx)("p",{className:"text-text-muted text-sm mt-1",children:w("modelPricingDesc")})]}),(0,t.jsxs)("div",{className:"flex gap-3 text-sm",children:[(0,t.jsxs)("div",{className:"bg-bg-subtle rounded-lg px-3 py-2 text-center",children:[(0,t.jsx)("div",{className:"text-text-muted text-xs font-semibold",children:w("providers")}),(0,t.jsx)("div",{className:"text-lg font-bold",children:k.providers})]}),(0,t.jsxs)("div",{className:"bg-bg-subtle rounded-lg px-3 py-2 text-center",children:[(0,t.jsx)("div",{className:"text-text-muted text-xs font-semibold",children:w("registry")}),(0,t.jsx)("div",{className:"text-lg font-bold",children:k.totalModels})]}),(0,t.jsxs)("div",{className:"bg-bg-subtle rounded-lg px-3 py-2 text-center",children:[(0,t.jsx)("div",{className:"text-text-muted text-xs font-semibold",children:w("priced")}),(0,t.jsx)("div",{className:"text-lg font-bold text-success",children:k.pricedCount})]})]})]}),u&&(0,t.jsx)("div",{className:"px-3 py-2 rounded-lg bg-bg-subtle border border-border text-sm",children:u}),(0,t.jsxs)("div",{className:"flex gap-3 items-center flex-wrap",children:[(0,t.jsxs)("div",{className:"relative flex-1 min-w-[200px]",children:[(0,t.jsx)("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-text-muted text-lg",children:"search"}),(0,t.jsx)("input",{type:"text",placeholder:w("searchProvidersModels"),value:f,onChange:e=>j(e.target.value),className:"w-full pl-10 pr-3 py-2 bg-bg-base border border-border rounded-lg focus:outline-none focus:border-primary text-sm"})]}),p&&(0,t.jsxs)("button",{onClick:()=>h(null),className:"px-3 py-2 text-xs bg-primary/10 text-primary border border-primary/20 rounded-lg hover:bg-primary/20 transition-colors flex items-center gap-1",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-sm",children:"close"}),p.toUpperCase()," — ",w("showAll")]})]}),(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:S.map(e=>(0,t.jsxs)("button",{onClick:()=>D(e.alias),className:`px-2.5 py-1 rounded-md text-xs font-medium transition-all ${p===e.alias?"bg-primary text-white shadow-sm":v.has(e.alias)?"bg-yellow-500/15 text-yellow-400 border border-yellow-500/30":"bg-bg-subtle text-text-muted hover:bg-bg-hover border border-transparent"}`,children:[e.alias.toUpperCase()," ",(0,t.jsxs)("span",{className:"opacity-60",children:["(",e.modelCount,")"]})]},e.alias))}),(0,t.jsxs)("div",{className:"flex flex-col gap-2",children:[F.map(e=>(0,t.jsx)(g,{provider:e,pricingData:i[e.alias]||{},isExpanded:b.has(e.alias),isEdited:v.has(e.alias),onToggle:()=>T(e.alias),onPricingChange:(t,s,a)=>U(e.alias,t,s,a),onSave:()=>P(e.alias),onReset:()=>$(e.alias),saving:c},e.alias)),0===F.length&&(0,t.jsx)("div",{className:"text-center py-12 text-text-muted",children:w("noProvidersMatch")})]}),(0,t.jsxs)(r.Card,{className:"p-4 mt-2",children:[(0,t.jsxs)("h3",{className:"text-sm font-semibold mb-2",children:[(0,t.jsx)("span",{className:"material-symbols-outlined text-sm align-middle mr-1",children:"info"}),w("howPricingWorks")]}),(0,t.jsxs)("div",{className:"text-xs text-text-muted space-y-1",children:[(0,t.jsxs)("p",{children:[w("pricingDescInput")," • ",w("pricingDescOutput")," • ",w("pricingDescCached")," •"," ",w("pricingDescReasoning")," • ",w("pricingDescCacheWrite")]}),(0,t.jsx)("p",{children:w("pricingDescFormula")})]})]})]})}function g({provider:e,pricingData:s,isExpanded:a,isEdited:i,onToggle:r,onPricingChange:n,onSave:d,onReset:o,saving:c}){let m=(0,l.useTranslations)("settings"),u=(0,l.useTranslations)(),h=Object.keys(s).length,g="oauth"===e.authType?u("providers.oauthLabel"):"apikey"===e.authType?u("providers.apiKeyLabel"):e.authType;return(0,t.jsxs)("div",{className:`border rounded-lg overflow-hidden transition-colors ${i?"border-yellow-500/40 bg-yellow-500/5":"border-border"}`,children:[(0,t.jsxs)("button",{onClick:r,className:"w-full flex items-center justify-between px-4 py-3 hover:bg-bg-hover/50 transition-colors text-left",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("span",{className:`material-symbols-outlined text-lg transition-transform ${a?"rotate-90":""}`,children:"chevron_right"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"font-semibold text-sm",children:e.id.charAt(0).toUpperCase()+e.id.slice(1)}),(0,t.jsxs)("span",{className:"text-text-muted text-xs ml-2",children:["(",e.alias.toUpperCase(),")"]})]}),(0,t.jsx)("span",{className:"px-1.5 py-0.5 bg-bg-subtle text-text-muted text-[10px] rounded uppercase font-semibold",children:g}),(0,t.jsx)("span",{className:"px-1.5 py-0.5 bg-bg-subtle text-text-muted text-[10px] rounded uppercase font-semibold",children:e.format})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[i&&(0,t.jsx)("span",{className:"text-yellow-500 text-xs font-medium",children:m("unsaved")}),(0,t.jsxs)("span",{className:"text-text-muted text-xs",children:[h,"/",e.modelCount," ",m("withPricing")]}),(0,t.jsx)("div",{className:"w-16 h-1.5 bg-bg-subtle rounded-full overflow-hidden",children:(0,t.jsx)("div",{className:"h-full bg-primary rounded-full transition-all",style:{width:`${e.modelCount>0?Math.round(h/e.modelCount*100):0}%`}})})]})]}),a&&(0,t.jsxs)("div",{className:"border-t border-border",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 bg-bg-subtle/50",children:[(0,t.jsxs)("span",{className:"text-xs text-text-muted",children:[e.modelCount," ",m("models")," • ",h," ",m("withPricing")]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("button",{onClick:e=>{e.stopPropagation(),o()},className:"px-2.5 py-1 text-[11px] text-red-400 hover:bg-red-500/10 rounded border border-red-500/20 transition-colors",children:m("resetDefaults")}),(0,t.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},disabled:c||!i,className:"px-2.5 py-1 text-[11px] bg-primary text-white rounded hover:bg-primary/90 transition-colors disabled:opacity-40",children:c?m("saving"):m("saveProvider")})]})]}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full text-sm",children:[(0,t.jsx)("thead",{className:"text-[11px] text-text-muted uppercase bg-bg-subtle/30",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"px-4 py-2 text-left font-semibold",children:m("model")}),x.map(e=>(0,t.jsx)("th",{className:"px-2 py-2 text-right font-semibold w-24",children:m(p[e])},e))]})}),(0,t.jsx)("tbody",{className:"divide-y divide-border/50",children:e.models.map(e=>(0,t.jsx)(b,{model:e,pricing:s[e.id],onPricingChange:(t,s)=>n(e.id,t,s)},e.id))})]})})]})]})}function b({model:e,pricing:s,onPricingChange:a}){let i=(0,l.useTranslations)("settings"),r=s&&Object.values(s).some(e=>e>0);return(0,t.jsxs)("tr",{className:"hover:bg-bg-hover/30 group",children:[(0,t.jsx)("td",{className:"px-4 py-1.5",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:`w-1.5 h-1.5 rounded-full ${r?"bg-success":"bg-text-muted/30"}`}),(0,t.jsx)("span",{className:"font-medium text-xs",children:e.name}),e.custom&&(0,t.jsx)("span",{className:"px-1 py-0.5 text-[8px] font-bold bg-blue-500/15 text-blue-400 border border-blue-500/20 rounded uppercase",children:i("custom")}),(0,t.jsx)("span",{className:"text-text-muted text-[10px] opacity-0 group-hover:opacity-100 transition-opacity",children:e.id})]})}),x.map(e=>(0,t.jsx)("td",{className:"px-2 py-1.5",children:(0,t.jsx)("input",{type:"number",step:"0.01",min:"0",value:s?.[e]||0,onChange:t=>a(e,t.target.value),className:"w-full px-2 py-1 text-right text-xs bg-transparent border border-transparent hover:border-border focus:border-primary focus:bg-bg-base rounded transition-colors outline-none tabular-nums"})},e))]})}function y(){let[e,i]=(0,s.useState)("budget"),r=(0,l.useTranslations)("costs"),n=(0,l.useTranslations)("settings");return(0,t.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,t.jsx)(a.SegmentedControl,{options:[{value:"budget",label:r("budget")},{value:"pricing",label:n("pricing")}],value:e,onChange:i}),"budget"===e&&(0,t.jsx)(u,{}),"pricing"===e&&(0,t.jsx)(h,{})]})}e.s(["default",()=>y],979765)}]);
package/app/CHANGELOG.md CHANGED
@@ -4,6 +4,36 @@
4
4
 
5
5
  ---
6
6
 
7
+ ## [2.7.8] — 2026-03-18
8
+
9
+ > Sprint: Budget save bug + combo agent features UI + omniModel tag security fix.
10
+
11
+ ### 🐛 Bug Fixes
12
+
13
+ - **fix(budget)**: "Save Limits" no longer returns 422 — `warningThreshold` is now correctly sent as fraction (0–1) instead of percentage (0–100) (#451)
14
+ - **fix(combos)**: `<omniModel>` internal cache tag is now stripped before forwarding requests to providers, preventing cache session breaks (#454)
15
+
16
+ ### ✨ Features
17
+
18
+ - **feat(combos)**: Agent Features section added to combo create/edit modal — expose `system_message` override, `tool_filter_regex`, and `context_cache_protection` directly from the dashboard (#454)
19
+
20
+ ---
21
+
22
+ ## [2.7.7] — 2026-03-18
23
+
24
+ > Sprint: Docker pino crash, Codex CLI responses worker fix, package-lock sync.
25
+
26
+ ### 🐛 Bug Fixes
27
+
28
+ - **fix(docker)**: `pino-abstract-transport` and `pino-pretty` now explicitly copied in Docker runner stage — Next.js standalone trace misses these peer deps, causing `Cannot find module pino-abstract-transport` crash on startup (#449)
29
+ - **fix(responses)**: Remove `initTranslators()` from `/v1/responses` route — was crashing Next.js worker with `the worker has exited` uncaughtException on Codex CLI requests (#450)
30
+
31
+ ### 🔧 Maintenance
32
+
33
+ - **chore(deps)**: `package-lock.json` now committed on every version bump to ensure Docker `npm ci` uses exact dependency versions
34
+
35
+ ---
36
+
7
37
  ## [2.7.5] — 2026-03-18
8
38
 
9
39
  > Sprint: UX improvements and Windows CLI healthcheck fix.
package/app/Dockerfile CHANGED
@@ -32,6 +32,10 @@ COPY --from=builder /app/.next/static ./.next/static
32
32
  COPY --from=builder /app/.next/standalone ./
33
33
  # Explicitly copy @swc/helpers — not always traced by standalone output but needed at runtime
34
34
  COPY --from=builder /app/node_modules/@swc/helpers ./node_modules/@swc/helpers
35
+ # Explicitly copy pino transport dependencies — pino spawns a worker that requires
36
+ # pino-abstract-transport at runtime; Next.js standalone trace does not capture it (#449)
37
+ COPY --from=builder /app/node_modules/pino-abstract-transport ./node_modules/pino-abstract-transport
38
+ COPY --from=builder /app/node_modules/pino-pretty ./node_modules/pino-pretty
35
39
  COPY --from=builder /app/scripts/run-standalone.mjs ./run-standalone.mjs
36
40
  COPY --from=builder /app/scripts/runtime-env.mjs ./runtime-env.mjs
37
41
  COPY --from=builder /app/scripts/bootstrap-env.mjs ./bootstrap-env.mjs
@@ -1,7 +1,7 @@
1
1
  openapi: 3.1.0
2
2
  info:
3
3
  title: OmniRoute API
4
- version: 2.7.5
4
+ version: 2.7.8
5
5
  description: |
6
6
  OmniRoute is a local-first AI API proxy router. It provides an OpenAI-compatible
7
7
  endpoint that routes requests to multiple AI providers with load balancing,
@@ -123,6 +123,20 @@ export function applyToolFilter(
123
123
  });
124
124
  }
125
125
 
126
+ /**
127
+ * Strip all <omniModel> tags from message content before forwarding to the provider.
128
+ * The tag is an internal OmniRoute marker; providers must never see it or their
129
+ * cache will treat every tagged request as a new session (#454).
130
+ */
131
+ export function stripModelTags(messages: Message[]): Message[] {
132
+ return messages.map((msg) => {
133
+ if (typeof msg.content === "string" && CACHE_TAG_PATTERN.test(msg.content)) {
134
+ return { ...msg, content: msg.content.replace(CACHE_TAG_PATTERN, "").trimEnd() };
135
+ }
136
+ return msg;
137
+ });
138
+ }
139
+
126
140
  // ── Main Middleware ──────────────────────────────────────────────────────────
127
141
 
128
142
  /**
@@ -158,6 +172,11 @@ export function applyComboAgentMiddleware(
158
172
  comboConfig.tool_filter_regex
159
173
  );
160
174
 
175
+ // 4. Strip internal <omniModel> tags before forwarding to provider (#454)
176
+ // These tags are OmniRoute-internal markers and must never reach the provider
177
+ // since providers would treat each tagged request as a new cache session.
178
+ messages = stripModelTags(messages);
179
+
161
180
  return {
162
181
  body: {
163
182
  ...body,
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "omniroute",
3
- "version": "2.7.5",
3
+ "version": "2.7.8",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "omniroute",
9
- "version": "2.7.5",
9
+ "version": "2.7.8",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "workspaces": [
package/app/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omniroute",
3
- "version": "2.7.5",
3
+ "version": "2.7.8",
4
4
  "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.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1181,6 +1181,12 @@ function ComboFormModal({ isOpen, combo, onClose, onSave, activeProviders }) {
1181
1181
  const [config, setConfig] = useState(combo?.config || {});
1182
1182
  const [showStrategyNudge, setShowStrategyNudge] = useState(false);
1183
1183
  const strategyChangeMountedRef = useRef(false);
1184
+ // Agent features (#399 / #401 / #454)
1185
+ const [agentSystemMessage, setAgentSystemMessage] = useState<string>(combo?.system_message || "");
1186
+ const [agentToolFilter, setAgentToolFilter] = useState<string>(combo?.tool_filter_regex || "");
1187
+ const [agentContextCache, setAgentContextCache] = useState<boolean>(
1188
+ !!combo?.context_cache_protection
1189
+ );
1184
1190
 
1185
1191
  // DnD state
1186
1192
  const hasPricingForModel = useCallback(
@@ -1532,6 +1538,14 @@ function ComboFormModal({ isOpen, combo, onClose, onSave, activeProviders }) {
1532
1538
  saveData.config = configToSave;
1533
1539
  }
1534
1540
 
1541
+ // Agent features (#399 / #401 / #454)
1542
+ if (agentSystemMessage.trim()) saveData.system_message = agentSystemMessage.trim();
1543
+ else delete saveData.system_message;
1544
+ if (agentToolFilter.trim()) saveData.tool_filter_regex = agentToolFilter.trim();
1545
+ else delete saveData.tool_filter_regex;
1546
+ if (agentContextCache) saveData.context_cache_protection = true;
1547
+ else delete saveData.context_cache_protection;
1548
+
1535
1549
  await onSave(saveData);
1536
1550
  setSaving(false);
1537
1551
  };
@@ -2052,6 +2066,72 @@ function ComboFormModal({ isOpen, combo, onClose, onSave, activeProviders }) {
2052
2066
  </div>
2053
2067
  )}
2054
2068
 
2069
+ {/* Agent Features (#399 / #401 / #454) */}
2070
+ <div className="flex flex-col gap-2 p-3 bg-black/[0.02] dark:bg-white/[0.02] rounded-lg border border-black/5 dark:border-white/5">
2071
+ <div className="flex items-center gap-1.5 mb-1">
2072
+ <span className="material-symbols-outlined text-[14px] text-primary">smart_toy</span>
2073
+ <p className="text-xs font-medium">Agent Features</p>
2074
+ <span className="text-[10px] text-text-muted">
2075
+ — optional, for agent/tool workflows
2076
+ </span>
2077
+ </div>
2078
+
2079
+ {/* System Message Override */}
2080
+ <div>
2081
+ <label className="text-[11px] font-medium text-text-muted block mb-0.5">
2082
+ System Message Override
2083
+ </label>
2084
+ <textarea
2085
+ rows={2}
2086
+ value={agentSystemMessage}
2087
+ onChange={(e) => setAgentSystemMessage(e.target.value)}
2088
+ placeholder="Override the system prompt for all requests routed through this combo…"
2089
+ className="w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none resize-none"
2090
+ />
2091
+ <p className="text-[10px] text-text-muted mt-0.5">
2092
+ Replaces any system message sent by the client. Leave empty to pass through client
2093
+ system messages.
2094
+ </p>
2095
+ </div>
2096
+
2097
+ {/* Tool Filter Regex */}
2098
+ <div>
2099
+ <label className="text-[11px] font-medium text-text-muted block mb-0.5">
2100
+ Tool Filter Regex
2101
+ </label>
2102
+ <input
2103
+ type="text"
2104
+ value={agentToolFilter}
2105
+ onChange={(e) => setAgentToolFilter(e.target.value)}
2106
+ placeholder="e.g. ^(bash|computer)$"
2107
+ className="w-full text-xs py-1.5 px-2 rounded border border-black/10 dark:border-white/10 bg-transparent focus:border-primary focus:outline-none font-mono"
2108
+ />
2109
+ <p className="text-[10px] text-text-muted mt-0.5">
2110
+ Only tools whose name matches this regex are forwarded to the provider. Leave empty
2111
+ to forward all tools.
2112
+ </p>
2113
+ </div>
2114
+
2115
+ {/* Context Cache Protection */}
2116
+ <div className="flex items-center justify-between gap-2">
2117
+ <div>
2118
+ <label className="text-[11px] font-medium text-text-muted block">
2119
+ Context Cache Protection
2120
+ </label>
2121
+ <p className="text-[10px] text-text-muted">
2122
+ Pins the provider/model across turns to preserve cache sessions. Internal tags are
2123
+ stripped before forwarding to the provider.
2124
+ </p>
2125
+ </div>
2126
+ <input
2127
+ type="checkbox"
2128
+ checked={agentContextCache}
2129
+ onChange={(e) => setAgentContextCache(e.target.checked)}
2130
+ className="accent-primary shrink-0"
2131
+ />
2132
+ </div>
2133
+ </div>
2134
+
2055
2135
  {/* Actions */}
2056
2136
  <div className="flex gap-2 pt-1">
2057
2137
  <Button onClick={onClose} variant="ghost" fullWidth size="sm">
@@ -83,7 +83,11 @@ export default function BudgetTab() {
83
83
  if (data.monthlyLimitUsd)
84
84
  setForm((f) => ({ ...f, monthlyLimitUsd: String(data.monthlyLimitUsd) }));
85
85
  if (data.warningThreshold)
86
- setForm((f) => ({ ...f, warningThreshold: String(data.warningThreshold) }));
86
+ // stored as fraction (0–1), display as percentage (0–100)
87
+ setForm((f) => ({
88
+ ...f,
89
+ warningThreshold: String(Math.round(data.warningThreshold * 100)),
90
+ }));
87
91
  }
88
92
  } catch {
89
93
  // silent
@@ -104,7 +108,8 @@ export default function BudgetTab() {
104
108
  apiKeyId: selectedKey,
105
109
  dailyLimitUsd: form.dailyLimitUsd ? parseFloat(form.dailyLimitUsd) : null,
106
110
  monthlyLimitUsd: form.monthlyLimitUsd ? parseFloat(form.monthlyLimitUsd) : null,
107
- warningThreshold: parseInt(form.warningThreshold) || 80,
111
+ // schema expects a fraction (0–1); UI shows percentage (0–100)
112
+ warningThreshold: (parseInt(form.warningThreshold) || 80) / 100,
108
113
  }),
109
114
  });
110
115
  if (res.ok) {
@@ -1,16 +1,14 @@
1
1
  import { CORS_ORIGIN } from "@/shared/utils/cors";
2
2
  import { handleChat } from "@/sse/handlers/chat";
3
- import { initTranslators } from "@omniroute/open-sse/translator/index.ts";
4
3
 
5
- let initialized = false;
6
-
7
- async function ensureInitialized() {
8
- if (!initialized) {
9
- await initTranslators();
10
- initialized = true;
11
- console.log("[SSE] Translators initialized for /v1/responses");
12
- }
13
- }
4
+ // NOTE: We do NOT call initTranslators() here — the translator registry is
5
+ // bootstrapped at module level inside open-sse/translator/index.ts when it
6
+ // is first imported. Calling it again from a Next.js Route Handler caused a
7
+ // "the worker has exited" uncaughtException crash on Codex CLI requests (#450)
8
+ // because the dynamic import runs in a Next.js server worker context where
9
+ // certain Node APIs used by the translator bootstrap are not available.
10
+ // The translators are always initialized via the open-sse side (chatCore),
11
+ // so /v1/responses just delegates to handleChat which handles everything.
14
12
 
15
13
  export async function OPTIONS() {
16
14
  return new Response(null, {
@@ -24,9 +22,8 @@ export async function OPTIONS() {
24
22
 
25
23
  /**
26
24
  * POST /v1/responses - OpenAI Responses API format
27
- * Now handled by translator pattern (openai-responses format auto-detected)
25
+ * Handled by the unified chat handler (openai-responses format auto-detected).
28
26
  */
29
27
  export async function POST(request) {
30
- await ensureInitialized();
31
28
  return await handleChat(request);
32
29
  }