@mastra/voice-aws-nova-sonic 0.2.1 → 0.2.2-alpha.1
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/LICENSE.md +6 -4
- package/README.md +6 -332
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/base/index.d.ts +1 -1
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/index-Biaf3BmX.d.ts +319 -0
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/request-context/index.d.ts +46 -1
- package/dist/_types/@internal_voice/dist/voice/composite-voice.d.ts +1 -1
- package/dist/docs/SKILL.md +6 -6
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/integrations-voice-aws-nova-sonic.md +2 -0
- package/dist/docs/references/{guides-voice-overview.md → reference-voice-overview.md} +7 -5
- package/dist/docs/references/{guides-voice-speech-to-speech.md → reference-voice-speech-to-speech.md} +4 -2
- package/dist/index.cjs +89 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/package.json +6 -7
- package/CHANGELOG.md +0 -144
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/index-S1lgaKO7.d.ts +0 -218
package/LICENSE.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Portions of this software are licensed as follows:
|
|
2
2
|
|
|
3
|
-
- All content that resides under any directory named
|
|
3
|
+
- All content that resides under any directory named `ee/` within this
|
|
4
4
|
repository, including but not limited to:
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
|
|
5
|
+
- `@mastra/core/auth/ee`
|
|
6
|
+
- `@mastra/core/agent-builder/ee`
|
|
7
|
+
- `@mastra/editor/ee`
|
|
8
|
+
|
|
9
|
+
is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
|
|
8
10
|
|
|
9
11
|
- All third-party components incorporated into the Mastra Software are
|
|
10
12
|
licensed under the original license provided by the owner of the
|
package/README.md
CHANGED
|
@@ -2,97 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Mastra integration for AWS Nova 2 Sonic, providing real-time bidirectional speech-to-speech capabilities using Amazon Bedrock's bidirectional streaming API.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Real-time bidirectional streaming**: Continuous audio streaming in both directions
|
|
8
|
-
- **Multilingual support**: Supports English, French, Italian, German, Spanish, Portuguese, and Hindi
|
|
9
|
-
- **Polyglot voices**: Voices that can speak multiple languages within the same session
|
|
10
|
-
- **Barge-in support**: Users can interrupt the assistant mid-speech; handled server-side by Nova Sonic
|
|
11
|
-
- **Tool/function calling**: Support for agentic workflows and async tool execution
|
|
12
|
-
- **Cross-modal input**: Support for both audio and text inputs in the same conversation
|
|
13
|
-
- **Natural turn-taking**: Intelligent voice activity detection and turn management
|
|
14
|
-
- **Robust error handling**: Comprehensive error handling with detailed error codes
|
|
15
|
-
|
|
16
5
|
## Installation
|
|
17
6
|
|
|
18
7
|
```bash
|
|
19
8
|
npm install @mastra/voice-aws-nova-sonic
|
|
20
|
-
# or
|
|
21
|
-
pnpm add @mastra/voice-aws-nova-sonic
|
|
22
|
-
# or
|
|
23
|
-
yarn add @mastra/voice-aws-nova-sonic
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Prerequisites
|
|
27
|
-
|
|
28
|
-
- Node.js >= 22.13.0
|
|
29
|
-
- AWS account with access to Amazon Bedrock
|
|
30
|
-
- AWS credentials configured (see [AWS Setup](#aws-setup))
|
|
31
|
-
- Access to Nova 2 Sonic model in your AWS region
|
|
32
|
-
|
|
33
|
-
## AWS Setup
|
|
34
|
-
|
|
35
|
-
### 1. Enable Nova 2 Sonic in Amazon Bedrock
|
|
36
|
-
|
|
37
|
-
1. Go to the [Amazon Bedrock Console](https://console.aws.amazon.com/bedrock/)
|
|
38
|
-
2. Navigate to "Model access" in the left sidebar
|
|
39
|
-
3. Request access to "Amazon Nova 2 Sonic" model
|
|
40
|
-
4. Wait for approval (usually instant)
|
|
41
|
-
|
|
42
|
-
### 2. Configure AWS Credentials
|
|
43
|
-
|
|
44
|
-
You can configure AWS credentials in several ways:
|
|
45
|
-
|
|
46
|
-
**Option 1: Environment Variables**
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
export AWS_ACCESS_KEY_ID=your-access-key-id
|
|
50
|
-
export AWS_SECRET_ACCESS_KEY=your-secret-access-key
|
|
51
|
-
export AWS_REGION=us-east-1
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Option 2: AWS Credentials File**
|
|
55
|
-
|
|
56
|
-
```ini
|
|
57
|
-
# ~/.aws/credentials
|
|
58
|
-
[default]
|
|
59
|
-
aws_access_key_id = your-access-key-id
|
|
60
|
-
aws_secret_access_key = your-secret-access-key
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**Option 3: IAM Role** (for EC2/Lambda)
|
|
64
|
-
|
|
65
|
-
- Attach an IAM role with Bedrock permissions to your EC2 instance or Lambda function
|
|
66
|
-
|
|
67
|
-
**Option 4: Explicit Credentials in Code**
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import { NovaSonicVoice } from '@mastra/voice-aws-nova-sonic';
|
|
71
|
-
|
|
72
|
-
const voice = new NovaSonicVoice({
|
|
73
|
-
region: 'us-east-1',
|
|
74
|
-
credentials: {
|
|
75
|
-
accessKeyId: 'your-access-key-id',
|
|
76
|
-
secretAccessKey: 'your-secret-access-key',
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### 3. IAM Permissions
|
|
82
|
-
|
|
83
|
-
Your AWS credentials need the following IAM permissions:
|
|
84
|
-
|
|
85
|
-
```json
|
|
86
|
-
{
|
|
87
|
-
"Version": "2012-10-17",
|
|
88
|
-
"Statement": [
|
|
89
|
-
{
|
|
90
|
-
"Effect": "Allow",
|
|
91
|
-
"Action": ["bedrock:InvokeModel", "bedrock:InvokeModelWithBidirectionalStream"],
|
|
92
|
-
"Resource": "arn:aws:bedrock:*::foundation-model/amazon.nova-2-sonic-v1:0"
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
9
|
```
|
|
97
10
|
|
|
98
11
|
## Usage
|
|
@@ -132,253 +45,14 @@ agent.voice.on('writing', ({ text, role, generationStage }) => {
|
|
|
132
45
|
await agent.voice.send(microphoneStream);
|
|
133
46
|
```
|
|
134
47
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
import { NovaSonicVoice } from '@mastra/voice-aws-nova-sonic';
|
|
139
|
-
|
|
140
|
-
const voice = new NovaSonicVoice({
|
|
141
|
-
region: 'us-east-1', // or 'us-west-2', 'ap-northeast-1'
|
|
142
|
-
model: 'amazon.nova-2-sonic-v1:0',
|
|
143
|
-
speaker: 'matthew', // or 'tiffany', 'amy', etc.
|
|
144
|
-
languageCode: 'en-US',
|
|
145
|
-
instructions: 'You are a helpful assistant.',
|
|
146
|
-
sessionConfig: {
|
|
147
|
-
tools: [
|
|
148
|
-
{
|
|
149
|
-
name: 'search',
|
|
150
|
-
description: 'Search the web',
|
|
151
|
-
inputSchema: {
|
|
152
|
-
type: 'object',
|
|
153
|
-
properties: {
|
|
154
|
-
query: { type: 'string' },
|
|
155
|
-
},
|
|
156
|
-
required: ['query'],
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
turnDetectionConfiguration: {
|
|
161
|
-
// HIGH = fastest (1.5s pause), MEDIUM = balanced (1.75s), LOW = slowest (2s)
|
|
162
|
-
endpointingSensitivity: 'MEDIUM',
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
debug: true,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
await voice.connect();
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### With Tools
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
import { Agent } from '@mastra/core/agent';
|
|
175
|
-
import { NovaSonicVoice } from '@mastra/voice-aws-nova-sonic';
|
|
176
|
-
import { createTool } from '@mastra/core/tools';
|
|
177
|
-
import { z } from 'zod';
|
|
178
|
-
|
|
179
|
-
const weatherTool = createTool({
|
|
180
|
-
id: 'weather',
|
|
181
|
-
description: 'Get weather information',
|
|
182
|
-
inputSchema: z.object({
|
|
183
|
-
location: z.string(),
|
|
184
|
-
}),
|
|
185
|
-
execute: async ({ context }) => {
|
|
186
|
-
// Fetch weather data
|
|
187
|
-
return { temperature: 72, condition: 'sunny' };
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const agent = new Agent({
|
|
192
|
-
name: 'Weather Agent',
|
|
193
|
-
instructions: 'You help users get weather information.',
|
|
194
|
-
model: 'openai/gpt-4o',
|
|
195
|
-
tools: {
|
|
196
|
-
weather: weatherTool,
|
|
197
|
-
},
|
|
198
|
-
voice: new NovaSonicVoice({
|
|
199
|
-
region: 'us-east-1',
|
|
200
|
-
}),
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
await agent.voice.connect();
|
|
204
|
-
// Tools are automatically available to the voice model
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### Cross-Modal Text Input
|
|
208
|
-
|
|
209
|
-
Send text messages during an active voice session:
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
// After connecting and starting audio streaming
|
|
213
|
-
await agent.voice.speak('What is the weather in New York?');
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## API Reference
|
|
217
|
-
|
|
218
|
-
### Constructor
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
new NovaSonicVoice(config?: NovaSonicVoiceConfig)
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
**Configuration Options:**
|
|
225
|
-
|
|
226
|
-
- `region` (string, optional): AWS region. Default: `'us-east-1'`. Supported: `'us-east-1'`, `'us-west-2'`, `'ap-northeast-1'`
|
|
227
|
-
- `model` (string, optional): Model ID. Default: `'amazon.nova-2-sonic-v1:0'`
|
|
228
|
-
- `credentials` (Credentials, optional): AWS credentials. If not provided, uses default credential chain
|
|
229
|
-
- `speaker` (string, optional): Voice name/identifier (e.g., `'matthew'`, `'tiffany'`, `'amy'`)
|
|
230
|
-
- `languageCode` (string, optional): Language code (e.g., `'en-US'`, `'fr-FR'`)
|
|
231
|
-
- `instructions` (string, optional): System instructions for the model
|
|
232
|
-
- `tools` (array, optional): Tool definitions
|
|
233
|
-
- `sessionConfig` (object, optional): Session configuration including `turnDetectionConfiguration`, `tools`, `inferenceConfiguration`
|
|
234
|
-
- `debug` (boolean, optional): Enable debug logging. Default: `false`
|
|
235
|
-
|
|
236
|
-
### Methods
|
|
237
|
-
|
|
238
|
-
#### `connect(options?)`
|
|
239
|
-
|
|
240
|
-
Establishes connection to AWS Bedrock. Must be called before using other methods.
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
await voice.connect();
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
#### `speak(input, options?)`
|
|
247
|
-
|
|
248
|
-
Send cross-modal text input during an active voice session. Nova Sonic processes it and responds with audio.
|
|
249
|
-
|
|
250
|
-
```typescript
|
|
251
|
-
await voice.speak('Hello, world!');
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
#### `listen(audioStream, options?)`
|
|
255
|
-
|
|
256
|
-
Stream audio input for transcription. For Nova Sonic, this is equivalent to `send()`.
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
await voice.listen(audioStream);
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### `send(audioData)`
|
|
263
|
-
|
|
264
|
-
Stream audio data in real-time. Accepts a `NodeJS.ReadableStream` (PCM16 audio) or an `Int16Array`.
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
// Stream from a ReadableStream
|
|
268
|
-
await voice.send(audioStream);
|
|
269
|
-
|
|
270
|
-
// Or with Int16Array
|
|
271
|
-
const audioArray = new Int16Array([...]);
|
|
272
|
-
await voice.send(audioArray);
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
#### `close()`
|
|
276
|
-
|
|
277
|
-
Disconnect and cleanup resources.
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
voice.close();
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
#### `on(event, callback)`
|
|
284
|
-
|
|
285
|
-
Register an event listener.
|
|
286
|
-
|
|
287
|
-
```typescript
|
|
288
|
-
voice.on('speaking', ({ audio }) => {
|
|
289
|
-
// audio is a base64-encoded string of PCM audio
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
voice.on('writing', ({ text, role, generationStage }) => {
|
|
293
|
-
// generationStage: 'SPECULATIVE' (preview) or 'FINAL' (actual transcript)
|
|
294
|
-
console.log(`${role}: ${text}`);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
voice.on('error', ({ message, code }) => {
|
|
298
|
-
console.error(`Error: ${message} (${code})`);
|
|
299
|
-
});
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
#### `off(event, callback)`
|
|
303
|
-
|
|
304
|
-
Remove an event listener.
|
|
305
|
-
|
|
306
|
-
```typescript
|
|
307
|
-
voice.off('speaking', callback);
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### Events
|
|
311
|
-
|
|
312
|
-
- **`speaker`**: Audio stream (`NodeJS.ReadableStream`) for the full response
|
|
313
|
-
- **`speaking`**: Audio chunk `{ audio: string, audioData: Buffer, response_id?: string }`
|
|
314
|
-
- **`writing`**: Text transcription `{ text: string, role: 'assistant' | 'user', generationStage?: 'SPECULATIVE' | 'FINAL' }`
|
|
315
|
-
- **`error`**: Error event `{ message: string, code?: string, details?: unknown }`
|
|
316
|
-
- **`toolCall`**: Tool invocation `{ name: string, args: Record<string, any>, id: string }`
|
|
317
|
-
- **`turnComplete`**: Turn completion `{ timestamp: number }`
|
|
318
|
-
- **`interrupt`**: Barge-in detected `{ type: string, timestamp: number }`
|
|
319
|
-
- **`contentStart`**: Content block started (raw Nova Sonic event)
|
|
320
|
-
- **`contentEnd`**: Content block ended (raw Nova Sonic event)
|
|
321
|
-
- **`usage`**: Token usage `{ inputTokens: number, outputTokens: number, totalTokens: number }`
|
|
322
|
-
|
|
323
|
-
## Supported Regions
|
|
324
|
-
|
|
325
|
-
- `us-east-1` (US East - N. Virginia)
|
|
326
|
-
- `us-west-2` (US West - Oregon)
|
|
327
|
-
- `ap-northeast-1` (Asia Pacific - Tokyo)
|
|
328
|
-
|
|
329
|
-
## Supported Languages
|
|
330
|
-
|
|
331
|
-
- English (US, UK, India, Australia)
|
|
332
|
-
- French
|
|
333
|
-
- Italian
|
|
334
|
-
- German
|
|
335
|
-
- Spanish
|
|
336
|
-
- Portuguese
|
|
337
|
-
- Hindi
|
|
338
|
-
|
|
339
|
-
## Error Handling
|
|
340
|
-
|
|
341
|
-
The package provides error handling with specific error codes:
|
|
342
|
-
|
|
343
|
-
```typescript
|
|
344
|
-
import { NovaSonicError, NovaSonicErrorCode } from '@mastra/voice-aws-nova-sonic';
|
|
345
|
-
|
|
346
|
-
voice.on('error', ({ message, code, details }) => {
|
|
347
|
-
if (code === NovaSonicErrorCode.CONNECTION_FAILED) {
|
|
348
|
-
// Handle connection error
|
|
349
|
-
} else if (code === NovaSonicErrorCode.CREDENTIALS_MISSING) {
|
|
350
|
-
// Handle credentials error
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
## Troubleshooting
|
|
356
|
-
|
|
357
|
-
### Connection Issues
|
|
358
|
-
|
|
359
|
-
- Verify AWS credentials are configured correctly
|
|
360
|
-
- Check that Nova 2 Sonic is enabled in your AWS Bedrock console
|
|
361
|
-
- Ensure your IAM role/user has the required permissions
|
|
362
|
-
- Verify the region supports Nova 2 Sonic
|
|
363
|
-
|
|
364
|
-
### Audio Issues
|
|
365
|
-
|
|
366
|
-
- Ensure audio format is compatible (PCM, 16-bit, 16kHz)
|
|
367
|
-
- Check sample rate matches expected format
|
|
368
|
-
- Verify audio stream is not empty
|
|
369
|
-
|
|
370
|
-
### Authentication Issues
|
|
48
|
+
## Documentation
|
|
371
49
|
|
|
372
|
-
-
|
|
373
|
-
- Verify IAM permissions include Bedrock access
|
|
374
|
-
- Ensure region is correct
|
|
50
|
+
- [@mastra/voice-aws-nova-sonic documentation](https://mastra.ai/integrations/voice/aws-nova-sonic)
|
|
375
51
|
|
|
376
|
-
##
|
|
52
|
+
## Changelog
|
|
377
53
|
|
|
378
|
-
|
|
54
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/voice/aws-nova-sonic/CHANGELOG.md) for version history and release notes.
|
|
379
55
|
|
|
380
|
-
##
|
|
56
|
+
## Support
|
|
381
57
|
|
|
382
|
-
|
|
383
|
-
- [AWS Nova 2 Sonic Documentation](https://docs.aws.amazon.com/nova/latest/nova2-userguide/using-conversational-speech.html)
|
|
384
|
-
- [Amazon Bedrock Documentation](https://docs.aws.amazon.com/bedrock/)
|
|
58
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { Transform } from "stream";
|
|
2
|
+
//#region src/logger/adapter.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* OpenTelemetry-compatible trace correlation fields, injected at the top
|
|
5
|
+
* level of a logger's native record.
|
|
6
|
+
*
|
|
7
|
+
* Field names are part of the platform contract (snake_case, W3C formats):
|
|
8
|
+
* external consumers (e.g. the Studio logs view reading Railway stdout)
|
|
9
|
+
* parse structured log lines and look for exactly these keys.
|
|
10
|
+
*/
|
|
11
|
+
interface TraceFields {
|
|
12
|
+
/** 32-char lowercase hex W3C trace id */
|
|
13
|
+
trace_id: string;
|
|
14
|
+
/**
|
|
15
|
+
* 16-char lowercase hex W3C span id.
|
|
16
|
+
*
|
|
17
|
+
* Optional, and omitted rather than emitted empty: the active span may be
|
|
18
|
+
* one observability never exports (an internal span, or one dropped by
|
|
19
|
+
* `excludeSpanTypes`), leaving no span id a consumer could look up. The
|
|
20
|
+
* trace is still addressable in that case, so the line keeps `trace_id` and
|
|
21
|
+
* drops only this field. Consumers must treat `span_id` as possibly absent.
|
|
22
|
+
*/
|
|
23
|
+
span_id?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Destination for log records derived from the logger's native record,
|
|
27
|
+
* exported to Mastra observability. Structurally compatible with
|
|
28
|
+
* `LoggerContext` from `@mastra/core/observability`.
|
|
29
|
+
*/
|
|
30
|
+
interface AdapterLogSink {
|
|
31
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
32
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
33
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
34
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
35
|
+
}
|
|
36
|
+
interface LoggerAdapterOptions {
|
|
37
|
+
/** Inject trace_id/span_id into the logger's native records. */
|
|
38
|
+
correlation: boolean;
|
|
39
|
+
/** Export records derived from the native record to Mastra observability. */
|
|
40
|
+
export: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Context handed to an adaptable logger by Mastra when observability is
|
|
44
|
+
* wired up. All members are safe to call on every log call (synchronous,
|
|
45
|
+
* never throw).
|
|
46
|
+
*/
|
|
47
|
+
interface LoggerAdapterContext {
|
|
48
|
+
/**
|
|
49
|
+
* Resolve correlation fields for the currently active span, or undefined
|
|
50
|
+
* when no span is active (in which case no trace fields are added).
|
|
51
|
+
*/
|
|
52
|
+
resolveTraceFields: () => TraceFields | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the observability log sink at call time. Returns the
|
|
55
|
+
* span-correlated sink when a span is active, the global sink otherwise,
|
|
56
|
+
* and undefined when export is disabled or observability is not
|
|
57
|
+
* initialized. Records must still be written to the native destination
|
|
58
|
+
* regardless.
|
|
59
|
+
*/
|
|
60
|
+
getLogSink: () => AdapterLogSink | undefined;
|
|
61
|
+
options: LoggerAdapterOptions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Capability marker a logger implements to opt into native trace
|
|
65
|
+
* correlation and observability export. When a configured logger implements
|
|
66
|
+
* this, Mastra attaches observability directly instead of wrapping the
|
|
67
|
+
* logger in the deprecated `DualLogger`.
|
|
68
|
+
*/
|
|
69
|
+
interface AdaptableLogger extends IMastraLogger {
|
|
70
|
+
__attachObservability(ctx: LoggerAdapterContext): void;
|
|
71
|
+
/**
|
|
72
|
+
* Stable identity for the attachment target. Loggers whose adapter context
|
|
73
|
+
* lives in state shared across a root/child family (e.g. PinoLogger's
|
|
74
|
+
* mixin ref cell) return that shared object, so attaching any family
|
|
75
|
+
* member is recognized as re-attaching the whole family. Defaults to the
|
|
76
|
+
* logger instance itself when absent.
|
|
77
|
+
*/
|
|
78
|
+
__observabilityAttachmentKey?(): object;
|
|
79
|
+
}
|
|
80
|
+
declare function isAdaptableLogger(logger: IMastraLogger): logger is AdaptableLogger;
|
|
81
|
+
/**
|
|
82
|
+
* Export a tracked exception through the adapter sink, mirroring the
|
|
83
|
+
* DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
|
|
84
|
+
* when present on a MastraError-like value). Never throws into the caller.
|
|
85
|
+
*/
|
|
86
|
+
declare function exportTrackedException(ctx: LoggerAdapterContext | undefined, error: Error, metadata?: Record<string, unknown>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Adapt IMastraLogger's variadic args into the structured `data` payload of
|
|
89
|
+
* an exported log record. Extracts the first plain object as data,
|
|
90
|
+
* serializes an Error arg, and collects remaining primitives under `args`
|
|
91
|
+
* so the derived record preserves all context from the native call.
|
|
92
|
+
*/
|
|
93
|
+
declare function buildLogRecordData(args: unknown[]): Record<string, unknown> | undefined;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/logger/index.d.ts
|
|
96
|
+
declare const RegisteredLogger: {
|
|
97
|
+
readonly AGENT: 'AGENT';
|
|
98
|
+
readonly OBSERVABILITY: 'OBSERVABILITY';
|
|
99
|
+
readonly AUTH: 'AUTH';
|
|
100
|
+
readonly BROWSER: 'BROWSER';
|
|
101
|
+
readonly NETWORK: 'NETWORK';
|
|
102
|
+
readonly WORKFLOW: 'WORKFLOW';
|
|
103
|
+
readonly LLM: 'LLM';
|
|
104
|
+
readonly TTS: 'TTS';
|
|
105
|
+
readonly VOICE: 'VOICE';
|
|
106
|
+
readonly VECTOR: 'VECTOR';
|
|
107
|
+
readonly BUNDLER: 'BUNDLER';
|
|
108
|
+
readonly DEPLOYER: 'DEPLOYER';
|
|
109
|
+
readonly MEMORY: 'MEMORY';
|
|
110
|
+
readonly STORAGE: 'STORAGE';
|
|
111
|
+
readonly EMBEDDINGS: 'EMBEDDINGS';
|
|
112
|
+
readonly MCP_SERVER: 'MCP_SERVER';
|
|
113
|
+
readonly SERVER_CACHE: 'SERVER_CACHE';
|
|
114
|
+
readonly SERVER: 'SERVER';
|
|
115
|
+
readonly WORKSPACE: 'WORKSPACE';
|
|
116
|
+
readonly CHANNEL: 'CHANNEL';
|
|
117
|
+
};
|
|
118
|
+
type RegisteredLogger = (typeof RegisteredLogger)[keyof typeof RegisteredLogger];
|
|
119
|
+
declare const LogLevel: {
|
|
120
|
+
readonly DEBUG: 'debug';
|
|
121
|
+
readonly INFO: 'info';
|
|
122
|
+
readonly WARN: 'warn';
|
|
123
|
+
readonly ERROR: 'error';
|
|
124
|
+
readonly NONE: 'silent';
|
|
125
|
+
};
|
|
126
|
+
type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
127
|
+
interface BaseLogMessage {
|
|
128
|
+
runId?: string;
|
|
129
|
+
msg: string;
|
|
130
|
+
level: LogLevel;
|
|
131
|
+
time: Date;
|
|
132
|
+
pid: number;
|
|
133
|
+
hostname: string;
|
|
134
|
+
name: string;
|
|
135
|
+
}
|
|
136
|
+
declare abstract class LoggerTransport extends Transform {
|
|
137
|
+
constructor(opts?: any);
|
|
138
|
+
listLogsByRunId(_args: {
|
|
139
|
+
runId: string;
|
|
140
|
+
fromDate?: Date;
|
|
141
|
+
toDate?: Date;
|
|
142
|
+
logLevel?: LogLevel;
|
|
143
|
+
filters?: Record<string, any>;
|
|
144
|
+
page?: number;
|
|
145
|
+
perPage?: number;
|
|
146
|
+
}): Promise<{
|
|
147
|
+
logs: BaseLogMessage[];
|
|
148
|
+
total: number;
|
|
149
|
+
page: number;
|
|
150
|
+
perPage: number;
|
|
151
|
+
hasMore: boolean;
|
|
152
|
+
}>;
|
|
153
|
+
listLogs(_args?: {
|
|
154
|
+
fromDate?: Date;
|
|
155
|
+
toDate?: Date;
|
|
156
|
+
logLevel?: LogLevel;
|
|
157
|
+
filters?: Record<string, any>;
|
|
158
|
+
returnPaginationResults?: boolean;
|
|
159
|
+
page?: number;
|
|
160
|
+
perPage?: number;
|
|
161
|
+
}): Promise<{
|
|
162
|
+
logs: BaseLogMessage[];
|
|
163
|
+
total: number;
|
|
164
|
+
page: number;
|
|
165
|
+
perPage: number;
|
|
166
|
+
hasMore: boolean;
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
declare const createCustomTransport: (stream: Transform, listLogs?: LoggerTransport['listLogs'], listLogsByRunId?: LoggerTransport['listLogsByRunId']) => LoggerTransport;
|
|
170
|
+
interface IMastraLogger {
|
|
171
|
+
debug(message: string, ...args: any[]): void;
|
|
172
|
+
info(message: string, ...args: any[]): void;
|
|
173
|
+
warn(message: string, ...args: any[]): void;
|
|
174
|
+
error(message: string, ...args: any[]): void;
|
|
175
|
+
trackException(error: Error, metadata?: Record<string, unknown>): void;
|
|
176
|
+
getTransports(): Map<string, LoggerTransport>;
|
|
177
|
+
listLogs(_transportId: string, _params?: {
|
|
178
|
+
fromDate?: Date;
|
|
179
|
+
toDate?: Date;
|
|
180
|
+
logLevel?: LogLevel;
|
|
181
|
+
filters?: Record<string, any>;
|
|
182
|
+
page?: number;
|
|
183
|
+
perPage?: number;
|
|
184
|
+
}): Promise<{
|
|
185
|
+
logs: BaseLogMessage[];
|
|
186
|
+
total: number;
|
|
187
|
+
page: number;
|
|
188
|
+
perPage: number;
|
|
189
|
+
hasMore: boolean;
|
|
190
|
+
}>;
|
|
191
|
+
listLogsByRunId(_args: {
|
|
192
|
+
transportId: string;
|
|
193
|
+
runId: string;
|
|
194
|
+
fromDate?: Date;
|
|
195
|
+
toDate?: Date;
|
|
196
|
+
logLevel?: LogLevel;
|
|
197
|
+
filters?: Record<string, any>;
|
|
198
|
+
page?: number;
|
|
199
|
+
perPage?: number;
|
|
200
|
+
}): Promise<{
|
|
201
|
+
logs: BaseLogMessage[];
|
|
202
|
+
total: number;
|
|
203
|
+
page: number;
|
|
204
|
+
perPage: number;
|
|
205
|
+
hasMore: boolean;
|
|
206
|
+
}>;
|
|
207
|
+
}
|
|
208
|
+
declare abstract class MastraLogger implements IMastraLogger {
|
|
209
|
+
protected name: string;
|
|
210
|
+
protected level: LogLevel;
|
|
211
|
+
protected transports: Map<string, LoggerTransport>;
|
|
212
|
+
constructor(options?: {
|
|
213
|
+
name?: string;
|
|
214
|
+
level?: LogLevel;
|
|
215
|
+
transports?: Record<string, LoggerTransport>;
|
|
216
|
+
});
|
|
217
|
+
abstract debug(message: string, ...args: any[]): void;
|
|
218
|
+
abstract info(message: string, ...args: any[]): void;
|
|
219
|
+
abstract warn(message: string, ...args: any[]): void;
|
|
220
|
+
abstract error(message: string, ...args: any[]): void;
|
|
221
|
+
getTransports(): Map<string, LoggerTransport>;
|
|
222
|
+
trackException(_error: Error, _metadata?: Record<string, unknown>): void;
|
|
223
|
+
listLogs(transportId: string, params?: {
|
|
224
|
+
fromDate?: Date;
|
|
225
|
+
toDate?: Date;
|
|
226
|
+
logLevel?: LogLevel;
|
|
227
|
+
filters?: Record<string, any>;
|
|
228
|
+
page?: number;
|
|
229
|
+
perPage?: number;
|
|
230
|
+
}): Promise<{
|
|
231
|
+
logs: BaseLogMessage[];
|
|
232
|
+
total: number;
|
|
233
|
+
page: number;
|
|
234
|
+
perPage: number;
|
|
235
|
+
hasMore: boolean;
|
|
236
|
+
}>;
|
|
237
|
+
listLogsByRunId({ transportId, runId, fromDate, toDate, logLevel, filters, page, perPage }: {
|
|
238
|
+
transportId: string;
|
|
239
|
+
runId: string;
|
|
240
|
+
fromDate?: Date;
|
|
241
|
+
toDate?: Date;
|
|
242
|
+
logLevel?: LogLevel;
|
|
243
|
+
filters?: Record<string, any>;
|
|
244
|
+
page?: number;
|
|
245
|
+
perPage?: number;
|
|
246
|
+
}): Promise<{
|
|
247
|
+
logs: BaseLogMessage[];
|
|
248
|
+
total: number;
|
|
249
|
+
page: number;
|
|
250
|
+
perPage: number;
|
|
251
|
+
hasMore: boolean;
|
|
252
|
+
}>;
|
|
253
|
+
}
|
|
254
|
+
type LogFilterContext = {
|
|
255
|
+
component?: RegisteredLogger;
|
|
256
|
+
level: LogLevel;
|
|
257
|
+
message: string;
|
|
258
|
+
args: unknown[];
|
|
259
|
+
};
|
|
260
|
+
type LogFilter = (ctx: LogFilterContext) => boolean;
|
|
261
|
+
interface ConsoleLoggerOptions {
|
|
262
|
+
name?: string;
|
|
263
|
+
level?: LogLevel;
|
|
264
|
+
component?: RegisteredLogger;
|
|
265
|
+
filter?: LogFilter;
|
|
266
|
+
}
|
|
267
|
+
declare class ConsoleLogger extends MastraLogger {
|
|
268
|
+
#private;
|
|
269
|
+
protected component?: RegisteredLogger;
|
|
270
|
+
protected filter?: LogFilter;
|
|
271
|
+
constructor(options?: ConsoleLoggerOptions);
|
|
272
|
+
/**
|
|
273
|
+
* Adapter hook (see `AdaptableLogger`): enables native trace correlation
|
|
274
|
+
* (trace_id/span_id appended to console output) and observability export
|
|
275
|
+
* derived from the same record. Called by Mastra during setup.
|
|
276
|
+
*/
|
|
277
|
+
__attachObservability(ctx: LoggerAdapterContext): void;
|
|
278
|
+
child(componentOrBindings: RegisteredLogger | Record<string, unknown>): ConsoleLogger;
|
|
279
|
+
private shouldLog;
|
|
280
|
+
private prefix;
|
|
281
|
+
debug(message: string, ...args: any[]): void;
|
|
282
|
+
info(message: string, ...args: any[]): void;
|
|
283
|
+
warn(message: string, ...args: any[]): void;
|
|
284
|
+
error(message: string, ...args: any[]): void;
|
|
285
|
+
trackException(error: Error, metadata?: Record<string, unknown>): void;
|
|
286
|
+
listLogs(_transportId: string, _params?: {
|
|
287
|
+
fromDate?: Date;
|
|
288
|
+
toDate?: Date;
|
|
289
|
+
logLevel?: LogLevel;
|
|
290
|
+
filters?: Record<string, any>;
|
|
291
|
+
page?: number;
|
|
292
|
+
perPage?: number;
|
|
293
|
+
}): Promise<{
|
|
294
|
+
logs: never[];
|
|
295
|
+
total: number;
|
|
296
|
+
page: number;
|
|
297
|
+
perPage: number;
|
|
298
|
+
hasMore: boolean;
|
|
299
|
+
}>;
|
|
300
|
+
listLogsByRunId(_args: {
|
|
301
|
+
transportId: string;
|
|
302
|
+
runId: string;
|
|
303
|
+
fromDate?: Date;
|
|
304
|
+
toDate?: Date;
|
|
305
|
+
logLevel?: LogLevel;
|
|
306
|
+
filters?: Record<string, any>;
|
|
307
|
+
page?: number;
|
|
308
|
+
perPage?: number;
|
|
309
|
+
}): Promise<{
|
|
310
|
+
logs: never[];
|
|
311
|
+
total: number;
|
|
312
|
+
page: number;
|
|
313
|
+
perPage: number;
|
|
314
|
+
hasMore: boolean;
|
|
315
|
+
}>;
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
export { buildLogRecordData as _, LogFilter as a, LoggerTransport as c, createCustomTransport as d, AdaptableLogger as f, TraceFields as g, LoggerAdapterOptions as h, IMastraLogger as i, MastraLogger as l, LoggerAdapterContext as m, ConsoleLogger as n, LogFilterContext as o, AdapterLogSink as p, ConsoleLoggerOptions as r, LogLevel as s, BaseLogMessage as t, RegisteredLogger as u, exportTrackedException as v, isAdaptableLogger as y };
|
|
319
|
+
//# sourceMappingURL=index-Biaf3BmX.d.ts.map
|