Skip to content

feat(ai): add apply-to-editor actions for assistant code suggestions#864

Open
Divyansh2992 wants to merge 1 commit intoaccordproject:mainfrom
Divyansh2992:feat/ai-apply-to-editor
Open

feat(ai): add apply-to-editor actions for assistant code suggestions#864
Divyansh2992 wants to merge 1 commit intoaccordproject:mainfrom
Divyansh2992:feat/ai-apply-to-editor

Conversation

@Divyansh2992
Copy link
Copy Markdown

Closes #853

Adds one-click apply actions for AI-generated editor replacements in the chat panel. When the assistant returns complete templatemarkApply, concertoApply, or jsonApply code blocks, users can apply them directly to the matching editor without copy-paste. The system prompt was also tightened so the assistant is more consistent about returning apply-ready code fences.

Changes

  • update the AI chat panel to detect templatemarkApply, concertoApply, and jsonApply fenced code blocks and render an Apply to Editor button beneath each supported block
  • wire apply actions to the existing editor store update flow so the matching editor is updated immediately and the preview rebuilds through the normal TemplateMark, Concerto, and JSON paths
  • strengthen the AI system prompt so full editor replacements are returned with exact *Apply code fence tags, including coordinated multi-editor responses when needed

Flags

  • manual verification completed by applying AI-generated TemplateMark, Concerto, and JSON suggestions from the chat panel and confirming editor and preview updates
  • no new automated tests were added in this change; linting passed and the production build completed successfully
  • success and error feedback is currently shown inline beneath the applied code block instead of through a toast notification

Screenshots

accord editor

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

Signed-off-by: Divyansh2992 <149261675+Divyansh2992@users.noreply.github.com>
@Divyansh2992 Divyansh2992 requested a review from a team as a code owner April 1, 2026 05:43
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

Deploy Preview for ap-template-playground ready!

Name Link
🔨 Latest commit 080a416
🔍 Latest deploy log https://app.netlify.com/projects/ap-template-playground/deploys/69ccb08af6e3900008e3f0e4
😎 Deploy Preview https://deploy-preview-864--ap-template-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions Bot added the Stale label Apr 17, 2026
@Divyansh2992
Copy link
Copy Markdown
Author

@sanketshevkar @DianaLease @dselman can you please review my this pr, as this has been reported to be stale by github bot. So can you please it asap.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements one-click “Apply to Editor” actions for AI assistant responses by detecting templatemarkApply, concertoApply, and jsonApply fenced code blocks in the chat UI, and tightens the system prompt so the assistant returns apply-ready blocks more consistently.

Changes:

  • Added apply-target detection and an “Apply to Editor” button for supported fenced code blocks in the AI chat panel.
  • Wired apply actions to the existing Zustand editor update + rebuild flow (TemplateMark / Concerto / JSON).
  • Strengthened system prompt instructions to require exact *Apply fence tags for full editor replacements.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/components/AIChatPanel.tsx Detects apply-ready code fences, renders Apply UI, and triggers editor updates + rebuilds.
src/ai-assistant/prompts.ts Adds shared prompt instructions enforcing exact templatemarkApply / concertoApply / jsonApply tags.

Comment on lines +225 to +231
const handleApplyToEditor = async (language: string, code: string, blockKey: string) => {
const applyTarget = getApplyTarget(language);

if (!applyTarget) {
return;
}

Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

This PR adds a new user-facing workflow (detect *Apply code fences, render an Apply button, update the correct editor, and rebuild). There are component tests in src/tests/components/, but no coverage for AIChatPanel. Please add unit tests for at least: (1) rendering the Apply button only for templatemarkApply/concertoApply/jsonApply blocks, and (2) clicking Apply calling the correct store setters and showing success/error feedback.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +232 to +236
setApplyingBlockKey(blockKey);
setApplyFeedback(null);

try {
await applyTarget.apply(code);
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

applyingBlockKey and applyFeedback are stored as single global values, but multiple Apply buttons can be clicked before an earlier apply finishes. This can cause a race where a later click overwrites applyingBlockKey, and then the earlier apply's finally clears it, leaving the UI in an incorrect state while the later apply is still running. Consider tracking applying/feedback state per block key (e.g., a map keyed by blockKey, or disable all Apply buttons while any apply is in progress).

Copilot uses AI. Check for mistakes.
code = segments[i].substring(firstLineBreak + 1);
}
const language = firstLineBreak > -1 ? segments[i].substring(0, firstLineBreak).trim() : "";
const code = (firstLineBreak > -1 ? segments[i].substring(firstLineBreak + 1) : segments[i]).trim();
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

The extracted code is .trim()'d before rendering and applying. Trimming can change the actual TemplateMark/Concerto content (e.g., removing leading indentation or trailing newlines) and may alter template output. Prefer preserving the exact code block contents (typically only strip the initial newline after the language tag, if present) when applying to the editors.

Suggested change
const code = (firstLineBreak > -1 ? segments[i].substring(firstLineBreak + 1) : segments[i]).trim();
const code = firstLineBreak > -1 ? segments[i].substring(firstLineBreak + 1) : segments[i];

Copilot uses AI. Check for mistakes.
const language = firstLineBreak > -1 ? segments[i].substring(0, firstLineBreak).trim() : "";
const code = (firstLineBreak > -1 ? segments[i].substring(firstLineBreak + 1) : segments[i]).trim();
const applyTarget = getApplyTarget(language);
const blockKey = `${messageId ?? "message"}:${i}:${language}:${code}`;
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

blockKey includes the entire code string, which can be very large. This increases memory usage and makes state comparisons (applyingBlockKey === blockKey) potentially expensive; it also risks unstable keys if whitespace changes. Use a stable, short identifier (e.g., ${messageId}:${i}:${language}) and, if needed, keep the code separately.

Suggested change
const blockKey = `${messageId ?? "message"}:${i}:${language}:${code}`;
const blockKey = `${messageId ?? "message"}:${i}:${language}`;

Copilot uses AI. Check for mistakes.
@mttrbrts
Copy link
Copy Markdown
Member

Thanks for this contribution! Before we can review, please resolve the merge conflicts with the base branch.

git fetch origin main
git rebase origin/main
# Resolve conflicts
git push --force-with-lease

Once the conflicts are resolved, we'll proceed with the review.


This comment was generated by AI on behalf of @mttrbrts.

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.

Add "Apply to Editor" button for AI code suggestions in chat panel

3 participants