@mastra/client-js 1.39.0-alpha.1 → 1.39.0-alpha.13
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 +165 -0
- package/dist/client.d.ts +22 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-a2a.md +39 -0
- package/dist/docs/references/docs-long-running-agents-schedules.md +1 -1
- package/dist/docs/references/docs-long-running-agents-signals.md +1 -1
- package/dist/docs/references/docs-server-auth-auth0.md +1 -1
- package/dist/docs/references/docs-server-auth-clerk.md +2 -2
- package/dist/docs/references/docs-server-auth-firebase.md +1 -1
- package/dist/docs/references/docs-server-auth-supabase.md +2 -2
- package/dist/docs/references/docs-server-auth-workos.md +1 -1
- package/dist/docs/references/docs-server-mastra-client.md +13 -13
- package/dist/docs/references/reference-client-js-agents.md +2 -1
- package/dist/docs/references/reference-client-js-workflows.md +32 -19
- package/dist/index.cjs +109 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +109 -21
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts +14 -0
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent-controller.d.ts +22 -3
- package/dist/resources/agent-controller.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +6 -0
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/dynamic-workflow.d.ts +18 -0
- package/dist/resources/dynamic-workflow.d.ts.map +1 -0
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +318 -241
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +15 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-a2a-stream.d.ts +1 -1
- package/dist/utils/process-a2a-stream.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/resources/stored-workflow.d.ts +0 -18
- package/dist/resources/stored-workflow.d.ts.map +0 -1
|
@@ -12,6 +12,19 @@ Retrieve a list of all available workflows:
|
|
|
12
12
|
const workflows = await mastraClient.listWorkflows()
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Getting workflow run counts
|
|
16
|
+
|
|
17
|
+
Retrieve per-workflow counts of `running` and [`suspended`](https://mastra.ai/docs/workflows/suspend-and-resume) runs in a single request. The counts are computed on the server and keyed by the workflow's registry key, the key used when registering the workflow in the Mastra config, which can differ from the workflow's own `id`:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const runCounts = await mastraClient.listWorkflowRunCounts()
|
|
21
|
+
// { "cityWorkflow": { running: 2, suspended: 1 }, ... }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Returns: `Record<string, { running: number; suspended: number }>`
|
|
25
|
+
|
|
26
|
+
The server may cache the counts for a few seconds between requests. Servers that predate this endpoint respond with `404 Not Found`. Handle the error when the client can talk to older deployments.
|
|
27
|
+
|
|
15
28
|
## Working with a specific workflow
|
|
16
29
|
|
|
17
30
|
Get an instance of a specific workflow by its ID:
|
|
@@ -212,28 +225,28 @@ A workflow run result yields the following:
|
|
|
212
225
|
|
|
213
226
|
**payload** (`object`): Contains currentStep (id, status, output, payload) and workflowState (status, steps record)
|
|
214
227
|
|
|
215
|
-
##
|
|
228
|
+
## Dynamic workflows
|
|
216
229
|
|
|
217
|
-
> **Beta:**
|
|
230
|
+
> **Beta:** Breaking changes may occur without a major version bump until the API is stable.
|
|
218
231
|
|
|
219
|
-
|
|
232
|
+
Dynamic workflows are workflow definitions expressed as JSON. The server persists each definition and registers it as a runnable workflow. See [Dynamic workflows](https://mastra.ai/docs/workflows/dynamic-workflows) for the definition format.
|
|
220
233
|
|
|
221
|
-
### `
|
|
234
|
+
### `listDynamicWorkflows()`
|
|
222
235
|
|
|
223
|
-
List
|
|
236
|
+
List dynamic workflow definitions, optionally filtered by `status` (`'active' | 'archived'`) and `authorId`:
|
|
224
237
|
|
|
225
238
|
```typescript
|
|
226
|
-
const { definitions, total } = await mastraClient.
|
|
239
|
+
const { definitions, total } = await mastraClient.listDynamicWorkflows({
|
|
227
240
|
status: 'active',
|
|
228
241
|
})
|
|
229
242
|
```
|
|
230
243
|
|
|
231
|
-
### `
|
|
244
|
+
### `upsertDynamicWorkflow()`
|
|
232
245
|
|
|
233
|
-
Create or replace a
|
|
246
|
+
Create or replace a dynamic workflow definition. The server validates the definition, persists it, and live-registers it for execution:
|
|
234
247
|
|
|
235
248
|
```typescript
|
|
236
|
-
const stored = await mastraClient.
|
|
249
|
+
const stored = await mastraClient.upsertDynamicWorkflow({
|
|
237
250
|
id: 'greeting-workflow',
|
|
238
251
|
description: 'Returns a greeting for the supplied name',
|
|
239
252
|
inputSchema: {
|
|
@@ -261,7 +274,7 @@ const stored = await mastraClient.upsertStoredWorkflow({
|
|
|
261
274
|
When the root definition nests helper workflows that don't exist yet, pass them in the same request through `dependencies`. The server validates and registers the bundle as a unit and echoes the helper ids back as `dependencyIds`:
|
|
262
275
|
|
|
263
276
|
```typescript
|
|
264
|
-
const stored = await mastraClient.
|
|
277
|
+
const stored = await mastraClient.upsertDynamicWorkflow({
|
|
265
278
|
id: 'root-workflow',
|
|
266
279
|
// ...schemas and graph referencing 'helper-workflow'...
|
|
267
280
|
dependencies: [helperDefinition],
|
|
@@ -270,33 +283,33 @@ const stored = await mastraClient.upsertStoredWorkflow({
|
|
|
270
283
|
console.log(stored.dependencyIds) // ['helper-workflow']
|
|
271
284
|
```
|
|
272
285
|
|
|
273
|
-
### `
|
|
286
|
+
### `getDynamicWorkflow()`
|
|
274
287
|
|
|
275
|
-
Get a
|
|
288
|
+
Get a dynamic workflow instance for definition management. To execute a dynamic workflow, use `getWorkflow(id).createRun()` like any other workflow:
|
|
276
289
|
|
|
277
290
|
```typescript
|
|
278
|
-
const
|
|
291
|
+
const dynamicWorkflow = mastraClient.getDynamicWorkflow('greeting-workflow')
|
|
279
292
|
```
|
|
280
293
|
|
|
281
|
-
### `
|
|
294
|
+
### `dynamicWorkflow.details()`
|
|
282
295
|
|
|
283
296
|
Retrieve the persisted definition, including schemas, graph, status, and timestamps:
|
|
284
297
|
|
|
285
298
|
```typescript
|
|
286
|
-
const definition = await
|
|
299
|
+
const definition = await dynamicWorkflow.details()
|
|
287
300
|
```
|
|
288
301
|
|
|
289
|
-
### `
|
|
302
|
+
### `dynamicWorkflow.delete()`
|
|
290
303
|
|
|
291
304
|
Delete the stored definition and unregister the live workflow:
|
|
292
305
|
|
|
293
306
|
```typescript
|
|
294
|
-
await
|
|
307
|
+
await dynamicWorkflow.delete()
|
|
295
308
|
```
|
|
296
309
|
|
|
297
|
-
### Executing a
|
|
310
|
+
### Executing a dynamic workflow
|
|
298
311
|
|
|
299
|
-
Once registered, a
|
|
312
|
+
Once registered, a dynamic workflow runs through the ordinary workflow API:
|
|
300
313
|
|
|
301
314
|
```typescript
|
|
302
315
|
const workflow = mastraClient.getWorkflow('greeting-workflow')
|
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ let _mastra_schema_compat_schema = require("@mastra/schema-compat/schema");
|
|
|
28
28
|
let _mastra_core_request_context = require("@mastra/core/request-context");
|
|
29
29
|
let _mastra_schema_compat_zod_to_json = require("@mastra/schema-compat/zod-to-json");
|
|
30
30
|
let _mastra_core_a2a_client = require("@mastra/core/a2a/client");
|
|
31
|
+
let _mastra_core_a2a_v1 = require("@mastra/core/a2a/v1");
|
|
31
32
|
let canonicalize = require("canonicalize");
|
|
32
33
|
canonicalize = __toESM(canonicalize, 1);
|
|
33
34
|
let jose = require("jose");
|
|
@@ -3849,6 +3850,74 @@ var A2A = class extends BaseResource {
|
|
|
3849
3850
|
}));
|
|
3850
3851
|
}
|
|
3851
3852
|
};
|
|
3853
|
+
/** Client for the A2A Protocol v1.0 wire format. */
|
|
3854
|
+
var A2AV1 = class extends BaseResource {
|
|
3855
|
+
agentId;
|
|
3856
|
+
constructor(options, agentId) {
|
|
3857
|
+
super(options);
|
|
3858
|
+
this.agentId = agentId;
|
|
3859
|
+
}
|
|
3860
|
+
async rpc(method, params) {
|
|
3861
|
+
return unwrapA2AResult(await this.request(`/a2a/${this.agentId}`, {
|
|
3862
|
+
method: "POST",
|
|
3863
|
+
headers: { "A2A-Version": "1.0" },
|
|
3864
|
+
body: {
|
|
3865
|
+
jsonrpc: "2.0",
|
|
3866
|
+
id: crypto.randomUUID(),
|
|
3867
|
+
method,
|
|
3868
|
+
params
|
|
3869
|
+
}
|
|
3870
|
+
}));
|
|
3871
|
+
}
|
|
3872
|
+
async getAgentCard() {
|
|
3873
|
+
const card = await this.request(`/.well-known/${this.agentId}/agent-card.json`, { headers: { "A2A-Version": "1.0" } });
|
|
3874
|
+
return _mastra_core_a2a_v1.AgentCard.fromJSON(card);
|
|
3875
|
+
}
|
|
3876
|
+
async sendMessage(params) {
|
|
3877
|
+
const result = await this.rpc("message/send", _mastra_core_a2a_v1.SendMessageRequest.toJSON(params));
|
|
3878
|
+
return _mastra_core_a2a_v1.SendMessageResponse.fromJSON(result);
|
|
3879
|
+
}
|
|
3880
|
+
async *sendMessageStream(params) {
|
|
3881
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
3882
|
+
method: "POST",
|
|
3883
|
+
headers: { "A2A-Version": "1.0" },
|
|
3884
|
+
body: {
|
|
3885
|
+
jsonrpc: "2.0",
|
|
3886
|
+
id: crypto.randomUUID(),
|
|
3887
|
+
method: "message/stream",
|
|
3888
|
+
params: _mastra_core_a2a_v1.SendMessageRequest.toJSON(params)
|
|
3889
|
+
},
|
|
3890
|
+
stream: true
|
|
3891
|
+
});
|
|
3892
|
+
for await (const event of processA2AStream(await requireResponseBody(response, "message/stream"))) yield _mastra_core_a2a_v1.StreamResponse.fromJSON(event);
|
|
3893
|
+
}
|
|
3894
|
+
async getTask(params) {
|
|
3895
|
+
const result = await this.rpc("tasks/get", _mastra_core_a2a_v1.GetTaskRequest.toJSON(params));
|
|
3896
|
+
return _mastra_core_a2a_v1.Task.fromJSON(result);
|
|
3897
|
+
}
|
|
3898
|
+
async listTasks(params) {
|
|
3899
|
+
const result = await this.rpc("tasks/list", _mastra_core_a2a_v1.ListTasksRequest.toJSON(params));
|
|
3900
|
+
return _mastra_core_a2a_v1.ListTasksResponse.fromJSON(result);
|
|
3901
|
+
}
|
|
3902
|
+
async cancelTask(params) {
|
|
3903
|
+
const result = await this.rpc("tasks/cancel", _mastra_core_a2a_v1.CancelTaskRequest.toJSON(params));
|
|
3904
|
+
return _mastra_core_a2a_v1.Task.fromJSON(result);
|
|
3905
|
+
}
|
|
3906
|
+
async *resubscribeTask(params) {
|
|
3907
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
3908
|
+
method: "POST",
|
|
3909
|
+
headers: { "A2A-Version": "1.0" },
|
|
3910
|
+
body: {
|
|
3911
|
+
jsonrpc: "2.0",
|
|
3912
|
+
id: crypto.randomUUID(),
|
|
3913
|
+
method: "tasks/resubscribe",
|
|
3914
|
+
params: _mastra_core_a2a_v1.SubscribeToTaskRequest.toJSON(params)
|
|
3915
|
+
},
|
|
3916
|
+
stream: true
|
|
3917
|
+
});
|
|
3918
|
+
for await (const event of processA2AStream(await requireResponseBody(response, "tasks/resubscribe"))) yield _mastra_core_a2a_v1.StreamResponse.fromJSON(event);
|
|
3919
|
+
}
|
|
3920
|
+
};
|
|
3852
3921
|
//#endregion
|
|
3853
3922
|
//#region src/resources/mcp-tool.ts
|
|
3854
3923
|
/**
|
|
@@ -4688,27 +4757,27 @@ var StoredAgent = class extends BaseResource {
|
|
|
4688
4757
|
}
|
|
4689
4758
|
};
|
|
4690
4759
|
//#endregion
|
|
4691
|
-
//#region src/resources/
|
|
4692
|
-
/** Resource for interacting with a specific
|
|
4693
|
-
var
|
|
4694
|
-
|
|
4695
|
-
constructor(options,
|
|
4760
|
+
//#region src/resources/dynamic-workflow.ts
|
|
4761
|
+
/** Resource for interacting with a specific dynamic workflow definition. */
|
|
4762
|
+
var DynamicWorkflow = class extends BaseResource {
|
|
4763
|
+
dynamicWorkflowId;
|
|
4764
|
+
constructor(options, dynamicWorkflowId) {
|
|
4696
4765
|
super(options);
|
|
4697
|
-
this.
|
|
4766
|
+
this.dynamicWorkflowId = dynamicWorkflowId;
|
|
4698
4767
|
}
|
|
4699
4768
|
/**
|
|
4700
|
-
* Retrieves the full
|
|
4701
|
-
* @returns Promise containing the
|
|
4769
|
+
* Retrieves the full dynamic workflow definition (schemas, graph, status, metadata)
|
|
4770
|
+
* @returns Promise containing the dynamic workflow definition
|
|
4702
4771
|
*/
|
|
4703
4772
|
details() {
|
|
4704
|
-
return this.request(`/stored/workflows/${encodeURIComponent(this.
|
|
4773
|
+
return this.request(`/stored/workflows/${encodeURIComponent(this.dynamicWorkflowId)}`);
|
|
4705
4774
|
}
|
|
4706
4775
|
/**
|
|
4707
|
-
* Deletes the
|
|
4776
|
+
* Deletes the dynamic workflow definition and unregisters it from the server
|
|
4708
4777
|
* @returns Promise containing the deletion result
|
|
4709
4778
|
*/
|
|
4710
4779
|
delete() {
|
|
4711
|
-
return this.request(`/stored/workflows/${encodeURIComponent(this.
|
|
4780
|
+
return this.request(`/stored/workflows/${encodeURIComponent(this.dynamicWorkflowId)}`, { method: "DELETE" });
|
|
4712
4781
|
}
|
|
4713
4782
|
};
|
|
4714
4783
|
//#endregion
|
|
@@ -6365,6 +6434,18 @@ var MastraClient = class extends BaseResource {
|
|
|
6365
6434
|
return this.request(`/workflows${queryString ? `?${queryString}` : ""}`);
|
|
6366
6435
|
}
|
|
6367
6436
|
/**
|
|
6437
|
+
* Retrieves per-workflow counts of running and suspended (awaiting resume) runs
|
|
6438
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
6439
|
+
* @returns Promise containing map of workflow IDs to run counts
|
|
6440
|
+
*/
|
|
6441
|
+
listWorkflowRunCounts(requestContext) {
|
|
6442
|
+
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
6443
|
+
const searchParams = new URLSearchParams();
|
|
6444
|
+
if (requestContextParam) searchParams.set("requestContext", requestContextParam);
|
|
6445
|
+
const queryString = searchParams.toString();
|
|
6446
|
+
return this.request(`/workflows/run-counts${queryString ? `?${queryString}` : ""}`);
|
|
6447
|
+
}
|
|
6448
|
+
/**
|
|
6368
6449
|
* Gets a workflow instance by ID
|
|
6369
6450
|
* @param workflowId - ID of the workflow to retrieve
|
|
6370
6451
|
* @returns Workflow instance
|
|
@@ -6516,6 +6597,13 @@ var MastraClient = class extends BaseResource {
|
|
|
6516
6597
|
return new A2A(this.options, agentId);
|
|
6517
6598
|
}
|
|
6518
6599
|
/**
|
|
6600
|
+
* Gets an A2A Protocol v1.0 client for an agent.
|
|
6601
|
+
* @param agentId - ID of the agent to interact with
|
|
6602
|
+
*/
|
|
6603
|
+
getA2AV1(agentId) {
|
|
6604
|
+
return new A2AV1(this.options, agentId);
|
|
6605
|
+
}
|
|
6606
|
+
/**
|
|
6519
6607
|
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
6520
6608
|
* @param agentId - ID of the agent.
|
|
6521
6609
|
* @param threadId - ID of the thread.
|
|
@@ -6827,11 +6915,11 @@ var MastraClient = class extends BaseResource {
|
|
|
6827
6915
|
return new StoredAgent(this.options, storedAgentId);
|
|
6828
6916
|
}
|
|
6829
6917
|
/**
|
|
6830
|
-
* Lists
|
|
6918
|
+
* Lists dynamic workflow definitions, optionally filtered by status or author
|
|
6831
6919
|
* @param params - Optional filters: `status` ('active' | 'archived') and `authorId`
|
|
6832
6920
|
* @returns Promise containing the matching definitions and a total count
|
|
6833
6921
|
*/
|
|
6834
|
-
|
|
6922
|
+
listDynamicWorkflows(params) {
|
|
6835
6923
|
const searchParams = new URLSearchParams();
|
|
6836
6924
|
if (params?.status) searchParams.set("status", params.status);
|
|
6837
6925
|
if (params?.authorId) searchParams.set("authorId", params.authorId);
|
|
@@ -6839,26 +6927,26 @@ var MastraClient = class extends BaseResource {
|
|
|
6839
6927
|
return this.request(`/stored/workflows${queryString ? `?${queryString}` : ""}`);
|
|
6840
6928
|
}
|
|
6841
6929
|
/**
|
|
6842
|
-
* Creates or replaces a
|
|
6930
|
+
* Creates or replaces a dynamic workflow definition and live-registers it on the server.
|
|
6843
6931
|
* Optional `dependencies` lets helper workflows referenced by the root definition be
|
|
6844
6932
|
* saved in the same request; their ids are echoed back as `dependencyIds`.
|
|
6845
6933
|
* @param params - The workflow definition (id, schemas, graph) plus optional helper dependencies
|
|
6846
6934
|
* @returns Promise containing the persisted definition and any dependency ids
|
|
6847
6935
|
*/
|
|
6848
|
-
|
|
6936
|
+
upsertDynamicWorkflow(params) {
|
|
6849
6937
|
return this.request("/stored/workflows", {
|
|
6850
6938
|
method: "POST",
|
|
6851
6939
|
body: params
|
|
6852
6940
|
});
|
|
6853
6941
|
}
|
|
6854
6942
|
/**
|
|
6855
|
-
* Gets a
|
|
6856
|
-
* To execute a
|
|
6857
|
-
* @param
|
|
6858
|
-
* @returns
|
|
6943
|
+
* Gets a dynamic workflow instance by ID for further operations (details, delete).
|
|
6944
|
+
* To execute a dynamic workflow, use `getWorkflow(id).createRun()` like any other workflow.
|
|
6945
|
+
* @param dynamicWorkflowId - ID of the dynamic workflow definition
|
|
6946
|
+
* @returns DynamicWorkflow instance
|
|
6859
6947
|
*/
|
|
6860
|
-
|
|
6861
|
-
return new
|
|
6948
|
+
getDynamicWorkflow(dynamicWorkflowId) {
|
|
6949
|
+
return new DynamicWorkflow(this.options, dynamicWorkflowId);
|
|
6862
6950
|
}
|
|
6863
6951
|
/**
|
|
6864
6952
|
* Lists all stored prompt blocks with optional pagination
|