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:
@@ -363,7 +363,10 @@ export class ChatPanelInput extends SignalWatcher(WithDisposable(LitElement)) {
|
|||||||
const { images, status } = this.chatContextValue;
|
const { images, status } = this.chatContextValue;
|
||||||
const hasImages = images.length > 0;
|
const hasImages = images.length > 0;
|
||||||
const maxHeight = hasImages ? 272 + 2 : 200 + 2;
|
const maxHeight = hasImages ? 272 + 2 : 200 + 2;
|
||||||
const networkDisabled = !!this.chatContextValue.images.length;
|
const networkDisabled =
|
||||||
|
!!this.chatContextValue.images.length ||
|
||||||
|
!!this.chatContextValue.chips.filter(chip => chip.state !== 'candidate')
|
||||||
|
.length;
|
||||||
const networkActive = !!this.networkSearchConfig.enabled.value;
|
const networkActive = !!this.networkSearchConfig.enabled.value;
|
||||||
const uploadDisabled = networkActive && !networkDisabled;
|
const uploadDisabled = networkActive && !networkDisabled;
|
||||||
return html`<style>
|
return html`<style>
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ export function setupAIProvider(
|
|||||||
globalDialogService: GlobalDialogService,
|
globalDialogService: GlobalDialogService,
|
||||||
networkSearchService: AINetworkSearchService
|
networkSearchService: AINetworkSearchService
|
||||||
) {
|
) {
|
||||||
function getChatPrompt(attachments?: (string | File | Blob)[]) {
|
function getChatPrompt(options: BlockSuitePresets.ChatOptions) {
|
||||||
if (attachments?.length) {
|
const { attachments, docs } = options;
|
||||||
|
if (attachments?.length || docs?.length) {
|
||||||
return 'Chat With AFFiNE AI';
|
return 'Chat With AFFiNE AI';
|
||||||
}
|
}
|
||||||
const { enabled, visible } = networkSearchService;
|
const { enabled, visible } = networkSearchService;
|
||||||
@@ -60,19 +61,16 @@ export function setupAIProvider(
|
|||||||
? 'Search With AFFiNE AI'
|
? 'Search With AFFiNE AI'
|
||||||
: 'Chat With AFFiNE AI';
|
: 'Chat With AFFiNE AI';
|
||||||
}
|
}
|
||||||
async function getChatSessionId(
|
async function getChatSessionId(options: BlockSuitePresets.ChatOptions) {
|
||||||
workspaceId: string,
|
|
||||||
docId: string,
|
|
||||||
attachments?: (string | File | Blob)[]
|
|
||||||
) {
|
|
||||||
const userId = (await AIProvider.userInfo)?.id;
|
const userId = (await AIProvider.userInfo)?.id;
|
||||||
|
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
throw new UnauthorizedError();
|
throw new UnauthorizedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { workspaceId, docId } = options;
|
||||||
const storeKey = `${userId}:${workspaceId}:${docId}`;
|
const storeKey = `${userId}:${workspaceId}:${docId}`;
|
||||||
const promptName = getChatPrompt(attachments);
|
const promptName = getChatPrompt(options);
|
||||||
if (!chatSessions.has(storeKey)) {
|
if (!chatSessions.has(storeKey)) {
|
||||||
chatSessions.set(storeKey, {
|
chatSessions.set(storeKey, {
|
||||||
getSessionId: createChatSession({
|
getSessionId: createChatSession({
|
||||||
@@ -114,9 +112,7 @@ export function setupAIProvider(
|
|||||||
|
|
||||||
//#region actions
|
//#region actions
|
||||||
AIProvider.provide('chat', options => {
|
AIProvider.provide('chat', options => {
|
||||||
const sessionId =
|
const sessionId = options.sessionId ?? getChatSessionId(options);
|
||||||
options.sessionId ??
|
|
||||||
getChatSessionId(options.workspaceId, options.docId, options.attachments);
|
|
||||||
const { input, docs, ...rest } = options;
|
const { input, docs, ...rest } = options;
|
||||||
const params = docs?.length
|
const params = docs?.length
|
||||||
? {
|
? {
|
||||||
|
|||||||
Reference in New Issue
Block a user