@mastra/core 0.16.3 → 0.16.4-alpha.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 (151) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/agent/agent.d.ts +1 -1
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.types.d.ts +7 -1
  5. package/dist/agent/agent.types.d.ts.map +1 -1
  6. package/dist/agent/index.cjs +11 -11
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/input-processor/index.cjs +6 -6
  9. package/dist/agent/input-processor/index.js +1 -1
  10. package/dist/ai-tracing/exporters/cloud.d.ts.map +1 -1
  11. package/dist/ai-tracing/exporters/default.d.ts.map +1 -1
  12. package/dist/ai-tracing/index.cjs +42 -30
  13. package/dist/ai-tracing/index.d.ts +3 -2
  14. package/dist/ai-tracing/index.d.ts.map +1 -1
  15. package/dist/ai-tracing/index.js +1 -1
  16. package/dist/ai-tracing/registry.d.ts +11 -12
  17. package/dist/ai-tracing/registry.d.ts.map +1 -1
  18. package/dist/ai-tracing/span_processors/index.d.ts +5 -0
  19. package/dist/ai-tracing/span_processors/index.d.ts.map +1 -0
  20. package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts +79 -0
  21. package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts.map +1 -0
  22. package/dist/ai-tracing/spans/base.d.ts +59 -0
  23. package/dist/ai-tracing/spans/base.d.ts.map +1 -0
  24. package/dist/ai-tracing/spans/default.d.ts +13 -0
  25. package/dist/ai-tracing/spans/default.d.ts.map +1 -0
  26. package/dist/ai-tracing/spans/index.d.ts +7 -0
  27. package/dist/ai-tracing/spans/index.d.ts.map +1 -0
  28. package/dist/ai-tracing/spans/no-op.d.ts +15 -0
  29. package/dist/ai-tracing/spans/no-op.d.ts.map +1 -0
  30. package/dist/ai-tracing/{base.d.ts → tracers/base.d.ts} +11 -24
  31. package/dist/ai-tracing/tracers/base.d.ts.map +1 -0
  32. package/dist/ai-tracing/tracers/default.d.ts +7 -0
  33. package/dist/ai-tracing/tracers/default.d.ts.map +1 -0
  34. package/dist/ai-tracing/tracers/index.d.ts +6 -0
  35. package/dist/ai-tracing/tracers/index.d.ts.map +1 -0
  36. package/dist/ai-tracing/types.d.ts +181 -97
  37. package/dist/ai-tracing/types.d.ts.map +1 -1
  38. package/dist/ai-tracing/utils.d.ts +13 -30
  39. package/dist/ai-tracing/utils.d.ts.map +1 -1
  40. package/dist/{chunk-37GX66ZQ.cjs → chunk-2S2YFQ3W.cjs} +7 -7
  41. package/dist/{chunk-37GX66ZQ.cjs.map → chunk-2S2YFQ3W.cjs.map} +1 -1
  42. package/dist/{chunk-2LEMTQEN.cjs → chunk-6ACAYXAV.cjs} +4 -4
  43. package/dist/{chunk-2LEMTQEN.cjs.map → chunk-6ACAYXAV.cjs.map} +1 -1
  44. package/dist/{chunk-YW7UILPE.js → chunk-A3QHQYMC.js} +9 -4
  45. package/dist/chunk-A3QHQYMC.js.map +1 -0
  46. package/dist/{chunk-DWGGSV3L.js → chunk-BVE3UPHV.js} +4 -4
  47. package/dist/{chunk-DWGGSV3L.js.map → chunk-BVE3UPHV.js.map} +1 -1
  48. package/dist/{chunk-I77GWNQI.cjs → chunk-DUUXEPE5.cjs} +4 -4
  49. package/dist/{chunk-I77GWNQI.cjs.map → chunk-DUUXEPE5.cjs.map} +1 -1
  50. package/dist/{chunk-VVUCWRGD.cjs → chunk-ERRIEUC2.cjs} +415 -371
  51. package/dist/chunk-ERRIEUC2.cjs.map +1 -0
  52. package/dist/{chunk-AV5QBG6P.cjs → chunk-GJKL73EJ.cjs} +14 -10
  53. package/dist/chunk-GJKL73EJ.cjs.map +1 -0
  54. package/dist/{chunk-SLQGF75B.js → chunk-MS6HHGRW.js} +3 -3
  55. package/dist/{chunk-SLQGF75B.js.map → chunk-MS6HHGRW.js.map} +1 -1
  56. package/dist/{chunk-WAN6BRTN.js → chunk-O5GOFG6A.js} +11 -7
  57. package/dist/chunk-O5GOFG6A.js.map +1 -0
  58. package/dist/{chunk-W5K2KOZX.js → chunk-ODLGLX2R.js} +410 -369
  59. package/dist/chunk-ODLGLX2R.js.map +1 -0
  60. package/dist/{chunk-HHRWDBFK.js → chunk-OSMP67E2.js} +27 -24
  61. package/dist/chunk-OSMP67E2.js.map +1 -0
  62. package/dist/{chunk-S6MAHT7F.cjs → chunk-OXAN5SM7.cjs} +9 -4
  63. package/dist/chunk-OXAN5SM7.cjs.map +1 -0
  64. package/dist/{chunk-BE6HGZV7.js → chunk-P5BVWWMV.js} +3 -3
  65. package/dist/{chunk-BE6HGZV7.js.map → chunk-P5BVWWMV.js.map} +1 -1
  66. package/dist/{chunk-6ILOFPTU.js → chunk-SWI3TK2R.js} +21 -141
  67. package/dist/chunk-SWI3TK2R.js.map +1 -0
  68. package/dist/{chunk-3CYEVZGC.cjs → chunk-VH3RNDZA.cjs} +6 -6
  69. package/dist/{chunk-3CYEVZGC.cjs.map → chunk-VH3RNDZA.cjs.map} +1 -1
  70. package/dist/{chunk-46ZMVRXN.js → chunk-XKXZ6I72.js} +5 -5
  71. package/dist/chunk-XKXZ6I72.js.map +1 -0
  72. package/dist/{chunk-PPMRSBCA.cjs → chunk-Z3DIAA2J.cjs} +25 -145
  73. package/dist/chunk-Z3DIAA2J.cjs.map +1 -0
  74. package/dist/{chunk-7ARB2XCY.js → chunk-ZDMAOD35.js} +3 -3
  75. package/dist/{chunk-7ARB2XCY.js.map → chunk-ZDMAOD35.js.map} +1 -1
  76. package/dist/{chunk-VK7LOYGD.cjs → chunk-ZJRDXVAR.cjs} +12 -12
  77. package/dist/chunk-ZJRDXVAR.cjs.map +1 -0
  78. package/dist/{chunk-CM4UEIAB.cjs → chunk-ZL6RHYVT.cjs} +51 -48
  79. package/dist/chunk-ZL6RHYVT.cjs.map +1 -0
  80. package/dist/index.cjs +38 -38
  81. package/dist/index.js +7 -7
  82. package/dist/llm/model/model.d.ts.map +1 -1
  83. package/dist/llm/model/model.loop.d.ts.map +1 -1
  84. package/dist/loop/index.cjs +2 -2
  85. package/dist/loop/index.js +1 -1
  86. package/dist/loop/network/index.d.ts +2 -1
  87. package/dist/loop/network/index.d.ts.map +1 -1
  88. package/dist/mastra/index.cjs +2 -2
  89. package/dist/mastra/index.d.ts +2 -2
  90. package/dist/mastra/index.d.ts.map +1 -1
  91. package/dist/mastra/index.js +1 -1
  92. package/dist/memory/index.cjs +4 -4
  93. package/dist/memory/index.js +1 -1
  94. package/dist/network/index.cjs +2 -2
  95. package/dist/network/index.js +1 -1
  96. package/dist/network/vNext/index.cjs +29 -29
  97. package/dist/network/vNext/index.js +2 -2
  98. package/dist/processors/index.cjs +8 -8
  99. package/dist/processors/index.js +2 -2
  100. package/dist/relevance/index.cjs +4 -4
  101. package/dist/relevance/index.js +1 -1
  102. package/dist/scores/index.cjs +8 -8
  103. package/dist/scores/index.js +1 -1
  104. package/dist/server/types.d.ts +3 -0
  105. package/dist/server/types.d.ts.map +1 -1
  106. package/dist/storage/index.cjs +3 -3
  107. package/dist/storage/index.js +1 -1
  108. package/dist/stream/MastraAgentNetworkStream.d.ts +18 -0
  109. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -0
  110. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  111. package/dist/stream/base/output.d.ts.map +1 -1
  112. package/dist/stream/index.cjs +3 -3
  113. package/dist/stream/index.js +1 -1
  114. package/dist/test-utils/llm-mock.cjs +2 -2
  115. package/dist/test-utils/llm-mock.js +1 -1
  116. package/dist/tools/index.cjs +2 -2
  117. package/dist/tools/index.js +1 -1
  118. package/dist/tools/stream.d.ts.map +1 -1
  119. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  120. package/dist/utils.cjs +17 -17
  121. package/dist/utils.js +1 -1
  122. package/dist/workflows/default.d.ts.map +1 -1
  123. package/dist/workflows/evented/index.cjs +10 -10
  124. package/dist/workflows/evented/index.js +1 -1
  125. package/dist/workflows/evented/workflow.d.ts +1 -21
  126. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  127. package/dist/workflows/index.cjs +10 -10
  128. package/dist/workflows/index.js +1 -1
  129. package/dist/workflows/legacy/index.cjs +22 -22
  130. package/dist/workflows/legacy/index.js +1 -1
  131. package/dist/workflows/types.d.ts +3 -14
  132. package/dist/workflows/types.d.ts.map +1 -1
  133. package/dist/workflows/workflow.d.ts.map +1 -1
  134. package/package.json +1 -1
  135. package/dist/ai-tracing/base.d.ts.map +0 -1
  136. package/dist/ai-tracing/default.d.ts +0 -17
  137. package/dist/ai-tracing/default.d.ts.map +0 -1
  138. package/dist/ai-tracing/no-op.d.ts +0 -62
  139. package/dist/ai-tracing/no-op.d.ts.map +0 -1
  140. package/dist/chunk-46ZMVRXN.js.map +0 -1
  141. package/dist/chunk-6ILOFPTU.js.map +0 -1
  142. package/dist/chunk-AV5QBG6P.cjs.map +0 -1
  143. package/dist/chunk-CM4UEIAB.cjs.map +0 -1
  144. package/dist/chunk-HHRWDBFK.js.map +0 -1
  145. package/dist/chunk-PPMRSBCA.cjs.map +0 -1
  146. package/dist/chunk-S6MAHT7F.cjs.map +0 -1
  147. package/dist/chunk-VK7LOYGD.cjs.map +0 -1
  148. package/dist/chunk-VVUCWRGD.cjs.map +0 -1
  149. package/dist/chunk-W5K2KOZX.js.map +0 -1
  150. package/dist/chunk-WAN6BRTN.js.map +0 -1
  151. package/dist/chunk-YW7UILPE.js.map +0 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  var chunkGPWMM745_cjs = require('./chunk-GPWMM745.cjs');
4
4
  var chunkC73WLCY3_cjs = require('./chunk-C73WLCY3.cjs');
5
- var chunkS6MAHT7F_cjs = require('./chunk-S6MAHT7F.cjs');
5
+ var chunkOXAN5SM7_cjs = require('./chunk-OXAN5SM7.cjs');
6
6
  var chunkABRPHTOG_cjs = require('./chunk-ABRPHTOG.cjs');
7
7
  var chunkKXCUCBEI_cjs = require('./chunk-KXCUCBEI.cjs');
8
8
  var chunkV5WKCX3G_cjs = require('./chunk-V5WKCX3G.cjs');
@@ -15,51 +15,238 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
15
 
16
16
  var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
17
17
 
18
- // src/ai-tracing/no-op.ts
19
- var NoOpAISpan = class _NoOpAISpan {
20
- id;
18
+ // src/ai-tracing/spans/base.ts
19
+ var BaseAISpan = class {
21
20
  name;
22
21
  type;
23
22
  attributes;
24
23
  parent;
25
- traceId;
26
24
  startTime;
27
25
  endTime;
28
26
  isEvent;
27
+ isInternal;
29
28
  aiTracing;
30
29
  input;
31
30
  output;
32
31
  errorInfo;
33
32
  metadata;
34
33
  constructor(options, aiTracing) {
35
- this.id = "no-op";
36
34
  this.name = options.name;
37
35
  this.type = options.type;
38
- this.attributes = options.attributes || {};
39
- this.metadata = options.metadata;
36
+ this.attributes = deepClean(options.attributes) || {};
37
+ this.metadata = deepClean(options.metadata);
40
38
  this.parent = options.parent;
41
- this.traceId = "no-op-trace";
42
39
  this.startTime = /* @__PURE__ */ new Date();
43
40
  this.aiTracing = aiTracing;
44
- this.input = options.input;
45
- this.output = options.isEvent ? options.output : void 0;
46
- this.isEvent = options.isEvent;
47
- }
48
- end(_options) {
49
- }
50
- error(_options) {
41
+ this.isEvent = options.isEvent ?? false;
42
+ this.isInternal = options.isInternal ?? false;
43
+ if (this.isEvent) {
44
+ this.output = deepClean(options.output);
45
+ } else {
46
+ this.input = deepClean(options.input);
47
+ }
51
48
  }
52
49
  createChildSpan(options) {
53
- return new _NoOpAISpan({ ...options, parent: this, isEvent: false }, this.aiTracing);
50
+ return this.aiTracing.startSpan({ ...options, parent: this, isEvent: false });
54
51
  }
55
52
  createEventSpan(options) {
56
- return new _NoOpAISpan({ ...options, parent: this, isEvent: true }, this.aiTracing);
57
- }
58
- update(_options) {
53
+ return this.aiTracing.startSpan({ ...options, parent: this, isEvent: true });
59
54
  }
55
+ /** Returns `TRUE` if the span is the root span of a trace */
60
56
  get isRootSpan() {
61
57
  return !this.parent;
62
58
  }
59
+ /** Get the closest parent spanId that isn't an internal span */
60
+ getParentSpanId(includeInternalSpans) {
61
+ if (!this.parent) return void 0;
62
+ if (includeInternalSpans) return this.parent.id;
63
+ if (this.parent.isInternal) return this.parent.getParentSpanId(includeInternalSpans);
64
+ return this.parent.id;
65
+ }
66
+ /** Returns a lightweight span ready for export */
67
+ exportSpan(includeInternalSpans) {
68
+ return {
69
+ id: this.id,
70
+ traceId: this.traceId,
71
+ name: this.name,
72
+ type: this.type,
73
+ attributes: this.attributes,
74
+ metadata: this.metadata,
75
+ startTime: this.startTime,
76
+ endTime: this.endTime,
77
+ input: this.input,
78
+ output: this.output,
79
+ errorInfo: this.errorInfo,
80
+ isEvent: this.isEvent,
81
+ isRootSpan: this.isRootSpan,
82
+ parentSpanId: this.getParentSpanId(includeInternalSpans)
83
+ };
84
+ }
85
+ };
86
+ var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
87
+ "logger",
88
+ "experimental_providerMetadata",
89
+ "providerMetadata",
90
+ "steps",
91
+ "tracingContext"
92
+ ]);
93
+ function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
94
+ const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
95
+ if (_depth > maxDepth) {
96
+ return "[MaxDepth]";
97
+ }
98
+ if (value === null || typeof value !== "object") {
99
+ try {
100
+ JSON.stringify(value);
101
+ return value;
102
+ } catch (error) {
103
+ return `[${error instanceof Error ? error.message : String(error)}]`;
104
+ }
105
+ }
106
+ if (_seen.has(value)) {
107
+ return "[Circular]";
108
+ }
109
+ _seen.add(value);
110
+ if (Array.isArray(value)) {
111
+ return value.map((item) => deepClean(item, options, _seen, _depth + 1));
112
+ }
113
+ const cleaned = {};
114
+ for (const [key, val] of Object.entries(value)) {
115
+ if (keysToStrip.has(key)) {
116
+ continue;
117
+ }
118
+ try {
119
+ cleaned[key] = deepClean(val, options, _seen, _depth + 1);
120
+ } catch (error) {
121
+ cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
122
+ }
123
+ }
124
+ return cleaned;
125
+ }
126
+
127
+ // src/ai-tracing/spans/default.ts
128
+ var DefaultAISpan = class extends BaseAISpan {
129
+ id;
130
+ traceId;
131
+ constructor(options, aiTracing) {
132
+ super(options, aiTracing);
133
+ this.id = generateSpanId();
134
+ if (!options.parent) {
135
+ this.traceId = generateTraceId();
136
+ } else {
137
+ this.traceId = options.parent.traceId;
138
+ }
139
+ }
140
+ end(options) {
141
+ if (this.isEvent) {
142
+ return;
143
+ }
144
+ this.endTime = /* @__PURE__ */ new Date();
145
+ if (options?.output !== void 0) {
146
+ this.output = deepClean(options.output);
147
+ }
148
+ if (options?.attributes) {
149
+ this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
150
+ }
151
+ if (options?.metadata) {
152
+ this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
153
+ }
154
+ }
155
+ error(options) {
156
+ if (this.isEvent) {
157
+ return;
158
+ }
159
+ const { error, endSpan = true, attributes, metadata } = options;
160
+ this.errorInfo = error instanceof chunkC73WLCY3_cjs.MastraError ? {
161
+ id: error.id,
162
+ details: error.details,
163
+ category: error.category,
164
+ domain: error.domain,
165
+ message: error.message
166
+ } : {
167
+ message: error.message
168
+ };
169
+ if (attributes) {
170
+ this.attributes = { ...this.attributes, ...deepClean(attributes) };
171
+ }
172
+ if (metadata) {
173
+ this.metadata = { ...this.metadata, ...deepClean(metadata) };
174
+ }
175
+ if (endSpan) {
176
+ this.end();
177
+ } else {
178
+ this.update({});
179
+ }
180
+ }
181
+ update(options) {
182
+ if (this.isEvent) {
183
+ return;
184
+ }
185
+ if (options.input !== void 0) {
186
+ this.input = deepClean(options.input);
187
+ }
188
+ if (options.output !== void 0) {
189
+ this.output = deepClean(options.output);
190
+ }
191
+ if (options.attributes) {
192
+ this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
193
+ }
194
+ if (options.metadata) {
195
+ this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
196
+ }
197
+ }
198
+ get isValid() {
199
+ return true;
200
+ }
201
+ async export() {
202
+ return JSON.stringify({
203
+ spanId: this.id,
204
+ traceId: this.traceId,
205
+ startTime: this.startTime,
206
+ endTime: this.endTime,
207
+ attributes: this.attributes,
208
+ metadata: this.metadata
209
+ });
210
+ }
211
+ };
212
+ function generateSpanId() {
213
+ const bytes = new Uint8Array(8);
214
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
215
+ crypto.getRandomValues(bytes);
216
+ } else {
217
+ for (let i = 0; i < 8; i++) {
218
+ bytes[i] = Math.floor(Math.random() * 256);
219
+ }
220
+ }
221
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
222
+ }
223
+ function generateTraceId() {
224
+ const bytes = new Uint8Array(16);
225
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
226
+ crypto.getRandomValues(bytes);
227
+ } else {
228
+ for (let i = 0; i < 16; i++) {
229
+ bytes[i] = Math.floor(Math.random() * 256);
230
+ }
231
+ }
232
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
233
+ }
234
+
235
+ // src/ai-tracing/spans/no-op.ts
236
+ var NoOpAISpan = class extends BaseAISpan {
237
+ id;
238
+ traceId;
239
+ constructor(options, aiTracing) {
240
+ super(options, aiTracing);
241
+ this.id = "no-op";
242
+ this.traceId = "no-op-trace";
243
+ }
244
+ end(_options) {
245
+ }
246
+ error(_options) {
247
+ }
248
+ update(_options) {
249
+ }
63
250
  get isValid() {
64
251
  return false;
65
252
  }
@@ -97,8 +284,8 @@ var AITracingEventType = /* @__PURE__ */ ((AITracingEventType2) => {
97
284
  return AITracingEventType2;
98
285
  })(AITracingEventType || {});
99
286
 
100
- // src/ai-tracing/base.ts
101
- var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
287
+ // src/ai-tracing/tracers/base.ts
288
+ var BaseAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
102
289
  config;
103
290
  constructor(config) {
104
291
  super({ component: chunkV5WKCX3G_cjs.RegisteredLogger.AI_TRACING, name: config.serviceName });
@@ -107,7 +294,8 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
107
294
  name: config.name,
108
295
  sampling: config.sampling ?? { type: "always" /* ALWAYS */ },
109
296
  exporters: config.exporters ?? [],
110
- processors: config.processors ?? []
297
+ processors: config.processors ?? [],
298
+ includeInternalSpans: config.includeInternalSpans ?? false
111
299
  };
112
300
  }
113
301
  /**
@@ -135,25 +323,11 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
135
323
  * Start a new span of a specific AISpanType
136
324
  */
137
325
  startSpan(options) {
138
- const { type, name, input, output, attributes, metadata, parent, startOptions, isEvent } = options;
139
- const { runtimeContext } = startOptions || {};
140
- if (!this.shouldSample({ runtimeContext })) {
141
- return new NoOpAISpan(
142
- { type, name, input, output, attributes, metadata, parent, isEvent: isEvent === true },
143
- this
144
- );
326
+ const { customSamplerOptions, ...createSpanOptions } = options;
327
+ if (!this.shouldSample(customSamplerOptions)) {
328
+ return new NoOpAISpan(createSpanOptions, this);
145
329
  }
146
- const spanOptions = {
147
- type,
148
- name,
149
- input,
150
- output,
151
- attributes,
152
- metadata,
153
- parent,
154
- isEvent: isEvent === true
155
- };
156
- const span = this.createSpan(spanOptions);
330
+ const span = this.createSpan(createSpanOptions);
157
331
  if (span.isEvent) {
158
332
  this.emitSpanEnded(span);
159
333
  } else {
@@ -200,6 +374,9 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
200
374
  * This ensures all spans emit events regardless of implementation
201
375
  */
202
376
  wireSpanLifecycle(span) {
377
+ if (!this.config.includeInternalSpans && span.isInternal) {
378
+ return;
379
+ }
203
380
  const originalEnd = span.end.bind(span);
204
381
  const originalUpdate = span.update.bind(span);
205
382
  span.end = (options) => {
@@ -225,7 +402,7 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
225
402
  /**
226
403
  * Check if an AI trace should be sampled
227
404
  */
228
- shouldSample(traceContext) {
405
+ shouldSample(options) {
229
406
  const { sampling } = this.config;
230
407
  switch (sampling.type) {
231
408
  case "always" /* ALWAYS */:
@@ -241,7 +418,7 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
241
418
  }
242
419
  return Math.random() < sampling.probability;
243
420
  case "custom" /* CUSTOM */:
244
- return sampling.sampler(traceContext);
421
+ return sampling.sampler(options);
245
422
  default:
246
423
  throw new Error(`Sampling strategy type not implemented: ${sampling.type}`);
247
424
  }
@@ -250,29 +427,34 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
250
427
  * Process a span through all processors
251
428
  */
252
429
  processSpan(span) {
253
- let processedSpan = span;
254
430
  for (const processor of this.processors) {
255
- if (!processedSpan) {
431
+ if (!span) {
256
432
  break;
257
433
  }
258
434
  try {
259
- processedSpan = processor.process(processedSpan);
435
+ span = processor.process(span);
260
436
  } catch (error) {
261
437
  this.logger.error(`[AI Tracing] Processor error [name=${processor.name}]`, error);
262
438
  }
263
439
  }
264
- return processedSpan;
440
+ return span;
265
441
  }
266
442
  // ============================================================================
267
443
  // Event-driven Export Methods
268
444
  // ============================================================================
445
+ getSpanForExport(span) {
446
+ if (!span.isValid) return void 0;
447
+ if (span.isInternal && !this.config.includeInternalSpans) return void 0;
448
+ const processedSpan = this.processSpan(span);
449
+ return processedSpan?.exportSpan(this.config.includeInternalSpans);
450
+ }
269
451
  /**
270
452
  * Emit a span started event
271
453
  */
272
454
  emitSpanStarted(span) {
273
- const processedSpan = this.processSpan(span);
274
- if (processedSpan) {
275
- this.exportEvent({ type: "span_started" /* SPAN_STARTED */, span: processedSpan }).catch((error) => {
455
+ const exportedSpan = this.getSpanForExport(span);
456
+ if (exportedSpan) {
457
+ this.exportEvent({ type: "span_started" /* SPAN_STARTED */, exportedSpan }).catch((error) => {
276
458
  this.logger.error("[AI Tracing] Failed to export span_started event", error);
277
459
  });
278
460
  }
@@ -281,9 +463,9 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
281
463
  * Emit a span ended event (called automatically when spans end)
282
464
  */
283
465
  emitSpanEnded(span) {
284
- const processedSpan = this.processSpan(span);
285
- if (processedSpan) {
286
- this.exportEvent({ type: "span_ended" /* SPAN_ENDED */, span: processedSpan }).catch((error) => {
466
+ const exportedSpan = this.getSpanForExport(span);
467
+ if (exportedSpan) {
468
+ this.exportEvent({ type: "span_ended" /* SPAN_ENDED */, exportedSpan }).catch((error) => {
287
469
  this.logger.error("[AI Tracing] Failed to export span_ended event", error);
288
470
  });
289
471
  }
@@ -292,9 +474,9 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
292
474
  * Emit a span updated event
293
475
  */
294
476
  emitSpanUpdated(span) {
295
- const processedSpan = this.processSpan(span);
296
- if (processedSpan) {
297
- this.exportEvent({ type: "span_updated" /* SPAN_UPDATED */, span: processedSpan }).catch((error) => {
477
+ const exportedSpan = this.getSpanForExport(span);
478
+ if (exportedSpan) {
479
+ this.exportEvent({ type: "span_updated" /* SPAN_UPDATED */, exportedSpan }).catch((error) => {
298
480
  this.logger.error("[AI Tracing] Failed to export span_updated event", error);
299
481
  });
300
482
  }
@@ -335,6 +517,16 @@ var MastraAITracing = class extends chunkKXCUCBEI_cjs.MastraBase {
335
517
  this.logger.info(`[AI Tracing] Shutdown completed [name=${this.name}]`);
336
518
  }
337
519
  };
520
+
521
+ // src/ai-tracing/tracers/default.ts
522
+ var DefaultAITracing = class extends BaseAITracing {
523
+ constructor(config) {
524
+ super(config);
525
+ }
526
+ createSpan(options) {
527
+ return new DefaultAISpan(options, this);
528
+ }
529
+ };
338
530
  var CoreToolBuilder = class extends chunkKXCUCBEI_cjs.MastraBase {
339
531
  originalTool;
340
532
  options;
@@ -407,7 +599,8 @@ var CoreToolBuilder = class extends chunkKXCUCBEI_cjs.MastraBase {
407
599
  toolId: options.name,
408
600
  toolDescription: options.description,
409
601
  toolType: logType || "tool"
410
- }
602
+ },
603
+ isInternal: options.tracingContext?.isInternal
411
604
  });
412
605
  try {
413
606
  let result;
@@ -424,7 +617,7 @@ var CoreToolBuilder = class extends chunkKXCUCBEI_cjs.MastraBase {
424
617
  memory: options.memory,
425
618
  runId: options.runId,
426
619
  runtimeContext: options.runtimeContext ?? new chunkGPWMM745_cjs.RuntimeContext(),
427
- writer: new chunkS6MAHT7F_cjs.ToolStream(
620
+ writer: new chunkOXAN5SM7_cjs.ToolStream(
428
621
  {
429
622
  prefix: "tool",
430
623
  callId: execOptions.toolCallId,
@@ -902,7 +1095,7 @@ var CloudExporter = class {
902
1095
  if (this.buffer.totalSize === 0) {
903
1096
  this.buffer.firstEventTime = /* @__PURE__ */ new Date();
904
1097
  }
905
- const spanRecord = this.formatSpan(event.span);
1098
+ const spanRecord = this.formatSpan(event.exportedSpan);
906
1099
  this.buffer.spans.push(spanRecord);
907
1100
  this.buffer.totalSize++;
908
1101
  }
@@ -910,7 +1103,7 @@ var CloudExporter = class {
910
1103
  const spanRecord = {
911
1104
  traceId: span.traceId,
912
1105
  spanId: span.id,
913
- parentSpanId: span.parent?.id ?? null,
1106
+ parentSpanId: span.parentSpanId ?? null,
914
1107
  name: span.name,
915
1108
  spanType: span.type,
916
1109
  attributes: span.attributes ?? null,
@@ -1060,7 +1253,7 @@ var ConsoleExporter = class {
1060
1253
  }
1061
1254
  }
1062
1255
  async exportEvent(event) {
1063
- const span = event.span;
1256
+ const span = event.exportedSpan;
1064
1257
  const formatAttributes = (attributes) => {
1065
1258
  try {
1066
1259
  return JSON.stringify(attributes, null, 2);
@@ -1239,8 +1432,8 @@ var DefaultExporter = class {
1239
1432
  */
1240
1433
  handleOutOfOrderUpdate(event) {
1241
1434
  this.logger.warn("Out-of-order span update detected - skipping event", {
1242
- spanId: event.span.id,
1243
- traceId: event.span.traceId,
1435
+ spanId: event.exportedSpan.id,
1436
+ traceId: event.exportedSpan.traceId,
1244
1437
  eventType: event.type
1245
1438
  });
1246
1439
  }
@@ -1248,7 +1441,7 @@ var DefaultExporter = class {
1248
1441
  * Adds an event to the appropriate buffer based on strategy
1249
1442
  */
1250
1443
  addToBuffer(event) {
1251
- const spanKey = this.buildSpanKey(event.span.traceId, event.span.id);
1444
+ const spanKey = this.buildSpanKey(event.exportedSpan.traceId, event.exportedSpan.id);
1252
1445
  if (this.buffer.totalSize === 0) {
1253
1446
  this.buffer.firstEventTime = /* @__PURE__ */ new Date();
1254
1447
  }
@@ -1256,9 +1449,9 @@ var DefaultExporter = class {
1256
1449
  case "span_started" /* SPAN_STARTED */:
1257
1450
  if (this.resolvedStrategy === "batch-with-updates") {
1258
1451
  const createRecord = {
1259
- traceId: event.span.traceId,
1260
- spanId: event.span.id,
1261
- ...this.buildCreateRecord(event.span),
1452
+ traceId: event.exportedSpan.traceId,
1453
+ spanId: event.exportedSpan.id,
1454
+ ...this.buildCreateRecord(event.exportedSpan),
1262
1455
  createdAt: /* @__PURE__ */ new Date(),
1263
1456
  updatedAt: null
1264
1457
  };
@@ -1270,10 +1463,10 @@ var DefaultExporter = class {
1270
1463
  if (this.resolvedStrategy === "batch-with-updates") {
1271
1464
  if (this.buffer.seenSpans.has(spanKey)) {
1272
1465
  this.buffer.updates.push({
1273
- traceId: event.span.traceId,
1274
- spanId: event.span.id,
1466
+ traceId: event.exportedSpan.traceId,
1467
+ spanId: event.exportedSpan.id,
1275
1468
  updates: {
1276
- ...this.buildUpdateRecord(event.span),
1469
+ ...this.buildUpdateRecord(event.exportedSpan),
1277
1470
  updatedAt: /* @__PURE__ */ new Date()
1278
1471
  },
1279
1472
  sequenceNumber: this.getNextSequence(spanKey)
@@ -1288,19 +1481,19 @@ var DefaultExporter = class {
1288
1481
  if (this.resolvedStrategy === "batch-with-updates") {
1289
1482
  if (this.buffer.seenSpans.has(spanKey)) {
1290
1483
  this.buffer.updates.push({
1291
- traceId: event.span.traceId,
1292
- spanId: event.span.id,
1484
+ traceId: event.exportedSpan.traceId,
1485
+ spanId: event.exportedSpan.id,
1293
1486
  updates: {
1294
- ...this.buildUpdateRecord(event.span),
1487
+ ...this.buildUpdateRecord(event.exportedSpan),
1295
1488
  updatedAt: /* @__PURE__ */ new Date()
1296
1489
  },
1297
1490
  sequenceNumber: this.getNextSequence(spanKey)
1298
1491
  });
1299
- } else if (event.span.isEvent) {
1492
+ } else if (event.exportedSpan.isEvent) {
1300
1493
  const createRecord = {
1301
- traceId: event.span.traceId,
1302
- spanId: event.span.id,
1303
- ...this.buildCreateRecord(event.span),
1494
+ traceId: event.exportedSpan.traceId,
1495
+ spanId: event.exportedSpan.id,
1496
+ ...this.buildCreateRecord(event.exportedSpan),
1304
1497
  createdAt: /* @__PURE__ */ new Date(),
1305
1498
  updatedAt: null
1306
1499
  };
@@ -1312,9 +1505,9 @@ var DefaultExporter = class {
1312
1505
  }
1313
1506
  } else if (this.resolvedStrategy === "insert-only") {
1314
1507
  const createRecord = {
1315
- traceId: event.span.traceId,
1316
- spanId: event.span.id,
1317
- ...this.buildCreateRecord(event.span),
1508
+ traceId: event.exportedSpan.traceId,
1509
+ spanId: event.exportedSpan.id,
1510
+ ...this.buildCreateRecord(event.exportedSpan),
1318
1511
  createdAt: /* @__PURE__ */ new Date(),
1319
1512
  updatedAt: null
1320
1513
  };
@@ -1401,7 +1594,7 @@ var DefaultExporter = class {
1401
1594
  }
1402
1595
  buildCreateRecord(span) {
1403
1596
  return {
1404
- parentSpanId: span.parent?.id ?? null,
1597
+ parentSpanId: span.parentSpanId ?? null,
1405
1598
  name: span.name,
1406
1599
  scope: null,
1407
1600
  spanType: span.type,
@@ -1433,7 +1626,7 @@ var DefaultExporter = class {
1433
1626
  * Handles realtime strategy - processes each event immediately
1434
1627
  */
1435
1628
  async handleRealtimeEvent(event, storage) {
1436
- const span = event.span;
1629
+ const span = event.exportedSpan;
1437
1630
  if (span.isEvent) {
1438
1631
  if (event.type === "span_ended" /* SPAN_ENDED */) {
1439
1632
  await storage.createAISpan({
@@ -1645,11 +1838,125 @@ var DefaultExporter = class {
1645
1838
  }
1646
1839
  };
1647
1840
 
1841
+ // src/ai-tracing/span_processors/sensitive-data-filter.ts
1842
+ var SensitiveDataFilter = class {
1843
+ name = "sensitive-data-filter";
1844
+ sensitiveFields;
1845
+ redactionToken;
1846
+ redactionStyle;
1847
+ constructor(options = {}) {
1848
+ this.sensitiveFields = (options.sensitiveFields || [
1849
+ "password",
1850
+ "token",
1851
+ "secret",
1852
+ "key",
1853
+ "apikey",
1854
+ "auth",
1855
+ "authorization",
1856
+ "bearer",
1857
+ "bearertoken",
1858
+ "jwt",
1859
+ "credential",
1860
+ "clientsecret",
1861
+ "privatekey",
1862
+ "refresh",
1863
+ "ssn"
1864
+ ]).map((f) => this.normalizeKey(f));
1865
+ this.redactionToken = options.redactionToken ?? "[REDACTED]";
1866
+ this.redactionStyle = options.redactionStyle ?? "full";
1867
+ }
1868
+ /**
1869
+ * Process a span by filtering sensitive data across its key fields.
1870
+ * Fields processed: attributes, metadata, input, output, errorInfo.
1871
+ *
1872
+ * @param span - The input span to filter
1873
+ * @returns A new span with sensitive values redacted
1874
+ */
1875
+ process(span) {
1876
+ span.attributes = this.tryFilter(span.attributes);
1877
+ span.metadata = this.tryFilter(span.metadata);
1878
+ span.input = this.tryFilter(span.input);
1879
+ span.output = this.tryFilter(span.output);
1880
+ span.errorInfo = this.tryFilter(span.errorInfo);
1881
+ return span;
1882
+ }
1883
+ /**
1884
+ * Recursively filter objects/arrays for sensitive keys.
1885
+ * Handles circular references by replacing with a marker.
1886
+ */
1887
+ deepFilter(obj, seen = /* @__PURE__ */ new WeakSet()) {
1888
+ if (obj === null || typeof obj !== "object") {
1889
+ return obj;
1890
+ }
1891
+ if (seen.has(obj)) {
1892
+ return "[Circular Reference]";
1893
+ }
1894
+ seen.add(obj);
1895
+ if (Array.isArray(obj)) {
1896
+ return obj.map((item) => this.deepFilter(item, seen));
1897
+ }
1898
+ const filtered = {};
1899
+ for (const key of Object.keys(obj)) {
1900
+ const normKey = this.normalizeKey(key);
1901
+ if (this.isSensitive(normKey)) {
1902
+ if (obj[key] && typeof obj[key] === "object") {
1903
+ filtered[key] = this.deepFilter(obj[key], seen);
1904
+ } else {
1905
+ filtered[key] = this.redactValue(obj[key]);
1906
+ }
1907
+ } else {
1908
+ filtered[key] = this.deepFilter(obj[key], seen);
1909
+ }
1910
+ }
1911
+ return filtered;
1912
+ }
1913
+ tryFilter(value) {
1914
+ try {
1915
+ return this.deepFilter(value);
1916
+ } catch {
1917
+ return { error: { processor: this.name } };
1918
+ }
1919
+ }
1920
+ /**
1921
+ * Normalize keys by lowercasing and stripping non-alphanumeric characters.
1922
+ * Ensures consistent matching for variants like "api-key", "api_key", "Api Key".
1923
+ */
1924
+ normalizeKey(key) {
1925
+ return key.toLowerCase().replace(/[^a-z0-9]/g, "");
1926
+ }
1927
+ /**
1928
+ * Check whether a normalized key matches any sensitive field substring.
1929
+ */
1930
+ isSensitive(normalizedKey) {
1931
+ return this.sensitiveFields.some((f) => normalizedKey.includes(f));
1932
+ }
1933
+ /**
1934
+ * Redact a sensitive value.
1935
+ * - Full style: replaces with a fixed token.
1936
+ * - Partial style: shows 3 chars at start and end, hides the middle.
1937
+ *
1938
+ * Non-string values are converted to strings before partial redaction.
1939
+ */
1940
+ redactValue(value) {
1941
+ if (this.redactionStyle === "full") {
1942
+ return this.redactionToken;
1943
+ }
1944
+ const str = String(value);
1945
+ const len = str.length;
1946
+ if (len <= 6) {
1947
+ return this.redactionToken;
1948
+ }
1949
+ return str.slice(0, 3) + "\u2026" + str.slice(len - 3);
1950
+ }
1951
+ async shutdown() {
1952
+ }
1953
+ };
1954
+
1648
1955
  // src/ai-tracing/registry.ts
1649
1956
  var AITracingRegistry = class {
1650
1957
  instances = /* @__PURE__ */ new Map();
1651
1958
  defaultInstance;
1652
- selector;
1959
+ configSelector;
1653
1960
  /**
1654
1961
  * Register a tracing instance
1655
1962
  */
@@ -1678,14 +1985,14 @@ var AITracingRegistry = class {
1678
1985
  * Set the tracing selector function
1679
1986
  */
1680
1987
  setSelector(selector) {
1681
- this.selector = selector;
1988
+ this.configSelector = selector;
1682
1989
  }
1683
1990
  /**
1684
1991
  * Get the selected tracing instance based on context
1685
1992
  */
1686
- getSelected(context) {
1687
- if (this.selector) {
1688
- const selected = this.selector(context, this.instances);
1993
+ getSelected(options) {
1994
+ if (this.configSelector) {
1995
+ const selected = this.configSelector(options, this.instances);
1689
1996
  if (selected && this.instances.has(selected)) {
1690
1997
  return this.instances.get(selected);
1691
1998
  }
@@ -1712,7 +2019,7 @@ var AITracingRegistry = class {
1712
2019
  clear() {
1713
2020
  this.instances.clear();
1714
2021
  this.defaultInstance = void 0;
1715
- this.selector = void 0;
2022
+ this.configSelector = void 0;
1716
2023
  }
1717
2024
  /**
1718
2025
  * Get all registered instances
@@ -1731,11 +2038,11 @@ function getAITracing(name) {
1731
2038
  function getDefaultAITracing() {
1732
2039
  return aiTracingRegistry.getDefault();
1733
2040
  }
1734
- function setAITracingSelector(selector) {
2041
+ function setSelector(selector) {
1735
2042
  aiTracingRegistry.setSelector(selector);
1736
2043
  }
1737
- function getSelectedAITracing(context) {
1738
- return aiTracingRegistry.getSelected(context);
2044
+ function getSelectedAITracing(options) {
2045
+ return aiTracingRegistry.getSelected(options);
1739
2046
  }
1740
2047
  function unregisterAITracing(name) {
1741
2048
  return aiTracingRegistry.unregister(name);
@@ -1757,7 +2064,7 @@ function hasAITracing(name) {
1757
2064
  return sampling.type !== "never" /* NEVER */;
1758
2065
  }
1759
2066
  function isAITracingInstance(obj) {
1760
- return obj instanceof MastraAITracing;
2067
+ return obj instanceof BaseAITracing;
1761
2068
  }
1762
2069
  function setupAITracing(config) {
1763
2070
  if (!config) {
@@ -1787,51 +2094,11 @@ function setupAITracing(config) {
1787
2094
  });
1788
2095
  }
1789
2096
  if (config.configSelector) {
1790
- setAITracingSelector(config.configSelector);
2097
+ setSelector(config.configSelector);
1791
2098
  }
1792
2099
  }
1793
2100
 
1794
2101
  // src/ai-tracing/utils.ts
1795
- var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
1796
- "logger",
1797
- "experimental_providerMetadata",
1798
- "providerMetadata",
1799
- "steps",
1800
- "tracingContext"
1801
- ]);
1802
- function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
1803
- const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
1804
- if (_depth > maxDepth) {
1805
- return "[MaxDepth]";
1806
- }
1807
- if (value === null || typeof value !== "object") {
1808
- try {
1809
- JSON.stringify(value);
1810
- return value;
1811
- } catch (error) {
1812
- return `[${error instanceof Error ? error.message : String(error)}]`;
1813
- }
1814
- }
1815
- if (_seen.has(value)) {
1816
- return "[Circular]";
1817
- }
1818
- _seen.add(value);
1819
- if (Array.isArray(value)) {
1820
- return value.map((item) => deepClean(item, options, _seen, _depth + 1));
1821
- }
1822
- const cleaned = {};
1823
- for (const [key, val] of Object.entries(value)) {
1824
- if (keysToStrip.has(key)) {
1825
- continue;
1826
- }
1827
- try {
1828
- cleaned[key] = deepClean(val, options, _seen, _depth + 1);
1829
- } catch (error) {
1830
- cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
1831
- }
1832
- }
1833
- return cleaned;
1834
- }
1835
2102
  function omitKeys(obj, keysToOmit) {
1836
2103
  return Object.fromEntries(Object.entries(obj).filter(([key]) => !keysToOmit.includes(key)));
1837
2104
  }
@@ -1867,6 +2134,9 @@ function setNestedValue(obj, path, value) {
1867
2134
  }, obj);
1868
2135
  target[lastKey] = value;
1869
2136
  }
2137
+ function getValidTraceId(span) {
2138
+ return span?.isValid ? span.traceId : void 0;
2139
+ }
1870
2140
  function getOrCreateSpan(options) {
1871
2141
  const { type, attributes, tracingContext, tracingOptions, runtimeContext, ...rest } = options;
1872
2142
  const metadata = {
@@ -1878,7 +2148,8 @@ function getOrCreateSpan(options) {
1878
2148
  type,
1879
2149
  attributes,
1880
2150
  ...rest,
1881
- metadata
2151
+ metadata,
2152
+ isInternal: tracingContext?.isInternal
1882
2153
  });
1883
2154
  }
1884
2155
  const aiTracing = getSelectedAITracing({
@@ -1887,244 +2158,14 @@ function getOrCreateSpan(options) {
1887
2158
  return aiTracing?.startSpan({
1888
2159
  type,
1889
2160
  attributes,
1890
- startOptions: {
1891
- runtimeContext
2161
+ customSamplerOptions: {
2162
+ runtimeContext,
2163
+ metadata
1892
2164
  },
1893
2165
  ...rest,
1894
2166
  metadata
1895
2167
  });
1896
2168
  }
1897
- function getValidTraceId(span) {
1898
- return span?.isValid ? span.traceId : void 0;
1899
- }
1900
-
1901
- // src/ai-tracing/default.ts
1902
- function generateSpanId() {
1903
- const bytes = new Uint8Array(8);
1904
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1905
- crypto.getRandomValues(bytes);
1906
- } else {
1907
- for (let i = 0; i < 8; i++) {
1908
- bytes[i] = Math.floor(Math.random() * 256);
1909
- }
1910
- }
1911
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1912
- }
1913
- function generateTraceId() {
1914
- const bytes = new Uint8Array(16);
1915
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1916
- crypto.getRandomValues(bytes);
1917
- } else {
1918
- for (let i = 0; i < 16; i++) {
1919
- bytes[i] = Math.floor(Math.random() * 256);
1920
- }
1921
- }
1922
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1923
- }
1924
- var DefaultAISpan = class {
1925
- id;
1926
- name;
1927
- type;
1928
- attributes;
1929
- parent;
1930
- traceId;
1931
- startTime;
1932
- endTime;
1933
- isEvent;
1934
- aiTracing;
1935
- input;
1936
- output;
1937
- errorInfo;
1938
- metadata;
1939
- constructor(options, aiTracing) {
1940
- this.id = generateSpanId();
1941
- this.name = options.name;
1942
- this.type = options.type;
1943
- this.attributes = deepClean(options.attributes) || {};
1944
- this.metadata = deepClean(options.metadata);
1945
- this.parent = options.parent;
1946
- this.startTime = /* @__PURE__ */ new Date();
1947
- this.aiTracing = aiTracing;
1948
- this.input = deepClean(options.input);
1949
- this.isEvent = options.isEvent;
1950
- if (!options.parent) {
1951
- this.traceId = generateTraceId();
1952
- } else {
1953
- this.traceId = options.parent.traceId;
1954
- }
1955
- if (this.isEvent) {
1956
- this.output = deepClean(options.output);
1957
- }
1958
- }
1959
- end(options) {
1960
- if (this.isEvent) {
1961
- return;
1962
- }
1963
- this.endTime = /* @__PURE__ */ new Date();
1964
- if (options?.output !== void 0) {
1965
- this.output = deepClean(options.output);
1966
- }
1967
- if (options?.attributes) {
1968
- this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
1969
- }
1970
- if (options?.metadata) {
1971
- this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
1972
- }
1973
- }
1974
- error(options) {
1975
- if (this.isEvent) {
1976
- return;
1977
- }
1978
- const { error, endSpan = true, attributes, metadata } = options;
1979
- this.errorInfo = error instanceof chunkC73WLCY3_cjs.MastraError ? {
1980
- id: error.id,
1981
- details: error.details,
1982
- category: error.category,
1983
- domain: error.domain,
1984
- message: error.message
1985
- } : {
1986
- message: error.message
1987
- };
1988
- if (attributes) {
1989
- this.attributes = { ...this.attributes, ...deepClean(attributes) };
1990
- }
1991
- if (metadata) {
1992
- this.metadata = { ...this.metadata, ...deepClean(metadata) };
1993
- }
1994
- if (endSpan) {
1995
- this.end();
1996
- } else {
1997
- this.update({});
1998
- }
1999
- }
2000
- createChildSpan(options) {
2001
- return this.aiTracing.startSpan({
2002
- ...options,
2003
- parent: this,
2004
- isEvent: false
2005
- });
2006
- }
2007
- createEventSpan(options) {
2008
- return this.aiTracing.startSpan({
2009
- ...options,
2010
- parent: this,
2011
- isEvent: true
2012
- });
2013
- }
2014
- update(options) {
2015
- if (this.isEvent) {
2016
- return;
2017
- }
2018
- if (options?.input !== void 0) {
2019
- this.input = deepClean(options.input);
2020
- }
2021
- if (options?.output !== void 0) {
2022
- this.output = deepClean(options.output);
2023
- }
2024
- if (options?.attributes) {
2025
- this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
2026
- }
2027
- if (options?.metadata) {
2028
- this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
2029
- }
2030
- }
2031
- get isRootSpan() {
2032
- return !this.parent;
2033
- }
2034
- get isValid() {
2035
- return true;
2036
- }
2037
- async export() {
2038
- return JSON.stringify({
2039
- id: this.id,
2040
- attributes: this.attributes,
2041
- metadata: this.metadata,
2042
- startTime: this.startTime,
2043
- endTime: this.endTime,
2044
- traceId: this.traceId
2045
- // OpenTelemetry trace ID
2046
- });
2047
- }
2048
- };
2049
- var SensitiveDataFilter = class {
2050
- name = "sensitive-data-filter";
2051
- sensitiveFields;
2052
- constructor(sensitiveFields) {
2053
- this.sensitiveFields = (sensitiveFields || [
2054
- "password",
2055
- "token",
2056
- "secret",
2057
- "key",
2058
- "apiKey",
2059
- "auth",
2060
- "authorization",
2061
- "bearer",
2062
- "jwt",
2063
- "credential",
2064
- "sessionId"
2065
- ]).map((field) => field.toLowerCase());
2066
- }
2067
- process(span) {
2068
- const deepFilter = (obj, seen = /* @__PURE__ */ new WeakSet()) => {
2069
- if (obj === null || typeof obj !== "object") {
2070
- return obj;
2071
- }
2072
- if (seen.has(obj)) {
2073
- return "[Circular Reference]";
2074
- }
2075
- seen.add(obj);
2076
- if (Array.isArray(obj)) {
2077
- return obj.map((item) => deepFilter(item, seen));
2078
- }
2079
- const filtered = {};
2080
- Object.keys(obj).forEach((key) => {
2081
- if (this.sensitiveFields.includes(key.toLowerCase())) {
2082
- if (obj[key] && typeof obj[key] === "object") {
2083
- filtered[key] = deepFilter(obj[key], seen);
2084
- } else {
2085
- filtered[key] = "[REDACTED]";
2086
- }
2087
- } else {
2088
- filtered[key] = deepFilter(obj[key], seen);
2089
- }
2090
- });
2091
- return filtered;
2092
- };
2093
- try {
2094
- const filteredSpan = { ...span };
2095
- filteredSpan.attributes = deepFilter(span.attributes);
2096
- filteredSpan.metadata = deepFilter(span.metadata);
2097
- filteredSpan.input = deepFilter(span.input);
2098
- filteredSpan.output = deepFilter(span.output);
2099
- filteredSpan.errorInfo = deepFilter(span.errorInfo);
2100
- return filteredSpan;
2101
- } catch (error) {
2102
- const safeSpan = { ...span };
2103
- safeSpan.attributes = {
2104
- "[FILTERING_ERROR]": "Attributes were completely redacted due to filtering error",
2105
- "[ERROR_MESSAGE]": error instanceof Error ? error.message : "Unknown filtering error"
2106
- };
2107
- return safeSpan;
2108
- }
2109
- }
2110
- async shutdown() {
2111
- }
2112
- };
2113
- var DefaultAITracing = class extends MastraAITracing {
2114
- constructor(config) {
2115
- const configWithDefaults = {
2116
- ...config,
2117
- exporters: config.exporters?.length ? config.exporters : [new ConsoleExporter()]
2118
- };
2119
- super(configWithDefaults);
2120
- }
2121
- // ============================================================================
2122
- // Abstract Method Implementations
2123
- // ============================================================================
2124
- createSpan(options) {
2125
- return new DefaultAISpan(options, this);
2126
- }
2127
- };
2128
2169
 
2129
2170
  // src/ai-tracing/context.ts
2130
2171
  var AGENT_GETTERS = ["getAgent", "getAgentById"];
@@ -2275,11 +2316,14 @@ function wrapRun(run, tracingContext) {
2275
2316
 
2276
2317
  exports.AISpanType = AISpanType;
2277
2318
  exports.AITracingEventType = AITracingEventType;
2319
+ exports.BaseAISpan = BaseAISpan;
2320
+ exports.BaseAITracing = BaseAITracing;
2278
2321
  exports.CloudExporter = CloudExporter;
2279
2322
  exports.ConsoleExporter = ConsoleExporter;
2323
+ exports.DefaultAISpan = DefaultAISpan;
2280
2324
  exports.DefaultAITracing = DefaultAITracing;
2281
2325
  exports.DefaultExporter = DefaultExporter;
2282
- exports.MastraAITracing = MastraAITracing;
2326
+ exports.NoOpAISpan = NoOpAISpan;
2283
2327
  exports.SamplingStrategyType = SamplingStrategyType;
2284
2328
  exports.SensitiveDataFilter = SensitiveDataFilter;
2285
2329
  exports.checkEvalStorageFields = checkEvalStorageFields;
@@ -2311,10 +2355,10 @@ exports.parseSqlIdentifier = parseSqlIdentifier;
2311
2355
  exports.registerAITracing = registerAITracing;
2312
2356
  exports.resolveSerializedZodOutput = resolveSerializedZodOutput;
2313
2357
  exports.selectFields = selectFields;
2314
- exports.setAITracingSelector = setAITracingSelector;
2358
+ exports.setSelector = setSelector;
2315
2359
  exports.setupAITracing = setupAITracing;
2316
2360
  exports.shutdownAITracingRegistry = shutdownAITracingRegistry;
2317
2361
  exports.unregisterAITracing = unregisterAITracing;
2318
2362
  exports.wrapMastra = wrapMastra;
2319
- //# sourceMappingURL=chunk-VVUCWRGD.cjs.map
2320
- //# sourceMappingURL=chunk-VVUCWRGD.cjs.map
2363
+ //# sourceMappingURL=chunk-ERRIEUC2.cjs.map
2364
+ //# sourceMappingURL=chunk-ERRIEUC2.cjs.map