@mastra/client-js 0.0.0-mcp-changeset-20250707162621 → 0.0.0-message-list-update-20250715150321
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 +8 -8
- package/CHANGELOG.md +109 -2
- package/LICENSE.md +11 -42
- package/dist/index.cjs +349 -271
- package/dist/index.d.cts +69 -39
- package/dist/index.d.ts +69 -39
- package/dist/index.js +350 -272
- package/package.json +5 -4
- package/src/client.ts +48 -2
- package/src/example.ts +45 -17
- package/src/resources/agent.ts +291 -254
- package/src/resources/base.ts +1 -0
- package/src/resources/vNextNetwork.ts +22 -5
- package/src/types.ts +9 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { processDataStream, parsePartialJson } 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
6
|
import { isVercelTool } from '@mastra/core/tools';
|
|
7
|
+
import { v4 } from '@lukeed/uuid';
|
|
7
8
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
8
9
|
|
|
9
10
|
// src/adapters/agui.ts
|
|
@@ -252,6 +253,7 @@ var BaseResource = class {
|
|
|
252
253
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
253
254
|
// 'x-mastra-client-type': 'js',
|
|
254
255
|
},
|
|
256
|
+
signal: this.options.abortSignal,
|
|
255
257
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
256
258
|
});
|
|
257
259
|
if (!response.ok) {
|
|
@@ -375,7 +377,11 @@ var Agent = class extends BaseResource {
|
|
|
375
377
|
body: processedParams
|
|
376
378
|
});
|
|
377
379
|
if (response.finishReason === "tool-calls") {
|
|
378
|
-
|
|
380
|
+
const toolCalls = response.toolCalls;
|
|
381
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
382
|
+
return response;
|
|
383
|
+
}
|
|
384
|
+
for (const toolCall of toolCalls) {
|
|
379
385
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
380
386
|
if (clientTool && clientTool.execute) {
|
|
381
387
|
const result = await clientTool.execute(
|
|
@@ -418,7 +424,8 @@ var Agent = class extends BaseResource {
|
|
|
418
424
|
onToolCall,
|
|
419
425
|
onFinish,
|
|
420
426
|
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
421
|
-
lastMessage
|
|
427
|
+
lastMessage,
|
|
428
|
+
streamProtocol
|
|
422
429
|
}) {
|
|
423
430
|
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
424
431
|
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
@@ -426,7 +433,7 @@ var Agent = class extends BaseResource {
|
|
|
426
433
|
return Math.max(max, toolInvocation.step ?? 0);
|
|
427
434
|
}, 0) ?? 0) : 0;
|
|
428
435
|
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
429
|
-
id:
|
|
436
|
+
id: v4(),
|
|
430
437
|
createdAt: getCurrentDate(),
|
|
431
438
|
role: "assistant",
|
|
432
439
|
content: "",
|
|
@@ -471,7 +478,7 @@ var Agent = class extends BaseResource {
|
|
|
471
478
|
// changes. This is why we need to add a revision id to ensure that the message
|
|
472
479
|
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
473
480
|
// forwarded to rendering):
|
|
474
|
-
revisionId:
|
|
481
|
+
revisionId: v4()
|
|
475
482
|
};
|
|
476
483
|
update({
|
|
477
484
|
message: copiedMessage,
|
|
@@ -479,228 +486,213 @@ var Agent = class extends BaseResource {
|
|
|
479
486
|
replaceLastMessage
|
|
480
487
|
});
|
|
481
488
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
text: value
|
|
489
|
-
};
|
|
490
|
-
message.parts.push(currentTextPart);
|
|
491
|
-
} else {
|
|
492
|
-
currentTextPart.text += value;
|
|
489
|
+
if (streamProtocol === "text") {
|
|
490
|
+
await processTextStream({
|
|
491
|
+
stream,
|
|
492
|
+
onTextPart(value) {
|
|
493
|
+
message.content += value;
|
|
494
|
+
execUpdate();
|
|
493
495
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
|
|
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;
|
|
502
510
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
type: "
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const invocation = {
|
|
566
|
-
state: "partial-call",
|
|
567
|
-
step,
|
|
568
|
-
toolCallId: value.toolCallId,
|
|
569
|
-
toolName: value.toolName,
|
|
570
|
-
args: void 0
|
|
571
|
-
};
|
|
572
|
-
message.toolInvocations.push(invocation);
|
|
573
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
|
574
|
-
execUpdate();
|
|
575
|
-
},
|
|
576
|
-
onToolCallDeltaPart(value) {
|
|
577
|
-
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
578
|
-
partialToolCall.text += value.argsTextDelta;
|
|
579
|
-
const { value: partialArgs } = parsePartialJson(partialToolCall.text);
|
|
580
|
-
const invocation = {
|
|
581
|
-
state: "partial-call",
|
|
582
|
-
step: partialToolCall.step,
|
|
583
|
-
toolCallId: value.toolCallId,
|
|
584
|
-
toolName: partialToolCall.toolName,
|
|
585
|
-
args: partialArgs
|
|
586
|
-
};
|
|
587
|
-
message.toolInvocations[partialToolCall.index] = invocation;
|
|
588
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
|
589
|
-
execUpdate();
|
|
590
|
-
},
|
|
591
|
-
async onToolCallPart(value) {
|
|
592
|
-
const invocation = {
|
|
593
|
-
state: "call",
|
|
594
|
-
step,
|
|
595
|
-
...value
|
|
596
|
-
};
|
|
597
|
-
if (partialToolCalls[value.toolCallId] != null) {
|
|
598
|
-
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
599
|
-
} else {
|
|
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) {
|
|
600
573
|
if (message.toolInvocations == null) {
|
|
601
574
|
message.toolInvocations = [];
|
|
602
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
|
+
};
|
|
603
589
|
message.toolInvocations.push(invocation);
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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);
|
|
619
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);
|
|
620
692
|
}
|
|
621
|
-
},
|
|
622
|
-
onToolResultPart(value) {
|
|
623
|
-
const toolInvocations = message.toolInvocations;
|
|
624
|
-
if (toolInvocations == null) {
|
|
625
|
-
throw new Error("tool_result must be preceded by a tool_call");
|
|
626
|
-
}
|
|
627
|
-
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
628
|
-
if (toolInvocationIndex === -1) {
|
|
629
|
-
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
630
|
-
}
|
|
631
|
-
const invocation = {
|
|
632
|
-
...toolInvocations[toolInvocationIndex],
|
|
633
|
-
state: "result",
|
|
634
|
-
...value
|
|
635
|
-
};
|
|
636
|
-
toolInvocations[toolInvocationIndex] = invocation;
|
|
637
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
|
638
|
-
execUpdate();
|
|
639
|
-
},
|
|
640
|
-
onDataPart(value) {
|
|
641
|
-
data.push(...value);
|
|
642
|
-
execUpdate();
|
|
643
|
-
},
|
|
644
|
-
onMessageAnnotationsPart(value) {
|
|
645
|
-
if (messageAnnotations == null) {
|
|
646
|
-
messageAnnotations = [...value];
|
|
647
|
-
} else {
|
|
648
|
-
messageAnnotations.push(...value);
|
|
649
|
-
}
|
|
650
|
-
execUpdate();
|
|
651
|
-
},
|
|
652
|
-
onFinishStepPart(value) {
|
|
653
|
-
step += 1;
|
|
654
|
-
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
655
|
-
currentReasoningPart = void 0;
|
|
656
|
-
currentReasoningTextDetail = void 0;
|
|
657
|
-
},
|
|
658
|
-
onStartStepPart(value) {
|
|
659
|
-
if (!replaceLastMessage) {
|
|
660
|
-
message.id = value.messageId;
|
|
661
|
-
}
|
|
662
|
-
message.parts.push({ type: "step-start" });
|
|
663
|
-
execUpdate();
|
|
664
|
-
},
|
|
665
|
-
onFinishMessagePart(value) {
|
|
666
|
-
finishReason = value.finishReason;
|
|
667
|
-
if (value.usage != null) {
|
|
668
|
-
usage = value.usage;
|
|
669
|
-
}
|
|
670
|
-
},
|
|
671
|
-
onErrorPart(error) {
|
|
672
|
-
throw new Error(error);
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
onFinish?.({ message, finishReason, usage });
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Streams a response from the agent
|
|
679
|
-
* @param params - Stream parameters including prompt
|
|
680
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
681
|
-
*/
|
|
682
|
-
async stream(params) {
|
|
683
|
-
const processedParams = {
|
|
684
|
-
...params,
|
|
685
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
686
|
-
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
687
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
688
|
-
clientTools: processClientTools(params.clientTools)
|
|
689
|
-
};
|
|
690
|
-
const { readable, writable } = new TransformStream();
|
|
691
|
-
const response = await this.processStreamResponse(processedParams, writable);
|
|
692
|
-
const streamResponse = new Response(readable, {
|
|
693
|
-
status: response.status,
|
|
694
|
-
statusText: response.statusText,
|
|
695
|
-
headers: response.headers
|
|
696
|
-
});
|
|
697
|
-
streamResponse.processDataStream = async (options = {}) => {
|
|
698
|
-
await processDataStream({
|
|
699
|
-
stream: streamResponse.body,
|
|
700
|
-
...options
|
|
701
693
|
});
|
|
702
|
-
|
|
703
|
-
|
|
694
|
+
onFinish?.({ message, finishReason, usage });
|
|
695
|
+
}
|
|
704
696
|
}
|
|
705
697
|
/**
|
|
706
698
|
* Processes the stream response and handles tool calls
|
|
@@ -715,6 +707,7 @@ var Agent = class extends BaseResource {
|
|
|
715
707
|
throw new Error("No response body");
|
|
716
708
|
}
|
|
717
709
|
try {
|
|
710
|
+
const streamProtocol = processedParams.output ? "text" : "data";
|
|
718
711
|
let toolCalls = [];
|
|
719
712
|
let messages = [];
|
|
720
713
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
@@ -794,17 +787,55 @@ var Agent = class extends BaseResource {
|
|
|
794
787
|
}
|
|
795
788
|
} else {
|
|
796
789
|
setTimeout(() => {
|
|
797
|
-
writable.
|
|
790
|
+
if (!writable.locked) {
|
|
791
|
+
writable.close();
|
|
792
|
+
}
|
|
798
793
|
}, 0);
|
|
799
794
|
}
|
|
800
795
|
},
|
|
801
|
-
lastMessage: void 0
|
|
796
|
+
lastMessage: void 0,
|
|
797
|
+
streamProtocol
|
|
802
798
|
});
|
|
803
799
|
} catch (error) {
|
|
804
800
|
console.error("Error processing stream response:", error);
|
|
805
801
|
}
|
|
806
802
|
return response;
|
|
807
803
|
}
|
|
804
|
+
/**
|
|
805
|
+
* Streams a response from the agent
|
|
806
|
+
* @param params - Stream parameters including prompt
|
|
807
|
+
* @returns Promise containing the enhanced Response object with processDataStream and processTextStream methods
|
|
808
|
+
*/
|
|
809
|
+
async stream(params) {
|
|
810
|
+
const processedParams = {
|
|
811
|
+
...params,
|
|
812
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
813
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
814
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
815
|
+
clientTools: processClientTools(params.clientTools)
|
|
816
|
+
};
|
|
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
|
|
823
|
+
});
|
|
824
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
825
|
+
await processDataStream({
|
|
826
|
+
stream: streamResponse.body,
|
|
827
|
+
...options
|
|
828
|
+
});
|
|
829
|
+
};
|
|
830
|
+
streamResponse.processTextStream = async (options) => {
|
|
831
|
+
await processTextStream({
|
|
832
|
+
stream: streamResponse.body,
|
|
833
|
+
onTextPart: options?.onTextPart ?? (() => {
|
|
834
|
+
})
|
|
835
|
+
});
|
|
836
|
+
};
|
|
837
|
+
return streamResponse;
|
|
838
|
+
}
|
|
808
839
|
/**
|
|
809
840
|
* Gets details about a specific tool available to the agent
|
|
810
841
|
* @param toolId - ID of the tool to retrieve
|
|
@@ -1637,6 +1668,54 @@ var MCPTool = class extends BaseResource {
|
|
|
1637
1668
|
}
|
|
1638
1669
|
};
|
|
1639
1670
|
|
|
1671
|
+
// src/resources/network-memory-thread.ts
|
|
1672
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1673
|
+
constructor(options, threadId, networkId) {
|
|
1674
|
+
super(options);
|
|
1675
|
+
this.threadId = threadId;
|
|
1676
|
+
this.networkId = networkId;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Retrieves the memory thread details
|
|
1680
|
+
* @returns Promise containing thread details including title and metadata
|
|
1681
|
+
*/
|
|
1682
|
+
get() {
|
|
1683
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Updates the memory thread properties
|
|
1687
|
+
* @param params - Update parameters including title and metadata
|
|
1688
|
+
* @returns Promise containing updated thread details
|
|
1689
|
+
*/
|
|
1690
|
+
update(params) {
|
|
1691
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1692
|
+
method: "PATCH",
|
|
1693
|
+
body: params
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Deletes the memory thread
|
|
1698
|
+
* @returns Promise containing deletion result
|
|
1699
|
+
*/
|
|
1700
|
+
delete() {
|
|
1701
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1702
|
+
method: "DELETE"
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Retrieves messages associated with the thread
|
|
1707
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1708
|
+
* @returns Promise containing thread messages and UI messages
|
|
1709
|
+
*/
|
|
1710
|
+
getMessages(params) {
|
|
1711
|
+
const query = new URLSearchParams({
|
|
1712
|
+
networkId: this.networkId,
|
|
1713
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1714
|
+
});
|
|
1715
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
|
|
1640
1719
|
// src/resources/vNextNetwork.ts
|
|
1641
1720
|
var RECORD_SEPARATOR3 = "";
|
|
1642
1721
|
var VNextNetwork = class extends BaseResource {
|
|
@@ -1659,7 +1738,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1659
1738
|
generate(params) {
|
|
1660
1739
|
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1661
1740
|
method: "POST",
|
|
1662
|
-
body:
|
|
1741
|
+
body: {
|
|
1742
|
+
...params,
|
|
1743
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1744
|
+
}
|
|
1663
1745
|
});
|
|
1664
1746
|
}
|
|
1665
1747
|
/**
|
|
@@ -1670,7 +1752,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1670
1752
|
loop(params) {
|
|
1671
1753
|
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1672
1754
|
method: "POST",
|
|
1673
|
-
body:
|
|
1755
|
+
body: {
|
|
1756
|
+
...params,
|
|
1757
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1758
|
+
}
|
|
1674
1759
|
});
|
|
1675
1760
|
}
|
|
1676
1761
|
async *streamProcessor(stream) {
|
|
@@ -1719,7 +1804,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1719
1804
|
async stream(params, onRecord) {
|
|
1720
1805
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1721
1806
|
method: "POST",
|
|
1722
|
-
body:
|
|
1807
|
+
body: {
|
|
1808
|
+
...params,
|
|
1809
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1810
|
+
},
|
|
1723
1811
|
stream: true
|
|
1724
1812
|
});
|
|
1725
1813
|
if (!response.ok) {
|
|
@@ -1744,7 +1832,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1744
1832
|
async loopStream(params, onRecord) {
|
|
1745
1833
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1746
1834
|
method: "POST",
|
|
1747
|
-
body:
|
|
1835
|
+
body: {
|
|
1836
|
+
...params,
|
|
1837
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1838
|
+
},
|
|
1748
1839
|
stream: true
|
|
1749
1840
|
});
|
|
1750
1841
|
if (!response.ok) {
|
|
@@ -1763,54 +1854,6 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1763
1854
|
}
|
|
1764
1855
|
};
|
|
1765
1856
|
|
|
1766
|
-
// src/resources/network-memory-thread.ts
|
|
1767
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
1768
|
-
constructor(options, threadId, networkId) {
|
|
1769
|
-
super(options);
|
|
1770
|
-
this.threadId = threadId;
|
|
1771
|
-
this.networkId = networkId;
|
|
1772
|
-
}
|
|
1773
|
-
/**
|
|
1774
|
-
* Retrieves the memory thread details
|
|
1775
|
-
* @returns Promise containing thread details including title and metadata
|
|
1776
|
-
*/
|
|
1777
|
-
get() {
|
|
1778
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Updates the memory thread properties
|
|
1782
|
-
* @param params - Update parameters including title and metadata
|
|
1783
|
-
* @returns Promise containing updated thread details
|
|
1784
|
-
*/
|
|
1785
|
-
update(params) {
|
|
1786
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1787
|
-
method: "PATCH",
|
|
1788
|
-
body: params
|
|
1789
|
-
});
|
|
1790
|
-
}
|
|
1791
|
-
/**
|
|
1792
|
-
* Deletes the memory thread
|
|
1793
|
-
* @returns Promise containing deletion result
|
|
1794
|
-
*/
|
|
1795
|
-
delete() {
|
|
1796
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1797
|
-
method: "DELETE"
|
|
1798
|
-
});
|
|
1799
|
-
}
|
|
1800
|
-
/**
|
|
1801
|
-
* Retrieves messages associated with the thread
|
|
1802
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1803
|
-
* @returns Promise containing thread messages and UI messages
|
|
1804
|
-
*/
|
|
1805
|
-
getMessages(params) {
|
|
1806
|
-
const query = new URLSearchParams({
|
|
1807
|
-
networkId: this.networkId,
|
|
1808
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1809
|
-
});
|
|
1810
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1811
|
-
}
|
|
1812
|
-
};
|
|
1813
|
-
|
|
1814
1857
|
// src/client.ts
|
|
1815
1858
|
var MastraClient = class extends BaseResource {
|
|
1816
1859
|
constructor(options) {
|
|
@@ -2205,6 +2248,41 @@ var MastraClient = class extends BaseResource {
|
|
|
2205
2248
|
getA2A(agentId) {
|
|
2206
2249
|
return new A2A(this.options, agentId);
|
|
2207
2250
|
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2253
|
+
* @param agentId - ID of the agent.
|
|
2254
|
+
* @param threadId - ID of the thread.
|
|
2255
|
+
* @param resourceId - Optional ID of the resource.
|
|
2256
|
+
* @returns Working memory for the specified thread or resource.
|
|
2257
|
+
*/
|
|
2258
|
+
getWorkingMemory({
|
|
2259
|
+
agentId,
|
|
2260
|
+
threadId,
|
|
2261
|
+
resourceId
|
|
2262
|
+
}) {
|
|
2263
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2267
|
+
* @param agentId - ID of the agent.
|
|
2268
|
+
* @param threadId - ID of the thread.
|
|
2269
|
+
* @param workingMemory - The new working memory content.
|
|
2270
|
+
* @param resourceId - Optional ID of the resource.
|
|
2271
|
+
*/
|
|
2272
|
+
updateWorkingMemory({
|
|
2273
|
+
agentId,
|
|
2274
|
+
threadId,
|
|
2275
|
+
workingMemory,
|
|
2276
|
+
resourceId
|
|
2277
|
+
}) {
|
|
2278
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2279
|
+
method: "POST",
|
|
2280
|
+
body: {
|
|
2281
|
+
workingMemory,
|
|
2282
|
+
resourceId
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2208
2286
|
};
|
|
2209
2287
|
|
|
2210
2288
|
export { MastraClient };
|