@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
package/dist/tts/index.cjs
CHANGED
|
@@ -1,335 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var pino = require('pino');
|
|
5
|
-
var pretty = require('pino-pretty');
|
|
6
|
-
var api = require('@opentelemetry/api');
|
|
3
|
+
var chunkHJPMYDWO_cjs = require('../chunk-HJPMYDWO.cjs');
|
|
7
4
|
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
5
|
|
|
10
|
-
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
11
|
-
var pretty__default = /*#__PURE__*/_interopDefault(pretty);
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
var __defProp = Object.defineProperty;
|
|
15
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
17
|
-
var __typeError = msg => {
|
|
18
|
-
throw TypeError(msg);
|
|
19
|
-
};
|
|
20
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
7
|
+
Object.defineProperty(exports, "MastraTTS", {
|
|
21
8
|
enumerable: true,
|
|
22
|
-
|
|
23
|
-
writable: true,
|
|
24
|
-
value
|
|
25
|
-
}) : obj[key] = value;
|
|
26
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
27
|
-
value,
|
|
28
|
-
configurable: true
|
|
9
|
+
get: function () { return chunkHJPMYDWO_cjs.MastraTTS; }
|
|
29
10
|
});
|
|
30
|
-
var __decoratorStart = base => [,,, __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
31
|
-
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
32
|
-
var __expectFn = fn => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
33
|
-
var __decoratorContext = (kind, name, done, metadata, fns) => ({
|
|
34
|
-
kind: __decoratorStrings[kind],
|
|
35
|
-
name,
|
|
36
|
-
metadata,
|
|
37
|
-
addInitializer: fn => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null))
|
|
38
|
-
});
|
|
39
|
-
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
40
|
-
var __runInitializers = (array, flags, self, value) => {
|
|
41
|
-
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
|
|
42
|
-
return value;
|
|
43
|
-
};
|
|
44
|
-
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
45
|
-
var it,
|
|
46
|
-
done,
|
|
47
|
-
ctx,
|
|
48
|
-
k = flags & 7,
|
|
49
|
-
p = false;
|
|
50
|
-
var j = 0;
|
|
51
|
-
var extraInitializers = array[j] || (array[j] = []);
|
|
52
|
-
var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(target , name));
|
|
53
|
-
__name(target, name);
|
|
54
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
55
|
-
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
56
|
-
it = (0, decorators[i])(target, ctx), done._ = 1;
|
|
57
|
-
__expectFn(it) && (target = it);
|
|
58
|
-
}
|
|
59
|
-
return __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
60
|
-
};
|
|
61
|
-
var RegisteredLogger = {
|
|
62
|
-
LLM: "LLM"};
|
|
63
|
-
var LogLevel = {
|
|
64
|
-
INFO: "info"};
|
|
65
|
-
var Logger = class {
|
|
66
|
-
logger;
|
|
67
|
-
transports;
|
|
68
|
-
constructor(options = {}) {
|
|
69
|
-
this.transports = options.transports || {};
|
|
70
|
-
const transportsAry = Object.entries(this.transports);
|
|
71
|
-
this.logger = pino__default.default({
|
|
72
|
-
name: options.name || "app",
|
|
73
|
-
level: options.level || LogLevel.INFO,
|
|
74
|
-
formatters: {
|
|
75
|
-
level: label => {
|
|
76
|
-
return {
|
|
77
|
-
level: label
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}, options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? pretty__default.default({
|
|
82
|
-
colorize: true,
|
|
83
|
-
levelFirst: true,
|
|
84
|
-
ignore: "pid,hostname",
|
|
85
|
-
colorizeObjects: true,
|
|
86
|
-
translateTime: "SYS:standard",
|
|
87
|
-
singleLine: false
|
|
88
|
-
}) : pino__default.default.multistream([...transportsAry.map(([_, transport]) => ({
|
|
89
|
-
stream: transport,
|
|
90
|
-
level: options.level || LogLevel.INFO
|
|
91
|
-
})), {
|
|
92
|
-
stream: pretty__default.default({
|
|
93
|
-
colorize: true,
|
|
94
|
-
levelFirst: true,
|
|
95
|
-
ignore: "pid,hostname",
|
|
96
|
-
colorizeObjects: true,
|
|
97
|
-
translateTime: "SYS:standard",
|
|
98
|
-
singleLine: false
|
|
99
|
-
}),
|
|
100
|
-
level: options.level || LogLevel.INFO
|
|
101
|
-
}]));
|
|
102
|
-
}
|
|
103
|
-
debug(message, args = {}) {
|
|
104
|
-
this.logger.debug(args, message);
|
|
105
|
-
}
|
|
106
|
-
info(message, args = {}) {
|
|
107
|
-
this.logger.info(args, message);
|
|
108
|
-
}
|
|
109
|
-
warn(message, args = {}) {
|
|
110
|
-
this.logger.warn(args, message);
|
|
111
|
-
}
|
|
112
|
-
error(message, args = {}) {
|
|
113
|
-
this.logger.error(args, message);
|
|
114
|
-
}
|
|
115
|
-
// Stream creation for process output handling
|
|
116
|
-
createStream() {
|
|
117
|
-
return new stream.Transform({
|
|
118
|
-
transform: (chunk, _encoding, callback) => {
|
|
119
|
-
const line = chunk.toString().trim();
|
|
120
|
-
if (line) {
|
|
121
|
-
this.info(line);
|
|
122
|
-
}
|
|
123
|
-
callback(null, chunk);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
async getLogs(transportId) {
|
|
128
|
-
if (!transportId || !this.transports[transportId]) {
|
|
129
|
-
return [];
|
|
130
|
-
}
|
|
131
|
-
return this.transports[transportId].getLogs();
|
|
132
|
-
}
|
|
133
|
-
async getLogsByRunId({
|
|
134
|
-
runId,
|
|
135
|
-
transportId
|
|
136
|
-
}) {
|
|
137
|
-
return this.transports[transportId]?.getLogsByRunId({
|
|
138
|
-
runId
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
function createLogger(options) {
|
|
143
|
-
return new Logger(options);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/base.ts
|
|
147
|
-
var MastraBase = class {
|
|
148
|
-
component = RegisteredLogger.LLM;
|
|
149
|
-
logger;
|
|
150
|
-
name;
|
|
151
|
-
telemetry;
|
|
152
|
-
constructor({
|
|
153
|
-
component,
|
|
154
|
-
name
|
|
155
|
-
}) {
|
|
156
|
-
this.component = component || RegisteredLogger.LLM;
|
|
157
|
-
this.name = name;
|
|
158
|
-
this.logger = createLogger({
|
|
159
|
-
name: `${this.component} - ${this.name}`
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Set the logger for the agent
|
|
164
|
-
* @param logger
|
|
165
|
-
*/
|
|
166
|
-
__setLogger(logger) {
|
|
167
|
-
this.logger = logger;
|
|
168
|
-
this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Set the telemetry for the
|
|
172
|
-
* @param telemetry
|
|
173
|
-
*/
|
|
174
|
-
__setTelemetry(telemetry) {
|
|
175
|
-
this.telemetry = telemetry;
|
|
176
|
-
this.logger.debug(`Telemetry updated [component=${this.component}] [tracer=${this.telemetry.tracer}]`);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Get the telemetry on the vector
|
|
180
|
-
* @returns telemetry
|
|
181
|
-
*/
|
|
182
|
-
__getTelemetry() {
|
|
183
|
-
return this.telemetry;
|
|
184
|
-
}
|
|
185
|
-
/*
|
|
186
|
-
get experimental_telemetry config
|
|
187
|
-
*/
|
|
188
|
-
get experimental_telemetry() {
|
|
189
|
-
return this.telemetry ? {
|
|
190
|
-
// tracer: this.telemetry.tracer,
|
|
191
|
-
tracer: this.telemetry.getBaggageTracer(),
|
|
192
|
-
isEnabled: !!this.telemetry.tracer
|
|
193
|
-
} : void 0;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
function hasActiveTelemetry(tracerName = "default-tracer") {
|
|
197
|
-
try {
|
|
198
|
-
return !!api.trace.getTracer(tracerName);
|
|
199
|
-
} catch {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// src/telemetry/telemetry.decorators.ts
|
|
205
|
-
function withSpan(options) {
|
|
206
|
-
return function (_target, propertyKey, descriptor) {
|
|
207
|
-
if (!descriptor || typeof descriptor === "number") return;
|
|
208
|
-
const originalMethod = descriptor.value;
|
|
209
|
-
const methodName = String(propertyKey);
|
|
210
|
-
descriptor.value = function (...args) {
|
|
211
|
-
if (options?.skipIfNoTelemetry && !hasActiveTelemetry(options?.tracerName)) {
|
|
212
|
-
return originalMethod.apply(this, args);
|
|
213
|
-
}
|
|
214
|
-
const tracer = api.trace.getTracer(options?.tracerName ?? "default-tracer");
|
|
215
|
-
let spanName;
|
|
216
|
-
let spanKind;
|
|
217
|
-
if (typeof options === "string") {
|
|
218
|
-
spanName = options;
|
|
219
|
-
} else if (options) {
|
|
220
|
-
spanName = options.spanName || methodName;
|
|
221
|
-
spanKind = options.spanKind;
|
|
222
|
-
} else {
|
|
223
|
-
spanName = methodName;
|
|
224
|
-
}
|
|
225
|
-
const span = tracer.startSpan(spanName, {
|
|
226
|
-
kind: spanKind
|
|
227
|
-
});
|
|
228
|
-
let ctx = api.trace.setSpan(api.context.active(), span);
|
|
229
|
-
args.forEach((arg, index) => {
|
|
230
|
-
try {
|
|
231
|
-
span.setAttribute(`${spanName}.argument.${index}`, JSON.stringify(arg));
|
|
232
|
-
} catch {
|
|
233
|
-
span.setAttribute(`${spanName}.argument.${index}`, "[Not Serializable]");
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
const currentBaggage = api.propagation.getBaggage(ctx);
|
|
237
|
-
if (currentBaggage?.componentName) {
|
|
238
|
-
span.setAttribute("componentName", currentBaggage?.componentName);
|
|
239
|
-
span.setAttribute("runId", currentBaggage?.runId);
|
|
240
|
-
} else if (this && this.name) {
|
|
241
|
-
span.setAttribute("componentName", this.name);
|
|
242
|
-
span.setAttribute("runId", this.runId);
|
|
243
|
-
ctx = api.propagation.setBaggage(ctx, {
|
|
244
|
-
componentName: this.name,
|
|
245
|
-
runId: this.runId
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
let result;
|
|
249
|
-
try {
|
|
250
|
-
result = api.context.with(ctx, () => originalMethod.apply(this, args));
|
|
251
|
-
if (result instanceof Promise) {
|
|
252
|
-
return result.then(resolvedValue => {
|
|
253
|
-
try {
|
|
254
|
-
span.setAttribute(`${spanName}.result`, JSON.stringify(resolvedValue));
|
|
255
|
-
} catch {
|
|
256
|
-
span.setAttribute(`${spanName}.result`, "[Not Serializable]");
|
|
257
|
-
}
|
|
258
|
-
return resolvedValue;
|
|
259
|
-
}).finally(() => span.end());
|
|
260
|
-
}
|
|
261
|
-
try {
|
|
262
|
-
span.setAttribute(`${spanName}.result`, JSON.stringify(result));
|
|
263
|
-
} catch {
|
|
264
|
-
span.setAttribute(`${spanName}.result`, "[Not Serializable]");
|
|
265
|
-
}
|
|
266
|
-
return result;
|
|
267
|
-
} catch (error) {
|
|
268
|
-
span.setStatus({
|
|
269
|
-
code: api.SpanStatusCode.ERROR,
|
|
270
|
-
message: error instanceof Error ? error.message : "Unknown error"
|
|
271
|
-
});
|
|
272
|
-
if (error instanceof Error) {
|
|
273
|
-
span.recordException(error);
|
|
274
|
-
}
|
|
275
|
-
throw error;
|
|
276
|
-
} finally {
|
|
277
|
-
if (!(result instanceof Promise)) {
|
|
278
|
-
span.end();
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
return descriptor;
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
function InstrumentClass(options) {
|
|
286
|
-
return function (target) {
|
|
287
|
-
const methods = Object.getOwnPropertyNames(target.prototype);
|
|
288
|
-
methods.forEach(method => {
|
|
289
|
-
if (options?.excludeMethods?.includes(method) || method === "constructor") return;
|
|
290
|
-
if (options?.methodFilter && !options.methodFilter(method)) return;
|
|
291
|
-
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, method);
|
|
292
|
-
if (descriptor && typeof descriptor.value === "function") {
|
|
293
|
-
Object.defineProperty(target.prototype, method, withSpan({
|
|
294
|
-
spanName: options?.prefix ? `${options.prefix}.${method}` : method,
|
|
295
|
-
skipIfNoTelemetry: true,
|
|
296
|
-
spanKind: options?.spanKind || api.SpanKind.INTERNAL,
|
|
297
|
-
tracerName: options?.tracerName
|
|
298
|
-
})(target, method, descriptor));
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
return target;
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// src/tts/index.ts
|
|
306
|
-
var _MastraTTS_decorators, _init, _a;
|
|
307
|
-
_MastraTTS_decorators = [InstrumentClass({
|
|
308
|
-
prefix: "tts",
|
|
309
|
-
excludeMethods: ["__setTools", "__setLogger", "__setTelemetry", "#log"]
|
|
310
|
-
})];
|
|
311
|
-
exports.MastraTTS = class MastraTTS extends (_a = MastraBase) {
|
|
312
|
-
model;
|
|
313
|
-
constructor({
|
|
314
|
-
model
|
|
315
|
-
}) {
|
|
316
|
-
super({
|
|
317
|
-
component: "TTS"
|
|
318
|
-
});
|
|
319
|
-
this.model = model;
|
|
320
|
-
}
|
|
321
|
-
traced(method, methodName) {
|
|
322
|
-
return this.telemetry?.traceMethod(method, {
|
|
323
|
-
spanName: `${this.model.name}-tts.${methodName}`,
|
|
324
|
-
attributes: {
|
|
325
|
-
"tts.type": `${this.model.name}`
|
|
326
|
-
}
|
|
327
|
-
}) ?? method;
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
exports.MastraTTS = /*@__PURE__*/(_ => {
|
|
331
|
-
_init = __decoratorStart(_a);
|
|
332
|
-
exports.MastraTTS = __decorateElement(_init, 0, "MastraTTS", _MastraTTS_decorators, exports.MastraTTS);
|
|
333
|
-
__runInitializers(_init, 1, exports.MastraTTS);
|
|
334
|
-
return exports.MastraTTS;
|
|
335
|
-
})();
|
package/dist/utils.cjs
CHANGED
|
@@ -1,314 +1,46 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var zod = require('zod');
|
|
3
|
+
var chunk43Y7WG5W_cjs = require('./chunk-43Y7WG5W.cjs');
|
|
5
4
|
|
|
6
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
5
|
|
|
8
|
-
var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
case "boolean":
|
|
51
|
-
zodType = zod.z.boolean().describe((value.description || "") + (value.examples ? `
|
|
52
|
-
Examples: ${value.examples.join(", ")}` : ""));
|
|
53
|
-
break;
|
|
54
|
-
case "array":
|
|
55
|
-
zodType = zod.z.array(jsonSchemaPropertiesToTSTypes(value.items)).describe((value.description || "") + (value.examples ? `
|
|
56
|
-
Examples: ${value.examples.join(", ")}` : ""));
|
|
57
|
-
break;
|
|
58
|
-
case "object":
|
|
59
|
-
zodType = jsonSchemaToModel(value).describe(
|
|
60
|
-
(value.description || "") + (value.examples ? `
|
|
61
|
-
Examples: ${value.examples.join(", ")}` : "")
|
|
62
|
-
);
|
|
63
|
-
break;
|
|
64
|
-
case "null":
|
|
65
|
-
zodType = zod.z.null().describe(value.description || "");
|
|
66
|
-
break;
|
|
67
|
-
default:
|
|
68
|
-
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
69
|
-
}
|
|
70
|
-
return zodType;
|
|
71
|
-
}
|
|
72
|
-
function jsonSchemaToModel(jsonSchema) {
|
|
73
|
-
const properties = jsonSchema.properties;
|
|
74
|
-
const requiredFields = jsonSchema.required || [];
|
|
75
|
-
if (!properties) {
|
|
76
|
-
return zod.z.object({});
|
|
77
|
-
}
|
|
78
|
-
const zodSchema = {};
|
|
79
|
-
for (const [key, _] of Object.entries(properties)) {
|
|
80
|
-
const value = _;
|
|
81
|
-
let zodType;
|
|
82
|
-
if (value.anyOf) {
|
|
83
|
-
const anyOfTypes = value.anyOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
|
|
84
|
-
zodType = zod.z.union(anyOfTypes).describe((value.description || "") + (value.examples ? `
|
|
85
|
-
Examples: ${value.examples.join(", ")}` : ""));
|
|
86
|
-
} else if (value.allOf) {
|
|
87
|
-
const allOfTypes = value.allOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
|
|
88
|
-
zodType = zod.z.intersection(
|
|
89
|
-
allOfTypes[0],
|
|
90
|
-
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
91
|
-
).describe((value.description || "") + (value.examples ? `
|
|
92
|
-
Examples: ${value.examples.join(", ")}` : ""));
|
|
93
|
-
} else {
|
|
94
|
-
if (!value.type) {
|
|
95
|
-
value.type = "string";
|
|
96
|
-
}
|
|
97
|
-
zodType = jsonSchemaPropertiesToTSTypes(value);
|
|
98
|
-
}
|
|
99
|
-
if (value.description) {
|
|
100
|
-
zodType = zodType.describe(value.description);
|
|
101
|
-
}
|
|
102
|
-
if (requiredFields.includes(key)) {
|
|
103
|
-
zodSchema[key] = zodType;
|
|
104
|
-
} else {
|
|
105
|
-
zodSchema[key] = zodType.nullable().optional();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return zod.z.object(zodSchema);
|
|
109
|
-
}
|
|
110
|
-
function deepMerge(target, source) {
|
|
111
|
-
const output = { ...target };
|
|
112
|
-
if (!source) return output;
|
|
113
|
-
Object.keys(source).forEach((key) => {
|
|
114
|
-
const targetValue = output[key];
|
|
115
|
-
const sourceValue = source[key];
|
|
116
|
-
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
|
117
|
-
output[key] = sourceValue;
|
|
118
|
-
} else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
|
|
119
|
-
output[key] = deepMerge(targetValue, sourceValue);
|
|
120
|
-
} else if (sourceValue !== void 0) {
|
|
121
|
-
output[key] = sourceValue;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
return output;
|
|
125
|
-
}
|
|
126
|
-
async function* maskStreamTags(stream, tag, options = {}) {
|
|
127
|
-
const { onStart, onEnd, onMask } = options;
|
|
128
|
-
const openTag = `<${tag}>`;
|
|
129
|
-
const closeTag = `</${tag}>`;
|
|
130
|
-
let buffer = "";
|
|
131
|
-
let fullContent = "";
|
|
132
|
-
let isMasking = false;
|
|
133
|
-
let isBuffering = false;
|
|
134
|
-
const trimOutsideDelimiter = (text, delimiter, trim) => {
|
|
135
|
-
if (!text.includes(delimiter)) {
|
|
136
|
-
return text;
|
|
137
|
-
}
|
|
138
|
-
const parts = text.split(delimiter);
|
|
139
|
-
if (trim === `before-start`) {
|
|
140
|
-
return `${delimiter}${parts[1]}`;
|
|
141
|
-
}
|
|
142
|
-
return `${parts[0]}${delimiter}`;
|
|
143
|
-
};
|
|
144
|
-
const startsWith = (text, pattern) => {
|
|
145
|
-
if (pattern.includes(openTag.substring(0, 3))) {
|
|
146
|
-
pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
|
|
147
|
-
}
|
|
148
|
-
return text.trim().startsWith(pattern.trim());
|
|
149
|
-
};
|
|
150
|
-
for await (const chunk of stream) {
|
|
151
|
-
fullContent += chunk;
|
|
152
|
-
if (isBuffering) buffer += chunk;
|
|
153
|
-
const chunkHasTag = startsWith(chunk, openTag);
|
|
154
|
-
const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
|
|
155
|
-
let toYieldBeforeMaskedStartTag = ``;
|
|
156
|
-
if (!isMasking && (chunkHasTag || bufferHasTag)) {
|
|
157
|
-
isMasking = true;
|
|
158
|
-
isBuffering = false;
|
|
159
|
-
const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
|
|
160
|
-
if (taggedTextToMask !== buffer.trim()) {
|
|
161
|
-
toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
|
|
162
|
-
}
|
|
163
|
-
buffer = "";
|
|
164
|
-
onStart?.();
|
|
165
|
-
}
|
|
166
|
-
if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
|
|
167
|
-
isBuffering = true;
|
|
168
|
-
buffer += chunk;
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (isBuffering && buffer && !startsWith(openTag, buffer)) {
|
|
172
|
-
yield buffer;
|
|
173
|
-
buffer = "";
|
|
174
|
-
isBuffering = false;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (isMasking && fullContent.includes(closeTag)) {
|
|
178
|
-
onMask?.(chunk);
|
|
179
|
-
onEnd?.();
|
|
180
|
-
isMasking = false;
|
|
181
|
-
const lastFullContent = fullContent;
|
|
182
|
-
fullContent = ``;
|
|
183
|
-
const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
|
|
184
|
-
if (textUntilEndTag !== lastFullContent) {
|
|
185
|
-
yield lastFullContent.replace(textUntilEndTag, ``);
|
|
186
|
-
}
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (isMasking) {
|
|
190
|
-
onMask?.(chunk);
|
|
191
|
-
if (toYieldBeforeMaskedStartTag) {
|
|
192
|
-
yield toYieldBeforeMaskedStartTag;
|
|
193
|
-
}
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
yield chunk;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function resolveSerializedZodOutput(schema) {
|
|
200
|
-
return Function("z", `"use strict";return (${schema});`)(zod.z);
|
|
201
|
-
}
|
|
202
|
-
function isVercelTool(tool) {
|
|
203
|
-
return !(tool instanceof Tool);
|
|
204
|
-
}
|
|
205
|
-
function createLogMessageOptions({ agentName, toolName, tool, type }) {
|
|
206
|
-
if (!agentName) {
|
|
207
|
-
return {
|
|
208
|
-
start: `Executing tool ${toolName}`,
|
|
209
|
-
error: `Failed tool execution`
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
const prefix = `[Agent:${agentName}]`;
|
|
213
|
-
const vercelPrefix = isVercelTool(tool) ? "Vercel " : "";
|
|
214
|
-
const toolType = type === "toolset" ? "toolset" : "tool";
|
|
215
|
-
return {
|
|
216
|
-
start: `${prefix} - Executing ${vercelPrefix}${toolType} ${toolName}`,
|
|
217
|
-
error: `${prefix} - Failed ${vercelPrefix}${toolType} execution`
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function createExecute(tool, options, logType) {
|
|
221
|
-
const { logger, ...rest } = options;
|
|
222
|
-
const { start, error } = createLogMessageOptions({
|
|
223
|
-
agentName: options.agentName,
|
|
224
|
-
toolName: options.name,
|
|
225
|
-
tool,
|
|
226
|
-
type: logType
|
|
227
|
-
});
|
|
228
|
-
const execFunction = async (args, execOptions) => {
|
|
229
|
-
if (isVercelTool(tool)) {
|
|
230
|
-
return tool?.execute?.(args, execOptions) ?? void 0;
|
|
231
|
-
}
|
|
232
|
-
return tool?.execute?.(
|
|
233
|
-
{
|
|
234
|
-
context: args,
|
|
235
|
-
threadId: options.threadId,
|
|
236
|
-
resourceId: options.resourceId,
|
|
237
|
-
mastra: options.mastra,
|
|
238
|
-
memory: options.memory,
|
|
239
|
-
runId: options.runId
|
|
240
|
-
},
|
|
241
|
-
execOptions
|
|
242
|
-
) ?? void 0;
|
|
243
|
-
};
|
|
244
|
-
return async (args, execOptions) => {
|
|
245
|
-
try {
|
|
246
|
-
logger.debug(start, { ...rest, args });
|
|
247
|
-
return await execFunction(args, execOptions);
|
|
248
|
-
} catch (err) {
|
|
249
|
-
logger.error(error, { ...rest, error: err, args });
|
|
250
|
-
throw err;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
function makeCoreTool(tool, options, logType) {
|
|
255
|
-
const getParameters = () => {
|
|
256
|
-
if (isVercelTool(tool)) {
|
|
257
|
-
return tool.parameters instanceof zod.z.ZodType ? tool.parameters : resolveSerializedZodOutput(jsonSchemaToZod__default.default(tool.parameters));
|
|
258
|
-
}
|
|
259
|
-
return tool.inputSchema;
|
|
260
|
-
};
|
|
261
|
-
return {
|
|
262
|
-
description: tool.description,
|
|
263
|
-
parameters: getParameters(),
|
|
264
|
-
execute: tool.execute ? createExecute(tool, { ...options, description: tool.description }, logType) : void 0
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
function createMastraProxy({ mastra, logger }) {
|
|
268
|
-
return new Proxy(mastra, {
|
|
269
|
-
get(target, prop) {
|
|
270
|
-
if (Reflect.has(target, prop)) {
|
|
271
|
-
return Reflect.get(target, prop);
|
|
272
|
-
}
|
|
273
|
-
if (prop === "logger") {
|
|
274
|
-
logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
|
|
275
|
-
return Reflect.apply(target.getLogger, target, []);
|
|
276
|
-
}
|
|
277
|
-
if (prop === "telemetry") {
|
|
278
|
-
logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
|
|
279
|
-
return Reflect.apply(target.getTelemetry, target, []);
|
|
280
|
-
}
|
|
281
|
-
if (prop === "storage") {
|
|
282
|
-
logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
|
|
283
|
-
return Reflect.get(target, "storage");
|
|
284
|
-
}
|
|
285
|
-
if (prop === "agents") {
|
|
286
|
-
logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
|
|
287
|
-
return Reflect.apply(target.getAgents, target, []);
|
|
288
|
-
}
|
|
289
|
-
if (prop === "tts") {
|
|
290
|
-
logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
|
|
291
|
-
return Reflect.apply(target.getTTS, target, []);
|
|
292
|
-
}
|
|
293
|
-
if (prop === "vectors") {
|
|
294
|
-
logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
|
|
295
|
-
return Reflect.apply(target.getVectors, target, []);
|
|
296
|
-
}
|
|
297
|
-
if (prop === "memory") {
|
|
298
|
-
logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
|
|
299
|
-
return Reflect.get(target, "memory");
|
|
300
|
-
}
|
|
301
|
-
return Reflect.get(target, prop);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
exports.createMastraProxy = createMastraProxy;
|
|
307
|
-
exports.deepMerge = deepMerge;
|
|
308
|
-
exports.delay = delay;
|
|
309
|
-
exports.isVercelTool = isVercelTool;
|
|
310
|
-
exports.jsonSchemaPropertiesToTSTypes = jsonSchemaPropertiesToTSTypes;
|
|
311
|
-
exports.jsonSchemaToModel = jsonSchemaToModel;
|
|
312
|
-
exports.makeCoreTool = makeCoreTool;
|
|
313
|
-
exports.maskStreamTags = maskStreamTags;
|
|
314
|
-
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
|
+
});
|