@mastra/core 0.5.0-alpha.8 → 0.5.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/dist/agent/index.cjs +3 -2100
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/{base-CTdONy0_.d.cts → base-CIPKleAU.d.cts} +103 -70
- package/dist/{base-DIn_km7X.d.ts → base-C_Oq53qk.d.ts} +103 -70
- package/dist/base.cjs +5 -140
- package/dist/bundler/index.cjs +5 -160
- package/dist/chunk-2W2GYEYQ.cjs +25 -0
- package/dist/chunk-3ASEZT7U.cjs +1586 -0
- package/dist/chunk-43Y7WG5W.cjs +335 -0
- package/dist/{chunk-HBHPTMAC.js → chunk-4Y74D74B.js} +46 -6
- package/dist/chunk-ENT7U27Y.cjs +37 -0
- package/dist/chunk-F5UYWPV4.cjs +14 -0
- package/dist/chunk-FL3GQXQ2.cjs +218 -0
- package/dist/chunk-FRQFWZDN.cjs +2 -0
- package/dist/chunk-GXQRMKSN.cjs +367 -0
- package/dist/chunk-HJPMYDWO.cjs +37 -0
- package/dist/chunk-IIWRJFLQ.cjs +51 -0
- package/dist/chunk-KFQ7Z3PO.cjs +347 -0
- package/dist/{chunk-SWDQYPJS.js → chunk-KP5UAFLN.js} +3 -2
- package/dist/chunk-KPKFLQFR.cjs +12 -0
- package/dist/{chunk-RRJB4TCC.js → chunk-MLFXOST6.js} +1 -1
- package/dist/{chunk-KBSR2LLT.js → chunk-OD7ZMKHY.js} +176 -63
- package/dist/chunk-OTFLHXHZ.cjs +65 -0
- package/dist/chunk-RWTSGWWL.cjs +81 -0
- package/dist/chunk-ST5RMVLG.cjs +87 -0
- package/dist/chunk-SYQ7NK2E.cjs +24 -0
- package/dist/chunk-UZNQG7QO.cjs +1868 -0
- package/dist/chunk-V5ORZPFW.cjs +38 -0
- package/dist/chunk-VA4P7QJT.cjs +443 -0
- package/dist/chunk-WB2HREXE.cjs +166 -0
- package/dist/chunk-WOMOGDGR.cjs +691 -0
- package/dist/chunk-XB2TJ7LX.cjs +408 -0
- package/dist/{chunk-QABMKXI3.js → chunk-XF2FMJYK.js} +1 -1
- package/dist/chunk-XLSROQ26.cjs +91 -0
- package/dist/chunk-YK3XJ52U.cjs +192 -0
- package/dist/{chunk-SF5GHHOQ.js → chunk-YPD6BQIM.js} +121 -93
- package/dist/deployer/index.cjs +5 -167
- package/dist/eval/index.cjs +9 -105
- package/dist/eval/index.d.cts +1 -1
- package/dist/eval/index.d.ts +1 -1
- package/dist/hooks/index.cjs +14 -83
- package/dist/index.cjs +253 -7470
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -7
- package/dist/integration/index.cjs +9 -108
- package/dist/integration/index.d.cts +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/logger/index.cjs +33 -161
- package/dist/mastra/index.cjs +3 -1755
- package/dist/mastra/index.d.cts +1 -1
- package/dist/mastra/index.d.ts +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -2050
- package/dist/memory/index.d.cts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/relevance/index.cjs +10 -2161
- package/dist/relevance/index.d.cts +19 -2
- package/dist/relevance/index.d.ts +19 -2
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.cjs +29 -367
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/libsql/index.cjs +9 -798
- package/dist/storage/libsql/index.d.cts +1 -1
- package/dist/storage/libsql/index.d.ts +1 -1
- package/dist/telemetry/index.cjs +21 -408
- package/dist/telemetry/index.d.cts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.cjs +11 -22
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/tts/index.cjs +3 -328
- package/dist/utils.cjs +41 -309
- package/dist/utils.d.cts +10 -4
- package/dist/utils.d.ts +10 -4
- package/dist/utils.js +1 -1
- package/dist/vector/filter/index.cjs +7 -189
- package/dist/vector/index.cjs +5 -172
- package/dist/vector/libsql/index.cjs +9 -1047
- package/dist/voice/index.cjs +8 -306
- package/dist/workflows/index.cjs +65 -1925
- package/dist/workflows/index.d.cts +4 -3
- package/dist/workflows/index.d.ts +4 -3
- package/dist/workflows/index.js +1 -1
- package/package.json +27 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMastraProxy } from './chunk-
|
|
1
|
+
import { createMastraProxy } from './chunk-4Y74D74B.js';
|
|
2
2
|
import { MastraBase } from './chunk-4VHCCQ7P.js';
|
|
3
3
|
import { setTimeout } from 'node:timers/promises';
|
|
4
4
|
import { context, trace } from '@opentelemetry/api';
|
|
@@ -12,6 +12,7 @@ var WhenConditionReturnValue = /* @__PURE__ */ ((WhenConditionReturnValue2) => {
|
|
|
12
12
|
WhenConditionReturnValue2["CONTINUE"] = "continue";
|
|
13
13
|
WhenConditionReturnValue2["CONTINUE_FAILED"] = "continue_failed";
|
|
14
14
|
WhenConditionReturnValue2["ABORT"] = "abort";
|
|
15
|
+
WhenConditionReturnValue2["LIMBO"] = "limbo";
|
|
15
16
|
return WhenConditionReturnValue2;
|
|
16
17
|
})(WhenConditionReturnValue || {});
|
|
17
18
|
|
|
@@ -47,13 +48,16 @@ function getSuspendedPaths({
|
|
|
47
48
|
function isFinalState(status) {
|
|
48
49
|
return ["completed", "failed"].includes(status);
|
|
49
50
|
}
|
|
51
|
+
function isLimboState(status) {
|
|
52
|
+
return status === "limbo";
|
|
53
|
+
}
|
|
50
54
|
function recursivelyCheckForFinalState({
|
|
51
55
|
value,
|
|
52
56
|
suspendedPaths,
|
|
53
57
|
path
|
|
54
58
|
}) {
|
|
55
59
|
if (typeof value === "string") {
|
|
56
|
-
return isFinalState(value) || suspendedPaths.has(path);
|
|
60
|
+
return isFinalState(value) || isLimboState(value) || suspendedPaths.has(path);
|
|
57
61
|
}
|
|
58
62
|
return Object.keys(value).every(
|
|
59
63
|
(key) => recursivelyCheckForFinalState({ value: value[key], suspendedPaths, path: path ? `${path}.${key}` : key })
|
|
@@ -320,6 +324,7 @@ var Machine = class extends EventEmitter {
|
|
|
320
324
|
return {
|
|
321
325
|
resolverFunction: fromPromise(async ({ input }) => {
|
|
322
326
|
const { stepNode, context } = input;
|
|
327
|
+
const attemptCount = context.attempts[stepNode.step.id];
|
|
323
328
|
const resolvedData = this.#resolveVariables({
|
|
324
329
|
stepConfig: stepNode.config,
|
|
325
330
|
context,
|
|
@@ -334,54 +339,65 @@ var Machine = class extends EventEmitter {
|
|
|
334
339
|
if (this.#mastra) {
|
|
335
340
|
mastraProxy = createMastraProxy({ mastra: this.#mastra, logger });
|
|
336
341
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
342
|
+
let result = void 0;
|
|
343
|
+
try {
|
|
344
|
+
result = await stepNode.config.handler({
|
|
345
|
+
context: resolvedData,
|
|
346
|
+
suspend: async (payload) => {
|
|
347
|
+
await this.#workflowInstance.suspend(stepNode.step.id, this);
|
|
348
|
+
if (this.#actor) {
|
|
349
|
+
context.steps[stepNode.step.id] = {
|
|
350
|
+
status: "suspended",
|
|
351
|
+
suspendPayload: payload
|
|
352
|
+
};
|
|
353
|
+
this.logger.debug(`Sending SUSPENDED event for step ${stepNode.step.id}`);
|
|
354
|
+
this.#actor?.send({ type: "SUSPENDED", suspendPayload: payload, stepId: stepNode.step.id });
|
|
355
|
+
} else {
|
|
356
|
+
this.logger.debug(`Actor not available for step ${stepNode.step.id}`);
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
runId: this.#runId,
|
|
360
|
+
mastra: mastraProxy
|
|
361
|
+
});
|
|
362
|
+
} catch (error) {
|
|
363
|
+
this.logger.debug(`Step ${stepNode.step.id} failed`, {
|
|
364
|
+
stepId: stepNode.step.id,
|
|
365
|
+
error,
|
|
366
|
+
runId: this.#runId
|
|
367
|
+
});
|
|
368
|
+
this.logger.debug(`Attempt count for step ${stepNode.step.id}`, {
|
|
369
|
+
attemptCount,
|
|
370
|
+
attempts: context.attempts,
|
|
371
|
+
runId: this.#runId,
|
|
372
|
+
stepId: stepNode.step.id
|
|
373
|
+
});
|
|
374
|
+
if (!attemptCount || attemptCount < 0) {
|
|
375
|
+
return {
|
|
376
|
+
type: "STEP_FAILED",
|
|
377
|
+
error: error instanceof Error ? error.message : `Step:${stepNode.step.id} failed with error: ${error}`,
|
|
378
|
+
stepId: stepNode.step.id
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return { type: "STEP_WAITING", stepId: stepNode.step.id };
|
|
382
|
+
}
|
|
355
383
|
this.logger.debug(`Step ${stepNode.step.id} result`, {
|
|
356
384
|
stepId: stepNode.step.id,
|
|
357
385
|
result,
|
|
358
386
|
runId: this.#runId
|
|
359
387
|
});
|
|
360
388
|
return {
|
|
361
|
-
|
|
362
|
-
result
|
|
389
|
+
type: "STEP_SUCCESS",
|
|
390
|
+
result,
|
|
391
|
+
stepId: stepNode.step.id
|
|
363
392
|
};
|
|
364
393
|
}),
|
|
365
394
|
conditionCheck: fromPromise(async ({ input }) => {
|
|
366
395
|
const { context, stepNode } = input;
|
|
367
396
|
const stepConfig = stepNode.config;
|
|
368
|
-
const attemptCount = context.attempts[stepNode.step.id];
|
|
369
397
|
this.logger.debug(`Checking conditions for step ${stepNode.step.id}`, {
|
|
370
398
|
stepId: stepNode.step.id,
|
|
371
399
|
runId: this.#runId
|
|
372
400
|
});
|
|
373
|
-
this.logger.debug(`Attempt count for step ${stepNode.step.id}`, {
|
|
374
|
-
attemptCount,
|
|
375
|
-
attempts: context.attempts,
|
|
376
|
-
runId: this.#runId,
|
|
377
|
-
stepId: stepNode.step.id
|
|
378
|
-
});
|
|
379
|
-
if (!attemptCount || attemptCount < 0) {
|
|
380
|
-
if (stepConfig?.snapshotOnTimeout) {
|
|
381
|
-
return { type: "SUSPENDED", stepId: stepNode.step.id };
|
|
382
|
-
}
|
|
383
|
-
return { type: "CONDITION_FAILED", error: `Step:${stepNode.step.id} condition check failed` };
|
|
384
|
-
}
|
|
385
401
|
if (!stepConfig?.when) {
|
|
386
402
|
return { type: "CONDITIONS_MET" };
|
|
387
403
|
}
|
|
@@ -394,10 +410,11 @@ var Machine = class extends EventEmitter {
|
|
|
394
410
|
context: {
|
|
395
411
|
...context,
|
|
396
412
|
getStepResult: (stepId) => {
|
|
397
|
-
|
|
413
|
+
const resolvedStepId = typeof stepId === "string" ? stepId : stepId.id;
|
|
414
|
+
if (resolvedStepId === "trigger") {
|
|
398
415
|
return context.triggerData;
|
|
399
416
|
}
|
|
400
|
-
const result = context.steps[
|
|
417
|
+
const result = context.steps[resolvedStepId];
|
|
401
418
|
if (result && result.status === "success") {
|
|
402
419
|
return result.output;
|
|
403
420
|
}
|
|
@@ -410,6 +427,8 @@ var Machine = class extends EventEmitter {
|
|
|
410
427
|
conditionMet = false;
|
|
411
428
|
} else if (conditionMet === "continue_failed" /* CONTINUE_FAILED */) {
|
|
412
429
|
return { type: "CONDITIONS_SKIPPED" };
|
|
430
|
+
} else if (conditionMet === "limbo" /* LIMBO */) {
|
|
431
|
+
return { type: "CONDITIONS_LIMBO" };
|
|
413
432
|
} else if (conditionMet) {
|
|
414
433
|
this.logger.debug(`Condition met for step ${stepNode.step.id}`, {
|
|
415
434
|
stepId: stepNode.step.id,
|
|
@@ -417,10 +436,7 @@ var Machine = class extends EventEmitter {
|
|
|
417
436
|
});
|
|
418
437
|
return { type: "CONDITIONS_MET" };
|
|
419
438
|
}
|
|
420
|
-
|
|
421
|
-
return { type: "CONDITION_FAILED", error: `Step:${stepNode.step.id} condition check failed` };
|
|
422
|
-
}
|
|
423
|
-
return { type: "WAITING", stepId: stepNode.step.id };
|
|
439
|
+
return { type: "CONDITIONS_LIMBO" };
|
|
424
440
|
} else {
|
|
425
441
|
const conditionMet = this.#evaluateCondition(stepConfig.when, context);
|
|
426
442
|
if (!conditionMet) {
|
|
@@ -459,10 +475,11 @@ var Machine = class extends EventEmitter {
|
|
|
459
475
|
const resolvedData = {
|
|
460
476
|
...context,
|
|
461
477
|
getStepResult: (stepId2) => {
|
|
462
|
-
|
|
478
|
+
const resolvedStepId = typeof stepId2 === "string" ? stepId2 : stepId2.id;
|
|
479
|
+
if (resolvedStepId === "trigger") {
|
|
463
480
|
return context.triggerData;
|
|
464
481
|
}
|
|
465
|
-
const result = context.steps[
|
|
482
|
+
const result = context.steps[resolvedStepId];
|
|
466
483
|
if (result && result.status === "success") {
|
|
467
484
|
return result.output;
|
|
468
485
|
}
|
|
@@ -608,6 +625,27 @@ var Machine = class extends EventEmitter {
|
|
|
608
625
|
},
|
|
609
626
|
target: "completed"
|
|
610
627
|
},
|
|
628
|
+
{
|
|
629
|
+
guard: ({ event }) => {
|
|
630
|
+
return event.output.type === "CONDITIONS_LIMBO";
|
|
631
|
+
},
|
|
632
|
+
target: "limbo",
|
|
633
|
+
actions: assign({
|
|
634
|
+
steps: ({ context }) => {
|
|
635
|
+
const newStep = {
|
|
636
|
+
...context.steps,
|
|
637
|
+
[stepNode.step.id]: {
|
|
638
|
+
status: "skipped"
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
this.logger.debug(`Step ${stepNode.step.id} skipped`, {
|
|
642
|
+
stepId: stepNode.step.id,
|
|
643
|
+
runId: this.#runId
|
|
644
|
+
});
|
|
645
|
+
return newStep;
|
|
646
|
+
}
|
|
647
|
+
})
|
|
648
|
+
},
|
|
611
649
|
{
|
|
612
650
|
guard: ({ event }) => {
|
|
613
651
|
return event.output.type === "CONDITION_FAILED";
|
|
@@ -654,6 +692,23 @@ var Machine = class extends EventEmitter {
|
|
|
654
692
|
}
|
|
655
693
|
}
|
|
656
694
|
},
|
|
695
|
+
limbo: {
|
|
696
|
+
// no target, will stay in limbo indefinitely
|
|
697
|
+
entry: () => {
|
|
698
|
+
this.logger.debug(`Step ${stepNode.step.id} limbo`, {
|
|
699
|
+
stepId: stepNode.step.id,
|
|
700
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
701
|
+
runId: this.#runId
|
|
702
|
+
});
|
|
703
|
+
},
|
|
704
|
+
exit: () => {
|
|
705
|
+
this.logger.debug(`Step ${stepNode.step.id} finished limbo`, {
|
|
706
|
+
stepId: stepNode.step.id,
|
|
707
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
708
|
+
runId: this.#runId
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
},
|
|
657
712
|
suspended: {
|
|
658
713
|
type: "final",
|
|
659
714
|
entry: [
|
|
@@ -708,18 +763,68 @@ var Machine = class extends EventEmitter {
|
|
|
708
763
|
context,
|
|
709
764
|
stepNode
|
|
710
765
|
}),
|
|
711
|
-
onDone:
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
766
|
+
onDone: [
|
|
767
|
+
{
|
|
768
|
+
guard: ({ event }) => {
|
|
769
|
+
return event.output.type === "STEP_FAILED";
|
|
770
|
+
},
|
|
771
|
+
target: "failed",
|
|
772
|
+
actions: assign({
|
|
773
|
+
steps: ({ context, event }) => {
|
|
774
|
+
if (event.output.type !== "STEP_FAILED") return context.steps;
|
|
775
|
+
const newStep = {
|
|
776
|
+
...context.steps,
|
|
777
|
+
[stepNode.step.id]: {
|
|
778
|
+
status: "failed",
|
|
779
|
+
error: event.output.error
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
this.logger.debug(`Step ${stepNode.step.id} failed`, {
|
|
783
|
+
error: event.output.error,
|
|
784
|
+
stepId: stepNode.step.id
|
|
785
|
+
});
|
|
786
|
+
return newStep;
|
|
787
|
+
}
|
|
788
|
+
})
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
guard: ({ event }) => {
|
|
792
|
+
return event.output.type === "STEP_SUCCESS";
|
|
793
|
+
},
|
|
794
|
+
actions: [
|
|
795
|
+
({ event }) => {
|
|
796
|
+
this.logger.debug(`Step ${stepNode.step.id} finished executing`, {
|
|
797
|
+
stepId: stepNode.step.id,
|
|
798
|
+
output: event.output,
|
|
799
|
+
runId: this.#runId
|
|
800
|
+
});
|
|
801
|
+
},
|
|
802
|
+
{ type: "updateStepResult", params: { stepId: stepNode.step.id } },
|
|
803
|
+
{ type: "spawnSubscribers", params: { stepId: stepNode.step.id } }
|
|
804
|
+
],
|
|
805
|
+
target: "runningSubscribers"
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
guard: ({ event }) => {
|
|
809
|
+
return event.output.type === "STEP_WAITING";
|
|
810
|
+
},
|
|
811
|
+
target: "waiting",
|
|
812
|
+
actions: [
|
|
813
|
+
{ type: "decrementAttemptCount", params: { stepId: stepNode.step.id } },
|
|
814
|
+
assign({
|
|
815
|
+
steps: ({ context, event }) => {
|
|
816
|
+
if (event.output.type !== "STEP_WAITING") return context.steps;
|
|
817
|
+
return {
|
|
818
|
+
...context.steps,
|
|
819
|
+
[stepNode.step.id]: {
|
|
820
|
+
status: "waiting"
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
})
|
|
825
|
+
]
|
|
826
|
+
}
|
|
827
|
+
],
|
|
723
828
|
onError: {
|
|
724
829
|
target: "failed",
|
|
725
830
|
actions: [{ type: "setStepError", params: { stepId: stepNode.step.id } }]
|
|
@@ -973,7 +1078,8 @@ var WorkflowInstance = class {
|
|
|
973
1078
|
steps: this.#steps,
|
|
974
1079
|
stepGraph,
|
|
975
1080
|
executionSpan: this.#executionSpan,
|
|
976
|
-
startStepId
|
|
1081
|
+
startStepId,
|
|
1082
|
+
retryConfig: this.#retryConfig
|
|
977
1083
|
});
|
|
978
1084
|
this.#machines[startStepId] = defaultMachine;
|
|
979
1085
|
const stateUpdateHandler = (startStepId2, state, context) => {
|
|
@@ -1004,7 +1110,7 @@ var WorkflowInstance = class {
|
|
|
1004
1110
|
const stepStatus = input.steps[parentStepId]?.status;
|
|
1005
1111
|
const subscriberKeys = Object.keys(this.#stepSubscriberGraph).filter((key) => key.split("&&").includes(parentStepId));
|
|
1006
1112
|
subscriberKeys.forEach((key) => {
|
|
1007
|
-
if (["success", "failure"].includes(stepStatus) && this.#isCompoundKey(key)) {
|
|
1113
|
+
if (["success", "failure", "skipped"].includes(stepStatus) && this.#isCompoundKey(key)) {
|
|
1008
1114
|
this.#compoundDependencies[key][parentStepId] = true;
|
|
1009
1115
|
}
|
|
1010
1116
|
});
|
|
@@ -1207,6 +1313,7 @@ var Workflow = class extends MastraBase {
|
|
|
1207
1313
|
telemetry: mastra.getTelemetry(),
|
|
1208
1314
|
logger: mastra.getLogger()
|
|
1209
1315
|
});
|
|
1316
|
+
this.#mastra = mastra;
|
|
1210
1317
|
}
|
|
1211
1318
|
}
|
|
1212
1319
|
step(step, config) {
|
|
@@ -1223,6 +1330,7 @@ var Workflow = class extends MastraBase {
|
|
|
1223
1330
|
config: {
|
|
1224
1331
|
...this.#makeStepDef(stepKey),
|
|
1225
1332
|
...config,
|
|
1333
|
+
serializedWhen: typeof config?.when === "function" ? config.when.toString() : config?.when,
|
|
1226
1334
|
data: requiredData
|
|
1227
1335
|
}
|
|
1228
1336
|
};
|
|
@@ -1259,6 +1367,7 @@ var Workflow = class extends MastraBase {
|
|
|
1259
1367
|
config: {
|
|
1260
1368
|
...this.#makeStepDef(stepKey),
|
|
1261
1369
|
...config,
|
|
1370
|
+
serializedWhen: typeof config?.when === "function" ? config.when.toString() : config?.when,
|
|
1262
1371
|
data: requiredData
|
|
1263
1372
|
}
|
|
1264
1373
|
};
|
|
@@ -1508,10 +1617,14 @@ var Workflow = class extends MastraBase {
|
|
|
1508
1617
|
return await context.with(
|
|
1509
1618
|
trace.setSpan(context.active(), this.getExecutionSpan(attributes?.runId ?? data?.runId)),
|
|
1510
1619
|
async () => {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1620
|
+
if (this?.telemetry) {
|
|
1621
|
+
return this.telemetry.traceMethod(handler2, {
|
|
1622
|
+
spanName,
|
|
1623
|
+
attributes
|
|
1624
|
+
})(data);
|
|
1625
|
+
} else {
|
|
1626
|
+
return handler2(data);
|
|
1627
|
+
}
|
|
1515
1628
|
}
|
|
1516
1629
|
);
|
|
1517
1630
|
};
|
|
@@ -1525,7 +1638,7 @@ var Workflow = class extends MastraBase {
|
|
|
1525
1638
|
...payload,
|
|
1526
1639
|
...context
|
|
1527
1640
|
};
|
|
1528
|
-
const finalAction = this
|
|
1641
|
+
const finalAction = this.telemetry ? executeStep(execute, `workflow.${this.name}.action.${stepId}`, {
|
|
1529
1642
|
componentName: this.name,
|
|
1530
1643
|
runId: rest.runId
|
|
1531
1644
|
}) : execute;
|
|
@@ -1730,4 +1843,4 @@ function createStep(opts) {
|
|
|
1730
1843
|
return new Step(opts);
|
|
1731
1844
|
}
|
|
1732
1845
|
|
|
1733
|
-
export { Step, WhenConditionReturnValue, Workflow, createStep, getActivePathsAndStatus, getResultActivePaths, getStepResult, getSuspendedPaths, isErrorEvent, isFinalState, isTransitionEvent, isVariableReference, mergeChildValue, recursivelyCheckForFinalState, updateStepInHierarchy };
|
|
1846
|
+
export { Step, WhenConditionReturnValue, Workflow, createStep, getActivePathsAndStatus, getResultActivePaths, getStepResult, getSuspendedPaths, isErrorEvent, isFinalState, isLimboState, isTransitionEvent, isVariableReference, mergeChildValue, recursivelyCheckForFinalState, updateStepInHierarchy };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk3ASEZT7U_cjs = require('./chunk-3ASEZT7U.cjs');
|
|
4
|
+
var cohereAi = require('cohere-ai');
|
|
5
|
+
|
|
6
|
+
var CohereRelevanceScorer = class {
|
|
7
|
+
client;
|
|
8
|
+
model;
|
|
9
|
+
constructor(model, apiKey) {
|
|
10
|
+
this.client = new cohereAi.CohereClient({
|
|
11
|
+
token: apiKey || process.env.COHERE_API_KEY || ""
|
|
12
|
+
});
|
|
13
|
+
this.model = model;
|
|
14
|
+
}
|
|
15
|
+
async getRelevanceScore(query, text) {
|
|
16
|
+
const response = await this.client.rerank({
|
|
17
|
+
query,
|
|
18
|
+
documents: [text],
|
|
19
|
+
model: this.model,
|
|
20
|
+
topN: 1
|
|
21
|
+
});
|
|
22
|
+
return response.results[0].relevanceScore;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/relevance/relevance-score-provider.ts
|
|
27
|
+
function createSimilarityPrompt(query, text) {
|
|
28
|
+
return `Rate the semantic similarity between the following the query and the text on a scale from 0 to 1 (decimals allowed), where 1 means exactly the same meaning and 0 means completely different:
|
|
29
|
+
|
|
30
|
+
Query: ${query}
|
|
31
|
+
|
|
32
|
+
Text: ${text}
|
|
33
|
+
|
|
34
|
+
Relevance score (0-1):`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/relevance/mastra-agent/index.ts
|
|
38
|
+
var MastraAgentRelevanceScorer = class {
|
|
39
|
+
agent;
|
|
40
|
+
constructor(name, model) {
|
|
41
|
+
this.agent = new chunk3ASEZT7U_cjs.Agent({
|
|
42
|
+
name: `Relevance Scorer ${name}`,
|
|
43
|
+
instructions: `You are a specialized agent for evaluating the relevance of text to queries.
|
|
44
|
+
Your task is to rate how well a text passage answers a given query.
|
|
45
|
+
Output only a number between 0 and 1, where:
|
|
46
|
+
1.0 = Perfectly relevant, directly answers the query
|
|
47
|
+
0.0 = Completely irrelevant
|
|
48
|
+
Consider:
|
|
49
|
+
- Direct relevance to the question
|
|
50
|
+
- Completeness of information
|
|
51
|
+
- Quality and specificity
|
|
52
|
+
Always return just the number, no explanation.`,
|
|
53
|
+
model
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async getRelevanceScore(query, text) {
|
|
57
|
+
const prompt = createSimilarityPrompt(query, text);
|
|
58
|
+
const response = await this.agent.generate(prompt);
|
|
59
|
+
return parseFloat(response.text);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.CohereRelevanceScorer = CohereRelevanceScorer;
|
|
64
|
+
exports.MastraAgentRelevanceScorer = MastraAgentRelevanceScorer;
|
|
65
|
+
exports.createSimilarityPrompt = createSimilarityPrompt;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
7
|
+
var __typeError = msg => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value
|
|
15
|
+
}) : obj[key] = value;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
17
|
+
value,
|
|
18
|
+
configurable: true
|
|
19
|
+
});
|
|
20
|
+
var __decoratorStart = base => [,,, __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
21
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
22
|
+
var __expectFn = fn => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
23
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({
|
|
24
|
+
kind: __decoratorStrings[kind],
|
|
25
|
+
name,
|
|
26
|
+
metadata,
|
|
27
|
+
addInitializer: fn => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null))
|
|
28
|
+
});
|
|
29
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
30
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
31
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
35
|
+
var fn,
|
|
36
|
+
it,
|
|
37
|
+
done,
|
|
38
|
+
ctx,
|
|
39
|
+
access,
|
|
40
|
+
k = flags & 7,
|
|
41
|
+
s = !!(flags & 8),
|
|
42
|
+
p = !!(flags & 16);
|
|
43
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0,
|
|
44
|
+
key = __decoratorStrings[k + 5];
|
|
45
|
+
var initializers = k > 3 && (array[j - 1] = []),
|
|
46
|
+
extraInitializers = array[j] || (array[j] = []);
|
|
47
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : {
|
|
48
|
+
get [name]() {
|
|
49
|
+
return __privateGet(this, extra);
|
|
50
|
+
},
|
|
51
|
+
set [name](x) {
|
|
52
|
+
return __privateSet(this, extra, x);
|
|
53
|
+
}
|
|
54
|
+
}, name));
|
|
55
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
56
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
57
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
58
|
+
if (k) {
|
|
59
|
+
ctx.static = s, ctx.private = p, access = ctx.access = {
|
|
60
|
+
has: p ? x => __privateIn(target, x) : x => name in x
|
|
61
|
+
};
|
|
62
|
+
if (k ^ 3) access.get = p ? x => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : x => x[name];
|
|
63
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
64
|
+
}
|
|
65
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : {
|
|
66
|
+
get: desc.get,
|
|
67
|
+
set: desc.set
|
|
68
|
+
} : target, ctx), done._ = 1;
|
|
69
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);else if (typeof it !== "object" || it === null) __typeError("Object expected");else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
70
|
+
}
|
|
71
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
72
|
+
};
|
|
73
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
74
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
75
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
76
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
77
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
78
|
+
|
|
79
|
+
exports.__decorateElement = __decorateElement;
|
|
80
|
+
exports.__decoratorStart = __decoratorStart;
|
|
81
|
+
exports.__runInitializers = __runInitializers;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/hooks/mitt.ts
|
|
4
|
+
function mitt(all) {
|
|
5
|
+
all = all || /* @__PURE__ */ new Map();
|
|
6
|
+
return {
|
|
7
|
+
/**
|
|
8
|
+
* A Map of event names to registered handler functions.
|
|
9
|
+
*/
|
|
10
|
+
all,
|
|
11
|
+
/**
|
|
12
|
+
* Register an event handler for the given type.
|
|
13
|
+
* @param {string|symbol} type Type of event to listen for, or `'*'` for all events
|
|
14
|
+
* @param {Function} handler Function to call in response to given event
|
|
15
|
+
* @memberOf mitt
|
|
16
|
+
*/
|
|
17
|
+
on(type, handler) {
|
|
18
|
+
const handlers = all.get(type);
|
|
19
|
+
if (handlers) {
|
|
20
|
+
handlers.push(handler);
|
|
21
|
+
} else {
|
|
22
|
+
all.set(type, [handler]);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Remove an event handler for the given type.
|
|
27
|
+
* If `handler` is omitted, all handlers of the given type are removed.
|
|
28
|
+
* @param {string|symbol} type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)
|
|
29
|
+
* @param {Function} [handler] Handler function to remove
|
|
30
|
+
* @memberOf mitt
|
|
31
|
+
*/
|
|
32
|
+
off(type, handler) {
|
|
33
|
+
const handlers = all.get(type);
|
|
34
|
+
if (handlers) {
|
|
35
|
+
if (handler) {
|
|
36
|
+
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
|
|
37
|
+
} else {
|
|
38
|
+
all.set(type, []);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Invoke all handlers for the given type.
|
|
44
|
+
* If present, `'*'` handlers are invoked after type-matched handlers.
|
|
45
|
+
*
|
|
46
|
+
* Note: Manually firing '*' handlers is not supported.
|
|
47
|
+
*
|
|
48
|
+
* @param {string|symbol} type The event type to invoke
|
|
49
|
+
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
|
|
50
|
+
* @memberOf mitt
|
|
51
|
+
*/
|
|
52
|
+
emit(type, evt) {
|
|
53
|
+
let handlers = all.get(type);
|
|
54
|
+
if (handlers) {
|
|
55
|
+
handlers.slice().map((handler) => {
|
|
56
|
+
handler(evt);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
handlers = all.get("*");
|
|
60
|
+
if (handlers) {
|
|
61
|
+
handlers.slice().map((handler) => {
|
|
62
|
+
handler(type, evt);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/hooks/index.ts
|
|
70
|
+
var AvailableHooks = /* @__PURE__ */ ((AvailableHooks2) => {
|
|
71
|
+
AvailableHooks2["ON_EVALUATION"] = "onEvaluation";
|
|
72
|
+
AvailableHooks2["ON_GENERATION"] = "onGeneration";
|
|
73
|
+
return AvailableHooks2;
|
|
74
|
+
})(AvailableHooks || {});
|
|
75
|
+
var hooks = mitt();
|
|
76
|
+
function registerHook(hook, action) {
|
|
77
|
+
hooks.on(hook, action);
|
|
78
|
+
}
|
|
79
|
+
function executeHook(hook, data) {
|
|
80
|
+
setImmediate(() => {
|
|
81
|
+
hooks.emit(hook, data);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.AvailableHooks = AvailableHooks;
|
|
86
|
+
exports.executeHook = executeHook;
|
|
87
|
+
exports.registerHook = registerHook;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkIIWRJFLQ_cjs = require('./chunk-IIWRJFLQ.cjs');
|
|
4
|
+
var promises = require('fs/promises');
|
|
5
|
+
var dotenv = require('dotenv');
|
|
6
|
+
|
|
7
|
+
var MastraBundler = class extends chunkIIWRJFLQ_cjs.MastraBase {
|
|
8
|
+
constructor({ name, component = "BUNDLER" }) {
|
|
9
|
+
super({ component, name });
|
|
10
|
+
}
|
|
11
|
+
async loadEnvVars() {
|
|
12
|
+
const envVars = /* @__PURE__ */ new Map();
|
|
13
|
+
for (const file of await this.getEnvFiles()) {
|
|
14
|
+
const content = await promises.readFile(file, "utf-8");
|
|
15
|
+
const config = dotenv.parse(content);
|
|
16
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
17
|
+
envVars.set(key, value);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return envVars;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.MastraBundler = MastraBundler;
|