Skip to content

Conversation

@felixfeng33
Copy link
Collaborator

Checklist

  • yarn typecheck
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

@codesandbox
Copy link

codesandbox bot commented Oct 21, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: 16c62fb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 21, 2025
@vercel
Copy link

vercel bot commented Oct 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
plate Ready Ready Preview Comment Oct 21, 2025 8:03am

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@claude
Copy link
Contributor

claude bot commented Oct 21, 2025

Claude finished @felixfeng33's task —— View job


Code Review Complete

I've reviewed your PR that adds rejectAISuggestions functionality and refactors acceptAISuggestions into a separate utility. Here's my detailed feedback:

Review Todo List

  • Analyze the code changes and refactoring
  • Check for proper error handling
  • Verify test coverage for new functionality
  • Review adherence to project coding standards
  • Check if changeset is needed
  • Provide comprehensive feedback

🚨 Critical Issues

1. Missing Changeset (Required)

The changeset-bot correctly identified that this PR modifies the @platejs/ai package but lacks a changeset. Since you're adding new functionality and exporting new utilities, you must add a changeset:

yarn changeset
# Select @platejs/ai
# Choose "patch" for this change
# Describe: "Add rejectAISuggestions utility and refactor acceptAISuggestions"

2. Missing Test Coverage

Neither the existing acceptAISuggestions nor the new rejectAISuggestions utilities have test files. This is concerning for maintainability:

  • No tests in packages/ai/src/react/ai-chat/utils/ directory
  • No tests for the acceptAIChat transform that uses these utilities

⚠️ Significant Issues

3. Unused Code

The new rejectAISuggestions function is added but not used anywhere in the codebase. While this might be intended for future use, adding unused code is generally not recommended:

  • Consider adding the corresponding rejectAIChat transform if this is meant to be used
  • Or document why this utility is being added preemptively

4. Code Duplication

The acceptAISuggestions and rejectAISuggestions functions are nearly identical (lines 6-33), differing only in calling acceptSuggestion vs rejectSuggestion. This violates DRY principles.

Suggested refactoring:

const processSuggestions = (
  editor: PlateEditor, 
  action: 'accept' | 'reject'
) => {
  const suggestions = editor.getApi(SuggestionPlugin).suggestion.nodes({
    transient: true,
  });

  suggestions.forEach(([suggestionNode]) => {
    const suggestionData = editor
      .getApi(SuggestionPlugin)
      .suggestion.suggestionData(suggestionNode);

    if (!suggestionData) return;

    const description = {
      createdAt: new Date(suggestionData.createdAt),
      keyId: getSuggestionKey(suggestionData.id),
      suggestionId: suggestionData.id,
      type: suggestionData.type,
      userId: suggestionData.userId,
    };

    if (action === 'accept') {
      acceptSuggestion(editor, description);
    } else {
      rejectSuggestion(editor, description);
    }
  });

  editor.tf.unsetNodes([getTransientSuggestionKey()], {
    at: [],
    mode: 'all',
    match: (n) => !!n[getTransientSuggestionKey()],
  });
};

export const acceptAISuggestions = (editor: PlateEditor) => 
  processSuggestions(editor, 'accept');

export const rejectAISuggestions = (editor: PlateEditor) => 
  processSuggestions(editor, 'reject');

✅ Positive Aspects

  • Good refactoring of acceptAISuggestions into a separate utility
  • Consistent code style following the project patterns
  • Proper TypeScript typing
  • Clean imports and exports

📋 Additional Recommendations

  1. Documentation: Consider adding JSDoc comments to explain what these utilities do
  2. Error Handling: The functions silently continue on errors (if (!suggestionData) return;). Consider logging warnings for debugging
  3. Type Safety: The suggestionData type could be more explicitly typed

Summary

While the refactoring improves code organization, this PR needs:

  1. A changeset (required)
  2. Test coverage for the new utilities
  3. Either usage of rejectAISuggestions or justification for adding it
  4. Consider reducing code duplication between accept/reject functions

@dosubot dosubot bot added the plugin:ai label Oct 21, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

import { acceptSuggestions } from './acceptAIChat';
import { createFormattedBlocks } from './replaceSelectionAIChat';
export const insertBelowAIChat = (
editor: PlateEditor,
sourceEditor: SlateEditor,
{ format = 'single' }: { format?: 'all' | 'none' | 'single' } = {}
) => {
const { toolName } = editor.getOptions(AIChatPlugin);
if (toolName === 'generate')
return insertBelowGenerate(editor, sourceEditor, { format });
const selectedBlocks = editor
.getApi(BlockSelectionPlugin)
.blockSelection.getNodes();
const selectedIds = editor.getOptions(BlockSelectionPlugin).selectedIds;
editor.getTransforms(AIPlugin).ai.undo();
const insertBlocksAndSelect =
editor.getTransforms(BlockSelectionPlugin).blockSelection
.insertBlocksAndSelect;
if (!selectedIds || selectedIds.size === 0) return;
const lastBlock = selectedBlocks.at(-1);
if (!lastBlock) return;
const nextPath = PathApi.next(lastBlock[1]);
const nodes = selectedBlocks.map((block) => block[0]);
insertBlocksAndSelect(nodes, {
at: nextPath,
insertedCallback: () => {
withAIBatch(editor, () => {
acceptSuggestions(editor);

P0 Badge Update import to new accept utility

The commit moved the suggestion acceptance logic into utils/acceptAISuggestions.ts and removed the acceptSuggestions export from acceptAIChat.ts, but insertBelowAIChat still imports and calls acceptSuggestions. After this change the module no longer exists, so this file will fail to compile with a missing export error. insertBelowAIChat should import acceptAISuggestions (or a new reject helper) from the utils barrel and invoke that instead.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@felixfeng33
Copy link
Collaborator Author

@claude /changeset

@claude
Copy link
Contributor

claude bot commented Oct 21, 2025

Claude finished @felixfeng33's task —— View job


Changeset Created ✅

I've created the changeset file for your PR that adds rejectAISuggestions functionality.

Todo List:

  • Read changed files to understand the modifications
  • Fix the import issue in insertBelowAIChat.ts (already fixed)
  • Create changeset file for @platejs/ai package
  • Commit changes to the PR branch

Summary

Created .changeset/platejs-ai-minor.md with a minor version bump for @platejs/ai package since this PR:

  • Adds new rejectAISuggestions utility function
  • Refactors acceptAISuggestions into a reusable module
  • Exports both utilities for use across different transforms

The changeset-bot should now recognize the changeset and update its comment accordingly.

@claude
Copy link
Contributor

claude bot commented Oct 21, 2025

Claude finished @felixfeng33's task —— View job


Changeset created successfully ✓

Todo List

  • Read changed files to understand the scope of changes
  • Create changeset file for @platejs/ai package
  • Commit the changeset

Created changeset .changeset/clever-ducks-shine.md with a patch version bump for @platejs/ai package. The changeset documents the addition of the new rejectAISuggestions utility and the refactoring of acceptAISuggestions into a separate utility for better code organization.

@felixfeng33 felixfeng33 merged commit 2528c15 into main Oct 21, 2025
9 checks passed
@felixfeng33 felixfeng33 deleted the fix/ai-suggestions branch October 21, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin:ai size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants