import{t as e}from"./bundled-dir-U738ay4K-BxbzrJOo.mjs";import{r as t}from"./boundary-file-read-BSd9MXPy-gnNVhPKT.mjs";import{c as n,l as r,r as i,t as a}from"./jiti-loader-cache-Bat69wam-DNIteTtO.mjs";import{createRequire as o}from"node:module";import s from"node:fs";import c from"node:path";import{fileURLToPath as l}from"node:url";function u(e){return`${e.dirName}::${e.artifactBasename}::${e.bundledPluginsDir?c.resolve(e.bundledPluginsDir):`<default>`}`}function d(e){if(e.cache.has(e.key))return e.cache.get(e.key)??null;let t=e.resolve();return e.cache.set(e.key,t),t}function f(e){if(!e.bundledPluginsDir)return e.packageRoot;let t=c.resolve(e.bundledPluginsDir);return e.modulePath.startsWith(`${t}${c.sep}`)?t:e.packageRoot}function p(e){let t=!e.currentModulePath.includes(`${c.sep}dist${c.sep}`),i={rootDir:e.packageRoot,env:e.env,...e.bundledPluginsDir?{bundledPluginsDir:e.bundledPluginsDir}:{},dirName:e.dirName,artifactBasename:e.artifactBasename},a=t?r({dirName:e.dirName,artifactBasename:e.artifactBasename,sourceRoot:e.bundledPluginsDir??c.resolve(e.packageRoot,`extensions`)})??n(i):n(i);return a?{modulePath:a,boundaryRoot:f({modulePath:a,bundledPluginsDir:e.bundledPluginsDir,packageRoot:e.packageRoot})}:null}const m=l(import.meta.url),h=o(import.meta.url),g=new Map,_=new Map,v=new Set,y=new Map;let b,x;function S(){if(b)return b;let{createJiti:e}=h(`jiti`);return b=e,b}function C(){return x||(x=i({modulePath:l(import.meta.url),moduleUrl:import.meta.url})??l(new URL(`../..`,import.meta.url)),x)}function w(t){let n=e(t.env??process.env);return u({...t,bundledPluginsDir:n})}function T(t){let n=e(t.env??process.env);return p({...t,currentModulePath:m,packageRoot:C(),bundledPluginsDir:n})}function E(e){return d({cache:y,key:w(e),resolve:()=>T(e)})}function D(e){return a({cache:g,modulePath:e,importerUrl:import.meta.url,preferBuiltDist:!0,jitiFilename:import.meta.url,createLoader:S()})}function O(e){let t=!1,n;return()=>(t||=(n=e(),!0),n)}function k(e){let t=O(e.load);return new Proxy(e.target,{defineProperty(e,n,r){return Reflect.defineProperty(t(),n,r)},deleteProperty(e,n){return Reflect.deleteProperty(t(),n)},get(e,n,r){return Reflect.get(t(),n,r)},getOwnPropertyDescriptor(e,n){return Reflect.getOwnPropertyDescriptor(t(),n)},getPrototypeOf(){return Reflect.getPrototypeOf(t())},has(e,n){return Reflect.has(t(),n)},isExtensible(){return Reflect.isExtensible(t())},ownKeys(){return Reflect.ownKeys(t())},preventExtensions(){return Reflect.preventExtensions(t())},set(e,n,r,i){return Reflect.set(t(),n,r,i)},setPrototypeOf(e,n){return Reflect.setPrototypeOf(t(),n)}})}function A(e){return k({load:e,target:{}})}function j(n){let r=_.get(n.location.modulePath);if(r)return r;let i=t({absolutePath:n.location.modulePath,rootPath:n.location.boundaryRoot,boundaryLabel:n.location.boundaryRoot===C()?`OpenClaw package root`:(()=>{let t=e();return t&&c.resolve(n.location.boundaryRoot)===c.resolve(t)?`bundled plugin directory`:`plugin root`})(),rejectHardlinks:!1});if(!i.ok)throw Error(`Unable to open bundled plugin public surface ${n.location.modulePath}`,{cause:i.error});s.closeSync(i.fd);let a={};_.set(n.location.modulePath,a);let o;try{o=n.loadModule?.(n.location.modulePath)??D(n.location.modulePath)(n.location.modulePath),Object.assign(a,o),v.add(typeof n.trackedPluginId==`function`?n.trackedPluginId():n.trackedPluginId)}catch(e){throw _.delete(n.location.modulePath),e}return a}function M(e){let t=E(e);if(!t)throw Error(`Unable to resolve bundled plugin public surface ${e.dirName}/${e.artifactBasename}`);return j({location:t,trackedPluginId:e.trackedPluginId??e.dirName})}export{p as a,u as i,M as n,d as o,j as r,A as t};