@mastra/braintrust 1.0.0-beta.9 → 1.0.1-alpha.0

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.
@@ -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;IACt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