Skip to content

Comments

migrate#4684

Merged
felixfeng33 merged 3 commits intomainfrom
migrate/ai-prompt
Oct 15, 2025
Merged

migrate#4684
felixfeng33 merged 3 commits intomainfrom
migrate/ai-prompt

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 15, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2025

⚠️ No Changeset found

Latest commit: 18a7b77

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Oct 15, 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 15, 2025 8:03am

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Oct 15, 2025
@claude
Copy link
Contributor

claude bot commented Oct 15, 2025

Claude finished @felixfeng33's task —— View job


Code Review

I've completed a thorough review of this pull request. Overall, this is a significant refactor of the AI functionality with some good architectural improvements, but there are several issues that need attention.

Good Changes:

  • Excellent refactoring of the AI command route into separate prompts.ts and utils.ts files for better code organization
  • Well-structured prompt builder utility with clear separation of concerns
  • Use of @ai-sdk/gateway for multi-provider AI model support
  • Proper TypeScript typing throughout the changes

Critical Issues:

1. Missing Changeset 🚨

The bot correctly flagged this - you're adding new dependencies (@ai-sdk/gateway) and making breaking changes but haven't added a changeset. This will break the release process.

2. Breaking Change Not Documented

The switch from OpenAI API key to AI Gateway API key is a breaking change. Users who have existing OPENAI_API_KEY environment variables will need to migrate.

3. Code Duplication

There's significant duplication between:

  • apps/www/src/registry/app/api/ai/command/route.ts
  • templates/plate-playground-template/src/app/api/ai/command/route.ts

Consider extracting shared code to a common package.

4. Security Concerns

// route.ts:33
const { apiKey: key, ctx, messages: messagesRaw, model } = await req.json();
  • API key is passed in request body without rate limiting or request validation
  • No input validation on user-provided model names
  • Error messages could leak information ({ error: 'Missing AI Gateway API key.' })

5. Poor Error Handling

// route.ts:144-149
} catch {
  return NextResponse.json(
    { error: 'Failed to process AI request' },
    { status: 500 }
  );
}

Swallowing all errors without logging makes debugging impossible.

6. UI/UX Issues

The model list in settings-dialog.tsx contains 200+ models in a single dropdown. This needs categorization or search functionality for better UX.

7. No Tests

No unit tests added for the new AI command functionality, prompt builders, or utilities.

Suggestions for Improvement:

  1. Add proper error handling:
} catch (error) {
  console.error('AI request failed:', error);
  
  if (error instanceof ZodError) {
    return NextResponse.json(
      { error: 'Invalid request format' },
      { status: 400 }
    );
  }
  
  return NextResponse.json(
    { error: 'An error occurred processing your request' },
    { status: 500 }
  );
}
  1. Add input validation:
const requestSchema = z.object({
  apiKey: z.string().optional(),
  model: z.string().optional(),
  ctx: z.object({
    children: z.array(z.any()),
    selection: z.any().optional(),
    toolName: z.enum(['generate', 'edit', 'comment']).optional()
  }),
  messages: z.array(z.any())
});

const validatedData = requestSchema.parse(await req.json());
  1. Organize model list:
const modelCategories = {
  'OpenAI': [
    { label: 'GPT-3.5 Turbo', value: 'openai/gpt-3.5-turbo' },
    // ...
  ],
  'Google': [
    { label: 'Gemini 2.0 Flash', value: 'google/gemini-2.0-flash' },
    // ...
  ],
  // ...
};
  1. Add migration guide for the breaking change in the changeset

  2. Extract common code to reduce duplication

  3. Add comprehensive tests for prompt builders and AI utilities

Required Actions:

  • Add changeset with proper version bump and migration notes
  • Fix security issues with API key handling
  • Improve error handling and logging
  • Consider reorganizing the model selection UI
  • Add unit tests for new functionality

Overall, the architectural improvements are good, but the implementation needs refinement for production readiness.

@claude
Copy link
Contributor

claude bot commented Oct 15, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@dosubot dosubot bot added the plugin:ai label Oct 15, 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

const chunks = indexes
.map((index) => {
const block = blocks[index];
if (!block) {
return [];
}
const blockString = NodeApi.string(block);
const endIndex = blockString.indexOf('.');
const content =
endIndex === -1 ? blockString : blockString.slice(0, endIndex);
return [
{
delay: faker.number.int({ max: 500, min: 200 }),
texts: `{"id":"${nanoid()}","data":{"blockId":"${block.id}","comment":"${faker.lorem.sentence()}","content":"${content}"},"type":"data-comment"}`,
},
];
})
.filter((chunk) => chunk.length > 0);
const result_chunks = [
[{ delay: 50, texts: '{"data":"comment","type":"data-toolName"}' }],
...chunks,
];
return result_chunks;

P1 Badge Mock comment stream emits outdated event shape

The fallback SSE generator still emits comment events in the old flat format ({"data":{"blockId":...,"comment":...,"content":...}}). The runtime code now expects a payload shaped like {status: 'streaming' | 'finished', comment: {blockId, comment, content} | null} and immediately calls aiCommentToRange on data.data.comment. When the demo runs without a real API key (the common scenario that triggers this fake stream), data.data.comment is just a string, so no range can be resolved and the comment overlay never appears. Update the fake stream to send status plus a nested comment object (and a terminal finished event) so that the mock path mirrors the real server responses.

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

@felixfeng33 felixfeng33 enabled auto-merge October 15, 2025 08:08
@felixfeng33 felixfeng33 disabled auto-merge October 15, 2025 08:08
@felixfeng33 felixfeng33 merged commit 930a129 into main Oct 15, 2025
7 checks passed
@felixfeng33 felixfeng33 deleted the migrate/ai-prompt branch October 15, 2025 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin:ai size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant