@mastra/braintrust 1.0.0-beta.12 → 1.0.0-beta.13

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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @mastra/braintrust
2
2
 
3
+ ## 1.0.0-beta.13
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `TrackingExporter` base class with improved handling for: ([#11870](https://github.com/mastra-ai/mastra/pull/11870))
8
+ - **Out-of-order span processing**: Spans that arrive before their parents are now queued and processed once dependencies are available
9
+ - **Delayed cleanup**: Trace data is retained briefly after spans end to handle late-arriving updates
10
+ - **Memory management**: Configurable limits on pending and total traces to prevent memory leaks
11
+
12
+ New configuration options on `TrackingExporterConfig`:
13
+ - `earlyQueueMaxAttempts` - Max retry attempts for queued events (default: 5)
14
+ - `earlyQueueTTLMs` - TTL for queued events in ms (default: 30000)
15
+ - `traceCleanupDelayMs` - Delay before cleaning up completed traces (default: 30000)
16
+ - `maxPendingCleanupTraces` - Soft cap on traces awaiting cleanup (default: 100)
17
+ - `maxTotalTraces` - Hard cap on total traces (default: 500)
18
+
19
+ Updated @mastra/braintrust, @mastra/langfuse, @mastra/langsmith, @mastra/posthog to use the new TrackingExporter
20
+
21
+ ### Patch Changes
22
+
23
+ - Fix `logFeedback()` not working because span_id differs from row id. ([#11927](https://github.com/mastra-ai/mastra/pull/11927))
24
+
25
+ **Problem**: When using `BraintrustExporter`, user feedback intended for specific agent responses appeared as separate rows in Braintrust rather than being attached to the original generation. The `startSpan()` call passed `spanId: span.id` but omitted the `event: { id: span.id }` parameter, causing Braintrust to auto-generate a different UUID for the row `id` field.
26
+
27
+ **Solution**: Add `event: { id: span.id }` to the `startSpan()` call so that the Mastra span ID is used as both the Braintrust `span_id` and row `id`. This allows `logFeedback({ id: span.id })` to correctly attach feedback to existing records.
28
+
29
+ - Fix Thread view truncation in Braintrust when LLM generations include tool calls. ([#11984](https://github.com/mastra-ai/mastra/pull/11984))
30
+
31
+ The Braintrust exporter now reconstructs LLM output in OpenAI Chat Completion format by examining child `MODEL_STEP` and `TOOL_CALL` spans. This enables Braintrust's Thread view to properly display the full conversation flow including tool calls and their results.
32
+
33
+ - Updated dependencies [[`ebae12a`](https://github.com/mastra-ai/mastra/commit/ebae12a2dd0212e75478981053b148a2c246962d), [`c61a0a5`](https://github.com/mastra-ai/mastra/commit/c61a0a5de4904c88fd8b3718bc26d1be1c2ec6e7), [`69136e7`](https://github.com/mastra-ai/mastra/commit/69136e748e32f57297728a4e0f9a75988462f1a7), [`449aed2`](https://github.com/mastra-ai/mastra/commit/449aed2ba9d507b75bf93d427646ea94f734dfd1), [`eb648a2`](https://github.com/mastra-ai/mastra/commit/eb648a2cc1728f7678768dd70cd77619b448dab9), [`0131105`](https://github.com/mastra-ai/mastra/commit/0131105532e83bdcbb73352fc7d0879eebf140dc), [`9d5059e`](https://github.com/mastra-ai/mastra/commit/9d5059eae810829935fb08e81a9bb7ecd5b144a7), [`ef756c6`](https://github.com/mastra-ai/mastra/commit/ef756c65f82d16531c43f49a27290a416611e526), [`b00ccd3`](https://github.com/mastra-ai/mastra/commit/b00ccd325ebd5d9e37e34dd0a105caae67eb568f), [`3bdfa75`](https://github.com/mastra-ai/mastra/commit/3bdfa7507a91db66f176ba8221aa28dd546e464a), [`e770de9`](https://github.com/mastra-ai/mastra/commit/e770de941a287a49b1964d44db5a5763d19890a6), [`52e2716`](https://github.com/mastra-ai/mastra/commit/52e2716b42df6eff443de72360ae83e86ec23993), [`27b4040`](https://github.com/mastra-ai/mastra/commit/27b4040bfa1a95d92546f420a02a626b1419a1d6), [`610a70b`](https://github.com/mastra-ai/mastra/commit/610a70bdad282079f0c630e0d7bb284578f20151), [`8dc7f55`](https://github.com/mastra-ai/mastra/commit/8dc7f55900395771da851dc7d78d53ae84fe34ec), [`8379099`](https://github.com/mastra-ai/mastra/commit/8379099fc467af6bef54dd7f80c9bd75bf8bbddf), [`b06be72`](https://github.com/mastra-ai/mastra/commit/b06be7223d5ef23edc98c01a67ef713c6cc039f9), [`8c0ec25`](https://github.com/mastra-ai/mastra/commit/8c0ec25646c8a7df253ed1e5ff4863a0d3f1316c), [`ff4d9a6`](https://github.com/mastra-ai/mastra/commit/ff4d9a6704fc87b31a380a76ed22736fdedbba5a), [`69821ef`](https://github.com/mastra-ai/mastra/commit/69821ef806482e2c44e2197ac0b050c3fe3a5285), [`1ed5716`](https://github.com/mastra-ai/mastra/commit/1ed5716830867b3774c4a1b43cc0d82935f32b96), [`4186bdd`](https://github.com/mastra-ai/mastra/commit/4186bdd00731305726fa06adba0b076a1d50b49f), [`7aaf973`](https://github.com/mastra-ai/mastra/commit/7aaf973f83fbbe9521f1f9e7a4fd99b8de464617)]:
34
+ - @mastra/core@1.0.0-beta.22
35
+ - @mastra/observability@1.0.0-beta.11
36
+
3
37
  ## 1.0.0-beta.12
4
38
 
5
39
  ### Minor Changes
@@ -16,7 +50,7 @@
16
50
  - SigNoz: `SIGNOZ_API_KEY`, `SIGNOZ_REGION`, `SIGNOZ_ENDPOINT`
17
51
  - New Relic: `NEW_RELIC_LICENSE_KEY`, `NEW_RELIC_ENDPOINT`
18
52
  - Traceloop: `TRACELOOP_API_KEY`, `TRACELOOP_DESTINATION_ID`, `TRACELOOP_ENDPOINT`
19
- - Laminar: `LMNR_PROJECT_API_KEY`, `LAMINAR_ENDPOINT`, `LAMINAR_TEAM_ID`
53
+ - Laminar: `LMNR_PROJECT_API_KEY`, `LAMINAR_ENDPOINT`
20
54
 
21
55
  Example usage:
22
56
 
@@ -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,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEnF;AAMD;;GAEG;AACH,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,WAAW,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