@mastra/core 0.2.0-alpha.99 → 0.2.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 (84) hide show
  1. package/dist/agent/index.d.ts +6 -8
  2. package/dist/agent/index.js +15 -7
  3. package/dist/{telemetry-oCUM52DG.d.ts → base-BbtPAA6f.d.ts} +50 -8
  4. package/dist/{index-Cwb-5AzX.d.ts → base-Bpb7Dmwe.d.ts} +367 -320
  5. package/dist/base.d.ts +3 -43
  6. package/dist/base.js +3 -3
  7. package/dist/bundler/index.d.ts +3 -4
  8. package/dist/bundler/index.js +4 -4
  9. package/dist/{chunk-MCB4M5W4.js → chunk-22LC46YN.js} +3 -9
  10. package/dist/{chunk-A7SNFYQB.js → chunk-2JL6DQMZ.js} +20 -28
  11. package/dist/chunk-2SAHBQEF.js +3 -0
  12. package/dist/chunk-3HBFW3Q7.js +24 -0
  13. package/dist/{chunk-KNPBNSJ7.js → chunk-55GTEVHJ.js} +12 -13
  14. package/dist/chunk-65VPTVVP.js +218 -0
  15. package/dist/chunk-AWEACB2T.js +66 -0
  16. package/dist/chunk-C6A6W6XS.js +49 -0
  17. package/dist/chunk-FGZVE4CM.js +404 -0
  18. package/dist/{chunk-DHCULRJM.js → chunk-J3W3IHDO.js} +114 -88
  19. package/dist/chunk-K36NSQWH.js +10 -0
  20. package/dist/{chunk-EO3TIPGQ.js → chunk-K4DFI76V.js} +382 -370
  21. package/dist/{chunk-42DYOLDV.js → chunk-MEISIZMP.js} +13 -21
  22. package/dist/chunk-MLWGYRJR.js +87 -0
  23. package/dist/{chunk-ICMEXHKD.js → chunk-O2VP5JBC.js} +48 -55
  24. package/dist/{chunk-ZJOMHCWE.js → chunk-OJ26F3J4.js} +98 -153
  25. package/dist/chunk-RG66XEJT.js +8 -0
  26. package/dist/chunk-SB37QG7O.js +1203 -0
  27. package/dist/chunk-SDBM53G4.js +32 -0
  28. package/dist/{chunk-4LJFWC2Q.js → chunk-SIFBBGY6.js} +59 -85
  29. package/dist/chunk-U6J2FOU4.js +624 -0
  30. package/dist/chunk-VB7CO5ND.js +31 -0
  31. package/dist/{chunk-C55JWGDU.js → chunk-ZJOXJFJI.js} +43 -15
  32. package/dist/deployer/index.d.ts +2 -4
  33. package/dist/deployer/index.js +5 -5
  34. package/dist/eval/index.d.ts +8 -13
  35. package/dist/eval/index.js +3 -3
  36. package/dist/filter/index.js +2 -2
  37. package/dist/hooks/index.d.ts +13 -18
  38. package/dist/hooks/index.js +2 -2
  39. package/dist/{index-CBZ2mk2H.d.ts → index-B2JCcAQt.d.ts} +1 -1
  40. package/dist/index.d.ts +15 -15
  41. package/dist/index.js +43 -69
  42. package/dist/integration/index.d.ts +8 -10
  43. package/dist/integration/index.js +6 -3
  44. package/dist/llm/index.d.ts +6 -8
  45. package/dist/llm/index.js +1 -1
  46. package/dist/logger/index.d.ts +1 -1
  47. package/dist/logger/index.js +2 -2
  48. package/dist/mastra/index.d.ts +10 -13
  49. package/dist/mastra/index.js +20 -9
  50. package/dist/memory/index.d.ts +8 -10
  51. package/dist/memory/index.js +11 -9
  52. package/dist/relevance/index.js +16 -8
  53. package/dist/storage/index.d.ts +21 -10
  54. package/dist/storage/index.js +8 -7
  55. package/dist/telemetry/index.d.ts +35 -5
  56. package/dist/telemetry/index.js +3 -2
  57. package/dist/telemetry/otel-vendor.d.ts +7 -0
  58. package/dist/telemetry/otel-vendor.js +8 -0
  59. package/dist/tools/index.d.ts +6 -8
  60. package/dist/tools/index.js +2 -2
  61. package/dist/tts/index.d.ts +2 -4
  62. package/dist/tts/index.js +6 -5
  63. package/dist/{metric-BWeQNZt6.d.ts → types-m9RryK9a.d.ts} +6 -1
  64. package/dist/utils.js +2 -2
  65. package/dist/vector/index.d.ts +4 -6
  66. package/dist/vector/index.js +4 -4
  67. package/dist/vector/libsql/index.d.ts +2 -4
  68. package/dist/vector/libsql/index.js +6 -6
  69. package/dist/{workflow-DTtv7_Eq.d.ts → workflow-Cy8UTGCt.d.ts} +3 -6
  70. package/dist/workflows/index.d.ts +7 -9
  71. package/dist/workflows/index.js +4 -4
  72. package/package.json +14 -10
  73. package/dist/chunk-4ZUSEHLH.js +0 -285
  74. package/dist/chunk-AJJZUHB4.js +0 -14
  75. package/dist/chunk-G4MCO7XF.js +0 -70
  76. package/dist/chunk-HBTQNIAX.js +0 -90
  77. package/dist/chunk-HPXWJBQK.js +0 -222
  78. package/dist/chunk-JJ57BXQR.js +0 -16
  79. package/dist/chunk-JP37ODNX.js +0 -36
  80. package/dist/chunk-K3N7KJHH.js +0 -52
  81. package/dist/chunk-MDM2JS2U.js +0 -1288
  82. package/dist/chunk-VOUPGVRD.js +0 -27
  83. package/dist/chunk-Z7JFMQZZ.js +0 -551
  84. /package/dist/{chunk-AE3H2QEY.js → chunk-VDOJTUYY.js} +0 -0
@@ -0,0 +1,404 @@
1
+ import { TABLE_TRACES } from './chunk-RG66XEJT.js';
2
+ import { trace, context, propagation, SpanStatusCode, SpanKind } from '@opentelemetry/api';
3
+ import { ExportResultCode } from '@opentelemetry/core';
4
+ import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';
5
+ import '@opentelemetry/sdk-trace-base';
6
+
7
+ function hasActiveTelemetry(tracerName = "default-tracer") {
8
+ try {
9
+ return !!trace.getTracer(tracerName);
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ // src/telemetry/telemetry.decorators.ts
16
+ function withSpan(options) {
17
+ return function(_target, propertyKey, descriptor) {
18
+ if (!descriptor || typeof descriptor === "number") return;
19
+ const originalMethod = descriptor.value;
20
+ const methodName = String(propertyKey);
21
+ descriptor.value = function(...args) {
22
+ if (options?.skipIfNoTelemetry && !hasActiveTelemetry(options?.tracerName)) {
23
+ return originalMethod.apply(this, args);
24
+ }
25
+ const tracer = trace.getTracer(options?.tracerName ?? "default-tracer");
26
+ let spanName;
27
+ let spanKind;
28
+ if (typeof options === "string") {
29
+ spanName = options;
30
+ } else if (options) {
31
+ spanName = options.spanName || methodName;
32
+ spanKind = options.spanKind;
33
+ } else {
34
+ spanName = methodName;
35
+ }
36
+ const span = tracer.startSpan(spanName, { kind: spanKind });
37
+ let ctx = trace.setSpan(context.active(), span);
38
+ args.forEach((arg, index) => {
39
+ try {
40
+ span.setAttribute(`${spanName}.argument.${index}`, JSON.stringify(arg));
41
+ } catch (e) {
42
+ span.setAttribute(`${spanName}.argument.${index}`, "[Not Serializable]");
43
+ }
44
+ });
45
+ const currentBaggage = propagation.getBaggage(ctx);
46
+ if (currentBaggage?.componentName) {
47
+ span.setAttribute("componentName", currentBaggage?.componentName);
48
+ span.setAttribute("runId", currentBaggage?.runId);
49
+ } else if (this && this.name) {
50
+ span.setAttribute("componentName", this.name);
51
+ span.setAttribute("runId", this.runId);
52
+ ctx = propagation.setBaggage(ctx, { componentName: this.name, runId: this.runId });
53
+ }
54
+ let result;
55
+ try {
56
+ result = context.with(ctx, () => originalMethod.apply(this, args));
57
+ if (result instanceof Promise) {
58
+ return result.then((resolvedValue) => {
59
+ try {
60
+ span.setAttribute(`${spanName}.result`, JSON.stringify(resolvedValue));
61
+ } catch (e) {
62
+ span.setAttribute(`${spanName}.result`, "[Not Serializable]");
63
+ }
64
+ return resolvedValue;
65
+ }).finally(() => span.end());
66
+ }
67
+ try {
68
+ span.setAttribute(`${spanName}.result`, JSON.stringify(result));
69
+ } catch (e) {
70
+ span.setAttribute(`${spanName}.result`, "[Not Serializable]");
71
+ }
72
+ return result;
73
+ } catch (error) {
74
+ span.setStatus({
75
+ code: SpanStatusCode.ERROR,
76
+ message: error instanceof Error ? error.message : "Unknown error"
77
+ });
78
+ if (error instanceof Error) {
79
+ span.recordException(error);
80
+ }
81
+ throw error;
82
+ } finally {
83
+ if (!(result instanceof Promise)) {
84
+ span.end();
85
+ }
86
+ }
87
+ };
88
+ return descriptor;
89
+ };
90
+ }
91
+ function InstrumentClass(options) {
92
+ return function(target) {
93
+ const methods = Object.getOwnPropertyNames(target.prototype);
94
+ methods.forEach((method) => {
95
+ if (options?.excludeMethods?.includes(method) || method === "constructor") return;
96
+ if (options?.methodFilter && !options.methodFilter(method)) return;
97
+ const descriptor = Object.getOwnPropertyDescriptor(target.prototype, method);
98
+ if (descriptor && typeof descriptor.value === "function") {
99
+ Object.defineProperty(
100
+ target.prototype,
101
+ method,
102
+ withSpan({
103
+ spanName: options?.prefix ? `${options.prefix}.${method}` : method,
104
+ skipIfNoTelemetry: true,
105
+ spanKind: options?.spanKind || SpanKind.INTERNAL,
106
+ tracerName: options?.tracerName
107
+ })(target, method, descriptor)
108
+ );
109
+ }
110
+ });
111
+ return target;
112
+ };
113
+ }
114
+ var OTLPTraceExporter = class {
115
+ storage;
116
+ queue = [];
117
+ serializer;
118
+ logger;
119
+ activeFlush = undefined;
120
+ constructor({ logger, storage }) {
121
+ this.storage = storage;
122
+ this.serializer = JsonTraceSerializer;
123
+ this.logger = logger;
124
+ }
125
+ export(internalRepresentation, resultCallback) {
126
+ const serializedRequest = this.serializer.serializeRequest(internalRepresentation);
127
+ const payload = JSON.parse(Buffer.from(serializedRequest.buffer, "utf8"));
128
+ const items = payload?.resourceSpans?.[0]?.scopeSpans;
129
+ this.logger.debug(`Exporting telemetry: ${items.length} scope spans to be processed [trace batch]`);
130
+ this.queue.push({ data: items, resultCallback });
131
+ if (!this.activeFlush) {
132
+ this.activeFlush = this.flush();
133
+ }
134
+ }
135
+ shutdown() {
136
+ return this.forceFlush();
137
+ }
138
+ flush() {
139
+ const now = /* @__PURE__ */ new Date();
140
+ const items = this.queue.shift();
141
+ if (!items) return Promise.resolve();
142
+ const allSpans = items.data.reduce((acc, scopedSpans) => {
143
+ const { scope, spans } = scopedSpans;
144
+ for (const span of spans) {
145
+ const {
146
+ spanId,
147
+ parentSpanId,
148
+ traceId,
149
+ name,
150
+ kind,
151
+ attributes,
152
+ status,
153
+ events,
154
+ links,
155
+ startTimeUnixNano,
156
+ endTimeUnixNano,
157
+ ...rest
158
+ } = span;
159
+ const startTime = Number(BigInt(startTimeUnixNano) / 1000n);
160
+ const endTime = Number(BigInt(endTimeUnixNano) / 1000n);
161
+ acc.push({
162
+ id: spanId,
163
+ parentSpanId,
164
+ traceId,
165
+ name,
166
+ scope: scope.name,
167
+ kind,
168
+ status: JSON.stringify(status),
169
+ events: JSON.stringify(events),
170
+ links: JSON.stringify(links),
171
+ attributes: JSON.stringify(
172
+ attributes.reduce((acc2, attr) => {
173
+ const valueKey = Object.keys(attr.value)[0];
174
+ if (valueKey) {
175
+ acc2[attr.key] = attr.value[valueKey];
176
+ }
177
+ return acc2;
178
+ }, {})
179
+ ),
180
+ startTime,
181
+ endTime,
182
+ other: JSON.stringify(rest),
183
+ createdAt: now
184
+ });
185
+ }
186
+ return acc;
187
+ }, []);
188
+ return this.storage.__batchInsert({
189
+ tableName: TABLE_TRACES,
190
+ records: allSpans
191
+ }).then(() => {
192
+ items.resultCallback({
193
+ code: ExportResultCode.SUCCESS
194
+ });
195
+ }).catch((e) => {
196
+ this.logger.error("span err:" + e?.message);
197
+ items.resultCallback({
198
+ code: ExportResultCode.FAILED,
199
+ error: e
200
+ });
201
+ }).finally(() => {
202
+ this.activeFlush = undefined;
203
+ });
204
+ }
205
+ async forceFlush() {
206
+ if (!this.queue.length) {
207
+ return;
208
+ }
209
+ await this.activeFlush;
210
+ while (this.queue.length) {
211
+ await this.flush();
212
+ }
213
+ }
214
+ __setLogger(logger) {
215
+ this.logger = logger;
216
+ }
217
+ };
218
+ var Telemetry = class _Telemetry {
219
+ tracer = trace.getTracer("default");
220
+ name = "default-service";
221
+ constructor(config) {
222
+ this.name = config.serviceName ?? "default-service";
223
+ this.tracer = trace.getTracer(this.name);
224
+ }
225
+ /**
226
+ * @deprecated This method does not do anything
227
+ */
228
+ async shutdown() {
229
+ }
230
+ /**
231
+ * Initialize telemetry with the given configuration
232
+ * @param config - Optional telemetry configuration object
233
+ * @returns Telemetry instance that can be used for tracing
234
+ */
235
+ static init(config = {}) {
236
+ try {
237
+ if (!global.__TELEMETRY__) {
238
+ global.__TELEMETRY__ = new _Telemetry(config);
239
+ }
240
+ return global.__TELEMETRY__;
241
+ } catch (error) {
242
+ console.error("Failed to initialize telemetry:", error);
243
+ throw error;
244
+ }
245
+ }
246
+ /**
247
+ * Get the global telemetry instance
248
+ * @throws {Error} If telemetry has not been initialized
249
+ * @returns {Telemetry} The global telemetry instance
250
+ */
251
+ static get() {
252
+ if (!global.__TELEMETRY__) {
253
+ throw new Error("Telemetry not initialized");
254
+ }
255
+ return global.__TELEMETRY__;
256
+ }
257
+ /**
258
+ * Wraps a class instance with telemetry tracing
259
+ * @param instance The class instance to wrap
260
+ * @param options Optional configuration for tracing
261
+ * @returns Wrapped instance with all methods traced
262
+ */
263
+ traceClass(instance, options = {}) {
264
+ const { skipIfNoTelemetry = true } = options;
265
+ if (skipIfNoTelemetry && !hasActiveTelemetry()) {
266
+ return instance;
267
+ }
268
+ const { spanNamePrefix = instance.constructor.name.toLowerCase(), attributes = {}, excludeMethods = [] } = options;
269
+ return new Proxy(instance, {
270
+ get: (target, prop) => {
271
+ const value = target[prop];
272
+ if (typeof value === "function" && prop !== "constructor" && !prop.toString().startsWith("_") && !excludeMethods.includes(prop.toString())) {
273
+ return this.traceMethod(value.bind(target), {
274
+ spanName: `${spanNamePrefix}.${prop.toString()}`,
275
+ attributes: {
276
+ ...attributes,
277
+ [`${spanNamePrefix}.name`]: target.constructor.name,
278
+ [`${spanNamePrefix}.method.name`]: prop.toString()
279
+ }
280
+ });
281
+ }
282
+ return value;
283
+ }
284
+ });
285
+ }
286
+ /**
287
+ * method to trace individual methods with proper context
288
+ * @param method The method to trace
289
+ * @param context Additional context for the trace
290
+ * @returns Wrapped method with tracing
291
+ */
292
+ traceMethod(method, context3) {
293
+ let ctx = context.active();
294
+ const { skipIfNoTelemetry = true } = context3;
295
+ if (skipIfNoTelemetry && !hasActiveTelemetry()) {
296
+ return method;
297
+ }
298
+ return (...args) => {
299
+ const span = this.tracer.startSpan(context3.spanName);
300
+ function handleError(error) {
301
+ span.recordException(error);
302
+ span.setStatus({
303
+ code: SpanStatusCode.ERROR,
304
+ message: error.message
305
+ });
306
+ span.end();
307
+ throw error;
308
+ }
309
+ try {
310
+ let recordResult2 = function(res) {
311
+ try {
312
+ span.setAttribute(`${context3.spanName}.result`, JSON.stringify(res));
313
+ } catch (e) {
314
+ span.setAttribute(`${context3.spanName}.result`, "[Not Serializable]");
315
+ }
316
+ span.end();
317
+ return res;
318
+ };
319
+ var recordResult = recordResult2;
320
+ if (context3.attributes) {
321
+ span.setAttributes(context3.attributes);
322
+ }
323
+ if (context3.attributes?.componentName) {
324
+ ctx = propagation.setBaggage(ctx, {
325
+ // @ts-ignore
326
+ componentName: context3.attributes.componentName,
327
+ runId: context3.attributes.runId
328
+ });
329
+ } else {
330
+ const currentBaggage = propagation.getBaggage(ctx);
331
+ if (currentBaggage?.componentName) {
332
+ span.setAttribute("componentName", currentBaggage?.componentName);
333
+ span.setAttribute("runId", currentBaggage?.runId);
334
+ } else if (this && this.name) {
335
+ span.setAttribute("componentName", this.name);
336
+ span.setAttribute("runId", this.runId);
337
+ ctx = propagation.setBaggage(ctx, { componentName: this.name, runId: this.runId });
338
+ }
339
+ }
340
+ args.forEach((arg, index) => {
341
+ try {
342
+ span.setAttribute(`${context3.spanName}.argument.${index}`, JSON.stringify(arg));
343
+ } catch (e) {
344
+ span.setAttribute(`${context3.spanName}.argument.${index}`, "[Not Serializable]");
345
+ }
346
+ });
347
+ let result;
348
+ context.with(trace.setSpan(ctx, span), () => {
349
+ result = method(...args);
350
+ });
351
+ if (result instanceof Promise) {
352
+ return result.then(recordResult2).catch(handleError);
353
+ } else {
354
+ return recordResult2(result);
355
+ }
356
+ } catch (error) {
357
+ handleError(error);
358
+ }
359
+ };
360
+ }
361
+ getBaggageTracer() {
362
+ return new BaggageTracer(this.tracer);
363
+ }
364
+ };
365
+ var BaggageTracer = class {
366
+ _tracer;
367
+ constructor(tracer) {
368
+ this._tracer = tracer;
369
+ }
370
+ startSpan(name, options = {}, ctx) {
371
+ ctx = ctx ?? context.active();
372
+ const span = this._tracer.startSpan(name, options, ctx);
373
+ const currentBaggage = propagation.getBaggage(ctx);
374
+ span.setAttribute("componentName", currentBaggage?.componentName);
375
+ span.setAttribute("runId", currentBaggage?.runId);
376
+ return span;
377
+ }
378
+ startActiveSpan(name, optionsOrFn, ctxOrFn, fn) {
379
+ if (typeof optionsOrFn === "function") {
380
+ const wrappedFn2 = (span) => {
381
+ const currentBaggage = propagation.getBaggage(context.active());
382
+ span.setAttribute("componentName", currentBaggage?.componentName);
383
+ return optionsOrFn(span);
384
+ };
385
+ return this._tracer.startActiveSpan(name, {}, context.active(), wrappedFn2);
386
+ }
387
+ if (typeof ctxOrFn === "function") {
388
+ const wrappedFn2 = (span) => {
389
+ const currentBaggage = propagation.getBaggage(context.active());
390
+ span.setAttribute("componentName", currentBaggage?.componentName);
391
+ return ctxOrFn(span);
392
+ };
393
+ return this._tracer.startActiveSpan(name, optionsOrFn, context.active(), wrappedFn2);
394
+ }
395
+ const wrappedFn = (span) => {
396
+ const currentBaggage = propagation.getBaggage(ctxOrFn ?? context.active());
397
+ span.setAttribute("componentName", currentBaggage?.componentName);
398
+ return fn(span);
399
+ };
400
+ return this._tracer.startActiveSpan(name, optionsOrFn, ctxOrFn, wrappedFn);
401
+ }
402
+ };
403
+
404
+ export { InstrumentClass, OTLPTraceExporter, Telemetry, hasActiveTelemetry, withSpan };
@@ -1,31 +1,25 @@
1
- import { DefaultStorage } from './chunk-Z7JFMQZZ.js';
2
- import { InstrumentClass, Telemetry } from './chunk-4ZUSEHLH.js';
3
- import { LogLevel, createLogger, noopLogger } from './chunk-ICMEXHKD.js';
4
- import { __name, __publicField } from './chunk-AJJZUHB4.js';
1
+ import { InstrumentClass, OTLPTraceExporter, Telemetry } from './chunk-FGZVE4CM.js';
2
+ import { DefaultStorage } from './chunk-U6J2FOU4.js';
3
+ import { LogLevel, createLogger, noopLogger } from './chunk-O2VP5JBC.js';
4
+ import { __decoratorStart, __decorateElement, __runInitializers } from './chunk-C6A6W6XS.js';
5
5
 
6
6
  // src/mastra/index.ts
7
- function _ts_decorate(decorators, target, key, desc) {
8
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11
- return c > 3 && r && Object.defineProperty(target, key, r), r;
12
- }
13
- __name(_ts_decorate, "_ts_decorate");
14
- function _ts_metadata(k, v) {
15
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16
- }
17
- __name(_ts_metadata, "_ts_metadata");
18
- var _Mastra = class _Mastra {
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;
19
22
  constructor(config) {
20
- __publicField(this, "vectors");
21
- __publicField(this, "agents");
22
- __publicField(this, "logger");
23
- __publicField(this, "workflows");
24
- __publicField(this, "telemetry");
25
- __publicField(this, "tts");
26
- __publicField(this, "deployer");
27
- __publicField(this, "storage");
28
- __publicField(this, "memory");
29
23
  let logger;
30
24
  if (config?.logger === false) {
31
25
  logger = noopLogger;
@@ -34,42 +28,45 @@ var _Mastra = class _Mastra {
34
28
  logger = config.logger;
35
29
  } else {
36
30
  const levleOnEnv = process.env.NODE_ENV === "production" ? LogLevel.WARN : LogLevel.INFO;
37
- logger = createLogger({
38
- name: "Mastra",
39
- level: levleOnEnv
40
- });
31
+ logger = createLogger({ name: "Mastra", level: levleOnEnv });
41
32
  }
42
33
  }
43
34
  this.logger = logger;
44
- if (config?.telemetry) {
45
- this.telemetry = Telemetry.init(config.telemetry);
35
+ let storage = config?.storage;
36
+ if (!storage) {
37
+ storage = new DefaultStorage({
38
+ config: {
39
+ url: process.env.MASTRA_DEFAULT_STORAGE_URL || `:memory:`
40
+ }
41
+ });
42
+ }
43
+ if (storage instanceof DefaultStorage && config?.telemetry?.export?.type !== "custom") {
44
+ const newTelemetry = {
45
+ ...config?.telemetry || {},
46
+ export: {
47
+ type: "custom",
48
+ exporter: new OTLPTraceExporter({
49
+ logger: this.getLogger(),
50
+ storage
51
+ })
52
+ }
53
+ };
54
+ this.telemetry = Telemetry.init(newTelemetry);
55
+ } else if (config?.telemetry) {
56
+ this.telemetry = Telemetry.init(config?.telemetry);
46
57
  }
47
58
  if (config?.deployer) {
48
59
  this.deployer = config.deployer;
49
60
  if (this.telemetry) {
50
61
  this.deployer = this.telemetry.traceClass(config.deployer, {
51
- excludeMethods: [
52
- "__setTelemetry",
53
- "__getTelemetry"
54
- ]
62
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
55
63
  });
56
64
  this.deployer.__setTelemetry(this.telemetry);
57
65
  }
58
66
  }
59
- let storage = config?.storage;
60
- if (!storage) {
61
- storage = new DefaultStorage({
62
- config: {
63
- url: ":memory:"
64
- }
65
- });
66
- }
67
67
  if (this.telemetry) {
68
68
  this.storage = this.telemetry.traceClass(storage, {
69
- excludeMethods: [
70
- "__setTelemetry",
71
- "__getTelemetry"
72
- ]
69
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
73
70
  });
74
71
  this.storage.__setTelemetry(this.telemetry);
75
72
  } else {
@@ -80,10 +77,7 @@ var _Mastra = class _Mastra {
80
77
  Object.entries(config.vectors).forEach(([key, vector]) => {
81
78
  if (this.telemetry) {
82
79
  vectors[key] = this.telemetry.traceClass(vector, {
83
- excludeMethods: [
84
- "__setTelemetry",
85
- "__getTelemetry"
86
- ]
80
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
87
81
  });
88
82
  vectors[key].__setTelemetry(this.telemetry);
89
83
  } else {
@@ -99,10 +93,7 @@ var _Mastra = class _Mastra {
99
93
  this.memory = config.memory;
100
94
  if (this.telemetry) {
101
95
  this.memory = this.telemetry.traceClass(config.memory, {
102
- excludeMethods: [
103
- "__setTelemetry",
104
- "__getTelemetry"
105
- ]
96
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
106
97
  });
107
98
  this.memory.__setTelemetry(this.telemetry);
108
99
  }
@@ -113,10 +104,7 @@ var _Mastra = class _Mastra {
113
104
  if (this.tts?.[key]) {
114
105
  if (this.telemetry) {
115
106
  this.tts[key] = this.telemetry.traceClass(ttsCl, {
116
- excludeMethods: [
117
- "__setTelemetry",
118
- "__getTelemetry"
119
- ]
107
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
120
108
  });
121
109
  this.tts[key].__setTelemetry(this.telemetry);
122
110
  }
@@ -157,9 +145,7 @@ var _Mastra = class _Mastra {
157
145
  this.workflows[key] = workflow;
158
146
  });
159
147
  }
160
- this.setLogger({
161
- logger
162
- });
148
+ this.setLogger({ logger });
163
149
  }
164
150
  getAgent(name) {
165
151
  const agent = this.agents?.[name];
@@ -190,9 +176,7 @@ var _Mastra = class _Mastra {
190
176
  throw new Error(`Workflow with ID ${String(id)} not found`);
191
177
  }
192
178
  if (serialized) {
193
- return {
194
- name: workflow.name
195
- };
179
+ return { name: workflow.name };
196
180
  }
197
181
  return workflow;
198
182
  }
@@ -201,15 +185,13 @@ var _Mastra = class _Mastra {
201
185
  return Object.entries(this.workflows).reduce((acc, [k, v]) => {
202
186
  return {
203
187
  ...acc,
204
- [k]: {
205
- name: v.name
206
- }
188
+ [k]: { name: v.name }
207
189
  };
208
190
  }, {});
209
191
  }
210
192
  return this.workflows;
211
193
  }
212
- setStorage({ storage }) {
194
+ setStorage(storage) {
213
195
  this.storage = storage;
214
196
  }
215
197
  setLogger({ logger }) {
@@ -244,6 +226,65 @@ var _Mastra = class _Mastra {
244
226
  });
245
227
  }
246
228
  }
229
+ setTelemetry(telemetry) {
230
+ this.telemetry = Telemetry.init(telemetry);
231
+ if (this.agents) {
232
+ Object.keys(this.agents).forEach((key) => {
233
+ if (this.telemetry) {
234
+ this.agents?.[key]?.__setTelemetry(this.telemetry);
235
+ }
236
+ });
237
+ }
238
+ if (this.workflows) {
239
+ Object.keys(this.workflows).forEach((key) => {
240
+ if (this.telemetry) {
241
+ this.workflows?.[key]?.__setTelemetry(this.telemetry);
242
+ }
243
+ });
244
+ }
245
+ if (this.memory) {
246
+ this.memory = this.telemetry.traceClass(this.memory, {
247
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
248
+ });
249
+ this.memory.__setTelemetry(this.telemetry);
250
+ }
251
+ if (this.deployer) {
252
+ this.deployer = this.telemetry.traceClass(this.deployer, {
253
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
254
+ });
255
+ this.deployer.__setTelemetry(this.telemetry);
256
+ }
257
+ if (this.tts) {
258
+ let tts = {};
259
+ Object.entries(this.tts).forEach(([key, ttsCl]) => {
260
+ if (this.telemetry) {
261
+ tts[key] = this.telemetry.traceClass(ttsCl, {
262
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
263
+ });
264
+ tts[key].__setTelemetry(this.telemetry);
265
+ }
266
+ });
267
+ this.tts = tts;
268
+ }
269
+ if (this.storage) {
270
+ this.storage = this.telemetry.traceClass(this.storage, {
271
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
272
+ });
273
+ this.storage.__setTelemetry(this.telemetry);
274
+ }
275
+ if (this.vectors) {
276
+ let vectors = {};
277
+ Object.entries(this.vectors).forEach(([key, vector]) => {
278
+ if (this.telemetry) {
279
+ vectors[key] = this.telemetry.traceClass(vector, {
280
+ excludeMethods: ["__setTelemetry", "__getTelemetry"]
281
+ });
282
+ vectors[key].__setTelemetry(this.telemetry);
283
+ }
284
+ });
285
+ this.vectors = vectors;
286
+ }
287
+ }
247
288
  getLogger() {
248
289
  return this.logger;
249
290
  }
@@ -254,10 +295,7 @@ var _Mastra = class _Mastra {
254
295
  if (!transportId) {
255
296
  throw new Error("Transport ID is required");
256
297
  }
257
- return await this.logger.getLogsByRunId({
258
- runId,
259
- transportId
260
- });
298
+ return await this.logger.getLogsByRunId({ runId, transportId });
261
299
  }
262
300
  async getLogs(transportId) {
263
301
  if (!transportId) {
@@ -266,20 +304,8 @@ var _Mastra = class _Mastra {
266
304
  return await this.logger.getLogs(transportId);
267
305
  }
268
306
  };
269
- __name(_Mastra, "Mastra");
270
- var Mastra = _Mastra;
271
- Mastra = _ts_decorate([
272
- InstrumentClass({
273
- prefix: "mastra",
274
- excludeMethods: [
275
- "getLogger",
276
- "getTelemetry"
277
- ]
278
- }),
279
- _ts_metadata("design:type", Function),
280
- _ts_metadata("design:paramtypes", [
281
- Object
282
- ])
283
- ], Mastra);
307
+ _init = __decoratorStart(null);
308
+ Mastra = __decorateElement(_init, 0, "Mastra", _Mastra_decorators, Mastra);
309
+ __runInitializers(_init, 1, Mastra);
284
310
 
285
311
  export { Mastra };
@@ -0,0 +1,10 @@
1
+ import { MastraBundler } from './chunk-22LC46YN.js';
2
+
3
+ // src/deployer/index.ts
4
+ var MastraDeployer = class extends MastraBundler {
5
+ constructor({ name }) {
6
+ super({ component: "DEPLOYER", name });
7
+ }
8
+ };
9
+
10
+ export { MastraDeployer };