@mastra/core 0.5.0-alpha.8 → 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.
- package/dist/agent/index.cjs +3 -2100
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/{base-CTdONy0_.d.cts → base-CIPKleAU.d.cts} +103 -70
- package/dist/{base-DIn_km7X.d.ts → base-C_Oq53qk.d.ts} +103 -70
- package/dist/base.cjs +5 -140
- package/dist/bundler/index.cjs +5 -160
- package/dist/chunk-2W2GYEYQ.cjs +25 -0
- package/dist/chunk-3ASEZT7U.cjs +1586 -0
- package/dist/chunk-43Y7WG5W.cjs +335 -0
- package/dist/{chunk-HBHPTMAC.js → chunk-4Y74D74B.js} +46 -6
- package/dist/chunk-ENT7U27Y.cjs +37 -0
- package/dist/chunk-F5UYWPV4.cjs +14 -0
- package/dist/chunk-FL3GQXQ2.cjs +218 -0
- package/dist/chunk-FRQFWZDN.cjs +2 -0
- package/dist/chunk-GXQRMKSN.cjs +367 -0
- package/dist/chunk-HJPMYDWO.cjs +37 -0
- package/dist/chunk-IIWRJFLQ.cjs +51 -0
- package/dist/chunk-KFQ7Z3PO.cjs +347 -0
- package/dist/{chunk-SWDQYPJS.js → chunk-KP5UAFLN.js} +3 -2
- package/dist/chunk-KPKFLQFR.cjs +12 -0
- package/dist/{chunk-RRJB4TCC.js → chunk-MLFXOST6.js} +1 -1
- package/dist/{chunk-KBSR2LLT.js → chunk-OD7ZMKHY.js} +176 -63
- package/dist/chunk-OTFLHXHZ.cjs +65 -0
- package/dist/chunk-RWTSGWWL.cjs +81 -0
- package/dist/chunk-ST5RMVLG.cjs +87 -0
- package/dist/chunk-SYQ7NK2E.cjs +24 -0
- package/dist/chunk-UZNQG7QO.cjs +1868 -0
- package/dist/chunk-V5ORZPFW.cjs +38 -0
- package/dist/chunk-VA4P7QJT.cjs +443 -0
- package/dist/chunk-WB2HREXE.cjs +166 -0
- package/dist/chunk-WOMOGDGR.cjs +691 -0
- package/dist/chunk-XB2TJ7LX.cjs +408 -0
- package/dist/{chunk-QABMKXI3.js → chunk-XF2FMJYK.js} +1 -1
- package/dist/chunk-XLSROQ26.cjs +91 -0
- package/dist/chunk-YK3XJ52U.cjs +192 -0
- package/dist/{chunk-SF5GHHOQ.js → chunk-YPD6BQIM.js} +121 -93
- package/dist/deployer/index.cjs +5 -167
- package/dist/eval/index.cjs +9 -105
- package/dist/eval/index.d.cts +1 -1
- package/dist/eval/index.d.ts +1 -1
- package/dist/hooks/index.cjs +14 -83
- package/dist/index.cjs +253 -7470
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -7
- package/dist/integration/index.cjs +9 -108
- package/dist/integration/index.d.cts +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/logger/index.cjs +33 -161
- package/dist/mastra/index.cjs +3 -1755
- package/dist/mastra/index.d.cts +1 -1
- package/dist/mastra/index.d.ts +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -2050
- package/dist/memory/index.d.cts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/relevance/index.cjs +10 -2161
- package/dist/relevance/index.d.cts +19 -2
- package/dist/relevance/index.d.ts +19 -2
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.cjs +29 -367
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/libsql/index.cjs +9 -798
- package/dist/storage/libsql/index.d.cts +1 -1
- package/dist/storage/libsql/index.d.ts +1 -1
- package/dist/telemetry/index.cjs +21 -408
- package/dist/telemetry/index.d.cts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.cjs +11 -22
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/tts/index.cjs +3 -328
- package/dist/utils.cjs +41 -309
- package/dist/utils.d.cts +10 -4
- package/dist/utils.d.ts +10 -4
- package/dist/utils.js +1 -1
- package/dist/vector/filter/index.cjs +7 -189
- package/dist/vector/index.cjs +5 -172
- package/dist/vector/libsql/index.cjs +9 -1047
- package/dist/voice/index.cjs +8 -306
- package/dist/workflows/index.cjs +65 -1925
- package/dist/workflows/index.d.cts +4 -3
- package/dist/workflows/index.d.ts +4 -3
- package/dist/workflows/index.js +1 -1
- package/package.json +27 -27
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2W2GYEYQ_cjs = require('./chunk-2W2GYEYQ.cjs');
|
|
4
|
+
var crypto = require('crypto');
|
|
5
|
+
var jsonSchemaToZod = require('json-schema-to-zod');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
|
|
11
|
+
|
|
12
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
13
|
+
function jsonSchemaPropertiesToTSTypes(value) {
|
|
14
|
+
if (!value.type) {
|
|
15
|
+
return zod.z.object({});
|
|
16
|
+
}
|
|
17
|
+
let zodType;
|
|
18
|
+
switch (value.type) {
|
|
19
|
+
case "string":
|
|
20
|
+
zodType = zod.z.string().describe((value.description || "") + (value.examples ? `
|
|
21
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
22
|
+
break;
|
|
23
|
+
case "number":
|
|
24
|
+
zodType = zod.z.number().describe((value.description || "") + (value.examples ? `
|
|
25
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
26
|
+
break;
|
|
27
|
+
case "integer":
|
|
28
|
+
zodType = zod.z.number().int().describe((value.description || "") + (value.examples ? `
|
|
29
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
30
|
+
break;
|
|
31
|
+
case "boolean":
|
|
32
|
+
zodType = zod.z.boolean().describe((value.description || "") + (value.examples ? `
|
|
33
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
34
|
+
break;
|
|
35
|
+
case "array":
|
|
36
|
+
zodType = zod.z.array(jsonSchemaPropertiesToTSTypes(value.items)).describe((value.description || "") + (value.examples ? `
|
|
37
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
38
|
+
break;
|
|
39
|
+
case "object":
|
|
40
|
+
zodType = jsonSchemaToModel(value).describe(
|
|
41
|
+
(value.description || "") + (value.examples ? `
|
|
42
|
+
Examples: ${value.examples.join(", ")}` : "")
|
|
43
|
+
);
|
|
44
|
+
break;
|
|
45
|
+
case "null":
|
|
46
|
+
zodType = zod.z.null().describe(value.description || "");
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
50
|
+
}
|
|
51
|
+
return zodType;
|
|
52
|
+
}
|
|
53
|
+
function jsonSchemaToModel(jsonSchema) {
|
|
54
|
+
const properties = jsonSchema.properties;
|
|
55
|
+
const requiredFields = jsonSchema.required || [];
|
|
56
|
+
if (!properties) {
|
|
57
|
+
return zod.z.object({});
|
|
58
|
+
}
|
|
59
|
+
const zodSchema = {};
|
|
60
|
+
for (const [key, _] of Object.entries(properties)) {
|
|
61
|
+
const value = _;
|
|
62
|
+
let zodType;
|
|
63
|
+
if (value.anyOf) {
|
|
64
|
+
const anyOfTypes = value.anyOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
|
|
65
|
+
zodType = zod.z.union(anyOfTypes).describe((value.description || "") + (value.examples ? `
|
|
66
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
67
|
+
} else if (value.allOf) {
|
|
68
|
+
const allOfTypes = value.allOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
|
|
69
|
+
zodType = zod.z.intersection(
|
|
70
|
+
allOfTypes[0],
|
|
71
|
+
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
72
|
+
).describe((value.description || "") + (value.examples ? `
|
|
73
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
74
|
+
} else {
|
|
75
|
+
if (!value.type) {
|
|
76
|
+
value.type = "string";
|
|
77
|
+
}
|
|
78
|
+
zodType = jsonSchemaPropertiesToTSTypes(value);
|
|
79
|
+
}
|
|
80
|
+
if (value.description) {
|
|
81
|
+
zodType = zodType.describe(value.description);
|
|
82
|
+
}
|
|
83
|
+
if (requiredFields.includes(key)) {
|
|
84
|
+
zodSchema[key] = zodType;
|
|
85
|
+
} else {
|
|
86
|
+
zodSchema[key] = zodType.nullable().optional();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return zod.z.object(zodSchema);
|
|
90
|
+
}
|
|
91
|
+
function deepMerge(target, source) {
|
|
92
|
+
const output = { ...target };
|
|
93
|
+
if (!source) return output;
|
|
94
|
+
Object.keys(source).forEach((key) => {
|
|
95
|
+
const targetValue = output[key];
|
|
96
|
+
const sourceValue = source[key];
|
|
97
|
+
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
|
98
|
+
output[key] = sourceValue;
|
|
99
|
+
} else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
|
|
100
|
+
output[key] = deepMerge(targetValue, sourceValue);
|
|
101
|
+
} else if (sourceValue !== void 0) {
|
|
102
|
+
output[key] = sourceValue;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return output;
|
|
106
|
+
}
|
|
107
|
+
async function* maskStreamTags(stream, tag, options = {}) {
|
|
108
|
+
const { onStart, onEnd, onMask } = options;
|
|
109
|
+
const openTag = `<${tag}>`;
|
|
110
|
+
const closeTag = `</${tag}>`;
|
|
111
|
+
let buffer = "";
|
|
112
|
+
let fullContent = "";
|
|
113
|
+
let isMasking = false;
|
|
114
|
+
let isBuffering = false;
|
|
115
|
+
const trimOutsideDelimiter = (text, delimiter, trim) => {
|
|
116
|
+
if (!text.includes(delimiter)) {
|
|
117
|
+
return text;
|
|
118
|
+
}
|
|
119
|
+
const parts = text.split(delimiter);
|
|
120
|
+
if (trim === `before-start`) {
|
|
121
|
+
return `${delimiter}${parts[1]}`;
|
|
122
|
+
}
|
|
123
|
+
return `${parts[0]}${delimiter}`;
|
|
124
|
+
};
|
|
125
|
+
const startsWith = (text, pattern) => {
|
|
126
|
+
if (pattern.includes(openTag.substring(0, 3))) {
|
|
127
|
+
pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
|
|
128
|
+
}
|
|
129
|
+
return text.trim().startsWith(pattern.trim());
|
|
130
|
+
};
|
|
131
|
+
for await (const chunk of stream) {
|
|
132
|
+
fullContent += chunk;
|
|
133
|
+
if (isBuffering) buffer += chunk;
|
|
134
|
+
const chunkHasTag = startsWith(chunk, openTag);
|
|
135
|
+
const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
|
|
136
|
+
let toYieldBeforeMaskedStartTag = ``;
|
|
137
|
+
if (!isMasking && (chunkHasTag || bufferHasTag)) {
|
|
138
|
+
isMasking = true;
|
|
139
|
+
isBuffering = false;
|
|
140
|
+
const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
|
|
141
|
+
if (taggedTextToMask !== buffer.trim()) {
|
|
142
|
+
toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
|
|
143
|
+
}
|
|
144
|
+
buffer = "";
|
|
145
|
+
onStart?.();
|
|
146
|
+
}
|
|
147
|
+
if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
|
|
148
|
+
isBuffering = true;
|
|
149
|
+
buffer += chunk;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (isBuffering && buffer && !startsWith(openTag, buffer)) {
|
|
153
|
+
yield buffer;
|
|
154
|
+
buffer = "";
|
|
155
|
+
isBuffering = false;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (isMasking && fullContent.includes(closeTag)) {
|
|
159
|
+
onMask?.(chunk);
|
|
160
|
+
onEnd?.();
|
|
161
|
+
isMasking = false;
|
|
162
|
+
const lastFullContent = fullContent;
|
|
163
|
+
fullContent = ``;
|
|
164
|
+
const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
|
|
165
|
+
if (textUntilEndTag !== lastFullContent) {
|
|
166
|
+
yield lastFullContent.replace(textUntilEndTag, ``);
|
|
167
|
+
}
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (isMasking) {
|
|
171
|
+
onMask?.(chunk);
|
|
172
|
+
if (toYieldBeforeMaskedStartTag) {
|
|
173
|
+
yield toYieldBeforeMaskedStartTag;
|
|
174
|
+
}
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
yield chunk;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function resolveSerializedZodOutput(schema) {
|
|
181
|
+
return Function("z", `"use strict";return (${schema});`)(zod.z);
|
|
182
|
+
}
|
|
183
|
+
function isVercelTool(tool) {
|
|
184
|
+
return !(tool instanceof chunk2W2GYEYQ_cjs.Tool);
|
|
185
|
+
}
|
|
186
|
+
function createLogMessageOptions({ agentName, toolName, tool, type }) {
|
|
187
|
+
if (!agentName) {
|
|
188
|
+
return {
|
|
189
|
+
start: `Executing tool ${toolName}`,
|
|
190
|
+
error: `Failed tool execution`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const prefix = `[Agent:${agentName}]`;
|
|
194
|
+
const vercelPrefix = isVercelTool(tool) ? "Vercel " : "";
|
|
195
|
+
const toolType = type === "toolset" ? "toolset" : "tool";
|
|
196
|
+
return {
|
|
197
|
+
start: `${prefix} - Executing ${vercelPrefix}${toolType} ${toolName}`,
|
|
198
|
+
error: `${prefix} - Failed ${vercelPrefix}${toolType} execution`
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function createExecute(tool, options, logType) {
|
|
202
|
+
const { logger, mastra: _mastra, memory: _memory, ...rest } = options;
|
|
203
|
+
const { start, error } = createLogMessageOptions({
|
|
204
|
+
agentName: options.agentName,
|
|
205
|
+
toolName: options.name,
|
|
206
|
+
tool,
|
|
207
|
+
type: logType
|
|
208
|
+
});
|
|
209
|
+
const execFunction = async (args, execOptions) => {
|
|
210
|
+
if (isVercelTool(tool)) {
|
|
211
|
+
return tool?.execute?.(args, execOptions) ?? void 0;
|
|
212
|
+
}
|
|
213
|
+
return tool?.execute?.(
|
|
214
|
+
{
|
|
215
|
+
context: args,
|
|
216
|
+
threadId: options.threadId,
|
|
217
|
+
resourceId: options.resourceId,
|
|
218
|
+
mastra: options.mastra,
|
|
219
|
+
memory: options.memory,
|
|
220
|
+
runId: options.runId
|
|
221
|
+
},
|
|
222
|
+
execOptions
|
|
223
|
+
) ?? void 0;
|
|
224
|
+
};
|
|
225
|
+
return async (args, execOptions) => {
|
|
226
|
+
try {
|
|
227
|
+
logger.debug(start, { ...rest, args });
|
|
228
|
+
return await execFunction(args, execOptions);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
logger.error(error, { ...rest, error: err, args });
|
|
231
|
+
throw err;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function isZodType(value) {
|
|
236
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
237
|
+
}
|
|
238
|
+
function createDeterministicId(input) {
|
|
239
|
+
return crypto.createHash("sha256").update(input).digest("hex").slice(0, 8);
|
|
240
|
+
}
|
|
241
|
+
function setVercelToolProperties(tool) {
|
|
242
|
+
const inputSchema = convertVercelToolParameters(tool);
|
|
243
|
+
const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
|
|
244
|
+
return {
|
|
245
|
+
...tool,
|
|
246
|
+
id: toolId,
|
|
247
|
+
inputSchema
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function ensureToolProperties(tools) {
|
|
251
|
+
const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
|
|
252
|
+
const tool = tools?.[key];
|
|
253
|
+
if (tool) {
|
|
254
|
+
if (isVercelTool(tool)) {
|
|
255
|
+
acc[key] = setVercelToolProperties(tool);
|
|
256
|
+
} else {
|
|
257
|
+
acc[key] = tool;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return acc;
|
|
261
|
+
}, {});
|
|
262
|
+
return toolsWithProperties;
|
|
263
|
+
}
|
|
264
|
+
function convertVercelToolParameters(tool) {
|
|
265
|
+
const schema = tool.parameters ?? zod.z.object({});
|
|
266
|
+
return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod__default.default(schema));
|
|
267
|
+
}
|
|
268
|
+
function makeCoreTool(tool, options, logType) {
|
|
269
|
+
const getParameters = () => {
|
|
270
|
+
if (isVercelTool(tool)) {
|
|
271
|
+
return convertVercelToolParameters(tool);
|
|
272
|
+
}
|
|
273
|
+
return tool.inputSchema ?? zod.z.object({});
|
|
274
|
+
};
|
|
275
|
+
return {
|
|
276
|
+
description: tool.description,
|
|
277
|
+
parameters: getParameters(),
|
|
278
|
+
execute: tool.execute ? createExecute(tool, { ...options, description: tool.description }, logType) : void 0
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function createMastraProxy({ mastra, logger }) {
|
|
282
|
+
return new Proxy(mastra, {
|
|
283
|
+
get(target, prop) {
|
|
284
|
+
const hasProp = Reflect.has(target, prop);
|
|
285
|
+
if (hasProp) {
|
|
286
|
+
const value = Reflect.get(target, prop);
|
|
287
|
+
const isFunction = typeof value === "function";
|
|
288
|
+
if (isFunction) {
|
|
289
|
+
return value.bind(target);
|
|
290
|
+
}
|
|
291
|
+
return value;
|
|
292
|
+
}
|
|
293
|
+
if (prop === "logger") {
|
|
294
|
+
logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
|
|
295
|
+
return Reflect.apply(target.getLogger, target, []);
|
|
296
|
+
}
|
|
297
|
+
if (prop === "telemetry") {
|
|
298
|
+
logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
|
|
299
|
+
return Reflect.apply(target.getTelemetry, target, []);
|
|
300
|
+
}
|
|
301
|
+
if (prop === "storage") {
|
|
302
|
+
logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
|
|
303
|
+
return Reflect.get(target, "storage");
|
|
304
|
+
}
|
|
305
|
+
if (prop === "agents") {
|
|
306
|
+
logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
|
|
307
|
+
return Reflect.apply(target.getAgents, target, []);
|
|
308
|
+
}
|
|
309
|
+
if (prop === "tts") {
|
|
310
|
+
logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
|
|
311
|
+
return Reflect.apply(target.getTTS, target, []);
|
|
312
|
+
}
|
|
313
|
+
if (prop === "vectors") {
|
|
314
|
+
logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
|
|
315
|
+
return Reflect.apply(target.getVectors, target, []);
|
|
316
|
+
}
|
|
317
|
+
if (prop === "memory") {
|
|
318
|
+
logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
|
|
319
|
+
return Reflect.get(target, "memory");
|
|
320
|
+
}
|
|
321
|
+
return Reflect.get(target, prop);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
exports.createMastraProxy = createMastraProxy;
|
|
327
|
+
exports.deepMerge = deepMerge;
|
|
328
|
+
exports.delay = delay;
|
|
329
|
+
exports.ensureToolProperties = ensureToolProperties;
|
|
330
|
+
exports.isVercelTool = isVercelTool;
|
|
331
|
+
exports.jsonSchemaPropertiesToTSTypes = jsonSchemaPropertiesToTSTypes;
|
|
332
|
+
exports.jsonSchemaToModel = jsonSchemaToModel;
|
|
333
|
+
exports.makeCoreTool = makeCoreTool;
|
|
334
|
+
exports.maskStreamTags = maskStreamTags;
|
|
335
|
+
exports.resolveSerializedZodOutput = resolveSerializedZodOutput;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Tool } from './chunk-ZINPRHAN.js';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
2
3
|
import jsonSchemaToZod from 'json-schema-to-zod';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
@@ -192,7 +193,7 @@ function createLogMessageOptions({ agentName, toolName, tool, type }) {
|
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
195
|
function createExecute(tool, options, logType) {
|
|
195
|
-
const { logger, ...rest } = options;
|
|
196
|
+
const { logger, mastra: _mastra, memory: _memory, ...rest } = options;
|
|
196
197
|
const { start, error } = createLogMessageOptions({
|
|
197
198
|
agentName: options.agentName,
|
|
198
199
|
toolName: options.name,
|
|
@@ -225,12 +226,45 @@ function createExecute(tool, options, logType) {
|
|
|
225
226
|
}
|
|
226
227
|
};
|
|
227
228
|
}
|
|
229
|
+
function isZodType(value) {
|
|
230
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
231
|
+
}
|
|
232
|
+
function createDeterministicId(input) {
|
|
233
|
+
return createHash("sha256").update(input).digest("hex").slice(0, 8);
|
|
234
|
+
}
|
|
235
|
+
function setVercelToolProperties(tool) {
|
|
236
|
+
const inputSchema = convertVercelToolParameters(tool);
|
|
237
|
+
const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
|
|
238
|
+
return {
|
|
239
|
+
...tool,
|
|
240
|
+
id: toolId,
|
|
241
|
+
inputSchema
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function ensureToolProperties(tools) {
|
|
245
|
+
const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
|
|
246
|
+
const tool = tools?.[key];
|
|
247
|
+
if (tool) {
|
|
248
|
+
if (isVercelTool(tool)) {
|
|
249
|
+
acc[key] = setVercelToolProperties(tool);
|
|
250
|
+
} else {
|
|
251
|
+
acc[key] = tool;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return acc;
|
|
255
|
+
}, {});
|
|
256
|
+
return toolsWithProperties;
|
|
257
|
+
}
|
|
258
|
+
function convertVercelToolParameters(tool) {
|
|
259
|
+
const schema = tool.parameters ?? z.object({});
|
|
260
|
+
return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod(schema));
|
|
261
|
+
}
|
|
228
262
|
function makeCoreTool(tool, options, logType) {
|
|
229
263
|
const getParameters = () => {
|
|
230
264
|
if (isVercelTool(tool)) {
|
|
231
|
-
return
|
|
265
|
+
return convertVercelToolParameters(tool);
|
|
232
266
|
}
|
|
233
|
-
return tool.inputSchema;
|
|
267
|
+
return tool.inputSchema ?? z.object({});
|
|
234
268
|
};
|
|
235
269
|
return {
|
|
236
270
|
description: tool.description,
|
|
@@ -241,8 +275,14 @@ function makeCoreTool(tool, options, logType) {
|
|
|
241
275
|
function createMastraProxy({ mastra, logger }) {
|
|
242
276
|
return new Proxy(mastra, {
|
|
243
277
|
get(target, prop) {
|
|
244
|
-
|
|
245
|
-
|
|
278
|
+
const hasProp = Reflect.has(target, prop);
|
|
279
|
+
if (hasProp) {
|
|
280
|
+
const value = Reflect.get(target, prop);
|
|
281
|
+
const isFunction = typeof value === "function";
|
|
282
|
+
if (isFunction) {
|
|
283
|
+
return value.bind(target);
|
|
284
|
+
}
|
|
285
|
+
return value;
|
|
246
286
|
}
|
|
247
287
|
if (prop === "logger") {
|
|
248
288
|
logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
|
|
@@ -277,4 +317,4 @@ function createMastraProxy({ mastra, logger }) {
|
|
|
277
317
|
});
|
|
278
318
|
}
|
|
279
319
|
|
|
280
|
-
export { createMastraProxy, deepMerge, delay, isVercelTool, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, makeCoreTool, maskStreamTags, resolveSerializedZodOutput };
|
|
320
|
+
export { createMastraProxy, deepMerge, delay, ensureToolProperties, isVercelTool, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, makeCoreTool, maskStreamTags, resolveSerializedZodOutput };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkIIWRJFLQ_cjs = require('./chunk-IIWRJFLQ.cjs');
|
|
4
|
+
|
|
5
|
+
// src/vector/vector.ts
|
|
6
|
+
var MastraVector = class extends chunkIIWRJFLQ_cjs.MastraBase {
|
|
7
|
+
constructor() {
|
|
8
|
+
super({ name: "MastraVector", component: "VECTOR" });
|
|
9
|
+
}
|
|
10
|
+
baseKeys = {
|
|
11
|
+
query: ["queryVector", "topK", "filter", "includeVector"],
|
|
12
|
+
upsert: ["vectors", "metadata", "ids"],
|
|
13
|
+
createIndex: ["dimension", "metric"]
|
|
14
|
+
};
|
|
15
|
+
normalizeArgs(method, [first, ...rest], extendedKeys = []) {
|
|
16
|
+
if (typeof first === "object") {
|
|
17
|
+
return first;
|
|
18
|
+
}
|
|
19
|
+
this.logger.warn(
|
|
20
|
+
`Deprecation Warning: Passing individual arguments to ${method}() is deprecated. Please use an object parameter instead.`
|
|
21
|
+
);
|
|
22
|
+
const baseKeys = this.baseKeys[method] || [];
|
|
23
|
+
const paramKeys = [...baseKeys, ...extendedKeys].slice(0, rest.length);
|
|
24
|
+
return {
|
|
25
|
+
indexName: first,
|
|
26
|
+
...Object.fromEntries(paramKeys.map((key, i) => [key, rest[i]]))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async updateIndexById(_indexName, _id, _update) {
|
|
30
|
+
throw new Error("updateIndexById is not implemented yet");
|
|
31
|
+
}
|
|
32
|
+
async deleteIndexById(_indexName, _id) {
|
|
33
|
+
throw new Error("deleteById is not implemented yet");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.MastraVector = MastraVector;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/storage/constants.ts
|
|
4
|
+
var TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
5
|
+
var TABLE_EVALS = "mastra_evals";
|
|
6
|
+
var TABLE_MESSAGES = "mastra_messages";
|
|
7
|
+
var TABLE_THREADS = "mastra_threads";
|
|
8
|
+
var TABLE_TRACES = "mastra_traces";
|
|
9
|
+
|
|
10
|
+
exports.TABLE_EVALS = TABLE_EVALS;
|
|
11
|
+
exports.TABLE_MESSAGES = TABLE_MESSAGES;
|
|
12
|
+
exports.TABLE_THREADS = TABLE_THREADS;
|
|
13
|
+
exports.TABLE_TRACES = TABLE_TRACES;
|
|
14
|
+
exports.TABLE_WORKFLOW_SNAPSHOT = TABLE_WORKFLOW_SNAPSHOT;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkF5UYWPV4_cjs = require('./chunk-F5UYWPV4.cjs');
|
|
4
|
+
var chunkIIWRJFLQ_cjs = require('./chunk-IIWRJFLQ.cjs');
|
|
5
|
+
|
|
6
|
+
// src/storage/base.ts
|
|
7
|
+
var MastraStorage = class extends chunkIIWRJFLQ_cjs.MastraBase {
|
|
8
|
+
/** @deprecated import from { TABLE_WORKFLOW_SNAPSHOT } '@mastra/core/storage' instead */
|
|
9
|
+
static TABLE_WORKFLOW_SNAPSHOT = chunkF5UYWPV4_cjs.TABLE_WORKFLOW_SNAPSHOT;
|
|
10
|
+
/** @deprecated import from { TABLE_EVALS } '@mastra/core/storage' instead */
|
|
11
|
+
static TABLE_EVALS = chunkF5UYWPV4_cjs.TABLE_EVALS;
|
|
12
|
+
/** @deprecated import from { TABLE_MESSAGES } '@mastra/core/storage' instead */
|
|
13
|
+
static TABLE_MESSAGES = chunkF5UYWPV4_cjs.TABLE_MESSAGES;
|
|
14
|
+
/** @deprecated import from { TABLE_THREADS } '@mastra/core/storage' instead */
|
|
15
|
+
static TABLE_THREADS = chunkF5UYWPV4_cjs.TABLE_THREADS;
|
|
16
|
+
/** @deprecated import { TABLE_TRACES } from '@mastra/core/storage' instead */
|
|
17
|
+
static TABLE_TRACES = chunkF5UYWPV4_cjs.TABLE_TRACES;
|
|
18
|
+
hasInitialized = null;
|
|
19
|
+
shouldCacheInit = true;
|
|
20
|
+
constructor({ name }) {
|
|
21
|
+
super({
|
|
22
|
+
component: "STORAGE",
|
|
23
|
+
name
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async __batchInsert({
|
|
27
|
+
tableName,
|
|
28
|
+
records
|
|
29
|
+
}) {
|
|
30
|
+
await this.init();
|
|
31
|
+
return this.batchInsert({ tableName, records });
|
|
32
|
+
}
|
|
33
|
+
async __getThreadById({ threadId }) {
|
|
34
|
+
await this.init();
|
|
35
|
+
return this.getThreadById({ threadId });
|
|
36
|
+
}
|
|
37
|
+
async __getThreadsByResourceId({ resourceId }) {
|
|
38
|
+
await this.init();
|
|
39
|
+
return this.getThreadsByResourceId({ resourceId });
|
|
40
|
+
}
|
|
41
|
+
async __saveThread({ thread }) {
|
|
42
|
+
await this.init();
|
|
43
|
+
return this.saveThread({ thread });
|
|
44
|
+
}
|
|
45
|
+
async __updateThread({
|
|
46
|
+
id,
|
|
47
|
+
title,
|
|
48
|
+
metadata
|
|
49
|
+
}) {
|
|
50
|
+
await this.init();
|
|
51
|
+
return this.updateThread({ id, title, metadata });
|
|
52
|
+
}
|
|
53
|
+
async __deleteThread({ threadId }) {
|
|
54
|
+
await this.init();
|
|
55
|
+
return this.deleteThread({ threadId });
|
|
56
|
+
}
|
|
57
|
+
async __getMessages({ threadId, selectBy, threadConfig }) {
|
|
58
|
+
await this.init();
|
|
59
|
+
return this.getMessages({ threadId, selectBy, threadConfig });
|
|
60
|
+
}
|
|
61
|
+
async __saveMessages({ messages }) {
|
|
62
|
+
await this.init();
|
|
63
|
+
return this.saveMessages({ messages });
|
|
64
|
+
}
|
|
65
|
+
async __getTraces({
|
|
66
|
+
scope,
|
|
67
|
+
page,
|
|
68
|
+
perPage,
|
|
69
|
+
attributes
|
|
70
|
+
}) {
|
|
71
|
+
await this.init();
|
|
72
|
+
return this.getTraces({ scope, page, perPage, attributes });
|
|
73
|
+
}
|
|
74
|
+
async init() {
|
|
75
|
+
if (this.shouldCacheInit && await this.hasInitialized) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.hasInitialized = Promise.all([
|
|
79
|
+
this.createTable({
|
|
80
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_WORKFLOW_SNAPSHOT,
|
|
81
|
+
schema: {
|
|
82
|
+
workflow_name: {
|
|
83
|
+
type: "text"
|
|
84
|
+
},
|
|
85
|
+
run_id: {
|
|
86
|
+
type: "text"
|
|
87
|
+
},
|
|
88
|
+
snapshot: {
|
|
89
|
+
type: "text"
|
|
90
|
+
},
|
|
91
|
+
createdAt: {
|
|
92
|
+
type: "timestamp"
|
|
93
|
+
},
|
|
94
|
+
updatedAt: {
|
|
95
|
+
type: "timestamp"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
this.createTable({
|
|
100
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_EVALS,
|
|
101
|
+
schema: {
|
|
102
|
+
input: {
|
|
103
|
+
type: "text"
|
|
104
|
+
},
|
|
105
|
+
output: {
|
|
106
|
+
type: "text"
|
|
107
|
+
},
|
|
108
|
+
result: {
|
|
109
|
+
type: "jsonb"
|
|
110
|
+
},
|
|
111
|
+
agent_name: {
|
|
112
|
+
type: "text"
|
|
113
|
+
},
|
|
114
|
+
metric_name: {
|
|
115
|
+
type: "text"
|
|
116
|
+
},
|
|
117
|
+
instructions: {
|
|
118
|
+
type: "text"
|
|
119
|
+
},
|
|
120
|
+
test_info: {
|
|
121
|
+
type: "jsonb",
|
|
122
|
+
nullable: true
|
|
123
|
+
},
|
|
124
|
+
global_run_id: {
|
|
125
|
+
type: "text"
|
|
126
|
+
},
|
|
127
|
+
run_id: {
|
|
128
|
+
type: "text"
|
|
129
|
+
},
|
|
130
|
+
created_at: {
|
|
131
|
+
type: "timestamp"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
this.createTable({
|
|
136
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_THREADS,
|
|
137
|
+
schema: {
|
|
138
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
139
|
+
resourceId: { type: "text", nullable: false },
|
|
140
|
+
title: { type: "text", nullable: false },
|
|
141
|
+
metadata: { type: "text", nullable: true },
|
|
142
|
+
createdAt: { type: "timestamp", nullable: false },
|
|
143
|
+
updatedAt: { type: "timestamp", nullable: false }
|
|
144
|
+
}
|
|
145
|
+
}),
|
|
146
|
+
this.createTable({
|
|
147
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_MESSAGES,
|
|
148
|
+
schema: {
|
|
149
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
150
|
+
thread_id: { type: "text", nullable: false },
|
|
151
|
+
content: { type: "text", nullable: false },
|
|
152
|
+
role: { type: "text", nullable: false },
|
|
153
|
+
type: { type: "text", nullable: false },
|
|
154
|
+
createdAt: { type: "timestamp", nullable: false }
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
this.createTable({
|
|
158
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_TRACES,
|
|
159
|
+
schema: {
|
|
160
|
+
id: { type: "text", nullable: false, primaryKey: true },
|
|
161
|
+
parentSpanId: { type: "text", nullable: true },
|
|
162
|
+
name: { type: "text", nullable: false },
|
|
163
|
+
traceId: { type: "text", nullable: false },
|
|
164
|
+
scope: { type: "text", nullable: false },
|
|
165
|
+
kind: { type: "integer", nullable: false },
|
|
166
|
+
attributes: { type: "jsonb", nullable: true },
|
|
167
|
+
status: { type: "jsonb", nullable: true },
|
|
168
|
+
events: { type: "jsonb", nullable: true },
|
|
169
|
+
links: { type: "jsonb", nullable: true },
|
|
170
|
+
other: { type: "text", nullable: true },
|
|
171
|
+
startTime: { type: "bigint", nullable: false },
|
|
172
|
+
endTime: { type: "bigint", nullable: false },
|
|
173
|
+
createdAt: { type: "timestamp", nullable: false }
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
]).then(() => true);
|
|
177
|
+
await this.hasInitialized;
|
|
178
|
+
}
|
|
179
|
+
async persistWorkflowSnapshot({
|
|
180
|
+
workflowName,
|
|
181
|
+
runId,
|
|
182
|
+
snapshot
|
|
183
|
+
}) {
|
|
184
|
+
await this.init();
|
|
185
|
+
const data = {
|
|
186
|
+
workflow_name: workflowName,
|
|
187
|
+
run_id: runId,
|
|
188
|
+
snapshot,
|
|
189
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
190
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
191
|
+
};
|
|
192
|
+
this.logger.debug("Persisting workflow snapshot", { workflowName, runId, data });
|
|
193
|
+
await this.insert({
|
|
194
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_WORKFLOW_SNAPSHOT,
|
|
195
|
+
record: data
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async loadWorkflowSnapshot({
|
|
199
|
+
workflowName,
|
|
200
|
+
runId
|
|
201
|
+
}) {
|
|
202
|
+
if (!this.hasInitialized) {
|
|
203
|
+
await this.init();
|
|
204
|
+
}
|
|
205
|
+
this.logger.debug("Loading workflow snapshot", { workflowName, runId });
|
|
206
|
+
const d = await this.load({
|
|
207
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_WORKFLOW_SNAPSHOT,
|
|
208
|
+
keys: { workflow_name: workflowName, run_id: runId }
|
|
209
|
+
});
|
|
210
|
+
return d ? d.snapshot : null;
|
|
211
|
+
}
|
|
212
|
+
async __getEvalsByAgentName(agentName, type) {
|
|
213
|
+
await this.init();
|
|
214
|
+
return this.getEvalsByAgentName(agentName, type);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
exports.MastraStorage = MastraStorage;
|