openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.44 kB
JavaScript
import{i as e}from"./transcript-global-singleton-DIJgobpU.mjs";import{g as t}from"./transcript-agent-creation-claim-Da8lP1e6.mjs";import{u as n}from"./transcript-sqlite-post-commit-B_pko32i.mjs";import"./transcript-sqlite-schema-facts-C1_zV4Yg.mjs";import{a as r,i,l as a,m as o,r as s,t as c}from"./transcript-kysely-sync-CAP5xe3V.mjs";import"./transcript-sqlite-transaction-CBQXI8WC.mjs";import"./transcript-session-row-changes-DGiwEF1b.mjs";import{g as l}from"./transcript-openclaw-state-db-cache-kzfc9rd-.mjs";import"./transcript-openclaw-state-db-schema-helpers-B1k_oHgC.mjs";import{t as u}from"./transcript-sqlite-schema-ensure-DehLIZgc.mjs";import{bt as d,pt as f}from"./transcript-openclaw-state-db-readonly-DQQE4HMs.mjs";import{d as p,n as m,t as h}from"./transcript-openclaw-state-db-MJzYHUz2.mjs";import"./transcript-secure-random-CSYkA38-.mjs";import g from"node:path";import{toUSVString as _}from"node:util";function createOpenClawStateSchemaEnsurer(e){let t=p(e.table,{endMarker:e.endMarker??`
) STRICT;
`,errorMessage:`Canonical state schema markers are missing for ${e.table}`}),r=u(()=>t,{tables:[e.table,...e.additionalTables??[]],indexes:e.indexes});return(t={})=>{let{db:i}=h(t),runWrite=r=>m(({db:t})=>{n(t)?f(t,e.table):r(t)},t,{operationLabel:e.operationLabel});n(i)?d(i,()=>runWrite(r)):r(i,runWrite)}}createOpenClawStateSchemaEnsurer({table:`user_background_images`,operationLabel:`users.background.schema.ensure`}),e(Symbol.for(`openclaw.userPreferences.publications`),()=>{let e=/* @__PURE__ */ new Map;return l(t=>{t.kind!==`opened`&&t.identity&&e.delete(t.identity.key)}),e}),createOpenClawStateSchemaEnsurer({table:`user_preferences`,operationLabel:`users.preferences.schema.ensure`});const v=[`image/png`,`image/jpeg`,`image/webp`];u(()=>p(`user_profiles`),{tables:[`user_profiles`,`user_profile_emails`,`user_profile_identities`],indexes:[`idx_user_profile_emails_profile_id`]}),u(()=>{let e=p(`user_profile_identities`,{endMarker:`ON user_profile_identities(authorization_id);`});return e.slice(e.indexOf(`CREATE INDEX`))},{tables:[],indexes:[`idx_user_profile_identities_profile_id`,`idx_user_profile_identities_authorization`]});var UserProfileNotFoundError=class extends Error{constructor(e){super(`user profile not found: ${e}`),this.profileId=e,this.name=`UserProfileNotFoundError`}};const y=o()(`avatar`,`is not`,null).as(`has_avatar`);function userProfilesDb(e){return r(e)}const b=[`id`,`display_name`,`avatar_mime`,`avatar_sha256`,`merged_into`,`updated_at`,y];function normalizeUserProfileAvatarMime(e){return v.find(t=>t===e)??null}function selectResolvedUserProfile(e,t,n){return readResolvedUserProfile(t,t=>i(e,typeof n==`function`?n(t):n.where(`id`,`=`,t)))}function readResolvedUserProfile(e,t){let n=t(e);return n?.merged_into?t(n.merged_into)??n:n}c(e=>a(e,t=>userProfilesDb(e).selectFrom(`user_profiles`).select(t=>[`id`,`display_name`,n(e)?t.val(null).as(`avatar`):t.case().when(t.fn(`typeof`,[`avatar`]),`=`,`blob`).then(null).else(t.ref(`avatar`)).end().as(`avatar`),`avatar_mime`,`avatar_sha256`,`merged_into`,`role`,`created_at`,`updated_at`]).where(`id`,`=`,t(e=>e))));function projectUserProfileDisplay(e){let t=normalizeUserProfileAvatarMime(e.avatar_mime);return{id:e.id,displayName:e.display_name,avatarRevision:e.avatar_sha256&&t?`${e.avatar_sha256}-${t.slice(6)}`:String(e.updated_at),hasAvatar:e.has_avatar===1}}function resolveCatalogProfile(e,t){let n=e.get(t);return e.get(n?.merged_into??t)??n}const profileCatalogPath=e=>g.resolve(e.path??t(e.env??process.env));function selectUserProfileDisplaysInDatabase(e,t){let n=userProfilesDb(e).selectFrom(`user_profiles`),r=s(e,n.select(b).where(e=>e.or([e(`id`,`in`,[...t]),e(`id`,`in`,n.select(`merged_into`).where(`id`,`in`,[...t]).where(`merged_into`,`!=`,``))]))).rows;if(r.some(e=>typeof e.id!=`string`||e.merged_into!==null&&typeof e.merged_into!=`string`)){let r=/* @__PURE__ */ new Map;for(let i of t)r.set(i,selectResolvedUserProfile(e,i,n.select(b)));return r}let i=new Map(r.map(e=>[e.id,e]));return new Map(t.map(e=>{let t=i.get(_(e));return[e,t?.merged_into?i.get(t.merged_into)??t:t]}))}function projectUserProfileDisplays(e,t){return new Map(e.flatMap(e=>{let n=t(e);return n?[[e,projectUserProfileDisplay(n)]]:[]}))}export{resolveCatalogProfile as a,projectUserProfileDisplay as i,projectUserProfileDisplays as n,UserProfileNotFoundError as o,selectUserProfileDisplaysInDatabase as r,profileCatalogPath as t};