@mastra/client-js 0.0.0-taofeeqInngest-20250603090617 → 0.0.0-transpile-packages-20250724123433
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 +575 -2
- package/LICENSE.md +11 -42
- package/README.md +2 -1
- package/dist/index.cjs +903 -33
- package/dist/index.d.cts +333 -16
- package/dist/index.d.ts +333 -16
- package/dist/index.js +904 -34
- package/package.json +22 -17
- package/src/client.ts +195 -3
- package/src/example.ts +46 -15
- package/src/index.test.ts +53 -5
- package/src/resources/agent.ts +613 -18
- package/src/resources/base.ts +4 -0
- package/src/resources/memory-thread.ts +18 -0
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +2 -3
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +66 -9
- package/src/types.ts +139 -6
- package/src/utils/process-client-tools.ts +32 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
3
|
+
import { processTextStream, processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
5
|
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
7
|
+
import { v4 } from '@lukeed/uuid';
|
|
6
8
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
7
9
|
|
|
8
10
|
// src/adapters/agui.ts
|
|
@@ -196,6 +198,33 @@ function zodToJsonSchema(zodSchema) {
|
|
|
196
198
|
}
|
|
197
199
|
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
198
200
|
}
|
|
201
|
+
function processClientTools(clientTools) {
|
|
202
|
+
if (!clientTools) {
|
|
203
|
+
return void 0;
|
|
204
|
+
}
|
|
205
|
+
return Object.fromEntries(
|
|
206
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
207
|
+
if (isVercelTool(value)) {
|
|
208
|
+
return [
|
|
209
|
+
key,
|
|
210
|
+
{
|
|
211
|
+
...value,
|
|
212
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
213
|
+
}
|
|
214
|
+
];
|
|
215
|
+
} else {
|
|
216
|
+
return [
|
|
217
|
+
key,
|
|
218
|
+
{
|
|
219
|
+
...value,
|
|
220
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
221
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
);
|
|
227
|
+
}
|
|
199
228
|
|
|
200
229
|
// src/resources/base.ts
|
|
201
230
|
var BaseResource = class {
|
|
@@ -218,11 +247,13 @@ var BaseResource = class {
|
|
|
218
247
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
219
248
|
...options,
|
|
220
249
|
headers: {
|
|
250
|
+
...options.body && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
221
251
|
...headers,
|
|
222
252
|
...options.headers
|
|
223
253
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
224
254
|
// 'x-mastra-client-type': 'js',
|
|
225
255
|
},
|
|
256
|
+
signal: this.options.abortSignal,
|
|
226
257
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
227
258
|
});
|
|
228
259
|
if (!response.ok) {
|
|
@@ -264,8 +295,6 @@ function parseClientRuntimeContext(runtimeContext) {
|
|
|
264
295
|
}
|
|
265
296
|
return void 0;
|
|
266
297
|
}
|
|
267
|
-
|
|
268
|
-
// src/resources/agent.ts
|
|
269
298
|
var AgentVoice = class extends BaseResource {
|
|
270
299
|
constructor(options, agentId) {
|
|
271
300
|
super(options);
|
|
@@ -334,50 +363,478 @@ var Agent = class extends BaseResource {
|
|
|
334
363
|
details() {
|
|
335
364
|
return this.request(`/api/agents/${this.agentId}`);
|
|
336
365
|
}
|
|
337
|
-
|
|
338
|
-
* Generates a response from the agent
|
|
339
|
-
* @param params - Generation parameters including prompt
|
|
340
|
-
* @returns Promise containing the generated response
|
|
341
|
-
*/
|
|
342
|
-
generate(params) {
|
|
366
|
+
async generate(params) {
|
|
343
367
|
const processedParams = {
|
|
344
368
|
...params,
|
|
345
369
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
346
370
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
347
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
371
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
372
|
+
clientTools: processClientTools(params.clientTools)
|
|
348
373
|
};
|
|
349
|
-
|
|
374
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
375
|
+
const response = await this.request(`/api/agents/${this.agentId}/generate`, {
|
|
350
376
|
method: "POST",
|
|
351
377
|
body: processedParams
|
|
352
378
|
});
|
|
379
|
+
if (response.finishReason === "tool-calls") {
|
|
380
|
+
const toolCalls = response.toolCalls;
|
|
381
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
382
|
+
return response;
|
|
383
|
+
}
|
|
384
|
+
for (const toolCall of toolCalls) {
|
|
385
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
386
|
+
if (clientTool && clientTool.execute) {
|
|
387
|
+
const result = await clientTool.execute(
|
|
388
|
+
{ context: toolCall?.args, runId, resourceId, threadId, runtimeContext },
|
|
389
|
+
{
|
|
390
|
+
messages: response.messages,
|
|
391
|
+
toolCallId: toolCall?.toolCallId
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
const updatedMessages = [
|
|
395
|
+
{
|
|
396
|
+
role: "user",
|
|
397
|
+
content: params.messages
|
|
398
|
+
},
|
|
399
|
+
...response.response.messages,
|
|
400
|
+
{
|
|
401
|
+
role: "tool",
|
|
402
|
+
content: [
|
|
403
|
+
{
|
|
404
|
+
type: "tool-result",
|
|
405
|
+
toolCallId: toolCall.toolCallId,
|
|
406
|
+
toolName: toolCall.toolName,
|
|
407
|
+
result
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
}
|
|
411
|
+
];
|
|
412
|
+
return this.generate({
|
|
413
|
+
...params,
|
|
414
|
+
messages: updatedMessages
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return response;
|
|
420
|
+
}
|
|
421
|
+
async processChatResponse({
|
|
422
|
+
stream,
|
|
423
|
+
update,
|
|
424
|
+
onToolCall,
|
|
425
|
+
onFinish,
|
|
426
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
427
|
+
lastMessage,
|
|
428
|
+
streamProtocol
|
|
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: v4(),
|
|
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: v4()
|
|
482
|
+
};
|
|
483
|
+
update({
|
|
484
|
+
message: copiedMessage,
|
|
485
|
+
data: copiedData,
|
|
486
|
+
replaceLastMessage
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (streamProtocol === "text") {
|
|
490
|
+
await processTextStream({
|
|
491
|
+
stream,
|
|
492
|
+
onTextPart(value) {
|
|
493
|
+
message.content += value;
|
|
494
|
+
execUpdate();
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
onFinish?.({ message, finishReason, usage });
|
|
498
|
+
} else {
|
|
499
|
+
await processDataStream({
|
|
500
|
+
stream,
|
|
501
|
+
onTextPart(value) {
|
|
502
|
+
if (currentTextPart == null) {
|
|
503
|
+
currentTextPart = {
|
|
504
|
+
type: "text",
|
|
505
|
+
text: value
|
|
506
|
+
};
|
|
507
|
+
message.parts.push(currentTextPart);
|
|
508
|
+
} else {
|
|
509
|
+
currentTextPart.text += value;
|
|
510
|
+
}
|
|
511
|
+
message.content += value;
|
|
512
|
+
execUpdate();
|
|
513
|
+
},
|
|
514
|
+
onReasoningPart(value) {
|
|
515
|
+
if (currentReasoningTextDetail == null) {
|
|
516
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
517
|
+
if (currentReasoningPart != null) {
|
|
518
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
currentReasoningTextDetail.text += value;
|
|
522
|
+
}
|
|
523
|
+
if (currentReasoningPart == null) {
|
|
524
|
+
currentReasoningPart = {
|
|
525
|
+
type: "reasoning",
|
|
526
|
+
reasoning: value,
|
|
527
|
+
details: [currentReasoningTextDetail]
|
|
528
|
+
};
|
|
529
|
+
message.parts.push(currentReasoningPart);
|
|
530
|
+
} else {
|
|
531
|
+
currentReasoningPart.reasoning += value;
|
|
532
|
+
}
|
|
533
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
534
|
+
execUpdate();
|
|
535
|
+
},
|
|
536
|
+
onReasoningSignaturePart(value) {
|
|
537
|
+
if (currentReasoningTextDetail != null) {
|
|
538
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
onRedactedReasoningPart(value) {
|
|
542
|
+
if (currentReasoningPart == null) {
|
|
543
|
+
currentReasoningPart = {
|
|
544
|
+
type: "reasoning",
|
|
545
|
+
reasoning: "",
|
|
546
|
+
details: []
|
|
547
|
+
};
|
|
548
|
+
message.parts.push(currentReasoningPart);
|
|
549
|
+
}
|
|
550
|
+
currentReasoningPart.details.push({
|
|
551
|
+
type: "redacted",
|
|
552
|
+
data: value.data
|
|
553
|
+
});
|
|
554
|
+
currentReasoningTextDetail = void 0;
|
|
555
|
+
execUpdate();
|
|
556
|
+
},
|
|
557
|
+
onFilePart(value) {
|
|
558
|
+
message.parts.push({
|
|
559
|
+
type: "file",
|
|
560
|
+
mimeType: value.mimeType,
|
|
561
|
+
data: value.data
|
|
562
|
+
});
|
|
563
|
+
execUpdate();
|
|
564
|
+
},
|
|
565
|
+
onSourcePart(value) {
|
|
566
|
+
message.parts.push({
|
|
567
|
+
type: "source",
|
|
568
|
+
source: value
|
|
569
|
+
});
|
|
570
|
+
execUpdate();
|
|
571
|
+
},
|
|
572
|
+
onToolCallStreamingStartPart(value) {
|
|
573
|
+
if (message.toolInvocations == null) {
|
|
574
|
+
message.toolInvocations = [];
|
|
575
|
+
}
|
|
576
|
+
partialToolCalls[value.toolCallId] = {
|
|
577
|
+
text: "",
|
|
578
|
+
step,
|
|
579
|
+
toolName: value.toolName,
|
|
580
|
+
index: message.toolInvocations.length
|
|
581
|
+
};
|
|
582
|
+
const invocation = {
|
|
583
|
+
state: "partial-call",
|
|
584
|
+
step,
|
|
585
|
+
toolCallId: value.toolCallId,
|
|
586
|
+
toolName: value.toolName,
|
|
587
|
+
args: void 0
|
|
588
|
+
};
|
|
589
|
+
message.toolInvocations.push(invocation);
|
|
590
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
591
|
+
execUpdate();
|
|
592
|
+
},
|
|
593
|
+
onToolCallDeltaPart(value) {
|
|
594
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
595
|
+
partialToolCall.text += value.argsTextDelta;
|
|
596
|
+
const { value: partialArgs } = parsePartialJson(partialToolCall.text);
|
|
597
|
+
const invocation = {
|
|
598
|
+
state: "partial-call",
|
|
599
|
+
step: partialToolCall.step,
|
|
600
|
+
toolCallId: value.toolCallId,
|
|
601
|
+
toolName: partialToolCall.toolName,
|
|
602
|
+
args: partialArgs
|
|
603
|
+
};
|
|
604
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
605
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
606
|
+
execUpdate();
|
|
607
|
+
},
|
|
608
|
+
async onToolCallPart(value) {
|
|
609
|
+
const invocation = {
|
|
610
|
+
state: "call",
|
|
611
|
+
step,
|
|
612
|
+
...value
|
|
613
|
+
};
|
|
614
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
615
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
616
|
+
} else {
|
|
617
|
+
if (message.toolInvocations == null) {
|
|
618
|
+
message.toolInvocations = [];
|
|
619
|
+
}
|
|
620
|
+
message.toolInvocations.push(invocation);
|
|
621
|
+
}
|
|
622
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
623
|
+
execUpdate();
|
|
624
|
+
if (onToolCall) {
|
|
625
|
+
const result = await onToolCall({ toolCall: value });
|
|
626
|
+
if (result != null) {
|
|
627
|
+
const invocation2 = {
|
|
628
|
+
state: "result",
|
|
629
|
+
step,
|
|
630
|
+
...value,
|
|
631
|
+
result
|
|
632
|
+
};
|
|
633
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
634
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
635
|
+
execUpdate();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
onToolResultPart(value) {
|
|
640
|
+
const toolInvocations = message.toolInvocations;
|
|
641
|
+
if (toolInvocations == null) {
|
|
642
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
643
|
+
}
|
|
644
|
+
const toolInvocationIndex = toolInvocations.findIndex(
|
|
645
|
+
(invocation2) => invocation2.toolCallId === value.toolCallId
|
|
646
|
+
);
|
|
647
|
+
if (toolInvocationIndex === -1) {
|
|
648
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
649
|
+
}
|
|
650
|
+
const invocation = {
|
|
651
|
+
...toolInvocations[toolInvocationIndex],
|
|
652
|
+
state: "result",
|
|
653
|
+
...value
|
|
654
|
+
};
|
|
655
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
656
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
657
|
+
execUpdate();
|
|
658
|
+
},
|
|
659
|
+
onDataPart(value) {
|
|
660
|
+
data.push(...value);
|
|
661
|
+
execUpdate();
|
|
662
|
+
},
|
|
663
|
+
onMessageAnnotationsPart(value) {
|
|
664
|
+
if (messageAnnotations == null) {
|
|
665
|
+
messageAnnotations = [...value];
|
|
666
|
+
} else {
|
|
667
|
+
messageAnnotations.push(...value);
|
|
668
|
+
}
|
|
669
|
+
execUpdate();
|
|
670
|
+
},
|
|
671
|
+
onFinishStepPart(value) {
|
|
672
|
+
step += 1;
|
|
673
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
674
|
+
currentReasoningPart = void 0;
|
|
675
|
+
currentReasoningTextDetail = void 0;
|
|
676
|
+
},
|
|
677
|
+
onStartStepPart(value) {
|
|
678
|
+
if (!replaceLastMessage) {
|
|
679
|
+
message.id = value.messageId;
|
|
680
|
+
}
|
|
681
|
+
message.parts.push({ type: "step-start" });
|
|
682
|
+
execUpdate();
|
|
683
|
+
},
|
|
684
|
+
onFinishMessagePart(value) {
|
|
685
|
+
finishReason = value.finishReason;
|
|
686
|
+
if (value.usage != null) {
|
|
687
|
+
usage = value.usage;
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
onErrorPart(error) {
|
|
691
|
+
throw new Error(error);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
onFinish?.({ message, finishReason, usage });
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Processes the stream response and handles tool calls
|
|
699
|
+
*/
|
|
700
|
+
async processStreamResponse(processedParams, writable) {
|
|
701
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
702
|
+
method: "POST",
|
|
703
|
+
body: processedParams,
|
|
704
|
+
stream: true
|
|
705
|
+
});
|
|
706
|
+
if (!response.body) {
|
|
707
|
+
throw new Error("No response body");
|
|
708
|
+
}
|
|
709
|
+
try {
|
|
710
|
+
const streamProtocol = processedParams.output ? "text" : "data";
|
|
711
|
+
let toolCalls = [];
|
|
712
|
+
let messages = [];
|
|
713
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
714
|
+
streamForWritable.pipeTo(writable, {
|
|
715
|
+
preventClose: true
|
|
716
|
+
}).catch((error) => {
|
|
717
|
+
console.error("Error piping to writable stream:", error);
|
|
718
|
+
});
|
|
719
|
+
this.processChatResponse({
|
|
720
|
+
stream: streamForProcessing,
|
|
721
|
+
update: ({ message }) => {
|
|
722
|
+
messages.push(message);
|
|
723
|
+
},
|
|
724
|
+
onFinish: async ({ finishReason, message }) => {
|
|
725
|
+
if (finishReason === "tool-calls") {
|
|
726
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
727
|
+
if (toolCall) {
|
|
728
|
+
toolCalls.push(toolCall);
|
|
729
|
+
}
|
|
730
|
+
for (const toolCall2 of toolCalls) {
|
|
731
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
732
|
+
if (clientTool && clientTool.execute) {
|
|
733
|
+
const result = await clientTool.execute(
|
|
734
|
+
{
|
|
735
|
+
context: toolCall2?.args,
|
|
736
|
+
runId: processedParams.runId,
|
|
737
|
+
resourceId: processedParams.resourceId,
|
|
738
|
+
threadId: processedParams.threadId,
|
|
739
|
+
runtimeContext: processedParams.runtimeContext
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
messages: response.messages,
|
|
743
|
+
toolCallId: toolCall2?.toolCallId
|
|
744
|
+
}
|
|
745
|
+
);
|
|
746
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
747
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
748
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
749
|
+
);
|
|
750
|
+
if (toolInvocationPart) {
|
|
751
|
+
toolInvocationPart.toolInvocation = {
|
|
752
|
+
...toolInvocationPart.toolInvocation,
|
|
753
|
+
state: "result",
|
|
754
|
+
result
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
758
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
759
|
+
);
|
|
760
|
+
if (toolInvocation) {
|
|
761
|
+
toolInvocation.state = "result";
|
|
762
|
+
toolInvocation.result = result;
|
|
763
|
+
}
|
|
764
|
+
const writer = writable.getWriter();
|
|
765
|
+
try {
|
|
766
|
+
await writer.write(
|
|
767
|
+
new TextEncoder().encode(
|
|
768
|
+
"a:" + JSON.stringify({
|
|
769
|
+
toolCallId: toolCall2.toolCallId,
|
|
770
|
+
result
|
|
771
|
+
}) + "\n"
|
|
772
|
+
)
|
|
773
|
+
);
|
|
774
|
+
} finally {
|
|
775
|
+
writer.releaseLock();
|
|
776
|
+
}
|
|
777
|
+
const originalMessages = processedParams.messages;
|
|
778
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
779
|
+
this.processStreamResponse(
|
|
780
|
+
{
|
|
781
|
+
...processedParams,
|
|
782
|
+
messages: [...messageArray, ...messages, lastMessage]
|
|
783
|
+
},
|
|
784
|
+
writable
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
} else {
|
|
789
|
+
setTimeout(() => {
|
|
790
|
+
if (!writable.locked) {
|
|
791
|
+
writable.close();
|
|
792
|
+
}
|
|
793
|
+
}, 0);
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
lastMessage: void 0,
|
|
797
|
+
streamProtocol
|
|
798
|
+
});
|
|
799
|
+
} catch (error) {
|
|
800
|
+
console.error("Error processing stream response:", error);
|
|
801
|
+
}
|
|
802
|
+
return response;
|
|
353
803
|
}
|
|
354
804
|
/**
|
|
355
805
|
* Streams a response from the agent
|
|
356
806
|
* @param params - Stream parameters including prompt
|
|
357
|
-
* @returns Promise containing the enhanced Response object with processDataStream
|
|
807
|
+
* @returns Promise containing the enhanced Response object with processDataStream and processTextStream methods
|
|
358
808
|
*/
|
|
359
809
|
async stream(params) {
|
|
360
810
|
const processedParams = {
|
|
361
811
|
...params,
|
|
362
812
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
363
813
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
364
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
814
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
815
|
+
clientTools: processClientTools(params.clientTools)
|
|
365
816
|
};
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
817
|
+
const { readable, writable } = new TransformStream();
|
|
818
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
819
|
+
const streamResponse = new Response(readable, {
|
|
820
|
+
status: response.status,
|
|
821
|
+
statusText: response.statusText,
|
|
822
|
+
headers: response.headers
|
|
370
823
|
});
|
|
371
|
-
|
|
372
|
-
throw new Error("No response body");
|
|
373
|
-
}
|
|
374
|
-
response.processDataStream = async (options = {}) => {
|
|
824
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
375
825
|
await processDataStream({
|
|
376
|
-
stream:
|
|
826
|
+
stream: streamResponse.body,
|
|
377
827
|
...options
|
|
378
828
|
});
|
|
379
829
|
};
|
|
380
|
-
|
|
830
|
+
streamResponse.processTextStream = async (options) => {
|
|
831
|
+
await processTextStream({
|
|
832
|
+
stream: streamResponse.body,
|
|
833
|
+
onTextPart: options?.onTextPart ?? (() => {
|
|
834
|
+
})
|
|
835
|
+
});
|
|
836
|
+
};
|
|
837
|
+
return streamResponse;
|
|
381
838
|
}
|
|
382
839
|
/**
|
|
383
840
|
* Gets details about a specific tool available to the agent
|
|
@@ -521,6 +978,21 @@ var MemoryThread = class extends BaseResource {
|
|
|
521
978
|
});
|
|
522
979
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
523
980
|
}
|
|
981
|
+
/**
|
|
982
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
983
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
984
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
985
|
+
*/
|
|
986
|
+
getMessagesPaginated({
|
|
987
|
+
selectBy,
|
|
988
|
+
...rest
|
|
989
|
+
}) {
|
|
990
|
+
const query = new URLSearchParams({
|
|
991
|
+
...rest,
|
|
992
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
993
|
+
});
|
|
994
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
995
|
+
}
|
|
524
996
|
};
|
|
525
997
|
|
|
526
998
|
// src/resources/vector.ts
|
|
@@ -771,7 +1243,7 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
771
1243
|
};
|
|
772
1244
|
|
|
773
1245
|
// src/resources/tool.ts
|
|
774
|
-
var
|
|
1246
|
+
var Tool2 = class extends BaseResource {
|
|
775
1247
|
constructor(options, toolId) {
|
|
776
1248
|
super(options);
|
|
777
1249
|
this.toolId = toolId;
|
|
@@ -876,10 +1348,10 @@ var Workflow = class extends BaseResource {
|
|
|
876
1348
|
if (params?.toDate) {
|
|
877
1349
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
878
1350
|
}
|
|
879
|
-
if (params?.limit) {
|
|
1351
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
880
1352
|
searchParams.set("limit", String(params.limit));
|
|
881
1353
|
}
|
|
882
|
-
if (params?.offset) {
|
|
1354
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
883
1355
|
searchParams.set("offset", String(params.offset));
|
|
884
1356
|
}
|
|
885
1357
|
if (params?.resourceId) {
|
|
@@ -891,6 +1363,43 @@ var Workflow = class extends BaseResource {
|
|
|
891
1363
|
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
892
1364
|
}
|
|
893
1365
|
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Retrieves a specific workflow run by its ID
|
|
1368
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1369
|
+
* @returns Promise containing the workflow run details
|
|
1370
|
+
*/
|
|
1371
|
+
runById(runId) {
|
|
1372
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1376
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1377
|
+
* @returns Promise containing the workflow run execution result
|
|
1378
|
+
*/
|
|
1379
|
+
runExecutionResult(runId) {
|
|
1380
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Cancels a specific workflow run by its ID
|
|
1384
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1385
|
+
* @returns Promise containing a success message
|
|
1386
|
+
*/
|
|
1387
|
+
cancelRun(runId) {
|
|
1388
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1389
|
+
method: "POST"
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Sends an event to a specific workflow run by its ID
|
|
1394
|
+
* @param params - Object containing the runId, event and data
|
|
1395
|
+
* @returns Promise containing a success message
|
|
1396
|
+
*/
|
|
1397
|
+
sendRunEvent(params) {
|
|
1398
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1399
|
+
method: "POST",
|
|
1400
|
+
body: { event: params.event, data: params.data }
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
894
1403
|
/**
|
|
895
1404
|
* Creates a new workflow run
|
|
896
1405
|
* @param params - Optional object containing the optional runId
|
|
@@ -905,6 +1414,14 @@ var Workflow = class extends BaseResource {
|
|
|
905
1414
|
method: "POST"
|
|
906
1415
|
});
|
|
907
1416
|
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Creates a new workflow run (alias for createRun)
|
|
1419
|
+
* @param params - Optional object containing the optional runId
|
|
1420
|
+
* @returns Promise containing the runId of the created run
|
|
1421
|
+
*/
|
|
1422
|
+
createRunAsync(params) {
|
|
1423
|
+
return this.createRun(params);
|
|
1424
|
+
}
|
|
908
1425
|
/**
|
|
909
1426
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
910
1427
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
@@ -956,16 +1473,16 @@ var Workflow = class extends BaseResource {
|
|
|
956
1473
|
});
|
|
957
1474
|
}
|
|
958
1475
|
/**
|
|
959
|
-
* Starts a
|
|
1476
|
+
* Starts a workflow run and returns a stream
|
|
960
1477
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
961
|
-
* @returns Promise containing the
|
|
1478
|
+
* @returns Promise containing the workflow execution results
|
|
962
1479
|
*/
|
|
963
1480
|
async stream(params) {
|
|
964
1481
|
const searchParams = new URLSearchParams();
|
|
965
1482
|
if (!!params?.runId) {
|
|
966
1483
|
searchParams.set("runId", params.runId);
|
|
967
1484
|
}
|
|
968
|
-
const runtimeContext =
|
|
1485
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
969
1486
|
const response = await this.request(
|
|
970
1487
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
971
1488
|
{
|
|
@@ -980,6 +1497,7 @@ var Workflow = class extends BaseResource {
|
|
|
980
1497
|
if (!response.body) {
|
|
981
1498
|
throw new Error("Response body is null");
|
|
982
1499
|
}
|
|
1500
|
+
let failedChunk = void 0;
|
|
983
1501
|
const transformStream = new TransformStream({
|
|
984
1502
|
start() {
|
|
985
1503
|
},
|
|
@@ -989,10 +1507,13 @@ var Workflow = class extends BaseResource {
|
|
|
989
1507
|
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
990
1508
|
for (const chunk2 of chunks) {
|
|
991
1509
|
if (chunk2) {
|
|
1510
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
992
1511
|
try {
|
|
993
|
-
const parsedChunk = JSON.parse(
|
|
1512
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
994
1513
|
controller.enqueue(parsedChunk);
|
|
995
|
-
|
|
1514
|
+
failedChunk = void 0;
|
|
1515
|
+
} catch (error) {
|
|
1516
|
+
failedChunk = newChunk;
|
|
996
1517
|
}
|
|
997
1518
|
}
|
|
998
1519
|
}
|
|
@@ -1174,6 +1695,192 @@ var MCPTool = class extends BaseResource {
|
|
|
1174
1695
|
}
|
|
1175
1696
|
};
|
|
1176
1697
|
|
|
1698
|
+
// src/resources/network-memory-thread.ts
|
|
1699
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1700
|
+
constructor(options, threadId, networkId) {
|
|
1701
|
+
super(options);
|
|
1702
|
+
this.threadId = threadId;
|
|
1703
|
+
this.networkId = networkId;
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Retrieves the memory thread details
|
|
1707
|
+
* @returns Promise containing thread details including title and metadata
|
|
1708
|
+
*/
|
|
1709
|
+
get() {
|
|
1710
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Updates the memory thread properties
|
|
1714
|
+
* @param params - Update parameters including title and metadata
|
|
1715
|
+
* @returns Promise containing updated thread details
|
|
1716
|
+
*/
|
|
1717
|
+
update(params) {
|
|
1718
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1719
|
+
method: "PATCH",
|
|
1720
|
+
body: params
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Deletes the memory thread
|
|
1725
|
+
* @returns Promise containing deletion result
|
|
1726
|
+
*/
|
|
1727
|
+
delete() {
|
|
1728
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1729
|
+
method: "DELETE"
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* Retrieves messages associated with the thread
|
|
1734
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1735
|
+
* @returns Promise containing thread messages and UI messages
|
|
1736
|
+
*/
|
|
1737
|
+
getMessages(params) {
|
|
1738
|
+
const query = new URLSearchParams({
|
|
1739
|
+
networkId: this.networkId,
|
|
1740
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1741
|
+
});
|
|
1742
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
// src/resources/vNextNetwork.ts
|
|
1747
|
+
var RECORD_SEPARATOR3 = "";
|
|
1748
|
+
var VNextNetwork = class extends BaseResource {
|
|
1749
|
+
constructor(options, networkId) {
|
|
1750
|
+
super(options);
|
|
1751
|
+
this.networkId = networkId;
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Retrieves details about the network
|
|
1755
|
+
* @returns Promise containing vNext network details
|
|
1756
|
+
*/
|
|
1757
|
+
details() {
|
|
1758
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Generates a response from the v-next network
|
|
1762
|
+
* @param params - Generation parameters including message
|
|
1763
|
+
* @returns Promise containing the generated response
|
|
1764
|
+
*/
|
|
1765
|
+
generate(params) {
|
|
1766
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1767
|
+
method: "POST",
|
|
1768
|
+
body: {
|
|
1769
|
+
...params,
|
|
1770
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1771
|
+
}
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1776
|
+
* @param params - Generation parameters including message
|
|
1777
|
+
* @returns Promise containing the generated response
|
|
1778
|
+
*/
|
|
1779
|
+
loop(params) {
|
|
1780
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1781
|
+
method: "POST",
|
|
1782
|
+
body: {
|
|
1783
|
+
...params,
|
|
1784
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
async *streamProcessor(stream) {
|
|
1789
|
+
const reader = stream.getReader();
|
|
1790
|
+
let doneReading = false;
|
|
1791
|
+
let buffer = "";
|
|
1792
|
+
try {
|
|
1793
|
+
while (!doneReading) {
|
|
1794
|
+
const { done, value } = await reader.read();
|
|
1795
|
+
doneReading = done;
|
|
1796
|
+
if (done && !value) continue;
|
|
1797
|
+
try {
|
|
1798
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1799
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1800
|
+
buffer = chunks.pop() || "";
|
|
1801
|
+
for (const chunk of chunks) {
|
|
1802
|
+
if (chunk) {
|
|
1803
|
+
if (typeof chunk === "string") {
|
|
1804
|
+
try {
|
|
1805
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1806
|
+
yield parsedChunk;
|
|
1807
|
+
} catch {
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
} catch {
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (buffer) {
|
|
1816
|
+
try {
|
|
1817
|
+
yield JSON.parse(buffer);
|
|
1818
|
+
} catch {
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
} finally {
|
|
1822
|
+
reader.cancel().catch(() => {
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Streams a response from the v-next network
|
|
1828
|
+
* @param params - Stream parameters including message
|
|
1829
|
+
* @returns Promise containing the results
|
|
1830
|
+
*/
|
|
1831
|
+
async stream(params, onRecord) {
|
|
1832
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1833
|
+
method: "POST",
|
|
1834
|
+
body: {
|
|
1835
|
+
...params,
|
|
1836
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1837
|
+
},
|
|
1838
|
+
stream: true
|
|
1839
|
+
});
|
|
1840
|
+
if (!response.ok) {
|
|
1841
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1842
|
+
}
|
|
1843
|
+
if (!response.body) {
|
|
1844
|
+
throw new Error("Response body is null");
|
|
1845
|
+
}
|
|
1846
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1847
|
+
if (typeof record === "string") {
|
|
1848
|
+
onRecord(JSON.parse(record));
|
|
1849
|
+
} else {
|
|
1850
|
+
onRecord(record);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Streams a response from the v-next network loop
|
|
1856
|
+
* @param params - Stream parameters including message
|
|
1857
|
+
* @returns Promise containing the results
|
|
1858
|
+
*/
|
|
1859
|
+
async loopStream(params, onRecord) {
|
|
1860
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1861
|
+
method: "POST",
|
|
1862
|
+
body: {
|
|
1863
|
+
...params,
|
|
1864
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1865
|
+
},
|
|
1866
|
+
stream: true
|
|
1867
|
+
});
|
|
1868
|
+
if (!response.ok) {
|
|
1869
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
1870
|
+
}
|
|
1871
|
+
if (!response.body) {
|
|
1872
|
+
throw new Error("Response body is null");
|
|
1873
|
+
}
|
|
1874
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1875
|
+
if (typeof record === "string") {
|
|
1876
|
+
onRecord(JSON.parse(record));
|
|
1877
|
+
} else {
|
|
1878
|
+
onRecord(record);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1177
1884
|
// src/client.ts
|
|
1178
1885
|
var MastraClient = class extends BaseResource {
|
|
1179
1886
|
constructor(options) {
|
|
@@ -1251,6 +1958,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1251
1958
|
getMemoryStatus(agentId) {
|
|
1252
1959
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1253
1960
|
}
|
|
1961
|
+
/**
|
|
1962
|
+
* Retrieves memory threads for a resource
|
|
1963
|
+
* @param params - Parameters containing the resource ID
|
|
1964
|
+
* @returns Promise containing array of memory threads
|
|
1965
|
+
*/
|
|
1966
|
+
getNetworkMemoryThreads(params) {
|
|
1967
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1968
|
+
}
|
|
1969
|
+
/**
|
|
1970
|
+
* Creates a new memory thread
|
|
1971
|
+
* @param params - Parameters for creating the memory thread
|
|
1972
|
+
* @returns Promise containing the created memory thread
|
|
1973
|
+
*/
|
|
1974
|
+
createNetworkMemoryThread(params) {
|
|
1975
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Gets a memory thread instance by ID
|
|
1979
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
1980
|
+
* @returns MemoryThread instance
|
|
1981
|
+
*/
|
|
1982
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
1983
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Saves messages to memory
|
|
1987
|
+
* @param params - Parameters containing messages to save
|
|
1988
|
+
* @returns Promise containing the saved messages
|
|
1989
|
+
*/
|
|
1990
|
+
saveNetworkMessageToMemory(params) {
|
|
1991
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
1992
|
+
method: "POST",
|
|
1993
|
+
body: params
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* Gets the status of the memory system
|
|
1998
|
+
* @returns Promise containing memory system status
|
|
1999
|
+
*/
|
|
2000
|
+
getNetworkMemoryStatus(networkId) {
|
|
2001
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2002
|
+
}
|
|
1254
2003
|
/**
|
|
1255
2004
|
* Retrieves all available tools
|
|
1256
2005
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1264,7 +2013,7 @@ var MastraClient = class extends BaseResource {
|
|
|
1264
2013
|
* @returns Tool instance
|
|
1265
2014
|
*/
|
|
1266
2015
|
getTool(toolId) {
|
|
1267
|
-
return new
|
|
2016
|
+
return new Tool2(this.options, toolId);
|
|
1268
2017
|
}
|
|
1269
2018
|
/**
|
|
1270
2019
|
* Retrieves all available legacy workflows
|
|
@@ -1310,7 +2059,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1310
2059
|
* @returns Promise containing array of log messages
|
|
1311
2060
|
*/
|
|
1312
2061
|
getLogs(params) {
|
|
1313
|
-
|
|
2062
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2063
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2064
|
+
const searchParams = new URLSearchParams();
|
|
2065
|
+
if (transportId) {
|
|
2066
|
+
searchParams.set("transportId", transportId);
|
|
2067
|
+
}
|
|
2068
|
+
if (fromDate) {
|
|
2069
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2070
|
+
}
|
|
2071
|
+
if (toDate) {
|
|
2072
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2073
|
+
}
|
|
2074
|
+
if (logLevel) {
|
|
2075
|
+
searchParams.set("logLevel", logLevel);
|
|
2076
|
+
}
|
|
2077
|
+
if (page) {
|
|
2078
|
+
searchParams.set("page", String(page));
|
|
2079
|
+
}
|
|
2080
|
+
if (perPage) {
|
|
2081
|
+
searchParams.set("perPage", String(perPage));
|
|
2082
|
+
}
|
|
2083
|
+
if (_filters) {
|
|
2084
|
+
if (Array.isArray(_filters)) {
|
|
2085
|
+
for (const filter of _filters) {
|
|
2086
|
+
searchParams.append("filters", filter);
|
|
2087
|
+
}
|
|
2088
|
+
} else {
|
|
2089
|
+
searchParams.set("filters", _filters);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
if (searchParams.size) {
|
|
2093
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
2094
|
+
} else {
|
|
2095
|
+
return this.request(`/api/logs`);
|
|
2096
|
+
}
|
|
1314
2097
|
}
|
|
1315
2098
|
/**
|
|
1316
2099
|
* Gets logs for a specific run
|
|
@@ -1318,7 +2101,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1318
2101
|
* @returns Promise containing array of log messages
|
|
1319
2102
|
*/
|
|
1320
2103
|
getLogForRun(params) {
|
|
1321
|
-
|
|
2104
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2105
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2106
|
+
const searchParams = new URLSearchParams();
|
|
2107
|
+
if (runId) {
|
|
2108
|
+
searchParams.set("runId", runId);
|
|
2109
|
+
}
|
|
2110
|
+
if (transportId) {
|
|
2111
|
+
searchParams.set("transportId", transportId);
|
|
2112
|
+
}
|
|
2113
|
+
if (fromDate) {
|
|
2114
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2115
|
+
}
|
|
2116
|
+
if (toDate) {
|
|
2117
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2118
|
+
}
|
|
2119
|
+
if (logLevel) {
|
|
2120
|
+
searchParams.set("logLevel", logLevel);
|
|
2121
|
+
}
|
|
2122
|
+
if (page) {
|
|
2123
|
+
searchParams.set("page", String(page));
|
|
2124
|
+
}
|
|
2125
|
+
if (perPage) {
|
|
2126
|
+
searchParams.set("perPage", String(perPage));
|
|
2127
|
+
}
|
|
2128
|
+
if (_filters) {
|
|
2129
|
+
if (Array.isArray(_filters)) {
|
|
2130
|
+
for (const filter of _filters) {
|
|
2131
|
+
searchParams.append("filters", filter);
|
|
2132
|
+
}
|
|
2133
|
+
} else {
|
|
2134
|
+
searchParams.set("filters", _filters);
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
if (searchParams.size) {
|
|
2138
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
2139
|
+
} else {
|
|
2140
|
+
return this.request(`/api/logs/${runId}`);
|
|
2141
|
+
}
|
|
1322
2142
|
}
|
|
1323
2143
|
/**
|
|
1324
2144
|
* List of all log transports
|
|
@@ -1376,6 +2196,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1376
2196
|
getNetworks() {
|
|
1377
2197
|
return this.request("/api/networks");
|
|
1378
2198
|
}
|
|
2199
|
+
/**
|
|
2200
|
+
* Retrieves all available vNext networks
|
|
2201
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2202
|
+
*/
|
|
2203
|
+
getVNextNetworks() {
|
|
2204
|
+
return this.request("/api/networks/v-next");
|
|
2205
|
+
}
|
|
1379
2206
|
/**
|
|
1380
2207
|
* Gets a network instance by ID
|
|
1381
2208
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1384,6 +2211,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1384
2211
|
getNetwork(networkId) {
|
|
1385
2212
|
return new Network(this.options, networkId);
|
|
1386
2213
|
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Gets a vNext network instance by ID
|
|
2216
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
2217
|
+
* @returns vNext Network instance
|
|
2218
|
+
*/
|
|
2219
|
+
getVNextNetwork(networkId) {
|
|
2220
|
+
return new VNextNetwork(this.options, networkId);
|
|
2221
|
+
}
|
|
1387
2222
|
/**
|
|
1388
2223
|
* Retrieves a list of available MCP servers.
|
|
1389
2224
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -1440,6 +2275,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1440
2275
|
getA2A(agentId) {
|
|
1441
2276
|
return new A2A(this.options, agentId);
|
|
1442
2277
|
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2280
|
+
* @param agentId - ID of the agent.
|
|
2281
|
+
* @param threadId - ID of the thread.
|
|
2282
|
+
* @param resourceId - Optional ID of the resource.
|
|
2283
|
+
* @returns Working memory for the specified thread or resource.
|
|
2284
|
+
*/
|
|
2285
|
+
getWorkingMemory({
|
|
2286
|
+
agentId,
|
|
2287
|
+
threadId,
|
|
2288
|
+
resourceId
|
|
2289
|
+
}) {
|
|
2290
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2294
|
+
* @param agentId - ID of the agent.
|
|
2295
|
+
* @param threadId - ID of the thread.
|
|
2296
|
+
* @param workingMemory - The new working memory content.
|
|
2297
|
+
* @param resourceId - Optional ID of the resource.
|
|
2298
|
+
*/
|
|
2299
|
+
updateWorkingMemory({
|
|
2300
|
+
agentId,
|
|
2301
|
+
threadId,
|
|
2302
|
+
workingMemory,
|
|
2303
|
+
resourceId
|
|
2304
|
+
}) {
|
|
2305
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2306
|
+
method: "POST",
|
|
2307
|
+
body: {
|
|
2308
|
+
workingMemory,
|
|
2309
|
+
resourceId
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
1443
2313
|
};
|
|
1444
2314
|
|
|
1445
2315
|
export { MastraClient };
|