| 137 | }, |
| 138 | |
| 139 | async abort(requestId: string): Promise<{ success: boolean; error?: string }> { |
| 140 | const entry = requestIdMap.get(requestId) |
| 141 | if (!entry) return { success: false, error: 'Request not found' } |
| 142 | |
| 143 | entry.abortController.abort() |
| 144 | |
| 145 | if (entry.serverId) { |
| 146 | try { |
| 147 | const { post } = await import('../utils/http') |
| 148 | await post<{ success: boolean }>('/ai/agent/abort', { requestId: entry.serverId }) |
| 149 | } catch { |
| 150 | // server-side abort is best-effort; client already aborted the fetch |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | requestIdMap.delete(requestId) |
| 155 | return { success: true } |
| 156 | }, |
| 157 | } |
| 158 | } |