UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 2.44 kB
import{t as ReefAutonomySchema}from"./friend-types-BIQirGc6.mjs";import{n as getActiveReef}from"./runtime-GaPe1Cyj.mjs"; //!extensions/reef/src/commands.ts async function handleReefCommand({args:e,senderIsOwner:t,assertOwnerCurrent:n}){const r=(e??``).trim().split(/\s+/).filter(Boolean);const i=r[0]===`friend`&&/^(code|request|remove|block|autonomy)$/.test(r[1]??``);const a=r[0]===`review`&&/^(approve|deny)$/.test(r[1]??``);if((i||a)&&t!==true)return{text:`Only an authorized owner can change Reef friends or decide reviews. Ask an owner; friendship changes can also use openclaw reef locally.`};const o=getActiveReef();if(r[0]===`friend`&&r[1]===`code`){const e=await o.friends.mintCode(n);return{text:`Reef friend code: ${e.code} (expires ${(/* @__PURE__ */ new Date(e.expires*1e3)).toISOString()})`}}if(r[0]===`friend`&&r[1]===`request`&&r[2]){await o.friends.request(r[2].replace(/^@/,``).toLowerCase(),r[3],n);return{text:`Reef friend request submitted.`}}if(r[0]===`friend`&&r[1]===`list`){const e=await o.friends.list();return{text:e.length?e.map(e=>`@${e.peer} ${e.status} epoch=${e.key_epoch} fingerprint=${e.fingerprint} autonomy=${e.autonomy??`unapproved`}`).join(` `):`No Reef friends.`}}if(r[0]===`friend`&&/^(remove|block)$/.test(r[1]??``)&&r[2]){const e=r[2].replace(/^@/,``).toLowerCase();await o.friends.remove(e,n);return{text:`Reef friend @${e} blocked and removed locally.`}}if(r[0]===`friend`&&r[1]===`autonomy`&&r[2]&&r[3]){const e=r[2].replace(/^@/,``).toLowerCase();const t=ReefAutonomySchema.parse(r[3]);await o.friends.setAutonomy(e,t,n);return{text:`Reef friend @${e} autonomy set to ${t}.`}}if(r[0]===`review`&&r[1]===`list`){const e=await o.reviews.list();return{text:e.length?e.map(e=>`${e.approvalDigest} ${e.direction} ${e.from} -> ${e.to} ${e.verdict.category}`).join(` `):`No pending Reef reviews.`}}if(r[0]===`review`&&/^(approve|deny)$/.test(r[1]??``)&&r[2]){const e=await o.reviews.decide(r[2],r[1]===`approve`,n);if(!e)return{text:`Unknown Reef approval digest.`};return{text:e.direction===`inbound`?`Reef review ${r[1]}d. The parked message from ${e.from} is re-processed from the relay within about 30 seconds.`:`Reef review ${r[1]}d. Retry the identical message to re-run the guard.`}}return{text:`Usage: /reef friend code|request <handle> [code]|list|remove <handle>|autonomy <handle> <notify-only|bounded|extended>; /reef review list|approve <digest>|deny <digest>`}}export{handleReefCommand};