feat(core): disable ai if value of sever copilot config is false (#10520)
Fix issue [AF-2224](https://linear.app/affine-design/issue/AF-2224).
This commit is contained in:
@@ -297,24 +297,28 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly _initPanel = async () => {
|
private readonly _initPanel = async () => {
|
||||||
const userId = (await AIProvider.userInfo)?.id;
|
try {
|
||||||
if (!userId) return;
|
const userId = (await AIProvider.userInfo)?.id;
|
||||||
|
if (!userId) return;
|
||||||
|
|
||||||
const sessions = await AIProvider.session?.getSessions(
|
const sessions = await AIProvider.session?.getSessions(
|
||||||
this.doc.workspace.id,
|
|
||||||
this.doc.id
|
|
||||||
);
|
|
||||||
if (sessions?.length) {
|
|
||||||
this._chatSessionId = sessions?.[0].id;
|
|
||||||
await this._updateHistory();
|
|
||||||
}
|
|
||||||
if (this._chatSessionId) {
|
|
||||||
this._chatContextId = await AIProvider.context?.getContextId(
|
|
||||||
this.doc.workspace.id,
|
this.doc.workspace.id,
|
||||||
this._chatSessionId
|
this.doc.id
|
||||||
);
|
);
|
||||||
|
if (sessions?.length) {
|
||||||
|
this._chatSessionId = sessions?.[0].id;
|
||||||
|
await this._updateHistory();
|
||||||
|
}
|
||||||
|
if (this._chatSessionId) {
|
||||||
|
this._chatContextId = await AIProvider.context?.getContextId(
|
||||||
|
this.doc.workspace.id,
|
||||||
|
this._chatSessionId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await this._updateChips();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
await this._updateChips();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override updated(_changedProperties: PropertyValues) {
|
protected override updated(_changedProperties: PropertyValues) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
|
||||||
import {
|
import {
|
||||||
CodeBlockSpec,
|
CodeBlockSpec,
|
||||||
EdgelessRootBlockSpec,
|
EdgelessRootBlockSpec,
|
||||||
@@ -18,10 +17,9 @@ import { AIParagraphBlockSpec } from './ai-paragraph';
|
|||||||
|
|
||||||
export function enableAIExtension(
|
export function enableAIExtension(
|
||||||
specBuilder: SpecBuilder,
|
specBuilder: SpecBuilder,
|
||||||
framework: FrameworkProvider
|
framework: FrameworkProvider,
|
||||||
|
enableAI: boolean
|
||||||
) {
|
) {
|
||||||
const featureFlagService = framework.get(FeatureFlagService);
|
|
||||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
|
||||||
if (!enableAI) {
|
if (!enableAI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Button, Divider, useLitPortalFactory } from '@affine/component';
|
import { Button, Divider, useLitPortalFactory } from '@affine/component';
|
||||||
|
import { useEnableAI } from '@affine/core/components/hooks/affine/use-enable-ai';
|
||||||
import { DocService } from '@affine/core/modules/doc';
|
import { DocService } from '@affine/core/modules/doc';
|
||||||
import {
|
import {
|
||||||
type Backlink,
|
type Backlink,
|
||||||
@@ -143,11 +144,13 @@ const usePreviewExtensions = () => {
|
|||||||
};
|
};
|
||||||
}, [workspaceService]);
|
}, [workspaceService]);
|
||||||
|
|
||||||
|
const enableAI = useEnableAI();
|
||||||
|
|
||||||
const extensions = useMemo(() => {
|
const extensions = useMemo(() => {
|
||||||
const specs = enableEditorExtension(framework, 'page');
|
const specs = enableEditorExtension(framework, 'page', enableAI);
|
||||||
specs.extend([patchReferenceRenderer(reactToLit, referenceRenderer)]);
|
specs.extend([patchReferenceRenderer(reactToLit, referenceRenderer)]);
|
||||||
return specs.value;
|
return specs.value;
|
||||||
}, [reactToLit, referenceRenderer, framework]);
|
}, [reactToLit, referenceRenderer, framework, enableAI]);
|
||||||
|
|
||||||
return [extensions, portals] as const;
|
return [extensions, portals] as const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
LitEdgelessEditor,
|
LitEdgelessEditor,
|
||||||
type PageEditor,
|
type PageEditor,
|
||||||
} from '@affine/core/blocksuite/editors';
|
} from '@affine/core/blocksuite/editors';
|
||||||
|
import { useEnableAI } from '@affine/core/components/hooks/affine/use-enable-ai';
|
||||||
import type { DocCustomPropertyInfo } from '@affine/core/modules/db';
|
import type { DocCustomPropertyInfo } from '@affine/core/modules/db';
|
||||||
import { DocService, DocsService } from '@affine/core/modules/doc';
|
import { DocService, DocsService } from '@affine/core/modules/doc';
|
||||||
import type {
|
import type {
|
||||||
@@ -129,8 +130,10 @@ const usePatchSpecs = (mode: DocMode) => {
|
|||||||
|
|
||||||
const confirmModal = useConfirmModal();
|
const confirmModal = useConfirmModal();
|
||||||
|
|
||||||
|
const enableAI = useEnableAI();
|
||||||
|
|
||||||
const patchedSpecs = useMemo(() => {
|
const patchedSpecs = useMemo(() => {
|
||||||
const builder = enableEditorExtension(framework, mode);
|
const builder = enableEditorExtension(framework, mode, enableAI);
|
||||||
|
|
||||||
builder.extend(
|
builder.extend(
|
||||||
[
|
[
|
||||||
@@ -169,6 +172,7 @@ const usePatchSpecs = (mode: DocMode) => {
|
|||||||
reactToLit,
|
reactToLit,
|
||||||
referenceRenderer,
|
referenceRenderer,
|
||||||
featureFlagService,
|
featureFlagService,
|
||||||
|
enableAI,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import { type FrameworkProvider } from '@toeverything/infra';
|
|||||||
|
|
||||||
export function enableEditorExtension(
|
export function enableEditorExtension(
|
||||||
framework: FrameworkProvider,
|
framework: FrameworkProvider,
|
||||||
mode: 'edgeless' | 'page'
|
mode: 'edgeless' | 'page',
|
||||||
|
enableAI: boolean
|
||||||
): SpecBuilder {
|
): SpecBuilder {
|
||||||
const spec = SpecProvider._.getSpec(mode);
|
const spec = SpecProvider._.getSpec(mode);
|
||||||
enableAffineExtension(spec, framework);
|
enableAffineExtension(spec, framework);
|
||||||
enableAIExtension(spec, framework);
|
enableAIExtension(spec, framework, enableAI);
|
||||||
|
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
|
||||||
import { useService } from '@toeverything/infra';
|
|
||||||
import { Suspense, useCallback, useEffect, useState } from 'react';
|
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { useEnableAI } from '../../hooks/affine/use-enable-ai';
|
||||||
import { AIOnboardingEdgeless } from './edgeless.dialog';
|
import { AIOnboardingEdgeless } from './edgeless.dialog';
|
||||||
import { AIOnboardingLocal } from './local.dialog';
|
import { AIOnboardingLocal } from './local.dialog';
|
||||||
import { AIOnboardingType } from './type';
|
import { AIOnboardingType } from './type';
|
||||||
@@ -28,8 +27,7 @@ const useDismiss = (key: AIOnboardingType) => {
|
|||||||
|
|
||||||
export const WorkspaceAIOnboarding = () => {
|
export const WorkspaceAIOnboarding = () => {
|
||||||
const [dismissLocal] = useDismiss(AIOnboardingType.LOCAL);
|
const [dismissLocal] = useDismiss(AIOnboardingType.LOCAL);
|
||||||
const featureFlagService = useService(FeatureFlagService);
|
const enableAI = useEnableAI();
|
||||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
@@ -40,8 +38,7 @@ export const WorkspaceAIOnboarding = () => {
|
|||||||
|
|
||||||
export const PageAIOnboarding = () => {
|
export const PageAIOnboarding = () => {
|
||||||
const [dismissEdgeless] = useDismiss(AIOnboardingType.EDGELESS);
|
const [dismissEdgeless] = useDismiss(AIOnboardingType.EDGELESS);
|
||||||
const featureFlagService = useService(FeatureFlagService);
|
const enableAI = useEnableAI();
|
||||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { ServerService } from '@affine/core/modules/cloud';
|
||||||
|
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||||
|
import { useLiveData, useService } from '@toeverything/infra';
|
||||||
|
|
||||||
|
export const useEnableAI = () => {
|
||||||
|
const featureFlagService = useService(FeatureFlagService);
|
||||||
|
const aiFeature = useLiveData(featureFlagService.flags.enable_ai.$);
|
||||||
|
|
||||||
|
const serverService = useService(ServerService);
|
||||||
|
const serverConfig = useLiveData(serverService.server.features$);
|
||||||
|
const aiConfig = serverConfig.copilot;
|
||||||
|
|
||||||
|
return aiFeature && aiConfig;
|
||||||
|
};
|
||||||
@@ -7,9 +7,9 @@ import { EditorOutlineViewer } from '@affine/core/blocksuite/outline-viewer';
|
|||||||
import { PageAIOnboarding } from '@affine/core/components/affine/ai-onboarding';
|
import { PageAIOnboarding } from '@affine/core/components/affine/ai-onboarding';
|
||||||
import { DocPropertySidebar } from '@affine/core/components/doc-properties/sidebar';
|
import { DocPropertySidebar } from '@affine/core/components/doc-properties/sidebar';
|
||||||
import { useAppSettingHelper } from '@affine/core/components/hooks/affine/use-app-setting-helper';
|
import { useAppSettingHelper } from '@affine/core/components/hooks/affine/use-app-setting-helper';
|
||||||
|
import { useEnableAI } from '@affine/core/components/hooks/affine/use-enable-ai';
|
||||||
import { DocService } from '@affine/core/modules/doc';
|
import { DocService } from '@affine/core/modules/doc';
|
||||||
import { EditorService } from '@affine/core/modules/editor';
|
import { EditorService } from '@affine/core/modules/editor';
|
||||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
|
||||||
import { GlobalContextService } from '@affine/core/modules/global-context';
|
import { GlobalContextService } from '@affine/core/modules/global-context';
|
||||||
import { PeekViewService } from '@affine/core/modules/peek-view';
|
import { PeekViewService } from '@affine/core/modules/peek-view';
|
||||||
import { GuardService } from '@affine/core/modules/permissions';
|
import { GuardService } from '@affine/core/modules/permissions';
|
||||||
@@ -72,7 +72,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
docService,
|
docService,
|
||||||
workspaceService,
|
workspaceService,
|
||||||
globalContextService,
|
globalContextService,
|
||||||
featureFlagService,
|
|
||||||
guardService,
|
guardService,
|
||||||
} = useServices({
|
} = useServices({
|
||||||
WorkbenchService,
|
WorkbenchService,
|
||||||
@@ -81,7 +80,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
DocService,
|
DocService,
|
||||||
WorkspaceService,
|
WorkspaceService,
|
||||||
GlobalContextService,
|
GlobalContextService,
|
||||||
FeatureFlagService,
|
|
||||||
GuardService,
|
GuardService,
|
||||||
});
|
});
|
||||||
const workbench = workbenchService.workbench;
|
const workbench = workbenchService.workbench;
|
||||||
@@ -107,7 +105,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
// TODO(@eyhn): remove jotai here
|
// TODO(@eyhn): remove jotai here
|
||||||
const [_, setActiveBlockSuiteEditor] = useActiveBlocksuiteEditor();
|
const [_, setActiveBlockSuiteEditor] = useActiveBlocksuiteEditor();
|
||||||
|
|
||||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
const enableAI = useEnableAI();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isActiveView) {
|
if (isActiveView) {
|
||||||
|
|||||||
Reference in New Issue
Block a user