import{n as e,t}from"./axios-DhfaybwJ.js";import{Ct as n,cn as r}from"./state-sIHsFpDu.js";import{E as i,O as a,Q as o,X as s,Y as c,Z as l,_ as u,h as d,l as f,p}from"./debug-otxXY3j-.js";import{o as m,r as h,t as g,v as _,y as v}from"./log-DSV4Ht5l.js";import{i as y,t as b}from"./sentry-9EbPa1Xu.js";import{r as x,t as S}from"./sink-Do5fWbUC.js";import{dirname as C,join as w}from"path";t(),r(),s(),v(),l(),f(),u(),m(),i(),y();var T=h(new Date);function E(){return w(_.errors(),T+`.jsonl`)}function D(e){return w(_.mcpLogs(e),T+`.jsonl`)}function O(e){let t=c(e);return{write(e){t.write(a(e)+`
`)},flush:t.flush,dispose:t.dispose}}var k=new Map;function A(e){let t=k.get(e);if(!t){let n=C(e);t=O({writeFn:t=>{try{d().appendFileSync(e,t)}catch{d().mkdirSync(n),d().appendFileSync(e,t)}},flushIntervalMs:1e3,maxBufferSize:50}),k.set(e,t),o(async()=>t?.dispose())}return t}function j(e,t){if(process.env.USER_TYPE!==`ant`)return;let r={timestamp:new Date().toISOString(),...t,cwd:d().cwd(),userType:process.env.USER_TYPE,sessionId:n(),version:`2.7.1`};A(e).write(r)}function M(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e;if(typeof t.message==`string`)return t.message;if(typeof t.error==`object`&&t.error&&`message`in t.error&&typeof t.error.message==`string`)return t.error.message}}function N(t){let n=t.stack||t.message,r=``;if(e.isAxiosError(t)&&t.config?.url){let e=[`url=${t.config.url}`];t.response?.status!==void 0&&e.push(`status=${t.response.status}`);let n=M(t.response?.data);n&&e.push(`body=${n}`),r=`[${e.join(`,`)}] `}p(`${t.name}: ${r}${n}`,{level:`error`}),j(E(),{error:`${r}${n}`}),b(t)}function P(e,t){p(`MCP server "${e}" ${t}`,{level:`error`});let r=D(e),i={error:t instanceof Error?t.stack||t.message:String(t),timestamp:new Date().toISOString(),sessionId:n(),cwd:d().cwd()};A(r).write(i)}function F(e,t){p(`MCP server "${e}": ${t}`);let r=D(e),i={debug:t,timestamp:new Date().toISOString(),sessionId:n(),cwd:d().cwd()};A(r).write(i)}function I(){g({logError:N,logMCPError:P,logMCPDebug:F,getErrorsPath:E,getMCPLogsPath:D}),p(`Error log sink initialized`)}S();function L(){I(),x()}export{L as t};