-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(chat): preserve markdown when copying messages #6903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/sim/app/workspace/[workspaceId]/home/components/message-content/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| export { | ||
| assistantMessageHasRenderableContent, | ||
| getOrchestratorMessageText, | ||
| MessageContent, | ||
| } from './message-content' | ||
| export type { MessagePhase } from './utils' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...sim/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { toCopyableMarkdown } from '@/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown' | ||
|
|
||
| describe('toCopyableMarkdown', () => { | ||
| it('preserves message Markdown, including fenced code and its language', () => { | ||
| const message = [ | ||
| '# Elevator diagnosis', | ||
| '', | ||
| 'The bug is in `dispatch_legacy.py`:', | ||
| '', | ||
| '```python', | ||
| 'def next_stop(requests, current):', | ||
| ' ranked = sorted(requests)', | ||
| ' return ranked[1:]', | ||
| '```', | ||
| '', | ||
| '**Result:** the closest request *was not* always selected.', | ||
| ].join('\n') | ||
|
|
||
| expect(toCopyableMarkdown(message)).toBe(message) | ||
| }) | ||
|
|
||
| it('removes internal structured tags without flattening surrounding Markdown', () => { | ||
| const message = [ | ||
| 'Before **formatted text**.', | ||
| '<credential>{"type":"service_account","provider":"gmail"}</credential>', | ||
| 'After [a link](https://example.com).', | ||
| ].join('\n') | ||
|
|
||
| expect(toCopyableMarkdown(message)).toBe( | ||
| ['Before **formatted text**.', '', 'After [a link](https://example.com).'].join('\n') | ||
| ) | ||
| }) | ||
|
|
||
| it('preserves tag-shaped text that the chat renders literally', () => { | ||
| const message = [ | ||
| 'Document `<credential>example</credential>`.', | ||
| '', | ||
| '```html', | ||
| '<file>example</file>', | ||
| '<question>example</question>', | ||
| '```', | ||
| ].join('\n') | ||
|
|
||
| expect(toCopyableMarkdown(message)).toBe(message) | ||
| }) | ||
| }) |
13 changes: 13 additions & 0 deletions
13
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/copyable-markdown.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { sanitizeChatDisplayContent } from '@/app/workspace/[workspaceId]/home/components/message-content/components/chat-content/chat-sanitize' | ||
| import { parseSpecialTags } from '@/app/workspace/[workspaceId]/home/components/message-content/components/special-tags' | ||
|
|
||
| export function toCopyableMarkdown(raw: string): string { | ||
| const displayContent = sanitizeChatDisplayContent(raw) | ||
| const { segments } = parseSpecialTags(displayContent, false) | ||
|
|
||
| return segments | ||
| .reduce((markdown, segment) => { | ||
| return segment.type === 'text' ? markdown + segment.content : markdown | ||
| }, '') | ||
| .trim() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy button ignores prepared content
Medium Severity
hasCopyContentis derived from raw orchestrator text beforetoCopyableMarkdown, while the click path bails out when the prepared markdown is empty. The Copy control can therefore appear for content that only yields stripable tags or unresolved non-text segments, and a click writes nothing with no feedback.Additional Locations (1)
apps/sim/app/workspace/[workspaceId]/components/message-actions/message-actions.tsx#L68-L74Reviewed by Cursor Bugbot for commit 8696252. Configure here.