@mastra/core 0.0.0-commonjs-20250227130920

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +180 -0
  3. package/dist/agent/index.cjs +1865 -0
  4. package/dist/agent/index.d.cts +15 -0
  5. package/dist/agent/index.d.ts +15 -0
  6. package/dist/agent/index.js +1 -0
  7. package/dist/base-D90KQ4XI.d.ts +139 -0
  8. package/dist/base-hs9NDAZ2.d.cts +139 -0
  9. package/dist/base-nKCMCNrM.d.ts +920 -0
  10. package/dist/base-nhesrHv3.d.cts +920 -0
  11. package/dist/base.cjs +138 -0
  12. package/dist/base.d.cts +6 -0
  13. package/dist/base.d.ts +6 -0
  14. package/dist/base.js +1 -0
  15. package/dist/bundler/index.cjs +158 -0
  16. package/dist/bundler/index.d.cts +28 -0
  17. package/dist/bundler/index.d.ts +28 -0
  18. package/dist/bundler/index.js +1 -0
  19. package/dist/chunk-33GSTUNK.js +620 -0
  20. package/dist/chunk-4YRYBCOZ.js +10 -0
  21. package/dist/chunk-55NFNRKO.js +10 -0
  22. package/dist/chunk-5XPCMNGW.js +215 -0
  23. package/dist/chunk-B3M27AMP.js +1479 -0
  24. package/dist/chunk-BB4KXGBU.js +83 -0
  25. package/dist/chunk-C6A6W6XS.js +77 -0
  26. package/dist/chunk-HQ55LN2U.js +318 -0
  27. package/dist/chunk-KNVTCZW7.js +416 -0
  28. package/dist/chunk-LH47WVJL.js +61 -0
  29. package/dist/chunk-NGD2HQYW.js +346 -0
  30. package/dist/chunk-NUDAZEOG.js +35 -0
  31. package/dist/chunk-OZ4XVJ6F.js +49 -0
  32. package/dist/chunk-PHMSPCTC.js +145 -0
  33. package/dist/chunk-PNZK456O.js +88 -0
  34. package/dist/chunk-QAAJAHDB.js +37 -0
  35. package/dist/chunk-RG66XEJT.js +8 -0
  36. package/dist/chunk-SIFBBGY6.js +190 -0
  37. package/dist/chunk-SVEAENO7.js +22 -0
  38. package/dist/chunk-SY5244IR.js +1499 -0
  39. package/dist/chunk-W5HVJX45.js +402 -0
  40. package/dist/chunk-WIBGG4X6.js +173 -0
  41. package/dist/chunk-ZDWFBE5L.js +1 -0
  42. package/dist/chunk-ZINPRHAN.js +22 -0
  43. package/dist/deployer/index.cjs +165 -0
  44. package/dist/deployer/index.d.cts +19 -0
  45. package/dist/deployer/index.d.ts +19 -0
  46. package/dist/deployer/index.js +1 -0
  47. package/dist/eval/index.cjs +110 -0
  48. package/dist/eval/index.d.cts +28 -0
  49. package/dist/eval/index.d.ts +28 -0
  50. package/dist/eval/index.js +1 -0
  51. package/dist/filter/index.cjs +192 -0
  52. package/dist/filter/index.d.cts +90 -0
  53. package/dist/filter/index.d.ts +90 -0
  54. package/dist/filter/index.js +1 -0
  55. package/dist/hooks/index.cjs +87 -0
  56. package/dist/hooks/index.d.cts +33 -0
  57. package/dist/hooks/index.d.ts +33 -0
  58. package/dist/hooks/index.js +1 -0
  59. package/dist/index-mKY1XrpK.d.cts +90 -0
  60. package/dist/index-mKY1XrpK.d.ts +90 -0
  61. package/dist/index.cjs +6844 -0
  62. package/dist/index.d.cts +97 -0
  63. package/dist/index.d.ts +97 -0
  64. package/dist/index.js +119 -0
  65. package/dist/integration/index.cjs +113 -0
  66. package/dist/integration/index.d.cts +52 -0
  67. package/dist/integration/index.d.ts +52 -0
  68. package/dist/integration/index.js +1 -0
  69. package/dist/llm/index.cjs +2 -0
  70. package/dist/llm/index.d.cts +15 -0
  71. package/dist/llm/index.d.ts +15 -0
  72. package/dist/llm/index.js +1 -0
  73. package/dist/logger/index.cjs +159 -0
  74. package/dist/logger/index.d.cts +3 -0
  75. package/dist/logger/index.d.ts +3 -0
  76. package/dist/logger/index.js +1 -0
  77. package/dist/mastra/index.cjs +1741 -0
  78. package/dist/mastra/index.d.cts +67 -0
  79. package/dist/mastra/index.d.ts +67 -0
  80. package/dist/mastra/index.js +1 -0
  81. package/dist/memory/index.cjs +1907 -0
  82. package/dist/memory/index.d.cts +15 -0
  83. package/dist/memory/index.d.ts +15 -0
  84. package/dist/memory/index.js +1 -0
  85. package/dist/relevance/index.cjs +1927 -0
  86. package/dist/relevance/index.d.cts +21 -0
  87. package/dist/relevance/index.d.ts +21 -0
  88. package/dist/relevance/index.js +1 -0
  89. package/dist/storage/index.cjs +361 -0
  90. package/dist/storage/index.d.cts +15 -0
  91. package/dist/storage/index.d.ts +15 -0
  92. package/dist/storage/index.js +2 -0
  93. package/dist/storage/libsql/index.cjs +770 -0
  94. package/dist/storage/libsql/index.d.cts +81 -0
  95. package/dist/storage/libsql/index.d.ts +81 -0
  96. package/dist/storage/libsql/index.js +1 -0
  97. package/dist/telemetry/index.cjs +413 -0
  98. package/dist/telemetry/index.d.cts +51 -0
  99. package/dist/telemetry/index.d.ts +51 -0
  100. package/dist/telemetry/index.js +1 -0
  101. package/dist/telemetry/otel-vendor.cjs +52 -0
  102. package/dist/telemetry/otel-vendor.d.cts +7 -0
  103. package/dist/telemetry/otel-vendor.d.ts +7 -0
  104. package/dist/telemetry/otel-vendor.js +7 -0
  105. package/dist/tools/index.cjs +25 -0
  106. package/dist/tools/index.d.cts +29 -0
  107. package/dist/tools/index.d.ts +29 -0
  108. package/dist/tools/index.js +1 -0
  109. package/dist/tts/index.cjs +328 -0
  110. package/dist/tts/index.d.cts +28 -0
  111. package/dist/tts/index.d.ts +28 -0
  112. package/dist/tts/index.js +1 -0
  113. package/dist/types-m9RryK9a.d.cts +14 -0
  114. package/dist/types-m9RryK9a.d.ts +14 -0
  115. package/dist/utils.cjs +179 -0
  116. package/dist/utils.d.cts +26 -0
  117. package/dist/utils.d.ts +26 -0
  118. package/dist/utils.js +1 -0
  119. package/dist/vector/index.cjs +145 -0
  120. package/dist/vector/index.d.cts +30 -0
  121. package/dist/vector/index.d.ts +30 -0
  122. package/dist/vector/index.js +1 -0
  123. package/dist/vector/libsql/index.cjs +951 -0
  124. package/dist/vector/libsql/index.d.cts +29 -0
  125. package/dist/vector/libsql/index.d.ts +29 -0
  126. package/dist/vector/libsql/index.js +1 -0
  127. package/dist/voice/index.cjs +369 -0
  128. package/dist/voice/index.d.cts +67 -0
  129. package/dist/voice/index.d.ts +67 -0
  130. package/dist/voice/index.js +76 -0
  131. package/dist/workflow-DqQ4pON_.d.cts +84 -0
  132. package/dist/workflow-Ng_F_Zaf.d.ts +84 -0
  133. package/dist/workflows/index.cjs +1628 -0
  134. package/dist/workflows/index.d.cts +48 -0
  135. package/dist/workflows/index.d.ts +48 -0
  136. package/dist/workflows/index.js +1 -0
  137. package/package.json +162 -0
@@ -0,0 +1,81 @@
1
+ import { M as MastraStorage, T as TABLE_NAMES, S as StorageColumn, b as StorageThreadType, c as MessageType, d as StorageGetMessagesArg, E as EvalRow } from '../../base-nhesrHv3.cjs';
2
+ import 'ai';
3
+ import '../../base-hs9NDAZ2.cjs';
4
+ import '@opentelemetry/api';
5
+ import '../../index-mKY1XrpK.cjs';
6
+ import 'stream';
7
+ import 'pino';
8
+ import '@opentelemetry/sdk-trace-base';
9
+ import 'sift';
10
+ import 'zod';
11
+ import 'json-schema';
12
+ import '../../types-m9RryK9a.cjs';
13
+ import '../../vector/index.cjs';
14
+ import '../../voice/index.cjs';
15
+ import '../../tts/index.cjs';
16
+
17
+ interface LibSQLConfig {
18
+ url: string;
19
+ authToken?: string;
20
+ }
21
+ declare class LibSQLStore extends MastraStorage {
22
+ private client;
23
+ constructor({ config }: {
24
+ config: LibSQLConfig;
25
+ });
26
+ protected rewriteDbUrl(url: string): string;
27
+ private getCreateTableSQL;
28
+ createTable({ tableName, schema, }: {
29
+ tableName: TABLE_NAMES;
30
+ schema: Record<string, StorageColumn>;
31
+ }): Promise<void>;
32
+ clearTable({ tableName }: {
33
+ tableName: TABLE_NAMES;
34
+ }): Promise<void>;
35
+ private prepareStatement;
36
+ insert({ tableName, record }: {
37
+ tableName: TABLE_NAMES;
38
+ record: Record<string, any>;
39
+ }): Promise<void>;
40
+ batchInsert({ tableName, records }: {
41
+ tableName: TABLE_NAMES;
42
+ records: Record<string, any>[];
43
+ }): Promise<void>;
44
+ load<R>({ tableName, keys }: {
45
+ tableName: TABLE_NAMES;
46
+ keys: Record<string, string>;
47
+ }): Promise<R | null>;
48
+ getThreadById({ threadId }: {
49
+ threadId: string;
50
+ }): Promise<StorageThreadType | null>;
51
+ getThreadsByResourceId({ resourceId }: {
52
+ resourceId: string;
53
+ }): Promise<StorageThreadType[]>;
54
+ saveThread({ thread }: {
55
+ thread: StorageThreadType;
56
+ }): Promise<StorageThreadType>;
57
+ updateThread({ id, title, metadata, }: {
58
+ id: string;
59
+ title: string;
60
+ metadata: Record<string, unknown>;
61
+ }): Promise<StorageThreadType>;
62
+ deleteThread({ threadId }: {
63
+ threadId: string;
64
+ }): Promise<void>;
65
+ private parseRow;
66
+ getMessages<T extends MessageType[]>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
67
+ saveMessages({ messages }: {
68
+ messages: MessageType[];
69
+ }): Promise<MessageType[]>;
70
+ private transformEvalRow;
71
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
72
+ getTraces({ name, scope, page, perPage, attributes, }?: {
73
+ name?: string;
74
+ scope?: string;
75
+ page: number;
76
+ perPage: number;
77
+ attributes?: Record<string, string>;
78
+ }): Promise<any[]>;
79
+ }
80
+
81
+ export { LibSQLStore as DefaultStorage, type LibSQLConfig, LibSQLStore };
@@ -0,0 +1,81 @@
1
+ import { M as MastraStorage, T as TABLE_NAMES, S as StorageColumn, b as StorageThreadType, c as MessageType, d as StorageGetMessagesArg, E as EvalRow } from '../../base-nKCMCNrM.js';
2
+ import 'ai';
3
+ import '../../base-D90KQ4XI.js';
4
+ import '@opentelemetry/api';
5
+ import '../../index-mKY1XrpK.js';
6
+ import 'stream';
7
+ import 'pino';
8
+ import '@opentelemetry/sdk-trace-base';
9
+ import 'sift';
10
+ import 'zod';
11
+ import 'json-schema';
12
+ import '../../types-m9RryK9a.js';
13
+ import '../../vector/index.js';
14
+ import '../../voice/index.js';
15
+ import '../../tts/index.js';
16
+
17
+ interface LibSQLConfig {
18
+ url: string;
19
+ authToken?: string;
20
+ }
21
+ declare class LibSQLStore extends MastraStorage {
22
+ private client;
23
+ constructor({ config }: {
24
+ config: LibSQLConfig;
25
+ });
26
+ protected rewriteDbUrl(url: string): string;
27
+ private getCreateTableSQL;
28
+ createTable({ tableName, schema, }: {
29
+ tableName: TABLE_NAMES;
30
+ schema: Record<string, StorageColumn>;
31
+ }): Promise<void>;
32
+ clearTable({ tableName }: {
33
+ tableName: TABLE_NAMES;
34
+ }): Promise<void>;
35
+ private prepareStatement;
36
+ insert({ tableName, record }: {
37
+ tableName: TABLE_NAMES;
38
+ record: Record<string, any>;
39
+ }): Promise<void>;
40
+ batchInsert({ tableName, records }: {
41
+ tableName: TABLE_NAMES;
42
+ records: Record<string, any>[];
43
+ }): Promise<void>;
44
+ load<R>({ tableName, keys }: {
45
+ tableName: TABLE_NAMES;
46
+ keys: Record<string, string>;
47
+ }): Promise<R | null>;
48
+ getThreadById({ threadId }: {
49
+ threadId: string;
50
+ }): Promise<StorageThreadType | null>;
51
+ getThreadsByResourceId({ resourceId }: {
52
+ resourceId: string;
53
+ }): Promise<StorageThreadType[]>;
54
+ saveThread({ thread }: {
55
+ thread: StorageThreadType;
56
+ }): Promise<StorageThreadType>;
57
+ updateThread({ id, title, metadata, }: {
58
+ id: string;
59
+ title: string;
60
+ metadata: Record<string, unknown>;
61
+ }): Promise<StorageThreadType>;
62
+ deleteThread({ threadId }: {
63
+ threadId: string;
64
+ }): Promise<void>;
65
+ private parseRow;
66
+ getMessages<T extends MessageType[]>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
67
+ saveMessages({ messages }: {
68
+ messages: MessageType[];
69
+ }): Promise<MessageType[]>;
70
+ private transformEvalRow;
71
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
72
+ getTraces({ name, scope, page, perPage, attributes, }?: {
73
+ name?: string;
74
+ scope?: string;
75
+ page: number;
76
+ perPage: number;
77
+ attributes?: Record<string, string>;
78
+ }): Promise<any[]>;
79
+ }
80
+
81
+ export { LibSQLStore as DefaultStorage, type LibSQLConfig, LibSQLStore };
@@ -0,0 +1 @@
1
+ export { LibSQLStore as DefaultStorage, LibSQLStore } from '../../chunk-KNVTCZW7.js';
@@ -0,0 +1,413 @@
1
+ 'use strict';
2
+
3
+ var api = require('@opentelemetry/api');
4
+ var core = require('@opentelemetry/core');
5
+ var otlpTransformer = require('@opentelemetry/otlp-transformer');
6
+
7
+ // src/telemetry/telemetry.decorators.ts
8
+ function hasActiveTelemetry(tracerName = "default-tracer") {
9
+ try {
10
+ return !!api.trace.getTracer(tracerName);
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ // src/telemetry/telemetry.decorators.ts
17
+ function withSpan(options) {
18
+ return function(_target, propertyKey, descriptor) {
19
+ if (!descriptor || typeof descriptor === "number") return;
20
+ const originalMethod = descriptor.value;
21
+ const methodName = String(propertyKey);
22
+ descriptor.value = function(...args) {
23
+ if (options?.skipIfNoTelemetry && !hasActiveTelemetry(options?.tracerName)) {
24
+ return originalMethod.apply(this, args);
25
+ }
26
+ const tracer = api.trace.getTracer(options?.tracerName ?? "default-tracer");
27
+ let spanName;
28
+ let spanKind;
29
+ if (typeof options === "string") {
30
+ spanName = options;
31
+ } else if (options) {
32
+ spanName = options.spanName || methodName;
33
+ spanKind = options.spanKind;
34
+ } else {
35
+ spanName = methodName;
36
+ }
37
+ const span = tracer.startSpan(spanName, { kind: spanKind });
38
+ let ctx = api.trace.setSpan(api.context.active(), span);
39
+ args.forEach((arg, index) => {
40
+ try {
41
+ span.setAttribute(`${spanName}.argument.${index}`, JSON.stringify(arg));
42
+ } catch {
43
+ span.setAttribute(`${spanName}.argument.${index}`, "[Not Serializable]");
44
+ }
45
+ });
46
+ const currentBaggage = api.propagation.getBaggage(ctx);
47
+ if (currentBaggage?.componentName) {
48
+ span.setAttribute("componentName", currentBaggage?.componentName);
49
+ span.setAttribute("runId", currentBaggage?.runId);
50
+ } else if (this && this.name) {
51
+ span.setAttribute("componentName", this.name);
52
+ span.setAttribute("runId", this.runId);
53
+ ctx = api.propagation.setBaggage(ctx, { componentName: this.name, runId: this.runId });
54
+ }
55
+ let result;
56
+ try {
57
+ result = api.context.with(ctx, () => originalMethod.apply(this, args));
58
+ if (result instanceof Promise) {
59
+ return result.then((resolvedValue) => {
60
+ try {
61
+ span.setAttribute(`${spanName}.result`, JSON.stringify(resolvedValue));
62
+ } catch {
63
+ span.setAttribute(`${spanName}.result`, "[Not Serializable]");
64
+ }
65
+ return resolvedValue;
66
+ }).finally(() => span.end());
67
+ }
68
+ try {
69
+ span.setAttribute(`${spanName}.result`, JSON.stringify(result));
70
+ } catch {
71
+ span.setAttribute(`${spanName}.result`, "[Not Serializable]");
72
+ }
73
+ return result;
74
+ } catch (error) {
75
+ span.setStatus({
76
+ code: api.SpanStatusCode.ERROR,
77
+ message: error instanceof Error ? error.message : "Unknown error"
78
+ });
79
+ if (error instanceof Error) {
80
+ span.recordException(error);
81
+ }
82
+ throw error;
83
+ } finally {
84
+ if (!(result instanceof Promise)) {
85
+ span.end();
86
+ }
87
+ }
88
+ };
89
+ return descriptor;
90
+ };
91
+ }
92
+ function InstrumentClass(options) {
93
+ return function(target) {
94
+ const methods = Object.getOwnPropertyNames(target.prototype);
95
+ methods.forEach((method) => {
96
+ if (options?.excludeMethods?.includes(method) || method === "constructor") return;
97
+ if (options?.methodFilter && !options.methodFilter(method)) return;
98
+ const descriptor = Object.getOwnPropertyDescriptor(target.prototype, method);
99
+ if (descriptor && typeof descriptor.value === "function") {
100
+ Object.defineProperty(
101
+ target.prototype,
102
+ method,
103
+ withSpan({
104
+ spanName: options?.prefix ? `${options.prefix}.${method}` : method,
105
+ skipIfNoTelemetry: true,
106
+ spanKind: options?.spanKind || api.SpanKind.INTERNAL,
107
+ tracerName: options?.tracerName
108
+ })(target, method, descriptor)
109
+ );
110
+ }
111
+ });
112
+ return target;
113
+ };
114
+ }
115
+
116
+ // src/storage/constants.ts
117
+ var TABLE_TRACES = "mastra_traces";
118
+
119
+ // src/telemetry/storage-exporter.ts
120
+ var OTLPTraceExporter = class {
121
+ storage;
122
+ queue = [];
123
+ serializer;
124
+ logger;
125
+ activeFlush = void 0;
126
+ constructor({ logger, storage }) {
127
+ this.storage = storage;
128
+ this.serializer = otlpTransformer.JsonTraceSerializer;
129
+ this.logger = logger;
130
+ }
131
+ export(internalRepresentation, resultCallback) {
132
+ const serializedRequest = this.serializer.serializeRequest(internalRepresentation);
133
+ const payload = JSON.parse(Buffer.from(serializedRequest.buffer, "utf8"));
134
+ const items = payload?.resourceSpans?.[0]?.scopeSpans;
135
+ this.logger.debug(`Exporting telemetry: ${items.length} scope spans to be processed [trace batch]`);
136
+ this.queue.push({ data: items, resultCallback });
137
+ if (!this.activeFlush) {
138
+ this.activeFlush = this.flush();
139
+ }
140
+ }
141
+ shutdown() {
142
+ return this.forceFlush();
143
+ }
144
+ flush() {
145
+ const now = /* @__PURE__ */ new Date();
146
+ const items = this.queue.shift();
147
+ if (!items) return Promise.resolve();
148
+ const allSpans = items.data.reduce((acc, scopedSpans) => {
149
+ const { scope, spans } = scopedSpans;
150
+ for (const span of spans) {
151
+ const {
152
+ spanId,
153
+ parentSpanId,
154
+ traceId,
155
+ name,
156
+ kind,
157
+ attributes,
158
+ status,
159
+ events,
160
+ links,
161
+ startTimeUnixNano,
162
+ endTimeUnixNano,
163
+ ...rest
164
+ } = span;
165
+ const startTime = Number(BigInt(startTimeUnixNano) / 1000n);
166
+ const endTime = Number(BigInt(endTimeUnixNano) / 1000n);
167
+ acc.push({
168
+ id: spanId,
169
+ parentSpanId,
170
+ traceId,
171
+ name,
172
+ scope: scope.name,
173
+ kind,
174
+ status: JSON.stringify(status),
175
+ events: JSON.stringify(events),
176
+ links: JSON.stringify(links),
177
+ attributes: JSON.stringify(
178
+ attributes.reduce((acc2, attr) => {
179
+ const valueKey = Object.keys(attr.value)[0];
180
+ if (valueKey) {
181
+ acc2[attr.key] = attr.value[valueKey];
182
+ }
183
+ return acc2;
184
+ }, {})
185
+ ),
186
+ startTime,
187
+ endTime,
188
+ other: JSON.stringify(rest),
189
+ createdAt: now
190
+ });
191
+ }
192
+ return acc;
193
+ }, []);
194
+ return this.storage.__batchInsert({
195
+ tableName: TABLE_TRACES,
196
+ records: allSpans
197
+ }).then(() => {
198
+ items.resultCallback({
199
+ code: core.ExportResultCode.SUCCESS
200
+ });
201
+ }).catch((e) => {
202
+ this.logger.error("span err:" + e?.message);
203
+ items.resultCallback({
204
+ code: core.ExportResultCode.FAILED,
205
+ error: e
206
+ });
207
+ }).finally(() => {
208
+ this.activeFlush = void 0;
209
+ });
210
+ }
211
+ async forceFlush() {
212
+ if (!this.queue.length) {
213
+ return;
214
+ }
215
+ await this.activeFlush;
216
+ while (this.queue.length) {
217
+ await this.flush();
218
+ }
219
+ }
220
+ __setLogger(logger) {
221
+ this.logger = logger;
222
+ }
223
+ };
224
+ var Telemetry = class _Telemetry {
225
+ tracer = api.trace.getTracer("default");
226
+ name = "default-service";
227
+ constructor(config) {
228
+ this.name = config.serviceName ?? "default-service";
229
+ this.tracer = api.trace.getTracer(this.name);
230
+ }
231
+ /**
232
+ * @deprecated This method does not do anything
233
+ */
234
+ async shutdown() {
235
+ }
236
+ /**
237
+ * Initialize telemetry with the given configuration
238
+ * @param config - Optional telemetry configuration object
239
+ * @returns Telemetry instance that can be used for tracing
240
+ */
241
+ static init(config = {}) {
242
+ try {
243
+ if (!global.__TELEMETRY__) {
244
+ global.__TELEMETRY__ = new _Telemetry(config);
245
+ }
246
+ return global.__TELEMETRY__;
247
+ } catch (error) {
248
+ console.error("Failed to initialize telemetry:", error);
249
+ throw error;
250
+ }
251
+ }
252
+ /**
253
+ * Get the global telemetry instance
254
+ * @throws {Error} If telemetry has not been initialized
255
+ * @returns {Telemetry} The global telemetry instance
256
+ */
257
+ static get() {
258
+ if (!global.__TELEMETRY__) {
259
+ throw new Error("Telemetry not initialized");
260
+ }
261
+ return global.__TELEMETRY__;
262
+ }
263
+ /**
264
+ * Wraps a class instance with telemetry tracing
265
+ * @param instance The class instance to wrap
266
+ * @param options Optional configuration for tracing
267
+ * @returns Wrapped instance with all methods traced
268
+ */
269
+ traceClass(instance, options = {}) {
270
+ const { skipIfNoTelemetry = true } = options;
271
+ if (skipIfNoTelemetry && !hasActiveTelemetry()) {
272
+ return instance;
273
+ }
274
+ const { spanNamePrefix = instance.constructor.name.toLowerCase(), attributes = {}, excludeMethods = [] } = options;
275
+ return new Proxy(instance, {
276
+ get: (target, prop) => {
277
+ const value = target[prop];
278
+ if (typeof value === "function" && prop !== "constructor" && !prop.toString().startsWith("_") && !excludeMethods.includes(prop.toString())) {
279
+ return this.traceMethod(value.bind(target), {
280
+ spanName: `${spanNamePrefix}.${prop.toString()}`,
281
+ attributes: {
282
+ ...attributes,
283
+ [`${spanNamePrefix}.name`]: target.constructor.name,
284
+ [`${spanNamePrefix}.method.name`]: prop.toString()
285
+ }
286
+ });
287
+ }
288
+ return value;
289
+ }
290
+ });
291
+ }
292
+ /**
293
+ * method to trace individual methods with proper context
294
+ * @param method The method to trace
295
+ * @param context Additional context for the trace
296
+ * @returns Wrapped method with tracing
297
+ */
298
+ traceMethod(method, context3) {
299
+ let ctx = api.context.active();
300
+ const { skipIfNoTelemetry = true } = context3;
301
+ if (skipIfNoTelemetry && !hasActiveTelemetry()) {
302
+ return method;
303
+ }
304
+ return (...args) => {
305
+ const span = this.tracer.startSpan(context3.spanName);
306
+ function handleError(error) {
307
+ span.recordException(error);
308
+ span.setStatus({
309
+ code: api.SpanStatusCode.ERROR,
310
+ message: error.message
311
+ });
312
+ span.end();
313
+ throw error;
314
+ }
315
+ try {
316
+ let recordResult2 = function(res) {
317
+ try {
318
+ span.setAttribute(`${context3.spanName}.result`, JSON.stringify(res));
319
+ } catch {
320
+ span.setAttribute(`${context3.spanName}.result`, "[Not Serializable]");
321
+ }
322
+ span.end();
323
+ return res;
324
+ };
325
+ if (context3.attributes) {
326
+ span.setAttributes(context3.attributes);
327
+ }
328
+ if (context3.attributes?.componentName) {
329
+ ctx = api.propagation.setBaggage(ctx, {
330
+ // @ts-ignore
331
+ componentName: context3.attributes.componentName,
332
+ runId: context3.attributes.runId
333
+ });
334
+ } else {
335
+ const currentBaggage = api.propagation.getBaggage(ctx);
336
+ if (currentBaggage?.componentName) {
337
+ span.setAttribute("componentName", currentBaggage?.componentName);
338
+ span.setAttribute("runId", currentBaggage?.runId);
339
+ } else if (this && this.name) {
340
+ span.setAttribute("componentName", this.name);
341
+ span.setAttribute("runId", this.runId);
342
+ ctx = api.propagation.setBaggage(ctx, { componentName: this.name, runId: this.runId });
343
+ }
344
+ }
345
+ args.forEach((arg, index) => {
346
+ try {
347
+ span.setAttribute(`${context3.spanName}.argument.${index}`, JSON.stringify(arg));
348
+ } catch {
349
+ span.setAttribute(`${context3.spanName}.argument.${index}`, "[Not Serializable]");
350
+ }
351
+ });
352
+ let result;
353
+ api.context.with(api.trace.setSpan(ctx, span), () => {
354
+ result = method(...args);
355
+ });
356
+ if (result instanceof Promise) {
357
+ return result.then(recordResult2).catch(handleError);
358
+ } else {
359
+ return recordResult2(result);
360
+ }
361
+ } catch (error) {
362
+ handleError(error);
363
+ }
364
+ };
365
+ }
366
+ getBaggageTracer() {
367
+ return new BaggageTracer(this.tracer);
368
+ }
369
+ };
370
+ var BaggageTracer = class {
371
+ _tracer;
372
+ constructor(tracer) {
373
+ this._tracer = tracer;
374
+ }
375
+ startSpan(name, options = {}, ctx) {
376
+ ctx = ctx ?? api.context.active();
377
+ const span = this._tracer.startSpan(name, options, ctx);
378
+ const currentBaggage = api.propagation.getBaggage(ctx);
379
+ span.setAttribute("componentName", currentBaggage?.componentName);
380
+ span.setAttribute("runId", currentBaggage?.runId);
381
+ return span;
382
+ }
383
+ startActiveSpan(name, optionsOrFn, ctxOrFn, fn) {
384
+ if (typeof optionsOrFn === "function") {
385
+ const wrappedFn2 = (span) => {
386
+ const currentBaggage = api.propagation.getBaggage(api.context.active());
387
+ span.setAttribute("componentName", currentBaggage?.componentName);
388
+ return optionsOrFn(span);
389
+ };
390
+ return this._tracer.startActiveSpan(name, {}, api.context.active(), wrappedFn2);
391
+ }
392
+ if (typeof ctxOrFn === "function") {
393
+ const wrappedFn2 = (span) => {
394
+ const currentBaggage = api.propagation.getBaggage(api.context.active());
395
+ span.setAttribute("componentName", currentBaggage?.componentName);
396
+ return ctxOrFn(span);
397
+ };
398
+ return this._tracer.startActiveSpan(name, optionsOrFn, api.context.active(), wrappedFn2);
399
+ }
400
+ const wrappedFn = (span) => {
401
+ const currentBaggage = api.propagation.getBaggage(ctxOrFn ?? api.context.active());
402
+ span.setAttribute("componentName", currentBaggage?.componentName);
403
+ return fn(span);
404
+ };
405
+ return this._tracer.startActiveSpan(name, optionsOrFn, ctxOrFn, wrappedFn);
406
+ }
407
+ };
408
+
409
+ exports.InstrumentClass = InstrumentClass;
410
+ exports.OTLPStorageExporter = OTLPTraceExporter;
411
+ exports.Telemetry = Telemetry;
412
+ exports.hasActiveTelemetry = hasActiveTelemetry;
413
+ exports.withSpan = withSpan;
@@ -0,0 +1,51 @@
1
+ export { O as OtelConfig, S as SamplingStrategy, T as Telemetry } from '../base-hs9NDAZ2.cjs';
2
+ import { SpanKind } from '@opentelemetry/api';
3
+ import { ExportResult } from '@opentelemetry/core';
4
+ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
5
+ import { L as Logger } from '../index-mKY1XrpK.cjs';
6
+ import { M as MastraStorage } from '../base-nhesrHv3.cjs';
7
+ import 'stream';
8
+ import 'pino';
9
+ import 'ai';
10
+ import 'sift';
11
+ import 'zod';
12
+ import 'json-schema';
13
+ import '../types-m9RryK9a.cjs';
14
+ import '../vector/index.cjs';
15
+ import '../voice/index.cjs';
16
+ import '../tts/index.cjs';
17
+
18
+ declare function withSpan(options: {
19
+ spanName?: string;
20
+ skipIfNoTelemetry?: boolean;
21
+ spanKind?: SpanKind;
22
+ tracerName?: string;
23
+ }): any;
24
+ declare function InstrumentClass(options?: {
25
+ prefix?: string;
26
+ spanKind?: SpanKind;
27
+ excludeMethods?: string[];
28
+ methodFilter?: (methodName: string) => boolean;
29
+ tracerName?: string;
30
+ }): (target: any) => any;
31
+
32
+ declare function hasActiveTelemetry(tracerName?: string): boolean;
33
+
34
+ declare class OTLPTraceExporter implements SpanExporter {
35
+ private storage;
36
+ private queue;
37
+ private serializer;
38
+ private logger;
39
+ private activeFlush;
40
+ constructor({ logger, storage }: {
41
+ logger: Logger;
42
+ storage: MastraStorage;
43
+ });
44
+ export(internalRepresentation: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
45
+ shutdown(): Promise<void>;
46
+ flush(): Promise<void>;
47
+ forceFlush(): Promise<void>;
48
+ __setLogger(logger: Logger): void;
49
+ }
50
+
51
+ export { InstrumentClass, OTLPTraceExporter as OTLPStorageExporter, hasActiveTelemetry, withSpan };
@@ -0,0 +1,51 @@
1
+ export { O as OtelConfig, S as SamplingStrategy, T as Telemetry } from '../base-D90KQ4XI.js';
2
+ import { SpanKind } from '@opentelemetry/api';
3
+ import { ExportResult } from '@opentelemetry/core';
4
+ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
5
+ import { L as Logger } from '../index-mKY1XrpK.js';
6
+ import { M as MastraStorage } from '../base-nKCMCNrM.js';
7
+ import 'stream';
8
+ import 'pino';
9
+ import 'ai';
10
+ import 'sift';
11
+ import 'zod';
12
+ import 'json-schema';
13
+ import '../types-m9RryK9a.js';
14
+ import '../vector/index.js';
15
+ import '../voice/index.js';
16
+ import '../tts/index.js';
17
+
18
+ declare function withSpan(options: {
19
+ spanName?: string;
20
+ skipIfNoTelemetry?: boolean;
21
+ spanKind?: SpanKind;
22
+ tracerName?: string;
23
+ }): any;
24
+ declare function InstrumentClass(options?: {
25
+ prefix?: string;
26
+ spanKind?: SpanKind;
27
+ excludeMethods?: string[];
28
+ methodFilter?: (methodName: string) => boolean;
29
+ tracerName?: string;
30
+ }): (target: any) => any;
31
+
32
+ declare function hasActiveTelemetry(tracerName?: string): boolean;
33
+
34
+ declare class OTLPTraceExporter implements SpanExporter {
35
+ private storage;
36
+ private queue;
37
+ private serializer;
38
+ private logger;
39
+ private activeFlush;
40
+ constructor({ logger, storage }: {
41
+ logger: Logger;
42
+ storage: MastraStorage;
43
+ });
44
+ export(internalRepresentation: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
45
+ shutdown(): Promise<void>;
46
+ flush(): Promise<void>;
47
+ forceFlush(): Promise<void>;
48
+ __setLogger(logger: Logger): void;
49
+ }
50
+
51
+ export { InstrumentClass, OTLPTraceExporter as OTLPStorageExporter, hasActiveTelemetry, withSpan };
@@ -0,0 +1 @@
1
+ export { InstrumentClass, OTLPTraceExporter as OTLPStorageExporter, Telemetry, hasActiveTelemetry, withSpan } from '../chunk-W5HVJX45.js';