UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.36 kB
import{r as resolveGlobalDedupeCache}from"./dedupe-CsfmSvUH.mjs"; //!src/plugin-sdk/dedupe-runtime.ts function createPersistentDedupeCache(e){const t=resolveGlobalDedupeCache(e.globalKey,{ttlMs:e.ttlMs,maxSize:e.maxSize});let n;let r=false;const disablePersistentStore=t=>{r=true;n=void 0;e.persistent.logError?.(t)};const getPersistentStore=()=>{if(r)return;if(n)return n;try{n=e.persistent.openStore({namespace:e.persistent.namespace,maxEntries:e.persistent.maxEntries,...e.ttlMs>0?{defaultTtlMs:e.ttlMs}:{}});return n}catch(e){disablePersistentStore(e);return}};return{peek:e=>t.peek(e),lookup:async n=>{if(t.peek(n))return true;const r=getPersistentStore();if(!r)return false;let i;try{i=await r.lookup(n);if(i===void 0)return false;if(e.ttlMs<=0){const e=r;if(typeof e.entries===`function`){const t=await e.entries();if(Array.isArray(t)){const e=t.find(e=>e.key===n);if(!e)return false;if(e.expiresAt!==void 0)return e.expiresAt>Date.now()}}}}catch(e){disablePersistentStore(e);return false}const a=e.persistent.readTimestamp?.(i);if(a!==void 0&&e.ttlMs>0&&Date.now()-a>=e.ttlMs)return false;t.check(n,a);return true},register:async(e,n,r)=>{t.check(e,r?.at);const i=getPersistentStore();if(!i)return;try{await i.register(e,n)}catch(e){disablePersistentStore(e)}},clearForTest:()=>{t.clear();n=void 0;r=false}}}export{createPersistentDedupeCache as t};