@mastra/core 0.0.0-a2a-20250421213654

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 (198) hide show
  1. package/LICENSE.md +46 -0
  2. package/README.md +182 -0
  3. package/agent.d.ts +1 -0
  4. package/base.d.ts +1 -0
  5. package/bundler.d.ts +1 -0
  6. package/deployer.d.ts +1 -0
  7. package/di.d.ts +1 -0
  8. package/dist/agent/index.cjs +10 -0
  9. package/dist/agent/index.d.cts +23 -0
  10. package/dist/agent/index.d.ts +23 -0
  11. package/dist/agent/index.js +1 -0
  12. package/dist/base-BihKcqDY.d.cts +146 -0
  13. package/dist/base-BlGpZfLc.d.ts +2139 -0
  14. package/dist/base-DT2poiVK.d.ts +146 -0
  15. package/dist/base-xpk2ifTz.d.cts +2139 -0
  16. package/dist/base.cjs +10 -0
  17. package/dist/base.d.cts +6 -0
  18. package/dist/base.d.ts +6 -0
  19. package/dist/base.js +1 -0
  20. package/dist/bundler/index.cjs +10 -0
  21. package/dist/bundler/index.d.cts +28 -0
  22. package/dist/bundler/index.d.ts +28 -0
  23. package/dist/bundler/index.js +1 -0
  24. package/dist/chunk-2BVZNKLX.js +153 -0
  25. package/dist/chunk-3C6V2FEP.cjs +38 -0
  26. package/dist/chunk-3PBEAM6M.js +69 -0
  27. package/dist/chunk-3XWBNOSO.cjs +91 -0
  28. package/dist/chunk-5TFGORLG.js +10 -0
  29. package/dist/chunk-7JBINHJX.cjs +37 -0
  30. package/dist/chunk-ANYT6KP7.js +96 -0
  31. package/dist/chunk-BB4KXGBU.js +83 -0
  32. package/dist/chunk-BBDXZGCM.cjs +4758 -0
  33. package/dist/chunk-BUNPX6LU.js +4730 -0
  34. package/dist/chunk-C6A6W6XS.js +77 -0
  35. package/dist/chunk-CLJQYXNM.js +49 -0
  36. package/dist/chunk-D63P5O4Q.cjs +51 -0
  37. package/dist/chunk-DGL5RCEO.js +739 -0
  38. package/dist/chunk-F4WOCJZQ.cjs +65 -0
  39. package/dist/chunk-FKUPMQZP.cjs +270 -0
  40. package/dist/chunk-FPM2XCMS.cjs +92 -0
  41. package/dist/chunk-FRQFWZDN.cjs +2 -0
  42. package/dist/chunk-FY57LEMC.js +35 -0
  43. package/dist/chunk-GHK3HBWN.js +22 -0
  44. package/dist/chunk-H6SGDOA4.cjs +394 -0
  45. package/dist/chunk-HFOT2NFM.js +443 -0
  46. package/dist/chunk-HHDP5KHS.js +61 -0
  47. package/dist/chunk-KAJSLFMA.js +430 -0
  48. package/dist/chunk-KR6AYHNH.cjs +449 -0
  49. package/dist/chunk-KRSZNW2W.cjs +421 -0
  50. package/dist/chunk-KWV5ZLOF.js +90 -0
  51. package/dist/chunk-LANFNMEE.js +127 -0
  52. package/dist/chunk-LGERQTJM.js +190 -0
  53. package/dist/chunk-LZQIMLJV.cjs +71 -0
  54. package/dist/chunk-M6MZXBG5.js +88 -0
  55. package/dist/chunk-MWLZJBPF.js +267 -0
  56. package/dist/chunk-O7IW545H.cjs +167 -0
  57. package/dist/chunk-P6KJ7FZZ.cjs +37 -0
  58. package/dist/chunk-PK5QRKSG.js +35 -0
  59. package/dist/chunk-PSMMSO72.js +394 -0
  60. package/dist/chunk-RIBNDTA6.cjs +449 -0
  61. package/dist/chunk-RWTSGWWL.cjs +81 -0
  62. package/dist/chunk-RZCYBC7D.cjs +12 -0
  63. package/dist/chunk-ST5RMVLG.cjs +87 -0
  64. package/dist/chunk-TEEAQX2B.cjs +741 -0
  65. package/dist/chunk-TNILINST.cjs +103 -0
  66. package/dist/chunk-WAW7QBY4.cjs +24 -0
  67. package/dist/chunk-WEYWYKLG.cjs +130 -0
  68. package/dist/chunk-YK3XJ52U.cjs +192 -0
  69. package/dist/chunk-ZDWFBE5L.js +1 -0
  70. package/dist/chunk-ZI2W5BQV.js +413 -0
  71. package/dist/chunk-ZRMY72JX.js +37 -0
  72. package/dist/deployer/index.cjs +10 -0
  73. package/dist/deployer/index.d.cts +19 -0
  74. package/dist/deployer/index.d.ts +19 -0
  75. package/dist/deployer/index.js +1 -0
  76. package/dist/di/index.cjs +10 -0
  77. package/dist/di/index.d.cts +52 -0
  78. package/dist/di/index.d.ts +52 -0
  79. package/dist/di/index.js +1 -0
  80. package/dist/eval/index.cjs +14 -0
  81. package/dist/eval/index.d.cts +37 -0
  82. package/dist/eval/index.d.ts +37 -0
  83. package/dist/eval/index.js +1 -0
  84. package/dist/hooks/index.cjs +18 -0
  85. package/dist/hooks/index.d.cts +33 -0
  86. package/dist/hooks/index.d.ts +33 -0
  87. package/dist/hooks/index.js +1 -0
  88. package/dist/index-CquI0inB.d.cts +91 -0
  89. package/dist/index-CquI0inB.d.ts +91 -0
  90. package/dist/index.cjs +350 -0
  91. package/dist/index.d.cts +97 -0
  92. package/dist/index.d.ts +97 -0
  93. package/dist/index.js +117 -0
  94. package/dist/integration/index.cjs +14 -0
  95. package/dist/integration/index.d.cts +59 -0
  96. package/dist/integration/index.d.ts +59 -0
  97. package/dist/integration/index.js +1 -0
  98. package/dist/llm/index.cjs +2 -0
  99. package/dist/llm/index.d.cts +23 -0
  100. package/dist/llm/index.d.ts +23 -0
  101. package/dist/llm/index.js +1 -0
  102. package/dist/logger/index.cjs +38 -0
  103. package/dist/logger/index.d.cts +3 -0
  104. package/dist/logger/index.d.ts +3 -0
  105. package/dist/logger/index.js +1 -0
  106. package/dist/mastra/index.cjs +10 -0
  107. package/dist/mastra/index.d.cts +23 -0
  108. package/dist/mastra/index.d.ts +23 -0
  109. package/dist/mastra/index.js +1 -0
  110. package/dist/memory/index.cjs +14 -0
  111. package/dist/memory/index.d.cts +23 -0
  112. package/dist/memory/index.d.ts +23 -0
  113. package/dist/memory/index.js +1 -0
  114. package/dist/network/index.cjs +305 -0
  115. package/dist/network/index.d.cts +23 -0
  116. package/dist/network/index.d.ts +23 -0
  117. package/dist/network/index.js +303 -0
  118. package/dist/relevance/index.cjs +18 -0
  119. package/dist/relevance/index.d.cts +43 -0
  120. package/dist/relevance/index.d.ts +43 -0
  121. package/dist/relevance/index.js +1 -0
  122. package/dist/server/index.cjs +17 -0
  123. package/dist/server/index.d.cts +39 -0
  124. package/dist/server/index.d.ts +39 -0
  125. package/dist/server/index.js +15 -0
  126. package/dist/storage/index.cjs +35 -0
  127. package/dist/storage/index.d.cts +23 -0
  128. package/dist/storage/index.d.ts +23 -0
  129. package/dist/storage/index.js +2 -0
  130. package/dist/storage/libsql/index.cjs +506 -0
  131. package/dist/storage/libsql/index.d.cts +106 -0
  132. package/dist/storage/libsql/index.d.ts +106 -0
  133. package/dist/storage/libsql/index.js +503 -0
  134. package/dist/telemetry/index.cjs +26 -0
  135. package/dist/telemetry/index.d.cts +59 -0
  136. package/dist/telemetry/index.d.ts +59 -0
  137. package/dist/telemetry/index.js +1 -0
  138. package/dist/telemetry/otel-vendor.cjs +103 -0
  139. package/dist/telemetry/otel-vendor.d.cts +20 -0
  140. package/dist/telemetry/otel-vendor.d.ts +20 -0
  141. package/dist/telemetry/otel-vendor.js +57 -0
  142. package/dist/tools/index.cjs +18 -0
  143. package/dist/tools/index.d.cts +24 -0
  144. package/dist/tools/index.d.ts +24 -0
  145. package/dist/tools/index.js +1 -0
  146. package/dist/tts/index.cjs +10 -0
  147. package/dist/tts/index.d.cts +28 -0
  148. package/dist/tts/index.d.ts +28 -0
  149. package/dist/tts/index.js +1 -0
  150. package/dist/types-BtMyV38I.d.cts +17 -0
  151. package/dist/types-BtMyV38I.d.ts +17 -0
  152. package/dist/utils.cjs +54 -0
  153. package/dist/utils.d.cts +101 -0
  154. package/dist/utils.d.ts +101 -0
  155. package/dist/utils.js +1 -0
  156. package/dist/vector/filter/index.cjs +10 -0
  157. package/dist/vector/filter/index.d.cts +90 -0
  158. package/dist/vector/filter/index.d.ts +90 -0
  159. package/dist/vector/filter/index.js +1 -0
  160. package/dist/vector/index.cjs +10 -0
  161. package/dist/vector/index.d.cts +66 -0
  162. package/dist/vector/index.d.ts +66 -0
  163. package/dist/vector/index.js +1 -0
  164. package/dist/vector/libsql/index.cjs +14 -0
  165. package/dist/vector/libsql/index.d.cts +49 -0
  166. package/dist/vector/libsql/index.d.ts +49 -0
  167. package/dist/vector/libsql/index.js +1 -0
  168. package/dist/voice/index.cjs +18 -0
  169. package/dist/voice/index.d.cts +35 -0
  170. package/dist/voice/index.d.ts +35 -0
  171. package/dist/voice/index.js +1 -0
  172. package/dist/workflows/index.cjs +94 -0
  173. package/dist/workflows/index.d.cts +85 -0
  174. package/dist/workflows/index.d.ts +85 -0
  175. package/dist/workflows/index.js +1 -0
  176. package/eval.d.ts +1 -0
  177. package/hooks.d.ts +1 -0
  178. package/integration.d.ts +1 -0
  179. package/llm.d.ts +1 -0
  180. package/logger.d.ts +1 -0
  181. package/mastra.d.ts +1 -0
  182. package/memory.d.ts +1 -0
  183. package/network.d.ts +1 -0
  184. package/package.json +181 -0
  185. package/relevance.d.ts +1 -0
  186. package/server.d.ts +1 -0
  187. package/storage/libsql.d.ts +1 -0
  188. package/storage.d.ts +1 -0
  189. package/telemetry/otel-vendor.d.ts +1 -0
  190. package/telemetry.d.ts +1 -0
  191. package/tools.d.ts +1 -0
  192. package/tts.d.ts +1 -0
  193. package/utils.d.ts +1 -0
  194. package/vector/filter.d.ts +1 -0
  195. package/vector/libsql.d.ts +1 -0
  196. package/vector.d.ts +1 -0
  197. package/voice.d.ts +1 -0
  198. package/workflows.d.ts +1 -0
package/LICENSE.md ADDED
@@ -0,0 +1,46 @@
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
4
+
5
+ **Acceptance**
6
+ By using the software, you agree to all of the terms and conditions below.
7
+
8
+ **Copyright License**
9
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
10
+
11
+ **Limitations**
12
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
13
+
14
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
15
+
16
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
17
+
18
+ **Patents**
19
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
20
+
21
+ **Notices**
22
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
23
+
24
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
25
+
26
+ **No Other Rights**
27
+ These terms do not imply any licenses other than those expressly granted in these terms.
28
+
29
+ **Termination**
30
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
31
+
32
+ **No Liability**
33
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
34
+
35
+ **Definitions**
36
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
37
+
38
+ _you_ refers to the individual or entity agreeing to these terms.
39
+
40
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
41
+
42
+ _your licenses_ are all the licenses granted to you for the software under these terms.
43
+
44
+ _use_ means anything you do with the software requiring one of your licenses.
45
+
46
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # @mastra/core
2
+
3
+ The core foundation of the Mastra framework, providing essential components and interfaces for building AI-powered applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/core
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ `@mastra/core` is the foundational package of the Mastra framework, providing:
14
+
15
+ - Core abstractions and interfaces
16
+ - AI agent management and execution
17
+ - Integration with multiple AI providers
18
+ - Workflow orchestration
19
+ - Memory and vector store management
20
+ - Telemetry and logging infrastructure
21
+ - Text-to-speech capabilities
22
+
23
+ For comprehensive documentation, visit our [official documentation](https://mastra.ai/docs).
24
+
25
+ ## Core Components
26
+
27
+ ### Agents (`/agent`)
28
+
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
+
31
+ ```typescript
32
+ import { Agent } from '@mastra/core/agent';
33
+ import { openai } from '@ai-sdk/openai';
34
+
35
+ const agent = new Agent({
36
+ name: 'my-agent',
37
+ instructions: 'Your task-specific instructions',
38
+ model: openai('gpt-4o-mini'),
39
+ tools: {}, // Optional tools
40
+ });
41
+ ```
42
+
43
+ [Agent documentation →](https://mastra.ai/docs/agents/overview)
44
+
45
+ ### Workflows (`/workflows`)
46
+
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
+
49
+ ```typescript
50
+ import { Workflow } from '@mastra/core';
51
+
52
+ const workflow = new Workflow({
53
+ name: 'my-workflow',
54
+ steps: [
55
+ // Workflow steps
56
+ ],
57
+ });
58
+ ```
59
+
60
+ [Workflow documentation →](https://mastra.ai/docs/workflows/overview)
61
+
62
+ ### Memory (`/memory`)
63
+
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.
65
+
66
+ ```typescript
67
+ import { Memory } from '@mastra/memory';
68
+ import { Agent } from '@mastra/core/agent';
69
+ import { openai } from '@ai-sdk/openai';
70
+
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
+ }),
84
+ });
85
+ ```
86
+
87
+ [Memory documentation →](https://mastra.ai/reference/memory/Memory)
88
+
89
+ ### Tools (`/tools`)
90
+
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.
92
+
93
+ ```typescript
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
+ },
106
+ });
107
+ ```
108
+
109
+ [Tools documentation →](https://mastra.ai/docs/agents/adding-tools)
110
+
111
+ ### Evals (`/eval`)
112
+
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.
114
+
115
+ ```typescript
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';
120
+
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(),
131
+ },
132
+ });
133
+ ```
134
+
135
+ [More evals documentation →](https://mastra.ai/docs/evals/overview)
136
+
137
+ ### Logger (`/logger`)
138
+
139
+ The logging system provides structured, leveled logging with multiple transport options. It supports debug information, performance monitoring, and error tracking across your AI applications.
140
+
141
+ ```typescript
142
+ import { createLogger, LogLevel } from '@mastra/core';
143
+
144
+ const logger = createLogger({
145
+ name: 'MyApp',
146
+ level: LogLevel.INFO,
147
+ });
148
+ ```
149
+
150
+ [More logging documentation →](https://mastra.ai/reference/observability/logging)
151
+
152
+ ### Telemetry (`/telemetry`)
153
+
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.
155
+
156
+ ```typescript
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
+ },
172
+ });
173
+ ```
174
+
175
+ [More Telemetry documentation →](https://mastra.ai/reference/observability/telemetry)
176
+
177
+ ## Additional Resources
178
+
179
+ - [Getting Started Guide](https://mastra.ai/docs/getting-started/installation)
180
+ - [API Reference](https://mastra.ai/reference)
181
+ - [Examples](https://mastra.ai/docs/examples)
182
+ - [Deployment Guide](https://mastra.ai/docs/deployment/overview)
package/agent.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/agent';
package/base.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/base.d.cts';
package/bundler.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/bundler';
package/deployer.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/deployer';
package/di.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/di';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunkBBDXZGCM_cjs = require('../chunk-BBDXZGCM.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "Agent", {
8
+ enumerable: true,
9
+ get: function () { return chunkBBDXZGCM_cjs.Agent; }
10
+ });
@@ -0,0 +1,23 @@
1
+ export { Message as AiMessageType } from 'ai';
2
+ import 'json-schema';
3
+ import 'zod';
4
+ export { j as Agent, k as AgentConfig, aM as AgentGenerateOptions, aN as AgentStreamOptions, aG as MastraLanguageModel, aH as ToolsInput, aL as ToolsetsInput } from '../base-xpk2ifTz.cjs';
5
+ import '../base-BihKcqDY.cjs';
6
+ import '../di/index.cjs';
7
+ import '../types-BtMyV38I.cjs';
8
+ import 'sift';
9
+ import '../index-CquI0inB.cjs';
10
+ import 'stream';
11
+ import 'pino';
12
+ import '@opentelemetry/api';
13
+ import 'xstate';
14
+ import 'node:events';
15
+ import '../vector/index.cjs';
16
+ import '../vector/filter/index.cjs';
17
+ import '@opentelemetry/sdk-trace-base';
18
+ import '../tts/index.cjs';
19
+ import '../deployer/index.cjs';
20
+ import '../bundler/index.cjs';
21
+ import 'hono';
22
+ import 'hono/cors';
23
+ import 'hono-openapi';
@@ -0,0 +1,23 @@
1
+ export { Message as AiMessageType } from 'ai';
2
+ import 'json-schema';
3
+ import 'zod';
4
+ export { j as Agent, k as AgentConfig, aM as AgentGenerateOptions, aN as AgentStreamOptions, aG as MastraLanguageModel, aH as ToolsInput, aL as ToolsetsInput } from '../base-BlGpZfLc.js';
5
+ import '../base-DT2poiVK.js';
6
+ import '../di/index.js';
7
+ import '../types-BtMyV38I.js';
8
+ import 'sift';
9
+ import '../index-CquI0inB.js';
10
+ import 'stream';
11
+ import 'pino';
12
+ import '@opentelemetry/api';
13
+ import 'xstate';
14
+ import 'node:events';
15
+ import '../vector/index.js';
16
+ import '../vector/filter/index.js';
17
+ import '@opentelemetry/sdk-trace-base';
18
+ import '../tts/index.js';
19
+ import '../deployer/index.js';
20
+ import '../bundler/index.js';
21
+ import 'hono';
22
+ import 'hono/cors';
23
+ import 'hono-openapi';
@@ -0,0 +1 @@
1
+ export { Agent } from '../chunk-BUNPX6LU.js';
@@ -0,0 +1,146 @@
1
+ import * as _opentelemetry_api from '@opentelemetry/api';
2
+ import { Tracer, Span, Context } from '@opentelemetry/api';
3
+ import { R as RegisteredLogger, L as Logger } from './index-CquI0inB.cjs';
4
+ import { SpanExporter } from '@opentelemetry/sdk-trace-base';
5
+
6
+ /** Sampling strategy configuration for OpenTelemetry */
7
+ type SamplingStrategy = {
8
+ /** Sample traces based on a probability between 0 and 1 */
9
+ type: 'ratio';
10
+ /** Probability between 0 and 1 (e.g., 0.1 for 10% sampling) */
11
+ probability: number;
12
+ } | {
13
+ /** Sample all traces */
14
+ type: 'always_on';
15
+ } | {
16
+ /** Don't sample any traces */
17
+ type: 'always_off';
18
+ } | {
19
+ /** Use parent sampling decision if available, otherwise use root sampler */
20
+ type: 'parent_based';
21
+ /** Configuration for the root sampler when no parent context exists */
22
+ root: {
23
+ /** Probability between 0 and 1 for the root sampler */
24
+ probability: number;
25
+ };
26
+ };
27
+ /** Configuration options for OpenTelemetry */
28
+ type OtelConfig = {
29
+ /** Name of the service for telemetry identification */
30
+ serviceName?: string;
31
+ /** Whether telemetry is enabled. Defaults to true */
32
+ enabled?: boolean;
33
+ /** Name of the tracer to use. Defaults to 'mastra-tracer' */
34
+ tracerName?: string;
35
+ /** Sampling configuration to control trace data volume */
36
+ sampling?: SamplingStrategy;
37
+ /** Whether to disable local export */
38
+ disableLocalExport?: boolean;
39
+ /** Export configuration for sending telemetry data */
40
+ export?: {
41
+ /** Export to an OTLP (OpenTelemetry Protocol) endpoint */
42
+ type: 'otlp';
43
+ /** Whether to use gRPC or HTTP for OTLP */
44
+ protocol?: 'grpc' | 'http';
45
+ /** OTLP endpoint URL */
46
+ endpoint?: string;
47
+ /** Optional headers for OTLP requests */
48
+ headers?: Record<string, string>;
49
+ } | {
50
+ /** Export to console for development/debugging */
51
+ type: 'console';
52
+ } | {
53
+ type: 'custom';
54
+ tracerName?: string;
55
+ exporter: SpanExporter;
56
+ };
57
+ };
58
+
59
+ declare global {
60
+ var __TELEMETRY__: Telemetry | undefined;
61
+ }
62
+ declare class Telemetry {
63
+ tracer: Tracer;
64
+ name: string;
65
+ private constructor();
66
+ /**
67
+ * @deprecated This method does not do anything
68
+ */
69
+ shutdown(): Promise<void>;
70
+ /**
71
+ * Initialize telemetry with the given configuration
72
+ * @param config - Optional telemetry configuration object
73
+ * @returns Telemetry instance that can be used for tracing
74
+ */
75
+ static init(config?: OtelConfig): Telemetry;
76
+ static getActiveSpan(): Span | undefined;
77
+ /**
78
+ * Get the global telemetry instance
79
+ * @throws {Error} If telemetry has not been initialized
80
+ * @returns {Telemetry} The global telemetry instance
81
+ */
82
+ static get(): Telemetry;
83
+ /**
84
+ * Wraps a class instance with telemetry tracing
85
+ * @param instance The class instance to wrap
86
+ * @param options Optional configuration for tracing
87
+ * @returns Wrapped instance with all methods traced
88
+ */
89
+ traceClass<T extends object>(instance: T, options?: {
90
+ /** Base name for spans (e.g. 'integration', 'agent') */
91
+ spanNamePrefix?: string;
92
+ /** Additional attributes to add to all spans */
93
+ attributes?: Record<string, string>;
94
+ /** Methods to exclude from tracing */
95
+ excludeMethods?: string[];
96
+ /** Skip tracing if telemetry is not active */
97
+ skipIfNoTelemetry?: boolean;
98
+ }): T;
99
+ static setBaggage(baggage: Record<string, string>, ctx?: Context): Context;
100
+ static withContext(ctx: Context, fn: () => void): void;
101
+ /**
102
+ * method to trace individual methods with proper context
103
+ * @param method The method to trace
104
+ * @param context Additional context for the trace
105
+ * @returns Wrapped method with tracing
106
+ */
107
+ traceMethod<TMethod extends Function>(method: TMethod, context: {
108
+ spanName: string;
109
+ attributes?: Record<string, string>;
110
+ skipIfNoTelemetry?: boolean;
111
+ parentSpan?: Span;
112
+ }): TMethod;
113
+ getBaggageTracer(): Tracer;
114
+ }
115
+
116
+ declare class MastraBase {
117
+ component: RegisteredLogger;
118
+ protected logger: Logger;
119
+ name?: string;
120
+ telemetry?: Telemetry;
121
+ constructor({ component, name }: {
122
+ component?: RegisteredLogger;
123
+ name?: string;
124
+ });
125
+ /**
126
+ * Set the logger for the agent
127
+ * @param logger
128
+ */
129
+ __setLogger(logger: Logger): void;
130
+ /**
131
+ * Set the telemetry for the
132
+ * @param telemetry
133
+ */
134
+ __setTelemetry(telemetry: Telemetry): void;
135
+ /**
136
+ * Get the telemetry on the vector
137
+ * @returns telemetry
138
+ */
139
+ __getTelemetry(): Telemetry | undefined;
140
+ get experimental_telemetry(): {
141
+ tracer: _opentelemetry_api.Tracer;
142
+ isEnabled: boolean;
143
+ } | undefined;
144
+ }
145
+
146
+ export { MastraBase as M, type OtelConfig as O, type SamplingStrategy as S, Telemetry as T };