@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.
Files changed (235) hide show
  1. package/a2a.d.ts +1 -0
  2. package/agent.d.ts +1 -0
  3. package/base.d.ts +1 -0
  4. package/bundler.d.ts +1 -0
  5. package/deployer.d.ts +1 -0
  6. package/di.d.ts +1 -0
  7. package/dist/a2a/index.cjs +79 -0
  8. package/dist/a2a/index.d.cts +780 -0
  9. package/dist/a2a/index.d.ts +780 -0
  10. package/dist/a2a/index.js +68 -0
  11. package/dist/agent/index.cjs +15 -0
  12. package/dist/agent/index.d.cts +29 -0
  13. package/dist/agent/index.d.ts +29 -0
  14. package/dist/agent/index.js +2 -0
  15. package/dist/base-B_y9sMg0.d.cts +162 -0
  16. package/dist/base-CTj7ESwt.d.cts +4132 -0
  17. package/dist/base-ClrXcCRx.d.ts +162 -0
  18. package/dist/base-qVqAnB-c.d.ts +4132 -0
  19. package/dist/base.cjs +10 -0
  20. package/dist/base.d.cts +6 -0
  21. package/dist/base.d.ts +6 -0
  22. package/dist/base.js +1 -0
  23. package/dist/bundler/index.cjs +10 -0
  24. package/dist/bundler/index.d.cts +30 -0
  25. package/dist/bundler/index.d.ts +30 -0
  26. package/dist/bundler/index.js +1 -0
  27. package/dist/chunk-32C7JDIZ.js +1 -0
  28. package/dist/chunk-4UWPFBC6.js +88 -0
  29. package/dist/chunk-4Z3OU5RY.cjs +31 -0
  30. package/dist/chunk-5HTMDAXP.js +359 -0
  31. package/dist/chunk-5IEKR756.js +53 -0
  32. package/dist/chunk-5YDTZN2X.js +114 -0
  33. package/dist/chunk-6UNGH46J.js +75 -0
  34. package/dist/chunk-6Y4UL5Z6.cjs +94 -0
  35. package/dist/chunk-7H2GET5Z.cjs +668 -0
  36. package/dist/chunk-7HZ6NIAF.cjs +2 -0
  37. package/dist/chunk-7XQIPES3.js +668 -0
  38. package/dist/chunk-AKYTYALY.js +70 -0
  39. package/dist/chunk-AOWJUV2N.js +2415 -0
  40. package/dist/chunk-ATXBSEFT.js +22 -0
  41. package/dist/chunk-B6TOBUS6.cjs +80 -0
  42. package/dist/chunk-B7SQOKEC.cjs +91 -0
  43. package/dist/chunk-BB4KXGBU.js +83 -0
  44. package/dist/chunk-BB6DPGIV.cjs +6 -0
  45. package/dist/chunk-BVD7NVAR.cjs +244 -0
  46. package/dist/chunk-C4LMN2IR.js +27 -0
  47. package/dist/chunk-DR4JS662.js +989 -0
  48. package/dist/chunk-F2WMR75C.cjs +183 -0
  49. package/dist/chunk-FEYYOBBG.cjs +24 -0
  50. package/dist/chunk-FL5SZ2XU.js +181 -0
  51. package/dist/chunk-GH2KM66J.js +37 -0
  52. package/dist/chunk-GWFS5DAR.cjs +37 -0
  53. package/dist/chunk-HNEE7IF4.js +60 -0
  54. package/dist/chunk-HSVOEWAM.cjs +2 -0
  55. package/dist/chunk-IBKM5CLQ.js +428 -0
  56. package/dist/chunk-ID5LG5CQ.cjs +659 -0
  57. package/dist/chunk-J52TXHZV.cjs +73 -0
  58. package/dist/chunk-J62R4M7K.js +240 -0
  59. package/dist/chunk-JNMQKJH4.js +10 -0
  60. package/dist/chunk-JQOMTERC.js +89 -0
  61. package/dist/chunk-LABUWBKX.cjs +71 -0
  62. package/dist/chunk-LBUQ6YNU.cjs +447 -0
  63. package/dist/chunk-LXFZUKP3.cjs +34 -0
  64. package/dist/chunk-MP2QBLUJ.cjs +70 -0
  65. package/dist/chunk-MUNFCOMB.cjs +62 -0
  66. package/dist/chunk-MVCHTRVB.js +5038 -0
  67. package/dist/chunk-NH5WJNNS.js +1 -0
  68. package/dist/chunk-P3Q73CAW.cjs +55 -0
  69. package/dist/chunk-Q33INUG2.cjs +81 -0
  70. package/dist/chunk-QFTBW7ZZ.cjs +2 -0
  71. package/dist/chunk-QQ5K5TZE.cjs +619 -0
  72. package/dist/chunk-R4V75T7J.js +1 -0
  73. package/dist/chunk-RVFWMGGR.js +77 -0
  74. package/dist/chunk-SGGPJWRQ.js +69 -0
  75. package/dist/chunk-ST5RMVLG.cjs +87 -0
  76. package/dist/chunk-TC2SCOTE.js +605 -0
  77. package/dist/chunk-TTMYHBQM.js +657 -0
  78. package/dist/chunk-U64IJDC5.cjs +109 -0
  79. package/dist/chunk-ULZ6MRTN.cjs +5065 -0
  80. package/dist/chunk-V5D2LIF5.js +68 -0
  81. package/dist/chunk-WQNOATKB.js +103 -0
  82. package/dist/chunk-Y7D2JLKS.js +4 -0
  83. package/dist/chunk-YOQP5T77.js +32 -0
  84. package/dist/chunk-ZCU3PLIL.cjs +2429 -0
  85. package/dist/chunk-ZIZ3CVHN.cjs +120 -0
  86. package/dist/chunk-ZPOUMTTH.cjs +362 -0
  87. package/dist/chunk-ZTPPDHQK.cjs +991 -0
  88. package/dist/chunk-ZZLBNB3U.cjs +12 -0
  89. package/dist/deployer/index.cjs +10 -0
  90. package/dist/deployer/index.d.cts +19 -0
  91. package/dist/deployer/index.d.ts +19 -0
  92. package/dist/deployer/index.js +1 -0
  93. package/dist/di/index.cjs +10 -0
  94. package/dist/di/index.d.cts +1 -0
  95. package/dist/di/index.d.ts +1 -0
  96. package/dist/di/index.js +1 -0
  97. package/dist/error/index.cjs +22 -0
  98. package/dist/error/index.d.cts +86 -0
  99. package/dist/error/index.d.ts +86 -0
  100. package/dist/error/index.js +1 -0
  101. package/dist/eval/index.cjs +14 -0
  102. package/dist/eval/index.d.cts +43 -0
  103. package/dist/eval/index.d.ts +43 -0
  104. package/dist/eval/index.js +1 -0
  105. package/dist/hooks/index.cjs +18 -0
  106. package/dist/hooks/index.d.cts +33 -0
  107. package/dist/hooks/index.d.ts +33 -0
  108. package/dist/hooks/index.js +1 -0
  109. package/dist/index.cjs +285 -0
  110. package/dist/index.d.cts +92 -0
  111. package/dist/index.d.ts +92 -0
  112. package/dist/index.js +112 -0
  113. package/dist/integration/index.cjs +14 -0
  114. package/dist/integration/index.d.cts +65 -0
  115. package/dist/integration/index.d.ts +65 -0
  116. package/dist/integration/index.js +1 -0
  117. package/dist/llm/index.cjs +10 -0
  118. package/dist/llm/index.d.cts +29 -0
  119. package/dist/llm/index.d.ts +29 -0
  120. package/dist/llm/index.js +1 -0
  121. package/dist/logger/index.cjs +43 -0
  122. package/dist/logger/index.d.cts +96 -0
  123. package/dist/logger/index.d.ts +96 -0
  124. package/dist/logger/index.js +2 -0
  125. package/dist/logger-B8XXh6ya.d.cts +159 -0
  126. package/dist/logger-Bpa2oLL4.d.ts +159 -0
  127. package/dist/mastra/index.cjs +10 -0
  128. package/dist/mastra/index.d.cts +29 -0
  129. package/dist/mastra/index.d.ts +29 -0
  130. package/dist/mastra/index.js +1 -0
  131. package/dist/mcp/index.cjs +106 -0
  132. package/dist/mcp/index.d.cts +29 -0
  133. package/dist/mcp/index.d.ts +29 -0
  134. package/dist/mcp/index.js +100 -0
  135. package/dist/memory/index.cjs +18 -0
  136. package/dist/memory/index.d.cts +29 -0
  137. package/dist/memory/index.d.ts +29 -0
  138. package/dist/memory/index.js +1 -0
  139. package/dist/network/index.cjs +311 -0
  140. package/dist/network/index.d.cts +29 -0
  141. package/dist/network/index.d.ts +29 -0
  142. package/dist/network/index.js +309 -0
  143. package/dist/network/vNext/index.cjs +880 -0
  144. package/dist/network/vNext/index.d.cts +29 -0
  145. package/dist/network/vNext/index.d.ts +29 -0
  146. package/dist/network/vNext/index.js +878 -0
  147. package/dist/relevance/index.cjs +18 -0
  148. package/dist/relevance/index.d.cts +50 -0
  149. package/dist/relevance/index.d.ts +50 -0
  150. package/dist/relevance/index.js +1 -0
  151. package/dist/runtime-context/index.cjs +10 -0
  152. package/dist/runtime-context/index.d.cts +52 -0
  153. package/dist/runtime-context/index.d.ts +52 -0
  154. package/dist/runtime-context/index.js +1 -0
  155. package/dist/server/index.cjs +62 -0
  156. package/dist/server/index.d.cts +52 -0
  157. package/dist/server/index.d.ts +52 -0
  158. package/dist/server/index.js +59 -0
  159. package/dist/storage/index.cjs +336 -0
  160. package/dist/storage/index.d.cts +149 -0
  161. package/dist/storage/index.d.ts +149 -0
  162. package/dist/storage/index.js +303 -0
  163. package/dist/telemetry/index.cjs +30 -0
  164. package/dist/telemetry/index.d.cts +75 -0
  165. package/dist/telemetry/index.d.ts +75 -0
  166. package/dist/telemetry/index.js +1 -0
  167. package/dist/telemetry/otel-vendor.cjs +103 -0
  168. package/dist/telemetry/otel-vendor.d.cts +20 -0
  169. package/dist/telemetry/otel-vendor.d.ts +20 -0
  170. package/dist/telemetry/otel-vendor.js +57 -0
  171. package/dist/tools/index.cjs +18 -0
  172. package/dist/tools/index.d.cts +41 -0
  173. package/dist/tools/index.d.ts +41 -0
  174. package/dist/tools/index.js +1 -0
  175. package/dist/tts/index.cjs +10 -0
  176. package/dist/tts/index.d.cts +28 -0
  177. package/dist/tts/index.d.ts +28 -0
  178. package/dist/tts/index.js +1 -0
  179. package/dist/types-Bo1uigWx.d.cts +17 -0
  180. package/dist/types-Bo1uigWx.d.ts +17 -0
  181. package/dist/utils.cjs +62 -0
  182. package/dist/utils.d.cts +150 -0
  183. package/dist/utils.d.ts +150 -0
  184. package/dist/utils.js +1 -0
  185. package/dist/vector/filter/index.cjs +192 -0
  186. package/dist/vector/filter/index.d.cts +128 -0
  187. package/dist/vector/filter/index.d.ts +128 -0
  188. package/dist/vector/filter/index.js +190 -0
  189. package/dist/vector/index.cjs +10 -0
  190. package/dist/vector/index.d.cts +77 -0
  191. package/dist/vector/index.d.ts +77 -0
  192. package/dist/vector/index.js +1 -0
  193. package/dist/voice/index.cjs +18 -0
  194. package/dist/voice/index.d.cts +29 -0
  195. package/dist/voice/index.d.ts +29 -0
  196. package/dist/voice/index.js +1 -0
  197. package/dist/workflows/constants.cjs +10 -0
  198. package/dist/workflows/constants.d.cts +3 -0
  199. package/dist/workflows/constants.d.ts +3 -0
  200. package/dist/workflows/constants.js +1 -0
  201. package/dist/workflows/index.cjs +42 -0
  202. package/dist/workflows/index.d.cts +285 -0
  203. package/dist/workflows/index.d.ts +285 -0
  204. package/dist/workflows/index.js +1 -0
  205. package/dist/workflows/legacy/index.cjs +90 -0
  206. package/dist/workflows/legacy/index.d.cts +91 -0
  207. package/dist/workflows/legacy/index.d.ts +91 -0
  208. package/dist/workflows/legacy/index.js +1 -0
  209. package/error.d.ts +1 -0
  210. package/eval.d.ts +1 -0
  211. package/hooks.d.ts +1 -0
  212. package/integration.d.ts +1 -0
  213. package/llm.d.ts +1 -0
  214. package/logger.d.ts +1 -0
  215. package/mastra.d.ts +1 -0
  216. package/mcp.d.ts +1 -0
  217. package/memory.d.ts +1 -0
  218. package/network/vNext.d.ts +1 -0
  219. package/network.d.ts +1 -0
  220. package/package.json +2 -3
  221. package/relevance.d.ts +1 -0
  222. package/runtime-context.d.ts +1 -0
  223. package/server.d.ts +1 -0
  224. package/storage.d.ts +1 -0
  225. package/telemetry/otel-vendor.d.ts +1 -0
  226. package/telemetry.d.ts +1 -0
  227. package/tools.d.ts +1 -0
  228. package/tts.d.ts +1 -0
  229. package/utils.d.ts +1 -0
  230. package/vector/filter.d.ts +1 -0
  231. package/vector.d.ts +1 -0
  232. package/voice.d.ts +1 -0
  233. package/workflows/_constants.d.ts +1 -0
  234. package/workflows/legacy.d.ts +1 -0
  235. package/workflows.d.ts +1 -0
@@ -0,0 +1,22 @@
1
+ import { MastraBase } from './chunk-5IEKR756.js';
2
+ import { readFile } from 'fs/promises';
3
+ import { parse } from 'dotenv';
4
+
5
+ var MastraBundler = class extends MastraBase {
6
+ constructor({ name, component = "BUNDLER" }) {
7
+ super({ component, name });
8
+ }
9
+ async loadEnvVars() {
10
+ const envVars = /* @__PURE__ */ new Map();
11
+ for (const file of await this.getEnvFiles()) {
12
+ const content = await readFile(file, "utf-8");
13
+ const config = parse(content);
14
+ Object.entries(config).forEach(([key, value]) => {
15
+ envVars.set(key, value);
16
+ });
17
+ }
18
+ return envVars;
19
+ }
20
+ };
21
+
22
+ export { MastraBundler };
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ // src/error/index.ts
4
+ var ErrorDomain = /* @__PURE__ */ ((ErrorDomain2) => {
5
+ ErrorDomain2["TOOL"] = "TOOL";
6
+ ErrorDomain2["AGENT"] = "AGENT";
7
+ ErrorDomain2["MCP"] = "MCP";
8
+ ErrorDomain2["AGENT_NETWORK"] = "AGENT_NETWORK";
9
+ ErrorDomain2["MASTRA_SERVER"] = "MASTRA_SERVER";
10
+ ErrorDomain2["MASTRA_TELEMETRY"] = "MASTRA_TELEMETRY";
11
+ ErrorDomain2["MASTRA_WORKFLOW"] = "MASTRA_WORKFLOW";
12
+ ErrorDomain2["MASTRA_VOICE"] = "MASTRA_VOICE";
13
+ ErrorDomain2["MASTRA_VECTOR"] = "MASTRA_VECTOR";
14
+ ErrorDomain2["LLM"] = "LLM";
15
+ ErrorDomain2["EVAL"] = "EVAL";
16
+ ErrorDomain2["A2A"] = "A2A";
17
+ ErrorDomain2["MASTRA_INSTANCE"] = "MASTRA_INSTANCE";
18
+ ErrorDomain2["MASTRA"] = "MASTRA";
19
+ ErrorDomain2["DEPLOYER"] = "DEPLOYER";
20
+ ErrorDomain2["STORAGE"] = "STORAGE";
21
+ return ErrorDomain2;
22
+ })(ErrorDomain || {});
23
+ var ErrorCategory = /* @__PURE__ */ ((ErrorCategory2) => {
24
+ ErrorCategory2["UNKNOWN"] = "UNKNOWN";
25
+ ErrorCategory2["USER"] = "USER";
26
+ ErrorCategory2["SYSTEM"] = "SYSTEM";
27
+ ErrorCategory2["THIRD_PARTY"] = "THIRD_PARTY";
28
+ return ErrorCategory2;
29
+ })(ErrorCategory || {});
30
+ var MastraBaseError = class extends Error {
31
+ id;
32
+ domain;
33
+ category;
34
+ details = {};
35
+ message;
36
+ constructor(errorDefinition, originalError) {
37
+ let error;
38
+ if (originalError instanceof Error) {
39
+ error = originalError;
40
+ } else if (originalError) {
41
+ error = new Error(String(originalError));
42
+ }
43
+ const message = errorDefinition.text ?? error?.message ?? "Unknown error";
44
+ super(message, { cause: error });
45
+ this.id = errorDefinition.id;
46
+ this.domain = errorDefinition.domain;
47
+ this.category = errorDefinition.category;
48
+ this.details = errorDefinition.details ?? {};
49
+ this.message = message;
50
+ Object.setPrototypeOf(this, new.target.prototype);
51
+ }
52
+ /**
53
+ * Returns a structured representation of the error, useful for logging or API responses.
54
+ */
55
+ toJSONDetails() {
56
+ return {
57
+ message: this.message,
58
+ domain: this.domain,
59
+ category: this.category,
60
+ details: this.details
61
+ };
62
+ }
63
+ toJSON() {
64
+ return {
65
+ message: this.message,
66
+ details: this.toJSONDetails(),
67
+ code: this.id
68
+ };
69
+ }
70
+ toString() {
71
+ return JSON.stringify(this.toJSON());
72
+ }
73
+ };
74
+ var MastraError = class extends MastraBaseError {
75
+ };
76
+
77
+ exports.ErrorCategory = ErrorCategory;
78
+ exports.ErrorDomain = ErrorDomain;
79
+ exports.MastraBaseError = MastraBaseError;
80
+ exports.MastraError = MastraError;
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ var chunk4Z3OU5RY_cjs = require('./chunk-4Z3OU5RY.cjs');
4
+ var zod = require('zod');
5
+
6
+ // src/integration/integration.ts
7
+ var Integration = class {
8
+ name = "Integration";
9
+ workflows;
10
+ constructor() {
11
+ this.workflows = {};
12
+ }
13
+ /**
14
+ * Workflows
15
+ */
16
+ registerWorkflow(name, fn) {
17
+ if (this.workflows[name]) {
18
+ throw new Error(`Sync function "${name}" already registered`);
19
+ }
20
+ this.workflows[name] = fn;
21
+ }
22
+ getWorkflows({ serialized }) {
23
+ if (serialized) {
24
+ return Object.entries(this.workflows).reduce((acc, [k, v]) => {
25
+ return {
26
+ ...acc,
27
+ [k]: {
28
+ name: v.name
29
+ }
30
+ };
31
+ }, {});
32
+ }
33
+ return this.workflows;
34
+ }
35
+ /**
36
+ * TOOLS
37
+ */
38
+ getStaticTools(_params) {
39
+ throw new Error("Method not implemented.");
40
+ }
41
+ async getTools(_params) {
42
+ throw new Error("Method not implemented.");
43
+ }
44
+ async getApiClient() {
45
+ throw new Error("Method not implemented");
46
+ }
47
+ };
48
+ var OpenAPIToolset = class {
49
+ authType = "API_KEY";
50
+ constructor() {
51
+ }
52
+ get toolSchemas() {
53
+ return {};
54
+ }
55
+ get toolDocumentations() {
56
+ return {};
57
+ }
58
+ get baseClient() {
59
+ return {};
60
+ }
61
+ async getApiClient() {
62
+ throw new Error("API not implemented");
63
+ }
64
+ _generateIntegrationTools() {
65
+ const { client: _client, ...clientMethods } = this.baseClient;
66
+ const schemas = this.toolSchemas;
67
+ const documentations = this.toolDocumentations;
68
+ const tools = Object.keys(clientMethods).reduce((acc, key) => {
69
+ const comment = documentations[key]?.comment;
70
+ const fallbackComment = `Execute ${key}`;
71
+ const tool = chunk4Z3OU5RY_cjs.createTool({
72
+ id: key,
73
+ inputSchema: schemas[key] || zod.z.object({}),
74
+ description: comment || fallbackComment,
75
+ // documentation: doc || fallbackComment,
76
+ execute: async ({ context }) => {
77
+ const client = await this.getApiClient();
78
+ const value = client[key];
79
+ return value({
80
+ ...context
81
+ });
82
+ }
83
+ });
84
+ return { ...acc, [key]: tool };
85
+ }, {});
86
+ return tools;
87
+ }
88
+ };
89
+
90
+ exports.Integration = Integration;
91
+ exports.OpenAPIToolset = OpenAPIToolset;
@@ -0,0 +1,83 @@
1
+ // src/hooks/mitt.ts
2
+ function mitt(all) {
3
+ all = all || /* @__PURE__ */ new Map();
4
+ return {
5
+ /**
6
+ * A Map of event names to registered handler functions.
7
+ */
8
+ all,
9
+ /**
10
+ * Register an event handler for the given type.
11
+ * @param {string|symbol} type Type of event to listen for, or `'*'` for all events
12
+ * @param {Function} handler Function to call in response to given event
13
+ * @memberOf mitt
14
+ */
15
+ on(type, handler) {
16
+ const handlers = all.get(type);
17
+ if (handlers) {
18
+ handlers.push(handler);
19
+ } else {
20
+ all.set(type, [handler]);
21
+ }
22
+ },
23
+ /**
24
+ * Remove an event handler for the given type.
25
+ * If `handler` is omitted, all handlers of the given type are removed.
26
+ * @param {string|symbol} type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)
27
+ * @param {Function} [handler] Handler function to remove
28
+ * @memberOf mitt
29
+ */
30
+ off(type, handler) {
31
+ const handlers = all.get(type);
32
+ if (handlers) {
33
+ if (handler) {
34
+ handlers.splice(handlers.indexOf(handler) >>> 0, 1);
35
+ } else {
36
+ all.set(type, []);
37
+ }
38
+ }
39
+ },
40
+ /**
41
+ * Invoke all handlers for the given type.
42
+ * If present, `'*'` handlers are invoked after type-matched handlers.
43
+ *
44
+ * Note: Manually firing '*' handlers is not supported.
45
+ *
46
+ * @param {string|symbol} type The event type to invoke
47
+ * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
48
+ * @memberOf mitt
49
+ */
50
+ emit(type, evt) {
51
+ let handlers = all.get(type);
52
+ if (handlers) {
53
+ handlers.slice().map((handler) => {
54
+ handler(evt);
55
+ });
56
+ }
57
+ handlers = all.get("*");
58
+ if (handlers) {
59
+ handlers.slice().map((handler) => {
60
+ handler(type, evt);
61
+ });
62
+ }
63
+ }
64
+ };
65
+ }
66
+
67
+ // src/hooks/index.ts
68
+ var AvailableHooks = /* @__PURE__ */ ((AvailableHooks2) => {
69
+ AvailableHooks2["ON_EVALUATION"] = "onEvaluation";
70
+ AvailableHooks2["ON_GENERATION"] = "onGeneration";
71
+ return AvailableHooks2;
72
+ })(AvailableHooks || {});
73
+ var hooks = mitt();
74
+ function registerHook(hook, action) {
75
+ hooks.on(hook, action);
76
+ }
77
+ function executeHook(hook, data) {
78
+ setImmediate(() => {
79
+ hooks.emit(hook, data);
80
+ });
81
+ }
82
+
83
+ export { AvailableHooks, executeHook, registerHook };
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ // src/workflows/constants.ts
4
+ var EMITTER_SYMBOL = Symbol("emitter");
5
+
6
+ exports.EMITTER_SYMBOL = EMITTER_SYMBOL;
@@ -0,0 +1,244 @@
1
+ 'use strict';
2
+
3
+ var chunkLXFZUKP3_cjs = require('./chunk-LXFZUKP3.cjs');
4
+ var chunkZTPPDHQK_cjs = require('./chunk-ZTPPDHQK.cjs');
5
+ var chunkLBUQ6YNU_cjs = require('./chunk-LBUQ6YNU.cjs');
6
+ var chunkP3Q73CAW_cjs = require('./chunk-P3Q73CAW.cjs');
7
+
8
+ // src/memory/memory.ts
9
+ var MemoryProcessor = class extends chunkP3Q73CAW_cjs.MastraBase {
10
+ /**
11
+ * Process a list of messages and return a filtered or transformed list.
12
+ * @param messages The messages to process
13
+ * @returns The processed messages
14
+ */
15
+ process(messages, _opts) {
16
+ return messages;
17
+ }
18
+ };
19
+ var memoryDefaultOptions = {
20
+ lastMessages: 10,
21
+ semanticRecall: false,
22
+ threads: {
23
+ generateTitle: false
24
+ },
25
+ workingMemory: {
26
+ enabled: false,
27
+ template: `
28
+ # User Information
29
+ - **First Name**:
30
+ - **Last Name**:
31
+ - **Location**:
32
+ - **Occupation**:
33
+ - **Interests**:
34
+ - **Goals**:
35
+ - **Events**:
36
+ - **Facts**:
37
+ - **Projects**:
38
+ `
39
+ }
40
+ };
41
+ var MastraMemory = class extends chunkP3Q73CAW_cjs.MastraBase {
42
+ MAX_CONTEXT_TOKENS;
43
+ _storage;
44
+ vector;
45
+ embedder;
46
+ processors = [];
47
+ threadConfig = { ...memoryDefaultOptions };
48
+ constructor(config) {
49
+ super({ component: "MEMORY", name: config.name });
50
+ if (config.options) this.threadConfig = this.getMergedThreadConfig(config.options);
51
+ if (config.processors) this.processors = config.processors;
52
+ if (config.storage) {
53
+ this._storage = chunkLXFZUKP3_cjs.augmentWithInit(config.storage);
54
+ this._hasOwnStorage = true;
55
+ }
56
+ if (this.threadConfig.semanticRecall) {
57
+ if (!config.vector) {
58
+ throw new Error(
59
+ `Semantic recall requires a vector store to be configured.
60
+
61
+ https://mastra.ai/en/docs/memory/semantic-recall`
62
+ );
63
+ }
64
+ this.vector = config.vector;
65
+ if (!config.embedder) {
66
+ throw new Error(
67
+ `Semantic recall requires an embedder to be configured.
68
+
69
+ https://mastra.ai/en/docs/memory/semantic-recall`
70
+ );
71
+ }
72
+ this.embedder = config.embedder;
73
+ }
74
+ }
75
+ _hasOwnStorage = false;
76
+ get hasOwnStorage() {
77
+ return this._hasOwnStorage;
78
+ }
79
+ get storage() {
80
+ if (!this._storage) {
81
+ throw new Error(
82
+ `Memory requires a storage provider to function. Add a storage configuration to Memory or to your Mastra instance.
83
+
84
+ https://mastra.ai/en/docs/memory/overview`
85
+ );
86
+ }
87
+ return this._storage;
88
+ }
89
+ setStorage(storage) {
90
+ this._storage = chunkLXFZUKP3_cjs.augmentWithInit(storage);
91
+ }
92
+ setVector(vector) {
93
+ this.vector = vector;
94
+ }
95
+ setEmbedder(embedder) {
96
+ this.embedder = embedder;
97
+ }
98
+ /**
99
+ * Get a system message to inject into the conversation.
100
+ * This will be called before each conversation turn.
101
+ * Implementations can override this to inject custom system messages.
102
+ */
103
+ async getSystemMessage(_input) {
104
+ return null;
105
+ }
106
+ /**
107
+ * Get tools that should be available to the agent.
108
+ * This will be called when converting tools for the agent.
109
+ * Implementations can override this to provide additional tools.
110
+ */
111
+ getTools(_config) {
112
+ return {};
113
+ }
114
+ async createEmbeddingIndex(dimensions) {
115
+ const defaultDimensions = 1536;
116
+ const isDefault = dimensions === defaultDimensions;
117
+ const usedDimensions = dimensions ?? defaultDimensions;
118
+ const separator = this.vector?.indexSeparator ?? "_";
119
+ const indexName = isDefault ? `memory${separator}messages` : `memory${separator}messages${separator}${usedDimensions}`;
120
+ if (typeof this.vector === `undefined`) {
121
+ throw new Error(`Tried to create embedding index but no vector db is attached to this Memory instance.`);
122
+ }
123
+ await this.vector.createIndex({
124
+ indexName,
125
+ dimension: usedDimensions
126
+ });
127
+ return { indexName };
128
+ }
129
+ getMergedThreadConfig(config) {
130
+ if (config?.workingMemory && "use" in config.workingMemory) {
131
+ throw new Error("The workingMemory.use option has been removed. Working memory always uses tool-call mode.");
132
+ }
133
+ const mergedConfig = chunkLBUQ6YNU_cjs.deepMerge(this.threadConfig, config || {});
134
+ if (config?.workingMemory?.schema) {
135
+ if (mergedConfig.workingMemory) {
136
+ mergedConfig.workingMemory.schema = config.workingMemory.schema;
137
+ }
138
+ }
139
+ return mergedConfig;
140
+ }
141
+ /**
142
+ * Apply all configured message processors to a list of messages.
143
+ * @param messages The messages to process
144
+ * @returns The processed messages
145
+ */
146
+ applyProcessors(messages, opts) {
147
+ const processors = opts.processors || this.processors;
148
+ if (!processors || processors.length === 0) {
149
+ return messages;
150
+ }
151
+ let processedMessages = [...messages];
152
+ for (const processor of processors) {
153
+ processedMessages = processor.process(processedMessages, {
154
+ systemMessage: opts.systemMessage,
155
+ newMessages: opts.newMessages,
156
+ memorySystemMessage: opts.memorySystemMessage
157
+ });
158
+ }
159
+ return processedMessages;
160
+ }
161
+ processMessages({
162
+ messages,
163
+ processors,
164
+ ...opts
165
+ }) {
166
+ return this.applyProcessors(messages, { processors: processors || this.processors, ...opts });
167
+ }
168
+ estimateTokens(text) {
169
+ return Math.ceil(text.split(" ").length * 1.3);
170
+ }
171
+ /**
172
+ * Helper method to create a new thread
173
+ * @param title - Optional title for the thread
174
+ * @param metadata - Optional metadata for the thread
175
+ * @returns Promise resolving to the created thread
176
+ */
177
+ async createThread({
178
+ threadId,
179
+ resourceId,
180
+ title,
181
+ metadata,
182
+ memoryConfig
183
+ }) {
184
+ const thread = {
185
+ id: threadId || this.generateId(),
186
+ title: title || `New Thread ${(/* @__PURE__ */ new Date()).toISOString()}`,
187
+ resourceId,
188
+ createdAt: /* @__PURE__ */ new Date(),
189
+ updatedAt: /* @__PURE__ */ new Date(),
190
+ metadata
191
+ };
192
+ return this.saveThread({ thread, memoryConfig });
193
+ }
194
+ /**
195
+ * Helper method to add a single message to a thread
196
+ * @param threadId - The thread to add the message to
197
+ * @param content - The message content
198
+ * @param role - The role of the message sender
199
+ * @param type - The type of the message
200
+ * @param toolNames - Optional array of tool names that were called
201
+ * @param toolCallArgs - Optional array of tool call arguments
202
+ * @param toolCallIds - Optional array of tool call ids
203
+ * @returns Promise resolving to the saved message
204
+ * @deprecated use saveMessages instead
205
+ */
206
+ async addMessage({
207
+ threadId,
208
+ resourceId,
209
+ config,
210
+ content,
211
+ role,
212
+ type,
213
+ toolNames,
214
+ toolCallArgs,
215
+ toolCallIds
216
+ }) {
217
+ const message = {
218
+ id: this.generateId(),
219
+ content,
220
+ role,
221
+ createdAt: /* @__PURE__ */ new Date(),
222
+ threadId,
223
+ resourceId,
224
+ type,
225
+ toolNames,
226
+ toolCallArgs,
227
+ toolCallIds
228
+ };
229
+ const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
230
+ const list = new chunkZTPPDHQK_cjs.MessageList({ threadId, resourceId }).add(savedMessages[0], "memory");
231
+ return list.get.all.v1()[0];
232
+ }
233
+ /**
234
+ * Generates a unique identifier
235
+ * @returns A unique string ID
236
+ */
237
+ generateId() {
238
+ return crypto.randomUUID();
239
+ }
240
+ };
241
+
242
+ exports.MastraMemory = MastraMemory;
243
+ exports.MemoryProcessor = MemoryProcessor;
244
+ exports.memoryDefaultOptions = memoryDefaultOptions;
@@ -0,0 +1,27 @@
1
+ // src/tools/tool.ts
2
+ var Tool = class {
3
+ id;
4
+ description;
5
+ inputSchema;
6
+ outputSchema;
7
+ execute;
8
+ mastra;
9
+ constructor(opts) {
10
+ this.id = opts.id;
11
+ this.description = opts.description;
12
+ this.inputSchema = opts.inputSchema;
13
+ this.outputSchema = opts.outputSchema;
14
+ this.execute = opts.execute;
15
+ this.mastra = opts.mastra;
16
+ }
17
+ };
18
+ function createTool(opts) {
19
+ return new Tool(opts);
20
+ }
21
+
22
+ // src/tools/toolchecks.ts
23
+ function isVercelTool(tool) {
24
+ return !!(tool && !(tool instanceof Tool) && "parameters" in tool);
25
+ }
26
+
27
+ export { Tool, createTool, isVercelTool };