| 1 |
/** |
| 2 |
* Content Normalizer |
| 3 |
* |
| 4 |
* Normalizes message content into a uniform block structure. |
| 5 |
* Supports string (legacy) and array (structured) content formats. |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Normalize content into an array of typed blocks. |
| 10 |
* @param {string|Array} content - Message content (string or block array) |
| 11 |
* @returns {Array<{type: string, text?: string, componentType?: string, props?: Object}>} |
| 12 |
*/ |
| 13 |
export const normalizeContent = (content) => { |
| 14 |
if (!content) return []; |
| 15 |
|
| 16 |
// Already structured — return as-is |
| 17 |
if (Array.isArray(content)) return content; |
| 18 |
|
| 19 |
// Legacy string format → single text block |
| 20 |
return [{ type: 'text', text: content }]; |
| 21 |
}; |
| 22 |
|
| 23 |
/** |
| 24 |
* Extract plain text from content for copy/clipboard. |
| 25 |
* @param {string|Array} content - Message content (string or block array) |
| 26 |
* @returns {string} |
| 27 |
*/ |
| 28 |
export const getTextContent = (content) => { |
| 29 |
if (!content) return ''; |
| 30 |
|
| 31 |
if (typeof content === 'string') return content; |
| 32 |
|
| 33 |
if (Array.isArray(content)) { |
| 34 |
return content |
| 35 |
.filter((block) => block.type === 'text') |
| 36 |
.map((block) => block.text) |
| 37 |
.join('\n\n'); |
| 38 |
} |
| 39 |
|
| 40 |
return ''; |
| 41 |
}; |
| 42 |
|