mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
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:
@@ -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
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user