@mastra/core 0.2.0-alpha.98 → 0.2.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 (84) hide show
  1. package/dist/agent/index.d.ts +6 -8
  2. package/dist/agent/index.js +15 -7
  3. package/dist/{telemetry-oCUM52DG.d.ts → base-BbtPAA6f.d.ts} +50 -8
  4. package/dist/{index-Cwb-5AzX.d.ts → base-Bpb7Dmwe.d.ts} +367 -320
  5. package/dist/base.d.ts +3 -43
  6. package/dist/base.js +3 -3
  7. package/dist/bundler/index.d.ts +3 -4
  8. package/dist/bundler/index.js +4 -4
  9. package/dist/{chunk-MCB4M5W4.js → chunk-22LC46YN.js} +3 -9
  10. package/dist/{chunk-MG3WAQV7.js → chunk-2JL6DQMZ.js} +20 -28
  11. package/dist/chunk-2SAHBQEF.js +3 -0
  12. package/dist/chunk-3HBFW3Q7.js +24 -0
  13. package/dist/{chunk-KNPBNSJ7.js → chunk-55GTEVHJ.js} +12 -13
  14. package/dist/chunk-65VPTVVP.js +218 -0
  15. package/dist/chunk-AWEACB2T.js +66 -0
  16. package/dist/chunk-C6A6W6XS.js +49 -0
  17. package/dist/chunk-FGZVE4CM.js +404 -0
  18. package/dist/{chunk-TYIBRZOY.js → chunk-J3W3IHDO.js} +120 -87
  19. package/dist/chunk-K36NSQWH.js +10 -0
  20. package/dist/{chunk-QXH6EK72.js → chunk-K4DFI76V.js} +382 -370
  21. package/dist/{chunk-42DYOLDV.js → chunk-MEISIZMP.js} +13 -21
  22. package/dist/chunk-MLWGYRJR.js +87 -0
  23. package/dist/{chunk-ICMEXHKD.js → chunk-O2VP5JBC.js} +48 -55
  24. package/dist/{chunk-ZJOMHCWE.js → chunk-OJ26F3J4.js} +98 -153
  25. package/dist/chunk-RG66XEJT.js +8 -0
  26. package/dist/chunk-SB37QG7O.js +1203 -0
  27. package/dist/chunk-SDBM53G4.js +32 -0
  28. package/dist/{chunk-4LJFWC2Q.js → chunk-SIFBBGY6.js} +59 -85
  29. package/dist/chunk-U6J2FOU4.js +624 -0
  30. package/dist/chunk-VB7CO5ND.js +31 -0
  31. package/dist/{chunk-C55JWGDU.js → chunk-ZJOXJFJI.js} +43 -15
  32. package/dist/deployer/index.d.ts +2 -4
  33. package/dist/deployer/index.js +5 -5
  34. package/dist/eval/index.d.ts +8 -13
  35. package/dist/eval/index.js +3 -3
  36. package/dist/filter/index.js +2 -2
  37. package/dist/hooks/index.d.ts +13 -18
  38. package/dist/hooks/index.js +2 -2
  39. package/dist/{index-CBZ2mk2H.d.ts → index-B2JCcAQt.d.ts} +1 -1
  40. package/dist/index.d.ts +15 -15
  41. package/dist/index.js +43 -69
  42. package/dist/integration/index.d.ts +8 -10
  43. package/dist/integration/index.js +6 -3
  44. package/dist/llm/index.d.ts +6 -8
  45. package/dist/llm/index.js +1 -1
  46. package/dist/logger/index.d.ts +1 -1
  47. package/dist/logger/index.js +2 -2
  48. package/dist/mastra/index.d.ts +10 -13
  49. package/dist/mastra/index.js +20 -4
  50. package/dist/memory/index.d.ts +8 -10
  51. package/dist/memory/index.js +11 -9
  52. package/dist/relevance/index.js +16 -8
  53. package/dist/storage/index.d.ts +21 -10
  54. package/dist/storage/index.js +8 -7
  55. package/dist/telemetry/index.d.ts +35 -5
  56. package/dist/telemetry/index.js +3 -2
  57. package/dist/telemetry/otel-vendor.d.ts +7 -0
  58. package/dist/telemetry/otel-vendor.js +8 -0
  59. package/dist/tools/index.d.ts +6 -8
  60. package/dist/tools/index.js +2 -2
  61. package/dist/tts/index.d.ts +2 -4
  62. package/dist/tts/index.js +6 -5
  63. package/dist/{metric-BWeQNZt6.d.ts → types-m9RryK9a.d.ts} +6 -1
  64. package/dist/utils.js +2 -2
  65. package/dist/vector/index.d.ts +4 -6
  66. package/dist/vector/index.js +4 -4
  67. package/dist/vector/libsql/index.d.ts +2 -4
  68. package/dist/vector/libsql/index.js +6 -6
  69. package/dist/{workflow-DTtv7_Eq.d.ts → workflow-Cy8UTGCt.d.ts} +3 -6
  70. package/dist/workflows/index.d.ts +7 -9
  71. package/dist/workflows/index.js +4 -4
  72. package/package.json +14 -10
  73. package/dist/chunk-4ZUSEHLH.js +0 -285
  74. package/dist/chunk-AJJZUHB4.js +0 -14
  75. package/dist/chunk-G4MCO7XF.js +0 -70
  76. package/dist/chunk-HBTQNIAX.js +0 -90
  77. package/dist/chunk-HPXWJBQK.js +0 -222
  78. package/dist/chunk-JJ57BXQR.js +0 -16
  79. package/dist/chunk-JP37ODNX.js +0 -36
  80. package/dist/chunk-K3N7KJHH.js +0 -52
  81. package/dist/chunk-MDM2JS2U.js +0 -1288
  82. package/dist/chunk-VOUPGVRD.js +0 -27
  83. package/dist/chunk-Z7JFMQZZ.js +0 -551
  84. /package/dist/{chunk-AE3H2QEY.js → chunk-VDOJTUYY.js} +0 -0
package/dist/base.d.ts CHANGED
@@ -1,46 +1,6 @@
1
- import * as _opentelemetry_api from '@opentelemetry/api';
2
- import { R as RegisteredLogger, L as Logger, a as LogLevel } from './index-CBZ2mk2H.js';
3
- import { T as Telemetry } from './telemetry-oCUM52DG.js';
1
+ import '@opentelemetry/api';
2
+ import './index-B2JCcAQt.js';
3
+ export { M as MastraBase } from './base-BbtPAA6f.js';
4
4
  import 'pino';
5
5
  import 'stream';
6
- import '@opentelemetry/sdk-node';
7
6
  import '@opentelemetry/sdk-trace-base';
8
-
9
- declare class MastraBase {
10
- component: RegisteredLogger;
11
- protected logger: Logger;
12
- name?: string;
13
- telemetry?: Telemetry;
14
- constructor({ component, name }: {
15
- component?: RegisteredLogger;
16
- name?: string;
17
- });
18
- /**
19
- * Set the logger for the agent
20
- * @param logger
21
- */
22
- __setLogger(logger: Logger): void;
23
- /**
24
- * Internal logging helper that formats and sends logs to the configured logger
25
- * @param level - Severity level of the log
26
- * @param message - Main log message
27
- * @param opts - Optional object for the log
28
- */
29
- log(level: LogLevel, message: string, opts?: Record<string, any>): void;
30
- /**
31
- * Set the telemetry for the
32
- * @param telemetry
33
- */
34
- __setTelemetry(telemetry: Telemetry): void;
35
- /**
36
- * Get the telemetry on the vector
37
- * @returns telemetry
38
- */
39
- __getTelemetry(): Telemetry | undefined;
40
- get experimental_telemetry(): {
41
- tracer: _opentelemetry_api.Tracer;
42
- isEnabled: boolean;
43
- } | undefined;
44
- }
45
-
46
- export { MastraBase };
package/dist/base.js CHANGED
@@ -1,3 +1,3 @@
1
- export { MastraBase } from './chunk-G4MCO7XF.js';
2
- import './chunk-ICMEXHKD.js';
3
- import './chunk-AJJZUHB4.js';
1
+ export { MastraBase } from './chunk-AWEACB2T.js';
2
+ import './chunk-O2VP5JBC.js';
3
+ import './chunk-C6A6W6XS.js';
@@ -1,10 +1,8 @@
1
- import { MastraBase } from '../base.js';
1
+ import { M as MastraBase } from '../base-BbtPAA6f.js';
2
2
  import '@opentelemetry/api';
3
- import '../index-CBZ2mk2H.js';
3
+ import '../index-B2JCcAQt.js';
4
4
  import 'pino';
5
5
  import 'stream';
6
- import '../telemetry-oCUM52DG.js';
7
- import '@opentelemetry/sdk-node';
8
6
  import '@opentelemetry/sdk-trace-base';
9
7
 
10
8
  interface IBundler {
@@ -22,6 +20,7 @@ declare abstract class MastraBundler extends MastraBase implements IBundler {
22
20
  loadEnvVars(): Promise<Map<string, string>>;
23
21
  abstract prepare(outputDirectory: string): Promise<void>;
24
22
  abstract writePackageJson(outputDirectory: string, dependencies: Map<string, string>): Promise<void>;
23
+ abstract writeInstrumentationFile(outputDirectory: string): Promise<void>;
25
24
  abstract getEnvFiles(): Promise<string[]>;
26
25
  abstract bundle(entryFile: string, outputDirectory: string): Promise<void>;
27
26
  }
@@ -1,4 +1,4 @@
1
- export { MastraBundler } from '../chunk-MCB4M5W4.js';
2
- import '../chunk-G4MCO7XF.js';
3
- import '../chunk-ICMEXHKD.js';
4
- import '../chunk-AJJZUHB4.js';
1
+ export { MastraBundler } from '../chunk-22LC46YN.js';
2
+ import '../chunk-AWEACB2T.js';
3
+ import '../chunk-O2VP5JBC.js';
4
+ import '../chunk-C6A6W6XS.js';
@@ -1,14 +1,10 @@
1
- import { MastraBase } from './chunk-G4MCO7XF.js';
2
- import { __name } from './chunk-AJJZUHB4.js';
1
+ import { MastraBase } from './chunk-AWEACB2T.js';
3
2
  import { parse } from 'dotenv';
4
3
  import { readFile } from 'fs/promises';
5
4
 
6
- var _MastraBundler = class _MastraBundler extends MastraBase {
5
+ var MastraBundler = class extends MastraBase {
7
6
  constructor({ name, component = "BUNDLER" }) {
8
- super({
9
- component,
10
- name
11
- });
7
+ super({ component, name });
12
8
  }
13
9
  async loadEnvVars() {
14
10
  const envVars = /* @__PURE__ */ new Map();
@@ -22,7 +18,5 @@ var _MastraBundler = class _MastraBundler extends MastraBase {
22
18
  return envVars;
23
19
  }
24
20
  };
25
- __name(_MastraBundler, "MastraBundler");
26
- var MastraBundler = _MastraBundler;
27
21
 
28
22
  export { MastraBundler };
@@ -1,11 +1,23 @@
1
- import { Agent } from './chunk-QXH6EK72.js';
2
- import { __name, __publicField } from './chunk-AJJZUHB4.js';
1
+ import { Agent } from './chunk-K4DFI76V.js';
3
2
  import { CohereClient } from 'cohere-ai';
3
+ import 'ai';
4
4
 
5
- var _CohereRelevanceScorer = class _CohereRelevanceScorer {
5
+ // src/relevance/relevance-score-provider.ts
6
+ function createSimilarityPrompt(query, text) {
7
+ 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:
8
+
9
+ Query: ${query}
10
+
11
+ Text: ${text}
12
+
13
+ Relevance score (0-1):`;
14
+ }
15
+
16
+ // src/relevance/cohere/index.ts
17
+ var CohereRelevanceScorer = class {
18
+ client;
19
+ model;
6
20
  constructor(model, apiKey) {
7
- __publicField(this, "client");
8
- __publicField(this, "model");
9
21
  this.client = new CohereClient({
10
22
  token: apiKey || process.env.COHERE_API_KEY || ""
11
23
  });
@@ -14,34 +26,16 @@ var _CohereRelevanceScorer = class _CohereRelevanceScorer {
14
26
  async getRelevanceScore(query, text) {
15
27
  const response = await this.client.rerank({
16
28
  query,
17
- documents: [
18
- text
19
- ],
29
+ documents: [text],
20
30
  model: this.model,
21
31
  topN: 1
22
32
  });
23
33
  return response.results[0].relevanceScore;
24
34
  }
25
35
  };
26
- __name(_CohereRelevanceScorer, "CohereRelevanceScorer");
27
- var CohereRelevanceScorer = _CohereRelevanceScorer;
28
-
29
- // src/relevance/relevance-score-provider.ts
30
- function createSimilarityPrompt(query, text) {
31
- 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:
32
-
33
- Query: ${query}
34
-
35
- Text: ${text}
36
-
37
- Relevance score (0-1):`;
38
- }
39
- __name(createSimilarityPrompt, "createSimilarityPrompt");
40
-
41
- // src/relevance/mastra-agent/index.ts
42
- var _MastraAgentRelevanceScorer = class _MastraAgentRelevanceScorer {
36
+ var MastraAgentRelevanceScorer = class {
37
+ agent;
43
38
  constructor(name, model) {
44
- __publicField(this, "agent");
45
39
  this.agent = new Agent({
46
40
  name: `Relevance Scorer ${name}`,
47
41
  instructions: `You are a specialized agent for evaluating the relevance of text to queries.
@@ -63,7 +57,5 @@ Always return just the number, no explanation.`,
63
57
  return parseFloat(response.text);
64
58
  }
65
59
  };
66
- __name(_MastraAgentRelevanceScorer, "MastraAgentRelevanceScorer");
67
- var MastraAgentRelevanceScorer = _MastraAgentRelevanceScorer;
68
60
 
69
61
  export { CohereRelevanceScorer, MastraAgentRelevanceScorer, createSimilarityPrompt };
@@ -0,0 +1,3 @@
1
+ import 'ai';
2
+ import 'json-schema';
3
+ import 'zod';
@@ -0,0 +1,24 @@
1
+ import 'zod';
2
+
3
+ // src/tools/tool.ts
4
+ var Tool = class {
5
+ id;
6
+ description;
7
+ inputSchema;
8
+ outputSchema;
9
+ execute;
10
+ mastra;
11
+ constructor(opts) {
12
+ this.id = opts.id;
13
+ this.description = opts.description;
14
+ this.inputSchema = opts.inputSchema;
15
+ this.outputSchema = opts.outputSchema;
16
+ this.execute = opts.execute;
17
+ this.mastra = opts.mastra;
18
+ }
19
+ };
20
+ function createTool(opts) {
21
+ return new Tool(opts);
22
+ }
23
+
24
+ export { Tool, createTool };
@@ -1,7 +1,7 @@
1
- import { __name } from './chunk-AJJZUHB4.js';
2
1
  import { z } from 'zod';
3
2
 
4
- var delay = /* @__PURE__ */ __name((ms) => new Promise((resolve) => setTimeout(resolve, ms)), "delay");
3
+ // src/utils.ts
4
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
5
5
  function jsonSchemaPropertiesToTSTypes(value) {
6
6
  if (!value.type) {
7
7
  return z.object({});
@@ -29,8 +29,10 @@ Examples: ${value.examples.join(", ")}` : ""));
29
29
  Examples: ${value.examples.join(", ")}` : ""));
30
30
  break;
31
31
  case "object":
32
- zodType = jsonSchemaToModel(value).describe((value.description || "") + (value.examples ? `
33
- Examples: ${value.examples.join(", ")}` : ""));
32
+ zodType = jsonSchemaToModel(value).describe(
33
+ (value.description || "") + (value.examples ? `
34
+ Examples: ${value.examples.join(", ")}` : "")
35
+ );
34
36
  break;
35
37
  case "null":
36
38
  zodType = z.null().describe(value.description || "");
@@ -40,7 +42,6 @@ Examples: ${value.examples.join(", ")}` : ""));
40
42
  }
41
43
  return zodType;
42
44
  }
43
- __name(jsonSchemaPropertiesToTSTypes, "jsonSchemaPropertiesToTSTypes");
44
45
  function jsonSchemaToModel(jsonSchema) {
45
46
  const properties = jsonSchema.properties;
46
47
  const requiredFields = jsonSchema.required || [];
@@ -57,7 +58,10 @@ function jsonSchemaToModel(jsonSchema) {
57
58
  Examples: ${value.examples.join(", ")}` : ""));
58
59
  } else if (value.allOf) {
59
60
  const allOfTypes = value.allOf.map((schema) => jsonSchemaPropertiesToTSTypes(schema));
60
- zodType = z.intersection(allOfTypes[0], allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])).describe((value.description || "") + (value.examples ? `
61
+ zodType = z.intersection(
62
+ allOfTypes[0],
63
+ allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
64
+ ).describe((value.description || "") + (value.examples ? `
61
65
  Examples: ${value.examples.join(", ")}` : ""));
62
66
  } else {
63
67
  if (!value.type) {
@@ -76,11 +80,8 @@ Examples: ${value.examples.join(", ")}` : ""));
76
80
  }
77
81
  return z.object(zodSchema);
78
82
  }
79
- __name(jsonSchemaToModel, "jsonSchemaToModel");
80
83
  function deepMerge(target, source) {
81
- const output = {
82
- ...target
83
- };
84
+ const output = { ...target };
84
85
  if (!source) return output;
85
86
  Object.keys(source).forEach((key) => {
86
87
  const targetValue = output[key];
@@ -95,7 +96,6 @@ function deepMerge(target, source) {
95
96
  });
96
97
  return output;
97
98
  }
98
- __name(deepMerge, "deepMerge");
99
99
  async function* maskStreamTags(stream, tag, options = {}) {
100
100
  const { onStart, onEnd, onMask } = options;
101
101
  const openTag = `<${tag}>`;
@@ -104,7 +104,7 @@ async function* maskStreamTags(stream, tag, options = {}) {
104
104
  let fullContent = "";
105
105
  let isMasking = false;
106
106
  let isBuffering = false;
107
- const startsWith = /* @__PURE__ */ __name((text, pattern) => text.trim().startsWith(pattern.trim()), "startsWith");
107
+ const startsWith = (text, pattern) => text.trim().startsWith(pattern.trim());
108
108
  for await (const chunk of stream) {
109
109
  fullContent += chunk;
110
110
  if (isBuffering) buffer += chunk;
@@ -140,6 +140,5 @@ async function* maskStreamTags(stream, tag, options = {}) {
140
140
  yield chunk;
141
141
  }
142
142
  }
143
- __name(maskStreamTags, "maskStreamTags");
144
143
 
145
144
  export { deepMerge, delay, jsonSchemaPropertiesToTSTypes, jsonSchemaToModel, maskStreamTags };
@@ -0,0 +1,218 @@
1
+ import { DefaultStorage } from './chunk-U6J2FOU4.js';
2
+ import { DefaultVectorDB } from './chunk-OJ26F3J4.js';
3
+ import { defaultEmbedder } from './chunk-ZJOXJFJI.js';
4
+ import { deepMerge } from './chunk-55GTEVHJ.js';
5
+ import { MastraBase } from './chunk-AWEACB2T.js';
6
+
7
+ // src/memory/memory.ts
8
+ var MastraMemory = class extends MastraBase {
9
+ MAX_CONTEXT_TOKENS;
10
+ storage;
11
+ vector;
12
+ embedder;
13
+ threadConfig = {
14
+ lastMessages: 40,
15
+ semanticRecall: true
16
+ };
17
+ constructor(config) {
18
+ super({ component: "MEMORY", name: config.name });
19
+ this.storage = config.storage || new DefaultStorage({
20
+ config: {
21
+ url: "file:memory.db"
22
+ }
23
+ });
24
+ if (config.vector) {
25
+ this.vector = config.vector;
26
+ } else {
27
+ this.vector = new DefaultVectorDB({
28
+ connectionUrl: "file:memory-vector.db"
29
+ // file name needs to be different than default storage or it wont work properly
30
+ });
31
+ }
32
+ if (config.embedder) {
33
+ this.embedder = config.embedder;
34
+ } else {
35
+ this.embedder = defaultEmbedder("bge-small-en-v1.5");
36
+ }
37
+ if (config.options) {
38
+ this.threadConfig = this.getMergedThreadConfig(config.options);
39
+ }
40
+ }
41
+ setStorage(storage) {
42
+ this.storage = storage;
43
+ }
44
+ setVector(vector) {
45
+ this.vector = vector;
46
+ }
47
+ setEmbedder(embedder) {
48
+ this.embedder = embedder;
49
+ }
50
+ /**
51
+ * Get a system message to inject into the conversation.
52
+ * This will be called before each conversation turn.
53
+ * Implementations can override this to inject custom system messages.
54
+ */
55
+ async getSystemMessage(_input) {
56
+ return null;
57
+ }
58
+ async createEmbeddingIndex() {
59
+ const defaultDimensions = 1536;
60
+ const dimensionsByModelId = {
61
+ "bge-small-en-v1.5": 384,
62
+ "bge-base-en-v1.5": 768
63
+ };
64
+ const dimensions = dimensionsByModelId[this.embedder.modelId] || defaultDimensions;
65
+ const isDefault = dimensions === defaultDimensions;
66
+ const indexName = isDefault ? "memory_messages" : `memory_messages_${dimensions}`;
67
+ await this.vector.createIndex(indexName, dimensions);
68
+ return { indexName };
69
+ }
70
+ getMergedThreadConfig(config) {
71
+ return deepMerge(this.threadConfig, config || {});
72
+ }
73
+ estimateTokens(text) {
74
+ return Math.ceil(text.split(" ").length * 1.3);
75
+ }
76
+ parseMessages(messages) {
77
+ return messages.map((msg) => ({
78
+ ...msg,
79
+ content: typeof msg.content === "string" && (msg.content.startsWith("[") || msg.content.startsWith("{")) ? JSON.parse(msg.content) : msg.content
80
+ }));
81
+ }
82
+ convertToUIMessages(messages) {
83
+ function addToolMessageToChat({
84
+ toolMessage,
85
+ messages: messages2,
86
+ toolResultContents
87
+ }) {
88
+ const chatMessages2 = messages2.map((message) => {
89
+ if (message.toolInvocations) {
90
+ return {
91
+ ...message,
92
+ toolInvocations: message.toolInvocations.map((toolInvocation) => {
93
+ const toolResult = toolMessage.content.find((tool) => tool.toolCallId === toolInvocation.toolCallId);
94
+ if (toolResult) {
95
+ return {
96
+ ...toolInvocation,
97
+ state: "result",
98
+ result: toolResult.result
99
+ };
100
+ }
101
+ return toolInvocation;
102
+ })
103
+ };
104
+ }
105
+ return message;
106
+ });
107
+ const resultContents = [...toolResultContents, ...toolMessage.content];
108
+ return { chatMessages: chatMessages2, toolResultContents: resultContents };
109
+ }
110
+ const { chatMessages } = messages.reduce(
111
+ (obj, message) => {
112
+ if (message.role === "tool") {
113
+ return addToolMessageToChat({
114
+ toolMessage: message,
115
+ messages: obj.chatMessages,
116
+ toolResultContents: obj.toolResultContents
117
+ });
118
+ }
119
+ let textContent = "";
120
+ let toolInvocations = [];
121
+ if (typeof message.content === "string") {
122
+ textContent = message.content;
123
+ } else if (Array.isArray(message.content)) {
124
+ for (const content of message.content) {
125
+ if (content.type === "text") {
126
+ textContent += content.text;
127
+ } else if (content.type === "tool-call") {
128
+ const toolResult = obj.toolResultContents.find((tool) => tool.toolCallId === content.toolCallId);
129
+ toolInvocations.push({
130
+ state: toolResult ? "result" : "call",
131
+ toolCallId: content.toolCallId,
132
+ toolName: content.toolName,
133
+ args: content.args,
134
+ result: toolResult?.result
135
+ });
136
+ }
137
+ }
138
+ }
139
+ obj.chatMessages.push({
140
+ id: message.id,
141
+ role: message.role,
142
+ content: textContent,
143
+ toolInvocations
144
+ });
145
+ return obj;
146
+ },
147
+ { chatMessages: [], toolResultContents: [] }
148
+ );
149
+ return chatMessages;
150
+ }
151
+ /**
152
+ * Helper method to create a new thread
153
+ * @param title - Optional title for the thread
154
+ * @param metadata - Optional metadata for the thread
155
+ * @returns Promise resolving to the created thread
156
+ */
157
+ async createThread({
158
+ threadId,
159
+ resourceId,
160
+ title,
161
+ metadata,
162
+ memoryConfig
163
+ }) {
164
+ const thread = {
165
+ id: threadId || this.generateId(),
166
+ title: title || "New Thread",
167
+ resourceId,
168
+ createdAt: /* @__PURE__ */ new Date(),
169
+ updatedAt: /* @__PURE__ */ new Date(),
170
+ metadata
171
+ };
172
+ return this.saveThread({ thread, memoryConfig });
173
+ }
174
+ /**
175
+ * Helper method to add a single message to a thread
176
+ * @param threadId - The thread to add the message to
177
+ * @param content - The message content
178
+ * @param role - The role of the message sender
179
+ * @param type - The type of the message
180
+ * @param toolNames - Optional array of tool names that were called
181
+ * @param toolCallArgs - Optional array of tool call arguments
182
+ * @param toolCallIds - Optional array of tool call ids
183
+ * @returns Promise resolving to the saved message
184
+ */
185
+ async addMessage({
186
+ threadId,
187
+ config,
188
+ content,
189
+ role,
190
+ type,
191
+ toolNames,
192
+ toolCallArgs,
193
+ toolCallIds
194
+ }) {
195
+ const message = {
196
+ id: this.generateId(),
197
+ content,
198
+ role,
199
+ createdAt: /* @__PURE__ */ new Date(),
200
+ threadId,
201
+ type,
202
+ toolNames,
203
+ toolCallArgs,
204
+ toolCallIds
205
+ };
206
+ const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
207
+ return savedMessages[0];
208
+ }
209
+ /**
210
+ * Generates a unique identifier
211
+ * @returns A unique string ID
212
+ */
213
+ generateId() {
214
+ return crypto.randomUUID();
215
+ }
216
+ };
217
+
218
+ export { MastraMemory };
@@ -0,0 +1,66 @@
1
+ import { RegisteredLogger, createLogger } from './chunk-O2VP5JBC.js';
2
+
3
+ // src/base.ts
4
+ var MastraBase = class {
5
+ component = RegisteredLogger.LLM;
6
+ logger;
7
+ name;
8
+ telemetry;
9
+ constructor({ component, name }) {
10
+ this.component = component || RegisteredLogger.LLM;
11
+ this.name = name;
12
+ this.logger = createLogger({ name: `${this.component} - ${this.name}` });
13
+ }
14
+ /**
15
+ * Set the logger for the agent
16
+ * @param logger
17
+ */
18
+ __setLogger(logger) {
19
+ this.logger = logger;
20
+ this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
21
+ }
22
+ /**
23
+ * Internal logging helper that formats and sends logs to the configured logger
24
+ * @param level - Severity level of the log
25
+ * @param message - Main log message
26
+ * @param opts - Optional object for the log
27
+ */
28
+ log(level, message, opts) {
29
+ if (!this.logger) return;
30
+ const logMessage = {
31
+ type: this.component,
32
+ message,
33
+ destinationPath: this.name ? `${this.component}/${this.name}` : this.component,
34
+ ...opts || {}
35
+ };
36
+ const logMethod = level.toLowerCase();
37
+ this.logger[logMethod]?.(logMessage);
38
+ }
39
+ /**
40
+ * Set the telemetry for the
41
+ * @param telemetry
42
+ */
43
+ __setTelemetry(telemetry) {
44
+ this.telemetry = telemetry;
45
+ this.logger.debug(`Telemetry updated [component=${this.component}] [tracer=${this.telemetry.tracer}]`);
46
+ }
47
+ /**
48
+ * Get the telemetry on the vector
49
+ * @returns telemetry
50
+ */
51
+ __getTelemetry() {
52
+ return this.telemetry;
53
+ }
54
+ /*
55
+ get experimental_telemetry config
56
+ */
57
+ get experimental_telemetry() {
58
+ return this.telemetry ? {
59
+ // tracer: this.telemetry.tracer,
60
+ tracer: this.telemetry.getBaggageTracer(),
61
+ isEnabled: !!this.telemetry.tracer
62
+ } : undefined;
63
+ }
64
+ };
65
+
66
+ export { MastraBase };
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
11
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
12
+ var __expectFn = (fn) => fn !== undefined && typeof fn !== "function" ? __typeError("Function expected") : fn;
13
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
14
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
15
+ var __runInitializers = (array, flags, self, value) => {
16
+ 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);
17
+ return value;
18
+ };
19
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
20
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
21
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
22
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
23
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
24
+ return __privateGet(this, extra);
25
+ }, set [name](x) {
26
+ return __privateSet(this, extra, x);
27
+ } }, name));
28
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
29
+ for (var i = decorators.length - 1; i >= 0; i--) {
30
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
31
+ if (k) {
32
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
33
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
34
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
35
+ }
36
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? undefined : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
37
+ if (k ^ 4 || it === undefined) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
38
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
39
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
40
+ }
41
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
42
+ };
43
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
44
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
45
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
46
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
47
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
48
+
49
+ export { __decorateElement, __decoratorStart, __runInitializers };