From 1f0cc51462e308fc17e6fa35f38d13aa44fe80ba Mon Sep 17 00:00:00 2001 From: akumatus Date: Wed, 4 Jun 2025 03:42:25 +0000 Subject: [PATCH] fix(core): ai retry missing reasoning and webSearch params (#12690) Close [AI-165](https://linear.app/affine-design/issue/AI-165) ## Summary by CodeRabbit - **New Features** - Enhanced chat components to support advanced reasoning and network search options, providing more control over AI-powered interactions. - Improved polling for context documents and files, now also triggered by additional chip types for more comprehensive updates. - **Bug Fixes** - Ensured consistent application of configuration settings across all relevant chat components. --- .../ai/chat-panel/chat-panel-messages.ts | 23 +++++++++++++++++++ .../src/blocksuite/ai/chat-panel/index.ts | 2 ++ .../ai-chat-composer/ai-chat-composer.ts | 7 ++++-- .../ai/components/playground/chat.ts | 2 ++ .../ai/peek-view/chat-block-peek-view.ts | 13 +++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-messages.ts b/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-messages.ts index 6f4edd22c..31cdb81dd 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-messages.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/chat-panel-messages.ts @@ -13,6 +13,10 @@ import { repeat } from 'lit/directives/repeat.js'; import { debounce } from 'lodash-es'; import { AffineIcon } from '../_common/icons'; +import type { + AINetworkSearchConfig, + AIReasoningConfig, +} from '../components/ai-chat-input'; import { type ChatMessage, isChatAction, @@ -161,6 +165,12 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) { @property({ attribute: false }) accessor affineFeatureFlagService!: FeatureFlagService; + @property({ attribute: false }) + accessor networkSearchConfig!: AINetworkSearchConfig; + + @property({ attribute: false }) + accessor reasoningConfig!: AIReasoningConfig; + @query('.chat-panel-messages-container') accessor messagesContainer: HTMLDivElement | null = null; @@ -175,6 +185,17 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) { return this.messagesContainer; } + private get _isNetworkActive() { + return ( + !!this.networkSearchConfig.visible.value && + !!this.networkSearchConfig.enabled.value + ); + } + + private get _isReasoningActive() { + return !!this.reasoningConfig.enabled.value; + } + private _renderAIOnboarding() { return this.isLoading || !this.host?.store.get(FeatureFlagService).getFlag('enable_ai_onboarding') @@ -380,6 +401,8 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) { where: 'chat-panel', control: 'chat-send', isRootSession: true, + reasoning: this._isReasoningActive, + webSearch: this._isNetworkActive, }); this.updateContext({ abortController }); for await (const text of stream) { diff --git a/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts b/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts index baa72ed31..307022667 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts @@ -456,6 +456,8 @@ export class ChatPanel extends SignalWatcher( .isLoading=${this.isLoading} .extensions=${this.extensions} .affineFeatureFlagService=${this.affineFeatureFlagService} + .networkSearchConfig=${this.networkSearchConfig} + .reasoningConfig=${this.reasoningConfig} > chip.state === 'processing'); - if (isProcessing) { + const needPoll = this.chips.some( + chip => + chip.state === 'processing' || isTagChip(chip) || isCollectionChip(chip) + ); + if (needPoll) { await this._pollContextDocsAndFiles(); } this._isLoading = false; diff --git a/packages/frontend/core/src/blocksuite/ai/components/playground/chat.ts b/packages/frontend/core/src/blocksuite/ai/components/playground/chat.ts index 908967dc5..b4753dfac 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/playground/chat.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/playground/chat.ts @@ -299,6 +299,8 @@ export class PlaygroundChat extends SignalWatcher( .isLoading=${this.isLoading} .extensions=${this.extensions} .affineFeatureFlagService=${this.affineFeatureFlagService} + .networkSearchConfig=${this.networkSearchConfig} + .reasoningConfig=${this.reasoningConfig} >