var d=(n,s,a)=>new Promise((r,i)=>{var f=c=>{try{h(a.next(c))}catch(p){i(p)}},g=c=>{try{h(a.throw(c))}catch(p){i(p)}},h=c=>c.done?r(c.value):Promise.resolve(c.value).then(f,g);h((a=a.apply(n,s)).next())});import{a as v,d as j,r as m,w as y,_ as T}from"./main-CqQrmdFR.js";function x(n,s){if(!n)return s;try{return JSON.parse(n)}catch(a){return s}}function M(){return d(this,null,function*(){return v("/api/config")})}function E(n){return d(this,null,function*(){return v("/api/config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})})}function P(n){return d(this,null,function*(){return(yield v(`/api/config/models?channel=${encodeURIComponent(n)}`)).models||[]})}function z(n,s){return d(this,null,function*(){return(yield v("/api/config/models/probe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({base_url:n,api_key:s})})).models||[]})}function B(n){return d(this,null,function*(){return v("/api/config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:n})})})}function _(n){var s,a,r,i,f,g;return{llm:((s=n.llm)==null?void 0:s.api_key_set)===!0||((i=(r=(a=n.llm)==null?void 0:a.channels)==null?void 0:r.length)!=null?i:0)>0,embedding:((f=n.embedding)==null?void 0:f.api_key_set)===!0,mineru:((g=n.mineru)==null?void 0:g.api_key_set)===!0}}const N=Object.freeze(Object.defineProperty({__proto__:null,checkConfigCompleteness:_,fetchConfig:M,fetchModels:P,probeModels:z,saveConfig:E,testConfig:B},Symbol.toStringTag,{value:"Module"}));function U(n,s,a,r){if(!n)return r;const i=Number(n);return Number.isFinite(i)?Math.max(s,Math.min(a,i)):r}const $=j("settings",()=>{const n=m(localStorage.getItem("apiUrl")||""),s=m(localStorage.getItem("apiKey")||""),a=m(x(localStorage.getItem("models"),[])),r=m(localStorage.getItem("selectedModel")||""),i=m([]),f=m(localStorage.getItem("backendConfigured")==="true"),g=m(!1),h=m(U(localStorage.getItem("fontSize"),10,24,14));function c(t,o){localStorage.setItem(t,String(o))}y(n,t=>c("apiUrl",t)),y(s,t=>c("apiKey",t)),y(r,t=>{t&&c("selectedModel",t)}),y(f,t=>c("backendConfigured",t)),y(h,t=>{c("fontSize",t),document.documentElement.style.fontSize=`${t}px`});const p=m(null);function b(t){return d(this,null,function*(){var l;p.value=null;const o=t||((l=i.value[0])==null?void 0:l.name);if(!o){p.value="尚未配置任何渠道";return}try{const{fetchModels:e}=yield T(()=>d(null,null,function*(){const{fetchModels:S}=yield Promise.resolve().then(()=>N);return{fetchModels:S}}),void 0,import.meta.url),u=(yield e(o)).map(S=>S.id);u.length>0&&(a.value=u,localStorage.setItem("models",JSON.stringify(a.value)),a.value.includes(r.value)||(r.value=a.value[0]||""))}catch(e){const u=e instanceof Error?e.message:"获取模型列表失败";p.value=u}})}function k(t){if(!t)return"";const o=i.value.filter(l=>{var e;return(e=l.models)==null?void 0:e.some(u=>u.id===t)});return o.length===1?o[0].name:""}function C(){const t=["apiUrl","apiKey","selectedModel","models","fontSize","theme-mode"],o={};t.forEach(l=>{const e=localStorage.getItem(l);e&&(o[l]=e)}),localStorage.clear(),Object.entries(o).forEach(([l,e])=>localStorage.setItem(l,e))}function w(){let t=0;for(let l=0;l<localStorage.length;l++){const e=localStorage.key(l);if(e){const u=localStorage.getItem(e)||"";t+=e.length+u.length}}const o=t*2;return o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/(1024*1024)).toFixed(2)} MB`}document.documentElement.style.fontSize=`${h.value}px`;function I(){return d(this,null,function*(){var t,o,l;try{const e=yield M();(t=e==null?void 0:e.llm)!=null&&t.model&&(r.value=e.llm.model),(o=e==null?void 0:e.llm)!=null&&o.channels&&(i.value=e.llm.channels),(l=e==null?void 0:e.llm)!=null&&l.base_url&&!n.value&&(n.value=e.llm.base_url)}catch(e){}})}function O(){return d(this,null,function*(){var t,o,l;g.value=!0;try{const e=yield M(),u=_(e);return f.value=u.llm,(t=e.llm)!=null&&t.model&&!r.value&&(r.value=e.llm.model),(o=e.llm)!=null&&o.channels&&(i.value=e.llm.channels),(l=e.llm)!=null&&l.base_url&&!n.value&&(n.value=e.llm.base_url),{data:{},configured:u}}catch(e){return f.value=!1,{data:{},configured:{llm:!1,embedding:!1,mineru:!1}}}finally{g.value=!1}})}return{apiUrl:n,apiKey:s,models:a,selectedModel:r,channels:i,fontSize:h,backendConfigured:f,configLoading:g,fetchModelsError:p,fetchModels:b,fetchBackendConfig:O,resolveChannel:k,loadFromBackend:I,clearCache:C,estimateStorageUsage:w}}),F=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14">
	<g fill="none">
		<path stroke="#4147d5" stroke-linecap="round" stroke-linejoin="round" d="M6.022 4.36a18.5 18.5 0 0 0-1.93 1.686C1.248 8.889-.192 12.059.874 13.125s4.236-.374 7.079-3.218a18.5 18.5 0 0 0 1.686-1.93" />
		<path stroke="#4147d5" stroke-linecap="round" stroke-linejoin="round" d="M9.639 7.976c1.677 2.226 2.36 4.321 1.532 5.149c-1.067 1.066-4.236-.374-7.08-3.218C1.249 7.064-.191 3.894.875 2.828C1.702 2 3.796 2.683 6.022 4.36" />
		<path stroke="#4147d5" stroke-linecap="round" stroke-linejoin="round" d="M5.522 7.976a.5.5 0 1 0 1 0a.5.5 0 0 0-1 0" />
		<path fill="#d7e0ff" d="M8.032 3.597c-.315-.054-.315-.505 0-.56a2.84 2.84 0 0 0 2.29-2.193l.019-.087c.068-.31.51-.312.58-.002l.024.1a2.86 2.86 0 0 0 2.296 2.18c.316.056.316.509 0 .564a2.86 2.86 0 0 0-2.296 2.18l-.024.1c-.07.31-.512.309-.58-.002l-.02-.086a2.84 2.84 0 0 0-2.29-2.194" />
		<path stroke="#4147d5" stroke-linecap="round" stroke-linejoin="round" d="M8.032 3.597c-.315-.054-.315-.505 0-.56a2.84 2.84 0 0 0 2.29-2.193l.019-.087c.068-.31.51-.312.58-.002l.024.1a2.86 2.86 0 0 0 2.296 2.18c.316.056.316.509 0 .564a2.86 2.86 0 0 0-2.296 2.18l-.024.1c-.07.31-.512.309-.58-.002l-.02-.086a2.84 2.84 0 0 0-2.29-2.194" />
	</g>
</svg>
`;export{E as a,P as b,M as f,F as l,z as p,x as s,B as t,$ as u};
