@mastra/core 0.0.0-storage-20250225005900
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/LICENSE +21 -0
- package/README.md +180 -0
- package/dist/agent/index.d.ts +15 -0
- package/dist/agent/index.js +1 -0
- package/dist/base-CHNzbTDj.d.ts +894 -0
- package/dist/base-eWkcLLSb.d.ts +139 -0
- package/dist/base.d.ts +6 -0
- package/dist/base.js +1 -0
- package/dist/bundler/index.d.ts +28 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-4IIE6KIC.js +10 -0
- package/dist/chunk-4ZNSY7J7.js +215 -0
- package/dist/chunk-4ZRHVG25.js +402 -0
- package/dist/chunk-5275WBGX.js +318 -0
- package/dist/chunk-6RDA4JYW.js +49 -0
- package/dist/chunk-BB4KXGBU.js +83 -0
- package/dist/chunk-C6A6W6XS.js +77 -0
- package/dist/chunk-FEBWYMJQ.js +416 -0
- package/dist/chunk-KP5SHTKA.js +145 -0
- package/dist/chunk-N7KZVQDK.js +61 -0
- package/dist/chunk-NDQR6IPC.js +37 -0
- package/dist/chunk-NUDAZEOG.js +35 -0
- package/dist/chunk-ORM3OCHX.js +1367 -0
- package/dist/chunk-PNZK456O.js +88 -0
- package/dist/chunk-QXPUH6PK.js +620 -0
- package/dist/chunk-RG66XEJT.js +8 -0
- package/dist/chunk-SIFBBGY6.js +190 -0
- package/dist/chunk-TCMOYQ74.js +1204 -0
- package/dist/chunk-WIBGG4X6.js +173 -0
- package/dist/chunk-YKDBP67T.js +346 -0
- package/dist/chunk-YUOADWSP.js +22 -0
- package/dist/chunk-Z735LDV7.js +10 -0
- package/dist/chunk-ZDWFBE5L.js +1 -0
- package/dist/chunk-ZINPRHAN.js +22 -0
- package/dist/deployer/index.d.ts +19 -0
- package/dist/deployer/index.js +1 -0
- package/dist/eval/index.d.ts +28 -0
- package/dist/eval/index.js +1 -0
- package/dist/filter/index.d.ts +90 -0
- package/dist/filter/index.js +1 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index-C5uPdbs4.d.ts +90 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +119 -0
- package/dist/integration/index.d.ts +53 -0
- package/dist/integration/index.js +1 -0
- package/dist/llm/index.d.ts +15 -0
- package/dist/llm/index.js +1 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.js +1 -0
- package/dist/mastra/index.d.ts +68 -0
- package/dist/mastra/index.js +1 -0
- package/dist/memory/index.d.ts +15 -0
- package/dist/memory/index.js +1 -0
- package/dist/relevance/index.d.ts +21 -0
- package/dist/relevance/index.js +1 -0
- package/dist/storage/index.d.ts +15 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/libsql/index.d.ts +81 -0
- package/dist/storage/libsql/index.js +1 -0
- package/dist/telemetry/index.d.ts +51 -0
- package/dist/telemetry/index.js +1 -0
- package/dist/telemetry/otel-vendor.d.ts +7 -0
- package/dist/telemetry/otel-vendor.js +7 -0
- package/dist/tools/index.d.ts +29 -0
- package/dist/tools/index.js +1 -0
- package/dist/tts/index.d.ts +28 -0
- package/dist/tts/index.js +1 -0
- package/dist/types-m9RryK9a.d.ts +14 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.js +1 -0
- package/dist/vector/index.d.ts +29 -0
- package/dist/vector/index.js +1 -0
- package/dist/vector/libsql/index.d.ts +29 -0
- package/dist/vector/libsql/index.js +1 -0
- package/dist/voice/index.d.ts +67 -0
- package/dist/voice/index.js +76 -0
- package/dist/workflow-CddifUps.d.ts +92 -0
- package/dist/workflows/index.d.ts +31 -0
- package/dist/workflows/index.js +1 -0
- package/package.json +134 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/utils.ts
|
|
4
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
function jsonSchemaPropertiesToTSTypes(value) {
|
|
6
|
+
if (!value.type) {
|
|
7
|
+
return z.object({});
|
|
8
|
+
}
|
|
9
|
+
let zodType;
|
|
10
|
+
switch (value.type) {
|
|
11
|
+
case "string":
|
|
12
|
+
zodType = z.string().describe((value.description || "") + (value.examples ? `
|
|
13
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
14
|
+
break;
|
|
15
|
+
case "number":
|
|
16
|
+
zodType = z.number().describe((value.description || "") + (value.examples ? `
|
|
17
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
18
|
+
break;
|
|
19
|
+
case "integer":
|
|
20
|
+
zodType = z.number().int().describe((value.description || "") + (value.examples ? `
|
|
21
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
22
|
+
break;
|
|
23
|
+
case "boolean":
|
|
24
|
+
zodType = z.boolean().describe((value.description || "") + (value.examples ? `
|
|
25
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
26
|
+
break;
|
|
27
|
+
case "array":
|
|
28
|
+
zodType = z.array(jsonSchemaPropertiesToTSTypes(value.items)).describe((value.description || "") + (value.examples ? `
|
|
29
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
30
|
+
break;
|
|
31
|
+
case "object":
|
|
32
|
+
zodType = jsonSchemaToModel(value).describe(
|
|
33
|
+
(value.description || "") + (value.examples ? `
|
|
34
|
+
Examples: ${value.examples.join(", ")}` : "")
|
|
35
|
+
);
|
|
36
|
+
break;
|
|
37
|
+
case "null":
|
|
38
|
+
zodType = z.null().describe(value.description || "");
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
42
|
+
}
|
|
43
|
+
return zodType;
|
|
44
|
+
}
|
|
45
|
+
function jsonSchemaToModel(jsonSchema) {
|
|
46
|
+
const properties = jsonSchema.properties;
|
|
47
|
+
const requiredFields = jsonSchema.required || [];
|
|
48
|
+
if (!properties) {
|
|
49
|
+
return z.object({});
|
|
50
|
+
}
|
|
51
|
+
const zodSchema = {};
|
|
52
|
+
for (const [key, _] of Object.entries(properties)) {
|
|
53
|
+
const value = _;
|
|
54
|
+
let zodType;
|
|
55
|
+
if (value.anyOf) {
|
|
56
|
+
const anyOfTypes = value.anyOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
|
|
57
|
+
zodType = z.union(anyOfTypes).describe((value.description || "") + (value.examples ? `
|
|
58
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
59
|
+
} else if (value.allOf) {
|
|
60
|
+
const allOfTypes = value.allOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
|
|
61
|
+
zodType = z.intersection(
|
|
62
|
+
allOfTypes[0],
|
|
63
|
+
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
64
|
+
).describe((value.description || "") + (value.examples ? `
|
|
65
|
+
Examples: ${value.examples.join(", ")}` : ""));
|
|
66
|
+
} else {
|
|
67
|
+
if (!value.type) {
|
|
68
|
+
value.type = "string";
|
|
69
|
+
}
|
|
70
|
+
zodType = jsonSchemaPropertiesToTSTypes(value);
|
|
71
|
+
}
|
|
72
|
+
if (value.description) {
|
|
73
|
+
zodType = zodType.describe(value.description);
|
|
74
|
+
}
|
|
75
|
+
if (requiredFields.includes(key)) {
|
|
76
|
+
zodSchema[key] = zodType;
|
|
77
|
+
} else {
|
|
78
|
+
zodSchema[key] = zodType.nullable();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return z.object(zodSchema);
|
|
82
|
+
}
|
|
83
|
+
function deepMerge(target, source) {
|
|
84
|
+
const output = { ...target };
|
|
85
|
+
if (!source) return output;
|
|
86
|
+
Object.keys(source).forEach((key) => {
|
|
87
|
+
const targetValue = output[key];
|
|
88
|
+
const sourceValue = source[key];
|
|
89
|
+
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
|
90
|
+
output[key] = sourceValue;
|
|
91
|
+
} else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
|
|
92
|
+
output[key] = deepMerge(targetValue, sourceValue);
|
|
93
|
+
} else if (sourceValue !== void 0) {
|
|
94
|
+
output[key] = sourceValue;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return output;
|
|
98
|
+
}
|
|
99
|
+
async function* maskStreamTags(stream, tag, options = {}) {
|
|
100
|
+
const { onStart, onEnd, onMask } = options;
|
|
101
|
+
const openTag = `<${tag}>`;
|
|
102
|
+
const closeTag = `</${tag}>`;
|
|
103
|
+
let buffer = "";
|
|
104
|
+
let fullContent = "";
|
|
105
|
+
let isMasking = false;
|
|
106
|
+
let isBuffering = false;
|
|
107
|
+
const trimOutsideDelimiter = (text, delimiter, trim) => {
|
|
108
|
+
if (!text.includes(delimiter)) {
|
|
109
|
+
return text;
|
|
110
|
+
}
|
|
111
|
+
const parts = text.split(delimiter);
|
|
112
|
+
if (trim === `before-start`) {
|
|
113
|
+
return `${delimiter}${parts[1]}`;
|
|
114
|
+
}
|
|
115
|
+
return `${parts[0]}${delimiter}`;
|
|
116
|
+
};
|
|
117
|
+
const startsWith = (text, pattern) => {
|
|
118
|
+
if (pattern.includes(openTag.substring(0, 3))) {
|
|
119
|
+
pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
|
|
120
|
+
}
|
|
121
|
+
return text.trim().startsWith(pattern.trim());
|
|
122
|
+
};
|
|
123
|
+
for await (const chunk of stream) {
|
|
124
|
+
fullContent += chunk;
|
|
125
|
+
if (isBuffering) buffer += chunk;
|
|
126
|
+
const chunkHasTag = startsWith(chunk, openTag);
|
|
127
|
+
const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
|
|
128
|
+
let toYieldBeforeMaskedStartTag = ``;
|
|
129
|
+
if (!isMasking && (chunkHasTag || bufferHasTag)) {
|
|
130
|
+
isMasking = true;
|
|
131
|
+
isBuffering = false;
|
|
132
|
+
const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
|
|
133
|
+
if (taggedTextToMask !== buffer.trim()) {
|
|
134
|
+
toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
|
|
135
|
+
}
|
|
136
|
+
buffer = "";
|
|
137
|
+
onStart?.();
|
|
138
|
+
}
|
|
139
|
+
if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
|
|
140
|
+
isBuffering = true;
|
|
141
|
+
buffer += chunk;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (isBuffering && buffer && !startsWith(openTag, buffer)) {
|
|
145
|
+
yield buffer;
|
|
146
|
+
buffer = "";
|
|
147
|
+
isBuffering = false;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (isMasking && fullContent.includes(closeTag)) {
|
|
151
|
+
onMask?.(chunk);
|
|
152
|
+
onEnd?.();
|
|
153
|
+
isMasking = false;
|
|
154
|
+
const lastFullContent = fullContent;
|
|
155
|
+
fullContent = ``;
|
|
156
|
+
const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
|
|
157
|
+
if (textUntilEndTag !== lastFullContent) {
|
|
158
|
+
yield lastFullContent.replace(textUntilEndTag, ``);
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (isMasking) {
|
|
163
|
+
onMask?.(chunk);
|
|
164
|
+
if (toYieldBeforeMaskedStartTag) {
|
|
165
|
+
yield toYieldBeforeMaskedStartTag;
|
|
166
|
+
}
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
yield chunk;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { deepMerge, delay, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, maskStreamTags };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { LibSQLStore } from './chunk-FEBWYMJQ.js';
|
|
2
|
+
import { InstrumentClass, OTLPTraceExporter, Telemetry } from './chunk-4ZRHVG25.js';
|
|
3
|
+
import { createLogger, LogLevel, noopLogger } from './chunk-KP5SHTKA.js';
|
|
4
|
+
import { __decoratorStart, __decorateElement, __runInitializers } from './chunk-C6A6W6XS.js';
|
|
5
|
+
|
|
6
|
+
// src/mastra/index.ts
|
|
7
|
+
var _Mastra_decorators, _init;
|
|
8
|
+
_Mastra_decorators = [InstrumentClass({
|
|
9
|
+
prefix: "mastra",
|
|
10
|
+
excludeMethods: ["getLogger", "getTelemetry"]
|
|
11
|
+
})];
|
|
12
|
+
var Mastra = class {
|
|
13
|
+
vectors;
|
|
14
|
+
agents;
|
|
15
|
+
logger;
|
|
16
|
+
workflows;
|
|
17
|
+
telemetry;
|
|
18
|
+
tts;
|
|
19
|
+
deployer;
|
|
20
|
+
storage;
|
|
21
|
+
memory;
|
|
22
|
+
constructor(config) {
|
|
23
|
+
let logger;
|
|
24
|
+
if (config?.logger === false) {
|
|
25
|
+
logger = noopLogger;
|
|
26
|
+
} else {
|
|
27
|
+
if (config?.logger) {
|
|
28
|
+
logger = config.logger;
|
|
29
|
+
} else {
|
|
30
|
+
const levleOnEnv = process.env.NODE_ENV === "production" ? LogLevel.WARN : LogLevel.INFO;
|
|
31
|
+
logger = createLogger({
|
|
32
|
+
name: "Mastra",
|
|
33
|
+
level: levleOnEnv
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
let storage = config?.storage;
|
|
39
|
+
if (!storage) {
|
|
40
|
+
storage = new LibSQLStore({
|
|
41
|
+
config: {
|
|
42
|
+
url: process.env.MASTRA_DEFAULT_STORAGE_URL || `:memory:`
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (storage instanceof LibSQLStore && config?.telemetry?.export?.type !== "custom") {
|
|
47
|
+
const newTelemetry = {
|
|
48
|
+
...(config?.telemetry || {}),
|
|
49
|
+
export: {
|
|
50
|
+
type: "custom",
|
|
51
|
+
exporter: new OTLPTraceExporter({
|
|
52
|
+
logger: this.getLogger(),
|
|
53
|
+
storage
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.telemetry = Telemetry.init(newTelemetry);
|
|
58
|
+
} else if (config?.telemetry) {
|
|
59
|
+
this.telemetry = Telemetry.init(config?.telemetry);
|
|
60
|
+
}
|
|
61
|
+
if (config?.deployer) {
|
|
62
|
+
this.deployer = config.deployer;
|
|
63
|
+
if (this.telemetry) {
|
|
64
|
+
this.deployer = this.telemetry.traceClass(config.deployer, {
|
|
65
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
66
|
+
});
|
|
67
|
+
this.deployer.__setTelemetry(this.telemetry);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (this.telemetry) {
|
|
71
|
+
this.storage = this.telemetry.traceClass(storage, {
|
|
72
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
73
|
+
});
|
|
74
|
+
this.storage.__setTelemetry(this.telemetry);
|
|
75
|
+
} else {
|
|
76
|
+
this.storage = storage;
|
|
77
|
+
}
|
|
78
|
+
if (config?.vectors) {
|
|
79
|
+
let vectors = {};
|
|
80
|
+
Object.entries(config.vectors).forEach(([key, vector]) => {
|
|
81
|
+
if (this.telemetry) {
|
|
82
|
+
vectors[key] = this.telemetry.traceClass(vector, {
|
|
83
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
84
|
+
});
|
|
85
|
+
vectors[key].__setTelemetry(this.telemetry);
|
|
86
|
+
} else {
|
|
87
|
+
vectors[key] = vector;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
this.vectors = vectors;
|
|
91
|
+
}
|
|
92
|
+
if (config?.vectors) {
|
|
93
|
+
this.vectors = config.vectors;
|
|
94
|
+
}
|
|
95
|
+
if (config?.memory) {
|
|
96
|
+
this.memory = config.memory;
|
|
97
|
+
if (this.telemetry) {
|
|
98
|
+
this.memory = this.telemetry.traceClass(config.memory, {
|
|
99
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
100
|
+
});
|
|
101
|
+
this.memory.__setTelemetry(this.telemetry);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (config && `memory` in config) {
|
|
105
|
+
this.logger.warn(`
|
|
106
|
+
Memory should be added to Agents, not to Mastra.
|
|
107
|
+
|
|
108
|
+
Instead of:
|
|
109
|
+
new Mastra({ memory: new Memory() })
|
|
110
|
+
|
|
111
|
+
do:
|
|
112
|
+
new Agent({ memory: new Memory() })
|
|
113
|
+
|
|
114
|
+
This is a warning for now, but will throw an error in the future
|
|
115
|
+
`);
|
|
116
|
+
}
|
|
117
|
+
if (config?.tts) {
|
|
118
|
+
this.tts = config.tts;
|
|
119
|
+
Object.entries(this.tts).forEach(([key, ttsCl]) => {
|
|
120
|
+
if (this.tts?.[key]) {
|
|
121
|
+
if (this.telemetry) {
|
|
122
|
+
this.tts[key] = this.telemetry.traceClass(ttsCl, {
|
|
123
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
124
|
+
});
|
|
125
|
+
this.tts[key].__setTelemetry(this.telemetry);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const agents = {};
|
|
131
|
+
if (config?.agents) {
|
|
132
|
+
Object.entries(config.agents).forEach(([key, agent]) => {
|
|
133
|
+
if (agents[key]) {
|
|
134
|
+
throw new Error(`Agent with name ID:${key} already exists`);
|
|
135
|
+
}
|
|
136
|
+
agent.__registerPrimitives({
|
|
137
|
+
logger: this.getLogger(),
|
|
138
|
+
telemetry: this.telemetry,
|
|
139
|
+
storage: this.storage,
|
|
140
|
+
memory: this.memory,
|
|
141
|
+
agents,
|
|
142
|
+
tts: this.tts,
|
|
143
|
+
vectors: this.vectors
|
|
144
|
+
});
|
|
145
|
+
agents[key] = agent;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
this.agents = agents;
|
|
149
|
+
this.workflows = {};
|
|
150
|
+
if (config?.workflows) {
|
|
151
|
+
Object.entries(config.workflows).forEach(([key, workflow]) => {
|
|
152
|
+
workflow.__registerPrimitives({
|
|
153
|
+
logger: this.getLogger(),
|
|
154
|
+
telemetry: this.telemetry,
|
|
155
|
+
storage: this.storage,
|
|
156
|
+
memory: this.memory,
|
|
157
|
+
agents: this.agents,
|
|
158
|
+
tts: this.tts,
|
|
159
|
+
vectors: this.vectors
|
|
160
|
+
});
|
|
161
|
+
this.workflows[key] = workflow;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
this.setLogger({
|
|
165
|
+
logger
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
getAgent(name) {
|
|
169
|
+
const agent = this.agents?.[name];
|
|
170
|
+
if (!agent) {
|
|
171
|
+
throw new Error(`Agent with name ${String(name)} not found`);
|
|
172
|
+
}
|
|
173
|
+
return this.agents[name];
|
|
174
|
+
}
|
|
175
|
+
getAgents() {
|
|
176
|
+
return this.agents;
|
|
177
|
+
}
|
|
178
|
+
getVector(name) {
|
|
179
|
+
const vector = this.vectors?.[name];
|
|
180
|
+
if (!vector) {
|
|
181
|
+
throw new Error(`Vector with name ${String(name)} not found`);
|
|
182
|
+
}
|
|
183
|
+
return vector;
|
|
184
|
+
}
|
|
185
|
+
getVectors() {
|
|
186
|
+
return this.vectors;
|
|
187
|
+
}
|
|
188
|
+
getDeployer() {
|
|
189
|
+
return this.deployer;
|
|
190
|
+
}
|
|
191
|
+
getWorkflow(id, {
|
|
192
|
+
serialized
|
|
193
|
+
} = {}) {
|
|
194
|
+
const workflow = this.workflows?.[id];
|
|
195
|
+
if (!workflow) {
|
|
196
|
+
throw new Error(`Workflow with ID ${String(id)} not found`);
|
|
197
|
+
}
|
|
198
|
+
if (serialized) {
|
|
199
|
+
return {
|
|
200
|
+
name: workflow.name
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return workflow;
|
|
204
|
+
}
|
|
205
|
+
getWorkflows(props = {}) {
|
|
206
|
+
if (props.serialized) {
|
|
207
|
+
return Object.entries(this.workflows).reduce((acc, [k, v]) => {
|
|
208
|
+
return {
|
|
209
|
+
...acc,
|
|
210
|
+
[k]: {
|
|
211
|
+
name: v.name
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}, {});
|
|
215
|
+
}
|
|
216
|
+
return this.workflows;
|
|
217
|
+
}
|
|
218
|
+
setStorage(storage) {
|
|
219
|
+
this.storage = storage;
|
|
220
|
+
}
|
|
221
|
+
setLogger({
|
|
222
|
+
logger
|
|
223
|
+
}) {
|
|
224
|
+
this.logger = logger;
|
|
225
|
+
if (this.agents) {
|
|
226
|
+
Object.keys(this.agents).forEach(key => {
|
|
227
|
+
this.agents?.[key]?.__setLogger(this.logger);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (this.workflows) {
|
|
231
|
+
Object.keys(this.workflows).forEach(key => {
|
|
232
|
+
this.workflows?.[key]?.__setLogger(this.logger);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (this.memory) {
|
|
236
|
+
this.memory.__setLogger(this.logger);
|
|
237
|
+
}
|
|
238
|
+
if (this.deployer) {
|
|
239
|
+
this.deployer.__setLogger(this.logger);
|
|
240
|
+
}
|
|
241
|
+
if (this.tts) {
|
|
242
|
+
Object.keys(this.tts).forEach(key => {
|
|
243
|
+
this.tts?.[key]?.__setLogger(this.logger);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (this.storage) {
|
|
247
|
+
this.storage.__setLogger(this.logger);
|
|
248
|
+
}
|
|
249
|
+
if (this.vectors) {
|
|
250
|
+
Object.keys(this.vectors).forEach(key => {
|
|
251
|
+
this.vectors?.[key]?.__setLogger(this.logger);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
setTelemetry(telemetry) {
|
|
256
|
+
this.telemetry = Telemetry.init(telemetry);
|
|
257
|
+
if (this.agents) {
|
|
258
|
+
Object.keys(this.agents).forEach(key => {
|
|
259
|
+
if (this.telemetry) {
|
|
260
|
+
this.agents?.[key]?.__setTelemetry(this.telemetry);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (this.workflows) {
|
|
265
|
+
Object.keys(this.workflows).forEach(key => {
|
|
266
|
+
if (this.telemetry) {
|
|
267
|
+
this.workflows?.[key]?.__setTelemetry(this.telemetry);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (this.memory) {
|
|
272
|
+
this.memory = this.telemetry.traceClass(this.memory, {
|
|
273
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
274
|
+
});
|
|
275
|
+
this.memory.__setTelemetry(this.telemetry);
|
|
276
|
+
}
|
|
277
|
+
if (this.deployer) {
|
|
278
|
+
this.deployer = this.telemetry.traceClass(this.deployer, {
|
|
279
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
280
|
+
});
|
|
281
|
+
this.deployer.__setTelemetry(this.telemetry);
|
|
282
|
+
}
|
|
283
|
+
if (this.tts) {
|
|
284
|
+
let tts = {};
|
|
285
|
+
Object.entries(this.tts).forEach(([key, ttsCl]) => {
|
|
286
|
+
if (this.telemetry) {
|
|
287
|
+
tts[key] = this.telemetry.traceClass(ttsCl, {
|
|
288
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
289
|
+
});
|
|
290
|
+
tts[key].__setTelemetry(this.telemetry);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
this.tts = tts;
|
|
294
|
+
}
|
|
295
|
+
if (this.storage) {
|
|
296
|
+
this.storage = this.telemetry.traceClass(this.storage, {
|
|
297
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
298
|
+
});
|
|
299
|
+
this.storage.__setTelemetry(this.telemetry);
|
|
300
|
+
}
|
|
301
|
+
if (this.vectors) {
|
|
302
|
+
let vectors = {};
|
|
303
|
+
Object.entries(this.vectors).forEach(([key, vector]) => {
|
|
304
|
+
if (this.telemetry) {
|
|
305
|
+
vectors[key] = this.telemetry.traceClass(vector, {
|
|
306
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
307
|
+
});
|
|
308
|
+
vectors[key].__setTelemetry(this.telemetry);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
this.vectors = vectors;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
getLogger() {
|
|
315
|
+
return this.logger;
|
|
316
|
+
}
|
|
317
|
+
getTelemetry() {
|
|
318
|
+
return this.telemetry;
|
|
319
|
+
}
|
|
320
|
+
async getLogsByRunId({
|
|
321
|
+
runId,
|
|
322
|
+
transportId
|
|
323
|
+
}) {
|
|
324
|
+
if (!transportId) {
|
|
325
|
+
throw new Error("Transport ID is required");
|
|
326
|
+
}
|
|
327
|
+
return await this.logger.getLogsByRunId({
|
|
328
|
+
runId,
|
|
329
|
+
transportId
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
async getLogs(transportId) {
|
|
333
|
+
if (!transportId) {
|
|
334
|
+
throw new Error("Transport ID is required");
|
|
335
|
+
}
|
|
336
|
+
return await this.logger.getLogs(transportId);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
Mastra = /*@__PURE__*/(_ => {
|
|
340
|
+
_init = __decoratorStart(null);
|
|
341
|
+
Mastra = __decorateElement(_init, 0, "Mastra", _Mastra_decorators, Mastra);
|
|
342
|
+
__runInitializers(_init, 1, Mastra);
|
|
343
|
+
return Mastra;
|
|
344
|
+
})();
|
|
345
|
+
|
|
346
|
+
export { Mastra };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MastraBase } from './chunk-6RDA4JYW.js';
|
|
2
|
+
import { parse } from 'dotenv';
|
|
3
|
+
import { readFile } from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
var MastraBundler = class extends MastraBase {
|
|
6
|
+
constructor({ name, component = "BUNDLER" }) {
|
|
7
|
+
super({ component, name });
|
|
8
|
+
}
|
|
9
|
+
async loadEnvVars() {
|
|
10
|
+
const envVars = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const file of await this.getEnvFiles()) {
|
|
12
|
+
const content = await readFile(file, "utf-8");
|
|
13
|
+
const config = parse(content);
|
|
14
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
15
|
+
envVars.set(key, value);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return envVars;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { MastraBundler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/tools/tool.ts
|
|
2
|
+
var Tool = class {
|
|
3
|
+
id;
|
|
4
|
+
description;
|
|
5
|
+
inputSchema;
|
|
6
|
+
outputSchema;
|
|
7
|
+
execute;
|
|
8
|
+
mastra;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.id = opts.id;
|
|
11
|
+
this.description = opts.description;
|
|
12
|
+
this.inputSchema = opts.inputSchema;
|
|
13
|
+
this.outputSchema = opts.outputSchema;
|
|
14
|
+
this.execute = opts.execute;
|
|
15
|
+
this.mastra = opts.mastra;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function createTool(opts) {
|
|
19
|
+
return new Tool(opts);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Tool, createTool };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MastraBundler, IBundler } from '../bundler/index.js';
|
|
2
|
+
import '../base-eWkcLLSb.js';
|
|
3
|
+
import '@opentelemetry/api';
|
|
4
|
+
import '../index-C5uPdbs4.js';
|
|
5
|
+
import 'pino';
|
|
6
|
+
import 'stream';
|
|
7
|
+
import '@opentelemetry/sdk-trace-base';
|
|
8
|
+
|
|
9
|
+
interface IDeployer extends IBundler {
|
|
10
|
+
deploy(outputDirectory: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
declare abstract class MastraDeployer extends MastraBundler implements IDeployer {
|
|
13
|
+
constructor({ name }: {
|
|
14
|
+
name: string;
|
|
15
|
+
});
|
|
16
|
+
abstract deploy(outputDirectory: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { type IDeployer, MastraDeployer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MastraDeployer } from '../chunk-Z735LDV7.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { a as Metric, T as TestInfo, M as MetricResult } from '../types-m9RryK9a.js';
|
|
2
|
+
import { A as Agent } from '../base-CHNzbTDj.js';
|
|
3
|
+
import 'ai';
|
|
4
|
+
import '../base-eWkcLLSb.js';
|
|
5
|
+
import '@opentelemetry/api';
|
|
6
|
+
import '../index-C5uPdbs4.js';
|
|
7
|
+
import 'pino';
|
|
8
|
+
import 'stream';
|
|
9
|
+
import '@opentelemetry/sdk-trace-base';
|
|
10
|
+
import 'sift';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import 'json-schema';
|
|
13
|
+
import '../vector/index.js';
|
|
14
|
+
import '../voice/index.js';
|
|
15
|
+
import '../tts/index.js';
|
|
16
|
+
|
|
17
|
+
declare function evaluate<T extends Agent>({ agentName, input, metric, output, runId, globalRunId, testInfo, instructions, }: {
|
|
18
|
+
agentName: string;
|
|
19
|
+
input: Parameters<T['generate']>[0];
|
|
20
|
+
metric: Metric;
|
|
21
|
+
output: string;
|
|
22
|
+
globalRunId: string;
|
|
23
|
+
runId?: string;
|
|
24
|
+
testInfo?: TestInfo;
|
|
25
|
+
instructions: string;
|
|
26
|
+
}): Promise<MetricResult>;
|
|
27
|
+
|
|
28
|
+
export { Metric, MetricResult, TestInfo, evaluate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Metric, evaluate } from '../chunk-NUDAZEOG.js';
|