( input: string, pastedContents: Record<number, PastedContent>, )
| 79 | * Image refs are left alone — they become content blocks, not inlined text. |
| 80 | */ |
| 81 | export function expandPastedTextRefs( |
| 82 | input: string, |
| 83 | pastedContents: Record<number, PastedContent>, |
| 84 | ): string { |
| 85 | const refs = parseReferences(input) |
| 86 | let expanded = input |
| 87 | // Splice at the original match offsets so placeholder-like strings inside |
| 88 | // pasted content are never confused for real refs. Reverse order keeps |
| 89 | // earlier offsets valid after later replacements. |
| 90 | for (let i = refs.length - 1; i >= 0; i--) { |
| 91 | const ref = refs[i]! |
| 92 | const content = pastedContents[ref.id] |
| 93 | if (content?.type !== 'text') continue |
| 94 | expanded = |
| 95 | expanded.slice(0, ref.index) + |
| 96 | content.content + |
| 97 | expanded.slice(ref.index + ref.match.length) |
| 98 | } |
| 99 | return expanded |
| 100 | } |
| 101 | |
| 102 | function deserializeLogEntry(line: string): LogEntry { |
| 103 | return jsonParse(line) as LogEntry |
no test coverage detected