(response: StreamResponse)
| 115 | const validator = new LanguageValidator(language); |
| 116 | |
| 117 | const processResponse = (response: StreamResponse) => { |
| 118 | const pattern = get(selectedPatternName); |
| 119 | |
| 120 | if (pattern) { |
| 121 | // Do NOT call cleanPatternOutput here - it runs on each streaming token |
| 122 | // and .trim() strips leading spaces that serve as word separators. |
| 123 | // Cleaning should be done on the final accumulated content at display time. |
| 124 | |
| 125 | // Simplified format determination - always markdown unless mermaid |
| 126 | const isMermaid = [ |
| 127 | "graph TD", |
| 128 | "gantt", |
| 129 | "flowchart", |
| 130 | "sequenceDiagram", |
| 131 | "classDiagram", |
| 132 | "stateDiagram", |
| 133 | ].some((starter) => response.content.trim().startsWith(starter)); |
| 134 | |
| 135 | response.format = isMermaid ? "mermaid" : "markdown"; |
| 136 | } |
| 137 | |
| 138 | if (response.type === "content") { |
| 139 | response.content = validator.enforceLanguage(response.content); |
| 140 | } |
| 141 | |
| 142 | return response; |
| 143 | }; |
| 144 | return new ReadableStream({ |
| 145 | async start(controller) { |
| 146 | try { |
nothing calls this directly
no test coverage detected