@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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +29 -0
- package/README.md +6 -4
- package/dist/index.cjs +49 -9
- package/dist/index.d.cts +49 -7
- package/dist/index.d.ts +49 -7
- package/dist/index.js +49 -9
- package/package.json +2 -2
- package/src/example.ts +14 -16
- package/src/resources/workflow.ts +59 -10
- package/src/types.ts +16 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/client-js@0.1.9-alpha.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m17.49 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 847ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m17.58 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 848ms
|
|
16
16
|
[34mDTS[39m Build start
|
|
17
|
-
[32mDTS[39m ⚡️ Build success in
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 11271ms
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m16.15 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m16.15 KB[39m
|
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.
|
|
83
|
-
- `workflow.
|
|
84
|
-
- `workflow.
|
|
85
|
-
- `workflow.
|
|
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
|
|
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
|
-
|
|
275
|
-
|
|
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
|
|
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
|
-
|
|
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: '
|
|
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
|
|
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
|
-
|
|
294
|
+
createRun(params?: {
|
|
295
|
+
runId?: string;
|
|
296
|
+
}): Promise<{
|
|
287
297
|
runId: string;
|
|
288
298
|
}>;
|
|
289
299
|
/**
|
|
290
|
-
*
|
|
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<
|
|
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
|
-
}
|
|
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: '
|
|
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
|
|
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
|
-
|
|
294
|
+
createRun(params?: {
|
|
295
|
+
runId?: string;
|
|
296
|
+
}): Promise<{
|
|
287
297
|
runId: string;
|
|
288
298
|
}>;
|
|
289
299
|
/**
|
|
290
|
-
*
|
|
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<
|
|
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
|
-
}
|
|
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
|
|
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
|
-
|
|
273
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
//
|
|
54
|
+
// try {
|
|
55
|
+
// const workflowId = 'myWorkflow';
|
|
56
|
+
// const workflow = client.getWorkflow(workflowId);
|
|
56
57
|
|
|
57
|
-
//
|
|
58
|
-
// const workflowId = 'weatherWorkflow';
|
|
58
|
+
// const { runId } = await workflow.createRun();
|
|
59
59
|
|
|
60
|
-
//
|
|
60
|
+
// workflow.watch({ runId }, record => {
|
|
61
|
+
// console.log(new Date().toTimeString(), record);
|
|
62
|
+
// });
|
|
61
63
|
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
+
// await workflow.start({
|
|
65
|
+
// runId,
|
|
66
|
+
// triggerData: {
|
|
67
|
+
// city: 'New York',
|
|
68
|
+
// },
|
|
64
69
|
// });
|
|
65
70
|
|
|
66
|
-
//
|
|
67
|
-
//
|
|
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
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
*
|
|
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<
|
|
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) =>
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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;
|