mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(core): show selected content chip if needed (#13415)
> CLOSE AF-2784 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved reliability when handling AI chat actions by ensuring valid context is present before proceeding. * Enhanced error handling and logging for failed context extraction in AI chat features. * **New Features** * Context extraction is now performed asynchronously before opening the AI Chat, providing more accurate and relevant chat context. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -211,13 +211,32 @@ export class AIChatComposer extends SignalWatcher(
|
||||
if (!params) return;
|
||||
|
||||
const { context, host } = params;
|
||||
if (this.host !== host) return;
|
||||
if (this.host !== host || !context) return;
|
||||
|
||||
if (context) {
|
||||
this.updateContext(context);
|
||||
if (
|
||||
context.attachments ||
|
||||
context.snapshot ||
|
||||
context.combinedElementsMarkdown
|
||||
) {
|
||||
// Wait for context value updated next frame
|
||||
setTimeout(() => {
|
||||
this.addSelectedContextChip().catch(console.error);
|
||||
}, 0);
|
||||
}
|
||||
})
|
||||
);
|
||||
this._disposables.add(
|
||||
AIProvider.slots.requestSendWithChat.subscribe(params => {
|
||||
if (!params) return;
|
||||
|
||||
if (context?.attachments) {
|
||||
const { context, host } = params;
|
||||
if (this.host !== host || !context) return;
|
||||
|
||||
if (
|
||||
context.attachments ||
|
||||
context.snapshot ||
|
||||
context.combinedElementsMarkdown
|
||||
) {
|
||||
// Wait for context value updated next frame
|
||||
setTimeout(() => {
|
||||
this.addSelectedContextChip().catch(console.error);
|
||||
|
||||
@@ -52,6 +52,7 @@ import type { AIItemGroupConfig } from '../../components/ai-item/types';
|
||||
import { AIProvider } from '../../provider';
|
||||
import { getAIPanelWidget } from '../../utils/ai-widgets';
|
||||
import { mindMapToMarkdown } from '../../utils/edgeless';
|
||||
import { extractSelectedContent } from '../../utils/extract';
|
||||
import { canvasToBlob, randomSeed } from '../../utils/image';
|
||||
import {
|
||||
getCopilotSelectedElems,
|
||||
@@ -114,11 +115,16 @@ const othersGroup: AIItemGroupConfig = {
|
||||
showWhen: () => true,
|
||||
handler: host => {
|
||||
const panel = getAIPanelWidget(host);
|
||||
AIProvider.slots.requestOpenWithChat.next({
|
||||
host,
|
||||
mode: 'edgeless',
|
||||
autoSelect: true,
|
||||
});
|
||||
extractSelectedContent(host)
|
||||
.then(context => {
|
||||
AIProvider.slots.requestOpenWithChat.next({
|
||||
host,
|
||||
mode: 'edgeless',
|
||||
autoSelect: true,
|
||||
context,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
panel.hide();
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user