| 188 | // =========================================================================== |
| 189 | |
| 190 | override async fetch(request: Request): Promise<Response> { |
| 191 | const url = new URL(request.url) |
| 192 | const parts = url.pathname.split('/').filter(Boolean) |
| 193 | |
| 194 | if (parts[0] === 'runs' && typeof parts[1] === 'string') { |
| 195 | if (parts[2] === 'stream') return this.acceptStream(parts[1], request) |
| 196 | if (parts.length === 2 && request.method === 'GET') { |
| 197 | const record = await this.status(parts[1]) |
| 198 | return record |
| 199 | ? this.jsonResponse(record) |
| 200 | : this.jsonResponse({ error: 'unknown run' }, 404) |
| 201 | } |
| 202 | } |
| 203 | return this.handleRoute(request, parts) |
| 204 | } |
| 205 | |
| 206 | // =========================================================================== |
| 207 | // WebSocket streaming with hibernation + resumable cursor |