Skip to content

Commit e3e15c6

Browse files
committed
fix(core): rollback ai service (#8321)
closes #8320
1 parent 7184d83 commit e3e15c6

File tree

3 files changed

+18
-40
lines changed

3 files changed

+18
-40
lines changed

packages/frontend/core/src/modules/cloud/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { SubscriptionPrices } from './entities/subscription-prices';
3535
import { UserCopilotQuota } from './entities/user-copilot-quota';
3636
import { UserFeature } from './entities/user-feature';
3737
import { UserQuota } from './entities/user-quota';
38-
import { AIService } from './services/ai';
3938
import { AuthService } from './services/auth';
4039
import { CloudDocMetaService } from './services/cloud-doc-meta';
4140
import { FetchService } from './services/fetch';
@@ -69,7 +68,6 @@ export function configureCloudModule(framework: Framework) {
6968
.entity(AuthSession, [AuthStore])
7069
.service(SubscriptionService, [SubscriptionStore])
7170
.store(SubscriptionStore, [GraphQLService, GlobalCache])
72-
.service(AIService, [AuthService])
7371
.entity(Subscription, [AuthService, ServerConfigService, SubscriptionStore])
7472
.entity(SubscriptionPrices, [ServerConfigService, SubscriptionStore])
7573
.service(UserQuotaService)

packages/frontend/core/src/modules/cloud/services/ai.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/frontend/core/src/modules/cloud/services/auth.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { notify } from '@affine/component';
2+
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
23
import { apis, appInfo, events } from '@affine/electron-api';
34
import type { OAuthProviderType } from '@affine/graphql';
45
import { I18n } from '@affine/i18n';
@@ -16,6 +17,16 @@ import { type AuthAccountInfo, AuthSession } from '../entities/session';
1617
import type { AuthStore } from '../stores/auth';
1718
import 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
2031
export 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

Comments
 (0)