@mastra/client-js 0.0.0-commonjs-20250227130920
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 +19 -0
- package/CHANGELOG.md +111 -0
- package/LICENSE +44 -0
- package/README.md +125 -0
- package/dist/index.cjs +489 -0
- package/dist/index.d.cts +405 -0
- package/dist/index.d.ts +405 -0
- package/dist/index.js +487 -0
- package/eslint.config.js +6 -0
- package/package.json +46 -0
- package/src/client.ts +205 -0
- package/src/example.ts +43 -0
- package/src/index.test.ts +597 -0
- package/src/index.ts +2 -0
- package/src/resources/agent.ts +116 -0
- package/src/resources/base.ts +68 -0
- package/src/resources/index.ts +6 -0
- package/src/resources/memory-thread.ts +60 -0
- package/src/resources/tool.ts +32 -0
- package/src/resources/vector.ts +83 -0
- package/src/resources/workflow.ts +68 -0
- package/src/types.ts +163 -0
- package/tsconfig.json +5 -0
- package/vitest.config.js +8 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
> @mastra/client-js@0.1.5-alpha.0 build C:\Users\Ward\projects\mastra\mastra\client-sdks\client-js
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.3.6
|
|
8
|
+
[34mCLI[39m Target: es2022
|
|
9
|
+
[34mCLI[39m Cleaning output folder
|
|
10
|
+
[34mESM[39m Build start
|
|
11
|
+
[34mCJS[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist\index.cjs [22m[32m13.62 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 106ms
|
|
14
|
+
[32mESM[39m [1mdist\index.js [22m[32m13.56 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 106ms
|
|
16
|
+
[34mDTS[39m Build start
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 1301ms
|
|
18
|
+
[32mDTS[39m [1mdist\index.d.ts [22m[32m13.64 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist\index.d.cts [22m[32m13.64 KB[39m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @mastra/client-js
|
|
2
|
+
|
|
3
|
+
## 0.0.0-commonjs-20250227130920
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4a712fc: Add support for commonjs
|
|
8
|
+
- Updated dependencies [ed55f1d]
|
|
9
|
+
- Updated dependencies [06aa827]
|
|
10
|
+
- Updated dependencies [8d13b14]
|
|
11
|
+
- Updated dependencies [4a712fc]
|
|
12
|
+
- Updated dependencies [108793c]
|
|
13
|
+
- Updated dependencies [5f28f44]
|
|
14
|
+
- @mastra/core@0.0.0-commonjs-20250227130920
|
|
15
|
+
|
|
16
|
+
## 0.1.5-alpha.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [06aa827]
|
|
21
|
+
- @mastra/core@0.4.3-alpha.0
|
|
22
|
+
|
|
23
|
+
## 0.1.4
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [7fceae1]
|
|
28
|
+
- Updated dependencies [8d94c3e]
|
|
29
|
+
- Updated dependencies [99dcdb5]
|
|
30
|
+
- Updated dependencies [6cb63e0]
|
|
31
|
+
- Updated dependencies [f626fbb]
|
|
32
|
+
- Updated dependencies [e752340]
|
|
33
|
+
- Updated dependencies [eb91535]
|
|
34
|
+
- @mastra/core@0.4.2
|
|
35
|
+
|
|
36
|
+
## 0.1.4-alpha.2
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [8d94c3e]
|
|
41
|
+
- Updated dependencies [99dcdb5]
|
|
42
|
+
- Updated dependencies [e752340]
|
|
43
|
+
- Updated dependencies [eb91535]
|
|
44
|
+
- @mastra/core@0.4.2-alpha.2
|
|
45
|
+
|
|
46
|
+
## 0.1.4-alpha.1
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [6cb63e0]
|
|
51
|
+
- @mastra/core@0.4.2-alpha.1
|
|
52
|
+
|
|
53
|
+
## 0.1.4-alpha.0
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies [7fceae1]
|
|
58
|
+
- Updated dependencies [f626fbb]
|
|
59
|
+
- @mastra/core@0.4.2-alpha.0
|
|
60
|
+
|
|
61
|
+
## 0.1.3
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies [ce44b9b]
|
|
66
|
+
- Updated dependencies [967da43]
|
|
67
|
+
- Updated dependencies [b405f08]
|
|
68
|
+
- @mastra/core@0.4.1
|
|
69
|
+
|
|
70
|
+
## 0.1.2
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- 5297264: Fix build errors by changing contracts
|
|
75
|
+
- Updated dependencies [2fc618f]
|
|
76
|
+
- Updated dependencies [fe0fd01]
|
|
77
|
+
- @mastra/core@0.4.0
|
|
78
|
+
|
|
79
|
+
## 0.1.2-alpha.1
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies [fe0fd01]
|
|
84
|
+
- @mastra/core@0.4.0-alpha.1
|
|
85
|
+
|
|
86
|
+
## 0.1.2-alpha.0
|
|
87
|
+
|
|
88
|
+
### Patch Changes
|
|
89
|
+
|
|
90
|
+
- 5297264: Fix build errors by changing contracts
|
|
91
|
+
- Updated dependencies [2fc618f]
|
|
92
|
+
- @mastra/core@0.4.0-alpha.0
|
|
93
|
+
|
|
94
|
+
## 0.1.1
|
|
95
|
+
|
|
96
|
+
### Patch Changes
|
|
97
|
+
|
|
98
|
+
- Updated dependencies [f205ede]
|
|
99
|
+
- @mastra/core@0.3.0
|
|
100
|
+
|
|
101
|
+
## 0.1.0
|
|
102
|
+
|
|
103
|
+
### Patch Changes
|
|
104
|
+
|
|
105
|
+
- b9ef5fd: Add workflow watch and resume to client sdk
|
|
106
|
+
|
|
107
|
+
## 0.1.0-alpha.18
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- b9ef5fd: Add workflow watch and resume to client sdk
|
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Elastic License 2.0 (ELv2)
|
|
2
|
+
|
|
3
|
+
**Acceptance**
|
|
4
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
5
|
+
|
|
6
|
+
**Copyright License**
|
|
7
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
8
|
+
|
|
9
|
+
**Limitations**
|
|
10
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
11
|
+
|
|
12
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
13
|
+
|
|
14
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
15
|
+
|
|
16
|
+
**Patents**
|
|
17
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
18
|
+
|
|
19
|
+
**Notices**
|
|
20
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
21
|
+
|
|
22
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
23
|
+
|
|
24
|
+
**No Other Rights**
|
|
25
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
26
|
+
|
|
27
|
+
**Termination**
|
|
28
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
29
|
+
|
|
30
|
+
**No Liability**
|
|
31
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
32
|
+
|
|
33
|
+
**Definitions**
|
|
34
|
+
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
35
|
+
|
|
36
|
+
_you_ refers to the individual or entity agreeing to these terms.
|
|
37
|
+
|
|
38
|
+
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
39
|
+
|
|
40
|
+
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
41
|
+
|
|
42
|
+
_use_ means anything you do with the software requiring one of your licenses.
|
|
43
|
+
|
|
44
|
+
_trademark_ means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Mastra Client
|
|
2
|
+
|
|
3
|
+
JavaScript/TypeScript client library for the [Mastra AI](https://mastra.ai) framework. This client provides a simple interface to interact with Mastra AI's APIs for agents, vectors, memory, tools, and workflows.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/client-js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { MastraClient } from '@mastra/client';
|
|
15
|
+
|
|
16
|
+
// Initialize the client
|
|
17
|
+
const client = new MastraClient({
|
|
18
|
+
baseUrl: 'http://localhost:4111', // Your Mastra API endpoint
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Example: Working with an Agent
|
|
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);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Client Configuration
|
|
36
|
+
|
|
37
|
+
The client can be configured with several options:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const client = new MastraClient({
|
|
41
|
+
baseUrl: string; // Base URL for the Mastra API
|
|
42
|
+
retries?: number; // Number of retry attempts (default: 3)
|
|
43
|
+
backoffMs?: number; // Initial backoff time in ms (default: 300)
|
|
44
|
+
maxBackoffMs?: number; // Maximum backoff time in ms (default: 5000)
|
|
45
|
+
headers?: Record<string, string>; // Custom headers
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Available Methods
|
|
50
|
+
|
|
51
|
+
### Agents
|
|
52
|
+
|
|
53
|
+
- `getAgents()`: Get all available agents
|
|
54
|
+
- `getAgent(agentId)`: Get a specific agent instance
|
|
55
|
+
- `agent.details()`: Get agent details
|
|
56
|
+
- `agent.generate(params)`: Generate a response
|
|
57
|
+
- `agent.stream(params)`: Stream a response
|
|
58
|
+
- `agent.getTool(toolId)`: Get agent tool details
|
|
59
|
+
- `agent.evals()`: Get agent evaluations
|
|
60
|
+
- `agent.liveEvals()`: Get live evaluations
|
|
61
|
+
|
|
62
|
+
### Memory
|
|
63
|
+
|
|
64
|
+
- `getMemoryThreads(params)`: Get memory threads
|
|
65
|
+
- `createMemoryThread(params)`: Create a new memory thread
|
|
66
|
+
- `getMemoryThread(threadId)`: Get a memory thread instance
|
|
67
|
+
- `saveMessageToMemory(params)`: Save messages to memory
|
|
68
|
+
- `getMemoryStatus()`: Get memory system status
|
|
69
|
+
|
|
70
|
+
### Tools
|
|
71
|
+
|
|
72
|
+
- `getTools()`: Get all available tools
|
|
73
|
+
- `getTool(toolId)`: Get a tool instance
|
|
74
|
+
- `tool.details()`: Get tool details
|
|
75
|
+
- `tool.execute(params)`: Execute the tool
|
|
76
|
+
|
|
77
|
+
### Workflows
|
|
78
|
+
|
|
79
|
+
- `getWorkflows()`: Get all workflows
|
|
80
|
+
- `getWorkflow(workflowId)`: Get a workflow instance
|
|
81
|
+
- `workflow.details()`: Get workflow details
|
|
82
|
+
- `workflow.execute(params)`: Execute the workflow
|
|
83
|
+
- `workflow.watch(params)`: Watch the workflow
|
|
84
|
+
- `workflow.resume(params)`: Resume the workflow
|
|
85
|
+
|
|
86
|
+
### Vectors
|
|
87
|
+
|
|
88
|
+
- `getVector(vectorName)`: Get a vector instance
|
|
89
|
+
- `vector.details(indexName)`: Get vector index details
|
|
90
|
+
- `vector.delete(indexName)`: Delete a vector index
|
|
91
|
+
- `vector.getIndexes()`: Get all indexes
|
|
92
|
+
- `vector.createIndex(params)`: Create a new index
|
|
93
|
+
- `vector.upsert(params)`: Upsert vectors
|
|
94
|
+
- `vector.query(params)`: Query vectors
|
|
95
|
+
|
|
96
|
+
### Logs
|
|
97
|
+
|
|
98
|
+
- `getLogs(params)`: Get system logs
|
|
99
|
+
- `getLog(params)`: Get specific log entry
|
|
100
|
+
- `getLogTransports()`: Get configured Log transports
|
|
101
|
+
|
|
102
|
+
### Telemetry
|
|
103
|
+
|
|
104
|
+
- `getTelemetry(params)`: Get telemetry data
|
|
105
|
+
|
|
106
|
+
## Error Handling
|
|
107
|
+
|
|
108
|
+
The client includes built-in retry logic for failed requests:
|
|
109
|
+
|
|
110
|
+
- Automatically retries failed requests with exponential backoff
|
|
111
|
+
- Configurable retry count and backoff timing
|
|
112
|
+
- Throws error after max retries reached
|
|
113
|
+
|
|
114
|
+
## Internal Implementation
|
|
115
|
+
|
|
116
|
+
The client uses the native `fetch` API internally for making HTTP requests. All requests are automatically handled with:
|
|
117
|
+
|
|
118
|
+
- JSON serialization/deserialization
|
|
119
|
+
- Retry logic with exponential backoff
|
|
120
|
+
- Custom header management
|
|
121
|
+
- Error handling
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|