( input: string, pastedContents: Record<number, PastedContent>, )
| 59 | } |
| 60 | |
| 61 | export function maybeTruncateInput( |
| 62 | input: string, |
| 63 | pastedContents: Record<number, PastedContent>, |
| 64 | ): { newInput: string; newPastedContents: Record<number, PastedContent> } { |
| 65 | // Get the next available ID for the truncated content |
| 66 | const existingIds = Object.keys(pastedContents).map(Number) |
| 67 | const nextPasteId = existingIds.length > 0 ? Math.max(...existingIds) + 1 : 1 |
| 68 | |
| 69 | // Apply truncation |
| 70 | const { truncatedText, placeholderContent } = maybeTruncateMessageForInput( |
| 71 | input, |
| 72 | nextPasteId, |
| 73 | ) |
| 74 | |
| 75 | if (!placeholderContent) { |
| 76 | return { newInput: input, newPastedContents: pastedContents } |
| 77 | } |
| 78 | |
| 79 | return { |
| 80 | newInput: truncatedText, |
| 81 | newPastedContents: { |
| 82 | ...pastedContents, |
| 83 | [nextPasteId]: { |
| 84 | id: nextPasteId, |
| 85 | type: 'text', |
| 86 | content: placeholderContent, |
| 87 | }, |
| 88 | }, |
| 89 | } |
| 90 | } |
| 91 |
no test coverage detected