Files
openchamber/packages/ui/src/lib/messages/messageText.ts
T

14 lines
488 B
TypeScript
Raw Normal View History

2026-01-03 13:39:59 +02:00
import type { Part } from '@opencode-ai/sdk/v2';
type TextLikePart = Part & { text?: string; content?: string };
export const flattenAssistantTextParts = (parts: Part[]): string => {
const textParts = parts
.filter((part): part is TextLikePart => part?.type === 'text')
.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');
};