openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.23 kB
JavaScript
import{i as runClaimableDedupeClaimLoop,n as createClaimableDedupe}from"../persistent-dedupe-CCW7etv5.mjs";
//!src/plugin-sdk/ingress-effect-once.ts
const INGRESS_EFFECT_ONCE_NAMESPACE_PREFIX=`ingress-effect-once`;var IngressEffectRunFailedError=class extends Error{constructor(){super(`ingress effect failed before its durable commit`);this.name=`IngressEffectRunFailedError`}};function createIngressEffectOnce(e){const t=createClaimableDedupe({pluginId:e.pluginId,namespacePrefix:INGRESS_EFFECT_ONCE_NAMESPACE_PREFIX,ttlMs:e.ttlMs,stateMaxEntries:e.stateMaxEntries,memoryMaxSize:e.memoryMaxSize??e.stateMaxEntries,onDiskError:t=>{e.onDiskError?.(t);throw t}});return{runOnce:async n=>{const r=JSON.stringify([n.effect,n.eventId]);const i=e.namespacePrefix;if((await runClaimableDedupeClaimLoop(()=>t.claim(r,{namespace:i}),e=>{if(e instanceof IngressEffectRunFailedError)return true;throw e})).kind===`duplicate`)return{kind:`replayed`};let a;try{a=await n.run()}catch(e){t.release(r,{namespace:i,error:new IngressEffectRunFailedError});throw e}try{await t.commit(r,{namespace:i})}catch(e){try{await t.forget(r,{namespace:i,onDiskError:e=>{throw e}})}catch{}throw e}return{kind:`executed`,value:a}}}}export{createIngressEffectOnce};