@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-update-scorers-api-20250801170445
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 +1110 -2
- package/LICENSE.md +11 -42
- package/README.md +2 -1
- package/dist/adapters/agui.d.ts +23 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +265 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +1403 -131
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -730
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1401 -133
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +44 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +112 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +422 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +18 -0
- package/integration-tests/src/mastra/index.ts +35 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +28 -19
- package/src/adapters/agui.test.ts +164 -9
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +386 -22
- package/src/example.ts +59 -29
- package/src/index.test.ts +522 -6
- package/src/index.ts +1 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +629 -48
- package/src/resources/base.ts +7 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +49 -3
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +81 -0
- package/src/resources/network.ts +10 -16
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +255 -96
- package/src/types.ts +265 -25
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/index.d.cts +0 -730
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,14 @@ var client = require('@ag-ui/client');
|
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
6
|
var zod = require('zod');
|
|
7
|
-
var
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
9
|
+
var uuid = require('@lukeed/uuid');
|
|
10
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
8
15
|
|
|
9
16
|
// src/adapters/agui.ts
|
|
10
17
|
var AGUIAdapter = class extends client.AbstractAgent {
|
|
@@ -44,6 +51,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
44
51
|
)
|
|
45
52
|
}).then((response) => {
|
|
46
53
|
let currentMessageId = void 0;
|
|
54
|
+
let isInTextMessage = false;
|
|
47
55
|
return response.processDataStream({
|
|
48
56
|
onTextPart: (text) => {
|
|
49
57
|
if (currentMessageId === void 0) {
|
|
@@ -54,6 +62,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
54
62
|
role: "assistant"
|
|
55
63
|
};
|
|
56
64
|
subscriber.next(message2);
|
|
65
|
+
isInTextMessage = true;
|
|
57
66
|
}
|
|
58
67
|
const message = {
|
|
59
68
|
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
@@ -62,14 +71,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
62
71
|
};
|
|
63
72
|
subscriber.next(message);
|
|
64
73
|
},
|
|
65
|
-
onFinishMessagePart: (
|
|
66
|
-
console.log("onFinishMessagePart", message);
|
|
74
|
+
onFinishMessagePart: () => {
|
|
67
75
|
if (currentMessageId !== void 0) {
|
|
68
|
-
const
|
|
76
|
+
const message = {
|
|
69
77
|
type: client.EventType.TEXT_MESSAGE_END,
|
|
70
78
|
messageId: currentMessageId
|
|
71
79
|
};
|
|
72
|
-
subscriber.next(
|
|
80
|
+
subscriber.next(message);
|
|
81
|
+
isInTextMessage = false;
|
|
73
82
|
}
|
|
74
83
|
subscriber.next({
|
|
75
84
|
type: client.EventType.RUN_FINISHED,
|
|
@@ -80,6 +89,14 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
80
89
|
},
|
|
81
90
|
onToolCallPart(streamPart) {
|
|
82
91
|
const parentMessageId = currentMessageId || generateUUID();
|
|
92
|
+
if (isInTextMessage) {
|
|
93
|
+
const message = {
|
|
94
|
+
type: client.EventType.TEXT_MESSAGE_END,
|
|
95
|
+
messageId: parentMessageId
|
|
96
|
+
};
|
|
97
|
+
subscriber.next(message);
|
|
98
|
+
isInTextMessage = false;
|
|
99
|
+
}
|
|
83
100
|
subscriber.next({
|
|
84
101
|
type: client.EventType.TOOL_CALL_START,
|
|
85
102
|
toolCallId: streamPart.toolCallId,
|
|
@@ -100,7 +117,7 @@ var AGUIAdapter = class extends client.AbstractAgent {
|
|
|
100
117
|
}
|
|
101
118
|
});
|
|
102
119
|
}).catch((error) => {
|
|
103
|
-
console.
|
|
120
|
+
console.error("error", error);
|
|
104
121
|
subscriber.error(error);
|
|
105
122
|
});
|
|
106
123
|
return () => {
|
|
@@ -149,6 +166,17 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
149
166
|
role: "assistant",
|
|
150
167
|
content: parts
|
|
151
168
|
});
|
|
169
|
+
if (message.toolCalls?.length) {
|
|
170
|
+
result.push({
|
|
171
|
+
role: "tool",
|
|
172
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
173
|
+
type: "tool-result",
|
|
174
|
+
toolCallId: toolCall.id,
|
|
175
|
+
toolName: toolCall.function.name,
|
|
176
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
177
|
+
}))
|
|
178
|
+
});
|
|
179
|
+
}
|
|
152
180
|
} else if (message.role === "user") {
|
|
153
181
|
result.push({
|
|
154
182
|
role: "user",
|
|
@@ -170,6 +198,39 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
170
198
|
}
|
|
171
199
|
return result;
|
|
172
200
|
}
|
|
201
|
+
function zodToJsonSchema(zodSchema) {
|
|
202
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
203
|
+
return zodSchema;
|
|
204
|
+
}
|
|
205
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
206
|
+
}
|
|
207
|
+
function processClientTools(clientTools) {
|
|
208
|
+
if (!clientTools) {
|
|
209
|
+
return void 0;
|
|
210
|
+
}
|
|
211
|
+
return Object.fromEntries(
|
|
212
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
213
|
+
if (isVercelTool.isVercelTool(value)) {
|
|
214
|
+
return [
|
|
215
|
+
key,
|
|
216
|
+
{
|
|
217
|
+
...value,
|
|
218
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
219
|
+
}
|
|
220
|
+
];
|
|
221
|
+
} else {
|
|
222
|
+
return [
|
|
223
|
+
key,
|
|
224
|
+
{
|
|
225
|
+
...value,
|
|
226
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
227
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
228
|
+
}
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
);
|
|
233
|
+
}
|
|
173
234
|
|
|
174
235
|
// src/resources/base.ts
|
|
175
236
|
var BaseResource = class {
|
|
@@ -189,14 +250,16 @@ var BaseResource = class {
|
|
|
189
250
|
let delay = backoffMs;
|
|
190
251
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
191
252
|
try {
|
|
192
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
253
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
193
254
|
...options,
|
|
194
255
|
headers: {
|
|
256
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
195
257
|
...headers,
|
|
196
258
|
...options.headers
|
|
197
259
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
198
260
|
// 'x-mastra-client-type': 'js',
|
|
199
261
|
},
|
|
262
|
+
signal: this.options.abortSignal,
|
|
200
263
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
201
264
|
});
|
|
202
265
|
if (!response.ok) {
|
|
@@ -229,8 +292,15 @@ var BaseResource = class {
|
|
|
229
292
|
throw lastError || new Error("Request failed");
|
|
230
293
|
}
|
|
231
294
|
};
|
|
232
|
-
|
|
233
|
-
|
|
295
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
296
|
+
if (runtimeContext$1) {
|
|
297
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
298
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
299
|
+
}
|
|
300
|
+
return runtimeContext$1;
|
|
301
|
+
}
|
|
302
|
+
return void 0;
|
|
303
|
+
}
|
|
234
304
|
var AgentVoice = class extends BaseResource {
|
|
235
305
|
constructor(options, agentId) {
|
|
236
306
|
super(options);
|
|
@@ -277,6 +347,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
277
347
|
getSpeakers() {
|
|
278
348
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
279
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* Get the listener configuration for the agent's voice provider
|
|
352
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
353
|
+
*/
|
|
354
|
+
getListener() {
|
|
355
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
356
|
+
}
|
|
280
357
|
};
|
|
281
358
|
var Agent = class extends BaseResource {
|
|
282
359
|
constructor(options, agentId) {
|
|
@@ -292,21 +369,325 @@ var Agent = class extends BaseResource {
|
|
|
292
369
|
details() {
|
|
293
370
|
return this.request(`/api/agents/${this.agentId}`);
|
|
294
371
|
}
|
|
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) {
|
|
372
|
+
async generate(params) {
|
|
301
373
|
const processedParams = {
|
|
302
374
|
...params,
|
|
303
|
-
output: params.output
|
|
304
|
-
experimental_output: params.experimental_output
|
|
375
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
376
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
377
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
378
|
+
clientTools: processClientTools(params.clientTools)
|
|
305
379
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
380
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
381
|
+
const response = await this.request(
|
|
382
|
+
`/api/agents/${this.agentId}/generate`,
|
|
383
|
+
{
|
|
384
|
+
method: "POST",
|
|
385
|
+
body: processedParams
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
if (response.finishReason === "tool-calls") {
|
|
389
|
+
const toolCalls = response.toolCalls;
|
|
390
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
391
|
+
return response;
|
|
392
|
+
}
|
|
393
|
+
for (const toolCall of toolCalls) {
|
|
394
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
395
|
+
if (clientTool && clientTool.execute) {
|
|
396
|
+
const result = await clientTool.execute(
|
|
397
|
+
{ context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
|
|
398
|
+
{
|
|
399
|
+
messages: response.messages,
|
|
400
|
+
toolCallId: toolCall?.toolCallId
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
const updatedMessages = [
|
|
404
|
+
{
|
|
405
|
+
role: "user",
|
|
406
|
+
content: params.messages
|
|
407
|
+
},
|
|
408
|
+
...response.response.messages,
|
|
409
|
+
{
|
|
410
|
+
role: "tool",
|
|
411
|
+
content: [
|
|
412
|
+
{
|
|
413
|
+
type: "tool-result",
|
|
414
|
+
toolCallId: toolCall.toolCallId,
|
|
415
|
+
toolName: toolCall.toolName,
|
|
416
|
+
result
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
return this.generate({
|
|
422
|
+
...params,
|
|
423
|
+
messages: updatedMessages
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return response;
|
|
429
|
+
}
|
|
430
|
+
async processChatResponse({
|
|
431
|
+
stream,
|
|
432
|
+
update,
|
|
433
|
+
onToolCall,
|
|
434
|
+
onFinish,
|
|
435
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
436
|
+
lastMessage
|
|
437
|
+
}) {
|
|
438
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
439
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
440
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
441
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
442
|
+
}, 0) ?? 0) : 0;
|
|
443
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
444
|
+
id: uuid.v4(),
|
|
445
|
+
createdAt: getCurrentDate(),
|
|
446
|
+
role: "assistant",
|
|
447
|
+
content: "",
|
|
448
|
+
parts: []
|
|
449
|
+
};
|
|
450
|
+
let currentTextPart = void 0;
|
|
451
|
+
let currentReasoningPart = void 0;
|
|
452
|
+
let currentReasoningTextDetail = void 0;
|
|
453
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
454
|
+
const part = message.parts.find(
|
|
455
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
456
|
+
);
|
|
457
|
+
if (part != null) {
|
|
458
|
+
part.toolInvocation = invocation;
|
|
459
|
+
} else {
|
|
460
|
+
message.parts.push({
|
|
461
|
+
type: "tool-invocation",
|
|
462
|
+
toolInvocation: invocation
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
const data = [];
|
|
467
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
468
|
+
const partialToolCalls = {};
|
|
469
|
+
let usage = {
|
|
470
|
+
completionTokens: NaN,
|
|
471
|
+
promptTokens: NaN,
|
|
472
|
+
totalTokens: NaN
|
|
473
|
+
};
|
|
474
|
+
let finishReason = "unknown";
|
|
475
|
+
function execUpdate() {
|
|
476
|
+
const copiedData = [...data];
|
|
477
|
+
if (messageAnnotations?.length) {
|
|
478
|
+
message.annotations = messageAnnotations;
|
|
479
|
+
}
|
|
480
|
+
const copiedMessage = {
|
|
481
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
482
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
483
|
+
...structuredClone(message),
|
|
484
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
485
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
486
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
487
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
488
|
+
// forwarded to rendering):
|
|
489
|
+
revisionId: uuid.v4()
|
|
490
|
+
};
|
|
491
|
+
update({
|
|
492
|
+
message: copiedMessage,
|
|
493
|
+
data: copiedData,
|
|
494
|
+
replaceLastMessage
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
await uiUtils.processDataStream({
|
|
498
|
+
stream,
|
|
499
|
+
onTextPart(value) {
|
|
500
|
+
if (currentTextPart == null) {
|
|
501
|
+
currentTextPart = {
|
|
502
|
+
type: "text",
|
|
503
|
+
text: value
|
|
504
|
+
};
|
|
505
|
+
message.parts.push(currentTextPart);
|
|
506
|
+
} else {
|
|
507
|
+
currentTextPart.text += value;
|
|
508
|
+
}
|
|
509
|
+
message.content += value;
|
|
510
|
+
execUpdate();
|
|
511
|
+
},
|
|
512
|
+
onReasoningPart(value) {
|
|
513
|
+
if (currentReasoningTextDetail == null) {
|
|
514
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
515
|
+
if (currentReasoningPart != null) {
|
|
516
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
currentReasoningTextDetail.text += value;
|
|
520
|
+
}
|
|
521
|
+
if (currentReasoningPart == null) {
|
|
522
|
+
currentReasoningPart = {
|
|
523
|
+
type: "reasoning",
|
|
524
|
+
reasoning: value,
|
|
525
|
+
details: [currentReasoningTextDetail]
|
|
526
|
+
};
|
|
527
|
+
message.parts.push(currentReasoningPart);
|
|
528
|
+
} else {
|
|
529
|
+
currentReasoningPart.reasoning += value;
|
|
530
|
+
}
|
|
531
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
532
|
+
execUpdate();
|
|
533
|
+
},
|
|
534
|
+
onReasoningSignaturePart(value) {
|
|
535
|
+
if (currentReasoningTextDetail != null) {
|
|
536
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
onRedactedReasoningPart(value) {
|
|
540
|
+
if (currentReasoningPart == null) {
|
|
541
|
+
currentReasoningPart = {
|
|
542
|
+
type: "reasoning",
|
|
543
|
+
reasoning: "",
|
|
544
|
+
details: []
|
|
545
|
+
};
|
|
546
|
+
message.parts.push(currentReasoningPart);
|
|
547
|
+
}
|
|
548
|
+
currentReasoningPart.details.push({
|
|
549
|
+
type: "redacted",
|
|
550
|
+
data: value.data
|
|
551
|
+
});
|
|
552
|
+
currentReasoningTextDetail = void 0;
|
|
553
|
+
execUpdate();
|
|
554
|
+
},
|
|
555
|
+
onFilePart(value) {
|
|
556
|
+
message.parts.push({
|
|
557
|
+
type: "file",
|
|
558
|
+
mimeType: value.mimeType,
|
|
559
|
+
data: value.data
|
|
560
|
+
});
|
|
561
|
+
execUpdate();
|
|
562
|
+
},
|
|
563
|
+
onSourcePart(value) {
|
|
564
|
+
message.parts.push({
|
|
565
|
+
type: "source",
|
|
566
|
+
source: value
|
|
567
|
+
});
|
|
568
|
+
execUpdate();
|
|
569
|
+
},
|
|
570
|
+
onToolCallStreamingStartPart(value) {
|
|
571
|
+
if (message.toolInvocations == null) {
|
|
572
|
+
message.toolInvocations = [];
|
|
573
|
+
}
|
|
574
|
+
partialToolCalls[value.toolCallId] = {
|
|
575
|
+
text: "",
|
|
576
|
+
step,
|
|
577
|
+
toolName: value.toolName,
|
|
578
|
+
index: message.toolInvocations.length
|
|
579
|
+
};
|
|
580
|
+
const invocation = {
|
|
581
|
+
state: "partial-call",
|
|
582
|
+
step,
|
|
583
|
+
toolCallId: value.toolCallId,
|
|
584
|
+
toolName: value.toolName,
|
|
585
|
+
args: void 0
|
|
586
|
+
};
|
|
587
|
+
message.toolInvocations.push(invocation);
|
|
588
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
589
|
+
execUpdate();
|
|
590
|
+
},
|
|
591
|
+
onToolCallDeltaPart(value) {
|
|
592
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
593
|
+
partialToolCall.text += value.argsTextDelta;
|
|
594
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
595
|
+
const invocation = {
|
|
596
|
+
state: "partial-call",
|
|
597
|
+
step: partialToolCall.step,
|
|
598
|
+
toolCallId: value.toolCallId,
|
|
599
|
+
toolName: partialToolCall.toolName,
|
|
600
|
+
args: partialArgs
|
|
601
|
+
};
|
|
602
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
603
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
604
|
+
execUpdate();
|
|
605
|
+
},
|
|
606
|
+
async onToolCallPart(value) {
|
|
607
|
+
const invocation = {
|
|
608
|
+
state: "call",
|
|
609
|
+
step,
|
|
610
|
+
...value
|
|
611
|
+
};
|
|
612
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
613
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
614
|
+
} else {
|
|
615
|
+
if (message.toolInvocations == null) {
|
|
616
|
+
message.toolInvocations = [];
|
|
617
|
+
}
|
|
618
|
+
message.toolInvocations.push(invocation);
|
|
619
|
+
}
|
|
620
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
621
|
+
execUpdate();
|
|
622
|
+
if (onToolCall) {
|
|
623
|
+
const result = await onToolCall({ toolCall: value });
|
|
624
|
+
if (result != null) {
|
|
625
|
+
const invocation2 = {
|
|
626
|
+
state: "result",
|
|
627
|
+
step,
|
|
628
|
+
...value,
|
|
629
|
+
result
|
|
630
|
+
};
|
|
631
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
632
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
633
|
+
execUpdate();
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
onToolResultPart(value) {
|
|
638
|
+
const toolInvocations = message.toolInvocations;
|
|
639
|
+
if (toolInvocations == null) {
|
|
640
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
641
|
+
}
|
|
642
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
643
|
+
if (toolInvocationIndex === -1) {
|
|
644
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
645
|
+
}
|
|
646
|
+
const invocation = {
|
|
647
|
+
...toolInvocations[toolInvocationIndex],
|
|
648
|
+
state: "result",
|
|
649
|
+
...value
|
|
650
|
+
};
|
|
651
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
652
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
653
|
+
execUpdate();
|
|
654
|
+
},
|
|
655
|
+
onDataPart(value) {
|
|
656
|
+
data.push(...value);
|
|
657
|
+
execUpdate();
|
|
658
|
+
},
|
|
659
|
+
onMessageAnnotationsPart(value) {
|
|
660
|
+
if (messageAnnotations == null) {
|
|
661
|
+
messageAnnotations = [...value];
|
|
662
|
+
} else {
|
|
663
|
+
messageAnnotations.push(...value);
|
|
664
|
+
}
|
|
665
|
+
execUpdate();
|
|
666
|
+
},
|
|
667
|
+
onFinishStepPart(value) {
|
|
668
|
+
step += 1;
|
|
669
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
670
|
+
currentReasoningPart = void 0;
|
|
671
|
+
currentReasoningTextDetail = void 0;
|
|
672
|
+
},
|
|
673
|
+
onStartStepPart(value) {
|
|
674
|
+
if (!replaceLastMessage) {
|
|
675
|
+
message.id = value.messageId;
|
|
676
|
+
}
|
|
677
|
+
message.parts.push({ type: "step-start" });
|
|
678
|
+
execUpdate();
|
|
679
|
+
},
|
|
680
|
+
onFinishMessagePart(value) {
|
|
681
|
+
finishReason = value.finishReason;
|
|
682
|
+
if (value.usage != null) {
|
|
683
|
+
usage = value.usage;
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
onErrorPart(error) {
|
|
687
|
+
throw new Error(error);
|
|
688
|
+
}
|
|
309
689
|
});
|
|
690
|
+
onFinish?.({ message, finishReason, usage });
|
|
310
691
|
}
|
|
311
692
|
/**
|
|
312
693
|
* Streams a response from the agent
|
|
@@ -316,9 +697,30 @@ var Agent = class extends BaseResource {
|
|
|
316
697
|
async stream(params) {
|
|
317
698
|
const processedParams = {
|
|
318
699
|
...params,
|
|
319
|
-
output: params.output
|
|
320
|
-
experimental_output: params.experimental_output
|
|
700
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
701
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
702
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
703
|
+
clientTools: processClientTools(params.clientTools)
|
|
704
|
+
};
|
|
705
|
+
const { readable, writable } = new TransformStream();
|
|
706
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
707
|
+
const streamResponse = new Response(readable, {
|
|
708
|
+
status: response.status,
|
|
709
|
+
statusText: response.statusText,
|
|
710
|
+
headers: response.headers
|
|
711
|
+
});
|
|
712
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
713
|
+
await uiUtils.processDataStream({
|
|
714
|
+
stream: streamResponse.body,
|
|
715
|
+
...options
|
|
716
|
+
});
|
|
321
717
|
};
|
|
718
|
+
return streamResponse;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Processes the stream response and handles tool calls
|
|
722
|
+
*/
|
|
723
|
+
async processStreamResponse(processedParams, writable) {
|
|
322
724
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
323
725
|
method: "POST",
|
|
324
726
|
body: processedParams,
|
|
@@ -327,12 +729,104 @@ var Agent = class extends BaseResource {
|
|
|
327
729
|
if (!response.body) {
|
|
328
730
|
throw new Error("No response body");
|
|
329
731
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
732
|
+
try {
|
|
733
|
+
let toolCalls = [];
|
|
734
|
+
let messages = [];
|
|
735
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
736
|
+
streamForWritable.pipeTo(writable, {
|
|
737
|
+
preventClose: true
|
|
738
|
+
}).catch((error) => {
|
|
739
|
+
console.error("Error piping to writable stream:", error);
|
|
334
740
|
});
|
|
335
|
-
|
|
741
|
+
this.processChatResponse({
|
|
742
|
+
stream: streamForProcessing,
|
|
743
|
+
update: ({ message }) => {
|
|
744
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
745
|
+
if (existingIndex !== -1) {
|
|
746
|
+
messages[existingIndex] = message;
|
|
747
|
+
} else {
|
|
748
|
+
messages.push(message);
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
onFinish: async ({ finishReason, message }) => {
|
|
752
|
+
if (finishReason === "tool-calls") {
|
|
753
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
754
|
+
if (toolCall) {
|
|
755
|
+
toolCalls.push(toolCall);
|
|
756
|
+
}
|
|
757
|
+
for (const toolCall2 of toolCalls) {
|
|
758
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
759
|
+
if (clientTool && clientTool.execute) {
|
|
760
|
+
const result = await clientTool.execute(
|
|
761
|
+
{
|
|
762
|
+
context: toolCall2?.args,
|
|
763
|
+
runId: processedParams.runId,
|
|
764
|
+
resourceId: processedParams.resourceId,
|
|
765
|
+
threadId: processedParams.threadId,
|
|
766
|
+
runtimeContext: processedParams.runtimeContext
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
messages: response.messages,
|
|
770
|
+
toolCallId: toolCall2?.toolCallId
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
774
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
775
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
776
|
+
);
|
|
777
|
+
if (toolInvocationPart) {
|
|
778
|
+
toolInvocationPart.toolInvocation = {
|
|
779
|
+
...toolInvocationPart.toolInvocation,
|
|
780
|
+
state: "result",
|
|
781
|
+
result
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
785
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
786
|
+
);
|
|
787
|
+
if (toolInvocation) {
|
|
788
|
+
toolInvocation.state = "result";
|
|
789
|
+
toolInvocation.result = result;
|
|
790
|
+
}
|
|
791
|
+
const writer = writable.getWriter();
|
|
792
|
+
try {
|
|
793
|
+
await writer.write(
|
|
794
|
+
new TextEncoder().encode(
|
|
795
|
+
"a:" + JSON.stringify({
|
|
796
|
+
toolCallId: toolCall2.toolCallId,
|
|
797
|
+
result
|
|
798
|
+
}) + "\n"
|
|
799
|
+
)
|
|
800
|
+
);
|
|
801
|
+
} finally {
|
|
802
|
+
writer.releaseLock();
|
|
803
|
+
}
|
|
804
|
+
const originalMessages = processedParams.messages;
|
|
805
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
806
|
+
this.processStreamResponse(
|
|
807
|
+
{
|
|
808
|
+
...processedParams,
|
|
809
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
810
|
+
},
|
|
811
|
+
writable
|
|
812
|
+
).catch((error) => {
|
|
813
|
+
console.error("Error processing stream response:", error);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
} else {
|
|
818
|
+
setTimeout(() => {
|
|
819
|
+
writable.close();
|
|
820
|
+
}, 0);
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
lastMessage: void 0
|
|
824
|
+
}).catch((error) => {
|
|
825
|
+
console.error("Error processing stream response:", error);
|
|
826
|
+
});
|
|
827
|
+
} catch (error) {
|
|
828
|
+
console.error("Error processing stream response:", error);
|
|
829
|
+
}
|
|
336
830
|
return response;
|
|
337
831
|
}
|
|
338
832
|
/**
|
|
@@ -343,6 +837,22 @@ var Agent = class extends BaseResource {
|
|
|
343
837
|
getTool(toolId) {
|
|
344
838
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
345
839
|
}
|
|
840
|
+
/**
|
|
841
|
+
* Executes a tool for the agent
|
|
842
|
+
* @param toolId - ID of the tool to execute
|
|
843
|
+
* @param params - Parameters required for tool execution
|
|
844
|
+
* @returns Promise containing the tool execution results
|
|
845
|
+
*/
|
|
846
|
+
executeTool(toolId, params) {
|
|
847
|
+
const body = {
|
|
848
|
+
data: params.data,
|
|
849
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
850
|
+
};
|
|
851
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
852
|
+
method: "POST",
|
|
853
|
+
body
|
|
854
|
+
});
|
|
855
|
+
}
|
|
346
856
|
/**
|
|
347
857
|
* Retrieves evaluation results for the agent
|
|
348
858
|
* @returns Promise containing agent evaluations
|
|
@@ -378,8 +888,8 @@ var Network = class extends BaseResource {
|
|
|
378
888
|
generate(params) {
|
|
379
889
|
const processedParams = {
|
|
380
890
|
...params,
|
|
381
|
-
output:
|
|
382
|
-
experimental_output:
|
|
891
|
+
output: zodToJsonSchema(params.output),
|
|
892
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
383
893
|
};
|
|
384
894
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
385
895
|
method: "POST",
|
|
@@ -394,8 +904,8 @@ var Network = class extends BaseResource {
|
|
|
394
904
|
async stream(params) {
|
|
395
905
|
const processedParams = {
|
|
396
906
|
...params,
|
|
397
|
-
output:
|
|
398
|
-
experimental_output:
|
|
907
|
+
output: zodToJsonSchema(params.output),
|
|
908
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
399
909
|
};
|
|
400
910
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
401
911
|
method: "POST",
|
|
@@ -451,10 +961,45 @@ var MemoryThread = class extends BaseResource {
|
|
|
451
961
|
}
|
|
452
962
|
/**
|
|
453
963
|
* Retrieves messages associated with the thread
|
|
964
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
454
965
|
* @returns Promise containing thread messages and UI messages
|
|
455
966
|
*/
|
|
456
|
-
getMessages() {
|
|
457
|
-
|
|
967
|
+
getMessages(params) {
|
|
968
|
+
const query = new URLSearchParams({
|
|
969
|
+
agentId: this.agentId,
|
|
970
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
971
|
+
});
|
|
972
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
976
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
977
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
978
|
+
*/
|
|
979
|
+
getMessagesPaginated({
|
|
980
|
+
selectBy,
|
|
981
|
+
...rest
|
|
982
|
+
}) {
|
|
983
|
+
const query = new URLSearchParams({
|
|
984
|
+
...rest,
|
|
985
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
986
|
+
});
|
|
987
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Deletes one or more messages from the thread
|
|
991
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
992
|
+
* message object with id property, or array of message objects
|
|
993
|
+
* @returns Promise containing deletion result
|
|
994
|
+
*/
|
|
995
|
+
deleteMessages(messageIds) {
|
|
996
|
+
const query = new URLSearchParams({
|
|
997
|
+
agentId: this.agentId
|
|
998
|
+
});
|
|
999
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
1000
|
+
method: "POST",
|
|
1001
|
+
body: { messageIds }
|
|
1002
|
+
});
|
|
458
1003
|
}
|
|
459
1004
|
};
|
|
460
1005
|
|
|
@@ -524,24 +1069,24 @@ var Vector = class extends BaseResource {
|
|
|
524
1069
|
}
|
|
525
1070
|
};
|
|
526
1071
|
|
|
527
|
-
// src/resources/workflow.ts
|
|
1072
|
+
// src/resources/legacy-workflow.ts
|
|
528
1073
|
var RECORD_SEPARATOR = "";
|
|
529
|
-
var
|
|
1074
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
530
1075
|
constructor(options, workflowId) {
|
|
531
1076
|
super(options);
|
|
532
1077
|
this.workflowId = workflowId;
|
|
533
1078
|
}
|
|
534
1079
|
/**
|
|
535
|
-
* Retrieves details about the workflow
|
|
536
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1080
|
+
* Retrieves details about the legacy workflow
|
|
1081
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
537
1082
|
*/
|
|
538
1083
|
details() {
|
|
539
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1084
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
540
1085
|
}
|
|
541
1086
|
/**
|
|
542
|
-
* Retrieves all runs for a workflow
|
|
1087
|
+
* Retrieves all runs for a legacy workflow
|
|
543
1088
|
* @param params - Parameters for filtering runs
|
|
544
|
-
* @returns Promise containing workflow runs array
|
|
1089
|
+
* @returns Promise containing legacy workflow runs array
|
|
545
1090
|
*/
|
|
546
1091
|
runs(params) {
|
|
547
1092
|
const searchParams = new URLSearchParams();
|
|
@@ -561,25 +1106,13 @@ var Workflow = class extends BaseResource {
|
|
|
561
1106
|
searchParams.set("resourceId", params.resourceId);
|
|
562
1107
|
}
|
|
563
1108
|
if (searchParams.size) {
|
|
564
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1109
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
565
1110
|
} else {
|
|
566
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1111
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
567
1112
|
}
|
|
568
1113
|
}
|
|
569
1114
|
/**
|
|
570
|
-
*
|
|
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
|
|
1115
|
+
* Creates a new legacy workflow run
|
|
583
1116
|
* @returns Promise containing the generated run ID
|
|
584
1117
|
*/
|
|
585
1118
|
createRun(params) {
|
|
@@ -587,34 +1120,34 @@ var Workflow = class extends BaseResource {
|
|
|
587
1120
|
if (!!params?.runId) {
|
|
588
1121
|
searchParams.set("runId", params.runId);
|
|
589
1122
|
}
|
|
590
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
1123
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
591
1124
|
method: "POST"
|
|
592
1125
|
});
|
|
593
1126
|
}
|
|
594
1127
|
/**
|
|
595
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1128
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
596
1129
|
* @param params - Object containing the runId and triggerData
|
|
597
1130
|
* @returns Promise containing success message
|
|
598
1131
|
*/
|
|
599
1132
|
start(params) {
|
|
600
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1133
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
601
1134
|
method: "POST",
|
|
602
1135
|
body: params?.triggerData
|
|
603
1136
|
});
|
|
604
1137
|
}
|
|
605
1138
|
/**
|
|
606
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1139
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
607
1140
|
* @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
|
|
1141
|
+
* @param runId - ID of the legacy workflow run
|
|
1142
|
+
* @param context - Context to resume the legacy workflow with
|
|
1143
|
+
* @returns Promise containing the legacy workflow resume results
|
|
611
1144
|
*/
|
|
612
1145
|
resume({
|
|
613
1146
|
stepId,
|
|
614
1147
|
runId,
|
|
615
1148
|
context
|
|
616
1149
|
}) {
|
|
617
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1150
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
618
1151
|
method: "POST",
|
|
619
1152
|
body: {
|
|
620
1153
|
stepId,
|
|
@@ -632,18 +1165,18 @@ var Workflow = class extends BaseResource {
|
|
|
632
1165
|
if (!!params?.runId) {
|
|
633
1166
|
searchParams.set("runId", params.runId);
|
|
634
1167
|
}
|
|
635
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1168
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
636
1169
|
method: "POST",
|
|
637
1170
|
body: params?.triggerData
|
|
638
1171
|
});
|
|
639
1172
|
}
|
|
640
1173
|
/**
|
|
641
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1174
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
642
1175
|
* @param params - Object containing the runId, stepId, and context
|
|
643
1176
|
* @returns Promise containing the workflow resume results
|
|
644
1177
|
*/
|
|
645
1178
|
resumeAsync(params) {
|
|
646
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1179
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
647
1180
|
method: "POST",
|
|
648
1181
|
body: {
|
|
649
1182
|
stepId: params.stepId,
|
|
@@ -697,16 +1230,16 @@ var Workflow = class extends BaseResource {
|
|
|
697
1230
|
}
|
|
698
1231
|
}
|
|
699
1232
|
/**
|
|
700
|
-
* Watches workflow transitions in real-time
|
|
1233
|
+
* Watches legacy workflow transitions in real-time
|
|
701
1234
|
* @param runId - Optional run ID to filter the watch stream
|
|
702
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1235
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
703
1236
|
*/
|
|
704
1237
|
async watch({ runId }, onRecord) {
|
|
705
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1238
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
706
1239
|
stream: true
|
|
707
1240
|
});
|
|
708
1241
|
if (!response.ok) {
|
|
709
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1242
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
710
1243
|
}
|
|
711
1244
|
if (!response.body) {
|
|
712
1245
|
throw new Error("Response body is null");
|
|
@@ -718,7 +1251,7 @@ var Workflow = class extends BaseResource {
|
|
|
718
1251
|
};
|
|
719
1252
|
|
|
720
1253
|
// src/resources/tool.ts
|
|
721
|
-
var
|
|
1254
|
+
var Tool2 = class extends BaseResource {
|
|
722
1255
|
constructor(options, toolId) {
|
|
723
1256
|
super(options);
|
|
724
1257
|
this.toolId = toolId;
|
|
@@ -740,22 +1273,26 @@ var Tool = class extends BaseResource {
|
|
|
740
1273
|
if (params.runId) {
|
|
741
1274
|
url.set("runId", params.runId);
|
|
742
1275
|
}
|
|
1276
|
+
const body = {
|
|
1277
|
+
data: params.data,
|
|
1278
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1279
|
+
};
|
|
743
1280
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
744
1281
|
method: "POST",
|
|
745
|
-
body
|
|
1282
|
+
body
|
|
746
1283
|
});
|
|
747
1284
|
}
|
|
748
1285
|
};
|
|
749
1286
|
|
|
750
|
-
// src/resources/
|
|
1287
|
+
// src/resources/workflow.ts
|
|
751
1288
|
var RECORD_SEPARATOR2 = "";
|
|
752
|
-
var
|
|
1289
|
+
var Workflow = class extends BaseResource {
|
|
753
1290
|
constructor(options, workflowId) {
|
|
754
1291
|
super(options);
|
|
755
1292
|
this.workflowId = workflowId;
|
|
756
1293
|
}
|
|
757
1294
|
/**
|
|
758
|
-
* Creates an async generator that processes a readable stream and yields
|
|
1295
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
759
1296
|
* separated by the Record Separator character (\x1E)
|
|
760
1297
|
*
|
|
761
1298
|
* @param stream - The readable stream to process
|
|
@@ -800,16 +1337,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
800
1337
|
}
|
|
801
1338
|
}
|
|
802
1339
|
/**
|
|
803
|
-
* Retrieves details about the
|
|
804
|
-
* @returns Promise containing
|
|
1340
|
+
* Retrieves details about the workflow
|
|
1341
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
805
1342
|
*/
|
|
806
1343
|
details() {
|
|
807
|
-
return this.request(`/api/workflows
|
|
1344
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
808
1345
|
}
|
|
809
1346
|
/**
|
|
810
|
-
* Retrieves all runs for a
|
|
1347
|
+
* Retrieves all runs for a workflow
|
|
811
1348
|
* @param params - Parameters for filtering runs
|
|
812
|
-
* @returns Promise containing
|
|
1349
|
+
* @returns Promise containing workflow runs array
|
|
813
1350
|
*/
|
|
814
1351
|
runs(params) {
|
|
815
1352
|
const searchParams = new URLSearchParams();
|
|
@@ -819,23 +1356,60 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
819
1356
|
if (params?.toDate) {
|
|
820
1357
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
821
1358
|
}
|
|
822
|
-
if (params?.limit) {
|
|
1359
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
823
1360
|
searchParams.set("limit", String(params.limit));
|
|
824
1361
|
}
|
|
825
|
-
if (params?.offset) {
|
|
1362
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
826
1363
|
searchParams.set("offset", String(params.offset));
|
|
827
1364
|
}
|
|
828
1365
|
if (params?.resourceId) {
|
|
829
1366
|
searchParams.set("resourceId", params.resourceId);
|
|
830
1367
|
}
|
|
831
1368
|
if (searchParams.size) {
|
|
832
|
-
return this.request(`/api/workflows
|
|
1369
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
833
1370
|
} else {
|
|
834
|
-
return this.request(`/api/workflows
|
|
1371
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
835
1372
|
}
|
|
836
1373
|
}
|
|
837
1374
|
/**
|
|
838
|
-
*
|
|
1375
|
+
* Retrieves a specific workflow run by its ID
|
|
1376
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1377
|
+
* @returns Promise containing the workflow run details
|
|
1378
|
+
*/
|
|
1379
|
+
runById(runId) {
|
|
1380
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1384
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1385
|
+
* @returns Promise containing the workflow run execution result
|
|
1386
|
+
*/
|
|
1387
|
+
runExecutionResult(runId) {
|
|
1388
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Cancels a specific workflow run by its ID
|
|
1392
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1393
|
+
* @returns Promise containing a success message
|
|
1394
|
+
*/
|
|
1395
|
+
cancelRun(runId) {
|
|
1396
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1397
|
+
method: "POST"
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Sends an event to a specific workflow run by its ID
|
|
1402
|
+
* @param params - Object containing the runId, event and data
|
|
1403
|
+
* @returns Promise containing a success message
|
|
1404
|
+
*/
|
|
1405
|
+
sendRunEvent(params) {
|
|
1406
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1407
|
+
method: "POST",
|
|
1408
|
+
body: { event: params.event, data: params.data }
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Creates a new workflow run
|
|
839
1413
|
* @param params - Optional object containing the optional runId
|
|
840
1414
|
* @returns Promise containing the runId of the created run
|
|
841
1415
|
*/
|
|
@@ -844,23 +1418,32 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
844
1418
|
if (!!params?.runId) {
|
|
845
1419
|
searchParams.set("runId", params.runId);
|
|
846
1420
|
}
|
|
847
|
-
return this.request(`/api/workflows
|
|
1421
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
848
1422
|
method: "POST"
|
|
849
1423
|
});
|
|
850
1424
|
}
|
|
851
1425
|
/**
|
|
852
|
-
*
|
|
1426
|
+
* Creates a new workflow run (alias for createRun)
|
|
1427
|
+
* @param params - Optional object containing the optional runId
|
|
1428
|
+
* @returns Promise containing the runId of the created run
|
|
1429
|
+
*/
|
|
1430
|
+
createRunAsync(params) {
|
|
1431
|
+
return this.createRun(params);
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
853
1435
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
854
1436
|
* @returns Promise containing success message
|
|
855
1437
|
*/
|
|
856
1438
|
start(params) {
|
|
857
|
-
|
|
1439
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1440
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
858
1441
|
method: "POST",
|
|
859
|
-
body: { inputData: params?.inputData, runtimeContext
|
|
1442
|
+
body: { inputData: params?.inputData, runtimeContext }
|
|
860
1443
|
});
|
|
861
1444
|
}
|
|
862
1445
|
/**
|
|
863
|
-
* Resumes a suspended
|
|
1446
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
864
1447
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
865
1448
|
* @returns Promise containing success message
|
|
866
1449
|
*/
|
|
@@ -868,9 +1451,10 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
868
1451
|
step,
|
|
869
1452
|
runId,
|
|
870
1453
|
resumeData,
|
|
871
|
-
|
|
1454
|
+
...rest
|
|
872
1455
|
}) {
|
|
873
|
-
|
|
1456
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1457
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
874
1458
|
method: "POST",
|
|
875
1459
|
stream: true,
|
|
876
1460
|
body: {
|
|
@@ -881,63 +1465,452 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
881
1465
|
});
|
|
882
1466
|
}
|
|
883
1467
|
/**
|
|
884
|
-
* Starts a
|
|
1468
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
885
1469
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
886
|
-
* @returns Promise containing the
|
|
1470
|
+
* @returns Promise containing the workflow execution results
|
|
887
1471
|
*/
|
|
888
1472
|
startAsync(params) {
|
|
889
1473
|
const searchParams = new URLSearchParams();
|
|
890
1474
|
if (!!params?.runId) {
|
|
891
1475
|
searchParams.set("runId", params.runId);
|
|
892
1476
|
}
|
|
893
|
-
|
|
1477
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1478
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
894
1479
|
method: "POST",
|
|
895
|
-
body: { inputData: params.inputData, runtimeContext
|
|
1480
|
+
body: { inputData: params.inputData, runtimeContext }
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Starts a workflow run and returns a stream
|
|
1485
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1486
|
+
* @returns Promise containing the workflow execution results
|
|
1487
|
+
*/
|
|
1488
|
+
async stream(params) {
|
|
1489
|
+
const searchParams = new URLSearchParams();
|
|
1490
|
+
if (!!params?.runId) {
|
|
1491
|
+
searchParams.set("runId", params.runId);
|
|
1492
|
+
}
|
|
1493
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1494
|
+
const response = await this.request(
|
|
1495
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1496
|
+
{
|
|
1497
|
+
method: "POST",
|
|
1498
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1499
|
+
stream: true
|
|
1500
|
+
}
|
|
1501
|
+
);
|
|
1502
|
+
if (!response.ok) {
|
|
1503
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1504
|
+
}
|
|
1505
|
+
if (!response.body) {
|
|
1506
|
+
throw new Error("Response body is null");
|
|
1507
|
+
}
|
|
1508
|
+
let failedChunk = void 0;
|
|
1509
|
+
const transformStream = new TransformStream({
|
|
1510
|
+
start() {
|
|
1511
|
+
},
|
|
1512
|
+
async transform(chunk, controller) {
|
|
1513
|
+
try {
|
|
1514
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1515
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1516
|
+
for (const chunk2 of chunks) {
|
|
1517
|
+
if (chunk2) {
|
|
1518
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1519
|
+
try {
|
|
1520
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1521
|
+
controller.enqueue(parsedChunk);
|
|
1522
|
+
failedChunk = void 0;
|
|
1523
|
+
} catch (error) {
|
|
1524
|
+
failedChunk = newChunk;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
} catch {
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
896
1531
|
});
|
|
1532
|
+
return response.body.pipeThrough(transformStream);
|
|
897
1533
|
}
|
|
898
1534
|
/**
|
|
899
|
-
* Resumes a suspended
|
|
1535
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
900
1536
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
901
|
-
* @returns Promise containing the
|
|
1537
|
+
* @returns Promise containing the workflow resume results
|
|
902
1538
|
*/
|
|
903
1539
|
resumeAsync(params) {
|
|
904
|
-
|
|
1540
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1541
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
905
1542
|
method: "POST",
|
|
906
1543
|
body: {
|
|
907
1544
|
step: params.step,
|
|
908
1545
|
resumeData: params.resumeData,
|
|
909
|
-
runtimeContext
|
|
1546
|
+
runtimeContext
|
|
910
1547
|
}
|
|
911
1548
|
});
|
|
912
1549
|
}
|
|
913
1550
|
/**
|
|
914
|
-
* Watches
|
|
1551
|
+
* Watches workflow transitions in real-time
|
|
915
1552
|
* @param runId - Optional run ID to filter the watch stream
|
|
916
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
1553
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
917
1554
|
*/
|
|
918
1555
|
async watch({ runId }, onRecord) {
|
|
919
|
-
const response = await this.request(`/api/workflows
|
|
1556
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
920
1557
|
stream: true
|
|
921
1558
|
});
|
|
922
1559
|
if (!response.ok) {
|
|
923
|
-
throw new Error(`Failed to watch
|
|
1560
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
924
1561
|
}
|
|
925
1562
|
if (!response.body) {
|
|
926
1563
|
throw new Error("Response body is null");
|
|
927
1564
|
}
|
|
928
1565
|
for await (const record of this.streamProcessor(response.body)) {
|
|
929
|
-
|
|
1566
|
+
if (typeof record === "string") {
|
|
1567
|
+
onRecord(JSON.parse(record));
|
|
1568
|
+
} else {
|
|
1569
|
+
onRecord(record);
|
|
1570
|
+
}
|
|
930
1571
|
}
|
|
931
1572
|
}
|
|
932
|
-
};
|
|
933
|
-
|
|
934
|
-
// src/client.ts
|
|
935
|
-
var MastraClient = class extends BaseResource {
|
|
936
|
-
constructor(options) {
|
|
937
|
-
super(options);
|
|
938
|
-
}
|
|
939
1573
|
/**
|
|
940
|
-
*
|
|
1574
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
1575
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
1576
|
+
*
|
|
1577
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
1578
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
1579
|
+
*/
|
|
1580
|
+
static createRecordStream(records) {
|
|
1581
|
+
const encoder = new TextEncoder();
|
|
1582
|
+
return new ReadableStream({
|
|
1583
|
+
async start(controller) {
|
|
1584
|
+
try {
|
|
1585
|
+
for await (const record of records) {
|
|
1586
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1587
|
+
controller.enqueue(encoder.encode(json));
|
|
1588
|
+
}
|
|
1589
|
+
controller.close();
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
controller.error(err);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// src/resources/a2a.ts
|
|
1599
|
+
var A2A = class extends BaseResource {
|
|
1600
|
+
constructor(options, agentId) {
|
|
1601
|
+
super(options);
|
|
1602
|
+
this.agentId = agentId;
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Get the agent card with metadata about the agent
|
|
1606
|
+
* @returns Promise containing the agent card information
|
|
1607
|
+
*/
|
|
1608
|
+
async getCard() {
|
|
1609
|
+
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Send a message to the agent and get a response
|
|
1613
|
+
* @param params - Parameters for the task
|
|
1614
|
+
* @returns Promise containing the task response
|
|
1615
|
+
*/
|
|
1616
|
+
async sendMessage(params) {
|
|
1617
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1618
|
+
method: "POST",
|
|
1619
|
+
body: {
|
|
1620
|
+
method: "tasks/send",
|
|
1621
|
+
params
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
return { task: response.result };
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Get the status and result of a task
|
|
1628
|
+
* @param params - Parameters for querying the task
|
|
1629
|
+
* @returns Promise containing the task response
|
|
1630
|
+
*/
|
|
1631
|
+
async getTask(params) {
|
|
1632
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1633
|
+
method: "POST",
|
|
1634
|
+
body: {
|
|
1635
|
+
method: "tasks/get",
|
|
1636
|
+
params
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
return response.result;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Cancel a running task
|
|
1643
|
+
* @param params - Parameters identifying the task to cancel
|
|
1644
|
+
* @returns Promise containing the task response
|
|
1645
|
+
*/
|
|
1646
|
+
async cancelTask(params) {
|
|
1647
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1648
|
+
method: "POST",
|
|
1649
|
+
body: {
|
|
1650
|
+
method: "tasks/cancel",
|
|
1651
|
+
params
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Send a message and subscribe to streaming updates (not fully implemented)
|
|
1657
|
+
* @param params - Parameters for the task
|
|
1658
|
+
* @returns Promise containing the task response
|
|
1659
|
+
*/
|
|
1660
|
+
async sendAndSubscribe(params) {
|
|
1661
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
1662
|
+
method: "POST",
|
|
1663
|
+
body: {
|
|
1664
|
+
method: "tasks/sendSubscribe",
|
|
1665
|
+
params
|
|
1666
|
+
},
|
|
1667
|
+
stream: true
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
// src/resources/mcp-tool.ts
|
|
1673
|
+
var MCPTool = class extends BaseResource {
|
|
1674
|
+
serverId;
|
|
1675
|
+
toolId;
|
|
1676
|
+
constructor(options, serverId, toolId) {
|
|
1677
|
+
super(options);
|
|
1678
|
+
this.serverId = serverId;
|
|
1679
|
+
this.toolId = toolId;
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
1683
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1684
|
+
*/
|
|
1685
|
+
details() {
|
|
1686
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Executes this specific tool on the MCP server.
|
|
1690
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
1691
|
+
* @returns Promise containing the result of the tool execution.
|
|
1692
|
+
*/
|
|
1693
|
+
execute(params) {
|
|
1694
|
+
const body = {};
|
|
1695
|
+
if (params.data !== void 0) body.data = params.data;
|
|
1696
|
+
if (params.runtimeContext !== void 0) {
|
|
1697
|
+
body.runtimeContext = params.runtimeContext;
|
|
1698
|
+
}
|
|
1699
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
1700
|
+
method: "POST",
|
|
1701
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
// src/resources/network-memory-thread.ts
|
|
1707
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1708
|
+
constructor(options, threadId, networkId) {
|
|
1709
|
+
super(options);
|
|
1710
|
+
this.threadId = threadId;
|
|
1711
|
+
this.networkId = networkId;
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Retrieves the memory thread details
|
|
1715
|
+
* @returns Promise containing thread details including title and metadata
|
|
1716
|
+
*/
|
|
1717
|
+
get() {
|
|
1718
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Updates the memory thread properties
|
|
1722
|
+
* @param params - Update parameters including title and metadata
|
|
1723
|
+
* @returns Promise containing updated thread details
|
|
1724
|
+
*/
|
|
1725
|
+
update(params) {
|
|
1726
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1727
|
+
method: "PATCH",
|
|
1728
|
+
body: params
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Deletes the memory thread
|
|
1733
|
+
* @returns Promise containing deletion result
|
|
1734
|
+
*/
|
|
1735
|
+
delete() {
|
|
1736
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1737
|
+
method: "DELETE"
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Retrieves messages associated with the thread
|
|
1742
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1743
|
+
* @returns Promise containing thread messages and UI messages
|
|
1744
|
+
*/
|
|
1745
|
+
getMessages(params) {
|
|
1746
|
+
const query = new URLSearchParams({
|
|
1747
|
+
networkId: this.networkId,
|
|
1748
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1749
|
+
});
|
|
1750
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Deletes one or more messages from the thread
|
|
1754
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1755
|
+
* message object with id property, or array of message objects
|
|
1756
|
+
* @returns Promise containing deletion result
|
|
1757
|
+
*/
|
|
1758
|
+
deleteMessages(messageIds) {
|
|
1759
|
+
const query = new URLSearchParams({
|
|
1760
|
+
networkId: this.networkId
|
|
1761
|
+
});
|
|
1762
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
1763
|
+
method: "POST",
|
|
1764
|
+
body: { messageIds }
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
// src/resources/vNextNetwork.ts
|
|
1770
|
+
var RECORD_SEPARATOR3 = "";
|
|
1771
|
+
var VNextNetwork = class extends BaseResource {
|
|
1772
|
+
constructor(options, networkId) {
|
|
1773
|
+
super(options);
|
|
1774
|
+
this.networkId = networkId;
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Retrieves details about the network
|
|
1778
|
+
* @returns Promise containing vNext network details
|
|
1779
|
+
*/
|
|
1780
|
+
details() {
|
|
1781
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Generates a response from the v-next network
|
|
1785
|
+
* @param params - Generation parameters including message
|
|
1786
|
+
* @returns Promise containing the generated response
|
|
1787
|
+
*/
|
|
1788
|
+
generate(params) {
|
|
1789
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1790
|
+
method: "POST",
|
|
1791
|
+
body: {
|
|
1792
|
+
...params,
|
|
1793
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1799
|
+
* @param params - Generation parameters including message
|
|
1800
|
+
* @returns Promise containing the generated response
|
|
1801
|
+
*/
|
|
1802
|
+
loop(params) {
|
|
1803
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1804
|
+
method: "POST",
|
|
1805
|
+
body: {
|
|
1806
|
+
...params,
|
|
1807
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1808
|
+
}
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
async *streamProcessor(stream) {
|
|
1812
|
+
const reader = stream.getReader();
|
|
1813
|
+
let doneReading = false;
|
|
1814
|
+
let buffer = "";
|
|
1815
|
+
try {
|
|
1816
|
+
while (!doneReading) {
|
|
1817
|
+
const { done, value } = await reader.read();
|
|
1818
|
+
doneReading = done;
|
|
1819
|
+
if (done && !value) continue;
|
|
1820
|
+
try {
|
|
1821
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1822
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1823
|
+
buffer = chunks.pop() || "";
|
|
1824
|
+
for (const chunk of chunks) {
|
|
1825
|
+
if (chunk) {
|
|
1826
|
+
if (typeof chunk === "string") {
|
|
1827
|
+
try {
|
|
1828
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1829
|
+
yield parsedChunk;
|
|
1830
|
+
} catch {
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
} catch {
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
if (buffer) {
|
|
1839
|
+
try {
|
|
1840
|
+
yield JSON.parse(buffer);
|
|
1841
|
+
} catch {
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
} finally {
|
|
1845
|
+
reader.cancel().catch(() => {
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Streams a response from the v-next network
|
|
1851
|
+
* @param params - Stream parameters including message
|
|
1852
|
+
* @returns Promise containing the results
|
|
1853
|
+
*/
|
|
1854
|
+
async stream(params, onRecord) {
|
|
1855
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1856
|
+
method: "POST",
|
|
1857
|
+
body: {
|
|
1858
|
+
...params,
|
|
1859
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1860
|
+
},
|
|
1861
|
+
stream: true
|
|
1862
|
+
});
|
|
1863
|
+
if (!response.ok) {
|
|
1864
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1865
|
+
}
|
|
1866
|
+
if (!response.body) {
|
|
1867
|
+
throw new Error("Response body is null");
|
|
1868
|
+
}
|
|
1869
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1870
|
+
if (typeof record === "string") {
|
|
1871
|
+
onRecord(JSON.parse(record));
|
|
1872
|
+
} else {
|
|
1873
|
+
onRecord(record);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Streams a response from the v-next network loop
|
|
1879
|
+
* @param params - Stream parameters including message
|
|
1880
|
+
* @returns Promise containing the results
|
|
1881
|
+
*/
|
|
1882
|
+
async loopStream(params, onRecord) {
|
|
1883
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1884
|
+
method: "POST",
|
|
1885
|
+
body: {
|
|
1886
|
+
...params,
|
|
1887
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1888
|
+
},
|
|
1889
|
+
stream: true
|
|
1890
|
+
});
|
|
1891
|
+
if (!response.ok) {
|
|
1892
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
1893
|
+
}
|
|
1894
|
+
if (!response.body) {
|
|
1895
|
+
throw new Error("Response body is null");
|
|
1896
|
+
}
|
|
1897
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1898
|
+
if (typeof record === "string") {
|
|
1899
|
+
onRecord(JSON.parse(record));
|
|
1900
|
+
} else {
|
|
1901
|
+
onRecord(record);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// src/client.ts
|
|
1908
|
+
var MastraClient = class extends BaseResource {
|
|
1909
|
+
constructor(options) {
|
|
1910
|
+
super(options);
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Retrieves all available agents
|
|
941
1914
|
* @returns Promise containing map of agent IDs to agent details
|
|
942
1915
|
*/
|
|
943
1916
|
getAgents() {
|
|
@@ -1008,6 +1981,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1008
1981
|
getMemoryStatus(agentId) {
|
|
1009
1982
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1010
1983
|
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Retrieves memory threads for a resource
|
|
1986
|
+
* @param params - Parameters containing the resource ID
|
|
1987
|
+
* @returns Promise containing array of memory threads
|
|
1988
|
+
*/
|
|
1989
|
+
getNetworkMemoryThreads(params) {
|
|
1990
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Creates a new memory thread
|
|
1994
|
+
* @param params - Parameters for creating the memory thread
|
|
1995
|
+
* @returns Promise containing the created memory thread
|
|
1996
|
+
*/
|
|
1997
|
+
createNetworkMemoryThread(params) {
|
|
1998
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Gets a memory thread instance by ID
|
|
2002
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
2003
|
+
* @returns MemoryThread instance
|
|
2004
|
+
*/
|
|
2005
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
2006
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2007
|
+
}
|
|
2008
|
+
/**
|
|
2009
|
+
* Saves messages to memory
|
|
2010
|
+
* @param params - Parameters containing messages to save
|
|
2011
|
+
* @returns Promise containing the saved messages
|
|
2012
|
+
*/
|
|
2013
|
+
saveNetworkMessageToMemory(params) {
|
|
2014
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2015
|
+
method: "POST",
|
|
2016
|
+
body: params
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* Gets the status of the memory system
|
|
2021
|
+
* @returns Promise containing memory system status
|
|
2022
|
+
*/
|
|
2023
|
+
getNetworkMemoryStatus(networkId) {
|
|
2024
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2025
|
+
}
|
|
1011
2026
|
/**
|
|
1012
2027
|
* Retrieves all available tools
|
|
1013
2028
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1021,7 +2036,22 @@ var MastraClient = class extends BaseResource {
|
|
|
1021
2036
|
* @returns Tool instance
|
|
1022
2037
|
*/
|
|
1023
2038
|
getTool(toolId) {
|
|
1024
|
-
return new
|
|
2039
|
+
return new Tool2(this.options, toolId);
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Retrieves all available legacy workflows
|
|
2043
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2044
|
+
*/
|
|
2045
|
+
getLegacyWorkflows() {
|
|
2046
|
+
return this.request("/api/workflows/legacy");
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Gets a legacy workflow instance by ID
|
|
2050
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2051
|
+
* @returns Legacy Workflow instance
|
|
2052
|
+
*/
|
|
2053
|
+
getLegacyWorkflow(workflowId) {
|
|
2054
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
1025
2055
|
}
|
|
1026
2056
|
/**
|
|
1027
2057
|
* Retrieves all available workflows
|
|
@@ -1038,21 +2068,6 @@ var MastraClient = class extends BaseResource {
|
|
|
1038
2068
|
getWorkflow(workflowId) {
|
|
1039
2069
|
return new Workflow(this.options, workflowId);
|
|
1040
2070
|
}
|
|
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
2071
|
/**
|
|
1057
2072
|
* Gets a vector instance by name
|
|
1058
2073
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -1067,7 +2082,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1067
2082
|
* @returns Promise containing array of log messages
|
|
1068
2083
|
*/
|
|
1069
2084
|
getLogs(params) {
|
|
1070
|
-
|
|
2085
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2086
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2087
|
+
const searchParams = new URLSearchParams();
|
|
2088
|
+
if (transportId) {
|
|
2089
|
+
searchParams.set("transportId", transportId);
|
|
2090
|
+
}
|
|
2091
|
+
if (fromDate) {
|
|
2092
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2093
|
+
}
|
|
2094
|
+
if (toDate) {
|
|
2095
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2096
|
+
}
|
|
2097
|
+
if (logLevel) {
|
|
2098
|
+
searchParams.set("logLevel", logLevel);
|
|
2099
|
+
}
|
|
2100
|
+
if (page) {
|
|
2101
|
+
searchParams.set("page", String(page));
|
|
2102
|
+
}
|
|
2103
|
+
if (perPage) {
|
|
2104
|
+
searchParams.set("perPage", String(perPage));
|
|
2105
|
+
}
|
|
2106
|
+
if (_filters) {
|
|
2107
|
+
if (Array.isArray(_filters)) {
|
|
2108
|
+
for (const filter of _filters) {
|
|
2109
|
+
searchParams.append("filters", filter);
|
|
2110
|
+
}
|
|
2111
|
+
} else {
|
|
2112
|
+
searchParams.set("filters", _filters);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
if (searchParams.size) {
|
|
2116
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
2117
|
+
} else {
|
|
2118
|
+
return this.request(`/api/logs`);
|
|
2119
|
+
}
|
|
1071
2120
|
}
|
|
1072
2121
|
/**
|
|
1073
2122
|
* Gets logs for a specific run
|
|
@@ -1075,7 +2124,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1075
2124
|
* @returns Promise containing array of log messages
|
|
1076
2125
|
*/
|
|
1077
2126
|
getLogForRun(params) {
|
|
1078
|
-
|
|
2127
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2128
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2129
|
+
const searchParams = new URLSearchParams();
|
|
2130
|
+
if (runId) {
|
|
2131
|
+
searchParams.set("runId", runId);
|
|
2132
|
+
}
|
|
2133
|
+
if (transportId) {
|
|
2134
|
+
searchParams.set("transportId", transportId);
|
|
2135
|
+
}
|
|
2136
|
+
if (fromDate) {
|
|
2137
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2138
|
+
}
|
|
2139
|
+
if (toDate) {
|
|
2140
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2141
|
+
}
|
|
2142
|
+
if (logLevel) {
|
|
2143
|
+
searchParams.set("logLevel", logLevel);
|
|
2144
|
+
}
|
|
2145
|
+
if (page) {
|
|
2146
|
+
searchParams.set("page", String(page));
|
|
2147
|
+
}
|
|
2148
|
+
if (perPage) {
|
|
2149
|
+
searchParams.set("perPage", String(perPage));
|
|
2150
|
+
}
|
|
2151
|
+
if (_filters) {
|
|
2152
|
+
if (Array.isArray(_filters)) {
|
|
2153
|
+
for (const filter of _filters) {
|
|
2154
|
+
searchParams.append("filters", filter);
|
|
2155
|
+
}
|
|
2156
|
+
} else {
|
|
2157
|
+
searchParams.set("filters", _filters);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
if (searchParams.size) {
|
|
2161
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2162
|
+
} else {
|
|
2163
|
+
return this.request(`/api/logs/${runId}`);
|
|
2164
|
+
}
|
|
1079
2165
|
}
|
|
1080
2166
|
/**
|
|
1081
2167
|
* List of all log transports
|
|
@@ -1133,6 +2219,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1133
2219
|
getNetworks() {
|
|
1134
2220
|
return this.request("/api/networks");
|
|
1135
2221
|
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Retrieves all available vNext networks
|
|
2224
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2225
|
+
*/
|
|
2226
|
+
getVNextNetworks() {
|
|
2227
|
+
return this.request("/api/networks/v-next");
|
|
2228
|
+
}
|
|
1136
2229
|
/**
|
|
1137
2230
|
* Gets a network instance by ID
|
|
1138
2231
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1141,6 +2234,185 @@ var MastraClient = class extends BaseResource {
|
|
|
1141
2234
|
getNetwork(networkId) {
|
|
1142
2235
|
return new Network(this.options, networkId);
|
|
1143
2236
|
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Gets a vNext network instance by ID
|
|
2239
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2240
|
+
* @returns vNext Network instance
|
|
2241
|
+
*/
|
|
2242
|
+
getVNextNetwork(networkId) {
|
|
2243
|
+
return new VNextNetwork(this.options, networkId);
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Retrieves a list of available MCP servers.
|
|
2247
|
+
* @param params - Optional parameters for pagination (limit, offset).
|
|
2248
|
+
* @returns Promise containing the list of MCP servers and pagination info.
|
|
2249
|
+
*/
|
|
2250
|
+
getMcpServers(params) {
|
|
2251
|
+
const searchParams = new URLSearchParams();
|
|
2252
|
+
if (params?.limit !== void 0) {
|
|
2253
|
+
searchParams.set("limit", String(params.limit));
|
|
2254
|
+
}
|
|
2255
|
+
if (params?.offset !== void 0) {
|
|
2256
|
+
searchParams.set("offset", String(params.offset));
|
|
2257
|
+
}
|
|
2258
|
+
const queryString = searchParams.toString();
|
|
2259
|
+
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Retrieves detailed information for a specific MCP server.
|
|
2263
|
+
* @param serverId - The ID of the MCP server to retrieve.
|
|
2264
|
+
* @param params - Optional parameters, e.g., specific version.
|
|
2265
|
+
* @returns Promise containing the detailed MCP server information.
|
|
2266
|
+
*/
|
|
2267
|
+
getMcpServerDetails(serverId, params) {
|
|
2268
|
+
const searchParams = new URLSearchParams();
|
|
2269
|
+
if (params?.version) {
|
|
2270
|
+
searchParams.set("version", params.version);
|
|
2271
|
+
}
|
|
2272
|
+
const queryString = searchParams.toString();
|
|
2273
|
+
return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Retrieves a list of tools for a specific MCP server.
|
|
2277
|
+
* @param serverId - The ID of the MCP server.
|
|
2278
|
+
* @returns Promise containing the list of tools.
|
|
2279
|
+
*/
|
|
2280
|
+
getMcpServerTools(serverId) {
|
|
2281
|
+
return this.request(`/api/mcp/${serverId}/tools`);
|
|
2282
|
+
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Gets an MCPTool resource instance for a specific tool on an MCP server.
|
|
2285
|
+
* This instance can then be used to fetch details or execute the tool.
|
|
2286
|
+
* @param serverId - The ID of the MCP server.
|
|
2287
|
+
* @param toolId - The ID of the tool.
|
|
2288
|
+
* @returns MCPTool instance.
|
|
2289
|
+
*/
|
|
2290
|
+
getMcpServerTool(serverId, toolId) {
|
|
2291
|
+
return new MCPTool(this.options, serverId, toolId);
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Gets an A2A client for interacting with an agent via the A2A protocol
|
|
2295
|
+
* @param agentId - ID of the agent to interact with
|
|
2296
|
+
* @returns A2A client instance
|
|
2297
|
+
*/
|
|
2298
|
+
getA2A(agentId) {
|
|
2299
|
+
return new A2A(this.options, agentId);
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2303
|
+
* @param agentId - ID of the agent.
|
|
2304
|
+
* @param threadId - ID of the thread.
|
|
2305
|
+
* @param resourceId - Optional ID of the resource.
|
|
2306
|
+
* @returns Working memory for the specified thread or resource.
|
|
2307
|
+
*/
|
|
2308
|
+
getWorkingMemory({
|
|
2309
|
+
agentId,
|
|
2310
|
+
threadId,
|
|
2311
|
+
resourceId
|
|
2312
|
+
}) {
|
|
2313
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2317
|
+
* @param agentId - ID of the agent.
|
|
2318
|
+
* @param threadId - ID of the thread.
|
|
2319
|
+
* @param workingMemory - The new working memory content.
|
|
2320
|
+
* @param resourceId - Optional ID of the resource.
|
|
2321
|
+
*/
|
|
2322
|
+
updateWorkingMemory({
|
|
2323
|
+
agentId,
|
|
2324
|
+
threadId,
|
|
2325
|
+
workingMemory,
|
|
2326
|
+
resourceId
|
|
2327
|
+
}) {
|
|
2328
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2329
|
+
method: "POST",
|
|
2330
|
+
body: {
|
|
2331
|
+
workingMemory,
|
|
2332
|
+
resourceId
|
|
2333
|
+
}
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Retrieves all available scorers
|
|
2338
|
+
* @returns Promise containing list of available scorers
|
|
2339
|
+
*/
|
|
2340
|
+
getScorers() {
|
|
2341
|
+
return this.request("/api/scores/scorers");
|
|
2342
|
+
}
|
|
2343
|
+
/**
|
|
2344
|
+
* Retrieves a scorer by ID
|
|
2345
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2346
|
+
* @returns Promise containing the scorer
|
|
2347
|
+
*/
|
|
2348
|
+
getScorer(scorerId) {
|
|
2349
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2350
|
+
}
|
|
2351
|
+
getScoresByScorerId(params) {
|
|
2352
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2353
|
+
const searchParams = new URLSearchParams();
|
|
2354
|
+
if (entityId) {
|
|
2355
|
+
searchParams.set("entityId", entityId);
|
|
2356
|
+
}
|
|
2357
|
+
if (entityType) {
|
|
2358
|
+
searchParams.set("entityType", entityType);
|
|
2359
|
+
}
|
|
2360
|
+
if (page !== void 0) {
|
|
2361
|
+
searchParams.set("page", String(page));
|
|
2362
|
+
}
|
|
2363
|
+
if (perPage !== void 0) {
|
|
2364
|
+
searchParams.set("perPage", String(perPage));
|
|
2365
|
+
}
|
|
2366
|
+
const queryString = searchParams.toString();
|
|
2367
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Retrieves scores by run ID
|
|
2371
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2372
|
+
* @returns Promise containing scores and pagination info
|
|
2373
|
+
*/
|
|
2374
|
+
getScoresByRunId(params) {
|
|
2375
|
+
const { runId, page, perPage } = params;
|
|
2376
|
+
const searchParams = new URLSearchParams();
|
|
2377
|
+
if (page !== void 0) {
|
|
2378
|
+
searchParams.set("page", String(page));
|
|
2379
|
+
}
|
|
2380
|
+
if (perPage !== void 0) {
|
|
2381
|
+
searchParams.set("perPage", String(perPage));
|
|
2382
|
+
}
|
|
2383
|
+
const queryString = searchParams.toString();
|
|
2384
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Retrieves scores by entity ID and type
|
|
2388
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2389
|
+
* @returns Promise containing scores and pagination info
|
|
2390
|
+
*/
|
|
2391
|
+
getScoresByEntityId(params) {
|
|
2392
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2393
|
+
const searchParams = new URLSearchParams();
|
|
2394
|
+
if (page !== void 0) {
|
|
2395
|
+
searchParams.set("page", String(page));
|
|
2396
|
+
}
|
|
2397
|
+
if (perPage !== void 0) {
|
|
2398
|
+
searchParams.set("perPage", String(perPage));
|
|
2399
|
+
}
|
|
2400
|
+
const queryString = searchParams.toString();
|
|
2401
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Saves a score
|
|
2405
|
+
* @param params - Parameters containing the score data to save
|
|
2406
|
+
* @returns Promise containing the saved score
|
|
2407
|
+
*/
|
|
2408
|
+
saveScore(params) {
|
|
2409
|
+
return this.request("/api/scores", {
|
|
2410
|
+
method: "POST",
|
|
2411
|
+
body: params
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
1144
2414
|
};
|
|
1145
2415
|
|
|
1146
2416
|
exports.MastraClient = MastraClient;
|
|
2417
|
+
//# sourceMappingURL=index.cjs.map
|
|
2418
|
+
//# sourceMappingURL=index.cjs.map
|