diff --git a/packages/frontend/core/src/blocksuite/ai/actions/types.ts b/packages/frontend/core/src/blocksuite/ai/actions/types.ts index f690489d9d..de8ea85392 100644 --- a/packages/frontend/core/src/blocksuite/ai/actions/types.ts +++ b/packages/frontend/core/src/blocksuite/ai/actions/types.ts @@ -85,8 +85,8 @@ declare global { // internal context host: EditorHost; models?: (BlockModel | GfxModel)[]; - control: TrackerControl; - where: TrackerWhere; + control?: TrackerControl; + where?: TrackerWhere; } interface AIForkChatSessionOptions { 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 33df0497cd..baa72ed316 100644 --- a/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts +++ b/packages/frontend/core/src/blocksuite/ai/chat-panel/index.ts @@ -3,11 +3,13 @@ import './chat-panel-messages'; import type { FeatureFlagService } from '@affine/core/modules/feature-flag'; import type { ContextEmbedStatus, CopilotSessionType } from '@affine/graphql'; import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit'; +import { unsafeCSSVarV2 } from '@blocksuite/affine/shared/theme'; import type { EditorHost } from '@blocksuite/affine/std'; import { ShadowlessElement } from '@blocksuite/affine/std'; import type { ExtensionType, Store } from '@blocksuite/affine/store'; +import { CenterPeekIcon } from '@blocksuite/icons/lit'; import { type Signal, signal } from '@preact/signals-core'; -import { css, html, type PropertyValues } from 'lit'; +import { css, html, nothing, type PropertyValues } from 'lit'; import { property, state } from 'lit/decorators.js'; import { createRef, type Ref, ref } from 'lit/directives/ref.js'; import { styleMap } from 'lit/directives/style-map.js'; @@ -23,6 +25,7 @@ import type { AIReasoningConfig, } from '../components/ai-chat-input'; import { type HistoryMessage } from '../components/ai-chat-messages'; +import { createPlaygroundModal } from '../components/playground/modal'; import { AIProvider } from '../provider'; import { extractSelectedContent } from '../utils/extract'; import { @@ -104,6 +107,20 @@ export class ChatPanel extends SignalWatcher( .chat-panel-hints :nth-child(2) { color: var(--affine-text-secondary-color); } + + .chat-panel-playground { + cursor: pointer; + padding: 2px; + margin-left: 8px; + margin-right: auto; + display: flex; + justify-content: center; + align-items: center; + } + + .chat-panel-playground:hover svg { + color: ${unsafeCSSVarV2('icon/activated')}; + } `; private readonly _chatMessagesRef: Ref = @@ -165,13 +182,7 @@ export class ChatPanel extends SignalWatcher( this.doc.id, { action: false } )) || [] - ).filter(session => { - if (this.parentSessionId) { - return session.parentSessionId === this.parentSessionId; - } else { - return !session.parentSessionId; - } - }); + ).filter(session => !session.parentSessionId); this.session = sessions.at(-1); return this.session?.id; }; @@ -224,9 +235,6 @@ export class ChatPanel extends SignalWatcher( @property({ attribute: false }) accessor affineFeatureFlagService!: FeatureFlagService; - @property({ attribute: false }) - accessor parentSessionId: string | undefined = undefined; - @state() accessor isLoading = false; @@ -277,6 +285,25 @@ export class ChatPanel extends SignalWatcher( this.embeddingProgress = [0, 0]; }; + private readonly _openPlayground = () => { + const playgroundContent = html` + + `; + + createPlaygroundModal(playgroundContent, 'AI Playground'); + }; + protected override willUpdate(_changedProperties: PropertyValues) { if (_changedProperties.has('doc')) { this._resetPanel(); @@ -404,6 +431,13 @@ export class ChatPanel extends SignalWatcher( >` : 'AFFiNE AI'} + ${this.modelSwitchConfig.visible.value + ? html` +
+ ${CenterPeekIcon()} +
+ ` + : nothing} `; } 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 837d8c7786..a09407aaf1 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 @@ -97,13 +97,13 @@ export class AIChatComposer extends SignalWatcher( accessor onChatSuccess: (() => void) | undefined; @property({ attribute: false }) - accessor trackOptions!: BlockSuitePresets.TrackerOptions; + accessor trackOptions: BlockSuitePresets.TrackerOptions | undefined; @property({ attribute: false }) accessor portalContainer: HTMLElement | null = null; @property({ attribute: false }) - accessor sideBarWidth: Signal = signal(undefined); + accessor panelWidth: Signal = signal(undefined); @state() accessor chips: ChatChip[] = []; @@ -144,7 +144,7 @@ export class AIChatComposer extends SignalWatcher( .docDisplayConfig=${this.docDisplayConfig} .onChatSuccess=${this.onChatSuccess} .trackOptions=${this.trackOptions} - .sideBarWidth=${this.sideBarWidth} + .panelWidth=${this.panelWidth} .addImages=${this.addImages} >