@mastra/client-js 0.0.0-ai-v5-20250718021026 → 0.0.0-ai-v5-20250729181825

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/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@ var rxjs = require('rxjs');
5
5
  var uiUtils = require('@ai-sdk/ui-utils');
6
6
  var zod = require('zod');
7
7
  var originalZodToJsonSchema = require('zod-to-json-schema');
8
- var tools = require('@mastra/core/tools');
8
+ var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
9
9
  var uuid = require('@lukeed/uuid');
10
10
  var runtimeContext = require('@mastra/core/runtime-context');
11
11
 
@@ -210,7 +210,7 @@ function processClientTools(clientTools) {
210
210
  }
211
211
  return Object.fromEntries(
212
212
  Object.entries(clientTools).map(([key, value]) => {
213
- if (tools.isVercelTool(value)) {
213
+ if (isVercelTool.isVercelTool(value)) {
214
214
  return [
215
215
  key,
216
216
  {
@@ -253,7 +253,7 @@ var BaseResource = class {
253
253
  const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
254
254
  ...options,
255
255
  headers: {
256
- ...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
256
+ ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
257
257
  ...headers,
258
258
  ...options.headers
259
259
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
@@ -378,10 +378,13 @@ var Agent = class extends BaseResource {
378
378
  clientTools: processClientTools(params.clientTools)
379
379
  };
380
380
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
381
- const response = await this.request(`/api/agents/${this.agentId}/generate`, {
382
- method: "POST",
383
- body: processedParams
384
- });
381
+ const response = await this.request(
382
+ `/api/agents/${this.agentId}/generate`,
383
+ {
384
+ method: "POST",
385
+ body: processedParams
386
+ }
387
+ );
385
388
  if (response.finishReason === "tool-calls") {
386
389
  const toolCalls = response.toolCalls;
387
390
  if (!toolCalls || !Array.isArray(toolCalls)) {
@@ -430,8 +433,7 @@ var Agent = class extends BaseResource {
430
433
  onToolCall,
431
434
  onFinish,
432
435
  getCurrentDate = () => /* @__PURE__ */ new Date(),
433
- lastMessage,
434
- streamProtocol
436
+ lastMessage
435
437
  }) {
436
438
  const replaceLastMessage = lastMessage?.role === "assistant";
437
439
  let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
@@ -492,213 +494,228 @@ var Agent = class extends BaseResource {
492
494
  replaceLastMessage
493
495
  });
494
496
  }
495
- if (streamProtocol === "text") {
496
- await uiUtils.processTextStream({
497
- stream,
498
- onTextPart(value) {
499
- message.content += value;
500
- execUpdate();
497
+ await uiUtils.processDataStream({
498
+ stream,
499
+ onTextPart(value) {
500
+ if (currentTextPart == null) {
501
+ currentTextPart = {
502
+ type: "text",
503
+ text: value
504
+ };
505
+ message.parts.push(currentTextPart);
506
+ } else {
507
+ currentTextPart.text += value;
501
508
  }
502
- });
503
- onFinish?.({ message, finishReason, usage });
504
- } else {
505
- await uiUtils.processDataStream({
506
- stream,
507
- onTextPart(value) {
508
- if (currentTextPart == null) {
509
- currentTextPart = {
510
- type: "text",
511
- text: value
512
- };
513
- message.parts.push(currentTextPart);
514
- } else {
515
- currentTextPart.text += value;
516
- }
517
- message.content += value;
518
- execUpdate();
519
- },
520
- onReasoningPart(value) {
521
- if (currentReasoningTextDetail == null) {
522
- currentReasoningTextDetail = { type: "text", text: value };
523
- if (currentReasoningPart != null) {
524
- currentReasoningPart.details.push(currentReasoningTextDetail);
525
- }
526
- } else {
527
- currentReasoningTextDetail.text += value;
528
- }
529
- if (currentReasoningPart == null) {
530
- currentReasoningPart = {
531
- type: "reasoning",
532
- reasoning: value,
533
- details: [currentReasoningTextDetail]
534
- };
535
- message.parts.push(currentReasoningPart);
536
- } else {
537
- currentReasoningPart.reasoning += value;
538
- }
539
- message.reasoning = (message.reasoning ?? "") + value;
540
- execUpdate();
541
- },
542
- onReasoningSignaturePart(value) {
543
- if (currentReasoningTextDetail != null) {
544
- currentReasoningTextDetail.signature = value.signature;
545
- }
546
- },
547
- onRedactedReasoningPart(value) {
548
- if (currentReasoningPart == null) {
549
- currentReasoningPart = {
550
- type: "reasoning",
551
- reasoning: "",
552
- details: []
553
- };
554
- message.parts.push(currentReasoningPart);
509
+ message.content += value;
510
+ execUpdate();
511
+ },
512
+ onReasoningPart(value) {
513
+ if (currentReasoningTextDetail == null) {
514
+ currentReasoningTextDetail = { type: "text", text: value };
515
+ if (currentReasoningPart != null) {
516
+ currentReasoningPart.details.push(currentReasoningTextDetail);
555
517
  }
556
- currentReasoningPart.details.push({
557
- type: "redacted",
558
- data: value.data
559
- });
560
- currentReasoningTextDetail = void 0;
561
- execUpdate();
562
- },
563
- onFilePart(value) {
564
- message.parts.push({
565
- type: "file",
566
- mimeType: value.mimeType,
567
- data: value.data
568
- });
569
- execUpdate();
570
- },
571
- onSourcePart(value) {
572
- message.parts.push({
573
- type: "source",
574
- source: value
575
- });
576
- execUpdate();
577
- },
578
- onToolCallStreamingStartPart(value) {
518
+ } else {
519
+ currentReasoningTextDetail.text += value;
520
+ }
521
+ if (currentReasoningPart == null) {
522
+ currentReasoningPart = {
523
+ type: "reasoning",
524
+ reasoning: value,
525
+ details: [currentReasoningTextDetail]
526
+ };
527
+ message.parts.push(currentReasoningPart);
528
+ } else {
529
+ currentReasoningPart.reasoning += value;
530
+ }
531
+ message.reasoning = (message.reasoning ?? "") + value;
532
+ execUpdate();
533
+ },
534
+ onReasoningSignaturePart(value) {
535
+ if (currentReasoningTextDetail != null) {
536
+ currentReasoningTextDetail.signature = value.signature;
537
+ }
538
+ },
539
+ onRedactedReasoningPart(value) {
540
+ if (currentReasoningPart == null) {
541
+ currentReasoningPart = {
542
+ type: "reasoning",
543
+ reasoning: "",
544
+ details: []
545
+ };
546
+ message.parts.push(currentReasoningPart);
547
+ }
548
+ currentReasoningPart.details.push({
549
+ type: "redacted",
550
+ data: value.data
551
+ });
552
+ currentReasoningTextDetail = void 0;
553
+ execUpdate();
554
+ },
555
+ onFilePart(value) {
556
+ message.parts.push({
557
+ type: "file",
558
+ mimeType: value.mimeType,
559
+ data: value.data
560
+ });
561
+ execUpdate();
562
+ },
563
+ onSourcePart(value) {
564
+ message.parts.push({
565
+ type: "source",
566
+ source: value
567
+ });
568
+ execUpdate();
569
+ },
570
+ onToolCallStreamingStartPart(value) {
571
+ if (message.toolInvocations == null) {
572
+ message.toolInvocations = [];
573
+ }
574
+ partialToolCalls[value.toolCallId] = {
575
+ text: "",
576
+ step,
577
+ toolName: value.toolName,
578
+ index: message.toolInvocations.length
579
+ };
580
+ const invocation = {
581
+ state: "partial-call",
582
+ step,
583
+ toolCallId: value.toolCallId,
584
+ toolName: value.toolName,
585
+ args: void 0
586
+ };
587
+ message.toolInvocations.push(invocation);
588
+ updateToolInvocationPart(value.toolCallId, invocation);
589
+ execUpdate();
590
+ },
591
+ onToolCallDeltaPart(value) {
592
+ const partialToolCall = partialToolCalls[value.toolCallId];
593
+ partialToolCall.text += value.argsTextDelta;
594
+ const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
595
+ const invocation = {
596
+ state: "partial-call",
597
+ step: partialToolCall.step,
598
+ toolCallId: value.toolCallId,
599
+ toolName: partialToolCall.toolName,
600
+ args: partialArgs
601
+ };
602
+ message.toolInvocations[partialToolCall.index] = invocation;
603
+ updateToolInvocationPart(value.toolCallId, invocation);
604
+ execUpdate();
605
+ },
606
+ async onToolCallPart(value) {
607
+ const invocation = {
608
+ state: "call",
609
+ step,
610
+ ...value
611
+ };
612
+ if (partialToolCalls[value.toolCallId] != null) {
613
+ message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
614
+ } else {
579
615
  if (message.toolInvocations == null) {
580
616
  message.toolInvocations = [];
581
617
  }
582
- partialToolCalls[value.toolCallId] = {
583
- text: "",
584
- step,
585
- toolName: value.toolName,
586
- index: message.toolInvocations.length
587
- };
588
- const invocation = {
589
- state: "partial-call",
590
- step,
591
- toolCallId: value.toolCallId,
592
- toolName: value.toolName,
593
- args: void 0
594
- };
595
618
  message.toolInvocations.push(invocation);
596
- updateToolInvocationPart(value.toolCallId, invocation);
597
- execUpdate();
598
- },
599
- onToolCallDeltaPart(value) {
600
- const partialToolCall = partialToolCalls[value.toolCallId];
601
- partialToolCall.text += value.argsTextDelta;
602
- const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
603
- const invocation = {
604
- state: "partial-call",
605
- step: partialToolCall.step,
606
- toolCallId: value.toolCallId,
607
- toolName: partialToolCall.toolName,
608
- args: partialArgs
609
- };
610
- message.toolInvocations[partialToolCall.index] = invocation;
611
- updateToolInvocationPart(value.toolCallId, invocation);
612
- execUpdate();
613
- },
614
- async onToolCallPart(value) {
615
- const invocation = {
616
- state: "call",
617
- step,
618
- ...value
619
- };
620
- if (partialToolCalls[value.toolCallId] != null) {
621
- message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
622
- } else {
623
- if (message.toolInvocations == null) {
624
- message.toolInvocations = [];
625
- }
626
- message.toolInvocations.push(invocation);
627
- }
628
- updateToolInvocationPart(value.toolCallId, invocation);
629
- execUpdate();
630
- if (onToolCall) {
631
- const result = await onToolCall({ toolCall: value });
632
- if (result != null) {
633
- const invocation2 = {
634
- state: "result",
635
- step,
636
- ...value,
637
- result
638
- };
639
- message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
640
- updateToolInvocationPart(value.toolCallId, invocation2);
641
- execUpdate();
642
- }
643
- }
644
- },
645
- onToolResultPart(value) {
646
- const toolInvocations = message.toolInvocations;
647
- if (toolInvocations == null) {
648
- throw new Error("tool_result must be preceded by a tool_call");
649
- }
650
- const toolInvocationIndex = toolInvocations.findIndex(
651
- (invocation2) => invocation2.toolCallId === value.toolCallId
652
- );
653
- if (toolInvocationIndex === -1) {
654
- throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
655
- }
656
- const invocation = {
657
- ...toolInvocations[toolInvocationIndex],
658
- state: "result",
659
- ...value
660
- };
661
- toolInvocations[toolInvocationIndex] = invocation;
662
- updateToolInvocationPart(value.toolCallId, invocation);
663
- execUpdate();
664
- },
665
- onDataPart(value) {
666
- data.push(...value);
667
- execUpdate();
668
- },
669
- onMessageAnnotationsPart(value) {
670
- if (messageAnnotations == null) {
671
- messageAnnotations = [...value];
672
- } else {
673
- messageAnnotations.push(...value);
674
- }
675
- execUpdate();
676
- },
677
- onFinishStepPart(value) {
678
- step += 1;
679
- currentTextPart = value.isContinued ? currentTextPart : void 0;
680
- currentReasoningPart = void 0;
681
- currentReasoningTextDetail = void 0;
682
- },
683
- onStartStepPart(value) {
684
- if (!replaceLastMessage) {
685
- message.id = value.messageId;
686
- }
687
- message.parts.push({ type: "step-start" });
688
- execUpdate();
689
- },
690
- onFinishMessagePart(value) {
691
- finishReason = value.finishReason;
692
- if (value.usage != null) {
693
- usage = value.usage;
619
+ }
620
+ updateToolInvocationPart(value.toolCallId, invocation);
621
+ execUpdate();
622
+ if (onToolCall) {
623
+ const result = await onToolCall({ toolCall: value });
624
+ if (result != null) {
625
+ const invocation2 = {
626
+ state: "result",
627
+ step,
628
+ ...value,
629
+ result
630
+ };
631
+ message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
632
+ updateToolInvocationPart(value.toolCallId, invocation2);
633
+ execUpdate();
694
634
  }
695
- },
696
- onErrorPart(error) {
697
- throw new Error(error);
698
635
  }
636
+ },
637
+ onToolResultPart(value) {
638
+ const toolInvocations = message.toolInvocations;
639
+ if (toolInvocations == null) {
640
+ throw new Error("tool_result must be preceded by a tool_call");
641
+ }
642
+ const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
643
+ if (toolInvocationIndex === -1) {
644
+ throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
645
+ }
646
+ const invocation = {
647
+ ...toolInvocations[toolInvocationIndex],
648
+ state: "result",
649
+ ...value
650
+ };
651
+ toolInvocations[toolInvocationIndex] = invocation;
652
+ updateToolInvocationPart(value.toolCallId, invocation);
653
+ execUpdate();
654
+ },
655
+ onDataPart(value) {
656
+ data.push(...value);
657
+ execUpdate();
658
+ },
659
+ onMessageAnnotationsPart(value) {
660
+ if (messageAnnotations == null) {
661
+ messageAnnotations = [...value];
662
+ } else {
663
+ messageAnnotations.push(...value);
664
+ }
665
+ execUpdate();
666
+ },
667
+ onFinishStepPart(value) {
668
+ step += 1;
669
+ currentTextPart = value.isContinued ? currentTextPart : void 0;
670
+ currentReasoningPart = void 0;
671
+ currentReasoningTextDetail = void 0;
672
+ },
673
+ onStartStepPart(value) {
674
+ if (!replaceLastMessage) {
675
+ message.id = value.messageId;
676
+ }
677
+ message.parts.push({ type: "step-start" });
678
+ execUpdate();
679
+ },
680
+ onFinishMessagePart(value) {
681
+ finishReason = value.finishReason;
682
+ if (value.usage != null) {
683
+ usage = value.usage;
684
+ }
685
+ },
686
+ onErrorPart(error) {
687
+ throw new Error(error);
688
+ }
689
+ });
690
+ onFinish?.({ message, finishReason, usage });
691
+ }
692
+ /**
693
+ * Streams a response from the agent
694
+ * @param params - Stream parameters including prompt
695
+ * @returns Promise containing the enhanced Response object with processDataStream method
696
+ */
697
+ async stream(params) {
698
+ const processedParams = {
699
+ ...params,
700
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
701
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
702
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
703
+ clientTools: processClientTools(params.clientTools)
704
+ };
705
+ const { readable, writable } = new TransformStream();
706
+ const response = await this.processStreamResponse(processedParams, writable);
707
+ const streamResponse = new Response(readable, {
708
+ status: response.status,
709
+ statusText: response.statusText,
710
+ headers: response.headers
711
+ });
712
+ streamResponse.processDataStream = async (options = {}) => {
713
+ await uiUtils.processDataStream({
714
+ stream: streamResponse.body,
715
+ ...options
699
716
  });
700
- onFinish?.({ message, finishReason, usage });
701
- }
717
+ };
718
+ return streamResponse;
702
719
  }
703
720
  /**
704
721
  * Processes the stream response and handles tool calls
@@ -713,7 +730,6 @@ var Agent = class extends BaseResource {
713
730
  throw new Error("No response body");
714
731
  }
715
732
  try {
716
- const streamProtocol = processedParams.output ? "text" : "data";
717
733
  let toolCalls = [];
718
734
  let messages = [];
719
735
  const [streamForWritable, streamForProcessing] = response.body.tee();
@@ -725,7 +741,12 @@ var Agent = class extends BaseResource {
725
741
  this.processChatResponse({
726
742
  stream: streamForProcessing,
727
743
  update: ({ message }) => {
728
- messages.push(message);
744
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
745
+ if (existingIndex !== -1) {
746
+ messages[existingIndex] = message;
747
+ } else {
748
+ messages.push(message);
749
+ }
729
750
  },
730
751
  onFinish: async ({ finishReason, message }) => {
731
752
  if (finishReason === "tool-calls") {
@@ -785,63 +806,29 @@ var Agent = class extends BaseResource {
785
806
  this.processStreamResponse(
786
807
  {
787
808
  ...processedParams,
788
- messages: [...messageArray, ...messages, lastMessage]
809
+ messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
789
810
  },
790
811
  writable
791
- );
812
+ ).catch((error) => {
813
+ console.error("Error processing stream response:", error);
814
+ });
792
815
  }
793
816
  }
794
817
  } else {
795
818
  setTimeout(() => {
796
- if (!writable.locked) {
797
- writable.close();
798
- }
819
+ writable.close();
799
820
  }, 0);
800
821
  }
801
822
  },
802
- lastMessage: void 0,
803
- streamProtocol
823
+ lastMessage: void 0
824
+ }).catch((error) => {
825
+ console.error("Error processing stream response:", error);
804
826
  });
805
827
  } catch (error) {
806
828
  console.error("Error processing stream response:", error);
807
829
  }
808
830
  return response;
809
831
  }
810
- /**
811
- * Streams a response from the agent
812
- * @param params - Stream parameters including prompt
813
- * @returns Promise containing the enhanced Response object with processDataStream and processTextStream methods
814
- */
815
- async stream(params) {
816
- const processedParams = {
817
- ...params,
818
- output: params.output ? zodToJsonSchema(params.output) : void 0,
819
- experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
820
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
821
- clientTools: processClientTools(params.clientTools)
822
- };
823
- const { readable, writable } = new TransformStream();
824
- const response = await this.processStreamResponse(processedParams, writable);
825
- const streamResponse = new Response(readable, {
826
- status: response.status,
827
- statusText: response.statusText,
828
- headers: response.headers
829
- });
830
- streamResponse.processDataStream = async (options = {}) => {
831
- await uiUtils.processDataStream({
832
- stream: streamResponse.body,
833
- ...options
834
- });
835
- };
836
- streamResponse.processTextStream = async (options) => {
837
- await uiUtils.processTextStream({
838
- stream: streamResponse.body,
839
- onTextPart: options?.onTextPart ?? (() => {
840
- })
841
- });
842
- };
843
- return streamResponse;
844
- }
845
832
  /**
846
833
  * Gets details about a specific tool available to the agent
847
834
  * @param toolId - ID of the tool to retrieve
@@ -985,6 +972,36 @@ var MemoryThread = class extends BaseResource {
985
972
  });
986
973
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
987
974
  }
975
+ /**
976
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
977
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
978
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
979
+ */
980
+ getMessagesPaginated({
981
+ selectBy,
982
+ ...rest
983
+ }) {
984
+ const query = new URLSearchParams({
985
+ ...rest,
986
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
987
+ });
988
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
989
+ }
990
+ /**
991
+ * Deletes one or more messages from the thread
992
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
993
+ * message object with id property, or array of message objects
994
+ * @returns Promise containing deletion result
995
+ */
996
+ deleteMessages(messageIds) {
997
+ const query = new URLSearchParams({
998
+ agentId: this.agentId
999
+ });
1000
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
1001
+ method: "POST",
1002
+ body: { messageIds }
1003
+ });
1004
+ }
988
1005
  };
989
1006
 
990
1007
  // src/resources/vector.ts
@@ -1406,6 +1423,14 @@ var Workflow = class extends BaseResource {
1406
1423
  method: "POST"
1407
1424
  });
1408
1425
  }
1426
+ /**
1427
+ * Creates a new workflow run (alias for createRun)
1428
+ * @param params - Optional object containing the optional runId
1429
+ * @returns Promise containing the runId of the created run
1430
+ */
1431
+ createRunAsync(params) {
1432
+ return this.createRun(params);
1433
+ }
1409
1434
  /**
1410
1435
  * Starts a workflow run synchronously without waiting for the workflow to complete
1411
1436
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -1725,6 +1750,21 @@ var NetworkMemoryThread = class extends BaseResource {
1725
1750
  });
1726
1751
  return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1727
1752
  }
1753
+ /**
1754
+ * Deletes one or more messages from the thread
1755
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1756
+ * message object with id property, or array of message objects
1757
+ * @returns Promise containing deletion result
1758
+ */
1759
+ deleteMessages(messageIds) {
1760
+ const query = new URLSearchParams({
1761
+ networkId: this.networkId
1762
+ });
1763
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
1764
+ method: "POST",
1765
+ body: { messageIds }
1766
+ });
1767
+ }
1728
1768
  };
1729
1769
 
1730
1770
  // src/resources/vNextNetwork.ts
@@ -2294,6 +2334,84 @@ var MastraClient = class extends BaseResource {
2294
2334
  }
2295
2335
  });
2296
2336
  }
2337
+ /**
2338
+ * Retrieves all available scorers
2339
+ * @returns Promise containing list of available scorers
2340
+ */
2341
+ getScorers() {
2342
+ return this.request("/api/scores/scorers");
2343
+ }
2344
+ /**
2345
+ * Retrieves a scorer by ID
2346
+ * @param scorerId - ID of the scorer to retrieve
2347
+ * @returns Promise containing the scorer
2348
+ */
2349
+ getScorer(scorerId) {
2350
+ return this.request(`/api/scores/scorers/${scorerId}`);
2351
+ }
2352
+ getScoresByScorerId(params) {
2353
+ const { page, perPage, scorerId, entityId, entityType } = params;
2354
+ const searchParams = new URLSearchParams();
2355
+ if (entityId) {
2356
+ searchParams.set("entityId", entityId);
2357
+ }
2358
+ if (entityType) {
2359
+ searchParams.set("entityType", entityType);
2360
+ }
2361
+ if (page !== void 0) {
2362
+ searchParams.set("page", String(page));
2363
+ }
2364
+ if (perPage !== void 0) {
2365
+ searchParams.set("perPage", String(perPage));
2366
+ }
2367
+ const queryString = searchParams.toString();
2368
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
2369
+ }
2370
+ /**
2371
+ * Retrieves scores by run ID
2372
+ * @param params - Parameters containing run ID and pagination options
2373
+ * @returns Promise containing scores and pagination info
2374
+ */
2375
+ getScoresByRunId(params) {
2376
+ const { runId, page, perPage } = params;
2377
+ const searchParams = new URLSearchParams();
2378
+ if (page !== void 0) {
2379
+ searchParams.set("page", String(page));
2380
+ }
2381
+ if (perPage !== void 0) {
2382
+ searchParams.set("perPage", String(perPage));
2383
+ }
2384
+ const queryString = searchParams.toString();
2385
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
2386
+ }
2387
+ /**
2388
+ * Retrieves scores by entity ID and type
2389
+ * @param params - Parameters containing entity ID, type, and pagination options
2390
+ * @returns Promise containing scores and pagination info
2391
+ */
2392
+ getScoresByEntityId(params) {
2393
+ const { entityId, entityType, page, perPage } = params;
2394
+ const searchParams = new URLSearchParams();
2395
+ if (page !== void 0) {
2396
+ searchParams.set("page", String(page));
2397
+ }
2398
+ if (perPage !== void 0) {
2399
+ searchParams.set("perPage", String(perPage));
2400
+ }
2401
+ const queryString = searchParams.toString();
2402
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
2403
+ }
2404
+ /**
2405
+ * Saves a score
2406
+ * @param params - Parameters containing the score data to save
2407
+ * @returns Promise containing the saved score
2408
+ */
2409
+ saveScore(params) {
2410
+ return this.request("/api/scores", {
2411
+ method: "POST",
2412
+ body: params
2413
+ });
2414
+ }
2297
2415
  };
2298
2416
 
2299
2417
  exports.MastraClient = MastraClient;