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:
committed by
GitHub
co-authored by
Iuliia Ivashko
parent
2a1c10cb3e
commit
7aae5a6634
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user