mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 06:18:45 +08:00
@@ -35,7 +35,6 @@ import { SubscriptionPrices } from './entities/subscription-prices';
|
||||
import { UserCopilotQuota } from './entities/user-copilot-quota';
|
||||
import { UserFeature } from './entities/user-feature';
|
||||
import { UserQuota } from './entities/user-quota';
|
||||
import { AIService } from './services/ai';
|
||||
import { AuthService } from './services/auth';
|
||||
import { CloudDocMetaService } from './services/cloud-doc-meta';
|
||||
import { FetchService } from './services/fetch';
|
||||
@@ -69,7 +68,6 @@ export function configureCloudModule(framework: Framework) {
|
||||
.entity(AuthSession, [AuthStore])
|
||||
.service(SubscriptionService, [SubscriptionStore])
|
||||
.store(SubscriptionStore, [GraphQLService, GlobalCache])
|
||||
.service(AIService, [AuthService])
|
||||
.entity(Subscription, [AuthService, ServerConfigService, SubscriptionStore])
|
||||
.entity(SubscriptionPrices, [ServerConfigService, SubscriptionStore])
|
||||
.service(UserQuotaService)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { Service } from '@toeverything/infra';
|
||||
import { distinctUntilChanged, map, skip } from 'rxjs';
|
||||
|
||||
import { type AuthAccountInfo } from '../entities/session';
|
||||
import type { AuthService } from './auth';
|
||||
function toAIUserInfo(account: AuthAccountInfo | null) {
|
||||
if (!account) return null;
|
||||
return {
|
||||
avatarUrl: account.avatar ?? '',
|
||||
email: account.email ?? '',
|
||||
id: account.id,
|
||||
name: account.label,
|
||||
};
|
||||
}
|
||||
|
||||
export class AIService extends Service {
|
||||
constructor(private readonly auth: AuthService) {
|
||||
super();
|
||||
|
||||
AIProvider.provide('userInfo', () => {
|
||||
return toAIUserInfo(this.auth.session.account$.value);
|
||||
});
|
||||
|
||||
this.auth.session.account$
|
||||
.pipe(
|
||||
map(a => ({
|
||||
id: a?.id,
|
||||
account: a,
|
||||
})),
|
||||
distinctUntilChanged((a, b) => a.id === b.id), // only emit when the value changes
|
||||
skip(1) // skip the initial value
|
||||
)
|
||||
.subscribe(({ account }) => {
|
||||
AIProvider.slots.userInfo.emit(toAIUserInfo(account));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { notify } from '@affine/component';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { apis, appInfo, events } from '@affine/electron-api';
|
||||
import type { OAuthProviderType } from '@affine/graphql';
|
||||
import { I18n } from '@affine/i18n';
|
||||
@@ -16,6 +17,16 @@ import { type AuthAccountInfo, AuthSession } from '../entities/session';
|
||||
import type { AuthStore } from '../stores/auth';
|
||||
import type { FetchService } from './fetch';
|
||||
|
||||
function toAIUserInfo(account: AuthAccountInfo | null) {
|
||||
if (!account) return null;
|
||||
return {
|
||||
avatarUrl: account.avatar ?? '',
|
||||
email: account.email ?? '',
|
||||
id: account.id,
|
||||
name: account.label,
|
||||
};
|
||||
}
|
||||
|
||||
// Emit when account changed
|
||||
export const AccountChanged = createEvent<AuthAccountInfo | null>(
|
||||
'AccountChanged'
|
||||
@@ -37,6 +48,11 @@ export class AuthService extends Service {
|
||||
) {
|
||||
super();
|
||||
|
||||
// TODO(@forehalo): make AIProvider a standalone service passed to AI elements by props
|
||||
AIProvider.provide('userInfo', () => {
|
||||
return toAIUserInfo(this.session.account$.value);
|
||||
});
|
||||
|
||||
this.session.account$
|
||||
.pipe(
|
||||
map(a => ({
|
||||
@@ -47,6 +63,8 @@ export class AuthService extends Service {
|
||||
skip(1) // skip the initial value
|
||||
)
|
||||
.subscribe(({ account }) => {
|
||||
AIProvider.slots.userInfo.emit(toAIUserInfo(account));
|
||||
|
||||
if (account === null) {
|
||||
this.eventBus.emit(AccountLoggedOut, account);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user