PageSourceSearch

https://keepreap.com/assets/AdminAiRouting-BTuLw2xD.js

js keepreap.com collected 2026-09-24 14:46:18 UTC 11,773 bytes, 1 lines download raw bytes

1import{u as j,j as e,L as _,G as v,r as m,B as g,P as w,I as S}from"./index.js";import{g as k,h as C,i as I,j as M,k as R}from"./adminApi-ChUnuVlD.js";function N(t){return t.length>8?`${t.slice(0,8)}…`:t}function P(t){return t.charAt(0).toUpperCase()+t.slice(1)}function y(t){return`${t.vendor} / ${t.modelKey}`}function A({data:t}){const{t:a}=j(),[l,o]=m.useState(null),[s,c]=m.useState(""),[r,{isLoading:i}]=I(),f=new Map(t.profiles.map(d=>[d.id,d]));function u(d,x){o(d),c(x)}function h(){o(null),c("")}async function p(d){if(s)try{await r({plan:d,profileId:s}).unwrap()}catch{}finally{o(null),c("")}}return t.assignments.length===0?e.jsx("p",{className:"text-brand-text-3 text-sm",children:a("admin.ai_routing.no_assignments")}):e.jsx("div",{className:"bg-brand-bg border-brand-border-subtle overflow-x-auto rounded-xl border",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"border-brand-border bg-brand-surface text-brand-text-2 border-b text-xs uppercase",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:a("admin.ai_routing.col_plan")}),e.jsx("th",{className:"px-4 py-3",children:a("admin.ai_routing.col_routing_profile")}),e.jsx("th",{className:"px-4 py-3 text-right"})]})}),e.jsx("tbody",{children:t.assignments.map(d=>{const x=f.get(d.profileId),n=l===d.plan;return e.jsxs("tr",{className:"border-brand-border border-b last:border-0",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-brand-text-1 font-medium",children:P(d.plan)})}),e.jsx("td",{className:"px-4 py-3",children:n?e.jsx("select",{value:s,onChange:b=>c(b.target.value),className:"bg-brand-surface border-brand-border text-brand-text-1 rounded border px-2 py-1 text-sm focus:outline-none",children:t.profiles.map(b=>e.jsx("option",{value:b.id,children:b.slug},b.id))}):e.jsxs("div",{children:[e.jsx("span",{className:"text-brand-text-1 font-mono text-xs",children:(x==null?void 0:x.slug)??"—"}),(x==null?void 0:x.displayName)&&e.jsx("span",{className:"text-brand-text-3 ml-2 text-xs",children:x.displayName})]})}),e.jsx("td",{className:"px-4 py-3 text-right",children:n?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(g,{variant:"secondary",size:"sm",onClick:h,disabled:i,children:a("admin.ai_routing.action_cancel")}),e.jsx(g,{variant:"primary",size:"sm",onClick:()=>void p(d.plan),disabled:i||!s,loading:i,children:a("admin.ai_routing.action_save")})]}):e.jsx(g,{variant:"outline",size:"sm",onClick:()=>u(d.plan,d.profileId),children:a("admin.ai_routing.action_change")})})]},d.id)})})]})})}function z({rule:t,profileId:a,models:l,onDone:o}){const{t:s}=j(),[c,r]=m.useState(t.primaryModelId),[i,f]=m.useState(t.fallbackChainJson.join(", ")),[u,h]=m.useState(t.emergencyOverrideModelId??""),[p,{isLoading:d}]=R();async function x(){const n=i.split(",").map(b=>b.trim()).filter(b=>b.length>0);try{await p({profileId:a,capability:t.capability,primaryModelId:c,fallbackChainJson:n,emergencyOverrideModelId:u||null}).unwrap(),o()}catch{}}return e.jsxs("tr",{className:"border-brand-border bg-brand-surface/50 border-b last:border-0",children:[e.jsx("td",{className:"text-brand-text-1 px-3 py-2 font-mono text-xs",children:t.capability}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("select",{value:c,onChange:n=>r(n.target.value),className:"bg-brand-surface border-brand-border text-brand-text-1 w-full rounded border px-2 py-1 text-xs focus:outline-none",children:l.map(n=>e.jsx("option",{value:n.id,children:y(n)},n.id))})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("input",{type:"text",value:i,onChange:n=>f(n.target.value),placeholder:s("admin.ai_routing.fallback_placeholder"),className:"bg-brand-surface border-brand-border text-brand-text-1 placeholder:text-brand-text-3 w-full rounded border px-2 py-1 text-xs focus:outline-none"})}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("select",{value:u,onChange:n=>h(n.target.value),className:"bg-brand-surface border-brand-border text-brand-text-1 w-full rounded border px-2 py-1 text-xs focus:outline-none",children:[e.jsx("option",{value:"",children:s("admin.ai_routing.none_option")}),l.map(n=>e.jsx("option",{value:n.id,children:y(n)},n.id))]})}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(g,{variant:"secondary",size:"sm",onClick:o,disabled:d,children:s("admin.ai_routing.action_cancel")}),e.jsx(g,{variant:"primary",size:"sm",onClick:()=>void x(),disabled:d||!c,loading:d,children:s("admin.ai_routing.action_save")})]})})]})}function E({profileId:t,rules:a,models:l,modelsById:o}){const{t:s}=j(),[c,r]=m.useState(null);return a.length===0?e.jsx("p",{className:"text-brand-text-3 py-2 text-xs",children:s("admin.ai_routing.no_rules")}
1):e.jsx("div",{className:"bg-brand-bg border-brand-border-subtle overflow-x-auto rounded-xl border",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"border-brand-border bg-brand-surface text-brand-text-2 border-b text-xs uppercase",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:s("admin.ai_routing.col_capability")}),e.jsx("th",{className:"px-3 py-2",children:s("admin.ai_routing.col_primary_model")}),e.jsx("th",{className:"px-3 py-2",children:s("admin.ai_routing.col_fallback_chain")}),e.jsx("th",{className:"px-3 py-2",children:s("admin.ai_routing.col_emergency_override")}),e.jsx("th",{className:"px-3 py-2 text-right"})]})}),e.jsx("tbody",{children:a.map(i=>{if(c===i.id)return e.jsx(z,{rule:i,profileId:t,models:l,onDone:()=>r(null)},i.id);const u=o.get(i.primaryModelId),h=i.emergencyOverrideModelId?o.get(i.emergencyOverrideModelId):null;return e.jsxs("tr",{className:"border-brand-border border-b last:border-0",children:[e.jsx("td",{className:"text-brand-text-1 px-3 py-2 font-mono text-xs",children:i.capability}),e.jsx("td",{className:"text-brand-text-2 px-3 py-2 font-mono text-xs",title:i.primaryModelId,children:u?y(u):N(i.primaryModelId)}),e.jsx("td",{className:"text-brand-text-2 px-3 py-2 font-mono text-xs",children:i.fallbackChainJson.length===0?"—":i.fallbackChainJson.map(p=>{const d=o.get(p);return d?y(d):N(p)}).join(", ")}),e.jsx("td",{className:"text-brand-text-2 px-3 py-2 font-mono text-xs",children:h?y(h):i.emergencyOverrideModelId?N(i.emergencyOverrideModelId):"—"}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx(g,{variant:"outline",size:"sm",onClick:()=>r(i.id),children:s("admin.ai_routing.action_edit")})})]},i.id)})})]})})}function L({onDone:t}){const{t:a}=j(),[l,o]=m.useState(""),[s,c]=m.useState(""),[r,i]=m.useState(""),[f,u]=m.useState(""),[h,{isLoading:p}]=M();function d(n){return n?/^[a-z0-9-]+$/.test(n)?"":a("admin.ai_routing.slug_format"):a("admin.ai_routing.slug_required")}async function x(){const n=d(l);if(n){u(n);return}if(s.trim())try{await h({slug:l,displayName:s.trim(),description:r.trim()||void 0}).unwrap(),t()}catch{}}return e.jsxs("div",{className:"bg-brand-bg border-brand-border-subtle mt-4 rounded-xl border p-4",children:[e.jsx("p",{className:"text-brand-text-1 mb-3 text-sm font-semibold",children:a("admin.ai_routing.profile_form_title")}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-brand-text-2 block text-xs font-medium",children:[a("admin.ai_routing.profile_form_slug")," ",e.jsx("span",{className:"text-brand-text-3",children:a("admin.ai_routing.profile_form_slug_hint")})]}),e.jsx("input",{type:"text",value:l,onChange:n=>{o(n.target.value),u(d(n.target.value))},placeholder:"e.g. pro-experimental",className:"bg-brand-bg border-brand-border text-brand-text-1 placeholder:text-brand-text-3 w-full rounded border px-3 py-1.5 text-sm focus:outline-none"}),e.jsx(S,{message:f,size:"xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-brand-text-2 block text-xs font-medium",children:a("admin.ai_routing.profile_form_display_name")}),e.jsx("input",{type:"text",value:s,onChange:n=>c(n.target.value),placeholder:"e.g. Pro Experimental",className:"bg-brand-bg border-brand-border text-brand-text-1 placeholder:text-brand-text-3 w-full rounded border px-3 py-1.5 text-sm focus:outline-none"})]}),e.jsxs("div",{className:"space-y-1 sm:col-span-2",children:[e.jsxs("label",{className:"text-brand-text-2 block text-xs font-medium",children:[a("admin.ai_routing.profile_form_description")," ",e.jsx("span",{className:"text-brand-text-3",children:a("admin.ai_routing.profile_form_description_hint")})]}),e.jsx("input",{type:"text",value:r,onChange:n=>i(n.target.value),placeholder:"Brief description of when to use this profile",className:"bg-brand-bg border-brand-border text-brand-text-1 placeholder:text-brand-text-3 w-full rounded border px-3 py-1.5 text-sm focus:outline-none"})]})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[e.jsx(g,{variant:"secondary",size:"sm",onClick:t,disabled:p,children:a("admin.ai_routing.action_cancel")}),e.jsx(g,{variant:"primary",size:"sm",onClick:()=>void x(),disabled:p||!l||!s.trim()||!!f,loading:p,children:a("admin.ai_routing.action_create_profile")})]})]})}function O({data:t,models:a}){const{t:l}=j(),[o,s]=m.useState(!1),c=new Map(a.map(r=>[r.id,r]));return e.jsxs("div",{className:"space-y-6",children:[t.profiles.length===0&&e.jsx("p",{className:"text-brand-text-3 text-sm",children:l("admin.ai_routing.no_profiles")}),t.profiles.map(r=>e.jsxs("div",{className:"bg-brand-bg border-brand-border-subtle rounded-xl border",children:[e.jsx("div",{className:"border-brand-border border-b px-4 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-brand-text-1 flex items-center gap-2 font-semibold",children:[e.jsx("span",{className:"bg-brand-surface border-brand-border rounded-full border px-2 py-0.5 font-mono text-xs",children:r.slug}),e.jsx("span",{className:"text-sm",children:r.displayName})]}),r.description&&e.jsx("p",{className:"text-brand-text-3 mt-1 text-xs",children:r.description})]}),e.jsx("span",{className:"text-brand-text-3 font-mono text-xs",title:r.id,children:N(r.id)})]})}),e.jsxs("div",{className:"p-4",children:[e.jsx("p",{className:"text-brand-text-2 mb-2 text-xs font-medium uppercase tracking-wide",children:l("admin.ai_routing.rules_heading",{count:r.rules.length})}),e.jsx(E,{profileId:r.id,rules:r.rules,models:a,modelsById:c})]})]},r.id)),o?e.jsx(L,{onDone:()=>s(!1)}):e.jsxs(g,{variant:"secondary",size:"sm",onClick:()=>s(!0),children:[e.jsx(w,{className:"h-3.5 w-3.5"}),l("admin.ai_routing.action_add_profile")]})]})}function G(){const{t}=j(),{data:a,error:l,isLoading:o}=k(),{data:s,isLoading:c}=C();if(o||c)return e.jsx(_,{scope:"global"});if(l||!a)return e.jsx("p",{className:"text-brand-danger text-sm",children:t("admin.ai_routing.error")});const r=(s==null?void 0:s.models)??[];return e.jsxs("div",{className:"space-y-8",children:[e.jsx("header",{className:"flex items-center justify-between",children:e.jsxs("h1",{className:"text-brand-text-1 flex items-center gap-2 text-2xl font-semibold",children:[e.jsx(v,{className:"h-6 w-6"}),t("admin.ai_routing.title")]})}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-brand-text-2 text-sm font-medium uppercase tracking-wide",children:t("admin.ai_routing.section_assignments",{count:a.assignments.length})}),e.jsx(A,{data:a})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-brand-text-2 text-sm font-medium uppercase tracking-wide",children:t("admin.ai_routing.section_profiles",{count:a.profiles.length})}),e.jsx(O,{data:a,models:r})]})]})}export{G as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.