cascade-ai 0.2.1 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -84,6 +84,7 @@ User prompt
84
84
  - **Provider failover** — auto-switches provider on rate limits (exponential backoff); automatically re-enables recovered providers on success
85
85
  - **Context auto-summarization** — compresses history when the context window fills
86
86
  - **Conversation branching** — fork a session to try parallel approaches
87
+ - **Task cancellation** — pass an `AbortSignal` to stop any run mid-flight; all tiers halt at the next safe checkpoint and emit `run:cancelled` with partial output
87
88
 
88
89
  ### AI Providers
89
90
  - Anthropic (Claude Opus 4, Sonnet 4, Haiku 3.5)
@@ -421,6 +422,38 @@ const result = await cascade.run({
421
422
  });
422
423
  ```
423
424
 
425
+ ### Cancellation
426
+
427
+ Pass an `AbortSignal` to stop a run mid-execution. All active tiers (T1 → T2 → T3) halt at the next safe checkpoint, preventing further token spend. The `run()` call resolves with whatever partial output has been produced so far.
428
+
429
+ ```typescript
430
+ import { createCascade, CascadeCancelledError } from 'cascade-ai';
431
+
432
+ const cascade = createCascade({ /* config */ });
433
+ await cascade.init();
434
+
435
+ const controller = new AbortController();
436
+
437
+ // Listen for the cancellation event
438
+ cascade.on('run:cancelled', ({ taskId, reason, partialOutput }) => {
439
+ console.log(`Task ${taskId} cancelled: ${reason}`);
440
+ console.log('Partial output so far:', partialOutput);
441
+ });
442
+
443
+ // Start the run (non-blocking)
444
+ const runPromise = cascade.run({
445
+ prompt: 'Perform a deep codebase audit',
446
+ signal: controller.signal,
447
+ });
448
+
449
+ // Cancel after 10 seconds (e.g. user pressed Ctrl-C)
450
+ setTimeout(() => controller.abort('User requested stop'), 10_000);
451
+
452
+ const result = await runPromise; // resolves gracefully, not rejected
453
+ ```
454
+
455
+ **How it propagates:** The signal is threaded through `T1Administrator → T2Manager → T3Worker`. Each tier checks for cancellation before every LLM call so the run stops as soon as the current in-flight request completes — no mid-stream interruptions.
456
+
424
457
  ---
425
458
 
426
459
  ## MCP Support