()
| 248 | |
| 249 | // ── 4. Run lifecycle: finalise streams ───────────────────────────── |
| 250 | async onRunFinishedEvent() { |
| 251 | if (aborted) return; |
| 252 | const tasks: Promise<void>[] = []; |
| 253 | for (const [id, stream] of Array.from(streams.entries())) { |
| 254 | // Best-effort: a terminal-edit rejection (message too old, deleted, |
| 255 | // not-modified, flood-wait) must not bubble into the AG-UI run loop. |
| 256 | tasks.push( |
| 257 | stream |
| 258 | .finish() |
| 259 | .catch((e) => |
| 260 | console.error("[bot-telegram] stream finalize failed:", e), |
| 261 | ), |
| 262 | ); |
| 263 | streams.delete(id); |
| 264 | finalised.add(id); |
| 265 | } |
| 266 | buffers.clear(); |
| 267 | await Promise.all(tasks); |
| 268 | // Drain any tool-status placeholders left over from a tool call whose |
| 269 | // END never arrived before the run finished — flip them to done so they |
| 270 | // aren't orphaned as a perpetual "🔧 using <tool>…". |
| 271 | await drainToolStatuses((tool) => `✅ ${tool}`); |
| 272 | }, |
| 273 | |
| 274 | // ── 5. Errors ───────────────────────────────────────────────────── |
| 275 | async onRunErrorEvent({ event }) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…