| 1 | const COMPLETE_BLOCK_RE = /<memory-compiler-execution>[\s\S]*?<\/memory-compiler-execution>\s*/g; |
| 2 | const DANGLING_BLOCK_RE = /<memory-compiler-execution>[\s\S]*$/; |
| 3 | |
| 4 | /** |
| 5 | * Removes the legacy Memory v5 `<memory-compiler-execution>` contract block from |
| 6 | * a user turn before it is rendered in the transcript. |
| 7 | * |
| 8 | * The Memory v5 compiler was removed, but transcripts recorded by releases up to |
| 9 | * v1.17.x can still carry injected contracts: the block was model-internal |
| 10 | * planning metadata that REPLACED the user turn, and the backend unwraps it to |
| 11 | * the original prompt (`source_event`) for display. This is the display-boundary |
| 12 | * safety net for those old sessions: a corrupted/accreted contract from the |
| 13 | * pre-fix goal loop (#5342) could otherwise surface as raw JSON "乱码" after |
| 14 | * switching between conversations (#5361). Complete blocks are removed, then any |
| 15 | * dangling (unclosed/truncated) block is cut from its opening tag onward so raw |
| 16 | * contract JSON is never shown. |
| 17 | */ |
| 18 | export function stripMemoryCompilerExecution(text: string): string { |
| 19 | return text.replace(COMPLETE_BLOCK_RE, "").replace(DANGLING_BLOCK_RE, "").trimStart(); |
| 20 | } |
| 21 |