feat(core): move enable ai to feature flag (#8195)

This commit is contained in:
EYHN
2024-09-11 07:42:07 +00:00
parent 8c191e6baa
commit 498a69af53
15 changed files with 109 additions and 78 deletions

View File

@@ -5,6 +5,14 @@ const isDesktopEnvironment = environment.isElectron;
const isCanaryBuild = runtimeConfig.appBuildType === 'canary';
export const AFFINE_FLAGS = {
enable_ai: {
category: 'affine',
displayName: 'Enable AI',
description: 'Enable or disable ALL AI features.',
hide: true,
configurable: true,
defaultState: true,
},
enable_database_attachment_note: {
category: 'blocksuite',
bsFlag: 'enable_database_attachment_note',

View File

@@ -29,12 +29,17 @@ export class Flags extends Entity {
const configurable = flag.configurable ?? true;
const defaultState =
'defaultState' in flag ? flag.defaultState : undefined;
const getValue = () => {
return configurable
? (this.globalState.get<boolean>(FLAG_PREFIX + flagKey) ??
defaultState)
: defaultState;
};
const item = {
...flag,
value: configurable
? (this.globalState.get<boolean>(FLAG_PREFIX + flagKey) ??
defaultState)
: defaultState,
get value() {
return getValue();
},
set: (value: boolean) => {
if (!configurable) {
return;

View File

@@ -1,10 +1,14 @@
import { distinctUntilChanged, skip } from 'rxjs';
import { OnEvent, Service } from '../../../framework';
import { ApplicationStarted } from '../../lifecycle';
import type { Workspace } from '../../workspace';
import { WorkspaceInitialized } from '../../workspace/events';
import { AFFINE_FLAGS } from '../constant';
import { Flags, type FlagsExt } from '../entities/flags';
@OnEvent(WorkspaceInitialized, e => e.setupBlocksuiteEditorFlags)
@OnEvent(ApplicationStarted, e => e.setupRestartListener)
export class FeatureFlagService extends Service {
flags = this.framework.createEntity(Flags) as FlagsExt;
@@ -18,4 +22,13 @@ export class FeatureFlagService extends Service {
}
}
}
setupRestartListener() {
this.flags.enable_ai.$.pipe(distinctUntilChanged(), skip(1)).subscribe(
() => {
// when enable_ai flag changes, reload the page.
window.location.reload();
}
);
}
}

View File

@@ -5,6 +5,10 @@ export type FlagInfo = {
description?: string;
configurable?: boolean;
defaultState?: boolean; // default to open and not controlled by user
/**
* hide in the feature flag settings, but still can be controlled by the code
*/
hide?: boolean;
feedbackType?: FeedbackType;
feedbackLink?: string;
} & (