wiggum-cli 0.3.0 → 0.3.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.
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Braintrust Tracing Utility
3
+ * Provides AI call tracing for debugging and analysis
4
+ */
5
+
6
+ import { initLogger, wrapAISDK } from 'braintrust';
7
+ import * as ai from 'ai';
8
+
9
+ // Re-export traced utilities
10
+ export { traced, currentSpan, wrapTraced } from 'braintrust';
11
+
12
+ /**
13
+ * Initialize Braintrust logger if API key is available
14
+ */
15
+ let loggerInitialized = false;
16
+
17
+ export function initTracing(): void {
18
+ if (loggerInitialized) return;
19
+
20
+ const apiKey = process.env.BRAINTRUST_API_KEY;
21
+ if (!apiKey) {
22
+ // Silently skip tracing if no API key
23
+ return;
24
+ }
25
+
26
+ try {
27
+ initLogger({
28
+ apiKey,
29
+ projectName: process.env.BRAINTRUST_PROJECT_NAME || 'wiggum-cli',
30
+ });
31
+ loggerInitialized = true;
32
+ } catch {
33
+ // Silently fail if tracing can't be initialized
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Check if tracing is enabled
39
+ */
40
+ export function isTracingEnabled(): boolean {
41
+ return !!process.env.BRAINTRUST_API_KEY;
42
+ }
43
+
44
+ /**
45
+ * Get wrapped AI SDK functions for automatic tracing
46
+ * Falls back to original functions if tracing not available
47
+ */
48
+ export function getTracedAI() {
49
+ initTracing();
50
+
51
+ if (isTracingEnabled()) {
52
+ return wrapAISDK(ai);
53
+ }
54
+
55
+ // Return original AI SDK functions if tracing not enabled
56
+ return ai;
57
+ }
58
+
59
+ /**
60
+ * Wrap a function with tracing
61
+ * No-op if tracing is not enabled
62
+ */
63
+ export function maybeTraced<T extends (...args: unknown[]) => unknown>(
64
+ fn: T,
65
+ options: { type?: string; name?: string } = {}
66
+ ): T {
67
+ if (!isTracingEnabled()) {
68
+ return fn;
69
+ }
70
+
71
+ const { wrapTraced } = require('braintrust');
72
+ return wrapTraced(fn, {
73
+ type: options.type || 'function',
74
+ name: options.name || fn.name || 'anonymous',
75
+ });
76
+ }