@mastra/core 0.10.13 → 0.10.15-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/a2a.d.ts +1 -0
- package/agent.d.ts +1 -0
- package/base.d.ts +1 -0
- package/bundler.d.ts +1 -0
- package/deployer.d.ts +1 -0
- package/di.d.ts +1 -0
- package/dist/a2a/index.cjs +79 -0
- package/dist/a2a/index.d.cts +780 -0
- package/dist/a2a/index.d.ts +780 -0
- package/dist/a2a/index.js +68 -0
- package/dist/agent/index.cjs +15 -0
- package/dist/agent/index.d.cts +29 -0
- package/dist/agent/index.d.ts +29 -0
- package/dist/agent/index.js +2 -0
- package/dist/base-B_y9sMg0.d.cts +162 -0
- package/dist/base-CTj7ESwt.d.cts +4132 -0
- package/dist/base-ClrXcCRx.d.ts +162 -0
- package/dist/base-qVqAnB-c.d.ts +4132 -0
- package/dist/base.cjs +10 -0
- package/dist/base.d.cts +6 -0
- package/dist/base.d.ts +6 -0
- package/dist/base.js +1 -0
- package/dist/bundler/index.cjs +10 -0
- package/dist/bundler/index.d.cts +30 -0
- package/dist/bundler/index.d.ts +30 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-32C7JDIZ.js +1 -0
- package/dist/chunk-4UWPFBC6.js +88 -0
- package/dist/chunk-4Z3OU5RY.cjs +31 -0
- package/dist/chunk-5HTMDAXP.js +359 -0
- package/dist/chunk-5IEKR756.js +53 -0
- package/dist/chunk-5YDTZN2X.js +114 -0
- package/dist/chunk-6UNGH46J.js +75 -0
- package/dist/chunk-6Y4UL5Z6.cjs +94 -0
- package/dist/chunk-7H2GET5Z.cjs +668 -0
- package/dist/chunk-7HZ6NIAF.cjs +2 -0
- package/dist/chunk-7XQIPES3.js +668 -0
- package/dist/chunk-AKYTYALY.js +70 -0
- package/dist/chunk-AOWJUV2N.js +2415 -0
- package/dist/chunk-ATXBSEFT.js +22 -0
- package/dist/chunk-B6TOBUS6.cjs +80 -0
- package/dist/chunk-B7SQOKEC.cjs +91 -0
- package/dist/chunk-BB4KXGBU.js +83 -0
- package/dist/chunk-BB6DPGIV.cjs +6 -0
- package/dist/chunk-BVD7NVAR.cjs +244 -0
- package/dist/chunk-C4LMN2IR.js +27 -0
- package/dist/chunk-DR4JS662.js +989 -0
- package/dist/chunk-F2WMR75C.cjs +183 -0
- package/dist/chunk-FEYYOBBG.cjs +24 -0
- package/dist/chunk-FL5SZ2XU.js +181 -0
- package/dist/chunk-GH2KM66J.js +37 -0
- package/dist/chunk-GWFS5DAR.cjs +37 -0
- package/dist/chunk-HNEE7IF4.js +60 -0
- package/dist/chunk-HSVOEWAM.cjs +2 -0
- package/dist/chunk-IBKM5CLQ.js +428 -0
- package/dist/chunk-ID5LG5CQ.cjs +659 -0
- package/dist/chunk-J52TXHZV.cjs +73 -0
- package/dist/chunk-J62R4M7K.js +240 -0
- package/dist/chunk-JNMQKJH4.js +10 -0
- package/dist/chunk-JQOMTERC.js +89 -0
- package/dist/chunk-LABUWBKX.cjs +71 -0
- package/dist/chunk-LBUQ6YNU.cjs +447 -0
- package/dist/chunk-LXFZUKP3.cjs +34 -0
- package/dist/chunk-MP2QBLUJ.cjs +70 -0
- package/dist/chunk-MUNFCOMB.cjs +62 -0
- package/dist/chunk-MVCHTRVB.js +5038 -0
- package/dist/chunk-NH5WJNNS.js +1 -0
- package/dist/chunk-P3Q73CAW.cjs +55 -0
- package/dist/chunk-Q33INUG2.cjs +81 -0
- package/dist/chunk-QFTBW7ZZ.cjs +2 -0
- package/dist/chunk-QQ5K5TZE.cjs +619 -0
- package/dist/chunk-R4V75T7J.js +1 -0
- package/dist/chunk-RVFWMGGR.js +77 -0
- package/dist/chunk-SGGPJWRQ.js +69 -0
- package/dist/chunk-ST5RMVLG.cjs +87 -0
- package/dist/chunk-TC2SCOTE.js +605 -0
- package/dist/chunk-TTMYHBQM.js +657 -0
- package/dist/chunk-U64IJDC5.cjs +109 -0
- package/dist/chunk-ULZ6MRTN.cjs +5065 -0
- package/dist/chunk-V5D2LIF5.js +68 -0
- package/dist/chunk-WQNOATKB.js +103 -0
- package/dist/chunk-Y7D2JLKS.js +4 -0
- package/dist/chunk-YOQP5T77.js +32 -0
- package/dist/chunk-ZCU3PLIL.cjs +2429 -0
- package/dist/chunk-ZIZ3CVHN.cjs +120 -0
- package/dist/chunk-ZPOUMTTH.cjs +362 -0
- package/dist/chunk-ZTPPDHQK.cjs +991 -0
- package/dist/chunk-ZZLBNB3U.cjs +12 -0
- package/dist/deployer/index.cjs +10 -0
- package/dist/deployer/index.d.cts +19 -0
- package/dist/deployer/index.d.ts +19 -0
- package/dist/deployer/index.js +1 -0
- package/dist/di/index.cjs +10 -0
- package/dist/di/index.d.cts +1 -0
- package/dist/di/index.d.ts +1 -0
- package/dist/di/index.js +1 -0
- package/dist/error/index.cjs +22 -0
- package/dist/error/index.d.cts +86 -0
- package/dist/error/index.d.ts +86 -0
- package/dist/error/index.js +1 -0
- package/dist/eval/index.cjs +14 -0
- package/dist/eval/index.d.cts +43 -0
- package/dist/eval/index.d.ts +43 -0
- package/dist/eval/index.js +1 -0
- package/dist/hooks/index.cjs +18 -0
- package/dist/hooks/index.d.cts +33 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index.cjs +285 -0
- package/dist/index.d.cts +92 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +112 -0
- package/dist/integration/index.cjs +14 -0
- package/dist/integration/index.d.cts +65 -0
- package/dist/integration/index.d.ts +65 -0
- package/dist/integration/index.js +1 -0
- package/dist/llm/index.cjs +10 -0
- package/dist/llm/index.d.cts +29 -0
- package/dist/llm/index.d.ts +29 -0
- package/dist/llm/index.js +1 -0
- package/dist/logger/index.cjs +43 -0
- package/dist/logger/index.d.cts +96 -0
- package/dist/logger/index.d.ts +96 -0
- package/dist/logger/index.js +2 -0
- package/dist/logger-B8XXh6ya.d.cts +159 -0
- package/dist/logger-Bpa2oLL4.d.ts +159 -0
- package/dist/mastra/index.cjs +10 -0
- package/dist/mastra/index.d.cts +29 -0
- package/dist/mastra/index.d.ts +29 -0
- package/dist/mastra/index.js +1 -0
- package/dist/mcp/index.cjs +106 -0
- package/dist/mcp/index.d.cts +29 -0
- package/dist/mcp/index.d.ts +29 -0
- package/dist/mcp/index.js +100 -0
- package/dist/memory/index.cjs +18 -0
- package/dist/memory/index.d.cts +29 -0
- package/dist/memory/index.d.ts +29 -0
- package/dist/memory/index.js +1 -0
- package/dist/network/index.cjs +311 -0
- package/dist/network/index.d.cts +29 -0
- package/dist/network/index.d.ts +29 -0
- package/dist/network/index.js +309 -0
- package/dist/network/vNext/index.cjs +880 -0
- package/dist/network/vNext/index.d.cts +29 -0
- package/dist/network/vNext/index.d.ts +29 -0
- package/dist/network/vNext/index.js +878 -0
- package/dist/relevance/index.cjs +18 -0
- package/dist/relevance/index.d.cts +50 -0
- package/dist/relevance/index.d.ts +50 -0
- package/dist/relevance/index.js +1 -0
- package/dist/runtime-context/index.cjs +10 -0
- package/dist/runtime-context/index.d.cts +52 -0
- package/dist/runtime-context/index.d.ts +52 -0
- package/dist/runtime-context/index.js +1 -0
- package/dist/server/index.cjs +62 -0
- package/dist/server/index.d.cts +52 -0
- package/dist/server/index.d.ts +52 -0
- package/dist/server/index.js +59 -0
- package/dist/storage/index.cjs +336 -0
- package/dist/storage/index.d.cts +149 -0
- package/dist/storage/index.d.ts +149 -0
- package/dist/storage/index.js +303 -0
- package/dist/telemetry/index.cjs +30 -0
- package/dist/telemetry/index.d.cts +75 -0
- package/dist/telemetry/index.d.ts +75 -0
- package/dist/telemetry/index.js +1 -0
- package/dist/telemetry/otel-vendor.cjs +103 -0
- package/dist/telemetry/otel-vendor.d.cts +20 -0
- package/dist/telemetry/otel-vendor.d.ts +20 -0
- package/dist/telemetry/otel-vendor.js +57 -0
- package/dist/tools/index.cjs +18 -0
- package/dist/tools/index.d.cts +41 -0
- package/dist/tools/index.d.ts +41 -0
- package/dist/tools/index.js +1 -0
- package/dist/tts/index.cjs +10 -0
- package/dist/tts/index.d.cts +28 -0
- package/dist/tts/index.d.ts +28 -0
- package/dist/tts/index.js +1 -0
- package/dist/types-Bo1uigWx.d.cts +17 -0
- package/dist/types-Bo1uigWx.d.ts +17 -0
- package/dist/utils.cjs +62 -0
- package/dist/utils.d.cts +150 -0
- package/dist/utils.d.ts +150 -0
- package/dist/utils.js +1 -0
- package/dist/vector/filter/index.cjs +192 -0
- package/dist/vector/filter/index.d.cts +128 -0
- package/dist/vector/filter/index.d.ts +128 -0
- package/dist/vector/filter/index.js +190 -0
- package/dist/vector/index.cjs +10 -0
- package/dist/vector/index.d.cts +77 -0
- package/dist/vector/index.d.ts +77 -0
- package/dist/vector/index.js +1 -0
- package/dist/voice/index.cjs +18 -0
- package/dist/voice/index.d.cts +29 -0
- package/dist/voice/index.d.ts +29 -0
- package/dist/voice/index.js +1 -0
- package/dist/workflows/constants.cjs +10 -0
- package/dist/workflows/constants.d.cts +3 -0
- package/dist/workflows/constants.d.ts +3 -0
- package/dist/workflows/constants.js +1 -0
- package/dist/workflows/index.cjs +42 -0
- package/dist/workflows/index.d.cts +285 -0
- package/dist/workflows/index.d.ts +285 -0
- package/dist/workflows/index.js +1 -0
- package/dist/workflows/legacy/index.cjs +90 -0
- package/dist/workflows/legacy/index.d.cts +91 -0
- package/dist/workflows/legacy/index.d.ts +91 -0
- package/dist/workflows/legacy/index.js +1 -0
- package/error.d.ts +1 -0
- package/eval.d.ts +1 -0
- package/hooks.d.ts +1 -0
- package/integration.d.ts +1 -0
- package/llm.d.ts +1 -0
- package/logger.d.ts +1 -0
- package/mastra.d.ts +1 -0
- package/mcp.d.ts +1 -0
- package/memory.d.ts +1 -0
- package/network/vNext.d.ts +1 -0
- package/network.d.ts +1 -0
- package/package.json +2 -3
- package/relevance.d.ts +1 -0
- package/runtime-context.d.ts +1 -0
- package/server.d.ts +1 -0
- package/storage.d.ts +1 -0
- package/telemetry/otel-vendor.d.ts +1 -0
- package/telemetry.d.ts +1 -0
- package/tools.d.ts +1 -0
- package/tts.d.ts +1 -0
- package/utils.d.ts +1 -0
- package/vector/filter.d.ts +1 -0
- package/vector.d.ts +1 -0
- package/voice.d.ts +1 -0
- package/workflows/_constants.d.ts +1 -0
- package/workflows/legacy.d.ts +1 -0
- package/workflows.d.ts +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkST5RMVLG_cjs = require('./chunk-ST5RMVLG.cjs');
|
|
4
|
+
var chunkB6TOBUS6_cjs = require('./chunk-B6TOBUS6.cjs');
|
|
5
|
+
|
|
6
|
+
// src/eval/metric.ts
|
|
7
|
+
var Metric = class {
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/eval/evaluation.ts
|
|
11
|
+
async function evaluate({
|
|
12
|
+
agentName,
|
|
13
|
+
input,
|
|
14
|
+
metric,
|
|
15
|
+
output,
|
|
16
|
+
runId,
|
|
17
|
+
globalRunId,
|
|
18
|
+
testInfo,
|
|
19
|
+
instructions
|
|
20
|
+
}) {
|
|
21
|
+
const runIdToUse = runId || crypto.randomUUID();
|
|
22
|
+
let metricResult;
|
|
23
|
+
let metricName = metric.constructor.name;
|
|
24
|
+
try {
|
|
25
|
+
metricResult = await metric.measure(input.toString(), output);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
throw new chunkB6TOBUS6_cjs.MastraError(
|
|
28
|
+
{
|
|
29
|
+
id: "EVAL_METRIC_MEASURE_EXECUTION_FAILED",
|
|
30
|
+
domain: "EVAL" /* EVAL */,
|
|
31
|
+
category: "USER" /* USER */,
|
|
32
|
+
details: {
|
|
33
|
+
agentName,
|
|
34
|
+
metricName,
|
|
35
|
+
globalRunId
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
e
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
const traceObject = {
|
|
42
|
+
input: input.toString(),
|
|
43
|
+
output,
|
|
44
|
+
result: metricResult,
|
|
45
|
+
agentName,
|
|
46
|
+
metricName,
|
|
47
|
+
instructions,
|
|
48
|
+
globalRunId,
|
|
49
|
+
runId: runIdToUse,
|
|
50
|
+
testInfo
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
chunkST5RMVLG_cjs.executeHook("onEvaluation" /* ON_EVALUATION */, traceObject);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw new chunkB6TOBUS6_cjs.MastraError(
|
|
56
|
+
{
|
|
57
|
+
id: "EVAL_HOOK_EXECUTION_FAILED",
|
|
58
|
+
domain: "EVAL" /* EVAL */,
|
|
59
|
+
category: "USER" /* USER */,
|
|
60
|
+
details: {
|
|
61
|
+
agentName,
|
|
62
|
+
metricName,
|
|
63
|
+
globalRunId
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
e
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return { ...metricResult, output };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
exports.Metric = Metric;
|
|
73
|
+
exports.evaluate = evaluate;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { augmentWithInit } from './chunk-YOQP5T77.js';
|
|
2
|
+
import { MessageList } from './chunk-DR4JS662.js';
|
|
3
|
+
import { deepMerge } from './chunk-IBKM5CLQ.js';
|
|
4
|
+
import { MastraBase } from './chunk-5IEKR756.js';
|
|
5
|
+
|
|
6
|
+
// src/memory/memory.ts
|
|
7
|
+
var MemoryProcessor = class extends MastraBase {
|
|
8
|
+
/**
|
|
9
|
+
* Process a list of messages and return a filtered or transformed list.
|
|
10
|
+
* @param messages The messages to process
|
|
11
|
+
* @returns The processed messages
|
|
12
|
+
*/
|
|
13
|
+
process(messages, _opts) {
|
|
14
|
+
return messages;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var memoryDefaultOptions = {
|
|
18
|
+
lastMessages: 10,
|
|
19
|
+
semanticRecall: false,
|
|
20
|
+
threads: {
|
|
21
|
+
generateTitle: false
|
|
22
|
+
},
|
|
23
|
+
workingMemory: {
|
|
24
|
+
enabled: false,
|
|
25
|
+
template: `
|
|
26
|
+
# User Information
|
|
27
|
+
- **First Name**:
|
|
28
|
+
- **Last Name**:
|
|
29
|
+
- **Location**:
|
|
30
|
+
- **Occupation**:
|
|
31
|
+
- **Interests**:
|
|
32
|
+
- **Goals**:
|
|
33
|
+
- **Events**:
|
|
34
|
+
- **Facts**:
|
|
35
|
+
- **Projects**:
|
|
36
|
+
`
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var MastraMemory = class extends MastraBase {
|
|
40
|
+
MAX_CONTEXT_TOKENS;
|
|
41
|
+
_storage;
|
|
42
|
+
vector;
|
|
43
|
+
embedder;
|
|
44
|
+
processors = [];
|
|
45
|
+
threadConfig = { ...memoryDefaultOptions };
|
|
46
|
+
constructor(config) {
|
|
47
|
+
super({ component: "MEMORY", name: config.name });
|
|
48
|
+
if (config.options) this.threadConfig = this.getMergedThreadConfig(config.options);
|
|
49
|
+
if (config.processors) this.processors = config.processors;
|
|
50
|
+
if (config.storage) {
|
|
51
|
+
this._storage = augmentWithInit(config.storage);
|
|
52
|
+
this._hasOwnStorage = true;
|
|
53
|
+
}
|
|
54
|
+
if (this.threadConfig.semanticRecall) {
|
|
55
|
+
if (!config.vector) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Semantic recall requires a vector store to be configured.
|
|
58
|
+
|
|
59
|
+
https://mastra.ai/en/docs/memory/semantic-recall`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
this.vector = config.vector;
|
|
63
|
+
if (!config.embedder) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Semantic recall requires an embedder to be configured.
|
|
66
|
+
|
|
67
|
+
https://mastra.ai/en/docs/memory/semantic-recall`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
this.embedder = config.embedder;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
_hasOwnStorage = false;
|
|
74
|
+
get hasOwnStorage() {
|
|
75
|
+
return this._hasOwnStorage;
|
|
76
|
+
}
|
|
77
|
+
get storage() {
|
|
78
|
+
if (!this._storage) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Memory requires a storage provider to function. Add a storage configuration to Memory or to your Mastra instance.
|
|
81
|
+
|
|
82
|
+
https://mastra.ai/en/docs/memory/overview`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return this._storage;
|
|
86
|
+
}
|
|
87
|
+
setStorage(storage) {
|
|
88
|
+
this._storage = augmentWithInit(storage);
|
|
89
|
+
}
|
|
90
|
+
setVector(vector) {
|
|
91
|
+
this.vector = vector;
|
|
92
|
+
}
|
|
93
|
+
setEmbedder(embedder) {
|
|
94
|
+
this.embedder = embedder;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get a system message to inject into the conversation.
|
|
98
|
+
* This will be called before each conversation turn.
|
|
99
|
+
* Implementations can override this to inject custom system messages.
|
|
100
|
+
*/
|
|
101
|
+
async getSystemMessage(_input) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get tools that should be available to the agent.
|
|
106
|
+
* This will be called when converting tools for the agent.
|
|
107
|
+
* Implementations can override this to provide additional tools.
|
|
108
|
+
*/
|
|
109
|
+
getTools(_config) {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
async createEmbeddingIndex(dimensions) {
|
|
113
|
+
const defaultDimensions = 1536;
|
|
114
|
+
const isDefault = dimensions === defaultDimensions;
|
|
115
|
+
const usedDimensions = dimensions ?? defaultDimensions;
|
|
116
|
+
const separator = this.vector?.indexSeparator ?? "_";
|
|
117
|
+
const indexName = isDefault ? `memory${separator}messages` : `memory${separator}messages${separator}${usedDimensions}`;
|
|
118
|
+
if (typeof this.vector === `undefined`) {
|
|
119
|
+
throw new Error(`Tried to create embedding index but no vector db is attached to this Memory instance.`);
|
|
120
|
+
}
|
|
121
|
+
await this.vector.createIndex({
|
|
122
|
+
indexName,
|
|
123
|
+
dimension: usedDimensions
|
|
124
|
+
});
|
|
125
|
+
return { indexName };
|
|
126
|
+
}
|
|
127
|
+
getMergedThreadConfig(config) {
|
|
128
|
+
if (config?.workingMemory && "use" in config.workingMemory) {
|
|
129
|
+
throw new Error("The workingMemory.use option has been removed. Working memory always uses tool-call mode.");
|
|
130
|
+
}
|
|
131
|
+
const mergedConfig = deepMerge(this.threadConfig, config || {});
|
|
132
|
+
if (config?.workingMemory?.schema) {
|
|
133
|
+
if (mergedConfig.workingMemory) {
|
|
134
|
+
mergedConfig.workingMemory.schema = config.workingMemory.schema;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return mergedConfig;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Apply all configured message processors to a list of messages.
|
|
141
|
+
* @param messages The messages to process
|
|
142
|
+
* @returns The processed messages
|
|
143
|
+
*/
|
|
144
|
+
applyProcessors(messages, opts) {
|
|
145
|
+
const processors = opts.processors || this.processors;
|
|
146
|
+
if (!processors || processors.length === 0) {
|
|
147
|
+
return messages;
|
|
148
|
+
}
|
|
149
|
+
let processedMessages = [...messages];
|
|
150
|
+
for (const processor of processors) {
|
|
151
|
+
processedMessages = processor.process(processedMessages, {
|
|
152
|
+
systemMessage: opts.systemMessage,
|
|
153
|
+
newMessages: opts.newMessages,
|
|
154
|
+
memorySystemMessage: opts.memorySystemMessage
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return processedMessages;
|
|
158
|
+
}
|
|
159
|
+
processMessages({
|
|
160
|
+
messages,
|
|
161
|
+
processors,
|
|
162
|
+
...opts
|
|
163
|
+
}) {
|
|
164
|
+
return this.applyProcessors(messages, { processors: processors || this.processors, ...opts });
|
|
165
|
+
}
|
|
166
|
+
estimateTokens(text) {
|
|
167
|
+
return Math.ceil(text.split(" ").length * 1.3);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Helper method to create a new thread
|
|
171
|
+
* @param title - Optional title for the thread
|
|
172
|
+
* @param metadata - Optional metadata for the thread
|
|
173
|
+
* @returns Promise resolving to the created thread
|
|
174
|
+
*/
|
|
175
|
+
async createThread({
|
|
176
|
+
threadId,
|
|
177
|
+
resourceId,
|
|
178
|
+
title,
|
|
179
|
+
metadata,
|
|
180
|
+
memoryConfig
|
|
181
|
+
}) {
|
|
182
|
+
const thread = {
|
|
183
|
+
id: threadId || this.generateId(),
|
|
184
|
+
title: title || `New Thread ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
185
|
+
resourceId,
|
|
186
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
187
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
188
|
+
metadata
|
|
189
|
+
};
|
|
190
|
+
return this.saveThread({ thread, memoryConfig });
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Helper method to add a single message to a thread
|
|
194
|
+
* @param threadId - The thread to add the message to
|
|
195
|
+
* @param content - The message content
|
|
196
|
+
* @param role - The role of the message sender
|
|
197
|
+
* @param type - The type of the message
|
|
198
|
+
* @param toolNames - Optional array of tool names that were called
|
|
199
|
+
* @param toolCallArgs - Optional array of tool call arguments
|
|
200
|
+
* @param toolCallIds - Optional array of tool call ids
|
|
201
|
+
* @returns Promise resolving to the saved message
|
|
202
|
+
* @deprecated use saveMessages instead
|
|
203
|
+
*/
|
|
204
|
+
async addMessage({
|
|
205
|
+
threadId,
|
|
206
|
+
resourceId,
|
|
207
|
+
config,
|
|
208
|
+
content,
|
|
209
|
+
role,
|
|
210
|
+
type,
|
|
211
|
+
toolNames,
|
|
212
|
+
toolCallArgs,
|
|
213
|
+
toolCallIds
|
|
214
|
+
}) {
|
|
215
|
+
const message = {
|
|
216
|
+
id: this.generateId(),
|
|
217
|
+
content,
|
|
218
|
+
role,
|
|
219
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
220
|
+
threadId,
|
|
221
|
+
resourceId,
|
|
222
|
+
type,
|
|
223
|
+
toolNames,
|
|
224
|
+
toolCallArgs,
|
|
225
|
+
toolCallIds
|
|
226
|
+
};
|
|
227
|
+
const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
|
|
228
|
+
const list = new MessageList({ threadId, resourceId }).add(savedMessages[0], "memory");
|
|
229
|
+
return list.get.all.v1()[0];
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Generates a unique identifier
|
|
233
|
+
* @returns A unique string ID
|
|
234
|
+
*/
|
|
235
|
+
generateId() {
|
|
236
|
+
return crypto.randomUUID();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export { MastraMemory, MemoryProcessor, memoryDefaultOptions };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Transform } from 'stream';
|
|
2
|
+
|
|
3
|
+
// src/logger/multi-logger.ts
|
|
4
|
+
var MultiLogger = class {
|
|
5
|
+
loggers;
|
|
6
|
+
constructor(loggers) {
|
|
7
|
+
this.loggers = loggers;
|
|
8
|
+
}
|
|
9
|
+
debug(message, ...args) {
|
|
10
|
+
this.loggers.forEach((logger) => logger.debug(message, ...args));
|
|
11
|
+
}
|
|
12
|
+
info(message, ...args) {
|
|
13
|
+
this.loggers.forEach((logger) => logger.info(message, ...args));
|
|
14
|
+
}
|
|
15
|
+
warn(message, ...args) {
|
|
16
|
+
this.loggers.forEach((logger) => logger.warn(message, ...args));
|
|
17
|
+
}
|
|
18
|
+
error(message, ...args) {
|
|
19
|
+
this.loggers.forEach((logger) => logger.error(message, ...args));
|
|
20
|
+
}
|
|
21
|
+
trackException(error) {
|
|
22
|
+
this.loggers.forEach((logger) => logger.trackException(error));
|
|
23
|
+
}
|
|
24
|
+
getTransports() {
|
|
25
|
+
const transports = [];
|
|
26
|
+
this.loggers.forEach((logger) => transports.push(...logger.getTransports().entries()));
|
|
27
|
+
return new Map(transports);
|
|
28
|
+
}
|
|
29
|
+
async getLogs(transportId, params) {
|
|
30
|
+
for (const logger of this.loggers) {
|
|
31
|
+
const logs = await logger.getLogs(transportId, params);
|
|
32
|
+
if (logs.total > 0) {
|
|
33
|
+
return logs;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
37
|
+
}
|
|
38
|
+
async getLogsByRunId(args) {
|
|
39
|
+
for (const logger of this.loggers) {
|
|
40
|
+
const logs = await logger.getLogsByRunId(args);
|
|
41
|
+
if (logs.total > 0) {
|
|
42
|
+
return logs;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { logs: [], total: 0, page: args.page ?? 1, perPage: args.perPage ?? 100, hasMore: false };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/logger/noop-logger.ts
|
|
50
|
+
var noopLogger = {
|
|
51
|
+
debug: () => {
|
|
52
|
+
},
|
|
53
|
+
info: () => {
|
|
54
|
+
},
|
|
55
|
+
warn: () => {
|
|
56
|
+
},
|
|
57
|
+
error: () => {
|
|
58
|
+
},
|
|
59
|
+
cleanup: async () => {
|
|
60
|
+
},
|
|
61
|
+
getTransports: () => /* @__PURE__ */ new Map(),
|
|
62
|
+
trackException: () => {
|
|
63
|
+
},
|
|
64
|
+
getLogs: async () => ({ logs: [], total: 0, page: 1, perPage: 100, hasMore: false }),
|
|
65
|
+
getLogsByRunId: async () => ({ logs: [], total: 0, page: 1, perPage: 100, hasMore: false })
|
|
66
|
+
};
|
|
67
|
+
var LoggerTransport = class extends Transform {
|
|
68
|
+
constructor(opts = {}) {
|
|
69
|
+
super({ ...opts, objectMode: true });
|
|
70
|
+
}
|
|
71
|
+
async getLogsByRunId(_args) {
|
|
72
|
+
return { logs: [], total: 0, page: _args?.page ?? 1, perPage: _args?.perPage ?? 100, hasMore: false };
|
|
73
|
+
}
|
|
74
|
+
async getLogs(_args) {
|
|
75
|
+
return { logs: [], total: 0, page: _args?.page ?? 1, perPage: _args?.perPage ?? 100, hasMore: false };
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var createCustomTransport = (stream, getLogs, getLogsByRunId) => {
|
|
79
|
+
let transport = stream;
|
|
80
|
+
if (getLogs) {
|
|
81
|
+
transport.getLogs = getLogs;
|
|
82
|
+
}
|
|
83
|
+
if (getLogsByRunId) {
|
|
84
|
+
transport.getLogsByRunId = getLogsByRunId;
|
|
85
|
+
}
|
|
86
|
+
return transport;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { LoggerTransport, MultiLogger, createCustomTransport, noopLogger };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/runtime-context/index.ts
|
|
4
|
+
var RuntimeContext = class {
|
|
5
|
+
registry = /* @__PURE__ */ new Map();
|
|
6
|
+
constructor(iterable) {
|
|
7
|
+
this.registry = new Map(iterable);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* set a value with strict typing if `Values` is a Record and the key exists in it.
|
|
11
|
+
*/
|
|
12
|
+
set(key, value) {
|
|
13
|
+
this.registry.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a value with its type
|
|
17
|
+
*/
|
|
18
|
+
get(key) {
|
|
19
|
+
return this.registry.get(key);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if a key exists in the container
|
|
23
|
+
*/
|
|
24
|
+
has(key) {
|
|
25
|
+
return this.registry.has(key);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Delete a value by key
|
|
29
|
+
*/
|
|
30
|
+
delete(key) {
|
|
31
|
+
return this.registry.delete(key);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Clear all values from the container
|
|
35
|
+
*/
|
|
36
|
+
clear() {
|
|
37
|
+
this.registry.clear();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all keys in the container
|
|
41
|
+
*/
|
|
42
|
+
keys() {
|
|
43
|
+
return this.registry.keys();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get all values in the container
|
|
47
|
+
*/
|
|
48
|
+
values() {
|
|
49
|
+
return this.registry.values();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get all entries in the container
|
|
53
|
+
*/
|
|
54
|
+
entries() {
|
|
55
|
+
return this.registry.entries();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the size of the container
|
|
59
|
+
*/
|
|
60
|
+
size() {
|
|
61
|
+
return this.registry.size;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Execute a function for each entry in the container
|
|
65
|
+
*/
|
|
66
|
+
forEach(callbackfn) {
|
|
67
|
+
this.registry.forEach(callbackfn);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
exports.RuntimeContext = RuntimeContext;
|