@mastra/rag 2.7.0-alpha.2 → 2.7.0

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
@@ -17,7 +17,7 @@ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
17
17
  var __getOwnPropNames = Object.getOwnPropertyNames;
18
18
  var __getProtoOf = Object.getPrototypeOf;
19
19
  var __hasOwnProp = Object.prototype.hasOwnProperty;
20
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
20
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
21
21
  var __copyProps = (to, from, except, desc) => {
22
22
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
23
  key = keys[i];
@@ -28,7 +28,7 @@ var __copyProps = (to, from, except, desc) => {
28
28
  }
29
29
  return to;
30
30
  };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp$1(target, "default", {
32
32
  value: mod,
33
33
  enumerable: true
34
34
  }) : target, mod));
@@ -776,7 +776,6 @@ function createEventSourceParserStream() {
776
776
  case "retry":
777
777
  const parsedRetry = parseInt(value, 10);
778
778
  if (!isNaN(parsedRetry)) retry = parsedRetry;
779
- break;
780
779
  }
781
780
  }
782
781
  return new TransformStream({
@@ -1275,16 +1274,14 @@ function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false,
1275
1274
  case "text":
1276
1275
  text += part.text;
1277
1276
  break;
1278
- case "tool-call":
1279
- toolCalls.push({
1280
- id: part.toolCallId,
1281
- type: "function",
1282
- function: {
1283
- name: part.toolName,
1284
- arguments: JSON.stringify(part.args)
1285
- }
1286
- });
1287
- break;
1277
+ case "tool-call": toolCalls.push({
1278
+ id: part.toolCallId,
1279
+ type: "function",
1280
+ function: {
1281
+ name: part.toolName,
1282
+ arguments: JSON.stringify(part.args)
1283
+ }
1284
+ });
1288
1285
  }
1289
1286
  if (useLegacyFunctionCalling) {
1290
1287
  if (toolCalls.length > 1) throw new UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling with multiple tool calls in one message" });
@@ -2641,14 +2638,12 @@ function convertToOpenAIResponsesMessages({ prompt, systemMessageMode }) {
2641
2638
  }]
2642
2639
  });
2643
2640
  break;
2644
- case "tool-call":
2645
- messages.push({
2646
- type: "function_call",
2647
- call_id: part.toolCallId,
2648
- name: part.toolName,
2649
- arguments: JSON.stringify(part.args)
2650
- });
2651
- break;
2641
+ case "tool-call": messages.push({
2642
+ type: "function_call",
2643
+ call_id: part.toolCallId,
2644
+ name: part.toolName,
2645
+ arguments: JSON.stringify(part.args)
2646
+ });
2652
2647
  }
2653
2648
  break;
2654
2649
  case "tool":
@@ -2704,20 +2699,16 @@ function prepareResponsesTools({ mode, strict }) {
2704
2699
  user_location: tool.args.userLocation
2705
2700
  });
2706
2701
  break;
2707
- default:
2708
- toolWarnings.push({
2709
- type: "unsupported-tool",
2710
- tool
2711
- });
2712
- break;
2702
+ default: toolWarnings.push({
2703
+ type: "unsupported-tool",
2704
+ tool
2705
+ });
2713
2706
  }
2714
2707
  break;
2715
- default:
2716
- toolWarnings.push({
2717
- type: "unsupported-tool",
2718
- tool
2719
- });
2720
- break;
2708
+ default: toolWarnings.push({
2709
+ type: "unsupported-tool",
2710
+ tool
2711
+ });
2721
2712
  }
2722
2713
  if (toolChoice == null) return {
2723
2714
  tools: openaiTools2,
@@ -3332,19 +3323,21 @@ var OpenAISpeechModel = class {
3332
3323
  speed,
3333
3324
  instructions
3334
3325
  };
3335
- if (outputFormat) if ([
3336
- "mp3",
3337
- "opus",
3338
- "aac",
3339
- "flac",
3340
- "wav",
3341
- "pcm"
3342
- ].includes(outputFormat)) requestBody.response_format = outputFormat;
3343
- else warnings.push({
3344
- type: "unsupported-setting",
3345
- setting: "outputFormat",
3346
- details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3347
- });
3326
+ if (outputFormat) {
3327
+ if ([
3328
+ "mp3",
3329
+ "opus",
3330
+ "aac",
3331
+ "flac",
3332
+ "wav",
3333
+ "pcm"
3334
+ ].includes(outputFormat)) requestBody.response_format = outputFormat;
3335
+ else warnings.push({
3336
+ type: "unsupported-setting",
3337
+ setting: "outputFormat",
3338
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3339
+ });
3340
+ }
3348
3341
  if (openAIOptions) {
3349
3342
  const speechModelOptions = {};
3350
3343
  for (const key in speechModelOptions) {
@@ -4948,21 +4941,22 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4948
4941
  */
4949
4942
  handlePrimitiveValue(value, key, currentChunk, chunks, fullPath) {
4950
4943
  const testValue = { [key]: value };
4951
- if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) if (RecursiveJsonTransformer.jsonSize({
4952
- ...currentChunk,
4953
- ...testValue
4954
- }) <= this.maxSize) return {
4955
- currentChunk: {
4944
+ if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) {
4945
+ if (RecursiveJsonTransformer.jsonSize({
4956
4946
  ...currentChunk,
4957
4947
  ...testValue
4958
- },
4959
- chunks
4960
- };
4961
- else return {
4962
- currentChunk: testValue,
4963
- chunks: [...chunks, currentChunk]
4964
- };
4965
- else if (typeof value === "string") {
4948
+ }) <= this.maxSize) return {
4949
+ currentChunk: {
4950
+ ...currentChunk,
4951
+ ...testValue
4952
+ },
4953
+ chunks
4954
+ };
4955
+ else return {
4956
+ currentChunk: testValue,
4957
+ chunks: [...chunks, currentChunk]
4958
+ };
4959
+ } else if (typeof value === "string") {
4966
4960
  const newChunks = this.splitLongString(value).map((chunk) => {
4967
4961
  return this.createChunk(chunk, fullPath);
4968
4962
  }).filter((chunk) => RecursiveJsonTransformer.jsonSize(chunk) <= this.maxSize);
@@ -6896,9 +6890,10 @@ const createGraphRAGTool = (options) => {
6896
6890
  };
6897
6891
  const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
6898
6892
  let isInitialized = false;
6893
+ const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
6899
6894
  return createTool({
6900
6895
  id: toolId,
6901
- inputSchema: options.enableFilter ? filterSchema : z.object(baseSchema).passthrough(),
6896
+ inputSchema,
6902
6897
  outputSchema: outputSchema$1,
6903
6898
  description: toolDescription,
6904
6899
  execute: async (inputData, context) => {
@@ -7042,10 +7037,13 @@ const createGraphRAGTool = (options) => {
7042
7037
  const createVectorQueryTool = (options) => {
7043
7038
  const { id, description } = options;
7044
7039
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
7040
+ const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
7041
+ const toolDescription = description || defaultVectorQueryDescription();
7042
+ const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
7045
7043
  return createTool({
7046
- id: id || `VectorQuery ${storeName} ${options.indexName} Tool`,
7047
- description: description || defaultVectorQueryDescription(),
7048
- inputSchema: options.enableFilter ? filterSchema : z.object(baseSchema).passthrough(),
7044
+ id: toolId,
7045
+ description: toolDescription,
7046
+ inputSchema,
7049
7047
  outputSchema: outputSchema$1,
7050
7048
  execute: async (inputData, context) => {
7051
7049
  const { requestContext, mastra, tracingContext } = context || {};