@mastra/client-js 0.1.7-alpha.9 → 0.1.8-alpha.0
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 +10 -10
- package/CHANGELOG.md +80 -0
- package/README.md +4 -3
- package/dist/index.cjs +22 -8
- package/dist/index.d.cts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +22 -8
- package/package.json +12 -12
- package/src/example.ts +18 -8
- package/src/resources/workflow.ts +28 -8
- package/src/types.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/client-js@0.1.
|
|
3
|
-
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake
|
|
2
|
+
> @mastra/client-js@0.1.8-alpha.0 build /home/runner/work/mastra/mastra/client-sdks/client-js
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.
|
|
7
|
+
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
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[32m16.00 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 491ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m16.09 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 683ms
|
|
16
16
|
[34mDTS[39m Build start
|
|
17
|
-
[32mDTS[39m ⚡️ Build success in
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[32m14.
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 10443ms
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.79 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m14.79 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 0.1.8-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3729dbd]
|
|
8
|
+
- @mastra/core@0.5.1-alpha.0
|
|
9
|
+
|
|
10
|
+
## 0.1.7
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 960690d: Improve client-js workflow watch dx
|
|
15
|
+
- 8deb34c: Better workflow watch api + watch workflow by runId
|
|
16
|
+
- fd4a1d7: Update cjs bundling to make sure files are split
|
|
17
|
+
- Updated dependencies [a910463]
|
|
18
|
+
- Updated dependencies [59df7b6]
|
|
19
|
+
- Updated dependencies [22643eb]
|
|
20
|
+
- Updated dependencies [6feb23f]
|
|
21
|
+
- Updated dependencies [f2d6727]
|
|
22
|
+
- Updated dependencies [7a7a547]
|
|
23
|
+
- Updated dependencies [29f3a82]
|
|
24
|
+
- Updated dependencies [3d0e290]
|
|
25
|
+
- Updated dependencies [e9fbac5]
|
|
26
|
+
- Updated dependencies [301e4ee]
|
|
27
|
+
- Updated dependencies [ee667a2]
|
|
28
|
+
- Updated dependencies [dfbe4e9]
|
|
29
|
+
- Updated dependencies [dab255b]
|
|
30
|
+
- Updated dependencies [1e8bcbc]
|
|
31
|
+
- Updated dependencies [f6678e4]
|
|
32
|
+
- Updated dependencies [9e81f35]
|
|
33
|
+
- Updated dependencies [c93798b]
|
|
34
|
+
- Updated dependencies [a85ab24]
|
|
35
|
+
- Updated dependencies [dbd9f2d]
|
|
36
|
+
- Updated dependencies [59df7b6]
|
|
37
|
+
- Updated dependencies [caefaa2]
|
|
38
|
+
- Updated dependencies [c151ae6]
|
|
39
|
+
- Updated dependencies [52e0418]
|
|
40
|
+
- Updated dependencies [d79aedf]
|
|
41
|
+
- Updated dependencies [03236ec]
|
|
42
|
+
- Updated dependencies [3764e71]
|
|
43
|
+
- Updated dependencies [df982db]
|
|
44
|
+
- Updated dependencies [a171b37]
|
|
45
|
+
- Updated dependencies [506f1d5]
|
|
46
|
+
- Updated dependencies [02ffb7b]
|
|
47
|
+
- Updated dependencies [0461849]
|
|
48
|
+
- Updated dependencies [2259379]
|
|
49
|
+
- Updated dependencies [aeb5e36]
|
|
50
|
+
- Updated dependencies [f2301de]
|
|
51
|
+
- Updated dependencies [358f069]
|
|
52
|
+
- Updated dependencies [fd4a1d7]
|
|
53
|
+
- Updated dependencies [c139344]
|
|
54
|
+
- @mastra/core@0.5.0
|
|
55
|
+
|
|
56
|
+
## 0.1.7-alpha.12
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- Updated dependencies [a85ab24]
|
|
61
|
+
- @mastra/core@0.5.0-alpha.12
|
|
62
|
+
|
|
63
|
+
## 0.1.7-alpha.11
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- 8deb34c: Better workflow watch api + watch workflow by runId
|
|
68
|
+
- fd4a1d7: Update cjs bundling to make sure files are split
|
|
69
|
+
- Updated dependencies [7a7a547]
|
|
70
|
+
- Updated dependencies [c93798b]
|
|
71
|
+
- Updated dependencies [dbd9f2d]
|
|
72
|
+
- Updated dependencies [a171b37]
|
|
73
|
+
- Updated dependencies [fd4a1d7]
|
|
74
|
+
- @mastra/core@0.5.0-alpha.11
|
|
75
|
+
|
|
76
|
+
## 0.1.7-alpha.10
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- Updated dependencies [a910463]
|
|
81
|
+
- @mastra/core@0.5.0-alpha.10
|
|
82
|
+
|
|
3
83
|
## 0.1.7-alpha.9
|
|
4
84
|
|
|
5
85
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -79,9 +79,10 @@ 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
|
|
83
|
-
- `workflow.
|
|
84
|
-
- `workflow.
|
|
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
|
|
85
86
|
|
|
86
87
|
### Vectors
|
|
87
88
|
|
package/dist/index.cjs
CHANGED
|
@@ -266,6 +266,17 @@ var Workflow = class extends BaseResource {
|
|
|
266
266
|
body: params
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Creates a new workflow run instance and starts it
|
|
271
|
+
* @param params - Parameters required for the workflow run
|
|
272
|
+
* @returns Promise containing the generated run ID
|
|
273
|
+
*/
|
|
274
|
+
startRun(params) {
|
|
275
|
+
return this.request(`/api/workflows/${this.workflowId}/startRun`, {
|
|
276
|
+
method: "POST",
|
|
277
|
+
body: params
|
|
278
|
+
});
|
|
279
|
+
}
|
|
269
280
|
/**
|
|
270
281
|
* Resumes a suspended workflow step
|
|
271
282
|
* @param stepId - ID of the step to resume
|
|
@@ -278,11 +289,10 @@ var Workflow = class extends BaseResource {
|
|
|
278
289
|
runId,
|
|
279
290
|
context
|
|
280
291
|
}) {
|
|
281
|
-
return this.request(`/api/workflows/${this.workflowId}/resume`, {
|
|
292
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
282
293
|
method: "POST",
|
|
283
294
|
body: {
|
|
284
295
|
stepId,
|
|
285
|
-
runId,
|
|
286
296
|
context
|
|
287
297
|
}
|
|
288
298
|
});
|
|
@@ -318,6 +328,12 @@ var Workflow = class extends BaseResource {
|
|
|
318
328
|
if (record.trim().length > 0) {
|
|
319
329
|
try {
|
|
320
330
|
const parsedRecord = JSON.parse(record);
|
|
331
|
+
const isWorkflowCompleted = parsedRecord?.activePaths?.every(
|
|
332
|
+
(path) => path.status === "completed" || path.status === "suspended" || path.status === "failed"
|
|
333
|
+
);
|
|
334
|
+
if (isWorkflowCompleted) {
|
|
335
|
+
reader.cancel();
|
|
336
|
+
}
|
|
321
337
|
yield parsedRecord;
|
|
322
338
|
} catch (e) {
|
|
323
339
|
throw new Error(`Could not parse record: ${record}`);
|
|
@@ -326,15 +342,16 @@ var Workflow = class extends BaseResource {
|
|
|
326
342
|
}
|
|
327
343
|
}
|
|
328
344
|
} finally {
|
|
329
|
-
reader.
|
|
345
|
+
reader.cancel();
|
|
330
346
|
}
|
|
331
347
|
}
|
|
332
348
|
/**
|
|
333
349
|
* Watches workflow transitions in real-time
|
|
350
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
334
351
|
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
335
352
|
*/
|
|
336
|
-
async *watch() {
|
|
337
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch`, {
|
|
353
|
+
async *watch({ runId }) {
|
|
354
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
338
355
|
stream: true
|
|
339
356
|
});
|
|
340
357
|
if (!response.ok) {
|
|
@@ -504,9 +521,6 @@ var MastraClient = class extends BaseResource {
|
|
|
504
521
|
getTelemetry(params) {
|
|
505
522
|
const { name, scope, page, perPage, attribute } = params || {};
|
|
506
523
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
507
|
-
({
|
|
508
|
-
..._attribute?.length ? { attribute: _attribute } : {}
|
|
509
|
-
});
|
|
510
524
|
const searchParams = new URLSearchParams();
|
|
511
525
|
if (name) {
|
|
512
526
|
searchParams.set("name", name);
|
package/dist/index.d.cts
CHANGED
|
@@ -50,7 +50,7 @@ interface GetWorkflowResponse {
|
|
|
50
50
|
stepGraph: StepGraph;
|
|
51
51
|
stepSubscriberGraph: Record<string, StepGraph>;
|
|
52
52
|
}
|
|
53
|
-
type
|
|
53
|
+
type WorkflowRunResult = {
|
|
54
54
|
activePaths: Array<{
|
|
55
55
|
stepId: string;
|
|
56
56
|
stepPath: string[];
|
|
@@ -277,7 +277,15 @@ declare class Workflow extends BaseResource {
|
|
|
277
277
|
* @param params - Parameters required for workflow execution
|
|
278
278
|
* @returns Promise containing the workflow execution results
|
|
279
279
|
*/
|
|
280
|
-
execute(params: Record<string, any>): Promise<
|
|
280
|
+
execute(params: Record<string, any>): Promise<WorkflowRunResult>;
|
|
281
|
+
/**
|
|
282
|
+
* Creates a new workflow run instance and starts it
|
|
283
|
+
* @param params - Parameters required for the workflow run
|
|
284
|
+
* @returns Promise containing the generated run ID
|
|
285
|
+
*/
|
|
286
|
+
startRun(params: Record<string, any>): Promise<{
|
|
287
|
+
runId: string;
|
|
288
|
+
}>;
|
|
281
289
|
/**
|
|
282
290
|
* Resumes a suspended workflow step
|
|
283
291
|
* @param stepId - ID of the step to resume
|
|
@@ -300,9 +308,12 @@ declare class Workflow extends BaseResource {
|
|
|
300
308
|
private streamProcessor;
|
|
301
309
|
/**
|
|
302
310
|
* Watches workflow transitions in real-time
|
|
311
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
303
312
|
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
304
313
|
*/
|
|
305
|
-
watch(
|
|
314
|
+
watch({ runId }: {
|
|
315
|
+
runId?: string;
|
|
316
|
+
}): AsyncGenerator<WorkflowRunResult, void, unknown>;
|
|
306
317
|
}
|
|
307
318
|
|
|
308
319
|
declare class Tool extends BaseResource {
|
|
@@ -422,4 +433,4 @@ declare class MastraClient extends BaseResource {
|
|
|
422
433
|
getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse>;
|
|
423
434
|
}
|
|
424
435
|
|
|
425
|
-
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse,
|
|
436
|
+
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ interface GetWorkflowResponse {
|
|
|
50
50
|
stepGraph: StepGraph;
|
|
51
51
|
stepSubscriberGraph: Record<string, StepGraph>;
|
|
52
52
|
}
|
|
53
|
-
type
|
|
53
|
+
type WorkflowRunResult = {
|
|
54
54
|
activePaths: Array<{
|
|
55
55
|
stepId: string;
|
|
56
56
|
stepPath: string[];
|
|
@@ -277,7 +277,15 @@ declare class Workflow extends BaseResource {
|
|
|
277
277
|
* @param params - Parameters required for workflow execution
|
|
278
278
|
* @returns Promise containing the workflow execution results
|
|
279
279
|
*/
|
|
280
|
-
execute(params: Record<string, any>): Promise<
|
|
280
|
+
execute(params: Record<string, any>): Promise<WorkflowRunResult>;
|
|
281
|
+
/**
|
|
282
|
+
* Creates a new workflow run instance and starts it
|
|
283
|
+
* @param params - Parameters required for the workflow run
|
|
284
|
+
* @returns Promise containing the generated run ID
|
|
285
|
+
*/
|
|
286
|
+
startRun(params: Record<string, any>): Promise<{
|
|
287
|
+
runId: string;
|
|
288
|
+
}>;
|
|
281
289
|
/**
|
|
282
290
|
* Resumes a suspended workflow step
|
|
283
291
|
* @param stepId - ID of the step to resume
|
|
@@ -300,9 +308,12 @@ declare class Workflow extends BaseResource {
|
|
|
300
308
|
private streamProcessor;
|
|
301
309
|
/**
|
|
302
310
|
* Watches workflow transitions in real-time
|
|
311
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
303
312
|
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
304
313
|
*/
|
|
305
|
-
watch(
|
|
314
|
+
watch({ runId }: {
|
|
315
|
+
runId?: string;
|
|
316
|
+
}): AsyncGenerator<WorkflowRunResult, void, unknown>;
|
|
306
317
|
}
|
|
307
318
|
|
|
308
319
|
declare class Tool extends BaseResource {
|
|
@@ -422,4 +433,4 @@ declare class MastraClient extends BaseResource {
|
|
|
422
433
|
getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse>;
|
|
423
434
|
}
|
|
424
435
|
|
|
425
|
-
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse,
|
|
436
|
+
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult };
|
package/dist/index.js
CHANGED
|
@@ -264,6 +264,17 @@ var Workflow = class extends BaseResource {
|
|
|
264
264
|
body: params
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Creates a new workflow run instance and starts it
|
|
269
|
+
* @param params - Parameters required for the workflow run
|
|
270
|
+
* @returns Promise containing the generated run ID
|
|
271
|
+
*/
|
|
272
|
+
startRun(params) {
|
|
273
|
+
return this.request(`/api/workflows/${this.workflowId}/startRun`, {
|
|
274
|
+
method: "POST",
|
|
275
|
+
body: params
|
|
276
|
+
});
|
|
277
|
+
}
|
|
267
278
|
/**
|
|
268
279
|
* Resumes a suspended workflow step
|
|
269
280
|
* @param stepId - ID of the step to resume
|
|
@@ -276,11 +287,10 @@ var Workflow = class extends BaseResource {
|
|
|
276
287
|
runId,
|
|
277
288
|
context
|
|
278
289
|
}) {
|
|
279
|
-
return this.request(`/api/workflows/${this.workflowId}/resume`, {
|
|
290
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
280
291
|
method: "POST",
|
|
281
292
|
body: {
|
|
282
293
|
stepId,
|
|
283
|
-
runId,
|
|
284
294
|
context
|
|
285
295
|
}
|
|
286
296
|
});
|
|
@@ -316,6 +326,12 @@ var Workflow = class extends BaseResource {
|
|
|
316
326
|
if (record.trim().length > 0) {
|
|
317
327
|
try {
|
|
318
328
|
const parsedRecord = JSON.parse(record);
|
|
329
|
+
const isWorkflowCompleted = parsedRecord?.activePaths?.every(
|
|
330
|
+
(path) => path.status === "completed" || path.status === "suspended" || path.status === "failed"
|
|
331
|
+
);
|
|
332
|
+
if (isWorkflowCompleted) {
|
|
333
|
+
reader.cancel();
|
|
334
|
+
}
|
|
319
335
|
yield parsedRecord;
|
|
320
336
|
} catch (e) {
|
|
321
337
|
throw new Error(`Could not parse record: ${record}`);
|
|
@@ -324,15 +340,16 @@ var Workflow = class extends BaseResource {
|
|
|
324
340
|
}
|
|
325
341
|
}
|
|
326
342
|
} finally {
|
|
327
|
-
reader.
|
|
343
|
+
reader.cancel();
|
|
328
344
|
}
|
|
329
345
|
}
|
|
330
346
|
/**
|
|
331
347
|
* Watches workflow transitions in real-time
|
|
348
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
332
349
|
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
333
350
|
*/
|
|
334
|
-
async *watch() {
|
|
335
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch`, {
|
|
351
|
+
async *watch({ runId }) {
|
|
352
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
336
353
|
stream: true
|
|
337
354
|
});
|
|
338
355
|
if (!response.ok) {
|
|
@@ -502,9 +519,6 @@ var MastraClient = class extends BaseResource {
|
|
|
502
519
|
getTelemetry(params) {
|
|
503
520
|
const { name, scope, page, perPage, attribute } = params || {};
|
|
504
521
|
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
505
|
-
({
|
|
506
|
-
..._attribute?.length ? { attribute: _attribute } : {}
|
|
507
|
-
});
|
|
508
522
|
const searchParams = new URLSearchParams();
|
|
509
523
|
if (name) {
|
|
510
524
|
searchParams.set("name", name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8-alpha.0",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -23,23 +23,23 @@
|
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"json-schema": "^0.4.0",
|
|
26
|
-
"zod": "^3.24.
|
|
27
|
-
"zod-to-json-schema": "^3.24.
|
|
28
|
-
"@mastra/core": "^0.5.
|
|
26
|
+
"zod": "^3.24.2",
|
|
27
|
+
"zod-to-json-schema": "^3.24.3",
|
|
28
|
+
"@mastra/core": "^0.5.1-alpha.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/preset-env": "^7.26.
|
|
31
|
+
"@babel/preset-env": "^7.26.9",
|
|
32
32
|
"@babel/preset-typescript": "^7.26.0",
|
|
33
|
-
"@tsconfig/recommended": "^1.0.
|
|
33
|
+
"@tsconfig/recommended": "^1.0.8",
|
|
34
34
|
"@types/json-schema": "^7.0.15",
|
|
35
|
-
"@types/node": "^22.
|
|
36
|
-
"tsup": "^8.0
|
|
37
|
-
"typescript": "^5.
|
|
38
|
-
"vitest": "^3.0.
|
|
39
|
-
"@internal/lint": "0.0.
|
|
35
|
+
"@types/node": "^22.13.10",
|
|
36
|
+
"tsup": "^8.4.0",
|
|
37
|
+
"typescript": "^5.8.2",
|
|
38
|
+
"vitest": "^3.0.8",
|
|
39
|
+
"@internal/lint": "0.0.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake",
|
|
42
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
|
43
43
|
"dev": "pnpm build --watch",
|
|
44
44
|
"test": "vitest run"
|
|
45
45
|
}
|
package/src/example.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MastraClient } from './client';
|
|
2
|
+
import type { WorkflowRunResult } from './types';
|
|
2
3
|
|
|
3
4
|
// Agent
|
|
4
5
|
|
|
@@ -51,16 +52,25 @@ import { MastraClient } from './client';
|
|
|
51
52
|
// baseUrl: 'http://localhost:4111',
|
|
52
53
|
// });
|
|
53
54
|
|
|
54
|
-
//
|
|
55
|
+
// let finalWorkflowResult: WorkflowRunResult | null = null;
|
|
55
56
|
|
|
56
|
-
//
|
|
57
|
-
//
|
|
57
|
+
// try{
|
|
58
|
+
// const workflowId = 'weatherWorkflow';
|
|
58
59
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
//
|
|
60
|
+
// const workflow = client.getWorkflow(workflowId);
|
|
61
|
+
|
|
62
|
+
// const {runId} = await workflow.startRun({
|
|
63
|
+
// city: 'New York',
|
|
64
|
+
// });
|
|
62
65
|
|
|
63
|
-
//
|
|
64
|
-
//
|
|
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});
|
|
65
75
|
// }
|
|
66
76
|
// })();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetWorkflowResponse, ClientOptions,
|
|
1
|
+
import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult } from '../types';
|
|
2
2
|
|
|
3
3
|
import { BaseResource } from './base';
|
|
4
4
|
|
|
@@ -23,13 +23,25 @@ export class Workflow extends BaseResource {
|
|
|
23
23
|
* @param params - Parameters required for workflow execution
|
|
24
24
|
* @returns Promise containing the workflow execution results
|
|
25
25
|
*/
|
|
26
|
-
execute(params: Record<string, any>): Promise<
|
|
26
|
+
execute(params: Record<string, any>): Promise<WorkflowRunResult> {
|
|
27
27
|
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
28
28
|
method: 'POST',
|
|
29
29
|
body: params,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new workflow run instance and starts it
|
|
35
|
+
* @param params - Parameters required for the workflow run
|
|
36
|
+
* @returns Promise containing the generated run ID
|
|
37
|
+
*/
|
|
38
|
+
startRun(params: Record<string, any>): Promise<{ runId: string }> {
|
|
39
|
+
return this.request(`/api/workflows/${this.workflowId}/startRun`, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
body: params,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
/**
|
|
34
46
|
* Resumes a suspended workflow step
|
|
35
47
|
* @param stepId - ID of the step to resume
|
|
@@ -46,11 +58,10 @@ export class Workflow extends BaseResource {
|
|
|
46
58
|
runId: string;
|
|
47
59
|
context: Record<string, any>;
|
|
48
60
|
}): Promise<Record<string, any>> {
|
|
49
|
-
return this.request(`/api/workflows/${this.workflowId}/resume`, {
|
|
61
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
50
62
|
method: 'POST',
|
|
51
63
|
body: {
|
|
52
64
|
stepId,
|
|
53
|
-
runId,
|
|
54
65
|
context,
|
|
55
66
|
},
|
|
56
67
|
});
|
|
@@ -63,7 +74,7 @@ export class Workflow extends BaseResource {
|
|
|
63
74
|
* @param stream - The readable stream to process
|
|
64
75
|
* @returns An async generator that yields parsed records
|
|
65
76
|
*/
|
|
66
|
-
private async *streamProcessor(stream: ReadableStream): AsyncGenerator<
|
|
77
|
+
private async *streamProcessor(stream: ReadableStream): AsyncGenerator<WorkflowRunResult, void, unknown> {
|
|
67
78
|
const reader = stream.getReader();
|
|
68
79
|
let buffer = '';
|
|
69
80
|
|
|
@@ -99,6 +110,14 @@ export class Workflow extends BaseResource {
|
|
|
99
110
|
try {
|
|
100
111
|
// Assuming the records are JSON strings
|
|
101
112
|
const parsedRecord = JSON.parse(record);
|
|
113
|
+
|
|
114
|
+
//Check to see if all steps are completed and cancel reader
|
|
115
|
+
const isWorkflowCompleted = parsedRecord?.activePaths?.every(
|
|
116
|
+
(path: any) => path.status === 'completed' || path.status === 'suspended' || path.status === 'failed',
|
|
117
|
+
);
|
|
118
|
+
if (isWorkflowCompleted) {
|
|
119
|
+
reader.cancel();
|
|
120
|
+
}
|
|
102
121
|
yield parsedRecord;
|
|
103
122
|
} catch (e) {
|
|
104
123
|
throw new Error(`Could not parse record: ${record}`);
|
|
@@ -107,16 +126,17 @@ export class Workflow extends BaseResource {
|
|
|
107
126
|
}
|
|
108
127
|
}
|
|
109
128
|
} finally {
|
|
110
|
-
reader.
|
|
129
|
+
reader.cancel();
|
|
111
130
|
}
|
|
112
131
|
}
|
|
113
132
|
|
|
114
133
|
/**
|
|
115
134
|
* Watches workflow transitions in real-time
|
|
135
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
116
136
|
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
117
137
|
*/
|
|
118
|
-
async *watch() {
|
|
119
|
-
const response: Response = await this.request(`/api/workflows/${this.workflowId}/watch`, {
|
|
138
|
+
async *watch({ runId }: { runId?: string }) {
|
|
139
|
+
const response: Response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
120
140
|
stream: true,
|
|
121
141
|
});
|
|
122
142
|
|
package/src/types.ts
CHANGED