tiny-editor icon indicating copy to clipboard operation
tiny-editor copied to clipboard

feat: Add AI module

Open chenxi-20 opened this issue 8 months ago • 2 comments

PR

效果如下:

AI回答之后的效果: image

点击完成之后的效果: image

PR Checklist

Please check if your PR fulfills the following requirements:

  • [ ] The commit message follows our Commit Message Guidelines
  • [ ] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [ ] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Documentation content changes
  • [ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • [ ] Yes
  • [ ] No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced AI-assisted text generation in the Fluent Editor with a new AI toolbar button.
    • Added an interactive AI input dialog supporting live streaming responses and controls to insert, regenerate, or close AI-generated content.
    • Integrated a dedicated AI icon and comprehensive UI styling for a seamless AI interaction experience.
    • Included a demo component and documentation to showcase AI capabilities within the editor.
  • Documentation

    • Added a new AI section and demo in the usage examples sidebar.

chenxi-20 avatar Apr 16 '25 09:04 chenxi-20

Walkthrough

This update introduces AI-assisted text generation capabilities to the Fluent Editor. It adds a new AI module, integrates an AI button into the editor toolbar, and provides a user interface for submitting prompts and inserting AI-generated content. Supporting changes include new SCSS styles for the AI dialog, icon additions, toolbar configuration updates, and documentation with a demo. The sidebar is updated to include an AI demo entry, and relevant assets and modules are imported and registered to enable the new feature.

Changes

File(s) Change Summary
packages/docs/fluent-editor/.vitepress/sidebar.ts Added a sidebar entry labeled "AI" linking to "/docs/demo/ai" under the "使用示例" section.
packages/docs/fluent-editor/demos/ai.vue,
packages/docs/fluent-editor/docs/demo/ai.md
Introduced a new Vue demo component and corresponding markdown documentation showcasing AI integration and configuration within the editor.
packages/fluent-editor/src/assets/ai.scss,
packages/fluent-editor/src/assets/style.scss
Added new SCSS styles for the AI dialog and imported them into the main style entry file.
packages/fluent-editor/src/fluent-editor.ts Imported and registered the new AI module in the FluentEditor registration system.
packages/fluent-editor/src/modules/ai/index.ts Added a new exported AI class implementing the AI-assisted text generation interface, including UI, event handling, streaming API calls, and editor integration.
packages/fluent-editor/src/themes/snow.ts Added a no-op handler for 'ai' to the toolbar handlers in the snow theme configuration.
packages/fluent-editor/src/ui/icons.config.ts,
packages/fluent-editor/src/ui/icons.ts
Added a new AI SVG icon constant and registered it in the icons configuration for use in the editor UI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor (FluentEditor)
    participant AI Module
    participant AI Backend

    User->>Editor: Clicks AI button in toolbar
    Editor->>AI Module: Show AI input dialog
    User->>AI Module: Enters prompt and submits
    AI Module->>AI Backend: Sends prompt (streaming request)
    AI Backend-->>AI Module: Streams generated content
    AI Module->>User: Displays live AI response
    User->>AI Module: Chooses action (Insert/Regenerate/Close)
    AI Module->>Editor: Inserts content or closes dialog

Estimated code review effort

3 (90–240 minutes)

Poem

In the garden of code, a new seed is sown,
AI now whispers where ideas are grown.
With a click and a prompt, inspiration flows,
The editor listens, and creativity grows.
Icons gleam bright, dialogs appear—
Hopping ahead, the future is here!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3e9cbb3cd4edd29b512106963da242edb919624 and 02e980d13175262d5aaf741e7d35f7e5bea22deb.

📒 Files selected for processing (2)
  • packages/fluent-editor/src/fluent-editor.ts (2 hunks)
  • packages/fluent-editor/src/ui/icons.config.ts (1 hunks)
🪛 GitHub Check: lint
packages/fluent-editor/src/ui/icons.config.ts

[failure] 328-328: Unexpected tab character


[failure] 327-327: Unexpected tab character


[failure] 326-326: Unexpected tab character


[failure] 325-325: Unexpected tab character


[failure] 324-324: Unexpected tab character


[failure] 323-323: Unexpected tab character


[failure] 322-322: Unexpected tab character


[failure] 321-321: Unexpected tab character


[failure] 320-320: Unexpected tab character


[failure] 319-319: Unexpected tab character

🪛 ESLint
packages/fluent-editor/src/ui/icons.config.ts

[error] 319-319: Unexpected tab character.

(style/no-tabs)


[error] 320-320: Unexpected tab character.

(style/no-tabs)


[error] 321-321: Unexpected tab character.

(style/no-tabs)


[error] 322-322: Unexpected tab character.

(style/no-tabs)


[error] 323-323: Unexpected tab character.

(style/no-tabs)


[error] 324-324: Unexpected tab character.

(style/no-tabs)


[error] 325-325: Unexpected tab character.

(style/no-tabs)


[error] 326-326: Unexpected tab character.

(style/no-tabs)


[error] 327-327: Unexpected tab character.

(style/no-tabs)


[error] 328-328: Unexpected tab character.

(style/no-tabs)


[error] 329-329: Unexpected tab character.

(style/no-tabs)

🪛 GitHub Actions: autofix.ci
packages/fluent-editor/src/ui/icons.config.ts

[error] 319-319: ESLint: Unexpected tab character (style/no-tabs)

🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/fluent-editor/src/fluent-editor.ts
🧰 Additional context used
🪛 GitHub Check: lint
packages/fluent-editor/src/ui/icons.config.ts

[failure] 328-328: Unexpected tab character


[failure] 327-327: Unexpected tab character


[failure] 326-326: Unexpected tab character


[failure] 325-325: Unexpected tab character


[failure] 324-324: Unexpected tab character


[failure] 323-323: Unexpected tab character


[failure] 322-322: Unexpected tab character


[failure] 321-321: Unexpected tab character


[failure] 320-320: Unexpected tab character


[failure] 319-319: Unexpected tab character

🪛 ESLint
packages/fluent-editor/src/ui/icons.config.ts

[error] 319-319: Unexpected tab character.

(style/no-tabs)


[error] 320-320: Unexpected tab character.

(style/no-tabs)


[error] 321-321: Unexpected tab character.

(style/no-tabs)


[error] 322-322: Unexpected tab character.

(style/no-tabs)


[error] 323-323: Unexpected tab character.

(style/no-tabs)


[error] 324-324: Unexpected tab character.

(style/no-tabs)


[error] 325-325: Unexpected tab character.

(style/no-tabs)


[error] 326-326: Unexpected tab character.

(style/no-tabs)


[error] 327-327: Unexpected tab character.

(style/no-tabs)


[error] 328-328: Unexpected tab character.

(style/no-tabs)


[error] 329-329: Unexpected tab character.

(style/no-tabs)

🪛 GitHub Actions: autofix.ci
packages/fluent-editor/src/ui/icons.config.ts

[error] 319-319: ESLint: Unexpected tab character (style/no-tabs)

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 16 '25 09:04 coderabbitai[bot]

@chenxi-20 需要解决下冲突

kagol avatar Apr 16 '25 12:04 kagol

@all-contributors please add @chenxi-20 for code.

kagol avatar Oct 20 '25 07:10 kagol

@kagol

I've put up a pull request to add @chenxi-20! :tada:

allcontributors[bot] avatar Oct 20 '25 07:10 allcontributors[bot]