@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.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AbstractAgent, EventType } from '@ag-ui/client';
2
2
  import { Observable } from 'rxjs';
3
- import { processTextStream, processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
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.body instanceof FormData) && (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(`/api/agents/${this.agentId}/generate`, {
376
- method: "POST",
377
- body: processedParams
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
- if (streamProtocol === "text") {
490
- await processTextStream({
491
- stream,
492
- onTextPart(value) {
493
- message.content += value;
494
- execUpdate();
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
- 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);
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
- 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) {
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
- 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;
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
- onFinish?.({ message, finishReason, usage });
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();
@@ -719,7 +735,12 @@ var Agent = class extends BaseResource {
719
735
  this.processChatResponse({
720
736
  stream: streamForProcessing,
721
737
  update: ({ message }) => {
722
- messages.push(message);
738
+ const existingIndex = messages.findIndex((m) => m.id === message.id);
739
+ if (existingIndex !== -1) {
740
+ messages[existingIndex] = message;
741
+ } else {
742
+ messages.push(message);
743
+ }
723
744
  },
724
745
  onFinish: async ({ finishReason, message }) => {
725
746
  if (finishReason === "tool-calls") {
@@ -779,63 +800,29 @@ var Agent = class extends BaseResource {
779
800
  this.processStreamResponse(
780
801
  {
781
802
  ...processedParams,
782
- messages: [...messageArray, ...messages, lastMessage]
803
+ messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
783
804
  },
784
805
  writable
785
- );
806
+ ).catch((error) => {
807
+ console.error("Error processing stream response:", error);
808
+ });
786
809
  }
787
810
  }
788
811
  } else {
789
812
  setTimeout(() => {
790
- if (!writable.locked) {
791
- writable.close();
792
- }
813
+ writable.close();
793
814
  }, 0);
794
815
  }
795
816
  },
796
- lastMessage: void 0,
797
- streamProtocol
817
+ lastMessage: void 0
818
+ }).catch((error) => {
819
+ console.error("Error processing stream response:", error);
798
820
  });
799
821
  } catch (error) {
800
822
  console.error("Error processing stream response:", error);
801
823
  }
802
824
  return response;
803
825
  }
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
826
  /**
840
827
  * Gets details about a specific tool available to the agent
841
828
  * @param toolId - ID of the tool to retrieve
@@ -979,6 +966,36 @@ var MemoryThread = class extends BaseResource {
979
966
  });
980
967
  return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
981
968
  }
969
+ /**
970
+ * Retrieves paginated messages associated with the thread with advanced filtering and selection options
971
+ * @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
972
+ * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
973
+ */
974
+ getMessagesPaginated({
975
+ selectBy,
976
+ ...rest
977
+ }) {
978
+ const query = new URLSearchParams({
979
+ ...rest,
980
+ ...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
981
+ });
982
+ return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
983
+ }
984
+ /**
985
+ * Deletes one or more messages from the thread
986
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
987
+ * message object with id property, or array of message objects
988
+ * @returns Promise containing deletion result
989
+ */
990
+ deleteMessages(messageIds) {
991
+ const query = new URLSearchParams({
992
+ agentId: this.agentId
993
+ });
994
+ return this.request(`/api/memory/messages/delete?${query.toString()}`, {
995
+ method: "POST",
996
+ body: { messageIds }
997
+ });
998
+ }
982
999
  };
983
1000
 
984
1001
  // src/resources/vector.ts
@@ -1400,6 +1417,14 @@ var Workflow = class extends BaseResource {
1400
1417
  method: "POST"
1401
1418
  });
1402
1419
  }
1420
+ /**
1421
+ * Creates a new workflow run (alias for createRun)
1422
+ * @param params - Optional object containing the optional runId
1423
+ * @returns Promise containing the runId of the created run
1424
+ */
1425
+ createRunAsync(params) {
1426
+ return this.createRun(params);
1427
+ }
1403
1428
  /**
1404
1429
  * Starts a workflow run synchronously without waiting for the workflow to complete
1405
1430
  * @param params - Object containing the runId, inputData and runtimeContext
@@ -1719,6 +1744,21 @@ var NetworkMemoryThread = class extends BaseResource {
1719
1744
  });
1720
1745
  return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
1721
1746
  }
1747
+ /**
1748
+ * Deletes one or more messages from the thread
1749
+ * @param messageIds - Can be a single message ID (string), array of message IDs,
1750
+ * message object with id property, or array of message objects
1751
+ * @returns Promise containing deletion result
1752
+ */
1753
+ deleteMessages(messageIds) {
1754
+ const query = new URLSearchParams({
1755
+ networkId: this.networkId
1756
+ });
1757
+ return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
1758
+ method: "POST",
1759
+ body: { messageIds }
1760
+ });
1761
+ }
1722
1762
  };
1723
1763
 
1724
1764
  // src/resources/vNextNetwork.ts
@@ -2288,6 +2328,84 @@ var MastraClient = class extends BaseResource {
2288
2328
  }
2289
2329
  });
2290
2330
  }
2331
+ /**
2332
+ * Retrieves all available scorers
2333
+ * @returns Promise containing list of available scorers
2334
+ */
2335
+ getScorers() {
2336
+ return this.request("/api/scores/scorers");
2337
+ }
2338
+ /**
2339
+ * Retrieves a scorer by ID
2340
+ * @param scorerId - ID of the scorer to retrieve
2341
+ * @returns Promise containing the scorer
2342
+ */
2343
+ getScorer(scorerId) {
2344
+ return this.request(`/api/scores/scorers/${scorerId}`);
2345
+ }
2346
+ getScoresByScorerId(params) {
2347
+ const { page, perPage, scorerId, entityId, entityType } = params;
2348
+ const searchParams = new URLSearchParams();
2349
+ if (entityId) {
2350
+ searchParams.set("entityId", entityId);
2351
+ }
2352
+ if (entityType) {
2353
+ searchParams.set("entityType", entityType);
2354
+ }
2355
+ if (page !== void 0) {
2356
+ searchParams.set("page", String(page));
2357
+ }
2358
+ if (perPage !== void 0) {
2359
+ searchParams.set("perPage", String(perPage));
2360
+ }
2361
+ const queryString = searchParams.toString();
2362
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
2363
+ }
2364
+ /**
2365
+ * Retrieves scores by run ID
2366
+ * @param params - Parameters containing run ID and pagination options
2367
+ * @returns Promise containing scores and pagination info
2368
+ */
2369
+ getScoresByRunId(params) {
2370
+ const { runId, page, perPage } = params;
2371
+ const searchParams = new URLSearchParams();
2372
+ if (page !== void 0) {
2373
+ searchParams.set("page", String(page));
2374
+ }
2375
+ if (perPage !== void 0) {
2376
+ searchParams.set("perPage", String(perPage));
2377
+ }
2378
+ const queryString = searchParams.toString();
2379
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
2380
+ }
2381
+ /**
2382
+ * Retrieves scores by entity ID and type
2383
+ * @param params - Parameters containing entity ID, type, and pagination options
2384
+ * @returns Promise containing scores and pagination info
2385
+ */
2386
+ getScoresByEntityId(params) {
2387
+ const { entityId, entityType, page, perPage } = params;
2388
+ const searchParams = new URLSearchParams();
2389
+ if (page !== void 0) {
2390
+ searchParams.set("page", String(page));
2391
+ }
2392
+ if (perPage !== void 0) {
2393
+ searchParams.set("perPage", String(perPage));
2394
+ }
2395
+ const queryString = searchParams.toString();
2396
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
2397
+ }
2398
+ /**
2399
+ * Saves a score
2400
+ * @param params - Parameters containing the score data to save
2401
+ * @returns Promise containing the saved score
2402
+ */
2403
+ saveScore(params) {
2404
+ return this.request("/api/scores", {
2405
+ method: "POST",
2406
+ body: params
2407
+ });
2408
+ }
2291
2409
  };
2292
2410
 
2293
2411
  export { MastraClient };