UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

7 lines • 1.97 kB
import path from"node:path";import fs from"node:fs/promises";import{FsSafeError}from"@openclaw/fs-safe/errors";import{isNotFoundPathError}from"@openclaw/fs-safe/path";import{root}from"@openclaw/fs-safe/root"; //!src/infra/fs-observation-mode.ts const FS_RECONCILE_MS=3e5;function resolveFsObservationMode(e=process.env){const t=e.CHOKIDAR_USEPOLLING?.toLowerCase();return t&&t!==`false`&&t!==`0`?`poll`:`auto`}function resolveFsObservationIntervalMs(e=process.env,t=100){const n=Number.parseInt(e.CHOKIDAR_INTERVAL??``,10);return Number.isFinite(n)&&n>0?Math.min(2147483647,Math.max(20,n)):t} //!src/infra/fs-observation-root.ts async function observationPrefixKind(e,t,n){const r=e.entries(`./`+t,{symlinks:`reject`,maxEntries:1,signal:n});try{await r.next();return`directory`}catch(e){if(e instanceof FsSafeError){if(e.code===`symlink`)return`symlink`;if(e.code===`not-file`)return`other`;if(e.code===`not-found`)return`missing`}throw e}finally{await r.return?.()}}async function admitObservationRoot(e,t=`reject`){const n=path.resolve(e);let r=path.parse(n).root;for(const e of path.relative(r,n).split(path.sep).filter(Boolean)){const t=path.join(r,e);try{const e=await fs.lstat(t);if(!e.isDirectory()||e.isSymbolicLink())break;r=t}catch(e){if(!isNotFoundPathError(e))throw e;break}}return await root(r,{symlinks:`reject`,hardlinks:t})} //!src/infra/fs-observation-snapshot.ts var ObservationSampleCloseError=class extends Error{constructor(e){super(`File observation metadata handle cleanup failed`,{cause:e})}};async function readObservationSnapshot(e,t){let n;try{n=await e.open(`./`+t,{symlinks:`reject`})}catch{return}try{await n[Symbol.asyncDispose]()}catch(e){throw new ObservationSampleCloseError(e)}return{size:n.stat.size,mtimeMs:n.stat.mtimeMs}}export{FS_RECONCILE_MS as a,observationPrefixKind as i,readObservationSnapshot as n,resolveFsObservationIntervalMs as o,admitObservationRoot as r,resolveFsObservationMode as s,ObservationSampleCloseError as t};