1"use strict";(self.rspackChunknewapi_web=self.rspackChunknewapi_web||[]).push([[6678],{92964(e,s,l){l.d(s,{C:()=>d,z:()=>o});var a=l(72361),t=l(7649),n=l(70435),r=l(61409),i=l(81204);function o(e){let{className:s,...l}=e;return(0,a.jsx)(r.z,{"data-slot":"radio-group",className:(0,i.cn)("grid w-full gap-2",s),...l})}function d(e){let{className:s,...l}=e;return(0,a.jsx)(t.U,{"data-slot":"radio-group-item",className:(0,i.cn)("group/radio-group-item peer border-input focus-visible:border-ring focus-visible:ring-ring/25 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary relative flex aspect-square size-4 shrink-0 rounded-full border outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",s),...l,children:(0,a.jsx)(n.T,{"data-slot":"radio-group-indicator",className:"flex size-4 items-center justify-center",children:(0,a.jsx)("span",{className:"bg-primary-foreground absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full"})})})}},7138(e,s,l){l.d(s,{b:()=>n,n:()=>r});var a=l(53540),t=l(33351);function n(){return(0,a.I)({queryKey:["system-options"],queryFn:t.y,staleTime:3e5})}function r(e,s){if(!e)return s;let l={...s},a=[];return e.forEach(e=>{if(e.key in s){let t=function(e,s){if("boolean"==typeof s)return{success:!0,value:"true"===e||"1"===e};if("number"==typeof s){let l=e.trim();if(""===l)return{success:!1,error:"Empty string for number field",fallback:s};let a=Number(l);return Number.isNaN(a)?{success:!1,error:`Invalid number: "${e}"`,fallback:s}:{success:!0,value:a}}if(Array.isArray(s))try{let l=JSON.parse(e);if(!Array.isArray(l))return{success:!1,error:"Expected array but got non-array JSON",fallback:s};if(s.length>0){let e=typeof s[0],a=l.find(s=>typeof s!==e);if(void 0!==a)return{success:!1,error:`Array element type mismatch: expected ${e}, got ${typeof a}`,fallback:s}}return{success:!0,value:l}}catch(e){return{success:!1,error:`JSON parse failed: ${e instanceof Error?e.message:String(e)}`,fallback:s}}return{success:!0,value:e}}(e.value,s[e.key]);t.success?l[e.key]=t.value:(l[e.key]=t.fallback,a.push({key:e.key,error:t.error}))}}),a.length,l}},72597(e,s,l){l.r(s),l.d(s,{component:()=>sp});var a=l(72361),t=l(68413),n=l(96962),r=l(2718),i=l(82799),o=l(6702),d=l(61631),c=l(46775),m=l(34151),u=l(67267),x=l(82468),h=l(81204),p=l(77405);function g(e){let{label:s,status:l}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-3",children:["loading"===l&&(0,a.jsx)(d.krw,{className:"text-primary h-5 w-5 animate-spin"}),"done"===l&&(0,a.jsx)(d.Jly,{className:"h-5 w-5 text-green-500"}),"pending"===l&&(0,a.jsx)(d.jlt,{className:"text-muted-foreground/40 h-5 w-5"}),(0,a.jsx)("span",{className:(0,h.cn)("text-sm","loading"===l&&"text-foreground font-medium","done"===l&&"text-muted-foreground","pending"===l&&"text-muted-foreground/60"),children:s})]})}function j(e){let{children:s,loading:l,loadingPhase:t="settings",isEnabled:n,connectionLoading:r,connectionOk:m,connectionError:u,onRetry:x}=e,{t:h}=(0,o.Bd)(),j=(0,i.Z)(),f=()=>{j({to:"/system-settings/models/$section",params:{section:"model-deployment"}})};if(l||r){let e="connection"===t?"loading":"done"===t&&m?"done":"pending";return(0,a.jsx)("div",{className:"mx-auto mt-8 max-w-md",children:(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12",children:[(0,a.jsx)(d.krw,{className:"text-primary mb-6 h-10 w-10 animate-spin"}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)(g,{label:h("Loading configuration"),status:"settings"===t?"loading":"connection"===t||"done"===t?"done":"pending"}),(0,a.jsx)(g,{label:h("Checking connection"),status:e})]})]})})}return n?!1===m&&u?(0,a.jsxs)("div",{className:"mx-auto mt-8 max-w-md",children:[(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-red-100 dark:bg-red-900/20",children:(0,a.jsx)(d.RQC,{className:"h-8 w-8 text-red-600 dark:text-red-400"})}),(0,a.jsx)("h3",{className:"mb-6 text-xl font-semibold",children:h("Connection failed")})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)(p.Fc,{variant:"destructive",children:[(0,a.jsx)(d.RIJ,{className:"h-4 w-4"}),(0,a.jsx)(p.XL,{children:h("Connection error")}),(0,a.jsx)(p.TN,{children:h(u)})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(c.$,{variant:"outline",onClick:x,className:"flex-1",children:h("Retry")}),(0,a.jsxs)(c.$,{onClick:f,className:"flex-1",children:[(0,a.jsx)(d.wB_,{className:"mr-2 h-4 w-4"}),h("Go to settings")]})]})]})]}):(0,a.jsx)(a.Fragment,{children:s}):(0,a.jsxs)("div",{className:"mx-auto mt-8 max-w-md",children:[(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-amber-100 dar
1k:bg-amber-900/20",children:(0,a.jsx)(d.gq4,{className:"h-8 w-8 text-amber-600 dark:text-amber-400"})}),(0,a.jsx)("h3",{className:"mb-6 text-xl font-semibold",children:h("Model deployment service is disabled")})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)(p.Fc,{variant:"default",children:[(0,a.jsx)(d.RIJ,{className:"h-4 w-4"}),(0,a.jsx)(p.XL,{children:h("Configuration required")}),(0,a.jsx)(p.TN,{children:h("Please enable io.net model deployment service and configure an API key in System Settings.")})]}),(0,a.jsxs)(c.$,{onClick:f,className:"w-full",children:[(0,a.jsx)(d.wB_,{className:"mr-2 h-4 w-4"}),h("Go to settings")]})]})]})}var f=l(53540),y=l(55581),v=l(3521),b=l(11564),N=l(20598),w=l(74028),_=l(18692),C=l(58254);let S={openai:{path:"/v1/chat/completions",method:"POST"},"openai-response":{path:"/v1/responses",method:"POST"},anthropic:{path:"/v1/messages",method:"POST"},gemini:{path:"/v1beta/models/{model}:generateContent",method:"POST"},"jina-rerank":{path:"/rerank",method:"POST"},"image-generation":{path:"/v1/images/generations",method:"POST"},embeddings:{path:"/v1/embeddings",method:"POST"}},R={all:["models"],lists:()=>[...R.all,"list"],list:e=>[...R.lists(),e],detail:e=>[...R.all,"detail",e],missing:()=>[...R.all,"missing"]},k={all:["vendors"],lists:()=>[...k.all,"list"],list:e=>[...k.lists(),e],detail:e=>[...k.all,"detail",e]},z={all:["prefill-groups"],lists:()=>[...z.all,"list"],list:e=>[...z.lists(),e]},M={all:["deployments"],lists:()=>[...M.all,"list"],list:e=>[...M.lists(),e],detail:e=>[...M.all,"detail",e]};var I=l(3642);function F(e){return e?e.split(",").map(e=>e.trim()).filter(Boolean):[]}var E=l(25732);E.Ik({id:E.ai().optional(),model_name:E.Yj().min(1,"Model name is required"),description:E.Yj().default(""),icon:E.Yj().default(""),tags:E.YO(E.Yj()).default([]),vendor_id:E.ai().optional(),endpoints:E.Yj().default(""),name_rule:E.ai().min(0).max(3).default(0),status:E.zM().default(!0),sync_official:E.zM().default(!0),enable_groups:E.YO(E.Yj()).default([]),quota_types:E.YO(E.ai()).default([])}),E.Ik({id:E.ai().optional(),name:E.Yj().min(1,"Vendor name is required"),description:E.Yj().default(""),icon:E.Yj().default(""),status:E.ai().default(1)});var $=l(19376);async function A(e,s,l){try{let a=await (0,x.vo)(e,1);a.success?(N.oR.success($.Ay.t("Model enabled successfully")),s?.invalidateQueries({queryKey:R.lists()}),l?.()):N.oR.error(a.message||$.Ay.t("Failed to enable model"))}catch(e){N.oR.error(e?.message||$.Ay.t("Failed to enable model"))}}async function O(e,s,l){try{let a=await (0,x.vo)(e,0);a.success?(N.oR.success($.Ay.t("Model disabled successfully")),s?.invalidateQueries({queryKey:R.lists()}),l?.()):N.oR.error(a.message||$.Ay.t("Failed to disable model"))}catch(e){N.oR.error(e?.message||$.Ay.t("Failed to disable model"))}}async function B(e,s,l,a){1===s?await O(e,l,a):await A(e,l,a)}async function q(e,s,l){try{let a=await (0,x.De)(e);a.success?(N.oR.success($.Ay.t("Model deleted successfully")),s?.invalidateQueries({queryKey:R.lists()}),l?.()):N.oR.error(a.message||$.Ay.t("Failed to delete model"))}catch(e){N.oR.error(e?.message||$.Ay.t("Failed to delete model"))}}async function D(e,s,l){if(0===e.length)return void N.oR.error($.Ay.t("Please select at least one model"));try{let a=e.map(e=>(0,x.De)(e)),t=await Promise.all(a),n=0,r=0;t.forEach((s,l)=>{s.success?n++:(r++,console.error(`Failed to delete model ${e[l]}:`,s.message))}),n>0&&(N.oR.success($.Ay.t("Successfully deleted {{count}} model(s)",{count:n})),s?.invalidateQueries({queryKey:R.lists()}),l?.(n)),r>0&&N.oR.error($.Ay.t("Failed to delete {{count}} model(s)",{count:r}))}catch(e){N.oR.error(e?.message||$.Ay.t("Batch delete failed"))}}async function J(e,s,l){if(0===e.length)return void N.oR.error($.Ay.t("Please select at least one model"));try{let a=e.map(e=>(0,x.vo)(e,1)),t=await Promise.all(a),n=0,r=0;t.forEach(e=>{e.success?n++:r++}),n>0&&(N.oR.success($.Ay.t("Successfully enabled {{count}} model(s)",{count:n})),s?.invalidateQueries({queryKey:R.lists()}),l?.()),r>0&&N.oR.error($.Ay.t("Failed to enable {{count}} model(s)",{count:r}))}catch(e){N.oR.error(e?.message||$.Ay.t("Batch enable failed"))}}async function V(e,s,l){if(0===e.length)return void N.oR.error($.Ay.t("Please select at least one model"));try{let a=e.map(e=>(0,x.vo)(e,0)),t=await Promise.all(a),n=0,r=0;
1t.forEach(e=>{e.success?n++:r++}),n>0&&(N.oR.success($.Ay.t("Successfully disabled {{count}} model(s)",{count:n})),s?.invalidateQueries({queryKey:R.lists()}),l?.()),r>0&&N.oR.error($.Ay.t("Failed to disable {{count}} model(s)",{count:r}))}catch(e){N.oR.error(e?.message||$.Ay.t("Batch disable failed"))}}var K=l(72202),P=l(3088),T=l(21258);function L(e){return"string"==typeof e?e.trim().toLowerCase():""}var Y=l(1755),G=l(54023),U=l(72690);function W(e,s){let l="number"==typeof e?e:Number(e);return Number.isFinite(l)?Math.max(0,Math.round(l)):s}function H(e){let{open:s,onOpenChange:l,deploymentId:r}=e,{t:i}=(0,o.Bd)(),m=(0,n.jE)(),[u,h]=(0,t.useState)(1),[p,g]=(0,t.useState)(!1);(0,t.useEffect)(()=>{s&&h(1)},[s]);let{data:j,isLoading:y}=(0,f.I)({queryKey:["deployment-details-for-extend",r],queryFn:()=>r?(0,x.i8)(r):null,enabled:s&&null!==r}),v=j?.data,b=(0,t.useMemo)(()=>{if(!v)return null;let e=W(v.hardware_id,0),s=W(v.gpus_per_container,0),l=W(v.total_containers,0),a=(Array.isArray(v.locations)?v.locations:[]).map(e=>e&&"object"==typeof e?W(e?.id,0):0).filter(e=>e>0);return e<=0||s<=0||l<=0||0===a.length?null:{hardware_id:e,gpus_per_container:s,replica_count:l,location_ids:a}},[v]),{data:w,isLoading:_,isFetching:C}=(0,f.I)({queryKey:["deployment-extend-price",r,u,b],queryFn:()=>b?(0,x.c9)({location_ids:b.location_ids,hardware_id:b.hardware_id,gpus_per_container:b.gpus_per_container,replica_count:b.replica_count,duration_hours:u,currency:"usdc"}):null,enabled:s&&!!b&&u>0}),S=(0,t.useMemo)(()=>{let e=w?.data;if(!e||"object"!=typeof e)return"";let s=e.price_breakdown,l=e.total_cost;s&&"object"==typeof s&&!Array.isArray(s)&&(l=s.total_cost??s.totalCost??s.TotalCost??l);let a=e.currency??"USDC";return null==l?"":`${String(l)} ${String(a).toUpperCase()}`.trim()},[w]),R=!!r&&u>0&&!p,k=async()=>{if(!r)return;let e=W(u,1);if(e<=0)return void N.oR.error(i("Please enter a valid duration"));g(!0);try{let s=await (0,x.MG)(r,e);
1if(s.success){N.oR.success(i("Extended successfully")),m.invalidateQueries({queryKey:M.lists()}),m.invalidateQueries({queryKey:["deployment-details"]}),l(!1);return}N.oR.error(s.message||i("Extend failed"))}catch(e){N.oR.error(e instanceof Error?e.message:i("Extend failed"))}finally{g(!1)}};return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"sm:max-w-lg",children:[(0,a.jsx)(Y.c7,{children:(0,a.jsx)(Y.L3,{children:i("Extend deployment")})}),y?(0,a.jsx)("div",{className:"flex items-center justify-center py-10",children:(0,a.jsx)(d.krw,{className:"text-muted-foreground h-6 w-6 animate-spin"})}):(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-sm",children:[i("Deployment ID"),":"," ",(0,a.jsx)("span",{className:"font-mono",children:r})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("div",{className:"text-sm font-medium",children:i("Duration (hours)")}),(0,a.jsx)(G.p,{type:"number",min:1,value:u,onChange:e=>h(W(e.target.value,1))}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:i("This will extend the deployment by the specified hours.")})]}),(0,a.jsx)(U.w,{}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"text-sm font-medium",children:i("Estimated cost")}),(0,a.jsx)("div",{className:"text-muted-foreground text-sm",children:_||C?(0,a.jsxs)("span",{className:"inline-flex items-center gap-2",children:[(0,a.jsx)(d.krw,{className:"h-4 w-4 animate-spin"}),i("Calculating...")]}):b&&S||i("Not available")}),b?null:(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:i("Unable to estimate price for this deployment.")})]})]}),(0,a.jsxs)(Y.Es,{className:"mt-4",children:[(0,a.jsx)(c.$,{variant:"outline",onClick:()=>l(!1),children:i("Cancel")}),(0,a.jsxs)(c.$,{onClick:()=>void k(),disabled:!R,children:[p?(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}):null,i("Extend")]})]})]})})}function Q(e){let{open:s,onOpenChange:l,deploymentId:r,currentName:i}=e,{t:m}=(0,o.Bd)(),u=(0,n.jE)(),[h,p]=(0,t.useState)(i||""),[g,j]=(0,t.useState)(!1);(0,t.useEffect)(()=>{s&&p(i||"")},[s,i]);let y=h.trim(),{data:v,isFetching:b}=(0,f.I)({queryKey:["deployment-rename-check",y],queryFn:()=>y?(0,x.Z7)(y):null,enabled:s&&!!y,staleTime:1e4}),w=v?.success===!0?v?.data?.available:void 0,_=(0,t.useMemo)(()=>y?b?m("Checking name..."):!0===w?m("Name is available"):!1===w?m("Name is not available"):"":m("Enter a new name"),[w,b,m,y]),C=!!r&&!!y&&!1!==w&&!g,S=async()=>{if(r){if(!y)return void N.oR.error(m("Please enter a name"));if(!1===w)return void N.oR.error(m("Name is not available"));j(!0);try{let e=await (0,x.Ab)(r,y);if(e.success){N.oR.success(m("Renamed successfully")),u.invalidateQueries({queryKey:M.lists()}),u.invalidateQueries({queryKey:["deployment-details"]}),l(!1);return}N.oR.error(e.message||m("Rename failed"))}catch(e){N.oR.error(e instanceof Error?e.message:m("Rename failed"))}finally{j(!1)}}};return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"sm:max-w-lg",children:[(0,a.jsx)(Y.c7,{children:(0,a.jsx)(Y.L3,{children:m("Rename deployment")})}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-sm",children:[m("Deployment ID"),":"," ",(0,a.jsx)("span",{className:"font-mono",children:r})]}),(0,a.jsx)(G.p,{placeholder:m("Enter a new name"),value:h,onChange:e=>p(e.target.value),autoComplete:"off"}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:_})]}),(0,a.jsxs)(Y.Es,{className:"mt-4",children:[(0,a.jsx)(c.$,{variant:"outline",onClick:()=>l(!1),children:m("Cancel")}),(0,a.jsxs)(c.$,{onClick:()=>void S(),disabled:!C,children:[g?(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}):null,m("Rename")]})]})]})})}var Z=l(63859),X=l(86832),ee=l(48367),es=l(38579),el=l(97077),ea=l(28769);let et=E.Ik({image_url:E.Yj().optional(),traffic_port:Z.ai().int().min(1).max(65535).optional(),entrypoint:E.Yj().optional(),args:E.Yj().optional(),command:E.Yj().optional(),registry_username:E.Yj().optional(),registry_secret:E.Yj().optional(),env_json:E.Yj().optional(),secret_env_json:E.Yj().optional()});function en(e){if(!e||!e.trim())return;let s=JSON.parse(e);if(!s||"object"!=typeof s||Array.isArray(s))throw Error("JSON must be an object");return Object.fromEntries(Object.entries(s).map(e=>{let[s,l]=e;return[s,String(l)]}))}function er(e){let{open:s,onOpenChange:l,deploymentId:r}=e,{t:i}=(0,o.Bd)(),m=(0,n.jE)(),u=(0,X.mN)({resolver:(0,ee.u)(et),defaultValues:{image_url:"",traffic_port:void 0,entrypoint:"",args:"",command:"",registry_username:"",registry_secret:"",env_json:"",secret_env_json:""}}),{data:h,isLoading:p}=(0,f.I)({queryKey:["deployment-details-for-update",r],queryFn:()=>r?(0,x.i8)(r):null,enabled:s&&null!==r}),g=h?.data;(0,t.useEffect)(()=>
1{if(!s||!g)return;let e=g.container_config&&"object"==typeof g.container_config?g.container_config:{},l="string"==typeof e.image_url?e.image_url:"",a="number"==typeof e.traffic_port?e.traffic_port:void 0,t=Array.isArray(e.entrypoint)?e.entrypoint.map(e=>"string"==typeof e?e:"").filter(Boolean):[],n=e.env_variables&&"object"==typeof e.env_variables&&!Array.isArray(e.env_variables)?e.env_variables:{};u.reset({image_url:l,traffic_port:a,entrypoint:t.join(" "),args:"",command:"",registry_username:"",registry_secret:"",env_json:Object.keys(n).length?JSON.stringify(n,null,2):"",secret_env_json:""})},[s,g,u]);let j=(0,t.useMemo)(()=>r?`${i("Update configuration")} - ${r}`:i("Update configuration"),[r,i]),y=async e=>{if(r)try{let s=en(e.env_json),a=en(e.secret_env_json),t=e.entrypoint?e.entrypoint.split(" ").map(e=>e.trim()).filter(Boolean):void 0,n=e.args?e.args.split(" ").map(e=>e.trim()).filter(Boolean):void 0,o=await (0,x.VJ)(r,{image_url:e.image_url?.trim()||void 0,traffic_port:"number"==typeof e.traffic_port?e.traffic_port:void 0,registry_username:e.registry_username?.trim()||void 0,registry_secret:e.registry_secret?.trim()||void 0,command:e.command?.trim()||void 0,...t?.length?{entrypoint:t}:{},...n?.length?{args:n}:{},...s?{env_variables:s}:{},...a?{secret_env_variables:a}:{}});
1if(o.success){N.oR.success(i("Updated successfully")),m.invalidateQueries({queryKey:M.lists()}),m.invalidateQueries({queryKey:["deployment-details"]}),l(!1);return}N.oR.error(o.message||i("Update failed"))}catch(s){let e=s instanceof Error?s.message:i("Update failed");N.oR.error(e)}};return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"max-h-[calc(100dvh-2rem)] overflow-hidden max-sm:w-screen max-sm:max-w-none max-sm:rounded-none max-sm:p-4 sm:max-w-3xl",children:[(0,a.jsx)(Y.c7,{children:(0,a.jsx)(Y.L3,{children:j})}),p?(0,a.jsx)("div",{className:"flex items-center justify-center py-10",children:(0,a.jsx)(d.krw,{className:"text-muted-foreground h-6 w-6 animate-spin"})}):(0,a.jsx)("div",{className:"max-h-[calc(100dvh-8.5rem)] overflow-y-auto py-2 pr-1 sm:max-h-[72vh]",children:(0,a.jsx)(el.lV,{...u,children:(0,a.jsxs)("form",{onSubmit:u.handleSubmit(y),autoComplete:"off",className:"space-y-4",children:[(0,a.jsxs)("div",{className:"grid gap-3 md:grid-cols-2 md:gap-4",children:[(0,a.jsx)(el.zB,{control:u.control,name:"image_url",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Image")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:"ollama/ollama:latest",...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:u.control,name:"traffic_port",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Port")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"number",min:1,max:65535,value:"number"==typeof s.value||"string"==typeof s.value?s.value:"",onChange:e=>{let l=e.target.value;s.onChange(""===l?void 0:Number(l))},onBlur:s.onBlur,name:s.name,ref:s.ref})}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)("div",{className:"grid gap-3 md:grid-cols-2 md:gap-4",children:[(0,a.jsx)(el.zB,{control:u.control,name:"entrypoint",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Entrypoint (space separated)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:"bash -lc",...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:u.control,name:"args",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Args (space separated)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:"--foo bar",...s})}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsx)(el.zB,{control:u.control,name:"command",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Command")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:"Optional",...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsxs)(es.Nt,{className:"rounded-md border p-3",children:[(0,a.jsx)(es.R6,{className:"cursor-pointer text-sm",children:i("Registry (optional)")}),(0,a.jsx)(es.Ke,{children:(0,a.jsxs)("div",{className:"mt-3 grid gap-3 md:grid-cols-2 md:gap-4",children:[(0,a.jsx)(el.zB,{control:u.control,name:"registry_username",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Registry username")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{autoComplete:"off",...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:u.control,name:"registry_secret",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Registry secret")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"password",autoComplete:"off",...s})}),(0,a.jsx)(el.C5,{})]})}})]})})]}),(0,a.jsxs)(es.Nt,{className:"rounded-md border p-3",children:[(0,a.jsx)(es.R6,{className:"cursor-pointer text-sm",children:i("Environment variables")}),(0,a.jsx)(es.Ke,{children:(0,a.jsxs)("div",{className:"mt-3 grid gap-3 md:grid-cols-2 md:gap-4",children:[(0,a.jsx)(el.zB,{control:u.control,name:"env_json",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Env (JSON object)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{className:"min-h-40 font-mono text-xs",placeholder:'{"KEY":"VALUE"}',...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:u.control,name:"secret_env_json",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Secret env (JSON object)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{className:"min-h-40 font-mono text-xs",placeholder:'{"SECRET":"VALUE"}',...s})}),(0,a.jsx)(el.C5,{})]})}})]})})]}),(0,a.jsxs)(Y.Es,{className:"grid grid-cols-2 gap-2 pt-2 sm:flex",children:[(0,a.jsx)(c.$,{type:"button",variant:"outline",onClick:()=>l(!1),children:i("Cancel")}),(0,a.jsxs)(c.$,{type:"submit",disabled:u.formState.isSubmitting,children:[u.formState.isSubmitting?(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}):null,i("Update")]})]})]})})})]})})}function ei(e){let{open:s,onOpenChange:l,deploymentId:n}=e,{t:r}=(0,o.Bd)(),{data:i,isLoading:m,refetch:u,isFetching:h}=(0,f.I)({queryKey:["deployment-details",n],queryFn:()=>n?(0,x.i8)(n):null,enabled:s&&null!==n}),{data:p,isLoading:g,refetch:j,isFetching:y}=(0,f.I)({queryKey:["deployment-details-containers",n],queryFn:()=>n?(0,x.sC)(n):null,enabled:s&&null!==n}),v=i?.data,b=(0,t.useMemo)(()=>{let e=p?.data?.containers;return Array.isArray(e)?e:[]},[p?.data?.containers]),w=(0,t.useMemo)(()=>{let e=v?.locations;return Array.isArray(e)?e.map(e=>{if(!e||"object"!=typeof e)return null;
1let s=e?.name,l=e?.iso2,a=e?.id;return`${String(s??a??"")}${l?` (${l})`:""}`.trim()}).filter(Boolean):[]},[v]),_=async()=>{if(null!=n)try{await navigator.clipboard.writeText(String(n)),N.oR.success(r("Copied"))}catch{N.oR.error(r("Copy failed"))}},C=(0,t.useMemo)(()=>{if(!v)return"";try{return JSON.stringify(v,null,2)}catch{return""}},[v]);return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"max-h-[calc(100dvh-2rem)] overflow-hidden max-sm:w-screen max-sm:max-w-none max-sm:rounded-none max-sm:p-4 sm:max-w-3xl",children:[(0,a.jsx)(Y.c7,{children:(0,a.jsx)(Y.L3,{children:r("Deployment details")})}),(0,a.jsxs)("div",{className:"max-h-[calc(100dvh-8.5rem)] space-y-3 overflow-y-auto py-2 pr-1 sm:max-h-[72vh] sm:space-y-4",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-sm",children:[r("Deployment ID"),":"," ",(0,a.jsx)("span",{className:"font-mono",children:n})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2 sm:flex sm:items-center",children:[(0,a.jsxs)(c.$,{variant:"outline",size:"sm",onClick:_,children:[(0,a.jsx)(d.QRo,{className:"mr-2 h-4 w-4"}),r("Copy")]}),(0,a.jsxs)(c.$,{variant:"outline",size:"sm",onClick:()=>{u(),j()},disabled:h||y,children:[h||y?(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(d.g__,{className:"mr-2 h-4 w-4"}),r("Refresh")]})]})]}),(0,a.jsx)(U.w,{}),m||g?(0,a.jsx)("div",{className:"flex items-center justify-center py-10",children:(0,a.jsx)(d.krw,{className:"text-muted-foreground h-6 w-6 animate-spin"})}):i?.success?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Status")}),(0,a.jsx)("div",{className:"mt-1 font-medium",children:String(v?.status??"-")})]}),(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Hardware")}),(0,a.jsxs)("div",{className:"mt-1 font-medium",children:[String(v?.brand_name??"")," ",String(v?.hardware_name??"")]})]}),(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Total GPUs")}),(0,a.jsx)("div",{className:"mt-1 font-medium",children:String(v?.total_gpus??v?.hardware_qty??"-")})]}),(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Containers")}),(0,a.jsx)("div",{className:"mt-1 font-medium",children:b.length})]})]}),w.length?(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Locations")}),(0,a.jsx)("div",{className:"mt-1 flex flex-wrap gap-2 text-sm",children:w.map(e=>(0,a.jsx)("span",{className:"bg-muted rounded-md px-2 py-1",children:e},e))})]}):null,b.length?(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground mb-2 text-xs",children:r("Containers")}),(0,a.jsx)("div",{className:"space-y-2",children:b.map(e=>{let s=e?.container_id;if("string"!=typeof s||!s)return null;let l="string"==typeof e?.status?e.status:void 0,t="string"==typeof e?.public_url?e.public_url:"";return(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border px-3 py-2",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("div",{className:"truncate font-mono text-sm",children:s}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:l?`${r("Status")}: ${l}`:""})]}),t?(0,a.jsxs)(c.$,{variant:"outline",size:"sm",onClick:()=>window.open(t,"_blank"),children:[(0,a.jsx)(d.GrD,{className:"mr-2 h-4 w-4"}),r("Open")]}):null]},s)})})]}):null,(0,a.jsxs)(es.Nt,{className:"rounded-lg border p-3",children:[(0,a.jsx)(es.R6,{className:"cursor-pointer text-sm font-medium",children:r("Raw JSON")}),(0,a.jsx)(es.Ke,{children:(0,a.jsx)("pre",{className:"mt-3 max-h-[360px] overflow-auto rounded-md bg-black p-3 text-xs text-gray-200",children:C||"
1-"})})]})]}):(0,a.jsx)("div",{className:"text-muted-foreground py-10 text-center text-sm",children:i?.message||r("Failed to fetch deployment details")})]}),(0,a.jsx)(Y.Es,{children:(0,a.jsx)(c.$,{variant:"outline",onClick:()=>l(!1),className:"w-full sm:w-auto",children:r("Close")})})]})})}var eo=l(82243),ed=l(1951);function ec(e){let{open:s,onOpenChange:l,deploymentId:n}=e,{t:r}=(0,o.Bd)(),i=(0,t.useRef)(null),[m,u]=(0,t.useState)(!0),[h,p]=(0,t.useState)(!1),[g,j]=(0,t.useState)("stdout"),[y,v]=(0,t.useState)(""),{data:b,isLoading:N,refetch:w,isFetching:_}=(0,f.I)({queryKey:["deployment-containers",n],queryFn:()=>n?(0,x.sC)(n):null,enabled:s&&null!==n}),C=(0,t.useMemo)(()=>{let e=b?.data?.containers;return Array.isArray(e)?e:[]},[b?.data?.containers]);(0,t.useEffect)(()=>{if(!s){v(""),j("stdout"),u(!0),p(!1);return}if(s&&C.length>0&&!y){let e=C[0]?.container_id;"string"==typeof e&&e&&v(e)}},[s,C,y]);let{data:S,isLoading:R,refetch:k,isFetching:z}=(0,f.I)({queryKey:["deployment-logs",n,y,g],queryFn:()=>n&&y?(0,x.B1)(n,{container_id:y,stream:g,limit:500}):null,enabled:s&&null!==n&&!!y,refetchInterval:!!s&&!!h&&5e3}),M=(0,t.useMemo)(()=>{let e=S?.data;return"string"==typeof e?e:""},[S?.data]),I=(0,t.useMemo)(()=>{let e=M.replace(/\r\n?/g,"\n");return e?e.split("\n"):[]},[M]);return(0,t.useEffect)(()=>{m&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[I,m]),(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"flex h-[calc(100dvh-2rem)] flex-col max-sm:w-screen max-sm:max-w-none max-sm:rounded-none max-sm:p-4 sm:h-[80vh] sm:max-w-4xl",children:[(0,a.jsx)(Y.c7,{children:(0,a.jsxs)(Y.L3,{className:"flex items-center gap-2",children:[(0,a.jsx)(d.BKt,{className:"h-5 w-5"}),r("Deployment logs")]})}),(0,a.jsxs)("div",{className:"mb-3 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-3",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-sm",children:[r("Deployment ID"),": ",n]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2 sm:flex sm:flex-wrap sm:items-center",children:[(0,a.jsxs)(c.$,{variant:"outline",size:"sm",onClick:()=>{w(),k()},disabled:z||_,children:[z||_?(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(d.g__,{className:"mr-2 h-4 w-4"}),r("Refresh")]}),(0,a.jsxs)(c.$,{variant:"outline",size:"sm",onClick:()=>{if(!M.trim())return;let e=new Blob([M],{type:"text/plain"}),s=URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download=`deployment-${n}-${y||"logs"}.txt`,l.click(),URL.revokeObjectURL(s)},disabled:!M.trim(),children:[(0,a.jsx)(d.f5X,{className:"mr-2 h-4 w-4"}),r("Download")]}),(0,a.jsxs)("div",{className:"col-span-2 flex items-center justify-between gap-2 rounded-md border px-3 py-1.5 sm:col-span-1",children:[(0,a.jsx)("span",{className:"text-xs",children:r("Auto refresh")}),(0,a.jsx)(ed.d,{checked:h,onCheckedChange:p})]})]})]}),(0,a.jsxs)("div",{className:"mb-3 grid gap-2 sm:grid-cols-2 sm:gap-3",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Container")}),(0,a.jsxs)(eo.l6,{items:[...C.flatMap(e=>{let s=e?.container_id;if("string"!=typeof s||!s)return[];let l="string"==typeof e?.status&&e.status?` (${e.status})`:"";return[{value:s,label:(0,a.jsxs)(a.Fragment,{children:[s,l]})}]})],value:y,onValueChange:e=>null!==e&&v(e),disabled:N||0===C.length,children:[(0,a.jsx)(eo.bq,{children:(0,a.jsx)(eo.yv,{placeholder:r(N?"Loading...":0===C.length?"No containers":"Select")})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eo.s3,{children:C.map(e=>{let s=e?.container_id;if("string"!=typeof s||!s)return null;let l="string"==typeof e?.status&&e.status?` (${e.status})`:"";return(0,a.jsxs)(eo.eb,{value:s,children:[s,l]},s)})})})]})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:r("Stream")}),(0,a.jsxs)(eo.l6,{items:[{value:"stdout",label:"stdout"},{value:"stderr",label:"stderr"},{value:"all",label:"all"}],value:g,onValueChange:e=>{"stderr"===e||"all"===e||"stdout"===e?j(e):j("stdout")},children:[(0,a.jsx)(eo.bq,{children:(0,a.jsx)(eo.yv,{placeholder:r("Select")})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(eo.s3,{children:[(0,a.jsx)(eo.eb,{value:"stdout",children:"stdout"}),(0,a.jsx)(eo.eb,{value:"stderr",children:"stderr"}),(0,a.jsx)(eo.eb,{value:"all",children:"all"})]})})]})]})]}),(0,a.jsx)("div",{ref:i,className:"flex-1 overflow-auto rounded-md border bg-black p-3 sm:p-4",onScroll:e=>{let s=e.target;u(s.scrollHeight-s.scrollTop-s.clientHeight<50)},children:N||R?(0,a.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,a.jsx)(d.krw,{className:"h-6 w-6 animate-spin text-gray-400"})}):0===C.length?(0,a.jsx)("div",{className:"py-8 text-center text-gray-400",children:r("No containers")}):y?M.trim()?(0,a.jsx)("div",{className:"font-mono text-sm",children:I.map((e,s)=>(0,a.jsx)("div",{className:"whitespace-pre-wrap text-gray-200",children:e},s))}):(0,a.jsx)("div",{className:"py-8 text-center text-gray-400",children:r("No logs")}):(0,a.jsx)("div",{className:"py-8 text-center text-gray-400",children:r("Please select a container")})})]})})}let em=(0,r.GY)("/_authenticated/models/$section");function eu(){let{t:e}=(0,o.Bd)(),s=(0,n.jE)(),l=(0,b.Ub)("(max-width: 640px)"),{globalFilter:r,onGlobalFilterChange:i,columnFilters:m,onColumnFiltersChange:u,pagination:h,onPaginationChange:p,ensurePageInRange:g}=(0,w.c)({search:em.useSearch(),navigate:em.useNavigate(),pagination:{pageKey:"dPage",pageSizeKey:"dPageSize",defaultPage:1,defaultPageSize:l?8:10},globalFilter:{enabled:!0,key:"dFilter"},columnFilters:[{columnId:"status",searchKey:"dStatus",type:"array"}]}),j=r??"",S=m.find(e=>"status"===e.id)?.value||[],R=S.length>0&&!S.includes("all")?S[0]:void 0,[k,z]=(0,t.useState)(!1),[F,E]=(0,t.useState)(null),[$,A]=(0,t.useState)(!1),[O,B]=(0,t.useState)(null),[q,D]=(0,t.useState)(!1),[J,V]=(0,t.useState)(null),[Y,G]=(0,t.useState)(!1),[U,W]=(0,t.useState)(null),[Z,X]=(0,t.useState)(!1),[ee,es]=(0,t.useState)(null),[el,ea]=(0,t.useState)(""),[et,en]=(0,t.useState)(!1),[eo,ed]=(0,t.useState)(null),[eu,ex]=(0,t.useState)(!1),{data:eh,isLoading:ep,isFetching:eg}=(0,f.I)({queryKey:M.list({keyword:j,status:R,p:h.pageIndex+1,page_size:h.pageSize}),queryFn:async()=>j.trim()?(0,x.r8)({keyword:j,status:R,p:h.pageIndex+1,page_size:h.pageSize}):(0,x.Jn)({status:R,p:h.pageIndex+1,page_size:h.pageSize}),placeholderData:e=>e}),ej=eh?.data?.items||[],ef=eh?.data?.total||0,ey=async()=>
1{if(eo){ex(!0);try{let l=await (0,x.rd)(eo.id);l?.success?(N.oR.success(e("Deleted successfully")),s.invalidateQueries({queryKey:M.lists()})):N.oR.error(l?.message||e("Delete failed"))}catch(s){N.oR.error(s instanceof Error?s.message:e("Delete failed"))}finally{ex(!1),en(!1),ed(null)}}},[ev,eb]=(0,t.useState)({}),eN=function(e){let{t:s}=(0,o.Bd)(),l={running:{label:s("Running"),variant:"success"},completed:{label:s("Completed"),variant:"success"},failed:{label:s("Failed"),variant:"danger"},error:{label:s("Failed"),variant:"danger"},destroyed:{label:s("Destroyed"),variant:"danger"},"deployment requested":{label:s("Deployment requested"),variant:"warning"},"termination requested":{label:s("Termination requested"),variant:"warning"}};return[{accessorKey:"id",meta:{label:s("ID"),mobileHidden:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("ID")})},cell:e=>{let{row:s}=e,l=s.original.id;return(0,a.jsx)(T.C,{value:l})},size:120},{id:"name",accessorFn:e=>e.container_name||e.deployment_name||e.name||"",meta:{label:s("Name"),mobileTitle:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Name")})},cell:e=>{let{getValue:s}=e,l=String(s()||"-")||"-";return(0,a.jsx)(P.Wh,{label:l,variant:"neutral",copyText:l,size:"sm",className:"font-mono"})},minSize:220},{accessorKey:"status",meta:{label:s("Status"),mobileBadge:!0},header:s("Status"),cell:e=>{let{row:t}=e,n=t.original.status,r=l[L(n)]||{label:"string"==typeof n&&n.trim()?n.trim():s("Unknown"),variant:"neutral"};return(0,a.jsx)(P.Wh,{label:r.label,variant:r.variant,size:"sm",copyable:!1})},filterFn:(e,s,l)=>{if(!Array.isArray(l)||0===l.length||l.includes("all"))return!0;let a=L(e.getValue(s));return l.includes(a)},size:160,enableSorting:!1},{accessorKey:"provider",meta:{label:s("Provider")},header:s("Provider"),cell:e=>{let{row:s}=e,l=s.original.provider;return l?(0,a.jsx)(P.Wh,{label:String(l),autoColor:String(l),size:"sm",copyable:!1}):(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"})},size:140,enableSorting:!1},{accessorKey:"time_remaining",meta:{label:s("Time remaining")},header:s("Time remaining"),cell:e=>{let{row:l}=e,t=L(l.original.status),n="string"==typeof l.original.time_remaining&&l.original.time_remaining.trim()?l.original.time_remaining.trim():"-",r=function(e){let s="string"==typeof e?Number(e):"number"==typeof e?e:NaN;if(!Number.isFinite(s))return null;let l=Math.max(0,Math.round(s)),a=Math.floor(l/1440),t=Math.floor(l%1440/60),n=l%60,r=[];return a>0&&r.push(`${a}d`),t>0&&r.push(`${t}h`),(0===r.length||n>0)&&r.push(`${n}m`),r.join(" ")}(l.original.compute_minutes_remaining),i="number"==typeof l.original.completed_percent&&Number.isFinite(l.original.completed_percent)?Math.max(0,Math.min(100,Math.round(l.original.completed_percent))):null,o=null===i?null:Math.max(0,Math.min(100,100-i));return(0,a.jsxs)("div",{className:"flex flex-col gap-1 text-sm",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium",children:n}),"running"===t&&null!==o?(0,a.jsx)(P.Wh,{label:`${o}%`,variant:"info",size:"sm",copyable:!1}):null]}),r?(0,a.jsxs)("div",{className:"text-muted-foreground text-xs",children:[s("Approx.")," ",r]}):null]})},minSize:220,enableSorting:!1},{id:"hardware",meta:{label:s("Hardware"),mobileHidden:!0},header:s("Hardware"),accessorFn:e=>e.hardware_info||e.hardware_name||e.brand_name||"",cell:e=>{let{row:s}=e,l=s.original.hardware_name||("string"==typeof s.original.hardware_info?s.original.hardware_info:""),t="number"==typeof s.original.hardware_quantity?s.original.hardware_quantity:null;return l?(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)(P.Wh,{label:String(l),variant:"neutral",copyText:String(l),size:"sm"}),null!==t?(0,a.jsxs)("span",{className:"text-muted-foreground text-xs",children:["Ã",t]}):null]}):(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"})},minSize:220,enableSorting:!1},{accessorKey:"created_at",meta:{label:s("Created"),mobileHidden:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Created")})},cell:e=>{let{row:s}=e,l="number"==typeof s.original.created_at?s.original.created_at:"string"==typeof s.original.created_at?Number(s.original.created_at):void 0;return(0,a.jsx)("div",{className:"min-w-[140px] font-mono text-sm",children:(0,I.fk)(l)})},size:180},{id:"actions",enableHiding:!1,enableSorting:!1,cell:l=>{let{row:t}=l,n=t.original.id,r=t.original.container_name||t.original.deployment_name||t.original.n
1ame||"";return(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>e.onViewLogs(n),title:s("View logs"),children:(0,a.jsx)(d.kU3,{className:"h-4 w-4"})}),(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>e.onViewDetails(n),title:s("View details"),children:(0,a.jsx)(d.R2D,{className:"h-4 w-4"})}),(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>e.onUpdateConfig(n),title:s("Update configuration"),children:(0,a.jsx)(d.W$k,{className:"h-4 w-4"})}),(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>e.onExtend(n),title:s("Extend deployment"),children:(0,a.jsx)(d.M4G,{className:"h-4 w-4"})}),(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>e.onRename(n,String(r)),title:s("Rename deployment"),children:(0,a.jsx)(d.gHP,{className:"h-4 w-4"})}),(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>e.onDelete(t.original),title:s("Delete"),children:(0,a.jsx)(d.TBR,{className:"h-4 w-4 text-red-500"})})]})},size:180}]}({onViewLogs:e=>{E(e),z(!0)},onViewDetails:e=>{B(e),A(!0)},onUpdateConfig:e=>{V(e),D(!0)},onExtend:e=>{W(e),G(!0)},onRename:(e,s)=>{ea(s),es(e),X(!0)},onDelete:e=>{ed(e),en(!0)}}),ew=(0,y.N4)({data:ej,columns:eN,pageCount:Math.ceil(ef/h.pageSize),state:{columnFilters:m,columnVisibility:ev,pagination:h,globalFilter:r},onColumnFiltersChange:u,onColumnVisibilityChange:eb,onPaginationChange:p,onGlobalFilterChange:i,getCoreRowModel:(0,v.HT)(),manualPagination:!0,manualFiltering:!0}),e_=ew.getPageCount();(0,t.useEffect)(()=>{g(e_)},[g,e_]);let eC=(0,t.useMemo)(()=>[{label:e("All Status"),value:"all"},{label:e("Running"),value:"running"},{label:e("Completed"),value:"completed"},{label:e("Failed"),value:"failed"},{label:e("Deployment requested"),value:"deployment requested"},{label:e("Termination requested"),value:"termination requested"},{label:e("Destroyed"),value:"destroyed"}].map(e=>({label:e.label,value:e.value})),[e]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(C.cx,{table:ew,columns:eN,isLoading:ep,isFetching:eg,emptyTitle:e("No Deployments Found"),emptyDescription:e("No deployments available. Create one to get started."),skeletonKeyPrefix:"deployment-skeleton",applyHeaderSize:!0,toolbarProps:{searchPlaceholder:e("Search deployments..."),filters:[{columnId:"status",title:e("Status"),options:eC,singleSelect:!0}]}}),(0,a.jsx)(ec,{open:k,onOpenChange:e=>{z(e),e||E(null)},deploymentId:F}),(0,a.jsx)(ei,{open:$,onOpenChange:e=>{A(e),e||B(null)},deploymentId:O}),(0,a.jsx)(er,{open:q,onOpenChange:e=>{D(e),e||V(null)},deploymentId:J}),(0,a.jsx)(H,{open:Y,onOpenChange:e=>{G(e),e||W(null)},deploymentId:U}),(0,a.jsx)(Q,{open:Z,onOpenChange:e=>{X(e),e||es(null)},deploymentId:ee,currentName:el}),(0,a.jsx)(_.Lt,{open:et,onOpenChange:en,children:(0,a.jsxs)(_.EO,{children:[(0,a.jsxs)(_.wd,{children:[(0,a.jsx)(_.r7,{children:e("Confirm delete")}),(0,a.jsx)(_.$v,{children:e('Are you sure you want to delete deployment "{{name}}"? This action cannot be undone.',{name:eo?.container_name||eo?.deployment_name||eo?.id})})]}),(0,a.jsxs)(_.ck,{children:[(0,a.jsx)(_.Zr,{disabled:eu,children:e("Cancel")}),(0,a.jsx)(_.Rx,{onClick:ey,disabled:eu,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:eu?e("Deleting..."):e("Delete")})]})]})})]})}var ex=l(55667),eh=l(10998),ep=l(5304),eg=l(88584);let ej="ollama/ollama:latest",ef=E.Ik({resource_private_name:E.Yj().min(1),image_url:E.Yj().min(1),traffic_port:Z.ai().int().min(1).max(65535),hardware_id:E.Yj().min(1),gpus_per_container:Z.ai().int().min(1),location_ids:E.YO(E.Yj()).min(1),replica_count:Z.ai().int().min(1),duration_hours:Z.ai().int().min(1),env_json:E.Yj().optional(),secret_env_json:E.Yj().optional(),entrypoint:E.Yj().optional(),args:E.Yj().optional(),registry_username:E.Yj().optional(),registry_secret:E.Yj().optional(),currency:E.Yj().optional()});function ey(e,s){let l="number"==typeof e?e:Number(e);return Number.isFinite(l)?l:s}function ev(e){let{open:s,onOpenChange:l}=e,{t:r}=(0,o.Bd)(),i=(0,n.jE)(),d=(0,X.mN)({resolver:(0,ee.u)(ef),defaultValues:{resource_private_name:"",image_url:ej,traffic_port:11434,hardware_id:"",gpus_per_container:1,location_ids:[],replica_count:1,duration_hours:1,env_json:"",secret_env_json:"",entrypoint:"",args:"",registry_username:"",registry_secret:"",currency:"usdc"}}),m=d.watch("hardware_id"),u=ey(d.watch("gpus_per_container"),1),h=d.watch("location_ids"),p=ey(d.watch("duration_hours"),1),g=ey(d.watch("replica_count"),1),j=ey(d.watch("traffic_port"),11434),y=d.watch("currency"),v=d.watch("resource_private_name"),{data:b,isLoading:w}=(0,f.I)({queryKey:["deployment-hardware-types"],queryFn:x.cN,enabled:s}),_=(0,t.useMemo)(()=>{let e=b?.data?.hardware_types||[];return Array.isArray(e)?e.map(e=>({label:(e?.brand_name?`${e.brand_name} `:"")+String(e?.name??e?.id),value:String(e?.id),max_gpus:Number(e?.max_gpus||1)}
1)):[]},[b]);(0,t.useEffect)(()=>{if(!m)return;let e=_.find(e=>e.value===m);if(!e)return;let s=Number.isFinite(e.max_gpus)&&e.max_gpus>0?e.max_gpus:1;u>s&&d.setValue("gpus_per_container",s)},[m,_,u,d]);let{data:C,isLoading:S}=(0,f.I)({queryKey:["deployment-available-replicas",m,u],queryFn:()=>(0,x.Jd)({hardware_id:m,gpu_count:u}),enabled:s&&!!m&&u>0}),R=(0,t.useMemo)(()=>{let e=C?.data?.replicas||[];if(!Array.isArray(e))return[];let s=new Map;return e.forEach(e=>{let l=e?.location_id??e?.location?.id;if(null==l)return;let a=e?.location_name??e?.location?.name??e?.name??String(l),t=String(l);s.has(t)||s.set(t,{label:String(a),value:t})}),Array.from(s.values())},[C]),{data:k,isLoading:z}=(0,f.I)({queryKey:["deployment-price",m,u,p,g,h,y],queryFn:()=>(0,x.c9)({location_ids:h,hardware_id:m,gpus_per_container:u,duration_hours:p,replica_count:g,currency:y||"usdc"}),enabled:s&&!!m&&u>0&&p>0&&g>0&&h.length>0}),{data:I,isFetching:F}=(0,f.I)({queryKey:["deployment-name-check",v],queryFn:async()=>{let e=(v||"").trim();return e?await (0,x.Z7)(e):null},enabled:s&&!!(v&&v.trim().length>0),staleTime:1e4}),E=I?.success===!0?I?.data?.available:void 0,$=(0,ex.n)({mutationFn:async e=>{let s=e.env_json&&e.env_json.trim()?JSON.parse(e.env_json):void 0,l=e.secret_env_json&&e.secret_env_json.trim()?JSON.parse(e.secret_env_json):void 0,a=s&&"object"==typeof s&&!Array.isArray(s)?Object.fromEntries(Object.entries(s).map(e=>{let[s,l]=e;return[s,String(l)]})):void 0,t=l&&"object"==typeof l&&!Array.isArray(l)?Object.fromEntries(Object.entries(l).map(e=>{let[s,l]=e;return[s,String(l)]})):void 0,n=Number(e.gpus_per_container),r=Number(e.duration_hours),i=Number(e.replica_count),o=e.entrypoint?e.entrypoint.split(" ").map(e=>e.trim()).filter(Boolean):void 0,d=e.args?e.args.split(" ").map(e=>e.trim()).filter(Boolean):void 0,c=(e.location_ids||[]).map(e=>Number(e)).filter(e=>Number.isInteger(e)&&e>0),m={resource_private_name:e.resource_private_name.trim(),duration_hours:Number.isFinite(r)?r:1,gpus_per_container:Number.isFinite(n)?n:1,hardware_id:Number(e.hardware_id),location_ids:c,container_config:{replica_count:Number.isFinite(i)?i:1,traffic_port:Number.isFinite(j)?j:11434,...o?.length?{entrypoint:o}:{},...d?.length?{args:d}:{},...a?{env_variables:a}:{},...t?{secret_env_variables:t}:{}},registry_config:{image_url:e.image_url,...e.registry_username?.trim()?{registry_username:e.registry_username.trim()}:{},...e.registry_secret?.trim()?{registry_secret:e.registry_secret.trim()}:{}}};return await (0,x.Yy)(m)},onSuccess:e=>{if(e?.success){N.oR.success(r("Deployment created successfully")),i.invalidateQueries({queryKey:M.lists()}),l(!1);return}N.oR.error(e?.message||r("Failed to create deployment"))},onError:e=>{N.oR.error(e.message||r("Failed to create deployment"))}});return(0,t.useEffect)(()=>{s&&d.reset({resource_private_name:"",image_url:ej,traffic_port:11434,hardware_id:"",gpus_per_container:1,location_ids:[],replica_count:1,duration_hours:1,env_json:"",secret_env_json:"",entrypoint:"",args:"",registry_username:"",registry_secret:"",currency:"usdc"})},[s,d]),(0,t.useMemo)(()=>{let e=k?.data;if(!e||"object"!=typeof e)return"";let s=e?.total_cost??e?.total??"",l=e?.currency??"";return""===s&&""===l?"":`${s} ${l}`.trim()},[k]),(0,a.jsx)(eh.cj,{open:s,onOpenChange:e=>{l(e),e||d.reset()},children:(0,a.jsxs)(eh.h,{className:(0,ep.jW)("sm:max-w-[600px]"),children:[(0,a.jsxs)(eh.Fm,{className:(0,ep.Dt)(),children:[(0,a.jsx)(eh.qp,{children:r("Create deployment")}),(0,a.jsx)(eh.Qs,{children:r("Configure and deploy a new container instance.")})]}),(0,a.jsx)(el.lV,{...d,children:(0,a.jsxs)("form",{id:"deployment-form",onSubmit:d.handleSubmit(e=>$.mutate(e)),className:(0,ep.e)(),children:[(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-medium",children:r("Basic Configuration")}),(0,a.jsx)(el.zB,{control:d.control,name:"resource_private_name",render:e=>{let{field:l}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Container name")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:r("Enter a name"),...l})}),s&&l.value?.trim()?(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:F?r("Checking name..."):!0===E?r("Name is available"):!1===E?r("Name is not available"):""}):null,(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:d.control,name:"image_url",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Image")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{...s})}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-medium",children:r("Resource Configuration")}),(0,a.jsx)("div",{className:"grid gap-4 sm:grid-cols-2",children:(0,a.jsx)(el.zB,{control:d.control,name:"hardware_id",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Hardware type")}),(0,a.jsxs)(eo.l6,{items:[..._.map(e=>({value:e.value,label:e.label}))],value:s.value,onValueChange:e=>s.onChange(e),disabled:w,children:[(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eo.bq,{className:"w-full",children:(0,a.jsx)(eo.yv,{placeholder:r("Select")})})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eo.s3,{children:_.map(e=>(0,a.jsx)(eo.eb,{value:e.value,children:e.label},e.value))})})]}),(0,a.jsx)(el.C5,{})]})}})}),(0,a.jsx)(el.zB,{control:d.control,name:"location_ids",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Deployment location")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eg.K,{options:R,selected:s.value||[],onChange:e=>{!S&&m&&s.onChange(e)},placeholder:S?r("Loading..."):r("Select locations"),className:S||!m?"pointer-events-none opacity-60":""})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(el.zB,{control:d.control,name:"gpus_per_container",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("GPU count")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"number",value:ey(s.value,u),onChange:e=>s.onChange(""===e.target.value?0:Number(e.target.value))})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:d.control,name:"replica_count",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Replica count")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"number",value:ey(s.value,g),onChange:e=>s.onChange(""===e.target.value?0:Number(e.target.value))})}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(el.zB,{control:d.control,name:"duration_hours",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Duration (hours)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"number",value:ey(s.value,p),onChange:e=>s.onChange(""===e.target.value?0:Number(e.target.value))})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:d.control,name:"traffic_port",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Port")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"number",value:ey(s.value,
1j),onChange:e=>s.onChange(""===e.target.value?0:Number(e.target.value))})}),(0,a.jsx)(el.C5,{})]})}})]})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-medium",children:r("Price estimation")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:r("Price estimation description")}),(0,a.jsx)(el.zB,{control:d.control,name:"currency",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Billing currency")}),(0,a.jsxs)(eo.l6,{items:[{value:"usdc",label:"USDC"},{value:"iocoin",label:"IOCOIN"}],value:s.value||"usdc",onValueChange:e=>s.onChange(e),children:[(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eo.bq,{className:"w-full",children:(0,a.jsx)(eo.yv,{placeholder:r("Select")})})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(eo.s3,{children:[(0,a.jsx)(eo.eb,{value:"usdc",children:"USDC"}),(0,a.jsx)(eo.eb,{value:"iocoin",children:"IOCOIN"})]})})]})]})}})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-medium",children:r("Advanced Configuration")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:r("Optional settings for advanced container configuration.")}),(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(el.zB,{control:d.control,name:"entrypoint",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Entrypoint (space separated)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:"bash -lc",...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:d.control,name:"args",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Args (space separated)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:"--foo bar",...s})}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsx)(el.zB,{control:d.control,name:"env_json",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Environment variables (JSON)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{className:"min-h-24 font-mono text-xs",placeholder:'{"KEY":"VALUE"}',...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:d.control,name:"secret_env_json",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Secret environment variables (JSON)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{className:"min-h-24 font-mono text-xs",placeholder:'{"SECRET":"VALUE"}',...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(el.zB,{control:d.control,name:"registry_username",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Registry username")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{autoComplete:"off",...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:d.control,name:"registry_secret",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:r("Registry secret")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"password",autoComplete:"off",...s})}),(0,a.jsx)(el.C5,{})]})}})]})]})]})]})}),(0,a.jsxs)(eh.XW,{className:(0,ep.Jx)(),children:[(0,a.jsx)(eh.kN,{render:(0,a.jsx)(c.$,{variant:"outline"}),children:r("Cancel")}),(0,a.jsx)(c.$,{form:"deployment-form",type:"submit",disabled:$.isPending,children:$.isPending?r("Submitting..."):r("Create")})]})]})})}var eb=l(3676);function eN(e){let{open:s,onOpenChange:l,modelName:t,description:n}=e,{t:r}=(0,o.Bd)();return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"max-w-2xl",children:[(0,a.jsxs)(Y.c7,{children:[(0,a.jsx)(Y.L3,{children:t}),(0,a.jsx)(Y.rr,{children:r("Model Description")})]}),(0,a.jsx)(eb.F,{className:"max-h-96",children:(0,a.jsx)("div",{className:"space-y-2 pr-4",children:(0,a.jsx)("p",{className:"text-foreground text-sm leading-relaxed break-words whitespace-pre-wrap",children:n})})})]})})}var ew=l(23448),e_=l(15648);let eC=(0,t.createContext)(void 0);function eS(e){let{children:s}=e,[l,n]=(0,t.useState)(null),[r,i]=(0,t.useState)(null),[o,d]=(0,t.useState)(null),[c,m]=(0,t.useState)(null),[u,x]=(0,t.useState)(null),[h,p]=(0,t.useState)([]),[g,j]=(0,t.useState)({locale:"zh",source:"official"}),[f,y]=(0,t.useState)("metadata");return(0,a.jsx)(eC.Provider,{value:{open:l,setOpen:n,currentRow:r,setCurrentRow:i,currentVendor:o,setCurrentVendor:d,selectedVendor:c,setSelectedVendor:m,descriptionData:u,setDescriptionData:x,upstreamConflicts:h,setUpstreamConflicts:p,syncWizardOptions:g,setSyncWizardOptions:j,tabCategory:f,setTabCategory:y},children:s})}function eR(){let e=(0,t.useContext)(eC);if(!e)throw Error("useModels must be used within ModelsProvider");return e}function ek(e){let{open:s,onOpenChange:l}=e,{t:n}=(0,o.Bd)(),{setOpen:r,setCurrentRow:i}=eR(),m=(0,ew.a)(),[u,h]=(0,t.useState)(""),[p,g]=(0,t.useState)(1),{data:j,isLoading:y}=(0,f.I)({queryKey:R.missing(),queryFn:x.ng,enabled:s}),v=(0,t.useMemo)(()=>j?.data||[],[j?.data]);(0,t.useEffect)(()=>{s&&(h(""),g(1))},[s]);let b=(0,t.useMemo)(()=>
1{if(!u.trim())return v;let e=u.toLowerCase().trim();return v.filter(s=>s.toLowerCase().includes(e))},[v,u]),N=b.length,w=0===N?1:Math.ceil(N/20);(0,t.useEffect)(()=>{p>w&&g(Math.max(1,w))},[p,w]);let _=(0,t.useMemo)(()=>{let e=(p-1)*20;return b.slice(e,e+20)},[b,p,20]),C=0===N?0:(p-1)*20+1,S=0===N?0:Math.min(20*p,N),k=N>20;return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"flex max-h-[85vh] max-w-2xl flex-col gap-3 p-4",initialFocus:!m,children:[(0,a.jsxs)(Y.c7,{className:"flex-shrink-0 text-start",children:[(0,a.jsx)(Y.L3,{children:n("Missing Models")}),(0,a.jsx)(Y.rr,{children:n("Models that are being used but not configured in the system")})]}),y?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsx)(d.krw,{className:"h-8 w-8 animate-spin"})}):0===v.length?(0,a.jsxs)("div",{className:"text-muted-foreground py-12 text-center",children:[(0,a.jsx)("p",{children:n("No missing models found.")}),(0,a.jsx)("p",{className:"text-sm",children:n("All models in use are properly configured.")})]}):(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"flex flex-shrink-0 items-center justify-between gap-3",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-sm whitespace-nowrap",children:[n("Showing")," ",C,"-",S," ",n("of")," ",N]}),(0,a.jsxs)("div",{className:"relative w-48",children:[(0,a.jsx)(d.vji,{className:"text-muted-foreground pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"}),(0,a.jsx)(G.p,{value:u,onChange:e=>{h(e.target.value),g(1)},placeholder:n("Search models..."),className:"pl-9","aria-label":n("Search missing models")})]})]}),0===b.length?(0,a.jsx)(e_.Sv,{className:"border",children:(0,a.jsxs)(e_.FT,{children:[(0,a.jsx)(e_.Kr,{variant:"icon",children:(0,a.jsx)(d.vji,{className:"h-5 w-5"})}),(0,a.jsx)(e_.cz,{children:n("No matches found")}),(0,a.jsx)(e_.Ou,{children:n("Try adjusting your search to locate a missing model.")})]})}):(0,a.jsxs)("div",{className:"flex-shrink-0 rounded-lg border",children:[(0,a.jsx)("div",{className:"divide-y",children:_.map(e=>(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 p-3",children:[(0,a.jsx)("div",{className:"min-w-0 flex-1",children:(0,a.jsx)(P.Wh,{label:e,variant:"neutral",copyText:e})}),(0,a.jsxs)(c.$,{size:"sm",className:"flex-shrink-0 gap-1",onClick:()=>{i({model_name:e}),r("create-model")},children:[(0,a.jsx)(d.FWt,{className:"h-4 w-4"}),"Configure"]})]},e))}),(0,a.jsxs)("div",{className:"bg-muted/40 flex items-center justify-between border-t px-3 py-2 text-sm",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-sm",children:n("Page {{current}} of {{total}}",{current:p,total:w})}),k&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(c.$,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>g(e=>Math.max(1,e-1)),disabled:1===p,"aria-label":n("Previous page"),children:(0,a.jsx)(d.JGc,{className:"h-4 w-4"})}),(0,a.jsx)(c.$,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>g(e=>Math.min(w,e+1)),disabled:p===w,"aria-label":n("Next page"),children:(0,a.jsx)(d.c_$,{className:"h-4 w-4"})})]})]})]})]})]})})}var ez=l(34434),eM=l(63742);function eI(e){let{value:s=[],onChange:l,placeholder:n,className:r,disabled:i=!1}=e,{t:m}=(0,o.Bd)(),u=n??m("Add tags..."),[x,p]=(0,t.useState)(""),g=(0,t.useRef)(null),j=e=>{let a=e.trim();a&&!s.includes(a)&&(l([...s,a]),p(""))},f=e=>{l(s.filter(s=>s!==e))};return(0,a.jsxs)("div",{className:(0,h.cn)("border-input focus-within:border-ring focus-within:ring-ring/50 flex min-h-9 w-full flex-wrap items-center gap-2 rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-within:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),onClick:()=>g.current?.focus(),children:[s.map(e=>(0,a.jsxs)(eM.E,{variant:"secondary",className:"gap-1 pr-1",children:[e,!i&&(0,a.jsx)(c.$,{type:"button",variant:"ghost",size:"icon-sm","aria-label":"Remove tag",onClick:s=>{s.stopPropagation(),f(e)}
1,className:"hover:bg-secondary-foreground/20 size-auto rounded-sm p-0",children:(0,a.jsx)(d.X,{className:"h-3 w-3","aria-hidden":"true"})})]},e)),(0,a.jsx)("input",{ref:g,type:"text",value:x,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key||","===e.key?(e.preventDefault(),j(x)):"Backspace"===e.key&&!x&&s.length>0&&f(s[s.length-1])},onBlur:()=>{x.trim()&&j(x)},placeholder:0===s.length?u:"",disabled:i,className:"placeholder:text-muted-foreground min-w-[120px] flex-1 border-0 bg-transparent shadow-none outline-none focus-visible:ring-0"})]})}E.Ik({id:E.ai().optional(),model_name:E.Yj().min(1,"Model name is required"),description:E.Yj().default(""),icon:E.Yj().default(""),tags:E.YO(E.Yj()).default([]),vendor_id:E.ai().optional(),endpoints:E.Yj().default(""),name_rule:E.ai().min(0).max(3).default(0),status:E.zM().default(!0),sync_official:E.zM().default(!0)});let eF=E.Ik({id:E.ai().optional(),name:E.Yj().min(1,"Vendor name is required"),description:E.Yj().default(""),icon:E.Yj().default(""),status:E.ai().default(1)}),eE=E.Ik({id:E.ai().optional(),name:E.Yj().min(1,"Group name is required"),description:E.Yj().optional(),type:E.k5(["model","tag","endpoint"]),items:E.KC([E.Yj(),E.YO(E.Yj())])}),e$=[{value:"model",label:"Model Group",description:"Reusable sets of models you can attach to channels.",badge:"blue"},{value:"tag",label:"Tag Group",description:"Collections of metadata tags for bulk operations.",badge:"purple"},{value:"endpoint",label:"Endpoint Group",description:"HTTP endpoint mappings shared across providers.",badge:"cyan"}],eA=e$.reduce((e,s)=>(e[s.value]={label:s.label,badge:s.badge},e),{}),eO={name:"",description:"",type:"model",items:[]};function eB(e){if(!e)return[];if(Array.isArray(e))return e.map(e=>"string"==typeof e?e.trim():"").filter(Boolean);if("string"==typeof e)try{let s=JSON.parse(e);if(Array.isArray(s))return s.map(e=>"string"==typeof e?e.trim():"").filter(Boolean)}catch{return e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean)}return[]}function eq(e){let{open:s,onClose:l,currentGroup:r}=e,{t:i}=(0,o.Bd)(),m=(0,n.jE)(),u=!!r?.id,[h,p]=(0,t.useState)(!1),g=(0,X.mN)({resolver:(0,ee.u)(eE),defaultValues:eO}),j=g.watch("type");(0,t.useEffect)(()=>{s&&(u&&r?g.reset({id:r.id,name:r.name,description:r.description||"",type:r.type,items:"endpoint"===r.type?function(e){if(!e)return"";if("string"==typeof e)return e;try{return JSON.stringify(e,null,2)}catch{return""}}(r.items):eB(r.items)}):g.reset(eO))},[s,u,r,g]),(0,t.useEffect)(()=>{let e=g.getValues("items");"endpoint"===j&&Array.isArray(e)?g.setValue("items","",{shouldValidate:!1}):"endpoint"!==j&&"string"==typeof e&&g.setValue("items",[],{shouldValidate:!1})},[j,g]);let f=async e=>{p(!0);let s={name:e.name.trim(),type:e.type,description:e.description?.trim()||"",items:"endpoint"===e.type?"string"==typeof e.items?e.items:"":Array.isArray(e.items)?e.items:[]};try{let e=u?await (0,x.Lw)({id:r.id,...s}):await (0,x.Kx)(s);e.success?(N.oR.success(u?"Prefill group updated":"Prefill group created"),m.invalidateQueries({queryKey:z.lists()}),l()):N.oR.error(e.message||"Operation failed")}catch(e){N.oR.error(e?.message||"Operation failed")}finally{p(!1)}},y=eA[j]||eA.model;return(0,a.jsx)(eh.cj,{open:s,onOpenChange:e=>{e||l()},children:(0,a.jsxs)(eh.h,{className:(0,ep.jW)("sm:max-w-2xl"),children:[(0,a.jsxs)(eh.Fm,{className:(0,ep.Dt)(),children:[(0,a.jsx)(eh.qp,{children:u?i("Edit Prefill Group"):i("Create Prefill Group")}),(0,a.jsx)(eh.Qs,{children:u?i("Update the reusable bundle below."):i("Capture a reusable bundle of models, tags, or endpoints.")})]}),(0,a.jsx)(el.lV,{...g,children:(0,a.jsxs)("form",{id:"prefill-group-form",onSubmit:g.handleSubmit(f),className:(0,ep.e)(),children:[(0,a.jsxs)(ep.y5,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Group details")}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:i("Give the group a recognizable name and optional description.")})]}),(0,a.jsx)(el.zB,{control:g.control,name:"name",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Group Name")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:i("Premium chat models"),...s})}),(0,a.jsx)(el.Rr,{children:i("Give this group a recognizable name.")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:g.control,name:"description",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Description")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{placeholder:i("Optional notes about when to use this group"),rows:3,...s})}),(0,a.jsx)(el.Rr,{children:i("Make it easier for teammates to pick the right group.")}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Configuration")}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:i("Choose the bundle type and define the items inside it.")})]}),(0,a.jsx)(el.zB,{control:g.control,name:"type",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:"Group Type"}),(0,a.jsxs)(eo.l6,{items:[...e$.map(e=>({value:e.value,label:(0,a.jsxs)("div",{className:"flex flex-col text-left",children:[(0,a.jsx)("span",{className:"font-medium",children:e.label}),(0,a.jsx)("span",{"data-prefill-description":!0,className:"text-muted-foreground text-xs",children:e.description})]})}))],value:s.value,onValueChange:e=>null!==e&&s.onChange(e),children:[(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eo.bq,{className:"[&_[data-slot=select-value]_[data-prefill-description]]:hidden",children:(0,a.jsx)(eo.yv,{placeholder:i("Select a group type")})})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eo.s3,{children:e$.map(e=>(0,a.jsx)(eo.eb,{value:e.value,children:(0,a.jsxs)("div",{className:"flex flex-col text-left",children:[(0,a.jsx)("span",{className:"font-medium",children:e.label}),(0,a.jsx)("span",{"data-prefill-description":!0,className:"text-muted-foreground text-xs",children:e.description})]})},e.value))})})]}),(0,a.jsx)(el.Rr,{children:i("Determines how this group is applied elsewhere.")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsxs)("div",{className:"border-border/60 flex flex-col gap-3 border-y py-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("h4",{className:"text-sm font-medium",children:i("Project")}),(0,a.jsx)(P.Wh,{label:y.label,variant:y.badge,size:"sm",copyable:!1})]}),(0,a.jsx)(el.zB,{control:g.control,name:"items",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{className:"sr-only",children:i("Items")}),(0,a.jsx)(el.MJ,{children:"endpoint"===j?(0,a.jsx)(ez.i,{value:s.value||"",onChange:s.onChange,keyPlaceholder:"provider",valuePlaceholder:'{"path": "/v1/...","method": "POST"}',keyLabel:i("Provider"),valueLabel:i("Endpoint config"),valueType:"any",template:S,emptyMessage:i("Define endpoint mappings for each provider.")}):(0,a.jsx)(eI,{value:Array.isArray(s.value)?s.value:[],onChange:s.onChange,placeholder:i("Enter a value and press Enter")})}),(0,a.jsx)(el.Rr,{children:"endpoint"===j?i("Provide a JSON object where each key maps to an endpoint definition."):i("Add each model or tag you want to include.")}),(0,a.jsx)(el.C5,{})]})}})]})]})]})}),(0,a.jsxs)(eh.XW,{className:(0,ep.Jx)(),children:[(0,a.jsx)(eh.kN,{render:(0,a.jsx)(c.$,{type:"button",variant:"outline",disabled:h}),children:i("Cancel")}),(0,a.jsxs)(c.$,{type:"submit",form:"prefill-group-form",disabled:h,children:[h&&(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}),h?i("Saving..."):u?i("Save changes"):i("Create")]})]})]})})}var eD=l(31005),eJ=l(32999),eV=l(24993);function eK(e){let{open:s,onOpenChange:l,onCreateGroup:r,onEditGroup:i}=e,{t:m}=(0,o.Bd)(),u=(0,n.jE)(),g=(0,ew.a)(),[j,y]=(0,t.useState)({open:!1,group:null}),[v,b]=(0,t.useState)(!1),{data:w,isLoading:_,isFetching:C,error:S,refetch:R}=(0,f.I)({queryKey:z.list(),queryFn:()=>(0,x.xI)(),enabled:s}),k=(0,t.useMemo)(()=>w?.data??[],[w?.data]),M=(0,t.useMemo)(()=>[...k].sort((e,s)=>e.type===s.type?e.name.localeCompare(s.name):e.type.localeCompare(s.type)),[k]),I=(0,t.useMemo)(()=>M.map(e=>{let s=eA[e.type]||{label:e.type,badge:"neutral"},l="endpoint"===e.type?function(e){if(!e)return[];try{let s="string"==typeof e?JSON.parse(e||"{}"):e;if(Array.isArray(s))return s.map(e=>"string"==typeof e?e:"string"==typeof e?.name?e.name:"").filter(
1Boolean);if(s&&"object"==typeof s)return Object.keys(s)}catch{}return[]}(e.items):eB(e.items);return{group:e,meta:s,parsedItems:l}}),[M]);(0,t.useEffect)(()=>{s||(y({open:!1,group:null}),b(!1))},[s]);let F=e=>{y({open:!0,group:e})},E=async()=>{if(j.group){b(!0);try{let e=await (0,x.Vq)(j.group.id);e.success?(N.oR.success(`Deleted "${j.group.name}"`),u.invalidateQueries({queryKey:z.lists()}),y({open:!1,group:null})):N.oR.error(e.message||"Failed to delete group")}catch(e){N.oR.error(e?.message||"Failed to delete group")}finally{b(!1)}}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsx)(Y.Cf,{showCloseButton:!1,className:"prefill-dialog-content !top-4 !flex !-translate-y-0 !flex-col !gap-0 !border-none !bg-transparent !p-0 !shadow-none sm:!top-1/2 sm:!-translate-y-1/2",style:{maxWidth:"min(100vw, 64rem)"},children:(0,a.jsxs)("div",{className:(0,h.cn)("prefill-dialog-panel border-border/70 bg-background flex max-h-[calc(100dvh-1.5rem)] flex-col overflow-hidden border shadow-2xl",g?"rounded-none":"rounded-2xl"),children:[(0,a.jsxs)("div",{className:(0,h.cn)("relative flex flex-col gap-3 border-b px-4 py-4 sm:px-6 sm:py-5",g&&"pt-[calc(env(safe-area-inset-top,0px)+1rem)]"),children:[(0,a.jsxs)(Y.c7,{className:"max-w-3xl gap-3 pr-12 text-start sm:pr-0",children:[(0,a.jsxs)(Y.L3,{className:"flex flex-wrap items-center gap-2 text-xl",children:[(0,a.jsx)(d.ULk,{className:"text-foreground/80 h-5 w-5"}),m("Prefill Group Management")]}),(0,a.jsx)(Y.rr,{className:"text-base leading-relaxed sm:text-sm",children:m("Create reusable bundles of models, tags, endpoints, and user groups to speed up configuration elsewhere in the console.")})]}),(0,a.jsxs)(Y.HM,{render:(0,a.jsx)(c.$,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-foreground absolute top-4 right-4 border border-transparent sm:top-5 sm:right-6"}),children:[(0,a.jsx)("span",{className:"sr-only",children:m("Close dialog")}),(0,a.jsx)(d.X,{className:"h-4 w-4"})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3 border-b px-4 py-3 text-sm sm:px-6",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsxs)(c.$,{size:"sm",onClick:r,children:[(0,a.jsx)(d.FWt,{className:"mr-2 h-4 w-4"}),m("New Group")]}),(0,a.jsxs)(c.$,{size:"sm",variant:"ghost",onClick:()=>R(),disabled:C,children:[C?(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(d.g__,{className:"mr-2 h-4 w-4"}),m("Refresh")]})]}),(0,a.jsx)(P.Wh,{label:`${k.length} group${1===k.length?"":"s"}`,variant:"neutral",copyable:!1})]}),(0,a.jsx)("div",{className:(0,h.cn)("flex flex-1 flex-col overflow-hidden px-4 py-4 sm:px-6 sm:py-6",g&&"pb-[calc(env(safe-area-inset-bottom,0px)+1.5rem)]"),children:(0,a.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[S&&(0,a.jsxs)(p.Fc,{variant:"destructive",children:[(0,a.jsx)(p.XL,{children:m("Unable to load groups")}),(0,a.jsx)(p.TN,{children:S.message||"Please retry or refresh the page."})]}),_?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-center",children:[(0,a.jsx)(d.krw,{className:"text-muted-foreground h-6 w-6 animate-spin"}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:m("Fetching prefill groups...")})]}):0===I.length?(0,a.jsxs)(e_.Sv,{className:"border border-dashed",children:[(0,a.jsx)(e_.Kr,{variant:"icon",children:(0,a.jsx)(d.ULk,{className:"h-6 w-6"})}),(0,a.jsxs)(e_.FT,{children:[(0,a.jsx)(e_.cz,{children:m("No prefill groups yet")}),(0,a.jsx)(e_.Ou,{children:m("Create your first group to reuse model, tag, or endpoint selections anywhere in the dashboard.")})]}),(0,a.jsx)(e_.Ou,{children:m("Prefill groups help you keep complex configurations in sync.")})]}):g?(0,a.jsx)("div",{className:"space-y-4",children:I.map(e=>{let{group:s,meta:l,parsedItems:t}=e;return(0,a.jsxs)(eD.Zp,{className:"border-border/60",children:[(0,a.jsxs)(eD.aR,{className:"flex flex-row items-start justify-between gap-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)(eD.ZB,{className:"flex flex-wrap items-center gap-2",children:[s.name,(0,a.jsxs)(P.Wh,{variant:l.badge,size:"sm",copyable:!1,children:[l.label,(0,a.jsx)("span",{className:"text-muted-foreground
1/30",children:"·"}),(0,a.jsxs)("span",{className:"text-muted-foreground font-mono",children:["#",s.id]})]})]}),s.description?(0,a.jsx)(eD.BT,{className:"line-clamp-2",children:s.description}):(0,a.jsx)(eD.BT,{className:"text-muted-foreground italic",children:"No description provided"})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(c.$,{size:"icon",variant:"outline",onClick:()=>i(s),children:[(0,a.jsx)(d.gHP,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Edit group"})]}),(0,a.jsxs)(c.$,{size:"icon",variant:"ghost",className:"text-destructive hover:text-destructive",onClick:()=>F(s),children:[(0,a.jsx)(d.TBR,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Delete group"})]})]})]}),(0,a.jsxs)(eD.Wu,{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"text-muted-foreground flex flex-wrap items-center gap-2 text-xs font-medium tracking-wide uppercase",children:[(0,a.jsx)("span",{children:"Items"}),(0,a.jsx)(P.Wh,{label:`${t.length} item${1===t.length?"":"s"}`,variant:"neutral",size:"sm",copyable:!1})]}),t.length>0?(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[t.slice(0,6).map(e=>(0,a.jsx)(P.Wh,{label:e,autoColor:e,size:"sm"},e)),t.length>6&&(0,a.jsx)(P.Wh,{label:`+${t.length-6} more`,variant:"neutral",size:"sm",copyable:!1})]}):(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:"endpoint"===s.type?"No endpoint mappings configured.":"No items configured yet."})]})]},s.id)})}):(0,a.jsx)("div",{className:"rounded-md border",children:(0,a.jsx)("div",{className:"w-full overflow-x-auto",children:(0,a.jsxs)(eJ.XI,{className:"min-w-[720px]",children:[(0,a.jsx)(eJ.A0,{children:(0,a.jsxs)(eJ.Hj,{children:[(0,a.jsx)(eJ.nd,{children:m("Group")}),(0,a.jsx)(eJ.nd,{children:m("Type")}),(0,a.jsx)(eJ.nd,{className:"min-w-[280px]",children:m("Items")}),(0,a.jsx)(eJ.nd,{className:"w-[120px] text-right",children:m("Actions")})]})}),(0,a.jsx)(eJ.BF,{children:I.map(e=>{let{group:s,meta:l,parsedItems:t}=e;return(0,a.jsxs)(eJ.Hj,{children:[(0,a.jsx)(eJ.nA,{className:"align-top whitespace-normal",children:(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium",children:s.name}),(0,a.jsx)(T.C,{value:s.id})]}),s.description?(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:s.description}):(0,a.jsx)("p",{className:"text-muted-foreground text-xs italic",children:"No description provided"})]})}),(0,a.jsx)(eJ.nA,{className:"align-top",children:(0,a.jsx)(P.Wh,{label:l.label,variant:l.badge,size:"sm",copyable:!1})}),(0,a.jsxs)(eJ.nA,{className:"align-top whitespace-normal",children:[(0,a.jsx)("div",{className:"flex flex-wrap gap-2",children:t.length>0?(0,a.jsxs)(a.Fragment,{children:[t.slice(0,6).map(e=>(0,a.jsx)(P.Wh,{label:e,autoColor:e,size:"sm"},e)),t.length>6&&(0,a.jsx)(P.Wh,{label:`+${t.length-6} more`,variant:"neutral",size:"sm",copyable:!1})]}):(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:"endpoint"===s.type?"No endpoint mappings configured.":"No items configured yet."})}),(0,a.jsxs)("div",{className:"text-muted-foreground mt-2 text-xs font-medium tracking-wide uppercase",children:[t.length," item",1===t.length?"":"s"]})]}),(0,a.jsx)(eJ.nA,{className:"align-top",children:(0,a.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,a.jsxs)(c.$,{size:"icon",variant:"outline",onClick:()=>i(s),children:[(0,a.jsx)(d.gHP,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Edit group"})]}),(0,a.jsxs)(c.$,{size:"icon",variant:"ghost",className:"text-destructive hover:text-destructive",onClick:()=>F(s),children:[(0,a.jsx)(d.TBR,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Delete group"})]})]})})]},s.id)})})]})})})]})})})]})})}),(0,a.jsx)(eV.T,{open:j.open,onOpenChange:e=>y({open:e,group:null}),title:m("Delete group"),desc:(0,a.jsxs)("p",{children:[m("Are you sure you want to delete")," ",(0,a.jsx)("span",{className:"font-medium",children:j.group?.name}),m("? This action cannot be undone.")]}),destructive:!0,confirmText:v?"Deleting...":"Delete",isLoading:v,handleConfirm:E})]})}function eP(e){let{open:s,onOpenChange:l}=e,[n,r]=(0,t.useState)("dialog"),[i,o]=(0,t.useState)(null);(0,t.useEffect)(()=>{s||(r("dialog"),o(null))},[s]);let d=e=>{o(e),r("drawer")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(eK,{open:s&&"dialog"===n,onOpenChange:e=>{e||(r("dialog"),o(null),l(!1))},onCreateGroup:()=>d(null),onEditGroup:e=>d(e)}),(0,a.jsx)(eq,{open:s&&"drawer"===n,onClose:()=>{r("dialog"),o(null)},currentGroup:i})]})}var eT=l(61309),eL=l(92964);function eY(e){let{open:s,onOpenChange:l}=e,{t:r}=(0,o.Bd)(),i=(0,n.jE)(),{setOpen:m,setUpstreamConflicts:u,setSyncWizardOptions:p,syncWizardOptions:g}=eR(),j=(0,ew.a)(),[f,y]=(0,t.useState)("zh"),[v,b]=(0,t.useState)("official"),[w,_]=(0,t.useState)(!1),C=[{label:r("Official Repository"),value:"official",description:r("Sync from the public upstream metadata repository."),disabled:!1},{label:r("Configuration File"),value:"config",description:r("Upload or reference a local configuration file."),disabled:!0}],S=[{label:r("Chinese"),value:"zh"},{label:r("English"),value:"en"},{label:r("Japanese"),value:"ja"}];(0,t.useEffect)(()=>
1{if(s){y(g.locale||"zh");let e=C.find(e=>e.value===g.source);b(e&&!e.disabled?e.value:"official")}},[s,g,C]);let z=async()=>{_(!0);try{p({locale:f,source:v});let e=await (0,x.$v)({locale:f,source:v});if(!e.success)throw Error(e.message||"Failed to preview upstream diff");let s=e.data?.conflicts||[];if(s.length>0){N.oR.warning(`Found ${s.length} conflict${s.length>1?"s":""}. Please resolve them first.`),u(s),m("upstream-conflict");return}let a=await (0,x.ZZ)({locale:f,source:v});if(a.success){let{created_models:e,created_vendors:s,updated_models:t}=a.data||{};N.oR.success(`Sync completed! Created ${e||0} models, updated ${t||0}, and added ${s||0} vendors.`),i.invalidateQueries({queryKey:R.lists()}),i.invalidateQueries({queryKey:k.lists()}),l(!1)}else N.oR.error(a.message||"Sync failed")}catch(e){N.oR.error(e?.message||"Sync failed")}finally{_(!1)}};return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{className:"flex max-h-[90vh] w-full flex-col gap-4 p-4 sm:max-w-2xl sm:p-6",initialFocus:!j,children:[(0,a.jsxs)(Y.c7,{className:"flex-shrink-0 text-start",children:[(0,a.jsx)(Y.L3,{children:r("Sync Upstream Models")}),(0,a.jsx)(Y.rr,{children:r("Synchronize models and vendors from an upstream source")})]}),(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(eT.J,{className:"text-base",children:r("Select Sync Source")}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:r("Choose where to fetch upstream metadata.")})]}),(0,a.jsx)(eL.z,{value:v,onValueChange:e=>{let s=C.find(s=>s.value===e);s&&!s.disabled&&b(s.value)},className:"grid gap-3 md:grid-cols-2",children:C.map(e=>{let s=v===e.value,l=e.disabled;return(0,a.jsx)(eT.J,{htmlFor:`sync-source-${e.value}`,className:(0,h.cn)("flex-col items-start gap-0 rounded-lg border p-4 font-normal transition-all",s&&"border-primary ring-primary ring-1",l?"cursor-not-allowed opacity-60":"hover:border-primary/60 cursor-pointer"),children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)(eL.C,{value:e.value,id:`sync-source-${e.value}`,disabled:l}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"font-medium",children:e.label}),"official"===e.value&&(0,a.jsx)(P.Wh,{label:"Default",variant:"neutral",copyable:!1})]}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:e.description})]})]})},e.value)})})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eT.J,{className:"text-base",children:r("Select Language")}),(0,a.jsx)(eL.z,{value:f,onValueChange:e=>y(e),className:"grid gap-3 sm:grid-cols-3",children:S.map(e=>(0,a.jsxs)("div",{className:"flex items-center space-x-2 rounded-lg border p-3",children:[(0,a.jsx)(eL.C,{value:e.value,id:`locale-${e.value}`}),(0,a.jsx)(eT.J,{htmlFor:`locale-${e.value}`,className:"cursor-pointer font-normal",children:e.label})]},e.value))})]}),(0,a.jsx)("div",{className:"bg-muted/50 rounded-lg border p-4",children:(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:r("The sync will fetch missing models and vendors from the selected source. Existing records are updated only when you approve conflicts.")})})]}),(0,a.jsxs)(Y.Es,{className:"flex-shrink-0 gap-2 sm:justify-end",children:[(0,a.jsx)(c.$,{variant:"outline",onClick:()=>l(!1),disabled:w,children:r("Cancel")}),(0,a.jsxs)(c.$,{onClick:z,disabled:w,children:[w&&(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}),(0,a.jsx)(d.e9t,{className:"mr-2 h-4 w-4"}),w?"Syncing...":"Sync Now"]})]})]})})}var eG=l(33120),eU=l(48196);let eW={description:"Description",icon:"Icon",tags:"Tags",vendor:"Vendor",name_rule:"Name Rule",status:"Status",endpoints:"Endpoints",quota_types:"Quota Types",enable_groups:"Enable Groups"},eH=e=>{if(null==e)return"â";if("string"==typeof e)return e||"â";if("number"==typeof e||"boolean"==typeof e)return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}};function eQ(e){let{value:s}=e;return(0,a.jsx)("pre",{className:"bg-muted/70 text-muted-foreground max-h-32 overflow-auto rounded-md border px-2 py-1.5 font-mono text-xs break-words whitespace-pre-wrap",children:eH(s)})}function eZ(e){let{open:s,onOpenChange:l}=e,{t:r}=(0,o.Bd)(),i=(0,n.jE)(),{upstreamConflicts:m=[],setUpstreamConflicts:u,syncWizardOptions:h}=eR(),p=(0,ew.a)(),[g,j]=(0,t.useState)(""),[f,b]=(0,t.useState)(!1),[w,_]=(0,t.useState)({}),[C,S]=(0,t.useState)(10),[z,M]=(0,t.useState)(0);(0,t.useEffect)(()=>{s&&(_({}),j(""),M(0))},[s,m]);let I=(0,t.useMemo)(()=>m.flatMap(e=>e.fields?.length?e.fields.map(s=>({id:`${e.model_name}-${s.field}`,modelName:e.model_name,fieldKey:s.field,fieldLabel:eW[s.field]||s.field,localValue:s.local,upstreamValue:s.upstream})):[]),[m]),F=m.length,E=I.length,$=g.trim().toLowerCase(),{matchingModelNames:A,visibleRowIds:O}=(0,t.useMemo)(()=>
1{if(!$)return{matchingModelNames:null,visibleRowIds:null};let e=new Set;m.forEach(s=>{s.model_name?.toLowerCase().includes($)?e.add(s.model_name):s.fields?.some(e=>(eW[e.field]||e.field).toLowerCase().includes($)||e.field.toLowerCase().includes($))&&e.add(s.model_name)});let s=new Set;return I.forEach(l=>{(e.has(l.modelName)||l.fieldLabel.toLowerCase().includes($)||l.fieldKey.toLowerCase().includes($))&&s.add(l.id)}),{matchingModelNames:e,visibleRowIds:s}},[$,m,I]),B=(0,t.useMemo)(()=>{let e={accessorKey:"modelName",header:"Model",cell:e=>{let{row:s}=e;return(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[p?(0,a.jsx)(eG.S,{checked:s.getIsSelected(),onCheckedChange:e=>s.toggleSelected(!!e),"aria-label":"Select row"}):null,(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"leading-none font-medium",children:s.original.modelName}),(0,a.jsx)("span",{className:"text-muted-foreground font-mono text-xs",children:s.original.fieldKey}),p?(0,a.jsx)(P.Wh,{label:s.original.fieldLabel,variant:"neutral",size:"sm",copyable:!1}):null]})]})},size:220};return p?[e,{id:"actions",header:"Diff",enableSorting:!1,enableHiding:!1,cell:e=>{let{row:s}=e;return(0,a.jsxs)(eU.AM,{children:[(0,a.jsxs)(eU.Wv,{render:(0,a.jsx)(c.$,{variant:"ghost",size:"sm",className:p?"h-7 w-7 p-0":"h-7 gap-2 px-2 text-xs"}),children:[(0,a.jsx)(d.XEe,{className:"h-3.5 w-3.5"}),!p&&"View diff"]}),(0,a.jsxs)(eU.hl,{className:"w-[min(90vw,24rem)] space-y-4 text-sm",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(P.Wh,{label:"Local",variant:"neutral",size:"sm",copyable:!1,className:"mb-1"}),(0,a.jsx)("pre",{className:"bg-muted rounded-md p-2 text-xs",children:eH(s.original.localValue)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)(P.Wh,{label:"Upstream",variant:"info",size:"sm",copyable:!1,className:"mb-1"}),(0,a.jsx)("pre",{className:"bg-muted rounded-md p-2 text-xs",children:eH(s.original.upstreamValue)})]})]})]})},size:p?50:140}]:[{id:"select",header:e=>{let{table:s}=e;return(0,a.jsx)(eG.S,{checked:s.getIsAllPageRowsSelected(),indeterminate:s.getIsSomePageRowsSelected(),onCheckedChange:e=>s.toggleAllPageRowsSelected(!!e),"aria-label":"Select all"})},cell:e=>{let{row:s}=e;return(0,a.jsx)(eG.S,{checked:s.getIsSelected(),onCheckedChange:e=>s.toggleSelected(!!e),"aria-label":"Select row"})},enableSorting:!1,enableHiding:!1,size:40},e,{accessorKey:"fieldLabel",header:"Field",cell:e=>{let{row:s}=e;return(0,a.jsx)(P.Wh,{label:s.original.fieldLabel,variant:"neutral",size:"sm",copyable:!1})},enableSorting:!1,size:160},{accessorKey:"localValue",header:"Local Value",cell:e=>{let{row:s}=e;return(0,a.jsx)(eQ,{value:s.original.localValue})}},{accessorKey:"upstreamValue",header:"Upstream Value",cell:e=>{let{row:s}=e;return(0,a.jsx)(eQ,{value:s.original.upstreamValue})}}]},[p]),q=(0,y.N4)({data:I,columns:B,state:{rowSelection:w},enableRowSelection:!0,onRowSelectionChange:_,getCoreRowModel:(0,v.HT)(),getRowId:e=>e.id}),D=q.getSelectedRowModel().rows.length,J=D>0,V=q.getRowModel().rows,K=O?V.filter(e=>O.has(e.id)):V,T=K.length,L=0===T?1:Math.ceil(T/C);(0,t.useEffect)(()=>{M(e=>Math.min(e,Math.max(0,L-1)))},[L]);let U=z*C,W=K.slice(U,U+C),H=0===T?0:U+1,Q=0===T?0:Math.min(U+C,T),Z=0===T?0:z+1,X=0===T?0:L,ee=A?.size??F,es=E>0,el=es&&0===T,ea=(0,t.useCallback)(()=>{_({})},[]),et=async()=>{let e=Object.entries(q.getSelectedRowModel().rows.reduce((e,s)=>{let l=s.original.modelName;return e[l]||(e[l]=new Set),e[l].add(s.original.fieldKey),e},{})).map(e=>{let[s,l]=e;return{model_name:s,fields:Array.from(l)}}).filter(e=>e.fields.length>0);if(0===e.length)return void N.oR.warning(r("Select at least one field to overwrite."));b(!0);try{let s=await (0,x.RT)({overwrite:e,locale:h.locale,source:h.source});s.success?(N.oR.success(r("Selected conflicts were overwritten successfully.")),i.invalidateQueries({queryKey:R.lists()}),i.invalidateQueries({queryKey:k.lists()}),u([]),l(!1)):N.oR.error(s.message||r("Failed to apply overwrite."))}catch(e){N.oR.error(e?.message||r("Failed to apply overwrite."))}finally{b(!1)}};return(0,a.jsx)(Y.lG,{open:s,onOpenChange:e=>{e||u([]),l(e)},children:(0,a.jsxs)(Y.Cf,{className:"flex max-h-[90vh] w-full flex-col gap-4 p-4 sm:max-w-5xl sm:p-6",initialFocus:!p,children:[(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-hidden",children:[(0,a.jsxs)(Y.c7,{className:"flex-shrink-0 text-start",children:[(0,a.jsx)(Y.L3,{children:r("Resolve Conflicts")}),(0,a.jsx)(Y.rr,{children:r("Select the fields you want to overwrite with upstream data. Unselected fields keep their local values.")})]}),es?(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"text-sm font-medium",children:[ee," ",r("model"),1===ee?"":"s"," ",r("with conflicts")]}),(0,a.jsxs)("div",{className:"text-muted-foreground text-xs",children:[T," ",r("field"),1===T?"":"s"," ",r("showing â¢")," ",D," ",r("selected")]})]}),(0,a.jsxs)("div",{className:"flex w-full flex-col gap-2 sm:w-auto
1sm:flex-row",children:[(0,a.jsxs)("div",{className:"relative flex-1",children:[(0,a.jsx)(d.vji,{className:"text-muted-foreground pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"}),(0,a.jsx)(G.p,{value:g,onChange:e=>{j(e.target.value),M(0)},placeholder:r("Search models or fields..."),className:"pl-9","aria-label":r("Search conflicting models or fields")})]}),(0,a.jsx)(c.$,{variant:"ghost",size:"sm",onClick:ea,disabled:!J,children:r("Clear selection")})]})]}),el?(0,a.jsx)("div",{className:"text-muted-foreground flex flex-1 items-center justify-center rounded-md border border-dashed p-8 text-center text-sm",children:r("No conflicts match your search.")}):(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-md border",children:[(0,a.jsx)("div",{className:"flex-1 overflow-auto",children:(0,a.jsx)("div",{className:p?"min-w-full":"min-w-[720px]",children:(0,a.jsxs)(eJ.XI,{children:[(0,a.jsx)(eJ.A0,{children:q.getHeaderGroups().map(e=>(0,a.jsx)(eJ.Hj,{children:e.headers.map(e=>(0,a.jsx)(eJ.nd,{children:e.isPlaceholder?null:(0,y.Kv)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,a.jsx)(eJ.BF,{children:W.map(e=>(0,a.jsx)(eJ.Hj,{"data-state":e.getIsSelected()&&"selected",children:e.getVisibleCells().map(e=>(0,a.jsx)(eJ.nA,{children:(0,y.Kv)(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})}),(0,a.jsxs)("div",{className:"bg-muted/40 flex flex-col gap-2 border-t px-2 py-1.5 text-sm sm:flex-row sm:items-center sm:justify-between sm:gap-3 sm:px-3 sm:py-2",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-xs",children:[r("Showing")," ",H,"-",Q," ",r("of")," ",T," ",r("field"),1===T?"":"s"]}),(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 sm:flex-wrap sm:gap-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5 text-xs sm:gap-2",children:[(0,a.jsx)("span",{className:"hidden sm:inline",children:r("Rows per page")}),(0,a.jsxs)(eo.l6,{items:[...[5,10,20,50].map(e=>({value:String(e),label:e}))],value:String(C),onValueChange:e=>{S(Number(e)),M(0)},children:[(0,a.jsx)(eo.bq,{className:"h-8 w-[70px] text-xs sm:h-8 sm:w-[72px]",children:(0,a.jsx)(eo.yv,{})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eo.s3,{children:[5,10,20,50].map(e=>(0,a.jsx)(eo.eb,{value:String(e),children:e},e))})})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)(c.$,{variant:"outline",size:"icon",className:"h-7 w-7 sm:h-8 sm:w-8",onClick:()=>M(e=>Math.max(0,e-1)),disabled:0===z,"aria-label":r("Previous page"),children:(0,a.jsx)(d.JGc,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})}),(0,a.jsx)("span",{className:"text-xs font-medium",children:r("Page {{current}} of {{total}}",{current:Z,total:X})}),(0,a.jsx)(c.$,{variant:"outline",size:"icon",className:"h-7 w-7 sm:h-8 sm:w-8",onClick:()=>M(e=>Math.min(L-1,e+1)),disabled:z>=L-1||0===T,"aria-label":r("Next page"),children:(0,a.jsx)(d.c_$,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})]})]})]})]})]}):(0,a.jsx)("div",{className:"text-muted-foreground flex flex-1 items-center justify-center rounded-md border border-dashed p-8 text-center text-sm",children:r("No conflict entries available.")})]}),(0,a.jsx)(Y.Es,{className:"flex-shrink-0",children:(0,a.jsxs)("div",{className:"flex w-full flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"text-muted-foreground flex flex-1 items-start gap-2 text-xs",children:[(0,a.jsx)(d.R2D,{className:"h-4 w-4 flex-shrink-0"}),(0,a.jsx)("span",{children:r("Only selected fields will be overwritten. You can re-run the sync wizard if new conflicts appear.")})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:justify-end",children:[(0,a.jsx)(c.$,{variant:"outline",onClick:()=>{u([]),l(!1)},children:r("Cancel")}),(0,a.jsx)(c.$,{onClick:et,disabled:f||!J,children:f?r("Applying..."):r("Apply Overwrite")})]})]})})]})})}function eX(e){let{open:s,onOpenChange:l,currentVendor:r}=e,{t:i}=(0,o.Bd)(),m=(0,n.jE)(),u=!!r?.id,[h,p]=(0,t.useState)(!1),g=(0,X.mN)({resolver:(0,ee.u)(eF),defaultValues:{name:"",description:"",icon:"",status:1}});(0,t.useEffect)(()=>{s&&u&&r?g.reset({id:r.id,name:r.name,description:r.description||"",icon:r.icon||"",status:r.status||1}):s&&!u&&g.reset({name:"",description:"",icon:"",status:1})},[s,u,r,g]);let j=async e=>{p(!0);try{let s=u?await (0,x._d)({...e,id:r.id}):await (0,x.zC)(e);s.success?(N.oR.success(u?"Vendor updated successfully":"Vendor created successfully"),m.
1invalidateQueries({queryKey:k.lists()}),m.invalidateQueries({queryKey:R.lists()}),l(!1)):N.oR.error(s.message||"Operation failed")}catch(e){N.oR.error(e?.message||"Operation failed")}finally{p(!1)}};return(0,a.jsx)(Y.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(Y.Cf,{children:[(0,a.jsxs)(Y.c7,{children:[(0,a.jsx)(Y.L3,{children:u?i("Edit Vendor"):i("Create Vendor")}),(0,a.jsx)(Y.rr,{children:u?i("Update vendor information for {{name}}",{name:r?.name}):i("Add a new vendor to the system")})]}),(0,a.jsx)(el.lV,{...g,children:(0,a.jsxs)("form",{onSubmit:g.handleSubmit(j),className:"space-y-4",children:[(0,a.jsx)(el.zB,{control:g.control,name:"name",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Vendor Name *")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:i("OpenAI, Anthropic, etc."),...s})}),(0,a.jsx)(el.Rr,{children:i("The unique name for this vendor")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:g.control,name:"description",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Description")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{placeholder:i("Describe this vendor..."),rows:3,...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:g.control,name:"icon",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Icon")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:i("OpenAI, Anthropic, Google, etc."),...s})}),(0,a.jsx)(el.Rr,{children:i("@lobehub/icons key name")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsxs)(Y.Es,{children:[(0,a.jsx)(c.$,{type:"button",variant:"outline",onClick:()=>l(!1),disabled:h,children:i("Cancel")}),(0,a.jsxs)(c.$,{type:"submit",disabled:h,children:[h&&(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}),h?"Saving...":u?"Update":"Create"]})]})]})})]})})}var e0=l(7138),e1=l(21203),e2=l(61275),e4=l(85299);let e3=E.Ik({id:E.ai().optional(),model_name:E.Yj().min(1,"Model name is required"),description:E.Yj(),icon:E.Yj(),tags:E.YO(E.Yj()),vendor_id:E.ai().optional(),endpoints:E.Yj(),name_rule:E.ai(),status:E.zM(),sync_official:E.zM(),price:E.Yj().optional(),ratio:E.Yj().optional(),cacheRatio:E.Yj().optional(),completionRatio:E.Yj().optional(),imageRatio:E.Yj().optional(),audioRatio:E.Yj().optional(),audioCompletionRatio:E.Yj().optional()});function e5(e){let{open:s,onOpenChange:l,currentRow:r}=e,{t:i}=(0,o.Bd)(),m=(0,n.jE)(),u=!!r?.id,[h,p]=(0,t.useState)(!1),[g,j]=(0,t.useState)("per-token"),[y,v]=(0,t.useState)("ratio"),[b,w]=(0,t.useState)(!1),[_,C]=(0,t.useState)(""),[z,M]=(0,t.useState)(""),[I,E]=(0,t.useState)(""),{data:$}=(0,f.I)({queryKey:k.list(),queryFn:()=>(0,x.YQ)({page_size:1e3}),enabled:s}),A=$?.data?.items||[],{data:O}=(0,f.I)({queryKey:R.detail(r?.id||0),queryFn:()=>(0,x.E1)(r.id),enabled:s&&u}),{data:B}=(0,e0.b)(),q=(0,e1.M)(),D=(0,t.useMemo)(()=>B?.data?(0,e0.n)(B.data,{"global.pass_through_request_enabled":!1,"global.thinking_model_blacklist":"[]","global.chat_completions_to_responses_policy":"{}","general_setting.ping_interval_enabled":!1,"general_setting.ping_interval_seconds":60,"gemini.safety_settings":"","gemini.version_settings":"","gemini.supported_imagine_models":"","gemini.thinking_adapter_enabled":!1,"gemini.thinking_adapter_budget_tokens_percentage":.6,"gemini.function_call_thought_signature_enabled":!1,"gemini.remove_function_response_id_enabled":!0,"claude.model_headers_settings":"","claude.default_max_tokens":"","claude.thinking_adapter_enabled":!0,"claude.thinking_adapter_budget_tokens_percentage":.8,ModelPrice:"",ModelRatio:"",CacheRatio:"",CompletionRatio:"",ImageRatio:"",AudioRatio:"",AudioCompletionRatio:"",ExposeRatioEnabled:!1,"billing_setting.billing_mode":"{}","billing_setting.billing_expr":"{}","tool_price_setting.prices":"{}",TopupGroupRatio:"",GroupRatio:"",UserUsableGroups:"",GroupGroupRatio:"",AutoGroups:"",DefaultUseAutoGroup:!1,CreateCacheRatio:"","group_ratio_setting.group_special_usable_group":"{}","grok.violation_deduction_enabled":!1,"grok.violation_deduction_amount":0,"channel_affinity_setting.enabled":!1,"channel_affinity_setting.switch_on_success":!0,"channel_affinity_setting.max_entries":1e5,"channel_affinity_setting.default_ttl_seconds":3600,"channel_affinity_setting.rules":"[]","model_deployment.ionet.api_key":"","model_deployment.ionet.enabled":!1}):null,[B]),J=(0,X.mN)({resolver:(0,ee.u)(e3),defaultValues:{model_name:"",description:"",icon:"",tags:[],vendor_id:void 0,endpoints:"",name_rule:0,status:!0,sync_official:!0,price:"",ratio:"",cacheRatio:"",completionRatio:"",imageRatio:"",audioRatio:"",audioCompletionRatio:""}}),V=e=>""===e||!isNaN(parseFloat(e));(0,t.useEffect)(()=>
1{if(s&&u&&O?.data){let e=O.data;E(e.model_name);let s={id:e.id,model_name:e.model_name,description:e.description||"",icon:e.icon||"",tags:F(e.tags),vendor_id:e.vendor_id,endpoints:e.endpoints||"",name_rule:e.name_rule||0,status:1===e.status,sync_official:1===e.sync_official,price:"",ratio:"",cacheRatio:"",completionRatio:"",imageRatio:"",audioRatio:"",audioCompletionRatio:""};if(D){let l=(0,e4.jD)(D.ModelPrice,{fallback:{},silent:!0}),a=(0,e4.jD)(D.ModelRatio,{fallback:{},silent:!0}),t=(0,e4.jD)(D.CacheRatio,{fallback:{},silent:!0}),n=(0,e4.jD)(D.CompletionRatio,{fallback:{},silent:!0}),r=(0,e4.jD)(D.ImageRatio,{fallback:{},silent:!0}),i=(0,e4.jD)(D.AudioRatio,{fallback:{},silent:!0}),o=(0,e4.jD)(D.AudioCompletionRatio,{fallback:{},silent:!0}),d=e.model_name,c=l[d],m=a[d],u=t[d],x=n[d],h=r[d],p=i[d],g=o[d];if(null!=c)j("per-request"),J.reset({...s,price:c.toString()});else{if(j("per-token"),null!=m){let e=2*m;C(e.toString()),null!=x&&M((e*x).toString())}J.reset({...s,ratio:m?.toString()||"",cacheRatio:u?.toString()||"",completionRatio:x?.toString()||"",imageRatio:h?.toString()||"",audioRatio:p?.toString()||"",audioCompletionRatio:g?.toString()||""}),w(!!(u||h||p||g))}}else j("per-token"),J.reset(s),w(!1)}else s&&!u&&(E(""),j("per-token"),v("ratio"),C(""),M(""),w(!1),J.reset({model_name:r?.model_name||"",description:"",icon:"",tags:[],vendor_id:void 0,endpoints:"",name_rule:0,status:!0,sync_official:!0,price:"",ratio:"",cacheRatio:"",completionRatio:"",imageRatio:"",audioRatio:"",audioCompletionRatio:""}))},[s,u,O,r,J,D]);let K=(0,t.useCallback)(async e=>{p(!0);try{let{price:s,ratio:a,cacheRatio:t,completionRatio:n,imageRatio:i,audioRatio:o,audioCompletionRatio:d,...c}={...e,id:u?r.id:void 0,tags:Array.isArray(e.tags)?e.tags.join(","):"",status:+!!e.status,sync_official:+!!e.sync_official},h=u?await (0,x.Q5)({...c,id:r.id}):await (0,x.kQ)(c);if(h.success){let s=e.model_name,a="per-request"===g&&e.price&&""!==e.price||"per-token"===g&&(e.ratio||e.cacheRatio||e.completionRatio||e.imageRatio||e.audioRatio||e.audioCompletionRatio);if(D){let l=(0,e4.jD)(D.ModelPrice,{fallback:{},silent:!0}),t=(0,e4.jD)(D.ModelRatio,{fallback:{},silent:!0}),n=(0,e4.jD)(D.CacheRatio,{fallback:{},silent:!0}),r=(0,e4.jD)(D.CompletionRatio,{fallback:{},silent:!0}),i=(0,e4.jD)(D.ImageRatio,{fallback:{},silent:!0}),o=(0,e4.jD)(D.AudioRatio,{fallback:{},silent:!0}),d=(0,e4.jD)(D.AudioCompletionRatio,{fallback:{},silent:!0});u&&I&&I!==s&&(delete l[I],delete t[I],delete n[I],delete r[I],delete i[I],delete o[I],delete d[I]),delete l[s],delete t[s],delete n[s],delete r[s],delete i[s],delete o[s],delete d[s],a&&("per-request"===g&&e.price&&""!==e.price?l[s]=parseFloat(e.price):"per-token"===g&&(e.ratio&&""!==e.ratio&&(t[s]=parseFloat(e.ratio)),e.cacheRatio&&""!==e.cacheRatio&&(n[s]=parseFloat(e.cacheRatio)),e.completionRatio&&""!==e.completionRatio&&(r[s]=parseFloat(e.completionRatio)),e.imageRatio&&""!==e.imageRatio&&(i[s]=parseFloat(e.imageRatio)),e.audioRatio&&""!==e.audioRatio&&(o[s]=parseFloat(e.audioRatio)),e.audioCompletionRatio&&""!==e.audioCompletionRatio&&(d[s]=parseFloat(e.audioCompletionRatio))));let c=[],m=(0,e2.Nr)(JSON.stringify(l));m!==(0,e2.Nr)(D.ModelPrice)&&c.push({key:"ModelPrice",value:m});let x=(0,e2.Nr)(JSON.stringify(t));x!==(0,e2.Nr)(D.ModelRatio)&&c.push({key:"ModelRatio",value:x});let h=(0,e2.Nr)(JSON.stringify(n));h!==(0,e2.Nr)(D.CacheRatio)&&c.push({key:"CacheRatio",value:h});let p=(0,e2.Nr)(JSON.stringify(r));p!==(0,e2.Nr)(D.CompletionRatio)&&c.push({key:"CompletionRatio",value:p});let j=(0,e2.Nr)(JSON.stringify(i));j!==(0,e2.Nr)(D.ImageRatio)&&c.push({key:"ImageRatio",value:j});let f=(0,e2.Nr)(JSON.stringify(o));f!==(0,e2.Nr)(D.AudioRatio)&&c.push({key:"AudioRatio",value:f});let y=(0,e2.Nr)(JSON.stringify(d));for(let e of(y!==(0,e2.Nr)(D.AudioCompletionRatio)&&c.push({key:"AudioCompletionRatio",value:y}),c))await q.mutateAsync(e)}N.oR.success(u?"Model updated successfully":"Model created successfully"),m.invalidateQueries({queryKey:R.lists()}),m.invalidateQueries({queryKey:["system-options"]}),l(!1)}else N.oR.error(h.message||"Operation failed")}catch(e){N.oR.error(e?.message||"Operation failed")}finally{p(!1)}},[u,r,m,l,g,I,D,q]);return(0,a.jsx)(eh.cj,{open:s,onOpenChange:l,children:(0,a.jsxs)(eh.h,{className:(0,ep.jW)("sm:max-w-2xl"),children:[(0,a.jsxs)(eh.Fm,{className:(0,ep.Dt)(),children:[(0,a.jsx)(eh.qp,{children:u?i("Edit Model"):i("Create Model")}),(0,a.jsx)(eh.Qs,{children:u?i("Update model configuration and click save when you're done."):i("Add a new model to the system b
1y providing the necessary information.")})]}),(0,a.jsx)(el.lV,{...J,children:(0,a.jsxs)("form",{id:"model-form",onSubmit:J.handleSubmit(K),className:(0,ep.e)(),children:[(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Basic Information")}),(0,a.jsx)(el.zB,{control:J.control,name:"model_name",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Model Name *")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:i("gpt-4, claude-3-opus, etc."),...s})}),(0,a.jsx)(el.Rr,{children:i("The unique identifier for this model")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"description",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Description")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ea.T,{placeholder:i("Describe this model..."),rows:3,...s})}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"icon",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Icon")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{placeholder:i("OpenAI, Anthropic, etc."),...s})}),(0,a.jsx)(el.Rr,{className:"text-xs",children:i("@lobehub/icons key")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"vendor_id",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Vendor")}),(0,a.jsxs)(eo.l6,{items:[...A.map(e=>({value:String(e.id),label:e.name}))],onValueChange:e=>s.onChange(e?parseInt(e):void 0),value:s.value?String(s.value):void 0,children:[(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eo.bq,{children:(0,a.jsx)(eo.yv,{placeholder:i("Select vendor")})})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eo.s3,{children:A.map(e=>(0,a.jsx)(eo.eb,{value:String(e.id),children:e.name},e.id))})})]}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"tags",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Tags")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eI,{value:s.value||[],onChange:s.onChange,placeholder:i("Add tags...")})}),(0,a.jsx)(el.Rr,{children:i("Press Enter or comma to add tags")}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Matching Rules")}),(0,a.jsx)(el.zB,{control:J.control,name:"name_rule",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Name Rule")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(eL.z,{onValueChange:e=>s.onChange(parseInt(e)),value:String(s.value),className:"grid grid-cols-2 gap-4",children:[{label:i("Exact Match"),value:0},{label:i("Prefix Match"),value:1},{label:i("Contains Match"),value:2},{label:i("Suffix Match"),value:3}].map(e=>(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(eL.C,{value:String(e.value),id:`rule-${e.value}`}),(0,a.jsx)(eT.J,{htmlFor:`rule-${e.value}`,className:"cursor-pointer font-normal",children:e.label})]},e.value))})}),(0,a.jsx)(el.Rr,{children:i("How this model name should match requests")}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Endpoints")}),(0,a.jsxs)(eo.l6,{items:[...Object.keys(S).map(e=>({value:e,label:e}))],onValueChange:e=>null!==e&&(e=>{let s=S[e];if(s){let l=JSON.stringify({[e]:s},null,2);J.setValue("endpoints",l)}})(e),children:[(0,a.jsx)(eo.bq,{size:"sm",className:"w-[200px]",children:(0,a.jsx)(eo.yv,{placeholder:i("Load template...")})}),(0,a.jsx)(eo.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(eo.s3,{children:Object.keys(S).map(e=>(0,a.jsx)(eo.eb,{value:e,children:e},e))})})]})]}),(0,a.jsx)(el.zB,{control:J.control,name:"endpoints",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Endpoint Configuration")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ez.i,{value:s.value||"",onChange:s.onChange,keyPlaceholder:"endpoint_type",valuePlaceholder:'{"path": "/v1/...", "method": "POST"}',keyLabel:"Endpoint Type",valueLabel:"Configuration",valueType:"any",emptyMessage:i("No endpoints configured. Switch to JSON mode or add rows to define endpoints.")})}),(0,a.jsx)(el.Rr,{children:i("Define API endpoints for this model (JSON format)")}),(0,a.jsx)(el.C5,{})]})}})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Pricing Configuration")}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(eT.J,{children:i("Pricing mode")}),(0,a.jsxs)(eL.z,{value:g,onValueChange:e=>j(e),children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(eL.C,{value:"per-token",id:"per-token"}),(0,a.jsx)(eT.J,{htmlFor:"per-token",className:"font-normal",children:i("Per-token (ratio based)")})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(eL.C,{value:"per-request",id:"per-request"}),(0,a.jsx)(eT.J,{htmlFor:"per-request",className:"font-normal",children:i("Per-request (fixed price)")})]})]})]}),"per-request"===g?(0,a.jsx)(el.zB,{control:J.control,name:"price",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Fixed price (USD)")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"0.01",...s,onChange:e=>{let l=e.target.value;V(l)&&s.onChange(l)}})}),(0,a.jsx)(el.Rr,{children:i("Cost in USD per request, regardless of tokens used.")}),(0,a.jsx)(el.C5,{})]})}}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(eT.J,{children:i("Input mode")}),(0,a.jsxs)(eL.z,{value:y,onValueChange:e=>v(e),children:[(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(eL.C,{value:"ratio",id:"ratio"}),(0,a.jsx)(eT.J,{htmlFor:"ratio",className:"font-normal",children:i("Ratio mode")})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(eL.C,{value:"price",id:"price"}),(0,a.jsx)(eT.J,{htmlFor:"price",className:"font-normal",children:i("Price mode (USD per 1M tokens)")})]})]})]}),"ratio"===y?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(el.zB,{control:J.control,name:"ratio",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Model ratio")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"1.0",...s,onChange:e=>{let l=e.target.value;V(l)&&(s.onChange(l),l?C((2*parseFloat(l)).toString()):C(""))}})}),(0,a.jsx)(el.Rr,{children:s.value&&!isNaN(parseFloat(s.value))?`Calculated price: $${(2*parseFloat(s.value)).toFixed(4)} per 1M tokens`:i("Multiplier for prompt tokens.")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"completionRatio",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Completion ratio")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"1.0",...s,onChange:e=>{let l=e.target.value;if(V(l)){s.onChange(l);let e=J.getValues("ratio");
1l&&e?M((2*parseFloat(e)*parseFloat(l)).toString()):M("")}}})}),(0,a.jsx)(el.Rr,{children:s.value&&!isNaN(parseFloat(s.value))&&_&&!isNaN(parseFloat(_))?`Calculated price: $${(parseFloat(_)*parseFloat(s.value)).toFixed(4)} per 1M tokens`:i("Multiplier for completion tokens.")}),(0,a.jsx)(el.C5,{})]})}})]}):(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eT.J,{children:i("Prompt price ($/1M tokens)")}),(0,a.jsx)(G.p,{type:"text",placeholder:"2.0",value:_,onChange:e=>(e=>{if(C(e),e&&!isNaN(parseFloat(e))){let s=parseFloat(e)/2;J.setValue("ratio",s.toString())}else J.setValue("ratio","")})(e.target.value)}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:_&&!isNaN(parseFloat(_))?`Calculated ratio: ${(parseFloat(_)/2).toFixed(4)}`:i("Enter Input price to calculate ratio")})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(eT.J,{children:i("Completion price ($/1M tokens)")}),(0,a.jsx)(G.p,{type:"text",placeholder:"4.0",value:z,onChange:e=>(e=>{if(M(e),e&&!isNaN(parseFloat(e))&&_&&!isNaN(parseFloat(_))&&parseFloat(_)>0){let s=parseFloat(e)/parseFloat(_);J.setValue("completionRatio",s.toString())}else J.setValue("completionRatio","")})(e.target.value)}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:z&&!isNaN(parseFloat(z))&&_&&!isNaN(parseFloat(_))&&parseFloat(_)>0?`Calculated ratio: ${(parseFloat(z)/parseFloat(_)).toFixed(4)}`:i("Enter Completion price to calculate ratio")})]})]})}),(0,a.jsxs)(es.Nt,{open:b,onOpenChange:w,children:[(0,a.jsxs)(es.R6,{render:(0,a.jsx)(c.$,{type:"button",variant:"outline",className:"flex w-full items-center justify-between"}),children:[i("Advanced options"),(0,a.jsx)(d.yQN,{className:`h-4 w-4 transition-transform duration-200 ${b?"rotate-180":""}`})]}),(0,a.jsxs)(es.Ke,{className:"flex flex-col gap-4 pt-4",children:[(0,a.jsx)(el.zB,{control:J.control,name:"cacheRatio",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Cache ratio")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"0.1",...s,onChange:e=>{let l=e.target.value;V(l)&&s.onChange(l)}})}),(0,a.jsx)(el.Rr,{children:i("Discount ratio for cache hits.")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"imageRatio",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Image ratio")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"1.0",...s,onChange:e=>{let l=e.target.value;V(l)&&s.onChange(l)}})}),(0,a.jsx)(el.Rr,{children:i("Multiplier for image processing.")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"audioRatio",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Audio ratio")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"1.0",...s,onChange:e=>{let l=e.target.value;V(l)&&s.onChange(l)}})}),(0,a.jsx)(el.Rr,{children:i("Multiplier for audio inputs.")}),(0,a.jsx)(el.C5,{})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"audioCompletionRatio",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{children:[(0,a.jsx)(el.lR,{children:i("Audio completion ratio")}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(G.p,{type:"text",placeholder:"1.0",...s,onChange:e=>{let l=e.target.value;V(l)&&s.onChange(l)}})}),(0,a.jsx)(el.Rr,{children:i("Multiplier for audio outputs.")}),(0,a.jsx)(el.C5,{})]})}})]})]})]})]}),(0,a.jsxs)(ep.y5,{children:[(0,a.jsx)("h3",{className:"text-sm font-semibold",children:i("Status & Sync")}),(0,a.jsx)(el.zB,{control:J.control,name:"status",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{className:(0,ep.fE)(),children:[(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,a.jsx)(el.lR,{className:"text-base",children:i("Enabled")}),(0,a.jsx)(el.Rr,{children:i("Enable or disable this model")})]}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ed.d,{checked:s.value,onCheckedChange:s.onChange})})]})}}),(0,a.jsx)(el.zB,{control:J.control,name:"sync_official",render:e=>{let{field:s}=e;return(0,a.jsxs)(el.eI,{className:(0,ep.fE)(),children:[(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,a.jsx)(el.lR,{className:"text-base",children:i("Official Sync")}),(0,a.jsx)(el.Rr,{children:i("Sync this model with official upstream")})]}),(0,a.jsx)(el.MJ,{children:(0,a.jsx)(ed.d,{checked:s.value,onCheckedChange:s.onChange})})]})}})]})]})}),(0,a.jsxs)(eh.XW,{className:(0,ep.Jx)(),children:[(0,a.jsx)(eh.kN,{render:(0,a.jsx)(c.$,{variant:"outline",disabled:h}),children:i("Cancel")}),(0,a.jsxs)(c.$,{form:"model-form",type:"submit",disabled:h,children:[h&&(0,a.jsx)(d.krw,{className:"mr-2 h-4 w-4 animate-spin"}),u?i("Update Model"):i("Save changes")]})]})]})})}function e6(){let{open:e,setOpen:s,currentRow:l,currentVendor:t,descriptionData:n,setDescriptionData:r}=eR();return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(e5,{open:"create-model"===e||"update-model"===e,onOpenChange:e=>!e&&s(null),currentRow:l}),(0,a.jsx)(eX,{open:"create-vendor"===e||"update-vendor"===e,onOpenChange:e=>!e&&s(null),currentVendor:"update-vendor"===e?t:null}),(0,a.jsx)(ek,{open:"missing-models"===e,onOpenChange:e=>!e&&s(null)}),(0,a.jsx)(eY,{open:"sync-wizard"===e,onOpenChange:e=>!e&&s(null)}),(0,a.jsx)(eZ,{open:"upstream-conflict"===e,onOpenChange:e=>!e&&s(null)}),(0,a.jsx)(eP,{open:"prefill-groups"===e,onOpenChange:e=>!e&&s(null)}),(0,a.jsx)(eN,{open:"description"===e,onOpenChange:e=>{e||(s(null),r(null))},modelName:n?.modelName||"",description:n?.description||""})]})}var e8=l(43631);function e7(){let{t:e}=(0,o.Bd)(),{setOpen:s,setCurrentRow:l}=eR();return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(c.$,{onClick:()=>{l(null),s("create-model")},size:"sm",children:[(0,a.jsx)(d.FWt,{className:"h-4 w-4"}),e("Add Model")]}),(0,a.jsxs)(e8.rI,{children:[(0,a.jsx)(e8.ty,{render:(0,a.jsx)(c.$,{variant:"outline",size:"sm"}),children:(0,a.jsx)(d.a4,{className:"h-4 w-4"})}),(0,a.jsxs)(e8.SQ,{align:"end",className:"w-56",children:[(0,a.jsxs)(e8._2,{onClick:()=>{s("missing-models")},children:[e("Missing Models"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.RIJ,{className:"h-4 w-4"})})]}),(0,a.jsxs)(e8._2,{onClick:()=>{s("sync-wizard")},children:[e("Sync Upstream"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.e9t,{className:"h-4 w-4"})})]}),(0,a.jsx)(e8.mB,{}),(0,a.jsxs)(e8._2,{onClick:()=>{s("prefill-groups")},children:[e("Prefill Groups"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.B8B,{className:"h-4 w-4"})})]}),(0,a.jsxs)(e8._2,{onClick:()=>{s("create-vendor")},children:[e("Manage Vendors"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.t6i,{className:"h-4 w-4"})})]})]})]})]})}var e9=l(3075),se=l(34126);function ss(e){let{table:s}=e,{t:l}=(0,o.Bd)(),r=(0,n.jE)(),[i,m]=(0,t.useState)(!1),u=s.getFilteredSelectedRowModel().rows,x=u.reduce((e,s)=>{let l=s.original.id;return"number"==typeof l&&e.push(l),e},[]),h=u.map(e=>e.original),p=()=>{s.resetRowSelection()},g=async()=>{let e=h.map(e=>e.model_name).join(",");await (0,e9.l)(e)?N.oR.success(l("Model names copied to clipboard")):N.oR.error(l("Failed to copy model names"))};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(C.Of,{table:s,entityName:"model",children:[(0,a.jsxs)(se.m_,{children:[(0,a.jsxs)(se.k$,{render:(0,a.jsx)(c.$,{variant:"outline",size:"icon",onClick:()=>{J(x,r,p)},className:"size-8","aria-label":l("Enable selected models"),title:l("Enable selected models")}),children:[(0,a.jsx)(d.aJd,{}),(0,a.jsx)("span",{className:"sr-only",children:l("Enable selected models")})]}),(0,a.jsx)(se.ZI,{children:(0,a.jsx)("p",{children:l("Enable selected models")})})]}),(0,a.jsxs)(se.m_,{children:[(0,a.jsxs)(se.k$,{render:(0,a.jsx)(c.$,{variant:"outline",size:"icon",onClick:()=>{V(x,r,p)},className:"size-8","aria-label":l("Disable selected models"),title:l("Disable selected models")}),children:[(0,a.jsx)(d.$o3,{}),(0,a.jsx)("span",{className:"sr-only",children:l("Disable selected models")})]}),(0,a.jsx)(se.ZI,{children:(0,a.jsx)("p",{children:l("Disable selected models")})})]}),(0,a.jsxs)(se.m_,{children:[(0,a.jsxs)(se.k$,{render:(0,a.jsx)(c.$,{variant:"outline",size:"icon",onClick:g,className:"size-8","aria-label":l("Copy model names"),title:l("Copy model names")}),children:[(0,a.jsx)(d.QRo,{}),(0,a.jsx)("span",{className:"sr-only",children:l("Copy model names")})]}),(0,a.jsx)(se.ZI,{children:(0,a.jsx)("p",{children:l("Copy model names")})})]}),(0,a.jsxs)(se.m_,{children:[(0,a.jsxs)(se.k$,{render:(0,a.jsx)(c.$,{variant:"destructive",size:"icon",onClick:()=>m(!0),className:"size-8","aria-label":l("Delete selected models"),title:l("Delete selected models")}),children:[(0,a.jsx)(d.TBR,{}),(0,a.jsx)("span",{className:"sr-only",children:l("Delete selected models")})]}),(0,a.jsx)(se.ZI,{children:(0,a.jsx)("p",{children:l("Delete selected models")})})]})]}),(0,a.jsx)(Y.lG,{open:i,onOpenChange:m,children:(0,a.jsxs)(Y.Cf,{children:[(0,a.jsxs)(Y.c7,{children:[(0,a.jsx)(Y.L3,{children:l("Delete Models?")}),(0,a.jsx)(Y.rr,{children:l("Are you sure you want to delete {{count}} model(s)? This action cannot be undone.",{count:x.length})})]}),(0,a.jsxs)(Y.Es,{children:[(0,a.jsx)(c.$,{variant:"outline",onClick:()=>m(!1),children:l("Cancel")}),(0,a.jsx)(c.$,{variant:"destructive",onClick:()=>{D(x,r,()=>{m(!1),p()})},children:l("Delete")})]})]})})]})}var sl=l(38417),sa=l(38525);function st(e){let{row:s}=e,{t:l}=(0,o.Bd)(),r=s.original,{setOpen:i,setCurrentRow:m}=eR(),u=(0,n.jE)(),[x,h]=(0,t.useState)(!1),p=1===r.status;return(0,a.jsxs)(e8.rI,{children:[(0,a.jsxs)(e8.ty,{render:(0,a.jsx)(c.$,{variant:"ghost",className:"data-popup-open:bg-muted flex h-8 w-8 p-0"}),children:[(0,a.jsx)(d.a4,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:l("Open menu")})]}),(0,a.jsxs)(e8.SQ,{align:"end",className:"w-48",children:[(0,a.jsxs)(e8._2,{onClick:()=>{m(r),i("update-model")},children:[l("Edit"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.gHP,{size:16})})]}),(0,a.jsx)(e8.mB,{}),(0,a.jsx)(e8._2,{onClick:()=>{B(r.id,r.status,u)}
1,children:p?(0,a.jsxs)(a.Fragment,{children:[l("Disable"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.$o3,{size:16})})]}):(0,a.jsxs)(a.Fragment,{children:[l("Enable"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.aJd,{size:16})})]})}),(0,a.jsx)(e8.mB,{}),(0,a.jsxs)(e8._2,{onSelect:e=>{e.preventDefault(),h(!0)},className:"text-destructive focus:text-destructive",children:[l("Delete"),(0,a.jsx)(e8.V0,{children:(0,a.jsx)(d.TBR,{size:16})})]})]}),(0,a.jsx)(eV.T,{open:x,onOpenChange:h,title:l("Delete Model"),desc:`Are you sure you want to delete "${r.model_name}"? This action cannot be undone.`,confirmText:"Delete",destructive:!0,handleConfirm:()=>{q(r.id,u),h(!1)}})]})}function sn(e){let{modelName:s,description:l}=e,{setOpen:t,setDescriptionData:n}=eR();return l?(0,a.jsx)("div",{className:"max-w-[150px]",children:(0,a.jsx)(c.$,{variant:"link",onClick:()=>{n({modelName:s,description:l}),t("description")},className:"text-muted-foreground hover:text-foreground block h-auto w-full cursor-pointer overflow-hidden p-0 text-left text-sm text-ellipsis whitespace-nowrap no-underline",children:l})}):(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"})}function sr(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return(0,a.jsx)(P.M8,{items:e,max:s,renderItem:e=>e})}let si=(0,r.GY)("/_authenticated/models/$section");function so(){let{t:e}=(0,o.Bd)(),{selectedVendor:s}=eR(),l=(0,b.Ub)("(max-width: 640px)"),[n,r]=(0,t.useState)([]),[i,d]=(0,t.useState)({description:!1,bound_channels:!1,quota_types:!1}),[c,m]=(0,t.useState)({}),{globalFilter:u,onGlobalFilterChange:h,columnFilters:p,onColumnFiltersChange:g,pagination:j,onPaginationChange:N,ensurePageInRange:_}=(0,w.c)({search:si.useSearch(),navigate:si.useNavigate(),pagination:{defaultPage:1,defaultPageSize:l?10:20},globalFilter:{enabled:!0,key:"filter"}
1,columnFilters:[{columnId:"status",searchKey:"status",type:"array"},{columnId:"vendor_id",searchKey:"vendor",type:"array"},{columnId:"sync_official",searchKey:"sync",type:"array"}]}),S=p.find(e=>"status"===e.id)?.value||[],z=p.find(e=>"vendor_id"===e.id)?.value||[],M=p.find(e=>"sync_official"===e.id)?.value||[],{data:E}=(0,f.I)({queryKey:k.list(),queryFn:()=>(0,x.YQ)({page_size:1e3})}),$=(0,t.useMemo)(()=>E?.data?.items||[],[E?.data?.items]),A=(0,t.useMemo)(()=>$.map(e=>({label:e.name,value:String(e.id)})),[$]),O=!!u?.trim(),B=s||(z.length>0&&!z.includes("all")?z[0]:void 0),{data:q,isLoading:D,isFetching:J}=(0,f.I)({queryKey:R.list({keyword:u,vendor:B,status:S.length>0&&!S.includes("all")?S[0]:void 0,sync_official:M.length>0&&!M.includes("all")?M[0]:void 0,p:j.pageIndex+1,page_size:j.pageSize}),queryFn:async()=>O||B?(0,x.j6)({keyword:u,vendor:B,status:S.length>0&&!S.includes("all")?S[0]:void 0,sync_official:M.length>0&&!M.includes("all")?M[0]:void 0,p:j.pageIndex+1,page_size:j.pageSize}):(0,x.zr)({status:S.length>0&&!S.includes("all")?S[0]:void 0,sync_official:M.length>0&&!M.includes("all")?M[0]:void 0,p:j.pageIndex+1,page_size:j.pageSize}),placeholderData:e=>e}),V=q?.data?.items||[],L=q?.data?.total||0,Y=q?.data?.vendor_counts,G=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],{t:s}=(0,o.Bd)(),l={0:{label:s("Exact"),color:"green",description:s("Match model name exactly")},1:{label:s("Prefix"),color:"blue",description:s("Match models starting with this name")},2:{label:s("Contains"),color:"orange",description:s("Match models containing this name")},3:{label:s("Suffix"),color:"purple",description:s("Match models ending with this name")}},t={1:{label:s("Enabled"),variant:"success"},0:{label:s("Disabled"),variant:"neutral"}},n={0:{label:s("Usage-based"),color:"violet"},1:{label:s("Per-call"),color:"teal"}},r={};return e.forEach(e=>{r[e.id]=e}),[{id:"select",header:e=>{let{table:s}=e;return(0,a.jsx)(eG.S,{checked:s.getIsAllPageRowsSelected(),indeterminate:s.getIsSomePageRowsSelected(),onCheckedChange:e=>s.toggleAllPageRowsSelected(!!e),"aria-label":"Select all"})},cell:e=>{let{row:s}=e;return(0,a.jsx)(eG.S,{checked:s.getIsSelected(),onCheckedChange:e=>s.toggleSelected(!!e),"aria-label":"Select row"})},enableSorting:!1,enableHiding:!1,size:40},{accessorKey:"id",meta:{label:s("ID"),mobileHidden:!0},header:e=>{let{column:s}=e;return(0,a.jsx)(K.w,{column:s,title:"ID"})},cell:e=>{let{row:s}=e,l=s.getValue("id");return(0,a.jsx)(T.C,{value:l})},size:80},{accessorKey:"icon",meta:{label:s("Icon"),mobileHidden:!0},header:s("Icon"),cell:e=>{let{row:s}=e,l=s.original,t=l.icon||r[l.vendor_id||0]?.icon||l.model_name?.[0]||"N",n=(0,sl.Y)(t,20);return(0,a.jsx)("div",{className:"flex items-center justify-center",children:n})},size:70,enableSorting:!1},{accessorKey:"model_name",meta:{label:s("Model Name"),mobileTitle:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Model Name")})},cell:e=>{let{row:s}=e,l=s.getValue("model_name");return(0,a.jsx)(P.Wh,{label:l,variant:"neutral",copyText:l,size:"sm",className:"font-mono"})},minSize:200},{accessorKey:"name_rule",meta:{label:s("Match Type")},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Match Type")})},cell:e=>{let{row:s}=e,t=s.getValue("name_rule"),n=s.original,r=l[t],i=r.label;0!==t&&n.matched_count&&(i=`${r.label} (${n.matched_count})`);let o=(0,a.jsx)(P.Wh,{label:i,variant:"error"===r.color?"danger":r.color,size:"sm"});if(0!==t&&n.matched_models&&n.matched_models.length>0){let e=n.matched_models.map((e,s)=>(0,a.jsx)(P.Wh,{label:e,autoColor:e,size:"sm"},s));return(0,a.jsx)(se.Bc,{children:(0,a.jsxs)(se.m_,{children:[(0,a.jsx)(se.k$,{render:(0,a.jsx)("div",{}),children:o}),(0,a.jsx)(se.ZI,{side:"top",className:"border-border bg-popover max-h-48 max-w-[320px] overflow-y-auto p-2",children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:e})})]})})}return o},size:140,enableSorting:!1},{accessorKey:"status",meta:{label:s("Status"),mobileBadge:!0},header:s("Status"),cell:e=>{let{row:s}=e,l=t[s.getValue("status")]||t[0];return(0,a.jsx)(P.Wh,{label:l.label,variant:l.variant,size:"sm",copyable:!1})},filterFn:(e,s,l)=>{if(!l||0===l.length||l.includes("all"))return!0;let a=e.getValue(s);return l.includes("enabled")?1===a:!!l.includes("disabled")&&1!==a},size:120,enableSorting:!1},{accessorKey:"vendor_id",meta:{label:s("Vendor")},header:s("Vendor"),cell:e=>{let{row:s}=e,l=r[s.getValue("vendor_id")];if(!l)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let t=l.icon?(0,sl.Y)(l.icon,14):null;return(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[t,(0,a.jsx)(P.Wh,{label:l.name,autoColor:l.n
1ame,size:"sm"})]})},filterFn:(e,s,l)=>!!(!l||0===l.length||l.includes("all"))||l.includes(String(e.getValue(s))),size:150,enableSorting:!1},{accessorKey:"description",meta:{label:s("Description"),mobileHidden:!0},header:s("Description"),cell:e=>{let{row:s}=e,l=s.getValue("description"),t=s.getValue("model_name");return(0,a.jsx)(sn,{modelName:t,description:l})},size:150,enableSorting:!1},{accessorKey:"tags",meta:{label:s("Tags"),mobileHidden:!0},header:s("Tags"),cell:e=>{let{row:s}=e,l=F(s.getValue("tags"));if(0===l.length)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let t=l.map((e,s)=>(0,a.jsx)(P.Wh,{label:e,autoColor:e,size:"sm"},s));return(0,a.jsx)(se.Bc,{children:(0,a.jsxs)(se.m_,{children:[(0,a.jsx)(se.k$,{render:(0,a.jsx)("div",{}),children:sr(t,2)}),l.length>2&&(0,a.jsx)(se.ZI,{side:"top",className:"border-border bg-popover max-h-48 max-w-[320px] overflow-y-auto p-2",children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:t})})]})})},size:150,enableSorting:!1},{accessorKey:"endpoints",meta:{label:s("Endpoints"),mobileHidden:!0},header:s("Endpoints"),cell:e=>{let s,{row:l}=e,t=(s=function(e){if(!e||""===e.trim())return null;try{return JSON.parse(e)}catch{return null}}(l.getValue("endpoints")))?"object"!=typeof s||Array.isArray(s)?Array.isArray(s)?s.map(String):[]:Object.keys(s):[];if(0===t.length)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let n=t.map((e,s)=>(0,a.jsx)(P.Wh,{label:e,autoColor:e,size:"sm"},s));return(0,a.jsx)(se.Bc,{children:(0,a.jsxs)(se.m_,{children:[(0,a.jsx)(se.k$,{render:(0,a.jsx)("div",{}),children:sr(n,2)}),t.length>2&&(0,a.jsx)(se.ZI,{side:"top",className:"border-border bg-popover max-h-48 max-w-[320px] overflow-y-auto p-2",children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:n})})]})})},size:150,enableSorting:!1},{accessorKey:"bound_channels",meta:{label:s("Bound Channels"),mobileHidden:!0},header:s("Bound Channels"),cell:e=>{let{row:s}=e,l=s.getValue("bound_channels");if(!l||0===l.length)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let t=l.map((e,s)=>(0,a.jsx)(P.Wh,{label:`${e.name} (${e.type})`,autoColor:e.name,size:"sm"},s));return(0,a.jsx)(se.Bc,{children:(0,a.jsxs)(se.m_,{children:[(0,a.jsx)(se.k$,{render:(0,a.jsx)("div",{}),children:sr(t,2)}),l.length>2&&(0,a.jsx)(se.ZI,{side:"top",className:"border-border bg-popover max-h-48 max-w-[320px] overflow-y-auto p-2",children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:t})})]})})},size:150,enableSorting:!1},{accessorKey:"enable_groups",meta:{label:s("Enable Groups"),mobileHidden:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Enable Groups")})},cell:e=>{let{row:s}=e,l=s.getValue("enable_groups");if(!l||0===l.length)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let t=l.map(e=>(0,a.jsx)(sa.d,{group:e,size:"sm"},e));return(0,a.jsx)(se.Bc,{children:(0,a.jsxs)(se.m_,{children:[(0,a.jsx)(se.k$,{render:(0,a.jsx)("div",{}),children:sr(t,2)}),l.length>2&&(0,a.jsx)(se.ZI,{side:"top",className:"border-border bg-popover max-h-48 max-w-[320px] overflow-y-auto p-2",children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:t})})]})})},size:150,enableSorting:!1},{accessorKey:"quota_types",meta:{label:s("Quota Types"),mobileHidden:!0},header:s("Quota Types"),cell:e=>{let{row:s}=e,l=s.getValue("quota_types");if(!l||0===l.length)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let t=l.map((e,s)=>{let l=n[e];return(0,a.jsx)(P.Wh,{label:l?.label||String(e),variant:l?.color==="error"?"danger":l?.color,size:"sm"},s)});return(0,a.jsx)(se.Bc,{children:(0,a.jsxs)(se.m_,{children:[(0,a.jsx)(se.k$,{render:(0,a.jsx)("div",{}),children:sr(t,2)}),l.length>2&&(0,a.jsx)(se.ZI,{side:"top",className:"border-border bg-popover max-h-48 max-w-[320px] overflow-y-auto p-2",children:(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:t})})]})})},size:150,enableSorting:!1},{accessorKey:"sync_official",meta:{label:s("Official Sync"),mobileHidden:!0},header:s("Official Sync"),cell:e=>{let{row:l}=e,t=l.getValue("sync_official");return(0,a.jsx)(P.Wh,{label:1===t?s("Official Sync"):s("No Sync"),variant:1===t?"success":"warning",size:"sm",copyable:!1})},filterFn:(e,s,l)=>{if(!l||0===l.length||l.includes("all"))return!0;let a=e.getValue(s);return l.includes("yes")?1===a:!!l.includes("no")&&1!==a},size:120,enableSorting:!1},{accessorKey:"created_time",meta:{label:s("Created"),mobileHidden:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Created")})},cell:e=>{let{row:s}=e,l=s.getValue("created_time");return(0,a.jsx)("div",{className:"min-w-[140px] font-mono text-sm",children:(0,I.fk)(l)})},size:180},{accessorKey:"updated_time",meta:{label:s("Updated"),mobileHidden:!0},header:e=>{let{column:l}=e;return(0,a.jsx)(K.w,{column:l,title:s("Updated")})},cell:e=>{let{row:s}=e,l=s.getValue("updated_time");return(0,a.jsx)("div",{className:"min-w-[140px] font-mono text-sm",children:(0,I.fk)(l)})},size:180},{id:"actions",cell:e=>{let{row:s}=e;return(0,a.jsx)(st,{row:s})},size:100,enableSorting:!1,enableHiding:!1}]}($),U=(0,y.N4)({data:V,columns:G,pageCount:Math.ceil(L/j.pageSize),state:{sorting:n,columnFilters:p,columnVisibility:i,rowSelection:c,pagination:j,globalFilter:u},enableRowSelection:!0,onRowSelectionChange:m,onSortingChange:r,onColumnFiltersChange:g,onColumnVisibilityChange:d,onPaginationChange:N,onGlobalFilterChange:h,getCoreRowModel:(0,v.HT)(),manualPagination:!0,manualSorting:!0,manualFiltering:!0}),W=U.getPageCount();(0,t.useEffect)(()=>{_(W)},[W,_]);let H=[{label:`${e("All Vendors")}${Y?.all?` (${Y.all})`:""}`,value:"all"},...A.map(e=>({label:`${e.label}${Y?.[e.value]?` (${Y[e.value]})`:""}`,value:e.value}))];return(0,a.jsx)(C.cx,{table:U,columns:G,isLoading:D,isFetching:J,emptyTitle:e("No Models Found"),empty
1Description:e("No models available. Create your first model to get started."),skeletonKeyPrefix:"model-skeleton",applyHeaderSize:!0,toolbarProps:{searchPlaceholder:e("Filter by model name..."),filters:[{columnId:"status",title:e("Status"),options:[{label:e("All Status"),value:"all"},{label:e("Enabled"),value:"enabled"},{label:e("Disabled"),value:"disabled"}],singleSelect:!0},{columnId:"vendor_id",title:e("Vendor"),options:H,singleSelect:!0},{columnId:"sync_official",title:e("Official Sync"),options:[{label:e("All Sync Status"),value:"all"},{label:e("Official Sync"),value:"yes"},{label:e("No Sync"),value:"no"}],singleSelect:!0}]},bulkActions:(0,a.jsx)(ss,{table:U})})}let sd=null;function sc(e){sd={ok:e,timestamp:Date.now()}}var sm=l(27301);let su=(0,r.GY)("/_authenticated/models/$section"),sx={metadata:{titleKey:"Metadata"},deployments:{titleKey:"Deployments"}};function sh(){let{t:e}=(0,o.Bd)(),s=(0,i.Z)(),l=(0,n.jE)(),{tabCategory:r,setTabCategory:h}=eR(),p=su.useParams().section??sm.Fi,[g,f]=(0,t.useState)(!1);(0,t.useEffect)(()=>{r!==p&&h(p)},[p,h,r]);let{loading:y,loadingPhase:v,isIoNetEnabled:b,connectionLoading:N,connectionOk:w,connectionError:_,testConnection:C,refresh:S}=function(){let[e,s]=(0,t.useState)(!0),[l,a]=(0,t.useState)("settings"),[n,r]=(0,t.useState)({"model_deployment.ionet.enabled":!1}),[i,o]=(0,t.useState)({loading:!1,ok:null,error:null}),d=(0,t.useRef)(!0),c=(0,t.useCallback)(async function(){let e=!(arguments.length>0)||void 0===arguments[0]||arguments[0];s(!0),a("settings");try{let l=await (0,x.BY)(),t=l?.success&&l?.data?.enabled===!0;if(r({"model_deployment.ionet.enabled":t}),!t){o({loading:!1,ok:null,error:null}),a("done"),s(!1);return}if(e){let e=sd?Date.now()-sd.timestamp>3e5?(sd=null,null):sd.ok:null;if(null!==e){o({loading:!1,ok:e,error:null}),a("done"),s(!1);return}}a("connection"),o({loading:!0,ok:null,error:null});try{let e=await (0,x.ck)();if(e?.success)sc(!0),o({loading:!1,ok:!0,error:null});else{let s=e?.message||"Connection failed";sc(!1),o({loading:!1,ok:!1,error:s})}}catch(s){let e=s instanceof Error?s.message:"Connection failed";sc(!1),o({loading:!1,ok:!1,error:e})}}catch{o({loading:!1,ok:null,error:null})}finally{a("done"),s(!1)}},[]);(0,t.useEffect)(()=>{d.current&&(d.current=!1,c(!0))},[c]);let m=!!n["model_deployment.ionet.enabled"],u=(0,t.useCallback)(async()=>{sd=null,o({loading:!0,ok:null,error:null}),a("connection");try{let e=await (0,x.ck)();if(e?.success){sc(!0),o({loading:!1,ok:!0,error:null});return}let s=e?.message||"Connection failed";sc(!1),o({loading:!1,ok:!1,error:s})}catch(s){let e=s instanceof Error?s.message:"Connection failed";sc(!1),o({loading:!1,ok:!1,error:e})}finally{a("done")}},[]),h=(0,t.useCallback)(()=>(sd=null,c(!1)),[c]);return(0,t.useEffect)(()=>{let e=()=>{c(!0)};return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[c]),{loading:e,loadingPhase:l,settings:n,isIoNetEnabled:m,refresh:h,connectionLoading:i.loading,connectionOk:i.ok,connectionError:i.error,testConnection:u}}();(0,t.useEffect)(()=>{"deployments"===p&&S()},[p,S]),(0,t.useEffect)(()=>{if("deployments"===p&&b&&"connection"===v){let e={p:1,page_size:10};l.prefetchQuery({queryKey:M.list(e),queryFn:()=>(0,x.Jn)(e),staleTime:3e4})}},[p,b,v,l]);let R=(0,t.useCallback)(e=>{s({to:"/models/$section",params:{section:e}})},[s]),k=sx[p]??sx.metadata;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(u.Ni,{children:[(0,a.jsx)(u.Ni.Title,{children:e(k.titleKey)}),(0,a.jsx)(u.Ni.Actions,{children:"metadata"===p?(0,a.jsx)(e7,{}):(0,a.jsxs)(c.$,{onClick:()=>f(!0),size:"sm",children:[(0,a.jsx)(d.FWt,{className:"h-4 w-4"}),e("Create deployment")]})}),(0,a.jsx)(u.Ni.Content,{children:(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(m.tU,{value:p,onValueChange:R,children:(0,a.jsx)(m.j7,{className:"max-w-full flex-wrap justify-start group-data-horizontal/tabs:h-auto",children:sm.ev.map(s=>(0,a.jsx)(m.Xi,{value:s,children:e(sx[s].titleKey)},s))})}),"metadata"===p?(0,a.jsx)(so,{}):(0,a.jsx)(j,{loading:y,loadingPhase:v,isEnabled:b,connectionLoading:N,connectionOk:w,connectionError:_,onRetry:C,
1children:(0,a.jsx)(eu,{})})]})})]}),(0,a.jsx)(e6,{}),(0,a.jsx)(ev,{open:g,onOpenChange:f})]})}let sp=function(){return(0,a.jsx)(eS,{children:(0,a.jsx)(sh,{})})}}}]);
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.