@mastra/client-js 0.1.5-alpha.1 → 0.1.5-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/.turbo/turbo-build.log +10 -6
- package/CHANGELOG.md +30 -0
- package/dist/index.cjs +491 -0
- package/dist/{index.d.mts → index.d.cts} +7 -11
- package/dist/index.d.ts +401 -0
- package/dist/{index.mjs → index.js} +4 -2
- package/package.json +13 -8
- package/src/resources/agent.ts +8 -0
- package/src/types.ts +7 -10
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/client-js@0.1.5-alpha.
|
|
3
|
-
> tsup src/index.ts --format esm --dts --clean --treeshake
|
|
2
|
+
> @mastra/client-js@0.1.5-alpha.4 build /home/runner/work/mastra/mastra/client-sdks/client-js
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
11
|
+
[34mCJS[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m13.96 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 649ms
|
|
14
|
+
[32mESM[39m [1mdist/index.js [22m[32m13.86 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 652ms
|
|
13
16
|
[34mDTS[39m Build start
|
|
14
|
-
[32mDTS[39m ⚡️ Build success in
|
|
15
|
-
[32mDTS[39m [1mdist/index.d.
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 9179ms
|
|
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
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 0.1.5-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [dabecf4]
|
|
8
|
+
- @mastra/core@0.4.3-alpha.4
|
|
9
|
+
|
|
10
|
+
## 0.1.5-alpha.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 0d25b75: Add all agent stream,generate option to cliend-js sdk
|
|
15
|
+
- 7a64aff: Add more types to client-js sdk
|
|
16
|
+
- bb4f447: Add support for commonjs
|
|
17
|
+
- Updated dependencies [0fd78ac]
|
|
18
|
+
- Updated dependencies [0d25b75]
|
|
19
|
+
- Updated dependencies [fd14a3f]
|
|
20
|
+
- Updated dependencies [3f369a2]
|
|
21
|
+
- Updated dependencies [4d4e1e1]
|
|
22
|
+
- Updated dependencies [bb4f447]
|
|
23
|
+
- @mastra/core@0.4.3-alpha.3
|
|
24
|
+
|
|
25
|
+
## 0.1.5-alpha.2
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [2512a93]
|
|
30
|
+
- Updated dependencies [e62de74]
|
|
31
|
+
- @mastra/core@0.4.3-alpha.2
|
|
32
|
+
|
|
3
33
|
## 0.1.5-alpha.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var zodToJsonSchema = require('zod-to-json-schema');
|
|
5
|
+
|
|
6
|
+
// src/resources/agent.ts
|
|
7
|
+
|
|
8
|
+
// src/resources/base.ts
|
|
9
|
+
var BaseResource = class {
|
|
10
|
+
options;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Makes an HTTP request to the API with retries and exponential backoff
|
|
16
|
+
* @param path - The API endpoint path
|
|
17
|
+
* @param options - Optional request configuration
|
|
18
|
+
* @returns Promise containing the response data
|
|
19
|
+
*/
|
|
20
|
+
async request(path, options = {}) {
|
|
21
|
+
let lastError = null;
|
|
22
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
|
|
23
|
+
let delay = backoffMs;
|
|
24
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
27
|
+
...options,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
...headers,
|
|
31
|
+
...options.headers
|
|
32
|
+
},
|
|
33
|
+
body: options.body ? JSON.stringify(options.body) : void 0
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
const errorBody = await response.text();
|
|
37
|
+
let errorMessage = `HTTP error! status: ${response.status}`;
|
|
38
|
+
try {
|
|
39
|
+
const errorJson = JSON.parse(errorBody);
|
|
40
|
+
errorMessage += ` - ${JSON.stringify(errorJson)}`;
|
|
41
|
+
} catch {
|
|
42
|
+
if (errorBody) {
|
|
43
|
+
errorMessage += ` - ${errorBody}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error(errorMessage);
|
|
47
|
+
}
|
|
48
|
+
if (options.stream) {
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
return data;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
lastError = error;
|
|
55
|
+
if (attempt === retries) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
59
|
+
delay = Math.min(delay * 2, maxBackoffMs);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw lastError || new Error("Request failed");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/resources/agent.ts
|
|
67
|
+
var Agent = class extends BaseResource {
|
|
68
|
+
constructor(options, agentId) {
|
|
69
|
+
super(options);
|
|
70
|
+
this.agentId = agentId;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves details about the agent
|
|
74
|
+
* @returns Promise containing agent details including model and instructions
|
|
75
|
+
*/
|
|
76
|
+
details() {
|
|
77
|
+
return this.request(`/api/agents/${this.agentId}`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generates a response from the agent
|
|
81
|
+
* @param params - Generation parameters including prompt
|
|
82
|
+
* @returns Promise containing the generated response
|
|
83
|
+
*/
|
|
84
|
+
generate(params) {
|
|
85
|
+
const processedParams = {
|
|
86
|
+
...params,
|
|
87
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
88
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
89
|
+
};
|
|
90
|
+
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
91
|
+
method: "POST",
|
|
92
|
+
body: processedParams
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Streams a response from the agent
|
|
97
|
+
* @param params - Stream parameters including prompt
|
|
98
|
+
* @returns Promise containing the streamed response
|
|
99
|
+
*/
|
|
100
|
+
stream(params) {
|
|
101
|
+
const processedParams = {
|
|
102
|
+
...params,
|
|
103
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
104
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
105
|
+
};
|
|
106
|
+
return this.request(`/api/agents/${this.agentId}/stream`, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: processedParams,
|
|
109
|
+
stream: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets details about a specific tool available to the agent
|
|
114
|
+
* @param toolId - ID of the tool to retrieve
|
|
115
|
+
* @returns Promise containing tool details
|
|
116
|
+
*/
|
|
117
|
+
getTool(toolId) {
|
|
118
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Retrieves evaluation results for the agent
|
|
122
|
+
* @returns Promise containing agent evaluations
|
|
123
|
+
*/
|
|
124
|
+
evals() {
|
|
125
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves live evaluation results for the agent
|
|
129
|
+
* @returns Promise containing live agent evaluations
|
|
130
|
+
*/
|
|
131
|
+
liveEvals() {
|
|
132
|
+
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/resources/memory-thread.ts
|
|
137
|
+
var MemoryThread = class extends BaseResource {
|
|
138
|
+
constructor(options, threadId, agentId) {
|
|
139
|
+
super(options);
|
|
140
|
+
this.threadId = threadId;
|
|
141
|
+
this.agentId = agentId;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves the memory thread details
|
|
145
|
+
* @returns Promise containing thread details including title and metadata
|
|
146
|
+
*/
|
|
147
|
+
get() {
|
|
148
|
+
return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Updates the memory thread properties
|
|
152
|
+
* @param params - Update parameters including title and metadata
|
|
153
|
+
* @returns Promise containing updated thread details
|
|
154
|
+
*/
|
|
155
|
+
update(params) {
|
|
156
|
+
return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
|
|
157
|
+
method: "PATCH",
|
|
158
|
+
body: params
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Deletes the memory thread
|
|
163
|
+
* @returns Promise containing deletion result
|
|
164
|
+
*/
|
|
165
|
+
delete() {
|
|
166
|
+
return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
|
|
167
|
+
method: "DELETE"
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Retrieves messages associated with the thread
|
|
172
|
+
* @returns Promise containing thread messages and UI messages
|
|
173
|
+
*/
|
|
174
|
+
getMessages() {
|
|
175
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/resources/vector.ts
|
|
180
|
+
var Vector = class extends BaseResource {
|
|
181
|
+
constructor(options, vectorName) {
|
|
182
|
+
super(options);
|
|
183
|
+
this.vectorName = vectorName;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Retrieves details about a specific vector index
|
|
187
|
+
* @param indexName - Name of the index to get details for
|
|
188
|
+
* @returns Promise containing vector index details
|
|
189
|
+
*/
|
|
190
|
+
details(indexName) {
|
|
191
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Deletes a vector index
|
|
195
|
+
* @param indexName - Name of the index to delete
|
|
196
|
+
* @returns Promise indicating deletion success
|
|
197
|
+
*/
|
|
198
|
+
delete(indexName) {
|
|
199
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
|
|
200
|
+
method: "DELETE"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Retrieves a list of all available indexes
|
|
205
|
+
* @returns Promise containing array of index names
|
|
206
|
+
*/
|
|
207
|
+
getIndexes() {
|
|
208
|
+
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Creates a new vector index
|
|
212
|
+
* @param params - Parameters for index creation including dimension and metric
|
|
213
|
+
* @returns Promise indicating creation success
|
|
214
|
+
*/
|
|
215
|
+
createIndex(params) {
|
|
216
|
+
return this.request(`/api/vector/${this.vectorName}/create-index`, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
body: params
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Upserts vectors into an index
|
|
223
|
+
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
224
|
+
* @returns Promise containing array of vector IDs
|
|
225
|
+
*/
|
|
226
|
+
upsert(params) {
|
|
227
|
+
return this.request(`/api/vector/${this.vectorName}/upsert`, {
|
|
228
|
+
method: "POST",
|
|
229
|
+
body: params
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Queries vectors in an index
|
|
234
|
+
* @param params - Query parameters including query vector and search options
|
|
235
|
+
* @returns Promise containing query results
|
|
236
|
+
*/
|
|
237
|
+
query(params) {
|
|
238
|
+
return this.request(`/api/vector/${this.vectorName}/query`, {
|
|
239
|
+
method: "POST",
|
|
240
|
+
body: params
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/resources/workflow.ts
|
|
246
|
+
var Workflow = class extends BaseResource {
|
|
247
|
+
constructor(options, workflowId) {
|
|
248
|
+
super(options);
|
|
249
|
+
this.workflowId = workflowId;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Retrieves details about the workflow
|
|
253
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
254
|
+
*/
|
|
255
|
+
details() {
|
|
256
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Executes the workflow with the provided parameters
|
|
260
|
+
* @param params - Parameters required for workflow execution
|
|
261
|
+
* @returns Promise containing the workflow execution results
|
|
262
|
+
*/
|
|
263
|
+
execute(params) {
|
|
264
|
+
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
265
|
+
method: "POST",
|
|
266
|
+
body: params
|
|
267
|
+
});
|
|
268
|
+
}
|
|
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({
|
|
277
|
+
stepId,
|
|
278
|
+
runId,
|
|
279
|
+
context
|
|
280
|
+
}) {
|
|
281
|
+
return this.request(`/api/workflows/${this.workflowId}/resume`, {
|
|
282
|
+
method: "POST",
|
|
283
|
+
body: {
|
|
284
|
+
stepId,
|
|
285
|
+
runId,
|
|
286
|
+
context
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Watches workflow transitions in real-time
|
|
292
|
+
* @returns Promise containing the workflow watch stream
|
|
293
|
+
*/
|
|
294
|
+
watch() {
|
|
295
|
+
return this.request(`/api/workflows/${this.workflowId}/watch`, {
|
|
296
|
+
stream: true
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// src/resources/tool.ts
|
|
302
|
+
var Tool = class extends BaseResource {
|
|
303
|
+
constructor(options, toolId) {
|
|
304
|
+
super(options);
|
|
305
|
+
this.toolId = toolId;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Retrieves details about the tool
|
|
309
|
+
* @returns Promise containing tool details including description and schemas
|
|
310
|
+
*/
|
|
311
|
+
details() {
|
|
312
|
+
return this.request(`/api/tools/${this.toolId}`);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Executes the tool with the provided parameters
|
|
316
|
+
* @param params - Parameters required for tool execution
|
|
317
|
+
* @returns Promise containing the tool execution results
|
|
318
|
+
*/
|
|
319
|
+
execute(params) {
|
|
320
|
+
return this.request(`/api/tools/${this.toolId}/execute`, {
|
|
321
|
+
method: "POST",
|
|
322
|
+
body: params
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/client.ts
|
|
328
|
+
var MastraClient = class extends BaseResource {
|
|
329
|
+
constructor(options) {
|
|
330
|
+
super(options);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Retrieves all available agents
|
|
334
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
335
|
+
*/
|
|
336
|
+
getAgents() {
|
|
337
|
+
return this.request("/api/agents");
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Gets an agent instance by ID
|
|
341
|
+
* @param agentId - ID of the agent to retrieve
|
|
342
|
+
* @returns Agent instance
|
|
343
|
+
*/
|
|
344
|
+
getAgent(agentId) {
|
|
345
|
+
return new Agent(this.options, agentId);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Retrieves memory threads for a resource
|
|
349
|
+
* @param params - Parameters containing the resource ID
|
|
350
|
+
* @returns Promise containing array of memory threads
|
|
351
|
+
*/
|
|
352
|
+
getMemoryThreads(params) {
|
|
353
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Creates a new memory thread
|
|
357
|
+
* @param params - Parameters for creating the memory thread
|
|
358
|
+
* @returns Promise containing the created memory thread
|
|
359
|
+
*/
|
|
360
|
+
createMemoryThread(params) {
|
|
361
|
+
return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Gets a memory thread instance by ID
|
|
365
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
366
|
+
* @returns MemoryThread instance
|
|
367
|
+
*/
|
|
368
|
+
getMemoryThread(threadId, agentId) {
|
|
369
|
+
return new MemoryThread(this.options, threadId, agentId);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Saves messages to memory
|
|
373
|
+
* @param params - Parameters containing messages to save
|
|
374
|
+
* @returns Promise containing the saved messages
|
|
375
|
+
*/
|
|
376
|
+
saveMessageToMemory(params) {
|
|
377
|
+
return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
|
|
378
|
+
method: "POST",
|
|
379
|
+
body: params
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Gets the status of the memory system
|
|
384
|
+
* @returns Promise containing memory system status
|
|
385
|
+
*/
|
|
386
|
+
getMemoryStatus(agentId) {
|
|
387
|
+
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Retrieves all available tools
|
|
391
|
+
* @returns Promise containing map of tool IDs to tool details
|
|
392
|
+
*/
|
|
393
|
+
getTools() {
|
|
394
|
+
return this.request("/api/tools");
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Gets a tool instance by ID
|
|
398
|
+
* @param toolId - ID of the tool to retrieve
|
|
399
|
+
* @returns Tool instance
|
|
400
|
+
*/
|
|
401
|
+
getTool(toolId) {
|
|
402
|
+
return new Tool(this.options, toolId);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Retrieves all available workflows
|
|
406
|
+
* @returns Promise containing map of workflow IDs to workflow details
|
|
407
|
+
*/
|
|
408
|
+
getWorkflows() {
|
|
409
|
+
return this.request("/api/workflows");
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Gets a workflow instance by ID
|
|
413
|
+
* @param workflowId - ID of the workflow to retrieve
|
|
414
|
+
* @returns Workflow instance
|
|
415
|
+
*/
|
|
416
|
+
getWorkflow(workflowId) {
|
|
417
|
+
return new Workflow(this.options, workflowId);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Gets a vector instance by name
|
|
421
|
+
* @param vectorName - Name of the vector to retrieve
|
|
422
|
+
* @returns Vector instance
|
|
423
|
+
*/
|
|
424
|
+
getVector(vectorName) {
|
|
425
|
+
return new Vector(this.options, vectorName);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Retrieves logs
|
|
429
|
+
* @param params - Parameters for filtering logs
|
|
430
|
+
* @returns Promise containing array of log messages
|
|
431
|
+
*/
|
|
432
|
+
getLogs(params) {
|
|
433
|
+
return this.request(`/api/logs?transportId=${params.transportId}`);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Gets logs for a specific run
|
|
437
|
+
* @param params - Parameters containing run ID to retrieve
|
|
438
|
+
* @returns Promise containing array of log messages
|
|
439
|
+
*/
|
|
440
|
+
getLogForRun(params) {
|
|
441
|
+
return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* List of all log transports
|
|
445
|
+
* @returns Promise containing list of log transports
|
|
446
|
+
*/
|
|
447
|
+
getLogTransports() {
|
|
448
|
+
return this.request("/api/logs/transports");
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* List of all traces (paged)
|
|
452
|
+
* @param params - Parameters for filtering traces
|
|
453
|
+
* @returns Promise containing telemetry data
|
|
454
|
+
*/
|
|
455
|
+
getTelemetry(params) {
|
|
456
|
+
const { name, scope, page, perPage, attribute } = params || {};
|
|
457
|
+
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
458
|
+
({
|
|
459
|
+
..._attribute?.length ? { attribute: _attribute } : {}
|
|
460
|
+
});
|
|
461
|
+
const searchParams = new URLSearchParams();
|
|
462
|
+
if (name) {
|
|
463
|
+
searchParams.set("name", name);
|
|
464
|
+
}
|
|
465
|
+
if (scope) {
|
|
466
|
+
searchParams.set("scope", scope);
|
|
467
|
+
}
|
|
468
|
+
if (page) {
|
|
469
|
+
searchParams.set("page", String(page));
|
|
470
|
+
}
|
|
471
|
+
if (perPage) {
|
|
472
|
+
searchParams.set("perPage", String(perPage));
|
|
473
|
+
}
|
|
474
|
+
if (_attribute) {
|
|
475
|
+
if (Array.isArray(_attribute)) {
|
|
476
|
+
for (const attr of _attribute) {
|
|
477
|
+
searchParams.append("attribute", attr);
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
searchParams.set("attribute", _attribute);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (searchParams.size) {
|
|
484
|
+
return this.request(`/api/telemetry?${searchParams}`);
|
|
485
|
+
} else {
|
|
486
|
+
return this.request(`/api/telemetry`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
exports.MastraClient = MastraClient;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { CoreMessage,
|
|
1
|
+
import { CoreMessage, StorageThreadType, AiMessageType, MessageType, StepAction, StepGraph, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
|
|
2
2
|
import { JSONSchema7 } from 'json-schema';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
|
+
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
4
5
|
|
|
5
6
|
interface ClientOptions {
|
|
6
7
|
/** Base URL for API requests */
|
|
@@ -25,19 +26,14 @@ interface GetAgentResponse {
|
|
|
25
26
|
instructions: string;
|
|
26
27
|
tools: Record<string, GetToolResponse>;
|
|
27
28
|
provider: string;
|
|
29
|
+
modelId: string;
|
|
28
30
|
}
|
|
29
|
-
|
|
31
|
+
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
30
32
|
messages: string | string[] | CoreMessage[];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
output?: OutputType | T;
|
|
34
|
-
}
|
|
35
|
-
interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
|
|
33
|
+
} & Partial<AgentGenerateOptions<T>>;
|
|
34
|
+
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
36
35
|
messages: string | string[] | CoreMessage[];
|
|
37
|
-
|
|
38
|
-
resourceid?: string;
|
|
39
|
-
output?: OutputType | T;
|
|
40
|
-
}
|
|
36
|
+
} & Partial<AgentStreamOptions<T>>;
|
|
41
37
|
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
42
38
|
evals: any[];
|
|
43
39
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { CoreMessage, StorageThreadType, AiMessageType, MessageType, StepAction, StepGraph, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
|
|
2
|
+
import { JSONSchema7 } from 'json-schema';
|
|
3
|
+
import { ZodSchema } from 'zod';
|
|
4
|
+
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
5
|
+
|
|
6
|
+
interface ClientOptions {
|
|
7
|
+
/** Base URL for API requests */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/** Number of retry attempts for failed requests */
|
|
10
|
+
retries?: number;
|
|
11
|
+
/** Initial backoff time in milliseconds between retries */
|
|
12
|
+
backoffMs?: number;
|
|
13
|
+
/** Maximum backoff time in milliseconds between retries */
|
|
14
|
+
maxBackoffMs?: number;
|
|
15
|
+
/** Custom headers to include with requests */
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
interface RequestOptions {
|
|
19
|
+
method?: string;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
body?: any;
|
|
22
|
+
stream?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface GetAgentResponse {
|
|
25
|
+
name: string;
|
|
26
|
+
instructions: string;
|
|
27
|
+
tools: Record<string, GetToolResponse>;
|
|
28
|
+
provider: string;
|
|
29
|
+
modelId: string;
|
|
30
|
+
}
|
|
31
|
+
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
32
|
+
messages: string | string[] | CoreMessage[];
|
|
33
|
+
} & Partial<AgentGenerateOptions<T>>;
|
|
34
|
+
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
35
|
+
messages: string | string[] | CoreMessage[];
|
|
36
|
+
} & Partial<AgentStreamOptions<T>>;
|
|
37
|
+
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
38
|
+
evals: any[];
|
|
39
|
+
}
|
|
40
|
+
interface GetToolResponse {
|
|
41
|
+
id: string;
|
|
42
|
+
description: string;
|
|
43
|
+
inputSchema: string;
|
|
44
|
+
outputSchema: string;
|
|
45
|
+
}
|
|
46
|
+
interface GetWorkflowResponse {
|
|
47
|
+
name: string;
|
|
48
|
+
triggerSchema: string;
|
|
49
|
+
steps: Record<string, StepAction<any, any, any, any>>;
|
|
50
|
+
stepGraph: StepGraph;
|
|
51
|
+
stepSubscriberGraph: Record<string, StepGraph>;
|
|
52
|
+
}
|
|
53
|
+
interface UpsertVectorParams {
|
|
54
|
+
indexName: string;
|
|
55
|
+
vectors: number[][];
|
|
56
|
+
metadata?: Record<string, any>[];
|
|
57
|
+
ids?: string[];
|
|
58
|
+
}
|
|
59
|
+
interface CreateIndexParams {
|
|
60
|
+
indexName: string;
|
|
61
|
+
dimension: number;
|
|
62
|
+
metric?: 'cosine' | 'euclidean' | 'dotproduct';
|
|
63
|
+
}
|
|
64
|
+
interface QueryVectorParams {
|
|
65
|
+
indexName: string;
|
|
66
|
+
queryVector: number[];
|
|
67
|
+
topK?: number;
|
|
68
|
+
filter?: Record<string, any>;
|
|
69
|
+
includeVector?: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface QueryVectorResponse {
|
|
72
|
+
results: QueryResult[];
|
|
73
|
+
}
|
|
74
|
+
interface GetVectorIndexResponse {
|
|
75
|
+
dimension: number;
|
|
76
|
+
metric: 'cosine' | 'euclidean' | 'dotproduct';
|
|
77
|
+
count: number;
|
|
78
|
+
}
|
|
79
|
+
interface SaveMessageToMemoryParams {
|
|
80
|
+
messages: MessageType[];
|
|
81
|
+
agentId: string;
|
|
82
|
+
}
|
|
83
|
+
type SaveMessageToMemoryResponse = MessageType[];
|
|
84
|
+
interface CreateMemoryThreadParams {
|
|
85
|
+
title: string;
|
|
86
|
+
metadata: Record<string, any>;
|
|
87
|
+
resourceid: string;
|
|
88
|
+
threadId: string;
|
|
89
|
+
agentId: string;
|
|
90
|
+
}
|
|
91
|
+
type CreateMemoryThreadResponse = StorageThreadType;
|
|
92
|
+
interface GetMemoryThreadParams {
|
|
93
|
+
resourceId: string;
|
|
94
|
+
agentId: string;
|
|
95
|
+
}
|
|
96
|
+
type GetMemoryThreadResponse = StorageThreadType[];
|
|
97
|
+
interface UpdateMemoryThreadParams {
|
|
98
|
+
title: string;
|
|
99
|
+
metadata: Record<string, any>;
|
|
100
|
+
resourceid: string;
|
|
101
|
+
}
|
|
102
|
+
interface GetMemoryThreadMessagesResponse {
|
|
103
|
+
messages: CoreMessage[];
|
|
104
|
+
uiMessages: AiMessageType[];
|
|
105
|
+
}
|
|
106
|
+
interface GetLogsParams {
|
|
107
|
+
transportId: string;
|
|
108
|
+
}
|
|
109
|
+
interface GetLogParams {
|
|
110
|
+
runId: string;
|
|
111
|
+
transportId: string;
|
|
112
|
+
}
|
|
113
|
+
type GetLogsResponse = BaseLogMessage[];
|
|
114
|
+
type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
115
|
+
interface GetTelemetryResponse {
|
|
116
|
+
traces: any[];
|
|
117
|
+
}
|
|
118
|
+
interface GetTelemetryParams {
|
|
119
|
+
name?: string;
|
|
120
|
+
scope?: string;
|
|
121
|
+
page?: number;
|
|
122
|
+
perPage?: number;
|
|
123
|
+
attribute?: Record<string, string>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
declare class BaseResource {
|
|
127
|
+
readonly options: ClientOptions;
|
|
128
|
+
constructor(options: ClientOptions);
|
|
129
|
+
/**
|
|
130
|
+
* Makes an HTTP request to the API with retries and exponential backoff
|
|
131
|
+
* @param path - The API endpoint path
|
|
132
|
+
* @param options - Optional request configuration
|
|
133
|
+
* @returns Promise containing the response data
|
|
134
|
+
*/
|
|
135
|
+
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare class Agent extends BaseResource {
|
|
139
|
+
private agentId;
|
|
140
|
+
constructor(options: ClientOptions, agentId: string);
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves details about the agent
|
|
143
|
+
* @returns Promise containing agent details including model and instructions
|
|
144
|
+
*/
|
|
145
|
+
details(): Promise<GetAgentResponse>;
|
|
146
|
+
/**
|
|
147
|
+
* Generates a response from the agent
|
|
148
|
+
* @param params - Generation parameters including prompt
|
|
149
|
+
* @returns Promise containing the generated response
|
|
150
|
+
*/
|
|
151
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
|
|
152
|
+
/**
|
|
153
|
+
* Streams a response from the agent
|
|
154
|
+
* @param params - Stream parameters including prompt
|
|
155
|
+
* @returns Promise containing the streamed response
|
|
156
|
+
*/
|
|
157
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response>;
|
|
158
|
+
/**
|
|
159
|
+
* Gets details about a specific tool available to the agent
|
|
160
|
+
* @param toolId - ID of the tool to retrieve
|
|
161
|
+
* @returns Promise containing tool details
|
|
162
|
+
*/
|
|
163
|
+
getTool(toolId: string): Promise<GetToolResponse>;
|
|
164
|
+
/**
|
|
165
|
+
* Retrieves evaluation results for the agent
|
|
166
|
+
* @returns Promise containing agent evaluations
|
|
167
|
+
*/
|
|
168
|
+
evals(): Promise<GetEvalsByAgentIdResponse>;
|
|
169
|
+
/**
|
|
170
|
+
* Retrieves live evaluation results for the agent
|
|
171
|
+
* @returns Promise containing live agent evaluations
|
|
172
|
+
*/
|
|
173
|
+
liveEvals(): Promise<GetEvalsByAgentIdResponse>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class MemoryThread extends BaseResource {
|
|
177
|
+
private threadId;
|
|
178
|
+
private agentId;
|
|
179
|
+
constructor(options: ClientOptions, threadId: string, agentId: string);
|
|
180
|
+
/**
|
|
181
|
+
* Retrieves the memory thread details
|
|
182
|
+
* @returns Promise containing thread details including title and metadata
|
|
183
|
+
*/
|
|
184
|
+
get(): Promise<StorageThreadType>;
|
|
185
|
+
/**
|
|
186
|
+
* Updates the memory thread properties
|
|
187
|
+
* @param params - Update parameters including title and metadata
|
|
188
|
+
* @returns Promise containing updated thread details
|
|
189
|
+
*/
|
|
190
|
+
update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
|
|
191
|
+
/**
|
|
192
|
+
* Deletes the memory thread
|
|
193
|
+
* @returns Promise containing deletion result
|
|
194
|
+
*/
|
|
195
|
+
delete(): Promise<{
|
|
196
|
+
result: string;
|
|
197
|
+
}>;
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves messages associated with the thread
|
|
200
|
+
* @returns Promise containing thread messages and UI messages
|
|
201
|
+
*/
|
|
202
|
+
getMessages(): Promise<GetMemoryThreadMessagesResponse>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
declare class Vector extends BaseResource {
|
|
206
|
+
private vectorName;
|
|
207
|
+
constructor(options: ClientOptions, vectorName: string);
|
|
208
|
+
/**
|
|
209
|
+
* Retrieves details about a specific vector index
|
|
210
|
+
* @param indexName - Name of the index to get details for
|
|
211
|
+
* @returns Promise containing vector index details
|
|
212
|
+
*/
|
|
213
|
+
details(indexName: string): Promise<GetVectorIndexResponse>;
|
|
214
|
+
/**
|
|
215
|
+
* Deletes a vector index
|
|
216
|
+
* @param indexName - Name of the index to delete
|
|
217
|
+
* @returns Promise indicating deletion success
|
|
218
|
+
*/
|
|
219
|
+
delete(indexName: string): Promise<{
|
|
220
|
+
success: boolean;
|
|
221
|
+
}>;
|
|
222
|
+
/**
|
|
223
|
+
* Retrieves a list of all available indexes
|
|
224
|
+
* @returns Promise containing array of index names
|
|
225
|
+
*/
|
|
226
|
+
getIndexes(): Promise<{
|
|
227
|
+
indexes: string[];
|
|
228
|
+
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a new vector index
|
|
231
|
+
* @param params - Parameters for index creation including dimension and metric
|
|
232
|
+
* @returns Promise indicating creation success
|
|
233
|
+
*/
|
|
234
|
+
createIndex(params: CreateIndexParams): Promise<{
|
|
235
|
+
success: boolean;
|
|
236
|
+
}>;
|
|
237
|
+
/**
|
|
238
|
+
* Upserts vectors into an index
|
|
239
|
+
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
240
|
+
* @returns Promise containing array of vector IDs
|
|
241
|
+
*/
|
|
242
|
+
upsert(params: UpsertVectorParams): Promise<string[]>;
|
|
243
|
+
/**
|
|
244
|
+
* Queries vectors in an index
|
|
245
|
+
* @param params - Query parameters including query vector and search options
|
|
246
|
+
* @returns Promise containing query results
|
|
247
|
+
*/
|
|
248
|
+
query(params: QueryVectorParams): Promise<QueryVectorResponse>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
declare class Workflow extends BaseResource {
|
|
252
|
+
private workflowId;
|
|
253
|
+
constructor(options: ClientOptions, workflowId: string);
|
|
254
|
+
/**
|
|
255
|
+
* Retrieves details about the workflow
|
|
256
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
257
|
+
*/
|
|
258
|
+
details(): Promise<GetWorkflowResponse>;
|
|
259
|
+
/**
|
|
260
|
+
* Executes the workflow with the provided parameters
|
|
261
|
+
* @param params - Parameters required for workflow execution
|
|
262
|
+
* @returns Promise containing the workflow execution results
|
|
263
|
+
*/
|
|
264
|
+
execute(params: Record<string, any>): Promise<Record<string, any>>;
|
|
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({ stepId, runId, context, }: {
|
|
273
|
+
stepId: string;
|
|
274
|
+
runId: string;
|
|
275
|
+
context: Record<string, any>;
|
|
276
|
+
}): Promise<Record<string, any>>;
|
|
277
|
+
/**
|
|
278
|
+
* Watches workflow transitions in real-time
|
|
279
|
+
* @returns Promise containing the workflow watch stream
|
|
280
|
+
*/
|
|
281
|
+
watch(): Promise<Response>;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
declare class Tool extends BaseResource {
|
|
285
|
+
private toolId;
|
|
286
|
+
constructor(options: ClientOptions, toolId: string);
|
|
287
|
+
/**
|
|
288
|
+
* Retrieves details about the tool
|
|
289
|
+
* @returns Promise containing tool details including description and schemas
|
|
290
|
+
*/
|
|
291
|
+
details(): Promise<GetToolResponse>;
|
|
292
|
+
/**
|
|
293
|
+
* Executes the tool with the provided parameters
|
|
294
|
+
* @param params - Parameters required for tool execution
|
|
295
|
+
* @returns Promise containing the tool execution results
|
|
296
|
+
*/
|
|
297
|
+
execute(params: {
|
|
298
|
+
data: any;
|
|
299
|
+
}): Promise<any>;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
declare class MastraClient extends BaseResource {
|
|
303
|
+
constructor(options: ClientOptions);
|
|
304
|
+
/**
|
|
305
|
+
* Retrieves all available agents
|
|
306
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
307
|
+
*/
|
|
308
|
+
getAgents(): Promise<Record<string, GetAgentResponse>>;
|
|
309
|
+
/**
|
|
310
|
+
* Gets an agent instance by ID
|
|
311
|
+
* @param agentId - ID of the agent to retrieve
|
|
312
|
+
* @returns Agent instance
|
|
313
|
+
*/
|
|
314
|
+
getAgent(agentId: string): Agent;
|
|
315
|
+
/**
|
|
316
|
+
* Retrieves memory threads for a resource
|
|
317
|
+
* @param params - Parameters containing the resource ID
|
|
318
|
+
* @returns Promise containing array of memory threads
|
|
319
|
+
*/
|
|
320
|
+
getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse>;
|
|
321
|
+
/**
|
|
322
|
+
* Creates a new memory thread
|
|
323
|
+
* @param params - Parameters for creating the memory thread
|
|
324
|
+
* @returns Promise containing the created memory thread
|
|
325
|
+
*/
|
|
326
|
+
createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse>;
|
|
327
|
+
/**
|
|
328
|
+
* Gets a memory thread instance by ID
|
|
329
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
330
|
+
* @returns MemoryThread instance
|
|
331
|
+
*/
|
|
332
|
+
getMemoryThread(threadId: string, agentId: string): MemoryThread;
|
|
333
|
+
/**
|
|
334
|
+
* Saves messages to memory
|
|
335
|
+
* @param params - Parameters containing messages to save
|
|
336
|
+
* @returns Promise containing the saved messages
|
|
337
|
+
*/
|
|
338
|
+
saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse>;
|
|
339
|
+
/**
|
|
340
|
+
* Gets the status of the memory system
|
|
341
|
+
* @returns Promise containing memory system status
|
|
342
|
+
*/
|
|
343
|
+
getMemoryStatus(agentId: string): Promise<{
|
|
344
|
+
result: boolean;
|
|
345
|
+
}>;
|
|
346
|
+
/**
|
|
347
|
+
* Retrieves all available tools
|
|
348
|
+
* @returns Promise containing map of tool IDs to tool details
|
|
349
|
+
*/
|
|
350
|
+
getTools(): Promise<Record<string, GetToolResponse>>;
|
|
351
|
+
/**
|
|
352
|
+
* Gets a tool instance by ID
|
|
353
|
+
* @param toolId - ID of the tool to retrieve
|
|
354
|
+
* @returns Tool instance
|
|
355
|
+
*/
|
|
356
|
+
getTool(toolId: string): Tool;
|
|
357
|
+
/**
|
|
358
|
+
* Retrieves all available workflows
|
|
359
|
+
* @returns Promise containing map of workflow IDs to workflow details
|
|
360
|
+
*/
|
|
361
|
+
getWorkflows(): Promise<Record<string, GetWorkflowResponse>>;
|
|
362
|
+
/**
|
|
363
|
+
* Gets a workflow instance by ID
|
|
364
|
+
* @param workflowId - ID of the workflow to retrieve
|
|
365
|
+
* @returns Workflow instance
|
|
366
|
+
*/
|
|
367
|
+
getWorkflow(workflowId: string): Workflow;
|
|
368
|
+
/**
|
|
369
|
+
* Gets a vector instance by name
|
|
370
|
+
* @param vectorName - Name of the vector to retrieve
|
|
371
|
+
* @returns Vector instance
|
|
372
|
+
*/
|
|
373
|
+
getVector(vectorName: string): Vector;
|
|
374
|
+
/**
|
|
375
|
+
* Retrieves logs
|
|
376
|
+
* @param params - Parameters for filtering logs
|
|
377
|
+
* @returns Promise containing array of log messages
|
|
378
|
+
*/
|
|
379
|
+
getLogs(params: GetLogsParams): Promise<GetLogsResponse>;
|
|
380
|
+
/**
|
|
381
|
+
* Gets logs for a specific run
|
|
382
|
+
* @param params - Parameters containing run ID to retrieve
|
|
383
|
+
* @returns Promise containing array of log messages
|
|
384
|
+
*/
|
|
385
|
+
getLogForRun(params: GetLogParams): Promise<GetLogsResponse>;
|
|
386
|
+
/**
|
|
387
|
+
* List of all log transports
|
|
388
|
+
* @returns Promise containing list of log transports
|
|
389
|
+
*/
|
|
390
|
+
getLogTransports(): Promise<{
|
|
391
|
+
transports: string[];
|
|
392
|
+
}>;
|
|
393
|
+
/**
|
|
394
|
+
* List of all traces (paged)
|
|
395
|
+
* @param params - Parameters for filtering traces
|
|
396
|
+
* @returns Promise containing telemetry data
|
|
397
|
+
*/
|
|
398
|
+
getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse>;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
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 };
|
|
@@ -82,7 +82,8 @@ var Agent = class extends BaseResource {
|
|
|
82
82
|
generate(params) {
|
|
83
83
|
const processedParams = {
|
|
84
84
|
...params,
|
|
85
|
-
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
|
|
85
|
+
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
|
|
86
|
+
experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
86
87
|
};
|
|
87
88
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
88
89
|
method: "POST",
|
|
@@ -97,7 +98,8 @@ var Agent = class extends BaseResource {
|
|
|
97
98
|
stream(params) {
|
|
98
99
|
const processedParams = {
|
|
99
100
|
...params,
|
|
100
|
-
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
|
|
101
|
+
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
|
|
102
|
+
experimental_output: params.experimental_output instanceof ZodSchema ? zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
101
103
|
};
|
|
102
104
|
return this.request(`/api/agents/${this.agentId}/stream`, {
|
|
103
105
|
method: "POST",
|
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1.5-alpha.
|
|
3
|
+
"version": "0.1.5-alpha.4",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"main": "dist/index.js",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": {
|
|
11
|
-
"types": "./dist/index.d.
|
|
12
|
-
"default": "./dist/index.
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"./package.json": "./package.json"
|
|
@@ -20,7 +25,7 @@
|
|
|
20
25
|
"json-schema": "^0.4.0",
|
|
21
26
|
"zod": "^3.24.1",
|
|
22
27
|
"zod-to-json-schema": "^3.24.1",
|
|
23
|
-
"@mastra/core": "^0.4.3-alpha.
|
|
28
|
+
"@mastra/core": "^0.4.3-alpha.4"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"@babel/preset-env": "^7.26.0",
|
|
@@ -34,8 +39,8 @@
|
|
|
34
39
|
"@internal/lint": "0.0.0"
|
|
35
40
|
},
|
|
36
41
|
"scripts": {
|
|
37
|
-
"build": "tsup src/index.ts --format esm --dts --clean --treeshake",
|
|
38
|
-
"dev": "
|
|
42
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake",
|
|
43
|
+
"dev": "pnpm build --watch",
|
|
39
44
|
"test": "vitest run"
|
|
40
45
|
}
|
|
41
46
|
}
|
package/src/resources/agent.ts
CHANGED
|
@@ -63,6 +63,10 @@ export class Agent extends BaseResource {
|
|
|
63
63
|
const processedParams = {
|
|
64
64
|
...params,
|
|
65
65
|
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
|
|
66
|
+
experimental_output:
|
|
67
|
+
params.experimental_output instanceof ZodSchema
|
|
68
|
+
? zodToJsonSchema(params.experimental_output)
|
|
69
|
+
: params.experimental_output,
|
|
66
70
|
};
|
|
67
71
|
|
|
68
72
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
@@ -80,6 +84,10 @@ export class Agent extends BaseResource {
|
|
|
80
84
|
const processedParams = {
|
|
81
85
|
...params,
|
|
82
86
|
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
|
|
87
|
+
experimental_output:
|
|
88
|
+
params.experimental_output instanceof ZodSchema
|
|
89
|
+
? zodToJsonSchema(params.experimental_output)
|
|
90
|
+
: params.experimental_output,
|
|
83
91
|
};
|
|
84
92
|
|
|
85
93
|
return this.request(`/api/agents/${this.agentId}/stream`, {
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type {
|
|
|
9
9
|
BaseLogMessage,
|
|
10
10
|
OutputType,
|
|
11
11
|
} from '@mastra/core';
|
|
12
|
+
|
|
13
|
+
import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
12
14
|
import type { JSONSchema7 } from 'json-schema';
|
|
13
15
|
import { ZodSchema } from 'zod';
|
|
14
16
|
|
|
@@ -37,21 +39,16 @@ export interface GetAgentResponse {
|
|
|
37
39
|
instructions: string;
|
|
38
40
|
tools: Record<string, GetToolResponse>;
|
|
39
41
|
provider: string;
|
|
42
|
+
modelId: string;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
export
|
|
45
|
+
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
43
46
|
messages: string | string[] | CoreMessage[];
|
|
44
|
-
|
|
45
|
-
resourceid?: string;
|
|
46
|
-
output?: OutputType | T;
|
|
47
|
-
}
|
|
47
|
+
} & Partial<AgentGenerateOptions<T>>;
|
|
48
48
|
|
|
49
|
-
export
|
|
49
|
+
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
50
50
|
messages: string | string[] | CoreMessage[];
|
|
51
|
-
|
|
52
|
-
resourceid?: string;
|
|
53
|
-
output?: OutputType | T;
|
|
54
|
-
}
|
|
51
|
+
} & Partial<AgentStreamOptions<T>>;
|
|
55
52
|
|
|
56
53
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
57
54
|
evals: any[];
|