@mastra/client-js 0.1.0-alpha.17 → 0.1.0-alpha.18

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.
@@ -0,0 +1,15 @@
1
+
2
+ > @mastra/client-js@0.1.0-alpha.18 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
+ > tsup-node src/index.ts --format esm --dts --clean --treeshake
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.3.6
8
+ CLI Target: es2022
9
+ CLI Cleaning output folder
10
+ ESM Build start
11
+ ESM dist/index.mjs 13.06 KB
12
+ ESM ⚡️ Build success in 617ms
13
+ DTS Build start
14
+ DTS ⚡️ Build success in 9243ms
15
+ DTS dist/index.d.mts 13.46 KB
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @mastra/client-js
2
+
3
+ ## 0.1.0-alpha.18
4
+
5
+ ### Patch Changes
6
+
7
+ - b9ef5fd: Add workflow watch and resume to client sdk
package/README.md CHANGED
@@ -15,20 +15,20 @@ import { MastraClient } from '@mastra/client';
15
15
 
16
16
  // Initialize the client
17
17
  const client = new MastraClient({
18
- baseUrl: 'http://localhost:4111', // Your Mastra API endpoint
18
+ baseUrl: 'http://localhost:4111', // Your Mastra API endpoint
19
19
  });
20
20
 
21
21
  // Example: Working with an Agent
22
22
  async function main() {
23
- // Get an agent instance
24
- const agent = client.getAgent('your-agent-id');
25
-
26
- // Generate a response
27
- const response = await agent.generate({
28
- messages: [{ role: 'user', content: "What's the weather like today?" }],
29
- });
30
-
31
- console.log(response);
23
+ // Get an agent instance
24
+ const agent = client.getAgent('your-agent-id');
25
+
26
+ // Generate a response
27
+ const response = await agent.generate({
28
+ messages: [{ role: 'user', content: "What's the weather like today?" }],
29
+ });
30
+
31
+ console.log(response);
32
32
  }
33
33
  ```
34
34
 
@@ -49,6 +49,7 @@ const client = new MastraClient({
49
49
  ## Available Methods
50
50
 
51
51
  ### Agents
52
+
52
53
  - `getAgents()`: Get all available agents
53
54
  - `getAgent(agentId)`: Get a specific agent instance
54
55
  - `agent.details()`: Get agent details
@@ -59,6 +60,7 @@ const client = new MastraClient({
59
60
  - `agent.liveEvals()`: Get live evaluations
60
61
 
61
62
  ### Memory
63
+
62
64
  - `getMemoryThreads(params)`: Get memory threads
63
65
  - `createMemoryThread(params)`: Create a new memory thread
64
66
  - `getMemoryThread(threadId)`: Get a memory thread instance
@@ -66,18 +68,23 @@ const client = new MastraClient({
66
68
  - `getMemoryStatus()`: Get memory system status
67
69
 
68
70
  ### Tools
71
+
69
72
  - `getTools()`: Get all available tools
70
73
  - `getTool(toolId)`: Get a tool instance
71
74
  - `tool.details()`: Get tool details
72
75
  - `tool.execute(params)`: Execute the tool
73
76
 
74
77
  ### Workflows
78
+
75
79
  - `getWorkflows()`: Get all workflows
76
80
  - `getWorkflow(workflowId)`: Get a workflow instance
77
81
  - `workflow.details()`: Get workflow details
78
82
  - `workflow.execute(params)`: Execute the workflow
83
+ - `workflow.watch(params)`: Watch the workflow
84
+ - `workflow.resume(params)`: Resume the workflow
79
85
 
80
86
  ### Vectors
87
+
81
88
  - `getVector(vectorName)`: Get a vector instance
82
89
  - `vector.details(indexName)`: Get vector index details
83
90
  - `vector.delete(indexName)`: Delete a vector index
@@ -87,15 +94,18 @@ const client = new MastraClient({
87
94
  - `vector.query(params)`: Query vectors
88
95
 
89
96
  ### Logs
97
+
90
98
  - `getLogs(params)`: Get system logs
91
99
  - `getLog(params)`: Get specific log entry
92
100
 
93
101
  ### Telemetry
102
+
94
103
  - `getTelemetry(params)`: Get telemetry data
95
104
 
96
105
  ## Error Handling
97
106
 
98
107
  The client includes built-in retry logic for failed requests:
108
+
99
109
  - Automatically retries failed requests with exponential backoff
100
110
  - Configurable retry count and backoff timing
101
111
  - Throws error after max retries reached
@@ -103,6 +113,7 @@ The client includes built-in retry logic for failed requests:
103
113
  ## Internal Implementation
104
114
 
105
115
  The client uses the native `fetch` API internally for making HTTP requests. All requests are automatically handled with:
116
+
106
117
  - JSON serialization/deserialization
107
118
  - Retry logic with exponential backoff
108
119
  - Custom header management
package/dist/index.d.mts CHANGED
@@ -266,6 +266,23 @@ declare class Workflow extends BaseResource {
266
266
  * @returns Promise containing the workflow execution results
267
267
  */
268
268
  execute(params: Record<string, any>): Promise<Record<string, any>>;
269
+ /**
270
+ * Resumes a suspended workflow step
271
+ * @param stepId - ID of the step to resume
272
+ * @param runId - ID of the workflow run
273
+ * @param context - Context to resume the workflow with
274
+ * @returns Promise containing the workflow resume results
275
+ */
276
+ resume({ stepId, runId, context, }: {
277
+ stepId: string;
278
+ runId: string;
279
+ context: Record<string, any>;
280
+ }): Promise<Record<string, any>>;
281
+ /**
282
+ * Watches workflow transitions in real-time
283
+ * @returns Promise containing the workflow watch stream
284
+ */
285
+ watch(): Promise<Response>;
269
286
  }
270
287
 
271
288
  declare class Tool extends BaseResource {
package/dist/index.mjs CHANGED
@@ -262,6 +262,36 @@ var Workflow = class extends BaseResource {
262
262
  body: params
263
263
  });
264
264
  }
265
+ /**
266
+ * Resumes a suspended workflow step
267
+ * @param stepId - ID of the step to resume
268
+ * @param runId - ID of the workflow run
269
+ * @param context - Context to resume the workflow with
270
+ * @returns Promise containing the workflow resume results
271
+ */
272
+ resume({
273
+ stepId,
274
+ runId,
275
+ context
276
+ }) {
277
+ return this.request(`/api/workflows/${this.workflowId}/resume`, {
278
+ method: "POST",
279
+ body: {
280
+ stepId,
281
+ runId,
282
+ context
283
+ }
284
+ });
285
+ }
286
+ /**
287
+ * Watches workflow transitions in real-time
288
+ * @returns Promise containing the workflow watch stream
289
+ */
290
+ watch() {
291
+ return this.request(`/api/workflows/${this.workflowId}/watch`, {
292
+ stream: true
293
+ });
294
+ }
265
295
  };
266
296
 
267
297
  // src/resources/tool.ts
@@ -0,0 +1,6 @@
1
+ import { createConfig } from '@internal/lint/eslint';
2
+
3
+ const config = await createConfig();
4
+
5
+ /** @type {import("eslint").Linter.Config[]} */
6
+ export default [...config];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.0-alpha.17",
3
+ "version": "0.1.0-alpha.18",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "types": "dist/index.d.mts",
@@ -16,16 +16,11 @@
16
16
  },
17
17
  "repository": "github:mastra-ai/client-js",
18
18
  "license": "ISC",
19
- "scripts": {
20
- "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
21
- "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
22
- "test": "vitest run"
23
- },
24
19
  "dependencies": {
25
- "@mastra/core": "^0.2.0-alpha.83",
26
20
  "json-schema": "^0.4.0",
27
21
  "zod": "^3.24.1",
28
- "zod-to-json-schema": "^3.24.1"
22
+ "zod-to-json-schema": "^3.24.1",
23
+ "@mastra/core": "^0.2.1"
29
24
  },
30
25
  "devDependencies": {
31
26
  "@babel/preset-env": "^7.26.0",
@@ -35,6 +30,12 @@
35
30
  "@types/node": "^22.9.0",
36
31
  "tsup": "^8.0.1",
37
32
  "typescript": "^5.7.3",
38
- "vitest": "^3.0.4"
33
+ "vitest": "^3.0.4",
34
+ "@internal/lint": "0.0.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
38
+ "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
39
+ "test": "vitest run"
39
40
  }
40
- }
41
+ }
package/src/client.ts CHANGED
@@ -1,158 +1,173 @@
1
- import type { ClientOptions, CreateMemoryThreadParams, CreateMemoryThreadResponse, GetAgentResponse, GetLogParams, GetLogsParams, GetLogsResponse, GetMemoryThreadParams, GetMemoryThreadResponse, GetTelemetryParams, GetTelemetryResponse, GetToolResponse, GetWorkflowResponse, RequestOptions, SaveMessageToMemoryParams, SaveMessageToMemoryResponse } from './types';
2
1
  import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource } from './resources';
2
+ import type {
3
+ ClientOptions,
4
+ CreateMemoryThreadParams,
5
+ CreateMemoryThreadResponse,
6
+ GetAgentResponse,
7
+ GetLogParams,
8
+ GetLogsParams,
9
+ GetLogsResponse,
10
+ GetMemoryThreadParams,
11
+ GetMemoryThreadResponse,
12
+ GetTelemetryParams,
13
+ GetTelemetryResponse,
14
+ GetToolResponse,
15
+ GetWorkflowResponse,
16
+ RequestOptions,
17
+ SaveMessageToMemoryParams,
18
+ SaveMessageToMemoryResponse,
19
+ } from './types';
3
20
 
4
21
  export class MastraClient extends BaseResource {
5
-
6
- constructor(options: ClientOptions) {
7
- super(options);
8
- }
9
-
10
-
11
- /**
12
- * Retrieves all available agents
13
- * @returns Promise containing map of agent IDs to agent details
14
- */
15
- public getAgents(): Promise<Record<string, GetAgentResponse>> {
16
- return this.request('/api/agents');
17
- }
18
-
19
- /**
20
- * Gets an agent instance by ID
21
- * @param agentId - ID of the agent to retrieve
22
- * @returns Agent instance
23
- */
24
- public getAgent(agentId: string) {
25
- return new Agent(this.options, agentId);
26
- }
27
-
28
- /**
29
- * Retrieves memory threads for a resource
30
- * @param params - Parameters containing the resource ID
31
- * @returns Promise containing array of memory threads
32
- */
33
- public getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse> {
34
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
35
- }
36
-
37
- /**
38
- * Creates a new memory thread
39
- * @param params - Parameters for creating the memory thread
40
- * @returns Promise containing the created memory thread
41
- */
42
- public createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
43
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: 'POST', body: params });
44
- }
45
-
46
- /**
47
- * Gets a memory thread instance by ID
48
- * @param threadId - ID of the memory thread to retrieve
49
- * @returns MemoryThread instance
50
- */
51
- public getMemoryThread(threadId: string, agentId: string) {
52
- return new MemoryThread(this.options, threadId, agentId);
53
- }
54
-
55
- /**
56
- * Saves messages to memory
57
- * @param params - Parameters containing messages to save
58
- * @returns Promise containing the saved messages
59
- */
60
- public saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
61
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
62
- method: 'POST',
63
- body: params,
64
- });
65
- }
66
-
67
- /**
68
- * Gets the status of the memory system
69
- * @returns Promise containing memory system status
70
- */
71
- public getMemoryStatus(agentId: string): Promise<{ result: boolean }> {
72
- return this.request(`/api/memory/status?agentId=${agentId}`);
73
- }
74
-
75
- /**
76
- * Retrieves all available tools
77
- * @returns Promise containing map of tool IDs to tool details
78
- */
79
- public getTools(): Promise<Record<string, GetToolResponse>> {
80
- return this.request('/api/tools');
81
- }
82
-
83
- /**
84
- * Gets a tool instance by ID
85
- * @param toolId - ID of the tool to retrieve
86
- * @returns Tool instance
87
- */
88
- public getTool(toolId: string) {
89
- return new Tool(this.options, toolId);
90
- }
91
-
92
- /**
93
- * Retrieves all available workflows
94
- * @returns Promise containing map of workflow IDs to workflow details
95
- */
96
- public getWorkflows(): Promise<Record<string, GetWorkflowResponse>> {
97
- return this.request('/api/workflows');
98
- }
99
-
100
- /**
101
- * Gets a workflow instance by ID
102
- * @param workflowId - ID of the workflow to retrieve
103
- * @returns Workflow instance
104
- */
105
- public getWorkflow(workflowId: string) {
106
- return new Workflow(this.options, workflowId);
107
- }
108
-
109
- /**
110
- * Gets a vector instance by name
111
- * @param vectorName - Name of the vector to retrieve
112
- * @returns Vector instance
113
- */
114
- public getVector(vectorName: string) {
115
- return new Vector(this.options, vectorName);
116
- }
117
-
118
- /**
119
- * Retrieves logs
120
- * @param params - Parameters for filtering logs
121
- * @returns Promise containing array of log messages
122
- */
123
- public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
124
- return this.request(`/api/logs?transportId=${params.transportId}`);
125
- }
126
-
127
- /**
128
- * Gets logs for a specific run
129
- * @param params - Parameters containing run ID to retrieve
130
- * @returns Promise containing array of log messages
131
- */
132
- public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
133
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
134
- }
135
-
136
- /**
137
- * List of all traces (paged)
138
- * @param params - Parameters for filtering traces
139
- * @returns Promise containing telemetry data
140
- */
141
- public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
142
- const { name, scope, page, perPage, attribute } = params || {};
143
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
144
-
145
- const queryObj = {
146
- ...(name ? { name } : {}),
147
- ...(scope ? { scope } : {}),
148
- ...(page ? { page: String(page) } : {}),
149
- ...(perPage ? { perPage: String(perPage) } : {}),
150
- ...(_attribute?.length ? { attribute: _attribute } : {})
151
- }
152
-
153
- const hasQueryParams = Object.keys(queryObj).length > 0;
154
-
155
- const queryParams = hasQueryParams ? new URLSearchParams(queryObj) : '';
156
- return this.request(`/api/telemetry?${queryParams}`);
157
- }
158
- }
22
+ constructor(options: ClientOptions) {
23
+ super(options);
24
+ }
25
+
26
+ /**
27
+ * Retrieves all available agents
28
+ * @returns Promise containing map of agent IDs to agent details
29
+ */
30
+ public getAgents(): Promise<Record<string, GetAgentResponse>> {
31
+ return this.request('/api/agents');
32
+ }
33
+
34
+ /**
35
+ * Gets an agent instance by ID
36
+ * @param agentId - ID of the agent to retrieve
37
+ * @returns Agent instance
38
+ */
39
+ public getAgent(agentId: string) {
40
+ return new Agent(this.options, agentId);
41
+ }
42
+
43
+ /**
44
+ * Retrieves memory threads for a resource
45
+ * @param params - Parameters containing the resource ID
46
+ * @returns Promise containing array of memory threads
47
+ */
48
+ public getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse> {
49
+ return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
50
+ }
51
+
52
+ /**
53
+ * Creates a new memory thread
54
+ * @param params - Parameters for creating the memory thread
55
+ * @returns Promise containing the created memory thread
56
+ */
57
+ public createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
58
+ return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: 'POST', body: params });
59
+ }
60
+
61
+ /**
62
+ * Gets a memory thread instance by ID
63
+ * @param threadId - ID of the memory thread to retrieve
64
+ * @returns MemoryThread instance
65
+ */
66
+ public getMemoryThread(threadId: string, agentId: string) {
67
+ return new MemoryThread(this.options, threadId, agentId);
68
+ }
69
+
70
+ /**
71
+ * Saves messages to memory
72
+ * @param params - Parameters containing messages to save
73
+ * @returns Promise containing the saved messages
74
+ */
75
+ public saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
76
+ return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
77
+ method: 'POST',
78
+ body: params,
79
+ });
80
+ }
81
+
82
+ /**
83
+ * Gets the status of the memory system
84
+ * @returns Promise containing memory system status
85
+ */
86
+ public getMemoryStatus(agentId: string): Promise<{ result: boolean }> {
87
+ return this.request(`/api/memory/status?agentId=${agentId}`);
88
+ }
89
+
90
+ /**
91
+ * Retrieves all available tools
92
+ * @returns Promise containing map of tool IDs to tool details
93
+ */
94
+ public getTools(): Promise<Record<string, GetToolResponse>> {
95
+ return this.request('/api/tools');
96
+ }
97
+
98
+ /**
99
+ * Gets a tool instance by ID
100
+ * @param toolId - ID of the tool to retrieve
101
+ * @returns Tool instance
102
+ */
103
+ public getTool(toolId: string) {
104
+ return new Tool(this.options, toolId);
105
+ }
106
+
107
+ /**
108
+ * Retrieves all available workflows
109
+ * @returns Promise containing map of workflow IDs to workflow details
110
+ */
111
+ public getWorkflows(): Promise<Record<string, GetWorkflowResponse>> {
112
+ return this.request('/api/workflows');
113
+ }
114
+
115
+ /**
116
+ * Gets a workflow instance by ID
117
+ * @param workflowId - ID of the workflow to retrieve
118
+ * @returns Workflow instance
119
+ */
120
+ public getWorkflow(workflowId: string) {
121
+ return new Workflow(this.options, workflowId);
122
+ }
123
+
124
+ /**
125
+ * Gets a vector instance by name
126
+ * @param vectorName - Name of the vector to retrieve
127
+ * @returns Vector instance
128
+ */
129
+ public getVector(vectorName: string) {
130
+ return new Vector(this.options, vectorName);
131
+ }
132
+
133
+ /**
134
+ * Retrieves logs
135
+ * @param params - Parameters for filtering logs
136
+ * @returns Promise containing array of log messages
137
+ */
138
+ public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
139
+ return this.request(`/api/logs?transportId=${params.transportId}`);
140
+ }
141
+
142
+ /**
143
+ * Gets logs for a specific run
144
+ * @param params - Parameters containing run ID to retrieve
145
+ * @returns Promise containing array of log messages
146
+ */
147
+ public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
148
+ return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
149
+ }
150
+
151
+ /**
152
+ * List of all traces (paged)
153
+ * @param params - Parameters for filtering traces
154
+ * @returns Promise containing telemetry data
155
+ */
156
+ public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
157
+ const { name, scope, page, perPage, attribute } = params || {};
158
+ const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
159
+
160
+ const queryObj = {
161
+ ...(name ? { name } : {}),
162
+ ...(scope ? { scope } : {}),
163
+ ...(page ? { page: String(page) } : {}),
164
+ ...(perPage ? { perPage: String(perPage) } : {}),
165
+ ...(_attribute?.length ? { attribute: _attribute } : {}),
166
+ };
167
+
168
+ const hasQueryParams = Object.keys(queryObj).length > 0;
169
+
170
+ const queryParams = hasQueryParams ? new URLSearchParams(queryObj) : '';
171
+ return this.request(`/api/telemetry?${queryParams}`);
172
+ }
173
+ }
package/src/example.ts CHANGED
@@ -1,43 +1,43 @@
1
- import { MastraClient } from "./client";
2
-
1
+ import { MastraClient } from './client';
3
2
 
4
3
  (async () => {
5
- const client = new MastraClient({
6
- baseUrl: 'http://localhost:4111',
4
+ const client = new MastraClient({
5
+ baseUrl: 'http://localhost:4111',
6
+ });
7
+
8
+ try {
9
+ const agent = client.getAgent('weatherAgent');
10
+ const response = await agent.stream({
11
+ messages: [
12
+ {
13
+ role: 'user',
14
+ content: 'Hello, world!',
15
+ },
16
+ ],
7
17
  });
8
18
 
9
- try {
10
- const agent = client.getAgent('weatherAgent');
11
- const response = await agent.stream({
12
- messages: [{
13
- role: 'user',
14
- content: 'Hello, world!',
15
- }]
16
- })
17
-
18
-
19
- const reader = response?.body?.getReader()
20
- const decoder = new TextDecoder()
21
- let buffer = ''
19
+ const reader = response?.body?.getReader();
20
+ const decoder = new TextDecoder();
21
+ let buffer = '';
22
22
 
23
- while (true) {
24
- if (!reader) break;
25
- const { value, done } = await reader.read()
26
- if (done) break;
23
+ while (true) {
24
+ if (!reader) break;
25
+ const { value, done } = await reader.read();
26
+ if (done) break;
27
27
 
28
- const chunk = decoder.decode(value);
29
- buffer += chunk;
28
+ const chunk = decoder.decode(value);
29
+ buffer += chunk;
30
30
 
31
- console.log(buffer);
31
+ console.log(buffer);
32
32
 
33
- const matches = buffer.matchAll(/0:"([^"]*)"/g);
33
+ const matches = buffer.matchAll(/0:"([^"]*)"/g);
34
34
 
35
- for (const match of matches) {
36
- const content = match[1];
37
- process.stdout.write(`${content}\n`);
38
- }
39
- }
40
- } catch (error) {
41
- console.error(error);
35
+ for (const match of matches) {
36
+ const content = match[1];
37
+ process.stdout.write(`${content}\n`);
38
+ }
42
39
  }
43
- })()
40
+ } catch (error) {
41
+ console.error(error);
42
+ }
43
+ })();