@mastra/client-js 0.1.9-alpha.1 → 0.1.9

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @mastra/client-js@0.1.9-alpha.1 build /home/runner/work/mastra/mastra/client-sdks/client-js
2
+ > @mastra/client-js@0.1.9-alpha.2 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
3
  > tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,11 +9,11 @@
9
9
  CLI Cleaning output folder
10
10
  ESM Build start
11
11
  CJS Build start
12
- CJS dist/index.cjs 16.09 KB
13
- CJS ⚡️ Build success in 847ms
14
- ESM dist/index.js 16.00 KB
15
- ESM ⚡️ Build success in 848ms
12
+ ESM dist/index.js 17.49 KB
13
+ ESM ⚡️ Build success in 847ms
14
+ CJS dist/index.cjs 17.58 KB
15
+ CJS ⚡️ Build success in 848ms
16
16
  DTS Build start
17
- DTS ⚡️ Build success in 10169ms
18
- DTS dist/index.d.ts 14.79 KB
19
- DTS dist/index.d.cts 14.79 KB
17
+ DTS ⚡️ Build success in 11271ms
18
+ DTS dist/index.d.ts 16.15 KB
19
+ DTS dist/index.d.cts 16.15 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 0.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 0850b4c: Watch and resume per run
8
+ - 4356859: Bump types from core so it can pass instructions optionally
9
+ - Updated dependencies [fc2f89c]
10
+ - Updated dependencies [dfbb131]
11
+ - Updated dependencies [f4854ee]
12
+ - Updated dependencies [afaf73f]
13
+ - Updated dependencies [0850b4c]
14
+ - Updated dependencies [7bcfaee]
15
+ - Updated dependencies [44631b1]
16
+ - Updated dependencies [9116d70]
17
+ - Updated dependencies [6e559a0]
18
+ - Updated dependencies [5f43505]
19
+ - @mastra/core@0.6.1
20
+
21
+ ## 0.1.9-alpha.2
22
+
23
+ ### Patch Changes
24
+
25
+ - 0850b4c: Watch and resume per run
26
+ - Updated dependencies [fc2f89c]
27
+ - Updated dependencies [dfbb131]
28
+ - Updated dependencies [0850b4c]
29
+ - Updated dependencies [9116d70]
30
+ - @mastra/core@0.6.1-alpha.2
31
+
3
32
  ## 0.1.9-alpha.1
4
33
 
5
34
  ### Patch Changes
package/README.md CHANGED
@@ -79,10 +79,12 @@ const client = new MastraClient({
79
79
  - `getWorkflows()`: Get all workflows
80
80
  - `getWorkflow(workflowId)`: Get a workflow instance
81
81
  - `workflow.details()`: Get workflow details
82
- - `workflow.execute(params)`: Execute the workflow and wait for execution results
83
- - `workflow.startRun()`: Start a new workflow run
84
- - `workflow.watch(params)`: Watch the workflow run
85
- - `workflow.resume(params)`: Resume the workflow run
82
+ - `workflow.createRun()`: Create workflow run
83
+ - `workflow.startAsync(params)`: Execute the workflow and wait for execution results
84
+ - `workflow.resumeAsync(parmas)`: Resume suspended workflow step async
85
+ - `workflow.watch({runId},(record)=>{})`: Watch the step transitions of the workflow run
86
+ - `workflow.start({runId, triggerData})`: Start a workflow run sync
87
+ - `workflow.resume(params)`: Resume the workflow run sync
86
88
 
87
89
  ### Vectors
88
90
 
package/dist/index.cjs CHANGED
@@ -267,18 +267,31 @@ var Workflow = class extends BaseResource {
267
267
  });
268
268
  }
269
269
  /**
270
- * Creates a new workflow run instance and starts it
271
- * @param params - Parameters required for the workflow run
270
+ * Creates a new workflow run
272
271
  * @returns Promise containing the generated run ID
273
272
  */
274
- startRun(params) {
275
- return this.request(`/api/workflows/${this.workflowId}/startRun`, {
273
+ createRun(params) {
274
+ const searchParams = new URLSearchParams();
275
+ if (!!params?.runId) {
276
+ searchParams.set("runId", params.runId);
277
+ }
278
+ return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
279
+ method: "POST"
280
+ });
281
+ }
282
+ /**
283
+ * Starts a workflow run synchronously without waiting for the workflow to complete
284
+ * @param params - Object containing the runId and triggerData
285
+ * @returns Promise containing success message
286
+ */
287
+ start(params) {
288
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
276
289
  method: "POST",
277
- body: params
290
+ body: params?.triggerData
278
291
  });
279
292
  }
280
293
  /**
281
- * Resumes a suspended workflow step
294
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
282
295
  * @param stepId - ID of the step to resume
283
296
  * @param runId - ID of the workflow run
284
297
  * @param context - Context to resume the workflow with
@@ -297,6 +310,31 @@ var Workflow = class extends BaseResource {
297
310
  }
298
311
  });
299
312
  }
313
+ /**
314
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
315
+ * @param params - Object containing the runId and triggerData
316
+ * @returns Promise containing the workflow execution results
317
+ */
318
+ startAsync(params) {
319
+ return this.request(`/api/workflows/${this.workflowId}/startAsync?runId=${params.runId}`, {
320
+ method: "POST",
321
+ body: params?.triggerData
322
+ });
323
+ }
324
+ /**
325
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
326
+ * @param params - Object containing the runId, stepId, and context
327
+ * @returns Promise containing the workflow resume results
328
+ */
329
+ resumeAsync(params) {
330
+ return this.request(`/api/workflows/${this.workflowId}/resumeAsync?runId=${params.runId}`, {
331
+ method: "POST",
332
+ body: {
333
+ stepId: params.stepId,
334
+ context: params.context
335
+ }
336
+ });
337
+ }
300
338
  /**
301
339
  * Creates an async generator that processes a readable stream and yields records
302
340
  * separated by the Record Separator character (\x1E)
@@ -329,7 +367,7 @@ var Workflow = class extends BaseResource {
329
367
  try {
330
368
  const parsedRecord = JSON.parse(record);
331
369
  const isWorkflowCompleted = parsedRecord?.activePaths?.every(
332
- (path) => path.status === "completed" || path.status === "suspended" || path.status === "failed"
370
+ (path) => path.status === "completed" || path.status === "suspended" || path.status === "failed" || path.status === "skipped"
333
371
  );
334
372
  if (isWorkflowCompleted) {
335
373
  reader.cancel();
@@ -350,7 +388,7 @@ var Workflow = class extends BaseResource {
350
388
  * @param runId - Optional run ID to filter the watch stream
351
389
  * @returns AsyncGenerator that yields parsed records from the workflow watch stream
352
390
  */
353
- async *watch({ runId }) {
391
+ async watch({ runId }, onRecord) {
354
392
  const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
355
393
  stream: true
356
394
  });
@@ -360,7 +398,9 @@ var Workflow = class extends BaseResource {
360
398
  if (!response.body) {
361
399
  throw new Error("Response body is null");
362
400
  }
363
- yield* this.streamProcessor(response.body);
401
+ for await (const record of this.streamProcessor(response.body)) {
402
+ onRecord(record);
403
+ }
364
404
  }
365
405
  };
366
406
 
package/dist/index.d.cts CHANGED
@@ -20,6 +20,7 @@ interface RequestOptions {
20
20
  headers?: Record<string, string>;
21
21
  body?: any;
22
22
  stream?: boolean;
23
+ signal?: AbortSignal;
23
24
  }
24
25
  interface GetAgentResponse {
25
26
  name: string;
@@ -58,7 +59,15 @@ type WorkflowRunResult = {
58
59
  }>;
59
60
  context: {
60
61
  steps: Record<string, {
61
- status: 'completed' | 'suspended' | 'running';
62
+ status: 'success';
63
+ output: any;
64
+ [key: string]: any;
65
+ } | {
66
+ status: 'pending';
67
+ [key: string]: any;
68
+ } | {
69
+ status: 'suspended';
70
+ suspendPayload: any;
62
71
  [key: string]: any;
63
72
  }>;
64
73
  };
@@ -279,15 +288,27 @@ declare class Workflow extends BaseResource {
279
288
  */
280
289
  execute(params: Record<string, any>): Promise<WorkflowRunResult>;
281
290
  /**
282
- * Creates a new workflow run instance and starts it
283
- * @param params - Parameters required for the workflow run
291
+ * Creates a new workflow run
284
292
  * @returns Promise containing the generated run ID
285
293
  */
286
- startRun(params: Record<string, any>): Promise<{
294
+ createRun(params?: {
295
+ runId?: string;
296
+ }): Promise<{
287
297
  runId: string;
288
298
  }>;
289
299
  /**
290
- * Resumes a suspended workflow step
300
+ * Starts a workflow run synchronously without waiting for the workflow to complete
301
+ * @param params - Object containing the runId and triggerData
302
+ * @returns Promise containing success message
303
+ */
304
+ start(params: {
305
+ runId: string;
306
+ triggerData: Record<string, any>;
307
+ }): Promise<{
308
+ message: string;
309
+ }>;
310
+ /**
311
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
291
312
  * @param stepId - ID of the step to resume
292
313
  * @param runId - ID of the workflow run
293
314
  * @param context - Context to resume the workflow with
@@ -297,7 +318,28 @@ declare class Workflow extends BaseResource {
297
318
  stepId: string;
298
319
  runId: string;
299
320
  context: Record<string, any>;
300
- }): Promise<Record<string, any>>;
321
+ }): Promise<{
322
+ message: string;
323
+ }>;
324
+ /**
325
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
326
+ * @param params - Object containing the runId and triggerData
327
+ * @returns Promise containing the workflow execution results
328
+ */
329
+ startAsync(params: {
330
+ runId: string;
331
+ triggerData: Record<string, any>;
332
+ }): Promise<WorkflowRunResult>;
333
+ /**
334
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
335
+ * @param params - Object containing the runId, stepId, and context
336
+ * @returns Promise containing the workflow resume results
337
+ */
338
+ resumeAsync(params: {
339
+ runId: string;
340
+ stepId: string;
341
+ context: Record<string, any>;
342
+ }): Promise<WorkflowRunResult>;
301
343
  /**
302
344
  * Creates an async generator that processes a readable stream and yields records
303
345
  * separated by the Record Separator character (\x1E)
@@ -313,7 +355,7 @@ declare class Workflow extends BaseResource {
313
355
  */
314
356
  watch({ runId }: {
315
357
  runId?: string;
316
- }): AsyncGenerator<WorkflowRunResult, void, unknown>;
358
+ }, onRecord: (record: WorkflowRunResult) => void): Promise<void>;
317
359
  }
318
360
 
319
361
  declare class Tool extends BaseResource {
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ interface RequestOptions {
20
20
  headers?: Record<string, string>;
21
21
  body?: any;
22
22
  stream?: boolean;
23
+ signal?: AbortSignal;
23
24
  }
24
25
  interface GetAgentResponse {
25
26
  name: string;
@@ -58,7 +59,15 @@ type WorkflowRunResult = {
58
59
  }>;
59
60
  context: {
60
61
  steps: Record<string, {
61
- status: 'completed' | 'suspended' | 'running';
62
+ status: 'success';
63
+ output: any;
64
+ [key: string]: any;
65
+ } | {
66
+ status: 'pending';
67
+ [key: string]: any;
68
+ } | {
69
+ status: 'suspended';
70
+ suspendPayload: any;
62
71
  [key: string]: any;
63
72
  }>;
64
73
  };
@@ -279,15 +288,27 @@ declare class Workflow extends BaseResource {
279
288
  */
280
289
  execute(params: Record<string, any>): Promise<WorkflowRunResult>;
281
290
  /**
282
- * Creates a new workflow run instance and starts it
283
- * @param params - Parameters required for the workflow run
291
+ * Creates a new workflow run
284
292
  * @returns Promise containing the generated run ID
285
293
  */
286
- startRun(params: Record<string, any>): Promise<{
294
+ createRun(params?: {
295
+ runId?: string;
296
+ }): Promise<{
287
297
  runId: string;
288
298
  }>;
289
299
  /**
290
- * Resumes a suspended workflow step
300
+ * Starts a workflow run synchronously without waiting for the workflow to complete
301
+ * @param params - Object containing the runId and triggerData
302
+ * @returns Promise containing success message
303
+ */
304
+ start(params: {
305
+ runId: string;
306
+ triggerData: Record<string, any>;
307
+ }): Promise<{
308
+ message: string;
309
+ }>;
310
+ /**
311
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
291
312
  * @param stepId - ID of the step to resume
292
313
  * @param runId - ID of the workflow run
293
314
  * @param context - Context to resume the workflow with
@@ -297,7 +318,28 @@ declare class Workflow extends BaseResource {
297
318
  stepId: string;
298
319
  runId: string;
299
320
  context: Record<string, any>;
300
- }): Promise<Record<string, any>>;
321
+ }): Promise<{
322
+ message: string;
323
+ }>;
324
+ /**
325
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
326
+ * @param params - Object containing the runId and triggerData
327
+ * @returns Promise containing the workflow execution results
328
+ */
329
+ startAsync(params: {
330
+ runId: string;
331
+ triggerData: Record<string, any>;
332
+ }): Promise<WorkflowRunResult>;
333
+ /**
334
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
335
+ * @param params - Object containing the runId, stepId, and context
336
+ * @returns Promise containing the workflow resume results
337
+ */
338
+ resumeAsync(params: {
339
+ runId: string;
340
+ stepId: string;
341
+ context: Record<string, any>;
342
+ }): Promise<WorkflowRunResult>;
301
343
  /**
302
344
  * Creates an async generator that processes a readable stream and yields records
303
345
  * separated by the Record Separator character (\x1E)
@@ -313,7 +355,7 @@ declare class Workflow extends BaseResource {
313
355
  */
314
356
  watch({ runId }: {
315
357
  runId?: string;
316
- }): AsyncGenerator<WorkflowRunResult, void, unknown>;
358
+ }, onRecord: (record: WorkflowRunResult) => void): Promise<void>;
317
359
  }
318
360
 
319
361
  declare class Tool extends BaseResource {
package/dist/index.js CHANGED
@@ -265,18 +265,31 @@ var Workflow = class extends BaseResource {
265
265
  });
266
266
  }
267
267
  /**
268
- * Creates a new workflow run instance and starts it
269
- * @param params - Parameters required for the workflow run
268
+ * Creates a new workflow run
270
269
  * @returns Promise containing the generated run ID
271
270
  */
272
- startRun(params) {
273
- return this.request(`/api/workflows/${this.workflowId}/startRun`, {
271
+ createRun(params) {
272
+ const searchParams = new URLSearchParams();
273
+ if (!!params?.runId) {
274
+ searchParams.set("runId", params.runId);
275
+ }
276
+ return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
277
+ method: "POST"
278
+ });
279
+ }
280
+ /**
281
+ * Starts a workflow run synchronously without waiting for the workflow to complete
282
+ * @param params - Object containing the runId and triggerData
283
+ * @returns Promise containing success message
284
+ */
285
+ start(params) {
286
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
274
287
  method: "POST",
275
- body: params
288
+ body: params?.triggerData
276
289
  });
277
290
  }
278
291
  /**
279
- * Resumes a suspended workflow step
292
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
280
293
  * @param stepId - ID of the step to resume
281
294
  * @param runId - ID of the workflow run
282
295
  * @param context - Context to resume the workflow with
@@ -295,6 +308,31 @@ var Workflow = class extends BaseResource {
295
308
  }
296
309
  });
297
310
  }
311
+ /**
312
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
313
+ * @param params - Object containing the runId and triggerData
314
+ * @returns Promise containing the workflow execution results
315
+ */
316
+ startAsync(params) {
317
+ return this.request(`/api/workflows/${this.workflowId}/startAsync?runId=${params.runId}`, {
318
+ method: "POST",
319
+ body: params?.triggerData
320
+ });
321
+ }
322
+ /**
323
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
324
+ * @param params - Object containing the runId, stepId, and context
325
+ * @returns Promise containing the workflow resume results
326
+ */
327
+ resumeAsync(params) {
328
+ return this.request(`/api/workflows/${this.workflowId}/resumeAsync?runId=${params.runId}`, {
329
+ method: "POST",
330
+ body: {
331
+ stepId: params.stepId,
332
+ context: params.context
333
+ }
334
+ });
335
+ }
298
336
  /**
299
337
  * Creates an async generator that processes a readable stream and yields records
300
338
  * separated by the Record Separator character (\x1E)
@@ -327,7 +365,7 @@ var Workflow = class extends BaseResource {
327
365
  try {
328
366
  const parsedRecord = JSON.parse(record);
329
367
  const isWorkflowCompleted = parsedRecord?.activePaths?.every(
330
- (path) => path.status === "completed" || path.status === "suspended" || path.status === "failed"
368
+ (path) => path.status === "completed" || path.status === "suspended" || path.status === "failed" || path.status === "skipped"
331
369
  );
332
370
  if (isWorkflowCompleted) {
333
371
  reader.cancel();
@@ -348,7 +386,7 @@ var Workflow = class extends BaseResource {
348
386
  * @param runId - Optional run ID to filter the watch stream
349
387
  * @returns AsyncGenerator that yields parsed records from the workflow watch stream
350
388
  */
351
- async *watch({ runId }) {
389
+ async watch({ runId }, onRecord) {
352
390
  const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
353
391
  stream: true
354
392
  });
@@ -358,7 +396,9 @@ var Workflow = class extends BaseResource {
358
396
  if (!response.body) {
359
397
  throw new Error("Response body is null");
360
398
  }
361
- yield* this.streamProcessor(response.body);
399
+ for await (const record of this.streamProcessor(response.body)) {
400
+ onRecord(record);
401
+ }
362
402
  }
363
403
  };
364
404
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.9-alpha.1",
3
+ "version": "0.1.9",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "json-schema": "^0.4.0",
26
26
  "zod": "^3.24.2",
27
27
  "zod-to-json-schema": "^3.24.3",
28
- "@mastra/core": "^0.6.1-alpha.1"
28
+ "@mastra/core": "^0.6.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@babel/preset-env": "^7.26.9",
package/src/example.ts CHANGED
@@ -46,31 +46,29 @@ import type { WorkflowRunResult } from './types';
46
46
  // })();
47
47
 
48
48
  // Workflow
49
-
50
49
  // (async () => {
51
50
  // const client = new MastraClient({
52
51
  // baseUrl: 'http://localhost:4111',
53
52
  // });
54
53
 
55
- // let finalWorkflowResult: WorkflowRunResult | null = null;
54
+ // try {
55
+ // const workflowId = 'myWorkflow';
56
+ // const workflow = client.getWorkflow(workflowId);
56
57
 
57
- // try{
58
- // const workflowId = 'weatherWorkflow';
58
+ // const { runId } = await workflow.createRun();
59
59
 
60
- // const workflow = client.getWorkflow(workflowId);
60
+ // workflow.watch({ runId }, record => {
61
+ // console.log(new Date().toTimeString(), record);
62
+ // });
61
63
 
62
- // const {runId} = await workflow.startRun({
63
- // city: 'New York',
64
+ // await workflow.start({
65
+ // runId,
66
+ // triggerData: {
67
+ // city: 'New York',
68
+ // },
64
69
  // });
65
70
 
66
- // for await (const record of workflow.watch({runId})) {
67
- // console.log(new Date().toTimeString(), record);
68
- // finalWorkflowResult = record;
69
- // }
70
- // }catch(e){
71
- // console.log(e);
72
- // }finally{
73
- // console.log('Done')
74
- // console.log({finalWorkflowResult});
71
+ // } catch (e) {
72
+ // console.error('Workflow error:', e);
75
73
  // }
76
74
  // })();
@@ -31,19 +31,35 @@ export class Workflow extends BaseResource {
31
31
  }
32
32
 
33
33
  /**
34
- * Creates a new workflow run instance and starts it
35
- * @param params - Parameters required for the workflow run
34
+ * Creates a new workflow run
36
35
  * @returns Promise containing the generated run ID
37
36
  */
38
- startRun(params: Record<string, any>): Promise<{ runId: string }> {
39
- return this.request(`/api/workflows/${this.workflowId}/startRun`, {
37
+ createRun(params?: { runId?: string }): Promise<{ runId: string }> {
38
+ const searchParams = new URLSearchParams();
39
+
40
+ if (!!params?.runId) {
41
+ searchParams.set('runId', params.runId);
42
+ }
43
+
44
+ return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
40
45
  method: 'POST',
41
- body: params,
42
46
  });
43
47
  }
44
48
 
45
49
  /**
46
- * Resumes a suspended workflow step
50
+ * Starts a workflow run synchronously without waiting for the workflow to complete
51
+ * @param params - Object containing the runId and triggerData
52
+ * @returns Promise containing success message
53
+ */
54
+ start(params: { runId: string; triggerData: Record<string, any> }): Promise<{ message: string }> {
55
+ return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
56
+ method: 'POST',
57
+ body: params?.triggerData,
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
47
63
  * @param stepId - ID of the step to resume
48
64
  * @param runId - ID of the workflow run
49
65
  * @param context - Context to resume the workflow with
@@ -57,7 +73,7 @@ export class Workflow extends BaseResource {
57
73
  stepId: string;
58
74
  runId: string;
59
75
  context: Record<string, any>;
60
- }): Promise<Record<string, any>> {
76
+ }): Promise<{ message: string }> {
61
77
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
62
78
  method: 'POST',
63
79
  body: {
@@ -67,6 +83,33 @@ export class Workflow extends BaseResource {
67
83
  });
68
84
  }
69
85
 
86
+ /**
87
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
88
+ * @param params - Object containing the runId and triggerData
89
+ * @returns Promise containing the workflow execution results
90
+ */
91
+ startAsync(params: { runId: string; triggerData: Record<string, any> }): Promise<WorkflowRunResult> {
92
+ return this.request(`/api/workflows/${this.workflowId}/startAsync?runId=${params.runId}`, {
93
+ method: 'POST',
94
+ body: params?.triggerData,
95
+ });
96
+ }
97
+
98
+ /**
99
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
100
+ * @param params - Object containing the runId, stepId, and context
101
+ * @returns Promise containing the workflow resume results
102
+ */
103
+ resumeAsync(params: { runId: string; stepId: string; context: Record<string, any> }): Promise<WorkflowRunResult> {
104
+ return this.request(`/api/workflows/${this.workflowId}/resumeAsync?runId=${params.runId}`, {
105
+ method: 'POST',
106
+ body: {
107
+ stepId: params.stepId,
108
+ context: params.context,
109
+ },
110
+ });
111
+ }
112
+
70
113
  /**
71
114
  * Creates an async generator that processes a readable stream and yields records
72
115
  * separated by the Record Separator character (\x1E)
@@ -113,7 +156,11 @@ export class Workflow extends BaseResource {
113
156
 
114
157
  //Check to see if all steps are completed and cancel reader
115
158
  const isWorkflowCompleted = parsedRecord?.activePaths?.every(
116
- (path: any) => path.status === 'completed' || path.status === 'suspended' || path.status === 'failed',
159
+ (path: any) =>
160
+ path.status === 'completed' ||
161
+ path.status === 'suspended' ||
162
+ path.status === 'failed' ||
163
+ path.status === 'skipped',
117
164
  );
118
165
  if (isWorkflowCompleted) {
119
166
  reader.cancel();
@@ -135,7 +182,7 @@ export class Workflow extends BaseResource {
135
182
  * @param runId - Optional run ID to filter the watch stream
136
183
  * @returns AsyncGenerator that yields parsed records from the workflow watch stream
137
184
  */
138
- async *watch({ runId }: { runId?: string }) {
185
+ async watch({ runId }: { runId?: string }, onRecord: (record: WorkflowRunResult) => void) {
139
186
  const response: Response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
140
187
  stream: true,
141
188
  });
@@ -148,6 +195,8 @@ export class Workflow extends BaseResource {
148
195
  throw new Error('Response body is null');
149
196
  }
150
197
 
151
- yield* this.streamProcessor(response.body);
198
+ for await (const record of this.streamProcessor(response.body)) {
199
+ onRecord(record);
200
+ }
152
201
  }
153
202
  }
package/src/types.ts CHANGED
@@ -25,6 +25,7 @@ export interface ClientOptions {
25
25
  maxBackoffMs?: number;
26
26
  /** Custom headers to include with requests */
27
27
  headers?: Record<string, string>;
28
+ /** Abort signal for request */
28
29
  }
29
30
 
30
31
  export interface RequestOptions {
@@ -32,6 +33,7 @@ export interface RequestOptions {
32
33
  headers?: Record<string, string>;
33
34
  body?: any;
34
35
  stream?: boolean;
36
+ signal?: AbortSignal;
35
37
  }
36
38
 
37
39
  export interface GetAgentResponse {
@@ -78,10 +80,20 @@ export type WorkflowRunResult = {
78
80
  context: {
79
81
  steps: Record<
80
82
  string,
81
- {
82
- status: 'completed' | 'suspended' | 'running';
83
- [key: string]: any;
84
- }
83
+ | {
84
+ status: 'success';
85
+ output: any;
86
+ [key: string]: any;
87
+ }
88
+ | {
89
+ status: 'pending';
90
+ [key: string]: any;
91
+ }
92
+ | {
93
+ status: 'suspended';
94
+ suspendPayload: any;
95
+ [key: string]: any;
96
+ }
85
97
  >;
86
98
  };
87
99
  timestamp: number;