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