From 9823761e03c0fb9b70268050526f303d6aa21ca6 Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Thu, 7 May 2026 12:11:01 +0200 Subject: [PATCH] Implement stream cancellation in OllamaClient Add `cancelStream` method to allow aborting active requests. Store the current `AbortController` on the client instance and reset it when the stream completes or is cancelled. Update `ChatView` to call `cancelStream` on close. Add comprehensive tests for stream cancellation scenarios, including aborting active requests, handling cancellation when no stream is active, clearing the controller after normal completion, and allowing new streams after cancellation. --- .gitignore | 1 + coverage/lcov-report/chat-view.ts.html | 14 +- coverage/lcov-report/error-handler.ts.html | 2 +- coverage/lcov-report/index.html | 42 +-- coverage/lcov-report/ollama-client.ts.html | 153 ++++---- coverage/lcov-report/tool-executor.ts.html | 2 +- coverage/lcov-report/types.ts.html | 2 +- coverage/lcov-report/utils.ts.html | 2 +- coverage/lcov-report/vault-indexer.ts.html | 2 +- coverage/lcov.info | 400 +++++++++++---------- src/chat-view.js | 2 +- src/chat-view.ts | 2 +- src/ollama-client.js | 10 + src/ollama-client.ts | 11 + tests/ollama-client.test.ts | 146 +++++++- 15 files changed, 495 insertions(+), 296 deletions(-) diff --git a/.gitignore b/.gitignore index 7f1a909..eca2080 100755 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ lib/ dist/ out/ build/ +coverage/ # IDE files .idea/ diff --git a/coverage/lcov-report/chat-view.ts.html b/coverage/lcov-report/chat-view.ts.html index 1ad901d..af9ceaa 100644 --- a/coverage/lcov-report/chat-view.ts.html +++ b/coverage/lcov-report/chat-view.ts.html @@ -23,9 +23,9 @@
- 92.52% + 92.55% Statements - 198/214 + 199/215
@@ -44,9 +44,9 @@
- 94.5% + 94.52% Lines - 189/200 + 190/201
@@ -628,7 +628,7 @@       -  +3x 3x 3x 3x @@ -1105,7 +1105,7 @@ export class ChatView extends ItemView { }   onClose(): Promise<void> { - // Removed cancelStream call as we now use local controllers + this.ollamaClient.cancelStream(); this.removeEventListeners(); this.cleanupStreamingResources(); this.lastMessageEl = null; @@ -1501,7 +1501,7 @@ export class ChatView extends ItemView {