@mastra/client-js 1.0.0-beta.15 → 1.0.0-beta.16
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +67 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -1
- package/dist/resources/run.d.ts +65 -0
- package/dist/resources/run.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2723,12 +2723,79 @@ var Run = class extends BaseResource {
|
|
|
2723
2723
|
/**
|
|
2724
2724
|
* Cancels a specific workflow run by its ID
|
|
2725
2725
|
* @returns Promise containing a success message
|
|
2726
|
+
* @deprecated Use `cancel()` instead
|
|
2726
2727
|
*/
|
|
2727
2728
|
cancelRun() {
|
|
2728
2729
|
return this.request(`/api/workflows/${this.workflowId}/runs/${this.runId}/cancel`, {
|
|
2729
2730
|
method: "POST"
|
|
2730
2731
|
});
|
|
2731
2732
|
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Cancels a workflow run.
|
|
2735
|
+
*
|
|
2736
|
+
* This method aborts any running steps and updates the workflow status to 'canceled' .
|
|
2737
|
+
* It works for both actively running workflows and suspended/waiting workflows.
|
|
2738
|
+
*
|
|
2739
|
+
* ## How cancellation works
|
|
2740
|
+
*
|
|
2741
|
+
* When called, the workflow will:
|
|
2742
|
+
* 1. **Trigger the abort signal** - Uses the standard Web API AbortSignal to notify running steps
|
|
2743
|
+
* 2. **Prevent subsequent steps** - No further steps will be executed
|
|
2744
|
+
*
|
|
2745
|
+
* ## Abort signal behavior
|
|
2746
|
+
*
|
|
2747
|
+
* Steps that check the `abortSignal` parameter can respond to cancellation:
|
|
2748
|
+
* - Steps can listen to the 'abort' event: `abortSignal.addEventListener('abort', callback)`
|
|
2749
|
+
* - Steps can check if already aborted: `if (abortSignal.aborted) { ... }`
|
|
2750
|
+
* - Useful for canceling timeouts, network requests, or long-running operations
|
|
2751
|
+
*
|
|
2752
|
+
* **Note:** Steps must actively check the abort signal to be canceled mid-execution.
|
|
2753
|
+
* Steps that don't check the signal will run to completion, but subsequent steps won't execute.
|
|
2754
|
+
*
|
|
2755
|
+
* @returns Promise that resolves with `{ message: 'Workflow run canceled' }` when cancellation succeeds
|
|
2756
|
+
* @throws {HTTPException} 400 - If workflow ID or run ID is missing
|
|
2757
|
+
* @throws {HTTPException} 404 - If workflow or workflow run is not found
|
|
2758
|
+
*
|
|
2759
|
+
* @example
|
|
2760
|
+
* ```typescript
|
|
2761
|
+
* const run = await workflow.createRun({ runId: 'run-123' });
|
|
2762
|
+
* await run.cancel();
|
|
2763
|
+
* // Returns: { message: 'Workflow run canceled' }
|
|
2764
|
+
* ```
|
|
2765
|
+
*
|
|
2766
|
+
* @example
|
|
2767
|
+
* ```typescript
|
|
2768
|
+
* // Example of a step that responds to cancellation
|
|
2769
|
+
* const step = createStep({
|
|
2770
|
+
* id: 'long-running-step',
|
|
2771
|
+
* execute: async ({ inputData, abortSignal, abort }) => {
|
|
2772
|
+
* const timeout = new Promise((resolve) => {
|
|
2773
|
+
* const timer = setTimeout(() => resolve('done'), 10000);
|
|
2774
|
+
*
|
|
2775
|
+
* // Clean up if canceled
|
|
2776
|
+
* abortSignal.addEventListener('abort', () => {
|
|
2777
|
+
* clearTimeout(timer);
|
|
2778
|
+
* resolve('canceled');
|
|
2779
|
+
* });
|
|
2780
|
+
* });
|
|
2781
|
+
*
|
|
2782
|
+
* const result = await timeout;
|
|
2783
|
+
*
|
|
2784
|
+
* // Check if aborted after async operation
|
|
2785
|
+
* if (abortSignal.aborted) {
|
|
2786
|
+
* return abort(); // Stop execution
|
|
2787
|
+
* }
|
|
2788
|
+
*
|
|
2789
|
+
* return { result };
|
|
2790
|
+
* }
|
|
2791
|
+
* });
|
|
2792
|
+
* ```
|
|
2793
|
+
*/
|
|
2794
|
+
cancel() {
|
|
2795
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${this.runId}/cancel`, {
|
|
2796
|
+
method: "POST"
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2732
2799
|
/**
|
|
2733
2800
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
2734
2801
|
* @param params - Object containing the inputData, initialState and requestContext
|