Skip to content

Conversation

@qinluhe
Copy link
Contributor

@qinluhe qinluhe commented Mar 18, 2025

Description


Checklist

General

  • I've included relevant documentation or comments for the changes introduced.
  • I've tested the changes in multiple environments (e.g., different browsers, operating systems).

Testing

  • I've added or updated tests to validate the changes introduced for AppFlowy Web.

Feature-Specific

  • For feature additions, I've added a preview (video, screenshot, or demo) in the "Feature Preview" section.
  • I've verified that this feature integrates seamlessly with existing functionality.

Summary by Sourcery

Add AI writer support to the AppFlowy web editor, including AI assistant features, slash menu AI options, and infrastructure for AI-powered writing tools

New Features:

  • Integrate AI writer functionality into the editor's toolbar and slash menu
  • Add AI assistant actions like improve writing and ask AI
  • Implement AI-powered writing assistance with context-aware suggestions

Enhancements:

  • Extend editor context to support AI writing features
  • Add new AI-related icons and styling
  • Improve selection and content extraction for AI tools

@github-actions
Copy link

github-actions bot commented Mar 18, 2025

🥷 Ninja i18n – 🛎️ Translations need to be updated

Project /project.inlang

lint rule new reports level link
Missing translation 504 warning contribute (via Fink 🐦)

@qinluhe qinluhe force-pushed the feat/support-ai-writer branch from 6a9aa6c to 12aa3f2 Compare March 18, 2025 08:21
@qinluhe qinluhe force-pushed the feat/support-ai-writer branch from 12aa3f2 to a3a81ad Compare March 19, 2025 02:40
@qinluhe qinluhe force-pushed the feat/support-ai-writer branch 20 times, most recently from 80a22e5 to 0bc9a4b Compare March 26, 2025 06:48
@qinluhe qinluhe force-pushed the feat/support-ai-writer branch 5 times, most recently from 64e2335 to 62dc3b9 Compare March 27, 2025 08:04
@qinluhe qinluhe force-pushed the feat/support-ai-writer branch 8 times, most recently from 355e369 to 97efa9f Compare March 28, 2025 05:47
@qinluhe qinluhe marked this pull request as ready for review March 28, 2025 06:07
@qinluhe qinluhe force-pushed the feat/support-ai-writer branch from 97efa9f to 4235493 Compare March 28, 2025 06:08
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 28, 2025

Reviewer's Guide by Sourcery

This pull request introduces AI writing assistance features, improves the selection toolbar's visibility logic and positioning, adds functionality to duplicate pages, and fixes a bug where blocks could not be found.

Sequence diagram for AI Writer: Ask AI Anything

sequenceDiagram
    participant User
    participant SlashPanel
    participant Editor
    participant AIWriter

    User->>SlashPanel: Types '/' and selects 'Ask AI Anything'
    activate SlashPanel
    SlashPanel->>Editor: getBeforeContent()
    activate Editor
    Editor-->>SlashPanel: Returns content before cursor
    deactivate Editor
    SlashPanel->>AIWriter: askAIAnything(content)
    deactivate SlashPanel
    activate AIWriter
    AIWriter->>AIWriter: Processes content and generates response
    AIWriter-->>Editor: Inserts AI-generated content into Editor
    deactivate AIWriter
Loading

Sequence diagram for AI Writer: Continue Writing

sequenceDiagram
    participant User
    participant SlashPanel
    participant Editor
    participant AIWriter

    User->>SlashPanel: Types '/' and selects 'Continue Writing'
    activate SlashPanel
    SlashPanel->>Editor: getBeforeContent()
    activate Editor
    Editor-->>SlashPanel: Returns content before cursor
    deactivate Editor
    SlashPanel->>AIWriter: continueWriting(content)
    deactivate SlashPanel
    activate AIWriter
    AIWriter->>AIWriter: Processes content and generates response
    AIWriter-->>Editor: Inserts AI-generated content into Editor
    deactivate AIWriter
Loading

Updated class diagram for EditorOverlay

classDiagram
    class EditorOverlay{
        -viewId: string
        -workspaceId: string
        -writerRequest: WriterRequest
        -handleInsertBelow(data: EditorData): void
        -handleReplaceSelection(data: EditorData): void
        -handleExit(): void
        -container: HTMLDivElement | null
        -scrollerContainer: HTMLDivElement | null
        -absoluteHeight: number
    }
    class WriterRequest{
        -workspaceId: string
        -viewId: string
        -requestInstance: any
        +WriterRequest(workspaceId: string, viewId: string, requestInstance: any)
    }
    EditorOverlay --|> AIAssistantProvider : uses
    EditorOverlay ..> WriterRequest : creates
    AIAssistantProvider ..> EditorData : handles
    note for EditorOverlay "This class integrates the AI Assistant Provider into the editor overlay."
Loading

Updated class diagram for SlashPanel

classDiagram
    class SlashPanel{
        -searchText: string
        -removeContent(): void
        -addPage(parentId: string, payload: CreatePagePayload): Promise<string>
        -openPageModal(pageId: string): void
        -viewId: string
        -loadViewMeta(viewId: string): Promise<View>
        -viewName: string
        -setViewName(name: string): void
        -editor: YjsEditor
        -t: UseTranslation
        -optionsRef: useRef
        -selectedOption: string | null
        -transformOrigin: PopoverOrigin | undefined
        -selectedOptionRef: useRef
        -openPopover(anchorEl: HTMLElement): void
        -closePopover(): void
        -openPanel(panelType: PanelType): void
        -askAIAnything(content: string): void
        -continueWriting(content: string): Promise<void>
        -getBeforeContent(): string
        -chars: number
    }
    SlashPanel --|> usePanelContext : uses
    SlashPanel --|> useEditorContext : uses
    SlashPanel --|> useTranslation : uses
    SlashPanel --|> useSlateStatic : uses
    SlashPanel --|> useAIWriter : uses
    note for SlashPanel "This class integrates AI writing actions into the slash panel."
Loading

File-Level Changes

Change Details Files
Introduces AI writing assistance features within the editor, allowing users to ask AI for help and continue writing with AI suggestions.
  • Added @appflowyinc/ai-chat dependency.
  • Wrapped the editor overlay with AIAssistantProvider to manage AI writing requests and responses.
  • Implemented handleInsertBelow and handleReplaceSelection functions to insert AI-generated content into the editor.
  • Added a context placeholder to display AI writing context.
  • Added AI-related actions to the selection toolbar.
  • Added slash commands for AI writing.
  • Added a new component AIAssistant to the toolbar.
  • Added a new component AIWriterMenu to the toolbar.
  • Added a new component BlockNotFound to handle blocks that are not found.
  • Added a new component UpgradeAIMax to handle AI Max subscription.
  • Added a new component AskAIIcon to the toolbar.
  • Added a new component ContinueWritingIcon to the toolbar.
  • Added a new component ImproveWritingIcon to the toolbar.
src/components/editor/EditorOverlay.tsx
pnpm-lock.yaml
src/components/editor/components/toolbar/selection-toolbar/ToolbarActions.tsx
src/components/billing/UpgradePlan.tsx
src/components/editor/components/panels/slash-panel/SlashPanel.tsx
src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.hooks.ts
src/components/ai-chat/utils.ts
src/components/app/workspaces/Workspaces.tsx
src/components/app/view-actions/MoreSpaceActions.tsx
src/components/app/header/MoreActionsContent.tsx
src/pages/AcceptInvitationPage.tsx
src/application/slate-yjs/utils/applyToYjs.ts
src/components/editor/Editable.tsx
src/application/slate-yjs/utils/applyToSlate.ts
src/components/editor/components/toolbar/block-controls/HoverControls.hooks.ts
src/components/editor/components/blocks/link-preview/LinkPreview.tsx
src/components/database/Database.tsx
src/components/editor/editor.scss
src/components/_shared/notify/InfoSnackbar.tsx
src/application/slate-yjs/command/index.ts
src/application/services/js-services/http/http_api.ts
src/components/database/components/header/DatabaseRowHeader.tsx
src/components/_shared/breadcrumb/BreadcrumbItem.tsx
src/components/_shared/help/Help.tsx
src/components/publish/CollabView.tsx
src/components/database/components/database-row/DatabaseRowSubDocument.tsx
src/components/editor/__tests__/mount.tsx
src/components/editor/components/blocks/text/Text.tsx
src/application/slate-yjs/utils/yjs.ts
src/components/ai-chat/DrawerContent.tsx
src/components/publish/DatabaseView.tsx
tailwind/colors.cjs
src/application/slate-yjs/utils/convert.ts
src/components/editor/EditorContext.tsx
src/components/editor/components/blocks/image/Img.tsx
src/application/database-yjs/context.ts
src/application/types.ts
src/components/billing/UpgradeAIMax.tsx
src/components/editor/components/toolbar/selection-toolbar/actions/AIAssistant.tsx
src/components/editor/components/element/BlockNotFound.tsx
src/assets/ai.svg
src/assets/continue_writing.svg
src/assets/help_documentation.svg
src/assets/improve-writing.svg
src/assets/upgrade_ai_max.svg
Improves the selection toolbar's visibility logic and positioning.
  • Modified useVisible hook to include assistantType in determining toolbar visibility.
  • Added event listeners for selectionchange to dynamically update toolbar visibility.
  • Updated useToolbarPosition hook to ensure the toolbar remains within the editor bounds.
src/components/editor/components/toolbar/selection-toolbar/SelectionToolbar.hooks.ts
Adds functionality to duplicate pages within the application.
  • Implemented duplicateAppPage in AFClientService to call the duplicate page API.
  • Added a duplicate page API call in http_api.ts.
  • Added duplicate action to the more actions menu in MoreActionsContent.tsx.
  • Added duplicate action to the more space actions menu in MoreSpaceActions.tsx.
src/application/services/js-services/index.ts
src/application/services/js-services/http/http_api.ts
src/components/app/view-actions/MoreSpaceActions.tsx
src/components/app/header/MoreActionsContent.tsx
Fixes a bug where blocks could not be found.
  • Added a new component BlockNotFound to handle blocks that are not found.
  • Modified traverseBlock to return a block_not_found block when a block is not found.
src/application/slate-yjs/utils/convert.ts
src/components/editor/components/element/BlockNotFound.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We encountered an error and are unable to review this PR. We have been notified and are working to fix it.

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

@qinluhe qinluhe force-pushed the feat/support-ai-writer branch 4 times, most recently from 211e88a to 289cf4c Compare March 28, 2025 07:49
@qinluhe qinluhe force-pushed the feat/support-ai-writer branch from 289cf4c to 5693542 Compare March 31, 2025 02:13
@qinluhe qinluhe merged commit b298bb4 into main Mar 31, 2025
3 checks passed
@qinluhe qinluhe deleted the feat/support-ai-writer branch March 31, 2025 02:21
appflowy pushed a commit that referenced this pull request Nov 14, 2025
josue693 pushed a commit to josue693/AppFlowy-Web that referenced this pull request Dec 21, 2025
* feat: support ai writer

* feat: support duplicate page

* feat: support upgrade AI Max
josue693 pushed a commit to josue693/AppFlowy-Web that referenced this pull request Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant