const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./-KJ6CMi52.js","./Bcuvp8aL.js","./DrKWWDpL.js","./DsQIgu-4.js","./DnOaYask.js","./ZFQjeFO0.js","./Wadww7ZG.js","./DYP3EJMY.js"])))=>i.map(i=>d[i]);
import{s as e}from"./DrKWWDpL.js";import{n as t,t as n}from"./DsQIgu-4.js";import{t as r}from"./DYP3EJMY.js";import{a as i,i as a,n as o,o as s,r as c}from"./DFksoWtO2.js";var l=e(r(),1);t();var u={markdown:`md`,json:`json`,txt:`txt`,llmtxt:`llmtxt`};function d(e,t,n){let r={includeMetadata:n.includeMetadata!==!1};switch(t){case`markdown`:return s(e,r);case`json`:return i(e,r);case`txt`:return a(e);case`llmtxt`:return c(e,r);default:throw new o(`UNSUPPORTED_FORMAT`,`Unsupported export format: ${String(t)}`)}}function f(e,t){let n=l.default.dirname(e),r=e+`.tmp`;try{l.default.mkdirSync(n,{recursive:!0}),l.default.writeFileSync(r,t),l.default.renameSync(r,e)}catch(t){try{l.default.existsSync(r)&&l.default.unlinkSync(r)}catch{}throw new o(`WRITE_FAILED`,`Failed to write export file ${e}: ${t instanceof Error?t.message:String(t)}`)}}function p(e){return(0,l.createHash)(`sha256`).update(e).digest(`hex`)}function m(e){return(0,l.createHash)(`sha256`).update(Buffer.from(e,`utf8`)).digest(`hex`)}async function h(t,r){let{AgentIdentity:i}=await n(async()=>{let{AgentIdentity:e}=await import(`./-KJ6CMi52.js`);return{AgentIdentity:e}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),a=await i.load();if(!a&&r)try{let{promises:t}=await n(async()=>{let{promises:t}=await import(`./Wadww7ZG.js`).then(t=>e(t.default,1));return{promises:t}},__vite__mapDeps([6,7,2]),import.meta.url),o=await t.readFile(r,`utf-8`),s=JSON.parse(o),{fromHex:c}=await n(async()=>{let{fromHex:e}=await import(`./-KJ6CMi52.js`);return{fromHex:e}},__vite__mapDeps([0,1,2,3,4,5]),import.meta.url),l=Buffer.from(s.sk,`hex`);a=await i.fromSeed(l)}catch{}if(!a)throw new o(`SIGN_FAILED`,"No Ed25519 identity found. Run `llmtxt identity generate` to create one.");let s=Buffer.from(t,`hex`),c=await a.sign(s);return Buffer.from(c).toString(`hex`)}async function g(e,t,n){let{format:r,outputPath:i,includeMetadata:a,sign:o}=t,s=l.default.resolve(i),c=d(e,r,{includeMetadata:a}),u=Buffer.from(c,`utf8`),m=p(u);f(s,u);let g=null;return o===!0&&(g=await h(m,n)),{filePath:s,slug:e.slug,version:e.version,fileHash:m,byteCount:u.byteLength,exportedAt:e.exportedAt,signatureHex:g}}function _(e,t,n){return l.default.join(e,`${t}.${u[n]}`)}export{_ as n,g as r,m as t};