fix: ai chat session handling (#6751)

fix AFF-999
upstream: https://github.com/toeverything/blocksuite/pull/6932
This commit is contained in:
pengx17
2024-04-30 15:08:26 +00:00
parent 0c175ada31
commit 91ee5e05bb
2 changed files with 30 additions and 13 deletions

View File

@@ -24,6 +24,16 @@ export const AccountLoggedIn = createEvent<AuthAccountInfo>('AccountLoggedIn');
export const AccountLoggedOut =
createEvent<AuthAccountInfo>('AccountLoggedOut');
function toAIUserInfo(account: AuthAccountInfo | null) {
if (!account) return null;
return {
avatarUrl: account.avatar ?? '',
email: account.email ?? '',
id: account.id,
name: account.label,
};
}
@OnEvent(ApplicationStarted, e => e.onApplicationStart)
@OnEvent(ApplicationFocused, e => e.onApplicationFocused)
export class AuthService extends Service {
@@ -36,14 +46,7 @@ export class AuthService extends Service {
super();
AIProvider.provide('userInfo', () => {
const account = this.session.account$.value;
if (!account) return null;
return {
avatarUrl: account.avatar ?? '',
email: account.email ?? '',
id: account.id,
name: account.label,
};
return toAIUserInfo(this.session.account$.value);
});
this.session.account$
@@ -62,6 +65,7 @@ export class AuthService extends Service {
this.eventBus.emit(AccountLoggedIn, account);
}
this.eventBus.emit(AccountChanged, account);
AIProvider.slots.userInfo.emit(toAIUserInfo(account));
});
}