@mastra/core 0.1.27-unstable.1 → 0.2.0-alpha.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -4
- package/dist/action/index.d.ts +18 -0
- package/dist/action/index.js +1 -0
- package/dist/agent/index.d.ts +18 -60
- package/dist/agent/index.js +9 -0
- package/dist/base.d.ts +46 -0
- package/dist/base.js +3 -0
- package/dist/chunk-27EL4TRB.js +70 -0
- package/dist/chunk-42DYOLDV.js +96 -0
- package/dist/chunk-5R6DBXQM.js +57 -0
- package/dist/chunk-6ZVFVYLE.js +101 -0
- package/dist/chunk-AJJZUHB4.js +14 -0
- package/dist/chunk-AO76Z4K3.js +77 -0
- package/dist/chunk-BQMCLBCR.js +1364 -0
- package/dist/chunk-BWEOV64I.js +504 -0
- package/dist/chunk-FCRDS4YS.js +315 -0
- package/dist/chunk-FROFMREE.js +197 -0
- package/dist/chunk-HBTQNIAX.js +90 -0
- package/dist/chunk-K7KUCZT2.js +630 -0
- package/dist/chunk-LUULSM4U.js +81 -0
- package/dist/chunk-LYNJHHQX.js +36 -0
- package/dist/chunk-NLQVQJOD.js +148 -0
- package/dist/chunk-OJJ6QGX4.js +185 -0
- package/dist/chunk-OZZS5Y3C.js +188 -0
- package/dist/chunk-Q5JF3TKZ.js +52 -0
- package/dist/chunk-QLN26TPI.js +35 -0
- package/dist/chunk-RPBNMIV7.js +694 -0
- package/dist/chunk-S45F6AHA.js +199 -0
- package/dist/chunk-VOUPGVRD.js +27 -0
- package/dist/chunk-Y7TKCKRI.js +77 -0
- package/dist/deployer/index.d.ts +35 -0
- package/dist/deployer/index.js +4 -0
- package/dist/embeddings/index.d.ts +8 -0
- package/dist/embeddings/index.js +2 -0
- package/dist/engine/index.d.ts +40 -127
- package/dist/engine/index.js +4 -0
- package/dist/engine-EwEG-4Iv.d.ts +127 -0
- package/dist/eval/index.d.ts +33 -0
- package/dist/eval/index.js +3 -0
- package/dist/filter/index.d.ts +87 -0
- package/dist/filter/index.js +2 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +2 -0
- package/dist/index-B9i6dmc0.d.ts +84 -0
- package/dist/index-CA9EWqaj.d.ts +1039 -0
- package/dist/index.d.ts +109 -11
- package/dist/index.js +168 -5
- package/dist/integration/index.d.ts +44 -4
- package/dist/integration/index.js +3 -0
- package/dist/llm/index.d.ts +18 -101
- package/dist/llm/index.js +6 -0
- package/dist/logger/index.d.ts +3 -60
- package/dist/logger/index.js +2 -0
- package/dist/mastra/index.d.ts +65 -42
- package/dist/mastra/index.js +8 -0
- package/dist/memory/index.d.ts +18 -0
- package/dist/memory/index.js +4 -0
- package/dist/metric-D2V4CR8D.d.ts +9 -0
- package/dist/relevance/index.d.ts +38 -0
- package/dist/relevance/index.js +10 -0
- package/dist/storage/index.d.ts +70 -0
- package/dist/storage/index.js +4 -0
- package/dist/telemetry/index.d.ts +118 -0
- package/dist/telemetry/index.js +3 -0
- package/dist/tools/index.d.ts +32 -2
- package/dist/tools/index.js +2 -0
- package/dist/tts/index.d.ts +30 -0
- package/dist/tts/index.js +6 -0
- package/dist/types-M16hSruO.d.ts +40 -0
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +2 -0
- package/dist/vector/index.d.ts +24 -4
- package/dist/vector/index.js +5 -0
- package/dist/workflow-Dam5GtdA.d.ts +113 -0
- package/dist/workflows/index.d.ts +34 -3
- package/dist/workflows/index.js +4 -0
- package/package.json +87 -44
- package/dist/core.cjs.development.js +0 -2969
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -2943
- package/dist/core.esm.js.map +0 -1
- package/dist/engine/schema.d.ts +0 -36
- package/dist/engine/types.d.ts +0 -115
- package/dist/engine/utils.d.ts +0 -27
- package/dist/integration/test-integration.d.ts +0 -12
- package/dist/llm/types.d.ts +0 -174
- package/dist/mastra/types.d.ts +0 -1
- package/dist/sync/index.d.ts +0 -2
- package/dist/sync/types.d.ts +0 -30
- package/dist/tools/types.d.ts +0 -35
- package/dist/workflows/step.d.ts +0 -15
- package/dist/workflows/types.d.ts +0 -129
- package/dist/workflows/utils.d.ts +0 -8
- package/dist/workflows/workflow.d.ts +0 -53
package/README.md
CHANGED
|
@@ -1,8 +1,178 @@
|
|
|
1
1
|
# @mastra/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The core foundation of the Mastra framework, providing essential components and interfaces for building AI-powered applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
|
|
34
|
+
const agent = new Agent({
|
|
35
|
+
name: 'my-agent',
|
|
36
|
+
instructions: 'Your task-specific instructions',
|
|
37
|
+
model: {
|
|
38
|
+
provider: 'openai',
|
|
39
|
+
model: 'gpt-4',
|
|
40
|
+
},
|
|
41
|
+
tools: {}, // Optional tools
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
[More agent documentation →](https://mastra.ai/docs/reference/agents/overview)
|
|
46
|
+
|
|
47
|
+
### Embeddings (`/embeddings`)
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { embed, EmbeddingOptions } from '@mastra/core';
|
|
53
|
+
|
|
54
|
+
const embeddings = await embed('text to embed', {
|
|
55
|
+
provider: 'OPEN_AI',
|
|
56
|
+
model: 'text-embedding-ada-002',
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Supported providers right now are OpenAI, Cohere, Amazon Bedrock, Google AI, Mistral, and Voyage.
|
|
61
|
+
|
|
62
|
+
[More embeddings documentation →](https://mastra.ai/docs/reference/embeddings/overview)
|
|
63
|
+
|
|
64
|
+
### Evaluations (`/eval`)
|
|
65
|
+
|
|
66
|
+
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.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { Metric, evaluate } from '@mastra/core';
|
|
70
|
+
|
|
71
|
+
class CustomMetric extends Metric {
|
|
72
|
+
async measure(input: string, output: string): Promise<MetricResult> {
|
|
73
|
+
// Your evaluation logic
|
|
74
|
+
return { score: 0.95 };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
[More evaluations documentation →](https://mastra.ai/docs/reference/eval/overview)
|
|
80
|
+
|
|
81
|
+
### Memory (`/memory`)
|
|
82
|
+
|
|
83
|
+
Memory management provides persistent storage and retrieval of AI interactions. It supports different storage backends and enables context-aware conversations and long-term learning.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { MastraMemory } from '@mastra/core';
|
|
87
|
+
|
|
88
|
+
const memory = new MastraMemory({
|
|
89
|
+
// Memory configuration
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
[More memory documentation →](https://mastra.ai/docs/reference/memory/overview)
|
|
94
|
+
|
|
95
|
+
### Vector Stores (`/vector`)
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { MastraVector } from '@mastra/core';
|
|
101
|
+
|
|
102
|
+
class CustomVectorStore extends MastraVector {
|
|
103
|
+
// Vector store implementation
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
[More vector stores documentation →](https://mastra.ai/docs/reference/vector/overview)
|
|
108
|
+
|
|
109
|
+
### Workflows (`/workflows`)
|
|
110
|
+
|
|
111
|
+
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.
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { Workflow } from '@mastra/core';
|
|
115
|
+
|
|
116
|
+
const workflow = new Workflow({
|
|
117
|
+
name: 'my-workflow',
|
|
118
|
+
steps: [
|
|
119
|
+
// Workflow steps
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
[More workflows documentation →](https://mastra.ai/docs/reference/workflows/overview)
|
|
125
|
+
|
|
126
|
+
### Tools (`/tools`)
|
|
127
|
+
|
|
128
|
+
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.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { ToolAction } from '@mastra/core';
|
|
132
|
+
|
|
133
|
+
const tool = new ToolAction({
|
|
134
|
+
name: 'tool-name',
|
|
135
|
+
description: 'Tool description',
|
|
136
|
+
execute: async context => {
|
|
137
|
+
// Tool implementation
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
[More tools documentation →](https://mastra.ai/docs/reference/tools/overview)
|
|
143
|
+
|
|
144
|
+
### Logger (`/logger`)
|
|
145
|
+
|
|
146
|
+
The logging system provides structured, leveled logging with multiple transport options. It supports debug information, performance monitoring, and error tracking across your AI applications.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { createLogger, LogLevel } from '@mastra/core';
|
|
150
|
+
|
|
151
|
+
const logger = createLogger({
|
|
152
|
+
name: 'MyApp',
|
|
153
|
+
level: LogLevel.INFO,
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
[More logging documentation →](https://mastra.ai/docs/reference/observability/logging)
|
|
158
|
+
|
|
159
|
+
### Telemetry (`/telemetry`)
|
|
160
|
+
|
|
161
|
+
Telemetry provides OpenTelemetry integration for comprehensive monitoring of your AI systems. Track latency, success rates, and system health with distributed tracing and metrics collection.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { Telemetry } from '@mastra/core';
|
|
165
|
+
|
|
166
|
+
const telemetry = Telemetry.init({
|
|
167
|
+
serviceName: 'my-service',
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
[More Telemetry documentation →](https://mastra.ai/docs/reference/observability/telemetry)
|
|
172
|
+
|
|
173
|
+
## Additional Resources
|
|
174
|
+
|
|
175
|
+
- [Getting Started Guide](https://mastra.ai/docs/getting-started/installation)
|
|
176
|
+
- [API Reference](https://mastra.ai/docs/reference)
|
|
177
|
+
- [Examples](https://mastra.ai/docs/examples)
|
|
178
|
+
- [Deployment Guide](https://mastra.ai/docs/deployment/overview)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'zod';
|
|
2
|
+
export { I as IAction, aR as IExecutionContext, d as MastraPrimitives } from '../index-CA9EWqaj.js';
|
|
3
|
+
import '../engine-EwEG-4Iv.js';
|
|
4
|
+
import '../index-B9i6dmc0.js';
|
|
5
|
+
import '../telemetry/index.js';
|
|
6
|
+
import '../tts/index.js';
|
|
7
|
+
import '../vector/index.js';
|
|
8
|
+
import 'ai';
|
|
9
|
+
import 'json-schema';
|
|
10
|
+
import '../base.js';
|
|
11
|
+
import '@opentelemetry/api';
|
|
12
|
+
import 'pino';
|
|
13
|
+
import 'stream';
|
|
14
|
+
import '@opentelemetry/sdk-node';
|
|
15
|
+
import '@opentelemetry/sdk-trace-base';
|
|
16
|
+
import '../metric-D2V4CR8D.js';
|
|
17
|
+
import 'sift';
|
|
18
|
+
import '../types-M16hSruO.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,60 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
/**
|
|
21
|
-
* Set the concrete tools for the agent
|
|
22
|
-
* @param tools
|
|
23
|
-
*/
|
|
24
|
-
__setTools(tools: Record<TKeys, ToolApi>): void;
|
|
25
|
-
/**
|
|
26
|
-
* Set the logger for the agent
|
|
27
|
-
* @param logger
|
|
28
|
-
*/
|
|
29
|
-
__setLogger(logger: Logger): void;
|
|
30
|
-
text({ messages, onStepFinish, maxSteps, }: {
|
|
31
|
-
messages: UserContent[];
|
|
32
|
-
onStepFinish?: (step: string) => void;
|
|
33
|
-
maxSteps?: number;
|
|
34
|
-
}): Promise<import("ai").GenerateTextResult<{}>>;
|
|
35
|
-
textObject({ messages, structuredOutput, onStepFinish, maxSteps, }: {
|
|
36
|
-
messages: UserContent[];
|
|
37
|
-
structuredOutput: StructuredOutput;
|
|
38
|
-
onStepFinish?: (step: string) => void;
|
|
39
|
-
maxSteps?: number;
|
|
40
|
-
}): Promise<import("ai").GenerateObjectResult<{
|
|
41
|
-
[x: string]: any;
|
|
42
|
-
}>>;
|
|
43
|
-
stream({ messages, onStepFinish, onFinish, maxSteps, }: {
|
|
44
|
-
messages: UserContent[];
|
|
45
|
-
onStepFinish?: (step: string) => void;
|
|
46
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
47
|
-
maxSteps?: number;
|
|
48
|
-
}): Promise<import("ai").StreamTextResult<{}>>;
|
|
49
|
-
streamObject({ messages, structuredOutput, onStepFinish, onFinish, maxSteps, }: {
|
|
50
|
-
messages: UserContent[];
|
|
51
|
-
structuredOutput: StructuredOutput;
|
|
52
|
-
onStepFinish?: (step: string) => void;
|
|
53
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
54
|
-
maxSteps?: number;
|
|
55
|
-
}): Promise<import("ai").StreamObjectResult<{
|
|
56
|
-
[x: string]: any;
|
|
57
|
-
}, {
|
|
58
|
-
[x: string]: any;
|
|
59
|
-
}, never>>;
|
|
60
|
-
}
|
|
1
|
+
import 'ai';
|
|
2
|
+
import 'json-schema';
|
|
3
|
+
import 'zod';
|
|
4
|
+
export { A as Agent } from '../index-CA9EWqaj.js';
|
|
5
|
+
import '../base.js';
|
|
6
|
+
import '../metric-D2V4CR8D.js';
|
|
7
|
+
import '../telemetry/index.js';
|
|
8
|
+
import '@opentelemetry/api';
|
|
9
|
+
import '@opentelemetry/sdk-node';
|
|
10
|
+
import '@opentelemetry/sdk-trace-base';
|
|
11
|
+
import '../index-B9i6dmc0.js';
|
|
12
|
+
import 'pino';
|
|
13
|
+
import 'stream';
|
|
14
|
+
import 'sift';
|
|
15
|
+
import '../types-M16hSruO.js';
|
|
16
|
+
import '../vector/index.js';
|
|
17
|
+
import '../engine-EwEG-4Iv.js';
|
|
18
|
+
import '../tts/index.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Agent } from '../chunk-RPBNMIV7.js';
|
|
2
|
+
import '../chunk-OZZS5Y3C.js';
|
|
3
|
+
import '../chunk-K7KUCZT2.js';
|
|
4
|
+
import '../chunk-6ZVFVYLE.js';
|
|
5
|
+
import '../chunk-LUULSM4U.js';
|
|
6
|
+
import '../chunk-27EL4TRB.js';
|
|
7
|
+
import '../chunk-NLQVQJOD.js';
|
|
8
|
+
import '../chunk-HBTQNIAX.js';
|
|
9
|
+
import '../chunk-AJJZUHB4.js';
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as _opentelemetry_api from '@opentelemetry/api';
|
|
2
|
+
import { R as RegisteredLogger, L as Logger, a as LogLevel } from './index-B9i6dmc0.js';
|
|
3
|
+
import { Telemetry } from './telemetry/index.js';
|
|
4
|
+
import 'pino';
|
|
5
|
+
import 'stream';
|
|
6
|
+
import '@opentelemetry/sdk-node';
|
|
7
|
+
import '@opentelemetry/sdk-trace-base';
|
|
8
|
+
|
|
9
|
+
declare class MastraBase {
|
|
10
|
+
component: RegisteredLogger;
|
|
11
|
+
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
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { RegisteredLogger, createLogger } from './chunk-NLQVQJOD.js';
|
|
2
|
+
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
3
|
+
|
|
4
|
+
// src/base.ts
|
|
5
|
+
var _MastraBase = class _MastraBase {
|
|
6
|
+
constructor({ component, name }) {
|
|
7
|
+
__publicField(this, "component", RegisteredLogger.LLM);
|
|
8
|
+
__publicField(this, "logger");
|
|
9
|
+
__publicField(this, "name");
|
|
10
|
+
__publicField(this, "telemetry");
|
|
11
|
+
this.component = component || RegisteredLogger.LLM;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.logger = createLogger({
|
|
14
|
+
name: `${this.component} - ${this.name}`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Set the logger for the agent
|
|
19
|
+
* @param logger
|
|
20
|
+
*/
|
|
21
|
+
__setLogger(logger) {
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.logger.debug(`Logger updated for ${this.component}:${this.name}`);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Internal logging helper that formats and sends logs to the configured logger
|
|
27
|
+
* @param level - Severity level of the log
|
|
28
|
+
* @param message - Main log message
|
|
29
|
+
* @param opts - Optional object for the log
|
|
30
|
+
*/
|
|
31
|
+
log(level, message, opts) {
|
|
32
|
+
if (!this.logger) return;
|
|
33
|
+
const logMessage = {
|
|
34
|
+
type: this.component,
|
|
35
|
+
message,
|
|
36
|
+
destinationPath: this.name ? `${this.component}/${this.name}` : this.component,
|
|
37
|
+
...opts || {}
|
|
38
|
+
};
|
|
39
|
+
const logMethod = level.toLowerCase();
|
|
40
|
+
this.logger[logMethod]?.(logMessage);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set the telemetry for the
|
|
44
|
+
* @param telemetry
|
|
45
|
+
*/
|
|
46
|
+
__setTelemetry(telemetry) {
|
|
47
|
+
this.telemetry = telemetry;
|
|
48
|
+
this.logger.debug(`Telemetry updated for ${this.component} ${this.telemetry.tracer}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get the telemetry on the vector
|
|
52
|
+
* @returns telemetry
|
|
53
|
+
*/
|
|
54
|
+
__getTelemetry() {
|
|
55
|
+
return this.telemetry;
|
|
56
|
+
}
|
|
57
|
+
/*
|
|
58
|
+
get experimental_telemetry config
|
|
59
|
+
*/
|
|
60
|
+
get experimental_telemetry() {
|
|
61
|
+
return this.telemetry ? {
|
|
62
|
+
tracer: this.telemetry.tracer,
|
|
63
|
+
isEnabled: !!this.telemetry.tracer
|
|
64
|
+
} : undefined;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
__name(_MastraBase, "MastraBase");
|
|
68
|
+
var MastraBase = _MastraBase;
|
|
69
|
+
|
|
70
|
+
export { MastraBase };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createTool } from './chunk-VOUPGVRD.js';
|
|
2
|
+
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
// src/integration/integration.ts
|
|
6
|
+
var _Integration = class _Integration {
|
|
7
|
+
constructor() {
|
|
8
|
+
__publicField(this, "name", "Integration");
|
|
9
|
+
__publicField(this, "workflows");
|
|
10
|
+
this.workflows = {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Workflows
|
|
14
|
+
*/
|
|
15
|
+
registerWorkflow(name, fn) {
|
|
16
|
+
if (this.workflows[name]) {
|
|
17
|
+
throw new Error(`Sync function "${name}" already registered`);
|
|
18
|
+
}
|
|
19
|
+
this.workflows[name] = fn;
|
|
20
|
+
}
|
|
21
|
+
getWorkflows({ serialized }) {
|
|
22
|
+
if (serialized) {
|
|
23
|
+
return Object.entries(this.workflows).reduce((acc, [k, v]) => {
|
|
24
|
+
return {
|
|
25
|
+
...acc,
|
|
26
|
+
[k]: {
|
|
27
|
+
name: v.name
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, {});
|
|
31
|
+
}
|
|
32
|
+
return this.workflows;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* TOOLS
|
|
36
|
+
*/
|
|
37
|
+
getStaticTools(_params) {
|
|
38
|
+
throw new Error("Method not implemented.");
|
|
39
|
+
}
|
|
40
|
+
async getTools(_params) {
|
|
41
|
+
throw new Error("Method not implemented.");
|
|
42
|
+
}
|
|
43
|
+
async getApiClient() {
|
|
44
|
+
throw new Error("Method not implemented");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__name(_Integration, "Integration");
|
|
48
|
+
var Integration = _Integration;
|
|
49
|
+
var _OpenAPIToolset = class _OpenAPIToolset {
|
|
50
|
+
constructor() {
|
|
51
|
+
__publicField(this, "authType", "API_KEY");
|
|
52
|
+
}
|
|
53
|
+
get toolSchemas() {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
get toolDocumentations() {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
get baseClient() {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
async getApiClient() {
|
|
63
|
+
throw new Error("API not implemented");
|
|
64
|
+
}
|
|
65
|
+
_generateIntegrationTools() {
|
|
66
|
+
const { client, ...clientMethods } = this.baseClient;
|
|
67
|
+
const schemas = this.toolSchemas;
|
|
68
|
+
const documentations = this.toolDocumentations;
|
|
69
|
+
const tools = Object.keys(clientMethods).reduce((acc, key) => {
|
|
70
|
+
const comment = documentations[key]?.comment;
|
|
71
|
+
const fallbackComment = `Execute ${key}`;
|
|
72
|
+
const tool = createTool({
|
|
73
|
+
id: key,
|
|
74
|
+
inputSchema: schemas[key] || z.object({}),
|
|
75
|
+
description: comment || fallbackComment,
|
|
76
|
+
// documentation: doc || fallbackComment,
|
|
77
|
+
execute: /* @__PURE__ */ __name(async ({ context }) => {
|
|
78
|
+
const client2 = await this.getApiClient();
|
|
79
|
+
const value = client2[key];
|
|
80
|
+
return value({
|
|
81
|
+
...context
|
|
82
|
+
});
|
|
83
|
+
}, "execute")
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
...acc,
|
|
87
|
+
[key]: tool
|
|
88
|
+
};
|
|
89
|
+
}, {});
|
|
90
|
+
return tools;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
__name(_OpenAPIToolset, "OpenAPIToolset");
|
|
94
|
+
var OpenAPIToolset = _OpenAPIToolset;
|
|
95
|
+
|
|
96
|
+
export { Integration, OpenAPIToolset };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MastraBase } from './chunk-27EL4TRB.js';
|
|
2
|
+
import { __name, __publicField } from './chunk-AJJZUHB4.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
import { readFileSync, existsSync } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
|
|
7
|
+
var _MastraDeployer = class _MastraDeployer extends MastraBase {
|
|
8
|
+
constructor({ scope, env, projectName }) {
|
|
9
|
+
super({
|
|
10
|
+
component: "DEPLOYER",
|
|
11
|
+
name: "MasterDeployer"
|
|
12
|
+
});
|
|
13
|
+
__publicField(this, "scope");
|
|
14
|
+
__publicField(this, "projectName");
|
|
15
|
+
__publicField(this, "env");
|
|
16
|
+
this.scope = scope;
|
|
17
|
+
this.env = env;
|
|
18
|
+
this.projectName = projectName;
|
|
19
|
+
}
|
|
20
|
+
loadEnvVars() {
|
|
21
|
+
this.logger.debug("Loading environment variables into context.");
|
|
22
|
+
this.getEnvFiles().forEach((file) => {
|
|
23
|
+
const content = readFileSync(file, "utf-8");
|
|
24
|
+
const config = dotenv.parse(content);
|
|
25
|
+
this.env = {
|
|
26
|
+
...this.env,
|
|
27
|
+
...config
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getEnvFiles() {
|
|
32
|
+
this.logger.debug("Reading environment variables from .env or .env.production files.");
|
|
33
|
+
const envFiles = [
|
|
34
|
+
".env",
|
|
35
|
+
".env.production"
|
|
36
|
+
].map((file) => join(process.cwd(), file)).filter((file) => existsSync(file));
|
|
37
|
+
return envFiles;
|
|
38
|
+
}
|
|
39
|
+
parseEnvFile(filePath) {
|
|
40
|
+
this.logger.debug(`Parsing environment variables file: ${filePath}`);
|
|
41
|
+
const content = readFileSync(filePath, "utf-8");
|
|
42
|
+
return content.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#")).filter((line) => line.includes("="));
|
|
43
|
+
}
|
|
44
|
+
writeFiles({ dir }) {
|
|
45
|
+
this.logger.debug(`Writing files to ${dir}`);
|
|
46
|
+
}
|
|
47
|
+
writeIndex({ dir }) {
|
|
48
|
+
this.logger.debug(`Writing index file to ${dir}`);
|
|
49
|
+
}
|
|
50
|
+
async deploy({ dir, siteId }) {
|
|
51
|
+
this.logger.debug(`Deploying with command ${this.scope}...${siteId || ""} to ${dir} ${this.projectName || "mastra-starter"}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
__name(_MastraDeployer, "MastraDeployer");
|
|
55
|
+
var MastraDeployer = _MastraDeployer;
|
|
56
|
+
|
|
57
|
+
export { MastraDeployer };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { __name } from './chunk-AJJZUHB4.js';
|
|
2
|
+
import { trace, context, SpanStatusCode, SpanKind } from '@opentelemetry/api';
|
|
3
|
+
|
|
4
|
+
function hasActiveTelemetry() {
|
|
5
|
+
try {
|
|
6
|
+
return !!trace.getTracer("default-tracer");
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
__name(hasActiveTelemetry, "hasActiveTelemetry");
|
|
12
|
+
function withSpan(options) {
|
|
13
|
+
return function(_target, propertyKey, descriptor) {
|
|
14
|
+
if (!descriptor || typeof descriptor === "number") return;
|
|
15
|
+
const originalMethod = descriptor.value;
|
|
16
|
+
const methodName = String(propertyKey);
|
|
17
|
+
descriptor.value = function(...args) {
|
|
18
|
+
if (options?.skipIfNoTelemetry && !hasActiveTelemetry()) {
|
|
19
|
+
return originalMethod.apply(this, args);
|
|
20
|
+
}
|
|
21
|
+
const tracer = trace.getTracer("default-tracer");
|
|
22
|
+
let spanName;
|
|
23
|
+
let spanKind;
|
|
24
|
+
if (typeof options === "string") {
|
|
25
|
+
spanName = options;
|
|
26
|
+
} else if (options) {
|
|
27
|
+
spanName = options.spanName || methodName;
|
|
28
|
+
spanKind = options.spanKind;
|
|
29
|
+
} else {
|
|
30
|
+
spanName = methodName;
|
|
31
|
+
}
|
|
32
|
+
const span = tracer.startSpan(spanName, {
|
|
33
|
+
kind: spanKind
|
|
34
|
+
});
|
|
35
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
36
|
+
args.forEach((arg, index) => {
|
|
37
|
+
try {
|
|
38
|
+
span.setAttribute(`${spanName}.argument.${index}`, JSON.stringify(arg));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
span.setAttribute(`${spanName}.argument.${index}`, "[Not Serializable]");
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
let result;
|
|
44
|
+
try {
|
|
45
|
+
result = context.with(ctx, () => originalMethod.apply(this, args));
|
|
46
|
+
if (result instanceof Promise) {
|
|
47
|
+
return result.then((resolvedValue) => {
|
|
48
|
+
try {
|
|
49
|
+
span.setAttribute(`${spanName}.result`, JSON.stringify(resolvedValue));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
span.setAttribute(`${spanName}.result`, "[Not Serializable]");
|
|
52
|
+
}
|
|
53
|
+
return resolvedValue;
|
|
54
|
+
}).finally(() => span.end());
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
span.setAttribute(`${spanName}.result`, JSON.stringify(result));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
span.setAttribute(`${spanName}.result`, "[Not Serializable]");
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
span.setStatus({
|
|
64
|
+
code: SpanStatusCode.ERROR,
|
|
65
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
66
|
+
});
|
|
67
|
+
if (error instanceof Error) {
|
|
68
|
+
span.recordException(error);
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
} finally {
|
|
72
|
+
if (!(result instanceof Promise)) {
|
|
73
|
+
span.end();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return descriptor;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
__name(withSpan, "withSpan");
|
|
81
|
+
function InstrumentClass(options) {
|
|
82
|
+
return function(target) {
|
|
83
|
+
const methods = Object.getOwnPropertyNames(target.prototype);
|
|
84
|
+
methods.forEach((method) => {
|
|
85
|
+
if (options?.excludeMethods?.includes(method) || method === "constructor") return;
|
|
86
|
+
if (options?.methodFilter && !options.methodFilter(method)) return;
|
|
87
|
+
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, method);
|
|
88
|
+
if (descriptor && typeof descriptor.value === "function") {
|
|
89
|
+
Object.defineProperty(target.prototype, method, withSpan({
|
|
90
|
+
spanName: options?.prefix ? `${options.prefix}.${method}` : method,
|
|
91
|
+
skipIfNoTelemetry: true,
|
|
92
|
+
spanKind: options?.spanKind || SpanKind.INTERNAL
|
|
93
|
+
})(target, method, descriptor));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return target;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
__name(InstrumentClass, "InstrumentClass");
|
|
100
|
+
|
|
101
|
+
export { InstrumentClass, hasActiveTelemetry, withSpan };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
9
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
10
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
11
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
12
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
13
|
+
|
|
14
|
+
export { __name, __privateAdd, __privateGet, __privateMethod, __privateSet, __publicField };
|