1"use strict";(self.rspackChunknewapi_web=self.rspackChunknewapi_web||[]).push([[2172],{89806(e,t,s){s.d(t,{nc:()=>l,lW:()=>i,$e:()=>n,Rk:()=>o,pF:()=>r});var a=s(64577);async function r(){return(await a.FH.get("/api/user/passkey")).data}async function l(){return(await a.FH.post("/api/user/passkey/login/begin")).data}async function n(e){return(await a.FH.post("/api/user/passkey/login/finish",e)).data}async function i(){return(await a.FH.post("/api/user/passkey/verify/begin")).data}async function o(e){return(await a.FH.post("/api/user/passkey/verify/finish",e)).data}s(68413),s(19376),s(20598)},32094(e,t,s){s.d(t,{OP:()=>j,S$:()=>p,SO:()=>y,TK:()=>o,UL:()=>m,XD:()=>g,Xw:()=>u,ZC:()=>c,f:()=>x,hG:()=>d,kg:()=>i,lo:()=>r,tg:()=>h,wz:()=>n,x5:()=>l,zm:()=>f});var a=s(64577);async function r(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{p:t=1,page_size:s=10}=e;return(await a.FH.get(`/api/user/?p=${t}&page_size=${s}`)).data}async function l(e){let{keyword:t="",group:s="",role:r="",status:l="",p:n=1,page_size:i=10}=e,o=new URLSearchParams;return o.set("keyword",t),o.set("group",s),r&&o.set("role",r),l&&o.set("status",l),o.set("p",String(n)),o.set("page_size",String(i)),(await a.FH.get(`/api/user/search?${o.toString()}`)).data}async function n(e){return(await a.FH.get(`/api/user/${e}`)).data}async function i(e){return(await a.FH.post("/api/user/",e)).data}async function o(e){return(await a.FH.put("/api/user/",e)).data}async function d(e){return(await a.FH.delete(`/api/user/${e}/`)).data}async function c(e,t){return(await a.FH.post("/api/user/manage",{id:e,action:t})).data}async function u(e){return(await a.FH.post("/api/user/manage",e)).data}async function m(e,t){return(await a.FH.post("/api/user/tier",{user_id:e,tier:t})).data}async function h(e){return(await a.FH.delete(`/api/user/${e}/reset_passkey`)).data}async function p(e){return(await a.FH.delete(`/api/user/${e}/2fa`)).data}async function x(){return(await a.FH.get("/api/group/")).data}async function g(e){return(await a.FH.get(`/api/user/${e}/oauth/bindings`)).data}async function f(e,t){return(await a.FH.delete(`/api/user/${e}/bindings/${t}`)).data}async function j(e,t){return(await a.FH.delete(`/api/user/${e}/oauth/bindings/${t}`)).data}async function y(){return(await a.FH.get("/api/user/topup/overview")).data.data}},54369(e,t,s){function a(e){if(!e)return new ArrayBuffer(0);let t="=".repeat((4-e.length%4)%4),s=(e+t).replace(/-/g,"+").replace(/_/g,"/"),a=globalThis,r=("function"==typeof a.atob?a.atob.bind(a):e=>{if(void 0!==a.Buffer)return a.Buffer.from(e,"base64").toString("binary");throw Error("Base64 decoding is not supported in this environment")})(s),l=new ArrayBuffer(r.length),n=new Uint8Array(l);for(let e=0;e<r.length;e+=1)n[e]=r.charCodeAt(e);return l}function r(e){if(!e)return"";let t=globalThis,s=new Uint8Array(e),a="";for(let e=0;e<s.byteLength;e+=1)a+=String.fromCharCode(s[e]);return("function"==typeof t.btoa?t.btoa.bind(t):e=>{if(void 0!==t.Buffer)return t.Buffer.from(e,"binary").toString("base64");throw Error("Base64 encoding is not supported in this environment")})(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function l(e){let t=e?.publicKey??e?.PublicKey??e?.response??e?.Response;if(!t)throw Error("Unable to parse Passkey login options from response");let s={...t,challenge:a(t.challenge)};return Array.isArray(t.allowCredentials)&&(s.allowCredentials=t.allowCredentials.map(e=>({...e,id:a(e.id)}))),s}function n(e){if(!e)return null;let t=e.response;return{id:e.id,rawId:r(e.rawId),type:e.type,authenticatorAttachment:e.authenticatorAttachment,response:{authenticatorData:r(t.authenticatorData),clientDataJSON:r(t.clientDataJSON),signature:r(t.signature),userHandle:t.userHandle?r(t.userHandle):null},clientExtensionResults:e.getClientExtensionResults?.()??{}}}async function i(){if("u"<typeof window)return!1;let{PublicKeyCredential:e}=window;if(!e)return!1;if("function"==typeof e.isConditionalMediationAvailable)try{if(await e.isConditionalMediationAvailable())return!0}catch{}if("function"==typeof e.isUserVerifyingPlatformAuthenticatorAvailable)try{return await e.isUserVerifyingPlatformAuthenticatorAvailable()}catch{return!1}return!0}s.d(t,{Il:()=>n,TA:()=>i,ig:()=>l})}
1,56743(e,t,s){s.r(t),s.d(t,{component:()=>aL});var a=s(72361),r=s(6702),l=s(67267),n=s(68413),i=s(96962),o=s(20598),d=s(64577);function c(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return Array.from(new Set((e||[]).map(e=>String(e||"").trim()).filter(Boolean)))}function u(e){let t=null;if(e&&"object"==typeof e&&!Array.isArray(e))t=e;else if("string"==typeof e)try{t=JSON.parse(e)}catch{t=null}return t&&"object"==typeof t?{enabled:!0===t.upstream_model_update_check_enabled,pendingAddModels:c(t.upstream_model_update_last_detected_models||[]),pendingRemoveModels:c(t.upstream_model_update_last_removed_models||[])}:{enabled:!1,pendingAddModels:[],pendingRemoveModels:[]}}let m={skipBusinessError:!0,skipErrorHandler:!0};var h=s(19376),p=s(52946),x=s(32094);let g=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{...e,skipBusinessError:!0,skipErrorHandler:!0}};async function f(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(await d.FH.get("/api/channel",{params:e})).data}async function j(e){return(await d.FH.get("/api/channel/search",{params:e})).data}async function y(e){return(await d.FH.get(`/api/channel/${e}`)).data}async function v(e){return(await d.FH.post("/api/channel",e,g())).data}async function b(e,t){return(await d.FH.put("/api/channel/",{id:e,...t},g())).data}async function _(e){return(await d.FH.delete(`/api/channel/${e}`,g())).data}async function N(e){return(await d.FH.post("/api/channel/batch",e,g())).data}async function w(e){return(await d.FH.post("/api/channel/batch/tag",e,g())).data}async function k(e,t){return(await d.FH.get(`/api/channel/test/${e}`,g({params:t}))).data}async function C(e){return(await d.FH.get(`/api/channel/update_balance/${e}`,g())).data}async function S(e){return(await d.FH.get(`/api/channel/fetch_models/${e}`,g())).data}async function R(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(await d.FH.post(`/api/channel/copy/${e}`,null,g({params:t}))).data}async function A(){return(await d.FH.post("/api/channel/fix",void 0,g())).data}async function M(){return(await d.FH.delete("/api/channel/disabled",g())).data}async function O(e,t){return(await d.FH.post(`/api/channel/${e}/key`,t?{code:t}:void 0,g())).data}async function I(){return(await d.FH.post("/api/channel/codex/oauth/start",{},g())).data}async function F(e){return(await d.FH.post("/api/channel/codex/oauth/complete",{input:e},g())).data}async function z(e){return(await d.FH.post(`/api/channel/${e}/codex/refresh`,{},g())).data}async function E(e){return(await d.FH.get(`/api/channel/${e}/codex/usage`,g({disableDuplicate:!0}))).data}async function $(e){return(await d.FH.post("/api/channel/multi_key/manage",e,g())).data}async function T(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:50,a=arguments.length>3?arguments[3]:void 0;return $({channel_id:e,action:"get_key_status",page:t,page_size:s,status:a})}async function P(e,t){return $({channel_id:e,action:"enable_key",key_index:t})}async function B(e,t){return $({channel_id:e,action:"disable_key",key_index:t})}async function J(e,t){return $({channel_id:e,action:"delete_key",key_index:t})}async function D(e){return $({channel_id:e,action:"enable_all_keys"})}async function q(e){return $({channel_id:e,action:"disable_all_keys"})}async function V(e){return $({channel_id:e,action:"delete_disabled_keys"})}async function K(e){return(await d.FH.post("/api/channel/tag/enabled",{tag:e},g())).data}async function L(e){return(await d.FH.post("/api/channel/tag/disabled",{tag:e},g())).data}async function H(e){return(await d.FH.put("/api/channel/tag",e,g())).data}async function U(e){return(await d.FH.get("/api/channel/tag/models",{params:{tag:e}})).data}async function W(e){return(await d.FH.post("/api/channel/fetch_models",e,g())).data}async function Q(e){return(await d.FH.delete("/api/channel/ollama/delete",g({data:e}))).data}async function G(){return(await d.FH.get("/api/channel/test",g())).data}async function X(){return(await d.FH.get("/api/channel/update_balance",g())).data}async function Y(){return(await d.FH.get("/api/channel/models")).data}let Z=x.f;async function ee(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"model";return(await d.FH.get("/api/prefill_group",{params:{type:e}})).data}let et={0:"Unknown",1:"OpenAI",2:"Midjourney",3:"Azure",4:"Ollama",5:"MidjourneyPlus",6:"OpenAIMax",7:"OhMyGPT",8:"Custom",9:"AILS",10:"AI Proxy",11:"PaLM",12:"API2GPT",13:"AIGC2D",14:"Anthropic",15:"Baidu",16:"Zhipu",17:"Ali",18:"Xunfei",19:"360",20:"OpenRouter",21:"AI Proxy Library",22:"FastGPT",23:"Tencent",24:"Gemini",25:"Moonshot",26:"Zhipu V4",27:"Perplexity",31:"LingYiWanWu",33:"AWS",34:"Cohere",35:"MiniMax",36:"SunoAPI",37:"Dify",38:"Jina",39:"Cloudflare",40:"SiliconFlow",41:"Vertex AI",42:"Mistral",43:"DeepSeek",44:"MokaAI",45:"VolcEngine",46:"Baidu V2",47:"Xinference",48:"xAI",49:"Coze",50:"Kling",51:"Jimeng",52:"Vidu",53:"Submodel",54:"DoubaoVideo",55:"Sora",56:"Replicate",57:"Codex"},es=[1,14,33,24,43,3,41,48,42,34,20,4,40,27,25,17,26,15,46,23,18,45,31,35,49,19,47,37,38,39,11,8,57,22,21,44,2,5,36,50,51,52,53,54,55,56],ea=(()=>{let e=[],t=new Set;for(let s of es){let a=et[s];a&&(e.push({value:s,label:a}),t.add(s))}for(let[s,a]of Object.entries(et)){let r=Number(s);0===r||t.has(r)||e.push({value:r,label:a})}return e})(),er=[{value:"all",label:"All Status"},{value:"enabled",label:"Enabled"},{value:"disabled",label:"Disabled"}],el={0:{variant:"neutral",label:"Unknown"},1:{variant:"success",label:"Enabled"},2:{variant:"danger",label:"Disabled"},3:{variant:"warning",label:"Auto Disabled"}},en={1:{variant:"success",label:"Enabled"},2:{variant:"neutral",label:"Manual Disabled"},3:{variant:"danger",label:"Auto Disabled"}},ei=[{value:"single",label:"Single Key"},{value:"batch",label:"Batch Add (one key per line)"},{value:"multi_to_single",label:"Multi-Key Mode (multiple keys, one channel)"}],eo=[{value:"all",label:"All Status"},{value:"1",label:"Enabled"},{value:"2",label:"Manual Disabled"},{value:"3",label:"Auto Disabled"}],ed="Invalid JSON format",ec="Failed to create channel",eu="Failed to update channel",em="Failed to delete channel",eh="Failed to test channel",ep={variant:"success",label:"Excellent"},ex={variant:"info",label:"Good"},eg={variant:"warning",label:"Fair"},ef={variant:"danger",label:"Poor"},ej={variant:"neutral",label:"Not tested"},ey=new Set([1,4,14,17,20,23,24,25,26,27,31,34,35,40,42,43,47,48]),ev={15:"Format: APIKey|SecretKey",18:"Format: APPID|APISecret|APIKey",22:"Format: APIKey-AppId, e.g., fastgpt-0sp2gtvfdgyi4k30jwlgwf1i-64f335d84283f05518e9e041",23:"Format: AppId|SecretId|SecretKey",33:"Format: Ak|Sk|Region",50:"Format: AccessKey|SecretKey (or just ApiKey if upstream is New API)",51:"Format: Access Key ID|Secret Acce
1ss Key",57:"Paste Codex OAuth JSON credential (access_token / refresh_token / account_id)"},eb={3:'For channels added after May 10, 2025, no need to remove "." from model names during deployment',8:"If connecting to upstream One API or New API relay projects, use OpenAI type instead unless you know what you are doing",37:"Dify channels only support chatflow and agent, and agent does not support images"},e_={all:["channels"],lists:()=>[...e_.all,"list"],list:e=>[...e_.lists(),e],details:()=>[...e_.all,"detail"],detail:e=>[...e_.details(),e]};async function eN(e,t,s){try{let a=await b(e,{status:1});a.success?(o.oR.success(h.Ay.t("Channel enabled successfully")),t?.invalidateQueries({queryKey:e_.lists()}),s?.()):o.oR.error(a.message||h.Ay.t(eu))}catch(e){o.oR.error(h.Ay.t(eu))}}async function ew(e,t,s){try{let a=await b(e,{status:2});a.success?(o.oR.success(h.Ay.t("Channel disabled successfully")),t?.invalidateQueries({queryKey:e_.lists()}),s?.()):o.oR.error(a.message||h.Ay.t(eu))}catch(e){o.oR.error(h.Ay.t(eu))}}async function ek(e,t,s,a){1===t?await ew(e,s,a):await eN(e,s,a)}async function eC(e,t,s){try{let a=await _(e);a.success?(o.oR.success(h.Ay.t("Channel deleted successfully")),t?.invalidateQueries({queryKey:e_.lists()}),s?.()):o.oR.error(a.message||h.Ay.t(em))}catch(e){o.oR.error(h.Ay.t(em))}}async function eS(e,t,s,a,r){try{let l=await b(e,{[t]:s});if(l.success){let e=t.charAt(0).toUpperCase()+t.slice(1).toLowerCase();o.oR.success(h.Ay.t("{{field}} updated to {{value}}",{field:e,value:s})),a?.invalidateQueries({queryKey:e_.lists()}),r?.()}else o.oR.error(l.message||h.Ay.t(eu))}catch(e){o.oR.error(h.Ay.t(eu))}}async function eR(e,t,s,a,r){try{let l=await H({tag:e,[t]:s});if(l.success){let l=t.charAt(0).toUpperCase()+t.slice(1).toLowerCase();o.oR.success(h.Ay.t("{{field}} updated to {{value}} for tag: {{tag}}",{field:l,value:s,tag:e})),a?.invalidateQueries({queryKey:e_.lists()}),r?.()}else o.oR.error(l.message||h.Ay.t(eu))}catch(e){o.oR.error(h.Ay.t(eu))}}async function eA(e,t,s){let a=t&&(t.testModel||t.endpointType||t.stream)?{...t.testModel?{model:t.testModel}:{},...t.endpointType?{endpoint_type:t.endpointType}:{},...t.stream?{stream:!0}:{}}:void 0;try{let r=await k(e,a);r.success?(t?.silent||o.oR.success(h.Ay.t("Channel test completed")),s?.(!0,r.data?.response_time)):(t?.silent||o.oR.error(r.message||h.Ay.t(eh)),s?.(!1,void 0,r.message,r.error_code))}catch(a){let e=a?.response?.data?.message||h.Ay.t(eh);t?.silent||o.oR.error(e),s?.(!1,void 0,e)}}async function eM(e,t,s,a){try{let r=await R(e,t);r.success?(o.oR.success(h.Ay.t("Channel copied successfully")),s?.invalidateQueries({queryKey:e_.lists()}),a?.(r.data?.id??0)):o.oR.error(r.message||h.Ay.t("Failed to copy channel"))}catch(e){o.oR.error(h.Ay.t("Failed to copy channel"))}}async function eO(e,t,s){try{let a=await C(e);if(a.success&&void 0!==a.balance){let e=a.balance;o.oR.success(h.Ay.t("Balance updated: {{balance}}",{balance:(0,p.J5)(e,{digitsLarge:2,digitsSmall:4,abbreviate:!1})})),t?.invalidateQueries({queryKey:e_.lists()}),s?.(e)}else o.oR.error(a.message||h.Ay.t("Failed to update balance"))}catch(e){o.oR.error(e instanceof Error?e.message:h.Ay.t("Failed to update balance"))}}async function eI(e,t,s){if(0===e.length)return void o.oR.error(h.Ay.t("No channels selected"));try{let a=await N({ids:e});a.success?(o.oR.success(h.Ay.t("{{count}} channel(s) deleted",{count:a.data||e.length})),t?.invalidateQueries({queryKey:e_.lists()}),s?.(a.data||e.length)):o.oR.error(a.message||h.Ay.t(em))}catch(e){o.oR.error(h.Ay.t(em))}}async function eF(e,t,s){if(0===e.length)return void o.oR.error(h.Ay.t("No channels selected"));try{let a=e.map(e=>b(e,{status:1})),r=await Promise.allSettled(a),l=r.filter(e=>"fulfilled"===e.status&&e.value.success).length,n=r.length-l;l>0&&(o.oR.success(h.Ay.t("{{count}} channel(s) enabled",{count:l})),t?.invalidateQueries({queryKey:e_.lists()}),s?.()),n>0&&o.oR.error(h.Ay.t("{{count}} channel(s) failed to enable",{count:n}))}catch(e){o.oR.error(h.Ay.t("Failed to enable channels"))}}async function ez(e,t,s){if(0===e.length)return void o.oR.error(h.Ay.t("No channels selected"));try{let a=e.map(e=>b(e,{status:2})),r=await Promise.allSettled(a),l=r.filter(e=>"fulfilled"===e.status&&e.value.success).length,n=r.length-l;l>0&&(o.oR.success(h.Ay.t("{{count}} channel(s) disabled",{count:l}
1)),t?.invalidateQueries({queryKey:e_.lists()}),s?.()),n>0&&o.oR.error(h.Ay.t("{{count}} channel(s) failed to disable",{count:n}))}catch(e){o.oR.error(h.Ay.t("Failed to disable channels"))}}async function eE(e,t,s,a){if(0===e.length)return void o.oR.error(h.Ay.t("No channels selected"));try{let r=await w({ids:e,tag:t});r.success?(o.oR.success(h.Ay.t("Tag set successfully")),s?.invalidateQueries({queryKey:e_.lists()}),a?.()):o.oR.error(r.message||h.Ay.t("Failed to set tag"))}catch(e){o.oR.error(h.Ay.t("Failed to set tag"))}}async function e$(e,t,s){try{let a=await K(e);a.success?(o.oR.success(h.Ay.t("Enabled all channels with tag: {{tag}}",{tag:e})),t?.invalidateQueries({queryKey:e_.lists()}),s?.()):o.oR.error(a.message||h.Ay.t("Failed to enable tag channels"))}catch(e){o.oR.error(h.Ay.t("Failed to enable tag channels"))}}async function eT(e,t,s){try{let a=await L(e);a.success?(o.oR.success(h.Ay.t("Disabled all channels with tag: {{tag}}",{tag:e})),t?.invalidateQueries({queryKey:e_.lists()}),s?.()):o.oR.error(a.message||h.Ay.t("Failed to disable tag channels"))}catch(e){o.oR.error(h.Ay.t("Failed to disable tag channels"))}}async function eP(e,t){try{let s=await M();s.success?(o.oR.success(h.Ay.t("{{count}} disabled channel(s) deleted",{count:s.data||0})),e?.invalidateQueries({queryKey:e_.lists()}),t?.(s.data||0)):o.oR.error(s.message||h.Ay.t("Failed to delete disabled channels"))}catch(e){o.oR.error(h.Ay.t("Failed to delete disabled channels"))}}async function eB(e,t){try{let s=await A();s.success&&s.data?(o.oR.success(h.Ay.t("Fixed abilities: {{success}} succeeded, {{fails}} failed",{success:s.data.success,fails:s.data.fails})),e?.invalidateQueries({queryKey:e_.lists()}),t?.(s.data)):o.oR.error(s.message||h.Ay.t("Failed to fix abilities"))}catch(e){o.oR.error(h.Ay.t("Failed to fix abilities"))}}async function eJ(e,t){try{let s=await G();s.success?(o.oR.success(h.Ay.t("Testing all enabled channels started. Please refresh to see results.")),e?.invalidateQueries({queryKey:e_.lists()}),t?.()):o.oR.error(s.message||h.Ay.t("Failed to start testing all channels"))}catch(e){o.oR.error(h.Ay.t("Failed to test all channels"))}}async function eD(e,t){try{let s=await X();s.success?(o.oR.success(h.Ay.t("Updating all channel balances. This may take a while. Please refresh to see results.")),e?.invalidateQueries({queryKey:e_.lists()}),t?.()):o.oR.error(s.message||h.Ay.t("Failed to update all balances"))}catch(e){o.oR.error(h.Ay.t("Failed to update all balances"))}}var eq=s(41128),eV=s(25732);function eK(e){if(e?.trim())return JSON.parse(e)}function eL(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function eH(e){try{let t=eK(e);return void 0===t||eL(t)}catch{return!1}}function eU(e,t,s){e.addIssue({code:eq.eq.custom,path:[t],message:s})}let eW=eV.Ik({name:eV.Yj().min(1,"Channel name is required"),type:eV.ai().min(0,"Channel type is required"),base_url:eV.Yj().optional(),key:eV.Yj(),openai_organization:eV.Yj().optional(),models:eV.Yj().min(1,"Models are required"),group:eV.YO(eV.Yj()).min(1,"Group is required"),model_mapping:eV.Yj().optional().refine(function(e){try{let t=eK(e);if(void 0===t)return!0;if(!eL(t))return!1;return Object.values(t).every(e=>"string"==typeof e)}catch{return!1}},"Model mapping must be a JSON object with string values"),priority:eV.ai().optional(),weight:eV.ai().optional(),test_model:eV.Yj().optional(),auto_ban:eV.ai().optional(),status:eV.ai(),status_code_mapping:eV.Yj().optional().refine(function(e){try{let t=eK(e);if(void 0===t)return!0;if(!eL(t))return!1;return Object.entries(t).every(e=>{let[t,s]=e,a=Number(t),r=Number(s);return Number.isInteger(a)&&Number.isInteger(r)&&a>=100&&a<=599&&r>=100&&r<=599})}catch{return!1}},"Status code mapping must use valid HTTP status codes"),tag:eV.Yj().optional(),remark:eV.Yj().max(255,"Remark must be less than 255 characters").optional(),setting:eV.Yj().optional().refine(eH,ed),param_override:eV.Yj().optional().refine(eH,ed),header_override:eV.Yj().optional().refine(eH,ed),settings:eV.Yj().optional().refine(eH,ed),other:eV.Yj().optional(),multi_key_mode:eV.k5(["single","batch","multi_to_single"]).optional(),multi_key_type:eV.k5(["random","polling"]).optional(),batch_add_set_key_prefix_2_name:eV.zM().optional(),key_mode:eV.k5(["append","replace"]).optional(),force_format:eV.zM().optional(),thinking_to_content:eV.zM().optional(),proxy:eV.Yj().optional(),pass_through_body_enabled:eV.zM().optional(),system_prompt:eV.Yj().optional(),system_prompt_override:eV.zM().optional(),is_enterprise_account:eV.zM().optional(),vertex_key_type:eV.k5(["json","api_key"]).optional(),aws_key_type:eV.k5(["ak_sk","api_key"]).optional(),azure_responses_version:eV.Yj().optional(),allow_service_tier:eV.zM().optional(),disable_store:eV.zM().optional(),allow_safety_identifier:eV.zM().optional(),allow_include_obfuscation:eV.zM().optional(),allow_inference_geo:eV.zM().optional(),allow_speed:eV.zM().optional(),claude_beta_query:eV.zM().optional(),upstream_model_update_check_enabled:eV.zM().optional(),upstream_model_update_auto_
1sync_enabled:eV.zM().optional(),upstream_model_update_ignored_models:eV.Yj().optional()}).superRefine((e,t)=>{[3,8,36,45].includes(e.type)&&!e.base_url?.trim()&&eU(t,"base_url","Base URL is required for this channel type"),[3,18,21,39,41,49].includes(e.type)&&!e.other?.trim()&&eU(t,"other","This channel type requires additional configuration"),57===e.type&&(e.multi_key_mode&&"single"!==e.multi_key_mode&&eU(t,"multi_key_mode","Codex channels do not support batch creation"),e.key?.trim()&&!function(e){try{let t=eK(e);if(void 0===t)return!0;return eL(t)&&"string"==typeof t.access_token&&t.access_token.trim().length>0&&"string"==typeof t.account_id&&t.account_id.trim().length>0}catch{return!1}}(e.key)&&eU(t,"key","Codex credential must be a JSON object with access_token and account_id")),41===e.type&&"json"===e.vertex_key_type&&e.key?.trim()&&!function(e){try{let t=eK(e);if(void 0===t)return!0;if(Array.isArray(t))return t.every(e=>eL(e));return eL(t)}catch{return!1}}(e.key)&&eU(t,"key","Vertex AI service account key must be valid JSON"),41===e.type&&"api_key"===e.vertex_key_type&&e.multi_key_mode&&"single"!==e.multi_key_mode&&eU(t,"multi_key_mode","Vertex AI API Key mode does not support batch creation")}),eQ={name:"",type:1,base_url:"",key:"",openai_organization:"",models:"",group:["default"],model_mapping:"",priority:0,weight:0,test_model:"",auto_ban:1,status:1,status_code_mapping:"",tag:"",remark:"",setting:"",param_override:"",header_override:"",settings:"{}",other:"",multi_key_mode:"single",multi_key_type:"random",batch_add_set_key_prefix_2_name:!1,key_mode:"append",force_format:!1,thinking_to_content:!1,proxy:"",pass_through_body_enabled:!1,system_prompt:"",system_prompt_override:!1,is_enterprise_account:!1,vertex_key_type:"json",aws_key_type:"ak_sk",azure_responses_version:"",allow_service_tier:!1,disable_store:!1,allow_safety_identifier:!1,allow_include_obfuscation:!1,allow_inference_geo:!1,allow_speed:!1,claude_beta_query:!1,upstream_model_update_check_enabled:!1,upstream_model_update_auto_sync_enabled:!1,upstream_model_update_ignored_models:""};function eG(e){return JSON.stringify({force_format:e.force_format||!1,thinking_to_content:e.thinking_to_content||!1,proxy:e.proxy||"",pass_through_body_enabled:e.pass_through_body_enabled||!1,system_prompt:e.system_prompt||"",system_prompt_override:e.system_prompt_override||!1})}function eX(e){let t={};if(e.settings&&"{}"!==e.settings)try{t=JSON.parse(e.settings)}catch(e){console.error("Failed to parse existing settings:",e)}return 41===e.type?t.vertex_key_type=e.vertex_key_type||"json":"vertex_key_type"in t&&delete t.vertex_key_type,3===e.type&&e.azure_responses_version?t.azure_responses_version=e.azure_responses_version:"azure_responses_version"in t&&delete t.azure_responses_version,20===e.type?t.openrouter_enterprise=!0===e.is_enterprise_account:"openrouter_enterprise"in t&&delete t.openrouter_enterprise,33===e.type?t.aws_key_type=e.aws_key_type||"ak_sk":"aws_key_type"in t&&delete t.aws_key_type,1===e.type||14===e.type?t.allow_service_tier=!0===e.allow_service_tier:"allow_service_tier"in t&&delete t.allow_service_tier,1===e.type?(t.disable_store=!0===e.disable_store,t.allow_safety_identifier=!0===e.allow_safety_identifier,t.allow_include_obfuscation=!0===e.allow_include_obfuscation,t.allow_inference_geo=!0===e.allow_inference_geo):("disable_store"in t&&delete t.disable_store,"allow_safety_identifier"in t&&delete t.allow_safety_identifier,"allow_include_obfuscation"in t&&delete t.allow_include_obfuscation,14!==e.type&&"allow_inference_geo"in t&&delete t.allow_inference_geo),14===e.type?(t.allow_inference_geo=!0===e.allow_inference_geo,t.allow_speed=!0===e.allow_speed,t.claude_beta_query=!0===e.claude_beta_query):("allow_speed"in t&&delete t.allow_speed,"claude_beta_query"in t&&delete t.claude_beta_query),ey.has(e.type)&&(t.upstream_model_update_check_enabled=!0===e.upstream_model_update_check_enabled,t.upstream_model_update_auto_sync_enabled=!0===t.upstream_model_update_check_enabled&&!0===e.upstream_model_update_auto_sync_enabled,t.upstream_model_update_ignored_models=Array.from(new Set(String(e.upstream_model_update_ignored_models||"").split(",").map(e=>
1e.trim()).filter(Boolean))),Array.isArray(t.upstream_model_update_last_detected_models)&&!0===t.upstream_model_update_check_enabled||(t.upstream_model_update_last_detected_models=[]),"number"!=typeof t.upstream_model_update_last_check_time&&(t.upstream_model_update_last_check_time=0)),JSON.stringify(t)}function eY(e){return String(e||"").trim().replace(/\/+$/,"")}et["1"],et["3"],et["14"],et["24"],et["41"],et["43"],et["20"],et["56"];var eZ=s(37936),e0=s(3642);function e1(e){return et[e]||"Unknown"}function e2(e){return({1:"OpenAI",6:"OpenAI",7:"OpenAI",8:"OpenAI",3:"Azure",14:"Claude",24:"Gemini",11:"Google",41:"Gemini",33:"Aws",39:"Cloudflare",15:"Baidu",46:"Baidu",16:"Zhipu",26:"Zhipu",17:"Qwen",18:"Spark",23:"Hunyuan",19:"Ai360",25:"Moonshot",31:"Yi",35:"Minimax",45:"Volcengine",4:"Ollama",27:"Perplexity",34:"Cohere",42:"Mistral",43:"DeepSeek",48:"XAI",49:"Coze",40:"SiliconCloud",44:"OpenAI",20:"OpenRouter",2:"Midjourney",5:"Midjourney",50:"Kling",51:"Jimeng",52:"Vidu",36:"Suno",55:"OpenAI",54:"Doubao",56:"Replicate",37:"Dify",38:"Jina",22:"FastGPT",47:"Xinference",53:"OpenAI",10:"OpenAI",21:"OpenAI",12:"OpenAI",13:"OpenAI",9:"OpenAI"})[e]||"OpenAI"}function e4(e){return e.channel_info?.is_multi_key||!1}function e3(e){return e?e.split(",").map(e=>e.trim()).filter(e=>e.length>0).sort((e,t)=>"default"===e?-1:"default"===t?1:e.localeCompare(t)):[]}function e5(e,t){return 0===e?t?t("Not tested"):"Not tested":e<1e3?t?t("{{value}}ms",{value:e}):`${e}ms`:t?t("{{value}}s",{value:(e/1e3).toFixed(2)}):`${(e/1e3).toFixed(2)}s`}function e6(e){return Array.isArray(e.children)}function e8(e){return e?e.split(",").map(e=>e.trim()).filter(Boolean):[]}function e7(e){return Array.from(new Set(e)).join(",")}function e9(e){return"string"==typeof e?e.trim():""}let te=(0,n.createContext)(void 0);function tt(e){let{children:t}
1=e,[s,l]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),[p,x]=(0,n.useState)(null),[g,f]=(0,n.useState)(()=>"true"===localStorage.getItem("enable-tag-mode")),[j,y]=(0,n.useState)(()=>"true"===localStorage.getItem("channels-id-sort")),v=(0,i.jE)(),b=function(e){let{t}=(0,r.Bd)(),[s,a]=(0,n.useState)(!1),[l,i]=(0,n.useState)(null),[u,h]=(0,n.useState)([]),[p,x]=(0,n.useState)([]),[g,f]=(0,n.useState)("add"),[j,y]=(0,n.useState)(!1),[v,b]=(0,n.useState)(!1),[_,N]=(0,n.useState)(!1),w=(0,n.useRef)(!1),k=(0,n.useRef)(!1),C=(0,n.useRef)(!1),S=(0,n.useRef)(!1),R=(0,n.useCallback)(function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"add",n=c(s),d=c(r);e?.id&&(0!==n.length||0!==d.length)?(i(e),h(n),x(d),f(l),a(!0)):o.oR.info(t("No processable upstream model updates for this channel"))},[t]),A=(0,n.useCallback)(()=>{a(!1),i(null),h([]),x([]),f("add")},[]),M=(0,n.useCallback)(async function(){let{addModels:s=[],removeModels:a=[]}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!w.current){if(!l?.id)return void A();w.current=!0,y(!0);try{let r=c(s),n=new Set(r),i=u.filter(e=>!n.has(e)),{success:h,message:p,data:x}=(await d.FH.post("/api/channel/upstream_updates/apply",{id:l.id,add_models:r,ignore_models:i,remove_models:c(a)},m)).data||{};if(!h)return void o.oR.error(p||t("Operation failed"));o.oR.success(t("Upstream model updates applied: {{added}} added, {{removed}} removed, {{ignored}} ignored this time, {{totalIgnored}} total ignored models",{added:x?.added_models?.length||0,removed:x?.removed_models?.length||0,ignored:c(i).length,totalIgnored:function(e){let t=null;if(e&&"object"==typeof e)t=e;else if("string"==typeof e)try{t=JSON.parse(e)}catch{t=null}return t?c(t.upstream_model_update_ignored_models||[]).length:0}(x?.settings)})),A(),await e()}catch(e){o.oR.error(e?.response?.data?.message||e?.message||t("Operation failed"))}finally{w.current=!1,y(!1)}}},[l,u,A,e,t]),O=(0,n.useCallback)(async()=>{if(!S.current){S.current=!0,N(!0);try{let{success:s,message:a,data:r}=(await d.FH.post("/api/channel/upstream_updates/apply_all",{},m)).data||{};if(!s)return void o.oR.error(a||t("Batch processing failed"));o.oR.success(t("Batch upstream model updates applied: {{channels}} channels, {{added}} added, {{removed}} removed, {{fails}} failed",{channels:r?.processed_channels||0,added:r?.added_models||0,removed:r?.removed_models||0,fails:(r?.failed_channel_ids||[]).length})),await e()}catch(e){o.oR.error(e?.response?.data?.message||e?.message||t("Batch processing failed"))}finally{S.current=!1,N(!1)}}},[e,t]),I=(0,n.useCallback)(async s=>{if(!k.current&&s?.id){k.current=!0;try{let{success:a,message:r,data:l}=(await d.FH.post("/api/channel/upstream_updates/detect",{id:s.id},m)).data||{};if(!a)return void o.oR.error(r||t("Detection failed"));o.oR.success(t("Detection complete: {{add}} to add, {{remove}} to remove",{add:l?.add_models?.length||0,remove:l?.remove_models?.length||0})),await e()}catch(e){o.oR.error(e?.response?.data?.message||e?.message||t("Detection failed"))}finally{k.current=!1}}},[e,t]),F=(0,n.useCallback)(async()=>{if(!C.current){C.current=!0,b(!0);try{let{success:s,message:a,data:r}=(await d.FH.post("/api/channel/upstream_updates/detect_all",{},m)).data||{};if(!s)return void o.oR.error(a||t("Batch detection failed"));o.oR.success(t("Batch detection complete: {{channels}} channels, {{add}} to add, {{remove}} to remove, {{fails}} failed",{channels:r?.processed_channels||0,add:r?.detected_add_models||0,remove:r?.detected_remove_models||0,fails:(r?.failed_channel_ids||[]).length})),await e()}catch(e){o.oR.error(e?.response?.data?.message||e?.message||t("Batch detection failed"))}finally{C.current=!1,b(!1)}}},[e,t]);return{showModal:s,channel:l,addModels:u,removeModels:p,preferredTab:g,applyLoading:j,detectAllLoading:v,applyAllLoading:_,openModal:R,closeModal:A,applyUpdates:M,applyAllUpdates:O,detectChannelUpdates:I,detectAllUpdates:F}}((0,n.useCallback)(async()=>
1{await v.invalidateQueries({queryKey:e_.all})},[v]));return(0,a.jsx)(te.Provider,{value:{open:s,setOpen:l,currentRow:u,setCurrentRow:h,currentTag:p,setCurrentTag:x,enableTagMode:g,setEnableTagMode:f,idSort:j,setIdSort:y,upstream:b},children:t})}function ts(){let e=(0,n.useContext)(te);if(!e)throw Error("useChannels must be used within ChannelsProvider");return e}var ta=s(61631),tr=s(46775),tl=s(1755),tn=s(52606),ti=s(59958),to=s(3676),td=s(3088);function tc(e,t){let s=Number(e);if(!Number.isFinite(s)||s<=0)return"-";let a=Math.floor(s),r=Math.floor(a/3600),l=Math.floor(a%3600/60),n=a%60;return r>0?`${r}${t("h")} ${l}${t("m")}`:l>0?`${l}${t("m")} ${n}${t("s")}`:`${n}${t("s")}`}function tu(e){return null==e?"":String(e).trim().toLowerCase()}let tm={enterprise:{label:"Enterprise",variant:"success"},team:{label:"Team",variant:"info"},pro:{label:"Pro",variant:"blue"},plus:{label:"Plus",variant:"purple"},free:{label:"Free",variant:"warning"}};function th(e){var t;let s,l,{t:n}=(0,r.Bd)(),i=!!e.window&&"object"==typeof e.window&&Object.keys(e.window).length>0,{percent:o,variant:d}=(t=e.window,{percent:l=Number.isFinite(s=Number(t?.used_percent))?Math.max(0,Math.min(100,s)):0,variant:l>=95?"danger":l>=80?"warning":"info"});return(0,a.jsxs)("div",{className:"rounded-lg border p-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("div",{className:"text-sm font-medium",children:e.title}),(0,a.jsx)(td.Wh,{label:`${o}%`,variant:d,copyable:!1})]}),(0,a.jsx)("div",{className:"mt-3",children:(0,a.jsx)(ti.ke,{value:o,"aria-label":`${e.title} usage: ${o}%`})}),i?(0,a.jsxs)("div",{className:"text-muted-foreground mt-2 space-y-1 text-xs",children:[(0,a.jsxs)("div",{children:[n("Reset at:")," ",function(e){let t=Number(e);if(!Number.isFinite(t)||t<=0)return"-";try{return(0,eZ.A)(1e3*t).format("YYYY-MM-DD HH:mm:ss")}catch{return String(e)}}(e.window?.reset_at)]}),(0,a.jsxs)("div",{children:[n("Resets in:")," ",tc(e.window?.reset_after_seconds,n)]}),(0,a.jsxs)("div",{children:[n("Window:")," ",tc(e.window?.limit_window_seconds,n)]})]}):(0,a.jsx)("div",{className:"text-muted-foreground mt-2 text-xs",children:"-"})]})}function tp(e){let{t}=(0,r.Bd)(),{fiveHourWindow:s,weeklyWindow:l}=function(e){let t=e?.rate_limit??{},s=t?.primary_window??null,a=t?.secondary_window??null,r=[s,a].filter(Boolean),l=tu(e?.plan_type??t?.plan_type),n=null,i=null;for(let e of r){let t=function(e){let t=Number(e?.limit_window_seconds);return!Number.isFinite(t)||t<=0?null:t>=86400?"weekly":"fiveHour"}(e);if("fiveHour"===t&&!n){n=e;continue}"weekly"!==t||i||(i=e)}return"free"===l?(i||(i=s??a??null),{fiveHourWindow:null,weeklyWindow:i}):n||i?(n||(n=r.find(e=>e!==i)??null),i||(i=r.find(e=>e!==n)??null),{fiveHourWindow:n,weeklyWindow:i}):{fiveHourWindow:s,weeklyWindow:a}}(e.source);return(0,a.jsxs)("section",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"text-sm font-semibold",children:e.title}),(e.description||e.meteredFeature)&&(0,a.jsxs)("div",{className:"text-muted-foreground flex flex-wrap items-center gap-2 text-xs",children:[e.description&&(0,a.jsx)("span",{children:e.description}),e.meteredFeature&&(0,a.jsxs)("span",{className:"bg-muted/60 inline-flex max-w-full items-center gap-2 rounded-md px-2 py-0.5",children:[(0,a.jsx)("span",{className:"text-[11px]",children:"metered_feature"}),(0,a.jsx)("span",{className:"min-w-0 font-mono text-xs break-all",children:e.meteredFeature})]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[(0,a.jsx)(th,{title:t("5-Hour Window"),window:s}),(0,a.jsx)(th,{title:t("Weekly Window"),window:l})]})]})}function tx(e){let{copyToClipboard:t,copiedText:s}=(0,tn.C)({notify:!1}),r=e.value?.trim()||"",l=s===r;return(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2 py-1",children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,a.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:e.icon}),(0,a.jsx)("span",{className:"text-muted-foreground flex-shrink-0 text-xs",children:e.label}),(0,a.jsx)("span",{className:`min-w-0 truncate text-xs ${e.mono?"font-mono":""}`,children:r||"-"})]}),r&&(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>t(r),children:l?(0,a.jsx)(ta.Jlk,{className:"h-3 w-3 text-green-600"}):(0,a.jsx)(ta.QRo,{className:"h-3 w-3"})})]})}function tg(e){var t;let{open:s,onOpenChange:l,channelName:i,channelId:o,response:d,onRefresh:c,isRefreshing:u}=e,{t:m}=(0,r.Bd)(),{copiedText:h,copyToClipboard:p}=(0,tn.C)({notify:!1}
1),[x,g]=(0,n.useState)(!1),f=(0,n.useMemo)(()=>{let e=d?.data;return e&&"object"==typeof e?e:null},[d?.data]),j=f?.rate_limit,y=(t=f?.plan_type??j?.plan_type,tm[tu(t)]??{label:String(t||"")||m("Unknown"),variant:"neutral"}),v=(f?.additional_rate_limits??[]).filter(e=>e&&Object.keys(e).length>0),b=j&&0!==Object.keys(j).length?j.allowed&&!j.limit_reached?(0,a.jsx)(td.Wh,{label:m("Available"),variant:"success",copyable:!1}):(0,a.jsx)(td.Wh,{label:m("Limited"),variant:"danger",copyable:!1}):(0,a.jsx)(td.Wh,{label:m("Pending"),variant:"neutral",copyable:!1}),_=d?.success===!1?d?.message?.trim()||m("Failed to fetch usage"):"",N=(0,n.useMemo)(()=>{if(!d)return"";try{return JSON.stringify({success:d.success,message:d.message,upstream_status:d.upstream_status,data:d.data},null,2)}catch{return String(d?.data??"")}},[d]);return(0,a.jsx)(tl.lG,{open:s,onOpenChange:l,children:(0,a.jsxs)(tl.Cf,{className:"sm:max-w-3xl",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{className:"flex items-center gap-2",children:m("Codex Account & Usage")}),(0,a.jsxs)(tl.rr,{children:[m("Channel:")," ",(0,a.jsx)("strong",{children:i||"-"})," ",o?`(#${o})`:""]})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[_&&(0,a.jsx)("div",{className:"rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-800 dark:bg-red-950/30 dark:text-red-400",children:_}),(0,a.jsxs)("div",{className:"rounded-lg border p-4",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)(td.Wh,{label:y.label,variant:y.variant,copyable:!1}),b,"number"==typeof d?.upstream_status&&(0,a.jsx)(td.Wh,{label:`${m("Status:")} ${d.upstream_status}`,variant:"neutral",copyable:!1})]}),c&&(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:c,disabled:!!u,children:[(0,a.jsx)(ta.e9t,{className:"mr-1.5 h-3.5 w-3.5"}),m("Refresh")]})]}),(0,a.jsxs)("div",{className:"bg-muted/30 mt-3 rounded-md px-3 py-2",children:[(0,a.jsx)(tx,{icon:(0,a.jsx)(ta.KJW,{className:"h-3.5 w-3.5"}),label:"User ID",value:f?.user_id,mono:!0}),(0,a.jsx)(tx,{icon:(0,a.jsx)(ta.gE4,{className:"h-3.5 w-3.5"}),label:m("Email"),value:f?.email}),(0,a.jsx)(tx,{icon:(0,a.jsx)(ta.VwU,{className:"h-3.5 w-3.5"}),label:"Account ID",value:f?.account_id,mono:!0})]})]}),(0,a.jsxs)("div",{className:"space-y-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"mb-1 text-sm font-medium",children:m("Rate Limit Windows")}),(0,a.jsx)("p",{className:"text-muted-foreground mb-3 text-xs",children:m("Tracks current account base limits and additional metered usage on Codex upstream.")}),(0,a.jsx)(tp,{title:m("Base Limits"),description:m("Base rate limit windows for this account."),source:f})]}),v.length>0&&(0,a.jsxs)("div",{className:"space-y-4 border-t pt-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-sm font-medium",children:m("Additional Limits")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:m("Per-feature metered windows split by model or capability.")})]}),(0,a.jsx)("div",{className:"space-y-4",children:v.map((e,t)=>{let s=e.limit_name||e.metered_feature||`${m("Additional Limit")} ${t+1}`;return(0,a.jsx)("div",{className:t>0?"border-t pt-4":"",children:(0,a.jsx)(tp,{title:s,description:m("Additional metered capability"),source:e,meteredFeature:e.metered_feature})},`${s}-${e.metered_feature??""}-${t}`)})})]})]}),(0,a.jsxs)("div",{className:"rounded-lg border",children:[(0,a.jsxs)("button",{type:"button",className:"hover:bg-muted/40 flex w-full items-center justify-between gap-2 p-3 transition-colors",onClick:()=>g(e=>!e),children:[(0,a.jsx)("div",{className:"text-sm font-medium",children:m("Raw JSON")}),x?(0,a.jsx)(ta.rXn,{className:"text-muted-foreground h-4 w-4"}):(0,a.jsx)(ta.yQN,{className:"text-muted-foreground h-4 w-4"})]}),x&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex justify-end border-t px-3 py-2",children:(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>p(N),disabled:!N,children:[h===N?(0,a.jsx)(ta.Jlk,{className:"mr-1.5 h-3.5 w-3.5 text-green-600"}):(0,a.jsx)(ta.QRo,{className:"mr-1.5 h-3.5 w-3.5"}),m("Copy")]})}),(0,a.jsx)(to.F,{className:"max-h-[50vh]",children:(0,a.jsx)("pre",{className:"bg-muted/30 m-0 p-3 text-xs break-words whitespace-pre-wrap",children:N||"-"})})]})]})]}),(0,a.jsx)(tl.Es,{children:(0,a.jsx)(tr.$,{type:"button",variant:"outline",onClick:()=>l(!1),children:m("Close")})})]})})}function tf(e){var t;let s,{open:l,onOpenChange:d}=e,{t:c}=(0,r.Bd)(),{currentRow:u,setCurrentRow:m}
1=ts(),h=(0,i.jE)(),[x,g]=(0,n.useState)(!1),[f,j]=(0,n.useState)(null),[y,v]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),N=u?.type===57,w=async()=>{if(u){g(!0);try{let e=await E(u.id);if(!e.success)throw Error(e.message||c("Failed to fetch usage"));_(e)}catch(e){o.oR.error(e instanceof Error?e.message:c("Failed to fetch usage"))}finally{g(!1)}}};if((0,n.useEffect)(()=>{!N||l&&w()},[l,N]),!u)return null;let k=async()=>{g(!0);try{let e=await C(u.id);if(e.success&&void 0!==e.balance){let t=e.balance,s=Math.floor(Date.now()/1e3);j(t),v(s),o.oR.success(c("Balance updated successfully")),m({...u,balance:t,balance_updated_time:s}),await h.invalidateQueries({queryKey:e_.lists()})}else o.oR.error(e.message||c("Failed to query balance"))}catch(e){o.oR.error(e instanceof Error?e.message:c("Failed to query balance"))}finally{g(!1)}},S=()=>{j(null),v(null),_(null),d(!1)};if(N)return(0,a.jsx)(tg,{open:l,onOpenChange:e=>{e||S()},channelName:u.name,channelId:u.id,response:b,onRefresh:w,isRefreshing:x});return(0,a.jsx)(tl.lG,{open:l,onOpenChange:S,children:(0,a.jsxs)(tl.Cf,{children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:c("Query Balance")}),(0,a.jsxs)(tl.rr,{children:[c("Update balance for:")," ",(0,a.jsx)("strong",{children:u.name})]})]}),(0,a.jsxs)("div",{className:"space-y-4 py-4",children:[(0,a.jsxs)("div",{className:"bg-muted/50 rounded-lg border p-4",children:[(0,a.jsxs)("div",{className:"text-muted-foreground mb-2 flex items-center gap-2 text-sm",children:[(0,a.jsx)(ta.G9t,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:c("Current Balance")})]}),(0,a.jsx)("div",{className:"text-2xl font-bold",children:(s=null!==f?f:u.balance,(0,p.J5)(s,{digitsLarge:2,digitsSmall:4,abbreviate:!1}))}),(0,a.jsxs)("div",{className:"text-muted-foreground mt-2 text-xs",children:[c("Last updated:")," ",(t=y??u.balance_updated_time)?(0,e0.fk)(t):"Never"]})]}),(0,a.jsxs)(tr.$,{className:"w-full",onClick:k,disabled:x,children:[x&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),!x&&(0,a.jsx)(ta.e9t,{className:"mr-2 h-4 w-4"}),x?c("Querying..."):c("Update Balance")]})]}),(0,a.jsx)(tl.Es,{children:(0,a.jsx)(tr.$,{variant:"outline",onClick:S,disabled:x,children:c("Close")})})]})})}var tj=s(55581),ty=s(3521),tv=s(23448),tb=s(33120),t_=s(54023),tN=s(61309),tw=s(82243),tk=s(10998),tC=s(1951),tS=s(32999),tR=s(34126),tA=s(58254),tM=s(23336),tO=s(5304);let tI=[{value:"auto",label:"Auto detect (default)"},{value:"openai",label:"OpenAI (/v1/chat/completions)"},{value:"openai-response",label:"OpenAI Responses (/v1/responses)"},{value:"openai-response-compact",label:"OpenAI Response Compaction (/v1/responses/compact)"},{value:"anthropic",label:"Anthropic (/v1/messages)"},{value:"gemini",label:"Gemini (/v1beta/models/{model}:generateContent)"},{value:"jina-rerank",label:"Jina Rerank (/v1/rerank)"},{value:"image-generation",label:"Image Generation (/v1/images/generations)"},{value:"embeddings",label:"Embeddings (/v1/embeddings)"}],tF=new Set(["embeddings","image-generation","jina-rerank","openai-response-compact"]);function tz(e){return e.replace(/\s+/g," ").trim()}function tE(e){switch(e){case"select":return"w-10 min-w-10";case"model":return"w-auto whitespace-nowrap";case"status":return"w-70 min-w-70 max-w-70 whitespace-normal";case"actions":return"bg-popover sticky right-0 z-20 w-24 min-w-24 border-l shadow-[-8px_0_8px_-8px_rgb(0_0_0_/_0.2)] whitespace-nowrap sm:w-28 sm:min-w-28";default:return}}function t$(e){let{open:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),{currentRow:i}=ts(),[d,c]=(0,n.useState)("auto"),[u,m]=(0,n.useState)(!1),[h,p]=(0,n.useState)(""),[x,g]=(0,n.useState)({}),[f,j]=(0,n.useState)({}
1),[y,v]=(0,n.useState)(()=>new Set),[b,_]=(0,n.useState)(!1),[N,w]=(0,n.useState)(null),[k,C]=(0,n.useState)({pageIndex:0,pageSize:10}),S=(0,n.useCallback)(()=>{c("auto"),m(!1),p(""),g({}),j({}),v(()=>new Set),_(!1),w(null),C({pageIndex:0,pageSize:10})},[]);(0,n.useEffect)(()=>{t&&i&&S()},[t,i?.id,S]);let R=tF.has(d);(0,n.useEffect)(()=>{R&&m(!1)},[R]);let A=i?.models??"",M=i?.test_model?.trim(),O=(0,n.useMemo)(()=>A?A.split(",").map(e=>e.trim()).filter(Boolean):[],[A]),I=(0,n.useMemo)(()=>{if(!h)return O;let e=h.toLowerCase();return O.filter(t=>t.toLowerCase().includes(e))},[O,h]);(0,n.useEffect)(()=>{C(e=>({...e,pageIndex:0}))},[h,A]);let F=(0,n.useMemo)(()=>I.map(e=>({model:e})),[I]),z=(0,n.useCallback)((e,t)=>{v(s=>{let a=new Set(s);return t?a.add(e):a.delete(e),a})},[]),E=(0,n.useCallback)((e,t)=>{w(t=>t?.model===e?null:t),g(s=>({...s,[e]:t}))},[]),$=(0,n.useCallback)(async function(e){let t,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(i){z(e,!0),E(e,{status:"testing"});try{await eA(i.id,{testModel:e,endpointType:"auto"===d?void 0:d,stream:u||void 0,silent:s},(s,a,r,l)=>{t={status:s?"success":"error",responseTime:a,error:r,errorCode:l},E(e,t)})}catch(s){E(e,t={status:"error",error:s instanceof Error?s.message:l("Test failed")})}finally{z(e,!1)}return t}},[i,d,u,z,l,E]),T=(0,n.useCallback)(async e=>{if(e.length){_(!0);try{let t=(await Promise.allSettled(e.map(e=>$(e,!0)))).map(e=>"fulfilled"===e.status?e.value:void 0).filter(e=>!!e).filter(e=>"success"===e.status).length,s=e.length-t;s>0?o.oR.error(l("Batch test completed: {{success}} succeeded, {{failed}} failed",{success:t,failed:s})):o.oR.success(l("Batch test completed: {{count}} succeeded",{count:t}))}finally{_(!1),j({})}}},[l,$]),P=()=>{S(),s(!1)},B=y.size>0||b,J=(0,n.useMemo)(()=>[{id:"select",header:e=>{let{table:t}=e;return(0,a.jsx)(tb.S,{checked:t.getIsAllPageRowsSelected(),indeterminate:t.getIsSomePageRowsSelected(),onCheckedChange:e=>t.toggleAllPageRowsSelected(!!e),"aria-label":l("Select all models")})},cell:e=>{let{row:t}=e;return(0,a.jsx)(tb.S,{checked:t.getIsSelected(),onCheckedChange:e=>t.toggleSelected(!!e),"aria-label":l("Select model {{model}}",{model:t.original.model})})},enableSorting:!1,enableHiding:!1,size:40},{accessorKey:"model",header:l("Model"),cell:e=>{let{row:t}=e,s=t.original.model,r=M===s;return(0,a.jsxs)("div",{className:"flex w-max items-center gap-2 whitespace-nowrap",children:[(0,a.jsx)("span",{className:"font-medium whitespace-nowrap",title:s,children:s}),r&&(0,a.jsx)(td.Wh,{label:l("Default"),variant:"info",size:"sm",copyable:!1})]})}},{id:"status",header:l("Status"),cell:e=>{let{row:t}=e,s=t.original.model,r=x[s];return(0,a.jsx)(tT,{result:r,model:s,onOpenDetails:w})},enableSorting:!1,size:220},{id:"actions",header:l("Actions"),cell:e=>{let{row:t}=e,s=t.original.model,r=y.has(s);return(0,a.jsxs)(tr.$,{variant:"outline",size:"sm",onClick:()=>$(s),disabled:r||b,children:[r&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),l("Test")]})},enableSorting:!1,size:120}],[M,b,l,x,y,$]),D=(0,tj.N4)({data:F,columns:J,state:{rowSelection:f,pagination:k},enableRowSelection:!0,getCoreRowModel:(0,ty.HT)(),getPaginationRowModel:(0,ty.kW)(),onRowSelectionChange:j,onPaginationChange:C});return i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tl.lG,{open:t,onOpenChange:P,children:(0,a.jsxs)(tl.Cf,{className:"max-h-[90vh] overflow-hidden sm:max-w-3xl",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:l("Test Channel Connection")}),(0,a.jsxs)(tl.rr,{children:[l("Test connectivity for:")," ",(0,a.jsx)("strong",{children:i.name})]})]}),(0,a.jsxs)("div",{className:"max-h-[78vh] space-y-4 overflow-y-auto py-4 pr-1",children:[(0,a.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(tN.J,{htmlFor:"endpoint-type",children:l("Endpoint Type")}),(0,a.jsxs)(tw.l6,{items:[...tI.map(e=>({value:e.value,label:l(e.label)}))],value:d,onValueChange:e=>null!==e&&c(e),children:[(0,a.jsx)(tw.bq,{id:"endpoint-type",children:(0,a.jsx)(tw.yv,{placeholder:l("Auto detect (default)")})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:tI.map(e=>{let t=e.value;return(0,a.jsx)(tw.eb,{value:t,children:l(e.label)},t)}
1)})})]}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("Override the endpoint used for testing. Leave empty to auto detect.")})]}),(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(tN.J,{htmlFor:"stream-toggle",children:l("Stream Mode")}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(tC.d,{id:"stream-toggle",checked:u,onCheckedChange:m,disabled:R}),(0,a.jsx)("span",{className:"text-sm",children:u?l("Enabled"):l("Disabled")})]}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("Enable streaming mode for the test request.")})]})]}),(0,a.jsxs)("div",{className:'space-y-3 max-sm:has-[div[role="toolbar"]]:pb-16',children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:l("Channel models")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("Select models to run batch tests.")})]}),(0,a.jsx)(t_.p,{placeholder:l("Filter models..."),value:h,onChange:e=>p(e.target.value),className:"sm:w-64"})]}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("div",{className:"overflow-hidden rounded-md border",role:"region","aria-label":l("Channel models"),children:(0,a.jsx)("div",{className:"max-h-90 overflow-auto **:data-[slot=table-container]:overflow-visible",children:(0,a.jsxs)(tS.XI,{className:"w-max min-w-full table-auto",children:[(0,a.jsxs)("colgroup",{children:[(0,a.jsx)("col",{className:"w-10 min-w-10"}),(0,a.jsx)("col",{className:"w-auto"}),(0,a.jsx)("col",{className:"w-70"}),(0,a.jsx)("col",{className:"w-24 sm:w-28"})]}),(0,a.jsx)(tS.A0,{children:D.getHeaderGroups().map(e=>(0,a.jsx)(tS.Hj,{children:e.headers.map(e=>(0,a.jsx)(tS.nd,{className:tE(e.column.id),children:e.isPlaceholder?null:(0,tj.Kv)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,a.jsx)(tS.BF,{children:D.getRowModel().rows.length?D.getRowModel().rows.map(e=>(0,a.jsx)(tS.Hj,{"data-state":e.getIsSelected()?"selected":void 0,children:e.getVisibleCells().map(e=>(0,a.jsx)(tS.nA,{className:tE(e.column.id),children:(0,tj.Kv)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,a.jsx)(tS.Hj,{children:(0,a.jsx)(tS.nA,{colSpan:D.getVisibleLeafColumns().length,className:"text-muted-foreground h-16 text-center text-sm",children:O.length?"No models matched your search.":"This channel has no configured models."})})})]})})}),(0,a.jsx)(tM.T,{table:D})]}),(0,a.jsx)(tJ,{table:D,disabled:B,onTestSelected:T})]})]}),(0,a.jsx)(tl.Es,{children:(0,a.jsx)(tr.$,{variant:"outline",onClick:P,children:l("Close")})})]})}),(0,a.jsx)(tB,{details:N,onOpenChange:e=>{e||w(null)}})]}):null}function tT(e){let{result:t,model:s,onOpenDetails:l}=e,{t:n}=(0,r.Bd)();return t&&"idle"!==t.status?"testing"===t.status?(0,a.jsxs)("div",{className:"text-muted-foreground flex min-w-0 items-center gap-2 text-sm",children:[(0,a.jsx)(ta.krw,{className:"h-4 w-4 shrink-0 animate-spin"}),(0,a.jsx)("span",{className:"truncate",children:n("Testing...")})]}):"success"===t.status?(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-1 text-xs",children:[(0,a.jsx)(td.Wh,{label:n("Success"),variant:"success",copyable:!1}),"number"==typeof t.responseTime&&(0,a.jsx)("span",{className:"text-muted-foreground truncate",children:e5(t.responseTime,n)})]}):(0,a.jsx)(tP,{result:t,model:s,onOpenDetails:l}):(0,a.jsx)(td.Wh,{label:n("Not tested"),variant:"neutral",copyable:!1})}function tP(e){let{result:t,model:s,onOpenDetails:l}=e,{t:n}=(0,r.Bd)(),i=t.error?.trim(),o="model_price_error"===t.errorCode,d=n("Model price is not configured. Please complete model pricing in settings."),{summary:c,details:u}=function(e){var t;let{errorText:s,fallbackSummary:a,isModelPriceError:r,modelPriceSummary:l}=e,n=s?.trim();if(!n)return{summary:a};if(r)return{summary:l,details:n===l?void 0:n};let i=(t=tz(n.split(/\r?\n/).map(e=>e.trim()).find(Boolean)??n)).length<=96?t:`${t.slice(0,96).trimEnd()}...`;return{summary:i,details:i===tz(n)?void 0:n}}({errorText:i,fallbackSummary:n("Test failed"),isModelPriceError:o,modelPriceSummary:d});return(0,a.jsxs)("div",{className:"flex min-w-0 flex-col gap-1.5 text-xs whitespace-normal",children:[(0,a.jsx)(td.Wh,{label:n("Failed"),variant:"danger",copyable:!1}),(0,a.jsx)("p",{className:"text-muted-foreground line-clamp-2 min-w-0 leading-snug wrap-break-word",children:c}),(0,a.jsxs)("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[o&&(0,a.jsxs)(tr.$,{variant:"outline",size:"sm",className:"h-7 w-fit px-2 text-xs",onClick:()=>window.open("/system-settings/billing/model-pricing","_blank"),children:[(0,a.jsx)(ta.wB_,{className:"mr-1 h-3 w-3 shrink-0"}),n("Go to Settings")]}),u&&(0,a.jsxs)(tr.$,{variant:"ghost",size:"sm",className:"h-7 w-fit px-2 text-xs","aria-haspopup":"dialog",onClick:()=>l({model:s,summary:c,details:u}),children:[(0,a.jsx)(ta.R2D,{className:"mr-1 h-3 w-3 shrink-0"}),n("Details")]})]})]})}function tB(e){let{details:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),n=(0,tv.a)(),{copiedText:i,copyToClipboard:o}=(0,tn.C)({notify:!1});return(0,a.jsx)(tk.cj,{open:!!t,onOpenChange:s,children:(0,a.jsx)(tk.h,{side:n?"bottom":"right",className:n?(0,tO.jW)("h-auto max-h-[85dvh] rounded-t-xl"):(0,tO.jW)("sm:max-w-lg"),children:t&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(tk.Fm,{className:(0,tO.Dt)("sm:px-5"),children:[(0,a.jsx)(tk.qp,{className:"pr-10",children:l("Details")}),(0,a.jsx)(tk.Qs,{className:"pr-10 wrap-break-word",children:t.model})]}),(0,a.jsxs)("div",{className:(0,tO.e)("gap-4 sm:px-5"),children:[(0,a.jsxs)("section",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs font-medium",children:l("Model")}),(0,a.jsx)("p",{className:"text-sm font-medium break-all",children:t.model})]}),(0,a.jsxs)("section",{className:"space-y-1",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs font-medium",children:l("Failed")}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm leading-relaxed wrap-break-word",children:t.summary})]}),(0,a.jsxs)("section",{className:"space-y-2",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-xs font-medium",children:l("Details")}),(0,a.jsx)("pre",{className:"bg-muted/30 text-muted-foreground m-0 max-w-full rounded-md border p-3 text-xs leading-relaxed wrap-break-word whitespace-pre-wrap",children:t.details})]})]}),(0,a.jsx)(tk.XW,{className:(0,tO.Jx)("sm:px-5"),children:(0,a.jsxs)(tr.$,{variant:"outline",className:"w-full sm:w-auto",onClick:()=>o(t.details),children:[i===t.details?(0,a.jsx)(ta.Jlk,{className:"mr-2 h-4 w-4 text-green-600"}):(0,a.jsx)(ta.QRo,{className:"mr-2 h-4 w-4"}),l("Copy")]})})]})})})}function tJ(e){let{table:t,disabled:s,onTestSelected:l}=e,{t:n}=(0,r.Bd)(),i=t.getFilteredSelectedRowModel().rows.map(e=>e.original.model),o=i.length>0?n("Test {{count}} selected",{count:i.length}):n("Test selected models");return(0,a.jsx)(tA.Of,{table:t,entityName:"model",children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(tr.$,{size:"sm",onClick:()=>l(i),disabled:s||0===i.length}),children:s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),n("Testing...")]}):o}),(0,a.jsx)(tR.ZI,{children:(0,a.jsx)("p",{children:n("Run tests for the selected models")})})]})})}function tD(e){let{open:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),{currentRow:o}
1=ts(),d=(0,i.jE)(),[c,u]=(0,n.useState)("_copy"),[m,h]=(0,n.useState)(!0),[p,x]=(0,n.useState)(!1);if(!o)return null;let g=async()=>{x(!0),await eM(o.id,{suffix:c,reset_balance:m},d,()=>{s(!1),u("_copy"),h(!0)}),x(!1)};return(0,a.jsx)(tl.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(tl.Cf,{children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:l("Copy Channel")}),(0,a.jsxs)(tl.rr,{children:[l("Create a copy of:")," ",(0,a.jsx)("strong",{children:o.name})]})]}),(0,a.jsxs)("div",{className:"space-y-4 py-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tN.J,{htmlFor:"suffix",children:l("Name Suffix")}),(0,a.jsx)(t_.p,{id:"suffix",placeholder:l("_copy"),value:c,onChange:e=>u(e.target.value),disabled:p}),(0,a.jsxs)("p",{className:"text-muted-foreground text-xs",children:[l("New name will be:")," ",o.name,c]})]}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(tb.S,{id:"reset-balance",checked:m,onCheckedChange:e=>h(!!e),disabled:p}),(0,a.jsx)(tN.J,{htmlFor:"reset-balance",className:"text-sm font-normal",children:l("Reset balance and used quota")})]})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:()=>s(!1),disabled:p,children:l("Cancel")}),(0,a.jsxs)(tr.$,{onClick:g,disabled:p,children:[p&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),p?"Copying...":"Copy Channel"]})]})]})})}var tq=s(53540),tV=s(72690),tK=s(28769),tL=s(38525);function tH(e){let{open:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),{currentTag:d}=ts(),c=(0,i.jE)(),[u,m]=(0,n.useState)(""),[h,p]=(0,n.useState)([]),[x,g]=(0,n.useState)(""),[f,j]=(0,n.useState)(""),[y,v]=(0,n.use
1State)([]),[b,_]=(0,n.useState)(!1),{data:N,isLoading:w}=(0,tq.I)({queryKey:["tag-models",d],queryFn:()=>d?U(d):null,enabled:t&&!!d}),{data:k}=(0,tq.I)({queryKey:["all-models"],queryFn:Y,enabled:t}),{data:C}=(0,tq.I)({queryKey:["groups"],queryFn:Z,enabled:t}),S=k?.data?.map(e=>e.id).filter(Boolean)||[],R=C?.data||[];(0,n.useEffect)(()=>{t&&d&&(m(d),j(""),v([]),g(""),N?.data?p(N.data.split(",").filter(Boolean)):p([]))},[t,d,N]);let A=()=>{if(!x.trim())return;let e=x.split(",").map(e=>e.trim()).filter(Boolean).filter(e=>!h.includes(e));e.length>0?(p([...h,...e]),o.oR.success(l("Added {{count}} model(s)",{count:e.length})),g("")):o.oR.info(l("No new models to add"))},M=async()=>{if(d&&(()=>{if(f.trim())try{JSON.parse(f)}catch{return o.oR.error(l("Model mapping must be valid JSON")),!1}return!0})()){if(!(u!==d||f.trim()||h.length>0||y.length>0))return void o.oR.warning(l("No changes to save"));_(!0);try{let e={tag:d};u&&u!==d&&(e.new_tag=u||null),f.trim()&&(e.model_mapping=f),h.length>0&&(e.models=h.join(",")),y.length>0&&(e.groups=y.join(","));let t=await H(e);t.success?(o.oR.success(l("Tag updated successfully")),c.invalidateQueries({queryKey:e_.lists()}),s(!1)):o.oR.error(t.message||l("Failed to update tag"))}catch(e){o.oR.error(e instanceof Error?e.message:l("Failed to update tag"))}finally{_(!1)}}},O=()=>{s(!1)};return d?(0,a.jsx)(tl.lG,{open:t,onOpenChange:O,children:(0,a.jsxs)(tl.Cf,{className:"max-h-[90vh] max-w-2xl",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsxs)(tl.L3,{children:[l("Edit Tag:")," ",d]}),(0,a.jsx)(tl.rr,{children:l("Batch edit all channels with this tag. Leave fields empty to keep current values.")})]}),(0,a.jsx)(to.F,{className:"max-h-[60vh] pr-4",children:(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)(tN.J,{htmlFor:"new-tag",children:[l("Tag Name"),(0,a.jsx)("span",{className:"text-muted-foreground ml-2 text-xs",children:l("(Leave empty to dissolve tag)")})]}),(0,a.jsx)(t_.p,{id:"new-tag",value:u,onChange:e=>m(e.target.value),placeholder:l("Enter new tag name or leave empty")})]}),(0,a.jsx)(tV.w,{}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)(tN.J,{children:[l("Models"),(0,a.jsx)("span",{className:"text-muted-foreground ml-2 text-xs",children:l("(Override all channels' models)")})]}),w?(0,a.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,a.jsx)(ta.krw,{className:"h-4 w-4 animate-spin"}),(0,a.jsx)("span",{className:"text-muted-foreground text-sm",children:l("Loading current models...")})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex min-h-[60px] flex-wrap gap-2 rounded-md border p-3",children:h.length>0?h.map(e=>(0,a.jsxs)(td.Wh,{variant:"neutral",className:"cursor-pointer transition-opacity hover:opacity-70",copyable:!1,onClick:()=>{p(h.filter(t=>t!==e))},children:[e," Ã"]},e)):(0,a.jsx)("span",{className:"text-muted-foreground text-sm",children:l("No models selected")})}),(0,a.jsx)("div",{className:"flex gap-2",children:(0,a.jsxs)(tw.l6,{items:[...S.map(e=>({value:e,label:e}))],onValueChange:e=>{null!==e&&(h.includes(e)||p([...h,e]))},children:[(0,a.jsx)(tw.bq,{className:"flex-1",children:(0,a.jsx)(tw.yv,{placeholder:l("Add from available models...")})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:(0,a.jsx)(to.F,{className:"h-60",children:S.map(e=>(0,a.jsx)(tw.eb,{value:e,children:e},e))})})})]})}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(t_.p,{placeholder:l("Custom model (comma-separated)"),value:x,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),A())}}),(0,a.jsx)(tr.$,{type:"button",variant:"secondary",onClick:A,children:l("Add")})]})]})]}),(0,a.jsx)(tV.w,{}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)(tN.J,{htmlFor:"model-mapping",children:[l("Model Mapping (JSON)"),(0,a.jsx)("span",{className:"text-muted-foreground ml-2 text-xs",children:l("(Optional: redirect model names)")})]}),(0,a.jsx)(tK.T,{id:"model-mapping",value:f,onChange:e=>j(e.target.value),placeholder:'{\n "gpt-3.5-turbo": "gpt-3.5-turbo-0125"\n}',rows:4,className:"font-mono text-sm"}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>j(JSON.stringify({"gpt-3.5-turbo":"gpt-3.5-turbo-0125"},null,2)),children:l("Example")}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>j(JSON.stringify({},null,2)),children:l("Clear Mapping")}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>j(""),children:l("No Change")})]})]}),(0,a.jsx)(tV.w,{}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)(tN.J,{children:[l("Groups"),(0,a.jsx)("span",{className:"text-muted-foreground ml-2 text-xs",children:l("(Override all channels' groups)")})]}
1),(0,a.jsx)("div",{className:"flex min-h-[60px] flex-wrap gap-2 rounded-md border p-3",children:R.map(e=>(0,a.jsx)(tL.d,{group:e,className:`cursor-pointer rounded-sm transition-opacity hover:opacity-70 ${y.includes(e)?"bg-muted/70 px-1":""}`,onClick:()=>{v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}},e))})]})]})}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:O,children:l("Cancel")}),(0,a.jsxs)(tr.$,{onClick:M,disabled:b,children:[b&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),l("Save Changes")]})]})]})}):null}var tU=s(38579),tW=s(34151);function tQ(e){return Array.from(new Set(e.map(e=>e9(e)).filter(Boolean)))}function tG(e){let{open:t,onOpenChange:s,onModelsSelected:l,redirectModels:d=[],redirectSourceModels:c=[],customFetcher:u,existingModelsOverride:m,channelName:h}=e,{t:p}=(0,r.Bd)(),{currentRow:x}=ts(),g=u?null:x,f=(0,i.jE)(),[j,y]=(0,n.useState)(!1),[v,_]=(0,n.useState)(!1),[N,w]=(0,n.useState)([]),[k,C]=(0,n.useState)([]),[R,A]=(0,n.useState)(""),M=(0,n.useMemo)(()=>m??e8(g?.models||""),[m,g?.models]),{classificationSet:O,redirectOnlySet:I}=(0,n.useMemo)(()=>{let e,t,s,a;return e=new Set(M.map(e=>e9(e)).filter(Boolean)),s=new Set([...e,...t=new Set(d.map(e=>e9(e)).filter(Boolean))]),a=new Set(Array.from(t).filter(t=>!e.has(t))),{normalizedCurrentModels:e,normalizedRedirectModels:t,classificationSet:s,redirectOnlySet:a}},[M,d]),F=(0,n.useMemo)(()=>new Set(tQ(N)),[N]),z=(0,n.useMemo)(()=>new Set(tQ(c)),[c]),E=(0,n.useMemo)(()=>{let e=R.toLowerCase().trim();return tQ(k).filter(t=>!(F.has(t)||z.has(t))&&(!e||t.toLowerCase().includes(e)))},[F,z,R,k]);(0,n.useEffect)(()=>{t&&(g||u)&&$()},[t,g?.id,u]);let $=async()=>{if(g||u){y(!0);try{if(u){let e=await u();w(e),C(M),o.oR.success(p("Fetched {{count}} models",{count:e.length}))}else{let e=await S(g.id);if(e.success){let t=Array.isArray(e.data)?e.data:[];w(t),C(M),o.oR.success(p("Fetched {{count}} models",{count:t.length}))}else o.oR.error(e.message||p("Failed to fetch models")),w([])}}catch(e){o.oR.error(e instanceof Error?e.message:p("Failed to fetch models")),w([])}finally{y(!1)}}},T=async()=>{if(l){l(k),o.oR.success(p("Models filled to form")),s(!1);return}if(g){_(!0);try{let e=k.join(","),t=await b(g.id,{models:e});t.success?(o.oR.success(p("Models updated successfully")),f.invalidateQueries({queryKey:e_.lists()}),s(!1)):o.oR.error(t.message||p("Failed to update models"))}catch(e){o.oR.error(e instanceof Error?e.message:p("Failed to update models"))}finally{_(!1)}}},P=()=>{w([]),C([]),A(""),s(!1)},B=e=>{let t={};return e.forEach(e=>{let s="Other";e.toLowerCase().includes("gpt")||e.toLowerCase().includes("o1")||e.toLowerCase().includes("o3")?s="OpenAI":e.toLowerCase().includes("claude")?s="Anthropic":e.toLowerCase().includes("gemini")?s="Gemini":e.toLowerCase().includes("qwen")?s="Qwen":e.toLowerCase().includes("deepseek")?s="DeepSeek":e.toLowerCase().includes("glm")?s="Zhipu":e.toLowerCase().includes("llama")?s="Meta":e.toLowerCase().includes("mistral")&&(s="Mistral"),t[s]||(t[s]=[]),t[s].push(e)}),t},J=(0,n.useMemo)(()=>R?N.filter(e=>e.toLowerCase().includes(R.toLowerCase())):N,[N,R]),D=e=>O.has(e9(e)),q=J.filter(e=>!D(e)),V=J.filter(e=>D(e)),K=B(q),L=B(V),H=e=>Object.entries(e).sort((e,t)=>{let[s]=e,[a]=t;return"Other"===s?1:"Other"===a?-1:s.localeCompare(a,void 0,{sensitivity:"base"})}),U=(e,t)=>{let s=t.every(e=>k.includes(e));return(0,a.jsxs)(tU.Nt,{defaultOpen:!0,children:[(0,a.jsxs)(tU.R6,{className:"hover:bg-muted/50 flex w-full items-center justify-between rounded-lg border p-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ta.yQN,{className:"h-4 w-4"}),(0,a.jsxs)("span",{className:"font-medium",children:[e," (",t.length,")"]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("span",{className:"text-muted-foreground text-sm",children:[t.filter(e=>k.includes(e)).length," ","/ ",t.length," selected"]}),(0,a.jsx)(tb.S,{checked:s,onCheckedChange:e=>{var s;return s=!!e,void C(e=>{if(!s)return e.filter(e=>!t.includes(e));{let s=[...e];return t.forEach(e=>{s.includes(e)||s.push(e)}),s}})},onClick:e=>e.stopPropagation()})]})]}),(0,a.jsx)(tU.Ke,{className:"px-4 py-2",children:(0,a.jsx)("div",{className:"grid grid-cols-2 gap-2",children:t.map(e=>(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(tb.S,{id:e,checked:k.includes(e),onCheckedChange:()=>{C(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}}),(0,a.jsxs)(tN.J,{htmlFor:e,className:"flex cursor-pointer items-center gap-1.5 text-sm font-normal",children:[(0,a.jsx)("span",{children:e}),I.has(e9(e))&&(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(ta.R2D,{className:"h-3.5 w-3.5 text-amber-500"})}),(0,a.jsx)(tR.ZI,{children:p("From model redirect, not yet added to models list")})]})]})]},e))})})]},e)};return(0,a.jsx)(tl.lG,{open:t,onOpenChange:P,children:(0,a.jsxs)(tl.Cf,{className:"max-w-3xl",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:p("Fetch Models")}),(0,a.jsx)(tl.rr,{children:g?(0,a.jsxs)(a.Fragment,{children:[p("Fetch available models for:")," ",(0,a.jsx)("strong",{children:g.name})]}):h?(0,a.jsxs)(a.Fragment,{children:[p("Fetch available models for:")," ",(0,a.jsx)("strong",{children:h})]}):p("Fetch available models from upstream")})]}),g||u?j?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsx)(ta.krw,{className:"text-muted-foreground h-8 w-8 animate-spin"})}):0===N.length&&0===E.length?(0,a.jsxs)("div",{className:"text-muted-foreground py-8 text-center",children:[(0,a.jsx)("p",{children:p("No models fetched yet.")}),(0,a.jsx)(tr.$,{className:"mt-4",onClick:$,disabled:j,children:p("Fetch Models")})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(ta.vji,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"}),(0,a.jsx)(t_.p,{placeholder:p("Search models..."),value:R,onChange:e=>A(e.target.value),className:"pl-9"})]}),(0,a.jsxs)(tW.tU,{defaultValue:q.length>0?"new":E.length>0?"removed":"existing",children:[(0,a.jsxs)(tW.j7,{className:`grid w-full ${E.length>0?"grid-cols-3":"grid-cols-2"}`,children:[(0,a.jsx)(tW.Xi,{value:"new",disabled:0===q.length,children:p("New Models ({{count}})",{count:q.length})}),(0,a.jsx)(tW.Xi,{value:"existing",disabled:0===V.length,children:p("Existing Models ({{count}})",{count:V.length})}),E.length>0&&(0,a.jsx)(tW.Xi,{value:"removed",children:p("Removed Models ({{count}})",{count:E.length})})]}),(0,a.jsx)(tW.av,{value:"new",className:"max-h-96 space-y-2 overflow-y-auto",children:H(K).map(e=>{let[t,s]=e;return U(t,s)})}),(0,a.jsx)(tW.av,{value:"existing",className:"max-h-96 space-y-2 overflow-y-auto",children:H(L).map(e=>{let[t,s]=e;return U(t,s)})}),E.length>0&&(0,a.jsxs)(tW.av,{value:"removed",className:"max-h-96 space-y-2 overflow-y-auto",children:[(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:p("These models are still in your selection but were not returned by the upstream listing. Entries that are only model_mapping source aliases are omitted. Toggle to adjust before saving.")}),U(p("Removed"),E)]})]},`${g?.id??"custom"}-${N.length}-${E.length}`),(0,a.jsx)("div",{className:"bg-muted/50 rounded-lg border p-3 text-sm",children:p("{{n}} model(s) selected",{n:k.length})})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:P,disabled:v,children:p("Cancel")}),(0,a.jsxs)(tr.$,{onClick:T,disabled:v,children:[v&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),v?p("Saving..."):p("Save Models")]})]})]}):(0,a.jsx)("div",{className:"text-muted-foreground py-8 text-center",children:p("No channel selected")})]})})}var tX=s(24993);function tY(e){let{label:t,count:s,total:l}=e,{t:n}=(0,r.Bd)();return(0,a.jsxs)("div",{className:"rounded-md border p-3",children:[(0,a.jsx)("div",{className:"text-muted-foreground mb-1 text-xs font-medium",children:t}),(0,a.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,a.jsx)("span",{className:"text-foreground text-2xl font-semibold",children:s}),(0,a.jsxs)("span",{className:"text-muted-foreground text-sm",children:[n("of")," ",l]})]})]})}function tZ(e){let{keyIndex:t,status:s,onAction:l}=e,{t:n}=(0,r.Bd)();return(0,a.jsxs)("div",{className:"flex justify-end gap-2",children:[1===s?(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>l({type:"disable",keyIndex:t}),children:n("Disable")}):(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>l({type:"enable",keyIndex:t}),children:n("Enable")}),(0,a.jsx)(tr.$,{variant:"destructive",size:"sm",onClick:()=>
1l({type:"delete",keyIndex:t}),children:n("Delete")})]})}function t0(e){let{open:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),{currentRow:d}=ts(),c=(0,i.jE)(),[u,m]=(0,n.useState)(!1),[h,p]=(0,n.useState)([]),[x,g]=(0,n.useState)(1),[f,j]=(0,n.useState)(10),[y,v]=(0,n.useState)(0),[b,_]=(0,n.useState)(0),[N,w]=(0,n.useState)(0),[k,C]=(0,n.useState)(0),[S,R]=(0,n.useState)(0),[A,M]=(0,n.useState)(null),[O,I]=(0,n.useState)(null),[F,z]=(0,n.useState)(!1);(0,n.useEffect)(()=>{t&&d&&(g(1),M(null),E(1,f,null))},[t,d?.id]);let E=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:x,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:A;if(d){m(!0);try{let a=await T(d.id,e,t,null===s?void 0:s);a.success&&a.data?(p(a.data.keys||[]),v(a.data.total||0),g(a.data.page||1),j(a.data.page_size||10),_(a.data.total_pages||0),w(a.data.enabled_count||0),C(a.data.manual_disabled_count||0),R(a.data.auto_disabled_count||0)):o.oR.error(a.message||l("Failed to load key status"))}catch(e){o.oR.error(e instanceof Error?e.message:l("Failed to load key status"))}finally{m(!1)}}},$=e=>{g(e),E(e,f)},K=async()=>{if(O&&d){z(!0);try{let e,{type:t,keyIndex:s}=O;"enable"===t&&void 0!==s?e=await P(d.id,s):"disable"===t&&void 0!==s?e=await B(d.id,s):"delete"===t&&void 0!==s?e=await J(d.id,s):"enable-all"===t?e=await D(d.id):"disable-all"===t?e=await q(d.id):"delete-disabled"===t&&(e=await V(d.id)),e?.success?(o.oR.success(e.message||l("Operation successful")),c.invalidateQueries({queryKey:e_.lists()}),t.includes("all")||"delete-disabled"===t?(g(1),E(1,f)):E(x,f)):o.oR.error(e?.message||l("Operation failed"))}catch(e){o.oR.error(e instanceof Error?e.message:l("Operation failed"))}finally{z(!1),I(null)}}};return d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tl.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(tl.Cf,{className:"flex max-h-[90vh] max-w-5xl flex-col",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsxs)(tl.L3,{className:"flex items-center gap-2",children:[l("Multi-Key Management"),(0,a.jsx)(td.Wh,{label:d.name,variant:"neutral",copyable:!1}),d.channel_info?.multi_key_mode&&(0,a.jsx)(td.Wh,{label:"random"===d.channel_info.multi_key_mode?l("Random"):l("Polling"),variant:"neutral",copyable:!1})]}),(0,a.jsx)(tl.rr,{children:l("Manage multi-key status and configuration for this channel")})]}),(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col space-y-4 overflow-hidden",children:[(0,a.jsxs)("div",{className:"grid shrink-0 grid-cols-3 gap-3",children:[(0,a.jsx)(tY,{label:l("Enabled"),count:N,total:y}),(0,a.jsx)(tY,{label:l("Manual Disabled"),count:k,total:y}),(0,a.jsx)(tY,{label:l("Auto Disabled"),count:S,total:y})]}),(0,a.jsx)(tV.w,{className:"shrink-0"}),(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between",children:[(0,a.jsxs)(tw.l6,{items:[...eo.map(e=>({value:e.value,label:l(e.label)}))],value:null===A?"all":A.toString(),onValueChange:e=>{let t;return null!==e&&void(M(t="all"===e?null:parseInt(e)),g(1),E(1,f,t))},children:[(0,a.jsx)(tw.bq,{className:"w-40",children:(0,a.jsx)(tw.yv,{placeholder:l("All Status")})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:eo.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:l(e.label)},e.value))})})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>E(),disabled:u,children:(0,a.jsx)(ta.e9t,{className:"h-4 w-4"})}),k+S>0&&(0,a.jsxs)(tr.$,{variant:"default",size:"sm",onClick:()=>I({type:"enable-all"}),children:[(0,a.jsx)(ta.aJd,{className:"mr-2 h-4 w-4"}),l("Enable All")]}),N>0&&(0,a.jsxs)(tr.$,{variant:"destructive",size:"sm",onClick:()=>I({type:"disable-all"}),children:[(0,a.jsx)(ta.$o3,{className:"mr-2 h-4 w-4"}),l("Disable All")]}),S>0&&(0,a.jsxs)(tr.$,{variant:"destructive",size:"sm",onClick:()=>I({type:"delete-disabled"}),children:[(0,a.jsx)(ta.TBR,{className:"mr-2 h-4 w-4"}),l("Delete Auto-Disabled")]})]})]}),(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-auto rounded-md border",children:u?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsx)(ta.krw,{className:"text-muted-foreground h-8 w-8 animate-spin"})}):0===h.length?(0,a.jsx)("div",{className:"text-muted-foreground py-12 text-center",children:l("No keys found")}):(0,a.jsx)("div",{className:"min-w-[800px]",children:(0,a.jsxs)(tS.XI,{children:[(0,a.jsx)(tS.A0,{children:(0,a.jsxs)(tS.Hj,{children:[(0,a.jsx)(tS.nd,{className:"w-20",children:l("Index")}),(0,a.jsx)(tS.nd,{className:"w-32",children:l("Status")}),(0,a.jsx)(tS.nd,{className:"min-w-[200px]",children:l("Disabled Reason")}),(0,a.jsx)(tS.nd,{className:"w-44",children:l("Disabled Time")}),(0,a.jsx)(tS.nd,{className:"w-44 text-right",children:l("Actions")})]})}),(0,a.jsx)(tS.BF,{children:h.map(e=>{let t;return(0,a.jsxs)(tS.Hj,{children:[(0,a.jsxs)(tS.nA,{className:"font-mono text-sm",children:["#",e.index+1]}),(0,a.jsx)(tS.nA,{children:(t=en[e.status]||{variant:"neutral",label:"Unknown"},(0,a.jsx)(td.Wh,{label:l(t.label),variant:t.variant,showDot:!0,copyable:!1}))}),(0,a.jsx)(tS.nA,{className:"max-w-xs truncate text-sm",children:e.reason||"-"}),(0,a.jsx)(tS.nA,{className:"text-muted-foreground text-sm",children:(e=>{if(!e)return"-";if(!e||0===e)return"N/A";try{return(0,e0.fk)(e)}catch{return"Invalid date"}})(e.disabled_time)}
1),(0,a.jsx)(tS.nA,{children:(0,a.jsx)(tZ,{keyIndex:e.index,status:e.status,onAction:I})})]},e.index)})})]})})}),b>1&&(0,a.jsxs)("div",{className:"flex shrink-0 items-center justify-between",children:[(0,a.jsx)("div",{className:"text-muted-foreground text-sm",children:l("Page {{current}} of {{total}}",{current:x,total:b})}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>$(x-1),disabled:1===x||u,children:l("Previous")}),(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>$(x+1),disabled:x>=b||u,children:l("Next")})]})]})]})]})}),(0,a.jsx)(tX.T,{open:null!==O,onOpenChange:e=>!e&&I(null),title:l("Confirm Action"),desc:l(function(e){if(!e)return"";switch(e.type){case"delete":return"Are you sure you want to delete this key? This action cannot be undone.";case"enable":return"Enable this key?";case"disable":return"Disable this key?";case"enable-all":return"Are you sure you want to enable all keys?";case"disable-all":return"Are you sure you want to disable all enabled keys?";case"delete-disabled":return"Are you sure you want to delete all auto-disabled keys? This action cannot be undone.";default:return""}}(O)),destructive:!!O&&("delete"===O.type||"delete-disabled"===O.type||"disable-all"===O.type),isLoading:F,handleConfirm:K})]}):null}var t1=s(18692);function t2(e){return"object"==typeof e&&null!==e}function t4(e){return"string"==typeof e?e:void 0}function t3(e){return"number"==typeof e?e:void 0}function t5(e){if(!e)return"";let t="string"==typeof e.base_url?e.base_url.trim():"";if(t)return t;let s="string"==typeof e?.ollama_base_url?String(e.ollama_base_url).trim():"";if(s)return s;let a=function(e){if(!e)return null;if("object"==typeof e)return e;if("string"==typeof e)try{return JSON.parse(e)}catch{}return null}(e.other_info);if(t2(a)){let e=t4(a.base_url)?.trim();if(e)return e;let t=t4(a.public_url)?.trim();if(t)return t;let s=t4(a.api_url)?.trim();if(s)return s}return""}function t6(e){return Array.isArray(e)?e.map(e=>{if(!e)return null;if("string"==typeof e)return{id:e,owned_by:"ollama"};if(t2(e)){let t=t4(e.id)||t4(e.ID)||t4(e.name)||t4(e.model)||t4(e.Model);if(!t)return null;let s=e.metadata??e.Metadata,a={...e,id:t,owned_by:t4(e.owned_by)||t4(e.ownedBy)||"ollama"},r=t3(e.size);if("number"!=typeof r||a.size||(a.size=r),t2(s)){let e=t3(s.size);"number"!=typeof e||a.size||(a.size=e);let t=t4(s.digest);!a.digest&&t&&(a.digest=t);let r=t4(s.modified_at);!a.modified_at&&r&&(a.modified_at=r),s.details&&!a.details&&(a.details=s.details)}return a}return null}).filter(Boolean):[]}function t8(e){let{open:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),c=(0,i.jE)(),{currentRow:u}=ts(),m=u?.type===4,h=u?.id,[p,x]=(0,n.useState)(!1),[g,f]=(0,n.useState)([]),[j,y]=(0,n.useState)([]),[v,_]=(0,n.useState)(""),[N,w]=(0,n.useState)(""),[k,C]=(0,n.useState)(!1),[R,A]=(0,n.use
1State)(null),M=(0,n.useRef)(null),[O,I]=(0,n.useState)(!1),[F,z]=(0,n.useState)(null),[E,$]=(0,n.useState)(!1),T=(0,n.useMemo)(()=>{if(!v.trim())return g;let e=v.trim().toLowerCase();return g.filter(t=>t.id.toLowerCase().includes(e))},[g,v]),P=(0,n.useMemo)(()=>e8(u?.models??""),[u?.models]);(0,n.useEffect)(()=>{if(!t){f([]),y([]),_(""),w(""),C(!1),A(null),M.current?.abort(),M.current=null;return}t&&m&&h&&B()},[t,m,h]);let B=(0,n.useCallback)(async()=>{if(h){x(!0);try{let e=[],t="",s=t5(u??null);if(m&&s)try{let a=await W({base_url:s,type:4,key:"string"==typeof u?.key?u.key:""});a?.success?e=t6(a.data):a?.message&&(t=String(a.message))}catch(e){t=e instanceof Error?e.message:""}if(!e.length){let s=await S(Number(h));s?.success?(e=t6(s.data),t=""):t=String(s?.message||"")}!e.length&&t&&o.oR.error(t||l("Failed to fetch models")),f(e),y(t=>{if(!t.length)return e.map(e=>e.id);let s=t.filter(t=>e.some(e=>e.id===t));return s.length?s:e.map(e=>e.id)})}catch(t){let e=t instanceof Error?t.message:void 0;o.oR.error(e||l("Failed to fetch models")),f([])}finally{x(!1)}}},[h,u,m,l]),J=async e=>{if(!u)return;if(!j.length)return void o.oR.info(l("No models selected"));let t="replace"===e?Array.from(new Set(j)):Array.from(new Set([...P,...j]));try{let s=await b(u.id,{models:t.join(",")});s.success?(o.oR.success("replace"===e?l("Models updated successfully"):l("Models appended successfully")),c.invalidateQueries({queryKey:e_.lists()})):o.oR.error(s.message||l("Failed to update models"))}catch(e){o.oR.error(e instanceof Error?e.message:l("Failed to update models"))}},D=async()=>{if(!h)return;if(!N.trim())return void o.oR.error(l("Please enter model name"));if(!t5(u))return void o.oR.error(l("Please set Ollama API Base URL first"));M.current?.abort();let e=new AbortController;M.current=e,C(!0),A({status:"starting",completed:0,total:0});try{let t=await fetch("/api/channel/ollama/pull/stream",{method:"POST",credentials:"include",headers:{...(0,d.Ql)(),Accept:"text/event-stream"},body:JSON.stringify({channel_id:h,model_name:N.trim()}),signal:e.signal});if(!t.ok||!t.body)throw Error(`HTTP ${t.status}: ${t.statusText}`);let s=t.body.getReader(),a=new TextDecoder,r="";for(;;){let{done:e,value:t}=await s.read();if(e)break;let l=(r+=a.decode(t,{stream:!0})).split("\n");for(let e of(r=l.pop()||"",l)){if(!e.startsWith("data: "))continue;let t=e.slice(6);if(t){if("[DONE]"===t){C(!1),A(null),M.current=null;return}try{let e=JSON.parse(t);if(e?.status)A(e);else if(e?.error){o.oR.error(String(e.error)),C(!1),A(null),M.current=null;return}else if(e?.message){o.oR.success(String(e.message)),w(""),C(!1),A(null),M.current=null,await B(),c.invalidateQueries({queryKey:e_.lists()});return}}catch{}}}}C(!1),A(null),M.current=null,await B(),c.invalidateQueries({queryKey:e_.lists()})}catch(e){if(!("object"==typeof e&&null!==e&&"name"in e&&"AbortError"===e.name)){let t=e instanceof Error?e.message:"";o.oR.error(l("Model pull failed: {{msg}}",{msg:t}))}C(!1),A(null),M.current=null}},q=async e=>{if(h)try{$(!0);let t=await Q({channel_id:Number(h),model_name:e});t?.success?(o.oR.success(l("Model deleted")),await B(),c.invalidateQueries({queryKey:e_.lists()}),I(!1),z(null)):o.oR.error(t?.message||l("Failed to delete model"))}catch(t){let e=t instanceof Error?t.message:void 0;o.oR.error(e||l("Failed to delete model"))}finally{$(!1)}},V=()=>{M.current?.abort(),M.current=null,s(!1)};return t?(0,a.jsxs)(tl.lG,{open:t,onOpenChange:V,children:[(0,a.jsxs)(tl.Cf,{className:"max-h-[90vh] overflow-hidden sm:max-w-3xl",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:l("Ollama Models")}),(0,a.jsxs)(tl.rr,{children:[l("Manage local models for:")," ",(0,a.jsx)("strong",{children:u?.name})]})]}),m?(0,a.jsxs)("div",{className:"max-h-[78vh] space-y-4 overflow-y-auto py-2 pr-1",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[(0,a.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,a.jsx)(tN.J,{htmlFor:"ollama-pull",children:l("Pull model")}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)(t_.p,{id:"ollama-pull",placeholder:l("e.g. llama3.1:8b"),value:N,onChange:e=>w(e.target.value),disabled:!h||k}),(0,a.jsx)(tr.$,{onClick:()=>void D(),disabled:!h||k,children:k?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),l("Pulling...")]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ta.f5X,{className:"mr-2 h-4 w-4"}),l("Pull")]})})]}),R&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"text-muted-foreground text-xs",children:[l("Status:")," ",String(R.status||"-")]}),(0,a.jsx)(ti.ke,{value:"number"==typeof R.completed&&"number"==typeof R.total&&R.total>0?Math.min(100,Math.round(R.completed/R.total*100)):0})]})]}),(0,a.jsx)("div",{className:"flex gap-2",children:(0,a.jsxs)(tr.$,{variant:"outline",onClick:()=>void B(),disabled:!h||p,children:[p?(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(ta.e9t,{className:"mr-2 h-4 w-4"}),l("Refresh")]})})]}),(0,a.jsx)(tV.w,{}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:l("Local models")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("Select models and apply to channel models list.")})]}),(0,a.jsxs)("div",{className:"relative sm:w-72",children:[(0,a.jsx)(ta.vji,{className:"text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"}),(0,a.jsx)(t_.p,{placeholder:l("Search models..."),value:v,onCh
1ange:e=>_(e.target.value),className:"pl-9"})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>{y(e=>{let t=new Set(e);return T.forEach(e=>t.add(e.id)),Array.from(t)})},children:l("Select all (filtered)")}),(0,a.jsx)(tr.$,{variant:"outline",size:"sm",onClick:()=>y([]),children:l("Clear selection")}),(0,a.jsx)(tr.$,{size:"sm",onClick:()=>void J("append"),disabled:!j.length,children:l("Append to channel")}),(0,a.jsx)(tr.$,{variant:"secondary",size:"sm",onClick:()=>void J("replace"),disabled:!j.length,children:l("Replace channel models")})]}),(0,a.jsx)("div",{className:"overflow-hidden rounded-md border",children:(0,a.jsx)("div",{className:"max-h-[420px] overflow-y-auto",children:0===T.length?(0,a.jsx)("div",{className:"text-muted-foreground p-6 text-center text-sm",children:l("No models found.")}):(0,a.jsx)("div",{className:"divide-y",children:T.map(e=>{let t=j.includes(e.id);return(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3 p-3",children:[(0,a.jsxs)("div",{className:"flex min-w-0 items-start gap-3",children:[(0,a.jsx)(tb.S,{checked:t,onCheckedChange:t=>{var s,a;return s=e.id,a=!!t,void y(e=>a?e.includes(s)?e:[...e,s]:e.filter(e=>e!==s))},"aria-label":`Select model ${e.id}`}),(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("div",{className:"truncate font-mono text-sm",children:e.id}),(0,a.jsxs)("div",{className:"text-muted-foreground flex flex-wrap gap-x-3 gap-y-1 text-xs",children:[(0,a.jsxs)("span",{children:[l("Size:")," ",function(e){if("number"!=typeof e||Number.isNaN(e))return"-";if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t.toFixed(1)} KB`;let s=t/1024;if(s<1024)return`${s.toFixed(1)} MB`;let a=s/1024;return`${a.toFixed(2)} GB`}(e.size)]}),e.digest&&(0,a.jsxs)("span",{className:"truncate",children:[l("Digest:")," ",String(e.digest)]})]})]})]}),(0,a.jsx)(tr.$,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>{z(e.id),I(!0)},disabled:!h,children:(0,a.jsx)(ta.TBR,{className:"h-4 w-4"})})]},e.id)})})})})]})]}):(0,a.jsx)("div",{className:"text-muted-foreground py-8 text-center",children:l("This channel is not an Ollama channel.")}),(0,a.jsx)(tl.Es,{children:(0,a.jsx)(tr.$,{variant:"outline",onClick:V,children:l("Close")})})]}),(0,a.jsx)(t1.Lt,{open:O,onOpenChange:e=>{I(e),e||z(null)},children:(0,a.jsxs)(t1.EO,{children:[(0,a.jsxs)(t1.wd,{children:[(0,a.jsx)(t1.r7,{children:l("Confirm delete")}),(0,a.jsx)(t1.$v,{children:l('Delete model "{{name}}"? This cannot be undone.',{name:F||""})})]}),(0,a.jsxs)(t1.ck,{children:[(0,a.jsx)(t1.Zr,{disabled:E,children:l("Cancel")}),(0,a.jsxs)(t1.Rx,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:E||!F,onClick:()=>{F&&q(F)},children:[E?(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}):null,l("Delete")]})]})]})})]}):null}var t7=s(77405),t9=s(18434),se=s(88584),st=s(81204);let ss='{ "duplicate_source_models": ';function sa(e){let t=new Set,s=new Set;for(let a of e){let e=a.from.trim();e&&(t.has(e)?s.add(e):t.add(e))}return Array.from(s)}function sr(e){let{t}=(0,r.Bd)(),s=(0,n.useId)(),l=(0,n.useId)(),[i,o]=(0,n.useState)("visual"),[d,c]=(0,n.useState)([]),[u,m]=(0,n.useState)(e.value),[h,p]=(0,n.useState)(null),x=(0,n.useRef)(0),g=(0,n.useMemo)(()=>sa(d),[d]),f=()=>(x.current+=1,`mapping-${x.current}`),j=e=>{try{if(!e.trim())return c([]),p(null),!0;let s=JSON.parse(e);if(!s||"object"!=typeof s||Array.isArray(s))return p(t("Model mapping must be a valid JSON object")),!1;let a=Object.entries(s);if(a.find(e=>{let[,t]=e;return"string"!=typeof t}))return p(t("Model mapping values must be strings")),!1;return c(e=>{let t=[...e];return a.map((s,a)=>{let[r,l]=s,n=String(l),i=t.findIndex(t=>t.from===r||t.from===r&&t.to===n||e[a]?.id===t.id);if(i>=0){let[e]=t.splice(i,1);return{id:e.id,from:r,to:n}}return{id:f(),from:r,to:n}})}),p(null),!0}catch(e){return p(t("Model mapping must be valid JSON format")),!1}};(0,n.useEffect)(()=>{m(e.value),j(e.value)},[e.value]);let y=e=>{if(0===e.length)return"";let t={};
1return e.forEach(e=>{e.from.trim()&&(t[e.from.trim()]=e.to.trim())}),JSON.stringify(t,null,2)},v=s=>{if(c(s),sa(s).length>0){p(t("Duplicate source model mappings are not allowed")),m(ss),e.onChange(ss);return}let a=y(s);p(null),m(a),e.onChange(a)},b=(e,t,s)=>{v(d.map(a=>a.id===e?{...a,[t]:s}:a))};return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)(tW.tU,{value:i,onValueChange:t=>{if("visual"===t||"json"===t){if("json"===t){if(0===sa(d).length){let t=y(d);m(t),e.onChange(t)}o("json");return}j(u),o("visual")}},className:"space-y-2",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,a.jsxs)(tW.j7,{children:[(0,a.jsxs)(tW.Xi,{value:"visual",children:[(0,a.jsx)(ta.XIK,{className:"h-4 w-4","aria-hidden":"true"}),t("Visual")]}),(0,a.jsxs)(tW.Xi,{value:"json",children:[(0,a.jsx)(ta.CyN,{className:"h-4 w-4","aria-hidden":"true"}),t("JSON")]})]}),(0,a.jsx)(tr.$,{type:"button",variant:"link",size:"sm",className:"h-auto p-0",onClick:()=>{let t=JSON.stringify({"gpt-3.5-turbo":"gpt-3.5-turbo-0125"},null,2);m(t),e.onChange(t),j(t)},disabled:e.disabled,children:t("Fill Template")})]}),h&&(0,a.jsx)(t7.Fc,{variant:"destructive",children:(0,a.jsx)(t7.TN,{children:h})}),g.length>0&&(0,a.jsx)(t7.Fc,{children:(0,a.jsx)(t7.TN,{children:t("Duplicate source model(s): {{models}}",{models:g.join(", ")})})}),(0,a.jsxs)(tW.av,{value:"visual",className:"space-y-2",children:[d.length>0?(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2 text-sm font-medium",children:[(0,a.jsx)("div",{children:t("Original Model")}),(0,a.jsx)("div",{children:t("Replacement Model")}),(0,a.jsx)("div",{className:"w-10"})]}),d.map(r=>(0,a.jsxs)("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2",children:[(0,a.jsx)(t_.p,{value:r.from,onChange:e=>b(r.id,"from",e.target.value),placeholder:"gpt-3.5-turbo",disabled:e.disabled,list:s}),(0,a.jsx)(t_.p,{value:r.to,onChange:e=>b(r.id,"to",e.target.value),placeholder:"gpt-3.5-turbo-0125",disabled:e.disabled,list:l}),(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"icon",onClick:()=>{var e;return e=r.id,void v(d.filter(t=>t.id!==e))},disabled:e.disabled,className:"h-10 w-10","aria-label":t("Delete mapping"),children:(0,a.jsx)(ta.TBR,{className:"h-4 w-4","aria-hidden":"true"})})]},r.id))]}):(0,a.jsx)("div",{className:"text-muted-foreground flex h-24 items-center justify-center rounded-md border border-dashed text-sm",children:t('No model mappings configured. Click "Add Mapping" to get started.')}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{v([...d,{id:f(),from:"",to:""}])},disabled:e.disabled,className:"w-full",children:[(0,a.jsx)(ta.FWt,{className:"mr-2 h-4 w-4"}),t("Add Mapping")]})]}),(0,a.jsx)(tW.av,{value:"json",children:(0,a.jsx)(tK.T,{value:u,onChange:t=>{var s;m(s=t.target.value),e.onChange(s),j(s)},placeholder:t('{"original-model": "replacement-model"}'),disabled:e.disabled,rows:8,className:(0,st.cn)("font-mono text-sm",h&&"border-destructive"),"aria-invalid":!!h})})]}),e.sourceModelOptions&&e.sourceModelOptions.length>0&&(0,a.jsx)("datalist",{id:s,children:e.sourceModelOptions.map(e=>(0,a.jsx)("option",{value:e},e))}),e.targetModelOptions&&e.targetModelOptions.length>0&&(0,a.jsx)("datalist",{id:l,children:e.targetModelOptions.map(e=>(0,a.jsx)("option",{value:e},e))})]})}function sl(e){let{open:t,onOpenChange:s}=e,{t:l}=(0,r.Bd)(),{currentTag:d}=ts(),c=(0,i.jE)(),[u,m]=(0,n.useState)(!1),[h,p]=(0,n.useState)(!1),[x,g]=(0,n.useState)(""),[f,j]=(0,n.useState)(""),[y,v]=(0,n.use
1State)(""),[b,_]=(0,n.useState)([]),{data:N,isLoading:w}=(0,tq.I)({queryKey:["groups"],queryFn:Z}),k=(0,n.useMemo)(()=>N?.data?Array.from(new Set([...N.data,...b])).map(e=>({value:e,label:e})):[],[N,b]);(0,n.useEffect)(()=>{t&&d&&C()},[t,d]);let C=async()=>{if(d){m(!0);try{let e=await U(d);e.success&&e.data&&j(e.data);let t=await Y();t.success&&t.data,g(d)}catch(e){o.oR.error(e instanceof Error?e.message:l("Failed to load tag data"))}finally{m(!1)}}},S=async()=>{if(d){if(y.trim())try{JSON.parse(y)}catch(e){o.oR.error(l("Model mapping must be valid JSON"));return}p(!0);try{let e={tag:d};if(x!==d&&(e.new_tag=x||void 0),f.trim()&&(e.models=f),y.trim()&&(e.model_mapping=y),b.length>0&&(e.groups=b.join(",")),1===Object.keys(e).length)return void o.oR.warning(l("No changes made"));let t=await H(e);t.success?(o.oR.success(l("Tag updated successfully")),c.invalidateQueries({queryKey:e_.lists()}),R()):o.oR.error(t.message||l("Failed to update tag"))}catch(e){o.oR.error(e instanceof Error?e.message:l("Failed to update tag"))}finally{p(!1)}}},R=()=>{g(""),j(""),v(""),_([]),s(!1)};return d?(0,a.jsx)(tl.lG,{open:t,onOpenChange:R,children:(0,a.jsxs)(tl.Cf,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:l("Batch Edit by Tag")}),(0,a.jsxs)(tl.rr,{children:[l("Edit all channels with tag:")," ",(0,a.jsx)("strong",{children:d})]})]}),u?(0,a.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,a.jsx)(ta.krw,{className:"text-muted-foreground h-8 w-8 animate-spin"})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"space-y-4 py-4",children:[(0,a.jsxs)(t7.Fc,{children:[(0,a.jsx)(ta.RIJ,{className:"h-4 w-4"}),(0,a.jsx)(t7.TN,{children:l("All edits are overwrite operations. Leave fields empty to keep current values unchanged.")})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tN.J,{htmlFor:"new-tag",children:l("Tag Name")}),(0,a.jsx)(t_.p,{id:"new-tag",placeholder:l("Enter new tag name (leave empty to disband tag)"),value:x,onChange:e=>g(e.target.value),disabled:h}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("Leave empty to disband the tag")})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tN.J,{htmlFor:"models",children:l("Models")}),(0,a.jsx)(tK.T,{id:"models",placeholder:l("Comma-separated model names (leave empty to keep current)"),value:f,onChange:e=>j(e.target.value),disabled:h,rows:3}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("Current models for the longest channel in this tag. May not include all models from all channels.")})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tN.J,{htmlFor:"model-mapping",children:l("Model Mapping")}),(0,a.jsx)(sr,{value:y,onChange:v,disabled:h})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(tN.J,{htmlFor:"groups",children:l("Groups")}),w?(0,a.jsx)(t9.E,{className:"h-10 w-full"}):(0,a.jsx)(se.K,{options:k,selected:b,onChange:_,placeholder:l("Select groups (leave empty to keep current)")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:l("User groups that can access channels with this tag")})]})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:R,disabled:h,children:l("Cancel")}),(0,a.jsxs)(tr.$,{onClick:S,disabled:h,children:[h&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),h?l("Saving..."):l("Save Changes")]})]})]})]})}):null}function sn(e){let{t}
1=(0,r.Bd)(),[s,l]=(0,n.useState)(e.preferredTab),[i,o]=(0,n.useState)(""),[d,c]=(0,n.useState)(""),[u,m]=(0,n.useState)(()=>new Set(e.addModels)),[h,p]=(0,n.useState)(()=>new Set(e.removeModels)),[x,g]=(0,n.useState)(!1),f=(0,n.useMemo)(()=>e.addModels.filter(e=>e.toLowerCase().includes(i.toLowerCase())),[e.addModels,i]),j=(0,n.useMemo)(()=>e.removeModels.filter(e=>e.toLowerCase().includes(d.toLowerCase())),[e.removeModels,d]),y=(e,t,s)=>{let a=new Set(t);a.has(e)?a.delete(e):a.add(e),s(a)},v=(e,t,s)=>{let a=e.every(e=>t.has(e)),r=new Set(t);a?e.forEach(e=>r.delete(e)):e.forEach(e=>r.add(e)),s(r)};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tl.lG,{open:e.open,onOpenChange:t=>!t&&e.onCancel(),children:(0,a.jsxs)(tl.Cf,{className:"sm:max-w-lg",children:[(0,a.jsx)(tl.c7,{children:(0,a.jsx)(tl.L3,{children:t("Upstream Model Updates")})}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:t('Select models to process. Unselected "add" models will be ignored.')}),(0,a.jsxs)(tW.tU,{value:s,onValueChange:e=>l(e),children:[(0,a.jsxs)(tW.j7,{className:"grid w-full grid-cols-2",children:[(0,a.jsxs)(tW.Xi,{value:"add",className:"gap-1",children:[t("Add Models"),(0,a.jsxs)(td.Wh,{variant:"neutral",className:"ml-1",copyable:!1,children:[u.size,"/",e.addModels.length]})]}),(0,a.jsxs)(tW.Xi,{value:"remove",className:"gap-1",children:[t("Remove Models"),(0,a.jsxs)(td.Wh,{variant:"neutral",className:"ml-1",copyable:!1,children:[h.size,"/",e.removeModels.length]})]})]}),(0,a.jsxs)(tW.av,{value:"add",className:"space-y-3",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(ta.vji,{className:"text-muted-foreground absolute top-2.5 left-2.5 h-4 w-4"}),(0,a.jsx)(t_.p,{placeholder:t("Search models..."),className:"pl-8",value:i,onChange:e=>o(e.target.value)})]}),f.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(tb.S,{checked:f.every(e=>u.has(e)),onCheckedChange:()=>v(f,u,m)}),(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Select All Visible")})]}),(0,a.jsx)(to.F,{className:"h-[280px] rounded-md border p-2",children:f.length>0?(0,a.jsx)("div",{className:"space-y-1",children:f.map(e=>(0,a.jsxs)("label",{className:"hover:bg-accent flex cursor-pointer items-center gap-2 rounded px-2 py-1.5",children:[(0,a.jsx)(tb.S,{checked:u.has(e),onCheckedChange:()=>y(e,u,m)}),(0,a.jsx)("span",{className:"truncate text-sm",children:e})]},e))}):(0,a.jsx)("p",{className:"text-muted-foreground py-8 text-center text-sm",children:t(0===e.addModels.length?"No models to add":"No matching results")})})]}),(0,a.jsxs)(tW.av,{value:"remove",className:"space-y-3",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(ta.vji,{className:"text-muted-foreground absolute top-2.5 left-2.5 h-4 w-4"}),(0,a.jsx)(t_.p,{placeholder:t("Search models..."),className:"pl-8",value:d,onChange:e=>c(e.target.value)})]}),j.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(tb.S,{checked:j.every(e=>h.has(e)),onCheckedChange:()=>v(j,h,p)}),(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Select All Visible")})]}),(0,a.jsx)(to.F,{className:"h-[280px] rounded-md border p-2",children:j.length>0?(0,a.jsx)("div",{className:"space-y-1",children:j.map(e=>(0,a.jsxs)("label",{className:"hover:bg-accent flex cursor-pointer items-center gap-2 rounded px-2 py-1.5",children:[(0,a.jsx)(tb.S,{checked:h.has(e),onCheckedChange:()=>y(e,h,p)}),(0,a.jsx)("span",{className:"truncate text-sm",children:e})]},e))}):(0,a.jsx)("p",{className:"text-muted-foreground py-8 text-center text-sm",children:t(0===e.removeModels.length?"No models to remove":"No matching results")})})]})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:e.onCancel,children:t("Cancel")}),(0,a.jsx)(tr.$,{onClick:()=>{let t=e.addModels.length>0,s=e.removeModels.length>0,a=Array.from(u),r=Array.from(h),l=a.length>0,n=r.length>0;t&&s&&l!==n?g(!0):e.onConfirm({addModels:a,removeModels:r})},disabled:e.confirmLoading||0===e.addModels.length&&0===e.removeModels.length,children:t("Confirm")})]})]})}),(0,a.jsx)(tX.T,{open:x,onOpenChange:g,title:t("Partial Submission"),desc:t("There are both add and remove models pending, but you only selected one type. Confirm submitting only the selected items?"),handleConfirm:()=>{g(!1),e.onConfirm({addModels:Array.from(u),removeModels:Array.from(h)})}})]})}var si=s(86832),so=s(48367),sd=s(38417),sc=s(63742),su=s(10726),sm=s(97077),sh=s(34434),sp=s(54369),sx=s(89806);async function sg(){try{let[e,t,s]=await Promise.all([(0,d.sv)(),(0,sx.pF)(),(0,sp.TA)()]),a=!!e?.success&&!!e?.data?.enabled,r=!!t?.success&&!!t?.data?.enabled;return{has2FA:a,hasPasskey:r,passkeySupported:s}}catch(e){return console.error("[Secure Verification] Failed to check methods",e),{has2FA:!1,hasPasskey:!1,passkeySupported:!1}}}async function sf(e,t){switch(e){case"2fa":return sj(t);case"passkey":return sy();default:throw Error(`Unsupported verification method: ${e}`)}}async function sj(e){let t=e?.trim();if(!t)throw Error("Please enter the verification code or backup code");let s=await d.FH.post("/api/verify",{method:"2fa",code:t});if(!s.data?.success)throw Error(s.data?.message||"Verification failed")}async function sy(){if("u"<typeof navigator||!navigator.credentials)throw Error("Passkey verification is not supported in this environment");try{let e=await (0,sx.lW)();if(!e.success)throw Error(e.message||"Failed to start verification");let t=(0,sp.ig)(e.data?.options??e.data),s=await navigator.credentials.get({publicKey:t});if(!s)throw Error("Passkey verification was cancelled");let a=(0,sp.Il)(s);if(!a)throw Error("Unable to build Passkey assertion");let r=await (0,sx.Rk)(a);if(!r.success)throw Error(r.message||"Passkey verification failed");let l=await d.FH.post("/api/verify",{method:"passkey"});if(!l.data?.success)throw Error(l.data?.message||"Failed to complete verification")}catch(e){if(e instanceof DOMException&&"NotAllowedError"===e.name)throw Error("Passkey verification was cancelled or timed out",{cause:e});if(e instanceof DOMException&&"InvalidStateError"===e.name)throw Error("Passkey verification is not available in the current state",{cause:e});throw e}}let sv={has2FA:!1,hasPasskey:!1,passkeySupported:!1},sb={method:null,loading:!1,code:"",title:void 0,description:void 0,apiCall:null};function s_(e){let{open:t,onOpenChange:s,methods:l,state:i,onVerify:o,onCancel:d,onCodeChange:c,onMethodChange:u}=e,{t:m}=(0,r.Bd)(),h=(0,n.useMemo)(()=>{let e=[];return l.has2FA&&e.push("2fa"),l.hasPasskey&&l.passkeySupported&&e.push("passkey"),e},[l]),p=i.method??(h.length>0?h[0]:null),x=i.title??(h.length?"Additional verification required":"Verification unavailable"),g=i.description??(h.length?"Confirm your identity before accessing this sensitive action.":"Enable Two-factor Authentication or Passkey in your profile settings to continue."),f=()=>{if(!p)return;let e="2fa"===p?i.code:void 0;o(p,e)},j=i.loading||"2fa"===p&&(!i.code.trim()||i.code.length<6);return(0,a.jsx)(tl.lG,{open:t,onOpenChange:s,children:(0,a.jsx)(tl.Cf,{className:"top-[8vh] max-w-[calc(100%-1.5rem)] translate-y-0 gap-0 overflow-hidden border-none p-0 shadow-xl sm:top-1/2 sm:max-w-md
1sm:translate-y-[-50%] sm:rounded-xl",showCloseButton:!i.loading,children:(0,a.jsxs)("div",{className:"bg-background flex max-h-[calc(100dvh-2rem)] flex-col",children:[(0,a.jsxs)(tl.c7,{className:"border-b px-6 py-5 text-left",children:[(0,a.jsxs)(tl.L3,{className:"flex items-center gap-2 text-lg font-semibold",children:[(0,a.jsx)(ta.oxo,{className:"text-primary h-5 w-5"}),x]}),(0,a.jsx)(tl.rr,{className:"text-left",children:g})]}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:0===h.length?(0,a.jsxs)("div",{className:"grid place-items-center gap-4 text-center",children:[(0,a.jsx)("div",{className:"bg-muted flex h-16 w-16 items-center justify-center rounded-2xl",children:(0,a.jsx)(ta.oxo,{className:"text-muted-foreground h-8 w-8"})}),(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:m("Enable Two-factor Authentication or Passkey in your profile to unlock sensitive operations.")})]}):(0,a.jsxs)(tW.tU,{value:p??h[0],onValueChange:e=>u(e),className:"gap-4",children:[(0,a.jsxs)(tW.j7,{children:[l.has2FA&&(0,a.jsx)(tW.Xi,{value:"2fa",children:m("Authenticator code")}),l.hasPasskey&&l.passkeySupported&&(0,a.jsx)(tW.Xi,{value:"passkey",children:m("Passkey")})]}),(0,a.jsxs)(tW.av,{value:"2fa",className:"space-y-3",children:[(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:m("Enter the 6-digit Time-based One-Time Password or 8-character backup code from your authenticator app.")}),(0,a.jsx)(t_.p,{inputMode:"numeric",maxLength:8,value:i.code,onChange:e=>c(e.target.value),placeholder:m("Enter verification code"),disabled:i.loading,autoFocus:"2fa"===p,onKeyDown:e=>{"Enter"!==e.key||j||(e.preventDefault(),f())}})]}),(0,a.jsxs)(tW.av,{value:"passkey",className:"space-y-4",children:[(0,a.jsx)("div",{className:"bg-muted/50 flex items-center justify-center rounded-lg p-4",children:(0,a.jsxs)("div",{className:"text-muted-foreground flex items-center gap-3",children:[(0,a.jsx)(ta.kVM,{className:"text-primary h-6 w-6"}),(0,a.jsxs)("div",{className:"text-left text-sm",children:[(0,a.jsx)("p",{className:"text-foreground font-medium",children:m("Use your Passkey")}),(0,a.jsx)("p",{children:m("We will prompt your device to confirm using biometrics or your hardware key.")})]})]})}),!l.passkeySupported&&(0,a.jsx)("p",{className:"text-destructive text-sm",children:m("This device does not support Passkey verification.")})]})]})}),(0,a.jsxs)(tl.Es,{className:"bg-muted/30 border-t px-6 py-4 sm:flex-row sm:justify-end",children:[(0,a.jsx)(tr.$,{type:"button",variant:"outline",disabled:i.loading,onClick:d,children:m("Cancel")}),(0,a.jsxs)(tr.$,{type:"button",onClick:f,disabled:0===h.length||j,children:[i.loading&&(0,a.jsx)(ta.krw,{className:"h-4 w-4 animate-spin"}),m("Verify")]})]})]})})})}var sN=s(55667);function sw(e){return"object"==typeof e&&null!==e}let sk=new Set([504,524]);function sC(e){let t=e.trim();return/^[1-5]\d{2}$/.test(t)?Number.parseInt(t,10):null}function sS(e){if("number"==typeof e&&Number.isInteger(e))return e>=100&&e<=599?e:null;if("string"==typeof e){let t=e.trim();if(!/^[1-5]\d{2}$/.test(t))return null;let s=Number.parseInt(t,10);return s>=100&&s<=599?s:null}return null}function sR(e){let t;if(!e?.trim())return[];try{t=JSON.parse(e)}catch{return[]}if(!t||"object"!=typeof t||Array.isArray(t))return[];let s=[];for(let[e,a]of Object.entries(t)){let t=sC(e),r=sS(a);null!==t&&null!==r&&sk.has(t)&&t!==r&&s.push(`${t} -> ${r}`)}return[...new Set(s)].sort()}function sA(e){let{open:t,onOpenChange:s,onKeyGenerated:l}=e,{t:i}=(0,r.Bd)(),{copiedText:d,copyToClipboard:c}=(0,tn.C)({notify:!1}),[u,m]=(0,n.useState)({authorizeUrl:"",callbackUrl:"",isStarting:!1,isCompleting:!1});(0,n.useEffect)(()=>{t||m({authorizeUrl:"",callbackUrl:"",isStarting:!1,isCompleting:!1})},[t]);let h=!!(u.authorizeUrl&&!u.isStarting),p=(0,n.useMemo)(()=>!!u.callbackUrl.trim()&&!u.isCompleting,[u.callbackUrl,u.isCompleting]),x=async()=>{m(e=>({...e,isStarting:!0}));try{let e=await I();if(!e.success)throw Error(e.message||"Failed to start OAuth");let t=e.data?.authorize_url||"";if(!t)throw Error("Missing authorize_url in response");m(e=>({...e,authorizeUrl:t}));try{window.open(t,"_blank","noopener,noreferrer"),o.oR.success(i("Opened authorization page"))}catch(e){console.warn("Failed to open authorization page:",e),o.oR.warning(i("Please manually copy and open the authorization link"))}}catch(e){o.oR.error(e instanceof Error?e.message:i("OAuth start failed"))}finally{m(e=>({...e,isStarting:!1}))}},g=async()=>
1{if(u.callbackUrl.trim()){m(e=>({...e,isCompleting:!0}));try{let e=await F(u.callbackUrl.trim());if(!e.success)throw Error(e.message||"OAuth failed");let t=e.data?.key||"";if(!t)throw Error("Missing key in response");l((0,st.e0)(t)),o.oR.success(i("Credential generated")),s(!1)}catch(e){o.oR.error(e instanceof Error?e.message:i("OAuth failed"))}finally{m(e=>({...e,isCompleting:!1}))}}};return(0,a.jsx)(tl.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(tl.Cf,{className:"sm:max-w-2xl",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:i("Codex Authorization")}),(0,a.jsx)(tl.rr,{children:i("Generate a Codex OAuth credential and paste it into the channel key field.")})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(t7.Fc,{children:(0,a.jsx)(t7.TN,{children:i('1) Click "Open authorization page" and complete login. 2) Your browser may redirect to localhost (it is OK if the page does not load). 3) Copy the full URL from the address bar and paste it below. 4) Click "Generate credential".')})}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsxs)(tr.$,{onClick:x,disabled:u.isStarting,children:[u.isStarting?(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(ta.GrD,{className:"mr-2 h-4 w-4"}),i("Open authorization page")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",disabled:!h,onClick:async()=>{u.authorizeUrl&&await c(u.authorizeUrl)},"aria-label":i("Copy authorization link"),title:i("Copy authorization link"),children:[d===u.authorizeUrl?(0,a.jsx)(ta.Jlk,{className:"mr-2 h-4 w-4 text-green-600"}):(0,a.jsx)(ta.QRo,{className:"mr-2 h-4 w-4"}),i("Copy authorization link")]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("div",{className:"text-sm font-medium",children:i("Callback URL")}),(0,a.jsx)(t_.p,{value:u.callbackUrl,onChange:e=>m(t=>({...t,callbackUrl:e.target.value})),placeholder:i("Paste the full callback URL (includes code & state)"),autoComplete:"off",spellCheck:!1}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:i("Tip: The generated key is a JSON credential including access_token / refresh_token / account_id.")})]})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{type:"button",variant:"outline",onClick:()=>s(!1),disabled:u.isStarting||u.isCompleting,children:i("Cancel")}),(0,a.jsxs)(tr.$,{onClick:g,disabled:!p,children:[u.isCompleting&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),u.isCompleting?i("Generating..."):i("Generate credential")]})]})]})})}function sM(e){let{open:t,missingModels:s,onConfirm:l,onOpenChange:n}=e,{t:i}=(0,r.Bd)();return(0,a.jsx)(t1.Lt,{open:t,onOpenChange:e=>{e||l("cancel"),n?.(e)},children:(0,a.jsxs)(t1.EO,{children:[(0,a.jsxs)(t1.wd,{children:[(0,a.jsx)(t1.r7,{children:i("Models not in list, may fail to invoke")}),(0,a.jsxs)(t1.$v,{render:(0,a.jsx)("div",{className:"space-y-3 text-sm"}),children:[(0,a.jsx)("div",{children:i('The following models in the model redirect have not been added to the "Models" list and may fail during invocation due to missing available models:')}),(0,a.jsx)("div",{className:"rounded-md bg-red-50 p-2 font-mono text-xs break-all text-red-600 dark:bg-red-950/50 dark:text-red-400",children:s.join(", ")}),(0,a.jsx)("div",{children:i('You can manually add them in "Custom Model Names", click "Fill" and then submit, or use the operations below to handle automatically.')})]})]}),(0,a.jsxs)(t1.ck,{className:"flex-col gap-2 sm:flex-row",children:[(0,a.jsx)(t1.Zr,{onClick:()=>l("cancel"),children:i("Go back and edit")}),(0,a.jsx)(tr.$,{variant:"secondary",onClick:()=>l("submit"),children:i("Submit directly")}),(0,a.jsx)(t1.Rx,{onClick:()=>l("add"),children:i("Add and submit")})]})]})})}let sO=[{label:"Set Field",value:"set"},{label:"Delete Field",value:"delete"},{label:"Append to End",value:"append"},{label:"Prepend to Start",value:"prepend"},{label:"Copy Field",value:"copy"},{label:"Move Field",value:"move"},{label:"String Replace",value:"replace"},{label:"Regex Replace",value:"regex_replace"},{label:"Trim Prefix",value:"trim_prefix"},{label:"Trim Suffix",value:"trim_suffix"},{label:"Ensure Prefix",value:"ensure_prefix"},{label:"Ensure Suffix",value:"ensure_suffix"},{label:"Trim Space",value:"trim_space"},{label:"To Lowercase",value:"to_lower"},{label:"To Uppercase",value:"to_upper"},{label:"Return Custom Error",value:"return_error"},{label:"Prune Object Items",value:"prune_objects"},{label:"Pass Through Headers",value:"pass_headers"},{label:"Sync Fields",value:"sync_fields"},{label:"Set Request Header",value:"set_header"},{label:"Delete Request Header",value:"delete_header"},{label:"Copy Request Header",value:"copy_header"},{label:"Move Request Header",value:"move_header"}],sI=new Set(sO.map(e=>e.value)),sF=sO.reduce((e,t)=>
1(e[t.value]=t.label,e),{}),sz=[{label:"Exact Match",value:"full"},{label:"Prefix",value:"prefix"},{label:"Suffix",value:"suffix"},{label:"Contains",value:"contains"},{label:"Greater Than",value:"gt"},{label:"Greater Than or Equal",value:"gte"},{label:"Less Than",value:"lt"},{label:"Less Than or Equal",value:"lte"}],sE=new Set(sz.map(e=>e.value)),s$={delete:{path:!0},set:{path:!0,value:!0,keepOrigin:!0},append:{path:!0,value:!0,keepOrigin:!0},prepend:{path:!0,value:!0,keepOrigin:!0},copy:{from:!0,to:!0},move:{from:!0,to:!0},replace:{path:!0,from:!0,to:!1},regex_replace:{path:!0,from:!0,to:!1},trim_prefix:{path:!0,value:!0},trim_suffix:{path:!0,value:!0},ensure_prefix:{path:!0,value:!0},ensure_suffix:{path:!0,value:!0},trim_space:{path:!0},to_lower:{path:!0},to_upper:{path:!0},return_error:{value:!0},prune_objects:{pathOptional:!0,value:!0},pass_headers:{value:!0,keepOrigin:!0},sync_fields:{from:!0,to:!0},set_header:{path:!0,value:!0,keepOrigin:!0},delete_header:{path:!0},copy_header:{from:!0,to:!0,keepOrigin:!0,pathAlias:!0},move_header:{from:!0,to:!0,keepOrigin:!0,pathAlias:!0}},sT=new Set(["trim_prefix","trim_suffix","ensure_prefix","ensure_suffix","set_header","return_error","prune_objects","pass_headers"]),sP=new Set(["copy","move","replace","regex_replace","copy_header","move_header","sync_fields"]),sB=new Set(["copy","move","copy_header","move_header","sync_fields"]),sJ={set:"Write value to the target field",delete:"Remove the target field",append:"Append value to array / string / object end",prepend:"Prepend value to array / string / object start",copy:"Copy source field to target field",move:"Move source field to target field",replace:"Do string replacement in the target field",regex_replace:"Do regex replacement in the target field",trim_prefix:"Remove string prefix",trim_suffix:"Remove string suffix",ensure_prefix:"Ensure the string has a specified prefix",ensure_suffix:"Ensure the string has a specified suffix",trim_space:"Trim leading/trailing whitespace",to_lower:"Convert string to lowercase",to_upper:"Convert string to uppercase",return_error:"Return a custom error immediately",prune_objects:"Prune object items by conditions",pass_headers:"Pass specified request headers to upstream",sync_fields:"Auto-fill when one field exists and another is missing",set_header:"Set runtime request header: override entire value, or manipulate comma-separated tokens",delete_header:"Delete a runtime request header",copy_header:"Copy a request header",move_header:"Move a request header"},sD=[{label:"Request Body Field",value:"json"},{label:"Request Header Field",value:"header"}],sq={temperature:0,max_tokens:1e3},sV={operations:[{description:"Set default temperature for openai/* models.",path:"temperature",mode:"set",value:.7,conditions:[{path:"model",mode:"prefix",value:"openai/"}],logic:"AND"}]},sK=e=>({operations:[{mode:"pass_headers",value:[...e],keep_origin:!0}]}),sL=sK(["Originator","Session_id","User-Agent","X-Codex-Beta-Features","X-Codex-Turn-Metadata"]),sH={operations_default:{label:"New Format Template",kind:"operations",payload:sV},legacy_default:{label:"Legacy Format Template",kind:"legacy",payload:sq},pass_headers_auth:{label:"Header Passthrough (X-Request-Id)",kind:"operations",payload:{operations:[{description:"Pass through X-Request-Id header to upstream.",mode:"pass_headers",value:["X-Request-Id"],keep_origin:!0}]}},gemini_image_4k:{label:"Gemini Image 4K",kind:"operations",payload:{operations:[{description:"Set imageSize to 4K when model contains gemini/image and ends with 4k.",mode:"set",path:"generationConfig.imageConfig.imageSize",value:"4K",conditions:[{path:"original_model",mode:"contains",value:"gemini"},{path:"original_model",mode:"contains",value:"image"},{path:"original_model",mode:"suffix",value:"4k"}],logic:"AND"}]}},claude_cli_headers_passthrough:{label:"Claude CLI Header Passthrough",kind:"operations",payload:sK(["X-Stainless-Arch","X-Stainless-Lang","X-Stainless-Os","X-Stainless-Package-Version","X-Stainless-Retry-Count","X-Stainless-Runtime","X-Stainless-Runtime-Version","X-Stainless-Timeout","User-Agent","X-App","Anthropic-Beta","Anthropic-Dangerous-Direct-Browser-Access","Anthropic-Version"])},codex_cli_headers_passthrough:{label:"Codex CLI Header Passthrough",kind:"operations",payload:sL},aws_bedrock_anthropic_beta_override:{label:"AWS Bedrock Claude Compat",kind:"operations",payload:{operations:[{description:"Normalize anthropic-beta header tokens for Bedrock compatibility.",mode:"set_header",path:"anthropic-beta",value:{"advanced-tool-use-2025-11-20":"tool-search-tool-2025-10-19",bash_20241022:null,bas
1h_20250124:null,"code-execution-2025-08-25":null,"compact-2026-01-12":"compact-2026-01-12","computer-use-2025-01-24":"computer-use-2025-01-24","computer-use-2025-11-24":"computer-use-2025-11-24","context-1m-2025-08-07":"context-1m-2025-08-07","context-management-2025-06-27":"context-management-2025-06-27","effort-2025-11-24":null,"fast-mode-2026-02-01":null,"files-api-2025-04-14":null,"fine-grained-tool-streaming-2025-05-14":null,"interleaved-thinking-2025-05-14":"interleaved-thinking-2025-05-14","mcp-client-2025-11-20":null,"mcp-client-2025-04-04":null,"mcp-servers-2025-12-04":null,"output-128k-2025-02-19":null,"structured-output-2024-03-01":null,"prompt-caching-scope-2026-01-05":null,"skills-2025-10-02":null,"structured-outputs-2025-11-13":null,text_editor_20241022:null,text_editor_20250124:null,"token-efficient-tools-2025-02-19":null,"tool-search-tool-2025-10-19":"tool-search-tool-2025-10-19","web-fetch-2025-09-10":null,"web-search-2025-03-05":null,"oauth-2025-04-20":null}},{description:"Remove all tools[*].custom.input_examples before upstream relay.",mode:"delete",path:"tools.*.custom.input_examples"}]}}},sU=0,sW=()=>`po_${Date.now()}_${sU++}`,sQ=e=>{if(void 0===e)return"";if("string"==typeof e)return e;try{return JSON.stringify(e)}catch{return String(e)}},sG=e=>{let t=String(e??"").trim();if(""===t)return"";try{return JSON.parse(t)}catch{return t}},sX=e=>{try{return JSON.parse(e),!0}catch{return!1}},sY=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{id:sW(),path:"string"==typeof e.path?e.path:"",mode:sE.has(e.mode)?e.mode:"full",value_text:sQ(e.value),invert:!0===e.invert,pass_missing_key:!0===e.pass_missing_key}},sZ=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{id:sW(),description:"string"==typeof e.description?e.description:"",path:"str
1ing"==typeof e.path?e.path:"",mode:sI.has(e.mode)?e.mode:"set",value_text:sQ(e.value),keep_origin:!0===e.keep_origin,from:"string"==typeof e.from?e.from:"",to:"string"==typeof e.to?e.to:"",logic:"AND"===String(e.logic||"OR").toUpperCase()?"AND":"OR",conditions:Array.isArray(e.conditions)?e.conditions.map(sY):[]}},s0=()=>sZ({mode:"set"}),s1=function(e,t,s){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"before";if(!t||!s||t===s)return e;let r=e.findIndex(e=>e.id===t);if(r<0)return e;let l=[...e],[n]=l.splice(r,1),i=l.findIndex(e=>e.id===s);return i<0?e:("after"===a&&(i+=1),l.splice(i,0,n),l)},s2=e=>{let t=e.conditions.some(e=>e.path.trim()||e.value_text.trim()||"full"!==e.mode||e.invert||e.pass_missing_key);return"set"===e.mode&&!e.path.trim()&&!e.from.trim()&&!e.to.trim()&&""===e.value_text.trim()&&!e.keep_origin&&!t},s4=(e,t)=>{let s=e.mode||"set",a=sF[s]||s;if("sync_fields"===s){let s=e.from.trim(),r=e.to.trim();return`${t+1}. ${a} \xb7 ${s||r||"-"}`}let r=e.path.trim(),l=e.from.trim(),n=e.to.trim();return`${t+1}. ${a} \xb7 ${r||l||n||"-"}`},s3=e=>e.includes("header")?"bg-cyan-500/15 text-cyan-700 dark:text-cyan-300 border-cyan-500/20":e.includes("replace")||e.includes("trim")?"bg-violet-500/15 text-violet-700 dark:text-violet-300 border-violet-500/20":e.includes("copy")||e.includes("move")?"bg-blue-500/15 text-blue-700 dark:text-blue-300 border-blue-500/20":e.includes("error")||e.includes("prune")?"bg-red-500/15 text-red-700 dark:text-red-300 border-red-500/20":e.includes("sync")?"bg-green-500/15 text-green-700 dark:text-green-300 border-green-500/20":"bg-muted text-muted-foreground",s5=e=>{let t=String(e??"").trim();if(!t)return{type:"json",key:""};let s=t.indexOf(":");if(s<0)return{type:"json",key:t};let a=t.slice(0,s).trim().toLowerCase(),r=t.slice(s+1).trim();return"header"===a?{type:"header",key:r}:{type:"json",key:r}},s6=(e,t)=>{let s=String(t??"").trim();return s?`${"header"===e?"header":"json"}:${s}`:""},s8=e=>{let t={message:"",statusCode:400,code:"",type:"",skipRetry:!0,simpleMode:!0},s=String(e??"").trim();if(!s)return t;try{let e=JSON.parse(s);if(e&&"object"==typeof e&&!Array.isArray(e)){let s=void 0!==e.status_code?e.status_code:e.status,a=Number(s);return{...t,message:String(e.message||e.msg||"").trim(),statusCode:Number.isInteger(a)&&a>=100&&a<=599?a:400,code:String(e.code||"").trim(),type:String(e.type||"").trim(),skipRetry:!1!==e.skip_retry,simpleMode:!1}}}catch{}return{...t,message:s,simpleMode:!0}},s7=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{id:sW(),path:"string"==typeof e.path?e.path:"",mode:sE.has(e.mode)?e.mode:"full",value_text:sQ(e.value),invert:!0===e.invert,pass_missing_key:!0===e.pass_missing_key}},s9=e=>{let t={simpleMode:!0,typeText:"",logic:"AND",recursive:!0,rules:[]},s=String(e??"").trim();if(!s)return t;try{let e=JSON.parse(s);if("string"==typeof e)return{...t,typeText:e.trim()};if(e&&"object"==typeof e&&!Array.isArray(e)){let s=[];if(e.where&&"object"==typeof e.where&&!Array.isArray(e.where))for(let[t,a]of Object.entries(e.where))s.push(s7({path:t,mode:"full",value:a}));if(Array.isArray(e.conditions))for(let t of e.conditions)t&&"object"==typeof t&&s.push(s7(t));else if(e.conditions&&"object"==typeof e.conditions&&!Array.isArray(e.conditions))for(let[t,a]of Object.entries(e.conditions))s.push(s7({path:t,mode:"full",value:a}));let a=void 0===e.type?"":String(e.type).trim(),r="OR"===String(e.logic||"AND").toUpperCase()?"OR":"AND",l=!1!==e.recursive,n=void 0!==e.logic||void 0!==e.recursive||void 0!==e.where||void 0!==e.conditions;return{...t,simpleMode:!n,typeText:a,logic:r,recursive:l,rules:s}}return{...t,typeText:String(e??"").trim()}}catch{return{...t,typeText:s}}},ae=e=>{if(Array.isArray(e))return e.map(e=>String(e??"").trim()).filter(Boolean);if(e&&"object"==typeof e){if(Array.isArray(e.headers))return e.headers.map(e=>String(e??"").trim()).filter(Boolean);if(void 0!==e.header){let t=String(e.header??"").trim();return t?[t]:[]}return[]}return"string"==typeof e?e.split(",").map(e=>e.trim()).filter(Boolean):[]},at=e=>{let t=e.path.trim();if(!t)return null;let s={path:t,mode:e.mode||"full",value:sG(e.value_text)};return e.invert&&(s.invert=!0),e.pass_missing_key&&(s.pass_missing_key=!0),s},as=(e,t,s)=>{let a=e.filter(e=>!s2(e));if(0===a.length)return"";if(t.validate){let e=((e,t)=>{for(let s=0;s<e.length;
1s++){let a=e[s],r=a.mode||"set",l=s$[r]||s$.set,n=s+1,i=a.path.trim(),o=a.from.trim(),d=a.to.trim();if(l.path&&!i)return t("Rule {{line}} is missing target path",{line:n});if(sP.has(r)&&!o&&!(l.pathAlias&&i))return t("Rule {{line}} is missing source field",{line:n});if(sB.has(r)&&!d&&!(l.pathAlias&&i))return t("Rule {{line}} is missing target field",{line:n});if(sT.has(r)&&""===a.value_text.trim())return t("Rule {{line}} is missing value",{line:n});if("return_error"===r){let e=a.value_text.trim();if(!e)return t("Rule {{line}} is missing value",{line:n});try{let s=JSON.parse(e);if(s&&"object"==typeof s&&!Array.isArray(s)&&!String(s.message||"").trim())return t("Rule {{line}} return_error requires a message field",{line:n})}catch{}}if("prune_objects"===r&&!a.value_text.trim())return t("Rule {{line}} prune_objects is missing conditions",{line:n});if("pass_headers"===r){let e=a.value_text.trim();if(!e)return t("Rule {{line}} pass_headers is missing header names",{line:n});if(0===ae(sG(e)).length)return t("Rule {{line}} pass_headers format is invalid",{line:n})}}return""})(a,s);if(e)throw Error(e)}return JSON.stringify({operations:a.map(e=>{let t=e.mode||"set",s=s$[t]||s$.set,a=String(e.description||"").trim(),r=e.path.trim(),l=e.from.trim(),n=e.to.trim(),i={mode:t};a&&(i.description=a),s.path&&(i.path=r),s.pathOptional&&r&&(i.path=r),s.value&&(i.value=sG(e.value_text)),s.keepOrigin&&e.keep_origin&&(i.keep_origin=!0),s.from&&(i.from=l),!s.to&&e.to.trim()&&(i.to=n),s.to&&(i.to=n),s.pathAlias&&(!i.from&&r&&(i.from=r),!i.to&&r&&(i.to=r));let o=e.conditions.map(at).filter(Boolean);return o.length>0&&(i.conditions=o,i.logic="AND"===e.logic?"AND":"OR"),i})},null,2)};function aa(e){let{t}
1=(0,r.Bd)(),[s,l]=(0,n.useState)("visual"),[i,d]=(0,n.useState)("operations"),[c,u]=(0,n.useState)(""),[m,h]=(0,n.useState)([s0()]),[p,x]=(0,n.useState)(""),[g,f]=(0,n.useState)(""),[j,y]=(0,n.useState)(""),[v,b]=(0,n.useState)(""),[_,N]=(0,n.useState)({}),[w,k]=(0,n.useState)(""),[C,S]=(0,n.useState)(""),[R,A]=(0,n.useState)("before"),[M,O]=(0,n.useState)("operations_default");(0,n.useEffect)(()=>{if(!e.open)return;let t=(e=>{let t="string"==typeof e?e:"",s=t.trim();if(!s)return{editMode:"visual",visualMode:"operations",legacyValue:"",operations:[s0()],jsonText:"",jsonError:""};if(!sX(s))return{editMode:"json",visualMode:"operations",legacyValue:"",operations:[s0()],jsonText:t,jsonError:"Invalid JSON format"};let a=JSON.parse(s),r=JSON.stringify(a,null,2);return a&&"object"==typeof a&&!Array.isArray(a)&&Array.isArray(a.operations)?{editMode:"visual",visualMode:"operations",legacyValue:"",operations:a.operations.length>0?a.operations.map(sZ):[s0()],jsonText:r,jsonError:""}:a&&"object"==typeof a&&!Array.isArray(a)?{editMode:"visual",visualMode:"legacy",legacyValue:r,operations:[s0()],jsonText:r,jsonError:""}:{editMode:"json",visualMode:"operations",legacyValue:"",operations:[s0()],jsonText:r,jsonError:""}})(e.value);l(t.editMode),d(t.visualMode),u(t.legacyValue),h(t.operations),x(t.jsonText),f(t.jsonError),y(""),b(t.operations[0]?.id||""),N({}),k(""),S(""),A("before"),"legacy"===t.visualMode?O("legacy_default"):O("operations_default")},[e.open,e.value]),(0,n.useEffect)(()=>{0===m.length?b(""):m.some(e=>e.id===v)||b(m[0].id)},[m,v]);let I=(0,n.useMemo)(()=>Object.entries(sH).map(e=>{let[t,s]=e;return{value:t,label:s.label}}),[]),F=(0,n.useMemo)(()=>m.filter(e=>!s2(e)).length,[m]),z=(0,n.useMemo)(()=>{let e=j.trim().toLowerCase();return e?m.filter(t=>[t.description,t.mode,t.path,t.from,t.to,t.value_text].filter(Boolean).join(" ").toLowerCase().includes(e)):m},[j,m]),E=(0,n.useMemo)(()=>m.find(e=>e.id===v),[m,v]),$=(0,n.useMemo)(()=>m.findIndex(e=>e.id===v),[m,v]),T=(0,n.useMemo)(()=>E&&"return_error"===E.mode?s8(E.value_text):null,[E]),P=(0,n.useMemo)(()=>E&&"prune_objects"===E.mode?s9(E.value_text):null,[E]),B=(0,n.useMemo)(()=>{let e={};for(let t of m){let s=t.mode||"set";e[s]=(e[s]||0)+1}return Object.entries(e).sort((e,t)=>t[1]-e[1]).slice(0,4)},[m]),J=(0,n.useCallback)((e,t)=>{h(s=>s.map(s=>s.id===e?{...s,...t}:s))},[]),D=(0,n.useCallback)(()=>{let e=s0();h(t=>[...t,e]),b(e.id)},[]),q=(0,n.useCallback)(e=>{let t="";h(s=>{let a=s.findIndex(t=>t.id===e);if(a<0)return s;let r=s[a],l=sZ({description:r.description,path:r.path,mode:r.mode,value:sG(r.value_text),keep_origin:r.keep_origin,from:r.from,to:r.to,logic:r.logic,conditions:r.conditions.map(e=>({path:e.path,mode:e.mode,value:sG(e.value_text),invert:e.invert,pass_missing_key:e.pass_missing_key}))});t=l.id;let n=[...s];return n.splice(a+1,0,l),n}),t&&b(t)},[]),V=(0,n.useCallback)(e=>{h(t=>t.length<=1?[s0()]:t.filter(t=>t.id!==e))},[]),K=(0,n.useCallback)(e=>{let t=sY({});h(s=>s.map(s=>s.id===e?{...s,conditions:[...s.conditions,t]}:s)),N(e=>({...e,[t.id]:!0}))},[]),L=(0,n.useCallback)((e,t,s)=>{h(a=>a.map(a=>a.id===e?{...a,conditions:a.conditions.map(e=>e.id===t?{...e,...s}:e)}:a))},[]),H=(0,n.useCallback)((e,t)=>{h(s=>s.map(s=>s.id===e?{...s,conditions:s.conditions.filter(e=>e.id!==t)}:s))},[]),U=(0,n.useCallback)((e,t)=>{h(s=>s.map(s=>{if(s.id!==e)return s;let a={...s8(s.value_text),...t};return{...s,value_text:(e=>{let t=String(e.message||"").trim();if(e.simpleMode)return t;let s=Number(e.statusCode),a={message:t,status_code:Number.isInteger(s)&&s>=100&&s<=599?s:400},r=String(e.code||"").trim(),l=String(e.type||"").trim();return r&&(a.code=r),l&&(a.type=l),!1===e.skipRetry&&(a.skip_retry=!1),JSON.stringify(a)})(a)}}))},[]),W=(0,n.useCallback)((e,t)=>{h(s=>s.map(s=>{if(s.id!==e)return s;let a=s9(s.value_text),r="function"==typeof t?t(a):{...a,...t};return{...s,value_text:(e=>{let t=String(e.typeText||"").trim();if(e.simpleMode)return t;let s={};t&&(s.type=t),"OR"===String(e.logic||"AND").toUpperCase()&&(s.logic="OR"),!1===e.recursive&&(s.recursive=!1);let a=(e.rules||[]).filter(e=>String(e.path||"").trim()).map(e=>{let t={path:String(e.path||"").trim(),mode:sE.has(e.mode)?e.mode:"full"},s=String(e.value_text||"").trim();return""!==s&&(t.value=sG(s)),e.invert&&(t.invert=!0),e.pass_missing_key&&(t.pass_missing_key=!0),t});return(a.length>0&&(s.conditions=a),s.type||s.conditions)?JSON.stringify(s):JSON.stringify({logic:"AND"})})(r)}}))},[]),Q=(0,n.useCallback)(e=>{W(e,e=>({...e,simpleMode:!1,rules:[...e.rules,s7({})]}))},[W]),G=(0,n.useCallback)((e,t,s)=>{W(e,e=>({...e,rules:e.rules.map(e=>e.id===t?{...e,...s}:e)}))},[W]),X=(0,n.useCallback)((e,t)=>{W(e,e=>({...e,rules:e.rules.filter(e=>e.id!==t)}))},[W]),Y=(0,n.useCallback)(()=>{k(""),S(""),A("before")},[]),Z=(0,n.useCallback)((e,t)=>{k(t),b(t),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t)},[]),ee=(0,n.useCallback)((e,t)=>{if(e.preventDefault(),!w||w===t)return;let s=e.currentTarget.getBoundingClientRect(),a=e.clientY-s.top>s.height/2?"after":"before";S(t),A(a),e.dataTransfer.dropEffect="move"},[w]),et=(0,n.useCallback)((e,t)=>{e.preventDefault();let s=w||e.dataTransfer.getData("text/plain"),a=C===t?R:"before";s&&t&&s!==t&&(h(e=>s1(e,s,t,a)),b(s)),Y()},[w,C,R,Y]),es=(0,n.useCallback)(()=>
1{if("legacy"===i){let e=c.trim();if(!e)return"";if(!sX(e))throw Error(t("Parameter override must be valid JSON format"));let s=JSON.parse(e);if(!s||"object"!=typeof s||Array.isArray(s))throw Error(t("Legacy format must be a JSON object"));return JSON.stringify(s,null,2)}return as(m,{validate:!0},t)},[c,m,t,i]),ea=(0,n.useCallback)(()=>{if("json"!==s){try{x(es()),f("")}catch(e){o.oR.error(e.message),"legacy"===i?x(c):x(as(m,{validate:!1},t)),f(e.message||t("Parameter configuration error"))}l("json")}},[es,s,c,m,t,i]),er=(0,n.useCallback)(()=>{if("visual"===s)return;let e=p.trim();if(!e){let e=s0();d("operations"),h([e]),b(e.id),u(""),f(""),l("visual");return}if(!sX(e))return void o.oR.error(t("Parameter override must be valid JSON format"));let a=JSON.parse(e);if(a&&"object"==typeof a&&!Array.isArray(a)&&Array.isArray(a.operations)){let e=a.operations.length>0?a.operations.map(sZ):[s0()];d("operations"),h(e),b(e[0]?.id||""),u(""),f(""),l("visual"),O("operations_default");return}if(a&&"object"==typeof a&&!Array.isArray(a)){let e=s0();d("legacy"),u(JSON.stringify(a,null,2)),h([e]),b(e.id),f(""),l("visual"),O("legacy_default");return}o.oR.error(t("Parameter override must be a valid JSON object"))},[s,p,t]),el=(0,n.useCallback)(e=>{let s=sH[M]||sH.operations_default,a=s.payload;if("legacy"===s.kind){if("append"===e&&"legacy"===i){let e=c.trim(),s={};if(e){if(!sX(e))return void o.oR.error(t("Current legacy JSON is invali
1d, cannot append"));s=JSON.parse(e)}let r=JSON.stringify({...a||{},...s},null,2);d("legacy"),u(r),h([s0()]),x(r),f(""),l("visual")}else{let e=JSON.stringify(a,null,2);d("legacy"),u(e),h([s0()]),x(e),f(""),l("visual")}return}let r=a.operations||[];if("append"===e){let e=r.map(sZ),t=[..."operations"===i?m.filter(e=>!s2(e)):[],...e];d("operations"),h(t.length>0?t:e),b(t[0]?.id||e[0]?.id||""),u(""),f(""),l("visual"),x("")}else{let e=r.map(sZ),t=e.length>0?e:[s0()];d("operations"),h(t),b(t[0]?.id||""),x(JSON.stringify({operations:r},null,2)),f(""),l("visual")}},[c,m,M,i,t]),en=(0,n.useCallback)(()=>{let e=s0();d("operations"),u(""),h([e]),b(e.id),x(""),f(""),O("operations_default"),l("visual")},[]),ei=(0,n.useCallback)(e=>{x(e);let s=e.trim();s?f(sX(s)?"":t("JSON format error")):f("")},[t]),eo=(0,n.useCallback)(()=>{let e=p.trim();if(e){if(!sX(e))return void o.oR.error(t("Parameter override must be valid JSON format"));x(JSON.stringify(JSON.parse(e),null,2)),f("")}},[p,t]),ed=(0,n.useMemo)(()=>{if("visual"!==s)return"";try{return es(),""}catch(e){return e?.message||t("Parameter configuration error")}},[es,s,t]),ec=(0,n.useCallback)(()=>{try{let a="";if("json"===s){let e=p.trim();if(e){if(!sX(e))throw Error(t("Parameter override must be valid JSON format"));a=JSON.stringify(JSON.parse(e),null,2)}}else a=es();e.onSave(a),e.onOpenChange(!1)}catch(e){o.oR.error(e.message)}},[es,s,p,e,t]),eu=(0,n.useCallback)(()=>{if(!E)return;let e={};for(let t of E.conditions)e[t.id]=!0;N(t=>({...t,...e}))},[E]),em=(0,n.useCallback)(()=>{if(!E)return;let e={};for(let t of E.conditions)e[t.id]=!1;N(t=>({...t,...e}))},[E]);return(0,a.jsx)(tl.lG,{open:e.open,onOpenChange:e.onOpenChange,children:(0,a.jsxs)(tl.Cf,{className:"flex max-h-[90vh] flex-col gap-0 p-0 sm:max-w-5xl",children:[(0,a.jsxs)(tl.c7,{className:"border-b px-6 py-4",children:[(0,a.jsx)(tl.L3,{children:t("Parameter Override")}),(0,a.jsx)(tl.rr,{children:t("Create request parameter override rules with a visual editor or raw JSON.")})]}),(0,a.jsx)("div",{className:"bg-muted/30 border-b px-4 py-3",children:(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-xs font-medium",children:t("Mode")}),(0,a.jsx)(tr.$,{type:"button",variant:"visual"===s?"default":"outline",size:"sm",onClick:er,children:t("Visual")}),(0,a.jsx)(tr.$,{type:"button",variant:"json"===s?"default":"outline",size:"sm",onClick:ea,children:t("JSON Text")}),(0,a.jsx)("div",{className:"bg-border mx-1 h-5 w-px"}),(0,a.jsx)("span",{className:"text-muted-foreground text-xs font-medium",children:t("Template")}),(0,a.jsxs)(tw.l6,{items:[...I.map(e=>({value:e.value,label:t(e.label)}))],value:M,onValueChange:e=>O(e||"operations_default"),children:[(0,a.jsx)(tw.bq,{className:"h-8 w-[220px]",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:I.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:t(e.label)},e.value))})})]}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>el("fill"),children:t("Fill Template")}),(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>el("append"),children:t("Append Template")}),(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:en,children:t("Reset")})]})}),(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-hidden",children:"visual"===s?"legacy"===i?(0,a.jsxs)("div",{className:"p-4",children:[(0,a.jsx)("p",{className:"text-muted-foreground mb-2 text-sm",children:t("Legacy Format (JSON Object)")}),(0,a.jsx)(tK.T,{value:c,onChange:e=>u(e.target.value),placeholder:JSON.stringify(sq,null,2),rows:14,className:"font-mono text-xs"}),(0,a.jsx)("p",{className:"text-muted-foreground mt-2 text-xs",children:t("Edit JSON object directly. Suitable for simple parameter overrides.")})]}):(0,a.jsxs)("div",{className:"flex h-full",children:[(0,a.jsxs)("div",{className:"flex w-[280px] flex-shrink-0 flex-col border-r",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:t("Rules")}),(0,a.jsxs)(sc.E,{variant:"secondary",children:[F,"/",m.length]})]}),(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:D,children:(0,a.jsx)(ta.FWt,{className:"h-4 w-4"})})]}),B.length>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-1 border-b px-3 py-2",children:B.map(e=>{let[s,r]=e;return(0,a.jsxs)("span",{className:(0,st.cn)("inline-flex items-center rounded-md border px-1.5 py-0.5 text-[10px] font-medium",s3(s)),children:[t(sF[s]||s)," · ",r]},`mode_stat_${s}`)})}),(0,a.jsx)("div",{className:"px-3 py-2",children:(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(ta.vji,{className:"text-muted-foreground absolute top-2.5 left-2.5 h-3.5 w-3.5"}),(0,a.jsx)(t_.p,{value:j,onChange:e=>y(e.target.value),placeholder:t("Search rules..."),className:"h-8 pl-8 text-xs"})]})}),(0,a.jsx)(to.F,{className:"flex-1",children:(0,a.jsx)("div",{className:"flex flex-col gap-1 px-3 pb-3",children:0===z.length?(0,a.jsx)("p",{className:"text-muted-foreground py-4 text-center text-xs",children:t("No matching rules")}):z.map(e=>{let s=m.findIndex(t=>t.id===e.id),r=e.id===v,l=e.id===w,n=e.id===C&&""!==w&&w!==e.id;return(0,a.jsx)("div",{role:"button",tabIndex:0,draggable:m.length>1,onClick:()=>b(e.id),onDragStart:t=>
1Z(t,e.id),onDragOver:t=>ee(t,e.id),onDrop:t=>et(t,e.id),onDragEnd:Y,onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),b(e.id))},className:(0,st.cn)("cursor-pointer rounded-lg border p-2.5 transition-colors",r?"border-primary bg-primary/5":"hover:bg-muted/50",l&&"opacity-50",n&&"before"===R&&"border-t-primary border-t-2",n&&"after"===R&&"border-b-primary border-b-2"),children:(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)(ta.f2M,{className:(0,st.cn)("text-muted-foreground mt-0.5 h-3.5 w-3.5 flex-shrink-0",m.length>1?"cursor-grab":"cursor-default")}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-1",children:[(0,a.jsxs)("span",{className:"text-xs font-semibold",children:["#",s+1]}),(0,a.jsx)(sc.E,{variant:"outline",className:"text-[10px]",children:e.conditions.length})]}),(0,a.jsx)("p",{className:"text-muted-foreground mt-0.5 line-clamp-1 text-[11px]",children:s4(e,s)}),e.description.trim()&&(0,a.jsx)("p",{className:"text-muted-foreground mt-0.5 line-clamp-2 text-[10px]",children:e.description}),(0,a.jsx)("span",{className:(0,st.cn)("mt-1 inline-flex items-center rounded-md border px-1.5 py-0.5 text-[10px] font-medium",s3(e.mode||"set")),children:t(sF[e.mode||"set"]||e.mode||"set")})]})]})},e.id)})})})]}),(0,a.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col overflow-y-auto",children:[E?(0,a.jsx)(ar,{operation:E,operationIndex:$,operations:m,returnErrorDraft:T,pruneObjectsDraft:P,expandedConditions:_,setExpandedConditions:N,updateOperation:J,duplicateOperation:q,removeOperation:V,addCondition:K,updateCondition:L,removeCondition:H,updateReturnErrorDraft:U,updatePruneObjectsDraft:W,addPruneRule:Q,updatePruneRule:G,removePruneRule:X,expandAllConditions:eu,collapseAllConditions:em}):(0,a.jsx)("div",{className:"flex flex-1 items-center justify-center",children:(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:t("Select a rule to edit.")})}),ed&&(0,a.jsx)("div",{className:"border-t px-4 py-2",children:(0,a.jsx)("p",{className:"text-destructive text-xs",children:ed})})]})]}):(0,a.jsxs)("div",{className:"p-4",children:[(0,a.jsxs)("div",{className:"mb-2 flex items-center gap-2",children:[(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:eo,children:t("Format")}),(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Advanced text editing")})]}),(0,a.jsx)(tK.T,{value:p,onChange:e=>ei(e.target.value),placeholder:JSON.stringify(sV,null,2),rows:20,className:"font-mono text-xs"}),(0,a.jsx)("p",{className:"text-muted-foreground mt-2 text-xs",children:t("Edit JSON text directly. Format will be validated on save.")}),g&&(0,a.jsx)("p",{className:"text-destructive mt-1 text-xs",children:g})]})}),(0,a.jsxs)(tl.Es,{className:"border-t px-6 py-4",children:[(0,a.jsx)(tr.$,{type:"button",variant:"outline",onClick:()=>e.onOpenChange(!1),children:t("Cancel")}),(0,a.jsx)(tr.$,{type:"button",onClick:ec,children:t("Save")})]})]})})}function ar(e){let{t}=(0,r.Bd)(),s=e.operation,l=s.mode||"set",n=s$[l]||s$.set,i=s.conditions,o="sync_fields"===l?s5(s.from):null,d="sync_fields"===l?s5(s.to):null;return(0,a.jsx)(to.F,{className:"flex-1",children:(0,a.jsxs)("div",{className:"space-y-4 p-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(sc.E,{variant:"outline",children:["#",e.operationIndex+1]}),(0,a.jsx)("span",{className:"text-muted-foreground line-clamp-1 text-xs",children:s4(s,e.operationIndex)})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>e.duplicateOperation(s.id),children:[(0,a.jsx)(ta.QRo,{className:"mr-1 h-3.5 w-3.5"}),t("Duplicate")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>e.removeOperation(s.id),children:[(0,a.jsx)(ta.TBR,{className:"mr-1 h-3.5 w-3.5"}),t("Delete")]})]})]}),(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Operation Type")}),(0,a.jsxs)(tw.l6,{items:[...sO.map(e=>({value:e.value,label:t(e.label)}))],value:l,onValueChange:t=>null!==t&&e.updateOperation(s.id,{mode:t}),children:[(0,a.jsx)(tw.bq,{className:"h-9",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:sO.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:t(e.label)},e.value))})})]})]}),(n.path||n.pathOptional)&&(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("set_header"===l||"delete_header"===l?"Header Name":"prune_objects"===l?"Target Path (optional)":"Target Field Path")}),(0,a.jsx)(t_.p,{value:s.path,onChange:t=>e.updateOperation(s.id,{path:t.target.value}),placeholder:"set_header"===l?"Authorization":"delete_header"===l?"X-Debug-Mode":"prune_objects"===l?"messages":"temperature",className:"h-9"})]})]}),sJ[l]&&(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:t(sJ[l])}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Rule Description (optional)")}),(0,a.jsxs)("span",{className:"text-muted-foreground text-[10px]",children:[s.description.length,"/180"]})]}),(0,a.jsx)(t_.p,{value:s.description,onChange:t=>e.updateOperation(s.id,{description:t.target.value}),placeholder:t("e.g. Clean tool parameters to avoid upstream validation errors"),maxLength:180,className:"h-9"})]}),n.value&&("return_error"===l&&e.returnErrorDraft?(0,a.jsx)(an,{operationId:s.id,draft:e.returnErrorDraft,updateDraft:e.updateReturnErrorDraft}):"prune_objects"===l&&e.pruneObjectsDraft?(0,a.jsx)(ai,{operationId:s.id,draft:e.pruneObjectsDraft,updateDraft:e.updatePruneObjectsDraft,addRule:e.addPruneRule,updateRule:e.updatePruneRule,removeRule:e.removePruneRule}):(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("set_header"===l?"Header Value (supports string or JSON mapping)":"pass_headers"===l?"Pass-through Headers (comma-separated or JSON array)":"trim_prefix"===l||"trim_suffix"===l||"ensure_prefix"===l||"ensure_suffix"===l?"Prefix/Suffix Text":"prune_objects"===l?"Prune Rule (string or JSON object)":"Value (supports JSON or plain text)")}),s.value_text.trim().startsWith("{")&&(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"text-muted-foreground h-auto px-1.5 py-0.5 text-xs",onClick:()=>{try{let t=JSON.parse(s.value_text);e.updateOperation(s.id,{value_text:JSON.stringify(t,null,2)})}catch(e){}},children:t("Format")})]}),(0,a.jsx)(tK.T,{value:s.value_text,onChange:t=>e.updateOperation(s.id,{value_text:t.target.value}),placeholder:"set_header"===l?"Bearer sk-xxx":"pass_headers"===l?"Authorization, X-Request-Id":"trim_prefix"===l||"trim_suffix"===l||"ensure_prefix"===l||"ensure_suffix"===l?"openai/":"prune_objects"===l?'{"type":"redacted_thinking"}':"0.7",rows:3,className:"max-h-[200px] resize-y overflow-y-auto font-mono text-xs"})]})),n.keepOrigin&&(0,a.jsxs)("div",{className:"flex items-center justify-between rounded-lg border px-3 py-2",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:t("Keep original value (skip if target exists)")}),(0,a.jsx)(tC.d,{checked:s.keep_origin,onCheckedChange:t=>e.updateOperation(s.id,{keep_origin:t})})]}),"sync_fields"===l&&o&&d?(0,a.jsx)(ao,{operationId:s.id,syncFromTarget:
1o,syncToTarget:d,updateOperation:e.updateOperation}):(n.from||void 0!==n.to)&&"sync_fields"!==l?(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(n.from||!1===n.to)&&(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("replace"===l?"Match Text":"regex_replace"===l?"Regex Pattern":"copy_header"===l||"move_header"===l?"Source Header":"Source Field")}),(0,a.jsx)(t_.p,{value:s.from,onChange:t=>e.updateOperation(s.id,{from:t.target.value}),placeholder:"replace"===l?"openai/":"regex_replace"===l?"^gpt-":"copy_header"===l||"move_header"===l?"Authorization":"model",className:"h-9"})]}),(n.to||!1===n.to)&&(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("replace"===l||"regex_replace"===l?"Replace With":"copy_header"===l||"move_header"===l?"Target Header":"Target Field")}),(0,a.jsx)(t_.p,{value:s.to,onChange:t=>e.updateOperation(s.id,{to:t.target.value}),placeholder:"replace"===l?"(leave empty to delete)":"regex_replace"===l?"openai/gpt-":"copy_header"===l||"move_header"===l?"X-Upstream-Auth":"original_model",className:"h-9"})]})]}):null,(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:t("Conditions")}),(0,a.jsxs)(tw.l6,{items:[{value:"OR",label:t("Match Any (OR)")},{value:"AND",label:t("Match All (AND)")}],value:s.logic||"OR",onValueChange:t=>null!==t&&e.updateOperation(s.id,{logic:t}),children:[(0,a.jsx)(tw.bq,{className:"h-7 w-[120px] text-xs",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"OR",children:t("Match Any (OR)")}),(0,a.jsx)(tw.eb,{value:"AND",children:t("Match All (AND)")})]})})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[i.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:e.expandAllConditions,children:[(0,a.jsx)(ta.yQN,{className:"mr-1 h-3 w-3"}),t("Expand All")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:e.collapseAllConditions,children:[(0,a.jsx)(ta.rXn,{className:"mr-1 h-3 w-3"}),t("Collapse All")]})]}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>e.addCondition(s.id),children:[(0,a.jsx)(ta.FWt,{className:"mr-1 h-3 w-3"}),t("Add Condition")]})]})]}),0===i.length?(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:t("When no conditions are set, the operation always executes.")}):(0,a.jsx)("div",{className:"space-y-2",children:i.map((t,r)=>(0,a.jsx)(al,{condition:t,conditionIndex:r,operationId:s.id,expanded:e.expandedConditions[t.id]??!1,onExpandedChange:s=>e.setExpandedConditions(e=>({...e,[t.id]:s})),updateCondition:e.updateCondition,removeCondition:e.removeCondition},t.id))})]})]})})}function al(e){let{t}=(0,r.Bd)(),s=e.condition;return(0,a.jsx)(tU.Nt,{open:e.expanded,onOpenChange:e.onExpandedChange,children:(0,a.jsxs)("div",{className:"rounded-md border",children:[(0,a.jsxs)(tU.R6,{className:"hover:bg-muted/50 flex w-full items-center justify-between px-3 py-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(sc.E,{variant:"outline",className:"text-[10px]",children:["C",e.conditionIndex+1]}),(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:s.path||t("Path not set")})]}),e.expanded?(0,a.jsx)(ta.rXn,{className:"text-muted-foreground h-3.5 w-3.5"}):(0,a.jsx)(ta.yQN,{className:"text-muted-foreground h-3.5 w-3.5"})]}),(0,a.jsx)(tU.Ke,{children:(0,a.jsxs)("div",{className:"space-y-3 border-t px-3 py-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Condition Settings")}),(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive h-7 text-xs",onClick:()=>e.removeCondition(e.operationId,s.id),children:[(0,a.jsx)(ta.TBR,{className:"mr-1 h-3 w-3"}),t("Delete Condition")]})]}),(0,a.jsxs)("div",{className:"grid gap-2 sm:grid-cols-3",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Field Path")}),(0,a.jsx)(t_.p,{value:s.path,onChange:t=>e.updateCondition(e.operationId,s.id,{path:t.target.value}),placeholder:"model",className:"h-8 text-xs"})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Match Mode")}),(0,a.jsxs)(tw.l6,{items:[...sz.map(e=>({value:e.value,label:t(e.label)}))],value:s.mode,onValueChange:t=>null!==t&&e.updateCondition(e.operationId,s.id,{mode:t}),children:[(0,a.jsx)(tw.bq,{className:"h-8 text-xs",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:sz.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:t(e.label)},e.value))})})]})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Match Value")}),(0,a.jsx)(t_.p,{value:s.value_text,onChange:t=>e.updateCondition(e.operationId,s.id,{value_text:t.target.value}),placeholder:"gpt",className:"h-8 text-xs"})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-4",children:[(0,a.jsxs)("label",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)(tC.d,{checked:s.invert,onCheckedChange:t=>e.updateCondition(e.operationId,s.id,{invert:t})}),t("Invert match")]}),(0,a.jsxs)("label",{className:"flex items-center gap-2 text-xs",children:[(0,a.jsx)(tC.d,{checked:s.pass_missing_key,onCheckedChange:t=>e.updateCondition(e.operationId,s.id,{pass_missing_key:t})}),t("Pass when key is missing")]})]})]})})]})})}function an(e){let{t}=(0,r.Bd)(),s=e.draft;return(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:t("Custom Error Response")}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Mode")}),(0,a.jsx)(tr.$,{type:"button",variant:s.simpleMode?"default":"outline",size:"sm",className:"h-7 text-xs",onClick:()=>e.updateDraft(e.operationId,{simpleMode:!0}),children:t("Simple")}),(0,a.jsx)(tr.$,{type:"button",variant:s.simpleMode?"outline":"default",size:"sm",className:"h-7 text-xs",onClick:()=>e.updateDraft(e.operationId,{simpleMode:!1}),children:t("Advanced")})]})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Error Message (required)")}),(0,a.jsx)(tK.T,{value:s.message,onChange:t=>e.updateDraft(e.operationId,{message:t.target.value}),placeholder:t("e.g. This request does not meet access policy"),rows:2,className:"text-xs"})]}),s.simpleMode?(0,a.jsx)("p",{className:"text-muted-foreground mt-2 text-xs",children:t("Simple mode only returns message; status code and error type use system defaults.")}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-3",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Status Code")}),(0,a.jsx)(t_.p,{value:String(s.statusCode??""),onChange:t=>e.updateDraft(e.operationId,{statusCode:parseInt(t.target.value,10)||400}),placeholder:"400",className:"h-8 text-xs"})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Error Code (optional)")}),(0,a.jsx)(t_.p,{value:s.code,onChange:t=>e.updateDraft(e.operationId,{code:t.target.value}),placeholder:"forced_bad_request",className:"h-8 text-xs"})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Error Type (optional)")}
1),(0,a.jsx)(t_.p,{value:s.type,onChange:t=>e.updateDraft(e.operationId,{type:t.target.value}),placeholder:"invalid_request_error",className:"h-8 text-xs"})]})]}),(0,a.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Retry Suggestion")}),(0,a.jsx)(tr.$,{type:"button",variant:s.skipRetry?"default":"outline",size:"sm",className:"h-7 text-xs",onClick:()=>e.updateDraft(e.operationId,{skipRetry:!0}),children:t("Stop Retry")}),(0,a.jsx)(tr.$,{type:"button",variant:s.skipRetry?"outline":"default",size:"sm",className:"h-7 text-xs",onClick:()=>e.updateDraft(e.operationId,{skipRetry:!1}),children:t("Allow Retry")})]}),(0,a.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:[{label:"Bad Request",statusCode:400,code:"invalid_request",type:"invalid_request_error"},{label:"Unauthorized",statusCode:401,code:"unauthorized",type:"authentication_error"},{label:"Rate Limited",statusCode:429,code:"rate_limited",type:"rate_limit_error"}].map(s=>(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",className:"h-6 text-[10px]",onClick:()=>e.updateDraft(e.operationId,{statusCode:s.statusCode,code:s.code,type:s.type}),children:t(s.label)},s.code))})]})]})}function ai(e){let{t}=(0,r.Bd)(),s=e.draft;return(0,a.jsxs)("div",{className:"rounded-lg border p-3",children:[(0,a.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-sm font-medium",children:t("Object Prune Rules")}),(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:t("Mode")}),(0,a.jsx)(tr.$,{type:"button",variant:s.simpleMode?"default":"outline",size:"sm",className:"h-7 text-xs",onClick:()=>e.updateDraft(e.operationId,{simpleMode:!0}),children:t("Simple")}),(0,a.jsx)(tr.$,{type:"button",variant:s.simpleMode?"outline":"default",size:"sm",className:"h-7 text-xs",onClick:()=>e.updateDraft(e.operationId,{simpleMode:!1}),children:t("Advanced")})]})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Type (common)")}),(0,a.jsx)(t_.p,{value:s.typeText,onChange:t=>e.updateDraft(e.operationId,{typeText:t.target.value}),placeholder:"redacted_thinking",className:"h-8 text-xs"})]}),s.simpleMode?(0,a.jsx)("p",{className:"text-muted-foreground mt-2 text-xs",children:t("Simple mode: prune objects by type, e.g. redacted_thinking.")}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Logic")}),(0,a.jsxs)(tw.l6,{items:[{value:"AND",label:t("All Must Match (AND)")},{value:"OR",label:t("Any Match (OR)")}],value:s.logic,onValueChange:t=>e.updateDraft(e.operationId,{logic:t||"AND"}),children:[(0,a.jsx)(tw.bq,{className:"h-8 text-xs",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"AND",children:t("All Must Match (AND)")}),(0,a.jsx)(tw.eb,{value:"OR",children:t("Any Match (OR)")})]})})]})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Recursion Strategy")}),(0,a.jsxs)("div",{className:"flex gap-1",children:[(0,a.jsx)(tr.$,{type:"button",variant:s.recursive?"default":"outline",size:"sm",className:"h-8 text-xs",onClick:()=>e.updateDraft(e.operationId,{recursive:!0}),children:t("Recursive")}),(0,a.jsx)(tr.$,{type:"button",variant:s.recursive?"outline":"default",size:"sm",className:"h-8 text-xs",onClick:()=>e.updateDraft(e.operationId,{recursive:!1}),children:t("Current Level Only")})]})]})]}),(0,a.jsxs)("div",{className:"bg-muted/30 mt-3 rounded-md border p-2",children:[(0,a.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,a.jsx)("span",{className:"text-xs font-medium",children:t("Additional Conditions")}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>e.addRule(e.operationId),children:[(0,a.jsx)(ta.FWt,{className:"mr-1 h-3 w-3"}),t("Add Condition")]})]}),0===s.rules.length?(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:t("Without additional conditions, only the type above is used for pruning.")}):(0,a.jsx)("div",{className:"space-y-2",children:s.rules.map((s,r)=>(0,a.jsxs)("div",{className:"bg-background rounded-md border p-2",children:[(0,a.jsxs)("div",{className:"mb-1 flex items-center justify-between",children:[(0,a.jsxs)(sc.E,{variant:"outline",className:"text-[10px]",children:["R",r+1]}),(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive h-6 text-[10px]",onClick:()=>e.removeRule(e.operationId,s.id),children:[(0,a.jsx)(ta.TBR,{className:"mr-1 h-3 w-3"}),t("Delete")]})]}),(0,a.jsxs)("div",{className:"grid gap-2 sm:grid-cols-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Field Path")}),(0,a.jsx)(t_.p,{value:s.path,onChange:t=>e.updateRule(e.operationId,s.id,{path:t.target.value}),placeholder:"type",className:"h-7 text-xs"})]}),(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Match Mode")}),(0,a.jsxs)(tw.l6,{items:[...sz.map(e=>({value:e.value,label:t(e.label)}))],value:s.mode,onValueChange:t=>null!==t&&e.updateRule(e.operationId,s.id,{mode:t}),children:[(0,a.jsx)(tw.bq,{className:"h-7 text-xs",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:sz.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:t(e.label)},e.value))})})]})]}),(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Match Value (optional)")}),(0,a.jsx)(t_.p,{value:s.value_text,onChange:t=>e.updateRule(e.operationId,s.id,{value_text:t.target.value}),placeholder:"redacted_thinking",className:"h-7 text-xs"})]})]}),(0,a.jsxs)("div",{className:"mt-1.5 flex flex-wrap gap-3",children:[(0,a.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,a.jsx)(tC.d,{checked:s.invert,onCheckedChange:t=>e.updateRule(e.operationId,s.id,{invert:t})}),t("Invert match")]}),(0,a.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px]",children:[(0,a.jsx)(tC.d,{checked:s.pass_missing_key,onCheckedChange:t=>e.updateRule(e.operationId,s.id,{pass_missing_key:t})}),t("Pass when key is missing")]})]})]},s.id))})]})]})]})}function ao(e){let{t}=(0,r.Bd)();return(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("label",{className:"text-xs font-medium",children:t("Sync Endpoints")}),(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Source Endpoint")}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)(tw.l6,{items:[...sD.map(e=>({value:e.value,label:t(e.label)}))],value:e.syncFromTarget.type||"json",onValueChange:t=>null!==t&&e.updateOperation(e.operationId,{from:s6(t,e.syncFromTarget.key)}),children:[(0,a.jsx)(tw.bq,{className:"h-8 w-[110px] text-xs",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:sD.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:t(e.label)},e.value))})})]}),(0,a.jsx)(t_.p,{value:e.syncFromTarget.key,onChange:t=>e.updateOperation(e.operationId,{from:s6(e.syncFromTarget.type,t.target.value)}),placeholder:"session_id",className:"h-8 text-xs"})]})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("label",{className:"text-[10px] font-medium",children:t("Target Endpoint")}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)(tw.l6,{items:[...sD.map(e=>({value:e.value,label:t(e.label)}))],value:e.syncToTarget.type||"json",onValueChange:t=>null!==t&&e.updateOperation(e.operationId,{to:s6(t,e.syncToTarget.key)}),children:[(0,a.jsx)(tw.bq,{className:"h-8 w-[110px] text-xs",children:(0,a.jsx)(tw.yv,{})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:sD.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:t(e.label)},e.value))})})]}),(0,a.jsx)(t_.p,{value:e.syncToTarget.key,onChange:t=>e.updateOperation(e.operationId,{to:s6(e.syncToTarget.type,t.target.value)}),placeholder:"prompt_cache_key",className:"h-8 text-xs"})]})]})]}),(0,a.jsx)("div",{className:"flex flex-wrap gap-1",children:[{label:"header:session_id -> json:prompt_cache_key",from:"header:session_id",to:"json:prompt_cache_key"},{label:"json:prompt_cache_key -> header:session_id",from:"json:prompt_cache_key",to:"header:session_id"}].map(t=>(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",className:"h-6 text-[10px]",onClick:()=>e.updateOperation(e.operationId,{from:t.from,to:t.to}),children:t.label},t.label))})]})}let ad=["High-risk status code retry risk check 1","High-risk status code retry risk check 2","High-risk status code retry risk check 3","High-risk status code retry risk check 4"];function ac(e){let{open:t,onOpenChange:s,detailItems:l,onConfirm:i}=e,{t:o}
1=(0,r.Bd)(),[d,c]=(0,n.useState)(new Set),[u,m]=(0,n.useState)(""),h=o("High-risk status code retry confirmation text"),p=d.size===ad.length,x=u.trim()===h.trim(),g=p&&x;return(0,a.jsx)(tl.lG,{open:t,onOpenChange:s,children:(0,a.jsxs)(tl.Cf,{className:"max-w-lg",children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsxs)(tl.L3,{className:"text-destructive flex items-center gap-2",children:[(0,a.jsx)(ta.hcu,{className:"h-5 w-5"}),o("High-risk operation confirmation")]}),(0,a.jsx)(tl.rr,{children:o("High-risk status code retry risk disclaimer")})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[l.length>0&&(0,a.jsxs)("div",{className:"border-destructive/30 bg-destructive/5 rounded-lg border p-3",children:[(0,a.jsx)("p",{className:"mb-2 text-sm font-medium",children:o("Detected high-risk status code redirect rules")}),(0,a.jsx)("ul",{className:"list-inside list-disc text-sm",children:l.map(e=>(0,a.jsx)("li",{className:"font-mono text-xs",children:e},e))})]}),(0,a.jsx)("div",{className:"space-y-2",children:ad.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-start gap-2",children:[(0,a.jsx)(tb.S,{id:`risk-check-${t}`,checked:d.has(t),onCheckedChange:()=>{c(e=>{let s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s})}}),(0,a.jsx)(tN.J,{htmlFor:`risk-check-${t}`,className:"text-sm leading-tight",children:o(e)})]},e))}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsxs)(tN.J,{className:"text-sm",children:[o("Action confirmation"),":"," ",(0,a.jsx)("code",{className:"bg-muted rounded px-1 text-xs",children:h})]}),(0,a.jsx)(t_.p,{value:u,onChange:e=>m(e.target.value),placeholder:o("High-risk status code retry input placeholder")}),u&&!x&&(0,a.jsx)("p",{className:"text-destructive text-xs",children:o("High-risk status code retry input mismatch")})]})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:()=>{c(new Set),m(""),s(!1)},children:o("Cancel")}),(0,a.jsx)(tr.$,{variant:"destructive",disabled:!g,onClick:()=>{g&&(c(new Set),m(""),i())},children:o("I confirm enabling high-risk retry")})]})]})})}function au(e){let{t}=(0,r.Bd)();return(0,a.jsxs)(tU.Nt,{open:e.open,onOpenChange:e.onOpenChange,children:[(0,a.jsxs)(tU.R6,{render:(0,a.jsx)("button",{type:"button",className:"hover:bg-muted/40 border-border/60 flex w-full items-center justify-between rounded-lg border px-3 py-3 text-left transition-colors","aria-expanded":e.open}),children:[(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("span",{className:"bg-muted text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-md",children:(0,a.jsx)(ta.wB_,{className:"h-4 w-4","aria-hidden":"true"})}),(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,a.jsx)("div",{className:"text-[13px] font-semibold",children:t("Advanced Settings")}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:t("Request overrides, routing behavior, and upstream model automation")})]})]}),(0,a.jsx)(ta.yQN,{className:(0,st.cn)("text-muted-foreground h-4 w-4 shrink-0 transition-transform",e.open&&"rotate-180"),"aria-hidden":"true"})]}),(0,a.jsx)(tU.Ke,{className:"mt-5 flex flex-col gap-5",children:e.children})]})}function am(e){let{t}=(0,r.Bd)();return(0,a.jsxs)(tO.y5,{children:[(0,a.jsx)(tO.JP,{title:t("API Access"),description:t("Endpoint, provider-specific settings, and credentials."),icon:(0,a.jsx)(ta.vvC,{className:"h-4 w-4","aria-hidden":"true"})}),e.children]})}function ah(e){let{t}=(0,r.Bd)();return(0,a.jsxs)("div",{className:"border-border/60 flex flex-col gap-4 border-t pt-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(ta.kVM,{className:"text-muted-foreground h-3.5 w-3.5","aria-hidden":"true"}),(0,a.jsx)("h4",{className:"text-muted-foreground text-xs font-medium tracking-wide uppercase",children:t("Authentication")})]}),e.children]})}function ap(e){let{t}=(0,r.Bd)();return(0,a.jsxs)(tO.y5,{children:[(0,a.jsx)(tO.JP,{title:t("Basic Information"),description:t("Name, provider type, and availability."),icon:(0,a.jsx)(ta.gq4,{className:"h-4 w-4","aria-hidden":"true"})}),e.children]})}function ax(){let{t:e}=(0,r.Bd)();return(0,a.jsxs)("div",{className:"border-border/60 flex flex-col gap-4 roun
1ded-lg border p-4","aria-live":"polite",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:e("Loading channel details")}),(0,a.jsx)("p",{className:"text-muted-foreground mt-1 text-xs",children:e("Please wait before editing to avoid overwriting saved values.")})]}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(t9.E,{className:"h-10 w-full"}),(0,a.jsx)(t9.E,{className:"h-10 w-full"})]}),(0,a.jsx)(t9.E,{className:"h-24 w-full"}),(0,a.jsx)(t9.E,{className:"h-32 w-full"})]})}function ag(e){let{t}=(0,r.Bd)();return(0,a.jsxs)(tO.y5,{children:[(0,a.jsx)(tO.JP,{title:t("Models & Groups"),description:t("Published models, groups, and model remapping rules."),icon:(0,a.jsx)(ta.QQ,{className:"h-4 w-4","aria-hidden":"true"})}),e.children]})}let af=()=>({invalidJson:!1,entries:[],missingSourceModels:[],exposedTargetModels:[]}),aj=e=>e.map(e=>`"${e}"`).join(", "),ay=[{source:"client-model",target:"upstream-model"}],av="channel-advanced-settings-expanded";function ab(e){let{title:t,icon:s}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[s&&(0,a.jsx)("span",{className:"bg-muted text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-md",children:s}),(0,a.jsx)("h3",{className:"text-sm font-semibold tracking-tight",children:t})]})}function a_(e){let{title:t,icon:s}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[s&&(0,a.jsx)("span",{className:"text-muted-foreground",children:s}),(0,a.jsx)("h4",{className:"text-muted-foreground text-xs font-medium tracking-wide uppercase",children:t})]})}function aN(e){let t,{open:s,onOpenChange:l,currentRow:d}=e,{t:c}=(0,r.Bd)(),u=(0,i.jE)(),{setOpen:m}=ts(),[p,x]=(0,n.useState)(!1),[g,f]=(0,n.useState)(null),[j,_]=(0,n.use
1State)(!1),[N,w]=(0,n.useState)(!1),[k,C]=(0,n.useState)(!1),S=(0,n.useRef)([]),R=(0,n.useRef)(""),A=(0,n.useRef)(""),[M,I]=(0,n.useState)(!1),[F,E]=(0,n.useState)([]),$=(0,n.useRef)(null),[T,P]=(0,n.useState)(!1),[B,J]=(0,n.useState)([]),D=(0,n.useRef)(null),[q,V]=(0,n.useState)(!1),[K,L]=(0,n.useState)(!1),H=!!d,U=d?.id??null,{data:Q,isLoading:G}=(0,tq.I)({queryKey:e_.detail(d?.id||0),queryFn:()=>y(d.id),enabled:H&&!!d?.id}),{data:X,isLoading:et}=(0,tq.I)({queryKey:["groups"],queryFn:Z}),{data:es}=(0,tq.I)({queryKey:["channel_models"],queryFn:Y}),{data:er}=(0,tq.I)({queryKey:["prefill_groups","model"],queryFn:()=>ee("model")}),{copyToClipboard:el}=(0,tn.C)(),{open:en,methods:eo,state:ed,executeVerification:em,withVerification:eh,cancel:ep,setCode:ex,switchMethod:eg}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{onSuccess:t,onError:s,successMessage:a,autoReset:r=!0}=e,[l,i]=(0,n.useState)(sv),[d,c]=(0,n.useState)(sb),[u,m]=(0,n.useState)(!1),p=(0,n.useCallback)(async()=>{let e=await sg();return i(e),e},[]);(0,n.useEffect)(()=>{p()},[p]);let x=(0,n.useCallback)(()=>{c(sb),m(!1)},[]),g=(0,n.useCallback)(async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{preferredMethod:a,title:r,description:l}=t,n=await p();if(!n.has2FA&&!n.hasPasskey)return o.oR.error(h.Ay.t("Please enable Two-factor Authentication or Passkey before proceeding")),s?.(Error("No verification methods available. Enable 2FA or Passkey to continue.")),!1;let i=a??null;return!i&&(n.hasPasskey&&n.passkeySupported?i="passkey":n.has2FA&&(i="2fa")),c(t=>({...t,apiCall:e,method:i,title:r,description:l})),m(!0),!0},[p,s]),f=(0,n.useCallback)(async(e,l)=>{if(!d.apiCall)return void o.oR.error(h.Ay.t("Verification is not configured properly"));let n=e??d.method;if(!n)return void o.oR.error(h.Ay.t("Select a verification method first"));c(e=>({...e,loading:!0}));try{await sf(n,l??d.code);let e=await d.apiCall();return a&&o.oR.success(a),t?.(e,n),r&&x(),e}catch(t){let e=t instanceof Error?t.message:h.Ay.t("Verification failed");throw o.oR.error(e),s?.(t),t}finally{c(e=>({...e,loading:!1}))}},[d,a,t,s,r,x]),j=(0,n.useCallback)(e=>{c(t=>({...t,code:e}))},[]),y=(0,n.useCallback)(e=>{c(t=>({...t,method:e,code:""}))},[]),v=(0,n.useCallback)(()=>{x()},[x]),b=(0,n.useCallback)(async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{return await e()}catch(s){if(function(e){if(!e||"object"!=typeof e||403!==e.response?.status)return!1;let t=e.response?.data?.code;return!!t&&new Set(["VERIFICATION_REQUIRED","VERIFICATION_EXPIRED","VERIFICATION_INVA
1LID"]).has(t)}(s)){let a={code:s.response?.data?.code,message:s.response?.data?.message??"Secure verification is required",required:!0};return o.oR.info(a.message),await g(e,t),null}throw s}},[g]),_=(0,n.useCallback)(e=>"2fa"===e?l.has2FA:"passkey"===e&&l.hasPasskey&&l.passkeySupported,[l]),N=(0,n.useMemo)(()=>l.hasPasskey&&l.passkeySupported?"passkey":l.has2FA?"2fa":null,[l]);return{open:u,setOpen:m,methods:l,state:d,startVerification:g,executeVerification:f,cancel:v,reset:x,setCode:j,switchMethod:y,withVerification:b,fetchVerificationMethods:p,canUseMethod:_,recommendedMethod:N,hasAnyMethod:l.has2FA||l.hasPasskey,isLoading:d.loading,currentMethod:d.method,code:d.code}}();(0,n.useEffect)(()=>{s?U&&f(null):(f(null),_(!1))},[s,U]);let ef=H&&Q?.data?.channel_info?.is_multi_key===!0,ej=(0,si.mN)({resolver:(0,so.u)(eW),defaultValues:eQ}),eN=ej.watch("multi_key_mode"),ew=ej.watch("multi_key_type"),ek=ej.watch("key_mode"),eC=ej.watch("group"),eS=ej.watch("type"),eR=ej.watch("base_url"),eA=ej.watch("models"),eM=ej.watch("name"),eO=ej.watch("model_mapping"),eI=ej.watch("aws_key_type"),eF=ej.watch("upstream_model_update_check_enabled"),ez=ej.watch("settings"),{unlocked:eE,handleClick:e$,reset:eT}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.disabled??!1,s=e.requiredClicks??3,a=e.onUnlock,r=(0,n.useRef)(0),[l,i]=(0,n.useState)(!1),o=(0,n.useCallback)(()=>{r.current=0,i(!1)},[]),d=(0,n.useCallback)(()=>{if(t||l)return;let e=r.current+1;r.current=e,e>=s&&(r.current=0,i(!0),a?.())},[t,a,s,l]);return{unlocked:l,handleClick:d,reset:o}}({requiredClicks:10,disabled:45!==eS,onUnlock:()=>{o.oR.info(c("Doubao custom API address editing unlocked"))}});(0,n.useEffect)(()=>{s||eT()},[s,eT]);let eP="batch"===eN||"multi_to_single"===eN,eB=H&&G,eJ=(0,n.useMemo)(()=>es?.data?.map(e=>e.id).filter(Boolean)||[],[es]),eD=(0,n.useMemo)(()=>eJ.length?1===eS?eJ.filter(e=>e.startsWith("gpt-")||e.startsWith("text-")):eJ:[],[eJ,eS]),eq=(0,n.useMemo)(()=>er?.data||[],[er]),eV=(0,n.useMemo)(()=>X?.data?Array.from(new Set([...X.data,...eC||[]])).map(e=>({value:e,label:e})):[],[X,eC]),eK=(0,n.useMemo)(()=>e8(eA),[eA]),eL=(0,n.useMemo)(()=>ea.find(e=>e.value===eS)?.label||`#${eS}`,[eS]),eH=(0,n.useMemo)(()=>{let e=ea.map(e=>({value:String(e.value),label:c(e.label),icon:(0,sd.Y)(`${e2(e.value)}.Color`,16)}));return e.some(e=>Number(e.value)===eS)||e.push({value:String(eS),label:`#${eS}`,icon:(0,sd.Y)(`${e2(eS)}.Color`,16)}),e},[eS,c]),eU=(0,n.useMemo)(()=>(function(e){if("string"!=typeof e)return[];let t=e.trim();if(!t)return[];try{let e=JSON.parse(t);if(!e||"object"!=typeof e||Array.isArray(e))return[];let s=Object.values(e).map(e=>"string"==typeof e?e.trim():void 0).filter(e=>!!e);return Array.from(new Set(s))}catch{return[]}})(eO||""),[eO]),eZ=(0,n.useMemo)(()=>(function(e){if("string"!=typeof e)return[];let t=e.trim();if(!t)return[];try{let e=JSON.parse(t);if(!e||"object"!=typeof e||Array.isArray(e))return[];let s=Object.keys(e).map(e=>e.trim()).filter(Boolean);return Array.from(new Set(s))}catch{return[]}})(eO||""),[eO]),e0=(0,n.useMemo)(()=>Array.from(new Set([...eJ,...eK])).map(e=>({value:e,label:e})),[eJ,eK]),e1=(0,n.useMemo)(()=>{if(!eO?.trim())return af();try{let e=JSON.parse(eO);if(!e||"object"!=typeof e||Array.isArray(e))return{...af(),invalidJson:!0};let t=Object.entries(e).reduce((e,t)=>{let[s,a]=t,r=String(s).trim(),l=String(a??"").trim();return r&&l&&e.push({source:r,target:l}),e},[]),s=Array.from(new Set(t.filter(e=>!!e.source&&!eK.includes(e.source)).map(e=>e.source))),a=Array.from(new Set(t.filter(e=>!!e.target&&eK.includes(e.target)).map(e=>e.target)));return{invalidJson:!1,entries:t,missingSourceModels:s,exposedTargetModels:a}}catch{return{...af(),invalidJson:!0}}},[eO,eK]),e4=e1.entries.length>0?e1.entries.slice(0,3):ay,e3=e1.entries.length>3?e1.entries.length-3:0,e5=(0,n.useMemo)(()=>{let e=function(e){if(!e?.trim())return{};try{let t=JSON.parse(e);if(t&&"object"==typeof t&&!Array.isArray(t))return t}catch{}return{}}(ez),t=Array.isArray(e.upstream_model_update_last_detected_models)?e.upstream_model_update_last_detected_models.map(e=>
1String(e||"").trim()).filter(Boolean):[];return{lastCheckTime:e.upstream_model_update_last_check_time,detectedModels:Array.from(new Set(t))}},[ez]),e6=e5.detectedModels.slice(0,8),te=e5.detectedModels.length-e6.length;(0,n.useEffect)(()=>{if(H&&Q?.data){let e=function(e){var t;let s={force_format:!1,thinking_to_content:!1,proxy:"",pass_through_body_enabled:!1,system_prompt:"",system_prompt_override:!1};if(e.setting)try{let t=JSON.parse(e.setting);s={force_format:t.force_format||!1,thinking_to_content:t.thinking_to_content||!1,proxy:t.proxy||"",pass_through_body_enabled:t.pass_through_body_enabled||!1,system_prompt:t.system_prompt||"",system_prompt_override:t.system_prompt_override||!1}}catch(e){console.error("Failed to parse channel setting:",e)}let a="json",r="",l=!1,n="ak_sk",i=!1,o=!1,d=!1,c=!1,u=!1,m=!1,h=!1,p=!1,x=!1,g="";if(e.settings)try{let t=JSON.parse(e.settings);a=t.vertex_key_type||"json",r=t.azure_responses_version||"",l=!0===t.openrouter_enterprise,n=t.aws_key_type||"ak_sk",i=!0===t.allow_service_tier,o=!0===t.disable_store,d=!0===t.allow_safety_identifier,c=!0===t.allow_include_obfuscation,u=!0===t.allow_inference_geo,m=!0===t.allow_speed,h=!0===t.claude_beta_query,p=!0===t.upstream_model_update_check_enabled,x=!0===t.upstream_model_update_auto_sync_enabled,g=Array.isArray(t.upstream_model_update_ignored_models)?t.upstream_model_update_ignored_models.join(","):""}catch(e){console.error("Failed to parse channel settings:",e)}return{name:e.name||"",type:e.type,base_url:e.base_url||"",key:"",openai_organization:e.openai_organization||"",models:e.models||"",group:(t=e.group||"default",t.split(",").map(e=>e.trim()).filter(e=>e.length>0)),model_mapping:e.model_mapping||"",priority:e.priority||0,weight:e.weight||0,test_model:e.test_model||"",auto_ban:e.auto_ban??1,status:e.status,status_code_mapping:e.status_code_mapping||"",tag:e.tag||"",remark:e.remark||"",setting:e.setting||"",param_override:e.param_override||"",header_override:e.header_override||"",settings:e.settings||"{}",other:e.other||"",multi_key_mode:"single",multi_key_type:e.channel_info.multi_key_mode||"random",batch_add_set_key_prefix_2_name:!1,key_mode:"append",...s,is_enterprise_account:l,vertex_key_type:a,azure_responses_version:r,aws_key_type:n,allow_service_tier:i,disable_store:o,allow_include_obfuscation:c,allow_inference_geo:u,allow_speed:m,claude_beta_query:h,allow_safety_identifier:d,upstream_model_update_check_enabled:p,upstream_model_update_auto_sync_enabled:x,upstream_model_update_ignored_models:g}}(Q.data);ej.reset(e),V(!("u"<typeof window)&&"true"===window.localStorage.getItem(av)||!!(e.model_mapping?.trim()||e.param_override?.trim()||e.header_override?.trim()||e.status_code_mapping?.trim()||e.tag?.trim()||e.remark?.trim()||e.priority||e.weight||e.proxy?.trim()||e.system_prompt?.trim()||e.force_format||e.thinking_to_content||e.pass_through_body_enabled||e.system_prompt_override||e.claude_beta_query||e.upstream_model_update_check_enabled||e.upstream_model_update_auto_sync_enabled||e.upstream_model_update_ignored_models?.trim())),S.current=e8(Q.data.models||""),R.current=Q.data.model_mapping||"",A.current=Q.data.status_code_mapping||""}else H||(ej.reset(eQ),V(!1),S.current=[],R.current="",A.current="")},[H,Q,ej]),(0,n.useEffect)(()=>{if(!H){if(45===eS){let e=ej.getValues("base_url");e&&""!==e||ej.setValue("base_url","https://ark.cn-beijing.volces.com")}if(18===eS){let e=ej.getValues("other");e&&""!==e||ej.setValue("other","v2.1")}}},[eS,H,ej]),(0,n.useEffect)(()=>{if(!eR||!eR.endsWith("/v1"))return;let e=setTimeout(()=>{o.oR.warning(c("Warning: Base URL should not end with /v1. New API will handle it automatically. This may cause request failures."),{duration:5e3})},500);return()=>clearTimeout(e)},[eR]);let tt=()=>{let e=ej.getValues("key");if(!e||""===e.trim())return void o.oR.info(c("Please enter keys first"));let t=function(e){if(!e||""===e.trim())return{deduplicatedText:"",beforeCount:0,afterCount:0,removedCount:0};let t=e.split("\n"),s=t.length,a=new Set,r=[];t.forEach(e=>{let t=e.trim();t&&!a.has(t)&&(a.add(t),r.push(t))});let l=r.length;return{deduplicatedText:r.join("\n"),beforeCount:s,afterCount:l,removedCount:s-l}}(e);0===t.removedCount?o.oR.info(c("No duplicate keys found")):(ej.setValue("key",t.deduplicatedText),o.oR.success(c("Removed {{removed}} duplicate key(s). Before: {{before}}, After: {{after}}",{removed:t.removedCount,before:t.beforeCount,after:t.afterCount})))},tl=(0,n.useCallback)(async()=>
1{if(!U)throw Error("Channel is not selected");_(!0);try{let e=await O(U);if(!e.success)throw Error(e.message||c("Failed to fetch channel key"));let t=e.data?.key??"";return f(t),o.oR.success(c("Channel key unlocked")),e}finally{_(!1)}},[U,c]),ti=(0,n.useCallback)(async()=>{if(U)try{await eh(tl,{preferredMethod:"passkey",title:"Verify to view channel key",description:"Use Passkey or 2FA to confirm your identity before revealing this channel key."})}catch(e){e instanceof Error&&o.oR.error(e.message)}},[U,eh,tl]),to=(0,n.useCallback)(async()=>{if(U){C(!0);try{let e=await z(U);if(!e.success)throw Error(e.message||c("Failed to refresh credential"));o.oR.success(c("Credential refreshed")),u.invalidateQueries({queryKey:e_.detail(U)})}catch(e){o.oR.error(e instanceof Error?e.message:c("Refresh failed"))}finally{C(!1)}}},[U,u,c]),td=(0,n.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=t?e7([...eK,...e]):e7(e);return ej.setValue("models",s),e.length},[eK,ej]),tc=(0,n.useCallback)(async()=>{let e=ej.getValues("type");if(!ey.has(e))return void o.oR.error(c("This channel type does not support fetching models"));if(!H){let e=ej.getValues("key");if(!e?.trim())return void o.oR.error(c("Please enter API key first"))}x(!0)},[H,ej,c]),tu=(0,n.useCallback)(async()=>{let e=await W({type:ej.getValues("type"),key:ej.getValues("key"),base_url:ej.getValues("base_url")||""});if(e.success&&e.data)return e.data;throw Error(e.message||"No models fetched from upstream")},[ej]),tm=(0,n.useCallback)(()=>{eD.length?(td(eD),o.oR.success(c("Filled {{count}} related model(s)",{count:eD.length}))):o.oR.info(c("No related models available for this channel type"))},[eD,td,c]),th=(0,n.useCallback)(()=>{eJ.length?(td(eJ),o.oR.success(c("Filled {{count}} model(s)",{count:eJ.length}))):o.oR.info(c("No models available"))},[eJ,td,c]),tp=(0,n.useCallback)(()=>{ej.setValue("models",""),o.oR.success(c("Cleared all models"))},[ej,c]),tx=(0,n.useCallback)(async()=>{let e=ej.getValues("models");e?.trim()?await el(e):o.oR.info(c("No models to copy"))},[ej,el,c]),tg=(0,n.useCallback)(e=>{try{let t=Array.isArray(e.items)?e.items:JSON.parse(e.items);if(!Array.isArray(t))throw Error("Invalid items format");let s=td(t,!0);o.oR.success(c('Added {{count}} models from "{{name}}"',{count:s,name:e.name}))}catch{o.oR.error(c("Failed to parse group items"))}},[td,c]),tf=(0,n.useCallback)(e=>{ej.setValue("models",e.join(","))},[ej]),tj=(0,n.useCallback)(()=>{u.invalidateQueries({queryKey:e_.lists()}),U&&u.invalidateQueries({queryKey:e_.detail(U)}),l(!1),m(null)},[U,u,l,m]),ty=(0,n.useCallback)(e=>new Promise(t=>{J(e),P(!0),D.current=t}),[]),tv=(0,n.useCallback)(e=>{P(!1),D.current&&(D.current(e),D.current=null)},[]),tb=(0,n.useCallback)(e=>new Promise(t=>{$.current=t,E(e),I(!0)}),[]),tN=(0,n.useCallback)(e=>{I(!1),E([]),$.current&&($.current(e),$.current=null)},[]);(0,n.useEffect)(()=>()=>{$.current&&($.current(!1),$.current=null)},[]);let tS=function(e){let{t}=(0,r.Bd)();return(0,sN.n)({mutationFn:async s=>{let a,r;if(e.isEditing&&e.currentRow){let a,r=(a={id:e.currentRow.id,name:s.name,type:s.type,base_url:eY(s.base_url)||null,openai_organization:s.openai_organization||null,models:s.models,group:s.group.join(","),model_mapping:s.model_mapping||null,priority:s.priority??0,weight:s.weight??0,test_model:s.test_model||null,auto_ban:s.auto_ban??1,status:s.status,status_code_mapping:s.status_code_mapping||null,tag:s.tag||null,remark:s.remark||"",setting:eG(s),param_override:s.param_override||null,header_override:s.header_override||null,settings:eX(s),other:s.other||""},s.key&&s.key.trim()&&(a.key=s.key),Object.keys(a).forEach(e=>{""===a[e]&&(a[e]=null)}),a.base_url=eY(s.base_url)||"",a.openai_organization=s.openai_organization||"",a.test_model=s.test_model||"",a.tag=s.tag||"",a.remark=s.remark||"",a.model_mapping=s.model_mapping||"",a.status_code_mapping=s.status_code_mapping||"",a.param_override=s.param_override||"",a.header_override=s.header_override||"",a),l=e.isMultiKeyChannel&&s.key_mode?{...r,key_mode:s.key_mode}:r,n=await b(e.currentRow.id,l);if(!n.success)throw Error(n.message||t(eu));return"Channel updated successfully"}let l=(a=s.multi_key_mode||"single",Object.keys(r={name:s.name,type:s.type,base_url:eY(s.base_url)||null,key:s.key,open
1ai_organization:s.openai_organization||null,models:s.models,group:s.group.join(","),model_mapping:s.model_mapping||null,priority:s.priority||null,weight:s.weight||null,test_model:s.test_model||null,auto_ban:s.auto_ban??1,status:s.status,status_code_mapping:s.status_code_mapping||null,tag:s.tag||null,remark:s.remark||"",setting:eG(s),param_override:s.param_override||null,header_override:s.header_override||null,settings:eX(s),other:s.other||""}).forEach(e=>{""===r[e]&&(r[e]=null)}),{mode:a,multi_key_mode:"multi_to_single"===a?s.multi_key_type:void 0,batch_add_set_key_prefix_2_name:"batch"===a?s.batch_add_set_key_prefix_2_name:void 0,channel:r}),n=await v(l);if(!n.success)throw Error(n.message||t(ec));return"Channel created successfully"},onSuccess:s=>{o.oR.success(t(s)),e.onSuccess()},onError:e=>{o.oR.error(function(e){if(e instanceof Error&&"string"==typeof e.message)return e.message;if(!sw(e))return;let t=e.response;if(sw(t)){let e=t.data;if(sw(e)){let t=e.message;if("string"==typeof t)return t}}let s=e.message;if("string"==typeof s)return s}(e)||t(ec))}})}({currentRow:d,isEditing:H,isMultiKeyChannel:ef,onSuccess:tj}),tA=tS.isPending,tM=(0,n.useCallback)(async e=>{if(!H&&!e.key?.trim())return void ej.setError("key",{type:"manual",message:"API key is required"});if(e.status_code_mapping?.trim()){let t=function(e){let t;if(!e?.trim())return[];try{t=JSON.parse(e)}catch{return[]}if(!t||"object"!=typeof t||Array.isArray(t))return[];let s=[];for(let[e,a]of Object.entries(t)){let t=sC(e),r=sS(a);(null===t||null===r)&&s.push(`${e} â ${a}`)}return s}(e.status_code_mapping);if(t.length>0)return void o.oR.error(c("Invalid status code mapping entries: {{entries}}",{entries:t.join(", ")}));let s=function(e,t){let s=sR(t);if(0===s.length)return[];let a=new Set(sR(e));return s.filter(e=>!a.has(e))}(A.current,e.status_code_mapping);if(s.length>0&&!await tb(s))return}let t="string"==typeof e.model_mapping&&""!==e.model_mapping.trim();if(t){let t=function(e){if(!e||""===e.trim())return{valid:!0};try{let t=JSON.parse(e);if(!t||"object"!=typeof t||Array.isArray(t))return{valid:!1,error:"Model mapping must be a valid JSON object"};if(Object.values(t).some(e=>"string"!=typeof e))return{valid:!1,error:"Model mapping values must be strings"};return{valid:!0}}catch{return{valid:!1,error:"Model mapping must be valid JSON format"}}}(e.model_mapping);if(!t.valid)return void o.oR.error(c(t.error||"Invalid model mapping"))}let s=e8(e.models||"");if(t){let t=function(e,t){let s;if(!e||""===e.trim())return[];try{if(!(s=JSON.parse(e))||"object"!=typeof s||Array.isArray(s))return[]}catch{return[]}let a=new Set(t.map(e=>e9(e)));return Array.from(new Set(Object.keys(s).map(e=>e9(e)).filter(e=>e&&!a.has(e))))}(e.model_mapping,s);if(t.length>0&&function(e,t,s,a){if(0===s.length&&!a||e.length!==s.length)return!0;for(let t=0;t<e.length;t++)if(e[t]!==s[t])return!0;return(t||"").trim()!==(a||"").trim()}(s,e.model_mapping||"",S.current,R.current)){let a=await ty(t);if("cancel"===a)return;"add"===a&&(e.models=e7(Array.from(new Set([...s,...t]))),ej.setValue("models",e.models))}}await tS.mutateAsync(e)},[H,ej,ty,tb,tS,c]),tI=(0,n.useCallback)(e=>{l(e),e||(ej.reset(eQ),V(!1))},[l,ej]),tF=(0,n.useCallback)(e=>{V(e),"u">typeof window&&window.localStorage.setItem(av,String(e))},[]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(tk.cj,{open:s,onOpenChange:tI,children:(0,a.jsxs)(tk.h,{className:(0,tO.jW)("sm:max-w-3xl"),children:[(0,a.jsxs)(tk.Fm,{className:(0,tO.Dt)(),children:[(0,a.jsxs)(tk.qp,{className:"flex items-center gap-3",children:[(0,a.jsx)("span",{className:"bg-muted flex size-9 shrink-0 items-center justify-center rounded-md",children:(0,sd.Y)(`${e2(eS)}.Color`,22)}),(0,a.jsxs)("span",{children:[H?c("Edit Channel"):c("Create Channel"),(0,a.jsx)("span",{className:"text-muted-foreground ml-2 text-sm font-normal",children:c(eL)})]})]}),(0,a.jsx)(tk.Qs,{children:H?c("Update channel configuration and click save when you're done."):c("Add a new channel by providing the necessary information.")})]}),(0,a.jsx)(sm.lV,{...ej,children:(0,a.jsx)("form",{id:"channel-form",onSubmit:ej.handleSubmit(tM),className:(0,tO.e)("gap-
15"),children:eB?(0,a.jsx)(ax,{}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(ap,{children:[(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"name",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Name *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., OpenAI GPT-4 Production"),...t})}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"type",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Type *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(su.G3,{options:eH,value:String(t.value),onValueChange:e=>{let s=Number(e);Number.isInteger(s)&&s>0&&t.onChange(s)},placeholder:c("Select channel type"),searchPlaceholder:c("Search channel type..."),emptyText:c("No channel type found."),allowCustomValue:!0})}),(0,a.jsx)(sm.C5,{})]})}})]}),(0,a.jsx)(sm.zB,{control:ej.control,name:"status",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:(0,tO.fE)(),children:[(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Enabled")}),(0,a.jsx)(sm.Rr,{className:"text-xs",children:c("Enable or disable this channel")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:1===t.value,onCheckedChange:e=>t.onChange(e?1:2)})})]})}}),1===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"openai_organization",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("OpenAI Organization")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("org-..."),...t})}),(0,a.jsx)(sm.Rr,{children:c("OpenAI Organization ID (optional)")}),(0,a.jsx)(sm.C5,{})]})}})]}),(0,a.jsxs)(am,{children:[eb[eS]&&(0,a.jsx)(t7.Fc,{children:(0,a.jsx)(t7.TN,{children:c(eb[eS])})}),3===eS&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("AZURE_OPENAI_ENDPOINT *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., https://docs-test-001.openai.azure.com"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Your Azure OpenAI endpoint URL")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"other",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Default API Version *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., 2025-04-01-preview"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Default API version for this channel")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"azure_responses_version",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Responses API Version")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., preview"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Default Responses API version, if empty, will use the API version above")}),(0,a.jsx)(sm.C5,{})]})}})]}),8===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsxs)(sm.lR,{children:[c("Full Base URL (supports")," ","{",c("model"),"}"," ",c("variable) *")]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., https://api.openai.com/v1/chat/completions"),...t})}),(0,a.jsxs)(sm.Rr,{children:[c("Enter the complete URL, supports")," ","{",c("model"),"}"," ",c("variable")]}),(0,a.jsx)(sm.C5,{})]})}}),18===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"other",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Model Version *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., v2.1"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Spark model version, e.g., v2.1 (version number in API URL)")}),(0,a.jsx)(sm.C5,{})]})}}),20===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"is_enterprise_account",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Enterprise Account")}),(0,a.jsx)(sm.Rr,{children:c("Enable if this is an OpenRouter enterprise account with special response format")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),33===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"aws_key_type",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("AWS Key Format")}),(0,a.jsxs)(tw.l6,{items:[{value:"ak_sk",label:c("AccessKey / SecretAccessKey")},{value:"api_key",label:c("API Key")}],onValueChange:t.onChange,value:t.value,children:[(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tw.bq,{children:(0,a.jsx)(tw.yv,{placeholder:c("Select key format")})})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"ak_sk",children:c("AccessKey / SecretAccessKey")}),(0,a.jsx)(tw.eb,{value:"api_key",children:c("API Key")})]})})]}),(0,a.jsx)(sm.Rr,{children:"api_key"===t.value?c("API Key mode: use APIKey|Region"):c("AK/SK mode: use AccessKey|SecretAccessKey|Region")}),(0,a.jsx)(sm.C5,{})]})}}),21===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"other",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Knowledge Base ID *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., 123456"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Enter the knowledge base ID")}),(0,a.jsx)(sm.C5,{})]})}}),22===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Private Deployment URL")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., https://fastgpt.run/api/openapi"),...t})}),(0,a.jsx)(sm.Rr,{children:c("For private deployments, format: https://fastgpt.run/api/openapi")}),(0,a.jsx)(sm.C5,{})]})}}),36===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("API Base URL (Important: Not Chat API) *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., https://api.example.com (path before /suno)"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Enter the path before /suno, usually just the domain")}),(0,a.jsx)(sm.C5,{})]})}}),39===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"other",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Account ID *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., d6b5da8hk1awo8nap34ube6gh"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Your Cloudflare Account ID")}),(0,a.jsx)(sm.C5,{})]})}}),40===eS&&(0,a.jsx)(t7.Fc,{children:(0,a.jsxs)(t7.TN,{children:[c("Referral link:")," ",(0,a.jsx)("a",{href:"https://cloud.siliconflow.cn/i/hij0YNTZ",target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:c("https://cloud.siliconflow.cn/i/hij0YNTZ")})]})}),41===eS&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"vertex_key_type",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Vertex AI Key Format")}),(0,a.jsxs)(tw.l6,{items:[{value:"json",label:c("JSON")},{value:"api_key",label:c("API Key")}],onValueChange:t.onChange,value:t.value,children:[(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tw.bq,{children:(0,a.jsx)(tw.yv,{})})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"json",children:c("JSON")}),(0,a.jsx)(tw.eb,{value:"api_key",children:c("API Key")})]})})]}),(0,a.jsx)(sm.Rr,{children:"json"===t.value?c("JSON format supports service account JSON files"):c("API Key mode (does not support batch creation)")}),(0,a.jsx)(sm.C5,{})]})}}),"json"===ej.watch("vertex_key_type")&&(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Service account JSON file(s)")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{type:"file",accept:".json,application/json",multiple:eP,onChange:async e=>{let t=e.target.files,s=t?Array.from(t):[];if(e.target.value="",0===s.length)return void o.oR.info(c("Please upload key file(s)"));let a=[];for(let e of s)try{let t=await e.text();a.push(JSON.parse(t))}catch{o.oR.error(c("Failed to parse JSON file: {{name}}",{name:e.name}));return}if(0===a.length)return void o.oR.info(c("Please upload key file(s)"));let r=eP?JSON.stringify(a):JSON.stringify(a[0]);ej.setValue("key",r,{shouldDirty:!0,shouldValidate:!0}),o.oR.success(c("Parsed {{count}} service account file(s)",{count:a.length}))}})}),(0,a.jsx)(sm.Rr,{children:eP?c("Upload multiple JSON files in batch modes"):c("Upload a single service account JSON file")}),(0,a.jsx)(sm.C5,{})]}),(0,a.jsx)(sm.zB,{control:ej.control,name:"other",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Deployment Region *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tK.T,{placeholder:c("e.g., us-central1 or JSON format for model-specific regions"),rows:3,...t})}),(0,a.jsxs)(sm.Rr,{children:[c("Enter deployment region or JSON mapping:")," ","{",c('"default": "us-central1", "claude-3-5-sonnet-20240620": "europe-west1"'),"}"]}),(0,a.jsx)(sm.C5,{})]})}})]}),45===eS&&!eE&&(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{className:"cursor-pointer select-none",onClick:e$,children:c("API Base URL *")}),(0,a.jsxs)(tw.l6,{items:[{value:"https://ark.cn-beijing.volces.com",label:c("https://ark.cn-beijing.volces.com")},{value:"https://ark.ap-southeast.bytepluses.com",label:c("https://ark.ap-southeast.bytepluses.com")},{value:"doubao-coding-plan",label:c("Doubao Coding Plan")}],onValueChange:t.onChange,value:t.value||"https://ark.cn-beijing.volces.com",children:[(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tw.bq,{children:(0,a.jsx)(tw.yv,{})})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"https://ark.cn-beijing.volces.com",children:c("https://ark.cn-beijing.volces.com")}),(0,a.jsx)(tw.eb,{value:"https://ark.ap-southeast.bytepluses.com",children:c("https://ark.ap-southeast.bytepluses.com")}),(0,a.jsx)(tw.eb,{value:"doubao-coding-plan",children:c("Doubao Coding Plan")})]})})]}),(0,a.jsx)(sm.Rr,{children:c("Select the API endpoint region")}),(0,a.jsx)(sm.C5,{})]})}}),45===eS&&eE&&(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("API Base URL *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., https://ark.cn-beijing.volces.com"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Enter custom API endpoint URL")}),(0,a.jsx)(sm.C5,{})]})}}),49===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"other",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Agent ID *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., 7342866812345"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Enter the Coze agent ID")}),(0,a.jsx)(sm.C5,{})]})}}),![3,8,22,36,45].includes(eS)&&(0,a.jsx)(sm.zB,{control:ej.control,name:"base_url",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Base URL")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("Leave empty to use default"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Custom API base URL. For official channels, New API has built-in addresses. Only fill this for third-party proxy sites or special endpoints. Do not add /v1 or trailing slash.")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsxs)(ah,{children:[!H&&(0,a.jsx)(sm.zB,{control:ej.control,name:"multi_key_mode",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Add Mode")}),(0,a.jsxs)(tw.l6,{items:[...ei.map(e=>({value:e.value,label:c(e.label)}))],onValueChange:t.onChange,value:t.value,children:[(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tw.bq,{children:(0,a.jsx)(tw.yv,{})})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsx)(tw.s3,{children:ei.map(e=>(0,a.jsx)(tw.eb,{value:e.value,children:c(e.label)},e.value))})})]}),(0,a.jsx)(sm.Rr,{children:c("Create multiple channels from multiple keys")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"key",render:e=>{let{field:t}=e,s=H?c("Leave empty to keep existing key"):33===eS?"api_key"===eI?eP?c("Enter API Key, one per line, format: APIKey|Region"):c("Enter API Key, format: APIKey|Region"):eP?c("Enter key, one per line, format: AccessKey|SecretAccessKey|Region"):c("Enter key, format: AccessKey|SecretAccessKey|Region"):eP?c("Enter one key per line for batch creation"):c(ev[eS]||"Enter API key for this channel");return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("API Key *")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tK.T,{placeholder:s,rows:eP?8:4,...t})}),(0,a.jsx)(sm.Rr,{children:(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsx)("span",{children:H?(0,a.jsxs)(a.Fragment,{children:[c("Enter new key to update, or leave empty to keep current key"),ef&&(0,a.jsxs)("span",{className:"text-warning mt-1 block",children:[c("Multi-key channel: Keys will be")," ","replace"===ek?c("replaced"):c("appended")]})]}):eP?c("Enter one API key per line for batch creation"):c("API key from the provider")}),eP&&(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:tt,className:"w-fit",children:[(0,a.jsx)(ta.TBR,{className:"mr-2 h-4 w-4"}),c("Remove Duplicates")]})]})}),H&&(0,a.jsxs)("div",{className:"border-border/60 mt-4 flex flex-col gap-3 border-y border-dashed py-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:c("Current key")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:c("Verification required to reveal the saved key.")})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:ti,disabled:j||ed.loading,children:[j||ed.loading?(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(ta.kU3,{className:"mr-2 h-4 w-4"}),c("Reveal key")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:async()=>{g&&await el(g)},disabled:!g,children:[(0,a.jsx)(ta.QRo,{className:"mr-2 h-4 w-4"}),c("Copy")]})]})]}),(0,a.jsx)(t_.p,{readOnly:!0,value:g??"",placeholder:c("Hidden â verify to reveal"),className:"font-mono"})]}),(0,a.jsx)(sm.C5,{})]})}}),57===eS&&(0,a.jsxs)("div",{className:"border-border/60 flex flex-col gap-3 border-y py-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,a.jsx)("div",{className:"text-sm font-semibold",children:c("Codex Authorization")}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:c("Codex channels use an OAuth JSON credential as the key.")})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>w(!0),children:[(0,a.jsx)(ta.vvC,{className:"mr-2 h-4 w-4"}),c("Authorize")]}),H&&U&&(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:to,disabled:k,children:[k?(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(ta.e9t,{className:"mr-2 h-4 w-4"}),k?c("Refreshing..."):c("Refresh credential")]})]})]}),(0,a.jsx)(t7.Fc,{children:(0,a.jsx)(t7.TN,{children:c("If authorization succeeds, the generated JSON will be inserted into the key field. You still need to save the channel to persist it.")})})]}),(0,a.jsx)(sA,{open:N,onOpenChange:w,onKeyGenerated:e=>{ej.setValue("key",e,{shouldDirty:!0})}}),H&&ef&&(0,a.jsx)(sm.zB,{control:ej.control,name:"key_mode",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Key Update Mode")}),(0,a.jsxs)(tw.l6,{items:[{value:"append",label:c("Append to existing keys")},{value:"replace",label:c("Replace all existing keys")}],onValueChange:t.onChange,value:t.value,children:[(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tw.bq,{children:(0,a.jsx)(tw.yv,{})})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"append",children:c("Append to existing keys")}),(0,a.jsx)(tw.eb,{value:"replace",children:c("Replace all exist
1ing keys")})]})})]}),(0,a.jsx)(sm.Rr,{children:"replace"===t.value?c("Replace mode: Will completely replace all existing keys"):c("Append mode: New keys will be added to the end of the existing key list")}),(0,a.jsx)(sm.C5,{})]})}}),!H&&"multi_to_single"===eN&&(0,a.jsx)(sm.zB,{control:ej.control,name:"multi_key_type",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Multi-Key Strategy")}),(0,a.jsxs)(tw.l6,{items:[{value:"random",label:c("Random")},{value:"polling",label:c("Polling")}],onValueChange:t.onChange,value:t.value,children:[(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tw.bq,{children:(0,a.jsx)(tw.yv,{})})}),(0,a.jsx)(tw.gC,{alignItemWithTrigger:!1,children:(0,a.jsxs)(tw.s3,{children:[(0,a.jsx)(tw.eb,{value:"random",children:c("Random")}),(0,a.jsx)(tw.eb,{value:"polling",children:c("Polling")})]})})]}),(0,a.jsx)(sm.Rr,{children:"polling"===ew?(0,a.jsx)("span",{className:"text-warning",children:c("Polling mode requires Redis and memory cache, otherwise performance will be significantly degraded")}):c("Randomly select a key from the pool for each request")}),(0,a.jsx)(sm.C5,{})]})}})]})]}),(0,a.jsx)(ag,{children:(0,a.jsxs)("div",{className:"space-y-5",children:[(0,a.jsxs)("div",{className:"border-border/60 bg-muted/10 rounded-lg border p-4",children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"models",render:()=>(0,a.jsxs)(sm.eI,{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)(sm.lR,{children:c("Models *")}),(0,a.jsx)(sm.Rr,{children:c("List of models supported by this channel. Use comma to separate multiple models.")})]}),(0,a.jsx)(sc.E,{variant:"outline",className:"w-fit",children:c("Selected {{count}}",{count:eK.length})})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(se.K,{options:e0,selected:eK,onChange:tf,placeholder:c("Select models or add custom ones"),allowCreate:!0,createLabel:'Add custom model "{{value}}"',maxVisibleChips:8})}),e1.exposedTargetModels.length>0&&(0,a.jsx)(t7.Fc,{className:"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-50",children:(0,a.jsxs)(t7.TN,{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("span",{children:[c("The mapped upstream model(s)")," ",aj(e1.exposedTargetModels)," ",c("are also listed here. Remove them from Models to keep the `/v1/models` response user-friendly and hide vendor-specific names.")]}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{let e=new Set(e1.exposedTargetModels);td(eK.filter(t=>!e.has(t)))},children:c("Remove mapped targets")})]})}),(0,a.jsx)(sm.C5,{})]})}),(0,a.jsx)(tV.w,{className:"my-4"}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:c("Quick actions")}),(0,a.jsx)("p",{className:"text-muted-foreground text-xs",children:c("Use presets or upstream discovery to populate the model list faster.")})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:tm,disabled:!eD.length,children:[(0,a.jsx)(ta.iUU,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),c("Fill Related Models")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:th,disabled:!eJ.length,children:[(0,a.jsx)(ta.FWt,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),c("Fill All Models")]}),ey.has(eS)&&(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:tc,children:[(0,a.jsx)(ta.sUz,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),c("Fetch from Upstream")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:tx,disabled:0===eK.length,children:[(0,a.jsx)(ta.QRo,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),c("Copy All")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:tp,disabled:0===eK.length,children:[(0,a.jsx)(ta.Xn5,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),c("Clear All")]})]}),eq.length>0&&(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,a.jsxs)("span",{className:"text-muted-foreground text-xs",children:[c("Preset groups"),":"]}),eq.map(e=>(0,a.jsx)(tr.$,{type:"button",variant:"secondary",size:"sm",onClick:()=>tg(e),children:e.name},e.id))]})]})]}),(0,a.jsx)("div",{className:"border-border/60 rounded-lg border p-4",children:(0,a.jsx)(sm.zB,{control:ej.control,name:"model_mapping",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"space-y-3",children:[(0,a.jsx)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(sm.lR,{className:"mb-0",children:c("Model Mapping")}),(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"icon-sm",className:"text-muted-foreground hover:text-foreground size-auto p-0","aria-label":c("How model mapping works")}),children:(0,a.jsx)(ta.mNh,{className:"h-4 w-4","aria-hidden":"true"})}),(0,a.jsxs)(tR.ZI,{side:"top",align:"start",className:"max-w-xs space-y-2 text-left",children:[(0,a.jsx)("p",{className:"text-xs font-semibold tracking-wide uppercase",children:c("Request flow")}),(0,a.jsxs)("div",{className:"space-y-1 font-mono text-xs",children:[e4.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsx)("span",{children:e.source}),(0,a.jsx)(ta.Qpb,{className:"h-3.5 w-3.5 opacity-70","aria-hidden":"true"}),(0,a.jsx)("span",{children:e.target})]},`${e.source}-${e.target}`)),e3>0&&(0,a.jsxs)("div",{className:"text-[11px] opacity-70",children:["+",e3," ",c("more mapping"),e3>1?"s":""]})]}),(0,a.jsx)("p",{className:"text-[11px] leading-relaxed opacity-80",children:c("Users call the model on the left. The platform forwards the request to the upstream model on the right.")})]})]})]}),(0,a.jsx)(sm.Rr,{children:c("Map request model names to actual provider model names (JSON format)")})]})}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(sr,{value:t.value||"",onChange:t.onChange,disabled:tA,sourceModelOptions:eK,targetModelOptions:e0.map(e=>e.value)})}),e1.invalidJson&&(0,a.jsx)(t7.Fc,{variant:"destructive",children:(0,a.jsxs)(t7.TN,{children:[c("Model Mapping must be a JSON object like")," ",(0,a.jsx)("code",{className:"font-mono",children:'{"gpt-4":"Azure-GPT4"}'}),c(". Please fix the JSON before saving.")]})}),e1.missingSourceModels.length>0&&(0,a.jsx)(t7.Fc,{className:"border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-50",children:(0,a.jsxs)(t7.TN,{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,a.jsxs)("span",{children:[c("Add")," ",aj(e1.missingSourceModels)," ",c("to the Models list so users can use them before the mapping sends traffic upstream.")]}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{td([...eK,...e1.missingSourceModels])},children:c("Add missing models")})]})}),(0,a.jsx)(sm.C5,{})]})}})}),(0,a.jsx)("div",{className:"border-border/60 rounded-lg border p-4",children:(0,a.jsx)(sm.zB,{control:ej.control,name:"group",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)(sm.lR,{children:c("Groups *")}),(0,a.jsx)(sm.Rr,{children:c("User groups that can access this channel. ")})]}),(0,a.jsx)(sm.MJ,{children:et?(0,a.jsx)(t9.E,{className:"h-10 w-full"}):(0,a.jsx)(se.K,{options:eV,selected:t.value,onChange:t.onChange,placeholder:c("Please Select user groups that can access this channel.")})}),(0,a.jsx)(sm.C5,{})]})}})})]})}),(0,a.jsxs)(au,{open:q,onOpenChange:tF,children:[(0,a.jsxs)("div",{className:(0,tO.nP)(),children:[(0,a.jsx)(ab,{title:c("Routing & Overrides"),icon:(0,a.jsx)(ta.qhu,{className:"h-4 w-4"})}),(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsx)(a_,{title:c("Routing Strategy"),icon:(0,a.jsx)(ta.qhu,{className:"h-3.5 w-3.5"})}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"priority",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Priority")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{type:"number",placeholder:"0",...t,onChange:e=>t.onChange(Number(e.target.value))})}),(0,a.jsx)(sm.Rr,{children:c("Higher priority channels are selected first")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"weight",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Weight")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{type:"number",placeholder:"0",...t,onChange:e=>t.onChange(Number(e.target.value))})}),(0,a.jsx)(sm.Rr,{children:c("Used for load balancing. Higher weight = more requests")}),(0,a.jsx)(sm.C5,{})]})}})]}),(0,a.jsx)(sm.zB,{control:ej.control,name:"test_model",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Test Model")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("Model to use for testing"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Model to use when testing channel connectivity")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"auto_ban",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Auto Ban")}),(0,a.jsx)(sm.Rr,{children:c("Automatically disable channel on repeated failures")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:1===t.value,onCheckedChange:e=>t.onChange(+!!e)})})]})}})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-4 border-t pt-4",children:[(0,a.jsx)(a_,{title:c("Internal Notes"),icon:(0,a.jsx)(ta.iUU,{className:"h-3.5 w-3.5"})}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"tag",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Tag")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("Optional tag for grouping channels"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Group channels by tag for batch operations")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"remark",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Remark")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tK.T,{placeholder:c("Optional notes about this channel"),rows:2,...t})}),(0,a.jsx)(sm.Rr,{children:c("Internal notes (not shown to users)")}),(0,a.jsx)(sm.C5,{})]})}})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-4 border-t pt-4",children:[(0,a.jsx)(a_,{title:c("Override Rules"),icon:(0,a.jsx)(ta.CyN,{className:"h-3.5 w-3.5"})}),(0,a.jsx)(sm.zB,{control:ej.control,name:"status_code_mapping",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)(sm.lR,{children:c("Status Code Mapping")}),(0,a.jsx)(sm.Rr,{children:c("Map upstream status codes to different c
1odes")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(sh.i,{value:t.value||"",onChange:t.onChange,disabled:tA,keyPlaceholder:"400",valuePlaceholder:"500",keyLabel:"Original Code",valueLabel:"Mapped Code",emptyMessage:c("No status code mappings configured."),template:{400:"500",429:"503"},valueType:"string"})}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"param_override",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"space-y-3 border-t pt-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)(sm.lR,{children:c("Parameter Override")}),(0,a.jsx)(sm.Rr,{children:c("Override request parameters. Cannot override stream parameter.")})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>L(!0),children:[(0,a.jsx)(ta.HMp,{className:"mr-2 h-4 w-4"}),c("Visual edit")]}),(0,a.jsxs)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{t.onChange(JSON.stringify({operations:[{path:"temperature",mode:"set",value:.7,conditions:[{path:"model",mode:"prefix",value:"gpt"}],logic:"AND"}]},null,2))},children:[(0,a.jsx)(ta.CyN,{className:"mr-2 h-4 w-4"}),c("New Format Template")]}),(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>t.onChange(""),children:c("Clear")})]})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tK.T,{value:t.value||"",onChange:t.onChange,disabled:tA,rows:8,placeholder:c("Override request parameters. Cannot override stream parameter."),className:"max-h-72 min-h-40 resize-y overflow-auto font-mono text-xs"})}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"header_override",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"space-y-3 border-t pt-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)(sm.lR,{children:c("Request Header Override")}),(0,a.jsx)(sm.Rr,{children:c("Override request headers")})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>t.onChange(JSON.stringify({"*":!0,"re:^X-Trace-.*$":!0,"X-Foo":"{client_header:X-Foo}",Authorization:"Bearer {api_key}"},null,2)),children:c("Fill Template")}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>t.onChange(JSON.stringify({"*":!0},null,2)),children:c("Passthrough Template")}),(0,a.jsx)(tr.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{try{let e=JSON.parse(t.value||"{}");t.onChange(JSON.stringify(e,null,2))}catch(e){}},children:c("Format")}),(0,a.jsx)(tr.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>t.onChange(""),children:c("Clear")})]})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tK.T,{className:"font-mono text-sm",rows:6,value:t.value||"",onChange:t.onChange,disabled:tA,placeholder:c("Enter JSON to override request headers")})}),(0,a.jsxs)(sm.Rr,{className:"text-xs",children:[c("Supported variables"),":"," ",(0,a.jsx)("code",{className:"bg-muted rounded px-1 py-0.5",children:"{api_key}"})," ","â ",c("Channel key"),","," ",(0,a.jsx)("code",{className:"bg-muted rounded px-1 py-0.5",children:"{client_header:NAME}"})," ","â ",c("Client header value")]}),(0,a.jsx)(sm.C5,{})]})}})]})]}),(0,a.jsxs)("div",{className:(0,tO.nP)(),children:[(0,a.jsx)(ab,{title:c("Channel Extra Settings"),icon:(0,a.jsx)(ta.wB_,{className:"h-4 w-4"})}),(1===eS||14===eS)&&(0,a.jsxs)("div",{className:"border-border/60 flex flex-col gap-3 border-y py-4",children:[(0,a.jsx)(a_,{title:c("Field passthrough controls"),icon:(0,a.jsx)(ta.lCl,{className:"h-3.5 w-3.5"})}),(0,a.jsxs)("div",{className:"divide-border space-y-0 divide-y border-y",children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"allow_service_tier",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow service_tier passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the service_tier field")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),1===eS&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"disable_store",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Disable store passthrough")}),(0,a.jsx)(sm.Rr,{children:c("When enabled, the store field will be blocked")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"allow_safety_identifier",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow safety_identifier passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the safety_identifier field")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"allow_include_obfuscation",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow include usage obfuscation passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the include field for usage obfuscation")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"allow_inference_geo",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow inference geography passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the inference_geo field for geographic routing")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}})]}),14===eS&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"allow_inference_geo",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow inference_geo passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the inference_geo field for Claude data residency region control")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"allow_speed",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow speed passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the speed field for Claude inference speed mode control")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"claude_beta_query",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between gap-3 px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{className:"text-sm",children:c("Allow Claude beta query passthrough")}),(0,a.jsx)(sm.Rr,{children:c("Pass through the anthropic-beta header for beta features")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}})]})]})]}),(0,a.jsxs)("div",{className:"divide-border space-y-0 divide-y border-y",children:[1===eS&&(0,a.jsx)(sm.zB,{control:ej.control,name:"force_format",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Force Format")}),(0,a.jsx)(sm.Rr,{children:c("Force format response to OpenAI standard (OpenAI channel only)")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"thinking_to_content",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Thinking to Content")}),(0,a.jsx)(sm.Rr,{children:c("Convert reasoning_content to <think> tag in content")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"pass_through_body_enabled",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Pass Through Body")}),(0,a.jsx)(sm.Rr,{children:c("Pass request body directly to upstream")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}})]}),(0,a.jsx)(sm.zB,{control:ej.control,name:"proxy",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Proxy Address")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("socks5://user:pass@host:port"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Network proxy for this channel (supports socks5 protocol)")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"system_prompt",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("System Prompt")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tK.T,{placeholder:c("Enter system prompt (user prompt takes priority)"),rows:3,...t})}),(0,a.jsx)(sm.Rr,{children:c("Default system prompt for this channel")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"system_prompt_override",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("System Prompt Concatenation")}),(0,a.jsx)(sm.Rr,{children:c("Concatenate channel system prompt with user's prompt")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),ey.has(eS)&&(0,a.jsxs)("div",{className:"border-border/60 flex flex-col gap-3 border-y py-4",children:[(0,a.jsx)(a_,{title:c("Upstream Model Detection Settings"),icon:(0,a.jsx)(ta.e9t,{className:"h-3.5 w-3.5"})}),(0,a.jsxs)("div",{className:"divide-border space-y-0 divide-y border-y",children:[(0,a.jsx)(sm.zB,{control:ej.control,name:"upstream_model_update_check_enabled",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Upstream Model Update Check")}),(0,a.jsx)(sm.Rr,{children:c("Periodically check for upstream model changes")}
1)]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,onCheckedChange:t.onChange})})]})}}),(0,a.jsx)(sm.zB,{control:ej.control,name:"upstream_model_update_auto_sync_enabled",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{className:"flex items-center justify-between px-4 py-3",children:[(0,a.jsxs)("div",{className:"space-y-0.5",children:[(0,a.jsx)(sm.lR,{children:c("Auto Sync Upstream Models")}),(0,a.jsx)(sm.Rr,{children:c("Automatically sync model list when upstream changes are detected")})]}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(tC.d,{checked:t.value,disabled:!eF,onCheckedChange:t.onChange})})]})}})]}),(0,a.jsx)(sm.zB,{control:ej.control,name:"upstream_model_update_ignored_models",render:e=>{let{field:t}=e;return(0,a.jsxs)(sm.eI,{children:[(0,a.jsx)(sm.lR,{children:c("Ignored upstream models")}),(0,a.jsx)(sm.MJ,{children:(0,a.jsx)(t_.p,{placeholder:c("e.g., gpt-4.1-nano,regex:^claude-.*$,regex:^sora-.*$"),...t})}),(0,a.jsx)(sm.Rr,{children:c("Comma-separated exact model names. Prefix with regex: to ignore by regular expression.")}),(0,a.jsx)(sm.C5,{})]})}}),(0,a.jsxs)("div",{className:"text-muted-foreground space-y-2 border-t pt-3 text-xs",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("span",{className:"text-foreground font-medium",children:[c("Last check time"),":"]})," ",!Number.isFinite(t=Number(e5.lastCheckTime))||t<=0?"-":new Date(1e3*t).toLocaleString()]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("span",{className:"text-foreground font-medium",children:[c("Last detected addable models"),":"]})," ",0===e5.detectedModels.length?c("None"):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"break-all",children:e6.join(", ")}),te>0&&(0,a.jsx)("span",{className:"ml-1",children:c("({{total}} total, {{omit}} omitted)",{total:e5.detectedModels.length,omit:te})})]})]})]})]})]})]})]})})}),(0,a.jsxs)(tk.XW,{className:(0,tO.Jx)(),children:[(0,a.jsx)(tk.kN,{render:(0,a.jsx)(tr.$,{variant:"outline",disabled:tA}),children:c("Cancel")}),(0,a.jsxs)(tr.$,{form:"channel-form",type:"submit",disabled:tA,children:[tA&&(0,a.jsx)(ta.krw,{className:"mr-2 h-4 w-4 animate-spin"}),H?c("Update Channel"):c("Save changes")]})]})]})}),K&&(0,a.jsx)(aa,{open:K,value:ej.watch("param_override")||"",onOpenChange:L,onSave:e=>{ej.setValue("param_override",e,{shouldDirty:!0,shouldValidate:!0})}}),(0,a.jsx)(tG,{open:p,onOpenChange:x,onModelsSelected:e=>{ej.setValue("models",e7(e))},redirectModels:eU,redirectSourceModels:eZ,customFetcher:H?void 0:tu,channelName:H?void 0:eM?.trim(),existingModelsOverride:H?void 0:e8(ej.getValues("models")||"")}),(0,a.jsx)(s_,{open:en,onOpenChange:e=>{e||ep()},methods:eo,state:ed,onVerify:async(e,t)=>{await em(e,t)},onCancel:ep,onCodeChange:ex,onMethodChange:eg}),(0,a.jsx)(sM,{open:T,missingModels:B,onConfirm:tv,onOpenChange:P}),(0,a.jsx)(ac,{open:M,onOpenChange:e=>{e||tN(!1)},detailItems:F,onConfirm:()=>tN(!0)})]})}function aw(){let{open:e,setOpen:t,currentRow:s,upstream:r}=ts();return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(aN,{open:"create-channel"===e||"update-channel"===e,onOpenChange:e=>!e&&t(null),currentRow:"update-channel"===e?s:null}),(0,a.jsx)(t$,{open:"test-channel"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(tf,{open:"balance-query"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(tG,{open:"fetch-models"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(t8,{open:"ollama-models"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(tD,{open:"copy-channel"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(t0,{open:"multi-key-manage"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(sl,{open:"tag-batch-edit"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(tH,{open:"edit-tag"===e,onOpenChange:e=>!e&&t(null)}),(0,a.jsx)(sn,{open:r.showModal,addModels:r.addModels,removeModels:r.removeModels,preferredTab:r.preferredTab,confirmLoading:r.applyLoading,onConfirm:r.applyUpdates,onCancel:r.closeModal})]})}var ak=s(43631);function aC(){let{t:e}=(0,r.Bd)(),{setOpen:t,setCurrentRow:s,enableTagMode:l,setEnableTagMode:o,idSort:d,setIdSort:c,upstream:u}=ts(),m=(0,i.jE)(),[h,p]=(0,n.useState)(!1),x=e=>{localStorage.setItem("enable-tag-mode",String(e)),o(e)},g=e=>{localStorage.setItem("channels-id-sort",String(e)),c(e)};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsxs)("div",{className:"hidden items-center gap-2 rounded-md border px-3 py-1.5 sm:flex",children:[(0,a.jsx)(ta.YDL,{className:"text-muted-foreground h-4 w-4"}),(0,a.jsx)(tN.J,{htmlFor:"tag-mode",className:"cursor-pointer text-sm",children:e("Tag Mode")}),(0,a.jsx)(tC.d,{id:"tag-mode",checked:l,onCheckedChange:x})]}),(0,a.jsxs)("div",{className:"hidden items-center gap-2 rounded-md border px-3 py-1.5 sm:flex",children:[(0,a.jsx)(ta.gE3,{className:"text-muted-foreground h-4 w-4"}),(0,a.jsx)(tN.J,{htmlFor:"id-sort",className:"cursor-pointer text-sm",children:e("Sort by ID")}),(0,a.jsx)(tC.d,{id:"id-sort",checked:d,onCheckedChange:g})]}),(0,a.jsxs)(tr.$,{onClick:()=>{s(null),t("create-channel")},size:"sm",children:[(0,a.jsx)(ta.FWt,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"max-sm:hidden",children:e("Create Channel")}),(0,a.jsx)("span",{className:"sm:hidden",children:e("Create")})]}
1),(0,a.jsxs)(ak.rI,{children:[(0,a.jsx)(ak.ty,{render:(0,a.jsx)(tr.$,{variant:"outline",size:"sm"}),children:(0,a.jsx)(ta.a4,{className:"h-4 w-4"})}),(0,a.jsxs)(ak.SQ,{align:"end",className:"w-56",children:[(0,a.jsxs)(ak.hO,{className:"sm:hidden",checked:l,onCheckedChange:x,children:[(0,a.jsx)(ta.YDL,{className:"mr-2 h-4 w-4"}),e("Tag Mode")]}),(0,a.jsxs)(ak.hO,{className:"sm:hidden",checked:d,onCheckedChange:g,children:[(0,a.jsx)(ta.gE3,{className:"mr-2 h-4 w-4"}),e("Sort by ID")]}),(0,a.jsx)(ak.mB,{className:"sm:hidden"}),(0,a.jsxs)(ak._2,{onClick:()=>{eJ(m)},children:[e("Test All Channels"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.jUT,{className:"h-4 w-4"})})]}),(0,a.jsxs)(ak._2,{onClick:()=>{eD(m)},children:[e("Update All Balances"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.G9t,{className:"h-4 w-4"})})]}),(0,a.jsx)(ak.mB,{}),(0,a.jsxs)(ak._2,{onClick:()=>u.detectAllUpdates(),disabled:u.detectAllLoading,children:[e("Detect All Upstream Updates"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.e9t,{className:"h-4 w-4"})})]}),(0,a.jsxs)(ak._2,{onClick:()=>u.applyAllUpdates(),disabled:u.applyAllLoading,children:[e("Apply All Upstream Updates"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.nJw,{className:"h-4 w-4"})})]}),(0,a.jsx)(ak.mB,{}),(0,a.jsxs)(ak._2,{onClick:()=>{eB(m,e=>{})},children:[e("Fix Abilities"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.W$k,{className:"h-4 w-4"})})]}),(0,a.jsx)(ak.mB,{}),(0,a.jsxs)(ak._2,{onSelect:e=>{e.preventDefault(),p(!0)},className:"text-destructive focus:text-destructive",children:[e("Delete All Disabled"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.TBR,{className:"h-4 w-4"})})]})]})]})]}),(0,a.jsx)(tX.T,{open:h,onOpenChange:p,title:e("Delete All Disabled Channels?"),desc:"This will permanently delete all manually and automatically disabled channels. This action cannot be undone.",destructive:!0,handleConfirm:()=>{eP(m,e=>{}),p(!1)}})]})}var aS=s(2718),aR=s(11564),aA=s(74028),aM=s(72202),aO=s(21258);function aI(e){let{text:t,className:s,maxWidth:r="max-w-[200px]",side:l="top"}=e;return(0,a.jsx)(tR.Bc,{delay:300,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("span",{className:(0,st.cn)("block truncate",r,s)}),children:t}),(0,a.jsx)(tR.ZI,{side:l,className:"max-w-xs break-all",children:t})]})})}function aF(e){let{row:t}=e,{t:s}=(0,r.Bd)(),l=t.original,{setOpen:o,setCurrentRow:d,upstream:c}=ts(),m=(0,i.jE)(),[h,p]=(0,n.useState)(!1),[x,g]=(0,n.useState)(!1),[f,j]=(0,n.useState)(!1),y=1===l.status,v=e4(l),b=async e=>{e.stopPropagation(),g(!0);try{await eA(l.id,void 0,()=>{m.invalidateQueries({queryKey:e_.lists()})})}finally{g(!1)}},_=async e=>{e?.stopPropagation(),j(!0);try{await ek(l.id,l.status,m)}finally{j(!1)}};return(0,a.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(tr.$,{variant:"ghost",size:"icon-sm",onClick:b,disabled:x,"aria-label":s("Test Connection")}),children:x?(0,a.jsx)(ta.krw,{className:"size-4 animate-spin"}):(0,a.jsx)(ta._I2,{className:"size-4"})}),(0,a.jsx)(tR.ZI,{children:s("Test Connection")})]}),(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(tr.$,{variant:"ghost",size:"icon-sm",onClick:_,disabled:f,"aria-label":s(y?"Disable":"Enable"),className:y?"text-destructive hover:text-destructive":"text-emerald-600 hover:text-emerald-600 dark:text-emerald-400 dark:hover:text-emerald-400"}),children:f?(0,a.jsx)(ta.krw,{className:"size-4 animate-spin"}):y?(0,a.jsx)(ta.$o3,{className:"size-4"}):(0,a.jsx)(ta.aJd,{className:"size-4"})}),(0,a.jsx)(tR.ZI,{children:s(y?"Disable":"Enable")})]}),(0,a.jsxs)(ak.rI,{children:[(0,a.jsxs)(ak.ty,{render:(0,a.jsx)(tr.$,{variant:"ghost",className:"data-popup-open:bg-muted flex h-8 w-8 p-0"}),children:[(0,a.jsx)(ta.a4,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:s("Open menu")})]}),(0,a.jsxs)(ak.SQ,{align:"end",className:"w-48",children:[(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("update-channel")},children:[s("Edit"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.gHP,{size:16})})]}),(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("test-channel")},children:[s("Test Connection"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.jUT,{size:16})})]}),(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("balance-query")},children:[s("Query Balance"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.G9t,{size:16})})]}),(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("fetch-models")},children:[s("Fetch Models"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.f5X,{size:16})})]}),ey.has(l.type)&&(0,a.jsxs)(ak._2,{onClick:()=>{let e=u(l.settings);e.pendingAddModels.length>0||e.pendingRemoveModels.length>
10?c.openModal(l,e.pendingAddModels,e.pendingRemoveModels,e.pendingAddModels.length>0?"add":"remove"):c.detectChannelUpdates(l)},children:[s("Upstream Updates"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.e9t,{size:16})})]}),4===l.type&&(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("ollama-models")},children:[s("Manage Ollama Models"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.QQ,{size:16})})]}),(0,a.jsx)(ak.mB,{}),(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("copy-channel")},children:[s("Copy Channel"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.QRo,{size:16})})]}),v&&(0,a.jsxs)(ak._2,{onClick:()=>{d(l),o("multi-key-manage")},children:[s("Manage Keys"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.Uzy,{size:16})})]}),(0,a.jsx)(ak.mB,{}),(0,a.jsxs)(ak._2,{onSelect:e=>{e.preventDefault(),p(!0)},className:"text-destructive focus:text-destructive",children:[s("Delete"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.TBR,{size:16})})]})]})]}),(0,a.jsx)(tX.T,{open:h,onOpenChange:p,title:s("Delete Channel"),desc:`Are you sure you want to delete "${l.name}"? This action cannot be undone.`,confirmText:"Delete",destructive:!0,handleConfirm:()=>{eC(l.id,m),p(!1)}})]})}function az(e){let{row:t}=e,{t:s}=(0,r.Bd)(),l=t.original.tag,{setOpen:n,setCurrentTag:o}=ts(),d=(0,i.jE)();return l?(0,a.jsxs)(ak.rI,{children:[(0,a.jsxs)(ak.ty,{render:(0,a.jsx)(tr.$,{variant:"ghost",className:"data-popup-open:bg-muted flex h-8 w-8 p-0"}),children:[(0,a.jsx)(ta.a4,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:s("Open menu")})]}),(0,a.jsxs)(ak.SQ,{align:"end",className:"w-48",children:[(0,a.jsxs)(ak._2,{onClick:()=>{o(l),n("edit-tag")},children:[s("Edit Tag"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.ffu,{size:16})})]}),(0,a.jsxs)(ak._2,{onClick:()=>{o(l),n("tag-batch-edit")},children:[s("Batch Edit"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.gHP,{size:16})})]}),(0,a.jsx)(ak.mB,{}),(0,a.jsxs)(ak._2,{onClick:()=>{e$(l,d)},children:[s("Enable All"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.aJd,{size:16})})]}),(0,a.jsxs)(ak._2,{onClick:()=>{eT(l,d)},children:[s("Disable All"),(0,a.jsx)(ak.V0,{children:(0,a.jsx)(ta.$o3,{size:16})})]})]})]}):null}function aE(e){let{value:t,onChange:s,min:r=0,max:l,step:i=1,disabled:o=!1,className:d,label:c}=e,[u,m]=(0,n.useState)(String(t??0)),[h,p]=(0,n.useState)(!1),x=(0,n.useRef)(null);(0,n.useEffect)(()=>{h||m(String(t??0))},[t,h]);let g=e=>{let t=e;return void 0!==r&&(t=Math.max(r,t)),void 0!==l&&(t=Math.min(l,t)),t},f=()=>{p(!1);let e=Number(u);if(isNaN(e)||""===u||"-"===u)return void m(String(t??0));let a=g(e);m(String(a)),a!==(t??0)&&s(a)},j=void 0!==r&&Number(u)<=r,y=void 0!==l&&Number(u)>=l;return(0,a.jsxs)("div",{className:(0,st.cn)("inline-flex items-center",d),children:[c&&(0,a.jsx)(tN.J,{className:"text-muted-foreground mr-1.5 text-xs",children:c}),(0,a.jsxs)("div",{className:(0,st.cn)("group/spinner inline-flex h-7 items-center gap-0 rounded-md transition-colors",!o&&"hover:bg-muted/60",h&&"bg-muted/60 ring-primary/30 ring-1"),children:[(0,a.jsx)("button",{type:"button",tabIndex:-1,"aria-label":"Decrement",onClick:e=>{if(e.stopPropagation(),o)return;let t=g((Number(u)||0)-i);m(String(t)),s(t)},disabled:o||j,className:(0,st.cn)("text-muted-foreground/0 group-hover/spinner:text-muted-foreground flex h-7 w-6 shrink-0 items-center justify-center rounded-l-md transition-colors",!o&&!j&&"group-hover/spinner:hover:text-foreground group-hover/spinner:hover:bg-muted",(o||j)&&"group-hover/spinner:opacity-30"),children:(0,a.jsx)(ta.Hsy,{className:"size-3"})}),h?(0,a.jsx)("input",{ref:x,type:"text",value:u,onChange:e=>{let t=e.target.value;""===t||"-"===t?m(t):/^-?\d+$/.test(t)&&m(t)},onBlur:f,onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),f()):"Escape"===e.key&&(p(!1),m(String(t??0)))},className:"h-7 w-10 bg-transparent text-center font-mono text-sm outline-none",autoFocus:!0}):(0,a.jsx)("button",{type:"button",onClick:()=>{o||(p(!0),requestAnimationFrame(()=>x.current?.select()))},disabled:o,className:(0,st.cn)("h-7 min-w-8 cursor-text px-1 text-center font-mono text-sm tabular-nums",o&&"cursor-default opacity-50"),children:u}),(0,a.jsx)("button",{type:"button",tabIndex:-1,"aria-label":"Increment",onClick:e=>{if(e.stopPropagation(),o)return;let t=g((Number(u)||0)+i);m(String(t)),s(t)}
1,disabled:o||y,className:(0,st.cn)("text-muted-foreground/0 group-hover/spinner:text-muted-foreground flex h-7 w-6 shrink-0 items-center justify-center rounded-r-md transition-colors",!o&&!y&&"group-hover/spinner:hover:text-foreground group-hover/spinner:hover:bg-muted",(o||y)&&"group-hover/spinner:opacity-30"),children:(0,a.jsx)(ta.FWt,{className:"size-3"})})]})]})}function a$(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;return(0,a.jsx)(td.M8,{items:e,max:t,renderItem:e=>e})}function aT(e){let{channel:t}=e,{upstream:s,setCurrentRow:r}=ts();if(!ey.has(t.type))return null;let l=u(t.settings);if(!l.enabled)return null;let n=l.pendingAddModels.length,i=l.pendingRemoveModels.length;return 0===n&&0===i?null:(0,a.jsxs)("div",{className:"flex items-center gap-0.5",children:[n>0&&(0,a.jsx)(td.Wh,{label:`+${n}`,variant:"success",size:"sm",copyable:!1,className:"cursor-pointer",onClick:e=>{e.stopPropagation(),r(t),s.openModal(t,l.pendingAddModels,l.pendingRemoveModels,"add")}}),i>0&&(0,a.jsx)(td.Wh,{label:`-${i}`,variant:"danger",size:"sm",copyable:!1,className:"cursor-pointer",onClick:e=>{e.stopPropagation(),r(t),s.openModal(t,l.pendingAddModels,l.pendingRemoveModels,"remove")}})]})}function aP(e){let{channel:t}=e,{t:s}
1=(0,r.Bd)(),l=(0,i.jE)(),o=e6(t),d=t.priority,[c,u]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null);if(o){let e=t.tag||"",r=t.children?.length||0;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(aE,{value:d??0,onChange:e=>{h(e),u(!0)},min:-999}),(0,a.jsx)(tX.T,{open:c,onOpenChange:u,title:s("Confirm Batch Update"),desc:`This will update the priority to ${m} for all ${r} channel(s) with tag "${e}". Continue?`,confirmText:"Update",handleConfirm:()=>{null!==m&&eR(e,"priority",m,l),u(!1)}})]})}return(0,a.jsx)(aE,{value:d??0,onChange:e=>{eS(t.id,"priority",e,l)},min:-999})}function aB(e){let{channel:t}=e,{t:s}=(0,r.Bd)(),l=(0,i.jE)(),o=e6(t),d=t.weight,[c,u]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null);if(o){let e=t.tag||"",r=t.children?.length||0;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(aE,{value:d??0,onChange:e=>{h(e),u(!0)},min:0}),(0,a.jsx)(tX.T,{open:c,onOpenChange:u,title:s("Confirm Batch Update"),desc:`This will update the weight to ${m} for all ${r} channel(s) with tag "${e}". Continue?`,confirmText:"Update",handleConfirm:()=>{null!==m&&eR(e,"weight",m,l),u(!1)}})]})}return(0,a.jsx)(aE,{value:d??0,onChange:e=>{eS(t.id,"weight",e,l)},min:0})}function aJ(e){let{channel:t}=e,{t:s}=(0,r.Bd)(),l=(0,i.jE)(),d=e6(t),c=t.balance||0,u=t.used_quota||0,[m,h]=(0,n.useState)(!1),[x,g]=(0,n.useState)(!1),[f,j]=(0,n.useState)(null),y="Tokens"===(0,p.yz)()?" Tokens":"",v=e=>y&&"-"!==e?`${e}${y}`:e,b=v((0,e0.eN)(u)),_=v(null==c||Number.isNaN(c)?"-":(0,p.J5)(c,{digitsLarge:2,digitsSmall:4,abbreviate:!1})),N=`${s("Used:")} ${b}`,w=`${s("Remaining:")} ${_}`;if(d)return(0,a.jsx)(td.Wh,{label:N,variant:"neutral",size:"sm",copyable:!1,showDot:!1});let k=0===c?"neutral":c<1?"danger":c<10?"warning":"success",C=async()=>{if(!m){if(h(!0),57===t.type){try{let e=await E(t.id);if(!e.success)throw Error(e.message||s("Failed to fetch usage"));j(e),g(!0)}catch(e){o.oR.error(e instanceof Error?e.message:s("Failed to fetch usage"))}finally{h(!1)}return}await eO(t.id,l),h(!1)}};return(0,a.jsxs)(tR.Bc,{children:[(0,a.jsxs)("div",{className:"flex items-center gap-1",children:[(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(td.Wh,{label:b,variant:"neutral",size:"sm",copyable:!1,showDot:!1,className:"cursor-help"})}),(0,a.jsx)(tR.ZI,{children:(0,a.jsx)("p",{children:N})})]}),(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(td.Wh,{label:m?s("Updating..."):57===t.type?s("Account Info"):_,variant:57===t.type?"info":m?"neutral":k,size:"sm",copyable:!1,showDot:!1,className:"cursor-pointer",onClick:C})}),(0,a.jsxs)(tR.ZI,{children:[(0,a.jsx)("p",{children:57===t.type?s("Click to view Codex usage"):w}),57!==t.type&&(0,a.jsx)("p",{children:s("Click to update balance")})]})]})]}),(0,a.jsx)(tg,{open:x,onOpenChange:g,channelName:t.name,channelId:t.id,response:f,onRefresh:async()=>{if(!m){h(!0);try{let e=await E(t.id);if(!e.success)throw Error(e.message||s("Failed to fetch usage"));j(e)}catch(e){o.oR.error(e instanceof Error?e.message:s("Failed to fetch usage"))}finally{h(!1)}}},isRefreshing:m})]})}function aD(e){let{table:t}=e,{t:s}=(0,r.Bd)(),l=(0,i.jE)(),[o,d]=(0,n.useState)(!1),[c,u]=(0,n.use
1State)(!1),[m,h]=(0,n.useState)(""),p=t.getFilteredSelectedRowModel().rows.reduce((e,t)=>{let s=t.original.id;return"number"==typeof s&&e.push(s),e},[]),x=()=>{t.resetRowSelection()};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(tA.Of,{table:t,entityName:"channel",children:[(0,a.jsxs)(tR.m_,{children:[(0,a.jsxs)(tR.k$,{render:(0,a.jsx)(tr.$,{variant:"outline",size:"icon",onClick:()=>{eF(p,l,x)},className:"size-8","aria-label":s("Enable selected channels"),title:s("Enable selected channels")}),children:[(0,a.jsx)(ta.aJd,{}),(0,a.jsx)("span",{className:"sr-only",children:s("Enable selected channels")})]}),(0,a.jsx)(tR.ZI,{children:(0,a.jsx)("p",{children:s("Enable selected channels")})})]}),(0,a.jsxs)(tR.m_,{children:[(0,a.jsxs)(tR.k$,{render:(0,a.jsx)(tr.$,{variant:"outline",size:"icon",onClick:()=>{ez(p,l,x)},className:"size-8","aria-label":s("Disable selected channels"),title:s("Disable selected channels")}),children:[(0,a.jsx)(ta.$o3,{}),(0,a.jsx)("span",{className:"sr-only",children:s("Disable selected channels")})]}),(0,a.jsx)(tR.ZI,{children:(0,a.jsx)("p",{children:s("Disable selected channels")})})]}),(0,a.jsxs)(tR.m_,{children:[(0,a.jsxs)(tR.k$,{render:(0,a.jsx)(tr.$,{variant:"outline",size:"icon",onClick:()=>d(!0),className:"size-8","aria-label":s("Set tag for selected channels"),title:s("Set tag for selected channels")}),children:[(0,a.jsx)(ta.vwO,{}),(0,a.jsx)("span",{className:"sr-only",children:s("Set tag for selected channels")})]}),(0,a.jsx)(tR.ZI,{children:(0,a.jsx)("p",{children:s("Set tag for selected channels")})})]}),(0,a.jsxs)(tR.m_,{children:[(0,a.jsxs)(tR.k$,{render:(0,a.jsx)(tr.$,{variant:"destructive",size:"icon",onClick:()=>u(!0),className:"size-8","aria-label":s("Delete selected channels"),title:s("Delete selected channels")}),children:[(0,a.jsx)(ta.TBR,{}),(0,a.jsx)("span",{className:"sr-only",children:s("Delete selected channels")})]}),(0,a.jsx)(tR.ZI,{children:(0,a.jsx)("p",{children:s("Delete selected channels")})})]})]}),(0,a.jsx)(tl.lG,{open:o,onOpenChange:d,children:(0,a.jsxs)(tl.Cf,{children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:s("Set Tag")}),(0,a.jsxs)(tl.rr,{children:[s("Set a tag for")," ",p.length," ",s("selected channel(s). Leave empty to remove tag.")]})]}),(0,a.jsx)("div",{className:"grid gap-4 py-4",children:(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)(tN.J,{htmlFor:"tag",children:s("Tag")}),(0,a.jsx)(t_.p,{id:"tag",placeholder:s("Enter tag name (optional)"),value:m,onChange:e=>h(e.target.value)})]})}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:()=>{d(!1),h("")},children:s("Cancel")}),(0,a.jsx)(tr.$,{onClick:()=>{eE(p,m||null,l,()=>{d(!1),h(""),x()})},children:s("Set Tag")})]})]})}),(0,a.jsx)(tl.lG,{open:c,onOpenChange:u,children:(0,a.jsxs)(tl.Cf,{children:[(0,a.jsxs)(tl.c7,{children:[(0,a.jsx)(tl.L3,{children:s("Delete Channels?")}),(0,a.jsxs)(tl.rr,{children:[s("Are you sure you want to delete")," ",p.length," ",s("channel(s)? This action cannot be undone.")]})]}),(0,a.jsxs)(tl.Es,{children:[(0,a.jsx)(tr.$,{variant:"outline",onClick:()=>u(!1),children:s("Cancel")}),(0,a.jsx)(tr.$,{variant:"destructive",onClick:()=>{eI(p,l,()=>{u(!1),x()})},children:s("Delete")})]})]})})]})}let aq=(0,aS.GY)("/_authenticated/channels/"),aV=new Set(["id","name","priority","balance","response_time","test_time"]);function aK(){let{t:e}=(0,r.Bd)(),{enableTagMode:t,idSort:s}=ts(),l=(0,aR.Ub)("(max-width: 640px)"),[i,o]=(0,n.useState)([]),[d,c]=(0,n.useState)({models:!1,tag:!1}),[u,m]=(0,n.useState)({}),[h,p]=(0,n.useState)({}),{globalFilter:x,onGlobalFilterChange:g,columnFilters:y,onColumnFiltersChange:v,pagination:b,onPaginationChange:_,ensurePageInRange:N}=(0,aA.c)({search:aq.useSearch(),navigate:aq.useNavigate(),pagination:{defaultPage:1,defaultPageSize:l?10:20},globalFilter:{enabled:!0,key:"filter"}
1,columnFilters:[{columnId:"status",searchKey:"status",type:"array"},{columnId:"type",searchKey:"type",type:"array"},{columnId:"group",searchKey:"group",type:"array"},{columnId:"model",searchKey:"model",type:"string"}]}),w=y.find(e=>"status"===e.id)?.value||[],k=y.find(e=>"type"===e.id)?.value||[],C=y.find(e=>"group"===e.id)?.value||[],S=y.find(e=>"model"===e.id)?.value||"",[R,A]=(0,n.useState)(S),M=(0,aR.d7)(R,500);(0,n.useEffect)(()=>{A(S)},[S]),(0,n.useEffect)(()=>{M!==S&&v(e=>{let t=e.filter(e=>"model"!==e.id);return M?[...t,{id:"model",value:M}]:t})},[M,S,v]);let O=!!(x?.trim()||S.trim()),I=(0,n.useMemo)(()=>{let e=i[0];return e&&aV.has(e.id)?{sort_by:e.id,sort_order:e.desc?"desc":"asc"}:{}},[i]),{data:F}=(0,tq.I)({queryKey:["groups"],queryFn:Z}),z=(0,n.useMemo)(()=>(F?.data||[]).map(e=>({label:e,value:e})),[F]),{data:E,isLoading:$,isFetching:T}=(0,tq.I)({queryKey:e_.list({keyword:x,model:S,group:C.length>0&&!C.includes("all")?C[0]:void 0,status:w.length>0&&!w.includes("all")?w[0]:void 0,type:k.length>0&&!k.includes("all")?Number(k[0]):void 0,tag_mode:t,id_sort:s,...I,p:b.pageIndex+1,page_size:b.pageSize}),queryFn:async()=>O?j({keyword:x,model:S,group:C.length>0&&!C.includes("all")?C[0]:void 0,status:w.length>0&&!w.includes("all")?w[0]:void 0,type:k.length>0&&!k.includes("all")?Number(k[0]):void 0,tag_mode:t,id_sort:s,...I,p:b.pageIndex+1,page_size:b.pageSize}):f({group:C.length>0&&!C.includes("all")?C[0]:void 0,status:w.length>0&&!w.includes("all")?w[0]:void 0,type:k.length>0&&!k.includes("all")?Number(k[0]):void 0,tag_mode:t,id_sort:s,...I,p:b.pageIndex+1,page_size:b.pageSize}),placeholderData:e=>e}),P=(0,n.useMemo)(()=>{let e=E?.data?.items||[];return t&&e.length>0?function(e){let t=new Map,s=[];for(let a of e){let e=a.tag||"";if(!t.has(e)){let r={...a,key:e,id:e,tag:e,name:e,type:0,status:void 0,group:"",used_quota:0,response_time:0,priority:-1,weight:-1,balance:0,test_time:0,created_time:0,balance_updated_time:0,models:"",children:[]};t.set(e,r),s.push(r)}let r=t.get(e);r.children.push(a);let l=r.children.length;if(r.used_quota+=a.used_quota,r.response_time=(r.response_time*(l-1)+a.response_time)/l,-1===r.priority?r.priority=a.priority:r.priority!==a.priority&&(r.priority=null),-1===r.weight?r.weight=a.weight:r.weight!==a.weight&&(r.weight=null),""===r.group)r.group=a.group;else{let e=new Set(r.group.split(",").filter(Boolean));a.group.split(",").filter(Boolean).forEach(t=>{e.has(t)||(r.group+=","+t)})}1===a.status?r.status=1:void 0===r.status&&(r.status=a.status)}return s}(e):e},[E,t]),B=E?.data?.total||0,J=E?.data?.type_counts,D=function(){let{t:e}=(0,r.Bd)();return[{id:"select",header:e=>{let{table:t}=e;return(0,a.jsx)(tb.S,{checked:t.getIsAllPageRowsSelected(),indeterminate:t.getIsSomePageRowsSelected(),onCheckedChange:e=>t.toggleAllPageRowsSelected(!!e),"aria-label":"Select all"})},cell:e=>{let{row:t}=e;return e6(t.original)?null:(0,a.jsx)(tb.S,{checked:t.getIsSelected(),onCheckedChange:e=>t.toggleSelected(!!e),"aria-label":"Select row"})},enableSorting:!1,enableHiding:!1,size:40},{accessorKey:"id",meta:{label:e("ID"),mobileHidden:!0},header:e=>{let{column:t}=e;return(0,a.jsx)(aM.w,{column:t,title:"ID"})},cell:e=>{let{row:t}=e,s=t.getValue("id");return(0,a.jsx)(aO.C,{value:s})},size:80},{accessorKey:"name",meta:{label:e("Name"),mobileTitle:!0},header:t=>{let{column:s}=t;return(0,a.jsx)(aM.w,{column:s,title:e("Name")})},cell:t=>{let{row:s}=t,r=e6(s.original),l=s.getValue("name"),n=s.original;if(r){let e=s.original.tag||l,t=s.original.children?.length||0;return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(tr.$,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:s.getToggleExpandedHandler(),children:s.getIsExpanded()?(0,a.jsx)(ta.yQN,{className:"h-4 w-4"}):(0,a.jsx)(ta.c_$,{className:"h-4 w-4"})}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsxs)("span",{className:"font-semibold",children:["Tagï¼",e]}),(0,a.jsx)(td.Wh,{label:`${t} channels`,variant:"blue",size:"sm",copyable:!1})]})]})}let i=!0===function(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}(n.setting).pass_through_body_enabled,o=!!n.param_override?.trim();return(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(aI,{text:l,className:"font-medium",maxWidth:"max-w-[180px]"}),i&&(0,a.jsx)(tR.Bc,{delay:100,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(ta.hcu,{className:"h-3.5 w-3.5 flex-shrink-0 text-amber-500"})}),(0,a.jsx)(tR.ZI,{side:"top",children:e("Request body pass-through is enabled. The request body will be sent directly to the upstream without any conversion.")})]})}),o&&(0,a.jsx)(tR.Bc,{delay:100,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)(ta.lCl,{className:"text-info h-3.5 w-3.5 flex-shrink-0"})}),(0,a.jsx)(tR.ZI,{side:"top",children:e("Override request parameters")})]})}),(0,a.jsx)(aT,{channel:n})]}),n.remark&&(0,a.jsx)(tR.Bc,{delay:200,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("span",{className:"text-muted-foreground text-xs"}),children:(0,st.EJ)(n.remark,40)}),(0,a.jsx)(tR.ZI,{side:"bottom",className:"max-w-xs",children:n.remark})]})})]})})},minSize:200},{accessorKey:"type",meta:{label:e("Type")},header:e("Type"),cell:t=>{let{row:s}=t;if(e6(s.original))return(0,a.jsx)(td.Wh,{label:e("Tag Aggregate"),variant:"blue",size:"sm",copyable:!1});let r=s.getValue("type"),l=e(e1(r)),n=e2(r),i=(0,sd.Y)(`${n}.Color`,14),o=s.original,d=e4(o),c=o.channel_info?.multi_key_mode??"random",u="random"===c?ta.goF:ta.cMz,m="random"===c?e("Multi-key: Random rotation"):e("Multi-key: Polling rotation"),h=function(e){if(!e)return null;try{let t=JSON.parse(e);if(t&&"object"==typeof t)return t}catch{}return null}(o.other_info),p=h?.source==="ionet",x="string"==typeof h?.deployment_id?h?.deployment_id:void 0;return(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[d&&(0,a.jsx)(tR.Bc,{delay:100,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("span",{className:"border-border bg-muted text-primary inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-md border"}),children:(0,a.jsx)(u,{className:"h-3 w-3"})}),(0,a.jsx)(tR.ZI,{side:"top",children:m})]})}),(0,a.jsxs)(td.Wh,{autoColor:l,size:"sm",copyable:!1,showDot:!1,className:"gap-1 pl-1",children:[i,(0,a.jsx)("span",{className:"truncate",children:l})]}),p&&(0,a.jsx)(tR.Bc,{delay:100,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("span",{className:"flex cursor-pointer items-center gap-1.5 text-xs font-medium",onClick:e=>{if(e.stopPropagation(),!x)return;let t=`/models/deployments?dFilter=${encodeURIComponent(String(x))}`;window.open(t,"_blank","noopener")}}),children:(0,a.jsx)(td.Wh,{label:"IO.NET",variant:"purple",size:"sm",copyable:!1,className:"cursor-pointer"})}),(0,a.jsx)(tR.ZI,{side:"top",children:(0,a.jsxs)("div",{className:"max-w-xs space-y-1",children:[(0,a.jsx)("div",{className:"text-xs",children:e("From IO.NET deployment")}),x&&(0,a.jsxs)("div",{className:"text-muted-foreground font-mono text-xs",children:[e("Deployment ID"),": ",x]}),(0,a.jsx)("div",{className:"text-muted-foreground text-xs",children:e("Click to open deployment")})]})})]})})]})},filterFn:(e,t,s)=>!!(!s||0===s.length||s.includes("all"))||s.includes(String(e.getValue(t))),size:140,enableSorting:!1},{accessorKey:"status",meta:{label:e("Status"),mobileBadge:!0},header:e("Status"),cell:t=>{let{row:s}=t,r=e6(s.original),l=s.getValue("status"),n=s.original;if(r){let e=s.original.children?.length||0;
1return 1===l?(0,a.jsx)(td.Wh,{label:`Active (${e})`,variant:"success",size:"sm",copyable:!1}):(0,a.jsx)(td.Wh,{label:`Inactive (${e})`,variant:"neutral",size:"sm",copyable:!1})}let i=el[l]||el["0"],o=e4(n),d=n.channel_info?.multi_key_size??0,c=Math.max(0,d-(n.channel_info?.multi_key_status_list?Object.keys(n.channel_info.multi_key_status_list).length:0)),u=o&&d>0?`${e(i.label)} (${c}/${d})`:e(i.label);if(3===l){let t="",s="";try{let e=n.other_info?JSON.parse(n.other_info):null;e&&(t=e.status_reason||"",s=e.status_time?(0,e0.fk)(e.status_time):"")}catch{}if(t||s)return(0,a.jsx)(tR.Bc,{delay:100,children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("span",{}),children:(0,a.jsx)(td.Wh,{label:u,variant:i.variant,size:"sm",copyable:!1})}),(0,a.jsx)(tR.ZI,{side:"top",className:"max-w-xs",children:(0,a.jsxs)("div",{className:"space-y-1 text-xs",children:[t&&(0,a.jsxs)("div",{children:[e("Reason:")," ",t]}),s&&(0,a.jsxs)("div",{children:[e("Time:")," ",s]})]})})]})})}return(0,a.jsx)(td.Wh,{label:u,variant:i.variant,size:"sm",copyable:!1})},filterFn:(e,t,s)=>{if(!s||0===s.length||s.includes("all"))return!0;let a=e.getValue(t);return s.includes("enabled")?1===a:!!s.includes("disabled")&&1!==a},size:120,enableSorting:!1},{accessorKey:"models",meta:{label:e("Models"),mobileHidden:!0},header:e("Models"),cell:e=>{var t;let{row:s}=e,r=(t=s.getValue("models"))?t.split(",").map(e=>e.trim()).filter(e=>e.length>0):[];if(0===r.length)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let l=r.map((e,t)=>(0,a.jsx)(td.Wh,{label:e,autoColor:e,size:"sm",className:"font-mono"},t));return(0,a.jsx)(tR.Bc,{children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("div",{}),children:a$(l,2)}),r.length>2&&(0,a.jsx)(tR.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:l})})]})})},size:200,enableSorting:!1},{accessorKey:"group",meta:{label:e("Groups"),mobileHidden:!0},header:e("Groups"),cell:e=>{let{row:t}=e,s=e3(t.getValue("group")),r=s.map(e=>(0,a.jsx)(tL.d,{group:e,size:"sm"},e));return(0,a.jsx)(tR.Bc,{children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("div",{}),children:a$(r,2)}),s.length>2&&(0,a.jsx)(tR.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:r})})]})})},filterFn:(e,t,s)=>!!(!s||0===s.length||s.includes("all"))||e3(e.getValue(t)).some(e=>s.includes(e)),size:150,enableSorting:!1},{accessorKey:"tag",meta:{label:e("Tag"),mobileHidden:!0},header:e("Tag"),cell:e=>{let{row:t}=e,s=t.getValue("tag");return s?(0,a.jsx)(td.Wh,{label:s,autoColor:s,size:"sm"}):(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"})},size:120,enableSorting:!1},{accessorKey:"priority",meta:{label:e("Priority"),mobileHidden:!0},header:t=>{let{column:s}=t;return(0,a.jsx)(aM.w,{column:s,title:e("Priority")})},cell:e=>{let{row:t}=e;return(0,a.jsx)(aP,{channel:t.original})},size:100},{accessorKey:"weight",meta:{label:e("Weight"),mobileHidden:!0},header:e("Weight"),cell:e=>{let{row:t}=e;return(0,a.jsx)(aB,{channel:t.original})},size:90,enableSorting:!1},{accessorKey:"balance",meta:{label:e("Used / Remaining")},header:t=>{let{column:s}=t;return(0,a.jsx)(aM.w,{column:s,title:e("Used / Remaining")})},cell:e=>{let{row:t}=e;return(0,a.jsx)(aJ,{channel:t.original})},size:180},{accessorKey:"response_time",meta:{label:e("Response"),mobileHidden:!0},header:t=>{let{column:s}=t;return(0,a.jsx)(aM.w,{column:s,title:e("Response")})},cell:t=>{let{row:s}=t,r=s.getValue("response_time"),l=0===r?ej:r<=500?ep:r<=1e3?ex:r<=2e3?eg:ef;return(0,a.jsx)(td.Wh,{label:e5(r,e),variant:l.variant,size:"sm",copyable:!1})},size:110},{accessorKey:"test_time",meta:{label:e("Last Tested"),mobileHidden:!0},header:t=>{let{column:s}=t;return(0,a.jsx)(aM.w,{column:s,title:e("Last Tested")})},cell:e=>{let{row:t}=e,s=t.getValue("test_time");if(!s||0===s)return(0,a.jsx)("span",{className:"text-muted-foreground text-xs",children:"-"});let r=function(e){if(!e||0===e)return"Never";try{return(0,eZ.A)(1e3*e).fromNow()}catch{return"Unknown"}}(s),l=(0,e0.fk)(s);return(0,a.jsx)(tR.Bc,{children:(0,a.jsxs)(tR.m_,{children:[(0,a.jsx)(tR.k$,{render:(0,a.jsx)("span",{className:"text-muted-foreground cursor-pointer font-mono text-sm"}),children:r}),(0,a.jsx)(tR.ZI,{side:"top",children:(0,a.jsx)("p",{className:"font-mono text-sm",children:l})})]})})},size:120,enableSorting:!1},{id:"actions",cell:e=>{let{row:t}=e;return e6(t.original)?(0,a.jsx)(az,{row:t}):(0,a.jsx)(aF,{row:t})},size:132,enableSorting:!1,enableHiding:!1}]}(),q=(0,tj.N4)({data:P,columns:D,pageCount:Math.ceil(B/b.pageSize),state:{sorting:i,columnFilters:y,columnVisibility:d,rowSelection:u,pagination:b,expanded:h,globalFilter:x},enableRowSelection:e=>!e6(e.original),onRowSelectionChange:m,onSortingChange:e=>{o(t=>{let s="function"==typeof e?e(t):e;return b.pageIndex>0&&_({...b,pageIndex:0}),s})},onColumnFiltersChange:v,onColumnVisibilityChange:c,onPaginationChange:_,onExpandedChange:p,onGlobalFilterChange:g,getCoreRowModel:(0,ty.HT)(),getExpandedRowModel:(0,ty.D0)(),getSubRows:e=>e.children,manualPagination:!0,manualSorting:!0,manualFiltering:!0}),V=q.getPageCount();(0,n.useEffect)(()=>{N(V)},[V,N]);let K=(0,n.useMemo)(()=>{let t=J||{},s=Object.entries(t).map(e=>{let[t,s]=e;return{type:Number(t),count:Number(s)||0}}).filter(e=>e.type>0&&e.count>0).sort((t,s)=>{let a=e(e1(t.type)),r=e(e1(s.type));return a.localeCompare(r)}),a=k.find(e=>"all"!==e);if(a){let e=Number(a),r=s.some(t=>t.type===e);e>0&&!r&&s.push({type:e,count:Number(t[a])||0})}return[{label:"All Types",value:"all",count:Object.values(t).reduce((e,t)=>
1e+(Number(t)||0),0)},...s.map(e=>{let t=e2(e.type);return{label:e1(e.type),value:String(e.type),count:e.count,iconNode:(0,sd.Y)(`${t}.Color`,16)}})]},[e,J,k]),L=[{label:e("All Groups"),value:"all"},...z];return(0,a.jsx)(tA.cx,{table:q,columns:D,isLoading:$,isFetching:T,emptyTitle:e("No Channels Found"),emptyDescription:e("No channels available. Create your first channel to get started."),skeletonKeyPrefix:"channel-skeleton",applyHeaderSize:!0,toolbarProps:{searchPlaceholder:e("Filter by name, ID, or key..."),additionalSearch:(0,a.jsx)(t_.p,{placeholder:e("Filter by model..."),value:R,onChange:e=>A(e.target.value),className:"w-full sm:w-[150px] lg:w-[180px]"}),filters:[{columnId:"status",title:e("Status"),options:[...er],singleSelect:!0},{columnId:"type",title:e("Type"),options:K,singleSelect:!0},{columnId:"group",title:e("Group"),options:L,singleSelect:!0}]},getRowClassName:(e,t)=>{var s;let{isMobile:a}=t;return e6(s=e.original)||1===s.status?void 0:a?tA.Z0:tA.JM},bulkActions:(0,a.jsx)(aD,{table:q})})}let aL=function(){let{t:e}=(0,r.Bd)();return(0,a.jsxs)(tt,{children:[(0,a.jsxs)(l.Ni,{children:[(0,a.jsx)(l.Ni.Title,{children:e("Channels")}),(0,a.jsx)(l.Ni.Actions,{children:(0,a.jsx)(aC,{})}),(0,a.jsx)(l.Ni.Content,{children:(0,a.jsx)(aK,{})})]}),(0,a.jsx)(aw,{})]})}}}]);
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.