115 lines
18 KiB
JavaScript
115 lines
18 KiB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{ai as t,er as n,oi as r}from"./control-ui-foundation-CeFMP1Ly.js";import{Qc as i,dr as a,el as o,fl as s,fr as c,fs as l,ml as u,ms as d,pr as ee,tl as f}from"./control-ui-core-pH6nakZ-.js";import{G as p,J as m,W as te,Z as ne,rt as h}from"./lit-runtime-BEtFSUCp.js";import{Cn as re,I as ie,Jt as ae,Sn as oe,Tt as se,ln as ce,m as le,p as ue,qt as de,wt as fe}from"./control-ui-core-DGVkFhVB.js";import{Ht as g,Lt as pe,Rt as me,qt as _}from"./control-ui-core-Br5DB0Zj.js";import{Gt as he,Ht as ge,In as _e,Jt as v,Kt as ve,Ln as ye,Qt as y,Ut as b,Vt as x,Wt as be,Xt as S,cn as C,en as w,in as xe,nn as T,on as E,un as D}from"./control-ui-boot-wpHCbPL9.js";import{Cn as Se,Dc as Ce,Hc as we,Oc as Te,Sn as Ee,bn as O,cn as De,dn as k,gn as A,mn as j,on as M,pn as Oe,un as N,vn as P}from"./control-ui-boot-Cdpgu1Gm.js";import{ft as ke,ut as Ae}from"./control-ui-boot-BPFwXC8p.js";import{a as F,r as I}from"./settings-targets-GAGqNu16.js";import{n as je,t as Me}from"./settings-workspace-Bo4nqRhI.js";function Ne(e){return e===void 0||e===!0}var L,R,z,B,V,H,U,W,G,K;function q(){return(q=e((()=>{he(),be(),ge(),L=`git.coauthor.enabled`,R=S({minLength:1,maxLength:128}),z=S({maxLength:256}),B=S({minLength:1,maxLength:128,pattern:`\\S`}),V=S({pattern:`^.{1,256}$`}),H=ve(V,E()),U=ve(V,E(),{maxProperties:32}),W=v([w(`image/png`),w(`image/jpeg`),w(`image/webp`)]),G=b({login:S({minLength:1,maxLength:39}),profileUrl:x,avatarUrl:x}),K=b({id:R,displayName:v([z,y()]),avatarMime:v([W,y()]),mergedInto:v([R,y()]),createdAt:T({minimum:0}),updatedAt:T({minimum:0}),emails:D(x),githubIdentity:v([G,y()]),hasAvatar:xe(),role:C(B)}),b({}),b({profiles:D(K)}),b({}),b({profile:K}),b({email:S({minLength:1,maxLength:320}),targetProfileId:R}),b({profile:K}),b({profileId:R,displayName:v([z,y()])}),b({profile:K}),b({profileId:R,role:v([B,y()])}),b({profile:K}),b({profileId:R,mime:W,avatarBase64:S({minLength:1,maxLength:7e5})}),b({profile:K,avatarRevision:x}),b({keys:C(D(V,{maxItems:32,uniqueItems:!0}))}),v([b({status:w(`ok`),entries:H}),b({status:w(`no_durable_identity`)})]),b({entries:U}),v([b({status:w(`ok`)}),b({status:w(`no_durable_identity`)})]),b({profileId:R,keys:D(V,{maxItems:32,uniqueItems:!0})})})))()}function Pe(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)throw new X(`invalid-image`);let n=Math.min(e,t),r=Math.min(1,J/n);return{sourceEdge:n,sourceX:Math.max(0,Math.round((e-n)/2)),sourceY:Math.max(0,Math.round((t-n)/2)),edge:Math.max(1,Math.round(n*r))}}async function Fe(e){let t=URL.createObjectURL(e);try{let e=new Image;return e.decoding=`async`,e.src=t,await e.decode(),e}catch{throw new X(`invalid-image`)}finally{URL.revokeObjectURL(t)}}function Ie(e,t,n){return new Promise(r=>{e.toBlob(r,t,n)})}function Le(e){let t=[];for(let n=0;n<e.length;n+=32768)t.push(String.fromCharCode(...e.subarray(n,n+32768)));return btoa(t.join(``))}async function Re(e,t){if(e.size>Y)throw new X(`too-large`);let n=new Uint8Array(await e.arrayBuffer()),r=Le(n);if(r.length>Be)throw new X(`too-large`);return{mime:t,avatarBase64:r,byteLength:n.byteLength}}async function ze(e){if(![`image/png`,`image/jpeg`,`image/webp`].includes(e.type))throw new X(`invalid-image`);if(e.size>Ve)throw new X(`source-too-large`);let t=await Fe(e),n=Pe(t.naturalWidth,t.naturalHeight),r=document.createElement(`canvas`);r.width=n.edge,r.height=n.edge;let i=r.getContext(`2d`);if(!i)throw new X(`invalid-image`);i.drawImage(t,n.sourceX,n.sourceY,n.sourceEdge,n.sourceEdge,0,0,n.edge,n.edge);let a=e.type===`image/webp`?`image/webp`:`image/png`,o=await Ie(r,a,a===`image/webp`?.9:void 0);if((!o||o.type!==a||o.size>Y)&&(a=`image/webp`,o=await Ie(r,a,.82)),!o||o.type!==a)throw new X(`invalid-image`);return Re(o,a)}var J,Y,Be,Ve,X;function He(){return(He=e((()=>{J=512,Y=524288,Be=7e5,Ve=10485760,X=class extends Error{constructor(e){super(e),this.code=e,this.name=`ProfileAvatarError`}}})))()}function Ue(e,t){return{id:e.id,name:e.displayName??void 0,email:e.emails[0],avatarUrl:t??void 0,watchedSessions:[]}}function We(e){let t=e.profile.displayName??``,n=e.displayName.trim()!==t,r=e.profile.emails.join(`, `),i=e.profile.githubIdentity;return m`<div id=${I.identity}>
|
|
${P({title:_(`profilePage.identity.title`),description:_(`profilePage.identity.description`)},m`
|
|
${A({title:_(`profilePage.identity.avatar`),description:_(`profilePage.identity.avatarDescription`),control:m`
|
|
<span class="identity-avatar-control">
|
|
<openclaw-viewer-avatar
|
|
.user=${Ue(e.profile,e.avatarUrl)}
|
|
variant="profile"
|
|
></openclaw-viewer-avatar>
|
|
<button
|
|
type="button"
|
|
class="btn btn--sm"
|
|
?disabled=${e.busy!==null}
|
|
@click=${e=>{let t=e.currentTarget,n=t instanceof HTMLButtonElement?t.nextElementSibling:null;n instanceof HTMLInputElement&&n.click()}}
|
|
>
|
|
${e.busy===`avatar`?_(`profilePage.identity.processingAvatar`):_(`profilePage.identity.chooseAvatar`)}
|
|
</button>
|
|
<input
|
|
type="file"
|
|
accept="image/png,image/jpeg,image/webp"
|
|
hidden
|
|
?disabled=${e.busy!==null}
|
|
@change=${t=>{let n=t.currentTarget,r=n.files?.[0];n.value=``,r&&e.onAvatarSelect(r)}}
|
|
/>
|
|
</span>
|
|
`})}
|
|
${A({title:_(`profilePage.identity.displayName`),description:_(`profilePage.identity.displayNameDescription`),control:m`
|
|
<form
|
|
class="identity-name-control"
|
|
@submit=${t=>{t.preventDefault(),e.onSaveDisplayName()}}
|
|
>
|
|
<input
|
|
class="settings-input"
|
|
type="text"
|
|
maxlength="256"
|
|
aria-label=${_(`profilePage.identity.displayName`)}
|
|
.value=${e.displayName}
|
|
?disabled=${e.busy!==null}
|
|
@input=${t=>e.onDisplayNameInput(t.currentTarget.value)}
|
|
/>
|
|
<button
|
|
type="submit"
|
|
class="btn btn--sm"
|
|
?disabled=${e.busy!==null||!n}
|
|
>
|
|
${e.busy===`display-name`?_(`common.saving`):_(`common.save`)}
|
|
</button>
|
|
</form>
|
|
`})}
|
|
${A({title:_(`profilePage.identity.linkedEmails`),description:_(`profilePage.identity.linkedEmailsDescription`),control:r?Se(r):p})}
|
|
${A({title:_(`profilePage.identity.githubAccount`),description:_(i?`profilePage.identity.githubAccountDescription`:`profilePage.identity.githubUnavailableDescription`),control:i?m`
|
|
<a
|
|
class="settings-account"
|
|
href=${i.profileUrl}
|
|
target=${a}
|
|
rel=${c()}
|
|
>
|
|
<img class="settings-account__avatar" src=${i.avatarUrl} alt="" />
|
|
<span class="settings-row__value settings-row__value--mono"
|
|
>@${i.login}</span
|
|
>
|
|
</a>
|
|
${O({kind:`ok`,label:_(`profilePage.identity.githubVerified`)})}
|
|
`:O({kind:`muted`,label:_(`profilePage.identity.githubUnavailable`)})})}
|
|
${Ee({title:_(`profilePage.identity.gitCoauthor`),description:_(i?`profilePage.identity.gitCoauthorDescription`:`profilePage.identity.gitCoauthorUnavailable`),checked:!!(i&&e.gitCoauthorEnabled),disabled:e.busy!==null||!i,onChange:e.onGitCoauthorChange})}
|
|
${e.error?m`<div class="settings-row identity-error" role="alert">
|
|
<span class="settings-row__desc">${e.error}</span>
|
|
</div>`:p}
|
|
`)}
|
|
</div>`}function Ge(){return(Ge=e((()=>{te(),M(),g(),we(),ee(),F()})))()}function Ke(e,t,n,i=``,a){let o=a??globalThis.location?.href;if(!o)return null;try{let a=new URL(o),s=new URL(e,a);if(s.protocol===`ws:`?s.protocol=`http:`:s.protocol===`wss:`&&(s.protocol=`https:`),![`http:`,`https:`].includes(s.protocol))return null;s.username=``,s.password=``;let c=s.origin===a.origin?r(i):``;return new URL(Ae(t,n,c),s.origin).href}catch{return null}}function qe(){return(qe=e((()=>{t(),ke()})))()}function Z(e){return l(e,_(`profilePage.identity.profileUnavailable`))}var Je,Q;function $(){return($=e((()=>{ye(),te(),ne(),q(),ce(),le(),fe(),ae(),me(),M(),Me(),g(),Te(),i(),d(),u(),F(),He(),Ge(),qe(),Je=`https://docs.openclaw.ai/concepts/user-model`,Q=class extends s{constructor(...e){super(...e),this.selfUser=null,this.ownProfile=null,this.displayName=``,this.gitCoauthorEnabled=!0,this.identityLoading=!1,this.identityBusy=null,this.identityError=null,this.failedHeroAvatarUrl=null,this.client=null,this.connected=!1,this.canWrite=!1,this.heroAvatarAuthCandidates=[],this.heroAvatarAuthReady=!1,this.heroAvatarLoader=new Ce(()=>{this.isConnected&&this.requestUpdate()}),this.identityRequestId=0,this.subscriptions=[]}connectedCallback(){super.connectedCallback(),this.subscriptions=[this.context.gateway.subscribe(e=>this.applyGatewaySnapshot(e)),this.context.agents.subscribe(()=>this.requestUpdate()),this.context.agentIdentity.subscribe(()=>this.requestUpdate())],this.applyGatewaySnapshot(this.context.gateway.snapshot)}disconnectedCallback(){for(let e of this.subscriptions)e();this.subscriptions=[],this.identityRequestId+=1,this.heroAvatarLoader.reset(),this.heroAvatarAuthCandidates=[],this.heroAvatarAuthReady=!1,this.client=null,this.connected=!1,this.canWrite=!1,super.disconnectedCallback()}applyGatewaySnapshot(e){let t=se({hello:e.hello,settings:{token:this.context.gateway.connection.token},password:this.context.gateway.connection.password});t.join(`\0`)!==this.heroAvatarAuthCandidates.join(`\0`)&&(this.heroAvatarAuthCandidates=t),this.heroAvatarAuthReady=!!(e.hello||this.context.gateway.connection.token.trim()||this.context.gateway.connection.password.trim());let n=e.client!==this.client,r=e.phase===`connected`,i=r&&de(e.hello?.auth??null),a=i!==this.canWrite,o=r!==this.connected,s=r?ie({snapshotUser:e.selfUser}):null,c=s?.id!==this.selfUser?.id,l=n||o||c||a;this.client=e.client,this.connected=r,this.canWrite=i,this.selfUser=s,this.requestUpdate(),l&&(this.identityRequestId+=1,this.ownProfile=null,this.displayName=``,this.gitCoauthorEnabled=!0,this.identityLoading=!1,this.identityBusy=null,this.identityError=null),!(!r||!e.client)&&(s&&i&&l&&this.loadIdentity(),this.context.agents.ensureList().then(e=>{e&&this.context.agentIdentity.ensure([e.defaultId])}))}async loadIdentity(){let e=this.client;if(!e||!this.connected||!this.canWrite||this.identityLoading)return;let t=++this.identityRequestId,n=this.ownProfile,r=this.displayName,i=n!==null&&r.trim()!==(n.displayName??``);this.identityLoading=!0,this.identityError=null;try{let n=await e.request(`users.self`,{});if(t!==this.identityRequestId)return;let a=n?.profile;if(!a)return;if(this.ownProfile=a,this.displayName=i?r:a.displayName??``,this.gitCoauthorEnabled=!0,a.githubIdentity){let n=await e.request(`users.prefs.get`,{keys:[L]});if(t!==this.identityRequestId)return;this.gitCoauthorEnabled=n.status===`ok`&&Ne(n.entries[`git.coauthor.enabled`])}}catch(e){t===this.identityRequestId&&(this.identityError=Z(e))}finally{t===this.identityRequestId&&(this.identityLoading=!1)}}applyOwnProfile(e){this.ownProfile=e,this.displayName=e.displayName??``}async saveDisplayName(){let e=this.client,t=this.ownProfile;if(!e||!t||!this.canWrite||this.identityBusy||this.identityLoading)return;this.identityBusy=`display-name`,this.identityError=null;let n=this.identityRequestId,r=!1;try{let i=this.displayName.trim()||null,a=await e.request(`users.setDisplayName`,{profileId:t.id,displayName:i});if(e!==this.client||n!==this.identityRequestId)return;this.applyOwnProfile(a.profile),this.context.gateway.updateSelfUser?.({name:a.profile.displayName??void 0}),r=!0}catch(t){e===this.client&&n===this.identityRequestId&&(this.identityError=Z(t))}finally{n===this.identityRequestId&&this.identityBusy===`display-name`&&(this.identityBusy=null)}r&&e===this.client&&n===this.identityRequestId&&this.loadIdentity()}async saveAvatar(e){let t=this.client,n=this.ownProfile;if(!t||!n||!this.canWrite||this.identityBusy||this.identityLoading)return;this.identityBusy=`avatar`,this.identityError=null;let r=this.identityRequestId,i=this.displayName,a=i.trim()!==(n.displayName??``),o=this.selfUser?.id===n.id?this.selfUser.avatarUrl:void 0,s=!1;try{let c=await ze(e);if(t!==this.client||r!==this.identityRequestId)return;let l=await t.request(`users.setAvatar`,{profileId:n.id,mime:c.mime,avatarBase64:c.avatarBase64});if(t!==this.client||r!==this.identityRequestId)return;this.ownProfile=l.profile,this.displayName=a?i:l.profile.displayName??``;let u=Ke(this.context.gateway.connection.gatewayUrl,l.profile.id,l.avatarRevision,this.context.resourceBasePath),d=this.selfUser?.id===l.profile.id&&this.selfUser.avatarUrl!==o;u&&!d&&this.context.gateway.updateSelfUser?.({avatarUrl:u}),s=!0}catch(e){t===this.client&&r===this.identityRequestId&&(this.identityError=e instanceof X?_(e.code===`too-large`?`profilePage.identity.avatarErrors.tooLarge`:e.code===`source-too-large`?`profilePage.identity.avatarErrors.sourceTooLarge`:`profilePage.identity.avatarErrors.invalid`):Z(e))}finally{r===this.identityRequestId&&this.identityBusy===`avatar`&&(this.identityBusy=null)}s&&t===this.client&&r===this.identityRequestId&&this.loadIdentity()}async saveGitCoauthorPreference(e){let t=this.client,n=this.ownProfile;if(!t||!n?.githubIdentity||!this.canWrite||this.identityBusy||this.identityLoading)return;this.identityBusy=`git-coauthor`,this.identityError=null;let r=this.identityRequestId;try{let n=await t.request(`users.prefs.set`,{entries:{[L]:e}});if(t!==this.client||r!==this.identityRequestId)return;if(n.status!==`ok`)throw Error(_(`profilePage.identity.profileUnavailable`));this.gitCoauthorEnabled=e}catch(e){t===this.client&&r===this.identityRequestId&&(this.identityError=Z(e))}finally{r===this.identityRequestId&&this.identityBusy===`git-coauthor`&&(this.identityBusy=null)}}renderIdentity(){if(!this.selfUser)return p;if(!this.canWrite)return m`<div id=${I.identity}>
|
|
${P({title:_(`profilePage.identity.title`)},N(_(`profilePage.identity.writeRequired`)))}
|
|
</div>`;if(!this.ownProfile){let e=this.identityLoading?_(`profilePage.identity.loading`):this.identityError?this.identityError:m`<div class="profile-identity-empty">
|
|
<span>${_(`profilePage.identity.notSet`)}</span>
|
|
<button type="button" class="btn btn--sm" @click=${()=>void this.loadIdentity()}>
|
|
${_(`profilePage.identity.setIdentity`)}
|
|
</button>
|
|
</div>`;return m`<div id=${I.identity}>
|
|
${P({title:_(`profilePage.identity.title`)},N(e))}
|
|
</div>`}let e=this.selfUser?.id===this.ownProfile.id&&this.selfUser.avatarUrl?this.selfUser.avatarUrl:Ke(this.context.gateway.connection.gatewayUrl,this.ownProfile.id,this.ownProfile.updatedAt,this.context.resourceBasePath);return We({profile:this.ownProfile,avatarUrl:e,displayName:this.displayName,gitCoauthorEnabled:this.gitCoauthorEnabled,busy:this.identityLoading?`loading`:this.identityBusy,error:this.identityError,onDisplayNameInput:e=>{this.displayName=e},onSaveDisplayName:()=>void this.saveDisplayName(),onAvatarSelect:e=>void this.saveAvatar(e),onGitCoauthorChange:e=>void this.saveGitCoauthorPreference(e)})}refreshManually(){this.selfUser&&this.canWrite&&!this.identityBusy&&!this.identityLoading&&this.loadIdentity()}featuredAgent(){let e=this.context.agents.state.agentsList,t=e?.defaultId??`main`,n=e?.agents.find(e=>e.id===t)??{id:t},r=this.context.agentIdentity.get(t),i=o(n,r),a=f(r?.avatar)??f(n.identity?.emoji)??f(n.identity?.avatar);return{agentId:t,name:r?.name?.trim()||n.identity?.name?.trim()||n.name?.trim()||t,avatarUrl:i,textAvatar:a}}renderAvatar(e,t,n){let r=e?.startsWith(`/`)?this.heroAvatarAuthReady?this.heroAvatarLoader.resolve(e,this.heroAvatarAuthCandidates):null:e;return e&&e!==this.failedHeroAvatarUrl&&r?m`<img
|
|
class="profile-hero__avatar-image"
|
|
src=${r}
|
|
alt=${n}
|
|
@error=${()=>{this.failedHeroAvatarUrl=e}}
|
|
/>`:t?m`<span class="profile-hero__avatar-text">${t}</span>`:m`<span class="profile-hero__avatar-mascot" aria-hidden="true"
|
|
>${pe.lobster}</span
|
|
>`}renderHero(){let{agentId:e,name:t,avatarUrl:n,textAvatar:r}=this.featuredAgent();return k(m`
|
|
<section class="profile-hero">
|
|
<div class="profile-hero__avatar">${this.renderAvatar(n,r,t)}</div>
|
|
<div class="profile-hero__name">${t}</div>
|
|
<div class="profile-hero__handle">
|
|
<span>@${e}</span>
|
|
<span class="profile-hero__badge">OpenClaw</span>
|
|
</div>
|
|
</section>
|
|
`)}renderBody(){return!this.connected||!this.client?j(k(N(_(`profilePage.offline`)))):j(m`
|
|
${this.renderHero()} ${this.renderIdentity()}
|
|
${k(Oe({title:_(`profilePage.usageStatistics`),description:_(`profilePage.usageStatisticsDescription`),onClick:()=>this.context.navigate(`usage`)}))}
|
|
`)}render(){return this.heroAvatarLoader.withActiveRoutes(()=>this.renderContent())}renderContent(){return m`
|
|
<section class="content-header">
|
|
<div>
|
|
<div class="page-title">${re(`profile`)}</div>
|
|
<div class="page-subtitle">
|
|
${oe(`profile`)} ${De(Je)}
|
|
</div>
|
|
</div>
|
|
${this.selfUser?m`<button
|
|
class="btn profile-refresh"
|
|
?disabled=${this.identityLoading||this.identityBusy!==null}
|
|
@click=${()=>this.refreshManually()}
|
|
>
|
|
${this.identityLoading?_(`common.refreshing`):_(`common.refresh`)}
|
|
</button>`:p}
|
|
</section>
|
|
${je(this.renderBody())}
|
|
`}},n([_e({context:ue,subscribe:!1})],Q.prototype,`context`,void 0),n([h()],Q.prototype,`selfUser`,void 0),n([h()],Q.prototype,`ownProfile`,void 0),n([h()],Q.prototype,`displayName`,void 0),n([h()],Q.prototype,`gitCoauthorEnabled`,void 0),n([h()],Q.prototype,`identityLoading`,void 0),n([h()],Q.prototype,`identityBusy`,void 0),n([h()],Q.prototype,`identityError`,void 0),n([h()],Q.prototype,`failedHeroAvatarUrl`,void 0),customElements.get(`openclaw-profile-page`)||customElements.define(`openclaw-profile-page`,Q)})))()}$();
|
|
//# sourceMappingURL=profile-page-CftlOK3x.js.map
|