@mastra/core 0.5.0-alpha.9 → 0.5.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.
Files changed (91) hide show
  1. package/dist/agent/index.cjs +3 -2140
  2. package/dist/agent/index.d.cts +1 -1
  3. package/dist/agent/index.d.ts +1 -1
  4. package/dist/agent/index.js +1 -1
  5. package/dist/{base-CMEKtEnE.d.cts → base-CIPKleAU.d.cts} +97 -60
  6. package/dist/{base-B78F6w8S.d.ts → base-C_Oq53qk.d.ts} +97 -60
  7. package/dist/base.cjs +5 -140
  8. package/dist/bundler/index.cjs +5 -160
  9. package/dist/chunk-2W2GYEYQ.cjs +25 -0
  10. package/dist/chunk-3ASEZT7U.cjs +1586 -0
  11. package/dist/chunk-43Y7WG5W.cjs +335 -0
  12. package/dist/{chunk-IM7CM3DU.js → chunk-4Y74D74B.js} +1 -1
  13. package/dist/chunk-ENT7U27Y.cjs +37 -0
  14. package/dist/chunk-F5UYWPV4.cjs +14 -0
  15. package/dist/chunk-FL3GQXQ2.cjs +218 -0
  16. package/dist/chunk-FRQFWZDN.cjs +2 -0
  17. package/dist/chunk-GXQRMKSN.cjs +367 -0
  18. package/dist/chunk-HJPMYDWO.cjs +37 -0
  19. package/dist/chunk-IIWRJFLQ.cjs +51 -0
  20. package/dist/chunk-KFQ7Z3PO.cjs +347 -0
  21. package/dist/{chunk-TWAIC2XA.js → chunk-KP5UAFLN.js} +1 -1
  22. package/dist/chunk-KPKFLQFR.cjs +12 -0
  23. package/dist/{chunk-NR5T72G7.js → chunk-MLFXOST6.js} +1 -1
  24. package/dist/{chunk-6V737PR2.js → chunk-OD7ZMKHY.js} +166 -58
  25. package/dist/chunk-OTFLHXHZ.cjs +65 -0
  26. package/dist/chunk-RWTSGWWL.cjs +81 -0
  27. package/dist/chunk-ST5RMVLG.cjs +87 -0
  28. package/dist/chunk-SYQ7NK2E.cjs +24 -0
  29. package/dist/chunk-UZNQG7QO.cjs +1868 -0
  30. package/dist/chunk-V5ORZPFW.cjs +38 -0
  31. package/dist/chunk-VA4P7QJT.cjs +443 -0
  32. package/dist/chunk-WB2HREXE.cjs +166 -0
  33. package/dist/chunk-WOMOGDGR.cjs +691 -0
  34. package/dist/chunk-XB2TJ7LX.cjs +408 -0
  35. package/dist/{chunk-4AQBRUR2.js → chunk-XF2FMJYK.js} +1 -1
  36. package/dist/chunk-XLSROQ26.cjs +91 -0
  37. package/dist/chunk-YK3XJ52U.cjs +192 -0
  38. package/dist/{chunk-EWB556GS.js → chunk-YPD6BQIM.js} +29 -1
  39. package/dist/deployer/index.cjs +5 -167
  40. package/dist/eval/index.cjs +9 -105
  41. package/dist/eval/index.d.cts +1 -1
  42. package/dist/eval/index.d.ts +1 -1
  43. package/dist/hooks/index.cjs +14 -83
  44. package/dist/index.cjs +253 -7516
  45. package/dist/index.d.cts +3 -3
  46. package/dist/index.d.ts +3 -3
  47. package/dist/index.js +7 -7
  48. package/dist/integration/index.cjs +9 -108
  49. package/dist/integration/index.d.cts +1 -1
  50. package/dist/integration/index.d.ts +1 -1
  51. package/dist/llm/index.d.cts +1 -1
  52. package/dist/llm/index.d.ts +1 -1
  53. package/dist/logger/index.cjs +33 -161
  54. package/dist/mastra/index.cjs +3 -1755
  55. package/dist/mastra/index.d.cts +1 -1
  56. package/dist/mastra/index.d.ts +1 -1
  57. package/dist/mastra/index.js +1 -1
  58. package/dist/memory/index.cjs +4 -2050
  59. package/dist/memory/index.d.cts +1 -1
  60. package/dist/memory/index.d.ts +1 -1
  61. package/dist/memory/index.js +1 -1
  62. package/dist/relevance/index.cjs +10 -2201
  63. package/dist/relevance/index.d.cts +19 -2
  64. package/dist/relevance/index.d.ts +19 -2
  65. package/dist/relevance/index.js +1 -1
  66. package/dist/storage/index.cjs +29 -367
  67. package/dist/storage/index.d.cts +1 -1
  68. package/dist/storage/index.d.ts +1 -1
  69. package/dist/storage/libsql/index.cjs +9 -798
  70. package/dist/storage/libsql/index.d.cts +1 -1
  71. package/dist/storage/libsql/index.d.ts +1 -1
  72. package/dist/telemetry/index.cjs +21 -408
  73. package/dist/telemetry/index.d.cts +1 -1
  74. package/dist/telemetry/index.d.ts +1 -1
  75. package/dist/tools/index.cjs +11 -22
  76. package/dist/tools/index.d.cts +3 -3
  77. package/dist/tools/index.d.ts +3 -3
  78. package/dist/tts/index.cjs +3 -328
  79. package/dist/utils.cjs +41 -350
  80. package/dist/utils.d.cts +3 -3
  81. package/dist/utils.d.ts +3 -3
  82. package/dist/utils.js +1 -1
  83. package/dist/vector/filter/index.cjs +7 -189
  84. package/dist/vector/index.cjs +5 -172
  85. package/dist/vector/libsql/index.cjs +9 -1047
  86. package/dist/voice/index.cjs +8 -306
  87. package/dist/workflows/index.cjs +65 -1936
  88. package/dist/workflows/index.d.cts +4 -3
  89. package/dist/workflows/index.d.ts +4 -3
  90. package/dist/workflows/index.js +1 -1
  91. package/package.json +27 -27
package/dist/utils.cjs CHANGED
@@ -1,355 +1,46 @@
1
1
  'use strict';
2
2
 
3
- var crypto = require('crypto');
4
- var jsonSchemaToZod = require('json-schema-to-zod');
5
- var zod = require('zod');
3
+ var chunk43Y7WG5W_cjs = require('./chunk-43Y7WG5W.cjs');
6
4
 
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
5
 
9
- var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
10
6
 
11
- // src/utils.ts
12
-
13
- // src/tools/tool.ts
14
- var Tool = class {
15
- id;
16
- description;
17
- inputSchema;
18
- outputSchema;
19
- execute;
20
- mastra;
21
- constructor(opts) {
22
- this.id = opts.id;
23
- this.description = opts.description;
24
- this.inputSchema = opts.inputSchema;
25
- this.outputSchema = opts.outputSchema;
26
- this.execute = opts.execute;
27
- this.mastra = opts.mastra;
28
- }
29
- };
30
-
31
- // src/utils.ts
32
- var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
33
- function jsonSchemaPropertiesToTSTypes(value) {
34
- if (!value.type) {
35
- return zod.z.object({});
36
- }
37
- let zodType;
38
- switch (value.type) {
39
- case "string":
40
- zodType = zod.z.string().describe((value.description || "") + (value.examples ? `
41
- Examples: ${value.examples.join(", ")}` : ""));
42
- break;
43
- case "number":
44
- zodType = zod.z.number().describe((value.description || "") + (value.examples ? `
45
- Examples: ${value.examples.join(", ")}` : ""));
46
- break;
47
- case "integer":
48
- zodType = zod.z.number().int().describe((value.description || "") + (value.examples ? `
49
- Examples: ${value.examples.join(", ")}` : ""));
50
- break;
51
- case "boolean":
52
- zodType = zod.z.boolean().describe((value.description || "") + (value.examples ? `
53
- Examples: ${value.examples.join(", ")}` : ""));
54
- break;
55
- case "array":
56
- zodType = zod.z.array(jsonSchemaPropertiesToTSTypes(value.items)).describe((value.description || "") + (value.examples ? `
57
- Examples: ${value.examples.join(", ")}` : ""));
58
- break;
59
- case "object":
60
- zodType = jsonSchemaToModel(value).describe(
61
- (value.description || "") + (value.examples ? `
62
- Examples: ${value.examples.join(", ")}` : "")
63
- );
64
- break;
65
- case "null":
66
- zodType = zod.z.null().describe(value.description || "");
67
- break;
68
- default:
69
- throw new Error(`Unsupported JSON schema type: ${value.type}`);
70
- }
71
- return zodType;
72
- }
73
- function jsonSchemaToModel(jsonSchema) {
74
- const properties = jsonSchema.properties;
75
- const requiredFields = jsonSchema.required || [];
76
- if (!properties) {
77
- return zod.z.object({});
78
- }
79
- const zodSchema = {};
80
- for (const [key, _] of Object.entries(properties)) {
81
- const value = _;
82
- let zodType;
83
- if (value.anyOf) {
84
- const anyOfTypes = value.anyOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
85
- zodType = zod.z.union(anyOfTypes).describe((value.description || "") + (value.examples ? `
86
- Examples: ${value.examples.join(", ")}` : ""));
87
- } else if (value.allOf) {
88
- const allOfTypes = value.allOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
89
- zodType = zod.z.intersection(
90
- allOfTypes[0],
91
- allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
92
- ).describe((value.description || "") + (value.examples ? `
93
- Examples: ${value.examples.join(", ")}` : ""));
94
- } else {
95
- if (!value.type) {
96
- value.type = "string";
97
- }
98
- zodType = jsonSchemaPropertiesToTSTypes(value);
99
- }
100
- if (value.description) {
101
- zodType = zodType.describe(value.description);
102
- }
103
- if (requiredFields.includes(key)) {
104
- zodSchema[key] = zodType;
105
- } else {
106
- zodSchema[key] = zodType.nullable().optional();
107
- }
108
- }
109
- return zod.z.object(zodSchema);
110
- }
111
- function deepMerge(target, source) {
112
- const output = { ...target };
113
- if (!source) return output;
114
- Object.keys(source).forEach((key) => {
115
- const targetValue = output[key];
116
- const sourceValue = source[key];
117
- if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
118
- output[key] = sourceValue;
119
- } else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
120
- output[key] = deepMerge(targetValue, sourceValue);
121
- } else if (sourceValue !== void 0) {
122
- output[key] = sourceValue;
123
- }
124
- });
125
- return output;
126
- }
127
- async function* maskStreamTags(stream, tag, options = {}) {
128
- const { onStart, onEnd, onMask } = options;
129
- const openTag = `<${tag}>`;
130
- const closeTag = `</${tag}>`;
131
- let buffer = "";
132
- let fullContent = "";
133
- let isMasking = false;
134
- let isBuffering = false;
135
- const trimOutsideDelimiter = (text, delimiter, trim) => {
136
- if (!text.includes(delimiter)) {
137
- return text;
138
- }
139
- const parts = text.split(delimiter);
140
- if (trim === `before-start`) {
141
- return `${delimiter}${parts[1]}`;
142
- }
143
- return `${parts[0]}${delimiter}`;
144
- };
145
- const startsWith = (text, pattern) => {
146
- if (pattern.includes(openTag.substring(0, 3))) {
147
- pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
148
- }
149
- return text.trim().startsWith(pattern.trim());
150
- };
151
- for await (const chunk of stream) {
152
- fullContent += chunk;
153
- if (isBuffering) buffer += chunk;
154
- const chunkHasTag = startsWith(chunk, openTag);
155
- const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
156
- let toYieldBeforeMaskedStartTag = ``;
157
- if (!isMasking && (chunkHasTag || bufferHasTag)) {
158
- isMasking = true;
159
- isBuffering = false;
160
- const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
161
- if (taggedTextToMask !== buffer.trim()) {
162
- toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
163
- }
164
- buffer = "";
165
- onStart?.();
166
- }
167
- if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
168
- isBuffering = true;
169
- buffer += chunk;
170
- continue;
171
- }
172
- if (isBuffering && buffer && !startsWith(openTag, buffer)) {
173
- yield buffer;
174
- buffer = "";
175
- isBuffering = false;
176
- continue;
177
- }
178
- if (isMasking && fullContent.includes(closeTag)) {
179
- onMask?.(chunk);
180
- onEnd?.();
181
- isMasking = false;
182
- const lastFullContent = fullContent;
183
- fullContent = ``;
184
- const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
185
- if (textUntilEndTag !== lastFullContent) {
186
- yield lastFullContent.replace(textUntilEndTag, ``);
187
- }
188
- continue;
189
- }
190
- if (isMasking) {
191
- onMask?.(chunk);
192
- if (toYieldBeforeMaskedStartTag) {
193
- yield toYieldBeforeMaskedStartTag;
194
- }
195
- continue;
196
- }
197
- yield chunk;
198
- }
199
- }
200
- function resolveSerializedZodOutput(schema) {
201
- return Function("z", `"use strict";return (${schema});`)(zod.z);
202
- }
203
- function isVercelTool(tool) {
204
- return !(tool instanceof Tool);
205
- }
206
- function createLogMessageOptions({ agentName, toolName, tool, type }) {
207
- if (!agentName) {
208
- return {
209
- start: `Executing tool ${toolName}`,
210
- error: `Failed tool execution`
211
- };
212
- }
213
- const prefix = `[Agent:${agentName}]`;
214
- const vercelPrefix = isVercelTool(tool) ? "Vercel " : "";
215
- const toolType = type === "toolset" ? "toolset" : "tool";
216
- return {
217
- start: `${prefix} - Executing ${vercelPrefix}${toolType} ${toolName}`,
218
- error: `${prefix} - Failed ${vercelPrefix}${toolType} execution`
219
- };
220
- }
221
- function createExecute(tool, options, logType) {
222
- const { logger, ...rest } = options;
223
- const { start, error } = createLogMessageOptions({
224
- agentName: options.agentName,
225
- toolName: options.name,
226
- tool,
227
- type: logType
228
- });
229
- const execFunction = async (args, execOptions) => {
230
- if (isVercelTool(tool)) {
231
- return tool?.execute?.(args, execOptions) ?? void 0;
232
- }
233
- return tool?.execute?.(
234
- {
235
- context: args,
236
- threadId: options.threadId,
237
- resourceId: options.resourceId,
238
- mastra: options.mastra,
239
- memory: options.memory,
240
- runId: options.runId
241
- },
242
- execOptions
243
- ) ?? void 0;
244
- };
245
- return async (args, execOptions) => {
246
- try {
247
- logger.debug(start, { ...rest, args });
248
- return await execFunction(args, execOptions);
249
- } catch (err) {
250
- logger.error(error, { ...rest, error: err, args });
251
- throw err;
252
- }
253
- };
254
- }
255
- function isZodType(value) {
256
- return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
257
- }
258
- function createDeterministicId(input) {
259
- return crypto.createHash("sha256").update(input).digest("hex").slice(0, 8);
260
- }
261
- function setVercelToolProperties(tool) {
262
- const inputSchema = convertVercelToolParameters(tool);
263
- const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
264
- return {
265
- ...tool,
266
- id: toolId,
267
- inputSchema
268
- };
269
- }
270
- function ensureToolProperties(tools) {
271
- const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
272
- const tool = tools?.[key];
273
- if (tool) {
274
- if (isVercelTool(tool)) {
275
- acc[key] = setVercelToolProperties(tool);
276
- } else {
277
- acc[key] = tool;
278
- }
279
- }
280
- return acc;
281
- }, {});
282
- return toolsWithProperties;
283
- }
284
- function convertVercelToolParameters(tool) {
285
- const schema = tool.parameters ?? zod.z.object({});
286
- return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod__default.default(schema));
287
- }
288
- function makeCoreTool(tool, options, logType) {
289
- const getParameters = () => {
290
- if (isVercelTool(tool)) {
291
- return convertVercelToolParameters(tool);
292
- }
293
- return tool.inputSchema ?? zod.z.object({});
294
- };
295
- return {
296
- description: tool.description,
297
- parameters: getParameters(),
298
- execute: tool.execute ? createExecute(tool, { ...options, description: tool.description }, logType) : void 0
299
- };
300
- }
301
- function createMastraProxy({ mastra, logger }) {
302
- return new Proxy(mastra, {
303
- get(target, prop) {
304
- const hasProp = Reflect.has(target, prop);
305
- if (hasProp) {
306
- const value = Reflect.get(target, prop);
307
- const isFunction = typeof value === "function";
308
- if (isFunction) {
309
- return value.bind(target);
310
- }
311
- return value;
312
- }
313
- if (prop === "logger") {
314
- logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
315
- return Reflect.apply(target.getLogger, target, []);
316
- }
317
- if (prop === "telemetry") {
318
- logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
319
- return Reflect.apply(target.getTelemetry, target, []);
320
- }
321
- if (prop === "storage") {
322
- logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
323
- return Reflect.get(target, "storage");
324
- }
325
- if (prop === "agents") {
326
- logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
327
- return Reflect.apply(target.getAgents, target, []);
328
- }
329
- if (prop === "tts") {
330
- logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
331
- return Reflect.apply(target.getTTS, target, []);
332
- }
333
- if (prop === "vectors") {
334
- logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
335
- return Reflect.apply(target.getVectors, target, []);
336
- }
337
- if (prop === "memory") {
338
- logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
339
- return Reflect.get(target, "memory");
340
- }
341
- return Reflect.get(target, prop);
342
- }
343
- });
344
- }
345
-
346
- exports.createMastraProxy = createMastraProxy;
347
- exports.deepMerge = deepMerge;
348
- exports.delay = delay;
349
- exports.ensureToolProperties = ensureToolProperties;
350
- exports.isVercelTool = isVercelTool;
351
- exports.jsonSchemaPropertiesToTSTypes = jsonSchemaPropertiesToTSTypes;
352
- exports.jsonSchemaToModel = jsonSchemaToModel;
353
- exports.makeCoreTool = makeCoreTool;
354
- exports.maskStreamTags = maskStreamTags;
355
- exports.resolveSerializedZodOutput = resolveSerializedZodOutput;
7
+ Object.defineProperty(exports, "createMastraProxy", {
8
+ enumerable: true,
9
+ get: function () { return chunk43Y7WG5W_cjs.createMastraProxy; }
10
+ });
11
+ Object.defineProperty(exports, "deepMerge", {
12
+ enumerable: true,
13
+ get: function () { return chunk43Y7WG5W_cjs.deepMerge; }
14
+ });
15
+ Object.defineProperty(exports, "delay", {
16
+ enumerable: true,
17
+ get: function () { return chunk43Y7WG5W_cjs.delay; }
18
+ });
19
+ Object.defineProperty(exports, "ensureToolProperties", {
20
+ enumerable: true,
21
+ get: function () { return chunk43Y7WG5W_cjs.ensureToolProperties; }
22
+ });
23
+ Object.defineProperty(exports, "isVercelTool", {
24
+ enumerable: true,
25
+ get: function () { return chunk43Y7WG5W_cjs.isVercelTool; }
26
+ });
27
+ Object.defineProperty(exports, "jsonSchemaPropertiesToTSTypes", {
28
+ enumerable: true,
29
+ get: function () { return chunk43Y7WG5W_cjs.jsonSchemaPropertiesToTSTypes; }
30
+ });
31
+ Object.defineProperty(exports, "jsonSchemaToModel", {
32
+ enumerable: true,
33
+ get: function () { return chunk43Y7WG5W_cjs.jsonSchemaToModel; }
34
+ });
35
+ Object.defineProperty(exports, "makeCoreTool", {
36
+ enumerable: true,
37
+ get: function () { return chunk43Y7WG5W_cjs.makeCoreTool; }
38
+ });
39
+ Object.defineProperty(exports, "maskStreamTags", {
40
+ enumerable: true,
41
+ get: function () { return chunk43Y7WG5W_cjs.maskStreamTags; }
42
+ });
43
+ Object.defineProperty(exports, "resolveSerializedZodOutput", {
44
+ enumerable: true,
45
+ get: function () { return chunk43Y7WG5W_cjs.resolveSerializedZodOutput; }
46
+ });
package/dist/utils.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { MastraTTS } from './tts/index.cjs';
2
2
  import { MastraVector } from './vector/index.cjs';
3
- import { V as VercelTool, T as ToolAction, a as ToolsInput, M as Mastra, b as MastraPrimitives, c as MastraMemory, C as CoreTool, A as Agent, W as Workflow } from './base-CMEKtEnE.cjs';
3
+ import { V as VercelTool, T as ToolAction, a as ToolsInput, M as Mastra, b as MastraPrimitives, c as MastraMemory, C as CoreTool, A as Agent, W as Workflow, S as Step, d as StepExecutionContext, e as WorkflowContext } from './base-CIPKleAU.cjs';
4
+ import { M as Metric } from './types-CwTG2XyQ.cjs';
4
5
  import { z, ZodObject } from 'zod';
5
6
  import { L as Logger } from './index-mKY1XrpK.cjs';
6
- import { M as Metric } from './types-CwTG2XyQ.cjs';
7
7
  import './base-DboIg_Cd.cjs';
8
8
  import './vector/filter/index.cjs';
9
9
  import 'ai';
@@ -88,6 +88,6 @@ declare function makeCoreTool(tool: ToolToConvert, options: ToolOptions, logType
88
88
  declare function createMastraProxy({ mastra, logger }: {
89
89
  mastra: Mastra;
90
90
  logger: Logger;
91
- }): Mastra<Record<string, Agent<any, Record<string, Metric>>>, Record<string, Workflow<any, any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger>;
91
+ }): Mastra<Record<string, Agent<any, Record<string, Metric>>>, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[]>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger>;
92
92
 
93
93
  export { type TagMaskOptions, createMastraProxy, deepMerge, delay, ensureToolProperties, isVercelTool, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, makeCoreTool, maskStreamTags, resolveSerializedZodOutput };
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { MastraTTS } from './tts/index.js';
2
2
  import { MastraVector } from './vector/index.js';
3
- import { V as VercelTool, T as ToolAction, a as ToolsInput, M as Mastra, b as MastraPrimitives, c as MastraMemory, C as CoreTool, A as Agent, W as Workflow } from './base-B78F6w8S.js';
3
+ import { V as VercelTool, T as ToolAction, a as ToolsInput, M as Mastra, b as MastraPrimitives, c as MastraMemory, C as CoreTool, A as Agent, W as Workflow, S as Step, d as StepExecutionContext, e as WorkflowContext } from './base-C_Oq53qk.js';
4
+ import { M as Metric } from './types-CwTG2XyQ.js';
4
5
  import { z, ZodObject } from 'zod';
5
6
  import { L as Logger } from './index-mKY1XrpK.js';
6
- import { M as Metric } from './types-CwTG2XyQ.js';
7
7
  import './base-BZViaFTt.js';
8
8
  import './vector/filter/index.js';
9
9
  import 'ai';
@@ -88,6 +88,6 @@ declare function makeCoreTool(tool: ToolToConvert, options: ToolOptions, logType
88
88
  declare function createMastraProxy({ mastra, logger }: {
89
89
  mastra: Mastra;
90
90
  logger: Logger;
91
- }): Mastra<Record<string, Agent<any, Record<string, Metric>>>, Record<string, Workflow<any, any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger>;
91
+ }): Mastra<Record<string, Agent<any, Record<string, Metric>>>, Record<string, Workflow<Step<string, any, any, StepExecutionContext<any, WorkflowContext<any, Step<string, any, any, any>[]>>>[], any>>, Record<string, MastraVector>, Record<string, MastraTTS>, Logger>;
92
92
 
93
93
  export { type TagMaskOptions, createMastraProxy, deepMerge, delay, ensureToolProperties, isVercelTool, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, makeCoreTool, maskStreamTags, resolveSerializedZodOutput };
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- export { createMastraProxy, deepMerge, delay, ensureToolProperties, isVercelTool, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, makeCoreTool, maskStreamTags, resolveSerializedZodOutput } from './chunk-IM7CM3DU.js';
1
+ export { createMastraProxy, deepMerge, delay, ensureToolProperties, isVercelTool, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, makeCoreTool, maskStreamTags, resolveSerializedZodOutput } from './chunk-4Y74D74B.js';
@@ -1,192 +1,10 @@
1
1
  'use strict';
2
2
 
3
- // src/vector/filter/base.ts
4
- var BaseFilterTranslator = class _BaseFilterTranslator {
5
- /**
6
- * Operator type checks
7
- */
8
- isOperator(key) {
9
- return key.startsWith("$");
10
- }
11
- static BASIC_OPERATORS = ["$eq", "$ne"];
12
- static NUMERIC_OPERATORS = ["$gt", "$gte", "$lt", "$lte"];
13
- static ARRAY_OPERATORS = ["$in", "$nin", "$all", "$elemMatch"];
14
- static LOGICAL_OPERATORS = ["$and", "$or", "$not", "$nor"];
15
- static ELEMENT_OPERATORS = ["$exists"];
16
- static REGEX_OPERATORS = ["$regex", "$options"];
17
- static DEFAULT_OPERATORS = {
18
- logical: _BaseFilterTranslator.LOGICAL_OPERATORS,
19
- basic: _BaseFilterTranslator.BASIC_OPERATORS,
20
- numeric: _BaseFilterTranslator.NUMERIC_OPERATORS,
21
- array: _BaseFilterTranslator.ARRAY_OPERATORS,
22
- element: _BaseFilterTranslator.ELEMENT_OPERATORS,
23
- regex: _BaseFilterTranslator.REGEX_OPERATORS
24
- };
25
- isLogicalOperator(key) {
26
- return _BaseFilterTranslator.DEFAULT_OPERATORS.logical.includes(key);
27
- }
28
- isBasicOperator(key) {
29
- return _BaseFilterTranslator.DEFAULT_OPERATORS.basic.includes(key);
30
- }
31
- isNumericOperator(key) {
32
- return _BaseFilterTranslator.DEFAULT_OPERATORS.numeric.includes(key);
33
- }
34
- isArrayOperator(key) {
35
- return _BaseFilterTranslator.DEFAULT_OPERATORS.array.includes(key);
36
- }
37
- isElementOperator(key) {
38
- return _BaseFilterTranslator.DEFAULT_OPERATORS.element.includes(key);
39
- }
40
- isRegexOperator(key) {
41
- return _BaseFilterTranslator.DEFAULT_OPERATORS.regex.includes(key);
42
- }
43
- isFieldOperator(key) {
44
- return this.isOperator(key) && !this.isLogicalOperator(key);
45
- }
46
- isCustomOperator(key) {
47
- const support = this.getSupportedOperators();
48
- return support.custom?.includes(key) ?? false;
49
- }
50
- getSupportedOperators() {
51
- return _BaseFilterTranslator.DEFAULT_OPERATORS;
52
- }
53
- isValidOperator(key) {
54
- const support = this.getSupportedOperators();
55
- const allSupported = Object.values(support).flat();
56
- return allSupported.includes(key);
57
- }
58
- /**
59
- * Value normalization for comparison operators
60
- */
61
- normalizeComparisonValue(value) {
62
- if (value instanceof Date) {
63
- return value.toISOString();
64
- }
65
- if (typeof value === "number" && Object.is(value, -0)) {
66
- return 0;
67
- }
68
- return value;
69
- }
70
- /**
71
- * Helper method to simulate $all operator using $and + $eq when needed.
72
- * Some vector stores don't support $all natively.
73
- */
74
- simulateAllOperator(field, values) {
75
- return {
76
- $and: values.map((value) => ({
77
- [field]: { $in: [this.normalizeComparisonValue(value)] }
78
- }))
79
- };
80
- }
81
- /**
82
- * Utility functions for type checking
83
- */
84
- isPrimitive(value) {
85
- return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
86
- }
87
- isRegex(value) {
88
- return value instanceof RegExp;
89
- }
90
- isEmpty(obj) {
91
- return obj === null || obj === void 0 || typeof obj === "object" && Object.keys(obj).length === 0;
92
- }
93
- static ErrorMessages = {
94
- UNSUPPORTED_OPERATOR: (op) => `Unsupported operator: ${op}`,
95
- INVALID_LOGICAL_OPERATOR_LOCATION: (op, path) => `Logical operator ${op} cannot be used at field level: ${path}`,
96
- NOT_REQUIRES_OBJECT: `$not operator requires an object`,
97
- NOT_CANNOT_BE_EMPTY: `$not operator cannot be empty`,
98
- INVALID_LOGICAL_OPERATOR_CONTENT: (path) => `Logical operators must contain field conditions, not direct operators: ${path}`,
99
- INVALID_TOP_LEVEL_OPERATOR: (op) => `Invalid top-level operator: ${op}`,
100
- ELEM_MATCH_REQUIRES_OBJECT: `$elemMatch requires an object with conditions`
101
- };
102
- /**
103
- * Helper to handle array value normalization consistently
104
- */
105
- normalizeArrayValues(values) {
106
- return values.map((value) => this.normalizeComparisonValue(value));
107
- }
108
- validateFilter(filter) {
109
- const validation = this.validateFilterSupport(filter);
110
- if (!validation.supported) {
111
- throw new Error(validation.messages.join(", "));
112
- }
113
- }
114
- /**
115
- * Validates if a filter structure is supported by the specific vector DB
116
- * and returns detailed validation information.
117
- */
118
- validateFilterSupport(node, path = "") {
119
- const messages = [];
120
- if (this.isPrimitive(node) || this.isEmpty(node)) {
121
- return { supported: true, messages: [] };
122
- }
123
- if (Array.isArray(node)) {
124
- const arrayResults = node.map((item) => this.validateFilterSupport(item, path));
125
- const arrayMessages = arrayResults.flatMap((r) => r.messages);
126
- return {
127
- supported: arrayResults.every((r) => r.supported),
128
- messages: arrayMessages
129
- };
130
- }
131
- const nodeObj = node;
132
- let isSupported = true;
133
- for (const [key, value] of Object.entries(nodeObj)) {
134
- const newPath = path ? `${path}.${key}` : key;
135
- if (this.isOperator(key)) {
136
- if (!this.isValidOperator(key)) {
137
- isSupported = false;
138
- messages.push(_BaseFilterTranslator.ErrorMessages.UNSUPPORTED_OPERATOR(key));
139
- continue;
140
- }
141
- if (!path && !this.isLogicalOperator(key)) {
142
- isSupported = false;
143
- messages.push(_BaseFilterTranslator.ErrorMessages.INVALID_TOP_LEVEL_OPERATOR(key));
144
- continue;
145
- }
146
- if (key === "$elemMatch" && (typeof value !== "object" || Array.isArray(value))) {
147
- isSupported = false;
148
- messages.push(_BaseFilterTranslator.ErrorMessages.ELEM_MATCH_REQUIRES_OBJECT);
149
- continue;
150
- }
151
- if (this.isLogicalOperator(key)) {
152
- if (key === "$not") {
153
- if (Array.isArray(value) || typeof value !== "object") {
154
- isSupported = false;
155
- messages.push(_BaseFilterTranslator.ErrorMessages.NOT_REQUIRES_OBJECT);
156
- continue;
157
- }
158
- if (this.isEmpty(value)) {
159
- isSupported = false;
160
- messages.push(_BaseFilterTranslator.ErrorMessages.NOT_CANNOT_BE_EMPTY);
161
- continue;
162
- }
163
- continue;
164
- }
165
- if (path && !this.isLogicalOperator(path.split(".").pop())) {
166
- isSupported = false;
167
- messages.push(_BaseFilterTranslator.ErrorMessages.INVALID_LOGICAL_OPERATOR_LOCATION(key, newPath));
168
- continue;
169
- }
170
- if (Array.isArray(value)) {
171
- const hasDirectOperators = value.some(
172
- (item) => typeof item === "object" && Object.keys(item).length === 1 && this.isFieldOperator(Object.keys(item)[0])
173
- );
174
- if (hasDirectOperators) {
175
- isSupported = false;
176
- messages.push(_BaseFilterTranslator.ErrorMessages.INVALID_LOGICAL_OPERATOR_CONTENT(newPath));
177
- continue;
178
- }
179
- }
180
- }
181
- }
182
- const nestedValidation = this.validateFilterSupport(value, newPath);
183
- if (!nestedValidation.supported) {
184
- isSupported = false;
185
- messages.push(...nestedValidation.messages);
186
- }
187
- }
188
- return { supported: isSupported, messages };
189
- }
190
- };
3
+ var chunkYK3XJ52U_cjs = require('../../chunk-YK3XJ52U.cjs');
191
4
 
192
- exports.BaseFilterTranslator = BaseFilterTranslator;
5
+
6
+
7
+ Object.defineProperty(exports, "BaseFilterTranslator", {
8
+ enumerable: true,
9
+ get: function () { return chunkYK3XJ52U_cjs.BaseFilterTranslator; }
10
+ });