fix(core): not using Internet search after user selects document or file (#10058)

Fix issue [BS-2546](https://linear.app/affine-design/issue/BS-2546).
This commit is contained in:
akumatus
2025-02-10 10:40:14 +00:00
parent 6839e634e7
commit 397887e3b5
2 changed files with 11 additions and 12 deletions

View File

@@ -51,8 +51,9 @@ export function setupAIProvider(
globalDialogService: GlobalDialogService,
networkSearchService: AINetworkSearchService
) {
function getChatPrompt(attachments?: (string | File | Blob)[]) {
if (attachments?.length) {
function getChatPrompt(options: BlockSuitePresets.ChatOptions) {
const { attachments, docs } = options;
if (attachments?.length || docs?.length) {
return 'Chat With AFFiNE AI';
}
const { enabled, visible } = networkSearchService;
@@ -60,19 +61,16 @@ export function setupAIProvider(
? 'Search With AFFiNE AI'
: 'Chat With AFFiNE AI';
}
async function getChatSessionId(
workspaceId: string,
docId: string,
attachments?: (string | File | Blob)[]
) {
async function getChatSessionId(options: BlockSuitePresets.ChatOptions) {
const userId = (await AIProvider.userInfo)?.id;
if (!userId) {
throw new UnauthorizedError();
}
const { workspaceId, docId } = options;
const storeKey = `${userId}:${workspaceId}:${docId}`;
const promptName = getChatPrompt(attachments);
const promptName = getChatPrompt(options);
if (!chatSessions.has(storeKey)) {
chatSessions.set(storeKey, {
getSessionId: createChatSession({
@@ -114,9 +112,7 @@ export function setupAIProvider(
//#region actions
AIProvider.provide('chat', options => {
const sessionId =
options.sessionId ??
getChatSessionId(options.workspaceId, options.docId, options.attachments);
const sessionId = options.sessionId ?? getChatSessionId(options);
const { input, docs, ...rest } = options;
const params = docs?.length
? {