@mastra/server 0.19.1 → 0.20.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/{chunk-GIM2ZSPB.cjs → chunk-4HS3I2TI.cjs} +91 -12
- package/dist/chunk-4HS3I2TI.cjs.map +1 -0
- package/dist/{chunk-QGW2VHZU.js → chunk-AX5SCBJL.js} +91 -13
- package/dist/chunk-AX5SCBJL.js.map +1 -0
- package/dist/{chunk-2QPKCXLB.cjs → chunk-FYZHFAFB.cjs} +76 -36
- package/dist/chunk-FYZHFAFB.cjs.map +1 -0
- package/dist/{chunk-6QZD7S52.js → chunk-HRG5HN4U.js} +74 -34
- package/dist/chunk-HRG5HN4U.js.map +1 -0
- package/dist/{chunk-BNNUFPA7.cjs → chunk-JOXMWFM6.cjs} +33 -33
- package/dist/{chunk-BNNUFPA7.cjs.map → chunk-JOXMWFM6.cjs.map} +1 -1
- package/dist/{chunk-OZLRIVC4.cjs → chunk-LHGBI76Y.cjs} +19 -39
- package/dist/chunk-LHGBI76Y.cjs.map +1 -0
- package/dist/{chunk-JHH2BWAB.js → chunk-QDPOVUS4.js} +19 -19
- package/dist/{chunk-JHH2BWAB.js.map → chunk-QDPOVUS4.js.map} +1 -1
- package/dist/{chunk-SQY4T6EJ.js → chunk-SZUAJANR.js} +19 -39
- package/dist/chunk-SZUAJANR.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.d.ts.map +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +25 -25
- package/dist/server/handlers/agents.d.ts +24 -21
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/memory.cjs +16 -16
- package/dist/server/handlers/memory.d.ts +14 -15
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/workflows.cjs +22 -18
- package/dist/server/handlers/workflows.d.ts +2 -1
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +13 -13
- package/dist/server/handlers.js +5 -5
- package/package.json +5 -5
- package/dist/chunk-2QPKCXLB.cjs.map +0 -1
- package/dist/chunk-6QZD7S52.js.map +0 -1
- package/dist/chunk-GIM2ZSPB.cjs.map +0 -1
- package/dist/chunk-OZLRIVC4.cjs.map +0 -1
- package/dist/chunk-QGW2VHZU.js.map +0 -1
- package/dist/chunk-SQY4T6EJ.js.map +0 -1
- package/dist/server/handlers/vNextNetwork.cjs +0 -220
- package/dist/server/handlers/vNextNetwork.cjs.map +0 -1
- package/dist/server/handlers/vNextNetwork.d.ts +0 -246
- package/dist/server/handlers/vNextNetwork.d.ts.map +0 -1
- package/dist/server/handlers/vNextNetwork.js +0 -213
- package/dist/server/handlers/vNextNetwork.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @mastra/server
|
|
2
2
|
|
|
3
|
+
## 0.20.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Breaking change to move the agent.streamVNext/generateVNext implementation to the default stream/generate. The old stream/generate have now been moved to streamLegacy and generateLegacy ([#8097](https://github.com/mastra-ai/mastra/pull/8097))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Add approve and decline tool calls to mastra server pkg ([#8360](https://github.com/mastra-ai/mastra/pull/8360))
|
|
12
|
+
|
|
13
|
+
- Fix/8219 preserve resourceid on resume ([#8359](https://github.com/mastra-ai/mastra/pull/8359))
|
|
14
|
+
|
|
15
|
+
- Add observe strean to get streans after workflow has been interrupted ([#8318](https://github.com/mastra-ai/mastra/pull/8318))
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`00cb6bd`](https://github.com/mastra-ai/mastra/commit/00cb6bdf78737c0fac14a5a0c7b532a11e38558a), [`869ba22`](https://github.com/mastra-ai/mastra/commit/869ba222e1d6b58fc1b65e7c9fd55ca4e01b8c2f), [`1b73665`](https://github.com/mastra-ai/mastra/commit/1b73665e8e23f5c09d49fcf3e7d709c75259259e), [`f7d7475`](https://github.com/mastra-ai/mastra/commit/f7d747507341aef60ed39e4b49318db1f86034a6), [`084b77b`](https://github.com/mastra-ai/mastra/commit/084b77b2955960e0190af8db3f77138aa83ed65c), [`a93ff84`](https://github.com/mastra-ai/mastra/commit/a93ff84b5e1af07ee236ac8873dac9b49aa5d501), [`bc5aacb`](https://github.com/mastra-ai/mastra/commit/bc5aacb646d468d325327e36117129f28cd13bf6), [`6b5af12`](https://github.com/mastra-ai/mastra/commit/6b5af12ce9e09066e0c32e821c203a6954498bea), [`bf60e4a`](https://github.com/mastra-ai/mastra/commit/bf60e4a89c515afd9570b7b79f33b95e7d07c397), [`d41aee5`](https://github.com/mastra-ai/mastra/commit/d41aee526d124e35f42720a08e64043229193679), [`e8fe13c`](https://github.com/mastra-ai/mastra/commit/e8fe13c4b4c255a42520127797ec394310f7c919), [`3ca833d`](https://github.com/mastra-ai/mastra/commit/3ca833dc994c38e3c9b4f9b4478a61cd8e07b32a), [`1edb8d1`](https://github.com/mastra-ai/mastra/commit/1edb8d1cfb963e72a12412990fb9170936c9904c), [`fbf6e32`](https://github.com/mastra-ai/mastra/commit/fbf6e324946332d0f5ed8930bf9d4d4479cefd7a), [`4753027`](https://github.com/mastra-ai/mastra/commit/4753027ee889288775c6958bdfeda03ff909af67)]:
|
|
18
|
+
- @mastra/core@0.20.0-alpha.0
|
|
19
|
+
|
|
3
20
|
## 0.19.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -16,6 +16,7 @@ chunkEMMSS5I5_cjs.__export(workflows_exports, {
|
|
|
16
16
|
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
17
17
|
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
18
18
|
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
19
|
+
observeStreamVNextWorkflowHandler: () => observeStreamVNextWorkflowHandler,
|
|
19
20
|
observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
|
|
20
21
|
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
21
22
|
resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
|
|
@@ -209,7 +210,7 @@ async function startWorkflowRunHandler({
|
|
|
209
210
|
if (!run) {
|
|
210
211
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
211
212
|
}
|
|
212
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
213
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
213
214
|
void _run.start({
|
|
214
215
|
inputData,
|
|
215
216
|
runtimeContext,
|
|
@@ -241,7 +242,7 @@ async function watchWorkflowHandler({
|
|
|
241
242
|
if (!run) {
|
|
242
243
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
243
244
|
}
|
|
244
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
245
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
245
246
|
let unwatch;
|
|
246
247
|
let asyncRef = null;
|
|
247
248
|
const stream = new web.ReadableStream({
|
|
@@ -332,7 +333,7 @@ async function observeStreamWorkflowHandler({
|
|
|
332
333
|
if (!run) {
|
|
333
334
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
334
335
|
}
|
|
335
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
336
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
336
337
|
const serverCache = mastra.getServerCache();
|
|
337
338
|
if (!serverCache) {
|
|
338
339
|
throw new chunk7NADHFD2_cjs.HTTPException(500, { message: "Server cache not found" });
|
|
@@ -370,11 +371,18 @@ async function streamVNextWorkflowHandler({
|
|
|
370
371
|
if (!workflow) {
|
|
371
372
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
372
373
|
}
|
|
374
|
+
const serverCache = mastra.getServerCache();
|
|
373
375
|
const run = await workflow.createRunAsync({ runId });
|
|
374
376
|
const result = run.streamVNext({
|
|
375
377
|
inputData,
|
|
376
378
|
runtimeContext,
|
|
377
379
|
closeOnSuspend,
|
|
380
|
+
onChunk: async (chunk) => {
|
|
381
|
+
if (serverCache) {
|
|
382
|
+
const cacheKey = runId;
|
|
383
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
384
|
+
}
|
|
385
|
+
},
|
|
378
386
|
tracingOptions
|
|
379
387
|
});
|
|
380
388
|
return result;
|
|
@@ -382,6 +390,69 @@ async function streamVNextWorkflowHandler({
|
|
|
382
390
|
return chunkRE4RPXT2_cjs.handleError(error, "Error streaming workflow");
|
|
383
391
|
}
|
|
384
392
|
}
|
|
393
|
+
async function observeStreamVNextWorkflowHandler({
|
|
394
|
+
mastra,
|
|
395
|
+
workflowId,
|
|
396
|
+
runId
|
|
397
|
+
}) {
|
|
398
|
+
try {
|
|
399
|
+
if (!workflowId) {
|
|
400
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
401
|
+
}
|
|
402
|
+
if (!runId) {
|
|
403
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
404
|
+
}
|
|
405
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
406
|
+
if (!workflow) {
|
|
407
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
408
|
+
}
|
|
409
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
410
|
+
if (!run) {
|
|
411
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
412
|
+
}
|
|
413
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
414
|
+
const serverCache = mastra.getServerCache();
|
|
415
|
+
if (!serverCache) {
|
|
416
|
+
throw new chunk7NADHFD2_cjs.HTTPException(500, { message: "Server cache not found" });
|
|
417
|
+
}
|
|
418
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, 0);
|
|
419
|
+
const combinedStream = new web.ReadableStream({
|
|
420
|
+
start(controller) {
|
|
421
|
+
const emitCachedChunks = async () => {
|
|
422
|
+
for (const chunk of cachedRunChunks) {
|
|
423
|
+
controller.enqueue(chunk);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const liveStream = _run.observeStreamVNext();
|
|
427
|
+
const reader = liveStream.getReader();
|
|
428
|
+
const pump = async () => {
|
|
429
|
+
try {
|
|
430
|
+
while (true) {
|
|
431
|
+
const { done, value } = await reader.read();
|
|
432
|
+
if (done) {
|
|
433
|
+
controller.close();
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
controller.enqueue(value);
|
|
437
|
+
}
|
|
438
|
+
} catch (error) {
|
|
439
|
+
controller.error(error);
|
|
440
|
+
} finally {
|
|
441
|
+
reader.releaseLock();
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
void emitCachedChunks().then(() => {
|
|
445
|
+
void pump();
|
|
446
|
+
}).catch((error) => {
|
|
447
|
+
controller.error(error);
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
return combinedStream;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error observing workflow stream");
|
|
454
|
+
}
|
|
455
|
+
}
|
|
385
456
|
async function resumeAsyncWorkflowHandler({
|
|
386
457
|
mastra,
|
|
387
458
|
workflowId,
|
|
@@ -408,7 +479,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
408
479
|
if (!run) {
|
|
409
480
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
410
481
|
}
|
|
411
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
482
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
412
483
|
const result = await _run.resume({
|
|
413
484
|
step: body.step,
|
|
414
485
|
resumeData: body.resumeData,
|
|
@@ -446,7 +517,7 @@ async function resumeWorkflowHandler({
|
|
|
446
517
|
if (!run) {
|
|
447
518
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
448
519
|
}
|
|
449
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
520
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
450
521
|
void _run.resume({
|
|
451
522
|
step: body.step,
|
|
452
523
|
resumeData: body.resumeData,
|
|
@@ -484,12 +555,19 @@ async function resumeStreamWorkflowHandler({
|
|
|
484
555
|
if (!run) {
|
|
485
556
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
486
557
|
}
|
|
487
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
488
|
-
const
|
|
558
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
559
|
+
const serverCache = mastra.getServerCache();
|
|
560
|
+
const stream = _run.resumeStreamVNext({
|
|
489
561
|
step: body.step,
|
|
490
562
|
resumeData: body.resumeData,
|
|
491
563
|
runtimeContext,
|
|
492
|
-
tracingOptions
|
|
564
|
+
tracingOptions,
|
|
565
|
+
onChunk: async (chunk) => {
|
|
566
|
+
if (serverCache) {
|
|
567
|
+
const cacheKey = runId;
|
|
568
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
493
571
|
});
|
|
494
572
|
return stream;
|
|
495
573
|
} catch (error) {
|
|
@@ -542,7 +620,7 @@ async function cancelWorkflowRunHandler({
|
|
|
542
620
|
if (!run) {
|
|
543
621
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
544
622
|
}
|
|
545
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
623
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
546
624
|
await _run.cancel();
|
|
547
625
|
return { message: "Workflow run cancelled" };
|
|
548
626
|
} catch (error) {
|
|
@@ -571,7 +649,7 @@ async function sendWorkflowRunEventHandler({
|
|
|
571
649
|
if (!run) {
|
|
572
650
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
573
651
|
}
|
|
574
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
652
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
575
653
|
await _run.sendEvent(event, data);
|
|
576
654
|
return { message: "Workflow run event sent" };
|
|
577
655
|
} catch (error) {
|
|
@@ -586,6 +664,7 @@ exports.getWorkflowRunByIdHandler = getWorkflowRunByIdHandler;
|
|
|
586
664
|
exports.getWorkflowRunExecutionResultHandler = getWorkflowRunExecutionResultHandler;
|
|
587
665
|
exports.getWorkflowRunsHandler = getWorkflowRunsHandler;
|
|
588
666
|
exports.getWorkflowsHandler = getWorkflowsHandler;
|
|
667
|
+
exports.observeStreamVNextWorkflowHandler = observeStreamVNextWorkflowHandler;
|
|
589
668
|
exports.observeStreamWorkflowHandler = observeStreamWorkflowHandler;
|
|
590
669
|
exports.resumeAsyncWorkflowHandler = resumeAsyncWorkflowHandler;
|
|
591
670
|
exports.resumeStreamWorkflowHandler = resumeStreamWorkflowHandler;
|
|
@@ -597,5 +676,5 @@ exports.streamVNextWorkflowHandler = streamVNextWorkflowHandler;
|
|
|
597
676
|
exports.streamWorkflowHandler = streamWorkflowHandler;
|
|
598
677
|
exports.watchWorkflowHandler = watchWorkflowHandler;
|
|
599
678
|
exports.workflows_exports = workflows_exports;
|
|
600
|
-
//# sourceMappingURL=chunk-
|
|
601
|
-
//# sourceMappingURL=chunk-
|
|
679
|
+
//# sourceMappingURL=chunk-4HS3I2TI.cjs.map
|
|
680
|
+
//# sourceMappingURL=chunk-4HS3I2TI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/workflows.ts"],"names":["__export","getWorkflowInfo","handleError","HTTPException","WorkflowRegistry","ReadableStream","TransformStream"],"mappings":";;;;;;;;;AAAA,IAAA,iBAAA,GAAA;AAAAA,0BAAA,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,iCAAA,EAAA,MAAA,iCAAA;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;AAeA,eAAsB,mBAAA,CAAoB,EAAE,MAAA,EAAO,EAAoB;AACrE,EAAA,IAAI;AACF,IAAA,MAAM,YAAY,MAAA,CAAO,YAAA,CAAa,EAAE,UAAA,EAAY,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,OAAA,CAAQ,SAAS,CAAA,CAAE,MAAA,CAAqC,CAAC,GAAA,EAAK,CAAC,GAAA,EAAK,QAAQ,CAAA,KAAM;AAC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AEnD,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0BAA0B,CAAA;AAAA,IACpE;AAEA,IAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,cAAA,CAAe,EAAE,KAAA,EAAO,UAAA,EAAY,GAAA,CAAI,UAAA,EAAY,CAAA;AAEhF,IAAA,MAAM,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,IAAI,CAAA;AAEhC,IAAA,OAAO,EAAE,SAAS,yBAAA,EAA0B;AAAA,EAC9C,SAAS,KAAA,EAAO;AACd,IAAA,OAAOD,6BAAA,CAAY,OAAO,kCAAkC,CAAA;AAAA,EAC9D;AACF","file":"chunk-4HS3I2TI.cjs","sourcesContent":["import { ReadableStream, TransformStream } from 'node:stream/web';\nimport type { TracingOptions } from '@mastra/core/ai-tracing';\nimport type { RuntimeContext } from '@mastra/core/di';\nimport type { WorkflowRuns } from '@mastra/core/storage';\nimport type { Workflow, WatchEvent, WorkflowInfo, StreamEvent, ChunkType } 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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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 tracingOptions,\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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n void _run.start({\n inputData,\n runtimeContext,\n tracingOptions,\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, resourceId: run.resourceId });\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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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 tracingOptions,\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, resourceId: run.resourceId });\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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n closeOnSuspend?: boolean;\n tracingOptions?: TracingOptions;\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 serverCache = mastra.getServerCache();\n\n const run = await workflow.createRunAsync({ runId });\n const result = run.streamVNext({\n inputData,\n runtimeContext,\n closeOnSuspend,\n onChunk: async chunk => {\n if (serverCache) {\n const cacheKey = runId;\n await serverCache.listPush(cacheKey, chunk);\n }\n },\n tracingOptions,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error streaming workflow');\n }\n}\n\nexport async function observeStreamVNextWorkflowHandler({\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, resourceId: run.resourceId });\n const serverCache = mastra.getServerCache();\n if (!serverCache) {\n throw new HTTPException(500, { message: 'Server cache not found' });\n }\n\n // Get cached chunks first\n const cachedRunChunks = await serverCache.listFromTo(runId, 0);\n\n // Create a readable stream that first emits cached chunks, then the live stream\n const combinedStream = new ReadableStream<ChunkType>({\n start(controller) {\n // First, emit all cached chunks\n const emitCachedChunks = async () => {\n for (const chunk of cachedRunChunks) {\n controller.enqueue(chunk as ChunkType);\n }\n };\n\n // Then, pipe the live stream\n const liveStream = _run.observeStreamVNext();\n const reader = liveStream.getReader();\n\n const pump = async () => {\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n break;\n }\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n } finally {\n reader.releaseLock();\n }\n };\n\n // Start with cached chunks, then live stream\n void emitCachedChunks()\n .then(() => {\n void pump();\n })\n .catch(error => {\n controller.error(error);\n });\n },\n });\n\n return combinedStream;\n } catch (error) {\n return handleError(error, 'Error observing workflow stream');\n }\n}\n\nexport async function resumeAsyncWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n tracingOptions,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n const result = await _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n tracingOptions,\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 tracingOptions,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n\n void _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n tracingOptions,\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 tracingOptions,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n const serverCache = mastra.getServerCache();\n\n const stream = _run.resumeStreamVNext({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n tracingOptions,\n onChunk: async chunk => {\n if (serverCache) {\n const cacheKey = runId;\n await serverCache.listPush(cacheKey, chunk);\n }\n },\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, resourceId: run.resourceId });\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, resourceId: run.resourceId });\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"]}
|
|
@@ -14,6 +14,7 @@ __export(workflows_exports, {
|
|
|
14
14
|
getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
|
|
15
15
|
getWorkflowRunsHandler: () => getWorkflowRunsHandler,
|
|
16
16
|
getWorkflowsHandler: () => getWorkflowsHandler,
|
|
17
|
+
observeStreamVNextWorkflowHandler: () => observeStreamVNextWorkflowHandler,
|
|
17
18
|
observeStreamWorkflowHandler: () => observeStreamWorkflowHandler,
|
|
18
19
|
resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
|
|
19
20
|
resumeStreamWorkflowHandler: () => resumeStreamWorkflowHandler,
|
|
@@ -207,7 +208,7 @@ async function startWorkflowRunHandler({
|
|
|
207
208
|
if (!run) {
|
|
208
209
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
209
210
|
}
|
|
210
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
211
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
211
212
|
void _run.start({
|
|
212
213
|
inputData,
|
|
213
214
|
runtimeContext,
|
|
@@ -239,7 +240,7 @@ async function watchWorkflowHandler({
|
|
|
239
240
|
if (!run) {
|
|
240
241
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
241
242
|
}
|
|
242
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
243
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
243
244
|
let unwatch;
|
|
244
245
|
let asyncRef = null;
|
|
245
246
|
const stream = new ReadableStream({
|
|
@@ -330,7 +331,7 @@ async function observeStreamWorkflowHandler({
|
|
|
330
331
|
if (!run) {
|
|
331
332
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
332
333
|
}
|
|
333
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
334
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
334
335
|
const serverCache = mastra.getServerCache();
|
|
335
336
|
if (!serverCache) {
|
|
336
337
|
throw new HTTPException(500, { message: "Server cache not found" });
|
|
@@ -368,11 +369,18 @@ async function streamVNextWorkflowHandler({
|
|
|
368
369
|
if (!workflow) {
|
|
369
370
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
370
371
|
}
|
|
372
|
+
const serverCache = mastra.getServerCache();
|
|
371
373
|
const run = await workflow.createRunAsync({ runId });
|
|
372
374
|
const result = run.streamVNext({
|
|
373
375
|
inputData,
|
|
374
376
|
runtimeContext,
|
|
375
377
|
closeOnSuspend,
|
|
378
|
+
onChunk: async (chunk) => {
|
|
379
|
+
if (serverCache) {
|
|
380
|
+
const cacheKey = runId;
|
|
381
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
382
|
+
}
|
|
383
|
+
},
|
|
376
384
|
tracingOptions
|
|
377
385
|
});
|
|
378
386
|
return result;
|
|
@@ -380,6 +388,69 @@ async function streamVNextWorkflowHandler({
|
|
|
380
388
|
return handleError(error, "Error streaming workflow");
|
|
381
389
|
}
|
|
382
390
|
}
|
|
391
|
+
async function observeStreamVNextWorkflowHandler({
|
|
392
|
+
mastra,
|
|
393
|
+
workflowId,
|
|
394
|
+
runId
|
|
395
|
+
}) {
|
|
396
|
+
try {
|
|
397
|
+
if (!workflowId) {
|
|
398
|
+
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
399
|
+
}
|
|
400
|
+
if (!runId) {
|
|
401
|
+
throw new HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
402
|
+
}
|
|
403
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
404
|
+
if (!workflow) {
|
|
405
|
+
throw new HTTPException(404, { message: "Workflow not found" });
|
|
406
|
+
}
|
|
407
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
408
|
+
if (!run) {
|
|
409
|
+
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
410
|
+
}
|
|
411
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
412
|
+
const serverCache = mastra.getServerCache();
|
|
413
|
+
if (!serverCache) {
|
|
414
|
+
throw new HTTPException(500, { message: "Server cache not found" });
|
|
415
|
+
}
|
|
416
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, 0);
|
|
417
|
+
const combinedStream = new ReadableStream({
|
|
418
|
+
start(controller) {
|
|
419
|
+
const emitCachedChunks = async () => {
|
|
420
|
+
for (const chunk of cachedRunChunks) {
|
|
421
|
+
controller.enqueue(chunk);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const liveStream = _run.observeStreamVNext();
|
|
425
|
+
const reader = liveStream.getReader();
|
|
426
|
+
const pump = async () => {
|
|
427
|
+
try {
|
|
428
|
+
while (true) {
|
|
429
|
+
const { done, value } = await reader.read();
|
|
430
|
+
if (done) {
|
|
431
|
+
controller.close();
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
controller.enqueue(value);
|
|
435
|
+
}
|
|
436
|
+
} catch (error) {
|
|
437
|
+
controller.error(error);
|
|
438
|
+
} finally {
|
|
439
|
+
reader.releaseLock();
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
void emitCachedChunks().then(() => {
|
|
443
|
+
void pump();
|
|
444
|
+
}).catch((error) => {
|
|
445
|
+
controller.error(error);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
return combinedStream;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
return handleError(error, "Error observing workflow stream");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
383
454
|
async function resumeAsyncWorkflowHandler({
|
|
384
455
|
mastra,
|
|
385
456
|
workflowId,
|
|
@@ -406,7 +477,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
406
477
|
if (!run) {
|
|
407
478
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
408
479
|
}
|
|
409
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
480
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
410
481
|
const result = await _run.resume({
|
|
411
482
|
step: body.step,
|
|
412
483
|
resumeData: body.resumeData,
|
|
@@ -444,7 +515,7 @@ async function resumeWorkflowHandler({
|
|
|
444
515
|
if (!run) {
|
|
445
516
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
446
517
|
}
|
|
447
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
518
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
448
519
|
void _run.resume({
|
|
449
520
|
step: body.step,
|
|
450
521
|
resumeData: body.resumeData,
|
|
@@ -482,12 +553,19 @@ async function resumeStreamWorkflowHandler({
|
|
|
482
553
|
if (!run) {
|
|
483
554
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
484
555
|
}
|
|
485
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
486
|
-
const
|
|
556
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
557
|
+
const serverCache = mastra.getServerCache();
|
|
558
|
+
const stream = _run.resumeStreamVNext({
|
|
487
559
|
step: body.step,
|
|
488
560
|
resumeData: body.resumeData,
|
|
489
561
|
runtimeContext,
|
|
490
|
-
tracingOptions
|
|
562
|
+
tracingOptions,
|
|
563
|
+
onChunk: async (chunk) => {
|
|
564
|
+
if (serverCache) {
|
|
565
|
+
const cacheKey = runId;
|
|
566
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
491
569
|
});
|
|
492
570
|
return stream;
|
|
493
571
|
} catch (error) {
|
|
@@ -540,7 +618,7 @@ async function cancelWorkflowRunHandler({
|
|
|
540
618
|
if (!run) {
|
|
541
619
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
542
620
|
}
|
|
543
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
621
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
544
622
|
await _run.cancel();
|
|
545
623
|
return { message: "Workflow run cancelled" };
|
|
546
624
|
} catch (error) {
|
|
@@ -569,7 +647,7 @@ async function sendWorkflowRunEventHandler({
|
|
|
569
647
|
if (!run) {
|
|
570
648
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
571
649
|
}
|
|
572
|
-
const _run = await workflow.createRunAsync({ runId });
|
|
650
|
+
const _run = await workflow.createRunAsync({ runId, resourceId: run.resourceId });
|
|
573
651
|
await _run.sendEvent(event, data);
|
|
574
652
|
return { message: "Workflow run event sent" };
|
|
575
653
|
} catch (error) {
|
|
@@ -577,6 +655,6 @@ async function sendWorkflowRunEventHandler({
|
|
|
577
655
|
}
|
|
578
656
|
}
|
|
579
657
|
|
|
580
|
-
export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
581
|
-
//# sourceMappingURL=chunk-
|
|
582
|
-
//# sourceMappingURL=chunk-
|
|
658
|
+
export { cancelWorkflowRunHandler, createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, observeStreamVNextWorkflowHandler, observeStreamWorkflowHandler, resumeAsyncWorkflowHandler, resumeStreamWorkflowHandler, resumeWorkflowHandler, sendWorkflowRunEventHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamVNextWorkflowHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
|
|
659
|
+
//# sourceMappingURL=chunk-AX5SCBJL.js.map
|
|
660
|
+
//# sourceMappingURL=chunk-AX5SCBJL.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,iCAAA,EAAA,MAAA,iCAAA;AAAA,EAAA,4BAAA,EAAA,MAAA,4BAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAA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AAM,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,IAAA,GAAO,MAAM,QAAA,CAAS,cAAA,CAAe,EAAE,KAAA,EAAO,UAAA,EAAY,GAAA,CAAI,UAAA,EAAY,CAAA;AAEhF,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-AX5SCBJL.js","sourcesContent":["import { ReadableStream, TransformStream } from 'node:stream/web';\nimport type { TracingOptions } from '@mastra/core/ai-tracing';\nimport type { RuntimeContext } from '@mastra/core/di';\nimport type { WorkflowRuns } from '@mastra/core/storage';\nimport type { Workflow, WatchEvent, WorkflowInfo, StreamEvent, ChunkType } 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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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 tracingOptions,\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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n void _run.start({\n inputData,\n runtimeContext,\n tracingOptions,\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, resourceId: run.resourceId });\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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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 tracingOptions,\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, resourceId: run.resourceId });\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 tracingOptions,\n}: Pick<WorkflowContext, 'mastra' | 'workflowId' | 'runId'> & {\n inputData?: unknown;\n runtimeContext?: RuntimeContext;\n closeOnSuspend?: boolean;\n tracingOptions?: TracingOptions;\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 serverCache = mastra.getServerCache();\n\n const run = await workflow.createRunAsync({ runId });\n const result = run.streamVNext({\n inputData,\n runtimeContext,\n closeOnSuspend,\n onChunk: async chunk => {\n if (serverCache) {\n const cacheKey = runId;\n await serverCache.listPush(cacheKey, chunk);\n }\n },\n tracingOptions,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error streaming workflow');\n }\n}\n\nexport async function observeStreamVNextWorkflowHandler({\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, resourceId: run.resourceId });\n const serverCache = mastra.getServerCache();\n if (!serverCache) {\n throw new HTTPException(500, { message: 'Server cache not found' });\n }\n\n // Get cached chunks first\n const cachedRunChunks = await serverCache.listFromTo(runId, 0);\n\n // Create a readable stream that first emits cached chunks, then the live stream\n const combinedStream = new ReadableStream<ChunkType>({\n start(controller) {\n // First, emit all cached chunks\n const emitCachedChunks = async () => {\n for (const chunk of cachedRunChunks) {\n controller.enqueue(chunk as ChunkType);\n }\n };\n\n // Then, pipe the live stream\n const liveStream = _run.observeStreamVNext();\n const reader = liveStream.getReader();\n\n const pump = async () => {\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n break;\n }\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n } finally {\n reader.releaseLock();\n }\n };\n\n // Start with cached chunks, then live stream\n void emitCachedChunks()\n .then(() => {\n void pump();\n })\n .catch(error => {\n controller.error(error);\n });\n },\n });\n\n return combinedStream;\n } catch (error) {\n return handleError(error, 'Error observing workflow stream');\n }\n}\n\nexport async function resumeAsyncWorkflowHandler({\n mastra,\n workflowId,\n runId,\n body,\n runtimeContext,\n tracingOptions,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n const result = await _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n tracingOptions,\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 tracingOptions,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n\n void _run.resume({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n tracingOptions,\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 tracingOptions,\n}: WorkflowContext & {\n body: { step: string | string[]; resumeData?: unknown };\n runtimeContext?: RuntimeContext;\n tracingOptions?: TracingOptions;\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, resourceId: run.resourceId });\n const serverCache = mastra.getServerCache();\n\n const stream = _run.resumeStreamVNext({\n step: body.step,\n resumeData: body.resumeData,\n runtimeContext,\n tracingOptions,\n onChunk: async chunk => {\n if (serverCache) {\n const cacheKey = runId;\n await serverCache.listPush(cacheKey, chunk);\n }\n },\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, resourceId: run.resourceId });\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, resourceId: run.resourceId });\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"]}
|