@@ -35,7 +35,6 @@ import { SubscriptionPrices } from './entities/subscription-prices';
|
|||||||
import { UserCopilotQuota } from './entities/user-copilot-quota';
|
import { UserCopilotQuota } from './entities/user-copilot-quota';
|
||||||
import { UserFeature } from './entities/user-feature';
|
import { UserFeature } from './entities/user-feature';
|
||||||
import { UserQuota } from './entities/user-quota';
|
import { UserQuota } from './entities/user-quota';
|
||||||
import { AIService } from './services/ai';
|
|
||||||
import { AuthService } from './services/auth';
|
import { AuthService } from './services/auth';
|
||||||
import { CloudDocMetaService } from './services/cloud-doc-meta';
|
import { CloudDocMetaService } from './services/cloud-doc-meta';
|
||||||
import { FetchService } from './services/fetch';
|
import { FetchService } from './services/fetch';
|
||||||
@@ -69,7 +68,6 @@ export function configureCloudModule(framework: Framework) {
|
|||||||
.entity(AuthSession, [AuthStore])
|
.entity(AuthSession, [AuthStore])
|
||||||
.service(SubscriptionService, [SubscriptionStore])
|
.service(SubscriptionService, [SubscriptionStore])
|
||||||
.store(SubscriptionStore, [GraphQLService, GlobalCache])
|
.store(SubscriptionStore, [GraphQLService, GlobalCache])
|
||||||
.service(AIService, [AuthService])
|
|
||||||
.entity(Subscription, [AuthService, ServerConfigService, SubscriptionStore])
|
.entity(Subscription, [AuthService, ServerConfigService, SubscriptionStore])
|
||||||
.entity(SubscriptionPrices, [ServerConfigService, SubscriptionStore])
|
.entity(SubscriptionPrices, [ServerConfigService, SubscriptionStore])
|
||||||
.service(UserQuotaService)
|
.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 { notify } from '@affine/component';
|
||||||
|
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||||
import { apis, appInfo, events } from '@affine/electron-api';
|
import { apis, appInfo, events } from '@affine/electron-api';
|
||||||
import type { OAuthProviderType } from '@affine/graphql';
|
import type { OAuthProviderType } from '@affine/graphql';
|
||||||
import { I18n } from '@affine/i18n';
|
import { I18n } from '@affine/i18n';
|
||||||
@@ -16,6 +17,16 @@ import { type AuthAccountInfo, AuthSession } from '../entities/session';
|
|||||||
import type { AuthStore } from '../stores/auth';
|
import type { AuthStore } from '../stores/auth';
|
||||||
import type { FetchService } from './fetch';
|
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
|
// Emit when account changed
|
||||||
export const AccountChanged = createEvent<AuthAccountInfo | null>(
|
export const AccountChanged = createEvent<AuthAccountInfo | null>(
|
||||||
'AccountChanged'
|
'AccountChanged'
|
||||||
@@ -37,6 +48,11 @@ export class AuthService extends Service {
|
|||||||
) {
|
) {
|
||||||
super();
|
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$
|
this.session.account$
|
||||||
.pipe(
|
.pipe(
|
||||||
map(a => ({
|
map(a => ({
|
||||||
@@ -47,6 +63,8 @@ export class AuthService extends Service {
|
|||||||
skip(1) // skip the initial value
|
skip(1) // skip the initial value
|
||||||
)
|
)
|
||||||
.subscribe(({ account }) => {
|
.subscribe(({ account }) => {
|
||||||
|
AIProvider.slots.userInfo.emit(toAIUserInfo(account));
|
||||||
|
|
||||||
if (account === null) {
|
if (account === null) {
|
||||||
this.eventBus.emit(AccountLoggedOut, account);
|
this.eventBus.emit(AccountLoggedOut, account);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user