@mastra/server 0.0.0-llamaindex-switch-core-20250424001624 → 0.0.0-main-test-20251105183450

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 (263) hide show
  1. package/CHANGELOG.md +4494 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +45 -137
  4. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  5. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  6. package/dist/chunk-46Z2KDQL.js +124 -0
  7. package/dist/chunk-46Z2KDQL.js.map +1 -0
  8. package/dist/{chunk-FV45V6WC.cjs → chunk-64ITUOXI.cjs} +3 -7
  9. package/dist/chunk-64ITUOXI.cjs.map +1 -0
  10. package/dist/{chunk-TRDNDNGQ.js → chunk-6QWQZI4Q.js} +4 -7
  11. package/dist/chunk-6QWQZI4Q.js.map +1 -0
  12. package/dist/chunk-73PAWDM5.js +83 -0
  13. package/dist/chunk-73PAWDM5.js.map +1 -0
  14. package/dist/chunk-A5SOZY5R.js +502 -0
  15. package/dist/chunk-A5SOZY5R.js.map +1 -0
  16. package/dist/chunk-AEVI2HIU.cjs +651 -0
  17. package/dist/chunk-AEVI2HIU.cjs.map +1 -0
  18. package/dist/chunk-ALOLTNSO.js +477 -0
  19. package/dist/chunk-ALOLTNSO.js.map +1 -0
  20. package/dist/chunk-B6NK4KI5.cjs +128 -0
  21. package/dist/chunk-B6NK4KI5.cjs.map +1 -0
  22. package/dist/chunk-BANGX6SC.cjs +200 -0
  23. package/dist/chunk-BANGX6SC.cjs.map +1 -0
  24. package/dist/chunk-BHQH5QXD.cjs +172 -0
  25. package/dist/chunk-BHQH5QXD.cjs.map +1 -0
  26. package/dist/chunk-BTWIR2B7.cjs +28 -0
  27. package/dist/chunk-BTWIR2B7.cjs.map +1 -0
  28. package/dist/chunk-DNUO33HF.js +129 -0
  29. package/dist/chunk-DNUO33HF.js.map +1 -0
  30. package/dist/chunk-GTZOYEAU.cjs +130 -0
  31. package/dist/chunk-GTZOYEAU.cjs.map +1 -0
  32. package/dist/chunk-GU4EWMZB.cjs +769 -0
  33. package/dist/chunk-GU4EWMZB.cjs.map +1 -0
  34. package/dist/chunk-IGOWG5V5.js +192 -0
  35. package/dist/chunk-IGOWG5V5.js.map +1 -0
  36. package/dist/chunk-JO2AZFJN.js +165 -0
  37. package/dist/chunk-JO2AZFJN.js.map +1 -0
  38. package/dist/chunk-JZ65BJ6H.cjs +678 -0
  39. package/dist/chunk-JZ65BJ6H.cjs.map +1 -0
  40. package/dist/{chunk-4JINXASC.js → chunk-KWH5QBXP.js} +7 -4
  41. package/dist/chunk-KWH5QBXP.js.map +1 -0
  42. package/dist/chunk-LF2ZLOFP.js +767 -0
  43. package/dist/chunk-LF2ZLOFP.js.map +1 -0
  44. package/dist/{chunk-Q6SHQECN.js → chunk-LPCK5MAF.js} +47 -13
  45. package/dist/chunk-LPCK5MAF.js.map +1 -0
  46. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  47. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  48. package/dist/chunk-LWLSQ2W4.cjs +133 -0
  49. package/dist/chunk-LWLSQ2W4.cjs.map +1 -0
  50. package/dist/chunk-MMQIJZ2Q.cjs +23079 -0
  51. package/dist/chunk-MMQIJZ2Q.cjs.map +1 -0
  52. package/dist/chunk-O7I5CWRX.cjs +44 -0
  53. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  54. package/dist/chunk-PPMIB3FQ.cjs +88 -0
  55. package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
  56. package/dist/chunk-PR4QN5HX.js +39 -0
  57. package/dist/chunk-PR4QN5HX.js.map +1 -0
  58. package/dist/chunk-QU6N55W6.cjs +256 -0
  59. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  60. package/dist/chunk-R6OQFR47.js +630 -0
  61. package/dist/chunk-R6OQFR47.js.map +1 -0
  62. package/dist/chunk-RQK4FQUD.js +1012 -0
  63. package/dist/chunk-RQK4FQUD.js.map +1 -0
  64. package/dist/{chunk-M56ECCHK.cjs → chunk-S54HNARD.cjs} +22 -19
  65. package/dist/chunk-S54HNARD.cjs.map +1 -0
  66. package/dist/chunk-SHWNNZBL.js +254 -0
  67. package/dist/chunk-SHWNNZBL.js.map +1 -0
  68. package/dist/chunk-SIPNICB3.cjs +517 -0
  69. package/dist/chunk-SIPNICB3.cjs.map +1 -0
  70. package/dist/{chunk-L7XE5QTW.js → chunk-SZIFSF4T.js} +11 -2
  71. package/dist/chunk-SZIFSF4T.js.map +1 -0
  72. package/dist/chunk-TOCYBDP2.js +46 -0
  73. package/dist/chunk-TOCYBDP2.js.map +1 -0
  74. package/dist/chunk-UU7MMOP5.js +23039 -0
  75. package/dist/chunk-UU7MMOP5.js.map +1 -0
  76. package/dist/chunk-UXGQZUYZ.js +16 -0
  77. package/dist/chunk-UXGQZUYZ.js.map +1 -0
  78. package/dist/chunk-V5WWQN7P.cjs +18 -0
  79. package/dist/chunk-V5WWQN7P.cjs.map +1 -0
  80. package/dist/chunk-VYR3SAFM.js +658 -0
  81. package/dist/chunk-VYR3SAFM.js.map +1 -0
  82. package/dist/chunk-X6C7BUWN.cjs +48 -0
  83. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  84. package/dist/chunk-XXGID4PQ.cjs +485 -0
  85. package/dist/chunk-XXGID4PQ.cjs.map +1 -0
  86. package/dist/chunk-ZULZ2752.js +2774 -0
  87. package/dist/chunk-ZULZ2752.js.map +1 -0
  88. package/dist/dist-4MVGNSRL.cjs +1150 -0
  89. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  90. package/dist/dist-FZYCV3VB.cjs +940 -0
  91. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  92. package/dist/dist-G2BYZJOC.cjs +928 -0
  93. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  94. package/dist/dist-P4MXBQ3U.cjs +16 -0
  95. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  96. package/dist/dist-PQZUVLPC.js +937 -0
  97. package/dist/dist-PQZUVLPC.js.map +1 -0
  98. package/dist/dist-R7WYX6LC.js +925 -0
  99. package/dist/dist-R7WYX6LC.js.map +1 -0
  100. package/dist/dist-RFMYFILX.cjs +764 -0
  101. package/dist/dist-RFMYFILX.cjs.map +1 -0
  102. package/dist/dist-X7XR3M3Z.js +1147 -0
  103. package/dist/dist-X7XR3M3Z.js.map +1 -0
  104. package/dist/dist-XVBSOGFK.js +761 -0
  105. package/dist/dist-XVBSOGFK.js.map +1 -0
  106. package/dist/dist-YREX2TJT.js +3 -0
  107. package/dist/dist-YREX2TJT.js.map +1 -0
  108. package/dist/index.cjs +6 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +5 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/server/a2a/protocol.d.ts +8 -0
  115. package/dist/server/a2a/protocol.d.ts.map +1 -0
  116. package/dist/server/a2a/store.cjs +25 -0
  117. package/dist/server/a2a/store.cjs.map +1 -0
  118. package/dist/server/a2a/store.d.ts +14 -0
  119. package/dist/server/a2a/store.d.ts.map +1 -0
  120. package/dist/server/a2a/store.js +23 -0
  121. package/dist/server/a2a/store.js.map +1 -0
  122. package/dist/server/a2a/tasks.d.ts +20 -0
  123. package/dist/server/a2a/tasks.d.ts.map +1 -0
  124. package/dist/server/handlers/a2a.cjs +32 -0
  125. package/dist/server/handlers/a2a.cjs.map +1 -0
  126. package/dist/server/handlers/a2a.d.ts +68 -0
  127. package/dist/server/handlers/a2a.d.ts.map +1 -0
  128. package/dist/server/handlers/a2a.js +3 -0
  129. package/dist/server/handlers/a2a.js.map +1 -0
  130. package/dist/server/handlers/agent-builder.cjs +84 -0
  131. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  132. package/dist/server/handlers/agent-builder.d.ts +91 -0
  133. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  134. package/dist/server/handlers/agent-builder.js +3 -0
  135. package/dist/server/handlers/agent-builder.js.map +1 -0
  136. package/dist/server/handlers/agents.cjs +60 -10
  137. package/dist/server/handlers/agents.cjs.map +1 -0
  138. package/dist/server/handlers/agents.d.ts +194 -6
  139. package/dist/server/handlers/agents.d.ts.map +1 -0
  140. package/dist/server/handlers/agents.js +3 -1
  141. package/dist/server/handlers/agents.js.map +1 -0
  142. package/dist/server/handlers/error.cjs +4 -2
  143. package/dist/server/handlers/error.cjs.map +1 -0
  144. package/dist/server/handlers/error.d.ts +2 -1
  145. package/dist/server/handlers/error.d.ts.map +1 -0
  146. package/dist/server/handlers/error.js +3 -1
  147. package/dist/server/handlers/error.js.map +1 -0
  148. package/dist/server/handlers/logs.cjs +9 -7
  149. package/dist/server/handlers/logs.cjs.map +1 -0
  150. package/dist/server/handlers/logs.d.ts +34 -3
  151. package/dist/server/handlers/logs.d.ts.map +1 -0
  152. package/dist/server/handlers/logs.js +3 -1
  153. package/dist/server/handlers/logs.js.map +1 -0
  154. package/dist/server/handlers/memory.cjs +34 -12
  155. package/dist/server/handlers/memory.cjs.map +1 -0
  156. package/dist/server/handlers/memory.d.ts +112 -8
  157. package/dist/server/handlers/memory.d.ts.map +1 -0
  158. package/dist/server/handlers/memory.js +3 -1
  159. package/dist/server/handlers/memory.js.map +1 -0
  160. package/dist/server/handlers/observability.cjs +24 -0
  161. package/dist/server/handlers/observability.cjs.map +1 -0
  162. package/dist/server/handlers/observability.d.ts +49 -0
  163. package/dist/server/handlers/observability.d.ts.map +1 -0
  164. package/dist/server/handlers/observability.js +3 -0
  165. package/dist/server/handlers/observability.js.map +1 -0
  166. package/dist/server/handlers/scores.cjs +32 -0
  167. package/dist/server/handlers/scores.cjs.map +1 -0
  168. package/dist/server/handlers/scores.d.ts +152 -0
  169. package/dist/server/handlers/scores.d.ts.map +1 -0
  170. package/dist/server/handlers/scores.js +3 -0
  171. package/dist/server/handlers/scores.js.map +1 -0
  172. package/dist/server/handlers/tools.cjs +12 -6
  173. package/dist/server/handlers/tools.cjs.map +1 -0
  174. package/dist/server/handlers/tools.d.ts +25 -4
  175. package/dist/server/handlers/tools.d.ts.map +1 -0
  176. package/dist/server/handlers/tools.js +3 -1
  177. package/dist/server/handlers/tools.js.map +1 -0
  178. package/dist/server/handlers/utils.cjs +8 -2
  179. package/dist/server/handlers/utils.cjs.map +1 -0
  180. package/dist/server/handlers/utils.d.ts +8 -1
  181. package/dist/server/handlers/utils.d.ts.map +1 -0
  182. package/dist/server/handlers/utils.js +3 -1
  183. package/dist/server/handlers/utils.js.map +1 -0
  184. package/dist/server/handlers/vector.cjs +9 -7
  185. package/dist/server/handlers/vector.cjs.map +1 -0
  186. package/dist/server/handlers/vector.d.ts +51 -6
  187. package/dist/server/handlers/vector.d.ts.map +1 -0
  188. package/dist/server/handlers/vector.js +3 -1
  189. package/dist/server/handlers/vector.js.map +1 -0
  190. package/dist/server/handlers/voice.cjs +10 -4
  191. package/dist/server/handlers/voice.cjs.map +1 -0
  192. package/dist/server/handlers/voice.d.ts +41 -3
  193. package/dist/server/handlers/voice.d.ts.map +1 -0
  194. package/dist/server/handlers/voice.js +3 -1
  195. package/dist/server/handlers/voice.js.map +1 -0
  196. package/dist/server/handlers/workflows.cjs +54 -16
  197. package/dist/server/handlers/workflows.cjs.map +1 -0
  198. package/dist/server/handlers/workflows.d.ts +94 -10
  199. package/dist/server/handlers/workflows.d.ts.map +1 -0
  200. package/dist/server/handlers/workflows.js +3 -1
  201. package/dist/server/handlers/workflows.js.map +1 -0
  202. package/dist/server/handlers.cjs +38 -26
  203. package/dist/server/handlers.cjs.map +1 -0
  204. package/dist/server/handlers.d.ts +12 -9
  205. package/dist/server/handlers.d.ts.map +1 -0
  206. package/dist/server/handlers.js +13 -9
  207. package/dist/server/handlers.js.map +1 -0
  208. package/dist/server/http-exception.d.ts +82 -0
  209. package/dist/server/http-exception.d.ts.map +1 -0
  210. package/dist/server/types.d.ts +10 -0
  211. package/dist/server/types.d.ts.map +1 -0
  212. package/dist/server/utils.d.ts +44 -0
  213. package/dist/server/utils.d.ts.map +1 -0
  214. package/dist/token-375W3LEI.cjs +64 -0
  215. package/dist/token-375W3LEI.cjs.map +1 -0
  216. package/dist/token-C3IMNCC4.js +62 -0
  217. package/dist/token-C3IMNCC4.js.map +1 -0
  218. package/dist/token-util-CV3RRG6K.cjs +9 -0
  219. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  220. package/dist/token-util-E5QO2RCL.js +7 -0
  221. package/dist/token-util-E5QO2RCL.js.map +1 -0
  222. package/package.json +46 -19
  223. package/dist/_tsup-dts-rollup.d.cts +0 -571
  224. package/dist/_tsup-dts-rollup.d.ts +0 -571
  225. package/dist/chunk-2FJURXCL.cjs +0 -213
  226. package/dist/chunk-3AHQ5RGN.js +0 -11
  227. package/dist/chunk-3EJZQ6TQ.js +0 -49
  228. package/dist/chunk-55HTWX4C.cjs +0 -93
  229. package/dist/chunk-5JNVY6DU.js +0 -120
  230. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  231. package/dist/chunk-7IWQE76Z.cjs +0 -139
  232. package/dist/chunk-D3G23FP3.cjs +0 -126
  233. package/dist/chunk-FPIWDH5Y.cjs +0 -126
  234. package/dist/chunk-HCOPJZ4A.cjs +0 -164
  235. package/dist/chunk-LFOBHRFO.js +0 -305
  236. package/dist/chunk-OMN3UI6X.js +0 -5576
  237. package/dist/chunk-QN4KF3BH.cjs +0 -18
  238. package/dist/chunk-R4J7XQYU.js +0 -156
  239. package/dist/chunk-RBQASTUP.js +0 -203
  240. package/dist/chunk-RE6YL32K.js +0 -120
  241. package/dist/chunk-SKBVVI24.cjs +0 -54
  242. package/dist/chunk-TZK63M5N.cjs +0 -317
  243. package/dist/chunk-WTHDCRMY.js +0 -135
  244. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  245. package/dist/index.d.cts +0 -1
  246. package/dist/server/handlers/agents.d.cts +0 -6
  247. package/dist/server/handlers/error.d.cts +0 -1
  248. package/dist/server/handlers/logs.d.cts +0 -3
  249. package/dist/server/handlers/memory.d.cts +0 -8
  250. package/dist/server/handlers/network.cjs +0 -22
  251. package/dist/server/handlers/network.d.cts +0 -4
  252. package/dist/server/handlers/network.d.ts +0 -4
  253. package/dist/server/handlers/network.js +0 -1
  254. package/dist/server/handlers/telemetry.cjs +0 -14
  255. package/dist/server/handlers/telemetry.d.cts +0 -2
  256. package/dist/server/handlers/telemetry.d.ts +0 -2
  257. package/dist/server/handlers/telemetry.js +0 -1
  258. package/dist/server/handlers/tools.d.cts +0 -4
  259. package/dist/server/handlers/utils.d.cts +0 -1
  260. package/dist/server/handlers/vector.d.cts +0 -6
  261. package/dist/server/handlers/voice.d.cts +0 -3
  262. package/dist/server/handlers/workflows.d.cts +0 -10
  263. package/dist/server/handlers.d.cts +0 -9
@@ -0,0 +1,129 @@
1
+ import { stringify } from './chunk-LF2ZLOFP.js';
2
+ import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
3
+
4
+ function getSteps(steps, path) {
5
+ return Object.entries(steps).reduce((acc, [key, step]) => {
6
+ const fullKey = path ? `${path}.${key}` : key;
7
+ acc[fullKey] = {
8
+ id: step.id,
9
+ description: step.description,
10
+ inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
11
+ outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
12
+ resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
13
+ suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
14
+ isWorkflow: step.component === "WORKFLOW",
15
+ component: step.component
16
+ };
17
+ if (step.component === "WORKFLOW" && step.steps) {
18
+ const nestedSteps = getSteps(step.steps, fullKey) || {};
19
+ acc = { ...acc, ...nestedSteps };
20
+ }
21
+ return acc;
22
+ }, {});
23
+ }
24
+ function getWorkflowInfo(workflow) {
25
+ return {
26
+ name: workflow.name,
27
+ description: workflow.description,
28
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
29
+ acc[key] = {
30
+ id: step.id,
31
+ description: step.description,
32
+ inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
33
+ outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
34
+ resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
35
+ suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
36
+ component: step.component
37
+ };
38
+ return acc;
39
+ }, {}),
40
+ allSteps: getSteps(workflow.steps) || {},
41
+ stepGraph: workflow.serializedStepGraph,
42
+ inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : void 0,
43
+ outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : void 0
44
+ };
45
+ }
46
+ var WorkflowRegistry = class {
47
+ static additionalWorkflows = {};
48
+ /**
49
+ * Register a workflow temporarily
50
+ */
51
+ static registerTemporaryWorkflow(id, workflow) {
52
+ this.additionalWorkflows[id] = workflow;
53
+ }
54
+ /**
55
+ * Register all workflows from map
56
+ */
57
+ static registerTemporaryWorkflows(workflows, mastra) {
58
+ for (const [id, workflow] of Object.entries(workflows)) {
59
+ if (mastra) {
60
+ workflow.__registerMastra(mastra);
61
+ workflow.__registerPrimitives({
62
+ logger: mastra.getLogger(),
63
+ storage: mastra.getStorage(),
64
+ agents: mastra.listAgents(),
65
+ tts: mastra.getTTS(),
66
+ vectors: mastra.getVectors()
67
+ });
68
+ }
69
+ this.additionalWorkflows[id] = workflow;
70
+ }
71
+ }
72
+ /**
73
+ * Get a workflow by ID from the registry (returns undefined if not found)
74
+ */
75
+ static getWorkflow(workflowId) {
76
+ return this.additionalWorkflows[workflowId];
77
+ }
78
+ /**
79
+ * Get all workflows from the registry
80
+ */
81
+ static getAllWorkflows() {
82
+ return { ...this.additionalWorkflows };
83
+ }
84
+ /**
85
+ * Clean up a temporary workflow
86
+ */
87
+ static cleanupTemporaryWorkflow(workflowId) {
88
+ delete this.additionalWorkflows[workflowId];
89
+ }
90
+ /**
91
+ * Clean up all registered workflows
92
+ */
93
+ static cleanup() {
94
+ this.additionalWorkflows = {};
95
+ }
96
+ /**
97
+ * Check if a workflow ID is a valid agent-builder workflow
98
+ */
99
+ static isAgentBuilderWorkflow(workflowId) {
100
+ return workflowId in this.additionalWorkflows;
101
+ }
102
+ /**
103
+ * Get all registered temporary workflow IDs (for debugging)
104
+ */
105
+ static getRegisteredWorkflowIds() {
106
+ return Object.keys(this.additionalWorkflows);
107
+ }
108
+ };
109
+ function convertInstructionsToString(message) {
110
+ if (!message) {
111
+ return "";
112
+ }
113
+ if (typeof message === "string") {
114
+ return message;
115
+ }
116
+ if (Array.isArray(message)) {
117
+ return message.map((m) => {
118
+ if (typeof m === "string") {
119
+ return m;
120
+ }
121
+ return typeof m.content === "string" ? m.content : "";
122
+ }).filter((content) => content).join("\n");
123
+ }
124
+ return typeof message.content === "string" ? message.content : "";
125
+ }
126
+
127
+ export { WorkflowRegistry, convertInstructionsToString, getWorkflowInfo };
128
+ //# sourceMappingURL=chunk-DNUO33HF.js.map
129
+ //# sourceMappingURL=chunk-DNUO33HF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/utils.ts"],"names":[],"mappings":";;;AAKA,SAAS,QAAA,CAAS,OAA0C,IAAA,EAAe;AACzE,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,MAAA,CAAY,CAAC,GAAA,EAAK,CAAC,GAAA,EAAK,IAAI,CAAA,KAAM;AAC7D,IAAA,MAAM,UAAU,IAAA,GAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,GAAK,GAAA;AAC1C,IAAA,GAAA,CAAI,OAAO,CAAA,GAAI;AAAA,MACb,IAAI,IAAA,CAAK,EAAA;AAAA,MACT,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,WAAA,EAAa,KAAK,WAAA,GAAc,S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AO,OAAA;AAAA,EACT;AAEA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC1B,IAAA,OAAO,OAAA,CACJ,IAAI,CAAA,CAAA,KAAK;AACR,MAAA,IAAI,OAAO,MAAM,QAAA,EAAU;AACzB,QAAA,OAAO,CAAA;AAAA,MACT;AAEA,MAAA,OAAO,OAAO,CAAA,CAAE,OAAA,KAAY,QAAA,GAAW,EAAE,OAAA,GAAU,EAAA;AAAA,IACrD,CAAC,CAAA,CACA,MAAA,CAAO,aAAW,OAAO,CAAA,CACzB,KAAK,IAAI,CAAA;AAAA,EACd;AAGA,EAAA,OAAO,OAAO,OAAA,CAAQ,OAAA,KAAY,QAAA,GAAW,QAAQ,OAAA,GAAU,EAAA;AACjE","file":"chunk-DNUO33HF.js","sourcesContent":["import type { SystemMessage } from '@mastra/core/llm';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport type { StepWithComponent, Workflow, WorkflowInfo } from '@mastra/core/workflows';\nimport { stringify } from 'superjson';\n\nfunction getSteps(steps: Record<string, StepWithComponent>, path?: string) {\n return Object.entries(steps).reduce<any>((acc, [key, step]) => {\n const fullKey = path ? `${path}.${key}` : key;\n acc[fullKey] = {\n id: step.id,\n description: step.description,\n inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : undefined,\n outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : undefined,\n resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : undefined,\n suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : undefined,\n isWorkflow: step.component === 'WORKFLOW',\n component: step.component,\n };\n\n if (step.component === 'WORKFLOW' && step.steps) {\n const nestedSteps = getSteps(step.steps, fullKey) || {};\n acc = { ...acc, ...nestedSteps };\n }\n\n return acc;\n }, {});\n}\n\nexport function getWorkflowInfo(workflow: Workflow): WorkflowInfo {\n return {\n name: workflow.name,\n description: workflow.description,\n steps: Object.entries(workflow.steps).reduce<any>((acc, [key, step]) => {\n acc[key] = {\n id: step.id,\n description: step.description,\n inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : undefined,\n outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : undefined,\n resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : undefined,\n suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : undefined,\n component: step.component,\n };\n return acc;\n }, {}),\n allSteps: getSteps(workflow.steps) || {},\n stepGraph: workflow.serializedStepGraph,\n inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : undefined,\n outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : undefined,\n };\n}\n\n/**\n * Workflow Registry for temporarily registering additional workflows\n * that are not part of the user's Mastra instance (e.g., internal template workflows)\n */\nexport class WorkflowRegistry {\n private static additionalWorkflows: Record<string, Workflow> = {};\n\n /**\n * Register a workflow temporarily\n */\n static registerTemporaryWorkflow(id: string, workflow: Workflow): void {\n this.additionalWorkflows[id] = workflow;\n }\n\n /**\n * Register all workflows from map\n */\n static registerTemporaryWorkflows(workflows: Record<string, Workflow>, mastra?: any): void {\n for (const [id, workflow] of Object.entries(workflows)) {\n // Register Mastra instance with the workflow if provided\n if (mastra) {\n workflow.__registerMastra(mastra);\n workflow.__registerPrimitives({\n logger: mastra.getLogger(),\n storage: mastra.getStorage(),\n agents: mastra.listAgents(),\n tts: mastra.getTTS(),\n vectors: mastra.getVectors(),\n });\n }\n this.additionalWorkflows[id] = workflow;\n }\n }\n\n /**\n * Get a workflow by ID from the registry (returns undefined if not found)\n */\n static getWorkflow(workflowId: string): Workflow | undefined {\n return this.additionalWorkflows[workflowId];\n }\n\n /**\n * Get all workflows from the registry\n */\n static getAllWorkflows(): Record<string, Workflow> {\n return { ...this.additionalWorkflows };\n }\n\n /**\n * Clean up a temporary workflow\n */\n static cleanupTemporaryWorkflow(workflowId: string): void {\n delete this.additionalWorkflows[workflowId];\n }\n /**\n * Clean up all registered workflows\n */\n static cleanup(): void {\n // Clear all workflows (since we register all agent-builder workflows each time)\n this.additionalWorkflows = {};\n }\n\n /**\n * Check if a workflow ID is a valid agent-builder workflow\n */\n static isAgentBuilderWorkflow(workflowId: string): boolean {\n return workflowId in this.additionalWorkflows;\n }\n\n /**\n * Get all registered temporary workflow IDs (for debugging)\n */\n static getRegisteredWorkflowIds(): string[] {\n return Object.keys(this.additionalWorkflows);\n }\n}\n\nexport function convertInstructionsToString(message: SystemMessage): string {\n if (!message) {\n return '';\n }\n\n if (typeof message === 'string') {\n return message;\n }\n\n if (Array.isArray(message)) {\n return message\n .map(m => {\n if (typeof m === 'string') {\n return m;\n }\n // Safely extract content from message objects\n return typeof m.content === 'string' ? m.content : '';\n })\n .filter(content => content) // Remove empty strings\n .join('\\n');\n }\n\n // Handle single message object - safely extract content\n return typeof message.content === 'string' ? message.content : '';\n}\n"]}
@@ -0,0 +1,130 @@
1
+ 'use strict';
2
+
3
+ var chunkV5WWQN7P_cjs = require('./chunk-V5WWQN7P.cjs');
4
+ var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs');
5
+ var chunkO7I5CWRX_cjs = require('./chunk-O7I5CWRX.cjs');
6
+ var scoreTraces = require('@mastra/core/evals/scoreTraces');
7
+
8
+ // src/server/handlers/observability.ts
9
+ var observability_exports = {};
10
+ chunkO7I5CWRX_cjs.__export(observability_exports, {
11
+ getAITraceHandler: () => getAITraceHandler,
12
+ getAITracesPaginatedHandler: () => getAITracesPaginatedHandler,
13
+ listScoresBySpan: () => listScoresBySpan,
14
+ scoreTracesHandler: () => scoreTracesHandler
15
+ });
16
+ async function getAITraceHandler({ mastra, traceId }) {
17
+ try {
18
+ if (!traceId) {
19
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Trace ID is required" });
20
+ }
21
+ const storage = mastra.getStorage();
22
+ if (!storage) {
23
+ throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not available" });
24
+ }
25
+ const trace = await storage.getAITrace(traceId);
26
+ if (!trace) {
27
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Trace with ID '${traceId}' not found` });
28
+ }
29
+ return trace;
30
+ } catch (error) {
31
+ chunkV5WWQN7P_cjs.handleError(error, "Error getting AI trace");
32
+ }
33
+ }
34
+ async function getAITracesPaginatedHandler({ mastra, body }) {
35
+ try {
36
+ const storage = mastra.getStorage();
37
+ if (!storage) {
38
+ throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not available" });
39
+ }
40
+ if (!body) {
41
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Request body is required" });
42
+ }
43
+ const { filters, pagination } = body;
44
+ if (pagination?.page && pagination.page < 0) {
45
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Page must be a non-negative integer" });
46
+ }
47
+ if (pagination?.perPage && pagination.perPage < 0) {
48
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Per page must be a non-negative integer" });
49
+ }
50
+ if (pagination?.dateRange) {
51
+ const { start, end } = pagination.dateRange;
52
+ if (start && !(start instanceof Date)) {
53
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Invalid date format in date range" });
54
+ }
55
+ if (end && !(end instanceof Date)) {
56
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Invalid date format in date range" });
57
+ }
58
+ }
59
+ return storage.getAITracesPaginated({
60
+ pagination,
61
+ filters
62
+ });
63
+ } catch (error) {
64
+ chunkV5WWQN7P_cjs.handleError(error, "Error getting AI traces paginated");
65
+ }
66
+ }
67
+ async function scoreTracesHandler({ mastra, body }) {
68
+ try {
69
+ if (!body) {
70
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Request body is required" });
71
+ }
72
+ const { scorerName, targets } = body;
73
+ if (!scorerName) {
74
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Scorer ID is required" });
75
+ }
76
+ if (!targets || targets.length === 0) {
77
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "At least one target is required" });
78
+ }
79
+ const storage = mastra.getStorage();
80
+ if (!storage) {
81
+ throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not available" });
82
+ }
83
+ const scorer = mastra.getScorerById(scorerName);
84
+ if (!scorer) {
85
+ throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Scorer '${scorerName}' not found` });
86
+ }
87
+ const logger = mastra.getLogger();
88
+ scoreTraces.scoreTraces({
89
+ scorerId: scorer.config.id || scorer.config.name,
90
+ targets,
91
+ mastra
92
+ }).catch((error) => {
93
+ logger?.error(`Background trace scoring failed: ${error.message}`, error);
94
+ });
95
+ return {
96
+ status: "success",
97
+ message: `Scoring started for ${targets.length} ${targets.length === 1 ? "trace" : "traces"}`,
98
+ traceCount: targets.length
99
+ };
100
+ } catch (error) {
101
+ chunkV5WWQN7P_cjs.handleError(error, "Error processing trace scoring");
102
+ }
103
+ }
104
+ async function listScoresBySpan({
105
+ mastra,
106
+ traceId,
107
+ spanId,
108
+ pagination
109
+ }) {
110
+ try {
111
+ const storage = mastra.getStorage();
112
+ if (!storage) {
113
+ throw new chunk64ITUOXI_cjs.HTTPException(500, { message: "Storage is not available" });
114
+ }
115
+ if (!traceId || !spanId) {
116
+ throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Trace ID and span ID are required" });
117
+ }
118
+ return await storage.listScoresBySpan({ traceId, spanId, pagination });
119
+ } catch (error) {
120
+ return chunkV5WWQN7P_cjs.handleError(error, "Error getting scores by span");
121
+ }
122
+ }
123
+
124
+ exports.getAITraceHandler = getAITraceHandler;
125
+ exports.getAITracesPaginatedHandler = getAITracesPaginatedHandler;
126
+ exports.listScoresBySpan = listScoresBySpan;
127
+ exports.observability_exports = observability_exports;
128
+ exports.scoreTracesHandler = scoreTracesHandler;
129
+ //# sourceMappingURL=chunk-GTZOYEAU.cjs.map
130
+ //# sourceMappingURL=chunk-GTZOYEAU.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/handlers/observability.ts"],"names":["__export","HTTPException","handleError","scoreTraces"],"mappings":";;;;;;;;AAAA,IAAA,qBAAA,GAAA;AAAAA,0BAAA,CAAA,qBAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AA0BA,eAAsB,iBAAA,CAAkB,EAAE,MAAA,EAAQ,OAAA,EAAQ,EAA+C;AACvG,EAAA,IAAI;AACF,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAIC,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,wBAAwB,CAAA;AAAA,IAClE;AAEA,IAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAClC,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,4BAA4B,CAAA;AAAA,IACtE;AAEA,IAAA,MAAM,KAAA,GAAQ,MAAM,OAAA,CAAQ,UAAA,CAAW,OAAO,CAAA;AAE9C,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,MAAM,IAAIA,gCAAc,GAAA,EAAK,EAAE,SAAS,CAAA,eAAA,EAAkB,OAAO,eAAe,CAAA;AAAA,IAClF;AAEA,IAAA,OAAO,KAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAAC,6BAAA,CAAY,OAAO,wBAAwB,CAAA;AAAA,EAC7C;AACF;AAMA,eAAsB,2BAAA,CAA4B,EAAE,MAAA,EAAQ,IAAA,EAAK,EAAyB;AACxF,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAClC,IAAA,IAAI,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AA,KAAA,KAAS;AAChB,MAAA,MAAA,EAAQ,KAAA,CAAM,CAAA,iCAAA,EAAoC,KAAA,CAAM,OAAO,IAAI,KAAK,CAAA;AAAA,IAC1E,CAAC,CAAA;AAGD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,SAAA;AAAA,MACR,OAAA,EAAS,uBAAuB,OAAA,CAAQ,MAAM,IAAI,OAAA,CAAQ,MAAA,KAAW,CAAA,GAAI,OAAA,GAAU,QAAQ,CAAA,CAAA;AAAA,MAC3F,YAAY,OAAA,CAAQ;AAAA,KACtB;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAAD,6BAAA,CAAY,OAAO,gCAAgC,CAAA;AAAA,EACrD;AACF;AAEA,eAAsB,gBAAA,CAAiB;AAAA,EACrC,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,EAAiF;AAC/E,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAClC,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAID,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,4BAA4B,CAAA;AAAA,IACtE;AAEA,IAAA,IAAI,CAAC,OAAA,IAAW,CAAC,MAAA,EAAQ;AACvB,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,qCAAqC,CAAA;AAAA,IAC/E;AAEA,IAAA,OAAO,MAAM,OAAA,CAAQ,gBAAA,CAAiB,EAAE,OAAA,EAAS,MAAA,EAAQ,YAAY,CAAA;AAAA,EACvE,SAAS,KAAA,EAAO;AACd,IAAA,OAAOC,6BAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF","file":"chunk-GTZOYEAU.cjs","sourcesContent":["import { scoreTraces } from '@mastra/core/evals/scoreTraces';\nimport type { AITracesPaginatedArg, StoragePagination } from '@mastra/core/storage';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\nimport { handleError } from './error';\n\ninterface ObservabilityContext extends Context {\n traceId?: string;\n body?: AITracesPaginatedArg;\n}\n\ninterface ScoreTracesContext extends Context {\n body?: {\n // scorer.id\n scorerName: string;\n targets: Array<{\n traceId: string;\n spanId?: string;\n }>;\n };\n}\n\n/**\n * Get a complete AI trace by trace ID\n * Returns all spans in the trace with their parent-child relationships\n */\nexport async function getAITraceHandler({ mastra, traceId }: ObservabilityContext & { traceId: string }) {\n try {\n if (!traceId) {\n throw new HTTPException(400, { message: 'Trace ID is required' });\n }\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n const trace = await storage.getAITrace(traceId);\n\n if (!trace) {\n throw new HTTPException(404, { message: `Trace with ID '${traceId}' not found` });\n }\n\n return trace;\n } catch (error) {\n handleError(error, 'Error getting AI trace');\n }\n}\n\n/**\n * Get paginated AI traces with filtering and pagination\n * Returns only root spans (parent spans) for pagination, not child spans\n */\nexport async function getAITracesPaginatedHandler({ mastra, body }: ObservabilityContext) {\n try {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n if (!body) {\n throw new HTTPException(400, { message: 'Request body is required' });\n }\n\n const { filters, pagination } = body;\n\n if (pagination?.page && pagination.page < 0) {\n throw new HTTPException(400, { message: 'Page must be a non-negative integer' });\n }\n\n if (pagination?.perPage && pagination.perPage < 0) {\n throw new HTTPException(400, { message: 'Per page must be a non-negative integer' });\n }\n\n if (pagination?.dateRange) {\n const { start, end } = pagination.dateRange;\n\n if (start && !(start instanceof Date)) {\n throw new HTTPException(400, { message: 'Invalid date format in date range' });\n }\n\n if (end && !(end instanceof Date)) {\n throw new HTTPException(400, { message: 'Invalid date format in date range' });\n }\n }\n\n return storage.getAITracesPaginated({\n pagination,\n filters,\n });\n } catch (error) {\n handleError(error, 'Error getting AI traces paginated');\n }\n}\n\n/**\n * Score traces using a specified scorer\n * Fire-and-forget approach - returns immediately while scoring runs in background\n */\nexport async function scoreTracesHandler({ mastra, body }: ScoreTracesContext) {\n try {\n if (!body) {\n throw new HTTPException(400, { message: 'Request body is required' });\n }\n\n const { scorerName, targets } = body;\n\n if (!scorerName) {\n throw new HTTPException(400, { message: 'Scorer ID is required' });\n }\n\n if (!targets || targets.length === 0) {\n throw new HTTPException(400, { message: 'At least one target is required' });\n }\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n const scorer = mastra.getScorerById(scorerName);\n if (!scorer) {\n throw new HTTPException(404, { message: `Scorer '${scorerName}' not found` });\n }\n\n const logger = mastra.getLogger();\n\n scoreTraces({\n scorerId: scorer.config.id || scorer.config.name,\n targets,\n mastra,\n }).catch(error => {\n logger?.error(`Background trace scoring failed: ${error.message}`, error);\n });\n\n // Return immediate response\n return {\n status: 'success',\n message: `Scoring started for ${targets.length} ${targets.length === 1 ? 'trace' : 'traces'}`,\n traceCount: targets.length,\n };\n } catch (error) {\n handleError(error, 'Error processing trace scoring');\n }\n}\n\nexport async function listScoresBySpan({\n mastra,\n traceId,\n spanId,\n pagination,\n}: Context & { traceId: string; spanId: string; pagination: StoragePagination }) {\n try {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n if (!traceId || !spanId) {\n throw new HTTPException(400, { message: 'Trace ID and span ID are required' });\n }\n\n return await storage.listScoresBySpan({ traceId, spanId, pagination });\n } catch (error) {\n return handleError(error, 'Error getting scores by span');\n }\n}\n"]}