mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-22 09:13:18 +03:00
feat(core): make AI functions follow server configuration (#8374)
This commit is contained in:
parent
075cedabf7
commit
82916e8264
@ -1,4 +1,9 @@
|
||||
import { FeatureFlagService, useService } from '@toeverything/infra';
|
||||
import { ServerConfigService } from '@affine/core/modules/cloud';
|
||||
import {
|
||||
FeatureFlagService,
|
||||
useLiveData,
|
||||
useService,
|
||||
} from '@toeverything/infra';
|
||||
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { AIOnboardingEdgeless } from './edgeless.dialog';
|
||||
@ -30,7 +35,12 @@ export const WorkspaceAIOnboarding = () => {
|
||||
const [dismissGeneral] = useDismiss(AIOnboardingType.GENERAL);
|
||||
const [dismissLocal] = useDismiss(AIOnboardingType.LOCAL);
|
||||
const featureFlagService = useService(FeatureFlagService);
|
||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
||||
const serverConfigService = useService(ServerConfigService);
|
||||
const serverFeatures = useLiveData(
|
||||
serverConfigService.serverConfig.features$
|
||||
);
|
||||
const enableAI =
|
||||
serverFeatures?.copilot && featureFlagService.flags.enable_ai.value;
|
||||
|
||||
return (
|
||||
<Suspense>
|
||||
@ -43,7 +53,12 @@ export const WorkspaceAIOnboarding = () => {
|
||||
export const PageAIOnboarding = () => {
|
||||
const [dismissEdgeless] = useDismiss(AIOnboardingType.EDGELESS);
|
||||
const featureFlagService = useService(FeatureFlagService);
|
||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
||||
const serverConfigService = useService(ServerConfigService);
|
||||
const serverFeatures = useLiveData(
|
||||
serverConfigService.serverConfig.features$
|
||||
);
|
||||
const enableAI =
|
||||
serverFeatures?.copilot && featureFlagService.flags.enable_ai.value;
|
||||
|
||||
return (
|
||||
<Suspense>
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
SettingRow,
|
||||
SettingWrapper,
|
||||
} from '@affine/component/setting-components';
|
||||
import { ServerConfigService } from '@affine/core/modules/cloud';
|
||||
import {
|
||||
EditorSettingService,
|
||||
type FontFamily,
|
||||
@ -402,8 +403,13 @@ export const SpellCheckSettings = () => {
|
||||
const AISettings = () => {
|
||||
const t = useI18n();
|
||||
const { openConfirmModal } = useConfirmModal();
|
||||
const { featureFlagService } = useServices({ FeatureFlagService });
|
||||
|
||||
const { featureFlagService, serverConfigService } = useServices({
|
||||
FeatureFlagService,
|
||||
ServerConfigService,
|
||||
});
|
||||
const serverFeatures = useLiveData(
|
||||
serverConfigService.serverConfig.features$
|
||||
);
|
||||
const enableAI = useLiveData(featureFlagService.flags.enable_ai.$);
|
||||
|
||||
const onAIChange = useCallback(
|
||||
@ -440,6 +446,10 @@ const AISettings = () => {
|
||||
[openConfirmModal, t, onAIChange]
|
||||
);
|
||||
|
||||
if (!serverFeatures?.copilot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingRow
|
||||
name={t['com.affine.settings.editorSettings.general.ai.title']()}
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
useLitPortalFactory,
|
||||
} from '@affine/component';
|
||||
import { useJournalInfoHelper } from '@affine/core/components/hooks/use-journal';
|
||||
import { ServerConfigService } from '@affine/core/modules/cloud';
|
||||
import { EditorService } from '@affine/core/modules/editor';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-settting';
|
||||
import { toURLSearchParams } from '@affine/core/modules/navigation';
|
||||
@ -86,6 +87,7 @@ const usePatchSpecs = (shared: boolean, mode: DocMode) => {
|
||||
editorService,
|
||||
workspaceService,
|
||||
featureFlagService,
|
||||
serverConfigService,
|
||||
} = useServices({
|
||||
PeekViewService,
|
||||
DocService,
|
||||
@ -93,8 +95,12 @@ const usePatchSpecs = (shared: boolean, mode: DocMode) => {
|
||||
WorkspaceService,
|
||||
EditorService,
|
||||
FeatureFlagService,
|
||||
ServerConfigService,
|
||||
});
|
||||
const framework = useFramework();
|
||||
const serverFeatures = useLiveData(
|
||||
serverConfigService.serverConfig.features$
|
||||
);
|
||||
const referenceRenderer: ReferenceReactRenderer = useMemo(() => {
|
||||
return function customReference(reference) {
|
||||
const data = reference.delta.attributes?.reference;
|
||||
@ -120,11 +126,17 @@ const usePatchSpecs = (shared: boolean, mode: DocMode) => {
|
||||
}, [workspaceService]);
|
||||
|
||||
const specs = useMemo(() => {
|
||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
||||
const enableAI =
|
||||
serverFeatures?.copilot && featureFlagService.flags.enable_ai.value;
|
||||
return mode === 'edgeless'
|
||||
? createEdgelessModeSpecs(framework, enableAI)
|
||||
: createPageModeSpecs(framework, enableAI);
|
||||
}, [featureFlagService, mode, framework]);
|
||||
? createEdgelessModeSpecs(framework, !!enableAI)
|
||||
: createPageModeSpecs(framework, !!enableAI);
|
||||
}, [
|
||||
serverFeatures?.copilot,
|
||||
featureFlagService.flags.enable_ai.value,
|
||||
mode,
|
||||
framework,
|
||||
]);
|
||||
|
||||
const confirmModal = useConfirmModal();
|
||||
const patchedSpecs = useMemo(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user