11import { notify } from '@affine/component' ;
2+ import { AIProvider } from '@affine/core/blocksuite/presets/ai' ;
23import { apis , appInfo , events } from '@affine/electron-api' ;
34import type { OAuthProviderType } from '@affine/graphql' ;
45import { I18n } from '@affine/i18n' ;
@@ -16,6 +17,16 @@ import { type AuthAccountInfo, AuthSession } from '../entities/session';
1617import type { AuthStore } from '../stores/auth' ;
1718import type { FetchService } from './fetch' ;
1819
20+ function toAIUserInfo ( account : AuthAccountInfo | null ) {
21+ if ( ! account ) return null ;
22+ return {
23+ avatarUrl : account . avatar ?? '' ,
24+ email : account . email ?? '' ,
25+ id : account . id ,
26+ name : account . label ,
27+ } ;
28+ }
29+
1930// Emit when account changed
2031export const AccountChanged = createEvent < AuthAccountInfo | null > (
2132 'AccountChanged'
@@ -37,6 +48,11 @@ export class AuthService extends Service {
3748 ) {
3849 super ( ) ;
3950
51+ // TODO(@forehalo): make AIProvider a standalone service passed to AI elements by props
52+ AIProvider . provide ( 'userInfo' , ( ) => {
53+ return toAIUserInfo ( this . session . account$ . value ) ;
54+ } ) ;
55+
4056 this . session . account$
4157 . pipe (
4258 map ( a => ( {
@@ -47,6 +63,8 @@ export class AuthService extends Service {
4763 skip ( 1 ) // skip the initial value
4864 )
4965 . subscribe ( ( { account } ) => {
66+ AIProvider . slots . userInfo . emit ( toAIUserInfo ( account ) ) ;
67+
5068 if ( account === null ) {
5169 this . eventBus . emit ( AccountLoggedOut , account ) ;
5270 } else {
0 commit comments