openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.75 kB
JavaScript
import{p as e,s as t}from"./transcript-sqlite-schema-facts-C1_zV4Yg.mjs";import{a as n,c as r,r as i,t as a,u as o}from"./transcript-kysely-sync-CAP5xe3V.mjs";import{i as s}from"./transcript-openclaw-state-db-schema-helpers-B1k_oHgC.mjs";import"./transcript-openclaw-agent-db-identity-BPgUuROx.mjs";import"./transcript-openclaw-agent-db-contract-DXUC0rkZ.mjs";import{i as c,r as l}from"./transcript-session-participant-identity-D5n_Iz19.mjs";import{t as u}from"./transcript-session-actor-transaction-LsCQWbNw.mjs";const d=/* @__PURE__ */ new WeakMap;function readSessionActorParticipants(e,t){let n=u(e,{sessionKey:t}),r=n?.hot.target.sessionKey===t?n.hot.participants:d.get(e.db)?.read(e,t);return r&&structuredClone([...r])}function selectParticipantRows(e){return n(e).selectFrom(`session_participants`).select([`session_key`,`identity_namespace`,`actor_id`,`contribution_count`,`first_prompted_at`,`last_prompted_at`]).orderBy(`session_key`).orderBy(`first_prompted_at`,e=>e.asc().nullsFirst()).orderBy(`actor_id`).orderBy(`identity_namespace`)}const f=a(n=>{let i=r(n,e=>selectParticipantRows(n).where(`session_key`,`=`,e(e=>e))),a;return r=>e(n,()=>{let e=t(n);if(e&&a?.key===r&&a.revision===e)return a.rows;let o=i(r).rows;return a=e?{key:r,revision:e,rows:o}:void 0,o})});function readParticipantRows(e,t){let n=t?.length===1?t[0]:void 0;if(n!==void 0)return f(e)(n);let r=selectParticipantRows(e);return t&&(r=r.where(`session_key`,`in`,o(t))),i(e,r).rows}function readParticipantRecord(e){return{identity:l(e.identity_namespace,e.actor_id),contributionCount:e.contribution_count,firstPromptedAt:e.first_prompted_at,lastPromptedAt:e.last_prompted_at}}function participantRecordsBySessionKey(t,n){return e(t,()=>{let e=/* @__PURE__ */ new Map,r=n?.filter(n=>{let r=readSessionActorParticipants({db:t},n);return r===void 0||(r.length&&e.set(n,r),!1)});if(r?.length===0||!s(t,`session_participants`))return e;for(let n of readParticipantRows(t,r)){let t=e.get(n.session_key)??[];t.push(readParticipantRecord(n)),e.set(n.session_key,t)}return e})}function participantProjection(e){return e.length===0?{}:{participants:e.map(({identity:e})=>({identity:e})),participantCount:e.length}}function withProjectedParticipants(e,t){return t.length?{...e,...participantProjection(t)}:e}function projectSqliteSessionParticipants(e,t,n,r){let i=readSessionActorParticipants({db:e},t);if(i!==void 0)return withProjectedParticipants(n,i);if(r!==void 0)return withProjectedParticipants(n,JSON.parse(r).map(([e,t])=>({identity:l(e,t)})));let a=c(e,t);return a?a.participants?{...n,...a}:n:withProjectedParticipants(n,participantRecordsBySessionKey(e,[t]).get(t)??[])}function prepareSqliteSessionParticipantProjection(e,t){let n,r=!1;return(i,a,o)=>{if(o!==void 0)return projectSqliteSessionParticipants(e,i,a,o);let s=readSessionActorParticipants({db:e},i);if(s!==void 0)return withProjectedParticipants(a,s);let l=c(e,i);if(l)return l.participants?{...a,...l}:a;if(!n&&!r)try{n=participantRecordsBySessionKey(e,t)}catch{r=!0}return r?projectSqliteSessionParticipants(e,i,a):withProjectedParticipants(a,n?.get(i)??[])}}function projectSqliteSessionParticipantsBatch(e,t){let n=new Map(t),r=[];for(let[i,a]of t){let t=readSessionActorParticipants({db:e},i);if(t!==void 0){n.set(i,withProjectedParticipants(a,t));continue}let o=c(e,i);o?n.set(i,o.participants?{...a,...o}:a):r.push(i)}if(r.length===0)return n;let i=participantRecordsBySessionKey(e,r);for(let[e,r]of i){let i=t.get(e);i&&n.set(e,withProjectedParticipants(i,r))}return n}export{readParticipantRecord as a,projectSqliteSessionParticipantsBatch as i,prepareSqliteSessionParticipantProjection as n,withProjectedParticipants as o,projectSqliteSessionParticipants as r,participantRecordsBySessionKey as t};