* Drain to the final text (the `done` frame's text, else accumulated event * deltas). Throws AgentStreamError on an error outcome.
()
| 158 | * deltas). Throws {@link AgentStreamError} on an error outcome. |
| 159 | */ |
| 160 | async collect(): Promise<string> { |
| 161 | let text = ""; |
| 162 | for await (const f of this) { |
| 163 | if (f.type === "event") { |
| 164 | const p = f.payload as { delta?: string; text?: string } | undefined; |
| 165 | text += p?.delta ?? p?.text ?? ""; |
| 166 | } else if (f.type === "done") { |
| 167 | return f.text || text; |
| 168 | } |
| 169 | } |
| 170 | return text; |
| 171 | } |
| 172 | } |