mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 05:07:06 +08:00
fix(core): doc reference error in ai answer (#13141)
Close [AI-303](https://linear.app/affine-design/issue/AI-303) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced a new AI configuration hook to streamline AI-related features and integrations. * Integrated enhanced AI specifications into chat components for improved AI chat experiences. * **Refactor** * Updated chat panels to use the new AI configuration hook, simplifying extension management and improving maintainability. * **Chores** * Improved options handling in the editor view extension for more flexible configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -44,6 +44,8 @@ const optionsSchema = z.object({
|
|||||||
.args(z.custom<ConfirmModalProps>().optional(), z.any().optional()),
|
.args(z.custom<ConfirmModalProps>().optional(), z.any().optional()),
|
||||||
closeConfirmModal: z.function(),
|
closeConfirmModal: z.function(),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
scope: z.enum(['doc', 'workspace']).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type AffineEditorViewOptions = z.infer<typeof optionsSchema>;
|
export type AffineEditorViewOptions = z.infer<typeof optionsSchema>;
|
||||||
@@ -93,16 +95,7 @@ export class AffineEditorViewExtension extends ViewExtensionProvider<AffineEdito
|
|||||||
if (!options) {
|
if (!options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {
|
const { framework, reactToLit, confirmModal, scope = 'doc' } = options;
|
||||||
framework,
|
|
||||||
|
|
||||||
reactToLit,
|
|
||||||
confirmModal,
|
|
||||||
} = options;
|
|
||||||
|
|
||||||
const docService = framework.get(DocService);
|
|
||||||
const docsService = framework.get(DocsService);
|
|
||||||
const editorService = framework.get(EditorService);
|
|
||||||
|
|
||||||
const referenceRenderer = this._getCustomReferenceRenderer(framework);
|
const referenceRenderer = this._getCustomReferenceRenderer(framework);
|
||||||
|
|
||||||
@@ -112,12 +105,20 @@ export class AffineEditorViewExtension extends ViewExtensionProvider<AffineEdito
|
|||||||
patchNotificationService(confirmModal),
|
patchNotificationService(confirmModal),
|
||||||
patchOpenDocExtension(),
|
patchOpenDocExtension(),
|
||||||
patchSideBarService(framework),
|
patchSideBarService(framework),
|
||||||
patchDocModeService(docService, docsService, editorService),
|
|
||||||
patchFileSizeLimitExtension(framework),
|
patchFileSizeLimitExtension(framework),
|
||||||
buildDocDisplayMetaExtension(framework),
|
buildDocDisplayMetaExtension(framework),
|
||||||
patchForAudioEmbedView(reactToLit),
|
patchForAudioEmbedView(reactToLit),
|
||||||
])
|
])
|
||||||
.register(patchDocUrlExtensions(framework))
|
.register(patchDocUrlExtensions(framework))
|
||||||
.register(patchQuickSearchService(framework));
|
.register(patchQuickSearchService(framework));
|
||||||
|
|
||||||
|
if (scope === 'doc') {
|
||||||
|
const docService = framework.get(DocService);
|
||||||
|
const docsService = framework.get(DocsService);
|
||||||
|
const editorService = framework.get(EditorService);
|
||||||
|
context.register([
|
||||||
|
patchDocModeService(docService, docsService, editorService),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { useConfirmModal, useLitPortalFactory } from '@affine/component';
|
||||||
|
import { getViewManager } from '@affine/core/blocksuite/manager/view';
|
||||||
|
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||||
|
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||||
|
import { useFramework, useLiveData, useServices } from '@toeverything/infra';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
|
import { useEnableAI } from './use-enable-ai';
|
||||||
|
|
||||||
|
export const useAISpecs = () => {
|
||||||
|
const framework = useFramework();
|
||||||
|
const enableAI = useEnableAI();
|
||||||
|
const confirmModal = useConfirmModal();
|
||||||
|
const [reactToLit, _portals] = useLitPortalFactory();
|
||||||
|
|
||||||
|
const { workspaceService, featureFlagService } = useServices({
|
||||||
|
WorkspaceService,
|
||||||
|
FeatureFlagService,
|
||||||
|
});
|
||||||
|
|
||||||
|
const enablePDFEmbedPreview = useLiveData(
|
||||||
|
featureFlagService.flags.enable_pdf_embed_preview.$
|
||||||
|
);
|
||||||
|
|
||||||
|
const isCloud = workspaceService.workspace.flavour !== 'local';
|
||||||
|
|
||||||
|
const specs = useMemo(() => {
|
||||||
|
const manager = getViewManager()
|
||||||
|
.config.init()
|
||||||
|
.foundation(framework)
|
||||||
|
.ai(enableAI, framework)
|
||||||
|
.editorConfig(framework)
|
||||||
|
.editorView({
|
||||||
|
framework,
|
||||||
|
reactToLit,
|
||||||
|
confirmModal,
|
||||||
|
scope: 'workspace',
|
||||||
|
})
|
||||||
|
.cloud(framework, isCloud)
|
||||||
|
.pdf(enablePDFEmbedPreview, reactToLit)
|
||||||
|
.database(framework)
|
||||||
|
.linkedDoc(framework)
|
||||||
|
.paragraph(enableAI)
|
||||||
|
.mobile(framework)
|
||||||
|
.electron(framework)
|
||||||
|
.linkPreview(framework)
|
||||||
|
.codeBlockHtmlPreview(framework).value;
|
||||||
|
|
||||||
|
return manager.get('page');
|
||||||
|
}, [
|
||||||
|
framework,
|
||||||
|
reactToLit,
|
||||||
|
enableAI,
|
||||||
|
enablePDFEmbedPreview,
|
||||||
|
isCloud,
|
||||||
|
confirmModal,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return specs;
|
||||||
|
};
|
||||||
@@ -9,6 +9,7 @@ import { AIChatToolbar } from '@affine/core/blocksuite/ai/components/ai-chat-too
|
|||||||
import type { PromptKey } from '@affine/core/blocksuite/ai/provider/prompt';
|
import type { PromptKey } from '@affine/core/blocksuite/ai/provider/prompt';
|
||||||
import { NotificationServiceImpl } from '@affine/core/blocksuite/view-extensions/editor-view/notification-service';
|
import { NotificationServiceImpl } from '@affine/core/blocksuite/view-extensions/editor-view/notification-service';
|
||||||
import { useAIChatConfig } from '@affine/core/components/hooks/affine/use-ai-chat-config';
|
import { useAIChatConfig } from '@affine/core/components/hooks/affine/use-ai-chat-config';
|
||||||
|
import { useAISpecs } from '@affine/core/components/hooks/affine/use-ai-specs';
|
||||||
import {
|
import {
|
||||||
EventSourceService,
|
EventSourceService,
|
||||||
FetchService,
|
FetchService,
|
||||||
@@ -139,6 +140,7 @@ export const Component = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const confirmModal = useConfirmModal();
|
const confirmModal = useConfirmModal();
|
||||||
|
const specs = useAISpecs();
|
||||||
|
|
||||||
// init or update ai-chat-content
|
// init or update ai-chat-content
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -154,6 +156,7 @@ export const Component = () => {
|
|||||||
|
|
||||||
content.session = currentSession;
|
content.session = currentSession;
|
||||||
content.workspaceId = workspaceId;
|
content.workspaceId = workspaceId;
|
||||||
|
content.extensions = specs;
|
||||||
content.docDisplayConfig = docDisplayConfig;
|
content.docDisplayConfig = docDisplayConfig;
|
||||||
content.searchMenuConfig = searchMenuConfig;
|
content.searchMenuConfig = searchMenuConfig;
|
||||||
content.networkSearchConfig = networkSearchConfig;
|
content.networkSearchConfig = networkSearchConfig;
|
||||||
@@ -191,6 +194,7 @@ export const Component = () => {
|
|||||||
workspaceId,
|
workspaceId,
|
||||||
confirmModal,
|
confirmModal,
|
||||||
onContextChange,
|
onContextChange,
|
||||||
|
specs,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// init or update header ai-chat-toolbar
|
// init or update header ai-chat-toolbar
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { AIProvider, ChatPanel } from '@affine/core/blocksuite/ai';
|
|||||||
import type { AffineEditorContainer } from '@affine/core/blocksuite/block-suite-editor';
|
import type { AffineEditorContainer } from '@affine/core/blocksuite/block-suite-editor';
|
||||||
import { NotificationServiceImpl } from '@affine/core/blocksuite/view-extensions/editor-view/notification-service';
|
import { NotificationServiceImpl } from '@affine/core/blocksuite/view-extensions/editor-view/notification-service';
|
||||||
import { useAIChatConfig } from '@affine/core/components/hooks/affine/use-ai-chat-config';
|
import { useAIChatConfig } from '@affine/core/components/hooks/affine/use-ai-chat-config';
|
||||||
|
import { useAISpecs } from '@affine/core/components/hooks/affine/use-ai-specs';
|
||||||
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||||
import { AppThemeService } from '@affine/core/modules/theme';
|
import { AppThemeService } from '@affine/core/modules/theme';
|
||||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
import { ViewExtensionManagerIdentifier } from '@blocksuite/affine/ext-loader';
|
|
||||||
import { RefNodeSlotsProvider } from '@blocksuite/affine/inlines/reference';
|
import { RefNodeSlotsProvider } from '@blocksuite/affine/inlines/reference';
|
||||||
import { DocModeProvider } from '@blocksuite/affine/shared/services';
|
import { DocModeProvider } from '@blocksuite/affine/shared/services';
|
||||||
import { createSignalFromObservable } from '@blocksuite/affine/shared/utils';
|
import { createSignalFromObservable } from '@blocksuite/affine/shared/utils';
|
||||||
@@ -55,6 +55,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
|||||||
playgroundConfig,
|
playgroundConfig,
|
||||||
} = useAIChatConfig();
|
} = useAIChatConfig();
|
||||||
const confirmModal = useConfirmModal();
|
const confirmModal = useConfirmModal();
|
||||||
|
const specs = useAISpecs();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor || !editor.host) return;
|
if (!editor || !editor.host) return;
|
||||||
@@ -81,9 +82,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
|||||||
chatPanelRef.current.networkSearchConfig = networkSearchConfig;
|
chatPanelRef.current.networkSearchConfig = networkSearchConfig;
|
||||||
chatPanelRef.current.reasoningConfig = reasoningConfig;
|
chatPanelRef.current.reasoningConfig = reasoningConfig;
|
||||||
chatPanelRef.current.playgroundConfig = playgroundConfig;
|
chatPanelRef.current.playgroundConfig = playgroundConfig;
|
||||||
chatPanelRef.current.extensions = editor.host.std
|
chatPanelRef.current.extensions = specs;
|
||||||
.get(ViewExtensionManagerIdentifier)
|
|
||||||
.get('preview-page');
|
|
||||||
chatPanelRef.current.affineFeatureFlagService =
|
chatPanelRef.current.affineFeatureFlagService =
|
||||||
framework.get(FeatureFlagService);
|
framework.get(FeatureFlagService);
|
||||||
chatPanelRef.current.affineWorkspaceDialogService = framework.get(
|
chatPanelRef.current.affineWorkspaceDialogService = framework.get(
|
||||||
@@ -127,6 +126,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
|||||||
reasoningConfig,
|
reasoningConfig,
|
||||||
playgroundConfig,
|
playgroundConfig,
|
||||||
confirmModal,
|
confirmModal,
|
||||||
|
specs,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [autoResized, setAutoResized] = useState(false);
|
const [autoResized, setAutoResized] = useState(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user