@mastra/client-js 0.0.0-storage-20250225005900 → 0.0.0-vnext-inngest-20250506121901
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +981 -3
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +6 -3
- package/dist/index.cjs +1146 -0
- package/dist/index.d.cts +730 -0
- package/dist/index.d.ts +730 -0
- package/dist/index.js +1144 -0
- package/package.json +30 -19
- package/src/adapters/agui.test.ts +167 -0
- package/src/adapters/agui.ts +219 -0
- package/src/client.ts +65 -11
- package/src/example.ts +65 -43
- package/src/index.test.ts +173 -60
- package/src/resources/agent.ts +92 -4
- package/src/resources/base.ts +5 -3
- package/src/resources/index.ts +2 -0
- package/src/resources/memory-thread.ts +1 -8
- package/src/resources/network.ts +92 -0
- package/src/resources/tool.ts +9 -3
- package/src/resources/vnext-workflow.ts +257 -0
- package/src/resources/workflow.ts +192 -9
- package/src/types.ts +116 -17
- package/.turbo/turbo-build.log +0 -16
- package/dist/index.d.mts +0 -405
- package/dist/index.mjs +0 -487
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@ag-ui/client');
|
|
4
|
+
var rxjs = require('rxjs');
|
|
5
|
+
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var zodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
|
|
9
|
+
// src/adapters/agui.ts
|
|
10
|
+
var AGUIAdapter = class extends client.AbstractAgent {
|
|
11
|
+
agent;
|
|
12
|
+
resourceId;
|
|
13
|
+
constructor({ agent, agentId, resourceId, ...rest }) {
|
|
14
|
+
super({
|
|
15
|
+
agentId,
|
|
16
|
+
...rest
|
|
17
|
+
});
|
|
18
|
+
this.agent = agent;
|
|
19
|
+
this.resourceId = resourceId;
|
|
20
|
+
}
|
|
21
|
+
run(input) {
|
|
22
|
+
return new rxjs.Observable((subscriber) => {
|
|
23
|
+
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
24
|
+
subscriber.next({
|
|
25
|
+
type: client.EventType.RUN_STARTED,
|
|
26
|
+
threadId: input.threadId,
|
|
27
|
+
runId: input.runId
|
|
28
|
+
});
|
|
29
|
+
this.agent.stream({
|
|
30
|
+
threadId: input.threadId,
|
|
31
|
+
resourceId: this.resourceId ?? "",
|
|
32
|
+
runId: input.runId,
|
|
33
|
+
messages: convertedMessages,
|
|
34
|
+
clientTools: input.tools.reduce(
|
|
35
|
+
(acc, tool) => {
|
|
36
|
+
acc[tool.name] = {
|
|
37
|
+
id: tool.name,
|
|
38
|
+
description: tool.description,
|
|
39
|
+
inputSchema: tool.parameters
|
|
40
|
+
};
|
|
41
|
+
return acc;
|
|
42
|
+
},
|
|
43
|
+
{}
|
|
44
|
+
)
|
|
45
|
+
}).then((response) => {
|
|
46
|
+
let currentMessageId = void 0;
|
|
47
|
+
return response.processDataStream({
|
|
48
|
+
onTextPart: (text) => {
|
|
49
|
+
if (currentMessageId === void 0) {
|
|
50
|
+
currentMessageId = generateUUID();
|
|
51
|
+
const message2 = {
|
|
52
|
+
type: client.EventType.TEXT_MESSAGE_START,
|
|
53
|
+
messageId: currentMessageId,
|
|
54
|
+
role: "assistant"
|
|
55
|
+
};
|
|
56
|
+
subscriber.next(message2);
|
|
57
|
+
}
|
|
58
|
+
const message = {
|
|
59
|
+
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
60
|
+
messageId: currentMessageId,
|
|
61
|
+
delta: text
|
|
62
|
+
};
|
|
63
|
+
subscriber.next(message);
|
|
64
|
+
},
|
|
65
|
+
onFinishMessagePart: (message) => {
|
|
66
|
+
console.log("onFinishMessagePart", message);
|
|
67
|
+
if (currentMessageId !== void 0) {
|
|
68
|
+
const message2 = {
|
|
69
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
70
|
+
messageId: currentMessageId
|
|
71
|
+
};
|
|
72
|
+
subscriber.next(message2);
|
|
73
|
+
}
|
|
74
|
+
subscriber.next({
|
|
75
|
+
type: client.EventType.RUN_FINISHED,
|
|
76
|
+
threadId: input.threadId,
|
|
77
|
+
runId: input.runId
|
|
78
|
+
});
|
|
79
|
+
subscriber.complete();
|
|
80
|
+
},
|
|
81
|
+
onToolCallPart(streamPart) {
|
|
82
|
+
const parentMessageId = currentMessageId || generateUUID();
|
|
83
|
+
subscriber.next({
|
|
84
|
+
type: client.EventType.TOOL_CALL_START,
|
|
85
|
+
toolCallId: streamPart.toolCallId,
|
|
86
|
+
toolCallName: streamPart.toolName,
|
|
87
|
+
parentMessageId
|
|
88
|
+
});
|
|
89
|
+
subscriber.next({
|
|
90
|
+
type: client.EventType.TOOL_CALL_ARGS,
|
|
91
|
+
toolCallId: streamPart.toolCallId,
|
|
92
|
+
delta: JSON.stringify(streamPart.args),
|
|
93
|
+
parentMessageId
|
|
94
|
+
});
|
|
95
|
+
subscriber.next({
|
|
96
|
+
type: client.EventType.TOOL_CALL_END,
|
|
97
|
+
toolCallId: streamPart.toolCallId,
|
|
98
|
+
parentMessageId
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
console.log("error", error);
|
|
104
|
+
subscriber.error(error);
|
|
105
|
+
});
|
|
106
|
+
return () => {
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function generateUUID() {
|
|
112
|
+
if (typeof crypto !== "undefined") {
|
|
113
|
+
if (typeof crypto.randomUUID === "function") {
|
|
114
|
+
return crypto.randomUUID();
|
|
115
|
+
}
|
|
116
|
+
if (typeof crypto.getRandomValues === "function") {
|
|
117
|
+
const buffer = new Uint8Array(16);
|
|
118
|
+
crypto.getRandomValues(buffer);
|
|
119
|
+
buffer[6] = buffer[6] & 15 | 64;
|
|
120
|
+
buffer[8] = buffer[8] & 63 | 128;
|
|
121
|
+
let hex = "";
|
|
122
|
+
for (let i = 0; i < 16; i++) {
|
|
123
|
+
hex += buffer[i].toString(16).padStart(2, "0");
|
|
124
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
125
|
+
}
|
|
126
|
+
return hex;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
130
|
+
const r = Math.random() * 16 | 0;
|
|
131
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
132
|
+
return v.toString(16);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function convertMessagesToMastraMessages(messages) {
|
|
136
|
+
const result = [];
|
|
137
|
+
for (const message of messages) {
|
|
138
|
+
if (message.role === "assistant") {
|
|
139
|
+
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
140
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
141
|
+
parts.push({
|
|
142
|
+
type: "tool-call",
|
|
143
|
+
toolCallId: toolCall.id,
|
|
144
|
+
toolName: toolCall.function.name,
|
|
145
|
+
args: JSON.parse(toolCall.function.arguments)
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
result.push({
|
|
149
|
+
role: "assistant",
|
|
150
|
+
content: parts
|
|
151
|
+
});
|
|
152
|
+
} else if (message.role === "user") {
|
|
153
|
+
result.push({
|
|
154
|
+
role: "user",
|
|
155
|
+
content: message.content || ""
|
|
156
|
+
});
|
|
157
|
+
} else if (message.role === "tool") {
|
|
158
|
+
result.push({
|
|
159
|
+
role: "tool",
|
|
160
|
+
content: [
|
|
161
|
+
{
|
|
162
|
+
type: "tool-result",
|
|
163
|
+
toolCallId: message.toolCallId,
|
|
164
|
+
toolName: "unknown",
|
|
165
|
+
result: message.content
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/resources/base.ts
|
|
175
|
+
var BaseResource = class {
|
|
176
|
+
options;
|
|
177
|
+
constructor(options) {
|
|
178
|
+
this.options = options;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Makes an HTTP request to the API with retries and exponential backoff
|
|
182
|
+
* @param path - The API endpoint path
|
|
183
|
+
* @param options - Optional request configuration
|
|
184
|
+
* @returns Promise containing the response data
|
|
185
|
+
*/
|
|
186
|
+
async request(path, options = {}) {
|
|
187
|
+
let lastError = null;
|
|
188
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
|
|
189
|
+
let delay = backoffMs;
|
|
190
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
191
|
+
try {
|
|
192
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
193
|
+
...options,
|
|
194
|
+
headers: {
|
|
195
|
+
...headers,
|
|
196
|
+
...options.headers
|
|
197
|
+
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
198
|
+
// 'x-mastra-client-type': 'js',
|
|
199
|
+
},
|
|
200
|
+
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
201
|
+
});
|
|
202
|
+
if (!response.ok) {
|
|
203
|
+
const errorBody = await response.text();
|
|
204
|
+
let errorMessage = `HTTP error! status: ${response.status}`;
|
|
205
|
+
try {
|
|
206
|
+
const errorJson = JSON.parse(errorBody);
|
|
207
|
+
errorMessage += ` - ${JSON.stringify(errorJson)}`;
|
|
208
|
+
} catch {
|
|
209
|
+
if (errorBody) {
|
|
210
|
+
errorMessage += ` - ${errorBody}`;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
throw new Error(errorMessage);
|
|
214
|
+
}
|
|
215
|
+
if (options.stream) {
|
|
216
|
+
return response;
|
|
217
|
+
}
|
|
218
|
+
const data = await response.json();
|
|
219
|
+
return data;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
lastError = error;
|
|
222
|
+
if (attempt === retries) {
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
226
|
+
delay = Math.min(delay * 2, maxBackoffMs);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
throw lastError || new Error("Request failed");
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/resources/agent.ts
|
|
234
|
+
var AgentVoice = class extends BaseResource {
|
|
235
|
+
constructor(options, agentId) {
|
|
236
|
+
super(options);
|
|
237
|
+
this.agentId = agentId;
|
|
238
|
+
this.agentId = agentId;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Convert text to speech using the agent's voice provider
|
|
242
|
+
* @param text - Text to convert to speech
|
|
243
|
+
* @param options - Optional provider-specific options for speech generation
|
|
244
|
+
* @returns Promise containing the audio data
|
|
245
|
+
*/
|
|
246
|
+
async speak(text, options) {
|
|
247
|
+
return this.request(`/api/agents/${this.agentId}/voice/speak`, {
|
|
248
|
+
method: "POST",
|
|
249
|
+
headers: {
|
|
250
|
+
"Content-Type": "application/json"
|
|
251
|
+
},
|
|
252
|
+
body: { input: text, options },
|
|
253
|
+
stream: true
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Convert speech to text using the agent's voice provider
|
|
258
|
+
* @param audio - Audio data to transcribe
|
|
259
|
+
* @param options - Optional provider-specific options
|
|
260
|
+
* @returns Promise containing the transcribed text
|
|
261
|
+
*/
|
|
262
|
+
listen(audio, options) {
|
|
263
|
+
const formData = new FormData();
|
|
264
|
+
formData.append("audio", audio);
|
|
265
|
+
if (options) {
|
|
266
|
+
formData.append("options", JSON.stringify(options));
|
|
267
|
+
}
|
|
268
|
+
return this.request(`/api/agents/${this.agentId}/voice/listen`, {
|
|
269
|
+
method: "POST",
|
|
270
|
+
body: formData
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get available speakers for the agent's voice provider
|
|
275
|
+
* @returns Promise containing list of available speakers
|
|
276
|
+
*/
|
|
277
|
+
getSpeakers() {
|
|
278
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
var Agent = class extends BaseResource {
|
|
282
|
+
constructor(options, agentId) {
|
|
283
|
+
super(options);
|
|
284
|
+
this.agentId = agentId;
|
|
285
|
+
this.voice = new AgentVoice(options, this.agentId);
|
|
286
|
+
}
|
|
287
|
+
voice;
|
|
288
|
+
/**
|
|
289
|
+
* Retrieves details about the agent
|
|
290
|
+
* @returns Promise containing agent details including model and instructions
|
|
291
|
+
*/
|
|
292
|
+
details() {
|
|
293
|
+
return this.request(`/api/agents/${this.agentId}`);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Generates a response from the agent
|
|
297
|
+
* @param params - Generation parameters including prompt
|
|
298
|
+
* @returns Promise containing the generated response
|
|
299
|
+
*/
|
|
300
|
+
generate(params) {
|
|
301
|
+
const processedParams = {
|
|
302
|
+
...params,
|
|
303
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
304
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
305
|
+
};
|
|
306
|
+
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
body: processedParams
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Streams a response from the agent
|
|
313
|
+
* @param params - Stream parameters including prompt
|
|
314
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
315
|
+
*/
|
|
316
|
+
async stream(params) {
|
|
317
|
+
const processedParams = {
|
|
318
|
+
...params,
|
|
319
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
320
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
321
|
+
};
|
|
322
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
323
|
+
method: "POST",
|
|
324
|
+
body: processedParams,
|
|
325
|
+
stream: true
|
|
326
|
+
});
|
|
327
|
+
if (!response.body) {
|
|
328
|
+
throw new Error("No response body");
|
|
329
|
+
}
|
|
330
|
+
response.processDataStream = async (options = {}) => {
|
|
331
|
+
await uiUtils.processDataStream({
|
|
332
|
+
stream: response.body,
|
|
333
|
+
...options
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
return response;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Gets details about a specific tool available to the agent
|
|
340
|
+
* @param toolId - ID of the tool to retrieve
|
|
341
|
+
* @returns Promise containing tool details
|
|
342
|
+
*/
|
|
343
|
+
getTool(toolId) {
|
|
344
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Retrieves evaluation results for the agent
|
|
348
|
+
* @returns Promise containing agent evaluations
|
|
349
|
+
*/
|
|
350
|
+
evals() {
|
|
351
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Retrieves live evaluation results for the agent
|
|
355
|
+
* @returns Promise containing live agent evaluations
|
|
356
|
+
*/
|
|
357
|
+
liveEvals() {
|
|
358
|
+
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var Network = class extends BaseResource {
|
|
362
|
+
constructor(options, networkId) {
|
|
363
|
+
super(options);
|
|
364
|
+
this.networkId = networkId;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Retrieves details about the network
|
|
368
|
+
* @returns Promise containing network details
|
|
369
|
+
*/
|
|
370
|
+
details() {
|
|
371
|
+
return this.request(`/api/networks/${this.networkId}`);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Generates a response from the agent
|
|
375
|
+
* @param params - Generation parameters including prompt
|
|
376
|
+
* @returns Promise containing the generated response
|
|
377
|
+
*/
|
|
378
|
+
generate(params) {
|
|
379
|
+
const processedParams = {
|
|
380
|
+
...params,
|
|
381
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
382
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
383
|
+
};
|
|
384
|
+
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
385
|
+
method: "POST",
|
|
386
|
+
body: processedParams
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Streams a response from the agent
|
|
391
|
+
* @param params - Stream parameters including prompt
|
|
392
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
393
|
+
*/
|
|
394
|
+
async stream(params) {
|
|
395
|
+
const processedParams = {
|
|
396
|
+
...params,
|
|
397
|
+
output: params.output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.output) : params.output,
|
|
398
|
+
experimental_output: params.experimental_output instanceof zod.ZodSchema ? zodToJsonSchema.zodToJsonSchema(params.experimental_output) : params.experimental_output
|
|
399
|
+
};
|
|
400
|
+
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
401
|
+
method: "POST",
|
|
402
|
+
body: processedParams,
|
|
403
|
+
stream: true
|
|
404
|
+
});
|
|
405
|
+
if (!response.body) {
|
|
406
|
+
throw new Error("No response body");
|
|
407
|
+
}
|
|
408
|
+
response.processDataStream = async (options = {}) => {
|
|
409
|
+
await uiUtils.processDataStream({
|
|
410
|
+
stream: response.body,
|
|
411
|
+
...options
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
return response;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
// src/resources/memory-thread.ts
|
|
419
|
+
var MemoryThread = class extends BaseResource {
|
|
420
|
+
constructor(options, threadId, agentId) {
|
|
421
|
+
super(options);
|
|
422
|
+
this.threadId = threadId;
|
|
423
|
+
this.agentId = agentId;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Retrieves the memory thread details
|
|
427
|
+
* @returns Promise containing thread details including title and metadata
|
|
428
|
+
*/
|
|
429
|
+
get() {
|
|
430
|
+
return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Updates the memory thread properties
|
|
434
|
+
* @param params - Update parameters including title and metadata
|
|
435
|
+
* @returns Promise containing updated thread details
|
|
436
|
+
*/
|
|
437
|
+
update(params) {
|
|
438
|
+
return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
|
|
439
|
+
method: "PATCH",
|
|
440
|
+
body: params
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Deletes the memory thread
|
|
445
|
+
* @returns Promise containing deletion result
|
|
446
|
+
*/
|
|
447
|
+
delete() {
|
|
448
|
+
return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
|
|
449
|
+
method: "DELETE"
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Retrieves messages associated with the thread
|
|
454
|
+
* @returns Promise containing thread messages and UI messages
|
|
455
|
+
*/
|
|
456
|
+
getMessages() {
|
|
457
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// src/resources/vector.ts
|
|
462
|
+
var Vector = class extends BaseResource {
|
|
463
|
+
constructor(options, vectorName) {
|
|
464
|
+
super(options);
|
|
465
|
+
this.vectorName = vectorName;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Retrieves details about a specific vector index
|
|
469
|
+
* @param indexName - Name of the index to get details for
|
|
470
|
+
* @returns Promise containing vector index details
|
|
471
|
+
*/
|
|
472
|
+
details(indexName) {
|
|
473
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Deletes a vector index
|
|
477
|
+
* @param indexName - Name of the index to delete
|
|
478
|
+
* @returns Promise indicating deletion success
|
|
479
|
+
*/
|
|
480
|
+
delete(indexName) {
|
|
481
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
|
|
482
|
+
method: "DELETE"
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Retrieves a list of all available indexes
|
|
487
|
+
* @returns Promise containing array of index names
|
|
488
|
+
*/
|
|
489
|
+
getIndexes() {
|
|
490
|
+
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Creates a new vector index
|
|
494
|
+
* @param params - Parameters for index creation including dimension and metric
|
|
495
|
+
* @returns Promise indicating creation success
|
|
496
|
+
*/
|
|
497
|
+
createIndex(params) {
|
|
498
|
+
return this.request(`/api/vector/${this.vectorName}/create-index`, {
|
|
499
|
+
method: "POST",
|
|
500
|
+
body: params
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Upserts vectors into an index
|
|
505
|
+
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
506
|
+
* @returns Promise containing array of vector IDs
|
|
507
|
+
*/
|
|
508
|
+
upsert(params) {
|
|
509
|
+
return this.request(`/api/vector/${this.vectorName}/upsert`, {
|
|
510
|
+
method: "POST",
|
|
511
|
+
body: params
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Queries vectors in an index
|
|
516
|
+
* @param params - Query parameters including query vector and search options
|
|
517
|
+
* @returns Promise containing query results
|
|
518
|
+
*/
|
|
519
|
+
query(params) {
|
|
520
|
+
return this.request(`/api/vector/${this.vectorName}/query`, {
|
|
521
|
+
method: "POST",
|
|
522
|
+
body: params
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// src/resources/workflow.ts
|
|
528
|
+
var RECORD_SEPARATOR = "";
|
|
529
|
+
var Workflow = class extends BaseResource {
|
|
530
|
+
constructor(options, workflowId) {
|
|
531
|
+
super(options);
|
|
532
|
+
this.workflowId = workflowId;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Retrieves details about the workflow
|
|
536
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
537
|
+
*/
|
|
538
|
+
details() {
|
|
539
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Retrieves all runs for a workflow
|
|
543
|
+
* @param params - Parameters for filtering runs
|
|
544
|
+
* @returns Promise containing workflow runs array
|
|
545
|
+
*/
|
|
546
|
+
runs(params) {
|
|
547
|
+
const searchParams = new URLSearchParams();
|
|
548
|
+
if (params?.fromDate) {
|
|
549
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
550
|
+
}
|
|
551
|
+
if (params?.toDate) {
|
|
552
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
553
|
+
}
|
|
554
|
+
if (params?.limit) {
|
|
555
|
+
searchParams.set("limit", String(params.limit));
|
|
556
|
+
}
|
|
557
|
+
if (params?.offset) {
|
|
558
|
+
searchParams.set("offset", String(params.offset));
|
|
559
|
+
}
|
|
560
|
+
if (params?.resourceId) {
|
|
561
|
+
searchParams.set("resourceId", params.resourceId);
|
|
562
|
+
}
|
|
563
|
+
if (searchParams.size) {
|
|
564
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
565
|
+
} else {
|
|
566
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* @deprecated Use `startAsync` instead
|
|
571
|
+
* Executes the workflow with the provided parameters
|
|
572
|
+
* @param params - Parameters required for workflow execution
|
|
573
|
+
* @returns Promise containing the workflow execution results
|
|
574
|
+
*/
|
|
575
|
+
execute(params) {
|
|
576
|
+
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
577
|
+
method: "POST",
|
|
578
|
+
body: params
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Creates a new workflow run
|
|
583
|
+
* @returns Promise containing the generated run ID
|
|
584
|
+
*/
|
|
585
|
+
createRun(params) {
|
|
586
|
+
const searchParams = new URLSearchParams();
|
|
587
|
+
if (!!params?.runId) {
|
|
588
|
+
searchParams.set("runId", params.runId);
|
|
589
|
+
}
|
|
590
|
+
return this.request(`/api/workflows/${this.workflowId}/createRun?${searchParams.toString()}`, {
|
|
591
|
+
method: "POST"
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
596
|
+
* @param params - Object containing the runId and triggerData
|
|
597
|
+
* @returns Promise containing success message
|
|
598
|
+
*/
|
|
599
|
+
start(params) {
|
|
600
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
601
|
+
method: "POST",
|
|
602
|
+
body: params?.triggerData
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
607
|
+
* @param stepId - ID of the step to resume
|
|
608
|
+
* @param runId - ID of the workflow run
|
|
609
|
+
* @param context - Context to resume the workflow with
|
|
610
|
+
* @returns Promise containing the workflow resume results
|
|
611
|
+
*/
|
|
612
|
+
resume({
|
|
613
|
+
stepId,
|
|
614
|
+
runId,
|
|
615
|
+
context
|
|
616
|
+
}) {
|
|
617
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
618
|
+
method: "POST",
|
|
619
|
+
body: {
|
|
620
|
+
stepId,
|
|
621
|
+
context
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
627
|
+
* @param params - Object containing the optional runId and triggerData
|
|
628
|
+
* @returns Promise containing the workflow execution results
|
|
629
|
+
*/
|
|
630
|
+
startAsync(params) {
|
|
631
|
+
const searchParams = new URLSearchParams();
|
|
632
|
+
if (!!params?.runId) {
|
|
633
|
+
searchParams.set("runId", params.runId);
|
|
634
|
+
}
|
|
635
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
636
|
+
method: "POST",
|
|
637
|
+
body: params?.triggerData
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
642
|
+
* @param params - Object containing the runId, stepId, and context
|
|
643
|
+
* @returns Promise containing the workflow resume results
|
|
644
|
+
*/
|
|
645
|
+
resumeAsync(params) {
|
|
646
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
647
|
+
method: "POST",
|
|
648
|
+
body: {
|
|
649
|
+
stepId: params.stepId,
|
|
650
|
+
context: params.context
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Creates an async generator that processes a readable stream and yields records
|
|
656
|
+
* separated by the Record Separator character (\x1E)
|
|
657
|
+
*
|
|
658
|
+
* @param stream - The readable stream to process
|
|
659
|
+
* @returns An async generator that yields parsed records
|
|
660
|
+
*/
|
|
661
|
+
async *streamProcessor(stream) {
|
|
662
|
+
const reader = stream.getReader();
|
|
663
|
+
let doneReading = false;
|
|
664
|
+
let buffer = "";
|
|
665
|
+
try {
|
|
666
|
+
while (!doneReading) {
|
|
667
|
+
const { done, value } = await reader.read();
|
|
668
|
+
doneReading = done;
|
|
669
|
+
if (done && !value) continue;
|
|
670
|
+
try {
|
|
671
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
672
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
673
|
+
buffer = chunks.pop() || "";
|
|
674
|
+
for (const chunk of chunks) {
|
|
675
|
+
if (chunk) {
|
|
676
|
+
if (typeof chunk === "string") {
|
|
677
|
+
try {
|
|
678
|
+
const parsedChunk = JSON.parse(chunk);
|
|
679
|
+
yield parsedChunk;
|
|
680
|
+
} catch {
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (buffer) {
|
|
689
|
+
try {
|
|
690
|
+
yield JSON.parse(buffer);
|
|
691
|
+
} catch {
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
} finally {
|
|
695
|
+
reader.cancel().catch(() => {
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Watches workflow transitions in real-time
|
|
701
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
702
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
703
|
+
*/
|
|
704
|
+
async watch({ runId }, onRecord) {
|
|
705
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
706
|
+
stream: true
|
|
707
|
+
});
|
|
708
|
+
if (!response.ok) {
|
|
709
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
710
|
+
}
|
|
711
|
+
if (!response.body) {
|
|
712
|
+
throw new Error("Response body is null");
|
|
713
|
+
}
|
|
714
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
715
|
+
onRecord(record);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
// src/resources/tool.ts
|
|
721
|
+
var Tool = class extends BaseResource {
|
|
722
|
+
constructor(options, toolId) {
|
|
723
|
+
super(options);
|
|
724
|
+
this.toolId = toolId;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Retrieves details about the tool
|
|
728
|
+
* @returns Promise containing tool details including description and schemas
|
|
729
|
+
*/
|
|
730
|
+
details() {
|
|
731
|
+
return this.request(`/api/tools/${this.toolId}`);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Executes the tool with the provided parameters
|
|
735
|
+
* @param params - Parameters required for tool execution
|
|
736
|
+
* @returns Promise containing the tool execution results
|
|
737
|
+
*/
|
|
738
|
+
execute(params) {
|
|
739
|
+
const url = new URLSearchParams();
|
|
740
|
+
if (params.runId) {
|
|
741
|
+
url.set("runId", params.runId);
|
|
742
|
+
}
|
|
743
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
744
|
+
method: "POST",
|
|
745
|
+
body: params.data
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
// src/resources/vnext-workflow.ts
|
|
751
|
+
var RECORD_SEPARATOR2 = "";
|
|
752
|
+
var VNextWorkflow = class extends BaseResource {
|
|
753
|
+
constructor(options, workflowId) {
|
|
754
|
+
super(options);
|
|
755
|
+
this.workflowId = workflowId;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Creates an async generator that processes a readable stream and yields vNext workflow records
|
|
759
|
+
* separated by the Record Separator character (\x1E)
|
|
760
|
+
*
|
|
761
|
+
* @param stream - The readable stream to process
|
|
762
|
+
* @returns An async generator that yields parsed records
|
|
763
|
+
*/
|
|
764
|
+
async *streamProcessor(stream) {
|
|
765
|
+
const reader = stream.getReader();
|
|
766
|
+
let doneReading = false;
|
|
767
|
+
let buffer = "";
|
|
768
|
+
try {
|
|
769
|
+
while (!doneReading) {
|
|
770
|
+
const { done, value } = await reader.read();
|
|
771
|
+
doneReading = done;
|
|
772
|
+
if (done && !value) continue;
|
|
773
|
+
try {
|
|
774
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
775
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
776
|
+
buffer = chunks.pop() || "";
|
|
777
|
+
for (const chunk of chunks) {
|
|
778
|
+
if (chunk) {
|
|
779
|
+
if (typeof chunk === "string") {
|
|
780
|
+
try {
|
|
781
|
+
const parsedChunk = JSON.parse(chunk);
|
|
782
|
+
yield parsedChunk;
|
|
783
|
+
} catch {
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
} catch {
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
if (buffer) {
|
|
792
|
+
try {
|
|
793
|
+
yield JSON.parse(buffer);
|
|
794
|
+
} catch {
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
} finally {
|
|
798
|
+
reader.cancel().catch(() => {
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Retrieves details about the vNext workflow
|
|
804
|
+
* @returns Promise containing vNext workflow details including steps and graphs
|
|
805
|
+
*/
|
|
806
|
+
details() {
|
|
807
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}`);
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Retrieves all runs for a vNext workflow
|
|
811
|
+
* @param params - Parameters for filtering runs
|
|
812
|
+
* @returns Promise containing vNext workflow runs array
|
|
813
|
+
*/
|
|
814
|
+
runs(params) {
|
|
815
|
+
const searchParams = new URLSearchParams();
|
|
816
|
+
if (params?.fromDate) {
|
|
817
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
818
|
+
}
|
|
819
|
+
if (params?.toDate) {
|
|
820
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
821
|
+
}
|
|
822
|
+
if (params?.limit) {
|
|
823
|
+
searchParams.set("limit", String(params.limit));
|
|
824
|
+
}
|
|
825
|
+
if (params?.offset) {
|
|
826
|
+
searchParams.set("offset", String(params.offset));
|
|
827
|
+
}
|
|
828
|
+
if (params?.resourceId) {
|
|
829
|
+
searchParams.set("resourceId", params.resourceId);
|
|
830
|
+
}
|
|
831
|
+
if (searchParams.size) {
|
|
832
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
|
|
833
|
+
} else {
|
|
834
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Creates a new vNext workflow run
|
|
839
|
+
* @param params - Optional object containing the optional runId
|
|
840
|
+
* @returns Promise containing the runId of the created run
|
|
841
|
+
*/
|
|
842
|
+
createRun(params) {
|
|
843
|
+
const searchParams = new URLSearchParams();
|
|
844
|
+
if (!!params?.runId) {
|
|
845
|
+
searchParams.set("runId", params.runId);
|
|
846
|
+
}
|
|
847
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
848
|
+
method: "POST"
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Starts a vNext workflow run synchronously without waiting for the workflow to complete
|
|
853
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
854
|
+
* @returns Promise containing success message
|
|
855
|
+
*/
|
|
856
|
+
start(params) {
|
|
857
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
858
|
+
method: "POST",
|
|
859
|
+
body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
|
|
864
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
865
|
+
* @returns Promise containing success message
|
|
866
|
+
*/
|
|
867
|
+
resume({
|
|
868
|
+
step,
|
|
869
|
+
runId,
|
|
870
|
+
resumeData,
|
|
871
|
+
runtimeContext
|
|
872
|
+
}) {
|
|
873
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
874
|
+
method: "POST",
|
|
875
|
+
stream: true,
|
|
876
|
+
body: {
|
|
877
|
+
step,
|
|
878
|
+
resumeData,
|
|
879
|
+
runtimeContext
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
885
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
886
|
+
* @returns Promise containing the vNext workflow execution results
|
|
887
|
+
*/
|
|
888
|
+
startAsync(params) {
|
|
889
|
+
const searchParams = new URLSearchParams();
|
|
890
|
+
if (!!params?.runId) {
|
|
891
|
+
searchParams.set("runId", params.runId);
|
|
892
|
+
}
|
|
893
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
894
|
+
method: "POST",
|
|
895
|
+
body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
|
|
900
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
901
|
+
* @returns Promise containing the vNext workflow resume results
|
|
902
|
+
*/
|
|
903
|
+
resumeAsync(params) {
|
|
904
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
905
|
+
method: "POST",
|
|
906
|
+
body: {
|
|
907
|
+
step: params.step,
|
|
908
|
+
resumeData: params.resumeData,
|
|
909
|
+
runtimeContext: params.runtimeContext
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Watches vNext workflow transitions in real-time
|
|
915
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
916
|
+
* @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
|
|
917
|
+
*/
|
|
918
|
+
async watch({ runId }, onRecord) {
|
|
919
|
+
const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
|
|
920
|
+
stream: true
|
|
921
|
+
});
|
|
922
|
+
if (!response.ok) {
|
|
923
|
+
throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
|
|
924
|
+
}
|
|
925
|
+
if (!response.body) {
|
|
926
|
+
throw new Error("Response body is null");
|
|
927
|
+
}
|
|
928
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
929
|
+
onRecord(record);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// src/client.ts
|
|
935
|
+
var MastraClient = class extends BaseResource {
|
|
936
|
+
constructor(options) {
|
|
937
|
+
super(options);
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Retrieves all available agents
|
|
941
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
942
|
+
*/
|
|
943
|
+
getAgents() {
|
|
944
|
+
return this.request("/api/agents");
|
|
945
|
+
}
|
|
946
|
+
async getAGUI({ resourceId }) {
|
|
947
|
+
const agents = await this.getAgents();
|
|
948
|
+
return Object.entries(agents).reduce(
|
|
949
|
+
(acc, [agentId]) => {
|
|
950
|
+
const agent = this.getAgent(agentId);
|
|
951
|
+
acc[agentId] = new AGUIAdapter({
|
|
952
|
+
agentId,
|
|
953
|
+
agent,
|
|
954
|
+
resourceId
|
|
955
|
+
});
|
|
956
|
+
return acc;
|
|
957
|
+
},
|
|
958
|
+
{}
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Gets an agent instance by ID
|
|
963
|
+
* @param agentId - ID of the agent to retrieve
|
|
964
|
+
* @returns Agent instance
|
|
965
|
+
*/
|
|
966
|
+
getAgent(agentId) {
|
|
967
|
+
return new Agent(this.options, agentId);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Retrieves memory threads for a resource
|
|
971
|
+
* @param params - Parameters containing the resource ID
|
|
972
|
+
* @returns Promise containing array of memory threads
|
|
973
|
+
*/
|
|
974
|
+
getMemoryThreads(params) {
|
|
975
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* Creates a new memory thread
|
|
979
|
+
* @param params - Parameters for creating the memory thread
|
|
980
|
+
* @returns Promise containing the created memory thread
|
|
981
|
+
*/
|
|
982
|
+
createMemoryThread(params) {
|
|
983
|
+
return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Gets a memory thread instance by ID
|
|
987
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
988
|
+
* @returns MemoryThread instance
|
|
989
|
+
*/
|
|
990
|
+
getMemoryThread(threadId, agentId) {
|
|
991
|
+
return new MemoryThread(this.options, threadId, agentId);
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Saves messages to memory
|
|
995
|
+
* @param params - Parameters containing messages to save
|
|
996
|
+
* @returns Promise containing the saved messages
|
|
997
|
+
*/
|
|
998
|
+
saveMessageToMemory(params) {
|
|
999
|
+
return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
|
|
1000
|
+
method: "POST",
|
|
1001
|
+
body: params
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Gets the status of the memory system
|
|
1006
|
+
* @returns Promise containing memory system status
|
|
1007
|
+
*/
|
|
1008
|
+
getMemoryStatus(agentId) {
|
|
1009
|
+
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Retrieves all available tools
|
|
1013
|
+
* @returns Promise containing map of tool IDs to tool details
|
|
1014
|
+
*/
|
|
1015
|
+
getTools() {
|
|
1016
|
+
return this.request("/api/tools");
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Gets a tool instance by ID
|
|
1020
|
+
* @param toolId - ID of the tool to retrieve
|
|
1021
|
+
* @returns Tool instance
|
|
1022
|
+
*/
|
|
1023
|
+
getTool(toolId) {
|
|
1024
|
+
return new Tool(this.options, toolId);
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Retrieves all available workflows
|
|
1028
|
+
* @returns Promise containing map of workflow IDs to workflow details
|
|
1029
|
+
*/
|
|
1030
|
+
getWorkflows() {
|
|
1031
|
+
return this.request("/api/workflows");
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Gets a workflow instance by ID
|
|
1035
|
+
* @param workflowId - ID of the workflow to retrieve
|
|
1036
|
+
* @returns Workflow instance
|
|
1037
|
+
*/
|
|
1038
|
+
getWorkflow(workflowId) {
|
|
1039
|
+
return new Workflow(this.options, workflowId);
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Retrieves all available vNext workflows
|
|
1043
|
+
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
1044
|
+
*/
|
|
1045
|
+
getVNextWorkflows() {
|
|
1046
|
+
return this.request("/api/workflows/v-next");
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Gets a vNext workflow instance by ID
|
|
1050
|
+
* @param workflowId - ID of the vNext workflow to retrieve
|
|
1051
|
+
* @returns vNext Workflow instance
|
|
1052
|
+
*/
|
|
1053
|
+
getVNextWorkflow(workflowId) {
|
|
1054
|
+
return new VNextWorkflow(this.options, workflowId);
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Gets a vector instance by name
|
|
1058
|
+
* @param vectorName - Name of the vector to retrieve
|
|
1059
|
+
* @returns Vector instance
|
|
1060
|
+
*/
|
|
1061
|
+
getVector(vectorName) {
|
|
1062
|
+
return new Vector(this.options, vectorName);
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Retrieves logs
|
|
1066
|
+
* @param params - Parameters for filtering logs
|
|
1067
|
+
* @returns Promise containing array of log messages
|
|
1068
|
+
*/
|
|
1069
|
+
getLogs(params) {
|
|
1070
|
+
return this.request(`/api/logs?transportId=${params.transportId}`);
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Gets logs for a specific run
|
|
1074
|
+
* @param params - Parameters containing run ID to retrieve
|
|
1075
|
+
* @returns Promise containing array of log messages
|
|
1076
|
+
*/
|
|
1077
|
+
getLogForRun(params) {
|
|
1078
|
+
return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* List of all log transports
|
|
1082
|
+
* @returns Promise containing list of log transports
|
|
1083
|
+
*/
|
|
1084
|
+
getLogTransports() {
|
|
1085
|
+
return this.request("/api/logs/transports");
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* List of all traces (paged)
|
|
1089
|
+
* @param params - Parameters for filtering traces
|
|
1090
|
+
* @returns Promise containing telemetry data
|
|
1091
|
+
*/
|
|
1092
|
+
getTelemetry(params) {
|
|
1093
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
1094
|
+
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
1095
|
+
const searchParams = new URLSearchParams();
|
|
1096
|
+
if (name) {
|
|
1097
|
+
searchParams.set("name", name);
|
|
1098
|
+
}
|
|
1099
|
+
if (scope) {
|
|
1100
|
+
searchParams.set("scope", scope);
|
|
1101
|
+
}
|
|
1102
|
+
if (page) {
|
|
1103
|
+
searchParams.set("page", String(page));
|
|
1104
|
+
}
|
|
1105
|
+
if (perPage) {
|
|
1106
|
+
searchParams.set("perPage", String(perPage));
|
|
1107
|
+
}
|
|
1108
|
+
if (_attribute) {
|
|
1109
|
+
if (Array.isArray(_attribute)) {
|
|
1110
|
+
for (const attr of _attribute) {
|
|
1111
|
+
searchParams.append("attribute", attr);
|
|
1112
|
+
}
|
|
1113
|
+
} else {
|
|
1114
|
+
searchParams.set("attribute", _attribute);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
if (fromDate) {
|
|
1118
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1119
|
+
}
|
|
1120
|
+
if (toDate) {
|
|
1121
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1122
|
+
}
|
|
1123
|
+
if (searchParams.size) {
|
|
1124
|
+
return this.request(`/api/telemetry?${searchParams}`);
|
|
1125
|
+
} else {
|
|
1126
|
+
return this.request(`/api/telemetry`);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Retrieves all available networks
|
|
1131
|
+
* @returns Promise containing map of network IDs to network details
|
|
1132
|
+
*/
|
|
1133
|
+
getNetworks() {
|
|
1134
|
+
return this.request("/api/networks");
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Gets a network instance by ID
|
|
1138
|
+
* @param networkId - ID of the network to retrieve
|
|
1139
|
+
* @returns Network instance
|
|
1140
|
+
*/
|
|
1141
|
+
getNetwork(networkId) {
|
|
1142
|
+
return new Network(this.options, networkId);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
exports.MastraClient = MastraClient;
|