UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 7.37 kB
import{n as e}from"./openclaw-state-read-rolldown-runtime-C7TU3oOp.mjs";import{u as t}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import{o as n,w as r}from"./openclaw-state-read-sqlite-schema-facts-Dtolu7-X.mjs";import{a as i,i as a,l as o,m as s,r as c,t as l}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{o as u,s as d}from"./openclaw-state-read-openclaw-state-db-schema-helpers-QFZd8aJI.mjs";import{a as f}from"./openclaw-state-read-sqlite-transaction-Bt-IwVhZ.mjs";import"./openclaw-state-read-openclaw-state-db-B3dGXm7m.mjs";import"./openclaw-state-read-openclaw-state-db-legacy-backfills-CP_449sp.mjs";import{t as p}from"./openclaw-state-read-sqlite-schema-ensure-Bksnvnd1.mjs";import{t as m}from"./openclaw-state-read-user-profile-constants-DC9CyEfK.mjs";import{t as h}from"./openclaw-state-read-openclaw-state-feature-schema-BaBHFVL8.mjs";import"./openclaw-state-read-user-profile-events-D1aryhLR.mjs";import"./openclaw-state-read-secure-random-DS7aQ3jW.mjs";const g=[`image/png`,`image/jpeg`,`image/webp`];p(()=>h(`user_profiles`),{tables:[`user_profiles`,`user_profile_emails`,`user_profile_identities`],indexes:[`idx_user_profile_emails_profile_id`]}),p(()=>{let e=h(`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`}},UserProfileOwnerError=class extends Error{constructor(e){super(e===`repair-required`?`the shared owner profile requires repair; run openclaw doctor --fix and reconnect`:e===`merge`?`the shared owner profile cannot be merged; sign in with a personal identity instead`:`the shared owner profile is not governed by operator roles`),this.code=e,this.name=`UserProfileOwnerError`}},_=/* @__PURE__ */ e({inspectProfileAvatarInDatabase:()=>inspectProfileAvatarInDatabase,projectUserProfileDisplay:()=>projectUserProfileDisplay,readUserProfileAvatarCommand:()=>readUserProfileAvatarCommand,requireResolvedUserProfileMetadataById:()=>requireResolvedUserProfileMetadataById,selectProfileDisplayEntries:()=>selectProfileDisplayEntries,selectResolvedUserProfile:()=>selectResolvedUserProfile,selectResolvedUserProfileById:()=>selectResolvedUserProfileById,selectResolvedUserProfileMetadataById:()=>selectResolvedUserProfileMetadataById,selectUserProfileEmailAlias:()=>selectUserProfileEmailAlias,selectUserProfileEmails:()=>selectUserProfileEmails,toUserProfile:()=>toUserProfile,userProfileAvatarPresence:()=>v,userProfileDisplaySelection:()=>y,userProfilesDb:()=>userProfilesDb});function toUserProfile(e){return{id:e.id,displayName:e.display_name,avatarMime:normalizeUserProfileAvatarMime(e.avatar_mime),mergedInto:e.merged_into,...e.role?{role:e.role}:{},createdAt:e.created_at,updatedAt:e.updated_at}}const v=s()(`avatar`,`is not`,null).as(`has_avatar`);function userProfilesDb(e){return i(e)}function selectUserProfileEmailAlias(e,t){return a(e,userProfilesDb(e).selectFrom(`user_profile_emails`).select(`profile_id`).where(`email`,`=`,t))}function selectUserProfileEmails(e,t){return c(e,userProfilesDb(e).selectFrom(`user_profile_emails`).select(`email`).where(`profile_id`,`=`,t).orderBy(`email`,`asc`)).rows.map(({email:e})=>e)}const y=[`id`,`display_name`,`avatar_mime`,`avatar_sha256`,`merged_into`,`updated_at`,v];function selectProfileDisplayEntries(e,t){let n=userProfilesDb(e).selectFrom(`user_profiles`).select([...y,`created_at`,...d(e,`user_profiles`,`role`)?[`role`]:[]]).select(t=>u(e,`user_profile_identities`)?t.selectFrom(`user_profile_identities`).select(`user_profiles.created_at`).where(`provider`,`=`,`gateway.local`).where(`subject`,`=`,`owner`).whereRef(`profile_id`,`=`,`user_profiles.id`).where(`user_profiles.id`,`=`,m).$asScalar().as(`gateway_owner_created_at`):t.val(null).as(`gateway_owner_created_at`));return c(e,t?n.where(`id`,`in`,t):n).rows.map(({gateway_owner_created_at:e,...t})=>[t.id,{...t,...e==null?{}:{gatewayOwnerCreatedAt:e}}])}function normalizeUserProfileAvatarMime(e){return g.find(t=>t===e)??null}function selectResolvedUserProfile(e,t,n){return readResolvedUserProfile(t,t=>a(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}function selectResolvedUserProfileById(e,t){return selectResolvedUserProfile(e,t,userProfilesDb(e).selectFrom(`user_profiles`).selectAll())}const b=l(e=>o(e,n=>userProfilesDb(e).selectFrom(`user_profiles`).select(n=>[`id`,`display_name`,t(e)?n.val(null).as(`avatar`):n.case().when(n.fn(`typeof`,[`avatar`]),`=`,`blob`).then(null).else(n.ref(`avatar`)).end().as(`avatar`),`avatar_mime`,`avatar_sha256`,`merged_into`,`role`,`created_at`,`updated_at`]).where(`id`,`=`,n(e=>e))));function selectResolvedUserProfileMetadataById(e,t){return d(e,`user_profiles`,`role`)?readResolvedUserProfile(t,b(e)):selectResolvedUserProfileById(e,t)}function requireResolvedUserProfileMetadataById(e,t){let n=selectResolvedUserProfileMetadataById(e,t);if(!n)throw new UserProfileNotFoundError(t);return n}function selectProfileAvatarMetadata(e,i){if(!(t(e)?r(e):n(e)))throw Error(`Profile avatar reads require admitted schema facts`);if(u(e,`user_profiles`))return selectResolvedUserProfile(e,i,userProfilesDb(e).selectFrom(`user_profiles`).select([...y,`created_at`]).select(t=>[d(e,`user_profiles`,`role`)?`role`:t.val(null).as(`role`),t.fn(`length`,[`avatar`]).as(`avatar_byte_length`)]))}function inspectProfileAvatarInDatabase(e,t){return f(e,()=>{let n=selectProfileAvatarMetadata(e,t),r=normalizeUserProfileAvatarMime(n?.avatar_mime??null),i=n?.has_avatar&&r&&n.avatar_sha256?{mime:r,sha256:n.avatar_sha256,updatedAt:n.updated_at,byteLength:n.avatar_byte_length??0}:void 0;return{profile:n&&toUserProfile(n),hasAvatar:n?.has_avatar===1,avatar:i,emails:n&&!i?selectUserProfileEmails(e,n.id):[]}})}function readProfileAvatarInDatabase(e,t,n){return f(e,()=>{let r=selectProfileAvatarMetadata(e,t),i=normalizeUserProfileAvatarMime(r?.avatar_mime??null);if(!r?.has_avatar||!i||!r.avatar_sha256||r.id!==n.canonicalProfileId||r.avatar_sha256!==n.sha256||i!==n.mime)return;let o=a(e,userProfilesDb(e).selectFrom(`user_profiles`).select(`avatar`).where(`id`,`=`,r.id))?.avatar;return o?{bytes:o,mime:i,sha256:r.avatar_sha256,updatedAt:r.updated_at}:void 0})}function readUserProfileAvatarCommand(e,t){return t.type===`userProfiles.avatar.inspect`?{type:t.type,inspection:inspectProfileAvatarInDatabase(e,t.profileId)}:{type:t.type,avatar:readProfileAvatarInDatabase(e,t.profileId,t.expected)}}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}}export{selectResolvedUserProfile as a,selectUserProfileEmails as c,_ as d,UserProfileNotFoundError as f,selectProfileDisplayEntries as i,y as l,readUserProfileAvatarCommand as n,selectResolvedUserProfileMetadataById as o,UserProfileOwnerError as p,requireResolvedUserProfileMetadataById as r,selectUserProfileEmailAlias as s,projectUserProfileDisplay as t,userProfilesDb as u};