@mastra/client-js 0.0.0-course-20250527170450 → 0.0.0-custom-instrumentation-20250708222033
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +510 -2
- package/LICENSE.md +11 -42
- package/README.md +1 -1
- package/dist/index.cjs +803 -26
- package/dist/index.d.cts +283 -17
- package/dist/index.d.ts +283 -17
- package/dist/index.js +804 -27
- package/package.json +21 -17
- package/src/client.ts +149 -3
- package/src/example.ts +4 -1
- package/src/resources/agent.ts +576 -10
- package/src/resources/base.ts +2 -0
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +2 -3
- package/src/resources/vNextNetwork.ts +177 -0
- package/src/resources/workflow.ts +54 -7
- package/src/types.ts +123 -10
- package/src/utils/process-client-tools.ts +32 -0
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var rxjs = require('rxjs');
|
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
6
|
var zod = require('zod');
|
|
7
7
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var tools = require('@mastra/core/tools');
|
|
8
9
|
var runtimeContext = require('@mastra/core/runtime-context');
|
|
9
10
|
|
|
10
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -202,6 +203,33 @@ function zodToJsonSchema(zodSchema) {
|
|
|
202
203
|
}
|
|
203
204
|
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
204
205
|
}
|
|
206
|
+
function processClientTools(clientTools) {
|
|
207
|
+
if (!clientTools) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
return Object.fromEntries(
|
|
211
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
212
|
+
if (tools.isVercelTool(value)) {
|
|
213
|
+
return [
|
|
214
|
+
key,
|
|
215
|
+
{
|
|
216
|
+
...value,
|
|
217
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
} else {
|
|
221
|
+
return [
|
|
222
|
+
key,
|
|
223
|
+
{
|
|
224
|
+
...value,
|
|
225
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
226
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
}
|
|
205
233
|
|
|
206
234
|
// src/resources/base.ts
|
|
207
235
|
var BaseResource = class {
|
|
@@ -224,11 +252,13 @@ var BaseResource = class {
|
|
|
224
252
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
225
253
|
...options,
|
|
226
254
|
headers: {
|
|
255
|
+
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
227
256
|
...headers,
|
|
228
257
|
...options.headers
|
|
229
258
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
230
259
|
// 'x-mastra-client-type': 'js',
|
|
231
260
|
},
|
|
261
|
+
signal: this.options.abortSignal,
|
|
232
262
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
233
263
|
});
|
|
234
264
|
if (!response.ok) {
|
|
@@ -270,8 +300,6 @@ function parseClientRuntimeContext(runtimeContext$1) {
|
|
|
270
300
|
}
|
|
271
301
|
return void 0;
|
|
272
302
|
}
|
|
273
|
-
|
|
274
|
-
// src/resources/agent.ts
|
|
275
303
|
var AgentVoice = class extends BaseResource {
|
|
276
304
|
constructor(options, agentId) {
|
|
277
305
|
super(options);
|
|
@@ -318,6 +346,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
318
346
|
getSpeakers() {
|
|
319
347
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
320
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Get the listener configuration for the agent's voice provider
|
|
351
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
352
|
+
*/
|
|
353
|
+
getListener() {
|
|
354
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
355
|
+
}
|
|
321
356
|
};
|
|
322
357
|
var Agent = class extends BaseResource {
|
|
323
358
|
constructor(options, agentId) {
|
|
@@ -333,22 +368,318 @@ var Agent = class extends BaseResource {
|
|
|
333
368
|
details() {
|
|
334
369
|
return this.request(`/api/agents/${this.agentId}`);
|
|
335
370
|
}
|
|
336
|
-
|
|
337
|
-
* Generates a response from the agent
|
|
338
|
-
* @param params - Generation parameters including prompt
|
|
339
|
-
* @returns Promise containing the generated response
|
|
340
|
-
*/
|
|
341
|
-
generate(params) {
|
|
371
|
+
async generate(params) {
|
|
342
372
|
const processedParams = {
|
|
343
373
|
...params,
|
|
344
374
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
345
375
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
346
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
376
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
377
|
+
clientTools: processClientTools(params.clientTools)
|
|
347
378
|
};
|
|
348
|
-
|
|
379
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
380
|
+
const response = await this.request(`/api/agents/${this.agentId}/generate`, {
|
|
349
381
|
method: "POST",
|
|
350
382
|
body: processedParams
|
|
351
383
|
});
|
|
384
|
+
if (response.finishReason === "tool-calls") {
|
|
385
|
+
for (const toolCall of response.toolCalls) {
|
|
386
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
387
|
+
if (clientTool && clientTool.execute) {
|
|
388
|
+
const result = await clientTool.execute(
|
|
389
|
+
{ context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
|
|
390
|
+
{
|
|
391
|
+
messages: response.messages,
|
|
392
|
+
toolCallId: toolCall?.toolCallId
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
const updatedMessages = [
|
|
396
|
+
{
|
|
397
|
+
role: "user",
|
|
398
|
+
content: params.messages
|
|
399
|
+
},
|
|
400
|
+
...response.response.messages,
|
|
401
|
+
{
|
|
402
|
+
role: "tool",
|
|
403
|
+
content: [
|
|
404
|
+
{
|
|
405
|
+
type: "tool-result",
|
|
406
|
+
toolCallId: toolCall.toolCallId,
|
|
407
|
+
toolName: toolCall.toolName,
|
|
408
|
+
result
|
|
409
|
+
}
|
|
410
|
+
]
|
|
411
|
+
}
|
|
412
|
+
];
|
|
413
|
+
return this.generate({
|
|
414
|
+
...params,
|
|
415
|
+
messages: updatedMessages
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return response;
|
|
421
|
+
}
|
|
422
|
+
async processChatResponse({
|
|
423
|
+
stream,
|
|
424
|
+
update,
|
|
425
|
+
onToolCall,
|
|
426
|
+
onFinish,
|
|
427
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
428
|
+
lastMessage
|
|
429
|
+
}) {
|
|
430
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
431
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
432
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
433
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
434
|
+
}, 0) ?? 0) : 0;
|
|
435
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
436
|
+
id: crypto.randomUUID(),
|
|
437
|
+
createdAt: getCurrentDate(),
|
|
438
|
+
role: "assistant",
|
|
439
|
+
content: "",
|
|
440
|
+
parts: []
|
|
441
|
+
};
|
|
442
|
+
let currentTextPart = void 0;
|
|
443
|
+
let currentReasoningPart = void 0;
|
|
444
|
+
let currentReasoningTextDetail = void 0;
|
|
445
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
446
|
+
const part = message.parts.find(
|
|
447
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
448
|
+
);
|
|
449
|
+
if (part != null) {
|
|
450
|
+
part.toolInvocation = invocation;
|
|
451
|
+
} else {
|
|
452
|
+
message.parts.push({
|
|
453
|
+
type: "tool-invocation",
|
|
454
|
+
toolInvocation: invocation
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const data = [];
|
|
459
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
460
|
+
const partialToolCalls = {};
|
|
461
|
+
let usage = {
|
|
462
|
+
completionTokens: NaN,
|
|
463
|
+
promptTokens: NaN,
|
|
464
|
+
totalTokens: NaN
|
|
465
|
+
};
|
|
466
|
+
let finishReason = "unknown";
|
|
467
|
+
function execUpdate() {
|
|
468
|
+
const copiedData = [...data];
|
|
469
|
+
if (messageAnnotations?.length) {
|
|
470
|
+
message.annotations = messageAnnotations;
|
|
471
|
+
}
|
|
472
|
+
const copiedMessage = {
|
|
473
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
474
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
475
|
+
...structuredClone(message),
|
|
476
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
477
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
478
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
479
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
480
|
+
// forwarded to rendering):
|
|
481
|
+
revisionId: crypto.randomUUID()
|
|
482
|
+
};
|
|
483
|
+
update({
|
|
484
|
+
message: copiedMessage,
|
|
485
|
+
data: copiedData,
|
|
486
|
+
replaceLastMessage
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
await uiUtils.processDataStream({
|
|
490
|
+
stream,
|
|
491
|
+
onTextPart(value) {
|
|
492
|
+
if (currentTextPart == null) {
|
|
493
|
+
currentTextPart = {
|
|
494
|
+
type: "text",
|
|
495
|
+
text: value
|
|
496
|
+
};
|
|
497
|
+
message.parts.push(currentTextPart);
|
|
498
|
+
} else {
|
|
499
|
+
currentTextPart.text += value;
|
|
500
|
+
}
|
|
501
|
+
message.content += value;
|
|
502
|
+
execUpdate();
|
|
503
|
+
},
|
|
504
|
+
onReasoningPart(value) {
|
|
505
|
+
if (currentReasoningTextDetail == null) {
|
|
506
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
507
|
+
if (currentReasoningPart != null) {
|
|
508
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
currentReasoningTextDetail.text += value;
|
|
512
|
+
}
|
|
513
|
+
if (currentReasoningPart == null) {
|
|
514
|
+
currentReasoningPart = {
|
|
515
|
+
type: "reasoning",
|
|
516
|
+
reasoning: value,
|
|
517
|
+
details: [currentReasoningTextDetail]
|
|
518
|
+
};
|
|
519
|
+
message.parts.push(currentReasoningPart);
|
|
520
|
+
} else {
|
|
521
|
+
currentReasoningPart.reasoning += value;
|
|
522
|
+
}
|
|
523
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
524
|
+
execUpdate();
|
|
525
|
+
},
|
|
526
|
+
onReasoningSignaturePart(value) {
|
|
527
|
+
if (currentReasoningTextDetail != null) {
|
|
528
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
onRedactedReasoningPart(value) {
|
|
532
|
+
if (currentReasoningPart == null) {
|
|
533
|
+
currentReasoningPart = {
|
|
534
|
+
type: "reasoning",
|
|
535
|
+
reasoning: "",
|
|
536
|
+
details: []
|
|
537
|
+
};
|
|
538
|
+
message.parts.push(currentReasoningPart);
|
|
539
|
+
}
|
|
540
|
+
currentReasoningPart.details.push({
|
|
541
|
+
type: "redacted",
|
|
542
|
+
data: value.data
|
|
543
|
+
});
|
|
544
|
+
currentReasoningTextDetail = void 0;
|
|
545
|
+
execUpdate();
|
|
546
|
+
},
|
|
547
|
+
onFilePart(value) {
|
|
548
|
+
message.parts.push({
|
|
549
|
+
type: "file",
|
|
550
|
+
mimeType: value.mimeType,
|
|
551
|
+
data: value.data
|
|
552
|
+
});
|
|
553
|
+
execUpdate();
|
|
554
|
+
},
|
|
555
|
+
onSourcePart(value) {
|
|
556
|
+
message.parts.push({
|
|
557
|
+
type: "source",
|
|
558
|
+
source: value
|
|
559
|
+
});
|
|
560
|
+
execUpdate();
|
|
561
|
+
},
|
|
562
|
+
onToolCallStreamingStartPart(value) {
|
|
563
|
+
if (message.toolInvocations == null) {
|
|
564
|
+
message.toolInvocations = [];
|
|
565
|
+
}
|
|
566
|
+
partialToolCalls[value.toolCallId] = {
|
|
567
|
+
text: "",
|
|
568
|
+
step,
|
|
569
|
+
toolName: value.toolName,
|
|
570
|
+
index: message.toolInvocations.length
|
|
571
|
+
};
|
|
572
|
+
const invocation = {
|
|
573
|
+
state: "partial-call",
|
|
574
|
+
step,
|
|
575
|
+
toolCallId: value.toolCallId,
|
|
576
|
+
toolName: value.toolName,
|
|
577
|
+
args: void 0
|
|
578
|
+
};
|
|
579
|
+
message.toolInvocations.push(invocation);
|
|
580
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
581
|
+
execUpdate();
|
|
582
|
+
},
|
|
583
|
+
onToolCallDeltaPart(value) {
|
|
584
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
585
|
+
partialToolCall.text += value.argsTextDelta;
|
|
586
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
587
|
+
const invocation = {
|
|
588
|
+
state: "partial-call",
|
|
589
|
+
step: partialToolCall.step,
|
|
590
|
+
toolCallId: value.toolCallId,
|
|
591
|
+
toolName: partialToolCall.toolName,
|
|
592
|
+
args: partialArgs
|
|
593
|
+
};
|
|
594
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
595
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
596
|
+
execUpdate();
|
|
597
|
+
},
|
|
598
|
+
async onToolCallPart(value) {
|
|
599
|
+
const invocation = {
|
|
600
|
+
state: "call",
|
|
601
|
+
step,
|
|
602
|
+
...value
|
|
603
|
+
};
|
|
604
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
605
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
606
|
+
} else {
|
|
607
|
+
if (message.toolInvocations == null) {
|
|
608
|
+
message.toolInvocations = [];
|
|
609
|
+
}
|
|
610
|
+
message.toolInvocations.push(invocation);
|
|
611
|
+
}
|
|
612
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
613
|
+
execUpdate();
|
|
614
|
+
if (onToolCall) {
|
|
615
|
+
const result = await onToolCall({ toolCall: value });
|
|
616
|
+
if (result != null) {
|
|
617
|
+
const invocation2 = {
|
|
618
|
+
state: "result",
|
|
619
|
+
step,
|
|
620
|
+
...value,
|
|
621
|
+
result
|
|
622
|
+
};
|
|
623
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
624
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
625
|
+
execUpdate();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
onToolResultPart(value) {
|
|
630
|
+
const toolInvocations = message.toolInvocations;
|
|
631
|
+
if (toolInvocations == null) {
|
|
632
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
633
|
+
}
|
|
634
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
635
|
+
if (toolInvocationIndex === -1) {
|
|
636
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
637
|
+
}
|
|
638
|
+
const invocation = {
|
|
639
|
+
...toolInvocations[toolInvocationIndex],
|
|
640
|
+
state: "result",
|
|
641
|
+
...value
|
|
642
|
+
};
|
|
643
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
644
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
645
|
+
execUpdate();
|
|
646
|
+
},
|
|
647
|
+
onDataPart(value) {
|
|
648
|
+
data.push(...value);
|
|
649
|
+
execUpdate();
|
|
650
|
+
},
|
|
651
|
+
onMessageAnnotationsPart(value) {
|
|
652
|
+
if (messageAnnotations == null) {
|
|
653
|
+
messageAnnotations = [...value];
|
|
654
|
+
} else {
|
|
655
|
+
messageAnnotations.push(...value);
|
|
656
|
+
}
|
|
657
|
+
execUpdate();
|
|
658
|
+
},
|
|
659
|
+
onFinishStepPart(value) {
|
|
660
|
+
step += 1;
|
|
661
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
662
|
+
currentReasoningPart = void 0;
|
|
663
|
+
currentReasoningTextDetail = void 0;
|
|
664
|
+
},
|
|
665
|
+
onStartStepPart(value) {
|
|
666
|
+
if (!replaceLastMessage) {
|
|
667
|
+
message.id = value.messageId;
|
|
668
|
+
}
|
|
669
|
+
message.parts.push({ type: "step-start" });
|
|
670
|
+
execUpdate();
|
|
671
|
+
},
|
|
672
|
+
onFinishMessagePart(value) {
|
|
673
|
+
finishReason = value.finishReason;
|
|
674
|
+
if (value.usage != null) {
|
|
675
|
+
usage = value.usage;
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
onErrorPart(error) {
|
|
679
|
+
throw new Error(error);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
onFinish?.({ message, finishReason, usage });
|
|
352
683
|
}
|
|
353
684
|
/**
|
|
354
685
|
* Streams a response from the agent
|
|
@@ -360,8 +691,28 @@ var Agent = class extends BaseResource {
|
|
|
360
691
|
...params,
|
|
361
692
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
362
693
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
363
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
694
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
695
|
+
clientTools: processClientTools(params.clientTools)
|
|
364
696
|
};
|
|
697
|
+
const { readable, writable } = new TransformStream();
|
|
698
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
699
|
+
const streamResponse = new Response(readable, {
|
|
700
|
+
status: response.status,
|
|
701
|
+
statusText: response.statusText,
|
|
702
|
+
headers: response.headers
|
|
703
|
+
});
|
|
704
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
705
|
+
await uiUtils.processDataStream({
|
|
706
|
+
stream: streamResponse.body,
|
|
707
|
+
...options
|
|
708
|
+
});
|
|
709
|
+
};
|
|
710
|
+
return streamResponse;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Processes the stream response and handles tool calls
|
|
714
|
+
*/
|
|
715
|
+
async processStreamResponse(processedParams, writable) {
|
|
365
716
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
366
717
|
method: "POST",
|
|
367
718
|
body: processedParams,
|
|
@@ -370,12 +721,95 @@ var Agent = class extends BaseResource {
|
|
|
370
721
|
if (!response.body) {
|
|
371
722
|
throw new Error("No response body");
|
|
372
723
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
724
|
+
try {
|
|
725
|
+
let toolCalls = [];
|
|
726
|
+
let messages = [];
|
|
727
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
728
|
+
streamForWritable.pipeTo(writable, {
|
|
729
|
+
preventClose: true
|
|
730
|
+
}).catch((error) => {
|
|
731
|
+
console.error("Error piping to writable stream:", error);
|
|
377
732
|
});
|
|
378
|
-
|
|
733
|
+
this.processChatResponse({
|
|
734
|
+
stream: streamForProcessing,
|
|
735
|
+
update: ({ message }) => {
|
|
736
|
+
messages.push(message);
|
|
737
|
+
},
|
|
738
|
+
onFinish: async ({ finishReason, message }) => {
|
|
739
|
+
if (finishReason === "tool-calls") {
|
|
740
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
741
|
+
if (toolCall) {
|
|
742
|
+
toolCalls.push(toolCall);
|
|
743
|
+
}
|
|
744
|
+
for (const toolCall2 of toolCalls) {
|
|
745
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
746
|
+
if (clientTool && clientTool.execute) {
|
|
747
|
+
const result = await clientTool.execute(
|
|
748
|
+
{
|
|
749
|
+
context: toolCall2?.args,
|
|
750
|
+
runId: processedParams.runId,
|
|
751
|
+
resourceId: processedParams.resourceId,
|
|
752
|
+
threadId: processedParams.threadId,
|
|
753
|
+
runtimeContext: processedParams.runtimeContext
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
messages: response.messages,
|
|
757
|
+
toolCallId: toolCall2?.toolCallId
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
761
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
762
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
763
|
+
);
|
|
764
|
+
if (toolInvocationPart) {
|
|
765
|
+
toolInvocationPart.toolInvocation = {
|
|
766
|
+
...toolInvocationPart.toolInvocation,
|
|
767
|
+
state: "result",
|
|
768
|
+
result
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
772
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
773
|
+
);
|
|
774
|
+
if (toolInvocation) {
|
|
775
|
+
toolInvocation.state = "result";
|
|
776
|
+
toolInvocation.result = result;
|
|
777
|
+
}
|
|
778
|
+
const writer = writable.getWriter();
|
|
779
|
+
try {
|
|
780
|
+
await writer.write(
|
|
781
|
+
new TextEncoder().encode(
|
|
782
|
+
"a:" + JSON.stringify({
|
|
783
|
+
toolCallId: toolCall2.toolCallId,
|
|
784
|
+
result
|
|
785
|
+
}) + "\n"
|
|
786
|
+
)
|
|
787
|
+
);
|
|
788
|
+
} finally {
|
|
789
|
+
writer.releaseLock();
|
|
790
|
+
}
|
|
791
|
+
const originalMessages = processedParams.messages;
|
|
792
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
793
|
+
this.processStreamResponse(
|
|
794
|
+
{
|
|
795
|
+
...processedParams,
|
|
796
|
+
messages: [...messageArray, ...messages, lastMessage]
|
|
797
|
+
},
|
|
798
|
+
writable
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
} else {
|
|
803
|
+
setTimeout(() => {
|
|
804
|
+
writable.close();
|
|
805
|
+
}, 0);
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
lastMessage: void 0
|
|
809
|
+
});
|
|
810
|
+
} catch (error) {
|
|
811
|
+
console.error("Error processing stream response:", error);
|
|
812
|
+
}
|
|
379
813
|
return response;
|
|
380
814
|
}
|
|
381
815
|
/**
|
|
@@ -770,7 +1204,7 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
770
1204
|
};
|
|
771
1205
|
|
|
772
1206
|
// src/resources/tool.ts
|
|
773
|
-
var
|
|
1207
|
+
var Tool2 = class extends BaseResource {
|
|
774
1208
|
constructor(options, toolId) {
|
|
775
1209
|
super(options);
|
|
776
1210
|
this.toolId = toolId;
|
|
@@ -875,10 +1309,10 @@ var Workflow = class extends BaseResource {
|
|
|
875
1309
|
if (params?.toDate) {
|
|
876
1310
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
877
1311
|
}
|
|
878
|
-
if (params?.limit) {
|
|
1312
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
879
1313
|
searchParams.set("limit", String(params.limit));
|
|
880
1314
|
}
|
|
881
|
-
if (params?.offset) {
|
|
1315
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
882
1316
|
searchParams.set("offset", String(params.offset));
|
|
883
1317
|
}
|
|
884
1318
|
if (params?.resourceId) {
|
|
@@ -890,6 +1324,43 @@ var Workflow = class extends BaseResource {
|
|
|
890
1324
|
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
891
1325
|
}
|
|
892
1326
|
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Retrieves a specific workflow run by its ID
|
|
1329
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1330
|
+
* @returns Promise containing the workflow run details
|
|
1331
|
+
*/
|
|
1332
|
+
runById(runId) {
|
|
1333
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1337
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1338
|
+
* @returns Promise containing the workflow run execution result
|
|
1339
|
+
*/
|
|
1340
|
+
runExecutionResult(runId) {
|
|
1341
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Cancels a specific workflow run by its ID
|
|
1345
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1346
|
+
* @returns Promise containing a success message
|
|
1347
|
+
*/
|
|
1348
|
+
cancelRun(runId) {
|
|
1349
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1350
|
+
method: "POST"
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Sends an event to a specific workflow run by its ID
|
|
1355
|
+
* @param params - Object containing the runId, event and data
|
|
1356
|
+
* @returns Promise containing a success message
|
|
1357
|
+
*/
|
|
1358
|
+
sendRunEvent(params) {
|
|
1359
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1360
|
+
method: "POST",
|
|
1361
|
+
body: { event: params.event, data: params.data }
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
893
1364
|
/**
|
|
894
1365
|
* Creates a new workflow run
|
|
895
1366
|
* @param params - Optional object containing the optional runId
|
|
@@ -955,16 +1426,16 @@ var Workflow = class extends BaseResource {
|
|
|
955
1426
|
});
|
|
956
1427
|
}
|
|
957
1428
|
/**
|
|
958
|
-
* Starts a
|
|
1429
|
+
* Starts a workflow run and returns a stream
|
|
959
1430
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
960
|
-
* @returns Promise containing the
|
|
1431
|
+
* @returns Promise containing the workflow execution results
|
|
961
1432
|
*/
|
|
962
1433
|
async stream(params) {
|
|
963
1434
|
const searchParams = new URLSearchParams();
|
|
964
1435
|
if (!!params?.runId) {
|
|
965
1436
|
searchParams.set("runId", params.runId);
|
|
966
1437
|
}
|
|
967
|
-
const runtimeContext =
|
|
1438
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
968
1439
|
const response = await this.request(
|
|
969
1440
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
970
1441
|
{
|
|
@@ -1033,7 +1504,11 @@ var Workflow = class extends BaseResource {
|
|
|
1033
1504
|
throw new Error("Response body is null");
|
|
1034
1505
|
}
|
|
1035
1506
|
for await (const record of this.streamProcessor(response.body)) {
|
|
1036
|
-
|
|
1507
|
+
if (typeof record === "string") {
|
|
1508
|
+
onRecord(JSON.parse(record));
|
|
1509
|
+
} else {
|
|
1510
|
+
onRecord(record);
|
|
1511
|
+
}
|
|
1037
1512
|
}
|
|
1038
1513
|
}
|
|
1039
1514
|
/**
|
|
@@ -1169,6 +1644,180 @@ var MCPTool = class extends BaseResource {
|
|
|
1169
1644
|
}
|
|
1170
1645
|
};
|
|
1171
1646
|
|
|
1647
|
+
// src/resources/vNextNetwork.ts
|
|
1648
|
+
var RECORD_SEPARATOR3 = "";
|
|
1649
|
+
var VNextNetwork = class extends BaseResource {
|
|
1650
|
+
constructor(options, networkId) {
|
|
1651
|
+
super(options);
|
|
1652
|
+
this.networkId = networkId;
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Retrieves details about the network
|
|
1656
|
+
* @returns Promise containing vNext network details
|
|
1657
|
+
*/
|
|
1658
|
+
details() {
|
|
1659
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Generates a response from the v-next network
|
|
1663
|
+
* @param params - Generation parameters including message
|
|
1664
|
+
* @returns Promise containing the generated response
|
|
1665
|
+
*/
|
|
1666
|
+
generate(params) {
|
|
1667
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1668
|
+
method: "POST",
|
|
1669
|
+
body: params
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1674
|
+
* @param params - Generation parameters including message
|
|
1675
|
+
* @returns Promise containing the generated response
|
|
1676
|
+
*/
|
|
1677
|
+
loop(params) {
|
|
1678
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1679
|
+
method: "POST",
|
|
1680
|
+
body: params
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
async *streamProcessor(stream) {
|
|
1684
|
+
const reader = stream.getReader();
|
|
1685
|
+
let doneReading = false;
|
|
1686
|
+
let buffer = "";
|
|
1687
|
+
try {
|
|
1688
|
+
while (!doneReading) {
|
|
1689
|
+
const { done, value } = await reader.read();
|
|
1690
|
+
doneReading = done;
|
|
1691
|
+
if (done && !value) continue;
|
|
1692
|
+
try {
|
|
1693
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1694
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1695
|
+
buffer = chunks.pop() || "";
|
|
1696
|
+
for (const chunk of chunks) {
|
|
1697
|
+
if (chunk) {
|
|
1698
|
+
if (typeof chunk === "string") {
|
|
1699
|
+
try {
|
|
1700
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1701
|
+
yield parsedChunk;
|
|
1702
|
+
} catch {
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
} catch {
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (buffer) {
|
|
1711
|
+
try {
|
|
1712
|
+
yield JSON.parse(buffer);
|
|
1713
|
+
} catch {
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
} finally {
|
|
1717
|
+
reader.cancel().catch(() => {
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Streams a response from the v-next network
|
|
1723
|
+
* @param params - Stream parameters including message
|
|
1724
|
+
* @returns Promise containing the results
|
|
1725
|
+
*/
|
|
1726
|
+
async stream(params, onRecord) {
|
|
1727
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1728
|
+
method: "POST",
|
|
1729
|
+
body: params,
|
|
1730
|
+
stream: true
|
|
1731
|
+
});
|
|
1732
|
+
if (!response.ok) {
|
|
1733
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1734
|
+
}
|
|
1735
|
+
if (!response.body) {
|
|
1736
|
+
throw new Error("Response body is null");
|
|
1737
|
+
}
|
|
1738
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1739
|
+
if (typeof record === "string") {
|
|
1740
|
+
onRecord(JSON.parse(record));
|
|
1741
|
+
} else {
|
|
1742
|
+
onRecord(record);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Streams a response from the v-next network loop
|
|
1748
|
+
* @param params - Stream parameters including message
|
|
1749
|
+
* @returns Promise containing the results
|
|
1750
|
+
*/
|
|
1751
|
+
async loopStream(params, onRecord) {
|
|
1752
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1753
|
+
method: "POST",
|
|
1754
|
+
body: params,
|
|
1755
|
+
stream: true
|
|
1756
|
+
});
|
|
1757
|
+
if (!response.ok) {
|
|
1758
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
1759
|
+
}
|
|
1760
|
+
if (!response.body) {
|
|
1761
|
+
throw new Error("Response body is null");
|
|
1762
|
+
}
|
|
1763
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1764
|
+
if (typeof record === "string") {
|
|
1765
|
+
onRecord(JSON.parse(record));
|
|
1766
|
+
} else {
|
|
1767
|
+
onRecord(record);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
// src/resources/network-memory-thread.ts
|
|
1774
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1775
|
+
constructor(options, threadId, networkId) {
|
|
1776
|
+
super(options);
|
|
1777
|
+
this.threadId = threadId;
|
|
1778
|
+
this.networkId = networkId;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Retrieves the memory thread details
|
|
1782
|
+
* @returns Promise containing thread details including title and metadata
|
|
1783
|
+
*/
|
|
1784
|
+
get() {
|
|
1785
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Updates the memory thread properties
|
|
1789
|
+
* @param params - Update parameters including title and metadata
|
|
1790
|
+
* @returns Promise containing updated thread details
|
|
1791
|
+
*/
|
|
1792
|
+
update(params) {
|
|
1793
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1794
|
+
method: "PATCH",
|
|
1795
|
+
body: params
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Deletes the memory thread
|
|
1800
|
+
* @returns Promise containing deletion result
|
|
1801
|
+
*/
|
|
1802
|
+
delete() {
|
|
1803
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1804
|
+
method: "DELETE"
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Retrieves messages associated with the thread
|
|
1809
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1810
|
+
* @returns Promise containing thread messages and UI messages
|
|
1811
|
+
*/
|
|
1812
|
+
getMessages(params) {
|
|
1813
|
+
const query = new URLSearchParams({
|
|
1814
|
+
networkId: this.networkId,
|
|
1815
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1816
|
+
});
|
|
1817
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1172
1821
|
// src/client.ts
|
|
1173
1822
|
var MastraClient = class extends BaseResource {
|
|
1174
1823
|
constructor(options) {
|
|
@@ -1246,6 +1895,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1246
1895
|
getMemoryStatus(agentId) {
|
|
1247
1896
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1248
1897
|
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Retrieves memory threads for a resource
|
|
1900
|
+
* @param params - Parameters containing the resource ID
|
|
1901
|
+
* @returns Promise containing array of memory threads
|
|
1902
|
+
*/
|
|
1903
|
+
getNetworkMemoryThreads(params) {
|
|
1904
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* Creates a new memory thread
|
|
1908
|
+
* @param params - Parameters for creating the memory thread
|
|
1909
|
+
* @returns Promise containing the created memory thread
|
|
1910
|
+
*/
|
|
1911
|
+
createNetworkMemoryThread(params) {
|
|
1912
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1913
|
+
}
|
|
1914
|
+
/**
|
|
1915
|
+
* Gets a memory thread instance by ID
|
|
1916
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
1917
|
+
* @returns MemoryThread instance
|
|
1918
|
+
*/
|
|
1919
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
1920
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Saves messages to memory
|
|
1924
|
+
* @param params - Parameters containing messages to save
|
|
1925
|
+
* @returns Promise containing the saved messages
|
|
1926
|
+
*/
|
|
1927
|
+
saveNetworkMessageToMemory(params) {
|
|
1928
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
1929
|
+
method: "POST",
|
|
1930
|
+
body: params
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Gets the status of the memory system
|
|
1935
|
+
* @returns Promise containing memory system status
|
|
1936
|
+
*/
|
|
1937
|
+
getNetworkMemoryStatus(networkId) {
|
|
1938
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
1939
|
+
}
|
|
1249
1940
|
/**
|
|
1250
1941
|
* Retrieves all available tools
|
|
1251
1942
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1259,7 +1950,7 @@ var MastraClient = class extends BaseResource {
|
|
|
1259
1950
|
* @returns Tool instance
|
|
1260
1951
|
*/
|
|
1261
1952
|
getTool(toolId) {
|
|
1262
|
-
return new
|
|
1953
|
+
return new Tool2(this.options, toolId);
|
|
1263
1954
|
}
|
|
1264
1955
|
/**
|
|
1265
1956
|
* Retrieves all available legacy workflows
|
|
@@ -1305,7 +1996,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1305
1996
|
* @returns Promise containing array of log messages
|
|
1306
1997
|
*/
|
|
1307
1998
|
getLogs(params) {
|
|
1308
|
-
|
|
1999
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2000
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2001
|
+
const searchParams = new URLSearchParams();
|
|
2002
|
+
if (transportId) {
|
|
2003
|
+
searchParams.set("transportId", transportId);
|
|
2004
|
+
}
|
|
2005
|
+
if (fromDate) {
|
|
2006
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2007
|
+
}
|
|
2008
|
+
if (toDate) {
|
|
2009
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2010
|
+
}
|
|
2011
|
+
if (logLevel) {
|
|
2012
|
+
searchParams.set("logLevel", logLevel);
|
|
2013
|
+
}
|
|
2014
|
+
if (page) {
|
|
2015
|
+
searchParams.set("page", String(page));
|
|
2016
|
+
}
|
|
2017
|
+
if (perPage) {
|
|
2018
|
+
searchParams.set("perPage", String(perPage));
|
|
2019
|
+
}
|
|
2020
|
+
if (_filters) {
|
|
2021
|
+
if (Array.isArray(_filters)) {
|
|
2022
|
+
for (const filter of _filters) {
|
|
2023
|
+
searchParams.append("filters", filter);
|
|
2024
|
+
}
|
|
2025
|
+
} else {
|
|
2026
|
+
searchParams.set("filters", _filters);
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
if (searchParams.size) {
|
|
2030
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
2031
|
+
} else {
|
|
2032
|
+
return this.request(`/api/logs`);
|
|
2033
|
+
}
|
|
1309
2034
|
}
|
|
1310
2035
|
/**
|
|
1311
2036
|
* Gets logs for a specific run
|
|
@@ -1313,7 +2038,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1313
2038
|
* @returns Promise containing array of log messages
|
|
1314
2039
|
*/
|
|
1315
2040
|
getLogForRun(params) {
|
|
1316
|
-
|
|
2041
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2042
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2043
|
+
const searchParams = new URLSearchParams();
|
|
2044
|
+
if (runId) {
|
|
2045
|
+
searchParams.set("runId", runId);
|
|
2046
|
+
}
|
|
2047
|
+
if (transportId) {
|
|
2048
|
+
searchParams.set("transportId", transportId);
|
|
2049
|
+
}
|
|
2050
|
+
if (fromDate) {
|
|
2051
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2052
|
+
}
|
|
2053
|
+
if (toDate) {
|
|
2054
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2055
|
+
}
|
|
2056
|
+
if (logLevel) {
|
|
2057
|
+
searchParams.set("logLevel", logLevel);
|
|
2058
|
+
}
|
|
2059
|
+
if (page) {
|
|
2060
|
+
searchParams.set("page", String(page));
|
|
2061
|
+
}
|
|
2062
|
+
if (perPage) {
|
|
2063
|
+
searchParams.set("perPage", String(perPage));
|
|
2064
|
+
}
|
|
2065
|
+
if (_filters) {
|
|
2066
|
+
if (Array.isArray(_filters)) {
|
|
2067
|
+
for (const filter of _filters) {
|
|
2068
|
+
searchParams.append("filters", filter);
|
|
2069
|
+
}
|
|
2070
|
+
} else {
|
|
2071
|
+
searchParams.set("filters", _filters);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
if (searchParams.size) {
|
|
2075
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2076
|
+
} else {
|
|
2077
|
+
return this.request(`/api/logs/${runId}`);
|
|
2078
|
+
}
|
|
1317
2079
|
}
|
|
1318
2080
|
/**
|
|
1319
2081
|
* List of all log transports
|
|
@@ -1371,6 +2133,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1371
2133
|
getNetworks() {
|
|
1372
2134
|
return this.request("/api/networks");
|
|
1373
2135
|
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Retrieves all available vNext networks
|
|
2138
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2139
|
+
*/
|
|
2140
|
+
getVNextNetworks() {
|
|
2141
|
+
return this.request("/api/networks/v-next");
|
|
2142
|
+
}
|
|
1374
2143
|
/**
|
|
1375
2144
|
* Gets a network instance by ID
|
|
1376
2145
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1379,6 +2148,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1379
2148
|
getNetwork(networkId) {
|
|
1380
2149
|
return new Network(this.options, networkId);
|
|
1381
2150
|
}
|
|
2151
|
+
/**
|
|
2152
|
+
* Gets a vNext network instance by ID
|
|
2153
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2154
|
+
* @returns vNext Network instance
|
|
2155
|
+
*/
|
|
2156
|
+
getVNextNetwork(networkId) {
|
|
2157
|
+
return new VNextNetwork(this.options, networkId);
|
|
2158
|
+
}
|
|
1382
2159
|
/**
|
|
1383
2160
|
* Retrieves a list of available MCP servers.
|
|
1384
2161
|
* @param params - Optional parameters for pagination (limit, offset).
|