@mastra/client-js 0.10.15-alpha.1 → 0.10.15-alpha.3
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 +37 -0
- package/README.md +1 -0
- package/dist/index.cjs +327 -248
- package/dist/index.d.cts +124 -19
- package/dist/index.d.ts +124 -19
- package/dist/index.js +327 -248
- package/package.json +2 -2
- package/src/client.ts +97 -0
- package/src/index.test.ts +294 -6
- package/src/resources/agent.ts +272 -297
- package/src/resources/base.ts +3 -1
- package/src/resources/memory-thread.ts +18 -0
- package/src/resources/network.ts +4 -3
- package/src/resources/workflow.ts +9 -0
- package/src/types.ts +75 -1
- package/src/utils/process-client-tools.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import {
|
|
3
|
+
import { 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';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
7
7
|
import { v4 } from '@lukeed/uuid';
|
|
8
8
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
9
9
|
|
|
@@ -247,7 +247,7 @@ var BaseResource = class {
|
|
|
247
247
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
248
248
|
...options,
|
|
249
249
|
headers: {
|
|
250
|
-
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
250
|
+
...options.body && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
251
251
|
...headers,
|
|
252
252
|
...options.headers
|
|
253
253
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
@@ -372,10 +372,13 @@ var Agent = class extends BaseResource {
|
|
|
372
372
|
clientTools: processClientTools(params.clientTools)
|
|
373
373
|
};
|
|
374
374
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
375
|
-
const response = await this.request(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
375
|
+
const response = await this.request(
|
|
376
|
+
`/api/agents/${this.agentId}/generate`,
|
|
377
|
+
{
|
|
378
|
+
method: "POST",
|
|
379
|
+
body: processedParams
|
|
380
|
+
}
|
|
381
|
+
);
|
|
379
382
|
if (response.finishReason === "tool-calls") {
|
|
380
383
|
const toolCalls = response.toolCalls;
|
|
381
384
|
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
@@ -424,8 +427,7 @@ var Agent = class extends BaseResource {
|
|
|
424
427
|
onToolCall,
|
|
425
428
|
onFinish,
|
|
426
429
|
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
427
|
-
lastMessage
|
|
428
|
-
streamProtocol
|
|
430
|
+
lastMessage
|
|
429
431
|
}) {
|
|
430
432
|
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
431
433
|
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
@@ -486,213 +488,228 @@ var Agent = class extends BaseResource {
|
|
|
486
488
|
replaceLastMessage
|
|
487
489
|
});
|
|
488
490
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
491
|
+
await processDataStream({
|
|
492
|
+
stream,
|
|
493
|
+
onTextPart(value) {
|
|
494
|
+
if (currentTextPart == null) {
|
|
495
|
+
currentTextPart = {
|
|
496
|
+
type: "text",
|
|
497
|
+
text: value
|
|
498
|
+
};
|
|
499
|
+
message.parts.push(currentTextPart);
|
|
500
|
+
} else {
|
|
501
|
+
currentTextPart.text += value;
|
|
495
502
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
if (
|
|
503
|
-
|
|
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);
|
|
503
|
+
message.content += value;
|
|
504
|
+
execUpdate();
|
|
505
|
+
},
|
|
506
|
+
onReasoningPart(value) {
|
|
507
|
+
if (currentReasoningTextDetail == null) {
|
|
508
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
509
|
+
if (currentReasoningPart != null) {
|
|
510
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
549
511
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
512
|
+
} else {
|
|
513
|
+
currentReasoningTextDetail.text += value;
|
|
514
|
+
}
|
|
515
|
+
if (currentReasoningPart == null) {
|
|
516
|
+
currentReasoningPart = {
|
|
517
|
+
type: "reasoning",
|
|
518
|
+
reasoning: value,
|
|
519
|
+
details: [currentReasoningTextDetail]
|
|
520
|
+
};
|
|
521
|
+
message.parts.push(currentReasoningPart);
|
|
522
|
+
} else {
|
|
523
|
+
currentReasoningPart.reasoning += value;
|
|
524
|
+
}
|
|
525
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
526
|
+
execUpdate();
|
|
527
|
+
},
|
|
528
|
+
onReasoningSignaturePart(value) {
|
|
529
|
+
if (currentReasoningTextDetail != null) {
|
|
530
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
onRedactedReasoningPart(value) {
|
|
534
|
+
if (currentReasoningPart == null) {
|
|
535
|
+
currentReasoningPart = {
|
|
536
|
+
type: "reasoning",
|
|
537
|
+
reasoning: "",
|
|
538
|
+
details: []
|
|
539
|
+
};
|
|
540
|
+
message.parts.push(currentReasoningPart);
|
|
541
|
+
}
|
|
542
|
+
currentReasoningPart.details.push({
|
|
543
|
+
type: "redacted",
|
|
544
|
+
data: value.data
|
|
545
|
+
});
|
|
546
|
+
currentReasoningTextDetail = void 0;
|
|
547
|
+
execUpdate();
|
|
548
|
+
},
|
|
549
|
+
onFilePart(value) {
|
|
550
|
+
message.parts.push({
|
|
551
|
+
type: "file",
|
|
552
|
+
mimeType: value.mimeType,
|
|
553
|
+
data: value.data
|
|
554
|
+
});
|
|
555
|
+
execUpdate();
|
|
556
|
+
},
|
|
557
|
+
onSourcePart(value) {
|
|
558
|
+
message.parts.push({
|
|
559
|
+
type: "source",
|
|
560
|
+
source: value
|
|
561
|
+
});
|
|
562
|
+
execUpdate();
|
|
563
|
+
},
|
|
564
|
+
onToolCallStreamingStartPart(value) {
|
|
565
|
+
if (message.toolInvocations == null) {
|
|
566
|
+
message.toolInvocations = [];
|
|
567
|
+
}
|
|
568
|
+
partialToolCalls[value.toolCallId] = {
|
|
569
|
+
text: "",
|
|
570
|
+
step,
|
|
571
|
+
toolName: value.toolName,
|
|
572
|
+
index: message.toolInvocations.length
|
|
573
|
+
};
|
|
574
|
+
const invocation = {
|
|
575
|
+
state: "partial-call",
|
|
576
|
+
step,
|
|
577
|
+
toolCallId: value.toolCallId,
|
|
578
|
+
toolName: value.toolName,
|
|
579
|
+
args: void 0
|
|
580
|
+
};
|
|
581
|
+
message.toolInvocations.push(invocation);
|
|
582
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
583
|
+
execUpdate();
|
|
584
|
+
},
|
|
585
|
+
onToolCallDeltaPart(value) {
|
|
586
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
587
|
+
partialToolCall.text += value.argsTextDelta;
|
|
588
|
+
const { value: partialArgs } = parsePartialJson(partialToolCall.text);
|
|
589
|
+
const invocation = {
|
|
590
|
+
state: "partial-call",
|
|
591
|
+
step: partialToolCall.step,
|
|
592
|
+
toolCallId: value.toolCallId,
|
|
593
|
+
toolName: partialToolCall.toolName,
|
|
594
|
+
args: partialArgs
|
|
595
|
+
};
|
|
596
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
597
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
598
|
+
execUpdate();
|
|
599
|
+
},
|
|
600
|
+
async onToolCallPart(value) {
|
|
601
|
+
const invocation = {
|
|
602
|
+
state: "call",
|
|
603
|
+
step,
|
|
604
|
+
...value
|
|
605
|
+
};
|
|
606
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
607
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
608
|
+
} else {
|
|
573
609
|
if (message.toolInvocations == null) {
|
|
574
610
|
message.toolInvocations = [];
|
|
575
611
|
}
|
|
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
612
|
message.toolInvocations.push(invocation);
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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;
|
|
613
|
+
}
|
|
614
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
615
|
+
execUpdate();
|
|
616
|
+
if (onToolCall) {
|
|
617
|
+
const result = await onToolCall({ toolCall: value });
|
|
618
|
+
if (result != null) {
|
|
619
|
+
const invocation2 = {
|
|
620
|
+
state: "result",
|
|
621
|
+
step,
|
|
622
|
+
...value,
|
|
623
|
+
result
|
|
624
|
+
};
|
|
625
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
626
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
627
|
+
execUpdate();
|
|
688
628
|
}
|
|
689
|
-
},
|
|
690
|
-
onErrorPart(error) {
|
|
691
|
-
throw new Error(error);
|
|
692
629
|
}
|
|
630
|
+
},
|
|
631
|
+
onToolResultPart(value) {
|
|
632
|
+
const toolInvocations = message.toolInvocations;
|
|
633
|
+
if (toolInvocations == null) {
|
|
634
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
635
|
+
}
|
|
636
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
637
|
+
if (toolInvocationIndex === -1) {
|
|
638
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
639
|
+
}
|
|
640
|
+
const invocation = {
|
|
641
|
+
...toolInvocations[toolInvocationIndex],
|
|
642
|
+
state: "result",
|
|
643
|
+
...value
|
|
644
|
+
};
|
|
645
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
646
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
647
|
+
execUpdate();
|
|
648
|
+
},
|
|
649
|
+
onDataPart(value) {
|
|
650
|
+
data.push(...value);
|
|
651
|
+
execUpdate();
|
|
652
|
+
},
|
|
653
|
+
onMessageAnnotationsPart(value) {
|
|
654
|
+
if (messageAnnotations == null) {
|
|
655
|
+
messageAnnotations = [...value];
|
|
656
|
+
} else {
|
|
657
|
+
messageAnnotations.push(...value);
|
|
658
|
+
}
|
|
659
|
+
execUpdate();
|
|
660
|
+
},
|
|
661
|
+
onFinishStepPart(value) {
|
|
662
|
+
step += 1;
|
|
663
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
664
|
+
currentReasoningPart = void 0;
|
|
665
|
+
currentReasoningTextDetail = void 0;
|
|
666
|
+
},
|
|
667
|
+
onStartStepPart(value) {
|
|
668
|
+
if (!replaceLastMessage) {
|
|
669
|
+
message.id = value.messageId;
|
|
670
|
+
}
|
|
671
|
+
message.parts.push({ type: "step-start" });
|
|
672
|
+
execUpdate();
|
|
673
|
+
},
|
|
674
|
+
onFinishMessagePart(value) {
|
|
675
|
+
finishReason = value.finishReason;
|
|
676
|
+
if (value.usage != null) {
|
|
677
|
+
usage = value.usage;
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
onErrorPart(error) {
|
|
681
|
+
throw new Error(error);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
onFinish?.({ message, finishReason, usage });
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Streams a response from the agent
|
|
688
|
+
* @param params - Stream parameters including prompt
|
|
689
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
690
|
+
*/
|
|
691
|
+
async stream(params) {
|
|
692
|
+
const processedParams = {
|
|
693
|
+
...params,
|
|
694
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
695
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
696
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
697
|
+
clientTools: processClientTools(params.clientTools)
|
|
698
|
+
};
|
|
699
|
+
const { readable, writable } = new TransformStream();
|
|
700
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
701
|
+
const streamResponse = new Response(readable, {
|
|
702
|
+
status: response.status,
|
|
703
|
+
statusText: response.statusText,
|
|
704
|
+
headers: response.headers
|
|
705
|
+
});
|
|
706
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
707
|
+
await processDataStream({
|
|
708
|
+
stream: streamResponse.body,
|
|
709
|
+
...options
|
|
693
710
|
});
|
|
694
|
-
|
|
695
|
-
|
|
711
|
+
};
|
|
712
|
+
return streamResponse;
|
|
696
713
|
}
|
|
697
714
|
/**
|
|
698
715
|
* Processes the stream response and handles tool calls
|
|
@@ -707,7 +724,6 @@ var Agent = class extends BaseResource {
|
|
|
707
724
|
throw new Error("No response body");
|
|
708
725
|
}
|
|
709
726
|
try {
|
|
710
|
-
const streamProtocol = processedParams.output ? "text" : "data";
|
|
711
727
|
let toolCalls = [];
|
|
712
728
|
let messages = [];
|
|
713
729
|
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
@@ -787,55 +803,17 @@ var Agent = class extends BaseResource {
|
|
|
787
803
|
}
|
|
788
804
|
} else {
|
|
789
805
|
setTimeout(() => {
|
|
790
|
-
|
|
791
|
-
writable.close();
|
|
792
|
-
}
|
|
806
|
+
writable.close();
|
|
793
807
|
}, 0);
|
|
794
808
|
}
|
|
795
809
|
},
|
|
796
|
-
lastMessage: void 0
|
|
797
|
-
streamProtocol
|
|
810
|
+
lastMessage: void 0
|
|
798
811
|
});
|
|
799
812
|
} catch (error) {
|
|
800
813
|
console.error("Error processing stream response:", error);
|
|
801
814
|
}
|
|
802
815
|
return response;
|
|
803
816
|
}
|
|
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
|
-
}
|
|
839
817
|
/**
|
|
840
818
|
* Gets details about a specific tool available to the agent
|
|
841
819
|
* @param toolId - ID of the tool to retrieve
|
|
@@ -978,6 +956,21 @@ var MemoryThread = class extends BaseResource {
|
|
|
978
956
|
});
|
|
979
957
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
980
958
|
}
|
|
959
|
+
/**
|
|
960
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
961
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
962
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
963
|
+
*/
|
|
964
|
+
getMessagesPaginated({
|
|
965
|
+
selectBy,
|
|
966
|
+
...rest
|
|
967
|
+
}) {
|
|
968
|
+
const query = new URLSearchParams({
|
|
969
|
+
...rest,
|
|
970
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
971
|
+
});
|
|
972
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
973
|
+
}
|
|
981
974
|
};
|
|
982
975
|
|
|
983
976
|
// src/resources/vector.ts
|
|
@@ -1399,6 +1392,14 @@ var Workflow = class extends BaseResource {
|
|
|
1399
1392
|
method: "POST"
|
|
1400
1393
|
});
|
|
1401
1394
|
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Creates a new workflow run (alias for createRun)
|
|
1397
|
+
* @param params - Optional object containing the optional runId
|
|
1398
|
+
* @returns Promise containing the runId of the created run
|
|
1399
|
+
*/
|
|
1400
|
+
createRunAsync(params) {
|
|
1401
|
+
return this.createRun(params);
|
|
1402
|
+
}
|
|
1402
1403
|
/**
|
|
1403
1404
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1404
1405
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
@@ -2287,6 +2288,84 @@ var MastraClient = class extends BaseResource {
|
|
|
2287
2288
|
}
|
|
2288
2289
|
});
|
|
2289
2290
|
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Retrieves all available scorers
|
|
2293
|
+
* @returns Promise containing list of available scorers
|
|
2294
|
+
*/
|
|
2295
|
+
getScorers() {
|
|
2296
|
+
return this.request("/api/scores/scorers");
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Retrieves a scorer by ID
|
|
2300
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2301
|
+
* @returns Promise containing the scorer
|
|
2302
|
+
*/
|
|
2303
|
+
getScorer(scorerId) {
|
|
2304
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2305
|
+
}
|
|
2306
|
+
getScoresByScorerId(params) {
|
|
2307
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2308
|
+
const searchParams = new URLSearchParams();
|
|
2309
|
+
if (entityId) {
|
|
2310
|
+
searchParams.set("entityId", entityId);
|
|
2311
|
+
}
|
|
2312
|
+
if (entityType) {
|
|
2313
|
+
searchParams.set("entityType", entityType);
|
|
2314
|
+
}
|
|
2315
|
+
if (page !== void 0) {
|
|
2316
|
+
searchParams.set("page", String(page));
|
|
2317
|
+
}
|
|
2318
|
+
if (perPage !== void 0) {
|
|
2319
|
+
searchParams.set("perPage", String(perPage));
|
|
2320
|
+
}
|
|
2321
|
+
const queryString = searchParams.toString();
|
|
2322
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Retrieves scores by run ID
|
|
2326
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2327
|
+
* @returns Promise containing scores and pagination info
|
|
2328
|
+
*/
|
|
2329
|
+
getScoresByRunId(params) {
|
|
2330
|
+
const { runId, page, perPage } = params;
|
|
2331
|
+
const searchParams = new URLSearchParams();
|
|
2332
|
+
if (page !== void 0) {
|
|
2333
|
+
searchParams.set("page", String(page));
|
|
2334
|
+
}
|
|
2335
|
+
if (perPage !== void 0) {
|
|
2336
|
+
searchParams.set("perPage", String(perPage));
|
|
2337
|
+
}
|
|
2338
|
+
const queryString = searchParams.toString();
|
|
2339
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* Retrieves scores by entity ID and type
|
|
2343
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2344
|
+
* @returns Promise containing scores and pagination info
|
|
2345
|
+
*/
|
|
2346
|
+
getScoresByEntityId(params) {
|
|
2347
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2348
|
+
const searchParams = new URLSearchParams();
|
|
2349
|
+
if (page !== void 0) {
|
|
2350
|
+
searchParams.set("page", String(page));
|
|
2351
|
+
}
|
|
2352
|
+
if (perPage !== void 0) {
|
|
2353
|
+
searchParams.set("perPage", String(perPage));
|
|
2354
|
+
}
|
|
2355
|
+
const queryString = searchParams.toString();
|
|
2356
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Saves a score
|
|
2360
|
+
* @param params - Parameters containing the score data to save
|
|
2361
|
+
* @returns Promise containing the saved score
|
|
2362
|
+
*/
|
|
2363
|
+
saveScore(params) {
|
|
2364
|
+
return this.request("/api/scores", {
|
|
2365
|
+
method: "POST",
|
|
2366
|
+
body: params
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2290
2369
|
};
|
|
2291
2370
|
|
|
2292
2371
|
export { MastraClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.10.15-alpha.
|
|
3
|
+
"version": "0.10.15-alpha.3",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"rxjs": "7.8.1",
|
|
35
35
|
"zod": "^3.25.67",
|
|
36
36
|
"zod-to-json-schema": "^3.24.5",
|
|
37
|
-
"@mastra/core": "0.11.0-alpha.
|
|
37
|
+
"@mastra/core": "0.11.0-alpha.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"zod": "^3.0.0"
|