import{AsyncLocalStorage as e}from"node:async_hooks";const t=new e;function n(){return t.getStore()}let r=null;function i(e){r=e}function a(){return r}function o(){if(!r)throw Error(`Feishu plugin runtime has not been initialised. Ensure LarkClient.setRuntime() is called during plugin activation.`);return r}const s=`\x1B[0m`;function c(e){let t=`feishu/${e}`;return{debug:(e,n)=>console.debug(`[90m[${t}]${s}`,e,...n?[n]:[]),info:(e,n)=>console.log(`[36m[${t}]${s}`,e,...n?[n]:[]),warn:(e,n)=>console.warn(`[33m[${t}]${s}`,e,...n?[n]:[]),error:(e,n)=>console.error(`[31m[${t}]${s}`,e,...n?[n]:[])}}function l(e){try{let t=a();return t?t.logging.getChildLogger({subsystem:`feishu/${e}`}):null}catch{return null}}function u(){let e=n();if(!e)return null;let t={accountId:e.accountId,messageId:e.messageId,chatId:e.chatId};return e.senderOpenId&&(t.senderOpenId=e.senderOpenId),t}function d(e){let t=u();return t?e?{...t,...e}:t:e??{}}function f(){let e=n();return e?`feishu[${e.accountId}][msg:${e.messageId}]:`:`feishu:`}function p(e,t){let n=f();if(!t||Object.keys(t).length===0)return`${n} ${e}`;let r=Object.entries(t).map(([e,t])=>t===void 0||t==null?null:typeof t==`object`?`${e}=${JSON.stringify(t)}`:`${e}=${t}`).filter(Boolean);return r.length>0?`${n} ${e} (${r.join(`, `)})`:`${n} ${e}`}function m(e){let t=null,n=!1;function r(){return n||(t=l(e),t&&(n=!0)),t??c(e)}return{subsystem:e,debug(e,t){r().debug?.(p(e,t),d(t))},info(e,t){r().info(p(e,t),d(t))},warn(e,t){r().warn(p(e,t),d(t))},error(e,t){r().error(p(e,t),d(t))},child(t){return m(`${e}/${t}`)}}}function h(e){return m(e)}export{o as n,i as r,h as t};