@mastra/core 0.2.0-alpha.95 → 0.2.0-alpha.98
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.d.ts +2 -2
- package/dist/agent/index.js +2 -2
- package/dist/chunk-C55JWGDU.js +76 -0
- package/dist/{chunk-G4LP2IJU.js → chunk-HPXWJBQK.js} +23 -2
- package/dist/{chunk-QLN26TPI.js → chunk-JP37ODNX.js} +3 -2
- package/dist/{chunk-E3TBVBIO.js → chunk-MDM2JS2U.js} +54 -58
- package/dist/{chunk-N44BCOWP.js → chunk-MG3WAQV7.js} +1 -1
- package/dist/{chunk-JY322VLW.js → chunk-QXH6EK72.js} +21 -7
- package/dist/{chunk-EULBQ77C.js → chunk-Z7JFMQZZ.js} +44 -1
- package/dist/{chunk-5DZIXJRV.js → chunk-ZJOMHCWE.js} +16 -2
- package/dist/eval/index.d.ts +4 -3
- package/dist/eval/index.js +1 -1
- package/dist/hooks/index.d.ts +6 -1
- package/dist/{index-CBxGSZZE.d.ts → index-Cwb-5AzX.d.ts} +20 -12
- package/dist/index.d.ts +7 -7
- package/dist/index.js +13 -12
- package/dist/integration/index.d.ts +3 -3
- package/dist/llm/index.d.ts +2 -2
- package/dist/mastra/index.d.ts +3 -3
- package/dist/memory/index.d.ts +2 -2
- package/dist/memory/index.js +5 -1
- package/dist/{metric-D2V4CR8D.d.ts → metric-BWeQNZt6.d.ts} +1 -1
- package/dist/relevance/index.js +3 -3
- package/dist/storage/index.d.ts +6 -4
- package/dist/storage/index.js +4 -4
- package/dist/tools/index.d.ts +3 -3
- package/dist/vector/index.d.ts +4 -1
- package/dist/vector/index.js +1 -1
- package/dist/vector/libsql/index.d.ts +2 -0
- package/dist/vector/libsql/index.js +3 -3
- package/dist/{workflow-BA2Pnq90.d.ts → workflow-DTtv7_Eq.d.ts} +1 -1
- package/dist/workflows/index.d.ts +4 -4
- package/dist/workflows/index.js +1 -1
- package/package.json +7 -3
- package/dist/action/index.d.ts +0 -16
- package/dist/action/index.js +0 -1
- package/dist/chunk-MBOUQZQT.js +0 -16
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent } from '../index-
|
|
4
|
+
export { A as Agent } from '../index-Cwb-5AzX.js';
|
|
5
5
|
import '../base.js';
|
|
6
|
-
import '../metric-
|
|
6
|
+
import '../metric-BWeQNZt6.js';
|
|
7
7
|
import '../telemetry-oCUM52DG.js';
|
|
8
8
|
import 'sift';
|
|
9
9
|
import '../index-CBZ2mk2H.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { Agent } from '../chunk-
|
|
1
|
+
export { Agent } from '../chunk-QXH6EK72.js';
|
|
2
2
|
import '../chunk-4ZUSEHLH.js';
|
|
3
3
|
import '../chunk-KNPBNSJ7.js';
|
|
4
|
-
import '../chunk-HBTQNIAX.js';
|
|
5
4
|
import '../chunk-G4MCO7XF.js';
|
|
6
5
|
import '../chunk-ICMEXHKD.js';
|
|
6
|
+
import '../chunk-HBTQNIAX.js';
|
|
7
7
|
import '../chunk-AJJZUHB4.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { MastraBase } from './chunk-G4MCO7XF.js';
|
|
2
|
+
import { __name } from './chunk-AJJZUHB4.js';
|
|
3
|
+
import { experimental_customProvider } from 'ai';
|
|
4
|
+
import node_modulesPath from 'node_modules-path';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
var cachedPath = false;
|
|
8
|
+
function getModelCachePath() {
|
|
9
|
+
if (cachedPath) return cachedPath;
|
|
10
|
+
const firstNodeModules = node_modulesPath().split("node_modules")[0];
|
|
11
|
+
cachedPath = path.join(firstNodeModules, "node_modules", ".fastembed-model-cache");
|
|
12
|
+
return cachedPath;
|
|
13
|
+
}
|
|
14
|
+
__name(getModelCachePath, "getModelCachePath");
|
|
15
|
+
var fastEmbedImportPath = "fastembed?" + Date.now();
|
|
16
|
+
async function generateEmbeddings(values, modelType) {
|
|
17
|
+
try {
|
|
18
|
+
const { EmbeddingModel, FlagEmbedding } = await import(fastEmbedImportPath);
|
|
19
|
+
const model = await FlagEmbedding.init({
|
|
20
|
+
model: EmbeddingModel[modelType],
|
|
21
|
+
cacheDir: getModelCachePath()
|
|
22
|
+
});
|
|
23
|
+
const embeddings = await model.embed(values);
|
|
24
|
+
const allResults = [];
|
|
25
|
+
for await (const result of embeddings) {
|
|
26
|
+
allResults.push(...result.map((embedding) => Array.from(embedding)));
|
|
27
|
+
}
|
|
28
|
+
if (allResults.length === 0) throw new Error("No embeddings generated");
|
|
29
|
+
return {
|
|
30
|
+
embeddings: allResults
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error("Error generating embeddings:", error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
__name(generateEmbeddings, "generateEmbeddings");
|
|
38
|
+
var fastEmbedProvider = experimental_customProvider({
|
|
39
|
+
textEmbeddingModels: {
|
|
40
|
+
"bge-small-en-v1.5": {
|
|
41
|
+
specificationVersion: "v1",
|
|
42
|
+
provider: "fastembed",
|
|
43
|
+
modelId: "bge-small-en-v1.5",
|
|
44
|
+
maxEmbeddingsPerCall: 256,
|
|
45
|
+
supportsParallelCalls: true,
|
|
46
|
+
async doEmbed({ values }) {
|
|
47
|
+
return generateEmbeddings(values, "BGESmallENV15");
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"bge-base-en-v1.5": {
|
|
51
|
+
specificationVersion: "v1",
|
|
52
|
+
provider: "fastembed",
|
|
53
|
+
modelId: "bge-base-en-v1.5",
|
|
54
|
+
maxEmbeddingsPerCall: 256,
|
|
55
|
+
supportsParallelCalls: true,
|
|
56
|
+
async doEmbed({ values }) {
|
|
57
|
+
return generateEmbeddings(values, "BGEBaseENV15");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
var localEmbedder = fastEmbedProvider.textEmbeddingModel;
|
|
63
|
+
|
|
64
|
+
// src/vector/index.ts
|
|
65
|
+
var _MastraVector = class _MastraVector extends MastraBase {
|
|
66
|
+
constructor() {
|
|
67
|
+
super({
|
|
68
|
+
name: "MastraVector",
|
|
69
|
+
component: "VECTOR"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
__name(_MastraVector, "MastraVector");
|
|
74
|
+
var MastraVector = _MastraVector;
|
|
75
|
+
|
|
76
|
+
export { MastraVector, localEmbedder };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DefaultStorage } from './chunk-Z7JFMQZZ.js';
|
|
1
2
|
import { deepMerge } from './chunk-KNPBNSJ7.js';
|
|
2
3
|
import { MastraBase } from './chunk-G4MCO7XF.js';
|
|
3
4
|
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
@@ -17,7 +18,11 @@ var _MastraMemory = class _MastraMemory extends MastraBase {
|
|
|
17
18
|
lastMessages: 40,
|
|
18
19
|
semanticRecall: false
|
|
19
20
|
});
|
|
20
|
-
this.storage = config.storage
|
|
21
|
+
this.storage = config.storage || new DefaultStorage({
|
|
22
|
+
config: {
|
|
23
|
+
url: "file:memory.db"
|
|
24
|
+
}
|
|
25
|
+
});
|
|
21
26
|
if (config.vector) {
|
|
22
27
|
this.vector = config.vector;
|
|
23
28
|
this.threadConfig.semanticRecall = true;
|
|
@@ -37,6 +42,23 @@ var _MastraMemory = class _MastraMemory extends MastraBase {
|
|
|
37
42
|
async getSystemMessage(_input) {
|
|
38
43
|
return null;
|
|
39
44
|
}
|
|
45
|
+
async createEmbeddingIndex() {
|
|
46
|
+
if (!this.vector) {
|
|
47
|
+
throw new Error(`Cannot call MastraMemory.createEmbeddingIndex() without a vector db attached.`);
|
|
48
|
+
}
|
|
49
|
+
const defaultDimensions = 1536;
|
|
50
|
+
const dimensionsByModelId = {
|
|
51
|
+
"bge-small-en-v1.5": 384,
|
|
52
|
+
"bge-base-en-v1.5": 768
|
|
53
|
+
};
|
|
54
|
+
const dimensions = dimensionsByModelId[this.getEmbedder().modelId] || defaultDimensions;
|
|
55
|
+
const isDefault = dimensions === defaultDimensions;
|
|
56
|
+
const indexName = isDefault ? "memory_messages" : `memory_messages_${dimensions}`;
|
|
57
|
+
await this.vector.createIndex(indexName, dimensions);
|
|
58
|
+
return {
|
|
59
|
+
indexName
|
|
60
|
+
};
|
|
61
|
+
}
|
|
40
62
|
getEmbedder() {
|
|
41
63
|
if (!this.embedder) {
|
|
42
64
|
throw new Error(`Cannot use vector features without setting new Memory({ embedder: embedderInstance })
|
|
@@ -44,7 +66,6 @@ var _MastraMemory = class _MastraMemory extends MastraBase {
|
|
|
44
66
|
For example:
|
|
45
67
|
|
|
46
68
|
new Memory({
|
|
47
|
-
storage,
|
|
48
69
|
vector,
|
|
49
70
|
embedder: openai("text-embedding-3-small") // example
|
|
50
71
|
});
|
|
@@ -8,7 +8,7 @@ __name(_Metric, "Metric");
|
|
|
8
8
|
var Metric = _Metric;
|
|
9
9
|
|
|
10
10
|
// src/eval/evaluation.ts
|
|
11
|
-
async function evaluate({ agentName, input, metric, output, runId, globalRunId, testInfo }) {
|
|
11
|
+
async function evaluate({ agentName, input, metric, output, runId, globalRunId, testInfo, instructions }) {
|
|
12
12
|
const runIdToUse = runId || crypto.randomUUID();
|
|
13
13
|
const metricResult = await metric.measure(input.toString(), output);
|
|
14
14
|
const traceObject = {
|
|
@@ -24,7 +24,8 @@ async function evaluate({ agentName, input, metric, output, runId, globalRunId,
|
|
|
24
24
|
runId: runIdToUse,
|
|
25
25
|
agentName,
|
|
26
26
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27
|
-
metricName: metric.constructor.name
|
|
27
|
+
metricName: metric.constructor.name,
|
|
28
|
+
instructions
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
executeHook(AvailableHooks.ON_EVALUATION, traceObject);
|
|
@@ -18,7 +18,7 @@ function isVariableReference(value) {
|
|
|
18
18
|
}
|
|
19
19
|
__name(isVariableReference, "isVariableReference");
|
|
20
20
|
function getStepResult(result) {
|
|
21
|
-
if (result?.status === "success") return result.
|
|
21
|
+
if (result?.status === "success") return result.output;
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
24
|
__name(getStepResult, "getStepResult");
|
|
@@ -184,8 +184,8 @@ var _Workflow = class _Workflow extends MastraBase {
|
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
const machineInput = snapshot ? snapshot.context : {
|
|
187
|
-
// Maintain the original step results and their
|
|
188
|
-
|
|
187
|
+
// Maintain the original step results and their output
|
|
188
|
+
steps: {},
|
|
189
189
|
triggerData: triggerData || {},
|
|
190
190
|
attempts: Object.keys(__privateGet(this, _steps)).reduce((acc, stepKey) => {
|
|
191
191
|
acc[stepKey] = __privateGet(this, _steps)[stepKey]?.retryConfig?.attempts || __privateGet(this, _retryConfig)?.attempts || 3;
|
|
@@ -256,7 +256,7 @@ var _Workflow = class _Workflow extends MastraBase {
|
|
|
256
256
|
__privateMethod(this, _Workflow_instances, cleanup_fn).call(this);
|
|
257
257
|
resolve({
|
|
258
258
|
triggerData,
|
|
259
|
-
results: state.context.
|
|
259
|
+
results: state.context.steps,
|
|
260
260
|
runId: __privateGet(this, _runId)
|
|
261
261
|
});
|
|
262
262
|
} catch (error) {
|
|
@@ -266,7 +266,7 @@ var _Workflow = class _Workflow extends MastraBase {
|
|
|
266
266
|
__privateMethod(this, _Workflow_instances, cleanup_fn).call(this);
|
|
267
267
|
resolve({
|
|
268
268
|
triggerData,
|
|
269
|
-
results: state.context.
|
|
269
|
+
results: state.context.steps,
|
|
270
270
|
runId: __privateGet(this, _runId)
|
|
271
271
|
});
|
|
272
272
|
}
|
|
@@ -355,7 +355,7 @@ var _Workflow = class _Workflow extends MastraBase {
|
|
|
355
355
|
}
|
|
356
356
|
let parsedSnapshot;
|
|
357
357
|
try {
|
|
358
|
-
parsedSnapshot = JSON.parse(snapshot);
|
|
358
|
+
parsedSnapshot = typeof snapshot === "string" ? JSON.parse(snapshot) : snapshot;
|
|
359
359
|
} catch (error) {
|
|
360
360
|
this.logger.debug("Failed to parse workflow snapshot for resume", {
|
|
361
361
|
error,
|
|
@@ -364,10 +364,10 @@ var _Workflow = class _Workflow extends MastraBase {
|
|
|
364
364
|
throw new Error("Failed to parse workflow snapshot");
|
|
365
365
|
}
|
|
366
366
|
if (resumeContext) {
|
|
367
|
-
parsedSnapshot.context.
|
|
367
|
+
parsedSnapshot.context.steps[stepId] = {
|
|
368
368
|
status: "success",
|
|
369
|
-
|
|
370
|
-
...parsedSnapshot?.context?.
|
|
369
|
+
output: {
|
|
370
|
+
...parsedSnapshot?.context?.steps?.[stepId]?.output || {},
|
|
371
371
|
...resumeContext
|
|
372
372
|
}
|
|
373
373
|
};
|
|
@@ -506,16 +506,16 @@ buildBaseState_fn = /* @__PURE__ */ __name(function(stepNode, nextSteps = []) {
|
|
|
506
506
|
target: "suspended",
|
|
507
507
|
actions: [
|
|
508
508
|
assign({
|
|
509
|
-
|
|
510
|
-
if (event.output.type !== "SUSPENDED") return context.
|
|
509
|
+
steps: /* @__PURE__ */ __name(({ context, event }) => {
|
|
510
|
+
if (event.output.type !== "SUSPENDED") return context.steps;
|
|
511
511
|
return {
|
|
512
|
-
...context.
|
|
512
|
+
...context.steps,
|
|
513
513
|
[stepNode.step.id]: {
|
|
514
514
|
status: "suspended",
|
|
515
|
-
...context.
|
|
515
|
+
...context.steps?.[stepNode.step.id] || {}
|
|
516
516
|
}
|
|
517
517
|
};
|
|
518
|
-
}, "
|
|
518
|
+
}, "steps"),
|
|
519
519
|
attempts: /* @__PURE__ */ __name(({ context, event }) => {
|
|
520
520
|
if (event.output.type !== "SUSPENDED") return context.attempts;
|
|
521
521
|
return {
|
|
@@ -539,15 +539,15 @@ buildBaseState_fn = /* @__PURE__ */ __name(function(stepNode, nextSteps = []) {
|
|
|
539
539
|
}
|
|
540
540
|
},
|
|
541
541
|
assign({
|
|
542
|
-
|
|
543
|
-
if (event.output.type !== "WAITING") return context.
|
|
542
|
+
steps: /* @__PURE__ */ __name(({ context, event }) => {
|
|
543
|
+
if (event.output.type !== "WAITING") return context.steps;
|
|
544
544
|
return {
|
|
545
|
-
...context.
|
|
545
|
+
...context.steps,
|
|
546
546
|
[stepNode.step.id]: {
|
|
547
547
|
status: "waiting"
|
|
548
548
|
}
|
|
549
549
|
};
|
|
550
|
-
}, "
|
|
550
|
+
}, "steps")
|
|
551
551
|
})
|
|
552
552
|
]
|
|
553
553
|
},
|
|
@@ -563,20 +563,20 @@ buildBaseState_fn = /* @__PURE__ */ __name(function(stepNode, nextSteps = []) {
|
|
|
563
563
|
}, "guard"),
|
|
564
564
|
target: "failed",
|
|
565
565
|
actions: assign({
|
|
566
|
-
|
|
567
|
-
if (event.output.type !== "CONDITION_FAILED") return context.
|
|
566
|
+
steps: /* @__PURE__ */ __name(({ context, event }) => {
|
|
567
|
+
if (event.output.type !== "CONDITION_FAILED") return context.steps;
|
|
568
568
|
this.logger.debug(`workflow condition check failed`, {
|
|
569
569
|
error: event.output.error,
|
|
570
570
|
stepId: stepNode.step.id
|
|
571
571
|
});
|
|
572
572
|
return {
|
|
573
|
-
...context.
|
|
573
|
+
...context.steps,
|
|
574
574
|
[stepNode.step.id]: {
|
|
575
575
|
status: "failed",
|
|
576
576
|
error: event.output.error
|
|
577
577
|
}
|
|
578
578
|
};
|
|
579
|
-
}, "
|
|
579
|
+
}, "steps")
|
|
580
580
|
})
|
|
581
581
|
}
|
|
582
582
|
]
|
|
@@ -602,13 +602,13 @@ buildBaseState_fn = /* @__PURE__ */ __name(function(stepNode, nextSteps = []) {
|
|
|
602
602
|
this.logger.debug(`Step ${stepNode.step.id} suspended`);
|
|
603
603
|
},
|
|
604
604
|
assign({
|
|
605
|
-
|
|
606
|
-
...context.
|
|
605
|
+
steps: /* @__PURE__ */ __name(({ context }) => ({
|
|
606
|
+
...context.steps,
|
|
607
607
|
[stepNode.step.id]: {
|
|
608
|
-
...context?.
|
|
608
|
+
...context?.steps?.[stepNode.step.id] || {},
|
|
609
609
|
status: "suspended"
|
|
610
610
|
}
|
|
611
|
-
}), "
|
|
611
|
+
}), "steps")
|
|
612
612
|
})
|
|
613
613
|
]
|
|
614
614
|
},
|
|
@@ -621,12 +621,12 @@ buildBaseState_fn = /* @__PURE__ */ __name(function(stepNode, nextSteps = []) {
|
|
|
621
621
|
target: "suspended",
|
|
622
622
|
actions: [
|
|
623
623
|
assign({
|
|
624
|
-
|
|
625
|
-
...context.
|
|
624
|
+
steps: /* @__PURE__ */ __name(({ context }) => ({
|
|
625
|
+
...context.steps,
|
|
626
626
|
[stepNode.step.id]: {
|
|
627
627
|
status: "suspended"
|
|
628
628
|
}
|
|
629
|
-
}), "
|
|
629
|
+
}), "steps")
|
|
630
630
|
})
|
|
631
631
|
]
|
|
632
632
|
}
|
|
@@ -687,10 +687,10 @@ buildBaseState_fn = /* @__PURE__ */ __name(function(stepNode, nextSteps = []) {
|
|
|
687
687
|
target: nextStep ? nextStep.step.id : "completed",
|
|
688
688
|
actions: [
|
|
689
689
|
assign({
|
|
690
|
-
|
|
691
|
-
...context.
|
|
692
|
-
...event.output.
|
|
693
|
-
}), "
|
|
690
|
+
steps: /* @__PURE__ */ __name(({ context, event }) => ({
|
|
691
|
+
...context.steps,
|
|
692
|
+
...event.output.steps
|
|
693
|
+
}), "steps")
|
|
694
694
|
}),
|
|
695
695
|
() => this.logger.debug(`Subscriber execution completed`, {
|
|
696
696
|
stepId: stepNode.step.id
|
|
@@ -779,31 +779,31 @@ buildStateHierarchy_fn = /* @__PURE__ */ __name(function(stepGraph) {
|
|
|
779
779
|
getDefaultActions_fn = /* @__PURE__ */ __name(function() {
|
|
780
780
|
return {
|
|
781
781
|
updateStepResult: assign({
|
|
782
|
-
|
|
783
|
-
if (!isTransitionEvent(event)) return context.
|
|
782
|
+
steps: /* @__PURE__ */ __name(({ context, event }) => {
|
|
783
|
+
if (!isTransitionEvent(event)) return context.steps;
|
|
784
784
|
const { stepId, result } = event.output;
|
|
785
785
|
return {
|
|
786
|
-
...context.
|
|
786
|
+
...context.steps,
|
|
787
787
|
[stepId]: {
|
|
788
788
|
status: "success",
|
|
789
|
-
|
|
789
|
+
output: result
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
|
-
}, "
|
|
792
|
+
}, "steps")
|
|
793
793
|
}),
|
|
794
794
|
setStepError: assign({
|
|
795
|
-
|
|
796
|
-
if (!isErrorEvent(event)) return context.
|
|
795
|
+
steps: /* @__PURE__ */ __name(({ context, event }, params) => {
|
|
796
|
+
if (!isErrorEvent(event)) return context.steps;
|
|
797
797
|
const { stepId } = params;
|
|
798
|
-
if (!stepId) return context.
|
|
798
|
+
if (!stepId) return context.steps;
|
|
799
799
|
return {
|
|
800
|
-
...context.
|
|
800
|
+
...context.steps,
|
|
801
801
|
[stepId]: {
|
|
802
802
|
status: "failed",
|
|
803
803
|
error: event.error.message
|
|
804
804
|
}
|
|
805
805
|
};
|
|
806
|
-
}, "
|
|
806
|
+
}, "steps")
|
|
807
807
|
}),
|
|
808
808
|
notifyStepCompletion: /* @__PURE__ */ __name(async (_, params) => {
|
|
809
809
|
const { stepId } = params;
|
|
@@ -858,13 +858,10 @@ getDefaultActors_fn = /* @__PURE__ */ __name(function() {
|
|
|
858
858
|
runId: __privateGet(this, _runId)
|
|
859
859
|
});
|
|
860
860
|
const result = await stepNode.config.handler({
|
|
861
|
-
context:
|
|
862
|
-
machineContext: context,
|
|
863
|
-
...resolvedData
|
|
864
|
-
},
|
|
861
|
+
context: resolvedData,
|
|
865
862
|
suspend: /* @__PURE__ */ __name(async () => {
|
|
866
863
|
if (__privateGet(this, _actor)) {
|
|
867
|
-
context.
|
|
864
|
+
context.steps[stepNode.step.id] = {
|
|
868
865
|
status: "suspended"
|
|
869
866
|
};
|
|
870
867
|
await __privateMethod(this, _Workflow_instances, persistWorkflowSnapshot_fn).call(this);
|
|
@@ -958,7 +955,7 @@ getDefaultActors_fn = /* @__PURE__ */ __name(function() {
|
|
|
958
955
|
const stepGraph = __privateGet(this, _stepSubscriberGraph)[parentStepId];
|
|
959
956
|
if (!stepGraph) {
|
|
960
957
|
return {
|
|
961
|
-
|
|
958
|
+
steps: {}
|
|
962
959
|
};
|
|
963
960
|
}
|
|
964
961
|
const subscriberMachine = setup({
|
|
@@ -993,7 +990,7 @@ getDefaultActors_fn = /* @__PURE__ */ __name(function() {
|
|
|
993
990
|
if (allStatesComplete) {
|
|
994
991
|
actor.stop();
|
|
995
992
|
resolve({
|
|
996
|
-
|
|
993
|
+
steps: state.context.steps
|
|
997
994
|
});
|
|
998
995
|
}
|
|
999
996
|
});
|
|
@@ -1043,25 +1040,24 @@ loadWorkflowSnapshot_fn = /* @__PURE__ */ __name(async function(runId) {
|
|
|
1043
1040
|
* @returns Object containing resolved variable values
|
|
1044
1041
|
*/
|
|
1045
1042
|
resolveVariables_fn = /* @__PURE__ */ __name(function({ stepConfig, context, stepId }) {
|
|
1046
|
-
const resolvedData = {};
|
|
1047
1043
|
this.logger.debug(`Resolving variables for ${stepId}`, {
|
|
1048
1044
|
runId: __privateGet(this, _runId)
|
|
1049
1045
|
});
|
|
1050
|
-
resolvedData
|
|
1046
|
+
const resolvedData = {
|
|
1051
1047
|
...context,
|
|
1052
1048
|
getStepPayload: /* @__PURE__ */ __name((stepId2) => {
|
|
1053
1049
|
if (stepId2 === "trigger") {
|
|
1054
1050
|
return context.triggerData;
|
|
1055
1051
|
}
|
|
1056
|
-
const result = context.
|
|
1052
|
+
const result = context.steps[stepId2];
|
|
1057
1053
|
if (result && result.status === "success") {
|
|
1058
|
-
return result.
|
|
1054
|
+
return result.output;
|
|
1059
1055
|
}
|
|
1060
1056
|
return undefined;
|
|
1061
1057
|
}, "getStepPayload")
|
|
1062
1058
|
};
|
|
1063
1059
|
for (const [key, variable] of Object.entries(stepConfig.data)) {
|
|
1064
|
-
const sourceData = variable.step === "trigger" ? context.triggerData : getStepResult(context.
|
|
1060
|
+
const sourceData = variable.step === "trigger" ? context.triggerData : getStepResult(context.steps[variable.step.id]);
|
|
1065
1061
|
this.logger.debug(`Got source data for ${key} variable from ${variable.step === "trigger" ? "trigger" : variable.step.id}`, {
|
|
1066
1062
|
sourceData,
|
|
1067
1063
|
path: variable.path,
|
|
@@ -1092,7 +1088,7 @@ evaluateCondition_fn = /* @__PURE__ */ __name(function(condition, context) {
|
|
|
1092
1088
|
const [key, queryValue] = simpleCondition;
|
|
1093
1089
|
const [stepId, ...pathParts] = key.split(".");
|
|
1094
1090
|
const path = pathParts.join(".");
|
|
1095
|
-
const sourceData = stepId === "trigger" ? context.triggerData : getStepResult(context.
|
|
1091
|
+
const sourceData = stepId === "trigger" ? context.triggerData : getStepResult(context.steps[stepId]);
|
|
1096
1092
|
this.logger.debug(`Got condition data from ${stepId}`, {
|
|
1097
1093
|
sourceData,
|
|
1098
1094
|
runId: __privateGet(this, _runId)
|
|
@@ -1112,7 +1108,7 @@ evaluateCondition_fn = /* @__PURE__ */ __name(function(condition, context) {
|
|
|
1112
1108
|
}
|
|
1113
1109
|
if ("ref" in condition) {
|
|
1114
1110
|
const { ref, query } = condition;
|
|
1115
|
-
const sourceData = ref.step === "trigger" ? context.triggerData : getStepResult(context.
|
|
1111
|
+
const sourceData = ref.step === "trigger" ? context.triggerData : getStepResult(context.steps[ref.step.id]);
|
|
1116
1112
|
this.logger.debug(`Got condition data from ${ref.step === "trigger" ? "trigger" : ref.step.id}`, {
|
|
1117
1113
|
sourceData,
|
|
1118
1114
|
runId: __privateGet(this, _runId)
|
|
@@ -1226,7 +1222,7 @@ hasStateChanged_fn = /* @__PURE__ */ __name(function(previous, current) {
|
|
|
1226
1222
|
if (JSON.stringify(prevPath?.stepPath) !== JSON.stringify(currPath?.stepPath)) return true;
|
|
1227
1223
|
if (prevPath?.status !== currPath?.status) return true;
|
|
1228
1224
|
}
|
|
1229
|
-
if (JSON.stringify(previous.context.
|
|
1225
|
+
if (JSON.stringify(previous.context.steps) !== JSON.stringify(current.context.steps)) return true;
|
|
1230
1226
|
return false;
|
|
1231
1227
|
}, "#hasStateChanged");
|
|
1232
1228
|
getDeepestState_fn = /* @__PURE__ */ __name(function(value) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InstrumentClass } from './chunk-4ZUSEHLH.js';
|
|
2
2
|
import { delay } from './chunk-KNPBNSJ7.js';
|
|
3
|
-
import { executeHook, AvailableHooks } from './chunk-HBTQNIAX.js';
|
|
4
3
|
import { MastraBase } from './chunk-G4MCO7XF.js';
|
|
5
4
|
import { RegisteredLogger, LogLevel } from './chunk-ICMEXHKD.js';
|
|
5
|
+
import { executeHook, AvailableHooks } from './chunk-HBTQNIAX.js';
|
|
6
6
|
import { __name, __privateAdd, __privateSet, __privateGet, __publicField } from './chunk-AJJZUHB4.js';
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
8
|
import { z } from 'zod';
|
|
@@ -24,6 +24,9 @@ var _MastraLLMBase = class _MastraLLMBase extends MastraBase {
|
|
|
24
24
|
getProvider() {
|
|
25
25
|
return __privateGet(this, _model).provider;
|
|
26
26
|
}
|
|
27
|
+
getModelId() {
|
|
28
|
+
return __privateGet(this, _model).modelId;
|
|
29
|
+
}
|
|
27
30
|
convertToMessages(messages) {
|
|
28
31
|
if (Array.isArray(messages)) {
|
|
29
32
|
return messages.map((m) => {
|
|
@@ -124,6 +127,9 @@ var _MastraLLM = class _MastraLLM extends MastraLLMBase {
|
|
|
124
127
|
getProvider() {
|
|
125
128
|
return __privateGet(this, _model2).provider;
|
|
126
129
|
}
|
|
130
|
+
getModelId() {
|
|
131
|
+
return __privateGet(this, _model2).modelId;
|
|
132
|
+
}
|
|
127
133
|
convertTools(tools) {
|
|
128
134
|
this.logger.debug("Starting tool conversion for LLM");
|
|
129
135
|
const converted = Object.entries(tools || {}).reduce((memo, value) => {
|
|
@@ -476,6 +482,13 @@ var _Agent = class _Agent extends MastraBase {
|
|
|
476
482
|
getMemory() {
|
|
477
483
|
return __privateGet(this, _memory) ?? __privateGet(this, _mastra3)?.memory;
|
|
478
484
|
}
|
|
485
|
+
__updateInstructions(newInstructions) {
|
|
486
|
+
this.instructions = newInstructions;
|
|
487
|
+
this.logger.debug(`[Agents:${this.name}] Instructions updated.`, {
|
|
488
|
+
model: this.model,
|
|
489
|
+
name: this.name
|
|
490
|
+
});
|
|
491
|
+
}
|
|
479
492
|
__registerPrimitives(p) {
|
|
480
493
|
if (p.telemetry) {
|
|
481
494
|
this.__setTelemetry(p.telemetry);
|
|
@@ -562,7 +575,7 @@ var _Agent = class _Agent extends MastraBase {
|
|
|
562
575
|
threadId
|
|
563
576
|
});
|
|
564
577
|
if (!thread) {
|
|
565
|
-
this.logger.debug(`Thread not found, creating new thread for agent ${this.name}`, {
|
|
578
|
+
this.logger.debug(`Thread with id ${threadId} not found, creating new thread for agent ${this.name}`, {
|
|
566
579
|
runId: runId || this.name
|
|
567
580
|
});
|
|
568
581
|
const title = await this.genTitle(userMessage);
|
|
@@ -694,11 +707,11 @@ ${memorySystemMessage}` : ""}`
|
|
|
694
707
|
const responseMessagesWithoutIncompleteToolCalls = this.sanitizeResponseMessages(ms);
|
|
695
708
|
const memory = this.getMemory();
|
|
696
709
|
if (memory) {
|
|
697
|
-
this.logger.debug(`[Agent:${this.name}] - Memory persistence: store=${
|
|
710
|
+
this.logger.debug(`[Agent:${this.name}] - Memory persistence: store=${this.getMemory()?.constructor.name} threadId=${threadId}`, {
|
|
698
711
|
runId,
|
|
699
712
|
resourceId,
|
|
700
713
|
threadId,
|
|
701
|
-
memoryStore:
|
|
714
|
+
memoryStore: this.getMemory()?.constructor.name
|
|
702
715
|
});
|
|
703
716
|
await memory.saveMessages({
|
|
704
717
|
memoryConfig,
|
|
@@ -883,11 +896,11 @@ ${memorySystemMessage}` : ""}`
|
|
|
883
896
|
let coreMessages = messages;
|
|
884
897
|
let threadIdToUse = threadId;
|
|
885
898
|
if (this.getMemory() && resourceId) {
|
|
886
|
-
this.logger.debug(`[Agent:${this.name}] - Memory persistence enabled: store=${
|
|
899
|
+
this.logger.debug(`[Agent:${this.name}] - Memory persistence enabled: store=${this.getMemory()?.constructor.name}, resourceId=${resourceId}`, {
|
|
887
900
|
runId,
|
|
888
901
|
resourceId,
|
|
889
902
|
threadId: threadIdToUse,
|
|
890
|
-
memoryStore:
|
|
903
|
+
memoryStore: this.getMemory()?.constructor.name
|
|
891
904
|
});
|
|
892
905
|
const preExecuteResult = await this.preExecute({
|
|
893
906
|
resourceId,
|
|
@@ -981,7 +994,8 @@ ${memorySystemMessage}` : ""}`
|
|
|
981
994
|
output: outputText,
|
|
982
995
|
runId: runIdToUse,
|
|
983
996
|
metric,
|
|
984
|
-
agentName: this.name
|
|
997
|
+
agentName: this.name,
|
|
998
|
+
instructions: this.instructions
|
|
985
999
|
});
|
|
986
1000
|
}
|
|
987
1001
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MastraBase } from './chunk-G4MCO7XF.js';
|
|
2
2
|
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
3
3
|
import { createClient } from '@libsql/client';
|
|
4
|
+
import { join } from 'path';
|
|
4
5
|
|
|
5
6
|
// src/storage/base.ts
|
|
6
7
|
var _MastraStorage = class _MastraStorage extends MastraBase {
|
|
@@ -213,10 +214,23 @@ var _DefaultStorage = class _DefaultStorage extends MastraStorage {
|
|
|
213
214
|
});
|
|
214
215
|
__publicField(this, "client");
|
|
215
216
|
this.client = createClient({
|
|
216
|
-
url: config.url,
|
|
217
|
+
url: this.rewriteDbUrl(config.url),
|
|
217
218
|
authToken: config.authToken
|
|
218
219
|
});
|
|
219
220
|
}
|
|
221
|
+
rewriteDbUrl(url) {
|
|
222
|
+
if (url.startsWith("file:") && !url.startsWith("file:/")) {
|
|
223
|
+
const cwd = process.cwd();
|
|
224
|
+
const relativePath = url.slice("file:".length);
|
|
225
|
+
if (cwd.endsWith(".mastra") || cwd.endsWith(".mastra/")) {
|
|
226
|
+
const baseDir = join(cwd, `..`);
|
|
227
|
+
const fullPath = join(baseDir, relativePath);
|
|
228
|
+
this.logger.debug(`Initializing LibSQL db with url ${url} with relative file path from inside .mastra directory. Rewriting relative file url to "file:${fullPath}". This ensures it's outside the .mastra directory. If the db is stored inside .mastra it will be deleted when Mastra re-bundles code.`);
|
|
229
|
+
return `file:${fullPath}`;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return url;
|
|
233
|
+
}
|
|
220
234
|
getCreateTableSQL(tableName, schema) {
|
|
221
235
|
const columns = Object.entries(schema).map(([name, col]) => {
|
|
222
236
|
let type = col.type.toUpperCase();
|
|
@@ -501,6 +515,35 @@ var _DefaultStorage = class _DefaultStorage extends MastraStorage {
|
|
|
501
515
|
throw error;
|
|
502
516
|
}
|
|
503
517
|
}
|
|
518
|
+
async getEvalsByAgentName(agentName, type) {
|
|
519
|
+
try {
|
|
520
|
+
const baseQuery = `SELECT * FROM ${MastraStorage.TABLE_EVALS} WHERE meta->>'$.agentName' = ?`;
|
|
521
|
+
const typeCondition = type === "test" ? " AND meta->>'$.testPath' IS NOT NULL" : type === "live" ? " AND meta->>'$.testPath' IS NULL" : "";
|
|
522
|
+
const result = await this.client.execute({
|
|
523
|
+
sql: `${baseQuery}${typeCondition} ORDER BY createdAt DESC`,
|
|
524
|
+
args: [
|
|
525
|
+
agentName
|
|
526
|
+
]
|
|
527
|
+
});
|
|
528
|
+
if (!result.rows) {
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
531
|
+
return result.rows.map((row) => ({
|
|
532
|
+
...row,
|
|
533
|
+
result: typeof row.result === "string" ? JSON.parse(row.result) : row.result,
|
|
534
|
+
meta: typeof row.meta === "string" ? JSON.parse(row.meta) : row.meta,
|
|
535
|
+
input: row.input,
|
|
536
|
+
output: row.output,
|
|
537
|
+
createdAt: row.createdAt
|
|
538
|
+
}));
|
|
539
|
+
} catch (error) {
|
|
540
|
+
if (error instanceof Error && error.message.includes("no such table")) {
|
|
541
|
+
return [];
|
|
542
|
+
}
|
|
543
|
+
console.error("Failed to get evals for the specified agent", error);
|
|
544
|
+
throw error;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
504
547
|
};
|
|
505
548
|
__name(_DefaultStorage, "DefaultStorage");
|
|
506
549
|
var DefaultStorage = _DefaultStorage;
|