@mastra/client-js 0.1.0-alpha.2 → 0.1.0-alpha.4
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/.eslintrc.js +10 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +26 -0
- package/LICENSE +44 -201
- package/README.md +90 -271
- package/dist/index.d.mts +359 -0
- package/dist/index.mjs +399 -0
- package/package.json +30 -95
- package/src/client.ts +201 -0
- package/src/index.test.ts +528 -0
- package/src/index.ts +2 -200
- package/src/resources/agent.ts +97 -0
- package/src/resources/index.ts +5 -14
- package/src/resources/memory-thread.ts +51 -0
- package/src/resources/tool.ts +28 -0
- package/src/resources/vector.ts +79 -0
- package/src/resources/workflow.ts +28 -0
- package/src/types.ts +135 -0
- package/tsconfig.json +29 -0
- package/vitest.config.js +8 -0
- package/CHANGELOG.md +0 -29
- package/_shims/MultipartBody.d.ts +0 -9
- package/_shims/MultipartBody.d.ts.map +0 -1
- package/_shims/MultipartBody.js +0 -16
- package/_shims/MultipartBody.js.map +0 -1
- package/_shims/MultipartBody.mjs +0 -12
- package/_shims/MultipartBody.mjs.map +0 -1
- package/_shims/README.md +0 -46
- package/_shims/auto/runtime-bun.d.ts +0 -5
- package/_shims/auto/runtime-bun.d.ts.map +0 -1
- package/_shims/auto/runtime-bun.js +0 -21
- package/_shims/auto/runtime-bun.js.map +0 -1
- package/_shims/auto/runtime-bun.mjs +0 -2
- package/_shims/auto/runtime-bun.mjs.map +0 -1
- package/_shims/auto/runtime-node.d.ts +0 -5
- package/_shims/auto/runtime-node.d.ts.map +0 -1
- package/_shims/auto/runtime-node.js +0 -21
- package/_shims/auto/runtime-node.js.map +0 -1
- package/_shims/auto/runtime-node.mjs +0 -2
- package/_shims/auto/runtime-node.mjs.map +0 -1
- package/_shims/auto/runtime.d.ts +0 -5
- package/_shims/auto/runtime.d.ts.map +0 -1
- package/_shims/auto/runtime.js +0 -21
- package/_shims/auto/runtime.js.map +0 -1
- package/_shims/auto/runtime.mjs +0 -2
- package/_shims/auto/runtime.mjs.map +0 -1
- package/_shims/auto/types-node.d.ts +0 -5
- package/_shims/auto/types-node.d.ts.map +0 -1
- package/_shims/auto/types-node.js +0 -21
- package/_shims/auto/types-node.js.map +0 -1
- package/_shims/auto/types-node.mjs +0 -2
- package/_shims/auto/types-node.mjs.map +0 -1
- package/_shims/auto/types.d.ts +0 -101
- package/_shims/auto/types.js +0 -3
- package/_shims/auto/types.mjs +0 -3
- package/_shims/bun-runtime.d.ts +0 -6
- package/_shims/bun-runtime.d.ts.map +0 -1
- package/_shims/bun-runtime.js +0 -14
- package/_shims/bun-runtime.js.map +0 -1
- package/_shims/bun-runtime.mjs +0 -10
- package/_shims/bun-runtime.mjs.map +0 -1
- package/_shims/index.d.ts +0 -81
- package/_shims/index.js +0 -13
- package/_shims/index.mjs +0 -7
- package/_shims/manual-types.d.ts +0 -12
- package/_shims/manual-types.js +0 -3
- package/_shims/manual-types.mjs +0 -3
- package/_shims/node-runtime.d.ts +0 -3
- package/_shims/node-runtime.d.ts.map +0 -1
- package/_shims/node-runtime.js +0 -89
- package/_shims/node-runtime.js.map +0 -1
- package/_shims/node-runtime.mjs +0 -56
- package/_shims/node-runtime.mjs.map +0 -1
- package/_shims/node-types.d.ts +0 -42
- package/_shims/node-types.js +0 -3
- package/_shims/node-types.mjs +0 -3
- package/_shims/registry.d.ts +0 -37
- package/_shims/registry.d.ts.map +0 -1
- package/_shims/registry.js +0 -41
- package/_shims/registry.js.map +0 -1
- package/_shims/registry.mjs +0 -37
- package/_shims/registry.mjs.map +0 -1
- package/_shims/web-runtime.d.ts +0 -5
- package/_shims/web-runtime.d.ts.map +0 -1
- package/_shims/web-runtime.js +0 -78
- package/_shims/web-runtime.js.map +0 -1
- package/_shims/web-runtime.mjs +0 -71
- package/_shims/web-runtime.mjs.map +0 -1
- package/_shims/web-types.d.ts +0 -83
- package/_shims/web-types.js +0 -3
- package/_shims/web-types.mjs +0 -3
- package/core.d.ts +0 -241
- package/core.d.ts.map +0 -1
- package/core.js +0 -908
- package/core.js.map +0 -1
- package/core.mjs +0 -876
- package/core.mjs.map +0 -1
- package/error.d.ts +0 -47
- package/error.d.ts.map +0 -1
- package/error.js +0 -113
- package/error.js.map +0 -1
- package/error.mjs +0 -97
- package/error.mjs.map +0 -1
- package/index.d.mts +0 -121
- package/index.d.ts +0 -121
- package/index.d.ts.map +0 -1
- package/index.js +0 -131
- package/index.js.map +0 -1
- package/index.mjs +0 -88
- package/index.mjs.map +0 -1
- package/resource.d.ts +0 -6
- package/resource.d.ts.map +0 -1
- package/resource.js +0 -11
- package/resource.js.map +0 -1
- package/resource.mjs +0 -7
- package/resource.mjs.map +0 -1
- package/resources/agents/agents.d.ts +0 -41
- package/resources/agents/agents.d.ts.map +0 -1
- package/resources/agents/agents.js +0 -74
- package/resources/agents/agents.js.map +0 -1
- package/resources/agents/agents.mjs +0 -47
- package/resources/agents/agents.mjs.map +0 -1
- package/resources/agents/index.d.ts +0 -3
- package/resources/agents/index.d.ts.map +0 -1
- package/resources/agents/index.js +0 -9
- package/resources/agents/index.js.map +0 -1
- package/resources/agents/index.mjs +0 -4
- package/resources/agents/index.mjs.map +0 -1
- package/resources/agents/tools.d.ts +0 -17
- package/resources/agents/tools.d.ts.map +0 -1
- package/resources/agents/tools.js +0 -19
- package/resources/agents/tools.js.map +0 -1
- package/resources/agents/tools.mjs +0 -15
- package/resources/agents/tools.mjs.map +0 -1
- package/resources/index.d.ts +0 -8
- package/resources/index.d.ts.map +0 -1
- package/resources/index.js +0 -19
- package/resources/index.js.map +0 -1
- package/resources/index.mjs +0 -9
- package/resources/index.mjs.map +0 -1
- package/resources/logs.d.ts +0 -13
- package/resources/logs.d.ts.map +0 -1
- package/resources/logs.js +0 -24
- package/resources/logs.js.map +0 -1
- package/resources/logs.mjs +0 -20
- package/resources/logs.mjs.map +0 -1
- package/resources/memory/index.d.ts +0 -4
- package/resources/memory/index.d.ts.map +0 -1
- package/resources/memory/index.js +0 -11
- package/resources/memory/index.js.map +0 -1
- package/resources/memory/index.mjs +0 -5
- package/resources/memory/index.mjs.map +0 -1
- package/resources/memory/memory.d.ts +0 -23
- package/resources/memory/memory.d.ts.map +0 -1
- package/resources/memory/memory.js +0 -53
- package/resources/memory/memory.js.map +0 -1
- package/resources/memory/memory.mjs +0 -26
- package/resources/memory/memory.mjs.map +0 -1
- package/resources/memory/status.d.ts +0 -9
- package/resources/memory/status.d.ts.map +0 -1
- package/resources/memory/status.js +0 -18
- package/resources/memory/status.js.map +0 -1
- package/resources/memory/status.mjs +0 -14
- package/resources/memory/status.mjs.map +0 -1
- package/resources/memory/threads/index.d.ts +0 -3
- package/resources/memory/threads/index.d.ts.map +0 -1
- package/resources/memory/threads/index.js +0 -9
- package/resources/memory/threads/index.js.map +0 -1
- package/resources/memory/threads/index.mjs +0 -4
- package/resources/memory/threads/index.mjs.map +0 -1
- package/resources/memory/threads/messages.d.ts +0 -9
- package/resources/memory/threads/messages.d.ts.map +0 -1
- package/resources/memory/threads/messages.js +0 -18
- package/resources/memory/threads/messages.js.map +0 -1
- package/resources/memory/threads/messages.mjs +0 -14
- package/resources/memory/threads/messages.mjs.map +0 -1
- package/resources/memory/threads/threads.d.ts +0 -45
- package/resources/memory/threads/threads.d.ts.map +0 -1
- package/resources/memory/threads/threads.js +0 -104
- package/resources/memory/threads/threads.js.map +0 -1
- package/resources/memory/threads/threads.mjs +0 -77
- package/resources/memory/threads/threads.mjs.map +0 -1
- package/resources/syncs.d.ts +0 -15
- package/resources/syncs.d.ts.map +0 -1
- package/resources/syncs.js +0 -19
- package/resources/syncs.js.map +0 -1
- package/resources/syncs.mjs +0 -15
- package/resources/syncs.mjs.map +0 -1
- package/resources/system.d.ts +0 -9
- package/resources/system.d.ts.map +0 -1
- package/resources/system.js +0 -15
- package/resources/system.js.map +0 -1
- package/resources/system.mjs +0 -11
- package/resources/system.mjs.map +0 -1
- package/resources/tools/index.d.ts +0 -3
- package/resources/tools/index.d.ts.map +0 -1
- package/resources/tools/index.js +0 -9
- package/resources/tools/index.js.map +0 -1
- package/resources/tools/index.mjs +0 -4
- package/resources/tools/index.mjs.map +0 -1
- package/resources/tools/result.d.ts +0 -9
- package/resources/tools/result.d.ts.map +0 -1
- package/resources/tools/result.js +0 -18
- package/resources/tools/result.js.map +0 -1
- package/resources/tools/result.mjs +0 -14
- package/resources/tools/result.mjs.map +0 -1
- package/resources/tools/tools.d.ts +0 -29
- package/resources/tools/tools.d.ts.map +0 -1
- package/resources/tools/tools.js +0 -64
- package/resources/tools/tools.js.map +0 -1
- package/resources/tools/tools.mjs +0 -37
- package/resources/tools/tools.mjs.map +0 -1
- package/resources/workflows.d.ts +0 -23
- package/resources/workflows.d.ts.map +0 -1
- package/resources/workflows.js +0 -37
- package/resources/workflows.js.map +0 -1
- package/resources/workflows.mjs +0 -33
- package/resources/workflows.mjs.map +0 -1
- package/shims/node.d.ts +0 -30
- package/shims/node.d.ts.map +0 -1
- package/shims/node.js +0 -31
- package/shims/node.js.map +0 -1
- package/shims/node.mjs +0 -5
- package/shims/node.mjs.map +0 -1
- package/shims/web.d.ts +0 -26
- package/shims/web.d.ts.map +0 -1
- package/shims/web.js +0 -31
- package/shims/web.js.map +0 -1
- package/shims/web.mjs +0 -5
- package/shims/web.mjs.map +0 -1
- package/src/_shims/MultipartBody.ts +0 -9
- package/src/_shims/README.md +0 -46
- package/src/_shims/auto/runtime-bun.ts +0 -4
- package/src/_shims/auto/runtime-node.ts +0 -4
- package/src/_shims/auto/runtime.ts +0 -4
- package/src/_shims/auto/types-node.ts +0 -4
- package/src/_shims/auto/types.d.ts +0 -101
- package/src/_shims/auto/types.js +0 -3
- package/src/_shims/auto/types.mjs +0 -3
- package/src/_shims/bun-runtime.ts +0 -14
- package/src/_shims/index.d.ts +0 -81
- package/src/_shims/index.js +0 -13
- package/src/_shims/index.mjs +0 -7
- package/src/_shims/manual-types.d.ts +0 -12
- package/src/_shims/manual-types.js +0 -3
- package/src/_shims/manual-types.mjs +0 -3
- package/src/_shims/node-runtime.ts +0 -81
- package/src/_shims/node-types.d.ts +0 -42
- package/src/_shims/node-types.js +0 -3
- package/src/_shims/node-types.mjs +0 -3
- package/src/_shims/registry.ts +0 -67
- package/src/_shims/web-runtime.ts +0 -103
- package/src/_shims/web-types.d.ts +0 -83
- package/src/_shims/web-types.js +0 -3
- package/src/_shims/web-types.mjs +0 -3
- package/src/core.ts +0 -1201
- package/src/error.ts +0 -130
- package/src/lib/.keep +0 -4
- package/src/resource.ts +0 -11
- package/src/resources/agents/agents.ts +0 -83
- package/src/resources/agents/index.ts +0 -4
- package/src/resources/agents/tools.ts +0 -34
- package/src/resources/logs.ts +0 -23
- package/src/resources/memory/index.ts +0 -5
- package/src/resources/memory/memory.ts +0 -43
- package/src/resources/memory/status.ts +0 -16
- package/src/resources/memory/threads/index.ts +0 -4
- package/src/resources/memory/threads/messages.ts +0 -16
- package/src/resources/memory/threads/threads.ts +0 -105
- package/src/resources/syncs.ts +0 -25
- package/src/resources/system.ts +0 -13
- package/src/resources/tools/index.ts +0 -4
- package/src/resources/tools/result.ts +0 -16
- package/src/resources/tools/tools.ts +0 -54
- package/src/resources/workflows.ts +0 -49
- package/src/shims/node.ts +0 -50
- package/src/shims/web.ts +0 -50
- package/src/tsconfig.json +0 -11
- package/src/uploads.ts +0 -255
- package/src/version.ts +0 -1
- package/uploads.d.ts +0 -75
- package/uploads.d.ts.map +0 -1
- package/uploads.js +0 -171
- package/uploads.js.map +0 -1
- package/uploads.mjs +0 -158
- package/uploads.mjs.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -5
- package/version.js.map +0 -1
- package/version.mjs +0 -2
- package/version.mjs.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// src/resources/agent.ts
|
|
2
|
+
var Agent = class {
|
|
3
|
+
constructor(request, agentId) {
|
|
4
|
+
this.request = request;
|
|
5
|
+
this.agentId = agentId;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves details about the agent
|
|
9
|
+
* @returns Promise containing agent details including model and instructions
|
|
10
|
+
*/
|
|
11
|
+
details() {
|
|
12
|
+
return this.request(`/api/agents/${this.agentId}`);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generates a response from the agent
|
|
16
|
+
* @param params - Generation parameters including prompt
|
|
17
|
+
* @returns Promise containing the generated response
|
|
18
|
+
*/
|
|
19
|
+
generate(params) {
|
|
20
|
+
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
body: params
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Streams a response from the agent
|
|
27
|
+
* @param params - Stream parameters including prompt
|
|
28
|
+
* @returns Promise containing the streamed response
|
|
29
|
+
*/
|
|
30
|
+
stream(params) {
|
|
31
|
+
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: { ...params, stream: true }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets details about a specific tool available to the agent
|
|
38
|
+
* @param toolId - ID of the tool to retrieve
|
|
39
|
+
* @returns Promise containing tool details
|
|
40
|
+
*/
|
|
41
|
+
getTool(toolId) {
|
|
42
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves evaluation results for the agent
|
|
46
|
+
* @returns Promise containing agent evaluations
|
|
47
|
+
*/
|
|
48
|
+
evals() {
|
|
49
|
+
return this.request(`/api/agents/${this.agentId}/evals`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves live evaluation results for the agent
|
|
53
|
+
* @returns Promise containing live agent evaluations
|
|
54
|
+
*/
|
|
55
|
+
liveEvals() {
|
|
56
|
+
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/resources/memory-thread.ts
|
|
61
|
+
var MemoryThread = class {
|
|
62
|
+
constructor(request, threadId) {
|
|
63
|
+
this.request = request;
|
|
64
|
+
this.threadId = threadId;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the memory thread details
|
|
68
|
+
* @returns Promise containing thread details including title and metadata
|
|
69
|
+
*/
|
|
70
|
+
get() {
|
|
71
|
+
return this.request(`/api/memory/threads/${this.threadId}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Updates the memory thread properties
|
|
75
|
+
* @param params - Update parameters including title and metadata
|
|
76
|
+
* @returns Promise containing updated thread details
|
|
77
|
+
*/
|
|
78
|
+
update(params) {
|
|
79
|
+
return this.request(`/api/memory/threads/${this.threadId}`, {
|
|
80
|
+
method: "PATCH",
|
|
81
|
+
body: params
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Deletes the memory thread
|
|
86
|
+
* @returns Promise containing deletion result
|
|
87
|
+
*/
|
|
88
|
+
delete() {
|
|
89
|
+
return this.request(`/api/memory/threads/${this.threadId}`, {
|
|
90
|
+
method: "DELETE"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves messages associated with the thread
|
|
95
|
+
* @returns Promise containing thread messages and UI messages
|
|
96
|
+
*/
|
|
97
|
+
getMessages() {
|
|
98
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/resources/tool.ts
|
|
103
|
+
var Tool = class {
|
|
104
|
+
constructor(request, toolId) {
|
|
105
|
+
this.request = request;
|
|
106
|
+
this.toolId = toolId;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves details about the tool
|
|
110
|
+
* @returns Promise containing tool details including description and schemas
|
|
111
|
+
*/
|
|
112
|
+
details() {
|
|
113
|
+
return this.request(`/api/tools/${this.toolId}`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Executes the tool with the provided parameters
|
|
117
|
+
* @param params - Parameters required for tool execution
|
|
118
|
+
* @returns Promise containing the tool execution results
|
|
119
|
+
*/
|
|
120
|
+
execute(params) {
|
|
121
|
+
return this.request(`/api/tools/${this.toolId}/execute`, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
body: params
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/resources/workflow.ts
|
|
129
|
+
var Workflow = class {
|
|
130
|
+
constructor(request, workflowId) {
|
|
131
|
+
this.request = request;
|
|
132
|
+
this.workflowId = workflowId;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Retrieves details about the workflow
|
|
136
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
137
|
+
*/
|
|
138
|
+
details() {
|
|
139
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Executes the workflow with the provided parameters
|
|
143
|
+
* @param params - Parameters required for workflow execution
|
|
144
|
+
* @returns Promise containing the workflow execution results
|
|
145
|
+
*/
|
|
146
|
+
execute(params) {
|
|
147
|
+
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
148
|
+
method: "POST",
|
|
149
|
+
body: params
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/resources/vector.ts
|
|
155
|
+
var Vector = class {
|
|
156
|
+
constructor(request, vectorName) {
|
|
157
|
+
this.request = request;
|
|
158
|
+
this.vectorName = vectorName;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Retrieves details about a specific vector index
|
|
162
|
+
* @param indexName - Name of the index to get details for
|
|
163
|
+
* @returns Promise containing vector index details
|
|
164
|
+
*/
|
|
165
|
+
details(indexName) {
|
|
166
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Deletes a vector index
|
|
170
|
+
* @param indexName - Name of the index to delete
|
|
171
|
+
* @returns Promise indicating deletion success
|
|
172
|
+
*/
|
|
173
|
+
delete(indexName) {
|
|
174
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
|
|
175
|
+
method: "DELETE"
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Retrieves a list of all available indexes
|
|
180
|
+
* @returns Promise containing array of index names
|
|
181
|
+
*/
|
|
182
|
+
getIndexes() {
|
|
183
|
+
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates a new vector index
|
|
187
|
+
* @param params - Parameters for index creation including dimension and metric
|
|
188
|
+
* @returns Promise indicating creation success
|
|
189
|
+
*/
|
|
190
|
+
createIndex(params) {
|
|
191
|
+
return this.request(`/api/vector/${this.vectorName}/create-index`, {
|
|
192
|
+
method: "POST",
|
|
193
|
+
body: params
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Upserts vectors into an index
|
|
198
|
+
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
199
|
+
* @returns Promise containing array of vector IDs
|
|
200
|
+
*/
|
|
201
|
+
upsert(params) {
|
|
202
|
+
return this.request(`/api/vector/${this.vectorName}/upsert`, {
|
|
203
|
+
method: "POST",
|
|
204
|
+
body: params
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Queries vectors in an index
|
|
209
|
+
* @param params - Query parameters including query vector and search options
|
|
210
|
+
* @returns Promise containing query results
|
|
211
|
+
*/
|
|
212
|
+
query(params) {
|
|
213
|
+
return this.request(`/api/vector/${this.vectorName}/query`, {
|
|
214
|
+
method: "POST",
|
|
215
|
+
body: params
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/client.ts
|
|
221
|
+
var MastraClient = class {
|
|
222
|
+
baseUrl;
|
|
223
|
+
retries;
|
|
224
|
+
backoffMs;
|
|
225
|
+
maxBackoffMs;
|
|
226
|
+
headers;
|
|
227
|
+
constructor(options) {
|
|
228
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
229
|
+
this.retries = options.retries ?? 3;
|
|
230
|
+
this.backoffMs = options.backoffMs ?? 300;
|
|
231
|
+
this.maxBackoffMs = options.maxBackoffMs ?? 5e3;
|
|
232
|
+
this.headers = {
|
|
233
|
+
"Content-Type": "application/json",
|
|
234
|
+
...options.headers
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Makes an HTTP request to the Mastra API
|
|
239
|
+
* @param path - API endpoint path
|
|
240
|
+
* @param options - Request options including method, headers, and body
|
|
241
|
+
* @returns Promise containing the API response
|
|
242
|
+
* @throws Error if the request fails after all retries
|
|
243
|
+
*/
|
|
244
|
+
async request(path, options = {}) {
|
|
245
|
+
const url = `${this.baseUrl}${path}`;
|
|
246
|
+
let lastError = null;
|
|
247
|
+
let currentBackoff = this.backoffMs;
|
|
248
|
+
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
249
|
+
try {
|
|
250
|
+
const response = await fetch(url, {
|
|
251
|
+
method: options.method ?? "GET",
|
|
252
|
+
headers: {
|
|
253
|
+
...this.headers,
|
|
254
|
+
...options.headers
|
|
255
|
+
},
|
|
256
|
+
body: options.body ? JSON.stringify(options.body) : void 0
|
|
257
|
+
});
|
|
258
|
+
if (!response.ok) {
|
|
259
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
260
|
+
}
|
|
261
|
+
return await response.json();
|
|
262
|
+
} catch (error) {
|
|
263
|
+
lastError = error;
|
|
264
|
+
if (attempt === this.retries) break;
|
|
265
|
+
await new Promise((resolve) => setTimeout(resolve, currentBackoff));
|
|
266
|
+
currentBackoff = Math.min(currentBackoff * 2, this.maxBackoffMs);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
throw lastError;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Retrieves all available agents
|
|
273
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
274
|
+
*/
|
|
275
|
+
getAgents() {
|
|
276
|
+
return this.request("/api/agents");
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Gets an agent instance by ID
|
|
280
|
+
* @param agentId - ID of the agent to retrieve
|
|
281
|
+
* @returns Agent instance
|
|
282
|
+
*/
|
|
283
|
+
getAgent(agentId) {
|
|
284
|
+
return new Agent(
|
|
285
|
+
(path, options) => this.request(path, options),
|
|
286
|
+
agentId
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Retrieves memory threads for a resource
|
|
291
|
+
* @param params - Parameters containing the resource ID
|
|
292
|
+
* @returns Promise containing array of memory threads
|
|
293
|
+
*/
|
|
294
|
+
getMemoryThreads(params) {
|
|
295
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}`);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Creates a new memory thread
|
|
299
|
+
* @param params - Parameters for creating the memory thread
|
|
300
|
+
* @returns Promise containing the created memory thread
|
|
301
|
+
*/
|
|
302
|
+
createMemoryThread(params) {
|
|
303
|
+
return this.request("/api/memory/threads", { method: "POST", body: params });
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Gets a memory thread instance by ID
|
|
307
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
308
|
+
* @returns MemoryThread instance
|
|
309
|
+
*/
|
|
310
|
+
getMemoryThread(threadId) {
|
|
311
|
+
return new MemoryThread(
|
|
312
|
+
(path, options) => this.request(path, options),
|
|
313
|
+
threadId
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Saves messages to memory
|
|
318
|
+
* @param params - Parameters containing messages to save
|
|
319
|
+
* @returns Promise containing the saved messages
|
|
320
|
+
*/
|
|
321
|
+
saveMessageToMemory(params) {
|
|
322
|
+
return this.request("/api/memory/save-messages", {
|
|
323
|
+
method: "POST",
|
|
324
|
+
body: params
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Gets the status of the memory system
|
|
329
|
+
* @returns Promise containing memory system status
|
|
330
|
+
*/
|
|
331
|
+
getMemoryStatus() {
|
|
332
|
+
return this.request("/api/memory/status");
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Retrieves all available tools
|
|
336
|
+
* @returns Promise containing map of tool IDs to tool details
|
|
337
|
+
*/
|
|
338
|
+
getTools() {
|
|
339
|
+
return this.request("/api/tools");
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Gets a tool instance by ID
|
|
343
|
+
* @param toolId - ID of the tool to retrieve
|
|
344
|
+
* @returns Tool instance
|
|
345
|
+
*/
|
|
346
|
+
getTool(toolId) {
|
|
347
|
+
return new Tool(
|
|
348
|
+
(path, options) => this.request(path, options),
|
|
349
|
+
toolId
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Retrieves all available workflows
|
|
354
|
+
* @returns Promise containing map of workflow IDs to workflow details
|
|
355
|
+
*/
|
|
356
|
+
getWorkflows() {
|
|
357
|
+
return this.request("/api/workflows");
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Gets a workflow instance by ID
|
|
361
|
+
* @param workflowId - ID of the workflow to retrieve
|
|
362
|
+
* @returns Workflow instance
|
|
363
|
+
*/
|
|
364
|
+
getWorkflow(workflowId) {
|
|
365
|
+
return new Workflow(
|
|
366
|
+
(path, options) => this.request(path, options),
|
|
367
|
+
workflowId
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Gets a vector instance by name
|
|
372
|
+
* @param vectorName - Name of the vector to retrieve
|
|
373
|
+
* @returns Vector instance
|
|
374
|
+
*/
|
|
375
|
+
getVector(vectorName) {
|
|
376
|
+
return new Vector(
|
|
377
|
+
(path, options) => this.request(path, options),
|
|
378
|
+
vectorName
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Retrieves logs
|
|
383
|
+
* @param params - Parameters for filtering logs
|
|
384
|
+
* @returns Promise containing array of log messages
|
|
385
|
+
*/
|
|
386
|
+
getLogs(params) {
|
|
387
|
+
return this.request(`/api/logs?transportId=${params.transportId}`);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Gets logs for a specific run
|
|
391
|
+
* @param params - Parameters containing run ID to retrieve
|
|
392
|
+
* @returns Promise containing array of log messages
|
|
393
|
+
*/
|
|
394
|
+
getLogForRun(params) {
|
|
395
|
+
return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export { MastraClient };
|
package/package.json
CHANGED
|
@@ -1,103 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.4",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
|
-
"author": "
|
|
6
|
-
"types": "
|
|
7
|
-
"main": "
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"scripts": {
|
|
17
|
-
"test": "./scripts/test",
|
|
18
|
-
"build": "./scripts/build",
|
|
19
|
-
"format": "prettier --write --cache --cache-strategy metadata . !dist",
|
|
20
|
-
"tsn": "ts-node -r tsconfig-paths/register",
|
|
21
|
-
"lint": "./scripts/lint",
|
|
22
|
-
"fix": "./scripts/format"
|
|
5
|
+
"author": "",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
23
16
|
},
|
|
17
|
+
"repository": "github:mastra-ai/client-js",
|
|
18
|
+
"license": "ISC",
|
|
24
19
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"abort-controller": "^3.0.0",
|
|
28
|
-
"agentkeepalive": "^4.2.1",
|
|
29
|
-
"form-data-encoder": "1.7.2",
|
|
30
|
-
"formdata-node": "^4.3.2",
|
|
31
|
-
"node-fetch": "^2.6.7"
|
|
20
|
+
"@mastra/core": "^0.2.0-alpha.83",
|
|
21
|
+
"json-schema": "^0.4.0"
|
|
32
22
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"@mastra/client-js": ".",
|
|
43
|
-
"@mastra/client-js/*": "./src/*"
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@babel/preset-env": "^7.26.0",
|
|
25
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
26
|
+
"@tsconfig/recommended": "^1.0.7",
|
|
27
|
+
"@types/json-schema": "^7.0.15",
|
|
28
|
+
"@types/node": "^22.9.0",
|
|
29
|
+
"tsup": "^8.0.1",
|
|
30
|
+
"typescript": "^5.7.3",
|
|
31
|
+
"vitest": "^3.0.4"
|
|
44
32
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"require": "./_shims/auto/*.js",
|
|
50
|
-
"default": "./_shims/auto/*.mjs"
|
|
51
|
-
},
|
|
52
|
-
"bun": {
|
|
53
|
-
"types": "./_shims/auto/*.d.ts",
|
|
54
|
-
"require": "./_shims/auto/*-bun.js",
|
|
55
|
-
"default": "./_shims/auto/*-bun.mjs"
|
|
56
|
-
},
|
|
57
|
-
"browser": {
|
|
58
|
-
"types": "./_shims/auto/*.d.ts",
|
|
59
|
-
"require": "./_shims/auto/*.js",
|
|
60
|
-
"default": "./_shims/auto/*.mjs"
|
|
61
|
-
},
|
|
62
|
-
"worker": {
|
|
63
|
-
"types": "./_shims/auto/*.d.ts",
|
|
64
|
-
"require": "./_shims/auto/*.js",
|
|
65
|
-
"default": "./_shims/auto/*.mjs"
|
|
66
|
-
},
|
|
67
|
-
"workerd": {
|
|
68
|
-
"types": "./_shims/auto/*.d.ts",
|
|
69
|
-
"require": "./_shims/auto/*.js",
|
|
70
|
-
"default": "./_shims/auto/*.mjs"
|
|
71
|
-
},
|
|
72
|
-
"node": {
|
|
73
|
-
"types": "./_shims/auto/*-node.d.ts",
|
|
74
|
-
"require": "./_shims/auto/*-node.js",
|
|
75
|
-
"default": "./_shims/auto/*-node.mjs"
|
|
76
|
-
},
|
|
77
|
-
"types": "./_shims/auto/*.d.ts",
|
|
78
|
-
"require": "./_shims/auto/*.js",
|
|
79
|
-
"default": "./_shims/auto/*.mjs"
|
|
80
|
-
},
|
|
81
|
-
".": {
|
|
82
|
-
"require": {
|
|
83
|
-
"types": "./index.d.ts",
|
|
84
|
-
"default": "./index.js"
|
|
85
|
-
},
|
|
86
|
-
"types": "./index.d.mts",
|
|
87
|
-
"default": "./index.mjs"
|
|
88
|
-
},
|
|
89
|
-
"./*.mjs": {
|
|
90
|
-
"types": "./*.d.ts",
|
|
91
|
-
"default": "./*.mjs"
|
|
92
|
-
},
|
|
93
|
-
"./*.js": {
|
|
94
|
-
"types": "./*.d.ts",
|
|
95
|
-
"default": "./*.js"
|
|
96
|
-
},
|
|
97
|
-
"./*": {
|
|
98
|
-
"types": "./*.d.ts",
|
|
99
|
-
"require": "./*.js",
|
|
100
|
-
"default": "./*.mjs"
|
|
101
|
-
}
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
|
|
35
|
+
"dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
|
|
36
|
+
"test": "vitest run"
|
|
102
37
|
}
|
|
103
|
-
}
|
|
38
|
+
}
|