@mastra/core 0.15.3-alpha.3 → 0.15.3-alpha.5

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 (173) hide show
  1. package/CHANGELOG.md +3188 -0
  2. package/dist/agent/agent.types.d.ts +9 -4
  3. package/dist/agent/agent.types.d.ts.map +1 -1
  4. package/dist/agent/index.cjs +11 -11
  5. package/dist/agent/index.d.ts +33 -5
  6. package/dist/agent/index.d.ts.map +1 -1
  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/agent/types.d.ts +11 -6
  11. package/dist/agent/types.d.ts.map +1 -1
  12. package/dist/ai-tracing/context.d.ts.map +1 -1
  13. package/dist/ai-tracing/default.d.ts.map +1 -1
  14. package/dist/ai-tracing/index.cjs +43 -31
  15. package/dist/ai-tracing/index.js +1 -1
  16. package/dist/ai-tracing/no-op.d.ts +0 -1
  17. package/dist/ai-tracing/no-op.d.ts.map +1 -1
  18. package/dist/ai-tracing/types.d.ts +0 -2
  19. package/dist/ai-tracing/types.d.ts.map +1 -1
  20. package/dist/ai-tracing/utils.d.ts +44 -8
  21. package/dist/ai-tracing/utils.d.ts.map +1 -1
  22. package/dist/{chunk-BGOXFBFK.js → chunk-23NO6AMW.js} +458 -223
  23. package/dist/chunk-23NO6AMW.js.map +1 -0
  24. package/dist/{chunk-MEROMP3Z.js → chunk-2L6PFHHU.js} +3 -3
  25. package/dist/{chunk-MEROMP3Z.js.map → chunk-2L6PFHHU.js.map} +1 -1
  26. package/dist/{chunk-TWNFR6MQ.cjs → chunk-5CJDO3UO.cjs} +8 -8
  27. package/dist/{chunk-TWNFR6MQ.cjs.map → chunk-5CJDO3UO.cjs.map} +1 -1
  28. package/dist/{chunk-APVV75XG.js → chunk-A5NC3XK2.js} +62 -16
  29. package/dist/chunk-A5NC3XK2.js.map +1 -0
  30. package/dist/{chunk-ZAJTIZZF.cjs → chunk-ABRPHTOG.cjs} +2 -2
  31. package/dist/{chunk-ZAJTIZZF.cjs.map → chunk-ABRPHTOG.cjs.map} +1 -1
  32. package/dist/{chunk-GOG77M6R.js → chunk-BJGHUKKM.js} +2 -2
  33. package/dist/{chunk-GOG77M6R.js.map → chunk-BJGHUKKM.js.map} +1 -1
  34. package/dist/{chunk-5TFCIXWE.js → chunk-CKM2ESZF.js} +44 -21
  35. package/dist/chunk-CKM2ESZF.js.map +1 -0
  36. package/dist/{chunk-AYFN43FB.cjs → chunk-E264YNL3.cjs} +68 -22
  37. package/dist/chunk-E264YNL3.cjs.map +1 -0
  38. package/dist/{chunk-QHEB6ZLO.cjs → chunk-F2CAC2R2.cjs} +47 -24
  39. package/dist/chunk-F2CAC2R2.cjs.map +1 -0
  40. package/dist/{chunk-O7IQL4DX.js → chunk-F4SQXAXR.js} +7 -7
  41. package/dist/{chunk-O7IQL4DX.js.map → chunk-F4SQXAXR.js.map} +1 -1
  42. package/dist/{chunk-HXEHQLBD.cjs → chunk-F6XWBVVG.cjs} +4 -4
  43. package/dist/{chunk-HXEHQLBD.cjs.map → chunk-F6XWBVVG.cjs.map} +1 -1
  44. package/dist/{chunk-4DKPMUAC.cjs → chunk-I7OAONIW.cjs} +259 -177
  45. package/dist/chunk-I7OAONIW.cjs.map +1 -0
  46. package/dist/{chunk-EMAAAVRA.js → chunk-IODUKRQP.js} +3 -3
  47. package/dist/{chunk-EMAAAVRA.js.map → chunk-IODUKRQP.js.map} +1 -1
  48. package/dist/{chunk-DJKIK6ZB.cjs → chunk-JQKPRJCJ.cjs} +489 -254
  49. package/dist/chunk-JQKPRJCJ.cjs.map +1 -0
  50. package/dist/{chunk-WOTBMZCN.js → chunk-LOYT3WUA.js} +255 -176
  51. package/dist/chunk-LOYT3WUA.js.map +1 -0
  52. package/dist/{chunk-24TFSB6Z.cjs → chunk-LVGGMWSE.cjs} +8 -8
  53. package/dist/chunk-LVGGMWSE.cjs.map +1 -0
  54. package/dist/{chunk-D2GH2HAK.cjs → chunk-MVEPSGWQ.cjs} +10 -10
  55. package/dist/chunk-MVEPSGWQ.cjs.map +1 -0
  56. package/dist/{chunk-UGN2UU3K.cjs → chunk-OBKBA6CO.cjs} +4 -4
  57. package/dist/{chunk-UGN2UU3K.cjs.map → chunk-OBKBA6CO.cjs.map} +1 -1
  58. package/dist/{chunk-TQRLZH64.js → chunk-PQ3VP6NG.js} +5 -5
  59. package/dist/chunk-PQ3VP6NG.js.map +1 -0
  60. package/dist/{chunk-YTVX52NU.cjs → chunk-VVTB47UG.cjs} +6 -6
  61. package/dist/{chunk-YTVX52NU.cjs.map → chunk-VVTB47UG.cjs.map} +1 -1
  62. package/dist/{chunk-ZC64CG7J.js → chunk-WWQ3QRPF.js} +4 -4
  63. package/dist/chunk-WWQ3QRPF.js.map +1 -0
  64. package/dist/{chunk-WUQSFK7W.js → chunk-XPFWOBV4.js} +4 -4
  65. package/dist/{chunk-WUQSFK7W.js.map → chunk-XPFWOBV4.js.map} +1 -1
  66. package/dist/index.cjs +44 -44
  67. package/dist/index.js +10 -10
  68. package/dist/integration/index.cjs +3 -3
  69. package/dist/integration/index.js +1 -1
  70. package/dist/llm/index.d.ts +2 -2
  71. package/dist/llm/index.d.ts.map +1 -1
  72. package/dist/llm/model/base.types.d.ts +2 -2
  73. package/dist/llm/model/base.types.d.ts.map +1 -1
  74. package/dist/llm/model/model.d.ts +4 -4
  75. package/dist/llm/model/model.d.ts.map +1 -1
  76. package/dist/llm/model/model.loop.d.ts +1 -1
  77. package/dist/llm/model/model.loop.d.ts.map +1 -1
  78. package/dist/llm/model/model.loop.types.d.ts +2 -0
  79. package/dist/llm/model/model.loop.types.d.ts.map +1 -1
  80. package/dist/loop/index.cjs +2 -2
  81. package/dist/loop/index.js +1 -1
  82. package/dist/loop/loop.d.ts +1 -1
  83. package/dist/loop/loop.d.ts.map +1 -1
  84. package/dist/loop/types.d.ts +2 -0
  85. package/dist/loop/types.d.ts.map +1 -1
  86. package/dist/loop/workflow/stream.d.ts +1 -1
  87. package/dist/loop/workflow/stream.d.ts.map +1 -1
  88. package/dist/mastra/hooks.d.ts.map +1 -1
  89. package/dist/mastra/index.cjs +2 -2
  90. package/dist/mastra/index.d.ts +8 -3
  91. package/dist/mastra/index.d.ts.map +1 -1
  92. package/dist/mastra/index.js +1 -1
  93. package/dist/memory/index.cjs +4 -4
  94. package/dist/memory/index.js +1 -1
  95. package/dist/network/index.cjs +4 -4
  96. package/dist/network/index.js +2 -2
  97. package/dist/network/vNext/index.cjs +14 -14
  98. package/dist/network/vNext/index.js +2 -2
  99. package/dist/processors/index.cjs +13 -11
  100. package/dist/processors/index.cjs.map +1 -1
  101. package/dist/processors/index.d.ts +4 -0
  102. package/dist/processors/index.d.ts.map +1 -1
  103. package/dist/processors/index.js +7 -5
  104. package/dist/processors/index.js.map +1 -1
  105. package/dist/processors/processors/moderation.d.ts +4 -0
  106. package/dist/processors/processors/moderation.d.ts.map +1 -1
  107. package/dist/processors/processors/pii-detector.d.ts +3 -0
  108. package/dist/processors/processors/pii-detector.d.ts.map +1 -1
  109. package/dist/processors/processors/prompt-injection-detector.d.ts +2 -0
  110. package/dist/processors/processors/prompt-injection-detector.d.ts.map +1 -1
  111. package/dist/processors/processors/system-prompt-scrubber.d.ts +2 -0
  112. package/dist/processors/processors/system-prompt-scrubber.d.ts.map +1 -1
  113. package/dist/processors/runner.d.ts +5 -4
  114. package/dist/processors/runner.d.ts.map +1 -1
  115. package/dist/relevance/index.cjs +4 -4
  116. package/dist/relevance/index.js +1 -1
  117. package/dist/scores/base.d.ts +2 -0
  118. package/dist/scores/base.d.ts.map +1 -1
  119. package/dist/scores/hooks.d.ts +3 -1
  120. package/dist/scores/hooks.d.ts.map +1 -1
  121. package/dist/scores/index.cjs +27 -18
  122. package/dist/scores/index.cjs.map +1 -1
  123. package/dist/scores/index.js +23 -14
  124. package/dist/scores/index.js.map +1 -1
  125. package/dist/scores/run-experiment/index.d.ts +2 -0
  126. package/dist/scores/run-experiment/index.d.ts.map +1 -1
  127. package/dist/scores/types.d.ts +3 -0
  128. package/dist/scores/types.d.ts.map +1 -1
  129. package/dist/storage/domains/workflows/inmemory.d.ts +1 -1
  130. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  131. package/dist/storage/index.cjs +13 -14
  132. package/dist/storage/index.cjs.map +1 -1
  133. package/dist/storage/index.js +11 -12
  134. package/dist/storage/index.js.map +1 -1
  135. package/dist/stream/index.cjs +3 -3
  136. package/dist/stream/index.js +1 -1
  137. package/dist/test-utils/llm-mock.cjs +2 -2
  138. package/dist/test-utils/llm-mock.js +1 -1
  139. package/dist/tools/index.cjs +4 -4
  140. package/dist/tools/index.js +1 -1
  141. package/dist/tools/is-vercel-tool.cjs +2 -2
  142. package/dist/tools/is-vercel-tool.js +1 -1
  143. package/dist/tools/tool.d.ts +3 -1
  144. package/dist/tools/tool.d.ts.map +1 -1
  145. package/dist/utils.cjs +17 -17
  146. package/dist/utils.d.ts +3 -3
  147. package/dist/utils.d.ts.map +1 -1
  148. package/dist/utils.js +1 -1
  149. package/dist/workflows/default.d.ts +13 -3
  150. package/dist/workflows/default.d.ts.map +1 -1
  151. package/dist/workflows/evented/index.cjs +10 -10
  152. package/dist/workflows/evented/index.js +1 -1
  153. package/dist/workflows/execution-engine.d.ts +2 -2
  154. package/dist/workflows/execution-engine.d.ts.map +1 -1
  155. package/dist/workflows/index.cjs +10 -10
  156. package/dist/workflows/index.js +1 -1
  157. package/dist/workflows/legacy/index.cjs +22 -22
  158. package/dist/workflows/legacy/index.js +1 -1
  159. package/dist/workflows/workflow.d.ts +15 -10
  160. package/dist/workflows/workflow.d.ts.map +1 -1
  161. package/package.json +18 -8
  162. package/dist/chunk-24TFSB6Z.cjs.map +0 -1
  163. package/dist/chunk-4DKPMUAC.cjs.map +0 -1
  164. package/dist/chunk-5TFCIXWE.js.map +0 -1
  165. package/dist/chunk-APVV75XG.js.map +0 -1
  166. package/dist/chunk-AYFN43FB.cjs.map +0 -1
  167. package/dist/chunk-BGOXFBFK.js.map +0 -1
  168. package/dist/chunk-D2GH2HAK.cjs.map +0 -1
  169. package/dist/chunk-DJKIK6ZB.cjs.map +0 -1
  170. package/dist/chunk-QHEB6ZLO.cjs.map +0 -1
  171. package/dist/chunk-TQRLZH64.js.map +0 -1
  172. package/dist/chunk-WOTBMZCN.js.map +0 -1
  173. package/dist/chunk-ZC64CG7J.js.map +0 -1
@@ -9,7 +9,6 @@ var NoOpAISpan = class _NoOpAISpan {
9
9
  type;
10
10
  attributes;
11
11
  parent;
12
- trace;
13
12
  traceId;
14
13
  startTime;
15
14
  endTime;
@@ -26,7 +25,6 @@ var NoOpAISpan = class _NoOpAISpan {
26
25
  this.attributes = options.attributes || {};
27
26
  this.metadata = options.metadata;
28
27
  this.parent = options.parent;
29
- this.trace = options.parent ? options.parent.trace : this;
30
28
  this.traceId = "no-op-trace";
31
29
  this.startTime = /* @__PURE__ */ new Date();
32
30
  this.aiTracing = aiTracing;
@@ -900,6 +898,232 @@ var DefaultExporter = class {
900
898
  }
901
899
  };
902
900
 
901
+ // src/ai-tracing/registry.ts
902
+ var AITracingRegistry = class {
903
+ instances = /* @__PURE__ */ new Map();
904
+ defaultInstance;
905
+ selector;
906
+ /**
907
+ * Register a tracing instance
908
+ */
909
+ register(name, instance, isDefault = false) {
910
+ if (this.instances.has(name)) {
911
+ throw new Error(`AI Tracing instance '${name}' already registered`);
912
+ }
913
+ this.instances.set(name, instance);
914
+ if (isDefault || !this.defaultInstance) {
915
+ this.defaultInstance = instance;
916
+ }
917
+ }
918
+ /**
919
+ * Get a tracing instance by name
920
+ */
921
+ get(name) {
922
+ return this.instances.get(name);
923
+ }
924
+ /**
925
+ * Get the default tracing instance
926
+ */
927
+ getDefault() {
928
+ return this.defaultInstance;
929
+ }
930
+ /**
931
+ * Set the tracing selector function
932
+ */
933
+ setSelector(selector) {
934
+ this.selector = selector;
935
+ }
936
+ /**
937
+ * Get the selected tracing instance based on context
938
+ */
939
+ getSelected(context) {
940
+ if (this.selector) {
941
+ const selected = this.selector(context, this.instances);
942
+ if (selected && this.instances.has(selected)) {
943
+ return this.instances.get(selected);
944
+ }
945
+ }
946
+ return this.defaultInstance;
947
+ }
948
+ /**
949
+ * Unregister a tracing instance
950
+ */
951
+ unregister(name) {
952
+ return this.instances.delete(name);
953
+ }
954
+ /**
955
+ * Shutdown all instances and clear the registry
956
+ */
957
+ async shutdown() {
958
+ const shutdownPromises = Array.from(this.instances.values()).map((instance) => instance.shutdown());
959
+ await Promise.allSettled(shutdownPromises);
960
+ this.instances.clear();
961
+ }
962
+ /**
963
+ * Clear all instances without shutdown
964
+ */
965
+ clear() {
966
+ this.instances.clear();
967
+ this.defaultInstance = void 0;
968
+ this.selector = void 0;
969
+ }
970
+ /**
971
+ * Get all registered instances
972
+ */
973
+ getAll() {
974
+ return new Map(this.instances);
975
+ }
976
+ };
977
+ var aiTracingRegistry = new AITracingRegistry();
978
+ function registerAITracing(name, instance, isDefault = false) {
979
+ aiTracingRegistry.register(name, instance, isDefault);
980
+ }
981
+ function getAITracing(name) {
982
+ return aiTracingRegistry.get(name);
983
+ }
984
+ function getDefaultAITracing() {
985
+ return aiTracingRegistry.getDefault();
986
+ }
987
+ function setAITracingSelector(selector) {
988
+ aiTracingRegistry.setSelector(selector);
989
+ }
990
+ function getSelectedAITracing(context) {
991
+ return aiTracingRegistry.getSelected(context);
992
+ }
993
+ function unregisterAITracing(name) {
994
+ return aiTracingRegistry.unregister(name);
995
+ }
996
+ async function shutdownAITracingRegistry() {
997
+ await aiTracingRegistry.shutdown();
998
+ }
999
+ function clearAITracingRegistry() {
1000
+ aiTracingRegistry.clear();
1001
+ }
1002
+ function getAllAITracing() {
1003
+ return aiTracingRegistry.getAll();
1004
+ }
1005
+ function hasAITracing(name) {
1006
+ const tracing = getAITracing(name);
1007
+ if (!tracing) return false;
1008
+ const config = tracing.getConfig();
1009
+ const sampling = config.sampling;
1010
+ return sampling.type !== "never" /* NEVER */;
1011
+ }
1012
+ function isAITracingInstance(obj) {
1013
+ return obj instanceof MastraAITracing;
1014
+ }
1015
+ function setupAITracing(config) {
1016
+ const entries = Object.entries(config.instances);
1017
+ entries.forEach(([name, tracingDef], index) => {
1018
+ const instance = isAITracingInstance(tracingDef) ? tracingDef : new DefaultAITracing({ ...tracingDef, instanceName: name });
1019
+ const isDefault = index === 0;
1020
+ registerAITracing(name, instance, isDefault);
1021
+ });
1022
+ if (config.selector) {
1023
+ setAITracingSelector(config.selector);
1024
+ }
1025
+ }
1026
+
1027
+ // src/ai-tracing/utils.ts
1028
+ function shallowCleanObject(obj) {
1029
+ const cleaned = {};
1030
+ for (const [key, value] of Object.entries(obj)) {
1031
+ try {
1032
+ JSON.stringify(value);
1033
+ cleaned[key] = value;
1034
+ } catch (error) {
1035
+ cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
1036
+ }
1037
+ }
1038
+ return cleaned;
1039
+ }
1040
+ function shallowCleanArray(arr) {
1041
+ return arr.map((item) => {
1042
+ if (item && typeof item === "object" && !Array.isArray(item)) {
1043
+ return shallowCleanObject(item);
1044
+ }
1045
+ try {
1046
+ JSON.stringify(item);
1047
+ return item;
1048
+ } catch (error) {
1049
+ return `[${error instanceof Error ? error.message : String(error)}]`;
1050
+ }
1051
+ });
1052
+ }
1053
+ function shallowClean(value) {
1054
+ if (value === null || value === void 0) {
1055
+ return value;
1056
+ }
1057
+ if (Array.isArray(value)) {
1058
+ return shallowCleanArray(value);
1059
+ }
1060
+ if (typeof value === "object") {
1061
+ return shallowCleanObject(value);
1062
+ }
1063
+ try {
1064
+ JSON.stringify(value);
1065
+ return value;
1066
+ } catch (error) {
1067
+ return `[${error instanceof Error ? error.message : String(error)}]`;
1068
+ }
1069
+ }
1070
+ function omitKeys(obj, keysToOmit) {
1071
+ return Object.fromEntries(Object.entries(obj).filter(([key]) => !keysToOmit.includes(key)));
1072
+ }
1073
+ function selectFields(obj, fields) {
1074
+ if (!obj || typeof obj !== "object") {
1075
+ return obj;
1076
+ }
1077
+ const result = {};
1078
+ for (const field of fields) {
1079
+ const value = getNestedValue(obj, field);
1080
+ if (value !== void 0) {
1081
+ setNestedValue(result, field, value);
1082
+ }
1083
+ }
1084
+ return result;
1085
+ }
1086
+ function getNestedValue(obj, path) {
1087
+ return path.split(".").reduce((current, key) => {
1088
+ return current && typeof current === "object" ? current[key] : void 0;
1089
+ }, obj);
1090
+ }
1091
+ function setNestedValue(obj, path, value) {
1092
+ const keys = path.split(".");
1093
+ const lastKey = keys.pop();
1094
+ if (!lastKey) {
1095
+ return;
1096
+ }
1097
+ const target = keys.reduce((current, key) => {
1098
+ if (!current[key] || typeof current[key] !== "object") {
1099
+ current[key] = {};
1100
+ }
1101
+ return current[key];
1102
+ }, obj);
1103
+ target[lastKey] = value;
1104
+ }
1105
+ function getOrCreateSpan(options) {
1106
+ const { type, attributes, tracingContext, runtimeContext, ...rest } = options;
1107
+ if (tracingContext?.currentSpan) {
1108
+ return tracingContext.currentSpan.createChildSpan({
1109
+ type,
1110
+ attributes,
1111
+ ...rest
1112
+ });
1113
+ }
1114
+ const aiTracing = getSelectedAITracing({
1115
+ runtimeContext
1116
+ });
1117
+ return aiTracing?.startSpan({
1118
+ type,
1119
+ attributes,
1120
+ startOptions: {
1121
+ runtimeContext
1122
+ },
1123
+ ...rest
1124
+ });
1125
+ }
1126
+
903
1127
  // src/ai-tracing/default.ts
904
1128
  function generateSpanId() {
905
1129
  const bytes = new Uint8Array(8);
@@ -929,7 +1153,6 @@ var DefaultAISpan = class {
929
1153
  type;
930
1154
  attributes;
931
1155
  parent;
932
- trace;
933
1156
  traceId;
934
1157
  startTime;
935
1158
  endTime;
@@ -944,13 +1167,12 @@ var DefaultAISpan = class {
944
1167
  this.id = generateSpanId();
945
1168
  this.name = options.name;
946
1169
  this.type = options.type;
947
- this.attributes = options.attributes || {};
948
- this.metadata = options.metadata;
1170
+ this.attributes = shallowClean(options.attributes) || {};
1171
+ this.metadata = shallowClean(options.metadata);
949
1172
  this.parent = options.parent;
950
- this.trace = options.parent ? options.parent.trace : this;
951
1173
  this.startTime = /* @__PURE__ */ new Date();
952
1174
  this.aiTracing = aiTracing;
953
- this.input = options.input;
1175
+ this.input = shallowClean(options.input);
954
1176
  this.isEvent = options.isEvent;
955
1177
  this.logger = new ConsoleLogger({
956
1178
  name: "default-ai-span",
@@ -960,10 +1182,10 @@ var DefaultAISpan = class {
960
1182
  if (!options.parent) {
961
1183
  this.traceId = generateTraceId();
962
1184
  } else {
963
- this.traceId = options.parent.trace.traceId;
1185
+ this.traceId = options.parent.traceId;
964
1186
  }
965
1187
  if (this.isEvent) {
966
- this.output = options.output;
1188
+ this.output = shallowClean(options.output);
967
1189
  }
968
1190
  }
969
1191
  end(options) {
@@ -973,13 +1195,13 @@ var DefaultAISpan = class {
973
1195
  }
974
1196
  this.endTime = /* @__PURE__ */ new Date();
975
1197
  if (options?.output !== void 0) {
976
- this.output = options.output;
1198
+ this.output = shallowClean(options.output);
977
1199
  }
978
1200
  if (options?.attributes) {
979
- this.attributes = { ...this.attributes, ...options.attributes };
1201
+ this.attributes = { ...this.attributes, ...shallowClean(options.attributes) };
980
1202
  }
981
1203
  if (options?.metadata) {
982
- this.metadata = { ...this.metadata, ...options.metadata };
1204
+ this.metadata = { ...this.metadata, ...shallowClean(options.metadata) };
983
1205
  }
984
1206
  }
985
1207
  error(options) {
@@ -998,10 +1220,10 @@ var DefaultAISpan = class {
998
1220
  message: error.message
999
1221
  };
1000
1222
  if (attributes) {
1001
- this.attributes = { ...this.attributes, ...attributes };
1223
+ this.attributes = { ...this.attributes, ...shallowClean(attributes) };
1002
1224
  }
1003
1225
  if (metadata) {
1004
- this.metadata = { ...this.metadata, ...metadata };
1226
+ this.metadata = { ...this.metadata, ...shallowClean(metadata) };
1005
1227
  }
1006
1228
  if (endSpan) {
1007
1229
  this.end();
@@ -1029,16 +1251,16 @@ var DefaultAISpan = class {
1029
1251
  return;
1030
1252
  }
1031
1253
  if (options?.input !== void 0) {
1032
- this.input = options.input;
1254
+ this.input = shallowClean(options.input);
1033
1255
  }
1034
1256
  if (options?.output !== void 0) {
1035
- this.output = options.output;
1257
+ this.output = shallowClean(options.output);
1036
1258
  }
1037
1259
  if (options?.attributes) {
1038
- this.attributes = { ...this.attributes, ...options.attributes };
1260
+ this.attributes = { ...this.attributes, ...shallowClean(options.attributes) };
1039
1261
  }
1040
1262
  if (options?.metadata) {
1041
- this.metadata = { ...this.metadata, ...options.metadata };
1263
+ this.metadata = { ...this.metadata, ...shallowClean(options.metadata) };
1042
1264
  }
1043
1265
  }
1044
1266
  get isRootSpan() {
@@ -1139,155 +1361,6 @@ var DefaultAITracing = class extends MastraAITracing {
1139
1361
  }
1140
1362
  };
1141
1363
 
1142
- // src/ai-tracing/registry.ts
1143
- var AITracingRegistry = class {
1144
- instances = /* @__PURE__ */ new Map();
1145
- defaultInstance;
1146
- selector;
1147
- /**
1148
- * Register a tracing instance
1149
- */
1150
- register(name, instance, isDefault = false) {
1151
- if (this.instances.has(name)) {
1152
- throw new Error(`AI Tracing instance '${name}' already registered`);
1153
- }
1154
- this.instances.set(name, instance);
1155
- if (isDefault || !this.defaultInstance) {
1156
- this.defaultInstance = instance;
1157
- }
1158
- }
1159
- /**
1160
- * Get a tracing instance by name
1161
- */
1162
- get(name) {
1163
- return this.instances.get(name);
1164
- }
1165
- /**
1166
- * Get the default tracing instance
1167
- */
1168
- getDefault() {
1169
- return this.defaultInstance;
1170
- }
1171
- /**
1172
- * Set the tracing selector function
1173
- */
1174
- setSelector(selector) {
1175
- this.selector = selector;
1176
- }
1177
- /**
1178
- * Get the selected tracing instance based on context
1179
- */
1180
- getSelected(context) {
1181
- if (this.selector) {
1182
- const selected = this.selector(context, this.instances);
1183
- if (selected && this.instances.has(selected)) {
1184
- return this.instances.get(selected);
1185
- }
1186
- }
1187
- return this.defaultInstance;
1188
- }
1189
- /**
1190
- * Unregister a tracing instance
1191
- */
1192
- unregister(name) {
1193
- return this.instances.delete(name);
1194
- }
1195
- /**
1196
- * Shutdown all instances and clear the registry
1197
- */
1198
- async shutdown() {
1199
- const shutdownPromises = Array.from(this.instances.values()).map((instance) => instance.shutdown());
1200
- await Promise.allSettled(shutdownPromises);
1201
- this.instances.clear();
1202
- }
1203
- /**
1204
- * Clear all instances without shutdown
1205
- */
1206
- clear() {
1207
- this.instances.clear();
1208
- this.defaultInstance = void 0;
1209
- this.selector = void 0;
1210
- }
1211
- /**
1212
- * Get all registered instances
1213
- */
1214
- getAll() {
1215
- return new Map(this.instances);
1216
- }
1217
- };
1218
- var aiTracingRegistry = new AITracingRegistry();
1219
- function registerAITracing(name, instance, isDefault = false) {
1220
- aiTracingRegistry.register(name, instance, isDefault);
1221
- }
1222
- function getAITracing(name) {
1223
- return aiTracingRegistry.get(name);
1224
- }
1225
- function getDefaultAITracing() {
1226
- return aiTracingRegistry.getDefault();
1227
- }
1228
- function setAITracingSelector(selector) {
1229
- aiTracingRegistry.setSelector(selector);
1230
- }
1231
- function getSelectedAITracing(context) {
1232
- return aiTracingRegistry.getSelected(context);
1233
- }
1234
- function unregisterAITracing(name) {
1235
- return aiTracingRegistry.unregister(name);
1236
- }
1237
- async function shutdownAITracingRegistry() {
1238
- await aiTracingRegistry.shutdown();
1239
- }
1240
- function clearAITracingRegistry() {
1241
- aiTracingRegistry.clear();
1242
- }
1243
- function getAllAITracing() {
1244
- return aiTracingRegistry.getAll();
1245
- }
1246
- function hasAITracing(name) {
1247
- const tracing = getAITracing(name);
1248
- if (!tracing) return false;
1249
- const config = tracing.getConfig();
1250
- const sampling = config.sampling;
1251
- return sampling.type !== "never" /* NEVER */;
1252
- }
1253
- function isAITracingInstance(obj) {
1254
- return obj instanceof MastraAITracing;
1255
- }
1256
- function setupAITracing(config) {
1257
- const entries = Object.entries(config.instances);
1258
- entries.forEach(([name, tracingDef], index) => {
1259
- const instance = isAITracingInstance(tracingDef) ? tracingDef : new DefaultAITracing({ ...tracingDef, instanceName: name });
1260
- const isDefault = index === 0;
1261
- registerAITracing(name, instance, isDefault);
1262
- });
1263
- if (config.selector) {
1264
- setAITracingSelector(config.selector);
1265
- }
1266
- }
1267
-
1268
- // src/ai-tracing/utils.ts
1269
- function sanitizeMetadata(metadata) {
1270
- if (!metadata) return {};
1271
- const sanitized = {};
1272
- for (const [key, value] of Object.entries(metadata)) {
1273
- if (isSerializable(value)) {
1274
- sanitized[key] = value;
1275
- }
1276
- }
1277
- return sanitized;
1278
- }
1279
- function isSerializable(value) {
1280
- try {
1281
- JSON.stringify(value);
1282
- return true;
1283
- } catch {
1284
- return false;
1285
- }
1286
- }
1287
- function omitKeys(obj, keysToOmit) {
1288
- return Object.fromEntries(Object.entries(obj).filter(([key]) => !keysToOmit.includes(key)));
1289
- }
1290
-
1291
1364
  // src/ai-tracing/context.ts
1292
1365
  var AGENT_GETTERS = ["getAgent", "getAgentById"];
1293
1366
  var AGENT_METHODS_TO_WRAP = ["generate", "stream", "generateVNext", "streamVNext"];
@@ -1316,10 +1389,12 @@ function wrapMastra(mastra, tracingContext) {
1316
1389
  return wrapWorkflow(workflow, tracingContext);
1317
1390
  };
1318
1391
  }
1319
- return target[prop];
1392
+ const value = target[prop];
1393
+ return typeof value === "function" ? value.bind(target) : value;
1320
1394
  } catch (error) {
1321
1395
  console.warn("AI Tracing: Failed to wrap method, falling back to original", error);
1322
- return target[prop];
1396
+ const value = target[prop];
1397
+ return typeof value === "function" ? value.bind(target) : value;
1323
1398
  }
1324
1399
  }
1325
1400
  });
@@ -1344,10 +1419,12 @@ function wrapAgent(agent, tracingContext) {
1344
1419
  });
1345
1420
  };
1346
1421
  }
1347
- return target[prop];
1422
+ const value = target[prop];
1423
+ return typeof value === "function" ? value.bind(target) : value;
1348
1424
  } catch (error) {
1349
1425
  console.warn("AI Tracing: Failed to wrap agent method, falling back to original", error);
1350
- return target[prop];
1426
+ const value = target[prop];
1427
+ return typeof value === "function" ? value.bind(target) : value;
1351
1428
  }
1352
1429
  }
1353
1430
  });
@@ -1372,10 +1449,12 @@ function wrapWorkflow(workflow, tracingContext) {
1372
1449
  });
1373
1450
  };
1374
1451
  }
1375
- return target[prop];
1452
+ const value = target[prop];
1453
+ return typeof value === "function" ? value.bind(target) : value;
1376
1454
  } catch (error) {
1377
1455
  console.warn("AI Tracing: Failed to wrap workflow method, falling back to original", error);
1378
- return target[prop];
1456
+ const value = target[prop];
1457
+ return typeof value === "function" ? value.bind(target) : value;
1379
1458
  }
1380
1459
  }
1381
1460
  });
@@ -1385,6 +1464,6 @@ function wrapWorkflow(workflow, tracingContext) {
1385
1464
  }
1386
1465
  }
1387
1466
 
1388
- export { AISpanType, AITracingEventType, ConsoleExporter, DefaultAITracing, DefaultExporter, MastraAITracing, SamplingStrategyType, SensitiveDataFilter, aiTracingDefaultConfig, clearAITracingRegistry, getAITracing, getAllAITracing, getDefaultAITracing, getSelectedAITracing, hasAITracing, isSerializable, omitKeys, registerAITracing, sanitizeMetadata, setAITracingSelector, setupAITracing, shutdownAITracingRegistry, unregisterAITracing, wrapAgent, wrapMastra, wrapWorkflow };
1389
- //# sourceMappingURL=chunk-WOTBMZCN.js.map
1390
- //# sourceMappingURL=chunk-WOTBMZCN.js.map
1467
+ export { AISpanType, AITracingEventType, ConsoleExporter, DefaultAITracing, DefaultExporter, MastraAITracing, SamplingStrategyType, SensitiveDataFilter, aiTracingDefaultConfig, clearAITracingRegistry, getAITracing, getAllAITracing, getDefaultAITracing, getOrCreateSpan, getSelectedAITracing, hasAITracing, omitKeys, registerAITracing, selectFields, setAITracingSelector, setupAITracing, shallowClean, shallowCleanArray, shallowCleanObject, shutdownAITracingRegistry, unregisterAITracing, wrapAgent, wrapMastra, wrapWorkflow };
1468
+ //# sourceMappingURL=chunk-LOYT3WUA.js.map
1469
+ //# sourceMappingURL=chunk-LOYT3WUA.js.map