fix(core): circular dependencies (#8215)
This commit is contained in:
@@ -35,6 +35,7 @@ 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';
|
||||
@@ -68,6 +69,7 @@ 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)
|
||||
|
||||
38
packages/frontend/core/src/modules/cloud/services/ai.ts
Normal file
38
packages/frontend/core/src/modules/cloud/services/ai.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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,3 @@
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { track } from '@affine/core/mixpanel';
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
import type { OAuthProviderType } from '@affine/graphql';
|
||||
@@ -25,16 +24,6 @@ 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 {
|
||||
@@ -46,10 +35,6 @@ export class AuthService extends Service {
|
||||
) {
|
||||
super();
|
||||
|
||||
AIProvider.provide('userInfo', () => {
|
||||
return toAIUserInfo(this.session.account$.value);
|
||||
});
|
||||
|
||||
this.session.account$
|
||||
.pipe(
|
||||
map(a => ({
|
||||
@@ -66,7 +51,6 @@ export class AuthService extends Service {
|
||||
this.eventBus.emit(AccountLoggedIn, account);
|
||||
}
|
||||
this.eventBus.emit(AccountChanged, account);
|
||||
AIProvider.slots.userInfo.emit(toAIUserInfo(account));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user