import{n as e}from"./chunk-B3pr0VN8.js";import{r as t}from"./appRole-COi4XJJR.js";var n=e({CUSTOM_MODEL_PREFIX:()=>v,deleteCustomModel:()=>g,extractCustomModelId:()=>b,formatCustomModelChoice:()=>x,getCustomModelById:()=>_,getCustomModelMarketError:()=>d,getCustomModels:()=>p,isCnAllowedCustomModel:()=>u,isCustomModelChoice:()=>y,providerLabel:()=>S,saveCustomModels:()=>m,upsertCustomModel:()=>h}),r=`custom_models_v1`,i=[`api.deepseek.com`,`dashscope.aliyuncs.com`,`open.bigmodel.cn`,`api.moonshot.cn`,`api.minimaxi.com`,`api.siliconflow.cn`,`api-inference.modelscope.cn`],a=(()=>{let e={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_API2_ORIGIN:`https://api2.bysjob.com`,VITE_APP_ROLE:`jobseeker`,VITE_EXTENSION_MARKET:`intl`,VITE_EXTENSION_TEST_MODE:``,VITE_WEB_BUILD_ID:`20260701110412`};return e.DEV?!0:/^(1|true|yes|on)$/i.test(String(e.VITE_EXTENSION_TEST_MODE||``).trim())})(),o=e=>e===`localhost`||e===`127.0.0.1`||e===`::1`,s=()=>{try{let e=new Uint8Array(12);return crypto.getRandomValues(e),`cm_${Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}catch{return`cm_${Math.random().toString(16).slice(2)}_${Date.now().toString(16)}`}},c=e=>{if(!e||typeof e!=`object`)return null;let t=e.provider===`openai_compat`||e.provider===`anthropic`||e.provider===`gemini`?e.provider:null;if(!t)return null;let n=String(e.baseUrl||``).trim(),r=String(e.apiKey||``).trim(),i=String(e.modelId||``).trim();return!n||!r||!i?null:{id:String(e.id||``).trim()||s(),name:String(e.name||``).trim()||i,provider:t,baseUrl:n,apiKey:r,modelId:i}},l=e=>{try{return new URL(String(e||``).trim()).hostname.toLowerCase()}catch{return``}},u=e=>{if(t!==`cn`)return!0;if(e.provider!==`openai_compat`)return!1;let n=l(e.baseUrl);return n?o(n)?a:i.some(e=>n===e||n.endsWith(`.${e}`)):!1},d=e=>{if(t!==`cn`)return``;if(e.provider!==`openai_compat`)return`国内 BYOK 版仅允许 OpenAI 兼容格式的国内模型接口`;let n=l(e.baseUrl);return n&&o(n)&&!a?`国内正式 BYOK 版不允许使用本地中转地址，请直接填写已登记的国内模型接口域名`:u(e)?``:`国内 BYOK 版仅允许已登记的国内模型域名：DeepSeek、通义千问、智谱、Moonshot、MiniMax、ModelScope、SiliconFlow 或其他已登记国内兼容接口`},f=e=>!!e,p=async()=>await new Promise(e=>{try{chrome.storage?.local?.get?.({[r]:[]},t=>{e((Array.isArray(t?.[r])?t[r]:[]).map(c).filter(f).filter(u))})}catch{e([])}}),m=async e=>{let t=(Array.isArray(e)?e:[]).map(c).filter(f).filter(u);return await new Promise((e,n)=>{try{chrome.storage?.local?.set?.({[r]:t},()=>{let t=chrome.runtime?.lastError;t?n(t):e()})}catch(e){n(e)}})},h=async e=>{let t=c({...e,id:e.id||s()});if(!t)throw Error(`模型配置不完整：需要 厂商、Base URL、API Key、模型 ID`);let n=d(t);if(n)throw Error(n);let r=await p(),i=r.findIndex(e=>e.id===t.id);return i>=0?r[i]=t:r.push(t),await m(r),t},g=async e=>{await m((await p()).filter(t=>t.id!==String(e||``).trim()))},_=async e=>(await p()).find(t=>t.id===String(e||``).trim())||null,v=`custom:`,y=e=>String(e||``).startsWith(v),b=e=>{let t=String(e||``);return t.startsWith(`custom:`)?t.slice(7):``},x=e=>`${v}${e}`,S=e=>e===`anthropic`?`Anthropic`:e===`gemini`?`Gemini`:`OpenAI 兼容`;export{d as a,S as c,x as i,h as l,n,p as o,g as r,y as s,v as t};