mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 15:26:59 +08: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;
|
if (!params) return;
|
||||||
|
|
||||||
const { context, host } = params;
|
const { context, host } = params;
|
||||||
if (this.host !== host) return;
|
if (this.host !== host || !context) return;
|
||||||
|
|
||||||
if (context) {
|
if (
|
||||||
this.updateContext(context);
|
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
|
// Wait for context value updated next frame
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.addSelectedContextChip().catch(console.error);
|
this.addSelectedContextChip().catch(console.error);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import type { AIItemGroupConfig } from '../../components/ai-item/types';
|
|||||||
import { AIProvider } from '../../provider';
|
import { AIProvider } from '../../provider';
|
||||||
import { getAIPanelWidget } from '../../utils/ai-widgets';
|
import { getAIPanelWidget } from '../../utils/ai-widgets';
|
||||||
import { mindMapToMarkdown } from '../../utils/edgeless';
|
import { mindMapToMarkdown } from '../../utils/edgeless';
|
||||||
|
import { extractSelectedContent } from '../../utils/extract';
|
||||||
import { canvasToBlob, randomSeed } from '../../utils/image';
|
import { canvasToBlob, randomSeed } from '../../utils/image';
|
||||||
import {
|
import {
|
||||||
getCopilotSelectedElems,
|
getCopilotSelectedElems,
|
||||||
@@ -114,11 +115,16 @@ const othersGroup: AIItemGroupConfig = {
|
|||||||
showWhen: () => true,
|
showWhen: () => true,
|
||||||
handler: host => {
|
handler: host => {
|
||||||
const panel = getAIPanelWidget(host);
|
const panel = getAIPanelWidget(host);
|
||||||
AIProvider.slots.requestOpenWithChat.next({
|
extractSelectedContent(host)
|
||||||
host,
|
.then(context => {
|
||||||
mode: 'edgeless',
|
AIProvider.slots.requestOpenWithChat.next({
|
||||||
autoSelect: true,
|
host,
|
||||||
});
|
mode: 'edgeless',
|
||||||
|
autoSelect: true,
|
||||||
|
context,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
panel.hide();
|
panel.hide();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user