@mastra/core 0.7.0 → 0.8.0-alpha.2

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 (149) hide show
  1. package/README.md +76 -74
  2. package/dist/agent/index.cjs +2 -2
  3. package/dist/agent/index.d.cts +5 -3
  4. package/dist/agent/index.d.ts +5 -3
  5. package/dist/agent/index.js +1 -1
  6. package/dist/{base-Cmunaaxb.d.ts → base-BA_in99t.d.ts} +4 -1
  7. package/dist/{base-Cyl73WbV.d.ts → base-CQuRWXAH.d.ts} +985 -913
  8. package/dist/{base-ObPJ-w8K.d.cts → base-CvQbEqGB.d.cts} +4 -1
  9. package/dist/{base-C0wILuA9.d.cts → base-Dpt4tO56.d.cts} +985 -913
  10. package/dist/base.cjs +2 -2
  11. package/dist/base.d.cts +1 -1
  12. package/dist/base.d.ts +1 -1
  13. package/dist/base.js +1 -1
  14. package/dist/bundler/index.cjs +2 -2
  15. package/dist/bundler/index.d.cts +1 -1
  16. package/dist/bundler/index.d.ts +1 -1
  17. package/dist/bundler/index.js +1 -1
  18. package/dist/{chunk-L7CR75HA.js → chunk-2BVZNKLX.js} +1 -1
  19. package/dist/{chunk-V5ORZPFW.cjs → chunk-3C6V2FEP.cjs} +1 -1
  20. package/dist/chunk-3HE5CJBG.cjs +4604 -0
  21. package/dist/{chunk-PNZK456O.js → chunk-4RMSGSQN.js} +4 -4
  22. package/dist/{chunk-WESJ2ZY7.cjs → chunk-57LXIDIK.cjs} +2 -2
  23. package/dist/chunk-5RRJEWMA.cjs +107 -0
  24. package/dist/{chunk-3CNO7YB5.js → chunk-5TFGORLG.js} +1 -1
  25. package/dist/{chunk-5FAJ6HUC.cjs → chunk-64VPB7ZD.cjs} +23 -2
  26. package/dist/chunk-6XLV4KSD.js +100 -0
  27. package/dist/{chunk-XLSROQ26.cjs → chunk-7I7AKQH3.cjs} +5 -5
  28. package/dist/{chunk-RUA6BSB6.cjs → chunk-7JBINHJX.cjs} +2 -2
  29. package/dist/chunk-A6MBM56X.js +268 -0
  30. package/dist/{chunk-2YF5JYTJ.js → chunk-BC5B4EGI.js} +21 -2
  31. package/dist/chunk-BF7ZLRGO.cjs +271 -0
  32. package/dist/{chunk-SMBKF6K5.js → chunk-BRBHQ6KS.js} +10 -1
  33. package/dist/{chunk-VN4M67DA.js → chunk-CLJQYXNM.js} +1 -1
  34. package/dist/{chunk-PL7PVTGF.cjs → chunk-D63P5O4Q.cjs} +4 -4
  35. package/dist/chunk-DCGLGWHI.cjs +141 -0
  36. package/dist/{chunk-YXJQFZOW.cjs → chunk-DL4QPJKI.cjs} +24 -10
  37. package/dist/{chunk-ZABXT2MN.js → chunk-FY57LEMC.js} +1 -1
  38. package/dist/{chunk-XLXJUYKH.js → chunk-GHK3HBWN.js} +1 -1
  39. package/dist/{chunk-ONDCHP6G.cjs → chunk-GO2D7FEK.cjs} +2 -2
  40. package/dist/{chunk-7VTZI3YN.js → chunk-H6ZU5N2C.js} +1 -1
  41. package/dist/{chunk-WBE5RTFI.js → chunk-HAWAUEWK.js} +2 -2
  42. package/dist/chunk-HCDXBSMK.js +4577 -0
  43. package/dist/{chunk-RU7CSPAV.js → chunk-JGJMVCJ4.js} +7 -84
  44. package/dist/{chunk-W5HVJX45.js → chunk-N5ZYOQBL.js} +46 -5
  45. package/dist/{chunk-NPOKIPWC.cjs → chunk-O7IW545H.cjs} +1 -1
  46. package/dist/{chunk-XB2TJ7LX.cjs → chunk-PHWEC4VD.cjs} +47 -6
  47. package/dist/{chunk-NUDAZEOG.js → chunk-PK5QRKSG.js} +1 -1
  48. package/dist/{chunk-43SD5CUE.js → chunk-QDHRRKQ5.js} +63 -9
  49. package/dist/{chunk-ZBKJDQPM.js → chunk-RBWBJC6D.js} +17 -3
  50. package/dist/{chunk-4PYORXWM.cjs → chunk-RXDLSCBA.cjs} +4 -4
  51. package/dist/{chunk-IQLRSKED.cjs → chunk-RZCYBC7D.cjs} +2 -2
  52. package/dist/{chunk-ASFUEC75.cjs → chunk-TNNHN4ZY.cjs} +67 -12
  53. package/dist/{chunk-QM6WIIPM.js → chunk-UF4LZV3D.js} +1 -1
  54. package/dist/{chunk-JJ4YQTFT.cjs → chunk-WAW7QBY4.cjs} +2 -2
  55. package/dist/{chunk-U7ONOIBO.cjs → chunk-YZDUZFVZ.cjs} +11 -2
  56. package/dist/deployer/index.cjs +2 -2
  57. package/dist/deployer/index.d.cts +1 -1
  58. package/dist/deployer/index.d.ts +1 -1
  59. package/dist/deployer/index.js +1 -1
  60. package/dist/eval/index.cjs +3 -3
  61. package/dist/eval/index.d.cts +8 -5
  62. package/dist/eval/index.d.ts +8 -5
  63. package/dist/eval/index.js +1 -1
  64. package/dist/hooks/index.d.cts +1 -1
  65. package/dist/hooks/index.d.ts +1 -1
  66. package/dist/index.cjs +102 -92
  67. package/dist/index.d.cts +11 -9
  68. package/dist/index.d.ts +11 -9
  69. package/dist/index.js +18 -19
  70. package/dist/integration/index.cjs +3 -3
  71. package/dist/integration/index.d.cts +5 -3
  72. package/dist/integration/index.d.ts +5 -3
  73. package/dist/integration/index.js +1 -1
  74. package/dist/llm/index.d.cts +5 -3
  75. package/dist/llm/index.d.ts +5 -3
  76. package/dist/logger/index.cjs +9 -9
  77. package/dist/logger/index.js +1 -1
  78. package/dist/mastra/index.cjs +2 -2
  79. package/dist/mastra/index.d.cts +5 -3
  80. package/dist/mastra/index.d.ts +5 -3
  81. package/dist/mastra/index.js +1 -1
  82. package/dist/memory/index.cjs +6 -2
  83. package/dist/memory/index.d.cts +5 -3
  84. package/dist/memory/index.d.ts +5 -3
  85. package/dist/memory/index.js +1 -1
  86. package/dist/network/index.cjs +8 -8
  87. package/dist/network/index.d.cts +5 -3
  88. package/dist/network/index.d.ts +5 -3
  89. package/dist/network/index.js +4 -4
  90. package/dist/relevance/index.cjs +4 -4
  91. package/dist/relevance/index.d.cts +10 -8
  92. package/dist/relevance/index.d.ts +10 -8
  93. package/dist/relevance/index.js +1 -1
  94. package/dist/server/index.cjs +17 -0
  95. package/dist/server/index.d.cts +37 -0
  96. package/dist/server/index.d.ts +37 -0
  97. package/dist/server/index.js +15 -0
  98. package/dist/storage/index.cjs +12 -8
  99. package/dist/storage/index.d.cts +5 -3
  100. package/dist/storage/index.d.ts +5 -3
  101. package/dist/storage/index.js +2 -2
  102. package/dist/storage/libsql/index.cjs +24 -24
  103. package/dist/storage/libsql/index.d.cts +5 -3
  104. package/dist/storage/libsql/index.d.ts +5 -3
  105. package/dist/storage/libsql/index.js +12 -12
  106. package/dist/telemetry/index.cjs +6 -6
  107. package/dist/telemetry/index.d.cts +5 -3
  108. package/dist/telemetry/index.d.ts +5 -3
  109. package/dist/telemetry/index.js +1 -1
  110. package/dist/tools/index.cjs +7 -3
  111. package/dist/tools/index.d.cts +6 -3
  112. package/dist/tools/index.d.ts +6 -3
  113. package/dist/tools/index.js +1 -1
  114. package/dist/tts/index.cjs +2 -2
  115. package/dist/tts/index.d.cts +1 -1
  116. package/dist/tts/index.d.ts +1 -1
  117. package/dist/tts/index.js +1 -1
  118. package/dist/{types-CwTG2XyQ.d.cts → types-BtMyV38I.d.cts} +4 -1
  119. package/dist/{types-CwTG2XyQ.d.ts → types-BtMyV38I.d.ts} +4 -1
  120. package/dist/utils.cjs +13 -13
  121. package/dist/utils.d.cts +7 -5
  122. package/dist/utils.d.ts +7 -5
  123. package/dist/utils.js +1 -1
  124. package/dist/vector/index.cjs +2 -2
  125. package/dist/vector/index.d.cts +1 -1
  126. package/dist/vector/index.d.ts +1 -1
  127. package/dist/vector/index.js +1 -1
  128. package/dist/vector/libsql/index.cjs +3 -3
  129. package/dist/vector/libsql/index.d.cts +1 -1
  130. package/dist/vector/libsql/index.d.ts +1 -1
  131. package/dist/vector/libsql/index.js +1 -1
  132. package/dist/voice/index.cjs +13 -249
  133. package/dist/voice/index.d.cts +22 -8
  134. package/dist/voice/index.d.ts +22 -8
  135. package/dist/voice/index.js +1 -252
  136. package/dist/workflows/index.cjs +28 -20
  137. package/dist/workflows/index.d.cts +18 -7
  138. package/dist/workflows/index.d.ts +18 -7
  139. package/dist/workflows/index.js +1 -1
  140. package/package.json +5 -3
  141. package/dist/chunk-2W2GYEYQ.cjs +0 -25
  142. package/dist/chunk-C6BBAS4I.cjs +0 -1715
  143. package/dist/chunk-F5UYWPV4.cjs +0 -14
  144. package/dist/chunk-GG6TEAMJ.cjs +0 -2289
  145. package/dist/chunk-R2M5CZ5U.js +0 -2264
  146. package/dist/chunk-RG66XEJT.js +0 -8
  147. package/dist/chunk-VNQRLYIA.js +0 -1715
  148. package/dist/chunk-WVVKLIUW.cjs +0 -218
  149. package/dist/chunk-ZINPRHAN.js +0 -22
package/README.md CHANGED
@@ -29,8 +29,8 @@ For comprehensive documentation, visit our [official documentation](https://mast
29
29
  Agents are autonomous AI entities that can understand instructions, use tools, and complete tasks. They encapsulate LLM interactions and can maintain conversation history, use provided tools, and follow specific behavioral guidelines through instructions.
30
30
 
31
31
  ```typescript
32
- import { openai } from '@ai-sdk/openai';
33
32
  import { Agent } from '@mastra/core/agent';
33
+ import { openai } from '@ai-sdk/openai';
34
34
 
35
35
  const agent = new Agent({
36
36
  name: 'my-agent',
@@ -40,108 +40,99 @@ const agent = new Agent({
40
40
  });
41
41
  ```
42
42
 
43
- [More agent documentation →](https://mastra.ai/docs/reference/agents/overview)
43
+ [Agent documentation →](https://mastra.ai/docs/agents/00-overview)
44
44
 
45
- ### Embeddings (`/embeddings`)
45
+ ### Workflows (`/workflows`)
46
46
 
47
- The embeddings module provides a unified interface for converting text into vector representations across multiple AI providers. These vectors are essential for semantic search, similarity comparisons, and other NLP tasks.
47
+ Workflows orchestrate complex AI tasks by combining multiple actions into a coherent sequence. They handle state management, error recovery, and can include conditional logic and parallel execution.
48
48
 
49
49
  ```typescript
50
- import { openai } from '@ai-sdk/openai';
51
- import { embed } from 'ai';
50
+ import { Workflow } from '@mastra/core';
52
51
 
53
- const embeddings = await embed({
54
- model: openai.embedding('text-embedding-3-small'),
55
- value: 'text to embed',
52
+ const workflow = new Workflow({
53
+ name: 'my-workflow',
54
+ steps: [
55
+ // Workflow steps
56
+ ],
56
57
  });
57
58
  ```
58
59
 
59
- Supported providers right now are OpenAI, Cohere, Amazon Bedrock, Google AI, Mistral, and Voyage.
60
-
61
- [More embeddings documentation →](https://mastra.ai/docs/reference/embeddings/overview)
62
-
63
- ### Evaluations (`/eval`)
64
-
65
- The evaluation system enables quantitative assessment of AI outputs. Create custom metrics to measure specific aspects of AI performance, from response quality to task completion accuracy.
66
-
67
- ```typescript
68
- import { Metric, evaluate } from '@mastra/core';
69
-
70
- class CustomMetric extends Metric {
71
- async measure(input: string, output: string): Promise<MetricResult> {
72
- // Your evaluation logic
73
- return { score: 0.95 };
74
- }
75
- }
76
- ```
77
-
78
- [More evaluations documentation →](https://mastra.ai/docs/reference/eval/overview)
60
+ [Workflow documentation →](https://mastra.ai/docs/workflows/00-overview)
79
61
 
80
62
  ### Memory (`/memory`)
81
63
 
82
64
  Memory management provides persistent storage and retrieval of AI interactions. It supports different storage backends and enables context-aware conversations and long-term learning.
83
65
 
84
66
  ```typescript
85
- import { MastraMemory } from '@mastra/core';
67
+ import { Memory } from '@mastra/memory';
68
+ import { Agent } from '@mastra/core/agent';
69
+ import { openai } from '@ai-sdk/openai';
86
70
 
87
- const memory = new MastraMemory({
88
- // Memory configuration
71
+ const agent = new Agent({
72
+ name: 'Project Manager',
73
+ instructions: 'You are a project manager assistant.',
74
+ model: openai('gpt-4o-mini'),
75
+ memory: new Memory({
76
+ options: {
77
+ lastMessages: 20,
78
+ semanticRecall: {
79
+ topK: 3,
80
+ messageRange: { before: 2, after: 1 },
81
+ },
82
+ },
83
+ }),
89
84
  });
90
85
  ```
91
86
 
92
- **Note:** this is the base `MastraMemory` class. This class in `@mastra/core` is intended to be extended when developing custom agent memory strategies.
93
- To use a premade memory strategy (recommended), with long and short term memory built in, use `import { Memory } from "@mastra/memory"` instead.
94
-
95
- [Visit the memory documentation to use Memory in your project →](https://mastra.ai/docs/reference/memory/overview)
96
-
97
- ### Vector Stores (`/vector`)
98
-
99
- Vector stores provide the infrastructure for storing and querying vector embeddings. They support semantic search, similarity matching, and efficient vector operations across different backend implementations.
100
-
101
- ```typescript
102
- import { MastraVector } from '@mastra/core';
103
-
104
- class CustomVectorStore extends MastraVector {
105
- // Vector store implementation
106
- }
107
- ```
108
-
109
- [More vector stores documentation →](https://mastra.ai/docs/reference/vector/overview)
87
+ [Memory documentation →](https://mastra.ai/docs/reference/memory/Memory)
110
88
 
111
- ### Workflows (`/workflows`)
89
+ ### Tools (`/tools`)
112
90
 
113
- Workflows orchestrate complex AI tasks by combining multiple actions into a coherent sequence. They handle state management, error recovery, and can include conditional logic and parallel execution.
91
+ Tools are functions that agents can use to interact with external systems or perform specific tasks. Each tool has a clear description and schema, making it easy for AI to understand and use them effectively.
114
92
 
115
93
  ```typescript
116
- import { Workflow } from '@mastra/core';
117
-
118
- const workflow = new Workflow({
119
- name: 'my-workflow',
120
- steps: [
121
- // Workflow steps
122
- ],
94
+ import { createTool } from '@mastra/core/tools';
95
+ import { z } from 'zod';
96
+
97
+ const weatherInfo = createTool({
98
+ id: 'Get Weather Information',
99
+ inputSchema: z.object({
100
+ city: z.string(),
101
+ }),
102
+ description: 'Fetches the current weather information for a given city',
103
+ execute: async ({ context: { city } }) => {
104
+ // Tool implementation
105
+ },
123
106
  });
124
107
  ```
125
108
 
126
- [More workflows documentation →](https://mastra.ai/docs/reference/workflows/overview)
109
+ [Tools documentation →](https://mastra.ai/docs/agents/02-adding-tools)
127
110
 
128
- ### Tools (`/tools`)
111
+ ### Evals (`/eval`)
129
112
 
130
- Tools are functions that agents can use to interact with external systems or perform specific tasks. Each tool has a clear description and schema, making it easy for AI to understand and use them effectively.
113
+ The evaluation system enables quantitative assessment of AI outputs. Create custom metrics to measure specific aspects of AI performance, from response quality to task completion accuracy.
131
114
 
132
115
  ```typescript
133
- import { ToolAction } from '@mastra/core';
116
+ import { Agent } from '@mastra/core/agent';
117
+ import { openai } from '@ai-sdk/openai';
118
+ import { SummarizationMetric } from '@mastra/evals/llm';
119
+ import { ContentSimilarityMetric, ToneConsistencyMetric } from '@mastra/evals/nlp';
134
120
 
135
- const tool = new ToolAction({
136
- name: 'tool-name',
137
- description: 'Tool description',
138
- execute: async context => {
139
- // Tool implementation
121
+ const model = openai('gpt-4o');
122
+
123
+ const agent = new Agent({
124
+ name: 'ContentWriter',
125
+ instructions: 'You are a content writer that creates accurate summaries',
126
+ model,
127
+ evals: {
128
+ summarization: new SummarizationMetric(model),
129
+ contentSimilarity: new ContentSimilarityMetric(),
130
+ tone: new ToneConsistencyMetric(),
140
131
  },
141
132
  });
142
133
  ```
143
134
 
144
- [More tools documentation →](https://mastra.ai/docs/reference/tools/overview)
135
+ [More evals documentation →](https://mastra.ai/docs/evals/00-overview)
145
136
 
146
137
  ### Logger (`/logger`)
147
138
 
@@ -160,13 +151,24 @@ const logger = createLogger({
160
151
 
161
152
  ### Telemetry (`/telemetry`)
162
153
 
163
- Telemetry provides OpenTelemetry integration for comprehensive monitoring of your AI systems. Track latency, success rates, and system health with distributed tracing and metrics collection.
154
+ Telemetry provides OpenTelemetry (Otel) integration for comprehensive monitoring of your AI systems. Track latency, success rates, and system health with distributed tracing and metrics collection.
164
155
 
165
156
  ```typescript
166
- import { Telemetry } from '@mastra/core';
167
-
168
- const telemetry = Telemetry.init({
169
- serviceName: 'my-service',
157
+ import { Mastra } from '@mastra/core';
158
+
159
+ const mastra = new Mastra({
160
+ telemetry: {
161
+ serviceName: 'my-service',
162
+ enabled: true,
163
+ sampling: {
164
+ type: 'ratio',
165
+ probability: 0.5,
166
+ },
167
+ export: {
168
+ type: 'otlp',
169
+ endpoint: 'https://otel-collector.example.com/v1/traces',
170
+ },
171
+ },
170
172
  });
171
173
  ```
172
174
 
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkC6BBAS4I_cjs = require('../chunk-C6BBAS4I.cjs');
3
+ var chunk3HE5CJBG_cjs = require('../chunk-3HE5CJBG.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "Agent", {
8
8
  enumerable: true,
9
- get: function () { return chunkC6BBAS4I_cjs.Agent; }
9
+ get: function () { return chunk3HE5CJBG_cjs.Agent; }
10
10
  });
@@ -1,9 +1,9 @@
1
1
  export { Message as AiMessageType } from 'ai';
2
2
  import 'json-schema';
3
3
  import 'zod';
4
- export { A as Agent, m as AgentConfig, aH as AgentGenerateOptions, aI as AgentStreamOptions, az as MastraLanguageModel, a as ToolsInput, aG as ToolsetsInput } from '../base-C0wILuA9.cjs';
5
- import '../base-ObPJ-w8K.cjs';
6
- import '../types-CwTG2XyQ.cjs';
4
+ export { j as Agent, k as AgentConfig, aL as AgentGenerateOptions, aM as AgentStreamOptions, aF as MastraLanguageModel, aG as ToolsInput, aK as ToolsetsInput } from '../base-Dpt4tO56.cjs';
5
+ import '../base-CvQbEqGB.cjs';
6
+ import '../types-BtMyV38I.cjs';
7
7
  import 'sift';
8
8
  import '../index-CquI0inB.cjs';
9
9
  import 'stream';
@@ -17,3 +17,5 @@ import '@opentelemetry/sdk-trace-base';
17
17
  import '../tts/index.cjs';
18
18
  import '../deployer/index.cjs';
19
19
  import '../bundler/index.cjs';
20
+ import 'hono';
21
+ import 'hono-openapi';
@@ -1,9 +1,9 @@
1
1
  export { Message as AiMessageType } from 'ai';
2
2
  import 'json-schema';
3
3
  import 'zod';
4
- export { A as Agent, m as AgentConfig, aH as AgentGenerateOptions, aI as AgentStreamOptions, az as MastraLanguageModel, a as ToolsInput, aG as ToolsetsInput } from '../base-Cyl73WbV.js';
5
- import '../base-Cmunaaxb.js';
6
- import '../types-CwTG2XyQ.js';
4
+ export { j as Agent, k as AgentConfig, aL as AgentGenerateOptions, aM as AgentStreamOptions, aF as MastraLanguageModel, aG as ToolsInput, aK as ToolsetsInput } from '../base-CQuRWXAH.js';
5
+ import '../base-BA_in99t.js';
6
+ import '../types-BtMyV38I.js';
7
7
  import 'sift';
8
8
  import '../index-CquI0inB.js';
9
9
  import 'stream';
@@ -17,3 +17,5 @@ import '@opentelemetry/sdk-trace-base';
17
17
  import '../tts/index.js';
18
18
  import '../deployer/index.js';
19
19
  import '../bundler/index.js';
20
+ import 'hono';
21
+ import 'hono-openapi';
@@ -1 +1 @@
1
- export { Agent } from '../chunk-VNQRLYIA.js';
1
+ export { Agent } from '../chunk-HCDXBSMK.js';
@@ -1,5 +1,5 @@
1
1
  import * as _opentelemetry_api from '@opentelemetry/api';
2
- import { Tracer, Span } from '@opentelemetry/api';
2
+ import { Tracer, Span, Context } from '@opentelemetry/api';
3
3
  import { R as RegisteredLogger, L as Logger } from './index-CquI0inB.js';
4
4
  import { SpanExporter } from '@opentelemetry/sdk-trace-base';
5
5
 
@@ -71,6 +71,7 @@ declare class Telemetry {
71
71
  * @returns Telemetry instance that can be used for tracing
72
72
  */
73
73
  static init(config?: OtelConfig): Telemetry;
74
+ static getActiveSpan(): Span | undefined;
74
75
  /**
75
76
  * Get the global telemetry instance
76
77
  * @throws {Error} If telemetry has not been initialized
@@ -93,6 +94,8 @@ declare class Telemetry {
93
94
  /** Skip tracing if telemetry is not active */
94
95
  skipIfNoTelemetry?: boolean;
95
96
  }): T;
97
+ static setBaggage(baggage: Record<string, string>, ctx?: Context): Context;
98
+ static withContext(ctx: Context, fn: () => void): void;
96
99
  /**
97
100
  * method to trace individual methods with proper context
98
101
  * @param method The method to trace