openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.38 kB
JavaScript
import{s as e,x as t}from"./openclaw-state-read-sqlite-database-admission-Ck6VG7rE.mjs";import{_ as n,a as r,f as i,p as a,v as o}from"./openclaw-state-read-schemas-CLrAtqTl.mjs";import{a as s,r as c}from"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import"./openclaw-state-read-sqlite-worker-operation-admission-DTfv_SKu.mjs";import"./openclaw-state-read-openclaw-state-db-DnrW7QY9.mjs";const l=n().min(1).max(256),u=i().int().nonnegative().max(2**53-1),d=a({revision:u,nextSequence:u}),f=a({sessionId:l,content:a({senderProfileId:l,sessionKey:n().min(1).max(512),agentId:l,messageId:l,createdAt:u,excerpt:n().max(280).optional()})}),p=a({key:n().regex(/^[a-f0-9]{64}$/),sequence:u,expiresAt:u,recipients:r(o([l,l.nullable()])).max(10),message:f.optional()}),m={name:`state.mention-head`,read:e=>d.safeParse(e).data},h=`notifications.mentions.head`,g=`notifications.mentions.source.`;function readMentionStoreSnapshot(n,r){let i=s(r);if(e(r,m)?.revision===n)return;let a=c(r,i.selectFrom(`config_machine_state`).select([`state_key`,`value_json`]).where(e=>e.or([e(`state_key`,`=`,h),e.and([e(`state_key`,`>=`,g),e(`state_key`,`<`,`notifications.mentions.source/`)])])).limit(10002)).rows,o=a.find(e=>e.state_key===h),l=o?d.parse(JSON.parse(o.value_json)):{revision:0,nextSequence:0},u=e(r,m);if((!u||u.revision<=l.revision)&&t(r,m,l),l.revision===n)return;let f=a.filter(e=>e.state_key!==h);if(f.length>1e4)throw Error(`Mention retention exceeds its source budget`);let _=/* @__PURE__ */ new Set,v=/* @__PURE__ */ new Set,y=f.map(e=>{if(e.value_json.length>32768)throw Error(`Mention source exceeds its record budget`);let t=p.parse(JSON.parse(e.value_json));if(e.state_key!==`${g}${t.key}`||t.sequence>=l.nextSequence||v.has(t.sequence)||new Set(t.recipients.map(([e])=>e)).size!==t.recipients.length)throw Error(`Invalid mention source identity`);v.add(t.sequence);for(let[,e]of t.recipients)if(e!==null){if(!t.message||_.has(e))throw Error(`Invalid retained mention`);_.add(e)}if(t.message&&t.expiresAt!==t.message.content.createdAt+6048e5)throw Error(`Invalid mention retention window`);return t});if(_.size>1e4)throw Error(`Mention retention exceeds its item budget`);return{head:l,sources:y.toSorted((e,t)=>e.sequence-t.sequence)}}const _={"mentions.snapshot":(e,t)=>({type:`mentions.snapshot`,snapshot:readMentionStoreSnapshot(e,t)})};export{_ as mentionReadOperations};