mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
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 () => {
|
||||
const userId = (await AIProvider.userInfo)?.id;
|
||||
if (!userId) return;
|
||||
try {
|
||||
const userId = (await AIProvider.userInfo)?.id;
|
||||
if (!userId) return;
|
||||
|
||||
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(
|
||||
const sessions = await AIProvider.session?.getSessions(
|
||||
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) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||
import {
|
||||
CodeBlockSpec,
|
||||
EdgelessRootBlockSpec,
|
||||
@@ -18,10 +17,9 @@ import { AIParagraphBlockSpec } from './ai-paragraph';
|
||||
|
||||
export function enableAIExtension(
|
||||
specBuilder: SpecBuilder,
|
||||
framework: FrameworkProvider
|
||||
framework: FrameworkProvider,
|
||||
enableAI: boolean
|
||||
) {
|
||||
const featureFlagService = framework.get(FeatureFlagService);
|
||||
const enableAI = featureFlagService.flags.enable_ai.value;
|
||||
if (!enableAI) {
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,4 +1,5 @@
|
||||
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 {
|
||||
type Backlink,
|
||||
@@ -143,11 +144,13 @@ const usePreviewExtensions = () => {
|
||||
};
|
||||
}, [workspaceService]);
|
||||
|
||||
const enableAI = useEnableAI();
|
||||
|
||||
const extensions = useMemo(() => {
|
||||
const specs = enableEditorExtension(framework, 'page');
|
||||
const specs = enableEditorExtension(framework, 'page', enableAI);
|
||||
specs.extend([patchReferenceRenderer(reactToLit, referenceRenderer)]);
|
||||
return specs.value;
|
||||
}, [reactToLit, referenceRenderer, framework]);
|
||||
}, [reactToLit, referenceRenderer, framework, enableAI]);
|
||||
|
||||
return [extensions, portals] as const;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
LitEdgelessEditor,
|
||||
type PageEditor,
|
||||
} 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 { DocService, DocsService } from '@affine/core/modules/doc';
|
||||
import type {
|
||||
@@ -129,8 +130,10 @@ const usePatchSpecs = (mode: DocMode) => {
|
||||
|
||||
const confirmModal = useConfirmModal();
|
||||
|
||||
const enableAI = useEnableAI();
|
||||
|
||||
const patchedSpecs = useMemo(() => {
|
||||
const builder = enableEditorExtension(framework, mode);
|
||||
const builder = enableEditorExtension(framework, mode, enableAI);
|
||||
|
||||
builder.extend(
|
||||
[
|
||||
@@ -169,6 +172,7 @@ const usePatchSpecs = (mode: DocMode) => {
|
||||
reactToLit,
|
||||
referenceRenderer,
|
||||
featureFlagService,
|
||||
enableAI,
|
||||
]);
|
||||
|
||||
return [
|
||||
|
||||
@@ -6,11 +6,12 @@ import { type FrameworkProvider } from '@toeverything/infra';
|
||||
|
||||
export function enableEditorExtension(
|
||||
framework: FrameworkProvider,
|
||||
mode: 'edgeless' | 'page'
|
||||
mode: 'edgeless' | 'page',
|
||||
enableAI: boolean
|
||||
): SpecBuilder {
|
||||
const spec = SpecProvider._.getSpec(mode);
|
||||
enableAffineExtension(spec, framework);
|
||||
enableAIExtension(spec, framework);
|
||||
enableAIExtension(spec, framework, enableAI);
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user