@mastra/braintrust 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256
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/CHANGELOG.md +674 -3
- package/LICENSE.md +15 -0
- package/README.md +48 -6
- package/dist/formatter.d.ts +99 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/index.cjs +459 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +460 -192
- package/dist/index.js.map +1 -1
- package/dist/metrics.d.ts +5 -10
- package/dist/metrics.d.ts.map +1 -1
- package/dist/thread-reconstruction.d.ts +47 -0
- package/dist/thread-reconstruction.d.ts.map +1 -0
- package/dist/tracing.d.ts +109 -0
- package/dist/tracing.d.ts.map +1 -0
- package/package.json +23 -13
- package/dist/ai-tracing.d.ts +0 -37
- package/dist/ai-tracing.d.ts.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
1
16
|
# Apache License 2.0
|
|
2
17
|
|
|
3
18
|
Copyright (c) 2025 Kepler Software, Inc.
|
package/README.md
CHANGED
|
@@ -10,21 +10,52 @@ npm install @mastra/braintrust
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
### Zero-Config Setup
|
|
14
|
+
|
|
15
|
+
The exporter automatically reads credentials from environment variables:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Required
|
|
19
|
+
BRAINTRUST_API_KEY=sk-...
|
|
20
|
+
|
|
21
|
+
# Optional
|
|
22
|
+
BRAINTRUST_ENDPOINT=https://api.braintrust.dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { BraintrustExporter } from '@mastra/braintrust';
|
|
27
|
+
|
|
28
|
+
const mastra = new Mastra({
|
|
29
|
+
...,
|
|
30
|
+
observability: {
|
|
31
|
+
configs: {
|
|
32
|
+
braintrust: {
|
|
33
|
+
serviceName: 'my-service',
|
|
34
|
+
exporters: [new BraintrustExporter()],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Explicit Configuration
|
|
42
|
+
|
|
43
|
+
You can also pass credentials directly:
|
|
44
|
+
|
|
13
45
|
```typescript
|
|
14
46
|
import { BraintrustExporter } from '@mastra/braintrust';
|
|
15
47
|
|
|
16
|
-
// Use with Mastra
|
|
17
48
|
const mastra = new Mastra({
|
|
18
49
|
...,
|
|
19
50
|
observability: {
|
|
20
51
|
configs: {
|
|
21
52
|
braintrust: {
|
|
22
|
-
serviceName: 'service',
|
|
53
|
+
serviceName: 'my-service',
|
|
23
54
|
exporters: [
|
|
24
55
|
new BraintrustExporter({
|
|
25
|
-
apiKey:
|
|
26
|
-
projectName:
|
|
27
|
-
endpoint:
|
|
56
|
+
apiKey: 'sk-...',
|
|
57
|
+
projectName: 'mastra-tracing', // Optional, defaults to 'mastra-tracing'
|
|
58
|
+
endpoint: 'https://api.braintrust.dev', // Optional
|
|
28
59
|
}),
|
|
29
60
|
],
|
|
30
61
|
},
|
|
@@ -33,12 +64,23 @@ const mastra = new Mastra({
|
|
|
33
64
|
});
|
|
34
65
|
```
|
|
35
66
|
|
|
67
|
+
### Configuration Options
|
|
68
|
+
|
|
69
|
+
| Option | Type | Description |
|
|
70
|
+
| ------------------ | -------------------- | -------------------------------------------------------------- |
|
|
71
|
+
| `apiKey` | `string` | Braintrust API key. Defaults to `BRAINTRUST_API_KEY` env var |
|
|
72
|
+
| `endpoint` | `string` | Custom endpoint URL. Defaults to `BRAINTRUST_ENDPOINT` env var |
|
|
73
|
+
| `projectName` | `string` | Project name. Defaults to `'mastra-tracing'` |
|
|
74
|
+
| `braintrustLogger` | `Logger<true>` | Optional Braintrust logger instance for context integration |
|
|
75
|
+
| `tuningParameters` | `Record<string,any>` | Support tuning parameters |
|
|
76
|
+
|
|
36
77
|
## Features
|
|
37
78
|
|
|
38
|
-
###
|
|
79
|
+
### Tracing
|
|
39
80
|
|
|
40
81
|
- **Automatic span mapping**: Root spans become Braintrust traces
|
|
41
82
|
- **Type-specific metadata**: Extracts relevant metadata for each span type (agents, tools, workflows)
|
|
42
83
|
- **Error tracking**: Automatic error status and message tracking
|
|
43
84
|
- **Hierarchical traces**: Maintains parent-child relationships
|
|
44
85
|
- **Event span support**: Zero-duration spans for event-type traces
|
|
86
|
+
- **Context integration**: Attach to existing Braintrust spans from `logger.traced()` or `Eval()`
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message format conversion utilities for Braintrust.
|
|
3
|
+
*
|
|
4
|
+
* Converts AI SDK message format (v4/v5) to OpenAI Chat Completion format,
|
|
5
|
+
* which Braintrust requires for proper rendering of threads.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Remove null and undefined values from an object (shallow)
|
|
9
|
+
*/
|
|
10
|
+
export declare function removeNullish<T extends Record<string, unknown>>(obj: T): Partial<T>;
|
|
11
|
+
/**
|
|
12
|
+
* AI SDK content part types (both v4 and v5)
|
|
13
|
+
*/
|
|
14
|
+
interface AISDKTextPart {
|
|
15
|
+
type: 'text';
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
18
|
+
interface AISDKImagePart {
|
|
19
|
+
type: 'image';
|
|
20
|
+
image?: string | Uint8Array | URL;
|
|
21
|
+
mimeType?: string;
|
|
22
|
+
}
|
|
23
|
+
interface AISDKFilePart {
|
|
24
|
+
type: 'file';
|
|
25
|
+
data?: string | Uint8Array | URL;
|
|
26
|
+
filename?: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
mimeType?: string;
|
|
29
|
+
}
|
|
30
|
+
interface AISDKReasoningPart {
|
|
31
|
+
type: 'reasoning';
|
|
32
|
+
text?: string;
|
|
33
|
+
}
|
|
34
|
+
interface AISDKToolCallPart {
|
|
35
|
+
type: 'tool-call';
|
|
36
|
+
toolCallId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
args?: unknown;
|
|
39
|
+
input?: unknown;
|
|
40
|
+
}
|
|
41
|
+
interface AISDKToolResultPart {
|
|
42
|
+
type: 'tool-result';
|
|
43
|
+
toolCallId: string;
|
|
44
|
+
result?: unknown;
|
|
45
|
+
output?: unknown;
|
|
46
|
+
}
|
|
47
|
+
type AISDKContentPart = AISDKTextPart | AISDKImagePart | AISDKFilePart | AISDKReasoningPart | AISDKToolCallPart | AISDKToolResultPart | {
|
|
48
|
+
type: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* AI SDK message format (input format for conversion)
|
|
53
|
+
*/
|
|
54
|
+
interface AISDKMessage {
|
|
55
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
56
|
+
content: string | AISDKContentPart[];
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* OpenAI Chat Completion tool call format
|
|
61
|
+
*/
|
|
62
|
+
export interface OpenAIToolCall {
|
|
63
|
+
id: string;
|
|
64
|
+
type: 'function';
|
|
65
|
+
function: {
|
|
66
|
+
name: string;
|
|
67
|
+
arguments: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* OpenAI Chat Completion message format (output format)
|
|
72
|
+
*/
|
|
73
|
+
export interface OpenAIMessage {
|
|
74
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
75
|
+
content: string;
|
|
76
|
+
tool_calls?: OpenAIToolCall[];
|
|
77
|
+
tool_call_id?: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts AI SDK message format to OpenAI Chat Completion format for Braintrust.
|
|
82
|
+
*
|
|
83
|
+
* Supports both AI SDK v4 and v5 formats:
|
|
84
|
+
* - v4 uses 'args' for tool calls and 'result' for tool results
|
|
85
|
+
* - v5 uses 'input' for tool calls and 'output' for tool results
|
|
86
|
+
*
|
|
87
|
+
* AI SDK format:
|
|
88
|
+
* { role: "user", content: [{ type: "text", text: "hello" }] }
|
|
89
|
+
* { role: "assistant", content: [{ type: "text", text: "..." }, { type: "tool-call", toolCallId: "...", toolName: "...", args: {...} }] }
|
|
90
|
+
* { role: "tool", content: [{ type: "tool-result", toolCallId: "...", result: {...} }] }
|
|
91
|
+
*
|
|
92
|
+
* OpenAI format (what Braintrust expects):
|
|
93
|
+
* { role: "user", content: "hello" }
|
|
94
|
+
* { role: "assistant", content: "...", tool_calls: [{ id: "...", type: "function", function: { name: "...", arguments: "..." } }] }
|
|
95
|
+
* { role: "tool", content: "result", tool_call_id: "..." }
|
|
96
|
+
*/
|
|
97
|
+
export declare function convertAISDKMessage(message: AISDKMessage | OpenAIMessage | unknown): OpenAIMessage | unknown;
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAA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