import{d as m,l as d}from"./index-a63e1ad9.js";const S=m({id:"common",state:()=>({eventSource:null,log_cache:[],sse_connected:!1,log_cache_max_len:1e3,startTime:-1,tutorial_map:{qq_official_webhook:"https://astrbot.app/deploy/platform/qqofficial/webhook.html",qq_official:"https://astrbot.app/deploy/platform/qqofficial/websockets.html",aiocqhttp:"https://astrbot.app/deploy/platform/aiocqhttp/napcat.html",wecom:"https://astrbot.app/deploy/platform/wecom.html",gewechat:"https://astrbot.app/deploy/platform/gewechat.html",lark:"https://astrbot.app/deploy/platform/lark.html",telegram:"https://astrbot.app/deploy/platform/telegram.html",dingtalk:"https://astrbot.app/deploy/platform/dingtalk.html"},pluginMarketData:[]}),actions:{createEventSource(){if(this.eventSource)return;const e=new AbortController,{signal:t}=e,r={"Content-Type":"multipart/form-data",Authorization:"Bearer "+localStorage.getItem("token")};fetch("/api/live-log",{method:"GET",headers:r,signal:t,cache:"no-cache"}).then(o=>{if(!o.ok)throw new Error(`SSE connection failed: ${o.status}`);console.log("SSE stream opened"),this.sse_connected=!0;const l=o.body.getReader(),i=new TextDecoder,s=({done:n,value:a})=>{if(n){console.log("SSE stream closed"),setTimeout(()=>{this.eventSource=null,this.createEventSource()},2e3);return}return i.decode(a).split(`
`).forEach(c=>{if(c.startsWith("data:")){const p=c.substring(5).trim();let h=JSON.parse(p);h.type==="log"&&(this.log_cache.push(h),this.log_cache.length>this.log_cache_max_len&&this.log_cache.shift())}}),l.read().then(s)};l.read().then(s)}).catch(o=>{console.error("SSE error:",o),this.log_cache.push("SSE Connection failed, retrying in 5 seconds..."),setTimeout(()=>{this.eventSource=null,this.createEventSource()},1e3)}),this.eventSource=e},closeEventSourcet(){this.eventSource&&(this.eventSource.abort(),this.eventSource=null)},getLogCache(){return this.log_cache},getStartTime(){if(this.startTime!==-1)return this.startTime;d.get("/api/stat/start-time").then(e=>{this.startTime=e.data.data.start_time})},getTutorialLink(e){return this.tutorial_map[e]},async getPluginCollections(e=!1){return!e&&this.pluginMarketData.length>0?Promise.resolve(this.pluginMarketData):d.get("/api/plugin/market_list").then(t=>{var o,l,i,s,n;let r=[];for(let a in t.data.data)r.push({name:a,desc:t.data.data[a].desc,author:t.data.data[a].author,repo:t.data.data[a].repo,installed:!1,version:(o=t.data.data[a])!=null&&o.version?t.data.data[a].version:"未知",social_link:(l=t.data.data[a])==null?void 0:l.social_link,tags:(i=t.data.data[a])!=null&&i.tags?t.data.data[a].tags:[],logo:(s=t.data.data[a])!=null&&s.logo?t.data.data[a].logo:"",pinned:(n=t.data.data[a])!=null&&n.pinned?t.data.data[a].pinned:!1});return this.pluginMarketData=r,r}).catch(t=>(this.toast("获取插件市场数据失败: "+t,"error"),Promise.reject(t)))}}});export{S as u};
