fix: preserve Markdown blocks when copying messages (#2944)

* fix: preserve Markdown blocks when copying messages

* fix: preserve blank lines when copying code

---------

Co-authored-by: Iuliia Ivashko <yulia.ivashko@gmail.com>
This commit is contained in:
ChangeHow
2026-08-27 19:37:49 +03:00
committed by GitHub
co-authored by Iuliia Ivashko
parent 2a1c10cb3e
commit 7aae5a6634
6 changed files with 277 additions and 41 deletions
+31 -2
View File
@@ -1,6 +1,7 @@
import type { Part } from '@opencode-ai/sdk/v2';
type TextLikePart = Part & { text?: string; content?: string };
type UserTextPart = Part & { text?: string; content?: string; shellAction?: { output?: unknown; command?: unknown } };
export const flattenAssistantTextParts = (parts: Part[]): string => {
const textParts = parts
@@ -8,8 +9,36 @@ export const flattenAssistantTextParts = (parts: Part[]): string => {
.map((part) => (part.text || part.content || '').trim())
.filter((text) => text.length > 0);
const combined = textParts.join('\n');
return combined.replace(/\n\s*\n+/g, '\n');
return textParts.join('\n\n');
};
export const flattenUserTextParts = (parts: Part[]): string => {
const textParts = parts.filter((part): part is UserTextPart => part?.type === 'text');
const shellOutputs = textParts
.map((part) => {
const output = part.shellAction?.output;
return typeof output === 'string' ? output.trim() : '';
})
.filter((output) => output.length > 0);
if (shellOutputs.length > 0) {
return shellOutputs.join('\n\n');
}
const shellCommands = textParts
.map((part) => {
const command = part.shellAction?.command;
return typeof command === 'string' ? command.trim() : '';
})
.filter((command) => command.length > 0);
if (shellCommands.length > 0) {
return shellCommands.join('\n');
}
const plainTexts = textParts
.map((part) => (part.text || part.content || '').trim())
.filter((text) => text.length > 0);
return plainTexts.join('\n\n');
};
export const suggestPlanTitleFromText = (text: string): string => {