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 63f42e73b0..faba297b37 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts @@ -137,6 +137,9 @@ export class ChatPanel extends SignalWatcher( @property({ attribute: false }) accessor aiModelService!: AIModelService; + @property({ attribute: false }) + accessor onAISubscribe!: () => Promise; + @state() accessor session: CopilotChatHistoryFragment | null | undefined; @@ -462,6 +465,7 @@ export class ChatPanel extends SignalWatcher( .peekViewService=${this.peekViewService} .subscriptionService=${this.subscriptionService} .aiModelService=${this.aiModelService} + .onAISubscribe=${this.onAISubscribe} .onEmbeddingProgressChange=${this.onEmbeddingProgressChange} .onContextChange=${this.onContextChange} .width=${this.sidebarWidth} diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-composer/ai-chat-composer.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-composer/ai-chat-composer.ts index c40825251d..e8ba8c8dbe 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-composer/ai-chat-composer.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-composer/ai-chat-composer.ts @@ -149,6 +149,9 @@ export class AIChatComposer extends SignalWatcher( @property({ attribute: false }) accessor aiModelService!: AIModelService; + @property({ attribute: false }) + accessor onAISubscribe!: () => Promise; + @state() accessor chips: ChatChip[] = []; @@ -200,6 +203,7 @@ export class AIChatComposer extends SignalWatcher( .notificationService=${this.notificationService} .subscriptionService=${this.subscriptionService} .aiModelService=${this.aiModelService} + .onAISubscribe=${this.onAISubscribe} .portalContainer=${this.portalContainer} .onChatSuccess=${this.onChatSuccess} .trackOptions=${this.trackOptions} diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts index bf7e40e562..b90ae1f2ac 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-content/ai-chat-content.ts @@ -192,6 +192,9 @@ export class AIChatContent extends SignalWatcher( @property({ attribute: false }) accessor subscriptionService!: SubscriptionService; + @property({ attribute: false }) + accessor onAISubscribe!: () => Promise; + @state() accessor chatContextValue: ChatContextValue = DEFAULT_CHAT_CONTEXT_VALUE; @@ -381,6 +384,9 @@ export class AIChatContent extends SignalWatcher( .catch(console.error); } + // revalidate subscription to get the latest status + this.subscriptionService.subscription.revalidate(); + this._disposables.add( AIProvider.slots.actions.subscribe(({ event }) => { const { status } = this.chatContextValue; @@ -472,6 +478,7 @@ export class AIChatContent extends SignalWatcher( .aiToolsConfigService=${this.aiToolsConfigService} .subscriptionService=${this.subscriptionService} .aiModelService=${this.aiModelService} + .onAISubscribe=${this.onAISubscribe} .trackOptions=${{ where: 'chat-panel', control: 'chat-send', diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-input/ai-chat-input.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-input/ai-chat-input.ts index 51e546d427..2876438dff 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-chat-input/ai-chat-input.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-chat-input/ai-chat-input.ts @@ -377,6 +377,9 @@ export class AIChatInput extends SignalWatcher( @property({ attribute: false }) accessor aiModelService!: AIModelService; + @property({ attribute: false }) + accessor onAISubscribe!: () => Promise; + @property({ attribute: false }) accessor isRootSession: boolean = true; @@ -534,6 +537,7 @@ export class AIChatInput extends SignalWatcher( .notificationService=${this.notificationService} .subscriptionService=${this.subscriptionService} .aiModelService=${this.aiModelService} + .onAISubscribe=${this.onAISubscribe} > ${status === 'transmitting' || status === 'loading' ? html`