@mastra/server 0.0.0-fix-bundle-cleanup-20250911062914 → 0.0.0-fix-cloud-peer-deps-20250923194656

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 (107) hide show
  1. package/CHANGELOG.md +211 -4
  2. package/README.md +0 -5
  3. package/dist/{chunk-GUI3CROV.cjs → chunk-2GDLSAVJ.cjs} +60 -22
  4. package/dist/chunk-2GDLSAVJ.cjs.map +1 -0
  5. package/dist/{chunk-3TETONBL.cjs → chunk-2WMATOMO.cjs} +93 -8
  6. package/dist/chunk-2WMATOMO.cjs.map +1 -0
  7. package/dist/{chunk-6LUKYSWE.cjs → chunk-57HWW2TY.cjs} +96 -119
  8. package/dist/chunk-57HWW2TY.cjs.map +1 -0
  9. package/dist/{chunk-R7NOGUZG.js → chunk-5KRXONRF.js} +43 -4
  10. package/dist/chunk-5KRXONRF.js.map +1 -0
  11. package/dist/{chunk-L265APUD.cjs → chunk-5N724Q2T.cjs} +43 -3
  12. package/dist/chunk-5N724Q2T.cjs.map +1 -0
  13. package/dist/{chunk-3THIIWWW.cjs → chunk-AVEPEUN4.cjs} +4 -3
  14. package/dist/chunk-AVEPEUN4.cjs.map +1 -0
  15. package/dist/{chunk-DMSCGAWM.js → chunk-BZT5VYDT.js} +92 -9
  16. package/dist/chunk-BZT5VYDT.js.map +1 -0
  17. package/dist/chunk-CNU4A2XU.js +129 -0
  18. package/dist/chunk-CNU4A2XU.js.map +1 -0
  19. package/dist/{chunk-B2V3PUB7.js → chunk-G662L2YZ.js} +93 -116
  20. package/dist/chunk-G662L2YZ.js.map +1 -0
  21. package/dist/chunk-GDWMF6SB.cjs +133 -0
  22. package/dist/chunk-GDWMF6SB.cjs.map +1 -0
  23. package/dist/{chunk-7QEJ5QG5.js → chunk-IYJW2OVQ.js} +60 -22
  24. package/dist/chunk-IYJW2OVQ.js.map +1 -0
  25. package/dist/{chunk-A75S4TDD.js → chunk-JRDEOHAJ.js} +19 -11
  26. package/dist/chunk-JRDEOHAJ.js.map +1 -0
  27. package/dist/{chunk-SYRRSBGL.js → chunk-KM7EJKXV.js} +8 -4
  28. package/dist/chunk-KM7EJKXV.js.map +1 -0
  29. package/dist/{chunk-J7BPKKOG.cjs → chunk-LJFAAEU7.cjs} +8 -4
  30. package/dist/chunk-LJFAAEU7.cjs.map +1 -0
  31. package/dist/{chunk-WZC6CIVD.cjs → chunk-NLWACBE7.cjs} +19 -11
  32. package/dist/chunk-NLWACBE7.cjs.map +1 -0
  33. package/dist/{chunk-2JEDATG5.cjs → chunk-PLNQ4XER.cjs} +191 -150
  34. package/dist/chunk-PLNQ4XER.cjs.map +1 -0
  35. package/dist/{chunk-5QUKZCEF.js → chunk-PUYSH3IL.js} +4 -3
  36. package/dist/chunk-PUYSH3IL.js.map +1 -0
  37. package/dist/{chunk-OTU37YZO.js → chunk-X7564COI.js} +172 -131
  38. package/dist/chunk-X7564COI.js.map +1 -0
  39. package/dist/index.cjs +4 -0
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/server/handlers/a2a.cjs +7 -7
  44. package/dist/server/handlers/a2a.d.ts.map +1 -1
  45. package/dist/server/handlers/a2a.js +1 -1
  46. package/dist/server/handlers/agent-builder.cjs +16 -16
  47. package/dist/server/handlers/agent-builder.d.ts +5 -4
  48. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  49. package/dist/server/handlers/agent-builder.js +1 -1
  50. package/dist/server/handlers/agents.cjs +23 -15
  51. package/dist/server/handlers/agents.d.ts +46 -4
  52. package/dist/server/handlers/agents.d.ts.map +1 -1
  53. package/dist/server/handlers/agents.js +1 -1
  54. package/dist/server/handlers/observability.cjs +7 -3
  55. package/dist/server/handlers/observability.d.ts +18 -0
  56. package/dist/server/handlers/observability.d.ts.map +1 -1
  57. package/dist/server/handlers/observability.js +1 -1
  58. package/dist/server/handlers/scores.cjs +7 -7
  59. package/dist/server/handlers/scores.d.ts +208 -6
  60. package/dist/server/handlers/scores.d.ts.map +1 -1
  61. package/dist/server/handlers/scores.js +1 -1
  62. package/dist/server/handlers/tools.cjs +6 -6
  63. package/dist/server/handlers/tools.d.ts.map +1 -1
  64. package/dist/server/handlers/tools.js +1 -1
  65. package/dist/server/handlers/vNextNetwork.d.ts +73 -6
  66. package/dist/server/handlers/vNextNetwork.d.ts.map +1 -1
  67. package/dist/server/handlers/voice.cjs +5 -5
  68. package/dist/server/handlers/voice.d.ts +6 -4
  69. package/dist/server/handlers/voice.d.ts.map +1 -1
  70. package/dist/server/handlers/voice.js +1 -1
  71. package/dist/server/handlers/workflows.cjs +24 -16
  72. package/dist/server/handlers/workflows.d.ts +16 -7
  73. package/dist/server/handlers/workflows.d.ts.map +1 -1
  74. package/dist/server/handlers/workflows.js +1 -1
  75. package/dist/server/handlers.cjs +16 -21
  76. package/dist/server/handlers.d.ts +0 -1
  77. package/dist/server/handlers.d.ts.map +1 -1
  78. package/dist/server/handlers.js +8 -9
  79. package/dist/server/utils.d.ts +2 -0
  80. package/dist/server/utils.d.ts.map +1 -1
  81. package/package.json +8 -8
  82. package/dist/chunk-2JEDATG5.cjs.map +0 -1
  83. package/dist/chunk-3TETONBL.cjs.map +0 -1
  84. package/dist/chunk-3THIIWWW.cjs.map +0 -1
  85. package/dist/chunk-5QUKZCEF.js.map +0 -1
  86. package/dist/chunk-6LUKYSWE.cjs.map +0 -1
  87. package/dist/chunk-7QEJ5QG5.js.map +0 -1
  88. package/dist/chunk-A75S4TDD.js.map +0 -1
  89. package/dist/chunk-B2V3PUB7.js.map +0 -1
  90. package/dist/chunk-DMSCGAWM.js.map +0 -1
  91. package/dist/chunk-GUI3CROV.cjs.map +0 -1
  92. package/dist/chunk-IY34NOLA.cjs +0 -150
  93. package/dist/chunk-IY34NOLA.cjs.map +0 -1
  94. package/dist/chunk-J7BPKKOG.cjs.map +0 -1
  95. package/dist/chunk-L265APUD.cjs.map +0 -1
  96. package/dist/chunk-OTU37YZO.js.map +0 -1
  97. package/dist/chunk-R7NOGUZG.js.map +0 -1
  98. package/dist/chunk-SYRRSBGL.js.map +0 -1
  99. package/dist/chunk-U46VIX2V.js +0 -144
  100. package/dist/chunk-U46VIX2V.js.map +0 -1
  101. package/dist/chunk-WZC6CIVD.cjs.map +0 -1
  102. package/dist/server/handlers/network.cjs +0 -24
  103. package/dist/server/handlers/network.cjs.map +0 -1
  104. package/dist/server/handlers/network.d.ts +0 -50
  105. package/dist/server/handlers/network.d.ts.map +0 -1
  106. package/dist/server/handlers/network.js +0 -3
  107. package/dist/server/handlers/network.js.map +0 -1
@@ -1,9 +1,8 @@
1
- import { stringify } from './chunk-LF2ZLOFP.js';
1
+ import { getWorkflowInfo, WorkflowRegistry } from './chunk-CNU4A2XU.js';
2
2
  import { handleError } from './chunk-CY4TP3FK.js';
3
3
  import { HTTPException } from './chunk-MMROOK5J.js';
4
4
  import { __export } from './chunk-G3PMV62Z.js';
5
- import { ReadableStream } from 'stream/web';
6
- import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
5
+ import { ReadableStream, TransformStream } from 'stream/web';
7
6
 
8
7
  // src/server/handlers/workflows.ts
9
8
  var workflows_exports = {};
@@ -15,7 +14,9 @@ __export(workflows_exports, {
15
14
  getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
16
15
  getWorkflowRunsHandler: () => getWorkflowRunsHandler,
17
16
  getWorkflowsHandler: () => getWorkflowsHandler,
17
+ observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
18
18
  resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
19
+ resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
19
20
  resumeWorkflowHandler: () => resumeWorkflowHandler,
20
21
  sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
21
22
  startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
@@ -24,113 +25,6 @@ __export(workflows_exports, {
24
25
  streamWorkflowHandler: () => streamWorkflowHandler,
25
26
  watchWorkflowHandler: () => watchWorkflowHandler
26
27
  });
27
- function getSteps(steps, path) {
28
- return Object.entries(steps).reduce((acc, [key, step]) => {
29
- const fullKey = path ? `${path}.${key}` : key;
30
- acc[fullKey] = {
31
- id: step.id,
32
- description: step.description,
33
- inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
34
- outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
35
- resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
36
- suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
37
- isWorkflow: step.component === "WORKFLOW"
38
- };
39
- if (step.component === "WORKFLOW" && step.steps) {
40
- const nestedSteps = getSteps(step.steps, fullKey) || {};
41
- acc = { ...acc, ...nestedSteps };
42
- }
43
- return acc;
44
- }, {});
45
- }
46
- function getWorkflowInfo(workflow) {
47
- return {
48
- name: workflow.name,
49
- description: workflow.description,
50
- steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
51
- acc[key] = {
52
- id: step.id,
53
- description: step.description,
54
- inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
55
- outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
56
- resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
57
- suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0
58
- };
59
- return acc;
60
- }, {}),
61
- allSteps: getSteps(workflow.steps) || {},
62
- stepGraph: workflow.serializedStepGraph,
63
- inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : void 0,
64
- outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : void 0
65
- };
66
- }
67
- var WorkflowRegistry = class {
68
- static additionalWorkflows = {};
69
- /**
70
- * Register a workflow temporarily
71
- */
72
- static registerTemporaryWorkflow(id, workflow) {
73
- this.additionalWorkflows[id] = workflow;
74
- }
75
- /**
76
- * Register all workflows from map
77
- */
78
- static registerTemporaryWorkflows(workflows, mastra) {
79
- for (const [id, workflow] of Object.entries(workflows)) {
80
- if (mastra) {
81
- workflow.__registerMastra(mastra);
82
- workflow.__registerPrimitives({
83
- logger: mastra.getLogger(),
84
- telemetry: mastra.getTelemetry(),
85
- storage: mastra.getStorage(),
86
- memory: mastra.getMemory(),
87
- agents: mastra.getAgents(),
88
- tts: mastra.getTTS(),
89
- vectors: mastra.getVectors()
90
- });
91
- }
92
- this.additionalWorkflows[id] = workflow;
93
- }
94
- }
95
- /**
96
- * Get a workflow by ID from the registry (returns undefined if not found)
97
- */
98
- static getWorkflow(workflowId) {
99
- return this.additionalWorkflows[workflowId];
100
- }
101
- /**
102
- * Get all workflows from the registry
103
- */
104
- static getAllWorkflows() {
105
- return { ...this.additionalWorkflows };
106
- }
107
- /**
108
- * Clean up a temporary workflow
109
- */
110
- static cleanupTemporaryWorkflow(workflowId) {
111
- delete this.additionalWorkflows[workflowId];
112
- }
113
- /**
114
- * Clean up all registered workflows
115
- */
116
- static cleanup() {
117
- this.additionalWorkflows = {};
118
- }
119
- /**
120
- * Check if a workflow ID is a valid agent-builder workflow
121
- */
122
- static isAgentBuilderWorkflow(workflowId) {
123
- return workflowId in this.additionalWorkflows;
124
- }
125
- /**
126
- * Get all registered temporary workflow IDs (for debugging)
127
- */
128
- static getRegisteredWorkflowIds() {
129
- return Object.keys(this.additionalWorkflows);
130
- }
131
- };
132
-
133
- // src/server/handlers/workflows.ts
134
28
  async function getWorkflowsHandler({ mastra }) {
135
29
  try {
136
30
  const workflows = mastra.getWorkflows({ serialized: false });
@@ -393,22 +287,68 @@ async function streamWorkflowHandler({
393
287
  if (!workflow) {
394
288
  throw new HTTPException(404, { message: "Workflow not found" });
395
289
  }
290
+ const serverCache = mastra.getServerCache();
396
291
  const run = await workflow.createRunAsync({ runId });
397
292
  const result = run.stream({
398
293
  inputData,
399
- runtimeContext
294
+ runtimeContext,
295
+ onChunk: async (chunk) => {
296
+ if (serverCache) {
297
+ const cacheKey = runId;
298
+ await serverCache.listPush(cacheKey, chunk);
299
+ }
300
+ }
400
301
  });
401
302
  return result;
402
303
  } catch (error) {
403
304
  return handleError(error, "Error executing workflow");
404
305
  }
405
306
  }
307
+ async function observeStreamWorkflowHandler({
308
+ mastra,
309
+ workflowId,
310
+ runId
311
+ }) {
312
+ try {
313
+ if (!workflowId) {
314
+ throw new HTTPException(400, { message: "Workflow ID is required" });
315
+ }
316
+ if (!runId) {
317
+ throw new HTTPException(400, { message: "runId required to observe workflow stream" });
318
+ }
319
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
320
+ if (!workflow) {
321
+ throw new HTTPException(404, { message: "Workflow not found" });
322
+ }
323
+ const run = await workflow.getWorkflowRunById(runId);
324
+ if (!run) {
325
+ throw new HTTPException(404, { message: "Workflow run not found" });
326
+ }
327
+ const _run = await workflow.createRunAsync({ runId });
328
+ const serverCache = mastra.getServerCache();
329
+ if (!serverCache) {
330
+ throw new HTTPException(500, { message: "Server cache not found" });
331
+ }
332
+ const transformStream = new TransformStream();
333
+ const writer = transformStream.writable.getWriter();
334
+ const cachedRunChunks = await serverCache.listFromTo(runId, 0);
335
+ for (const chunk of cachedRunChunks) {
336
+ await writer.write(chunk);
337
+ }
338
+ writer.releaseLock();
339
+ const result = _run.observeStream();
340
+ return result.stream?.pipeThrough(transformStream);
341
+ } catch (error) {
342
+ return handleError(error, "Error observing workflow stream");
343
+ }
344
+ }
406
345
  async function streamVNextWorkflowHandler({
407
346
  mastra,
408
347
  runtimeContext,
409
348
  workflowId,
410
349
  runId,
411
- inputData
350
+ inputData,
351
+ closeOnSuspend
412
352
  }) {
413
353
  try {
414
354
  if (!workflowId) {
@@ -424,7 +364,8 @@ async function streamVNextWorkflowHandler({
424
364
  const run = await workflow.createRunAsync({ runId });
425
365
  const result = run.streamVNext({
426
366
  inputData,
427
- runtimeContext
367
+ runtimeContext,
368
+ closeOnSuspend
428
369
  });
429
370
  return result;
430
371
  } catch (error) {
@@ -503,6 +444,42 @@ async function resumeWorkflowHandler({
503
444
  return handleError(error, "Error resuming workflow");
504
445
  }
505
446
  }
447
+ async function resumeStreamWorkflowHandler({
448
+ mastra,
449
+ workflowId,
450
+ runId,
451
+ body,
452
+ runtimeContext
453
+ }) {
454
+ try {
455
+ if (!workflowId) {
456
+ throw new HTTPException(400, { message: "Workflow ID is required" });
457
+ }
458
+ if (!runId) {
459
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
460
+ }
461
+ if (!body.step) {
462
+ throw new HTTPException(400, { message: "step required to resume workflow" });
463
+ }
464
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
465
+ if (!workflow) {
466
+ throw new HTTPException(404, { message: "Workflow not found" });
467
+ }
468
+ const run = await workflow.getWorkflowRunById(runId);
469
+ if (!run) {
470
+ throw new HTTPException(404, { message: "Workflow run not found" });
471
+ }
472
+ const _run = await workflow.createRunAsync({ runId });
473
+ const stream = await _run.resumeStreamVNext({
474
+ step: body.step,
475
+ resumeData: body.resumeData,
476
+ runtimeContext
477
+ });
478
+ return stream;
479
+ } catch (error) {
480
+ return handleError(error, "Error resuming workflow");
481
+ }
482
+ }
506
483
  async function getWorkflowRunsHandler({
507
484
  mastra,
508
485
  workflowId,
@@ -586,6 +563,6 @@ async function sendWorkflowRunEventHandler({
586
563
  }
587
564
  }
588
565
 
589
- export { WorkflowRegistry, cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowInfo, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
590
- //# sourceMappingURL=chunk-B2V3PUB7.js.map
591
- //# sourceMappingURL=chunk-B2V3PUB7.js.map
566
+ export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
567
+ //# sourceMappingURL=chunk-G662L2YZ.js.map
568
+ //# sourceMappingURL=chunk-G662L2YZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/handlers/workflows.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,iBAAA,GAAA;AAAA,QAAA,CAAA,iBAAA,EAAA;AAAA,EAAA,wBAAA,EAAA,MAAA,wBAAA;AAAA,EAAA,wBAAA,EAAA,MAAA,wBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,yBAAA,EAAA,MAAA,yBAAA;AAAA,EAAA,oCAAA,EAAA,MAAA,oCAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,4BAAA,EAAA,MAAA,4BAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,yBAAA,EAAA,MAAA,yBAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,oBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAcA,eAAsB,mBAAA,CAAoB,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AC,KAAA,EAAO;AACV,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,6CAA6C,CAAA;AAAA,IACvF;AAEA,IAAA,MAAM,EAAE,UAAS,GAAI,MAAM,uBAAuB,EAAE,MAAA,EAAQ,YAAY,CAAA;AAExE,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,sBAAsB,CAAA;AAAA,IAChE;AAEA,IAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,kBAAA,CAAmB,KAAK,CAAA;AAEnD,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0BAA0B,CAAA;AAAA,IACpE;AAEA,IAAA,MAAM,OAAO,MAAM,QAAA,CAAS,cAAA,CAAe,EAAE,OAAO,CAAA;AAEpD,IAAA,MAAM,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,IAAI,CAAA;AAEhC,IAAA,OAAO,EAAE,SAAS,yBAAA,EAA0B;AAAA,EAC9C,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,kCAAkC,CAAA;AAAA,EAC9D;AACF","file":"chunk-G662L2YZ.js","sourcesContent":["import { ReadableStream, TransformStream } from 'node:stream/web';\nimport type { RuntimeContext } from '@mastra/core/di';\nimport type { WorkflowRuns } from '@mastra/core/storage';\nimport type { Workflow, WatchEvent, WorkflowInfo, StreamEvent } from '@mastra/core/workflows';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\nimport { getWorkflowInfo, WorkflowRegistry } from '../utils';\nimport { handleError } from './error';\n\nexport interface WorkflowContext extends Context {\n workflowId?: string;\n runId?: string;\n}\n\nexport async function getWorkflowsHandler({ mastra }: WorkflowContext) {\n try {\n const workflows = mastra.getWorkflows({ serialized: false });\n const _workflows = Object.entries(workflows).reduce<Record<string, WorkflowInfo>>((acc, [key, workflow]) => {\n acc[key] = getWorkflowInfo(workflow);\n return acc;\n }, {});\n return _workflows;\n } catch (error) {\n return handleError(error, 'Error getting workflows');\n }\n}\n\nasync function getWorkflowsFromSystem({ mastra, workflowId }: WorkflowContext) {\n const logger = mastra.getLogger();\n\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n let workflow;\n\n // First check registry for temporary workflows\n workflow = WorkflowRegistry.getWorkflow(workflowId);\n\n if (!workflow) {\n try {\n workflow = mastra.getWorkflow(workflowId);\n } catch (error) {\n logger.debug('Error getting workflow, searching agents for workflow', error);\n }\n }\n\n if (!workflow) {\n logger.debug('Workflow not found, searching agents for workflow', { workflowId });\n const agents = mastra.getAgents();\n\n if (Object.keys(agents || {}).length) {\n for (const [_, agent] of Object.entries(agents)) {\n try {\n const workflows = await agent.getWorkflows();\n\n if (workflows[workflowId]) {\n workflow = workflows[workflowId];\n break;\n }\n break;\n } catch (error) {\n logger.debug('Error getting workflow from agent', error);\n }\n }\n }\n }\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n return { workflow };\n}\n\nexport async function getWorkflowByIdHandler({ mastra, workflowId }: WorkflowContext): Promise<WorkflowInfo> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n return getWorkflowInfo(workflow);\n } catch (error) {\n return handleError(error, 'Error getting workflow');\n }\n}\n\nexport async function getWorkflowRunByIdHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<ReturnType<Workflow['getWorkflowRunById']>> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'Run ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n return run;\n } catch (error) {\n return handleError(error, 'Error getting workflow run');\n }\n}\n\nexport async function getWorkflowRunExecutionResultHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>): Promise<WatchEvent['payload']['workflowState']> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'Run ID is required' });\n }\n\n const workflow = mastra.getWorkflow(workflowId);\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const executionResult = await workflow.getWorkflowRunExecutionResult(runId);\n\n if (!executionResult) {\n throw new HTTPException(404, { message: 'Workflow run execution result not found' });\n }\n\n return executionResult;\n } catch (error) {\n return handleError(error, 'Error getting workflow run execution result');\n }\n}\n\nexport async function createWorkflowRunHandler({\n mastra,\n workflowId,\n runId: prevRunId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.createRunAsync({ runId: prevRunId });\n\n return { runId: run.runId };\n } catch (error) {\n return handleError(error, 'Error creating workflow run');\n }\n}\n\nexport async function startAsyncWorkflowHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n const result = await _run.start({\n inputData,\n runtimeContext,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error starting async workflow');\n }\n}\n\nexport async function startWorkflowRunHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to start run' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n void _run.start({\n inputData,\n runtimeContext,\n });\n\n return { message: 'Workflow run started' };\n } catch (e) {\n return handleError(e, 'Error starting workflow run');\n }\n}\n\nexport async function watchWorkflowHandler({\n mastra,\n workflowId,\n runId,\n eventType = 'watch',\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n eventType?: 'watch' | 'watch-v2';\n}): Promise<ReadableStream<string>> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to watch workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n let unwatch: () => void;\n let asyncRef: NodeJS.Immediate | null = null;\n const stream = new ReadableStream<string>({\n start(controller) {\n unwatch = _run.watch((event: any) => {\n const { type, payload, eventTimestamp } = event;\n controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));\n\n if (asyncRef) {\n clearImmediate(asyncRef);\n asyncRef = null;\n }\n\n // a run is finished if the status is not running\n asyncRef = setImmediate(async () => {\n const runDone = eventType === 'watch' ? payload.workflowState.status !== 'running' : type === 'finish';\n if (runDone) {\n controller.close();\n unwatch?.();\n }\n });\n }, eventType);\n },\n cancel() {\n if (asyncRef) {\n clearImmediate(asyncRef);\n asyncRef = null;\n }\n unwatch?.();\n },\n });\n\n return stream;\n } catch (error) {\n return handleError(error, 'Error watching workflow');\n }\n}\n\nexport async function streamWorkflowHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const serverCache = mastra.getServerCache();\n\n const run = await workflow.createRunAsync({ runId });\n const result = run.stream({\n inputData,\n runtimeContext,\n onChunk: async chunk => {\n if (serverCache) {\n const cacheKey = runId;\n await serverCache.listPush(cacheKey, chunk);\n }\n },\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing workflow');\n }\n}\n\nexport async function observeStreamWorkflowHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to observe workflow stream' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n const serverCache = mastra.getServerCache();\n if (!serverCache) {\n throw new HTTPException(500, { message: 'Server cache not found' });\n }\n\n const transformStream = new TransformStream<StreamEvent, StreamEvent>();\n\n const writer = transformStream.writable.getWriter();\n\n const cachedRunChunks = await serverCache.listFromTo(runId, 0);\n\n for (const chunk of cachedRunChunks) {\n await writer.write(chunk as any);\n }\n\n writer.releaseLock();\n\n const result = _run.observeStream();\n return result.stream?.pipeThrough(transformStream);\n } catch (error) {\n return handleError(error, 'Error observing workflow stream');\n }\n}\n\nexport async function streamVNextWorkflowHandler({\n mastra,\n runtimeContext,\n workflowId,\n runId,\n inputData,\n closeOnSuspend,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n closeOnSuspend?: boolean;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to stream workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.createRunAsync({ runId });\n const result = run.streamVNext({\n inputData,\n runtimeContext,\n closeOnSuspend,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error streaming workflow');\n }\n}\n\nexport async function resumeAsyncWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n if (!body.step) {\n throw new HTTPException(400, { message: 'step required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n const result = await _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error resuming workflow step');\n }\n}\n\nexport async function resumeWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n if (!body.step) {\n throw new HTTPException(400, { message: 'step required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n void _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n });\n\n return { message: 'Workflow run resumed' };\n } catch (error) {\n return handleError(error, 'Error resuming workflow');\n }\n}\n\nexport async function resumeStreamWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to resume workflow' });\n }\n\n if (!body.step) {\n throw new HTTPException(400, { message: 'step required to resume workflow' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n const stream = await _run.resumeStreamVNext({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n });\n\n return stream;\n } catch (error) {\n return handleError(error, 'Error resuming workflow');\n }\n}\n\nexport async function getWorkflowRunsHandler({\n mastra,\n workflowId,\n fromDate,\n toDate,\n limit,\n offset,\n resourceId,\n}: WorkflowContext & {\n fromDate?: Date;\n toDate?: Date;\n limit?: number;\n offset?: number;\n resourceId?: string;\n}): Promise<WorkflowRuns> {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const workflowRuns = (await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId })) || {\n runs: [],\n total: 0,\n };\n return workflowRuns;\n } catch (error) {\n return handleError(error, 'Error getting workflow runs');\n }\n}\n\nexport async function cancelWorkflowRunHandler({\n mastra,\n workflowId,\n runId,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'>) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to cancel workflow run' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n await _run.cancel();\n\n return { message: 'Workflow run cancelled' };\n } catch (error) {\n return handleError(error, 'Error canceling workflow run');\n }\n}\n\nexport async function sendWorkflowRunEventHandler({\n mastra,\n workflowId,\n runId,\n event,\n data,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n event: string;\n data: unknown;\n}) {\n try {\n if (!workflowId) {\n throw new HTTPException(400, { message: 'Workflow ID is required' });\n }\n\n if (!runId) {\n throw new HTTPException(400, { message: 'runId required to send workflow run event' });\n }\n\n const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });\n\n if (!workflow) {\n throw new HTTPException(404, { message: 'Workflow not found' });\n }\n\n const run = await workflow.getWorkflowRunById(runId);\n\n if (!run) {\n throw new HTTPException(404, { message: 'Workflow run not found' });\n }\n\n const _run = await workflow.createRunAsync({ runId });\n\n await _run.sendEvent(event, data);\n\n return { message: 'Workflow run event sent' };\n } catch (error) {\n return handleError(error, 'Error sending workflow run event');\n }\n}\n"]}
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ var chunkGU4EWMZB_cjs = require('./chunk-GU4EWMZB.cjs');
4
+ var zodToJson = require('@mastra/core/utils/zod-to-json');
5
+
6
+ function getSteps(steps, path) {
7
+ return Object.entries(steps).reduce((acc, [key, step]) => {
8
+ const fullKey = path ? `${path}.${key}` : key;
9
+ acc[fullKey] = {
10
+ id: step.id,
11
+ description: step.description,
12
+ inputSchema: step.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.inputSchema)) : void 0,
13
+ outputSchema: step.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.outputSchema)) : void 0,
14
+ resumeSchema: step.resumeSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.resumeSchema)) : void 0,
15
+ suspendSchema: step.suspendSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.suspendSchema)) : void 0,
16
+ isWorkflow: step.component === "WORKFLOW"
17
+ };
18
+ if (step.component === "WORKFLOW" && step.steps) {
19
+ const nestedSteps = getSteps(step.steps, fullKey) || {};
20
+ acc = { ...acc, ...nestedSteps };
21
+ }
22
+ return acc;
23
+ }, {});
24
+ }
25
+ function getWorkflowInfo(workflow) {
26
+ return {
27
+ name: workflow.name,
28
+ description: workflow.description,
29
+ steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
30
+ acc[key] = {
31
+ id: step.id,
32
+ description: step.description,
33
+ inputSchema: step.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.inputSchema)) : void 0,
34
+ outputSchema: step.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.outputSchema)) : void 0,
35
+ resumeSchema: step.resumeSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.resumeSchema)) : void 0,
36
+ suspendSchema: step.suspendSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(step.suspendSchema)) : void 0
37
+ };
38
+ return acc;
39
+ }, {}),
40
+ allSteps: getSteps(workflow.steps) || {},
41
+ stepGraph: workflow.serializedStepGraph,
42
+ inputSchema: workflow.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(workflow.inputSchema)) : void 0,
43
+ outputSchema: workflow.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.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
+ telemetry: mastra.getTelemetry(),
64
+ storage: mastra.getStorage(),
65
+ memory: mastra.getMemory(),
66
+ agents: mastra.getAgents(),
67
+ tts: mastra.getTTS(),
68
+ vectors: mastra.getVectors()
69
+ });
70
+ }
71
+ this.additionalWorkflows[id] = workflow;
72
+ }
73
+ }
74
+ /**
75
+ * Get a workflow by ID from the registry (returns undefined if not found)
76
+ */
77
+ static getWorkflow(workflowId) {
78
+ return this.additionalWorkflows[workflowId];
79
+ }
80
+ /**
81
+ * Get all workflows from the registry
82
+ */
83
+ static getAllWorkflows() {
84
+ return { ...this.additionalWorkflows };
85
+ }
86
+ /**
87
+ * Clean up a temporary workflow
88
+ */
89
+ static cleanupTemporaryWorkflow(workflowId) {
90
+ delete this.additionalWorkflows[workflowId];
91
+ }
92
+ /**
93
+ * Clean up all registered workflows
94
+ */
95
+ static cleanup() {
96
+ this.additionalWorkflows = {};
97
+ }
98
+ /**
99
+ * Check if a workflow ID is a valid agent-builder workflow
100
+ */
101
+ static isAgentBuilderWorkflow(workflowId) {
102
+ return workflowId in this.additionalWorkflows;
103
+ }
104
+ /**
105
+ * Get all registered temporary workflow IDs (for debugging)
106
+ */
107
+ static getRegisteredWorkflowIds() {
108
+ return Object.keys(this.additionalWorkflows);
109
+ }
110
+ };
111
+ function convertInstructionsToString(message) {
112
+ if (!message) {
113
+ return "";
114
+ }
115
+ if (typeof message === "string") {
116
+ return message;
117
+ }
118
+ if (Array.isArray(message)) {
119
+ return message.map((m) => {
120
+ if (typeof m === "string") {
121
+ return m;
122
+ }
123
+ return typeof m.content === "string" ? m.content : "";
124
+ }).filter((content) => content).join("\n");
125
+ }
126
+ return typeof message.content === "string" ? message.content : "";
127
+ }
128
+
129
+ exports.WorkflowRegistry = WorkflowRegistry;
130
+ exports.convertInstructionsToString = convertInstructionsToString;
131
+ exports.getWorkflowInfo = getWorkflowInfo;
132
+ //# sourceMappingURL=chunk-GDWMF6SB.cjs.map
133
+ //# sourceM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AA,EAA0B;AACxD,IAAA,OAAO,IAAA,CAAK,oBAAoB,UAAU,CAAA;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,OAAA,GAAgB;AAErB,IAAA,IAAA,CAAK,sBAAsB,EAAC;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,uBAAuB,UAAA,EAA6B;AACzD,IAAA,OAAO,cAAc,IAAA,CAAK,mBAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,wBAAA,GAAqC;AAC1C,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,IAAA,CAAK,mBAAmB,CAAA;AAAA,EAC7C;AACF;AAEO,SAAS,4BAA4B,OAAA,EAAgC;AAC1E,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAO,EAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,IAAA,OAAO,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-GDWMF6SB.cjs","sourcesContent":["import type { SystemMessage } from '@mastra/core';\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 };\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 };\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 telemetry: mastra.getTelemetry(),\n storage: mastra.getStorage(),\n memory: mastra.getMemory(),\n agents: mastra.getAgents(),\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"]}
@@ -18,19 +18,23 @@ async function getScorersFromSystem({
18
18
  const agents = mastra.getAgents();
19
19
  const workflows = mastra.getWorkflows();
20
20
  const scorersMap = /* @__PURE__ */ new Map();
21
- for (const [_agentId, agent] of Object.entries(agents)) {
21
+ for (const [agentId, agent] of Object.entries(agents)) {
22
22
  const scorers = await agent.getScorers({
23
23
  runtimeContext
24
24
  }) || {};
25
25
  if (Object.keys(scorers).length > 0) {
26
- for (const [scorerId, scorer] of Object.entries(scorers)) {
27
- if (scorersMap.has(scorerId)) {
28
- scorersMap.get(scorerId)?.agentIds.push(agent.name);
26
+ for (const [_scorerId, scorer] of Object.entries(scorers)) {
27
+ const scorerName = scorer.scorer.name;
28
+ if (scorersMap.has(scorerName)) {
29
+ scorersMap.get(scorerName)?.agentIds.push(agentId);
30
+ scorersMap.get(scorerName)?.agentNames.push(agent.name);
29
31
  } else {
30
- scorersMap.set(scorerId, {
32
+ scorersMap.set(scorerName, {
31
33
  workflowIds: [],
32
34
  ...scorer,
33
- agentIds: [agent.name]
35
+ agentNames: [agent.name],
36
+ agentIds: [agentId],
37
+ isRegistered: false
34
38
  });
35
39
  }
36
40
  }
@@ -41,19 +45,37 @@ async function getScorersFromSystem({
41
45
  runtimeContext
42
46
  }) || {};
43
47
  if (Object.keys(scorers).length > 0) {
44
- for (const [scorerId, scorer] of Object.entries(scorers)) {
45
- if (scorersMap.has(scorerId)) {
46
- scorersMap.get(scorerId)?.workflowIds.push(workflowId);
48
+ for (const [_scorerId, scorer] of Object.entries(scorers)) {
49
+ const scorerName = scorer.scorer.name;
50
+ if (scorersMap.has(scorerName)) {
51
+ scorersMap.get(scorerName)?.workflowIds.push(workflowId);
47
52
  } else {
48
- scorersMap.set(scorerId, {
53
+ scorersMap.set(scorerName, {
49
54
  agentIds: [],
55
+ agentNames: [],
50
56
  ...scorer,
51
- workflowIds: [workflowId]
57
+ workflowIds: [workflowId],
58
+ isRegistered: false
52
59
  });
53
60
  }
54
61
  }
55
62
  }
56
63
  }
64
+ const registeredScorers = await mastra.getScorers();
65
+ for (const [_scorerId, scorer] of Object.entries(registeredScorers || {})) {
66
+ const scorerName = scorer.name;
67
+ if (scorersMap.has(scorerName)) {
68
+ scorersMap.get(scorerName).isRegistered = true;
69
+ } else {
70
+ scorersMap.set(scorerName, {
71
+ scorer,
72
+ agentIds: [],
73
+ agentNames: [],
74
+ workflowIds: [],
75
+ isRegistered: true
76
+ });
77
+ }
78
+ }
57
79
  return Object.fromEntries(scorersMap.entries());
58
80
  }
59
81
  async function getScorersHandler({ mastra, runtimeContext }) {
@@ -84,11 +106,14 @@ async function getScoresByRunIdHandler({
84
106
  pagination
85
107
  }) {
86
108
  try {
87
- const scores = await mastra.getStorage()?.getScoresByRunId?.({
109
+ const scoreResults = await mastra.getStorage()?.getScoresByRunId?.({
88
110
  runId,
89
111
  pagination
90
- }) || [];
91
- return scores;
112
+ }) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };
113
+ return {
114
+ pagination: scoreResults.pagination,
115
+ scores: scoreResults.scores.map((score) => ({ ...score, ...getTraceDetails(score.traceId) }))
116
+ };
92
117
  } catch (error) {
93
118
  return handleError(error, "Error getting scores by run id");
94
119
  }
@@ -101,13 +126,16 @@ async function getScoresByScorerIdHandler({
101
126
  entityType
102
127
  }) {
103
128
  try {
104
- const scores = await mastra.getStorage()?.getScoresByScorerId?.({
129
+ const scoreResults = await mastra.getStorage()?.getScoresByScorerId?.({
105
130
  scorerId,
106
131
  pagination,
107
132
  entityId,
108
133
  entityType
109
- }) || [];
110
- return scores;
134
+ }) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };
135
+ return {
136
+ pagination: scoreResults.pagination,
137
+ scores: scoreResults.scores.map((score) => ({ ...score, ...getTraceDetails(score.traceId) }))
138
+ };
111
139
  } catch (error) {
112
140
  return handleError(error, "Error getting scores by scorer id");
113
141
  }
@@ -127,16 +155,26 @@ async function getScoresByEntityIdHandler({
127
155
  const workflow = mastra.getWorkflowById(entityId);
128
156
  entityIdToUse = workflow.id;
129
157
  }
130
- const scores = await mastra.getStorage()?.getScoresByEntityId?.({
158
+ const scoreResults = await mastra.getStorage()?.getScoresByEntityId?.({
131
159
  entityId: entityIdToUse,
132
160
  entityType,
133
161
  pagination
134
- }) || [];
135
- return scores;
162
+ }) || { pagination: { total: 0, page: 0, perPage: 0, hasMore: false }, scores: [] };
163
+ return {
164
+ pagination: scoreResults.pagination,
165
+ scores: scoreResults.scores.map((score) => ({ ...score, ...getTraceDetails(score.traceId) }))
166
+ };
136
167
  } catch (error) {
137
168
  return handleError(error, "Error getting scores by entity id");
138
169
  }
139
170
  }
171
+ function getTraceDetails(traceIdWithSpanId) {
172
+ if (!traceIdWithSpanId) {
173
+ return {};
174
+ }
175
+ const [traceId, spanId] = traceIdWithSpanId.split("-");
176
+ return { traceId, spanId };
177
+ }
140
178
  async function saveScoreHandler({ mastra, score }) {
141
179
  try {
142
180
  const scores = await mastra.getStorage()?.saveScore?.(score) || [];
@@ -147,5 +185,5 @@ async function saveScoreHandler({ mastra, score }) {
147
185
  }
148
186
 
149
187
  export { getScorerHandler, getScorersHandler, getScoresByEntityIdHandler, getScoresByRunIdHandler, getScoresByScorerIdHandler, saveScoreHandler, scores_exports };
150
- //# sourceMappingURL=chunk-7QEJ5QG5.js.map
151
- //# sourceMappingURL=chunk-7QEJ5QG5.js.map
188
+ //# sourceMappingURL=chunk-IYJW2OVQ.js.map
189
+ //# sourceMappingURL=chunk-IYJW2OVQ.js.map